@modern-js/app-tools 2.54.3-alpha.4 → 2.54.3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/plugins/deploy/dependencies/index.js +17 -26
- package/dist/cjs/plugins/deploy/dependencies/utils.js +21 -14
- package/dist/cjs/plugins/deploy/platforms/netlify.js +8 -10
- package/dist/cjs/plugins/deploy/platforms/netlifyEntry.js +1 -0
- package/dist/cjs/plugins/deploy/platforms/node.js +8 -11
- package/dist/cjs/plugins/deploy/platforms/nodeEntry.js +1 -0
- package/dist/cjs/plugins/deploy/platforms/vercel.js +8 -10
- package/dist/cjs/plugins/deploy/platforms/vercelEntry.js +1 -0
- package/dist/esm/plugins/deploy/dependencies/index.js +69 -94
- package/dist/esm/plugins/deploy/dependencies/utils.js +40 -19
- package/dist/esm/plugins/deploy/platforms/netlify.js +9 -11
- package/dist/esm/plugins/deploy/platforms/netlifyEntry.js +2 -1
- package/dist/esm/plugins/deploy/platforms/node.js +9 -12
- package/dist/esm/plugins/deploy/platforms/nodeEntry.js +2 -1
- package/dist/esm/plugins/deploy/platforms/vercel.js +9 -11
- package/dist/esm/plugins/deploy/platforms/vercelEntry.js +2 -1
- package/dist/esm-node/plugins/deploy/dependencies/index.js +18 -27
- package/dist/esm-node/plugins/deploy/dependencies/utils.js +22 -15
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +8 -10
- package/dist/esm-node/plugins/deploy/platforms/netlifyEntry.js +1 -0
- package/dist/esm-node/plugins/deploy/platforms/node.js +8 -11
- package/dist/esm-node/plugins/deploy/platforms/nodeEntry.js +1 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +8 -10
- package/dist/esm-node/plugins/deploy/platforms/vercelEntry.js +1 -0
- package/dist/types/plugins/deploy/dependencies/index.d.ts +1 -11
- package/dist/types/plugins/deploy/dependencies/utils.d.ts +1 -7
- package/package.json +17 -25
- package/dist/cjs/plugins/deploy/exports.js +0 -28
- package/dist/esm/plugins/deploy/exports.js +0 -4
- package/dist/esm-node/plugins/deploy/exports.js +0 -4
- package/dist/js/modern/analyze/constants.js +0 -15
- package/dist/js/modern/analyze/generateCode.js +0 -179
- package/dist/js/modern/analyze/getBundleEntry.js +0 -75
- package/dist/js/modern/analyze/getClientRoutes.js +0 -219
- package/dist/js/modern/analyze/getFileSystemEntry.js +0 -74
- package/dist/js/modern/analyze/getHtmlTemplate.js +0 -82
- package/dist/js/modern/analyze/getServerRoutes.js +0 -192
- package/dist/js/modern/analyze/index.js +0 -148
- package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -32
- package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -16
- package/dist/js/modern/analyze/templates.js +0 -88
- package/dist/js/modern/analyze/utils.js +0 -92
- package/dist/js/modern/commands/build.js +0 -154
- package/dist/js/modern/commands/deploy.js +0 -5
- package/dist/js/modern/commands/dev.js +0 -95
- package/dist/js/modern/commands/index.js +0 -3
- package/dist/js/modern/commands/inspect.js +0 -69
- package/dist/js/modern/commands/start.js +0 -31
- package/dist/js/modern/exports/server.js +0 -1
- package/dist/js/modern/hooks.js +0 -21
- package/dist/js/modern/index.js +0 -109
- package/dist/js/modern/locale/en.js +0 -35
- package/dist/js/modern/locale/index.js +0 -9
- package/dist/js/modern/locale/zh.js +0 -35
- package/dist/js/modern/utils/config.js +0 -78
- package/dist/js/modern/utils/createCompiler.js +0 -61
- package/dist/js/modern/utils/createServer.js +0 -18
- package/dist/js/modern/utils/getSpecifiedEntries.js +0 -36
- package/dist/js/modern/utils/language.js +0 -5
- package/dist/js/modern/utils/printInstructions.js +0 -11
- package/dist/js/modern/utils/routes.js +0 -15
- package/dist/js/modern/utils/types.js +0 -0
- package/dist/js/node/analyze/constants.js +0 -36
- package/dist/js/node/analyze/generateCode.js +0 -208
- package/dist/js/node/analyze/getBundleEntry.js +0 -89
- package/dist/js/node/analyze/getClientRoutes.js +0 -241
- package/dist/js/node/analyze/getFileSystemEntry.js +0 -90
- package/dist/js/node/analyze/getHtmlTemplate.js +0 -106
- package/dist/js/node/analyze/getServerRoutes.js +0 -208
- package/dist/js/node/analyze/index.js +0 -178
- package/dist/js/node/analyze/isDefaultExportFunction.js +0 -50
- package/dist/js/node/analyze/makeLegalIdentifier.js +0 -24
- package/dist/js/node/analyze/templates.js +0 -106
- package/dist/js/node/analyze/utils.js +0 -113
- package/dist/js/node/commands/build.js +0 -174
- package/dist/js/node/commands/deploy.js +0 -14
- package/dist/js/node/commands/dev.js +0 -120
- package/dist/js/node/commands/index.js +0 -44
- package/dist/js/node/commands/inspect.js +0 -98
- package/dist/js/node/commands/start.js +0 -47
- package/dist/js/node/exports/server.js +0 -13
- package/dist/js/node/hooks.js +0 -39
- package/dist/js/node/index.js +0 -141
- package/dist/js/node/locale/en.js +0 -42
- package/dist/js/node/locale/index.js +0 -20
- package/dist/js/node/locale/zh.js +0 -42
- package/dist/js/node/utils/config.js +0 -103
- package/dist/js/node/utils/createCompiler.js +0 -81
- package/dist/js/node/utils/createServer.js +0 -35
- package/dist/js/node/utils/getSpecifiedEntries.js +0 -46
- package/dist/js/node/utils/language.js +0 -13
- package/dist/js/node/utils/printInstructions.js +0 -22
- package/dist/js/node/utils/routes.js +0 -25
- package/dist/js/node/utils/types.js +0 -0
- package/dist/types/plugins/deploy/exports.d.ts +0 -1
@@ -5,7 +5,7 @@ import path from "path";
|
|
5
5
|
import os from "node:os";
|
6
6
|
import { fs as fse } from "@modern-js/utils";
|
7
7
|
import { parseNodeModulePath } from "mlly";
|
8
|
-
import { nodeFileTrace } from "@vercel/nft";
|
8
|
+
import { nodeFileTrace, resolve } from "@vercel/nft";
|
9
9
|
function applyPublicCondition(pkg) {
|
10
10
|
var _pkg_publishConfig;
|
11
11
|
if (pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig = pkg.publishConfig) === null || _pkg_publishConfig === void 0 ? void 0 : _pkg_publishConfig.exports) {
|
@@ -14,12 +14,11 @@ function applyPublicCondition(pkg) {
|
|
14
14
|
}
|
15
15
|
}
|
16
16
|
var writePackage = function() {
|
17
|
-
var _ref = _async_to_generator(function(
|
18
|
-
var
|
17
|
+
var _ref = _async_to_generator(function(pkg, version, projectDir, _pkgPath) {
|
18
|
+
var pkgPath, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, src, subpath, dest, dirname, subpath1, dest1, dirname1, err, pkgJSON, packageJsonPath;
|
19
19
|
return _ts_generator(this, function(_state) {
|
20
20
|
switch (_state.label) {
|
21
21
|
case 0:
|
22
|
-
pkg = options.pkg, version = options.version, projectDir = options.projectDir, _pkgPath = options._pkgPath;
|
23
22
|
pkgPath = _pkgPath || pkg.name;
|
24
23
|
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
25
24
|
_state.label = 1;
|
@@ -134,7 +133,7 @@ var writePackage = function() {
|
|
134
133
|
}
|
135
134
|
});
|
136
135
|
});
|
137
|
-
return function writePackage2(
|
136
|
+
return function writePackage2(pkg, version, projectDir, _pkgPath) {
|
138
137
|
return _ref.apply(this, arguments);
|
139
138
|
};
|
140
139
|
}();
|
@@ -319,20 +318,15 @@ var findPackageParents = function(pkg, version, tracedFiles) {
|
|
319
318
|
return tracedFiles[path2];
|
320
319
|
});
|
321
320
|
var parentPkgs = _to_consumable_array(new Set(versionFiles.flatMap(function(file) {
|
322
|
-
return (
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
return "".concat(parentFile.pkgName, "@").concat(parentFile.pkgVersion);
|
330
|
-
}).filter(Boolean)
|
331
|
-
);
|
321
|
+
return file.parents.map(function(parentPath) {
|
322
|
+
var parentFile = tracedFiles[parentPath];
|
323
|
+
if (!parentFile || parentFile.pkgName === pkg.name) {
|
324
|
+
return null;
|
325
|
+
}
|
326
|
+
return "".concat(parentFile.pkgName, "@").concat(parentFile.pkgVersion);
|
327
|
+
}).filter(Boolean);
|
332
328
|
})));
|
333
|
-
return parentPkgs
|
334
|
-
return parentPkg;
|
335
|
-
});
|
329
|
+
return parentPkgs;
|
336
330
|
};
|
337
331
|
var traceFiles = function() {
|
338
332
|
var _ref = _async_to_generator(function(entryFiles, serverRootDir) {
|
@@ -346,7 +340,34 @@ var traceFiles = function() {
|
|
346
340
|
4,
|
347
341
|
nodeFileTrace(entryFiles, {
|
348
342
|
base,
|
349
|
-
processCwd: serverRootDir
|
343
|
+
processCwd: serverRootDir,
|
344
|
+
resolve: function() {
|
345
|
+
var _ref2 = _async_to_generator(function(id, parent, job, isCjs) {
|
346
|
+
return _ts_generator(this, function(_state2) {
|
347
|
+
if (id.startsWith("@modern-js/prod-server")) {
|
348
|
+
return [
|
349
|
+
2,
|
350
|
+
require.resolve(id, {
|
351
|
+
paths: [
|
352
|
+
require.resolve("@modern-js/app-tools")
|
353
|
+
]
|
354
|
+
})
|
355
|
+
];
|
356
|
+
} else {
|
357
|
+
return [
|
358
|
+
2,
|
359
|
+
resolve(id, parent, job, isCjs)
|
360
|
+
];
|
361
|
+
}
|
362
|
+
return [
|
363
|
+
2
|
364
|
+
];
|
365
|
+
});
|
366
|
+
});
|
367
|
+
return function(id, parent, job, isCjs) {
|
368
|
+
return _ref2.apply(this, arguments);
|
369
|
+
};
|
370
|
+
}()
|
350
371
|
})
|
351
372
|
];
|
352
373
|
case 1:
|
@@ -204,7 +204,7 @@ var createNetlifyPreset = function(appContext, modernConfig, needModernServer) {
|
|
204
204
|
},
|
205
205
|
genEntry: function genEntry() {
|
206
206
|
return _async_to_generator(function() {
|
207
|
-
var _modernConfig_bff, serverConfig, pluginImportCode, dynamicProdOptions, entryCode, serverAppContext;
|
207
|
+
var _modernConfig_bff, serverConfig, pluginImportCode, dynamicProdOptions, pluginsCode, entryCode, serverAppContext;
|
208
208
|
return _ts_generator(this, function(_state) {
|
209
209
|
switch (_state.label) {
|
210
210
|
case 0:
|
@@ -224,9 +224,11 @@ var createNetlifyPreset = function(appContext, modernConfig, needModernServer) {
|
|
224
224
|
pluginImportCode = genPluginImportsCode(plugins || []);
|
225
225
|
dynamicProdOptions = {
|
226
226
|
config: serverConfig,
|
227
|
-
serverConfigFile: DEFAULT_SERVER_CONFIG
|
228
|
-
plugins
|
227
|
+
serverConfigFile: DEFAULT_SERVER_CONFIG
|
229
228
|
};
|
229
|
+
pluginsCode = "[".concat(plugins.map(function(plugin, index) {
|
230
|
+
return "plugin_".concat(index, "()");
|
231
|
+
}).join(","), "]");
|
230
232
|
return [
|
231
233
|
4,
|
232
234
|
fse.readFile(path.join(__dirname, "./netlifyEntry.js"))
|
@@ -234,7 +236,7 @@ var createNetlifyPreset = function(appContext, modernConfig, needModernServer) {
|
|
234
236
|
case 1:
|
235
237
|
entryCode = _state.sent().toString();
|
236
238
|
serverAppContext = serverAppContenxtTemplate(appContext);
|
237
|
-
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", '"'.concat(ROUTE_SPEC_FILE, '"')).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
239
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", '"'.concat(ROUTE_SPEC_FILE, '"')).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_plugins", pluginsCode).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
238
240
|
return [
|
239
241
|
4,
|
240
242
|
fse.writeFile(entryFilePath, entryCode)
|
@@ -273,13 +275,9 @@ var createNetlifyPreset = function(appContext, modernConfig, needModernServer) {
|
|
273
275
|
}
|
274
276
|
return [
|
275
277
|
4,
|
276
|
-
handleDependencies(
|
277
|
-
|
278
|
-
|
279
|
-
includeEntries: [
|
280
|
-
require.resolve("@modern-js/prod-server")
|
281
|
-
]
|
282
|
-
})
|
278
|
+
handleDependencies(appDirectory, funcsDirectory, [
|
279
|
+
"@modern-js/prod-server"
|
280
|
+
])
|
283
281
|
];
|
284
282
|
case 3:
|
285
283
|
_state.sent();
|
@@ -51,7 +51,7 @@ var createNodePreset = function(appContext, config) {
|
|
51
51
|
},
|
52
52
|
genEntry: function genEntry() {
|
53
53
|
return _async_to_generator(function() {
|
54
|
-
var _config_bff, serverConfig, pluginImportCode, dynamicProdOptions, entryCode, serverAppContext;
|
54
|
+
var _config_bff, serverConfig, pluginImportCode, dynamicProdOptions, pluginsCode, entryCode, serverAppContext;
|
55
55
|
return _ts_generator(this, function(_state) {
|
56
56
|
switch (_state.label) {
|
57
57
|
case 0:
|
@@ -69,9 +69,11 @@ var createNodePreset = function(appContext, config) {
|
|
69
69
|
pluginImportCode = genPluginImportsCode(plugins || []);
|
70
70
|
dynamicProdOptions = {
|
71
71
|
config: serverConfig,
|
72
|
-
serverConfigFile: DEFAULT_SERVER_CONFIG
|
73
|
-
plugins
|
72
|
+
serverConfigFile: DEFAULT_SERVER_CONFIG
|
74
73
|
};
|
74
|
+
pluginsCode = "[".concat(plugins.map(function(plugin, index) {
|
75
|
+
return "plugin_".concat(index, "()");
|
76
|
+
}).join(","), "]");
|
75
77
|
return [
|
76
78
|
4,
|
77
79
|
fse.readFile(path.join(__dirname, "./nodeEntry.js"))
|
@@ -79,7 +81,7 @@ var createNodePreset = function(appContext, config) {
|
|
79
81
|
case 1:
|
80
82
|
entryCode = _state.sent().toString();
|
81
83
|
serverAppContext = serverAppContenxtTemplate(appContext);
|
82
|
-
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", '"'.concat(ROUTE_SPEC_FILE, '"')).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
84
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", '"'.concat(ROUTE_SPEC_FILE, '"')).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_plugins", pluginsCode).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
83
85
|
return [
|
84
86
|
4,
|
85
87
|
fse.writeFile(entryFilePath, entryCode)
|
@@ -106,14 +108,9 @@ var createNodePreset = function(appContext, config) {
|
|
106
108
|
};
|
107
109
|
return [
|
108
110
|
4,
|
109
|
-
handleDependencies(
|
110
|
-
|
111
|
-
|
112
|
-
includeEntries: [
|
113
|
-
require.resolve("@modern-js/prod-server")
|
114
|
-
],
|
115
|
-
entryFilter: filter
|
116
|
-
})
|
111
|
+
handleDependencies(appDirectory, outputDirectory, [
|
112
|
+
"@modern-js/prod-server"
|
113
|
+
], filter)
|
117
114
|
];
|
118
115
|
case 1:
|
119
116
|
_state.sent();
|
@@ -151,7 +151,7 @@ var createVercelPreset = function(appContext, modernConfig, needModernServer) {
|
|
151
151
|
},
|
152
152
|
genEntry: function genEntry() {
|
153
153
|
return _async_to_generator(function() {
|
154
|
-
var _modernConfig_bff, serverConfig, pluginImportCode, dynamicProdOptions, serverAppContext, entryCode;
|
154
|
+
var _modernConfig_bff, serverConfig, pluginImportCode, dynamicProdOptions, pluginsCode, serverAppContext, entryCode;
|
155
155
|
return _ts_generator(this, function(_state) {
|
156
156
|
switch (_state.label) {
|
157
157
|
case 0:
|
@@ -171,9 +171,11 @@ var createVercelPreset = function(appContext, modernConfig, needModernServer) {
|
|
171
171
|
pluginImportCode = genPluginImportsCode(plugins || []);
|
172
172
|
dynamicProdOptions = {
|
173
173
|
config: serverConfig,
|
174
|
-
serverConfigFile: DEFAULT_SERVER_CONFIG
|
175
|
-
plugins
|
174
|
+
serverConfigFile: DEFAULT_SERVER_CONFIG
|
176
175
|
};
|
176
|
+
pluginsCode = "[".concat(plugins.map(function(plugin, index) {
|
177
|
+
return "plugin_".concat(index, "()");
|
178
|
+
}).join(","), "]");
|
177
179
|
serverAppContext = serverAppContenxtTemplate(appContext);
|
178
180
|
return [
|
179
181
|
4,
|
@@ -181,7 +183,7 @@ var createVercelPreset = function(appContext, modernConfig, needModernServer) {
|
|
181
183
|
];
|
182
184
|
case 1:
|
183
185
|
entryCode = _state.sent().toString();
|
184
|
-
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", '"'.concat(ROUTE_SPEC_FILE, '"')).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
186
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", '"'.concat(ROUTE_SPEC_FILE, '"')).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_plugins", pluginsCode).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
185
187
|
return [
|
186
188
|
4,
|
187
189
|
fse.writeFile(entryFilePath, entryCode)
|
@@ -207,13 +209,9 @@ var createVercelPreset = function(appContext, modernConfig, needModernServer) {
|
|
207
209
|
}
|
208
210
|
return [
|
209
211
|
4,
|
210
|
-
handleDependencies(
|
211
|
-
|
212
|
-
|
213
|
-
includeEntries: [
|
214
|
-
require.resolve("@modern-js/prod-server")
|
215
|
-
]
|
216
|
-
})
|
212
|
+
handleDependencies(appDirectory, funcsDirectory, [
|
213
|
+
"@modern-js/prod-server"
|
214
|
+
])
|
217
215
|
];
|
218
216
|
case 1:
|
219
217
|
_state.sent();
|
@@ -1,11 +1,21 @@
|
|
1
|
-
import path from "node:path";
|
1
|
+
import path, { isAbsolute } from "node:path";
|
2
2
|
import { fs as fse, pkgUp, semver } from "@modern-js/utils";
|
3
3
|
import { readPackageJSON } from "pkg-types";
|
4
4
|
import { parseNodeModulePath } from "mlly";
|
5
|
-
import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles
|
6
|
-
const handleDependencies = async (
|
5
|
+
import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles, findPackageParents, resolveTracedPath } from "./utils";
|
6
|
+
const handleDependencies = async (appDir, serverRootDir, include, entryFilter) => {
|
7
7
|
const base = "/";
|
8
8
|
const entryFiles = await findEntryFiles(serverRootDir, entryFilter);
|
9
|
+
const includeEntries = include.map((item) => {
|
10
|
+
if (isAbsolute(item)) {
|
11
|
+
return item;
|
12
|
+
}
|
13
|
+
try {
|
14
|
+
return require.resolve(item);
|
15
|
+
} catch (error) {
|
16
|
+
}
|
17
|
+
return item;
|
18
|
+
});
|
9
19
|
const fileTrace = await traceFiles(entryFiles.concat(includeEntries), serverRootDir, base);
|
10
20
|
const currentProjectModules = path.join(appDir, "node_modules");
|
11
21
|
const tracedFiles = Object.fromEntries(await Promise.all([
|
@@ -100,17 +110,9 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
|
|
100
110
|
}
|
101
111
|
tracedPackage.versions[pkgJSON.version] = tracedPackageVersion;
|
102
112
|
}
|
113
|
+
tracedFile.path.startsWith(tracedFile.pkgPath) && tracedPackageVersion.path === tracedFile.pkgPath && tracedPackageVersion.files.push(tracedFile.path);
|
103
114
|
tracedFile.pkgName = pkgName;
|
104
115
|
tracedFile.pkgVersion = pkgJSON.version;
|
105
|
-
const shouldCopyWholePackage = copyWholePackage === null || copyWholePackage === void 0 ? void 0 : copyWholePackage(pkgName);
|
106
|
-
if (tracedFile.path.startsWith(tracedFile.pkgPath) && tracedPackageVersion.pkgJSON.version === tracedFile.pkgVersion) {
|
107
|
-
if (shouldCopyWholePackage) {
|
108
|
-
const allFiles = await readDirRecursive(tracedFile.pkgPath);
|
109
|
-
tracedPackageVersion.files.push(...allFiles);
|
110
|
-
} else {
|
111
|
-
tracedPackageVersion.files.push(tracedFile.path);
|
112
|
-
}
|
113
|
-
}
|
114
116
|
}
|
115
117
|
const multiVersionPkgs = {};
|
116
118
|
const singleVersionPackages = [];
|
@@ -128,11 +130,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
|
|
128
130
|
await Promise.all(singleVersionPackages.map((pkgName) => {
|
129
131
|
const pkg = tracedPackages[pkgName];
|
130
132
|
const version = Object.keys(pkg.versions)[0];
|
131
|
-
return writePackage(
|
132
|
-
pkg,
|
133
|
-
version,
|
134
|
-
projectDir: serverRootDir
|
135
|
-
});
|
133
|
+
return writePackage(pkg, version, serverRootDir);
|
136
134
|
}));
|
137
135
|
const projectPkgJson = await readPackageJSON(serverRootDir).catch(() => ({}));
|
138
136
|
for (const [pkgName, pkgVersions] of Object.entries(multiVersionPkgs)) {
|
@@ -159,12 +157,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
|
|
159
157
|
for (const [version, parentPkgs] of versionEntires) {
|
160
158
|
const pkg = tracedPackages[pkgName];
|
161
159
|
const pkgDestPath = `.modernjs/${pkgName}@${version}/node_modules/${pkgName}`;
|
162
|
-
await writePackage(
|
163
|
-
pkg,
|
164
|
-
version,
|
165
|
-
projectDir: serverRootDir,
|
166
|
-
_pkgPath: pkgDestPath
|
167
|
-
});
|
160
|
+
await writePackage(pkg, version, serverRootDir, pkgDestPath);
|
168
161
|
await linkPackage(pkgDestPath, `${pkgName}`, serverRootDir);
|
169
162
|
for (const parentPkg of parentPkgs) {
|
170
163
|
const parentPkgName = parentPkg.replace(/@[^@]+$/, "");
|
@@ -173,7 +166,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
|
|
173
166
|
}
|
174
167
|
}
|
175
168
|
const outputPkgPath = path.join(serverRootDir, "package.json");
|
176
|
-
|
169
|
+
await fse.writeJSON(outputPkgPath, {
|
177
170
|
name: `${projectPkgJson.name || "modernjs-project"}-prod`,
|
178
171
|
version: projectPkgJson.version || "0.0.0",
|
179
172
|
private: true,
|
@@ -183,9 +176,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
|
|
183
176
|
Object.keys(pkg.versions)[0]
|
184
177
|
])
|
185
178
|
].sort(([a], [b]) => a.localeCompare(b)))
|
186
|
-
};
|
187
|
-
const finalPkgJson = (modifyPackageJson === null || modifyPackageJson === void 0 ? void 0 : modifyPackageJson(newPkgJson)) || newPkgJson;
|
188
|
-
await fse.writeJSON(outputPkgPath, finalPkgJson);
|
179
|
+
});
|
189
180
|
};
|
190
181
|
export {
|
191
182
|
handleDependencies
|
@@ -2,7 +2,7 @@ import path from "path";
|
|
2
2
|
import os from "node:os";
|
3
3
|
import { fs as fse } from "@modern-js/utils";
|
4
4
|
import { parseNodeModulePath } from "mlly";
|
5
|
-
import { nodeFileTrace } from "@vercel/nft";
|
5
|
+
import { nodeFileTrace, resolve } from "@vercel/nft";
|
6
6
|
function applyPublicCondition(pkg) {
|
7
7
|
var _pkg_publishConfig;
|
8
8
|
if (pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig = pkg.publishConfig) === null || _pkg_publishConfig === void 0 ? void 0 : _pkg_publishConfig.exports) {
|
@@ -10,8 +10,7 @@ function applyPublicCondition(pkg) {
|
|
10
10
|
pkg.exports = pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig1 = pkg.publishConfig) === null || _pkg_publishConfig1 === void 0 ? void 0 : _pkg_publishConfig1.exports;
|
11
11
|
}
|
12
12
|
}
|
13
|
-
const writePackage = async (
|
14
|
-
const { pkg, version, projectDir, _pkgPath } = options;
|
13
|
+
const writePackage = async (pkg, version, projectDir, _pkgPath) => {
|
15
14
|
const pkgPath = _pkgPath || pkg.name;
|
16
15
|
for (const src of pkg.versions[version].files) {
|
17
16
|
if (src.includes("node_modules")) {
|
@@ -85,23 +84,31 @@ const findEntryFiles = async (rootDir, entryFilter) => {
|
|
85
84
|
const findPackageParents = (pkg, version, tracedFiles) => {
|
86
85
|
const versionFiles = pkg.versions[version].files.map((path2) => tracedFiles[path2]);
|
87
86
|
const parentPkgs = [
|
88
|
-
...new Set(versionFiles.flatMap((file) => (
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
return `${parentFile.pkgName}@${parentFile.pkgVersion}`;
|
96
|
-
}).filter(Boolean)
|
97
|
-
)))
|
87
|
+
...new Set(versionFiles.flatMap((file) => file.parents.map((parentPath) => {
|
88
|
+
const parentFile = tracedFiles[parentPath];
|
89
|
+
if (!parentFile || parentFile.pkgName === pkg.name) {
|
90
|
+
return null;
|
91
|
+
}
|
92
|
+
return `${parentFile.pkgName}@${parentFile.pkgVersion}`;
|
93
|
+
}).filter(Boolean)))
|
98
94
|
];
|
99
|
-
return parentPkgs
|
95
|
+
return parentPkgs;
|
100
96
|
};
|
101
97
|
const traceFiles = async (entryFiles, serverRootDir, base = "/") => {
|
102
98
|
return await nodeFileTrace(entryFiles, {
|
103
99
|
base,
|
104
|
-
processCwd: serverRootDir
|
100
|
+
processCwd: serverRootDir,
|
101
|
+
resolve: async (id, parent, job, isCjs) => {
|
102
|
+
if (id.startsWith("@modern-js/prod-server")) {
|
103
|
+
return require.resolve(id, {
|
104
|
+
paths: [
|
105
|
+
require.resolve("@modern-js/app-tools")
|
106
|
+
]
|
107
|
+
});
|
108
|
+
} else {
|
109
|
+
return resolve(id, parent, job, isCjs);
|
110
|
+
}
|
111
|
+
}
|
105
112
|
});
|
106
113
|
};
|
107
114
|
const resolveTracedPath = async (base, p) => fse.realpath(path.resolve(base, p));
|
@@ -76,12 +76,14 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
|
76
76
|
const pluginImportCode = genPluginImportsCode(plugins || []);
|
77
77
|
const dynamicProdOptions = {
|
78
78
|
config: serverConfig,
|
79
|
-
serverConfigFile: DEFAULT_SERVER_CONFIG
|
80
|
-
plugins
|
79
|
+
serverConfigFile: DEFAULT_SERVER_CONFIG
|
81
80
|
};
|
81
|
+
const pluginsCode = `[${plugins.map((plugin, index) => {
|
82
|
+
return `plugin_${index}()`;
|
83
|
+
}).join(",")}]`;
|
82
84
|
let entryCode = (await fse.readFile(path.join(__dirname, "./netlifyEntry.js"))).toString();
|
83
85
|
const serverAppContext = serverAppContenxtTemplate(appContext);
|
84
|
-
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
86
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_plugins", pluginsCode).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
85
87
|
await fse.writeFile(entryFilePath, entryCode);
|
86
88
|
},
|
87
89
|
async end() {
|
@@ -91,13 +93,9 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
|
91
93
|
if (!needModernServer) {
|
92
94
|
return;
|
93
95
|
}
|
94
|
-
await handleDependencies(
|
95
|
-
|
96
|
-
|
97
|
-
includeEntries: [
|
98
|
-
require.resolve("@modern-js/prod-server")
|
99
|
-
]
|
100
|
-
});
|
96
|
+
await handleDependencies(appDirectory, funcsDirectory, [
|
97
|
+
"@modern-js/prod-server"
|
98
|
+
]);
|
101
99
|
}
|
102
100
|
};
|
103
101
|
};
|
@@ -31,12 +31,14 @@ const createNodePreset = (appContext, config) => {
|
|
31
31
|
const pluginImportCode = genPluginImportsCode(plugins || []);
|
32
32
|
const dynamicProdOptions = {
|
33
33
|
config: serverConfig,
|
34
|
-
serverConfigFile: DEFAULT_SERVER_CONFIG
|
35
|
-
plugins
|
34
|
+
serverConfigFile: DEFAULT_SERVER_CONFIG
|
36
35
|
};
|
36
|
+
const pluginsCode = `[${plugins.map((plugin, index) => {
|
37
|
+
return `plugin_${index}()`;
|
38
|
+
}).join(",")}]`;
|
37
39
|
let entryCode = (await fse.readFile(path.join(__dirname, "./nodeEntry.js"))).toString();
|
38
40
|
const serverAppContext = serverAppContenxtTemplate(appContext);
|
39
|
-
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
41
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_plugins", pluginsCode).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
40
42
|
await fse.writeFile(entryFilePath, entryCode);
|
41
43
|
},
|
42
44
|
async end() {
|
@@ -45,14 +47,9 @@ const createNodePreset = (appContext, config) => {
|
|
45
47
|
const filter = (filePath) => {
|
46
48
|
return !filePath.startsWith(staticDirectory);
|
47
49
|
};
|
48
|
-
await handleDependencies(
|
49
|
-
|
50
|
-
|
51
|
-
includeEntries: [
|
52
|
-
require.resolve("@modern-js/prod-server")
|
53
|
-
],
|
54
|
-
entryFilter: filter
|
55
|
-
});
|
50
|
+
await handleDependencies(appDirectory, outputDirectory, [
|
51
|
+
"@modern-js/prod-server"
|
52
|
+
], filter);
|
56
53
|
}
|
57
54
|
};
|
58
55
|
};
|
@@ -91,25 +91,23 @@ const createVercelPreset = (appContext, modernConfig, needModernServer) => {
|
|
91
91
|
const pluginImportCode = genPluginImportsCode(plugins || []);
|
92
92
|
const dynamicProdOptions = {
|
93
93
|
config: serverConfig,
|
94
|
-
serverConfigFile: DEFAULT_SERVER_CONFIG
|
95
|
-
plugins
|
94
|
+
serverConfigFile: DEFAULT_SERVER_CONFIG
|
96
95
|
};
|
96
|
+
const pluginsCode = `[${plugins.map((plugin, index) => {
|
97
|
+
return `plugin_${index}()`;
|
98
|
+
}).join(",")}]`;
|
97
99
|
const serverAppContext = serverAppContenxtTemplate(appContext);
|
98
100
|
let entryCode = (await fse.readFile(path.join(__dirname, "./vercelEntry.js"))).toString();
|
99
|
-
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
101
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_plugins", pluginsCode).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
100
102
|
await fse.writeFile(entryFilePath, entryCode);
|
101
103
|
},
|
102
104
|
async end() {
|
103
105
|
if (!needModernServer) {
|
104
106
|
return;
|
105
107
|
}
|
106
|
-
await handleDependencies(
|
107
|
-
|
108
|
-
|
109
|
-
includeEntries: [
|
110
|
-
require.resolve("@modern-js/prod-server")
|
111
|
-
]
|
112
|
-
});
|
108
|
+
await handleDependencies(appDirectory, funcsDirectory, [
|
109
|
+
"@modern-js/prod-server"
|
110
|
+
]);
|
113
111
|
}
|
114
112
|
};
|
115
113
|
};
|
@@ -1,11 +1 @@
|
|
1
|
-
|
2
|
-
import { traceFiles as defaultTraceFiles } from './utils';
|
3
|
-
export declare const handleDependencies: ({ appDir, serverRootDir, includeEntries, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, }: {
|
4
|
-
appDir: string;
|
5
|
-
serverRootDir: string;
|
6
|
-
includeEntries: string[];
|
7
|
-
traceFiles?: ((entryFiles: string[], serverRootDir: string, base?: string) => Promise<import("@vercel/nft").NodeFileTraceResult>) | undefined;
|
8
|
-
entryFilter?: ((filePath: string) => boolean) | undefined;
|
9
|
-
modifyPackageJson?: ((pkgJson: PackageJson) => PackageJson) | undefined;
|
10
|
-
copyWholePackage?: ((pkgName: string) => boolean) | undefined;
|
11
|
-
}) => Promise<void>;
|
1
|
+
export declare const handleDependencies: (appDir: string, serverRootDir: string, include: string[], entryFilter?: ((filePath: string) => boolean) | undefined) => Promise<void>;
|
@@ -17,13 +17,7 @@ export type TracedFile = {
|
|
17
17
|
pkgName: string;
|
18
18
|
pkgVersion?: string;
|
19
19
|
};
|
20
|
-
|
21
|
-
pkg: TracedPackage;
|
22
|
-
version: string;
|
23
|
-
projectDir: string;
|
24
|
-
_pkgPath?: string;
|
25
|
-
}
|
26
|
-
export declare const writePackage: (options: WritePackageOptions) => Promise<void>;
|
20
|
+
export declare const writePackage: (pkg: TracedPackage, version: string, projectDir: string, _pkgPath?: string) => Promise<void>;
|
27
21
|
export declare const linkPackage: (from: string, to: string, projectRootDir: string) => Promise<void>;
|
28
22
|
interface ReadDirOptions {
|
29
23
|
filter?: (filePath: string) => boolean;
|