@modern-js/module-tools 1.4.3 → 1.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/dist/js/modern/features/build/build-platform.js +1 -2
  3. package/dist/js/modern/features/build/build-watch.js +1 -2
  4. package/dist/js/modern/features/build/build.js +2 -5
  5. package/dist/js/modern/features/dev/index.js +1 -2
  6. package/dist/js/modern/hooks/build.js +20 -0
  7. package/dist/js/modern/hooks/dev.js +11 -0
  8. package/dist/js/modern/hooks/index.js +14 -0
  9. package/dist/js/modern/index.js +1 -1
  10. package/dist/js/modern/tasks/build-source-code.js +1 -2
  11. package/dist/js/modern/tasks/build-style.js +2 -3
  12. package/dist/js/modern/tasks/build-watch-style.js +3 -6
  13. package/dist/js/modern/tasks/copy-assets.js +1 -2
  14. package/dist/js/modern/tasks/generator-dts/index.js +8 -11
  15. package/dist/js/modern/tasks/generator-dts/utils.js +11 -3
  16. package/dist/js/modern/utils/babel.js +2 -19
  17. package/dist/js/modern/utils/copy.js +1 -2
  18. package/dist/js/modern/utils/logger.js +1 -2
  19. package/dist/js/node/features/build/build-platform.js +2 -3
  20. package/dist/js/node/features/build/build-watch.js +1 -3
  21. package/dist/js/node/features/build/build.js +1 -6
  22. package/dist/js/node/features/dev/index.js +2 -6
  23. package/dist/js/node/hooks/build.js +37 -0
  24. package/dist/js/node/hooks/dev.js +25 -0
  25. package/dist/js/node/hooks/index.js +39 -0
  26. package/dist/js/node/index.js +2 -2
  27. package/dist/js/node/tasks/build-source-code.js +3 -3
  28. package/dist/js/node/tasks/build-style.js +2 -4
  29. package/dist/js/node/tasks/build-watch-style.js +3 -7
  30. package/dist/js/node/tasks/copy-assets.js +1 -3
  31. package/dist/js/node/tasks/generator-dts/index.js +8 -16
  32. package/dist/js/node/tasks/generator-dts/utils.js +18 -8
  33. package/dist/js/node/utils/babel.js +1 -18
  34. package/dist/js/node/utils/copy.js +1 -2
  35. package/dist/js/node/utils/logger.js +5 -7
  36. package/dist/types/cli/build.d.ts +1 -1
  37. package/dist/types/cli/dev.d.ts +1 -1
  38. package/dist/types/cli/new.d.ts +1 -1
  39. package/dist/types/hooks/build.d.ts +46 -0
  40. package/dist/types/hooks/dev.d.ts +18 -0
  41. package/dist/types/hooks/index.d.ts +26 -0
  42. package/dist/types/tasks/generator-dts/utils.d.ts +2 -1
  43. package/dist/types/utils/babel.d.ts +2 -3
  44. package/jest.config.js +0 -3
  45. package/package.json +22 -25
  46. package/tests/dev-cli.test.ts +0 -59
  47. package/tests/dev-command.test.ts +0 -70
  48. package/tests/dev-feature.test.ts +0 -78
  49. package/tests/fixtures/tspaths/a.ts +0 -1
  50. package/tests/fixtures/tspaths/b.ts +0 -1
  51. package/tests/generator-dts-utils.test.ts +0 -10
  52. package/tests/generator-dts.test.ts +0 -48
  53. package/tests/index.test.ts +0 -7
  54. package/tests/tsconfig.json +0 -11
  55. package/tests/tspaths-transform.test.ts +0 -21
@@ -8,19 +8,16 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
8
8
 
9
9
  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; }
10
10
 
11
- /* eslint-disable max-statements */
12
11
  const logger = _utils.Import.lazy('../features/build/logger', require);
13
12
 
14
13
  const cssConfig = _utils.Import.lazy('@modern-js/css-config', require);
15
14
 
16
- const hooks = _utils.Import.lazy('@modern-js/module-tools-hooks', require);
15
+ const hooks = _utils.Import.lazy('../hooks', require);
17
16
 
18
17
  const core = _utils.Import.lazy('@modern-js/core', require);
19
18
 
20
19
  const compiler = _utils.Import.lazy('@modern-js/style-compiler', require);
21
20
 
22
- const glob = _utils.Import.lazy('glob', require);
23
-
24
21
  const STYLE_DIRS = 'styles';
25
22
  const SRC_STYLE_DIRS = 'src';
26
23
 
@@ -60,7 +57,7 @@ const copyOriginStyleFiles = ({
60
57
  targetDir,
61
58
  outputDir
62
59
  }) => {
63
- const styleFiles = glob.sync(`${targetDir}/**/*.{css,sass,scss,less}`);
60
+ const styleFiles = _utils.glob.sync(`${targetDir}/**/*.{css,sass,scss,less}`);
64
61
 
65
62
  if (styleFiles.length > 0) {
66
63
  _utils.fs.ensureDirSync(outputDir);
@@ -232,5 +229,4 @@ const taskMain = async ({
232
229
  console.error(e);
233
230
  }
234
231
  });
235
- })();
236
- /* eslint-enable max-statements */
232
+ })();
@@ -10,8 +10,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
10
10
 
11
11
  const argv = _utils.Import.lazy('process.argv', require);
12
12
 
13
- const glob = _utils.Import.lazy('glob', require);
14
-
15
13
  const core = _utils.Import.lazy('@modern-js/core', require);
16
14
 
17
15
  const copyUtils = _utils.Import.lazy('../utils/copy', require);
@@ -23,7 +21,7 @@ const copyAssets = ({
23
21
  targetDir,
24
22
  outputDir
25
23
  }) => {
26
- const assetsFiles = glob.sync(`${targetDir}/**/*.*`, {
24
+ const assetsFiles = _utils.glob.sync(`${targetDir}/**/*.*`, {
27
25
  ignore: ['**/*.{js,jsx,ts,tsx,d.ts,scss,less,css,sass}']
28
26
  });
29
27
 
@@ -1,17 +1,11 @@
1
1
  "use strict";
2
2
 
3
- var path = _interopRequireWildcard(require("path"));
4
-
5
3
  var _utils = require("@modern-js/utils");
6
4
 
7
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
8
-
9
- 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; }
5
+ var _utils2 = require("./utils");
10
6
 
11
7
  const core = _utils.Import.lazy('@modern-js/core', require);
12
8
 
13
- const execa = _utils.Import.lazy('execa', require);
14
-
15
9
  const JSON5 = _utils.Import.lazy('json5', require);
16
10
 
17
11
  const argv = _utils.Import.lazy('process.argv', require);
@@ -75,9 +69,9 @@ const generatorDts = async (_, config) => {
75
69
  sourceDir: sourceDirName
76
70
  });
77
71
  removeTsconfigPath = willDeleteTsconfigPath;
78
- const tscBinFile = path.join(appDirectory, './node_modules/.bin/tsc');
72
+ const tscBinFile = (0, _utils2.getTscBinPath)(appDirectory);
79
73
  const watchParams = watch ? ['-w'] : [];
80
- const childProgress = execa(tscBinFile, ['-p', willDeleteTsconfigPath, ...watchParams], {
74
+ const childProgress = (0, _utils.execa)(tscBinFile, ['-p', willDeleteTsconfigPath, ...watchParams], {
81
75
  stdio: 'pipe',
82
76
  cwd: appDirectory
83
77
  });
@@ -88,17 +82,15 @@ const generatorDts = async (_, config) => {
88
82
 
89
83
  try {
90
84
  await childProgress;
91
- console.info('[Tsc Compiler]: Successfully');
85
+ console.info('[TSC Compiler]: Successfully');
92
86
  } catch (e) {
93
87
  if (!tsCheck) {
94
88
  console.info(`There are some type warnings, which can be checked by configuring 'output.disableTsChecker = false'`);
89
+ } // 通过使用 execa,可以将 tsc 的 data 类型的报错信息变为异常错误信息
90
+ else if ((0, _utils.isObject)(e) && e.stdout) {
91
+ console.error(e.stdout);
95
92
  } else {
96
- const isRecord = input => typeof input === 'object'; // 通过使用 execa,可以将tsc 的 data 类型的报错信息变为异常错误信息
97
-
98
-
99
- if (isRecord(e)) {
100
- console.error(e.stdout);
101
- }
93
+ console.error(e);
102
94
  }
103
95
  }
104
96
 
@@ -3,12 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.resolveAlias = exports.generatorTsConfig = void 0;
6
+ exports.resolveAlias = exports.getTscBinPath = exports.generatorTsConfig = void 0;
7
7
 
8
8
  var path = _interopRequireWildcard(require("path"));
9
9
 
10
10
  var _utils = require("@modern-js/utils");
11
11
 
12
+ var _lodash = require("@modern-js/utils/lodash");
13
+
12
14
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
15
 
14
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; }
@@ -19,16 +21,12 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
19
21
 
20
22
  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; }
21
23
 
22
- const glob = _utils.Import.lazy('glob', require);
23
-
24
24
  const babel = _utils.Import.lazy('../../utils/babel', require);
25
25
 
26
26
  const tsPathsTransform = _utils.Import.lazy('../../utils/tspaths-transform', require);
27
27
 
28
28
  const constants = _utils.Import.lazy('../constants', require);
29
29
 
30
- const deepMerge = _utils.Import.lazy('lodash.merge', require);
31
-
32
30
  const generatorTsConfig = (projectTsconfig, {
33
31
  appDirectory,
34
32
  distDir,
@@ -69,7 +67,7 @@ const generatorTsConfig = (projectTsconfig, {
69
67
 
70
68
  _utils.fs.ensureFileSync(tempTsconfigPath);
71
69
 
72
- _utils.fs.writeJSONSync(tempTsconfigPath, deepMerge(recommendOption, projectTsconfig, // 此处是必须要覆盖用户默认配置
70
+ _utils.fs.writeJSONSync(tempTsconfigPath, (0, _lodash.merge)(recommendOption, projectTsconfig, // 此处是必须要覆盖用户默认配置
73
71
  resetConfig));
74
72
 
75
73
  return tempTsconfigPath;
@@ -85,7 +83,7 @@ const resolveAlias = (modernConfig, config, watchFilenames = []) => {
85
83
  '@': ['./src']
86
84
  };
87
85
  const dtsDistPath = `${config.distDir}/**/*.d.ts`;
88
- const dtsFilenames = watchFilenames.length > 0 ? watchFilenames : glob.sync(dtsDistPath, {
86
+ const dtsFilenames = watchFilenames.length > 0 ? watchFilenames : _utils.glob.sync(dtsDistPath, {
89
87
  absolute: true
90
88
  });
91
89
  const alias = babel.getFinalAlias(modernConfig, {
@@ -105,4 +103,16 @@ const resolveAlias = (modernConfig, config, watchFilenames = []) => {
105
103
  }
106
104
  };
107
105
 
108
- exports.resolveAlias = resolveAlias;
106
+ exports.resolveAlias = resolveAlias;
107
+
108
+ const getTscBinPath = appDirectory => {
109
+ const tscBinFile = path.join(appDirectory, './node_modules/.bin/tsc');
110
+
111
+ if (!_utils.fs.existsSync(tscBinFile)) {
112
+ throw new Error('Failed to excute the `tsc` command, please check if `typescript` is installed correctly in the current directory.');
113
+ }
114
+
115
+ return tscBinFile;
116
+ };
117
+
118
+ exports.getTscBinPath = getTscBinPath;
@@ -84,25 +84,8 @@ const resolveBabelConfig = (appDirectory, modernConfig, option) => {
84
84
  }); // Preventing warning when files are too large
85
85
 
86
86
  internalBabelConfig.compact = false;
87
- const babelChain = (0, _babelPresetModule.getModuleBabelChain)({
88
- appDirectory,
89
- enableReactPreset: true,
90
- enableTypescriptPreset: true,
91
- alias: aliasConfig,
92
- envVars,
93
- globalVars,
94
- lodashOptions,
95
- jsxTransformRuntime,
96
- importStyle
97
- }, {
98
- type: option.type,
99
- syntax: option.syntax
100
- });
101
87
  const userBabelConfig = modernConfig.tools.babel;
102
- return (0, _utils.applyOptionsChain)(internalBabelConfig, // TODO: 感觉 userBabelConfig 的类型应该是TransformOptions
103
- userBabelConfig, {
104
- chain: babelChain
105
- });
88
+ return (0, _utils.applyOptionsChain)(internalBabelConfig, userBabelConfig);
106
89
  };
107
90
 
108
91
  exports.resolveBabelConfig = resolveBabelConfig;
@@ -23,8 +23,7 @@ const globby = _utils.Import.lazy('globby', require);
23
23
 
24
24
  const fastGlob = _utils.Import.lazy('fast-glob', require);
25
25
 
26
- const normalizePath = _utils.Import.lazy('normalize-path', require); // eslint-disable-next-line max-statements
27
-
26
+ const normalizePath = _utils.Import.lazy('normalize-path', require);
28
27
 
29
28
  const copyTask = async option => {
30
29
  const {
@@ -11,8 +11,6 @@ var _utils = require("@modern-js/utils");
11
11
 
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
14
- const chalk = _utils.Import.lazy('chalk', require);
15
-
16
14
  const clearFlag = '\x1Bc';
17
15
  exports.clearFlag = clearFlag;
18
16
 
@@ -89,16 +87,16 @@ class LoggerManager extends _events.default {
89
87
  error: true
90
88
  },
91
89
  colors = {
92
- data: chalk.green,
93
- error: chalk.red,
94
- warning: chalk.yellow
90
+ data: _utils.chalk.green,
91
+ error: _utils.chalk.red,
92
+ warning: _utils.chalk.yellow
95
93
  }
96
94
  } = config;
97
95
 
98
96
  if (event.data) {
99
97
  stdout === null || stdout === void 0 ? void 0 : stdout.on('data', chunk => {
100
98
  const data = chunk.toString();
101
- const content = colors.data ? colors.data(data) : chalk.green(data);
99
+ const content = colors.data ? colors.data(data) : _utils.chalk.green(data);
102
100
  loggerText.append(content);
103
101
  this.emit('data');
104
102
  });
@@ -107,7 +105,7 @@ class LoggerManager extends _events.default {
107
105
  if (event.error) {
108
106
  stdout === null || stdout === void 0 ? void 0 : stdout.on('error', error => {
109
107
  const data = error.message;
110
- const content = colors.error ? colors.error(data) : chalk.red(data);
108
+ const content = colors.error ? colors.error(data) : _utils.chalk.red(data);
111
109
  loggerText.append(content);
112
110
  this.emit('data');
113
111
  });
@@ -1,3 +1,3 @@
1
- import type { Command } from 'commander';
1
+ import { Command } from '@modern-js/utils';
2
2
  import type { PluginAPI } from '@modern-js/core';
3
3
  export declare const buildCli: (program: Command, api: PluginAPI) => void;
@@ -1,3 +1,3 @@
1
+ import { Command } from '@modern-js/utils';
1
2
  import type { PluginAPI } from '@modern-js/core';
2
- import type { Command } from 'commander';
3
3
  export declare const devCli: (program: Command, api: PluginAPI) => void;
@@ -1,2 +1,2 @@
1
- import type { Command } from 'commander';
1
+ import { Command } from '@modern-js/utils';
2
2
  export declare const newCli: (program: Command, locale?: string | undefined) => void;
@@ -0,0 +1,46 @@
1
+ import { NormalizedConfig } from '@modern-js/core';
2
+ import { LessOption, SassOptions } from '@modern-js/style-compiler';
3
+ export interface PlatformBuildOption {
4
+ isTsProject: boolean;
5
+ }
6
+ export declare const platformBuild: import("@modern-js/plugin").ParallelWorkflow<PlatformBuildOption, {
7
+ name: string;
8
+ title: string;
9
+ taskPath: string;
10
+ params: string[];
11
+ }>;
12
+ export declare const moduleLessConfig: import("@modern-js/plugin").AsyncPipeline<{
13
+ modernConfig: NormalizedConfig;
14
+ }, LessOption | undefined>;
15
+ export declare const moduleSassConfig: import("@modern-js/plugin").AsyncPipeline<{
16
+ modernConfig: NormalizedConfig;
17
+ }, SassOptions<"sync"> | undefined>;
18
+ export declare const moduleTailwindConfig: import("@modern-js/plugin").AsyncPipeline<{
19
+ modernConfig: NormalizedConfig;
20
+ }, any>;
21
+ export declare const buildHooks: {
22
+ platformBuild: import("@modern-js/plugin").ParallelWorkflow<PlatformBuildOption, {
23
+ name: string;
24
+ title: string;
25
+ taskPath: string;
26
+ params: string[];
27
+ }>;
28
+ moduleLessConfig: import("@modern-js/plugin").AsyncPipeline<{
29
+ modernConfig: NormalizedConfig;
30
+ }, LessOption | undefined>;
31
+ moduleSassConfig: import("@modern-js/plugin").AsyncPipeline<{
32
+ modernConfig: NormalizedConfig;
33
+ }, SassOptions<"sync"> | undefined>;
34
+ moduleTailwindConfig: import("@modern-js/plugin").AsyncPipeline<{
35
+ modernConfig: NormalizedConfig;
36
+ }, any>;
37
+ };
38
+ export declare const lifecycle: () => void;
39
+ declare module '@modern-js/core' {
40
+ interface Hooks {
41
+ platformBuild: typeof platformBuild;
42
+ moduleLessConfig: typeof moduleLessConfig;
43
+ moduleSassConfig: typeof moduleSassConfig;
44
+ moduleTailwindConfig: typeof moduleTailwindConfig;
45
+ }
46
+ }
@@ -0,0 +1,18 @@
1
+ export declare const moduleToolsMenu: import("@modern-js/plugin").ParallelWorkflow<undefined, {
2
+ name: string;
3
+ value: string;
4
+ runTask: (p: any) => void | Promise<void>;
5
+ }>;
6
+ export declare const devHooks: {
7
+ moduleToolsMenu: import("@modern-js/plugin").ParallelWorkflow<undefined, {
8
+ name: string;
9
+ value: string;
10
+ runTask: (p: any) => void | Promise<void>;
11
+ }>;
12
+ };
13
+ export declare const lifecycle: () => void;
14
+ declare module '@modern-js/core' {
15
+ interface Hooks {
16
+ moduleToolsMenu: typeof moduleToolsMenu;
17
+ }
18
+ }
@@ -0,0 +1,26 @@
1
+ import { lifecycle as buildLifeCycle } from './build';
2
+ import { lifecycle as devLifeCycle } from './dev';
3
+ export { buildLifeCycle, devLifeCycle };
4
+ export declare const lifecycle: () => void;
5
+ export declare const hooks: {
6
+ moduleToolsMenu: import("@modern-js/plugin").ParallelWorkflow<undefined, {
7
+ name: string;
8
+ value: string;
9
+ runTask: (p: any) => void | Promise<void>;
10
+ }>;
11
+ platformBuild: import("@modern-js/plugin").ParallelWorkflow<import("./build").PlatformBuildOption, {
12
+ name: string;
13
+ title: string;
14
+ taskPath: string;
15
+ params: string[];
16
+ }>;
17
+ moduleLessConfig: import("@modern-js/plugin").AsyncPipeline<{
18
+ modernConfig: import("@modern-js/core").NormalizedConfig;
19
+ }, import("@modern-js/style-compiler").LessOption | undefined>;
20
+ moduleSassConfig: import("@modern-js/plugin").AsyncPipeline<{
21
+ modernConfig: import("@modern-js/core").NormalizedConfig;
22
+ }, import("@modern-js/style-compiler").SassOptions<"sync"> | undefined>;
23
+ moduleTailwindConfig: import("@modern-js/plugin").AsyncPipeline<{
24
+ modernConfig: import("@modern-js/core").NormalizedConfig;
25
+ }, any>;
26
+ };
@@ -20,4 +20,5 @@ export declare const generatorTsConfig: (projectTsconfig: ITsconfig, {
20
20
  distDir: string;
21
21
  sourceDir?: string | undefined;
22
22
  }) => string;
23
- export declare const resolveAlias: (modernConfig: NormalizedConfig, config: IGeneratorConfig, watchFilenames?: string[]) => void;
23
+ export declare const resolveAlias: (modernConfig: NormalizedConfig, config: IGeneratorConfig, watchFilenames?: string[]) => void;
24
+ export declare const getTscBinPath: (appDirectory: string) => string;
@@ -1,8 +1,7 @@
1
- import { TransformOptions } from '@babel/core';
2
- import { NormalizedConfig } from '@modern-js/core';
1
+ import type { NormalizedConfig } from '@modern-js/core';
3
2
  import { IPackageModeValue } from '../types';
4
3
  export declare const getFinalAlias: any;
5
4
  export declare const resolveBabelConfig: (appDirectory: string, modernConfig: NormalizedConfig, option: Pick<IPackageModeValue, 'syntax' | 'type'> & {
6
5
  sourceAbsDir: string;
7
6
  tsconfigPath: string;
8
- }) => TransformOptions;
7
+ }) => import("@modern-js/core").TransformOptions;
package/jest.config.js CHANGED
@@ -1,10 +1,7 @@
1
1
  const sharedConfig = require('@scripts/jest-config');
2
2
 
3
- console.info(sharedConfig.coveragePathIgnorePatterns);
4
-
5
3
  /** @type {import('@jest/types').Config.InitialOptions} */
6
4
  module.exports = {
7
- // eslint-disable-next-line node/no-unsupported-features/es-syntax
8
5
  ...sharedConfig,
9
6
  rootDir: __dirname,
10
7
  };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.4.3",
14
+ "version": "1.4.6",
15
15
  "bin": {
16
16
  "modern": "./bin/modern.js"
17
17
  },
@@ -40,39 +40,38 @@
40
40
  },
41
41
  "typesVersions": {
42
42
  "*": {
43
+ "types": [
44
+ "./lib/types.d.ts"
45
+ ],
43
46
  "type": [
44
47
  "./lib/types.d.ts"
45
48
  ]
46
49
  }
47
50
  },
48
51
  "dependencies": {
49
- "@modern-js/core": "^1.6.0",
50
52
  "@babel/generator": "^7.15.0",
51
53
  "@babel/parser": "^7.15.2",
52
54
  "@babel/runtime": "^7",
53
55
  "@babel/traverse": "^7.15.0",
54
56
  "@babel/types": "^7.17.0",
55
- "@modern-js/babel-compiler": "^1.2.2",
56
- "@modern-js/babel-preset-module": "^1.3.1",
57
- "@modern-js/css-config": "^1.2.2",
58
- "@modern-js/i18n-cli-language-detector": "^1.2.1",
59
- "@modern-js/module-tools-hooks": "^1.2.3",
60
- "@modern-js/new-action": "^1.3.3",
61
- "@modern-js/plugin-analyze": "^1.3.4",
62
- "@modern-js/plugin-changeset": "^1.2.3",
63
- "@modern-js/plugin-fast-refresh": "^1.2.2",
64
- "@modern-js/plugin-i18n": "^1.2.1",
65
- "@modern-js/style-compiler": "^1.2.2",
66
- "@modern-js/utils": "^1.3.6",
67
- "chalk": "^4.1.2",
57
+ "@modern-js/babel-compiler": "^1.2.3",
58
+ "@modern-js/babel-preset-module": "^1.3.2",
59
+ "@modern-js/core": "^1.8.0",
60
+ "@modern-js/css-config": "^1.2.4",
61
+ "@modern-js/i18n-cli-language-detector": "^1.2.2",
62
+ "@modern-js/new-action": "^1.3.6",
63
+ "@modern-js/plugin": "^1.3.3",
64
+ "@modern-js/plugin-analyze": "^1.4.0",
65
+ "@modern-js/plugin-changeset": "^1.2.5",
66
+ "@modern-js/plugin-fast-refresh": "^1.2.4",
67
+ "@modern-js/plugin-i18n": "^1.2.4",
68
+ "@modern-js/style-compiler": "^1.2.4",
69
+ "@modern-js/utils": "^1.5.0",
68
70
  "dotenv": "^10.0.0",
69
- "execa": "^5.1.1",
70
71
  "fast-glob": "^3.2.5",
71
- "glob": "^7.1.7",
72
72
  "globby": "^11",
73
73
  "inquirer": "^8.1.5",
74
74
  "json5": "^2.2.0",
75
- "lodash.merge": "^4.6.2",
76
75
  "normalize-path": "^3.0.0",
77
76
  "p-map": "^4",
78
77
  "process.argv": "^0.6.0",
@@ -80,23 +79,21 @@
80
79
  },
81
80
  "devDependencies": {
82
81
  "@babel/preset-typescript": "^7.15.0",
83
- "@modern-js/babel-chain": "^1.2.1",
82
+ "@modern-js/babel-chain": "^1.2.2",
83
+ "@scripts/build": "0.0.0",
84
+ "@scripts/jest-config": "0.0.0",
84
85
  "@types/babel__core": "^7.1.15",
85
86
  "@types/babel__generator": "^7.6.3",
86
87
  "@types/babel__traverse": "^7.14.2",
87
88
  "@types/glob": "^7.1.4",
88
89
  "@types/inquirer": "^8.1.1",
89
90
  "@types/jest": "^26",
90
- "@types/lodash.merge": "^4.6.6",
91
91
  "@types/node": "^14",
92
92
  "@types/normalize-path": "^3.0.0",
93
- "commander": "^8.1.0",
94
- "typescript": "^4",
95
- "@scripts/build": "0.0.0",
96
- "jest": "^27",
97
93
  "@types/react": "^17",
98
94
  "@types/react-dom": "^17",
99
- "@scripts/jest-config": "0.0.0"
95
+ "jest": "^27",
96
+ "typescript": "^4"
100
97
  },
101
98
  "sideEffects": false,
102
99
  "modernConfig": {
@@ -1,59 +0,0 @@
1
- import { manager } from '@modern-js/core';
2
- import { program } from 'commander';
3
- import { devCli } from '../src/cli/dev';
4
-
5
- const mockCommandDev = jest.fn();
6
-
7
- describe('dev cli subCmd', () => {
8
- beforeEach(() => {
9
- jest.resetAllMocks();
10
- jest.mock('../src/commands', () => ({
11
- __esModule: true,
12
- dev: mockCommandDev,
13
- }));
14
- });
15
- it('should be storybook with "dev storybook"', async () => {
16
- const mockAPI = {
17
- useAppContext: jest.fn((): any => ({
18
- existSrc: false,
19
- distDirectory: '',
20
- })),
21
- useResolvedConfigContext: jest.fn(),
22
- useHookRunners: (): any => ({}),
23
- };
24
- const cloned = manager.clone(mockAPI);
25
- cloned.usePlugin({
26
- setup(api) {
27
- devCli(program, api);
28
- program.parse(['', '', 'dev', 'storybook']);
29
- expect(mockCommandDev.mock.calls[0][2]).toBe('storybook');
30
- },
31
- });
32
- await cloned.init();
33
- });
34
-
35
- it('should be undefined with "dev"', async () => {
36
- const mockBeforeBuild = jest.fn();
37
- const mockAfterBuild = jest.fn();
38
- const mockAPI = {
39
- useAppContext: jest.fn((): any => ({
40
- existSrc: false,
41
- distDirectory: '',
42
- })),
43
- useResolvedConfigContext: jest.fn(),
44
- useHookRunners: (): any => ({
45
- afterBuild: mockAfterBuild,
46
- beforeBuild: mockBeforeBuild,
47
- }),
48
- };
49
- const cloned = manager.clone(mockAPI);
50
- cloned.usePlugin({
51
- setup(api) {
52
- devCli(program, api);
53
- program.parse(['', '', 'dev']);
54
- expect(mockCommandDev.mock.calls[0][2]).toBe(undefined);
55
- },
56
- });
57
- await cloned.init();
58
- });
59
- });
@@ -1,70 +0,0 @@
1
- import { manager } from '@modern-js/core';
2
- import { dev } from '../src/commands/dev';
3
-
4
- const mockRunSubCmd = jest.fn();
5
- jest.mock('../src/features/dev', () => ({
6
- __esModule: true,
7
- runSubCmd: mockRunSubCmd,
8
- devStorybook: jest.fn(),
9
- }));
10
-
11
- jest.mock('dotenv', () => ({
12
- __esModule: true,
13
- config: jest.fn(),
14
- }));
15
-
16
- jest.mock('../src/utils/valide', () => ({
17
- __esModule: true,
18
- valideBeforeTask: jest.fn(),
19
- }));
20
-
21
- jest.mock('../src/utils/tsconfig', () => ({
22
- __esModule: true,
23
- existTsConfigFile: jest.fn(),
24
- }));
25
-
26
- describe('dev command with subCmd', () => {
27
- beforeEach(() => {
28
- jest.clearAllMocks();
29
- });
30
- it('should call runSubCmd with storybook param', async () => {
31
- const mockAPI = {
32
- useAppContext: jest.fn((): any => ({
33
- existSrc: false,
34
- distDirectory: '',
35
- appDirectory: '',
36
- })),
37
- useResolvedConfigContext: jest.fn(),
38
- };
39
-
40
- const cloned = manager.clone(mockAPI);
41
- cloned.usePlugin({
42
- async setup(api) {
43
- await dev(api, { tsconfig: 'tsconfig.json' }, 'storybook');
44
- expect(mockRunSubCmd.mock.calls.length).toBe(1);
45
- expect(mockRunSubCmd.mock.calls[0][1]).toBe('storybook');
46
- },
47
- });
48
- await cloned.init();
49
- });
50
-
51
- it('should not call runSubCmd with nothing param', async () => {
52
- const mockAPI = {
53
- useAppContext: jest.fn((): any => ({
54
- existSrc: false,
55
- distDirectory: '',
56
- appDirectory: '',
57
- })),
58
- useResolvedConfigContext: jest.fn(),
59
- };
60
-
61
- const cloned = manager.clone(mockAPI);
62
- cloned.usePlugin({
63
- async setup(api) {
64
- await dev(api, { tsconfig: 'tsconfig.json' });
65
- expect(mockRunSubCmd.mock.calls.length).toBe(0);
66
- },
67
- });
68
- await cloned.init();
69
- });
70
- });