@modern-js/module-tools 1.4.2 → 1.4.3

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/CHANGELOG.md +20 -0
  2. package/dist/js/modern/cli/build.js +2 -2
  3. package/dist/js/modern/cli/dev.js +2 -2
  4. package/dist/js/modern/commands/build.js +4 -5
  5. package/dist/js/modern/commands/dev.js +6 -7
  6. package/dist/js/modern/features/build/build-platform.js +3 -3
  7. package/dist/js/modern/features/build/build-watch.js +5 -6
  8. package/dist/js/modern/features/build/build.js +5 -6
  9. package/dist/js/modern/features/build/index.js +5 -5
  10. package/dist/js/modern/features/build/utils.js +9 -10
  11. package/dist/js/modern/features/dev/index.js +9 -7
  12. package/dist/js/modern/index.js +37 -37
  13. package/dist/js/node/cli/build.js +2 -2
  14. package/dist/js/node/cli/dev.js +2 -2
  15. package/dist/js/node/commands/build.js +4 -6
  16. package/dist/js/node/commands/dev.js +6 -8
  17. package/dist/js/node/features/build/build-platform.js +3 -4
  18. package/dist/js/node/features/build/build-watch.js +5 -7
  19. package/dist/js/node/features/build/build.js +5 -7
  20. package/dist/js/node/features/build/index.js +5 -5
  21. package/dist/js/node/features/build/utils.js +9 -11
  22. package/dist/js/node/features/dev/index.js +9 -8
  23. package/dist/js/node/index.js +50 -42
  24. package/dist/types/cli/build.d.ts +2 -1
  25. package/dist/types/cli/dev.d.ts +2 -1
  26. package/dist/types/commands/build.d.ts +2 -1
  27. package/dist/types/commands/dev.d.ts +2 -1
  28. package/dist/types/features/build/build-platform.d.ts +2 -1
  29. package/dist/types/features/build/build-watch.d.ts +2 -2
  30. package/dist/types/features/build/build.d.ts +2 -2
  31. package/dist/types/features/build/index.d.ts +2 -2
  32. package/dist/types/features/build/utils.d.ts +4 -3
  33. package/dist/types/features/dev/index.d.ts +4 -3
  34. package/dist/types/index.d.ts +3 -19
  35. package/package.json +8 -8
  36. package/tests/dev-cli.test.ts +42 -8
  37. package/tests/dev-command.test.ts +36 -10
  38. package/tests/dev-feature.test.ts +45 -13
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @modern-js/module-tools
2
2
 
3
+ ## 1.4.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 366cf4fd: convert module-tools to new plugin
8
+ - Updated dependencies [05ce88a0]
9
+ - Updated dependencies [a8df060e]
10
+ - Updated dependencies [c2046f37]
11
+ - Updated dependencies [366cf4fd]
12
+ - Updated dependencies [61e3f623]
13
+ - Updated dependencies [6a7acb81]
14
+ - Updated dependencies [681a1ff9]
15
+ - Updated dependencies [4e2026e4]
16
+ - @modern-js/core@1.6.0
17
+ - @modern-js/utils@1.3.6
18
+ - @modern-js/module-tools-hooks@1.2.3
19
+ - @modern-js/plugin-changeset@1.2.3
20
+ - @modern-js/plugin-fast-refresh@1.2.2
21
+ - @modern-js/plugin-analyze@1.3.4
22
+
3
23
  ## 1.4.2
4
24
 
5
25
  ### Patch Changes
@@ -1,9 +1,9 @@
1
1
  import { Import } from '@modern-js/utils';
2
2
  const local = Import.lazy('../locale/index', require);
3
3
  const commands = Import.lazy('../commands', require);
4
- export const buildCli = program => {
4
+ export const buildCli = (program, api) => {
5
5
  // TODO: 初始化环境变量
6
6
  program.command('build').usage('[options]').description(local.i18n.t(local.localeKeys.command.build.describe)).option('-w, --watch', local.i18n.t(local.localeKeys.command.build.watch)).option('--tsconfig [tsconfig]', local.i18n.t(local.localeKeys.command.build.tsconfig), './tsconfig.json').option('--style-only', local.i18n.t(local.localeKeys.command.build.style_only)).option('-p, --platform [platform]', local.i18n.t(local.localeKeys.command.build.platform)).option('--no-tsc', local.i18n.t(local.localeKeys.command.build.no_tsc)).option('--no-clear', local.i18n.t(local.localeKeys.command.build.no_clear)).action(async subCommand => {
7
- await commands.build(subCommand);
7
+ await commands.build(api, subCommand);
8
8
  });
9
9
  };
@@ -1,8 +1,8 @@
1
1
  import { Import } from '@modern-js/utils';
2
2
  const local = Import.lazy('../locale', require);
3
3
  const commands = Import.lazy('../commands', require);
4
- export const devCli = program => {
4
+ export const devCli = (program, api) => {
5
5
  program.command('dev [subCmd]').usage('[options]').description(local.i18n.t(local.localeKeys.command.dev.describe)).option('--tsconfig [tsconfig]', local.i18n.t(local.localeKeys.command.build.tsconfig), './tsconfig.json').action(async (subCmd, params) => {
6
- await commands.dev(params, subCmd);
6
+ await commands.dev(api, params, subCmd);
7
7
  });
8
8
  };
@@ -3,9 +3,8 @@ import { fs, Import } from '@modern-js/utils';
3
3
  const tsConfigutils = Import.lazy('../utils/tsconfig', require);
4
4
  const valid = Import.lazy('../utils/valide', require);
5
5
  const buildFeature = Import.lazy('../features/build', require);
6
- const core = Import.lazy('@modern-js/core', require);
7
6
  const dotenv = Import.lazy('dotenv', require);
8
- export const build = async ({
7
+ export const build = async (api, {
9
8
  watch: _watch = false,
10
9
  tsconfig: tsconfigName,
11
10
  tsc,
@@ -14,8 +13,8 @@ export const build = async ({
14
13
  }) => {
15
14
  const {
16
15
  appDirectory
17
- } = core.useAppContext();
18
- const modernConfig = core.useResolvedConfigContext();
16
+ } = api.useAppContext();
17
+ const modernConfig = api.useResolvedConfigContext();
19
18
  const tsconfigPath = path.join(appDirectory, tsconfigName);
20
19
  dotenv.config();
21
20
  const isTsProject = tsConfigutils.existTsConfigFile(tsconfigPath);
@@ -25,7 +24,7 @@ export const build = async ({
25
24
  tsconfigPath
26
25
  }); // TODO: 一些配置只需要从modernConfig中获取
27
26
 
28
- await buildFeature.build({
27
+ await buildFeature.build(api, {
29
28
  appDirectory,
30
29
  enableWatchMode: _watch,
31
30
  isTsProject,
@@ -1,19 +1,18 @@
1
1
  import * as path from 'path';
2
2
  import { Import } from '@modern-js/utils';
3
3
  const devFeature = Import.lazy('../features/dev', require);
4
- const core = Import.lazy('@modern-js/core', require);
5
4
  const dotenv = Import.lazy('dotenv', require);
6
5
  const tsConfigutils = Import.lazy('../utils/tsconfig', require);
7
6
  const valid = Import.lazy('../utils/valide', require);
8
7
 
9
8
  const existSubCmd = subCmd => subCmd.length > 0;
10
9
 
11
- export const dev = async (option, subCmd = '') => {
10
+ export const dev = async (api, option, subCmd = '') => {
12
11
  const {
13
12
  tsconfig: tsconfigName
14
13
  } = option;
15
- const appContext = core.useAppContext();
16
- const modernConfig = core.useResolvedConfigContext();
14
+ const appContext = api.useAppContext();
15
+ const modernConfig = api.useResolvedConfigContext();
17
16
  const {
18
17
  appDirectory
19
18
  } = appContext;
@@ -26,7 +25,7 @@ export const dev = async (option, subCmd = '') => {
26
25
  const isTsProject = tsConfigutils.existTsConfigFile(tsconfigPath);
27
26
 
28
27
  if (existSubCmd(subCmd)) {
29
- await devFeature.runSubCmd(subCmd, {
28
+ await devFeature.runSubCmd(api, subCmd, {
30
29
  isTsProject,
31
30
  appDirectory
32
31
  });
@@ -35,12 +34,12 @@ export const dev = async (option, subCmd = '') => {
35
34
 
36
35
 
37
36
  if (process.env.RUN_PLATFORM) {
38
- await devFeature.showMenu({
37
+ await devFeature.showMenu(api, {
39
38
  isTsProject,
40
39
  appDirectory
41
40
  });
42
41
  } else {
43
- await devFeature.devStorybook({
42
+ await devFeature.devStorybook(api, {
44
43
  isTsProject,
45
44
  appDirectory
46
45
  });
@@ -5,18 +5,18 @@ 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 { Import, chalk } from '@modern-js/utils';
8
- const core = Import.lazy('@modern-js/core', require);
9
8
  const execa = Import.lazy('execa', require);
10
9
  const lg = Import.lazy('./logger', require);
11
10
  const pMap = Import.lazy('p-map', require);
12
- export const buildPlatform = async option => {
11
+ export const buildPlatform = async (api, option) => {
13
12
  const {
14
13
  isTsProject = false,
15
14
  platform
16
15
  } = option;
17
16
  const lm = new lg.LoggerManager(); // 获取platforms的参数
18
17
 
19
- const buildTasks = await core.mountHook().platformBuild({
18
+ const runners = api.useHookRunners();
19
+ const buildTasks = await runners.platformBuild({
20
20
  isTsProject
21
21
  });
22
22
 
@@ -1,16 +1,15 @@
1
1
  import * as path from 'path';
2
2
  import * as os from 'os';
3
3
  import { Import } from '@modern-js/utils';
4
- const core = Import.lazy('@modern-js/core', require);
5
4
  const execa = Import.lazy('execa', require);
6
5
  const lg = Import.lazy('./logger', require);
7
6
  const pMap = Import.lazy('p-map', require);
8
7
  const utils = Import.lazy('./utils', require);
9
8
  const constants = Import.lazy('./constants', require);
10
- export const buildInWatchMode = async (config, _) => {
9
+ export const buildInWatchMode = async (api, config, _) => {
11
10
  const {
12
11
  appDirectory
13
- } = core.useAppContext();
12
+ } = api.useAppContext();
14
13
  const {
15
14
  sourceDir,
16
15
  enableTscCompiler
@@ -30,15 +29,15 @@ export const buildInWatchMode = async (config, _) => {
30
29
  const copyLog = lm.createLoggerText({
31
30
  title: 'Copy Log:'
32
31
  });
33
- const initCodeMapper = utils.getCodeInitMapper(config);
34
- const taskMapper = [...utils.getCodeMapper({
32
+ const initCodeMapper = utils.getCodeInitMapper(api, config);
33
+ const taskMapper = [...utils.getCodeMapper(api, {
35
34
  logger: codeLog,
36
35
  taskPath: require.resolve("../../tasks/build-watch-source-code"),
37
36
  config,
38
37
  willCompilerDirOrFile: sourceDir,
39
38
  initMapper: initCodeMapper,
40
39
  srcRootDir
41
- }), ...(enableTscCompiler ? utils.getDtsMapper(config, dtsLog) : []), {
40
+ }), ...(enableTscCompiler ? utils.getDtsMapper(api, config, dtsLog) : []), {
42
41
  logger: styleLog,
43
42
  taskPath: require.resolve("../../tasks/build-watch-style")
44
43
  }, {
@@ -7,15 +7,14 @@ const utils = Import.lazy('./utils', require);
7
7
  const execa = Import.lazy('execa', require);
8
8
  const lg = Import.lazy('./logger', require);
9
9
  const constants = Import.lazy('./constants', require);
10
- const core = Import.lazy('@modern-js/core', require);
11
- export const buildSourceCode = async (config, _) => {
10
+ export const buildSourceCode = async (api, config, _) => {
12
11
  const {
13
12
  sourceDir,
14
13
  enableTscCompiler
15
14
  } = config;
16
15
  const {
17
16
  appDirectory
18
- } = core.useAppContext();
17
+ } = api.useAppContext();
19
18
  const concurrency = os.cpus().length;
20
19
  const srcRootDir = path.join(appDirectory, sourceDir);
21
20
  const lm = new lg.LoggerManager();
@@ -31,15 +30,15 @@ export const buildSourceCode = async (config, _) => {
31
30
  const copyLog = lm.createLoggerText({
32
31
  title: 'Copy Log:'
33
32
  });
34
- const initCodeMapper = utils.getCodeInitMapper(config);
35
- const taskMapper = [...utils.getCodeMapper({
33
+ const initCodeMapper = utils.getCodeInitMapper(api, config);
34
+ const taskMapper = [...utils.getCodeMapper(api, {
36
35
  logger: codeLog,
37
36
  taskPath: require.resolve("../../tasks/build-source-code"),
38
37
  config,
39
38
  willCompilerDirOrFile: sourceDir,
40
39
  initMapper: initCodeMapper,
41
40
  srcRootDir
42
- }), ...(enableTscCompiler ? utils.getDtsMapper(config, dtsLog) : []), {
41
+ }), ...(enableTscCompiler ? utils.getDtsMapper(api, config, dtsLog) : []), {
43
42
  logger: styleLog,
44
43
  taskPath: require.resolve("../../tasks/build-style")
45
44
  }, {
@@ -3,7 +3,7 @@ import { Import, fs } from '@modern-js/utils';
3
3
  const buildFeature = Import.lazy('./build', require);
4
4
  const buildWatchFeature = Import.lazy('./build-watch', require);
5
5
  const bp = Import.lazy('./build-platform', require);
6
- export const build = async (config, modernConfig) => {
6
+ export const build = async (api, config, modernConfig) => {
7
7
  const {
8
8
  appDirectory,
9
9
  enableWatchMode,
@@ -19,7 +19,7 @@ export const build = async (config, modernConfig) => {
19
19
 
20
20
  if (typeof platform === 'boolean' && platform) {
21
21
  if (process.env.RUN_PLATFORM) {
22
- await bp.buildPlatform({
22
+ await bp.buildPlatform(api, {
23
23
  platform: 'all',
24
24
  isTsProject
25
25
  });
@@ -30,7 +30,7 @@ export const build = async (config, modernConfig) => {
30
30
 
31
31
  if (typeof platform === 'string') {
32
32
  if (process.env.RUN_PLATFORM) {
33
- await bp.buildPlatform({
33
+ await bp.buildPlatform(api, {
34
34
  platform,
35
35
  isTsProject
36
36
  });
@@ -44,8 +44,8 @@ export const build = async (config, modernConfig) => {
44
44
  }
45
45
 
46
46
  if (enableWatchMode) {
47
- await buildWatchFeature.buildInWatchMode(config, modernConfig);
47
+ await buildWatchFeature.buildInWatchMode(api, config, modernConfig);
48
48
  } else {
49
- await buildFeature.buildSourceCode(config, modernConfig);
49
+ await buildFeature.buildSourceCode(api, config, modernConfig);
50
50
  }
51
51
  };
@@ -1,8 +1,7 @@
1
1
  import * as path from 'path';
2
2
  import * as os from 'os';
3
3
  import { Import, chalk } from '@modern-js/utils';
4
- const constants = Import.lazy('./constants', require);
5
- const core = Import.lazy('@modern-js/core', require); // 硬解字符串返回相应格式的对象
4
+ const constants = Import.lazy('./constants', require); // 硬解字符串返回相应格式的对象
6
5
 
7
6
  const updateMapper = (packageFieldValue, outDir, mapper) => {
8
7
  if (packageFieldValue === 'CJS+ES6') {
@@ -28,13 +27,13 @@ const updateMapper = (packageFieldValue, outDir, mapper) => {
28
27
  }
29
28
  };
30
29
 
31
- export const getCodeInitMapper = _ => {
30
+ export const getCodeInitMapper = (api, _) => {
32
31
  const {
33
32
  output: {
34
33
  packageFields,
35
34
  packageMode
36
35
  }
37
- } = core.useResolvedConfigContext();
36
+ } = api.useResolvedConfigContext();
38
37
  let initMapper = []; // 如果不存在packageFields配置或者packageFields为空对象,则使用 packageMode
39
38
 
40
39
  if (!packageFields || typeof packageFields === 'object' && Object.keys(packageFields).length === 0) {
@@ -63,7 +62,7 @@ export const getCodeInitMapper = _ => {
63
62
  return initMapper;
64
63
  }; // 获取执行构建源码的参数
65
64
 
66
- export const getCodeMapper = ({
65
+ export const getCodeMapper = (api, {
67
66
  logger,
68
67
  taskPath,
69
68
  config,
@@ -73,8 +72,8 @@ export const getCodeMapper = ({
73
72
  }) => {
74
73
  const {
75
74
  appDirectory
76
- } = core.useAppContext();
77
- const modernConfig = core.useResolvedConfigContext();
75
+ } = api.useAppContext();
76
+ const modernConfig = api.useResolvedConfigContext();
78
77
  const {
79
78
  output: {
80
79
  enableSourceMap,
@@ -99,11 +98,11 @@ export const getCodeMapper = ({
99
98
  });
100
99
  }; // 获取执行生成 d.ts 的参数
101
100
 
102
- export const getDtsMapper = (config, logger) => {
101
+ export const getDtsMapper = (api, config, logger) => {
103
102
  const {
104
103
  appDirectory
105
- } = core.useAppContext();
106
- const modernConfig = core.useResolvedConfigContext();
104
+ } = api.useAppContext();
105
+ const modernConfig = api.useResolvedConfigContext();
107
106
  const {
108
107
  output: {
109
108
  disableTsChecker,
@@ -1,10 +1,10 @@
1
1
  import { Import } from '@modern-js/utils';
2
2
  import chalk from 'chalk';
3
- const core = Import.lazy('@modern-js/core', require);
4
3
  const inquirer = Import.lazy('inquirer', require);
5
4
  const color = Import.lazy('../../utils/color', require);
6
- export const showMenu = async config => {
7
- const metas = await core.mountHook().moduleToolsMenu(undefined);
5
+ export const showMenu = async (api, config) => {
6
+ const runners = api.useHookRunners();
7
+ const metas = await runners.moduleToolsMenu(undefined);
8
8
 
9
9
  if (metas.length <= 0) {
10
10
  console.info(chalk.yellow('No runnable development features found.\nYou can use the `new` command to enable the development features')); // eslint-disable-next-line no-process-exit
@@ -27,8 +27,9 @@ export const showMenu = async config => {
27
27
  await devMeta.runTask(config);
28
28
  }
29
29
  };
30
- export const devStorybook = async config => {
31
- const metas = await core.mountHook().moduleToolsMenu(undefined);
30
+ export const devStorybook = async (api, config) => {
31
+ const runners = api.useHookRunners();
32
+ const metas = await runners.moduleToolsMenu(undefined);
32
33
  const findStorybook = metas.find(meta => meta.value === 'storybook');
33
34
 
34
35
  if (findStorybook) {
@@ -39,8 +40,9 @@ export const devStorybook = async config => {
39
40
  process.exit(0);
40
41
  }
41
42
  };
42
- export const runSubCmd = async (subCmd, config) => {
43
- const metas = await core.mountHook().moduleToolsMenu(undefined);
43
+ export const runSubCmd = async (api, subCmd, config) => {
44
+ const runners = api.useHookRunners();
45
+ const metas = await runners.moduleToolsMenu(undefined);
44
46
  const devMeta = metas.find(meta => meta.value === subCmd || Array.isArray(meta.aliasValues) && meta.aliasValues.includes(subCmd));
45
47
 
46
48
  if (devMeta) {
@@ -1,46 +1,46 @@
1
1
  import { Import } from '@modern-js/utils';
2
- const core = Import.lazy('@modern-js/core', require); // const { createPlugin, usePlugins, defineConfig } = core;
3
-
4
- const hooks = Import.lazy('@modern-js/module-tools-hooks', require);
2
+ import ChangesetPlugin from '@modern-js/plugin-changeset';
3
+ import AnalyzePlugin from '@modern-js/plugin-analyze';
4
+ import { hooks } from '@modern-js/module-tools-hooks';
5
5
  const cli = Import.lazy('./cli', require);
6
6
  const local = Import.lazy('./locale', require);
7
7
  const schema = Import.lazy('./schema', require);
8
8
  const lang = Import.lazy('./utils/language', require);
9
- export const {
10
- defineConfig
11
- } = core;
12
- core.usePlugins([require.resolve('@modern-js/plugin-changeset/cli'), require.resolve('@modern-js/plugin-analyze/cli')]);
13
- export default core.createPlugin(() => {
14
- const locale = lang.getLocaleLanguage();
15
- local.i18n.changeLanguage({
16
- locale
17
- });
18
- hooks.lifecycle();
19
- return {
20
- validateSchema() {
21
- return schema.addSchema();
22
- },
9
+ export { defineConfig } from '@modern-js/core';
10
+ export default (() => ({
11
+ name: '@modern-js/module-tools',
12
+ post: ['@modern-js/plugin-analyze', '@modern-js/plugin-changeset'],
13
+ registerHook: hooks,
14
+ usePlugins: [ChangesetPlugin(), AnalyzePlugin()],
15
+ setup: api => {
16
+ const locale = lang.getLocaleLanguage();
17
+ local.i18n.changeLanguage({
18
+ locale
19
+ });
20
+ return {
21
+ validateSchema() {
22
+ return schema.addSchema();
23
+ },
23
24
 
24
- config() {
25
- return {
26
- output: {
27
- enableSourceMap: false,
28
- jsPath: 'js'
29
- }
30
- };
31
- },
25
+ config() {
26
+ return {
27
+ output: {
28
+ enableSourceMap: false,
29
+ jsPath: 'js'
30
+ }
31
+ };
32
+ },
32
33
 
33
- commands({
34
- program
35
- }) {
36
- cli.devCli(program);
37
- cli.buildCli(program);
38
- cli.newCli(program, locale); // 便于其他插件辨别
34
+ commands({
35
+ program
36
+ }) {
37
+ cli.devCli(program, api);
38
+ cli.buildCli(program, api);
39
+ cli.newCli(program, locale); // 便于其他插件辨别
39
40
 
40
- program.$$libraryName = 'module-tools';
41
- }
41
+ program.$$libraryName = 'module-tools';
42
+ }
42
43
 
43
- };
44
- }, {
45
- post: ['@modern-js/plugin-analyze', '@modern-js/plugin-changeset']
46
- });
44
+ };
45
+ }
46
+ }));
@@ -11,10 +11,10 @@ const local = _utils.Import.lazy('../locale/index', require);
11
11
 
12
12
  const commands = _utils.Import.lazy('../commands', require);
13
13
 
14
- const buildCli = program => {
14
+ const buildCli = (program, api) => {
15
15
  // TODO: 初始化环境变量
16
16
  program.command('build').usage('[options]').description(local.i18n.t(local.localeKeys.command.build.describe)).option('-w, --watch', local.i18n.t(local.localeKeys.command.build.watch)).option('--tsconfig [tsconfig]', local.i18n.t(local.localeKeys.command.build.tsconfig), './tsconfig.json').option('--style-only', local.i18n.t(local.localeKeys.command.build.style_only)).option('-p, --platform [platform]', local.i18n.t(local.localeKeys.command.build.platform)).option('--no-tsc', local.i18n.t(local.localeKeys.command.build.no_tsc)).option('--no-clear', local.i18n.t(local.localeKeys.command.build.no_clear)).action(async subCommand => {
17
- await commands.build(subCommand);
17
+ await commands.build(api, subCommand);
18
18
  });
19
19
  };
20
20
 
@@ -11,9 +11,9 @@ const local = _utils.Import.lazy('../locale', require);
11
11
 
12
12
  const commands = _utils.Import.lazy('../commands', require);
13
13
 
14
- const devCli = program => {
14
+ const devCli = (program, api) => {
15
15
  program.command('dev [subCmd]').usage('[options]').description(local.i18n.t(local.localeKeys.command.dev.describe)).option('--tsconfig [tsconfig]', local.i18n.t(local.localeKeys.command.build.tsconfig), './tsconfig.json').action(async (subCmd, params) => {
16
- await commands.dev(params, subCmd);
16
+ await commands.dev(api, params, subCmd);
17
17
  });
18
18
  };
19
19
 
@@ -19,11 +19,9 @@ const valid = _utils.Import.lazy('../utils/valide', require);
19
19
 
20
20
  const buildFeature = _utils.Import.lazy('../features/build', require);
21
21
 
22
- const core = _utils.Import.lazy('@modern-js/core', require);
23
-
24
22
  const dotenv = _utils.Import.lazy('dotenv', require);
25
23
 
26
- const build = async ({
24
+ const build = async (api, {
27
25
  watch: _watch = false,
28
26
  tsconfig: tsconfigName,
29
27
  tsc,
@@ -32,8 +30,8 @@ const build = async ({
32
30
  }) => {
33
31
  const {
34
32
  appDirectory
35
- } = core.useAppContext();
36
- const modernConfig = core.useResolvedConfigContext();
33
+ } = api.useAppContext();
34
+ const modernConfig = api.useResolvedConfigContext();
37
35
  const tsconfigPath = path.join(appDirectory, tsconfigName);
38
36
  dotenv.config();
39
37
  const isTsProject = tsConfigutils.existTsConfigFile(tsconfigPath);
@@ -43,7 +41,7 @@ const build = async ({
43
41
  tsconfigPath
44
42
  }); // TODO: 一些配置只需要从modernConfig中获取
45
43
 
46
- await buildFeature.build({
44
+ await buildFeature.build(api, {
47
45
  appDirectory,
48
46
  enableWatchMode: _watch,
49
47
  isTsProject,
@@ -15,8 +15,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
15
15
 
16
16
  const devFeature = _utils.Import.lazy('../features/dev', require);
17
17
 
18
- const core = _utils.Import.lazy('@modern-js/core', require);
19
-
20
18
  const dotenv = _utils.Import.lazy('dotenv', require);
21
19
 
22
20
  const tsConfigutils = _utils.Import.lazy('../utils/tsconfig', require);
@@ -25,12 +23,12 @@ const valid = _utils.Import.lazy('../utils/valide', require);
25
23
 
26
24
  const existSubCmd = subCmd => subCmd.length > 0;
27
25
 
28
- const dev = async (option, subCmd = '') => {
26
+ const dev = async (api, option, subCmd = '') => {
29
27
  const {
30
28
  tsconfig: tsconfigName
31
29
  } = option;
32
- const appContext = core.useAppContext();
33
- const modernConfig = core.useResolvedConfigContext();
30
+ const appContext = api.useAppContext();
31
+ const modernConfig = api.useResolvedConfigContext();
34
32
  const {
35
33
  appDirectory
36
34
  } = appContext;
@@ -43,7 +41,7 @@ const dev = async (option, subCmd = '') => {
43
41
  const isTsProject = tsConfigutils.existTsConfigFile(tsconfigPath);
44
42
 
45
43
  if (existSubCmd(subCmd)) {
46
- await devFeature.runSubCmd(subCmd, {
44
+ await devFeature.runSubCmd(api, subCmd, {
47
45
  isTsProject,
48
46
  appDirectory
49
47
  });
@@ -52,12 +50,12 @@ const dev = async (option, subCmd = '') => {
52
50
 
53
51
 
54
52
  if (process.env.RUN_PLATFORM) {
55
- await devFeature.showMenu({
53
+ await devFeature.showMenu(api, {
56
54
  isTsProject,
57
55
  appDirectory
58
56
  });
59
57
  } else {
60
- await devFeature.devStorybook({
58
+ await devFeature.devStorybook(api, {
61
59
  isTsProject,
62
60
  appDirectory
63
61
  });
@@ -13,22 +13,21 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
13
13
 
14
14
  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; }
15
15
 
16
- const core = _utils.Import.lazy('@modern-js/core', require);
17
-
18
16
  const execa = _utils.Import.lazy('execa', require);
19
17
 
20
18
  const lg = _utils.Import.lazy('./logger', require);
21
19
 
22
20
  const pMap = _utils.Import.lazy('p-map', require);
23
21
 
24
- const buildPlatform = async option => {
22
+ const buildPlatform = async (api, option) => {
25
23
  const {
26
24
  isTsProject = false,
27
25
  platform
28
26
  } = option;
29
27
  const lm = new lg.LoggerManager(); // 获取platforms的参数
30
28
 
31
- const buildTasks = await core.mountHook().platformBuild({
29
+ const runners = api.useHookRunners();
30
+ const buildTasks = await runners.platformBuild({
32
31
  isTsProject
33
32
  });
34
33
 
@@ -15,8 +15,6 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
15
15
 
16
16
  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; }
17
17
 
18
- const core = _utils.Import.lazy('@modern-js/core', require);
19
-
20
18
  const execa = _utils.Import.lazy('execa', require);
21
19
 
22
20
  const lg = _utils.Import.lazy('./logger', require);
@@ -27,10 +25,10 @@ const utils = _utils.Import.lazy('./utils', require);
27
25
 
28
26
  const constants = _utils.Import.lazy('./constants', require);
29
27
 
30
- const buildInWatchMode = async (config, _) => {
28
+ const buildInWatchMode = async (api, config, _) => {
31
29
  const {
32
30
  appDirectory
33
- } = core.useAppContext();
31
+ } = api.useAppContext();
34
32
  const {
35
33
  sourceDir,
36
34
  enableTscCompiler
@@ -50,15 +48,15 @@ const buildInWatchMode = async (config, _) => {
50
48
  const copyLog = lm.createLoggerText({
51
49
  title: 'Copy Log:'
52
50
  });
53
- const initCodeMapper = utils.getCodeInitMapper(config);
54
- const taskMapper = [...utils.getCodeMapper({
51
+ const initCodeMapper = utils.getCodeInitMapper(api, config);
52
+ const taskMapper = [...utils.getCodeMapper(api, {
55
53
  logger: codeLog,
56
54
  taskPath: require.resolve("../../tasks/build-watch-source-code"),
57
55
  config,
58
56
  willCompilerDirOrFile: sourceDir,
59
57
  initMapper: initCodeMapper,
60
58
  srcRootDir
61
- }), ...(enableTscCompiler ? utils.getDtsMapper(config, dtsLog) : []), {
59
+ }), ...(enableTscCompiler ? utils.getDtsMapper(api, config, dtsLog) : []), {
62
60
  logger: styleLog,
63
61
  taskPath: require.resolve("../../tasks/build-watch-style")
64
62
  }, {