@modern-js/app-tools 2.49.3-alpha.9 → 2.49.4

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.
Files changed (43) hide show
  1. package/dist/cjs/analyze/getServerRoutes.js +3 -4
  2. package/dist/cjs/index.js +1 -3
  3. package/dist/cjs/utils/routes.js +2 -7
  4. package/dist/esm/analyze/getServerRoutes.js +4 -5
  5. package/dist/esm/index.js +1 -3
  6. package/dist/esm/utils/routes.js +2 -6
  7. package/dist/esm-node/analyze/getServerRoutes.js +4 -5
  8. package/dist/esm-node/index.js +1 -3
  9. package/dist/esm-node/utils/routes.js +2 -6
  10. package/dist/types/utils/routes.d.ts +3 -3
  11. package/package.json +22 -26
  12. package/dist/cjs/plugins/deploy/dependencies.js +0 -256
  13. package/dist/cjs/plugins/deploy/index.js +0 -215
  14. package/dist/cjs/plugins/deploy/platforms/netlify.js +0 -95
  15. package/dist/cjs/plugins/deploy/platforms/node.js +0 -88
  16. package/dist/cjs/plugins/deploy/platforms/platform.js +0 -16
  17. package/dist/cjs/plugins/deploy/platforms/vercel.js +0 -57
  18. package/dist/cjs/plugins/deploy/platforms/vercelEntry.js +0 -55
  19. package/dist/cjs/plugins/deploy/utils.js +0 -150
  20. package/dist/esm/plugins/deploy/dependencies.js +0 -725
  21. package/dist/esm/plugins/deploy/index.js +0 -356
  22. package/dist/esm/plugins/deploy/platforms/netlify.js +0 -41
  23. package/dist/esm/plugins/deploy/platforms/node.js +0 -39
  24. package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
  25. package/dist/esm/plugins/deploy/platforms/vercel.js +0 -47
  26. package/dist/esm/plugins/deploy/platforms/vercelEntry.js +0 -197
  27. package/dist/esm/plugins/deploy/utils.js +0 -244
  28. package/dist/esm-node/plugins/deploy/dependencies.js +0 -222
  29. package/dist/esm-node/plugins/deploy/index.js +0 -185
  30. package/dist/esm-node/plugins/deploy/platforms/netlify.js +0 -71
  31. package/dist/esm-node/plugins/deploy/platforms/node.js +0 -64
  32. package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
  33. package/dist/esm-node/plugins/deploy/platforms/vercel.js +0 -23
  34. package/dist/esm-node/plugins/deploy/platforms/vercelEntry.js +0 -63
  35. package/dist/esm-node/plugins/deploy/utils.js +0 -109
  36. package/dist/types/plugins/deploy/dependencies.d.ts +0 -1
  37. package/dist/types/plugins/deploy/index.d.ts +0 -4
  38. package/dist/types/plugins/deploy/platforms/netlify.d.ts +0 -5
  39. package/dist/types/plugins/deploy/platforms/node.d.ts +0 -5
  40. package/dist/types/plugins/deploy/platforms/platform.d.ts +0 -1
  41. package/dist/types/plugins/deploy/platforms/vercel.d.ts +0 -5
  42. package/dist/types/plugins/deploy/platforms/vercelEntry.d.ts +0 -2
  43. package/dist/types/plugins/deploy/utils.d.ts +0 -27
@@ -34,7 +34,6 @@ module.exports = __toCommonJS(getServerRoutes_exports);
34
34
  var import_path = __toESM(require("path"));
35
35
  var import_fs = __toESM(require("fs"));
36
36
  var import_utils = require("@modern-js/utils");
37
- var import_routes = require("../utils/routes");
38
37
  var import_utils2 = require("./utils");
39
38
  const applyBaseUrl = (baseUrl, routes) => {
40
39
  if (baseUrl) {
@@ -107,14 +106,14 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
107
106
  const { packageName } = appContext;
108
107
  const workerSSR = deploy === null || deploy === void 0 ? void 0 : (_deploy_worker = deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
109
108
  let htmlRoutes = entrypoints.reduce((previous, { entryName }) => {
110
- const isMain = (0, import_routes.isMainEntry)(entryName, mainEntryName);
111
- const entryOptions = (0, import_utils.getEntryOptions)(entryName, isMain, ssr, ssrByEntries, packageName);
109
+ const isMainEntry = entryName === (mainEntryName || import_utils.MAIN_ENTRY_NAME);
110
+ const entryOptions = (0, import_utils.getEntryOptions)(entryName, isMainEntry, ssr, ssrByEntries, packageName);
112
111
  const isSSR = Boolean(entryOptions);
113
112
  const isWorker = Boolean(workerSSR);
114
113
  const isStream = typeof entryOptions === "object" && (entryOptions.mode === "stream" || Boolean(entryOptions.preload));
115
114
  const { resHeaders } = (routes === null || routes === void 0 ? void 0 : routes[entryName]) || {};
116
115
  let route = {
117
- urlPath: `/${isMain ? "" : entryName}`,
116
+ urlPath: `/${isMainEntry ? "" : entryName}`,
118
117
  entryName,
119
118
  entryPath: (0, import_utils.removeLeadingSlash)(import_path.default.posix.normalize(`${htmlPath}/${entryName}${disableHtmlFolder ? ".html" : "/index.html"}`)),
120
119
  isSPA: true,
package/dist/cjs/index.js CHANGED
@@ -47,7 +47,6 @@ var import_initialize = __toESM(require("./initialize"));
47
47
  var import_hooks = require("./hooks");
48
48
  var import_locale = require("./locale");
49
49
  var import_serverBuild = __toESM(require("./plugins/serverBuild"));
50
- var import_deploy = __toESM(require("./plugins/deploy"));
51
50
  var import_restart = require("./utils/restart");
52
51
  var import_generateWatchFiles = require("./utils/generateWatchFiles");
53
52
  var import_core = require("@modern-js/core");
@@ -121,8 +120,7 @@ const appTools = (options = {
121
120
  bundler: (options === null || options === void 0 ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
122
121
  }),
123
122
  (0, import_serverBuild.default)(),
124
- (0, import_plugin_lint.lintPlugin)(),
125
- (0, import_deploy.default)()
123
+ (0, import_plugin_lint.lintPlugin)()
126
124
  ],
127
125
  setup: (api) => {
128
126
  const appContext = api.useAppContext();
@@ -29,8 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  var routes_exports = {};
30
30
  __export(routes_exports, {
31
31
  generateRoutes: () => generateRoutes,
32
- getPathWithoutExt: () => getPathWithoutExt,
33
- isMainEntry: () => isMainEntry
32
+ getPathWithoutExt: () => getPathWithoutExt
34
33
  });
35
34
  module.exports = __toCommonJS(routes_exports);
36
35
  var import_path = __toESM(require("path"));
@@ -46,12 +45,8 @@ const getPathWithoutExt = (filename) => {
46
45
  const extname = import_path.default.extname(filename);
47
46
  return filename.slice(0, -extname.length);
48
47
  };
49
- const isMainEntry = (entryName, mainEntryName) => {
50
- return entryName === (mainEntryName || import_utils.MAIN_ENTRY_NAME);
51
- };
52
48
  // Annotate the CommonJS export names for ESM import in node:
53
49
  0 && (module.exports = {
54
50
  generateRoutes,
55
- getPathWithoutExt,
56
- isMainEntry
51
+ getPathWithoutExt
57
52
  });
@@ -4,8 +4,7 @@ import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_
4
4
  import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
5
5
  import path from "path";
6
6
  import fs from "fs";
7
- import { urlJoin, isPlainObject, removeLeadingSlash, getEntryOptions, SERVER_BUNDLE_DIRECTORY, removeTailSlash, SERVER_WORKER_BUNDLE_DIRECTORY } from "@modern-js/utils";
8
- import { isMainEntry } from "../utils/routes";
7
+ import { urlJoin, isPlainObject, removeLeadingSlash, getEntryOptions, SERVER_BUNDLE_DIRECTORY, MAIN_ENTRY_NAME, removeTailSlash, SERVER_WORKER_BUNDLE_DIRECTORY } from "@modern-js/utils";
9
8
  import { walkDirectory } from "./utils";
10
9
  var applyBaseUrl = function(baseUrl, routes) {
11
10
  if (baseUrl) {
@@ -76,14 +75,14 @@ var collectHtmlRoutes = function(entrypoints, appContext, config) {
76
75
  var workerSSR = deploy === null || deploy === void 0 ? void 0 : (_deploy_worker = deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
77
76
  var htmlRoutes = entrypoints.reduce(function(previous, param) {
78
77
  var entryName = param.entryName;
79
- var isMain = isMainEntry(entryName, mainEntryName);
80
- var entryOptions = getEntryOptions(entryName, isMain, ssr, ssrByEntries, packageName);
78
+ var isMainEntry = entryName === (mainEntryName || MAIN_ENTRY_NAME);
79
+ var entryOptions = getEntryOptions(entryName, isMainEntry, ssr, ssrByEntries, packageName);
81
80
  var isSSR = Boolean(entryOptions);
82
81
  var isWorker = Boolean(workerSSR);
83
82
  var isStream = typeof entryOptions === "object" && (entryOptions.mode === "stream" || Boolean(entryOptions.preload));
84
83
  var resHeaders = ((routes === null || routes === void 0 ? void 0 : routes[entryName]) || {}).resHeaders;
85
84
  var route = {
86
- urlPath: "/".concat(isMain ? "" : entryName),
85
+ urlPath: "/".concat(isMainEntry ? "" : entryName),
87
86
  entryName,
88
87
  entryPath: removeLeadingSlash(path.posix.normalize("".concat(htmlPath, "/").concat(entryName).concat(disableHtmlFolder ? ".html" : "/index.html"))),
89
88
  isSPA: true,
package/dist/esm/index.js CHANGED
@@ -12,7 +12,6 @@ import initializePlugin from "./initialize";
12
12
  import { hooks } from "./hooks";
13
13
  import { i18n, localeKeys } from "./locale";
14
14
  import serverBuildPlugin from "./plugins/serverBuild";
15
- import deployPlugin from "./plugins/deploy";
16
15
  import { restart } from "./utils/restart";
17
16
  import { generateWatchFiles } from "./utils/generateWatchFiles";
18
17
  import { mergeConfig } from "@modern-js/core";
@@ -296,8 +295,7 @@ var appTools = function() {
296
295
  bundler: (options === null || options === void 0 ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
297
296
  }),
298
297
  serverBuildPlugin(),
299
- lintPlugin(),
300
- deployPlugin()
298
+ lintPlugin()
301
299
  ],
302
300
  setup: function(api) {
303
301
  var appContext = api.useAppContext();
@@ -1,7 +1,7 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import path from "path";
4
- import { fs, MAIN_ENTRY_NAME, ROUTE_SPEC_FILE } from "@modern-js/utils";
4
+ import { fs, ROUTE_SPEC_FILE } from "@modern-js/utils";
5
5
  var generateRoutes = function() {
6
6
  var _ref = _async_to_generator(function(appContext) {
7
7
  var serverRoutes, distDirectory, output;
@@ -32,11 +32,7 @@ var getPathWithoutExt = function(filename) {
32
32
  var extname = path.extname(filename);
33
33
  return filename.slice(0, -extname.length);
34
34
  };
35
- var isMainEntry = function(entryName, mainEntryName) {
36
- return entryName === (mainEntryName || MAIN_ENTRY_NAME);
37
- };
38
35
  export {
39
36
  generateRoutes,
40
- getPathWithoutExt,
41
- isMainEntry
37
+ getPathWithoutExt
42
38
  };
@@ -1,7 +1,6 @@
1
1
  import path from "path";
2
2
  import fs from "fs";
3
- import { urlJoin, isPlainObject, removeLeadingSlash, getEntryOptions, SERVER_BUNDLE_DIRECTORY, removeTailSlash, SERVER_WORKER_BUNDLE_DIRECTORY } from "@modern-js/utils";
4
- import { isMainEntry } from "../utils/routes";
3
+ import { urlJoin, isPlainObject, removeLeadingSlash, getEntryOptions, SERVER_BUNDLE_DIRECTORY, MAIN_ENTRY_NAME, removeTailSlash, SERVER_WORKER_BUNDLE_DIRECTORY } from "@modern-js/utils";
5
4
  import { walkDirectory } from "./utils";
6
5
  const applyBaseUrl = (baseUrl, routes) => {
7
6
  if (baseUrl) {
@@ -74,14 +73,14 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
74
73
  const { packageName } = appContext;
75
74
  const workerSSR = deploy === null || deploy === void 0 ? void 0 : (_deploy_worker = deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
76
75
  let htmlRoutes = entrypoints.reduce((previous, { entryName }) => {
77
- const isMain = isMainEntry(entryName, mainEntryName);
78
- const entryOptions = getEntryOptions(entryName, isMain, ssr, ssrByEntries, packageName);
76
+ const isMainEntry = entryName === (mainEntryName || MAIN_ENTRY_NAME);
77
+ const entryOptions = getEntryOptions(entryName, isMainEntry, ssr, ssrByEntries, packageName);
79
78
  const isSSR = Boolean(entryOptions);
80
79
  const isWorker = Boolean(workerSSR);
81
80
  const isStream = typeof entryOptions === "object" && (entryOptions.mode === "stream" || Boolean(entryOptions.preload));
82
81
  const { resHeaders } = (routes === null || routes === void 0 ? void 0 : routes[entryName]) || {};
83
82
  let route = {
84
- urlPath: `/${isMain ? "" : entryName}`,
83
+ urlPath: `/${isMainEntry ? "" : entryName}`,
85
84
  entryName,
86
85
  entryPath: removeLeadingSlash(path.posix.normalize(`${htmlPath}/${entryName}${disableHtmlFolder ? ".html" : "/index.html"}`)),
87
86
  isSPA: true,
@@ -8,7 +8,6 @@ import initializePlugin from "./initialize";
8
8
  import { hooks } from "./hooks";
9
9
  import { i18n, localeKeys } from "./locale";
10
10
  import serverBuildPlugin from "./plugins/serverBuild";
11
- import deployPlugin from "./plugins/deploy";
12
11
  import { restart } from "./utils/restart";
13
12
  import { generateWatchFiles } from "./utils/generateWatchFiles";
14
13
  import { mergeConfig } from "@modern-js/core";
@@ -82,8 +81,7 @@ const appTools = (options = {
82
81
  bundler: (options === null || options === void 0 ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
83
82
  }),
84
83
  serverBuildPlugin(),
85
- lintPlugin(),
86
- deployPlugin()
84
+ lintPlugin()
87
85
  ],
88
86
  setup: (api) => {
89
87
  const appContext = api.useAppContext();
@@ -1,5 +1,5 @@
1
1
  import path from "path";
2
- import { fs, MAIN_ENTRY_NAME, ROUTE_SPEC_FILE } from "@modern-js/utils";
2
+ import { fs, ROUTE_SPEC_FILE } from "@modern-js/utils";
3
3
  const generateRoutes = async (appContext) => {
4
4
  const { serverRoutes, distDirectory } = appContext;
5
5
  const output = JSON.stringify({
@@ -11,11 +11,7 @@ const getPathWithoutExt = (filename) => {
11
11
  const extname = path.extname(filename);
12
12
  return filename.slice(0, -extname.length);
13
13
  };
14
- const isMainEntry = (entryName, mainEntryName) => {
15
- return entryName === (mainEntryName || MAIN_ENTRY_NAME);
16
- };
17
14
  export {
18
15
  generateRoutes,
19
- getPathWithoutExt,
20
- isMainEntry
16
+ getPathWithoutExt
21
17
  };
@@ -1,4 +1,4 @@
1
1
  import type { IAppContext } from '@modern-js/core';
2
- export declare const generateRoutes: (appContext: IAppContext) => Promise<void>;
3
- export declare const getPathWithoutExt: (filename: string) => string;
4
- export declare const isMainEntry: (entryName: string, mainEntryName?: string) => boolean;
2
+ declare const generateRoutes: (appContext: IAppContext) => Promise<void>;
3
+ declare const getPathWithoutExt: (filename: string) => string;
4
+ export { generateRoutes, getPathWithoutExt };
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.49.3-alpha.9",
18
+ "version": "2.49.4",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -69,34 +69,30 @@
69
69
  "@babel/parser": "^7.22.15",
70
70
  "@babel/traverse": "^7.23.2",
71
71
  "@babel/types": "^7.23.0",
72
- "@rsbuild/plugin-node-polyfill": "0.6.10",
73
- "@rsbuild/shared": "0.6.10",
74
- "@rsbuild/core": "0.6.10",
75
- "@swc/helpers": "0.5.3",
76
- "@vercel/nft": "^0.26.4",
72
+ "@rsbuild/plugin-node-polyfill": "0.6.15",
73
+ "@rsbuild/shared": "0.6.15",
74
+ "@rsbuild/core": "0.6.15",
77
75
  "es-module-lexer": "^1.1.0",
78
76
  "esbuild": "0.17.19",
77
+ "@swc/helpers": "0.5.3",
79
78
  "esbuild-register": "^3.5.0",
80
- "mlly": "^1.6.1",
81
- "pkg-types": "^1.1.0",
82
- "std-env": "^3.7.0",
83
- "@modern-js/node-bundle-require": "2.49.2",
84
- "@modern-js/plugin-data-loader": "2.49.2",
85
- "@modern-js/plugin-lint": "2.49.2",
86
- "@modern-js/plugin": "2.49.2",
87
- "@modern-js/core": "2.49.2",
88
- "@modern-js/server": "2.49.2",
89
- "@modern-js/plugin-i18n": "2.49.2",
90
- "@modern-js/server-utils": "2.49.2",
91
- "@modern-js/prod-server": "2.49.2",
92
- "@modern-js/server-core": "2.49.2",
93
- "@modern-js/rsbuild-plugin-esbuild": "2.49.2",
94
- "@modern-js/types": "2.49.2",
95
- "@modern-js/utils": "2.49.2",
96
- "@modern-js/uni-builder": "2.49.2"
79
+ "@modern-js/core": "2.49.4",
80
+ "@modern-js/node-bundle-require": "2.49.4",
81
+ "@modern-js/plugin": "2.49.4",
82
+ "@modern-js/plugin-i18n": "2.49.4",
83
+ "@modern-js/plugin-data-loader": "2.49.4",
84
+ "@modern-js/prod-server": "2.49.4",
85
+ "@modern-js/plugin-lint": "2.49.4",
86
+ "@modern-js/server": "2.49.4",
87
+ "@modern-js/server-core": "2.49.4",
88
+ "@modern-js/types": "2.49.4",
89
+ "@modern-js/server-utils": "2.49.4",
90
+ "@modern-js/uni-builder": "2.49.4",
91
+ "@modern-js/utils": "2.49.4",
92
+ "@modern-js/rsbuild-plugin-esbuild": "2.49.4"
97
93
  },
98
94
  "devDependencies": {
99
- "@rsbuild/plugin-swc": "0.6.10",
95
+ "@rsbuild/plugin-swc": "0.6.15",
100
96
  "@types/babel__traverse": "7.18.5",
101
97
  "@types/jest": "^29",
102
98
  "@types/node": "^14",
@@ -105,8 +101,8 @@
105
101
  "tsconfig-paths": "^4.2.0",
106
102
  "typescript": "^5",
107
103
  "webpack": "^5.91.0",
108
- "@scripts/build": "2.49.2",
109
- "@scripts/jest-config": "2.49.2"
104
+ "@scripts/build": "2.49.4",
105
+ "@scripts/jest-config": "2.49.4"
110
106
  },
111
107
  "sideEffects": false,
112
108
  "publishConfig": {
@@ -1,256 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var dependencies_exports = {};
30
- __export(dependencies_exports, {
31
- handleDependencies: () => handleDependencies
32
- });
33
- module.exports = __toCommonJS(dependencies_exports);
34
- var import_node_path = __toESM(require("node:path"));
35
- var import_nft = require("@vercel/nft");
36
- var import_utils = require("@modern-js/utils");
37
- var import_pkg_types = require("pkg-types");
38
- var import_mlly = require("mlly");
39
- var import_utils2 = require("./utils");
40
- const readDirRecursive = async (dir) => {
41
- const files = await import_utils.fs.readdir(dir, {
42
- withFileTypes: true
43
- });
44
- const filesAndDirs = await Promise.all(files.map(async (file) => {
45
- const resPath = import_node_path.default.resolve(dir, file.name);
46
- return file.isDirectory() ? readDirRecursive(resPath) : resPath;
47
- }));
48
- return filesAndDirs.flat();
49
- };
50
- async function isFile(file) {
51
- try {
52
- const stat = await import_utils.fs.stat(file);
53
- return stat.isFile();
54
- } catch (error) {
55
- if (error.code === "ENOENT") {
56
- return false;
57
- }
58
- throw error;
59
- }
60
- }
61
- const findEntryFiles = async (rootDir) => {
62
- const files = await readDirRecursive(rootDir);
63
- return files;
64
- };
65
- const handleDependencies = async (appDir, serverRootDir, include) => {
66
- const base = "/";
67
- const entryFiles = await findEntryFiles(serverRootDir);
68
- const includeEntries = include.map((item) => {
69
- if ((0, import_node_path.isAbsolute)(item)) {
70
- return item;
71
- }
72
- try {
73
- return require.resolve(item);
74
- } catch (error) {
75
- }
76
- return item;
77
- });
78
- const _fileTrace = await (0, import_nft.nodeFileTrace)(entryFiles.concat(includeEntries), {
79
- base,
80
- processCwd: serverRootDir,
81
- resolve: async (id, parent, job, isCjs) => {
82
- if (id.startsWith("@modern-js/prod-server")) {
83
- return require.resolve(id, {
84
- paths: [
85
- require.resolve("@modern-js/app-tools")
86
- ]
87
- });
88
- } else {
89
- return (0, import_nft.resolve)(id, parent, job, isCjs);
90
- }
91
- }
92
- });
93
- const currentProjectModules = import_node_path.default.join(appDir, "node_modules");
94
- const _resolveTracedPath = (p) => import_utils.fs.realpath(import_node_path.default.resolve(base, p));
95
- const tracedFiles = Object.fromEntries(await Promise.all([
96
- ..._fileTrace.reasons.entries()
97
- ].map(async ([_path, reasons]) => {
98
- if (reasons.ignored) {
99
- return;
100
- }
101
- const filePath = await _resolveTracedPath(_path);
102
- if (filePath.startsWith(serverRootDir) || filePath.startsWith(appDir) && !filePath.startsWith(currentProjectModules)) {
103
- return;
104
- }
105
- if (!await isFile(filePath)) {
106
- return;
107
- }
108
- let baseDir;
109
- let pkgName;
110
- let subpath;
111
- let pkgPath;
112
- if (filePath.includes("node_modules")) {
113
- const parsed = (0, import_mlly.parseNodeModulePath)(filePath);
114
- baseDir = parsed.dir;
115
- pkgName = parsed.name;
116
- subpath = parsed.subpath;
117
- pkgPath = import_node_path.default.join(baseDir, pkgName);
118
- } else {
119
- const MODERN_UTILS_PATH = "packages/toolkit/utils";
120
- const MODERN_UTILS_PATH_REGEX = new RegExp(`(.*${MODERN_UTILS_PATH})`);
121
- const match = filePath.match(MODERN_UTILS_PATH_REGEX);
122
- const packageJsonPath = match ? import_node_path.default.join(match[0], "package.json") : await (0, import_utils.pkgUp)({
123
- cwd: import_node_path.default.dirname(filePath)
124
- });
125
- if (packageJsonPath) {
126
- const packageJson = await import_utils.fs.readJSON(packageJsonPath);
127
- pkgPath = baseDir = import_node_path.default.dirname(packageJsonPath);
128
- subpath = import_node_path.default.relative(baseDir, filePath);
129
- pkgName = packageJson.name;
130
- }
131
- }
132
- if (!baseDir) {
133
- return;
134
- }
135
- const parents = await Promise.all([
136
- ...reasons.parents
137
- ].map((p) => _resolveTracedPath(p)));
138
- const tracedFile = {
139
- path: filePath,
140
- parents,
141
- subpath,
142
- pkgName,
143
- pkgPath
144
- };
145
- return [
146
- filePath,
147
- tracedFile
148
- ];
149
- })).then((r) => r.filter(Boolean)));
150
- const tracedPackages = {};
151
- for (const tracedFile of Object.values(tracedFiles)) {
152
- const { pkgName } = tracedFile;
153
- let tracedPackage = tracedPackages[pkgName];
154
- let pkgJSON = await (0, import_pkg_types.readPackageJSON)(tracedFile.pkgPath, {
155
- cache: true
156
- }).catch(() => {
157
- });
158
- if (!pkgJSON) {
159
- pkgJSON = {
160
- name: pkgName,
161
- version: "0.0.0"
162
- };
163
- }
164
- if (!tracedPackage) {
165
- tracedPackage = {
166
- name: pkgName,
167
- versions: {}
168
- };
169
- tracedPackages[pkgName] = tracedPackage;
170
- }
171
- let tracedPackageVersion = tracedPackage.versions[pkgJSON.version];
172
- if (!tracedPackageVersion) {
173
- tracedPackageVersion = {
174
- path: tracedFile.pkgPath,
175
- files: [],
176
- pkgJSON
177
- };
178
- tracedPackage.versions[pkgJSON.version] = tracedPackageVersion;
179
- }
180
- tracedFile.path.startsWith(tracedFile.pkgPath) && tracedPackageVersion.path === tracedFile.pkgPath && tracedPackageVersion.files.push(tracedFile.path);
181
- tracedFile.pkgName = pkgName;
182
- tracedFile.pkgVersion = pkgJSON.version;
183
- }
184
- const findPackageParents = (pkg, version) => {
185
- const versionFiles = pkg.versions[version].files.map((path2) => tracedFiles[path2]);
186
- const parentPkgs = [
187
- ...new Set(versionFiles.flatMap((file) => file.parents.map((parentPath) => {
188
- const parentFile = tracedFiles[parentPath];
189
- if (parentFile.pkgName === pkg.name) {
190
- return null;
191
- }
192
- return `${parentFile.pkgName}@${parentFile.pkgVersion}`;
193
- }).filter(Boolean)))
194
- ];
195
- return parentPkgs;
196
- };
197
- const multiVersionPkgs = {};
198
- const singleVersionPackages = [];
199
- for (const tracedPackage of Object.values(tracedPackages)) {
200
- const versions = Object.keys(tracedPackage.versions);
201
- if (versions.length === 1) {
202
- singleVersionPackages.push(tracedPackage.name);
203
- continue;
204
- }
205
- multiVersionPkgs[tracedPackage.name] = {};
206
- for (const version of versions) {
207
- multiVersionPkgs[tracedPackage.name][version] = findPackageParents(tracedPackage, version);
208
- }
209
- }
210
- await Promise.all(singleVersionPackages.map((pkgName) => {
211
- const pkg = tracedPackages[pkgName];
212
- const version = Object.keys(pkg.versions)[0];
213
- return (0, import_utils2.writePackage)(pkg, version, serverRootDir);
214
- }));
215
- console.log("multiVersionPkgs111111111", multiVersionPkgs);
216
- for (const [pkgName, pkgVersions] of Object.entries(multiVersionPkgs)) {
217
- const versionEntires = Object.entries(pkgVersions).sort(([v1, p1], [v2, p2]) => {
218
- if (p1.length === 0) {
219
- return -1;
220
- }
221
- if (p2.length === 0) {
222
- return 1;
223
- }
224
- return import_utils.semver.lt(v1, v2, {
225
- loose: true
226
- }) ? 1 : -1;
227
- });
228
- for (const [version, parentPkgs] of versionEntires) {
229
- const pkg = tracedPackages[pkgName];
230
- const pkgDestPath = `.modernjs/${pkgName}@${version}/node_modules/${pkgName}`;
231
- await (0, import_utils2.writePackage)(pkg, version, serverRootDir, pkgDestPath);
232
- await (0, import_utils2.linkPackage)(pkgDestPath, `${pkgName}`, serverRootDir);
233
- for (const parentPkg of parentPkgs) {
234
- const parentPkgName = parentPkg.replace(/@[^@]+$/, "");
235
- await (multiVersionPkgs[parentPkgName] ? (0, import_utils2.linkPackage)(pkgDestPath, `.modernjs/${parentPkg}/node_modules/${pkgName}`, serverRootDir) : (0, import_utils2.linkPackage)(pkgDestPath, `${parentPkgName}/node_modules/${pkgName}`, serverRootDir));
236
- }
237
- }
238
- }
239
- const projectPkg = await (0, import_pkg_types.readPackageJSON)(serverRootDir).catch(() => ({}));
240
- const outputPkgPath = import_node_path.default.join(serverRootDir, "package.json");
241
- await import_utils.fs.writeJSON(outputPkgPath, {
242
- name: `${projectPkg.name || "modernjs-project"}-prod`,
243
- version: projectPkg.version || "0.0.0",
244
- private: true,
245
- dependencies: Object.fromEntries([
246
- ...Object.values(tracedPackages).map((pkg) => [
247
- pkg.name,
248
- Object.keys(pkg.versions)[0]
249
- ])
250
- ].sort(([a], [b]) => a.localeCompare(b)))
251
- });
252
- };
253
- // Annotate the CommonJS export names for ESM import in node:
254
- 0 && (module.exports = {
255
- handleDependencies
256
- });