@modern-js/plugin-server 1.17.0 → 1.18.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @modern-js/plugin-server
2
2
 
3
+ ## 1.18.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 2b7406d: feat: use typescript instead of babel as typescript compiler in server
8
+ feat: 服务端,增加 typescript 作为 typescipt 编译器
9
+ - Updated dependencies [8280920]
10
+ - Updated dependencies [2b7406d]
11
+ - Updated dependencies [0a4d622]
12
+ - Updated dependencies [60a2e3a]
13
+ - Updated dependencies [5227370]
14
+ - Updated dependencies [7928bae]
15
+ - @modern-js/utils@1.18.0
16
+ - @modern-js/server-utils@1.18.0
17
+ - @modern-js/babel-compiler@1.18.0
18
+
3
19
  ## 1.17.0
4
20
 
5
21
  ### Patch Changes
@@ -1,40 +1,8 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
- import { compiler } from '@modern-js/babel-compiler';
4
- import { resolveBabelConfig } from '@modern-js/server-utils';
3
+ import { compile } from '@modern-js/server-utils';
5
4
  import { SHARED_DIR, SERVER_DIR } from '@modern-js/utils';
6
5
  const TS_CONFIG_FILENAME = 'tsconfig.json';
7
- const FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs'];
8
-
9
- const compile = async (appDirectory, modernConfig, compileOptions) => {
10
- const {
11
- patterns
12
- } = compileOptions;
13
- const results = await Promise.all(patterns.map(pattern => {
14
- const {
15
- from,
16
- to,
17
- tsconfigPath
18
- } = pattern;
19
- const babelConfig = resolveBabelConfig(appDirectory, modernConfig, {
20
- tsconfigPath: tsconfigPath ? tsconfigPath : '',
21
- syntax: 'es6+',
22
- type: 'commonjs'
23
- });
24
- return compiler({
25
- rootDir: appDirectory,
26
- distDir: to,
27
- sourceDir: from,
28
- extensions: FILE_EXTENSIONS
29
- }, babelConfig);
30
- }));
31
- results.forEach(result => {
32
- if (result.code === 1) {
33
- throw new Error(result.message);
34
- }
35
- });
36
- };
37
-
38
6
  export default (() => ({
39
7
  name: '@modern-js/plugin-server',
40
8
  setup: api => ({
@@ -52,27 +20,21 @@ export default (() => ({
52
20
  const serverDir = path.resolve(appDirectory, SERVER_DIR);
53
21
  const sharedDir = path.resolve(appDirectory, SHARED_DIR);
54
22
  const tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
55
- const patterns = [];
23
+ const sourceDirs = [];
56
24
 
57
25
  if (fs.existsSync(serverDir)) {
58
- patterns.push({
59
- from: serverDir,
60
- to: distDir,
61
- tsconfigPath
62
- });
26
+ sourceDirs.push(serverDir);
63
27
  }
64
28
 
65
29
  if (fs.existsSync(sharedDir)) {
66
- patterns.push({
67
- from: sharedDir,
68
- to: distDir,
69
- tsconfigPath
70
- });
30
+ sourceDirs.push(sharedDir);
71
31
  }
72
32
 
73
- if (patterns.length > 0) {
33
+ if (sourceDirs.length > 0) {
74
34
  await compile(appDirectory, modernConfig, {
75
- patterns
35
+ sourceDirs,
36
+ distDir,
37
+ tsconfigPath
76
38
  });
77
39
  }
78
40
  }
@@ -9,8 +9,6 @@ var _fs = _interopRequireDefault(require("fs"));
9
9
 
10
10
  var _path = _interopRequireDefault(require("path"));
11
11
 
12
- var _babelCompiler = require("@modern-js/babel-compiler");
13
-
14
12
  var _serverUtils = require("@modern-js/server-utils");
15
13
 
16
14
  var _utils = require("@modern-js/utils");
@@ -18,36 +16,6 @@ var _utils = require("@modern-js/utils");
18
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
17
 
20
18
  const TS_CONFIG_FILENAME = 'tsconfig.json';
21
- const FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs'];
22
-
23
- const compile = async (appDirectory, modernConfig, compileOptions) => {
24
- const {
25
- patterns
26
- } = compileOptions;
27
- const results = await Promise.all(patterns.map(pattern => {
28
- const {
29
- from,
30
- to,
31
- tsconfigPath
32
- } = pattern;
33
- const babelConfig = (0, _serverUtils.resolveBabelConfig)(appDirectory, modernConfig, {
34
- tsconfigPath: tsconfigPath ? tsconfigPath : '',
35
- syntax: 'es6+',
36
- type: 'commonjs'
37
- });
38
- return (0, _babelCompiler.compiler)({
39
- rootDir: appDirectory,
40
- distDir: to,
41
- sourceDir: from,
42
- extensions: FILE_EXTENSIONS
43
- }, babelConfig);
44
- }));
45
- results.forEach(result => {
46
- if (result.code === 1) {
47
- throw new Error(result.message);
48
- }
49
- });
50
- };
51
19
 
52
20
  var _default = () => ({
53
21
  name: '@modern-js/plugin-server',
@@ -71,27 +39,21 @@ var _default = () => ({
71
39
 
72
40
  const tsconfigPath = _path.default.resolve(appDirectory, TS_CONFIG_FILENAME);
73
41
 
74
- const patterns = [];
42
+ const sourceDirs = [];
75
43
 
76
44
  if (_fs.default.existsSync(serverDir)) {
77
- patterns.push({
78
- from: serverDir,
79
- to: distDir,
80
- tsconfigPath
81
- });
45
+ sourceDirs.push(serverDir);
82
46
  }
83
47
 
84
48
  if (_fs.default.existsSync(sharedDir)) {
85
- patterns.push({
86
- from: sharedDir,
87
- to: distDir,
88
- tsconfigPath
89
- });
49
+ sourceDirs.push(sharedDir);
90
50
  }
91
51
 
92
- if (patterns.length > 0) {
93
- await compile(appDirectory, modernConfig, {
94
- patterns
52
+ if (sourceDirs.length > 0) {
53
+ await (0, _serverUtils.compile)(appDirectory, modernConfig, {
54
+ sourceDirs,
55
+ distDir,
56
+ tsconfigPath
95
57
  });
96
58
  }
97
59
  }
@@ -2,59 +2,9 @@ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
3
  import fs from 'fs';
4
4
  import path from 'path';
5
- import { compiler } from '@modern-js/babel-compiler';
6
- import { resolveBabelConfig } from '@modern-js/server-utils';
5
+ import { compile } from '@modern-js/server-utils';
7
6
  import { SHARED_DIR, SERVER_DIR } from '@modern-js/utils';
8
7
  var TS_CONFIG_FILENAME = 'tsconfig.json';
9
- var FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs'];
10
-
11
- var compile = /*#__PURE__*/function () {
12
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(appDirectory, modernConfig, compileOptions) {
13
- var patterns, results;
14
- return _regeneratorRuntime().wrap(function _callee$(_context) {
15
- while (1) {
16
- switch (_context.prev = _context.next) {
17
- case 0:
18
- patterns = compileOptions.patterns;
19
- _context.next = 3;
20
- return Promise.all(patterns.map(function (pattern) {
21
- var from = pattern.from,
22
- to = pattern.to,
23
- tsconfigPath = pattern.tsconfigPath;
24
- var babelConfig = resolveBabelConfig(appDirectory, modernConfig, {
25
- tsconfigPath: tsconfigPath ? tsconfigPath : '',
26
- syntax: 'es6+',
27
- type: 'commonjs'
28
- });
29
- return compiler({
30
- rootDir: appDirectory,
31
- distDir: to,
32
- sourceDir: from,
33
- extensions: FILE_EXTENSIONS
34
- }, babelConfig);
35
- }));
36
-
37
- case 3:
38
- results = _context.sent;
39
- results.forEach(function (result) {
40
- if (result.code === 1) {
41
- throw new Error(result.message);
42
- }
43
- });
44
-
45
- case 5:
46
- case "end":
47
- return _context.stop();
48
- }
49
- }
50
- }, _callee);
51
- }));
52
-
53
- return function compile(_x, _x2, _x3) {
54
- return _ref.apply(this, arguments);
55
- };
56
- }();
57
-
58
8
  export default (function () {
59
9
  return {
60
10
  name: '@modern-js/plugin-server',
@@ -64,12 +14,12 @@ export default (function () {
64
14
  return {};
65
15
  },
66
16
  afterBuild: function afterBuild() {
67
- return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
68
- var _api$useAppContext, appDirectory, distDirectory, modernConfig, distDir, serverDir, sharedDir, tsconfigPath, patterns;
17
+ return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
18
+ var _api$useAppContext, appDirectory, distDirectory, modernConfig, distDir, serverDir, sharedDir, tsconfigPath, sourceDirs;
69
19
 
70
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
20
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
71
21
  while (1) {
72
- switch (_context2.prev = _context2.next) {
22
+ switch (_context.prev = _context.next) {
73
23
  case 0:
74
24
  _api$useAppContext = api.useAppContext(), appDirectory = _api$useAppContext.appDirectory, distDirectory = _api$useAppContext.distDirectory;
75
25
  modernConfig = api.useResolvedConfigContext();
@@ -77,40 +27,34 @@ export default (function () {
77
27
  serverDir = path.resolve(appDirectory, SERVER_DIR);
78
28
  sharedDir = path.resolve(appDirectory, SHARED_DIR);
79
29
  tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
80
- patterns = [];
30
+ sourceDirs = [];
81
31
 
82
32
  if (fs.existsSync(serverDir)) {
83
- patterns.push({
84
- from: serverDir,
85
- to: distDir,
86
- tsconfigPath: tsconfigPath
87
- });
33
+ sourceDirs.push(serverDir);
88
34
  }
89
35
 
90
36
  if (fs.existsSync(sharedDir)) {
91
- patterns.push({
92
- from: sharedDir,
93
- to: distDir,
94
- tsconfigPath: tsconfigPath
95
- });
37
+ sourceDirs.push(sharedDir);
96
38
  }
97
39
 
98
- if (!(patterns.length > 0)) {
99
- _context2.next = 12;
40
+ if (!(sourceDirs.length > 0)) {
41
+ _context.next = 12;
100
42
  break;
101
43
  }
102
44
 
103
- _context2.next = 12;
45
+ _context.next = 12;
104
46
  return compile(appDirectory, modernConfig, {
105
- patterns: patterns
47
+ sourceDirs: sourceDirs,
48
+ distDir: distDir,
49
+ tsconfigPath: tsconfigPath
106
50
  });
107
51
 
108
52
  case 12:
109
53
  case "end":
110
- return _context2.stop();
54
+ return _context.stop();
111
55
  }
112
56
  }
113
- }, _callee2);
57
+ }, _callee);
114
58
  }))();
115
59
  }
116
60
  };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.17.0",
14
+ "version": "1.18.0",
15
15
  "types": "./dist/types/server.d.ts",
16
16
  "jsnext:source": "./src/server.ts",
17
17
  "main": "./dist/js/node/server.js",
@@ -48,20 +48,20 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@babel/runtime": "^7.18.0",
51
- "@modern-js/babel-compiler": "1.17.0",
52
- "@modern-js/server-utils": "1.17.0",
53
- "@modern-js/utils": "1.17.0"
51
+ "@modern-js/babel-compiler": "1.18.0",
52
+ "@modern-js/server-utils": "1.18.0",
53
+ "@modern-js/utils": "1.18.0"
54
54
  },
55
55
  "devDependencies": {
56
- "@modern-js/server-core": "1.17.0",
57
- "@modern-js/core": "1.17.0",
58
- "@scripts/build": "1.17.0",
59
- "@modern-js/types": "1.17.0",
56
+ "@modern-js/server-core": "1.18.0",
57
+ "@modern-js/core": "1.18.0",
58
+ "@scripts/build": "1.18.0",
59
+ "@modern-js/types": "1.18.0",
60
60
  "typescript": "^4",
61
61
  "@types/jest": "^27",
62
62
  "@types/node": "^14",
63
63
  "jest": "^27",
64
- "@scripts/jest-config": "1.17.0"
64
+ "@scripts/jest-config": "1.18.0"
65
65
  },
66
66
  "sideEffects": [
67
67
  "*.css",