@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
@@ -4,8 +4,8 @@ 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 { getBabelConfig, getModuleBabelChain } from '@modern-js/babel-preset-module';
8
- import { applyOptionsChain, getAlias } from '@modern-js/utils';
7
+ import { getBabelConfig } from '@modern-js/babel-preset-module';
8
+ import { applyOptionsChain, getAlias, isUseSSRBundle } from '@modern-js/utils';
9
9
  export const getFinalAlias = (modernConfig, option) => {
10
10
  const aliasConfig = getAlias(modernConfig.source.alias, option); // 排除内部别名,因为不需要处理
11
11
 
@@ -36,7 +36,8 @@ export const resolveBabelConfig = (appDirectory, modernConfig, option) => {
36
36
  importStyle
37
37
  },
38
38
  tools: {
39
- lodash: userLodashOption
39
+ lodash: userLodashOption,
40
+ styledComponents
40
41
  }
41
42
  } = modernConfig; // alias config
42
43
 
@@ -58,30 +59,19 @@ export const resolveBabelConfig = (appDirectory, modernConfig, option) => {
58
59
  globalVars,
59
60
  lodashOptions,
60
61
  jsxTransformRuntime,
61
- importStyle
62
+ importStyle,
63
+ styledComponentsOptions: applyOptionsChain({
64
+ pure: true,
65
+ displayName: true,
66
+ ssr: isUseSSRBundle(modernConfig),
67
+ transpileTemplateLiterals: true
68
+ }, styledComponents)
62
69
  }, {
63
70
  type: option.type,
64
71
  syntax: option.syntax
65
72
  }); // Preventing warning when files are too large
66
73
 
67
74
  internalBabelConfig.compact = false;
68
- const babelChain = getModuleBabelChain({
69
- appDirectory,
70
- enableReactPreset: true,
71
- enableTypescriptPreset: true,
72
- alias: aliasConfig,
73
- envVars,
74
- globalVars,
75
- lodashOptions,
76
- jsxTransformRuntime,
77
- importStyle
78
- }, {
79
- type: option.type,
80
- syntax: option.syntax
81
- });
82
75
  const userBabelConfig = modernConfig.tools.babel;
83
- return applyOptionsChain(internalBabelConfig, // TODO: 感觉 userBabelConfig 的类型应该是TransformOptions
84
- userBabelConfig, {
85
- chain: babelChain
86
- });
76
+ return applyOptionsChain(internalBabelConfig, userBabelConfig);
87
77
  };
@@ -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,18 +30,18 @@ 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);
40
- const enableTscCompiler = isTsProject && tsc;
38
+ const enableTscCompiler = isTsProject && tsc && !modernConfig.output.disableTsChecker;
41
39
  valid.valideBeforeTask({
42
40
  modernConfig,
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
  }, {
@@ -26,16 +26,14 @@ const lg = _utils.Import.lazy('./logger', require);
26
26
 
27
27
  const constants = _utils.Import.lazy('./constants', require);
28
28
 
29
- const core = _utils.Import.lazy('@modern-js/core', require);
30
-
31
- const buildSourceCode = async (config, _) => {
29
+ const buildSourceCode = async (api, config, _) => {
32
30
  const {
33
31
  sourceDir,
34
32
  enableTscCompiler
35
33
  } = config;
36
34
  const {
37
35
  appDirectory
38
- } = core.useAppContext();
36
+ } = api.useAppContext();
39
37
  const concurrency = os.cpus().length;
40
38
  const srcRootDir = path.join(appDirectory, sourceDir);
41
39
  const lm = new lg.LoggerManager();
@@ -51,15 +49,15 @@ const buildSourceCode = async (config, _) => {
51
49
  const copyLog = lm.createLoggerText({
52
50
  title: 'Copy Log:'
53
51
  });
54
- const initCodeMapper = utils.getCodeInitMapper(config);
55
- const taskMapper = [...utils.getCodeMapper({
52
+ const initCodeMapper = utils.getCodeInitMapper(api, config);
53
+ const taskMapper = [...utils.getCodeMapper(api, {
56
54
  logger: codeLog,
57
55
  taskPath: require.resolve("../../tasks/build-source-code"),
58
56
  config,
59
57
  willCompilerDirOrFile: sourceDir,
60
58
  initMapper: initCodeMapper,
61
59
  srcRootDir
62
- }), ...(enableTscCompiler ? utils.getDtsMapper(config, dtsLog) : []), {
60
+ }), ...(enableTscCompiler ? utils.getDtsMapper(api, config, dtsLog) : []), {
63
61
  logger: styleLog,
64
62
  taskPath: require.resolve("../../tasks/build-style")
65
63
  }, {
@@ -17,7 +17,7 @@ const buildWatchFeature = _utils.Import.lazy('./build-watch', require);
17
17
 
18
18
  const bp = _utils.Import.lazy('./build-platform', require);
19
19
 
20
- const build = async (config, modernConfig) => {
20
+ const build = async (api, config, modernConfig) => {
21
21
  const {
22
22
  appDirectory,
23
23
  enableWatchMode,
@@ -33,7 +33,7 @@ const build = async (config, modernConfig) => {
33
33
 
34
34
  if (typeof platform === 'boolean' && platform) {
35
35
  if (process.env.RUN_PLATFORM) {
36
- await bp.buildPlatform({
36
+ await bp.buildPlatform(api, {
37
37
  platform: 'all',
38
38
  isTsProject
39
39
  });
@@ -44,7 +44,7 @@ const build = async (config, modernConfig) => {
44
44
 
45
45
  if (typeof platform === 'string') {
46
46
  if (process.env.RUN_PLATFORM) {
47
- await bp.buildPlatform({
47
+ await bp.buildPlatform(api, {
48
48
  platform,
49
49
  isTsProject
50
50
  });
@@ -58,9 +58,9 @@ const build = async (config, modernConfig) => {
58
58
  }
59
59
 
60
60
  if (enableWatchMode) {
61
- await buildWatchFeature.buildInWatchMode(config, modernConfig);
61
+ await buildWatchFeature.buildInWatchMode(api, config, modernConfig);
62
62
  } else {
63
- await buildFeature.buildSourceCode(config, modernConfig);
63
+ await buildFeature.buildSourceCode(api, config, modernConfig);
64
64
  }
65
65
  };
66
66
 
@@ -15,9 +15,7 @@ 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 constants = _utils.Import.lazy('./constants', require);
19
-
20
- const core = _utils.Import.lazy('@modern-js/core', require); // 硬解字符串返回相应格式的对象
18
+ const constants = _utils.Import.lazy('./constants', require); // 硬解字符串返回相应格式的对象
21
19
 
22
20
 
23
21
  const updateMapper = (packageFieldValue, outDir, mapper) => {
@@ -44,13 +42,13 @@ const updateMapper = (packageFieldValue, outDir, mapper) => {
44
42
  }
45
43
  };
46
44
 
47
- const getCodeInitMapper = _ => {
45
+ const getCodeInitMapper = (api, _) => {
48
46
  const {
49
47
  output: {
50
48
  packageFields,
51
49
  packageMode
52
50
  }
53
- } = core.useResolvedConfigContext();
51
+ } = api.useResolvedConfigContext();
54
52
  let initMapper = []; // 如果不存在packageFields配置或者packageFields为空对象,则使用 packageMode
55
53
 
56
54
  if (!packageFields || typeof packageFields === 'object' && Object.keys(packageFields).length === 0) {
@@ -82,7 +80,7 @@ const getCodeInitMapper = _ => {
82
80
 
83
81
  exports.getCodeInitMapper = getCodeInitMapper;
84
82
 
85
- const getCodeMapper = ({
83
+ const getCodeMapper = (api, {
86
84
  logger,
87
85
  taskPath,
88
86
  config,
@@ -92,8 +90,8 @@ const getCodeMapper = ({
92
90
  }) => {
93
91
  const {
94
92
  appDirectory
95
- } = core.useAppContext();
96
- const modernConfig = core.useResolvedConfigContext();
93
+ } = api.useAppContext();
94
+ const modernConfig = api.useResolvedConfigContext();
97
95
  const {
98
96
  output: {
99
97
  enableSourceMap,
@@ -121,11 +119,11 @@ const getCodeMapper = ({
121
119
 
122
120
  exports.getCodeMapper = getCodeMapper;
123
121
 
124
- const getDtsMapper = (config, logger) => {
122
+ const getDtsMapper = (api, config, logger) => {
125
123
  const {
126
124
  appDirectory
127
- } = core.useAppContext();
128
- const modernConfig = core.useResolvedConfigContext();
125
+ } = api.useAppContext();
126
+ const modernConfig = api.useResolvedConfigContext();
129
127
  const {
130
128
  output: {
131
129
  disableTsChecker,
@@ -11,14 +11,13 @@ var _chalk = _interopRequireDefault(require("chalk"));
11
11
 
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
14
- const core = _utils.Import.lazy('@modern-js/core', require);
15
-
16
14
  const inquirer = _utils.Import.lazy('inquirer', require);
17
15
 
18
16
  const color = _utils.Import.lazy('../../utils/color', require);
19
17
 
20
- const showMenu = async config => {
21
- const metas = await core.mountHook().moduleToolsMenu(undefined);
18
+ const showMenu = async (api, config) => {
19
+ const runners = api.useHookRunners();
20
+ const metas = await runners.moduleToolsMenu(undefined);
22
21
 
23
22
  if (metas.length <= 0) {
24
23
  console.info(_chalk.default.yellow('No runnable development features found.\nYou can use the `new` command to enable the development features')); // eslint-disable-next-line no-process-exit
@@ -44,8 +43,9 @@ const showMenu = async config => {
44
43
 
45
44
  exports.showMenu = showMenu;
46
45
 
47
- const devStorybook = async config => {
48
- const metas = await core.mountHook().moduleToolsMenu(undefined);
46
+ const devStorybook = async (api, config) => {
47
+ const runners = api.useHookRunners();
48
+ const metas = await runners.moduleToolsMenu(undefined);
49
49
  const findStorybook = metas.find(meta => meta.value === 'storybook');
50
50
 
51
51
  if (findStorybook) {
@@ -59,8 +59,9 @@ const devStorybook = async config => {
59
59
 
60
60
  exports.devStorybook = devStorybook;
61
61
 
62
- const runSubCmd = async (subCmd, config) => {
63
- const metas = await core.mountHook().moduleToolsMenu(undefined);
62
+ const runSubCmd = async (api, subCmd, config) => {
63
+ const runners = api.useHookRunners();
64
+ const metas = await runners.moduleToolsMenu(undefined);
64
65
  const devMeta = metas.find(meta => meta.value === subCmd || Array.isArray(meta.aliasValues) && meta.aliasValues.includes(subCmd));
65
66
 
66
67
  if (devMeta) {
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.platformBuild = exports.moduleTailwindConfig = exports.moduleSassConfig = exports.moduleLessConfig = exports.lifecycle = exports.buildHooks = void 0;
7
+
8
+ var _plugin = require("@modern-js/plugin");
9
+
10
+ var _core = require("@modern-js/core");
11
+
12
+ const platformBuild = (0, _plugin.createParallelWorkflow)();
13
+ exports.platformBuild = platformBuild;
14
+ const moduleLessConfig = (0, _plugin.createAsyncPipeline)();
15
+ exports.moduleLessConfig = moduleLessConfig;
16
+ const moduleSassConfig = (0, _plugin.createAsyncPipeline)();
17
+ exports.moduleSassConfig = moduleSassConfig;
18
+ const moduleTailwindConfig = (0, _plugin.createAsyncPipeline)();
19
+ exports.moduleTailwindConfig = moduleTailwindConfig;
20
+ const buildHooks = {
21
+ platformBuild,
22
+ moduleLessConfig,
23
+ moduleSassConfig,
24
+ moduleTailwindConfig
25
+ };
26
+ exports.buildHooks = buildHooks;
27
+
28
+ const lifecycle = () => {
29
+ (0, _core.registerHook)({
30
+ moduleLessConfig,
31
+ moduleSassConfig,
32
+ moduleTailwindConfig,
33
+ platformBuild
34
+ });
35
+ };
36
+
37
+ exports.lifecycle = lifecycle;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.moduleToolsMenu = exports.lifecycle = exports.devHooks = void 0;
7
+
8
+ var _plugin = require("@modern-js/plugin");
9
+
10
+ var _core = require("@modern-js/core");
11
+
12
+ const moduleToolsMenu = (0, _plugin.createParallelWorkflow)();
13
+ exports.moduleToolsMenu = moduleToolsMenu;
14
+ const devHooks = {
15
+ moduleToolsMenu
16
+ };
17
+ exports.devHooks = devHooks;
18
+
19
+ const lifecycle = () => {
20
+ (0, _core.registerHook)({
21
+ moduleToolsMenu
22
+ });
23
+ };
24
+
25
+ exports.lifecycle = lifecycle;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "buildLifeCycle", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _build.lifecycle;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "devLifeCycle", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _dev.lifecycle;
16
+ }
17
+ });
18
+ exports.lifecycle = exports.hooks = void 0;
19
+
20
+ var _build = require("./build");
21
+
22
+ var _dev = require("./dev");
23
+
24
+ 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; }
25
+
26
+ 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; }
27
+
28
+ 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; }
29
+
30
+ const lifecycle = () => {
31
+ (0, _dev.lifecycle)();
32
+ (0, _build.lifecycle)();
33
+ };
34
+
35
+ exports.lifecycle = lifecycle;
36
+
37
+ const hooks = _objectSpread(_objectSpread({}, _build.buildHooks), _dev.devHooks);
38
+
39
+ exports.hooks = hooks;
@@ -3,14 +3,25 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.defineConfig = exports.default = void 0;
6
+ exports.default = void 0;
7
+ Object.defineProperty(exports, "defineConfig", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _core.defineConfig;
11
+ }
12
+ });
7
13
 
8
14
  var _utils = require("@modern-js/utils");
9
15
 
10
- const core = _utils.Import.lazy('@modern-js/core', require); // const { createPlugin, usePlugins, defineConfig } = core;
16
+ var _pluginChangeset = _interopRequireDefault(require("@modern-js/plugin-changeset"));
17
+
18
+ var _pluginAnalyze = _interopRequireDefault(require("@modern-js/plugin-analyze"));
19
+
20
+ var _hooks = require("./hooks");
11
21
 
22
+ var _core = require("@modern-js/core");
12
23
 
13
- const hooks = _utils.Import.lazy('@modern-js/module-tools-hooks', require);
24
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
25
 
15
26
  const cli = _utils.Import.lazy('./cli', require);
16
27
 
@@ -20,45 +31,42 @@ const schema = _utils.Import.lazy('./schema', require);
20
31
 
21
32
  const lang = _utils.Import.lazy('./utils/language', require);
22
33
 
23
- const {
24
- defineConfig
25
- } = core;
26
- exports.defineConfig = defineConfig;
27
- core.usePlugins([require.resolve('@modern-js/plugin-changeset/cli'), require.resolve('@modern-js/plugin-analyze/cli')]);
28
-
29
- var _default = core.createPlugin(() => {
30
- const locale = lang.getLocaleLanguage();
31
- local.i18n.changeLanguage({
32
- locale
33
- });
34
- hooks.lifecycle();
35
- return {
36
- validateSchema() {
37
- return schema.addSchema();
38
- },
39
-
40
- config() {
41
- return {
42
- output: {
43
- enableSourceMap: false,
44
- jsPath: 'js'
45
- }
46
- };
47
- },
48
-
49
- commands({
50
- program
51
- }) {
52
- cli.devCli(program);
53
- cli.buildCli(program);
54
- cli.newCli(program, locale); // 便于其他插件辨别
55
-
56
- program.$$libraryName = 'module-tools';
57
- }
58
-
59
- };
60
- }, {
61
- post: ['@modern-js/plugin-analyze', '@modern-js/plugin-changeset']
34
+ var _default = () => ({
35
+ name: '@modern-js/module-tools',
36
+ post: ['@modern-js/plugin-analyze', '@modern-js/plugin-changeset'],
37
+ registerHook: _hooks.hooks,
38
+ usePlugins: [(0, _pluginChangeset.default)(), (0, _pluginAnalyze.default)()],
39
+ setup: api => {
40
+ const locale = lang.getLocaleLanguage();
41
+ local.i18n.changeLanguage({
42
+ locale
43
+ });
44
+ return {
45
+ validateSchema() {
46
+ return schema.addSchema();
47
+ },
48
+
49
+ config() {
50
+ return {
51
+ output: {
52
+ enableSourceMap: false,
53
+ jsPath: 'js'
54
+ }
55
+ };
56
+ },
57
+
58
+ commands({
59
+ program
60
+ }) {
61
+ cli.devCli(program, api);
62
+ cli.buildCli(program, api);
63
+ cli.newCli(program, locale); // 便于其他插件辨别
64
+
65
+ program.$$libraryName = 'module-tools';
66
+ }
67
+
68
+ };
69
+ }
62
70
  });
63
71
 
64
72
  exports.default = _default;
@@ -47,7 +47,8 @@ const runBabelCompiler = async (willCompilerFiles, config, babelConfig = {}) =>
47
47
  enableVirtualDist: true,
48
48
  rootDir: srcRootDir,
49
49
  filenames: willCompilerFiles,
50
- distDir
50
+ distDir,
51
+ ignore: ['*.d.ts']
51
52
  }, babelConfig);
52
53
  };
53
54
 
@@ -16,7 +16,7 @@ const compiler = _utils.Import.lazy('@modern-js/style-compiler', require);
16
16
 
17
17
  const glob = _utils.Import.lazy('glob', require);
18
18
 
19
- const hooks = _utils.Import.lazy('@modern-js/module-tools-hooks', require);
19
+ const hooks = _utils.Import.lazy('../hooks', require);
20
20
 
21
21
  const STYLE_DIRS = 'styles';
22
22
  const SRC_STYLE_DIRS = 'src';