@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,13 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.addSchema = void 0;
|
|
7
|
-
|
|
8
7
|
var _source = require("./source");
|
|
9
|
-
|
|
10
8
|
var _output = require("./output");
|
|
11
|
-
|
|
12
9
|
var _tools = require("./tools");
|
|
13
|
-
|
|
14
10
|
const addSchema = () => [..._source.sourceSchema, ..._output.outputSchema, ..._tools.toolsSchema];
|
|
15
|
-
|
|
16
11
|
exports.addSchema = addSchema;
|
|
@@ -4,45 +4,49 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.outputSchema = void 0;
|
|
7
|
-
|
|
8
7
|
var _buildConfig = require("./build-config");
|
|
9
|
-
|
|
10
8
|
const PACKAGE_MODE_LIST = ['universal-js', 'universal-js-lite', 'browser-js', 'browser-js-lite', 'node-js'];
|
|
11
|
-
const outputSchema = [
|
|
12
|
-
/** packageMode will deprecated */
|
|
9
|
+
const outputSchema = [/** packageMode will deprecated */
|
|
13
10
|
{
|
|
14
11
|
target: 'output.packageMode',
|
|
15
12
|
schema: {
|
|
16
13
|
enum: PACKAGE_MODE_LIST
|
|
17
14
|
}
|
|
18
|
-
},
|
|
19
|
-
/** packageFields will deprecated */
|
|
15
|
+
}, /** packageFields will deprecated */
|
|
20
16
|
{
|
|
21
17
|
target: 'output.packageFields',
|
|
22
18
|
schema: {
|
|
23
19
|
typeof: 'object'
|
|
24
20
|
}
|
|
25
|
-
},
|
|
26
|
-
/** enableSourceMap will deprecated */
|
|
21
|
+
}, /** enableSourceMap will deprecated */
|
|
27
22
|
{
|
|
28
23
|
target: 'output.enableSourceMap',
|
|
29
24
|
schema: {
|
|
30
25
|
typeof: 'boolean'
|
|
31
26
|
}
|
|
32
|
-
},
|
|
33
|
-
/** importStyle will deprecated */
|
|
27
|
+
}, /** importStyle will deprecated */
|
|
34
28
|
{
|
|
35
29
|
target: 'output.importStyle',
|
|
36
30
|
schema: {
|
|
37
31
|
enum: ['compiled-code', 'source-code']
|
|
38
32
|
}
|
|
39
|
-
},
|
|
40
|
-
/** assetsPath will deprecated */
|
|
33
|
+
}, /** assetsPath will deprecated */
|
|
41
34
|
{
|
|
42
35
|
target: 'output.assetsPath',
|
|
43
36
|
schema: {
|
|
44
37
|
typeof: 'string',
|
|
45
38
|
default: 'styles'
|
|
46
39
|
}
|
|
40
|
+
}, {
|
|
41
|
+
target: 'output.jsPath',
|
|
42
|
+
schema: {
|
|
43
|
+
typeof: 'string',
|
|
44
|
+
default: ''
|
|
45
|
+
}
|
|
46
|
+
}, {
|
|
47
|
+
target: 'output.disableSourceMap',
|
|
48
|
+
schema: {
|
|
49
|
+
typeof: 'boolean'
|
|
50
|
+
}
|
|
47
51
|
}, ..._buildConfig.buildSchema];
|
|
48
52
|
exports.outputSchema = outputSchema;
|
|
@@ -4,44 +4,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.resolveBabelConfig = exports.getFinalAlias = void 0;
|
|
7
|
-
|
|
8
7
|
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
8
|
var _babelPresetModule = require("@modern-js/babel-preset-module");
|
|
11
|
-
|
|
12
9
|
var _utils = require("@modern-js/utils");
|
|
13
|
-
|
|
14
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
11
|
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; }
|
|
17
|
-
|
|
18
12
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
19
|
-
|
|
20
13
|
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; }
|
|
21
|
-
|
|
22
14
|
const getFinalAlias = (modernConfig, option) => {
|
|
23
|
-
const aliasConfig = (0, _utils.getAliasConfig)(modernConfig.source.alias, option);
|
|
24
|
-
|
|
15
|
+
const aliasConfig = (0, _utils.getAliasConfig)(modernConfig.source.alias, option);
|
|
16
|
+
// 排除内部别名,因为不需要处理
|
|
25
17
|
const finalPaths = {};
|
|
26
18
|
const internalAliasPrefix = '@modern-js/runtime';
|
|
27
|
-
|
|
28
19
|
if (aliasConfig.paths && typeof aliasConfig.paths === 'object') {
|
|
29
20
|
const pathsKey = Object.keys(aliasConfig.paths);
|
|
30
|
-
|
|
31
21
|
for (const key of pathsKey) {
|
|
32
22
|
if (!key.includes(internalAliasPrefix)) {
|
|
33
23
|
finalPaths[key] = aliasConfig.paths[key];
|
|
34
24
|
}
|
|
35
25
|
}
|
|
36
26
|
}
|
|
37
|
-
|
|
38
27
|
aliasConfig.paths = finalPaths;
|
|
39
28
|
return aliasConfig;
|
|
40
29
|
};
|
|
41
|
-
|
|
42
30
|
exports.getFinalAlias = getFinalAlias;
|
|
43
|
-
|
|
44
31
|
const resolveBabelConfig = (appDirectory, modernConfig, sourceMap, bundlelessOptions, option) => {
|
|
32
|
+
var _modernConfig$tools;
|
|
45
33
|
const {
|
|
46
34
|
source: {
|
|
47
35
|
envVars,
|
|
@@ -54,18 +42,24 @@ const resolveBabelConfig = (appDirectory, modernConfig, sourceMap, bundlelessOpt
|
|
|
54
42
|
tools: {
|
|
55
43
|
lodash: userLodashOption,
|
|
56
44
|
styledComponents
|
|
45
|
+
} = {
|
|
46
|
+
lodash: {},
|
|
47
|
+
styledComponents: {}
|
|
57
48
|
}
|
|
58
|
-
} = modernConfig;
|
|
49
|
+
} = modernConfig;
|
|
59
50
|
|
|
51
|
+
// alias config
|
|
60
52
|
const aliasConfig = getFinalAlias(modernConfig, _objectSpread({
|
|
61
53
|
appDirectory
|
|
62
|
-
}, option));
|
|
54
|
+
}, option));
|
|
63
55
|
|
|
56
|
+
// lodash config
|
|
64
57
|
const lodashOptions = (0, _utils.applyOptionsChain)({
|
|
65
58
|
id: ['lodash', 'ramda']
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
},
|
|
60
|
+
// TODO: 需要处理类型问题
|
|
61
|
+
userLodashOption || {});
|
|
62
|
+
// babel config
|
|
69
63
|
const internalBabelConfig = (0, _babelPresetModule.getBabelConfig)({
|
|
70
64
|
appDirectory,
|
|
71
65
|
enableReactPreset: true,
|
|
@@ -88,12 +82,12 @@ const resolveBabelConfig = (appDirectory, modernConfig, sourceMap, bundlelessOpt
|
|
|
88
82
|
}, {
|
|
89
83
|
type: option.type,
|
|
90
84
|
syntax: option.syntax
|
|
91
|
-
});
|
|
85
|
+
});
|
|
92
86
|
|
|
87
|
+
// Preventing warning when files are too large
|
|
93
88
|
internalBabelConfig.compact = false;
|
|
94
89
|
internalBabelConfig.sourceMaps = sourceMap === 'external' ? true : sourceMap;
|
|
95
|
-
const userBabelConfig = modernConfig.tools.babel;
|
|
90
|
+
const userBabelConfig = (_modernConfig$tools = modernConfig.tools) === null || _modernConfig$tools === void 0 ? void 0 : _modernConfig$tools.babel;
|
|
96
91
|
return (0, _babelPresetModule.applyUserBabelConfig)(internalBabelConfig, userBabelConfig);
|
|
97
92
|
};
|
|
98
|
-
|
|
99
93
|
exports.resolveBabelConfig = resolveBabelConfig;
|
|
@@ -4,23 +4,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.copyTask = void 0;
|
|
7
|
-
|
|
8
7
|
var path = _interopRequireWildcard(require("path"));
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
9
|
const _excluded = ["glob"];
|
|
13
|
-
|
|
14
10
|
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); }
|
|
15
|
-
|
|
16
11
|
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; }
|
|
17
|
-
|
|
18
12
|
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; }
|
|
19
|
-
|
|
20
13
|
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; }
|
|
21
|
-
|
|
22
14
|
const normalizePath = _utils.Import.lazy('normalize-path', require);
|
|
23
|
-
|
|
24
15
|
const copyTask = async option => {
|
|
25
16
|
const {
|
|
26
17
|
modernConfig,
|
|
@@ -37,11 +28,9 @@ const copyTask = async option => {
|
|
|
37
28
|
}
|
|
38
29
|
} = modernConfig;
|
|
39
30
|
const copyDistDir = path.join(outputPath, jsPath);
|
|
40
|
-
|
|
41
31
|
if (!copy) {
|
|
42
32
|
return;
|
|
43
33
|
}
|
|
44
|
-
|
|
45
34
|
try {
|
|
46
35
|
// 类型暂时这样处理,待之后优化copy的逻辑
|
|
47
36
|
for (const copyOption of copy) {
|
|
@@ -52,11 +41,10 @@ const copyTask = async option => {
|
|
|
52
41
|
globOptions,
|
|
53
42
|
to: toOrigin
|
|
54
43
|
} = copyOption;
|
|
55
|
-
let fromOrigin = from;
|
|
56
|
-
|
|
44
|
+
let fromOrigin = from;
|
|
45
|
+
// 获取 glob 规则
|
|
57
46
|
let glob = '';
|
|
58
47
|
let options = {};
|
|
59
|
-
|
|
60
48
|
if (fromOrigin !== null && typeof fromOrigin === 'object') {
|
|
61
49
|
var _fromOrigin = fromOrigin;
|
|
62
50
|
({
|
|
@@ -68,23 +56,19 @@ const copyTask = async option => {
|
|
|
68
56
|
} else if (globOptions && typeof globOptions === 'object') {
|
|
69
57
|
options = globOptions;
|
|
70
58
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
59
|
+
glob = path.isAbsolute(fromOrigin) ? fromOrigin : path.posix.join(_utils.fastGlob.escapePath(normalizePath(path.resolve(context))), fromOrigin);
|
|
60
|
+
// 计算 glob,获取目标文件
|
|
74
61
|
const paths = await (0, _utils.globby)((0, _utils.slash)(glob), options);
|
|
75
|
-
|
|
76
62
|
if (!paths.length) {
|
|
77
63
|
return;
|
|
78
64
|
}
|
|
79
|
-
|
|
80
65
|
const to = path.normalize(toOrigin ? toOrigin : '');
|
|
81
66
|
const isToDirectory = path.extname(to) === '';
|
|
82
67
|
paths.forEach(item => {
|
|
83
|
-
const relativeFrom = path.relative(context, item);
|
|
84
|
-
|
|
68
|
+
const relativeFrom = path.relative(context, item);
|
|
69
|
+
// 如果 to 是目录,通过相对路径计算完整的产物路径;如果 to 是文件,直接作为最终产物路径
|
|
85
70
|
const fileName = isToDirectory ? path.join(to, relativeFrom) : to;
|
|
86
71
|
const finalToPath = path.resolve(copyDistDir, fileName);
|
|
87
|
-
|
|
88
72
|
_utils.fs.copySync(item, finalToPath);
|
|
89
73
|
});
|
|
90
74
|
}
|
|
@@ -92,5 +76,4 @@ const copyTask = async option => {
|
|
|
92
76
|
console.error(`copy error: ${e.message}`);
|
|
93
77
|
}
|
|
94
78
|
};
|
|
95
|
-
|
|
96
79
|
exports.copyTask = copyTask;
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.initEnv = void 0;
|
|
7
|
-
|
|
8
7
|
const initEnv = ({
|
|
9
8
|
syntax,
|
|
10
9
|
type
|
|
@@ -16,8 +15,6 @@ const initEnv = ({
|
|
|
16
15
|
} else if (syntax === 'es5' && type === 'module') {
|
|
17
16
|
return 'ESM_ES5';
|
|
18
17
|
}
|
|
19
|
-
|
|
20
18
|
return '';
|
|
21
19
|
};
|
|
22
|
-
|
|
23
20
|
exports.initEnv = initEnv;
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.safeParse = void 0;
|
|
7
|
-
|
|
8
7
|
const safeParse = jsonString => {
|
|
9
8
|
try {
|
|
10
9
|
return {
|
|
@@ -18,5 +17,4 @@ const safeParse = jsonString => {
|
|
|
18
17
|
};
|
|
19
18
|
}
|
|
20
19
|
};
|
|
21
|
-
|
|
22
20
|
exports.safeParse = safeParse;
|
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getLocaleLanguage = getLocaleLanguage;
|
|
7
|
-
|
|
8
7
|
var _utils = require("@modern-js/utils");
|
|
9
|
-
|
|
10
8
|
const i18n = _utils.Import.lazy('@modern-js/plugin-i18n/language-detector', require);
|
|
11
|
-
|
|
12
9
|
function getLocaleLanguage() {
|
|
13
10
|
const detector = new i18n.I18CLILanguageDetector();
|
|
14
11
|
return detector.detect();
|
|
@@ -4,18 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.logTemplate = exports.clearFlag = exports.LoggerText = exports.LoggerManager = void 0;
|
|
7
|
-
|
|
8
7
|
var _events = _interopRequireDefault(require("events"));
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
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 clearFlag = '\x1Bc';
|
|
17
12
|
exports.clearFlag = clearFlag;
|
|
18
|
-
|
|
19
13
|
const logTemplate = (title, messageStack, maxLength, {
|
|
20
14
|
noBottomBorder: _noBottomBorder = false,
|
|
21
15
|
bottomBorderText: _bottomBorderText = '',
|
|
@@ -31,39 +25,29 @@ const logTemplate = (title, messageStack, maxLength, {
|
|
|
31
25
|
.filter(s => s !== leftBorderFlag) // 过滤空字符串
|
|
32
26
|
.slice(0, maxLength) // 控制长度
|
|
33
27
|
.reverse(); // 调换顺序,最新的消息在最后面
|
|
34
|
-
|
|
35
28
|
messageFragments[messageFragments.length - 1] = messageFragments[messageFragments.length - 1].trim();
|
|
36
29
|
const template = `${title}:
|
|
37
30
|
${_contentColor(messageFragments.join(''))}${_noBottomBorder ? '' : `\n${_bottomBorderText}`}`;
|
|
38
31
|
console.info('template', messageFragments);
|
|
39
32
|
return template;
|
|
40
33
|
};
|
|
41
|
-
|
|
42
34
|
exports.logTemplate = logTemplate;
|
|
43
|
-
|
|
44
35
|
class LoggerText {
|
|
45
36
|
constructor(option) {
|
|
46
37
|
_defineProperty(this, "messages", void 0);
|
|
47
|
-
|
|
48
38
|
_defineProperty(this, "option", void 0);
|
|
49
|
-
|
|
50
39
|
this.messages = [];
|
|
51
40
|
this.option = option;
|
|
52
41
|
}
|
|
53
|
-
|
|
54
42
|
append(message) {
|
|
55
43
|
var _this$option$contentC;
|
|
56
|
-
|
|
57
44
|
const replace = ((_this$option$contentC = this.option.contentConfig) === null || _this$option$contentC === void 0 ? void 0 : _this$option$contentC.replace) || [];
|
|
58
45
|
let content = message;
|
|
59
|
-
|
|
60
46
|
for (const r of replace) {
|
|
61
47
|
content = content.replace(new RegExp(r, 'g'), '');
|
|
62
48
|
}
|
|
63
|
-
|
|
64
49
|
this.messages.push(content);
|
|
65
50
|
}
|
|
66
|
-
|
|
67
51
|
get value() {
|
|
68
52
|
const {
|
|
69
53
|
title,
|
|
@@ -73,17 +57,14 @@ class LoggerText {
|
|
|
73
57
|
const messages = [...new Set(this.messages)];
|
|
74
58
|
return logTemplate(title, messages, maxLength, contentConfig);
|
|
75
59
|
}
|
|
76
|
-
|
|
77
60
|
}
|
|
78
|
-
|
|
79
61
|
exports.LoggerText = LoggerText;
|
|
80
|
-
|
|
81
62
|
class LoggerManager extends _events.default {
|
|
82
63
|
// constructor() {}
|
|
64
|
+
|
|
83
65
|
createLoggerText(option) {
|
|
84
66
|
return new LoggerText(option);
|
|
85
67
|
}
|
|
86
|
-
|
|
87
68
|
addStdout(loggerText, stdout, config = {}) {
|
|
88
69
|
const {
|
|
89
70
|
event = {
|
|
@@ -96,7 +77,6 @@ class LoggerManager extends _events.default {
|
|
|
96
77
|
warning: _utils.chalk.yellow
|
|
97
78
|
}
|
|
98
79
|
} = config;
|
|
99
|
-
|
|
100
80
|
if (event.data) {
|
|
101
81
|
stdout === null || stdout === void 0 ? void 0 : stdout.on('data', chunk => {
|
|
102
82
|
const data = chunk.toString();
|
|
@@ -105,7 +85,6 @@ class LoggerManager extends _events.default {
|
|
|
105
85
|
this.emit('data');
|
|
106
86
|
});
|
|
107
87
|
}
|
|
108
|
-
|
|
109
88
|
if (event.error) {
|
|
110
89
|
stdout === null || stdout === void 0 ? void 0 : stdout.on('error', error => {
|
|
111
90
|
const data = error.message;
|
|
@@ -115,18 +94,14 @@ class LoggerManager extends _events.default {
|
|
|
115
94
|
});
|
|
116
95
|
}
|
|
117
96
|
}
|
|
118
|
-
|
|
119
97
|
addStderr(loggerText, stderr) {
|
|
120
98
|
stderr === null || stderr === void 0 ? void 0 : stderr.on('data', chunk => {
|
|
121
99
|
const data = chunk.toString();
|
|
122
100
|
loggerText.append(data);
|
|
123
101
|
});
|
|
124
102
|
}
|
|
125
|
-
|
|
126
103
|
show(loggerText) {
|
|
127
104
|
console.info(loggerText.value);
|
|
128
105
|
}
|
|
129
|
-
|
|
130
106
|
}
|
|
131
|
-
|
|
132
107
|
exports.LoggerManager = LoggerManager;
|
|
@@ -4,30 +4,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.ReadlineUtils = void 0;
|
|
7
|
-
|
|
8
7
|
var readline = _interopRequireWildcard(require("readline"));
|
|
9
|
-
|
|
10
8
|
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); }
|
|
11
|
-
|
|
12
9
|
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; }
|
|
13
|
-
|
|
14
10
|
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
15
11
|
class ReadlineUtils {
|
|
16
12
|
static clearPrevLine(output) {
|
|
17
13
|
ReadlineUtils.clearLine(output, 1);
|
|
18
14
|
}
|
|
19
|
-
|
|
20
15
|
static clearLine(output, n = 1, dir = -1) {
|
|
21
16
|
// -1 向上,1 向下
|
|
22
17
|
const dx = dir === 1 ? 1 : -1;
|
|
23
|
-
|
|
24
18
|
for (let i = 0; i < n; i++) {
|
|
25
19
|
readline.moveCursor(output, 0, dx);
|
|
26
20
|
readline.clearLine(output, 0);
|
|
27
21
|
readline.cursorTo(output, 0);
|
|
28
22
|
}
|
|
29
23
|
}
|
|
30
|
-
|
|
31
24
|
}
|
|
32
|
-
|
|
33
25
|
exports.ReadlineUtils = ReadlineUtils;
|
|
@@ -4,25 +4,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.readTsConfig = exports.existTsConfigFile = void 0;
|
|
7
|
-
|
|
8
7
|
var _utils = require("@modern-js/utils");
|
|
9
|
-
|
|
10
8
|
const readTsConfig = (tsconfigPath, noExistReturn = null) => {
|
|
11
9
|
// 如果不存在,则返回 noExistReturn
|
|
12
10
|
if (!_utils.fs.existsSync(tsconfigPath)) {
|
|
13
11
|
return noExistReturn;
|
|
14
12
|
}
|
|
15
|
-
|
|
16
13
|
const content = _utils.fs.readFileSync(tsconfigPath, 'utf-8');
|
|
17
|
-
|
|
18
14
|
return _utils.json5.parse(content);
|
|
19
15
|
};
|
|
20
|
-
|
|
21
16
|
exports.readTsConfig = readTsConfig;
|
|
22
|
-
|
|
23
17
|
const existTsConfigFile = tsconfigAbsolutePath => {
|
|
24
18
|
const tsconfig = readTsConfig(tsconfigAbsolutePath);
|
|
25
19
|
return Boolean(tsconfig);
|
|
26
20
|
};
|
|
27
|
-
|
|
28
21
|
exports.existTsConfigFile = existTsConfigFile;
|
|
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.defaultTransformedFunctions = void 0;
|
|
7
|
-
const defaultTransformedFunctions = ['require', 'require.resolve', 'System.import',
|
|
8
|
-
|
|
7
|
+
const defaultTransformedFunctions = ['require', 'require.resolve', 'System.import',
|
|
8
|
+
// Jest methods
|
|
9
|
+
'jest.genMockFromModule', 'jest.mock', 'jest.unmock', 'jest.doMock', 'jest.dontMock', 'jest.setMock', 'jest.requireActual', 'jest.requireMock',
|
|
10
|
+
// Older Jest methods
|
|
9
11
|
'require.requireActual', 'require.requireMock'];
|
|
10
12
|
exports.defaultTransformedFunctions = defaultTransformedFunctions;
|
|
@@ -4,50 +4,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.transformDtsAlias = void 0;
|
|
7
|
-
|
|
8
7
|
var path = _interopRequireWildcard(require("path"));
|
|
9
|
-
|
|
10
8
|
var parser = _interopRequireWildcard(require("@babel/parser"));
|
|
11
|
-
|
|
12
9
|
var _traverse = _interopRequireDefault(require("@babel/traverse"));
|
|
13
|
-
|
|
14
10
|
var _generator = _interopRequireDefault(require("@babel/generator"));
|
|
15
|
-
|
|
16
11
|
var t = _interopRequireWildcard(require("@babel/types"));
|
|
17
|
-
|
|
18
12
|
var _tsconfigPaths = require("@modern-js/utils/tsconfig-paths");
|
|
19
|
-
|
|
20
13
|
var _utils = require("@modern-js/utils");
|
|
21
|
-
|
|
22
14
|
var _constants = require("./constants");
|
|
23
|
-
|
|
24
15
|
var _utils2 = require("./utils");
|
|
25
|
-
|
|
26
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
-
|
|
28
17
|
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); }
|
|
29
|
-
|
|
30
18
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
31
|
-
|
|
32
19
|
const getPathsMap = (paths, sourceDirName = 'src') => {
|
|
33
20
|
const pathKeys = Object.keys(paths);
|
|
34
21
|
const pathsMap = {};
|
|
35
|
-
|
|
36
22
|
const replaceSrcToTypes = s => s.replace(sourceDirName, 'types');
|
|
37
|
-
|
|
38
23
|
for (const key of pathKeys) {
|
|
39
24
|
const p = paths[key];
|
|
40
|
-
|
|
41
25
|
if (typeof p === 'string') {
|
|
42
26
|
pathsMap[key] = [replaceSrcToTypes(p)];
|
|
43
27
|
} else {
|
|
44
28
|
pathsMap[key] = paths[key].map(sp => replaceSrcToTypes(sp));
|
|
45
29
|
}
|
|
46
30
|
}
|
|
47
|
-
|
|
48
31
|
return pathsMap;
|
|
49
32
|
};
|
|
50
|
-
|
|
51
33
|
function mapPathString(nodePath, {
|
|
52
34
|
filename,
|
|
53
35
|
baseUrl,
|
|
@@ -56,7 +38,6 @@ function mapPathString(nodePath, {
|
|
|
56
38
|
if (!t.isStringLiteral(nodePath)) {
|
|
57
39
|
return;
|
|
58
40
|
}
|
|
59
|
-
|
|
60
41
|
const sourcePath = nodePath.node.value;
|
|
61
42
|
const currentFile = filename;
|
|
62
43
|
const pathsMap = getPathsMap(paths);
|
|
@@ -65,45 +46,36 @@ function mapPathString(nodePath, {
|
|
|
65
46
|
if (!_utils.fs.existsSync(packageJsonPath)) {
|
|
66
47
|
return undefined;
|
|
67
48
|
}
|
|
68
|
-
|
|
69
49
|
return _utils.fs.readJSONSync(packageJsonPath);
|
|
70
50
|
}, filePath => _utils.fs.existsSync(filePath), ['.d.ts']);
|
|
71
|
-
|
|
72
51
|
if (result) {
|
|
73
52
|
const relativePath = path.relative(path.dirname(currentFile), path.dirname(result));
|
|
74
|
-
const fileName = path.basename(result);
|
|
75
|
-
|
|
53
|
+
const fileName = path.basename(result);
|
|
54
|
+
// 如果是同级文件,则返回的是 ''
|
|
76
55
|
const filePath = path.normalize(`${relativePath.length === 0 ? '.' : relativePath}/${fileName}`);
|
|
77
56
|
const replaceString = filePath.startsWith('.') ? filePath : `./${filePath}`;
|
|
78
57
|
nodePath.replaceWith(t.stringLiteral(replaceString));
|
|
79
58
|
}
|
|
80
59
|
}
|
|
81
|
-
|
|
82
60
|
const transformCall = option => nodePath => {
|
|
83
61
|
const calleePath = nodePath.get('callee');
|
|
84
|
-
|
|
85
62
|
const isNormalCall = _constants.defaultTransformedFunctions.some(pattern => (0, _utils2.matchesPattern)(calleePath, pattern));
|
|
86
|
-
|
|
87
63
|
if (isNormalCall || (0, _utils2.isImportCall)(nodePath)) {
|
|
88
64
|
mapPathString(nodePath.get('arguments.0'), option);
|
|
89
65
|
}
|
|
90
66
|
};
|
|
91
|
-
|
|
92
67
|
const transformImport = option => nodePath => {
|
|
93
68
|
mapPathString(nodePath.get('source'), option);
|
|
94
69
|
};
|
|
95
|
-
|
|
96
70
|
const transformExport = option => nodePath => {
|
|
97
71
|
mapPathString(nodePath.get('source'), option);
|
|
98
72
|
};
|
|
99
|
-
|
|
100
73
|
const transformSingleFileAlias = ({
|
|
101
74
|
filename,
|
|
102
75
|
baseUrl,
|
|
103
76
|
paths
|
|
104
77
|
}) => {
|
|
105
78
|
const sourceCode = _utils.fs.readFileSync(filename, 'utf-8');
|
|
106
|
-
|
|
107
79
|
const ast = parser.parse(sourceCode, {
|
|
108
80
|
sourceType: 'module',
|
|
109
81
|
errorRecovery: true,
|
|
@@ -129,7 +101,6 @@ const transformSingleFileAlias = ({
|
|
|
129
101
|
});
|
|
130
102
|
return (0, _generator.default)(ast).code;
|
|
131
103
|
};
|
|
132
|
-
|
|
133
104
|
const transformDtsAlias = option => {
|
|
134
105
|
const {
|
|
135
106
|
filenames = [],
|
|
@@ -137,7 +108,6 @@ const transformDtsAlias = option => {
|
|
|
137
108
|
paths
|
|
138
109
|
} = option;
|
|
139
110
|
const transformResult = [];
|
|
140
|
-
|
|
141
111
|
for (const filename of filenames) {
|
|
142
112
|
transformResult.push({
|
|
143
113
|
path: filename,
|
|
@@ -148,8 +118,6 @@ const transformDtsAlias = option => {
|
|
|
148
118
|
})
|
|
149
119
|
});
|
|
150
120
|
}
|
|
151
|
-
|
|
152
121
|
return transformResult;
|
|
153
122
|
};
|
|
154
|
-
|
|
155
123
|
exports.transformDtsAlias = transformDtsAlias;
|
|
@@ -5,28 +5,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.isImportCall = isImportCall;
|
|
7
7
|
exports.matchesPattern = matchesPattern;
|
|
8
|
-
|
|
9
8
|
var _utils = require("@modern-js/utils");
|
|
10
|
-
|
|
11
9
|
const t = _utils.Import.lazy('@babel/types', require);
|
|
12
|
-
|
|
13
10
|
function matchesPattern(calleePath, pattern) {
|
|
14
11
|
const {
|
|
15
12
|
node
|
|
16
13
|
} = calleePath;
|
|
17
|
-
|
|
18
14
|
if (t.isMemberExpression(node)) {
|
|
19
15
|
return calleePath.matchesPattern(pattern);
|
|
20
16
|
}
|
|
21
|
-
|
|
22
17
|
if (!t.isIdentifier(node) || pattern.includes('.')) {
|
|
23
18
|
return false;
|
|
24
19
|
}
|
|
25
|
-
|
|
26
20
|
const name = pattern.split('.')[0];
|
|
27
21
|
return node.name === name;
|
|
28
22
|
}
|
|
29
|
-
|
|
30
23
|
function isImportCall(calleePath) {
|
|
31
24
|
return t.isImport(calleePath.node.callee);
|
|
32
25
|
}
|