@modern-js/server-utils 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 +58 -16
- package/dist/js/modern/common/index.js +0 -5
- package/dist/js/modern/compilers/babel/index.js +10 -14
- package/dist/js/modern/compilers/typescript/index.js +4 -16
- package/dist/js/modern/compilers/typescript/tsconfig-paths-plugin.js +11 -38
- package/dist/js/modern/compilers/typescript/typescript-loader.js +0 -8
- package/dist/js/node/common/index.js +0 -13
- package/dist/js/node/compilers/babel/index.js +9 -33
- package/dist/js/node/compilers/typescript/index.js +3 -27
- package/dist/js/node/compilers/typescript/tsconfig-paths-plugin.js +11 -45
- package/dist/js/node/compilers/typescript/typescript-loader.js +0 -10
- package/dist/js/node/index.js +0 -3
- package/dist/js/treeshaking/common/index.js +0 -14
- package/dist/js/treeshaking/compilers/babel/index.js +12 -20
- package/dist/js/treeshaking/compilers/typescript/index.js +7 -34
- package/dist/js/treeshaking/compilers/typescript/tsconfig-paths-plugin.js +14 -45
- package/dist/js/treeshaking/compilers/typescript/typescript-loader.js +0 -9
- package/package.json +10 -33
|
@@ -4,28 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.compileByTs = void 0;
|
|
7
|
-
|
|
8
7
|
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
9
|
var _typescript = _interopRequireDefault(require("typescript"));
|
|
13
|
-
|
|
14
10
|
var _typescriptLoader = require("./typescript-loader");
|
|
15
|
-
|
|
16
11
|
var _tsconfigPathsPlugin = require("./tsconfig-paths-plugin");
|
|
17
|
-
|
|
18
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
13
|
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; }
|
|
21
|
-
|
|
22
14
|
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; }
|
|
23
|
-
|
|
24
15
|
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; }
|
|
25
|
-
|
|
26
16
|
const readTsConfigByFile = tsConfigFile => {
|
|
27
17
|
const parsedCmd = _typescript.default.getParsedCommandLineOfConfigFile(tsConfigFile, undefined, _typescript.default.sys);
|
|
28
|
-
|
|
29
18
|
const {
|
|
30
19
|
options,
|
|
31
20
|
fileNames,
|
|
@@ -37,32 +26,25 @@ const readTsConfigByFile = tsConfigFile => {
|
|
|
37
26
|
projectReferences
|
|
38
27
|
};
|
|
39
28
|
};
|
|
40
|
-
|
|
41
29
|
const copyFiles = async (from, to, tsconfigPath) => {
|
|
42
30
|
if (await _utils.fs.pathExists(from)) {
|
|
43
31
|
const basename = _path.default.basename(from);
|
|
44
|
-
|
|
45
32
|
const targetDir = _path.default.join(to, basename);
|
|
46
|
-
|
|
47
33
|
await _utils.fs.copy(from, targetDir, {
|
|
48
34
|
filter: src => !['.ts'].includes(_path.default.extname(src)) && src !== tsconfigPath
|
|
49
35
|
});
|
|
50
36
|
}
|
|
51
37
|
};
|
|
52
|
-
|
|
53
38
|
const compileByTs = async (appDirectory, config, compileOptions) => {
|
|
54
39
|
_utils.logger.info(`Running ts compile...`);
|
|
55
|
-
|
|
56
40
|
const {
|
|
57
41
|
sourceDirs,
|
|
58
42
|
distDir,
|
|
59
43
|
tsconfigPath
|
|
60
44
|
} = compileOptions;
|
|
61
|
-
|
|
62
45
|
if (!tsconfigPath) {
|
|
63
46
|
return;
|
|
64
47
|
}
|
|
65
|
-
|
|
66
48
|
const ts = new _typescriptLoader.TypescriptLoader({
|
|
67
49
|
appDirectory
|
|
68
50
|
}).load();
|
|
@@ -71,7 +53,7 @@ const compileByTs = async (appDirectory, config, compileOptions) => {
|
|
|
71
53
|
const {
|
|
72
54
|
alias
|
|
73
55
|
} = config;
|
|
74
|
-
const aliasOption = (0, _utils.
|
|
56
|
+
const aliasOption = (0, _utils.getAliasConfig)(alias, {
|
|
75
57
|
appDirectory,
|
|
76
58
|
tsconfigPath
|
|
77
59
|
});
|
|
@@ -103,23 +85,17 @@ const compileByTs = async (appDirectory, config, compileOptions) => {
|
|
|
103
85
|
before: [tsconfigPathsPlugin]
|
|
104
86
|
});
|
|
105
87
|
const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
106
|
-
|
|
107
88
|
if (allDiagnostics.length > 0) {
|
|
108
|
-
_utils.logger.error(ts.formatDiagnosticsWithColorAndContext(allDiagnostics, formatHost));
|
|
109
|
-
|
|
110
|
-
|
|
89
|
+
_utils.logger.error(ts.formatDiagnosticsWithColorAndContext(allDiagnostics, formatHost));
|
|
90
|
+
// eslint-disable-next-line no-process-exit
|
|
111
91
|
process.exit(1);
|
|
112
92
|
}
|
|
113
|
-
|
|
114
93
|
for (const source of sourceDirs) {
|
|
115
94
|
await copyFiles(source, distDir, tsconfigPath);
|
|
116
95
|
}
|
|
117
|
-
|
|
118
96
|
_utils.logger.info(`Ts compile succeed`);
|
|
119
97
|
};
|
|
120
|
-
|
|
121
98
|
exports.compileByTs = compileByTs;
|
|
122
|
-
|
|
123
99
|
const getFormatHost = ts => {
|
|
124
100
|
return {
|
|
125
101
|
getCanonicalFileName: path => path,
|
|
@@ -4,32 +4,22 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.tsconfigPathsBeforeHookFactory = tsconfigPathsBeforeHookFactory;
|
|
7
|
-
|
|
8
7
|
var os = _interopRequireWildcard(require("os"));
|
|
9
|
-
|
|
10
8
|
var _path = _interopRequireWildcard(require("path"));
|
|
11
|
-
|
|
12
9
|
var ts = _interopRequireWildcard(require("typescript"));
|
|
13
|
-
|
|
14
10
|
var _tsconfigPaths = require("tsconfig-paths");
|
|
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 isRegExpKey = str => {
|
|
21
14
|
return str.startsWith('^') || str.endsWith('$');
|
|
22
15
|
};
|
|
23
|
-
|
|
24
16
|
const resolveAliasPath = (baseUrl, filePath) => {
|
|
25
17
|
// exclude absolute path and alias
|
|
26
18
|
if (filePath.startsWith('.') || filePath.startsWith('..')) {
|
|
27
19
|
return _path.default.resolve(baseUrl, filePath);
|
|
28
20
|
}
|
|
29
|
-
|
|
30
21
|
return filePath;
|
|
31
22
|
};
|
|
32
|
-
|
|
33
23
|
const createAliasMatcher = (baseUrl, alias) => {
|
|
34
24
|
const aliasPairs = Object.keys(alias).reduce((o, key) => {
|
|
35
25
|
if (isRegExpKey(key)) {
|
|
@@ -40,16 +30,15 @@ const createAliasMatcher = (baseUrl, alias) => {
|
|
|
40
30
|
const aliasPath = resolveAliasPath(baseUrl, alias[key]);
|
|
41
31
|
o.push([key, aliasPath]);
|
|
42
32
|
}
|
|
43
|
-
|
|
44
33
|
return o;
|
|
45
34
|
}, []);
|
|
46
|
-
const cacheMap = new Map();
|
|
35
|
+
const cacheMap = new Map();
|
|
47
36
|
|
|
37
|
+
// eslint-disable-next-line consistent-return
|
|
48
38
|
return requestedModule => {
|
|
49
39
|
if (cacheMap.has(requestedModule)) {
|
|
50
40
|
return cacheMap.get(requestedModule);
|
|
51
41
|
}
|
|
52
|
-
|
|
53
42
|
for (const [key, value] of aliasPairs) {
|
|
54
43
|
if (key instanceof RegExp) {
|
|
55
44
|
if (key.test(requestedModule)) {
|
|
@@ -57,7 +46,6 @@ const createAliasMatcher = (baseUrl, alias) => {
|
|
|
57
46
|
return value;
|
|
58
47
|
}
|
|
59
48
|
}
|
|
60
|
-
|
|
61
49
|
if (requestedModule === key) {
|
|
62
50
|
cacheMap.set(requestedModule, value);
|
|
63
51
|
return value;
|
|
@@ -65,11 +53,9 @@ const createAliasMatcher = (baseUrl, alias) => {
|
|
|
65
53
|
}
|
|
66
54
|
};
|
|
67
55
|
};
|
|
68
|
-
|
|
69
56
|
const isDynamicImport = (tsBinary, node) => {
|
|
70
57
|
return tsBinary.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword;
|
|
71
58
|
};
|
|
72
|
-
|
|
73
59
|
function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
|
|
74
60
|
const tsPaths = {};
|
|
75
61
|
const alias = {};
|
|
@@ -82,21 +68,16 @@ function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
|
|
|
82
68
|
});
|
|
83
69
|
const matchAliasPath = createAliasMatcher(baseUrl, alias);
|
|
84
70
|
const matchTsPath = (0, _tsconfigPaths.createMatchPath)(baseUrl, tsPaths, ['main']);
|
|
85
|
-
|
|
86
71
|
const matchPath = (requestedModule, readJSONSync, fileExists, extensions) => {
|
|
87
72
|
const result = matchTsPath(requestedModule, readJSONSync, fileExists, extensions);
|
|
88
|
-
|
|
89
73
|
if (result) {
|
|
90
74
|
return result;
|
|
91
75
|
}
|
|
92
|
-
|
|
93
76
|
return matchAliasPath(requestedModule);
|
|
94
77
|
};
|
|
95
|
-
|
|
96
78
|
if (Object.keys(paths).length === 0) {
|
|
97
79
|
return undefined;
|
|
98
80
|
}
|
|
99
|
-
|
|
100
81
|
return ctx => {
|
|
101
82
|
return sf => {
|
|
102
83
|
const visitNode = node => {
|
|
@@ -104,64 +85,53 @@ function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
|
|
|
104
85
|
const importPathWithQuotes = node.arguments[0].getText(sf);
|
|
105
86
|
const text = importPathWithQuotes.slice(1, importPathWithQuotes.length - 1);
|
|
106
87
|
const result = getNotAliasedPath(sf, matchPath, text);
|
|
107
|
-
|
|
108
88
|
if (!result) {
|
|
109
89
|
return node;
|
|
110
90
|
}
|
|
111
|
-
|
|
112
91
|
return tsBinary.factory.updateCallExpression(node, node.expression, node.typeArguments, tsBinary.factory.createNodeArray([tsBinary.factory.createStringLiteral(result)]));
|
|
113
92
|
}
|
|
114
|
-
|
|
115
93
|
if (tsBinary.isImportDeclaration(node) || tsBinary.isExportDeclaration(node) && node.moduleSpecifier) {
|
|
116
94
|
try {
|
|
117
95
|
var _node$moduleSpecifier;
|
|
118
|
-
|
|
119
96
|
const importPathWithQuotes = node === null || node === void 0 ? void 0 : (_node$moduleSpecifier = node.moduleSpecifier) === null || _node$moduleSpecifier === void 0 ? void 0 : _node$moduleSpecifier.getText();
|
|
120
|
-
|
|
121
97
|
if (!importPathWithQuotes) {
|
|
122
98
|
return node;
|
|
123
99
|
}
|
|
124
|
-
|
|
125
100
|
const text = importPathWithQuotes.substring(1, importPathWithQuotes.length - 1);
|
|
126
101
|
const result = getNotAliasedPath(sf, matchPath, text);
|
|
127
|
-
|
|
128
102
|
if (!result) {
|
|
129
103
|
return node;
|
|
130
104
|
}
|
|
131
|
-
|
|
132
105
|
const moduleSpecifier = tsBinary.factory.createStringLiteral(result);
|
|
133
106
|
moduleSpecifier.parent = node.moduleSpecifier.parent;
|
|
134
|
-
|
|
107
|
+
let newNode;
|
|
135
108
|
if (tsBinary.isImportDeclaration(node)) {
|
|
136
|
-
|
|
109
|
+
newNode = tsBinary.factory.updateImportDeclaration(node, node.decorators, node.modifiers, node.importClause, moduleSpecifier, node.assertClause);
|
|
137
110
|
} else {
|
|
138
|
-
|
|
111
|
+
newNode = tsBinary.factory.updateExportDeclaration(node, node.decorators, node.modifiers, node.isTypeOnly, node.exportClause, moduleSpecifier, node.assertClause);
|
|
139
112
|
}
|
|
113
|
+
newNode.flags = node.flags;
|
|
114
|
+
return newNode;
|
|
140
115
|
} catch (_unused) {
|
|
141
116
|
return node;
|
|
142
117
|
}
|
|
143
118
|
}
|
|
144
|
-
|
|
145
119
|
return tsBinary.visitEachChild(node, visitNode, ctx);
|
|
146
120
|
};
|
|
147
|
-
|
|
148
121
|
return tsBinary.visitNode(sf, visitNode);
|
|
149
122
|
};
|
|
150
123
|
};
|
|
151
|
-
}
|
|
152
|
-
|
|
124
|
+
}
|
|
153
125
|
|
|
126
|
+
// fork from https://github.com/nestjs/nest-cli/blob/HEAD/lib/compiler/hooks/tsconfig-paths.hook.ts
|
|
154
127
|
function getNotAliasedPath(sf, matcher, text) {
|
|
155
128
|
let result = matcher(text, undefined, undefined, ['.ts', '.tsx', '.js', '.jsx']);
|
|
156
|
-
|
|
157
129
|
if (!result) {
|
|
158
130
|
return;
|
|
159
131
|
}
|
|
160
|
-
|
|
161
132
|
if (os.platform() === 'win32') {
|
|
162
133
|
result = result.replace(/\\/g, '/');
|
|
163
134
|
}
|
|
164
|
-
|
|
165
135
|
if (!_path.default.isAbsolute(result)) {
|
|
166
136
|
// handle alias to alias
|
|
167
137
|
if (!result.startsWith('.') && !result.startsWith('..')) {
|
|
@@ -171,29 +141,25 @@ function getNotAliasedPath(sf, matcher, text) {
|
|
|
171
141
|
const packagePath = require.resolve(result, {
|
|
172
142
|
paths: [process.cwd(), ...module.paths]
|
|
173
143
|
});
|
|
174
|
-
|
|
175
144
|
if (packagePath) {
|
|
176
145
|
// eslint-disable-next-line consistent-return
|
|
177
146
|
return result;
|
|
178
147
|
}
|
|
179
148
|
} catch (_unused2) {}
|
|
180
149
|
}
|
|
181
|
-
|
|
182
150
|
try {
|
|
183
151
|
// Installed packages (node modules) should take precedence over root files with the same name.
|
|
184
152
|
// Ref: https://github.com/nestjs/nest-cli/issues/838
|
|
185
153
|
const packagePath = require.resolve(text, {
|
|
186
154
|
paths: [process.cwd(), ...module.paths]
|
|
187
155
|
});
|
|
188
|
-
|
|
189
156
|
if (packagePath) {
|
|
190
157
|
// eslint-disable-next-line consistent-return
|
|
191
158
|
return text;
|
|
192
159
|
}
|
|
193
160
|
} catch (_unused3) {}
|
|
194
161
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
162
|
+
const resolvedPath = _path.posix.relative((0, _path.dirname)(sf.fileName), result) || './';
|
|
163
|
+
// eslint-disable-next-line consistent-return
|
|
198
164
|
return resolvedPath[0] === '.' ? resolvedPath : `./${resolvedPath}`;
|
|
199
165
|
}
|
|
@@ -4,38 +4,28 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.TypescriptLoader = void 0;
|
|
7
|
-
|
|
8
7
|
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; }
|
|
9
|
-
|
|
10
8
|
class TypescriptLoader {
|
|
11
9
|
constructor({
|
|
12
10
|
appDirectory
|
|
13
11
|
}) {
|
|
14
12
|
_defineProperty(this, "tsBinary", void 0);
|
|
15
|
-
|
|
16
13
|
_defineProperty(this, "appDirectory", void 0);
|
|
17
|
-
|
|
18
14
|
this.appDirectory = appDirectory;
|
|
19
15
|
}
|
|
20
|
-
|
|
21
16
|
load() {
|
|
22
17
|
if (this.tsBinary) {
|
|
23
18
|
return this.tsBinary;
|
|
24
19
|
}
|
|
25
|
-
|
|
26
20
|
try {
|
|
27
21
|
const tsPath = require.resolve('typescript', {
|
|
28
22
|
paths: [this.appDirectory || process.cwd()]
|
|
29
23
|
});
|
|
30
|
-
|
|
31
24
|
const ts = require(tsPath);
|
|
32
|
-
|
|
33
25
|
return ts;
|
|
34
26
|
} catch (error) {
|
|
35
27
|
throw new Error('TypeScript could not be found! Please, install "typescript" package.');
|
|
36
28
|
}
|
|
37
29
|
}
|
|
38
|
-
|
|
39
30
|
}
|
|
40
|
-
|
|
41
31
|
exports.TypescriptLoader = TypescriptLoader;
|
package/dist/js/node/index.js
CHANGED
|
@@ -12,9 +12,7 @@ Object.defineProperty(exports, "compile", {
|
|
|
12
12
|
return _common.compile;
|
|
13
13
|
}
|
|
14
14
|
});
|
|
15
|
-
|
|
16
15
|
var _babel = require("./compilers/babel");
|
|
17
|
-
|
|
18
16
|
Object.keys(_babel).forEach(function (key) {
|
|
19
17
|
if (key === "default" || key === "__esModule") return;
|
|
20
18
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -26,5 +24,4 @@ Object.keys(_babel).forEach(function (key) {
|
|
|
26
24
|
}
|
|
27
25
|
});
|
|
28
26
|
});
|
|
29
|
-
|
|
30
27
|
var _common = require("./common");
|
|
@@ -5,23 +5,19 @@ import { fs } from '@modern-js/utils';
|
|
|
5
5
|
import { compileByTs } from "../compilers/typescript";
|
|
6
6
|
import { compileByBabel } from "../compilers/babel";
|
|
7
7
|
export var FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs'];
|
|
8
|
-
|
|
9
8
|
var validateAbsolutePath = function validateAbsolutePath(filename, message) {
|
|
10
9
|
if (!path.isAbsolute(filename)) {
|
|
11
10
|
throw new Error(message);
|
|
12
11
|
}
|
|
13
12
|
};
|
|
14
|
-
|
|
15
13
|
var validateAbsolutePaths = function validateAbsolutePaths(filenames, messageFunc) {
|
|
16
14
|
filenames.forEach(function (filename) {
|
|
17
15
|
return validateAbsolutePath(filename, messageFunc(filename));
|
|
18
16
|
});
|
|
19
17
|
};
|
|
20
|
-
|
|
21
18
|
export var compile = /*#__PURE__*/function () {
|
|
22
19
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(appDirectory, modernConfig, compileOptions) {
|
|
23
20
|
var _modernConfig$server;
|
|
24
|
-
|
|
25
21
|
var sourceDirs, distDir, tsconfigPath, compiler, isTsProject;
|
|
26
22
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
27
23
|
while (1) {
|
|
@@ -34,37 +30,28 @@ export var compile = /*#__PURE__*/function () {
|
|
|
34
30
|
validateAbsolutePath(distDir, "dist dir ".concat(distDir, " is not an absolute path."));
|
|
35
31
|
compiler = modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig$server = modernConfig.server) === null || _modernConfig$server === void 0 ? void 0 : _modernConfig$server.compiler;
|
|
36
32
|
_context.t0 = tsconfigPath;
|
|
37
|
-
|
|
38
33
|
if (!_context.t0) {
|
|
39
34
|
_context.next = 9;
|
|
40
35
|
break;
|
|
41
36
|
}
|
|
42
|
-
|
|
43
37
|
_context.next = 8;
|
|
44
38
|
return fs.pathExists(tsconfigPath);
|
|
45
|
-
|
|
46
39
|
case 8:
|
|
47
40
|
_context.t0 = _context.sent;
|
|
48
|
-
|
|
49
41
|
case 9:
|
|
50
42
|
isTsProject = _context.t0;
|
|
51
|
-
|
|
52
43
|
if (!(!isTsProject || compiler === 'babel')) {
|
|
53
44
|
_context.next = 15;
|
|
54
45
|
break;
|
|
55
46
|
}
|
|
56
|
-
|
|
57
47
|
_context.next = 13;
|
|
58
48
|
return compileByBabel(appDirectory, modernConfig, compileOptions);
|
|
59
|
-
|
|
60
49
|
case 13:
|
|
61
50
|
_context.next = 17;
|
|
62
51
|
break;
|
|
63
|
-
|
|
64
52
|
case 15:
|
|
65
53
|
_context.next = 17;
|
|
66
54
|
return compileByTs(appDirectory, modernConfig, compileOptions);
|
|
67
|
-
|
|
68
55
|
case 17:
|
|
69
56
|
case "end":
|
|
70
57
|
return _context.stop();
|
|
@@ -72,7 +59,6 @@ export var compile = /*#__PURE__*/function () {
|
|
|
72
59
|
}
|
|
73
60
|
}, _callee);
|
|
74
61
|
}));
|
|
75
|
-
|
|
76
62
|
return function compile(_x, _x2, _x3) {
|
|
77
63
|
return _ref.apply(this, arguments);
|
|
78
64
|
};
|
|
@@ -3,18 +3,16 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
|
3
3
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
4
4
|
import * as path from 'path';
|
|
5
5
|
import { getBabelChain, applyUserBabelConfig } from '@modern-js/babel-preset-lib';
|
|
6
|
-
import { fs, json5,
|
|
6
|
+
import { fs, json5, getAliasConfig } from '@modern-js/utils';
|
|
7
7
|
import { compiler } from '@modern-js/babel-compiler';
|
|
8
8
|
import { FILE_EXTENSIONS } from "../../common";
|
|
9
9
|
export * from '@babel/core';
|
|
10
10
|
export var readTsConfig = function readTsConfig(tsconfigPath) {
|
|
11
11
|
var noExistReturn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
12
|
-
|
|
13
12
|
// 如果不存在,则返回 noExistReturn
|
|
14
13
|
if (!fs.existsSync(tsconfigPath)) {
|
|
15
14
|
return noExistReturn;
|
|
16
15
|
}
|
|
17
|
-
|
|
18
16
|
var content = fs.readFileSync(tsconfigPath, 'utf-8');
|
|
19
17
|
return json5.parse(content);
|
|
20
18
|
};
|
|
@@ -28,17 +26,20 @@ export var getBabelConfig = function getBabelConfig(libPresetOption, syntaxOptio
|
|
|
28
26
|
sourceType: 'unambiguous'
|
|
29
27
|
}, chain.toJSON());
|
|
30
28
|
};
|
|
31
|
-
export var resolveBabelConfig = function resolveBabelConfig(appDirectory, config, option
|
|
29
|
+
export var resolveBabelConfig = function resolveBabelConfig(appDirectory, config, option
|
|
30
|
+
// FIXME: babel type can't pass type checking
|
|
32
31
|
) {
|
|
33
32
|
var envVars = config.envVars,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
globalVars = config.globalVars,
|
|
34
|
+
alias = config.alias,
|
|
35
|
+
babelConfig = config.babelConfig;
|
|
37
36
|
|
|
38
|
-
|
|
37
|
+
// alias config
|
|
38
|
+
var aliasConfig = getAliasConfig(alias, _objectSpread({
|
|
39
39
|
appDirectory: appDirectory
|
|
40
|
-
}, option));
|
|
40
|
+
}, option));
|
|
41
41
|
|
|
42
|
+
// babel config
|
|
42
43
|
var babelChain = getBabelChain({
|
|
43
44
|
appDirectory: appDirectory,
|
|
44
45
|
enableReactPreset: true,
|
|
@@ -57,14 +58,13 @@ export var resolveBabelConfig = function resolveBabelConfig(appDirectory, config
|
|
|
57
58
|
babelChain.plugin('babel-plugin-transform-typescript-metadata').use(require.resolve('babel-plugin-transform-typescript-metadata'), []);
|
|
58
59
|
babelChain.plugin('@babel/plugin-proposal-decorators').use(require.resolve('@babel/plugin-proposal-decorators'), [{
|
|
59
60
|
legacy: true
|
|
60
|
-
}]);
|
|
61
|
+
}]);
|
|
61
62
|
|
|
63
|
+
// resolve "Definitely assigned fields cannot be initialized here, but only in the constructor."
|
|
62
64
|
babelChain.plugin('@babel/plugin-proposal-class-properties').use(require.resolve('@babel/plugin-proposal-class-properties'), [{
|
|
63
65
|
loose: true
|
|
64
66
|
}]);
|
|
65
|
-
|
|
66
67
|
var internalBabelConfig = _objectSpread({}, babelChain.toJSON());
|
|
67
|
-
|
|
68
68
|
return applyUserBabelConfig(internalBabelConfig, babelConfig);
|
|
69
69
|
};
|
|
70
70
|
export var compileByBabel = /*#__PURE__*/function () {
|
|
@@ -90,13 +90,11 @@ export var compileByBabel = /*#__PURE__*/function () {
|
|
|
90
90
|
});
|
|
91
91
|
_context.next = 3;
|
|
92
92
|
return fs.pathExists(sourceDir);
|
|
93
|
-
|
|
94
93
|
case 3:
|
|
95
94
|
if (!_context.sent) {
|
|
96
95
|
_context.next = 8;
|
|
97
96
|
break;
|
|
98
97
|
}
|
|
99
|
-
|
|
100
98
|
basename = path.basename(sourceDir);
|
|
101
99
|
targetDir = path.join(distDir, basename);
|
|
102
100
|
_context.next = 8;
|
|
@@ -105,7 +103,6 @@ export var compileByBabel = /*#__PURE__*/function () {
|
|
|
105
103
|
return !['.ts', '.js'].includes(path.extname(src)) && src !== tsconfigPath;
|
|
106
104
|
}
|
|
107
105
|
});
|
|
108
|
-
|
|
109
106
|
case 8:
|
|
110
107
|
return _context.abrupt("return", compiler({
|
|
111
108
|
rootDir: appDirectory,
|
|
@@ -113,7 +110,6 @@ export var compileByBabel = /*#__PURE__*/function () {
|
|
|
113
110
|
sourceDir: sourceDir,
|
|
114
111
|
extensions: FILE_EXTENSIONS
|
|
115
112
|
}, babelConfig));
|
|
116
|
-
|
|
117
113
|
case 9:
|
|
118
114
|
case "end":
|
|
119
115
|
return _context.stop();
|
|
@@ -121,12 +117,10 @@ export var compileByBabel = /*#__PURE__*/function () {
|
|
|
121
117
|
}
|
|
122
118
|
}, _callee);
|
|
123
119
|
}));
|
|
124
|
-
|
|
125
120
|
return function (_x4) {
|
|
126
121
|
return _ref2.apply(this, arguments);
|
|
127
122
|
};
|
|
128
123
|
}()));
|
|
129
|
-
|
|
130
124
|
case 3:
|
|
131
125
|
results = _context2.sent;
|
|
132
126
|
results.forEach(function (result) {
|
|
@@ -134,7 +128,6 @@ export var compileByBabel = /*#__PURE__*/function () {
|
|
|
134
128
|
throw new Error(result.message);
|
|
135
129
|
}
|
|
136
130
|
});
|
|
137
|
-
|
|
138
131
|
case 5:
|
|
139
132
|
case "end":
|
|
140
133
|
return _context2.stop();
|
|
@@ -142,7 +135,6 @@ export var compileByBabel = /*#__PURE__*/function () {
|
|
|
142
135
|
}
|
|
143
136
|
}, _callee2);
|
|
144
137
|
}));
|
|
145
|
-
|
|
146
138
|
return function compileByBabel(_x, _x2, _x3) {
|
|
147
139
|
return _ref.apply(this, arguments);
|
|
148
140
|
};
|