@modern-js/app-tools 2.53.1-alpha.3 → 2.53.1-alpha.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -36,10 +36,10 @@ 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 ({ appDir, serverRootDir, includeEntries, entryFilter, modifyPackageJson, copyWholePackage }) => {
39
+ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = import_utils2.traceFiles, entryFilter, modifyPackageJson, copyWholePackage }) => {
40
40
  const base = "/";
41
41
  const entryFiles = await (0, import_utils2.findEntryFiles)(serverRootDir, entryFilter);
42
- const fileTrace = await (0, import_utils2.traceFiles)(entryFiles.concat(includeEntries), serverRootDir, base);
42
+ const fileTrace = await traceFiles(entryFiles.concat(includeEntries), serverRootDir, base);
43
43
  const currentProjectModules = import_node_path.default.join(appDir, "node_modules");
44
44
  const tracedFiles = Object.fromEntries(await Promise.all([
45
45
  ...fileTrace.reasons.entries()
@@ -125,31 +125,24 @@ const findEntryFiles = async (rootDir, entryFilter) => {
125
125
  const findPackageParents = (pkg, version, tracedFiles) => {
126
126
  const versionFiles = pkg.versions[version].files.map((path2) => tracedFiles[path2]);
127
127
  const parentPkgs = [
128
- ...new Set(versionFiles.flatMap((file) => file.parents.map((parentPath) => {
129
- const parentFile = tracedFiles[parentPath];
130
- if (!parentFile || parentFile.pkgName === pkg.name) {
131
- return null;
132
- }
133
- return `${parentFile.pkgName}@${parentFile.pkgVersion}`;
134
- }).filter(Boolean)))
128
+ ...new Set(versionFiles.flatMap((file) => (
129
+ // 因为支持 copyWholePackage 配置,并不是所有的文件都会被复制的
130
+ file === null || file === void 0 ? void 0 : file.parents.map((parentPath) => {
131
+ const parentFile = tracedFiles[parentPath];
132
+ if (!parentFile || parentFile.pkgName === pkg.name) {
133
+ return null;
134
+ }
135
+ return `${parentFile.pkgName}@${parentFile.pkgVersion}`;
136
+ }).filter(Boolean)
137
+ )))
135
138
  ];
136
- return parentPkgs;
139
+ return parentPkgs.filter((parentPkg) => parentPkg);
137
140
  };
138
141
  const traceFiles = async (entryFiles, serverRootDir, base = "/") => {
139
142
  return await (0, import_nft.nodeFileTrace)(entryFiles, {
140
143
  base,
141
144
  processCwd: serverRootDir,
142
- resolve: async (id, parent, job, isCjs) => {
143
- if (id.startsWith("@modern-js/prod-server")) {
144
- return require.resolve(id, {
145
- paths: [
146
- require.resolve("@modern-js/app-tools")
147
- ]
148
- });
149
- } else {
150
- return (0, import_nft.resolve)(id, parent, job, isCjs);
151
- }
152
- }
145
+ cache: /* @__PURE__ */ Object.create(null)
153
146
  });
154
147
  };
155
148
  const resolveTracedPath = async (base, p) => import_utils.fs.realpath(import_path.default.resolve(base, p));
@@ -84,10 +84,7 @@ const createNodePreset = (appContext, config) => {
84
84
  includeEntries: [
85
85
  require.resolve("@modern-js/prod-server")
86
86
  ],
87
- entryFilter: filter,
88
- copyWholePackage: (pkgName) => {
89
- return pkgName === "koa";
90
- }
87
+ entryFilter: filter
91
88
  });
92
89
  }
93
90
  };
@@ -7,14 +7,14 @@ 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, findPackageParents, resolveTracedPath, readDirRecursive } from "./utils";
10
+ import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaultTraceFiles, findPackageParents, resolveTracedPath, readDirRecursive } from "./utils";
11
11
  var handleDependencies = function() {
12
12
  var _ref = _async_to_generator(function(param) {
13
- var appDir, serverRootDir, includeEntries, entryFilter, modifyPackageJson, copyWholePackage, base, entryFiles, fileTrace, currentProjectModules, 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;
13
+ var appDir, serverRootDir, includeEntries, _param_traceFiles, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, base, entryFiles, fileTrace, currentProjectModules, 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;
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, entryFilter = param.entryFilter, modifyPackageJson = param.modifyPackageJson, copyWholePackage = param.copyWholePackage;
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
18
  base = "/";
19
19
  return [
20
20
  4,
@@ -5,7 +5,7 @@ import path from "path";
5
5
  import os from "node:os";
6
6
  import { fs as fse } from "@modern-js/utils";
7
7
  import { parseNodeModulePath } from "mlly";
8
- import { nodeFileTrace, resolve } from "@vercel/nft";
8
+ import { nodeFileTrace } from "@vercel/nft";
9
9
  function applyPublicCondition(pkg) {
10
10
  var _pkg_publishConfig;
11
11
  if (pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig = pkg.publishConfig) === null || _pkg_publishConfig === void 0 ? void 0 : _pkg_publishConfig.exports) {
@@ -319,15 +319,20 @@ var findPackageParents = function(pkg, version, tracedFiles) {
319
319
  return tracedFiles[path2];
320
320
  });
321
321
  var parentPkgs = _to_consumable_array(new Set(versionFiles.flatMap(function(file) {
322
- return file.parents.map(function(parentPath) {
323
- var parentFile = tracedFiles[parentPath];
324
- if (!parentFile || parentFile.pkgName === pkg.name) {
325
- return null;
326
- }
327
- return "".concat(parentFile.pkgName, "@").concat(parentFile.pkgVersion);
328
- }).filter(Boolean);
322
+ return (
323
+ // 因为支持 copyWholePackage 配置,并不是所有的文件都会被复制的
324
+ file === null || file === void 0 ? void 0 : file.parents.map(function(parentPath) {
325
+ var parentFile = tracedFiles[parentPath];
326
+ if (!parentFile || parentFile.pkgName === pkg.name) {
327
+ return null;
328
+ }
329
+ return "".concat(parentFile.pkgName, "@").concat(parentFile.pkgVersion);
330
+ }).filter(Boolean)
331
+ );
329
332
  })));
330
- return parentPkgs;
333
+ return parentPkgs.filter(function(parentPkg) {
334
+ return parentPkg;
335
+ });
331
336
  };
332
337
  var traceFiles = function() {
333
338
  var _ref = _async_to_generator(function(entryFiles, serverRootDir) {
@@ -342,33 +347,7 @@ var traceFiles = function() {
342
347
  nodeFileTrace(entryFiles, {
343
348
  base,
344
349
  processCwd: serverRootDir,
345
- resolve: function() {
346
- var _ref2 = _async_to_generator(function(id, parent, job, isCjs) {
347
- return _ts_generator(this, function(_state2) {
348
- if (id.startsWith("@modern-js/prod-server")) {
349
- return [
350
- 2,
351
- require.resolve(id, {
352
- paths: [
353
- require.resolve("@modern-js/app-tools")
354
- ]
355
- })
356
- ];
357
- } else {
358
- return [
359
- 2,
360
- resolve(id, parent, job, isCjs)
361
- ];
362
- }
363
- return [
364
- 2
365
- ];
366
- });
367
- });
368
- return function(id, parent, job, isCjs) {
369
- return _ref2.apply(this, arguments);
370
- };
371
- }()
350
+ cache: /* @__PURE__ */ Object.create(null)
372
351
  })
373
352
  ];
374
353
  case 1:
@@ -110,10 +110,7 @@ var createNodePreset = function(appContext, config) {
110
110
  includeEntries: [
111
111
  require.resolve("@modern-js/prod-server")
112
112
  ],
113
- entryFilter: filter,
114
- copyWholePackage: function(pkgName) {
115
- return pkgName === "koa";
116
- }
113
+ entryFilter: filter
117
114
  })
118
115
  ];
119
116
  case 1:
@@ -2,8 +2,8 @@ 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, findPackageParents, resolveTracedPath, readDirRecursive } from "./utils";
6
- const handleDependencies = async ({ appDir, serverRootDir, includeEntries, entryFilter, modifyPackageJson, copyWholePackage }) => {
5
+ import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles as defaultTraceFiles, findPackageParents, resolveTracedPath, readDirRecursive } from "./utils";
6
+ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = defaultTraceFiles, entryFilter, modifyPackageJson, copyWholePackage }) => {
7
7
  const base = "/";
8
8
  const entryFiles = await findEntryFiles(serverRootDir, entryFilter);
9
9
  const fileTrace = await traceFiles(entryFiles.concat(includeEntries), serverRootDir, base);
@@ -2,7 +2,7 @@ import path from "path";
2
2
  import os from "node:os";
3
3
  import { fs as fse } from "@modern-js/utils";
4
4
  import { parseNodeModulePath } from "mlly";
5
- import { nodeFileTrace, resolve } from "@vercel/nft";
5
+ import { nodeFileTrace } from "@vercel/nft";
6
6
  function applyPublicCondition(pkg) {
7
7
  var _pkg_publishConfig;
8
8
  if (pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig = pkg.publishConfig) === null || _pkg_publishConfig === void 0 ? void 0 : _pkg_publishConfig.exports) {
@@ -85,31 +85,24 @@ const findEntryFiles = async (rootDir, entryFilter) => {
85
85
  const findPackageParents = (pkg, version, tracedFiles) => {
86
86
  const versionFiles = pkg.versions[version].files.map((path2) => tracedFiles[path2]);
87
87
  const parentPkgs = [
88
- ...new Set(versionFiles.flatMap((file) => file.parents.map((parentPath) => {
89
- const parentFile = tracedFiles[parentPath];
90
- if (!parentFile || parentFile.pkgName === pkg.name) {
91
- return null;
92
- }
93
- return `${parentFile.pkgName}@${parentFile.pkgVersion}`;
94
- }).filter(Boolean)))
88
+ ...new Set(versionFiles.flatMap((file) => (
89
+ // 因为支持 copyWholePackage 配置,并不是所有的文件都会被复制的
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
+ )))
95
98
  ];
96
- return parentPkgs;
99
+ return parentPkgs.filter((parentPkg) => parentPkg);
97
100
  };
98
101
  const traceFiles = async (entryFiles, serverRootDir, base = "/") => {
99
102
  return await nodeFileTrace(entryFiles, {
100
103
  base,
101
104
  processCwd: serverRootDir,
102
- resolve: async (id, parent, job, isCjs) => {
103
- if (id.startsWith("@modern-js/prod-server")) {
104
- return require.resolve(id, {
105
- paths: [
106
- require.resolve("@modern-js/app-tools")
107
- ]
108
- });
109
- } else {
110
- return resolve(id, parent, job, isCjs);
111
- }
112
- }
105
+ cache: /* @__PURE__ */ Object.create(null)
113
106
  });
114
107
  };
115
108
  const resolveTracedPath = async (base, p) => fse.realpath(path.resolve(base, p));
@@ -51,10 +51,7 @@ const createNodePreset = (appContext, config) => {
51
51
  includeEntries: [
52
52
  require.resolve("@modern-js/prod-server")
53
53
  ],
54
- entryFilter: filter,
55
- copyWholePackage: (pkgName) => {
56
- return pkgName === "koa";
57
- }
54
+ entryFilter: filter
58
55
  });
59
56
  }
60
57
  };
@@ -1,8 +1,10 @@
1
1
  import type { PackageJson } from 'pkg-types';
2
- export declare const handleDependencies: ({ appDir, serverRootDir, includeEntries, entryFilter, modifyPackageJson, copyWholePackage, }: {
2
+ import { traceFiles as defaultTraceFiles } from './utils';
3
+ export declare const handleDependencies: ({ appDir, serverRootDir, includeEntries, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, }: {
3
4
  appDir: string;
4
5
  serverRootDir: string;
5
6
  includeEntries: string[];
7
+ traceFiles?: ((entryFiles: string[], serverRootDir: string, base?: string) => Promise<import("@vercel/nft").NodeFileTraceResult>) | undefined;
6
8
  entryFilter?: ((filePath: string) => boolean) | undefined;
7
9
  modifyPackageJson?: ((pkgJson: PackageJson) => PackageJson) | undefined;
8
10
  copyWholePackage?: ((pkgName: string) => boolean) | undefined;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.53.1-alpha.3",
18
+ "version": "2.53.1-alpha.4",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -90,18 +90,18 @@
90
90
  "std-env": "^3.7.0",
91
91
  "@modern-js/plugin-data-loader": "2.53.0",
92
92
  "@modern-js/core": "2.53.0",
93
- "@modern-js/plugin": "2.53.0",
94
93
  "@modern-js/node-bundle-require": "2.53.0",
95
94
  "@modern-js/prod-server": "2.53.0",
96
95
  "@modern-js/plugin-i18n": "2.53.0",
97
- "@modern-js/types": "2.53.0",
98
- "@modern-js/plugin-lint": "2.53.0",
96
+ "@modern-js/plugin": "2.53.0",
99
97
  "@modern-js/server-core": "2.53.0",
98
+ "@modern-js/types": "2.53.0",
99
+ "@modern-js/rsbuild-plugin-esbuild": "2.53.0",
100
+ "@modern-js/utils": "2.53.0",
100
101
  "@modern-js/server": "2.53.0",
102
+ "@modern-js/server-utils": "2.53.0",
101
103
  "@modern-js/uni-builder": "2.53.0",
102
- "@modern-js/utils": "2.53.0",
103
- "@modern-js/rsbuild-plugin-esbuild": "2.53.0",
104
- "@modern-js/server-utils": "2.53.0"
104
+ "@modern-js/plugin-lint": "2.53.0"
105
105
  },
106
106
  "devDependencies": {
107
107
  "@rsbuild/plugin-swc": "0.7.3",