@modern-js/app-tools 2.63.1 → 2.63.3
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/modern.js +1 -1
- package/dist/cjs/commands/build.js +19 -13
- package/dist/cjs/commands/deploy.js +5 -5
- package/dist/cjs/commands/dev.js +11 -11
- package/dist/cjs/commands/index.js +6 -6
- package/dist/cjs/commands/inspect.js +1 -1
- package/dist/cjs/commands/serve.js +4 -4
- package/dist/cjs/{new/compat → compat}/hooks.js +21 -6
- package/dist/cjs/{new/compat → compat}/index.js +7 -2
- package/dist/cjs/{new/compat → compat}/utils.js +29 -8
- package/dist/cjs/config/default.js +6 -1
- package/dist/cjs/config/legacy/index.js +0 -1
- package/dist/cjs/index.js +154 -5
- package/dist/cjs/plugins/analyze/getServerRoutes.js +12 -2
- package/dist/cjs/plugins/analyze/index.js +25 -10
- package/dist/cjs/plugins/analyze/utils.js +6 -0
- package/dist/cjs/plugins/deploy/platforms/netlify.js +7 -4
- package/dist/cjs/plugins/deploy/platforms/node.js +6 -3
- package/dist/cjs/plugins/deploy/platforms/vercel.js +7 -4
- package/dist/cjs/plugins/serverBuild.js +30 -32
- package/dist/cjs/{new/run.js → run/index.js} +6 -6
- package/dist/cjs/{new → utils}/getConfigFile.js +1 -1
- package/dist/cjs/{new/context.js → utils/initAppContext.js} +3 -3
- package/dist/cjs/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
- package/dist/cjs/utils/loadPlugins.js +35 -4
- package/dist/cjs/utils/printInstructions.js +2 -11
- package/dist/cjs/utils/restart.js +2 -2
- package/dist/esm/commands/build.js +18 -12
- package/dist/esm/commands/deploy.js +6 -6
- package/dist/esm/commands/dev.js +11 -11
- package/dist/esm/commands/index.js +8 -8
- package/dist/esm/commands/inspect.js +1 -1
- package/dist/esm/commands/serve.js +6 -6
- package/dist/esm/{new/compat → compat}/hooks.js +98 -49
- package/dist/esm/{new/compat → compat}/index.js +8 -3
- package/dist/esm/{new/compat → compat}/utils.js +29 -8
- package/dist/esm/config/default.js +12 -1
- package/dist/esm/config/legacy/index.js +0 -1
- package/dist/esm/index.js +245 -2
- package/dist/esm/plugins/analyze/getServerRoutes.js +11 -2
- package/dist/esm/plugins/analyze/index.js +76 -34
- package/dist/esm/plugins/analyze/utils.js +5 -0
- package/dist/esm/plugins/deploy/platforms/netlify.js +6 -3
- package/dist/esm/plugins/deploy/platforms/node.js +5 -2
- package/dist/esm/plugins/deploy/platforms/vercel.js +6 -3
- package/dist/esm/plugins/serverBuild.js +52 -56
- package/dist/esm/{new/run.js → run/index.js} +6 -6
- package/dist/esm/{new → utils}/getConfigFile.js +1 -1
- package/dist/esm/{new/utils/index.js → utils/isAutoLoadPlugins.js} +6 -6
- package/dist/esm/utils/loadPlugins.js +95 -7
- package/dist/esm/utils/printInstructions.js +1 -28
- package/dist/esm/utils/restart.js +3 -3
- package/dist/esm-node/commands/build.js +19 -13
- package/dist/esm-node/commands/deploy.js +5 -5
- package/dist/esm-node/commands/dev.js +12 -12
- package/dist/esm-node/commands/index.js +6 -6
- package/dist/esm-node/commands/inspect.js +1 -1
- package/dist/esm-node/commands/serve.js +5 -5
- package/dist/esm-node/{new/compat → compat}/hooks.js +21 -6
- package/dist/esm-node/{new/compat → compat}/index.js +8 -3
- package/dist/esm-node/{new/compat → compat}/utils.js +29 -8
- package/dist/esm-node/config/default.js +6 -1
- package/dist/esm-node/config/legacy/index.js +0 -1
- package/dist/esm-node/index.js +140 -2
- package/dist/esm-node/plugins/analyze/getServerRoutes.js +11 -2
- package/dist/esm-node/plugins/analyze/index.js +26 -11
- package/dist/esm-node/plugins/analyze/utils.js +5 -0
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +6 -3
- package/dist/esm-node/plugins/deploy/platforms/node.js +5 -2
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +6 -3
- package/dist/esm-node/plugins/serverBuild.js +30 -32
- package/dist/esm-node/{new/run.js → run/index.js} +6 -6
- package/dist/esm-node/{new → utils}/getConfigFile.js +1 -1
- package/dist/esm-node/{new/utils/index.js → utils/isAutoLoadPlugins.js} +2 -2
- package/dist/esm-node/utils/loadPlugins.js +34 -4
- package/dist/esm-node/utils/printInstructions.js +1 -9
- package/dist/esm-node/utils/restart.js +2 -2
- package/dist/types/commands/build.d.ts +2 -2
- package/dist/types/commands/deploy.d.ts +2 -2
- package/dist/types/commands/dev.d.ts +2 -2
- package/dist/types/commands/index.d.ts +6 -6
- package/dist/types/commands/inspect.d.ts +2 -2
- package/dist/types/commands/serve.d.ts +2 -2
- package/dist/types/{new/compat → compat}/hooks.d.ts +2 -2
- package/dist/types/compat/index.d.ts +2 -0
- package/dist/types/{new/compat → compat}/utils.d.ts +8 -1
- package/dist/types/index.d.ts +5 -3
- package/dist/types/plugins/analyze/getServerRoutes.d.ts +1 -0
- package/dist/types/plugins/analyze/utils.d.ts +1 -0
- package/dist/types/plugins/serverBuild.d.ts +2 -2
- package/dist/types/types/config/index.d.ts +0 -1
- package/dist/types/types/index.d.ts +2 -0
- package/dist/types/types/new.d.ts +11 -16
- package/dist/types/utils/generateWatchFiles.d.ts +2 -2
- package/dist/types/utils/isAutoLoadPlugins.d.ts +1 -0
- package/dist/types/utils/loadPlugins.d.ts +13 -3
- package/dist/types/utils/printInstructions.d.ts +1 -3
- package/dist/types/utils/restart.d.ts +2 -3
- package/package.json +24 -28
- package/dist/cjs/hooks.js +0 -60
- package/dist/cjs/new/index.js +0 -79
- package/dist/cjs/new/loadPlugins.js +0 -57
- package/dist/cjs/old.js +0 -179
- package/dist/cjs/plugins/deploy/dependencies/index.js +0 -237
- package/dist/cjs/plugins/deploy/dependencies/utils.js +0 -179
- package/dist/cjs/plugins/deploy/exports.js +0 -28
- package/dist/esm/hooks.js +0 -36
- package/dist/esm/new/index.js +0 -55
- package/dist/esm/new/loadPlugins.js +0 -94
- package/dist/esm/old.js +0 -258
- package/dist/esm/plugins/deploy/dependencies/index.js +0 -615
- package/dist/esm/plugins/deploy/dependencies/utils.js +0 -421
- package/dist/esm/plugins/deploy/exports.js +0 -4
- package/dist/esm-node/hooks.js +0 -36
- package/dist/esm-node/new/index.js +0 -52
- package/dist/esm-node/new/loadPlugins.js +0 -33
- package/dist/esm-node/old.js +0 -140
- package/dist/esm-node/plugins/deploy/dependencies/index.js +0 -202
- package/dist/esm-node/plugins/deploy/dependencies/utils.js +0 -137
- package/dist/esm-node/plugins/deploy/exports.js +0 -4
- package/dist/types/hooks.d.ts +0 -2
- package/dist/types/new/compat/index.d.ts +0 -2
- package/dist/types/new/index.d.ts +0 -6
- package/dist/types/new/loadPlugins.d.ts +0 -9
- package/dist/types/new/utils/index.d.ts +0 -1
- package/dist/types/old.d.ts +0 -13
- package/dist/types/plugins/deploy/dependencies/index.d.ts +0 -20
- package/dist/types/plugins/deploy/dependencies/utils.d.ts +0 -44
- package/dist/types/plugins/deploy/exports.d.ts +0 -1
- /package/dist/cjs/{new/constants.js → constants.js} +0 -0
- /package/dist/esm/{new/constants.js → constants.js} +0 -0
- /package/dist/esm/{new/context.js → utils/initAppContext.js} +0 -0
- /package/dist/esm-node/{new/constants.js → constants.js} +0 -0
- /package/dist/esm-node/{new/context.js → utils/initAppContext.js} +0 -0
- /package/dist/types/{new/constants.d.ts → constants.d.ts} +0 -0
- /package/dist/types/{new/run.d.ts → run/index.d.ts} +0 -0
- /package/dist/types/{new → utils}/getConfigFile.d.ts +0 -0
- /package/dist/types/{new/context.d.ts → utils/initAppContext.d.ts} +0 -0
@@ -1,237 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __create = Object.create;
|
3
|
-
var __defProp = Object.defineProperty;
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
-
var __export = (target, all) => {
|
9
|
-
for (var name in all)
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
-
};
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
-
for (let key of __getOwnPropNames(from))
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
-
}
|
18
|
-
return to;
|
19
|
-
};
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
-
mod
|
27
|
-
));
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
-
var dependencies_exports = {};
|
30
|
-
__export(dependencies_exports, {
|
31
|
-
handleDependencies: () => handleDependencies,
|
32
|
-
nodeFileTrace: () => import_nft.nodeFileTrace
|
33
|
-
});
|
34
|
-
module.exports = __toCommonJS(dependencies_exports);
|
35
|
-
var import_node_path = __toESM(require("node:path"));
|
36
|
-
var import_utils = require("@modern-js/utils");
|
37
|
-
var import_mlly = require("mlly");
|
38
|
-
var import_pkg_types = require("pkg-types");
|
39
|
-
var import_utils2 = require("./utils");
|
40
|
-
var import_nft = require("@vercel/nft");
|
41
|
-
const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = import_utils2.traceFiles, entryFilter, modifyPackageJson, copyWholePackage, traceOptions }) => {
|
42
|
-
const base = "/";
|
43
|
-
const entryFiles = await (0, import_utils2.findEntryFiles)(serverRootDir, entryFilter);
|
44
|
-
const fileTrace = await traceFiles({
|
45
|
-
entryFiles: entryFiles.concat(includeEntries),
|
46
|
-
serverRootDir,
|
47
|
-
base,
|
48
|
-
traceOptions
|
49
|
-
});
|
50
|
-
const currentProjectModules = import_node_path.default.join(appDir, "node_modules");
|
51
|
-
const dependencySearchRoot = import_node_path.default.resolve(appDir, "../../../../../../");
|
52
|
-
const tracedFiles = Object.fromEntries(await Promise.all([
|
53
|
-
...fileTrace.reasons.entries()
|
54
|
-
].map(async ([_path, reasons]) => {
|
55
|
-
if (reasons.ignored) {
|
56
|
-
return;
|
57
|
-
}
|
58
|
-
const filePath = await (0, import_utils2.resolveTracedPath)(base, _path);
|
59
|
-
if ((0, import_utils2.isSubPath)(serverRootDir, filePath) || (0, import_utils2.isSubPath)(appDir, filePath) && !(0, import_utils2.isSubPath)(currentProjectModules, filePath)) {
|
60
|
-
return;
|
61
|
-
}
|
62
|
-
if (!await (0, import_utils2.isFile)(filePath)) {
|
63
|
-
return;
|
64
|
-
}
|
65
|
-
let baseDir;
|
66
|
-
let pkgName;
|
67
|
-
let subpath;
|
68
|
-
let pkgPath;
|
69
|
-
if (filePath.includes("node_modules")) {
|
70
|
-
const parsed = (0, import_mlly.parseNodeModulePath)(filePath);
|
71
|
-
baseDir = parsed.dir;
|
72
|
-
pkgName = parsed.name;
|
73
|
-
subpath = parsed.subpath;
|
74
|
-
pkgPath = import_node_path.default.join(baseDir, pkgName);
|
75
|
-
} else {
|
76
|
-
const MODERN_UTILS_PATH = "packages/toolkit/utils";
|
77
|
-
const MODERN_UTILS_PATH_REGEX = new RegExp(`(.*${MODERN_UTILS_PATH})`);
|
78
|
-
const match = filePath.match(MODERN_UTILS_PATH_REGEX);
|
79
|
-
const packageJsonPath = match ? import_node_path.default.join(match[0], "package.json") : await (0, import_utils.pkgUp)({
|
80
|
-
cwd: import_node_path.default.dirname(filePath)
|
81
|
-
});
|
82
|
-
if (packageJsonPath && (0, import_utils2.isSubPath)(dependencySearchRoot, packageJsonPath)) {
|
83
|
-
const packageJson = await import_utils.fs.readJSON(packageJsonPath);
|
84
|
-
pkgPath = baseDir = import_node_path.default.dirname(packageJsonPath);
|
85
|
-
subpath = import_node_path.default.relative(baseDir, filePath);
|
86
|
-
pkgName = packageJson.name;
|
87
|
-
}
|
88
|
-
}
|
89
|
-
if (!baseDir) {
|
90
|
-
return;
|
91
|
-
}
|
92
|
-
const parents = await Promise.all([
|
93
|
-
...reasons.parents
|
94
|
-
].map((p) => (0, import_utils2.resolveTracedPath)(base, p)));
|
95
|
-
const tracedFile = {
|
96
|
-
path: filePath,
|
97
|
-
parents,
|
98
|
-
isDirectDep: parents.some((parent) => {
|
99
|
-
return (0, import_utils2.isSubPath)(appDir, parent) && !(0, import_utils2.isSubPath)(currentProjectModules, parent);
|
100
|
-
}),
|
101
|
-
subpath,
|
102
|
-
pkgName,
|
103
|
-
pkgPath
|
104
|
-
};
|
105
|
-
return [
|
106
|
-
filePath,
|
107
|
-
tracedFile
|
108
|
-
];
|
109
|
-
})).then((r) => r.filter(Boolean)));
|
110
|
-
const tracedPackages = {};
|
111
|
-
for (const tracedFile of Object.values(tracedFiles)) {
|
112
|
-
const { pkgName } = tracedFile;
|
113
|
-
let tracedPackage = tracedPackages[pkgName];
|
114
|
-
let pkgJSON = await (0, import_pkg_types.readPackageJSON)(tracedFile.pkgPath, {
|
115
|
-
cache: true
|
116
|
-
}).catch(() => {
|
117
|
-
});
|
118
|
-
if (!pkgJSON) {
|
119
|
-
pkgJSON = {
|
120
|
-
name: pkgName,
|
121
|
-
version: "0.0.0"
|
122
|
-
};
|
123
|
-
}
|
124
|
-
if (!tracedPackage) {
|
125
|
-
tracedPackage = {
|
126
|
-
name: pkgName,
|
127
|
-
versions: {}
|
128
|
-
};
|
129
|
-
tracedPackages[pkgName] = tracedPackage;
|
130
|
-
}
|
131
|
-
let tracedPackageVersion = tracedPackage.versions[pkgJSON.version];
|
132
|
-
if (!tracedPackageVersion) {
|
133
|
-
tracedPackageVersion = {
|
134
|
-
path: tracedFile.pkgPath,
|
135
|
-
files: [],
|
136
|
-
isDirectDep: false,
|
137
|
-
pkgJSON
|
138
|
-
};
|
139
|
-
if (tracedFile.isDirectDep) {
|
140
|
-
tracedPackageVersion.isDirectDep = tracedFile.isDirectDep;
|
141
|
-
}
|
142
|
-
tracedPackage.versions[pkgJSON.version] = tracedPackageVersion;
|
143
|
-
}
|
144
|
-
tracedFile.pkgName = pkgName;
|
145
|
-
tracedFile.pkgVersion = pkgJSON.version;
|
146
|
-
const shouldCopyWholePackage = copyWholePackage === null || copyWholePackage === void 0 ? void 0 : copyWholePackage(pkgName);
|
147
|
-
if (tracedFile.path.startsWith(tracedFile.pkgPath) && // Merged package files are based on the version, not on paths, to handle some boundary cases
|
148
|
-
tracedPackageVersion.pkgJSON.version === tracedFile.pkgVersion) {
|
149
|
-
if (shouldCopyWholePackage) {
|
150
|
-
const allFiles = await (0, import_utils2.readDirRecursive)(tracedFile.pkgPath);
|
151
|
-
tracedPackageVersion.files.push(...allFiles);
|
152
|
-
} else {
|
153
|
-
tracedPackageVersion.files.push(tracedFile.path);
|
154
|
-
}
|
155
|
-
}
|
156
|
-
}
|
157
|
-
const multiVersionPkgs = {};
|
158
|
-
const singleVersionPackages = [];
|
159
|
-
for (const tracedPackage of Object.values(tracedPackages)) {
|
160
|
-
const versions = Object.keys(tracedPackage.versions);
|
161
|
-
if (versions.length === 1) {
|
162
|
-
singleVersionPackages.push(tracedPackage.name);
|
163
|
-
continue;
|
164
|
-
}
|
165
|
-
multiVersionPkgs[tracedPackage.name] = {};
|
166
|
-
for (const version of versions) {
|
167
|
-
multiVersionPkgs[tracedPackage.name][version] = (0, import_utils2.findPackageParents)(tracedPackage, version, tracedFiles);
|
168
|
-
}
|
169
|
-
}
|
170
|
-
await Promise.all(singleVersionPackages.map((pkgName) => {
|
171
|
-
const pkg = tracedPackages[pkgName];
|
172
|
-
const version = Object.keys(pkg.versions)[0];
|
173
|
-
return (0, import_utils2.writePackage)({
|
174
|
-
pkg,
|
175
|
-
version,
|
176
|
-
projectDir: serverRootDir
|
177
|
-
});
|
178
|
-
}));
|
179
|
-
const projectPkgJson = await (0, import_pkg_types.readPackageJSON)(serverRootDir).catch(() => ({}));
|
180
|
-
for (const [pkgName, pkgVersions] of Object.entries(multiVersionPkgs)) {
|
181
|
-
const versionEntires = Object.entries(pkgVersions).sort(([v1, p1], [v2, p2]) => {
|
182
|
-
var _tracedPackages_pkgName_versions_v1, _tracedPackages_pkgName_versions, _tracedPackages_pkgName, _tracedPackages_pkgName_versions_v2, _tracedPackages_pkgName_versions1, _tracedPackages_pkgName1;
|
183
|
-
const shouldHoist1 = (_tracedPackages_pkgName = tracedPackages[pkgName]) === 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;
|
184
|
-
const shouldHoist2 = (_tracedPackages_pkgName1 = tracedPackages[pkgName]) === 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;
|
185
|
-
if (shouldHoist1 && !shouldHoist2) {
|
186
|
-
return -1;
|
187
|
-
}
|
188
|
-
if (!shouldHoist1 && shouldHoist2) {
|
189
|
-
return 1;
|
190
|
-
}
|
191
|
-
if (p1.length === 0) {
|
192
|
-
return -1;
|
193
|
-
}
|
194
|
-
if (p2.length === 0) {
|
195
|
-
return 1;
|
196
|
-
}
|
197
|
-
return import_utils.semver.lt(v1, v2, {
|
198
|
-
loose: true
|
199
|
-
}) ? 1 : -1;
|
200
|
-
});
|
201
|
-
for (const [version, parentPkgs] of versionEntires) {
|
202
|
-
const pkg = tracedPackages[pkgName];
|
203
|
-
const pkgDestPath = `.modernjs/${pkgName}@${version}/node_modules/${pkgName}`;
|
204
|
-
await (0, import_utils2.writePackage)({
|
205
|
-
pkg,
|
206
|
-
version,
|
207
|
-
projectDir: serverRootDir,
|
208
|
-
_pkgPath: pkgDestPath
|
209
|
-
});
|
210
|
-
await (0, import_utils2.linkPackage)(pkgDestPath, `${pkgName}`, serverRootDir);
|
211
|
-
for (const parentPkg of parentPkgs) {
|
212
|
-
const parentPkgName = parentPkg.replace(/@[^@]+$/, "");
|
213
|
-
await (multiVersionPkgs[parentPkgName] ? (0, import_utils2.linkPackage)(pkgDestPath, `.modernjs/${parentPkg}/node_modules/${pkgName}`, serverRootDir) : (0, import_utils2.linkPackage)(pkgDestPath, `${parentPkgName}/node_modules/${pkgName}`, serverRootDir));
|
214
|
-
}
|
215
|
-
}
|
216
|
-
}
|
217
|
-
const outputPkgPath = import_node_path.default.join(serverRootDir, "package.json");
|
218
|
-
const newPkgJson = {
|
219
|
-
name: `${projectPkgJson.name || "modernjs-project"}-prod`,
|
220
|
-
version: projectPkgJson.version || "0.0.0",
|
221
|
-
private: true,
|
222
|
-
type: projectPkgJson.type || "commonjs",
|
223
|
-
dependencies: Object.fromEntries([
|
224
|
-
...Object.values(tracedPackages).map((pkg) => [
|
225
|
-
pkg.name,
|
226
|
-
Object.keys(pkg.versions)[0]
|
227
|
-
])
|
228
|
-
].sort(([a], [b]) => a.localeCompare(b)))
|
229
|
-
};
|
230
|
-
const finalPkgJson = (modifyPackageJson === null || modifyPackageJson === void 0 ? void 0 : modifyPackageJson(newPkgJson)) || newPkgJson;
|
231
|
-
await import_utils.fs.writeJSON(outputPkgPath, finalPkgJson);
|
232
|
-
};
|
233
|
-
// Annotate the CommonJS export names for ESM import in node:
|
234
|
-
0 && (module.exports = {
|
235
|
-
handleDependencies,
|
236
|
-
nodeFileTrace
|
237
|
-
});
|
@@ -1,179 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __create = Object.create;
|
3
|
-
var __defProp = Object.defineProperty;
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
-
var __export = (target, all) => {
|
9
|
-
for (var name in all)
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
-
};
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
-
for (let key of __getOwnPropNames(from))
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
-
}
|
18
|
-
return to;
|
19
|
-
};
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
-
mod
|
27
|
-
));
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
-
var utils_exports = {};
|
30
|
-
__export(utils_exports, {
|
31
|
-
findEntryFiles: () => findEntryFiles,
|
32
|
-
findPackageParents: () => findPackageParents,
|
33
|
-
isFile: () => isFile,
|
34
|
-
isSubPath: () => isSubPath,
|
35
|
-
linkPackage: () => linkPackage,
|
36
|
-
readDirRecursive: () => readDirRecursive,
|
37
|
-
resolveTracedPath: () => resolveTracedPath,
|
38
|
-
traceFiles: () => traceFiles,
|
39
|
-
writePackage: () => writePackage
|
40
|
-
});
|
41
|
-
module.exports = __toCommonJS(utils_exports);
|
42
|
-
var import_node_os = __toESM(require("node:os"));
|
43
|
-
var import_path = __toESM(require("path"));
|
44
|
-
var import_utils = require("@modern-js/utils");
|
45
|
-
var import_nft = require("@vercel/nft");
|
46
|
-
var import_mlly = require("mlly");
|
47
|
-
function applyPublicCondition(pkg) {
|
48
|
-
var _pkg_publishConfig;
|
49
|
-
if (pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig = pkg.publishConfig) === null || _pkg_publishConfig === void 0 ? void 0 : _pkg_publishConfig.exports) {
|
50
|
-
var _pkg_publishConfig1;
|
51
|
-
pkg.exports = pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig1 = pkg.publishConfig) === null || _pkg_publishConfig1 === void 0 ? void 0 : _pkg_publishConfig1.exports;
|
52
|
-
}
|
53
|
-
}
|
54
|
-
const writePackage = async (options) => {
|
55
|
-
const { pkg, version, projectDir, _pkgPath } = options;
|
56
|
-
const pkgPath = _pkgPath || pkg.name;
|
57
|
-
for (const src of pkg.versions[version].files) {
|
58
|
-
if (src.includes("node_modules")) {
|
59
|
-
const { subpath } = (0, import_mlly.parseNodeModulePath)(src);
|
60
|
-
const dest = import_path.default.join(projectDir, "node_modules", pkgPath, subpath);
|
61
|
-
const dirname = import_path.default.dirname(dest);
|
62
|
-
await import_utils.fs.ensureDir(dirname);
|
63
|
-
await import_utils.fs.copyFile(src, dest);
|
64
|
-
} else {
|
65
|
-
const subpath = import_path.default.relative(pkg.versions[version].path, src);
|
66
|
-
const dest = import_path.default.join(projectDir, "node_modules", pkgPath, subpath);
|
67
|
-
const dirname = import_path.default.dirname(dest);
|
68
|
-
await import_utils.fs.ensureDir(dirname);
|
69
|
-
await import_utils.fs.copyFile(src, dest);
|
70
|
-
}
|
71
|
-
}
|
72
|
-
const { pkgJSON } = pkg.versions[version];
|
73
|
-
applyPublicCondition(pkgJSON);
|
74
|
-
const packageJsonPath = import_path.default.join(projectDir, "node_modules", pkgPath, "package.json");
|
75
|
-
await import_utils.fs.ensureDir(import_path.default.dirname(packageJsonPath));
|
76
|
-
await import_utils.fs.writeFile(packageJsonPath, JSON.stringify(pkgJSON, null, 2));
|
77
|
-
};
|
78
|
-
const isWindows = import_node_os.default.platform() === "win32";
|
79
|
-
const linkPackage = async (from, to, projectRootDir) => {
|
80
|
-
const src = import_path.default.join(projectRootDir, "node_modules", from);
|
81
|
-
const dest = import_path.default.join(projectRootDir, "node_modules", to);
|
82
|
-
const dstStat = await import_utils.fs.lstat(dest).catch(() => null);
|
83
|
-
const exists = dstStat === null || dstStat === void 0 ? void 0 : dstStat.isSymbolicLink();
|
84
|
-
if (exists) {
|
85
|
-
return;
|
86
|
-
}
|
87
|
-
await import_utils.fs.mkdir(import_path.default.dirname(dest), {
|
88
|
-
recursive: true
|
89
|
-
});
|
90
|
-
await import_utils.fs.symlink(import_path.default.relative(import_path.default.dirname(dest), src), dest, isWindows ? "junction" : "dir").catch((error) => {
|
91
|
-
console.error("Cannot link", from, "to", to, error);
|
92
|
-
});
|
93
|
-
};
|
94
|
-
const readDirRecursive = async (dir, options = {}) => {
|
95
|
-
const { filter } = options;
|
96
|
-
const files = await import_utils.fs.readdir(dir, {
|
97
|
-
withFileTypes: true
|
98
|
-
});
|
99
|
-
const filesAndDirs = await Promise.all(files.map(async (file) => {
|
100
|
-
const resolvedPath = import_path.default.resolve(dir, file.name);
|
101
|
-
if (file.isDirectory()) {
|
102
|
-
return readDirRecursive(resolvedPath, options);
|
103
|
-
} else {
|
104
|
-
return filter && !filter(resolvedPath) ? [] : resolvedPath;
|
105
|
-
}
|
106
|
-
}));
|
107
|
-
return filesAndDirs.flat();
|
108
|
-
};
|
109
|
-
const isFile = async (file) => {
|
110
|
-
try {
|
111
|
-
const stat = await import_utils.fs.stat(file);
|
112
|
-
return stat.isFile();
|
113
|
-
} catch (error) {
|
114
|
-
if (error.code === "ENOENT") {
|
115
|
-
return false;
|
116
|
-
}
|
117
|
-
throw error;
|
118
|
-
}
|
119
|
-
};
|
120
|
-
const findEntryFiles = async (rootDir, entryFilter) => {
|
121
|
-
const files = await readDirRecursive(rootDir, {
|
122
|
-
filter: entryFilter
|
123
|
-
});
|
124
|
-
return files.filter((file) => file.endsWith(".mjs") || file.endsWith(".cjs") || file.endsWith(".js"));
|
125
|
-
};
|
126
|
-
const findPackageParents = (pkg, version, tracedFiles) => {
|
127
|
-
const versionFiles = pkg.versions[version].files.map((path2) => tracedFiles[path2]);
|
128
|
-
const parentPkgs = [
|
129
|
-
...new Set(versionFiles.flatMap((file) => (
|
130
|
-
// Because it supports copyWholePackage configuration, not all files exist.
|
131
|
-
file === null || file === void 0 ? void 0 : file.parents.map((parentPath) => {
|
132
|
-
const parentFile = tracedFiles[parentPath];
|
133
|
-
if (!parentFile || parentFile.pkgName === pkg.name) {
|
134
|
-
return null;
|
135
|
-
}
|
136
|
-
return `${parentFile.pkgName}@${parentFile.pkgVersion}`;
|
137
|
-
}).filter(Boolean)
|
138
|
-
)))
|
139
|
-
];
|
140
|
-
return parentPkgs.filter((parentPkg) => parentPkg);
|
141
|
-
};
|
142
|
-
const traceFiles = async ({ entryFiles, serverRootDir, base = "/", traceOptions }) => {
|
143
|
-
return await (0, import_nft.nodeFileTrace)(entryFiles, {
|
144
|
-
base,
|
145
|
-
processCwd: serverRootDir,
|
146
|
-
resolve: async (id, parent, job, isCjs) => {
|
147
|
-
if (id.startsWith("@modern-js/prod-server")) {
|
148
|
-
return require.resolve(id, {
|
149
|
-
paths: [
|
150
|
-
require.resolve("@modern-js/app-tools")
|
151
|
-
]
|
152
|
-
});
|
153
|
-
} else {
|
154
|
-
return (0, import_nft.resolve)(id, parent, job, isCjs);
|
155
|
-
}
|
156
|
-
},
|
157
|
-
...traceOptions
|
158
|
-
});
|
159
|
-
};
|
160
|
-
const resolveTracedPath = async (base, p) => import_utils.fs.realpath(import_path.default.resolve(base, p));
|
161
|
-
const isSubPath = (parentPath, childPath) => {
|
162
|
-
if (!parentPath || !childPath) {
|
163
|
-
return false;
|
164
|
-
}
|
165
|
-
const relative = import_path.default.relative(parentPath, childPath);
|
166
|
-
return relative && !relative.startsWith("..");
|
167
|
-
};
|
168
|
-
// Annotate the CommonJS export names for ESM import in node:
|
169
|
-
0 && (module.exports = {
|
170
|
-
findEntryFiles,
|
171
|
-
findPackageParents,
|
172
|
-
isFile,
|
173
|
-
isSubPath,
|
174
|
-
linkPackage,
|
175
|
-
readDirRecursive,
|
176
|
-
resolveTracedPath,
|
177
|
-
traceFiles,
|
178
|
-
writePackage
|
179
|
-
});
|
@@ -1,28 +0,0 @@
|
|
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
|
-
});
|
package/dist/esm/hooks.js
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
import { createAsyncWaterfall, createAsyncWorkflow, createParallelWorkflow } from "@modern-js/plugin";
|
2
|
-
var hooks = {
|
3
|
-
_internalRuntimePlugins: createAsyncWaterfall(),
|
4
|
-
modifyFileSystemRoutes: createAsyncWaterfall(),
|
5
|
-
modifyServerRoutes: createAsyncWaterfall(),
|
6
|
-
/** add entry point info to entrypoints array */
|
7
|
-
modifyEntrypoints: createAsyncWaterfall(),
|
8
|
-
/** add entry type */
|
9
|
-
checkEntryPoint: createAsyncWaterfall(),
|
10
|
-
generateEntryCode: createAsyncWorkflow(),
|
11
|
-
htmlPartials: createAsyncWaterfall(),
|
12
|
-
beforeGenerateRoutes: createAsyncWaterfall(),
|
13
|
-
_internalServerPlugins: createAsyncWaterfall(),
|
14
|
-
beforeDev: createAsyncWorkflow(),
|
15
|
-
afterDev: createAsyncWorkflow(),
|
16
|
-
beforeCreateCompiler: createAsyncWorkflow(),
|
17
|
-
afterCreateCompiler: createAsyncWorkflow(),
|
18
|
-
beforePrintInstructions: createAsyncWaterfall(),
|
19
|
-
beforeBuild: createAsyncWorkflow(),
|
20
|
-
afterBuild: createAsyncWorkflow(),
|
21
|
-
beforeDeploy: createAsyncWorkflow(),
|
22
|
-
deploy: createAsyncWorkflow(),
|
23
|
-
afterDeploy: createAsyncWorkflow(),
|
24
|
-
beforeRestart: createAsyncWorkflow(),
|
25
|
-
/**
|
26
|
-
* @deprecated
|
27
|
-
*/
|
28
|
-
registerDev: createParallelWorkflow(),
|
29
|
-
/**
|
30
|
-
* @deprecated
|
31
|
-
*/
|
32
|
-
registerBuildPlatform: createParallelWorkflow()
|
33
|
-
};
|
34
|
-
export {
|
35
|
-
hooks
|
36
|
-
};
|
package/dist/esm/new/index.js
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
import { createAsyncHook } from "@modern-js/plugin-v2";
|
2
|
-
import { appTools as oldAppTools } from "../old";
|
3
|
-
import { compatPlugin } from "./compat";
|
4
|
-
import { DEFAULT_RUNTIME_CONFIG_FILE, DEFAULT_SERVER_CONFIG_FILE } from "./constants";
|
5
|
-
import { initAppContext } from "./context";
|
6
|
-
export * from "../defineConfig";
|
7
|
-
var appTools = function() {
|
8
|
-
var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
|
9
|
-
// default webpack to be compatible with original projects
|
10
|
-
bundler: "webpack"
|
11
|
-
};
|
12
|
-
return {
|
13
|
-
name: "@modern-js/app-tools",
|
14
|
-
usePlugins: [
|
15
|
-
compatPlugin(),
|
16
|
-
oldAppTools(options)
|
17
|
-
],
|
18
|
-
post: [
|
19
|
-
"@modern-js/app-tools-old"
|
20
|
-
],
|
21
|
-
registryHooks: {
|
22
|
-
onBeforeConfig: createAsyncHook(),
|
23
|
-
onAfterPrepare: createAsyncHook(),
|
24
|
-
deploy: createAsyncHook(),
|
25
|
-
_internalRuntimePlugins: createAsyncHook(),
|
26
|
-
_internalServerPlugins: createAsyncHook(),
|
27
|
-
checkEntryPoint: createAsyncHook(),
|
28
|
-
modifyEntrypoints: createAsyncHook(),
|
29
|
-
modifyFileSystemRoutes: createAsyncHook(),
|
30
|
-
modifyServerRoutes: createAsyncHook(),
|
31
|
-
generateEntryCode: createAsyncHook(),
|
32
|
-
onBeforeGenerateRoutes: createAsyncHook(),
|
33
|
-
onBeforePrintInstructions: createAsyncHook(),
|
34
|
-
registerDev: createAsyncHook(),
|
35
|
-
registerBuildPlatform: createAsyncHook(),
|
36
|
-
addRuntimeExports: createAsyncHook()
|
37
|
-
},
|
38
|
-
setup: function(api) {
|
39
|
-
var _userConfig_output;
|
40
|
-
var context = api.getAppContext();
|
41
|
-
var userConfig = api.getConfig();
|
42
|
-
api.updateAppContext(initAppContext({
|
43
|
-
appDirectory: context.appDirectory,
|
44
|
-
options: {},
|
45
|
-
serverConfigFile: DEFAULT_SERVER_CONFIG_FILE,
|
46
|
-
runtimeConfigFile: DEFAULT_RUNTIME_CONFIG_FILE,
|
47
|
-
tempDir: (_userConfig_output = userConfig.output) === null || _userConfig_output === void 0 ? void 0 : _userConfig_output.tempDir
|
48
|
-
}));
|
49
|
-
}
|
50
|
-
};
|
51
|
-
};
|
52
|
-
export {
|
53
|
-
appTools,
|
54
|
-
initAppContext
|
55
|
-
};
|
@@ -1,94 +0,0 @@
|
|
1
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
-
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
3
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
4
|
-
import { compatibleRequire, createDebugger, dynamicImport, getInternalPlugins, tryResolve } from "@modern-js/utils";
|
5
|
-
var debug = createDebugger("load-plugins");
|
6
|
-
var resolveCliPlugin = function() {
|
7
|
-
var _ref = _async_to_generator(function(p, appDirectory) {
|
8
|
-
var pkg, pluginOptions, path, module, e, ref, result;
|
9
|
-
return _ts_generator(this, function(_state) {
|
10
|
-
switch (_state.label) {
|
11
|
-
case 0:
|
12
|
-
pkg = typeof p === "string" ? p : p[0];
|
13
|
-
pluginOptions = typeof p === "string" ? void 0 : p[1];
|
14
|
-
path = tryResolve(pkg, appDirectory);
|
15
|
-
_state.label = 1;
|
16
|
-
case 1:
|
17
|
-
_state.trys.push([
|
18
|
-
1,
|
19
|
-
3,
|
20
|
-
,
|
21
|
-
5
|
22
|
-
]);
|
23
|
-
return [
|
24
|
-
4,
|
25
|
-
compatibleRequire(path)
|
26
|
-
];
|
27
|
-
case 2:
|
28
|
-
module = _state.sent();
|
29
|
-
return [
|
30
|
-
3,
|
31
|
-
5
|
32
|
-
];
|
33
|
-
case 3:
|
34
|
-
e = _state.sent();
|
35
|
-
return [
|
36
|
-
4,
|
37
|
-
dynamicImport(path)
|
38
|
-
];
|
39
|
-
case 4:
|
40
|
-
ref = _state.sent(), module = ref.default, ref;
|
41
|
-
return [
|
42
|
-
3,
|
43
|
-
5
|
44
|
-
];
|
45
|
-
case 5:
|
46
|
-
if (typeof module === "function") {
|
47
|
-
result = module(pluginOptions);
|
48
|
-
return [
|
49
|
-
2,
|
50
|
-
result
|
51
|
-
];
|
52
|
-
}
|
53
|
-
return [
|
54
|
-
2,
|
55
|
-
module
|
56
|
-
];
|
57
|
-
}
|
58
|
-
});
|
59
|
-
});
|
60
|
-
return function resolveCliPlugin2(p, appDirectory) {
|
61
|
-
return _ref.apply(this, arguments);
|
62
|
-
};
|
63
|
-
}();
|
64
|
-
var loadInternalPlugins = function() {
|
65
|
-
var _ref = _async_to_generator(function(appDirectory, internalPlugins, autoLoad, autoLoadPlugins) {
|
66
|
-
var plugins, loadedPlugins;
|
67
|
-
return _ts_generator(this, function(_state) {
|
68
|
-
switch (_state.label) {
|
69
|
-
case 0:
|
70
|
-
plugins = _to_consumable_array(autoLoadPlugins ? getInternalPlugins(appDirectory, internalPlugins) : []).concat(_to_consumable_array(autoLoad ? getInternalPlugins(appDirectory, autoLoad) : []));
|
71
|
-
return [
|
72
|
-
4,
|
73
|
-
Promise.all(plugins.map(function(plugin) {
|
74
|
-
var loadedPlugin = resolveCliPlugin(plugin, appDirectory);
|
75
|
-
debug("resolve plugin %s: %s", plugin, loadedPlugin);
|
76
|
-
return loadedPlugin;
|
77
|
-
}))
|
78
|
-
];
|
79
|
-
case 1:
|
80
|
-
loadedPlugins = _state.sent();
|
81
|
-
return [
|
82
|
-
2,
|
83
|
-
loadedPlugins
|
84
|
-
];
|
85
|
-
}
|
86
|
-
});
|
87
|
-
});
|
88
|
-
return function loadInternalPlugins2(appDirectory, internalPlugins, autoLoad, autoLoadPlugins) {
|
89
|
-
return _ref.apply(this, arguments);
|
90
|
-
};
|
91
|
-
}();
|
92
|
-
export {
|
93
|
-
loadInternalPlugins
|
94
|
-
};
|