@modern-js/server-utils 1.1.3-rc.0 → 1.2.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 +34 -12
- package/dist/js/modern/index.js +0 -2
- package/dist/js/node/index.js +0 -26
- package/dist/js/treeshaking/index.js +0 -2
- package/dist/types/index.d.ts +0 -2
- package/jest.config.js +7 -0
- package/modern.config.js +1 -14
- package/package.json +11 -9
- package/tests/__snapshots__/babel.test.ts.snap +1 -1
- package/tests/babel.test.ts +1 -1
- package/tests/fixtures/api/_app.ts +1 -1
- package/tests/fixtures/server/index.ts +1 -1
- package/tests/tsconfig.json +1 -3
- package/tsconfig.json +1 -3
- package/dist/js/modern/gather.js +0 -35
- package/dist/js/modern/middleware.js +0 -24
- package/dist/js/modern/requireModule.js +0 -24
- package/dist/js/node/gather.js +0 -55
- package/dist/js/node/middleware.js +0 -36
- package/dist/js/node/requireModule.js +0 -35
- package/dist/js/treeshaking/gather.js +0 -35
- package/dist/js/treeshaking/middleware.js +0 -28
- package/dist/js/treeshaking/requireModule.js +0 -26
- package/dist/types/gather.d.ts +0 -1
- package/dist/types/middleware.d.ts +0 -14
- package/dist/types/requireModule.d.ts +0 -1
- package/src/babel.ts +0 -151
- package/src/gather.ts +0 -30
- package/src/index.ts +0 -3
- package/src/middleware.ts +0 -35
- package/src/requireModule.ts +0 -23
- package/tests/gather.test.ts +0 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,20 +1,42 @@
|
|
|
1
1
|
# @modern-js/server-utils
|
|
2
2
|
|
|
3
|
-
## 1.
|
|
3
|
+
## 1.2.2
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
- Updated dependencies [
|
|
9
|
-
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- @modern-js/
|
|
7
|
+
- bebb39b6: chore: improve devDependencies and peerDependencies
|
|
8
|
+
- Updated dependencies [132f7b53]
|
|
9
|
+
- @modern-js/utils@1.3.7
|
|
10
|
+
|
|
11
|
+
## 1.2.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 83166714: change .npmignore
|
|
16
|
+
- Updated dependencies [83166714]
|
|
17
|
+
- @modern-js/babel-preset-lib@1.2.1
|
|
18
|
+
- @modern-js/plugin@1.2.1
|
|
19
|
+
- @modern-js/utils@1.2.2
|
|
20
|
+
|
|
21
|
+
## 1.2.0
|
|
22
|
+
|
|
23
|
+
### Minor Changes
|
|
24
|
+
|
|
25
|
+
- cfe11628: Make Modern.js self bootstraping
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- 146dcd85: modify server framework plugin hook types and hook context
|
|
30
|
+
- 146dcd85: modify server framework plugin hook types
|
|
31
|
+
- 146dcd85: fix test case in babel compiler
|
|
32
|
+
- 1ebc7ee2: fix: @babel/core version
|
|
33
|
+
- Updated dependencies [2da09c69]
|
|
34
|
+
- Updated dependencies [c3d46ee4]
|
|
35
|
+
- Updated dependencies [cfe11628]
|
|
36
|
+
- Updated dependencies [1ebc7ee2]
|
|
37
|
+
- @modern-js/utils@1.2.0
|
|
38
|
+
- @modern-js/babel-preset-lib@1.2.0
|
|
39
|
+
- @modern-js/plugin@1.2.0
|
|
18
40
|
|
|
19
41
|
## 1.1.2
|
|
20
42
|
|
package/dist/js/modern/index.js
CHANGED
package/dist/js/node/index.js
CHANGED
|
@@ -4,32 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
|
|
7
|
-
var _middleware = require("./middleware");
|
|
8
|
-
|
|
9
|
-
Object.keys(_middleware).forEach(function (key) {
|
|
10
|
-
if (key === "default" || key === "__esModule") return;
|
|
11
|
-
if (key in exports && exports[key] === _middleware[key]) return;
|
|
12
|
-
Object.defineProperty(exports, key, {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _middleware[key];
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
var _gather = require("./gather");
|
|
21
|
-
|
|
22
|
-
Object.keys(_gather).forEach(function (key) {
|
|
23
|
-
if (key === "default" || key === "__esModule") return;
|
|
24
|
-
if (key in exports && exports[key] === _gather[key]) return;
|
|
25
|
-
Object.defineProperty(exports, key, {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
get: function () {
|
|
28
|
-
return _gather[key];
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
7
|
var _babel = require("./babel");
|
|
34
8
|
|
|
35
9
|
Object.keys(_babel).forEach(function (key) {
|
package/dist/types/index.d.ts
CHANGED
package/jest.config.js
ADDED
package/modern.config.js
CHANGED
|
@@ -1,15 +1,2 @@
|
|
|
1
1
|
/** @type {import('@modern-js/module-tools').UserConfig} */
|
|
2
|
-
module.exports = {
|
|
3
|
-
testing: {
|
|
4
|
-
jest: {
|
|
5
|
-
collectCoverage: true,
|
|
6
|
-
collectCoverageFrom: ['./src/**/*.ts'],
|
|
7
|
-
coveragePathIgnorePatterns: ['/node_modules/'],
|
|
8
|
-
testEnvironment: 'jsdom',
|
|
9
|
-
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json'],
|
|
10
|
-
transform: {
|
|
11
|
-
'^.+\\.tsx?$': 'ts-jest',
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
};
|
|
2
|
+
module.exports = {};
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.2.2",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"exports": {
|
|
21
21
|
".": {
|
|
22
22
|
"node": {
|
|
23
|
+
"jsnext:source": "./src/index.ts",
|
|
23
24
|
"import": "./dist/js/modern/index.js",
|
|
24
25
|
"require": "./dist/js/node/index.js"
|
|
25
26
|
},
|
|
@@ -28,21 +29,21 @@
|
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
30
31
|
"@babel/compat-data": "^7.15.0",
|
|
31
|
-
"@babel/core": "
|
|
32
|
+
"@babel/core": "7.16.7",
|
|
32
33
|
"@babel/plugin-proposal-class-properties": "^7.14.5",
|
|
33
34
|
"@babel/plugin-proposal-decorators": "^7.15.4",
|
|
34
35
|
"@babel/preset-env": "^7.15.0",
|
|
35
36
|
"@babel/preset-typescript": "^7.15.0",
|
|
36
37
|
"@babel/runtime": "^7",
|
|
37
|
-
"@modern-js/babel-preset-lib": "^1.1
|
|
38
|
-
"@modern-js/plugin": "^1.1
|
|
39
|
-
"@modern-js/utils": "^1.
|
|
38
|
+
"@modern-js/babel-preset-lib": "^1.2.1",
|
|
39
|
+
"@modern-js/plugin": "^1.2.1",
|
|
40
|
+
"@modern-js/utils": "^1.3.7",
|
|
40
41
|
"babel-plugin-module-resolver": "^4.1.0",
|
|
41
42
|
"babel-plugin-transform-typescript-metadata": "^0.3.2",
|
|
42
43
|
"json5": "^2.2.0"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
|
-
"@modern-js/core": "
|
|
46
|
+
"@modern-js/core": "1.6.1",
|
|
46
47
|
"@types/babel__core": "^7.1.15",
|
|
47
48
|
"@types/jest": "^26",
|
|
48
49
|
"@types/node": "^14",
|
|
@@ -50,8 +51,9 @@
|
|
|
50
51
|
"@types/react-dom": "^17",
|
|
51
52
|
"ts-jest": "^27.0.4",
|
|
52
53
|
"typescript": "^4",
|
|
53
|
-
"@
|
|
54
|
-
"
|
|
54
|
+
"@scripts/build": "0.0.0",
|
|
55
|
+
"jest": "^27",
|
|
56
|
+
"@scripts/jest-config": "0.0.0"
|
|
55
57
|
},
|
|
56
58
|
"sideEffects": false,
|
|
57
59
|
"publishConfig": {
|
|
@@ -61,7 +63,7 @@
|
|
|
61
63
|
"scripts": {
|
|
62
64
|
"new": "modern new",
|
|
63
65
|
"build": "modern build",
|
|
64
|
-
"test": "
|
|
66
|
+
"test": "jest --passWithNoTests"
|
|
65
67
|
},
|
|
66
68
|
"readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
|
|
67
69
|
}
|
package/tests/babel.test.ts
CHANGED
package/tests/tsconfig.json
CHANGED
package/tsconfig.json
CHANGED
package/dist/js/modern/gather.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { createMiddlewareCollecter } from "./middleware";
|
|
3
|
-
import { requireModule } from "./requireModule";
|
|
4
|
-
const API_DIR_PATH = 'api';
|
|
5
|
-
const API_APP_NAME = '_app';
|
|
6
|
-
const SERVER_DIR_PATH = 'server';
|
|
7
|
-
const WEB_APP_NAME = 'index';
|
|
8
|
-
export const gather = pwd => {
|
|
9
|
-
const {
|
|
10
|
-
getMiddlewares,
|
|
11
|
-
addAPIMiddleware,
|
|
12
|
-
addWebMiddleware
|
|
13
|
-
} = createMiddlewareCollecter();
|
|
14
|
-
const apiPath = path.resolve(pwd, API_DIR_PATH);
|
|
15
|
-
const apiAppPath = path.resolve(apiPath, API_APP_NAME);
|
|
16
|
-
const serverPath = path.resolve(pwd, SERVER_DIR_PATH);
|
|
17
|
-
const webAppPath = path.resolve(serverPath, WEB_APP_NAME);
|
|
18
|
-
const apiAttacher = requireModule(apiAppPath);
|
|
19
|
-
|
|
20
|
-
if (apiAttacher) {
|
|
21
|
-
apiAttacher({
|
|
22
|
-
addMiddleware: addAPIMiddleware
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const webAttacher = requireModule(webAppPath);
|
|
27
|
-
|
|
28
|
-
if (webAttacher) {
|
|
29
|
-
webAttacher({
|
|
30
|
-
addMiddleware: addWebMiddleware
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return getMiddlewares();
|
|
35
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export const createMiddlewareCollecter = () => {
|
|
2
|
-
const webMiddlewares = [];
|
|
3
|
-
const apiMiddlewares = [];
|
|
4
|
-
|
|
5
|
-
const addWebMiddleware = input => {
|
|
6
|
-
webMiddlewares.push(input);
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
const addAPIMiddleware = input => {
|
|
10
|
-
apiMiddlewares.push(input);
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const getMiddlewares = () => ({
|
|
14
|
-
web: webMiddlewares,
|
|
15
|
-
api: apiMiddlewares
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
getMiddlewares,
|
|
20
|
-
addWebMiddleware,
|
|
21
|
-
addAPIMiddleware
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
export const hook = attacher => attacher;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { findExists } from '@modern-js/utils';
|
|
2
|
-
const FILE_EXTENSIONS = ['.ts', '.js'];
|
|
3
|
-
export const requireModule = filename => {
|
|
4
|
-
const exist = findExists(FILE_EXTENSIONS.map(ext => `${filename}${ext}`));
|
|
5
|
-
|
|
6
|
-
if (!exist) {
|
|
7
|
-
return null;
|
|
8
|
-
} // throw errors directly if require fail
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const mod = require(exist);
|
|
12
|
-
|
|
13
|
-
return interopRequire(mod);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
function interopRequire(obj) {
|
|
17
|
-
return interopRequireDefault(obj).default;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function interopRequireDefault(obj) {
|
|
21
|
-
return obj !== null && obj !== void 0 && obj.__esModule ? obj : {
|
|
22
|
-
default: obj
|
|
23
|
-
};
|
|
24
|
-
}
|
package/dist/js/node/gather.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.gather = void 0;
|
|
7
|
-
|
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
|
-
var _middleware = require("./middleware");
|
|
11
|
-
|
|
12
|
-
var _requireModule = require("./requireModule");
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
|
-
const API_DIR_PATH = 'api';
|
|
17
|
-
const API_APP_NAME = '_app';
|
|
18
|
-
const SERVER_DIR_PATH = 'server';
|
|
19
|
-
const WEB_APP_NAME = 'index';
|
|
20
|
-
|
|
21
|
-
const gather = pwd => {
|
|
22
|
-
const {
|
|
23
|
-
getMiddlewares,
|
|
24
|
-
addAPIMiddleware,
|
|
25
|
-
addWebMiddleware
|
|
26
|
-
} = (0, _middleware.createMiddlewareCollecter)();
|
|
27
|
-
|
|
28
|
-
const apiPath = _path.default.resolve(pwd, API_DIR_PATH);
|
|
29
|
-
|
|
30
|
-
const apiAppPath = _path.default.resolve(apiPath, API_APP_NAME);
|
|
31
|
-
|
|
32
|
-
const serverPath = _path.default.resolve(pwd, SERVER_DIR_PATH);
|
|
33
|
-
|
|
34
|
-
const webAppPath = _path.default.resolve(serverPath, WEB_APP_NAME);
|
|
35
|
-
|
|
36
|
-
const apiAttacher = (0, _requireModule.requireModule)(apiAppPath);
|
|
37
|
-
|
|
38
|
-
if (apiAttacher) {
|
|
39
|
-
apiAttacher({
|
|
40
|
-
addMiddleware: addAPIMiddleware
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const webAttacher = (0, _requireModule.requireModule)(webAppPath);
|
|
45
|
-
|
|
46
|
-
if (webAttacher) {
|
|
47
|
-
webAttacher({
|
|
48
|
-
addMiddleware: addWebMiddleware
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return getMiddlewares();
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
exports.gather = gather;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.hook = exports.createMiddlewareCollecter = void 0;
|
|
7
|
-
|
|
8
|
-
const createMiddlewareCollecter = () => {
|
|
9
|
-
const webMiddlewares = [];
|
|
10
|
-
const apiMiddlewares = [];
|
|
11
|
-
|
|
12
|
-
const addWebMiddleware = input => {
|
|
13
|
-
webMiddlewares.push(input);
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const addAPIMiddleware = input => {
|
|
17
|
-
apiMiddlewares.push(input);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const getMiddlewares = () => ({
|
|
21
|
-
web: webMiddlewares,
|
|
22
|
-
api: apiMiddlewares
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
getMiddlewares,
|
|
27
|
-
addWebMiddleware,
|
|
28
|
-
addAPIMiddleware
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
exports.createMiddlewareCollecter = createMiddlewareCollecter;
|
|
33
|
-
|
|
34
|
-
const hook = attacher => attacher;
|
|
35
|
-
|
|
36
|
-
exports.hook = hook;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.requireModule = void 0;
|
|
7
|
-
|
|
8
|
-
var _utils = require("@modern-js/utils");
|
|
9
|
-
|
|
10
|
-
const FILE_EXTENSIONS = ['.ts', '.js'];
|
|
11
|
-
|
|
12
|
-
const requireModule = filename => {
|
|
13
|
-
const exist = (0, _utils.findExists)(FILE_EXTENSIONS.map(ext => `${filename}${ext}`));
|
|
14
|
-
|
|
15
|
-
if (!exist) {
|
|
16
|
-
return null;
|
|
17
|
-
} // throw errors directly if require fail
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const mod = require(exist);
|
|
21
|
-
|
|
22
|
-
return interopRequire(mod);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
exports.requireModule = requireModule;
|
|
26
|
-
|
|
27
|
-
function interopRequire(obj) {
|
|
28
|
-
return interopRequireDefault(obj).default;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function interopRequireDefault(obj) {
|
|
32
|
-
return obj !== null && obj !== void 0 && obj.__esModule ? obj : {
|
|
33
|
-
default: obj
|
|
34
|
-
};
|
|
35
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { createMiddlewareCollecter } from "./middleware";
|
|
3
|
-
import { requireModule } from "./requireModule";
|
|
4
|
-
var API_DIR_PATH = 'api';
|
|
5
|
-
var API_APP_NAME = '_app';
|
|
6
|
-
var SERVER_DIR_PATH = 'server';
|
|
7
|
-
var WEB_APP_NAME = 'index';
|
|
8
|
-
export var gather = function gather(pwd) {
|
|
9
|
-
var _createMiddlewareColl = createMiddlewareCollecter(),
|
|
10
|
-
getMiddlewares = _createMiddlewareColl.getMiddlewares,
|
|
11
|
-
addAPIMiddleware = _createMiddlewareColl.addAPIMiddleware,
|
|
12
|
-
addWebMiddleware = _createMiddlewareColl.addWebMiddleware;
|
|
13
|
-
|
|
14
|
-
var apiPath = path.resolve(pwd, API_DIR_PATH);
|
|
15
|
-
var apiAppPath = path.resolve(apiPath, API_APP_NAME);
|
|
16
|
-
var serverPath = path.resolve(pwd, SERVER_DIR_PATH);
|
|
17
|
-
var webAppPath = path.resolve(serverPath, WEB_APP_NAME);
|
|
18
|
-
var apiAttacher = requireModule(apiAppPath);
|
|
19
|
-
|
|
20
|
-
if (apiAttacher) {
|
|
21
|
-
apiAttacher({
|
|
22
|
-
addMiddleware: addAPIMiddleware
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
var webAttacher = requireModule(webAppPath);
|
|
27
|
-
|
|
28
|
-
if (webAttacher) {
|
|
29
|
-
webAttacher({
|
|
30
|
-
addMiddleware: addWebMiddleware
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return getMiddlewares();
|
|
35
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export var createMiddlewareCollecter = function createMiddlewareCollecter() {
|
|
2
|
-
var webMiddlewares = [];
|
|
3
|
-
var apiMiddlewares = [];
|
|
4
|
-
|
|
5
|
-
var addWebMiddleware = function addWebMiddleware(input) {
|
|
6
|
-
webMiddlewares.push(input);
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
var addAPIMiddleware = function addAPIMiddleware(input) {
|
|
10
|
-
apiMiddlewares.push(input);
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
var getMiddlewares = function getMiddlewares() {
|
|
14
|
-
return {
|
|
15
|
-
web: webMiddlewares,
|
|
16
|
-
api: apiMiddlewares
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
getMiddlewares: getMiddlewares,
|
|
22
|
-
addWebMiddleware: addWebMiddleware,
|
|
23
|
-
addAPIMiddleware: addAPIMiddleware
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
export var hook = function hook(attacher) {
|
|
27
|
-
return attacher;
|
|
28
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { findExists } from '@modern-js/utils';
|
|
2
|
-
var FILE_EXTENSIONS = ['.ts', '.js'];
|
|
3
|
-
export var requireModule = function requireModule(filename) {
|
|
4
|
-
var exist = findExists(FILE_EXTENSIONS.map(function (ext) {
|
|
5
|
-
return "".concat(filename).concat(ext);
|
|
6
|
-
}));
|
|
7
|
-
|
|
8
|
-
if (!exist) {
|
|
9
|
-
return null;
|
|
10
|
-
} // throw errors directly if require fail
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var mod = require(exist);
|
|
14
|
-
|
|
15
|
-
return interopRequire(mod);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
function interopRequire(obj) {
|
|
19
|
-
return interopRequireDefault(obj)["default"];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function interopRequireDefault(obj) {
|
|
23
|
-
return obj !== null && obj !== void 0 && obj.__esModule ? obj : {
|
|
24
|
-
"default": obj
|
|
25
|
-
};
|
|
26
|
-
}
|
package/dist/types/gather.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const gather: (pwd: string) => import("./middleware").CollectMiddlewaresResult;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare type CollectMiddlewaresResult = {
|
|
2
|
-
web: any[];
|
|
3
|
-
api: any[];
|
|
4
|
-
};
|
|
5
|
-
export declare const createMiddlewareCollecter: () => {
|
|
6
|
-
getMiddlewares: () => CollectMiddlewaresResult;
|
|
7
|
-
addWebMiddleware: (input: any) => void;
|
|
8
|
-
addAPIMiddleware: (input: any) => void;
|
|
9
|
-
};
|
|
10
|
-
export declare type AttacherOptions = {
|
|
11
|
-
addMiddleware: (...input: any[]) => void;
|
|
12
|
-
};
|
|
13
|
-
export declare type Attacher = (options: AttacherOptions) => void;
|
|
14
|
-
export declare const hook: (attacher: Attacher) => Attacher;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const requireModule: (filename: string) => any;
|
package/src/babel.ts
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getBabelChain,
|
|
3
|
-
ILibPresetOption,
|
|
4
|
-
ISyntaxOption,
|
|
5
|
-
} from '@modern-js/babel-preset-lib';
|
|
6
|
-
import { TransformOptions } from '@babel/core';
|
|
7
|
-
import { applyOptionsChain, fs, getAlias } from '@modern-js/utils';
|
|
8
|
-
import type { NormalizedConfig } from '@modern-js/core';
|
|
9
|
-
import json5 from 'json5';
|
|
10
|
-
|
|
11
|
-
export * from '@babel/core';
|
|
12
|
-
|
|
13
|
-
export interface ITsconfig {
|
|
14
|
-
compilerOptions?:
|
|
15
|
-
| {
|
|
16
|
-
rootDir?: string;
|
|
17
|
-
baseUrl?: string;
|
|
18
|
-
declaration?: boolean;
|
|
19
|
-
emitDeclarationOnly?: boolean;
|
|
20
|
-
isolatedModules?: boolean;
|
|
21
|
-
allowJs?: boolean;
|
|
22
|
-
outDir?: string;
|
|
23
|
-
paths?: Record<string, string[]>;
|
|
24
|
-
}
|
|
25
|
-
| undefined;
|
|
26
|
-
include?: string[];
|
|
27
|
-
exclude?: string[];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const readTsConfig = <T extends null | ITsconfig>(
|
|
31
|
-
tsconfigPath: string,
|
|
32
|
-
noExistReturn: T = null as T,
|
|
33
|
-
): ITsconfig | T => {
|
|
34
|
-
// 如果不存在,则返回 noExistReturn
|
|
35
|
-
if (!fs.existsSync(tsconfigPath)) {
|
|
36
|
-
return noExistReturn;
|
|
37
|
-
}
|
|
38
|
-
const content = fs.readFileSync(tsconfigPath, 'utf-8');
|
|
39
|
-
return json5.parse(content);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export const existTsConfigFile = (tsconfigAbsolutePath: string) => {
|
|
43
|
-
const tsconfig = readTsConfig(tsconfigAbsolutePath);
|
|
44
|
-
return Boolean(tsconfig);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const getBabelConfig = (
|
|
48
|
-
libPresetOption: ILibPresetOption,
|
|
49
|
-
syntaxOption: ISyntaxOption,
|
|
50
|
-
): TransformOptions => {
|
|
51
|
-
const chain = getBabelChain(libPresetOption, syntaxOption);
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
sourceType: 'unambiguous',
|
|
55
|
-
...chain.toJSON(),
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export interface IPackageModeValue {
|
|
60
|
-
type: 'module' | 'commonjs';
|
|
61
|
-
syntax: 'es5' | 'es6+';
|
|
62
|
-
tsconfigPath: string;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export const resolveBabelConfig = (
|
|
66
|
-
appDirectory: string,
|
|
67
|
-
modernConfig: NormalizedConfig,
|
|
68
|
-
option: IPackageModeValue,
|
|
69
|
-
// FIXME: babel type can't pass type checking
|
|
70
|
-
): any => {
|
|
71
|
-
const {
|
|
72
|
-
source: {
|
|
73
|
-
envVars,
|
|
74
|
-
globalVars,
|
|
75
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
76
|
-
// @ts-expect-error
|
|
77
|
-
jsxTransformRuntime = 'automatic',
|
|
78
|
-
},
|
|
79
|
-
tools: { lodash: userLodashOption },
|
|
80
|
-
} = modernConfig;
|
|
81
|
-
|
|
82
|
-
// alias config
|
|
83
|
-
const aliasConfig = getAlias(modernConfig.source.alias, {
|
|
84
|
-
appDirectory,
|
|
85
|
-
...option,
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
// lodash config
|
|
89
|
-
const lodashOptions = applyOptionsChain(
|
|
90
|
-
{ id: ['lodash', 'ramda'] },
|
|
91
|
-
// TODO: 需要处理类型问题
|
|
92
|
-
userLodashOption as any,
|
|
93
|
-
);
|
|
94
|
-
// babel config
|
|
95
|
-
const babelChain = getBabelChain(
|
|
96
|
-
{
|
|
97
|
-
appDirectory,
|
|
98
|
-
enableReactPreset: true,
|
|
99
|
-
enableTypescriptPreset: true,
|
|
100
|
-
alias: aliasConfig,
|
|
101
|
-
envVars,
|
|
102
|
-
globalVars,
|
|
103
|
-
lodashOptions,
|
|
104
|
-
jsxTransformRuntime,
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
type: option.type,
|
|
108
|
-
syntax: option.syntax,
|
|
109
|
-
},
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
const envOptions = babelChain.preset('@babel/preset-env').options();
|
|
113
|
-
babelChain
|
|
114
|
-
.preset('@babel/preset-env')
|
|
115
|
-
.use(require.resolve('@babel/preset-env'), [
|
|
116
|
-
{
|
|
117
|
-
...envOptions[0],
|
|
118
|
-
loose: true,
|
|
119
|
-
},
|
|
120
|
-
]);
|
|
121
|
-
|
|
122
|
-
babelChain.plugin('babel-plugin-transform-typescript-metadata').use(
|
|
123
|
-
require.resolve('babel-plugin-transform-typescript-metadata'),
|
|
124
|
-
|
|
125
|
-
[],
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
babelChain
|
|
129
|
-
.plugin('@babel/plugin-proposal-decorators')
|
|
130
|
-
.use(require.resolve('@babel/plugin-proposal-decorators'), [
|
|
131
|
-
{ legacy: true },
|
|
132
|
-
]);
|
|
133
|
-
|
|
134
|
-
babelChain.plugin('@babel/plugin-proposal-class-properties').use(
|
|
135
|
-
require.resolve('@babel/plugin-proposal-class-properties'),
|
|
136
|
-
|
|
137
|
-
[{ loose: true }],
|
|
138
|
-
);
|
|
139
|
-
|
|
140
|
-
const internalBabelConfig = { ...babelChain.toJSON() };
|
|
141
|
-
|
|
142
|
-
const userBabelConfig = modernConfig.tools.babel;
|
|
143
|
-
applyOptionsChain(
|
|
144
|
-
internalBabelConfig,
|
|
145
|
-
// TODO: 感觉 userBabelConfig 的类型应该是TransformOptions
|
|
146
|
-
userBabelConfig as any,
|
|
147
|
-
{ chain: babelChain },
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
return internalBabelConfig;
|
|
151
|
-
};
|
package/src/gather.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { createMiddlewareCollecter } from './middleware';
|
|
3
|
-
import { requireModule } from './requireModule';
|
|
4
|
-
|
|
5
|
-
const API_DIR_PATH = 'api';
|
|
6
|
-
const API_APP_NAME = '_app';
|
|
7
|
-
const SERVER_DIR_PATH = 'server';
|
|
8
|
-
const WEB_APP_NAME = 'index';
|
|
9
|
-
|
|
10
|
-
export const gather = (pwd: string) => {
|
|
11
|
-
const { getMiddlewares, addAPIMiddleware, addWebMiddleware } =
|
|
12
|
-
createMiddlewareCollecter();
|
|
13
|
-
|
|
14
|
-
const apiPath = path.resolve(pwd, API_DIR_PATH);
|
|
15
|
-
const apiAppPath = path.resolve(apiPath, API_APP_NAME);
|
|
16
|
-
const serverPath = path.resolve(pwd, SERVER_DIR_PATH);
|
|
17
|
-
const webAppPath = path.resolve(serverPath, WEB_APP_NAME);
|
|
18
|
-
|
|
19
|
-
const apiAttacher = requireModule(apiAppPath);
|
|
20
|
-
if (apiAttacher) {
|
|
21
|
-
apiAttacher({ addMiddleware: addAPIMiddleware });
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const webAttacher = requireModule(webAppPath);
|
|
25
|
-
if (webAttacher) {
|
|
26
|
-
webAttacher({ addMiddleware: addWebMiddleware });
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return getMiddlewares();
|
|
30
|
-
};
|
package/src/index.ts
DELETED
package/src/middleware.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export type CollectMiddlewaresResult = {
|
|
2
|
-
web: any[];
|
|
3
|
-
api: any[];
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
export const createMiddlewareCollecter = () => {
|
|
7
|
-
const webMiddlewares: any[] = [];
|
|
8
|
-
const apiMiddlewares: any[] = [];
|
|
9
|
-
|
|
10
|
-
const addWebMiddleware = (input: any) => {
|
|
11
|
-
webMiddlewares.push(input);
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const addAPIMiddleware = (input: any) => {
|
|
15
|
-
apiMiddlewares.push(input);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const getMiddlewares = (): CollectMiddlewaresResult => ({
|
|
19
|
-
web: webMiddlewares,
|
|
20
|
-
api: apiMiddlewares,
|
|
21
|
-
});
|
|
22
|
-
return {
|
|
23
|
-
getMiddlewares,
|
|
24
|
-
addWebMiddleware,
|
|
25
|
-
addAPIMiddleware,
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export type AttacherOptions = {
|
|
30
|
-
addMiddleware: (...input: any[]) => void;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type Attacher = (options: AttacherOptions) => void;
|
|
34
|
-
|
|
35
|
-
export const hook = (attacher: Attacher) => attacher;
|
package/src/requireModule.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { findExists } from '@modern-js/utils';
|
|
2
|
-
|
|
3
|
-
const FILE_EXTENSIONS = ['.ts', '.js'];
|
|
4
|
-
|
|
5
|
-
export const requireModule = (filename: string) => {
|
|
6
|
-
const exist = findExists(FILE_EXTENSIONS.map(ext => `${filename}${ext}`));
|
|
7
|
-
|
|
8
|
-
if (!exist) {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// throw errors directly if require fail
|
|
13
|
-
const mod = require(exist);
|
|
14
|
-
return interopRequire(mod);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
function interopRequire(obj: any) {
|
|
18
|
-
return interopRequireDefault(obj).default;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function interopRequireDefault(obj: any) {
|
|
22
|
-
return obj?.__esModule ? obj : { default: obj };
|
|
23
|
-
}
|
package/tests/gather.test.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import { gather } from '@/index';
|
|
3
|
-
|
|
4
|
-
describe('@modern-js/server-utils', () => {
|
|
5
|
-
it('should work well', () => {
|
|
6
|
-
const pwd = path.resolve(__dirname, './fixtures');
|
|
7
|
-
const result = gather(pwd);
|
|
8
|
-
|
|
9
|
-
expect(result.api.length).toBe(1);
|
|
10
|
-
expect(result.api[0]).toBe('@koa/api');
|
|
11
|
-
expect(result.web.length).toBe(1);
|
|
12
|
-
expect(result.web[0]).toBe('@koa/web');
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('should get empty when pass a empty dir', () => {
|
|
16
|
-
const pwd = path.resolve(__dirname, './fixtures/empty');
|
|
17
|
-
const result = gather(pwd);
|
|
18
|
-
|
|
19
|
-
expect(result.api.length).toBe(0);
|
|
20
|
-
expect(result.web.length).toBe(0);
|
|
21
|
-
});
|
|
22
|
-
});
|