@mf-toolkit/shared-inspector 0.2.0 → 0.3.0
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/README.md +14 -7
- package/dist/collector/extract-mfp-shared.d.ts +14 -0
- package/dist/collector/extract-mfp-shared.d.ts.map +1 -0
- package/dist/collector/extract-mfp-shared.js +40 -0
- package/dist/collector/extract-mfp-shared.js.map +1 -0
- package/dist/plugins/webpack.d.ts.map +1 -1
- package/dist/plugins/webpack.js +10 -1
- package/dist/plugins/webpack.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://github.com/zvitaly7/mf-toolkit/blob/main/LICENSE)
|
|
6
6
|
[](https://nodejs.org)
|
|
7
7
|
|
|
8
|
-
> ⚠️ **Work in progress.** This package is fully tested (
|
|
8
|
+
> ⚠️ **Work in progress.** This package is fully tested (252 tests) and published to npm. The API is stable but may receive minor changes before the official stable release.
|
|
9
9
|
|
|
10
10
|
Build-time analyser for Module Federation `shared` dependencies. Two-phase architecture: **collect facts → analyse facts**.
|
|
11
11
|
|
|
@@ -78,6 +78,8 @@ const report = await inspect({
|
|
|
78
78
|
|
|
79
79
|
### Webpack plugin
|
|
80
80
|
|
|
81
|
+
`sharedConfig` is optional — the plugin auto-extracts it from `ModuleFederationPlugin` when not provided:
|
|
82
|
+
|
|
81
83
|
```typescript
|
|
82
84
|
import { MfSharedInspectorPlugin } from '@mf-toolkit/shared-inspector/webpack';
|
|
83
85
|
|
|
@@ -88,20 +90,25 @@ module.exports = {
|
|
|
88
90
|
shared: { react: { singleton: true }, mobx: { singleton: true } },
|
|
89
91
|
}),
|
|
90
92
|
|
|
93
|
+
// sharedConfig not needed — auto-extracted from ModuleFederationPlugin above
|
|
91
94
|
new MfSharedInspectorPlugin({
|
|
92
95
|
sourceDirs: ['./src'],
|
|
93
|
-
sharedConfig: {
|
|
94
|
-
react: { singleton: true, requiredVersion: '^19.0.0' },
|
|
95
|
-
mobx: { singleton: true },
|
|
96
|
-
},
|
|
97
|
-
tsconfigPath: './tsconfig.json', // resolve @alias/* imports
|
|
98
96
|
warn: true,
|
|
99
|
-
writeManifest: true,
|
|
97
|
+
writeManifest: true, // writes project-manifest.json for CI aggregation
|
|
100
98
|
}),
|
|
101
99
|
],
|
|
102
100
|
};
|
|
103
101
|
```
|
|
104
102
|
|
|
103
|
+
Pass `sharedConfig` explicitly to override auto-extraction:
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
new MfSharedInspectorPlugin({
|
|
107
|
+
sourceDirs: ['./src'],
|
|
108
|
+
sharedConfig: { react: { singleton: true, requiredVersion: '^18.0.0' } },
|
|
109
|
+
})
|
|
110
|
+
```
|
|
111
|
+
|
|
105
112
|
## Analysis depth
|
|
106
113
|
|
|
107
114
|
| Depth | What it finds | Speed |
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SharedDepConfig } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Tries to extract the `shared` config from a ModuleFederationPlugin instance
|
|
4
|
+
* found in `compiler.options.plugins`.
|
|
5
|
+
*
|
|
6
|
+
* Returns `null` when:
|
|
7
|
+
* - No ModuleFederationPlugin is found
|
|
8
|
+
* - The plugin exists but has no `shared` option
|
|
9
|
+
* - The plugin uses an unknown internal storage format
|
|
10
|
+
*
|
|
11
|
+
* This intentionally uses `any` to remain independent of webpack/rspack types.
|
|
12
|
+
*/
|
|
13
|
+
export declare function extractSharedFromCompiler(compiler: any): Record<string, SharedDepConfig> | null;
|
|
14
|
+
//# sourceMappingURL=extract-mfp-shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-mfp-shared.d.ts","sourceRoot":"","sources":["../../src/collector/extract-mfp-shared.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAWnD;;;;;;;;;;GAUG;AAEH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,IAAI,CAoB/F"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { parseSharedConfig } from './parse-shared-config.js';
|
|
2
|
+
/**
|
|
3
|
+
* Known constructor names for Module Federation plugins across bundlers.
|
|
4
|
+
* Checked by name to avoid a hard runtime dependency on webpack/rspack.
|
|
5
|
+
*/
|
|
6
|
+
const MFP_CONSTRUCTOR_NAMES = new Set([
|
|
7
|
+
'ModuleFederationPlugin', // webpack 5
|
|
8
|
+
'ModuleFederationPluginV2', // some community forks
|
|
9
|
+
]);
|
|
10
|
+
/**
|
|
11
|
+
* Tries to extract the `shared` config from a ModuleFederationPlugin instance
|
|
12
|
+
* found in `compiler.options.plugins`.
|
|
13
|
+
*
|
|
14
|
+
* Returns `null` when:
|
|
15
|
+
* - No ModuleFederationPlugin is found
|
|
16
|
+
* - The plugin exists but has no `shared` option
|
|
17
|
+
* - The plugin uses an unknown internal storage format
|
|
18
|
+
*
|
|
19
|
+
* This intentionally uses `any` to remain independent of webpack/rspack types.
|
|
20
|
+
*/
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
export function extractSharedFromCompiler(compiler) {
|
|
23
|
+
const plugins = compiler?.options?.plugins;
|
|
24
|
+
if (!Array.isArray(plugins))
|
|
25
|
+
return null;
|
|
26
|
+
const mfPlugin = plugins.find(
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
(p) => p != null && MFP_CONSTRUCTOR_NAMES.has(p.constructor?.name));
|
|
29
|
+
if (!mfPlugin)
|
|
30
|
+
return null;
|
|
31
|
+
// webpack 5 stores options as `this._options` (private but stable across 5.x)
|
|
32
|
+
// Fall back to `this.options` used by some community variants
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
+
const raw = mfPlugin._options?.shared ?? mfPlugin.options?.shared;
|
|
35
|
+
if (raw == null)
|
|
36
|
+
return null;
|
|
37
|
+
const parsed = parseSharedConfig(raw);
|
|
38
|
+
return Object.keys(parsed).length > 0 ? parsed : null;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=extract-mfp-shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-mfp-shared.js","sourceRoot":"","sources":["../../src/collector/extract-mfp-shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAG7D;;;GAGG;AACH,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACpC,wBAAwB,EAAQ,YAAY;IAC5C,0BAA0B,EAAM,uBAAuB;CACxD,CAAC,CAAC;AAEH;;;;;;;;;;GAUG;AACH,8DAA8D;AAC9D,MAAM,UAAU,yBAAyB,CAAC,QAAa;IACrD,MAAM,OAAO,GAAc,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC;IACtD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAC;IAEzC,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI;IAC3B,8DAA8D;IAC9D,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,IAAI,IAAI,IAAI,qBAAqB,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,CAAC,CACxE,CAAC;IAEF,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAE3B,8EAA8E;IAC9E,8DAA8D;IAC9D,8DAA8D;IAC9D,MAAM,GAAG,GAAI,QAAgB,CAAC,QAAQ,EAAE,MAAM,IAAK,QAAgB,CAAC,OAAO,EAAE,MAAM,CAAC;IAEpF,IAAI,GAAG,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC;IAE7B,MAAM,MAAM,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC;IACtC,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AACxD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webpack.d.ts","sourceRoot":"","sources":["../../src/plugins/webpack.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"webpack.d.ts","sourceRoot":"","sources":["../../src/plugins/webpack.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAUxD,UAAU,kBAAkB;IAC1B,MAAM,EAAE,KAAK,EAAE,CAAC;IAChB,QAAQ,EAAE,KAAK,EAAE,CAAC;CACnB;AAED,UAAU,eAAe;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE;QACP,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;IACF,KAAK,EAAE;QACL,YAAY,EAAE;YACZ,UAAU,CACR,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,CAAC,WAAW,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAC,GACrD,IAAI,CAAC;SACT,CAAC;KACH,CAAC;CACH;AAMD;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,uBAAuB;IAClC,OAAO,CAAC,OAAO,CAAuB;gBAE1B,OAAO,EAAE,oBAAoB;IAIzC,KAAK,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI;CA2GvC"}
|
package/dist/plugins/webpack.js
CHANGED
|
@@ -3,6 +3,7 @@ import { buildProjectManifest } from '../collector/build-project-manifest.js';
|
|
|
3
3
|
import { analyzeProject } from '../analyzer/analyze-project.js';
|
|
4
4
|
import { formatReport } from '../reporter/format-report.js';
|
|
5
5
|
import { writeManifest } from '../reporter/write-report.js';
|
|
6
|
+
import { extractSharedFromCompiler } from '../collector/extract-mfp-shared.js';
|
|
6
7
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
7
8
|
const PLUGIN_NAME = 'MfSharedInspectorPlugin';
|
|
8
9
|
/**
|
|
@@ -29,7 +30,7 @@ export class MfSharedInspectorPlugin {
|
|
|
29
30
|
}
|
|
30
31
|
apply(compiler) {
|
|
31
32
|
compiler.hooks.afterCompile.tapPromise(PLUGIN_NAME, async (compilation) => {
|
|
32
|
-
const { sourceDirs, depth = 'local-graph', sharedConfig, kind, packageJsonPath, extensions, ignore, tsconfigPath, workspacePackages, parser, analysis, warn = true, failOn, writeManifest: shouldWriteManifest = false, outputDir = '.', } = this.options;
|
|
33
|
+
const { sourceDirs, depth = 'local-graph', sharedConfig: explicitSharedConfig, kind, packageJsonPath, extensions, ignore, tsconfigPath, workspacePackages, parser, analysis, warn = true, failOn, writeManifest: shouldWriteManifest = false, outputDir = '.', } = this.options;
|
|
33
34
|
// Resolve name from webpack compiler, fallback to context dir name
|
|
34
35
|
const name = compiler.options.name ?? basename(compiler.context);
|
|
35
36
|
// Resolve paths relative to compiler.context when not absolute
|
|
@@ -41,6 +42,14 @@ export class MfSharedInspectorPlugin {
|
|
|
41
42
|
? outputDir
|
|
42
43
|
: join(compiler.context, outputDir);
|
|
43
44
|
try {
|
|
45
|
+
// Use explicit sharedConfig if provided, otherwise auto-extract from
|
|
46
|
+
// ModuleFederationPlugin found in compiler.options.plugins
|
|
47
|
+
const sharedConfig = explicitSharedConfig ?? extractSharedFromCompiler(compiler) ?? {};
|
|
48
|
+
const autoExtracted = !explicitSharedConfig && Object.keys(sharedConfig).length > 0;
|
|
49
|
+
if (autoExtracted && warn) {
|
|
50
|
+
console.log(`[${PLUGIN_NAME}] sharedConfig auto-extracted from ModuleFederationPlugin ` +
|
|
51
|
+
`(${Object.keys(sharedConfig).length} packages)`);
|
|
52
|
+
}
|
|
44
53
|
const manifest = await buildProjectManifest({
|
|
45
54
|
name,
|
|
46
55
|
sourceDirs: resolvedSourceDirs,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webpack.js","sourceRoot":"","sources":["../../src/plugins/webpack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"webpack.js","sourceRoot":"","sources":["../../src/plugins/webpack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AAyB/E,gFAAgF;AAEhF,MAAM,WAAW,GAAG,yBAAyB,CAAC;AAE9C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,uBAAuB;IAC1B,OAAO,CAAuB;IAEtC,YAAY,OAA6B;QACvC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,QAAyB;QAC7B,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC,UAAU,CACpC,WAAW,EACX,KAAK,EAAE,WAA+B,EAAE,EAAE;YACxC,MAAM,EACJ,UAAU,EACV,KAAK,GAAG,aAAa,EACrB,YAAY,EAAE,oBAAoB,EAClC,IAAI,EACJ,eAAe,EACf,UAAU,EAC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