@modern-js/app-tools 2.0.3-alpha.0 → 2.1.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/CHANGELOG.md +60 -0
- package/dist/js/modern/analyze/constants.js +1 -1
- package/dist/js/modern/analyze/generateCode.js +4 -12
- package/dist/js/modern/analyze/index.js +16 -4
- package/dist/js/modern/analyze/templates.js +15 -17
- package/dist/js/modern/analyze/utils.js +2 -19
- package/dist/js/modern/builder/index.js +1 -2
- package/dist/js/modern/config/default.js +3 -1
- package/dist/js/modern/initialize/index.js +7 -7
- package/dist/js/node/analyze/constants.js +1 -1
- package/dist/js/node/analyze/generateCode.js +3 -7
- package/dist/js/node/analyze/index.js +9 -3
- package/dist/js/node/analyze/templates.js +15 -17
- package/dist/js/node/analyze/utils.js +1 -18
- package/dist/js/node/builder/index.js +1 -2
- package/dist/js/node/config/default.js +3 -1
- package/dist/js/node/initialize/index.js +7 -7
- package/dist/js/treeshaking/analyze/constants.js +1 -1
- package/dist/js/treeshaking/analyze/generateCode.js +5 -8
- package/dist/js/treeshaking/analyze/index.js +5 -4
- package/dist/js/treeshaking/analyze/templates.js +10 -9
- package/dist/js/treeshaking/analyze/utils.js +2 -11
- package/dist/js/treeshaking/builder/index.js +1 -2
- package/dist/js/treeshaking/config/default.js +3 -1
- package/dist/js/treeshaking/initialize/index.js +19 -42
- package/dist/types/analyze/constants.d.ts +1 -1
- package/dist/types/analyze/templates.d.ts +2 -8
- package/dist/types/analyze/utils.d.ts +0 -1
- package/dist/types/types/config/dev.d.ts +1 -1
- package/lib/types.d.ts +6 -2
- package/package.json +24 -24
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,65 @@
|
|
|
1
1
|
# @modern-js/app-tools
|
|
2
2
|
|
|
3
|
+
## 2.1.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2ad9642: feat: new command support --lang params
|
|
8
|
+
|
|
9
|
+
feat: new 命令支持 --lang 参数
|
|
10
|
+
|
|
11
|
+
- bf38bda: feat(app-tools): allow to use dev.port config
|
|
12
|
+
|
|
13
|
+
feat(app-tools): 支持使用 dev.port 配置
|
|
14
|
+
|
|
15
|
+
- 29fbc66: fix(app-tools): SVG default export type
|
|
16
|
+
|
|
17
|
+
fix(app-tools): 修复 SVG 默认导出的类型错误
|
|
18
|
+
|
|
19
|
+
- 3a7da8c: fix(app-tools): server.port not work in development
|
|
20
|
+
|
|
21
|
+
fix(app-tools): 修复开发环境下 server.port 不生效的问题
|
|
22
|
+
|
|
23
|
+
- 3d0fb38: fix: remove the prebundle for data loader
|
|
24
|
+
fix: 移除 data loader 的预打包
|
|
25
|
+
- 6562578: chore: optimize the capitalization of plugin names
|
|
26
|
+
|
|
27
|
+
chore: 规范引用插件时的命名格式,统一使用 camelCase 代替 PascalCase
|
|
28
|
+
|
|
29
|
+
- 0d2af52: docs: add docs for config and init
|
|
30
|
+
docs: 添加 config 和 init 在嵌套路由下的文档
|
|
31
|
+
- 84ee9e9: fix: can't exit process after build
|
|
32
|
+
fix: 在 build 后不退出程序
|
|
33
|
+
- 5b54418: fix(builder): no longer remove comments of HTML
|
|
34
|
+
|
|
35
|
+
fix(builder): 不再默认移除 HTML 中的注释
|
|
36
|
+
|
|
37
|
+
- Updated dependencies [837620c]
|
|
38
|
+
- Updated dependencies [3d0fb38]
|
|
39
|
+
- Updated dependencies [3ad26c2]
|
|
40
|
+
- Updated dependencies [5b54418]
|
|
41
|
+
- Updated dependencies [bafa52e]
|
|
42
|
+
- Updated dependencies [ccbac43]
|
|
43
|
+
- Updated dependencies [8a9482c]
|
|
44
|
+
- Updated dependencies [679296d]
|
|
45
|
+
- @modern-js/utils@2.1.0
|
|
46
|
+
- @modern-js/plugin-data-loader@2.1.0
|
|
47
|
+
- @modern-js/server@2.1.0
|
|
48
|
+
- @modern-js/builder-shared@2.1.0
|
|
49
|
+
- @modern-js/builder-webpack-provider@2.1.0
|
|
50
|
+
- @modern-js/core@2.1.0
|
|
51
|
+
- @modern-js/builder@2.1.0
|
|
52
|
+
- @modern-js/builder-plugin-esbuild@2.1.0
|
|
53
|
+
- @modern-js/builder-plugin-node-polyfill@2.1.0
|
|
54
|
+
- @modern-js/plugin-i18n@2.1.0
|
|
55
|
+
- @modern-js/plugin-lint@2.1.0
|
|
56
|
+
- @modern-js/new-action@2.1.0
|
|
57
|
+
- @modern-js/prod-server@2.1.0
|
|
58
|
+
- @modern-js/node-bundle-require@2.1.0
|
|
59
|
+
- @modern-js/upgrade@2.1.0
|
|
60
|
+
- @modern-js/plugin@2.1.0
|
|
61
|
+
- @modern-js/types@2.1.0
|
|
62
|
+
|
|
3
63
|
## 2.0.2
|
|
4
64
|
|
|
5
65
|
### Patch Changes
|
|
@@ -19,11 +19,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
21
|
import path from "path";
|
|
22
|
-
import {
|
|
23
|
-
fs,
|
|
24
|
-
getEntryOptions,
|
|
25
|
-
logger
|
|
26
|
-
} from "@modern-js/utils";
|
|
22
|
+
import { fs, getEntryOptions, logger } from "@modern-js/utils";
|
|
27
23
|
import {
|
|
28
24
|
useResolvedConfigContext
|
|
29
25
|
} from "@modern-js/core";
|
|
@@ -87,7 +83,6 @@ const generateCode = (appContext, config, entrypoints, api) => __async(void 0, n
|
|
|
87
83
|
var _a, _b, _c;
|
|
88
84
|
const {
|
|
89
85
|
internalDirectory,
|
|
90
|
-
distDirectory,
|
|
91
86
|
srcDirectory,
|
|
92
87
|
internalDirAlias,
|
|
93
88
|
internalSrcAlias,
|
|
@@ -168,19 +163,16 @@ const generateCode = (appContext, config, entrypoints, api) => __async(void 0, n
|
|
|
168
163
|
ssrMode: mode,
|
|
169
164
|
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
170
165
|
entryName: entrypoint.entryName,
|
|
171
|
-
internalDirectory
|
|
172
|
-
internalDirAlias
|
|
166
|
+
internalDirectory
|
|
173
167
|
})
|
|
174
168
|
});
|
|
175
|
-
if (entrypoint.nestedRoutesEntry) {
|
|
169
|
+
if (entrypoint.nestedRoutesEntry && mode) {
|
|
176
170
|
const routesServerFile = getServerLoadersFile(
|
|
177
171
|
internalDirectory,
|
|
178
172
|
entryName
|
|
179
173
|
);
|
|
180
174
|
const code3 = templates.routesForServer({
|
|
181
|
-
routes
|
|
182
|
-
internalDirectory,
|
|
183
|
-
entryName
|
|
175
|
+
routes
|
|
184
176
|
});
|
|
185
177
|
yield fs.ensureFile(routesServerFile);
|
|
186
178
|
yield fs.writeFile(routesServerFile, code3);
|
|
@@ -38,7 +38,13 @@ var __async = (__this, __arguments, generator) => {
|
|
|
38
38
|
});
|
|
39
39
|
};
|
|
40
40
|
import * as path from "path";
|
|
41
|
-
import {
|
|
41
|
+
import {
|
|
42
|
+
createDebugger,
|
|
43
|
+
findExists,
|
|
44
|
+
fs,
|
|
45
|
+
getEntryOptions,
|
|
46
|
+
isApiOnly
|
|
47
|
+
} from "@modern-js/utils";
|
|
42
48
|
import { cloneDeep } from "@modern-js/utils/lodash";
|
|
43
49
|
import { createBuilderForModern } from "../builder";
|
|
44
50
|
import { printInstructions } from "../utils/printInstructions";
|
|
@@ -209,13 +215,19 @@ var analyze_default = () => ({
|
|
|
209
215
|
config() {
|
|
210
216
|
return {
|
|
211
217
|
tools: {
|
|
212
|
-
webpackChain: (chain, { name
|
|
218
|
+
webpackChain: (chain, { name }) => {
|
|
213
219
|
const appContext = api.useAppContext();
|
|
214
220
|
const resolvedConfig = api.useResolvedConfigContext();
|
|
215
|
-
const { entrypoints, internalDirectory } = appContext;
|
|
221
|
+
const { entrypoints, internalDirectory, packageName } = appContext;
|
|
216
222
|
entrypoints.forEach((entrypoint) => {
|
|
217
223
|
const { entryName } = entrypoint;
|
|
218
|
-
|
|
224
|
+
const ssr = getEntryOptions(
|
|
225
|
+
entryName,
|
|
226
|
+
resolvedConfig.server.ssr,
|
|
227
|
+
resolvedConfig.server.ssrByEntries,
|
|
228
|
+
packageName
|
|
229
|
+
);
|
|
230
|
+
if (entrypoint.nestedRoutesEntry && ssr && name === "server") {
|
|
219
231
|
const serverLoadersFile = getServerLoadersFile(
|
|
220
232
|
internalDirectory,
|
|
221
233
|
entryName
|
|
@@ -72,7 +72,7 @@ const renderFunction = ({
|
|
|
72
72
|
return `
|
|
73
73
|
const finalAppConfig = {
|
|
74
74
|
...App.config,
|
|
75
|
-
...typeof ${APP_CONFIG_NAME} === '
|
|
75
|
+
...typeof ${APP_CONFIG_NAME} === 'function' ? ${APP_CONFIG_NAME}() : {},
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
AppWrapper = createApp({
|
|
@@ -127,17 +127,9 @@ const html = (partials) => `
|
|
|
127
127
|
</html>
|
|
128
128
|
`;
|
|
129
129
|
const routesForServer = ({
|
|
130
|
-
routes
|
|
131
|
-
internalDirectory,
|
|
132
|
-
entryName
|
|
130
|
+
routes
|
|
133
131
|
}) => {
|
|
134
132
|
const loaders = [];
|
|
135
|
-
const loaderIndexFile = path.join(
|
|
136
|
-
internalDirectory,
|
|
137
|
-
entryName,
|
|
138
|
-
TEMP_LOADERS_DIR,
|
|
139
|
-
"index.js"
|
|
140
|
-
);
|
|
141
133
|
const traverseRouteTree = (route) => {
|
|
142
134
|
var _a;
|
|
143
135
|
let children;
|
|
@@ -176,7 +168,7 @@ const routesForServer = ({
|
|
|
176
168
|
let importLoadersCode = "";
|
|
177
169
|
if (loaders.length > 0) {
|
|
178
170
|
importLoadersCode = loaders.map((loader, index2) => {
|
|
179
|
-
return `import loader_${index2} from "${loader}"`;
|
|
171
|
+
return `import loader_${index2} from "${slash(loader)}"`;
|
|
180
172
|
}).join("\n");
|
|
181
173
|
}
|
|
182
174
|
return `
|
|
@@ -189,8 +181,7 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
189
181
|
ssrMode,
|
|
190
182
|
nestedRoutesEntry,
|
|
191
183
|
entryName,
|
|
192
|
-
internalDirectory
|
|
193
|
-
internalDirAlias
|
|
184
|
+
internalDirectory
|
|
194
185
|
}) {
|
|
195
186
|
const loadings = [];
|
|
196
187
|
const errors = [];
|
|
@@ -209,11 +200,14 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
209
200
|
let rootLayoutCode = ``;
|
|
210
201
|
let componentLoaderPath = "";
|
|
211
202
|
const getDataLoaderPath = (loaderId) => {
|
|
212
|
-
if (!ssrMode)
|
|
203
|
+
if (!ssrMode) {
|
|
213
204
|
return "";
|
|
205
|
+
}
|
|
214
206
|
let dataLoaderPath = require.resolve("@modern-js/plugin-data-loader/loader");
|
|
215
207
|
if (nestedRoutesEntry) {
|
|
216
|
-
dataLoaderPath = `${slash(dataLoaderPath)}?mapFile=${slash(
|
|
208
|
+
dataLoaderPath = `${slash(dataLoaderPath)}?mapFile=${slash(
|
|
209
|
+
loadersMapFile
|
|
210
|
+
)}&loaderId=${loaderId}!`;
|
|
217
211
|
}
|
|
218
212
|
return dataLoaderPath;
|
|
219
213
|
};
|
|
@@ -309,10 +303,14 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
309
303
|
let importLoadersCode = "";
|
|
310
304
|
for (const [key, loaderInfo] of Object.entries(loadersMap)) {
|
|
311
305
|
if (loaderInfo.inline) {
|
|
312
|
-
importLoadersCode += `import { loader as ${key} } from "${getDataLoaderPath(
|
|
306
|
+
importLoadersCode += `import { loader as ${key} } from "${getDataLoaderPath(
|
|
307
|
+
key
|
|
308
|
+
)}${slash(loaderInfo.filePath)}";
|
|
313
309
|
`;
|
|
314
310
|
} else {
|
|
315
|
-
importLoadersCode += `import ${key} from "${getDataLoaderPath(
|
|
311
|
+
importLoadersCode += `import ${key} from "${getDataLoaderPath(
|
|
312
|
+
key
|
|
313
|
+
)}${slash(loaderInfo.filePath)}";
|
|
316
314
|
`;
|
|
317
315
|
}
|
|
318
316
|
}
|
|
@@ -26,8 +26,7 @@ import { parse } from "es-module-lexer";
|
|
|
26
26
|
import {
|
|
27
27
|
FILE_SYSTEM_ROUTES_FILE_NAME,
|
|
28
28
|
JS_EXTENSIONS,
|
|
29
|
-
LOADER_EXPORT_NAME
|
|
30
|
-
NESTED_ROUTE
|
|
29
|
+
LOADER_EXPORT_NAME
|
|
31
30
|
} from "./constants";
|
|
32
31
|
const walkDirectory = (dir) => fs.readdirSync(dir).reduce((previous, filename) => {
|
|
33
32
|
const filePath = path.join(dir, filename);
|
|
@@ -105,17 +104,6 @@ const isPageComponentFile = (filePath) => {
|
|
|
105
104
|
}
|
|
106
105
|
return false;
|
|
107
106
|
};
|
|
108
|
-
const isNestedRouteComponent = (nestedRouteEntries, absoluteFilePath) => {
|
|
109
|
-
const reg = new RegExp(
|
|
110
|
-
`(${NESTED_ROUTE.LAYOUT_FILE}|${NESTED_ROUTE.PAGE_FILE})\\.tsx?$`
|
|
111
|
-
);
|
|
112
|
-
return nestedRouteEntries.some((nestedRoutesEntry) => {
|
|
113
|
-
if (absoluteFilePath.includes(nestedRoutesEntry) && reg.test(absoluteFilePath)) {
|
|
114
|
-
return true;
|
|
115
|
-
}
|
|
116
|
-
return false;
|
|
117
|
-
});
|
|
118
|
-
};
|
|
119
107
|
const replaceWithAlias = (base, filePath, alias) => normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
|
|
120
108
|
const parseModule = (_0) => __async(void 0, [_0], function* ({
|
|
121
109
|
source,
|
|
@@ -140,17 +128,12 @@ const hasLoader = (filename) => __async(void 0, null, function* () {
|
|
|
140
128
|
return moduleExports.some((e) => e.n === LOADER_EXPORT_NAME);
|
|
141
129
|
});
|
|
142
130
|
const getServerLoadersFile = (internalDirectory, entryName) => {
|
|
143
|
-
return path.join(
|
|
144
|
-
internalDirectory,
|
|
145
|
-
entryName,
|
|
146
|
-
"route-server-loaders.js"
|
|
147
|
-
);
|
|
131
|
+
return path.join(internalDirectory, entryName, "route-server-loaders.js");
|
|
148
132
|
};
|
|
149
133
|
export {
|
|
150
134
|
getDefaultImports,
|
|
151
135
|
getServerLoadersFile,
|
|
152
136
|
hasLoader,
|
|
153
|
-
isNestedRouteComponent,
|
|
154
137
|
isPageComponentFile,
|
|
155
138
|
parseModule,
|
|
156
139
|
replaceWithAlias,
|
|
@@ -87,7 +87,6 @@ function createBuilderForModern(_0) {
|
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
89
|
function createBuilderProviderConfig(normalizedConfig, appContext) {
|
|
90
|
-
var _a;
|
|
91
90
|
const output = createOutputConfig(normalizedConfig, appContext);
|
|
92
91
|
const htmlConfig = __spreadValues({}, normalizedConfig.html);
|
|
93
92
|
if (!htmlConfig.template) {
|
|
@@ -96,7 +95,7 @@ function createBuilderProviderConfig(normalizedConfig, appContext) {
|
|
|
96
95
|
return __spreadProps(__spreadValues({}, normalizedConfig), {
|
|
97
96
|
output,
|
|
98
97
|
dev: __spreadProps(__spreadValues({}, normalizedConfig.dev), {
|
|
99
|
-
port:
|
|
98
|
+
port: appContext.port
|
|
100
99
|
}),
|
|
101
100
|
html: htmlConfig
|
|
102
101
|
});
|
|
@@ -20,7 +20,9 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
20
20
|
import { createDefaultConfig as createDefaultBuilderConfig } from "@modern-js/builder-webpack-provider";
|
|
21
21
|
function createDefaultConfig(appContext) {
|
|
22
22
|
const defaultBuilderConfig = createDefaultBuilderConfig();
|
|
23
|
-
const dev = __spreadValues({}, defaultBuilderConfig.dev)
|
|
23
|
+
const dev = __spreadProps(__spreadValues({}, defaultBuilderConfig.dev), {
|
|
24
|
+
port: void 0
|
|
25
|
+
});
|
|
24
26
|
const tools = __spreadValues({}, defaultBuilderConfig.tools);
|
|
25
27
|
const output = __spreadProps(__spreadValues({}, defaultBuilderConfig.output), {
|
|
26
28
|
disableNodePolyfill: true
|
|
@@ -64,10 +64,10 @@ var initialize_default = () => ({
|
|
|
64
64
|
validateSchema,
|
|
65
65
|
resolvedConfig(_0) {
|
|
66
66
|
return __async(this, arguments, function* ({ resolved }) {
|
|
67
|
-
var _a2
|
|
67
|
+
var _a2;
|
|
68
68
|
let appContext = api.useAppContext();
|
|
69
69
|
const userConfig = api.useConfigContext();
|
|
70
|
-
const port = yield
|
|
70
|
+
const port = yield getServerPort(resolved);
|
|
71
71
|
appContext = __spreadProps(__spreadValues({}, appContext), {
|
|
72
72
|
port,
|
|
73
73
|
distDirectory: ensureAbsolutePath(
|
|
@@ -82,7 +82,7 @@ var initialize_default = () => ({
|
|
|
82
82
|
_raw: userConfig,
|
|
83
83
|
source: normalizedConfig.source || {},
|
|
84
84
|
server: __spreadProps(__spreadValues({}, normalizedConfig.server || {}), {
|
|
85
|
-
port
|
|
85
|
+
port
|
|
86
86
|
}),
|
|
87
87
|
bff: normalizedConfig.bff || {},
|
|
88
88
|
dev: normalizedConfig.dev || {},
|
|
@@ -106,13 +106,13 @@ var initialize_default = () => ({
|
|
|
106
106
|
};
|
|
107
107
|
}
|
|
108
108
|
});
|
|
109
|
-
function
|
|
109
|
+
function getServerPort(config) {
|
|
110
110
|
return __async(this, null, function* () {
|
|
111
|
-
|
|
111
|
+
const prodPort = config.server.port || 8080;
|
|
112
112
|
if (isDev() && isDevCommand()) {
|
|
113
|
-
return
|
|
113
|
+
return getPort(config.dev.port || prodPort);
|
|
114
114
|
}
|
|
115
|
-
return
|
|
115
|
+
return prodPort;
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
118
|
export {
|
|
@@ -68,7 +68,7 @@ const NESTED_ROUTE = {
|
|
|
68
68
|
ERROR_FILE: "error",
|
|
69
69
|
LOADER_FILE: "loader"
|
|
70
70
|
};
|
|
71
|
-
const APP_CONFIG_NAME = "
|
|
71
|
+
const APP_CONFIG_NAME = "config";
|
|
72
72
|
const APP_INIT_EXPORTED = "init";
|
|
73
73
|
const APP_INIT_IMPORTED = "appInit";
|
|
74
74
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -106,7 +106,6 @@ const generateCode = (appContext, config, entrypoints, api) => __async(void 0, n
|
|
|
106
106
|
var _a, _b, _c;
|
|
107
107
|
const {
|
|
108
108
|
internalDirectory,
|
|
109
|
-
distDirectory,
|
|
110
109
|
srcDirectory,
|
|
111
110
|
internalDirAlias,
|
|
112
111
|
internalSrcAlias,
|
|
@@ -187,19 +186,16 @@ const generateCode = (appContext, config, entrypoints, api) => __async(void 0, n
|
|
|
187
186
|
ssrMode: mode,
|
|
188
187
|
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
189
188
|
entryName: entrypoint.entryName,
|
|
190
|
-
internalDirectory
|
|
191
|
-
internalDirAlias
|
|
189
|
+
internalDirectory
|
|
192
190
|
})
|
|
193
191
|
});
|
|
194
|
-
if (entrypoint.nestedRoutesEntry) {
|
|
192
|
+
if (entrypoint.nestedRoutesEntry && mode) {
|
|
195
193
|
const routesServerFile = (0, import_utils2.getServerLoadersFile)(
|
|
196
194
|
internalDirectory,
|
|
197
195
|
entryName
|
|
198
196
|
);
|
|
199
197
|
const code3 = templates.routesForServer({
|
|
200
|
-
routes
|
|
201
|
-
internalDirectory,
|
|
202
|
-
entryName
|
|
198
|
+
routes
|
|
203
199
|
});
|
|
204
200
|
yield import_utils.fs.ensureFile(routesServerFile);
|
|
205
201
|
yield import_utils.fs.writeFile(routesServerFile, code3);
|
|
@@ -226,13 +226,19 @@ var analyze_default = () => ({
|
|
|
226
226
|
config() {
|
|
227
227
|
return {
|
|
228
228
|
tools: {
|
|
229
|
-
webpackChain: (chain, { name
|
|
229
|
+
webpackChain: (chain, { name }) => {
|
|
230
230
|
const appContext = api.useAppContext();
|
|
231
231
|
const resolvedConfig = api.useResolvedConfigContext();
|
|
232
|
-
const { entrypoints, internalDirectory } = appContext;
|
|
232
|
+
const { entrypoints, internalDirectory, packageName } = appContext;
|
|
233
233
|
entrypoints.forEach((entrypoint) => {
|
|
234
234
|
const { entryName } = entrypoint;
|
|
235
|
-
|
|
235
|
+
const ssr = (0, import_utils.getEntryOptions)(
|
|
236
|
+
entryName,
|
|
237
|
+
resolvedConfig.server.ssr,
|
|
238
|
+
resolvedConfig.server.ssrByEntries,
|
|
239
|
+
packageName
|
|
240
|
+
);
|
|
241
|
+
if (entrypoint.nestedRoutesEntry && ssr && name === "server") {
|
|
236
242
|
const serverLoadersFile = (0, import_utils2.getServerLoadersFile)(
|
|
237
243
|
internalDirectory,
|
|
238
244
|
entryName
|
|
@@ -102,7 +102,7 @@ const renderFunction = ({
|
|
|
102
102
|
return `
|
|
103
103
|
const finalAppConfig = {
|
|
104
104
|
...App.config,
|
|
105
|
-
...typeof ${import_constants.APP_CONFIG_NAME} === '
|
|
105
|
+
...typeof ${import_constants.APP_CONFIG_NAME} === 'function' ? ${import_constants.APP_CONFIG_NAME}() : {},
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
AppWrapper = createApp({
|
|
@@ -157,17 +157,9 @@ const html = (partials) => `
|
|
|
157
157
|
</html>
|
|
158
158
|
`;
|
|
159
159
|
const routesForServer = ({
|
|
160
|
-
routes
|
|
161
|
-
internalDirectory,
|
|
162
|
-
entryName
|
|
160
|
+
routes
|
|
163
161
|
}) => {
|
|
164
162
|
const loaders = [];
|
|
165
|
-
const loaderIndexFile = import_path.default.join(
|
|
166
|
-
internalDirectory,
|
|
167
|
-
entryName,
|
|
168
|
-
import_constants.TEMP_LOADERS_DIR,
|
|
169
|
-
"index.js"
|
|
170
|
-
);
|
|
171
163
|
const traverseRouteTree = (route) => {
|
|
172
164
|
var _a;
|
|
173
165
|
let children;
|
|
@@ -206,7 +198,7 @@ const routesForServer = ({
|
|
|
206
198
|
let importLoadersCode = "";
|
|
207
199
|
if (loaders.length > 0) {
|
|
208
200
|
importLoadersCode = loaders.map((loader, index2) => {
|
|
209
|
-
return `import loader_${index2} from "${loader}"`;
|
|
201
|
+
return `import loader_${index2} from "${(0, import_utils.slash)(loader)}"`;
|
|
210
202
|
}).join("\n");
|
|
211
203
|
}
|
|
212
204
|
return `
|
|
@@ -219,8 +211,7 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
219
211
|
ssrMode,
|
|
220
212
|
nestedRoutesEntry,
|
|
221
213
|
entryName,
|
|
222
|
-
internalDirectory
|
|
223
|
-
internalDirAlias
|
|
214
|
+
internalDirectory
|
|
224
215
|
}) {
|
|
225
216
|
const loadings = [];
|
|
226
217
|
const errors = [];
|
|
@@ -239,11 +230,14 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
239
230
|
let rootLayoutCode = ``;
|
|
240
231
|
let componentLoaderPath = "";
|
|
241
232
|
const getDataLoaderPath = (loaderId) => {
|
|
242
|
-
if (!ssrMode)
|
|
233
|
+
if (!ssrMode) {
|
|
243
234
|
return "";
|
|
235
|
+
}
|
|
244
236
|
let dataLoaderPath = require.resolve("@modern-js/plugin-data-loader/loader");
|
|
245
237
|
if (nestedRoutesEntry) {
|
|
246
|
-
dataLoaderPath = `${(0, import_utils.slash)(dataLoaderPath)}?mapFile=${(0, import_utils.slash)(
|
|
238
|
+
dataLoaderPath = `${(0, import_utils.slash)(dataLoaderPath)}?mapFile=${(0, import_utils.slash)(
|
|
239
|
+
loadersMapFile
|
|
240
|
+
)}&loaderId=${loaderId}!`;
|
|
247
241
|
}
|
|
248
242
|
return dataLoaderPath;
|
|
249
243
|
};
|
|
@@ -339,10 +333,14 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
|
339
333
|
let importLoadersCode = "";
|
|
340
334
|
for (const [key, loaderInfo] of Object.entries(loadersMap)) {
|
|
341
335
|
if (loaderInfo.inline) {
|
|
342
|
-
importLoadersCode += `import { loader as ${key} } from "${getDataLoaderPath(
|
|
336
|
+
importLoadersCode += `import { loader as ${key} } from "${getDataLoaderPath(
|
|
337
|
+
key
|
|
338
|
+
)}${(0, import_utils.slash)(loaderInfo.filePath)}";
|
|
343
339
|
`;
|
|
344
340
|
} else {
|
|
345
|
-
importLoadersCode += `import ${key} from "${getDataLoaderPath(
|
|
341
|
+
importLoadersCode += `import ${key} from "${getDataLoaderPath(
|
|
342
|
+
key
|
|
343
|
+
)}${(0, import_utils.slash)(loaderInfo.filePath)}";
|
|
346
344
|
`;
|
|
347
345
|
}
|
|
348
346
|
}
|
|
@@ -46,7 +46,6 @@ __export(utils_exports, {
|
|
|
46
46
|
getDefaultImports: () => getDefaultImports,
|
|
47
47
|
getServerLoadersFile: () => getServerLoadersFile,
|
|
48
48
|
hasLoader: () => hasLoader,
|
|
49
|
-
isNestedRouteComponent: () => isNestedRouteComponent,
|
|
50
49
|
isPageComponentFile: () => isPageComponentFile,
|
|
51
50
|
parseModule: () => parseModule,
|
|
52
51
|
replaceWithAlias: () => replaceWithAlias,
|
|
@@ -135,17 +134,6 @@ const isPageComponentFile = (filePath) => {
|
|
|
135
134
|
}
|
|
136
135
|
return false;
|
|
137
136
|
};
|
|
138
|
-
const isNestedRouteComponent = (nestedRouteEntries, absoluteFilePath) => {
|
|
139
|
-
const reg = new RegExp(
|
|
140
|
-
`(${import_constants.NESTED_ROUTE.LAYOUT_FILE}|${import_constants.NESTED_ROUTE.PAGE_FILE})\\.tsx?$`
|
|
141
|
-
);
|
|
142
|
-
return nestedRouteEntries.some((nestedRoutesEntry) => {
|
|
143
|
-
if (absoluteFilePath.includes(nestedRoutesEntry) && reg.test(absoluteFilePath)) {
|
|
144
|
-
return true;
|
|
145
|
-
}
|
|
146
|
-
return false;
|
|
147
|
-
});
|
|
148
|
-
};
|
|
149
137
|
const replaceWithAlias = (base, filePath, alias) => (0, import_utils.normalizeToPosixPath)(import_path.default.join(alias, import_path.default.relative(base, filePath)));
|
|
150
138
|
const parseModule = (_0) => __async(void 0, [_0], function* ({
|
|
151
139
|
source,
|
|
@@ -170,18 +158,13 @@ const hasLoader = (filename) => __async(void 0, null, function* () {
|
|
|
170
158
|
return moduleExports.some((e) => e.n === import_constants.LOADER_EXPORT_NAME);
|
|
171
159
|
});
|
|
172
160
|
const getServerLoadersFile = (internalDirectory, entryName) => {
|
|
173
|
-
return import_path.default.join(
|
|
174
|
-
internalDirectory,
|
|
175
|
-
entryName,
|
|
176
|
-
"route-server-loaders.js"
|
|
177
|
-
);
|
|
161
|
+
return import_path.default.join(internalDirectory, entryName, "route-server-loaders.js");
|
|
178
162
|
};
|
|
179
163
|
// Annotate the CommonJS export names for ESM import in node:
|
|
180
164
|
0 && (module.exports = {
|
|
181
165
|
getDefaultImports,
|
|
182
166
|
getServerLoadersFile,
|
|
183
167
|
hasLoader,
|
|
184
|
-
isNestedRouteComponent,
|
|
185
168
|
isPageComponentFile,
|
|
186
169
|
parseModule,
|
|
187
170
|
replaceWithAlias,
|
|
@@ -104,7 +104,6 @@ function createBuilderForModern(_0) {
|
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
function createBuilderProviderConfig(normalizedConfig, appContext) {
|
|
107
|
-
var _a;
|
|
108
107
|
const output = createOutputConfig(normalizedConfig, appContext);
|
|
109
108
|
const htmlConfig = __spreadValues({}, normalizedConfig.html);
|
|
110
109
|
if (!htmlConfig.template) {
|
|
@@ -113,7 +112,7 @@ function createBuilderProviderConfig(normalizedConfig, appContext) {
|
|
|
113
112
|
return __spreadProps(__spreadValues({}, normalizedConfig), {
|
|
114
113
|
output,
|
|
115
114
|
dev: __spreadProps(__spreadValues({}, normalizedConfig.dev), {
|
|
116
|
-
port:
|
|
115
|
+
port: appContext.port
|
|
117
116
|
}),
|
|
118
117
|
html: htmlConfig
|
|
119
118
|
});
|
|
@@ -41,7 +41,9 @@ module.exports = __toCommonJS(default_exports);
|
|
|
41
41
|
var import_builder_webpack_provider = require("@modern-js/builder-webpack-provider");
|
|
42
42
|
function createDefaultConfig(appContext) {
|
|
43
43
|
const defaultBuilderConfig = (0, import_builder_webpack_provider.createDefaultConfig)();
|
|
44
|
-
const dev = __spreadValues({}, defaultBuilderConfig.dev)
|
|
44
|
+
const dev = __spreadProps(__spreadValues({}, defaultBuilderConfig.dev), {
|
|
45
|
+
port: void 0
|
|
46
|
+
});
|
|
45
47
|
const tools = __spreadValues({}, defaultBuilderConfig.tools);
|
|
46
48
|
const output = __spreadProps(__spreadValues({}, defaultBuilderConfig.output), {
|
|
47
49
|
disableNodePolyfill: true
|
|
@@ -80,10 +80,10 @@ var initialize_default = () => ({
|
|
|
80
80
|
validateSchema,
|
|
81
81
|
resolvedConfig(_0) {
|
|
82
82
|
return __async(this, arguments, function* ({ resolved }) {
|
|
83
|
-
var _a2
|
|
83
|
+
var _a2;
|
|
84
84
|
let appContext = api.useAppContext();
|
|
85
85
|
const userConfig = api.useConfigContext();
|
|
86
|
-
const port = yield
|
|
86
|
+
const port = yield getServerPort(resolved);
|
|
87
87
|
appContext = __spreadProps(__spreadValues({}, appContext), {
|
|
88
88
|
port,
|
|
89
89
|
distDirectory: (0, import_utils.ensureAbsolutePath)(
|
|
@@ -98,7 +98,7 @@ var initialize_default = () => ({
|
|
|
98
98
|
_raw: userConfig,
|
|
99
99
|
source: normalizedConfig.source || {},
|
|
100
100
|
server: __spreadProps(__spreadValues({}, normalizedConfig.server || {}), {
|
|
101
|
-
port
|
|
101
|
+
port
|
|
102
102
|
}),
|
|
103
103
|
bff: normalizedConfig.bff || {},
|
|
104
104
|
dev: normalizedConfig.dev || {},
|
|
@@ -122,13 +122,13 @@ var initialize_default = () => ({
|
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
124
|
});
|
|
125
|
-
function
|
|
125
|
+
function getServerPort(config) {
|
|
126
126
|
return __async(this, null, function* () {
|
|
127
|
-
|
|
127
|
+
const prodPort = config.server.port || 8080;
|
|
128
128
|
if ((0, import_utils.isDev)() && (0, import_commands.isDevCommand)()) {
|
|
129
|
-
return (
|
|
129
|
+
return (0, import_utils.getPort)(config.dev.port || prodPort);
|
|
130
130
|
}
|
|
131
|
-
return
|
|
131
|
+
return prodPort;
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
134
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -34,7 +34,7 @@ var NESTED_ROUTE = {
|
|
|
34
34
|
ERROR_FILE: "error",
|
|
35
35
|
LOADER_FILE: "loader"
|
|
36
36
|
};
|
|
37
|
-
var APP_CONFIG_NAME = "
|
|
37
|
+
var APP_CONFIG_NAME = "config";
|
|
38
38
|
var APP_INIT_EXPORTED = "init";
|
|
39
39
|
var APP_INIT_IMPORTED = "appInit";
|
|
40
40
|
export { APP_CONFIG_NAME, APP_FILE_NAME, APP_INIT_EXPORTED, APP_INIT_IMPORTED, ENTRY_BOOTSTRAP_FILE_NAME, ENTRY_POINT_FILE_NAME, FILE_SYSTEM_ROUTES_COMPONENTS_DIR, FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP, FILE_SYSTEM_ROUTES_FILE_NAME, FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT, FILE_SYSTEM_ROUTES_IGNORED_REGEX, FILE_SYSTEM_ROUTES_INDEX, FILE_SYSTEM_ROUTES_LAYOUT, HTML_PARTIALS_EXTENSIONS, HTML_PARTIALS_FOLDER, INDEX_FILE_NAME, JS_EXTENSIONS, LOADER_EXPORT_NAME, NESTED_ROUTE, NESTED_ROUTES_DIR, PAGES_DIR_NAME, TEMP_LOADERS_DIR };
|
|
@@ -240,7 +240,7 @@ var createImportStatements = function(statements) {
|
|
|
240
240
|
};
|
|
241
241
|
var generateCode = function() {
|
|
242
242
|
var _ref = _asyncToGenerator(function(appContext, config, entrypoints, api) {
|
|
243
|
-
var ref, ref1, ref2, internalDirectory,
|
|
243
|
+
var ref, ref1, ref2, internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hookRunners, isV5, mountId, getRoutes;
|
|
244
244
|
function generateEntryCode(entrypoint) {
|
|
245
245
|
return _generateEntryCode.apply(this, arguments);
|
|
246
246
|
}
|
|
@@ -335,8 +335,7 @@ var generateCode = function() {
|
|
|
335
335
|
ssrMode: mode,
|
|
336
336
|
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
337
337
|
entryName: entrypoint.entryName,
|
|
338
|
-
internalDirectory: internalDirectory
|
|
339
|
-
internalDirAlias: internalDirAlias
|
|
338
|
+
internalDirectory: internalDirectory
|
|
340
339
|
})
|
|
341
340
|
];
|
|
342
341
|
case 5:
|
|
@@ -348,15 +347,13 @@ var generateCode = function() {
|
|
|
348
347
|
];
|
|
349
348
|
case 6:
|
|
350
349
|
ref = _state.sent(), code2 = ref.code;
|
|
351
|
-
if (!entrypoint.nestedRoutesEntry) return [
|
|
350
|
+
if (!(entrypoint.nestedRoutesEntry && mode)) return [
|
|
352
351
|
3,
|
|
353
352
|
9
|
|
354
353
|
];
|
|
355
354
|
routesServerFile = getServerLoadersFile(internalDirectory, entryName);
|
|
356
355
|
code3 = templates.routesForServer({
|
|
357
|
-
routes: routes
|
|
358
|
-
internalDirectory: internalDirectory,
|
|
359
|
-
entryName: entryName
|
|
356
|
+
routes: routes
|
|
360
357
|
});
|
|
361
358
|
return [
|
|
362
359
|
4,
|
|
@@ -464,7 +461,7 @@ var generateCode = function() {
|
|
|
464
461
|
return __generator(this, function(_state) {
|
|
465
462
|
switch(_state.label){
|
|
466
463
|
case 0:
|
|
467
|
-
internalDirectory = appContext.internalDirectory,
|
|
464
|
+
internalDirectory = appContext.internalDirectory, srcDirectory = appContext.srcDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias, packageName = appContext.packageName;
|
|
468
465
|
hookRunners = api.useHookRunners();
|
|
469
466
|
isV5 = typeof ((ref = config.runtime) === null || ref === void 0 ? void 0 : ref.router) !== "boolean" && (config === null || config === void 0 ? void 0 : (ref1 = config.runtime) === null || ref1 === void 0 ? void 0 : (ref2 = ref1.router) === null || ref2 === void 0 ? void 0 : ref2.mode) === "react-router-5";
|
|
470
467
|
mountId = config.html.mountId;
|
|
@@ -221,7 +221,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
221
221
|
}
|
|
222
222
|
};
|
|
223
223
|
import * as path from "path";
|
|
224
|
-
import { createDebugger, findExists, fs,
|
|
224
|
+
import { createDebugger, findExists, fs, getEntryOptions, isApiOnly } from "@modern-js/utils";
|
|
225
225
|
import { cloneDeep } from "@modern-js/utils/lodash";
|
|
226
226
|
import { createBuilderForModern } from "../builder";
|
|
227
227
|
import { printInstructions } from "../utils/printInstructions";
|
|
@@ -528,13 +528,14 @@ var analyze_default = function() {
|
|
|
528
528
|
return {
|
|
529
529
|
tools: {
|
|
530
530
|
webpackChain: function(chain, param) {
|
|
531
|
-
var name = param.name
|
|
531
|
+
var name = param.name;
|
|
532
532
|
var appContext = api.useAppContext();
|
|
533
533
|
var resolvedConfig = api.useResolvedConfigContext();
|
|
534
|
-
var entrypoints = appContext.entrypoints, internalDirectory = appContext.internalDirectory;
|
|
534
|
+
var entrypoints = appContext.entrypoints, internalDirectory = appContext.internalDirectory, packageName = appContext.packageName;
|
|
535
535
|
entrypoints.forEach(function(entrypoint) {
|
|
536
536
|
var entryName = entrypoint.entryName;
|
|
537
|
-
|
|
537
|
+
var ssr = getEntryOptions(entryName, resolvedConfig.server.ssr, resolvedConfig.server.ssrByEntries, packageName);
|
|
538
|
+
if (entrypoint.nestedRoutesEntry && ssr && name === "server") {
|
|
538
539
|
var serverLoadersFile = getServerLoadersFile(internalDirectory, entryName);
|
|
539
540
|
chain.entry("".concat(entryName, "-server-loaders")).add(serverLoadersFile);
|
|
540
541
|
}
|
|
@@ -229,7 +229,7 @@ var index = function(param) {
|
|
|
229
229
|
};
|
|
230
230
|
var renderFunction = function(param) {
|
|
231
231
|
var plugins = param.plugins, customBootstrap = param.customBootstrap, fileSystemRoutes2 = param.fileSystemRoutes;
|
|
232
|
-
return "\n const finalAppConfig = {\n ...App.config,\n ...typeof ".concat(APP_CONFIG_NAME, " === '
|
|
232
|
+
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(param) {
|
|
233
233
|
var name = param.name, options = param.options, args = param.args;
|
|
234
234
|
return "".concat(name, "({...").concat(options, ", ...finalAppConfig?.").concat(args || name, "}),");
|
|
235
235
|
}).join("\n"), "\n ]\n })(").concat(fileSystemRoutes2 ? "" : "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);" : "bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM);", "\n }\n\n return AppWrapper\n");
|
|
@@ -238,9 +238,8 @@ var html = function(partials) {
|
|
|
238
238
|
return "\n<!DOCTYPE html>\n<html>\n<head>\n <%= meta %>\n <title><%= title %></title>\n\n ".concat(partials.top.join("\n"), "\n\n <script>\n window.__assetPrefix__ = '<%= assetPrefix %>';\n </script>\n ").concat(partials.head.join("\n"), "\n\n <!--<?- chunksMap.css ?>-->\n</head>\n\n<body>\n <noscript>\n We're sorry but react app doesn't work properly without JavaScript enabled. Please enable it to continue.\n </noscript>\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");
|
|
239
239
|
};
|
|
240
240
|
var routesForServer = function(param) {
|
|
241
|
-
var routes = param.routes
|
|
241
|
+
var routes = param.routes;
|
|
242
242
|
var loaders = [];
|
|
243
|
-
var loaderIndexFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "index.js");
|
|
244
243
|
var traverseRouteTree = function(route) {
|
|
245
244
|
var children;
|
|
246
245
|
if ("children" in route && route.children) {
|
|
@@ -290,18 +289,18 @@ var routesForServer = function(param) {
|
|
|
290
289
|
var importLoadersCode = "";
|
|
291
290
|
if (loaders.length > 0) {
|
|
292
291
|
importLoadersCode = loaders.map(function(loader, index2) {
|
|
293
|
-
return "import loader_".concat(index2, ' from "').concat(loader, '"');
|
|
292
|
+
return "import loader_".concat(index2, ' from "').concat(slash(loader), '"');
|
|
294
293
|
}).join("\n");
|
|
295
294
|
}
|
|
296
295
|
return "\n ".concat(importLoadersCode, "\n ").concat(routesCode, "\n ");
|
|
297
296
|
};
|
|
298
297
|
var fileSystemRoutes = function() {
|
|
299
298
|
var _ref = _asyncToGenerator(function(param) {
|
|
300
|
-
var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory,
|
|
299
|
+
var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, loadings, errors, loaders, loadersMap, loadersMapFile, importLazyCode, rootLayoutCode, componentLoaderPath, getDataLoaderPath, traverseRouteTree, routeComponentsCode, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, route, newRoute, component, finalRoute, importLoadingCode, importErrorComponentsCode, importLoadersCode, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, _value, key, loaderInfo;
|
|
301
300
|
return __generator(this, function(_state) {
|
|
302
301
|
switch(_state.label){
|
|
303
302
|
case 0:
|
|
304
|
-
routes = param.routes, ssrMode = param.ssrMode, nestedRoutesEntry = param.nestedRoutesEntry, entryName = param.entryName, internalDirectory = param.internalDirectory
|
|
303
|
+
routes = param.routes, ssrMode = param.ssrMode, nestedRoutesEntry = param.nestedRoutesEntry, entryName = param.entryName, internalDirectory = param.internalDirectory;
|
|
305
304
|
loadings = [];
|
|
306
305
|
errors = [];
|
|
307
306
|
loaders = [];
|
|
@@ -311,7 +310,9 @@ var fileSystemRoutes = function() {
|
|
|
311
310
|
rootLayoutCode = "";
|
|
312
311
|
componentLoaderPath = "";
|
|
313
312
|
getDataLoaderPath = function(loaderId) {
|
|
314
|
-
if (!ssrMode)
|
|
313
|
+
if (!ssrMode) {
|
|
314
|
+
return "";
|
|
315
|
+
}
|
|
315
316
|
var dataLoaderPath = require.resolve("@modern-js/plugin-data-loader/loader");
|
|
316
317
|
if (nestedRoutesEntry) {
|
|
317
318
|
dataLoaderPath = "".concat(slash(dataLoaderPath), "?mapFile=").concat(slash(loadersMapFile), "&loaderId=").concat(loaderId, "!");
|
|
@@ -422,9 +423,9 @@ var fileSystemRoutes = function() {
|
|
|
422
423
|
for(_iterator1 = Object.entries(loadersMap)[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
423
424
|
_value = _slicedToArray(_step1.value, 2), key = _value[0], loaderInfo = _value[1];
|
|
424
425
|
if (loaderInfo.inline) {
|
|
425
|
-
importLoadersCode += "import { loader as ".concat(key, ' } from "').concat(getDataLoaderPath(key)).concat(loaderInfo.filePath, '";\n');
|
|
426
|
+
importLoadersCode += "import { loader as ".concat(key, ' } from "').concat(getDataLoaderPath(key)).concat(slash(loaderInfo.filePath), '";\n');
|
|
426
427
|
} else {
|
|
427
|
-
importLoadersCode += "import ".concat(key, ' from "').concat(getDataLoaderPath(key)).concat(loaderInfo.filePath, '";\n');
|
|
428
|
+
importLoadersCode += "import ".concat(key, ' from "').concat(getDataLoaderPath(key)).concat(slash(loaderInfo.filePath), '";\n');
|
|
428
429
|
}
|
|
429
430
|
}
|
|
430
431
|
} catch (err) {
|
|
@@ -185,7 +185,7 @@ import path from "path";
|
|
|
185
185
|
import { isReact18, normalizeToPosixPath, fs as fse } from "@modern-js/utils";
|
|
186
186
|
import { transform } from "esbuild";
|
|
187
187
|
import { parse } from "es-module-lexer";
|
|
188
|
-
import { FILE_SYSTEM_ROUTES_FILE_NAME, JS_EXTENSIONS, LOADER_EXPORT_NAME
|
|
188
|
+
import { FILE_SYSTEM_ROUTES_FILE_NAME, JS_EXTENSIONS, LOADER_EXPORT_NAME } from "./constants";
|
|
189
189
|
var walkDirectory = function(dir) {
|
|
190
190
|
return fs.readdirSync(dir).reduce(function(previous, filename) {
|
|
191
191
|
var filePath = path.join(dir, filename);
|
|
@@ -286,15 +286,6 @@ var isPageComponentFile = function(filePath) {
|
|
|
286
286
|
}
|
|
287
287
|
return false;
|
|
288
288
|
};
|
|
289
|
-
var isNestedRouteComponent = function(nestedRouteEntries, absoluteFilePath) {
|
|
290
|
-
var reg = new RegExp("(".concat(NESTED_ROUTE.LAYOUT_FILE, "|").concat(NESTED_ROUTE.PAGE_FILE, ")\\.tsx?$"));
|
|
291
|
-
return nestedRouteEntries.some(function(nestedRoutesEntry) {
|
|
292
|
-
if (absoluteFilePath.includes(nestedRoutesEntry) && reg.test(absoluteFilePath)) {
|
|
293
|
-
return true;
|
|
294
|
-
}
|
|
295
|
-
return false;
|
|
296
|
-
});
|
|
297
|
-
};
|
|
298
289
|
var replaceWithAlias = function(base, filePath, alias) {
|
|
299
290
|
return normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
|
|
300
291
|
};
|
|
@@ -380,4 +371,4 @@ var hasLoader = function() {
|
|
|
380
371
|
var getServerLoadersFile = function(internalDirectory, entryName) {
|
|
381
372
|
return path.join(internalDirectory, entryName, "route-server-loaders.js");
|
|
382
373
|
};
|
|
383
|
-
export { getDefaultImports, getServerLoadersFile, hasLoader,
|
|
374
|
+
export { getDefaultImports, getServerLoadersFile, hasLoader, isPageComponentFile, parseModule, replaceWithAlias, walkDirectory };
|
|
@@ -264,7 +264,6 @@ function createBuilderProviderConfig(normalizedConfig, appContext) {
|
|
|
264
264
|
cleanDistPath: false
|
|
265
265
|
});
|
|
266
266
|
};
|
|
267
|
-
var ref;
|
|
268
267
|
var output = createOutputConfig(normalizedConfig, appContext);
|
|
269
268
|
var htmlConfig = _objectSpread({}, normalizedConfig.html);
|
|
270
269
|
if (!htmlConfig.template) {
|
|
@@ -273,7 +272,7 @@ function createBuilderProviderConfig(normalizedConfig, appContext) {
|
|
|
273
272
|
return _objectSpreadProps(_objectSpread({}, normalizedConfig), {
|
|
274
273
|
output: output,
|
|
275
274
|
dev: _objectSpreadProps(_objectSpread({}, normalizedConfig.dev), {
|
|
276
|
-
port:
|
|
275
|
+
port: appContext.port
|
|
277
276
|
}),
|
|
278
277
|
html: htmlConfig
|
|
279
278
|
});
|
|
@@ -53,7 +53,9 @@ function _objectSpreadProps(target, source) {
|
|
|
53
53
|
import { createDefaultConfig as createDefaultBuilderConfig } from "@modern-js/builder-webpack-provider";
|
|
54
54
|
function createDefaultConfig(appContext) {
|
|
55
55
|
var defaultBuilderConfig = createDefaultBuilderConfig();
|
|
56
|
-
var dev = _objectSpread({}, defaultBuilderConfig.dev)
|
|
56
|
+
var dev = _objectSpreadProps(_objectSpread({}, defaultBuilderConfig.dev), {
|
|
57
|
+
port: void 0
|
|
58
|
+
});
|
|
57
59
|
var tools = _objectSpread({}, defaultBuilderConfig.tools);
|
|
58
60
|
var output = _objectSpreadProps(_objectSpread({}, defaultBuilderConfig.output), {
|
|
59
61
|
disableNodePolyfill: true
|
|
@@ -199,7 +199,7 @@ var initialize_default = function() {
|
|
|
199
199
|
resolvedConfig: function resolvedConfig(param) {
|
|
200
200
|
var resolved = param.resolved;
|
|
201
201
|
return _asyncToGenerator(function() {
|
|
202
|
-
var ref,
|
|
202
|
+
var ref, appContext, userConfig, port, normalizedConfig;
|
|
203
203
|
return __generator(this, function(_state) {
|
|
204
204
|
switch(_state.label){
|
|
205
205
|
case 0:
|
|
@@ -207,7 +207,7 @@ var initialize_default = function() {
|
|
|
207
207
|
userConfig = api.useConfigContext();
|
|
208
208
|
return [
|
|
209
209
|
4,
|
|
210
|
-
|
|
210
|
+
getServerPort(resolved)
|
|
211
211
|
];
|
|
212
212
|
case 1:
|
|
213
213
|
port = _state.sent();
|
|
@@ -224,7 +224,7 @@ var initialize_default = function() {
|
|
|
224
224
|
_raw: userConfig,
|
|
225
225
|
source: normalizedConfig.source || {},
|
|
226
226
|
server: _objectSpreadProps(_objectSpread({}, normalizedConfig.server || {}), {
|
|
227
|
-
port: port
|
|
227
|
+
port: port
|
|
228
228
|
}),
|
|
229
229
|
bff: normalizedConfig.bff || {},
|
|
230
230
|
dev: normalizedConfig.dev || {},
|
|
@@ -252,49 +252,26 @@ var initialize_default = function() {
|
|
|
252
252
|
}
|
|
253
253
|
};
|
|
254
254
|
};
|
|
255
|
-
function
|
|
256
|
-
return
|
|
255
|
+
function getServerPort(config) {
|
|
256
|
+
return _getServerPort.apply(this, arguments);
|
|
257
257
|
}
|
|
258
|
-
function
|
|
259
|
-
|
|
260
|
-
var
|
|
258
|
+
function _getServerPort() {
|
|
259
|
+
_getServerPort = _asyncToGenerator(function(config) {
|
|
260
|
+
var prodPort;
|
|
261
261
|
return __generator(this, function(_state) {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
if (!(((_port = appContext.port) !== null && _port !== void 0 ? _port : 0) > 0)) return [
|
|
269
|
-
3,
|
|
270
|
-
1
|
|
271
|
-
];
|
|
272
|
-
_tmp = appContext.port;
|
|
273
|
-
return [
|
|
274
|
-
3,
|
|
275
|
-
3
|
|
276
|
-
];
|
|
277
|
-
case 1:
|
|
278
|
-
return [
|
|
279
|
-
4,
|
|
280
|
-
getPort(resolved.server.port || 8080)
|
|
281
|
-
];
|
|
282
|
-
case 2:
|
|
283
|
-
_tmp = _state.sent();
|
|
284
|
-
_state.label = 3;
|
|
285
|
-
case 3:
|
|
286
|
-
return [
|
|
287
|
-
2,
|
|
288
|
-
_tmp
|
|
289
|
-
];
|
|
290
|
-
case 4:
|
|
291
|
-
return [
|
|
292
|
-
2,
|
|
293
|
-
resolved.server.port
|
|
294
|
-
];
|
|
262
|
+
prodPort = config.server.port || 8080;
|
|
263
|
+
if (isDev() && isDevCommand()) {
|
|
264
|
+
return [
|
|
265
|
+
2,
|
|
266
|
+
getPort(config.dev.port || prodPort)
|
|
267
|
+
];
|
|
295
268
|
}
|
|
269
|
+
return [
|
|
270
|
+
2,
|
|
271
|
+
prodPort
|
|
272
|
+
];
|
|
296
273
|
});
|
|
297
274
|
});
|
|
298
|
-
return
|
|
275
|
+
return _getServerPort.apply(this, arguments);
|
|
299
276
|
}
|
|
300
277
|
export { initialize_default as default };
|
|
@@ -25,6 +25,6 @@ export declare const NESTED_ROUTE: {
|
|
|
25
25
|
ERROR_FILE: string;
|
|
26
26
|
LOADER_FILE: string;
|
|
27
27
|
};
|
|
28
|
-
export declare const APP_CONFIG_NAME = "
|
|
28
|
+
export declare const APP_CONFIG_NAME = "config";
|
|
29
29
|
export declare const APP_INIT_EXPORTED = "init";
|
|
30
30
|
export declare const APP_INIT_IMPORTED = "appInit";
|
|
@@ -26,26 +26,20 @@ export declare const html: (partials: {
|
|
|
26
26
|
body: string[];
|
|
27
27
|
}) => string;
|
|
28
28
|
export declare const routesForServer: ({
|
|
29
|
-
routes
|
|
30
|
-
internalDirectory,
|
|
31
|
-
entryName
|
|
29
|
+
routes
|
|
32
30
|
}: {
|
|
33
31
|
routes: (NestedRoute | PageRoute)[];
|
|
34
|
-
internalDirectory: string;
|
|
35
|
-
entryName: string;
|
|
36
32
|
}) => string;
|
|
37
33
|
export declare const fileSystemRoutes: ({
|
|
38
34
|
routes,
|
|
39
35
|
ssrMode,
|
|
40
36
|
nestedRoutesEntry,
|
|
41
37
|
entryName,
|
|
42
|
-
internalDirectory
|
|
43
|
-
internalDirAlias
|
|
38
|
+
internalDirectory
|
|
44
39
|
}: {
|
|
45
40
|
routes: RouteLegacy[] | (NestedRoute | PageRoute)[];
|
|
46
41
|
ssrMode: 'string' | 'stream' | false;
|
|
47
42
|
nestedRoutesEntry?: string | undefined;
|
|
48
43
|
entryName: string;
|
|
49
44
|
internalDirectory: string;
|
|
50
|
-
internalDirAlias: string;
|
|
51
45
|
}) => Promise<string>;
|
|
@@ -15,7 +15,6 @@ export declare const getDefaultImports: ({
|
|
|
15
15
|
internalDirectory: string;
|
|
16
16
|
}) => ImportStatement[];
|
|
17
17
|
export declare const isPageComponentFile: (filePath: string) => boolean;
|
|
18
|
-
export declare const isNestedRouteComponent: (nestedRouteEntries: string[], absoluteFilePath: string) => boolean;
|
|
19
18
|
export declare const replaceWithAlias: (base: string, filePath: string, alias: string) => string;
|
|
20
19
|
export declare const parseModule: ({
|
|
21
20
|
source,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BuilderConfig } from '@modern-js/builder-webpack-provider';
|
|
2
2
|
type BuilderDevConfig = Required<BuilderConfig>['dev'];
|
|
3
3
|
export type DevProxyOptions = string | Record<string, string>;
|
|
4
|
-
export interface DevUserConfig extends
|
|
4
|
+
export interface DevUserConfig extends BuilderDevConfig {
|
|
5
5
|
/**
|
|
6
6
|
* The configuration of `dev.proxy` is provided by `proxy` plugin.
|
|
7
7
|
* Please use `yarn new` or `pnpm new` to enable the corresponding capability.
|
package/lib/types.d.ts
CHANGED
|
@@ -98,8 +98,12 @@ declare module '*.svg?inline' {
|
|
|
98
98
|
React.SVGProps<SVGSVGElement>
|
|
99
99
|
>;
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
/**
|
|
102
|
+
* The default export type depends on the svgDefaultExport config,
|
|
103
|
+
* it can be a string or a ReactComponent
|
|
104
|
+
* */
|
|
105
|
+
const content: any;
|
|
106
|
+
export default content;
|
|
103
107
|
}
|
|
104
108
|
|
|
105
109
|
declare module '*.bmp?url' {
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.
|
|
14
|
+
"version": "2.1.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -63,37 +63,37 @@
|
|
|
63
63
|
"@babel/runtime": "^7.18.0",
|
|
64
64
|
"@babel/traverse": "^7.18.0",
|
|
65
65
|
"@babel/types": "^7.18.0",
|
|
66
|
-
"@modern-js/builder": "2.0.2",
|
|
67
|
-
"@modern-js/builder-plugin-esbuild": "2.0.2",
|
|
68
|
-
"@modern-js/builder-plugin-node-polyfill": "2.0.2",
|
|
69
|
-
"@modern-js/builder-shared": "2.0.2",
|
|
70
|
-
"@modern-js/builder-webpack-provider": "2.0.2",
|
|
71
|
-
"@modern-js/core": "2.0.2",
|
|
72
|
-
"@modern-js/new-action": "2.0.2",
|
|
73
|
-
"@modern-js/node-bundle-require": "2.0.2",
|
|
74
|
-
"@modern-js/plugin": "2.0.2",
|
|
75
|
-
"@modern-js/plugin-data-loader": "2.0.3-alpha.0",
|
|
76
|
-
"@modern-js/plugin-i18n": "2.0.2",
|
|
77
|
-
"@modern-js/plugin-lint": "2.0.2",
|
|
78
|
-
"@modern-js/prod-server": "2.0.2",
|
|
79
|
-
"@modern-js/server": "2.0.2",
|
|
80
|
-
"@modern-js/types": "2.0.2",
|
|
81
|
-
"@modern-js/upgrade": "2.0.2",
|
|
82
|
-
"@modern-js/utils": "2.0.2",
|
|
83
66
|
"es-module-lexer": "^1.1.0",
|
|
84
|
-
"esbuild": "0.15.7"
|
|
67
|
+
"esbuild": "0.15.7",
|
|
68
|
+
"@modern-js/builder": "2.1.0",
|
|
69
|
+
"@modern-js/builder-plugin-esbuild": "2.1.0",
|
|
70
|
+
"@modern-js/builder-plugin-node-polyfill": "2.1.0",
|
|
71
|
+
"@modern-js/builder-shared": "2.1.0",
|
|
72
|
+
"@modern-js/builder-webpack-provider": "2.1.0",
|
|
73
|
+
"@modern-js/core": "2.1.0",
|
|
74
|
+
"@modern-js/new-action": "2.1.0",
|
|
75
|
+
"@modern-js/node-bundle-require": "2.1.0",
|
|
76
|
+
"@modern-js/plugin": "2.1.0",
|
|
77
|
+
"@modern-js/plugin-data-loader": "2.1.0",
|
|
78
|
+
"@modern-js/plugin-i18n": "2.1.0",
|
|
79
|
+
"@modern-js/plugin-lint": "2.1.0",
|
|
80
|
+
"@modern-js/prod-server": "2.1.0",
|
|
81
|
+
"@modern-js/server": "2.1.0",
|
|
82
|
+
"@modern-js/types": "2.1.0",
|
|
83
|
+
"@modern-js/upgrade": "2.1.0",
|
|
84
|
+
"@modern-js/utils": "2.1.0"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
|
-
"@modern-js/builder-plugin-swc": "2.0.2",
|
|
88
|
-
"@modern-js/server-core": "2.0.2",
|
|
89
|
-
"@scripts/build": "2.0.2",
|
|
90
|
-
"@scripts/jest-config": "2.0.2",
|
|
91
87
|
"@types/babel__traverse": "^7.14.2",
|
|
92
88
|
"@types/jest": "^27",
|
|
93
89
|
"@types/node": "^14",
|
|
94
90
|
"jest": "^27",
|
|
95
91
|
"typescript": "^4",
|
|
96
|
-
"webpack": "^5.75.0"
|
|
92
|
+
"webpack": "^5.75.0",
|
|
93
|
+
"@modern-js/builder-plugin-swc": "2.1.0",
|
|
94
|
+
"@modern-js/server-core": "2.1.0",
|
|
95
|
+
"@scripts/build": "2.1.0",
|
|
96
|
+
"@scripts/jest-config": "2.1.0"
|
|
97
97
|
},
|
|
98
98
|
"sideEffects": false,
|
|
99
99
|
"publishConfig": {
|