@modern-js/app-tools 2.54.1 → 2.54.2-alpha.3
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/commands/build.js +1 -1
- package/dist/cjs/commands/deploy.js +1 -2
- package/dist/cjs/commands/dev.js +1 -1
- package/dist/cjs/commands/serve.js +1 -1
- package/dist/cjs/plugins/deploy/dependencies/index.js +26 -17
- package/dist/cjs/plugins/deploy/dependencies/utils.js +14 -20
- package/dist/cjs/plugins/deploy/exports.js +28 -0
- package/dist/cjs/plugins/deploy/platforms/netlify.js +7 -3
- package/dist/cjs/plugins/deploy/platforms/node.js +8 -3
- package/dist/cjs/plugins/deploy/platforms/vercel.js +7 -3
- package/dist/cjs/utils/loadPlugins.js +5 -6
- package/dist/esm/commands/build.js +1 -1
- package/dist/esm/commands/deploy.js +2 -3
- package/dist/esm/commands/dev.js +1 -1
- package/dist/esm/commands/serve.js +1 -1
- package/dist/esm/plugins/deploy/dependencies/index.js +94 -69
- package/dist/esm/plugins/deploy/dependencies/utils.js +19 -39
- package/dist/esm/plugins/deploy/exports.js +4 -0
- package/dist/esm/plugins/deploy/platforms/netlify.js +7 -3
- package/dist/esm/plugins/deploy/platforms/node.js +8 -3
- package/dist/esm/plugins/deploy/platforms/vercel.js +7 -3
- package/dist/esm/utils/loadPlugins.js +6 -11
- package/dist/esm-node/commands/build.js +1 -1
- package/dist/esm-node/commands/deploy.js +1 -2
- package/dist/esm-node/commands/dev.js +1 -1
- package/dist/esm-node/commands/serve.js +1 -1
- package/dist/esm-node/plugins/deploy/dependencies/index.js +27 -18
- package/dist/esm-node/plugins/deploy/dependencies/utils.js +15 -21
- package/dist/esm-node/plugins/deploy/exports.js +4 -0
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +7 -3
- package/dist/esm-node/plugins/deploy/platforms/node.js +8 -3
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +7 -3
- package/dist/esm-node/utils/loadPlugins.js +5 -6
- package/dist/js/modern/analyze/constants.js +15 -0
- package/dist/js/modern/analyze/generateCode.js +179 -0
- package/dist/js/modern/analyze/getBundleEntry.js +75 -0
- package/dist/js/modern/analyze/getClientRoutes.js +219 -0
- package/dist/js/modern/analyze/getFileSystemEntry.js +74 -0
- package/dist/js/modern/analyze/getHtmlTemplate.js +82 -0
- package/dist/js/modern/analyze/getServerRoutes.js +192 -0
- package/dist/js/modern/analyze/index.js +148 -0
- package/dist/js/modern/analyze/isDefaultExportFunction.js +32 -0
- package/dist/js/modern/analyze/makeLegalIdentifier.js +16 -0
- package/dist/js/modern/analyze/templates.js +88 -0
- package/dist/js/modern/analyze/utils.js +92 -0
- package/dist/js/modern/commands/build.js +154 -0
- package/dist/js/modern/commands/deploy.js +5 -0
- package/dist/js/modern/commands/dev.js +95 -0
- package/dist/js/modern/commands/index.js +3 -0
- package/dist/js/modern/commands/inspect.js +69 -0
- package/dist/js/modern/commands/start.js +31 -0
- package/dist/js/modern/exports/server.js +1 -0
- package/dist/js/modern/hooks.js +21 -0
- package/dist/js/modern/index.js +109 -0
- package/dist/js/modern/locale/en.js +35 -0
- package/dist/js/modern/locale/index.js +9 -0
- package/dist/js/modern/locale/zh.js +35 -0
- package/dist/js/modern/utils/config.js +78 -0
- package/dist/js/modern/utils/createCompiler.js +61 -0
- package/dist/js/modern/utils/createServer.js +18 -0
- package/dist/js/modern/utils/getSpecifiedEntries.js +36 -0
- package/dist/js/modern/utils/language.js +5 -0
- package/dist/js/modern/utils/printInstructions.js +11 -0
- package/dist/js/modern/utils/routes.js +15 -0
- package/dist/js/modern/utils/types.js +0 -0
- package/dist/js/node/analyze/constants.js +36 -0
- package/dist/js/node/analyze/generateCode.js +208 -0
- package/dist/js/node/analyze/getBundleEntry.js +89 -0
- package/dist/js/node/analyze/getClientRoutes.js +241 -0
- package/dist/js/node/analyze/getFileSystemEntry.js +90 -0
- package/dist/js/node/analyze/getHtmlTemplate.js +106 -0
- package/dist/js/node/analyze/getServerRoutes.js +208 -0
- package/dist/js/node/analyze/index.js +178 -0
- package/dist/js/node/analyze/isDefaultExportFunction.js +50 -0
- package/dist/js/node/analyze/makeLegalIdentifier.js +24 -0
- package/dist/js/node/analyze/templates.js +106 -0
- package/dist/js/node/analyze/utils.js +113 -0
- package/dist/js/node/commands/build.js +174 -0
- package/dist/js/node/commands/deploy.js +14 -0
- package/dist/js/node/commands/dev.js +120 -0
- package/dist/js/node/commands/index.js +44 -0
- package/dist/js/node/commands/inspect.js +98 -0
- package/dist/js/node/commands/start.js +47 -0
- package/dist/js/node/exports/server.js +13 -0
- package/dist/js/node/hooks.js +39 -0
- package/dist/js/node/index.js +141 -0
- package/dist/js/node/locale/en.js +42 -0
- package/dist/js/node/locale/index.js +20 -0
- package/dist/js/node/locale/zh.js +42 -0
- package/dist/js/node/utils/config.js +103 -0
- package/dist/js/node/utils/createCompiler.js +81 -0
- package/dist/js/node/utils/createServer.js +35 -0
- package/dist/js/node/utils/getSpecifiedEntries.js +46 -0
- package/dist/js/node/utils/language.js +13 -0
- package/dist/js/node/utils/printInstructions.js +22 -0
- package/dist/js/node/utils/routes.js +25 -0
- package/dist/js/node/utils/types.js +0 -0
- package/dist/types/plugins/deploy/dependencies/index.d.ts +11 -1
- package/dist/types/plugins/deploy/dependencies/utils.d.ts +7 -1
- package/dist/types/plugins/deploy/exports.d.ts +1 -0
- package/dist/types/utils/loadPlugins.d.ts +2 -2
- package/package.json +14 -6
|
@@ -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
|
|
8
|
+
import { nodeFileTrace } 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,11 +14,12 @@ function applyPublicCondition(pkg) {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
var writePackage = function() {
|
|
17
|
-
var _ref = _async_to_generator(function(
|
|
18
|
-
var pkgPath, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, src, subpath, dest, dirname, subpath1, dest1, dirname1, err, pkgJSON, packageJsonPath;
|
|
17
|
+
var _ref = _async_to_generator(function(options) {
|
|
18
|
+
var pkg, version, projectDir, _pkgPath, 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;
|
|
22
23
|
pkgPath = _pkgPath || pkg.name;
|
|
23
24
|
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
24
25
|
_state.label = 1;
|
|
@@ -133,7 +134,7 @@ var writePackage = function() {
|
|
|
133
134
|
}
|
|
134
135
|
});
|
|
135
136
|
});
|
|
136
|
-
return function writePackage2(
|
|
137
|
+
return function writePackage2(options) {
|
|
137
138
|
return _ref.apply(this, arguments);
|
|
138
139
|
};
|
|
139
140
|
}();
|
|
@@ -318,15 +319,20 @@ var findPackageParents = function(pkg, version, tracedFiles) {
|
|
|
318
319
|
return tracedFiles[path2];
|
|
319
320
|
});
|
|
320
321
|
var parentPkgs = _to_consumable_array(new Set(versionFiles.flatMap(function(file) {
|
|
321
|
-
return
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
322
|
+
return (
|
|
323
|
+
// Because it supports copyWholePackage configuration, not all files exist.
|
|
324
|
+
file === null || file === void 0 ? void 0 : file.parents.map(function(parentPath) {
|
|
325
|
+
var parentFile = tracedFiles[parentPath];
|
|
326
|
+
if (!parentFile || parentFile.pkgName === pkg.name) {
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
329
|
+
return "".concat(parentFile.pkgName, "@").concat(parentFile.pkgVersion);
|
|
330
|
+
}).filter(Boolean)
|
|
331
|
+
);
|
|
328
332
|
})));
|
|
329
|
-
return parentPkgs
|
|
333
|
+
return parentPkgs.filter(function(parentPkg) {
|
|
334
|
+
return parentPkg;
|
|
335
|
+
});
|
|
330
336
|
};
|
|
331
337
|
var traceFiles = function() {
|
|
332
338
|
var _ref = _async_to_generator(function(entryFiles, serverRootDir) {
|
|
@@ -341,33 +347,7 @@ var traceFiles = function() {
|
|
|
341
347
|
nodeFileTrace(entryFiles, {
|
|
342
348
|
base,
|
|
343
349
|
processCwd: serverRootDir,
|
|
344
|
-
|
|
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
|
+
cache: /* @__PURE__ */ Object.create(null)
|
|
371
351
|
})
|
|
372
352
|
];
|
|
373
353
|
case 1:
|
|
@@ -273,9 +273,13 @@ var createNetlifyPreset = function(appContext, modernConfig, needModernServer) {
|
|
|
273
273
|
}
|
|
274
274
|
return [
|
|
275
275
|
4,
|
|
276
|
-
handleDependencies(
|
|
277
|
-
|
|
278
|
-
|
|
276
|
+
handleDependencies({
|
|
277
|
+
appDir: appDirectory,
|
|
278
|
+
serverRootDir: funcsDirectory,
|
|
279
|
+
includeEntries: [
|
|
280
|
+
require.resolve("@modern-js/prod-server")
|
|
281
|
+
]
|
|
282
|
+
})
|
|
279
283
|
];
|
|
280
284
|
case 3:
|
|
281
285
|
_state.sent();
|
|
@@ -106,9 +106,14 @@ var createNodePreset = function(appContext, config) {
|
|
|
106
106
|
};
|
|
107
107
|
return [
|
|
108
108
|
4,
|
|
109
|
-
handleDependencies(
|
|
110
|
-
|
|
111
|
-
|
|
109
|
+
handleDependencies({
|
|
110
|
+
appDir: appDirectory,
|
|
111
|
+
serverRootDir: outputDirectory,
|
|
112
|
+
includeEntries: [
|
|
113
|
+
require.resolve("@modern-js/prod-server")
|
|
114
|
+
],
|
|
115
|
+
entryFilter: filter
|
|
116
|
+
})
|
|
112
117
|
];
|
|
113
118
|
case 1:
|
|
114
119
|
_state.sent();
|
|
@@ -207,9 +207,13 @@ var createVercelPreset = function(appContext, modernConfig, needModernServer) {
|
|
|
207
207
|
}
|
|
208
208
|
return [
|
|
209
209
|
4,
|
|
210
|
-
handleDependencies(
|
|
211
|
-
|
|
212
|
-
|
|
210
|
+
handleDependencies({
|
|
211
|
+
appDir: appDirectory,
|
|
212
|
+
serverRootDir: funcsDirectory,
|
|
213
|
+
includeEntries: [
|
|
214
|
+
require.resolve("@modern-js/prod-server")
|
|
215
|
+
]
|
|
216
|
+
})
|
|
213
217
|
];
|
|
214
218
|
case 1:
|
|
215
219
|
_state.sent();
|
|
@@ -8,12 +8,10 @@ function getServerPlugins(api) {
|
|
|
8
8
|
}
|
|
9
9
|
function _getServerPlugins() {
|
|
10
10
|
_getServerPlugins = _async_to_generator(function(api) {
|
|
11
|
-
var
|
|
12
|
-
var _arguments = arguments;
|
|
11
|
+
var runner, plugins;
|
|
13
12
|
return _ts_generator(this, function(_state) {
|
|
14
13
|
switch (_state.label) {
|
|
15
14
|
case 0:
|
|
16
|
-
metaName = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : "modern-js";
|
|
17
15
|
runner = api.useHookRunners();
|
|
18
16
|
return [
|
|
19
17
|
4,
|
|
@@ -23,33 +21,30 @@ function _getServerPlugins() {
|
|
|
23
21
|
];
|
|
24
22
|
case 1:
|
|
25
23
|
plugins = _state.sent().plugins;
|
|
26
|
-
filtedPlugins = plugins.filter(function(plugin) {
|
|
27
|
-
return plugin.name.includes(metaName);
|
|
28
|
-
});
|
|
29
24
|
api.setAppContext(_object_spread_props(_object_spread({}, api.useAppContext()), {
|
|
30
|
-
serverPlugins:
|
|
25
|
+
serverPlugins: plugins
|
|
31
26
|
}));
|
|
32
27
|
return [
|
|
33
28
|
2,
|
|
34
|
-
|
|
29
|
+
plugins
|
|
35
30
|
];
|
|
36
31
|
}
|
|
37
32
|
});
|
|
38
33
|
});
|
|
39
34
|
return _getServerPlugins.apply(this, arguments);
|
|
40
35
|
}
|
|
41
|
-
function loadServerPlugins(api, appDirectory
|
|
36
|
+
function loadServerPlugins(api, appDirectory) {
|
|
42
37
|
return _loadServerPlugins.apply(this, arguments);
|
|
43
38
|
}
|
|
44
39
|
function _loadServerPlugins() {
|
|
45
|
-
_loadServerPlugins = _async_to_generator(function(api, appDirectory
|
|
40
|
+
_loadServerPlugins = _async_to_generator(function(api, appDirectory) {
|
|
46
41
|
var plugins, instances;
|
|
47
42
|
return _ts_generator(this, function(_state) {
|
|
48
43
|
switch (_state.label) {
|
|
49
44
|
case 0:
|
|
50
45
|
return [
|
|
51
46
|
4,
|
|
52
|
-
getServerPlugins(api
|
|
47
|
+
getServerPlugins(api)
|
|
53
48
|
];
|
|
54
49
|
case 1:
|
|
55
50
|
plugins = _state.sent();
|
|
@@ -12,7 +12,7 @@ const build = async (api, options) => {
|
|
|
12
12
|
let resolvedConfig = api.useResolvedConfigContext();
|
|
13
13
|
const appContext = api.useAppContext();
|
|
14
14
|
const hookRunners = api.useHookRunners();
|
|
15
|
-
await loadServerPlugins(api, appContext.appDirectory
|
|
15
|
+
await loadServerPlugins(api, appContext.appDirectory);
|
|
16
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);
|
|
17
17
|
const { apiOnly } = appContext;
|
|
18
18
|
if (apiOnly) {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { getServerPlugins } from "../utils/loadPlugins";
|
|
2
2
|
const deploy = async (api, options) => {
|
|
3
3
|
const hookRunners = api.useHookRunners();
|
|
4
|
-
|
|
5
|
-
await getServerPlugins(api, metaName);
|
|
4
|
+
await getServerPlugins(api);
|
|
6
5
|
await hookRunners.beforeDeploy(options);
|
|
7
6
|
await hookRunners.deploy(options);
|
|
8
7
|
await hookRunners.afterDeploy(options);
|
|
@@ -37,7 +37,7 @@ const dev = async (api, options, devServerOptions = {}) => {
|
|
|
37
37
|
throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
|
|
38
38
|
}
|
|
39
39
|
await generateRoutes(appContext);
|
|
40
|
-
const pluginInstances = await loadServerPlugins(api, appDirectory
|
|
40
|
+
const pluginInstances = await loadServerPlugins(api, appDirectory);
|
|
41
41
|
const serverOptions = {
|
|
42
42
|
metaName,
|
|
43
43
|
dev: {
|
|
@@ -17,7 +17,7 @@ const start = async (api) => {
|
|
|
17
17
|
}
|
|
18
18
|
const meta = getMeta(metaName);
|
|
19
19
|
const serverConfigPath = path.resolve(distDirectory, SERVER_DIR, `${meta}.server`);
|
|
20
|
-
const pluginInstances = await loadServerPlugins(api, appDirectory
|
|
20
|
+
const pluginInstances = await loadServerPlugins(api, appDirectory);
|
|
21
21
|
const app = await createProdServer({
|
|
22
22
|
metaName,
|
|
23
23
|
pwd: distDirectory,
|
|
@@ -1,21 +1,11 @@
|
|
|
1
|
-
import path
|
|
1
|
+
import path 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, findPackageParents, resolveTracedPath } from "./utils";
|
|
6
|
-
const handleDependencies = async (appDir, serverRootDir,
|
|
5
|
+
import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaultTraceFiles, findPackageParents, resolveTracedPath, readDirRecursive } from "./utils";
|
|
6
|
+
const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = defaultTraceFiles, entryFilter, modifyPackageJson, copyWholePackage }) => {
|
|
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
|
-
});
|
|
19
9
|
const fileTrace = await traceFiles(entryFiles.concat(includeEntries), serverRootDir, base);
|
|
20
10
|
const currentProjectModules = path.join(appDir, "node_modules");
|
|
21
11
|
const tracedFiles = Object.fromEntries(await Promise.all([
|
|
@@ -110,9 +100,17 @@ const handleDependencies = async (appDir, serverRootDir, include, entryFilter) =
|
|
|
110
100
|
}
|
|
111
101
|
tracedPackage.versions[pkgJSON.version] = tracedPackageVersion;
|
|
112
102
|
}
|
|
113
|
-
tracedFile.path.startsWith(tracedFile.pkgPath) && tracedPackageVersion.path === tracedFile.pkgPath && tracedPackageVersion.files.push(tracedFile.path);
|
|
114
103
|
tracedFile.pkgName = pkgName;
|
|
115
104
|
tracedFile.pkgVersion = pkgJSON.version;
|
|
105
|
+
const shouldCopyWholePackage = copyWholePackage === null || copyWholePackage === void 0 ? void 0 : copyWholePackage(pkgName);
|
|
106
|
+
if (tracedFile.path.startsWith(tracedFile.pkgPath) && tracedPackageVersion.path === tracedFile.pkgPath) {
|
|
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
|
+
}
|
|
116
114
|
}
|
|
117
115
|
const multiVersionPkgs = {};
|
|
118
116
|
const singleVersionPackages = [];
|
|
@@ -130,7 +128,11 @@ const handleDependencies = async (appDir, serverRootDir, include, entryFilter) =
|
|
|
130
128
|
await Promise.all(singleVersionPackages.map((pkgName) => {
|
|
131
129
|
const pkg = tracedPackages[pkgName];
|
|
132
130
|
const version = Object.keys(pkg.versions)[0];
|
|
133
|
-
return writePackage(
|
|
131
|
+
return writePackage({
|
|
132
|
+
pkg,
|
|
133
|
+
version,
|
|
134
|
+
projectDir: serverRootDir
|
|
135
|
+
});
|
|
134
136
|
}));
|
|
135
137
|
const projectPkgJson = await readPackageJSON(serverRootDir).catch(() => ({}));
|
|
136
138
|
for (const [pkgName, pkgVersions] of Object.entries(multiVersionPkgs)) {
|
|
@@ -157,7 +159,12 @@ const handleDependencies = async (appDir, serverRootDir, include, entryFilter) =
|
|
|
157
159
|
for (const [version, parentPkgs] of versionEntires) {
|
|
158
160
|
const pkg = tracedPackages[pkgName];
|
|
159
161
|
const pkgDestPath = `.modernjs/${pkgName}@${version}/node_modules/${pkgName}`;
|
|
160
|
-
await writePackage(
|
|
162
|
+
await writePackage({
|
|
163
|
+
pkg,
|
|
164
|
+
version,
|
|
165
|
+
projectDir: serverRootDir,
|
|
166
|
+
_pkgPath: pkgDestPath
|
|
167
|
+
});
|
|
161
168
|
await linkPackage(pkgDestPath, `${pkgName}`, serverRootDir);
|
|
162
169
|
for (const parentPkg of parentPkgs) {
|
|
163
170
|
const parentPkgName = parentPkg.replace(/@[^@]+$/, "");
|
|
@@ -166,7 +173,7 @@ const handleDependencies = async (appDir, serverRootDir, include, entryFilter) =
|
|
|
166
173
|
}
|
|
167
174
|
}
|
|
168
175
|
const outputPkgPath = path.join(serverRootDir, "package.json");
|
|
169
|
-
|
|
176
|
+
const newPkgJson = {
|
|
170
177
|
name: `${projectPkgJson.name || "modernjs-project"}-prod`,
|
|
171
178
|
version: projectPkgJson.version || "0.0.0",
|
|
172
179
|
private: true,
|
|
@@ -176,7 +183,9 @@ const handleDependencies = async (appDir, serverRootDir, include, entryFilter) =
|
|
|
176
183
|
Object.keys(pkg.versions)[0]
|
|
177
184
|
])
|
|
178
185
|
].sort(([a], [b]) => a.localeCompare(b)))
|
|
179
|
-
}
|
|
186
|
+
};
|
|
187
|
+
const finalPkgJson = (modifyPackageJson === null || modifyPackageJson === void 0 ? void 0 : modifyPackageJson(newPkgJson)) || newPkgJson;
|
|
188
|
+
await fse.writeJSON(outputPkgPath, finalPkgJson);
|
|
180
189
|
};
|
|
181
190
|
export {
|
|
182
191
|
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
|
|
5
|
+
import { nodeFileTrace } 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,7 +10,8 @@ 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 (
|
|
13
|
+
const writePackage = async (options) => {
|
|
14
|
+
const { pkg, version, projectDir, _pkgPath } = options;
|
|
14
15
|
const pkgPath = _pkgPath || pkg.name;
|
|
15
16
|
for (const src of pkg.versions[version].files) {
|
|
16
17
|
if (src.includes("node_modules")) {
|
|
@@ -84,31 +85,24 @@ const findEntryFiles = async (rootDir, entryFilter) => {
|
|
|
84
85
|
const findPackageParents = (pkg, version, tracedFiles) => {
|
|
85
86
|
const versionFiles = pkg.versions[version].files.map((path2) => tracedFiles[path2]);
|
|
86
87
|
const parentPkgs = [
|
|
87
|
-
...new Set(versionFiles.flatMap((file) =>
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
...new Set(versionFiles.flatMap((file) => (
|
|
89
|
+
// Because it supports copyWholePackage configuration, not all files exist.
|
|
90
|
+
file === null || file === void 0 ? void 0 : file.parents.map((parentPath) => {
|
|
91
|
+
const parentFile = tracedFiles[parentPath];
|
|
92
|
+
if (!parentFile || parentFile.pkgName === pkg.name) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
return `${parentFile.pkgName}@${parentFile.pkgVersion}`;
|
|
96
|
+
}).filter(Boolean)
|
|
97
|
+
)))
|
|
94
98
|
];
|
|
95
|
-
return parentPkgs;
|
|
99
|
+
return parentPkgs.filter((parentPkg) => parentPkg);
|
|
96
100
|
};
|
|
97
101
|
const traceFiles = async (entryFiles, serverRootDir, base = "/") => {
|
|
98
102
|
return await nodeFileTrace(entryFiles, {
|
|
99
103
|
base,
|
|
100
104
|
processCwd: serverRootDir,
|
|
101
|
-
|
|
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
|
+
cache: /* @__PURE__ */ Object.create(null)
|
|
112
106
|
});
|
|
113
107
|
};
|
|
114
108
|
const resolveTracedPath = async (base, p) => fse.realpath(path.resolve(base, p));
|
|
@@ -91,9 +91,13 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
|
|
91
91
|
if (!needModernServer) {
|
|
92
92
|
return;
|
|
93
93
|
}
|
|
94
|
-
await handleDependencies(
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
await handleDependencies({
|
|
95
|
+
appDir: appDirectory,
|
|
96
|
+
serverRootDir: funcsDirectory,
|
|
97
|
+
includeEntries: [
|
|
98
|
+
require.resolve("@modern-js/prod-server")
|
|
99
|
+
]
|
|
100
|
+
});
|
|
97
101
|
}
|
|
98
102
|
};
|
|
99
103
|
};
|
|
@@ -45,9 +45,14 @@ const createNodePreset = (appContext, config) => {
|
|
|
45
45
|
const filter = (filePath) => {
|
|
46
46
|
return !filePath.startsWith(staticDirectory);
|
|
47
47
|
};
|
|
48
|
-
await handleDependencies(
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
await handleDependencies({
|
|
49
|
+
appDir: appDirectory,
|
|
50
|
+
serverRootDir: outputDirectory,
|
|
51
|
+
includeEntries: [
|
|
52
|
+
require.resolve("@modern-js/prod-server")
|
|
53
|
+
],
|
|
54
|
+
entryFilter: filter
|
|
55
|
+
});
|
|
51
56
|
}
|
|
52
57
|
};
|
|
53
58
|
};
|
|
@@ -103,9 +103,13 @@ const createVercelPreset = (appContext, modernConfig, needModernServer) => {
|
|
|
103
103
|
if (!needModernServer) {
|
|
104
104
|
return;
|
|
105
105
|
}
|
|
106
|
-
await handleDependencies(
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
await handleDependencies({
|
|
107
|
+
appDir: appDirectory,
|
|
108
|
+
serverRootDir: funcsDirectory,
|
|
109
|
+
includeEntries: [
|
|
110
|
+
require.resolve("@modern-js/prod-server")
|
|
111
|
+
]
|
|
112
|
+
});
|
|
109
113
|
}
|
|
110
114
|
};
|
|
111
115
|
};
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { loadServerPlugins as loadServerPluginInstances } from "@modern-js/prod-server";
|
|
2
|
-
async function getServerPlugins(api
|
|
2
|
+
async function getServerPlugins(api) {
|
|
3
3
|
const runner = api.useHookRunners();
|
|
4
4
|
const { plugins } = await runner._internalServerPlugins({
|
|
5
5
|
plugins: []
|
|
6
6
|
});
|
|
7
|
-
const filtedPlugins = plugins.filter((plugin) => plugin.name.includes(metaName));
|
|
8
7
|
api.setAppContext({
|
|
9
8
|
...api.useAppContext(),
|
|
10
|
-
serverPlugins:
|
|
9
|
+
serverPlugins: plugins
|
|
11
10
|
});
|
|
12
|
-
return
|
|
11
|
+
return plugins;
|
|
13
12
|
}
|
|
14
|
-
async function loadServerPlugins(api, appDirectory
|
|
15
|
-
const plugins = await getServerPlugins(api
|
|
13
|
+
async function loadServerPlugins(api, appDirectory) {
|
|
14
|
+
const plugins = await getServerPlugins(api);
|
|
16
15
|
const instances = loadServerPluginInstances(plugins, appDirectory);
|
|
17
16
|
return instances;
|
|
18
17
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const JS_EXTENSIONS = ['.js', '.ts', '.jsx', '.tsx'];
|
|
2
|
+
export const INDEX_FILE_NAME = 'index';
|
|
3
|
+
export const APP_FILE_NAME = 'App';
|
|
4
|
+
export const PAGES_DIR_NAME = 'pages';
|
|
5
|
+
export const FILE_SYSTEM_ROUTES_FILE_NAME = 'routes.js';
|
|
6
|
+
export const ENTRY_POINT_FILE_NAME = 'index.js';
|
|
7
|
+
export const ENTRY_BOOTSTRAP_FILE_NAME = 'bootstrap.js';
|
|
8
|
+
export const FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP = /^\[(\S+)\]([*+?]?)$/;
|
|
9
|
+
export const FILE_SYSTEM_ROUTES_LAYOUT = '_layout';
|
|
10
|
+
export const FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT = '_app';
|
|
11
|
+
export const FILE_SYSTEM_ROUTES_INDEX = 'index';
|
|
12
|
+
export const FILE_SYSTEM_ROUTES_IGNORED_REGEX = /\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/;
|
|
13
|
+
export const HTML_PARTIALS_FOLDER = 'html';
|
|
14
|
+
export const HTML_PARTIALS_EXTENSIONS = ['.htm', '.html', '.ejs'];
|
|
15
|
+
export const FILE_SYSTEM_ROUTES_COMPONENTS_DIR = 'internal_components';
|