@modern-js/app-tools 1.4.3 → 1.4.6

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.
Files changed (38) hide show
  1. package/.eslintrc.js +8 -0
  2. package/CHANGELOG.md +75 -0
  3. package/dist/js/modern/commands/build.js +13 -14
  4. package/dist/js/modern/commands/deploy.js +4 -4
  5. package/dist/js/modern/commands/dev.js +12 -11
  6. package/dist/js/modern/commands/start.js +4 -8
  7. package/dist/js/modern/{lifecycle.js → hooks.js} +10 -13
  8. package/dist/js/modern/index.js +74 -73
  9. package/dist/js/modern/locale/zh.js +1 -1
  10. package/dist/js/modern/utils/createCompiler.js +7 -7
  11. package/dist/js/modern/utils/createServer.js +1 -2
  12. package/dist/js/modern/utils/printInstructions.js +3 -3
  13. package/dist/js/node/commands/build.js +9 -11
  14. package/dist/js/node/commands/deploy.js +4 -5
  15. package/dist/js/node/commands/dev.js +17 -16
  16. package/dist/js/node/commands/start.js +4 -9
  17. package/dist/js/node/{lifecycle.js → hooks.js} +12 -18
  18. package/dist/js/node/index.js +81 -77
  19. package/dist/js/node/locale/zh.js +1 -1
  20. package/dist/js/node/utils/createCompiler.js +7 -8
  21. package/dist/js/node/utils/createServer.js +1 -2
  22. package/dist/js/node/utils/printInstructions.js +3 -4
  23. package/dist/types/commands/build.d.ts +3 -5
  24. package/dist/types/commands/deploy.d.ts +2 -1
  25. package/dist/types/commands/dev.d.ts +2 -1
  26. package/dist/types/commands/start.d.ts +2 -1
  27. package/dist/types/{lifecycle.d.ts → hooks.d.ts} +19 -1
  28. package/dist/types/index.d.ts +2 -19
  29. package/dist/types/utils/createCompiler.d.ts +3 -1
  30. package/dist/types/utils/printInstructions.d.ts +2 -2
  31. package/dist/types/utils/routes.d.ts +1 -1
  32. package/dist/types/utils/types.d.ts +4 -1
  33. package/jest.config.js +0 -1
  34. package/modern.config.js +1 -0
  35. package/package.json +17 -21
  36. package/tests/.eslintrc.js +8 -0
  37. package/tests/commands/build.test.ts +25 -24
  38. package/tests/utils.test.ts +0 -1
package/.eslintrc.js ADDED
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ root: true,
3
+ extends: ['@modern-js'],
4
+ parserOptions: {
5
+ tsconfigRootDir: __dirname,
6
+ project: ['./tsconfig.json'],
7
+ },
8
+ };
package/CHANGELOG.md CHANGED
@@ -1,5 +1,80 @@
1
1
  # @modern-js/app-tools
2
2
 
3
+ ## 1.4.6
4
+
5
+ ### Patch Changes
6
+
7
+ - 8491b6dd: fix: optimise "types" exports from plugin
8
+ - Updated dependencies [bebb39b6]
9
+ - Updated dependencies [4b4e73b7]
10
+ - Updated dependencies [da60172c]
11
+ - Updated dependencies [ef28a4e6]
12
+ - Updated dependencies [6cff93dc]
13
+ - Updated dependencies [132f7b53]
14
+ - Updated dependencies [ff73a5cc]
15
+ - Updated dependencies [9d4a005b]
16
+ - @modern-js/plugin-analyze@1.3.5
17
+ - @modern-js/plugin-fast-refresh@1.2.3
18
+ - @modern-js/webpack@1.5.3
19
+ - @modern-js/prod-server@1.0.6
20
+ - @modern-js/server@1.4.9
21
+ - @modern-js/core@1.6.1
22
+ - @modern-js/types@1.3.6
23
+ - @modern-js/utils@1.3.7
24
+
25
+ ## 1.4.5
26
+
27
+ ### Patch Changes
28
+
29
+ - 32c9772c: feat: convert to new plugin
30
+ - Updated dependencies [05ce88a0]
31
+ - Updated dependencies [a8df060e]
32
+ - Updated dependencies [c2046f37]
33
+ - Updated dependencies [dc88abf9]
34
+ - Updated dependencies [d2d0fa11]
35
+ - Updated dependencies [66cbef42]
36
+ - Updated dependencies [0462ff77]
37
+ - Updated dependencies [61e3f623]
38
+ - Updated dependencies [6a7acb81]
39
+ - Updated dependencies [681a1ff9]
40
+ - Updated dependencies [4e2026e4]
41
+ - @modern-js/core@1.6.0
42
+ - @modern-js/server@1.4.8
43
+ - @modern-js/utils@1.3.6
44
+ - @modern-js/plugin@1.3.2
45
+ - @modern-js/prod-server@1.0.5
46
+ - @modern-js/webpack@1.5.0
47
+ - @modern-js/plugin-fast-refresh@1.2.2
48
+ - @modern-js/plugin-analyze@1.3.4
49
+
50
+ ## 1.4.4
51
+
52
+ ### Patch Changes
53
+
54
+ - d5bf095a: fix: disable load webpack when apiOnly mode
55
+ - Updated dependencies [5bf5868d]
56
+ - Updated dependencies [80d3cfb7]
57
+ - Updated dependencies [42c6b136]
58
+ - Updated dependencies [80d8ddfe]
59
+ - Updated dependencies [4e7dcbd5]
60
+ - Updated dependencies [d95f28c3]
61
+ - Updated dependencies [d95f28c3]
62
+ - Updated dependencies [d5bf095a]
63
+ - Updated dependencies [9e8bc4ab]
64
+ - Updated dependencies [0923c182]
65
+ - Updated dependencies [0c556e59]
66
+ - Updated dependencies [80d8ddfe]
67
+ - Updated dependencies [491145e3]
68
+ - Updated dependencies [2008fdbd]
69
+ - Updated dependencies [ca0bcf13]
70
+ - Updated dependencies [9229dfd1]
71
+ - @modern-js/utils@1.3.5
72
+ - @modern-js/core@1.5.0
73
+ - @modern-js/plugin@1.3.0
74
+ - @modern-js/prod-server@1.0.4
75
+ - @modern-js/types@1.3.5
76
+ - @modern-js/server@1.4.7
77
+
3
78
  ## 1.4.3
4
79
 
5
80
  ### Patch Changes
@@ -6,32 +6,31 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
6
6
 
7
7
  import { webpack } from 'webpack';
8
8
  import { WebpackConfigTarget, getWebpackConfig } from '@modern-js/webpack';
9
- import { useAppContext, useResolvedConfigContext, mountHook, ResolvedConfigContext, manager } from '@modern-js/core';
9
+ import { manager, ResolvedConfigContext } from '@modern-js/core';
10
10
  import { formatWebpackMessages, measureFileSizesBeforeBuild, printFileSizesAfterBuild, printBuildError, logger, isUseSSRBundle, emptyDir } from '@modern-js/utils';
11
- import { generateRoutes } from "../utils/routes"; // These sizes are pretty large. We'll warn for bundles exceeding them.
12
-
11
+ import { generateRoutes } from "../utils/routes";
12
+ // These sizes are pretty large. We'll warn for bundles exceeding them.
13
13
  const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
14
- const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
15
- // eslint-disable-next-line max-statements
16
- export const build = async options => {
17
- /* eslint-disable react-hooks/rules-of-hooks */
18
- const resolvedConfig = useResolvedConfigContext();
19
- const appContext = useAppContext();
14
+ const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024; // eslint-disable-next-line max-statements
15
+
16
+ export const build = async (api, options) => {
17
+ const resolvedConfig = api.useResolvedConfigContext();
18
+ const appContext = api.useAppContext();
19
+ const hookRunners = api.useHookRunners();
20
20
  const {
21
21
  existSrc
22
22
  } = appContext;
23
- /* eslint-enable react-hooks/rules-of-hooks */
24
23
 
25
24
  if (!existSrc) {
26
25
  const {
27
26
  distDirectory
28
27
  } = appContext;
29
28
  await emptyDir(distDirectory);
30
- await mountHook().beforeBuild({
29
+ await hookRunners.beforeBuild({
31
30
  webpackConfigs: []
32
31
  });
33
32
  await generateRoutes(appContext);
34
- await mountHook().afterBuild();
33
+ await hookRunners.afterBuild();
35
34
  return;
36
35
  }
37
36
 
@@ -116,7 +115,7 @@ export const build = async options => {
116
115
  });
117
116
  }
118
117
 
119
- await mountHook().beforeBuild({
118
+ await hookRunners.beforeBuild({
120
119
  webpackConfigs: buildConfigs.map(({
121
120
  config
122
121
  }) => config)
@@ -138,5 +137,5 @@ export const build = async options => {
138
137
  }
139
138
 
140
139
  await generateRoutes(appContext);
141
- await mountHook().afterBuild();
140
+ await hookRunners.afterBuild();
142
141
  };
@@ -1,5 +1,5 @@
1
- import { mountHook } from '@modern-js/core';
2
- export const deploy = async options => {
3
- await mountHook().beforeDeploy(options);
4
- await mountHook().afterDeploy(options);
1
+ export const deploy = async (api, options) => {
2
+ const hookRunners = api.useHookRunners();
3
+ await hookRunners.beforeDeploy(options);
4
+ await hookRunners.afterDeploy(options);
5
5
  };
@@ -4,20 +4,16 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  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
6
 
7
- import { getWebpackConfig, WebpackConfigTarget } from '@modern-js/webpack';
8
7
  import { fs, logger, HMR_SOCK_PATH, clearConsole, chalk, isSSR } from '@modern-js/utils';
9
- import { useAppContext, useResolvedConfigContext, mountHook, AppContext } from '@modern-js/core';
10
8
  import { createCompiler } from "../utils/createCompiler";
11
9
  import { createServer } from "../utils/createServer";
12
10
  import { generateRoutes } from "../utils/routes";
13
11
  import { printInstructions } from "../utils/printInstructions";
14
12
  import { getSpecifiedEntries } from "../utils/getSpecifiedEntries";
15
- export const dev = async options => {
16
- /* eslint-disable react-hooks/rules-of-hooks */
17
- const appContext = useAppContext();
18
- const userConfig = useResolvedConfigContext();
19
- /* eslint-enable react-hooks/rules-of-hooks */
20
-
13
+ export const dev = async (api, options) => {
14
+ const appContext = api.useAppContext();
15
+ const userConfig = api.useResolvedConfigContext();
16
+ const hookRunners = api.useHookRunners();
21
17
  const {
22
18
  appDirectory,
23
19
  distDirectory,
@@ -26,17 +22,22 @@ export const dev = async options => {
26
22
  entrypoints
27
23
  } = appContext;
28
24
  const checkedEntries = await getSpecifiedEntries(options.entry || false, entrypoints);
29
- AppContext.set(_objectSpread(_objectSpread({}, appContext), {}, {
25
+ api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
30
26
  checkedEntries
31
27
  }));
32
28
  appContext.checkedEntries = checkedEntries;
33
29
  fs.emptyDirSync(distDirectory);
34
- await mountHook().beforeDev();
30
+ await hookRunners.beforeDev();
35
31
  let compiler = null;
36
32
 
37
33
  if (existSrc) {
34
+ const {
35
+ getWebpackConfig,
36
+ WebpackConfigTarget
37
+ } = await import('@modern-js/webpack');
38
38
  const webpackConfigs = [isSSR(userConfig) && getWebpackConfig(WebpackConfigTarget.NODE), getWebpackConfig(WebpackConfigTarget.CLIENT)].filter(Boolean);
39
39
  compiler = await createCompiler({
40
+ api,
40
41
  webpackConfigs,
41
42
  userConfig,
42
43
  appContext
@@ -75,7 +76,7 @@ export const dev = async options => {
75
76
  clearConsole();
76
77
  logger.log(chalk.cyan(`Starting the development server...`));
77
78
  } else {
78
- await printInstructions(appContext, userConfig);
79
+ await printInstructions(api, appContext, userConfig);
79
80
  }
80
81
  });
81
82
  };
@@ -1,13 +1,9 @@
1
1
  import { logger, chalk } from '@modern-js/utils';
2
- import { useAppContext, useResolvedConfigContext } from '@modern-js/core';
3
2
  import server from '@modern-js/prod-server';
4
3
  import { printInstructions } from "../utils/printInstructions";
5
- export const start = async () => {
6
- /* eslint-disable react-hooks/rules-of-hooks */
7
- const appContext = useAppContext();
8
- const userConfig = useResolvedConfigContext();
9
- /* eslint-enable react-hooks/rules-of-hooks */
10
-
4
+ export const start = async api => {
5
+ const appContext = api.useAppContext();
6
+ const userConfig = api.useResolvedConfigContext();
11
7
  const {
12
8
  appDirectory,
13
9
  port
@@ -23,6 +19,6 @@ export const start = async () => {
23
19
  throw err;
24
20
  }
25
21
 
26
- await printInstructions(appContext, userConfig);
22
+ await printInstructions(api, appContext, userConfig);
27
23
  });
28
24
  };
@@ -1,5 +1,4 @@
1
1
  import { createAsyncWaterfall, createAsyncWorkflow } from '@modern-js/plugin';
2
- import { registerHook } from '@modern-js/core';
3
2
  export const beforeDev = createAsyncWorkflow();
4
3
  export const afterDev = createAsyncWorkflow();
5
4
  export const beforeCreateCompiler = createAsyncWorkflow();
@@ -9,16 +8,14 @@ export const beforeBuild = createAsyncWorkflow();
9
8
  export const afterBuild = createAsyncWorkflow();
10
9
  export const beforeDeploy = createAsyncWorkflow();
11
10
  export const afterDeploy = createAsyncWorkflow();
12
- export const lifecycle = () => {
13
- registerHook({
14
- beforeDev,
15
- afterDev,
16
- beforeCreateCompiler,
17
- afterCreateCompiler,
18
- beforePrintInstructions,
19
- beforeBuild,
20
- afterBuild,
21
- beforeDeploy,
22
- afterDeploy
23
- });
11
+ export const hooks = {
12
+ beforeDev,
13
+ afterDev,
14
+ beforeCreateCompiler,
15
+ afterCreateCompiler,
16
+ beforePrintInstructions,
17
+ beforeBuild,
18
+ afterBuild,
19
+ beforeDeploy,
20
+ afterDeploy
24
21
  };
@@ -5,90 +5,91 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
5
5
  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
6
 
7
7
  import * as path from 'path';
8
- import { createPlugin, defineConfig, usePlugins, cli, useAppContext } from '@modern-js/core';
8
+ import { defineConfig, cli } from '@modern-js/core';
9
+ import AnalyzePlugin from '@modern-js/plugin-analyze';
10
+ import FastRefreshPlugin from '@modern-js/plugin-fast-refresh/cli';
9
11
  import { cleanRequireCache } from '@modern-js/utils';
10
- import { lifecycle } from "./lifecycle";
12
+ import { hooks } from "./hooks";
11
13
  import { i18n, localeKeys } from "./locale";
12
14
  import { getLocaleLanguage } from "./utils/language";
13
15
  import { start } from "./commands/start";
14
16
  import { dev } from "./commands/dev";
15
17
  import { closeServer } from "./utils/createServer";
16
- export { defineConfig }; // eslint-disable-next-line react-hooks/rules-of-hooks
18
+ export { defineConfig };
19
+ export default (() => ({
20
+ name: '@modern-js/app-tools',
21
+ post: ['@modern-js/plugin-analyze', '@modern-js/plugin-fast-refresh', '@modern-js/plugin-ssr', '@modern-js/plugin-state', '@modern-js/plugin-router', '@modern-js/plugin-polyfill'],
22
+ registerHook: hooks,
23
+ usePlugins: [AnalyzePlugin(), FastRefreshPlugin()],
24
+ setup: api => {
25
+ const locale = getLocaleLanguage();
26
+ i18n.changeLanguage({
27
+ locale
28
+ });
29
+ return {
30
+ commands({
31
+ program
32
+ }) {
33
+ program.command('dev').usage('[options]').description(i18n.t(localeKeys.command.dev.describe)).option('-c --config <config>', i18n.t(localeKeys.command.dev.config)).option('-e --entry [entry...]', i18n.t(localeKeys.command.dev.entry)).action(async options => {
34
+ await dev(api, options);
35
+ });
36
+ program.command('build').usage('[options]').description(i18n.t(localeKeys.command.build.describe)).option('--analyze', i18n.t(localeKeys.command.build.analyze)).action(async options => {
37
+ const {
38
+ build
39
+ } = await import("./commands/build");
40
+ await build(api, options); // force exit after build.
41
+ // eslint-disable-next-line no-process-exit
17
42
 
18
- usePlugins([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')]);
19
- export default createPlugin(() => {
20
- const locale = getLocaleLanguage();
21
- i18n.changeLanguage({
22
- locale
23
- });
24
- lifecycle();
25
- return {
26
- commands({
27
- program
28
- }) {
29
- program.command('dev').usage('[options]').description(i18n.t(localeKeys.command.dev.describe)).option('-c --config <config>', i18n.t(localeKeys.command.dev.config)).option('-e --entry [entry...]', i18n.t(localeKeys.command.dev.entry)).action(async options => {
30
- await dev(options);
31
- });
32
- program.command('build').usage('[options]').description(i18n.t(localeKeys.command.build.describe)).option('--analyze', i18n.t(localeKeys.command.build.analyze)).action(async options => {
33
- const {
34
- build
35
- } = await import("./commands/build");
36
- await build(options); // force exit after build.
37
- // eslint-disable-next-line no-process-exit
43
+ process.exit(0);
44
+ });
45
+ program.command('start').usage('[options]').description(i18n.t(localeKeys.command.start.describe)).action(async () => {
46
+ await start(api);
47
+ });
48
+ program.command('deploy').usage('[options]').description(i18n.t(localeKeys.command.deploy.describe)).action(async options => {
49
+ const {
50
+ build
51
+ } = await import("./commands/build");
52
+ await build(api);
53
+ const {
54
+ deploy
55
+ } = await import("./commands/deploy");
56
+ await deploy(api, options); // eslint-disable-next-line no-process-exit
38
57
 
39
- process.exit(0);
40
- });
41
- program.command('start').usage('[options]').description(i18n.t(localeKeys.command.start.describe)).action(async () => {
42
- await start();
43
- });
44
- program.command('deploy').usage('[options]').description(i18n.t(localeKeys.command.deploy.describe)).action(async options => {
45
- const {
46
- build
47
- } = await import("./commands/build");
48
- await build();
49
- const {
50
- deploy
51
- } = await import("./commands/deploy");
52
- await deploy(options); // eslint-disable-next-line no-process-exit
58
+ process.exit(0);
59
+ });
60
+ program.command('new').usage('[options]').description(i18n.t(localeKeys.command.new.describe)).option('-d, --debug', i18n.t(localeKeys.command.new.debug), false).option('-c, --config <config>', i18n.t(localeKeys.command.new.config)).option('--dist-tag <tag>', i18n.t(localeKeys.command.new.distTag)).option('--registry', i18n.t(localeKeys.command.new.registry)).action(async options => {
61
+ const {
62
+ MWANewAction
63
+ } = await import('@modern-js/new-action');
64
+ await MWANewAction(_objectSpread(_objectSpread({}, options), {}, {
65
+ locale
66
+ }));
67
+ });
68
+ },
53
69
 
54
- process.exit(0);
55
- });
56
- program.command('new').usage('[options]').description(i18n.t(localeKeys.command.new.describe)).option('-d, --debug', i18n.t(localeKeys.command.new.debug), false).option('-c, --config <config>', i18n.t(localeKeys.command.new.config)).option('--dist-tag <tag>', i18n.t(localeKeys.command.new.distTag)).option('--registry', i18n.t(localeKeys.command.new.registry)).action(async options => {
70
+ // 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
71
+ async fileChange(e) {
57
72
  const {
58
- MWANewAction
59
- } = await import('@modern-js/new-action');
60
- await MWANewAction(_objectSpread(_objectSpread({}, options), {}, {
61
- locale
62
- }));
63
- });
64
- },
65
-
66
- // 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
67
- async fileChange(e) {
68
- const {
69
- filename,
70
- eventType
71
- } = e; // eslint-disable-next-line react-hooks/rules-of-hooks
73
+ filename,
74
+ eventType
75
+ } = e;
76
+ const appContext = api.useAppContext();
77
+ const {
78
+ appDirectory,
79
+ srcDirectory
80
+ } = appContext;
81
+ const absolutePath = path.resolve(appDirectory, filename);
72
82
 
73
- const appContext = useAppContext();
74
- const {
75
- appDirectory,
76
- srcDirectory
77
- } = appContext;
78
- const absolutePath = path.resolve(appDirectory, filename);
83
+ if (!absolutePath.includes(srcDirectory) && (eventType === 'change' || eventType === 'unlink')) {
84
+ await closeServer();
85
+ await cli.restart();
86
+ }
87
+ },
79
88
 
80
- if (!absolutePath.includes(srcDirectory) && (eventType === 'change' || eventType === 'unlink')) {
81
- await closeServer();
82
- await cli.restart();
89
+ async beforeRestart() {
90
+ cleanRequireCache([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')]);
83
91
  }
84
- },
85
92
 
86
- async beforeRestart() {
87
- cleanRequireCache([require.resolve('@modern-js/plugin-analyze/cli'), require.resolve('@modern-js/plugin-fast-refresh/cli')]);
88
- }
89
-
90
- };
91
- }, {
92
- name: '@modern-js/app-tools',
93
- post: ['@modern-js/plugin-analyze', '@modern-js/plugin-fast-refresh', '@modern-js/plugin-ssr', '@modern-js/plugin-state', '@modern-js/plugin-router', '@modern-js/plugin-polyfill']
94
- });
93
+ };
94
+ }
95
+ }));
@@ -7,7 +7,7 @@ export const ZH_LOCALE = {
7
7
  },
8
8
  build: {
9
9
  describe: '构建应用命令',
10
- analyze: '分析构建产物'
10
+ analyze: '分析构建产物体积,查看各个模块打包后的大小'
11
11
  },
12
12
  start: {
13
13
  describe: '应用启动命令'
@@ -1,5 +1,4 @@
1
1
  import webpack from 'webpack';
2
- import { mountHook } from '@modern-js/core';
3
2
  import { chalk, logger, formatWebpackMessages, clearConsole } from '@modern-js/utils';
4
3
  import { printInstructions } from "./printInstructions";
5
4
 
@@ -10,17 +9,19 @@ const prettyTime = stats => {
10
9
  };
11
10
 
12
11
  export const createCompiler = async ({
12
+ api,
13
13
  webpackConfigs,
14
14
  // TODO: params
15
15
  userConfig,
16
16
  appContext
17
17
  }) => {
18
18
  try {
19
- await mountHook().beforeCreateCompiler({
19
+ const hookRunners = api.useHookRunners();
20
+ await hookRunners.beforeCreateCompiler({
20
21
  webpackConfigs
21
22
  });
22
23
  const compiler = webpack(webpackConfigs);
23
- await mountHook().afterCreateCompiler({
24
+ await hookRunners.afterCreateCompiler({
24
25
  compiler
25
26
  });
26
27
  let isFirstCompile = true;
@@ -46,7 +47,7 @@ export const createCompiler = async ({
46
47
  logger.log(errors.join('\n\n'));
47
48
  logger.log();
48
49
  } else if (process.stdout.isTTY || isFirstCompile) {
49
- await mountHook().afterDev();
50
+ await hookRunners.afterDev();
50
51
 
51
52
  if (warnings.length) {
52
53
  logger.log(chalk.yellow(`Compiled with warnings.\n`));
@@ -56,9 +57,8 @@ export const createCompiler = async ({
56
57
  logger.log(chalk.green(`Compiled successfully in ${prettyTime(statsData)} ms.\n`));
57
58
  }
58
59
 
59
- await printInstructions(appContext, userConfig);
60
- } // eslint-disable-next-line require-atomic-updates
61
-
60
+ await printInstructions(api, appContext, userConfig);
61
+ }
62
62
 
63
63
  isFirstCompile = false;
64
64
  });
@@ -10,8 +10,7 @@ export const closeServer = async () => {
10
10
  export const createServer = async options => {
11
11
  if (server) {
12
12
  await server.close();
13
- } // eslint-disable-next-line require-atomic-updates
14
-
13
+ }
15
14
 
16
15
  server = new Server(options);
17
16
  const app = await server.init();
@@ -1,6 +1,5 @@
1
1
  import { prettyInstructions, logger, isDev, chalk } from '@modern-js/utils';
2
- import { mountHook } from '@modern-js/core';
3
- export const printInstructions = async (appContext, config) => {
2
+ export const printInstructions = async (api, appContext, config) => {
4
3
  let message = prettyInstructions(appContext, config);
5
4
  const {
6
5
  existSrc
@@ -11,9 +10,10 @@ export const printInstructions = async (appContext, config) => {
11
10
  } // call beforePrintInstructions hook.
12
11
 
13
12
 
13
+ const hookRunners = api.useHookRunners();
14
14
  const {
15
15
  instructions
16
- } = await mountHook().beforePrintInstructions({
16
+ } = await hookRunners.beforePrintInstructions({
17
17
  instructions: message
18
18
  });
19
19
  logger.log(instructions);
@@ -23,28 +23,26 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
23
23
 
24
24
  // These sizes are pretty large. We'll warn for bundles exceeding them.
25
25
  const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
26
- const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
26
+ const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024; // eslint-disable-next-line max-statements
27
27
 
28
- // eslint-disable-next-line max-statements
29
- const build = async options => {
30
- /* eslint-disable react-hooks/rules-of-hooks */
31
- const resolvedConfig = (0, _core.useResolvedConfigContext)();
32
- const appContext = (0, _core.useAppContext)();
28
+ const build = async (api, options) => {
29
+ const resolvedConfig = api.useResolvedConfigContext();
30
+ const appContext = api.useAppContext();
31
+ const hookRunners = api.useHookRunners();
33
32
  const {
34
33
  existSrc
35
34
  } = appContext;
36
- /* eslint-enable react-hooks/rules-of-hooks */
37
35
 
38
36
  if (!existSrc) {
39
37
  const {
40
38
  distDirectory
41
39
  } = appContext;
42
40
  await (0, _utils.emptyDir)(distDirectory);
43
- await (0, _core.mountHook)().beforeBuild({
41
+ await hookRunners.beforeBuild({
44
42
  webpackConfigs: []
45
43
  });
46
44
  await (0, _routes.generateRoutes)(appContext);
47
- await (0, _core.mountHook)().afterBuild();
45
+ await hookRunners.afterBuild();
48
46
  return;
49
47
  }
50
48
 
@@ -133,7 +131,7 @@ const build = async options => {
133
131
  });
134
132
  }
135
133
 
136
- await (0, _core.mountHook)().beforeBuild({
134
+ await hookRunners.beforeBuild({
137
135
  webpackConfigs: buildConfigs.map(({
138
136
  config
139
137
  }) => config)
@@ -155,7 +153,7 @@ const build = async options => {
155
153
  }
156
154
 
157
155
  await (0, _routes.generateRoutes)(appContext);
158
- await (0, _core.mountHook)().afterBuild();
156
+ await hookRunners.afterBuild();
159
157
  };
160
158
 
161
159
  exports.build = build;
@@ -5,11 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.deploy = void 0;
7
7
 
8
- var _core = require("@modern-js/core");
9
-
10
- const deploy = async options => {
11
- await (0, _core.mountHook)().beforeDeploy(options);
12
- await (0, _core.mountHook)().afterDeploy(options);
8
+ const deploy = async (api, options) => {
9
+ const hookRunners = api.useHookRunners();
10
+ await hookRunners.beforeDeploy(options);
11
+ await hookRunners.afterDeploy(options);
13
12
  };
14
13
 
15
14
  exports.deploy = deploy;