@modern-js/module-tools 1.5.7 → 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.
- package/CHANGELOG.md +34 -0
- package/dist/js/modern/cli/build.js +5 -4
- package/dist/js/modern/commands/build.js +40 -27
- package/dist/js/modern/features/build/bundle/index.js +6 -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 -55
- package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/index.js +46 -70
- package/dist/js/modern/{tasks → features/build/bundleless}/generator-dts/utils.js +6 -6
- package/dist/js/modern/features/build/bundleless/index.js +13 -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 +84 -19
- package/dist/js/modern/features/build/legacy-constants.js +99 -0
- package/dist/js/modern/features/build/normalize.js +293 -0
- package/dist/js/modern/features/build/types.js +0 -0
- package/dist/js/modern/features/build/utils.js +29 -137
- 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 +104 -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/node/cli/build.js +5 -4
- package/dist/js/node/commands/build.js +50 -29
- package/dist/js/node/features/build/bundle/index.js +17 -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 -55
- package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/index.js +59 -73
- package/dist/js/node/{tasks → features/build/bundleless}/generator-dts/utils.js +6 -6
- package/dist/js/node/features/build/bundleless/index.js +26 -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 +92 -19
- package/dist/js/node/features/build/legacy-constants.js +107 -0
- package/dist/js/node/features/build/normalize.js +322 -0
- package/dist/js/node/features/build/types.js +0 -0
- package/dist/js/node/features/build/utils.js +31 -145
- package/dist/js/node/index.js +5 -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 +113 -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/types/cli/build.d.ts +1 -1
- package/dist/types/cli/new.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 +4 -3
- package/dist/types/features/build/legacy-constants.d.ts +8 -0
- package/dist/types/features/build/logger/loggerManager.d.ts +2 -0
- package/dist/types/features/build/normalize.d.ts +18 -0
- package/dist/types/features/build/types.d.ts +15 -0
- package/dist/types/features/build/utils.d.ts +9 -31
- 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 +179 -0
- package/dist/types/schema/index.d.ts +166 -18
- package/dist/types/schema/output.d.ts +170 -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 +45 -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/dist/types/utils/logger.d.ts +2 -0
- package/package.json +28 -15
- 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 -207
- package/dist/js/modern/tasks/build-style.js +0 -168
- package/dist/js/modern/tasks/build-watch-source-code.js +0 -161
- package/dist/js/modern/tasks/build-watch-style.js +0 -215
- 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 -233
- package/dist/js/node/tasks/build-style.js +0 -183
- package/dist/js/node/tasks/build-watch-source-code.js +0 -173
- package/dist/js/node/tasks/build-watch-style.js +0 -232
- 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
|
@@ -3,77 +3,125 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
// Universal JS 的默认选择,三份构建产物,支持 Node.js,对现代浏览器有优化
|
|
8
|
-
const universalJs = [{
|
|
9
|
-
type: 'module',
|
|
10
|
-
syntax: 'es5',
|
|
11
|
-
outDir: 'treeshaking'
|
|
12
|
-
}, {
|
|
13
|
-
type: 'commonjs',
|
|
14
|
-
syntax: 'es6+',
|
|
15
|
-
outDir: 'node'
|
|
16
|
-
}, {
|
|
17
|
-
type: 'module',
|
|
18
|
-
syntax: 'es6+',
|
|
19
|
-
outDir: 'modern'
|
|
20
|
-
}]; // Universal JS 的优化选择,两份构建产物,对现代浏览器无优化
|
|
6
|
+
exports.unPresets = exports.unPresetWithTargetConfigs = exports.unPresetConfigs = exports.targets = exports.npmLibraryWithUmdPresetConfig = exports.npmLibraryPresetConfig = exports.npmComponentWithUmdPresetConfig = exports.npmComponentPresetConfig = exports.clearFlag = exports.buildingText = exports.buildSuccessText = exports.buildFailText = void 0;
|
|
21
7
|
|
|
22
|
-
|
|
23
|
-
type: 'module',
|
|
24
|
-
syntax: 'es5',
|
|
25
|
-
outDir: 'treeshaking'
|
|
26
|
-
}, {
|
|
27
|
-
type: 'commonjs',
|
|
28
|
-
syntax: 'es6+',
|
|
29
|
-
outDir: 'node',
|
|
30
|
-
copyDirs: ['modern']
|
|
31
|
-
}]; // 纯前端代码的默认选择,两份构建产物
|
|
8
|
+
var _utils = require("@modern-js/utils");
|
|
32
9
|
|
|
33
|
-
|
|
34
|
-
type: 'module',
|
|
35
|
-
syntax: 'es5',
|
|
36
|
-
outDir: 'treeshaking',
|
|
37
|
-
copyDirs: ['node']
|
|
38
|
-
}, {
|
|
39
|
-
type: 'module',
|
|
40
|
-
syntax: 'es6+',
|
|
41
|
-
outDir: 'modern'
|
|
42
|
-
}]; // 纯前端代码的优化选择,单份构建产物,对现代浏览器无优化
|
|
10
|
+
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; }
|
|
43
11
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
12
|
+
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; }
|
|
13
|
+
|
|
14
|
+
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; }
|
|
15
|
+
|
|
16
|
+
const clearFlag = '\x1Bc';
|
|
17
|
+
exports.clearFlag = clearFlag;
|
|
50
18
|
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
19
|
+
const buildingText = _utils.chalk.blue('Building...');
|
|
20
|
+
|
|
21
|
+
exports.buildingText = buildingText;
|
|
22
|
+
|
|
23
|
+
const buildSuccessText = _utils.chalk.green('Build succeed');
|
|
24
|
+
|
|
25
|
+
exports.buildSuccessText = buildSuccessText;
|
|
26
|
+
|
|
27
|
+
const buildFailText = _utils.chalk.red('Build Failed:');
|
|
28
|
+
|
|
29
|
+
exports.buildFailText = buildFailText;
|
|
30
|
+
const targets = ['es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', 'esnext'];
|
|
31
|
+
exports.targets = targets;
|
|
32
|
+
const npmLibraryPresetConfig = [{
|
|
33
|
+
format: 'cjs',
|
|
34
|
+
target: 'es6',
|
|
35
|
+
buildType: 'bundle',
|
|
36
|
+
outputPath: './lib'
|
|
37
|
+
}, {
|
|
38
|
+
format: 'esm',
|
|
39
|
+
target: 'es6',
|
|
40
|
+
buildType: 'bundle',
|
|
41
|
+
outputPath: './es'
|
|
55
42
|
}, {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
43
|
+
buildType: 'bundle',
|
|
44
|
+
outputPath: './types',
|
|
45
|
+
enableDts: true,
|
|
46
|
+
dtsOnly: true
|
|
59
47
|
}];
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
'
|
|
64
|
-
'
|
|
65
|
-
'
|
|
66
|
-
|
|
67
|
-
'
|
|
48
|
+
exports.npmLibraryPresetConfig = npmLibraryPresetConfig;
|
|
49
|
+
const npmLibraryWithUmdPresetConfig = [{
|
|
50
|
+
format: 'cjs',
|
|
51
|
+
target: 'es6',
|
|
52
|
+
buildType: 'bundle',
|
|
53
|
+
outputPath: './lib'
|
|
54
|
+
}, {
|
|
55
|
+
format: 'esm',
|
|
56
|
+
target: 'es6',
|
|
57
|
+
buildType: 'bundle',
|
|
58
|
+
outputPath: './es'
|
|
59
|
+
}, {
|
|
60
|
+
format: 'umd',
|
|
61
|
+
target: 'es6',
|
|
62
|
+
buildType: 'bundle',
|
|
63
|
+
outputPath: './umd'
|
|
64
|
+
}, {
|
|
65
|
+
buildType: 'bundle',
|
|
66
|
+
outputPath: './types',
|
|
67
|
+
enableDts: true,
|
|
68
|
+
dtsOnly: true
|
|
69
|
+
}];
|
|
70
|
+
exports.npmLibraryWithUmdPresetConfig = npmLibraryWithUmdPresetConfig;
|
|
71
|
+
const npmComponentPresetConfig = [{
|
|
72
|
+
format: 'cjs',
|
|
73
|
+
target: 'es6',
|
|
74
|
+
buildType: 'bundleless',
|
|
75
|
+
outputPath: './lib'
|
|
76
|
+
}, {
|
|
77
|
+
format: 'esm',
|
|
78
|
+
target: 'es6',
|
|
79
|
+
buildType: 'bundleless',
|
|
80
|
+
outputPath: './es'
|
|
81
|
+
}, {
|
|
82
|
+
buildType: 'bundleless',
|
|
83
|
+
outputPath: './types',
|
|
84
|
+
enableDts: true,
|
|
85
|
+
dtsOnly: true
|
|
86
|
+
}];
|
|
87
|
+
exports.npmComponentPresetConfig = npmComponentPresetConfig;
|
|
88
|
+
const npmComponentWithUmdPresetConfig = [{
|
|
89
|
+
format: 'cjs',
|
|
90
|
+
target: 'es6',
|
|
91
|
+
buildType: 'bundleless',
|
|
92
|
+
outputPath: './lib'
|
|
93
|
+
}, {
|
|
94
|
+
format: 'esm',
|
|
95
|
+
target: 'es6',
|
|
96
|
+
buildType: 'bundleless',
|
|
97
|
+
outputPath: './es'
|
|
98
|
+
}, {
|
|
99
|
+
format: 'umd',
|
|
100
|
+
target: 'es6',
|
|
101
|
+
buildType: 'bundle',
|
|
102
|
+
outputPath: './umd'
|
|
103
|
+
}, {
|
|
104
|
+
buildType: 'bundleless',
|
|
105
|
+
outputPath: './types',
|
|
106
|
+
enableDts: true,
|
|
107
|
+
dtsOnly: true
|
|
108
|
+
}];
|
|
109
|
+
exports.npmComponentWithUmdPresetConfig = npmComponentWithUmdPresetConfig;
|
|
110
|
+
const unPresetConfigs = {
|
|
111
|
+
'npm-library': npmLibraryPresetConfig,
|
|
112
|
+
'npm-library-with-umd': npmLibraryWithUmdPresetConfig,
|
|
113
|
+
'npm-component': npmComponentPresetConfig,
|
|
114
|
+
'npm-component-with-umd': npmComponentWithUmdPresetConfig
|
|
68
115
|
};
|
|
69
|
-
exports.
|
|
70
|
-
const
|
|
71
|
-
exports.
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
116
|
+
exports.unPresetConfigs = unPresetConfigs;
|
|
117
|
+
const unPresets = Object.keys(unPresetConfigs);
|
|
118
|
+
exports.unPresets = unPresets;
|
|
119
|
+
const unPresetWithTargetConfigs = unPresets.reduce((o, presetStr) => {
|
|
120
|
+
const rets = targets.map(target => [`${presetStr}-${target}`.toLowerCase(), unPresetConfigs[presetStr].map(config => {
|
|
121
|
+
return _objectSpread(_objectSpread({}, config), {}, {
|
|
122
|
+
target
|
|
123
|
+
});
|
|
124
|
+
})]);
|
|
125
|
+
return _objectSpread(_objectSpread({}, o), Object.fromEntries(rets));
|
|
126
|
+
}, {});
|
|
127
|
+
exports.unPresetWithTargetConfigs = unPresetWithTargetConfigs;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.padSpaceWith = exports.isInternalError = exports.isExecaError = exports.ModuleBuildError = exports.InternalDTSError = exports.InternalBuildError = void 0;
|
|
7
|
+
|
|
8
|
+
var _utils = require("@modern-js/utils");
|
|
9
|
+
|
|
10
|
+
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; }
|
|
11
|
+
|
|
12
|
+
const padSpaceWith = (str, targetL, opts = {}) => {
|
|
13
|
+
const {
|
|
14
|
+
endStr = '|',
|
|
15
|
+
style
|
|
16
|
+
} = opts;
|
|
17
|
+
const l = str.length;
|
|
18
|
+
const endStrL = endStr.length;
|
|
19
|
+
const resetL = targetL - l - endStrL; // str is 'aaa', targetL is 4, result is 'aaa|'
|
|
20
|
+
|
|
21
|
+
if (resetL === 0) {
|
|
22
|
+
return (style ? style(str) : str) + endStr;
|
|
23
|
+
} // str is 'aaa', targetL is 5, result is 'aaa |'
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
if (resetL > 0) {
|
|
27
|
+
const padStr = str.padEnd(targetL - 1, ' ');
|
|
28
|
+
|
|
29
|
+
if (style) {
|
|
30
|
+
return style(str) + padStr.replace(str, '') + endStr;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return padStr + endStr;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return str;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
exports.padSpaceWith = padSpaceWith;
|
|
40
|
+
|
|
41
|
+
class InternalBuildError extends Error {
|
|
42
|
+
constructor(e, opts) {
|
|
43
|
+
super(e.message);
|
|
44
|
+
|
|
45
|
+
_defineProperty(this, "buildType", void 0);
|
|
46
|
+
|
|
47
|
+
_defineProperty(this, "target", void 0);
|
|
48
|
+
|
|
49
|
+
_defineProperty(this, "format", void 0);
|
|
50
|
+
|
|
51
|
+
_defineProperty(this, "e", void 0);
|
|
52
|
+
|
|
53
|
+
Error.captureStackTrace(this, this.constructor);
|
|
54
|
+
this.e = e;
|
|
55
|
+
this.buildType = opts.buildType;
|
|
56
|
+
this.target = opts.target;
|
|
57
|
+
this.format = opts.format;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
toString() {
|
|
61
|
+
return this.formatError().join('\n');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
formatError() {
|
|
65
|
+
const msgs = [];
|
|
66
|
+
const {
|
|
67
|
+
e,
|
|
68
|
+
buildType,
|
|
69
|
+
target,
|
|
70
|
+
format
|
|
71
|
+
} = this;
|
|
72
|
+
const textL = 25;
|
|
73
|
+
const title = `│ ${padSpaceWith(`${buildType} failed:`, textL - 2, {
|
|
74
|
+
style: _utils.chalk.red.underline,
|
|
75
|
+
endStr: '│'
|
|
76
|
+
})}`;
|
|
77
|
+
const formatMsg = padSpaceWith(`│ - format is "${format}"`, textL, {
|
|
78
|
+
endStr: '│'
|
|
79
|
+
});
|
|
80
|
+
const targetMsg = padSpaceWith(`│ - target is "${target}"`, textL, {
|
|
81
|
+
endStr: '│'
|
|
82
|
+
});
|
|
83
|
+
const startLine = padSpaceWith('╭'.padEnd(textL - 1, '─'), textL, {
|
|
84
|
+
endStr: '╮'
|
|
85
|
+
});
|
|
86
|
+
const endLine = padSpaceWith('╰'.padEnd(textL - 1, '─'), textL, {
|
|
87
|
+
endStr: '╯'
|
|
88
|
+
});
|
|
89
|
+
msgs.push(startLine, title, formatMsg, targetMsg, endLine, _utils.chalk.blue.bold.underline(`\nDetailed Information: `));
|
|
90
|
+
msgs.push(e.toString());
|
|
91
|
+
msgs.push(e.stack || '');
|
|
92
|
+
return msgs;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
exports.InternalBuildError = InternalBuildError;
|
|
98
|
+
|
|
99
|
+
class InternalDTSError extends Error {
|
|
100
|
+
constructor(e, opts) {
|
|
101
|
+
super(e.message);
|
|
102
|
+
|
|
103
|
+
_defineProperty(this, "buildType", void 0);
|
|
104
|
+
|
|
105
|
+
_defineProperty(this, "e", void 0);
|
|
106
|
+
|
|
107
|
+
Error.captureStackTrace(this, this.constructor);
|
|
108
|
+
this.e = e;
|
|
109
|
+
this.buildType = opts.buildType;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
toString() {
|
|
113
|
+
return this.formatError().join('\n');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
formatError() {
|
|
117
|
+
const msgs = [];
|
|
118
|
+
const {
|
|
119
|
+
e,
|
|
120
|
+
buildType
|
|
121
|
+
} = this;
|
|
122
|
+
msgs.push(_utils.chalk.red.bold(`${buildType} DTS failed:`));
|
|
123
|
+
|
|
124
|
+
if (isExecaError(e)) {
|
|
125
|
+
/**
|
|
126
|
+
* `shortMeessage` content like:
|
|
127
|
+
* 'Command failed with exit code 2: /Users/github/modern.js/playground/module/node_modules/.bin/tsc -p /Users/github/modern.js/playground/module/node_modules/tsconfig.temp.json --pretty'
|
|
128
|
+
* Don`t need it.
|
|
129
|
+
*/
|
|
130
|
+
if (e.stack) {
|
|
131
|
+
var _e$stack;
|
|
132
|
+
|
|
133
|
+
msgs.push((_e$stack = e.stack) === null || _e$stack === void 0 ? void 0 : _e$stack.replace(`${e.name}: ${e.shortMessage}`, ''));
|
|
134
|
+
}
|
|
135
|
+
} else {
|
|
136
|
+
msgs.push(e.stack);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return msgs;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
exports.InternalDTSError = InternalDTSError;
|
|
145
|
+
|
|
146
|
+
class ModuleBuildError extends Error {
|
|
147
|
+
constructor(e) {
|
|
148
|
+
super(`\n\n${e}`);
|
|
149
|
+
Error.captureStackTrace(this, this.constructor);
|
|
150
|
+
this.name = 'ModuleBuildError';
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
exports.ModuleBuildError = ModuleBuildError;
|
|
156
|
+
|
|
157
|
+
const isInternalError = e => {
|
|
158
|
+
if (e instanceof InternalBuildError || e instanceof InternalDTSError) {
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return false;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
exports.isInternalError = isInternalError;
|
|
166
|
+
|
|
167
|
+
const isExecaError = e => {
|
|
168
|
+
if (e.stdout) {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return false;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
exports.isExecaError = isExecaError;
|
|
@@ -3,33 +3,33 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.build = void 0;
|
|
6
|
+
exports.buildInNormalMode = exports.build = void 0;
|
|
7
7
|
|
|
8
8
|
var _path = _interopRequireDefault(require("path"));
|
|
9
9
|
|
|
10
10
|
var _utils = require("@modern-js/utils");
|
|
11
11
|
|
|
12
|
+
var _readline = require("../../utils/readline");
|
|
13
|
+
|
|
14
|
+
var _normalize = require("./normalize");
|
|
15
|
+
|
|
16
|
+
var _constants = require("./constants");
|
|
17
|
+
|
|
18
|
+
var _error = require("./error");
|
|
19
|
+
|
|
12
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
21
|
|
|
14
|
-
const
|
|
22
|
+
const bundle = _utils.Import.lazy('./bundle', require);
|
|
15
23
|
|
|
16
|
-
const
|
|
24
|
+
const bundleless = _utils.Import.lazy('./bundleless', require);
|
|
17
25
|
|
|
18
26
|
const bp = _utils.Import.lazy('./build-platform', require);
|
|
19
27
|
|
|
20
|
-
const
|
|
28
|
+
const checkPlatformAndRunBuild = async (platform, options) => {
|
|
21
29
|
const {
|
|
22
|
-
|
|
23
|
-
enableWatchMode,
|
|
24
|
-
platform,
|
|
25
|
-
clear = true,
|
|
30
|
+
api,
|
|
26
31
|
isTsProject
|
|
27
|
-
} =
|
|
28
|
-
const {
|
|
29
|
-
output: {
|
|
30
|
-
path: outputPath = 'dist'
|
|
31
|
-
}
|
|
32
|
-
} = modernConfig; // TODO: maybe need watch mode in build platform
|
|
32
|
+
} = options;
|
|
33
33
|
|
|
34
34
|
if (typeof platform === 'boolean' && platform) {
|
|
35
35
|
if (process.env.RUN_PLATFORM) {
|
|
@@ -39,7 +39,9 @@ const build = async (api, config, modernConfig) => {
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
return
|
|
42
|
+
return {
|
|
43
|
+
exit: true
|
|
44
|
+
};
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
if (typeof platform === 'string') {
|
|
@@ -50,17 +52,88 @@ const build = async (api, config, modernConfig) => {
|
|
|
50
52
|
});
|
|
51
53
|
}
|
|
52
54
|
|
|
55
|
+
return {
|
|
56
|
+
exit: true
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
exit: false
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const buildInNormalMode = async buildTasks => {
|
|
66
|
+
console.info(_utils.chalk.blue.bold(_constants.buildingText));
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
// eslint-disable-next-line no-console
|
|
70
|
+
console.time(_constants.buildSuccessText);
|
|
71
|
+
await Promise.all(buildTasks);
|
|
72
|
+
|
|
73
|
+
_readline.ReadlineUtils.clearPrevLine(process.stdout); // eslint-disable-next-line no-console
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
console.timeEnd(_constants.buildSuccessText);
|
|
77
|
+
} catch (e) {
|
|
78
|
+
_readline.ReadlineUtils.clearPrevLine(process.stdout);
|
|
79
|
+
|
|
80
|
+
if ((0, _error.isInternalError)(e)) {
|
|
81
|
+
throw new _error.ModuleBuildError(e);
|
|
82
|
+
} else {
|
|
83
|
+
throw e;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
exports.buildInNormalMode = buildInNormalMode;
|
|
89
|
+
|
|
90
|
+
const build = async (api, config) => {
|
|
91
|
+
const {
|
|
92
|
+
platform,
|
|
93
|
+
clear = true,
|
|
94
|
+
isTsProject
|
|
95
|
+
} = config;
|
|
96
|
+
const {
|
|
97
|
+
appDirectory
|
|
98
|
+
} = api.useAppContext();
|
|
99
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
100
|
+
const {
|
|
101
|
+
output: {
|
|
102
|
+
path: outputPath = 'dist'
|
|
103
|
+
}
|
|
104
|
+
} = modernConfig; // build platform
|
|
105
|
+
|
|
106
|
+
const platformBuildRet = await checkPlatformAndRunBuild(platform, {
|
|
107
|
+
api,
|
|
108
|
+
isTsProject
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
if (platformBuildRet.exit) {
|
|
53
112
|
return;
|
|
54
113
|
}
|
|
55
114
|
|
|
56
115
|
if (clear) {
|
|
57
116
|
_utils.fs.removeSync(_path.default.join(appDirectory, outputPath));
|
|
58
|
-
}
|
|
117
|
+
} // should normalize module tool config here, ensure the same config for build
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
const normalizedModuleConfig = (0, _normalize.normalizeModuleConfig)({
|
|
121
|
+
buildFeatOption: config,
|
|
122
|
+
api
|
|
123
|
+
});
|
|
124
|
+
const buildTasks = normalizedModuleConfig.map(moduleConfig => {
|
|
125
|
+
if (moduleConfig.buildType === 'bundle') {
|
|
126
|
+
return bundle.build(api, moduleConfig);
|
|
127
|
+
} else {
|
|
128
|
+
return bundleless.build(api, moduleConfig, config);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
59
131
|
|
|
60
|
-
if (enableWatchMode) {
|
|
61
|
-
|
|
132
|
+
if (config.enableWatchMode) {
|
|
133
|
+
console.info(_utils.chalk.blue.underline('start build in watch mode...\n'));
|
|
134
|
+
await Promise.all(buildTasks);
|
|
62
135
|
} else {
|
|
63
|
-
await
|
|
136
|
+
await buildInNormalMode(buildTasks);
|
|
64
137
|
}
|
|
65
138
|
};
|
|
66
139
|
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.PACKAGE_MODES = exports.DEFAULT_PACKAGE_MODE = void 0;
|
|
7
|
+
// Universal JS 的默认选择,三份构建产物,支持 Node.js,对现代浏览器有优化
|
|
8
|
+
const universalJs = [{
|
|
9
|
+
format: 'esm',
|
|
10
|
+
target: 'es5',
|
|
11
|
+
outputPath: './js/treeshaking',
|
|
12
|
+
bundlelessOptions: {
|
|
13
|
+
style: {
|
|
14
|
+
compileMode: 'only-source-code'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}, {
|
|
18
|
+
format: 'cjs',
|
|
19
|
+
target: 'es6',
|
|
20
|
+
outputPath: './js/node'
|
|
21
|
+
}, {
|
|
22
|
+
format: 'esm',
|
|
23
|
+
target: 'es6',
|
|
24
|
+
outputPath: './js/modern'
|
|
25
|
+
}]; // Universal JS 的优化选择,两份构建产物,对现代浏览器无优化
|
|
26
|
+
|
|
27
|
+
const universalJsLite = [{
|
|
28
|
+
format: 'esm',
|
|
29
|
+
target: 'es5',
|
|
30
|
+
outputPath: './js/treeshaking',
|
|
31
|
+
bundlelessOptions: {
|
|
32
|
+
style: {
|
|
33
|
+
compileMode: 'only-source-code'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}, {
|
|
37
|
+
format: 'cjs',
|
|
38
|
+
target: 'es6',
|
|
39
|
+
outputPath: './js/node'
|
|
40
|
+
}, {
|
|
41
|
+
format: 'esm',
|
|
42
|
+
target: 'es5',
|
|
43
|
+
outputPath: './js/modern'
|
|
44
|
+
}]; // 纯前端代码的默认选择,两份构建产物
|
|
45
|
+
|
|
46
|
+
const browserJs = [{
|
|
47
|
+
format: 'esm',
|
|
48
|
+
target: 'es5',
|
|
49
|
+
outputPath: './js/treeshaking',
|
|
50
|
+
bundlelessOptions: {
|
|
51
|
+
style: {
|
|
52
|
+
compileMode: 'only-source-code'
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}, {
|
|
56
|
+
format: 'esm',
|
|
57
|
+
target: 'es6',
|
|
58
|
+
outputPath: './js/node'
|
|
59
|
+
}, {
|
|
60
|
+
format: 'esm',
|
|
61
|
+
target: 'es6',
|
|
62
|
+
outputPath: './js/modern'
|
|
63
|
+
}]; // 纯前端代码的优化选择,单份构建产物,对现代浏览器无优化
|
|
64
|
+
|
|
65
|
+
const browserJsLite = [{
|
|
66
|
+
format: 'esm',
|
|
67
|
+
target: 'es5',
|
|
68
|
+
outputPath: './js/treeshaking',
|
|
69
|
+
bundlelessOptions: {
|
|
70
|
+
style: {
|
|
71
|
+
compileMode: 'only-source-code'
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}, {
|
|
75
|
+
format: 'esm',
|
|
76
|
+
target: 'es5',
|
|
77
|
+
outputPath: './js/node'
|
|
78
|
+
}, {
|
|
79
|
+
format: 'esm',
|
|
80
|
+
target: 'es5',
|
|
81
|
+
outputPath: './js/modern'
|
|
82
|
+
}]; // 纯 Node.js 代码的默认选择,两份构建产物
|
|
83
|
+
|
|
84
|
+
const nodeJs = [{
|
|
85
|
+
format: 'cjs',
|
|
86
|
+
target: 'es6',
|
|
87
|
+
outputPath: './js/node',
|
|
88
|
+
bundlelessOptions: {
|
|
89
|
+
style: {
|
|
90
|
+
compileMode: 'only-source-code'
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}, {
|
|
94
|
+
format: 'esm',
|
|
95
|
+
target: 'es6',
|
|
96
|
+
outputPath: './js/modern'
|
|
97
|
+
}];
|
|
98
|
+
const DEFAULT_PACKAGE_MODE = 'universal-js';
|
|
99
|
+
exports.DEFAULT_PACKAGE_MODE = DEFAULT_PACKAGE_MODE;
|
|
100
|
+
const PACKAGE_MODES = {
|
|
101
|
+
'universal-js': universalJs,
|
|
102
|
+
'universal-js-lite': universalJsLite,
|
|
103
|
+
'browser-js': browserJs,
|
|
104
|
+
'browser-js-lite': browserJsLite,
|
|
105
|
+
'node-js': nodeJs
|
|
106
|
+
};
|
|
107
|
+
exports.PACKAGE_MODES = PACKAGE_MODES;
|