@modern-js/module-tools 1.21.5 → 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 +83 -46
- 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 +14 -19
- 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 +13 -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 +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 +13 -35
- 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 +1 -3
- package/dist/types/hooks/index.d.ts +2 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/schema/types.d.ts +1 -3
- package/dist/types/types.d.ts +0 -1
- package/package.json +20 -44
|
@@ -1,28 +1,22 @@
|
|
|
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 { getBabelConfig, applyUserBabelConfig } from '@modern-js/babel-preset-module';
|
|
9
|
-
import {
|
|
6
|
+
import { getAliasConfig, isUseSSRBundle, applyOptionsChain } from '@modern-js/utils';
|
|
10
7
|
export const getFinalAlias = (modernConfig, option) => {
|
|
11
|
-
const aliasConfig =
|
|
12
|
-
|
|
8
|
+
const aliasConfig = getAliasConfig(modernConfig.source.alias, option);
|
|
9
|
+
// 排除内部别名,因为不需要处理
|
|
13
10
|
const finalPaths = {};
|
|
14
11
|
const internalAliasPrefix = '@modern-js/runtime';
|
|
15
|
-
|
|
16
12
|
if (aliasConfig.paths && typeof aliasConfig.paths === 'object') {
|
|
17
13
|
const pathsKey = Object.keys(aliasConfig.paths);
|
|
18
|
-
|
|
19
14
|
for (const key of pathsKey) {
|
|
20
15
|
if (!key.includes(internalAliasPrefix)) {
|
|
21
16
|
finalPaths[key] = aliasConfig.paths[key];
|
|
22
17
|
}
|
|
23
18
|
}
|
|
24
19
|
}
|
|
25
|
-
|
|
26
20
|
aliasConfig.paths = finalPaths;
|
|
27
21
|
return aliasConfig;
|
|
28
22
|
};
|
|
@@ -40,17 +34,20 @@ export const resolveBabelConfig = (appDirectory, modernConfig, sourceMap, bundle
|
|
|
40
34
|
lodash: userLodashOption,
|
|
41
35
|
styledComponents
|
|
42
36
|
}
|
|
43
|
-
} = modernConfig;
|
|
37
|
+
} = modernConfig;
|
|
44
38
|
|
|
39
|
+
// alias config
|
|
45
40
|
const aliasConfig = getFinalAlias(modernConfig, _objectSpread({
|
|
46
41
|
appDirectory
|
|
47
|
-
}, option));
|
|
42
|
+
}, option));
|
|
48
43
|
|
|
44
|
+
// lodash config
|
|
49
45
|
const lodashOptions = applyOptionsChain({
|
|
50
46
|
id: ['lodash', 'ramda']
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
|
|
47
|
+
},
|
|
48
|
+
// TODO: 需要处理类型问题
|
|
49
|
+
userLodashOption);
|
|
50
|
+
// babel config
|
|
54
51
|
const internalBabelConfig = getBabelConfig({
|
|
55
52
|
appDirectory,
|
|
56
53
|
enableReactPreset: true,
|
|
@@ -73,8 +70,9 @@ export const resolveBabelConfig = (appDirectory, modernConfig, sourceMap, bundle
|
|
|
73
70
|
}, {
|
|
74
71
|
type: option.type,
|
|
75
72
|
syntax: option.syntax
|
|
76
|
-
});
|
|
73
|
+
});
|
|
77
74
|
|
|
75
|
+
// Preventing warning when files are too large
|
|
78
76
|
internalBabelConfig.compact = false;
|
|
79
77
|
internalBabelConfig.sourceMaps = sourceMap === 'external' ? true : sourceMap;
|
|
80
78
|
const userBabelConfig = modernConfig.tools.babel;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
const _excluded = ["glob"];
|
|
2
|
-
|
|
3
2
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
4
|
-
|
|
5
3
|
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
|
-
|
|
7
4
|
import * as path from 'path';
|
|
8
5
|
import { fs, Import, globby, fastGlob, slash } from '@modern-js/utils';
|
|
9
6
|
const normalizePath = Import.lazy('normalize-path', require);
|
|
@@ -23,11 +20,9 @@ export const copyTask = async option => {
|
|
|
23
20
|
}
|
|
24
21
|
} = modernConfig;
|
|
25
22
|
const copyDistDir = path.join(outputPath, jsPath);
|
|
26
|
-
|
|
27
23
|
if (!copy) {
|
|
28
24
|
return;
|
|
29
25
|
}
|
|
30
|
-
|
|
31
26
|
try {
|
|
32
27
|
// 类型暂时这样处理,待之后优化copy的逻辑
|
|
33
28
|
for (const copyOption of copy) {
|
|
@@ -38,11 +33,10 @@ export const copyTask = async option => {
|
|
|
38
33
|
globOptions,
|
|
39
34
|
to: toOrigin
|
|
40
35
|
} = copyOption;
|
|
41
|
-
let fromOrigin = from;
|
|
42
|
-
|
|
36
|
+
let fromOrigin = from;
|
|
37
|
+
// 获取 glob 规则
|
|
43
38
|
let glob = '';
|
|
44
39
|
let options = {};
|
|
45
|
-
|
|
46
40
|
if (fromOrigin !== null && typeof fromOrigin === 'object') {
|
|
47
41
|
var _fromOrigin = fromOrigin;
|
|
48
42
|
({
|
|
@@ -54,20 +48,17 @@ export const copyTask = async option => {
|
|
|
54
48
|
} else if (globOptions && typeof globOptions === 'object') {
|
|
55
49
|
options = globOptions;
|
|
56
50
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
51
|
+
glob = path.isAbsolute(fromOrigin) ? fromOrigin : path.posix.join(fastGlob.escapePath(normalizePath(path.resolve(context))), fromOrigin);
|
|
52
|
+
// 计算 glob,获取目标文件
|
|
60
53
|
const paths = await globby(slash(glob), options);
|
|
61
|
-
|
|
62
54
|
if (!paths.length) {
|
|
63
55
|
return;
|
|
64
56
|
}
|
|
65
|
-
|
|
66
57
|
const to = path.normalize(toOrigin ? toOrigin : '');
|
|
67
58
|
const isToDirectory = path.extname(to) === '';
|
|
68
59
|
paths.forEach(item => {
|
|
69
|
-
const relativeFrom = path.relative(context, item);
|
|
70
|
-
|
|
60
|
+
const relativeFrom = path.relative(context, item);
|
|
61
|
+
// 如果 to 是目录,通过相对路径计算完整的产物路径;如果 to 是文件,直接作为最终产物路径
|
|
71
62
|
const fileName = isToDirectory ? path.join(to, relativeFrom) : to;
|
|
72
63
|
const finalToPath = path.resolve(copyDistDir, fileName);
|
|
73
64
|
fs.copySync(item, finalToPath);
|
|
@@ -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 EventEmitter from 'events';
|
|
4
3
|
import { chalk } from '@modern-js/utils';
|
|
5
4
|
export const clearFlag = '\x1Bc';
|
|
@@ -18,7 +17,6 @@ export const logTemplate = (title, messageStack, maxLength, {
|
|
|
18
17
|
.filter(s => s !== leftBorderFlag) // 过滤空字符串
|
|
19
18
|
.slice(0, maxLength) // 控制长度
|
|
20
19
|
.reverse(); // 调换顺序,最新的消息在最后面
|
|
21
|
-
|
|
22
20
|
messageFragments[messageFragments.length - 1] = messageFragments[messageFragments.length - 1].trim();
|
|
23
21
|
const template = `${title}:
|
|
24
22
|
${_contentColor(messageFragments.join(''))}${_noBottomBorder ? '' : `\n${_bottomBorderText}`}`;
|
|
@@ -28,26 +26,19 @@ ${_contentColor(messageFragments.join(''))}${_noBottomBorder ? '' : `\n${_bottom
|
|
|
28
26
|
export class LoggerText {
|
|
29
27
|
constructor(option) {
|
|
30
28
|
_defineProperty(this, "messages", void 0);
|
|
31
|
-
|
|
32
29
|
_defineProperty(this, "option", void 0);
|
|
33
|
-
|
|
34
30
|
this.messages = [];
|
|
35
31
|
this.option = option;
|
|
36
32
|
}
|
|
37
|
-
|
|
38
33
|
append(message) {
|
|
39
34
|
var _this$option$contentC;
|
|
40
|
-
|
|
41
35
|
const replace = ((_this$option$contentC = this.option.contentConfig) === null || _this$option$contentC === void 0 ? void 0 : _this$option$contentC.replace) || [];
|
|
42
36
|
let content = message;
|
|
43
|
-
|
|
44
37
|
for (const r of replace) {
|
|
45
38
|
content = content.replace(new RegExp(r, 'g'), '');
|
|
46
39
|
}
|
|
47
|
-
|
|
48
40
|
this.messages.push(content);
|
|
49
41
|
}
|
|
50
|
-
|
|
51
42
|
get value() {
|
|
52
43
|
const {
|
|
53
44
|
title,
|
|
@@ -57,14 +48,13 @@ export class LoggerText {
|
|
|
57
48
|
const messages = [...new Set(this.messages)];
|
|
58
49
|
return logTemplate(title, messages, maxLength, contentConfig);
|
|
59
50
|
}
|
|
60
|
-
|
|
61
51
|
}
|
|
62
52
|
export class LoggerManager extends EventEmitter {
|
|
63
53
|
// constructor() {}
|
|
54
|
+
|
|
64
55
|
createLoggerText(option) {
|
|
65
56
|
return new LoggerText(option);
|
|
66
57
|
}
|
|
67
|
-
|
|
68
58
|
addStdout(loggerText, stdout, config = {}) {
|
|
69
59
|
const {
|
|
70
60
|
event = {
|
|
@@ -77,7 +67,6 @@ export class LoggerManager extends EventEmitter {
|
|
|
77
67
|
warning: chalk.yellow
|
|
78
68
|
}
|
|
79
69
|
} = config;
|
|
80
|
-
|
|
81
70
|
if (event.data) {
|
|
82
71
|
stdout === null || stdout === void 0 ? void 0 : stdout.on('data', chunk => {
|
|
83
72
|
const data = chunk.toString();
|
|
@@ -86,7 +75,6 @@ export class LoggerManager extends EventEmitter {
|
|
|
86
75
|
this.emit('data');
|
|
87
76
|
});
|
|
88
77
|
}
|
|
89
|
-
|
|
90
78
|
if (event.error) {
|
|
91
79
|
stdout === null || stdout === void 0 ? void 0 : stdout.on('error', error => {
|
|
92
80
|
const data = error.message;
|
|
@@ -96,16 +84,13 @@ export class LoggerManager extends EventEmitter {
|
|
|
96
84
|
});
|
|
97
85
|
}
|
|
98
86
|
}
|
|
99
|
-
|
|
100
87
|
addStderr(loggerText, stderr) {
|
|
101
88
|
stderr === null || stderr === void 0 ? void 0 : stderr.on('data', chunk => {
|
|
102
89
|
const data = chunk.toString();
|
|
103
90
|
loggerText.append(data);
|
|
104
91
|
});
|
|
105
92
|
}
|
|
106
|
-
|
|
107
93
|
show(loggerText) {
|
|
108
94
|
console.info(loggerText.value);
|
|
109
95
|
}
|
|
110
|
-
|
|
111
96
|
}
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import * as readline from 'readline';
|
|
1
|
+
import * as readline from 'readline';
|
|
2
2
|
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
3
4
|
export class ReadlineUtils {
|
|
4
5
|
static clearPrevLine(output) {
|
|
5
6
|
ReadlineUtils.clearLine(output, 1);
|
|
6
7
|
}
|
|
7
|
-
|
|
8
8
|
static clearLine(output, n = 1, dir = -1) {
|
|
9
9
|
// -1 向上,1 向下
|
|
10
10
|
const dx = dir === 1 ? 1 : -1;
|
|
11
|
-
|
|
12
11
|
for (let i = 0; i < n; i++) {
|
|
13
12
|
readline.moveCursor(output, 0, dx);
|
|
14
13
|
readline.clearLine(output, 0);
|
|
15
14
|
readline.cursorTo(output, 0);
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
|
-
|
|
19
17
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export const defaultTransformedFunctions = ['require', 'require.resolve', 'System.import',
|
|
2
|
-
|
|
1
|
+
export const defaultTransformedFunctions = ['require', 'require.resolve', 'System.import',
|
|
2
|
+
// Jest methods
|
|
3
|
+
'jest.genMockFromModule', 'jest.mock', 'jest.unmock', 'jest.doMock', 'jest.dontMock', 'jest.setMock', 'jest.requireActual', 'jest.requireMock',
|
|
4
|
+
// Older Jest methods
|
|
3
5
|
'require.requireActual', 'require.requireMock'];
|
|
@@ -7,26 +7,20 @@ import { createMatchPath } from '@modern-js/utils/tsconfig-paths';
|
|
|
7
7
|
import { fs } from '@modern-js/utils';
|
|
8
8
|
import { defaultTransformedFunctions } from "./constants";
|
|
9
9
|
import { matchesPattern, isImportCall } from "./utils";
|
|
10
|
-
|
|
11
10
|
const getPathsMap = (paths, sourceDirName = 'src') => {
|
|
12
11
|
const pathKeys = Object.keys(paths);
|
|
13
12
|
const pathsMap = {};
|
|
14
|
-
|
|
15
13
|
const replaceSrcToTypes = s => s.replace(sourceDirName, 'types');
|
|
16
|
-
|
|
17
14
|
for (const key of pathKeys) {
|
|
18
15
|
const p = paths[key];
|
|
19
|
-
|
|
20
16
|
if (typeof p === 'string') {
|
|
21
17
|
pathsMap[key] = [replaceSrcToTypes(p)];
|
|
22
18
|
} else {
|
|
23
19
|
pathsMap[key] = paths[key].map(sp => replaceSrcToTypes(sp));
|
|
24
20
|
}
|
|
25
21
|
}
|
|
26
|
-
|
|
27
22
|
return pathsMap;
|
|
28
23
|
};
|
|
29
|
-
|
|
30
24
|
function mapPathString(nodePath, {
|
|
31
25
|
filename,
|
|
32
26
|
baseUrl,
|
|
@@ -35,7 +29,6 @@ function mapPathString(nodePath, {
|
|
|
35
29
|
if (!t.isStringLiteral(nodePath)) {
|
|
36
30
|
return;
|
|
37
31
|
}
|
|
38
|
-
|
|
39
32
|
const sourcePath = nodePath.node.value;
|
|
40
33
|
const currentFile = filename;
|
|
41
34
|
const pathsMap = getPathsMap(paths);
|
|
@@ -44,37 +37,30 @@ function mapPathString(nodePath, {
|
|
|
44
37
|
if (!fs.existsSync(packageJsonPath)) {
|
|
45
38
|
return undefined;
|
|
46
39
|
}
|
|
47
|
-
|
|
48
40
|
return fs.readJSONSync(packageJsonPath);
|
|
49
41
|
}, filePath => fs.existsSync(filePath), ['.d.ts']);
|
|
50
|
-
|
|
51
42
|
if (result) {
|
|
52
43
|
const relativePath = path.relative(path.dirname(currentFile), path.dirname(result));
|
|
53
|
-
const fileName = path.basename(result);
|
|
54
|
-
|
|
44
|
+
const fileName = path.basename(result);
|
|
45
|
+
// 如果是同级文件,则返回的是 ''
|
|
55
46
|
const filePath = path.normalize(`${relativePath.length === 0 ? '.' : relativePath}/${fileName}`);
|
|
56
47
|
const replaceString = filePath.startsWith('.') ? filePath : `./${filePath}`;
|
|
57
48
|
nodePath.replaceWith(t.stringLiteral(replaceString));
|
|
58
49
|
}
|
|
59
50
|
}
|
|
60
|
-
|
|
61
51
|
const transformCall = option => nodePath => {
|
|
62
52
|
const calleePath = nodePath.get('callee');
|
|
63
53
|
const isNormalCall = defaultTransformedFunctions.some(pattern => matchesPattern(calleePath, pattern));
|
|
64
|
-
|
|
65
54
|
if (isNormalCall || isImportCall(nodePath)) {
|
|
66
55
|
mapPathString(nodePath.get('arguments.0'), option);
|
|
67
56
|
}
|
|
68
57
|
};
|
|
69
|
-
|
|
70
58
|
const transformImport = option => nodePath => {
|
|
71
59
|
mapPathString(nodePath.get('source'), option);
|
|
72
60
|
};
|
|
73
|
-
|
|
74
61
|
const transformExport = option => nodePath => {
|
|
75
62
|
mapPathString(nodePath.get('source'), option);
|
|
76
63
|
};
|
|
77
|
-
|
|
78
64
|
const transformSingleFileAlias = ({
|
|
79
65
|
filename,
|
|
80
66
|
baseUrl,
|
|
@@ -106,7 +92,6 @@ const transformSingleFileAlias = ({
|
|
|
106
92
|
});
|
|
107
93
|
return generator(ast).code;
|
|
108
94
|
};
|
|
109
|
-
|
|
110
95
|
export const transformDtsAlias = option => {
|
|
111
96
|
const {
|
|
112
97
|
filenames = [],
|
|
@@ -114,7 +99,6 @@ export const transformDtsAlias = option => {
|
|
|
114
99
|
paths
|
|
115
100
|
} = option;
|
|
116
101
|
const transformResult = [];
|
|
117
|
-
|
|
118
102
|
for (const filename of filenames) {
|
|
119
103
|
transformResult.push({
|
|
120
104
|
path: filename,
|
|
@@ -125,6 +109,5 @@ export const transformDtsAlias = option => {
|
|
|
125
109
|
})
|
|
126
110
|
});
|
|
127
111
|
}
|
|
128
|
-
|
|
129
112
|
return transformResult;
|
|
130
113
|
};
|
|
@@ -4,15 +4,12 @@ export function matchesPattern(calleePath, pattern) {
|
|
|
4
4
|
const {
|
|
5
5
|
node
|
|
6
6
|
} = calleePath;
|
|
7
|
-
|
|
8
7
|
if (t.isMemberExpression(node)) {
|
|
9
8
|
return calleePath.matchesPattern(pattern);
|
|
10
9
|
}
|
|
11
|
-
|
|
12
10
|
if (!t.isIdentifier(node) || pattern.includes('.')) {
|
|
13
11
|
return false;
|
|
14
12
|
}
|
|
15
|
-
|
|
16
13
|
const name = pattern.split('.')[0];
|
|
17
14
|
return node.name === name;
|
|
18
15
|
}
|
|
@@ -6,23 +6,19 @@ export const valideBeforeTask = ({
|
|
|
6
6
|
const modernConfigValidResult = modernConfigValid(modernConfig, {
|
|
7
7
|
tsconfigPath
|
|
8
8
|
});
|
|
9
|
-
|
|
10
9
|
if (modernConfigValidResult) {
|
|
11
|
-
console.error(modernConfigValidResult);
|
|
12
|
-
|
|
10
|
+
console.error(modernConfigValidResult);
|
|
11
|
+
// eslint-disable-next-line no-process-exit
|
|
13
12
|
process.exit(0);
|
|
14
13
|
}
|
|
15
14
|
};
|
|
16
15
|
export const modernConfigValid = (modernConfig, option) => {
|
|
17
16
|
const valids = [validAlias];
|
|
18
|
-
|
|
19
17
|
for (const validFn of valids) {
|
|
20
18
|
const result = validFn(modernConfig, option);
|
|
21
|
-
|
|
22
19
|
if (result) {
|
|
23
20
|
return result;
|
|
24
21
|
}
|
|
25
22
|
}
|
|
26
|
-
|
|
27
23
|
return null;
|
|
28
24
|
};
|
|
@@ -4,19 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.buildCli = void 0;
|
|
7
|
-
|
|
8
7
|
var _utils = require("@modern-js/utils");
|
|
9
|
-
|
|
10
8
|
const local = _utils.Import.lazy('../locale/index', require);
|
|
11
|
-
|
|
12
9
|
const command = _utils.Import.lazy('../commands/build', require);
|
|
13
|
-
|
|
14
10
|
const buildCli = (program, api) => {
|
|
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))
|
|
11
|
+
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))
|
|
12
|
+
// @deprecated
|
|
16
13
|
// The `--no-tsc` option has been superceded by the `--no-dts` option.
|
|
17
14
|
.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
15
|
await command.build(api, subCommand);
|
|
19
16
|
});
|
|
20
17
|
};
|
|
21
|
-
|
|
22
18
|
exports.buildCli = buildCli;
|
package/dist/js/node/cli/dev.js
CHANGED
|
@@ -4,20 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.devCli = void 0;
|
|
7
|
-
|
|
8
7
|
var _utils = require("@modern-js/utils");
|
|
9
|
-
|
|
10
8
|
const local = _utils.Import.lazy('../locale', require);
|
|
11
|
-
|
|
12
9
|
const commands = _utils.Import.lazy('../commands', require);
|
|
13
|
-
|
|
14
10
|
const devCli = (program, api) => {
|
|
15
11
|
program.command('dev [subCmd]').usage('[options]').description(local.i18n.t(local.localeKeys.command.dev.describe)).option('--tsconfig [tsconfig]', local.i18n.t(local.localeKeys.command.build.tsconfig), './tsconfig.json').action(async (subCmd, params) => {
|
|
16
|
-
await commands.dev(api, params, subCmd);
|
|
17
|
-
|
|
12
|
+
await commands.dev(api, params, subCmd);
|
|
13
|
+
// support plugin-proxy
|
|
18
14
|
const runner = api.useHookRunners();
|
|
19
15
|
await runner.afterDev();
|
|
20
16
|
});
|
|
21
17
|
};
|
|
22
|
-
|
|
23
18
|
exports.devCli = devCli;
|
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
6
|
var _build = require("./build");
|
|
8
|
-
|
|
9
7
|
Object.keys(_build).forEach(function (key) {
|
|
10
8
|
if (key === "default" || key === "__esModule") return;
|
|
11
9
|
if (key in exports && exports[key] === _build[key]) return;
|
|
@@ -16,9 +14,7 @@ Object.keys(_build).forEach(function (key) {
|
|
|
16
14
|
}
|
|
17
15
|
});
|
|
18
16
|
});
|
|
19
|
-
|
|
20
17
|
var _dev = require("./dev");
|
|
21
|
-
|
|
22
18
|
Object.keys(_dev).forEach(function (key) {
|
|
23
19
|
if (key === "default" || key === "__esModule") return;
|
|
24
20
|
if (key in exports && exports[key] === _dev[key]) return;
|
|
@@ -29,9 +25,7 @@ Object.keys(_dev).forEach(function (key) {
|
|
|
29
25
|
}
|
|
30
26
|
});
|
|
31
27
|
});
|
|
32
|
-
|
|
33
28
|
var _new = require("./new");
|
|
34
|
-
|
|
35
29
|
Object.keys(_new).forEach(function (key) {
|
|
36
30
|
if (key === "default" || key === "__esModule") return;
|
|
37
31
|
if (key in exports && exports[key] === _new[key]) return;
|
package/dist/js/node/cli/new.js
CHANGED
|
@@ -4,19 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.newCli = void 0;
|
|
7
|
-
|
|
8
7
|
var _utils = require("@modern-js/utils");
|
|
9
|
-
|
|
10
8
|
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; }
|
|
11
|
-
|
|
12
9
|
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
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; }
|
|
15
|
-
|
|
16
11
|
const newAction = _utils.Import.lazy('@modern-js/new-action', require);
|
|
17
|
-
|
|
18
12
|
const local = _utils.Import.lazy('../locale', require);
|
|
19
|
-
|
|
20
13
|
const newCli = (program, locale) => {
|
|
21
14
|
program.command('new').usage('[options]').description(local.i18n.t(local.localeKeys.command.new.describe)).option('-d, --debug', local.i18n.t(local.localeKeys.command.new.debug), false).option('-c, --config <config>', local.i18n.t(local.localeKeys.command.new.config)).option('--dist-tag <tag>', local.i18n.t(local.localeKeys.command.new.distTag)).option('--registry', local.i18n.t(local.localeKeys.command.new.registry)).action(async options => {
|
|
22
15
|
await newAction.ModuleNewAction(_objectSpread(_objectSpread({}, options), {}, {
|
|
@@ -24,5 +17,4 @@ const newCli = (program, locale) => {
|
|
|
24
17
|
}));
|
|
25
18
|
});
|
|
26
19
|
};
|
|
27
|
-
|
|
28
20
|
exports.newCli = newCli;
|
|
@@ -4,49 +4,34 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.init = exports.build = void 0;
|
|
7
|
-
|
|
8
7
|
var path = _interopRequireWildcard(require("path"));
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
9
|
var _signalExit = _interopRequireDefault(require("signal-exit"));
|
|
13
|
-
|
|
14
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
11
|
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); }
|
|
17
|
-
|
|
18
12
|
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; }
|
|
19
|
-
|
|
20
13
|
const tsConfigutils = _utils.Import.lazy('../utils/tsconfig', require);
|
|
21
|
-
|
|
22
14
|
const valid = _utils.Import.lazy('../utils/valide', require);
|
|
23
|
-
|
|
24
15
|
const buildFeature = _utils.Import.lazy('../features/build', require);
|
|
25
16
|
/**
|
|
26
17
|
* init work before build task.
|
|
27
18
|
* @param api
|
|
28
19
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
20
|
const init = api => {
|
|
32
21
|
const {
|
|
33
22
|
appDirectory
|
|
34
23
|
} = api.useAppContext();
|
|
35
|
-
|
|
36
24
|
_utils.dotenv.config();
|
|
37
|
-
|
|
38
25
|
(0, _signalExit.default)(async code => {
|
|
39
26
|
if (code === 0) {
|
|
40
27
|
return;
|
|
41
28
|
}
|
|
42
|
-
|
|
43
29
|
const tempTsconfigPathPattern = path.join(appDirectory, './node_modules', `./tsconfig.**.**.json`);
|
|
44
30
|
const files = (0, _utils.globby)((0, _utils.slash)(tempTsconfigPathPattern), {
|
|
45
31
|
stats: true,
|
|
46
32
|
absolute: true
|
|
47
33
|
});
|
|
48
34
|
const currentTime = Date.now();
|
|
49
|
-
|
|
50
35
|
for (const file of files) {
|
|
51
36
|
// over 30s, will delete it
|
|
52
37
|
if (currentTime - file.stats.birthtimeMs >= 30 * 1000) {
|
|
@@ -55,12 +40,9 @@ const init = api => {
|
|
|
55
40
|
}
|
|
56
41
|
});
|
|
57
42
|
};
|
|
58
|
-
|
|
59
43
|
exports.init = init;
|
|
60
|
-
|
|
61
44
|
const build = async (api, buildCommandOption) => {
|
|
62
45
|
var _modernConfig$output$;
|
|
63
|
-
|
|
64
46
|
const {
|
|
65
47
|
watch = false,
|
|
66
48
|
tsconfig: tsconfigName,
|
|
@@ -95,5 +77,4 @@ const build = async (api, buildCommandOption) => {
|
|
|
95
77
|
legacyTsc: tsc
|
|
96
78
|
});
|
|
97
79
|
};
|
|
98
|
-
|
|
99
80
|
exports.build = build;
|
|
@@ -4,23 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.dev = void 0;
|
|
7
|
-
|
|
8
7
|
var path = _interopRequireWildcard(require("path"));
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
9
|
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
|
-
|
|
14
10
|
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; }
|
|
15
|
-
|
|
16
11
|
const devFeature = _utils.Import.lazy('../features/dev', require);
|
|
17
|
-
|
|
18
12
|
const tsConfigutils = _utils.Import.lazy('../utils/tsconfig', require);
|
|
19
|
-
|
|
20
13
|
const valid = _utils.Import.lazy('../utils/valide', require);
|
|
21
|
-
|
|
22
14
|
const existSubCmd = subCmd => subCmd.length > 0;
|
|
23
|
-
|
|
24
15
|
const dev = async (api, option, subCmd = '') => {
|
|
25
16
|
const {
|
|
26
17
|
tsconfig: tsconfigName
|
|
@@ -31,24 +22,21 @@ const dev = async (api, option, subCmd = '') => {
|
|
|
31
22
|
appDirectory
|
|
32
23
|
} = appContext;
|
|
33
24
|
const tsconfigPath = path.join(appDirectory, tsconfigName);
|
|
34
|
-
|
|
35
25
|
_utils.dotenv.config();
|
|
36
|
-
|
|
37
26
|
valid.valideBeforeTask({
|
|
38
27
|
modernConfig,
|
|
39
28
|
tsconfigPath
|
|
40
29
|
});
|
|
41
30
|
const isTsProject = tsConfigutils.existTsConfigFile(tsconfigPath);
|
|
42
|
-
|
|
43
31
|
if (existSubCmd(subCmd)) {
|
|
44
32
|
await devFeature.runSubCmd(api, subCmd, {
|
|
45
33
|
isTsProject,
|
|
46
34
|
appDirectory
|
|
47
35
|
});
|
|
48
36
|
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
37
|
+
}
|
|
51
38
|
|
|
39
|
+
// Compatible with the use of jupiter, RUN_PLATFORM is used in jupiter
|
|
52
40
|
if (process.env.RUN_PLATFORM) {
|
|
53
41
|
await devFeature.showMenu(api, {
|
|
54
42
|
isTsProject,
|
|
@@ -61,5 +49,4 @@ const dev = async (api, option, subCmd = '') => {
|
|
|
61
49
|
});
|
|
62
50
|
}
|
|
63
51
|
};
|
|
64
|
-
|
|
65
52
|
exports.dev = dev;
|