webpack-federation-stats-plugin 1.1.0 → 1.1.2
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/.github/FUNDING.yml +1 -0
- package/README.md +10 -0
- package/{FederationStatsPlugin.js → index.js} +12 -24
- package/package.json +7 -7
- package/LICENSE +0 -21
- package/index.d.ts +0 -12
|
@@ -0,0 +1 @@
|
|
|
1
|
+
github: DanielAmenou
|
package/README.md
CHANGED
|
@@ -3,18 +3,17 @@ const PLUGIN_NAME = "FederationStatsPlugin"
|
|
|
3
3
|
const EXTENSION_REGEX = /\.[^/.]+$/
|
|
4
4
|
|
|
5
5
|
class FederationStatsPlugin {
|
|
6
|
-
constructor(options = {}) {
|
|
7
|
-
|
|
6
|
+
constructor(options = {fileName: "federation-stats.json"}) {
|
|
7
|
+
if (!options || !options.fileName) throw new Error("fileName option is required.")
|
|
8
|
+
this._options = options
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
apply(compiler) {
|
|
12
|
+
const logger = compiler.getInfrastructureLogger(PLUGIN_NAME)
|
|
11
13
|
const federationPlugin = compiler.options.plugins && compiler.options.plugins.find((plugin) => plugin.constructor.name === "ModuleFederationPlugin")
|
|
12
14
|
|
|
13
15
|
if (!federationPlugin) throw new Error("No ModuleFederationPlugin found.")
|
|
14
16
|
|
|
15
|
-
const appName = federationPlugin._options.name
|
|
16
|
-
|
|
17
|
-
// get exposed modules from the ModuleFederationPlugin
|
|
18
17
|
const exposedFiles = new Map(Object.entries(federationPlugin._options.exposes || {}).map(([k, v]) => (typeof v === "object" ? [v.import, k] : [v, k])))
|
|
19
18
|
|
|
20
19
|
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
@@ -25,9 +24,7 @@ class FederationStatsPlugin {
|
|
|
25
24
|
},
|
|
26
25
|
async () => {
|
|
27
26
|
const stats = compilation.getStats().toJson({})
|
|
28
|
-
|
|
29
|
-
const mfModules = stats.modules.filter((module) => module.issuerName === "container entry" && exposedFiles.has(module.name.replace(EXTENSION_REGEX, "")))
|
|
30
|
-
|
|
27
|
+
const modules = stats.modules.filter((module) => module.issuerName === "container entry" && exposedFiles.has(module.name.replace(EXTENSION_REGEX, "")))
|
|
31
28
|
const chunksReducer = (chunksArr, current) => {
|
|
32
29
|
current.siblings.forEach((s) => {
|
|
33
30
|
const chunk = stats.chunks.find((c) => c.id === s)
|
|
@@ -36,21 +33,17 @@ class FederationStatsPlugin {
|
|
|
36
33
|
current.files.forEach((f) => chunksArr.push(f))
|
|
37
34
|
return chunksArr
|
|
38
35
|
}
|
|
39
|
-
|
|
40
|
-
const chunks = mfModules.map((module) => {
|
|
36
|
+
const chunks = modules.map((module) => {
|
|
41
37
|
const exposedAs = exposedFiles.get(module.name.replace(EXTENSION_REGEX, ""))
|
|
42
|
-
const chunks = module.chunks
|
|
43
|
-
.map((chunkId) => stats.chunks.find((chunk) => chunk.id === chunkId))
|
|
44
|
-
.filter((chunk) => chunk.runtime.includes(appName))
|
|
45
|
-
.reduce(chunksReducer, [])
|
|
38
|
+
const chunks = module.chunks.map((chunkId) => stats.chunks.find((chunk) => chunk.id === chunkId)).reduce(chunksReducer, [])
|
|
46
39
|
return {
|
|
47
40
|
module: exposedAs,
|
|
48
41
|
chunks: chunks,
|
|
49
|
-
id: module.id
|
|
42
|
+
id: module.id
|
|
50
43
|
}
|
|
51
44
|
})
|
|
52
45
|
|
|
53
|
-
const exposes = chunks.reduce((
|
|
46
|
+
const exposes = chunks.reduce((p, c) => Object.assign(p, {[c.module.replace("./", "")]: c.chunks}), {})
|
|
54
47
|
const name = (federationPlugin._options.library && federationPlugin._options.library.name) || federationPlugin._options.name
|
|
55
48
|
|
|
56
49
|
const statsResult = {
|
|
@@ -58,23 +51,18 @@ class FederationStatsPlugin {
|
|
|
58
51
|
exposes,
|
|
59
52
|
}
|
|
60
53
|
|
|
61
|
-
const publicUrl = this._options.publicUrl
|
|
62
|
-
if (publicUrl) {
|
|
63
|
-
statsResult.publicUrl = publicUrl
|
|
64
|
-
}
|
|
65
|
-
|
|
66
54
|
const fileName = this._options.fileName
|
|
67
55
|
const statsBuffer = Buffer.from(JSON.stringify(statsResult), "utf-8")
|
|
68
|
-
const
|
|
56
|
+
const statsSource = {
|
|
69
57
|
source: () => statsBuffer,
|
|
70
58
|
size: () => statsBuffer.length,
|
|
71
59
|
}
|
|
72
60
|
|
|
73
61
|
const asset = compilation.getAsset(fileName)
|
|
74
62
|
if (asset) {
|
|
75
|
-
compilation.updateAsset(fileName,
|
|
63
|
+
compilation.updateAsset(fileName, statsSource)
|
|
76
64
|
} else {
|
|
77
|
-
compilation.emitAsset(fileName,
|
|
65
|
+
compilation.emitAsset(fileName, statsSource)
|
|
78
66
|
}
|
|
79
67
|
}
|
|
80
68
|
)
|
package/package.json
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webpack-federation-stats-plugin",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"types": "index.d.ts",
|
|
3
|
+
"version": "1.1.2",
|
|
5
4
|
"description": "export module federation stats",
|
|
6
|
-
"main": "
|
|
5
|
+
"main": "index.js",
|
|
7
6
|
"scripts": {
|
|
8
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
-
"publish:beta": "npm version prerelease --preid=beta -m \"beta version - %s\" && npm publish --tag beta",
|
|
10
7
|
"publish:patch": "npm version patch -m \"patch version - %s\" && npm publish",
|
|
11
8
|
"publish:minor": "npm version minor -m \"minor version - %s\" && npm publish",
|
|
12
9
|
"publish:major": "npm version major -m \"major version - %s\" && npm publish",
|
|
13
10
|
"postpublish": "git push && git push --tags"
|
|
14
11
|
},
|
|
12
|
+
"funding": {
|
|
13
|
+
"type": "github",
|
|
14
|
+
"url": "https://github.com/sponsors/DanielAmenou"
|
|
15
|
+
},
|
|
15
16
|
"homepage": "https://github.com/DanielAmenou/webpack-federation-stats-plugin#readme",
|
|
16
17
|
"repository": {
|
|
17
18
|
"type": "git",
|
|
@@ -20,8 +21,7 @@
|
|
|
20
21
|
"keywords": [
|
|
21
22
|
"webpack",
|
|
22
23
|
"plugin",
|
|
23
|
-
"module federation"
|
|
24
|
-
"loadable-components"
|
|
24
|
+
"module federation"
|
|
25
25
|
],
|
|
26
26
|
"author": "Daniel Amenou <amenou.daniel@gmail.com>",
|
|
27
27
|
"license": "MIT"
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 DanielAmenou
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/index.d.ts
DELETED