@modern-js/app-tools 2.48.6 → 2.49.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.
Files changed (52) hide show
  1. package/dist/cjs/builder/builder-webpack/index.js +1 -1
  2. package/dist/cjs/commands/build.js +3 -0
  3. package/dist/cjs/commands/dev.js +16 -16
  4. package/dist/cjs/commands/serve.js +14 -22
  5. package/dist/cjs/index.js +3 -1
  6. package/dist/cjs/plugins/deploy/dependencies.js +257 -0
  7. package/dist/cjs/plugins/deploy/entrys/netlify.js +95 -0
  8. package/dist/cjs/plugins/deploy/entrys/node.js +88 -0
  9. package/dist/cjs/plugins/deploy/entrys/vercel.js +95 -0
  10. package/dist/cjs/plugins/deploy/index.js +140 -0
  11. package/dist/cjs/plugins/deploy/utils.js +150 -0
  12. package/dist/cjs/utils/createServer.js +5 -27
  13. package/dist/cjs/utils/env.js +2 -2
  14. package/dist/cjs/utils/register.js +103 -0
  15. package/dist/esm/builder/builder-webpack/index.js +1 -1
  16. package/dist/esm/commands/build.js +16 -9
  17. package/dist/esm/commands/dev.js +34 -38
  18. package/dist/esm/commands/serve.js +28 -32
  19. package/dist/esm/index.js +3 -1
  20. package/dist/esm/plugins/deploy/dependencies.js +726 -0
  21. package/dist/esm/plugins/deploy/entrys/netlify.js +41 -0
  22. package/dist/esm/plugins/deploy/entrys/node.js +39 -0
  23. package/dist/esm/plugins/deploy/entrys/vercel.js +41 -0
  24. package/dist/esm/plugins/deploy/index.js +219 -0
  25. package/dist/esm/plugins/deploy/utils.js +244 -0
  26. package/dist/esm/utils/createServer.js +14 -50
  27. package/dist/esm/utils/env.js +1 -1
  28. package/dist/esm/utils/register.js +129 -0
  29. package/dist/esm-node/builder/builder-webpack/index.js +1 -1
  30. package/dist/esm-node/commands/build.js +3 -0
  31. package/dist/esm-node/commands/dev.js +17 -17
  32. package/dist/esm-node/commands/serve.js +14 -12
  33. package/dist/esm-node/index.js +3 -1
  34. package/dist/esm-node/plugins/deploy/dependencies.js +223 -0
  35. package/dist/esm-node/plugins/deploy/entrys/netlify.js +71 -0
  36. package/dist/esm-node/plugins/deploy/entrys/node.js +64 -0
  37. package/dist/esm-node/plugins/deploy/entrys/vercel.js +71 -0
  38. package/dist/esm-node/plugins/deploy/index.js +110 -0
  39. package/dist/esm-node/plugins/deploy/utils.js +109 -0
  40. package/dist/esm-node/utils/createServer.js +6 -17
  41. package/dist/esm-node/utils/env.js +1 -1
  42. package/dist/esm-node/utils/register.js +69 -0
  43. package/dist/types/plugins/deploy/dependencies.d.ts +1 -0
  44. package/dist/types/plugins/deploy/entrys/netlify.d.ts +5 -0
  45. package/dist/types/plugins/deploy/entrys/node.d.ts +5 -0
  46. package/dist/types/plugins/deploy/entrys/vercel.d.ts +5 -0
  47. package/dist/types/plugins/deploy/index.d.ts +4 -0
  48. package/dist/types/plugins/deploy/utils.d.ts +27 -0
  49. package/dist/types/types/config/tools.d.ts +1 -1
  50. package/dist/types/utils/createServer.d.ts +4 -9
  51. package/dist/types/utils/register.d.ts +3 -0
  52. package/package.json +28 -22
@@ -0,0 +1,95 @@
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 vercel_exports = {};
20
+ __export(vercel_exports, {
21
+ genVercelEntry: () => genVercelEntry
22
+ });
23
+ module.exports = __toCommonJS(vercel_exports);
24
+ var import_utils = require("@modern-js/utils");
25
+ var import_utils2 = require("../utils");
26
+ function genVercelEntry({ config, plugins, appContext } = {}) {
27
+ const defaultConfig = {
28
+ server: {
29
+ port: 8080
30
+ },
31
+ output: {
32
+ path: "."
33
+ }
34
+ };
35
+ return `
36
+
37
+ const fs = require('node:fs/promises');
38
+ const path = require('node:path');
39
+ const { createNetlifyFunction } = require('@modern-js/prod-server/netlify');
40
+ ${(0, import_utils2.genPluginImportsCode)(plugins || [])}
41
+
42
+ let requestHandler = null;
43
+
44
+ if(!process.env.NODE_ENV){
45
+ process.env.NODE_ENV = 'production';
46
+ }
47
+
48
+ async function createHandler() {
49
+ try {
50
+ let routes = [];
51
+ const routeFilepath = path.join(__dirname, "${import_utils.ROUTE_SPEC_FILE}");
52
+ try {
53
+ await fs.access(routeFilepath);
54
+ const content = await fs.readFile(routeFilepath, "utf-8");
55
+ const routeSpec = JSON.parse(content);
56
+ routes = routeSpec.routes;
57
+ } catch (error) {
58
+ console.warn('route.json not found, continuing with empty routes.');
59
+ }
60
+
61
+ const prodServerOptions = {
62
+ pwd: __dirname,
63
+ routes,
64
+ config: ${JSON.stringify(config || defaultConfig)},
65
+ serverConfigFile: '${import_utils.DEFAULT_SERVER_CONFIG}',
66
+ plugins: ${(0, import_utils2.getPluginsCode)(plugins || [])},
67
+ appContext: ${appContext ? (0, import_utils2.severAppContextTemplate)(appContext) : "undefined"},
68
+ disableCustomHook: true
69
+ }
70
+
71
+ requestHandler = await createNetlifyFunction(prodServerOptions)
72
+
73
+ return requestHandler
74
+ } catch(error) {
75
+ console.error(error);
76
+ process.exit(1);
77
+ }
78
+ }
79
+
80
+ createHandler();
81
+
82
+ const handleRequest = async(request, context) => {
83
+ if(typeof requestHandler !== 'function'){
84
+ await createHandler();
85
+ }
86
+ return requestHandler(request, context);
87
+ }
88
+
89
+ export default handleRequest;
90
+ `;
91
+ }
92
+ // Annotate the CommonJS export names for ESM import in node:
93
+ 0 && (module.exports = {
94
+ genVercelEntry
95
+ });
@@ -0,0 +1,140 @@
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 deploy_exports = {};
30
+ __export(deploy_exports, {
31
+ default: () => deploy_default
32
+ });
33
+ module.exports = __toCommonJS(deploy_exports);
34
+ var import_path = __toESM(require("path"));
35
+ var import_utils = require("@modern-js/utils");
36
+ var import_utils2 = require("./utils");
37
+ var import_dependencies = require("./dependencies");
38
+ var deploy_default = () => ({
39
+ name: "@modern-js/plugin-deploy",
40
+ pre: [
41
+ "@modern-js/plugin-bff",
42
+ "@modern-js/plugin-server"
43
+ ],
44
+ setup: (api) => {
45
+ return {
46
+ async beforeDeploy() {
47
+ const deployTarget = process.env.MODERNJS_DEPLOY || "node";
48
+ const appContext = api.useAppContext();
49
+ const { appDirectory, distDirectory, serverInternalPlugins, sharedDirectory, apiDirectory, lambdaDirectory, metaName } = appContext;
50
+ const configContext = api.useResolvedConfigContext();
51
+ const outputDirectory = import_path.default.join(appDirectory, ".output");
52
+ let funcsDirectory = outputDirectory;
53
+ let staticDirectory = import_path.default.join(outputDirectory, "static");
54
+ await import_utils.fs.remove(outputDirectory);
55
+ if (deployTarget === "node") {
56
+ await import_utils.fs.copy(distDirectory, outputDirectory, {
57
+ filter: (src) => {
58
+ const distStaticDirectory = import_path.default.join(distDirectory, "static");
59
+ return !src.includes(distStaticDirectory);
60
+ }
61
+ });
62
+ }
63
+ if (deployTarget === "vercel") {
64
+ funcsDirectory = import_path.default.join(outputDirectory, "functions");
65
+ staticDirectory = import_path.default.join(outputDirectory, "static");
66
+ await import_utils.fs.copy(distDirectory, funcsDirectory, {
67
+ filter: (src) => {
68
+ const distStaticDirectory = import_path.default.join(distDirectory, "static");
69
+ return !src.includes(distStaticDirectory);
70
+ }
71
+ });
72
+ await import_utils.fs.copy(import_path.default.join(distDirectory, "static"), staticDirectory);
73
+ await import_utils.fs.writeJSON(import_path.default.join(funcsDirectory, ".vc-config.json"), {
74
+ runtime: "nodejs16.x",
75
+ handler: "index.js",
76
+ launcherType: "Nodejs",
77
+ shouldAddHelpers: false,
78
+ supportsResponseStreaming: true
79
+ });
80
+ }
81
+ const { bff } = configContext;
82
+ const config = {
83
+ output: {
84
+ path: "."
85
+ },
86
+ bff
87
+ };
88
+ const plugins = (0, import_utils.getInternalPlugins)(appDirectory, serverInternalPlugins);
89
+ const serverAppContext = {
90
+ sharedDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, sharedDirectory)}")`,
91
+ apiDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, apiDirectory)}")`,
92
+ lambdaDirectory: `path.join(__dirname, "${import_path.default.relative(appDirectory, lambdaDirectory)}")`,
93
+ metaName
94
+ };
95
+ let code = ``;
96
+ console.log("deployTarget111111111", deployTarget);
97
+ switch (deployTarget) {
98
+ case "node": {
99
+ const { genNodeEntry } = await Promise.resolve().then(() => __toESM(require("./entrys/node")));
100
+ code = genNodeEntry({
101
+ plugins,
102
+ config,
103
+ appContext: serverAppContext
104
+ });
105
+ break;
106
+ }
107
+ case "vercel": {
108
+ const { genVercelEntry } = await Promise.resolve().then(() => __toESM(require("./entrys/vercel")));
109
+ code = genVercelEntry({
110
+ plugins,
111
+ config,
112
+ appContext: serverAppContext
113
+ });
114
+ break;
115
+ }
116
+ case "netlify": {
117
+ const { genNetlifyEntry } = await Promise.resolve().then(() => __toESM(require("./entrys/netlify")));
118
+ code = genNetlifyEntry({
119
+ plugins,
120
+ config,
121
+ appContext: serverAppContext
122
+ });
123
+ break;
124
+ }
125
+ default: {
126
+ code = `throw new Error("unknown deploy target, MODERNJS_DEPLOY should be set");`;
127
+ }
128
+ }
129
+ const { useSSR, useAPI, useWebServer } = (0, import_utils2.getProjectUsage)(appDirectory, distDirectory);
130
+ const entryFilePath = import_path.default.join(funcsDirectory, "index.js");
131
+ if (useSSR || useAPI || useWebServer) {
132
+ await import_utils.fs.writeFile(entryFilePath, code);
133
+ }
134
+ await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
135
+ "@modern-js/prod-server"
136
+ ]);
137
+ }
138
+ };
139
+ }
140
+ });
@@ -0,0 +1,150 @@
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 utils_exports = {};
30
+ __export(utils_exports, {
31
+ applyProductionCondition: () => applyProductionCondition,
32
+ applyPublicCondition: () => applyPublicCondition,
33
+ genPluginImportsCode: () => genPluginImportsCode,
34
+ getPluginsCode: () => getPluginsCode,
35
+ getProjectUsage: () => getProjectUsage,
36
+ linkPackage: () => linkPackage,
37
+ severAppContextTemplate: () => severAppContextTemplate,
38
+ writePackage: () => writePackage
39
+ });
40
+ module.exports = __toCommonJS(utils_exports);
41
+ var import_path = __toESM(require("path"));
42
+ var import_node_os = __toESM(require("node:os"));
43
+ var import_utils = require("@modern-js/utils");
44
+ var import_mlly = require("mlly");
45
+ const severAppContextTemplate = (serverAppContext) => {
46
+ return `{
47
+ sharedDirectory: ${serverAppContext.sharedDirectory},
48
+ apiDirectory: ${serverAppContext.apiDirectory},
49
+ lambdaDirectory: ${serverAppContext.lambdaDirectory},
50
+ }`;
51
+ };
52
+ const getPluginsCode = (plugins) => `[${plugins.map((_, index) => `plugin_${index}()`).join(",")}]`;
53
+ const genPluginImportsCode = (plugins) => {
54
+ return plugins.map((plugin, index) => `
55
+ let plugin_${index} = require('${plugin}')
56
+ plugin_${index} = plugin_${index}.default || plugin_${index}
57
+ `).join(";\n");
58
+ };
59
+ const getProjectUsage = (appDirectory, distDirectory) => {
60
+ const routeJSON = import_path.default.join(distDirectory, import_utils.ROUTE_SPEC_FILE);
61
+ const { routes } = import_utils.fs.readJSONSync(routeJSON);
62
+ let useSSR = false;
63
+ let useAPI = false;
64
+ routes.forEach((route) => {
65
+ if (route.isSSR) {
66
+ useSSR = true;
67
+ }
68
+ if (route.isApi) {
69
+ useAPI = true;
70
+ }
71
+ });
72
+ const useWebServer = (0, import_utils.isDepExists)(appDirectory, "@modern-js/plugin-server");
73
+ return {
74
+ useSSR,
75
+ useAPI,
76
+ useWebServer
77
+ };
78
+ };
79
+ function applyProductionCondition(exports) {
80
+ if (!exports || typeof exports === "string") {
81
+ return;
82
+ }
83
+ if (exports.production) {
84
+ if (typeof exports.production === "string") {
85
+ exports.default = exports.production;
86
+ } else {
87
+ Object.assign(exports, exports.production);
88
+ }
89
+ }
90
+ for (const key in exports) {
91
+ applyProductionCondition(exports[key]);
92
+ }
93
+ }
94
+ function applyPublicCondition(pkg) {
95
+ var _pkg_publishConfig;
96
+ if (pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig = pkg.publishConfig) === null || _pkg_publishConfig === void 0 ? void 0 : _pkg_publishConfig.exports) {
97
+ var _pkg_publishConfig1;
98
+ pkg.exports = pkg === null || pkg === void 0 ? void 0 : (_pkg_publishConfig1 = pkg.publishConfig) === null || _pkg_publishConfig1 === void 0 ? void 0 : _pkg_publishConfig1.exports;
99
+ }
100
+ }
101
+ const writePackage = async (pkg, version, projectDir, _pkgPath) => {
102
+ const pkgPath = _pkgPath || pkg.name;
103
+ for (const src of pkg.versions[version].files) {
104
+ if (src.includes("node_modules")) {
105
+ const { subpath } = (0, import_mlly.parseNodeModulePath)(src);
106
+ const dest = import_path.default.join(projectDir, "node_modules", pkgPath, subpath);
107
+ const dirname = import_path.default.dirname(dest);
108
+ await import_utils.fs.ensureDir(dirname);
109
+ await import_utils.fs.copyFile(src, dest);
110
+ } else {
111
+ const subpath = import_path.default.relative(pkg.versions[version].path, src);
112
+ const dest = import_path.default.join(projectDir, "node_modules", pkgPath, subpath);
113
+ const dirname = import_path.default.dirname(dest);
114
+ await import_utils.fs.ensureDir(dirname);
115
+ await import_utils.fs.copyFile(src, dest);
116
+ }
117
+ }
118
+ const { pkgJSON } = pkg.versions[version];
119
+ applyPublicCondition(pkgJSON);
120
+ const packageJsonPath = import_path.default.join(projectDir, "node_modules", pkgPath, "package.json");
121
+ await import_utils.fs.ensureDir(import_path.default.dirname(packageJsonPath));
122
+ await import_utils.fs.writeFile(packageJsonPath, JSON.stringify(pkgJSON, null, 2));
123
+ };
124
+ const isWindows = import_node_os.default.platform() === "win32";
125
+ const linkPackage = async (from, to, projectRootDir) => {
126
+ const src = import_path.default.join(projectRootDir, "node_modules", from);
127
+ const dest = import_path.default.join(projectRootDir, "node_modules", to);
128
+ const dstStat = await import_utils.fs.lstat(dest).catch(() => null);
129
+ const exists = dstStat === null || dstStat === void 0 ? void 0 : dstStat.isSymbolicLink();
130
+ if (exists) {
131
+ return;
132
+ }
133
+ await import_utils.fs.mkdir(import_path.default.dirname(dest), {
134
+ recursive: true
135
+ });
136
+ await import_utils.fs.symlink(import_path.default.relative(import_path.default.dirname(dest), src), dest, isWindows ? "junction" : "dir").catch((error) => {
137
+ console.error("Cannot link", from, "to", to, error);
138
+ });
139
+ };
140
+ // Annotate the CommonJS export names for ESM import in node:
141
+ 0 && (module.exports = {
142
+ applyProductionCondition,
143
+ applyPublicCondition,
144
+ genPluginImportsCode,
145
+ getPluginsCode,
146
+ getProjectUsage,
147
+ linkPackage,
148
+ severAppContextTemplate,
149
+ writePackage
150
+ });
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,25 +15,17 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
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
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var createServer_exports = {};
30
20
  __export(createServer_exports, {
31
21
  closeServer: () => closeServer,
32
22
  createServer: () => createServer,
33
23
  getServer: () => getServer,
34
- injectDataLoaderPlugin: () => injectDataLoaderPlugin,
35
24
  setServer: () => setServer
36
25
  });
37
26
  module.exports = __toCommonJS(createServer_exports);
38
27
  var import_server = require("@modern-js/server");
28
+ var import_prod_server = require("@modern-js/prod-server");
39
29
  let server = null;
40
30
  const getServer = () => server;
41
31
  const setServer = (newServer) => {
@@ -43,33 +33,21 @@ const setServer = (newServer) => {
43
33
  };
44
34
  const closeServer = async () => {
45
35
  if (server) {
46
- await server.close();
36
+ server.close();
47
37
  server = null;
48
38
  }
49
39
  };
50
40
  const createServer = async (options) => {
51
41
  if (server) {
52
- await server.close();
42
+ server.close();
53
43
  }
54
- server = new import_server.Server(options);
55
- const app = await server.init();
56
- return app;
57
- };
58
- const injectDataLoaderPlugin = (internalPlugins) => {
59
- const DataLoaderPlugin = require.resolve("@modern-js/plugin-data-loader/server");
60
- return {
61
- ...internalPlugins,
62
- "@modern-js/plugin-data-loader": {
63
- path: DataLoaderPlugin,
64
- forced: true
65
- }
66
- };
44
+ server = await (0, import_server.createDevServer)(options, import_prod_server.initProdMiddlewares);
45
+ return server;
67
46
  };
68
47
  // Annotate the CommonJS export names for ESM import in node:
69
48
  0 && (module.exports = {
70
49
  closeServer,
71
50
  createServer,
72
51
  getServer,
73
- injectDataLoaderPlugin,
74
52
  setServer
75
53
  });
@@ -21,10 +21,10 @@ __export(env_exports, {
21
21
  getAutoInjectEnv: () => getAutoInjectEnv
22
22
  });
23
23
  module.exports = __toCommonJS(env_exports);
24
- var import_utils = require("@modern-js/utils");
24
+ var import_universal = require("@modern-js/utils/universal");
25
25
  function getAutoInjectEnv(appContext) {
26
26
  const { metaName } = appContext;
27
- const prefix = `${(0, import_utils.cutNameByHyphen)(metaName)}_`.toUpperCase();
27
+ const prefix = `${(0, import_universal.cutNameByHyphen)(metaName)}_`.toUpperCase();
28
28
  const envReg = new RegExp(`^${prefix}`);
29
29
  return Object.keys(process.env).reduce((prev, key) => {
30
30
  const value = process.env[key];
@@ -0,0 +1,103 @@
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 register_exports = {};
30
+ __export(register_exports, {
31
+ registerCompiler: () => registerCompiler
32
+ });
33
+ module.exports = __toCommonJS(register_exports);
34
+ var import_node_path = __toESM(require("node:path"));
35
+ var import_utils = require("@modern-js/utils");
36
+ const registerCompiler = async (appDir = process.cwd(), distDir, alias) => {
37
+ const TS_CONFIG_FILENAME = `tsconfig.json`;
38
+ const tsconfigPath = import_node_path.default.resolve(appDir, TS_CONFIG_FILENAME);
39
+ const isTsProject = await import_utils.fs.pathExists(tsconfigPath);
40
+ const aliasConfig = (0, import_utils.getAliasConfig)(alias, {
41
+ appDirectory: appDir,
42
+ tsconfigPath
43
+ });
44
+ const { paths = {}, absoluteBaseUrl = "./" } = aliasConfig;
45
+ const tsPaths = Object.keys(paths).reduce((o, key) => {
46
+ let tsPath = paths[key];
47
+ if (typeof tsPath === "string" && import_node_path.default.isAbsolute(tsPath)) {
48
+ tsPath = import_node_path.default.relative(absoluteBaseUrl, tsPath);
49
+ }
50
+ if (typeof tsPath === "string") {
51
+ tsPath = [
52
+ tsPath
53
+ ];
54
+ }
55
+ return {
56
+ ...o,
57
+ [`${key}`]: tsPath
58
+ };
59
+ }, {});
60
+ let tsConfig = {};
61
+ if (isTsProject) {
62
+ tsConfig = (0, import_utils.readTsConfigByFile)(tsconfigPath);
63
+ }
64
+ try {
65
+ const tsNode = await Promise.resolve().then(() => __toESM(require("ts-node")));
66
+ const tsNodeOptions = tsConfig["ts-node"];
67
+ if (isTsProject) {
68
+ tsNode.register({
69
+ project: tsconfigPath,
70
+ scope: true,
71
+ // for env.d.ts, https://www.npmjs.com/package/ts-node#missing-types
72
+ files: true,
73
+ transpileOnly: true,
74
+ ignore: [
75
+ "(?:^|/)node_modules/",
76
+ `(?:^|/)${distDir}/`
77
+ ],
78
+ ...tsNodeOptions
79
+ });
80
+ }
81
+ } catch (error) {
82
+ const esbuildRegister = await Promise.resolve().then(() => __toESM(require("esbuild-register/dist/node")));
83
+ esbuildRegister.register({
84
+ tsconfigRaw: isTsProject ? tsConfig : void 0,
85
+ hookIgnoreNodeModules: true,
86
+ hookMatcher: (fileName) => !fileName.startsWith(distDir)
87
+ });
88
+ }
89
+ const tsConfigPaths = await Promise.resolve().then(() => __toESM(require("@modern-js/utils/tsconfig-paths")));
90
+ if (await import_utils.fs.pathExists(appDir)) {
91
+ const loaderRes = tsConfigPaths.loadConfig(appDir);
92
+ if (loaderRes.resultType === "success") {
93
+ tsConfigPaths.register({
94
+ baseUrl: absoluteBaseUrl || "./",
95
+ paths: tsPaths
96
+ });
97
+ }
98
+ }
99
+ };
100
+ // Annotate the CommonJS export names for ESM import in node:
101
+ 0 && (module.exports = {
102
+ registerCompiler
103
+ });
@@ -26,7 +26,7 @@ function _createWebpackBuilderForModern() {
26
26
  _normalizedConfig_tools = normalizedConfig.tools, esbuildOptions = _normalizedConfig_tools.esbuild;
27
27
  return [
28
28
  4,
29
- import("@rsbuild/plugin-esbuild")
29
+ import("@modern-js/rsbuild-plugin-esbuild")
30
30
  ];
31
31
  case 2:
32
32
  pluginEsbuild = _state.sent().pluginEsbuild;
@@ -6,9 +6,10 @@ import { ResolvedConfigContext } from "@modern-js/core";
6
6
  import { logger } from "@modern-js/utils";
7
7
  import { generateRoutes } from "../utils/routes";
8
8
  import { buildServerConfig } from "../utils/config";
9
+ import { registerCompiler } from "../utils/register";
9
10
  var build = function() {
10
11
  var _ref = _async_to_generator(function(api, options) {
11
- var resolvedConfig, appContext, hookRunners, apiOnly, appDirectory, distDirectory, serverConfigFile, distDirectory1, appDirectory1, serverConfigFile1;
12
+ var _resolvedConfig_source, resolvedConfig, appContext, hookRunners, apiOnly, appDirectory, distDirectory, serverConfigFile, distDirectory1, appDirectory1, serverConfigFile1;
12
13
  return _ts_generator(this, function(_state) {
13
14
  switch (_state.label) {
14
15
  case 0:
@@ -18,11 +19,17 @@ var build = function() {
18
19
  resolvedConfig = api.useResolvedConfigContext();
19
20
  appContext = api.useAppContext();
20
21
  hookRunners = api.useHookRunners();
22
+ return [
23
+ 4,
24
+ 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)
25
+ ];
26
+ case 1:
27
+ _state.sent();
21
28
  apiOnly = appContext.apiOnly;
22
29
  if (!apiOnly)
23
30
  return [
24
31
  3,
25
- 5
32
+ 6
26
33
  ];
27
34
  appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverConfigFile = appContext.serverConfigFile;
28
35
  return [
@@ -32,7 +39,7 @@ var build = function() {
32
39
  bundlerConfigs: void 0
33
40
  })
34
41
  ];
35
- case 1:
42
+ case 2:
36
43
  _state.sent();
37
44
  return [
38
45
  4,
@@ -42,13 +49,13 @@ var build = function() {
42
49
  configFile: serverConfigFile
43
50
  })
44
51
  ];
45
- case 2:
52
+ case 3:
46
53
  _state.sent();
47
54
  return [
48
55
  4,
49
56
  generateRoutes(appContext)
50
57
  ];
51
- case 3:
58
+ case 4:
52
59
  _state.sent();
53
60
  return [
54
61
  4,
@@ -57,12 +64,12 @@ var build = function() {
57
64
  stats: void 0
58
65
  })
59
66
  ];
60
- case 4:
67
+ case 5:
61
68
  _state.sent();
62
69
  return [
63
70
  2
64
71
  ];
65
- case 5:
72
+ case 6:
66
73
  resolvedConfig = _object_spread_props(_object_spread({}, resolvedConfig), {
67
74
  cliOptions: options
68
75
  });
@@ -76,7 +83,7 @@ var build = function() {
76
83
  configFile: serverConfigFile1
77
84
  })
78
85
  ];
79
- case 6:
86
+ case 7:
80
87
  _state.sent();
81
88
  logger.info("Starting production build...");
82
89
  if (!appContext.builder) {
@@ -86,7 +93,7 @@ var build = function() {
86
93
  4,
87
94
  appContext.builder.build()
88
95
  ];
89
- case 7:
96
+ case 8:
90
97
  _state.sent();
91
98
  return [
92
99
  2