@modern-js/app-tools 2.57.0 → 2.57.1-alpha.0

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.
@@ -49,7 +49,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
49
49
  return;
50
50
  }
51
51
  const filePath = await (0, import_utils2.resolveTracedPath)(base, _path);
52
- if (filePath.startsWith(serverRootDir) || filePath.startsWith(appDir) && !filePath.startsWith(currentProjectModules)) {
52
+ if ((0, import_utils2.isSubPath)(serverRootDir, filePath) || (0, import_utils2.isSubPath)(appDir, filePath) && !(0, import_utils2.isSubPath)(currentProjectModules, filePath)) {
53
53
  return;
54
54
  }
55
55
  if (!await (0, import_utils2.isFile)(filePath)) {
@@ -72,7 +72,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
72
72
  const packageJsonPath = match ? import_node_path.default.join(match[0], "package.json") : await (0, import_utils.pkgUp)({
73
73
  cwd: import_node_path.default.dirname(filePath)
74
74
  });
75
- if (packageJsonPath === null || packageJsonPath === void 0 ? void 0 : packageJsonPath.startsWith(dependencySearchRoot)) {
75
+ if (packageJsonPath && (0, import_utils2.isSubPath)(dependencySearchRoot, packageJsonPath)) {
76
76
  const packageJson = await import_utils.fs.readJSON(packageJsonPath);
77
77
  pkgPath = baseDir = import_node_path.default.dirname(packageJsonPath);
78
78
  subpath = import_node_path.default.relative(baseDir, filePath);
@@ -89,7 +89,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
89
89
  path: filePath,
90
90
  parents,
91
91
  isDirectDep: parents.some((parent) => {
92
- return parent.startsWith(appDir) && !parent.startsWith(currentProjectModules);
92
+ return (0, import_utils2.isSubPath)(appDir, parent) && !(0, import_utils2.isSubPath)(currentProjectModules, parent);
93
93
  }),
94
94
  subpath,
95
95
  pkgName,
@@ -31,6 +31,7 @@ __export(utils_exports, {
31
31
  findEntryFiles: () => findEntryFiles,
32
32
  findPackageParents: () => findPackageParents,
33
33
  isFile: () => isFile,
34
+ isSubPath: () => isSubPath,
34
35
  linkPackage: () => linkPackage,
35
36
  readDirRecursive: () => readDirRecursive,
36
37
  resolveTracedPath: () => resolveTracedPath,
@@ -145,11 +146,19 @@ const traceFiles = async (entryFiles, serverRootDir, base = "/") => {
145
146
  });
146
147
  };
147
148
  const resolveTracedPath = async (base, p) => import_utils.fs.realpath(import_path.default.resolve(base, p));
149
+ const isSubPath = (parentPath, childPath) => {
150
+ if (!parentPath || !childPath) {
151
+ return false;
152
+ }
153
+ const relative = import_path.default.relative(parentPath, childPath);
154
+ return relative && !relative.startsWith("..");
155
+ };
148
156
  // Annotate the CommonJS export names for ESM import in node:
149
157
  0 && (module.exports = {
150
158
  findEntryFiles,
151
159
  findPackageParents,
152
160
  isFile,
161
+ isSubPath,
153
162
  linkPackage,
154
163
  readDirRecursive,
155
164
  resolveTracedPath,
@@ -7,7 +7,7 @@ import path from "node:path";
7
7
  import { fs as fse, pkgUp, semver } from "@modern-js/utils";
8
8
  import { readPackageJSON } from "pkg-types";
9
9
  import { parseNodeModulePath } from "mlly";
10
- import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaultTraceFiles, findPackageParents, resolveTracedPath, readDirRecursive } from "./utils";
10
+ import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaultTraceFiles, findPackageParents, resolveTracedPath, readDirRecursive, isSubPath } from "./utils";
11
11
  var handleDependencies = function() {
12
12
  var _ref = _async_to_generator(function(param) {
13
13
  var appDir, serverRootDir, includeEntries, _param_traceFiles, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, base, entryFiles, fileTrace, currentProjectModules, dependencySearchRoot, tracedFiles, _, tracedPackages, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, tracedFile, pkgName, tracedPackage, pkgJSON, tracedPackageVersion, shouldCopyWholePackage, _tracedPackageVersion_files, allFiles, err, multiVersionPkgs, singleVersionPackages, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, tracedPackage1, versions, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, version, projectPkgJson, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _loop, _iterator3, _step3, err, outputPkgPath, newPkgJson, finalPkgJson;
@@ -51,7 +51,7 @@ var handleDependencies = function() {
51
51
  ];
52
52
  case 1:
53
53
  filePath = _state2.sent();
54
- if (filePath.startsWith(serverRootDir) || filePath.startsWith(appDir) && !filePath.startsWith(currentProjectModules)) {
54
+ if (isSubPath(serverRootDir, filePath) || isSubPath(appDir, filePath) && !isSubPath(currentProjectModules, filePath)) {
55
55
  return [
56
56
  2
57
57
  ];
@@ -106,7 +106,7 @@ var handleDependencies = function() {
106
106
  _state2.label = 6;
107
107
  case 6:
108
108
  packageJsonPath = _tmp;
109
- if (!(packageJsonPath === null || packageJsonPath === void 0 ? void 0 : packageJsonPath.startsWith(dependencySearchRoot)))
109
+ if (!(packageJsonPath && isSubPath(dependencySearchRoot, packageJsonPath)))
110
110
  return [
111
111
  3,
112
112
  8
@@ -139,7 +139,7 @@ var handleDependencies = function() {
139
139
  path: filePath,
140
140
  parents,
141
141
  isDirectDep: parents.some(function(parent) {
142
- return parent.startsWith(appDir) && !parent.startsWith(currentProjectModules);
142
+ return isSubPath(appDir, parent) && !isSubPath(currentProjectModules, parent);
143
143
  }),
144
144
  subpath,
145
145
  pkgName: pkgName2,
@@ -374,10 +374,18 @@ var resolveTracedPath = function() {
374
374
  return _ref.apply(this, arguments);
375
375
  };
376
376
  }();
377
+ var isSubPath = function(parentPath, childPath) {
378
+ if (!parentPath || !childPath) {
379
+ return false;
380
+ }
381
+ var relative = path.relative(parentPath, childPath);
382
+ return relative && !relative.startsWith("..");
383
+ };
377
384
  export {
378
385
  findEntryFiles,
379
386
  findPackageParents,
380
387
  isFile,
388
+ isSubPath,
381
389
  linkPackage,
382
390
  readDirRecursive,
383
391
  resolveTracedPath,
@@ -2,7 +2,7 @@ import path from "node:path";
2
2
  import { fs as fse, pkgUp, semver } from "@modern-js/utils";
3
3
  import { readPackageJSON } from "pkg-types";
4
4
  import { parseNodeModulePath } from "mlly";
5
- import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaultTraceFiles, findPackageParents, resolveTracedPath, readDirRecursive } from "./utils";
5
+ import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaultTraceFiles, findPackageParents, resolveTracedPath, readDirRecursive, isSubPath } from "./utils";
6
6
  const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = defaultTraceFiles, entryFilter, modifyPackageJson, copyWholePackage }) => {
7
7
  const base = "/";
8
8
  const entryFiles = await findEntryFiles(serverRootDir, entryFilter);
@@ -16,7 +16,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
16
16
  return;
17
17
  }
18
18
  const filePath = await resolveTracedPath(base, _path);
19
- if (filePath.startsWith(serverRootDir) || filePath.startsWith(appDir) && !filePath.startsWith(currentProjectModules)) {
19
+ if (isSubPath(serverRootDir, filePath) || isSubPath(appDir, filePath) && !isSubPath(currentProjectModules, filePath)) {
20
20
  return;
21
21
  }
22
22
  if (!await isFile(filePath)) {
@@ -39,7 +39,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
39
39
  const packageJsonPath = match ? path.join(match[0], "package.json") : await pkgUp({
40
40
  cwd: path.dirname(filePath)
41
41
  });
42
- if (packageJsonPath === null || packageJsonPath === void 0 ? void 0 : packageJsonPath.startsWith(dependencySearchRoot)) {
42
+ if (packageJsonPath && isSubPath(dependencySearchRoot, packageJsonPath)) {
43
43
  const packageJson = await fse.readJSON(packageJsonPath);
44
44
  pkgPath = baseDir = path.dirname(packageJsonPath);
45
45
  subpath = path.relative(baseDir, filePath);
@@ -56,7 +56,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
56
56
  path: filePath,
57
57
  parents,
58
58
  isDirectDep: parents.some((parent) => {
59
- return parent.startsWith(appDir) && !parent.startsWith(currentProjectModules);
59
+ return isSubPath(appDir, parent) && !isSubPath(currentProjectModules, parent);
60
60
  }),
61
61
  subpath,
62
62
  pkgName,
@@ -105,10 +105,18 @@ const traceFiles = async (entryFiles, serverRootDir, base = "/") => {
105
105
  });
106
106
  };
107
107
  const resolveTracedPath = async (base, p) => fse.realpath(path.resolve(base, p));
108
+ const isSubPath = (parentPath, childPath) => {
109
+ if (!parentPath || !childPath) {
110
+ return false;
111
+ }
112
+ const relative = path.relative(parentPath, childPath);
113
+ return relative && !relative.startsWith("..");
114
+ };
108
115
  export {
109
116
  findEntryFiles,
110
117
  findPackageParents,
111
118
  isFile,
119
+ isSubPath,
112
120
  linkPackage,
113
121
  readDirRecursive,
114
122
  resolveTracedPath,
@@ -34,4 +34,5 @@ export declare const findEntryFiles: (rootDir: string, entryFilter?: ((filePath:
34
34
  export declare const findPackageParents: (pkg: TracedPackage, version: string, tracedFiles: Record<string, TracedFile>) => string[];
35
35
  export declare const traceFiles: (entryFiles: string[], serverRootDir: string, base?: string) => Promise<import("@vercel/nft").NodeFileTraceResult>;
36
36
  export declare const resolveTracedPath: (base: string, p: string) => Promise<string>;
37
+ export declare const isSubPath: (parentPath: string, childPath: string) => boolean | "";
37
38
  export {};
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.57.0",
18
+ "version": "2.57.1-alpha.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -88,18 +88,18 @@
88
88
  "pkg-types": "^1.1.0",
89
89
  "std-env": "^3.7.0",
90
90
  "@modern-js/core": "2.57.0",
91
- "@modern-js/node-bundle-require": "2.57.0",
92
91
  "@modern-js/plugin": "2.57.0",
93
- "@modern-js/plugin-data-loader": "2.57.0",
94
92
  "@modern-js/plugin-i18n": "2.57.0",
95
- "@modern-js/plugin-lint": "2.57.0",
96
93
  "@modern-js/prod-server": "2.57.0",
97
- "@modern-js/rsbuild-plugin-esbuild": "2.57.0",
98
- "@modern-js/server-utils": "2.57.0",
99
94
  "@modern-js/server": "2.57.0",
100
95
  "@modern-js/server-core": "2.57.0",
101
- "@modern-js/types": "2.57.0",
96
+ "@modern-js/node-bundle-require": "2.57.0",
97
+ "@modern-js/server-utils": "2.57.0",
98
+ "@modern-js/plugin-lint": "2.57.0",
99
+ "@modern-js/rsbuild-plugin-esbuild": "2.57.0",
102
100
  "@modern-js/uni-builder": "2.57.0",
101
+ "@modern-js/types": "2.57.0",
102
+ "@modern-js/plugin-data-loader": "2.57.0",
103
103
  "@modern-js/utils": "2.57.0"
104
104
  },
105
105
  "devDependencies": {
@@ -112,8 +112,8 @@
112
112
  "tsconfig-paths": "^4.2.0",
113
113
  "typescript": "^5",
114
114
  "webpack": "^5.93.0",
115
- "@scripts/jest-config": "2.57.0",
116
- "@scripts/build": "2.57.0"
115
+ "@scripts/build": "2.57.0",
116
+ "@scripts/jest-config": "2.57.0"
117
117
  },
118
118
  "sideEffects": false,
119
119
  "publishConfig": {