@modern-js/app-tools 2.54.3-alpha.4 → 2.54.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/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
|
@@ -36,10 +36,20 @@ 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 (
|
|
39
|
+
const handleDependencies = async (appDir, serverRootDir, include, entryFilter) => {
|
|
40
40
|
const base = "/";
|
|
41
41
|
const entryFiles = await (0, import_utils2.findEntryFiles)(serverRootDir, entryFilter);
|
|
42
|
-
const
|
|
42
|
+
const includeEntries = include.map((item) => {
|
|
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);
|
|
43
53
|
const currentProjectModules = import_node_path.default.join(appDir, "node_modules");
|
|
44
54
|
const tracedFiles = Object.fromEntries(await Promise.all([
|
|
45
55
|
...fileTrace.reasons.entries()
|
|
@@ -133,17 +143,9 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
|
|
|
133
143
|
}
|
|
134
144
|
tracedPackage.versions[pkgJSON.version] = tracedPackageVersion;
|
|
135
145
|
}
|
|
146
|
+
tracedFile.path.startsWith(tracedFile.pkgPath) && tracedPackageVersion.path === tracedFile.pkgPath && tracedPackageVersion.files.push(tracedFile.path);
|
|
136
147
|
tracedFile.pkgName = pkgName;
|
|
137
148
|
tracedFile.pkgVersion = pkgJSON.version;
|
|
138
|
-
const shouldCopyWholePackage = copyWholePackage === null || copyWholePackage === void 0 ? void 0 : copyWholePackage(pkgName);
|
|
139
|
-
if (tracedFile.path.startsWith(tracedFile.pkgPath) && tracedPackageVersion.pkgJSON.version === tracedFile.pkgVersion) {
|
|
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
|
-
}
|
|
147
149
|
}
|
|
148
150
|
const multiVersionPkgs = {};
|
|
149
151
|
const singleVersionPackages = [];
|
|
@@ -161,11 +163,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
|
|
|
161
163
|
await Promise.all(singleVersionPackages.map((pkgName) => {
|
|
162
164
|
const pkg = tracedPackages[pkgName];
|
|
163
165
|
const version = Object.keys(pkg.versions)[0];
|
|
164
|
-
return (0, import_utils2.writePackage)(
|
|
165
|
-
pkg,
|
|
166
|
-
version,
|
|
167
|
-
projectDir: serverRootDir
|
|
168
|
-
});
|
|
166
|
+
return (0, import_utils2.writePackage)(pkg, version, serverRootDir);
|
|
169
167
|
}));
|
|
170
168
|
const projectPkgJson = await (0, import_pkg_types.readPackageJSON)(serverRootDir).catch(() => ({}));
|
|
171
169
|
for (const [pkgName, pkgVersions] of Object.entries(multiVersionPkgs)) {
|
|
@@ -192,12 +190,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
|
|
|
192
190
|
for (const [version, parentPkgs] of versionEntires) {
|
|
193
191
|
const pkg = tracedPackages[pkgName];
|
|
194
192
|
const pkgDestPath = `.modernjs/${pkgName}@${version}/node_modules/${pkgName}`;
|
|
195
|
-
await (0, import_utils2.writePackage)(
|
|
196
|
-
pkg,
|
|
197
|
-
version,
|
|
198
|
-
projectDir: serverRootDir,
|
|
199
|
-
_pkgPath: pkgDestPath
|
|
200
|
-
});
|
|
193
|
+
await (0, import_utils2.writePackage)(pkg, version, serverRootDir, pkgDestPath);
|
|
201
194
|
await (0, import_utils2.linkPackage)(pkgDestPath, `${pkgName}`, serverRootDir);
|
|
202
195
|
for (const parentPkg of parentPkgs) {
|
|
203
196
|
const parentPkgName = parentPkg.replace(/@[^@]+$/, "");
|
|
@@ -206,7 +199,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
|
|
|
206
199
|
}
|
|
207
200
|
}
|
|
208
201
|
const outputPkgPath = import_node_path.default.join(serverRootDir, "package.json");
|
|
209
|
-
|
|
202
|
+
await import_utils.fs.writeJSON(outputPkgPath, {
|
|
210
203
|
name: `${projectPkgJson.name || "modernjs-project"}-prod`,
|
|
211
204
|
version: projectPkgJson.version || "0.0.0",
|
|
212
205
|
private: true,
|
|
@@ -216,9 +209,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
|
|
|
216
209
|
Object.keys(pkg.versions)[0]
|
|
217
210
|
])
|
|
218
211
|
].sort(([a], [b]) => a.localeCompare(b)))
|
|
219
|
-
};
|
|
220
|
-
const finalPkgJson = (modifyPackageJson === null || modifyPackageJson === void 0 ? void 0 : modifyPackageJson(newPkgJson)) || newPkgJson;
|
|
221
|
-
await import_utils.fs.writeJSON(outputPkgPath, finalPkgJson);
|
|
212
|
+
});
|
|
222
213
|
};
|
|
223
214
|
// Annotate the CommonJS export names for ESM import in node:
|
|
224
215
|
0 && (module.exports = {
|
|
@@ -50,8 +50,7 @@ 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 (
|
|
54
|
-
const { pkg, version, projectDir, _pkgPath } = options;
|
|
53
|
+
const writePackage = async (pkg, version, projectDir, _pkgPath) => {
|
|
55
54
|
const pkgPath = _pkgPath || pkg.name;
|
|
56
55
|
for (const src of pkg.versions[version].files) {
|
|
57
56
|
if (src.includes("node_modules")) {
|
|
@@ -125,23 +124,31 @@ const findEntryFiles = async (rootDir, entryFilter) => {
|
|
|
125
124
|
const findPackageParents = (pkg, version, tracedFiles) => {
|
|
126
125
|
const versionFiles = pkg.versions[version].files.map((path2) => tracedFiles[path2]);
|
|
127
126
|
const parentPkgs = [
|
|
128
|
-
...new Set(versionFiles.flatMap((file) => (
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return `${parentFile.pkgName}@${parentFile.pkgVersion}`;
|
|
136
|
-
}).filter(Boolean)
|
|
137
|
-
)))
|
|
127
|
+
...new Set(versionFiles.flatMap((file) => file.parents.map((parentPath) => {
|
|
128
|
+
const parentFile = tracedFiles[parentPath];
|
|
129
|
+
if (!parentFile || parentFile.pkgName === pkg.name) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
return `${parentFile.pkgName}@${parentFile.pkgVersion}`;
|
|
133
|
+
}).filter(Boolean)))
|
|
138
134
|
];
|
|
139
|
-
return parentPkgs
|
|
135
|
+
return parentPkgs;
|
|
140
136
|
};
|
|
141
137
|
const traceFiles = async (entryFiles, serverRootDir, base = "/") => {
|
|
142
138
|
return await (0, import_nft.nodeFileTrace)(entryFiles, {
|
|
143
139
|
base,
|
|
144
|
-
processCwd: serverRootDir
|
|
140
|
+
processCwd: serverRootDir,
|
|
141
|
+
resolve: async (id, parent, job, isCjs) => {
|
|
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
152
|
});
|
|
146
153
|
};
|
|
147
154
|
const resolveTracedPath = async (base, p) => import_utils.fs.realpath(import_path.default.resolve(base, p));
|
|
@@ -109,12 +109,14 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
|
|
109
109
|
const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
|
|
110
110
|
const dynamicProdOptions = {
|
|
111
111
|
config: serverConfig,
|
|
112
|
-
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG
|
|
113
|
-
plugins
|
|
112
|
+
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG
|
|
114
113
|
};
|
|
114
|
+
const pluginsCode = `[${plugins.map((plugin, index) => {
|
|
115
|
+
return `plugin_${index}()`;
|
|
116
|
+
}).join(",")}]`;
|
|
115
117
|
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./netlifyEntry.js"))).toString();
|
|
116
118
|
const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
|
|
117
|
-
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
|
119
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.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);
|
|
118
120
|
await import_utils.fs.writeFile(entryFilePath, entryCode);
|
|
119
121
|
},
|
|
120
122
|
async end() {
|
|
@@ -124,13 +126,9 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
|
|
124
126
|
if (!needModernServer) {
|
|
125
127
|
return;
|
|
126
128
|
}
|
|
127
|
-
await (0, import_dependencies.handleDependencies)(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
includeEntries: [
|
|
131
|
-
require.resolve("@modern-js/prod-server")
|
|
132
|
-
]
|
|
133
|
-
});
|
|
129
|
+
await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
|
|
130
|
+
"@modern-js/prod-server"
|
|
131
|
+
]);
|
|
134
132
|
}
|
|
135
133
|
};
|
|
136
134
|
};
|
|
@@ -64,12 +64,14 @@ const createNodePreset = (appContext, config) => {
|
|
|
64
64
|
const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
|
|
65
65
|
const dynamicProdOptions = {
|
|
66
66
|
config: serverConfig,
|
|
67
|
-
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG
|
|
68
|
-
plugins
|
|
67
|
+
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG
|
|
69
68
|
};
|
|
69
|
+
const pluginsCode = `[${plugins.map((plugin, index) => {
|
|
70
|
+
return `plugin_${index}()`;
|
|
71
|
+
}).join(",")}]`;
|
|
70
72
|
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./nodeEntry.js"))).toString();
|
|
71
73
|
const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
|
|
72
|
-
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
|
74
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.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);
|
|
73
75
|
await import_utils.fs.writeFile(entryFilePath, entryCode);
|
|
74
76
|
},
|
|
75
77
|
async end() {
|
|
@@ -78,14 +80,9 @@ const createNodePreset = (appContext, config) => {
|
|
|
78
80
|
const filter = (filePath) => {
|
|
79
81
|
return !filePath.startsWith(staticDirectory);
|
|
80
82
|
};
|
|
81
|
-
await (0, import_dependencies.handleDependencies)(
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
includeEntries: [
|
|
85
|
-
require.resolve("@modern-js/prod-server")
|
|
86
|
-
],
|
|
87
|
-
entryFilter: filter
|
|
88
|
-
});
|
|
83
|
+
await (0, import_dependencies.handleDependencies)(appDirectory, outputDirectory, [
|
|
84
|
+
"@modern-js/prod-server"
|
|
85
|
+
], filter);
|
|
89
86
|
}
|
|
90
87
|
};
|
|
91
88
|
};
|
|
@@ -124,25 +124,23 @@ const createVercelPreset = (appContext, modernConfig, needModernServer) => {
|
|
|
124
124
|
const pluginImportCode = (0, import_utils2.genPluginImportsCode)(plugins || []);
|
|
125
125
|
const dynamicProdOptions = {
|
|
126
126
|
config: serverConfig,
|
|
127
|
-
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG
|
|
128
|
-
plugins
|
|
127
|
+
serverConfigFile: import_utils.DEFAULT_SERVER_CONFIG
|
|
129
128
|
};
|
|
129
|
+
const pluginsCode = `[${plugins.map((plugin, index) => {
|
|
130
|
+
return `plugin_${index}()`;
|
|
131
|
+
}).join(",")}]`;
|
|
130
132
|
const serverAppContext = (0, import_utils2.serverAppContenxtTemplate)(appContext);
|
|
131
133
|
let entryCode = (await import_utils.fs.readFile(import_node_path.default.join(__dirname, "./vercelEntry.js"))).toString();
|
|
132
|
-
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.ROUTE_SPEC_FILE}"`).replace("p_dynamicProdOptions", JSON.stringify(dynamicProdOptions)).replace("p_sharedDirectory", serverAppContext.sharedDirectory).replace("p_apiDirectory", serverAppContext.apiDirectory).replace("p_lambdaDirectory", serverAppContext.lambdaDirectory);
|
|
134
|
+
entryCode = entryCode.replace("p_genPluginImportsCode", pluginImportCode).replace("p_ROUTE_SPEC_FILE", `"${import_utils.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);
|
|
133
135
|
await import_utils.fs.writeFile(entryFilePath, entryCode);
|
|
134
136
|
},
|
|
135
137
|
async end() {
|
|
136
138
|
if (!needModernServer) {
|
|
137
139
|
return;
|
|
138
140
|
}
|
|
139
|
-
await (0, import_dependencies.handleDependencies)(
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
includeEntries: [
|
|
143
|
-
require.resolve("@modern-js/prod-server")
|
|
144
|
-
]
|
|
145
|
-
});
|
|
141
|
+
await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
|
|
142
|
+
"@modern-js/prod-server"
|
|
143
|
+
]);
|
|
146
144
|
}
|
|
147
145
|
};
|
|
148
146
|
};
|
|
@@ -3,18 +3,17 @@ 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 from "node:path";
|
|
6
|
+
import path, { isAbsolute } 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
|
|
10
|
+
import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles, findPackageParents, resolveTracedPath } from "./utils";
|
|
11
11
|
var handleDependencies = function() {
|
|
12
|
-
var _ref = _async_to_generator(function(
|
|
13
|
-
var
|
|
12
|
+
var _ref = _async_to_generator(function(appDir, serverRootDir, include, entryFilter) {
|
|
13
|
+
var base, entryFiles, includeEntries, fileTrace, currentProjectModules, tracedFiles, _, tracedPackages, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, tracedFile, pkgName, tracedPackage, pkgJSON, tracedPackageVersion, 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;
|
|
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;
|
|
18
17
|
base = "/";
|
|
19
18
|
return [
|
|
20
19
|
4,
|
|
@@ -22,6 +21,16 @@ var handleDependencies = function() {
|
|
|
22
21
|
];
|
|
23
22
|
case 1:
|
|
24
23
|
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
|
+
});
|
|
25
34
|
return [
|
|
26
35
|
4,
|
|
27
36
|
traceFiles(entryFiles.concat(includeEntries), serverRootDir, base)
|
|
@@ -33,12 +42,12 @@ var handleDependencies = function() {
|
|
|
33
42
|
return [
|
|
34
43
|
4,
|
|
35
44
|
Promise.all(_to_consumable_array(fileTrace.reasons.entries()).map(function() {
|
|
36
|
-
var _ref2 = _async_to_generator(function(
|
|
45
|
+
var _ref2 = _async_to_generator(function(param) {
|
|
37
46
|
var _param, _path, reasons, filePath, baseDir, pkgName2, subpath, pkgPath, parsed, MODERN_UTILS_PATH, MODERN_UTILS_PATH_REGEX, match, packageJsonPath, _tmp, packageJson, parents, tracedFile2;
|
|
38
47
|
return _ts_generator(this, function(_state2) {
|
|
39
48
|
switch (_state2.label) {
|
|
40
49
|
case 0:
|
|
41
|
-
_param = _sliced_to_array(
|
|
50
|
+
_param = _sliced_to_array(param, 2), _path = _param[0], reasons = _param[1];
|
|
42
51
|
if (reasons.ignored) {
|
|
43
52
|
return [
|
|
44
53
|
2
|
|
@@ -171,9 +180,9 @@ var handleDependencies = function() {
|
|
|
171
180
|
case 4:
|
|
172
181
|
_state.trys.push([
|
|
173
182
|
4,
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
183
|
+
9,
|
|
184
|
+
10,
|
|
185
|
+
11
|
|
177
186
|
]);
|
|
178
187
|
_iterator = Object.values(tracedFiles)[Symbol.iterator]();
|
|
179
188
|
_state.label = 5;
|
|
@@ -181,7 +190,7 @@ var handleDependencies = function() {
|
|
|
181
190
|
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done))
|
|
182
191
|
return [
|
|
183
192
|
3,
|
|
184
|
-
|
|
193
|
+
8
|
|
185
194
|
];
|
|
186
195
|
tracedFile = _step.value;
|
|
187
196
|
pkgName = tracedFile.pkgName;
|
|
@@ -221,53 +230,30 @@ var handleDependencies = function() {
|
|
|
221
230
|
}
|
|
222
231
|
tracedPackage.versions[pkgJSON.version] = tracedPackageVersion;
|
|
223
232
|
}
|
|
233
|
+
tracedFile.path.startsWith(tracedFile.pkgPath) && tracedPackageVersion.path === tracedFile.pkgPath && tracedPackageVersion.files.push(tracedFile.path);
|
|
224
234
|
tracedFile.pkgName = pkgName;
|
|
225
235
|
tracedFile.pkgVersion = pkgJSON.version;
|
|
226
|
-
|
|
227
|
-
if (!(tracedFile.path.startsWith(tracedFile.pkgPath) && tracedPackageVersion.pkgJSON.version === tracedFile.pkgVersion))
|
|
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
|
-
];
|
|
236
|
+
_state.label = 7;
|
|
241
237
|
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:
|
|
252
238
|
_iteratorNormalCompletion = true;
|
|
253
239
|
return [
|
|
254
240
|
3,
|
|
255
241
|
5
|
|
256
242
|
];
|
|
257
|
-
case
|
|
243
|
+
case 8:
|
|
258
244
|
return [
|
|
259
245
|
3,
|
|
260
|
-
|
|
246
|
+
11
|
|
261
247
|
];
|
|
262
|
-
case
|
|
248
|
+
case 9:
|
|
263
249
|
err = _state.sent();
|
|
264
250
|
_didIteratorError = true;
|
|
265
251
|
_iteratorError = err;
|
|
266
252
|
return [
|
|
267
253
|
3,
|
|
268
|
-
|
|
254
|
+
11
|
|
269
255
|
];
|
|
270
|
-
case
|
|
256
|
+
case 10:
|
|
271
257
|
try {
|
|
272
258
|
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
273
259
|
_iterator.return();
|
|
@@ -280,7 +266,7 @@ var handleDependencies = function() {
|
|
|
280
266
|
return [
|
|
281
267
|
7
|
|
282
268
|
];
|
|
283
|
-
case
|
|
269
|
+
case 11:
|
|
284
270
|
multiVersionPkgs = {};
|
|
285
271
|
singleVersionPackages = [];
|
|
286
272
|
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
|
|
@@ -333,14 +319,10 @@ var handleDependencies = function() {
|
|
|
333
319
|
Promise.all(singleVersionPackages.map(function(pkgName2) {
|
|
334
320
|
var pkg = tracedPackages[pkgName2];
|
|
335
321
|
var version2 = Object.keys(pkg.versions)[0];
|
|
336
|
-
return writePackage(
|
|
337
|
-
pkg,
|
|
338
|
-
version: version2,
|
|
339
|
-
projectDir: serverRootDir
|
|
340
|
-
});
|
|
322
|
+
return writePackage(pkg, version2, serverRootDir);
|
|
341
323
|
}))
|
|
342
324
|
];
|
|
343
|
-
case
|
|
325
|
+
case 12:
|
|
344
326
|
_state.sent();
|
|
345
327
|
return [
|
|
346
328
|
4,
|
|
@@ -348,16 +330,16 @@ var handleDependencies = function() {
|
|
|
348
330
|
return {};
|
|
349
331
|
})
|
|
350
332
|
];
|
|
351
|
-
case
|
|
333
|
+
case 13:
|
|
352
334
|
projectPkgJson = _state.sent();
|
|
353
335
|
_iteratorNormalCompletion3 = true, _didIteratorError3 = false, _iteratorError3 = void 0;
|
|
354
|
-
_state.label =
|
|
355
|
-
case
|
|
336
|
+
_state.label = 14;
|
|
337
|
+
case 14:
|
|
356
338
|
_state.trys.push([
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
339
|
+
14,
|
|
340
|
+
19,
|
|
341
|
+
20,
|
|
342
|
+
21
|
|
361
343
|
]);
|
|
362
344
|
_loop = function() {
|
|
363
345
|
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;
|
|
@@ -365,8 +347,8 @@ var handleDependencies = function() {
|
|
|
365
347
|
switch (_state2.label) {
|
|
366
348
|
case 0:
|
|
367
349
|
_step_value = _sliced_to_array(_step3.value, 2), pkgName2 = _step_value[0], pkgVersions = _step_value[1];
|
|
368
|
-
versionEntires = Object.entries(pkgVersions).sort(function(
|
|
369
|
-
var _param = _sliced_to_array(
|
|
350
|
+
versionEntires = Object.entries(pkgVersions).sort(function(param, param1) {
|
|
351
|
+
var _param = _sliced_to_array(param, 2), v1 = _param[0], p1 = _param[1], _param1 = _sliced_to_array(param1, 2), v2 = _param1[0], p2 = _param1[1];
|
|
370
352
|
var _tracedPackages_pkgName_versions_v1, _tracedPackages_pkgName_versions, _tracedPackages_pkgName, _tracedPackages_pkgName_versions_v2, _tracedPackages_pkgName_versions1, _tracedPackages_pkgName1;
|
|
371
353
|
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;
|
|
372
354
|
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;
|
|
@@ -408,12 +390,7 @@ var handleDependencies = function() {
|
|
|
408
390
|
pkgDestPath = ".modernjs/".concat(pkgName2, "@").concat(version2, "/node_modules/").concat(pkgName2);
|
|
409
391
|
return [
|
|
410
392
|
4,
|
|
411
|
-
writePackage(
|
|
412
|
-
pkg,
|
|
413
|
-
version: version2,
|
|
414
|
-
projectDir: serverRootDir,
|
|
415
|
-
_pkgPath: pkgDestPath
|
|
416
|
-
})
|
|
393
|
+
writePackage(pkg, version2, serverRootDir, pkgDestPath)
|
|
417
394
|
];
|
|
418
395
|
case 3:
|
|
419
396
|
_state2.sent();
|
|
@@ -521,40 +498,40 @@ var handleDependencies = function() {
|
|
|
521
498
|
});
|
|
522
499
|
};
|
|
523
500
|
_iterator3 = Object.entries(multiVersionPkgs)[Symbol.iterator]();
|
|
524
|
-
_state.label =
|
|
525
|
-
case
|
|
501
|
+
_state.label = 15;
|
|
502
|
+
case 15:
|
|
526
503
|
if (!!(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done))
|
|
527
504
|
return [
|
|
528
505
|
3,
|
|
529
|
-
|
|
506
|
+
18
|
|
530
507
|
];
|
|
531
508
|
return [
|
|
532
509
|
5,
|
|
533
510
|
_ts_values(_loop())
|
|
534
511
|
];
|
|
535
|
-
case
|
|
512
|
+
case 16:
|
|
536
513
|
_state.sent();
|
|
537
|
-
_state.label =
|
|
538
|
-
case
|
|
514
|
+
_state.label = 17;
|
|
515
|
+
case 17:
|
|
539
516
|
_iteratorNormalCompletion3 = true;
|
|
540
517
|
return [
|
|
541
518
|
3,
|
|
542
|
-
|
|
519
|
+
15
|
|
543
520
|
];
|
|
544
|
-
case
|
|
521
|
+
case 18:
|
|
545
522
|
return [
|
|
546
523
|
3,
|
|
547
|
-
|
|
524
|
+
21
|
|
548
525
|
];
|
|
549
|
-
case
|
|
526
|
+
case 19:
|
|
550
527
|
err = _state.sent();
|
|
551
528
|
_didIteratorError3 = true;
|
|
552
529
|
_iteratorError3 = err;
|
|
553
530
|
return [
|
|
554
531
|
3,
|
|
555
|
-
|
|
532
|
+
21
|
|
556
533
|
];
|
|
557
|
-
case
|
|
534
|
+
case 20:
|
|
558
535
|
try {
|
|
559
536
|
if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
|
|
560
537
|
_iterator3.return();
|
|
@@ -567,28 +544,26 @@ var handleDependencies = function() {
|
|
|
567
544
|
return [
|
|
568
545
|
7
|
|
569
546
|
];
|
|
570
|
-
case
|
|
547
|
+
case 21:
|
|
571
548
|
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;
|
|
587
549
|
return [
|
|
588
550
|
4,
|
|
589
|
-
fse.writeJSON(outputPkgPath,
|
|
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
|
+
})
|
|
590
565
|
];
|
|
591
|
-
case
|
|
566
|
+
case 22:
|
|
592
567
|
_state.sent();
|
|
593
568
|
return [
|
|
594
569
|
2
|
|
@@ -596,7 +571,7 @@ var handleDependencies = function() {
|
|
|
596
571
|
}
|
|
597
572
|
});
|
|
598
573
|
});
|
|
599
|
-
return function handleDependencies2(
|
|
574
|
+
return function handleDependencies2(appDir, serverRootDir, include, entryFilter) {
|
|
600
575
|
return _ref.apply(this, arguments);
|
|
601
576
|
};
|
|
602
577
|
}();
|