Skip to content

Commit

Permalink
fix: support multiple environment
Browse files Browse the repository at this point in the history
  • Loading branch information
9aoy committed Aug 6, 2024
1 parent 5ac9308 commit f34a8f6
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions packages/plugin-dts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const pluginDts = (options: pluginDtsOptions): RsbuildPlugin => ({
options.distPath =
options.distPath ?? config.output?.distPath?.root ?? 'dist';

let dtsPromise: Promise<void>;
const dtsPromises: Promise<void>[] = [];

api.onBeforeEnvironmentCompile(
({ isWatch, isFirstCompile, environment }) => {
Expand All @@ -55,19 +55,21 @@ export const pluginDts = (options: pluginDtsOptions): RsbuildPlugin => ({

childProcess.send(dtsGenOptions);

dtsPromise = new Promise((resolve, reject) => {
childProcess.on('message', (message) => {
if (message === 'success') {
resolve();
} else if (message === 'error') {
reject(
new Error(
`Error occurred in ${environment.name} dts generation`,
),
);
}
});
});
dtsPromises.push(
new Promise((resolve, reject) => {
childProcess.on('message', (message) => {
if (message === 'success') {
resolve();
} else if (message === 'error') {
reject(
new Error(
`Error occurred in ${environment.name} dts generation`,
),
);
}
});
}),
);
},
);

Expand All @@ -76,7 +78,7 @@ export const pluginDts = (options: pluginDtsOptions): RsbuildPlugin => ({
return;
}

await dtsPromise;
await Promise.all(dtsPromises);
});
},
});

0 comments on commit f34a8f6

Please sign in to comment.