@modern-js/app-tools 2.54.5 → 2.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/builder/generator/createBuilderOptions.js +18 -1
- package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +2 -2
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +2 -2
- package/dist/cjs/commands/index.js +2 -2
- package/dist/cjs/commands/serve.js +1 -0
- package/dist/cjs/config/default.js +2 -0
- package/dist/cjs/config/legacy/createSourceConfig.js +2 -1
- package/dist/cjs/hooks.js +2 -5
- package/dist/cjs/plugins/analyze/constants.js +3 -18
- package/dist/cjs/plugins/analyze/getFileSystemEntry.js +36 -11
- package/dist/cjs/plugins/analyze/index.js +7 -64
- package/dist/cjs/plugins/analyze/templates.js +2 -55
- package/dist/cjs/plugins/analyze/utils.js +0 -86
- package/dist/esm/builder/generator/createBuilderOptions.js +21 -1
- package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +1 -1
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +1 -1
- package/dist/esm/commands/index.js +1 -1
- package/dist/esm/commands/serve.js +1 -0
- package/dist/esm/config/default.js +2 -0
- package/dist/esm/config/legacy/createSourceConfig.js +2 -1
- package/dist/esm/hooks.js +2 -5
- package/dist/esm/plugins/analyze/constants.js +2 -12
- package/dist/esm/plugins/analyze/getFileSystemEntry.js +57 -14
- package/dist/esm/plugins/analyze/index.js +25 -128
- package/dist/esm/plugins/analyze/templates.js +1 -17
- package/dist/esm/plugins/analyze/utils.js +1 -87
- package/dist/esm-node/builder/generator/createBuilderOptions.js +18 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +1 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +1 -1
- package/dist/esm-node/commands/index.js +1 -1
- package/dist/esm-node/commands/serve.js +1 -0
- package/dist/esm-node/config/default.js +2 -0
- package/dist/esm-node/config/legacy/createSourceConfig.js +2 -1
- package/dist/esm-node/hooks.js +2 -5
- package/dist/esm-node/plugins/analyze/constants.js +2 -12
- package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +37 -12
- package/dist/esm-node/plugins/analyze/index.js +10 -67
- package/dist/esm-node/plugins/analyze/templates.js +1 -52
- package/dist/esm-node/plugins/analyze/utils.js +1 -86
- package/dist/types/builder/builder-webpack/createCopyPattern.d.ts +2 -2
- package/dist/types/builder/generator/createBuilderOptions.d.ts +1 -2
- package/dist/types/builder/generator/getBuilderTargets.d.ts +1 -1
- package/dist/types/builder/generator/index.d.ts +1 -2
- package/dist/types/builder/shared/builderPlugins/adapterBasic.d.ts +1 -1
- package/dist/types/builder/shared/builderPlugins/adapterHtml.d.ts +1 -1
- package/dist/types/builder/shared/builderPlugins/adapterSSR.d.ts +1 -1
- package/dist/types/builder/shared/builderPlugins/adapterWorker.d.ts +1 -1
- package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +1 -1
- package/dist/types/commands/inspect.d.ts +1 -1
- package/dist/types/plugins/analyze/constants.d.ts +1 -6
- package/dist/types/plugins/analyze/templates.d.ts +0 -14
- package/dist/types/plugins/analyze/utils.d.ts +0 -11
- package/dist/types/types/config/source.d.ts +5 -0
- package/dist/types/types/hooks.d.ts +7 -27
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/legacyConfig/output.d.ts +1 -1
- package/dist/types/types/legacyConfig/source.d.ts +4 -0
- package/dist/types/utils/register.d.ts +1 -1
- package/package.json +17 -18
- package/dist/cjs/plugins/analyze/generateCode.js +0 -185
- package/dist/esm/plugins/analyze/generateCode.js +0 -296
- package/dist/esm-node/plugins/analyze/generateCode.js +0 -149
- package/dist/types/plugins/analyze/generateCode.d.ts +0 -16
@@ -37,11 +37,28 @@ function createBuilderOptions(target, appContext) {
|
|
37
37
|
];
|
38
38
|
}
|
39
39
|
}
|
40
|
+
const serverEntries = {};
|
41
|
+
for (const entry in entries) {
|
42
|
+
const v = entries[entry];
|
43
|
+
serverEntries[entry] = v.map((entry2) => entry2.replace("index.jsx", "index.server.jsx"));
|
44
|
+
}
|
40
45
|
return {
|
41
46
|
cwd: appContext.appDirectory,
|
42
47
|
target,
|
43
48
|
frameworkConfigPath: appContext.configFile || void 0,
|
44
|
-
entry:
|
49
|
+
entry({ target: target2 }) {
|
50
|
+
if (target2 === "web") {
|
51
|
+
return entries;
|
52
|
+
}
|
53
|
+
if ([
|
54
|
+
"node",
|
55
|
+
"web-worker",
|
56
|
+
"service-worker"
|
57
|
+
].includes(target2)) {
|
58
|
+
return serverEntries;
|
59
|
+
}
|
60
|
+
return entries;
|
61
|
+
}
|
45
62
|
};
|
46
63
|
}
|
47
64
|
// Annotate the CommonJS export names for ESM import in node:
|
@@ -21,7 +21,7 @@ __export(adapterHtml_exports, {
|
|
21
21
|
builderPluginAdapterHtml: () => builderPluginAdapterHtml
|
22
22
|
});
|
23
23
|
module.exports = __toCommonJS(adapterHtml_exports);
|
24
|
-
var
|
24
|
+
var import_uni_builder = require("@modern-js/uni-builder");
|
25
25
|
var import_utils = require("@modern-js/utils");
|
26
26
|
var import_lodash = require("@modern-js/utils/lodash");
|
27
27
|
var import_bundlerPlugins = require("../bundlerPlugins");
|
@@ -31,7 +31,7 @@ const builderPluginAdapterHtml = (options) => ({
|
|
31
31
|
setup(api) {
|
32
32
|
api.modifyBundlerChain(async (chain, { CHAIN_ID, target, HtmlPlugin: HtmlBundlerPlugin }) => {
|
33
33
|
const builderConfig = api.getNormalizedConfig();
|
34
|
-
if (!(0,
|
34
|
+
if (!(0, import_uni_builder.isHtmlDisabled)(builderConfig, target)) {
|
35
35
|
applyBottomHtmlPlugin({
|
36
36
|
api,
|
37
37
|
options,
|
@@ -32,9 +32,9 @@ __export(adapterSSR_exports, {
|
|
32
32
|
});
|
33
33
|
module.exports = __toCommonJS(adapterSSR_exports);
|
34
34
|
var path = __toESM(require("path"));
|
35
|
-
var import_shared = require("@rsbuild/shared");
|
36
35
|
var import_core = require("@rsbuild/core");
|
37
36
|
var import_utils = require("@modern-js/utils");
|
37
|
+
var import_uni_builder = require("@modern-js/uni-builder");
|
38
38
|
var import_bundlerPlugins = require("../bundlerPlugins");
|
39
39
|
var import_utils2 = require("../../../plugins/analyze/utils");
|
40
40
|
const builderPluginAdapterSSR = (options) => ({
|
@@ -71,7 +71,7 @@ const builderPluginAdapterSSR = (options) => ({
|
|
71
71
|
appNormalizedConfig: normalizedConfig2
|
72
72
|
});
|
73
73
|
}
|
74
|
-
if (!(0,
|
74
|
+
if (!(0, import_uni_builder.isHtmlDisabled)(builderConfig, target)) {
|
75
75
|
applyAsyncChunkHtmlPlugin({
|
76
76
|
chain,
|
77
77
|
modernConfig: options.normalizedConfig,
|
@@ -38,7 +38,7 @@ __export(commands_exports, {
|
|
38
38
|
});
|
39
39
|
module.exports = __toCommonJS(commands_exports);
|
40
40
|
var import_utils = require("@modern-js/utils");
|
41
|
-
var
|
41
|
+
var import_uni_builder = require("@modern-js/uni-builder");
|
42
42
|
var import_locale = require("../locale");
|
43
43
|
const devCommand = async (program, api) => {
|
44
44
|
const runner = api.useHookRunners();
|
@@ -71,7 +71,7 @@ const buildCommand = async (program, api) => {
|
|
71
71
|
await build(api, options);
|
72
72
|
});
|
73
73
|
for (const platformBuilder of platformBuilders) {
|
74
|
-
const platforms = (0,
|
74
|
+
const platforms = (0, import_uni_builder.castArray)(platformBuilder.platform);
|
75
75
|
for (const platform of platforms) {
|
76
76
|
buildProgram.command(platform).action(async () => {
|
77
77
|
const { appDirectory } = api.useAppContext();
|
@@ -57,6 +57,7 @@ const start = async (api) => {
|
|
57
57
|
config: {
|
58
58
|
...userConfig,
|
59
59
|
dev: userConfig.dev,
|
60
|
+
// server-core can't get RegExp & Function output.enableInlineScripts by JSON.stringy;
|
60
61
|
output: {
|
61
62
|
path: (_userConfig_output_distPath = userConfig.output.distPath) === null || _userConfig_output_distPath === void 0 ? void 0 : _userConfig_output_distPath.root,
|
62
63
|
...userConfig.output || {}
|
@@ -50,6 +50,7 @@ function createDefaultConfig(appContext) {
|
|
50
50
|
entries: void 0,
|
51
51
|
mainEntryName: import_utils.MAIN_ENTRY_NAME,
|
52
52
|
enableAsyncEntry: false,
|
53
|
+
enableCustomEntry: false,
|
53
54
|
disableDefaultEntries: false,
|
54
55
|
entriesDir: "./src",
|
55
56
|
configDir: "./config",
|
@@ -122,6 +123,7 @@ function createLegacyDefaultConfig(appContext) {
|
|
122
123
|
entries: void 0,
|
123
124
|
mainEntryName: import_utils.MAIN_ENTRY_NAME,
|
124
125
|
enableAsyncEntry: false,
|
126
|
+
enableCustomEntry: false,
|
125
127
|
disableDefaultEntries: false,
|
126
128
|
entriesDir: "./src",
|
127
129
|
configDir: "./config",
|
@@ -22,7 +22,7 @@ __export(createSourceConfig_exports, {
|
|
22
22
|
});
|
23
23
|
module.exports = __toCommonJS(createSourceConfig_exports);
|
24
24
|
function createSourceConfig(config) {
|
25
|
-
const { alias, envVars, globalVars, include, moduleScopes, preEntry, entries, mainEntryName, enableAsyncEntry, disableDefaultEntries, entriesDir, configDir } = config.source;
|
25
|
+
const { alias, envVars, globalVars, include, moduleScopes, preEntry, entries, mainEntryName, enableAsyncEntry, enableCustomEntry, disableDefaultEntries, entriesDir, configDir } = config.source;
|
26
26
|
const builderGlobalVars = globalVars || {};
|
27
27
|
for (const envVar of envVars || []) {
|
28
28
|
const envVarValue = process.env[envVar];
|
@@ -37,6 +37,7 @@ function createSourceConfig(config) {
|
|
37
37
|
entries,
|
38
38
|
mainEntryName,
|
39
39
|
enableAsyncEntry,
|
40
|
+
enableCustomEntry,
|
40
41
|
disableDefaultEntries,
|
41
42
|
entriesDir,
|
42
43
|
configDir,
|
package/dist/cjs/hooks.js
CHANGED
@@ -23,17 +23,14 @@ __export(hooks_exports, {
|
|
23
23
|
module.exports = __toCommonJS(hooks_exports);
|
24
24
|
var import_plugin = require("@modern-js/plugin");
|
25
25
|
const hooks = {
|
26
|
-
|
27
|
-
modifyEntryImports: (0, import_plugin.createAsyncWaterfall)(),
|
28
|
-
modifyEntryRuntimePlugins: (0, import_plugin.createAsyncWaterfall)(),
|
29
|
-
modifyEntryRenderFunction: (0, import_plugin.createAsyncWaterfall)(),
|
30
|
-
modifyAsyncEntry: (0, import_plugin.createAsyncWaterfall)(),
|
26
|
+
_internalRuntimePlugins: (0, import_plugin.createAsyncWaterfall)(),
|
31
27
|
modifyFileSystemRoutes: (0, import_plugin.createAsyncWaterfall)(),
|
32
28
|
modifyServerRoutes: (0, import_plugin.createAsyncWaterfall)(),
|
33
29
|
/** add entry point info to entrypoints array */
|
34
30
|
modifyEntrypoints: (0, import_plugin.createAsyncWaterfall)(),
|
35
31
|
/** add entry type */
|
36
32
|
checkEntryPoint: (0, import_plugin.createAsyncWaterfall)(),
|
33
|
+
generateEntryCode: (0, import_plugin.createAsyncWorkflow)(),
|
37
34
|
htmlPartials: (0, import_plugin.createAsyncWaterfall)(),
|
38
35
|
beforeGenerateRoutes: (0, import_plugin.createAsyncWaterfall)(),
|
39
36
|
addDefineTypes: (0, import_plugin.createAsyncWaterfall)(),
|
@@ -18,38 +18,23 @@ var __copyProps = (to, from, except, desc) => {
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
19
|
var constants_exports = {};
|
20
20
|
__export(constants_exports, {
|
21
|
-
|
22
|
-
APP_INIT_EXPORTED: () => APP_INIT_EXPORTED,
|
23
|
-
APP_INIT_IMPORTED: () => APP_INIT_IMPORTED,
|
24
|
-
ENTRY_BOOTSTRAP_FILE_NAME: () => ENTRY_BOOTSTRAP_FILE_NAME,
|
25
|
-
ENTRY_POINT_FILE_NAME: () => ENTRY_POINT_FILE_NAME,
|
26
|
-
FILE_SYSTEM_ROUTES_FILE_NAME: () => FILE_SYSTEM_ROUTES_FILE_NAME,
|
21
|
+
ENTRY_FILE_NAME: () => ENTRY_FILE_NAME,
|
27
22
|
HTML_PARTIALS_EXTENSIONS: () => HTML_PARTIALS_EXTENSIONS,
|
28
23
|
HTML_PARTIALS_FOLDER: () => HTML_PARTIALS_FOLDER,
|
29
24
|
INDEX_FILE_NAME: () => INDEX_FILE_NAME
|
30
25
|
});
|
31
26
|
module.exports = __toCommonJS(constants_exports);
|
32
27
|
const INDEX_FILE_NAME = "index";
|
33
|
-
const
|
34
|
-
const ENTRY_POINT_FILE_NAME = "index.jsx";
|
35
|
-
const ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.jsx";
|
28
|
+
const ENTRY_FILE_NAME = "entry";
|
36
29
|
const HTML_PARTIALS_FOLDER = "html";
|
37
30
|
const HTML_PARTIALS_EXTENSIONS = [
|
38
31
|
".htm",
|
39
32
|
".html",
|
40
33
|
".ejs"
|
41
34
|
];
|
42
|
-
const APP_CONFIG_NAME = "config";
|
43
|
-
const APP_INIT_EXPORTED = "init";
|
44
|
-
const APP_INIT_IMPORTED = "appInit";
|
45
35
|
// Annotate the CommonJS export names for ESM import in node:
|
46
36
|
0 && (module.exports = {
|
47
|
-
|
48
|
-
APP_INIT_EXPORTED,
|
49
|
-
APP_INIT_IMPORTED,
|
50
|
-
ENTRY_BOOTSTRAP_FILE_NAME,
|
51
|
-
ENTRY_POINT_FILE_NAME,
|
52
|
-
FILE_SYSTEM_ROUTES_FILE_NAME,
|
37
|
+
ENTRY_FILE_NAME,
|
53
38
|
HTML_PARTIALS_EXTENSIONS,
|
54
39
|
HTML_PARTIALS_FOLDER,
|
55
40
|
INDEX_FILE_NAME
|
@@ -37,16 +37,28 @@ var import_utils = require("@modern-js/utils");
|
|
37
37
|
var import_constants = require("./constants");
|
38
38
|
var import_isDefaultExportFunction = require("./isDefaultExportFunction");
|
39
39
|
const hasIndex = (dir) => (0, import_utils.findExists)(import_utils.JS_EXTENSIONS.map((ext) => import_path.default.resolve(dir, `${import_constants.INDEX_FILE_NAME}${ext}`)));
|
40
|
-
const
|
41
|
-
|
40
|
+
const hasEntry = (dir) => (0, import_utils.findExists)(import_utils.JS_EXTENSIONS.map((ext) => import_path.default.resolve(dir, `${import_constants.ENTRY_FILE_NAME}${ext}`)));
|
41
|
+
const hasServerEntry = (dir) => (0, import_utils.findExists)(import_utils.JS_EXTENSIONS.map((ext) => import_path.default.resolve(dir, `${import_constants.ENTRY_FILE_NAME}.server${ext}`)));
|
42
|
+
const isBundleEntry = async (hookRunners, dir, enableCustomEntry) => {
|
43
|
+
const { entry } = await hookRunners.checkEntryPoint({
|
42
44
|
path: dir,
|
43
45
|
entry: false
|
44
|
-
})
|
46
|
+
});
|
47
|
+
if (entry) {
|
48
|
+
return entry;
|
49
|
+
}
|
50
|
+
const customEntry = hasEntry(dir);
|
51
|
+
if (enableCustomEntry && customEntry) {
|
52
|
+
return customEntry;
|
53
|
+
}
|
54
|
+
return hasIndex(dir);
|
45
55
|
};
|
46
|
-
const scanDir = (hookRunners, dirs) => Promise.all(dirs.map(async (dir) => {
|
56
|
+
const scanDir = (hookRunners, dirs, enableCustomEntry) => Promise.all(dirs.map(async (dir) => {
|
47
57
|
const indexFile = hasIndex(dir);
|
48
58
|
const customBootstrap = (0, import_isDefaultExportFunction.isDefaultExportFunction)(indexFile) ? indexFile : false;
|
49
59
|
const entryName = import_path.default.basename(dir);
|
60
|
+
const customEntryFile = hasEntry(dir);
|
61
|
+
const customServerEntry = hasServerEntry(dir);
|
50
62
|
if (indexFile && !customBootstrap) {
|
51
63
|
return {
|
52
64
|
entryName,
|
@@ -65,17 +77,30 @@ const scanDir = (hookRunners, dirs) => Promise.all(dirs.map(async (dir) => {
|
|
65
77
|
return {
|
66
78
|
entryName,
|
67
79
|
isMainEntry: false,
|
68
|
-
entry: entryFile,
|
80
|
+
entry: enableCustomEntry ? customEntryFile || entryFile : entryFile,
|
81
|
+
customServerEntry,
|
69
82
|
absoluteEntryDir: import_path.default.resolve(dir),
|
70
83
|
isAutoMount: true,
|
71
|
-
customBootstrap
|
84
|
+
customBootstrap,
|
85
|
+
customEntry: enableCustomEntry ? Boolean(customEntryFile) : false
|
86
|
+
};
|
87
|
+
}
|
88
|
+
if (enableCustomEntry && customEntryFile) {
|
89
|
+
return {
|
90
|
+
entryName,
|
91
|
+
isMainEntry: false,
|
92
|
+
entry: customEntryFile,
|
93
|
+
customServerEntry,
|
94
|
+
absoluteEntryDir: import_path.default.resolve(dir),
|
95
|
+
isAutoMount: false,
|
96
|
+
customEntry: Boolean(customEntryFile)
|
72
97
|
};
|
73
98
|
}
|
74
99
|
throw Error("There is no valid entry point in the current project!");
|
75
100
|
}));
|
76
101
|
const getFileSystemEntry = async (hookRunners, appContext, config) => {
|
77
102
|
const { appDirectory } = appContext;
|
78
|
-
const { source: { entriesDir, disableEntryDirs } } = config;
|
103
|
+
const { source: { entriesDir, disableEntryDirs, enableCustomEntry } } = config;
|
79
104
|
let disabledDirs = [];
|
80
105
|
if (disableEntryDirs && Array.isArray(disableEntryDirs)) {
|
81
106
|
disabledDirs = disableEntryDirs === null || disableEntryDirs === void 0 ? void 0 : disableEntryDirs.map((dir) => (0, import_utils.ensureAbsolutePath)(appDirectory, dir));
|
@@ -83,19 +108,19 @@ const getFileSystemEntry = async (hookRunners, appContext, config) => {
|
|
83
108
|
const src = (0, import_utils.ensureAbsolutePath)(appDirectory, entriesDir || "");
|
84
109
|
if (import_fs.default.existsSync(src)) {
|
85
110
|
if (import_fs.default.statSync(src).isDirectory()) {
|
86
|
-
if (await isBundleEntry(hookRunners, src)) {
|
111
|
+
if (await isBundleEntry(hookRunners, src, enableCustomEntry)) {
|
87
112
|
return scanDir(hookRunners, [
|
88
113
|
src
|
89
|
-
]);
|
114
|
+
], enableCustomEntry);
|
90
115
|
}
|
91
116
|
const dirs = [];
|
92
117
|
await Promise.all(import_fs.default.readdirSync(src).map(async (filename) => {
|
93
118
|
const file = import_path.default.join(src, filename);
|
94
|
-
if (import_fs.default.statSync(file).isDirectory() && await isBundleEntry(hookRunners, file) && !disabledDirs.includes(file)) {
|
119
|
+
if (import_fs.default.statSync(file).isDirectory() && await isBundleEntry(hookRunners, file, enableCustomEntry) && !disabledDirs.includes(file)) {
|
95
120
|
dirs.push(file);
|
96
121
|
}
|
97
122
|
}));
|
98
|
-
return scanDir(hookRunners, dirs);
|
123
|
+
return scanDir(hookRunners, dirs, enableCustomEntry);
|
99
124
|
} else {
|
100
125
|
throw Error(`source.entriesDir accept a directory.`);
|
101
126
|
}
|
@@ -40,11 +40,12 @@ var import_getSelectedEntries = require("../../utils/getSelectedEntries");
|
|
40
40
|
var import_config2 = require("../../config");
|
41
41
|
var import_builder = require("../../builder");
|
42
42
|
var import_utils2 = require("./utils");
|
43
|
-
var import_constants = require("./constants");
|
44
|
-
var import_generateCode = require("./generateCode");
|
45
43
|
const debug = (0, import_utils.createDebugger)("plugin-analyze");
|
46
44
|
var analyze_default = ({ bundler }) => ({
|
47
45
|
name: "@modern-js/plugin-analyze",
|
46
|
+
post: [
|
47
|
+
"@modern-js/runtime"
|
48
|
+
],
|
48
49
|
setup: (api) => {
|
49
50
|
let pagesDir = [];
|
50
51
|
let nestedRouteEntries = [];
|
@@ -75,10 +76,9 @@ var analyze_default = ({ bundler }) => ({
|
|
75
76
|
api.setAppContext(appContext);
|
76
77
|
return;
|
77
78
|
}
|
78
|
-
const [{ getBundleEntry }, { getServerRoutes }, {
|
79
|
+
const [{ getBundleEntry }, { getServerRoutes }, { getHtmlTemplate }] = await Promise.all([
|
79
80
|
Promise.resolve().then(() => __toESM(require("./getBundleEntry"))),
|
80
81
|
Promise.resolve().then(() => __toESM(require("./getServerRoutes"))),
|
81
|
-
Promise.resolve().then(() => __toESM(require("./generateCode"))),
|
82
82
|
Promise.resolve().then(() => __toESM(require("./getHtmlTemplate")))
|
83
83
|
]);
|
84
84
|
const { entrypoints } = await hookRunners.modifyEntrypoints({
|
@@ -101,7 +101,6 @@ var analyze_default = ({ bundler }) => ({
|
|
101
101
|
api.setAppContext(appContext);
|
102
102
|
nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
|
103
103
|
pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !path.extname(entry)).concat(nestedRouteEntries);
|
104
|
-
const { importsStatemets } = await generateCode(appContext, resolvedConfig, entrypoints, api);
|
105
104
|
const htmlTemplates = await getHtmlTemplate(entrypoints, api, {
|
106
105
|
appContext,
|
107
106
|
config: resolvedConfig
|
@@ -124,6 +123,9 @@ var analyze_default = ({ bundler }) => ({
|
|
124
123
|
};
|
125
124
|
api.setAppContext(appContext);
|
126
125
|
if ((0, import_utils2.checkIsBuildCommands)()) {
|
126
|
+
await hookRunners.generateEntryCode({
|
127
|
+
entrypoints
|
128
|
+
});
|
127
129
|
const normalizedConfig = api.useResolvedConfigContext();
|
128
130
|
const createBuilderForModern = await (0, import_builder.createBuilderGenerator)(bundler);
|
129
131
|
const builder = await createBuilderForModern({
|
@@ -155,14 +157,6 @@ var analyze_default = ({ bundler }) => ({
|
|
155
157
|
});
|
156
158
|
builder.onBeforeCreateCompiler(async ({ bundlerConfigs }) => {
|
157
159
|
const hookRunners2 = api.useHookRunners();
|
158
|
-
await (0, import_generateCode.generateIndexCode)({
|
159
|
-
appContext,
|
160
|
-
config: resolvedConfig,
|
161
|
-
entrypoints,
|
162
|
-
api,
|
163
|
-
importsStatemets,
|
164
|
-
bundlerConfigs
|
165
|
-
});
|
166
160
|
await hookRunners2.beforeCreateCompiler({
|
167
161
|
bundlerConfigs
|
168
162
|
});
|
@@ -193,57 +187,6 @@ var analyze_default = ({ bundler }) => ({
|
|
193
187
|
return {
|
194
188
|
resolved: config
|
195
189
|
};
|
196
|
-
},
|
197
|
-
// This logic is not in the router plugin to avoid having to include some dependencies in the utils package
|
198
|
-
async modifyEntryImports({ entrypoint, imports }) {
|
199
|
-
const appContext = api.useAppContext();
|
200
|
-
const { srcDirectory, internalSrcAlias } = appContext;
|
201
|
-
const { fileSystemRoutes, nestedRoutesEntry } = entrypoint;
|
202
|
-
if (fileSystemRoutes && nestedRoutesEntry) {
|
203
|
-
const rootLayoutPath = path.join(nestedRoutesEntry, "layout");
|
204
|
-
const rootLayoutFile = (0, import_utils.findExists)([
|
205
|
-
".js",
|
206
|
-
".ts",
|
207
|
-
".jsx",
|
208
|
-
".tsx"
|
209
|
-
].map((ext) => `${rootLayoutPath}${ext}`));
|
210
|
-
if (rootLayoutFile) {
|
211
|
-
const rootLayoutBuffer = await import_utils.fs.readFile(rootLayoutFile);
|
212
|
-
const rootLayout = rootLayoutBuffer.toString();
|
213
|
-
const [, moduleExports] = await (0, import_utils2.parseModule)({
|
214
|
-
source: rootLayout.toString(),
|
215
|
-
filename: rootLayoutFile
|
216
|
-
});
|
217
|
-
const hasAppConfig = moduleExports.some((e) => e.n === import_constants.APP_CONFIG_NAME);
|
218
|
-
const generateLayoutPath = (0, import_routes.getPathWithoutExt)((0, import_utils2.replaceWithAlias)(srcDirectory, rootLayoutFile, internalSrcAlias));
|
219
|
-
if (hasAppConfig) {
|
220
|
-
imports.push({
|
221
|
-
value: generateLayoutPath,
|
222
|
-
specifiers: [
|
223
|
-
{
|
224
|
-
imported: import_constants.APP_CONFIG_NAME
|
225
|
-
}
|
226
|
-
]
|
227
|
-
});
|
228
|
-
}
|
229
|
-
const hasAppInit = moduleExports.some((e) => e.n === import_constants.APP_INIT_EXPORTED);
|
230
|
-
if (hasAppInit) {
|
231
|
-
imports.push({
|
232
|
-
value: generateLayoutPath,
|
233
|
-
specifiers: [
|
234
|
-
{
|
235
|
-
imported: import_constants.APP_INIT_EXPORTED,
|
236
|
-
local: import_constants.APP_INIT_IMPORTED
|
237
|
-
}
|
238
|
-
]
|
239
|
-
});
|
240
|
-
}
|
241
|
-
}
|
242
|
-
}
|
243
|
-
return {
|
244
|
-
entrypoint,
|
245
|
-
imports
|
246
|
-
};
|
247
190
|
}
|
248
191
|
};
|
249
192
|
}
|
@@ -18,60 +18,9 @@ var __copyProps = (to, from, except, desc) => {
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
19
|
var templates_exports = {};
|
20
20
|
__export(templates_exports, {
|
21
|
-
html: () => html
|
22
|
-
index: () => index,
|
23
|
-
renderFunction: () => renderFunction
|
21
|
+
html: () => html
|
24
22
|
});
|
25
23
|
module.exports = __toCommonJS(templates_exports);
|
26
|
-
var import_constants = require("./constants");
|
27
|
-
const index = ({ mountId, imports, renderFunction: renderFunction2, exportStatement }) => `
|
28
|
-
const IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';
|
29
|
-
const IS_REACT18 = process.env.IS_REACT18 === 'true';
|
30
|
-
const MOUNT_ID = '${mountId}';
|
31
|
-
|
32
|
-
${imports}
|
33
|
-
|
34
|
-
let AppWrapper = null;
|
35
|
-
|
36
|
-
let root = null;
|
37
|
-
|
38
|
-
function render() {
|
39
|
-
${renderFunction2}
|
40
|
-
}
|
41
|
-
|
42
|
-
AppWrapper = render();
|
43
|
-
|
44
|
-
${exportStatement};
|
45
|
-
`;
|
46
|
-
const renderFunction = ({ plugins, customBootstrap, fileSystemRoutes, customRuntimeConfig }) => {
|
47
|
-
const bootstrap = "bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM)";
|
48
|
-
const runtimePlugins = `...(runtimeConfig?.plugins || []),`;
|
49
|
-
return `
|
50
|
-
const finalAppConfig = {
|
51
|
-
...App.config,
|
52
|
-
...typeof ${import_constants.APP_CONFIG_NAME} === 'function' ? ${import_constants.APP_CONFIG_NAME}() : {},
|
53
|
-
}
|
54
|
-
|
55
|
-
AppWrapper = createApp({
|
56
|
-
plugins: [
|
57
|
-
${plugins.map(({ name, options, args }) => `${name}({...${options}, ...finalAppConfig?.${args || name}}),`).join("\n")}
|
58
|
-
${customRuntimeConfig ? runtimePlugins : ""}
|
59
|
-
]
|
60
|
-
})(${fileSystemRoutes ? "" : `App`})
|
61
|
-
|
62
|
-
|
63
|
-
if(!AppWrapper.init && typeof appInit !== 'undefined') {
|
64
|
-
AppWrapper.init = appInit;
|
65
|
-
}
|
66
|
-
|
67
|
-
|
68
|
-
if (IS_BROWSER) {
|
69
|
-
${customBootstrap ? `customBootstrap(AppWrapper, () => ${bootstrap});` : `${bootstrap};`}
|
70
|
-
}
|
71
|
-
|
72
|
-
return AppWrapper
|
73
|
-
`;
|
74
|
-
};
|
75
24
|
const html = (partials) => `
|
76
25
|
<!DOCTYPE html>
|
77
26
|
<html>
|
@@ -95,7 +44,5 @@ const html = (partials) => `
|
|
95
44
|
`;
|
96
45
|
// Annotate the CommonJS export names for ESM import in node:
|
97
46
|
0 && (module.exports = {
|
98
|
-
html
|
99
|
-
index,
|
100
|
-
renderFunction
|
47
|
+
html
|
101
48
|
});
|
@@ -29,7 +29,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
29
29
|
var utils_exports = {};
|
30
30
|
__export(utils_exports, {
|
31
31
|
checkIsBuildCommands: () => checkIsBuildCommands,
|
32
|
-
getDefaultImports: () => getDefaultImports,
|
33
32
|
getServerCombinedModueFile: () => getServerCombinedModueFile,
|
34
33
|
isSubDirOrEqual: () => isSubDirOrEqual,
|
35
34
|
parseModule: () => parseModule,
|
@@ -42,7 +41,6 @@ var import_path = __toESM(require("path"));
|
|
42
41
|
var import_utils = require("@modern-js/utils");
|
43
42
|
var import_esbuild = require("esbuild");
|
44
43
|
var import_es_module_lexer = require("es-module-lexer");
|
45
|
-
var import_constants = require("./constants");
|
46
44
|
const walkDirectory = (dir) => import_fs.default.readdirSync(dir).reduce((previous, filename) => {
|
47
45
|
const filePath = import_path.default.join(dir, filename);
|
48
46
|
if (import_fs.default.statSync(filePath).isDirectory()) {
|
@@ -57,89 +55,6 @@ const walkDirectory = (dir) => import_fs.default.readdirSync(dir).reduce((previo
|
|
57
55
|
];
|
58
56
|
}
|
59
57
|
}, []);
|
60
|
-
const getDefaultImports = ({ entrypoint, srcDirectory, appDirectory, internalSrcAlias, internalDirAlias, runtimeConfigFile, customRuntimeConfig }) => {
|
61
|
-
const { entryName, fileSystemRoutes, customBootstrap, entry } = entrypoint;
|
62
|
-
const imports = [
|
63
|
-
{
|
64
|
-
specifiers: [
|
65
|
-
{
|
66
|
-
local: "React"
|
67
|
-
}
|
68
|
-
],
|
69
|
-
value: "react"
|
70
|
-
},
|
71
|
-
{
|
72
|
-
specifiers: [
|
73
|
-
{
|
74
|
-
local: "ReactDOM"
|
75
|
-
}
|
76
|
-
],
|
77
|
-
value: (0, import_utils.isReact18)(import_path.default.join(appDirectory)) ? "react-dom/client" : "react-dom"
|
78
|
-
},
|
79
|
-
{
|
80
|
-
specifiers: [
|
81
|
-
{
|
82
|
-
imported: "createApp"
|
83
|
-
},
|
84
|
-
{
|
85
|
-
imported: "bootstrap"
|
86
|
-
}
|
87
|
-
],
|
88
|
-
value: "@modern-js/runtime"
|
89
|
-
},
|
90
|
-
customBootstrap && {
|
91
|
-
specifiers: [
|
92
|
-
{
|
93
|
-
local: "customBootstrap"
|
94
|
-
}
|
95
|
-
],
|
96
|
-
value: (0, import_utils.normalizeToPosixPath)(customBootstrap.replace(srcDirectory, internalSrcAlias))
|
97
|
-
}
|
98
|
-
].filter(Boolean);
|
99
|
-
if (fileSystemRoutes) {
|
100
|
-
const route = {
|
101
|
-
specifiers: [
|
102
|
-
{
|
103
|
-
imported: "routes"
|
104
|
-
}
|
105
|
-
],
|
106
|
-
value: (0, import_utils.normalizeToPosixPath)(`${internalDirAlias}/${entryName}/${import_constants.FILE_SYSTEM_ROUTES_FILE_NAME.replace(".js", "")}`)
|
107
|
-
};
|
108
|
-
if (fileSystemRoutes.globalApp) {
|
109
|
-
imports.push({
|
110
|
-
specifiers: [
|
111
|
-
{
|
112
|
-
local: "App"
|
113
|
-
}
|
114
|
-
],
|
115
|
-
value: (0, import_utils.normalizeToPosixPath)(fileSystemRoutes.globalApp.replace(srcDirectory, internalSrcAlias))
|
116
|
-
});
|
117
|
-
} else {
|
118
|
-
route.initialize = "const App = false;";
|
119
|
-
}
|
120
|
-
imports.push(route);
|
121
|
-
} else {
|
122
|
-
imports.push({
|
123
|
-
specifiers: [
|
124
|
-
{
|
125
|
-
local: "App"
|
126
|
-
}
|
127
|
-
],
|
128
|
-
value: (0, import_utils.normalizeToPosixPath)(entry.replace(srcDirectory, internalSrcAlias))
|
129
|
-
});
|
130
|
-
}
|
131
|
-
if (customRuntimeConfig) {
|
132
|
-
imports.push({
|
133
|
-
specifiers: [
|
134
|
-
{
|
135
|
-
local: "runtimeConfig"
|
136
|
-
}
|
137
|
-
],
|
138
|
-
value: import_path.default.join(internalSrcAlias, runtimeConfigFile || "")
|
139
|
-
});
|
140
|
-
}
|
141
|
-
return imports;
|
142
|
-
};
|
143
58
|
const replaceWithAlias = (base, filePath, alias) => {
|
144
59
|
if (filePath.includes(base)) {
|
145
60
|
return (0, import_utils.normalizeToPosixPath)(import_path.default.join(alias, import_path.default.relative(base, filePath)));
|
@@ -184,7 +99,6 @@ const isSubDirOrEqual = (parent, child) => {
|
|
184
99
|
// Annotate the CommonJS export names for ESM import in node:
|
185
100
|
0 && (module.exports = {
|
186
101
|
checkIsBuildCommands,
|
187
|
-
getDefaultImports,
|
188
102
|
getServerCombinedModueFile,
|
189
103
|
isSubDirOrEqual,
|
190
104
|
parseModule,
|
@@ -31,11 +31,31 @@ function createBuilderOptions(target, appContext) {
|
|
31
31
|
}
|
32
32
|
}
|
33
33
|
}
|
34
|
+
var serverEntries = {};
|
35
|
+
for (var entry1 in entries) {
|
36
|
+
var v = entries[entry1];
|
37
|
+
serverEntries[entry1] = v.map(function(entry2) {
|
38
|
+
return entry2.replace("index.jsx", "index.server.jsx");
|
39
|
+
});
|
40
|
+
}
|
34
41
|
return {
|
35
42
|
cwd: appContext.appDirectory,
|
36
43
|
target,
|
37
44
|
frameworkConfigPath: appContext.configFile || void 0,
|
38
|
-
entry:
|
45
|
+
entry: function entry2(param) {
|
46
|
+
var _$target = param.target;
|
47
|
+
if (_$target === "web") {
|
48
|
+
return entries;
|
49
|
+
}
|
50
|
+
if ([
|
51
|
+
"node",
|
52
|
+
"web-worker",
|
53
|
+
"service-worker"
|
54
|
+
].includes(_$target)) {
|
55
|
+
return serverEntries;
|
56
|
+
}
|
57
|
+
return entries;
|
58
|
+
}
|
39
59
|
};
|
40
60
|
}
|
41
61
|
export {
|
@@ -2,7 +2,7 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
3
3
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
5
|
-
import { isHtmlDisabled } from "@
|
5
|
+
import { isHtmlDisabled } from "@modern-js/uni-builder";
|
6
6
|
import { MAIN_ENTRY_NAME, getEntryOptions, removeTailSlash } from "@modern-js/utils";
|
7
7
|
import { template as lodashTemplate } from "@modern-js/utils/lodash";
|
8
8
|
import { BottomTemplatePlugin } from "../bundlerPlugins";
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
3
3
|
import * as path from "path";
|
4
|
-
import { isHtmlDisabled } from "@rsbuild/shared";
|
5
4
|
import { mergeRsbuildConfig } from "@rsbuild/core";
|
6
5
|
import { fs, isUseSSRBundle } from "@modern-js/utils";
|
6
|
+
import { isHtmlDisabled } from "@modern-js/uni-builder";
|
7
7
|
import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
|
8
8
|
import { getServerCombinedModueFile } from "../../../plugins/analyze/utils";
|
9
9
|
var builderPluginAdapterSSR = function(options) {
|
@@ -3,7 +3,7 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
3
3
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
5
5
|
import { newAction, upgradeAction } from "@modern-js/utils";
|
6
|
-
import { castArray } from "@
|
6
|
+
import { castArray } from "@modern-js/uni-builder";
|
7
7
|
import { i18n, localeKeys } from "../locale";
|
8
8
|
var devCommand = function() {
|
9
9
|
var _ref = _async_to_generator(function(program, api) {
|
@@ -42,6 +42,7 @@ var start = function() {
|
|
42
42
|
pwd: distDirectory,
|
43
43
|
config: _object_spread_props(_object_spread({}, userConfig), {
|
44
44
|
dev: userConfig.dev,
|
45
|
+
// server-core can't get RegExp & Function output.enableInlineScripts by JSON.stringy;
|
45
46
|
output: _object_spread({
|
46
47
|
path: (_userConfig_output_distPath = userConfig.output.distPath) === null || _userConfig_output_distPath === void 0 ? void 0 : _userConfig_output_distPath.root
|
47
48
|
}, userConfig.output || {})
|