@modern-js/app-tools 3.0.4 → 3.1.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.
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +1 -1
- package/dist/cjs/config/default.js +1 -1
- package/dist/cjs/index.js +14 -5
- package/dist/cjs/plugins/analyze/utils.js +6 -6
- package/dist/cjs/plugins/deploy/index.js +10 -5
- package/dist/cjs/plugins/deploy/platforms/gh-pages.js +1 -1
- package/dist/cjs/plugins/deploy/platforms/netlify.js +17 -33
- package/dist/cjs/plugins/deploy/platforms/node.js +17 -38
- package/dist/cjs/plugins/deploy/platforms/templates/netlify-entry.cjs +57 -0
- package/dist/cjs/plugins/deploy/platforms/templates/netlify-entry.mjs +59 -0
- package/dist/cjs/plugins/deploy/platforms/templates/node-entry.cjs +44 -0
- package/dist/{esm/plugins/deploy/platforms → cjs/plugins/deploy/platforms/templates}/node-entry.mjs +5 -27
- package/dist/cjs/plugins/deploy/platforms/templates/vercel-entry.cjs +56 -0
- package/dist/cjs/plugins/deploy/platforms/templates/vercel-entry.mjs +58 -0
- package/dist/cjs/plugins/deploy/platforms/vercel.js +15 -32
- package/dist/cjs/plugins/deploy/types.js +18 -0
- package/dist/cjs/plugins/deploy/utils/generator.js +103 -0
- package/dist/cjs/plugins/deploy/{utils.js → utils/index.js} +28 -24
- package/dist/cjs/rsbuild.js +74 -0
- package/dist/cjs/utils/getConfigFile.js +1 -1
- package/dist/cjs/utils/register.js +1 -9
- package/dist/esm/builder/shared/builderPlugins/adapterBasic.mjs +2 -2
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.mjs +2 -2
- package/dist/esm/commands/build.mjs +3 -3
- package/dist/esm/commands/dev.mjs +5 -5
- package/dist/esm/commands/serve.mjs +2 -2
- package/dist/esm/config/default.mjs +1 -1
- package/dist/esm/esm/register-esm.mjs +3 -3
- package/dist/esm/index.mjs +2 -1
- package/dist/esm/plugins/analyze/utils.mjs +2 -2
- package/dist/esm/plugins/deploy/index.mjs +9 -4
- package/dist/esm/plugins/deploy/platforms/gh-pages.mjs +1 -1
- package/dist/esm/plugins/deploy/platforms/netlify.mjs +25 -41
- package/dist/esm/plugins/deploy/platforms/node.mjs +22 -43
- package/dist/esm/plugins/deploy/platforms/templates/netlify-entry.cjs +57 -0
- package/dist/esm/plugins/deploy/platforms/templates/netlify-entry.mjs +59 -0
- package/dist/esm/plugins/deploy/platforms/templates/node-entry.cjs +44 -0
- package/dist/esm/plugins/deploy/platforms/templates/node-entry.mjs +46 -0
- package/dist/esm/plugins/deploy/platforms/templates/vercel-entry.cjs +56 -0
- package/dist/esm/plugins/deploy/platforms/templates/vercel-entry.mjs +58 -0
- package/dist/esm/plugins/deploy/platforms/vercel.mjs +28 -45
- package/dist/esm/plugins/deploy/types.mjs +0 -0
- package/dist/esm/plugins/deploy/utils/generator.mjs +47 -0
- package/dist/esm/plugins/deploy/utils/index.mjs +40 -0
- package/dist/esm/rsbuild.mjs +40 -0
- package/dist/esm/utils/getConfigFile.mjs +1 -1
- package/dist/esm/utils/loadPlugins.mjs +4 -4
- package/dist/esm/utils/register.mjs +6 -14
- package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.mjs +2 -2
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.mjs +2 -2
- package/dist/esm-node/commands/build.mjs +3 -3
- package/dist/esm-node/commands/dev.mjs +5 -5
- package/dist/esm-node/commands/serve.mjs +2 -2
- package/dist/esm-node/config/default.mjs +1 -1
- package/dist/esm-node/esm/register-esm.mjs +3 -3
- package/dist/esm-node/index.mjs +2 -1
- package/dist/esm-node/plugins/analyze/utils.mjs +2 -2
- package/dist/esm-node/plugins/deploy/index.mjs +9 -4
- package/dist/esm-node/plugins/deploy/platforms/gh-pages.mjs +1 -1
- package/dist/esm-node/plugins/deploy/platforms/netlify.mjs +25 -44
- package/dist/esm-node/plugins/deploy/platforms/node.mjs +22 -46
- package/dist/esm-node/plugins/deploy/platforms/templates/netlify-entry.cjs +57 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/netlify-entry.mjs +59 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/node-entry.cjs +44 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/node-entry.mjs +46 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/vercel-entry.cjs +56 -0
- package/dist/esm-node/plugins/deploy/platforms/templates/vercel-entry.mjs +58 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel.mjs +28 -48
- package/dist/esm-node/plugins/deploy/types.mjs +1 -0
- package/dist/esm-node/plugins/deploy/utils/generator.mjs +48 -0
- package/dist/esm-node/plugins/deploy/utils/index.mjs +44 -0
- package/dist/esm-node/rsbuild.mjs +41 -0
- package/dist/esm-node/utils/getConfigFile.mjs +1 -1
- package/dist/esm-node/utils/loadPlugins.mjs +4 -4
- package/dist/esm-node/utils/register.mjs +6 -14
- package/dist/types/index.d.ts +1 -0
- package/dist/types/plugins/analyze/utils.d.ts +1 -1
- package/dist/types/plugins/deploy/platforms/platform.d.ts +8 -1
- package/dist/types/plugins/deploy/platforms/templates/netlify-entry.d.mts +2 -0
- package/dist/types/plugins/deploy/platforms/templates/node-entry.d.mts +1 -0
- package/dist/types/plugins/deploy/platforms/templates/vercel-entry.d.cts +2 -0
- package/dist/types/plugins/deploy/platforms/templates/vercel-entry.d.mts +2 -0
- package/dist/types/plugins/deploy/types.d.ts +3 -0
- package/dist/types/plugins/deploy/utils/generator.d.ts +24 -0
- package/dist/types/plugins/deploy/utils/index.d.ts +16 -0
- package/dist/types/rsbuild.d.ts +12 -0
- package/dist/types/utils/getConfigFile.d.ts +1 -1
- package/package.json +16 -15
- package/rslib.config.mts +19 -0
- package/dist/cjs/plugins/deploy/platforms/netlify-entry.js +0 -36
- package/dist/cjs/plugins/deploy/platforms/netlify-handler.js +0 -89
- package/dist/cjs/plugins/deploy/platforms/node-entry.js +0 -75
- package/dist/cjs/plugins/deploy/platforms/vercel-entry.js +0 -37
- package/dist/cjs/plugins/deploy/platforms/vercel-handler.js +0 -89
- package/dist/esm/plugins/deploy/platforms/netlify-entry.mjs +0 -2
- package/dist/esm/plugins/deploy/platforms/netlify-handler.mjs +0 -85
- package/dist/esm/plugins/deploy/platforms/vercel-entry.mjs +0 -3
- package/dist/esm/plugins/deploy/platforms/vercel-handler.mjs +0 -85
- package/dist/esm/plugins/deploy/utils.mjs +0 -39
- package/dist/esm-node/plugins/deploy/platforms/netlify-entry.mjs +0 -3
- package/dist/esm-node/plugins/deploy/platforms/netlify-handler.mjs +0 -89
- package/dist/esm-node/plugins/deploy/platforms/node-entry.mjs +0 -72
- package/dist/esm-node/plugins/deploy/platforms/vercel-entry.mjs +0 -4
- package/dist/esm-node/plugins/deploy/platforms/vercel-handler.mjs +0 -89
- package/dist/esm-node/plugins/deploy/utils.mjs +0 -40
- package/dist/types/plugins/deploy/platforms/netlify-entry.d.cts +0 -2
- package/dist/types/plugins/deploy/platforms/netlify-entry.d.mts +0 -1
- package/dist/types/plugins/deploy/platforms/vercel-entry.d.mts +0 -2
- package/dist/types/plugins/deploy/platforms/vercel-entry.d.ts +0 -2
- package/dist/types/plugins/deploy/platforms/vercel-handler.d.cts +0 -1
- package/dist/types/plugins/deploy/utils.d.ts +0 -23
- /package/dist/types/plugins/deploy/platforms/{netlify-handler.d.cts → templates/netlify-entry.d.cts} +0 -0
- /package/dist/types/plugins/deploy/platforms/{node-entry.d.ts → templates/node-entry.d.cts} +0 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { createProdServer } from '@modern-js/prod-server';
|
|
5
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
p_genPluginImportsCode;
|
|
7
|
+
if (!process.env.NODE_ENV) process.env.NODE_ENV = 'production';
|
|
8
|
+
let requestHandler = null;
|
|
9
|
+
let handlerCreationPromise = null;
|
|
10
|
+
async function loadRoutes(routeFilepath) {
|
|
11
|
+
try {
|
|
12
|
+
await fs.access(routeFilepath);
|
|
13
|
+
const content = await fs.readFile(routeFilepath, 'utf-8');
|
|
14
|
+
const routeSpec = JSON.parse(content);
|
|
15
|
+
return routeSpec.routes || [];
|
|
16
|
+
} catch (error) {
|
|
17
|
+
console.warn('route.json not found or invalid, continuing with empty routes.');
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async function initServer() {
|
|
22
|
+
const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
|
23
|
+
const routes = await loadRoutes(routeFilepath);
|
|
24
|
+
const dynamicProdOptions = p_dynamicProdOptions;
|
|
25
|
+
const prodServerOptions = {
|
|
26
|
+
pwd: __dirname,
|
|
27
|
+
routes,
|
|
28
|
+
disableCustomHook: true,
|
|
29
|
+
appContext: {
|
|
30
|
+
sharedDirectory: p_sharedDirectory,
|
|
31
|
+
apiDirectory: p_apiDirectory,
|
|
32
|
+
lambdaDirectory: p_lambdaDirectory
|
|
33
|
+
},
|
|
34
|
+
plugins: p_plugins,
|
|
35
|
+
serverConfigPath: p_serverDirectory,
|
|
36
|
+
...dynamicProdOptions
|
|
37
|
+
};
|
|
38
|
+
const app = await createProdServer(prodServerOptions);
|
|
39
|
+
return app.getRequestListener();
|
|
40
|
+
}
|
|
41
|
+
async function createHandler() {
|
|
42
|
+
if (!handlerCreationPromise) handlerCreationPromise = (async ()=>{
|
|
43
|
+
try {
|
|
44
|
+
requestHandler = await initServer();
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error('Error creating server:', error);
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
})();
|
|
50
|
+
await handlerCreationPromise;
|
|
51
|
+
return requestHandler;
|
|
52
|
+
}
|
|
53
|
+
createHandler();
|
|
54
|
+
const handler = async (req, res)=>{
|
|
55
|
+
if (!requestHandler) await createHandler();
|
|
56
|
+
return requestHandler(req, res);
|
|
57
|
+
};
|
|
58
|
+
export default handler;
|
|
@@ -40,19 +40,15 @@ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_no
|
|
|
40
40
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
41
41
|
const external_ndepe_namespaceObject = require("ndepe");
|
|
42
42
|
const routes_js_namespaceObject = require("../../../utils/routes.js");
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
|
|
43
|
+
const index_js_namespaceObject = require("../utils/index.js");
|
|
44
|
+
const generator_js_namespaceObject = require("../utils/generator.js");
|
|
45
|
+
const createVercelPreset = ({ appContext, modernConfig, needModernServer })=>{
|
|
46
|
+
const { appDirectory, distDirectory, entrypoints, moduleType } = appContext;
|
|
46
47
|
const isEsmProject = 'module' === moduleType;
|
|
47
|
-
const plugins = serverPlugins.map((plugin)=>[
|
|
48
|
-
plugin.name,
|
|
49
|
-
plugin.options
|
|
50
|
-
]);
|
|
51
48
|
const vercelOutput = external_node_path_default().join(appDirectory, '.vercel');
|
|
52
49
|
const outputDirectory = external_node_path_default().join(vercelOutput, 'output');
|
|
53
50
|
const funcsDirectory = external_node_path_default().join(outputDirectory, 'functions', 'index.func');
|
|
54
51
|
const entryFilePath = external_node_path_default().join(funcsDirectory, 'index.js');
|
|
55
|
-
const handlerFilePath = external_node_path_default().join(funcsDirectory, 'vercel-handler.cjs');
|
|
56
52
|
return {
|
|
57
53
|
async prepare () {
|
|
58
54
|
await utils_namespaceObject.fs.remove(vercelOutput);
|
|
@@ -121,37 +117,24 @@ const createVercelPreset = (appContext, modernConfig, needModernServer)=>{
|
|
|
121
117
|
},
|
|
122
118
|
async genEntry () {
|
|
123
119
|
if (!needModernServer) return;
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
const pluginImportCode = (0, external_utils_js_namespaceObject.genPluginImportsCode)(plugins || []);
|
|
135
|
-
const dynamicProdOptions = {
|
|
136
|
-
config: serverConfig
|
|
137
|
-
};
|
|
138
|
-
const meta = (0, utils_namespaceObject.getMeta)(metaName);
|
|
139
|
-
const serverConfigPath = `path.join(__dirname, "${utils_namespaceObject.SERVER_DIR}", "${meta}.server")`;
|
|
140
|
-
const pluginsCode = (0, external_utils_js_namespaceObject.getPluginsCode)(plugins || []);
|
|
141
|
-
const serverAppContext = (0, external_utils_js_namespaceObject.serverAppContenxtTemplate)(appContext);
|
|
142
|
-
let handlerCode = (await utils_namespaceObject.fs.readFile(external_node_path_default().join(__dirname, './vercel-handler.js'))).toString();
|
|
143
|
-
handlerCode = handlerCode.replace('p_genPluginImportsCode', pluginImportCode).replace('p_ROUTE_SPEC_FILE', `"${utils_namespaceObject.ROUTE_SPEC_FILE}"`).replace('p_dynamicProdOptions', JSON.stringify(dynamicProdOptions)).replace('p_plugins', pluginsCode).replace('p_serverDirectory', serverConfigPath).replace('p_sharedDirectory', serverAppContext.sharedDirectory).replace('p_apiDirectory', serverAppContext.apiDirectory).replace('p_lambdaDirectory', serverAppContext.lambdaDirectory);
|
|
144
|
-
await utils_namespaceObject.fs.writeFile(handlerFilePath, handlerCode);
|
|
145
|
-
if (isEsmProject) await utils_namespaceObject.fs.copy(external_node_path_default().join(__dirname, './vercel-entry.mjs'), entryFilePath);
|
|
146
|
-
else await utils_namespaceObject.fs.copy(external_node_path_default().join(__dirname, './vercel-entry.js'), entryFilePath);
|
|
120
|
+
const template = await (0, index_js_namespaceObject.readTemplate)(`vercel-entry.${isEsmProject ? 'mjs' : 'cjs'}`);
|
|
121
|
+
const code = await (0, generator_js_namespaceObject.generateHandler)({
|
|
122
|
+
template,
|
|
123
|
+
appContext,
|
|
124
|
+
config: modernConfig,
|
|
125
|
+
isESM: isEsmProject
|
|
126
|
+
});
|
|
127
|
+
await utils_namespaceObject.fs.writeFile(entryFilePath, code);
|
|
147
128
|
},
|
|
148
129
|
async end () {
|
|
149
130
|
if (!needModernServer) return;
|
|
131
|
+
const entry = isEsmProject ? await (0, index_js_namespaceObject.resolveESMDependency)('@modern-js/prod-server') : require.resolve('@modern-js/prod-server');
|
|
132
|
+
if (!entry) throw new Error('Cannot find @modern-js/prod-server');
|
|
150
133
|
await (0, external_ndepe_namespaceObject.nodeDepEmit)({
|
|
151
134
|
appDir: appDirectory,
|
|
152
135
|
sourceDir: funcsDirectory,
|
|
153
136
|
includeEntries: [
|
|
154
|
-
|
|
137
|
+
entry
|
|
155
138
|
],
|
|
156
139
|
copyWholePackage (pkgName) {
|
|
157
140
|
return '@modern-js/utils' === pkgName;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.r = (exports1)=>{
|
|
5
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
6
|
+
value: 'Module'
|
|
7
|
+
});
|
|
8
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
})();
|
|
13
|
+
var __webpack_exports__ = {};
|
|
14
|
+
__webpack_require__.r(__webpack_exports__);
|
|
15
|
+
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
16
|
+
Object.defineProperty(exports, '__esModule', {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
serverAppContextTemplate: ()=>serverAppContextTemplate,
|
|
37
|
+
getPluginsCode: ()=>getPluginsCode,
|
|
38
|
+
genPluginImportsCode: ()=>genPluginImportsCode,
|
|
39
|
+
generateHandler: ()=>generateHandler,
|
|
40
|
+
getServerConfigPath: ()=>getServerConfigPath
|
|
41
|
+
});
|
|
42
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
43
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
44
|
+
const utils_namespaceObject = require("@modern-js/utils");
|
|
45
|
+
const lodash_namespaceObject = require("@modern-js/utils/lodash");
|
|
46
|
+
const external_index_js_namespaceObject = require("./index.js");
|
|
47
|
+
const serverAppContextTemplate = (appContext)=>{
|
|
48
|
+
const { appDirectory, sharedDirectory, apiDirectory, lambdaDirectory, metaName, bffRuntimeFramework } = appContext;
|
|
49
|
+
return {
|
|
50
|
+
sharedDirectory: `path.join(__dirname, "${(0, external_index_js_namespaceObject.normalizePath)(external_node_path_default().relative(appDirectory, sharedDirectory))}")`,
|
|
51
|
+
apiDirectory: `path.join(__dirname, "${(0, external_index_js_namespaceObject.normalizePath)(external_node_path_default().relative(appDirectory, apiDirectory))}")`,
|
|
52
|
+
lambdaDirectory: `path.join(__dirname, "${(0, external_index_js_namespaceObject.normalizePath)(external_node_path_default().relative(appDirectory, lambdaDirectory))}")`,
|
|
53
|
+
metaName,
|
|
54
|
+
bffRuntimeFramework: bffRuntimeFramework || 'hono'
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const genPluginImportsCode = (plugins, isESM = false)=>plugins.map(([name, options], index)=>{
|
|
58
|
+
const im = isESM ? `import * as plugin_${index}_ns from '${name}'` : `const plugin_${index}_ns = require('${name}')`;
|
|
59
|
+
return `${im};const plugin_${index} = plugin_${index}_ns.default || plugin_${index}_ns`;
|
|
60
|
+
}).join(';\n');
|
|
61
|
+
const getPluginsCode = (plugins)=>`[${plugins.map(([, options], index)=>`plugin_${index}(${options ? JSON.stringify(options) : ''})`).join(',')}]`;
|
|
62
|
+
const getServerConfigPath = (meta)=>`"${(0, external_index_js_namespaceObject.normalizePath)(external_node_path_default().join(utils_namespaceObject.SERVER_DIR, `${meta}.server`))}"`;
|
|
63
|
+
const generateHandler = async ({ template, appContext, config, serverConfig: modifyServerConfig, genAppContextTemplate = serverAppContextTemplate, genPluginImports = genPluginImportsCode, isESM })=>{
|
|
64
|
+
const { serverPlugins, metaName } = appContext;
|
|
65
|
+
const plugins = serverPlugins.map((plugin)=>[
|
|
66
|
+
plugin.name,
|
|
67
|
+
plugin.options
|
|
68
|
+
]);
|
|
69
|
+
const serverConfig = (0, lodash_namespaceObject.merge)({
|
|
70
|
+
bff: {
|
|
71
|
+
prefix: config?.bff?.prefix
|
|
72
|
+
},
|
|
73
|
+
output: {
|
|
74
|
+
distPath: {
|
|
75
|
+
root: '.'
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}, modifyServerConfig || {});
|
|
79
|
+
const meta = (0, utils_namespaceObject.getMeta)(metaName);
|
|
80
|
+
const pluginImportCode = genPluginImports(plugins || [], Boolean(isESM));
|
|
81
|
+
const dynamicProdOptions = {
|
|
82
|
+
config: serverConfig
|
|
83
|
+
};
|
|
84
|
+
const serverConfigPath = getServerConfigPath(meta);
|
|
85
|
+
const pluginsCode = getPluginsCode(plugins);
|
|
86
|
+
const serverAppContext = genAppContextTemplate(appContext);
|
|
87
|
+
return template.replace('p_genPluginImportsCode', pluginImportCode).replace('p_ROUTE_SPEC_FILE', `"${utils_namespaceObject.ROUTE_SPEC_FILE}"`).replace('p_dynamicProdOptions', JSON.stringify(dynamicProdOptions)).replace('p_plugins', pluginsCode).replace('p_bffRuntimeFramework', `"${serverAppContext.bffRuntimeFramework}"`).replace('p_serverDirectory', serverConfigPath).replace('p_sharedDirectory', serverAppContext.sharedDirectory).replace('p_apiDirectory', serverAppContext.apiDirectory).replace('p_lambdaDirectory', serverAppContext.lambdaDirectory);
|
|
88
|
+
};
|
|
89
|
+
exports.genPluginImportsCode = __webpack_exports__.genPluginImportsCode;
|
|
90
|
+
exports.generateHandler = __webpack_exports__.generateHandler;
|
|
91
|
+
exports.getPluginsCode = __webpack_exports__.getPluginsCode;
|
|
92
|
+
exports.getServerConfigPath = __webpack_exports__.getServerConfigPath;
|
|
93
|
+
exports.serverAppContextTemplate = __webpack_exports__.serverAppContextTemplate;
|
|
94
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
95
|
+
"genPluginImportsCode",
|
|
96
|
+
"generateHandler",
|
|
97
|
+
"getPluginsCode",
|
|
98
|
+
"getServerConfigPath",
|
|
99
|
+
"serverAppContextTemplate"
|
|
100
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
101
|
+
Object.defineProperty(exports, '__esModule', {
|
|
102
|
+
value: true
|
|
103
|
+
});
|
|
@@ -33,29 +33,17 @@ var __webpack_require__ = {};
|
|
|
33
33
|
var __webpack_exports__ = {};
|
|
34
34
|
__webpack_require__.r(__webpack_exports__);
|
|
35
35
|
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
getTemplatePath: ()=>getTemplatePath,
|
|
36
37
|
getProjectUsage: ()=>getProjectUsage,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
normalizePath: ()=>normalizePath,
|
|
39
|
+
readTemplate: ()=>readTemplate,
|
|
40
|
+
resolveESMDependency: ()=>resolveESMDependency
|
|
40
41
|
});
|
|
42
|
+
const external_node_url_namespaceObject = require("node:url");
|
|
41
43
|
const external_path_namespaceObject = require("path");
|
|
42
44
|
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
43
45
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
44
|
-
const
|
|
45
|
-
const { appDirectory, sharedDirectory, apiDirectory, lambdaDirectory, metaName, bffRuntimeFramework } = appContext;
|
|
46
|
-
return {
|
|
47
|
-
sharedDirectory: `path.join(__dirname, "${external_path_default().relative(appDirectory, sharedDirectory)}")`,
|
|
48
|
-
apiDirectory: `path.join(__dirname, "${external_path_default().relative(appDirectory, apiDirectory)}")`,
|
|
49
|
-
lambdaDirectory: `path.join(__dirname, "${external_path_default().relative(appDirectory, lambdaDirectory)}")`,
|
|
50
|
-
metaName,
|
|
51
|
-
bffRuntimeFramework: bffRuntimeFramework || 'hono'
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
const genPluginImportsCode = (plugins)=>plugins.map(([name, options], index)=>`
|
|
55
|
-
let plugin_${index} = require('${name}')
|
|
56
|
-
plugin_${index} = plugin_${index}.default || plugin_${index}
|
|
57
|
-
`).join(';\n');
|
|
58
|
-
const getPluginsCode = (plugins)=>`[${plugins.map(([, options], index)=>`plugin_${index}(${options ? JSON.stringify(options) : ''})`).join(',')}]`;
|
|
46
|
+
const normalizePath = (filePath)=>filePath.replace(/\\/g, '/');
|
|
59
47
|
const getProjectUsage = (appDirectory, distDirectory, metaName)=>{
|
|
60
48
|
const routeJSON = external_path_default().join(distDirectory, utils_namespaceObject.ROUTE_SPEC_FILE);
|
|
61
49
|
const { routes } = utils_namespaceObject.fs.readJSONSync(routeJSON);
|
|
@@ -77,15 +65,31 @@ const getProjectUsage = (appDirectory, distDirectory, metaName)=>{
|
|
|
77
65
|
useWebServer: isServerConfigExists
|
|
78
66
|
};
|
|
79
67
|
};
|
|
80
|
-
|
|
81
|
-
|
|
68
|
+
const getTemplatePath = (file)=>external_path_default().join(__dirname, '../platforms/templates', file);
|
|
69
|
+
const readTemplate = async (file)=>(await utils_namespaceObject.fs.readFile(getTemplatePath(file))).toString();
|
|
70
|
+
const resolveESMDependency = async (entry)=>{
|
|
71
|
+
const conditions = new Set([
|
|
72
|
+
'node',
|
|
73
|
+
'import',
|
|
74
|
+
'module',
|
|
75
|
+
'default'
|
|
76
|
+
]);
|
|
77
|
+
try {
|
|
78
|
+
const { moduleResolve } = await import("import-meta-resolve");
|
|
79
|
+
return normalizePath(moduleResolve(entry, (0, external_node_url_namespaceObject.pathToFileURL)(`${__dirname}/`), conditions, false).pathname.replace(/^\/(\w)\:/, '$1:'));
|
|
80
|
+
} catch (err) {}
|
|
81
|
+
};
|
|
82
82
|
exports.getProjectUsage = __webpack_exports__.getProjectUsage;
|
|
83
|
-
exports.
|
|
83
|
+
exports.getTemplatePath = __webpack_exports__.getTemplatePath;
|
|
84
|
+
exports.normalizePath = __webpack_exports__.normalizePath;
|
|
85
|
+
exports.readTemplate = __webpack_exports__.readTemplate;
|
|
86
|
+
exports.resolveESMDependency = __webpack_exports__.resolveESMDependency;
|
|
84
87
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
85
|
-
"genPluginImportsCode",
|
|
86
|
-
"getPluginsCode",
|
|
87
88
|
"getProjectUsage",
|
|
88
|
-
"
|
|
89
|
+
"getTemplatePath",
|
|
90
|
+
"normalizePath",
|
|
91
|
+
"readTemplate",
|
|
92
|
+
"resolveESMDependency"
|
|
89
93
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
90
94
|
Object.defineProperty(exports, '__esModule', {
|
|
91
95
|
value: true
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: definition[key]
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
})();
|
|
11
|
+
(()=>{
|
|
12
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
+
})();
|
|
14
|
+
(()=>{
|
|
15
|
+
__webpack_require__.r = (exports1)=>{
|
|
16
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
+
value: 'Module'
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
+
value: true
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
})();
|
|
24
|
+
var __webpack_exports__ = {};
|
|
25
|
+
__webpack_require__.r(__webpack_exports__);
|
|
26
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
+
resolveModernRsbuildConfig: ()=>resolveModernRsbuildConfig
|
|
28
|
+
});
|
|
29
|
+
const builder_namespaceObject = require("@modern-js/builder");
|
|
30
|
+
const cli_namespaceObject = require("@modern-js/plugin/cli");
|
|
31
|
+
const index_js_namespaceObject = require("./builder/shared/builderPlugins/index.js");
|
|
32
|
+
const external_constants_js_namespaceObject = require("./constants.js");
|
|
33
|
+
const getConfigFile_js_namespaceObject = require("./utils/getConfigFile.js");
|
|
34
|
+
const MODERN_META_NAME = 'modern-js';
|
|
35
|
+
async function resolveModernRsbuildConfig(options) {
|
|
36
|
+
const { cwd = process.cwd(), metaName = MODERN_META_NAME } = options;
|
|
37
|
+
const configFile = options.configPath || (0, getConfigFile_js_namespaceObject.getConfigFile)(void 0, cwd);
|
|
38
|
+
if (!configFile) throw new Error(`Cannot find config file in ${cwd}. Please make sure you have a ${external_constants_js_namespaceObject.DEFAULT_CONFIG_FILE} file in your project.`);
|
|
39
|
+
const { config: modernConfig, getAppContext } = await (0, cli_namespaceObject.createConfigOptions)({
|
|
40
|
+
command: options.command,
|
|
41
|
+
cwd,
|
|
42
|
+
configFile,
|
|
43
|
+
metaName,
|
|
44
|
+
modifyModernConfig: options.modifyModernConfig
|
|
45
|
+
});
|
|
46
|
+
const nonStandardConfig = {
|
|
47
|
+
...modernConfig,
|
|
48
|
+
plugins: modernConfig.builderPlugins
|
|
49
|
+
};
|
|
50
|
+
const appContext = getAppContext();
|
|
51
|
+
const { rsbuildConfig, rsbuildPlugins } = await (0, builder_namespaceObject.parseRspackConfig)(nonStandardConfig, {
|
|
52
|
+
cwd
|
|
53
|
+
});
|
|
54
|
+
const adapterParams = {
|
|
55
|
+
appContext,
|
|
56
|
+
normalizedConfig: modernConfig
|
|
57
|
+
};
|
|
58
|
+
rsbuildConfig.plugins = [
|
|
59
|
+
...rsbuildPlugins,
|
|
60
|
+
...rsbuildConfig.plugins || [],
|
|
61
|
+
(0, index_js_namespaceObject.builderPluginAdapterBasic)(adapterParams),
|
|
62
|
+
(0, index_js_namespaceObject.builderPluginAdapterHooks)(adapterParams)
|
|
63
|
+
];
|
|
64
|
+
return {
|
|
65
|
+
rsbuildConfig
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
exports.resolveModernRsbuildConfig = __webpack_exports__.resolveModernRsbuildConfig;
|
|
69
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
70
|
+
"resolveModernRsbuildConfig"
|
|
71
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
72
|
+
Object.defineProperty(exports, '__esModule', {
|
|
73
|
+
value: true
|
|
74
|
+
});
|
|
@@ -39,7 +39,7 @@ const external_path_namespaceObject = require("path");
|
|
|
39
39
|
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
40
40
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
41
41
|
const external_constants_js_namespaceObject = require("../constants.js");
|
|
42
|
-
const getConfigFile = (configFile)=>(0, utils_namespaceObject.findExists)(utils_namespaceObject.CONFIG_FILE_EXTENSIONS.map((extension)=>external_path_default().resolve(
|
|
42
|
+
const getConfigFile = (configFile, cwd = process.cwd())=>(0, utils_namespaceObject.findExists)(utils_namespaceObject.CONFIG_FILE_EXTENSIONS.map((extension)=>external_path_default().resolve(cwd, `${configFile || external_constants_js_namespaceObject.DEFAULT_CONFIG_FILE}${extension}`)));
|
|
43
43
|
exports.getConfigFile = __webpack_exports__.getConfigFile;
|
|
44
44
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
45
45
|
"getConfigFile"
|
|
@@ -38,19 +38,11 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
38
38
|
const external_node_path_namespaceObject = require("node:path");
|
|
39
39
|
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
40
40
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
41
|
-
const checkDepExist = (dep, appDir)=>{
|
|
42
|
-
try {
|
|
43
|
-
(0, utils_namespaceObject.tryResolve)(dep, appDir, process.cwd());
|
|
44
|
-
return true;
|
|
45
|
-
} catch {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
41
|
const setupTsRuntime = async (appDir, distDir, alias)=>{
|
|
50
42
|
const TS_CONFIG_FILENAME = "tsconfig.json";
|
|
51
43
|
const tsconfigPath = external_node_path_default().resolve(appDir, TS_CONFIG_FILENAME);
|
|
52
44
|
const isTsProject = await utils_namespaceObject.fs.pathExists(tsconfigPath);
|
|
53
|
-
const hasTsNode =
|
|
45
|
+
const hasTsNode = (0, utils_namespaceObject.isDepExists)(appDir, 'ts-node');
|
|
54
46
|
if (!isTsProject || !hasTsNode) return;
|
|
55
47
|
const aliasConfig = (0, utils_namespaceObject.getAliasConfig)(alias, {
|
|
56
48
|
appDirectory: appDir,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import node_path from "node:path";
|
|
1
2
|
import { SERVICE_WORKER_ENVIRONMENT_NAME } from "@modern-js/builder";
|
|
2
|
-
import * as __rspack_external_node_path_c5b9b54f from "node:path";
|
|
3
3
|
const builderPluginAdapterBasic = (options)=>({
|
|
4
4
|
name: 'builder-plugin-adapter-modern-basic',
|
|
5
5
|
setup (api) {
|
|
@@ -10,7 +10,7 @@ const builderPluginAdapterBasic = (options)=>({
|
|
|
10
10
|
const bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
|
|
11
11
|
const depExt = 'mjs';
|
|
12
12
|
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(bareServerModuleReg);
|
|
13
|
-
chain.module.rule('bare-server-module').test(bareServerModuleReg).use('server-module-loader').loader(
|
|
13
|
+
chain.module.rule('bare-server-module').test(bareServerModuleReg).use('server-module-loader').loader(node_path.join(__dirname, `../loaders/serverModuleLoader.${depExt}`));
|
|
14
14
|
}
|
|
15
15
|
const { appContext } = options;
|
|
16
16
|
const { metaName } = appContext;
|
|
@@ -2,7 +2,7 @@ import { resolve, sep } from "path";
|
|
|
2
2
|
import { SERVICE_WORKER_ENVIRONMENT_NAME, isHtmlDisabled } from "@modern-js/builder";
|
|
3
3
|
import { fs, isUseRsc, isUseSSRBundle } from "@modern-js/utils";
|
|
4
4
|
import { mergeRsbuildConfig } from "@rsbuild/core";
|
|
5
|
-
import {
|
|
5
|
+
import { getServerCombinedModuleFile } from "../../../plugins/analyze/utils.mjs";
|
|
6
6
|
import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins/index.mjs";
|
|
7
7
|
const builderPluginAdapterSSR = (options)=>({
|
|
8
8
|
name: 'builder-plugin-adapter-modern-ssr',
|
|
@@ -99,7 +99,7 @@ async function applySSRLoaderEntry(chain, optinos, isServer) {
|
|
|
99
99
|
const { entrypoints } = appContext;
|
|
100
100
|
await Promise.all(entrypoints.map(async (entrypoint)=>{
|
|
101
101
|
const { entryName } = entrypoint;
|
|
102
|
-
const serverLoadersFile =
|
|
102
|
+
const serverLoadersFile = getServerCombinedModuleFile(internalDirectory, entryName);
|
|
103
103
|
if (isServer) try {
|
|
104
104
|
await fs.access(serverLoadersFile, fs.constants.F_OK);
|
|
105
105
|
chain.entry(`${entryName}-server-loaders`).add(serverLoadersFile);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import node_path from "node:path";
|
|
1
2
|
import { fs, logger } from "@modern-js/utils";
|
|
2
3
|
import { loadServerPlugins } from "../utils/loadPlugins.mjs";
|
|
3
4
|
import { setupTsRuntime } from "../utils/register.mjs";
|
|
4
5
|
import { generateRoutes } from "../utils/routes.mjs";
|
|
5
|
-
import * as __rspack_external_node_path_c5b9b54f from "node:path";
|
|
6
6
|
async function copyEnvFiles(appDirectory, distDirectory) {
|
|
7
7
|
try {
|
|
8
8
|
const files = await fs.readdir(appDirectory);
|
|
@@ -10,8 +10,8 @@ async function copyEnvFiles(appDirectory, distDirectory) {
|
|
|
10
10
|
const envFiles = files.filter((file)=>envFileRegex.test(file));
|
|
11
11
|
if (0 === envFiles.length) return void logger.debug('No .env files found to copy');
|
|
12
12
|
const copyPromises = envFiles.map(async (envFile)=>{
|
|
13
|
-
const sourcePath =
|
|
14
|
-
const targetPath =
|
|
13
|
+
const sourcePath = node_path.resolve(appDirectory, envFile);
|
|
14
|
+
const targetPath = node_path.resolve(distDirectory, envFile);
|
|
15
15
|
try {
|
|
16
16
|
const stat = await fs.stat(sourcePath);
|
|
17
17
|
if (stat.isDirectory()) return;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import node_path from "node:path";
|
|
2
|
+
import { applyPlugins } from "@modern-js/prod-server";
|
|
1
3
|
import { createDevServer } from "@modern-js/server";
|
|
2
4
|
import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta, logger } from "@modern-js/utils";
|
|
3
5
|
import { setServer } from "../utils/createServer.mjs";
|
|
@@ -5,8 +7,6 @@ import { loadServerPlugins } from "../utils/loadPlugins.mjs";
|
|
|
5
7
|
import { printInstructions } from "../utils/printInstructions.mjs";
|
|
6
8
|
import { setupTsRuntime } from "../utils/register.mjs";
|
|
7
9
|
import { generateRoutes } from "../utils/routes.mjs";
|
|
8
|
-
import * as __rspack_external_node_path_c5b9b54f from "node:path";
|
|
9
|
-
import * as __rspack_external__modern_js_prod_server_057184e2 from "@modern-js/prod-server";
|
|
10
10
|
const dev = async (api, options, devServerOptions)=>{
|
|
11
11
|
if (options.analyze) process.env.BUNDLE_ANALYZE = 'true';
|
|
12
12
|
const normalizedConfig = api.getNormalizedConfig();
|
|
@@ -24,7 +24,7 @@ const dev = async (api, options, devServerOptions)=>{
|
|
|
24
24
|
await setupTsRuntime(appContext.appDirectory, appContext.distDirectory, combinedAlias);
|
|
25
25
|
const { appDirectory, port, apiOnly, metaName, serverRoutes } = appContext;
|
|
26
26
|
const meta = getMeta(metaName);
|
|
27
|
-
const serverConfigPath =
|
|
27
|
+
const serverConfigPath = node_path.resolve(appDirectory, SERVER_DIR, `${meta}.server`);
|
|
28
28
|
await hooks.onBeforeDev.call();
|
|
29
29
|
if (!appContext.builder && !apiOnly) throw new Error('Expect the Builder to have been initialized, But the appContext.builder received `undefined`');
|
|
30
30
|
await generateRoutes(appContext);
|
|
@@ -55,7 +55,7 @@ const dev = async (api, options, devServerOptions)=>{
|
|
|
55
55
|
const { server } = await createDevServer({
|
|
56
56
|
...serverOptions,
|
|
57
57
|
runCompile: false
|
|
58
|
-
}, devServerOptions?.applyPlugins ||
|
|
58
|
+
}, devServerOptions?.applyPlugins || applyPlugins);
|
|
59
59
|
server.listen({
|
|
60
60
|
port,
|
|
61
61
|
host
|
|
@@ -67,7 +67,7 @@ const dev = async (api, options, devServerOptions)=>{
|
|
|
67
67
|
const { server, afterListen } = await createDevServer({
|
|
68
68
|
...serverOptions,
|
|
69
69
|
builder: appContext.builder
|
|
70
|
-
}, devServerOptions?.applyPlugins ||
|
|
70
|
+
}, devServerOptions?.applyPlugins || applyPlugins);
|
|
71
71
|
server.listen({
|
|
72
72
|
port,
|
|
73
73
|
host
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
+
import { createProdServer } from "@modern-js/prod-server";
|
|
2
3
|
import { SERVER_DIR, getMeta, getTargetDir, isApiOnly, logger } from "@modern-js/utils";
|
|
3
4
|
import { loadServerPlugins } from "../utils/loadPlugins.mjs";
|
|
4
5
|
import { printInstructions } from "../utils/printInstructions.mjs";
|
|
5
|
-
import * as __rspack_external__modern_js_prod_server_057184e2 from "@modern-js/prod-server";
|
|
6
6
|
const serve = async (api, serverOptions)=>{
|
|
7
7
|
const appContext = api.getAppContext();
|
|
8
8
|
const userConfig = api.getNormalizedConfig();
|
|
@@ -16,7 +16,7 @@ const serve = async (api, serverOptions)=>{
|
|
|
16
16
|
const meta = getMeta(metaName);
|
|
17
17
|
const serverConfigPath = path.resolve(distDirectory, SERVER_DIR, `${meta}.server`);
|
|
18
18
|
const pluginInstances = await loadServerPlugins(api, appDirectory, metaName);
|
|
19
|
-
const app = await (serverOptions?.launcher ||
|
|
19
|
+
const app = await (serverOptions?.launcher || createProdServer)({
|
|
20
20
|
metaName,
|
|
21
21
|
pwd: distDirectory,
|
|
22
22
|
config: {
|
|
@@ -4,7 +4,7 @@ function createDefaultConfig(appContext) {
|
|
|
4
4
|
const dev = {
|
|
5
5
|
cliShortcuts: {
|
|
6
6
|
help: false,
|
|
7
|
-
custom: (shortcuts = [])=>shortcuts.filter(({ key })=>'r' !== key && 'u' !== key)
|
|
7
|
+
custom: (shortcuts = [])=>shortcuts.filter(({ key })=>'r' !== key && 'u' !== key && 'o' !== key)
|
|
8
8
|
}
|
|
9
9
|
};
|
|
10
10
|
const output = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import node_path from "node:path";
|
|
1
2
|
import { fs } from "@modern-js/utils";
|
|
2
|
-
import * as __rspack_external_node_path_c5b9b54f from "node:path";
|
|
3
3
|
const checkDepExist = async (dep)=>{
|
|
4
4
|
try {
|
|
5
5
|
await import(dep);
|
|
@@ -10,7 +10,7 @@ const checkDepExist = async (dep)=>{
|
|
|
10
10
|
};
|
|
11
11
|
const registerModuleHooks = async ({ appDir, distDir, alias })=>{
|
|
12
12
|
const TS_CONFIG_FILENAME = "tsconfig.json";
|
|
13
|
-
const tsconfigPath =
|
|
13
|
+
const tsconfigPath = node_path.resolve(appDir, TS_CONFIG_FILENAME);
|
|
14
14
|
const hasTsconfig = await fs.pathExists(tsconfigPath);
|
|
15
15
|
const hasTsNode = await checkDepExist('ts-node');
|
|
16
16
|
if (!hasTsconfig || !hasTsNode) return;
|
|
@@ -19,7 +19,7 @@ const registerModuleHooks = async ({ appDir, distDir, alias })=>{
|
|
|
19
19
|
process.env.TS_NODE_PROJECT = tsconfigPath;
|
|
20
20
|
process.env.TS_NODE_SCOPE = true;
|
|
21
21
|
process.env.TS_NODE_FILES = true;
|
|
22
|
-
process.env.TS_NODE_IGNORE = `(?:^|/)node_modules/,(?:^|/)${
|
|
22
|
+
process.env.TS_NODE_IGNORE = `(?:^|/)node_modules/,(?:^|/)${node_path.relative(appDir, distDir)}/`;
|
|
23
23
|
register('./ts-node-loader.mjs', import.meta.url, {
|
|
24
24
|
data: {
|
|
25
25
|
appDir,
|
package/dist/esm/index.mjs
CHANGED
|
@@ -18,6 +18,7 @@ import { restart } from "./utils/restart.mjs";
|
|
|
18
18
|
import { defineConfig } from "./defineConfig.mjs";
|
|
19
19
|
import { dev } from "./commands/dev.mjs";
|
|
20
20
|
import { serve } from "./commands/serve.mjs";
|
|
21
|
+
import { resolveModernRsbuildConfig } from "./rsbuild.mjs";
|
|
21
22
|
import { mergeConfig } from "@modern-js/plugin/cli";
|
|
22
23
|
export * from "./defineConfig.mjs";
|
|
23
24
|
export * from "./types/index.mjs";
|
|
@@ -119,4 +120,4 @@ const appTools = ()=>({
|
|
|
119
120
|
}
|
|
120
121
|
});
|
|
121
122
|
const src = appTools;
|
|
122
|
-
export { appTools, src as default, defineConfig, dev, generateWatchFiles, initAppContext, mergeConfig, serve };
|
|
123
|
+
export { appTools, src as default, defineConfig, dev, generateWatchFiles, initAppContext, mergeConfig, resolveModernRsbuildConfig, serve };
|
|
@@ -29,7 +29,7 @@ const parseModule = async ({ source, filename })=>{
|
|
|
29
29
|
}
|
|
30
30
|
return await parse(content);
|
|
31
31
|
};
|
|
32
|
-
const
|
|
32
|
+
const getServerCombinedModuleFile = (internalDirectory, entryName)=>path.join(internalDirectory, entryName, 'server-loader-combined.js');
|
|
33
33
|
const checkIsBuildCommands = ()=>{
|
|
34
34
|
const buildCommands = [
|
|
35
35
|
'dev',
|
|
@@ -52,4 +52,4 @@ const isSubDirOrEqual = (parent, child)=>{
|
|
|
52
52
|
const isSubdir = relative && !relative.startsWith('..') && !path.isAbsolute(relative);
|
|
53
53
|
return Boolean(isSubdir);
|
|
54
54
|
};
|
|
55
|
-
export { checkIsBuildCommands, checkIsServeCommand,
|
|
55
|
+
export { checkIsBuildCommands, checkIsServeCommand, getServerCombinedModuleFile, isSubDirOrEqual, parseModule, replaceWithAlias, walkDirectory };
|