@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,202 +0,0 @@
|
|
1
|
-
import path from "node:path";
|
2
|
-
import { fs as fse, pkgUp, semver } from "@modern-js/utils";
|
3
|
-
import { parseNodeModulePath } from "mlly";
|
4
|
-
import { readPackageJSON } from "pkg-types";
|
5
|
-
import { traceFiles as defaultTraceFiles, findEntryFiles, findPackageParents, isFile, isSubPath, linkPackage, readDirRecursive, resolveTracedPath, writePackage } from "./utils";
|
6
|
-
import { nodeFileTrace } from "@vercel/nft";
|
7
|
-
const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = defaultTraceFiles, entryFilter, modifyPackageJson, copyWholePackage, traceOptions }) => {
|
8
|
-
const base = "/";
|
9
|
-
const entryFiles = await findEntryFiles(serverRootDir, entryFilter);
|
10
|
-
const fileTrace = await traceFiles({
|
11
|
-
entryFiles: entryFiles.concat(includeEntries),
|
12
|
-
serverRootDir,
|
13
|
-
base,
|
14
|
-
traceOptions
|
15
|
-
});
|
16
|
-
const currentProjectModules = path.join(appDir, "node_modules");
|
17
|
-
const dependencySearchRoot = path.resolve(appDir, "../../../../../../");
|
18
|
-
const tracedFiles = Object.fromEntries(await Promise.all([
|
19
|
-
...fileTrace.reasons.entries()
|
20
|
-
].map(async ([_path, reasons]) => {
|
21
|
-
if (reasons.ignored) {
|
22
|
-
return;
|
23
|
-
}
|
24
|
-
const filePath = await resolveTracedPath(base, _path);
|
25
|
-
if (isSubPath(serverRootDir, filePath) || isSubPath(appDir, filePath) && !isSubPath(currentProjectModules, filePath)) {
|
26
|
-
return;
|
27
|
-
}
|
28
|
-
if (!await isFile(filePath)) {
|
29
|
-
return;
|
30
|
-
}
|
31
|
-
let baseDir;
|
32
|
-
let pkgName;
|
33
|
-
let subpath;
|
34
|
-
let pkgPath;
|
35
|
-
if (filePath.includes("node_modules")) {
|
36
|
-
const parsed = parseNodeModulePath(filePath);
|
37
|
-
baseDir = parsed.dir;
|
38
|
-
pkgName = parsed.name;
|
39
|
-
subpath = parsed.subpath;
|
40
|
-
pkgPath = path.join(baseDir, pkgName);
|
41
|
-
} else {
|
42
|
-
const MODERN_UTILS_PATH = "packages/toolkit/utils";
|
43
|
-
const MODERN_UTILS_PATH_REGEX = new RegExp(`(.*${MODERN_UTILS_PATH})`);
|
44
|
-
const match = filePath.match(MODERN_UTILS_PATH_REGEX);
|
45
|
-
const packageJsonPath = match ? path.join(match[0], "package.json") : await pkgUp({
|
46
|
-
cwd: path.dirname(filePath)
|
47
|
-
});
|
48
|
-
if (packageJsonPath && isSubPath(dependencySearchRoot, packageJsonPath)) {
|
49
|
-
const packageJson = await fse.readJSON(packageJsonPath);
|
50
|
-
pkgPath = baseDir = path.dirname(packageJsonPath);
|
51
|
-
subpath = path.relative(baseDir, filePath);
|
52
|
-
pkgName = packageJson.name;
|
53
|
-
}
|
54
|
-
}
|
55
|
-
if (!baseDir) {
|
56
|
-
return;
|
57
|
-
}
|
58
|
-
const parents = await Promise.all([
|
59
|
-
...reasons.parents
|
60
|
-
].map((p) => resolveTracedPath(base, p)));
|
61
|
-
const tracedFile = {
|
62
|
-
path: filePath,
|
63
|
-
parents,
|
64
|
-
isDirectDep: parents.some((parent) => {
|
65
|
-
return isSubPath(appDir, parent) && !isSubPath(currentProjectModules, parent);
|
66
|
-
}),
|
67
|
-
subpath,
|
68
|
-
pkgName,
|
69
|
-
pkgPath
|
70
|
-
};
|
71
|
-
return [
|
72
|
-
filePath,
|
73
|
-
tracedFile
|
74
|
-
];
|
75
|
-
})).then((r) => r.filter(Boolean)));
|
76
|
-
const tracedPackages = {};
|
77
|
-
for (const tracedFile of Object.values(tracedFiles)) {
|
78
|
-
const { pkgName } = tracedFile;
|
79
|
-
let tracedPackage = tracedPackages[pkgName];
|
80
|
-
let pkgJSON = await readPackageJSON(tracedFile.pkgPath, {
|
81
|
-
cache: true
|
82
|
-
}).catch(() => {
|
83
|
-
});
|
84
|
-
if (!pkgJSON) {
|
85
|
-
pkgJSON = {
|
86
|
-
name: pkgName,
|
87
|
-
version: "0.0.0"
|
88
|
-
};
|
89
|
-
}
|
90
|
-
if (!tracedPackage) {
|
91
|
-
tracedPackage = {
|
92
|
-
name: pkgName,
|
93
|
-
versions: {}
|
94
|
-
};
|
95
|
-
tracedPackages[pkgName] = tracedPackage;
|
96
|
-
}
|
97
|
-
let tracedPackageVersion = tracedPackage.versions[pkgJSON.version];
|
98
|
-
if (!tracedPackageVersion) {
|
99
|
-
tracedPackageVersion = {
|
100
|
-
path: tracedFile.pkgPath,
|
101
|
-
files: [],
|
102
|
-
isDirectDep: false,
|
103
|
-
pkgJSON
|
104
|
-
};
|
105
|
-
if (tracedFile.isDirectDep) {
|
106
|
-
tracedPackageVersion.isDirectDep = tracedFile.isDirectDep;
|
107
|
-
}
|
108
|
-
tracedPackage.versions[pkgJSON.version] = tracedPackageVersion;
|
109
|
-
}
|
110
|
-
tracedFile.pkgName = pkgName;
|
111
|
-
tracedFile.pkgVersion = pkgJSON.version;
|
112
|
-
const shouldCopyWholePackage = copyWholePackage === null || copyWholePackage === void 0 ? void 0 : copyWholePackage(pkgName);
|
113
|
-
if (tracedFile.path.startsWith(tracedFile.pkgPath) && // Merged package files are based on the version, not on paths, to handle some boundary cases
|
114
|
-
tracedPackageVersion.pkgJSON.version === tracedFile.pkgVersion) {
|
115
|
-
if (shouldCopyWholePackage) {
|
116
|
-
const allFiles = await readDirRecursive(tracedFile.pkgPath);
|
117
|
-
tracedPackageVersion.files.push(...allFiles);
|
118
|
-
} else {
|
119
|
-
tracedPackageVersion.files.push(tracedFile.path);
|
120
|
-
}
|
121
|
-
}
|
122
|
-
}
|
123
|
-
const multiVersionPkgs = {};
|
124
|
-
const singleVersionPackages = [];
|
125
|
-
for (const tracedPackage of Object.values(tracedPackages)) {
|
126
|
-
const versions = Object.keys(tracedPackage.versions);
|
127
|
-
if (versions.length === 1) {
|
128
|
-
singleVersionPackages.push(tracedPackage.name);
|
129
|
-
continue;
|
130
|
-
}
|
131
|
-
multiVersionPkgs[tracedPackage.name] = {};
|
132
|
-
for (const version of versions) {
|
133
|
-
multiVersionPkgs[tracedPackage.name][version] = findPackageParents(tracedPackage, version, tracedFiles);
|
134
|
-
}
|
135
|
-
}
|
136
|
-
await Promise.all(singleVersionPackages.map((pkgName) => {
|
137
|
-
const pkg = tracedPackages[pkgName];
|
138
|
-
const version = Object.keys(pkg.versions)[0];
|
139
|
-
return writePackage({
|
140
|
-
pkg,
|
141
|
-
version,
|
142
|
-
projectDir: serverRootDir
|
143
|
-
});
|
144
|
-
}));
|
145
|
-
const projectPkgJson = await readPackageJSON(serverRootDir).catch(() => ({}));
|
146
|
-
for (const [pkgName, pkgVersions] of Object.entries(multiVersionPkgs)) {
|
147
|
-
const versionEntires = Object.entries(pkgVersions).sort(([v1, p1], [v2, p2]) => {
|
148
|
-
var _tracedPackages_pkgName_versions_v1, _tracedPackages_pkgName_versions, _tracedPackages_pkgName, _tracedPackages_pkgName_versions_v2, _tracedPackages_pkgName_versions1, _tracedPackages_pkgName1;
|
149
|
-
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;
|
150
|
-
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;
|
151
|
-
if (shouldHoist1 && !shouldHoist2) {
|
152
|
-
return -1;
|
153
|
-
}
|
154
|
-
if (!shouldHoist1 && shouldHoist2) {
|
155
|
-
return 1;
|
156
|
-
}
|
157
|
-
if (p1.length === 0) {
|
158
|
-
return -1;
|
159
|
-
}
|
160
|
-
if (p2.length === 0) {
|
161
|
-
return 1;
|
162
|
-
}
|
163
|
-
return semver.lt(v1, v2, {
|
164
|
-
loose: true
|
165
|
-
}) ? 1 : -1;
|
166
|
-
});
|
167
|
-
for (const [version, parentPkgs] of versionEntires) {
|
168
|
-
const pkg = tracedPackages[pkgName];
|
169
|
-
const pkgDestPath = `.modernjs/${pkgName}@${version}/node_modules/${pkgName}`;
|
170
|
-
await writePackage({
|
171
|
-
pkg,
|
172
|
-
version,
|
173
|
-
projectDir: serverRootDir,
|
174
|
-
_pkgPath: pkgDestPath
|
175
|
-
});
|
176
|
-
await linkPackage(pkgDestPath, `${pkgName}`, serverRootDir);
|
177
|
-
for (const parentPkg of parentPkgs) {
|
178
|
-
const parentPkgName = parentPkg.replace(/@[^@]+$/, "");
|
179
|
-
await (multiVersionPkgs[parentPkgName] ? linkPackage(pkgDestPath, `.modernjs/${parentPkg}/node_modules/${pkgName}`, serverRootDir) : linkPackage(pkgDestPath, `${parentPkgName}/node_modules/${pkgName}`, serverRootDir));
|
180
|
-
}
|
181
|
-
}
|
182
|
-
}
|
183
|
-
const outputPkgPath = path.join(serverRootDir, "package.json");
|
184
|
-
const newPkgJson = {
|
185
|
-
name: `${projectPkgJson.name || "modernjs-project"}-prod`,
|
186
|
-
version: projectPkgJson.version || "0.0.0",
|
187
|
-
private: true,
|
188
|
-
type: projectPkgJson.type || "commonjs",
|
189
|
-
dependencies: Object.fromEntries([
|
190
|
-
...Object.values(tracedPackages).map((pkg) => [
|
191
|
-
pkg.name,
|
192
|
-
Object.keys(pkg.versions)[0]
|
193
|
-
])
|
194
|
-
].sort(([a], [b]) => a.localeCompare(b)))
|
195
|
-
};
|
196
|
-
const finalPkgJson = (modifyPackageJson === null || modifyPackageJson === void 0 ? void 0 : modifyPackageJson(newPkgJson)) || newPkgJson;
|
197
|
-
await fse.writeJSON(outputPkgPath, finalPkgJson);
|
198
|
-
};
|
199
|
-
export {
|
200
|
-
handleDependencies,
|
201
|
-
nodeFileTrace
|
202
|
-
};
|
@@ -1,137 +0,0 @@
|
|
1
|
-
import os from "node:os";
|
2
|
-
import path from "path";
|
3
|
-
import { fs as fse } from "@modern-js/utils";
|
4
|
-
import { nodeFileTrace, resolve } from "@vercel/nft";
|
5
|
-
import { parseNodeModulePath } from "mlly";
|
6
|
-
function applyPublicCondition(pkg) {
|
7
|
-
var _pkg_publishConfig;
|
8
|
-
if (pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig = pkg.publishConfig) === null || _pkg_publishConfig === void 0 ? void 0 : _pkg_publishConfig.exports) {
|
9
|
-
var _pkg_publishConfig1;
|
10
|
-
pkg.exports = pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig1 = pkg.publishConfig) === null || _pkg_publishConfig1 === void 0 ? void 0 : _pkg_publishConfig1.exports;
|
11
|
-
}
|
12
|
-
}
|
13
|
-
const writePackage = async (options) => {
|
14
|
-
const { pkg, version, projectDir, _pkgPath } = options;
|
15
|
-
const pkgPath = _pkgPath || pkg.name;
|
16
|
-
for (const src of pkg.versions[version].files) {
|
17
|
-
if (src.includes("node_modules")) {
|
18
|
-
const { subpath } = parseNodeModulePath(src);
|
19
|
-
const dest = path.join(projectDir, "node_modules", pkgPath, subpath);
|
20
|
-
const dirname = path.dirname(dest);
|
21
|
-
await fse.ensureDir(dirname);
|
22
|
-
await fse.copyFile(src, dest);
|
23
|
-
} else {
|
24
|
-
const subpath = path.relative(pkg.versions[version].path, src);
|
25
|
-
const dest = path.join(projectDir, "node_modules", pkgPath, subpath);
|
26
|
-
const dirname = path.dirname(dest);
|
27
|
-
await fse.ensureDir(dirname);
|
28
|
-
await fse.copyFile(src, dest);
|
29
|
-
}
|
30
|
-
}
|
31
|
-
const { pkgJSON } = pkg.versions[version];
|
32
|
-
applyPublicCondition(pkgJSON);
|
33
|
-
const packageJsonPath = path.join(projectDir, "node_modules", pkgPath, "package.json");
|
34
|
-
await fse.ensureDir(path.dirname(packageJsonPath));
|
35
|
-
await fse.writeFile(packageJsonPath, JSON.stringify(pkgJSON, null, 2));
|
36
|
-
};
|
37
|
-
const isWindows = os.platform() === "win32";
|
38
|
-
const linkPackage = async (from, to, projectRootDir) => {
|
39
|
-
const src = path.join(projectRootDir, "node_modules", from);
|
40
|
-
const dest = path.join(projectRootDir, "node_modules", to);
|
41
|
-
const dstStat = await fse.lstat(dest).catch(() => null);
|
42
|
-
const exists = dstStat === null || dstStat === void 0 ? void 0 : dstStat.isSymbolicLink();
|
43
|
-
if (exists) {
|
44
|
-
return;
|
45
|
-
}
|
46
|
-
await fse.mkdir(path.dirname(dest), {
|
47
|
-
recursive: true
|
48
|
-
});
|
49
|
-
await fse.symlink(path.relative(path.dirname(dest), src), dest, isWindows ? "junction" : "dir").catch((error) => {
|
50
|
-
console.error("Cannot link", from, "to", to, error);
|
51
|
-
});
|
52
|
-
};
|
53
|
-
const readDirRecursive = async (dir, options = {}) => {
|
54
|
-
const { filter } = options;
|
55
|
-
const files = await fse.readdir(dir, {
|
56
|
-
withFileTypes: true
|
57
|
-
});
|
58
|
-
const filesAndDirs = await Promise.all(files.map(async (file) => {
|
59
|
-
const resolvedPath = path.resolve(dir, file.name);
|
60
|
-
if (file.isDirectory()) {
|
61
|
-
return readDirRecursive(resolvedPath, options);
|
62
|
-
} else {
|
63
|
-
return filter && !filter(resolvedPath) ? [] : resolvedPath;
|
64
|
-
}
|
65
|
-
}));
|
66
|
-
return filesAndDirs.flat();
|
67
|
-
};
|
68
|
-
const isFile = async (file) => {
|
69
|
-
try {
|
70
|
-
const stat = await fse.stat(file);
|
71
|
-
return stat.isFile();
|
72
|
-
} catch (error) {
|
73
|
-
if (error.code === "ENOENT") {
|
74
|
-
return false;
|
75
|
-
}
|
76
|
-
throw error;
|
77
|
-
}
|
78
|
-
};
|
79
|
-
const findEntryFiles = async (rootDir, entryFilter) => {
|
80
|
-
const files = await readDirRecursive(rootDir, {
|
81
|
-
filter: entryFilter
|
82
|
-
});
|
83
|
-
return files.filter((file) => file.endsWith(".mjs") || file.endsWith(".cjs") || file.endsWith(".js"));
|
84
|
-
};
|
85
|
-
const findPackageParents = (pkg, version, tracedFiles) => {
|
86
|
-
const versionFiles = pkg.versions[version].files.map((path2) => tracedFiles[path2]);
|
87
|
-
const parentPkgs = [
|
88
|
-
...new Set(versionFiles.flatMap((file) => (
|
89
|
-
// Because it supports copyWholePackage configuration, not all files exist.
|
90
|
-
file === null || file === void 0 ? void 0 : file.parents.map((parentPath) => {
|
91
|
-
const parentFile = tracedFiles[parentPath];
|
92
|
-
if (!parentFile || parentFile.pkgName === pkg.name) {
|
93
|
-
return null;
|
94
|
-
}
|
95
|
-
return `${parentFile.pkgName}@${parentFile.pkgVersion}`;
|
96
|
-
}).filter(Boolean)
|
97
|
-
)))
|
98
|
-
];
|
99
|
-
return parentPkgs.filter((parentPkg) => parentPkg);
|
100
|
-
};
|
101
|
-
const traceFiles = async ({ entryFiles, serverRootDir, base = "/", traceOptions }) => {
|
102
|
-
return await nodeFileTrace(entryFiles, {
|
103
|
-
base,
|
104
|
-
processCwd: serverRootDir,
|
105
|
-
resolve: async (id, parent, job, isCjs) => {
|
106
|
-
if (id.startsWith("@modern-js/prod-server")) {
|
107
|
-
return require.resolve(id, {
|
108
|
-
paths: [
|
109
|
-
require.resolve("@modern-js/app-tools")
|
110
|
-
]
|
111
|
-
});
|
112
|
-
} else {
|
113
|
-
return resolve(id, parent, job, isCjs);
|
114
|
-
}
|
115
|
-
},
|
116
|
-
...traceOptions
|
117
|
-
});
|
118
|
-
};
|
119
|
-
const resolveTracedPath = async (base, p) => fse.realpath(path.resolve(base, p));
|
120
|
-
const isSubPath = (parentPath, childPath) => {
|
121
|
-
if (!parentPath || !childPath) {
|
122
|
-
return false;
|
123
|
-
}
|
124
|
-
const relative = path.relative(parentPath, childPath);
|
125
|
-
return relative && !relative.startsWith("..");
|
126
|
-
};
|
127
|
-
export {
|
128
|
-
findEntryFiles,
|
129
|
-
findPackageParents,
|
130
|
-
isFile,
|
131
|
-
isSubPath,
|
132
|
-
linkPackage,
|
133
|
-
readDirRecursive,
|
134
|
-
resolveTracedPath,
|
135
|
-
traceFiles,
|
136
|
-
writePackage
|
137
|
-
};
|
package/dist/types/hooks.d.ts
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
import { type AppToolsOptions } from '../old';
|
2
|
-
import type { AppTools, CliPluginFuture } from '../types';
|
3
|
-
import { initAppContext } from './context';
|
4
|
-
export * from '../defineConfig';
|
5
|
-
export { initAppContext };
|
6
|
-
export declare const appTools: (options?: AppToolsOptions) => CliPluginFuture<AppTools<'shared'>>;
|
@@ -1,9 +0,0 @@
|
|
1
|
-
import type { Plugin } from '@modern-js/plugin-v2';
|
2
|
-
import type { InternalPlugins } from '@modern-js/types';
|
3
|
-
/**
|
4
|
-
* Load internal plugins which in @modern-js scope and user's custom plugins.
|
5
|
-
* @param appDirectory - Application root directory.
|
6
|
-
* @param internalPlugins - Internal plugins.
|
7
|
-
* @returns Plugin Objects has been required.
|
8
|
-
*/
|
9
|
-
export declare const loadInternalPlugins: (appDirectory: string, internalPlugins?: InternalPlugins, autoLoad?: InternalPlugins, autoLoadPlugins?: boolean) => Promise<Plugin[]>;
|
@@ -1 +0,0 @@
|
|
1
|
-
export declare function getIsAutoLoadPlugins(appDirectory: string, configFile?: string, packageJsonConfig?: string): Promise<boolean>;
|
package/dist/types/old.d.ts
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
import type { CliPlugin } from '@modern-js/core';
|
2
|
-
import type { AppTools, AppToolsOptions } from './types';
|
3
|
-
export { dev } from './commands/dev';
|
4
|
-
export type { DevOptions } from './utils/types';
|
5
|
-
export { mergeConfig } from '@modern-js/core';
|
6
|
-
export * from './defineConfig';
|
7
|
-
export * from './types';
|
8
|
-
export type { RuntimeUserConfig } from './types/config';
|
9
|
-
/**
|
10
|
-
* The core package of the framework, providing CLI commands, build capabilities, configuration parsing and more.
|
11
|
-
*/
|
12
|
-
export declare const appTools: (options?: AppToolsOptions) => CliPlugin<AppTools<'shared'>>;
|
13
|
-
export default appTools;
|
@@ -1,20 +0,0 @@
|
|
1
|
-
import type { NodeFileTraceOptions } from '@vercel/nft';
|
2
|
-
import type { PackageJson } from 'pkg-types';
|
3
|
-
import { traceFiles as defaultTraceFiles } from './utils';
|
4
|
-
export type { NodeFileTraceOptions } from '@vercel/nft';
|
5
|
-
export { nodeFileTrace } from '@vercel/nft';
|
6
|
-
export declare const handleDependencies: ({ appDir, serverRootDir, includeEntries, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, traceOptions, }: {
|
7
|
-
appDir: string;
|
8
|
-
serverRootDir: string;
|
9
|
-
includeEntries: string[];
|
10
|
-
traceFiles?: (({ entryFiles, serverRootDir, base, traceOptions, }: {
|
11
|
-
entryFiles: string[];
|
12
|
-
serverRootDir: string;
|
13
|
-
base?: string | undefined;
|
14
|
-
traceOptions?: NodeFileTraceOptions | undefined;
|
15
|
-
}) => Promise<import("@vercel/nft").NodeFileTraceResult>) | undefined;
|
16
|
-
entryFilter?: ((filePath: string) => boolean) | undefined;
|
17
|
-
modifyPackageJson?: ((pkgJson: PackageJson) => PackageJson) | undefined;
|
18
|
-
copyWholePackage?: ((pkgName: string) => boolean) | undefined;
|
19
|
-
traceOptions?: NodeFileTraceOptions | undefined;
|
20
|
-
}) => Promise<void>;
|
@@ -1,44 +0,0 @@
|
|
1
|
-
import { type NodeFileTraceOptions } from '@vercel/nft';
|
2
|
-
import type { PackageJson } from 'pkg-types';
|
3
|
-
export type TracedPackage = {
|
4
|
-
name: string;
|
5
|
-
versions: Record<string, {
|
6
|
-
pkgJSON: PackageJson;
|
7
|
-
path: string;
|
8
|
-
isDirectDep: boolean;
|
9
|
-
files: string[];
|
10
|
-
}>;
|
11
|
-
};
|
12
|
-
export type TracedFile = {
|
13
|
-
path: string;
|
14
|
-
subpath: string;
|
15
|
-
parents: string[];
|
16
|
-
isDirectDep: boolean;
|
17
|
-
pkgPath: string;
|
18
|
-
pkgName: string;
|
19
|
-
pkgVersion?: string;
|
20
|
-
};
|
21
|
-
interface WritePackageOptions {
|
22
|
-
pkg: TracedPackage;
|
23
|
-
version: string;
|
24
|
-
projectDir: string;
|
25
|
-
_pkgPath?: string;
|
26
|
-
}
|
27
|
-
export declare const writePackage: (options: WritePackageOptions) => Promise<void>;
|
28
|
-
export declare const linkPackage: (from: string, to: string, projectRootDir: string) => Promise<void>;
|
29
|
-
interface ReadDirOptions {
|
30
|
-
filter?: (filePath: string) => boolean;
|
31
|
-
}
|
32
|
-
export declare const readDirRecursive: (dir: string, options?: ReadDirOptions) => Promise<string[]>;
|
33
|
-
export declare const isFile: (file: string) => Promise<boolean>;
|
34
|
-
export declare const findEntryFiles: (rootDir: string, entryFilter?: ((filePath: string) => boolean) | undefined) => Promise<string[]>;
|
35
|
-
export declare const findPackageParents: (pkg: TracedPackage, version: string, tracedFiles: Record<string, TracedFile>) => string[];
|
36
|
-
export declare const traceFiles: ({ entryFiles, serverRootDir, base, traceOptions, }: {
|
37
|
-
entryFiles: string[];
|
38
|
-
serverRootDir: string;
|
39
|
-
base?: string | undefined;
|
40
|
-
traceOptions?: NodeFileTraceOptions | undefined;
|
41
|
-
}) => Promise<import("@vercel/nft").NodeFileTraceResult>;
|
42
|
-
export declare const resolveTracedPath: (base: string, p: string) => Promise<string>;
|
43
|
-
export declare const isSubPath: (parentPath: string, childPath: string) => boolean | "";
|
44
|
-
export {};
|
@@ -1 +0,0 @@
|
|
1
|
-
export { handleDependencies } from './dependencies';
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|