@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
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import node_path from "node:path";
|
|
2
|
+
import { ROUTE_SPEC_FILE, SERVER_DIR, getMeta } from "@modern-js/utils";
|
|
3
|
+
import { merge } from "@modern-js/utils/lodash";
|
|
4
|
+
import { normalizePath } from "./index.mjs";
|
|
5
|
+
const serverAppContextTemplate = (appContext)=>{
|
|
6
|
+
const { appDirectory, sharedDirectory, apiDirectory, lambdaDirectory, metaName, bffRuntimeFramework } = appContext;
|
|
7
|
+
const getRelativePathTemplate = (targetDirectory)=>`path.join(__dirname, ${JSON.stringify(normalizePath(node_path.relative(appDirectory, targetDirectory)))})`;
|
|
8
|
+
return {
|
|
9
|
+
sharedDirectory: getRelativePathTemplate(sharedDirectory),
|
|
10
|
+
apiDirectory: getRelativePathTemplate(apiDirectory),
|
|
11
|
+
lambdaDirectory: getRelativePathTemplate(lambdaDirectory),
|
|
12
|
+
metaName,
|
|
13
|
+
bffRuntimeFramework: bffRuntimeFramework || 'hono'
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
const genPluginImportsCode = (plugins, isESM = false)=>plugins.map(([name, options], index)=>{
|
|
17
|
+
const im = isESM ? `import * as plugin_${index}_ns from '${name}'` : `const plugin_${index}_ns = require('${name}')`;
|
|
18
|
+
return `${im};const plugin_${index} = plugin_${index}_ns.default || plugin_${index}_ns`;
|
|
19
|
+
}).join(';\n');
|
|
20
|
+
const getPluginsCode = (plugins)=>`[${plugins.map(([, options], index)=>`plugin_${index}(${options ? JSON.stringify(options) : ''})`).join(',')}]`;
|
|
21
|
+
const getServerConfigPath = (meta)=>`"${normalizePath(node_path.join(SERVER_DIR, `${meta}.server`))}"`;
|
|
22
|
+
const generateHandler = async ({ template, appContext, config, serverConfig: modifyServerConfig, genAppContextTemplate = serverAppContextTemplate, genPluginImports = genPluginImportsCode, isESM })=>{
|
|
23
|
+
const { serverPlugins, metaName } = appContext;
|
|
24
|
+
const plugins = serverPlugins.map((plugin)=>[
|
|
25
|
+
plugin.name,
|
|
26
|
+
plugin.options
|
|
27
|
+
]);
|
|
28
|
+
const serverConfig = merge({
|
|
29
|
+
bff: {
|
|
30
|
+
prefix: config?.bff?.prefix
|
|
31
|
+
},
|
|
32
|
+
output: {
|
|
33
|
+
distPath: {
|
|
34
|
+
root: '.'
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}, modifyServerConfig || {});
|
|
38
|
+
const meta = getMeta(metaName);
|
|
39
|
+
const pluginImportCode = genPluginImports(plugins || [], Boolean(isESM));
|
|
40
|
+
const dynamicProdOptions = {
|
|
41
|
+
config: serverConfig
|
|
42
|
+
};
|
|
43
|
+
const serverConfigPath = getServerConfigPath(meta);
|
|
44
|
+
const pluginsCode = getPluginsCode(plugins);
|
|
45
|
+
const serverAppContext = genAppContextTemplate(appContext);
|
|
46
|
+
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);
|
|
47
|
+
};
|
|
48
|
+
export { genPluginImportsCode, generateHandler, getPluginsCode, getServerConfigPath, serverAppContextTemplate };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { pathToFileURL } from "node:url";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { ROUTE_SPEC_FILE, SERVER_DIR, fs, getMeta } from "@modern-js/utils";
|
|
4
|
+
const normalizePath = (filePath)=>filePath.replace(/\\/g, '/');
|
|
5
|
+
const getProjectUsage = (appDirectory, distDirectory, metaName)=>{
|
|
6
|
+
const routeJSON = path.join(distDirectory, ROUTE_SPEC_FILE);
|
|
7
|
+
const { routes } = fs.readJSONSync(routeJSON);
|
|
8
|
+
let useSSR = false;
|
|
9
|
+
let useAPI = false;
|
|
10
|
+
routes.forEach((route)=>{
|
|
11
|
+
if (route.isSSR) useSSR = true;
|
|
12
|
+
if (route.isApi) useAPI = true;
|
|
13
|
+
});
|
|
14
|
+
const meta = getMeta(metaName);
|
|
15
|
+
const serverConfigPath = path.resolve(appDirectory, SERVER_DIR, `${meta}.server`);
|
|
16
|
+
const isServerConfigExists = [
|
|
17
|
+
'.ts',
|
|
18
|
+
'.js'
|
|
19
|
+
].some((ex)=>fs.existsSync(`${serverConfigPath}${ex}`));
|
|
20
|
+
return {
|
|
21
|
+
useSSR,
|
|
22
|
+
useAPI,
|
|
23
|
+
useWebServer: isServerConfigExists
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const getTemplatePath = (file)=>path.join(__dirname, '../platforms/templates', file);
|
|
27
|
+
const readTemplate = async (file)=>(await fs.readFile(getTemplatePath(file))).toString();
|
|
28
|
+
const resolveESMDependency = async (entry)=>{
|
|
29
|
+
const conditions = new Set([
|
|
30
|
+
'node',
|
|
31
|
+
'import',
|
|
32
|
+
'module',
|
|
33
|
+
'default'
|
|
34
|
+
]);
|
|
35
|
+
try {
|
|
36
|
+
const { moduleResolve } = await import("import-meta-resolve");
|
|
37
|
+
return normalizePath(moduleResolve(entry, pathToFileURL(`${__dirname}/`), conditions, false).pathname.replace(/^\/(\w)\:/, '$1:'));
|
|
38
|
+
} catch (err) {}
|
|
39
|
+
};
|
|
40
|
+
export { getProjectUsage, getTemplatePath, normalizePath, readTemplate, resolveESMDependency };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { loadServerPlugins } from "@modern-js/prod-server";
|
|
1
2
|
import { compatibleRequire, createDebugger, dynamicImport, getInternalPlugins, tryResolve } from "@modern-js/utils";
|
|
2
|
-
import * as __rspack_external__modern_js_prod_server_057184e2 from "@modern-js/prod-server";
|
|
3
3
|
const debug = createDebugger('load-plugins');
|
|
4
4
|
async function getServerPlugins(api, metaName = 'modern-js') {
|
|
5
5
|
const hooks = api.getHooks();
|
|
@@ -12,9 +12,9 @@ async function getServerPlugins(api, metaName = 'modern-js') {
|
|
|
12
12
|
});
|
|
13
13
|
return filtedPlugins;
|
|
14
14
|
}
|
|
15
|
-
async function
|
|
15
|
+
async function loadPlugins_loadServerPlugins(api, appDirectory, metaName) {
|
|
16
16
|
const plugins = await getServerPlugins(api, metaName);
|
|
17
|
-
const instances = await
|
|
17
|
+
const instances = await loadServerPlugins(plugins, appDirectory);
|
|
18
18
|
return instances;
|
|
19
19
|
}
|
|
20
20
|
const resolveCliPlugin = async (p, appDirectory)=>{
|
|
@@ -42,4 +42,4 @@ const loadInternalPlugins = async (appDirectory, internalPlugins)=>{
|
|
|
42
42
|
}));
|
|
43
43
|
return loadedPlugins;
|
|
44
44
|
};
|
|
45
|
-
export { getServerPlugins, loadInternalPlugins, loadServerPlugins };
|
|
45
|
+
export { getServerPlugins, loadInternalPlugins, loadPlugins_loadServerPlugins as loadServerPlugins };
|
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
const checkDepExist = (dep, appDir)=>{
|
|
4
|
-
try {
|
|
5
|
-
tryResolve(dep, appDir, process.cwd());
|
|
6
|
-
return true;
|
|
7
|
-
} catch {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
};
|
|
1
|
+
import node_path from "node:path";
|
|
2
|
+
import { fs, getAliasConfig, isDepExists, loadFromProject, readTsConfigByFile } from "@modern-js/utils";
|
|
11
3
|
const setupTsRuntime = async (appDir, distDir, alias)=>{
|
|
12
4
|
const TS_CONFIG_FILENAME = "tsconfig.json";
|
|
13
|
-
const tsconfigPath =
|
|
5
|
+
const tsconfigPath = node_path.resolve(appDir, TS_CONFIG_FILENAME);
|
|
14
6
|
const isTsProject = await fs.pathExists(tsconfigPath);
|
|
15
|
-
const hasTsNode =
|
|
7
|
+
const hasTsNode = isDepExists(appDir, 'ts-node');
|
|
16
8
|
if (!isTsProject || !hasTsNode) return;
|
|
17
9
|
const aliasConfig = getAliasConfig(alias, {
|
|
18
10
|
appDirectory: appDir,
|
|
@@ -29,7 +21,7 @@ const setupTsRuntime = async (appDir, distDir, alias)=>{
|
|
|
29
21
|
]
|
|
30
22
|
});
|
|
31
23
|
} catch {}
|
|
32
|
-
if ('string' == typeof tsPath &&
|
|
24
|
+
if ('string' == typeof tsPath && node_path.isAbsolute(tsPath)) tsPath = node_path.relative(absoluteBaseUrl, tsPath);
|
|
33
25
|
if ('string' == typeof tsPath) tsPath = [
|
|
34
26
|
tsPath
|
|
35
27
|
];
|
|
@@ -48,7 +40,7 @@ const setupTsRuntime = async (appDir, distDir, alias)=>{
|
|
|
48
40
|
transpileOnly: true,
|
|
49
41
|
ignore: [
|
|
50
42
|
'(?:^|/)node_modules/',
|
|
51
|
-
`(?:^|/)${
|
|
43
|
+
`(?:^|/)${node_path.relative(appDir, distDir)}/`
|
|
52
44
|
],
|
|
53
45
|
...tsNodeOptions
|
|
54
46
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import { parseRspackConfig } from "@modern-js/builder";
|
|
3
|
-
import { builderPluginAdapterBasic, builderPluginAdapterHooks } from "./shared/builderPlugins/index.mjs";
|
|
4
2
|
async function createBuilderGenerator() {
|
|
5
3
|
const { createRspackBuilderForModern } = await import("./builder-rspack/index.mjs");
|
|
6
4
|
return createRspackBuilderForModern;
|
|
7
5
|
}
|
|
8
|
-
export {
|
|
6
|
+
export { parseRspackConfig } from "@modern-js/builder";
|
|
7
|
+
export { builderPluginAdapterBasic, builderPluginAdapterHooks } from "./shared/builderPlugins/index.mjs";
|
|
8
|
+
export { createBuilderGenerator };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
|
|
3
3
|
import { dirname as __rspack_dirname } from "node:path";
|
|
4
|
+
import node_path from "node:path";
|
|
4
5
|
import { SERVICE_WORKER_ENVIRONMENT_NAME } from "@modern-js/builder";
|
|
5
|
-
import * as __rspack_external_node_path_c5b9b54f from "node:path";
|
|
6
6
|
var adapterBasic_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
|
|
7
7
|
const builderPluginAdapterBasic = (options)=>({
|
|
8
8
|
name: 'builder-plugin-adapter-modern-basic',
|
|
@@ -14,7 +14,7 @@ const builderPluginAdapterBasic = (options)=>({
|
|
|
14
14
|
const bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
|
|
15
15
|
const depExt = 'mjs';
|
|
16
16
|
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(bareServerModuleReg);
|
|
17
|
-
chain.module.rule('bare-server-module').test(bareServerModuleReg).use('server-module-loader').loader(
|
|
17
|
+
chain.module.rule('bare-server-module').test(bareServerModuleReg).use('server-module-loader').loader(node_path.join(adapterBasic_dirname, `../loaders/serverModuleLoader.${depExt}`));
|
|
18
18
|
}
|
|
19
19
|
const { appContext } = options;
|
|
20
20
|
const { metaName } = appContext;
|
|
@@ -4,7 +4,7 @@ import { resolve, sep } from "path";
|
|
|
4
4
|
import { SERVICE_WORKER_ENVIRONMENT_NAME, isHtmlDisabled } from "@modern-js/builder";
|
|
5
5
|
import { fs, isUseRsc, isUseSSRBundle } from "@modern-js/utils";
|
|
6
6
|
import { mergeRsbuildConfig } from "@rsbuild/core";
|
|
7
|
-
import {
|
|
7
|
+
import { getServerCombinedModuleFile } from "../../../plugins/analyze/utils.mjs";
|
|
8
8
|
import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins/index.mjs";
|
|
9
9
|
const builderPluginAdapterSSR = (options)=>({
|
|
10
10
|
name: 'builder-plugin-adapter-modern-ssr',
|
|
@@ -101,7 +101,7 @@ async function applySSRLoaderEntry(chain, optinos, isServer) {
|
|
|
101
101
|
const { entrypoints } = appContext;
|
|
102
102
|
await Promise.all(entrypoints.map(async (entrypoint)=>{
|
|
103
103
|
const { entryName } = entrypoint;
|
|
104
|
-
const serverLoadersFile =
|
|
104
|
+
const serverLoadersFile = getServerCombinedModuleFile(internalDirectory, entryName);
|
|
105
105
|
if (isServer) try {
|
|
106
106
|
await fs.access(serverLoadersFile, fs.constants.F_OK);
|
|
107
107
|
chain.entry(`${entryName}-server-loaders`).add(serverLoadersFile);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
+
import node_path from "node:path";
|
|
2
3
|
import { fs, logger } from "@modern-js/utils";
|
|
3
4
|
import { loadServerPlugins } from "../utils/loadPlugins.mjs";
|
|
4
5
|
import { setupTsRuntime } from "../utils/register.mjs";
|
|
5
6
|
import { generateRoutes } from "../utils/routes.mjs";
|
|
6
|
-
import * as __rspack_external_node_path_c5b9b54f from "node:path";
|
|
7
7
|
async function copyEnvFiles(appDirectory, distDirectory) {
|
|
8
8
|
try {
|
|
9
9
|
const files = await fs.readdir(appDirectory);
|
|
@@ -11,8 +11,8 @@ async function copyEnvFiles(appDirectory, distDirectory) {
|
|
|
11
11
|
const envFiles = files.filter((file)=>envFileRegex.test(file));
|
|
12
12
|
if (0 === envFiles.length) return void logger.debug('No .env files found to copy');
|
|
13
13
|
const copyPromises = envFiles.map(async (envFile)=>{
|
|
14
|
-
const sourcePath =
|
|
15
|
-
const targetPath =
|
|
14
|
+
const sourcePath = node_path.resolve(appDirectory, envFile);
|
|
15
|
+
const targetPath = node_path.resolve(distDirectory, envFile);
|
|
16
16
|
try {
|
|
17
17
|
const stat = await fs.stat(sourcePath);
|
|
18
18
|
if (stat.isDirectory()) return;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
import { applyPlugins } from "@modern-js/prod-server";
|
|
2
4
|
import { createDevServer } from "@modern-js/server";
|
|
3
5
|
import { DEFAULT_DEV_HOST, SERVER_DIR, getMeta, logger } from "@modern-js/utils";
|
|
4
6
|
import { setServer } from "../utils/createServer.mjs";
|
|
@@ -6,8 +8,6 @@ import { loadServerPlugins } from "../utils/loadPlugins.mjs";
|
|
|
6
8
|
import { printInstructions } from "../utils/printInstructions.mjs";
|
|
7
9
|
import { setupTsRuntime } from "../utils/register.mjs";
|
|
8
10
|
import { generateRoutes } from "../utils/routes.mjs";
|
|
9
|
-
import * as __rspack_external_node_path_c5b9b54f from "node:path";
|
|
10
|
-
import * as __rspack_external__modern_js_prod_server_057184e2 from "@modern-js/prod-server";
|
|
11
11
|
const dev = async (api, options, devServerOptions)=>{
|
|
12
12
|
if (options.analyze) process.env.BUNDLE_ANALYZE = 'true';
|
|
13
13
|
const normalizedConfig = api.getNormalizedConfig();
|
|
@@ -25,7 +25,7 @@ const dev = async (api, options, devServerOptions)=>{
|
|
|
25
25
|
await setupTsRuntime(appContext.appDirectory, appContext.distDirectory, combinedAlias);
|
|
26
26
|
const { appDirectory, port, apiOnly, metaName, serverRoutes } = appContext;
|
|
27
27
|
const meta = getMeta(metaName);
|
|
28
|
-
const serverConfigPath =
|
|
28
|
+
const serverConfigPath = node_path.resolve(appDirectory, SERVER_DIR, `${meta}.server`);
|
|
29
29
|
await hooks.onBeforeDev.call();
|
|
30
30
|
if (!appContext.builder && !apiOnly) throw new Error('Expect the Builder to have been initialized, But the appContext.builder received `undefined`');
|
|
31
31
|
await generateRoutes(appContext);
|
|
@@ -56,7 +56,7 @@ const dev = async (api, options, devServerOptions)=>{
|
|
|
56
56
|
const { server } = await createDevServer({
|
|
57
57
|
...serverOptions,
|
|
58
58
|
runCompile: false
|
|
59
|
-
}, devServerOptions?.applyPlugins ||
|
|
59
|
+
}, devServerOptions?.applyPlugins || applyPlugins);
|
|
60
60
|
server.listen({
|
|
61
61
|
port,
|
|
62
62
|
host
|
|
@@ -68,7 +68,7 @@ const dev = async (api, options, devServerOptions)=>{
|
|
|
68
68
|
const { server, afterListen } = await createDevServer({
|
|
69
69
|
...serverOptions,
|
|
70
70
|
builder: appContext.builder
|
|
71
|
-
}, devServerOptions?.applyPlugins ||
|
|
71
|
+
}, devServerOptions?.applyPlugins || applyPlugins);
|
|
72
72
|
server.listen({
|
|
73
73
|
port,
|
|
74
74
|
host
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import path from "path";
|
|
3
|
+
import { createProdServer } from "@modern-js/prod-server";
|
|
3
4
|
import { SERVER_DIR, getMeta, getTargetDir, isApiOnly, logger } from "@modern-js/utils";
|
|
4
5
|
import { loadServerPlugins } from "../utils/loadPlugins.mjs";
|
|
5
6
|
import { printInstructions } from "../utils/printInstructions.mjs";
|
|
6
|
-
import * as __rspack_external__modern_js_prod_server_057184e2 from "@modern-js/prod-server";
|
|
7
7
|
const serve = async (api, serverOptions)=>{
|
|
8
8
|
const appContext = api.getAppContext();
|
|
9
9
|
const userConfig = api.getNormalizedConfig();
|
|
@@ -17,7 +17,7 @@ const serve = async (api, serverOptions)=>{
|
|
|
17
17
|
const meta = getMeta(metaName);
|
|
18
18
|
const serverConfigPath = path.resolve(distDirectory, SERVER_DIR, `${meta}.server`);
|
|
19
19
|
const pluginInstances = await loadServerPlugins(api, appDirectory, metaName);
|
|
20
|
-
const app = await (serverOptions?.launcher ||
|
|
20
|
+
const app = await (serverOptions?.launcher || createProdServer)({
|
|
21
21
|
metaName,
|
|
22
22
|
pwd: distDirectory,
|
|
23
23
|
config: {
|
|
@@ -5,7 +5,7 @@ function createDefaultConfig(appContext) {
|
|
|
5
5
|
const dev = {
|
|
6
6
|
cliShortcuts: {
|
|
7
7
|
help: false,
|
|
8
|
-
custom: (shortcuts = [])=>shortcuts.filter(({ key })=>'r' !== key && 'u' !== key)
|
|
8
|
+
custom: (shortcuts = [])=>shortcuts.filter(({ key })=>'r' !== key && 'u' !== key && 'o' !== key)
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
11
|
const output = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
+
import node_path from "node:path";
|
|
2
3
|
import { fs } from "@modern-js/utils";
|
|
3
|
-
import * as __rspack_external_node_path_c5b9b54f from "node:path";
|
|
4
4
|
const checkDepExist = async (dep)=>{
|
|
5
5
|
try {
|
|
6
6
|
await import(dep);
|
|
@@ -11,7 +11,7 @@ const checkDepExist = async (dep)=>{
|
|
|
11
11
|
};
|
|
12
12
|
const registerModuleHooks = async ({ appDir, distDir, alias })=>{
|
|
13
13
|
const TS_CONFIG_FILENAME = "tsconfig.json";
|
|
14
|
-
const tsconfigPath =
|
|
14
|
+
const tsconfigPath = node_path.resolve(appDir, TS_CONFIG_FILENAME);
|
|
15
15
|
const hasTsconfig = await fs.pathExists(tsconfigPath);
|
|
16
16
|
const hasTsNode = await checkDepExist('ts-node');
|
|
17
17
|
if (!hasTsconfig || !hasTsNode) return;
|
|
@@ -20,7 +20,7 @@ const registerModuleHooks = async ({ appDir, distDir, alias })=>{
|
|
|
20
20
|
process.env.TS_NODE_PROJECT = tsconfigPath;
|
|
21
21
|
process.env.TS_NODE_SCOPE = true;
|
|
22
22
|
process.env.TS_NODE_FILES = true;
|
|
23
|
-
process.env.TS_NODE_IGNORE = `(?:^|/)node_modules/,(?:^|/)${
|
|
23
|
+
process.env.TS_NODE_IGNORE = `(?:^|/)node_modules/,(?:^|/)${node_path.relative(appDir, distDir)}/`;
|
|
24
24
|
register('./ts-node-loader.mjs', import.meta.url, {
|
|
25
25
|
data: {
|
|
26
26
|
appDir,
|
package/dist/esm-node/index.mjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import __rslib_shim_module__ from "node:module";
|
|
2
2
|
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
|
|
3
|
+
export * from "./defineConfig.mjs";
|
|
4
|
+
export * from "./types/index.mjs";
|
|
3
5
|
import path from "path";
|
|
4
6
|
import { castArray } from "@modern-js/builder";
|
|
5
7
|
import { getLocaleLanguage } from "@modern-js/i18n-utils/language-detector";
|
|
@@ -17,13 +19,6 @@ import serverRuntime from "./plugins/serverRuntime.mjs";
|
|
|
17
19
|
import { generateWatchFiles } from "./utils/generateWatchFiles.mjs";
|
|
18
20
|
import { initAppContext } from "./utils/initAppContext.mjs";
|
|
19
21
|
import { restart } from "./utils/restart.mjs";
|
|
20
|
-
import { defineConfig } from "./defineConfig.mjs";
|
|
21
|
-
import { dev } from "./commands/dev.mjs";
|
|
22
|
-
import { serve } from "./commands/serve.mjs";
|
|
23
|
-
import { resolveModernRsbuildConfig } from "./rsbuild.mjs";
|
|
24
|
-
import { mergeConfig } from "@modern-js/plugin/cli";
|
|
25
|
-
export * from "./defineConfig.mjs";
|
|
26
|
-
export * from "./types/index.mjs";
|
|
27
22
|
const appTools = ()=>({
|
|
28
23
|
name: '@modern-js/app-tools',
|
|
29
24
|
usePlugins: [
|
|
@@ -122,4 +117,10 @@ const appTools = ()=>({
|
|
|
122
117
|
}
|
|
123
118
|
});
|
|
124
119
|
const src = appTools;
|
|
125
|
-
export {
|
|
120
|
+
export { defineConfig } from "./defineConfig.mjs";
|
|
121
|
+
export { dev } from "./commands/dev.mjs";
|
|
122
|
+
export { serve } from "./commands/serve.mjs";
|
|
123
|
+
export { resolveModernRsbuildConfig } from "./rsbuild.mjs";
|
|
124
|
+
export { mergeConfig } from "@modern-js/plugin/cli";
|
|
125
|
+
export default src;
|
|
126
|
+
export { appTools, generateWatchFiles, initAppContext };
|
|
@@ -30,7 +30,7 @@ const parseModule = async ({ source, filename })=>{
|
|
|
30
30
|
}
|
|
31
31
|
return await parse(content);
|
|
32
32
|
};
|
|
33
|
-
const
|
|
33
|
+
const getServerCombinedModuleFile = (internalDirectory, entryName)=>path.join(internalDirectory, entryName, 'server-loader-combined.js');
|
|
34
34
|
const checkIsBuildCommands = ()=>{
|
|
35
35
|
const buildCommands = [
|
|
36
36
|
'dev',
|
|
@@ -53,4 +53,4 @@ const isSubDirOrEqual = (parent, child)=>{
|
|
|
53
53
|
const isSubdir = relative && !relative.startsWith('..') && !path.isAbsolute(relative);
|
|
54
54
|
return Boolean(isSubdir);
|
|
55
55
|
};
|
|
56
|
-
export { checkIsBuildCommands, checkIsServeCommand,
|
|
56
|
+
export { checkIsBuildCommands, checkIsServeCommand, getServerCombinedModuleFile, isSubDirOrEqual, parseModule, replaceWithAlias, walkDirectory };
|
|
@@ -4,20 +4,25 @@ import { createGhPagesPreset } from "./platforms/gh-pages.mjs";
|
|
|
4
4
|
import { createNetlifyPreset } from "./platforms/netlify.mjs";
|
|
5
5
|
import { createNodePreset } from "./platforms/node.mjs";
|
|
6
6
|
import { createVercelPreset } from "./platforms/vercel.mjs";
|
|
7
|
-
import { getProjectUsage } from "./utils.mjs";
|
|
7
|
+
import { getProjectUsage } from "./utils/index.mjs";
|
|
8
8
|
const deployPresets = {
|
|
9
9
|
node: createNodePreset,
|
|
10
10
|
vercel: createVercelPreset,
|
|
11
11
|
netlify: createNetlifyPreset,
|
|
12
12
|
ghPages: createGhPagesPreset
|
|
13
13
|
};
|
|
14
|
-
async function getDeployPreset(appContext, modernConfig, deployTarget) {
|
|
14
|
+
async function getDeployPreset(appContext, modernConfig, deployTarget, api) {
|
|
15
15
|
const { appDirectory, distDirectory, metaName } = appContext;
|
|
16
16
|
const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory, metaName);
|
|
17
17
|
const needModernServer = useSSR || useAPI || useWebServer;
|
|
18
18
|
const createPreset = deployPresets[deployTarget];
|
|
19
19
|
if (!createPreset) throw new Error(`Unknown deploy target: '${deployTarget}'. MODERNJS_DEPLOY should be 'node', 'vercel', or 'netlify'.`);
|
|
20
|
-
return createPreset(
|
|
20
|
+
return createPreset({
|
|
21
|
+
appContext,
|
|
22
|
+
modernConfig,
|
|
23
|
+
needModernServer,
|
|
24
|
+
api
|
|
25
|
+
});
|
|
21
26
|
}
|
|
22
27
|
const deploy = ()=>({
|
|
23
28
|
name: '@modern-js/plugin-deploy',
|
|
@@ -28,7 +33,7 @@ const deploy = ()=>({
|
|
|
28
33
|
const { metaName } = appContext;
|
|
29
34
|
if ('modern-js' !== metaName && !process.env.MODERNJS_DEPLOY) return;
|
|
30
35
|
const modernConfig = api.getNormalizedConfig();
|
|
31
|
-
const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget);
|
|
36
|
+
const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget, api);
|
|
32
37
|
deployPreset?.prepare && await deployPreset?.prepare();
|
|
33
38
|
deployPreset?.writeOutput && await deployPreset?.writeOutput();
|
|
34
39
|
deployPreset?.genEntry && await deployPreset?.genEntry();
|
|
@@ -36,4 +41,4 @@ const deploy = ()=>({
|
|
|
36
41
|
});
|
|
37
42
|
}
|
|
38
43
|
});
|
|
39
|
-
export
|
|
44
|
+
export default deploy;
|
|
@@ -24,7 +24,7 @@ async function reorganizeHtmlFiles(routes, baseDir, baseUrl = '/') {
|
|
|
24
24
|
});
|
|
25
25
|
await Promise.all(copyPromises);
|
|
26
26
|
}
|
|
27
|
-
const createGhPagesPreset = (appContext, modernConfig)=>{
|
|
27
|
+
const createGhPagesPreset = ({ appContext, modernConfig })=>{
|
|
28
28
|
const { serverRoutes, appDirectory, distDirectory } = appContext;
|
|
29
29
|
const { server: { baseUrl } } = modernConfig;
|
|
30
30
|
const outputDirectory = path.join(appDirectory, '.output');
|
|
@@ -1,35 +1,28 @@
|
|
|
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
|
-
var netlify_dirname = __rspack_dirname(__rspack_fileURLToPath(import.meta.url));
|
|
7
|
+
import { readTemplate, resolveESMDependency } from "../utils/index.mjs";
|
|
8
|
+
import { generateHandler } from "../utils/generator.mjs";
|
|
11
9
|
async function cleanDistDirectory(dir) {
|
|
12
10
|
try {
|
|
13
11
|
const items = await fs.readdir(dir);
|
|
14
12
|
for (const item of items){
|
|
15
|
-
const fullPath =
|
|
13
|
+
const fullPath = node_path.join(dir, item);
|
|
16
14
|
if ('static' !== item && '_redirects' !== item && 'html' !== item) await fs.remove(fullPath);
|
|
17
15
|
}
|
|
18
16
|
} catch (error) {
|
|
19
17
|
console.error('Error cleaning directory:', error);
|
|
20
18
|
}
|
|
21
19
|
}
|
|
22
|
-
const createNetlifyPreset = (appContext, modernConfig, needModernServer)=>{
|
|
23
|
-
const { appDirectory, distDirectory, entrypoints,
|
|
20
|
+
const createNetlifyPreset = ({ appContext, modernConfig, needModernServer })=>{
|
|
21
|
+
const { appDirectory, distDirectory, entrypoints, moduleType } = appContext;
|
|
24
22
|
const isEsmProject = 'module' === moduleType;
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
]);
|
|
29
|
-
const netlifyOutput = __rspack_external_node_path_c5b9b54f["default"].join(appDirectory, '.netlify');
|
|
30
|
-
const funcsDirectory = __rspack_external_node_path_c5b9b54f["default"].join(netlifyOutput, 'functions');
|
|
31
|
-
const entryFilePath = __rspack_external_node_path_c5b9b54f["default"].join(funcsDirectory, 'index.js');
|
|
32
|
-
const handlerFilePath = __rspack_external_node_path_c5b9b54f["default"].join(funcsDirectory, 'netlify-handler.cjs');
|
|
23
|
+
const netlifyOutput = node_path.join(appDirectory, '.netlify');
|
|
24
|
+
const funcsDirectory = node_path.join(netlifyOutput, 'functions');
|
|
25
|
+
const entryFilePath = node_path.join(funcsDirectory, 'index.js');
|
|
33
26
|
return {
|
|
34
27
|
async prepare () {
|
|
35
28
|
await fs.remove(netlifyOutput);
|
|
@@ -56,49 +49,37 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer)=>{
|
|
|
56
49
|
await fs.ensureDir(funcsDirectory);
|
|
57
50
|
await fs.copy(distDirectory, funcsDirectory, {
|
|
58
51
|
filter: (src)=>{
|
|
59
|
-
const distStaticDirectory =
|
|
52
|
+
const distStaticDirectory = node_path.join(distDirectory, "static");
|
|
60
53
|
return !src.includes(distStaticDirectory);
|
|
61
54
|
}
|
|
62
55
|
});
|
|
63
56
|
}
|
|
64
|
-
const redirectFilePath =
|
|
57
|
+
const redirectFilePath = node_path.join(distDirectory, '_redirects');
|
|
65
58
|
await fs.writeFile(redirectFilePath, redirectContent);
|
|
66
59
|
},
|
|
67
60
|
async genEntry () {
|
|
68
61
|
if (!needModernServer) return;
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
const meta = getMeta(metaName);
|
|
80
|
-
const pluginImportCode = genPluginImportsCode(plugins || []);
|
|
81
|
-
const dynamicProdOptions = {
|
|
82
|
-
config: serverConfig
|
|
83
|
-
};
|
|
84
|
-
const serverConfigPath = `path.join(__dirname, "${SERVER_DIR}", "${meta}.server")`;
|
|
85
|
-
const pluginsCode = getPluginsCode(plugins);
|
|
86
|
-
let handlerCode = (await fs.readFile(__rspack_external_node_path_c5b9b54f["default"].join(netlify_dirname, './netlify-handler.js'))).toString();
|
|
87
|
-
const serverAppContext = serverAppContenxtTemplate(appContext);
|
|
88
|
-
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);
|
|
89
|
-
await fs.writeFile(handlerFilePath, handlerCode);
|
|
90
|
-
if (isEsmProject) await fs.writeFile(entryFilePath, "export { handler as default } from './netlify-handler.cjs';\n");
|
|
91
|
-
else await fs.writeFile(entryFilePath, "const { handler } = require('./netlify-handler.cjs');\nexports.handler = handler;\n");
|
|
62
|
+
const template = await readTemplate(`netlify-entry.${isEsmProject ? 'mjs' : 'cjs'}`);
|
|
63
|
+
const code = await generateHandler({
|
|
64
|
+
template,
|
|
65
|
+
appContext,
|
|
66
|
+
config: modernConfig,
|
|
67
|
+
isESM: isEsmProject
|
|
68
|
+
});
|
|
69
|
+
await fs.writeFile(entryFilePath, code);
|
|
92
70
|
},
|
|
93
71
|
async end () {
|
|
94
72
|
if ('development' !== process.env.NODE_ENV) await cleanDistDirectory(distDirectory);
|
|
95
73
|
if (!needModernServer) return;
|
|
74
|
+
const entry = isEsmProject ? await resolveESMDependency('@modern-js/prod-server') : require.resolve('@modern-js/prod-server');
|
|
75
|
+
const netlifyEntry = isEsmProject ? await resolveESMDependency('@modern-js/prod-server/netlify') : require.resolve('@modern-js/prod-server/netlify');
|
|
76
|
+
if (!entry || !netlifyEntry) throw new Error('Cannot find @modern-js/prod-server');
|
|
96
77
|
await nodeDepEmit({
|
|
97
78
|
appDir: appDirectory,
|
|
98
79
|
sourceDir: funcsDirectory,
|
|
99
80
|
includeEntries: [
|
|
100
|
-
|
|
101
|
-
|
|
81
|
+
entry,
|
|
82
|
+
netlifyEntry
|
|
102
83
|
],
|
|
103
84
|
copyWholePackage (pkgName) {
|
|
104
85
|
return '@modern-js/utils' === pkgName;
|