@modern-js/app-tools 3.0.5 → 3.1.1
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 +104 -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/generator/createCopyPattern.mjs +1 -1
- package/dist/esm/builder/index.mjs +3 -3
- package/dist/esm/builder/shared/builderPlugins/adapterBasic.mjs +2 -2
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.mjs +2 -2
- package/dist/esm/builder/shared/loaders/serverModuleLoader.mjs +1 -1
- 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 +9 -8
- package/dist/esm/plugins/analyze/index.mjs +2 -2
- package/dist/esm/plugins/analyze/utils.mjs +2 -2
- package/dist/esm/plugins/deploy/index.mjs +10 -5
- 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 +48 -0
- package/dist/esm/plugins/deploy/utils/index.mjs +40 -0
- package/dist/esm/plugins/initialize/index.mjs +1 -1
- package/dist/esm/plugins/serverBuild.mjs +1 -1
- package/dist/esm/plugins/serverRuntime.mjs +1 -1
- package/dist/esm/utils/loadPlugins.mjs +4 -4
- package/dist/esm/utils/register.mjs +6 -14
- package/dist/esm-node/builder/generator/createCopyPattern.mjs +1 -1
- package/dist/esm-node/builder/index.mjs +3 -3
- 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/builder/shared/loaders/serverModuleLoader.mjs +1 -1
- 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 +9 -8
- package/dist/esm-node/plugins/analyze/index.mjs +1 -1
- package/dist/esm-node/plugins/analyze/utils.mjs +2 -2
- package/dist/esm-node/plugins/deploy/index.mjs +10 -5
- 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 +49 -0
- package/dist/esm-node/plugins/deploy/utils/index.mjs +44 -0
- package/dist/esm-node/plugins/initialize/index.mjs +1 -1
- package/dist/esm-node/plugins/serverBuild.mjs +1 -1
- package/dist/esm-node/plugins/serverRuntime.mjs +1 -1
- 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.cts +2 -0
- 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 +13 -12
- package/rslib.config.mts +19 -0
- package/{rstest.config.ts → rstest.config.mts} +0 -4
- 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/netlify-handler.d.cts +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/{node-entry.d.ts → templates/node-entry.d.cts} +0 -0
|
@@ -1,22 +1,16 @@
|
|
|
1
1
|
import __rslib_shim_module__ from "node:module";
|
|
2
2
|
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { ROUTE_SPEC_FILE, SERVER_DIR, chalk, fs, getMeta, removeModuleSyncFromExports } from "@modern-js/utils";
|
|
3
|
+
import node_path from "node:path";
|
|
4
|
+
import { chalk, fs, removeModuleSyncFromExports } from "@modern-js/utils";
|
|
6
5
|
import { nodeDepEmit } from "ndepe";
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
const { appDirectory, distDirectory, serverPlugins, moduleType, metaName } = appContext;
|
|
6
|
+
import { readTemplate, resolveESMDependency } from "../utils/index.mjs";
|
|
7
|
+
import { generateHandler } from "../utils/generator.mjs";
|
|
8
|
+
const createNodePreset = ({ appContext, modernConfig, api })=>{
|
|
9
|
+
const { appDirectory, distDirectory, moduleType } = appContext;
|
|
12
10
|
const isEsmProject = 'module' === moduleType;
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
]);
|
|
17
|
-
const outputDirectory = __rspack_external_node_path_c5b9b54f["default"].join(appDirectory, '.output');
|
|
18
|
-
const staticDirectory = __rspack_external_node_path_c5b9b54f["default"].join(outputDirectory, 'static');
|
|
19
|
-
const entryFilePath = __rspack_external_node_path_c5b9b54f["default"].join(outputDirectory, 'index.js');
|
|
11
|
+
const outputDirectory = node_path.join(appDirectory, '.output');
|
|
12
|
+
const staticDirectory = node_path.join(outputDirectory, 'static');
|
|
13
|
+
const entryFilePath = node_path.join(outputDirectory, 'index.js');
|
|
20
14
|
return {
|
|
21
15
|
async prepare () {
|
|
22
16
|
await fs.remove(outputDirectory);
|
|
@@ -25,44 +19,24 @@ const createNodePreset = (appContext, config)=>{
|
|
|
25
19
|
await fs.copy(distDirectory, outputDirectory);
|
|
26
20
|
},
|
|
27
21
|
async genEntry () {
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
distPath: {
|
|
37
|
-
root: '.'
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
const pluginImportCode = genPluginImportsCode(plugins || []);
|
|
42
|
-
const dynamicProdOptions = {
|
|
43
|
-
config: serverConfig
|
|
44
|
-
};
|
|
45
|
-
const meta = getMeta(metaName);
|
|
46
|
-
const serverConfigPath = `path.join(__dirname, "${SERVER_DIR}", "${meta}.server")`;
|
|
47
|
-
const pluginsCode = getPluginsCode(plugins);
|
|
48
|
-
let entryCode = (await fs.readFile(__rspack_external_node_path_c5b9b54f["default"].join(node_dirname, './node-entry.js'))).toString();
|
|
49
|
-
const serverAppContext = serverAppContenxtTemplate(appContext);
|
|
50
|
-
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);
|
|
51
|
-
if (isEsmProject) {
|
|
52
|
-
const cjsEntryFilePath = __rspack_external_node_path_c5b9b54f["default"].join(outputDirectory, 'index.cjs');
|
|
53
|
-
await fs.writeFile(cjsEntryFilePath, entryCode);
|
|
54
|
-
await fs.writeFile(entryFilePath, "import('./index.cjs');");
|
|
55
|
-
} else await fs.writeFile(entryFilePath, entryCode);
|
|
22
|
+
const template = await readTemplate(`node-entry.${isEsmProject ? 'mjs' : 'cjs'}`);
|
|
23
|
+
const code = await generateHandler({
|
|
24
|
+
template,
|
|
25
|
+
appContext,
|
|
26
|
+
config: modernConfig,
|
|
27
|
+
isESM: isEsmProject
|
|
28
|
+
});
|
|
29
|
+
await fs.writeFile(entryFilePath, code);
|
|
56
30
|
},
|
|
57
31
|
async end () {
|
|
58
|
-
console.log('Static directory:', chalk.blue(__rspack_external_node_path_c5b9b54f["default"].relative(appDirectory, staticDirectory)));
|
|
59
|
-
console.log("You can preview this build by", chalk.blue("node .output/index"));
|
|
60
32
|
const filter = (filePath)=>!filePath.startsWith(staticDirectory) && !filePath.endsWith('.map');
|
|
33
|
+
const entry = isEsmProject ? await resolveESMDependency('@modern-js/prod-server') : require.resolve('@modern-js/prod-server');
|
|
34
|
+
if (!entry) throw new Error('Cannot find @modern-js/prod-server');
|
|
61
35
|
await nodeDepEmit({
|
|
62
36
|
appDir: appDirectory,
|
|
63
37
|
sourceDir: outputDirectory,
|
|
64
38
|
includeEntries: [
|
|
65
|
-
|
|
39
|
+
entry
|
|
66
40
|
],
|
|
67
41
|
copyWholePackage (pkgName) {
|
|
68
42
|
return '@modern-js/utils' === pkgName;
|
|
@@ -76,6 +50,8 @@ const createNodePreset = (appContext, config)=>{
|
|
|
76
50
|
};
|
|
77
51
|
}
|
|
78
52
|
});
|
|
53
|
+
console.log('Static directory:', chalk.blue(node_path.relative(appDirectory, staticDirectory).replace(/\\/g, '/')));
|
|
54
|
+
console.log("You can preview this build by", chalk.blue('node .output/index'));
|
|
79
55
|
}
|
|
80
56
|
};
|
|
81
57
|
};
|
|
@@ -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
|
+
module.exports.default = 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;
|
|
@@ -1,25 +1,18 @@
|
|
|
1
1
|
import __rslib_shim_module__ from "node:module";
|
|
2
2
|
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { ROUTE_SPEC_FILE, SERVER_DIR, fs, getMeta, removeModuleSyncFromExports } from "@modern-js/utils";
|
|
3
|
+
import node_path from "node:path";
|
|
4
|
+
import { fs, removeModuleSyncFromExports } from "@modern-js/utils";
|
|
6
5
|
import { nodeDepEmit } from "ndepe";
|
|
7
6
|
import { isMainEntry } from "../../../utils/routes.mjs";
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const { appDirectory, distDirectory, entrypoints, serverPlugins, moduleType, metaName } = appContext;
|
|
7
|
+
import { readTemplate, resolveESMDependency } from "../utils/index.mjs";
|
|
8
|
+
import { generateHandler } from "../utils/generator.mjs";
|
|
9
|
+
const createVercelPreset = ({ appContext, modernConfig, needModernServer })=>{
|
|
10
|
+
const { appDirectory, distDirectory, entrypoints, moduleType } = appContext;
|
|
13
11
|
const isEsmProject = 'module' === moduleType;
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const vercelOutput = __rspack_external_node_path_c5b9b54f["default"].join(appDirectory, '.vercel');
|
|
19
|
-
const outputDirectory = __rspack_external_node_path_c5b9b54f["default"].join(vercelOutput, 'output');
|
|
20
|
-
const funcsDirectory = __rspack_external_node_path_c5b9b54f["default"].join(outputDirectory, 'functions', 'index.func');
|
|
21
|
-
const entryFilePath = __rspack_external_node_path_c5b9b54f["default"].join(funcsDirectory, 'index.js');
|
|
22
|
-
const handlerFilePath = __rspack_external_node_path_c5b9b54f["default"].join(funcsDirectory, 'vercel-handler.cjs');
|
|
12
|
+
const vercelOutput = node_path.join(appDirectory, '.vercel');
|
|
13
|
+
const outputDirectory = node_path.join(vercelOutput, 'output');
|
|
14
|
+
const funcsDirectory = node_path.join(outputDirectory, 'functions', 'index.func');
|
|
15
|
+
const entryFilePath = node_path.join(funcsDirectory, 'index.js');
|
|
23
16
|
return {
|
|
24
17
|
async prepare () {
|
|
25
18
|
await fs.remove(vercelOutput);
|
|
@@ -59,21 +52,21 @@ const createVercelPreset = (appContext, modernConfig, needModernServer)=>{
|
|
|
59
52
|
});
|
|
60
53
|
}
|
|
61
54
|
await fs.ensureDir(outputDirectory);
|
|
62
|
-
await fs.writeJSON(
|
|
55
|
+
await fs.writeJSON(node_path.join(outputDirectory, 'config.json'), config, {
|
|
63
56
|
spaces: 2
|
|
64
57
|
});
|
|
65
|
-
const staticDirectory =
|
|
66
|
-
await fs.copy(
|
|
58
|
+
const staticDirectory = node_path.join(outputDirectory, 'static/static');
|
|
59
|
+
await fs.copy(node_path.join(distDirectory, 'static'), staticDirectory);
|
|
67
60
|
if (needModernServer) {
|
|
68
61
|
await fs.ensureDir(funcsDirectory);
|
|
69
62
|
await fs.copy(distDirectory, funcsDirectory, {
|
|
70
63
|
filter: (src)=>{
|
|
71
|
-
const distStaticDirectory =
|
|
64
|
+
const distStaticDirectory = node_path.join(distDirectory, 'static');
|
|
72
65
|
return !src.includes(distStaticDirectory);
|
|
73
66
|
}
|
|
74
67
|
});
|
|
75
68
|
const nodeVersion = process.versions.node.split('.')[0];
|
|
76
|
-
await fs.writeJSON(
|
|
69
|
+
await fs.writeJSON(node_path.join(funcsDirectory, '.vc-config.json'), {
|
|
77
70
|
runtime: `nodejs${nodeVersion}.x`,
|
|
78
71
|
handler: 'index.js',
|
|
79
72
|
launcherType: 'Nodejs',
|
|
@@ -81,44 +74,31 @@ const createVercelPreset = (appContext, modernConfig, needModernServer)=>{
|
|
|
81
74
|
supportsResponseStreaming: true
|
|
82
75
|
});
|
|
83
76
|
} else {
|
|
84
|
-
const destHtmlDirectory =
|
|
85
|
-
const outputHtmlDirectory =
|
|
77
|
+
const destHtmlDirectory = node_path.join(distDirectory, 'html');
|
|
78
|
+
const outputHtmlDirectory = node_path.join(node_path.join(outputDirectory, 'static'), 'html');
|
|
86
79
|
await fs.copy(destHtmlDirectory, outputHtmlDirectory);
|
|
87
80
|
}
|
|
88
81
|
},
|
|
89
82
|
async genEntry () {
|
|
90
83
|
if (!needModernServer) return;
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
const pluginImportCode = genPluginImportsCode(plugins || []);
|
|
102
|
-
const dynamicProdOptions = {
|
|
103
|
-
config: serverConfig
|
|
104
|
-
};
|
|
105
|
-
const meta = getMeta(metaName);
|
|
106
|
-
const serverConfigPath = `path.join(__dirname, "${SERVER_DIR}", "${meta}.server")`;
|
|
107
|
-
const pluginsCode = getPluginsCode(plugins || []);
|
|
108
|
-
const serverAppContext = serverAppContenxtTemplate(appContext);
|
|
109
|
-
let handlerCode = (await fs.readFile(__rspack_external_node_path_c5b9b54f["default"].join(vercel_dirname, './vercel-handler.js'))).toString();
|
|
110
|
-
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_serverDirectory', serverConfigPath).replace('p_sharedDirectory', serverAppContext.sharedDirectory).replace('p_apiDirectory', serverAppContext.apiDirectory).replace('p_lambdaDirectory', serverAppContext.lambdaDirectory);
|
|
111
|
-
await fs.writeFile(handlerFilePath, handlerCode);
|
|
112
|
-
if (isEsmProject) await fs.writeFile(entryFilePath, "import { handler } from './vercel-handler.cjs';\nexport default handler;\n");
|
|
113
|
-
else await fs.writeFile(entryFilePath, "const { handler } = require('./vercel-handler.cjs');\nmodule.exports = handler;\n");
|
|
84
|
+
const template = await readTemplate(`vercel-entry.${isEsmProject ? 'mjs' : 'cjs'}`);
|
|
85
|
+
const code = await generateHandler({
|
|
86
|
+
template,
|
|
87
|
+
appContext,
|
|
88
|
+
config: modernConfig,
|
|
89
|
+
isESM: isEsmProject
|
|
90
|
+
});
|
|
91
|
+
await fs.writeFile(entryFilePath, code);
|
|
114
92
|
},
|
|
115
93
|
async end () {
|
|
116
94
|
if (!needModernServer) return;
|
|
95
|
+
const entry = isEsmProject ? await resolveESMDependency('@modern-js/prod-server') : require.resolve('@modern-js/prod-server');
|
|
96
|
+
if (!entry) throw new Error('Cannot find @modern-js/prod-server');
|
|
117
97
|
await nodeDepEmit({
|
|
118
98
|
appDir: appDirectory,
|
|
119
99
|
sourceDir: funcsDirectory,
|
|
120
100
|
includeEntries: [
|
|
121
|
-
|
|
101
|
+
entry
|
|
122
102
|
],
|
|
123
103
|
copyWholePackage (pkgName) {
|
|
124
104
|
return '@modern-js/utils' === pkgName;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "node:module";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
import { ROUTE_SPEC_FILE, SERVER_DIR, getMeta } from "@modern-js/utils";
|
|
4
|
+
import { merge } from "@modern-js/utils/lodash";
|
|
5
|
+
import { normalizePath } from "./index.mjs";
|
|
6
|
+
const serverAppContextTemplate = (appContext)=>{
|
|
7
|
+
const { appDirectory, sharedDirectory, apiDirectory, lambdaDirectory, metaName, bffRuntimeFramework } = appContext;
|
|
8
|
+
const getRelativePathTemplate = (targetDirectory)=>`path.join(__dirname, ${JSON.stringify(normalizePath(node_path.relative(appDirectory, targetDirectory)))})`;
|
|
9
|
+
return {
|
|
10
|
+
sharedDirectory: getRelativePathTemplate(sharedDirectory),
|
|
11
|
+
apiDirectory: getRelativePathTemplate(apiDirectory),
|
|
12
|
+
lambdaDirectory: getRelativePathTemplate(lambdaDirectory),
|
|
13
|
+
metaName,
|
|
14
|
+
bffRuntimeFramework: bffRuntimeFramework || 'hono'
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
const genPluginImportsCode = (plugins, isESM = false)=>plugins.map(([name, options], index)=>{
|
|
18
|
+
const im = isESM ? `import * as plugin_${index}_ns from '${name}'` : `const plugin_${index}_ns = require('${name}')`;
|
|
19
|
+
return `${im};const plugin_${index} = plugin_${index}_ns.default || plugin_${index}_ns`;
|
|
20
|
+
}).join(';\n');
|
|
21
|
+
const getPluginsCode = (plugins)=>`[${plugins.map(([, options], index)=>`plugin_${index}(${options ? JSON.stringify(options) : ''})`).join(',')}]`;
|
|
22
|
+
const getServerConfigPath = (meta)=>`"${normalizePath(node_path.join(SERVER_DIR, `${meta}.server`))}"`;
|
|
23
|
+
const generateHandler = async ({ template, appContext, config, serverConfig: modifyServerConfig, genAppContextTemplate = serverAppContextTemplate, genPluginImports = genPluginImportsCode, isESM })=>{
|
|
24
|
+
const { serverPlugins, metaName } = appContext;
|
|
25
|
+
const plugins = serverPlugins.map((plugin)=>[
|
|
26
|
+
plugin.name,
|
|
27
|
+
plugin.options
|
|
28
|
+
]);
|
|
29
|
+
const serverConfig = merge({
|
|
30
|
+
bff: {
|
|
31
|
+
prefix: config?.bff?.prefix
|
|
32
|
+
},
|
|
33
|
+
output: {
|
|
34
|
+
distPath: {
|
|
35
|
+
root: '.'
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}, modifyServerConfig || {});
|
|
39
|
+
const meta = getMeta(metaName);
|
|
40
|
+
const pluginImportCode = genPluginImports(plugins || [], Boolean(isESM));
|
|
41
|
+
const dynamicProdOptions = {
|
|
42
|
+
config: serverConfig
|
|
43
|
+
};
|
|
44
|
+
const serverConfigPath = getServerConfigPath(meta);
|
|
45
|
+
const pluginsCode = getPluginsCode(plugins);
|
|
46
|
+
const serverAppContext = genAppContextTemplate(appContext);
|
|
47
|
+
return template.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);
|
|
48
|
+
};
|
|
49
|
+
export { genPluginImportsCode, generateHandler, getPluginsCode, getServerConfigPath, serverAppContextTemplate };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
3
|
+
import { dirname as __rspack_dirname } from "node:path";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import { ROUTE_SPEC_FILE, SERVER_DIR, fs, getMeta } from "@modern-js/utils";
|
|
7
|
+
var utils_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
|
|
8
|
+
const normalizePath = (filePath)=>filePath.replace(/\\/g, '/');
|
|
9
|
+
const getProjectUsage = (appDirectory, distDirectory, metaName)=>{
|
|
10
|
+
const routeJSON = path.join(distDirectory, ROUTE_SPEC_FILE);
|
|
11
|
+
const { routes } = fs.readJSONSync(routeJSON);
|
|
12
|
+
let useSSR = false;
|
|
13
|
+
let useAPI = false;
|
|
14
|
+
routes.forEach((route)=>{
|
|
15
|
+
if (route.isSSR) useSSR = true;
|
|
16
|
+
if (route.isApi) useAPI = true;
|
|
17
|
+
});
|
|
18
|
+
const meta = getMeta(metaName);
|
|
19
|
+
const serverConfigPath = path.resolve(appDirectory, SERVER_DIR, `${meta}.server`);
|
|
20
|
+
const isServerConfigExists = [
|
|
21
|
+
'.ts',
|
|
22
|
+
'.js'
|
|
23
|
+
].some((ex)=>fs.existsSync(`${serverConfigPath}${ex}`));
|
|
24
|
+
return {
|
|
25
|
+
useSSR,
|
|
26
|
+
useAPI,
|
|
27
|
+
useWebServer: isServerConfigExists
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
const getTemplatePath = (file)=>path.join(utils_dirname, '../platforms/templates', file);
|
|
31
|
+
const readTemplate = async (file)=>(await fs.readFile(getTemplatePath(file))).toString();
|
|
32
|
+
const resolveESMDependency = async (entry)=>{
|
|
33
|
+
const conditions = new Set([
|
|
34
|
+
'node',
|
|
35
|
+
'import',
|
|
36
|
+
'module',
|
|
37
|
+
'default'
|
|
38
|
+
]);
|
|
39
|
+
try {
|
|
40
|
+
const { moduleResolve } = await import("import-meta-resolve");
|
|
41
|
+
return normalizePath(moduleResolve(entry, pathToFileURL(`${utils_dirname}/`), conditions, false).pathname.replace(/^\/(\w)\:/, '$1:'));
|
|
42
|
+
} catch (err) {}
|
|
43
|
+
};
|
|
44
|
+
export { getProjectUsage, getTemplatePath, normalizePath, readTemplate, resolveESMDependency };
|