@modern-js/module-tools 2.0.0-beta.0 → 2.0.0-beta.2
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 +102 -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 +2 -6
- 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 +6 -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 +11 -11
- package/dist/js/modern/schema/build-config.js +2 -1
- package/dist/js/modern/schema/output.js +16 -10
- package/dist/js/modern/utils/babel.js +17 -15
- 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 +10 -12
- 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 +2 -21
- 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 +6 -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 +12 -36
- 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 +16 -12
- package/dist/js/node/utils/babel.js +17 -23
- 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 +10 -17
- 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/normalize.d.ts +1 -1
- package/dist/types/features/build/utils.d.ts +0 -1
- package/dist/types/hooks/build.d.ts +6 -6
- package/dist/types/hooks/index.d.ts +3 -3
- package/dist/types/index.d.ts +0 -3
- package/dist/types/schema/types.d.ts +1 -3
- package/dist/types/types.d.ts +0 -1
- package/dist/types/utils/babel.d.ts +2 -2
- package/dist/types/utils/valide.d.ts +2 -2
- package/package.json +22 -22
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.padSpaceWith = exports.isInternalError = exports.isExecaError = exports.ModuleBuildError = exports.InternalDTSError = exports.InternalBuildError = void 0;
|
|
7
|
-
|
|
8
7
|
var _utils = require("@modern-js/utils");
|
|
9
|
-
|
|
10
8
|
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
9
|
const padSpaceWith = (str, targetL, opts = {}) => {
|
|
13
10
|
const {
|
|
14
11
|
endStr = '|',
|
|
@@ -16,51 +13,40 @@ const padSpaceWith = (str, targetL, opts = {}) => {
|
|
|
16
13
|
} = opts;
|
|
17
14
|
const l = str.length;
|
|
18
15
|
const endStrL = endStr.length;
|
|
19
|
-
const resetL = targetL - l - endStrL;
|
|
16
|
+
const resetL = targetL - l - endStrL;
|
|
20
17
|
|
|
18
|
+
// str is 'aaa', targetL is 4, result is 'aaa|'
|
|
21
19
|
if (resetL === 0) {
|
|
22
20
|
return (style ? style(str) : str) + endStr;
|
|
23
|
-
}
|
|
24
|
-
|
|
21
|
+
}
|
|
25
22
|
|
|
23
|
+
// str is 'aaa', targetL is 5, result is 'aaa |'
|
|
26
24
|
if (resetL > 0) {
|
|
27
25
|
const padStr = str.padEnd(targetL - 1, ' ');
|
|
28
|
-
|
|
29
26
|
if (style) {
|
|
30
27
|
return style(str) + padStr.replace(str, '') + endStr;
|
|
31
28
|
}
|
|
32
|
-
|
|
33
29
|
return padStr + endStr;
|
|
34
30
|
}
|
|
35
|
-
|
|
36
31
|
return str;
|
|
37
32
|
};
|
|
38
|
-
|
|
39
33
|
exports.padSpaceWith = padSpaceWith;
|
|
40
|
-
|
|
41
34
|
class InternalBuildError extends Error {
|
|
42
35
|
constructor(e, opts) {
|
|
43
36
|
super(e.message);
|
|
44
|
-
|
|
45
37
|
_defineProperty(this, "buildType", void 0);
|
|
46
|
-
|
|
47
38
|
_defineProperty(this, "target", void 0);
|
|
48
|
-
|
|
49
39
|
_defineProperty(this, "format", void 0);
|
|
50
|
-
|
|
51
40
|
_defineProperty(this, "e", void 0);
|
|
52
|
-
|
|
53
41
|
Error.captureStackTrace(this, this.constructor);
|
|
54
42
|
this.e = e;
|
|
55
43
|
this.buildType = opts.buildType;
|
|
56
44
|
this.target = opts.target;
|
|
57
45
|
this.format = opts.format;
|
|
58
46
|
}
|
|
59
|
-
|
|
60
47
|
toString() {
|
|
61
48
|
return this.formatError().join('\n');
|
|
62
49
|
}
|
|
63
|
-
|
|
64
50
|
formatError() {
|
|
65
51
|
const msgs = [];
|
|
66
52
|
const {
|
|
@@ -91,28 +77,20 @@ class InternalBuildError extends Error {
|
|
|
91
77
|
msgs.push(e.stack || '');
|
|
92
78
|
return msgs;
|
|
93
79
|
}
|
|
94
|
-
|
|
95
80
|
}
|
|
96
|
-
|
|
97
81
|
exports.InternalBuildError = InternalBuildError;
|
|
98
|
-
|
|
99
82
|
class InternalDTSError extends Error {
|
|
100
83
|
constructor(e, opts) {
|
|
101
84
|
super(e.message);
|
|
102
|
-
|
|
103
85
|
_defineProperty(this, "buildType", void 0);
|
|
104
|
-
|
|
105
86
|
_defineProperty(this, "e", void 0);
|
|
106
|
-
|
|
107
87
|
Error.captureStackTrace(this, this.constructor);
|
|
108
88
|
this.e = e;
|
|
109
89
|
this.buildType = opts.buildType;
|
|
110
90
|
}
|
|
111
|
-
|
|
112
91
|
toString() {
|
|
113
92
|
return this.formatError().join('\n');
|
|
114
93
|
}
|
|
115
|
-
|
|
116
94
|
formatError() {
|
|
117
95
|
const msgs = [];
|
|
118
96
|
const {
|
|
@@ -120,7 +98,6 @@ class InternalDTSError extends Error {
|
|
|
120
98
|
buildType
|
|
121
99
|
} = this;
|
|
122
100
|
msgs.push(_utils.chalk.red.bold(`${buildType} DTS failed:`));
|
|
123
|
-
|
|
124
101
|
if (isExecaError(e)) {
|
|
125
102
|
/**
|
|
126
103
|
* `shortMeessage` content like:
|
|
@@ -129,47 +106,34 @@ class InternalDTSError extends Error {
|
|
|
129
106
|
*/
|
|
130
107
|
if (e.stack) {
|
|
131
108
|
var _e$stack;
|
|
132
|
-
|
|
133
109
|
msgs.push((_e$stack = e.stack) === null || _e$stack === void 0 ? void 0 : _e$stack.replace(`${e.name}: ${e.shortMessage}`, ''));
|
|
134
110
|
}
|
|
135
111
|
} else {
|
|
136
112
|
msgs.push(e.stack);
|
|
137
113
|
}
|
|
138
|
-
|
|
139
114
|
return msgs;
|
|
140
115
|
}
|
|
141
|
-
|
|
142
116
|
}
|
|
143
|
-
|
|
144
117
|
exports.InternalDTSError = InternalDTSError;
|
|
145
|
-
|
|
146
118
|
class ModuleBuildError extends Error {
|
|
147
119
|
constructor(e) {
|
|
148
120
|
super(`\n\n${e}`);
|
|
149
121
|
Error.captureStackTrace(this, this.constructor);
|
|
150
122
|
this.name = 'ModuleBuildError';
|
|
151
123
|
}
|
|
152
|
-
|
|
153
124
|
}
|
|
154
|
-
|
|
155
125
|
exports.ModuleBuildError = ModuleBuildError;
|
|
156
|
-
|
|
157
126
|
const isInternalError = e => {
|
|
158
127
|
if (e instanceof InternalBuildError || e instanceof InternalDTSError) {
|
|
159
128
|
return true;
|
|
160
129
|
}
|
|
161
|
-
|
|
162
130
|
return false;
|
|
163
131
|
};
|
|
164
|
-
|
|
165
132
|
exports.isInternalError = isInternalError;
|
|
166
|
-
|
|
167
133
|
const isExecaError = e => {
|
|
168
134
|
if (e.stdout) {
|
|
169
135
|
return true;
|
|
170
136
|
}
|
|
171
|
-
|
|
172
137
|
return false;
|
|
173
138
|
};
|
|
174
|
-
|
|
175
139
|
exports.isExecaError = isExecaError;
|
|
@@ -4,39 +4,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.runBuild = exports.checkPlatformAndRunBuild = exports.buildInNormalMode = exports.build = void 0;
|
|
7
|
-
|
|
8
7
|
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
9
|
var _pMap = _interopRequireDefault(require("p-map"));
|
|
13
|
-
|
|
14
10
|
var _readline = require("../../utils/readline");
|
|
15
|
-
|
|
16
11
|
var _normalize = require("./normalize");
|
|
17
|
-
|
|
18
12
|
var _constants = require("./constants");
|
|
19
|
-
|
|
20
13
|
var _error = require("./error");
|
|
21
|
-
|
|
22
14
|
var _utils2 = require("./utils");
|
|
23
|
-
|
|
24
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
-
|
|
26
16
|
const bundle = _utils.Import.lazy('./bundle', require);
|
|
27
|
-
|
|
28
17
|
const bundleless = _utils.Import.lazy('./bundleless', require);
|
|
29
|
-
|
|
30
18
|
const bp = _utils.Import.lazy('./build-platform', require);
|
|
31
|
-
|
|
32
19
|
const copyUtils = _utils.Import.lazy('../../utils/copy', require);
|
|
33
|
-
|
|
34
20
|
const checkPlatformAndRunBuild = async (platform, options) => {
|
|
35
21
|
const {
|
|
36
22
|
api,
|
|
37
23
|
isTsProject
|
|
38
24
|
} = options;
|
|
39
|
-
|
|
40
25
|
if (typeof platform === 'boolean' && platform) {
|
|
41
26
|
if (process.env.RUN_PLATFORM) {
|
|
42
27
|
await bp.buildPlatform(api, {
|
|
@@ -44,12 +29,10 @@ const checkPlatformAndRunBuild = async (platform, options) => {
|
|
|
44
29
|
isTsProject
|
|
45
30
|
});
|
|
46
31
|
}
|
|
47
|
-
|
|
48
32
|
return {
|
|
49
33
|
exit: true
|
|
50
34
|
};
|
|
51
35
|
}
|
|
52
|
-
|
|
53
36
|
if (typeof platform === 'string') {
|
|
54
37
|
if (process.env.RUN_PLATFORM) {
|
|
55
38
|
await bp.buildPlatform(api, {
|
|
@@ -57,19 +40,15 @@ const checkPlatformAndRunBuild = async (platform, options) => {
|
|
|
57
40
|
isTsProject
|
|
58
41
|
});
|
|
59
42
|
}
|
|
60
|
-
|
|
61
43
|
return {
|
|
62
44
|
exit: true
|
|
63
45
|
};
|
|
64
46
|
}
|
|
65
|
-
|
|
66
47
|
return {
|
|
67
48
|
exit: false
|
|
68
49
|
};
|
|
69
50
|
};
|
|
70
|
-
|
|
71
51
|
exports.checkPlatformAndRunBuild = checkPlatformAndRunBuild;
|
|
72
|
-
|
|
73
52
|
const runBuild = async (api, normalizedModuleConfig, config) => {
|
|
74
53
|
await (0, _pMap.default)(normalizedModuleConfig, async moduleConfig => {
|
|
75
54
|
if (moduleConfig.buildType === 'bundle') {
|
|
@@ -79,24 +58,18 @@ const runBuild = async (api, normalizedModuleConfig, config) => {
|
|
|
79
58
|
}
|
|
80
59
|
});
|
|
81
60
|
};
|
|
82
|
-
|
|
83
61
|
exports.runBuild = runBuild;
|
|
84
|
-
|
|
85
62
|
const buildInNormalMode = async (api, normalizedModuleConfig, config) => {
|
|
86
63
|
console.info(_utils.chalk.blue.bold(_constants.buildingText));
|
|
87
|
-
|
|
88
64
|
try {
|
|
89
65
|
// eslint-disable-next-line no-console
|
|
90
66
|
console.time(_constants.buildSuccessText);
|
|
91
67
|
await runBuild(api, normalizedModuleConfig, config);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
68
|
+
_readline.ReadlineUtils.clearPrevLine(process.stdout);
|
|
69
|
+
// eslint-disable-next-line no-console
|
|
96
70
|
console.timeEnd(_constants.buildSuccessText);
|
|
97
71
|
} catch (e) {
|
|
98
72
|
_readline.ReadlineUtils.clearPrevLine(process.stdout);
|
|
99
|
-
|
|
100
73
|
if ((0, _error.isInternalError)(e)) {
|
|
101
74
|
throw new _error.ModuleBuildError(e);
|
|
102
75
|
} else {
|
|
@@ -104,9 +77,7 @@ const buildInNormalMode = async (api, normalizedModuleConfig, config) => {
|
|
|
104
77
|
}
|
|
105
78
|
}
|
|
106
79
|
};
|
|
107
|
-
|
|
108
80
|
exports.buildInNormalMode = buildInNormalMode;
|
|
109
|
-
|
|
110
81
|
const build = async (api, config) => {
|
|
111
82
|
const {
|
|
112
83
|
platform,
|
|
@@ -122,23 +93,22 @@ const build = async (api, config) => {
|
|
|
122
93
|
output: {
|
|
123
94
|
path: outputPath = 'dist'
|
|
124
95
|
}
|
|
125
|
-
} = modernConfig;
|
|
96
|
+
} = modernConfig;
|
|
126
97
|
|
|
98
|
+
// build platform
|
|
127
99
|
const platformBuildRet = await checkPlatformAndRunBuild(platform, {
|
|
128
100
|
api,
|
|
129
101
|
isTsProject
|
|
130
102
|
});
|
|
131
|
-
|
|
132
103
|
if (platformBuildRet.exit) {
|
|
133
104
|
return;
|
|
134
105
|
}
|
|
135
|
-
|
|
136
106
|
if (clear) {
|
|
137
107
|
_utils.fs.removeSync(_path.default.join(appDirectory, outputPath));
|
|
138
108
|
}
|
|
109
|
+
const deps = (0, _utils2.getAllDeps)(appDirectory);
|
|
139
110
|
|
|
140
|
-
|
|
141
|
-
|
|
111
|
+
// should normalize module tool config here, ensure the same config for build
|
|
142
112
|
const normalizedModuleConfig = (0, _normalize.normalizeModuleConfig)({
|
|
143
113
|
buildFeatOption: config,
|
|
144
114
|
api,
|
|
@@ -148,7 +118,6 @@ const build = async (api, config) => {
|
|
|
148
118
|
modernConfig,
|
|
149
119
|
appContext
|
|
150
120
|
});
|
|
151
|
-
|
|
152
121
|
if (config.enableWatchMode) {
|
|
153
122
|
console.info(_utils.chalk.blue.underline('start build in watch mode...\n'));
|
|
154
123
|
await runBuild(api, normalizedModuleConfig, config);
|
|
@@ -156,5 +125,4 @@ const build = async (api, config) => {
|
|
|
156
125
|
await buildInNormalMode(api, normalizedModuleConfig, config);
|
|
157
126
|
}
|
|
158
127
|
};
|
|
159
|
-
|
|
160
128
|
exports.build = build;
|
|
@@ -22,8 +22,9 @@ const universalJs = [{
|
|
|
22
22
|
format: 'esm',
|
|
23
23
|
target: 'es6',
|
|
24
24
|
outputPath: './js/modern'
|
|
25
|
-
}];
|
|
25
|
+
}];
|
|
26
26
|
|
|
27
|
+
// Universal JS 的优化选择,两份构建产物,对现代浏览器无优化
|
|
27
28
|
const universalJsLite = [{
|
|
28
29
|
format: 'esm',
|
|
29
30
|
target: 'es5',
|
|
@@ -41,8 +42,9 @@ const universalJsLite = [{
|
|
|
41
42
|
format: 'esm',
|
|
42
43
|
target: 'es5',
|
|
43
44
|
outputPath: './js/modern'
|
|
44
|
-
}];
|
|
45
|
+
}];
|
|
45
46
|
|
|
47
|
+
// 纯前端代码的默认选择,两份构建产物
|
|
46
48
|
const browserJs = [{
|
|
47
49
|
format: 'esm',
|
|
48
50
|
target: 'es5',
|
|
@@ -60,8 +62,9 @@ const browserJs = [{
|
|
|
60
62
|
format: 'esm',
|
|
61
63
|
target: 'es6',
|
|
62
64
|
outputPath: './js/modern'
|
|
63
|
-
}];
|
|
65
|
+
}];
|
|
64
66
|
|
|
67
|
+
// 纯前端代码的优化选择,单份构建产物,对现代浏览器无优化
|
|
65
68
|
const browserJsLite = [{
|
|
66
69
|
format: 'esm',
|
|
67
70
|
target: 'es5',
|
|
@@ -79,8 +82,9 @@ const browserJsLite = [{
|
|
|
79
82
|
format: 'esm',
|
|
80
83
|
target: 'es5',
|
|
81
84
|
outputPath: './js/modern'
|
|
82
|
-
}];
|
|
85
|
+
}];
|
|
83
86
|
|
|
87
|
+
// 纯 Node.js 代码的默认选择,两份构建产物
|
|
84
88
|
const nodeJs = [{
|
|
85
89
|
format: 'cjs',
|
|
86
90
|
target: 'es6',
|
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
6
|
var _logText = require("./logText");
|
|
8
|
-
|
|
9
7
|
Object.keys(_logText).forEach(function (key) {
|
|
10
8
|
if (key === "default" || key === "__esModule") return;
|
|
11
9
|
if (key in exports && exports[key] === _logText[key]) return;
|
|
@@ -16,9 +14,7 @@ Object.keys(_logText).forEach(function (key) {
|
|
|
16
14
|
}
|
|
17
15
|
});
|
|
18
16
|
});
|
|
19
|
-
|
|
20
17
|
var _loggerManager = require("./loggerManager");
|
|
21
|
-
|
|
22
18
|
Object.keys(_loggerManager).forEach(function (key) {
|
|
23
19
|
if (key === "default" || key === "__esModule") return;
|
|
24
20
|
if (key in exports && exports[key] === _loggerManager[key]) return;
|
|
@@ -4,18 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.logTemplate = exports.colors = exports.clearFlag = exports.LoggerText = void 0;
|
|
7
|
-
|
|
8
7
|
var _utils = require("@modern-js/utils");
|
|
9
|
-
|
|
10
8
|
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
9
|
const colors = {
|
|
13
10
|
title: _utils.chalk.rgb(218, 152, 92)
|
|
14
11
|
};
|
|
15
12
|
exports.colors = colors;
|
|
16
13
|
const clearFlag = '\x1Bc';
|
|
17
14
|
exports.clearFlag = clearFlag;
|
|
18
|
-
|
|
19
15
|
const logTemplate = (title, messageStack, {
|
|
20
16
|
noBottomBorder: _noBottomBorder = false,
|
|
21
17
|
bottomBorderText: _bottomBorderText = '',
|
|
@@ -24,7 +20,6 @@ const logTemplate = (title, messageStack, {
|
|
|
24
20
|
contentColor: _contentColor = s => s
|
|
25
21
|
} = {}) => {
|
|
26
22
|
const maxLength = Infinity; // TODO: 考虑后面是否提供该参数
|
|
27
|
-
|
|
28
23
|
const leftBorderFlag = _noLeftBorder ? '' : _leftBorder;
|
|
29
24
|
const messageFragments = messageStack.map(p => {
|
|
30
25
|
p.trim();
|
|
@@ -32,44 +27,33 @@ const logTemplate = (title, messageStack, {
|
|
|
32
27
|
}) // 移除 clearFlag
|
|
33
28
|
.filter(s => s !== leftBorderFlag) // 过滤空字符串
|
|
34
29
|
.slice(0, maxLength); // 控制长度
|
|
35
|
-
|
|
36
30
|
const template = `${colors.title(title)}:
|
|
37
31
|
${_contentColor(messageFragments.join(''))}${_noBottomBorder ? '' : `\n${_bottomBorderText}`}`;
|
|
38
32
|
return template;
|
|
39
33
|
};
|
|
40
|
-
|
|
41
34
|
exports.logTemplate = logTemplate;
|
|
42
|
-
|
|
43
35
|
// 处理Log内容如何展示
|
|
44
36
|
class LoggerText {
|
|
45
37
|
constructor(option) {
|
|
46
38
|
_defineProperty(this, "messages", void 0);
|
|
47
|
-
|
|
48
39
|
_defineProperty(this, "hasErrorMessage", void 0);
|
|
49
|
-
|
|
50
40
|
_defineProperty(this, "option", void 0);
|
|
51
|
-
|
|
52
41
|
this.messages = [];
|
|
53
42
|
this.option = option;
|
|
54
43
|
this.hasErrorMessage = false;
|
|
55
44
|
}
|
|
56
|
-
|
|
57
45
|
append(message) {
|
|
58
46
|
if (message.includes(clearFlag)) {
|
|
59
47
|
this.messages = [];
|
|
60
48
|
}
|
|
61
|
-
|
|
62
49
|
this.messages.push(message);
|
|
63
50
|
}
|
|
64
|
-
|
|
65
51
|
errorHappen() {
|
|
66
52
|
this.hasErrorMessage = true;
|
|
67
53
|
}
|
|
68
|
-
|
|
69
54
|
hasMessages() {
|
|
70
55
|
return this.messages.length > 0;
|
|
71
56
|
}
|
|
72
|
-
|
|
73
57
|
get value() {
|
|
74
58
|
const {
|
|
75
59
|
title,
|
|
@@ -78,7 +62,5 @@ class LoggerText {
|
|
|
78
62
|
const messages = [...new Set(this.messages)];
|
|
79
63
|
return logTemplate(title, messages, contentConfig);
|
|
80
64
|
}
|
|
81
|
-
|
|
82
65
|
}
|
|
83
|
-
|
|
84
66
|
exports.LoggerText = LoggerText;
|
|
@@ -4,38 +4,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.LoggerManager = void 0;
|
|
7
|
-
|
|
8
7
|
var _events = _interopRequireDefault(require("events"));
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
9
|
let _ = t => t,
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
_t;
|
|
15
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
|
|
17
12
|
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; }
|
|
18
|
-
|
|
19
13
|
const logText = _utils.Import.lazy('./logText', require);
|
|
20
|
-
|
|
21
14
|
const readline = _utils.Import.lazy('../../../utils/readline', require);
|
|
22
|
-
|
|
23
15
|
class LoggerManager extends _events.default {
|
|
24
16
|
constructor() {
|
|
25
17
|
super();
|
|
26
|
-
|
|
27
18
|
_defineProperty(this, "_compilering", void 0);
|
|
28
|
-
|
|
29
19
|
_defineProperty(this, "_listeners", void 0);
|
|
30
|
-
|
|
31
20
|
this._compilering = false;
|
|
32
21
|
this._listeners = [];
|
|
33
22
|
}
|
|
34
|
-
|
|
35
23
|
createLoggerText(option) {
|
|
36
24
|
return new logText.LoggerText(option);
|
|
37
25
|
}
|
|
38
|
-
|
|
39
26
|
addStdout(loggerText, stdout, config = {}) {
|
|
40
27
|
const {
|
|
41
28
|
event = {
|
|
@@ -48,7 +35,6 @@ class LoggerManager extends _events.default {
|
|
|
48
35
|
warning: _utils.chalk.yellow
|
|
49
36
|
}
|
|
50
37
|
} = config;
|
|
51
|
-
|
|
52
38
|
if (event.data) {
|
|
53
39
|
stdout === null || stdout === void 0 ? void 0 : stdout.on('data', chunk => {
|
|
54
40
|
const data = chunk.toString();
|
|
@@ -57,7 +43,6 @@ class LoggerManager extends _events.default {
|
|
|
57
43
|
this.emit('data');
|
|
58
44
|
});
|
|
59
45
|
}
|
|
60
|
-
|
|
61
46
|
if (event.error) {
|
|
62
47
|
stdout === null || stdout === void 0 ? void 0 : stdout.on('error', error => {
|
|
63
48
|
console.info('error');
|
|
@@ -68,10 +53,8 @@ class LoggerManager extends _events.default {
|
|
|
68
53
|
this.emit('data');
|
|
69
54
|
});
|
|
70
55
|
}
|
|
71
|
-
|
|
72
56
|
this._listeners.push(stdout);
|
|
73
57
|
}
|
|
74
|
-
|
|
75
58
|
addStderr(loggerText, stderr, color = _utils.chalk.red) {
|
|
76
59
|
stderr === null || stderr === void 0 ? void 0 : stderr.on('data', chunk => {
|
|
77
60
|
const data = chunk.toString();
|
|
@@ -80,29 +63,27 @@ class LoggerManager extends _events.default {
|
|
|
80
63
|
this.emit('data');
|
|
81
64
|
});
|
|
82
65
|
}
|
|
83
|
-
|
|
84
66
|
showCompiling() {
|
|
85
67
|
if (!this._compilering) {
|
|
86
68
|
this._compilering = true;
|
|
87
69
|
console.info(_utils.chalk.green(_t || (_t = _`Compiling in progress...`)));
|
|
88
70
|
}
|
|
89
71
|
}
|
|
90
|
-
|
|
91
72
|
disappearCompiling() {
|
|
92
73
|
if (this._compilering) {
|
|
93
74
|
readline.ReadlineUtils.clearLine(process.stdout);
|
|
94
75
|
this._compilering = false;
|
|
95
76
|
}
|
|
96
77
|
}
|
|
97
|
-
|
|
98
|
-
|
|
78
|
+
listenDateAndShow(logTexts
|
|
79
|
+
// stdout: NodeJS.WriteStream & {
|
|
99
80
|
// fd: 1;
|
|
100
81
|
// } = process.stdout,
|
|
101
82
|
) {
|
|
102
83
|
this.on('data', () => {
|
|
103
84
|
this.disappearCompiling();
|
|
104
|
-
const content = logTexts.map(logtext => logtext.value).join('');
|
|
105
|
-
|
|
85
|
+
const content = logTexts.map(logtext => logtext.value).join('');
|
|
86
|
+
// 每次更新,使用新的内容覆盖旧的内容,有几率出现内容错乱问题
|
|
106
87
|
console.info(content);
|
|
107
88
|
});
|
|
108
89
|
return () => {
|
|
@@ -110,7 +91,5 @@ class LoggerManager extends _events.default {
|
|
|
110
91
|
process.exit(0);
|
|
111
92
|
};
|
|
112
93
|
}
|
|
113
|
-
|
|
114
94
|
}
|
|
115
|
-
|
|
116
95
|
exports.LoggerManager = LoggerManager;
|