@modern-js/app-tools 2.0.0-beta.0 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +181 -0
- package/dist/js/modern/analyze/generateCode.js +29 -37
- package/dist/js/modern/analyze/getBundleEntry.js +4 -12
- package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +5 -30
- package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +5 -30
- package/dist/js/modern/analyze/getClientRoutes/utils.js +0 -3
- package/dist/js/modern/analyze/getFileSystemEntry.js +4 -17
- package/dist/js/modern/analyze/getHtmlTemplate.js +2 -9
- package/dist/js/modern/analyze/getServerRoutes.js +15 -32
- package/dist/js/modern/analyze/index.js +79 -22
- package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -4
- package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -2
- package/dist/js/modern/analyze/nestedRoutes.js +8 -33
- package/dist/js/modern/analyze/templates.js +22 -37
- package/dist/js/modern/analyze/utils.js +0 -7
- package/dist/js/modern/builder/builderPlugins/compatModern.js +30 -48
- package/dist/js/modern/builder/createHtmlConfig.js +2 -2
- package/dist/js/modern/builder/createOutputConfig.js +7 -4
- package/dist/js/modern/builder/createSourceConfig.js +0 -11
- package/dist/js/modern/builder/createToolsConfig.js +3 -10
- package/dist/js/modern/builder/index.js +24 -22
- package/dist/js/modern/builder/share.js +0 -4
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -8
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +2 -13
- package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +97 -0
- package/dist/js/modern/commands/build.js +6 -46
- package/dist/js/modern/commands/dev.js +4 -16
- package/dist/js/modern/commands/inspect.js +3 -20
- package/dist/js/modern/commands/start.js +0 -2
- package/dist/js/modern/index.js +6 -15
- package/dist/js/modern/utils/config.js +1 -12
- package/dist/js/modern/utils/createServer.js +0 -5
- package/dist/js/modern/utils/getSpecifiedEntries.js +0 -6
- package/dist/js/modern/utils/printInstructions.js +2 -1
- package/dist/js/modern/utils/routes.js +0 -2
- package/dist/js/node/analyze/generateCode.js +29 -60
- package/dist/js/node/analyze/getBundleEntry.js +4 -18
- package/dist/js/node/analyze/getClientRoutes/getRoutes.js +5 -45
- package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +5 -45
- package/dist/js/node/analyze/getClientRoutes/index.js +0 -2
- package/dist/js/node/analyze/getClientRoutes/utils.js +0 -14
- package/dist/js/node/analyze/getFileSystemEntry.js +4 -25
- package/dist/js/node/analyze/getHtmlTemplate.js +2 -23
- package/dist/js/node/analyze/getServerRoutes.js +14 -40
- package/dist/js/node/analyze/index.js +79 -32
- package/dist/js/node/analyze/isDefaultExportFunction.js +0 -12
- package/dist/js/node/analyze/makeLegalIdentifier.js +0 -4
- package/dist/js/node/analyze/nestedRoutes.js +8 -41
- package/dist/js/node/analyze/templates.js +22 -47
- package/dist/js/node/analyze/utils.js +0 -20
- package/dist/js/node/builder/builderPlugins/compatModern.js +30 -59
- package/dist/js/node/builder/createHtmlConfig.js +2 -10
- package/dist/js/node/builder/createOutputConfig.js +7 -6
- package/dist/js/node/builder/createSourceConfig.js +0 -17
- package/dist/js/node/builder/createToolsConfig.js +3 -12
- package/dist/js/node/builder/index.js +24 -36
- package/dist/js/node/builder/share.js +0 -12
- package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -10
- package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +2 -15
- package/dist/js/node/builder/webpackPlugins/routerPlugin.js +105 -0
- package/dist/js/node/commands/build.js +4 -57
- package/dist/js/node/commands/deploy.js +0 -2
- package/dist/js/node/commands/dev.js +3 -27
- package/dist/js/node/commands/index.js +0 -6
- package/dist/js/node/commands/inspect.js +3 -27
- package/dist/js/node/commands/start.js +0 -11
- package/dist/js/node/exports/server.js +0 -1
- package/dist/js/node/hooks.js +0 -2
- package/dist/js/node/index.js +7 -34
- package/dist/js/node/locale/index.js +0 -4
- package/dist/js/node/utils/commands.js +0 -2
- package/dist/js/node/utils/config.js +1 -25
- package/dist/js/node/utils/createServer.js +0 -15
- package/dist/js/node/utils/getSpecifiedEntries.js +0 -9
- package/dist/js/node/utils/language.js +0 -2
- package/dist/js/node/utils/printInstructions.js +2 -5
- package/dist/js/node/utils/routes.js +0 -5
- package/dist/js/treeshaking/analyze/generateCode.js +57 -100
- package/dist/js/treeshaking/analyze/getBundleEntry.js +11 -19
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +16 -42
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +16 -42
- package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +0 -3
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +4 -17
- package/dist/js/treeshaking/analyze/getHtmlTemplate.js +2 -26
- package/dist/js/treeshaking/analyze/getServerRoutes.js +24 -37
- package/dist/js/treeshaking/analyze/index.js +185 -65
- package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +0 -4
- package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +0 -2
- package/dist/js/treeshaking/analyze/nestedRoutes.js +9 -51
- package/dist/js/treeshaking/analyze/templates.js +31 -50
- package/dist/js/treeshaking/analyze/utils.js +7 -14
- package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +40 -59
- package/dist/js/treeshaking/builder/createHtmlConfig.js +15 -15
- package/dist/js/treeshaking/builder/createOutputConfig.js +26 -23
- package/dist/js/treeshaking/builder/createSourceConfig.js +7 -19
- package/dist/js/treeshaking/builder/createToolsConfig.js +16 -21
- package/dist/js/treeshaking/builder/index.js +38 -49
- package/dist/js/treeshaking/builder/share.js +0 -4
- package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +1 -13
- package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +2 -14
- package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +121 -0
- package/dist/js/treeshaking/commands/build.js +26 -111
- package/dist/js/treeshaking/commands/deploy.js +0 -3
- package/dist/js/treeshaking/commands/dev.js +13 -35
- package/dist/js/treeshaking/commands/inspect.js +5 -28
- package/dist/js/treeshaking/commands/start.js +0 -9
- package/dist/js/treeshaking/index.js +2 -39
- package/dist/js/treeshaking/utils/config.js +1 -17
- package/dist/js/treeshaking/utils/createServer.js +0 -10
- package/dist/js/treeshaking/utils/getSpecifiedEntries.js +0 -10
- package/dist/js/treeshaking/utils/printInstructions.js +0 -5
- package/dist/js/treeshaking/utils/routes.js +0 -4
- package/dist/types/analyze/index.d.ts +2 -3
- package/dist/types/analyze/nestedRoutes.d.ts +1 -1
- package/dist/types/analyze/templates.d.ts +3 -1
- package/dist/types/builder/builderPlugins/compatModern.d.ts +0 -1
- package/dist/types/builder/index.d.ts +2 -6
- package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +10 -0
- package/dist/types/commands/inspect.d.ts +1 -4
- package/dist/types/index.d.ts +0 -2
- package/dist/types/utils/config.d.ts +0 -1
- package/package.json +23 -22
- package/dist/js/modern/utils/createCompiler.js +0 -58
- package/dist/js/node/utils/createCompiler.js +0 -75
- package/dist/js/treeshaking/utils/createCompiler.js +0 -117
- package/dist/types/utils/createCompiler.d.ts +0 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,186 @@
|
|
|
1
1
|
# @modern-js/app-tools
|
|
2
2
|
|
|
3
|
+
## 2.0.0-beta.1
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- dda38c9: chore: v2
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- edd1cfb1af: feat: modernjs Access builder compiler
|
|
12
|
+
feat: modernjs 接入 builder 构建
|
|
13
|
+
- 543be9558e: feat: compile server loader and support handle loader request
|
|
14
|
+
feat: 编译 server loader 并支持处理 loader 的请求
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- c9f912ca4d: feat(app-tools): improve build logs of dev and build command
|
|
19
|
+
|
|
20
|
+
feat(app-tools): 优化 dev 和 build 过程中的日志展示
|
|
21
|
+
|
|
22
|
+
- 103973cde9: fix: builder tools.webpackChain config args not match the Modernjs tools.webpackChain
|
|
23
|
+
fix: builder tools.webpackChain 配置传参无法匹配 Modernjs tools.webpackChain
|
|
24
|
+
- 0b2d1ef02b: fix: repeat register `babel-plugin-lodash`
|
|
25
|
+
fix: 重复注册 `babel-plugin-lodash`
|
|
26
|
+
- 82cef85ed7: fix: specify builder compiler framework
|
|
27
|
+
fix: 指明 builder 构建时框架
|
|
28
|
+
- 3e57f2b: feat: add document feature with plugin
|
|
29
|
+
|
|
30
|
+
feat: 增加 document 功能插件
|
|
31
|
+
|
|
32
|
+
- 85edee888c: feat(app-tools): support tools.htmlPlugin config
|
|
33
|
+
|
|
34
|
+
feat(app-tools): 支持 tools.htmlPlugin 配置项
|
|
35
|
+
|
|
36
|
+
- 5402fdb: feat(Builder): add output.disableTsChecker config
|
|
37
|
+
|
|
38
|
+
feat(Builder): 新增 output.disableTsChecker 配置项
|
|
39
|
+
|
|
40
|
+
- dc8eeb9cbb: fix: clear distDirectory in prepare hook & inject data loader plugin to server
|
|
41
|
+
fix: 在 prepare hook 中清理 dist 目录,并且向 server 中注入 data loader plugin
|
|
42
|
+
- cc971eabfc: refactor: move server plugin load logic in `@modern-js/core`
|
|
43
|
+
refactor:移除在 `@modern-js/core` 中的 server 插件加载逻辑
|
|
44
|
+
- 5b9049f: feat: inject async js chunk when streaming ssr
|
|
45
|
+
feat: streaming ssr 时, 注入 async 类型的 js chunk
|
|
46
|
+
- d4a4566: chore: rename plugin-jarvis to plugin-lint
|
|
47
|
+
|
|
48
|
+
chore: 重命名 plugin-jarvis 为 plugin-lint
|
|
49
|
+
|
|
50
|
+
- 6bda14ed71: feat: refactor router with react-router@6.4
|
|
51
|
+
|
|
52
|
+
feat: 使用 react-router@6.4 重构路由模块
|
|
53
|
+
|
|
54
|
+
- d36c6ee126: fix(app-tools): failed to run inspect command
|
|
55
|
+
|
|
56
|
+
fix(app-tools): 修复运行 inspect 命令失败的问题
|
|
57
|
+
|
|
58
|
+
- 92004d1: feat: support load chunks parallelly
|
|
59
|
+
feat: 支持并行加载 chunks
|
|
60
|
+
- b8bbe036c7: feat: change type logic
|
|
61
|
+
feat: 修改类型相关的逻辑
|
|
62
|
+
- 40ed587: feat: inject css chunk into html for streaming ssr
|
|
63
|
+
feat: streaming ssr 返回的 html 注入 css chunk
|
|
64
|
+
- af4422d: feat(builder): complete utils of tools.webpack
|
|
65
|
+
|
|
66
|
+
feat(builder): 补全 tools.webpack 提供的 utils 方法
|
|
67
|
+
|
|
68
|
+
- 87c1ff8: feat(app-tools): attach builder instance to appContext
|
|
69
|
+
|
|
70
|
+
feat(app-tools): 将 builder 实例挂载到 appContext 上
|
|
71
|
+
|
|
72
|
+
- c258e34202: fix: add builder hooks `beforeBuild` params
|
|
73
|
+
fix: 新增 builder hooks `beforeBuild` 的参数
|
|
74
|
+
- 8b8e1bb571: feat: support nested routes
|
|
75
|
+
feat: 支持嵌套路由
|
|
76
|
+
- 7de97ae: fix: `deploy` command has't load `builder` instance
|
|
77
|
+
fix: `deploy` 命令没有加载 builder 实例
|
|
78
|
+
- c3b7de4: fix(app-tools): dev.assetPrefix not work
|
|
79
|
+
|
|
80
|
+
fix(app-tools): 修复 dev.assetPrefix 配置项不生效的问题
|
|
81
|
+
|
|
82
|
+
- 92004d1: fix: use loadable lazy instead of loadable
|
|
83
|
+
fix: 使用 loadable lazy 组件替代 loadable
|
|
84
|
+
- c677befc22: fix(app-tools): compat legacy resolve behavior
|
|
85
|
+
|
|
86
|
+
fix(app-tools): 兼容旧版本 node_modules 解析逻辑
|
|
87
|
+
|
|
88
|
+
- 3f7cde5caa: fix: builder plugin setup can't get config
|
|
89
|
+
fix: builder 插件在 setup 阶段无法拿到 config
|
|
90
|
+
- 99213e4bae: fix: process does't exit when exec command
|
|
91
|
+
fix: 修复执行命令时进程未退出的问题
|
|
92
|
+
- b16fd96: fix: `modern-js/app-tools` pass error config to builder.
|
|
93
|
+
fix: `modern-js/app-tools` 传递错误的 config 给 builder.
|
|
94
|
+
- 7eefedd7ca: fix: add html-webpack-plugin `__internal__` options, for bottom template
|
|
95
|
+
fix: 为了 bottom template, 增加 `html-webpack-plugin` `__internal__` 配置项,
|
|
96
|
+
- 14b712d: fix: use consistent alias type and default value across packages
|
|
97
|
+
|
|
98
|
+
fix: 在各个包中使用一致的 alias 类型定义和默认值
|
|
99
|
+
|
|
100
|
+
- Updated dependencies [c9f912ca4d]
|
|
101
|
+
- Updated dependencies [95be7cc49c]
|
|
102
|
+
- Updated dependencies [e439457a51]
|
|
103
|
+
- Updated dependencies [4d1545f8c0]
|
|
104
|
+
- Updated dependencies [2bc090c089]
|
|
105
|
+
- Updated dependencies [f96a725211]
|
|
106
|
+
- Updated dependencies [828f42f9ce]
|
|
107
|
+
- Updated dependencies [c745686]
|
|
108
|
+
- Updated dependencies [c9e800d39a]
|
|
109
|
+
- Updated dependencies [0ff846f]
|
|
110
|
+
- Updated dependencies [57077b2]
|
|
111
|
+
- Updated dependencies [d032d49]
|
|
112
|
+
- Updated dependencies [2ff6167]
|
|
113
|
+
- Updated dependencies [287f298990]
|
|
114
|
+
- Updated dependencies [15bf09d9c8]
|
|
115
|
+
- Updated dependencies [423188db70]
|
|
116
|
+
- Updated dependencies [fd2d652]
|
|
117
|
+
- Updated dependencies [0c2d8dae31]
|
|
118
|
+
- Updated dependencies [2edad29]
|
|
119
|
+
- Updated dependencies [85edee888c]
|
|
120
|
+
- Updated dependencies [a2509bfbdb]
|
|
121
|
+
- Updated dependencies [3998875791]
|
|
122
|
+
- Updated dependencies [3998875791]
|
|
123
|
+
- Updated dependencies [ba86b8b711]
|
|
124
|
+
- Updated dependencies [61f21d1e77]
|
|
125
|
+
- Updated dependencies [5402fdb]
|
|
126
|
+
- Updated dependencies [2ae58176fe]
|
|
127
|
+
- Updated dependencies [92f0ead]
|
|
128
|
+
- Updated dependencies [edd1cfb1af]
|
|
129
|
+
- Updated dependencies [5d67c26]
|
|
130
|
+
- Updated dependencies [cc971eabfc]
|
|
131
|
+
- Updated dependencies [5b9049f]
|
|
132
|
+
- Updated dependencies [d4a4566]
|
|
133
|
+
- Updated dependencies [18360a38d7]
|
|
134
|
+
- Updated dependencies [6bda14ed71]
|
|
135
|
+
- Updated dependencies [0b314e6946]
|
|
136
|
+
- Updated dependencies [92004d1]
|
|
137
|
+
- Updated dependencies [b8bbe036c7]
|
|
138
|
+
- Updated dependencies [40ed587]
|
|
139
|
+
- Updated dependencies [af4422d]
|
|
140
|
+
- Updated dependencies [87c1ff8]
|
|
141
|
+
- Updated dependencies [d5a31df781]
|
|
142
|
+
- Updated dependencies [dda38c9]
|
|
143
|
+
- Updated dependencies [102d32e4ba]
|
|
144
|
+
- Updated dependencies [c258e34202]
|
|
145
|
+
- Updated dependencies [7248342e4d]
|
|
146
|
+
- Updated dependencies [568eab1e42]
|
|
147
|
+
- Updated dependencies [8b8e1bb571]
|
|
148
|
+
- Updated dependencies [3bbea92b2a]
|
|
149
|
+
- Updated dependencies [ae71096d45]
|
|
150
|
+
- Updated dependencies [73cd29dd9f]
|
|
151
|
+
- Updated dependencies [a23010138d]
|
|
152
|
+
- Updated dependencies [75d1b2657c]
|
|
153
|
+
- Updated dependencies [18aaf42]
|
|
154
|
+
- Updated dependencies [f179749]
|
|
155
|
+
- Updated dependencies [3fae2d0]
|
|
156
|
+
- Updated dependencies [8a6d45f]
|
|
157
|
+
- Updated dependencies [ebbeed1]
|
|
158
|
+
- Updated dependencies [90e2879520]
|
|
159
|
+
- Updated dependencies [df41d71]
|
|
160
|
+
- Updated dependencies [f727e5c6cc]
|
|
161
|
+
- Updated dependencies [5e3cecd523]
|
|
162
|
+
- Updated dependencies [abf3421]
|
|
163
|
+
- Updated dependencies [da2d1fc3c2]
|
|
164
|
+
- Updated dependencies [543be9558e]
|
|
165
|
+
- Updated dependencies [14b712d]
|
|
166
|
+
- @modern-js/builder-webpack-provider@2.0.0-beta.1
|
|
167
|
+
- @modern-js/builder-shared@2.0.0-beta.1
|
|
168
|
+
- @modern-js/core@2.0.0-beta.1
|
|
169
|
+
- @modern-js/prod-server@2.0.0-beta.1
|
|
170
|
+
- @modern-js/builder-plugin-esbuild@2.0.0-beta.1
|
|
171
|
+
- @modern-js/server@2.0.0-beta.1
|
|
172
|
+
- @modern-js/node-bundle-require@2.0.0-beta.1
|
|
173
|
+
- @modern-js/utils@2.0.0-beta.1
|
|
174
|
+
- @modern-js/builder-plugin-node-polyfill@2.0.0-beta.1
|
|
175
|
+
- @modern-js/types@2.0.0-beta.1
|
|
176
|
+
- @modern-js/plugin-lint@2.0.0-beta.1
|
|
177
|
+
- @modern-js/plugin@2.0.0-beta.1
|
|
178
|
+
- @modern-js/builder@2.0.0-beta.1
|
|
179
|
+
- @modern-js/plugin-data-loader@2.0.0-beta.1
|
|
180
|
+
- @modern-js/plugin-i18n@2.0.0-beta.1
|
|
181
|
+
- @modern-js/new-action@2.0.0-beta.1
|
|
182
|
+
- @modern-js/upgrade@2.0.0-beta.1
|
|
183
|
+
|
|
3
184
|
## 2.0.0-beta.0
|
|
4
185
|
|
|
5
186
|
### Major Changes
|
|
@@ -8,11 +8,9 @@ import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
|
|
|
8
8
|
import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME } from "./constants";
|
|
9
9
|
import { getDefaultImports } from "./utils";
|
|
10
10
|
import { walk } from "./nestedRoutes";
|
|
11
|
-
|
|
12
11
|
const createImportSpecifier = specifiers => {
|
|
13
12
|
let defaults = '';
|
|
14
13
|
const named = [];
|
|
15
|
-
|
|
16
14
|
for (const {
|
|
17
15
|
local,
|
|
18
16
|
imported
|
|
@@ -25,7 +23,6 @@ const createImportSpecifier = specifiers => {
|
|
|
25
23
|
named.push(imported);
|
|
26
24
|
}
|
|
27
25
|
}
|
|
28
|
-
|
|
29
26
|
if (defaults && named.length) {
|
|
30
27
|
return `${defaults}, { ${named.join(', ')} }`;
|
|
31
28
|
} else if (defaults) {
|
|
@@ -34,12 +31,10 @@ const createImportSpecifier = specifiers => {
|
|
|
34
31
|
return `{ ${named.join(', ')} }`;
|
|
35
32
|
}
|
|
36
33
|
};
|
|
37
|
-
|
|
38
34
|
export const createImportStatements = statements => {
|
|
39
35
|
// merge import statements with the same value.
|
|
40
36
|
const deDuplicated = [];
|
|
41
37
|
const seen = new Map();
|
|
42
|
-
|
|
43
38
|
for (const {
|
|
44
39
|
value,
|
|
45
40
|
specifiers,
|
|
@@ -54,22 +49,19 @@ export const createImportStatements = statements => {
|
|
|
54
49
|
seen.set(value, specifiers);
|
|
55
50
|
} else {
|
|
56
51
|
var _deDuplicated$modifyI, _deDuplicated$modifyI2;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
seen.get(value).push(...specifiers);
|
|
53
|
+
// make "initialize" param can be connected when multiple plugins were imported from same package
|
|
60
54
|
const modifyIndex = deDuplicated.findIndex(v => v.value === value);
|
|
61
55
|
const originInitialize = (_deDuplicated$modifyI = (_deDuplicated$modifyI2 = deDuplicated[modifyIndex]) === null || _deDuplicated$modifyI2 === void 0 ? void 0 : _deDuplicated$modifyI2.initialize) !== null && _deDuplicated$modifyI !== void 0 ? _deDuplicated$modifyI : '';
|
|
62
56
|
deDuplicated[modifyIndex].initialize = originInitialize.concat(`\n${initialize || ''}`);
|
|
63
57
|
}
|
|
64
58
|
}
|
|
65
|
-
|
|
66
59
|
return deDuplicated.map(({
|
|
67
60
|
value,
|
|
68
61
|
specifiers,
|
|
69
62
|
initialize
|
|
70
63
|
}) => `import ${createImportSpecifier(specifiers)} from '${value}';\n${initialize || ''}`).join('\n');
|
|
71
64
|
};
|
|
72
|
-
|
|
73
65
|
const buildLoader = async (entry, outfile) => {
|
|
74
66
|
const loader = {
|
|
75
67
|
'.js': 'jsx',
|
|
@@ -89,32 +81,27 @@ const buildLoader = async (entry, outfile) => {
|
|
|
89
81
|
outfile,
|
|
90
82
|
plugins: [{
|
|
91
83
|
name: 'make-all-packages-external',
|
|
92
|
-
|
|
93
84
|
setup(build) {
|
|
94
85
|
// https://github.com/evanw/esbuild/issues/619#issuecomment-751995294
|
|
95
86
|
build.onResolve({
|
|
96
87
|
filter: EXTERNAL_REGEXP
|
|
97
88
|
}, args => {
|
|
98
|
-
let external = true;
|
|
99
|
-
|
|
89
|
+
let external = true;
|
|
90
|
+
// FIXME: windows external entrypoint
|
|
100
91
|
if (args.kind === 'entry-point') {
|
|
101
92
|
external = false;
|
|
102
93
|
}
|
|
103
|
-
|
|
104
94
|
return {
|
|
105
95
|
path: args.path,
|
|
106
96
|
external
|
|
107
97
|
};
|
|
108
98
|
});
|
|
109
99
|
}
|
|
110
|
-
|
|
111
100
|
}]
|
|
112
101
|
});
|
|
113
102
|
};
|
|
114
|
-
|
|
115
103
|
export const generateCode = async (appContext, config, entrypoints, api) => {
|
|
116
104
|
var _config$runtime, _config$runtime$route;
|
|
117
|
-
|
|
118
105
|
const {
|
|
119
106
|
internalDirectory,
|
|
120
107
|
distDirectory,
|
|
@@ -129,7 +116,6 @@ export const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
129
116
|
} = config.output;
|
|
130
117
|
const getRoutes = islegacy ? getClientRoutesLegacy : getClientRoutes;
|
|
131
118
|
await Promise.all(entrypoints.map(generateEntryCode));
|
|
132
|
-
|
|
133
119
|
async function generateEntryCode(entrypoint) {
|
|
134
120
|
const {
|
|
135
121
|
entryName,
|
|
@@ -137,13 +123,11 @@ export const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
137
123
|
customBootstrap,
|
|
138
124
|
fileSystemRoutes
|
|
139
125
|
} = entrypoint;
|
|
140
|
-
|
|
141
126
|
if (isAutoMount) {
|
|
142
127
|
// generate routes file for file system routes entrypoint.
|
|
143
128
|
if (fileSystemRoutes) {
|
|
144
129
|
let initialRoutes = [];
|
|
145
130
|
let nestedRoute = null;
|
|
146
|
-
|
|
147
131
|
if (entrypoint.entry) {
|
|
148
132
|
initialRoutes = getRoutes({
|
|
149
133
|
entrypoint,
|
|
@@ -153,24 +137,21 @@ export const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
153
137
|
internalDirAlias
|
|
154
138
|
});
|
|
155
139
|
}
|
|
156
|
-
|
|
157
140
|
if (entrypoint.nestedRoutesEntry) {
|
|
158
141
|
if (!islegacy) {
|
|
159
142
|
nestedRoute = await walk(entrypoint.nestedRoutesEntry, entrypoint.nestedRoutesEntry, {
|
|
160
143
|
name: internalSrcAlias,
|
|
161
144
|
basename: srcDirectory
|
|
162
|
-
});
|
|
163
|
-
|
|
145
|
+
}, entrypoint.entryName);
|
|
164
146
|
if (nestedRoute) {
|
|
165
147
|
initialRoutes.unshift(nestedRoute);
|
|
166
148
|
}
|
|
167
149
|
} else {
|
|
168
|
-
logger.error('Nested routes is not supported in legacy mode.');
|
|
169
|
-
|
|
150
|
+
logger.error('Nested routes is not supported in legacy mode.');
|
|
151
|
+
// eslint-disable-next-line no-process-exit
|
|
170
152
|
process.exit(1);
|
|
171
153
|
}
|
|
172
154
|
}
|
|
173
|
-
|
|
174
155
|
const {
|
|
175
156
|
routes
|
|
176
157
|
} = await hookRunners.modifyFileSystemRoutes({
|
|
@@ -180,13 +161,19 @@ export const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
180
161
|
const config = useResolvedConfigContext();
|
|
181
162
|
const ssr = config === null || config === void 0 ? void 0 : config.server.ssr;
|
|
182
163
|
let mode;
|
|
183
|
-
|
|
184
164
|
if (ssr) {
|
|
185
165
|
mode = typeof ssr === 'object' ? ssr.mode || 'string' : 'string';
|
|
186
166
|
} else {
|
|
187
167
|
mode = false;
|
|
188
168
|
}
|
|
189
|
-
|
|
169
|
+
if (mode === 'stream') {
|
|
170
|
+
const hasPageRoute = routes.some(route => 'type' in route && route.type === 'page');
|
|
171
|
+
if (hasPageRoute) {
|
|
172
|
+
logger.error('streaming ssr is not supported when pages dir exists');
|
|
173
|
+
// eslint-disable-next-line no-process-exit
|
|
174
|
+
process.exit(1);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
190
177
|
const {
|
|
191
178
|
code
|
|
192
179
|
} = await hookRunners.beforeGenerateRoutes({
|
|
@@ -194,10 +181,12 @@ export const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
194
181
|
code: templates.fileSystemRoutes({
|
|
195
182
|
routes,
|
|
196
183
|
ssrMode: mode,
|
|
197
|
-
nestedRoutesEntry: entrypoint.nestedRoutesEntry
|
|
184
|
+
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
185
|
+
entryName: entrypoint.entryName
|
|
198
186
|
})
|
|
199
|
-
});
|
|
187
|
+
});
|
|
200
188
|
|
|
189
|
+
// extract nested router loaders
|
|
201
190
|
if (entrypoint.nestedRoutesEntry) {
|
|
202
191
|
const routesServerFile = path.join(internalDirectory, entryName, 'routes.server.js');
|
|
203
192
|
const outputRoutesServerFile = path.join(distDirectory, 'loader-routes', entryName, 'index.js');
|
|
@@ -212,11 +201,10 @@ export const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
212
201
|
await fs.writeFile(routesServerFile, code);
|
|
213
202
|
await buildLoader(routesServerFile, outputRoutesServerFile);
|
|
214
203
|
}
|
|
215
|
-
|
|
216
204
|
fs.outputFileSync(path.resolve(internalDirectory, `./${entryName}/${FILE_SYSTEM_ROUTES_FILE_NAME}`), code, 'utf8');
|
|
217
|
-
}
|
|
218
|
-
|
|
205
|
+
}
|
|
219
206
|
|
|
207
|
+
// call modifyEntryImports hook
|
|
220
208
|
const {
|
|
221
209
|
imports: importStatements
|
|
222
210
|
} = await hookRunners.modifyEntryImports({
|
|
@@ -228,15 +216,17 @@ export const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
228
216
|
internalDirAlias,
|
|
229
217
|
internalDirectory
|
|
230
218
|
})
|
|
231
|
-
});
|
|
219
|
+
});
|
|
232
220
|
|
|
221
|
+
// call modifyEntryRuntimePlugins hook
|
|
233
222
|
const {
|
|
234
223
|
plugins
|
|
235
224
|
} = await hookRunners.modifyEntryRuntimePlugins({
|
|
236
225
|
entrypoint,
|
|
237
226
|
plugins: []
|
|
238
|
-
});
|
|
227
|
+
});
|
|
239
228
|
|
|
229
|
+
// call modifyEntryRenderFunction hook
|
|
240
230
|
const {
|
|
241
231
|
code: renderFunction
|
|
242
232
|
} = await hookRunners.modifyEntryRenderFunction({
|
|
@@ -246,8 +236,9 @@ export const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
246
236
|
customBootstrap,
|
|
247
237
|
fileSystemRoutes
|
|
248
238
|
})
|
|
249
|
-
});
|
|
239
|
+
});
|
|
250
240
|
|
|
241
|
+
// call modifyEntryExport hook
|
|
251
242
|
const {
|
|
252
243
|
exportStatement
|
|
253
244
|
} = await hookRunners.modifyEntryExport({
|
|
@@ -261,8 +252,9 @@ export const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
261
252
|
exportStatement
|
|
262
253
|
});
|
|
263
254
|
const entryFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_POINT_FILE_NAME}`);
|
|
264
|
-
entrypoint.entry = entryFile;
|
|
255
|
+
entrypoint.entry = entryFile;
|
|
265
256
|
|
|
257
|
+
// generate entry file.
|
|
266
258
|
if (config.source.enableAsyncEntry) {
|
|
267
259
|
const {
|
|
268
260
|
code: asyncEntryCode
|
|
@@ -2,30 +2,24 @@ import path from 'path';
|
|
|
2
2
|
import { ensureAbsolutePath, fs, findExists, MAIN_ENTRY_NAME } from '@modern-js/utils';
|
|
3
3
|
import { getFileSystemEntry } from "./getFileSystemEntry";
|
|
4
4
|
import { JS_EXTENSIONS } from "./constants";
|
|
5
|
-
|
|
6
5
|
const ensureExtensions = file => {
|
|
7
6
|
if (!path.extname(file)) {
|
|
8
7
|
return findExists(JS_EXTENSIONS.map(ext => `${file}${ext}`)) || file;
|
|
9
8
|
}
|
|
10
|
-
|
|
11
9
|
return file;
|
|
12
10
|
};
|
|
13
|
-
|
|
14
11
|
const ifAlreadyExists = (entrypoints, checked) => entrypoints.some(entrypoint => {
|
|
15
12
|
if (ensureExtensions(entrypoint.entry) === ensureExtensions(checked.entry)) {
|
|
16
13
|
// reset entryName
|
|
17
14
|
checked.entryName = entrypoint.entryName;
|
|
18
15
|
return true;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
}
|
|
17
|
+
// filesystem routes entrypoint conflict with normal entrypoint.
|
|
22
18
|
if (entrypoint.entry.startsWith(checked.entry) || checked.entry.startsWith(entrypoint.entry)) {
|
|
23
19
|
throw new Error(`Entry configuration conflicts\n Your configuration: ${checked.entry}.\n Default entrypoint: ${entrypoint.entry}\n Please reset source.entries or set source.disableDefaultEntries to disable the default entry rules.`);
|
|
24
20
|
}
|
|
25
|
-
|
|
26
21
|
return false;
|
|
27
22
|
});
|
|
28
|
-
|
|
29
23
|
export const getBundleEntry = (appContext, config) => {
|
|
30
24
|
const {
|
|
31
25
|
appDirectory,
|
|
@@ -38,8 +32,9 @@ export const getBundleEntry = (appContext, config) => {
|
|
|
38
32
|
entriesDir
|
|
39
33
|
}
|
|
40
34
|
} = config;
|
|
41
|
-
const defaults = disableDefaultEntries ? [] : getFileSystemEntry(appContext, config);
|
|
35
|
+
const defaults = disableDefaultEntries ? [] : getFileSystemEntry(appContext, config);
|
|
42
36
|
|
|
37
|
+
// merge entrypoints from user config with directory convention.
|
|
43
38
|
if (entries) {
|
|
44
39
|
Object.keys(entries).forEach(name => {
|
|
45
40
|
const value = entries[name];
|
|
@@ -54,13 +49,11 @@ export const getBundleEntry = (appContext, config) => {
|
|
|
54
49
|
isAutoMount: !value.disableMount,
|
|
55
50
|
fileSystemRoutes: value.enableFileSystemRoutes ? {} : undefined
|
|
56
51
|
};
|
|
57
|
-
|
|
58
52
|
if (!ifAlreadyExists(defaults, entrypoint)) {
|
|
59
53
|
defaults.push(entrypoint);
|
|
60
54
|
}
|
|
61
55
|
});
|
|
62
56
|
}
|
|
63
|
-
|
|
64
57
|
if (!disableDefaultEntries) {
|
|
65
58
|
// find main entry point which server route is '/'.
|
|
66
59
|
const entriesDirAbs = ensureAbsolutePath(appDirectory, entriesDir);
|
|
@@ -71,6 +64,5 @@ export const getBundleEntry = (appContext, config) => {
|
|
|
71
64
|
}) => entryName === packageName || path.dirname(entry) === entriesDirAbs || path.dirname(_nestedRoutesEntry) === entriesDirAbs);
|
|
72
65
|
found && (found.entryName = MAIN_ENTRY_NAME);
|
|
73
66
|
}
|
|
74
|
-
|
|
75
67
|
return defaults;
|
|
76
68
|
};
|
|
@@ -1,30 +1,24 @@
|
|
|
1
1
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
|
|
3
2
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
|
|
5
3
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
|
|
7
4
|
import path from 'path';
|
|
8
5
|
import { fs } from '@modern-js/utils';
|
|
9
6
|
import { makeLegalIdentifier } from "../makeLegalIdentifier";
|
|
10
7
|
import { FILE_SYSTEM_ROUTES_COMPONENTS_DIR, FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP, FILE_SYSTEM_ROUTES_INDEX, FILE_SYSTEM_ROUTES_LAYOUT } from "../constants";
|
|
11
8
|
import { replaceWithAlias } from "../utils";
|
|
12
9
|
import { debug, findLayout, shouldSkip, getRouteWeight } from "./utils";
|
|
13
|
-
|
|
14
10
|
const compName = (srcDirectory, filePath) => {
|
|
15
11
|
const legalCompName = makeLegalIdentifier(path.relative(srcDirectory, filePath));
|
|
16
12
|
return `Comp_${legalCompName}`;
|
|
17
13
|
};
|
|
18
|
-
|
|
19
14
|
const layoutNameAbbr = filePath => {
|
|
20
15
|
const prefix = 'L_';
|
|
21
16
|
const dirName = path.dirname(filePath).split('/').pop() || '';
|
|
22
17
|
return `${prefix}${makeLegalIdentifier(dirName)}`;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
const parents = [];
|
|
26
|
-
/* eslint-disable no-param-reassign */
|
|
27
20
|
|
|
21
|
+
/* eslint-disable no-param-reassign */
|
|
28
22
|
const recursiveReadDir = ({
|
|
29
23
|
dir,
|
|
30
24
|
routes,
|
|
@@ -36,7 +30,6 @@ const recursiveReadDir = ({
|
|
|
36
30
|
let resetParent = false;
|
|
37
31
|
let parent = parents[parents.length - 1];
|
|
38
32
|
const layout = findLayout(dir);
|
|
39
|
-
|
|
40
33
|
if (layout) {
|
|
41
34
|
if (_basePath === '/') {
|
|
42
35
|
throw new Error(`should use _app instead of _layout in ${dir}`);
|
|
@@ -58,16 +51,13 @@ const recursiveReadDir = ({
|
|
|
58
51
|
routes = route.children;
|
|
59
52
|
}
|
|
60
53
|
}
|
|
61
|
-
|
|
62
54
|
for (const relative of fs.readdirSync(dir)) {
|
|
63
55
|
const filePath = path.join(dir, relative);
|
|
64
|
-
|
|
65
56
|
if (!shouldSkip(filePath)) {
|
|
66
57
|
const filename = path.basename(filePath, path.extname(filePath));
|
|
67
58
|
const alias = replaceWithAlias(srcDirectory, filePath, srcAlias);
|
|
68
59
|
const componentName = compName(srcDirectory, filePath);
|
|
69
60
|
const dynamicRouteMatched = FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP.exec(filename);
|
|
70
|
-
|
|
71
61
|
if (dynamicRouteMatched) {
|
|
72
62
|
if (hasDynamicRoute) {
|
|
73
63
|
throw new Error(`Can't set two dynamic route in one directory: ${dir}`);
|
|
@@ -75,7 +65,6 @@ const recursiveReadDir = ({
|
|
|
75
65
|
hasDynamicRoute = true;
|
|
76
66
|
}
|
|
77
67
|
}
|
|
78
|
-
|
|
79
68
|
const route = {
|
|
80
69
|
path: `${_basePath}${dynamicRouteMatched ? `:${dynamicRouteMatched[1]}${dynamicRouteMatched[2]}` : filename}`,
|
|
81
70
|
_component: alias,
|
|
@@ -83,7 +72,6 @@ const recursiveReadDir = ({
|
|
|
83
72
|
parent,
|
|
84
73
|
type: 'page'
|
|
85
74
|
};
|
|
86
|
-
|
|
87
75
|
if (fs.statSync(filePath).isDirectory()) {
|
|
88
76
|
recursiveReadDir({
|
|
89
77
|
dir: filePath,
|
|
@@ -94,38 +82,32 @@ const recursiveReadDir = ({
|
|
|
94
82
|
});
|
|
95
83
|
continue;
|
|
96
84
|
}
|
|
97
|
-
|
|
98
85
|
if (filename === FILE_SYSTEM_ROUTES_LAYOUT) {
|
|
99
86
|
continue;
|
|
100
87
|
}
|
|
101
|
-
|
|
102
88
|
if (filename === FILE_SYSTEM_ROUTES_INDEX) {
|
|
103
89
|
route.path = _basePath === '/' ? _basePath : `${_basePath.substring(0, _basePath.length - 1)}`;
|
|
104
90
|
}
|
|
105
|
-
|
|
106
91
|
if (filename === '404' && _basePath === '/') {
|
|
107
92
|
route.path = '*';
|
|
108
93
|
}
|
|
109
|
-
|
|
110
94
|
routes.push(route);
|
|
111
95
|
}
|
|
112
96
|
}
|
|
113
|
-
|
|
114
97
|
if (resetParent) {
|
|
115
98
|
parents.pop();
|
|
116
99
|
}
|
|
117
100
|
};
|
|
118
101
|
/* eslint-enable no-param-reassign */
|
|
119
102
|
|
|
120
|
-
|
|
121
103
|
const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory, internalDirAlias) => {
|
|
122
104
|
const flat = routes => routes.reduce((memo, route) => memo.concat(Array.isArray(route.children) ? flat(route.children) : [route]), []);
|
|
123
|
-
|
|
124
105
|
const generate = route => {
|
|
125
106
|
const codes = [];
|
|
126
107
|
let lastComponent = route.component;
|
|
127
|
-
const imports = [`import React from 'react';`, `import ${lastComponent} from '${route._component}'`];
|
|
108
|
+
const imports = [`import React from 'react';`, `import ${lastComponent} from '${route._component}'`];
|
|
128
109
|
|
|
110
|
+
// eslint-disable-next-line no-param-reassign, no-cond-assign
|
|
129
111
|
while (route = route.parent) {
|
|
130
112
|
const layoutComponent = route.component;
|
|
131
113
|
const layoutComponentAbbr = layoutNameAbbr(route._component);
|
|
@@ -134,7 +116,6 @@ const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory,
|
|
|
134
116
|
codes.push(`const ${currentComponent} = props => <${layoutComponent} Component={${lastComponent}} {...props} />;`);
|
|
135
117
|
lastComponent = currentComponent;
|
|
136
118
|
}
|
|
137
|
-
|
|
138
119
|
const file = path.resolve(internalComponentsDir, `${lastComponent}.jsx`);
|
|
139
120
|
fs.outputFileSync(file, `${imports.join('\n')}\n${codes.join('\n')}\nexport default ${lastComponent}`);
|
|
140
121
|
return {
|
|
@@ -142,7 +123,6 @@ const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory,
|
|
|
142
123
|
_component: replaceWithAlias(internalDirectory, file, internalDirAlias)
|
|
143
124
|
};
|
|
144
125
|
};
|
|
145
|
-
|
|
146
126
|
const normalized = flat(nested).map(route => route.parent ? _objectSpread(_objectSpread(_objectSpread({}, route), generate(route)), {}, {
|
|
147
127
|
parent: undefined
|
|
148
128
|
}) : _objectSpread(_objectSpread({}, route), {}, {
|
|
@@ -150,7 +130,6 @@ const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory,
|
|
|
150
130
|
}));
|
|
151
131
|
return normalized;
|
|
152
132
|
};
|
|
153
|
-
|
|
154
133
|
export const getClientRoutes = ({
|
|
155
134
|
entrypoint,
|
|
156
135
|
srcDirectory,
|
|
@@ -162,15 +141,12 @@ export const getClientRoutes = ({
|
|
|
162
141
|
entry,
|
|
163
142
|
entryName
|
|
164
143
|
} = entrypoint;
|
|
165
|
-
|
|
166
144
|
if (!fs.existsSync(entry)) {
|
|
167
145
|
throw new Error(`generate file system routes error, ${entry} directory not found.`);
|
|
168
146
|
}
|
|
169
|
-
|
|
170
147
|
if (!(fs.existsSync(entry) && fs.statSync(entry).isDirectory())) {
|
|
171
148
|
throw new Error(`generate file system routes error, ${entry} should be directory.`);
|
|
172
149
|
}
|
|
173
|
-
|
|
174
150
|
let routes = [];
|
|
175
151
|
recursiveReadDir({
|
|
176
152
|
dir: entry,
|
|
@@ -182,15 +158,14 @@ export const getClientRoutes = ({
|
|
|
182
158
|
const internalComponentsDir = path.resolve(internalDirectory, `${entryName}/${FILE_SYSTEM_ROUTES_COMPONENTS_DIR}`);
|
|
183
159
|
fs.emptyDirSync(internalComponentsDir);
|
|
184
160
|
routes = normalizeNestedRoutes(routes, internalComponentsDir, internalDirectory, internalDirAlias);
|
|
185
|
-
parents.length = 0;
|
|
161
|
+
parents.length = 0;
|
|
186
162
|
|
|
163
|
+
// FIXME: support more situations
|
|
187
164
|
routes.sort((a, b) => {
|
|
188
165
|
const delta = getRouteWeight(a.path) - getRouteWeight(b.path);
|
|
189
|
-
|
|
190
166
|
if (delta === 0) {
|
|
191
167
|
return a.path.length - b.path.length;
|
|
192
168
|
}
|
|
193
|
-
|
|
194
169
|
return delta;
|
|
195
170
|
});
|
|
196
171
|
debug(`fileSystem routes: %o`, routes);
|