@modern-js/module-tools 1.4.1 → 1.4.4

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 (66) hide show
  1. package/CHANGELOG.md +64 -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 +5 -6
  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/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 +2 -1
  17. package/dist/js/modern/tasks/build-style.js +1 -1
  18. package/dist/js/modern/tasks/build-watch-source-code.js +2 -1
  19. package/dist/js/modern/tasks/build-watch-style.js +1 -1
  20. package/dist/js/modern/tasks/generator-dts/index.js +8 -10
  21. package/dist/js/modern/tasks/generator-dts/utils.js +9 -0
  22. package/dist/js/modern/utils/babel.js +12 -22
  23. package/dist/js/node/cli/build.js +2 -2
  24. package/dist/js/node/cli/dev.js +2 -2
  25. package/dist/js/node/commands/build.js +5 -7
  26. package/dist/js/node/commands/dev.js +6 -8
  27. package/dist/js/node/features/build/build-platform.js +3 -4
  28. package/dist/js/node/features/build/build-watch.js +5 -7
  29. package/dist/js/node/features/build/build.js +5 -7
  30. package/dist/js/node/features/build/index.js +5 -5
  31. package/dist/js/node/features/build/utils.js +9 -11
  32. package/dist/js/node/features/dev/index.js +9 -8
  33. package/dist/js/node/hooks/build.js +37 -0
  34. package/dist/js/node/hooks/dev.js +25 -0
  35. package/dist/js/node/hooks/index.js +39 -0
  36. package/dist/js/node/index.js +50 -42
  37. package/dist/js/node/tasks/build-source-code.js +2 -1
  38. package/dist/js/node/tasks/build-style.js +1 -1
  39. package/dist/js/node/tasks/build-watch-source-code.js +2 -1
  40. package/dist/js/node/tasks/build-watch-style.js +1 -1
  41. package/dist/js/node/tasks/generator-dts/index.js +7 -13
  42. package/dist/js/node/tasks/generator-dts/utils.js +14 -2
  43. package/dist/js/node/utils/babel.js +10 -20
  44. package/dist/types/cli/build.d.ts +2 -1
  45. package/dist/types/cli/dev.d.ts +2 -1
  46. package/dist/types/commands/build.d.ts +2 -1
  47. package/dist/types/commands/dev.d.ts +2 -1
  48. package/dist/types/features/build/build-platform.d.ts +2 -1
  49. package/dist/types/features/build/build-watch.d.ts +2 -2
  50. package/dist/types/features/build/build.d.ts +2 -2
  51. package/dist/types/features/build/index.d.ts +2 -2
  52. package/dist/types/features/build/utils.d.ts +4 -3
  53. package/dist/types/features/dev/index.d.ts +4 -3
  54. package/dist/types/hooks/build.d.ts +46 -0
  55. package/dist/types/hooks/dev.d.ts +18 -0
  56. package/dist/types/hooks/index.d.ts +26 -0
  57. package/dist/types/index.d.ts +3 -19
  58. package/dist/types/tasks/generator-dts/utils.d.ts +2 -1
  59. package/dist/types/utils/babel.d.ts +1 -2
  60. package/jest.config.js +0 -3
  61. package/lib/types.d.ts +92 -0
  62. package/package.json +19 -20
  63. package/tests/dev-cli.test.ts +42 -8
  64. package/tests/dev-command.test.ts +36 -10
  65. package/tests/dev-feature.test.ts +45 -13
  66. package/tests/generate-dts.test.ts +9 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,69 @@
1
1
  # @modern-js/module-tools
2
2
 
3
+ ## 1.4.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 12b4dd41: fix: throw error when tsc is not installed
8
+ - 132f7b53: feat: move config declarations to @modern-js/core
9
+ - 8491b6dd: fix: optimise "types" exports from plugin
10
+ - 133a5dd7: remove module hooks dep
11
+ - 9d4a005b: fix: config babel via tools.babel
12
+ - Updated dependencies [bebb39b6]
13
+ - Updated dependencies [ef28a4e6]
14
+ - Updated dependencies [132f7b53]
15
+ - Updated dependencies [ff73a5cc]
16
+ - Updated dependencies [9d4a005b]
17
+ - @modern-js/css-config@1.2.3
18
+ - @modern-js/plugin-analyze@1.3.5
19
+ - @modern-js/plugin-changeset@1.2.4
20
+ - @modern-js/plugin-fast-refresh@1.2.3
21
+ - @modern-js/core@1.6.1
22
+ - @modern-js/utils@1.3.7
23
+
24
+ ## 1.4.3
25
+
26
+ ### Patch Changes
27
+
28
+ - 366cf4fd: convert module-tools to new plugin
29
+ - Updated dependencies [05ce88a0]
30
+ - Updated dependencies [a8df060e]
31
+ - Updated dependencies [c2046f37]
32
+ - Updated dependencies [366cf4fd]
33
+ - Updated dependencies [61e3f623]
34
+ - Updated dependencies [6a7acb81]
35
+ - Updated dependencies [681a1ff9]
36
+ - Updated dependencies [4e2026e4]
37
+ - @modern-js/core@1.6.0
38
+ - @modern-js/utils@1.3.6
39
+ - @modern-js/module-tools-hooks@1.2.3
40
+ - @modern-js/plugin-changeset@1.2.3
41
+ - @modern-js/plugin-fast-refresh@1.2.2
42
+ - @modern-js/plugin-analyze@1.3.4
43
+
44
+ ## 1.4.2
45
+
46
+ ### Patch Changes
47
+
48
+ - 4b5d4bf4: feat: add img resource's inline and url type declaration
49
+ - 969f172f: support tools.styledComponents for module-tools,support close tsc process with disbaleTsChecker
50
+ - 55e18278: chore: remove unused dependencies and devDependencies
51
+ - edc3bd3d: fix: @modern-js/core package not found
52
+ - Updated dependencies [969f172f]
53
+ - Updated dependencies [4c792f68]
54
+ - Updated dependencies [83059b93]
55
+ - Updated dependencies [4b5d4bf4]
56
+ - Updated dependencies [62f5b8c8]
57
+ - Updated dependencies [55e18278]
58
+ - Updated dependencies [4499a674]
59
+ - Updated dependencies [403f5169]
60
+ - Updated dependencies [a7f42f48]
61
+ - Updated dependencies [83059b93]
62
+ - @modern-js/core@1.4.4
63
+ - @modern-js/utils@1.3.3
64
+ - @modern-js/new-action@1.3.3
65
+ - @modern-js/babel-compiler@1.2.2
66
+
3
67
  ## 1.4.1
4
68
 
5
69
  ### 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,18 +13,18 @@ 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);
22
- const enableTscCompiler = isTsProject && tsc;
21
+ const enableTscCompiler = isTsProject && tsc && !modernConfig.output.disableTsChecker;
23
22
  valid.valideBeforeTask({
24
23
  modernConfig,
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) {
@@ -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
+ }));
@@ -31,7 +31,8 @@ const runBabelCompiler = async (willCompilerFiles, config, babelConfig = {}) =>
31
31
  enableVirtualDist: true,
32
32
  rootDir: srcRootDir,
33
33
  filenames: willCompilerFiles,
34
- distDir
34
+ distDir,
35
+ ignore: ['*.d.ts']
35
36
  }, babelConfig);
36
37
  };
37
38
 
@@ -4,7 +4,7 @@ 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
6
  const glob = Import.lazy('glob', require);
7
- const hooks = Import.lazy('@modern-js/module-tools-hooks', require);
7
+ const hooks = Import.lazy('../hooks', require);
8
8
  const STYLE_DIRS = 'styles';
9
9
  const SRC_STYLE_DIRS = 'src';
10
10
 
@@ -66,7 +66,8 @@ const runBabelCompiler = async (config, modernConfig) => {
66
66
  rootDir: config.srcRootDir,
67
67
  distDir: config.distDir,
68
68
  watchDir: config.srcRootDir,
69
- extensions: getExts(isTs)
69
+ extensions: getExts(isTs),
70
+ ignore: ['*.d.ts']
70
71
  }, _objectSpread(_objectSpread({}, babelConfig), {}, {
71
72
  sourceMaps: config.sourceMaps
72
73
  }));
@@ -3,7 +3,7 @@ import * as path from 'path';
3
3
  import { fs, watch, WatchChangeType, Import } from '@modern-js/utils';
4
4
  const logger = Import.lazy('../features/build/logger', require);
5
5
  const cssConfig = Import.lazy('@modern-js/css-config', require);
6
- const hooks = Import.lazy('@modern-js/module-tools-hooks', require);
6
+ const hooks = Import.lazy('../hooks', require);
7
7
  const core = Import.lazy('@modern-js/core', require);
8
8
  const compiler = Import.lazy('@modern-js/style-compiler', require);
9
9
  const glob = Import.lazy('glob', require);
@@ -1,5 +1,5 @@
1
- import * as path from 'path';
2
- import { Import, fs } from '@modern-js/utils';
1
+ import { Import, fs, isObject } from '@modern-js/utils';
2
+ import { getTscBinPath } from "./utils";
3
3
  const core = Import.lazy('@modern-js/core', require);
4
4
  const execa = Import.lazy('execa', require);
5
5
  const JSON5 = Import.lazy('json5', require);
@@ -62,7 +62,7 @@ const generatorDts = async (_, config) => {
62
62
  sourceDir: sourceDirName
63
63
  });
64
64
  removeTsconfigPath = willDeleteTsconfigPath;
65
- const tscBinFile = path.join(appDirectory, './node_modules/.bin/tsc');
65
+ const tscBinFile = getTscBinPath(appDirectory);
66
66
  const watchParams = watch ? ['-w'] : [];
67
67
  const childProgress = execa(tscBinFile, ['-p', willDeleteTsconfigPath, ...watchParams], {
68
68
  stdio: 'pipe',
@@ -75,17 +75,15 @@ const generatorDts = async (_, config) => {
75
75
 
76
76
  try {
77
77
  await childProgress;
78
- console.info('[Tsc Compiler]: Successfully');
78
+ console.info('[TSC Compiler]: Successfully');
79
79
  } catch (e) {
80
80
  if (!tsCheck) {
81
81
  console.info(`There are some type warnings, which can be checked by configuring 'output.disableTsChecker = false'`);
82
+ } // 通过使用 execa,可以将 tsc 的 data 类型的报错信息变为异常错误信息
83
+ else if (isObject(e) && e.stdout) {
84
+ console.error(e.stdout);
82
85
  } else {
83
- const isRecord = input => typeof input === 'object'; // 通过使用 execa,可以将tsc 的 data 类型的报错信息变为异常错误信息
84
-
85
-
86
- if (isRecord(e)) {
87
- console.error(e.stdout);
88
- }
86
+ console.error(e);
89
87
  }
90
88
  }
91
89
 
@@ -79,4 +79,13 @@ export const resolveAlias = (modernConfig, config, watchFilenames = []) => {
79
79
  for (const r of result) {
80
80
  fs.writeFileSync(r.path, r.content);
81
81
  }
82
+ };
83
+ export const getTscBinPath = appDirectory => {
84
+ const tscBinFile = path.join(appDirectory, './node_modules/.bin/tsc');
85
+
86
+ if (!fs.existsSync(tscBinFile)) {
87
+ throw new Error('Failed to excute the `tsc` command, please check if `typescript` is installed correctly in the current directory.');
88
+ }
89
+
90
+ return tscBinFile;
82
91
  };