@modern-js/server-utils 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 +76 -0
- package/dist/js/modern/common/index.js +0 -5
- package/dist/js/modern/compilers/babel/index.js +12 -15
- package/dist/js/modern/compilers/typescript/index.js +2 -14
- package/dist/js/modern/compilers/typescript/tsconfig-paths-plugin.js +7 -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 +12 -35
- package/dist/js/node/compilers/typescript/index.js +2 -26
- package/dist/js/node/compilers/typescript/tsconfig-paths-plugin.js +7 -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 +13 -20
- package/dist/js/treeshaking/compilers/typescript/index.js +5 -32
- package/dist/js/treeshaking/compilers/typescript/tsconfig-paths-plugin.js +10 -45
- package/dist/js/treeshaking/compilers/typescript/typescript-loader.js +0 -9
- package/dist/types/common/index.d.ts +5 -5
- package/package.json +12 -13
|
@@ -4,21 +4,17 @@ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIt
|
|
|
4
4
|
import * as os from 'os';
|
|
5
5
|
import path, { dirname, posix } from 'path';
|
|
6
6
|
import * as ts from 'typescript';
|
|
7
|
-
import { createMatchPath } from 'tsconfig-paths';
|
|
8
|
-
|
|
7
|
+
import { createMatchPath } from '@modern-js/utils/tsconfig-paths';
|
|
9
8
|
var isRegExpKey = function isRegExpKey(str) {
|
|
10
9
|
return str.startsWith('^') || str.endsWith('$');
|
|
11
10
|
};
|
|
12
|
-
|
|
13
11
|
var resolveAliasPath = function resolveAliasPath(baseUrl, filePath) {
|
|
14
12
|
// exclude absolute path and alias
|
|
15
13
|
if (filePath.startsWith('.') || filePath.startsWith('..')) {
|
|
16
14
|
return path.resolve(baseUrl, filePath);
|
|
17
15
|
}
|
|
18
|
-
|
|
19
16
|
return filePath;
|
|
20
17
|
};
|
|
21
|
-
|
|
22
18
|
var createAliasMatcher = function createAliasMatcher(baseUrl, alias) {
|
|
23
19
|
var aliasPairs = Object.keys(alias).reduce(function (o, key) {
|
|
24
20
|
if (isRegExpKey(key)) {
|
|
@@ -27,35 +23,30 @@ var createAliasMatcher = function createAliasMatcher(baseUrl, alias) {
|
|
|
27
23
|
o.push([regexp, aliasPath]);
|
|
28
24
|
} else {
|
|
29
25
|
var _aliasPath = resolveAliasPath(baseUrl, alias[key]);
|
|
30
|
-
|
|
31
26
|
o.push([key, _aliasPath]);
|
|
32
27
|
}
|
|
33
|
-
|
|
34
28
|
return o;
|
|
35
29
|
}, []);
|
|
36
|
-
var cacheMap = new Map();
|
|
30
|
+
var cacheMap = new Map();
|
|
37
31
|
|
|
32
|
+
// eslint-disable-next-line consistent-return
|
|
38
33
|
return function (requestedModule) {
|
|
39
34
|
if (cacheMap.has(requestedModule)) {
|
|
40
35
|
return cacheMap.get(requestedModule);
|
|
41
36
|
}
|
|
42
|
-
|
|
43
37
|
var _iterator = _createForOfIteratorHelper(aliasPairs),
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
_step;
|
|
46
39
|
try {
|
|
47
40
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
48
41
|
var _step$value = _slicedToArray(_step.value, 2),
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
42
|
+
key = _step$value[0],
|
|
43
|
+
value = _step$value[1];
|
|
52
44
|
if (key instanceof RegExp) {
|
|
53
45
|
if (key.test(requestedModule)) {
|
|
54
46
|
cacheMap.set(requestedModule, value);
|
|
55
47
|
return value;
|
|
56
48
|
}
|
|
57
49
|
}
|
|
58
|
-
|
|
59
50
|
if (requestedModule === key) {
|
|
60
51
|
cacheMap.set(requestedModule, value);
|
|
61
52
|
return value;
|
|
@@ -68,11 +59,9 @@ var createAliasMatcher = function createAliasMatcher(baseUrl, alias) {
|
|
|
68
59
|
}
|
|
69
60
|
};
|
|
70
61
|
};
|
|
71
|
-
|
|
72
62
|
var isDynamicImport = function isDynamicImport(tsBinary, node) {
|
|
73
63
|
return tsBinary.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword;
|
|
74
64
|
};
|
|
75
|
-
|
|
76
65
|
export function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
|
|
77
66
|
var tsPaths = {};
|
|
78
67
|
var alias = {};
|
|
@@ -85,21 +74,16 @@ export function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
|
|
|
85
74
|
});
|
|
86
75
|
var matchAliasPath = createAliasMatcher(baseUrl, alias);
|
|
87
76
|
var matchTsPath = createMatchPath(baseUrl, tsPaths, ['main']);
|
|
88
|
-
|
|
89
77
|
var matchPath = function matchPath(requestedModule, readJSONSync, fileExists, extensions) {
|
|
90
78
|
var result = matchTsPath(requestedModule, readJSONSync, fileExists, extensions);
|
|
91
|
-
|
|
92
79
|
if (result) {
|
|
93
80
|
return result;
|
|
94
81
|
}
|
|
95
|
-
|
|
96
82
|
return matchAliasPath(requestedModule);
|
|
97
83
|
};
|
|
98
|
-
|
|
99
84
|
if (Object.keys(paths).length === 0) {
|
|
100
85
|
return undefined;
|
|
101
86
|
}
|
|
102
|
-
|
|
103
87
|
return function (ctx) {
|
|
104
88
|
return function (sf) {
|
|
105
89
|
var visitNode = function visitNode(node) {
|
|
@@ -107,68 +91,53 @@ export function tsconfigPathsBeforeHookFactory(tsBinary, baseUrl, paths) {
|
|
|
107
91
|
var importPathWithQuotes = node.arguments[0].getText(sf);
|
|
108
92
|
var text = importPathWithQuotes.slice(1, importPathWithQuotes.length - 1);
|
|
109
93
|
var result = getNotAliasedPath(sf, matchPath, text);
|
|
110
|
-
|
|
111
94
|
if (!result) {
|
|
112
95
|
return node;
|
|
113
96
|
}
|
|
114
|
-
|
|
115
97
|
return tsBinary.factory.updateCallExpression(node, node.expression, node.typeArguments, tsBinary.factory.createNodeArray([tsBinary.factory.createStringLiteral(result)]));
|
|
116
98
|
}
|
|
117
|
-
|
|
118
99
|
if (tsBinary.isImportDeclaration(node) || tsBinary.isExportDeclaration(node) && node.moduleSpecifier) {
|
|
119
100
|
try {
|
|
120
101
|
var _node$moduleSpecifier;
|
|
121
|
-
|
|
122
102
|
var _importPathWithQuotes = node === null || node === void 0 ? void 0 : (_node$moduleSpecifier = node.moduleSpecifier) === null || _node$moduleSpecifier === void 0 ? void 0 : _node$moduleSpecifier.getText();
|
|
123
|
-
|
|
124
103
|
if (!_importPathWithQuotes) {
|
|
125
104
|
return node;
|
|
126
105
|
}
|
|
127
|
-
|
|
128
106
|
var _text = _importPathWithQuotes.substring(1, _importPathWithQuotes.length - 1);
|
|
129
|
-
|
|
130
107
|
var _result = getNotAliasedPath(sf, matchPath, _text);
|
|
131
|
-
|
|
132
108
|
if (!_result) {
|
|
133
109
|
return node;
|
|
134
110
|
}
|
|
135
|
-
|
|
136
111
|
var moduleSpecifier = tsBinary.factory.createStringLiteral(_result);
|
|
137
112
|
moduleSpecifier.parent = node.moduleSpecifier.parent;
|
|
138
113
|
var newNode;
|
|
139
|
-
|
|
140
114
|
if (tsBinary.isImportDeclaration(node)) {
|
|
141
115
|
newNode = tsBinary.factory.updateImportDeclaration(node, node.decorators, node.modifiers, node.importClause, moduleSpecifier, node.assertClause);
|
|
142
116
|
} else {
|
|
143
117
|
newNode = tsBinary.factory.updateExportDeclaration(node, node.decorators, node.modifiers, node.isTypeOnly, node.exportClause, moduleSpecifier, node.assertClause);
|
|
144
118
|
}
|
|
145
|
-
|
|
146
119
|
newNode.flags = node.flags;
|
|
147
120
|
return newNode;
|
|
148
121
|
} catch (_unused) {
|
|
149
122
|
return node;
|
|
150
123
|
}
|
|
151
124
|
}
|
|
152
|
-
|
|
153
125
|
return tsBinary.visitEachChild(node, visitNode, ctx);
|
|
154
126
|
};
|
|
155
|
-
|
|
156
127
|
return tsBinary.visitNode(sf, visitNode);
|
|
157
128
|
};
|
|
158
129
|
};
|
|
159
|
-
}
|
|
130
|
+
}
|
|
160
131
|
|
|
132
|
+
// fork from https://github.com/nestjs/nest-cli/blob/HEAD/lib/compiler/hooks/tsconfig-paths.hook.ts
|
|
161
133
|
function getNotAliasedPath(sf, matcher, text) {
|
|
162
134
|
var result = matcher(text, undefined, undefined, ['.ts', '.tsx', '.js', '.jsx']);
|
|
163
|
-
|
|
164
135
|
if (!result) {
|
|
165
136
|
return;
|
|
166
137
|
}
|
|
167
|
-
|
|
168
138
|
if (os.platform() === 'win32') {
|
|
169
139
|
result = result.replace(/\\/g, '/');
|
|
170
140
|
}
|
|
171
|
-
|
|
172
141
|
if (!path.isAbsolute(result)) {
|
|
173
142
|
// handle alias to alias
|
|
174
143
|
if (!result.startsWith('.') && !result.startsWith('..')) {
|
|
@@ -178,29 +147,25 @@ function getNotAliasedPath(sf, matcher, text) {
|
|
|
178
147
|
var packagePath = require.resolve(result, {
|
|
179
148
|
paths: [process.cwd()].concat(_toConsumableArray(module.paths))
|
|
180
149
|
});
|
|
181
|
-
|
|
182
150
|
if (packagePath) {
|
|
183
151
|
// eslint-disable-next-line consistent-return
|
|
184
152
|
return result;
|
|
185
153
|
}
|
|
186
154
|
} catch (_unused2) {}
|
|
187
155
|
}
|
|
188
|
-
|
|
189
156
|
try {
|
|
190
157
|
// Installed packages (node modules) should take precedence over root files with the same name.
|
|
191
158
|
// Ref: https://github.com/nestjs/nest-cli/issues/838
|
|
192
159
|
var _packagePath = require.resolve(text, {
|
|
193
160
|
paths: [process.cwd()].concat(_toConsumableArray(module.paths))
|
|
194
161
|
});
|
|
195
|
-
|
|
196
162
|
if (_packagePath) {
|
|
197
163
|
// eslint-disable-next-line consistent-return
|
|
198
164
|
return text;
|
|
199
165
|
}
|
|
200
166
|
} catch (_unused3) {}
|
|
201
167
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
168
|
+
var resolvedPath = posix.relative(dirname(sf.fileName), result) || './';
|
|
169
|
+
// eslint-disable-next-line consistent-return
|
|
205
170
|
return resolvedPath[0] === '.' ? resolvedPath : "./".concat(resolvedPath);
|
|
206
171
|
}
|
|
@@ -4,36 +4,27 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
4
4
|
export var TypescriptLoader = /*#__PURE__*/function () {
|
|
5
5
|
function TypescriptLoader(_ref) {
|
|
6
6
|
var appDirectory = _ref.appDirectory;
|
|
7
|
-
|
|
8
7
|
_classCallCheck(this, TypescriptLoader);
|
|
9
|
-
|
|
10
8
|
_defineProperty(this, "tsBinary", void 0);
|
|
11
|
-
|
|
12
9
|
_defineProperty(this, "appDirectory", void 0);
|
|
13
|
-
|
|
14
10
|
this.appDirectory = appDirectory;
|
|
15
11
|
}
|
|
16
|
-
|
|
17
12
|
_createClass(TypescriptLoader, [{
|
|
18
13
|
key: "load",
|
|
19
14
|
value: function load() {
|
|
20
15
|
if (this.tsBinary) {
|
|
21
16
|
return this.tsBinary;
|
|
22
17
|
}
|
|
23
|
-
|
|
24
18
|
try {
|
|
25
19
|
var tsPath = require.resolve('typescript', {
|
|
26
20
|
paths: [this.appDirectory || process.cwd()]
|
|
27
21
|
});
|
|
28
|
-
|
|
29
22
|
var _ts = require(tsPath);
|
|
30
|
-
|
|
31
23
|
return _ts;
|
|
32
24
|
} catch (error) {
|
|
33
25
|
throw new Error('TypeScript could not be found! Please, install "typescript" package.');
|
|
34
26
|
}
|
|
35
27
|
}
|
|
36
28
|
}]);
|
|
37
|
-
|
|
38
29
|
return TypescriptLoader;
|
|
39
30
|
}();
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SourceNormalizedConfig, ToolsNormalizedConfig } from '@modern-js/server-core';
|
|
2
2
|
export interface Pattern {
|
|
3
3
|
from: string;
|
|
4
4
|
to: string;
|
|
5
5
|
tsconfigPath?: string;
|
|
6
6
|
}
|
|
7
7
|
export interface IConfig {
|
|
8
|
-
alias?:
|
|
9
|
-
|
|
10
|
-
globalVars?:
|
|
11
|
-
babelConfig?:
|
|
8
|
+
alias?: SourceNormalizedConfig['alias'];
|
|
9
|
+
define?: SourceNormalizedConfig['define'];
|
|
10
|
+
globalVars?: SourceNormalizedConfig['globalVars'];
|
|
11
|
+
babelConfig?: ToolsNormalizedConfig['babel'];
|
|
12
12
|
server: {
|
|
13
13
|
compiler?: 'babel' | 'typescript';
|
|
14
14
|
};
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "2.0.0-beta.
|
|
14
|
+
"version": "2.0.0-beta.2",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -35,24 +35,23 @@
|
|
|
35
35
|
"@babel/preset-env": "^7.18.0",
|
|
36
36
|
"@babel/preset-typescript": "^7.17.12",
|
|
37
37
|
"@babel/runtime": "^7.18.0",
|
|
38
|
-
"@modern-js/babel-compiler": "2.0.0-beta.0",
|
|
39
|
-
"@modern-js/babel-preset-lib": "2.0.0-beta.0",
|
|
40
|
-
"@modern-js/plugin": "2.0.0-beta.0",
|
|
41
|
-
"@modern-js/utils": "2.0.0-beta.0",
|
|
42
38
|
"babel-plugin-module-resolver": "^4.1.0",
|
|
43
39
|
"babel-plugin-transform-typescript-metadata": "^0.3.2",
|
|
44
|
-
"
|
|
40
|
+
"@modern-js/babel-compiler": "2.0.0-beta.2",
|
|
41
|
+
"@modern-js/babel-preset-lib": "2.0.0-beta.2",
|
|
42
|
+
"@modern-js/plugin": "2.0.0-beta.2",
|
|
43
|
+
"@modern-js/utils": "2.0.0-beta.2"
|
|
45
44
|
},
|
|
46
45
|
"devDependencies": {
|
|
47
|
-
"@modern-js/core": "2.0.0-beta.0",
|
|
48
|
-
"@scripts/build": "2.0.0-beta.0",
|
|
49
|
-
"@scripts/jest-config": "2.0.0-beta.0",
|
|
50
46
|
"@types/babel__core": "^7.1.15",
|
|
51
47
|
"@types/jest": "^27",
|
|
52
48
|
"@types/node": "^14",
|
|
53
49
|
"jest": "^27",
|
|
54
50
|
"ts-jest": "^27.0.4",
|
|
55
|
-
"typescript": "^4"
|
|
51
|
+
"typescript": "^4",
|
|
52
|
+
"@modern-js/server-core": "2.0.0-beta.2",
|
|
53
|
+
"@scripts/build": "2.0.0-beta.2",
|
|
54
|
+
"@scripts/jest-config": "2.0.0-beta.2"
|
|
56
55
|
},
|
|
57
56
|
"sideEffects": false,
|
|
58
57
|
"publishConfig": {
|
|
@@ -60,9 +59,9 @@
|
|
|
60
59
|
"access": "public"
|
|
61
60
|
},
|
|
62
61
|
"scripts": {
|
|
63
|
-
"new": "modern new",
|
|
64
|
-
"dev": "modern build --watch",
|
|
65
|
-
"build": "modern build",
|
|
62
|
+
"new": "modern-lib new",
|
|
63
|
+
"dev": "modern-lib build --watch",
|
|
64
|
+
"build": "modern-lib build",
|
|
66
65
|
"test": "jest --passWithNoTests"
|
|
67
66
|
}
|
|
68
67
|
}
|