@modern-js/module-tools 1.1.5 → 1.3.2

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 (74) hide show
  1. package/.eslintrc.js +4 -1
  2. package/CHANGELOG.md +85 -0
  3. package/dist/js/modern/cli/build.js +1 -1
  4. package/dist/js/modern/cli/dev.js +2 -2
  5. package/dist/js/modern/commands/dev.js +13 -1
  6. package/dist/js/modern/features/dev/index.js +11 -0
  7. package/dist/js/node/cli/build.js +1 -1
  8. package/dist/js/node/cli/dev.js +2 -2
  9. package/dist/js/node/commands/dev.js +12 -1
  10. package/dist/js/node/features/dev/index.js +16 -2
  11. package/dist/types/commands/build.d.ts +1 -1
  12. package/dist/types/commands/dev.d.ts +1 -1
  13. package/dist/types/features/dev/index.d.ts +2 -1
  14. package/dist/types/index.d.ts +3 -1
  15. package/jest.config.js +8 -0
  16. package/lib/types.d.ts +0 -11
  17. package/package.json +30 -22
  18. package/tests/dev-cli.test.ts +25 -0
  19. package/tests/dev-command.test.ts +44 -0
  20. package/tests/dev-feature.test.ts +30 -0
  21. package/tests/fixtures/tspaths/a.ts +1 -0
  22. package/tests/fixtures/tspaths/b.ts +1 -0
  23. package/tests/index.test.ts +7 -0
  24. package/tests/tsconfig.json +11 -0
  25. package/tests/tspaths-transform.test.ts +21 -0
  26. package/tsconfig.json +2 -3
  27. package/src/.eslintrc.json +0 -5
  28. package/src/cli/build.ts +0 -39
  29. package/src/cli/dev.ts +0 -24
  30. package/src/cli/index.ts +0 -3
  31. package/src/cli/new.ts +0 -32
  32. package/src/commands/build.ts +0 -74
  33. package/src/commands/dev.ts +0 -43
  34. package/src/commands/index.ts +0 -2
  35. package/src/features/build/build-platform.ts +0 -83
  36. package/src/features/build/build-watch.ts +0 -99
  37. package/src/features/build/build.ts +0 -111
  38. package/src/features/build/constants.ts +0 -52
  39. package/src/features/build/index.ts +0 -54
  40. package/src/features/build/logger/index.ts +0 -2
  41. package/src/features/build/logger/logText.ts +0 -80
  42. package/src/features/build/logger/loggerManager.ts +0 -132
  43. package/src/features/build/utils.ts +0 -235
  44. package/src/features/dev/index.ts +0 -62
  45. package/src/index.ts +0 -55
  46. package/src/locale/en.ts +0 -21
  47. package/src/locale/index.ts +0 -15
  48. package/src/locale/zh.ts +0 -21
  49. package/src/schema/index.ts +0 -4
  50. package/src/schema/output.ts +0 -41
  51. package/src/schema/schema.d.ts +0 -13
  52. package/src/schema/source.ts +0 -16
  53. package/src/tasks/build-source-code.ts +0 -234
  54. package/src/tasks/build-style.ts +0 -194
  55. package/src/tasks/build-watch-source-code.ts +0 -186
  56. package/src/tasks/build-watch-style.ts +0 -271
  57. package/src/tasks/constants.ts +0 -1
  58. package/src/tasks/copy-assets.ts +0 -123
  59. package/src/tasks/generator-dts.ts +0 -277
  60. package/src/type.d.ts +0 -1
  61. package/src/types.ts +0 -65
  62. package/src/utils/babel.ts +0 -104
  63. package/src/utils/color.ts +0 -3
  64. package/src/utils/copy.ts +0 -71
  65. package/src/utils/init-env.ts +0 -31
  66. package/src/utils/json.ts +0 -13
  67. package/src/utils/language.ts +0 -9
  68. package/src/utils/logger.ts +0 -141
  69. package/src/utils/readline.ts +0 -28
  70. package/src/utils/tsconfig.ts +0 -37
  71. package/src/utils/tspaths-transform/constants.ts +0 -19
  72. package/src/utils/tspaths-transform/index.ts +0 -139
  73. package/src/utils/tspaths-transform/utils.ts +0 -25
  74. package/src/utils/valide.ts +0 -37
package/.eslintrc.js CHANGED
@@ -1,7 +1,10 @@
1
1
  module.exports = {
2
2
  extends: ['@modern-js'],
3
3
  parserOptions: {
4
- project: require.resolve('./tsconfig.json'),
4
+ project: [
5
+ require.resolve('./tsconfig.json'),
6
+ require.resolve('./tests/tsconfig.json'),
7
+ ],
5
8
  },
6
9
  ignorePatterns: ['types.d.ts'],
7
10
  };
package/CHANGELOG.md CHANGED
@@ -1,5 +1,90 @@
1
1
  # @modern-js/module-tools
2
2
 
3
+ ## 1.3.2
4
+
5
+ ### Patch Changes
6
+
7
+ - c78400c7: fix: remove stylus support
8
+ - Updated dependencies [b7a9eeba]
9
+ - Updated dependencies [53aca274]
10
+ - Updated dependencies [78279953]
11
+ - Updated dependencies [e116ace5]
12
+ - Updated dependencies [4d72edea]
13
+ - @modern-js/plugin-analyze@1.3.1
14
+ - @modern-js/core@1.4.1
15
+ - @modern-js/utils@1.3.1
16
+
17
+ ## 1.3.1
18
+
19
+ ### Patch Changes
20
+
21
+ - 83166714: change .npmignore
22
+ - Updated dependencies [83166714]
23
+ - Updated dependencies [c3de9882]
24
+ - Updated dependencies [33ff48af]
25
+ - Updated dependencies [b7c48198]
26
+ - @modern-js/babel-preset-module@1.3.1
27
+ - @modern-js/core@1.3.2
28
+ - @modern-js/css-config@1.2.1
29
+ - @modern-js/i18n-cli-language-detector@1.2.1
30
+ - @modern-js/plugin-analyze@1.2.1
31
+ - @modern-js/plugin-changeset@1.2.1
32
+ - @modern-js/plugin-fast-refresh@1.2.1
33
+ - @modern-js/plugin-i18n@1.2.1
34
+ - @modern-js/new-action@1.3.1
35
+ - @modern-js/babel-compiler@1.2.1
36
+ - @modern-js/style-compiler@1.2.1
37
+ - @modern-js/module-tools-hooks@1.2.1
38
+ - @modern-js/utils@1.2.2
39
+
40
+ ## 1.3.0
41
+
42
+ ### Minor Changes
43
+
44
+ - c5973e7a: add dev sub commands
45
+ - 0d9516f3: fix resolve static file and add -p params
46
+
47
+ ### Patch Changes
48
+
49
+ - c1455cd6: fix module-tools type file
50
+ - Updated dependencies [823809c6]
51
+ - Updated dependencies [4584cc04]
52
+ - Updated dependencies [7c19fd94]
53
+ - Updated dependencies [0d9516f3]
54
+ - @modern-js/utils@1.2.1
55
+ - @modern-js/core@1.3.1
56
+ - @modern-js/babel-preset-module@1.3.0
57
+
58
+ ## 1.2.0
59
+
60
+ ### Minor Changes
61
+
62
+ - cfe11628: Make Modern.js self bootstraping
63
+
64
+ ### Patch Changes
65
+
66
+ - Updated dependencies [2da09c69]
67
+ - Updated dependencies [fc71e36f]
68
+ - Updated dependencies [2c049918]
69
+ - Updated dependencies [c3d46ee4]
70
+ - Updated dependencies [cfe11628]
71
+ - Updated dependencies [1ebc7ee2]
72
+ - Updated dependencies [146dcd85]
73
+ - Updated dependencies [1ebc7ee2]
74
+ - @modern-js/utils@1.2.0
75
+ - @modern-js/core@1.3.0
76
+ - @modern-js/new-action@1.3.0
77
+ - @modern-js/babel-preset-module@1.2.0
78
+ - @modern-js/css-config@1.2.0
79
+ - @modern-js/i18n-cli-language-detector@1.2.0
80
+ - @modern-js/plugin-analyze@1.2.0
81
+ - @modern-js/plugin-changeset@1.2.0
82
+ - @modern-js/plugin-fast-refresh@1.2.0
83
+ - @modern-js/plugin-i18n@1.2.0
84
+ - @modern-js/babel-compiler@1.2.0
85
+ - @modern-js/style-compiler@1.2.0
86
+ - @modern-js/module-tools-hooks@1.2.0
87
+
3
88
  ## 1.1.5
4
89
 
5
90
  ### Patch Changes
@@ -3,7 +3,7 @@ const local = Import.lazy('../locale/index', require);
3
3
  const commands = Import.lazy('../commands', require);
4
4
  export const buildCli = program => {
5
5
  // TODO: 初始化环境变量
6
- program.command('build').usage('[options]').description(local.i18n.t(local.localeKeys.command.build.describe)).option('-w, --watch', local.i18n.t(local.localeKeys.command.build.watch)).option('--tsconfig [tsconfig]', local.i18n.t(local.localeKeys.command.build.tsconfig), './tsconfig.json').option('--style-only', local.i18n.t(local.localeKeys.command.build.style_only)).option('--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 => {
6
+ program.command('build').usage('[options]').description(local.i18n.t(local.localeKeys.command.build.describe)).option('-w, --watch', local.i18n.t(local.localeKeys.command.build.watch)).option('--tsconfig [tsconfig]', local.i18n.t(local.localeKeys.command.build.tsconfig), './tsconfig.json').option('--style-only', local.i18n.t(local.localeKeys.command.build.style_only)).option('-p, --platform [platform]', local.i18n.t(local.localeKeys.command.build.platform)).option('--no-tsc', local.i18n.t(local.localeKeys.command.build.no_tsc)).option('--no-clear', local.i18n.t(local.localeKeys.command.build.no_clear)).action(async subCommand => {
7
7
  await commands.build(subCommand);
8
8
  });
9
9
  };
@@ -2,7 +2,7 @@ import { Import } from '@modern-js/utils';
2
2
  const local = Import.lazy('../locale', require);
3
3
  const commands = Import.lazy('../commands', require);
4
4
  export const devCli = program => {
5
- program.command('dev').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 params => {
6
- await commands.dev(params);
5
+ program.command('dev [subCmd]').usage('[options]').description(local.i18n.t(local.localeKeys.command.dev.describe)).option('--tsconfig [tsconfig]', local.i18n.t(local.localeKeys.command.build.tsconfig), './tsconfig.json').action(async (subCmd, params) => {
6
+ await commands.dev(params, subCmd);
7
7
  });
8
8
  };
@@ -5,7 +5,10 @@ const core = Import.lazy('@modern-js/core', require);
5
5
  const dotenv = Import.lazy('dotenv', require);
6
6
  const tsConfigutils = Import.lazy('../utils/tsconfig', require);
7
7
  const valid = Import.lazy('../utils/valide', require);
8
- export const dev = async option => {
8
+
9
+ const existSubCmd = subCmd => subCmd.length > 0;
10
+
11
+ export const dev = async (option, subCmd = '') => {
9
12
  const {
10
13
  tsconfig: tsconfigName
11
14
  } = option;
@@ -22,6 +25,15 @@ export const dev = async option => {
22
25
  });
23
26
  const isTsProject = tsConfigutils.existTsConfigFile(tsconfigPath);
24
27
 
28
+ if (existSubCmd(subCmd)) {
29
+ await devFeature.runSubCmd(subCmd, {
30
+ isTsProject,
31
+ appDirectory
32
+ });
33
+ return;
34
+ } // Compatible with the use of jupiter, RUN_PLATFORM is used in jupiter
35
+
36
+
25
37
  if (process.env.RUN_PLATFORM) {
26
38
  await devFeature.showMenu({
27
39
  isTsProject,
@@ -36,6 +36,17 @@ export const devStorybook = async config => {
36
36
  } else {
37
37
  console.info(chalk.yellow('No development features found.\nYou can use the `new` command to enable the development features')); // eslint-disable-next-line no-process-exit
38
38
 
39
+ process.exit(0);
40
+ }
41
+ };
42
+ export const runSubCmd = async (subCmd, config) => {
43
+ const metas = await core.mountHook().moduleToolsMenu(undefined);
44
+ const devMeta = metas.find(meta => meta.value === subCmd);
45
+
46
+ if (devMeta) {
47
+ await devMeta.runTask(config);
48
+ } else {
49
+ // eslint-disable-next-line no-process-exit
39
50
  process.exit(0);
40
51
  }
41
52
  };
@@ -13,7 +13,7 @@ const commands = _utils.Import.lazy('../commands', require);
13
13
 
14
14
  const buildCli = program => {
15
15
  // TODO: 初始化环境变量
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('--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 => {
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
17
  await commands.build(subCommand);
18
18
  });
19
19
  };
@@ -12,8 +12,8 @@ const local = _utils.Import.lazy('../locale', require);
12
12
  const commands = _utils.Import.lazy('../commands', require);
13
13
 
14
14
  const devCli = program => {
15
- program.command('dev').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 params => {
16
- await commands.dev(params);
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);
17
17
  });
18
18
  };
19
19
 
@@ -23,7 +23,9 @@ const tsConfigutils = _utils.Import.lazy('../utils/tsconfig', require);
23
23
 
24
24
  const valid = _utils.Import.lazy('../utils/valide', require);
25
25
 
26
- const dev = async option => {
26
+ const existSubCmd = subCmd => subCmd.length > 0;
27
+
28
+ const dev = async (option, subCmd = '') => {
27
29
  const {
28
30
  tsconfig: tsconfigName
29
31
  } = option;
@@ -40,6 +42,15 @@ const dev = async option => {
40
42
  });
41
43
  const isTsProject = tsConfigutils.existTsConfigFile(tsconfigPath);
42
44
 
45
+ if (existSubCmd(subCmd)) {
46
+ await devFeature.runSubCmd(subCmd, {
47
+ isTsProject,
48
+ appDirectory
49
+ });
50
+ return;
51
+ } // Compatible with the use of jupiter, RUN_PLATFORM is used in jupiter
52
+
53
+
43
54
  if (process.env.RUN_PLATFORM) {
44
55
  await devFeature.showMenu({
45
56
  isTsProject,
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.showMenu = exports.devStorybook = void 0;
6
+ exports.showMenu = exports.runSubCmd = exports.devStorybook = void 0;
7
7
 
8
8
  var _utils = require("@modern-js/utils");
9
9
 
@@ -57,4 +57,18 @@ const devStorybook = async config => {
57
57
  }
58
58
  };
59
59
 
60
- exports.devStorybook = devStorybook;
60
+ exports.devStorybook = devStorybook;
61
+
62
+ const runSubCmd = async (subCmd, config) => {
63
+ const metas = await core.mountHook().moduleToolsMenu(undefined);
64
+ const devMeta = metas.find(meta => meta.value === subCmd);
65
+
66
+ if (devMeta) {
67
+ await devMeta.runTask(config);
68
+ } else {
69
+ // eslint-disable-next-line no-process-exit
70
+ process.exit(0);
71
+ }
72
+ };
73
+
74
+ exports.runSubCmd = runSubCmd;
@@ -1,4 +1,4 @@
1
- import type { Platform } from "../types.d";
1
+ import type { Platform } from '../types';
2
2
  export interface IBuildOption {
3
3
  watch: boolean;
4
4
  tsconfig: string;
@@ -1,4 +1,4 @@
1
1
  export interface IDevOption {
2
2
  tsconfig: string;
3
3
  }
4
- export declare const dev: (option: IDevOption) => Promise<void>;
4
+ export declare const dev: (option: IDevOption, subCmd?: string) => Promise<void>;
@@ -4,4 +4,5 @@ export interface IDevConfig {
4
4
  }
5
5
  export declare type DevTaskType = 'storybook' | 'docsite' | 'unknow';
6
6
  export declare const showMenu: (config: IDevConfig) => Promise<void>;
7
- export declare const devStorybook: (config: IDevConfig) => Promise<void>;
7
+ export declare const devStorybook: (config: IDevConfig) => Promise<void>;
8
+ export declare const runSubCmd: (subCmd: string, config: IDevConfig) => Promise<void>;
@@ -1,4 +1,4 @@
1
- export declare const defineConfig: (config: import("@modern-js/core/config").ConfigParam) => import("@modern-js/core/config").ConfigParam;
1
+ export declare const defineConfig: (config: import("@modern-js/core/src/config").ConfigParam) => import("@modern-js/core/src/config").ConfigParam;
2
2
 
3
3
  declare const _default: import("@modern-js/core").AsyncPlugin<Partial<import("@modern-js/core").Progresses2Threads<{
4
4
  config: import("@modern-js/core").ParallelWorkflow<void, unknown>;
@@ -13,8 +13,10 @@ declare const _default: import("@modern-js/core").AsyncPlugin<Partial<import("@m
13
13
  watchFiles: import("@modern-js/core").ParallelWorkflow<void, unknown>;
14
14
  fileChange: import("@modern-js/core").AsyncWorkflow<{
15
15
  filename: string;
16
+ eventType: "add" | "unlink" | "change";
16
17
  }, void>;
17
18
  beforeExit: import("@modern-js/core").AsyncWorkflow<void, void>;
19
+ beforeRestart: import("@modern-js/core").AsyncWorkflow<void, void>;
18
20
  } & import("@modern-js/core").ClearDraftProgress<import("@modern-js/core").Hooks>>>>;
19
21
 
20
22
  export default _default;
package/jest.config.js ADDED
@@ -0,0 +1,8 @@
1
+ const sharedConfig = require('@scripts/jest-config');
2
+
3
+ /** @type {import('@jest/types').Config.InitialOptions} */
4
+ module.exports = {
5
+ // eslint-disable-next-line node/no-unsupported-features/es-syntax
6
+ ...sharedConfig,
7
+ rootDir: __dirname,
8
+ };
package/lib/types.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="react" />
3
3
  /// <reference types="react-dom" />
4
- /// <reference path="../dist/types/index.d.ts" />
5
4
 
6
5
  declare namespace NodeJS {
7
6
  interface ProcessEnv {
@@ -71,11 +70,6 @@ declare module '*.less' {
71
70
  export default classes;
72
71
  }
73
72
 
74
- declare module '*.styl' {
75
- const classes: { readonly [key: string]: string };
76
- export default classes;
77
- }
78
-
79
73
  declare module '*.sass' {
80
74
  const classes: { readonly [key: string]: string };
81
75
  export default classes;
@@ -96,11 +90,6 @@ declare module '*.module.less' {
96
90
  export default classes;
97
91
  }
98
92
 
99
- declare module '*.module.styl' {
100
- const classes: { readonly [key: string]: string };
101
- export default classes;
102
- }
103
-
104
93
  declare module '*.module.sass' {
105
94
  const classes: { readonly [key: string]: string };
106
95
  export default classes;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.1.5",
14
+ "version": "1.3.2",
15
15
  "bin": {
16
16
  "modern": "./bin/modern.js"
17
17
  },
@@ -23,18 +23,25 @@
23
23
  "exports": {
24
24
  ".": {
25
25
  "node": {
26
+ "jsnext:source": "./src/index.ts",
26
27
  "import": "./dist/js/modern/index.js",
27
28
  "require": "./dist/js/node/index.js"
28
29
  },
29
30
  "default": "./dist/js/treeshaking/index.js"
30
31
  },
31
- "./cli": "./dist/js/node/index.js",
32
- "./build": "./dist/js/node/build.js"
32
+ "./cli": {
33
+ "jsnext:source": "./src/index.ts",
34
+ "default": "./dist/js/node/index.js"
35
+ },
36
+ "./build": {
37
+ "jsnext:source": "./src/build.ts",
38
+ "default": "./dist/js/node/build.js"
39
+ }
33
40
  },
34
41
  "typesVersions": {
35
42
  "*": {
36
- "build": [
37
- "./dist/types/build.d.ts"
43
+ "type": [
44
+ "./lib/types.d.ts"
38
45
  ]
39
46
  }
40
47
  },
@@ -44,19 +51,19 @@
44
51
  "@babel/runtime": "^7",
45
52
  "@babel/traverse": "^7.15.0",
46
53
  "@babel/types": "^7.15.0",
47
- "@modern-js/babel-compiler": "^1.1.4",
48
- "@modern-js/babel-preset-module": "^1.1.2",
49
- "@modern-js/core": "^1.2.0",
50
- "@modern-js/css-config": "^1.1.2",
51
- "@modern-js/i18n-cli-language-detector": "^1.1.1",
52
- "@modern-js/module-tools-hooks": "^1.1.2",
53
- "@modern-js/new-action": "^1.2.1",
54
- "@modern-js/plugin-analyze": "^1.1.2",
55
- "@modern-js/plugin-changeset": "^1.1.2",
56
- "@modern-js/plugin-fast-refresh": "^1.1.1",
57
- "@modern-js/plugin-i18n": "^1.1.2",
58
- "@modern-js/style-compiler": "^1.1.3",
59
- "@modern-js/utils": "^1.1.6",
54
+ "@modern-js/babel-compiler": "^1.2.1",
55
+ "@modern-js/babel-preset-module": "^1.3.1",
56
+ "@modern-js/core": "^1.4.1",
57
+ "@modern-js/css-config": "^1.2.1",
58
+ "@modern-js/i18n-cli-language-detector": "^1.2.1",
59
+ "@modern-js/module-tools-hooks": "^1.2.1",
60
+ "@modern-js/new-action": "^1.3.1",
61
+ "@modern-js/plugin-analyze": "^1.3.1",
62
+ "@modern-js/plugin-changeset": "^1.2.1",
63
+ "@modern-js/plugin-fast-refresh": "^1.2.1",
64
+ "@modern-js/plugin-i18n": "^1.2.1",
65
+ "@modern-js/style-compiler": "^1.2.1",
66
+ "@modern-js/utils": "^1.3.1",
60
67
  "chalk": "^4.1.2",
61
68
  "chokidar": "^3.5.2",
62
69
  "dotenv": "^10.0.0",
@@ -75,7 +82,7 @@
75
82
  },
76
83
  "devDependencies": {
77
84
  "@babel/preset-typescript": "^7.15.0",
78
- "@modern-js/babel-chain": "^1.1.2",
85
+ "@modern-js/babel-chain": "^1.2.1",
79
86
  "@types/babel__core": "^7.1.15",
80
87
  "@types/babel__generator": "^7.6.3",
81
88
  "@types/babel__traverse": "^7.14.2",
@@ -88,8 +95,9 @@
88
95
  "@types/signale": "^1.4.2",
89
96
  "commander": "^8.1.0",
90
97
  "typescript": "^4",
91
- "@modern-js/plugin-testing": "^1.2.2",
92
- "@modern-js/module-tools": "^1.1.4"
98
+ "@scripts/build": "0.0.0",
99
+ "jest": "^27",
100
+ "@scripts/jest-config": "0.0.0"
93
101
  },
94
102
  "sideEffects": false,
95
103
  "modernConfig": {
@@ -104,7 +112,7 @@
104
112
  "scripts": {
105
113
  "new": "modern new",
106
114
  "build": "modern build",
107
- "test": "modern test --passWithNoTests"
115
+ "test": "jest --passWithNoTests"
108
116
  },
109
117
  "readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
110
118
  }
@@ -0,0 +1,25 @@
1
+ import { program } from 'commander';
2
+ import { devCli } from '../src/cli/dev';
3
+
4
+ const mockCommandDev = jest.fn();
5
+
6
+ describe('dev cli subCmd', () => {
7
+ beforeEach(() => {
8
+ jest.resetAllMocks();
9
+ jest.mock('../src/commands', () => ({
10
+ __esModule: true,
11
+ dev: mockCommandDev,
12
+ }));
13
+ });
14
+ it('should be storybook with "dev storybook"', () => {
15
+ devCli(program);
16
+ program.parse(['', '', 'dev', 'storybook']);
17
+ expect(mockCommandDev.mock.calls[0][1]).toBe('storybook');
18
+ });
19
+
20
+ it('should be undefined with "dev"', () => {
21
+ devCli(program);
22
+ program.parse(['', '', 'dev']);
23
+ expect(mockCommandDev.mock.calls[0][1]).toBe(undefined);
24
+ });
25
+ });
@@ -0,0 +1,44 @@
1
+ import { dev } from '../src/commands/dev';
2
+
3
+ const mockRunSubCmd = jest.fn();
4
+ jest.mock('../src/features/dev', () => ({
5
+ __esModule: true,
6
+ runSubCmd: mockRunSubCmd,
7
+ devStorybook: jest.fn(),
8
+ }));
9
+ jest.mock('@modern-js/core', () => ({
10
+ __esModule: true,
11
+ useAppContext: jest.fn(() => ({ appDirectory: '' })),
12
+ useResolvedConfigContext: jest.fn(),
13
+ }));
14
+
15
+ jest.mock('dotenv', () => ({
16
+ __esModule: true,
17
+ config: jest.fn(),
18
+ }));
19
+
20
+ jest.mock('../src/utils/valide', () => ({
21
+ __esModule: true,
22
+ valideBeforeTask: jest.fn(),
23
+ }));
24
+
25
+ jest.mock('../src/utils/tsconfig', () => ({
26
+ __esModule: true,
27
+ existTsConfigFile: jest.fn(),
28
+ }));
29
+
30
+ describe('dev command with subCmd', () => {
31
+ beforeEach(() => {
32
+ jest.clearAllMocks();
33
+ });
34
+ it('should call runSubCmd with storybook param', async () => {
35
+ await dev({ tsconfig: 'tsconfig.json' }, 'storybook');
36
+ expect(mockRunSubCmd.mock.calls.length).toBe(1);
37
+ expect(mockRunSubCmd.mock.calls[0][0]).toBe('storybook');
38
+ });
39
+
40
+ it('should not call runSubCmd with nothing param', async () => {
41
+ await dev({ tsconfig: 'tsconfig.json' });
42
+ expect(mockRunSubCmd.mock.calls.length).toBe(0);
43
+ });
44
+ });
@@ -0,0 +1,30 @@
1
+ import { runSubCmd } from '../src/features/dev';
2
+
3
+ const mockModuleToolsMenu = jest.fn();
4
+ const mockDevMeta = jest.fn();
5
+ const exit = jest.spyOn(process, 'exit').mockImplementation();
6
+ jest.mock('@modern-js/core', () => ({
7
+ __esModule: true,
8
+ mountHook: jest.fn(() => ({
9
+ moduleToolsMenu: mockModuleToolsMenu,
10
+ })),
11
+ }));
12
+
13
+ describe('dev feature with subCmd', () => {
14
+ beforeEach(() => {
15
+ console.info('asdas');
16
+ });
17
+ it('should run task with "storybook" params when storybook plugin exist', async () => {
18
+ mockModuleToolsMenu.mockReturnValue([
19
+ { value: 'storybook', runTask: mockDevMeta },
20
+ ]);
21
+ await runSubCmd('storybook', { isTsProject: true, appDirectory: '' });
22
+ expect(mockDevMeta.mock.calls.length).toBe(1);
23
+ });
24
+
25
+ it('should run task with "storybook" params when storybook plugin not exist', async () => {
26
+ mockModuleToolsMenu.mockReturnValue([]);
27
+ await runSubCmd('storybook', { isTsProject: true, appDirectory: '' });
28
+ expect(exit).toHaveBeenCalled();
29
+ });
30
+ });
@@ -0,0 +1 @@
1
+ import '@/b.ts';
@@ -0,0 +1 @@
1
+ export const b = 10;
@@ -0,0 +1,7 @@
1
+ import plugin from '../src';
2
+
3
+ describe('module-tools', () => {
4
+ it('default', () => {
5
+ expect(plugin).toBeDefined();
6
+ });
7
+ });
@@ -0,0 +1,11 @@
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
+ }
@@ -0,0 +1,21 @@
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
+ });
package/tsconfig.json CHANGED
@@ -5,9 +5,8 @@
5
5
  "jsx": "preserve",
6
6
  "baseUrl": "./",
7
7
  "isolatedModules": true,
8
- "paths": {
9
- "@/*": ["./src/*"]
10
- }
8
+ "paths": {},
9
+ "types": ["jest"]
11
10
  },
12
11
  "include": ["src"]
13
12
  }
@@ -1,5 +0,0 @@
1
- {
2
- "rules": {
3
- "react-hooks/rules-of-hooks": "off"
4
- }
5
- }
package/src/cli/build.ts DELETED
@@ -1,39 +0,0 @@
1
- import { Import } from '@modern-js/utils';
2
- import type { Command } from 'commander';
3
- import type { IBuildOption } from '../commands/build';
4
-
5
- const local: typeof import('../locale') = Import.lazy(
6
- '../locale/index',
7
- require,
8
- );
9
- const commands: typeof import('../commands') = Import.lazy(
10
- '../commands',
11
- require,
12
- );
13
-
14
- export const buildCli = (program: Command) => {
15
- // TODO: 初始化环境变量
16
- program
17
- .command('build')
18
- .usage('[options]')
19
- .description(local.i18n.t(local.localeKeys.command.build.describe))
20
- .option('-w, --watch', local.i18n.t(local.localeKeys.command.build.watch))
21
- .option(
22
- '--tsconfig [tsconfig]',
23
- local.i18n.t(local.localeKeys.command.build.tsconfig),
24
- './tsconfig.json',
25
- )
26
- .option(
27
- '--style-only',
28
- local.i18n.t(local.localeKeys.command.build.style_only),
29
- )
30
- .option(
31
- '--platform [platform]',
32
- local.i18n.t(local.localeKeys.command.build.platform),
33
- )
34
- .option('--no-tsc', local.i18n.t(local.localeKeys.command.build.no_tsc))
35
- .option('--no-clear', local.i18n.t(local.localeKeys.command.build.no_clear))
36
- .action(async (subCommand: IBuildOption) => {
37
- await commands.build(subCommand);
38
- });
39
- };