@umijs/mfsu 4.0.31 → 4.0.33

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/dist/dep/dep.d.ts CHANGED
@@ -7,11 +7,13 @@ export declare class Dep {
7
7
  normalizedFile: string;
8
8
  filePath: string;
9
9
  excludeNodeNatives: boolean;
10
+ importer: string | undefined;
10
11
  constructor(opts: {
11
12
  file: string;
12
13
  version: string;
13
14
  cwd: string;
14
15
  excludeNodeNatives: boolean;
16
+ importer?: string;
15
17
  });
16
18
  buildExposeContent(): Promise<string>;
17
19
  getRealFile(): Promise<string | null>;
@@ -19,6 +21,7 @@ export declare class Dep {
19
21
  deps: Record<string, {
20
22
  file: string;
21
23
  version: string;
24
+ importer?: string;
22
25
  }>;
23
26
  cwd: string;
24
27
  mfsu: MFSU;
package/dist/dep/dep.js CHANGED
@@ -37,13 +37,23 @@ var resolver = import_enhanced_resolve.default.create({
37
37
  mainFields: ["module", "browser", "main"],
38
38
  extensions: [".wasm", ".mjs", ".js", ".jsx", ".ts", ".tsx", ".json"],
39
39
  exportsFields: ["exports"],
40
- conditionNames: ["import", "module", "require", "node"]
40
+ conditionNames: ["import", "module", "require", "node"],
41
+ symlinks: false
41
42
  });
42
43
  async function resolve(context, path) {
43
44
  return new Promise((resolve2, reject) => {
44
45
  resolver(context, path, (err, result) => err ? reject(err) : resolve2(result));
45
46
  });
46
47
  }
48
+ async function resolveFromContexts(contexts, path) {
49
+ for (const context of contexts) {
50
+ try {
51
+ return await resolve(context, path);
52
+ } catch (e) {
53
+ }
54
+ }
55
+ throw new Error(`Can't resolve ${path} from ${contexts.join(", ")}`);
56
+ }
47
57
  var Dep = class {
48
58
  constructor(opts) {
49
59
  this.file = (0, import_utils.winPath)(opts.file);
@@ -53,6 +63,7 @@ var Dep = class {
53
63
  this.normalizedFile = this.shortFile.replace(/\//g, "_").replace(/:/g, "_");
54
64
  this.filePath = `${import_constants.MF_VA_PREFIX}${this.normalizedFile}.js`;
55
65
  this.excludeNodeNatives = opts.excludeNodeNatives;
66
+ this.importer = opts.importer;
56
67
  }
57
68
  async buildExposeContent() {
58
69
  const isNodeNatives = !!process.binding("natives")[this.file];
@@ -80,7 +91,11 @@ export * from '${this.file}';
80
91
  }
81
92
  async getRealFile() {
82
93
  try {
83
- return await resolve(this.cwd, this.file);
94
+ const contexts = [this.cwd];
95
+ if (this.importer) {
96
+ contexts.push((0, import_path.dirname)(this.importer));
97
+ }
98
+ return await resolveFromContexts(contexts, this.file);
84
99
  } catch (e) {
85
100
  return null;
86
101
  }
@@ -28,13 +28,15 @@ module.exports = __toCommonJS(getExposeFromContent_exports);
28
28
  var import_assert = __toESM(require("assert"));
29
29
  var import_path = require("path");
30
30
  var import_getModuleExports = require("./getModuleExports");
31
+ var import_utils = require("@umijs/utils");
31
32
  async function getExposeFromContent(opts) {
33
+ const importPath = (0, import_utils.winPath)(opts.filePath);
32
34
  if (opts.filePath && /\.(css|less|scss|sass|stylus|styl)$/.test(opts.filePath)) {
33
- return `import '${opts.dep.file}';`;
35
+ return `import '${importPath}';`;
34
36
  }
35
37
  if (opts.filePath && /\.(json|svg|png|jpe?g|avif|gif|webp|ico|eot|woff|woff2|ttf|txt|text|mdx?)$/.test(opts.filePath)) {
36
38
  return `
37
- import _ from '${opts.dep.file}';
39
+ import _ from '${importPath}';
38
40
  export default _;`.trim();
39
41
  }
40
42
  (0, import_assert.default)(/(js|jsx|mjs|ts|tsx)$/.test(opts.filePath), `file type not supported for ${(0, import_path.basename)(opts.filePath)}.`);
@@ -44,29 +46,29 @@ export default _;`.trim();
44
46
  });
45
47
  if (isCJS) {
46
48
  return [
47
- `import _ from '${opts.dep.file}';`,
49
+ `import _ from '${importPath}';`,
48
50
  `export default _;`,
49
- `export * from '${opts.dep.file}';`
51
+ `export * from '${importPath}';`
50
52
  ].join("\n");
51
53
  } else {
52
54
  const ret = [];
53
55
  let hasExports = false;
54
56
  if (exports.includes("default")) {
55
- ret.push(`import _ from '${opts.dep.file}';`);
57
+ ret.push(`import _ from '${importPath}';`);
56
58
  ret.push(`export default _;`);
57
59
  hasExports = true;
58
60
  }
59
61
  if (hasNonDefaultExports(exports) || /export\s*\*\s*from/.test(opts.content)) {
60
- ret.push(`export * from '${opts.dep.file}';`);
62
+ ret.push(`export * from '${importPath}';`);
61
63
  hasExports = true;
62
64
  }
63
65
  if (!hasExports) {
64
66
  if (exports.includes("__esModule")) {
65
- ret.push(`import _ from '${opts.dep.file}';`);
67
+ ret.push(`import _ from '${importPath}';`);
66
68
  ret.push(`export default _;`);
67
- ret.push(`export * from '${opts.dep.file}';`);
69
+ ret.push(`export * from '${importPath}';`);
68
70
  } else {
69
- ret.push(`import '${opts.dep.file}';`);
71
+ ret.push(`import '${importPath}';`);
70
72
  }
71
73
  }
72
74
  return ret.join("\n");
package/dist/depInfo.d.ts CHANGED
@@ -6,6 +6,7 @@ interface IOpts {
6
6
  export declare type DepModule = {
7
7
  file: string;
8
8
  version: string;
9
+ importer?: string;
9
10
  };
10
11
  export interface IDepInfo {
11
12
  shouldBuild(): string | boolean;
@@ -122,15 +122,16 @@ var StaticAnalyzeStrategy = class {
122
122
  },
123
123
  onFileChange: async (c) => {
124
124
  import_utils.logger.debug("webpack found changes modified:", c.modifiedFiles, "removed:", c.removedFiles);
125
+ const cwd = this.mfsu.opts.cwd;
125
126
  const fileEvents = [
126
127
  ...this.staticDepInfo.opts.srcCodeCache.replayChangeEvents(),
127
- ...extractJSCodeFiles(c.modifiedFiles).map((f) => {
128
+ ...extractJSCodeFiles(cwd, c.modifiedFiles).map((f) => {
128
129
  return {
129
130
  event: "change",
130
131
  path: f
131
132
  };
132
133
  }),
133
- ...extractJSCodeFiles(c.removedFiles).map((f) => {
134
+ ...extractJSCodeFiles(cwd, c.removedFiles).map((f) => {
134
135
  return {
135
136
  event: "unlink",
136
137
  path: f
@@ -161,13 +162,13 @@ var StaticAnalyzeStrategy = class {
161
162
  }
162
163
  };
163
164
  var REG_CODE_EXT = /\.(jsx|js|ts|tsx)$/;
164
- function extractJSCodeFiles(files) {
165
+ function extractJSCodeFiles(folderBase, files) {
165
166
  const jsFiles = [];
166
167
  if (!files) {
167
168
  return jsFiles;
168
169
  }
169
170
  for (let file of files.values()) {
170
- if (REG_CODE_EXT.test(file)) {
171
+ if (file.startsWith(folderBase) && REG_CODE_EXT.test(file)) {
171
172
  jsFiles.push(file);
172
173
  }
173
174
  }
@@ -44,6 +44,7 @@ export declare class ModuleGraph {
44
44
  getDepInfo(mod: ModuleNode): {
45
45
  file: string;
46
46
  version: string;
47
+ importer: string;
47
48
  };
48
49
  hasDepChanged(): boolean;
49
50
  onFileChange(opts: {
@@ -22,7 +22,6 @@ __export(moduleGraph_exports, {
22
22
  ModuleGraph: () => ModuleGraph
23
23
  });
24
24
  module.exports = __toCommonJS(moduleGraph_exports);
25
- var import_utils = require("@umijs/utils");
26
25
  var ModuleNode = class {
27
26
  constructor(file) {
28
27
  this.importers = /* @__PURE__ */ new Set();
@@ -124,14 +123,31 @@ var ModuleGraph = class {
124
123
  }, {});
125
124
  }
126
125
  getDepInfo(mod) {
126
+ const [importer] = mod.importers;
127
127
  return {
128
128
  file: mod.file,
129
- version: mod.version
129
+ version: mod.version,
130
+ importer: importer == null ? void 0 : importer.file
130
131
  };
131
132
  }
132
133
  hasDepChanged() {
133
134
  const depModulesInfo = this.getDepsInfo(this.depToModules);
134
- return !import_utils.lodash.isEqual(depModulesInfo, this.depSnapshotModules);
135
+ const depKeys = Object.keys(depModulesInfo);
136
+ const snapshotKeys = Object.keys(this.depSnapshotModules);
137
+ if (depKeys.length !== snapshotKeys.length) {
138
+ return true;
139
+ }
140
+ for (const k of depKeys) {
141
+ const dep = depModulesInfo[k];
142
+ const snapshot = this.depSnapshotModules[k];
143
+ if (dep.file !== (snapshot == null ? void 0 : snapshot.file)) {
144
+ return true;
145
+ }
146
+ if (dep.version !== (snapshot == null ? void 0 : snapshot.version)) {
147
+ return true;
148
+ }
149
+ }
150
+ return false;
135
151
  }
136
152
  onFileChange(opts) {
137
153
  if (this.fileToModules.has(opts.file)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/mfsu",
3
- "version": "4.0.31",
3
+ "version": "4.0.33",
4
4
  "description": "@umijs/mfsu",
5
5
  "homepage": "https://github.com/umijs/umi/tree/master/packages/mfsu#readme",
6
6
  "bugs": "https://github.com/umijs/umi/issues",
@@ -23,9 +23,9 @@
23
23
  "test": "umi-scripts jest-turbo"
24
24
  },
25
25
  "dependencies": {
26
- "@umijs/bundler-esbuild": "4.0.31",
27
- "@umijs/bundler-utils": "4.0.31",
28
- "@umijs/utils": "4.0.31",
26
+ "@umijs/bundler-esbuild": "4.0.33",
27
+ "@umijs/bundler-utils": "4.0.33",
28
+ "@umijs/utils": "4.0.33",
29
29
  "enhanced-resolve": "5.9.3",
30
30
  "is-equal": "^1.6.4"
31
31
  },