@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
|
@@ -35,7 +35,7 @@ const build = async (api, options) => {
|
|
|
35
35
|
let resolvedConfig = api.useResolvedConfigContext();
|
|
36
36
|
const appContext = api.useAppContext();
|
|
37
37
|
const hookRunners = api.useHookRunners();
|
|
38
|
-
await (0, import_loadPlugins.loadServerPlugins)(api, appContext.appDirectory
|
|
38
|
+
await (0, import_loadPlugins.loadServerPlugins)(api, appContext.appDirectory);
|
|
39
39
|
await (0, import_register.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);
|
|
40
40
|
const { apiOnly } = appContext;
|
|
41
41
|
if (apiOnly) {
|
|
@@ -24,8 +24,7 @@ module.exports = __toCommonJS(deploy_exports);
|
|
|
24
24
|
var import_loadPlugins = require("../utils/loadPlugins");
|
|
25
25
|
const deploy = async (api, options) => {
|
|
26
26
|
const hookRunners = api.useHookRunners();
|
|
27
|
-
|
|
28
|
-
await (0, import_loadPlugins.getServerPlugins)(api, metaName);
|
|
27
|
+
await (0, import_loadPlugins.getServerPlugins)(api);
|
|
29
28
|
await hookRunners.beforeDeploy(options);
|
|
30
29
|
await hookRunners.deploy(options);
|
|
31
30
|
await hookRunners.afterDeploy(options);
|
package/dist/cjs/commands/dev.js
CHANGED
|
@@ -70,7 +70,7 @@ const dev = async (api, options, devServerOptions = {}) => {
|
|
|
70
70
|
throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
|
|
71
71
|
}
|
|
72
72
|
await (0, import_routes.generateRoutes)(appContext);
|
|
73
|
-
const pluginInstances = await (0, import_loadPlugins.loadServerPlugins)(api, appDirectory
|
|
73
|
+
const pluginInstances = await (0, import_loadPlugins.loadServerPlugins)(api, appDirectory);
|
|
74
74
|
const serverOptions = {
|
|
75
75
|
metaName,
|
|
76
76
|
dev: {
|
|
@@ -50,7 +50,7 @@ const start = async (api) => {
|
|
|
50
50
|
}
|
|
51
51
|
const meta = (0, import_utils.getMeta)(metaName);
|
|
52
52
|
const serverConfigPath = import_path.default.resolve(distDirectory, import_utils.SERVER_DIR, `${meta}.server`);
|
|
53
|
-
const pluginInstances = await (0, import_loadPlugins.loadServerPlugins)(api, appDirectory
|
|
53
|
+
const pluginInstances = await (0, import_loadPlugins.loadServerPlugins)(api, appDirectory);
|
|
54
54
|
const app = await (0, import_prod_server.createProdServer)({
|
|
55
55
|
metaName,
|
|
56
56
|
pwd: distDirectory,
|
|
@@ -36,20 +36,10 @@ var import_utils = require("@modern-js/utils");
|
|
|
36
36
|
var import_pkg_types = require("pkg-types");
|
|
37
37
|
var import_mlly = require("mlly");
|
|
38
38
|
var import_utils2 = require("./utils");
|
|
39
|
-
const handleDependencies = async (appDir, serverRootDir,
|
|
39
|
+
const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = import_utils2.traceFiles, entryFilter, modifyPackageJson, copyWholePackage }) => {
|
|
40
40
|
const base = "/";
|
|
41
41
|
const entryFiles = await (0, import_utils2.findEntryFiles)(serverRootDir, entryFilter);
|
|
42
|
-
const
|
|
43
|
-
if ((0, import_node_path.isAbsolute)(item)) {
|
|
44
|
-
return item;
|
|
45
|
-
}
|
|
46
|
-
try {
|
|
47
|
-
return require.resolve(item);
|
|
48
|
-
} catch (error) {
|
|
49
|
-
}
|
|
50
|
-
return item;
|
|
51
|
-
});
|
|
52
|
-
const fileTrace = await (0, import_utils2.traceFiles)(entryFiles.concat(includeEntries), serverRootDir, base);
|
|
42
|
+
const fileTrace = await traceFiles(entryFiles.concat(includeEntries), serverRootDir, base);
|
|
53
43
|
const currentProjectModules = import_node_path.default.join(appDir, "node_modules");
|
|
54
44
|
const tracedFiles = Object.fromEntries(await Promise.all([
|
|
55
45
|
...fileTrace.reasons.entries()
|
|
@@ -143,9 +133,17 @@ const handleDependencies = async (appDir, serverRootDir, include, entryFilter) =
|
|
|
143
133
|
}
|
|
144
134
|
tracedPackage.versions[pkgJSON.version] = tracedPackageVersion;
|
|
145
135
|
}
|
|
146
|
-
tracedFile.path.startsWith(tracedFile.pkgPath) && tracedPackageVersion.path === tracedFile.pkgPath && tracedPackageVersion.files.push(tracedFile.path);
|
|
147
136
|
tracedFile.pkgName = pkgName;
|
|
148
137
|
tracedFile.pkgVersion = pkgJSON.version;
|
|
138
|
+
const shouldCopyWholePackage = copyWholePackage === null || copyWholePackage === void 0 ? void 0 : copyWholePackage(pkgName);
|
|
139
|
+
if (tracedFile.path.startsWith(tracedFile.pkgPath) && tracedPackageVersion.path === tracedFile.pkgPath) {
|
|
140
|
+
if (shouldCopyWholePackage) {
|
|
141
|
+
const allFiles = await (0, import_utils2.readDirRecursive)(tracedFile.pkgPath);
|
|
142
|
+
tracedPackageVersion.files.push(...allFiles);
|
|
143
|
+
} else {
|
|
144
|
+
tracedPackageVersion.files.push(tracedFile.path);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
149
147
|
}
|
|
150
148
|
const multiVersionPkgs = {};
|
|
151
149
|
const singleVersionPackages = [];
|
|
@@ -163,7 +161,11 @@ const handleDependencies = async (appDir, serverRootDir, include, entryFilter) =
|
|
|
163
161
|
await Promise.all(singleVersionPackages.map((pkgName) => {
|
|
164
162
|
const pkg = tracedPackages[pkgName];
|
|
165
163
|
const version = Object.keys(pkg.versions)[0];
|
|
166
|
-
return (0, import_utils2.writePackage)(
|
|
164
|
+
return (0, import_utils2.writePackage)({
|
|
165
|
+
pkg,
|
|
166
|
+
version,
|
|
167
|
+
projectDir: serverRootDir
|
|
168
|
+
});
|
|
167
169
|
}));
|
|
168
170
|
const projectPkgJson = await (0, import_pkg_types.readPackageJSON)(serverRootDir).catch(() => ({}));
|
|
169
171
|
for (const [pkgName, pkgVersions] of Object.entries(multiVersionPkgs)) {
|
|
@@ -190,7 +192,12 @@ const handleDependencies = async (appDir, serverRootDir, include, entryFilter) =
|
|
|
190
192
|
for (const [version, parentPkgs] of versionEntires) {
|
|
191
193
|
const pkg = tracedPackages[pkgName];
|
|
192
194
|
const pkgDestPath = `.modernjs/${pkgName}@${version}/node_modules/${pkgName}`;
|
|
193
|
-
await (0, import_utils2.writePackage)(
|
|
195
|
+
await (0, import_utils2.writePackage)({
|
|
196
|
+
pkg,
|
|
197
|
+
version,
|
|
198
|
+
projectDir: serverRootDir,
|
|
199
|
+
_pkgPath: pkgDestPath
|
|
200
|
+
});
|
|
194
201
|
await (0, import_utils2.linkPackage)(pkgDestPath, `${pkgName}`, serverRootDir);
|
|
195
202
|
for (const parentPkg of parentPkgs) {
|
|
196
203
|
const parentPkgName = parentPkg.replace(/@[^@]+$/, "");
|
|
@@ -199,7 +206,7 @@ const handleDependencies = async (appDir, serverRootDir, include, entryFilter) =
|
|
|
199
206
|
}
|
|
200
207
|
}
|
|
201
208
|
const outputPkgPath = import_node_path.default.join(serverRootDir, "package.json");
|
|
202
|
-
|
|
209
|
+
const newPkgJson = {
|
|
203
210
|
name: `${projectPkgJson.name || "modernjs-project"}-prod`,
|
|
204
211
|
version: projectPkgJson.version || "0.0.0",
|
|
205
212
|
private: true,
|
|
@@ -209,7 +216,9 @@ const handleDependencies = async (appDir, serverRootDir, include, entryFilter) =
|
|
|
209
216
|
Object.keys(pkg.versions)[0]
|
|
210
217
|
])
|
|
211
218
|
].sort(([a], [b]) => a.localeCompare(b)))
|
|
212
|
-
}
|
|
219
|
+
};
|
|
220
|
+
const finalPkgJson = (modifyPackageJson === null || modifyPackageJson === void 0 ? void 0 : modifyPackageJson(newPkgJson)) || newPkgJson;
|
|
221
|
+
await import_utils.fs.writeJSON(outputPkgPath, finalPkgJson);
|
|
213
222
|
};
|
|
214
223
|
// Annotate the CommonJS export names for ESM import in node:
|
|
215
224
|
0 && (module.exports = {
|
|
@@ -50,7 +50,8 @@ function applyPublicCondition(pkg) {
|
|
|
50
50
|
pkg.exports = pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig1 = pkg.publishConfig) === null || _pkg_publishConfig1 === void 0 ? void 0 : _pkg_publishConfig1.exports;
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
|
-
const writePackage = async (
|
|
53
|
+
const writePackage = async (options) => {
|
|
54
|
+
const { pkg, version, projectDir, _pkgPath } = options;
|
|
54
55
|
const pkgPath = _pkgPath || pkg.name;
|
|
55
56
|
for (const src of pkg.versions[version].files) {
|
|
56
57
|
if (src.includes("node_modules")) {
|
|
@@ -124,31 +125,24 @@ const findEntryFiles = async (rootDir, entryFilter) => {
|
|
|
124
125
|
const findPackageParents = (pkg, version, tracedFiles) => {
|
|
125
126
|
const versionFiles = pkg.versions[version].files.map((path2) => tracedFiles[path2]);
|
|
126
127
|
const parentPkgs = [
|
|
127
|
-
...new Set(versionFiles.flatMap((file) =>
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
128
|
+
...new Set(versionFiles.flatMap((file) => (
|
|
129
|
+
// Because it supports copyWholePackage configuration, not all files exist.
|
|
130
|
+
file === null || file === void 0 ? void 0 : file.parents.map((parentPath) => {
|
|
131
|
+
const parentFile = tracedFiles[parentPath];
|
|
132
|
+
if (!parentFile || parentFile.pkgName === pkg.name) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
return `${parentFile.pkgName}@${parentFile.pkgVersion}`;
|
|
136
|
+
}).filter(Boolean)
|
|
137
|
+
)))
|
|
134
138
|
];
|
|
135
|
-
return parentPkgs;
|
|
139
|
+
return parentPkgs.filter((parentPkg) => parentPkg);
|
|
136
140
|
};
|
|
137
141
|
const traceFiles = async (entryFiles, serverRootDir, base = "/") => {
|
|
138
142
|
return await (0, import_nft.nodeFileTrace)(entryFiles, {
|
|
139
143
|
base,
|
|
140
144
|
processCwd: serverRootDir,
|
|
141
|
-
|
|
142
|
-
if (id.startsWith("@modern-js/prod-server")) {
|
|
143
|
-
return require.resolve(id, {
|
|
144
|
-
paths: [
|
|
145
|
-
require.resolve("@modern-js/app-tools")
|
|
146
|
-
]
|
|
147
|
-
});
|
|
148
|
-
} else {
|
|
149
|
-
return (0, import_nft.resolve)(id, parent, job, isCjs);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
145
|
+
cache: /* @__PURE__ */ Object.create(null)
|
|
152
146
|
});
|
|
153
147
|
};
|
|
154
148
|
const resolveTracedPath = async (base, p) => import_utils.fs.realpath(import_path.default.resolve(base, p));
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var exports_exports = {};
|
|
20
|
+
__export(exports_exports, {
|
|
21
|
+
handleDependencies: () => import_dependencies.handleDependencies
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(exports_exports);
|
|
24
|
+
var import_dependencies = require("./dependencies");
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
handleDependencies
|
|
28
|
+
});
|
|
@@ -124,9 +124,13 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
|
|
124
124
|
if (!needModernServer) {
|
|
125
125
|
return;
|
|
126
126
|
}
|
|
127
|
-
await (0, import_dependencies.handleDependencies)(
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
await (0, import_dependencies.handleDependencies)({
|
|
128
|
+
appDir: appDirectory,
|
|
129
|
+
serverRootDir: funcsDirectory,
|
|
130
|
+
includeEntries: [
|
|
131
|
+
require.resolve("@modern-js/prod-server")
|
|
132
|
+
]
|
|
133
|
+
});
|
|
130
134
|
}
|
|
131
135
|
};
|
|
132
136
|
};
|
|
@@ -78,9 +78,14 @@ const createNodePreset = (appContext, config) => {
|
|
|
78
78
|
const filter = (filePath) => {
|
|
79
79
|
return !filePath.startsWith(staticDirectory);
|
|
80
80
|
};
|
|
81
|
-
await (0, import_dependencies.handleDependencies)(
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
await (0, import_dependencies.handleDependencies)({
|
|
82
|
+
appDir: appDirectory,
|
|
83
|
+
serverRootDir: outputDirectory,
|
|
84
|
+
includeEntries: [
|
|
85
|
+
require.resolve("@modern-js/prod-server")
|
|
86
|
+
],
|
|
87
|
+
entryFilter: filter
|
|
88
|
+
});
|
|
84
89
|
}
|
|
85
90
|
};
|
|
86
91
|
};
|
|
@@ -136,9 +136,13 @@ const createVercelPreset = (appContext, modernConfig, needModernServer) => {
|
|
|
136
136
|
if (!needModernServer) {
|
|
137
137
|
return;
|
|
138
138
|
}
|
|
139
|
-
await (0, import_dependencies.handleDependencies)(
|
|
140
|
-
|
|
141
|
-
|
|
139
|
+
await (0, import_dependencies.handleDependencies)({
|
|
140
|
+
appDir: appDirectory,
|
|
141
|
+
serverRootDir: funcsDirectory,
|
|
142
|
+
includeEntries: [
|
|
143
|
+
require.resolve("@modern-js/prod-server")
|
|
144
|
+
]
|
|
145
|
+
});
|
|
142
146
|
}
|
|
143
147
|
};
|
|
144
148
|
};
|
|
@@ -23,20 +23,19 @@ __export(loadPlugins_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(loadPlugins_exports);
|
|
25
25
|
var import_prod_server = require("@modern-js/prod-server");
|
|
26
|
-
async function getServerPlugins(api
|
|
26
|
+
async function getServerPlugins(api) {
|
|
27
27
|
const runner = api.useHookRunners();
|
|
28
28
|
const { plugins } = await runner._internalServerPlugins({
|
|
29
29
|
plugins: []
|
|
30
30
|
});
|
|
31
|
-
const filtedPlugins = plugins.filter((plugin) => plugin.name.includes(metaName));
|
|
32
31
|
api.setAppContext({
|
|
33
32
|
...api.useAppContext(),
|
|
34
|
-
serverPlugins:
|
|
33
|
+
serverPlugins: plugins
|
|
35
34
|
});
|
|
36
|
-
return
|
|
35
|
+
return plugins;
|
|
37
36
|
}
|
|
38
|
-
async function loadServerPlugins(api, appDirectory
|
|
39
|
-
const plugins = await getServerPlugins(api
|
|
37
|
+
async function loadServerPlugins(api, appDirectory) {
|
|
38
|
+
const plugins = await getServerPlugins(api);
|
|
40
39
|
const instances = (0, import_prod_server.loadServerPlugins)(plugins, appDirectory);
|
|
41
40
|
return instances;
|
|
42
41
|
}
|
|
@@ -3,15 +3,14 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
|
3
3
|
import { getServerPlugins } from "../utils/loadPlugins";
|
|
4
4
|
var deploy = function() {
|
|
5
5
|
var _ref = _async_to_generator(function(api, options) {
|
|
6
|
-
var hookRunners
|
|
6
|
+
var hookRunners;
|
|
7
7
|
return _ts_generator(this, function(_state) {
|
|
8
8
|
switch (_state.label) {
|
|
9
9
|
case 0:
|
|
10
10
|
hookRunners = api.useHookRunners();
|
|
11
|
-
metaName = api.useAppContext().metaName;
|
|
12
11
|
return [
|
|
13
12
|
4,
|
|
14
|
-
getServerPlugins(api
|
|
13
|
+
getServerPlugins(api)
|
|
15
14
|
];
|
|
16
15
|
case 1:
|
|
17
16
|
_state.sent();
|
package/dist/esm/commands/dev.js
CHANGED
|
@@ -31,7 +31,7 @@ var start = function() {
|
|
|
31
31
|
serverConfigPath = path.resolve(distDirectory, SERVER_DIR, "".concat(meta, ".server"));
|
|
32
32
|
return [
|
|
33
33
|
4,
|
|
34
|
-
loadServerPlugins(api, appDirectory
|
|
34
|
+
loadServerPlugins(api, appDirectory)
|
|
35
35
|
];
|
|
36
36
|
case 2:
|
|
37
37
|
pluginInstances = _state.sent();
|
|
@@ -3,17 +3,18 @@ import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
|
3
3
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
5
5
|
import { _ as _ts_values } from "@swc/helpers/_/_ts_values";
|
|
6
|
-
import path
|
|
6
|
+
import path from "node:path";
|
|
7
7
|
import { fs as fse, pkgUp, semver } from "@modern-js/utils";
|
|
8
8
|
import { readPackageJSON } from "pkg-types";
|
|
9
9
|
import { parseNodeModulePath } from "mlly";
|
|
10
|
-
import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles, findPackageParents, resolveTracedPath } from "./utils";
|
|
10
|
+
import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaultTraceFiles, findPackageParents, resolveTracedPath, readDirRecursive } from "./utils";
|
|
11
11
|
var handleDependencies = function() {
|
|
12
|
-
var _ref = _async_to_generator(function(
|
|
13
|
-
var
|
|
12
|
+
var _ref = _async_to_generator(function(param) {
|
|
13
|
+
var appDir, serverRootDir, includeEntries, _param_traceFiles, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, base, entryFiles, fileTrace, currentProjectModules, tracedFiles, _, tracedPackages, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, tracedFile, pkgName, tracedPackage, pkgJSON, tracedPackageVersion, shouldCopyWholePackage, _tracedPackageVersion_files, allFiles, err, multiVersionPkgs, singleVersionPackages, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, tracedPackage1, versions, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, version, projectPkgJson, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _loop, _iterator3, _step3, err, outputPkgPath, newPkgJson, finalPkgJson;
|
|
14
14
|
return _ts_generator(this, function(_state) {
|
|
15
15
|
switch (_state.label) {
|
|
16
16
|
case 0:
|
|
17
|
+
appDir = param.appDir, serverRootDir = param.serverRootDir, includeEntries = param.includeEntries, _param_traceFiles = param.traceFiles, traceFiles = _param_traceFiles === void 0 ? defaultTraceFiles : _param_traceFiles, entryFilter = param.entryFilter, modifyPackageJson = param.modifyPackageJson, copyWholePackage = param.copyWholePackage;
|
|
17
18
|
base = "/";
|
|
18
19
|
return [
|
|
19
20
|
4,
|
|
@@ -21,16 +22,6 @@ var handleDependencies = function() {
|
|
|
21
22
|
];
|
|
22
23
|
case 1:
|
|
23
24
|
entryFiles = _state.sent();
|
|
24
|
-
includeEntries = include.map(function(item) {
|
|
25
|
-
if (isAbsolute(item)) {
|
|
26
|
-
return item;
|
|
27
|
-
}
|
|
28
|
-
try {
|
|
29
|
-
return require.resolve(item);
|
|
30
|
-
} catch (error) {
|
|
31
|
-
}
|
|
32
|
-
return item;
|
|
33
|
-
});
|
|
34
25
|
return [
|
|
35
26
|
4,
|
|
36
27
|
traceFiles(entryFiles.concat(includeEntries), serverRootDir, base)
|
|
@@ -42,12 +33,12 @@ var handleDependencies = function() {
|
|
|
42
33
|
return [
|
|
43
34
|
4,
|
|
44
35
|
Promise.all(_to_consumable_array(fileTrace.reasons.entries()).map(function() {
|
|
45
|
-
var _ref2 = _async_to_generator(function(
|
|
36
|
+
var _ref2 = _async_to_generator(function(param2) {
|
|
46
37
|
var _param, _path, reasons, filePath, baseDir, pkgName2, subpath, pkgPath, parsed, MODERN_UTILS_PATH, MODERN_UTILS_PATH_REGEX, match, packageJsonPath, _tmp, packageJson, parents, tracedFile2;
|
|
47
38
|
return _ts_generator(this, function(_state2) {
|
|
48
39
|
switch (_state2.label) {
|
|
49
40
|
case 0:
|
|
50
|
-
_param = _sliced_to_array(
|
|
41
|
+
_param = _sliced_to_array(param2, 2), _path = _param[0], reasons = _param[1];
|
|
51
42
|
if (reasons.ignored) {
|
|
52
43
|
return [
|
|
53
44
|
2
|
|
@@ -180,9 +171,9 @@ var handleDependencies = function() {
|
|
|
180
171
|
case 4:
|
|
181
172
|
_state.trys.push([
|
|
182
173
|
4,
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
174
|
+
11,
|
|
175
|
+
12,
|
|
176
|
+
13
|
|
186
177
|
]);
|
|
187
178
|
_iterator = Object.values(tracedFiles)[Symbol.iterator]();
|
|
188
179
|
_state.label = 5;
|
|
@@ -190,7 +181,7 @@ var handleDependencies = function() {
|
|
|
190
181
|
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done))
|
|
191
182
|
return [
|
|
192
183
|
3,
|
|
193
|
-
|
|
184
|
+
10
|
|
194
185
|
];
|
|
195
186
|
tracedFile = _step.value;
|
|
196
187
|
pkgName = tracedFile.pkgName;
|
|
@@ -230,30 +221,53 @@ var handleDependencies = function() {
|
|
|
230
221
|
}
|
|
231
222
|
tracedPackage.versions[pkgJSON.version] = tracedPackageVersion;
|
|
232
223
|
}
|
|
233
|
-
tracedFile.path.startsWith(tracedFile.pkgPath) && tracedPackageVersion.path === tracedFile.pkgPath && tracedPackageVersion.files.push(tracedFile.path);
|
|
234
224
|
tracedFile.pkgName = pkgName;
|
|
235
225
|
tracedFile.pkgVersion = pkgJSON.version;
|
|
236
|
-
|
|
226
|
+
shouldCopyWholePackage = copyWholePackage === null || copyWholePackage === void 0 ? void 0 : copyWholePackage(pkgName);
|
|
227
|
+
if (!(tracedFile.path.startsWith(tracedFile.pkgPath) && tracedPackageVersion.path === tracedFile.pkgPath))
|
|
228
|
+
return [
|
|
229
|
+
3,
|
|
230
|
+
9
|
|
231
|
+
];
|
|
232
|
+
if (!shouldCopyWholePackage)
|
|
233
|
+
return [
|
|
234
|
+
3,
|
|
235
|
+
8
|
|
236
|
+
];
|
|
237
|
+
return [
|
|
238
|
+
4,
|
|
239
|
+
readDirRecursive(tracedFile.pkgPath)
|
|
240
|
+
];
|
|
237
241
|
case 7:
|
|
242
|
+
allFiles = _state.sent();
|
|
243
|
+
(_tracedPackageVersion_files = tracedPackageVersion.files).push.apply(_tracedPackageVersion_files, _to_consumable_array(allFiles));
|
|
244
|
+
return [
|
|
245
|
+
3,
|
|
246
|
+
9
|
|
247
|
+
];
|
|
248
|
+
case 8:
|
|
249
|
+
tracedPackageVersion.files.push(tracedFile.path);
|
|
250
|
+
_state.label = 9;
|
|
251
|
+
case 9:
|
|
238
252
|
_iteratorNormalCompletion = true;
|
|
239
253
|
return [
|
|
240
254
|
3,
|
|
241
255
|
5
|
|
242
256
|
];
|
|
243
|
-
case
|
|
257
|
+
case 10:
|
|
244
258
|
return [
|
|
245
259
|
3,
|
|
246
|
-
|
|
260
|
+
13
|
|
247
261
|
];
|
|
248
|
-
case
|
|
262
|
+
case 11:
|
|
249
263
|
err = _state.sent();
|
|
250
264
|
_didIteratorError = true;
|
|
251
265
|
_iteratorError = err;
|
|
252
266
|
return [
|
|
253
267
|
3,
|
|
254
|
-
|
|
268
|
+
13
|
|
255
269
|
];
|
|
256
|
-
case
|
|
270
|
+
case 12:
|
|
257
271
|
try {
|
|
258
272
|
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
259
273
|
_iterator.return();
|
|
@@ -266,7 +280,7 @@ var handleDependencies = function() {
|
|
|
266
280
|
return [
|
|
267
281
|
7
|
|
268
282
|
];
|
|
269
|
-
case
|
|
283
|
+
case 13:
|
|
270
284
|
multiVersionPkgs = {};
|
|
271
285
|
singleVersionPackages = [];
|
|
272
286
|
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
|
|
@@ -319,10 +333,14 @@ var handleDependencies = function() {
|
|
|
319
333
|
Promise.all(singleVersionPackages.map(function(pkgName2) {
|
|
320
334
|
var pkg = tracedPackages[pkgName2];
|
|
321
335
|
var version2 = Object.keys(pkg.versions)[0];
|
|
322
|
-
return writePackage(
|
|
336
|
+
return writePackage({
|
|
337
|
+
pkg,
|
|
338
|
+
version: version2,
|
|
339
|
+
projectDir: serverRootDir
|
|
340
|
+
});
|
|
323
341
|
}))
|
|
324
342
|
];
|
|
325
|
-
case
|
|
343
|
+
case 14:
|
|
326
344
|
_state.sent();
|
|
327
345
|
return [
|
|
328
346
|
4,
|
|
@@ -330,16 +348,16 @@ var handleDependencies = function() {
|
|
|
330
348
|
return {};
|
|
331
349
|
})
|
|
332
350
|
];
|
|
333
|
-
case
|
|
351
|
+
case 15:
|
|
334
352
|
projectPkgJson = _state.sent();
|
|
335
353
|
_iteratorNormalCompletion3 = true, _didIteratorError3 = false, _iteratorError3 = void 0;
|
|
336
|
-
_state.label =
|
|
337
|
-
case
|
|
354
|
+
_state.label = 16;
|
|
355
|
+
case 16:
|
|
338
356
|
_state.trys.push([
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
357
|
+
16,
|
|
358
|
+
21,
|
|
359
|
+
22,
|
|
360
|
+
23
|
|
343
361
|
]);
|
|
344
362
|
_loop = function() {
|
|
345
363
|
var _step_value, pkgName2, pkgVersions, versionEntires, _iteratorNormalCompletion4, _didIteratorError4, _iteratorError4, _iterator4, _step4, _step_value1, version2, parentPkgs, pkg, pkgDestPath, _iteratorNormalCompletion12, _didIteratorError12, _iteratorError12, _iterator12, _step12, parentPkg, parentPkgName, err2, err2;
|
|
@@ -347,8 +365,8 @@ var handleDependencies = function() {
|
|
|
347
365
|
switch (_state2.label) {
|
|
348
366
|
case 0:
|
|
349
367
|
_step_value = _sliced_to_array(_step3.value, 2), pkgName2 = _step_value[0], pkgVersions = _step_value[1];
|
|
350
|
-
versionEntires = Object.entries(pkgVersions).sort(function(
|
|
351
|
-
var _param = _sliced_to_array(
|
|
368
|
+
versionEntires = Object.entries(pkgVersions).sort(function(param2, param1) {
|
|
369
|
+
var _param = _sliced_to_array(param2, 2), v1 = _param[0], p1 = _param[1], _param1 = _sliced_to_array(param1, 2), v2 = _param1[0], p2 = _param1[1];
|
|
352
370
|
var _tracedPackages_pkgName_versions_v1, _tracedPackages_pkgName_versions, _tracedPackages_pkgName, _tracedPackages_pkgName_versions_v2, _tracedPackages_pkgName_versions1, _tracedPackages_pkgName1;
|
|
353
371
|
var shouldHoist1 = (_tracedPackages_pkgName = tracedPackages[pkgName2]) === null || _tracedPackages_pkgName === void 0 ? void 0 : (_tracedPackages_pkgName_versions = _tracedPackages_pkgName.versions) === null || _tracedPackages_pkgName_versions === void 0 ? void 0 : (_tracedPackages_pkgName_versions_v1 = _tracedPackages_pkgName_versions[v1]) === null || _tracedPackages_pkgName_versions_v1 === void 0 ? void 0 : _tracedPackages_pkgName_versions_v1.isDirectDep;
|
|
354
372
|
var shouldHoist2 = (_tracedPackages_pkgName1 = tracedPackages[pkgName2]) === null || _tracedPackages_pkgName1 === void 0 ? void 0 : (_tracedPackages_pkgName_versions1 = _tracedPackages_pkgName1.versions) === null || _tracedPackages_pkgName_versions1 === void 0 ? void 0 : (_tracedPackages_pkgName_versions_v2 = _tracedPackages_pkgName_versions1[v2]) === null || _tracedPackages_pkgName_versions_v2 === void 0 ? void 0 : _tracedPackages_pkgName_versions_v2.isDirectDep;
|
|
@@ -390,7 +408,12 @@ var handleDependencies = function() {
|
|
|
390
408
|
pkgDestPath = ".modernjs/".concat(pkgName2, "@").concat(version2, "/node_modules/").concat(pkgName2);
|
|
391
409
|
return [
|
|
392
410
|
4,
|
|
393
|
-
writePackage(
|
|
411
|
+
writePackage({
|
|
412
|
+
pkg,
|
|
413
|
+
version: version2,
|
|
414
|
+
projectDir: serverRootDir,
|
|
415
|
+
_pkgPath: pkgDestPath
|
|
416
|
+
})
|
|
394
417
|
];
|
|
395
418
|
case 3:
|
|
396
419
|
_state2.sent();
|
|
@@ -498,40 +521,40 @@ var handleDependencies = function() {
|
|
|
498
521
|
});
|
|
499
522
|
};
|
|
500
523
|
_iterator3 = Object.entries(multiVersionPkgs)[Symbol.iterator]();
|
|
501
|
-
_state.label =
|
|
502
|
-
case
|
|
524
|
+
_state.label = 17;
|
|
525
|
+
case 17:
|
|
503
526
|
if (!!(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done))
|
|
504
527
|
return [
|
|
505
528
|
3,
|
|
506
|
-
|
|
529
|
+
20
|
|
507
530
|
];
|
|
508
531
|
return [
|
|
509
532
|
5,
|
|
510
533
|
_ts_values(_loop())
|
|
511
534
|
];
|
|
512
|
-
case
|
|
535
|
+
case 18:
|
|
513
536
|
_state.sent();
|
|
514
|
-
_state.label =
|
|
515
|
-
case
|
|
537
|
+
_state.label = 19;
|
|
538
|
+
case 19:
|
|
516
539
|
_iteratorNormalCompletion3 = true;
|
|
517
540
|
return [
|
|
518
541
|
3,
|
|
519
|
-
|
|
542
|
+
17
|
|
520
543
|
];
|
|
521
|
-
case
|
|
544
|
+
case 20:
|
|
522
545
|
return [
|
|
523
546
|
3,
|
|
524
|
-
|
|
547
|
+
23
|
|
525
548
|
];
|
|
526
|
-
case
|
|
549
|
+
case 21:
|
|
527
550
|
err = _state.sent();
|
|
528
551
|
_didIteratorError3 = true;
|
|
529
552
|
_iteratorError3 = err;
|
|
530
553
|
return [
|
|
531
554
|
3,
|
|
532
|
-
|
|
555
|
+
23
|
|
533
556
|
];
|
|
534
|
-
case
|
|
557
|
+
case 22:
|
|
535
558
|
try {
|
|
536
559
|
if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
|
|
537
560
|
_iterator3.return();
|
|
@@ -544,26 +567,28 @@ var handleDependencies = function() {
|
|
|
544
567
|
return [
|
|
545
568
|
7
|
|
546
569
|
];
|
|
547
|
-
case
|
|
570
|
+
case 23:
|
|
548
571
|
outputPkgPath = path.join(serverRootDir, "package.json");
|
|
572
|
+
newPkgJson = {
|
|
573
|
+
name: "".concat(projectPkgJson.name || "modernjs-project", "-prod"),
|
|
574
|
+
version: projectPkgJson.version || "0.0.0",
|
|
575
|
+
private: true,
|
|
576
|
+
dependencies: Object.fromEntries(_to_consumable_array(Object.values(tracedPackages).map(function(pkg) {
|
|
577
|
+
return [
|
|
578
|
+
pkg.name,
|
|
579
|
+
Object.keys(pkg.versions)[0]
|
|
580
|
+
];
|
|
581
|
+
})).sort(function(param2, param1) {
|
|
582
|
+
var _param = _sliced_to_array(param2, 1), a = _param[0], _param1 = _sliced_to_array(param1, 1), b = _param1[0];
|
|
583
|
+
return a.localeCompare(b);
|
|
584
|
+
}))
|
|
585
|
+
};
|
|
586
|
+
finalPkgJson = (modifyPackageJson === null || modifyPackageJson === void 0 ? void 0 : modifyPackageJson(newPkgJson)) || newPkgJson;
|
|
549
587
|
return [
|
|
550
588
|
4,
|
|
551
|
-
fse.writeJSON(outputPkgPath,
|
|
552
|
-
name: "".concat(projectPkgJson.name || "modernjs-project", "-prod"),
|
|
553
|
-
version: projectPkgJson.version || "0.0.0",
|
|
554
|
-
private: true,
|
|
555
|
-
dependencies: Object.fromEntries(_to_consumable_array(Object.values(tracedPackages).map(function(pkg) {
|
|
556
|
-
return [
|
|
557
|
-
pkg.name,
|
|
558
|
-
Object.keys(pkg.versions)[0]
|
|
559
|
-
];
|
|
560
|
-
})).sort(function(param, param1) {
|
|
561
|
-
var _param = _sliced_to_array(param, 1), a = _param[0], _param1 = _sliced_to_array(param1, 1), b = _param1[0];
|
|
562
|
-
return a.localeCompare(b);
|
|
563
|
-
}))
|
|
564
|
-
})
|
|
589
|
+
fse.writeJSON(outputPkgPath, finalPkgJson)
|
|
565
590
|
];
|
|
566
|
-
case
|
|
591
|
+
case 24:
|
|
567
592
|
_state.sent();
|
|
568
593
|
return [
|
|
569
594
|
2
|
|
@@ -571,7 +596,7 @@ var handleDependencies = function() {
|
|
|
571
596
|
}
|
|
572
597
|
});
|
|
573
598
|
});
|
|
574
|
-
return function handleDependencies2(
|
|
599
|
+
return function handleDependencies2(_) {
|
|
575
600
|
return _ref.apply(this, arguments);
|
|
576
601
|
};
|
|
577
602
|
}();
|