@modern-js/app-tools 2.57.2-alpha.0 → 2.58.1-alpha.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/builder/builder-webpack/index.js +1 -1
- package/dist/cjs/builder/generator/index.js +2 -2
- package/dist/cjs/builder/index.js +2 -2
- package/dist/cjs/commands/build.js +0 -19
- package/dist/cjs/commands/dev.js +0 -9
- package/dist/cjs/commands/index.js +8 -8
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/plugins/analyze/index.js +3 -3
- package/dist/cjs/plugins/deploy/dependencies/index.js +12 -2
- package/dist/cjs/plugins/deploy/dependencies/utils.js +73 -13
- package/dist/cjs/plugins/deploy/platforms/netlify.js +5 -14
- package/dist/cjs/plugins/deploy/platforms/{netlify-handler.js → netlifyEntry.js} +4 -6
- package/dist/cjs/plugins/deploy/platforms/node.js +4 -13
- package/dist/cjs/plugins/deploy/platforms/vercel.js +5 -14
- package/dist/cjs/plugins/deploy/platforms/{vercel-handler.js → vercelEntry.js} +1 -27
- package/dist/cjs/utils/config.js +7 -23
- package/dist/cjs/utils/loadPlugins.js +1 -1
- package/dist/cjs/utils/register.js +22 -49
- package/dist/esm/builder/builder-rspack/adapterCopy.js +4 -3
- package/dist/esm/builder/generator/getBuilderEnvironments.js +2 -0
- package/dist/esm/builder/generator/index.js +1 -1
- package/dist/esm/builder/index.js +2 -2
- package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +1 -1
- package/dist/esm/commands/build.js +16 -9
- package/dist/esm/commands/dev.js +55 -37
- package/dist/esm/commands/index.js +7 -7
- package/dist/esm/index.js +1 -42
- package/dist/esm/plugins/analyze/index.js +10 -6
- package/dist/esm/plugins/deploy/dependencies/index.js +28 -8
- package/dist/esm/plugins/deploy/dependencies/utils.js +290 -10
- package/dist/esm/utils/config.js +6 -21
- package/dist/esm/utils/createServer.js +1 -1
- package/dist/esm-node/builder/builder-rspack/adapterCopy.js +2 -2
- package/dist/esm-node/builder/generator/getBuilderEnvironments.js +1 -1
- package/dist/esm-node/builder/generator/index.js +1 -1
- package/dist/esm-node/builder/index.js +2 -2
- package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +1 -1
- package/dist/esm-node/commands/build.js +3 -0
- package/dist/esm-node/commands/dev.js +24 -16
- package/dist/esm-node/commands/index.js +7 -7
- package/dist/esm-node/index.js +1 -17
- package/dist/esm-node/plugins/analyze/index.js +7 -5
- package/dist/esm-node/plugins/deploy/dependencies/index.js +26 -7
- package/dist/esm-node/plugins/deploy/dependencies/utils.js +83 -3
- package/dist/esm-node/utils/config.js +5 -20
- package/dist/esm-node/utils/createServer.js +1 -1
- package/dist/types/builder/index.d.ts +1 -1
- package/dist/types/plugins/deploy/dependencies/index.d.ts +5 -3
- package/dist/types/plugins/deploy/dependencies/utils.d.ts +7 -1
- package/dist/types/plugins/deploy/platforms/netlifyEntry.d.ts +2 -0
- package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +2 -0
- package/dist/types/utils/config.d.ts +0 -5
- package/package.json +23 -21
- package/dist/cjs/esm/esbuild-loader.mjs +0 -20
- package/dist/cjs/esm/register-esm.mjs +0 -65
- package/dist/cjs/esm/ts-node-loader.mjs +0 -21
- package/dist/cjs/esm/utils.mjs +0 -43
- package/dist/cjs/plugins/deploy/platforms/netlify-entry.js +0 -3
- package/dist/cjs/plugins/deploy/platforms/netlify-entry.mjs +0 -1
- package/dist/cjs/plugins/deploy/platforms/vercel-entry.js +0 -3
- package/dist/cjs/plugins/deploy/platforms/vercel-entry.mjs +0 -3
- package/dist/esm/custom-loader.mjs +0 -41
- package/dist/esm/register-esm.mjs +0 -22
- package/dist/esm-node/esm/esbuild-loader.js +0 -39
- package/dist/esm-node/esm/register-esm.js +0 -39
- package/dist/esm-node/esm/ts-node-loader.js +0 -42
- package/dist/types/esm/esbuild-loader.d.mts +0 -6
- package/dist/types/esm/register-esm.d.mts +0 -5
- package/dist/types/esm/ts-node-loader.d.mts +0 -6
- package/dist/types/esm/utils.d.mts +0 -6
- package/dist/types/plugins/deploy/platforms/netlify-entry.d.cts +0 -1
- package/dist/types/plugins/deploy/platforms/netlify-entry.d.mts +0 -1
- package/dist/types/plugins/deploy/platforms/netlify-handler.d.cts +0 -1
- package/dist/types/plugins/deploy/platforms/vercel-entry.d.cts +0 -2
- package/dist/types/plugins/deploy/platforms/vercel-entry.d.mts +0 -2
- package/dist/types/plugins/deploy/platforms/vercel-handler.d.cts +0 -1
- /package/dist/cjs/plugins/deploy/platforms/{node-entry.js → nodeEntry.js} +0 -0
- /package/dist/types/plugins/deploy/platforms/{node-entry.d.ts → nodeEntry.d.ts} +0 -0
@@ -1,4 +1,6 @@
|
|
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";
|
2
4
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
3
5
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
4
6
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
@@ -7,15 +9,21 @@ import path from "node:path";
|
|
7
9
|
import { fs as fse, pkgUp, semver } from "@modern-js/utils";
|
8
10
|
import { readPackageJSON } from "pkg-types";
|
9
11
|
import { parseNodeModulePath } from "mlly";
|
10
|
-
import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaultTraceFiles, findPackageParents, resolveTracedPath, readDirRecursive } from "./utils";
|
12
|
+
import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaultTraceFiles, findPackageParents, resolveTracedPath, readDirRecursive, isSubPath } from "./utils";
|
13
|
+
import { nodeFileTrace } from "@vercel/nft";
|
11
14
|
var handleDependencies = function() {
|
12
15
|
var _ref = _async_to_generator(function(param) {
|
13
|
-
var appDir, serverRootDir, includeEntries, _param_traceFiles, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, base, entryFiles, fileTrace, currentProjectModules, 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;
|
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
17
|
return _ts_generator(this, function(_state) {
|
15
18
|
switch (_state.label) {
|
16
19
|
case 0:
|
17
|
-
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
|
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
|
+
fileCache: true,
|
23
|
+
analysisCache: true
|
24
|
+
} : _param_cacheOptions, traceOptions = param.traceOptions;
|
18
25
|
base = "/";
|
26
|
+
startTime = Date.now();
|
19
27
|
return [
|
20
28
|
4,
|
21
29
|
findEntryFiles(serverRootDir, entryFilter)
|
@@ -24,11 +32,20 @@ var handleDependencies = function() {
|
|
24
32
|
entryFiles = _state.sent();
|
25
33
|
return [
|
26
34
|
4,
|
27
|
-
traceFiles(
|
35
|
+
traceFiles({
|
36
|
+
entryFiles: entryFiles.concat(includeEntries),
|
37
|
+
serverRootDir,
|
38
|
+
cacheOptions: _object_spread_props(_object_spread({}, cacheOptions), {
|
39
|
+
cacheDir: path.resolve(appDir, cacheOptions.cacheDir)
|
40
|
+
}),
|
41
|
+
base,
|
42
|
+
traceOptions
|
43
|
+
})
|
28
44
|
];
|
29
45
|
case 2:
|
30
46
|
fileTrace = _state.sent();
|
31
47
|
currentProjectModules = path.join(appDir, "node_modules");
|
48
|
+
dependencySearchRoot = path.resolve(appDir, "../../../../../../");
|
32
49
|
_ = Object.fromEntries;
|
33
50
|
return [
|
34
51
|
4,
|
@@ -50,7 +67,7 @@ var handleDependencies = function() {
|
|
50
67
|
];
|
51
68
|
case 1:
|
52
69
|
filePath = _state2.sent();
|
53
|
-
if (
|
70
|
+
if (isSubPath(serverRootDir, filePath) || isSubPath(appDir, filePath) && !isSubPath(currentProjectModules, filePath)) {
|
54
71
|
return [
|
55
72
|
2
|
56
73
|
];
|
@@ -105,7 +122,7 @@ var handleDependencies = function() {
|
|
105
122
|
_state2.label = 6;
|
106
123
|
case 6:
|
107
124
|
packageJsonPath = _tmp;
|
108
|
-
if (!packageJsonPath)
|
125
|
+
if (!(packageJsonPath && isSubPath(dependencySearchRoot, packageJsonPath)))
|
109
126
|
return [
|
110
127
|
3,
|
111
128
|
8
|
@@ -138,7 +155,7 @@ var handleDependencies = function() {
|
|
138
155
|
path: filePath,
|
139
156
|
parents,
|
140
157
|
isDirectDep: parents.some(function(parent) {
|
141
|
-
return
|
158
|
+
return isSubPath(appDir, parent) && !isSubPath(currentProjectModules, parent);
|
142
159
|
}),
|
143
160
|
subpath,
|
144
161
|
pkgName: pkgName2,
|
@@ -591,6 +608,8 @@ var handleDependencies = function() {
|
|
591
608
|
];
|
592
609
|
case 24:
|
593
610
|
_state.sent();
|
611
|
+
endTime = Date.now();
|
612
|
+
console.log("handleDependencies cost:", endTime - startTime);
|
594
613
|
return [
|
595
614
|
2
|
596
615
|
];
|
@@ -602,5 +621,6 @@ var handleDependencies = function() {
|
|
602
621
|
};
|
603
622
|
}();
|
604
623
|
export {
|
605
|
-
handleDependencies
|
624
|
+
handleDependencies,
|
625
|
+
nodeFileTrace
|
606
626
|
};
|
@@ -1,4 +1,7 @@
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
+
import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
|
3
|
+
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
4
|
+
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
2
5
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
3
6
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
4
7
|
import path from "path";
|
@@ -334,30 +337,299 @@ var findPackageParents = function(pkg, version, tracedFiles) {
|
|
334
337
|
return parentPkg;
|
335
338
|
});
|
336
339
|
};
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
340
|
+
function serializeMap(map) {
|
341
|
+
return _serializeMap.apply(this, arguments);
|
342
|
+
}
|
343
|
+
function _serializeMap() {
|
344
|
+
_serializeMap = // function serializeMap(map: Map<string, any>) {
|
345
|
+
// return JSON.stringify(map, (key, value) => {
|
346
|
+
// if (value instanceof Map) {
|
347
|
+
// return {
|
348
|
+
// dataType: 'Map',
|
349
|
+
// value: [...value.entries()],
|
350
|
+
// };
|
351
|
+
// }
|
352
|
+
// if (value instanceof Set) {
|
353
|
+
// return {
|
354
|
+
// dataType: 'Set',
|
355
|
+
// value: [...value],
|
356
|
+
// };
|
357
|
+
// }
|
358
|
+
// return value;
|
359
|
+
// });
|
360
|
+
// }
|
361
|
+
_async_to_generator(function(map) {
|
362
|
+
var resolvedMap;
|
341
363
|
return _ts_generator(this, function(_state) {
|
342
364
|
switch (_state.label) {
|
343
365
|
case 0:
|
344
|
-
|
366
|
+
resolvedMap = /* @__PURE__ */ new Map();
|
345
367
|
return [
|
346
368
|
4,
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
369
|
+
Promise.all(Array.from(map.entries()).map(function() {
|
370
|
+
var _ref = _async_to_generator(function(param) {
|
371
|
+
var _param, key, value, _, _tmp, _tmp1;
|
372
|
+
return _ts_generator(this, function(_state2) {
|
373
|
+
switch (_state2.label) {
|
374
|
+
case 0:
|
375
|
+
_param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
|
376
|
+
_ = resolvedMap.set;
|
377
|
+
_tmp = [
|
378
|
+
key
|
379
|
+
];
|
380
|
+
if (!_instanceof(value, Promise))
|
381
|
+
return [
|
382
|
+
3,
|
383
|
+
2
|
384
|
+
];
|
385
|
+
return [
|
386
|
+
4,
|
387
|
+
Promise.resolve(value)
|
388
|
+
];
|
389
|
+
case 1:
|
390
|
+
_tmp1 = _state2.sent();
|
391
|
+
return [
|
392
|
+
3,
|
393
|
+
3
|
394
|
+
];
|
395
|
+
case 2:
|
396
|
+
_tmp1 = value;
|
397
|
+
_state2.label = 3;
|
398
|
+
case 3:
|
399
|
+
_.apply(resolvedMap, _tmp.concat([
|
400
|
+
_tmp1
|
401
|
+
]));
|
402
|
+
return [
|
403
|
+
2
|
404
|
+
];
|
405
|
+
}
|
406
|
+
});
|
407
|
+
});
|
408
|
+
return function(_) {
|
409
|
+
return _ref.apply(this, arguments);
|
410
|
+
};
|
411
|
+
}()))
|
351
412
|
];
|
352
413
|
case 1:
|
414
|
+
_state.sent();
|
353
415
|
return [
|
354
416
|
2,
|
417
|
+
JSON.stringify(resolvedMap, function(key, value) {
|
418
|
+
if (_instanceof(value, Map)) {
|
419
|
+
return {
|
420
|
+
dataType: "Map",
|
421
|
+
value: Array.from(value.entries())
|
422
|
+
};
|
423
|
+
}
|
424
|
+
if (_instanceof(value, Set)) {
|
425
|
+
return {
|
426
|
+
dataType: "Set",
|
427
|
+
value: Array.from(value)
|
428
|
+
};
|
429
|
+
}
|
430
|
+
return value;
|
431
|
+
})
|
432
|
+
];
|
433
|
+
}
|
434
|
+
});
|
435
|
+
});
|
436
|
+
return _serializeMap.apply(this, arguments);
|
437
|
+
}
|
438
|
+
function deserializeMap(serializedData) {
|
439
|
+
return JSON.parse(serializedData, function(key, value) {
|
440
|
+
if (value && value.dataType === "Map") {
|
441
|
+
return new Map(value.value);
|
442
|
+
}
|
443
|
+
if (value && value.dataType === "Set") {
|
444
|
+
return new Set(value.value);
|
445
|
+
}
|
446
|
+
return value;
|
447
|
+
});
|
448
|
+
}
|
449
|
+
var traceFiles = function() {
|
450
|
+
var _ref = _async_to_generator(function(param) {
|
451
|
+
var entryFiles, serverRootDir, _param_base, base, cacheOptions, traceOptions, cacheDir, enableFileCache, enableAnalysisCache, analysisCacheFile, fileCacheFile, cache, _tmp, analysisCache, _tmp1, fileCache, res, analysisCache1, fileCache1, newAnalysisCache, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, key, _, _tmp2, newFileCache, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, key1, _1, _tmp3;
|
452
|
+
return _ts_generator(this, function(_state) {
|
453
|
+
switch (_state.label) {
|
454
|
+
case 0:
|
455
|
+
entryFiles = param.entryFiles, serverRootDir = param.serverRootDir, _param_base = param.base, base = _param_base === void 0 ? "/" : _param_base, cacheOptions = param.cacheOptions, traceOptions = param.traceOptions;
|
456
|
+
cacheDir = cacheOptions.cacheDir, enableFileCache = cacheOptions.fileCache, enableAnalysisCache = cacheOptions.analysisCache;
|
457
|
+
analysisCacheFile = path.join(cacheDir, "analysis-cache.json");
|
458
|
+
fileCacheFile = path.join(cacheDir, "file-cache.json");
|
459
|
+
cache = /* @__PURE__ */ Object.create(null);
|
460
|
+
_tmp = enableAnalysisCache;
|
461
|
+
if (!_tmp)
|
462
|
+
return [
|
463
|
+
3,
|
464
|
+
2
|
465
|
+
];
|
466
|
+
return [
|
467
|
+
4,
|
468
|
+
fse.pathExists(analysisCacheFile)
|
469
|
+
];
|
470
|
+
case 1:
|
471
|
+
_tmp = _state.sent();
|
472
|
+
_state.label = 2;
|
473
|
+
case 2:
|
474
|
+
if (!_tmp)
|
475
|
+
return [
|
476
|
+
3,
|
477
|
+
4
|
478
|
+
];
|
479
|
+
return [
|
480
|
+
4,
|
481
|
+
fse.readFile(analysisCacheFile)
|
482
|
+
];
|
483
|
+
case 3:
|
484
|
+
analysisCache = _state.sent().toString();
|
485
|
+
cache.analysisCache = deserializeMap(analysisCache);
|
486
|
+
_state.label = 4;
|
487
|
+
case 4:
|
488
|
+
_tmp1 = enableFileCache;
|
489
|
+
if (!_tmp1)
|
490
|
+
return [
|
491
|
+
3,
|
492
|
+
6
|
493
|
+
];
|
494
|
+
return [
|
495
|
+
4,
|
496
|
+
fse.pathExists(fileCacheFile)
|
497
|
+
];
|
498
|
+
case 5:
|
499
|
+
_tmp1 = _state.sent();
|
500
|
+
_state.label = 6;
|
501
|
+
case 6:
|
502
|
+
if (!_tmp1)
|
503
|
+
return [
|
504
|
+
3,
|
505
|
+
8
|
506
|
+
];
|
507
|
+
return [
|
508
|
+
4,
|
509
|
+
fse.readFile(fileCacheFile)
|
510
|
+
];
|
511
|
+
case 7:
|
512
|
+
fileCache = _state.sent().toString();
|
513
|
+
cache.fileCache = deserializeMap(fileCache);
|
514
|
+
_state.label = 8;
|
515
|
+
case 8:
|
516
|
+
return [
|
517
|
+
4,
|
518
|
+
nodeFileTrace(entryFiles, _object_spread({
|
519
|
+
base,
|
520
|
+
processCwd: serverRootDir,
|
521
|
+
cache
|
522
|
+
}, traceOptions))
|
523
|
+
];
|
524
|
+
case 9:
|
525
|
+
res = _state.sent();
|
526
|
+
analysisCache1 = cache.analysisCache, fileCache1 = cache.fileCache;
|
527
|
+
if (!(analysisCache1 || fileCache1))
|
528
|
+
return [
|
529
|
+
3,
|
530
|
+
14
|
531
|
+
];
|
532
|
+
return [
|
533
|
+
4,
|
534
|
+
fse.ensureDir(cacheDir)
|
535
|
+
];
|
536
|
+
case 10:
|
537
|
+
_state.sent();
|
538
|
+
if (!analysisCache1)
|
539
|
+
return [
|
540
|
+
3,
|
541
|
+
12
|
542
|
+
];
|
543
|
+
newAnalysisCache = new Map(analysisCache1);
|
544
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
545
|
+
try {
|
546
|
+
for (_iterator = newAnalysisCache.keys()[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
547
|
+
key = _step.value;
|
548
|
+
if (!key.includes("node_modules/")) {
|
549
|
+
newAnalysisCache.delete(key);
|
550
|
+
}
|
551
|
+
}
|
552
|
+
} catch (err) {
|
553
|
+
_didIteratorError = true;
|
554
|
+
_iteratorError = err;
|
555
|
+
} finally {
|
556
|
+
try {
|
557
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
558
|
+
_iterator.return();
|
559
|
+
}
|
560
|
+
} finally {
|
561
|
+
if (_didIteratorError) {
|
562
|
+
throw _iteratorError;
|
563
|
+
}
|
564
|
+
}
|
565
|
+
}
|
566
|
+
_ = fse.writeFile;
|
567
|
+
_tmp2 = [
|
568
|
+
analysisCacheFile
|
569
|
+
];
|
570
|
+
return [
|
571
|
+
4,
|
572
|
+
serializeMap(newAnalysisCache)
|
573
|
+
];
|
574
|
+
case 11:
|
575
|
+
_.apply(fse, _tmp2.concat([
|
576
|
+
_state.sent()
|
577
|
+
]));
|
578
|
+
_state.label = 12;
|
579
|
+
case 12:
|
580
|
+
if (!fileCache1)
|
581
|
+
return [
|
582
|
+
3,
|
583
|
+
14
|
584
|
+
];
|
585
|
+
newFileCache = new Map(fileCache1);
|
586
|
+
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
|
587
|
+
try {
|
588
|
+
for (_iterator1 = newFileCache.keys()[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
|
589
|
+
key1 = _step1.value;
|
590
|
+
if (!key1.includes("node_modules/")) {
|
591
|
+
newFileCache.delete(key1);
|
592
|
+
}
|
593
|
+
}
|
594
|
+
} catch (err) {
|
595
|
+
_didIteratorError1 = true;
|
596
|
+
_iteratorError1 = err;
|
597
|
+
} finally {
|
598
|
+
try {
|
599
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
600
|
+
_iterator1.return();
|
601
|
+
}
|
602
|
+
} finally {
|
603
|
+
if (_didIteratorError1) {
|
604
|
+
throw _iteratorError1;
|
605
|
+
}
|
606
|
+
}
|
607
|
+
}
|
608
|
+
console.time("111");
|
609
|
+
_1 = fse.writeFile;
|
610
|
+
_tmp3 = [
|
611
|
+
fileCacheFile
|
612
|
+
];
|
613
|
+
return [
|
614
|
+
4,
|
615
|
+
serializeMap(newFileCache)
|
616
|
+
];
|
617
|
+
case 13:
|
618
|
+
_1.apply(fse, _tmp3.concat([
|
355
619
|
_state.sent()
|
620
|
+
]));
|
621
|
+
console.timeEnd("111");
|
622
|
+
_state.label = 14;
|
623
|
+
case 14:
|
624
|
+
console.log("ffffffff", __filename);
|
625
|
+
return [
|
626
|
+
2,
|
627
|
+
res
|
356
628
|
];
|
357
629
|
}
|
358
630
|
});
|
359
631
|
});
|
360
|
-
return function traceFiles2(
|
632
|
+
return function traceFiles2(_) {
|
361
633
|
return _ref.apply(this, arguments);
|
362
634
|
};
|
363
635
|
}();
|
@@ -374,10 +646,18 @@ var resolveTracedPath = function() {
|
|
374
646
|
return _ref.apply(this, arguments);
|
375
647
|
};
|
376
648
|
}();
|
649
|
+
var isSubPath = function(parentPath, childPath) {
|
650
|
+
if (!parentPath || !childPath) {
|
651
|
+
return false;
|
652
|
+
}
|
653
|
+
var relative = path.relative(parentPath, childPath);
|
654
|
+
return relative && !relative.startsWith("..");
|
655
|
+
};
|
377
656
|
export {
|
378
657
|
findEntryFiles,
|
379
658
|
findPackageParents,
|
380
659
|
isFile,
|
660
|
+
isSubPath,
|
381
661
|
linkPackage,
|
382
662
|
readDirRecursive,
|
383
663
|
resolveTracedPath,
|
package/dist/esm/utils/config.js
CHANGED
@@ -5,6 +5,7 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
5
|
import * as path from "path";
|
6
6
|
import { bundle } from "@modern-js/node-bundle-require";
|
7
7
|
import { fs, getServerConfig, ensureAbsolutePath, OUTPUT_CONFIG_FILE, CONFIG_FILE_EXTENSIONS } from "@modern-js/utils";
|
8
|
+
import { stringify } from "flatted";
|
8
9
|
var defineServerConfig = function(config) {
|
9
10
|
return config;
|
10
11
|
};
|
@@ -88,33 +89,18 @@ var buildServerConfig = function() {
|
|
88
89
|
return _ref.apply(this, arguments);
|
89
90
|
};
|
90
91
|
}();
|
91
|
-
var safeReplacer = function() {
|
92
|
-
var cache = [];
|
93
|
-
var keyCache = [];
|
94
|
-
return function safeReplacer2(key, value) {
|
95
|
-
if (typeof value === "object" && value !== null) {
|
96
|
-
var index = cache.indexOf(value);
|
97
|
-
if (index !== -1) {
|
98
|
-
return "[Circular ".concat(keyCache[index], "]");
|
99
|
-
}
|
100
|
-
cache.push(value);
|
101
|
-
keyCache.push(key || "root");
|
102
|
-
}
|
103
|
-
return value;
|
104
|
-
};
|
105
|
-
};
|
106
92
|
var emitResolvedConfig = function() {
|
107
93
|
var _ref = _async_to_generator(function(appDirectory, resolvedConfig) {
|
108
|
-
var _resolvedConfig_output_distPath, outputPath;
|
94
|
+
var _resolvedConfig_output_distPath, outputPath, output;
|
109
95
|
return _ts_generator(this, function(_state) {
|
110
96
|
switch (_state.label) {
|
111
97
|
case 0:
|
112
98
|
outputPath = ensureAbsolutePath(appDirectory, path.join(((_resolvedConfig_output_distPath = resolvedConfig.output.distPath) === null || _resolvedConfig_output_distPath === void 0 ? void 0 : _resolvedConfig_output_distPath.root) || "./dist", OUTPUT_CONFIG_FILE));
|
99
|
+
output = stringify(resolvedConfig);
|
113
100
|
return [
|
114
101
|
4,
|
115
|
-
fs.
|
116
|
-
|
117
|
-
replacer: safeReplacer()
|
102
|
+
fs.writeFile(outputPath, output, {
|
103
|
+
encoding: "utf-8"
|
118
104
|
})
|
119
105
|
];
|
120
106
|
case 1:
|
@@ -132,6 +118,5 @@ var emitResolvedConfig = function() {
|
|
132
118
|
export {
|
133
119
|
buildServerConfig,
|
134
120
|
defineServerConfig,
|
135
|
-
emitResolvedConfig
|
136
|
-
safeReplacer
|
121
|
+
emitResolvedConfig
|
137
122
|
};
|
@@ -40,10 +40,10 @@ const builderPluginAdpaterCopy = (options) => ({
|
|
40
40
|
const filepaths = (await fs.readdir(publicDir)).map((file) => path.resolve(publicDir, file));
|
41
41
|
await Promise.all(filepaths.filter((file) => HTML_REGEXP.test(file)).map(async (file) => {
|
42
42
|
const content = await fs.readFile(file, "utf-8");
|
43
|
-
if (publicPath) {
|
43
|
+
if (publicPath && typeof publicPath === "string") {
|
44
44
|
await fs.writeFile(file, content.replace(/<%=\s*assetPrefix\s*%>/g, removeTailSlash(publicPath)));
|
45
45
|
} else {
|
46
|
-
logger.warn(
|
46
|
+
logger.warn(`Expect get a string from \`publicPath\`, but receive \`${typeof publicPath}\`.`);
|
47
47
|
await fs.writeFile(file, content.replace(/<%=\s*assetPrefix\s*%>/g, removeTailSlash("/")));
|
48
48
|
}
|
49
49
|
}));
|
@@ -19,7 +19,7 @@ function getBuilderEnvironments(normalizedConfig, appContext) {
|
|
19
19
|
const serverEntries = {};
|
20
20
|
for (const entry in entries) {
|
21
21
|
const v = entries[entry];
|
22
|
-
serverEntries[entry] = v.map((entry2) => entry2.replace("index.jsx", "index.server.jsx"));
|
22
|
+
serverEntries[entry] = v.map((entry2) => entry2.replace("index.jsx", "index.server.jsx")).map((entry2) => entry2.replace("bootstrap.jsx", "bootstrap.server.jsx"));
|
23
23
|
}
|
24
24
|
const environments = {
|
25
25
|
web: {
|
@@ -17,7 +17,7 @@ async function generateBuilder(options, bundlerType) {
|
|
17
17
|
return builder;
|
18
18
|
}
|
19
19
|
async function applyBuilderPlugins(builder, options) {
|
20
|
-
const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, builderPluginAdapterWorker } = await import("../shared/builderPlugins
|
20
|
+
const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR, builderPluginAdapterWorker } = await import("../shared/builderPlugins");
|
21
21
|
builder.addPlugins([
|
22
22
|
builderPluginAdapterBasic(),
|
23
23
|
builderPluginAdapterSSR(options),
|
@@ -1,9 +1,9 @@
|
|
1
1
|
async function createBuilderGenerator(bundler) {
|
2
2
|
if (bundler === "rspack") {
|
3
|
-
const { createRspackBuilderForModern } = await import("./builder-rspack
|
3
|
+
const { createRspackBuilderForModern } = await import("./builder-rspack");
|
4
4
|
return createRspackBuilderForModern;
|
5
5
|
}
|
6
|
-
const { createWebpackBuilderForModern } = await import("./builder-webpack
|
6
|
+
const { createWebpackBuilderForModern } = await import("./builder-webpack");
|
7
7
|
return createWebpackBuilderForModern;
|
8
8
|
}
|
9
9
|
export {
|
@@ -3,7 +3,9 @@ import { logger } from "@modern-js/utils";
|
|
3
3
|
import { loadServerPlugins } from "../utils/loadPlugins";
|
4
4
|
import { generateRoutes } from "../utils/routes";
|
5
5
|
import { buildServerConfig } from "../utils/config";
|
6
|
+
import { registerCompiler } from "../utils/register";
|
6
7
|
const build = async (api, options) => {
|
8
|
+
var _resolvedConfig_source;
|
7
9
|
if (options === null || options === void 0 ? void 0 : options.analyze) {
|
8
10
|
process.env.BUNDLE_ANALYZE = "true";
|
9
11
|
}
|
@@ -11,6 +13,7 @@ const build = async (api, options) => {
|
|
11
13
|
const appContext = api.useAppContext();
|
12
14
|
const hookRunners = api.useHookRunners();
|
13
15
|
await loadServerPlugins(api, appContext.appDirectory, appContext.metaName);
|
16
|
+
await registerCompiler(appContext.appDirectory, appContext.distDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.alias);
|
14
17
|
const { apiOnly } = appContext;
|
15
18
|
if (apiOnly) {
|
16
19
|
const { appDirectory: appDirectory2, distDirectory: distDirectory2, serverConfigFile: serverConfigFile2 } = appContext;
|
@@ -1,27 +1,23 @@
|
|
1
1
|
import path from "node:path";
|
2
2
|
import { ResolvedConfigContext } from "@modern-js/core";
|
3
|
-
import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta } from "@modern-js/utils";
|
3
|
+
import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta, logger } from "@modern-js/utils";
|
4
4
|
import { createDevServer } from "@modern-js/server";
|
5
5
|
import { applyPlugins } from "@modern-js/prod-server";
|
6
6
|
import { loadServerPlugins } from "../utils/loadPlugins";
|
7
|
+
import { registerCompiler } from "../utils/register";
|
7
8
|
import { printInstructions } from "../utils/printInstructions";
|
8
9
|
import { setServer } from "../utils/createServer";
|
9
10
|
import { generateRoutes } from "../utils/routes";
|
10
11
|
import { buildServerConfig } from "../utils/config";
|
11
|
-
const dev = async (api, options, devServerOptions
|
12
|
-
var _normalizedConfig_source, _normalizedConfig_tools;
|
12
|
+
const dev = async (api, options, devServerOptions) => {
|
13
|
+
var _normalizedConfig_source, _normalizedConfig_tools, _normalizedConfig_dev;
|
13
14
|
if (options.analyze) {
|
14
15
|
process.env.BUNDLE_ANALYZE = "true";
|
15
16
|
}
|
16
17
|
let normalizedConfig = api.useResolvedConfigContext();
|
17
18
|
const appContext = api.useAppContext();
|
18
19
|
const hookRunners = api.useHookRunners();
|
19
|
-
|
20
|
-
await registerEsm({
|
21
|
-
appDir: appContext.appDirectory,
|
22
|
-
distDir: appContext.distDirectory,
|
23
|
-
alias: (_normalizedConfig_source = normalizedConfig.source) === null || _normalizedConfig_source === void 0 ? void 0 : _normalizedConfig_source.alias
|
24
|
-
});
|
20
|
+
await registerCompiler(appContext.appDirectory, appContext.distDirectory, normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_source = normalizedConfig.source) === null || _normalizedConfig_source === void 0 ? void 0 : _normalizedConfig_source.alias);
|
25
21
|
normalizedConfig = {
|
26
22
|
...normalizedConfig,
|
27
23
|
cliOptions: options
|
@@ -64,20 +60,32 @@ const dev = async (api, options, devServerOptions = {}) => {
|
|
64
60
|
plugins: pluginInstances,
|
65
61
|
...devServerOptions
|
66
62
|
};
|
63
|
+
const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
|
67
64
|
if (apiOnly) {
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
65
|
+
const { server } = await createDevServer({
|
66
|
+
...serverOptions,
|
67
|
+
runCompile: false
|
68
|
+
}, (devServerOptions === null || devServerOptions === void 0 ? void 0 : devServerOptions.applyPlugins) || applyPlugins);
|
69
|
+
server.listen({
|
72
70
|
port,
|
73
71
|
host
|
74
72
|
}, () => {
|
75
73
|
printInstructions(hookRunners, appContext, normalizedConfig);
|
76
74
|
});
|
77
75
|
} else {
|
78
|
-
const { server } = await
|
79
|
-
serverOptions,
|
80
|
-
|
76
|
+
const { server, afterListen } = await createDevServer({
|
77
|
+
...serverOptions,
|
78
|
+
builder: appContext.builder
|
79
|
+
}, (devServerOptions === null || devServerOptions === void 0 ? void 0 : devServerOptions.applyPlugins) || applyPlugins);
|
80
|
+
server.listen({
|
81
|
+
port,
|
82
|
+
host
|
83
|
+
}, async (err) => {
|
84
|
+
if (err) {
|
85
|
+
logger.error("Occur error %s, when start dev server", err);
|
86
|
+
}
|
87
|
+
logger.debug("listen dev server done");
|
88
|
+
await afterListen();
|
81
89
|
});
|
82
90
|
setServer(server);
|
83
91
|
}
|