webpack-assets-manifest 5.1.0 → 5.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +44 -42
- package/readme.md +63 -63
- package/src/WebpackAssetsManifest.js +209 -259
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webpack-assets-manifest",
|
|
3
|
-
"version": "5.1
|
|
3
|
+
"version": "5.2.1",
|
|
4
4
|
"description": "This Webpack plugin will generate a JSON file that matches the original filename with the hashed version.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -27,17 +27,7 @@
|
|
|
27
27
|
"files": [
|
|
28
28
|
"src"
|
|
29
29
|
],
|
|
30
|
-
"
|
|
31
|
-
"lint": "eslint --fix src test",
|
|
32
|
-
"typecheck": "tsc",
|
|
33
|
-
"spellcheck": "cspell --no-progress './{.github,src,test}/**/*.{js,json}' './*.{md,js}' './package.json'",
|
|
34
|
-
"test": "nyc mocha --colors",
|
|
35
|
-
"test:report": "nyc --reporter=lcov --reporter=text mocha --colors",
|
|
36
|
-
"lcov": "nyc report --reporter=text-lcov > coverage.lcov",
|
|
37
|
-
"pre-commit": "lint-staged",
|
|
38
|
-
"prepare": "husky install",
|
|
39
|
-
"prepublishOnly": "npm run spellcheck && npm run lint && npm test"
|
|
40
|
-
},
|
|
30
|
+
"packageManager": "pnpm@8.15.3+sha256.fc4a49bd609550a41e14d20efbce802a4b892aa4cac877322de2f0924f122991",
|
|
41
31
|
"lint-staged": {
|
|
42
32
|
"*.{js,json,md}": "cspell lint --no-progress --no-summary --no-must-find-files",
|
|
43
33
|
"*.js": "eslint --fix"
|
|
@@ -50,46 +40,58 @@
|
|
|
50
40
|
"name": "Eric King",
|
|
51
41
|
"url": "http://webdeveric.com/"
|
|
52
42
|
},
|
|
43
|
+
"prettier": "@webdeveric/prettier-config",
|
|
53
44
|
"dependencies": {
|
|
54
|
-
"chalk": "^4.
|
|
55
|
-
"deepmerge": "^4.
|
|
56
|
-
"lockfile": "^1.0",
|
|
57
|
-
"lodash.get": "^4.
|
|
58
|
-
"lodash.has": "^4.
|
|
59
|
-
"schema-utils": "^3.0",
|
|
60
|
-
"tapable": "^2.
|
|
45
|
+
"chalk": "^4.1.2",
|
|
46
|
+
"deepmerge": "^4.3.1",
|
|
47
|
+
"lockfile": "^1.0.4",
|
|
48
|
+
"lodash.get": "^4.4.2",
|
|
49
|
+
"lodash.has": "^4.5.2",
|
|
50
|
+
"schema-utils": "^3.3.0",
|
|
51
|
+
"tapable": "^2.2.1"
|
|
61
52
|
},
|
|
62
53
|
"peerDependencies": {
|
|
63
54
|
"webpack": "^5.2.0"
|
|
64
55
|
},
|
|
65
56
|
"devDependencies": {
|
|
66
|
-
"@types/lodash.get": "^4.4.
|
|
67
|
-
"@types/lodash.has": "^4.5.
|
|
68
|
-
"@types/node": "^
|
|
69
|
-
"@types/tapable": "^2.2.
|
|
70
|
-
"@types/webpack-sources": "^3.2.
|
|
71
|
-
"@webdeveric/eslint-config": "^0.
|
|
72
|
-
"
|
|
73
|
-
"chai
|
|
57
|
+
"@types/lodash.get": "^4.4.9",
|
|
58
|
+
"@types/lodash.has": "^4.5.9",
|
|
59
|
+
"@types/node": "^20.11.20",
|
|
60
|
+
"@types/tapable": "^2.2.7",
|
|
61
|
+
"@types/webpack-sources": "^3.2.3",
|
|
62
|
+
"@webdeveric/eslint-config": "^0.4.0",
|
|
63
|
+
"@webdeveric/prettier-config": "^0.2.0",
|
|
64
|
+
"chai": "^4.4.1",
|
|
65
|
+
"chai-spies": "^1.1.0",
|
|
74
66
|
"compression-webpack-plugin": "^7.1.2",
|
|
75
67
|
"copy-webpack-plugin": "^8.1.1",
|
|
76
|
-
"cspell": "^
|
|
77
|
-
"css-loader": "^5.2.
|
|
78
|
-
"eslint": "^
|
|
68
|
+
"cspell": "^8.4.1",
|
|
69
|
+
"css-loader": "^5.2.7",
|
|
70
|
+
"eslint": "^8.57.0",
|
|
71
|
+
"eslint-config-prettier": "^9.1.0",
|
|
79
72
|
"file-loader": "^6.2.0",
|
|
80
|
-
"fs-extra": "^
|
|
81
|
-
"husky": "^
|
|
82
|
-
"lint-staged": "^
|
|
73
|
+
"fs-extra": "^11.2.0",
|
|
74
|
+
"husky": "^9.0.11",
|
|
75
|
+
"lint-staged": "^15.2.2",
|
|
83
76
|
"memory-fs": "^0.5.0",
|
|
84
|
-
"mini-css-extract-plugin": "^1.6.
|
|
85
|
-
"
|
|
86
|
-
"mocha": "^8.4.0",
|
|
77
|
+
"mini-css-extract-plugin": "^1.6.2",
|
|
78
|
+
"mocha": "^10.3.0",
|
|
87
79
|
"nyc": "^15.1.0",
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"webpack
|
|
80
|
+
"prettier": "^3.2.5",
|
|
81
|
+
"rimraf": "^5.0.5",
|
|
82
|
+
"superagent": "^8.1.2",
|
|
83
|
+
"typescript": "^5.3.3",
|
|
84
|
+
"webpack": "^5.90.3",
|
|
85
|
+
"webpack-dev-server": "^3.11.3",
|
|
93
86
|
"webpack-subresource-integrity": "^1.5.2"
|
|
87
|
+
},
|
|
88
|
+
"scripts": {
|
|
89
|
+
"lint": "eslint --fix src test",
|
|
90
|
+
"format": "prettier --write .",
|
|
91
|
+
"typecheck": "tsc --noEmit",
|
|
92
|
+
"spellcheck": "cspell --no-progress './{.github,src,test}/**/*.{js,json}' './*.{md,js}' './package.json'",
|
|
93
|
+
"test": "NODE_OPTIONS='--openssl-legacy-provider' nyc mocha --colors",
|
|
94
|
+
"test:report": "nyc --reporter=lcov --reporter=text mocha --colors",
|
|
95
|
+
"lcov": "nyc report --reporter=text-lcov > coverage.lcov"
|
|
94
96
|
}
|
|
95
|
-
}
|
|
97
|
+
}
|
package/readme.md
CHANGED
|
@@ -1,35 +1,41 @@
|
|
|
1
1
|
# Webpack Assets Manifest
|
|
2
2
|
|
|
3
|
-
[](https://github.com/webdeveric/webpack-assets-manifest/actions/workflows/node.js.yml)
|
|
4
4
|
[](https://codecov.io/gh/webdeveric/webpack-assets-manifest)
|
|
5
|
-
[](https://david-dm.org/webdeveric/webpack-assets-manifest)
|
|
6
|
-
[](https://david-dm.org/webdeveric/webpack-assets-manifest?type=dev)
|
|
7
5
|
|
|
8
6
|
This webpack plugin will generate a JSON file that matches the original filename with the hashed version.
|
|
9
7
|
|
|
10
8
|
## Installation
|
|
11
9
|
|
|
12
10
|
```shell
|
|
13
|
-
|
|
11
|
+
pnpm add -D webpack-assets-manifest
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
```shell
|
|
15
|
+
npm install webpack-assets-manifest -D
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```shell
|
|
19
|
+
yarn add webpack-assets-manifest -D
|
|
14
20
|
```
|
|
15
21
|
|
|
16
22
|
## New in version 5
|
|
17
23
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
24
|
+
- Compatible with webpack 5 only (5.1+ required).
|
|
25
|
+
- Supports finding [asset modules](https://webpack.js.org/guides/asset-modules/).
|
|
26
|
+
- Updated options schema to prevent additional properties. This helps with catching typos in option names.
|
|
27
|
+
- :warning: Updated default value of the `output` option to be `assets-manifest.json`.
|
|
22
28
|
This is to prevent confusion when working with [Web app manifests](https://developer.mozilla.org/en-US/docs/Web/Manifest) or [WebExtension manifests](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json).
|
|
23
|
-
|
|
29
|
+
|
|
24
30
|
## New in version 4
|
|
25
31
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
- Requires Node 10+.
|
|
33
|
+
- Compatible with webpack 4 only (4.40+ required).
|
|
34
|
+
- Added options: [`enabled`](#enabled), [`entrypointsUseAssets`](#entrypointsUseAssets), [`contextRelativeKeys`](#contextRelativeKeys).
|
|
35
|
+
- Updated [`writeToDisk`](#writeToDisk) option to default to `auto`.
|
|
36
|
+
- Use lock files for various operations.
|
|
37
|
+
- `done` hook is now an `AsyncSeriesHook`.
|
|
38
|
+
- :warning: The structure of the `entrypoints` data has been updated to include `preload` and `prefetch` assets. Assets for an entrypoint are now included in an `assets` property under the entrypoint.
|
|
33
39
|
|
|
34
40
|
Example:
|
|
35
41
|
|
|
@@ -38,22 +44,14 @@ npm install webpack-assets-manifest --save-dev
|
|
|
38
44
|
"entrypoints": {
|
|
39
45
|
"main": {
|
|
40
46
|
"assets": {
|
|
41
|
-
"css": [
|
|
42
|
-
|
|
43
|
-
],
|
|
44
|
-
"js": [
|
|
45
|
-
"main.js"
|
|
46
|
-
]
|
|
47
|
+
"css": ["main.css"],
|
|
48
|
+
"js": ["main.js"]
|
|
47
49
|
},
|
|
48
50
|
"prefetch": {
|
|
49
|
-
"js": [
|
|
50
|
-
"prefetch.js"
|
|
51
|
-
]
|
|
51
|
+
"js": ["prefetch.js"]
|
|
52
52
|
},
|
|
53
53
|
"preload": {
|
|
54
|
-
"js": [
|
|
55
|
-
"preload.js"
|
|
56
|
-
]
|
|
54
|
+
"js": ["preload.js"]
|
|
57
55
|
}
|
|
58
56
|
}
|
|
59
57
|
}
|
|
@@ -65,17 +63,17 @@ npm install webpack-assets-manifest --save-dev
|
|
|
65
63
|
In your webpack config, require the plugin then add an instance to the `plugins` array.
|
|
66
64
|
|
|
67
65
|
```js
|
|
68
|
-
const path = require(
|
|
69
|
-
const WebpackAssetsManifest = require(
|
|
66
|
+
const path = require("path");
|
|
67
|
+
const WebpackAssetsManifest = require("webpack-assets-manifest");
|
|
70
68
|
|
|
71
69
|
module.exports = {
|
|
72
70
|
entry: {
|
|
73
71
|
// Your entry points
|
|
74
72
|
},
|
|
75
73
|
output: {
|
|
76
|
-
path: path.join(
|
|
77
|
-
filename:
|
|
78
|
-
chunkFilename:
|
|
74
|
+
path: path.join(__dirname, "dist"),
|
|
75
|
+
filename: "[name]-[hash].js",
|
|
76
|
+
chunkFilename: "[id]-[chunkhash].js",
|
|
79
77
|
},
|
|
80
78
|
module: {
|
|
81
79
|
// Your loader rules go here.
|
|
@@ -84,7 +82,7 @@ module.exports = {
|
|
|
84
82
|
new WebpackAssetsManifest({
|
|
85
83
|
// Options go here
|
|
86
84
|
}),
|
|
87
|
-
|
|
85
|
+
],
|
|
88
86
|
};
|
|
89
87
|
```
|
|
90
88
|
|
|
@@ -205,7 +203,7 @@ See the [sorted](examples/sorted.js) example.
|
|
|
205
203
|
new WebpackAssetsManifest({
|
|
206
204
|
sortManifest(a, b) {
|
|
207
205
|
// Return -1, 0, or 1
|
|
208
|
-
}
|
|
206
|
+
},
|
|
209
207
|
});
|
|
210
208
|
```
|
|
211
209
|
|
|
@@ -220,12 +218,12 @@ The default behavior is to use the existing keys/values without modification.
|
|
|
220
218
|
|
|
221
219
|
```js
|
|
222
220
|
new WebpackAssetsManifest({
|
|
223
|
-
output:
|
|
224
|
-
merge: true
|
|
221
|
+
output: "/path/to/manifest.json",
|
|
222
|
+
merge: true,
|
|
225
223
|
});
|
|
226
224
|
```
|
|
227
225
|
|
|
228
|
-
If you need to customize during merge, use `merge: 'customize'`.
|
|
226
|
+
If you need to customize during merge, use `merge: 'customize'`.
|
|
229
227
|
|
|
230
228
|
If you want to know if `customize` was called when merging with an existing manifest, you can check `manifest.isMerging`.
|
|
231
229
|
|
|
@@ -258,7 +256,7 @@ When using a string, it will be the value prefix. One common use is to prefix yo
|
|
|
258
256
|
|
|
259
257
|
```js
|
|
260
258
|
const manifest = new WebpackAssetsManifest({
|
|
261
|
-
publicPath:
|
|
259
|
+
publicPath: "//cdn.example.com",
|
|
262
260
|
});
|
|
263
261
|
```
|
|
264
262
|
|
|
@@ -266,11 +264,10 @@ If you'd like to have more control, use a function. See the [custom CDN](example
|
|
|
266
264
|
|
|
267
265
|
```js
|
|
268
266
|
const manifest = new WebpackAssetsManifest({
|
|
269
|
-
publicPath(filename, manifest)
|
|
270
|
-
{
|
|
267
|
+
publicPath(filename, manifest) {
|
|
271
268
|
// customize filename here
|
|
272
269
|
return filename;
|
|
273
|
-
}
|
|
270
|
+
},
|
|
274
271
|
});
|
|
275
272
|
```
|
|
276
273
|
|
|
@@ -389,14 +386,14 @@ This plugin is using hooks from [Tapable](https://github.com/webpack/tapable/).
|
|
|
389
386
|
|
|
390
387
|
The `apply`, `customize`, `transform`, and `done` options are automatically tapped into the appropriate hook.
|
|
391
388
|
|
|
392
|
-
| Name
|
|
393
|
-
|
|
|
394
|
-
| `apply`
|
|
395
|
-
| `customize`
|
|
396
|
-
| `transform`
|
|
397
|
-
| `done`
|
|
398
|
-
| `options`
|
|
399
|
-
| `afterOptions` | `SyncHook`
|
|
389
|
+
| Name | Type | Callback signature |
|
|
390
|
+
| -------------- | ------------------- | ---------------------------------------------- |
|
|
391
|
+
| `apply` | `SyncHook` | `function(manifest){}` |
|
|
392
|
+
| `customize` | `SyncWaterfallHook` | `function(entry, original, manifest, asset){}` |
|
|
393
|
+
| `transform` | `SyncWaterfallHook` | `function(assets, manifest){}` |
|
|
394
|
+
| `done` | `AsyncSeriesHook` | `async function(manifest, stats){}` |
|
|
395
|
+
| `options` | `SyncWaterfallHook` | `function(options){}` |
|
|
396
|
+
| `afterOptions` | `SyncHook` | `function(options){}` |
|
|
400
397
|
|
|
401
398
|
#### Tapping into hooks
|
|
402
399
|
|
|
@@ -408,32 +405,35 @@ See the [customized](examples/customized.js) and [transformed](examples/transfor
|
|
|
408
405
|
```js
|
|
409
406
|
const manifest = new WebpackAssetsManifest();
|
|
410
407
|
|
|
411
|
-
manifest.hooks.apply.tap(
|
|
408
|
+
manifest.hooks.apply.tap("YourPluginName", function (manifest) {
|
|
412
409
|
// Do something here
|
|
413
|
-
manifest.set(
|
|
410
|
+
manifest.set("some-key", "some-value");
|
|
414
411
|
});
|
|
415
412
|
|
|
416
|
-
manifest.hooks.customize.tap(
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
413
|
+
manifest.hooks.customize.tap(
|
|
414
|
+
"YourPluginName",
|
|
415
|
+
function (entry, original, manifest, asset) {
|
|
416
|
+
// customize entry here
|
|
417
|
+
return entry;
|
|
418
|
+
}
|
|
419
|
+
);
|
|
420
420
|
|
|
421
|
-
manifest.hooks.transform.tap(
|
|
421
|
+
manifest.hooks.transform.tap("YourPluginName", function (assets, manifest) {
|
|
422
422
|
// customize assets here
|
|
423
423
|
return assets;
|
|
424
424
|
});
|
|
425
425
|
|
|
426
|
-
manifest.hooks.options.tap(
|
|
426
|
+
manifest.hooks.options.tap("YourPluginName", function (options) {
|
|
427
427
|
// customize options here
|
|
428
428
|
return options;
|
|
429
429
|
});
|
|
430
430
|
|
|
431
|
-
manifest.hooks.done.tap(
|
|
431
|
+
manifest.hooks.done.tap("YourPluginName", function (manifest, stats) {
|
|
432
432
|
console.log(`The manifest has been written to ${manifest.getOutputPath()}`);
|
|
433
433
|
console.log(`${manifest}`);
|
|
434
434
|
});
|
|
435
435
|
|
|
436
|
-
manifest.hooks.done.tapPromise(
|
|
436
|
+
manifest.hooks.done.tapPromise("YourPluginName", async (manifest, stats) => {
|
|
437
437
|
await yourAsyncOperation();
|
|
438
438
|
});
|
|
439
439
|
```
|
|
@@ -445,7 +445,7 @@ new WebpackAssetsManifest({
|
|
|
445
445
|
done(manifest, stats) {
|
|
446
446
|
console.log(`The manifest has been written to ${manifest.getOutputPath()}`);
|
|
447
447
|
console.log(`${manifest}`);
|
|
448
|
-
}
|
|
448
|
+
},
|
|
449
449
|
});
|
|
450
450
|
```
|
|
451
451
|
|
|
@@ -464,7 +464,7 @@ If you want to write the manifest to another location, you can use `writeTo(dest
|
|
|
464
464
|
```js
|
|
465
465
|
new WebpackAssetsManifest({
|
|
466
466
|
async done(manifest) {
|
|
467
|
-
await manifest.writeTo(
|
|
468
|
-
}
|
|
467
|
+
await manifest.writeTo("/some/other/path/assets-manifest.json");
|
|
468
|
+
},
|
|
469
469
|
});
|
|
470
470
|
```
|
|
@@ -14,7 +14,6 @@ const get = require('lodash.get');
|
|
|
14
14
|
const has = require('lodash.has');
|
|
15
15
|
const { validate } = require('schema-utils');
|
|
16
16
|
const { AsyncSeriesHook, SyncHook, SyncWaterfallHook } = require('tapable');
|
|
17
|
-
const { Compilation, NormalModule, sources: { RawSource } } = require('webpack');
|
|
18
17
|
|
|
19
18
|
const {
|
|
20
19
|
maybeArrayWrap,
|
|
@@ -36,55 +35,52 @@ const optionsSchema = require('./options-schema.json');
|
|
|
36
35
|
const IS_MERGING = Symbol('isMerging');
|
|
37
36
|
const PLUGIN_NAME = 'WebpackAssetsManifest';
|
|
38
37
|
|
|
39
|
-
class WebpackAssetsManifest
|
|
40
|
-
{
|
|
38
|
+
class WebpackAssetsManifest {
|
|
41
39
|
/**
|
|
42
40
|
* @param {object} options - configuration options
|
|
43
41
|
* @constructor
|
|
44
42
|
*/
|
|
45
|
-
constructor(options = {})
|
|
46
|
-
{
|
|
43
|
+
constructor(options = {}) {
|
|
47
44
|
/**
|
|
48
45
|
* This is using hooks from {@link https://github.com/webpack/tapable Tapable}.
|
|
49
46
|
*/
|
|
50
47
|
this.hooks = Object.freeze({
|
|
51
|
-
apply: new SyncHook([
|
|
52
|
-
customize: new SyncWaterfallHook([
|
|
53
|
-
transform: new SyncWaterfallHook([
|
|
54
|
-
done: new AsyncSeriesHook([
|
|
55
|
-
options: new SyncWaterfallHook([
|
|
56
|
-
afterOptions: new SyncHook([
|
|
48
|
+
apply: new SyncHook(['manifest']),
|
|
49
|
+
customize: new SyncWaterfallHook(['entry', 'original', 'manifest', 'asset']),
|
|
50
|
+
transform: new SyncWaterfallHook(['assets', 'manifest']),
|
|
51
|
+
done: new AsyncSeriesHook(['manifest', 'stats']),
|
|
52
|
+
options: new SyncWaterfallHook(['options']),
|
|
53
|
+
afterOptions: new SyncHook(['options', 'manifest']),
|
|
57
54
|
});
|
|
58
55
|
|
|
59
56
|
this.hooks.transform.tap(PLUGIN_NAME, (assets, manifest) => {
|
|
60
57
|
const { sortManifest } = manifest.options;
|
|
61
58
|
|
|
62
|
-
return sortManifest
|
|
63
|
-
assets,
|
|
64
|
-
|
|
65
|
-
) : assets;
|
|
59
|
+
return sortManifest
|
|
60
|
+
? getSortedObject(assets, typeof sortManifest === 'function' ? sortManifest.bind(manifest) : undefined)
|
|
61
|
+
: assets;
|
|
66
62
|
});
|
|
67
63
|
|
|
68
64
|
this.hooks.afterOptions.tap(PLUGIN_NAME, (options, manifest) => {
|
|
69
|
-
manifest.options = Object.assign(
|
|
70
|
-
manifest.options.integrityHashes = filterHashes(
|
|
65
|
+
manifest.options = Object.assign(manifest.defaultOptions, options);
|
|
66
|
+
manifest.options.integrityHashes = filterHashes(manifest.options.integrityHashes);
|
|
71
67
|
|
|
72
68
|
validate(optionsSchema, manifest.options, { name: PLUGIN_NAME });
|
|
73
69
|
|
|
74
|
-
manifest.options.output = path.normalize(
|
|
70
|
+
manifest.options.output = path.normalize(manifest.options.output);
|
|
75
71
|
|
|
76
72
|
// Copy over any entries that may have been added to the manifest before apply() was called.
|
|
77
73
|
// If the same key exists in assets and options.assets, options.assets should be used.
|
|
78
74
|
manifest.assets = Object.assign(manifest.options.assets, manifest.assets, manifest.options.assets);
|
|
79
75
|
|
|
80
|
-
[
|
|
81
|
-
if (
|
|
82
|
-
manifest.hooks[
|
|
76
|
+
['apply', 'customize', 'transform', 'done'].forEach(hookName => {
|
|
77
|
+
if (typeof manifest.options[hookName] === 'function') {
|
|
78
|
+
manifest.hooks[hookName].tap(`${PLUGIN_NAME}.option.${hookName}`, manifest.options[hookName]);
|
|
83
79
|
}
|
|
84
80
|
});
|
|
85
81
|
});
|
|
86
82
|
|
|
87
|
-
this.options = Object.assign(
|
|
83
|
+
this.options = Object.assign(this.defaultOptions, options);
|
|
88
84
|
|
|
89
85
|
// This is what gets JSON stringified
|
|
90
86
|
this.assets = this.options.assets;
|
|
@@ -99,7 +95,7 @@ class WebpackAssetsManifest
|
|
|
99
95
|
this.compiler = null;
|
|
100
96
|
|
|
101
97
|
// Is a merge happening?
|
|
102
|
-
this[
|
|
98
|
+
this[IS_MERGING] = false;
|
|
103
99
|
}
|
|
104
100
|
|
|
105
101
|
/**
|
|
@@ -107,8 +103,7 @@ class WebpackAssetsManifest
|
|
|
107
103
|
*
|
|
108
104
|
* @param {object} compiler - The Webpack compiler object
|
|
109
105
|
*/
|
|
110
|
-
apply(compiler)
|
|
111
|
-
{
|
|
106
|
+
apply(compiler) {
|
|
112
107
|
this.compiler = compiler;
|
|
113
108
|
|
|
114
109
|
// Allow hooks to modify options
|
|
@@ -117,7 +112,7 @@ class WebpackAssetsManifest
|
|
|
117
112
|
// Ensure options contain defaults and are valid
|
|
118
113
|
this.hooks.afterOptions.call(this.options, this);
|
|
119
114
|
|
|
120
|
-
if (
|
|
115
|
+
if (!this.options.enabled) {
|
|
121
116
|
return;
|
|
122
117
|
}
|
|
123
118
|
|
|
@@ -131,7 +126,7 @@ class WebpackAssetsManifest
|
|
|
131
126
|
compiler.hooks.afterEmit.tapPromise(PLUGIN_NAME, this.handleAfterEmit.bind(this));
|
|
132
127
|
|
|
133
128
|
// The compilation has finished
|
|
134
|
-
compiler.hooks.done.tapPromise(PLUGIN_NAME, async stats => await this.hooks.done.promise(this, stats)
|
|
129
|
+
compiler.hooks.done.tapPromise(PLUGIN_NAME, async stats => await this.hooks.done.promise(this, stats));
|
|
135
130
|
|
|
136
131
|
// Setup is complete.
|
|
137
132
|
this.hooks.apply.call(this);
|
|
@@ -142,8 +137,7 @@ class WebpackAssetsManifest
|
|
|
142
137
|
*
|
|
143
138
|
* @return {object}
|
|
144
139
|
*/
|
|
145
|
-
get defaultOptions()
|
|
146
|
-
{
|
|
140
|
+
get defaultOptions() {
|
|
147
141
|
return {
|
|
148
142
|
enabled: true,
|
|
149
143
|
assets: Object.create(null),
|
|
@@ -158,10 +152,10 @@ class WebpackAssetsManifest
|
|
|
158
152
|
contextRelativeKeys: false,
|
|
159
153
|
|
|
160
154
|
// Hooks
|
|
161
|
-
apply: null,
|
|
155
|
+
apply: null, // After setup is complete
|
|
162
156
|
customize: null, // Customize each entry in the manifest
|
|
163
157
|
transform: null, // Transform the entire manifest
|
|
164
|
-
done: null,
|
|
158
|
+
done: null, // Compilation is done and the manifest has been written
|
|
165
159
|
|
|
166
160
|
// Include `compilation.entrypoints` in the manifest file
|
|
167
161
|
entrypoints: false,
|
|
@@ -170,7 +164,7 @@ class WebpackAssetsManifest
|
|
|
170
164
|
|
|
171
165
|
// https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity
|
|
172
166
|
integrity: false,
|
|
173
|
-
integrityHashes: [
|
|
167
|
+
integrityHashes: ['sha256', 'sha384', 'sha512'],
|
|
174
168
|
integrityPropertyName: 'integrity',
|
|
175
169
|
|
|
176
170
|
// Store arbitrary data here for use in customize/transform
|
|
@@ -183,9 +177,8 @@ class WebpackAssetsManifest
|
|
|
183
177
|
*
|
|
184
178
|
* @return {boolean}
|
|
185
179
|
*/
|
|
186
|
-
get isMerging()
|
|
187
|
-
|
|
188
|
-
return this[ IS_MERGING ];
|
|
180
|
+
get isMerging() {
|
|
181
|
+
return this[IS_MERGING];
|
|
189
182
|
}
|
|
190
183
|
|
|
191
184
|
/**
|
|
@@ -194,18 +187,17 @@ class WebpackAssetsManifest
|
|
|
194
187
|
* @param {string} filename
|
|
195
188
|
* @return {string}
|
|
196
189
|
*/
|
|
197
|
-
getExtension(filename)
|
|
198
|
-
|
|
199
|
-
if (! filename || typeof filename !== 'string') {
|
|
190
|
+
getExtension(filename) {
|
|
191
|
+
if (!filename || typeof filename !== 'string') {
|
|
200
192
|
return '';
|
|
201
193
|
}
|
|
202
194
|
|
|
203
|
-
filename = filename.split(/[?#]/)[
|
|
195
|
+
filename = filename.split(/[?#]/)[0];
|
|
204
196
|
|
|
205
197
|
if (this.options.fileExtRegex) {
|
|
206
198
|
const ext = filename.match(this.options.fileExtRegex);
|
|
207
199
|
|
|
208
|
-
return ext && ext.length ? ext[
|
|
200
|
+
return ext && ext.length ? ext[0] : '';
|
|
209
201
|
}
|
|
210
202
|
|
|
211
203
|
return path.extname(filename);
|
|
@@ -216,9 +208,8 @@ class WebpackAssetsManifest
|
|
|
216
208
|
*
|
|
217
209
|
* @return {string}
|
|
218
210
|
*/
|
|
219
|
-
fixKey(key)
|
|
220
|
-
|
|
221
|
-
return typeof key === 'string' ? key.replace( /\\/g, '/' ) : key;
|
|
211
|
+
fixKey(key) {
|
|
212
|
+
return typeof key === 'string' ? key.replace(/\\/g, '/') : key;
|
|
222
213
|
}
|
|
223
214
|
|
|
224
215
|
/**
|
|
@@ -228,9 +219,8 @@ class WebpackAssetsManifest
|
|
|
228
219
|
* @param {any} value
|
|
229
220
|
* @return {object} this
|
|
230
221
|
*/
|
|
231
|
-
setRaw(key, value)
|
|
232
|
-
|
|
233
|
-
this.assets[ key ] = value;
|
|
222
|
+
setRaw(key, value) {
|
|
223
|
+
this.assets[key] = value;
|
|
234
224
|
|
|
235
225
|
return this;
|
|
236
226
|
}
|
|
@@ -242,15 +232,14 @@ class WebpackAssetsManifest
|
|
|
242
232
|
* @param {any} value
|
|
243
233
|
* @return {object} this
|
|
244
234
|
*/
|
|
245
|
-
set(key, value)
|
|
246
|
-
|
|
247
|
-
if ( this.isMerging && this.options.merge !== 'customize' ) {
|
|
235
|
+
set(key, value) {
|
|
236
|
+
if (this.isMerging && this.options.merge !== 'customize') {
|
|
248
237
|
// Do not fix the key if merging since it should already be correct.
|
|
249
238
|
return this.setRaw(key, value);
|
|
250
239
|
}
|
|
251
240
|
|
|
252
241
|
const fixedKey = this.fixKey(key);
|
|
253
|
-
const publicPath = this.getPublicPath(
|
|
242
|
+
const publicPath = this.getPublicPath(value);
|
|
254
243
|
|
|
255
244
|
const entry = this.hooks.customize.call(
|
|
256
245
|
{
|
|
@@ -266,29 +255,29 @@ class WebpackAssetsManifest
|
|
|
266
255
|
);
|
|
267
256
|
|
|
268
257
|
// Allow the entry to be skipped
|
|
269
|
-
if (
|
|
258
|
+
if (entry === false) {
|
|
270
259
|
return this;
|
|
271
260
|
}
|
|
272
261
|
|
|
273
262
|
// Use the customized values
|
|
274
|
-
if (
|
|
263
|
+
if (isObject(entry)) {
|
|
275
264
|
let { key = fixedKey, value = publicPath } = entry;
|
|
276
265
|
|
|
277
266
|
// If the integrity should be returned but the entry value was
|
|
278
267
|
// not customized lets do that now so it includes both.
|
|
279
|
-
if (
|
|
268
|
+
if (value === publicPath && this.options.integrity) {
|
|
280
269
|
value = {
|
|
281
270
|
src: value,
|
|
282
271
|
integrity: get(this, `currentAsset.info.${this.options.integrityPropertyName}`, ''),
|
|
283
272
|
};
|
|
284
273
|
}
|
|
285
274
|
|
|
286
|
-
return this.setRaw(
|
|
275
|
+
return this.setRaw(key, value);
|
|
287
276
|
}
|
|
288
277
|
|
|
289
278
|
warn.once(`Unexpected customize() return type: ${varType(entry)}`);
|
|
290
279
|
|
|
291
|
-
return this.setRaw(
|
|
280
|
+
return this.setRaw(fixedKey, publicPath);
|
|
292
281
|
}
|
|
293
282
|
|
|
294
283
|
/**
|
|
@@ -297,8 +286,7 @@ class WebpackAssetsManifest
|
|
|
297
286
|
* @param {string} key
|
|
298
287
|
* @return {boolean}
|
|
299
288
|
*/
|
|
300
|
-
has(key)
|
|
301
|
-
{
|
|
289
|
+
has(key) {
|
|
302
290
|
return has(this.assets, key) || has(this.assets, this.fixKey(key));
|
|
303
291
|
}
|
|
304
292
|
|
|
@@ -309,9 +297,8 @@ class WebpackAssetsManifest
|
|
|
309
297
|
* @param {any} defaultValue
|
|
310
298
|
* @return {*}
|
|
311
299
|
*/
|
|
312
|
-
get(key, defaultValue = undefined)
|
|
313
|
-
|
|
314
|
-
return this.assets[ key ] || this.assets[ this.fixKey(key) ] || defaultValue;
|
|
300
|
+
get(key, defaultValue = undefined) {
|
|
301
|
+
return this.assets[key] || this.assets[this.fixKey(key)] || defaultValue;
|
|
315
302
|
}
|
|
316
303
|
|
|
317
304
|
/**
|
|
@@ -320,16 +307,15 @@ class WebpackAssetsManifest
|
|
|
320
307
|
* @param {string} key
|
|
321
308
|
* @return {boolean}
|
|
322
309
|
*/
|
|
323
|
-
delete(key)
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
return (delete this.assets[ key ]);
|
|
310
|
+
delete(key) {
|
|
311
|
+
if (has(this.assets, key)) {
|
|
312
|
+
return delete this.assets[key];
|
|
327
313
|
}
|
|
328
314
|
|
|
329
315
|
key = this.fixKey(key);
|
|
330
316
|
|
|
331
|
-
if (
|
|
332
|
-
return
|
|
317
|
+
if (has(this.assets, key)) {
|
|
318
|
+
return delete this.assets[key];
|
|
333
319
|
}
|
|
334
320
|
|
|
335
321
|
return false;
|
|
@@ -342,13 +328,12 @@ class WebpackAssetsManifest
|
|
|
342
328
|
* @param {Set} hmrFiles - Set of HMR files
|
|
343
329
|
* @return {object}
|
|
344
330
|
*/
|
|
345
|
-
processAssetsByChunkName(
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
.
|
|
350
|
-
|
|
351
|
-
this.assetNames.set( chunkName + this.getExtension( filename ), filename );
|
|
331
|
+
processAssetsByChunkName(assets, hmrFiles = new Set()) {
|
|
332
|
+
Object.keys(assets).forEach(chunkName => {
|
|
333
|
+
maybeArrayWrap(assets[chunkName])
|
|
334
|
+
.filter(filename => !hmrFiles.has(filename)) // Remove hot module replacement files
|
|
335
|
+
.forEach(filename => {
|
|
336
|
+
this.assetNames.set(chunkName + this.getExtension(filename), filename);
|
|
352
337
|
});
|
|
353
338
|
});
|
|
354
339
|
|
|
@@ -360,8 +345,7 @@ class WebpackAssetsManifest
|
|
|
360
345
|
*
|
|
361
346
|
* @return {object}
|
|
362
347
|
*/
|
|
363
|
-
toJSON()
|
|
364
|
-
{
|
|
348
|
+
toJSON() {
|
|
365
349
|
// This is the last chance to modify the data before the manifest file gets created.
|
|
366
350
|
return this.hooks.transform.call(this.assets, this);
|
|
367
351
|
}
|
|
@@ -371,42 +355,41 @@ class WebpackAssetsManifest
|
|
|
371
355
|
*
|
|
372
356
|
* @return {string}
|
|
373
357
|
*/
|
|
374
|
-
toString()
|
|
375
|
-
{
|
|
358
|
+
toString() {
|
|
376
359
|
return JSON.stringify(this, this.options.replacer, this.options.space) || '{}';
|
|
377
360
|
}
|
|
378
361
|
|
|
379
362
|
/**
|
|
380
363
|
* Merge data if the output file already exists
|
|
381
364
|
*/
|
|
382
|
-
maybeMerge()
|
|
383
|
-
|
|
384
|
-
if ( this.options.merge ) {
|
|
365
|
+
maybeMerge() {
|
|
366
|
+
if (this.options.merge) {
|
|
385
367
|
try {
|
|
386
|
-
this[
|
|
368
|
+
this[IS_MERGING] = true;
|
|
387
369
|
|
|
388
|
-
const data = JSON.parse(
|
|
370
|
+
const data = JSON.parse(fs.readFileSync(this.getOutputPath(), { encoding: 'utf8' }));
|
|
389
371
|
|
|
390
372
|
const deepmerge = require('deepmerge');
|
|
391
373
|
|
|
392
374
|
const arrayMerge = (_destArray, srcArray) => srcArray;
|
|
393
375
|
|
|
394
|
-
for (
|
|
395
|
-
if (
|
|
376
|
+
for (const [key, oldValue] of Object.entries(data)) {
|
|
377
|
+
if (this.has(key)) {
|
|
396
378
|
const currentValue = this.get(key);
|
|
397
379
|
|
|
398
|
-
if (
|
|
399
|
-
const newValue = deepmerge(
|
|
380
|
+
if (isObject(oldValue) && isObject(currentValue)) {
|
|
381
|
+
const newValue = deepmerge(oldValue, currentValue, { arrayMerge });
|
|
400
382
|
|
|
401
|
-
this.set(
|
|
383
|
+
this.set(key, newValue);
|
|
402
384
|
}
|
|
403
385
|
} else {
|
|
404
|
-
this.set(
|
|
386
|
+
this.set(key, oldValue);
|
|
405
387
|
}
|
|
406
388
|
}
|
|
407
|
-
} catch (err) {
|
|
389
|
+
} catch (err) {
|
|
390
|
+
// eslint-disable-line
|
|
408
391
|
} finally {
|
|
409
|
-
this[
|
|
392
|
+
this[IS_MERGING] = false;
|
|
410
393
|
}
|
|
411
394
|
}
|
|
412
395
|
}
|
|
@@ -416,33 +399,30 @@ class WebpackAssetsManifest
|
|
|
416
399
|
*
|
|
417
400
|
* @param {object} compilation
|
|
418
401
|
*/
|
|
419
|
-
async emitAssetsManifest(compilation)
|
|
420
|
-
{
|
|
402
|
+
async emitAssetsManifest(compilation) {
|
|
421
403
|
const outputPath = this.getOutputPath();
|
|
422
404
|
|
|
423
405
|
const output = this.getManifestPath(
|
|
424
406
|
compilation,
|
|
425
|
-
this.inDevServer()
|
|
426
|
-
path.basename(
|
|
427
|
-
path.relative(
|
|
407
|
+
this.inDevServer()
|
|
408
|
+
? path.basename(this.options.output)
|
|
409
|
+
: path.relative(compilation.compiler.outputPath, outputPath),
|
|
428
410
|
);
|
|
429
411
|
|
|
430
|
-
if (
|
|
431
|
-
await lock(
|
|
412
|
+
if (this.options.merge) {
|
|
413
|
+
await lock(outputPath);
|
|
432
414
|
}
|
|
433
415
|
|
|
434
416
|
this.maybeMerge();
|
|
435
417
|
|
|
436
|
-
compilation.emitAsset(
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
},
|
|
442
|
-
);
|
|
418
|
+
compilation.emitAsset(output, new compilation.compiler.webpack.sources.RawSource(this.toString(), false), {
|
|
419
|
+
assetsManifest: true,
|
|
420
|
+
generated: true,
|
|
421
|
+
generatedBy: [PLUGIN_NAME],
|
|
422
|
+
});
|
|
443
423
|
|
|
444
|
-
if (
|
|
445
|
-
await unlock(
|
|
424
|
+
if (this.options.merge) {
|
|
425
|
+
await unlock(outputPath);
|
|
446
426
|
}
|
|
447
427
|
}
|
|
448
428
|
|
|
@@ -451,8 +431,7 @@ class WebpackAssetsManifest
|
|
|
451
431
|
*
|
|
452
432
|
* @param {*} compilation
|
|
453
433
|
*/
|
|
454
|
-
handleProcessAssetsAnalyse(
|
|
455
|
-
{
|
|
434
|
+
handleProcessAssetsAnalyse(compilation /* , assets */) {
|
|
456
435
|
const { contextRelativeKeys } = this.options;
|
|
457
436
|
const { assetsInfo, chunkGraph, chunks, compiler, codeGenerationResults } = compilation;
|
|
458
437
|
|
|
@@ -463,13 +442,11 @@ class WebpackAssetsManifest
|
|
|
463
442
|
for (const module of modules) {
|
|
464
443
|
const codeGenData = codeGenerationResults.get(module, chunk.runtime).data;
|
|
465
444
|
|
|
466
|
-
const {
|
|
467
|
-
assetInfo = codeGenData.get('assetInfo'),
|
|
468
|
-
filename = codeGenData.get('filename'),
|
|
469
|
-
} = module.buildInfo;
|
|
445
|
+
const { assetInfo = codeGenData.get('assetInfo'), filename = codeGenData.get('filename') } = module.buildInfo;
|
|
470
446
|
|
|
471
447
|
const info = Object.assign(
|
|
472
448
|
{
|
|
449
|
+
rawRequest: module.rawRequest,
|
|
473
450
|
sourceFilename: path.relative(compiler.context, module.userRequest),
|
|
474
451
|
},
|
|
475
452
|
assetInfo,
|
|
@@ -478,9 +455,9 @@ class WebpackAssetsManifest
|
|
|
478
455
|
assetsInfo.set(filename, info);
|
|
479
456
|
|
|
480
457
|
this.assetNames.set(
|
|
481
|
-
contextRelativeKeys
|
|
482
|
-
info.sourceFilename
|
|
483
|
-
path.join(
|
|
458
|
+
contextRelativeKeys
|
|
459
|
+
? info.sourceFilename
|
|
460
|
+
: path.join(path.dirname(filename), path.basename(module.userRequest)),
|
|
484
461
|
filename,
|
|
485
462
|
);
|
|
486
463
|
}
|
|
@@ -495,16 +472,15 @@ class WebpackAssetsManifest
|
|
|
495
472
|
*
|
|
496
473
|
* @param {Object[]} assets
|
|
497
474
|
*/
|
|
498
|
-
processStatsAssets(assets)
|
|
499
|
-
{
|
|
475
|
+
processStatsAssets(assets) {
|
|
500
476
|
const { contextRelativeKeys } = this.options;
|
|
501
477
|
|
|
502
|
-
assets.forEach(
|
|
503
|
-
if (
|
|
478
|
+
assets.forEach(asset => {
|
|
479
|
+
if (asset.name && asset.info.sourceFilename) {
|
|
504
480
|
this.assetNames.set(
|
|
505
|
-
contextRelativeKeys
|
|
506
|
-
asset.info.sourceFilename
|
|
507
|
-
path.join(
|
|
481
|
+
contextRelativeKeys
|
|
482
|
+
? asset.info.sourceFilename
|
|
483
|
+
: path.join(path.dirname(asset.name), path.basename(asset.info.sourceFilename)),
|
|
508
484
|
asset.name,
|
|
509
485
|
);
|
|
510
486
|
}
|
|
@@ -518,20 +494,18 @@ class WebpackAssetsManifest
|
|
|
518
494
|
*
|
|
519
495
|
* @returns {object}
|
|
520
496
|
*/
|
|
521
|
-
getCompilationAssets(
|
|
497
|
+
getCompilationAssets(compilation) {
|
|
522
498
|
const hmrFiles = new Set();
|
|
523
499
|
|
|
524
|
-
const assets = compilation.getAssets().filter(
|
|
525
|
-
asset
|
|
526
|
-
|
|
527
|
-
hmrFiles.add( asset.name );
|
|
500
|
+
const assets = compilation.getAssets().filter(asset => {
|
|
501
|
+
if (asset.info.hotModuleReplacement) {
|
|
502
|
+
hmrFiles.add(asset.name);
|
|
528
503
|
|
|
529
|
-
|
|
530
|
-
|
|
504
|
+
return false;
|
|
505
|
+
}
|
|
531
506
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
);
|
|
507
|
+
return !asset.info.assetsManifest;
|
|
508
|
+
});
|
|
535
509
|
|
|
536
510
|
return {
|
|
537
511
|
assets,
|
|
@@ -544,8 +518,7 @@ class WebpackAssetsManifest
|
|
|
544
518
|
*
|
|
545
519
|
* @param {object} compilation
|
|
546
520
|
*/
|
|
547
|
-
async handleProcessAssetsReport(
|
|
548
|
-
{
|
|
521
|
+
async handleProcessAssetsReport(compilation) {
|
|
549
522
|
// Look in DefaultStatsPresetPlugin.js for options
|
|
550
523
|
const stats = compilation.getStats().toJson({
|
|
551
524
|
all: false,
|
|
@@ -556,83 +529,74 @@ class WebpackAssetsManifest
|
|
|
556
529
|
chunkGroupChildren: this.options.entrypoints,
|
|
557
530
|
});
|
|
558
531
|
|
|
559
|
-
const { assets, hmrFiles } = this.getCompilationAssets(
|
|
532
|
+
const { assets, hmrFiles } = this.getCompilationAssets(compilation);
|
|
560
533
|
|
|
561
|
-
this.processStatsAssets(
|
|
534
|
+
this.processStatsAssets(stats.assets);
|
|
562
535
|
|
|
563
|
-
this.processAssetsByChunkName(
|
|
536
|
+
this.processAssetsByChunkName(stats.assetsByChunkName, hmrFiles);
|
|
564
537
|
|
|
565
|
-
const findAssetKeys = findMapKeysByValue(
|
|
538
|
+
const findAssetKeys = findMapKeysByValue(this.assetNames);
|
|
566
539
|
|
|
567
540
|
const { contextRelativeKeys } = this.options;
|
|
568
541
|
|
|
569
|
-
for (
|
|
570
|
-
const sourceFilenames = findAssetKeys(
|
|
542
|
+
for (const asset of assets) {
|
|
543
|
+
const sourceFilenames = findAssetKeys(asset.name);
|
|
571
544
|
|
|
572
|
-
if (
|
|
545
|
+
if (!sourceFilenames.length) {
|
|
573
546
|
const { sourceFilename } = asset.info;
|
|
574
|
-
const name = sourceFilename
|
|
575
|
-
|
|
576
|
-
|
|
547
|
+
const name = sourceFilename
|
|
548
|
+
? contextRelativeKeys
|
|
549
|
+
? sourceFilename
|
|
550
|
+
: path.basename(sourceFilename)
|
|
551
|
+
: asset.name;
|
|
577
552
|
|
|
578
|
-
sourceFilenames.push(
|
|
553
|
+
sourceFilenames.push(name);
|
|
579
554
|
}
|
|
580
555
|
|
|
581
|
-
sourceFilenames.forEach(
|
|
556
|
+
sourceFilenames.forEach(key => {
|
|
582
557
|
this.currentAsset = asset;
|
|
583
558
|
|
|
584
|
-
this.set(
|
|
559
|
+
this.set(key, asset.name);
|
|
585
560
|
|
|
586
561
|
this.currentAsset = null;
|
|
587
562
|
});
|
|
588
563
|
}
|
|
589
564
|
|
|
590
|
-
if (
|
|
591
|
-
const removeHMR = file => !
|
|
565
|
+
if (this.options.entrypoints) {
|
|
566
|
+
const removeHMR = file => !hmrFiles.has(file);
|
|
592
567
|
const getExtensionGroup = file => this.getExtension(file).substring(1).toLowerCase();
|
|
593
568
|
const getAssetOrFilename = file => {
|
|
594
|
-
const asset = this.options.entrypointsUseAssets
|
|
595
|
-
this.assets[
|
|
596
|
-
undefined;
|
|
569
|
+
const asset = this.options.entrypointsUseAssets
|
|
570
|
+
? this.assets[findAssetKeys(file).pop()] || this.assets[file]
|
|
571
|
+
: undefined;
|
|
597
572
|
|
|
598
|
-
return asset ? asset : this.getPublicPath(
|
|
573
|
+
return asset ? asset : this.getPublicPath(file);
|
|
599
574
|
};
|
|
600
575
|
|
|
601
576
|
const entrypoints = Object.create(null);
|
|
602
577
|
|
|
603
|
-
for (
|
|
604
|
-
entrypoints[
|
|
605
|
-
assets: group(
|
|
606
|
-
entrypoint.getFiles().filter( removeHMR ),
|
|
607
|
-
getExtensionGroup,
|
|
608
|
-
getAssetOrFilename,
|
|
609
|
-
),
|
|
578
|
+
for (const [name, entrypoint] of compilation.entrypoints) {
|
|
579
|
+
entrypoints[name] = {
|
|
580
|
+
assets: group(entrypoint.getFiles().filter(removeHMR), getExtensionGroup, getAssetOrFilename),
|
|
610
581
|
};
|
|
611
582
|
|
|
612
583
|
// This contains preload and prefetch
|
|
613
|
-
const { childAssets } = stats.namedChunkGroups[
|
|
584
|
+
const { childAssets } = stats.namedChunkGroups[name];
|
|
614
585
|
|
|
615
|
-
for (
|
|
616
|
-
entrypoints[
|
|
617
|
-
assets.filter( removeHMR ),
|
|
618
|
-
getExtensionGroup,
|
|
619
|
-
getAssetOrFilename,
|
|
620
|
-
);
|
|
586
|
+
for (const [property, assets] of Object.entries(childAssets)) {
|
|
587
|
+
entrypoints[name][property] = group(assets.filter(removeHMR), getExtensionGroup, getAssetOrFilename);
|
|
621
588
|
}
|
|
622
589
|
}
|
|
623
590
|
|
|
624
|
-
if (
|
|
625
|
-
for (
|
|
626
|
-
this.setRaw(
|
|
591
|
+
if (this.options.entrypointsKey === false) {
|
|
592
|
+
for (const key in entrypoints) {
|
|
593
|
+
this.setRaw(key, entrypoints[key]);
|
|
627
594
|
}
|
|
628
595
|
} else {
|
|
629
|
-
this.setRaw(
|
|
630
|
-
this.options.entrypointsKey,
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
...entrypoints,
|
|
634
|
-
},
|
|
635
|
-
);
|
|
596
|
+
this.setRaw(this.options.entrypointsKey, {
|
|
597
|
+
...this.get(this.options.entrypointsKey),
|
|
598
|
+
...entrypoints,
|
|
599
|
+
});
|
|
636
600
|
}
|
|
637
601
|
}
|
|
638
602
|
|
|
@@ -646,9 +610,8 @@ class WebpackAssetsManifest
|
|
|
646
610
|
* @param {string} filename
|
|
647
611
|
* @return {string}
|
|
648
612
|
*/
|
|
649
|
-
getManifestPath(compilation, filename)
|
|
650
|
-
|
|
651
|
-
return compilation.getPath( filename, { chunk: { name: 'assets-manifest' }, filename: 'assets-manifest.json' } );
|
|
613
|
+
getManifestPath(compilation, filename) {
|
|
614
|
+
return compilation.getPath(filename, { chunk: { name: 'assets-manifest' }, filename: 'assets-manifest.json' });
|
|
652
615
|
}
|
|
653
616
|
|
|
654
617
|
/**
|
|
@@ -656,29 +619,26 @@ class WebpackAssetsManifest
|
|
|
656
619
|
*
|
|
657
620
|
* @param {string} destination
|
|
658
621
|
*/
|
|
659
|
-
async writeTo(destination)
|
|
660
|
-
|
|
661
|
-
await lock( destination );
|
|
622
|
+
async writeTo(destination) {
|
|
623
|
+
await lock(destination);
|
|
662
624
|
|
|
663
|
-
await fs.promises.mkdir(
|
|
625
|
+
await fs.promises.mkdir(path.dirname(destination), { recursive: true });
|
|
664
626
|
|
|
665
|
-
await fs.promises.writeFile(
|
|
627
|
+
await fs.promises.writeFile(destination, this.toString());
|
|
666
628
|
|
|
667
|
-
await unlock(
|
|
629
|
+
await unlock(destination);
|
|
668
630
|
}
|
|
669
631
|
|
|
670
|
-
clear()
|
|
671
|
-
{
|
|
632
|
+
clear() {
|
|
672
633
|
// Delete properties instead of setting to {} so that the variable reference
|
|
673
634
|
// is maintained incase the `assets` is being shared in multi-compiler mode.
|
|
674
|
-
Object.keys(
|
|
635
|
+
Object.keys(this.assets).forEach(key => delete this.assets[key]);
|
|
675
636
|
}
|
|
676
637
|
|
|
677
638
|
/**
|
|
678
639
|
* Cleanup before running Webpack
|
|
679
640
|
*/
|
|
680
|
-
handleWatchRun()
|
|
681
|
-
{
|
|
641
|
+
handleWatchRun() {
|
|
682
642
|
this.clear();
|
|
683
643
|
}
|
|
684
644
|
|
|
@@ -688,24 +648,23 @@ class WebpackAssetsManifest
|
|
|
688
648
|
* @param {object} compilation
|
|
689
649
|
* @return {boolean}
|
|
690
650
|
*/
|
|
691
|
-
shouldWriteToDisk(compilation)
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
const wdsWriteToDisk = get( compilation, 'options.devServer.writeToDisk' );
|
|
651
|
+
shouldWriteToDisk(compilation) {
|
|
652
|
+
if (this.options.writeToDisk === 'auto') {
|
|
653
|
+
if (this.inDevServer()) {
|
|
654
|
+
const wdsWriteToDisk = get(compilation, 'options.devServer.writeToDisk');
|
|
696
655
|
|
|
697
|
-
if (
|
|
656
|
+
if (wdsWriteToDisk === true) {
|
|
698
657
|
return false;
|
|
699
658
|
}
|
|
700
659
|
|
|
701
|
-
const manifestPath = this.getManifestPath(
|
|
660
|
+
const manifestPath = this.getManifestPath(compilation, this.getOutputPath());
|
|
702
661
|
|
|
703
|
-
if (
|
|
662
|
+
if (typeof wdsWriteToDisk === 'function' && wdsWriteToDisk(manifestPath) === true) {
|
|
704
663
|
return false;
|
|
705
664
|
}
|
|
706
665
|
|
|
707
666
|
// Return true if the manifest output is above the compiler outputPath.
|
|
708
|
-
return path.relative(
|
|
667
|
+
return path.relative(this.compiler.outputPath, manifestPath).startsWith('..');
|
|
709
668
|
}
|
|
710
669
|
|
|
711
670
|
return false;
|
|
@@ -719,10 +678,9 @@ class WebpackAssetsManifest
|
|
|
719
678
|
*
|
|
720
679
|
* @param {object} compilation - the Webpack compilation object
|
|
721
680
|
*/
|
|
722
|
-
async handleAfterEmit(compilation)
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
await this.writeTo( this.getManifestPath( compilation, this.getOutputPath() ) );
|
|
681
|
+
async handleAfterEmit(compilation) {
|
|
682
|
+
if (this.shouldWriteToDisk(compilation)) {
|
|
683
|
+
await this.writeTo(this.getManifestPath(compilation, this.getOutputPath()));
|
|
726
684
|
}
|
|
727
685
|
}
|
|
728
686
|
|
|
@@ -733,25 +691,26 @@ class WebpackAssetsManifest
|
|
|
733
691
|
* @param {object} loaderContext
|
|
734
692
|
* @param {object} module
|
|
735
693
|
*/
|
|
736
|
-
handleNormalModuleLoader(compilation, loaderContext, module)
|
|
737
|
-
|
|
738
|
-
const { emitFile } = loaderContext;
|
|
694
|
+
handleNormalModuleLoader(compilation, loaderContext, module) {
|
|
695
|
+
const emitFile = loaderContext.emitFile.bind(module);
|
|
739
696
|
const { contextRelativeKeys } = this.options;
|
|
740
697
|
|
|
741
698
|
// assetInfo parameter was added in Webpack 4.40.0
|
|
742
699
|
loaderContext.emitFile = (name, content, sourceMap, assetInfo) => {
|
|
743
|
-
const info = Object.assign(
|
|
744
|
-
|
|
745
|
-
|
|
700
|
+
const info = Object.assign(
|
|
701
|
+
{
|
|
702
|
+
rawRequest: module.rawRequest,
|
|
703
|
+
sourceFilename: path.relative(compilation.compiler.context, module.userRequest),
|
|
704
|
+
},
|
|
705
|
+
assetInfo,
|
|
706
|
+
);
|
|
746
707
|
|
|
747
708
|
this.assetNames.set(
|
|
748
|
-
contextRelativeKeys ?
|
|
749
|
-
info.sourceFilename :
|
|
750
|
-
path.join( path.dirname(name), path.basename(module.userRequest) ),
|
|
709
|
+
contextRelativeKeys ? info.sourceFilename : path.join(path.dirname(name), path.basename(module.userRequest)),
|
|
751
710
|
name,
|
|
752
711
|
);
|
|
753
712
|
|
|
754
|
-
|
|
713
|
+
emitFile(name, content, sourceMap, info);
|
|
755
714
|
};
|
|
756
715
|
}
|
|
757
716
|
|
|
@@ -760,16 +719,16 @@ class WebpackAssetsManifest
|
|
|
760
719
|
*
|
|
761
720
|
* @param {object} compilation
|
|
762
721
|
*/
|
|
763
|
-
recordSubresourceIntegrity(
|
|
764
|
-
{
|
|
722
|
+
recordSubresourceIntegrity(compilation) {
|
|
765
723
|
const { integrityHashes, integrityPropertyName } = this.options;
|
|
766
724
|
|
|
767
|
-
for (
|
|
768
|
-
if (
|
|
725
|
+
for (const asset of compilation.getAssets()) {
|
|
726
|
+
if (!asset.info[integrityPropertyName]) {
|
|
769
727
|
// webpack-subresource-integrity stores the integrity hash on the source object.
|
|
770
|
-
asset.info[
|
|
728
|
+
asset.info[integrityPropertyName] =
|
|
729
|
+
asset.source[integrityPropertyName] || getSRIHash(integrityHashes, asset.source.source());
|
|
771
730
|
|
|
772
|
-
compilation.assetsInfo.set(
|
|
731
|
+
compilation.assetsInfo.set(asset.name, asset.info);
|
|
773
732
|
}
|
|
774
733
|
}
|
|
775
734
|
}
|
|
@@ -779,9 +738,8 @@ class WebpackAssetsManifest
|
|
|
779
738
|
*
|
|
780
739
|
* @param {object} compilation - the Webpack compilation object
|
|
781
740
|
*/
|
|
782
|
-
handleCompilation(compilation)
|
|
783
|
-
|
|
784
|
-
NormalModule.getCompilationHooks(compilation).loader.tap(
|
|
741
|
+
handleCompilation(compilation) {
|
|
742
|
+
compilation.compiler.webpack.NormalModule.getCompilationHooks(compilation).loader.tap(
|
|
785
743
|
PLUGIN_NAME,
|
|
786
744
|
this.handleNormalModuleLoader.bind(this, compilation),
|
|
787
745
|
);
|
|
@@ -789,7 +747,7 @@ class WebpackAssetsManifest
|
|
|
789
747
|
compilation.hooks.processAssets.tap(
|
|
790
748
|
{
|
|
791
749
|
name: PLUGIN_NAME,
|
|
792
|
-
stage: Compilation.
|
|
750
|
+
stage: compilation.compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ANALYSE,
|
|
793
751
|
},
|
|
794
752
|
this.handleProcessAssetsAnalyse.bind(this, compilation),
|
|
795
753
|
);
|
|
@@ -800,13 +758,12 @@ class WebpackAssetsManifest
|
|
|
800
758
|
*
|
|
801
759
|
* @param {object} compilation - the Webpack compilation object
|
|
802
760
|
*/
|
|
803
|
-
handleThisCompilation(compilation)
|
|
804
|
-
|
|
805
|
-
if ( this.options.integrity ) {
|
|
761
|
+
handleThisCompilation(compilation) {
|
|
762
|
+
if (this.options.integrity) {
|
|
806
763
|
compilation.hooks.processAssets.tap(
|
|
807
764
|
{
|
|
808
765
|
name: PLUGIN_NAME,
|
|
809
|
-
stage: Compilation.PROCESS_ASSETS_STAGE_ANALYSE,
|
|
766
|
+
stage: compilation.compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ANALYSE,
|
|
810
767
|
},
|
|
811
768
|
this.recordSubresourceIntegrity.bind(this, compilation),
|
|
812
769
|
);
|
|
@@ -815,7 +772,7 @@ class WebpackAssetsManifest
|
|
|
815
772
|
compilation.hooks.processAssets.tapPromise(
|
|
816
773
|
{
|
|
817
774
|
name: PLUGIN_NAME,
|
|
818
|
-
stage: Compilation.PROCESS_ASSETS_STAGE_REPORT,
|
|
775
|
+
stage: compilation.compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT,
|
|
819
776
|
},
|
|
820
777
|
this.handleProcessAssetsReport.bind(this, compilation),
|
|
821
778
|
);
|
|
@@ -829,15 +786,14 @@ class WebpackAssetsManifest
|
|
|
829
786
|
*
|
|
830
787
|
* @return {boolean}
|
|
831
788
|
*/
|
|
832
|
-
inDevServer()
|
|
833
|
-
|
|
834
|
-
const [ , webpackPath, serve ] = process.argv;
|
|
789
|
+
inDevServer() {
|
|
790
|
+
const [, webpackPath, serve] = process.argv;
|
|
835
791
|
|
|
836
|
-
if (
|
|
792
|
+
if (serve === 'serve' && webpackPath && path.basename(webpackPath) === 'webpack') {
|
|
837
793
|
return true;
|
|
838
794
|
}
|
|
839
795
|
|
|
840
|
-
if (
|
|
796
|
+
if (process.argv.some(arg => arg.includes('webpack-dev-server'))) {
|
|
841
797
|
return true;
|
|
842
798
|
}
|
|
843
799
|
|
|
@@ -849,28 +805,27 @@ class WebpackAssetsManifest
|
|
|
849
805
|
*
|
|
850
806
|
* @return {string} path to manifest file
|
|
851
807
|
*/
|
|
852
|
-
getOutputPath()
|
|
853
|
-
|
|
854
|
-
if ( path.isAbsolute( this.options.output ) ) {
|
|
808
|
+
getOutputPath() {
|
|
809
|
+
if (path.isAbsolute(this.options.output)) {
|
|
855
810
|
return this.options.output;
|
|
856
811
|
}
|
|
857
812
|
|
|
858
|
-
if (
|
|
813
|
+
if (!this.compiler) {
|
|
859
814
|
return '';
|
|
860
815
|
}
|
|
861
816
|
|
|
862
|
-
if (
|
|
863
|
-
let outputPath = get(
|
|
817
|
+
if (this.inDevServer()) {
|
|
818
|
+
let outputPath = get(this, 'compiler.options.devServer.outputPath', get(this, 'compiler.outputPath', '/'));
|
|
864
819
|
|
|
865
|
-
if (
|
|
820
|
+
if (outputPath === '/') {
|
|
866
821
|
warn.once('Please use an absolute path in options.output when using webpack-dev-server.');
|
|
867
|
-
outputPath = get(
|
|
822
|
+
outputPath = get(this, 'compiler.context', process.cwd());
|
|
868
823
|
}
|
|
869
824
|
|
|
870
|
-
return path.resolve(
|
|
825
|
+
return path.resolve(outputPath, this.options.output);
|
|
871
826
|
}
|
|
872
827
|
|
|
873
|
-
return path.resolve(
|
|
828
|
+
return path.resolve(this.compiler.outputPath, this.options.output);
|
|
874
829
|
}
|
|
875
830
|
|
|
876
831
|
/**
|
|
@@ -878,24 +833,20 @@ class WebpackAssetsManifest
|
|
|
878
833
|
*
|
|
879
834
|
* @param {string} filename
|
|
880
835
|
*/
|
|
881
|
-
getPublicPath(filename)
|
|
882
|
-
|
|
883
|
-
if ( typeof filename === 'string' ) {
|
|
836
|
+
getPublicPath(filename) {
|
|
837
|
+
if (typeof filename === 'string') {
|
|
884
838
|
const { publicPath } = this.options;
|
|
885
839
|
|
|
886
|
-
if (
|
|
887
|
-
return publicPath(
|
|
840
|
+
if (typeof publicPath === 'function') {
|
|
841
|
+
return publicPath(filename, this);
|
|
888
842
|
}
|
|
889
843
|
|
|
890
|
-
if (
|
|
891
|
-
return url.resolve(
|
|
844
|
+
if (typeof publicPath === 'string') {
|
|
845
|
+
return url.resolve(publicPath, filename);
|
|
892
846
|
}
|
|
893
847
|
|
|
894
|
-
if (
|
|
895
|
-
return url.resolve(
|
|
896
|
-
get( this, 'compiler.options.output.publicPath', '' ),
|
|
897
|
-
filename,
|
|
898
|
-
);
|
|
848
|
+
if (publicPath === true) {
|
|
849
|
+
return url.resolve(get(this, 'compiler.options.output.publicPath', ''), filename);
|
|
899
850
|
}
|
|
900
851
|
}
|
|
901
852
|
|
|
@@ -909,8 +860,7 @@ class WebpackAssetsManifest
|
|
|
909
860
|
* @param {boolean} raw - Should the proxy use `setRaw` instead of `set`?
|
|
910
861
|
* @return {Proxy}
|
|
911
862
|
*/
|
|
912
|
-
getProxy(raw = false)
|
|
913
|
-
{
|
|
863
|
+
getProxy(raw = false) {
|
|
914
864
|
const setMethod = raw ? 'setRaw' : 'set';
|
|
915
865
|
|
|
916
866
|
const handler = {
|
|
@@ -921,7 +871,7 @@ class WebpackAssetsManifest
|
|
|
921
871
|
return target.get(property);
|
|
922
872
|
},
|
|
923
873
|
set(target, property, value) {
|
|
924
|
-
return target[
|
|
874
|
+
return target[setMethod](property, value).has(property);
|
|
925
875
|
},
|
|
926
876
|
deleteProperty(target, property) {
|
|
927
877
|
return target.delete(property);
|