@modern-js/server-utils 2.0.0-beta.3 → 2.0.0-beta.6

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.
@@ -1,65 +1,204 @@
1
- import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
- import * as path from 'path';
4
- import { fs } from '@modern-js/utils';
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
+ }
15
+ function _asyncToGenerator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
29
+ }
30
+ var __generator = this && this.__generator || function(thisArg, body) {
31
+ var f, y, t, g, _ = {
32
+ label: 0,
33
+ sent: function() {
34
+ if (t[0] & 1) throw t[1];
35
+ return t[1];
36
+ },
37
+ trys: [],
38
+ ops: []
39
+ };
40
+ return(g = {
41
+ next: verb(0),
42
+ "throw": verb(1),
43
+ "return": verb(2)
44
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
+ return this;
46
+ }), g);
47
+ function verb(n) {
48
+ return function(v) {
49
+ return step([
50
+ n,
51
+ v
52
+ ]);
53
+ };
54
+ }
55
+ function step(op) {
56
+ if (f) throw new TypeError("Generator is already executing.");
57
+ while(_)try {
58
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
59
+ if (y = 0, t) op = [
60
+ op[0] & 2,
61
+ t.value
62
+ ];
63
+ switch(op[0]){
64
+ case 0:
65
+ case 1:
66
+ t = op;
67
+ break;
68
+ case 4:
69
+ _.label++;
70
+ return {
71
+ value: op[1],
72
+ done: false
73
+ };
74
+ case 5:
75
+ _.label++;
76
+ y = op[1];
77
+ op = [
78
+ 0
79
+ ];
80
+ continue;
81
+ case 7:
82
+ op = _.ops.pop();
83
+ _.trys.pop();
84
+ continue;
85
+ default:
86
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
87
+ _ = 0;
88
+ continue;
89
+ }
90
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
91
+ _.label = op[1];
92
+ break;
93
+ }
94
+ if (op[0] === 6 && _.label < t[1]) {
95
+ _.label = t[1];
96
+ t = op;
97
+ break;
98
+ }
99
+ if (t && _.label < t[2]) {
100
+ _.label = t[2];
101
+ _.ops.push(op);
102
+ break;
103
+ }
104
+ if (t[2]) _.ops.pop();
105
+ _.trys.pop();
106
+ continue;
107
+ }
108
+ op = body.call(thisArg, _);
109
+ } catch (e) {
110
+ op = [
111
+ 6,
112
+ e
113
+ ];
114
+ y = 0;
115
+ } finally{
116
+ f = t = 0;
117
+ }
118
+ if (op[0] & 5) throw op[1];
119
+ return {
120
+ value: op[0] ? op[1] : void 0,
121
+ done: true
122
+ };
123
+ }
124
+ };
125
+ import * as path from "path";
126
+ import { fs } from "@modern-js/utils";
5
127
  import { compileByTs } from "../compilers/typescript";
6
128
  import { compileByBabel } from "../compilers/babel";
7
- export var FILE_EXTENSIONS = ['.js', '.ts', '.mjs', '.ejs'];
8
- var validateAbsolutePath = function validateAbsolutePath(filename, message) {
9
- if (!path.isAbsolute(filename)) {
10
- throw new Error(message);
11
- }
129
+ var FILE_EXTENSIONS = [
130
+ ".js",
131
+ ".ts",
132
+ ".mjs",
133
+ ".ejs"
134
+ ];
135
+ var validateAbsolutePath = function(filename, message) {
136
+ if (!path.isAbsolute(filename)) {
137
+ throw new Error(message);
138
+ }
12
139
  };
13
- var validateAbsolutePaths = function validateAbsolutePaths(filenames, messageFunc) {
14
- filenames.forEach(function (filename) {
15
- return validateAbsolutePath(filename, messageFunc(filename));
16
- });
140
+ var validateAbsolutePaths = function(filenames, messageFunc) {
141
+ filenames.forEach(function(filename) {
142
+ return validateAbsolutePath(filename, messageFunc(filename));
143
+ });
17
144
  };
18
- export var compile = /*#__PURE__*/function () {
19
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(appDirectory, modernConfig, compileOptions) {
20
- var _modernConfig$server;
21
- var sourceDirs, distDir, tsconfigPath, compiler, isTsProject;
22
- return _regeneratorRuntime().wrap(function _callee$(_context) {
23
- while (1) {
24
- switch (_context.prev = _context.next) {
25
- case 0:
26
- sourceDirs = compileOptions.sourceDirs, distDir = compileOptions.distDir, tsconfigPath = compileOptions.tsconfigPath;
27
- validateAbsolutePaths(sourceDirs, function (dir) {
28
- return "source dir ".concat(dir, " is not an absolute path.");
29
- });
30
- validateAbsolutePath(distDir, "dist dir ".concat(distDir, " is not an absolute path."));
31
- compiler = modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig$server = modernConfig.server) === null || _modernConfig$server === void 0 ? void 0 : _modernConfig$server.compiler;
32
- _context.t0 = tsconfigPath;
33
- if (!_context.t0) {
34
- _context.next = 9;
35
- break;
36
- }
37
- _context.next = 8;
38
- return fs.pathExists(tsconfigPath);
39
- case 8:
40
- _context.t0 = _context.sent;
41
- case 9:
42
- isTsProject = _context.t0;
43
- if (!(!isTsProject || compiler === 'babel')) {
44
- _context.next = 15;
45
- break;
145
+ var compile = function() {
146
+ var _ref = _asyncToGenerator(function(appDirectory, modernConfig, compileOptions) {
147
+ var ref, sourceDirs, distDir, tsconfigPath, compiler, isTsProject, _tmp;
148
+ return __generator(this, function(_state) {
149
+ switch(_state.label){
150
+ case 0:
151
+ sourceDirs = compileOptions.sourceDirs, distDir = compileOptions.distDir, tsconfigPath = compileOptions.tsconfigPath;
152
+ validateAbsolutePaths(sourceDirs, function(dir) {
153
+ return "source dir ".concat(dir, " is not an absolute path.");
154
+ });
155
+ validateAbsolutePath(distDir, "dist dir ".concat(distDir, " is not an absolute path."));
156
+ compiler = modernConfig === null || modernConfig === void 0 ? void 0 : (ref = modernConfig.server) === null || ref === void 0 ? void 0 : ref.compiler;
157
+ _tmp = tsconfigPath;
158
+ if (!_tmp) return [
159
+ 3,
160
+ 2
161
+ ];
162
+ return [
163
+ 4,
164
+ fs.pathExists(tsconfigPath)
165
+ ];
166
+ case 1:
167
+ _tmp = _state.sent();
168
+ _state.label = 2;
169
+ case 2:
170
+ isTsProject = _tmp;
171
+ if (!(!isTsProject || compiler === "babel")) return [
172
+ 3,
173
+ 4
174
+ ];
175
+ return [
176
+ 4,
177
+ compileByBabel(appDirectory, modernConfig, compileOptions)
178
+ ];
179
+ case 3:
180
+ _state.sent();
181
+ return [
182
+ 3,
183
+ 6
184
+ ];
185
+ case 4:
186
+ return [
187
+ 4,
188
+ compileByTs(appDirectory, modernConfig, compileOptions)
189
+ ];
190
+ case 5:
191
+ _state.sent();
192
+ _state.label = 6;
193
+ case 6:
194
+ return [
195
+ 2
196
+ ];
46
197
  }
47
- _context.next = 13;
48
- return compileByBabel(appDirectory, modernConfig, compileOptions);
49
- case 13:
50
- _context.next = 17;
51
- break;
52
- case 15:
53
- _context.next = 17;
54
- return compileByTs(appDirectory, modernConfig, compileOptions);
55
- case 17:
56
- case "end":
57
- return _context.stop();
58
- }
59
- }
60
- }, _callee);
61
- }));
62
- return function compile(_x, _x2, _x3) {
63
- return _ref.apply(this, arguments);
64
- };
65
- }();
198
+ });
199
+ });
200
+ return function compile(appDirectory, modernConfig, compileOptions) {
201
+ return _ref.apply(this, arguments);
202
+ };
203
+ }();
204
+ export { FILE_EXTENSIONS, compile };