@modern-js/module-tools 2.0.0-beta.0 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +51 -0
- package/dist/js/modern/cli/build.js +2 -1
- package/dist/js/modern/cli/dev.js +2 -2
- package/dist/js/modern/cli/new.js +0 -3
- package/dist/js/modern/commands/build.js +0 -4
- package/dist/js/modern/commands/dev.js +2 -5
- package/dist/js/modern/features/build/build-platform.js +11 -14
- package/dist/js/modern/features/build/bundle/runRollup.js +5 -18
- package/dist/js/modern/features/build/bundle/runSpeedy.js +4 -18
- package/dist/js/modern/features/build/bundleless/copy-assets.js +0 -8
- package/dist/js/modern/features/build/bundleless/generator-dts/index.js +7 -17
- package/dist/js/modern/features/build/bundleless/generator-dts/utils.js +6 -16
- package/dist/js/modern/features/build/bundleless/index.js +0 -2
- package/dist/js/modern/features/build/bundleless/runBabel.js +7 -34
- package/dist/js/modern/features/build/bundleless/style.js +1 -30
- package/dist/js/modern/features/build/constants.js +0 -3
- package/dist/js/modern/features/build/error.js +4 -27
- package/dist/js/modern/features/build/index.js +6 -15
- package/dist/js/modern/features/build/legacy-constants.js +8 -4
- package/dist/js/modern/features/build/logger/logText.js +0 -12
- package/dist/js/modern/features/build/logger/loggerManager.js +6 -19
- package/dist/js/modern/features/build/normalize.js +18 -43
- package/dist/js/modern/features/build/utils.js +5 -14
- package/dist/js/modern/features/dev/index.js +4 -9
- package/dist/js/modern/hooks/index.js +0 -3
- package/dist/js/modern/index.js +5 -9
- package/dist/js/modern/schema/build-config.js +2 -1
- package/dist/js/modern/schema/output.js +5 -10
- package/dist/js/modern/utils/babel.js +12 -14
- package/dist/js/modern/utils/copy.js +6 -15
- package/dist/js/modern/utils/init-env.js +0 -1
- package/dist/js/modern/utils/logger.js +1 -16
- package/dist/js/modern/utils/readline.js +2 -4
- package/dist/js/modern/utils/tsconfig.js +0 -1
- package/dist/js/modern/utils/tspaths-transform/constants.js +4 -2
- package/dist/js/modern/utils/tspaths-transform/index.js +2 -19
- package/dist/js/modern/utils/tspaths-transform/utils.js +0 -3
- package/dist/js/modern/utils/valide.js +2 -6
- package/dist/js/node/cli/build.js +2 -6
- package/dist/js/node/cli/dev.js +2 -7
- package/dist/js/node/cli/index.js +0 -6
- package/dist/js/node/cli/new.js +0 -8
- package/dist/js/node/commands/build.js +0 -19
- package/dist/js/node/commands/dev.js +2 -15
- package/dist/js/node/commands/index.js +0 -2
- package/dist/js/node/features/build/build-platform.js +11 -20
- package/dist/js/node/features/build/bundle/index.js +0 -6
- package/dist/js/node/features/build/bundle/runRollup.js +3 -32
- package/dist/js/node/features/build/bundle/runSpeedy.js +4 -32
- package/dist/js/node/features/build/bundleless/copy-assets.js +0 -20
- package/dist/js/node/features/build/bundleless/generator-dts/index.js +7 -27
- package/dist/js/node/features/build/bundleless/generator-dts/utils.js +6 -32
- package/dist/js/node/features/build/bundleless/index.js +0 -11
- package/dist/js/node/features/build/bundleless/runBabel.js +6 -60
- package/dist/js/node/features/build/bundleless/style.js +1 -50
- package/dist/js/node/features/build/constants.js +0 -11
- package/dist/js/node/features/build/error.js +4 -40
- package/dist/js/node/features/build/index.js +6 -38
- package/dist/js/node/features/build/legacy-constants.js +8 -4
- package/dist/js/node/features/build/logger/index.js +0 -4
- package/dist/js/node/features/build/logger/logText.js +0 -18
- package/dist/js/node/features/build/logger/loggerManager.js +5 -26
- package/dist/js/node/features/build/normalize.js +18 -61
- package/dist/js/node/features/build/utils.js +5 -30
- package/dist/js/node/features/dev/index.js +4 -17
- package/dist/js/node/hooks/build.js +0 -5
- package/dist/js/node/hooks/dev.js +0 -5
- package/dist/js/node/hooks/index.js +0 -10
- package/dist/js/node/index.js +6 -26
- package/dist/js/node/locale/index.js +0 -5
- package/dist/js/node/schema/build-config.js +2 -1
- package/dist/js/node/schema/index.js +0 -5
- package/dist/js/node/schema/output.js +5 -12
- package/dist/js/node/utils/babel.js +12 -22
- package/dist/js/node/utils/color.js +0 -3
- package/dist/js/node/utils/copy.js +6 -23
- package/dist/js/node/utils/init-env.js +0 -3
- package/dist/js/node/utils/json.js +0 -2
- package/dist/js/node/utils/language.js +0 -3
- package/dist/js/node/utils/logger.js +1 -26
- package/dist/js/node/utils/readline.js +0 -8
- package/dist/js/node/utils/tsconfig.js +0 -7
- package/dist/js/node/utils/tspaths-transform/constants.js +4 -2
- package/dist/js/node/utils/tspaths-transform/index.js +2 -34
- package/dist/js/node/utils/tspaths-transform/utils.js +0 -7
- package/dist/js/node/utils/valide.js +2 -11
- package/dist/types/commands/build.d.ts +0 -1
- package/dist/types/features/build/logger/loggerManager.d.ts +0 -1
- package/dist/types/features/build/utils.d.ts +0 -1
- package/dist/types/index.d.ts +0 -2
- package/dist/types/schema/types.d.ts +1 -3
- package/dist/types/types.d.ts +0 -1
- package/package.json +19 -19
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
|
|
3
2
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
|
|
5
3
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
|
|
7
4
|
import path from 'path';
|
|
8
5
|
import { Import, glob, fs, chalk, globby, slash } from '@modern-js/utils';
|
|
9
6
|
import { InternalBuildError } from "../error";
|
|
@@ -11,20 +8,15 @@ import { SectionTitleStatus, watchSectionTitle } from "../utils";
|
|
|
11
8
|
export class BabelBuildError extends Error {
|
|
12
9
|
constructor(message, opts) {
|
|
13
10
|
super(message);
|
|
14
|
-
|
|
15
11
|
_defineProperty(this, "summary", void 0);
|
|
16
|
-
|
|
17
12
|
_defineProperty(this, "details", void 0);
|
|
18
|
-
|
|
19
13
|
Error.captureStackTrace(this, this.constructor);
|
|
20
14
|
this.summary = opts === null || opts === void 0 ? void 0 : opts.summary;
|
|
21
15
|
this.details = opts === null || opts === void 0 ? void 0 : opts.details;
|
|
22
16
|
}
|
|
23
|
-
|
|
24
17
|
toString() {
|
|
25
18
|
return this.formatError().join('\n');
|
|
26
19
|
}
|
|
27
|
-
|
|
28
20
|
formatError() {
|
|
29
21
|
const msgs = [];
|
|
30
22
|
const {
|
|
@@ -32,45 +24,39 @@ export class BabelBuildError extends Error {
|
|
|
32
24
|
details = []
|
|
33
25
|
} = this;
|
|
34
26
|
msgs.push(chalk.red.bold(summary));
|
|
35
|
-
|
|
36
27
|
for (const detail of details) {
|
|
37
28
|
msgs.push(detail.content);
|
|
38
29
|
msgs.push('\n');
|
|
39
30
|
}
|
|
40
|
-
|
|
41
31
|
return msgs;
|
|
42
32
|
}
|
|
43
|
-
|
|
44
33
|
}
|
|
45
34
|
const babelCompiler = Import.lazy('@modern-js/babel-compiler', require);
|
|
46
35
|
const bc = Import.lazy('../../../utils/babel', require);
|
|
47
|
-
const ts = Import.lazy('../../../utils/tsconfig', require);
|
|
36
|
+
const ts = Import.lazy('../../../utils/tsconfig', require);
|
|
37
|
+
|
|
38
|
+
// const logger: typeof import('../logger') = Import.lazy('../logger', require);
|
|
48
39
|
|
|
49
40
|
const getExts = (isTs, tsconfig) => {
|
|
50
41
|
// TODO: 是否受控tsconfig.json 里的jsx配置
|
|
51
42
|
let exts = [];
|
|
52
|
-
|
|
53
43
|
if (isTs) {
|
|
54
44
|
var _tsconfig$compilerOpt;
|
|
55
|
-
|
|
56
45
|
exts = tsconfig !== null && tsconfig !== void 0 && (_tsconfig$compilerOpt = tsconfig.compilerOptions) !== null && _tsconfig$compilerOpt !== void 0 && _tsconfig$compilerOpt.allowJs ? ['.ts', '.tsx', '.js', '.jsx'] : ['.ts', '.tsx'];
|
|
57
46
|
} else {
|
|
58
47
|
exts = ['.js', '.jsx'];
|
|
59
48
|
}
|
|
60
|
-
|
|
61
49
|
return exts;
|
|
62
50
|
};
|
|
63
|
-
|
|
64
51
|
export const getWillCompilerCode = (srcDirOrFile, option) => {
|
|
65
52
|
const {
|
|
66
53
|
tsconfig,
|
|
67
54
|
isTsProject
|
|
68
|
-
} = option;
|
|
69
|
-
|
|
55
|
+
} = option;
|
|
56
|
+
// 如果是一个文件路径,则直接返回
|
|
70
57
|
if (fs.existsSync(srcDirOrFile) && fs.lstatSync(srcDirOrFile).isFile()) {
|
|
71
58
|
return [srcDirOrFile];
|
|
72
59
|
}
|
|
73
|
-
|
|
74
60
|
const exts = getExts(isTsProject, tsconfig);
|
|
75
61
|
const globPattern = `${srcDirOrFile}/**/*{${exts.join(',')}}`;
|
|
76
62
|
const files = glob.sync(globPattern, {
|
|
@@ -93,7 +79,6 @@ export const buildSourceCode = async config => {
|
|
|
93
79
|
tsconfig,
|
|
94
80
|
isTsProject: Boolean(tsconfig)
|
|
95
81
|
});
|
|
96
|
-
|
|
97
82
|
if (watch) {
|
|
98
83
|
const emitter = await babelCompiler.compiler({
|
|
99
84
|
quiet: true,
|
|
@@ -119,7 +104,6 @@ export const buildSourceCode = async config => {
|
|
|
119
104
|
}, babelConfig);
|
|
120
105
|
}
|
|
121
106
|
};
|
|
122
|
-
|
|
123
107
|
const generatorRealFiles = virtualDists => {
|
|
124
108
|
for (const virtualDist of virtualDists) {
|
|
125
109
|
const {
|
|
@@ -130,7 +114,6 @@ const generatorRealFiles = virtualDists => {
|
|
|
130
114
|
} = virtualDist;
|
|
131
115
|
fs.ensureFileSync(distPath);
|
|
132
116
|
fs.writeFileSync(distPath, code);
|
|
133
|
-
|
|
134
117
|
if (sourcemap.length > 0) {
|
|
135
118
|
fs.ensureFileSync(sourceMapPath);
|
|
136
119
|
fs.writeFileSync(sourceMapPath, sourcemap);
|
|
@@ -142,8 +125,6 @@ const generatorRealFiles = virtualDists => {
|
|
|
142
125
|
* @param outputResults
|
|
143
126
|
* @param context
|
|
144
127
|
*/
|
|
145
|
-
|
|
146
|
-
|
|
147
128
|
const outputDist = (outputResults, context) => {
|
|
148
129
|
const {
|
|
149
130
|
code,
|
|
@@ -151,7 +132,6 @@ const outputDist = (outputResults, context) => {
|
|
|
151
132
|
messageDetails,
|
|
152
133
|
virtualDists = []
|
|
153
134
|
} = outputResults;
|
|
154
|
-
|
|
155
135
|
if (code === 0) {
|
|
156
136
|
generatorRealFiles(virtualDists);
|
|
157
137
|
} else if (messageDetails && messageDetails.length > 0) {
|
|
@@ -164,7 +144,6 @@ const outputDist = (outputResults, context) => {
|
|
|
164
144
|
}));
|
|
165
145
|
}
|
|
166
146
|
};
|
|
167
|
-
|
|
168
147
|
export const jsFileSuffix = ['js', 'jsx', 'ts', 'tsx'];
|
|
169
148
|
export const haveNotAnyJsFile = async sourceDir => {
|
|
170
149
|
const files = await globby(slash(`${sourceDir}/**/*.{${jsFileSuffix.join(',')}}`));
|
|
@@ -194,12 +173,11 @@ export const runBabelBuild = async (api, config) => {
|
|
|
194
173
|
} = bundlelessOptions;
|
|
195
174
|
const sourceAbsDir = path.join(appDirectory, sourceDir);
|
|
196
175
|
const tsconfigPath = path.join(appDirectory, tsconfig);
|
|
197
|
-
|
|
198
176
|
if (await haveNotAnyJsFile(sourceAbsDir)) {
|
|
199
177
|
return;
|
|
200
|
-
}
|
|
201
|
-
|
|
178
|
+
}
|
|
202
179
|
|
|
180
|
+
// TODO: Refactoring based on format and target
|
|
203
181
|
const syntax = target === 'es5' ? 'es5' : 'es6+';
|
|
204
182
|
const type = format === 'cjs' ? 'commonjs' : 'module';
|
|
205
183
|
const titleText = `[Bundleless:Babel: ${format}_${target}]`;
|
|
@@ -223,14 +201,12 @@ export const runBabelBuild = async (api, config) => {
|
|
|
223
201
|
babelConfig: buildConfig.babelConfig,
|
|
224
202
|
watch
|
|
225
203
|
});
|
|
226
|
-
|
|
227
204
|
if (watch) {
|
|
228
205
|
const emitter = result;
|
|
229
206
|
emitter.on(babelCompiler.BuildWatchEvent.firstCompiler, result => {
|
|
230
207
|
if (result.code === 1) {
|
|
231
208
|
console.info(watchSectionTitle(titleText, SectionTitleStatus.Fail));
|
|
232
209
|
console.error(result.message);
|
|
233
|
-
|
|
234
210
|
for (const detail of result.messageDetails || []) {
|
|
235
211
|
console.error(detail.content);
|
|
236
212
|
}
|
|
@@ -242,15 +218,12 @@ export const runBabelBuild = async (api, config) => {
|
|
|
242
218
|
emitter.on(babelCompiler.BuildWatchEvent.watchingCompiler, result => {
|
|
243
219
|
if (result.code === 1) {
|
|
244
220
|
var _result$virtualDists;
|
|
245
|
-
|
|
246
221
|
// console.error(logger.clearFlag);
|
|
247
222
|
console.info(watchSectionTitle(titleText, SectionTitleStatus.Fail));
|
|
248
223
|
console.error(result.message);
|
|
249
|
-
|
|
250
224
|
for (const detail of result.messageDetails || []) {
|
|
251
225
|
console.error(detail.content);
|
|
252
226
|
}
|
|
253
|
-
|
|
254
227
|
if (Array.isArray(result.virtualDists) && ((_result$virtualDists = result.virtualDists) === null || _result$virtualDists === void 0 ? void 0 : _result$virtualDists.length) > 0) {
|
|
255
228
|
generatorRealFiles(result.virtualDists);
|
|
256
229
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
|
|
3
2
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
|
|
5
3
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
|
|
7
4
|
import * as path from 'path';
|
|
8
5
|
import { fs, glob, Import, watch as watcher, WatchChangeType, chalk, globby, slash } from '@modern-js/utils';
|
|
9
6
|
import { InternalBuildError } from "../error";
|
|
@@ -12,20 +9,15 @@ const compiler = Import.lazy('@modern-js/style-compiler', require);
|
|
|
12
9
|
export class StyleBuildError extends Error {
|
|
13
10
|
constructor(message, opts) {
|
|
14
11
|
super(message);
|
|
15
|
-
|
|
16
12
|
_defineProperty(this, "summary", void 0);
|
|
17
|
-
|
|
18
13
|
_defineProperty(this, "details", void 0);
|
|
19
|
-
|
|
20
14
|
Error.captureStackTrace(this, this.constructor);
|
|
21
15
|
this.summary = opts === null || opts === void 0 ? void 0 : opts.summary;
|
|
22
16
|
this.details = opts === null || opts === void 0 ? void 0 : opts.details;
|
|
23
17
|
}
|
|
24
|
-
|
|
25
18
|
toString() {
|
|
26
19
|
return this.formatError().join('\n');
|
|
27
20
|
}
|
|
28
|
-
|
|
29
21
|
formatError() {
|
|
30
22
|
const msgs = [];
|
|
31
23
|
const {
|
|
@@ -33,24 +25,21 @@ export class StyleBuildError extends Error {
|
|
|
33
25
|
details = []
|
|
34
26
|
} = this;
|
|
35
27
|
msgs.push(chalk.red.bold(summary));
|
|
36
|
-
|
|
37
28
|
for (const detail of details) {
|
|
38
29
|
if (detail.error) {
|
|
39
30
|
msgs.push(detail.error);
|
|
40
31
|
msgs.push('\n');
|
|
41
32
|
}
|
|
42
33
|
}
|
|
43
|
-
|
|
44
34
|
return msgs;
|
|
45
35
|
}
|
|
46
|
-
|
|
47
36
|
}
|
|
37
|
+
|
|
48
38
|
/**
|
|
49
39
|
* when modern build, only throw Error or silent
|
|
50
40
|
* @param result
|
|
51
41
|
* @param context
|
|
52
42
|
*/
|
|
53
|
-
|
|
54
43
|
const generatorFileOrLogError = (result, context) => {
|
|
55
44
|
if (result.code === 0) {
|
|
56
45
|
for (const file of result.dists) {
|
|
@@ -70,42 +59,35 @@ const generatorFileOrLogError = (result, context) => {
|
|
|
70
59
|
}, context));
|
|
71
60
|
}
|
|
72
61
|
};
|
|
73
|
-
|
|
74
62
|
const generatorFileAndLog = (result, titleText) => {
|
|
75
63
|
if (result.code === 0) {
|
|
76
64
|
for (const file of result.dists) {
|
|
77
65
|
fs.ensureFileSync(file.filename);
|
|
78
66
|
fs.writeFileSync(file.filename, file.content);
|
|
79
67
|
}
|
|
80
|
-
|
|
81
68
|
console.info(watchSectionTitle(titleText, SectionTitleStatus.Success));
|
|
82
69
|
} else {
|
|
83
70
|
console.info(watchSectionTitle(titleText, SectionTitleStatus.Fail));
|
|
84
|
-
|
|
85
71
|
for (const file of result.errors) {
|
|
86
72
|
console.error(file.error);
|
|
87
73
|
}
|
|
88
74
|
}
|
|
89
75
|
};
|
|
90
|
-
|
|
91
76
|
const copyOriginStyleFiles = ({
|
|
92
77
|
targetDir,
|
|
93
78
|
outputDir,
|
|
94
79
|
ignoreCSS: _ignoreCSS = false
|
|
95
80
|
}) => {
|
|
96
81
|
const styleFiles = glob.sync(`${targetDir}/**/*.{${_ignoreCSS ? '' : 'css,'}sass,scss,less}`);
|
|
97
|
-
|
|
98
82
|
if (styleFiles.length > 0) {
|
|
99
83
|
fs.ensureDirSync(outputDir);
|
|
100
84
|
}
|
|
101
|
-
|
|
102
85
|
for (const styleFile of styleFiles) {
|
|
103
86
|
const file = path.relative(targetDir, styleFile);
|
|
104
87
|
fs.ensureDirSync(path.dirname(path.join(outputDir, file)));
|
|
105
88
|
fs.copyFileSync(styleFile, path.join(outputDir, file));
|
|
106
89
|
}
|
|
107
90
|
};
|
|
108
|
-
|
|
109
91
|
export const runBuild = async option => {
|
|
110
92
|
const {
|
|
111
93
|
watch,
|
|
@@ -116,7 +98,6 @@ export const runBuild = async option => {
|
|
|
116
98
|
sassOption,
|
|
117
99
|
postcssOption
|
|
118
100
|
} = option;
|
|
119
|
-
|
|
120
101
|
if (watch) {
|
|
121
102
|
const srcStyleEmitter = compiler.styleCompiler({
|
|
122
103
|
watch: true,
|
|
@@ -153,7 +134,6 @@ export const haveNotAnyStyles = async sourceDir => {
|
|
|
153
134
|
};
|
|
154
135
|
export const buildStyle = async (api, config) => {
|
|
155
136
|
var _style$path;
|
|
156
|
-
|
|
157
137
|
const modernConfig = api.useResolvedConfigContext();
|
|
158
138
|
const {
|
|
159
139
|
appDirectory
|
|
@@ -173,11 +153,9 @@ export const buildStyle = async (api, config) => {
|
|
|
173
153
|
}
|
|
174
154
|
} = modernConfig;
|
|
175
155
|
const titleText = `[Bundleless:Style:${sourceDir}]`;
|
|
176
|
-
|
|
177
156
|
if ((await haveNotAnyStyles(sourceDir)) || style.compileMode === false) {
|
|
178
157
|
return;
|
|
179
158
|
}
|
|
180
|
-
|
|
181
159
|
const runner = api.useHookRunners();
|
|
182
160
|
const lessOption = await runner.moduleLessConfig({
|
|
183
161
|
modernConfig
|
|
@@ -195,16 +173,12 @@ export const buildStyle = async (api, config) => {
|
|
|
195
173
|
onLast: async _ => undefined
|
|
196
174
|
});
|
|
197
175
|
const postcssOption = getPostcssOption(appDirectory, modernConfig);
|
|
198
|
-
|
|
199
176
|
if (tailwindPlugin) {
|
|
200
177
|
var _postcssOption$plugin;
|
|
201
|
-
|
|
202
178
|
(_postcssOption$plugin = postcssOption.plugins) === null || _postcssOption$plugin === void 0 ? void 0 : _postcssOption$plugin.push(tailwindPlugin);
|
|
203
179
|
}
|
|
204
|
-
|
|
205
180
|
const srcDir = path.resolve(appDirectory, sourceDir);
|
|
206
181
|
const outputDirToSrc = path.join(appDirectory, distPath, outputPath, (_style$path = style.path) !== null && _style$path !== void 0 ? _style$path : './');
|
|
207
|
-
|
|
208
182
|
if (style.compileMode === 'all' || style.compileMode === 'only-compiled-code') {
|
|
209
183
|
const result = await runBuild({
|
|
210
184
|
appDirectory,
|
|
@@ -215,7 +189,6 @@ export const buildStyle = async (api, config) => {
|
|
|
215
189
|
sassOption,
|
|
216
190
|
postcssOption
|
|
217
191
|
});
|
|
218
|
-
|
|
219
192
|
if (watch) {
|
|
220
193
|
const emitter = result;
|
|
221
194
|
emitter.on(compiler.BuildWatchEvent.firstCompiler, result => {
|
|
@@ -233,7 +206,6 @@ export const buildStyle = async (api, config) => {
|
|
|
233
206
|
});
|
|
234
207
|
}
|
|
235
208
|
}
|
|
236
|
-
|
|
237
209
|
if (style.compileMode === 'all' || style.compileMode === 'only-source-code') {
|
|
238
210
|
if (watch) {
|
|
239
211
|
copyOriginStyleFiles({
|
|
@@ -256,7 +228,6 @@ export const buildStyle = async (api, config) => {
|
|
|
256
228
|
ignoreCSS: style.compileMode === 'all'
|
|
257
229
|
});
|
|
258
230
|
}
|
|
259
|
-
|
|
260
231
|
console.info(watchSectionTitle(titleText, SectionTitleStatus.Success));
|
|
261
232
|
});
|
|
262
233
|
} else {
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
-
|
|
3
2
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
|
|
5
3
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
|
|
7
4
|
import { chalk } from '@modern-js/utils';
|
|
8
5
|
export const clearFlag = '\x1Bc';
|
|
9
6
|
export const buildingText = chalk.blue('Building...');
|
|
@@ -1,5 +1,4 @@
|
|
|
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
|
-
|
|
3
2
|
import { chalk } from '@modern-js/utils';
|
|
4
3
|
export const padSpaceWith = (str, targetL, opts = {}) => {
|
|
5
4
|
const {
|
|
@@ -8,48 +7,39 @@ export const padSpaceWith = (str, targetL, opts = {}) => {
|
|
|
8
7
|
} = opts;
|
|
9
8
|
const l = str.length;
|
|
10
9
|
const endStrL = endStr.length;
|
|
11
|
-
const resetL = targetL - l - endStrL;
|
|
10
|
+
const resetL = targetL - l - endStrL;
|
|
12
11
|
|
|
12
|
+
// str is 'aaa', targetL is 4, result is 'aaa|'
|
|
13
13
|
if (resetL === 0) {
|
|
14
14
|
return (style ? style(str) : str) + endStr;
|
|
15
|
-
}
|
|
16
|
-
|
|
15
|
+
}
|
|
17
16
|
|
|
17
|
+
// str is 'aaa', targetL is 5, result is 'aaa |'
|
|
18
18
|
if (resetL > 0) {
|
|
19
19
|
const padStr = str.padEnd(targetL - 1, ' ');
|
|
20
|
-
|
|
21
20
|
if (style) {
|
|
22
21
|
return style(str) + padStr.replace(str, '') + endStr;
|
|
23
22
|
}
|
|
24
|
-
|
|
25
23
|
return padStr + endStr;
|
|
26
24
|
}
|
|
27
|
-
|
|
28
25
|
return str;
|
|
29
26
|
};
|
|
30
27
|
export class InternalBuildError extends Error {
|
|
31
28
|
constructor(e, opts) {
|
|
32
29
|
super(e.message);
|
|
33
|
-
|
|
34
30
|
_defineProperty(this, "buildType", void 0);
|
|
35
|
-
|
|
36
31
|
_defineProperty(this, "target", void 0);
|
|
37
|
-
|
|
38
32
|
_defineProperty(this, "format", void 0);
|
|
39
|
-
|
|
40
33
|
_defineProperty(this, "e", void 0);
|
|
41
|
-
|
|
42
34
|
Error.captureStackTrace(this, this.constructor);
|
|
43
35
|
this.e = e;
|
|
44
36
|
this.buildType = opts.buildType;
|
|
45
37
|
this.target = opts.target;
|
|
46
38
|
this.format = opts.format;
|
|
47
39
|
}
|
|
48
|
-
|
|
49
40
|
toString() {
|
|
50
41
|
return this.formatError().join('\n');
|
|
51
42
|
}
|
|
52
|
-
|
|
53
43
|
formatError() {
|
|
54
44
|
const msgs = [];
|
|
55
45
|
const {
|
|
@@ -80,25 +70,19 @@ export class InternalBuildError extends Error {
|
|
|
80
70
|
msgs.push(e.stack || '');
|
|
81
71
|
return msgs;
|
|
82
72
|
}
|
|
83
|
-
|
|
84
73
|
}
|
|
85
74
|
export class InternalDTSError extends Error {
|
|
86
75
|
constructor(e, opts) {
|
|
87
76
|
super(e.message);
|
|
88
|
-
|
|
89
77
|
_defineProperty(this, "buildType", void 0);
|
|
90
|
-
|
|
91
78
|
_defineProperty(this, "e", void 0);
|
|
92
|
-
|
|
93
79
|
Error.captureStackTrace(this, this.constructor);
|
|
94
80
|
this.e = e;
|
|
95
81
|
this.buildType = opts.buildType;
|
|
96
82
|
}
|
|
97
|
-
|
|
98
83
|
toString() {
|
|
99
84
|
return this.formatError().join('\n');
|
|
100
85
|
}
|
|
101
|
-
|
|
102
86
|
formatError() {
|
|
103
87
|
const msgs = [];
|
|
104
88
|
const {
|
|
@@ -106,7 +90,6 @@ export class InternalDTSError extends Error {
|
|
|
106
90
|
buildType
|
|
107
91
|
} = this;
|
|
108
92
|
msgs.push(chalk.red.bold(`${buildType} DTS failed:`));
|
|
109
|
-
|
|
110
93
|
if (isExecaError(e)) {
|
|
111
94
|
/**
|
|
112
95
|
* `shortMeessage` content like:
|
|
@@ -115,16 +98,13 @@ export class InternalDTSError extends Error {
|
|
|
115
98
|
*/
|
|
116
99
|
if (e.stack) {
|
|
117
100
|
var _e$stack;
|
|
118
|
-
|
|
119
101
|
msgs.push((_e$stack = e.stack) === null || _e$stack === void 0 ? void 0 : _e$stack.replace(`${e.name}: ${e.shortMessage}`, ''));
|
|
120
102
|
}
|
|
121
103
|
} else {
|
|
122
104
|
msgs.push(e.stack);
|
|
123
105
|
}
|
|
124
|
-
|
|
125
106
|
return msgs;
|
|
126
107
|
}
|
|
127
|
-
|
|
128
108
|
}
|
|
129
109
|
export class ModuleBuildError extends Error {
|
|
130
110
|
constructor(e) {
|
|
@@ -132,19 +112,16 @@ export class ModuleBuildError extends Error {
|
|
|
132
112
|
Error.captureStackTrace(this, this.constructor);
|
|
133
113
|
this.name = 'ModuleBuildError';
|
|
134
114
|
}
|
|
135
|
-
|
|
136
115
|
}
|
|
137
116
|
export const isInternalError = e => {
|
|
138
117
|
if (e instanceof InternalBuildError || e instanceof InternalDTSError) {
|
|
139
118
|
return true;
|
|
140
119
|
}
|
|
141
|
-
|
|
142
120
|
return false;
|
|
143
121
|
};
|
|
144
122
|
export const isExecaError = e => {
|
|
145
123
|
if (e.stdout) {
|
|
146
124
|
return true;
|
|
147
125
|
}
|
|
148
|
-
|
|
149
126
|
return false;
|
|
150
127
|
};
|
|
@@ -15,7 +15,6 @@ export const checkPlatformAndRunBuild = async (platform, options) => {
|
|
|
15
15
|
api,
|
|
16
16
|
isTsProject
|
|
17
17
|
} = options;
|
|
18
|
-
|
|
19
18
|
if (typeof platform === 'boolean' && platform) {
|
|
20
19
|
if (process.env.RUN_PLATFORM) {
|
|
21
20
|
await bp.buildPlatform(api, {
|
|
@@ -23,12 +22,10 @@ export const checkPlatformAndRunBuild = async (platform, options) => {
|
|
|
23
22
|
isTsProject
|
|
24
23
|
});
|
|
25
24
|
}
|
|
26
|
-
|
|
27
25
|
return {
|
|
28
26
|
exit: true
|
|
29
27
|
};
|
|
30
28
|
}
|
|
31
|
-
|
|
32
29
|
if (typeof platform === 'string') {
|
|
33
30
|
if (process.env.RUN_PLATFORM) {
|
|
34
31
|
await bp.buildPlatform(api, {
|
|
@@ -36,12 +33,10 @@ export const checkPlatformAndRunBuild = async (platform, options) => {
|
|
|
36
33
|
isTsProject
|
|
37
34
|
});
|
|
38
35
|
}
|
|
39
|
-
|
|
40
36
|
return {
|
|
41
37
|
exit: true
|
|
42
38
|
};
|
|
43
39
|
}
|
|
44
|
-
|
|
45
40
|
return {
|
|
46
41
|
exit: false
|
|
47
42
|
};
|
|
@@ -57,17 +52,15 @@ export const runBuild = async (api, normalizedModuleConfig, config) => {
|
|
|
57
52
|
};
|
|
58
53
|
export const buildInNormalMode = async (api, normalizedModuleConfig, config) => {
|
|
59
54
|
console.info(chalk.blue.bold(buildingText));
|
|
60
|
-
|
|
61
55
|
try {
|
|
62
56
|
// eslint-disable-next-line no-console
|
|
63
57
|
console.time(buildSuccessText);
|
|
64
58
|
await runBuild(api, normalizedModuleConfig, config);
|
|
65
|
-
ReadlineUtils.clearPrevLine(process.stdout);
|
|
66
|
-
|
|
59
|
+
ReadlineUtils.clearPrevLine(process.stdout);
|
|
60
|
+
// eslint-disable-next-line no-console
|
|
67
61
|
console.timeEnd(buildSuccessText);
|
|
68
62
|
} catch (e) {
|
|
69
63
|
ReadlineUtils.clearPrevLine(process.stdout);
|
|
70
|
-
|
|
71
64
|
if (isInternalError(e)) {
|
|
72
65
|
throw new ModuleBuildError(e);
|
|
73
66
|
} else {
|
|
@@ -90,23 +83,22 @@ export const build = async (api, config) => {
|
|
|
90
83
|
output: {
|
|
91
84
|
path: outputPath = 'dist'
|
|
92
85
|
}
|
|
93
|
-
} = modernConfig;
|
|
86
|
+
} = modernConfig;
|
|
94
87
|
|
|
88
|
+
// build platform
|
|
95
89
|
const platformBuildRet = await checkPlatformAndRunBuild(platform, {
|
|
96
90
|
api,
|
|
97
91
|
isTsProject
|
|
98
92
|
});
|
|
99
|
-
|
|
100
93
|
if (platformBuildRet.exit) {
|
|
101
94
|
return;
|
|
102
95
|
}
|
|
103
|
-
|
|
104
96
|
if (clear) {
|
|
105
97
|
fs.removeSync(path.join(appDirectory, outputPath));
|
|
106
98
|
}
|
|
99
|
+
const deps = getAllDeps(appDirectory);
|
|
107
100
|
|
|
108
|
-
|
|
109
|
-
|
|
101
|
+
// should normalize module tool config here, ensure the same config for build
|
|
110
102
|
const normalizedModuleConfig = normalizeModuleConfig({
|
|
111
103
|
buildFeatOption: config,
|
|
112
104
|
api,
|
|
@@ -116,7 +108,6 @@ export const build = async (api, config) => {
|
|
|
116
108
|
modernConfig,
|
|
117
109
|
appContext
|
|
118
110
|
});
|
|
119
|
-
|
|
120
111
|
if (config.enableWatchMode) {
|
|
121
112
|
console.info(chalk.blue.underline('start build in watch mode...\n'));
|
|
122
113
|
await runBuild(api, normalizedModuleConfig, config);
|
|
@@ -16,8 +16,9 @@ const universalJs = [{
|
|
|
16
16
|
format: 'esm',
|
|
17
17
|
target: 'es6',
|
|
18
18
|
outputPath: './js/modern'
|
|
19
|
-
}];
|
|
19
|
+
}];
|
|
20
20
|
|
|
21
|
+
// Universal JS 的优化选择,两份构建产物,对现代浏览器无优化
|
|
21
22
|
const universalJsLite = [{
|
|
22
23
|
format: 'esm',
|
|
23
24
|
target: 'es5',
|
|
@@ -35,8 +36,9 @@ const universalJsLite = [{
|
|
|
35
36
|
format: 'esm',
|
|
36
37
|
target: 'es5',
|
|
37
38
|
outputPath: './js/modern'
|
|
38
|
-
}];
|
|
39
|
+
}];
|
|
39
40
|
|
|
41
|
+
// 纯前端代码的默认选择,两份构建产物
|
|
40
42
|
const browserJs = [{
|
|
41
43
|
format: 'esm',
|
|
42
44
|
target: 'es5',
|
|
@@ -54,8 +56,9 @@ const browserJs = [{
|
|
|
54
56
|
format: 'esm',
|
|
55
57
|
target: 'es6',
|
|
56
58
|
outputPath: './js/modern'
|
|
57
|
-
}];
|
|
59
|
+
}];
|
|
58
60
|
|
|
61
|
+
// 纯前端代码的优化选择,单份构建产物,对现代浏览器无优化
|
|
59
62
|
const browserJsLite = [{
|
|
60
63
|
format: 'esm',
|
|
61
64
|
target: 'es5',
|
|
@@ -73,8 +76,9 @@ const browserJsLite = [{
|
|
|
73
76
|
format: 'esm',
|
|
74
77
|
target: 'es5',
|
|
75
78
|
outputPath: './js/modern'
|
|
76
|
-
}];
|
|
79
|
+
}];
|
|
77
80
|
|
|
81
|
+
// 纯 Node.js 代码的默认选择,两份构建产物
|
|
78
82
|
const nodeJs = [{
|
|
79
83
|
format: 'cjs',
|
|
80
84
|
target: 'es6',
|
|
@@ -1,5 +1,4 @@
|
|
|
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
|
-
|
|
3
2
|
import { chalk } from '@modern-js/utils';
|
|
4
3
|
export const colors = {
|
|
5
4
|
title: chalk.rgb(218, 152, 92)
|
|
@@ -13,7 +12,6 @@ export const logTemplate = (title, messageStack, {
|
|
|
13
12
|
contentColor: _contentColor = s => s
|
|
14
13
|
} = {}) => {
|
|
15
14
|
const maxLength = Infinity; // TODO: 考虑后面是否提供该参数
|
|
16
|
-
|
|
17
15
|
const leftBorderFlag = _noLeftBorder ? '' : _leftBorder;
|
|
18
16
|
const messageFragments = messageStack.map(p => {
|
|
19
17
|
p.trim();
|
|
@@ -21,7 +19,6 @@ export const logTemplate = (title, messageStack, {
|
|
|
21
19
|
}) // 移除 clearFlag
|
|
22
20
|
.filter(s => s !== leftBorderFlag) // 过滤空字符串
|
|
23
21
|
.slice(0, maxLength); // 控制长度
|
|
24
|
-
|
|
25
22
|
const template = `${colors.title(title)}:
|
|
26
23
|
${_contentColor(messageFragments.join(''))}${_noBottomBorder ? '' : `\n${_bottomBorderText}`}`;
|
|
27
24
|
return template;
|
|
@@ -30,32 +27,24 @@ ${_contentColor(messageFragments.join(''))}${_noBottomBorder ? '' : `\n${_bottom
|
|
|
30
27
|
export class LoggerText {
|
|
31
28
|
constructor(option) {
|
|
32
29
|
_defineProperty(this, "messages", void 0);
|
|
33
|
-
|
|
34
30
|
_defineProperty(this, "hasErrorMessage", void 0);
|
|
35
|
-
|
|
36
31
|
_defineProperty(this, "option", void 0);
|
|
37
|
-
|
|
38
32
|
this.messages = [];
|
|
39
33
|
this.option = option;
|
|
40
34
|
this.hasErrorMessage = false;
|
|
41
35
|
}
|
|
42
|
-
|
|
43
36
|
append(message) {
|
|
44
37
|
if (message.includes(clearFlag)) {
|
|
45
38
|
this.messages = [];
|
|
46
39
|
}
|
|
47
|
-
|
|
48
40
|
this.messages.push(message);
|
|
49
41
|
}
|
|
50
|
-
|
|
51
42
|
errorHappen() {
|
|
52
43
|
this.hasErrorMessage = true;
|
|
53
44
|
}
|
|
54
|
-
|
|
55
45
|
hasMessages() {
|
|
56
46
|
return this.messages.length > 0;
|
|
57
47
|
}
|
|
58
|
-
|
|
59
48
|
get value() {
|
|
60
49
|
const {
|
|
61
50
|
title,
|
|
@@ -64,5 +53,4 @@ export class LoggerText {
|
|
|
64
53
|
const messages = [...new Set(this.messages)];
|
|
65
54
|
return logTemplate(title, messages, contentConfig);
|
|
66
55
|
}
|
|
67
|
-
|
|
68
56
|
}
|