@modern-js/module-tools 1.21.5 → 2.0.0-beta.1

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 (94) hide show
  1. package/CHANGELOG.md +83 -46
  2. package/dist/js/modern/cli/build.js +2 -1
  3. package/dist/js/modern/cli/dev.js +2 -2
  4. package/dist/js/modern/cli/new.js +0 -3
  5. package/dist/js/modern/commands/build.js +0 -4
  6. package/dist/js/modern/commands/dev.js +2 -5
  7. package/dist/js/modern/features/build/build-platform.js +11 -14
  8. package/dist/js/modern/features/build/bundle/runRollup.js +5 -18
  9. package/dist/js/modern/features/build/bundle/runSpeedy.js +4 -18
  10. package/dist/js/modern/features/build/bundleless/copy-assets.js +0 -8
  11. package/dist/js/modern/features/build/bundleless/generator-dts/index.js +7 -17
  12. package/dist/js/modern/features/build/bundleless/generator-dts/utils.js +6 -16
  13. package/dist/js/modern/features/build/bundleless/index.js +0 -2
  14. package/dist/js/modern/features/build/bundleless/runBabel.js +7 -34
  15. package/dist/js/modern/features/build/bundleless/style.js +1 -30
  16. package/dist/js/modern/features/build/constants.js +0 -3
  17. package/dist/js/modern/features/build/error.js +4 -27
  18. package/dist/js/modern/features/build/index.js +6 -15
  19. package/dist/js/modern/features/build/legacy-constants.js +8 -4
  20. package/dist/js/modern/features/build/logger/logText.js +0 -12
  21. package/dist/js/modern/features/build/logger/loggerManager.js +6 -19
  22. package/dist/js/modern/features/build/normalize.js +18 -43
  23. package/dist/js/modern/features/build/utils.js +14 -19
  24. package/dist/js/modern/features/dev/index.js +4 -9
  25. package/dist/js/modern/hooks/index.js +0 -3
  26. package/dist/js/modern/index.js +5 -9
  27. package/dist/js/modern/schema/build-config.js +2 -1
  28. package/dist/js/modern/schema/output.js +5 -10
  29. package/dist/js/modern/utils/babel.js +13 -15
  30. package/dist/js/modern/utils/copy.js +6 -15
  31. package/dist/js/modern/utils/init-env.js +0 -1
  32. package/dist/js/modern/utils/logger.js +1 -16
  33. package/dist/js/modern/utils/readline.js +2 -4
  34. package/dist/js/modern/utils/tsconfig.js +0 -1
  35. package/dist/js/modern/utils/tspaths-transform/constants.js +4 -2
  36. package/dist/js/modern/utils/tspaths-transform/index.js +2 -19
  37. package/dist/js/modern/utils/tspaths-transform/utils.js +0 -3
  38. package/dist/js/modern/utils/valide.js +2 -6
  39. package/dist/js/node/cli/build.js +2 -6
  40. package/dist/js/node/cli/dev.js +2 -7
  41. package/dist/js/node/cli/index.js +0 -6
  42. package/dist/js/node/cli/new.js +0 -8
  43. package/dist/js/node/commands/build.js +0 -19
  44. package/dist/js/node/commands/dev.js +2 -15
  45. package/dist/js/node/commands/index.js +0 -2
  46. package/dist/js/node/features/build/build-platform.js +11 -20
  47. package/dist/js/node/features/build/bundle/index.js +0 -6
  48. package/dist/js/node/features/build/bundle/runRollup.js +3 -32
  49. package/dist/js/node/features/build/bundle/runSpeedy.js +4 -32
  50. package/dist/js/node/features/build/bundleless/copy-assets.js +0 -20
  51. package/dist/js/node/features/build/bundleless/generator-dts/index.js +7 -27
  52. package/dist/js/node/features/build/bundleless/generator-dts/utils.js +6 -32
  53. package/dist/js/node/features/build/bundleless/index.js +0 -11
  54. package/dist/js/node/features/build/bundleless/runBabel.js +6 -60
  55. package/dist/js/node/features/build/bundleless/style.js +1 -50
  56. package/dist/js/node/features/build/constants.js +0 -11
  57. package/dist/js/node/features/build/error.js +4 -40
  58. package/dist/js/node/features/build/index.js +6 -38
  59. package/dist/js/node/features/build/legacy-constants.js +8 -4
  60. package/dist/js/node/features/build/logger/index.js +0 -4
  61. package/dist/js/node/features/build/logger/logText.js +0 -18
  62. package/dist/js/node/features/build/logger/loggerManager.js +5 -26
  63. package/dist/js/node/features/build/normalize.js +18 -61
  64. package/dist/js/node/features/build/utils.js +13 -35
  65. package/dist/js/node/features/dev/index.js +4 -17
  66. package/dist/js/node/hooks/build.js +0 -5
  67. package/dist/js/node/hooks/dev.js +0 -5
  68. package/dist/js/node/hooks/index.js +0 -10
  69. package/dist/js/node/index.js +6 -26
  70. package/dist/js/node/locale/index.js +0 -5
  71. package/dist/js/node/schema/build-config.js +2 -1
  72. package/dist/js/node/schema/index.js +0 -5
  73. package/dist/js/node/schema/output.js +5 -12
  74. package/dist/js/node/utils/babel.js +12 -22
  75. package/dist/js/node/utils/color.js +0 -3
  76. package/dist/js/node/utils/copy.js +6 -23
  77. package/dist/js/node/utils/init-env.js +0 -3
  78. package/dist/js/node/utils/json.js +0 -2
  79. package/dist/js/node/utils/language.js +0 -3
  80. package/dist/js/node/utils/logger.js +1 -26
  81. package/dist/js/node/utils/readline.js +0 -8
  82. package/dist/js/node/utils/tsconfig.js +0 -7
  83. package/dist/js/node/utils/tspaths-transform/constants.js +4 -2
  84. package/dist/js/node/utils/tspaths-transform/index.js +2 -34
  85. package/dist/js/node/utils/tspaths-transform/utils.js +0 -7
  86. package/dist/js/node/utils/valide.js +2 -11
  87. package/dist/types/commands/build.d.ts +0 -1
  88. package/dist/types/features/build/logger/loggerManager.d.ts +0 -1
  89. package/dist/types/features/build/utils.d.ts +1 -3
  90. package/dist/types/hooks/index.d.ts +2 -1
  91. package/dist/types/index.d.ts +2 -2
  92. package/dist/types/schema/types.d.ts +1 -3
  93. package/dist/types/types.d.ts +0 -1
  94. package/package.json +20 -44
package/CHANGELOG.md CHANGED
@@ -1,57 +1,94 @@
1
1
  # @modern-js/module-tools
2
2
 
3
- ## 1.21.5
3
+ ## 2.0.0-beta.1
4
4
 
5
- ### Patch Changes
6
-
7
- - @modern-js/babel-preset-module@1.21.5
8
- - @modern-js/core@1.21.5
9
- - @modern-js/css-config@1.21.5
10
- - @modern-js/plugin-changeset@1.21.5
11
- - @modern-js/plugin-i18n@1.21.5
12
- - @modern-js/plugin-jarvis@1.21.5
13
- - @modern-js/new-action@1.21.5
14
- - @modern-js/babel-compiler@1.21.5
15
- - @modern-js/style-compiler@1.21.5
16
- - @modern-js/plugin@1.21.5
17
- - @modern-js/upgrade@1.21.5
18
- - @modern-js/utils@1.21.5
5
+ ### Major Changes
19
6
 
20
- ## 1.21.4
7
+ - dda38c9: chore: v2
21
8
 
22
9
  ### Patch Changes
23
10
 
24
- - 89dba24: update speedy-core to fix sass resolve error
11
+ - d61ca88: update speedy version
12
+ 更新依赖里 speedy 的版本
13
+ - b8bbe036c7: feat: export Hooks type
14
+ feat: 导出 Hooks 类型
15
+ - ebbeed1: update speedy-core to fix sass resolve error
25
16
  更新 speedy-core 版本以修复 sass resolve 错误
26
- - @modern-js/babel-preset-module@1.21.4
27
- - @modern-js/core@1.21.4
28
- - @modern-js/css-config@1.21.4
29
- - @modern-js/plugin-changeset@1.21.4
30
- - @modern-js/plugin-i18n@1.21.4
31
- - @modern-js/plugin-jarvis@1.21.4
32
- - @modern-js/new-action@1.21.4
33
- - @modern-js/babel-compiler@1.21.4
34
- - @modern-js/style-compiler@1.21.4
35
- - @modern-js/plugin@1.21.4
36
- - @modern-js/upgrade@1.21.4
37
- - @modern-js/utils@1.21.4
38
-
39
- ## 1.21.3
40
-
41
- ### Patch Changes
42
-
43
- - @modern-js/upgrade@1.21.3
44
- - @modern-js/new-action@1.21.3
45
- - @modern-js/babel-preset-module@1.21.3
46
- - @modern-js/core@1.21.3
47
- - @modern-js/css-config@1.21.3
48
- - @modern-js/plugin-changeset@1.21.3
49
- - @modern-js/plugin-i18n@1.21.3
50
- - @modern-js/plugin-jarvis@1.21.3
51
- - @modern-js/babel-compiler@1.21.3
52
- - @modern-js/style-compiler@1.21.3
53
- - @modern-js/plugin@1.21.3
54
- - @modern-js/utils@1.21.3
17
+ - d4a4566: chore: rename plugin-jarvis to plugin-lint
18
+
19
+ chore: 重命名 plugin-jarvis 为 plugin-lint
20
+
21
+ - 14b712d: fix: use consistent alias type and default value across packages
22
+
23
+ fix: 在各个包中使用一致的 alias 类型定义和默认值
24
+
25
+ - Updated dependencies [c9e800d39a]
26
+ - Updated dependencies [85edee888c]
27
+ - Updated dependencies [92f0ead]
28
+ - Updated dependencies [edd1cfb1af]
29
+ - Updated dependencies [cc971eabfc]
30
+ - Updated dependencies [5b9049f]
31
+ - Updated dependencies [d4a4566]
32
+ - Updated dependencies [92004d1]
33
+ - Updated dependencies [b8bbe036c7]
34
+ - Updated dependencies [d5a31df781]
35
+ - Updated dependencies [dda38c9]
36
+ - Updated dependencies [8b8e1bb571]
37
+ - Updated dependencies [3bbea92b2a]
38
+ - Updated dependencies [f179749]
39
+ - Updated dependencies [abf3421]
40
+ - Updated dependencies [543be9558e]
41
+ - Updated dependencies [14b712d]
42
+ - @modern-js/core@2.0.0-beta.1
43
+ - @modern-js/utils@2.0.0-beta.1
44
+ - @modern-js/plugin-lint@2.0.0-beta.1
45
+ - @modern-js/plugin@2.0.0-beta.1
46
+ - @modern-js/babel-preset-module@2.0.0-beta.1
47
+ - @modern-js/plugin-changeset@2.0.0-beta.1
48
+ - @modern-js/plugin-i18n@2.0.0-beta.1
49
+ - @modern-js/new-action@2.0.0-beta.1
50
+ - @modern-js/babel-compiler@2.0.0-beta.1
51
+ - @modern-js/style-compiler@2.0.0-beta.1
52
+ - @modern-js/upgrade@2.0.0-beta.1
53
+
54
+ ## 2.0.0-beta.0
55
+
56
+ ### Major Changes
57
+
58
+ - dda38c9: chore: v2
59
+
60
+ ### Patch Changes
61
+
62
+ - b8bbe036c: feat: export Hooks type
63
+ feat: 导出 Hooks 类型
64
+ - 14b712d: fix: use consistent alias type and default value across packages
65
+
66
+ fix: 在各个包中使用一致的 alias 类型定义和默认值
67
+
68
+ - Updated dependencies [c9e800d39]
69
+ - Updated dependencies [85edee8]
70
+ - Updated dependencies [edd1cfb1a]
71
+ - Updated dependencies [cc971eabf]
72
+ - Updated dependencies [5b9049f]
73
+ - Updated dependencies [b8bbe036c]
74
+ - Updated dependencies [d5a31df78]
75
+ - Updated dependencies [dda38c9]
76
+ - Updated dependencies [8b8e1bb57]
77
+ - Updated dependencies [3bbea92b2]
78
+ - Updated dependencies [abf3421]
79
+ - Updated dependencies [543be95]
80
+ - Updated dependencies [14b712d]
81
+ - @modern-js/core@2.0.0-beta.0
82
+ - @modern-js/utils@2.0.0-beta.0
83
+ - @modern-js/plugin@2.0.0-beta.0
84
+ - @modern-js/babel-preset-module@2.0.0-beta.0
85
+ - @modern-js/plugin-changeset@2.0.0-beta.0
86
+ - @modern-js/plugin-i18n@2.0.0-beta.0
87
+ - @modern-js/plugin-jarvis@2.0.0-beta.0
88
+ - @modern-js/new-action@2.0.0-beta.0
89
+ - @modern-js/babel-compiler@2.0.0-beta.0
90
+ - @modern-js/style-compiler@2.0.0-beta.0
91
+ - @modern-js/upgrade@2.0.0-beta.0
55
92
 
56
93
  ## 1.21.2
57
94
 
@@ -2,7 +2,8 @@ import { Import } from '@modern-js/utils';
2
2
  const local = Import.lazy('../locale/index', require);
3
3
  const command = Import.lazy('../commands/build', require);
4
4
  export const buildCli = (program, api) => {
5
- return 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)) // @deprecated
5
+ return 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))
6
+ // @deprecated
6
7
  // The `--no-tsc` option has been superceded by the `--no-dts` option.
7
8
  .option('--no-tsc', local.i18n.t(local.localeKeys.command.build.no_tsc)).option('--dts', local.i18n.t(local.localeKeys.command.build.dts)).option('--no-clear', local.i18n.t(local.localeKeys.command.build.no_clear)).option('-c --config <config>', local.i18n.t(local.localeKeys.command.build.config)).action(async subCommand => {
8
9
  await command.build(api, subCommand);
@@ -3,8 +3,8 @@ const local = Import.lazy('../locale', require);
3
3
  const commands = Import.lazy('../commands', require);
4
4
  export const devCli = (program, api) => {
5
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(api, params, subCmd); // support plugin-proxy
7
-
6
+ await commands.dev(api, params, subCmd);
7
+ // support plugin-proxy
8
8
  const runner = api.useHookRunners();
9
9
  await runner.afterDev();
10
10
  });
@@ -1,9 +1,6 @@
1
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
2
  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
3
  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
-
7
4
  import { Import } from '@modern-js/utils';
8
5
  const newAction = Import.lazy('@modern-js/new-action', require);
9
6
  const local = Import.lazy('../locale', require);
@@ -8,7 +8,6 @@ const buildFeature = Import.lazy('../features/build', require);
8
8
  * init work before build task.
9
9
  * @param api
10
10
  */
11
-
12
11
  export const init = api => {
13
12
  const {
14
13
  appDirectory
@@ -18,14 +17,12 @@ export const init = api => {
18
17
  if (code === 0) {
19
18
  return;
20
19
  }
21
-
22
20
  const tempTsconfigPathPattern = path.join(appDirectory, './node_modules', `./tsconfig.**.**.json`);
23
21
  const files = globby(slash(tempTsconfigPathPattern), {
24
22
  stats: true,
25
23
  absolute: true
26
24
  });
27
25
  const currentTime = Date.now();
28
-
29
26
  for (const file of files) {
30
27
  // over 30s, will delete it
31
28
  if (currentTime - file.stats.birthtimeMs >= 30 * 1000) {
@@ -36,7 +33,6 @@ export const init = api => {
36
33
  };
37
34
  export const build = async (api, buildCommandOption) => {
38
35
  var _modernConfig$output$;
39
-
40
36
  const {
41
37
  watch = false,
42
38
  tsconfig: tsconfigName,
@@ -3,9 +3,7 @@ import { dotenv, Import } from '@modern-js/utils';
3
3
  const devFeature = Import.lazy('../features/dev', require);
4
4
  const tsConfigutils = Import.lazy('../utils/tsconfig', require);
5
5
  const valid = Import.lazy('../utils/valide', require);
6
-
7
6
  const existSubCmd = subCmd => subCmd.length > 0;
8
-
9
7
  export const dev = async (api, option, subCmd = '') => {
10
8
  const {
11
9
  tsconfig: tsconfigName
@@ -22,16 +20,15 @@ export const dev = async (api, option, subCmd = '') => {
22
20
  tsconfigPath
23
21
  });
24
22
  const isTsProject = tsConfigutils.existTsConfigFile(tsconfigPath);
25
-
26
23
  if (existSubCmd(subCmd)) {
27
24
  await devFeature.runSubCmd(api, subCmd, {
28
25
  isTsProject,
29
26
  appDirectory
30
27
  });
31
28
  return;
32
- } // Compatible with the use of jupiter, RUN_PLATFORM is used in jupiter
33
-
29
+ }
34
30
 
31
+ // Compatible with the use of jupiter, RUN_PLATFORM is used in jupiter
35
32
  if (process.env.RUN_PLATFORM) {
36
33
  await devFeature.showMenu(api, {
37
34
  isTsProject,
@@ -1,9 +1,6 @@
1
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
2
  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
3
  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
-
7
4
  import { execa, Import, chalk } from '@modern-js/utils';
8
5
  const lg = Import.lazy('./logger', require);
9
6
  const pMap = Import.lazy('p-map', require);
@@ -12,18 +9,16 @@ export const buildPlatform = async (api, option) => {
12
9
  isTsProject = false,
13
10
  platform
14
11
  } = option;
15
- const lm = new lg.LoggerManager(); // 获取platforms的参数
16
-
12
+ const lm = new lg.LoggerManager();
13
+ // 获取platforms的参数
17
14
  const runners = api.useHookRunners();
18
15
  const buildTasks = await runners.platformBuild({
19
16
  isTsProject
20
17
  });
21
-
22
18
  if (buildTasks.length <= 0) {
23
19
  console.info(chalk.yellow('No build tasks detected.\nYou can use the `new` command to enable the more features'));
24
20
  return;
25
21
  }
26
-
27
22
  const loggerMap = {};
28
23
  const taskMapper = buildTasks.filter(task => platform === 'all' || task.name === platform).map(params => {
29
24
  const logger = lm.createLoggerText({
@@ -34,12 +29,10 @@ export const buildPlatform = async (api, option) => {
34
29
  logger
35
30
  }, params);
36
31
  });
37
-
38
32
  if (taskMapper.length <= 0) {
39
33
  console.info(chalk.yellow(`'${platform}' is undefined task`));
40
34
  return;
41
35
  }
42
-
43
36
  lm.showCompiling();
44
37
  await pMap(taskMapper, async ({
45
38
  taskPath,
@@ -49,23 +42,27 @@ export const buildPlatform = async (api, option) => {
49
42
  const childProcess = execa.node(taskPath, params, {
50
43
  stdio: 'inherit',
51
44
  all: true
52
- }); // lm.addStdout(logger, childProcess.stdout, {
45
+ });
46
+
47
+ // lm.addStdout(logger, childProcess.stdout, {
53
48
  // event: { data: true, error: true },
54
49
  // });
55
- // lm.addStderr(logger, childProcess.stderr);
56
50
 
51
+ // lm.addStderr(logger, childProcess.stderr);
57
52
  try {
58
53
  await childProcess;
59
54
  } catch (_unused) {
60
55
  // eslint-disable-next-line no-process-exit
61
56
  process.exit(1);
62
- } // lm.disappearCompiling();
57
+ }
58
+ // lm.disappearCompiling();
63
59
  // console.info(lg.colors.title(title));
64
60
  // console.info(a.all);
65
-
66
61
  }, {
67
62
  concurrency: 1
68
- }); // lm.disappearCompiling();
63
+ });
64
+
65
+ // lm.disappearCompiling();
69
66
  // for (const key of Object.keys(loggerMap)) {
70
67
  // console.info(loggerMap[key].value);
71
68
  // }
@@ -1,30 +1,26 @@
1
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
2
  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
3
  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
-
7
4
  import path from 'path';
8
5
  import ts from 'typescript';
9
6
  import hashbangPlugin from 'rollup-plugin-hashbang';
10
7
  import jsonPlugin from '@rollup/plugin-json';
11
8
  import { InternalDTSError } from "../error";
12
- import { SectionTitleStatus, watchSectionTitle } from "../utils"; // Copied from https://github.com/egoist/tsup/blob/dev/src/rollup.ts
9
+ import { SectionTitleStatus, watchSectionTitle } from "../utils";
10
+
11
+ // Copied from https://github.com/egoist/tsup/blob/dev/src/rollup.ts
13
12
 
14
13
  const loadCompilerOptions = tsconfig => {
15
14
  if (!tsconfig) {
16
15
  return {};
17
16
  }
18
-
19
17
  const configFile = ts.readConfigFile(tsconfig, ts.sys.readFile);
20
18
  const {
21
19
  options
22
20
  } = ts.parseJsonConfigFileContent(configFile.config, ts.sys, './');
23
21
  return options;
24
22
  };
25
-
26
23
  const dtsPlugin = require('rollup-plugin-dts');
27
-
28
24
  const getRollupConfig = async (api, options) => {
29
25
  const {
30
26
  appDirectory
@@ -46,29 +42,23 @@ const getRollupConfig = async (api, options) => {
46
42
  };
47
43
  const ignoreFiles = {
48
44
  name: 'ignore-files',
49
-
50
45
  load(id) {
51
46
  if (!/\.(js|jsx|ts|tsx|json)$/.test(id)) {
52
47
  return '';
53
48
  }
54
-
55
49
  return null;
56
50
  }
57
-
58
51
  };
59
52
  return {
60
53
  inputConfig: {
61
54
  input: dtsOptions.entry,
62
55
  external: bundleOptions.externals,
63
-
64
56
  onwarn(warning, handler) {
65
57
  if (warning.code === 'UNRESOLVED_IMPORT' || warning.code === 'CIRCULAR_DEPENDENCY' || warning.code === 'EMPTY_BUNDLE') {
66
58
  return;
67
59
  }
68
-
69
60
  handler(warning);
70
61
  },
71
-
72
62
  plugins: [hashbangPlugin(), jsonPlugin(), ignoreFiles, dtsPlugin.default({
73
63
  // use external to prevent them which come from node_modules from be bundled.
74
64
  respectExternal: true,
@@ -98,7 +88,6 @@ const getRollupConfig = async (api, options) => {
98
88
  }
99
89
  };
100
90
  };
101
-
102
91
  async function runRollup(options, context) {
103
92
  try {
104
93
  const {
@@ -114,7 +103,6 @@ async function runRollup(options, context) {
114
103
  }
115
104
  }
116
105
  }
117
-
118
106
  async function watchRollup(options) {
119
107
  const {
120
108
  watch
@@ -128,15 +116,14 @@ async function watchRollup(options) {
128
116
  console.info(watchSectionTitle(titleText, SectionTitleStatus.Log));
129
117
  } else if (event.code === 'BUNDLE_END') {
130
118
  console.info(watchSectionTitle(titleText, SectionTitleStatus.Success));
131
- } else if (event.code === 'ERROR') {// this is dts rollup plugin bug, error not complete message
119
+ } else if (event.code === 'ERROR') {
120
+ // this is dts rollup plugin bug, error not complete message
132
121
  }
133
122
  });
134
123
  }
135
-
136
124
  export const startRollup = async (api, options) => {
137
125
  if (options.enableDts) {
138
126
  const config = await getRollupConfig(api, options);
139
-
140
127
  if (options.watch) {
141
128
  watchRollup(config);
142
129
  } else {
@@ -1,9 +1,6 @@
1
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
2
  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
3
  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
-
7
4
  import path from 'path';
8
5
  import { SpeedyBundler } from '@speedy-js/speedy-core';
9
6
  import { es5InputPlugin } from '@speedy-js/speedy-plugin-es5';
@@ -17,8 +14,8 @@ export const getAlias = api => {
17
14
  } = api.useAppContext();
18
15
  const {
19
16
  source
20
- } = api.useResolvedConfigContext(); // TODO: maybe check tsconfig `paths`
21
-
17
+ } = api.useResolvedConfigContext();
18
+ // TODO: maybe check tsconfig `paths`
22
19
  const defaultAlias = {
23
20
  '@': srcDirectory
24
21
  };
@@ -46,7 +43,6 @@ export const getDefine = api => {
46
43
  }, {});
47
44
  return _objectSpread(_objectSpread({}, envVarsDefine), globalVarsDefine);
48
45
  };
49
-
50
46
  const getStyleOptionFromModern = async api => {
51
47
  const runner = api.useHookRunners();
52
48
  const {
@@ -69,13 +65,10 @@ const getStyleOptionFromModern = async api => {
69
65
  onLast: async _ => undefined
70
66
  });
71
67
  const postcssOption = getPostcssOption(appDirectory, modernConfig);
72
-
73
68
  if (tailwindPlugin) {
74
69
  var _postcssOption$plugin;
75
-
76
70
  (_postcssOption$plugin = postcssOption.plugins) === null || _postcssOption$plugin === void 0 ? void 0 : _postcssOption$plugin.push(tailwindPlugin);
77
71
  }
78
-
79
72
  return {
80
73
  less: lessOption === null || lessOption === void 0 ? void 0 : lessOption.lessOption,
81
74
  sass: sassOption,
@@ -84,7 +77,6 @@ const getStyleOptionFromModern = async api => {
84
77
  })
85
78
  };
86
79
  };
87
-
88
80
  export const runSpeedy = async (api, config) => {
89
81
  const {
90
82
  appDirectory
@@ -118,23 +110,19 @@ export const runSpeedy = async (api, config) => {
118
110
  const style = await getStyleOptionFromModern(api);
119
111
  const alias = getAlias(api);
120
112
  const define = getDefine(api);
121
-
122
113
  const watchPlugin = () => {
123
114
  return {
124
115
  name: 'watch-plugin',
125
-
126
116
  apply(compiler) {
127
117
  compiler.hooks.watchChange.tap('watch-plugin', async () => {
128
118
  console.info(watchSectionTitle(titleText, SectionTitleStatus.Log));
129
119
  });
130
120
  }
131
-
132
121
  };
133
122
  };
134
-
135
123
  const plugins = target === 'es5' ? [es5InputPlugin()] : [];
136
- plugins.push(watchPlugin()); // TODO: add speedy plugin about react
137
-
124
+ plugins.push(watchPlugin());
125
+ // TODO: add speedy plugin about react
138
126
  const internalSpeedyConfig = {
139
127
  command: 'build',
140
128
  mode: 'production',
@@ -165,12 +153,10 @@ export const runSpeedy = async (api, config) => {
165
153
  };
166
154
  const speedyConfig = applyOptionsChain(internalSpeedyConfig, userSpeedyConfig);
167
155
  const compiler = await SpeedyBundler.create(speedyConfig);
168
-
169
156
  try {
170
157
  if (watch) {
171
158
  console.info(watchSectionTitle(titleText, SectionTitleStatus.Log));
172
159
  }
173
-
174
160
  await compiler.build();
175
161
  } catch (e) {
176
162
  /**
@@ -2,7 +2,6 @@ import * as path from 'path';
2
2
  import { fs, watch, glob, WatchChangeType, Import } from '@modern-js/utils';
3
3
  const copyUtils = Import.lazy('../../../utils/copy', require);
4
4
  const SRC_DIRS = 'src';
5
-
6
5
  const copyAssets = ({
7
6
  targetDir,
8
7
  outputDir
@@ -10,18 +9,15 @@ const copyAssets = ({
10
9
  const assetsFiles = glob.sync(`${targetDir}/**/*.*`, {
11
10
  ignore: ['**/*.{js,jsx,ts,tsx,d.ts,scss,less,css,sass}']
12
11
  });
13
-
14
12
  if (assetsFiles.length > 0) {
15
13
  fs.ensureDirSync(outputDir);
16
14
  }
17
-
18
15
  for (const resource of assetsFiles) {
19
16
  const file = path.relative(targetDir, resource);
20
17
  fs.ensureDirSync(path.dirname(path.resolve(outputDir, file)));
21
18
  fs.copyFileSync(resource, path.resolve(outputDir, file));
22
19
  }
23
20
  };
24
-
25
21
  const watchAssets = (api, {
26
22
  targetDir,
27
23
  outputDir
@@ -35,15 +31,12 @@ const watchAssets = (api, {
35
31
  fs.removeSync(removeFile);
36
32
  return;
37
33
  }
38
-
39
34
  const file = path.relative(targetDir, changedFilePath);
40
35
  fs.copyFileSync(changedFilePath, path.resolve(outputDir, file));
41
36
  }, ['**/*.{js,jsx,ts,tsx,d.ts,scss,less,css,sass}']);
42
37
  };
43
-
44
38
  export const copyStaticAssets = async (api, config) => {
45
39
  var _bundlelessOptions$so;
46
-
47
40
  const appContext = api.useAppContext();
48
41
  const modernConfig = api.useResolvedConfigContext();
49
42
  const {
@@ -73,7 +66,6 @@ export const copyStaticAssets = async (api, config) => {
73
66
  modernConfig,
74
67
  appContext
75
68
  });
76
-
77
69
  if (config.watch) {
78
70
  watchAssets(api, {
79
71
  targetDir: srcDir,
@@ -4,20 +4,16 @@ import { InternalDTSError } from "../../error";
4
4
  import { SectionTitleStatus, watchSectionTitle } from "../../utils";
5
5
  import { getTscBinPath } from "./utils";
6
6
  const utils = Import.lazy('./utils', require);
7
-
8
7
  const getProjectTsconfig = tsconfigPath => {
9
8
  if (!tsconfigPath || !fs.existsSync(tsconfigPath)) {
10
9
  return {};
11
10
  }
12
-
13
11
  return json5.parse(fs.readFileSync(tsconfigPath, 'utf-8'));
14
12
  };
15
-
16
13
  const resolveLog = (childProgress, {
17
14
  watch: _watch = false
18
15
  } = {}) => {
19
16
  var _childProgress$stdout, _childProgress$stdout2, _childProgress$stderr;
20
-
21
17
  /**
22
18
  * tsc 所有的log信息都是从stdout data 事件中获取
23
19
  * 正常模式下,如果有报错信息,交给 resolveLog 后面的逻辑来处理
@@ -28,8 +24,8 @@ const resolveLog = (childProgress, {
28
24
  console.info(watchSectionTitle('[Bundleless:DTS]', SectionTitleStatus.Log));
29
25
  console.info(data.toString());
30
26
  }
31
- }); // 正常以下内容都不会触发,因为tsc 不会产生以下类型的log信息,不过防止意外情况
32
-
27
+ });
28
+ // 正常以下内容都不会触发,因为tsc 不会产生以下类型的log信息,不过防止意外情况
33
29
  (_childProgress$stdout2 = childProgress.stdout) === null || _childProgress$stdout2 === void 0 ? void 0 : _childProgress$stdout2.on('error', error => {
34
30
  console.error(error.message);
35
31
  });
@@ -37,7 +33,6 @@ const resolveLog = (childProgress, {
37
33
  console.error(chunk.toString());
38
34
  });
39
35
  };
40
-
41
36
  const generatorDts = async (_, config) => {
42
37
  const {
43
38
  tsconfigPath,
@@ -54,9 +49,9 @@ const generatorDts = async (_, config) => {
54
49
  });
55
50
  const tscBinFile = getTscBinPath(appDirectory);
56
51
  const watchParams = watch ? ['-w'] : [];
57
- const childProgress = execa(tscBinFile, ['-p', willDeleteTsconfigPath,
58
- /* Required parameter, use it stdout have color */
59
- '--pretty', // https://github.com/microsoft/TypeScript/issues/21824
52
+ const childProgress = execa(tscBinFile, ['-p', willDeleteTsconfigPath, /* Required parameter, use it stdout have color */
53
+ '--pretty',
54
+ // https://github.com/microsoft/TypeScript/issues/21824
60
55
  '--preserveWatchOutput', ...watchParams], {
61
56
  stdio: 'pipe',
62
57
  cwd: appDirectory
@@ -64,7 +59,6 @@ const generatorDts = async (_, config) => {
64
59
  resolveLog(childProgress, {
65
60
  watch
66
61
  });
67
-
68
62
  try {
69
63
  await childProgress;
70
64
  } catch (e) {
@@ -74,10 +68,8 @@ const generatorDts = async (_, config) => {
74
68
  });
75
69
  }
76
70
  }
77
-
78
71
  fs.removeSync(willDeleteTsconfigPath);
79
72
  };
80
-
81
73
  export const genDts = async (api, config) => {
82
74
  const {
83
75
  outputPath,
@@ -88,11 +80,9 @@ export const genDts = async (api, config) => {
88
80
  },
89
81
  enableDts
90
82
  } = config;
91
-
92
83
  if (!enableDts) {
93
84
  return;
94
85
  }
95
-
96
86
  const {
97
87
  appDirectory
98
88
  } = api.useAppContext();
@@ -110,7 +100,7 @@ export const genDts = async (api, config) => {
110
100
  watch,
111
101
  sourceDir
112
102
  };
113
- await generatorDts(modernConfig, option); // TODO: watch 模式下无法转换
114
-
103
+ await generatorDts(modernConfig, option);
104
+ // TODO: watch 模式下无法转换
115
105
  utils.resolveAlias(modernConfig, option);
116
106
  };