@modern-js/module-tools 1.4.4 → 1.5.0

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 (47) hide show
  1. package/CHANGELOG.md +89 -0
  2. package/dist/js/modern/commands/build.js +1 -2
  3. package/dist/js/modern/commands/dev.js +1 -2
  4. package/dist/js/modern/features/build/build-platform.js +1 -2
  5. package/dist/js/modern/features/build/build-watch.js +1 -2
  6. package/dist/js/modern/features/build/build.js +2 -5
  7. package/dist/js/modern/features/dev/index.js +1 -3
  8. package/dist/js/modern/tasks/build-source-code.js +1 -2
  9. package/dist/js/modern/tasks/build-style.js +1 -2
  10. package/dist/js/modern/tasks/build-watch-style.js +2 -5
  11. package/dist/js/modern/tasks/copy-assets.js +1 -2
  12. package/dist/js/modern/tasks/generator-dts/index.js +2 -4
  13. package/dist/js/modern/tasks/generator-dts/utils.js +2 -3
  14. package/dist/js/modern/utils/copy.js +2 -5
  15. package/dist/js/modern/utils/logger.js +1 -2
  16. package/dist/js/modern/utils/tsconfig.js +1 -2
  17. package/dist/js/node/commands/build.js +3 -3
  18. package/dist/js/node/commands/dev.js +3 -3
  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 +3 -9
  23. package/dist/js/node/tasks/build-source-code.js +3 -3
  24. package/dist/js/node/tasks/build-style.js +1 -3
  25. package/dist/js/node/tasks/build-watch-style.js +2 -6
  26. package/dist/js/node/tasks/copy-assets.js +1 -3
  27. package/dist/js/node/tasks/generator-dts/index.js +2 -6
  28. package/dist/js/node/tasks/generator-dts/utils.js +4 -6
  29. package/dist/js/node/utils/copy.js +3 -8
  30. package/dist/js/node/utils/logger.js +5 -7
  31. package/dist/js/node/utils/tsconfig.js +1 -3
  32. package/dist/types/cli/build.d.ts +1 -1
  33. package/dist/types/cli/dev.d.ts +1 -1
  34. package/dist/types/cli/new.d.ts +1 -1
  35. package/dist/types/utils/babel.d.ts +1 -1
  36. package/package.json +15 -27
  37. package/tests/dev-cli.test.ts +0 -59
  38. package/tests/dev-command.test.ts +0 -70
  39. package/tests/dev-feature.test.ts +0 -78
  40. package/tests/fixtures/tspaths/a.ts +0 -1
  41. package/tests/fixtures/tspaths/b.ts +0 -1
  42. package/tests/generate-dts.test.ts +0 -9
  43. package/tests/generator-dts-utils.test.ts +0 -10
  44. package/tests/generator-dts.test.ts +0 -48
  45. package/tests/index.test.ts +0 -7
  46. package/tests/tsconfig.json +0 -11
  47. package/tests/tspaths-transform.test.ts +0 -21
package/CHANGELOG.md CHANGED
@@ -1,5 +1,94 @@
1
1
  # @modern-js/module-tools
2
2
 
3
+ ## 1.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 0b26b93b: feat: prebundle all dependencies of @modern-js/core
8
+
9
+ ### Patch Changes
10
+
11
+ - 592edabc: feat: prebundle url-join,mime-types,json5,fast-glob,globby,ora,inquirer
12
+ - 895fa0ff: chore: using "workspace:\*" in devDependencies
13
+ - Updated dependencies [2d155c4c]
14
+ - Updated dependencies [123e432d]
15
+ - Updated dependencies [e5a9b26d]
16
+ - Updated dependencies [0b26b93b]
17
+ - Updated dependencies [123e432d]
18
+ - Updated dependencies [f9f66ef9]
19
+ - Updated dependencies [592edabc]
20
+ - Updated dependencies [f9f66ef9]
21
+ - Updated dependencies [895fa0ff]
22
+ - Updated dependencies [3578913e]
23
+ - Updated dependencies [1c3beab3]
24
+ - @modern-js/utils@1.6.0
25
+ - @modern-js/core@1.9.0
26
+ - @modern-js/plugin-analyze@1.4.1
27
+ - @modern-js/new-action@1.3.7
28
+ - @modern-js/babel-preset-module@1.3.3
29
+ - @modern-js/css-config@1.2.4
30
+ - @modern-js/plugin-changeset@1.2.5
31
+ - @modern-js/plugin-fast-refresh@1.2.4
32
+
33
+ ## 1.4.6
34
+
35
+ ### Patch Changes
36
+
37
+ - 04ae5262: chore: bump @modern-js/utils to v1.4.1 in dependencies
38
+ - 60f7d8bf: feat: add tests dir to npmignore
39
+ - 3bf4f8b0: feat: support start api server only
40
+ - 305e0bb4: fix: commander.commandsMap typing not work
41
+ - Updated dependencies [a4330c73]
42
+ - Updated dependencies [b8599d09]
43
+ - Updated dependencies [6cffe99d]
44
+ - Updated dependencies [04ae5262]
45
+ - Updated dependencies [60f7d8bf]
46
+ - Updated dependencies [e4cec1ce]
47
+ - Updated dependencies [3b7aa8bb]
48
+ - Updated dependencies [5dbbeb57]
49
+ - Updated dependencies [ebfcbb35]
50
+ - Updated dependencies [3bf4f8b0]
51
+ - Updated dependencies [305e0bb4]
52
+ - Updated dependencies [ebfcbb35]
53
+ - @modern-js/core@1.8.0
54
+ - @modern-js/utils@1.5.0
55
+ - @modern-js/babel-preset-module@1.3.2
56
+ - @modern-js/css-config@1.2.4
57
+ - @modern-js/i18n-cli-language-detector@1.2.2
58
+ - @modern-js/plugin-changeset@1.2.5
59
+ - @modern-js/plugin-fast-refresh@1.2.4
60
+ - @modern-js/plugin-i18n@1.2.4
61
+ - @modern-js/new-action@1.3.6
62
+ - @modern-js/babel-compiler@1.2.3
63
+ - @modern-js/style-compiler@1.2.4
64
+ - @modern-js/plugin@1.3.3
65
+ - @modern-js/plugin-analyze@1.4.0
66
+
67
+ ## 1.4.5
68
+
69
+ ### Patch Changes
70
+
71
+ - 07a4887e: feat: prebundle commander and signale to @modern-js/utils
72
+ - 17d0cc46: feat: prebundle lodash to @modern-js/utils/lodash
73
+ - Updated dependencies [60855eb2]
74
+ - Updated dependencies [046e58aa]
75
+ - Updated dependencies [ec1b7367]
76
+ - Updated dependencies [77ff9754]
77
+ - Updated dependencies [d2d1d6b2]
78
+ - Updated dependencies [07a4887e]
79
+ - Updated dependencies [ea2ae711]
80
+ - Updated dependencies [17d0cc46]
81
+ - Updated dependencies [d2d1d6b2]
82
+ - @modern-js/core@1.7.0
83
+ - @modern-js/plugin-analyze@1.3.6
84
+ - @modern-js/utils@1.4.0
85
+ - @modern-js/plugin-i18n@1.2.3
86
+ - @modern-js/new-action@1.3.5
87
+ - @modern-js/style-compiler@1.2.3
88
+ - @modern-js/css-config@1.2.3
89
+ - @modern-js/plugin-changeset@1.2.4
90
+ - @modern-js/plugin-fast-refresh@1.2.3
91
+
3
92
  ## 1.4.4
4
93
 
5
94
  ### Patch Changes
@@ -1,9 +1,8 @@
1
1
  import * as path from 'path';
2
- import { fs, Import } from '@modern-js/utils';
2
+ import { fs, Import, dotenv } 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 dotenv = Import.lazy('dotenv', require);
7
6
  export const build = async (api, {
8
7
  watch: _watch = false,
9
8
  tsconfig: tsconfigName,
@@ -1,7 +1,6 @@
1
1
  import * as path from 'path';
2
- import { Import } from '@modern-js/utils';
2
+ import { dotenv, Import } from '@modern-js/utils';
3
3
  const devFeature = Import.lazy('../features/dev', require);
4
- const dotenv = Import.lazy('dotenv', require);
5
4
  const tsConfigutils = Import.lazy('../utils/tsconfig', require);
6
5
  const valid = Import.lazy('../utils/valide', require);
7
6
 
@@ -4,8 +4,7 @@ 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 execa = Import.lazy('execa', require);
7
+ import { execa, Import, chalk } from '@modern-js/utils';
9
8
  const lg = Import.lazy('./logger', require);
10
9
  const pMap = Import.lazy('p-map', require);
11
10
  export const buildPlatform = async (api, option) => {
@@ -1,7 +1,6 @@
1
1
  import * as path from 'path';
2
2
  import * as os from 'os';
3
- import { Import } from '@modern-js/utils';
4
- const execa = Import.lazy('execa', require);
3
+ import { execa, Import } from '@modern-js/utils';
5
4
  const lg = Import.lazy('./logger', require);
6
5
  const pMap = Import.lazy('p-map', require);
7
6
  const utils = Import.lazy('./utils', require);
@@ -1,10 +1,8 @@
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
8
  export const buildSourceCode = async (api, config, _) => {
@@ -105,5 +103,4 @@ export const buildSourceCode = async (api, config, _) => {
105
103
  // eslint-disable-next-line no-process-exit
106
104
  process.exit(1);
107
105
  }
108
- };
109
- /* eslint-enable max-statements */
106
+ };
@@ -1,6 +1,4 @@
1
- import { Import } from '@modern-js/utils';
2
- import chalk from 'chalk';
3
- const inquirer = Import.lazy('inquirer', require);
1
+ import { chalk, Import, inquirer } from '@modern-js/utils';
4
2
  const color = Import.lazy('../../utils/color', require);
5
3
  export const showMenu = async (api, config) => {
6
4
  const runners = api.useHookRunners();
@@ -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,9 +1,8 @@
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
6
  const hooks = Import.lazy('../hooks', require);
8
7
  const STYLE_DIRS = 'styles';
9
8
  const SRC_STYLE_DIRS = 'src';
@@ -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
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';
@@ -1,8 +1,6 @@
1
- import { Import, fs, isObject } from '@modern-js/utils';
1
+ import { Import, execa, fs, json5, isObject } from '@modern-js/utils';
2
2
  import { getTscBinPath } from "./utils";
3
3
  const core = Import.lazy('@modern-js/core', require);
4
- const execa = Import.lazy('execa', require);
5
- const JSON5 = Import.lazy('json5', require);
6
4
  const argv = Import.lazy('process.argv', require);
7
5
  const utils = Import.lazy('./utils', require);
8
6
  let removeTsconfigPath = '';
@@ -12,7 +10,7 @@ const getProjectTsconfig = tsconfigPath => {
12
10
  return {};
13
11
  }
14
12
 
15
- return JSON5.parse(fs.readFileSync(tsconfigPath, 'utf-8'));
13
+ return json5.parse(fs.readFileSync(tsconfigPath, 'utf-8'));
16
14
  };
17
15
 
18
16
  const resolveLog = (childProgress, {
@@ -5,12 +5,11 @@ 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 * as path from 'path';
8
- import { Import, fs } from '@modern-js/utils';
9
- const glob = Import.lazy('glob', require);
8
+ import { Import, glob, fs } from '@modern-js/utils';
9
+ import { merge as deepMerge } from '@modern-js/utils/lodash';
10
10
  const babel = Import.lazy('../../utils/babel', require);
11
11
  const tsPathsTransform = Import.lazy('../../utils/tspaths-transform', require);
12
12
  const constants = Import.lazy('../constants', require);
13
- const deepMerge = Import.lazy('lodash.merge', require);
14
13
  export const generatorTsConfig = (projectTsconfig, {
15
14
  appDirectory,
16
15
  distDir,
@@ -5,11 +5,8 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
5
5
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
6
6
 
7
7
  import * as path from 'path';
8
- import { fs, Import } from '@modern-js/utils';
9
- const globby = Import.lazy('globby', require);
10
- const fastGlob = Import.lazy('fast-glob', require);
11
- const normalizePath = Import.lazy('normalize-path', require); // eslint-disable-next-line max-statements
12
-
8
+ import { fs, Import, globby, fastGlob } from '@modern-js/utils';
9
+ const normalizePath = Import.lazy('normalize-path', require);
13
10
  export const copyTask = async option => {
14
11
  const {
15
12
  modernConfig,
@@ -1,6 +1,5 @@
1
1
  import EventEmitter from 'events';
2
- import { Import } from '@modern-js/utils';
3
- const chalk = Import.lazy('chalk', require);
2
+ import { chalk } from '@modern-js/utils';
4
3
  export const clearFlag = '\x1Bc';
5
4
  export const logTemplate = (title, messageStack, maxLength, {
6
5
  noBottomBorder: _noBottomBorder = false,
@@ -1,5 +1,4 @@
1
- import { fs, Import } from '@modern-js/utils';
2
- const json5 = Import.lazy('json5', require);
1
+ import { fs, json5 } from '@modern-js/utils';
3
2
  export const readTsConfig = (tsconfigPath, noExistReturn = null) => {
4
3
  // 如果不存在,则返回 noExistReturn
5
4
  if (!fs.existsSync(tsconfigPath)) {
@@ -19,8 +19,6 @@ const valid = _utils.Import.lazy('../utils/valide', require);
19
19
 
20
20
  const buildFeature = _utils.Import.lazy('../features/build', require);
21
21
 
22
- const dotenv = _utils.Import.lazy('dotenv', require);
23
-
24
22
  const build = async (api, {
25
23
  watch: _watch = false,
26
24
  tsconfig: tsconfigName,
@@ -33,7 +31,9 @@ const build = async (api, {
33
31
  } = api.useAppContext();
34
32
  const modernConfig = api.useResolvedConfigContext();
35
33
  const tsconfigPath = path.join(appDirectory, tsconfigName);
36
- dotenv.config();
34
+
35
+ _utils.dotenv.config();
36
+
37
37
  const isTsProject = tsConfigutils.existTsConfigFile(tsconfigPath);
38
38
  const enableTscCompiler = isTsProject && tsc && !modernConfig.output.disableTsChecker;
39
39
  valid.valideBeforeTask({
@@ -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 dotenv = _utils.Import.lazy('dotenv', require);
19
-
20
18
  const tsConfigutils = _utils.Import.lazy('../utils/tsconfig', require);
21
19
 
22
20
  const valid = _utils.Import.lazy('../utils/valide', require);
@@ -33,7 +31,9 @@ const dev = async (api, option, subCmd = '') => {
33
31
  appDirectory
34
32
  } = appContext;
35
33
  const tsconfigPath = path.join(appDirectory, tsconfigName);
36
- dotenv.config();
34
+
35
+ _utils.dotenv.config();
36
+
37
37
  valid.valideBeforeTask({
38
38
  modernConfig,
39
39
  tsconfigPath
@@ -13,8 +13,6 @@ 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 execa = _utils.Import.lazy('execa', require);
17
-
18
16
  const lg = _utils.Import.lazy('./logger', require);
19
17
 
20
18
  const pMap = _utils.Import.lazy('p-map', require);
@@ -58,7 +56,7 @@ const buildPlatform = async (api, option) => {
58
56
  params,
59
57
  logger: _
60
58
  }) => {
61
- const childProcess = execa.node(taskPath, params, {
59
+ const childProcess = _utils.execa.node(taskPath, params, {
62
60
  stdio: 'inherit',
63
61
  all: true
64
62
  }); // lm.addStdout(logger, childProcess.stdout, {
@@ -66,6 +64,7 @@ const buildPlatform = async (api, option) => {
66
64
  // });
67
65
  // lm.addStderr(logger, childProcess.stderr);
68
66
 
67
+
69
68
  try {
70
69
  await childProcess;
71
70
  } catch (_unused) {
@@ -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 execa = _utils.Import.lazy('execa', require);
19
-
20
18
  const lg = _utils.Import.lazy('./logger', require);
21
19
 
22
20
  const pMap = _utils.Import.lazy('p-map', require);
@@ -75,7 +73,7 @@ const buildInWatchMode = async (api, config, _) => {
75
73
  taskPath,
76
74
  params
77
75
  }) => {
78
- const childProcess = execa.node(taskPath, params, {
76
+ const childProcess = _utils.execa.node(taskPath, params, {
79
77
  stdio: 'pipe'
80
78
  });
81
79
 
@@ -15,13 +15,10 @@ 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
- /* eslint-disable max-statements */
19
18
  const pMap = _utils.Import.lazy('p-map', require);
20
19
 
21
20
  const utils = _utils.Import.lazy('./utils', require);
22
21
 
23
- const execa = _utils.Import.lazy('execa', require);
24
-
25
22
  const lg = _utils.Import.lazy('./logger', require);
26
23
 
27
24
  const constants = _utils.Import.lazy('./constants', require);
@@ -70,7 +67,7 @@ const buildSourceCode = async (api, config, _) => {
70
67
  taskPath,
71
68
  params
72
69
  }) => {
73
- const childProcess = execa.node(taskPath, params, {
70
+ const childProcess = _utils.execa.node(taskPath, params, {
74
71
  stdio: 'pipe'
75
72
  });
76
73
 
@@ -125,7 +122,5 @@ const buildSourceCode = async (api, config, _) => {
125
122
  process.exit(1);
126
123
  }
127
124
  };
128
- /* eslint-enable max-statements */
129
-
130
125
 
131
126
  exports.buildSourceCode = buildSourceCode;
@@ -7,12 +7,6 @@ exports.showMenu = exports.runSubCmd = exports.devStorybook = void 0;
7
7
 
8
8
  var _utils = require("@modern-js/utils");
9
9
 
10
- var _chalk = _interopRequireDefault(require("chalk"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- const inquirer = _utils.Import.lazy('inquirer', require);
15
-
16
10
  const color = _utils.Import.lazy('../../utils/color', require);
17
11
 
18
12
  const showMenu = async (api, config) => {
@@ -20,7 +14,7 @@ const showMenu = async (api, config) => {
20
14
  const metas = await runners.moduleToolsMenu(undefined);
21
15
 
22
16
  if (metas.length <= 0) {
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
17
+ console.info(_utils.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
24
18
 
25
19
  process.exit(0);
26
20
  }
@@ -28,7 +22,7 @@ const showMenu = async (api, config) => {
28
22
  const menuMessage = color.devMenuTitle('Select the debug mode:');
29
23
  const {
30
24
  type
31
- } = await inquirer.prompt([{
25
+ } = await _utils.inquirer.prompt([{
32
26
  name: 'type',
33
27
  message: menuMessage,
34
28
  type: 'list',
@@ -51,7 +45,7 @@ const devStorybook = async (api, config) => {
51
45
  if (findStorybook) {
52
46
  await findStorybook.runTask(config);
53
47
  } else {
54
- console.info(_chalk.default.yellow('No development features found.\nYou can use the `new` command to enable the development features')); // eslint-disable-next-line no-process-exit
48
+ console.info(_utils.chalk.yellow('No development features found.\nYou can use the `new` command to enable the development features')); // eslint-disable-next-line no-process-exit
55
49
 
56
50
  process.exit(0);
57
51
  }
@@ -17,8 +17,6 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
17
17
 
18
18
  const babelCompiler = _utils.Import.lazy('@modern-js/babel-compiler', require);
19
19
 
20
- const glob = _utils.Import.lazy('glob', require);
21
-
22
20
  const argv = _utils.Import.lazy('process.argv', require);
23
21
 
24
22
  const core = _utils.Import.lazy('@modern-js/core', require);
@@ -79,10 +77,12 @@ const getWillCompilerCode = (srcDirOrFile, option) => {
79
77
 
80
78
  const exts = getExts(isTsProject);
81
79
  const globPattern = `${srcDirOrFile}/**/*{${exts.join(',')}}`;
82
- const files = glob.sync(globPattern, {
80
+
81
+ const files = _utils.glob.sync(globPattern, {
83
82
  ignore: [`${srcDirOrFile}/**/*.d.ts`],
84
83
  absolute: true
85
84
  });
85
+
86
86
  return files;
87
87
  };
88
88
 
@@ -14,8 +14,6 @@ const core = _utils.Import.lazy('@modern-js/core', require);
14
14
 
15
15
  const compiler = _utils.Import.lazy('@modern-js/style-compiler', require);
16
16
 
17
- const glob = _utils.Import.lazy('glob', require);
18
-
19
17
  const hooks = _utils.Import.lazy('../hooks', require);
20
18
 
21
19
  const STYLE_DIRS = 'styles';
@@ -61,7 +59,7 @@ const copyOriginStyleFiles = ({
61
59
  targetDir,
62
60
  outputDir
63
61
  }) => {
64
- const styleFiles = glob.sync(`${targetDir}/**/*.{css,sass,scss,less}`);
62
+ const styleFiles = _utils.glob.sync(`${targetDir}/**/*.{css,sass,scss,less}`);
65
63
 
66
64
  if (styleFiles.length > 0) {
67
65
  _utils.fs.ensureDirSync(outputDir);
@@ -8,7 +8,6 @@ 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);
@@ -19,8 +18,6 @@ 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
 
@@ -6,10 +6,6 @@ var _utils2 = require("./utils");
6
6
 
7
7
  const core = _utils.Import.lazy('@modern-js/core', require);
8
8
 
9
- const execa = _utils.Import.lazy('execa', require);
10
-
11
- const JSON5 = _utils.Import.lazy('json5', require);
12
-
13
9
  const argv = _utils.Import.lazy('process.argv', require);
14
10
 
15
11
  const utils = _utils.Import.lazy('./utils', require);
@@ -21,7 +17,7 @@ const getProjectTsconfig = tsconfigPath => {
21
17
  return {};
22
18
  }
23
19
 
24
- return JSON5.parse(_utils.fs.readFileSync(tsconfigPath, 'utf-8'));
20
+ return _utils.json5.parse(_utils.fs.readFileSync(tsconfigPath, 'utf-8'));
25
21
  };
26
22
 
27
23
  const resolveLog = (childProgress, {
@@ -73,7 +69,7 @@ const generatorDts = async (_, config) => {
73
69
  removeTsconfigPath = willDeleteTsconfigPath;
74
70
  const tscBinFile = (0, _utils2.getTscBinPath)(appDirectory);
75
71
  const watchParams = watch ? ['-w'] : [];
76
- const childProgress = execa(tscBinFile, ['-p', willDeleteTsconfigPath, ...watchParams], {
72
+ const childProgress = (0, _utils.execa)(tscBinFile, ['-p', willDeleteTsconfigPath, ...watchParams], {
77
73
  stdio: 'pipe',
78
74
  cwd: appDirectory
79
75
  });
@@ -9,6 +9,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, {
@@ -19,12 +19,7 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
19
19
 
20
20
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
21
21
 
22
- const globby = _utils.Import.lazy('globby', require);
23
-
24
- const fastGlob = _utils.Import.lazy('fast-glob', require);
25
-
26
- const normalizePath = _utils.Import.lazy('normalize-path', require); // eslint-disable-next-line max-statements
27
-
22
+ const normalizePath = _utils.Import.lazy('normalize-path', require);
28
23
 
29
24
  const copyTask = async option => {
30
25
  const {
@@ -74,9 +69,9 @@ const copyTask = async option => {
74
69
  options = globOptions;
75
70
  }
76
71
 
77
- glob = path.isAbsolute(fromOrigin) ? fromOrigin : path.posix.join(fastGlob.escapePath(normalizePath(path.resolve(context))), fromOrigin); // 计算 glob,获取目标文件
72
+ glob = path.isAbsolute(fromOrigin) ? fromOrigin : path.posix.join(_utils.fastGlob.escapePath(normalizePath(path.resolve(context))), fromOrigin); // 计算 glob,获取目标文件
78
73
 
79
- const paths = await globby(glob, options);
74
+ const paths = await (0, _utils.globby)(glob, options);
80
75
 
81
76
  if (!paths.length) {
82
77
  return;
@@ -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
  });
@@ -7,8 +7,6 @@ exports.readTsConfig = exports.existTsConfigFile = void 0;
7
7
 
8
8
  var _utils = require("@modern-js/utils");
9
9
 
10
- const json5 = _utils.Import.lazy('json5', require);
11
-
12
10
  const readTsConfig = (tsconfigPath, noExistReturn = null) => {
13
11
  // 如果不存在,则返回 noExistReturn
14
12
  if (!_utils.fs.existsSync(tsconfigPath)) {
@@ -17,7 +15,7 @@ const readTsConfig = (tsconfigPath, noExistReturn = null) => {
17
15
 
18
16
  const content = _utils.fs.readFileSync(tsconfigPath, 'utf-8');
19
17
 
20
- return json5.parse(content);
18
+ return _utils.json5.parse(content);
21
19
  };
22
20
 
23
21
  exports.readTsConfig = readTsConfig;
@@ -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;
@@ -1,4 +1,4 @@
1
- import { NormalizedConfig } from '@modern-js/core';
1
+ import type { NormalizedConfig } from '@modern-js/core';
2
2
  import { IPackageModeValue } from '../types';
3
3
  export declare const getFinalAlias: any;
4
4
  export declare const resolveBabelConfig: (appDirectory: string, modernConfig: NormalizedConfig, option: Pick<IPackageModeValue, 'syntax' | 'type'> & {
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.4.4",
14
+ "version": "1.5.0",
15
15
  "bin": {
16
16
  "modern": "./bin/modern.js"
17
17
  },
@@ -54,28 +54,19 @@
54
54
  "@babel/runtime": "^7",
55
55
  "@babel/traverse": "^7.15.0",
56
56
  "@babel/types": "^7.17.0",
57
- "@modern-js/babel-compiler": "^1.2.2",
58
- "@modern-js/babel-preset-module": "^1.3.1",
59
- "@modern-js/core": "^1.6.1",
60
- "@modern-js/css-config": "^1.2.3",
61
- "@modern-js/i18n-cli-language-detector": "^1.2.1",
62
- "@modern-js/new-action": "^1.3.3",
63
- "@modern-js/plugin": "^1.3.2",
64
- "@modern-js/plugin-analyze": "^1.3.5",
65
- "@modern-js/plugin-changeset": "^1.2.4",
66
- "@modern-js/plugin-fast-refresh": "^1.2.3",
67
- "@modern-js/plugin-i18n": "^1.2.1",
68
- "@modern-js/style-compiler": "^1.2.2",
69
- "@modern-js/utils": "^1.3.7",
70
- "chalk": "^4.1.2",
71
- "dotenv": "^10.0.0",
72
- "execa": "^5.1.1",
73
- "fast-glob": "^3.2.5",
74
- "glob": "^7.1.7",
75
- "globby": "^11",
76
- "inquirer": "^8.1.5",
77
- "json5": "^2.2.0",
78
- "lodash.merge": "^4.6.2",
57
+ "@modern-js/babel-compiler": "^1.2.3",
58
+ "@modern-js/babel-preset-module": "^1.3.3",
59
+ "@modern-js/core": "^1.9.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.7",
63
+ "@modern-js/plugin": "^1.3.3",
64
+ "@modern-js/plugin-analyze": "^1.4.1",
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.6.0",
79
70
  "normalize-path": "^3.0.0",
80
71
  "p-map": "^4",
81
72
  "process.argv": "^0.6.0",
@@ -83,21 +74,18 @@
83
74
  },
84
75
  "devDependencies": {
85
76
  "@babel/preset-typescript": "^7.15.0",
86
- "@modern-js/babel-chain": "^1.2.1",
77
+ "@modern-js/babel-chain": "1.2.2",
87
78
  "@scripts/build": "0.0.0",
88
79
  "@scripts/jest-config": "0.0.0",
89
80
  "@types/babel__core": "^7.1.15",
90
81
  "@types/babel__generator": "^7.6.3",
91
82
  "@types/babel__traverse": "^7.14.2",
92
83
  "@types/glob": "^7.1.4",
93
- "@types/inquirer": "^8.1.1",
94
84
  "@types/jest": "^26",
95
- "@types/lodash.merge": "^4.6.6",
96
85
  "@types/node": "^14",
97
86
  "@types/normalize-path": "^3.0.0",
98
87
  "@types/react": "^17",
99
88
  "@types/react-dom": "^17",
100
- "commander": "^8.1.0",
101
89
  "jest": "^27",
102
90
  "typescript": "^4"
103
91
  },
@@ -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
- });
@@ -1,78 +0,0 @@
1
- import { manager } from '@modern-js/core';
2
- import { runSubCmd } from '../src/features/dev';
3
-
4
- const mockModuleToolsMenu = jest.fn();
5
- const mockDevMeta = jest.fn();
6
- const exit = jest.spyOn(process, 'exit').mockImplementation();
7
- const mockAPI = {
8
- useAppContext: jest.fn((): any => ({})),
9
- useResolvedConfigContext: jest.fn(),
10
- useHookRunners: (): any => ({
11
- moduleToolsMenu: mockModuleToolsMenu,
12
- }),
13
- };
14
-
15
- describe('dev feature with subCmd', () => {
16
- beforeEach(() => {
17
- jest.clearAllMocks();
18
- });
19
- it('should run task with "storybook" params when storybook plugin exist', async () => {
20
- mockModuleToolsMenu.mockReturnValue([
21
- { value: 'storybook', runTask: mockDevMeta },
22
- ]);
23
- const cloned = manager.clone(mockAPI);
24
- cloned.usePlugin({
25
- async setup(api) {
26
- await runSubCmd(api, 'storybook', {
27
- isTsProject: true,
28
- appDirectory: '',
29
- });
30
- expect(mockDevMeta.mock.calls.length).toBe(1);
31
- },
32
- });
33
- await cloned.init();
34
- });
35
-
36
- it('should run task with "storybook" params when storybook plugin not exist', async () => {
37
- mockModuleToolsMenu.mockReturnValue([]);
38
- const cloned = manager.clone(mockAPI);
39
- cloned.usePlugin({
40
- async setup(api) {
41
- await runSubCmd(api, 'storybook', {
42
- isTsProject: true,
43
- appDirectory: '',
44
- });
45
- expect(exit).toHaveBeenCalled();
46
- },
47
- });
48
- await cloned.init();
49
- });
50
-
51
- it('should run task with alias name "story" params when storybook plugin exist', async () => {
52
- mockModuleToolsMenu.mockReturnValue([
53
- { value: 'storybook', aliasValues: ['story'], runTask: mockDevMeta },
54
- ]);
55
- const cloned = manager.clone(mockAPI);
56
- cloned.usePlugin({
57
- async setup(api) {
58
- await runSubCmd(api, 'story', { isTsProject: true, appDirectory: '' });
59
- expect(mockDevMeta.mock.calls.length).toBe(1);
60
- },
61
- });
62
- await cloned.init();
63
- });
64
-
65
- it('should run task with alias name "story1" params when storybook plugin exist', async () => {
66
- mockModuleToolsMenu.mockReturnValue([
67
- { value: 'storybook', aliasValues: ['story'], runTask: mockDevMeta },
68
- ]);
69
- const cloned = manager.clone(mockAPI);
70
- cloned.usePlugin({
71
- async setup(api) {
72
- await runSubCmd(api, 'story1', { isTsProject: true, appDirectory: '' });
73
- expect(mockDevMeta.mock.calls.length).toBe(0);
74
- },
75
- });
76
- await cloned.init();
77
- });
78
- });
@@ -1 +0,0 @@
1
- import '@/b.ts';
@@ -1 +0,0 @@
1
- export const b = 10;
@@ -1,9 +0,0 @@
1
- import { getTscBinPath } from '../src/tasks/generator-dts/utils';
2
-
3
- describe('generate dts', () => {
4
- test('should throw error when tsc bin is not exist', () => {
5
- expect(() => {
6
- getTscBinPath('/foo');
7
- }).toThrowError();
8
- });
9
- });
@@ -1,10 +0,0 @@
1
- import * as path from 'path';
2
- import { generatorTsConfig } from '../src/tasks/generator-dts/utils';
3
-
4
- describe('test generator dts utils', () => {
5
- it('test generatorTsConfig', () => {
6
- const appDir = path.join(__dirname, './fixtures/tsconfig');
7
- const ret = generatorTsConfig({}, { appDirectory: appDir, distDir: '' });
8
- expect(ret).toContain('tsconfig.temp.json');
9
- });
10
- });
@@ -1,48 +0,0 @@
1
- jest.mock('@modern-js/core', () => ({
2
- manager: {
3
- run: async (fn: any) => {
4
- await fn();
5
- },
6
- },
7
- cli: {
8
- init: () => ({}),
9
- },
10
- }));
11
- jest.mock('process.argv', () => () => (o: any) => ({ ...o, tsCheck: false }));
12
- jest.mock('execa', () => () => {
13
- // eslint-disable-next-line prefer-promise-reject-errors
14
- const fn = Promise.reject('error');
15
- (fn as any).stdout = {
16
- on: () => 0,
17
- };
18
- (fn as any).stderr = {
19
- on: () => 0,
20
- };
21
- return fn;
22
- });
23
- jest.mock('../src/tasks/generator-dts/utils');
24
- jest.mock('@modern-js/utils', () => {
25
- const originalModule = jest.requireActual('@modern-js/utils');
26
- return {
27
- __esModule: true, // Use it when dealing with esModules
28
- ...originalModule,
29
- fs: {
30
- ...originalModule.fs,
31
- removeSync: jest.fn(),
32
- },
33
- };
34
- });
35
- process.argv = [];
36
-
37
- describe('generator dts test', () => {
38
- it('test tsCheck is true', () => {
39
- console.info = jest.fn(str => {
40
- expect(str).toBe(
41
- "There are some type warnings, which can be checked by configuring 'output.disableTsChecker = false'",
42
- );
43
- });
44
- require('../src/tasks/generator-dts');
45
- });
46
- });
47
-
48
- export {};
@@ -1,7 +0,0 @@
1
- import plugin from '../src';
2
-
3
- describe('module-tools', () => {
4
- it('default', () => {
5
- expect(plugin).toBeDefined();
6
- });
7
- });
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "@modern-js/tsconfig/base",
3
- "compilerOptions": {
4
- "declaration": false,
5
- "jsx": "preserve",
6
- "baseUrl": "./",
7
- "isolatedModules": true,
8
- "esModuleInterop": true,
9
- "paths": {}
10
- }
11
- }
@@ -1,21 +0,0 @@
1
- import path from 'path';
2
- import { transformDtsAlias } from '../src/utils/tspaths-transform';
3
-
4
- describe('tspaths-transform', () => {
5
- it('transformDtsAlias', () => {
6
- const filepath = path.join(__dirname, 'fixtures/tspaths/a.ts');
7
- const options = {
8
- filenames: [filepath],
9
- baseUrl: './',
10
- paths: {
11
- '@/*': ['./*'],
12
- },
13
- };
14
- expect(transformDtsAlias(options)).toEqual([
15
- {
16
- path: filepath,
17
- content: "import '@/b.ts';",
18
- },
19
- ]);
20
- });
21
- });