Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Timeless0911 committed Jul 30, 2024
1 parent 1bb588e commit c1ea1b6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 12 deletions.
1 change: 0 additions & 1 deletion e2e/cases/dts/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ test('dts when bundle: true', async () => {
const fixturePath = join(__dirname, 'bundle');
const { entryFiles } = await buildAndGetResults(fixturePath, 'dts');

console.log('entryFiles: ', entryFiles);
expect(entryFiles.esm!.endsWith('index.d.ts')).toEqual(true);
expect(entryFiles.cjs!.endsWith('index.d.ts')).toEqual(true);
});
12 changes: 3 additions & 9 deletions packages/plugin-dts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const pluginDts = (

setup(api) {
const { tsconfigPath, distPath, bundle, isWatch } = options;
let isFirstCompile = true;

api.onBeforeBuild(async ({ environments }) => {
const cwd = process.cwd();
Expand All @@ -48,7 +47,7 @@ export const pluginDts = (
const declarationDir = getDeclarationDir(bundle, distPath) || './dist';
let entry = '';

if (options.bundle === true) {
if (bundle === true) {
const entrySourcePath = join(
cwd,
environments.esm?.config.source.entry?.main as string,
Expand All @@ -62,7 +61,7 @@ export const pluginDts = (
}

const onComplete = (isSuccess: boolean) => {
if (isSuccess && options.bundle === true) {
if (isSuccess && bundle === true) {
bundleDts({
cwd,
outDir,
Expand All @@ -79,23 +78,18 @@ export const pluginDts = (
rootDir,
declarationDir,
},
isFirstCompile,
onComplete,
isWatch,
);

if (options.bundle === true && !isWatch) {
if (bundle === true && !isWatch) {
bundleDts({
cwd,
outDir,
entry,
tsconfigPath,
});
}

if (isFirstCompile) {
isFirstCompile = false;
}
});
},
});
3 changes: 1 addition & 2 deletions packages/plugin-dts/src/tsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export type emitDtsOptions = {

export function emitDts(
options: emitDtsOptions,
isFirstCompile: boolean,
onComplete: (isSuccess: boolean) => void,
isWatch = false,
) {
Expand Down Expand Up @@ -73,7 +72,7 @@ export function emitDts(
}

logger.info('TypeScript compilation succeeded\n');
} else if (isFirstCompile) {
} else {
const createProgram = ts.createSemanticDiagnosticsBuilderProgram;
const formatHost: ts.FormatDiagnosticsHost = {
getCanonicalFileName: (path) => path,
Expand Down

0 comments on commit c1ea1b6

Please sign in to comment.