@bleedingdev/modern-js-app-tools 3.9.0-ultramodern.2 → 3.9.0-ultramodern.20
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/generator/createCopyPattern.js +2 -1
- package/dist/cjs/builder/generator/index.js +0 -1
- package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +2 -1
- package/dist/cjs/builder/shared/builderPlugins/index.js +4 -11
- package/dist/cjs/builder/shared/lazyCompilation.js +26 -0
- package/dist/cjs/commands/index.js +6 -2
- package/dist/cjs/compat/hooks.js +1 -1
- package/dist/cjs/config/index.js +4 -11
- package/dist/cjs/index.js +70 -87
- package/dist/cjs/plugins/analyze/getFileSystemEntry.js +1 -1
- package/dist/cjs/plugins/analyze/getServerRoutes.js +1 -1
- package/dist/cjs/plugins/analyze/utils.js +2 -2
- package/dist/cjs/plugins/deploy/index.js +7 -28
- package/dist/cjs/plugins/deploy/platforms/netlify.js +2 -1
- package/dist/cjs/plugins/deploy/platforms/node.js +12 -16
- package/dist/cjs/plugins/deploy/platforms/vercel.js +2 -1
- package/dist/cjs/plugins/deploy/utils/generator.js +1 -1
- package/dist/cjs/plugins/deploy/utils/index.js +15 -12
- package/dist/cjs/plugins/initialize/index.js +3 -1
- package/dist/cjs/plugins/serverBuild.js +2 -3
- package/dist/cjs/{plugins/backendFederationBuild.js → server-plugin.js} +4 -7
- package/dist/cjs/utils/loadPlugins.js +1 -6
- package/dist/esm/builder/generator/createCopyPattern.mjs +2 -1
- package/dist/esm/builder/generator/index.mjs +1 -2
- package/dist/esm/builder/shared/builderPlugins/adapterHtml.mjs +2 -1
- package/dist/esm/builder/shared/builderPlugins/index.mjs +0 -1
- package/dist/esm/builder/shared/lazyCompilation.mjs +14 -1
- package/dist/esm/commands/index.mjs +6 -2
- package/dist/esm/compat/hooks.mjs +1 -1
- package/dist/esm/config/index.mjs +0 -1
- package/dist/esm/index.mjs +9 -6
- package/dist/esm/plugins/analyze/getFileSystemEntry.mjs +1 -1
- package/dist/esm/plugins/analyze/getServerRoutes.mjs +1 -1
- package/dist/esm/plugins/analyze/utils.mjs +2 -2
- package/dist/esm/plugins/deploy/index.mjs +5 -21
- package/dist/esm/plugins/deploy/platforms/netlify.mjs +2 -1
- package/dist/esm/plugins/deploy/platforms/node.mjs +12 -16
- package/dist/esm/plugins/deploy/platforms/vercel.mjs +2 -1
- package/dist/esm/plugins/deploy/utils/generator.mjs +1 -1
- package/dist/esm/plugins/deploy/utils/index.mjs +17 -14
- package/dist/esm/plugins/initialize/index.mjs +3 -1
- package/dist/esm/plugins/serverBuild.mjs +2 -3
- package/dist/esm/server-plugin.mjs +1 -0
- package/dist/esm/utils/loadPlugins.mjs +2 -7
- package/dist/esm-node/builder/generator/createCopyPattern.mjs +2 -1
- package/dist/esm-node/builder/generator/index.mjs +1 -2
- package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.mjs +2 -1
- package/dist/esm-node/builder/shared/builderPlugins/index.mjs +0 -1
- package/dist/esm-node/builder/shared/lazyCompilation.mjs +14 -1
- package/dist/esm-node/commands/index.mjs +6 -2
- package/dist/esm-node/compat/hooks.mjs +1 -1
- package/dist/esm-node/config/index.mjs +0 -1
- package/dist/esm-node/index.mjs +9 -6
- package/dist/esm-node/plugins/analyze/getFileSystemEntry.mjs +1 -1
- package/dist/esm-node/plugins/analyze/getServerRoutes.mjs +1 -1
- package/dist/esm-node/plugins/analyze/utils.mjs +2 -2
- package/dist/esm-node/plugins/deploy/index.mjs +5 -21
- package/dist/esm-node/plugins/deploy/platforms/netlify.mjs +2 -1
- package/dist/esm-node/plugins/deploy/platforms/node.mjs +12 -16
- package/dist/esm-node/plugins/deploy/platforms/vercel.mjs +2 -1
- package/dist/esm-node/plugins/deploy/utils/generator.mjs +1 -1
- package/dist/esm-node/plugins/deploy/utils/index.mjs +17 -15
- package/dist/esm-node/plugins/initialize/index.mjs +3 -1
- package/dist/esm-node/plugins/serverBuild.mjs +2 -3
- package/dist/esm-node/server-plugin.mjs +2 -0
- package/dist/esm-node/utils/loadPlugins.mjs +2 -7
- package/dist/types/builder/shared/builderPlugins/index.d.ts +0 -1
- package/dist/types/builder/shared/lazyCompilation.d.ts +15 -0
- package/dist/types/config/index.d.ts +0 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/plugins/deploy/index.d.ts +1 -4
- package/dist/types/plugins/deploy/utils/generator.d.ts +1 -1
- package/dist/types/plugins/deploy/utils/index.d.ts +1 -1
- package/dist/types/server-plugin.d.ts +10 -0
- package/dist/types/types/config/output.d.ts +0 -9
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/plugin.d.ts +58 -2
- package/dist/types/utils/initAppContext.d.ts +3 -2
- package/docs/apis/app/commands.md +1 -0
- package/docs/configure/app/bff/effect.md +34 -36
- package/docs/configure/app/source/react-compiler.md +2 -0
- package/docs/guides/advanced-features/bff/data-platform.md +2 -2
- package/docs/guides/advanced-features/bff/frameworks.md +36 -24
- package/docs/guides/advanced-features/bff/function.md +2 -2
- package/docs/guides/advanced-features/bff/operators.md +17 -17
- package/docs/guides/basic-features/render/ssr-cache.md +14 -1
- package/docs/guides/get-started/quick-start.md +2 -6
- package/docs/guides/get-started/ultramodern.md +14 -97
- package/docs/llms.txt +3 -3
- package/docs/plugin/server-plugins/api.md +1 -0
- package/package.json +38 -36
- package/dist/cjs/builder/shared/builderPlugins/adapterPrecompress.js +0 -125
- package/dist/cjs/config/build-environment.js +0 -268
- package/dist/cjs/config/public.js +0 -46
- package/dist/cjs/plugins/backend-federation/codegen.js +0 -256
- package/dist/cjs/plugins/backend-federation/config.js +0 -204
- package/dist/cjs/plugins/backend-federation/emit.js +0 -150
- package/dist/cjs/plugins/deploy/platforms/cloudflare-output-verifier/index.js +0 -62
- package/dist/cjs/plugins/deploy/utils/npmAliases.js +0 -226
- package/dist/cjs/plugins/ultramodernReleaseEnvelope.js +0 -44
- package/dist/cjs/presetUltramodern.js +0 -168
- package/dist/cjs/types/config/precompress.js +0 -18
- package/dist/esm/builder/shared/builderPlugins/adapterPrecompress.mjs +0 -77
- package/dist/esm/config/build-environment.mjs +0 -224
- package/dist/esm/config/public.mjs +0 -1
- package/dist/esm/plugins/backend-federation/codegen.mjs +0 -205
- package/dist/esm/plugins/backend-federation/config.mjs +0 -128
- package/dist/esm/plugins/backend-federation/emit.mjs +0 -99
- package/dist/esm/plugins/backendFederationBuild.mjs +0 -1
- package/dist/esm/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +0 -1
- package/dist/esm/plugins/deploy/utils/npmAliases.mjs +0 -174
- package/dist/esm/plugins/ultramodernReleaseEnvelope.mjs +0 -6
- package/dist/esm/presetUltramodern.mjs +0 -112
- package/dist/esm/types/config/precompress.mjs +0 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterPrecompress.mjs +0 -78
- package/dist/esm-node/config/build-environment.mjs +0 -225
- package/dist/esm-node/config/public.mjs +0 -2
- package/dist/esm-node/plugins/backend-federation/codegen.mjs +0 -206
- package/dist/esm-node/plugins/backend-federation/config.mjs +0 -129
- package/dist/esm-node/plugins/backend-federation/emit.mjs +0 -100
- package/dist/esm-node/plugins/backendFederationBuild.mjs +0 -2
- package/dist/esm-node/plugins/deploy/platforms/cloudflare-output-verifier/index.mjs +0 -2
- package/dist/esm-node/plugins/deploy/utils/npmAliases.mjs +0 -175
- package/dist/esm-node/plugins/ultramodernReleaseEnvelope.mjs +0 -7
- package/dist/esm-node/presetUltramodern.mjs +0 -113
- package/dist/esm-node/types/config/precompress.mjs +0 -1
- package/dist/types/builder/shared/builderPlugins/adapterPrecompress.d.ts +0 -3
- package/dist/types/config/build-environment.d.ts +0 -22
- package/dist/types/config/public.d.ts +0 -2
- package/dist/types/plugins/backend-federation/codegen.d.ts +0 -86
- package/dist/types/plugins/backend-federation/config.d.ts +0 -103
- package/dist/types/plugins/backend-federation/emit.d.ts +0 -13
- package/dist/types/plugins/backendFederationBuild.d.ts +0 -2
- package/dist/types/plugins/deploy/platforms/cloudflare-output-verifier/index.d.ts +0 -1
- package/dist/types/plugins/deploy/utils/npmAliases.d.ts +0 -14
- package/dist/types/plugins/ultramodernReleaseEnvelope.d.ts +0 -3
- package/dist/types/presetUltramodern.d.ts +0 -87
- package/dist/types/types/config/precompress.d.ts +0 -20
|
@@ -39,15 +39,16 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
39
39
|
__webpack_require__.d(__webpack_exports__, {
|
|
40
40
|
createNodePreset: ()=>createNodePreset
|
|
41
41
|
});
|
|
42
|
+
const external_node_module_namespaceObject = require("node:module");
|
|
42
43
|
const external_node_path_namespaceObject = require("node:path");
|
|
43
44
|
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
45
|
+
const trace_files_namespaceObject = require("@modern-js/app-tools-extensions/deploy-output/trace-files");
|
|
44
46
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
45
47
|
const external_ndepe_namespaceObject = require("ndepe");
|
|
46
48
|
const index_js_namespaceObject = require("../utils/index.js");
|
|
47
49
|
const generator_js_namespaceObject = require("../utils/generator.js");
|
|
48
|
-
const npmAliases_js_namespaceObject = require("../utils/npmAliases.js");
|
|
49
50
|
const createNodePreset = ({ appContext, modernConfig })=>{
|
|
50
|
-
const { appDirectory, distDirectory, moduleType } = appContext;
|
|
51
|
+
const { appDirectory, distDirectory, moduleType, serverPlugins } = appContext;
|
|
51
52
|
const isEsmProject = 'module' === moduleType;
|
|
52
53
|
const outputDirectory = external_node_path_default().join(appDirectory, '.output');
|
|
53
54
|
const staticDirectory = external_node_path_default().join(outputDirectory, 'static');
|
|
@@ -77,13 +78,19 @@ const createNodePreset = ({ appContext, modernConfig })=>{
|
|
|
77
78
|
async end () {
|
|
78
79
|
const filter = (filePath)=>!filePath.startsWith(staticDirectory) && !filePath.endsWith('.map');
|
|
79
80
|
const entry = isEsmProject ? await (0, index_js_namespaceObject.resolveESMDependency)('@modern-js/prod-server') : require.resolve('@modern-js/prod-server');
|
|
80
|
-
|
|
81
|
-
const
|
|
81
|
+
const requireFromApp = (0, external_node_module_namespaceObject.createRequire)(external_node_path_default().join(appDirectory, 'package.json'));
|
|
82
|
+
const pluginEntries = new Set();
|
|
83
|
+
for (const plugin of serverPlugins)for (const specifier of plugin.includeEntries ?? []){
|
|
84
|
+
pluginEntries.add(requireFromApp.resolve(specifier));
|
|
85
|
+
if (isEsmProject) pluginEntries.add(await (0, index_js_namespaceObject.resolveESMDependency)(specifier, appDirectory));
|
|
86
|
+
}
|
|
82
87
|
await (0, external_ndepe_namespaceObject.nodeDepEmit)({
|
|
88
|
+
traceFiles: trace_files_namespaceObject.traceDeployFiles,
|
|
83
89
|
appDir: appDirectory,
|
|
84
90
|
sourceDir: outputDirectory,
|
|
85
91
|
includeEntries: [
|
|
86
|
-
entry
|
|
92
|
+
entry,
|
|
93
|
+
...pluginEntries
|
|
87
94
|
],
|
|
88
95
|
copyWholePackage (pkgName) {
|
|
89
96
|
return '@modern-js/utils' === pkgName;
|
|
@@ -97,17 +104,6 @@ const createNodePreset = ({ appContext, modernConfig })=>{
|
|
|
97
104
|
};
|
|
98
105
|
}
|
|
99
106
|
});
|
|
100
|
-
await (0, npmAliases_js_namespaceObject.preserveNpmAliases)({
|
|
101
|
-
appDirectory,
|
|
102
|
-
outputDirectory,
|
|
103
|
-
implicitAliases: [
|
|
104
|
-
{
|
|
105
|
-
aliasName: '@modern-js/prod-server',
|
|
106
|
-
targetName: prodServerPackage.name,
|
|
107
|
-
targetVersion: prodServerPackage.version
|
|
108
|
-
}
|
|
109
|
-
]
|
|
110
|
-
});
|
|
111
107
|
console.log('Static directory:', utils_namespaceObject.chalk.blue(external_node_path_default().relative(appDirectory, staticDirectory).replace(/\\/g, '/')));
|
|
112
108
|
console.log("You can preview this build by", utils_namespaceObject.chalk.blue('node .output/index'));
|
|
113
109
|
}
|
|
@@ -41,6 +41,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
41
41
|
});
|
|
42
42
|
const external_node_path_namespaceObject = require("node:path");
|
|
43
43
|
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
44
|
+
const trace_files_namespaceObject = require("@modern-js/app-tools-extensions/deploy-output/trace-files");
|
|
44
45
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
45
46
|
const external_ndepe_namespaceObject = require("ndepe");
|
|
46
47
|
const routes_js_namespaceObject = require("../../../utils/routes.js");
|
|
@@ -133,8 +134,8 @@ const createVercelPreset = ({ appContext, modernConfig, needModernServer })=>{
|
|
|
133
134
|
async end () {
|
|
134
135
|
if (!needModernServer) return;
|
|
135
136
|
const entry = isEsmProject ? await (0, index_js_namespaceObject.resolveESMDependency)('@modern-js/prod-server') : require.resolve('@modern-js/prod-server');
|
|
136
|
-
if (!entry) throw new Error('Cannot find @modern-js/prod-server');
|
|
137
137
|
await (0, external_ndepe_namespaceObject.nodeDepEmit)({
|
|
138
|
+
traceFiles: trace_files_namespaceObject.traceDeployFiles,
|
|
138
139
|
appDir: appDirectory,
|
|
139
140
|
sourceDir: funcsDirectory,
|
|
140
141
|
includeEntries: [
|
|
@@ -61,7 +61,7 @@ const serverAppContextTemplate = (appContext)=>{
|
|
|
61
61
|
};
|
|
62
62
|
const genPluginImportsCode = (plugins, isESM = false)=>plugins.map(([name, options], index)=>{
|
|
63
63
|
const im = isESM ? `import * as plugin_${index}_ns from '${name}'` : `const plugin_${index}_ns = require('${name}')`;
|
|
64
|
-
return `${im};const plugin_${index} = plugin_${index}_ns.default
|
|
64
|
+
return `${im};const plugin_${index} = typeof plugin_${index}_ns === 'function' ? plugin_${index}_ns : typeof plugin_${index}_ns.default === 'function' ? plugin_${index}_ns.default : plugin_${index}_ns.default?.default`;
|
|
65
65
|
}).join(';\n');
|
|
66
66
|
const getPluginsCode = (plugins)=>`[${plugins.map(([, options], index)=>`plugin_${index}(${options ? JSON.stringify(options) : ''})`).join(',')}]`;
|
|
67
67
|
const getServerConfigPath = (meta)=>`path.join(__dirname, "${utils_namespaceObject.SERVER_DIR}", "${meta}.server")`;
|
|
@@ -43,9 +43,9 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
43
43
|
readTemplate: ()=>readTemplate,
|
|
44
44
|
resolveESMDependency: ()=>resolveESMDependency
|
|
45
45
|
});
|
|
46
|
-
const external_node_module_namespaceObject = require("node:module");
|
|
47
46
|
const external_node_url_namespaceObject = require("node:url");
|
|
48
47
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
48
|
+
const external_import_meta_resolve_namespaceObject = require("import-meta-resolve");
|
|
49
49
|
const external_path_namespaceObject = require("path");
|
|
50
50
|
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
51
51
|
const normalizePath = (filePath)=>filePath.replace(/\\/g, '/');
|
|
@@ -72,18 +72,21 @@ const getProjectUsage = (appDirectory, distDirectory, metaName)=>{
|
|
|
72
72
|
};
|
|
73
73
|
const getTemplatePath = (file)=>external_path_default().join(__dirname, '../platforms/templates', file);
|
|
74
74
|
const readTemplate = async (file)=>(await utils_namespaceObject.fs.readFile(getTemplatePath(file))).toString();
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
75
|
+
const DEPLOY_CONDITIONS = [
|
|
76
|
+
'node',
|
|
77
|
+
'import',
|
|
78
|
+
'module',
|
|
79
|
+
'default'
|
|
80
|
+
];
|
|
81
|
+
const resolveESMDependency = async (entry, fromDirectory)=>{
|
|
82
|
+
const base = fromDirectory ? (0, external_node_url_namespaceObject.pathToFileURL)(external_path_default().join(fromDirectory, 'package.json')) : (0, external_node_url_namespaceObject.pathToFileURL)(`${__dirname}/`);
|
|
82
83
|
try {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
84
|
+
return normalizePath((0, external_node_url_namespaceObject.fileURLToPath)((0, external_import_meta_resolve_namespaceObject.moduleResolve)(entry, base, new Set(DEPLOY_CONDITIONS), false)));
|
|
85
|
+
} catch (cause) {
|
|
86
|
+
throw new Error(`Cannot resolve "${entry}" with conditions [${DEPLOY_CONDITIONS.join(', ')}] from ${base.href}: ${cause.message}`, {
|
|
87
|
+
cause
|
|
88
|
+
});
|
|
89
|
+
}
|
|
87
90
|
};
|
|
88
91
|
exports.getProjectUsage = __webpack_exports__.getProjectUsage;
|
|
89
92
|
exports.getTemplatePath = __webpack_exports__.getTemplatePath;
|
|
@@ -31,6 +31,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
31
31
|
default: ()=>initialize
|
|
32
32
|
});
|
|
33
33
|
const utils_namespaceObject = require("@modern-js/utils");
|
|
34
|
+
const lazyCompilation_js_namespaceObject = require("../../builder/shared/lazyCompilation.js");
|
|
34
35
|
const index_js_namespaceObject = require("../../config/index.js");
|
|
35
36
|
const initialize = ()=>({
|
|
36
37
|
name: '@modern-js/plugin-initialize',
|
|
@@ -49,7 +50,8 @@ const initialize = ()=>({
|
|
|
49
50
|
...defaultConfig.dev,
|
|
50
51
|
lazyCompilation: {
|
|
51
52
|
imports: true,
|
|
52
|
-
entries: false
|
|
53
|
+
entries: false,
|
|
54
|
+
test: (0, lazyCompilation_js_namespaceObject.buildDefaultLazyCompilationTest)(appContext.appDirectory, appContext.internalDirectory)
|
|
53
55
|
}
|
|
54
56
|
};
|
|
55
57
|
return defaultConfig;
|
|
@@ -72,16 +72,15 @@ const serverBuild = ()=>({
|
|
|
72
72
|
sourceDirs.push(serverDir);
|
|
73
73
|
if (external_fs_default().existsSync(sharedDir)) sourceDirs.push(sharedDir);
|
|
74
74
|
}
|
|
75
|
-
const { server } = modernConfig;
|
|
76
75
|
const { alias } = modernConfig.source;
|
|
77
76
|
if (sourceDirs.length > 0) await (0, server_utils_namespaceObject.compile)(appDirectory, {
|
|
78
|
-
server,
|
|
79
77
|
alias
|
|
80
78
|
}, {
|
|
81
79
|
sourceDirs,
|
|
82
80
|
distDir,
|
|
83
81
|
tsconfigPath,
|
|
84
|
-
moduleType
|
|
82
|
+
moduleType,
|
|
83
|
+
excludeFiles: api.getAppContext().serverCompileExcludedFiles
|
|
85
84
|
});
|
|
86
85
|
});
|
|
87
86
|
}
|
|
@@ -37,16 +37,13 @@ var __webpack_require__ = {};
|
|
|
37
37
|
var __webpack_exports__ = {};
|
|
38
38
|
__webpack_require__.r(__webpack_exports__);
|
|
39
39
|
__webpack_require__.d(__webpack_exports__, {
|
|
40
|
-
default: ()=>
|
|
41
|
-
emitBackendFederationArtifacts: ()=>emit_js_namespaceObject.emitBackendFederationArtifacts
|
|
40
|
+
default: ()=>server_plugin_default()
|
|
42
41
|
});
|
|
43
|
-
const
|
|
44
|
-
var
|
|
42
|
+
const server_plugin_namespaceObject = require("@modern-js/server-runtime-extensions/server-plugin");
|
|
43
|
+
var server_plugin_default = /*#__PURE__*/ __webpack_require__.n(server_plugin_namespaceObject);
|
|
45
44
|
exports["default"] = __webpack_exports__["default"];
|
|
46
|
-
exports.emitBackendFederationArtifacts = __webpack_exports__.emitBackendFederationArtifacts;
|
|
47
45
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
48
|
-
"default"
|
|
49
|
-
"emitBackendFederationArtifacts"
|
|
46
|
+
"default"
|
|
50
47
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
51
48
|
Object.defineProperty(exports, '__esModule', {
|
|
52
49
|
value: true
|
|
@@ -55,12 +55,7 @@ const resolveCliPlugin = async (p, appDirectory)=>{
|
|
|
55
55
|
const pkg = 'string' == typeof p ? p : p[0];
|
|
56
56
|
const pluginOptions = 'string' == typeof p ? void 0 : p[1];
|
|
57
57
|
const path = (0, utils_namespaceObject.tryResolve)(pkg, appDirectory);
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
module = await (0, utils_namespaceObject.compatibleRequire)(path);
|
|
61
|
-
} catch (e) {
|
|
62
|
-
({ default: module } = await (0, utils_namespaceObject.dynamicImport)(path));
|
|
63
|
-
}
|
|
58
|
+
const module = await (0, utils_namespaceObject.compatibleRequire)(path);
|
|
64
59
|
if ('function' == typeof module) {
|
|
65
60
|
const result = module(pluginOptions);
|
|
66
61
|
return result;
|
|
@@ -14,7 +14,8 @@ function createPublicPattern(appContext, config, chain) {
|
|
|
14
14
|
noErrorOnMissing: true,
|
|
15
15
|
transform: (content, absoluteFrom)=>{
|
|
16
16
|
if (!/\.html?$/.test(absoluteFrom)) return content;
|
|
17
|
-
|
|
17
|
+
const publicPath = chain.output.get('publicPath');
|
|
18
|
+
return content.toString('utf8').replace(/<%=\s*assetPrefix\s*%>/g, removeTailSlash('string' == typeof publicPath ? publicPath : ''));
|
|
18
19
|
}
|
|
19
20
|
};
|
|
20
21
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createBuilder } from "@modern-js/builder";
|
|
2
2
|
import { mergeRsbuildConfig } from "@rsbuild/core";
|
|
3
|
-
import { builderPluginAdapterBasic, builderPluginAdapterHooks, builderPluginAdapterHtml,
|
|
3
|
+
import { builderPluginAdapterBasic, builderPluginAdapterHooks, builderPluginAdapterHtml, builderPluginAdapterSSR } from "../shared/builderPlugins/index.mjs";
|
|
4
4
|
import { builderPluginAdapterCopy } from "./adapterCopy.mjs";
|
|
5
5
|
import { createBuilderProviderConfig } from "./createBuilderProviderConfig.mjs";
|
|
6
6
|
import { getBuilderEnvironments } from "./getBuilderEnvironments.mjs";
|
|
@@ -40,7 +40,6 @@ async function applyBuilderPlugins(builder, options) {
|
|
|
40
40
|
builderPluginAdapterBasic(options),
|
|
41
41
|
builderPluginAdapterSSR(options),
|
|
42
42
|
builderPluginAdapterHtml(options),
|
|
43
|
-
builderPluginAdapterPrecompress(options),
|
|
44
43
|
builderPluginAdapterHooks(options)
|
|
45
44
|
]);
|
|
46
45
|
builder.addPlugins([
|
|
@@ -26,7 +26,8 @@ const builderPluginAdapterHtml = (options)=>({
|
|
|
26
26
|
async function injectAssetPrefix({ chain }) {
|
|
27
27
|
const entries = chain.entryPoints.entries() || {};
|
|
28
28
|
const entryNames = Object.keys(entries);
|
|
29
|
-
const
|
|
29
|
+
const publicPath = chain.output.get('publicPath');
|
|
30
|
+
const assetPrefix = removeTailSlash('string' == typeof publicPath ? publicPath : '');
|
|
30
31
|
const code = `window.__assetPrefix__ = '${assetPrefix}';`;
|
|
31
32
|
entryNames.forEach((entryName)=>{
|
|
32
33
|
entries[entryName].prepend(createVirtualModule(code));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import node_path from "node:path";
|
|
1
2
|
import { collectRouteComponentFiles, normalizeModulePath } from "@modern-js/utils";
|
|
2
3
|
function aggregateEagerRouteComponentFiles(byEntry) {
|
|
3
4
|
const files = new Set();
|
|
@@ -20,6 +21,18 @@ function buildSSRLazyCompilationTest(eagerRouteFiles, userTest) {
|
|
|
20
21
|
return userTestFn(m);
|
|
21
22
|
};
|
|
22
23
|
}
|
|
24
|
+
function buildDefaultLazyCompilationTest(appDirectory, internalDirectory) {
|
|
25
|
+
let dirs;
|
|
26
|
+
return (m)=>{
|
|
27
|
+
if (!('resource' in m) || 'string' != typeof m.resource) return true;
|
|
28
|
+
dirs ??= {
|
|
29
|
+
app: normalizeModulePath(appDirectory),
|
|
30
|
+
internal: normalizeModulePath(internalDirectory)
|
|
31
|
+
};
|
|
32
|
+
const file = m.resource.split('?')[0].split(node_path.sep).join('/');
|
|
33
|
+
return file.startsWith(`${dirs.app}/`) && !file.startsWith(`${dirs.internal}/`) && !file.slice(dirs.app.length).includes('/node_modules/');
|
|
34
|
+
};
|
|
35
|
+
}
|
|
23
36
|
function planSSRLazyCompilation(current, info) {
|
|
24
37
|
if (!current) return {
|
|
25
38
|
apply: false
|
|
@@ -41,4 +54,4 @@ function planSSRLazyCompilation(current, info) {
|
|
|
41
54
|
}
|
|
42
55
|
};
|
|
43
56
|
}
|
|
44
|
-
export { aggregateEagerRouteComponentFiles, buildSSRLazyCompilationTest, collectRouteComponentFiles, normalizeModulePath, planSSRLazyCompilation };
|
|
57
|
+
export { aggregateEagerRouteComponentFiles, buildDefaultLazyCompilationTest, buildSSRLazyCompilationTest, collectRouteComponentFiles, normalizeModulePath, planSSRLazyCompilation };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { i18n, localeKeys } from "../locale/index.mjs";
|
|
2
|
+
const deployTargetOption = [
|
|
3
|
+
'--deploy-target <target>',
|
|
4
|
+
'deploy target; overrides deploy.target and MODERNJS_DEPLOY'
|
|
5
|
+
];
|
|
2
6
|
const devCommand = async (program, api)=>{
|
|
3
7
|
program.command('dev').alias('start').usage('[options]').description(i18n.t(localeKeys.command.dev.describe)).option('-c --config <config>', i18n.t(localeKeys.command.shared.config)).option('-e --entry [entry...]', i18n.t(localeKeys.command.dev.entry)).option('--analyze', i18n.t(localeKeys.command.shared.analyze)).option('--api-only', i18n.t(localeKeys.command.dev.apiOnly)).option('--web-only', i18n.t(localeKeys.command.dev.webOnly)).action(async (options)=>{
|
|
4
8
|
const { dev } = await import("./dev.mjs");
|
|
@@ -6,7 +10,7 @@ const devCommand = async (program, api)=>{
|
|
|
6
10
|
});
|
|
7
11
|
};
|
|
8
12
|
const buildCommand = async (program, api)=>{
|
|
9
|
-
program.command('build').usage('[options]').description(i18n.t(localeKeys.command.build.describe)).option('-c --config <config>', i18n.t(localeKeys.command.shared.config)).option('--analyze', i18n.t(localeKeys.command.shared.analyze)).option('-w --watch', i18n.t(localeKeys.command.build.watch)).action(async (options)=>{
|
|
13
|
+
program.command('build').usage('[options]').description(i18n.t(localeKeys.command.build.describe)).option('-c --config <config>', i18n.t(localeKeys.command.shared.config)).option('--analyze', i18n.t(localeKeys.command.shared.analyze)).option('-w --watch', i18n.t(localeKeys.command.build.watch)).option(...deployTargetOption).action(async (options)=>{
|
|
10
14
|
const { build } = await import("./build.mjs");
|
|
11
15
|
await build(api, options);
|
|
12
16
|
});
|
|
@@ -18,7 +22,7 @@ const serverCommand = (program, api)=>{
|
|
|
18
22
|
});
|
|
19
23
|
};
|
|
20
24
|
const deployCommand = (program, api)=>{
|
|
21
|
-
program.command('deploy').usage('[options]').option('-c --config <config>', i18n.t(localeKeys.command.shared.config)).option('-s --skip-build', i18n.t(localeKeys.command.shared.skipBuild)).description(i18n.t(localeKeys.command.deploy.describe)).action(async (options)=>{
|
|
25
|
+
program.command('deploy').usage('[options]').option('-c --config <config>', i18n.t(localeKeys.command.shared.config)).option('-s --skip-build', i18n.t(localeKeys.command.shared.skipBuild)).option(...deployTargetOption).description(i18n.t(localeKeys.command.deploy.describe)).action(async (options)=>{
|
|
22
26
|
const { deploy } = await import("./deploy.mjs");
|
|
23
27
|
await deploy(api, options);
|
|
24
28
|
process.exit(0);
|
|
@@ -59,7 +59,7 @@ function handleSetupResult(setupResult, api) {
|
|
|
59
59
|
if (newAPI && api[newAPI]) api[newAPI](async (...params)=>{
|
|
60
60
|
const { isMultiple, params: transformParams } = transformHookParams(key, params);
|
|
61
61
|
if (isMultiple) return transformHookResult(key, await fn(...transformParams));
|
|
62
|
-
return transformHookResult(key, await fn(transformParams));
|
|
62
|
+
else return transformHookResult(key, await fn(transformParams));
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
});
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolveDeployTarget } from "@modern-js/app-tools-extensions/deploy-output/target";
|
|
2
|
+
import { createPolicyDefaultsPlugin } from "@modern-js/app-tools-extensions/policy-defaults";
|
|
2
3
|
import { castArray } from "@modern-js/builder";
|
|
3
4
|
import { getLocaleLanguage } from "@modern-js/i18n-utils/language-detector";
|
|
4
5
|
import { createAsyncHook } from "@modern-js/plugin";
|
|
@@ -9,7 +10,6 @@ import { compatPlugin } from "./compat/index.mjs";
|
|
|
9
10
|
import { DEFAULT_RUNTIME_CONFIG_FILE } from "./constants.mjs";
|
|
10
11
|
import { i18n } from "./locale/index.mjs";
|
|
11
12
|
import analyze from "./plugins/analyze/index.mjs";
|
|
12
|
-
import backendFederationBuild from "./plugins/backendFederationBuild.mjs";
|
|
13
13
|
import deploy from "./plugins/deploy/index.mjs";
|
|
14
14
|
import initialize from "./plugins/initialize/index.mjs";
|
|
15
15
|
import serverBuild from "./plugins/serverBuild.mjs";
|
|
@@ -18,9 +18,8 @@ import { generateWatchFiles } from "./utils/generateWatchFiles.mjs";
|
|
|
18
18
|
import { initAppContext } from "./utils/initAppContext.mjs";
|
|
19
19
|
import { restart } from "./utils/restart.mjs";
|
|
20
20
|
export * from "./defineConfig.mjs";
|
|
21
|
-
export * from "./presetUltramodern.mjs";
|
|
22
21
|
export * from "./types/index.mjs";
|
|
23
|
-
const appTools = ()=>({
|
|
22
|
+
const appTools = (options = {})=>({
|
|
24
23
|
name: '@modern-js/app-tools',
|
|
25
24
|
usePlugins: [
|
|
26
25
|
serverRuntime(),
|
|
@@ -28,9 +27,8 @@ const appTools = ()=>({
|
|
|
28
27
|
initialize(),
|
|
29
28
|
analyze(),
|
|
30
29
|
serverBuild(),
|
|
31
|
-
backendFederationBuild(),
|
|
32
30
|
deploy(),
|
|
33
|
-
|
|
31
|
+
createPolicyDefaultsPlugin(options)
|
|
34
32
|
],
|
|
35
33
|
post: [
|
|
36
34
|
'@modern-js/plugin-initialize',
|
|
@@ -77,6 +75,11 @@ const appTools = ()=>({
|
|
|
77
75
|
deprecatedCommands(program);
|
|
78
76
|
});
|
|
79
77
|
api.onPrepare(async ()=>{
|
|
78
|
+
api.updateAppContext({
|
|
79
|
+
deployTarget: resolveDeployTarget({
|
|
80
|
+
configTarget: api.getNormalizedConfig().deploy?.target
|
|
81
|
+
})
|
|
82
|
+
});
|
|
80
83
|
const command = getCommand();
|
|
81
84
|
if ('deploy' === command) {
|
|
82
85
|
const isSkipBuild = [
|
|
@@ -61,6 +61,6 @@ const getFileSystemEntry = async (hooks, appContext, config)=>{
|
|
|
61
61
|
}));
|
|
62
62
|
return scanDir(hooks, dirs);
|
|
63
63
|
} else throw Error("source.entriesDir accept a directory.");
|
|
64
|
-
throw Error(`src dir ${entriesDir} not found.`);
|
|
64
|
+
else throw Error(`src dir ${entriesDir} not found.`);
|
|
65
65
|
};
|
|
66
66
|
export { getFileSystemEntry, hasEntry, hasServerEntry };
|
|
@@ -9,14 +9,14 @@ const walkDirectory = (dir)=>fs.readdirSync(dir).reduce((previous, filename)=>{
|
|
|
9
9
|
...previous,
|
|
10
10
|
...walkDirectory(filePath)
|
|
11
11
|
];
|
|
12
|
-
return [
|
|
12
|
+
else return [
|
|
13
13
|
...previous,
|
|
14
14
|
filePath
|
|
15
15
|
];
|
|
16
16
|
}, []);
|
|
17
17
|
const replaceWithAlias = (base, filePath, alias)=>{
|
|
18
18
|
if (filePath.includes(base)) return normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
|
|
19
|
-
return filePath;
|
|
19
|
+
else return filePath;
|
|
20
20
|
};
|
|
21
21
|
const parseModule = async ({ source, filename })=>{
|
|
22
22
|
let content = source;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createCloudflarePreset } from "@modern-js/app-tools-extensions/cloudflare";
|
|
2
|
-
import {
|
|
2
|
+
import { getDeployingTarget } from "@modern-js/app-tools-extensions/deploy-output/target";
|
|
3
3
|
import { createGhPagesPreset } from "./platforms/gh-pages.mjs";
|
|
4
4
|
import { createNetlifyPreset } from "./platforms/netlify.mjs";
|
|
5
5
|
import { createNodePreset } from "./platforms/node.mjs";
|
|
@@ -12,24 +12,11 @@ const deployPresets = {
|
|
|
12
12
|
ghPages: createGhPagesPreset,
|
|
13
13
|
cloudflare: createCloudflarePreset
|
|
14
14
|
};
|
|
15
|
-
const getSupportedDeployTargets = ()=>Object.keys(deployPresets);
|
|
16
|
-
const isDeployTarget = (target)=>Object.prototype.hasOwnProperty.call(deployPresets, target);
|
|
17
|
-
const providerDeployTargets = {
|
|
18
|
-
vercel: 'vercel',
|
|
19
|
-
netlify: 'netlify',
|
|
20
|
-
cloudflare: 'cloudflare',
|
|
21
|
-
cloudflare_pages: 'cloudflare',
|
|
22
|
-
cloudflare_workers: 'cloudflare'
|
|
23
|
-
};
|
|
24
|
-
const normalizeDetectedProvider = (value)=>value ? providerDeployTargets[value] : void 0;
|
|
25
|
-
const resolveDeployTarget = (modernConfig, envDeployTarget = process.env.MODERNJS_DEPLOY, detectedProvider = provider)=>modernConfig.deploy?.target || envDeployTarget || normalizeDetectedProvider(detectedProvider) || 'node';
|
|
26
15
|
async function getDeployPreset(appContext, modernConfig, deployTarget, api) {
|
|
27
16
|
const { appDirectory, distDirectory, metaName } = appContext;
|
|
28
17
|
const { useSSR, useAPI, useWebServer } = getProjectUsage(appDirectory, distDirectory, metaName);
|
|
29
18
|
const needModernServer = useSSR || useAPI || useWebServer;
|
|
30
|
-
|
|
31
|
-
const createPreset = deployPresets[deployTarget];
|
|
32
|
-
return createPreset({
|
|
19
|
+
return deployPresets[deployTarget]({
|
|
33
20
|
appContext,
|
|
34
21
|
modernConfig,
|
|
35
22
|
needModernServer,
|
|
@@ -41,11 +28,9 @@ const deploy = ()=>({
|
|
|
41
28
|
setup: (api)=>{
|
|
42
29
|
api.deploy(async ()=>{
|
|
43
30
|
const appContext = api.getAppContext();
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
if ('modern-js' !== metaName && !modernConfig.deploy?.target && !process.env.MODERNJS_DEPLOY) return;
|
|
48
|
-
const deployPreset = await getDeployPreset(appContext, modernConfig, deployTarget, api);
|
|
31
|
+
const deployTarget = getDeployingTarget(appContext);
|
|
32
|
+
if (!deployTarget) return;
|
|
33
|
+
const deployPreset = await getDeployPreset(appContext, api.getNormalizedConfig(), deployTarget, api);
|
|
49
34
|
deployPreset?.prepare && await deployPreset?.prepare();
|
|
50
35
|
deployPreset?.writeOutput && await deployPreset?.writeOutput();
|
|
51
36
|
deployPreset?.genEntry && await deployPreset?.genEntry();
|
|
@@ -54,4 +39,3 @@ const deploy = ()=>({
|
|
|
54
39
|
}
|
|
55
40
|
});
|
|
56
41
|
export default deploy;
|
|
57
|
-
export { getSupportedDeployTargets, resolveDeployTarget };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import node_path from "node:path";
|
|
2
|
+
import { traceDeployFiles } from "@modern-js/app-tools-extensions/deploy-output/trace-files";
|
|
2
3
|
import { fs, removeModuleSyncFromExports } from "@modern-js/utils";
|
|
3
4
|
import { nodeDepEmit } from "ndepe";
|
|
4
5
|
import { isMainEntry } from "../../../utils/routes.mjs";
|
|
@@ -71,8 +72,8 @@ const createNetlifyPreset = ({ appContext, modernConfig, needModernServer })=>{
|
|
|
71
72
|
if (!needModernServer) return;
|
|
72
73
|
const entry = isEsmProject ? await resolveESMDependency('@modern-js/prod-server') : require.resolve('@modern-js/prod-server');
|
|
73
74
|
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');
|
|
75
75
|
await nodeDepEmit({
|
|
76
|
+
traceFiles: traceDeployFiles,
|
|
76
77
|
appDir: appDirectory,
|
|
77
78
|
sourceDir: funcsDirectory,
|
|
78
79
|
includeEntries: [
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
1
2
|
import node_path from "node:path";
|
|
3
|
+
import { traceDeployFiles } from "@modern-js/app-tools-extensions/deploy-output/trace-files";
|
|
2
4
|
import { chalk, fs, removeModuleSyncFromExports } from "@modern-js/utils";
|
|
3
5
|
import { nodeDepEmit } from "ndepe";
|
|
4
6
|
import { readTemplate, resolveESMDependency } from "../utils/index.mjs";
|
|
5
7
|
import { generateHandler } from "../utils/generator.mjs";
|
|
6
|
-
import { preserveNpmAliases, readPackageIdentity } from "../utils/npmAliases.mjs";
|
|
7
8
|
const createNodePreset = ({ appContext, modernConfig })=>{
|
|
8
|
-
const { appDirectory, distDirectory, moduleType } = appContext;
|
|
9
|
+
const { appDirectory, distDirectory, moduleType, serverPlugins } = appContext;
|
|
9
10
|
const isEsmProject = 'module' === moduleType;
|
|
10
11
|
const outputDirectory = node_path.join(appDirectory, '.output');
|
|
11
12
|
const staticDirectory = node_path.join(outputDirectory, 'static');
|
|
@@ -35,13 +36,19 @@ const createNodePreset = ({ appContext, modernConfig })=>{
|
|
|
35
36
|
async end () {
|
|
36
37
|
const filter = (filePath)=>!filePath.startsWith(staticDirectory) && !filePath.endsWith('.map');
|
|
37
38
|
const entry = isEsmProject ? await resolveESMDependency('@modern-js/prod-server') : require.resolve('@modern-js/prod-server');
|
|
38
|
-
|
|
39
|
-
const
|
|
39
|
+
const requireFromApp = createRequire(node_path.join(appDirectory, 'package.json'));
|
|
40
|
+
const pluginEntries = new Set();
|
|
41
|
+
for (const plugin of serverPlugins)for (const specifier of plugin.includeEntries ?? []){
|
|
42
|
+
pluginEntries.add(requireFromApp.resolve(specifier));
|
|
43
|
+
if (isEsmProject) pluginEntries.add(await resolveESMDependency(specifier, appDirectory));
|
|
44
|
+
}
|
|
40
45
|
await nodeDepEmit({
|
|
46
|
+
traceFiles: traceDeployFiles,
|
|
41
47
|
appDir: appDirectory,
|
|
42
48
|
sourceDir: outputDirectory,
|
|
43
49
|
includeEntries: [
|
|
44
|
-
entry
|
|
50
|
+
entry,
|
|
51
|
+
...pluginEntries
|
|
45
52
|
],
|
|
46
53
|
copyWholePackage (pkgName) {
|
|
47
54
|
return '@modern-js/utils' === pkgName;
|
|
@@ -55,17 +62,6 @@ const createNodePreset = ({ appContext, modernConfig })=>{
|
|
|
55
62
|
};
|
|
56
63
|
}
|
|
57
64
|
});
|
|
58
|
-
await preserveNpmAliases({
|
|
59
|
-
appDirectory,
|
|
60
|
-
outputDirectory,
|
|
61
|
-
implicitAliases: [
|
|
62
|
-
{
|
|
63
|
-
aliasName: '@modern-js/prod-server',
|
|
64
|
-
targetName: prodServerPackage.name,
|
|
65
|
-
targetVersion: prodServerPackage.version
|
|
66
|
-
}
|
|
67
|
-
]
|
|
68
|
-
});
|
|
69
65
|
console.log('Static directory:', chalk.blue(node_path.relative(appDirectory, staticDirectory).replace(/\\/g, '/')));
|
|
70
66
|
console.log("You can preview this build by", chalk.blue('node .output/index'));
|
|
71
67
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import node_path from "node:path";
|
|
2
|
+
import { traceDeployFiles } from "@modern-js/app-tools-extensions/deploy-output/trace-files";
|
|
2
3
|
import { fs, removeModuleSyncFromExports } from "@modern-js/utils";
|
|
3
4
|
import { nodeDepEmit } from "ndepe";
|
|
4
5
|
import { isMainEntry } from "../../../utils/routes.mjs";
|
|
@@ -91,8 +92,8 @@ const createVercelPreset = ({ appContext, modernConfig, needModernServer })=>{
|
|
|
91
92
|
async end () {
|
|
92
93
|
if (!needModernServer) return;
|
|
93
94
|
const entry = isEsmProject ? await resolveESMDependency('@modern-js/prod-server') : require.resolve('@modern-js/prod-server');
|
|
94
|
-
if (!entry) throw new Error('Cannot find @modern-js/prod-server');
|
|
95
95
|
await nodeDepEmit({
|
|
96
|
+
traceFiles: traceDeployFiles,
|
|
96
97
|
appDir: appDirectory,
|
|
97
98
|
sourceDir: funcsDirectory,
|
|
98
99
|
includeEntries: [
|
|
@@ -15,7 +15,7 @@ const serverAppContextTemplate = (appContext)=>{
|
|
|
15
15
|
};
|
|
16
16
|
const genPluginImportsCode = (plugins, isESM = false)=>plugins.map(([name, options], index)=>{
|
|
17
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
|
|
18
|
+
return `${im};const plugin_${index} = typeof plugin_${index}_ns === 'function' ? plugin_${index}_ns : typeof plugin_${index}_ns.default === 'function' ? plugin_${index}_ns.default : plugin_${index}_ns.default?.default`;
|
|
19
19
|
}).join(';\n');
|
|
20
20
|
const getPluginsCode = (plugins)=>`[${plugins.map(([, options], index)=>`plugin_${index}(${options ? JSON.stringify(options) : ''})`).join(',')}]`;
|
|
21
21
|
const getServerConfigPath = (meta)=>`path.join(__dirname, "${SERVER_DIR}", "${meta}.server")`;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
2
|
+
import { ROUTE_SPEC_FILE, SERVER_DIR, fs, getMeta } from "@modern-js/utils";
|
|
3
|
+
import { moduleResolve } from "import-meta-resolve";
|
|
4
4
|
import path from "path";
|
|
5
5
|
const normalizePath = (filePath)=>filePath.replace(/\\/g, '/');
|
|
6
6
|
const getProjectUsage = (appDirectory, distDirectory, metaName)=>{
|
|
@@ -26,17 +26,20 @@ const getProjectUsage = (appDirectory, distDirectory, metaName)=>{
|
|
|
26
26
|
};
|
|
27
27
|
const getTemplatePath = (file)=>path.join(__dirname, '../platforms/templates', file);
|
|
28
28
|
const readTemplate = async (file)=>(await fs.readFile(getTemplatePath(file))).toString();
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
const DEPLOY_CONDITIONS = [
|
|
30
|
+
'node',
|
|
31
|
+
'import',
|
|
32
|
+
'module',
|
|
33
|
+
'default'
|
|
34
|
+
];
|
|
35
|
+
const resolveESMDependency = async (entry, fromDirectory)=>{
|
|
36
|
+
const base = fromDirectory ? pathToFileURL(path.join(fromDirectory, 'package.json')) : pathToFileURL(`${__dirname}/`);
|
|
36
37
|
try {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
return normalizePath(fileURLToPath(moduleResolve(entry, base, new Set(DEPLOY_CONDITIONS), false)));
|
|
39
|
+
} catch (cause) {
|
|
40
|
+
throw new Error(`Cannot resolve "${entry}" with conditions [${DEPLOY_CONDITIONS.join(', ')}] from ${base.href}: ${cause.message}`, {
|
|
41
|
+
cause
|
|
42
|
+
});
|
|
43
|
+
}
|
|
41
44
|
};
|
|
42
45
|
export { getProjectUsage, getTemplatePath, normalizePath, readTemplate, resolveESMDependency };
|