@modern-js/module-tools 1.5.8 → 1.6.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.
- package/CHANGELOG.md +41 -0
- package/dist/js/modern/cli/build.js +5 -4
- package/dist/js/modern/commands/build.js +55 -28
- package/dist/js/modern/features/build/bundle/index.js +9 -0
- package/dist/js/modern/features/build/bundle/runRollup.js +149 -0
- package/dist/js/modern/features/build/bundle/runSpeedy.js +185 -0
- package/dist/js/modern/{tasks → features/build/bundleless}/copy-assets.js +31 -56
- package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/index.js +46 -71
- package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/utils.js +10 -10
- package/dist/js/modern/features/build/bundleless/index.js +23 -0
- package/dist/js/modern/features/build/bundleless/runBabel.js +269 -0
- package/dist/js/modern/features/build/bundleless/style.js +266 -0
- package/dist/js/modern/features/build/constants.js +94 -59
- package/dist/js/modern/features/build/error.js +150 -0
- package/dist/js/modern/features/build/index.js +87 -18
- package/dist/js/modern/features/build/legacy-constants.js +99 -0
- package/dist/js/modern/features/build/normalize.js +301 -0
- package/dist/js/modern/features/build/types.js +0 -0
- package/dist/js/modern/features/build/utils.js +39 -136
- package/dist/js/modern/index.js +3 -1
- package/dist/js/modern/locale/en.js +5 -3
- package/dist/js/modern/locale/zh.js +5 -3
- package/dist/js/modern/schema/build-config.js +111 -0
- package/dist/js/modern/schema/index.js +2 -1
- package/dist/js/modern/schema/output.js +18 -9
- package/dist/js/modern/schema/source.js +2 -10
- package/dist/js/modern/schema/tools.js +6 -0
- package/dist/js/modern/schema/types.js +0 -0
- package/dist/js/modern/utils/babel.js +4 -1
- package/dist/js/modern/utils/constants.js +3 -0
- package/dist/js/modern/utils/copy.js +2 -2
- package/dist/js/node/cli/build.js +5 -4
- package/dist/js/node/commands/build.js +62 -29
- package/dist/js/node/features/build/bundle/index.js +23 -0
- package/dist/js/node/features/build/bundle/runRollup.js +174 -0
- package/dist/js/node/features/build/bundle/runSpeedy.js +209 -0
- package/dist/js/node/{tasks → features/build/bundleless}/copy-assets.js +37 -56
- package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/index.js +58 -73
- package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/utils.js +9 -10
- package/dist/js/node/features/build/bundleless/index.js +40 -0
- package/dist/js/node/features/build/bundleless/runBabel.js +309 -0
- package/dist/js/node/features/build/bundleless/style.js +299 -0
- package/dist/js/node/features/build/constants.js +115 -67
- package/dist/js/node/features/build/error.js +175 -0
- package/dist/js/node/features/build/index.js +104 -18
- package/dist/js/node/features/build/legacy-constants.js +107 -0
- package/dist/js/node/features/build/normalize.js +330 -0
- package/dist/js/node/features/build/types.js +0 -0
- package/dist/js/node/features/build/utils.js +48 -145
- package/dist/js/node/index.js +20 -1
- package/dist/js/node/locale/en.js +5 -3
- package/dist/js/node/locale/zh.js +5 -3
- package/dist/js/node/schema/build-config.js +120 -0
- package/dist/js/node/schema/index.js +3 -1
- package/dist/js/node/schema/output.js +20 -9
- package/dist/js/node/schema/source.js +2 -10
- package/dist/js/node/schema/tools.js +13 -0
- package/dist/js/node/schema/types.js +0 -0
- package/dist/js/node/utils/babel.js +4 -1
- package/dist/js/node/utils/constants.js +11 -0
- package/dist/js/node/utils/copy.js +1 -1
- package/dist/types/cli/build.d.ts +1 -1
- package/dist/types/commands/build.d.ts +12 -12
- package/dist/types/features/build/bundle/index.d.ts +3 -0
- package/dist/types/features/build/bundle/runRollup.d.ts +3 -0
- package/dist/types/features/build/bundle/runSpeedy.d.ts +10 -0
- package/dist/types/features/build/bundleless/copy-assets.d.ts +3 -0
- package/dist/types/features/build/bundleless/generator-dts/index.d.ts +3 -0
- package/dist/types/{tasks → features/build/bundleless}/generator-dts/utils.d.ts +3 -6
- package/dist/types/features/build/bundleless/index.d.ts +4 -0
- package/dist/types/features/build/bundleless/runBabel.d.ts +32 -0
- package/dist/types/features/build/bundleless/style.d.ts +25 -0
- package/dist/types/features/build/constants.d.ts +17 -13
- package/dist/types/features/build/error.d.ts +33 -0
- package/dist/types/features/build/index.d.ts +12 -3
- package/dist/types/features/build/legacy-constants.d.ts +8 -0
- package/dist/types/features/build/normalize.d.ts +19 -0
- package/dist/types/features/build/types.d.ts +15 -0
- package/dist/types/features/build/utils.d.ts +10 -31
- package/dist/types/index.d.ts +1 -0
- package/dist/types/locale/en.d.ts +2 -0
- package/dist/types/locale/index.d.ts +4 -0
- package/dist/types/locale/zh.d.ts +2 -0
- package/dist/types/schema/build-config.d.ts +197 -0
- package/dist/types/schema/index.d.ts +184 -18
- package/dist/types/schema/output.d.ts +188 -10
- package/dist/types/schema/source.d.ts +2 -11
- package/dist/types/schema/tools.d.ts +6 -0
- package/dist/types/schema/types.d.ts +46 -0
- package/dist/types/types.d.ts +29 -28
- package/dist/types/utils/babel.d.ts +3 -2
- package/dist/types/utils/constants.d.ts +2 -0
- package/package.json +23 -9
- package/dist/js/modern/features/build/build-watch.js +0 -101
- package/dist/js/modern/features/build/build.js +0 -123
- package/dist/js/modern/tasks/build-source-code.js +0 -208
- package/dist/js/modern/tasks/build-style.js +0 -169
- package/dist/js/modern/tasks/build-watch-source-code.js +0 -162
- package/dist/js/modern/tasks/build-watch-style.js +0 -216
- package/dist/js/modern/tasks/constants.js +0 -1
- package/dist/js/node/features/build/build-watch.js +0 -121
- package/dist/js/node/features/build/build.js +0 -143
- package/dist/js/node/tasks/build-source-code.js +0 -234
- package/dist/js/node/tasks/build-style.js +0 -184
- package/dist/js/node/tasks/build-watch-source-code.js +0 -174
- package/dist/js/node/tasks/build-watch-style.js +0 -233
- package/dist/js/node/tasks/constants.js +0 -8
- package/dist/types/features/build/build-watch.d.ts +0 -3
- package/dist/types/features/build/build.d.ts +0 -3
- package/dist/types/tasks/build-source-code.d.ts +0 -25
- package/dist/types/tasks/build-style.d.ts +0 -1
- package/dist/types/tasks/build-watch-source-code.d.ts +0 -1
- package/dist/types/tasks/build-watch-style.d.ts +0 -1
- package/dist/types/tasks/constants.d.ts +0 -1
- package/dist/types/tasks/copy-assets.d.ts +0 -1
- package/dist/types/tasks/generator-dts/index.d.ts +0 -1
|
@@ -1,129 +1,10 @@
|
|
|
1
1
|
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; }
|
|
2
2
|
|
|
3
|
-
import * as path from 'path';
|
|
4
3
|
import * as os from 'os';
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
if (packageFieldValue === 'CJS+ES6') {
|
|
10
|
-
return [...mapper, {
|
|
11
|
-
type: 'commonjs',
|
|
12
|
-
syntax: 'es6+',
|
|
13
|
-
outDir
|
|
14
|
-
}];
|
|
15
|
-
} else if (packageFieldValue === 'ESM+ES5') {
|
|
16
|
-
return [...mapper, {
|
|
17
|
-
type: 'module',
|
|
18
|
-
syntax: 'es5',
|
|
19
|
-
outDir
|
|
20
|
-
}];
|
|
21
|
-
} else if (packageFieldValue === 'ESM+ES6') {
|
|
22
|
-
return [...mapper, {
|
|
23
|
-
type: 'module',
|
|
24
|
-
syntax: 'es6+',
|
|
25
|
-
outDir
|
|
26
|
-
}];
|
|
27
|
-
} else {
|
|
28
|
-
return [...mapper];
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const getCodeInitMapper = (api, _) => {
|
|
33
|
-
const {
|
|
34
|
-
output: {
|
|
35
|
-
packageFields,
|
|
36
|
-
packageMode
|
|
37
|
-
}
|
|
38
|
-
} = api.useResolvedConfigContext();
|
|
39
|
-
let initMapper = []; // 如果不存在packageFields配置或者packageFields为空对象,则使用 packageMode
|
|
40
|
-
|
|
41
|
-
if (!packageFields || typeof packageFields === 'object' && Object.keys(packageFields).length === 0) {
|
|
42
|
-
initMapper = constants.PACKAGE_MODES[packageMode || constants.DEFAULT_PACKAGE_MODE];
|
|
43
|
-
} else if (packageFields && Object.keys(packageFields).length > 0) {
|
|
44
|
-
if (packageFields.modern) {
|
|
45
|
-
initMapper = updateMapper(packageFields.modern, 'modern', initMapper);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (packageFields.main) {
|
|
49
|
-
initMapper = updateMapper(packageFields.main, 'node', initMapper);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (packageFields.module) {
|
|
53
|
-
initMapper = updateMapper(packageFields.module, 'treeshaking', initMapper);
|
|
54
|
-
} // TODO: 如果存在其他配置,需要提示
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (!packageFields.modern && !packageFields.main && !packageFields.module) {
|
|
58
|
-
console.error(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
|
|
59
|
-
|
|
60
|
-
process.exit(1);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return initMapper;
|
|
65
|
-
}; // 获取执行构建源码的参数
|
|
66
|
-
|
|
67
|
-
export const getCodeMapper = (api, {
|
|
68
|
-
logger,
|
|
69
|
-
taskPath,
|
|
70
|
-
config,
|
|
71
|
-
initMapper,
|
|
72
|
-
srcRootDir,
|
|
73
|
-
willCompilerDirOrFile
|
|
74
|
-
}) => {
|
|
75
|
-
const {
|
|
76
|
-
appDirectory
|
|
77
|
-
} = api.useAppContext();
|
|
78
|
-
const modernConfig = api.useResolvedConfigContext();
|
|
79
|
-
const {
|
|
80
|
-
output: {
|
|
81
|
-
enableSourceMap,
|
|
82
|
-
jsPath = 'js',
|
|
83
|
-
path: distDir = 'dist'
|
|
84
|
-
}
|
|
85
|
-
} = modernConfig;
|
|
86
|
-
const {
|
|
87
|
-
tsconfigName = 'tsconfig.json'
|
|
88
|
-
} = config;
|
|
89
|
-
const tsconfigPath = path.join(appDirectory, tsconfigName);
|
|
90
|
-
return initMapper.map(option => {
|
|
91
|
-
var _option$copyDirs;
|
|
92
|
-
|
|
93
|
-
// 不是output.copy配置,而是内部的js copy逻辑
|
|
94
|
-
const copyDirs = (_option$copyDirs = option.copyDirs) === null || _option$copyDirs === void 0 ? void 0 : _option$copyDirs.map(copyDir => path.join(appDirectory, `./${distDir}/${jsPath}/${copyDir}`));
|
|
95
|
-
return {
|
|
96
|
-
logger,
|
|
97
|
-
taskPath,
|
|
98
|
-
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}`]
|
|
99
|
-
};
|
|
100
|
-
});
|
|
101
|
-
}; // 获取执行生成 d.ts 的参数
|
|
102
|
-
|
|
103
|
-
export const getDtsMapper = (api, config, logger) => {
|
|
104
|
-
const {
|
|
105
|
-
appDirectory
|
|
106
|
-
} = api.useAppContext();
|
|
107
|
-
const modernConfig = api.useResolvedConfigContext();
|
|
108
|
-
const {
|
|
109
|
-
output: {
|
|
110
|
-
disableTsChecker,
|
|
111
|
-
path: outputPath = 'dist'
|
|
112
|
-
}
|
|
113
|
-
} = modernConfig;
|
|
114
|
-
const {
|
|
115
|
-
tsconfigName = 'tsconfig.json',
|
|
116
|
-
enableWatchMode,
|
|
117
|
-
sourceDir
|
|
118
|
-
} = config;
|
|
119
|
-
const srcDir = path.join(appDirectory, './src');
|
|
120
|
-
const tsconfigPath = path.join(appDirectory, tsconfigName);
|
|
121
|
-
return [{
|
|
122
|
-
logger,
|
|
123
|
-
taskPath: require.resolve("../../tasks/generator-dts"),
|
|
124
|
-
params: [`--srcDir=${srcDir}`, `--distDir=${path.join(appDirectory, `./${outputPath}/types`)}`, `--appDirectory=${appDirectory}`, `--tsconfigPath=${tsconfigPath}`, `--sourceDirName=${sourceDir}`, enableWatchMode ? `--watch` : '', disableTsChecker ? '' : `--tsCheck`]
|
|
125
|
-
}];
|
|
126
|
-
};
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { chalk, Import, fs } from '@modern-js/utils';
|
|
6
|
+
const constants = Import.lazy('./constants', require);
|
|
7
|
+
const cssConfig = Import.lazy('@modern-js/css-config', require);
|
|
127
8
|
/**
|
|
128
9
|
* 处理日志信息
|
|
129
10
|
*/
|
|
@@ -176,19 +57,41 @@ export const logTemplate = (title, messageStack, maxLength, {
|
|
|
176
57
|
const template = `${title}:
|
|
177
58
|
${_contentColor(messageFragments.join(os.EOL))}${_noBottomBorder ? '' : `\n${_bottomBorderText}`}`;
|
|
178
59
|
return template;
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
60
|
+
};
|
|
61
|
+
export let SectionTitleStatus;
|
|
62
|
+
|
|
63
|
+
(function (SectionTitleStatus) {
|
|
64
|
+
SectionTitleStatus[SectionTitleStatus["Success"] = 0] = "Success";
|
|
65
|
+
SectionTitleStatus[SectionTitleStatus["Fail"] = 1] = "Fail";
|
|
66
|
+
SectionTitleStatus[SectionTitleStatus["Log"] = 2] = "Log";
|
|
67
|
+
})(SectionTitleStatus || (SectionTitleStatus = {}));
|
|
68
|
+
|
|
69
|
+
export const watchSectionTitle = (str, status) => {
|
|
70
|
+
if (status === SectionTitleStatus.Success) {
|
|
71
|
+
return `${chalk.bgWhite.gray.underline(str)} ${chalk.green.underline('Successful')}`;
|
|
72
|
+
} else if (status === SectionTitleStatus.Fail) {
|
|
73
|
+
return `${chalk.bgWhite.gray.underline(str)} ${chalk.red.underline('Build Failed')}`;
|
|
184
74
|
}
|
|
185
75
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
76
|
+
return `${chalk.bgWhite.gray.underline(str)} ${chalk.blue.underline('Log')}`;
|
|
77
|
+
};
|
|
78
|
+
export const getPostcssOption = (appDirectory, modernConfig) => {
|
|
79
|
+
var _postcssOption$postcs;
|
|
80
|
+
|
|
81
|
+
const postcssOption = cssConfig.getPostcssConfig(appDirectory, modernConfig, false);
|
|
82
|
+
return {
|
|
83
|
+
plugins: (postcssOption === null || postcssOption === void 0 ? void 0 : (_postcssOption$postcs = postcssOption.postcssOptions) === null || _postcssOption$postcs === void 0 ? void 0 : _postcssOption$postcs.plugins) || [],
|
|
84
|
+
enableSourceMap: (postcssOption === null || postcssOption === void 0 ? void 0 : postcssOption.sourceMap) || false,
|
|
85
|
+
options: {}
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
export const getAllDeps = appDirectory => {
|
|
89
|
+
try {
|
|
90
|
+
const json = JSON.parse(fs.readFileSync(path.resolve(appDirectory, './package.json'), 'utf8')); // return json[packageJsonConfig ?? PACKAGE_JSON_CONFIG_NAME] as T | undefined;
|
|
91
|
+
|
|
92
|
+
return [...Object.keys(json.dependencies || {}), ...Object.keys(json.devDependencies || {}), ...Object.keys(json.peerDependencies || {})];
|
|
93
|
+
} catch (e) {
|
|
94
|
+
console.warn('[WARN] package.json is broken');
|
|
95
|
+
return [];
|
|
190
96
|
}
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
_defineProperty(TimeCounter, "_now", void 0);
|
|
97
|
+
};
|
package/dist/js/modern/index.js
CHANGED
|
@@ -3,16 +3,18 @@ import ChangesetPlugin from '@modern-js/plugin-changeset';
|
|
|
3
3
|
import AnalyzePlugin from '@modern-js/plugin-analyze';
|
|
4
4
|
import LintPlugin from '@modern-js/plugin-jarvis';
|
|
5
5
|
import { hooks } from "./hooks";
|
|
6
|
+
export * from "./types";
|
|
6
7
|
const cli = Import.lazy('./cli', require);
|
|
7
8
|
const local = Import.lazy('./locale', require);
|
|
8
9
|
const schema = Import.lazy('./schema', require);
|
|
9
10
|
const lang = Import.lazy('./utils/language', require);
|
|
10
11
|
export { defineConfig } from '@modern-js/core';
|
|
12
|
+
const isBuildMode = process.argv.slice(2)[0] === 'build';
|
|
11
13
|
export default (() => ({
|
|
12
14
|
name: '@modern-js/module-tools',
|
|
13
15
|
post: ['@modern-js/plugin-analyze', '@modern-js/plugin-changeset'],
|
|
14
16
|
registerHook: hooks,
|
|
15
|
-
usePlugins: [ChangesetPlugin(), AnalyzePlugin(), LintPlugin()],
|
|
17
|
+
usePlugins: [ChangesetPlugin(), ...(isBuildMode ? [] : [AnalyzePlugin()]), LintPlugin()],
|
|
16
18
|
setup: api => {
|
|
17
19
|
const locale = lang.getLocaleLanguage();
|
|
18
20
|
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: '
|
|
9
|
-
no_tsc: 'close tsc compiler to emit d.ts',
|
|
10
|
-
|
|
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
|
-
|
|
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,111 @@
|
|
|
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
|
+
anyOf: [{
|
|
32
|
+
instanceof: 'RegExp'
|
|
33
|
+
}, {
|
|
34
|
+
typeof: 'string'
|
|
35
|
+
}]
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
platform: {
|
|
39
|
+
enum: ['node', 'browser']
|
|
40
|
+
},
|
|
41
|
+
minify: {
|
|
42
|
+
enum: ['esbuild', 'terser', false]
|
|
43
|
+
},
|
|
44
|
+
skipDeps: {
|
|
45
|
+
type: 'boolean'
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
bundlelessOptions: {
|
|
50
|
+
type: 'object',
|
|
51
|
+
properties: {
|
|
52
|
+
sourceDir: {
|
|
53
|
+
type: 'string'
|
|
54
|
+
},
|
|
55
|
+
style: {
|
|
56
|
+
type: 'object',
|
|
57
|
+
properties: {
|
|
58
|
+
compileMode: {
|
|
59
|
+
enum: ['all', 'only-compiled-code', 'only-source-code', false]
|
|
60
|
+
},
|
|
61
|
+
path: {
|
|
62
|
+
type: 'string'
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
static: {
|
|
67
|
+
type: 'object',
|
|
68
|
+
properties: {
|
|
69
|
+
path: {
|
|
70
|
+
type: 'string'
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
tsconfig: {
|
|
77
|
+
type: 'string'
|
|
78
|
+
},
|
|
79
|
+
enableDts: {
|
|
80
|
+
type: 'boolean'
|
|
81
|
+
},
|
|
82
|
+
dtsOnly: {
|
|
83
|
+
type: 'boolean'
|
|
84
|
+
},
|
|
85
|
+
outputPath: {
|
|
86
|
+
type: 'string'
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
export const buildSchema = [{
|
|
90
|
+
target: 'output.buildConfig',
|
|
91
|
+
schema: {
|
|
92
|
+
if: {
|
|
93
|
+
type: 'array'
|
|
94
|
+
},
|
|
95
|
+
then: {
|
|
96
|
+
items: [{
|
|
97
|
+
type: 'object',
|
|
98
|
+
properties
|
|
99
|
+
}]
|
|
100
|
+
},
|
|
101
|
+
else: {
|
|
102
|
+
type: 'object',
|
|
103
|
+
properties
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}, {
|
|
107
|
+
target: 'output.buildPreset',
|
|
108
|
+
schema: {
|
|
109
|
+
enum: presets
|
|
110
|
+
}
|
|
111
|
+
}];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { sourceSchema } from "./source";
|
|
2
2
|
import { outputSchema } from "./output";
|
|
3
|
-
|
|
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
|
}];
|
|
File without changes
|
|
@@ -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
79
|
return applyUserBabelConfig(internalBabelConfig, userBabelConfig);
|
|
77
80
|
};
|
|
@@ -5,7 +5,7 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
|
5
5
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
6
6
|
|
|
7
7
|
import * as path from 'path';
|
|
8
|
-
import { fs, Import, globby, fastGlob } from '@modern-js/utils';
|
|
8
|
+
import { fs, Import, globby, fastGlob, slash } from '@modern-js/utils';
|
|
9
9
|
const normalizePath = Import.lazy('normalize-path', require);
|
|
10
10
|
export const copyTask = async option => {
|
|
11
11
|
const {
|
|
@@ -57,7 +57,7 @@ export const copyTask = async option => {
|
|
|
57
57
|
|
|
58
58
|
glob = path.isAbsolute(fromOrigin) ? fromOrigin : path.posix.join(fastGlob.escapePath(normalizePath(path.resolve(context))), fromOrigin); // 计算 glob,获取目标文件
|
|
59
59
|
|
|
60
|
-
const paths = await globby(glob, options);
|
|
60
|
+
const paths = await globby(slash(glob), options);
|
|
61
61
|
|
|
62
62
|
if (!paths.length) {
|
|
63
63
|
return;
|
|
@@ -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
|
|
12
|
+
const command = _utils.Import.lazy('../commands/build', require);
|
|
13
13
|
|
|
14
14
|
const buildCli = (program, api) => {
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
|
|
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,16 @@
|
|
|
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
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
12
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); }
|
|
13
17
|
|
|
14
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; }
|
|
@@ -18,48 +22,77 @@ const tsConfigutils = _utils.Import.lazy('../utils/tsconfig', require);
|
|
|
18
22
|
const valid = _utils.Import.lazy('../utils/valide', require);
|
|
19
23
|
|
|
20
24
|
const buildFeature = _utils.Import.lazy('../features/build', require);
|
|
25
|
+
/**
|
|
26
|
+
* init work before build task.
|
|
27
|
+
* @param api
|
|
28
|
+
*/
|
|
21
29
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
tsconfig: tsconfigName,
|
|
25
|
-
tsc,
|
|
26
|
-
clear: _clear = true,
|
|
27
|
-
platform,
|
|
28
|
-
styleOnly
|
|
29
|
-
}) => {
|
|
30
|
+
|
|
31
|
+
const init = api => {
|
|
30
32
|
const {
|
|
31
33
|
appDirectory
|
|
32
34
|
} = api.useAppContext();
|
|
33
|
-
const modernConfig = api.useResolvedConfigContext();
|
|
34
|
-
const tsconfigPath = path.join(appDirectory, tsconfigName);
|
|
35
35
|
|
|
36
36
|
_utils.dotenv.config();
|
|
37
37
|
|
|
38
|
+
(0, _signalExit.default)(async code => {
|
|
39
|
+
if (code === 0) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const tempTsconfigPathPattern = path.join(appDirectory, './node_modules', `./tsconfig.**.**.json`);
|
|
44
|
+
const files = (0, _utils.globby)((0, _utils.slash)(tempTsconfigPathPattern), {
|
|
45
|
+
stats: true,
|
|
46
|
+
absolute: true
|
|
47
|
+
});
|
|
48
|
+
const currentTime = Date.now();
|
|
49
|
+
|
|
50
|
+
for (const file of files) {
|
|
51
|
+
// over 30s, will delete it
|
|
52
|
+
if (currentTime - file.stats.birthtimeMs >= 30 * 1000) {
|
|
53
|
+
_utils.fs.unlinkSync(file.path);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
exports.init = init;
|
|
60
|
+
|
|
61
|
+
const build = async (api, buildCommandOption) => {
|
|
62
|
+
var _modernConfig$output$;
|
|
63
|
+
|
|
64
|
+
const {
|
|
65
|
+
watch = false,
|
|
66
|
+
tsconfig: tsconfigName,
|
|
67
|
+
tsc,
|
|
68
|
+
dts = false,
|
|
69
|
+
clear,
|
|
70
|
+
platform = false,
|
|
71
|
+
styleOnly = false
|
|
72
|
+
} = buildCommandOption;
|
|
73
|
+
init(api);
|
|
74
|
+
const {
|
|
75
|
+
appDirectory
|
|
76
|
+
} = api.useAppContext();
|
|
77
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
78
|
+
const tsconfigPath = path.join(appDirectory, tsconfigName);
|
|
79
|
+
const outputPath = (_modernConfig$output$ = modernConfig.output.path) !== null && _modernConfig$output$ !== void 0 ? _modernConfig$output$ : 'dist';
|
|
38
80
|
const isTsProject = tsConfigutils.existTsConfigFile(tsconfigPath);
|
|
39
|
-
const
|
|
81
|
+
const enableDtsGen = isTsProject && dts;
|
|
40
82
|
valid.valideBeforeTask({
|
|
41
83
|
modernConfig,
|
|
42
84
|
tsconfigPath
|
|
43
|
-
});
|
|
44
|
-
|
|
85
|
+
});
|
|
45
86
|
await buildFeature.build(api, {
|
|
46
|
-
|
|
47
|
-
|
|
87
|
+
enableWatchMode: watch,
|
|
88
|
+
enableDtsGen,
|
|
48
89
|
isTsProject,
|
|
49
|
-
platform,
|
|
50
|
-
sourceDir: 'src',
|
|
51
90
|
tsconfigName,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
}
|
|
91
|
+
outputPath,
|
|
92
|
+
styleOnly,
|
|
93
|
+
platform,
|
|
94
|
+
clear,
|
|
95
|
+
legacyTsc: tsc
|
|
63
96
|
});
|
|
64
97
|
};
|
|
65
98
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.build = void 0;
|
|
7
|
+
|
|
8
|
+
var _pMap = _interopRequireDefault(require("p-map"));
|
|
9
|
+
|
|
10
|
+
var _runSpeedy = require("./runSpeedy");
|
|
11
|
+
|
|
12
|
+
var _runRollup = require("./runRollup");
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
const build = async (api, config) => {
|
|
17
|
+
const tasks = config.dtsOnly ? [_runRollup.startRollup] : [_runSpeedy.runSpeedy, _runRollup.startRollup];
|
|
18
|
+
await (0, _pMap.default)(tasks, async task => {
|
|
19
|
+
await task(api, config);
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
exports.build = build;
|