@modern-js/app-tools 3.0.5 → 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/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/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/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/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/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/utils/loadPlugins.mjs +4 -4
- package/dist/esm-node/utils/register.mjs +6 -14
- 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/package.json +12 -11
- 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
|
@@ -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.writeFile(entryFilePath, "import { handler } from './vercel-handler.cjs';\nexport default handler;\n");
|
|
146
|
-
else await utils_namespaceObject.fs.writeFile(entryFilePath, "const { handler } = require('./vercel-handler.cjs');\nmodule.exports = handler;\n");
|
|
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
|
|
@@ -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,
|
|
@@ -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 };
|
|
@@ -3,20 +3,25 @@ import { createGhPagesPreset } from "./platforms/gh-pages.mjs";
|
|
|
3
3
|
import { createNetlifyPreset } from "./platforms/netlify.mjs";
|
|
4
4
|
import { createNodePreset } from "./platforms/node.mjs";
|
|
5
5
|
import { createVercelPreset } from "./platforms/vercel.mjs";
|
|
6
|
-
import { getProjectUsage } from "./utils.mjs";
|
|
6
|
+
import { getProjectUsage } from "./utils/index.mjs";
|
|
7
7
|
const deployPresets = {
|
|
8
8
|
node: createNodePreset,
|
|
9
9
|
vercel: createVercelPreset,
|
|
10
10
|
netlify: createNetlifyPreset,
|
|
11
11
|
ghPages: createGhPagesPreset
|
|
12
12
|
};
|
|
13
|
-
async function getDeployPreset(appContext, modernConfig, deployTarget) {
|
|
13
|
+
async function getDeployPreset(appContext, modernConfig, deployTarget, api) {
|
|
14
14
|
const { appDirectory, distDirectory, metaName } = appContext;
|
|
15
15
|
const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory, metaName);
|
|
16
16
|
const needModernServer = useSSR || useAPI || useWebServer;
|
|
17
17
|
const createPreset = deployPresets[deployTarget];
|
|
18
18
|
if (!createPreset) throw new Error(`Unknown deploy target: '${deployTarget}'. MODERNJS_DEPLOY should be 'node', 'vercel', or 'netlify'.`);
|
|
19
|
-
return createPreset(
|
|
19
|
+
return createPreset({
|
|
20
|
+
appContext,
|
|
21
|
+
modernConfig,
|
|
22
|
+
needModernServer,
|
|
23
|
+
api
|
|
24
|
+
});
|
|
20
25
|
}
|
|
21
26
|
const deploy = ()=>({
|
|
22
27
|
name: '@modern-js/plugin-deploy',
|
|
@@ -27,7 +32,7 @@ const deploy = ()=>({
|
|
|
27
32
|
const { metaName } = appContext;
|
|
28
33
|
if ('modern-js' !== metaName && !process.env.MODERNJS_DEPLOY) return;
|
|
29
34
|
const modernConfig = api.getNormalizedConfig();
|
|
30
|
-
const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget);
|
|
35
|
+
const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget, api);
|
|
31
36
|
deployPreset?.prepare && await deployPreset?.prepare();
|
|
32
37
|
deployPreset?.writeOutput && await deployPreset?.writeOutput();
|
|
33
38
|
deployPreset?.genEntry && await deployPreset?.genEntry();
|
|
@@ -23,7 +23,7 @@ async function reorganizeHtmlFiles(routes, baseDir, baseUrl = '/') {
|
|
|
23
23
|
});
|
|
24
24
|
await Promise.all(copyPromises);
|
|
25
25
|
}
|
|
26
|
-
const createGhPagesPreset = (appContext, modernConfig)=>{
|
|
26
|
+
const createGhPagesPreset = ({ appContext, modernConfig })=>{
|
|
27
27
|
const { serverRoutes, appDirectory, distDirectory } = appContext;
|
|
28
28
|
const { server: { baseUrl } } = modernConfig;
|
|
29
29
|
const outputDirectory = path.join(appDirectory, '.output');
|
|
@@ -1,30 +1,26 @@
|
|
|
1
|
-
import
|
|
1
|
+
import node_path from "node:path";
|
|
2
|
+
import { fs, removeModuleSyncFromExports } from "@modern-js/utils";
|
|
2
3
|
import { nodeDepEmit } from "ndepe";
|
|
3
4
|
import { isMainEntry } from "../../../utils/routes.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
5
|
+
import { readTemplate, resolveESMDependency } from "../utils/index.mjs";
|
|
6
|
+
import { generateHandler } from "../utils/generator.mjs";
|
|
6
7
|
async function cleanDistDirectory(dir) {
|
|
7
8
|
try {
|
|
8
9
|
const items = await fs.readdir(dir);
|
|
9
10
|
for (const item of items){
|
|
10
|
-
const fullPath =
|
|
11
|
+
const fullPath = node_path.join(dir, item);
|
|
11
12
|
if ('static' !== item && '_redirects' !== item && 'html' !== item) await fs.remove(fullPath);
|
|
12
13
|
}
|
|
13
14
|
} catch (error) {
|
|
14
15
|
console.error('Error cleaning directory:', error);
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
|
-
const createNetlifyPreset = (appContext, modernConfig, needModernServer)=>{
|
|
18
|
-
const { appDirectory, distDirectory, entrypoints,
|
|
18
|
+
const createNetlifyPreset = ({ appContext, modernConfig, needModernServer })=>{
|
|
19
|
+
const { appDirectory, distDirectory, entrypoints, moduleType } = appContext;
|
|
19
20
|
const isEsmProject = 'module' === moduleType;
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
]);
|
|
24
|
-
const netlifyOutput = __rspack_external_node_path_c5b9b54f["default"].join(appDirectory, '.netlify');
|
|
25
|
-
const funcsDirectory = __rspack_external_node_path_c5b9b54f["default"].join(netlifyOutput, 'functions');
|
|
26
|
-
const entryFilePath = __rspack_external_node_path_c5b9b54f["default"].join(funcsDirectory, 'index.js');
|
|
27
|
-
const handlerFilePath = __rspack_external_node_path_c5b9b54f["default"].join(funcsDirectory, 'netlify-handler.cjs');
|
|
21
|
+
const netlifyOutput = node_path.join(appDirectory, '.netlify');
|
|
22
|
+
const funcsDirectory = node_path.join(netlifyOutput, 'functions');
|
|
23
|
+
const entryFilePath = node_path.join(funcsDirectory, 'index.js');
|
|
28
24
|
return {
|
|
29
25
|
async prepare () {
|
|
30
26
|
await fs.remove(netlifyOutput);
|
|
@@ -51,49 +47,37 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer)=>{
|
|
|
51
47
|
await fs.ensureDir(funcsDirectory);
|
|
52
48
|
await fs.copy(distDirectory, funcsDirectory, {
|
|
53
49
|
filter: (src)=>{
|
|
54
|
-
const distStaticDirectory =
|
|
50
|
+
const distStaticDirectory = node_path.join(distDirectory, "static");
|
|
55
51
|
return !src.includes(distStaticDirectory);
|
|
56
52
|
}
|
|
57
53
|
});
|
|
58
54
|
}
|
|
59
|
-
const redirectFilePath =
|
|
55
|
+
const redirectFilePath = node_path.join(distDirectory, '_redirects');
|
|
60
56
|
await fs.writeFile(redirectFilePath, redirectContent);
|
|
61
57
|
},
|
|
62
58
|
async genEntry () {
|
|
63
59
|
if (!needModernServer) return;
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
const meta = getMeta(metaName);
|
|
75
|
-
const pluginImportCode = genPluginImportsCode(plugins || []);
|
|
76
|
-
const dynamicProdOptions = {
|
|
77
|
-
config: serverConfig
|
|
78
|
-
};
|
|
79
|
-
const serverConfigPath = `path.join(__dirname, "${SERVER_DIR}", "${meta}.server")`;
|
|
80
|
-
const pluginsCode = getPluginsCode(plugins);
|
|
81
|
-
let handlerCode = (await fs.readFile(__rspack_external_node_path_c5b9b54f["default"].join(__dirname, './netlify-handler.js'))).toString();
|
|
82
|
-
const serverAppContext = serverAppContenxtTemplate(appContext);
|
|
83
|
-
handlerCode = handlerCode.replace('p_genPluginImportsCode', pluginImportCode).replace('p_ROUTE_SPEC_FILE', `"${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);
|
|
84
|
-
await fs.writeFile(handlerFilePath, handlerCode);
|
|
85
|
-
if (isEsmProject) await fs.writeFile(entryFilePath, "export { handler as default } from './netlify-handler.cjs';\n");
|
|
86
|
-
else await fs.writeFile(entryFilePath, "const { handler } = require('./netlify-handler.cjs');\nexports.handler = handler;\n");
|
|
60
|
+
const template = await readTemplate(`netlify-entry.${isEsmProject ? 'mjs' : 'cjs'}`);
|
|
61
|
+
const code = await generateHandler({
|
|
62
|
+
template,
|
|
63
|
+
appContext,
|
|
64
|
+
config: modernConfig,
|
|
65
|
+
isESM: isEsmProject
|
|
66
|
+
});
|
|
67
|
+
await fs.writeFile(entryFilePath, code);
|
|
87
68
|
},
|
|
88
69
|
async end () {
|
|
89
70
|
if ('development' !== process.env.NODE_ENV) await cleanDistDirectory(distDirectory);
|
|
90
71
|
if (!needModernServer) return;
|
|
72
|
+
const entry = isEsmProject ? await resolveESMDependency('@modern-js/prod-server') : require.resolve('@modern-js/prod-server');
|
|
73
|
+
const netlifyEntry = isEsmProject ? await resolveESMDependency('@modern-js/prod-server/netlify') : require.resolve('@modern-js/prod-server/netlify');
|
|
74
|
+
if (!entry || !netlifyEntry) throw new Error('Cannot find @modern-js/prod-server');
|
|
91
75
|
await nodeDepEmit({
|
|
92
76
|
appDir: appDirectory,
|
|
93
77
|
sourceDir: funcsDirectory,
|
|
94
78
|
includeEntries: [
|
|
95
|
-
|
|
96
|
-
|
|
79
|
+
entry,
|
|
80
|
+
netlifyEntry
|
|
97
81
|
],
|
|
98
82
|
copyWholePackage (pkgName) {
|
|
99
83
|
return '@modern-js/utils' === pkgName;
|