From b85479ebd433ba1b17d4bc069fa29162baaa661e Mon Sep 17 00:00:00 2001 From: William Mura Date: Thu, 16 Dec 2021 10:09:19 -0800 Subject: [PATCH] Expose isIncluded in module info --- docs/05-plugin-development.md | 1 + src/ExternalModule.ts | 1 + src/Module.ts | 7 +++++++ src/rollup/types.d.ts | 1 + .../implicitly-dependent-emitted-entry/_config.js | 2 ++ .../implicitly-dependent-entry/_config.js | 2 ++ .../implicit-dependencies/multiple-dependencies/_config.js | 3 +++ .../implicit-dependencies/single-dependency/_config.js | 2 ++ .../samples/deprecated/manual-chunks-info/_config.js | 4 ++++ test/function/samples/manual-chunks-info/_config.js | 4 ++++ test/function/samples/module-parsed-hook/_config.js | 2 ++ test/function/samples/plugin-module-information/_config.js | 5 +++++ test/function/samples/preload-module/_config.js | 2 ++ 13 files changed, 36 insertions(+) diff --git a/docs/05-plugin-development.md b/docs/05-plugin-development.md index 239421e37a9..d67b216587b 100644 --- a/docs/05-plugin-development.md +++ b/docs/05-plugin-development.md @@ -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() diff --git a/src/ExternalModule.ts b/src/ExternalModule.ts index 434ac4e7a22..8a395b827df 100644 --- a/src/ExternalModule.ts +++ b/src/ExternalModule.ts @@ -55,6 +55,7 @@ export default class ExternalModule { }, isEntry: false, isExternal: true, + isIncluded: null, meta, syntheticNamedExports: false }; diff --git a/src/Module.ts b/src/Module.ts index 531cfe8bef7..9af5446b1e7 100644 --- a/src/Module.ts +++ b/src/Module.ts @@ -46,6 +46,7 @@ import { TransformModuleJSON } from './rollup/types'; import { EMPTY_OBJECT } from './utils/blank'; +import { BuildPhase } from './utils/buildPhase'; import { augmentCodeLocation, errAmbiguousExternalNamespaces, @@ -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 }; diff --git a/src/rollup/types.d.ts b/src/rollup/types.d.ts index a4458ef9058..1197dc41e8a 100644 --- a/src/rollup/types.d.ts +++ b/src/rollup/types.d.ts @@ -169,6 +169,7 @@ interface ModuleInfo { importers: readonly string[]; isEntry: boolean; isExternal: boolean; + isIncluded: boolean | null; meta: CustomPluginOptions; syntheticNamedExports: boolean | string; } diff --git a/test/chunking-form/samples/implicit-dependencies/implicitly-dependent-emitted-entry/_config.js b/test/chunking-form/samples/implicit-dependencies/implicitly-dependent-emitted-entry/_config.js index fe9919b5db9..a0d90878714 100644 --- a/test/chunking-form/samples/implicit-dependencies/implicitly-dependent-emitted-entry/_config.js +++ b/test/chunking-form/samples/implicit-dependencies/implicitly-dependent-emitted-entry/_config.js @@ -80,6 +80,7 @@ module.exports = { importers: [], isEntry: true, isExternal: false, + isIncluded: true, meta: {}, syntheticNamedExports: false }); @@ -139,6 +140,7 @@ module.exports = { importers: [], isEntry: true, isExternal: false, + isIncluded: true, meta: {}, syntheticNamedExports: false }); diff --git a/test/chunking-form/samples/implicit-dependencies/implicitly-dependent-entry/_config.js b/test/chunking-form/samples/implicit-dependencies/implicitly-dependent-entry/_config.js index 99999c335fc..897835fb6d0 100644 --- a/test/chunking-form/samples/implicit-dependencies/implicitly-dependent-entry/_config.js +++ b/test/chunking-form/samples/implicit-dependencies/implicitly-dependent-entry/_config.js @@ -76,6 +76,7 @@ module.exports = { importers: [], isEntry: true, isExternal: false, + isIncluded: true, meta: {}, syntheticNamedExports: false }); @@ -135,6 +136,7 @@ module.exports = { importers: [], isEntry: true, isExternal: false, + isIncluded: true, meta: {}, syntheticNamedExports: false }); diff --git a/test/chunking-form/samples/implicit-dependencies/multiple-dependencies/_config.js b/test/chunking-form/samples/implicit-dependencies/multiple-dependencies/_config.js index fdb0d9005fc..2d38a4c3fd6 100644 --- a/test/chunking-form/samples/implicit-dependencies/multiple-dependencies/_config.js +++ b/test/chunking-form/samples/implicit-dependencies/multiple-dependencies/_config.js @@ -124,6 +124,7 @@ module.exports = { importers: [], isEntry: true, isExternal: false, + isIncluded: true, meta: {}, syntheticNamedExports: false }); @@ -218,6 +219,7 @@ module.exports = { importers: [], isEntry: true, isExternal: false, + isIncluded: true, meta: {}, syntheticNamedExports: false }); @@ -311,6 +313,7 @@ module.exports = { importers: [], isEntry: false, isExternal: false, + isIncluded: true, meta: {}, syntheticNamedExports: false }); diff --git a/test/chunking-form/samples/implicit-dependencies/single-dependency/_config.js b/test/chunking-form/samples/implicit-dependencies/single-dependency/_config.js index 08b3d95c54d..26fab23a6d8 100644 --- a/test/chunking-form/samples/implicit-dependencies/single-dependency/_config.js +++ b/test/chunking-form/samples/implicit-dependencies/single-dependency/_config.js @@ -75,6 +75,7 @@ module.exports = { importers: [], isEntry: true, isExternal: false, + isIncluded: true, meta: {}, syntheticNamedExports: false }); @@ -134,6 +135,7 @@ module.exports = { importers: [], isEntry: false, isExternal: false, + isIncluded: true, meta: {}, syntheticNamedExports: false }); diff --git a/test/function/samples/deprecated/manual-chunks-info/_config.js b/test/function/samples/deprecated/manual-chunks-info/_config.js index 68c19d401c1..ac8ce09551e 100644 --- a/test/function/samples/deprecated/manual-chunks-info/_config.js +++ b/test/function/samples/deprecated/manual-chunks-info/_config.js @@ -110,6 +110,7 @@ module.exports = { importers: [], isEntry: true, isExternal: false, + isIncluded: true, meta: {}, syntheticNamedExports: false }, @@ -126,6 +127,7 @@ module.exports = { importers: [getId('main')], isEntry: false, isExternal: true, + isIncluded: null, meta: {}, syntheticNamedExports: false }, @@ -155,6 +157,7 @@ module.exports = { importers: [getId('dynamic'), getId('main')], isEntry: false, isExternal: false, + isIncluded: true, meta: {}, syntheticNamedExports: false }, @@ -227,6 +230,7 @@ module.exports = { importers: [], isEntry: false, isExternal: false, + isIncluded: true, meta: {}, syntheticNamedExports: false } diff --git a/test/function/samples/manual-chunks-info/_config.js b/test/function/samples/manual-chunks-info/_config.js index c95cef71aff..9639ec5fbb2 100644 --- a/test/function/samples/manual-chunks-info/_config.js +++ b/test/function/samples/manual-chunks-info/_config.js @@ -109,6 +109,7 @@ module.exports = { importers: [], isEntry: true, isExternal: false, + isIncluded: true, meta: {}, syntheticNamedExports: false }, @@ -125,6 +126,7 @@ module.exports = { importers: [getId('main')], isEntry: false, isExternal: true, + isIncluded: null, meta: {}, syntheticNamedExports: false }, @@ -154,6 +156,7 @@ module.exports = { importers: [getId('dynamic'), getId('main')], isEntry: false, isExternal: false, + isIncluded: true, meta: {}, syntheticNamedExports: false }, @@ -226,6 +229,7 @@ module.exports = { importers: [], isEntry: false, isExternal: false, + isIncluded: true, meta: {}, syntheticNamedExports: false } diff --git a/test/function/samples/module-parsed-hook/_config.js b/test/function/samples/module-parsed-hook/_config.js index ffe1a6c8b89..f0dae77c7d3 100644 --- a/test/function/samples/module-parsed-hook/_config.js +++ b/test/function/samples/module-parsed-hook/_config.js @@ -58,6 +58,7 @@ module.exports = { importers: [], isEntry: true, isExternal: false, + isIncluded: false, meta: {}, syntheticNamedExports: false }, @@ -103,6 +104,7 @@ module.exports = { importers: [ID_MAIN], isEntry: false, isExternal: false, + isIncluded: true, meta: {}, syntheticNamedExports: false } diff --git a/test/function/samples/plugin-module-information/_config.js b/test/function/samples/plugin-module-information/_config.js index 4daa0338a10..0b8f55f201a 100644 --- a/test/function/samples/plugin-module-information/_config.js +++ b/test/function/samples/plugin-module-information/_config.js @@ -27,6 +27,7 @@ module.exports = { importers: [], isEntry: id === ID_MAIN, isExternal: false, + isIncluded: null, meta: {}, syntheticNamedExports: false }); @@ -172,6 +173,7 @@ module.exports = { importers: [], isEntry: true, isExternal: false, + isIncluded: true, meta: {}, syntheticNamedExports: false }, @@ -248,6 +250,7 @@ module.exports = { importers: [ID_MAIN, ID_NESTED], isEntry: false, isExternal: false, + isIncluded: true, meta: {}, syntheticNamedExports: false }, @@ -264,6 +267,7 @@ module.exports = { importers: [ID_FOO], isEntry: false, isExternal: true, + isIncluded: null, meta: {}, syntheticNamedExports: false }, @@ -343,6 +347,7 @@ module.exports = { importers: [], isEntry: false, isExternal: false, + isIncluded: true, meta: {}, syntheticNamedExports: false } diff --git a/test/function/samples/preload-module/_config.js b/test/function/samples/preload-module/_config.js index f9326371ae0..9364c4b843f 100644 --- a/test/function/samples/preload-module/_config.js +++ b/test/function/samples/preload-module/_config.js @@ -42,6 +42,7 @@ module.exports = { importers: [], isEntry: false, isExternal: false, + isIncluded: null, meta: { testPlugin: 'first' }, syntheticNamedExports: false }); @@ -79,6 +80,7 @@ module.exports = { importers: [ID_MAIN], isEntry: false, isExternal: false, + isIncluded: true, meta: {}, syntheticNamedExports: false });