@modern-js/server 1.15.0 → 1.15.1-beta.0
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.
|
@@ -6,28 +6,71 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
6
6
|
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import { resolveBabelConfig } from '@modern-js/server-utils';
|
|
9
|
+
import { fs, getAlias } from '@modern-js/utils';
|
|
10
|
+
import * as tsNode from 'ts-node';
|
|
11
|
+
import * as tsConfigPaths from 'tsconfig-paths';
|
|
9
12
|
const registerDirs = ['./api', './server', './config/mock', './shared'];
|
|
10
|
-
export const enableRegister = (projectRoot, config
|
|
13
|
+
export const enableRegister = (projectRoot, config // eslint-disable-next-line consistent-return
|
|
14
|
+
) => {
|
|
11
15
|
const TS_CONFIG_FILENAME = `tsconfig.json`;
|
|
12
16
|
const tsconfigPath = path.resolve(projectRoot, TS_CONFIG_FILENAME);
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
const isTsProject = fs.existsSync(tsconfigPath);
|
|
18
|
+
|
|
19
|
+
if (isTsProject) {
|
|
20
|
+
const {
|
|
21
|
+
alias
|
|
22
|
+
} = config.source;
|
|
23
|
+
const aliasOption = getAlias(alias || {}, {
|
|
24
|
+
appDirectory: projectRoot,
|
|
25
|
+
tsconfigPath
|
|
26
|
+
});
|
|
27
|
+
const {
|
|
28
|
+
paths = {},
|
|
29
|
+
absoluteBaseUrl = './'
|
|
30
|
+
} = aliasOption;
|
|
31
|
+
const tsPaths = Object.keys(paths).reduce((o, key) => {
|
|
32
|
+
let tsPath = paths[key]; // 要不要把对 modern 的判断去掉
|
|
33
|
+
|
|
34
|
+
if (typeof tsPath === 'string' && path.isAbsolute(tsPath)) {
|
|
35
|
+
tsPath = path.relative(absoluteBaseUrl, tsPath);
|
|
24
36
|
}
|
|
25
37
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
if (typeof tsPath === 'string') {
|
|
39
|
+
tsPath = [tsPath];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return _objectSpread(_objectSpread({}, o), {}, {
|
|
43
|
+
[`${key}`]: tsPath
|
|
44
|
+
});
|
|
45
|
+
}, {});
|
|
46
|
+
tsConfigPaths.register({
|
|
47
|
+
baseUrl: absoluteBaseUrl || './',
|
|
48
|
+
paths: tsPaths
|
|
49
|
+
});
|
|
50
|
+
tsNode.register({
|
|
51
|
+
project: tsconfigPath,
|
|
52
|
+
transpileOnly: true
|
|
53
|
+
});
|
|
54
|
+
} else {
|
|
55
|
+
const babelConfig = resolveBabelConfig(projectRoot, config, {
|
|
56
|
+
tsconfigPath,
|
|
57
|
+
syntax: 'es6+',
|
|
58
|
+
type: 'commonjs'
|
|
59
|
+
});
|
|
60
|
+
return require('@babel/register')(_objectSpread(_objectSpread({}, babelConfig), {}, {
|
|
61
|
+
only: [function (filePath) {
|
|
62
|
+
// TODO: wait params
|
|
63
|
+
// FIXME: 删除hardcode,根据 AppContext 中的 metaName 设置路径
|
|
64
|
+
if (filePath.includes(`node_modules${path.sep}.modern-js`)) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return registerDirs.some(registerDir => filePath.startsWith(path.join(projectRoot, registerDir)));
|
|
69
|
+
}],
|
|
70
|
+
extensions: ['.js', '.ts'],
|
|
71
|
+
babelrc: false,
|
|
72
|
+
configFile: false,
|
|
73
|
+
root: projectRoot
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
33
76
|
};
|
|
@@ -9,6 +9,16 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
9
9
|
|
|
10
10
|
var _serverUtils = require("@modern-js/server-utils");
|
|
11
11
|
|
|
12
|
+
var _utils = require("@modern-js/utils");
|
|
13
|
+
|
|
14
|
+
var tsNode = _interopRequireWildcard(require("ts-node"));
|
|
15
|
+
|
|
16
|
+
var tsConfigPaths = _interopRequireWildcard(require("tsconfig-paths"));
|
|
17
|
+
|
|
18
|
+
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); }
|
|
19
|
+
|
|
20
|
+
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; }
|
|
21
|
+
|
|
12
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
23
|
|
|
14
24
|
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; }
|
|
@@ -19,31 +29,71 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
19
29
|
|
|
20
30
|
const registerDirs = ['./api', './server', './config/mock', './shared'];
|
|
21
31
|
|
|
22
|
-
const enableRegister = (projectRoot, config
|
|
32
|
+
const enableRegister = (projectRoot, config // eslint-disable-next-line consistent-return
|
|
33
|
+
) => {
|
|
23
34
|
const TS_CONFIG_FILENAME = `tsconfig.json`;
|
|
24
35
|
|
|
25
36
|
const tsconfigPath = _path.default.resolve(projectRoot, TS_CONFIG_FILENAME);
|
|
26
37
|
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
const isTsProject = _utils.fs.existsSync(tsconfigPath);
|
|
39
|
+
|
|
40
|
+
if (isTsProject) {
|
|
41
|
+
const {
|
|
42
|
+
alias
|
|
43
|
+
} = config.source;
|
|
44
|
+
const aliasOption = (0, _utils.getAlias)(alias || {}, {
|
|
45
|
+
appDirectory: projectRoot,
|
|
46
|
+
tsconfigPath
|
|
47
|
+
});
|
|
48
|
+
const {
|
|
49
|
+
paths = {},
|
|
50
|
+
absoluteBaseUrl = './'
|
|
51
|
+
} = aliasOption;
|
|
52
|
+
const tsPaths = Object.keys(paths).reduce((o, key) => {
|
|
53
|
+
let tsPath = paths[key]; // 要不要把对 modern 的判断去掉
|
|
54
|
+
|
|
55
|
+
if (typeof tsPath === 'string' && _path.default.isAbsolute(tsPath)) {
|
|
56
|
+
tsPath = _path.default.relative(absoluteBaseUrl, tsPath);
|
|
38
57
|
}
|
|
39
58
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
59
|
+
if (typeof tsPath === 'string') {
|
|
60
|
+
tsPath = [tsPath];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return _objectSpread(_objectSpread({}, o), {}, {
|
|
64
|
+
[`${key}`]: tsPath
|
|
65
|
+
});
|
|
66
|
+
}, {});
|
|
67
|
+
tsConfigPaths.register({
|
|
68
|
+
baseUrl: absoluteBaseUrl || './',
|
|
69
|
+
paths: tsPaths
|
|
70
|
+
});
|
|
71
|
+
tsNode.register({
|
|
72
|
+
project: tsconfigPath,
|
|
73
|
+
transpileOnly: true
|
|
74
|
+
});
|
|
75
|
+
} else {
|
|
76
|
+
const babelConfig = (0, _serverUtils.resolveBabelConfig)(projectRoot, config, {
|
|
77
|
+
tsconfigPath,
|
|
78
|
+
syntax: 'es6+',
|
|
79
|
+
type: 'commonjs'
|
|
80
|
+
});
|
|
81
|
+
return require('@babel/register')(_objectSpread(_objectSpread({}, babelConfig), {}, {
|
|
82
|
+
only: [function (filePath) {
|
|
83
|
+
// TODO: wait params
|
|
84
|
+
// FIXME: 删除hardcode,根据 AppContext 中的 metaName 设置路径
|
|
85
|
+
if (filePath.includes(`node_modules${_path.default.sep}.modern-js`)) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return registerDirs.some(registerDir => filePath.startsWith(_path.default.join(projectRoot, registerDir)));
|
|
90
|
+
}],
|
|
91
|
+
extensions: ['.js', '.ts'],
|
|
92
|
+
babelrc: false,
|
|
93
|
+
configFile: false,
|
|
94
|
+
root: projectRoot
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
47
97
|
};
|
|
48
98
|
|
|
49
99
|
exports.enableRegister = enableRegister;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.15.0",
|
|
14
|
+
"version": "1.15.1-beta.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -32,11 +32,12 @@
|
|
|
32
32
|
"@babel/register": "^7.17.7",
|
|
33
33
|
"@modern-js/prod-server": "1.15.0",
|
|
34
34
|
"@modern-js/server-utils": "1.15.0",
|
|
35
|
-
"@modern-js/webpack": "1.15.0",
|
|
36
35
|
"@modern-js/utils": "1.15.0",
|
|
36
|
+
"@modern-js/webpack": "1.15.0",
|
|
37
37
|
"devcert": "^1.2.2",
|
|
38
38
|
"minimatch": "^3.0.4",
|
|
39
39
|
"path-to-regexp": "^6.2.0",
|
|
40
|
+
"tsconfig-paths": "3.14.1",
|
|
40
41
|
"ws": "^8.2.0"
|
|
41
42
|
},
|
|
42
43
|
"devDependencies": {
|
|
@@ -50,9 +51,13 @@
|
|
|
50
51
|
"@types/node": "^14",
|
|
51
52
|
"@types/ws": "^7.4.7",
|
|
52
53
|
"jest": "^27",
|
|
54
|
+
"ts-node": "^10.1.0",
|
|
53
55
|
"typescript": "^4",
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
+
"webpack": "^5.71.0",
|
|
57
|
+
"websocket": "^1"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"ts-node": "^10.1.0"
|
|
56
61
|
},
|
|
57
62
|
"sideEffects": false,
|
|
58
63
|
"modernConfig": {
|
|
@@ -62,7 +67,8 @@
|
|
|
62
67
|
},
|
|
63
68
|
"publishConfig": {
|
|
64
69
|
"registry": "https://registry.npmjs.org/",
|
|
65
|
-
"access": "public"
|
|
70
|
+
"access": "public",
|
|
71
|
+
"types": "./dist/types/index.d.ts"
|
|
66
72
|
},
|
|
67
73
|
"wireit": {
|
|
68
74
|
"build": {
|