@modern-js/app-tools 2.63.2 → 2.63.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. package/dist/cjs/compat/hooks.js +16 -1
  2. package/dist/cjs/compat/index.js +3 -1
  3. package/dist/cjs/compat/utils.js +29 -8
  4. package/dist/cjs/plugins/deploy/platforms/netlify.js +7 -4
  5. package/dist/cjs/plugins/deploy/platforms/node.js +6 -3
  6. package/dist/cjs/plugins/deploy/platforms/vercel.js +7 -4
  7. package/dist/esm/compat/hooks.js +83 -24
  8. package/dist/esm/compat/index.js +4 -2
  9. package/dist/esm/compat/utils.js +29 -8
  10. package/dist/esm/plugins/deploy/platforms/netlify.js +6 -3
  11. package/dist/esm/plugins/deploy/platforms/node.js +5 -2
  12. package/dist/esm/plugins/deploy/platforms/vercel.js +6 -3
  13. package/dist/esm-node/compat/hooks.js +16 -1
  14. package/dist/esm-node/compat/index.js +4 -2
  15. package/dist/esm-node/compat/utils.js +29 -8
  16. package/dist/esm-node/plugins/deploy/platforms/netlify.js +6 -3
  17. package/dist/esm-node/plugins/deploy/platforms/node.js +5 -2
  18. package/dist/esm-node/plugins/deploy/platforms/vercel.js +6 -3
  19. package/dist/types/compat/utils.d.ts +8 -1
  20. package/package.json +19 -23
  21. package/dist/cjs/plugins/deploy/dependencies/index.js +0 -237
  22. package/dist/cjs/plugins/deploy/dependencies/utils.js +0 -179
  23. package/dist/cjs/plugins/deploy/exports.js +0 -28
  24. package/dist/esm/plugins/deploy/dependencies/index.js +0 -615
  25. package/dist/esm/plugins/deploy/dependencies/utils.js +0 -421
  26. package/dist/esm/plugins/deploy/exports.js +0 -4
  27. package/dist/esm-node/plugins/deploy/dependencies/index.js +0 -202
  28. package/dist/esm-node/plugins/deploy/dependencies/utils.js +0 -137
  29. package/dist/esm-node/plugins/deploy/exports.js +0 -4
  30. package/dist/types/plugins/deploy/dependencies/index.d.ts +0 -20
  31. package/dist/types/plugins/deploy/dependencies/utils.d.ts +0 -44
  32. package/dist/types/plugins/deploy/exports.d.ts +0 -1
@@ -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
- };
@@ -1,4 +0,0 @@
1
- import { handleDependencies } from "./dependencies";
2
- export {
3
- handleDependencies
4
- };
@@ -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';