From 64fc03146ea99ba0503084edec4eb3d1287fe9f9 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Wed, 10 Jul 2024 12:20:37 +0200 Subject: [PATCH] Merge pull request #28507 from storybookjs/norbert/apply-fixes-on-incorrect-types-due-to-cpc CPC: Fix type generation (cherry picked from commit a937895ce21ec774bd6696750f9e64ab491d3ce5) --- scripts/prepare/addon-bundle.ts | 15 ++++++++++++++- scripts/prepare/bundle.ts | 12 ++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/scripts/prepare/addon-bundle.ts b/scripts/prepare/addon-bundle.ts index 8b1aeb79bf96..f6d15a2ce377 100755 --- a/scripts/prepare/addon-bundle.ts +++ b/scripts/prepare/addon-bundle.ts @@ -10,6 +10,7 @@ import { exec } from '../utils/exec'; import { globalPackages as globalPreviewPackages } from '../../code/core/src/preview/globals/globals'; import { globalPackages as globalManagerPackages } from '../../code/core/src/manager/globals/globals'; +import { glob } from 'glob'; /* TYPES */ @@ -62,8 +63,9 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => { const tasks: Promise[] = []; + const outDir = join(process.cwd(), 'dist'); const commonOptions: Options = { - outDir: join(process.cwd(), 'dist'), + outDir, silent: true, treeshake: true, shims: false, @@ -190,6 +192,17 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => { await Promise.all(tasks); + const dtsFiles = await glob(outDir + '/**/*.d.ts'); + await Promise.all( + dtsFiles.map(async (file) => { + const content = await fs.readFile(file, 'utf-8'); + await fs.writeFile( + file, + content.replace(/from \'core\/dist\/(.*)\'/g, `from 'storybook/internal/$1'`) + ); + }) + ); + if (post) { await exec(`bun ${post}`, { cwd }, { debug: true }); } diff --git a/scripts/prepare/bundle.ts b/scripts/prepare/bundle.ts index 1ff5b793af20..28e994773c29 100755 --- a/scripts/prepare/bundle.ts +++ b/scripts/prepare/bundle.ts @@ -7,6 +7,7 @@ import aliasPlugin from 'esbuild-plugin-alias'; import { dedent } from 'ts-dedent'; import slash from 'slash'; import { exec } from '../utils/exec'; +import { glob } from 'glob'; /* TYPES */ @@ -147,6 +148,17 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => { await Promise.all(tasks); + const dtsFiles = await glob(outDir + '/**/*.d.ts'); + await Promise.all( + dtsFiles.map(async (file) => { + const content = await fs.readFile(file, 'utf-8'); + await fs.writeFile( + file, + content.replace(/from \'core\/dist\/(.*)\'/g, `from 'storybook/internal/$1'`) + ); + }) + ); + if (post) { await exec(`bun ${post}`, { cwd }, { debug: true }); }