@modern-js/module-tools 1.1.4 → 1.3.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 (38) hide show
  1. package/.eslintrc.js +4 -1
  2. package/CHANGELOG.md +64 -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/modern/tasks/build-source-code.js +2 -1
  8. package/dist/js/modern/tasks/build-watch-source-code.js +9 -1
  9. package/dist/js/node/cli/build.js +1 -1
  10. package/dist/js/node/cli/dev.js +2 -2
  11. package/dist/js/node/commands/dev.js +12 -1
  12. package/dist/js/node/features/dev/index.js +16 -2
  13. package/dist/js/node/tasks/build-source-code.js +2 -1
  14. package/dist/js/node/tasks/build-watch-source-code.js +9 -1
  15. package/dist/types/commands/build.d.ts +1 -1
  16. package/dist/types/commands/dev.d.ts +1 -1
  17. package/dist/types/features/dev/index.d.ts +2 -1
  18. package/dist/types/index.d.ts +1 -1
  19. package/jest.config.js +8 -0
  20. package/lib/types.d.ts +0 -1
  21. package/package.json +32 -23
  22. package/src/cli/build.ts +1 -1
  23. package/src/cli/dev.ts +4 -4
  24. package/src/commands/build.ts +1 -1
  25. package/src/commands/dev.ts +10 -1
  26. package/src/features/dev/index.ts +12 -0
  27. package/src/tasks/build-source-code.ts +1 -0
  28. package/src/tasks/build-watch-source-code.ts +1 -1
  29. package/src/tasks/generator-dts.ts +1 -1
  30. package/tests/dev-cli.test.ts +25 -0
  31. package/tests/dev-command.test.ts +44 -0
  32. package/tests/dev-feature.test.ts +30 -0
  33. package/tests/fixtures/tspaths/a.ts +1 -0
  34. package/tests/fixtures/tspaths/b.ts +1 -0
  35. package/tests/index.test.ts +7 -0
  36. package/tests/tsconfig.json +11 -0
  37. package/tests/tspaths-transform.test.ts +21 -0
  38. package/tsconfig.json +2 -3
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,69 @@
1
1
  # @modern-js/module-tools
2
2
 
3
+ ## 1.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - c5973e7a: add dev sub commands
8
+ - 0d9516f3: fix resolve static file and add -p params
9
+
10
+ ### Patch Changes
11
+
12
+ - c1455cd6: fix module-tools type file
13
+ - Updated dependencies [823809c6]
14
+ - Updated dependencies [4584cc04]
15
+ - Updated dependencies [7c19fd94]
16
+ - Updated dependencies [0d9516f3]
17
+ - @modern-js/utils@1.2.1
18
+ - @modern-js/core@1.3.1
19
+ - @modern-js/babel-preset-module@1.3.0
20
+
21
+ ## 1.2.0
22
+
23
+ ### Minor Changes
24
+
25
+ - cfe11628: Make Modern.js self bootstraping
26
+
27
+ ### Patch Changes
28
+
29
+ - Updated dependencies [2da09c69]
30
+ - Updated dependencies [fc71e36f]
31
+ - Updated dependencies [2c049918]
32
+ - Updated dependencies [c3d46ee4]
33
+ - Updated dependencies [cfe11628]
34
+ - Updated dependencies [1ebc7ee2]
35
+ - Updated dependencies [146dcd85]
36
+ - Updated dependencies [1ebc7ee2]
37
+ - @modern-js/utils@1.2.0
38
+ - @modern-js/core@1.3.0
39
+ - @modern-js/new-action@1.3.0
40
+ - @modern-js/babel-preset-module@1.2.0
41
+ - @modern-js/css-config@1.2.0
42
+ - @modern-js/i18n-cli-language-detector@1.2.0
43
+ - @modern-js/plugin-analyze@1.2.0
44
+ - @modern-js/plugin-changeset@1.2.0
45
+ - @modern-js/plugin-fast-refresh@1.2.0
46
+ - @modern-js/plugin-i18n@1.2.0
47
+ - @modern-js/babel-compiler@1.2.0
48
+ - @modern-js/style-compiler@1.2.0
49
+ - @modern-js/module-tools-hooks@1.2.0
50
+
51
+ ## 1.1.5
52
+
53
+ ### Patch Changes
54
+
55
+ - 2da27d3b: fix sourcemap 'source' config
56
+ - Updated dependencies [5e3de7d8]
57
+ - Updated dependencies [2da27d3b]
58
+ - Updated dependencies [4819a3c7]
59
+ - Updated dependencies [b7fb82ec]
60
+ - Updated dependencies [81d93503]
61
+ - @modern-js/plugin-i18n@1.1.2
62
+ - @modern-js/babel-compiler@1.1.4
63
+ - @modern-js/new-action@1.2.2
64
+ - @modern-js/plugin-changeset@1.1.2
65
+ - @modern-js/utils@1.1.6
66
+
3
67
  ## 1.1.4
4
68
 
5
69
  ### 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
  };
@@ -63,7 +63,8 @@ export const getWillCompilerCode = (srcDirOrFile, option) => {
63
63
  const exts = getExts(isTsProject);
64
64
  const globPattern = `${srcDirOrFile}/**/*{${exts.join(',')}}`;
65
65
  const files = glob.sync(globPattern, {
66
- ignore: [`${srcDirOrFile}/**/*.d.ts`]
66
+ ignore: [`${srcDirOrFile}/**/*.d.ts`],
67
+ absolute: true
67
68
  });
68
69
  return files;
69
70
  };
@@ -1,3 +1,9 @@
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
+
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+
5
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+
1
7
  import { Import, fs } from '@modern-js/utils';
2
8
  import { initEnv } from "../utils/init-env";
3
9
  const babelCompiler = Import.lazy('@modern-js/babel-compiler', require);
@@ -61,7 +67,9 @@ const runBabelCompiler = async (config, modernConfig) => {
61
67
  distDir: config.distDir,
62
68
  watchDir: config.srcRootDir,
63
69
  extensions: getExts(isTs)
64
- }, babelConfig);
70
+ }, _objectSpread(_objectSpread({}, babelConfig), {}, {
71
+ sourceMaps: config.sourceMaps
72
+ }));
65
73
  emitter.on(babelCompiler.BuildWatchEvent.compiling, () => {
66
74
  console.info(logger.clearFlag, `Compiling...`);
67
75
  });
@@ -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;
@@ -79,7 +79,8 @@ const getWillCompilerCode = (srcDirOrFile, option) => {
79
79
  const exts = getExts(isTsProject);
80
80
  const globPattern = `${srcDirOrFile}/**/*{${exts.join(',')}}`;
81
81
  const files = glob.sync(globPattern, {
82
- ignore: [`${srcDirOrFile}/**/*.d.ts`]
82
+ ignore: [`${srcDirOrFile}/**/*.d.ts`],
83
+ absolute: true
83
84
  });
84
85
  return files;
85
86
  };
@@ -4,6 +4,12 @@ var _utils = require("@modern-js/utils");
4
4
 
5
5
  var _initEnv = require("../utils/init-env");
6
6
 
7
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
8
+
9
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
10
+
11
+ 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; }
12
+
7
13
  const babelCompiler = _utils.Import.lazy('@modern-js/babel-compiler', require);
8
14
 
9
15
  const logger = _utils.Import.lazy('../features/build/logger', require);
@@ -73,7 +79,9 @@ const runBabelCompiler = async (config, modernConfig) => {
73
79
  distDir: config.distDir,
74
80
  watchDir: config.srcRootDir,
75
81
  extensions: getExts(isTs)
76
- }, babelConfig);
82
+ }, _objectSpread(_objectSpread({}, babelConfig), {}, {
83
+ sourceMaps: config.sourceMaps
84
+ }));
77
85
  emitter.on(babelCompiler.BuildWatchEvent.compiling, () => {
78
86
  console.info(logger.clearFlag, `Compiling...`);
79
87
  });
@@ -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>;
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 {
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.1.4",
14
+ "version": "1.3.0",
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.3",
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.0",
54
- "@modern-js/plugin-analyze": "^1.1.2",
55
- "@modern-js/plugin-changeset": "^1.1.1",
56
- "@modern-js/plugin-fast-refresh": "^1.1.1",
57
- "@modern-js/plugin-i18n": "^1.1.1",
58
- "@modern-js/style-compiler": "^1.1.3",
59
- "@modern-js/utils": "^1.1.5",
54
+ "@modern-js/babel-compiler": "^1.2.0",
55
+ "@modern-js/babel-preset-module": "^1.3.0",
56
+ "@modern-js/core": "^1.3.1",
57
+ "@modern-js/css-config": "^1.2.0",
58
+ "@modern-js/i18n-cli-language-detector": "^1.2.0",
59
+ "@modern-js/module-tools-hooks": "^1.2.0",
60
+ "@modern-js/new-action": "^1.3.0",
61
+ "@modern-js/plugin-analyze": "^1.2.0",
62
+ "@modern-js/plugin-changeset": "^1.2.0",
63
+ "@modern-js/plugin-fast-refresh": "^1.2.0",
64
+ "@modern-js/plugin-i18n": "^1.2.0",
65
+ "@modern-js/style-compiler": "^1.2.0",
66
+ "@modern-js/utils": "^1.2.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.1",
85
+ "@modern-js/babel-chain": "^1.2.0",
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.0",
92
- "@modern-js/module-tools": "^1.1.3"
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": {
@@ -99,12 +107,13 @@
99
107
  },
100
108
  "publishConfig": {
101
109
  "registry": "https://registry.npmjs.org/",
102
- "access": "public"
110
+ "access": "public",
111
+ "types": "./dist/types/index.d.ts"
103
112
  },
104
113
  "scripts": {
105
114
  "new": "modern new",
106
115
  "build": "modern build",
107
- "test": "modern test --passWithNoTests"
116
+ "test": "jest --passWithNoTests"
108
117
  },
109
118
  "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
119
  }
package/src/cli/build.ts CHANGED
@@ -28,7 +28,7 @@ export const buildCli = (program: Command) => {
28
28
  local.i18n.t(local.localeKeys.command.build.style_only),
29
29
  )
30
30
  .option(
31
- '--platform [platform]',
31
+ '-p, --platform [platform]',
32
32
  local.i18n.t(local.localeKeys.command.build.platform),
33
33
  )
34
34
  .option('--no-tsc', local.i18n.t(local.localeKeys.command.build.no_tsc))
package/src/cli/dev.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Import } from '@modern-js/utils';
2
2
  import type { Command } from 'commander';
3
- import type { IDevOption } from '@/commands/dev';
3
+ import type { IDevOption } from '../commands/dev';
4
4
 
5
5
  const local: typeof import('../locale') = Import.lazy('../locale', require);
6
6
  const commands: typeof import('../commands') = Import.lazy(
@@ -10,7 +10,7 @@ const commands: typeof import('../commands') = Import.lazy(
10
10
 
11
11
  export const devCli = (program: Command) => {
12
12
  program
13
- .command('dev')
13
+ .command('dev [subCmd]')
14
14
  .usage('[options]')
15
15
  .description(local.i18n.t(local.localeKeys.command.dev.describe))
16
16
  .option(
@@ -18,7 +18,7 @@ export const devCli = (program: Command) => {
18
18
  local.i18n.t(local.localeKeys.command.build.tsconfig),
19
19
  './tsconfig.json',
20
20
  )
21
- .action(async (params: IDevOption) => {
22
- await commands.dev(params);
21
+ .action(async (subCmd: string, params: IDevOption) => {
22
+ await commands.dev(params, subCmd);
23
23
  });
24
24
  };
@@ -1,6 +1,6 @@
1
1
  import * as path from 'path';
2
2
  import { fs, Import } from '@modern-js/utils';
3
- import type { Platform } from '@/types';
3
+ import type { Platform } from '../types';
4
4
 
5
5
  const tsConfigutils: typeof import('../utils/tsconfig') = Import.lazy(
6
6
  '../utils/tsconfig',
@@ -23,7 +23,9 @@ export interface IDevOption {
23
23
  tsconfig: string;
24
24
  }
25
25
 
26
- export const dev = async (option: IDevOption) => {
26
+ const existSubCmd = (subCmd: string) => subCmd.length > 0;
27
+
28
+ export const dev = async (option: IDevOption, subCmd = '') => {
27
29
  const { tsconfig: tsconfigName } = option;
28
30
  const appContext = core.useAppContext();
29
31
  const modernConfig = core.useResolvedConfigContext();
@@ -35,6 +37,13 @@ export const dev = async (option: IDevOption) => {
35
37
  valid.valideBeforeTask({ modernConfig, tsconfigPath });
36
38
 
37
39
  const isTsProject = tsConfigutils.existTsConfigFile(tsconfigPath);
40
+
41
+ if (existSubCmd(subCmd)) {
42
+ await devFeature.runSubCmd(subCmd, { isTsProject, appDirectory });
43
+ return;
44
+ }
45
+
46
+ // Compatible with the use of jupiter, RUN_PLATFORM is used in jupiter
38
47
  if (process.env.RUN_PLATFORM) {
39
48
  await devFeature.showMenu({ isTsProject, appDirectory });
40
49
  } else {
@@ -60,3 +60,15 @@ export const devStorybook = async (config: IDevConfig) => {
60
60
  process.exit(0);
61
61
  }
62
62
  };
63
+
64
+ export const runSubCmd = async (subCmd: string, config: IDevConfig) => {
65
+ const metas = await (core.mountHook() as any).moduleToolsMenu(undefined);
66
+
67
+ const devMeta = metas.find((meta: any) => meta.value === subCmd);
68
+ if (devMeta) {
69
+ await devMeta.runTask(config);
70
+ } else {
71
+ // eslint-disable-next-line no-process-exit
72
+ process.exit(0);
73
+ }
74
+ };
@@ -92,6 +92,7 @@ export const getWillCompilerCode = (
92
92
  const globPattern = `${srcDirOrFile}/**/*{${exts.join(',')}}`;
93
93
  const files = glob.sync(globPattern, {
94
94
  ignore: [`${srcDirOrFile}/**/*.d.ts`],
95
+ absolute: true,
95
96
  });
96
97
 
97
98
  return files;
@@ -82,7 +82,7 @@ const runBabelCompiler = async (
82
82
  watchDir: config.srcRootDir,
83
83
  extensions: getExts(isTs),
84
84
  },
85
- babelConfig,
85
+ { ...babelConfig, sourceMaps: config.sourceMaps },
86
86
  );
87
87
  emitter.on(babelCompiler.BuildWatchEvent.compiling, () => {
88
88
  console.info(logger.clearFlag, `Compiling...`);
@@ -3,7 +3,7 @@ import * as path from 'path';
3
3
  import * as os from 'os';
4
4
  import { Import, fs } from '@modern-js/utils';
5
5
  import type { NormalizedConfig, CoreOptions } from '@modern-js/core';
6
- import type { ITsconfig } from '@/types';
6
+ import type { ITsconfig } from '../types';
7
7
 
8
8
  const tsPathsTransform: typeof import('../utils/tspaths-transform') =
9
9
  Import.lazy('../utils/tspaths-transform', require);
@@ -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
  }