@umijs/mfsu 4.0.14 → 4.0.17

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
@@ -6,12 +6,12 @@ export declare class Dep {
6
6
  shortFile: string;
7
7
  normalizedFile: string;
8
8
  filePath: string;
9
- mfsu: MFSU;
9
+ excludeNodeNatives: boolean;
10
10
  constructor(opts: {
11
11
  file: string;
12
12
  version: string;
13
13
  cwd: string;
14
- mfsu: MFSU;
14
+ excludeNodeNatives: boolean;
15
15
  });
16
16
  buildExposeContent(): Promise<string>;
17
17
  getRealFile(): Promise<string | null>;
package/dist/dep/dep.js CHANGED
@@ -69,12 +69,12 @@ var Dep = class {
69
69
  this.shortFile = this.file;
70
70
  this.normalizedFile = this.shortFile.replace(/\//g, "_").replace(/:/g, "_");
71
71
  this.filePath = `${import_constants.MF_VA_PREFIX}${this.normalizedFile}.js`;
72
- this.mfsu = opts.mfsu;
72
+ this.excludeNodeNatives = opts.excludeNodeNatives;
73
73
  }
74
74
  async buildExposeContent() {
75
75
  const isNodeNatives = !!process.binding("natives")[this.file];
76
76
  if (isNodeNatives) {
77
- return (0, import_trimFileContent.trimFileContent)(this.mfsu.opts.excludeNodeNatives ? `
77
+ return (0, import_trimFileContent.trimFileContent)(this.excludeNodeNatives ? `
78
78
  const _ = require('${this.file}');
79
79
  module.exports = _;
80
80
  ` : `
@@ -103,7 +103,7 @@ export * from '${this.file}';
103
103
  return Object.keys(opts.deps).map((file) => {
104
104
  return new Dep(__spreadProps(__spreadValues({}, opts.deps[file]), {
105
105
  cwd: opts.cwd,
106
- mfsu: opts.mfsu
106
+ excludeNodeNatives: opts.mfsu.opts.excludeNodeNatives
107
107
  }));
108
108
  });
109
109
  }
@@ -16,6 +16,10 @@ export declare class DepBuilder {
16
16
  onBuildComplete: Function;
17
17
  deps: Dep[];
18
18
  }): Promise<void>;
19
+ buildWithWorker(opts: {
20
+ onBuildComplete: Function;
21
+ deps: Dep[];
22
+ }): Promise<void>;
19
23
  build(opts: {
20
24
  deps: Dep[];
21
25
  }): Promise<void>;
@@ -97,6 +97,38 @@ var DepBuilder = class {
97
97
  import_utils.logger.event(`[mfsu] compiled with esbuild successfully in ${+new Date() - date} ms`);
98
98
  opts.onBuildComplete();
99
99
  }
100
+ async buildWithWorker(opts) {
101
+ const worker = this.opts.mfsu.opts.startBuildWorker(opts.deps);
102
+ worker.postMessage(opts.deps);
103
+ return new Promise((resolve, reject) => {
104
+ const onMessage = ({
105
+ progress,
106
+ done,
107
+ error
108
+ }) => {
109
+ if (done) {
110
+ opts.onBuildComplete();
111
+ worker.off("message", onMessage);
112
+ resolve();
113
+ }
114
+ if (error) {
115
+ worker.off("message", onMessage);
116
+ opts.onBuildComplete();
117
+ import_utils.logger.error("[MFSU][eager] build failed", error);
118
+ reject(error);
119
+ }
120
+ if (progress) {
121
+ this.opts.mfsu.onProgress(progress);
122
+ }
123
+ };
124
+ worker.on("message", onMessage);
125
+ worker.once("error", (e) => {
126
+ import_utils.logger.error("[MFSU][eager] worker got Error", e);
127
+ opts.onBuildComplete();
128
+ reject(e);
129
+ });
130
+ });
131
+ }
100
132
  async build(opts) {
101
133
  this.isBuilding = true;
102
134
  const onBuildComplete = () => {
@@ -105,14 +137,18 @@ var DepBuilder = class {
105
137
  this.completeFns = [];
106
138
  };
107
139
  try {
108
- await this.writeMFFiles({ deps: opts.deps });
109
- const newOpts = __spreadProps(__spreadValues({}, opts), {
140
+ const buildOpts = __spreadProps(__spreadValues({}, opts), {
110
141
  onBuildComplete
111
142
  });
143
+ if (this.opts.mfsu.opts.strategy === "eager") {
144
+ await this.buildWithWorker(buildOpts);
145
+ return;
146
+ }
147
+ await this.writeMFFiles({ deps: opts.deps });
112
148
  if (this.opts.mfsu.opts.buildDepWithESBuild) {
113
- await this.buildWithESBuild(newOpts);
149
+ await this.buildWithESBuild(buildOpts);
114
150
  } else {
115
- await this.buildWithWebpack(newOpts);
151
+ await this.buildWithWebpack(buildOpts);
116
152
  }
117
153
  } catch (e) {
118
154
  onBuildComplete();
@@ -1,5 +1,7 @@
1
+ /// <reference types="node" />
1
2
  import type { NextFunction, Request, Response } from '@umijs/bundler-utils/compiled/express';
2
3
  import webpack, { Configuration } from 'webpack';
4
+ import type { Worker } from 'worker_threads';
3
5
  import { DepBuilder } from '../depBuilder/depBuilder';
4
6
  import { DepModule } from '../depInfo';
5
7
  import { Mode } from '../types';
@@ -25,6 +27,7 @@ interface IOpts {
25
27
  remoteName?: string;
26
28
  remoteAliases?: string[];
27
29
  serverBase?: string;
30
+ startBuildWorker: (dep: any[]) => Worker;
28
31
  }
29
32
  export declare class MFSU {
30
33
  opts: IOpts;
@@ -100,10 +100,10 @@ var StaticAnalyzeStrategy = class {
100
100
  const mfsu = this.mfsu;
101
101
  return {
102
102
  beforeCompile: async () => {
103
- import_utils.logger.event(`[MFSU][eager] start build deps`);
104
103
  if (mfsu.depBuilder.isBuilding) {
105
104
  mfsu.buildDepsAgain = true;
106
105
  } else {
106
+ import_utils.logger.event(`[MFSU][eager] start build deps`);
107
107
  this.staticDepInfo.consumeAllProducedEvents();
108
108
  mfsu.buildDeps().then(() => {
109
109
  mfsu.onProgress({
@@ -34,7 +34,11 @@ var BuildDepPlugin = class {
34
34
  });
35
35
  compiler.hooks.beforeCompile.tap(PLUGIN_NAME, () => {
36
36
  var _a, _b;
37
- (_b = (_a = this.opts).beforeCompile) == null ? void 0 : _b.call(_a);
37
+ if (this.opts.beforeCompile) {
38
+ return (_b = (_a = this.opts).beforeCompile) == null ? void 0 : _b.call(_a);
39
+ } else {
40
+ return Promise.resolve();
41
+ }
38
42
  });
39
43
  compiler.hooks.done.tap(PLUGIN_NAME, (stats) => {
40
44
  if (!stats.hasErrors()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/mfsu",
3
- "version": "4.0.14",
3
+ "version": "4.0.17",
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.14",
27
- "@umijs/bundler-utils": "4.0.14",
28
- "@umijs/utils": "4.0.14",
26
+ "@umijs/bundler-esbuild": "4.0.17",
27
+ "@umijs/bundler-utils": "4.0.17",
28
+ "@umijs/utils": "4.0.17",
29
29
  "enhanced-resolve": "5.9.3",
30
30
  "is-equal": "^1.6.4"
31
31
  },