Skip to content

Commit

Permalink
Add "isEntry" to "getModuleInfo"
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed May 13, 2019
1 parent e0ed3b9 commit d73d100
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/05-plugins.md
Expand Up @@ -360,6 +360,7 @@ Returns additional information about the module in question in the form
```
{
id: string, // the id of the module, for convenience
isEntry: boolean, // is this a user- or plugin-defined entry point
isExternal: boolean, // for external modules that are not included in the graph
importedIds: string[], // the module ids imported by this module
hasModuleSideEffects: boolean // are imports of this module included if nothing is imported from it
Expand Down
1 change: 1 addition & 0 deletions src/rollup/types.d.ts
Expand Up @@ -125,6 +125,7 @@ export interface PluginContext extends MinimalPluginContext {
hasModuleSideEffects: boolean;
id: string;
importedIds: string[];
isEntry: boolean;
isExternal: boolean;
};
/** @deprecated Use `this.resolve` instead */
Expand Down
11 changes: 7 additions & 4 deletions src/utils/pluginDriver.ts
@@ -1,5 +1,6 @@
import { EventEmitter } from 'events';
import { version as rollupVersion } from 'package.json';
import ExternalModule from '../ExternalModule';
import Graph from '../Graph';
import Module from '../Module';
import {
Expand Down Expand Up @@ -177,10 +178,12 @@ export function createPluginDriver(
return {
hasModuleSideEffects: foundModule.moduleSideEffects,
id: foundModule.id,
importedIds: foundModule.isExternal
? []
: (foundModule as Module).sources.map(id => (foundModule as Module).resolvedIds[id].id),
isExternal: !!foundModule.isExternal
importedIds:
foundModule instanceof ExternalModule
? []
: foundModule.sources.map(id => foundModule.resolvedIds[id].id),
isEntry: foundModule instanceof Module && foundModule.isEntryPoint,
isExternal: foundModule instanceof ExternalModule
};
},
meta: {
Expand Down
4 changes: 4 additions & 0 deletions test/function/samples/plugin-module-information/_config.js
Expand Up @@ -21,24 +21,28 @@ module.exports = {
hasModuleSideEffects: true,
id: ID_MAIN,
importedIds: [ID_FOO, ID_NESTED],
isEntry: true,
isExternal: false
});
assert.deepEqual(this.getModuleInfo(ID_FOO), {
hasModuleSideEffects: true,
id: ID_FOO,
importedIds: [ID_PATH],
isEntry: false,
isExternal: false
});
assert.deepEqual(this.getModuleInfo(ID_NESTED), {
hasModuleSideEffects: true,
id: ID_NESTED,
importedIds: [ID_FOO],
isEntry: false,
isExternal: false
});
assert.deepEqual(this.getModuleInfo(ID_PATH), {
hasModuleSideEffects: true,
id: ID_PATH,
importedIds: [],
isEntry: false,
isExternal: true
});
}
Expand Down

0 comments on commit d73d100

Please sign in to comment.