diff --git a/src/plugin/typescript-plugin.ts b/src/plugin/typescript-plugin.ts index 75738bd1..1f50016b 100644 --- a/src/plugin/typescript-plugin.ts +++ b/src/plugin/typescript-plugin.ts @@ -464,6 +464,8 @@ export default function typescriptRollupPlugin(pluginInputOptions: Partial { Object.values(bundle).forEach(value => { if (isOutputChunk(value)) { Object.keys(value.modules).forEach(fileName => bundledFilenames.add(path.normalize(fileName))); - } else { + } else if ("fileName" in value) { bundledFilenames.add(path.normalize(value.fileName)); } }); diff --git a/test/babel.test.ts b/test/babel.test.ts index 8675236f..ff13075a 100644 --- a/test/babel.test.ts +++ b/test/babel.test.ts @@ -508,7 +508,7 @@ test.serial("Will use the proper @babel/runtime/helpers/esm helpers when format } } = bundle; - t.deepEqual(formatCode(file.code), formatCode(`import '@babel/runtime/helpers/esm/typeof';`)); + t.true(formatCode(file.code).includes(`@babel/runtime/helpers/esm/typeof`)); }); test.serial("Will use the proper @babel/runtime/helpers helpers when format is CJS. #1", withTypeScript, async (t, {typescript}) => { diff --git a/test/deferred-assets.test.ts b/test/deferred-assets.test.ts new file mode 100644 index 00000000..830793c8 --- /dev/null +++ b/test/deferred-assets.test.ts @@ -0,0 +1,46 @@ +import test from "ava"; +import {withTypeScript} from "./util/ts-macro"; +import {generateRollupBundle} from "./setup/setup-rollup"; +import {formatCode} from "./util/format-code"; + +test.serial("Won't break when other plugins declare deferred assets. #1", withTypeScript, async (t, {typescript}) => { + let asset: string | undefined; + + const bundle = await generateRollupBundle( + [ + { + entry: true, + fileName: "index.ts", + text: `\ + console.log('whatever');` + } + ], + { + typescript, + postPlugins: [ + { + name: "my-plugin", + buildStart() { + asset = this.emitFile({ + type: "asset", + fileName: "test.txt" + }); + }, + generateBundle() { + this.setAssetSource(asset!, "whatever"); + } + } + ] + } + ); + const { + declarations: [file] + } = bundle; + + t.deepEqual( + formatCode(file.code), + formatCode(`\ + export {}; + `) + ); +}); diff --git a/test/setup/test-file.ts b/test/setup/test-file.ts index 4172f56c..829e8593 100644 --- a/test/setup/test-file.ts +++ b/test/setup/test-file.ts @@ -63,18 +63,20 @@ export function createBuiltInModuleTestFiles(...modules: ("fs" | "globals" | "bu } ` }, - { - entry: false, - fileName: "node_modules/@types/node/index.d.ts", - text: ` - /// - ` - }, - ...modules.map(module => ({ - entry: false, - fileName: `node_modules/@types/node/${module}.d.ts`, - text: fsWorker.readFile(path.native.join(nodeTypesDir, `${module}.d.ts`)) ?? "" - })) + ...modules.flatMap(module => [ + { + entry: false, + fileName: "node_modules/@types/node/index.d.ts", + text: ` + /// + ` + }, + { + entry: false, + fileName: `node_modules/@types/node/${module}.d.ts`, + text: fsWorker.readFile(path.native.join(nodeTypesDir, `${module}.d.ts`)) ?? "" + } + ]) ]; }