@modern-js/app-tools 2.54.5 → 2.55.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -31,6 +31,7 @@ function createDefaultConfig(appContext) {
|
|
31
31
|
entries: void 0,
|
32
32
|
mainEntryName: MAIN_ENTRY_NAME,
|
33
33
|
enableAsyncEntry: false,
|
34
|
+
enableCustomEntry: false,
|
34
35
|
disableDefaultEntries: false,
|
35
36
|
entriesDir: "./src",
|
36
37
|
configDir: "./config",
|
@@ -94,6 +95,7 @@ function createLegacyDefaultConfig(appContext) {
|
|
94
95
|
entries: void 0,
|
95
96
|
mainEntryName: MAIN_ENTRY_NAME,
|
96
97
|
enableAsyncEntry: false,
|
98
|
+
enableCustomEntry: false,
|
97
99
|
disableDefaultEntries: false,
|
98
100
|
entriesDir: "./src",
|
99
101
|
configDir: "./config",
|
@@ -1,5 +1,5 @@
|
|
1
1
|
function createSourceConfig(config) {
|
2
|
-
var _config_source = config.source, alias = _config_source.alias, envVars = _config_source.envVars, globalVars = _config_source.globalVars, include = _config_source.include, moduleScopes = _config_source.moduleScopes, preEntry = _config_source.preEntry, entries = _config_source.entries, mainEntryName = _config_source.mainEntryName, enableAsyncEntry = _config_source.enableAsyncEntry, disableDefaultEntries = _config_source.disableDefaultEntries, entriesDir = _config_source.entriesDir, configDir = _config_source.configDir;
|
2
|
+
var _config_source = config.source, alias = _config_source.alias, envVars = _config_source.envVars, globalVars = _config_source.globalVars, include = _config_source.include, moduleScopes = _config_source.moduleScopes, preEntry = _config_source.preEntry, entries = _config_source.entries, mainEntryName = _config_source.mainEntryName, enableAsyncEntry = _config_source.enableAsyncEntry, enableCustomEntry = _config_source.enableCustomEntry, disableDefaultEntries = _config_source.disableDefaultEntries, entriesDir = _config_source.entriesDir, configDir = _config_source.configDir;
|
3
3
|
var builderGlobalVars = globalVars || {};
|
4
4
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
5
5
|
try {
|
@@ -31,6 +31,7 @@ function createSourceConfig(config) {
|
|
31
31
|
entries,
|
32
32
|
mainEntryName,
|
33
33
|
enableAsyncEntry,
|
34
|
+
enableCustomEntry,
|
34
35
|
disableDefaultEntries,
|
35
36
|
entriesDir,
|
36
37
|
configDir,
|
package/dist/esm/hooks.js
CHANGED
@@ -1,16 +1,13 @@
|
|
1
1
|
import { createAsyncWaterfall, createAsyncWorkflow, createParallelWorkflow } from "@modern-js/plugin";
|
2
2
|
var hooks = {
|
3
|
-
|
4
|
-
modifyEntryImports: createAsyncWaterfall(),
|
5
|
-
modifyEntryRuntimePlugins: createAsyncWaterfall(),
|
6
|
-
modifyEntryRenderFunction: createAsyncWaterfall(),
|
7
|
-
modifyAsyncEntry: createAsyncWaterfall(),
|
3
|
+
_internalRuntimePlugins: createAsyncWaterfall(),
|
8
4
|
modifyFileSystemRoutes: createAsyncWaterfall(),
|
9
5
|
modifyServerRoutes: createAsyncWaterfall(),
|
10
6
|
/** add entry point info to entrypoints array */
|
11
7
|
modifyEntrypoints: createAsyncWaterfall(),
|
12
8
|
/** add entry type */
|
13
9
|
checkEntryPoint: createAsyncWaterfall(),
|
10
|
+
generateEntryCode: createAsyncWorkflow(),
|
14
11
|
htmlPartials: createAsyncWaterfall(),
|
15
12
|
beforeGenerateRoutes: createAsyncWaterfall(),
|
16
13
|
addDefineTypes: createAsyncWaterfall(),
|
@@ -1,23 +1,13 @@
|
|
1
1
|
var INDEX_FILE_NAME = "index";
|
2
|
-
var
|
3
|
-
var ENTRY_POINT_FILE_NAME = "index.jsx";
|
4
|
-
var ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.jsx";
|
2
|
+
var ENTRY_FILE_NAME = "entry";
|
5
3
|
var HTML_PARTIALS_FOLDER = "html";
|
6
4
|
var HTML_PARTIALS_EXTENSIONS = [
|
7
5
|
".htm",
|
8
6
|
".html",
|
9
7
|
".ejs"
|
10
8
|
];
|
11
|
-
var APP_CONFIG_NAME = "config";
|
12
|
-
var APP_INIT_EXPORTED = "init";
|
13
|
-
var APP_INIT_IMPORTED = "appInit";
|
14
9
|
export {
|
15
|
-
|
16
|
-
APP_INIT_EXPORTED,
|
17
|
-
APP_INIT_IMPORTED,
|
18
|
-
ENTRY_BOOTSTRAP_FILE_NAME,
|
19
|
-
ENTRY_POINT_FILE_NAME,
|
20
|
-
FILE_SYSTEM_ROUTES_FILE_NAME,
|
10
|
+
ENTRY_FILE_NAME,
|
21
11
|
HTML_PARTIALS_EXTENSIONS,
|
22
12
|
HTML_PARTIALS_FOLDER,
|
23
13
|
INDEX_FILE_NAME
|
@@ -3,15 +3,26 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
3
3
|
import fs from "fs";
|
4
4
|
import path from "path";
|
5
5
|
import { findExists, ensureAbsolutePath, JS_EXTENSIONS } from "@modern-js/utils";
|
6
|
-
import { INDEX_FILE_NAME } from "./constants";
|
6
|
+
import { ENTRY_FILE_NAME, INDEX_FILE_NAME } from "./constants";
|
7
7
|
import { isDefaultExportFunction } from "./isDefaultExportFunction";
|
8
8
|
var hasIndex = function(dir) {
|
9
9
|
return findExists(JS_EXTENSIONS.map(function(ext) {
|
10
10
|
return path.resolve(dir, "".concat(INDEX_FILE_NAME).concat(ext));
|
11
11
|
}));
|
12
12
|
};
|
13
|
+
var hasEntry = function(dir) {
|
14
|
+
return findExists(JS_EXTENSIONS.map(function(ext) {
|
15
|
+
return path.resolve(dir, "".concat(ENTRY_FILE_NAME).concat(ext));
|
16
|
+
}));
|
17
|
+
};
|
18
|
+
var hasServerEntry = function(dir) {
|
19
|
+
return findExists(JS_EXTENSIONS.map(function(ext) {
|
20
|
+
return path.resolve(dir, "".concat(ENTRY_FILE_NAME, ".server").concat(ext));
|
21
|
+
}));
|
22
|
+
};
|
13
23
|
var isBundleEntry = function() {
|
14
|
-
var _ref = _async_to_generator(function(hookRunners, dir) {
|
24
|
+
var _ref = _async_to_generator(function(hookRunners, dir, enableCustomEntry) {
|
25
|
+
var entry, customEntry;
|
15
26
|
return _ts_generator(this, function(_state) {
|
16
27
|
switch (_state.label) {
|
17
28
|
case 0:
|
@@ -23,27 +34,43 @@ var isBundleEntry = function() {
|
|
23
34
|
})
|
24
35
|
];
|
25
36
|
case 1:
|
37
|
+
entry = _state.sent().entry;
|
38
|
+
if (entry) {
|
39
|
+
return [
|
40
|
+
2,
|
41
|
+
entry
|
42
|
+
];
|
43
|
+
}
|
44
|
+
customEntry = hasEntry(dir);
|
45
|
+
if (enableCustomEntry && customEntry) {
|
46
|
+
return [
|
47
|
+
2,
|
48
|
+
customEntry
|
49
|
+
];
|
50
|
+
}
|
26
51
|
return [
|
27
52
|
2,
|
28
|
-
|
53
|
+
hasIndex(dir)
|
29
54
|
];
|
30
55
|
}
|
31
56
|
});
|
32
57
|
});
|
33
|
-
return function isBundleEntry2(hookRunners, dir) {
|
58
|
+
return function isBundleEntry2(hookRunners, dir, enableCustomEntry) {
|
34
59
|
return _ref.apply(this, arguments);
|
35
60
|
};
|
36
61
|
}();
|
37
|
-
var scanDir = function(hookRunners, dirs) {
|
62
|
+
var scanDir = function(hookRunners, dirs, enableCustomEntry) {
|
38
63
|
return Promise.all(dirs.map(function() {
|
39
64
|
var _ref = _async_to_generator(function(dir) {
|
40
|
-
var indexFile, customBootstrap, entryName, entryFile;
|
65
|
+
var indexFile, customBootstrap, entryName, customEntryFile, customServerEntry, entryFile;
|
41
66
|
return _ts_generator(this, function(_state) {
|
42
67
|
switch (_state.label) {
|
43
68
|
case 0:
|
44
69
|
indexFile = hasIndex(dir);
|
45
70
|
customBootstrap = isDefaultExportFunction(indexFile) ? indexFile : false;
|
46
71
|
entryName = path.basename(dir);
|
72
|
+
customEntryFile = hasEntry(dir);
|
73
|
+
customServerEntry = hasServerEntry(dir);
|
47
74
|
if (indexFile && !customBootstrap) {
|
48
75
|
return [
|
49
76
|
2,
|
@@ -72,10 +99,26 @@ var scanDir = function(hookRunners, dirs) {
|
|
72
99
|
{
|
73
100
|
entryName,
|
74
101
|
isMainEntry: false,
|
75
|
-
entry: entryFile,
|
102
|
+
entry: enableCustomEntry ? customEntryFile || entryFile : entryFile,
|
103
|
+
customServerEntry,
|
76
104
|
absoluteEntryDir: path.resolve(dir),
|
77
105
|
isAutoMount: true,
|
78
|
-
customBootstrap
|
106
|
+
customBootstrap,
|
107
|
+
customEntry: enableCustomEntry ? Boolean(customEntryFile) : false
|
108
|
+
}
|
109
|
+
];
|
110
|
+
}
|
111
|
+
if (enableCustomEntry && customEntryFile) {
|
112
|
+
return [
|
113
|
+
2,
|
114
|
+
{
|
115
|
+
entryName,
|
116
|
+
isMainEntry: false,
|
117
|
+
entry: customEntryFile,
|
118
|
+
customServerEntry,
|
119
|
+
absoluteEntryDir: path.resolve(dir),
|
120
|
+
isAutoMount: false,
|
121
|
+
customEntry: Boolean(customEntryFile)
|
79
122
|
}
|
80
123
|
];
|
81
124
|
}
|
@@ -90,12 +133,12 @@ var scanDir = function(hookRunners, dirs) {
|
|
90
133
|
};
|
91
134
|
var getFileSystemEntry = function() {
|
92
135
|
var _ref = _async_to_generator(function(hookRunners, appContext, config) {
|
93
|
-
var appDirectory, _config_source, entriesDir, disableEntryDirs, disabledDirs, src, dirs;
|
136
|
+
var appDirectory, _config_source, entriesDir, disableEntryDirs, enableCustomEntry, disabledDirs, src, dirs;
|
94
137
|
return _ts_generator(this, function(_state) {
|
95
138
|
switch (_state.label) {
|
96
139
|
case 0:
|
97
140
|
appDirectory = appContext.appDirectory;
|
98
|
-
_config_source = config.source, entriesDir = _config_source.entriesDir, disableEntryDirs = _config_source.disableEntryDirs;
|
141
|
+
_config_source = config.source, entriesDir = _config_source.entriesDir, disableEntryDirs = _config_source.disableEntryDirs, enableCustomEntry = _config_source.enableCustomEntry;
|
99
142
|
disabledDirs = [];
|
100
143
|
if (disableEntryDirs && Array.isArray(disableEntryDirs)) {
|
101
144
|
disabledDirs = disableEntryDirs === null || disableEntryDirs === void 0 ? void 0 : disableEntryDirs.map(function(dir) {
|
@@ -115,7 +158,7 @@ var getFileSystemEntry = function() {
|
|
115
158
|
];
|
116
159
|
return [
|
117
160
|
4,
|
118
|
-
isBundleEntry(hookRunners, src)
|
161
|
+
isBundleEntry(hookRunners, src, enableCustomEntry)
|
119
162
|
];
|
120
163
|
case 1:
|
121
164
|
if (_state.sent()) {
|
@@ -123,7 +166,7 @@ var getFileSystemEntry = function() {
|
|
123
166
|
2,
|
124
167
|
scanDir(hookRunners, [
|
125
168
|
src
|
126
|
-
])
|
169
|
+
], enableCustomEntry)
|
127
170
|
];
|
128
171
|
}
|
129
172
|
dirs = [];
|
@@ -144,7 +187,7 @@ var getFileSystemEntry = function() {
|
|
144
187
|
];
|
145
188
|
return [
|
146
189
|
4,
|
147
|
-
isBundleEntry(hookRunners, file)
|
190
|
+
isBundleEntry(hookRunners, file, enableCustomEntry)
|
148
191
|
];
|
149
192
|
case 1:
|
150
193
|
_tmp = _state2.sent();
|
@@ -168,7 +211,7 @@ var getFileSystemEntry = function() {
|
|
168
211
|
_state.sent();
|
169
212
|
return [
|
170
213
|
2,
|
171
|
-
scanDir(hookRunners, dirs)
|
214
|
+
scanDir(hookRunners, dirs, enableCustomEntry)
|
172
215
|
];
|
173
216
|
case 3:
|
174
217
|
throw Error("source.entriesDir accept a directory.");
|
@@ -4,28 +4,29 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
4
4
|
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
5
5
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
6
6
|
import * as path from "path";
|
7
|
-
import { createDebugger,
|
7
|
+
import { createDebugger, fs, isApiOnly, minimist, isDevCommand, getArgv } from "@modern-js/utils";
|
8
8
|
import { printInstructions } from "../../utils/printInstructions";
|
9
|
-
import { generateRoutes
|
9
|
+
import { generateRoutes } from "../../utils/routes";
|
10
10
|
import { emitResolvedConfig } from "../../utils/config";
|
11
11
|
import { getSelectedEntries } from "../../utils/getSelectedEntries";
|
12
12
|
import { initialNormalizedConfig } from "../../config";
|
13
13
|
import { createBuilderGenerator } from "../../builder";
|
14
|
-
import { checkIsBuildCommands
|
15
|
-
import { APP_CONFIG_NAME, APP_INIT_EXPORTED, APP_INIT_IMPORTED } from "./constants";
|
16
|
-
import { generateIndexCode } from "./generateCode";
|
14
|
+
import { checkIsBuildCommands } from "./utils";
|
17
15
|
var debug = createDebugger("plugin-analyze");
|
18
16
|
function analyze_default(param) {
|
19
17
|
var bundler = param.bundler;
|
20
18
|
return {
|
21
19
|
name: "@modern-js/plugin-analyze",
|
20
|
+
post: [
|
21
|
+
"@modern-js/runtime"
|
22
|
+
],
|
22
23
|
setup: function(api) {
|
23
24
|
var pagesDir = [];
|
24
25
|
var nestedRouteEntries = [];
|
25
26
|
return {
|
26
27
|
prepare: function prepare() {
|
27
28
|
return _async_to_generator(function() {
|
28
|
-
var _resolvedConfig_source, appContext, resolvedConfig, hookRunners, apiOnly, routes, _ref, getBundleEntry, getServerRoutes,
|
29
|
+
var _resolvedConfig_source, appContext, resolvedConfig, hookRunners, apiOnly, routes, _ref, getBundleEntry, getServerRoutes, getHtmlTemplate, entrypoints, _, _tmp, initialRoutes, routes1, htmlTemplates, checkedEntries, entry, normalizedConfig, createBuilderForModern, builder;
|
29
30
|
return _ts_generator(this, function(_state) {
|
30
31
|
switch (_state.label) {
|
31
32
|
case 0:
|
@@ -78,15 +79,14 @@ function analyze_default(param) {
|
|
78
79
|
Promise.all([
|
79
80
|
import("./getBundleEntry"),
|
80
81
|
import("./getServerRoutes"),
|
81
|
-
import("./generateCode"),
|
82
82
|
import("./getHtmlTemplate")
|
83
83
|
])
|
84
84
|
];
|
85
85
|
case 5:
|
86
86
|
_ref = _sliced_to_array.apply(void 0, [
|
87
87
|
_state.sent(),
|
88
|
-
|
89
|
-
]), getBundleEntry = _ref[0].getBundleEntry, getServerRoutes = _ref[1].getServerRoutes,
|
88
|
+
3
|
89
|
+
]), getBundleEntry = _ref[0].getBundleEntry, getServerRoutes = _ref[1].getServerRoutes, getHtmlTemplate = _ref[2].getHtmlTemplate;
|
90
90
|
_ = hookRunners.modifyEntrypoints;
|
91
91
|
_tmp = {};
|
92
92
|
return [
|
@@ -129,12 +129,6 @@ function analyze_default(param) {
|
|
129
129
|
}).filter(function(entry2) {
|
130
130
|
return entry2 && !path.extname(entry2);
|
131
131
|
}).concat(nestedRouteEntries);
|
132
|
-
return [
|
133
|
-
4,
|
134
|
-
generateCode(appContext, resolvedConfig, entrypoints, api)
|
135
|
-
];
|
136
|
-
case 9:
|
137
|
-
importsStatemets = _state.sent().importsStatemets;
|
138
132
|
return [
|
139
133
|
4,
|
140
134
|
getHtmlTemplate(entrypoints, api, {
|
@@ -142,14 +136,14 @@ function analyze_default(param) {
|
|
142
136
|
config: resolvedConfig
|
143
137
|
})
|
144
138
|
];
|
145
|
-
case
|
139
|
+
case 9:
|
146
140
|
htmlTemplates = _state.sent();
|
147
141
|
debug("html templates: %o", htmlTemplates);
|
148
142
|
return [
|
149
143
|
4,
|
150
144
|
hookRunners.addDefineTypes()
|
151
145
|
];
|
152
|
-
case
|
146
|
+
case 10:
|
153
147
|
_state.sent();
|
154
148
|
debug("add Define Types");
|
155
149
|
checkedEntries = entrypoints.map(function(point) {
|
@@ -158,17 +152,17 @@ function analyze_default(param) {
|
|
158
152
|
if (!isDevCommand())
|
159
153
|
return [
|
160
154
|
3,
|
161
|
-
|
155
|
+
12
|
162
156
|
];
|
163
157
|
entry = minimist(getArgv()).entry;
|
164
158
|
return [
|
165
159
|
4,
|
166
160
|
getSelectedEntries(typeof entry === "string" ? entry.split(",") : entry, entrypoints)
|
167
161
|
];
|
168
|
-
case
|
162
|
+
case 11:
|
169
163
|
checkedEntries = _state.sent();
|
170
|
-
_state.label =
|
171
|
-
case
|
164
|
+
_state.label = 12;
|
165
|
+
case 12:
|
172
166
|
appContext = _object_spread_props(_object_spread({}, api.useAppContext()), {
|
173
167
|
entrypoints,
|
174
168
|
checkedEntries,
|
@@ -182,6 +176,14 @@ function analyze_default(param) {
|
|
182
176
|
3,
|
183
177
|
16
|
184
178
|
];
|
179
|
+
return [
|
180
|
+
4,
|
181
|
+
hookRunners.generateEntryCode({
|
182
|
+
entrypoints
|
183
|
+
})
|
184
|
+
];
|
185
|
+
case 13:
|
186
|
+
_state.sent();
|
185
187
|
normalizedConfig = api.useResolvedConfigContext();
|
186
188
|
return [
|
187
189
|
4,
|
@@ -291,26 +293,13 @@ function analyze_default(param) {
|
|
291
293
|
case 0:
|
292
294
|
bundlerConfigs = param2.bundlerConfigs;
|
293
295
|
hookRunners2 = api.useHookRunners();
|
294
|
-
return [
|
295
|
-
4,
|
296
|
-
generateIndexCode({
|
297
|
-
appContext,
|
298
|
-
config: resolvedConfig,
|
299
|
-
entrypoints,
|
300
|
-
api,
|
301
|
-
importsStatemets,
|
302
|
-
bundlerConfigs
|
303
|
-
})
|
304
|
-
];
|
305
|
-
case 1:
|
306
|
-
_state2.sent();
|
307
296
|
return [
|
308
297
|
4,
|
309
298
|
hookRunners2.beforeCreateCompiler({
|
310
299
|
bundlerConfigs
|
311
300
|
})
|
312
301
|
];
|
313
|
-
case
|
302
|
+
case 1:
|
314
303
|
_state2.sent();
|
315
304
|
return [
|
316
305
|
2
|
@@ -375,99 +364,7 @@ function analyze_default(param) {
|
|
375
364
|
return {
|
376
365
|
resolved: config
|
377
366
|
};
|
378
|
-
}
|
379
|
-
modifyEntryImports: (
|
380
|
-
// This logic is not in the router plugin to avoid having to include some dependencies in the utils package
|
381
|
-
function modifyEntryImports(param2) {
|
382
|
-
var entrypoint = param2.entrypoint, imports = param2.imports;
|
383
|
-
return _async_to_generator(function() {
|
384
|
-
var appContext, srcDirectory, internalSrcAlias, fileSystemRoutes, nestedRoutesEntry, rootLayoutPath, rootLayoutFile, rootLayoutBuffer, rootLayout, _ref, moduleExports, hasAppConfig, generateLayoutPath, hasAppInit;
|
385
|
-
return _ts_generator(this, function(_state) {
|
386
|
-
switch (_state.label) {
|
387
|
-
case 0:
|
388
|
-
appContext = api.useAppContext();
|
389
|
-
srcDirectory = appContext.srcDirectory, internalSrcAlias = appContext.internalSrcAlias;
|
390
|
-
fileSystemRoutes = entrypoint.fileSystemRoutes, nestedRoutesEntry = entrypoint.nestedRoutesEntry;
|
391
|
-
if (!(fileSystemRoutes && nestedRoutesEntry))
|
392
|
-
return [
|
393
|
-
3,
|
394
|
-
3
|
395
|
-
];
|
396
|
-
rootLayoutPath = path.join(nestedRoutesEntry, "layout");
|
397
|
-
rootLayoutFile = findExists([
|
398
|
-
".js",
|
399
|
-
".ts",
|
400
|
-
".jsx",
|
401
|
-
".tsx"
|
402
|
-
].map(function(ext) {
|
403
|
-
return "".concat(rootLayoutPath).concat(ext);
|
404
|
-
}));
|
405
|
-
if (!rootLayoutFile)
|
406
|
-
return [
|
407
|
-
3,
|
408
|
-
3
|
409
|
-
];
|
410
|
-
return [
|
411
|
-
4,
|
412
|
-
fs.readFile(rootLayoutFile)
|
413
|
-
];
|
414
|
-
case 1:
|
415
|
-
rootLayoutBuffer = _state.sent();
|
416
|
-
rootLayout = rootLayoutBuffer.toString();
|
417
|
-
return [
|
418
|
-
4,
|
419
|
-
parseModule({
|
420
|
-
source: rootLayout.toString(),
|
421
|
-
filename: rootLayoutFile
|
422
|
-
})
|
423
|
-
];
|
424
|
-
case 2:
|
425
|
-
_ref = _sliced_to_array.apply(void 0, [
|
426
|
-
_state.sent(),
|
427
|
-
2
|
428
|
-
]), moduleExports = _ref[1];
|
429
|
-
hasAppConfig = moduleExports.some(function(e) {
|
430
|
-
return e.n === APP_CONFIG_NAME;
|
431
|
-
});
|
432
|
-
generateLayoutPath = getPathWithoutExt(replaceWithAlias(srcDirectory, rootLayoutFile, internalSrcAlias));
|
433
|
-
if (hasAppConfig) {
|
434
|
-
imports.push({
|
435
|
-
value: generateLayoutPath,
|
436
|
-
specifiers: [
|
437
|
-
{
|
438
|
-
imported: APP_CONFIG_NAME
|
439
|
-
}
|
440
|
-
]
|
441
|
-
});
|
442
|
-
}
|
443
|
-
hasAppInit = moduleExports.some(function(e) {
|
444
|
-
return e.n === APP_INIT_EXPORTED;
|
445
|
-
});
|
446
|
-
if (hasAppInit) {
|
447
|
-
imports.push({
|
448
|
-
value: generateLayoutPath,
|
449
|
-
specifiers: [
|
450
|
-
{
|
451
|
-
imported: APP_INIT_EXPORTED,
|
452
|
-
local: APP_INIT_IMPORTED
|
453
|
-
}
|
454
|
-
]
|
455
|
-
});
|
456
|
-
}
|
457
|
-
_state.label = 3;
|
458
|
-
case 3:
|
459
|
-
return [
|
460
|
-
2,
|
461
|
-
{
|
462
|
-
entrypoint,
|
463
|
-
imports
|
464
|
-
}
|
465
|
-
];
|
466
|
-
}
|
467
|
-
});
|
468
|
-
})();
|
469
|
-
}
|
470
|
-
)
|
367
|
+
}
|
471
368
|
};
|
472
369
|
}
|
473
370
|
};
|
@@ -1,22 +1,6 @@
|
|
1
|
-
import { APP_CONFIG_NAME } from "./constants";
|
2
|
-
var index = function(param) {
|
3
|
-
var mountId = param.mountId, imports = param.imports, renderFunction2 = param.renderFunction, exportStatement = param.exportStatement;
|
4
|
-
return "\nconst IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';\nconst IS_REACT18 = process.env.IS_REACT18 === 'true';\nconst MOUNT_ID = '".concat(mountId, "';\n\n").concat(imports, "\n\nlet AppWrapper = null;\n\nlet root = null;\n\nfunction render() {\n ").concat(renderFunction2, "\n}\n\nAppWrapper = render();\n\n").concat(exportStatement, ";\n");
|
5
|
-
};
|
6
|
-
var renderFunction = function(param) {
|
7
|
-
var plugins = param.plugins, customBootstrap = param.customBootstrap, fileSystemRoutes = param.fileSystemRoutes, customRuntimeConfig = param.customRuntimeConfig;
|
8
|
-
var bootstrap = "bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM)";
|
9
|
-
var runtimePlugins = "...(runtimeConfig?.plugins || []),";
|
10
|
-
return "\n const finalAppConfig = {\n ...App.config,\n ...typeof ".concat(APP_CONFIG_NAME, " === 'function' ? ").concat(APP_CONFIG_NAME, "() : {},\n }\n\n AppWrapper = createApp({\n plugins: [\n ").concat(plugins.map(function(param2) {
|
11
|
-
var name = param2.name, options = param2.options, args = param2.args;
|
12
|
-
return "".concat(name, "({...").concat(options, ", ...finalAppConfig?.").concat(args || name, "}),");
|
13
|
-
}).join("\n"), "\n ").concat(customRuntimeConfig ? runtimePlugins : "", "\n ]\n })(").concat(fileSystemRoutes ? "" : "App", ")\n\n\n if(!AppWrapper.init && typeof appInit !== 'undefined') {\n AppWrapper.init = appInit;\n }\n\n\n if (IS_BROWSER) {\n ").concat(customBootstrap ? "customBootstrap(AppWrapper, () => ".concat(bootstrap, ");") : "".concat(bootstrap, ";"), "\n }\n\n return AppWrapper\n");
|
14
|
-
};
|
15
1
|
var html = function(partials) {
|
16
2
|
return "\n<!DOCTYPE html>\n<html>\n<head>\n\n ".concat(partials.top.join("\n"), "\n\n ").concat(partials.head.join("\n"), '\n\n</head>\n\n<body>\n <div id="<%= mountId %>"><!--<?- html ?>--></div>\n ').concat(partials.body.join("\n"), "\n <!--<?- chunksMap.js ?>-->\n <!--<?- SSRDataScript ?>-->\n <!--<?- bottomTemplate ?>-->\n</body>\n\n</html>\n");
|
17
3
|
};
|
18
4
|
export {
|
19
|
-
html
|
20
|
-
index,
|
21
|
-
renderFunction
|
5
|
+
html
|
22
6
|
};
|
@@ -3,10 +3,9 @@ import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
3
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
4
4
|
import fs from "fs";
|
5
5
|
import path from "path";
|
6
|
-
import {
|
6
|
+
import { normalizeToPosixPath, getCommand, JS_EXTENSIONS } from "@modern-js/utils";
|
7
7
|
import { transform } from "esbuild";
|
8
8
|
import { parse } from "es-module-lexer";
|
9
|
-
import { FILE_SYSTEM_ROUTES_FILE_NAME } from "./constants";
|
10
9
|
var walkDirectory = function(dir) {
|
11
10
|
return fs.readdirSync(dir).reduce(function(previous, filename) {
|
12
11
|
var filePath = path.join(dir, filename);
|
@@ -19,90 +18,6 @@ var walkDirectory = function(dir) {
|
|
19
18
|
}
|
20
19
|
}, []);
|
21
20
|
};
|
22
|
-
var getDefaultImports = function(param) {
|
23
|
-
var entrypoint = param.entrypoint, srcDirectory = param.srcDirectory, appDirectory = param.appDirectory, internalSrcAlias = param.internalSrcAlias, internalDirAlias = param.internalDirAlias, runtimeConfigFile = param.runtimeConfigFile, customRuntimeConfig = param.customRuntimeConfig;
|
24
|
-
var entryName = entrypoint.entryName, fileSystemRoutes = entrypoint.fileSystemRoutes, customBootstrap = entrypoint.customBootstrap, entry = entrypoint.entry;
|
25
|
-
var imports = [
|
26
|
-
{
|
27
|
-
specifiers: [
|
28
|
-
{
|
29
|
-
local: "React"
|
30
|
-
}
|
31
|
-
],
|
32
|
-
value: "react"
|
33
|
-
},
|
34
|
-
{
|
35
|
-
specifiers: [
|
36
|
-
{
|
37
|
-
local: "ReactDOM"
|
38
|
-
}
|
39
|
-
],
|
40
|
-
value: isReact18(path.join(appDirectory)) ? "react-dom/client" : "react-dom"
|
41
|
-
},
|
42
|
-
{
|
43
|
-
specifiers: [
|
44
|
-
{
|
45
|
-
imported: "createApp"
|
46
|
-
},
|
47
|
-
{
|
48
|
-
imported: "bootstrap"
|
49
|
-
}
|
50
|
-
],
|
51
|
-
value: "@modern-js/runtime"
|
52
|
-
},
|
53
|
-
customBootstrap && {
|
54
|
-
specifiers: [
|
55
|
-
{
|
56
|
-
local: "customBootstrap"
|
57
|
-
}
|
58
|
-
],
|
59
|
-
value: normalizeToPosixPath(customBootstrap.replace(srcDirectory, internalSrcAlias))
|
60
|
-
}
|
61
|
-
].filter(Boolean);
|
62
|
-
if (fileSystemRoutes) {
|
63
|
-
var route = {
|
64
|
-
specifiers: [
|
65
|
-
{
|
66
|
-
imported: "routes"
|
67
|
-
}
|
68
|
-
],
|
69
|
-
value: normalizeToPosixPath("".concat(internalDirAlias, "/").concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_FILE_NAME.replace(".js", "")))
|
70
|
-
};
|
71
|
-
if (fileSystemRoutes.globalApp) {
|
72
|
-
imports.push({
|
73
|
-
specifiers: [
|
74
|
-
{
|
75
|
-
local: "App"
|
76
|
-
}
|
77
|
-
],
|
78
|
-
value: normalizeToPosixPath(fileSystemRoutes.globalApp.replace(srcDirectory, internalSrcAlias))
|
79
|
-
});
|
80
|
-
} else {
|
81
|
-
route.initialize = "const App = false;";
|
82
|
-
}
|
83
|
-
imports.push(route);
|
84
|
-
} else {
|
85
|
-
imports.push({
|
86
|
-
specifiers: [
|
87
|
-
{
|
88
|
-
local: "App"
|
89
|
-
}
|
90
|
-
],
|
91
|
-
value: normalizeToPosixPath(entry.replace(srcDirectory, internalSrcAlias))
|
92
|
-
});
|
93
|
-
}
|
94
|
-
if (customRuntimeConfig) {
|
95
|
-
imports.push({
|
96
|
-
specifiers: [
|
97
|
-
{
|
98
|
-
local: "runtimeConfig"
|
99
|
-
}
|
100
|
-
],
|
101
|
-
value: path.join(internalSrcAlias, runtimeConfigFile || "")
|
102
|
-
});
|
103
|
-
}
|
104
|
-
return imports;
|
105
|
-
};
|
106
21
|
var replaceWithAlias = function(base, filePath, alias) {
|
107
22
|
if (filePath.includes(base)) {
|
108
23
|
return normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
|
@@ -178,7 +93,6 @@ var isSubDirOrEqual = function(parent, child) {
|
|
178
93
|
};
|
179
94
|
export {
|
180
95
|
checkIsBuildCommands,
|
181
|
-
getDefaultImports,
|
182
96
|
getServerCombinedModueFile,
|
183
97
|
isSubDirOrEqual,
|
184
98
|
parseModule,
|
@@ -14,11 +14,28 @@ function createBuilderOptions(target, appContext) {
|
|
14
14
|
];
|
15
15
|
}
|
16
16
|
}
|
17
|
+
const serverEntries = {};
|
18
|
+
for (const entry in entries) {
|
19
|
+
const v = entries[entry];
|
20
|
+
serverEntries[entry] = v.map((entry2) => entry2.replace("index.jsx", "index.server.jsx"));
|
21
|
+
}
|
17
22
|
return {
|
18
23
|
cwd: appContext.appDirectory,
|
19
24
|
target,
|
20
25
|
frameworkConfigPath: appContext.configFile || void 0,
|
21
|
-
entry:
|
26
|
+
entry({ target: target2 }) {
|
27
|
+
if (target2 === "web") {
|
28
|
+
return entries;
|
29
|
+
}
|
30
|
+
if ([
|
31
|
+
"node",
|
32
|
+
"web-worker",
|
33
|
+
"service-worker"
|
34
|
+
].includes(target2)) {
|
35
|
+
return serverEntries;
|
36
|
+
}
|
37
|
+
return entries;
|
38
|
+
}
|
22
39
|
};
|
23
40
|
}
|
24
41
|
export {
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { isHtmlDisabled } from "@
|
1
|
+
import { isHtmlDisabled } from "@modern-js/uni-builder";
|
2
2
|
import { MAIN_ENTRY_NAME, getEntryOptions, removeTailSlash } from "@modern-js/utils";
|
3
3
|
import { template as lodashTemplate } from "@modern-js/utils/lodash";
|
4
4
|
import { BottomTemplatePlugin } from "../bundlerPlugins";
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import * as path from "path";
|
2
|
-
import { isHtmlDisabled } from "@rsbuild/shared";
|
3
2
|
import { mergeRsbuildConfig } from "@rsbuild/core";
|
4
3
|
import { fs, isUseSSRBundle } from "@modern-js/utils";
|
4
|
+
import { isHtmlDisabled } from "@modern-js/uni-builder";
|
5
5
|
import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
|
6
6
|
import { getServerCombinedModueFile } from "../../../plugins/analyze/utils";
|
7
7
|
const builderPluginAdapterSSR = (options) => ({
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { newAction, upgradeAction } from "@modern-js/utils";
|
2
|
-
import { castArray } from "@
|
2
|
+
import { castArray } from "@modern-js/uni-builder";
|
3
3
|
import { i18n, localeKeys } from "../locale";
|
4
4
|
const devCommand = async (program, api) => {
|
5
5
|
const runner = api.useHookRunners();
|