@umijs/mfsu 4.0.0-canary.20220429.3 → 4.0.0-canary.20220506.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.
Files changed (55) hide show
  1. package/dist/babelPlugins/awaitImport/awaitImport.d.ts +27 -0
  2. package/dist/babelPlugins/awaitImport/awaitImport.js +120 -0
  3. package/dist/babelPlugins/awaitImport/checkMatch.d.ts +18 -0
  4. package/dist/babelPlugins/awaitImport/checkMatch.js +127 -0
  5. package/dist/babelPlugins/awaitImport/getAliasedPath.d.ts +4 -0
  6. package/dist/babelPlugins/awaitImport/getAliasedPath.js +30 -0
  7. package/dist/babelPlugins/awaitImport/getRealPath.d.ts +4 -0
  8. package/dist/babelPlugins/awaitImport/getRealPath.js +24 -0
  9. package/dist/babelPlugins/awaitImport/isExternals.d.ts +11 -0
  10. package/dist/babelPlugins/awaitImport/isExternals.js +29 -0
  11. package/dist/babelPlugins/awaitImport/parseSpecifiers.d.ts +1 -0
  12. package/dist/babelPlugins/awaitImport/parseSpecifiers.js +55 -0
  13. package/dist/constants.d.ts +7 -0
  14. package/dist/constants.js +10 -0
  15. package/dist/dep/dep.d.ts +30 -0
  16. package/dist/dep/dep.js +96 -0
  17. package/dist/dep/getCJSExports.d.ts +3 -0
  18. package/dist/dep/getCJSExports.js +58 -0
  19. package/dist/dep/getExposeFromContent.d.ts +6 -0
  20. package/dist/dep/getExposeFromContent.js +69 -0
  21. package/dist/dep/getModuleExports.d.ts +7 -0
  22. package/dist/dep/getModuleExports.js +34 -0
  23. package/dist/depBuilder/depBuilder.d.ts +30 -0
  24. package/dist/depBuilder/depBuilder.js +164 -0
  25. package/dist/depBuilder/getESBuildEntry.d.ts +4 -0
  26. package/dist/depBuilder/getESBuildEntry.js +328 -0
  27. package/dist/depInfo.d.ts +17 -0
  28. package/dist/depInfo.js +50 -0
  29. package/dist/esbuildHandlers/autoCssModules.d.ts +2 -0
  30. package/dist/esbuildHandlers/autoCssModules.js +24 -0
  31. package/dist/esbuildHandlers/awaitImport/index.d.ts +12 -0
  32. package/dist/esbuildHandlers/awaitImport/index.js +44 -0
  33. package/dist/index.d.ts +4 -0
  34. package/dist/index.js +23 -0
  35. package/dist/loader/esbuild.d.ts +5 -0
  36. package/dist/loader/esbuild.js +38 -0
  37. package/dist/mfsu.d.ts +63 -0
  38. package/dist/mfsu.js +294 -0
  39. package/dist/moduleGraph.d.ts +73 -0
  40. package/dist/moduleGraph.js +197 -0
  41. package/dist/types.d.ts +16 -0
  42. package/dist/types.js +8 -0
  43. package/dist/utils/makeArray.d.ts +1 -0
  44. package/dist/utils/makeArray.js +7 -0
  45. package/dist/utils/trimFileContent.d.ts +1 -0
  46. package/dist/utils/trimFileContent.js +7 -0
  47. package/dist/webpackPlugins/buildDepPlugin.d.ts +10 -0
  48. package/dist/webpackPlugins/buildDepPlugin.js +17 -0
  49. package/dist/webpackPlugins/depChunkIdPrefixPlugin.d.ts +5 -0
  50. package/dist/webpackPlugins/depChunkIdPrefixPlugin.js +19 -0
  51. package/dist/webpackPlugins/stripSourceMapUrlPlugin.d.ts +10 -0
  52. package/dist/webpackPlugins/stripSourceMapUrlPlugin.js +28 -0
  53. package/dist/webpackPlugins/writeCachePlugin.d.ts +10 -0
  54. package/dist/webpackPlugins/writeCachePlugin.js +15 -0
  55. package/package.json +4 -4
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ModuleGraph = void 0;
4
+ const utils_1 = require("@umijs/utils");
5
+ class ModuleNode {
6
+ constructor(file) {
7
+ this.importers = new Set();
8
+ this.importedModules = new Set();
9
+ this.isDependency = false;
10
+ this.isRoot = false;
11
+ this.version = null;
12
+ this.file = file;
13
+ }
14
+ }
15
+ class ModuleGraph {
16
+ constructor() {
17
+ this.fileToModules = new Map();
18
+ this.depToModules = new Map();
19
+ this.depSnapshotModules = {};
20
+ this.rootModules = new Set();
21
+ }
22
+ restore(data) {
23
+ let fileMap = new Map();
24
+ const addNode = ({ file, importer }) => {
25
+ // fix circular dependency
26
+ if (fileMap.has(file))
27
+ return;
28
+ fileMap.set(file, true);
29
+ const mod = new ModuleNode(file);
30
+ let isDependency = false;
31
+ let info;
32
+ if (data.fileModules[file]) {
33
+ info = data.fileModules[file];
34
+ }
35
+ else if (data.depModules[file]) {
36
+ info = data.depModules[file];
37
+ isDependency = true;
38
+ }
39
+ if (info.isRoot)
40
+ mod.isRoot = true;
41
+ if (importer) {
42
+ mod.importers.add(importer);
43
+ importer.importedModules.add(mod);
44
+ }
45
+ mod.isDependency = isDependency;
46
+ if (info.version !== undefined) {
47
+ mod.version = info.version;
48
+ }
49
+ if (isDependency) {
50
+ this.depToModules.set(file, mod);
51
+ }
52
+ else {
53
+ for (const importedModule of info.importedModules) {
54
+ addNode({ file: importedModule, importer: mod });
55
+ }
56
+ this.fileToModules.set(file, mod);
57
+ }
58
+ };
59
+ for (const root of data.roots) {
60
+ addNode({ file: root });
61
+ }
62
+ this.depSnapshotModules = data.depSnapshotModules;
63
+ }
64
+ toJSON() {
65
+ const roots = [];
66
+ const fileModules = {};
67
+ const depModules = {};
68
+ this.depToModules.forEach((value, key) => {
69
+ depModules[key] = {
70
+ version: value.version,
71
+ };
72
+ });
73
+ this.fileToModules.forEach((value, key) => {
74
+ fileModules[key] = {
75
+ importedModules: Array.from(value.importedModules).map((item) => item.file),
76
+ };
77
+ if (value.isRoot) {
78
+ fileModules[key].isRoot = true;
79
+ roots.push(key);
80
+ }
81
+ });
82
+ return {
83
+ roots,
84
+ fileModules,
85
+ depModules,
86
+ depSnapshotModules: this.depSnapshotModules,
87
+ };
88
+ }
89
+ snapshotDeps() {
90
+ this.depSnapshotModules = this.getDepsInfo(this.depToModules);
91
+ }
92
+ getDepsInfo(mods) {
93
+ return Array.from(mods.keys()).reduce((memo, key) => {
94
+ memo[key] = this.getDepInfo(mods.get(key));
95
+ return memo;
96
+ }, {});
97
+ }
98
+ getDepInfo(mod) {
99
+ return {
100
+ file: mod.file,
101
+ version: mod.version,
102
+ };
103
+ }
104
+ hasDepChanged() {
105
+ const depModulesInfo = this.getDepsInfo(this.depToModules);
106
+ return !utils_1.lodash.isEqual(depModulesInfo, this.depSnapshotModules);
107
+ }
108
+ onFileChange(opts) {
109
+ if (this.fileToModules.has(opts.file)) {
110
+ const mod = this.fileToModules.get(opts.file);
111
+ this.updateModule({
112
+ mod,
113
+ deps: opts.deps,
114
+ });
115
+ }
116
+ else {
117
+ const mod = new ModuleNode(opts.file);
118
+ mod.isRoot = true;
119
+ this.fileToModules.set(opts.file, mod);
120
+ this.rootModules.add(mod);
121
+ opts.deps.forEach((dep) => {
122
+ this.addNode({
123
+ file: dep.file,
124
+ isDependency: dep.isDependency,
125
+ version: dep.version || null,
126
+ importer: mod,
127
+ });
128
+ });
129
+ }
130
+ }
131
+ updateModule(opts) {
132
+ const importedModulesMap = Array.from(opts.mod.importedModules).reduce((memo, mod) => {
133
+ memo[mod.file] = mod;
134
+ return memo;
135
+ }, {});
136
+ const newDeps = [];
137
+ for (const dep of opts.deps) {
138
+ // update
139
+ if (importedModulesMap[dep.file]) {
140
+ if (dep.version !== undefined) {
141
+ importedModulesMap[dep.file].version = dep.version;
142
+ }
143
+ delete importedModulesMap[dep.file];
144
+ }
145
+ // add
146
+ else {
147
+ newDeps.push(dep);
148
+ }
149
+ }
150
+ Object.keys(importedModulesMap).forEach((key) => {
151
+ this.deleteNode({ mod: importedModulesMap[key], importer: opts.mod });
152
+ });
153
+ newDeps.forEach((dep) => {
154
+ this.addNode({ ...dep, importer: opts.mod });
155
+ });
156
+ }
157
+ addNode(opts) {
158
+ const modules = opts.isDependency ? this.depToModules : this.fileToModules;
159
+ let mod;
160
+ if (modules.has(opts.file)) {
161
+ mod = modules.get(opts.file);
162
+ if (opts.version !== undefined)
163
+ mod.version = opts.version;
164
+ }
165
+ else {
166
+ mod = new ModuleNode(opts.file);
167
+ mod.isDependency = opts.isDependency;
168
+ if (opts.version !== undefined)
169
+ mod.version = opts.version;
170
+ modules.set(opts.file, mod);
171
+ }
172
+ if (!mod.importers.has(opts.importer)) {
173
+ mod.importers.add(opts.importer);
174
+ }
175
+ if (!opts.importer.importedModules.has(mod)) {
176
+ opts.importer.importedModules.add(mod);
177
+ }
178
+ }
179
+ deleteNode(opts) {
180
+ const modules = opts.mod.isDependency
181
+ ? this.depToModules
182
+ : this.fileToModules;
183
+ const { mod, importer } = opts;
184
+ mod.importers.delete(opts.importer);
185
+ importer.importedModules.delete(mod);
186
+ if (!mod.importers.size) {
187
+ modules.delete(opts.mod.file);
188
+ mod.importedModules.forEach((importedModule) => {
189
+ this.deleteNode({
190
+ mod: importedModule,
191
+ importer: mod,
192
+ });
193
+ });
194
+ }
195
+ }
196
+ }
197
+ exports.ModuleGraph = ModuleGraph;
@@ -0,0 +1,16 @@
1
+ import type { ImportSpecifier } from '@umijs/bundler-utils/compiled/es-module-lexer';
2
+ import type { TransformOptions } from '@umijs/bundler-utils/compiled/esbuild';
3
+ export declare enum Mode {
4
+ development = "development",
5
+ production = "production"
6
+ }
7
+ export interface IEsbuildLoaderHandlerParams {
8
+ code: string;
9
+ filePath: string;
10
+ imports: readonly ImportSpecifier[];
11
+ exports: readonly string[];
12
+ }
13
+ export interface IEsbuildLoaderOpts extends Partial<TransformOptions> {
14
+ handler?: Array<(opts: IEsbuildLoaderHandlerParams) => string>;
15
+ implementation?: typeof import('@umijs/bundler-utils/compiled/esbuild');
16
+ }
package/dist/types.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Mode = void 0;
4
+ var Mode;
5
+ (function (Mode) {
6
+ Mode["development"] = "development";
7
+ Mode["production"] = "production";
8
+ })(Mode = exports.Mode || (exports.Mode = {}));
@@ -0,0 +1 @@
1
+ export declare function makeArray(item: any): any[];
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeArray = void 0;
4
+ function makeArray(item) {
5
+ return Array.isArray(item) ? item : [item];
6
+ }
7
+ exports.makeArray = makeArray;
@@ -0,0 +1 @@
1
+ export declare function trimFileContent(content: string): string;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.trimFileContent = void 0;
4
+ function trimFileContent(content) {
5
+ return content.trim() + '\n';
6
+ }
7
+ exports.trimFileContent = trimFileContent;
@@ -0,0 +1,10 @@
1
+ import type { Compiler } from 'webpack';
2
+ interface IOpts {
3
+ onCompileDone: Function;
4
+ }
5
+ export declare class BuildDepPlugin {
6
+ private opts;
7
+ constructor(opts: IOpts);
8
+ apply(compiler: Compiler): void;
9
+ }
10
+ export {};
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BuildDepPlugin = void 0;
4
+ const PLUGIN_NAME = 'MFSUBuildDeps';
5
+ class BuildDepPlugin {
6
+ constructor(opts) {
7
+ this.opts = opts;
8
+ }
9
+ apply(compiler) {
10
+ compiler.hooks.done.tap(PLUGIN_NAME, (stats) => {
11
+ if (!stats.hasErrors()) {
12
+ this.opts.onCompileDone();
13
+ }
14
+ });
15
+ }
16
+ }
17
+ exports.BuildDepPlugin = BuildDepPlugin;
@@ -0,0 +1,5 @@
1
+ import { Compiler } from 'webpack';
2
+ export declare class DepChunkIdPrefixPlugin {
3
+ constructor();
4
+ apply(compiler: Compiler): void;
5
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DepChunkIdPrefixPlugin = void 0;
4
+ const constants_1 = require("../constants");
5
+ const pluginId = 'MFSUDepChunkIdPrefix';
6
+ class DepChunkIdPrefixPlugin {
7
+ constructor() { }
8
+ apply(compiler) {
9
+ compiler.hooks.compilation.tap(pluginId, (compilation) => {
10
+ compilation.hooks.afterOptimizeChunkIds.tap(pluginId, (chunks) => {
11
+ for (const chunk of chunks) {
12
+ chunk.id = constants_1.MF_DEP_PREFIX + chunk.id;
13
+ chunk.ids = [chunk.id];
14
+ }
15
+ });
16
+ });
17
+ }
18
+ }
19
+ exports.DepChunkIdPrefixPlugin = DepChunkIdPrefixPlugin;
@@ -0,0 +1,10 @@
1
+ import type { Compiler } from 'webpack';
2
+ interface IOpts {
3
+ webpack: any;
4
+ }
5
+ export declare class StripSourceMapUrlPlugin {
6
+ opts: IOpts;
7
+ constructor(opts: IOpts);
8
+ apply(compiler: Compiler): void;
9
+ }
10
+ export {};
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StripSourceMapUrlPlugin = void 0;
4
+ class StripSourceMapUrlPlugin {
5
+ constructor(opts) {
6
+ this.opts = opts;
7
+ }
8
+ apply(compiler) {
9
+ compiler.hooks.compilation.tap('StripSourceMapUrlPlugin', (compilation) => {
10
+ compilation.hooks.processAssets.tap({
11
+ name: 'StripSourceMapUrlPlugin',
12
+ stage: this.opts.webpack.Compilation.PROCESS_ASSETS_STAGE_DERIVE,
13
+ }, (assets) => {
14
+ Object.keys(assets)
15
+ .filter((filename) => /\.js$/.test(filename))
16
+ .forEach((filename) => {
17
+ const asset = assets[filename];
18
+ const source = asset
19
+ .source()
20
+ .toString()
21
+ .replace(/# sourceMappingURL=(.+?\.map)/g, '# $1');
22
+ compilation.updateAsset(filename, new this.opts.webpack.sources.RawSource(source));
23
+ });
24
+ });
25
+ });
26
+ }
27
+ }
28
+ exports.StripSourceMapUrlPlugin = StripSourceMapUrlPlugin;
@@ -0,0 +1,10 @@
1
+ import type { Compiler } from 'webpack';
2
+ interface IOpts {
3
+ onWriteCache: Function;
4
+ }
5
+ export declare class WriteCachePlugin {
6
+ private opts;
7
+ constructor(opts: IOpts);
8
+ apply(compiler: Compiler): void;
9
+ }
10
+ export {};
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WriteCachePlugin = void 0;
4
+ const PLUGIN_NAME = 'MFSUWriteCache';
5
+ class WriteCachePlugin {
6
+ constructor(opts) {
7
+ this.opts = opts;
8
+ }
9
+ apply(compiler) {
10
+ compiler.cache.hooks.store.tap({ name: PLUGIN_NAME, stage: /*Cache.STAGE_DISK*/ 10 }, () => {
11
+ this.opts.onWriteCache();
12
+ });
13
+ }
14
+ }
15
+ exports.WriteCachePlugin = WriteCachePlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/mfsu",
3
- "version": "4.0.0-canary.20220429.3",
3
+ "version": "4.0.0-canary.20220506.2",
4
4
  "description": "@umijs/mfsu",
5
5
  "homepage": "https://github.com/umijs/umi-next/tree/master/packages/mfsu#readme",
6
6
  "bugs": "https://github.com/umijs/umi-next/issues",
@@ -22,9 +22,9 @@
22
22
  "test": "umi-scripts jest-turbo"
23
23
  },
24
24
  "dependencies": {
25
- "@umijs/bundler-esbuild": "4.0.0-canary.20220429.3",
26
- "@umijs/bundler-utils": "4.0.0-canary.20220429.3",
27
- "@umijs/utils": "4.0.0-canary.20220429.3",
25
+ "@umijs/bundler-esbuild": "4.0.0-canary.20220506.2",
26
+ "@umijs/bundler-utils": "4.0.0-canary.20220506.2",
27
+ "@umijs/utils": "4.0.0-canary.20220506.2",
28
28
  "enhanced-resolve": "5.9.2"
29
29
  },
30
30
  "devDependencies": {