@modern-js/app-tools 1.8.3 → 1.16.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,89 @@
1
1
  # @modern-js/app-tools
2
2
 
3
+ ## 1.16.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 1100dd58c: chore: support react 18
8
+
9
+ chore: 支持 React 18
10
+
11
+ ### Patch Changes
12
+
13
+ - 3904b30a5: fix: check apiOnly while has source.entriesDir
14
+
15
+ fix: 当配置 source.entriesDir 存在时,apiOnly 检查错误
16
+
17
+ - Updated dependencies [641592f52]
18
+ - Updated dependencies [3904b30a5]
19
+ - Updated dependencies [1100dd58c]
20
+ - Updated dependencies [e04e6e76a]
21
+ - Updated dependencies [2808ff5a2]
22
+ - Updated dependencies [81c66e4a4]
23
+ - Updated dependencies [2c305b6f5]
24
+ - Updated dependencies [9d9bbfd05]
25
+ - @modern-js/utils@1.16.0
26
+ - @modern-js/webpack@1.16.0
27
+ - @modern-js/types@1.16.0
28
+ - @modern-js/server@1.16.0
29
+ - @modern-js/prod-server@1.16.0
30
+ - @modern-js/new-action@1.16.0
31
+ - @modern-js/core@1.16.0
32
+ - @modern-js/plugin-i18n@1.16.0
33
+ - @modern-js/plugin-jarvis@1.16.0
34
+ - @modern-js/node-bundle-require@1.16.0
35
+ - @modern-js/plugin@1.16.0
36
+
37
+ ## 1.15.0
38
+
39
+ ### Patch Changes
40
+
41
+ - d85a20d: fix(app-tools): should not modify entry when using disableDefaultEntries
42
+
43
+ fix(app-tools): 修复开启 disableDefaultEntries 后 entry 名称被修改的问题
44
+
45
+ - 37cd159: feat(webpack): log more detailed error messages
46
+ - Updated dependencies [8658a78]
47
+ - Updated dependencies [0df4970]
48
+ - Updated dependencies [05d4a4f]
49
+ - Updated dependencies [b1f7000]
50
+ - Updated dependencies [ad05af9]
51
+ - Updated dependencies [5d53d1c]
52
+ - Updated dependencies [c087148]
53
+ - Updated dependencies [37cd159]
54
+ - @modern-js/utils@1.15.0
55
+ - @modern-js/webpack@1.15.0
56
+ - @modern-js/server@1.15.0
57
+ - @modern-js/types@1.15.0
58
+ - @modern-js/prod-server@1.15.0
59
+ - @modern-js/new-action@1.15.0
60
+ - @modern-js/core@1.15.0
61
+ - @modern-js/plugin-i18n@1.15.0
62
+ - @modern-js/plugin-jarvis@1.15.0
63
+ - @modern-js/node-bundle-require@1.15.0
64
+ - @modern-js/plugin@1.15.0
65
+
66
+ ## 1.8.4
67
+
68
+ ### Patch Changes
69
+
70
+ - 3c20a5e: fix: `@modern-js/app-tools` export fields
71
+
72
+ fix: 修复 `@modern-js/app-tools` 导出字段路径
73
+
74
+ - Updated dependencies [79e83ef]
75
+ - Updated dependencies [5f1a231]
76
+ - Updated dependencies [3c20a5e]
77
+ - Updated dependencies [22f4dca]
78
+ - Updated dependencies [7b9067f]
79
+ - @modern-js/utils@1.9.0
80
+ - @modern-js/webpack@1.12.4
81
+ - @modern-js/node-bundle-require@1.3.8
82
+ - @modern-js/core@1.14.0
83
+ - @modern-js/plugin-jarvis@1.2.14
84
+ - @modern-js/prod-server@1.2.2
85
+ - @modern-js/server@1.6.0
86
+
3
87
  ## 1.8.3
4
88
 
5
89
  ### 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,12 @@ 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);` : `if (IS_REACT18) {
42
+ root = ReactDOM.createRoot(document.getElementById(MOUNT_ID || 'root'))
43
+ bootstrap(AppWrapper, MOUNT_ID, root, root.render, ReactDOM.hydrateRoot);
44
+ } else {
45
+ bootstrap(AppWrapper, MOUNT_ID, undefined, ReactDOM.render, ReactDOM.hydrate);
46
+ }`}
39
47
  }
40
48
 
41
49
  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,
@@ -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,12 @@ 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);` : `if (IS_REACT18) {
52
+ root = ReactDOM.createRoot(document.getElementById(MOUNT_ID || 'root'))
53
+ bootstrap(AppWrapper, MOUNT_ID, root, root.render, ReactDOM.hydrateRoot);
54
+ } else {
55
+ bootstrap(AppWrapper, MOUNT_ID, undefined, ReactDOM.render, ReactDOM.hydrate);
56
+ }`}
49
57
  }
50
58
 
51
59
  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,
@@ -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;
@@ -3,5 +3,5 @@ import type { PluginAPI, NormalizedConfig, IAppContext } from '@modern-js/core';
3
3
  import type { InspectOptions } from '../utils/types';
4
4
  export declare const formatWebpackConfig: (config: Configuration, verbose?: boolean) => string;
5
5
  export declare const inspect: (api: PluginAPI, options: InspectOptions) => void;
6
- export declare const getTagByWebpackTarget: (webpackTarget: WebpackConfigTarget) => "modern" | "client" | "ssr";
6
+ export declare const getTagByWebpackTarget: (webpackTarget: WebpackConfigTarget) => "client" | "modern" | "ssr";
7
7
  export declare const printInspectResult: (webpackTarget: WebpackConfigTarget, appContext: IAppContext, resolvedConfig: NormalizedConfig, options: InspectOptions) => string;
package/package.json CHANGED
@@ -11,11 +11,10 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.8.3",
14
+ "version": "1.16.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
18
- "module": "./dist/js/treeshaking/index.js",
19
18
  "jsnext:modern": "./dist/js/modern/index.js",
20
19
  "exports": {
21
20
  ".": {
@@ -24,7 +23,7 @@
24
23
  "import": "./dist/js/modern/index.js",
25
24
  "require": "./dist/js/node/index.js"
26
25
  },
27
- "default": "./dist/js/treeshaking/index.js"
26
+ "default": "./dist/js/node/index.js"
28
27
  },
29
28
  "./cli": {
30
29
  "jsnext:source": "./src/index.ts",
@@ -57,30 +56,28 @@
57
56
  },
58
57
  "dependencies": {
59
58
  "@babel/runtime": "^7.18.0",
60
- "@modern-js/core": "^1.13.3",
61
- "@modern-js/new-action": "^1.4.0",
62
- "@modern-js/node-bundle-require": "^1.3.7",
63
- "@modern-js/plugin": "^1.4.1",
64
- "@modern-js/plugin-i18n": "^1.3.0",
65
- "@modern-js/plugin-jarvis": "^1.2.14",
66
- "@modern-js/prod-server": "^1.2.2",
67
- "@modern-js/server": "^1.6.0",
68
- "@modern-js/types": "^1.6.2",
69
- "@modern-js/utils": "^1.8.1",
70
- "@modern-js/webpack": "^1.12.3",
59
+ "@modern-js/core": "1.16.0",
60
+ "@modern-js/new-action": "1.16.0",
61
+ "@modern-js/node-bundle-require": "1.16.0",
62
+ "@modern-js/plugin": "1.16.0",
63
+ "@modern-js/plugin-i18n": "1.16.0",
64
+ "@modern-js/plugin-jarvis": "1.16.0",
65
+ "@modern-js/prod-server": "1.16.0",
66
+ "@modern-js/server": "1.16.0",
67
+ "@modern-js/types": "1.16.0",
68
+ "@modern-js/utils": "1.16.0",
69
+ "@modern-js/webpack": "1.16.0",
71
70
  "@babel/parser": "^7.18.0",
72
71
  "@babel/traverse": "^7.18.0",
73
72
  "@babel/types": "^7.18.0"
74
73
  },
75
74
  "devDependencies": {
76
- "@modern-js/server-core": "1.4.1",
75
+ "@modern-js/server-core": "1.16.0",
77
76
  "@types/babel__traverse": "^7.14.2",
78
- "@scripts/build": "0.0.0",
79
- "@scripts/jest-config": "0.0.0",
77
+ "@scripts/build": "1.15.0",
78
+ "@scripts/jest-config": "1.15.0",
80
79
  "@types/jest": "^27",
81
80
  "@types/node": "^14",
82
- "@types/react": "^17",
83
- "@types/react-dom": "^17",
84
81
  "jest": "^27",
85
82
  "typescript": "^4"
86
83
  },