Skip to content

Commit

Permalink
Expose isIncluded in module info (#4305)
Browse files Browse the repository at this point in the history
Co-authored-by: Lukas Taegert-Atkinson <lukastaegert@users.noreply.github.com>
  • Loading branch information
william57m and lukastaegert committed Dec 18, 2021
1 parent 5d43bd6 commit a37e6ad
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/05-plugin-development.md
Expand Up @@ -665,6 +665,7 @@ type ModuleInfo = {
ast: ESTree.Program; // the parsed abstract syntax tree if available
isEntry: boolean; // is this a user- or plugin-defined entry point
isExternal: boolean; // for external modules that are referenced but not included in the graph
isIncluded: boolean | null; // is the module included after tree-shaking, `null` if external or not yet available
importedIds: string[]; // the module ids statically imported by this module
importers: string[]; // the ids of all modules that statically import this module
dynamicallyImportedIds: string[]; // the module ids imported by this module via dynamic import()
Expand Down
1 change: 1 addition & 0 deletions src/ExternalModule.ts
Expand Up @@ -55,6 +55,7 @@ export default class ExternalModule {
},
isEntry: false,
isExternal: true,
isIncluded: null,
meta,
syntheticNamedExports: false
};
Expand Down
7 changes: 7 additions & 0 deletions src/Module.ts
Expand Up @@ -46,6 +46,7 @@ import {
TransformModuleJSON
} from './rollup/types';
import { EMPTY_OBJECT } from './utils/blank';
import { BuildPhase } from './utils/buildPhase';
import {
augmentCodeLocation,
errAmbiguousExternalNamespaces,
Expand Down Expand Up @@ -287,6 +288,12 @@ export default class Module {
},
isEntry,
isExternal: false,
get isIncluded() {
if (module.graph.phase !== BuildPhase.GENERATE) {
return null;
}
return module.isIncluded();
},
meta,
syntheticNamedExports
};
Expand Down
1 change: 1 addition & 0 deletions src/rollup/types.d.ts
Expand Up @@ -169,6 +169,7 @@ interface ModuleInfo {
importers: readonly string[];
isEntry: boolean;
isExternal: boolean;
isIncluded: boolean | null;
meta: CustomPluginOptions;
syntheticNamedExports: boolean | string;
}
Expand Down
Expand Up @@ -80,6 +80,7 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
});
Expand Down Expand Up @@ -139,6 +140,7 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
});
Expand Down
Expand Up @@ -76,6 +76,7 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
});
Expand Down Expand Up @@ -135,6 +136,7 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
});
Expand Down
Expand Up @@ -124,6 +124,7 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
});
Expand Down Expand Up @@ -218,6 +219,7 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
});
Expand Down Expand Up @@ -311,6 +313,7 @@ module.exports = {
importers: [],
isEntry: false,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
});
Expand Down
Expand Up @@ -75,6 +75,7 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
});
Expand Down Expand Up @@ -134,6 +135,7 @@ module.exports = {
importers: [],
isEntry: false,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
});
Expand Down
Expand Up @@ -110,6 +110,7 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
},
Expand All @@ -126,6 +127,7 @@ module.exports = {
importers: [getId('main')],
isEntry: false,
isExternal: true,
isIncluded: null,
meta: {},
syntheticNamedExports: false
},
Expand Down Expand Up @@ -155,6 +157,7 @@ module.exports = {
importers: [getId('dynamic'), getId('main')],
isEntry: false,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
},
Expand Down Expand Up @@ -227,6 +230,7 @@ module.exports = {
importers: [],
isEntry: false,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
}
Expand Down
4 changes: 4 additions & 0 deletions test/function/samples/manual-chunks-info/_config.js
Expand Up @@ -109,6 +109,7 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
},
Expand All @@ -125,6 +126,7 @@ module.exports = {
importers: [getId('main')],
isEntry: false,
isExternal: true,
isIncluded: null,
meta: {},
syntheticNamedExports: false
},
Expand Down Expand Up @@ -154,6 +156,7 @@ module.exports = {
importers: [getId('dynamic'), getId('main')],
isEntry: false,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
},
Expand Down Expand Up @@ -226,6 +229,7 @@ module.exports = {
importers: [],
isEntry: false,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
}
Expand Down
2 changes: 2 additions & 0 deletions test/function/samples/module-parsed-hook/_config.js
Expand Up @@ -58,6 +58,7 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
isIncluded: false,
meta: {},
syntheticNamedExports: false
},
Expand Down Expand Up @@ -103,6 +104,7 @@ module.exports = {
importers: [ID_MAIN],
isEntry: false,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
}
Expand Down
5 changes: 5 additions & 0 deletions test/function/samples/plugin-module-information/_config.js
Expand Up @@ -27,6 +27,7 @@ module.exports = {
importers: [],
isEntry: id === ID_MAIN,
isExternal: false,
isIncluded: null,
meta: {},
syntheticNamedExports: false
});
Expand Down Expand Up @@ -172,6 +173,7 @@ module.exports = {
importers: [],
isEntry: true,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
},
Expand Down Expand Up @@ -248,6 +250,7 @@ module.exports = {
importers: [ID_MAIN, ID_NESTED],
isEntry: false,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
},
Expand All @@ -264,6 +267,7 @@ module.exports = {
importers: [ID_FOO],
isEntry: false,
isExternal: true,
isIncluded: null,
meta: {},
syntheticNamedExports: false
},
Expand Down Expand Up @@ -343,6 +347,7 @@ module.exports = {
importers: [],
isEntry: false,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
}
Expand Down
2 changes: 2 additions & 0 deletions test/function/samples/preload-module/_config.js
Expand Up @@ -42,6 +42,7 @@ module.exports = {
importers: [],
isEntry: false,
isExternal: false,
isIncluded: null,
meta: { testPlugin: 'first' },
syntheticNamedExports: false
});
Expand Down Expand Up @@ -79,6 +80,7 @@ module.exports = {
importers: [ID_MAIN],
isEntry: false,
isExternal: false,
isIncluded: true,
meta: {},
syntheticNamedExports: false
});
Expand Down

0 comments on commit a37e6ad

Please sign in to comment.