Skip to content

Commit

Permalink
Fix isIncluded error when using rollup-plugin-typescript2 (#4725)
Browse files Browse the repository at this point in the history
* Wait for this.load before closing bundle

* Support this.load after build without awaiting it

* Do not await this.load in build as that would be the job of the plugin
  • Loading branch information
lukastaegert committed Nov 27, 2022
1 parent 96a5ba4 commit 4ee9a20
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Module.ts
Expand Up @@ -685,8 +685,12 @@ export default class Module {
this.includeAllExports(false);
}

isIncluded(): boolean {
return this.ast!.included || this.namespace.included || this.importedFromNotTreeshaken;
isIncluded(): boolean | null {
// Modules where this.ast is missing have been loaded via this.load and are
// not yet fully processed, hence they cannot be included.
return (
this.ast && (this.ast.included || this.namespace.included || this.importedFromNotTreeshaken)
);
}

linkImports(): void {
Expand Down
23 changes: 23 additions & 0 deletions test/function/samples/preload-after-build/_config.js
@@ -0,0 +1,23 @@
const path = require('node:path');

module.exports = {
description: 'supports this.load() in buildEnd and renderStart',
options: {
plugins: [
{
name: 'test',
buildEnd() {
this.load({ id: path.join(__dirname, 'other2.js') });
},
moduleParsed({ id }) {
if (id.endsWith('main.js')) {
this.load({ id: path.join(__dirname, 'other1.js') });
}
},
renderStart() {
this.load({ id: path.join(__dirname, 'other3.js') });
}
}
]
}
};
1 change: 1 addition & 0 deletions test/function/samples/preload-after-build/main.js
@@ -0,0 +1 @@
assert.ok(true);
1 change: 1 addition & 0 deletions test/function/samples/preload-after-build/other1.js
@@ -0,0 +1 @@
assert.ok(true);
1 change: 1 addition & 0 deletions test/function/samples/preload-after-build/other2.js
@@ -0,0 +1 @@
assert.ok(true);
1 change: 1 addition & 0 deletions test/function/samples/preload-after-build/other3.js
@@ -0,0 +1 @@
assert.ok(true);

0 comments on commit 4ee9a20

Please sign in to comment.