@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
|
@@ -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.copy(__rspack_external_node_path_c5b9b54f["default"].join(__dirname, './netlify-entry.mjs'), entryFilePath);
|
|
86
|
-
else await fs.copy(__rspack_external_node_path_c5b9b54f["default"].join(__dirname, './netlify-entry.js'), entryFilePath);
|
|
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;
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import node_path from "node:path";
|
|
2
|
+
import { chalk, fs, removeModuleSyncFromExports } from "@modern-js/utils";
|
|
2
3
|
import { nodeDepEmit } from "ndepe";
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
const createNodePreset = (appContext,
|
|
6
|
-
const { appDirectory, distDirectory,
|
|
4
|
+
import { readTemplate, resolveESMDependency } from "../utils/index.mjs";
|
|
5
|
+
import { generateHandler } from "../utils/generator.mjs";
|
|
6
|
+
const createNodePreset = ({ appContext, modernConfig, api })=>{
|
|
7
|
+
const { appDirectory, distDirectory, moduleType } = appContext;
|
|
7
8
|
const isEsmProject = 'module' === moduleType;
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
]);
|
|
12
|
-
const outputDirectory = __rspack_external_node_path_c5b9b54f["default"].join(appDirectory, '.output');
|
|
13
|
-
const staticDirectory = __rspack_external_node_path_c5b9b54f["default"].join(outputDirectory, 'static');
|
|
14
|
-
const entryFilePath = __rspack_external_node_path_c5b9b54f["default"].join(outputDirectory, 'index.js');
|
|
9
|
+
const outputDirectory = node_path.join(appDirectory, '.output');
|
|
10
|
+
const staticDirectory = node_path.join(outputDirectory, 'static');
|
|
11
|
+
const entryFilePath = node_path.join(outputDirectory, 'index.js');
|
|
15
12
|
return {
|
|
16
13
|
async prepare () {
|
|
17
14
|
await fs.remove(outputDirectory);
|
|
@@ -20,44 +17,24 @@ const createNodePreset = (appContext, config)=>{
|
|
|
20
17
|
await fs.copy(distDirectory, outputDirectory);
|
|
21
18
|
},
|
|
22
19
|
async genEntry () {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
distPath: {
|
|
32
|
-
root: '.'
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
const pluginImportCode = genPluginImportsCode(plugins || []);
|
|
37
|
-
const dynamicProdOptions = {
|
|
38
|
-
config: serverConfig
|
|
39
|
-
};
|
|
40
|
-
const meta = getMeta(metaName);
|
|
41
|
-
const serverConfigPath = `path.join(__dirname, "${SERVER_DIR}", "${meta}.server")`;
|
|
42
|
-
const pluginsCode = getPluginsCode(plugins);
|
|
43
|
-
let entryCode = (await fs.readFile(__rspack_external_node_path_c5b9b54f["default"].join(__dirname, './node-entry.js'))).toString();
|
|
44
|
-
const serverAppContext = serverAppContenxtTemplate(appContext);
|
|
45
|
-
entryCode = entryCode.replace('p_genPluginImportsCode', pluginImportCode).replace('p_ROUTE_SPEC_FILE', `"${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_bffRuntimeFramework', `"${serverAppContext.bffRuntimeFramework}"`).replace('p_lambdaDirectory', serverAppContext.lambdaDirectory);
|
|
46
|
-
if (isEsmProject) {
|
|
47
|
-
const cjsEntryFilePath = __rspack_external_node_path_c5b9b54f["default"].join(outputDirectory, 'index.cjs');
|
|
48
|
-
await fs.writeFile(cjsEntryFilePath, entryCode);
|
|
49
|
-
await fs.writeFile(entryFilePath, "import('./index.cjs');");
|
|
50
|
-
} else await fs.writeFile(entryFilePath, entryCode);
|
|
20
|
+
const template = await readTemplate(`node-entry.${isEsmProject ? 'mjs' : 'cjs'}`);
|
|
21
|
+
const code = await generateHandler({
|
|
22
|
+
template,
|
|
23
|
+
appContext,
|
|
24
|
+
config: modernConfig,
|
|
25
|
+
isESM: isEsmProject
|
|
26
|
+
});
|
|
27
|
+
await fs.writeFile(entryFilePath, code);
|
|
51
28
|
},
|
|
52
29
|
async end () {
|
|
53
|
-
console.log('Static directory:', chalk.blue(__rspack_external_node_path_c5b9b54f["default"].relative(appDirectory, staticDirectory)));
|
|
54
|
-
console.log("You can preview this build by", chalk.blue("node .output/index"));
|
|
55
30
|
const filter = (filePath)=>!filePath.startsWith(staticDirectory) && !filePath.endsWith('.map');
|
|
31
|
+
const entry = isEsmProject ? await resolveESMDependency('@modern-js/prod-server') : require.resolve('@modern-js/prod-server');
|
|
32
|
+
if (!entry) throw new Error('Cannot find @modern-js/prod-server');
|
|
56
33
|
await nodeDepEmit({
|
|
57
34
|
appDir: appDirectory,
|
|
58
35
|
sourceDir: outputDirectory,
|
|
59
36
|
includeEntries: [
|
|
60
|
-
|
|
37
|
+
entry
|
|
61
38
|
],
|
|
62
39
|
copyWholePackage (pkgName) {
|
|
63
40
|
return '@modern-js/utils' === pkgName;
|
|
@@ -71,6 +48,8 @@ const createNodePreset = (appContext, config)=>{
|
|
|
71
48
|
};
|
|
72
49
|
}
|
|
73
50
|
});
|
|
51
|
+
console.log('Static directory:', chalk.blue(node_path.relative(appDirectory, staticDirectory).replace(/\\/g, '/')));
|
|
52
|
+
console.log("You can preview this build by", chalk.blue('node .output/index'));
|
|
74
53
|
}
|
|
75
54
|
};
|
|
76
55
|
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const fs = require('node:fs/promises');
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
const { createNetlifyFunction } = require('@modern-js/prod-server/netlify');
|
|
4
|
+
p_genPluginImportsCode;
|
|
5
|
+
if (!process.env.NODE_ENV) process.env.NODE_ENV = 'production';
|
|
6
|
+
let requestHandler = null;
|
|
7
|
+
let handlerCreationPromise = null;
|
|
8
|
+
async function loadRoutes(routeFilepath) {
|
|
9
|
+
try {
|
|
10
|
+
await fs.access(routeFilepath);
|
|
11
|
+
const content = await fs.readFile(routeFilepath, 'utf-8');
|
|
12
|
+
const routeSpec = JSON.parse(content);
|
|
13
|
+
return routeSpec.routes || [];
|
|
14
|
+
} catch (error) {
|
|
15
|
+
console.warn('route.json not found or invalid, continuing with empty routes.');
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async function initServer() {
|
|
20
|
+
const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
|
21
|
+
const routes = await loadRoutes(routeFilepath);
|
|
22
|
+
const dynamicProdOptions = p_dynamicProdOptions;
|
|
23
|
+
const prodServerOptions = {
|
|
24
|
+
pwd: __dirname,
|
|
25
|
+
routes,
|
|
26
|
+
disableCustomHook: true,
|
|
27
|
+
appContext: {
|
|
28
|
+
sharedDirectory: p_sharedDirectory,
|
|
29
|
+
apiDirectory: p_apiDirectory,
|
|
30
|
+
lambdaDirectory: p_lambdaDirectory,
|
|
31
|
+
bffRuntimeFramework: p_bffRuntimeFramework
|
|
32
|
+
},
|
|
33
|
+
plugins: p_plugins,
|
|
34
|
+
serverConfigPath: p_serverDirectory,
|
|
35
|
+
...dynamicProdOptions
|
|
36
|
+
};
|
|
37
|
+
const requestHandler = await createNetlifyFunction(prodServerOptions);
|
|
38
|
+
return requestHandler;
|
|
39
|
+
}
|
|
40
|
+
async function createHandler() {
|
|
41
|
+
if (!handlerCreationPromise) handlerCreationPromise = (async ()=>{
|
|
42
|
+
try {
|
|
43
|
+
requestHandler = await initServer();
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.error('Error creating server:', error);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
})();
|
|
49
|
+
await handlerCreationPromise;
|
|
50
|
+
return requestHandler;
|
|
51
|
+
}
|
|
52
|
+
createHandler();
|
|
53
|
+
const handler = async (request, context)=>{
|
|
54
|
+
if (!requestHandler) await createHandler();
|
|
55
|
+
return requestHandler(request, context);
|
|
56
|
+
};
|
|
57
|
+
exports.handler = handler;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import { createNetlifyFunction } from '@modern-js/prod-server/netlify';
|
|
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
|
+
bffRuntimeFramework: p_bffRuntimeFramework
|
|
34
|
+
},
|
|
35
|
+
plugins: p_plugins,
|
|
36
|
+
serverConfigPath: p_serverDirectory,
|
|
37
|
+
...dynamicProdOptions
|
|
38
|
+
};
|
|
39
|
+
const requestHandler = await createNetlifyFunction(prodServerOptions);
|
|
40
|
+
return requestHandler;
|
|
41
|
+
}
|
|
42
|
+
async function createHandler() {
|
|
43
|
+
if (!handlerCreationPromise) handlerCreationPromise = (async ()=>{
|
|
44
|
+
try {
|
|
45
|
+
requestHandler = await initServer();
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error('Error creating server:', error);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
})();
|
|
51
|
+
await handlerCreationPromise;
|
|
52
|
+
return requestHandler;
|
|
53
|
+
}
|
|
54
|
+
createHandler();
|
|
55
|
+
const handler = async (request, context)=>{
|
|
56
|
+
if (!requestHandler) await createHandler();
|
|
57
|
+
return requestHandler(request, context);
|
|
58
|
+
};
|
|
59
|
+
export default handler;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const fs = require('node:fs/promises');
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
const { createProdServer } = require('@modern-js/prod-server');
|
|
4
|
+
p_genPluginImportsCode;
|
|
5
|
+
if (!process.env.NODE_ENV) process.env.NODE_ENV = 'production';
|
|
6
|
+
async function loadRoutes(routeFilepath) {
|
|
7
|
+
try {
|
|
8
|
+
await fs.access(routeFilepath);
|
|
9
|
+
const content = await fs.readFile(routeFilepath, 'utf-8');
|
|
10
|
+
const routeSpec = JSON.parse(content);
|
|
11
|
+
return routeSpec.routes || [];
|
|
12
|
+
} catch (error) {
|
|
13
|
+
console.warn('route.json not found or invalid, continuing with empty routes.');
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async function main() {
|
|
18
|
+
const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
|
19
|
+
const routes = await loadRoutes(routeFilepath);
|
|
20
|
+
const dynamicProdOptions = p_dynamicProdOptions;
|
|
21
|
+
const prodServerOptions = {
|
|
22
|
+
pwd: __dirname,
|
|
23
|
+
routes,
|
|
24
|
+
disableCustomHook: true,
|
|
25
|
+
appContext: {
|
|
26
|
+
sharedDirectory: p_sharedDirectory,
|
|
27
|
+
apiDirectory: p_apiDirectory,
|
|
28
|
+
lambdaDirectory: p_lambdaDirectory,
|
|
29
|
+
bffRuntimeFramework: p_bffRuntimeFramework
|
|
30
|
+
},
|
|
31
|
+
plugins: p_plugins,
|
|
32
|
+
serverConfigPath: p_serverDirectory,
|
|
33
|
+
...dynamicProdOptions
|
|
34
|
+
};
|
|
35
|
+
const app = await createProdServer(prodServerOptions);
|
|
36
|
+
const port = process.env.PORT || 8080;
|
|
37
|
+
app.listen({
|
|
38
|
+
host: '::',
|
|
39
|
+
port
|
|
40
|
+
}, ()=>{
|
|
41
|
+
console.log(`\x1b[32mServer is listening on http://[::]:${port}`, '\x1b[0m');
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
main();
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
async function loadRoutes(routeFilepath) {
|
|
9
|
+
try {
|
|
10
|
+
await fs.access(routeFilepath);
|
|
11
|
+
const content = await fs.readFile(routeFilepath, 'utf-8');
|
|
12
|
+
const routeSpec = JSON.parse(content);
|
|
13
|
+
return routeSpec.routes || [];
|
|
14
|
+
} catch (error) {
|
|
15
|
+
console.warn('route.json not found or invalid, continuing with empty routes.');
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async function main() {
|
|
20
|
+
const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
|
21
|
+
const routes = await loadRoutes(routeFilepath);
|
|
22
|
+
const dynamicProdOptions = p_dynamicProdOptions;
|
|
23
|
+
const prodServerOptions = {
|
|
24
|
+
pwd: __dirname,
|
|
25
|
+
routes,
|
|
26
|
+
disableCustomHook: true,
|
|
27
|
+
appContext: {
|
|
28
|
+
sharedDirectory: p_sharedDirectory,
|
|
29
|
+
apiDirectory: p_apiDirectory,
|
|
30
|
+
lambdaDirectory: p_lambdaDirectory,
|
|
31
|
+
bffRuntimeFramework: p_bffRuntimeFramework
|
|
32
|
+
},
|
|
33
|
+
plugins: p_plugins,
|
|
34
|
+
serverConfigPath: p_serverDirectory,
|
|
35
|
+
...dynamicProdOptions
|
|
36
|
+
};
|
|
37
|
+
const app = await createProdServer(prodServerOptions);
|
|
38
|
+
const port = process.env.PORT || 8080;
|
|
39
|
+
app.listen({
|
|
40
|
+
host: '::',
|
|
41
|
+
port
|
|
42
|
+
}, ()=>{
|
|
43
|
+
console.log(`\x1b[32mServer is listening on http://[::]:${port}`, '\x1b[0m');
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
main();
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const fs = require('node:fs/promises');
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
const { createProdServer } = require('@modern-js/prod-server');
|
|
4
|
+
p_genPluginImportsCode;
|
|
5
|
+
if (!process.env.NODE_ENV) process.env.NODE_ENV = 'production';
|
|
6
|
+
let requestHandler = null;
|
|
7
|
+
let handlerCreationPromise = null;
|
|
8
|
+
async function loadRoutes(routeFilepath) {
|
|
9
|
+
try {
|
|
10
|
+
await fs.access(routeFilepath);
|
|
11
|
+
const content = await fs.readFile(routeFilepath, 'utf-8');
|
|
12
|
+
const routeSpec = JSON.parse(content);
|
|
13
|
+
return routeSpec.routes || [];
|
|
14
|
+
} catch (error) {
|
|
15
|
+
console.warn('route.json not found or invalid, continuing with empty routes.');
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async function initServer() {
|
|
20
|
+
const routeFilepath = path.join(__dirname, p_ROUTE_SPEC_FILE);
|
|
21
|
+
const routes = await loadRoutes(routeFilepath);
|
|
22
|
+
const dynamicProdOptions = p_dynamicProdOptions;
|
|
23
|
+
const prodServerOptions = {
|
|
24
|
+
pwd: __dirname,
|
|
25
|
+
routes,
|
|
26
|
+
disableCustomHook: true,
|
|
27
|
+
appContext: {
|
|
28
|
+
sharedDirectory: p_sharedDirectory,
|
|
29
|
+
apiDirectory: p_apiDirectory,
|
|
30
|
+
lambdaDirectory: p_lambdaDirectory
|
|
31
|
+
},
|
|
32
|
+
plugins: p_plugins,
|
|
33
|
+
serverConfigPath: p_serverDirectory,
|
|
34
|
+
...dynamicProdOptions
|
|
35
|
+
};
|
|
36
|
+
const app = await createProdServer(prodServerOptions);
|
|
37
|
+
return app.getRequestListener();
|
|
38
|
+
}
|
|
39
|
+
async function createHandler() {
|
|
40
|
+
if (!handlerCreationPromise) handlerCreationPromise = (async ()=>{
|
|
41
|
+
try {
|
|
42
|
+
requestHandler = await initServer();
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.error('Error creating server:', error);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
})();
|
|
48
|
+
await handlerCreationPromise;
|
|
49
|
+
return requestHandler;
|
|
50
|
+
}
|
|
51
|
+
createHandler();
|
|
52
|
+
const handler = async (req, res)=>{
|
|
53
|
+
if (!requestHandler) await createHandler();
|
|
54
|
+
return requestHandler(req, res);
|
|
55
|
+
};
|
|
56
|
+
module.exports = handler;
|
|
@@ -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;
|