@modern-js/server 1.15.1-beta.2 → 1.16.0-alpha.underfin.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 +19 -0
- package/dist/js/modern/dev-tools/babel/register.js +33 -0
- package/dist/js/modern/dev-tools/dev-server-plugin.js +6 -7
- package/dist/js/modern/hmr-client/index.js +3 -4
- package/dist/js/modern/server/dev-server.js +20 -4
- package/dist/js/modern/types.js +0 -1
- package/dist/js/node/dev-tools/babel/register.js +49 -0
- package/dist/js/node/dev-tools/dev-server-plugin.js +6 -9
- package/dist/js/node/hmr-client/index.js +3 -4
- package/dist/js/node/server/dev-server.js +20 -4
- package/dist/js/node/types.js +0 -5
- package/dist/types/dev-tools/{register/index.d.ts → babel/register.d.ts} +0 -0
- package/dist/types/dev-tools/dev-server-plugin.d.ts +2 -2
- package/dist/types/dev-tools/socket-server.d.ts +2 -2
- package/dist/types/server/dev-server.d.ts +1 -0
- package/dist/types/types.d.ts +2 -2
- package/package.json +10 -18
- package/dist/js/modern/dev-tools/register/index.js +0 -94
- package/dist/js/node/dev-tools/register/index.js +0 -110
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @modern-js/server
|
|
2
2
|
|
|
3
|
+
## 1.16.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2808ff5a2: fix(dev-server): support enable hmr client by webpack target
|
|
8
|
+
|
|
9
|
+
fix(dev-server): 支持通过 webpack target 来判断是否启用 hmr client
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [641592f52]
|
|
12
|
+
- Updated dependencies [3904b30a5]
|
|
13
|
+
- Updated dependencies [1100dd58c]
|
|
14
|
+
- Updated dependencies [e04e6e76a]
|
|
15
|
+
- Updated dependencies [81c66e4a4]
|
|
16
|
+
- Updated dependencies [2c305b6f5]
|
|
17
|
+
- @modern-js/utils@1.16.0
|
|
18
|
+
- @modern-js/webpack@1.16.0
|
|
19
|
+
- @modern-js/server-utils@1.16.0
|
|
20
|
+
- @modern-js/prod-server@1.16.0
|
|
21
|
+
|
|
3
22
|
## 1.15.0
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
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
|
+
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
|
+
import path from 'path';
|
|
8
|
+
import { resolveBabelConfig } from '@modern-js/server-utils';
|
|
9
|
+
const registerDirs = ['./api', './server', './config/mock', './shared'];
|
|
10
|
+
export const enableRegister = (projectRoot, config) => {
|
|
11
|
+
const TS_CONFIG_FILENAME = `tsconfig.json`;
|
|
12
|
+
const tsconfigPath = path.resolve(projectRoot, TS_CONFIG_FILENAME);
|
|
13
|
+
const babelConfig = resolveBabelConfig(projectRoot, config, {
|
|
14
|
+
tsconfigPath,
|
|
15
|
+
syntax: 'es6+',
|
|
16
|
+
type: 'commonjs'
|
|
17
|
+
});
|
|
18
|
+
return require('@babel/register')(_objectSpread(_objectSpread({}, babelConfig), {}, {
|
|
19
|
+
only: [function (filePath) {
|
|
20
|
+
// TODO: wait params
|
|
21
|
+
// FIXME: 删除hardcode,根据 AppContext 中的 metaName 设置路径
|
|
22
|
+
if (filePath.includes(`node_modules${path.sep}.modern-js`)) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return registerDirs.some(registerDir => filePath.startsWith(path.join(projectRoot, registerDir)));
|
|
27
|
+
}],
|
|
28
|
+
extensions: ['.js', '.ts'],
|
|
29
|
+
babelrc: false,
|
|
30
|
+
configFile: false,
|
|
31
|
+
root: projectRoot
|
|
32
|
+
}));
|
|
33
|
+
};
|
|
@@ -1,9 +1,5 @@
|
|
|
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
2
|
|
|
3
|
-
import { webpack } from '@modern-js/webpack';
|
|
4
|
-
const {
|
|
5
|
-
EntryPlugin
|
|
6
|
-
} = webpack;
|
|
7
3
|
export default class DevServerPlugin {
|
|
8
4
|
constructor(options) {
|
|
9
5
|
_defineProperty(this, "options", void 0);
|
|
@@ -20,7 +16,7 @@ export default class DevServerPlugin {
|
|
|
20
16
|
const port = client.port ? `&port=${client.port}` : '';
|
|
21
17
|
const clientEntry = `${require.resolve("../hmr-client")}?${host}${path}${port}`; // use a hook to add entries if available
|
|
22
18
|
|
|
23
|
-
new EntryPlugin(compiler.context, clientEntry, {
|
|
19
|
+
new compiler.webpack.EntryPlugin(compiler.context, clientEntry, {
|
|
24
20
|
name: undefined
|
|
25
21
|
}).apply(compiler);
|
|
26
22
|
}
|
|
@@ -32,11 +28,14 @@ export default class DevServerPlugin {
|
|
|
32
28
|
|
|
33
29
|
|
|
34
30
|
const compilerOptions = compiler.options;
|
|
31
|
+
const {
|
|
32
|
+
HotModuleReplacementPlugin
|
|
33
|
+
} = compiler.webpack;
|
|
35
34
|
compilerOptions.plugins = compilerOptions.plugins || [];
|
|
36
35
|
|
|
37
|
-
if (!compilerOptions.plugins.find(p => p.constructor ===
|
|
36
|
+
if (!compilerOptions.plugins.find(p => p.constructor === HotModuleReplacementPlugin)) {
|
|
38
37
|
// apply the HMR plugin, if it didn't exist before.
|
|
39
|
-
const plugin = new
|
|
38
|
+
const plugin = new HotModuleReplacementPlugin();
|
|
40
39
|
plugin.apply(compiler);
|
|
41
40
|
}
|
|
42
41
|
}
|
|
@@ -8,6 +8,7 @@ import stripAnsi from '@modern-js/utils/strip-ansi';
|
|
|
8
8
|
import { formatWebpackMessages } from '@modern-js/utils/format';
|
|
9
9
|
import { createSocketUrl } from "./createSocketUrl"; // declare any to fix the type of `module.hot`
|
|
10
10
|
|
|
11
|
+
// TODO hadRuntimeError should be fixed.
|
|
11
12
|
// We need to keep track of if there has been a runtime error.
|
|
12
13
|
// Essentially, we cannot guarantee application state was not corrupted by the
|
|
13
14
|
// runtime error. To prevent confusing behavior, we forcibly reload the entire
|
|
@@ -171,11 +172,9 @@ function tryApplyUpdates() {
|
|
|
171
172
|
}
|
|
172
173
|
|
|
173
174
|
function handleApplyUpdates(err, updatedModules) {
|
|
174
|
-
|
|
175
|
-
const hasReactRefresh = process.env.FAST_REFRESH;
|
|
176
|
-
const wantsForcedReload = err || !updatedModules || hadRuntimeError; // React refresh can handle hot-reloading over errors.
|
|
175
|
+
const wantsForcedReload = err || !updatedModules || hadRuntimeError;
|
|
177
176
|
|
|
178
|
-
if (
|
|
177
|
+
if (wantsForcedReload) {
|
|
179
178
|
window.location.reload();
|
|
180
179
|
return;
|
|
181
180
|
}
|
|
@@ -8,13 +8,13 @@ import { createServer } from 'http';
|
|
|
8
8
|
import path from 'path';
|
|
9
9
|
import { createServer as createHttpsServer } from 'https';
|
|
10
10
|
import { API_DIR, SERVER_DIR, SHARED_DIR } from '@modern-js/utils';
|
|
11
|
-
import webpackDevMiddleware from '@modern-js/
|
|
11
|
+
import webpackDevMiddleware from '@modern-js/utils/webpack-dev-middleware';
|
|
12
12
|
import { createProxyHandler, ModernServer, AGGRED_DIR } from '@modern-js/prod-server';
|
|
13
13
|
import { getDefaultDevOptions } from "../constants";
|
|
14
14
|
import { createMockHandler } from "../dev-tools/mock";
|
|
15
15
|
import SocketServer from "../dev-tools/socket-server";
|
|
16
16
|
import DevServerPlugin from "../dev-tools/dev-server-plugin";
|
|
17
|
-
import { enableRegister } from "../dev-tools/register";
|
|
17
|
+
import { enableRegister } from "../dev-tools/babel/register";
|
|
18
18
|
import Watcher, { mergeWatchOptions } from "../dev-tools/watcher";
|
|
19
19
|
export class ModernDevServer extends ModernServer {
|
|
20
20
|
constructor(options) {
|
|
@@ -241,14 +241,30 @@ export class ModernDevServer extends ModernServer {
|
|
|
241
241
|
return this.setupDevMiddleware(compiler);
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
+
isClientCompiler(compiler) {
|
|
245
|
+
const {
|
|
246
|
+
target
|
|
247
|
+
} = compiler.options; // if target not contains `node`, it's a client compiler
|
|
248
|
+
|
|
249
|
+
if (target) {
|
|
250
|
+
if (Array.isArray(target)) {
|
|
251
|
+
return !target.includes('node');
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return target !== 'node';
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return compiler.name === 'client';
|
|
258
|
+
}
|
|
259
|
+
|
|
244
260
|
setupDevServerPlugin(compiler) {
|
|
245
261
|
const {
|
|
246
262
|
dev: devConf
|
|
247
|
-
} = this;
|
|
263
|
+
} = this; // apply dev server to client compiler, add hmr client to entry.
|
|
248
264
|
|
|
249
265
|
if (compiler.compilers) {
|
|
250
266
|
compiler.compilers.forEach(target => {
|
|
251
|
-
if (target
|
|
267
|
+
if (this.isClientCompiler(target)) {
|
|
252
268
|
new DevServerPlugin(devConf).apply(target);
|
|
253
269
|
}
|
|
254
270
|
});
|
package/dist/js/modern/types.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.enableRegister = void 0;
|
|
7
|
+
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
|
|
10
|
+
var _serverUtils = require("@modern-js/server-utils");
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
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; }
|
|
15
|
+
|
|
16
|
+
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; }
|
|
17
|
+
|
|
18
|
+
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; }
|
|
19
|
+
|
|
20
|
+
const registerDirs = ['./api', './server', './config/mock', './shared'];
|
|
21
|
+
|
|
22
|
+
const enableRegister = (projectRoot, config) => {
|
|
23
|
+
const TS_CONFIG_FILENAME = `tsconfig.json`;
|
|
24
|
+
|
|
25
|
+
const tsconfigPath = _path.default.resolve(projectRoot, TS_CONFIG_FILENAME);
|
|
26
|
+
|
|
27
|
+
const babelConfig = (0, _serverUtils.resolveBabelConfig)(projectRoot, config, {
|
|
28
|
+
tsconfigPath,
|
|
29
|
+
syntax: 'es6+',
|
|
30
|
+
type: 'commonjs'
|
|
31
|
+
});
|
|
32
|
+
return require('@babel/register')(_objectSpread(_objectSpread({}, babelConfig), {}, {
|
|
33
|
+
only: [function (filePath) {
|
|
34
|
+
// TODO: wait params
|
|
35
|
+
// FIXME: 删除hardcode,根据 AppContext 中的 metaName 设置路径
|
|
36
|
+
if (filePath.includes(`node_modules${_path.default.sep}.modern-js`)) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return registerDirs.some(registerDir => filePath.startsWith(_path.default.join(projectRoot, registerDir)));
|
|
41
|
+
}],
|
|
42
|
+
extensions: ['.js', '.ts'],
|
|
43
|
+
babelrc: false,
|
|
44
|
+
configFile: false,
|
|
45
|
+
root: projectRoot
|
|
46
|
+
}));
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
exports.enableRegister = enableRegister;
|
|
@@ -5,14 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _webpack = require("@modern-js/webpack");
|
|
9
|
-
|
|
10
8
|
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; }
|
|
11
9
|
|
|
12
|
-
const {
|
|
13
|
-
EntryPlugin
|
|
14
|
-
} = _webpack.webpack;
|
|
15
|
-
|
|
16
10
|
class DevServerPlugin {
|
|
17
11
|
constructor(options) {
|
|
18
12
|
_defineProperty(this, "options", void 0);
|
|
@@ -29,7 +23,7 @@ class DevServerPlugin {
|
|
|
29
23
|
const port = client.port ? `&port=${client.port}` : '';
|
|
30
24
|
const clientEntry = `${require.resolve("../hmr-client")}?${host}${path}${port}`; // use a hook to add entries if available
|
|
31
25
|
|
|
32
|
-
new EntryPlugin(compiler.context, clientEntry, {
|
|
26
|
+
new compiler.webpack.EntryPlugin(compiler.context, clientEntry, {
|
|
33
27
|
name: undefined
|
|
34
28
|
}).apply(compiler);
|
|
35
29
|
}
|
|
@@ -41,11 +35,14 @@ class DevServerPlugin {
|
|
|
41
35
|
|
|
42
36
|
|
|
43
37
|
const compilerOptions = compiler.options;
|
|
38
|
+
const {
|
|
39
|
+
HotModuleReplacementPlugin
|
|
40
|
+
} = compiler.webpack;
|
|
44
41
|
compilerOptions.plugins = compilerOptions.plugins || [];
|
|
45
42
|
|
|
46
|
-
if (!compilerOptions.plugins.find(p => p.constructor ===
|
|
43
|
+
if (!compilerOptions.plugins.find(p => p.constructor === HotModuleReplacementPlugin)) {
|
|
47
44
|
// apply the HMR plugin, if it didn't exist before.
|
|
48
|
-
const plugin = new
|
|
45
|
+
const plugin = new HotModuleReplacementPlugin();
|
|
49
46
|
plugin.apply(compiler);
|
|
50
47
|
}
|
|
51
48
|
}
|
|
@@ -14,6 +14,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
14
14
|
*
|
|
15
15
|
* Tips: this package will be bundled and running in the browser, do not import from the entry of @modern-js/utils.
|
|
16
16
|
*/
|
|
17
|
+
// TODO hadRuntimeError should be fixed.
|
|
17
18
|
// We need to keep track of if there has been a runtime error.
|
|
18
19
|
// Essentially, we cannot guarantee application state was not corrupted by the
|
|
19
20
|
// runtime error. To prevent confusing behavior, we forcibly reload the entire
|
|
@@ -177,11 +178,9 @@ function tryApplyUpdates() {
|
|
|
177
178
|
}
|
|
178
179
|
|
|
179
180
|
function handleApplyUpdates(err, updatedModules) {
|
|
180
|
-
|
|
181
|
-
const hasReactRefresh = process.env.FAST_REFRESH;
|
|
182
|
-
const wantsForcedReload = err || !updatedModules || hadRuntimeError; // React refresh can handle hot-reloading over errors.
|
|
181
|
+
const wantsForcedReload = err || !updatedModules || hadRuntimeError;
|
|
183
182
|
|
|
184
|
-
if (
|
|
183
|
+
if (wantsForcedReload) {
|
|
185
184
|
window.location.reload();
|
|
186
185
|
return;
|
|
187
186
|
}
|
|
@@ -13,7 +13,7 @@ var _https = require("https");
|
|
|
13
13
|
|
|
14
14
|
var _utils = require("@modern-js/utils");
|
|
15
15
|
|
|
16
|
-
var _webpackDevMiddleware = _interopRequireDefault(require("@modern-js/
|
|
16
|
+
var _webpackDevMiddleware = _interopRequireDefault(require("@modern-js/utils/webpack-dev-middleware"));
|
|
17
17
|
|
|
18
18
|
var _prodServer = require("@modern-js/prod-server");
|
|
19
19
|
|
|
@@ -25,7 +25,7 @@ var _socketServer = _interopRequireDefault(require("../dev-tools/socket-server")
|
|
|
25
25
|
|
|
26
26
|
var _devServerPlugin = _interopRequireDefault(require("../dev-tools/dev-server-plugin"));
|
|
27
27
|
|
|
28
|
-
var _register = require("../dev-tools/register");
|
|
28
|
+
var _register = require("../dev-tools/babel/register");
|
|
29
29
|
|
|
30
30
|
var _watcher = _interopRequireWildcard(require("../dev-tools/watcher"));
|
|
31
31
|
|
|
@@ -268,14 +268,30 @@ class ModernDevServer extends _prodServer.ModernServer {
|
|
|
268
268
|
return this.setupDevMiddleware(compiler);
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
+
isClientCompiler(compiler) {
|
|
272
|
+
const {
|
|
273
|
+
target
|
|
274
|
+
} = compiler.options; // if target not contains `node`, it's a client compiler
|
|
275
|
+
|
|
276
|
+
if (target) {
|
|
277
|
+
if (Array.isArray(target)) {
|
|
278
|
+
return !target.includes('node');
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return target !== 'node';
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
return compiler.name === 'client';
|
|
285
|
+
}
|
|
286
|
+
|
|
271
287
|
setupDevServerPlugin(compiler) {
|
|
272
288
|
const {
|
|
273
289
|
dev: devConf
|
|
274
|
-
} = this;
|
|
290
|
+
} = this; // apply dev server to client compiler, add hmr client to entry.
|
|
275
291
|
|
|
276
292
|
if (compiler.compilers) {
|
|
277
293
|
compiler.compilers.forEach(target => {
|
|
278
|
-
if (target
|
|
294
|
+
if (this.isClientCompiler(target)) {
|
|
279
295
|
new _devServerPlugin.default(devConf).apply(target);
|
|
280
296
|
}
|
|
281
297
|
});
|
package/dist/js/node/types.js
CHANGED
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { DevServerOptions } from '../types';
|
|
1
|
+
import type webpack from 'webpack';
|
|
2
|
+
import type { DevServerOptions } from '../types';
|
|
3
3
|
export default class DevServerPlugin {
|
|
4
4
|
private readonly options;
|
|
5
5
|
constructor(options: DevServerOptions);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Server } from 'http';
|
|
3
3
|
import ws from 'ws';
|
|
4
|
-
import type
|
|
5
|
-
import { DevServerOptions } from '../types';
|
|
4
|
+
import type webpack from 'webpack';
|
|
5
|
+
import type { DevServerOptions } from '../types';
|
|
6
6
|
export default class SocketServer {
|
|
7
7
|
private wsServer;
|
|
8
8
|
private readonly sockets;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
1
|
+
import type webpack from 'webpack';
|
|
2
|
+
import type { ModernServerOptions } from '@modern-js/prod-server';
|
|
3
3
|
export declare type DevServerOptions = {
|
|
4
4
|
client: {
|
|
5
5
|
path?: string;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.16.0-alpha.underfin.001",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -30,19 +30,18 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@babel/core": "^7.18.0",
|
|
32
32
|
"@babel/register": "^7.17.7",
|
|
33
|
-
"@modern-js/prod-server": "1.
|
|
34
|
-
"@modern-js/server-utils": "1.
|
|
35
|
-
"@modern-js/utils": "1.
|
|
36
|
-
"@modern-js/webpack": "1.15.0",
|
|
33
|
+
"@modern-js/prod-server": "1.16.0",
|
|
34
|
+
"@modern-js/server-utils": "1.16.0",
|
|
35
|
+
"@modern-js/utils": "1.16.0-alpha.underfin.001",
|
|
37
36
|
"devcert": "^1.2.2",
|
|
38
37
|
"minimatch": "^3.0.4",
|
|
39
38
|
"path-to-regexp": "^6.2.0",
|
|
40
39
|
"ws": "^8.2.0"
|
|
41
40
|
},
|
|
42
41
|
"devDependencies": {
|
|
43
|
-
"@modern-js/core": "1.
|
|
44
|
-
"@modern-js/server-core": "1.
|
|
45
|
-
"@modern-js/types": "1.
|
|
42
|
+
"@modern-js/core": "1.16.0",
|
|
43
|
+
"@modern-js/server-core": "1.16.0",
|
|
44
|
+
"@modern-js/types": "1.16.0",
|
|
46
45
|
"@scripts/build": "1.15.0",
|
|
47
46
|
"@scripts/jest-config": "1.15.0",
|
|
48
47
|
"@types/jest": "^27",
|
|
@@ -50,15 +49,9 @@
|
|
|
50
49
|
"@types/node": "^14",
|
|
51
50
|
"@types/ws": "^7.4.7",
|
|
52
51
|
"jest": "^27",
|
|
53
|
-
"ts-node": "^10.1.0",
|
|
54
|
-
"tsconfig-paths": "3.14.1",
|
|
55
52
|
"typescript": "^4",
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
},
|
|
59
|
-
"peerDependencies": {
|
|
60
|
-
"ts-node": "^10.1.0",
|
|
61
|
-
"tsconfig-paths": "3.14.1"
|
|
53
|
+
"websocket": "^1",
|
|
54
|
+
"webpack": "^5.71.0"
|
|
62
55
|
},
|
|
63
56
|
"sideEffects": false,
|
|
64
57
|
"modernConfig": {
|
|
@@ -68,8 +61,7 @@
|
|
|
68
61
|
},
|
|
69
62
|
"publishConfig": {
|
|
70
63
|
"registry": "https://registry.npmjs.org/",
|
|
71
|
-
"access": "public"
|
|
72
|
-
"types": "./dist/types/index.d.ts"
|
|
64
|
+
"access": "public"
|
|
73
65
|
},
|
|
74
66
|
"wireit": {
|
|
75
67
|
"build": {
|
|
@@ -1,94 +0,0 @@
|
|
|
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
|
-
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
|
-
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
|
-
import path from 'path';
|
|
8
|
-
import { resolveBabelConfig } from '@modern-js/server-utils';
|
|
9
|
-
import { fs, getAlias } from '@modern-js/utils';
|
|
10
|
-
|
|
11
|
-
const checkDep = (depName, paths) => {
|
|
12
|
-
let packagePath = '';
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
packagePath = require.resolve('ts-node', {
|
|
16
|
-
paths
|
|
17
|
-
});
|
|
18
|
-
} catch (error) {}
|
|
19
|
-
|
|
20
|
-
return Boolean(packagePath);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export const enableRegister = (projectRoot, config // eslint-disable-next-line consistent-return
|
|
24
|
-
) => {
|
|
25
|
-
const registerDirs = ['./api', './server', './config/mock', './shared'];
|
|
26
|
-
const TS_CONFIG_FILENAME = `tsconfig.json`;
|
|
27
|
-
const tsconfigPath = path.resolve(projectRoot, TS_CONFIG_FILENAME);
|
|
28
|
-
const isTsProject = fs.existsSync(tsconfigPath);
|
|
29
|
-
const existTsNode = checkDep('ts-node', [projectRoot]);
|
|
30
|
-
const existTsConfigPaths = checkDep('tsconfig-paths', [projectRoot]);
|
|
31
|
-
|
|
32
|
-
if (isTsProject && existTsNode && existTsConfigPaths) {
|
|
33
|
-
const tsNode = require('ts-node');
|
|
34
|
-
|
|
35
|
-
const tsConfigPaths = require('tsconfig-paths');
|
|
36
|
-
|
|
37
|
-
const {
|
|
38
|
-
alias
|
|
39
|
-
} = config.source;
|
|
40
|
-
const aliasOption = getAlias(alias || {}, {
|
|
41
|
-
appDirectory: projectRoot,
|
|
42
|
-
tsconfigPath
|
|
43
|
-
});
|
|
44
|
-
const {
|
|
45
|
-
paths = {},
|
|
46
|
-
absoluteBaseUrl = './'
|
|
47
|
-
} = aliasOption;
|
|
48
|
-
const tsPaths = Object.keys(paths).reduce((o, key) => {
|
|
49
|
-
let tsPath = paths[key];
|
|
50
|
-
|
|
51
|
-
if (typeof tsPath === 'string' && path.isAbsolute(tsPath)) {
|
|
52
|
-
tsPath = path.relative(absoluteBaseUrl, tsPath);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (typeof tsPath === 'string') {
|
|
56
|
-
tsPath = [tsPath];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return _objectSpread(_objectSpread({}, o), {}, {
|
|
60
|
-
[`${key}`]: tsPath
|
|
61
|
-
});
|
|
62
|
-
}, {});
|
|
63
|
-
tsConfigPaths.register({
|
|
64
|
-
baseUrl: absoluteBaseUrl || './',
|
|
65
|
-
paths: tsPaths
|
|
66
|
-
});
|
|
67
|
-
tsNode.register({
|
|
68
|
-
project: tsconfigPath,
|
|
69
|
-
// for env.d.ts, https://www.npmjs.com/package/ts-node#missing-types
|
|
70
|
-
files: true
|
|
71
|
-
});
|
|
72
|
-
} else {
|
|
73
|
-
const babelConfig = resolveBabelConfig(projectRoot, config, {
|
|
74
|
-
tsconfigPath,
|
|
75
|
-
syntax: 'es6+',
|
|
76
|
-
type: 'commonjs'
|
|
77
|
-
});
|
|
78
|
-
return require('@babel/register')(_objectSpread(_objectSpread({}, babelConfig), {}, {
|
|
79
|
-
only: [function (filePath) {
|
|
80
|
-
// TODO: wait params
|
|
81
|
-
// FIXME: 删除hardcode,根据 AppContext 中的 metaName 设置路径
|
|
82
|
-
if (filePath.includes(`node_modules${path.sep}.modern-js`)) {
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return registerDirs.some(registerDir => filePath.startsWith(path.join(projectRoot, registerDir)));
|
|
87
|
-
}],
|
|
88
|
-
extensions: ['.js', '.ts'],
|
|
89
|
-
babelrc: false,
|
|
90
|
-
configFile: false,
|
|
91
|
-
root: projectRoot
|
|
92
|
-
}));
|
|
93
|
-
}
|
|
94
|
-
};
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.enableRegister = void 0;
|
|
7
|
-
|
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
|
-
var _serverUtils = require("@modern-js/server-utils");
|
|
11
|
-
|
|
12
|
-
var _utils = require("@modern-js/utils");
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
|
-
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
|
-
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
|
-
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
|
-
const checkDep = (depName, paths) => {
|
|
23
|
-
let packagePath = '';
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
packagePath = require.resolve('ts-node', {
|
|
27
|
-
paths
|
|
28
|
-
});
|
|
29
|
-
} catch (error) {}
|
|
30
|
-
|
|
31
|
-
return Boolean(packagePath);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const enableRegister = (projectRoot, config // eslint-disable-next-line consistent-return
|
|
35
|
-
) => {
|
|
36
|
-
const registerDirs = ['./api', './server', './config/mock', './shared'];
|
|
37
|
-
const TS_CONFIG_FILENAME = `tsconfig.json`;
|
|
38
|
-
|
|
39
|
-
const tsconfigPath = _path.default.resolve(projectRoot, TS_CONFIG_FILENAME);
|
|
40
|
-
|
|
41
|
-
const isTsProject = _utils.fs.existsSync(tsconfigPath);
|
|
42
|
-
|
|
43
|
-
const existTsNode = checkDep('ts-node', [projectRoot]);
|
|
44
|
-
const existTsConfigPaths = checkDep('tsconfig-paths', [projectRoot]);
|
|
45
|
-
|
|
46
|
-
if (isTsProject && existTsNode && existTsConfigPaths) {
|
|
47
|
-
const tsNode = require('ts-node');
|
|
48
|
-
|
|
49
|
-
const tsConfigPaths = require('tsconfig-paths');
|
|
50
|
-
|
|
51
|
-
const {
|
|
52
|
-
alias
|
|
53
|
-
} = config.source;
|
|
54
|
-
const aliasOption = (0, _utils.getAlias)(alias || {}, {
|
|
55
|
-
appDirectory: projectRoot,
|
|
56
|
-
tsconfigPath
|
|
57
|
-
});
|
|
58
|
-
const {
|
|
59
|
-
paths = {},
|
|
60
|
-
absoluteBaseUrl = './'
|
|
61
|
-
} = aliasOption;
|
|
62
|
-
const tsPaths = Object.keys(paths).reduce((o, key) => {
|
|
63
|
-
let tsPath = paths[key];
|
|
64
|
-
|
|
65
|
-
if (typeof tsPath === 'string' && _path.default.isAbsolute(tsPath)) {
|
|
66
|
-
tsPath = _path.default.relative(absoluteBaseUrl, tsPath);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (typeof tsPath === 'string') {
|
|
70
|
-
tsPath = [tsPath];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return _objectSpread(_objectSpread({}, o), {}, {
|
|
74
|
-
[`${key}`]: tsPath
|
|
75
|
-
});
|
|
76
|
-
}, {});
|
|
77
|
-
tsConfigPaths.register({
|
|
78
|
-
baseUrl: absoluteBaseUrl || './',
|
|
79
|
-
paths: tsPaths
|
|
80
|
-
});
|
|
81
|
-
tsNode.register({
|
|
82
|
-
project: tsconfigPath,
|
|
83
|
-
// for env.d.ts, https://www.npmjs.com/package/ts-node#missing-types
|
|
84
|
-
files: true
|
|
85
|
-
});
|
|
86
|
-
} else {
|
|
87
|
-
const babelConfig = (0, _serverUtils.resolveBabelConfig)(projectRoot, config, {
|
|
88
|
-
tsconfigPath,
|
|
89
|
-
syntax: 'es6+',
|
|
90
|
-
type: 'commonjs'
|
|
91
|
-
});
|
|
92
|
-
return require('@babel/register')(_objectSpread(_objectSpread({}, babelConfig), {}, {
|
|
93
|
-
only: [function (filePath) {
|
|
94
|
-
// TODO: wait params
|
|
95
|
-
// FIXME: 删除hardcode,根据 AppContext 中的 metaName 设置路径
|
|
96
|
-
if (filePath.includes(`node_modules${_path.default.sep}.modern-js`)) {
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return registerDirs.some(registerDir => filePath.startsWith(_path.default.join(projectRoot, registerDir)));
|
|
101
|
-
}],
|
|
102
|
-
extensions: ['.js', '.ts'],
|
|
103
|
-
babelrc: false,
|
|
104
|
-
configFile: false,
|
|
105
|
-
root: projectRoot
|
|
106
|
-
}));
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
exports.enableRegister = enableRegister;
|