@modern-js/module-tools 1.4.2 → 1.4.5

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 (71) hide show
  1. package/CHANGELOG.md +66 -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 +4 -5
  7. package/dist/js/modern/features/build/build-watch.js +6 -8
  8. package/dist/js/modern/features/build/build.js +7 -11
  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 +10 -9
  12. package/dist/js/modern/hooks/build.js +20 -0
  13. package/dist/js/modern/hooks/dev.js +11 -0
  14. package/dist/js/modern/hooks/index.js +14 -0
  15. package/dist/js/modern/index.js +37 -37
  16. package/dist/js/modern/tasks/build-source-code.js +1 -2
  17. package/dist/js/modern/tasks/build-style.js +2 -3
  18. package/dist/js/modern/tasks/build-watch-style.js +3 -6
  19. package/dist/js/modern/tasks/copy-assets.js +1 -2
  20. package/dist/js/modern/tasks/generator-dts/index.js +8 -11
  21. package/dist/js/modern/tasks/generator-dts/utils.js +11 -3
  22. package/dist/js/modern/utils/babel.js +2 -19
  23. package/dist/js/modern/utils/copy.js +1 -2
  24. package/dist/js/modern/utils/logger.js +1 -2
  25. package/dist/js/node/cli/build.js +2 -2
  26. package/dist/js/node/cli/dev.js +2 -2
  27. package/dist/js/node/commands/build.js +4 -6
  28. package/dist/js/node/commands/dev.js +6 -8
  29. package/dist/js/node/features/build/build-platform.js +5 -7
  30. package/dist/js/node/features/build/build-watch.js +6 -10
  31. package/dist/js/node/features/build/build.js +6 -13
  32. package/dist/js/node/features/build/index.js +5 -5
  33. package/dist/js/node/features/build/utils.js +9 -11
  34. package/dist/js/node/features/dev/index.js +11 -14
  35. package/dist/js/node/hooks/build.js +37 -0
  36. package/dist/js/node/hooks/dev.js +25 -0
  37. package/dist/js/node/hooks/index.js +39 -0
  38. package/dist/js/node/index.js +50 -42
  39. package/dist/js/node/tasks/build-source-code.js +3 -3
  40. package/dist/js/node/tasks/build-style.js +2 -4
  41. package/dist/js/node/tasks/build-watch-style.js +3 -7
  42. package/dist/js/node/tasks/copy-assets.js +1 -3
  43. package/dist/js/node/tasks/generator-dts/index.js +8 -16
  44. package/dist/js/node/tasks/generator-dts/utils.js +18 -8
  45. package/dist/js/node/utils/babel.js +1 -18
  46. package/dist/js/node/utils/copy.js +1 -2
  47. package/dist/js/node/utils/logger.js +5 -7
  48. package/dist/types/cli/build.d.ts +3 -2
  49. package/dist/types/cli/dev.d.ts +3 -2
  50. package/dist/types/cli/new.d.ts +1 -1
  51. package/dist/types/commands/build.d.ts +2 -1
  52. package/dist/types/commands/dev.d.ts +2 -1
  53. package/dist/types/features/build/build-platform.d.ts +2 -1
  54. package/dist/types/features/build/build-watch.d.ts +2 -2
  55. package/dist/types/features/build/build.d.ts +2 -2
  56. package/dist/types/features/build/index.d.ts +2 -2
  57. package/dist/types/features/build/utils.d.ts +4 -3
  58. package/dist/types/features/dev/index.d.ts +4 -3
  59. package/dist/types/hooks/build.d.ts +46 -0
  60. package/dist/types/hooks/dev.d.ts +18 -0
  61. package/dist/types/hooks/index.d.ts +26 -0
  62. package/dist/types/index.d.ts +3 -19
  63. package/dist/types/tasks/generator-dts/utils.d.ts +2 -1
  64. package/dist/types/utils/babel.d.ts +2 -3
  65. package/jest.config.js +0 -3
  66. package/package.json +19 -22
  67. package/tests/dev-cli.test.ts +43 -9
  68. package/tests/dev-command.test.ts +36 -10
  69. package/tests/dev-feature.test.ts +45 -13
  70. package/tests/generate-dts.test.ts +9 -0
  71. package/tests/generator-dts.test.ts +0 -11
package/CHANGELOG.md CHANGED
@@ -1,5 +1,71 @@
1
1
  # @modern-js/module-tools
2
2
 
3
+ ## 1.4.5
4
+
5
+ ### Patch Changes
6
+
7
+ - 07a4887e: feat: prebundle commander and signale to @modern-js/utils
8
+ - 17d0cc46: feat: prebundle lodash to @modern-js/utils/lodash
9
+ - Updated dependencies [60855eb2]
10
+ - Updated dependencies [046e58aa]
11
+ - Updated dependencies [ec1b7367]
12
+ - Updated dependencies [77ff9754]
13
+ - Updated dependencies [d2d1d6b2]
14
+ - Updated dependencies [07a4887e]
15
+ - Updated dependencies [ea2ae711]
16
+ - Updated dependencies [17d0cc46]
17
+ - Updated dependencies [d2d1d6b2]
18
+ - @modern-js/core@1.7.0
19
+ - @modern-js/plugin-analyze@1.3.6
20
+ - @modern-js/utils@1.4.0
21
+ - @modern-js/plugin-i18n@1.2.3
22
+ - @modern-js/new-action@1.3.5
23
+ - @modern-js/style-compiler@1.2.3
24
+ - @modern-js/css-config@1.2.3
25
+ - @modern-js/plugin-changeset@1.2.4
26
+ - @modern-js/plugin-fast-refresh@1.2.3
27
+
28
+ ## 1.4.4
29
+
30
+ ### Patch Changes
31
+
32
+ - 12b4dd41: fix: throw error when tsc is not installed
33
+ - 132f7b53: feat: move config declarations to @modern-js/core
34
+ - 8491b6dd: fix: optimise "types" exports from plugin
35
+ - 133a5dd7: remove module hooks dep
36
+ - 9d4a005b: fix: config babel via tools.babel
37
+ - Updated dependencies [bebb39b6]
38
+ - Updated dependencies [ef28a4e6]
39
+ - Updated dependencies [132f7b53]
40
+ - Updated dependencies [ff73a5cc]
41
+ - Updated dependencies [9d4a005b]
42
+ - @modern-js/css-config@1.2.3
43
+ - @modern-js/plugin-analyze@1.3.5
44
+ - @modern-js/plugin-changeset@1.2.4
45
+ - @modern-js/plugin-fast-refresh@1.2.3
46
+ - @modern-js/core@1.6.1
47
+ - @modern-js/utils@1.3.7
48
+
49
+ ## 1.4.3
50
+
51
+ ### Patch Changes
52
+
53
+ - 366cf4fd: convert module-tools to new plugin
54
+ - Updated dependencies [05ce88a0]
55
+ - Updated dependencies [a8df060e]
56
+ - Updated dependencies [c2046f37]
57
+ - Updated dependencies [366cf4fd]
58
+ - Updated dependencies [61e3f623]
59
+ - Updated dependencies [6a7acb81]
60
+ - Updated dependencies [681a1ff9]
61
+ - Updated dependencies [4e2026e4]
62
+ - @modern-js/core@1.6.0
63
+ - @modern-js/utils@1.3.6
64
+ - @modern-js/module-tools-hooks@1.2.3
65
+ - @modern-js/plugin-changeset@1.2.3
66
+ - @modern-js/plugin-fast-refresh@1.2.2
67
+ - @modern-js/plugin-analyze@1.3.4
68
+
3
69
  ## 1.4.2
4
70
 
5
71
  ### 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
  });
@@ -4,19 +4,18 @@ 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 { Import, chalk } from '@modern-js/utils';
8
- const core = Import.lazy('@modern-js/core', require);
9
- const execa = Import.lazy('execa', require);
7
+ import { execa, Import, chalk } from '@modern-js/utils';
10
8
  const lg = Import.lazy('./logger', require);
11
9
  const pMap = Import.lazy('p-map', require);
12
- export const buildPlatform = async option => {
10
+ export const buildPlatform = async (api, option) => {
13
11
  const {
14
12
  isTsProject = false,
15
13
  platform
16
14
  } = option;
17
15
  const lm = new lg.LoggerManager(); // 获取platforms的参数
18
16
 
19
- const buildTasks = await core.mountHook().platformBuild({
17
+ const runners = api.useHookRunners();
18
+ const buildTasks = await runners.platformBuild({
20
19
  isTsProject
21
20
  });
22
21
 
@@ -1,16 +1,14 @@
1
1
  import * as path from 'path';
2
2
  import * as os from 'os';
3
- import { Import } from '@modern-js/utils';
4
- const core = Import.lazy('@modern-js/core', require);
5
- const execa = Import.lazy('execa', require);
3
+ import { execa, Import } from '@modern-js/utils';
6
4
  const lg = Import.lazy('./logger', require);
7
5
  const pMap = Import.lazy('p-map', require);
8
6
  const utils = Import.lazy('./utils', require);
9
7
  const constants = Import.lazy('./constants', require);
10
- export const buildInWatchMode = async (config, _) => {
8
+ export const buildInWatchMode = async (api, config, _) => {
11
9
  const {
12
10
  appDirectory
13
- } = core.useAppContext();
11
+ } = api.useAppContext();
14
12
  const {
15
13
  sourceDir,
16
14
  enableTscCompiler
@@ -30,15 +28,15 @@ export const buildInWatchMode = async (config, _) => {
30
28
  const copyLog = lm.createLoggerText({
31
29
  title: 'Copy Log:'
32
30
  });
33
- const initCodeMapper = utils.getCodeInitMapper(config);
34
- const taskMapper = [...utils.getCodeMapper({
31
+ const initCodeMapper = utils.getCodeInitMapper(api, config);
32
+ const taskMapper = [...utils.getCodeMapper(api, {
35
33
  logger: codeLog,
36
34
  taskPath: require.resolve("../../tasks/build-watch-source-code"),
37
35
  config,
38
36
  willCompilerDirOrFile: sourceDir,
39
37
  initMapper: initCodeMapper,
40
38
  srcRootDir
41
- }), ...(enableTscCompiler ? utils.getDtsMapper(config, dtsLog) : []), {
39
+ }), ...(enableTscCompiler ? utils.getDtsMapper(api, config, dtsLog) : []), {
42
40
  logger: styleLog,
43
41
  taskPath: require.resolve("../../tasks/build-watch-style")
44
42
  }, {
@@ -1,21 +1,18 @@
1
- /* eslint-disable max-statements */
2
1
  import * as path from 'path';
3
2
  import * as os from 'os';
4
- import { Import } from '@modern-js/utils';
3
+ import { execa, Import } from '@modern-js/utils';
5
4
  const pMap = Import.lazy('p-map', require);
6
5
  const utils = Import.lazy('./utils', require);
7
- const execa = Import.lazy('execa', require);
8
6
  const lg = Import.lazy('./logger', require);
9
7
  const constants = Import.lazy('./constants', require);
10
- const core = Import.lazy('@modern-js/core', require);
11
- export const buildSourceCode = async (config, _) => {
8
+ export const buildSourceCode = async (api, config, _) => {
12
9
  const {
13
10
  sourceDir,
14
11
  enableTscCompiler
15
12
  } = config;
16
13
  const {
17
14
  appDirectory
18
- } = core.useAppContext();
15
+ } = api.useAppContext();
19
16
  const concurrency = os.cpus().length;
20
17
  const srcRootDir = path.join(appDirectory, sourceDir);
21
18
  const lm = new lg.LoggerManager();
@@ -31,15 +28,15 @@ export const buildSourceCode = async (config, _) => {
31
28
  const copyLog = lm.createLoggerText({
32
29
  title: 'Copy Log:'
33
30
  });
34
- const initCodeMapper = utils.getCodeInitMapper(config);
35
- const taskMapper = [...utils.getCodeMapper({
31
+ const initCodeMapper = utils.getCodeInitMapper(api, config);
32
+ const taskMapper = [...utils.getCodeMapper(api, {
36
33
  logger: codeLog,
37
34
  taskPath: require.resolve("../../tasks/build-source-code"),
38
35
  config,
39
36
  willCompilerDirOrFile: sourceDir,
40
37
  initMapper: initCodeMapper,
41
38
  srcRootDir
42
- }), ...(enableTscCompiler ? utils.getDtsMapper(config, dtsLog) : []), {
39
+ }), ...(enableTscCompiler ? utils.getDtsMapper(api, config, dtsLog) : []), {
43
40
  logger: styleLog,
44
41
  taskPath: require.resolve("../../tasks/build-style")
45
42
  }, {
@@ -106,5 +103,4 @@ export const buildSourceCode = async (config, _) => {
106
103
  // eslint-disable-next-line no-process-exit
107
104
  process.exit(1);
108
105
  }
109
- };
110
- /* eslint-enable max-statements */
106
+ };
@@ -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,9 @@
1
- import { Import } from '@modern-js/utils';
2
- import chalk from 'chalk';
3
- const core = Import.lazy('@modern-js/core', require);
1
+ import { chalk, Import } from '@modern-js/utils';
4
2
  const inquirer = Import.lazy('inquirer', require);
5
3
  const color = Import.lazy('../../utils/color', require);
6
- export const showMenu = async config => {
7
- const metas = await core.mountHook().moduleToolsMenu(undefined);
4
+ export const showMenu = async (api, config) => {
5
+ const runners = api.useHookRunners();
6
+ const metas = await runners.moduleToolsMenu(undefined);
8
7
 
9
8
  if (metas.length <= 0) {
10
9
  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 +26,9 @@ export const showMenu = async config => {
27
26
  await devMeta.runTask(config);
28
27
  }
29
28
  };
30
- export const devStorybook = async config => {
31
- const metas = await core.mountHook().moduleToolsMenu(undefined);
29
+ export const devStorybook = async (api, config) => {
30
+ const runners = api.useHookRunners();
31
+ const metas = await runners.moduleToolsMenu(undefined);
32
32
  const findStorybook = metas.find(meta => meta.value === 'storybook');
33
33
 
34
34
  if (findStorybook) {
@@ -39,8 +39,9 @@ export const devStorybook = async config => {
39
39
  process.exit(0);
40
40
  }
41
41
  };
42
- export const runSubCmd = async (subCmd, config) => {
43
- const metas = await core.mountHook().moduleToolsMenu(undefined);
42
+ export const runSubCmd = async (api, subCmd, config) => {
43
+ const runners = api.useHookRunners();
44
+ const metas = await runners.moduleToolsMenu(undefined);
44
45
  const devMeta = metas.find(meta => meta.value === subCmd || Array.isArray(meta.aliasValues) && meta.aliasValues.includes(subCmd));
45
46
 
46
47
  if (devMeta) {
@@ -0,0 +1,20 @@
1
+ import { createParallelWorkflow, createAsyncPipeline } from '@modern-js/plugin';
2
+ import { registerHook } from '@modern-js/core';
3
+ export const platformBuild = createParallelWorkflow();
4
+ export const moduleLessConfig = createAsyncPipeline();
5
+ export const moduleSassConfig = createAsyncPipeline();
6
+ export const moduleTailwindConfig = createAsyncPipeline();
7
+ export const buildHooks = {
8
+ platformBuild,
9
+ moduleLessConfig,
10
+ moduleSassConfig,
11
+ moduleTailwindConfig
12
+ };
13
+ export const lifecycle = () => {
14
+ registerHook({
15
+ moduleLessConfig,
16
+ moduleSassConfig,
17
+ moduleTailwindConfig,
18
+ platformBuild
19
+ });
20
+ };
@@ -0,0 +1,11 @@
1
+ import { createParallelWorkflow } from '@modern-js/plugin';
2
+ import { registerHook } from '@modern-js/core';
3
+ export const moduleToolsMenu = createParallelWorkflow();
4
+ export const devHooks = {
5
+ moduleToolsMenu
6
+ };
7
+ export const lifecycle = () => {
8
+ registerHook({
9
+ moduleToolsMenu
10
+ });
11
+ };
@@ -0,0 +1,14 @@
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
+
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+
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
+
7
+ import { buildHooks, lifecycle as buildLifeCycle } from "./build";
8
+ import { devHooks, lifecycle as devLifeCycle } from "./dev";
9
+ export { buildLifeCycle, devLifeCycle };
10
+ export const lifecycle = () => {
11
+ devLifeCycle();
12
+ buildLifeCycle();
13
+ };
14
+ export const hooks = _objectSpread(_objectSpread({}, buildHooks), devHooks);
@@ -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 "./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
+ }));
@@ -4,10 +4,9 @@ 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 { Import, fs } from '@modern-js/utils';
7
+ import { Import, glob, fs } from '@modern-js/utils';
8
8
  import { initEnv } from "../utils/init-env";
9
9
  const babelCompiler = Import.lazy('@modern-js/babel-compiler', require);
10
- const glob = Import.lazy('glob', require);
11
10
  const argv = Import.lazy('process.argv', require);
12
11
  const core = Import.lazy('@modern-js/core', require);
13
12
  const bc = Import.lazy('../utils/babel', require);
@@ -1,10 +1,9 @@
1
1
  import * as path from 'path';
2
- import { fs, Import } from '@modern-js/utils';
2
+ import { fs, glob, Import } from '@modern-js/utils';
3
3
  const cssConfig = Import.lazy('@modern-js/css-config', require);
4
4
  const core = Import.lazy('@modern-js/core', require);
5
5
  const compiler = Import.lazy('@modern-js/style-compiler', require);
6
- const glob = Import.lazy('glob', require);
7
- const hooks = Import.lazy('@modern-js/module-tools-hooks', require);
6
+ const hooks = Import.lazy('../hooks', require);
8
7
  const STYLE_DIRS = 'styles';
9
8
  const SRC_STYLE_DIRS = 'src';
10
9
 
@@ -1,12 +1,10 @@
1
- /* eslint-disable max-statements */
2
1
  import * as path from 'path';
3
- import { fs, watch, WatchChangeType, Import } from '@modern-js/utils';
2
+ import { fs, glob, watch, WatchChangeType, Import } from '@modern-js/utils';
4
3
  const logger = Import.lazy('../features/build/logger', require);
5
4
  const cssConfig = Import.lazy('@modern-js/css-config', require);
6
- const hooks = Import.lazy('@modern-js/module-tools-hooks', require);
5
+ const hooks = Import.lazy('../hooks', require);
7
6
  const core = Import.lazy('@modern-js/core', require);
8
7
  const compiler = Import.lazy('@modern-js/style-compiler', require);
9
- const glob = Import.lazy('glob', require);
10
8
  const STYLE_DIRS = 'styles';
11
9
  const SRC_STYLE_DIRS = 'src';
12
10
 
@@ -214,5 +212,4 @@ const taskMain = async ({
214
212
  console.error(e);
215
213
  }
216
214
  });
217
- })();
218
- /* eslint-enable max-statements */
215
+ })();
@@ -1,7 +1,6 @@
1
1
  import * as path from 'path';
2
- import { fs, watch, WatchChangeType, Import } from '@modern-js/utils';
2
+ import { fs, watch, glob, WatchChangeType, Import } from '@modern-js/utils';
3
3
  const argv = Import.lazy('process.argv', require);
4
- const glob = Import.lazy('glob', require);
5
4
  const core = Import.lazy('@modern-js/core', require);
6
5
  const copyUtils = Import.lazy('../utils/copy', require);
7
6
  const STYLE_DIRS = 'styles';