@modern-js/module-tools 1.5.5 → 1.6.0-alpha.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 (116) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/dist/js/modern/cli/build.js +5 -4
  3. package/dist/js/modern/commands/build.js +40 -27
  4. package/dist/js/modern/features/build/bundle/index.js +6 -0
  5. package/dist/js/modern/features/build/bundle/runRollup.js +149 -0
  6. package/dist/js/modern/features/build/bundle/runSpeedy.js +185 -0
  7. package/dist/js/modern/{tasks → features/build/bundleless}/copy-assets.js +31 -55
  8. package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/index.js +46 -70
  9. package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/utils.js +6 -6
  10. package/dist/js/modern/features/build/bundleless/index.js +13 -0
  11. package/dist/js/modern/features/build/bundleless/runBabel.js +269 -0
  12. package/dist/js/modern/features/build/bundleless/style.js +266 -0
  13. package/dist/js/modern/features/build/constants.js +94 -59
  14. package/dist/js/modern/features/build/error.js +150 -0
  15. package/dist/js/modern/features/build/index.js +84 -19
  16. package/dist/js/modern/features/build/legacy-constants.js +99 -0
  17. package/dist/js/modern/features/build/normalize.js +293 -0
  18. package/dist/js/modern/features/build/types.js +0 -0
  19. package/dist/js/modern/features/build/utils.js +29 -137
  20. package/dist/js/modern/index.js +3 -1
  21. package/dist/js/modern/locale/en.js +5 -3
  22. package/dist/js/modern/locale/zh.js +5 -3
  23. package/dist/js/modern/schema/build-config.js +104 -0
  24. package/dist/js/modern/schema/index.js +2 -1
  25. package/dist/js/modern/schema/output.js +18 -9
  26. package/dist/js/modern/schema/source.js +2 -10
  27. package/dist/js/modern/schema/tools.js +6 -0
  28. package/dist/js/modern/schema/types.js +0 -0
  29. package/dist/js/modern/utils/babel.js +6 -3
  30. package/dist/js/modern/utils/constants.js +3 -0
  31. package/dist/js/node/cli/build.js +5 -4
  32. package/dist/js/node/commands/build.js +50 -29
  33. package/dist/js/node/features/build/bundle/index.js +17 -0
  34. package/dist/js/node/features/build/bundle/runRollup.js +174 -0
  35. package/dist/js/node/features/build/bundle/runSpeedy.js +209 -0
  36. package/dist/js/node/{tasks → features/build/bundleless}/copy-assets.js +37 -55
  37. package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/index.js +59 -73
  38. package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/utils.js +6 -6
  39. package/dist/js/node/features/build/bundleless/index.js +26 -0
  40. package/dist/js/node/features/build/bundleless/runBabel.js +309 -0
  41. package/dist/js/node/features/build/bundleless/style.js +299 -0
  42. package/dist/js/node/features/build/constants.js +115 -67
  43. package/dist/js/node/features/build/error.js +175 -0
  44. package/dist/js/node/features/build/index.js +92 -19
  45. package/dist/js/node/features/build/legacy-constants.js +107 -0
  46. package/dist/js/node/features/build/normalize.js +322 -0
  47. package/dist/js/node/features/build/types.js +0 -0
  48. package/dist/js/node/features/build/utils.js +31 -145
  49. package/dist/js/node/index.js +5 -1
  50. package/dist/js/node/locale/en.js +5 -3
  51. package/dist/js/node/locale/zh.js +5 -3
  52. package/dist/js/node/schema/build-config.js +113 -0
  53. package/dist/js/node/schema/index.js +3 -1
  54. package/dist/js/node/schema/output.js +20 -9
  55. package/dist/js/node/schema/source.js +2 -10
  56. package/dist/js/node/schema/tools.js +13 -0
  57. package/dist/js/node/schema/types.js +0 -0
  58. package/dist/js/node/utils/babel.js +5 -2
  59. package/dist/js/node/utils/constants.js +11 -0
  60. package/dist/types/cli/build.d.ts +1 -1
  61. package/dist/types/cli/new.d.ts +1 -1
  62. package/dist/types/commands/build.d.ts +12 -12
  63. package/dist/types/features/build/bundle/index.d.ts +3 -0
  64. package/dist/types/features/build/bundle/runRollup.d.ts +3 -0
  65. package/dist/types/features/build/bundle/runSpeedy.d.ts +10 -0
  66. package/dist/types/features/build/bundleless/copy-assets.d.ts +3 -0
  67. package/dist/types/features/build/bundleless/generator-dts/index.d.ts +3 -0
  68. package/dist/types/{tasks → features/build/bundleless}/generator-dts/utils.d.ts +3 -6
  69. package/dist/types/features/build/bundleless/index.d.ts +4 -0
  70. package/dist/types/features/build/bundleless/runBabel.d.ts +32 -0
  71. package/dist/types/features/build/bundleless/style.d.ts +25 -0
  72. package/dist/types/features/build/constants.d.ts +17 -13
  73. package/dist/types/features/build/error.d.ts +33 -0
  74. package/dist/types/features/build/index.d.ts +4 -3
  75. package/dist/types/features/build/legacy-constants.d.ts +8 -0
  76. package/dist/types/features/build/logger/loggerManager.d.ts +2 -0
  77. package/dist/types/features/build/normalize.d.ts +18 -0
  78. package/dist/types/features/build/types.d.ts +15 -0
  79. package/dist/types/features/build/utils.d.ts +9 -31
  80. package/dist/types/locale/en.d.ts +2 -0
  81. package/dist/types/locale/index.d.ts +4 -0
  82. package/dist/types/locale/zh.d.ts +2 -0
  83. package/dist/types/schema/build-config.d.ts +179 -0
  84. package/dist/types/schema/index.d.ts +166 -18
  85. package/dist/types/schema/output.d.ts +170 -10
  86. package/dist/types/schema/source.d.ts +2 -11
  87. package/dist/types/schema/tools.d.ts +6 -0
  88. package/dist/types/schema/types.d.ts +45 -0
  89. package/dist/types/types.d.ts +29 -28
  90. package/dist/types/utils/babel.d.ts +3 -2
  91. package/dist/types/utils/constants.d.ts +2 -0
  92. package/dist/types/utils/logger.d.ts +2 -0
  93. package/package.json +29 -16
  94. package/dist/js/modern/features/build/build-watch.js +0 -101
  95. package/dist/js/modern/features/build/build.js +0 -123
  96. package/dist/js/modern/tasks/build-source-code.js +0 -207
  97. package/dist/js/modern/tasks/build-style.js +0 -168
  98. package/dist/js/modern/tasks/build-watch-source-code.js +0 -161
  99. package/dist/js/modern/tasks/build-watch-style.js +0 -215
  100. package/dist/js/modern/tasks/constants.js +0 -1
  101. package/dist/js/node/features/build/build-watch.js +0 -121
  102. package/dist/js/node/features/build/build.js +0 -143
  103. package/dist/js/node/tasks/build-source-code.js +0 -233
  104. package/dist/js/node/tasks/build-style.js +0 -183
  105. package/dist/js/node/tasks/build-watch-source-code.js +0 -173
  106. package/dist/js/node/tasks/build-watch-style.js +0 -232
  107. package/dist/js/node/tasks/constants.js +0 -8
  108. package/dist/types/features/build/build-watch.d.ts +0 -3
  109. package/dist/types/features/build/build.d.ts +0 -3
  110. package/dist/types/tasks/build-source-code.d.ts +0 -25
  111. package/dist/types/tasks/build-style.d.ts +0 -1
  112. package/dist/types/tasks/build-watch-source-code.d.ts +0 -1
  113. package/dist/types/tasks/build-watch-style.d.ts +0 -1
  114. package/dist/types/tasks/constants.d.ts +0 -1
  115. package/dist/types/tasks/copy-assets.d.ts +0 -1
  116. package/dist/types/tasks/generator-dts/index.d.ts +0 -1
@@ -1,17 +1,19 @@
1
1
  import { Import } from '@modern-js/utils';
2
2
  import ChangesetPlugin from '@modern-js/plugin-changeset';
3
3
  import AnalyzePlugin from '@modern-js/plugin-analyze';
4
+ import LintPlugin from '@modern-js/plugin-jarvis';
4
5
  import { hooks } from "./hooks";
5
6
  const cli = Import.lazy('./cli', require);
6
7
  const local = Import.lazy('./locale', require);
7
8
  const schema = Import.lazy('./schema', require);
8
9
  const lang = Import.lazy('./utils/language', require);
9
10
  export { defineConfig } from '@modern-js/core';
11
+ const isBuildMode = process.argv.slice(2)[0] === 'build';
10
12
  export default (() => ({
11
13
  name: '@modern-js/module-tools',
12
14
  post: ['@modern-js/plugin-analyze', '@modern-js/plugin-changeset'],
13
15
  registerHook: hooks,
14
- usePlugins: [ChangesetPlugin(), AnalyzePlugin()],
16
+ usePlugins: [ChangesetPlugin(), ...(isBuildMode ? [] : [AnalyzePlugin()]), LintPlugin()],
15
17
  setup: api => {
16
18
  const locale = lang.getLocaleLanguage();
17
19
  local.i18n.changeLanguage({
@@ -5,9 +5,11 @@ export const EN_LOCALE = {
5
5
  watch: 'building module in watch mode',
6
6
  tsconfig: 'Specify a path to the tsconfig.json file',
7
7
  style_only: 'only build style',
8
- platform: 'building for other platforms',
9
- no_tsc: 'close tsc compiler to emit d.ts',
10
- no_clear: 'disable auto clear dist dir'
8
+ platform: 'build the specified task or all tasks, If exist. (tasks: "storybook", "docs")',
9
+ no_tsc: 'close tsc compiler to emit d.ts (Deprecated)',
10
+ dts: 'Turn on dts generation and type checking',
11
+ no_clear: 'disable auto clear dist dir',
12
+ config: 'specify config file'
11
13
  },
12
14
  dev: {
13
15
  describe: 'start dev server'
@@ -5,9 +5,11 @@ export const ZH_LOCALE = {
5
5
  watch: '使用 Watch 模式构建模块',
6
6
  tsconfig: '指定 tsconfig.json 文件的路径',
7
7
  style_only: '只构建样式文件',
8
- platform: '构建其他平台产物',
9
- no_tsc: '关闭 tsc 编译',
10
- no_clear: '不清理产物目录'
8
+ platform: '如果存在的话,执行指定的构建任务或者全部构建任务. (构建任务包括: "storybook", "文档")',
9
+ no_tsc: '关闭 tsc 编译(废弃)',
10
+ dts: '开启 dts 文件的生成以及类型检查',
11
+ no_clear: '不清理产物目录',
12
+ config: '指定配置文件路径,可以为相对路径或绝对路径'
11
13
  },
12
14
  dev: {
13
15
  describe: '本地开发命令'
@@ -0,0 +1,104 @@
1
+ export const targets = ['es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', // The default target is esnext which means that by default, assume all of the latest JavaScript and CSS features are supported.
2
+ 'esnext'];
3
+ export const presets = ['npm-library', 'npm-library-with-umd', 'npm-component', 'npm-component-with-umd', ...['npm-library', 'npm-library-with-umd', 'npm-component', 'npm-component-with-umd'].reduce((ret, crt) => {
4
+ return [...ret, ...targets.map(t => `${crt}-${t}`)];
5
+ }, [])];
6
+ const properties = {
7
+ target: {
8
+ enum: targets
9
+ },
10
+ format: {
11
+ enum: ['cjs', 'esm', 'umd']
12
+ },
13
+ sourceMap: {
14
+ enum: [true, false, 'inline', 'external']
15
+ },
16
+ buildType: {
17
+ enum: ['bundle', 'bundleless']
18
+ },
19
+ bundleOptions: {
20
+ type: 'object',
21
+ properties: {
22
+ entry: {
23
+ type: 'object'
24
+ },
25
+ splitting: {
26
+ type: 'boolean'
27
+ },
28
+ externals: {
29
+ type: 'array',
30
+ items: [{
31
+ type: 'string'
32
+ }]
33
+ },
34
+ platform: {
35
+ enum: ['node', 'browser']
36
+ },
37
+ minify: {
38
+ enum: ['esbuild', 'terser', false]
39
+ }
40
+ }
41
+ },
42
+ bundlelessOptions: {
43
+ type: 'object',
44
+ properties: {
45
+ sourceDir: {
46
+ type: 'string'
47
+ },
48
+ style: {
49
+ type: 'object',
50
+ properties: {
51
+ compileMode: {
52
+ enum: ['all', 'only-compiled-code', 'only-source-code', false]
53
+ },
54
+ path: {
55
+ type: 'string'
56
+ }
57
+ }
58
+ },
59
+ static: {
60
+ type: 'object',
61
+ properties: {
62
+ path: {
63
+ type: 'string'
64
+ }
65
+ }
66
+ }
67
+ }
68
+ },
69
+ tsconfig: {
70
+ type: 'string'
71
+ },
72
+ enableDts: {
73
+ type: 'boolean'
74
+ },
75
+ dtsOnly: {
76
+ type: 'boolean'
77
+ },
78
+ outputPath: {
79
+ type: 'string'
80
+ }
81
+ };
82
+ export const buildSchema = [{
83
+ target: 'output.buildConfig',
84
+ schema: {
85
+ if: {
86
+ type: 'array'
87
+ },
88
+ then: {
89
+ items: [{
90
+ type: 'object',
91
+ properties
92
+ }]
93
+ },
94
+ else: {
95
+ type: 'object',
96
+ properties
97
+ }
98
+ }
99
+ }, {
100
+ target: 'output.buildPreset',
101
+ schema: {
102
+ enum: presets
103
+ }
104
+ }];
@@ -1,3 +1,4 @@
1
1
  import { sourceSchema } from "./source";
2
2
  import { outputSchema } from "./output";
3
- export const addSchema = () => [...sourceSchema, ...outputSchema];
3
+ import { toolsSchema } from "./tools";
4
+ export const addSchema = () => [...sourceSchema, ...outputSchema, ...toolsSchema];
@@ -1,30 +1,39 @@
1
+ import { buildSchema } from "./build-config";
1
2
  const PACKAGE_MODE_LIST = ['universal-js', 'universal-js-lite', 'browser-js', 'browser-js-lite', 'node-js'];
2
- export const outputSchema = [{
3
+ export const outputSchema = [
4
+ /** packageMode will deprecated */
5
+ {
3
6
  target: 'output.packageMode',
4
7
  schema: {
5
8
  enum: PACKAGE_MODE_LIST
6
9
  }
7
- }, {
10
+ },
11
+ /** packageFields will deprecated */
12
+ {
8
13
  target: 'output.packageFields',
9
14
  schema: {
10
15
  typeof: 'object'
11
16
  }
12
- }, {
17
+ },
18
+ /** enableSourceMap will deprecated */
19
+ {
13
20
  target: 'output.enableSourceMap',
14
21
  schema: {
15
22
  typeof: 'boolean'
16
23
  }
17
- }, {
24
+ },
25
+ /** importStyle will deprecated */
26
+ {
18
27
  target: 'output.importStyle',
19
28
  schema: {
20
- enum: ['compiled-code', 'source-code'],
21
- // TODO: 目前default是无效的
22
- default: 'source-code'
29
+ enum: ['compiled-code', 'source-code']
23
30
  }
24
- }, {
31
+ },
32
+ /** assetsPath will deprecated */
33
+ {
25
34
  target: 'output.assetsPath',
26
35
  schema: {
27
36
  typeof: 'string',
28
37
  default: 'styles'
29
38
  }
30
- }];
39
+ }, ...buildSchema];
@@ -1,15 +1,7 @@
1
- export const sourceSchema = [// 启动区块运行时
2
- {
3
- target: 'source.enableBlockRuntime',
4
- schema: {
5
- type: 'boolean'
6
- }
7
- }, {
1
+ export const sourceSchema = [{
8
2
  target: 'source.jsxTransformRuntime',
9
3
  schema: {
10
4
  // https://babeljs.io/docs/en/babel-preset-react#runtime
11
- enum: ['classic', 'automatic'],
12
- // TODO: 目前default是无效的
13
- default: 'automatic'
5
+ enum: ['classic', 'automatic']
14
6
  }
15
7
  }];
@@ -0,0 +1,6 @@
1
+ export const toolsSchema = [{
2
+ target: 'tools.speedy',
3
+ schema: {
4
+ typeof: ['object', 'function']
5
+ }
6
+ }];
File without changes
@@ -4,7 +4,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
 
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
- import { getBabelConfig } from '@modern-js/babel-preset-module';
7
+ import { getBabelConfig, applyUserBabelConfig } from '@modern-js/babel-preset-module';
8
8
  import { applyOptionsChain, getAlias, isUseSSRBundle } from '@modern-js/utils';
9
9
  export const getFinalAlias = (modernConfig, option) => {
10
10
  const aliasConfig = getAlias(modernConfig.source.alias, option); // 排除内部别名,因为不需要处理
@@ -25,7 +25,7 @@ export const getFinalAlias = (modernConfig, option) => {
25
25
  aliasConfig.paths = finalPaths;
26
26
  return aliasConfig;
27
27
  };
28
- export const resolveBabelConfig = (appDirectory, modernConfig, option) => {
28
+ export const resolveBabelConfig = (appDirectory, modernConfig, sourceMap, bundlelessOptions, option) => {
29
29
  const {
30
30
  source: {
31
31
  envVars,
@@ -60,6 +60,8 @@ export const resolveBabelConfig = (appDirectory, modernConfig, option) => {
60
60
  lodashOptions,
61
61
  jsxTransformRuntime,
62
62
  importStyle,
63
+ styleDir: bundlelessOptions.style.path,
64
+ staticDir: bundlelessOptions.static.path,
63
65
  styledComponentsOptions: applyOptionsChain({
64
66
  pure: true,
65
67
  displayName: true,
@@ -72,6 +74,7 @@ export const resolveBabelConfig = (appDirectory, modernConfig, option) => {
72
74
  }); // Preventing warning when files are too large
73
75
 
74
76
  internalBabelConfig.compact = false;
77
+ internalBabelConfig.sourceMaps = sourceMap === 'external' ? true : sourceMap;
75
78
  const userBabelConfig = modernConfig.tools.babel;
76
- return applyOptionsChain(internalBabelConfig, userBabelConfig);
79
+ return applyUserBabelConfig(internalBabelConfig, userBabelConfig);
77
80
  };
@@ -0,0 +1,3 @@
1
+ // generator tsconfig file
2
+ export const tempTsconfigName = 'tsconfig.temp.json';
3
+ export const cliTsConfigDefaultValue = './tsconfig.json';
@@ -9,12 +9,13 @@ var _utils = require("@modern-js/utils");
9
9
 
10
10
  const local = _utils.Import.lazy('../locale/index', require);
11
11
 
12
- const commands = _utils.Import.lazy('../commands', require);
12
+ const command = _utils.Import.lazy('../commands/build', require);
13
13
 
14
14
  const buildCli = (program, api) => {
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('-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
- await commands.build(api, subCommand);
15
+ 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
16
+ // The `--no-tsc` option has been superceded by the `--no-dts` option.
17
+ .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 => {
18
+ await command.build(api, subCommand);
18
19
  });
19
20
  };
20
21
 
@@ -3,12 +3,18 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.build = void 0;
6
+ exports.init = exports.build = void 0;
7
7
 
8
8
  var path = _interopRequireWildcard(require("path"));
9
9
 
10
10
  var _utils = require("@modern-js/utils");
11
11
 
12
+ var _signalExit = _interopRequireDefault(require("signal-exit"));
13
+
14
+ var _constants = require("../utils/constants");
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
12
18
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
19
 
14
20
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -18,48 +24,63 @@ const tsConfigutils = _utils.Import.lazy('../utils/tsconfig', require);
18
24
  const valid = _utils.Import.lazy('../utils/valide', require);
19
25
 
20
26
  const buildFeature = _utils.Import.lazy('../features/build', require);
27
+ /**
28
+ * init work before build task.
29
+ * @param api
30
+ */
21
31
 
22
- const build = async (api, {
23
- watch: _watch = false,
24
- tsconfig: tsconfigName,
25
- tsc,
26
- clear: _clear = true,
27
- platform,
28
- styleOnly
29
- }) => {
32
+
33
+ const init = api => {
30
34
  const {
31
35
  appDirectory
32
36
  } = api.useAppContext();
33
- const modernConfig = api.useResolvedConfigContext();
34
- const tsconfigPath = path.join(appDirectory, tsconfigName);
35
37
 
36
38
  _utils.dotenv.config();
37
39
 
40
+ (0, _signalExit.default)(() => {
41
+ const tempTsconfigFileAbsPath = path.join(appDirectory, './node_modules', `./${_constants.tempTsconfigName}`);
42
+
43
+ _utils.fs.removeSync(tempTsconfigFileAbsPath);
44
+ });
45
+ };
46
+
47
+ exports.init = init;
48
+
49
+ const build = async (api, buildCommandOption) => {
50
+ var _modernConfig$output$;
51
+
52
+ const {
53
+ watch = false,
54
+ tsconfig: tsconfigName,
55
+ tsc,
56
+ dts = false,
57
+ clear,
58
+ platform = false,
59
+ styleOnly = false
60
+ } = buildCommandOption;
61
+ init(api);
62
+ const {
63
+ appDirectory
64
+ } = api.useAppContext();
65
+ const modernConfig = api.useResolvedConfigContext();
66
+ const tsconfigPath = path.join(appDirectory, tsconfigName);
67
+ const outputPath = (_modernConfig$output$ = modernConfig.output.path) !== null && _modernConfig$output$ !== void 0 ? _modernConfig$output$ : 'dist';
38
68
  const isTsProject = tsConfigutils.existTsConfigFile(tsconfigPath);
39
- const enableTscCompiler = isTsProject && tsc && !modernConfig.output.disableTsChecker;
69
+ const enableDtsGen = isTsProject && dts;
40
70
  valid.valideBeforeTask({
41
71
  modernConfig,
42
72
  tsconfigPath
43
- }); // TODO: 一些配置只需要从modernConfig中获取
44
-
73
+ });
45
74
  await buildFeature.build(api, {
46
- appDirectory,
47
- enableWatchMode: _watch,
75
+ enableWatchMode: watch,
76
+ enableDtsGen,
48
77
  isTsProject,
49
- platform,
50
- sourceDir: 'src',
51
78
  tsconfigName,
52
- enableTscCompiler,
53
- clear: _clear,
54
- styleOnly
55
- }, modernConfig);
56
- process.on('SIGBREAK', () => {
57
- console.info('exit');
58
- const tempTsconfigFilePath = path.join(appDirectory, './tsconfig.temp.json');
59
-
60
- if (_utils.fs.existsSync(tempTsconfigFilePath)) {
61
- _utils.fs.removeSync(tempTsconfigFilePath);
62
- }
79
+ outputPath,
80
+ styleOnly,
81
+ platform,
82
+ clear,
83
+ legacyTsc: tsc
63
84
  });
64
85
  };
65
86
 
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.build = void 0;
7
+
8
+ var _runSpeedy = require("./runSpeedy");
9
+
10
+ var _runRollup = require("./runRollup");
11
+
12
+ const build = async (api, config) => {
13
+ const tasks = config.dtsOnly ? [(0, _runRollup.startRollup)(api, config)] : [(0, _runSpeedy.runSpeedy)(api, config), (0, _runRollup.startRollup)(api, config)];
14
+ await Promise.all(tasks);
15
+ };
16
+
17
+ exports.build = build;
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.startRollup = void 0;
7
+
8
+ var _path = _interopRequireDefault(require("path"));
9
+
10
+ var _typescript = _interopRequireDefault(require("typescript"));
11
+
12
+ var _rollupPluginHashbang = _interopRequireDefault(require("rollup-plugin-hashbang"));
13
+
14
+ var _pluginJson = _interopRequireDefault(require("@rollup/plugin-json"));
15
+
16
+ var _error = require("../error");
17
+
18
+ var _utils = require("../utils");
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+
22
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
+
24
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
25
+
26
+ 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; }
27
+
28
+ 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; }
29
+
30
+ 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; }
31
+
32
+ // Copied from https://github.com/egoist/tsup/blob/dev/src/rollup.ts
33
+ const loadCompilerOptions = tsconfig => {
34
+ if (!tsconfig) {
35
+ return {};
36
+ }
37
+
38
+ const configFile = _typescript.default.readConfigFile(tsconfig, _typescript.default.sys.readFile);
39
+
40
+ const {
41
+ options
42
+ } = _typescript.default.parseJsonConfigFileContent(configFile.config, _typescript.default.sys, './');
43
+
44
+ return options;
45
+ };
46
+
47
+ const dtsPlugin = require('rollup-plugin-dts');
48
+
49
+ const getRollupConfig = async (api, options) => {
50
+ const {
51
+ appDirectory
52
+ } = api.useAppContext();
53
+ const {
54
+ output: {
55
+ path: distPath = 'dist'
56
+ }
57
+ } = api.useResolvedConfigContext();
58
+ const {
59
+ outputPath,
60
+ bundleOptions,
61
+ tsconfig
62
+ } = options;
63
+
64
+ const distDir = _path.default.join(appDirectory, distPath, outputPath);
65
+
66
+ const compilerOptions = loadCompilerOptions(tsconfig);
67
+ const dtsOptions = {
68
+ entry: bundleOptions.entry
69
+ };
70
+ const ignoreFiles = {
71
+ name: 'ignore-files',
72
+
73
+ load(id) {
74
+ if (!/\.(js|cjs|mjs|jsx|ts|tsx|mts|json)$/.test(id)) {
75
+ return '';
76
+ }
77
+
78
+ return null;
79
+ }
80
+
81
+ };
82
+ return {
83
+ inputConfig: {
84
+ input: dtsOptions.entry,
85
+ external: bundleOptions.externals,
86
+
87
+ onwarn(warning, handler) {
88
+ if (warning.code === 'UNRESOLVED_IMPORT' || warning.code === 'CIRCULAR_DEPENDENCY' || warning.code === 'EMPTY_BUNDLE') {
89
+ return;
90
+ }
91
+
92
+ handler(warning);
93
+ },
94
+
95
+ plugins: [(0, _rollupPluginHashbang.default)(), (0, _pluginJson.default)(), ignoreFiles, dtsPlugin.default({
96
+ // use external to prevent them which come from node_modules from be bundled.
97
+ respectExternal: true,
98
+ compilerOptions: _objectSpread(_objectSpread({}, compilerOptions), {}, {
99
+ baseUrl: _path.default.resolve(compilerOptions.baseUrl || '.'),
100
+ // Ensure ".d.ts" modules are generated
101
+ declaration: true,
102
+ // Skip ".js" generation
103
+ noEmit: false,
104
+ emitDeclarationOnly: true,
105
+ // Skip code generation when error occurs
106
+ noEmitOnError: true,
107
+ // Avoid extra work
108
+ checkJs: false,
109
+ declarationMap: false,
110
+ skipLibCheck: true,
111
+ preserveSymlinks: false,
112
+ // Ensure we can parse the latest code
113
+ target: _typescript.default.ScriptTarget.ESNext
114
+ })
115
+ })].filter(Boolean)
116
+ },
117
+ outputConfig: {
118
+ dir: distDir,
119
+ format: 'esm',
120
+ exports: 'named'
121
+ }
122
+ };
123
+ };
124
+
125
+ async function runRollup(options, context) {
126
+ try {
127
+ const {
128
+ rollup
129
+ } = await Promise.resolve().then(() => _interopRequireWildcard(require('rollup')));
130
+ const bundle = await rollup(options.inputConfig);
131
+ await bundle.write(options.outputConfig);
132
+ } catch (e) {
133
+ if (e instanceof Error) {
134
+ throw new _error.InternalDTSError(e, _objectSpread({
135
+ buildType: 'bundle'
136
+ }, context));
137
+ }
138
+ }
139
+ }
140
+
141
+ async function watchRollup(options) {
142
+ const {
143
+ watch
144
+ } = await Promise.resolve().then(() => _interopRequireWildcard(require('rollup')));
145
+ const titleText = '[Bundle:DTS]';
146
+ watch(_objectSpread(_objectSpread({}, options.inputConfig), {}, {
147
+ plugins: options.inputConfig.plugins,
148
+ output: options.outputConfig
149
+ })).on('event', event => {
150
+ if (event.code === 'START') {
151
+ console.info((0, _utils.watchSectionTitle)(titleText, _utils.SectionTitleStatus.Log));
152
+ } else if (event.code === 'BUNDLE_END') {
153
+ console.info((0, _utils.watchSectionTitle)(titleText, _utils.SectionTitleStatus.Success));
154
+ } else if (event.code === 'ERROR') {// this is dts rollup plugin bug, error not complete message
155
+ }
156
+ });
157
+ }
158
+
159
+ const startRollup = async (api, options) => {
160
+ if (options.enableDts) {
161
+ const config = await getRollupConfig(api, options);
162
+
163
+ if (options.watch) {
164
+ watchRollup(config);
165
+ } else {
166
+ await runRollup(config, {
167
+ target: options.target,
168
+ format: options.format
169
+ });
170
+ }
171
+ }
172
+ };
173
+
174
+ exports.startRollup = startRollup;