Skip to content

Commit

Permalink
Implement new APIs for inter-plugin communication (#3807)
Browse files Browse the repository at this point in the history
* Implement custom resolver options

* Add custom module meta information

* Test handling of external modules

* Cache module options

* Actually handle external modules

* Unify default logic

* Make `code` an optional property for the `transform` hook.

* Use an object with prototype as default for both custom options and meta info

* Add documentation

* Update dependencies

* Update docs/05-plugin-development.md

Co-authored-by: Lars den Bakker <larsdenbakker@gmail.com>

* Update docs/05-plugin-development.md

Co-authored-by: Lars den Bakker <larsdenbakker@gmail.com>

* Update docs/05-plugin-development.md

Co-authored-by: Lars den Bakker <larsdenbakker@gmail.com>

* Update docs/05-plugin-development.md

Co-authored-by: Lars den Bakker <larsdenbakker@gmail.com>

* return `null` instead of throwing when accessing a non-exiting module info, make module info lazy.

* Improve wording for the load hook

* Improve custom resoler options section

* Improve coverage

* Fix documentation links

Co-authored-by: Lars den Bakker <larsdenbakker@gmail.com>
  • Loading branch information
lukastaegert and LarsDenBakker committed Oct 8, 2020
1 parent 74e5081 commit 1ad8289
Show file tree
Hide file tree
Showing 63 changed files with 968 additions and 391 deletions.
201 changes: 184 additions & 17 deletions docs/05-plugin-development.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/999-big-list-of-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ manualChunks(id) {

Be aware that manual chunks can change the behaviour of the application if side-effects are triggered before the corresponding modules are actually used.

When using the function form, `manualChunks` will be passed an object as second parameter containing the functions `getModuleInfo` and `getModuleIds` that work the same way as [`this.getModuleInfo`](guide/en/#thisgetmoduleinfomoduleid-string--moduleinfo) and [`this.getModuleIds`](guide/en/#thisgetmoduleids--iterableiteratorstring) on the plugin context.
When using the function form, `manualChunks` will be passed an object as second parameter containing the functions `getModuleInfo` and `getModuleIds` that work the same way as [`this.getModuleInfo`](guide/en/#thisgetmoduleinfomoduleid-string--moduleinfo--null) and [`this.getModuleIds`](guide/en/#thisgetmoduleids--iterableiteratorstring) on the plugin context.

This can be used to dynamically determine into which manual chunk a module should be placed depending on its position in the module graph. For instance consider a scenario where you have a set of components, each of which dynamically imports a set of translated strings, i.e.

Expand Down
112 changes: 53 additions & 59 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"devDependencies": {
"@rollup/plugin-alias": "^3.1.1",
"@rollup/plugin-buble": "^0.21.3",
"@rollup/plugin-commonjs": "^15.0.0",
"@rollup/plugin-commonjs": "^15.1.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-replace": "^2.3.3",
Expand All @@ -75,7 +75,7 @@
"@types/require-relative": "^0.8.0",
"@types/signal-exit": "^3.0.0",
"@types/yargs-parser": "^15.0.0",
"acorn": "^8.0.1",
"acorn": "^8.0.3",
"acorn-class-fields": "^0.3.7",
"acorn-jsx": "^5.3.1",
"acorn-numeric-separator": "^0.3.6",
Expand All @@ -90,27 +90,27 @@
"date-time": "^3.1.0",
"es5-shim": "^4.5.14",
"es6-shim": "^0.35.5",
"eslint": "^7.9.0",
"eslint-plugin-import": "^2.22.0",
"eslint": "^7.10.0",
"eslint-plugin-import": "^2.22.1",
"execa": "^4.0.3",
"fixturify": "^2.1.0",
"hash.js": "^1.1.7",
"husky": "^4.3.0",
"is-reference": "^1.2.1",
"lint-staged": "^10.3.0",
"lint-staged": "^10.4.0",
"locate-character": "^2.0.5",
"magic-string": "^0.25.7",
"markdownlint-cli": "^0.23.2",
"markdownlint-cli": "^0.24.0",
"micromatch": "^4.0.2",
"mocha": "^8.1.3",
"node-fetch": "^2.6.1",
"nyc": "^15.1.0",
"prettier": "^2.1.2",
"pretty-bytes": "^5.4.1",
"pretty-ms": "^7.0.0",
"pretty-ms": "^7.0.1",
"require-relative": "^0.8.7",
"requirejs": "^2.3.6",
"rollup": "^2.26.11",
"rollup": "^2.28.2",
"rollup-plugin-license": "^2.2.0",
"rollup-plugin-string": "^3.0.0",
"rollup-plugin-terser": "^7.0.2",
Expand All @@ -124,12 +124,12 @@
"source-map-support": "^0.5.19",
"sourcemap-codec": "^1.4.8",
"systemjs": "^6.6.1",
"terser": "^5.3.1",
"terser": "^5.3.4",
"tslib": "^2.0.1",
"tslint": "^6.1.3",
"typescript": "^4.0.2",
"typescript": "^4.0.3",
"url-parse": "^1.4.7",
"yargs-parser": "^20.0.0"
"yargs-parser": "^20.2.1"
},
"files": [
"dist/**/*.js",
Expand Down
13 changes: 8 additions & 5 deletions src/ExternalModule.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import ExternalVariable from './ast/variables/ExternalVariable';
import { NormalizedInputOptions, NormalizedOutputOptions } from './rollup/types';
import {
CustomPluginOptions,
NormalizedInputOptions,
NormalizedOutputOptions
} from './rollup/types';
import { makeLegal } from './utils/identifierHelpers';
import { isAbsolute, normalize, relative } from './utils/path';

Expand All @@ -10,9 +14,7 @@ export default class ExternalModule {
dynamicImporters: string[] = [];
execIndex: number;
exportedVariables: Map<ExternalVariable, string>;
id: string;
importers: string[] = [];
moduleSideEffects: boolean | 'no-treeshake';
mostCommonSuggestion = 0;
namespaceVariableName = '';
nameSuggestions: { [name: string]: number };
Expand All @@ -25,8 +27,9 @@ export default class ExternalModule {

constructor(
private readonly options: NormalizedInputOptions,
id: string,
moduleSideEffects: boolean | 'no-treeshake'
public readonly id: string,
public moduleSideEffects: boolean | 'no-treeshake',
public meta: CustomPluginOptions
) {
this.id = id;
this.execIndex = Infinity;
Expand Down

0 comments on commit 1ad8289

Please sign in to comment.