@modern-js/module-tools 1.5.7 → 1.6.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 (119) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/dist/js/modern/cli/build.js +5 -4
  3. package/dist/js/modern/commands/build.js +55 -28
  4. package/dist/js/modern/features/build/bundle/index.js +9 -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 +10 -10
  10. package/dist/js/modern/features/build/bundleless/index.js +23 -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 +87 -18
  16. package/dist/js/modern/features/build/legacy-constants.js +99 -0
  17. package/dist/js/modern/features/build/normalize.js +301 -0
  18. package/dist/js/modern/features/build/types.js +0 -0
  19. package/dist/js/modern/features/build/utils.js +39 -136
  20. package/dist/js/modern/index.js +4 -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 +111 -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 +4 -1
  30. package/dist/js/modern/utils/constants.js +3 -0
  31. package/dist/js/modern/utils/copy.js +2 -2
  32. package/dist/js/node/cli/build.js +5 -4
  33. package/dist/js/node/commands/build.js +62 -29
  34. package/dist/js/node/features/build/bundle/index.js +23 -0
  35. package/dist/js/node/features/build/bundle/runRollup.js +174 -0
  36. package/dist/js/node/features/build/bundle/runSpeedy.js +209 -0
  37. package/dist/js/node/{tasks → features/build/bundleless}/copy-assets.js +37 -55
  38. package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/index.js +59 -73
  39. package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/utils.js +9 -10
  40. package/dist/js/node/features/build/bundleless/index.js +40 -0
  41. package/dist/js/node/features/build/bundleless/runBabel.js +309 -0
  42. package/dist/js/node/features/build/bundleless/style.js +299 -0
  43. package/dist/js/node/features/build/constants.js +115 -67
  44. package/dist/js/node/features/build/error.js +175 -0
  45. package/dist/js/node/features/build/index.js +104 -18
  46. package/dist/js/node/features/build/legacy-constants.js +107 -0
  47. package/dist/js/node/features/build/normalize.js +330 -0
  48. package/dist/js/node/features/build/types.js +0 -0
  49. package/dist/js/node/features/build/utils.js +48 -145
  50. package/dist/js/node/index.js +22 -1
  51. package/dist/js/node/locale/en.js +5 -3
  52. package/dist/js/node/locale/zh.js +5 -3
  53. package/dist/js/node/schema/build-config.js +120 -0
  54. package/dist/js/node/schema/index.js +3 -1
  55. package/dist/js/node/schema/output.js +20 -9
  56. package/dist/js/node/schema/source.js +2 -10
  57. package/dist/js/node/schema/tools.js +13 -0
  58. package/dist/js/node/schema/types.js +0 -0
  59. package/dist/js/node/utils/babel.js +4 -1
  60. package/dist/js/node/utils/constants.js +11 -0
  61. package/dist/js/node/utils/copy.js +1 -1
  62. package/dist/types/cli/build.d.ts +1 -1
  63. package/dist/types/cli/new.d.ts +1 -1
  64. package/dist/types/commands/build.d.ts +12 -12
  65. package/dist/types/features/build/bundle/index.d.ts +3 -0
  66. package/dist/types/features/build/bundle/runRollup.d.ts +3 -0
  67. package/dist/types/features/build/bundle/runSpeedy.d.ts +10 -0
  68. package/dist/types/features/build/bundleless/copy-assets.d.ts +3 -0
  69. package/dist/types/features/build/bundleless/generator-dts/index.d.ts +3 -0
  70. package/dist/types/{tasks → features/build/bundleless}/generator-dts/utils.d.ts +3 -6
  71. package/dist/types/features/build/bundleless/index.d.ts +4 -0
  72. package/dist/types/features/build/bundleless/runBabel.d.ts +32 -0
  73. package/dist/types/features/build/bundleless/style.d.ts +25 -0
  74. package/dist/types/features/build/constants.d.ts +17 -13
  75. package/dist/types/features/build/error.d.ts +33 -0
  76. package/dist/types/features/build/index.d.ts +12 -3
  77. package/dist/types/features/build/legacy-constants.d.ts +8 -0
  78. package/dist/types/features/build/logger/loggerManager.d.ts +2 -0
  79. package/dist/types/features/build/normalize.d.ts +19 -0
  80. package/dist/types/features/build/types.d.ts +15 -0
  81. package/dist/types/features/build/utils.d.ts +10 -31
  82. package/dist/types/index.d.ts +1 -0
  83. package/dist/types/locale/en.d.ts +2 -0
  84. package/dist/types/locale/index.d.ts +4 -0
  85. package/dist/types/locale/zh.d.ts +2 -0
  86. package/dist/types/schema/build-config.d.ts +197 -0
  87. package/dist/types/schema/index.d.ts +184 -18
  88. package/dist/types/schema/output.d.ts +188 -10
  89. package/dist/types/schema/source.d.ts +2 -11
  90. package/dist/types/schema/tools.d.ts +6 -0
  91. package/dist/types/schema/types.d.ts +46 -0
  92. package/dist/types/types.d.ts +29 -28
  93. package/dist/types/utils/babel.d.ts +3 -2
  94. package/dist/types/utils/constants.d.ts +2 -0
  95. package/dist/types/utils/logger.d.ts +2 -0
  96. package/package.json +28 -13
  97. package/dist/js/modern/features/build/build-watch.js +0 -101
  98. package/dist/js/modern/features/build/build.js +0 -123
  99. package/dist/js/modern/tasks/build-source-code.js +0 -207
  100. package/dist/js/modern/tasks/build-style.js +0 -168
  101. package/dist/js/modern/tasks/build-watch-source-code.js +0 -161
  102. package/dist/js/modern/tasks/build-watch-style.js +0 -215
  103. package/dist/js/modern/tasks/constants.js +0 -1
  104. package/dist/js/node/features/build/build-watch.js +0 -121
  105. package/dist/js/node/features/build/build.js +0 -143
  106. package/dist/js/node/tasks/build-source-code.js +0 -233
  107. package/dist/js/node/tasks/build-style.js +0 -183
  108. package/dist/js/node/tasks/build-watch-source-code.js +0 -173
  109. package/dist/js/node/tasks/build-watch-style.js +0 -232
  110. package/dist/js/node/tasks/constants.js +0 -8
  111. package/dist/types/features/build/build-watch.d.ts +0 -3
  112. package/dist/types/features/build/build.d.ts +0 -3
  113. package/dist/types/tasks/build-source-code.d.ts +0 -25
  114. package/dist/types/tasks/build-style.d.ts +0 -1
  115. package/dist/types/tasks/build-watch-source-code.d.ts +0 -1
  116. package/dist/types/tasks/build-watch-style.d.ts +0 -1
  117. package/dist/types/tasks/constants.d.ts +0 -1
  118. package/dist/types/tasks/copy-assets.d.ts +0 -1
  119. package/dist/types/tasks/generator-dts/index.d.ts +0 -1
@@ -3,155 +3,30 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.logTemplate = exports.getDtsMapper = exports.getCodeMapper = exports.getCodeInitMapper = exports.TimeCounter = exports.LogStack = void 0;
7
-
8
- var path = _interopRequireWildcard(require("path"));
6
+ exports.watchSectionTitle = exports.logTemplate = exports.getPostcssOption = exports.getAllDeps = exports.SectionTitleStatus = exports.LogStack = void 0;
9
7
 
10
8
  var os = _interopRequireWildcard(require("os"));
11
9
 
10
+ var _path = _interopRequireDefault(require("path"));
11
+
12
12
  var _utils = require("@modern-js/utils");
13
13
 
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
14
16
  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); }
15
17
 
16
18
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
19
 
18
20
  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; }
19
21
 
20
- const constants = _utils.Import.lazy('./constants', require); // 硬解字符串返回相应格式的对象
21
-
22
-
23
- const updateMapper = (packageFieldValue, outDir, mapper) => {
24
- if (packageFieldValue === 'CJS+ES6') {
25
- return [...mapper, {
26
- type: 'commonjs',
27
- syntax: 'es6+',
28
- outDir
29
- }];
30
- } else if (packageFieldValue === 'ESM+ES5') {
31
- return [...mapper, {
32
- type: 'module',
33
- syntax: 'es5',
34
- outDir
35
- }];
36
- } else if (packageFieldValue === 'ESM+ES6') {
37
- return [...mapper, {
38
- type: 'module',
39
- syntax: 'es6+',
40
- outDir
41
- }];
42
- } else {
43
- return [...mapper];
44
- }
45
- };
46
-
47
- const getCodeInitMapper = (api, _) => {
48
- const {
49
- output: {
50
- packageFields,
51
- packageMode
52
- }
53
- } = api.useResolvedConfigContext();
54
- let initMapper = []; // 如果不存在packageFields配置或者packageFields为空对象,则使用 packageMode
55
-
56
- if (!packageFields || typeof packageFields === 'object' && Object.keys(packageFields).length === 0) {
57
- initMapper = constants.PACKAGE_MODES[packageMode || constants.DEFAULT_PACKAGE_MODE];
58
- } else if (packageFields && Object.keys(packageFields).length > 0) {
59
- if (packageFields.modern) {
60
- initMapper = updateMapper(packageFields.modern, 'modern', initMapper);
61
- }
62
-
63
- if (packageFields.main) {
64
- initMapper = updateMapper(packageFields.main, 'node', initMapper);
65
- }
66
-
67
- if (packageFields.module) {
68
- initMapper = updateMapper(packageFields.module, 'treeshaking', initMapper);
69
- } // TODO: 如果存在其他配置,需要提示
70
-
71
-
72
- if (!packageFields.modern && !packageFields.main && !packageFields.module) {
73
- console.error(_utils.chalk.red(`Unrecognized ${JSON.stringify(packageFields)} configuration, please use keys: 'modern, main, jupiter:modern' and use values: 'CJS+ES6, ESM+ES5, ESM+ES6'`)); // eslint-disable-next-line no-process-exit
74
-
75
- process.exit(1);
76
- }
77
- }
22
+ const constants = _utils.Import.lazy('./constants', require);
78
23
 
79
- return initMapper;
80
- }; // 获取执行构建源码的参数
81
-
82
-
83
- exports.getCodeInitMapper = getCodeInitMapper;
84
-
85
- const getCodeMapper = (api, {
86
- logger,
87
- taskPath,
88
- config,
89
- initMapper,
90
- srcRootDir,
91
- willCompilerDirOrFile
92
- }) => {
93
- const {
94
- appDirectory
95
- } = api.useAppContext();
96
- const modernConfig = api.useResolvedConfigContext();
97
- const {
98
- output: {
99
- enableSourceMap,
100
- jsPath = 'js',
101
- path: distDir = 'dist'
102
- }
103
- } = modernConfig;
104
- const {
105
- tsconfigName = 'tsconfig.json'
106
- } = config;
107
- const tsconfigPath = path.join(appDirectory, tsconfigName);
108
- return initMapper.map(option => {
109
- var _option$copyDirs;
110
-
111
- // 不是output.copy配置,而是内部的js copy逻辑
112
- const copyDirs = (_option$copyDirs = option.copyDirs) === null || _option$copyDirs === void 0 ? void 0 : _option$copyDirs.map(copyDir => path.join(appDirectory, `./${distDir}/${jsPath}/${copyDir}`));
113
- return {
114
- logger,
115
- taskPath,
116
- params: [`--syntax=${option.syntax}`, `--type=${option.type}`, `--srcRootDir=${srcRootDir}`, `--willCompilerDirOrFile=${willCompilerDirOrFile}`, copyDirs ? `--copyDirs=${copyDirs.join(',')}` : '', `--distDir=${path.join(appDirectory, `./${distDir}/${jsPath}/${option.outDir}`)}`, `--appDirectory=${appDirectory}`, enableSourceMap ? '--sourceMaps' : '', `--tsconfigPath=${tsconfigPath}`]
117
- };
118
- });
119
- }; // 获取执行生成 d.ts 的参数
120
-
121
-
122
- exports.getCodeMapper = getCodeMapper;
123
-
124
- const getDtsMapper = (api, config, logger) => {
125
- const {
126
- appDirectory
127
- } = api.useAppContext();
128
- const modernConfig = api.useResolvedConfigContext();
129
- const {
130
- output: {
131
- disableTsChecker,
132
- path: outputPath = 'dist'
133
- }
134
- } = modernConfig;
135
- const {
136
- tsconfigName = 'tsconfig.json',
137
- enableWatchMode,
138
- sourceDir
139
- } = config;
140
- const srcDir = path.join(appDirectory, './src');
141
- const tsconfigPath = path.join(appDirectory, tsconfigName);
142
- return [{
143
- logger,
144
- taskPath: require.resolve("../../tasks/generator-dts"),
145
- params: [`--srcDir=${srcDir}`, `--distDir=${path.join(appDirectory, `./${outputPath}/types`)}`, `--appDirectory=${appDirectory}`, `--tsconfigPath=${tsconfigPath}`, `--sourceDirName=${sourceDir}`, enableWatchMode ? `--watch` : '', disableTsChecker ? '' : `--tsCheck`]
146
- }];
147
- };
24
+ const cssConfig = _utils.Import.lazy('@modern-js/css-config', require);
148
25
  /**
149
26
  * 处理日志信息
150
27
  */
151
28
 
152
29
 
153
- exports.getDtsMapper = getDtsMapper;
154
-
155
30
  class LogStack {
156
31
  constructor() {
157
32
  _defineProperty(this, "_codeLogStack", void 0);
@@ -203,24 +78,52 @@ const logTemplate = (title, messageStack, maxLength, {
203
78
  const template = `${title}:
204
79
  ${_contentColor(messageFragments.join(os.EOL))}${_noBottomBorder ? '' : `\n${_bottomBorderText}`}`;
205
80
  return template;
206
- }; // eslint-disable-next-line @typescript-eslint/no-extraneous-class
207
-
81
+ };
208
82
 
209
83
  exports.logTemplate = logTemplate;
210
-
211
- class TimeCounter {
212
- static time() {
213
- this._now = Date.now();
84
+ let SectionTitleStatus;
85
+ exports.SectionTitleStatus = SectionTitleStatus;
86
+
87
+ (function (SectionTitleStatus) {
88
+ SectionTitleStatus[SectionTitleStatus["Success"] = 0] = "Success";
89
+ SectionTitleStatus[SectionTitleStatus["Fail"] = 1] = "Fail";
90
+ SectionTitleStatus[SectionTitleStatus["Log"] = 2] = "Log";
91
+ })(SectionTitleStatus || (exports.SectionTitleStatus = SectionTitleStatus = {}));
92
+
93
+ const watchSectionTitle = (str, status) => {
94
+ if (status === SectionTitleStatus.Success) {
95
+ return `${_utils.chalk.bgWhite.gray.underline(str)} ${_utils.chalk.green.underline('Successful')}`;
96
+ } else if (status === SectionTitleStatus.Fail) {
97
+ return `${_utils.chalk.bgWhite.gray.underline(str)} ${_utils.chalk.red.underline('Build Failed')}`;
214
98
  }
215
99
 
216
- static timeEnd() {
217
- const span = Date.now() - this._now;
100
+ return `${_utils.chalk.bgWhite.gray.underline(str)} ${_utils.chalk.blue.underline('Log')}`;
101
+ };
102
+
103
+ exports.watchSectionTitle = watchSectionTitle;
218
104
 
219
- return span < 1000 ? `${span}ms` : `${(span / 1000).toFixed(2)}s`;
220
- }
105
+ const getPostcssOption = (appDirectory, modernConfig) => {
106
+ var _postcssOption$postcs;
221
107
 
222
- }
108
+ const postcssOption = cssConfig.getPostcssConfig(appDirectory, modernConfig, false);
109
+ return {
110
+ plugins: (postcssOption === null || postcssOption === void 0 ? void 0 : (_postcssOption$postcs = postcssOption.postcssOptions) === null || _postcssOption$postcs === void 0 ? void 0 : _postcssOption$postcs.plugins) || [],
111
+ enableSourceMap: (postcssOption === null || postcssOption === void 0 ? void 0 : postcssOption.sourceMap) || false,
112
+ options: {}
113
+ };
114
+ };
223
115
 
224
- exports.TimeCounter = TimeCounter;
116
+ exports.getPostcssOption = getPostcssOption;
117
+
118
+ const getAllDeps = appDirectory => {
119
+ try {
120
+ const json = JSON.parse(_utils.fs.readFileSync(_path.default.resolve(appDirectory, './package.json'), 'utf8')); // return json[packageJsonConfig ?? PACKAGE_JSON_CONFIG_NAME] as T | undefined;
121
+
122
+ return [...Object.keys(json.dependencies || {}), ...Object.keys(json.devDependencies || {}), ...Object.keys(json.peerDependencies || {})];
123
+ } catch (e) {
124
+ console.warn('[WARN] package.json is broken');
125
+ return [];
126
+ }
127
+ };
225
128
 
226
- _defineProperty(TimeCounter, "_now", void 0);
129
+ exports.getAllDeps = getAllDeps;
@@ -3,6 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ var _exportNames = {
7
+ defineConfig: true
8
+ };
6
9
  exports.default = void 0;
7
10
  Object.defineProperty(exports, "defineConfig", {
8
11
  enumerable: true,
@@ -17,8 +20,24 @@ var _pluginChangeset = _interopRequireDefault(require("@modern-js/plugin-changes
17
20
 
18
21
  var _pluginAnalyze = _interopRequireDefault(require("@modern-js/plugin-analyze"));
19
22
 
23
+ var _pluginJarvis = _interopRequireDefault(require("@modern-js/plugin-jarvis"));
24
+
20
25
  var _hooks = require("./hooks");
21
26
 
27
+ var _types = require("./types");
28
+
29
+ Object.keys(_types).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
32
+ if (key in exports && exports[key] === _types[key]) return;
33
+ Object.defineProperty(exports, key, {
34
+ enumerable: true,
35
+ get: function () {
36
+ return _types[key];
37
+ }
38
+ });
39
+ });
40
+
22
41
  var _core = require("@modern-js/core");
23
42
 
24
43
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -31,11 +50,13 @@ const schema = _utils.Import.lazy('./schema', require);
31
50
 
32
51
  const lang = _utils.Import.lazy('./utils/language', require);
33
52
 
53
+ const isBuildMode = process.argv.slice(2)[0] === 'build';
54
+
34
55
  var _default = () => ({
35
56
  name: '@modern-js/module-tools',
36
57
  post: ['@modern-js/plugin-analyze', '@modern-js/plugin-changeset'],
37
58
  registerHook: _hooks.hooks,
38
- usePlugins: [(0, _pluginChangeset.default)(), (0, _pluginAnalyze.default)()],
59
+ usePlugins: [(0, _pluginChangeset.default)(), ...(isBuildMode ? [] : [(0, _pluginAnalyze.default)()]), (0, _pluginJarvis.default)()],
39
60
  setup: api => {
40
61
  const locale = lang.getLocaleLanguage();
41
62
  local.i18n.changeLanguage({
@@ -11,9 +11,11 @@ const EN_LOCALE = {
11
11
  watch: 'building module in watch mode',
12
12
  tsconfig: 'Specify a path to the tsconfig.json file',
13
13
  style_only: 'only build style',
14
- platform: 'building for other platforms',
15
- no_tsc: 'close tsc compiler to emit d.ts',
16
- no_clear: 'disable auto clear dist dir'
14
+ platform: 'build the specified task or all tasks, If exist. (tasks: "storybook", "docs")',
15
+ no_tsc: 'close tsc compiler to emit d.ts (Deprecated)',
16
+ dts: 'Turn on dts generation and type checking',
17
+ no_clear: 'disable auto clear dist dir',
18
+ config: 'specify config file'
17
19
  },
18
20
  dev: {
19
21
  describe: 'start dev server'
@@ -11,9 +11,11 @@ const ZH_LOCALE = {
11
11
  watch: '使用 Watch 模式构建模块',
12
12
  tsconfig: '指定 tsconfig.json 文件的路径',
13
13
  style_only: '只构建样式文件',
14
- platform: '构建其他平台产物',
15
- no_tsc: '关闭 tsc 编译',
16
- no_clear: '不清理产物目录'
14
+ platform: '如果存在的话,执行指定的构建任务或者全部构建任务. (构建任务包括: "storybook", "文档")',
15
+ no_tsc: '关闭 tsc 编译(废弃)',
16
+ dts: '开启 dts 文件的生成以及类型检查',
17
+ no_clear: '不清理产物目录',
18
+ config: '指定配置文件路径,可以为相对路径或绝对路径'
17
19
  },
18
20
  dev: {
19
21
  describe: '本地开发命令'
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.targets = exports.presets = exports.buildSchema = void 0;
7
+ 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.
8
+ 'esnext'];
9
+ exports.targets = targets;
10
+ 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) => {
11
+ return [...ret, ...targets.map(t => `${crt}-${t}`)];
12
+ }, [])];
13
+ exports.presets = presets;
14
+ const properties = {
15
+ target: {
16
+ enum: targets
17
+ },
18
+ format: {
19
+ enum: ['cjs', 'esm', 'umd']
20
+ },
21
+ sourceMap: {
22
+ enum: [true, false, 'inline', 'external']
23
+ },
24
+ buildType: {
25
+ enum: ['bundle', 'bundleless']
26
+ },
27
+ bundleOptions: {
28
+ type: 'object',
29
+ properties: {
30
+ entry: {
31
+ type: 'object'
32
+ },
33
+ splitting: {
34
+ type: 'boolean'
35
+ },
36
+ externals: {
37
+ type: 'array',
38
+ items: {
39
+ anyOf: [{
40
+ instanceof: 'RegExp'
41
+ }, {
42
+ typeof: 'string'
43
+ }]
44
+ }
45
+ },
46
+ platform: {
47
+ enum: ['node', 'browser']
48
+ },
49
+ minify: {
50
+ enum: ['esbuild', 'terser', false]
51
+ },
52
+ skipDeps: {
53
+ type: 'boolean'
54
+ }
55
+ }
56
+ },
57
+ bundlelessOptions: {
58
+ type: 'object',
59
+ properties: {
60
+ sourceDir: {
61
+ type: 'string'
62
+ },
63
+ style: {
64
+ type: 'object',
65
+ properties: {
66
+ compileMode: {
67
+ enum: ['all', 'only-compiled-code', 'only-source-code', false]
68
+ },
69
+ path: {
70
+ type: 'string'
71
+ }
72
+ }
73
+ },
74
+ static: {
75
+ type: 'object',
76
+ properties: {
77
+ path: {
78
+ type: 'string'
79
+ }
80
+ }
81
+ }
82
+ }
83
+ },
84
+ tsconfig: {
85
+ type: 'string'
86
+ },
87
+ enableDts: {
88
+ type: 'boolean'
89
+ },
90
+ dtsOnly: {
91
+ type: 'boolean'
92
+ },
93
+ outputPath: {
94
+ type: 'string'
95
+ }
96
+ };
97
+ const buildSchema = [{
98
+ target: 'output.buildConfig',
99
+ schema: {
100
+ if: {
101
+ type: 'array'
102
+ },
103
+ then: {
104
+ items: [{
105
+ type: 'object',
106
+ properties
107
+ }]
108
+ },
109
+ else: {
110
+ type: 'object',
111
+ properties
112
+ }
113
+ }
114
+ }, {
115
+ target: 'output.buildPreset',
116
+ schema: {
117
+ enum: presets
118
+ }
119
+ }];
120
+ exports.buildSchema = buildSchema;
@@ -9,6 +9,8 @@ var _source = require("./source");
9
9
 
10
10
  var _output = require("./output");
11
11
 
12
- const addSchema = () => [..._source.sourceSchema, ..._output.outputSchema];
12
+ var _tools = require("./tools");
13
+
14
+ const addSchema = () => [..._source.sourceSchema, ..._output.outputSchema, ..._tools.toolsSchema];
13
15
 
14
16
  exports.addSchema = addSchema;
@@ -4,34 +4,45 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.outputSchema = void 0;
7
+
8
+ var _buildConfig = require("./build-config");
9
+
7
10
  const PACKAGE_MODE_LIST = ['universal-js', 'universal-js-lite', 'browser-js', 'browser-js-lite', 'node-js'];
8
- const outputSchema = [{
11
+ const outputSchema = [
12
+ /** packageMode will deprecated */
13
+ {
9
14
  target: 'output.packageMode',
10
15
  schema: {
11
16
  enum: PACKAGE_MODE_LIST
12
17
  }
13
- }, {
18
+ },
19
+ /** packageFields will deprecated */
20
+ {
14
21
  target: 'output.packageFields',
15
22
  schema: {
16
23
  typeof: 'object'
17
24
  }
18
- }, {
25
+ },
26
+ /** enableSourceMap will deprecated */
27
+ {
19
28
  target: 'output.enableSourceMap',
20
29
  schema: {
21
30
  typeof: 'boolean'
22
31
  }
23
- }, {
32
+ },
33
+ /** importStyle will deprecated */
34
+ {
24
35
  target: 'output.importStyle',
25
36
  schema: {
26
- enum: ['compiled-code', 'source-code'],
27
- // TODO: 目前default是无效的
28
- default: 'source-code'
37
+ enum: ['compiled-code', 'source-code']
29
38
  }
30
- }, {
39
+ },
40
+ /** assetsPath will deprecated */
41
+ {
31
42
  target: 'output.assetsPath',
32
43
  schema: {
33
44
  typeof: 'string',
34
45
  default: 'styles'
35
46
  }
36
- }];
47
+ }, ..._buildConfig.buildSchema];
37
48
  exports.outputSchema = outputSchema;
@@ -4,19 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.sourceSchema = void 0;
7
- const sourceSchema = [// 启动区块运行时
8
- {
9
- target: 'source.enableBlockRuntime',
10
- schema: {
11
- type: 'boolean'
12
- }
13
- }, {
7
+ const sourceSchema = [{
14
8
  target: 'source.jsxTransformRuntime',
15
9
  schema: {
16
10
  // https://babeljs.io/docs/en/babel-preset-react#runtime
17
- enum: ['classic', 'automatic'],
18
- // TODO: 目前default是无效的
19
- default: 'automatic'
11
+ enum: ['classic', 'automatic']
20
12
  }
21
13
  }];
22
14
  exports.sourceSchema = sourceSchema;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.toolsSchema = void 0;
7
+ const toolsSchema = [{
8
+ target: 'tools.speedy',
9
+ schema: {
10
+ typeof: ['object', 'function']
11
+ }
12
+ }];
13
+ exports.toolsSchema = toolsSchema;
File without changes
@@ -37,7 +37,7 @@ const getFinalAlias = (modernConfig, option) => {
37
37
 
38
38
  exports.getFinalAlias = getFinalAlias;
39
39
 
40
- const resolveBabelConfig = (appDirectory, modernConfig, option) => {
40
+ const resolveBabelConfig = (appDirectory, modernConfig, sourceMap, bundlelessOptions, option) => {
41
41
  const {
42
42
  source: {
43
43
  envVars,
@@ -72,6 +72,8 @@ const resolveBabelConfig = (appDirectory, modernConfig, option) => {
72
72
  lodashOptions,
73
73
  jsxTransformRuntime,
74
74
  importStyle,
75
+ styleDir: bundlelessOptions.style.path,
76
+ staticDir: bundlelessOptions.static.path,
75
77
  styledComponentsOptions: (0, _utils.applyOptionsChain)({
76
78
  pure: true,
77
79
  displayName: true,
@@ -84,6 +86,7 @@ const resolveBabelConfig = (appDirectory, modernConfig, option) => {
84
86
  }); // Preventing warning when files are too large
85
87
 
86
88
  internalBabelConfig.compact = false;
89
+ internalBabelConfig.sourceMaps = sourceMap === 'external' ? true : sourceMap;
87
90
  const userBabelConfig = modernConfig.tools.babel;
88
91
  return (0, _babelPresetModule.applyUserBabelConfig)(internalBabelConfig, userBabelConfig);
89
92
  };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.tempTsconfigName = exports.cliTsConfigDefaultValue = void 0;
7
+ // generator tsconfig file
8
+ const tempTsconfigName = 'tsconfig.temp.json';
9
+ exports.tempTsconfigName = tempTsconfigName;
10
+ const cliTsConfigDefaultValue = './tsconfig.json';
11
+ exports.cliTsConfigDefaultValue = cliTsConfigDefaultValue;
@@ -71,7 +71,7 @@ const copyTask = async option => {
71
71
 
72
72
  glob = path.isAbsolute(fromOrigin) ? fromOrigin : path.posix.join(_utils.fastGlob.escapePath(normalizePath(path.resolve(context))), fromOrigin); // 计算 glob,获取目标文件
73
73
 
74
- const paths = await (0, _utils.globby)(glob, options);
74
+ const paths = await (0, _utils.globby)((0, _utils.slash)(glob), options);
75
75
 
76
76
  if (!paths.length) {
77
77
  return;
@@ -1,3 +1,3 @@
1
1
  import { Command } from '@modern-js/utils';
2
2
  import type { PluginAPI } from '@modern-js/core';
3
- export declare const buildCli: (program: Command, api: PluginAPI) => void;
3
+ export declare const buildCli: (program: Command, api: PluginAPI) => Command;
@@ -1,2 +1,2 @@
1
1
  import { Command } from '@modern-js/utils';
2
- export declare const newCli: (program: Command, locale?: string | undefined) => void;
2
+ export declare const newCli: (program: Command, locale?: string) => void;
@@ -1,18 +1,18 @@
1
1
  import type { PluginAPI } from '@modern-js/core';
2
2
  import type { Platform } from '../types';
3
- export interface IBuildOption {
4
- watch: boolean;
3
+ /**
4
+ * init work before build task.
5
+ * @param api
6
+ */
7
+
8
+ export declare const init: (api: PluginAPI) => void;
9
+ export interface IBuildCommandOption {
10
+ watch?: boolean;
5
11
  tsconfig: string;
6
- platform: boolean | Exclude<Platform, 'all'>;
7
- styleOnly: boolean;
12
+ platform?: boolean | Exclude<Platform, 'all'>;
13
+ styleOnly?: boolean;
8
14
  tsc: boolean;
15
+ dts?: boolean;
9
16
  clear: boolean;
10
17
  }
11
- export declare const build: (api: PluginAPI, {
12
- watch,
13
- tsconfig: tsconfigName,
14
- tsc,
15
- clear,
16
- platform,
17
- styleOnly
18
- }: IBuildOption) => Promise<void>;
18
+ export declare const build: (api: PluginAPI, buildCommandOption: IBuildCommandOption) => Promise<void>;
@@ -0,0 +1,3 @@
1
+ import type { PluginAPI } from '@modern-js/core';
2
+ import type { NormalizedBundleBuildConfig } from '../types';
3
+ export declare const build: (api: PluginAPI, config: NormalizedBundleBuildConfig) => Promise<void>;
@@ -0,0 +1,3 @@
1
+ import type { PluginAPI } from '@modern-js/core';
2
+ import type { NormalizedBundleBuildConfig } from '../types';
3
+ export declare const startRollup: (api: PluginAPI, options: NormalizedBundleBuildConfig) => Promise<void>;
@@ -0,0 +1,10 @@
1
+ import type { PluginAPI } from '@modern-js/core';
2
+ import type { NormalizedBundleBuildConfig } from '../types';
3
+ export declare type ResolveAlias = {
4
+ [index: string]: string;
5
+ };
6
+ export declare const getAlias: (api: PluginAPI) => {};
7
+ export declare const getDefine: (api: PluginAPI) => {
8
+ [x: string]: string;
9
+ };
10
+ export declare const runSpeedy: (api: PluginAPI, config: NormalizedBundleBuildConfig) => Promise<void>;
@@ -0,0 +1,3 @@
1
+ import type { PluginAPI } from '@modern-js/core';
2
+ import { NormalizedBundlelessBuildConfig } from '../types';
3
+ export declare const copyStaticAssets: (api: PluginAPI, config: NormalizedBundlelessBuildConfig) => Promise<void>;
@@ -0,0 +1,3 @@
1
+ import type { PluginAPI } from '@modern-js/core';
2
+ import type { NormalizedBundlelessBuildConfig } from '../../types';
3
+ export declare const genDts: (api: PluginAPI, config: NormalizedBundlelessBuildConfig) => Promise<void>;