@modern-js/app-tools 2.54.2-alpha.3 → 2.54.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. package/dist/cjs/commands/build.js +1 -1
  2. package/dist/cjs/commands/deploy.js +2 -1
  3. package/dist/cjs/commands/dev.js +1 -1
  4. package/dist/cjs/commands/serve.js +1 -1
  5. package/dist/cjs/plugins/deploy/dependencies/index.js +17 -26
  6. package/dist/cjs/plugins/deploy/dependencies/utils.js +20 -14
  7. package/dist/cjs/plugins/deploy/platforms/netlify.js +3 -7
  8. package/dist/cjs/plugins/deploy/platforms/node.js +3 -8
  9. package/dist/cjs/plugins/deploy/platforms/vercel.js +3 -7
  10. package/dist/cjs/utils/loadPlugins.js +6 -5
  11. package/dist/esm/commands/build.js +1 -1
  12. package/dist/esm/commands/deploy.js +3 -2
  13. package/dist/esm/commands/dev.js +1 -1
  14. package/dist/esm/commands/serve.js +1 -1
  15. package/dist/esm/plugins/deploy/dependencies/index.js +69 -94
  16. package/dist/esm/plugins/deploy/dependencies/utils.js +39 -19
  17. package/dist/esm/plugins/deploy/platforms/netlify.js +3 -7
  18. package/dist/esm/plugins/deploy/platforms/node.js +3 -8
  19. package/dist/esm/plugins/deploy/platforms/vercel.js +3 -7
  20. package/dist/esm/utils/loadPlugins.js +11 -6
  21. package/dist/esm-node/commands/build.js +1 -1
  22. package/dist/esm-node/commands/deploy.js +2 -1
  23. package/dist/esm-node/commands/dev.js +1 -1
  24. package/dist/esm-node/commands/serve.js +1 -1
  25. package/dist/esm-node/plugins/deploy/dependencies/index.js +18 -27
  26. package/dist/esm-node/plugins/deploy/dependencies/utils.js +21 -15
  27. package/dist/esm-node/plugins/deploy/platforms/netlify.js +3 -7
  28. package/dist/esm-node/plugins/deploy/platforms/node.js +3 -8
  29. package/dist/esm-node/plugins/deploy/platforms/vercel.js +3 -7
  30. package/dist/esm-node/utils/loadPlugins.js +6 -5
  31. package/dist/types/plugins/deploy/dependencies/index.d.ts +1 -11
  32. package/dist/types/plugins/deploy/dependencies/utils.d.ts +1 -7
  33. package/dist/types/utils/loadPlugins.d.ts +2 -2
  34. package/package.json +17 -25
  35. package/dist/cjs/plugins/deploy/exports.js +0 -28
  36. package/dist/esm/plugins/deploy/exports.js +0 -4
  37. package/dist/esm-node/plugins/deploy/exports.js +0 -4
  38. package/dist/js/modern/analyze/constants.js +0 -15
  39. package/dist/js/modern/analyze/generateCode.js +0 -179
  40. package/dist/js/modern/analyze/getBundleEntry.js +0 -75
  41. package/dist/js/modern/analyze/getClientRoutes.js +0 -219
  42. package/dist/js/modern/analyze/getFileSystemEntry.js +0 -74
  43. package/dist/js/modern/analyze/getHtmlTemplate.js +0 -82
  44. package/dist/js/modern/analyze/getServerRoutes.js +0 -192
  45. package/dist/js/modern/analyze/index.js +0 -148
  46. package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -32
  47. package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -16
  48. package/dist/js/modern/analyze/templates.js +0 -88
  49. package/dist/js/modern/analyze/utils.js +0 -92
  50. package/dist/js/modern/commands/build.js +0 -154
  51. package/dist/js/modern/commands/deploy.js +0 -5
  52. package/dist/js/modern/commands/dev.js +0 -95
  53. package/dist/js/modern/commands/index.js +0 -3
  54. package/dist/js/modern/commands/inspect.js +0 -69
  55. package/dist/js/modern/commands/start.js +0 -31
  56. package/dist/js/modern/exports/server.js +0 -1
  57. package/dist/js/modern/hooks.js +0 -21
  58. package/dist/js/modern/index.js +0 -109
  59. package/dist/js/modern/locale/en.js +0 -35
  60. package/dist/js/modern/locale/index.js +0 -9
  61. package/dist/js/modern/locale/zh.js +0 -35
  62. package/dist/js/modern/utils/config.js +0 -78
  63. package/dist/js/modern/utils/createCompiler.js +0 -61
  64. package/dist/js/modern/utils/createServer.js +0 -18
  65. package/dist/js/modern/utils/getSpecifiedEntries.js +0 -36
  66. package/dist/js/modern/utils/language.js +0 -5
  67. package/dist/js/modern/utils/printInstructions.js +0 -11
  68. package/dist/js/modern/utils/routes.js +0 -15
  69. package/dist/js/modern/utils/types.js +0 -0
  70. package/dist/js/node/analyze/constants.js +0 -36
  71. package/dist/js/node/analyze/generateCode.js +0 -208
  72. package/dist/js/node/analyze/getBundleEntry.js +0 -89
  73. package/dist/js/node/analyze/getClientRoutes.js +0 -241
  74. package/dist/js/node/analyze/getFileSystemEntry.js +0 -90
  75. package/dist/js/node/analyze/getHtmlTemplate.js +0 -106
  76. package/dist/js/node/analyze/getServerRoutes.js +0 -208
  77. package/dist/js/node/analyze/index.js +0 -178
  78. package/dist/js/node/analyze/isDefaultExportFunction.js +0 -50
  79. package/dist/js/node/analyze/makeLegalIdentifier.js +0 -24
  80. package/dist/js/node/analyze/templates.js +0 -106
  81. package/dist/js/node/analyze/utils.js +0 -113
  82. package/dist/js/node/commands/build.js +0 -174
  83. package/dist/js/node/commands/deploy.js +0 -14
  84. package/dist/js/node/commands/dev.js +0 -120
  85. package/dist/js/node/commands/index.js +0 -44
  86. package/dist/js/node/commands/inspect.js +0 -98
  87. package/dist/js/node/commands/start.js +0 -47
  88. package/dist/js/node/exports/server.js +0 -13
  89. package/dist/js/node/hooks.js +0 -39
  90. package/dist/js/node/index.js +0 -141
  91. package/dist/js/node/locale/en.js +0 -42
  92. package/dist/js/node/locale/index.js +0 -20
  93. package/dist/js/node/locale/zh.js +0 -42
  94. package/dist/js/node/utils/config.js +0 -103
  95. package/dist/js/node/utils/createCompiler.js +0 -81
  96. package/dist/js/node/utils/createServer.js +0 -35
  97. package/dist/js/node/utils/getSpecifiedEntries.js +0 -46
  98. package/dist/js/node/utils/language.js +0 -13
  99. package/dist/js/node/utils/printInstructions.js +0 -22
  100. package/dist/js/node/utils/routes.js +0 -25
  101. package/dist/js/node/utils/types.js +0 -0
  102. package/dist/types/plugins/deploy/exports.d.ts +0 -1
@@ -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 } from "@vercel/nft";
8
+ import { nodeFileTrace, resolve } 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) {
@@ -14,12 +14,11 @@ function applyPublicCondition(pkg) {
14
14
  }
15
15
  }
16
16
  var writePackage = function() {
17
- var _ref = _async_to_generator(function(options) {
18
- var pkg, version, projectDir, _pkgPath, pkgPath, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, src, subpath, dest, dirname, subpath1, dest1, dirname1, err, pkgJSON, packageJsonPath;
17
+ var _ref = _async_to_generator(function(pkg, version, projectDir, _pkgPath) {
18
+ var pkgPath, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, src, subpath, dest, dirname, subpath1, dest1, dirname1, err, pkgJSON, packageJsonPath;
19
19
  return _ts_generator(this, function(_state) {
20
20
  switch (_state.label) {
21
21
  case 0:
22
- pkg = options.pkg, version = options.version, projectDir = options.projectDir, _pkgPath = options._pkgPath;
23
22
  pkgPath = _pkgPath || pkg.name;
24
23
  _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
25
24
  _state.label = 1;
@@ -134,7 +133,7 @@ var writePackage = function() {
134
133
  }
135
134
  });
136
135
  });
137
- return function writePackage2(options) {
136
+ return function writePackage2(pkg, version, projectDir, _pkgPath) {
138
137
  return _ref.apply(this, arguments);
139
138
  };
140
139
  }();
@@ -319,20 +318,15 @@ var findPackageParents = function(pkg, version, tracedFiles) {
319
318
  return tracedFiles[path2];
320
319
  });
321
320
  var parentPkgs = _to_consumable_array(new Set(versionFiles.flatMap(function(file) {
322
- return (
323
- // Because it supports copyWholePackage configuration, not all files exist.
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
- );
321
+ return file.parents.map(function(parentPath) {
322
+ var parentFile = tracedFiles[parentPath];
323
+ if (!parentFile || parentFile.pkgName === pkg.name) {
324
+ return null;
325
+ }
326
+ return "".concat(parentFile.pkgName, "@").concat(parentFile.pkgVersion);
327
+ }).filter(Boolean);
332
328
  })));
333
- return parentPkgs.filter(function(parentPkg) {
334
- return parentPkg;
335
- });
329
+ return parentPkgs;
336
330
  };
337
331
  var traceFiles = function() {
338
332
  var _ref = _async_to_generator(function(entryFiles, serverRootDir) {
@@ -347,7 +341,33 @@ var traceFiles = function() {
347
341
  nodeFileTrace(entryFiles, {
348
342
  base,
349
343
  processCwd: serverRootDir,
350
- cache: /* @__PURE__ */ Object.create(null)
344
+ resolve: function() {
345
+ var _ref2 = _async_to_generator(function(id, parent, job, isCjs) {
346
+ return _ts_generator(this, function(_state2) {
347
+ if (id.startsWith("@modern-js/prod-server")) {
348
+ return [
349
+ 2,
350
+ require.resolve(id, {
351
+ paths: [
352
+ require.resolve("@modern-js/app-tools")
353
+ ]
354
+ })
355
+ ];
356
+ } else {
357
+ return [
358
+ 2,
359
+ resolve(id, parent, job, isCjs)
360
+ ];
361
+ }
362
+ return [
363
+ 2
364
+ ];
365
+ });
366
+ });
367
+ return function(id, parent, job, isCjs) {
368
+ return _ref2.apply(this, arguments);
369
+ };
370
+ }()
351
371
  })
352
372
  ];
353
373
  case 1:
@@ -273,13 +273,9 @@ var createNetlifyPreset = function(appContext, modernConfig, needModernServer) {
273
273
  }
274
274
  return [
275
275
  4,
276
- handleDependencies({
277
- appDir: appDirectory,
278
- serverRootDir: funcsDirectory,
279
- includeEntries: [
280
- require.resolve("@modern-js/prod-server")
281
- ]
282
- })
276
+ handleDependencies(appDirectory, funcsDirectory, [
277
+ "@modern-js/prod-server"
278
+ ])
283
279
  ];
284
280
  case 3:
285
281
  _state.sent();
@@ -106,14 +106,9 @@ var createNodePreset = function(appContext, config) {
106
106
  };
107
107
  return [
108
108
  4,
109
- handleDependencies({
110
- appDir: appDirectory,
111
- serverRootDir: outputDirectory,
112
- includeEntries: [
113
- require.resolve("@modern-js/prod-server")
114
- ],
115
- entryFilter: filter
116
- })
109
+ handleDependencies(appDirectory, outputDirectory, [
110
+ "@modern-js/prod-server"
111
+ ], filter)
117
112
  ];
118
113
  case 1:
119
114
  _state.sent();
@@ -207,13 +207,9 @@ var createVercelPreset = function(appContext, modernConfig, needModernServer) {
207
207
  }
208
208
  return [
209
209
  4,
210
- handleDependencies({
211
- appDir: appDirectory,
212
- serverRootDir: funcsDirectory,
213
- includeEntries: [
214
- require.resolve("@modern-js/prod-server")
215
- ]
216
- })
210
+ handleDependencies(appDirectory, funcsDirectory, [
211
+ "@modern-js/prod-server"
212
+ ])
217
213
  ];
218
214
  case 1:
219
215
  _state.sent();
@@ -8,10 +8,12 @@ function getServerPlugins(api) {
8
8
  }
9
9
  function _getServerPlugins() {
10
10
  _getServerPlugins = _async_to_generator(function(api) {
11
- var runner, plugins;
11
+ var metaName, runner, plugins, filtedPlugins;
12
+ var _arguments = arguments;
12
13
  return _ts_generator(this, function(_state) {
13
14
  switch (_state.label) {
14
15
  case 0:
16
+ metaName = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : "modern-js";
15
17
  runner = api.useHookRunners();
16
18
  return [
17
19
  4,
@@ -21,30 +23,33 @@ function _getServerPlugins() {
21
23
  ];
22
24
  case 1:
23
25
  plugins = _state.sent().plugins;
26
+ filtedPlugins = plugins.filter(function(plugin) {
27
+ return plugin.name.includes(metaName);
28
+ });
24
29
  api.setAppContext(_object_spread_props(_object_spread({}, api.useAppContext()), {
25
- serverPlugins: plugins
30
+ serverPlugins: filtedPlugins
26
31
  }));
27
32
  return [
28
33
  2,
29
- plugins
34
+ filtedPlugins
30
35
  ];
31
36
  }
32
37
  });
33
38
  });
34
39
  return _getServerPlugins.apply(this, arguments);
35
40
  }
36
- function loadServerPlugins(api, appDirectory) {
41
+ function loadServerPlugins(api, appDirectory, metaName) {
37
42
  return _loadServerPlugins.apply(this, arguments);
38
43
  }
39
44
  function _loadServerPlugins() {
40
- _loadServerPlugins = _async_to_generator(function(api, appDirectory) {
45
+ _loadServerPlugins = _async_to_generator(function(api, appDirectory, metaName) {
41
46
  var plugins, instances;
42
47
  return _ts_generator(this, function(_state) {
43
48
  switch (_state.label) {
44
49
  case 0:
45
50
  return [
46
51
  4,
47
- getServerPlugins(api)
52
+ getServerPlugins(api, metaName)
48
53
  ];
49
54
  case 1:
50
55
  plugins = _state.sent();
@@ -12,7 +12,7 @@ const build = async (api, options) => {
12
12
  let resolvedConfig = api.useResolvedConfigContext();
13
13
  const appContext = api.useAppContext();
14
14
  const hookRunners = api.useHookRunners();
15
- await loadServerPlugins(api, appContext.appDirectory);
15
+ await loadServerPlugins(api, appContext.appDirectory, appContext.metaName);
16
16
  await registerCompiler(appContext.appDirectory, appContext.distDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.alias);
17
17
  const { apiOnly } = appContext;
18
18
  if (apiOnly) {
@@ -1,7 +1,8 @@
1
1
  import { getServerPlugins } from "../utils/loadPlugins";
2
2
  const deploy = async (api, options) => {
3
3
  const hookRunners = api.useHookRunners();
4
- await getServerPlugins(api);
4
+ const { metaName } = api.useAppContext();
5
+ await getServerPlugins(api, metaName);
5
6
  await hookRunners.beforeDeploy(options);
6
7
  await hookRunners.deploy(options);
7
8
  await hookRunners.afterDeploy(options);
@@ -37,7 +37,7 @@ const dev = async (api, options, devServerOptions = {}) => {
37
37
  throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
38
38
  }
39
39
  await generateRoutes(appContext);
40
- const pluginInstances = await loadServerPlugins(api, appDirectory);
40
+ const pluginInstances = await loadServerPlugins(api, appDirectory, metaName);
41
41
  const serverOptions = {
42
42
  metaName,
43
43
  dev: {
@@ -17,7 +17,7 @@ const start = async (api) => {
17
17
  }
18
18
  const meta = getMeta(metaName);
19
19
  const serverConfigPath = path.resolve(distDirectory, SERVER_DIR, `${meta}.server`);
20
- const pluginInstances = await loadServerPlugins(api, appDirectory);
20
+ const pluginInstances = await loadServerPlugins(api, appDirectory, metaName);
21
21
  const app = await createProdServer({
22
22
  metaName,
23
23
  pwd: distDirectory,
@@ -1,11 +1,21 @@
1
- import path from "node:path";
1
+ import path, { isAbsolute } 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";
6
- const handleDependencies = async ({ appDir, serverRootDir, includeEntries, traceFiles = defaultTraceFiles, entryFilter, modifyPackageJson, copyWholePackage }) => {
5
+ import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles, findPackageParents, resolveTracedPath } from "./utils";
6
+ const handleDependencies = async (appDir, serverRootDir, include, entryFilter) => {
7
7
  const base = "/";
8
8
  const entryFiles = await findEntryFiles(serverRootDir, entryFilter);
9
+ const includeEntries = include.map((item) => {
10
+ if (isAbsolute(item)) {
11
+ return item;
12
+ }
13
+ try {
14
+ return require.resolve(item);
15
+ } catch (error) {
16
+ }
17
+ return item;
18
+ });
9
19
  const fileTrace = await traceFiles(entryFiles.concat(includeEntries), serverRootDir, base);
10
20
  const currentProjectModules = path.join(appDir, "node_modules");
11
21
  const tracedFiles = Object.fromEntries(await Promise.all([
@@ -100,17 +110,9 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
100
110
  }
101
111
  tracedPackage.versions[pkgJSON.version] = tracedPackageVersion;
102
112
  }
113
+ tracedFile.path.startsWith(tracedFile.pkgPath) && tracedPackageVersion.path === tracedFile.pkgPath && tracedPackageVersion.files.push(tracedFile.path);
103
114
  tracedFile.pkgName = pkgName;
104
115
  tracedFile.pkgVersion = pkgJSON.version;
105
- const shouldCopyWholePackage = copyWholePackage === null || copyWholePackage === void 0 ? void 0 : copyWholePackage(pkgName);
106
- if (tracedFile.path.startsWith(tracedFile.pkgPath) && tracedPackageVersion.path === tracedFile.pkgPath) {
107
- if (shouldCopyWholePackage) {
108
- const allFiles = await readDirRecursive(tracedFile.pkgPath);
109
- tracedPackageVersion.files.push(...allFiles);
110
- } else {
111
- tracedPackageVersion.files.push(tracedFile.path);
112
- }
113
- }
114
116
  }
115
117
  const multiVersionPkgs = {};
116
118
  const singleVersionPackages = [];
@@ -128,11 +130,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
128
130
  await Promise.all(singleVersionPackages.map((pkgName) => {
129
131
  const pkg = tracedPackages[pkgName];
130
132
  const version = Object.keys(pkg.versions)[0];
131
- return writePackage({
132
- pkg,
133
- version,
134
- projectDir: serverRootDir
135
- });
133
+ return writePackage(pkg, version, serverRootDir);
136
134
  }));
137
135
  const projectPkgJson = await readPackageJSON(serverRootDir).catch(() => ({}));
138
136
  for (const [pkgName, pkgVersions] of Object.entries(multiVersionPkgs)) {
@@ -159,12 +157,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
159
157
  for (const [version, parentPkgs] of versionEntires) {
160
158
  const pkg = tracedPackages[pkgName];
161
159
  const pkgDestPath = `.modernjs/${pkgName}@${version}/node_modules/${pkgName}`;
162
- await writePackage({
163
- pkg,
164
- version,
165
- projectDir: serverRootDir,
166
- _pkgPath: pkgDestPath
167
- });
160
+ await writePackage(pkg, version, serverRootDir, pkgDestPath);
168
161
  await linkPackage(pkgDestPath, `${pkgName}`, serverRootDir);
169
162
  for (const parentPkg of parentPkgs) {
170
163
  const parentPkgName = parentPkg.replace(/@[^@]+$/, "");
@@ -173,7 +166,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
173
166
  }
174
167
  }
175
168
  const outputPkgPath = path.join(serverRootDir, "package.json");
176
- const newPkgJson = {
169
+ await fse.writeJSON(outputPkgPath, {
177
170
  name: `${projectPkgJson.name || "modernjs-project"}-prod`,
178
171
  version: projectPkgJson.version || "0.0.0",
179
172
  private: true,
@@ -183,9 +176,7 @@ const handleDependencies = async ({ appDir, serverRootDir, includeEntries, trace
183
176
  Object.keys(pkg.versions)[0]
184
177
  ])
185
178
  ].sort(([a], [b]) => a.localeCompare(b)))
186
- };
187
- const finalPkgJson = (modifyPackageJson === null || modifyPackageJson === void 0 ? void 0 : modifyPackageJson(newPkgJson)) || newPkgJson;
188
- await fse.writeJSON(outputPkgPath, finalPkgJson);
179
+ });
189
180
  };
190
181
  export {
191
182
  handleDependencies
@@ -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 } from "@vercel/nft";
5
+ import { nodeFileTrace, resolve } 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) {
@@ -10,8 +10,7 @@ function applyPublicCondition(pkg) {
10
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
11
  }
12
12
  }
13
- const writePackage = async (options) => {
14
- const { pkg, version, projectDir, _pkgPath } = options;
13
+ const writePackage = async (pkg, version, projectDir, _pkgPath) => {
15
14
  const pkgPath = _pkgPath || pkg.name;
16
15
  for (const src of pkg.versions[version].files) {
17
16
  if (src.includes("node_modules")) {
@@ -85,24 +84,31 @@ const findEntryFiles = async (rootDir, entryFilter) => {
85
84
  const findPackageParents = (pkg, version, tracedFiles) => {
86
85
  const versionFiles = pkg.versions[version].files.map((path2) => tracedFiles[path2]);
87
86
  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
- )))
87
+ ...new Set(versionFiles.flatMap((file) => file.parents.map((parentPath) => {
88
+ const parentFile = tracedFiles[parentPath];
89
+ if (!parentFile || parentFile.pkgName === pkg.name) {
90
+ return null;
91
+ }
92
+ return `${parentFile.pkgName}@${parentFile.pkgVersion}`;
93
+ }).filter(Boolean)))
98
94
  ];
99
- return parentPkgs.filter((parentPkg) => parentPkg);
95
+ return parentPkgs;
100
96
  };
101
97
  const traceFiles = async (entryFiles, serverRootDir, base = "/") => {
102
98
  return await nodeFileTrace(entryFiles, {
103
99
  base,
104
100
  processCwd: serverRootDir,
105
- cache: /* @__PURE__ */ Object.create(null)
101
+ resolve: async (id, parent, job, isCjs) => {
102
+ if (id.startsWith("@modern-js/prod-server")) {
103
+ return require.resolve(id, {
104
+ paths: [
105
+ require.resolve("@modern-js/app-tools")
106
+ ]
107
+ });
108
+ } else {
109
+ return resolve(id, parent, job, isCjs);
110
+ }
111
+ }
106
112
  });
107
113
  };
108
114
  const resolveTracedPath = async (base, p) => fse.realpath(path.resolve(base, p));
@@ -91,13 +91,9 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
91
91
  if (!needModernServer) {
92
92
  return;
93
93
  }
94
- await handleDependencies({
95
- appDir: appDirectory,
96
- serverRootDir: funcsDirectory,
97
- includeEntries: [
98
- require.resolve("@modern-js/prod-server")
99
- ]
100
- });
94
+ await handleDependencies(appDirectory, funcsDirectory, [
95
+ "@modern-js/prod-server"
96
+ ]);
101
97
  }
102
98
  };
103
99
  };
@@ -45,14 +45,9 @@ const createNodePreset = (appContext, config) => {
45
45
  const filter = (filePath) => {
46
46
  return !filePath.startsWith(staticDirectory);
47
47
  };
48
- await handleDependencies({
49
- appDir: appDirectory,
50
- serverRootDir: outputDirectory,
51
- includeEntries: [
52
- require.resolve("@modern-js/prod-server")
53
- ],
54
- entryFilter: filter
55
- });
48
+ await handleDependencies(appDirectory, outputDirectory, [
49
+ "@modern-js/prod-server"
50
+ ], filter);
56
51
  }
57
52
  };
58
53
  };
@@ -103,13 +103,9 @@ const createVercelPreset = (appContext, modernConfig, needModernServer) => {
103
103
  if (!needModernServer) {
104
104
  return;
105
105
  }
106
- await handleDependencies({
107
- appDir: appDirectory,
108
- serverRootDir: funcsDirectory,
109
- includeEntries: [
110
- require.resolve("@modern-js/prod-server")
111
- ]
112
- });
106
+ await handleDependencies(appDirectory, funcsDirectory, [
107
+ "@modern-js/prod-server"
108
+ ]);
113
109
  }
114
110
  };
115
111
  };
@@ -1,17 +1,18 @@
1
1
  import { loadServerPlugins as loadServerPluginInstances } from "@modern-js/prod-server";
2
- async function getServerPlugins(api) {
2
+ async function getServerPlugins(api, metaName = "modern-js") {
3
3
  const runner = api.useHookRunners();
4
4
  const { plugins } = await runner._internalServerPlugins({
5
5
  plugins: []
6
6
  });
7
+ const filtedPlugins = plugins.filter((plugin) => plugin.name.includes(metaName));
7
8
  api.setAppContext({
8
9
  ...api.useAppContext(),
9
- serverPlugins: plugins
10
+ serverPlugins: filtedPlugins
10
11
  });
11
- return plugins;
12
+ return filtedPlugins;
12
13
  }
13
- async function loadServerPlugins(api, appDirectory) {
14
- const plugins = await getServerPlugins(api);
14
+ async function loadServerPlugins(api, appDirectory, metaName) {
15
+ const plugins = await getServerPlugins(api, metaName);
15
16
  const instances = loadServerPluginInstances(plugins, appDirectory);
16
17
  return instances;
17
18
  }
@@ -1,11 +1 @@
1
- import type { PackageJson } from 'pkg-types';
2
- import { traceFiles as defaultTraceFiles } from './utils';
3
- export declare const handleDependencies: ({ appDir, serverRootDir, includeEntries, traceFiles, entryFilter, modifyPackageJson, copyWholePackage, }: {
4
- appDir: string;
5
- serverRootDir: string;
6
- includeEntries: string[];
7
- traceFiles?: ((entryFiles: string[], serverRootDir: string, base?: string) => Promise<import("@vercel/nft").NodeFileTraceResult>) | undefined;
8
- entryFilter?: ((filePath: string) => boolean) | undefined;
9
- modifyPackageJson?: ((pkgJson: PackageJson) => PackageJson) | undefined;
10
- copyWholePackage?: ((pkgName: string) => boolean) | undefined;
11
- }) => Promise<void>;
1
+ export declare const handleDependencies: (appDir: string, serverRootDir: string, include: string[], entryFilter?: ((filePath: string) => boolean) | undefined) => Promise<void>;
@@ -17,13 +17,7 @@ export type TracedFile = {
17
17
  pkgName: string;
18
18
  pkgVersion?: string;
19
19
  };
20
- interface WritePackageOptions {
21
- pkg: TracedPackage;
22
- version: string;
23
- projectDir: string;
24
- _pkgPath?: string;
25
- }
26
- export declare const writePackage: (options: WritePackageOptions) => Promise<void>;
20
+ export declare const writePackage: (pkg: TracedPackage, version: string, projectDir: string, _pkgPath?: string) => Promise<void>;
27
21
  export declare const linkPackage: (from: string, to: string, projectRootDir: string) => Promise<void>;
28
22
  interface ReadDirOptions {
29
23
  filter?: (filePath: string) => boolean;
@@ -1,5 +1,5 @@
1
1
  import { ServerPlugin as ServerPluginInstance } from '@modern-js/server-core';
2
2
  import { ServerPlugin } from '@modern-js/types';
3
3
  import { AppTools, PluginAPI } from '../types';
4
- export declare function getServerPlugins(api: PluginAPI<AppTools<'shared'>>): Promise<ServerPlugin[]>;
5
- export declare function loadServerPlugins(api: PluginAPI<AppTools<'shared'>>, appDirectory: string): Promise<ServerPluginInstance[]>;
4
+ export declare function getServerPlugins(api: PluginAPI<AppTools<'shared'>>, metaName?: string): Promise<ServerPlugin[]>;
5
+ export declare function loadServerPlugins(api: PluginAPI<AppTools<'shared'>>, appDirectory: string, metaName: string): Promise<ServerPluginInstance[]>;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.54.2-alpha.3",
18
+ "version": "2.54.2",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -43,11 +43,6 @@
43
43
  "types": "./dist/types/exports/server.d.ts",
44
44
  "jsnext:source": "./src/exports/server.ts",
45
45
  "default": "./dist/cjs/exports/server.js"
46
- },
47
- "./deploy": {
48
- "types": "./dist/types/plugins/deploy/exports.d.ts",
49
- "jsnext:source": "./src/plugins/deploy/exports.ts",
50
- "default": "./dist/cjs/plugins/deploy/exports.js"
51
46
  }
52
47
  },
53
48
  "engines": {
@@ -63,9 +58,6 @@
63
58
  ],
64
59
  "server": [
65
60
  "./dist/types/exports/server.d.ts"
66
- ],
67
- "deploy": [
68
- "./dist/types/plugins/deploy/exports.d.ts"
69
61
  ]
70
62
  }
71
63
  },
@@ -88,20 +80,20 @@
88
80
  "mlly": "^1.6.1",
89
81
  "pkg-types": "^1.1.0",
90
82
  "std-env": "^3.7.0",
91
- "@modern-js/core": "2.54.1",
92
- "@modern-js/plugin-data-loader": "2.54.1",
93
- "@modern-js/plugin-i18n": "2.54.1",
94
- "@modern-js/plugin-lint": "2.54.1",
95
- "@modern-js/rsbuild-plugin-esbuild": "2.54.1",
96
- "@modern-js/prod-server": "2.54.1",
97
- "@modern-js/server": "2.54.1",
98
- "@modern-js/server-core": "2.54.1",
99
- "@modern-js/server-utils": "2.54.1",
100
- "@modern-js/node-bundle-require": "2.54.1",
101
- "@modern-js/plugin": "2.54.1",
102
- "@modern-js/uni-builder": "2.54.1",
103
- "@modern-js/types": "2.54.1",
104
- "@modern-js/utils": "2.54.1"
83
+ "@modern-js/core": "2.54.2",
84
+ "@modern-js/node-bundle-require": "2.54.2",
85
+ "@modern-js/plugin": "2.54.2",
86
+ "@modern-js/plugin-i18n": "2.54.2",
87
+ "@modern-js/plugin-data-loader": "2.54.2",
88
+ "@modern-js/plugin-lint": "2.54.2",
89
+ "@modern-js/prod-server": "2.54.2",
90
+ "@modern-js/rsbuild-plugin-esbuild": "2.54.2",
91
+ "@modern-js/server": "2.54.2",
92
+ "@modern-js/server-core": "2.54.2",
93
+ "@modern-js/server-utils": "2.54.2",
94
+ "@modern-js/types": "2.54.2",
95
+ "@modern-js/uni-builder": "2.54.2",
96
+ "@modern-js/utils": "2.54.2"
105
97
  },
106
98
  "devDependencies": {
107
99
  "@rsbuild/plugin-swc": "0.7.9",
@@ -113,8 +105,8 @@
113
105
  "tsconfig-paths": "^4.2.0",
114
106
  "typescript": "^5",
115
107
  "webpack": "^5.92.0",
116
- "@scripts/build": "2.54.1",
117
- "@scripts/jest-config": "2.54.1"
108
+ "@scripts/build": "2.54.2",
109
+ "@scripts/jest-config": "2.54.2"
118
110
  },
119
111
  "sideEffects": false,
120
112
  "publishConfig": {
@@ -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
- });
@@ -1,4 +0,0 @@
1
- import { handleDependencies } from "./dependencies";
2
- export {
3
- handleDependencies
4
- };
@@ -1,4 +0,0 @@
1
- import { handleDependencies } from "./dependencies";
2
- export {
3
- handleDependencies
4
- };
@@ -1,15 +0,0 @@
1
- export const JS_EXTENSIONS = ['.js', '.ts', '.jsx', '.tsx'];
2
- export const INDEX_FILE_NAME = 'index';
3
- export const APP_FILE_NAME = 'App';
4
- export const PAGES_DIR_NAME = 'pages';
5
- export const FILE_SYSTEM_ROUTES_FILE_NAME = 'routes.js';
6
- export const ENTRY_POINT_FILE_NAME = 'index.js';
7
- export const ENTRY_BOOTSTRAP_FILE_NAME = 'bootstrap.js';
8
- export const FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP = /^\[(\S+)\]([*+?]?)$/;
9
- export const FILE_SYSTEM_ROUTES_LAYOUT = '_layout';
10
- export const FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT = '_app';
11
- export const FILE_SYSTEM_ROUTES_INDEX = 'index';
12
- export const FILE_SYSTEM_ROUTES_IGNORED_REGEX = /\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/;
13
- export const HTML_PARTIALS_FOLDER = 'html';
14
- export const HTML_PARTIALS_EXTENSIONS = ['.htm', '.html', '.ejs'];
15
- export const FILE_SYSTEM_ROUTES_COMPONENTS_DIR = 'internal_components';