@modern-js/app-tools 1.8.4 → 1.17.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 CHANGED
@@ -1,5 +1,104 @@
1
1
  # @modern-js/app-tools
2
2
 
3
+ ## 1.17.0
4
+
5
+ ### Patch Changes
6
+
7
+ - fb30bca: feat: add upgrade tools and command
8
+
9
+ feat: 增加升级工具和升级命令
10
+
11
+ - c3d4a6a: feat: support react 18 ssr
12
+ feat: 支持 React 18 下使用 SSR
13
+ - Updated dependencies [1b9176f]
14
+ - Updated dependencies [77d3a38]
15
+ - Updated dependencies [fb30bca]
16
+ - Updated dependencies [f3fab28]
17
+ - Updated dependencies [151329d]
18
+ - Updated dependencies [367405a]
19
+ - Updated dependencies [5af9472]
20
+ - Updated dependencies [6b6a534]
21
+ - Updated dependencies [6b43a2b]
22
+ - Updated dependencies [9f4e5ce]
23
+ - Updated dependencies [58c53a7]
24
+ - Updated dependencies [a7be124]
25
+ - Updated dependencies [31547b4]
26
+ - @modern-js/utils@1.17.0
27
+ - @modern-js/upgrade@1.17.0
28
+ - @modern-js/new-action@1.17.0
29
+ - @modern-js/webpack@1.17.0
30
+ - @modern-js/server@1.17.0
31
+ - @modern-js/core@1.17.0
32
+ - @modern-js/plugin-i18n@1.17.0
33
+ - @modern-js/plugin-jarvis@1.17.0
34
+ - @modern-js/prod-server@1.17.0
35
+ - @modern-js/node-bundle-require@1.17.0
36
+ - @modern-js/plugin@1.17.0
37
+ - @modern-js/types@1.17.0
38
+
39
+ ## 1.16.0
40
+
41
+ ### Minor Changes
42
+
43
+ - 1100dd58c: chore: support react 18
44
+
45
+ chore: 支持 React 18
46
+
47
+ ### Patch Changes
48
+
49
+ - 3904b30a5: fix: check apiOnly while has source.entriesDir
50
+
51
+ fix: 当配置 source.entriesDir 存在时,apiOnly 检查错误
52
+
53
+ - Updated dependencies [641592f52]
54
+ - Updated dependencies [3904b30a5]
55
+ - Updated dependencies [1100dd58c]
56
+ - Updated dependencies [e04e6e76a]
57
+ - Updated dependencies [2808ff5a2]
58
+ - Updated dependencies [81c66e4a4]
59
+ - Updated dependencies [2c305b6f5]
60
+ - Updated dependencies [9d9bbfd05]
61
+ - @modern-js/utils@1.16.0
62
+ - @modern-js/webpack@1.16.0
63
+ - @modern-js/types@1.16.0
64
+ - @modern-js/server@1.16.0
65
+ - @modern-js/prod-server@1.16.0
66
+ - @modern-js/new-action@1.16.0
67
+ - @modern-js/core@1.16.0
68
+ - @modern-js/plugin-i18n@1.16.0
69
+ - @modern-js/plugin-jarvis@1.16.0
70
+ - @modern-js/node-bundle-require@1.16.0
71
+ - @modern-js/plugin@1.16.0
72
+
73
+ ## 1.15.0
74
+
75
+ ### Patch Changes
76
+
77
+ - d85a20d: fix(app-tools): should not modify entry when using disableDefaultEntries
78
+
79
+ fix(app-tools): 修复开启 disableDefaultEntries 后 entry 名称被修改的问题
80
+
81
+ - 37cd159: feat(webpack): log more detailed error messages
82
+ - Updated dependencies [8658a78]
83
+ - Updated dependencies [0df4970]
84
+ - Updated dependencies [05d4a4f]
85
+ - Updated dependencies [b1f7000]
86
+ - Updated dependencies [ad05af9]
87
+ - Updated dependencies [5d53d1c]
88
+ - Updated dependencies [c087148]
89
+ - Updated dependencies [37cd159]
90
+ - @modern-js/utils@1.15.0
91
+ - @modern-js/webpack@1.15.0
92
+ - @modern-js/server@1.15.0
93
+ - @modern-js/types@1.15.0
94
+ - @modern-js/prod-server@1.15.0
95
+ - @modern-js/new-action@1.15.0
96
+ - @modern-js/core@1.15.0
97
+ - @modern-js/plugin-i18n@1.15.0
98
+ - @modern-js/plugin-jarvis@1.15.0
99
+ - @modern-js/node-bundle-require@1.15.0
100
+ - @modern-js/plugin@1.15.0
101
+
3
102
  ## 1.8.4
4
103
 
5
104
  ### Patch Changes
@@ -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
 
@@ -59,14 +59,17 @@ export const getBundleEntry = (appContext, config) => {
59
59
  defaults.push(entrypoint);
60
60
  }
61
61
  });
62
- } // find main entry point which server route is '/'.
62
+ }
63
63
 
64
+ if (!disableDefaultEntries) {
65
+ // find main entry point which server route is '/'.
66
+ const entriesDirAbs = ensureAbsolutePath(appDirectory, entriesDir);
67
+ const found = defaults.find(({
68
+ entryName,
69
+ entry
70
+ }) => entryName === packageName || path.dirname(entry) === entriesDirAbs);
71
+ found && (found.entryName = MAIN_ENTRY_NAME);
72
+ }
64
73
 
65
- const entriesDirAbs = ensureAbsolutePath(appDirectory, entriesDir);
66
- const found = defaults.find(({
67
- entryName,
68
- entry
69
- }) => entryName === packageName || path.dirname(entry) === entriesDirAbs);
70
- found && (found.entryName = MAIN_ENTRY_NAME);
71
74
  return defaults;
72
75
  };
@@ -39,6 +39,8 @@ export default (() => ({
39
39
  let originEntrypoints = [];
40
40
  return {
41
41
  async prepare() {
42
+ var _resolvedConfig$sourc;
43
+
42
44
  const appContext = api.useAppContext();
43
45
  const resolvedConfig = api.useResolvedConfigContext();
44
46
  const hookRunners = api.useHookRunners();
@@ -48,7 +50,7 @@ export default (() => ({
48
50
  } catch (_unused) {// FIXME:
49
51
  }
50
52
 
51
- const apiOnly = await isApiOnly(appContext.appDirectory);
53
+ 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
54
  await hookRunners.addRuntimeExports();
53
55
 
54
56
  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,
@@ -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
@@ -24,10 +24,7 @@ export const createCompiler = async ({
24
24
  });
25
25
  compiler.hooks.done.tap('done', async stats => {
26
26
  const statsData = stats.toJson({
27
- all: false,
28
- warnings: true,
29
- errors: true,
30
- timings: true
27
+ preset: 'errors-warnings'
31
28
  });
32
29
  const {
33
30
  errors,
@@ -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
 
@@ -71,15 +71,18 @@ const getBundleEntry = (appContext, config) => {
71
71
  defaults.push(entrypoint);
72
72
  }
73
73
  });
74
- } // find main entry point which server route is '/'.
74
+ }
75
75
 
76
+ if (!disableDefaultEntries) {
77
+ // find main entry point which server route is '/'.
78
+ const entriesDirAbs = (0, _utils.ensureAbsolutePath)(appDirectory, entriesDir);
79
+ const found = defaults.find(({
80
+ entryName,
81
+ entry
82
+ }) => entryName === packageName || _path.default.dirname(entry) === entriesDirAbs);
83
+ found && (found.entryName = _utils.MAIN_ENTRY_NAME);
84
+ }
76
85
 
77
- const entriesDirAbs = (0, _utils.ensureAbsolutePath)(appDirectory, entriesDir);
78
- const found = defaults.find(({
79
- entryName,
80
- entry
81
- }) => entryName === packageName || _path.default.dirname(entry) === entriesDirAbs);
82
- found && (found.entryName = _utils.MAIN_ENTRY_NAME);
83
86
  return defaults;
84
87
  };
85
88
 
@@ -66,6 +66,8 @@ var _default = () => ({
66
66
  let originEntrypoints = [];
67
67
  return {
68
68
  async prepare() {
69
+ var _resolvedConfig$sourc;
70
+
69
71
  const appContext = api.useAppContext();
70
72
  const resolvedConfig = api.useResolvedConfigContext();
71
73
  const hookRunners = api.useHookRunners();
@@ -75,7 +77,7 @@ var _default = () => ({
75
77
  } catch (_unused) {// FIXME:
76
78
  }
77
79
 
78
- const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory);
80
+ 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
81
  await hookRunners.addRuntimeExports();
80
82
 
81
83
  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,
@@ -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
@@ -35,10 +35,7 @@ const createCompiler = async ({
35
35
  });
36
36
  compiler.hooks.done.tap('done', async stats => {
37
37
  const statsData = stats.toJson({
38
- all: false,
39
- warnings: true,
40
- errors: true,
41
- timings: true
38
+ preset: 'errors-warnings'
42
39
  });
43
40
  const {
44
41
  errors,
@@ -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.8.4",
14
+ "version": "1.17.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.14.0",
60
- "@modern-js/new-action": "^1.4.0",
61
- "@modern-js/node-bundle-require": "^1.3.8",
62
- "@modern-js/plugin": "^1.4.1",
63
- "@modern-js/plugin-i18n": "^1.3.0",
64
- "@modern-js/plugin-jarvis": "^1.2.14",
65
- "@modern-js/prod-server": "^1.2.2",
66
- "@modern-js/server": "^1.6.0",
67
- "@modern-js/types": "^1.6.2",
68
- "@modern-js/utils": "^1.9.0",
69
- "@modern-js/webpack": "^1.12.4",
59
+ "@modern-js/core": "1.17.0",
60
+ "@modern-js/new-action": "1.17.0",
61
+ "@modern-js/upgrade": "1.17.0",
62
+ "@modern-js/node-bundle-require": "1.17.0",
63
+ "@modern-js/plugin": "1.17.0",
64
+ "@modern-js/plugin-i18n": "1.17.0",
65
+ "@modern-js/plugin-jarvis": "1.17.0",
66
+ "@modern-js/prod-server": "1.17.0",
67
+ "@modern-js/server": "1.17.0",
68
+ "@modern-js/types": "1.17.0",
69
+ "@modern-js/utils": "1.17.0",
70
+ "@modern-js/webpack": "1.17.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.4.1",
76
+ "@modern-js/server-core": "1.17.0",
76
77
  "@types/babel__traverse": "^7.14.2",
77
- "@scripts/build": "0.0.0",
78
- "@scripts/jest-config": "0.0.0",
78
+ "@scripts/build": "1.17.0",
79
+ "@scripts/jest-config": "1.17.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
  },