From c859744512fe4615766d4bd4ad79c867753c80f3 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Wed, 10 Jul 2024 11:51:47 +0200 Subject: [PATCH 1/2] Apply a band-aid on incorrect type generation --- 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..78aa20893bf2 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\/(.*)\'/, `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..4e16fc41289d 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\/(.*)\'/, `from 'storybook/internal/$1'`) + ); + }) + ); + if (post) { await exec(`bun ${post}`, { cwd }, { debug: true }); } From f776dd4af25d29191ba689b714b6efe0097f1aab Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Wed, 10 Jul 2024 11:56:37 +0200 Subject: [PATCH 2/2] make it a global regex to replace multiple occurrences --- scripts/prepare/addon-bundle.ts | 2 +- scripts/prepare/bundle.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/prepare/addon-bundle.ts b/scripts/prepare/addon-bundle.ts index 78aa20893bf2..f6d15a2ce377 100755 --- a/scripts/prepare/addon-bundle.ts +++ b/scripts/prepare/addon-bundle.ts @@ -198,7 +198,7 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => { const content = await fs.readFile(file, 'utf-8'); await fs.writeFile( file, - content.replace(/from \'core\/dist\/(.*)\'/, `from 'storybook/internal/$1'`) + content.replace(/from \'core\/dist\/(.*)\'/g, `from 'storybook/internal/$1'`) ); }) ); diff --git a/scripts/prepare/bundle.ts b/scripts/prepare/bundle.ts index 4e16fc41289d..28e994773c29 100755 --- a/scripts/prepare/bundle.ts +++ b/scripts/prepare/bundle.ts @@ -154,7 +154,7 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => { const content = await fs.readFile(file, 'utf-8'); await fs.writeFile( file, - content.replace(/from \'core\/dist\/(.*)\'/, `from 'storybook/internal/$1'`) + content.replace(/from \'core\/dist\/(.*)\'/g, `from 'storybook/internal/$1'`) ); }) );