@modern-js/app-tools 2.58.1-alpha.5 → 2.58.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -103,7 +103,11 @@ class RouterPlugin {
103
103
  routeAssets: {}
104
104
  });
105
105
  const prevManifest = JSON.parse(prevManifestStr);
106
+ const asyncEntryNames = [];
106
107
  for (const [name, chunkGroup] of Object.entries(namedChunkGroups)) {
108
+ if (name.startsWith("async-")) {
109
+ asyncEntryNames.push(name);
110
+ }
107
111
  const assets = chunkGroup.assets.map((asset) => {
108
112
  const filename = asset.name;
109
113
  return publicPath ? normalizePath(publicPath) + filename : filename;
@@ -123,6 +127,14 @@ class RouterPlugin {
123
127
  });
124
128
  }
125
129
  }
130
+ if (asyncEntryNames.length > 0) {
131
+ for (const asyncEntryName of asyncEntryNames) {
132
+ const syncEntryName = asyncEntryName.replace("async-", "");
133
+ const syncEntry = routeAssets[syncEntryName];
134
+ const asyncEntry = routeAssets[asyncEntryName];
135
+ (0, import_lodash.merge)(syncEntry, asyncEntry);
136
+ }
137
+ }
126
138
  const manifest = {
127
139
  routeAssets
128
140
  };
@@ -27,7 +27,7 @@ const inspect = async (api, options) => {
27
27
  throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
28
28
  }
29
29
  return appContext.builder.inspectConfig({
30
- env: options.env,
30
+ mode: options.env,
31
31
  verbose: options.verbose,
32
32
  outputPath: options.output,
33
33
  writeToDisk: true
@@ -38,27 +38,15 @@ var import_pkg_types = require("pkg-types");
38
38
  var import_mlly = require("mlly");
39
39
  var import_utils2 = require("./utils");
40
40
  var import_nft = require("@vercel/nft");
41
- const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = import_utils2.traceFiles, entryFilter, modifyPackageJson, copyWholePackage, cacheOptions = {
42
- cacheDir: ".modern-js/deploy",
43
- analysisCache: true,
44
- fileCache: false,
45
- symlinkCache: false
46
- }, traceOptions }) => {
41
+ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = import_utils2.traceFiles, entryFilter, modifyPackageJson, copyWholePackage, traceOptions }) => {
47
42
  const base = "/";
48
- const startTime = Date.now();
49
43
  const entryFiles = await (0, import_utils2.findEntryFiles)(serverRootDir, entryFilter);
50
- console.time("traceFiles");
51
44
  const fileTrace = await traceFiles({
52
45
  entryFiles: entryFiles.concat(includeEntries),
53
46
  serverRootDir,
54
- cacheOptions: {
55
- ...cacheOptions,
56
- cacheDir: import_node_path.default.resolve(appDir, cacheOptions.cacheDir)
57
- },
58
47
  base,
59
48
  traceOptions
60
49
  });
61
- console.timeEnd("traceFiles");
62
50
  const currentProjectModules = import_node_path.default.join(appDir, "node_modules");
63
51
  const dependencySearchRoot = import_node_path.default.resolve(appDir, "../../../../../../");
64
52
  const tracedFiles = Object.fromEntries(await Promise.all([
@@ -240,8 +228,6 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
240
228
  };
241
229
  const finalPkgJson = (modifyPackageJson === null || modifyPackageJson === void 0 ? void 0 : modifyPackageJson(newPkgJson)) || newPkgJson;
242
230
  await import_utils.fs.writeJSON(outputPkgPath, finalPkgJson);
243
- const endTime = Date.now();
244
- console.log("handleDependencies cost:", `${endTime - startTime}ms`);
245
231
  };
246
232
  // Annotate the CommonJS export names for ESM import in node:
247
233
  0 && (module.exports = {
@@ -139,88 +139,12 @@ const findPackageParents = (pkg, version, tracedFiles) => {
139
139
  ];
140
140
  return parentPkgs.filter((parentPkg) => parentPkg);
141
141
  };
142
- async function serializeMap(map) {
143
- const resolvedMap = /* @__PURE__ */ new Map();
144
- await Promise.all(Array.from(map.entries()).map(async ([key, value]) => {
145
- resolvedMap.set(key, value instanceof Promise ? await Promise.resolve(value) : value);
146
- }));
147
- return JSON.stringify(resolvedMap, (key, value) => {
148
- if (value === null) {
149
- return void 0;
150
- }
151
- if (value instanceof Map) {
152
- return {
153
- dataType: "Map",
154
- value: Array.from(value.entries())
155
- };
156
- }
157
- if (value instanceof Set) {
158
- return {
159
- dataType: "Set",
160
- value: Array.from(value)
161
- };
162
- }
163
- return value;
164
- });
165
- }
166
- function deserializeMap(serializedData) {
167
- return JSON.parse(serializedData, (key, value) => {
168
- if (value && value.dataType === "Map") {
169
- return new Map(value.value);
170
- }
171
- if (value && value.dataType === "Set") {
172
- return new Set(value.value);
173
- }
174
- return value;
175
- });
176
- }
177
- const loadCache = async (filePath, enabled) => {
178
- if (enabled && await import_utils.fs.pathExists(filePath)) {
179
- console.log("load cache:", filePath);
180
- const data = (await import_utils.fs.readFile(filePath)).toString();
181
- return deserializeMap(data);
182
- }
183
- return void 0;
184
- };
185
- const writeCache = async (filePath, cacheMap) => {
186
- const newCacheMap = /* @__PURE__ */ new Map();
187
- for (const [key, value] of cacheMap.entries()) {
188
- if (key.includes("node_modules/")) {
189
- newCacheMap.set(key, value);
190
- }
191
- }
192
- await import_utils.fs.writeFile(filePath, await serializeMap(newCacheMap));
193
- console.log(`write ${import_path.default.basename(filePath)} finish`);
194
- };
195
- const traceFiles = async ({ entryFiles, serverRootDir, base = "/", cacheOptions, traceOptions }) => {
196
- const { cacheDir, fileCache, analysisCache, symlinkCache } = cacheOptions;
197
- const analysisCacheFile = import_path.default.join(cacheDir, "analysis-cache.json");
198
- const fileCacheFile = import_path.default.join(cacheDir, "file-cache.json");
199
- const symlinkCacheFile = import_path.default.join(cacheDir, "symlink-cache.json");
200
- const cache = {
201
- analysisCache: await loadCache(analysisCacheFile, analysisCache),
202
- fileCache: await loadCache(fileCacheFile, fileCache),
203
- symlinkCache: await loadCache(symlinkCacheFile, symlinkCache)
204
- };
205
- const res = await (0, import_nft.nodeFileTrace)(entryFiles, {
142
+ const traceFiles = async ({ entryFiles, serverRootDir, base = "/", traceOptions }) => {
143
+ return await (0, import_nft.nodeFileTrace)(entryFiles, {
206
144
  base,
207
145
  processCwd: serverRootDir,
208
- cache,
209
146
  ...traceOptions
210
147
  });
211
- if (analysisCache || fileCache || symlinkCache) {
212
- await import_utils.fs.ensureDir(cacheDir);
213
- if (cache.analysisCache && analysisCache) {
214
- writeCache(analysisCacheFile, cache.analysisCache);
215
- }
216
- if (cache.fileCache && fileCache) {
217
- writeCache(fileCacheFile, cache.fileCache);
218
- }
219
- if (cache.symlinkCache && symlinkCache) {
220
- writeCache(symlinkCacheFile, cache.symlinkCache);
221
- }
222
- }
223
- return res;
224
148
  };
225
149
  const resolveTracedPath = async (base, p) => import_utils.fs.realpath(import_path.default.resolve(base, p));
226
150
  const isSubPath = (parentPath, childPath) => {
@@ -4,7 +4,7 @@ import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
4
4
  import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
5
5
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
6
6
  import { createHash } from "crypto";
7
- import { mergeWith } from "@modern-js/utils/lodash";
7
+ import { merge, mergeWith } from "@modern-js/utils/lodash";
8
8
  import { ROUTE_MANIFEST_FILE } from "@modern-js/utils";
9
9
  import { ROUTE_MANIFEST } from "@modern-js/utils/universal/constants";
10
10
  var PLUGIN_NAME = "ModernjsRoutePlugin";
@@ -86,7 +86,7 @@ var RouterPlugin = /* @__PURE__ */ function() {
86
86
  name: PLUGIN_NAME,
87
87
  stage: Compilation.PROCESS_ASSETS_STAGE_REPORT
88
88
  }, /* @__PURE__ */ _async_to_generator(function() {
89
- var _loop, stats, publicPath, _stats_chunks, chunks, namedChunkGroups, routeAssets, prevManifestAsset, prevManifestStr, prevManifest, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, name, chunkGroup, assets, referenceCssAssets, manifest, entryNames, entryChunks, orignalEntryIds, entryChunkFiles, entryChunkFileIds, i;
89
+ var _loop, stats, publicPath, _stats_chunks, chunks, namedChunkGroups, routeAssets, prevManifestAsset, prevManifestStr, prevManifest, asyncEntryNames, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, name, chunkGroup, assets, referenceCssAssets, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, asyncEntryName, syncEntryName, syncEntry, asyncEntry, manifest, entryNames, entryChunks, orignalEntryIds, entryChunkFiles, entryChunkFileIds, i;
90
90
  return _ts_generator(this, function(_state) {
91
91
  _loop = function(i2) {
92
92
  var entryName = entryNames[i2];
@@ -200,10 +200,14 @@ var RouterPlugin = /* @__PURE__ */ function() {
200
200
  routeAssets: {}
201
201
  });
202
202
  prevManifest = JSON.parse(prevManifestStr);
203
+ asyncEntryNames = [];
203
204
  _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
204
205
  try {
205
206
  for (_iterator = Object.entries(namedChunkGroups)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
206
207
  _step_value = _sliced_to_array(_step.value, 2), name = _step_value[0], chunkGroup = _step_value[1];
208
+ if (name.startsWith("async-")) {
209
+ asyncEntryNames.push(name);
210
+ }
207
211
  assets = chunkGroup.assets.map(function(asset) {
208
212
  var filename = asset.name;
209
213
  return publicPath ? normalizePath(publicPath) + filename : filename;
@@ -239,6 +243,31 @@ var RouterPlugin = /* @__PURE__ */ function() {
239
243
  }
240
244
  }
241
245
  }
246
+ if (asyncEntryNames.length > 0) {
247
+ _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
248
+ try {
249
+ for (_iterator1 = asyncEntryNames[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
250
+ asyncEntryName = _step1.value;
251
+ syncEntryName = asyncEntryName.replace("async-", "");
252
+ syncEntry = routeAssets[syncEntryName];
253
+ asyncEntry = routeAssets[asyncEntryName];
254
+ merge(syncEntry, asyncEntry);
255
+ }
256
+ } catch (err) {
257
+ _didIteratorError1 = true;
258
+ _iteratorError1 = err;
259
+ } finally {
260
+ try {
261
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
262
+ _iterator1.return();
263
+ }
264
+ } finally {
265
+ if (_didIteratorError1) {
266
+ throw _iteratorError1;
267
+ }
268
+ }
269
+ }
270
+ }
242
271
  manifest = {
243
272
  routeAssets
244
273
  };
@@ -11,7 +11,7 @@ var inspect = function() {
11
11
  return [
12
12
  2,
13
13
  appContext.builder.inspectConfig({
14
- env: options.env,
14
+ mode: options.env,
15
15
  verbose: options.verbose,
16
16
  outputPath: options.output,
17
17
  writeToDisk: true
@@ -1,6 +1,4 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
3
- import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
2
  import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
5
3
  import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
6
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
@@ -13,40 +11,29 @@ import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaul
13
11
  import { nodeFileTrace } from "@vercel/nft";
14
12
  var handleDependencies = function() {
15
13
  var _ref = _async_to_generator(function(param) {
16
- var appDir, serverRootDir, includeEntries, _param_traceFiles, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, _param_cacheOptions, cacheOptions, traceOptions, base, startTime, entryFiles, fileTrace, currentProjectModules, dependencySearchRoot, tracedFiles, _, tracedPackages, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, tracedFile, pkgName, tracedPackage, pkgJSON, tracedPackageVersion, shouldCopyWholePackage, _tracedPackageVersion_files, allFiles, err, multiVersionPkgs, singleVersionPackages, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, tracedPackage1, versions, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, version, projectPkgJson, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _loop, _iterator3, _step3, err, outputPkgPath, newPkgJson, finalPkgJson, endTime;
14
+ var appDir, serverRootDir, includeEntries, _param_traceFiles, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, traceOptions, base, entryFiles, fileTrace, currentProjectModules, dependencySearchRoot, tracedFiles, _, tracedPackages, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, tracedFile, pkgName, tracedPackage, pkgJSON, tracedPackageVersion, shouldCopyWholePackage, _tracedPackageVersion_files, allFiles, err, multiVersionPkgs, singleVersionPackages, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, tracedPackage1, versions, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, version, projectPkgJson, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _loop, _iterator3, _step3, err, outputPkgPath, newPkgJson, finalPkgJson;
17
15
  return _ts_generator(this, function(_state) {
18
16
  switch (_state.label) {
19
17
  case 0:
20
- appDir = param.appDir, serverRootDir = param.serverRootDir, includeEntries = param.includeEntries, _param_traceFiles = param.traceFiles, traceFiles = _param_traceFiles === void 0 ? defaultTraceFiles : _param_traceFiles, entryFilter = param.entryFilter, modifyPackageJson = param.modifyPackageJson, copyWholePackage = param.copyWholePackage, _param_cacheOptions = param.cacheOptions, cacheOptions = _param_cacheOptions === void 0 ? {
21
- cacheDir: ".modern-js/deploy",
22
- analysisCache: true,
23
- fileCache: false,
24
- symlinkCache: false
25
- } : _param_cacheOptions, traceOptions = param.traceOptions;
18
+ appDir = param.appDir, serverRootDir = param.serverRootDir, includeEntries = param.includeEntries, _param_traceFiles = param.traceFiles, traceFiles = _param_traceFiles === void 0 ? defaultTraceFiles : _param_traceFiles, entryFilter = param.entryFilter, modifyPackageJson = param.modifyPackageJson, copyWholePackage = param.copyWholePackage, traceOptions = param.traceOptions;
26
19
  base = "/";
27
- startTime = Date.now();
28
20
  return [
29
21
  4,
30
22
  findEntryFiles(serverRootDir, entryFilter)
31
23
  ];
32
24
  case 1:
33
25
  entryFiles = _state.sent();
34
- console.time("traceFiles");
35
26
  return [
36
27
  4,
37
28
  traceFiles({
38
29
  entryFiles: entryFiles.concat(includeEntries),
39
30
  serverRootDir,
40
- cacheOptions: _object_spread_props(_object_spread({}, cacheOptions), {
41
- cacheDir: path.resolve(appDir, cacheOptions.cacheDir)
42
- }),
43
31
  base,
44
32
  traceOptions
45
33
  })
46
34
  ];
47
35
  case 2:
48
36
  fileTrace = _state.sent();
49
- console.timeEnd("traceFiles");
50
37
  currentProjectModules = path.join(appDir, "node_modules");
51
38
  dependencySearchRoot = path.resolve(appDir, "../../../../../../");
52
39
  _ = Object.fromEntries;
@@ -611,8 +598,6 @@ var handleDependencies = function() {
611
598
  ];
612
599
  case 24:
613
600
  _state.sent();
614
- endTime = Date.now();
615
- console.log("handleDependencies cost:", "".concat(endTime - startTime, "ms"));
616
601
  return [
617
602
  2
618
603
  ];
@@ -1,7 +1,5 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
- import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
3
2
  import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
4
- import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
5
3
  import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
6
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
7
5
  import path from "path";
@@ -337,271 +335,24 @@ var findPackageParents = function(pkg, version, tracedFiles) {
337
335
  return parentPkg;
338
336
  });
339
337
  };
340
- function serializeMap(map) {
341
- return _serializeMap.apply(this, arguments);
342
- }
343
- function _serializeMap() {
344
- _serializeMap = _async_to_generator(function(map) {
345
- var resolvedMap;
346
- return _ts_generator(this, function(_state) {
347
- switch (_state.label) {
348
- case 0:
349
- resolvedMap = /* @__PURE__ */ new Map();
350
- return [
351
- 4,
352
- Promise.all(Array.from(map.entries()).map(function() {
353
- var _ref = _async_to_generator(function(param) {
354
- var _param, key, value, _, _tmp, _tmp1;
355
- return _ts_generator(this, function(_state2) {
356
- switch (_state2.label) {
357
- case 0:
358
- _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
359
- _ = resolvedMap.set;
360
- _tmp = [
361
- key
362
- ];
363
- if (!_instanceof(value, Promise))
364
- return [
365
- 3,
366
- 2
367
- ];
368
- return [
369
- 4,
370
- Promise.resolve(value)
371
- ];
372
- case 1:
373
- _tmp1 = _state2.sent();
374
- return [
375
- 3,
376
- 3
377
- ];
378
- case 2:
379
- _tmp1 = value;
380
- _state2.label = 3;
381
- case 3:
382
- _.apply(resolvedMap, _tmp.concat([
383
- _tmp1
384
- ]));
385
- return [
386
- 2
387
- ];
388
- }
389
- });
390
- });
391
- return function(_) {
392
- return _ref.apply(this, arguments);
393
- };
394
- }()))
395
- ];
396
- case 1:
397
- _state.sent();
398
- return [
399
- 2,
400
- JSON.stringify(resolvedMap, function(key, value) {
401
- if (value === null) {
402
- return void 0;
403
- }
404
- if (_instanceof(value, Map)) {
405
- return {
406
- dataType: "Map",
407
- value: Array.from(value.entries())
408
- };
409
- }
410
- if (_instanceof(value, Set)) {
411
- return {
412
- dataType: "Set",
413
- value: Array.from(value)
414
- };
415
- }
416
- return value;
417
- })
418
- ];
419
- }
420
- });
421
- });
422
- return _serializeMap.apply(this, arguments);
423
- }
424
- function deserializeMap(serializedData) {
425
- return JSON.parse(serializedData, function(key, value) {
426
- if (value && value.dataType === "Map") {
427
- return new Map(value.value);
428
- }
429
- if (value && value.dataType === "Set") {
430
- return new Set(value.value);
431
- }
432
- return value;
433
- });
434
- }
435
- var loadCache = function() {
436
- var _ref = _async_to_generator(function(filePath, enabled) {
437
- var _tmp, data;
438
- return _ts_generator(this, function(_state) {
439
- switch (_state.label) {
440
- case 0:
441
- _tmp = enabled;
442
- if (!_tmp)
443
- return [
444
- 3,
445
- 2
446
- ];
447
- return [
448
- 4,
449
- fse.pathExists(filePath)
450
- ];
451
- case 1:
452
- _tmp = _state.sent();
453
- _state.label = 2;
454
- case 2:
455
- if (!_tmp)
456
- return [
457
- 3,
458
- 4
459
- ];
460
- console.log("load cache:", filePath);
461
- return [
462
- 4,
463
- fse.readFile(filePath)
464
- ];
465
- case 3:
466
- data = _state.sent().toString();
467
- return [
468
- 2,
469
- deserializeMap(data)
470
- ];
471
- case 4:
472
- return [
473
- 2,
474
- void 0
475
- ];
476
- }
477
- });
478
- });
479
- return function loadCache2(filePath, enabled) {
480
- return _ref.apply(this, arguments);
481
- };
482
- }();
483
- var writeCache = function() {
484
- var _ref = _async_to_generator(function(filePath, cacheMap) {
485
- var newCacheMap, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, key, value, _, _tmp;
486
- return _ts_generator(this, function(_state) {
487
- switch (_state.label) {
488
- case 0:
489
- newCacheMap = /* @__PURE__ */ new Map();
490
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
491
- try {
492
- for (_iterator = cacheMap.entries()[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
493
- _step_value = _sliced_to_array(_step.value, 2), key = _step_value[0], value = _step_value[1];
494
- if (key.includes("node_modules/")) {
495
- newCacheMap.set(key, value);
496
- }
497
- }
498
- } catch (err) {
499
- _didIteratorError = true;
500
- _iteratorError = err;
501
- } finally {
502
- try {
503
- if (!_iteratorNormalCompletion && _iterator.return != null) {
504
- _iterator.return();
505
- }
506
- } finally {
507
- if (_didIteratorError) {
508
- throw _iteratorError;
509
- }
510
- }
511
- }
512
- _ = fse.writeFile;
513
- _tmp = [
514
- filePath
515
- ];
516
- return [
517
- 4,
518
- serializeMap(newCacheMap)
519
- ];
520
- case 1:
521
- return [
522
- 4,
523
- _.apply(fse, _tmp.concat([
524
- _state.sent()
525
- ]))
526
- ];
527
- case 2:
528
- _state.sent();
529
- console.log("write ".concat(path.basename(filePath), " finish"));
530
- return [
531
- 2
532
- ];
533
- }
534
- });
535
- });
536
- return function writeCache2(filePath, cacheMap) {
537
- return _ref.apply(this, arguments);
538
- };
539
- }();
540
338
  var traceFiles = function() {
541
339
  var _ref = _async_to_generator(function(param) {
542
- var entryFiles, serverRootDir, _param_base, base, cacheOptions, traceOptions, cacheDir, fileCache, analysisCache, symlinkCache, analysisCacheFile, fileCacheFile, symlinkCacheFile, cache, _tmp, res;
340
+ var entryFiles, serverRootDir, _param_base, base, traceOptions;
543
341
  return _ts_generator(this, function(_state) {
544
342
  switch (_state.label) {
545
343
  case 0:
546
- entryFiles = param.entryFiles, serverRootDir = param.serverRootDir, _param_base = param.base, base = _param_base === void 0 ? "/" : _param_base, cacheOptions = param.cacheOptions, traceOptions = param.traceOptions;
547
- cacheDir = cacheOptions.cacheDir, fileCache = cacheOptions.fileCache, analysisCache = cacheOptions.analysisCache, symlinkCache = cacheOptions.symlinkCache;
548
- analysisCacheFile = path.join(cacheDir, "analysis-cache.json");
549
- fileCacheFile = path.join(cacheDir, "file-cache.json");
550
- symlinkCacheFile = path.join(cacheDir, "symlink-cache.json");
551
- _tmp = {};
552
- return [
553
- 4,
554
- loadCache(analysisCacheFile, analysisCache)
555
- ];
556
- case 1:
557
- _tmp.analysisCache = _state.sent();
558
- return [
559
- 4,
560
- loadCache(fileCacheFile, fileCache)
561
- ];
562
- case 2:
563
- _tmp.fileCache = _state.sent();
564
- return [
565
- 4,
566
- loadCache(symlinkCacheFile, symlinkCache)
567
- ];
568
- case 3:
569
- cache = (_tmp.symlinkCache = _state.sent(), _tmp);
344
+ entryFiles = param.entryFiles, serverRootDir = param.serverRootDir, _param_base = param.base, base = _param_base === void 0 ? "/" : _param_base, traceOptions = param.traceOptions;
570
345
  return [
571
346
  4,
572
347
  nodeFileTrace(entryFiles, _object_spread({
573
348
  base,
574
- processCwd: serverRootDir,
575
- cache
349
+ processCwd: serverRootDir
576
350
  }, traceOptions))
577
351
  ];
578
- case 4:
579
- res = _state.sent();
580
- if (!(analysisCache || fileCache || symlinkCache))
581
- return [
582
- 3,
583
- 6
584
- ];
585
- return [
586
- 4,
587
- fse.ensureDir(cacheDir)
588
- ];
589
- case 5:
590
- _state.sent();
591
- if (cache.analysisCache && analysisCache) {
592
- writeCache(analysisCacheFile, cache.analysisCache);
593
- }
594
- if (cache.fileCache && fileCache) {
595
- writeCache(fileCacheFile, cache.fileCache);
596
- }
597
- if (cache.symlinkCache && symlinkCache) {
598
- writeCache(symlinkCacheFile, cache.symlinkCache);
599
- }
600
- _state.label = 6;
601
- case 6:
352
+ case 1:
602
353
  return [
603
354
  2,
604
- res
355
+ _state.sent()
605
356
  ];
606
357
  }
607
358
  });
@@ -1,5 +1,5 @@
1
1
  import { createHash } from "crypto";
2
- import { mergeWith } from "@modern-js/utils/lodash";
2
+ import { merge, mergeWith } from "@modern-js/utils/lodash";
3
3
  import { ROUTE_MANIFEST_FILE } from "@modern-js/utils";
4
4
  import { ROUTE_MANIFEST } from "@modern-js/utils/universal/constants";
5
5
  const PLUGIN_NAME = "ModernjsRoutePlugin";
@@ -80,7 +80,11 @@ class RouterPlugin {
80
80
  routeAssets: {}
81
81
  });
82
82
  const prevManifest = JSON.parse(prevManifestStr);
83
+ const asyncEntryNames = [];
83
84
  for (const [name, chunkGroup] of Object.entries(namedChunkGroups)) {
85
+ if (name.startsWith("async-")) {
86
+ asyncEntryNames.push(name);
87
+ }
84
88
  const assets = chunkGroup.assets.map((asset) => {
85
89
  const filename = asset.name;
86
90
  return publicPath ? normalizePath(publicPath) + filename : filename;
@@ -100,6 +104,14 @@ class RouterPlugin {
100
104
  });
101
105
  }
102
106
  }
107
+ if (asyncEntryNames.length > 0) {
108
+ for (const asyncEntryName of asyncEntryNames) {
109
+ const syncEntryName = asyncEntryName.replace("async-", "");
110
+ const syncEntry = routeAssets[syncEntryName];
111
+ const asyncEntry = routeAssets[asyncEntryName];
112
+ merge(syncEntry, asyncEntry);
113
+ }
114
+ }
103
115
  const manifest = {
104
116
  routeAssets
105
117
  };
@@ -4,7 +4,7 @@ const inspect = async (api, options) => {
4
4
  throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
5
5
  }
6
6
  return appContext.builder.inspectConfig({
7
- env: options.env,
7
+ mode: options.env,
8
8
  verbose: options.verbose,
9
9
  outputPath: options.output,
10
10
  writeToDisk: true
@@ -4,27 +4,15 @@ import { readPackageJSON } from "pkg-types";
4
4
  import { parseNodeModulePath } from "mlly";
5
5
  import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaultTraceFiles, findPackageParents, resolveTracedPath, readDirRecursive, isSubPath } from "./utils";
6
6
  import { nodeFileTrace } from "@vercel/nft";
7
- const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = defaultTraceFiles, entryFilter, modifyPackageJson, copyWholePackage, cacheOptions = {
8
- cacheDir: ".modern-js/deploy",
9
- analysisCache: true,
10
- fileCache: false,
11
- symlinkCache: false
12
- }, traceOptions }) => {
7
+ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = defaultTraceFiles, entryFilter, modifyPackageJson, copyWholePackage, traceOptions }) => {
13
8
  const base = "/";
14
- const startTime = Date.now();
15
9
  const entryFiles = await findEntryFiles(serverRootDir, entryFilter);
16
- console.time("traceFiles");
17
10
  const fileTrace = await traceFiles({
18
11
  entryFiles: entryFiles.concat(includeEntries),
19
12
  serverRootDir,
20
- cacheOptions: {
21
- ...cacheOptions,
22
- cacheDir: path.resolve(appDir, cacheOptions.cacheDir)
23
- },
24
13
  base,
25
14
  traceOptions
26
15
  });
27
- console.timeEnd("traceFiles");
28
16
  const currentProjectModules = path.join(appDir, "node_modules");
29
17
  const dependencySearchRoot = path.resolve(appDir, "../../../../../../");
30
18
  const tracedFiles = Object.fromEntries(await Promise.all([
@@ -206,8 +194,6 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
206
194
  };
207
195
  const finalPkgJson = (modifyPackageJson === null || modifyPackageJson === void 0 ? void 0 : modifyPackageJson(newPkgJson)) || newPkgJson;
208
196
  await fse.writeJSON(outputPkgPath, finalPkgJson);
209
- const endTime = Date.now();
210
- console.log("handleDependencies cost:", `${endTime - startTime}ms`);
211
197
  };
212
198
  export {
213
199
  handleDependencies,
@@ -98,88 +98,12 @@ const findPackageParents = (pkg, version, tracedFiles) => {
98
98
  ];
99
99
  return parentPkgs.filter((parentPkg) => parentPkg);
100
100
  };
101
- async function serializeMap(map) {
102
- const resolvedMap = /* @__PURE__ */ new Map();
103
- await Promise.all(Array.from(map.entries()).map(async ([key, value]) => {
104
- resolvedMap.set(key, value instanceof Promise ? await Promise.resolve(value) : value);
105
- }));
106
- return JSON.stringify(resolvedMap, (key, value) => {
107
- if (value === null) {
108
- return void 0;
109
- }
110
- if (value instanceof Map) {
111
- return {
112
- dataType: "Map",
113
- value: Array.from(value.entries())
114
- };
115
- }
116
- if (value instanceof Set) {
117
- return {
118
- dataType: "Set",
119
- value: Array.from(value)
120
- };
121
- }
122
- return value;
123
- });
124
- }
125
- function deserializeMap(serializedData) {
126
- return JSON.parse(serializedData, (key, value) => {
127
- if (value && value.dataType === "Map") {
128
- return new Map(value.value);
129
- }
130
- if (value && value.dataType === "Set") {
131
- return new Set(value.value);
132
- }
133
- return value;
134
- });
135
- }
136
- const loadCache = async (filePath, enabled) => {
137
- if (enabled && await fse.pathExists(filePath)) {
138
- console.log("load cache:", filePath);
139
- const data = (await fse.readFile(filePath)).toString();
140
- return deserializeMap(data);
141
- }
142
- return void 0;
143
- };
144
- const writeCache = async (filePath, cacheMap) => {
145
- const newCacheMap = /* @__PURE__ */ new Map();
146
- for (const [key, value] of cacheMap.entries()) {
147
- if (key.includes("node_modules/")) {
148
- newCacheMap.set(key, value);
149
- }
150
- }
151
- await fse.writeFile(filePath, await serializeMap(newCacheMap));
152
- console.log(`write ${path.basename(filePath)} finish`);
153
- };
154
- const traceFiles = async ({ entryFiles, serverRootDir, base = "/", cacheOptions, traceOptions }) => {
155
- const { cacheDir, fileCache, analysisCache, symlinkCache } = cacheOptions;
156
- const analysisCacheFile = path.join(cacheDir, "analysis-cache.json");
157
- const fileCacheFile = path.join(cacheDir, "file-cache.json");
158
- const symlinkCacheFile = path.join(cacheDir, "symlink-cache.json");
159
- const cache = {
160
- analysisCache: await loadCache(analysisCacheFile, analysisCache),
161
- fileCache: await loadCache(fileCacheFile, fileCache),
162
- symlinkCache: await loadCache(symlinkCacheFile, symlinkCache)
163
- };
164
- const res = await nodeFileTrace(entryFiles, {
101
+ const traceFiles = async ({ entryFiles, serverRootDir, base = "/", traceOptions }) => {
102
+ return await nodeFileTrace(entryFiles, {
165
103
  base,
166
104
  processCwd: serverRootDir,
167
- cache,
168
105
  ...traceOptions
169
106
  });
170
- if (analysisCache || fileCache || symlinkCache) {
171
- await fse.ensureDir(cacheDir);
172
- if (cache.analysisCache && analysisCache) {
173
- writeCache(analysisCacheFile, cache.analysisCache);
174
- }
175
- if (cache.fileCache && fileCache) {
176
- writeCache(fileCacheFile, cache.fileCache);
177
- }
178
- if (cache.symlinkCache && symlinkCache) {
179
- writeCache(symlinkCacheFile, cache.symlinkCache);
180
- }
181
- }
182
- return res;
183
107
  };
184
108
  const resolveTracedPath = async (base, p) => fse.realpath(path.resolve(base, p));
185
109
  const isSubPath = (parentPath, childPath) => {
@@ -1,22 +1,20 @@
1
1
  import type { PackageJson } from 'pkg-types';
2
2
  import type { NodeFileTraceOptions } from '@vercel/nft';
3
- import { traceFiles as defaultTraceFiles, CacheOptions } from './utils';
3
+ import { traceFiles as defaultTraceFiles } from './utils';
4
4
  export type { NodeFileTraceOptions } from '@vercel/nft';
5
5
  export { nodeFileTrace } from '@vercel/nft';
6
- export declare const handleDependencies: ({ appDir, serverRootDir, includeEntries, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, cacheOptions, traceOptions, }: {
6
+ export declare const handleDependencies: ({ appDir, serverRootDir, includeEntries, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, traceOptions, }: {
7
7
  appDir: string;
8
8
  serverRootDir: string;
9
9
  includeEntries: string[];
10
- traceFiles?: (({ entryFiles, serverRootDir, base, cacheOptions, traceOptions, }: {
10
+ traceFiles?: (({ entryFiles, serverRootDir, base, traceOptions, }: {
11
11
  entryFiles: string[];
12
12
  serverRootDir: string;
13
13
  base?: string | undefined;
14
- cacheOptions: CacheOptions;
15
14
  traceOptions?: NodeFileTraceOptions | undefined;
16
15
  }) => Promise<import("@vercel/nft").NodeFileTraceResult>) | undefined;
17
16
  entryFilter?: ((filePath: string) => boolean) | undefined;
18
17
  modifyPackageJson?: ((pkgJson: PackageJson) => PackageJson) | undefined;
19
18
  copyWholePackage?: ((pkgName: string) => boolean) | undefined;
20
- cacheOptions?: CacheOptions | undefined;
21
19
  traceOptions?: NodeFileTraceOptions | undefined;
22
20
  }) => Promise<void>;
@@ -33,17 +33,10 @@ export declare const readDirRecursive: (dir: string, options?: ReadDirOptions) =
33
33
  export declare const isFile: (file: string) => Promise<boolean>;
34
34
  export declare const findEntryFiles: (rootDir: string, entryFilter?: ((filePath: string) => boolean) | undefined) => Promise<string[]>;
35
35
  export declare const findPackageParents: (pkg: TracedPackage, version: string, tracedFiles: Record<string, TracedFile>) => string[];
36
- export interface CacheOptions {
37
- fileCache: boolean;
38
- analysisCache: boolean;
39
- symlinkCache: boolean;
40
- cacheDir: string;
41
- }
42
- export declare const traceFiles: ({ entryFiles, serverRootDir, base, cacheOptions, traceOptions, }: {
36
+ export declare const traceFiles: ({ entryFiles, serverRootDir, base, traceOptions, }: {
43
37
  entryFiles: string[];
44
38
  serverRootDir: string;
45
39
  base?: string | undefined;
46
- cacheOptions: CacheOptions;
47
40
  traceOptions?: NodeFileTraceOptions | undefined;
48
41
  }) => Promise<import("@vercel/nft").NodeFileTraceResult>;
49
42
  export declare const resolveTracedPath: (base: string, p: string) => Promise<string>;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.58.1-alpha.5",
18
+ "version": "2.58.1",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -77,10 +77,9 @@
77
77
  "@babel/parser": "^7.22.15",
78
78
  "@babel/traverse": "^7.23.2",
79
79
  "@babel/types": "^7.24.7",
80
- "@rsbuild/core": "1.0.1-beta.10",
80
+ "@rsbuild/core": "1.0.1-beta.13",
81
81
  "@rsbuild/plugin-node-polyfill": "1.0.4",
82
82
  "@swc/helpers": "0.5.3",
83
- "@ungap/structured-clone": "^1.2.0",
84
83
  "@vercel/nft": "^0.26.4",
85
84
  "es-module-lexer": "^1.1.0",
86
85
  "esbuild": "0.17.19",
@@ -89,23 +88,23 @@
89
88
  "mlly": "^1.6.1",
90
89
  "pkg-types": "^1.1.0",
91
90
  "std-env": "^3.7.0",
92
- "@modern-js/node-bundle-require": "2.58.0",
93
- "@modern-js/plugin": "2.58.0",
94
- "@modern-js/plugin-i18n": "2.58.0",
95
- "@modern-js/prod-server": "2.58.0",
96
- "@modern-js/plugin-lint": "2.58.0",
97
- "@modern-js/server": "2.58.0",
98
- "@modern-js/rsbuild-plugin-esbuild": "2.58.0",
99
- "@modern-js/plugin-data-loader": "2.58.0",
100
- "@modern-js/server-utils": "2.58.0",
101
- "@modern-js/server-core": "2.58.0",
102
- "@modern-js/types": "2.58.0",
103
- "@modern-js/uni-builder": "2.58.0",
104
- "@modern-js/core": "2.58.0",
105
- "@modern-js/utils": "2.58.0"
91
+ "@modern-js/core": "2.58.1",
92
+ "@modern-js/node-bundle-require": "2.58.1",
93
+ "@modern-js/plugin": "2.58.1",
94
+ "@modern-js/plugin-data-loader": "2.58.1",
95
+ "@modern-js/plugin-i18n": "2.58.1",
96
+ "@modern-js/prod-server": "2.58.1",
97
+ "@modern-js/plugin-lint": "2.58.1",
98
+ "@modern-js/server": "2.58.1",
99
+ "@modern-js/rsbuild-plugin-esbuild": "2.58.1",
100
+ "@modern-js/server-utils": "2.58.1",
101
+ "@modern-js/server-core": "2.58.1",
102
+ "@modern-js/types": "2.58.1",
103
+ "@modern-js/uni-builder": "2.58.1",
104
+ "@modern-js/utils": "2.58.1"
106
105
  },
107
106
  "devDependencies": {
108
- "@rsbuild/plugin-swc": "1.0.1-beta.10",
107
+ "@rsbuild/plugin-swc": "1.0.1-beta.13",
109
108
  "@types/babel__traverse": "7.18.5",
110
109
  "@types/jest": "^29",
111
110
  "@types/node": "^14",
@@ -114,8 +113,8 @@
114
113
  "tsconfig-paths": "^4.2.0",
115
114
  "typescript": "^5",
116
115
  "webpack": "^5.93.0",
117
- "@scripts/build": "2.58.0",
118
- "@scripts/jest-config": "2.58.0"
116
+ "@scripts/build": "2.58.1",
117
+ "@scripts/jest-config": "2.58.1"
119
118
  },
120
119
  "sideEffects": false,
121
120
  "publishConfig": {