From 81f8f2c1f0a2e1a9639ec6902f6b23b2e8aef8f3 Mon Sep 17 00:00:00 2001 From: Barak Date: Sun, 11 Feb 2024 23:19:31 +0200 Subject: [PATCH] fix: ensure directory when running in generating types in esbuild --- packages/cli/src/build-single-file.ts | 7 ++++++- packages/esbuild/src/stylable-esbuild-plugin.ts | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/build-single-file.ts b/packages/cli/src/build-single-file.ts index 8004d6328..10498f7a6 100644 --- a/packages/cli/src/build-single-file.ts +++ b/packages/cli/src/build-single-file.ts @@ -268,6 +268,7 @@ export function buildDTS({ relative, dirname, isAbsolute, + mkdirSync, }: { res: StylableResults; targetFilePath: string; @@ -279,13 +280,17 @@ export function buildDTS({ relative: (from: string, to: string) => string; dirname: (p: string) => string; isAbsolute: (p: string) => boolean; + mkdirSync?: (path: string, { recursive }: { recursive: boolean }) => void; }) { const dtsContent = generateDTSContent(res); const dtsPath = targetFilePath + '.d.ts'; generated.add(dtsPath); outputLogs.push('output .d.ts'); - + tryRun( + () => mkdirSync?.(dirname(dtsPath), { recursive: true }), + `Ensure directory: ${dirname(dtsPath)}` + ); tryRun(() => writeFileSync(dtsPath, dtsContent), `Write File Error: ${dtsPath}`); // .d.ts.map diff --git a/packages/esbuild/src/stylable-esbuild-plugin.ts b/packages/esbuild/src/stylable-esbuild-plugin.ts index 99c397736..4d98ba861 100644 --- a/packages/esbuild/src/stylable-esbuild-plugin.ts +++ b/packages/esbuild/src/stylable-esbuild-plugin.ts @@ -360,6 +360,7 @@ export const stylablePlugin = (initialPluginOptions: ESBuildOptions = {}): Plugi relative, dirname, isAbsolute, + mkdirSync: fs.mkdirSync, }); } }