@modern-js/app-tools 1.15.0 → 1.18.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 +101 -0
- package/dist/js/modern/analyze/constants.js +1 -0
- package/dist/js/modern/analyze/generateCode.js +19 -6
- package/dist/js/modern/analyze/index.js +5 -1
- package/dist/js/modern/analyze/templates.js +4 -1
- package/dist/js/modern/analyze/utils.js +8 -2
- package/dist/js/modern/commands/start.js +3 -1
- package/dist/js/modern/index.js +3 -1
- package/dist/js/node/analyze/constants.js +3 -1
- package/dist/js/node/analyze/generateCode.js +20 -4
- package/dist/js/node/analyze/index.js +7 -2
- package/dist/js/node/analyze/templates.js +4 -1
- package/dist/js/node/analyze/utils.js +7 -1
- package/dist/js/node/commands/start.js +3 -1
- package/dist/js/node/index.js +3 -0
- package/dist/types/analyze/constants.d.ts +1 -0
- package/dist/types/analyze/index.d.ts +4 -0
- package/dist/types/analyze/utils.d.ts +3 -1
- package/package.json +16 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,106 @@
|
|
|
1
1
|
# @modern-js/app-tools
|
|
2
2
|
|
|
3
|
+
## 1.18.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 66ad36f: feat: add source.enableAsyncEntry config
|
|
8
|
+
|
|
9
|
+
feat: 新增 source.enableAsyncEntry 配置项
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [8280920]
|
|
12
|
+
- Updated dependencies [3d5e3a5]
|
|
13
|
+
- Updated dependencies [8280920]
|
|
14
|
+
- Updated dependencies [2b7406d]
|
|
15
|
+
- Updated dependencies [9f13d8c]
|
|
16
|
+
- Updated dependencies [fc7214d]
|
|
17
|
+
- Updated dependencies [60a2e3a]
|
|
18
|
+
- Updated dependencies [5227370]
|
|
19
|
+
- Updated dependencies [66ad36f]
|
|
20
|
+
- Updated dependencies [7928bae]
|
|
21
|
+
- @modern-js/utils@1.18.0
|
|
22
|
+
- @modern-js/prod-server@1.18.0
|
|
23
|
+
- @modern-js/server@1.18.0
|
|
24
|
+
- @modern-js/upgrade@1.18.0
|
|
25
|
+
- @modern-js/core@1.18.0
|
|
26
|
+
- @modern-js/plugin-i18n@1.18.0
|
|
27
|
+
- @modern-js/plugin-jarvis@1.18.0
|
|
28
|
+
- @modern-js/webpack@1.18.0
|
|
29
|
+
- @modern-js/new-action@1.18.0
|
|
30
|
+
- @modern-js/node-bundle-require@1.18.0
|
|
31
|
+
- @modern-js/plugin@1.18.0
|
|
32
|
+
- @modern-js/types@1.18.0
|
|
33
|
+
|
|
34
|
+
## 1.17.0
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- fb30bca: feat: add upgrade tools and command
|
|
39
|
+
|
|
40
|
+
feat: 增加升级工具和升级命令
|
|
41
|
+
|
|
42
|
+
- c3d4a6a: feat: support react 18 ssr
|
|
43
|
+
feat: 支持 React 18 下使用 SSR
|
|
44
|
+
- Updated dependencies [1b9176f]
|
|
45
|
+
- Updated dependencies [77d3a38]
|
|
46
|
+
- Updated dependencies [fb30bca]
|
|
47
|
+
- Updated dependencies [f3fab28]
|
|
48
|
+
- Updated dependencies [151329d]
|
|
49
|
+
- Updated dependencies [367405a]
|
|
50
|
+
- Updated dependencies [5af9472]
|
|
51
|
+
- Updated dependencies [6b6a534]
|
|
52
|
+
- Updated dependencies [6b43a2b]
|
|
53
|
+
- Updated dependencies [9f4e5ce]
|
|
54
|
+
- Updated dependencies [58c53a7]
|
|
55
|
+
- Updated dependencies [a7be124]
|
|
56
|
+
- Updated dependencies [31547b4]
|
|
57
|
+
- @modern-js/utils@1.17.0
|
|
58
|
+
- @modern-js/upgrade@1.17.0
|
|
59
|
+
- @modern-js/new-action@1.17.0
|
|
60
|
+
- @modern-js/webpack@1.17.0
|
|
61
|
+
- @modern-js/server@1.17.0
|
|
62
|
+
- @modern-js/core@1.17.0
|
|
63
|
+
- @modern-js/plugin-i18n@1.17.0
|
|
64
|
+
- @modern-js/plugin-jarvis@1.17.0
|
|
65
|
+
- @modern-js/prod-server@1.17.0
|
|
66
|
+
- @modern-js/node-bundle-require@1.17.0
|
|
67
|
+
- @modern-js/plugin@1.17.0
|
|
68
|
+
- @modern-js/types@1.17.0
|
|
69
|
+
|
|
70
|
+
## 1.16.0
|
|
71
|
+
|
|
72
|
+
### Minor Changes
|
|
73
|
+
|
|
74
|
+
- 1100dd58c: chore: support react 18
|
|
75
|
+
|
|
76
|
+
chore: 支持 React 18
|
|
77
|
+
|
|
78
|
+
### Patch Changes
|
|
79
|
+
|
|
80
|
+
- 3904b30a5: fix: check apiOnly while has source.entriesDir
|
|
81
|
+
|
|
82
|
+
fix: 当配置 source.entriesDir 存在时,apiOnly 检查错误
|
|
83
|
+
|
|
84
|
+
- Updated dependencies [641592f52]
|
|
85
|
+
- Updated dependencies [3904b30a5]
|
|
86
|
+
- Updated dependencies [1100dd58c]
|
|
87
|
+
- Updated dependencies [e04e6e76a]
|
|
88
|
+
- Updated dependencies [2808ff5a2]
|
|
89
|
+
- Updated dependencies [81c66e4a4]
|
|
90
|
+
- Updated dependencies [2c305b6f5]
|
|
91
|
+
- Updated dependencies [9d9bbfd05]
|
|
92
|
+
- @modern-js/utils@1.16.0
|
|
93
|
+
- @modern-js/webpack@1.16.0
|
|
94
|
+
- @modern-js/types@1.16.0
|
|
95
|
+
- @modern-js/server@1.16.0
|
|
96
|
+
- @modern-js/prod-server@1.16.0
|
|
97
|
+
- @modern-js/new-action@1.16.0
|
|
98
|
+
- @modern-js/core@1.16.0
|
|
99
|
+
- @modern-js/plugin-i18n@1.16.0
|
|
100
|
+
- @modern-js/plugin-jarvis@1.16.0
|
|
101
|
+
- @modern-js/node-bundle-require@1.16.0
|
|
102
|
+
- @modern-js/plugin@1.16.0
|
|
103
|
+
|
|
3
104
|
## 1.15.0
|
|
4
105
|
|
|
5
106
|
### Patch Changes
|
|
@@ -4,6 +4,7 @@ export const APP_FILE_NAME = 'App';
|
|
|
4
4
|
export const PAGES_DIR_NAME = 'pages';
|
|
5
5
|
export const FILE_SYSTEM_ROUTES_FILE_NAME = 'routes.js';
|
|
6
6
|
export const ENTRY_POINT_FILE_NAME = 'index.js';
|
|
7
|
+
export const ENTRY_BOOTSTRAP_FILE_NAME = 'bootstrap.js';
|
|
7
8
|
export const FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP = /^\[(\S+)\]([*+?]?)$/;
|
|
8
9
|
export const FILE_SYSTEM_ROUTES_LAYOUT = '_layout';
|
|
9
10
|
export const FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT = '_app';
|
|
@@ -2,7 +2,7 @@ import path from 'path';
|
|
|
2
2
|
import { fs } from '@modern-js/utils';
|
|
3
3
|
import * as templates from "./templates";
|
|
4
4
|
import { getClientRoutes } from "./getClientRoutes";
|
|
5
|
-
import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME } from "./constants";
|
|
5
|
+
import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME } from "./constants";
|
|
6
6
|
import { getDefaultImports } from "./utils";
|
|
7
7
|
|
|
8
8
|
const createImportSpecifier = specifiers => {
|
|
@@ -123,7 +123,8 @@ export const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
123
123
|
entrypoint,
|
|
124
124
|
srcDirectory,
|
|
125
125
|
internalSrcAlias,
|
|
126
|
-
internalDirAlias
|
|
126
|
+
internalDirAlias,
|
|
127
|
+
internalDirectory
|
|
127
128
|
})
|
|
128
129
|
}); // call modifyEntryRuntimePlugins hook
|
|
129
130
|
|
|
@@ -156,11 +157,23 @@ export const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
156
157
|
imports: createImportStatements(importStatements),
|
|
157
158
|
renderFunction,
|
|
158
159
|
exportStatement
|
|
159
|
-
});
|
|
160
|
-
|
|
160
|
+
});
|
|
161
161
|
const entryFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_POINT_FILE_NAME}`);
|
|
162
|
-
entrypoint.entry = entryFile;
|
|
163
|
-
|
|
162
|
+
entrypoint.entry = entryFile; // generate entry file.
|
|
163
|
+
|
|
164
|
+
if (config.source.enableAsyncEntry) {
|
|
165
|
+
const {
|
|
166
|
+
code: asyncEntryCode
|
|
167
|
+
} = await hookRunners.modifyAsyncEntry({
|
|
168
|
+
entrypoint,
|
|
169
|
+
code: `import('./${ENTRY_BOOTSTRAP_FILE_NAME}');`
|
|
170
|
+
});
|
|
171
|
+
fs.outputFileSync(entryFile, asyncEntryCode, 'utf8');
|
|
172
|
+
const bootstrapFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_BOOTSTRAP_FILE_NAME}`);
|
|
173
|
+
fs.outputFileSync(bootstrapFile, code, 'utf8');
|
|
174
|
+
} else {
|
|
175
|
+
fs.outputFileSync(entryFile, code, 'utf8');
|
|
176
|
+
}
|
|
164
177
|
}
|
|
165
178
|
}
|
|
166
179
|
};
|
|
@@ -15,6 +15,7 @@ export const modifyEntryExport = createAsyncWaterfall();
|
|
|
15
15
|
export const addRuntimeExports = createAsyncWaterfall();
|
|
16
16
|
export const modifyEntryRuntimePlugins = createAsyncWaterfall();
|
|
17
17
|
export const modifyEntryRenderFunction = createAsyncWaterfall();
|
|
18
|
+
export const modifyAsyncEntry = createAsyncWaterfall();
|
|
18
19
|
export const modifyFileSystemRoutes = createAsyncWaterfall();
|
|
19
20
|
export const modifyServerRoutes = createAsyncWaterfall();
|
|
20
21
|
export const htmlPartials = createAsyncWaterfall();
|
|
@@ -23,6 +24,7 @@ export const addDefineTypes = createAsyncWaterfall();
|
|
|
23
24
|
export default (() => ({
|
|
24
25
|
name: '@modern-js/plugin-analyze',
|
|
25
26
|
registerHook: {
|
|
27
|
+
modifyAsyncEntry,
|
|
26
28
|
modifyEntryImports,
|
|
27
29
|
modifyEntryExport,
|
|
28
30
|
modifyEntryRuntimePlugins,
|
|
@@ -39,6 +41,8 @@ export default (() => ({
|
|
|
39
41
|
let originEntrypoints = [];
|
|
40
42
|
return {
|
|
41
43
|
async prepare() {
|
|
44
|
+
var _resolvedConfig$sourc;
|
|
45
|
+
|
|
42
46
|
const appContext = api.useAppContext();
|
|
43
47
|
const resolvedConfig = api.useResolvedConfigContext();
|
|
44
48
|
const hookRunners = api.useHookRunners();
|
|
@@ -48,7 +52,7 @@ export default (() => ({
|
|
|
48
52
|
} catch (_unused) {// FIXME:
|
|
49
53
|
}
|
|
50
54
|
|
|
51
|
-
const apiOnly = await isApiOnly(appContext.appDirectory);
|
|
55
|
+
const apiOnly = await isApiOnly(appContext.appDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$sourc = resolvedConfig.source) === null || _resolvedConfig$sourc === void 0 ? void 0 : _resolvedConfig$sourc.entriesDir);
|
|
52
56
|
await hookRunners.addRuntimeExports();
|
|
53
57
|
|
|
54
58
|
if (apiOnly) {
|
|
@@ -5,12 +5,15 @@ export const index = ({
|
|
|
5
5
|
exportStatement
|
|
6
6
|
}) => `
|
|
7
7
|
const IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';
|
|
8
|
+
const IS_REACT18 = process.env.IS_REACT18 === 'true';
|
|
8
9
|
const MOUNT_ID = '${mountId}';
|
|
9
10
|
|
|
10
11
|
${imports}
|
|
11
12
|
|
|
12
13
|
let AppWrapper = null;
|
|
13
14
|
|
|
15
|
+
let root = null;
|
|
16
|
+
|
|
14
17
|
function render() {
|
|
15
18
|
${renderFunction}
|
|
16
19
|
}
|
|
@@ -35,7 +38,7 @@ export const renderFunction = ({
|
|
|
35
38
|
})(${fileSystemRoutes ? '' : `App`})
|
|
36
39
|
|
|
37
40
|
if (IS_BROWSER) {
|
|
38
|
-
${customBootstrap ? `customBootstrap(AppWrapper);` : `bootstrap(AppWrapper, MOUNT_ID);`}
|
|
41
|
+
${customBootstrap ? `customBootstrap(AppWrapper);` : `bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM);`}
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
return AppWrapper
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import path from 'path';
|
|
3
|
-
import { normalizeToPosixPath } from '@modern-js/utils';
|
|
3
|
+
import { isReact18, normalizeToPosixPath } from '@modern-js/utils';
|
|
4
4
|
import { FILE_SYSTEM_ROUTES_FILE_NAME } from "./constants";
|
|
5
5
|
export const walkDirectory = dir => fs.readdirSync(dir).reduce((previous, filename) => {
|
|
6
6
|
const filePath = path.join(dir, filename);
|
|
@@ -15,7 +15,8 @@ export const getDefaultImports = ({
|
|
|
15
15
|
entrypoint,
|
|
16
16
|
srcDirectory,
|
|
17
17
|
internalSrcAlias,
|
|
18
|
-
internalDirAlias
|
|
18
|
+
internalDirAlias,
|
|
19
|
+
internalDirectory
|
|
19
20
|
}) => {
|
|
20
21
|
const {
|
|
21
22
|
entryName,
|
|
@@ -28,6 +29,11 @@ export const getDefaultImports = ({
|
|
|
28
29
|
local: 'React'
|
|
29
30
|
}],
|
|
30
31
|
value: 'react'
|
|
32
|
+
}, {
|
|
33
|
+
specifiers: [{
|
|
34
|
+
local: 'ReactDOM'
|
|
35
|
+
}],
|
|
36
|
+
value: isReact18(path.join(internalDirectory, '../../')) ? 'react-dom/client' : 'react-dom'
|
|
31
37
|
}, {
|
|
32
38
|
specifiers: [{
|
|
33
39
|
imported: 'createApp'
|
|
@@ -2,6 +2,8 @@ import { logger, chalk, isApiOnly } from '@modern-js/utils';
|
|
|
2
2
|
import server from '@modern-js/prod-server';
|
|
3
3
|
import { printInstructions } from "../utils/printInstructions";
|
|
4
4
|
export const start = async api => {
|
|
5
|
+
var _userConfig$source;
|
|
6
|
+
|
|
5
7
|
const appContext = api.useAppContext();
|
|
6
8
|
const userConfig = api.useResolvedConfigContext();
|
|
7
9
|
const hookRunners = api.useHookRunners();
|
|
@@ -11,7 +13,7 @@ export const start = async api => {
|
|
|
11
13
|
serverConfigFile
|
|
12
14
|
} = appContext;
|
|
13
15
|
logger.log(chalk.cyan(`Starting the modern server...`));
|
|
14
|
-
const apiOnly = await isApiOnly(appContext.appDirectory);
|
|
16
|
+
const apiOnly = await isApiOnly(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$source = userConfig.source) === null || _userConfig$source === void 0 ? void 0 : _userConfig$source.entriesDir);
|
|
15
17
|
const app = await server({
|
|
16
18
|
pwd: appDirectory,
|
|
17
19
|
config: userConfig,
|
package/dist/js/modern/index.js
CHANGED
|
@@ -7,12 +7,13 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import { defineConfig, cli } from '@modern-js/core';
|
|
9
9
|
import LintPlugin from '@modern-js/plugin-jarvis';
|
|
10
|
-
import { cleanRequireCache } from '@modern-js/utils';
|
|
10
|
+
import { cleanRequireCache, Import } from '@modern-js/utils';
|
|
11
11
|
import AnalyzePlugin from "./analyze";
|
|
12
12
|
import { hooks } from "./hooks";
|
|
13
13
|
import { i18n, localeKeys } from "./locale";
|
|
14
14
|
import { getLocaleLanguage } from "./utils/language";
|
|
15
15
|
export { defineConfig };
|
|
16
|
+
const upgradeModel = Import.lazy('@modern-js/upgrade', require);
|
|
16
17
|
export default (() => ({
|
|
17
18
|
name: '@modern-js/app-tools',
|
|
18
19
|
post: ['@modern-js/plugin-analyze', '@modern-js/plugin-ssr', '@modern-js/plugin-state', '@modern-js/plugin-router', '@modern-js/plugin-polyfill'],
|
|
@@ -74,6 +75,7 @@ export default (() => ({
|
|
|
74
75
|
} = await import("./commands/inspect");
|
|
75
76
|
inspect(api, options);
|
|
76
77
|
});
|
|
78
|
+
upgradeModel.defineCommand(program.command('upgrade'));
|
|
77
79
|
},
|
|
78
80
|
|
|
79
81
|
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.PAGES_DIR_NAME = exports.JS_EXTENSIONS = exports.INDEX_FILE_NAME = exports.HTML_PARTIALS_FOLDER = exports.HTML_PARTIALS_EXTENSIONS = exports.FILE_SYSTEM_ROUTES_LAYOUT = exports.FILE_SYSTEM_ROUTES_INDEX = exports.FILE_SYSTEM_ROUTES_IGNORED_REGEX = exports.FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT = exports.FILE_SYSTEM_ROUTES_FILE_NAME = exports.FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP = exports.FILE_SYSTEM_ROUTES_COMPONENTS_DIR = exports.ENTRY_POINT_FILE_NAME = exports.APP_FILE_NAME = void 0;
|
|
6
|
+
exports.PAGES_DIR_NAME = exports.JS_EXTENSIONS = exports.INDEX_FILE_NAME = exports.HTML_PARTIALS_FOLDER = exports.HTML_PARTIALS_EXTENSIONS = exports.FILE_SYSTEM_ROUTES_LAYOUT = exports.FILE_SYSTEM_ROUTES_INDEX = exports.FILE_SYSTEM_ROUTES_IGNORED_REGEX = exports.FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT = exports.FILE_SYSTEM_ROUTES_FILE_NAME = exports.FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP = exports.FILE_SYSTEM_ROUTES_COMPONENTS_DIR = exports.ENTRY_POINT_FILE_NAME = exports.ENTRY_BOOTSTRAP_FILE_NAME = exports.APP_FILE_NAME = void 0;
|
|
7
7
|
const JS_EXTENSIONS = ['.js', '.ts', '.jsx', '.tsx'];
|
|
8
8
|
exports.JS_EXTENSIONS = JS_EXTENSIONS;
|
|
9
9
|
const INDEX_FILE_NAME = 'index';
|
|
@@ -16,6 +16,8 @@ const FILE_SYSTEM_ROUTES_FILE_NAME = 'routes.js';
|
|
|
16
16
|
exports.FILE_SYSTEM_ROUTES_FILE_NAME = FILE_SYSTEM_ROUTES_FILE_NAME;
|
|
17
17
|
const ENTRY_POINT_FILE_NAME = 'index.js';
|
|
18
18
|
exports.ENTRY_POINT_FILE_NAME = ENTRY_POINT_FILE_NAME;
|
|
19
|
+
const ENTRY_BOOTSTRAP_FILE_NAME = 'bootstrap.js';
|
|
20
|
+
exports.ENTRY_BOOTSTRAP_FILE_NAME = ENTRY_BOOTSTRAP_FILE_NAME;
|
|
19
21
|
const FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP = /^\[(\S+)\]([*+?]?)$/;
|
|
20
22
|
exports.FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP = FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP;
|
|
21
23
|
const FILE_SYSTEM_ROUTES_LAYOUT = '_layout';
|
|
@@ -145,7 +145,8 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
145
145
|
entrypoint,
|
|
146
146
|
srcDirectory,
|
|
147
147
|
internalSrcAlias,
|
|
148
|
-
internalDirAlias
|
|
148
|
+
internalDirAlias,
|
|
149
|
+
internalDirectory
|
|
149
150
|
})
|
|
150
151
|
}); // call modifyEntryRuntimePlugins hook
|
|
151
152
|
|
|
@@ -178,13 +179,28 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
178
179
|
imports: createImportStatements(importStatements),
|
|
179
180
|
renderFunction,
|
|
180
181
|
exportStatement
|
|
181
|
-
});
|
|
182
|
+
});
|
|
182
183
|
|
|
183
184
|
const entryFile = _path.default.resolve(internalDirectory, `./${entryName}/${_constants.ENTRY_POINT_FILE_NAME}`);
|
|
184
185
|
|
|
185
|
-
entrypoint.entry = entryFile;
|
|
186
|
+
entrypoint.entry = entryFile; // generate entry file.
|
|
187
|
+
|
|
188
|
+
if (config.source.enableAsyncEntry) {
|
|
189
|
+
const {
|
|
190
|
+
code: asyncEntryCode
|
|
191
|
+
} = await hookRunners.modifyAsyncEntry({
|
|
192
|
+
entrypoint,
|
|
193
|
+
code: `import('./${_constants.ENTRY_BOOTSTRAP_FILE_NAME}');`
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
_utils.fs.outputFileSync(entryFile, asyncEntryCode, 'utf8');
|
|
197
|
+
|
|
198
|
+
const bootstrapFile = _path.default.resolve(internalDirectory, `./${entryName}/${_constants.ENTRY_BOOTSTRAP_FILE_NAME}`);
|
|
186
199
|
|
|
187
|
-
|
|
200
|
+
_utils.fs.outputFileSync(bootstrapFile, code, 'utf8');
|
|
201
|
+
} else {
|
|
202
|
+
_utils.fs.outputFileSync(entryFile, code, 'utf8');
|
|
203
|
+
}
|
|
188
204
|
}
|
|
189
205
|
}
|
|
190
206
|
};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.modifyServerRoutes = exports.modifyFileSystemRoutes = exports.modifyEntryRuntimePlugins = exports.modifyEntryRenderFunction = exports.modifyEntryImports = exports.modifyEntryExport = exports.htmlPartials = exports.default = exports.beforeGenerateRoutes = exports.addRuntimeExports = exports.addDefineTypes = void 0;
|
|
6
|
+
exports.modifyServerRoutes = exports.modifyFileSystemRoutes = exports.modifyEntryRuntimePlugins = exports.modifyEntryRenderFunction = exports.modifyEntryImports = exports.modifyEntryExport = exports.modifyAsyncEntry = exports.htmlPartials = exports.default = exports.beforeGenerateRoutes = exports.addRuntimeExports = exports.addDefineTypes = void 0;
|
|
7
7
|
|
|
8
8
|
var path = _interopRequireWildcard(require("path"));
|
|
9
9
|
|
|
@@ -36,6 +36,8 @@ const modifyEntryRuntimePlugins = (0, _plugin.createAsyncWaterfall)();
|
|
|
36
36
|
exports.modifyEntryRuntimePlugins = modifyEntryRuntimePlugins;
|
|
37
37
|
const modifyEntryRenderFunction = (0, _plugin.createAsyncWaterfall)();
|
|
38
38
|
exports.modifyEntryRenderFunction = modifyEntryRenderFunction;
|
|
39
|
+
const modifyAsyncEntry = (0, _plugin.createAsyncWaterfall)();
|
|
40
|
+
exports.modifyAsyncEntry = modifyAsyncEntry;
|
|
39
41
|
const modifyFileSystemRoutes = (0, _plugin.createAsyncWaterfall)();
|
|
40
42
|
exports.modifyFileSystemRoutes = modifyFileSystemRoutes;
|
|
41
43
|
const modifyServerRoutes = (0, _plugin.createAsyncWaterfall)();
|
|
@@ -50,6 +52,7 @@ exports.addDefineTypes = addDefineTypes;
|
|
|
50
52
|
var _default = () => ({
|
|
51
53
|
name: '@modern-js/plugin-analyze',
|
|
52
54
|
registerHook: {
|
|
55
|
+
modifyAsyncEntry,
|
|
53
56
|
modifyEntryImports,
|
|
54
57
|
modifyEntryExport,
|
|
55
58
|
modifyEntryRuntimePlugins,
|
|
@@ -66,6 +69,8 @@ var _default = () => ({
|
|
|
66
69
|
let originEntrypoints = [];
|
|
67
70
|
return {
|
|
68
71
|
async prepare() {
|
|
72
|
+
var _resolvedConfig$sourc;
|
|
73
|
+
|
|
69
74
|
const appContext = api.useAppContext();
|
|
70
75
|
const resolvedConfig = api.useResolvedConfigContext();
|
|
71
76
|
const hookRunners = api.useHookRunners();
|
|
@@ -75,7 +80,7 @@ var _default = () => ({
|
|
|
75
80
|
} catch (_unused) {// FIXME:
|
|
76
81
|
}
|
|
77
82
|
|
|
78
|
-
const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory);
|
|
83
|
+
const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$sourc = resolvedConfig.source) === null || _resolvedConfig$sourc === void 0 ? void 0 : _resolvedConfig$sourc.entriesDir);
|
|
79
84
|
await hookRunners.addRuntimeExports();
|
|
80
85
|
|
|
81
86
|
if (apiOnly) {
|
|
@@ -12,12 +12,15 @@ const index = ({
|
|
|
12
12
|
exportStatement
|
|
13
13
|
}) => `
|
|
14
14
|
const IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';
|
|
15
|
+
const IS_REACT18 = process.env.IS_REACT18 === 'true';
|
|
15
16
|
const MOUNT_ID = '${mountId}';
|
|
16
17
|
|
|
17
18
|
${imports}
|
|
18
19
|
|
|
19
20
|
let AppWrapper = null;
|
|
20
21
|
|
|
22
|
+
let root = null;
|
|
23
|
+
|
|
21
24
|
function render() {
|
|
22
25
|
${renderFunction}
|
|
23
26
|
}
|
|
@@ -45,7 +48,7 @@ const renderFunction = ({
|
|
|
45
48
|
})(${fileSystemRoutes ? '' : `App`})
|
|
46
49
|
|
|
47
50
|
if (IS_BROWSER) {
|
|
48
|
-
${customBootstrap ? `customBootstrap(AppWrapper);` : `bootstrap(AppWrapper, MOUNT_ID);`}
|
|
51
|
+
${customBootstrap ? `customBootstrap(AppWrapper);` : `bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM);`}
|
|
49
52
|
}
|
|
50
53
|
|
|
51
54
|
return AppWrapper
|
|
@@ -31,7 +31,8 @@ const getDefaultImports = ({
|
|
|
31
31
|
entrypoint,
|
|
32
32
|
srcDirectory,
|
|
33
33
|
internalSrcAlias,
|
|
34
|
-
internalDirAlias
|
|
34
|
+
internalDirAlias,
|
|
35
|
+
internalDirectory
|
|
35
36
|
}) => {
|
|
36
37
|
const {
|
|
37
38
|
entryName,
|
|
@@ -44,6 +45,11 @@ const getDefaultImports = ({
|
|
|
44
45
|
local: 'React'
|
|
45
46
|
}],
|
|
46
47
|
value: 'react'
|
|
48
|
+
}, {
|
|
49
|
+
specifiers: [{
|
|
50
|
+
local: 'ReactDOM'
|
|
51
|
+
}],
|
|
52
|
+
value: (0, _utils.isReact18)(_path.default.join(internalDirectory, '../../')) ? 'react-dom/client' : 'react-dom'
|
|
47
53
|
}, {
|
|
48
54
|
specifiers: [{
|
|
49
55
|
imported: 'createApp'
|
|
@@ -14,6 +14,8 @@ var _printInstructions = require("../utils/printInstructions");
|
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
15
|
|
|
16
16
|
const start = async api => {
|
|
17
|
+
var _userConfig$source;
|
|
18
|
+
|
|
17
19
|
const appContext = api.useAppContext();
|
|
18
20
|
const userConfig = api.useResolvedConfigContext();
|
|
19
21
|
const hookRunners = api.useHookRunners();
|
|
@@ -25,7 +27,7 @@ const start = async api => {
|
|
|
25
27
|
|
|
26
28
|
_utils.logger.log(_utils.chalk.cyan(`Starting the modern server...`));
|
|
27
29
|
|
|
28
|
-
const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory);
|
|
30
|
+
const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$source = userConfig.source) === null || _userConfig$source === void 0 ? void 0 : _userConfig$source.entriesDir);
|
|
29
31
|
const app = await (0, _prodServer.default)({
|
|
30
32
|
pwd: appDirectory,
|
|
31
33
|
config: userConfig,
|
package/dist/js/node/index.js
CHANGED
|
@@ -39,6 +39,8 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
39
39
|
|
|
40
40
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
41
41
|
|
|
42
|
+
const upgradeModel = _utils.Import.lazy('@modern-js/upgrade', require);
|
|
43
|
+
|
|
42
44
|
var _default = () => ({
|
|
43
45
|
name: '@modern-js/app-tools',
|
|
44
46
|
post: ['@modern-js/plugin-analyze', '@modern-js/plugin-ssr', '@modern-js/plugin-state', '@modern-js/plugin-router', '@modern-js/plugin-polyfill'],
|
|
@@ -102,6 +104,7 @@ var _default = () => ({
|
|
|
102
104
|
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/inspect")));
|
|
103
105
|
inspect(api, options);
|
|
104
106
|
});
|
|
107
|
+
upgradeModel.defineCommand(program.command('upgrade'));
|
|
105
108
|
},
|
|
106
109
|
|
|
107
110
|
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
|
@@ -4,6 +4,7 @@ export declare const APP_FILE_NAME = "App";
|
|
|
4
4
|
export declare const PAGES_DIR_NAME = "pages";
|
|
5
5
|
export declare const FILE_SYSTEM_ROUTES_FILE_NAME = "routes.js";
|
|
6
6
|
export declare const ENTRY_POINT_FILE_NAME = "index.js";
|
|
7
|
+
export declare const ENTRY_BOOTSTRAP_FILE_NAME = "bootstrap.js";
|
|
7
8
|
export declare const FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP: RegExp;
|
|
8
9
|
export declare const FILE_SYSTEM_ROUTES_LAYOUT = "_layout";
|
|
9
10
|
export declare const FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT = "_app";
|
|
@@ -17,6 +17,10 @@ export declare const modifyEntryRenderFunction: import("@modern-js/plugin").Asyn
|
|
|
17
17
|
entrypoint: Entrypoint;
|
|
18
18
|
code: string;
|
|
19
19
|
}>;
|
|
20
|
+
export declare const modifyAsyncEntry: import("@modern-js/plugin").AsyncWaterfall<{
|
|
21
|
+
entrypoint: Entrypoint;
|
|
22
|
+
code: string;
|
|
23
|
+
}>;
|
|
20
24
|
export declare const modifyFileSystemRoutes: import("@modern-js/plugin").AsyncWaterfall<{
|
|
21
25
|
entrypoint: Entrypoint;
|
|
22
26
|
routes: Route[];
|
|
@@ -5,11 +5,13 @@ export declare const getDefaultImports: ({
|
|
|
5
5
|
entrypoint,
|
|
6
6
|
srcDirectory,
|
|
7
7
|
internalSrcAlias,
|
|
8
|
-
internalDirAlias
|
|
8
|
+
internalDirAlias,
|
|
9
|
+
internalDirectory
|
|
9
10
|
}: {
|
|
10
11
|
entrypoint: Entrypoint;
|
|
11
12
|
srcDirectory: string;
|
|
12
13
|
internalSrcAlias: string;
|
|
13
14
|
internalDirAlias: string;
|
|
15
|
+
internalDirectory: string;
|
|
14
16
|
}) => ImportStatement[];
|
|
15
17
|
export declare const isRouteComponentFile: (filePath: string) => boolean;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.18.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -56,30 +56,29 @@
|
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@babel/runtime": "^7.18.0",
|
|
59
|
-
"@modern-js/core": "1.
|
|
60
|
-
"@modern-js/new-action": "1.
|
|
61
|
-
"@modern-js/
|
|
62
|
-
"@modern-js/
|
|
63
|
-
"@modern-js/plugin
|
|
64
|
-
"@modern-js/plugin-
|
|
65
|
-
"@modern-js/
|
|
66
|
-
"@modern-js/server": "1.
|
|
67
|
-
"@modern-js/
|
|
68
|
-
"@modern-js/
|
|
69
|
-
"@modern-js/
|
|
59
|
+
"@modern-js/core": "1.18.0",
|
|
60
|
+
"@modern-js/new-action": "1.18.0",
|
|
61
|
+
"@modern-js/upgrade": "1.18.0",
|
|
62
|
+
"@modern-js/node-bundle-require": "1.18.0",
|
|
63
|
+
"@modern-js/plugin": "1.18.0",
|
|
64
|
+
"@modern-js/plugin-i18n": "1.18.0",
|
|
65
|
+
"@modern-js/plugin-jarvis": "1.18.0",
|
|
66
|
+
"@modern-js/prod-server": "1.18.0",
|
|
67
|
+
"@modern-js/server": "1.18.0",
|
|
68
|
+
"@modern-js/types": "1.18.0",
|
|
69
|
+
"@modern-js/utils": "1.18.0",
|
|
70
|
+
"@modern-js/webpack": "1.18.0",
|
|
70
71
|
"@babel/parser": "^7.18.0",
|
|
71
72
|
"@babel/traverse": "^7.18.0",
|
|
72
73
|
"@babel/types": "^7.18.0"
|
|
73
74
|
},
|
|
74
75
|
"devDependencies": {
|
|
75
|
-
"@modern-js/server-core": "1.
|
|
76
|
+
"@modern-js/server-core": "1.18.0",
|
|
76
77
|
"@types/babel__traverse": "^7.14.2",
|
|
77
|
-
"@scripts/build": "1.
|
|
78
|
-
"@scripts/jest-config": "1.
|
|
78
|
+
"@scripts/build": "1.18.0",
|
|
79
|
+
"@scripts/jest-config": "1.18.0",
|
|
79
80
|
"@types/jest": "^27",
|
|
80
81
|
"@types/node": "^14",
|
|
81
|
-
"@types/react": "^17",
|
|
82
|
-
"@types/react-dom": "^17",
|
|
83
82
|
"jest": "^27",
|
|
84
83
|
"typescript": "^4"
|
|
85
84
|
},
|