@modern-js/app-tools 2.58.0 → 2.58.1-alpha.1
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/cjs/plugins/deploy/dependencies/index.js +14 -1
- package/dist/cjs/plugins/deploy/dependencies/utils.js +98 -2
- package/dist/cjs/utils/config.js +6 -22
- package/dist/esm/plugins/deploy/dependencies/index.js +16 -2
- package/dist/esm/plugins/deploy/dependencies/utils.js +379 -5
- package/dist/esm/utils/config.js +6 -21
- package/dist/esm-node/plugins/deploy/dependencies/index.js +14 -1
- package/dist/esm-node/plugins/deploy/dependencies/utils.js +98 -2
- package/dist/esm-node/utils/config.js +5 -20
- 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/utils/config.d.ts +0 -5
- package/package.json +16 -14
|
@@ -38,15 +38,26 @@ 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,
|
|
41
|
+
const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = import_utils2.traceFiles, entryFilter, modifyPackageJson, copyWholePackage, cacheOptions = {
|
|
42
|
+
cacheDir: ".modern-js/deploy",
|
|
43
|
+
fileCache: true,
|
|
44
|
+
analysisCache: true
|
|
45
|
+
}, traceOptions }) => {
|
|
42
46
|
const base = "/";
|
|
47
|
+
const startTime = Date.now();
|
|
43
48
|
const entryFiles = await (0, import_utils2.findEntryFiles)(serverRootDir, entryFilter);
|
|
49
|
+
console.time("traceFiles");
|
|
44
50
|
const fileTrace = await traceFiles({
|
|
45
51
|
entryFiles: entryFiles.concat(includeEntries),
|
|
46
52
|
serverRootDir,
|
|
53
|
+
cacheOptions: {
|
|
54
|
+
...cacheOptions,
|
|
55
|
+
cacheDir: import_node_path.default.resolve(appDir, cacheOptions.cacheDir)
|
|
56
|
+
},
|
|
47
57
|
base,
|
|
48
58
|
traceOptions
|
|
49
59
|
});
|
|
60
|
+
console.timeEnd("traceFiles");
|
|
50
61
|
const currentProjectModules = import_node_path.default.join(appDir, "node_modules");
|
|
51
62
|
const dependencySearchRoot = import_node_path.default.resolve(appDir, "../../../../../../");
|
|
52
63
|
const tracedFiles = Object.fromEntries(await Promise.all([
|
|
@@ -228,6 +239,8 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
|
|
|
228
239
|
};
|
|
229
240
|
const finalPkgJson = (modifyPackageJson === null || modifyPackageJson === void 0 ? void 0 : modifyPackageJson(newPkgJson)) || newPkgJson;
|
|
230
241
|
await import_utils.fs.writeJSON(outputPkgPath, finalPkgJson);
|
|
242
|
+
const endTime = Date.now();
|
|
243
|
+
console.log("handleDependencies cost:", `${endTime - startTime}ms`);
|
|
231
244
|
};
|
|
232
245
|
// Annotate the CommonJS export names for ESM import in node:
|
|
233
246
|
0 && (module.exports = {
|
|
@@ -139,12 +139,108 @@ const findPackageParents = (pkg, version, tracedFiles) => {
|
|
|
139
139
|
];
|
|
140
140
|
return parentPkgs.filter((parentPkg) => parentPkg);
|
|
141
141
|
};
|
|
142
|
-
|
|
143
|
-
|
|
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 instanceof Map) {
|
|
149
|
+
return {
|
|
150
|
+
dataType: "Map",
|
|
151
|
+
value: Array.from(value.entries())
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
if (value instanceof Set) {
|
|
155
|
+
return {
|
|
156
|
+
dataType: "Set",
|
|
157
|
+
value: Array.from(value)
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
if (value === null) {
|
|
161
|
+
return void 0;
|
|
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 traceFiles = async ({ entryFiles, serverRootDir, base = "/", cacheOptions, traceOptions }) => {
|
|
178
|
+
const { cacheDir, fileCache: enableFileCache, analysisCache: enableAnalysisCache } = cacheOptions;
|
|
179
|
+
const analysisCacheFile = import_path.default.join(cacheDir, "analysis-cache.json");
|
|
180
|
+
const fileCacheFile = import_path.default.join(cacheDir, "file-cache.json");
|
|
181
|
+
const statCacheFile = import_path.default.join(cacheDir, "stat-cache.json");
|
|
182
|
+
const symlinkCacheFile = import_path.default.join(cacheDir, "symlink-cache.json");
|
|
183
|
+
const cache = /* @__PURE__ */ Object.create(null);
|
|
184
|
+
if (enableAnalysisCache && await import_utils.fs.pathExists(analysisCacheFile)) {
|
|
185
|
+
const analysisCache2 = (await import_utils.fs.readFile(analysisCacheFile)).toString();
|
|
186
|
+
cache.analysisCache = deserializeMap(analysisCache2);
|
|
187
|
+
}
|
|
188
|
+
if (enableFileCache && await import_utils.fs.pathExists(fileCacheFile)) {
|
|
189
|
+
const fileCache2 = (await import_utils.fs.readFile(fileCacheFile)).toString();
|
|
190
|
+
cache.fileCache = deserializeMap(fileCache2);
|
|
191
|
+
}
|
|
192
|
+
if (await import_utils.fs.pathExists(symlinkCacheFile)) {
|
|
193
|
+
const symlinkCache2 = (await import_utils.fs.readFile(symlinkCacheFile)).toString();
|
|
194
|
+
cache.symlinkCache = deserializeMap(symlinkCache2);
|
|
195
|
+
}
|
|
196
|
+
const res = await (0, import_nft.nodeFileTrace)(entryFiles, {
|
|
144
197
|
base,
|
|
145
198
|
processCwd: serverRootDir,
|
|
199
|
+
cache,
|
|
146
200
|
...traceOptions
|
|
147
201
|
});
|
|
202
|
+
const { analysisCache, fileCache, statCache, symlinkCache } = cache;
|
|
203
|
+
if (analysisCache || fileCache || statCache || symlinkCache) {
|
|
204
|
+
await import_utils.fs.ensureDir(cacheDir);
|
|
205
|
+
if (analysisCache) {
|
|
206
|
+
const newAnalysisCache = new Map(analysisCache);
|
|
207
|
+
for (const key of newAnalysisCache.keys()) {
|
|
208
|
+
if (!key.includes("node_modules/")) {
|
|
209
|
+
newAnalysisCache.delete(key);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
(async () => {
|
|
213
|
+
await import_utils.fs.writeFile(analysisCacheFile, await serializeMap(newAnalysisCache));
|
|
214
|
+
console.log("write analysis cache finish");
|
|
215
|
+
})();
|
|
216
|
+
}
|
|
217
|
+
if (fileCache) {
|
|
218
|
+
const newFileCache = new Map(fileCache);
|
|
219
|
+
for (const key of newFileCache.keys()) {
|
|
220
|
+
if (!key.includes("node_modules/")) {
|
|
221
|
+
newFileCache.delete(key);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
(async () => {
|
|
225
|
+
await import_utils.fs.writeFile(fileCacheFile, await serializeMap(newFileCache));
|
|
226
|
+
console.log("write file cache finish");
|
|
227
|
+
})();
|
|
228
|
+
}
|
|
229
|
+
if (symlinkCache) {
|
|
230
|
+
const newSymlinkCache = new Map(symlinkCache);
|
|
231
|
+
for (const key of newSymlinkCache.keys()) {
|
|
232
|
+
if (!key.includes("node_modules/")) {
|
|
233
|
+
newSymlinkCache.delete(key);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
(async () => {
|
|
237
|
+
await import_utils.fs.writeFile(symlinkCacheFile, await serializeMap(newSymlinkCache));
|
|
238
|
+
console.log("write symlink cache finish");
|
|
239
|
+
})();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
console.log("ffffffff", __filename);
|
|
243
|
+
return res;
|
|
148
244
|
};
|
|
149
245
|
const resolveTracedPath = async (base, p) => import_utils.fs.realpath(import_path.default.resolve(base, p));
|
|
150
246
|
const isSubPath = (parentPath, childPath) => {
|
package/dist/cjs/utils/config.js
CHANGED
|
@@ -30,13 +30,13 @@ var config_exports = {};
|
|
|
30
30
|
__export(config_exports, {
|
|
31
31
|
buildServerConfig: () => buildServerConfig,
|
|
32
32
|
defineServerConfig: () => defineServerConfig,
|
|
33
|
-
emitResolvedConfig: () => emitResolvedConfig
|
|
34
|
-
safeReplacer: () => safeReplacer
|
|
33
|
+
emitResolvedConfig: () => emitResolvedConfig
|
|
35
34
|
});
|
|
36
35
|
module.exports = __toCommonJS(config_exports);
|
|
37
36
|
var path = __toESM(require("path"));
|
|
38
37
|
var import_node_bundle_require = require("@modern-js/node-bundle-require");
|
|
39
38
|
var import_utils = require("@modern-js/utils");
|
|
39
|
+
var import_flatted = require("flatted");
|
|
40
40
|
const defineServerConfig = (config) => config;
|
|
41
41
|
const buildServerConfig = async ({ appDirectory, distDirectory, configFile, options, watch }) => {
|
|
42
42
|
const configFilePath = await (0, import_utils.getServerConfig)(appDirectory, configFile);
|
|
@@ -69,33 +69,17 @@ const buildServerConfig = async ({ appDirectory, distDirectory, configFile, opti
|
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
};
|
|
72
|
-
const safeReplacer = () => {
|
|
73
|
-
const cache = [];
|
|
74
|
-
const keyCache = [];
|
|
75
|
-
return function(key, value) {
|
|
76
|
-
if (typeof value === "object" && value !== null) {
|
|
77
|
-
const index = cache.indexOf(value);
|
|
78
|
-
if (index !== -1) {
|
|
79
|
-
return `[Circular ${keyCache[index]}]`;
|
|
80
|
-
}
|
|
81
|
-
cache.push(value);
|
|
82
|
-
keyCache.push(key || "root");
|
|
83
|
-
}
|
|
84
|
-
return value;
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
72
|
const emitResolvedConfig = async (appDirectory, resolvedConfig) => {
|
|
88
73
|
var _resolvedConfig_output_distPath;
|
|
89
74
|
const outputPath = (0, import_utils.ensureAbsolutePath)(appDirectory, path.join(((_resolvedConfig_output_distPath = resolvedConfig.output.distPath) === null || _resolvedConfig_output_distPath === void 0 ? void 0 : _resolvedConfig_output_distPath.root) || "./dist", import_utils.OUTPUT_CONFIG_FILE));
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
75
|
+
const output = (0, import_flatted.stringify)(resolvedConfig);
|
|
76
|
+
await import_utils.fs.writeFile(outputPath, output, {
|
|
77
|
+
encoding: "utf-8"
|
|
93
78
|
});
|
|
94
79
|
};
|
|
95
80
|
// Annotate the CommonJS export names for ESM import in node:
|
|
96
81
|
0 && (module.exports = {
|
|
97
82
|
buildServerConfig,
|
|
98
83
|
defineServerConfig,
|
|
99
|
-
emitResolvedConfig
|
|
100
|
-
safeReplacer
|
|
84
|
+
emitResolvedConfig
|
|
101
85
|
});
|
|
@@ -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";
|
|
@@ -11,29 +13,39 @@ import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaul
|
|
|
11
13
|
import { nodeFileTrace } from "@vercel/nft";
|
|
12
14
|
var handleDependencies = function() {
|
|
13
15
|
var _ref = _async_to_generator(function(param) {
|
|
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;
|
|
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;
|
|
15
17
|
return _ts_generator(this, function(_state) {
|
|
16
18
|
switch (_state.label) {
|
|
17
19
|
case 0:
|
|
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,
|
|
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;
|
|
19
25
|
base = "/";
|
|
26
|
+
startTime = Date.now();
|
|
20
27
|
return [
|
|
21
28
|
4,
|
|
22
29
|
findEntryFiles(serverRootDir, entryFilter)
|
|
23
30
|
];
|
|
24
31
|
case 1:
|
|
25
32
|
entryFiles = _state.sent();
|
|
33
|
+
console.time("traceFiles");
|
|
26
34
|
return [
|
|
27
35
|
4,
|
|
28
36
|
traceFiles({
|
|
29
37
|
entryFiles: entryFiles.concat(includeEntries),
|
|
30
38
|
serverRootDir,
|
|
39
|
+
cacheOptions: _object_spread_props(_object_spread({}, cacheOptions), {
|
|
40
|
+
cacheDir: path.resolve(appDir, cacheOptions.cacheDir)
|
|
41
|
+
}),
|
|
31
42
|
base,
|
|
32
43
|
traceOptions
|
|
33
44
|
})
|
|
34
45
|
];
|
|
35
46
|
case 2:
|
|
36
47
|
fileTrace = _state.sent();
|
|
48
|
+
console.timeEnd("traceFiles");
|
|
37
49
|
currentProjectModules = path.join(appDir, "node_modules");
|
|
38
50
|
dependencySearchRoot = path.resolve(appDir, "../../../../../../");
|
|
39
51
|
_ = Object.fromEntries;
|
|
@@ -598,6 +610,8 @@ var handleDependencies = function() {
|
|
|
598
610
|
];
|
|
599
611
|
case 24:
|
|
600
612
|
_state.sent();
|
|
613
|
+
endTime = Date.now();
|
|
614
|
+
console.log("handleDependencies cost:", "".concat(endTime - startTime, "ms"));
|
|
601
615
|
return [
|
|
602
616
|
2
|
|
603
617
|
];
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
|
|
2
3
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
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";
|
|
5
7
|
import path from "path";
|
|
@@ -335,24 +337,396 @@ var findPackageParents = function(pkg, version, tracedFiles) {
|
|
|
335
337
|
return parentPkg;
|
|
336
338
|
});
|
|
337
339
|
};
|
|
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;
|
|
363
|
+
return _ts_generator(this, function(_state) {
|
|
364
|
+
switch (_state.label) {
|
|
365
|
+
case 0:
|
|
366
|
+
resolvedMap = /* @__PURE__ */ new Map();
|
|
367
|
+
return [
|
|
368
|
+
4,
|
|
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
|
+
}()))
|
|
412
|
+
];
|
|
413
|
+
case 1:
|
|
414
|
+
_state.sent();
|
|
415
|
+
return [
|
|
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
|
+
if (value === null) {
|
|
431
|
+
return void 0;
|
|
432
|
+
}
|
|
433
|
+
return value;
|
|
434
|
+
})
|
|
435
|
+
];
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
});
|
|
439
|
+
return _serializeMap.apply(this, arguments);
|
|
440
|
+
}
|
|
441
|
+
function deserializeMap(serializedData) {
|
|
442
|
+
return JSON.parse(serializedData, function(key, value) {
|
|
443
|
+
if (value && value.dataType === "Map") {
|
|
444
|
+
return new Map(value.value);
|
|
445
|
+
}
|
|
446
|
+
if (value && value.dataType === "Set") {
|
|
447
|
+
return new Set(value.value);
|
|
448
|
+
}
|
|
449
|
+
return value;
|
|
450
|
+
});
|
|
451
|
+
}
|
|
338
452
|
var traceFiles = function() {
|
|
339
453
|
var _ref = _async_to_generator(function(param) {
|
|
340
|
-
var entryFiles, serverRootDir, _param_base, base, traceOptions;
|
|
454
|
+
var entryFiles, serverRootDir, _param_base, base, cacheOptions, traceOptions, cacheDir, enableFileCache, enableAnalysisCache, analysisCacheFile, fileCacheFile, statCacheFile, symlinkCacheFile, cache, _tmp, analysisCache, _tmp1, fileCache, symlinkCache, res, analysisCache1, fileCache1, statCache, symlinkCache1, newAnalysisCache, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, key, newFileCache, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, key1, newSymlinkCache, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, key2;
|
|
341
455
|
return _ts_generator(this, function(_state) {
|
|
342
456
|
switch (_state.label) {
|
|
343
457
|
case 0:
|
|
344
|
-
entryFiles = param.entryFiles, serverRootDir = param.serverRootDir, _param_base = param.base, base = _param_base === void 0 ? "/" : _param_base, traceOptions = param.traceOptions;
|
|
458
|
+
entryFiles = param.entryFiles, serverRootDir = param.serverRootDir, _param_base = param.base, base = _param_base === void 0 ? "/" : _param_base, cacheOptions = param.cacheOptions, traceOptions = param.traceOptions;
|
|
459
|
+
cacheDir = cacheOptions.cacheDir, enableFileCache = cacheOptions.fileCache, enableAnalysisCache = cacheOptions.analysisCache;
|
|
460
|
+
analysisCacheFile = path.join(cacheDir, "analysis-cache.json");
|
|
461
|
+
fileCacheFile = path.join(cacheDir, "file-cache.json");
|
|
462
|
+
statCacheFile = path.join(cacheDir, "stat-cache.json");
|
|
463
|
+
symlinkCacheFile = path.join(cacheDir, "symlink-cache.json");
|
|
464
|
+
cache = /* @__PURE__ */ Object.create(null);
|
|
465
|
+
_tmp = enableAnalysisCache;
|
|
466
|
+
if (!_tmp)
|
|
467
|
+
return [
|
|
468
|
+
3,
|
|
469
|
+
2
|
|
470
|
+
];
|
|
471
|
+
return [
|
|
472
|
+
4,
|
|
473
|
+
fse.pathExists(analysisCacheFile)
|
|
474
|
+
];
|
|
475
|
+
case 1:
|
|
476
|
+
_tmp = _state.sent();
|
|
477
|
+
_state.label = 2;
|
|
478
|
+
case 2:
|
|
479
|
+
if (!_tmp)
|
|
480
|
+
return [
|
|
481
|
+
3,
|
|
482
|
+
4
|
|
483
|
+
];
|
|
484
|
+
return [
|
|
485
|
+
4,
|
|
486
|
+
fse.readFile(analysisCacheFile)
|
|
487
|
+
];
|
|
488
|
+
case 3:
|
|
489
|
+
analysisCache = _state.sent().toString();
|
|
490
|
+
cache.analysisCache = deserializeMap(analysisCache);
|
|
491
|
+
_state.label = 4;
|
|
492
|
+
case 4:
|
|
493
|
+
_tmp1 = enableFileCache;
|
|
494
|
+
if (!_tmp1)
|
|
495
|
+
return [
|
|
496
|
+
3,
|
|
497
|
+
6
|
|
498
|
+
];
|
|
499
|
+
return [
|
|
500
|
+
4,
|
|
501
|
+
fse.pathExists(fileCacheFile)
|
|
502
|
+
];
|
|
503
|
+
case 5:
|
|
504
|
+
_tmp1 = _state.sent();
|
|
505
|
+
_state.label = 6;
|
|
506
|
+
case 6:
|
|
507
|
+
if (!_tmp1)
|
|
508
|
+
return [
|
|
509
|
+
3,
|
|
510
|
+
8
|
|
511
|
+
];
|
|
512
|
+
return [
|
|
513
|
+
4,
|
|
514
|
+
fse.readFile(fileCacheFile)
|
|
515
|
+
];
|
|
516
|
+
case 7:
|
|
517
|
+
fileCache = _state.sent().toString();
|
|
518
|
+
cache.fileCache = deserializeMap(fileCache);
|
|
519
|
+
_state.label = 8;
|
|
520
|
+
case 8:
|
|
521
|
+
return [
|
|
522
|
+
4,
|
|
523
|
+
fse.pathExists(symlinkCacheFile)
|
|
524
|
+
];
|
|
525
|
+
case 9:
|
|
526
|
+
if (!_state.sent())
|
|
527
|
+
return [
|
|
528
|
+
3,
|
|
529
|
+
11
|
|
530
|
+
];
|
|
531
|
+
return [
|
|
532
|
+
4,
|
|
533
|
+
fse.readFile(symlinkCacheFile)
|
|
534
|
+
];
|
|
535
|
+
case 10:
|
|
536
|
+
symlinkCache = _state.sent().toString();
|
|
537
|
+
cache.symlinkCache = deserializeMap(symlinkCache);
|
|
538
|
+
_state.label = 11;
|
|
539
|
+
case 11:
|
|
345
540
|
return [
|
|
346
541
|
4,
|
|
347
542
|
nodeFileTrace(entryFiles, _object_spread({
|
|
348
543
|
base,
|
|
349
|
-
processCwd: serverRootDir
|
|
544
|
+
processCwd: serverRootDir,
|
|
545
|
+
cache
|
|
350
546
|
}, traceOptions))
|
|
351
547
|
];
|
|
352
|
-
case
|
|
548
|
+
case 12:
|
|
549
|
+
res = _state.sent();
|
|
550
|
+
analysisCache1 = cache.analysisCache, fileCache1 = cache.fileCache, statCache = cache.statCache, symlinkCache1 = cache.symlinkCache;
|
|
551
|
+
if (!(analysisCache1 || fileCache1 || statCache || symlinkCache1))
|
|
552
|
+
return [
|
|
553
|
+
3,
|
|
554
|
+
14
|
|
555
|
+
];
|
|
556
|
+
return [
|
|
557
|
+
4,
|
|
558
|
+
fse.ensureDir(cacheDir)
|
|
559
|
+
];
|
|
560
|
+
case 13:
|
|
561
|
+
_state.sent();
|
|
562
|
+
if (analysisCache1) {
|
|
563
|
+
newAnalysisCache = new Map(analysisCache1);
|
|
564
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
565
|
+
try {
|
|
566
|
+
for (_iterator = newAnalysisCache.keys()[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
567
|
+
key = _step.value;
|
|
568
|
+
if (!key.includes("node_modules/")) {
|
|
569
|
+
newAnalysisCache.delete(key);
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
} catch (err) {
|
|
573
|
+
_didIteratorError = true;
|
|
574
|
+
_iteratorError = err;
|
|
575
|
+
} finally {
|
|
576
|
+
try {
|
|
577
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
578
|
+
_iterator.return();
|
|
579
|
+
}
|
|
580
|
+
} finally {
|
|
581
|
+
if (_didIteratorError) {
|
|
582
|
+
throw _iteratorError;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
_async_to_generator(function() {
|
|
587
|
+
var _, _tmp2;
|
|
588
|
+
return _ts_generator(this, function(_state2) {
|
|
589
|
+
switch (_state2.label) {
|
|
590
|
+
case 0:
|
|
591
|
+
_ = fse.writeFile;
|
|
592
|
+
_tmp2 = [
|
|
593
|
+
analysisCacheFile
|
|
594
|
+
];
|
|
595
|
+
return [
|
|
596
|
+
4,
|
|
597
|
+
serializeMap(newAnalysisCache)
|
|
598
|
+
];
|
|
599
|
+
case 1:
|
|
600
|
+
return [
|
|
601
|
+
4,
|
|
602
|
+
_.apply(fse, _tmp2.concat([
|
|
603
|
+
_state2.sent()
|
|
604
|
+
]))
|
|
605
|
+
];
|
|
606
|
+
case 2:
|
|
607
|
+
_state2.sent();
|
|
608
|
+
console.log("write analysis cache finish");
|
|
609
|
+
return [
|
|
610
|
+
2
|
|
611
|
+
];
|
|
612
|
+
}
|
|
613
|
+
});
|
|
614
|
+
})();
|
|
615
|
+
}
|
|
616
|
+
if (fileCache1) {
|
|
617
|
+
newFileCache = new Map(fileCache1);
|
|
618
|
+
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
|
|
619
|
+
try {
|
|
620
|
+
for (_iterator1 = newFileCache.keys()[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
|
|
621
|
+
key1 = _step1.value;
|
|
622
|
+
if (!key1.includes("node_modules/")) {
|
|
623
|
+
newFileCache.delete(key1);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
} catch (err) {
|
|
627
|
+
_didIteratorError1 = true;
|
|
628
|
+
_iteratorError1 = err;
|
|
629
|
+
} finally {
|
|
630
|
+
try {
|
|
631
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
632
|
+
_iterator1.return();
|
|
633
|
+
}
|
|
634
|
+
} finally {
|
|
635
|
+
if (_didIteratorError1) {
|
|
636
|
+
throw _iteratorError1;
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
_async_to_generator(function() {
|
|
641
|
+
var _, _tmp2;
|
|
642
|
+
return _ts_generator(this, function(_state2) {
|
|
643
|
+
switch (_state2.label) {
|
|
644
|
+
case 0:
|
|
645
|
+
_ = fse.writeFile;
|
|
646
|
+
_tmp2 = [
|
|
647
|
+
fileCacheFile
|
|
648
|
+
];
|
|
649
|
+
return [
|
|
650
|
+
4,
|
|
651
|
+
serializeMap(newFileCache)
|
|
652
|
+
];
|
|
653
|
+
case 1:
|
|
654
|
+
return [
|
|
655
|
+
4,
|
|
656
|
+
_.apply(fse, _tmp2.concat([
|
|
657
|
+
_state2.sent()
|
|
658
|
+
]))
|
|
659
|
+
];
|
|
660
|
+
case 2:
|
|
661
|
+
_state2.sent();
|
|
662
|
+
console.log("write file cache finish");
|
|
663
|
+
return [
|
|
664
|
+
2
|
|
665
|
+
];
|
|
666
|
+
}
|
|
667
|
+
});
|
|
668
|
+
})();
|
|
669
|
+
}
|
|
670
|
+
if (symlinkCache1) {
|
|
671
|
+
newSymlinkCache = new Map(symlinkCache1);
|
|
672
|
+
_iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
|
|
673
|
+
try {
|
|
674
|
+
for (_iterator2 = newSymlinkCache.keys()[Symbol.iterator](); !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
675
|
+
key2 = _step2.value;
|
|
676
|
+
if (!key2.includes("node_modules/")) {
|
|
677
|
+
newSymlinkCache.delete(key2);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
} catch (err) {
|
|
681
|
+
_didIteratorError2 = true;
|
|
682
|
+
_iteratorError2 = err;
|
|
683
|
+
} finally {
|
|
684
|
+
try {
|
|
685
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
686
|
+
_iterator2.return();
|
|
687
|
+
}
|
|
688
|
+
} finally {
|
|
689
|
+
if (_didIteratorError2) {
|
|
690
|
+
throw _iteratorError2;
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
_async_to_generator(function() {
|
|
695
|
+
var _, _tmp2;
|
|
696
|
+
return _ts_generator(this, function(_state2) {
|
|
697
|
+
switch (_state2.label) {
|
|
698
|
+
case 0:
|
|
699
|
+
_ = fse.writeFile;
|
|
700
|
+
_tmp2 = [
|
|
701
|
+
symlinkCacheFile
|
|
702
|
+
];
|
|
703
|
+
return [
|
|
704
|
+
4,
|
|
705
|
+
serializeMap(newSymlinkCache)
|
|
706
|
+
];
|
|
707
|
+
case 1:
|
|
708
|
+
return [
|
|
709
|
+
4,
|
|
710
|
+
_.apply(fse, _tmp2.concat([
|
|
711
|
+
_state2.sent()
|
|
712
|
+
]))
|
|
713
|
+
];
|
|
714
|
+
case 2:
|
|
715
|
+
_state2.sent();
|
|
716
|
+
console.log("write symlink cache finish");
|
|
717
|
+
return [
|
|
718
|
+
2
|
|
719
|
+
];
|
|
720
|
+
}
|
|
721
|
+
});
|
|
722
|
+
})();
|
|
723
|
+
}
|
|
724
|
+
_state.label = 14;
|
|
725
|
+
case 14:
|
|
726
|
+
console.log("ffffffff", __filename);
|
|
353
727
|
return [
|
|
354
728
|
2,
|
|
355
|
-
|
|
729
|
+
res
|
|
356
730
|
];
|
|
357
731
|
}
|
|
358
732
|
});
|
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
|
};
|
|
@@ -4,15 +4,26 @@ 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,
|
|
7
|
+
const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = defaultTraceFiles, entryFilter, modifyPackageJson, copyWholePackage, cacheOptions = {
|
|
8
|
+
cacheDir: ".modern-js/deploy",
|
|
9
|
+
fileCache: true,
|
|
10
|
+
analysisCache: true
|
|
11
|
+
}, traceOptions }) => {
|
|
8
12
|
const base = "/";
|
|
13
|
+
const startTime = Date.now();
|
|
9
14
|
const entryFiles = await findEntryFiles(serverRootDir, entryFilter);
|
|
15
|
+
console.time("traceFiles");
|
|
10
16
|
const fileTrace = await traceFiles({
|
|
11
17
|
entryFiles: entryFiles.concat(includeEntries),
|
|
12
18
|
serverRootDir,
|
|
19
|
+
cacheOptions: {
|
|
20
|
+
...cacheOptions,
|
|
21
|
+
cacheDir: path.resolve(appDir, cacheOptions.cacheDir)
|
|
22
|
+
},
|
|
13
23
|
base,
|
|
14
24
|
traceOptions
|
|
15
25
|
});
|
|
26
|
+
console.timeEnd("traceFiles");
|
|
16
27
|
const currentProjectModules = path.join(appDir, "node_modules");
|
|
17
28
|
const dependencySearchRoot = path.resolve(appDir, "../../../../../../");
|
|
18
29
|
const tracedFiles = Object.fromEntries(await Promise.all([
|
|
@@ -194,6 +205,8 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
|
|
|
194
205
|
};
|
|
195
206
|
const finalPkgJson = (modifyPackageJson === null || modifyPackageJson === void 0 ? void 0 : modifyPackageJson(newPkgJson)) || newPkgJson;
|
|
196
207
|
await fse.writeJSON(outputPkgPath, finalPkgJson);
|
|
208
|
+
const endTime = Date.now();
|
|
209
|
+
console.log("handleDependencies cost:", `${endTime - startTime}ms`);
|
|
197
210
|
};
|
|
198
211
|
export {
|
|
199
212
|
handleDependencies,
|
|
@@ -98,12 +98,108 @@ const findPackageParents = (pkg, version, tracedFiles) => {
|
|
|
98
98
|
];
|
|
99
99
|
return parentPkgs.filter((parentPkg) => parentPkg);
|
|
100
100
|
};
|
|
101
|
-
|
|
102
|
-
|
|
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 instanceof Map) {
|
|
108
|
+
return {
|
|
109
|
+
dataType: "Map",
|
|
110
|
+
value: Array.from(value.entries())
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
if (value instanceof Set) {
|
|
114
|
+
return {
|
|
115
|
+
dataType: "Set",
|
|
116
|
+
value: Array.from(value)
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
if (value === null) {
|
|
120
|
+
return void 0;
|
|
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 traceFiles = async ({ entryFiles, serverRootDir, base = "/", cacheOptions, traceOptions }) => {
|
|
137
|
+
const { cacheDir, fileCache: enableFileCache, analysisCache: enableAnalysisCache } = cacheOptions;
|
|
138
|
+
const analysisCacheFile = path.join(cacheDir, "analysis-cache.json");
|
|
139
|
+
const fileCacheFile = path.join(cacheDir, "file-cache.json");
|
|
140
|
+
const statCacheFile = path.join(cacheDir, "stat-cache.json");
|
|
141
|
+
const symlinkCacheFile = path.join(cacheDir, "symlink-cache.json");
|
|
142
|
+
const cache = /* @__PURE__ */ Object.create(null);
|
|
143
|
+
if (enableAnalysisCache && await fse.pathExists(analysisCacheFile)) {
|
|
144
|
+
const analysisCache2 = (await fse.readFile(analysisCacheFile)).toString();
|
|
145
|
+
cache.analysisCache = deserializeMap(analysisCache2);
|
|
146
|
+
}
|
|
147
|
+
if (enableFileCache && await fse.pathExists(fileCacheFile)) {
|
|
148
|
+
const fileCache2 = (await fse.readFile(fileCacheFile)).toString();
|
|
149
|
+
cache.fileCache = deserializeMap(fileCache2);
|
|
150
|
+
}
|
|
151
|
+
if (await fse.pathExists(symlinkCacheFile)) {
|
|
152
|
+
const symlinkCache2 = (await fse.readFile(symlinkCacheFile)).toString();
|
|
153
|
+
cache.symlinkCache = deserializeMap(symlinkCache2);
|
|
154
|
+
}
|
|
155
|
+
const res = await nodeFileTrace(entryFiles, {
|
|
103
156
|
base,
|
|
104
157
|
processCwd: serverRootDir,
|
|
158
|
+
cache,
|
|
105
159
|
...traceOptions
|
|
106
160
|
});
|
|
161
|
+
const { analysisCache, fileCache, statCache, symlinkCache } = cache;
|
|
162
|
+
if (analysisCache || fileCache || statCache || symlinkCache) {
|
|
163
|
+
await fse.ensureDir(cacheDir);
|
|
164
|
+
if (analysisCache) {
|
|
165
|
+
const newAnalysisCache = new Map(analysisCache);
|
|
166
|
+
for (const key of newAnalysisCache.keys()) {
|
|
167
|
+
if (!key.includes("node_modules/")) {
|
|
168
|
+
newAnalysisCache.delete(key);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
(async () => {
|
|
172
|
+
await fse.writeFile(analysisCacheFile, await serializeMap(newAnalysisCache));
|
|
173
|
+
console.log("write analysis cache finish");
|
|
174
|
+
})();
|
|
175
|
+
}
|
|
176
|
+
if (fileCache) {
|
|
177
|
+
const newFileCache = new Map(fileCache);
|
|
178
|
+
for (const key of newFileCache.keys()) {
|
|
179
|
+
if (!key.includes("node_modules/")) {
|
|
180
|
+
newFileCache.delete(key);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
(async () => {
|
|
184
|
+
await fse.writeFile(fileCacheFile, await serializeMap(newFileCache));
|
|
185
|
+
console.log("write file cache finish");
|
|
186
|
+
})();
|
|
187
|
+
}
|
|
188
|
+
if (symlinkCache) {
|
|
189
|
+
const newSymlinkCache = new Map(symlinkCache);
|
|
190
|
+
for (const key of newSymlinkCache.keys()) {
|
|
191
|
+
if (!key.includes("node_modules/")) {
|
|
192
|
+
newSymlinkCache.delete(key);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
(async () => {
|
|
196
|
+
await fse.writeFile(symlinkCacheFile, await serializeMap(newSymlinkCache));
|
|
197
|
+
console.log("write symlink cache finish");
|
|
198
|
+
})();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
console.log("ffffffff", __filename);
|
|
202
|
+
return res;
|
|
107
203
|
};
|
|
108
204
|
const resolveTracedPath = async (base, p) => fse.realpath(path.resolve(base, p));
|
|
109
205
|
const isSubPath = (parentPath, childPath) => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as path from "path";
|
|
2
2
|
import { bundle } from "@modern-js/node-bundle-require";
|
|
3
3
|
import { fs, getServerConfig, ensureAbsolutePath, OUTPUT_CONFIG_FILE, CONFIG_FILE_EXTENSIONS } from "@modern-js/utils";
|
|
4
|
+
import { stringify } from "flatted";
|
|
4
5
|
const defineServerConfig = (config) => config;
|
|
5
6
|
const buildServerConfig = async ({ appDirectory, distDirectory, configFile, options, watch }) => {
|
|
6
7
|
const configFilePath = await getServerConfig(appDirectory, configFile);
|
|
@@ -33,32 +34,16 @@ const buildServerConfig = async ({ appDirectory, distDirectory, configFile, opti
|
|
|
33
34
|
});
|
|
34
35
|
}
|
|
35
36
|
};
|
|
36
|
-
const safeReplacer = () => {
|
|
37
|
-
const cache = [];
|
|
38
|
-
const keyCache = [];
|
|
39
|
-
return function(key, value) {
|
|
40
|
-
if (typeof value === "object" && value !== null) {
|
|
41
|
-
const index = cache.indexOf(value);
|
|
42
|
-
if (index !== -1) {
|
|
43
|
-
return `[Circular ${keyCache[index]}]`;
|
|
44
|
-
}
|
|
45
|
-
cache.push(value);
|
|
46
|
-
keyCache.push(key || "root");
|
|
47
|
-
}
|
|
48
|
-
return value;
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
37
|
const emitResolvedConfig = async (appDirectory, resolvedConfig) => {
|
|
52
38
|
var _resolvedConfig_output_distPath;
|
|
53
39
|
const 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));
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
40
|
+
const output = stringify(resolvedConfig);
|
|
41
|
+
await fs.writeFile(outputPath, output, {
|
|
42
|
+
encoding: "utf-8"
|
|
57
43
|
});
|
|
58
44
|
};
|
|
59
45
|
export {
|
|
60
46
|
buildServerConfig,
|
|
61
47
|
defineServerConfig,
|
|
62
|
-
emitResolvedConfig
|
|
63
|
-
safeReplacer
|
|
48
|
+
emitResolvedConfig
|
|
64
49
|
};
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import type { PackageJson } from 'pkg-types';
|
|
2
2
|
import type { NodeFileTraceOptions } from '@vercel/nft';
|
|
3
|
-
import { traceFiles as defaultTraceFiles } from './utils';
|
|
3
|
+
import { traceFiles as defaultTraceFiles, CacheOptions } 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, traceOptions, }: {
|
|
6
|
+
export declare const handleDependencies: ({ appDir, serverRootDir, includeEntries, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, cacheOptions, traceOptions, }: {
|
|
7
7
|
appDir: string;
|
|
8
8
|
serverRootDir: string;
|
|
9
9
|
includeEntries: string[];
|
|
10
|
-
traceFiles?: (({ entryFiles, serverRootDir, base, traceOptions, }: {
|
|
10
|
+
traceFiles?: (({ entryFiles, serverRootDir, base, cacheOptions, traceOptions, }: {
|
|
11
11
|
entryFiles: string[];
|
|
12
12
|
serverRootDir: string;
|
|
13
13
|
base?: string | undefined;
|
|
14
|
+
cacheOptions: CacheOptions;
|
|
14
15
|
traceOptions?: NodeFileTraceOptions | undefined;
|
|
15
16
|
}) => Promise<import("@vercel/nft").NodeFileTraceResult>) | undefined;
|
|
16
17
|
entryFilter?: ((filePath: string) => boolean) | undefined;
|
|
17
18
|
modifyPackageJson?: ((pkgJson: PackageJson) => PackageJson) | undefined;
|
|
18
19
|
copyWholePackage?: ((pkgName: string) => boolean) | undefined;
|
|
20
|
+
cacheOptions?: CacheOptions | undefined;
|
|
19
21
|
traceOptions?: NodeFileTraceOptions | undefined;
|
|
20
22
|
}) => Promise<void>;
|
|
@@ -33,10 +33,16 @@ 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
|
|
36
|
+
export interface CacheOptions {
|
|
37
|
+
fileCache: boolean;
|
|
38
|
+
analysisCache: boolean;
|
|
39
|
+
cacheDir: string;
|
|
40
|
+
}
|
|
41
|
+
export declare const traceFiles: ({ entryFiles, serverRootDir, base, cacheOptions, traceOptions, }: {
|
|
37
42
|
entryFiles: string[];
|
|
38
43
|
serverRootDir: string;
|
|
39
44
|
base?: string | undefined;
|
|
45
|
+
cacheOptions: CacheOptions;
|
|
40
46
|
traceOptions?: NodeFileTraceOptions | undefined;
|
|
41
47
|
}) => Promise<import("@vercel/nft").NodeFileTraceResult>;
|
|
42
48
|
export declare const resolveTracedPath: (base: string, p: string) => Promise<string>;
|
|
@@ -9,9 +9,4 @@ export declare const buildServerConfig: ({ appDirectory, distDirectory, configFi
|
|
|
9
9
|
options?: Parameters<typeof bundle>[1];
|
|
10
10
|
watch?: boolean | undefined;
|
|
11
11
|
}) => Promise<void>;
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* 处理循环引用的 replacer
|
|
15
|
-
*/
|
|
16
|
-
export declare const safeReplacer: () => (key: string, value: unknown) => unknown;
|
|
17
12
|
export declare const emitResolvedConfig: (appDirectory: string, resolvedConfig: AppNormalizedConfig<'shared'>) => Promise<void>;
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.58.
|
|
18
|
+
"version": "2.58.1-alpha.1",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -77,33 +77,35 @@
|
|
|
77
77
|
"@babel/parser": "^7.22.15",
|
|
78
78
|
"@babel/traverse": "^7.23.2",
|
|
79
79
|
"@babel/types": "^7.24.7",
|
|
80
|
-
"@rsbuild/
|
|
81
|
-
"@rsbuild/
|
|
80
|
+
"@rsbuild/core": "1.0.1-beta.10",
|
|
81
|
+
"@rsbuild/plugin-node-polyfill": "1.0.4",
|
|
82
82
|
"@swc/helpers": "0.5.3",
|
|
83
|
+
"@ungap/structured-clone": "^1.2.0",
|
|
83
84
|
"@vercel/nft": "^0.26.4",
|
|
84
85
|
"es-module-lexer": "^1.1.0",
|
|
85
86
|
"esbuild": "0.17.19",
|
|
86
87
|
"esbuild-register": "^3.5.0",
|
|
88
|
+
"flatted": "^3.2.9",
|
|
87
89
|
"mlly": "^1.6.1",
|
|
88
90
|
"pkg-types": "^1.1.0",
|
|
89
91
|
"std-env": "^3.7.0",
|
|
90
|
-
"@modern-js/core": "2.58.0",
|
|
91
|
-
"@modern-js/plugin-data-loader": "2.58.0",
|
|
92
92
|
"@modern-js/node-bundle-require": "2.58.0",
|
|
93
|
-
"@modern-js/plugin-lint": "2.58.0",
|
|
94
|
-
"@modern-js/rsbuild-plugin-esbuild": "2.58.0",
|
|
95
93
|
"@modern-js/plugin": "2.58.0",
|
|
94
|
+
"@modern-js/core": "2.58.0",
|
|
96
95
|
"@modern-js/plugin-i18n": "2.58.0",
|
|
97
|
-
"@modern-js/prod-server": "2.58.0",
|
|
98
96
|
"@modern-js/server": "2.58.0",
|
|
99
|
-
"@modern-js/server
|
|
97
|
+
"@modern-js/prod-server": "2.58.0",
|
|
98
|
+
"@modern-js/server-core": "2.58.0",
|
|
99
|
+
"@modern-js/plugin-lint": "2.58.0",
|
|
100
100
|
"@modern-js/types": "2.58.0",
|
|
101
|
+
"@modern-js/utils": "2.58.0",
|
|
101
102
|
"@modern-js/uni-builder": "2.58.0",
|
|
102
|
-
"@modern-js/
|
|
103
|
-
"@modern-js/
|
|
103
|
+
"@modern-js/rsbuild-plugin-esbuild": "2.58.0",
|
|
104
|
+
"@modern-js/plugin-data-loader": "2.58.0",
|
|
105
|
+
"@modern-js/server-utils": "2.58.0"
|
|
104
106
|
},
|
|
105
107
|
"devDependencies": {
|
|
106
|
-
"@rsbuild/plugin-swc": "1.0.1-beta.
|
|
108
|
+
"@rsbuild/plugin-swc": "1.0.1-beta.10",
|
|
107
109
|
"@types/babel__traverse": "7.18.5",
|
|
108
110
|
"@types/jest": "^29",
|
|
109
111
|
"@types/node": "^14",
|
|
@@ -112,8 +114,8 @@
|
|
|
112
114
|
"tsconfig-paths": "^4.2.0",
|
|
113
115
|
"typescript": "^5",
|
|
114
116
|
"webpack": "^5.93.0",
|
|
115
|
-
"@scripts/
|
|
116
|
-
"@scripts/
|
|
117
|
+
"@scripts/build": "2.58.0",
|
|
118
|
+
"@scripts/jest-config": "2.58.0"
|
|
117
119
|
},
|
|
118
120
|
"sideEffects": false,
|
|
119
121
|
"publishConfig": {
|