@sanity/pkg-utils 1.6.0 → 1.7.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/dist/{__resolveBuildContext-bc09bff3.cjs → __resolveBuildContext-9b0aa9f9.cjs} +218 -104
- package/dist/__resolveBuildContext-9b0aa9f9.cjs.map +1 -0
- package/dist/{_build-89aeaf6a.cjs → _build-6e7deb31.cjs} +82 -47
- package/dist/_build-6e7deb31.cjs.map +1 -0
- package/dist/{_buildAction-8855cb5a.cjs → _buildAction-d8841b41.cjs} +35 -8
- package/dist/_buildAction-d8841b41.cjs.map +1 -0
- package/dist/_check-04a1f749.cjs +242 -0
- package/dist/_check-04a1f749.cjs.map +1 -0
- package/dist/{_checkAction-a96c4021.cjs → _checkAction-09426a13.cjs} +17 -4
- package/dist/_checkAction-09426a13.cjs.map +1 -0
- package/dist/{_index-0e8b664d.cjs → _index-46cab21c.cjs} +331 -202
- package/dist/_index-46cab21c.cjs.map +1 -0
- package/dist/_watch-cf9c717f.cjs +264 -0
- package/dist/_watch-cf9c717f.cjs.map +1 -0
- package/dist/{_watchAction-bd901b01.cjs → _watchAction-5941527f.cjs} +38 -4
- package/dist/_watchAction-5941527f.cjs.map +1 -0
- package/dist/cli.cjs +24 -9
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +49 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.js +763 -500
- package/dist/index.js.map +1 -1
- package/package.json +15 -9
- package/src/node/_core/config/_loadConfig.ts +5 -0
- package/src/node/_core/config/types.ts +3 -2
- package/src/node/_core/pkg/_loadPkg.ts +2 -1
- package/src/node/_core/pkg/_parseExports.ts +4 -3
- package/src/node/_core/pkg/_types.ts +3 -2
- package/src/node/_printPackageTree.ts +3 -1
- package/src/node/_resolveBuildTasks.ts +1 -3
- package/src/node/_resolveWatchTasks.ts +1 -3
- package/src/node/_spinner.ts +5 -13
- package/src/node/_tasks/rollup/_resolveRollupConfig.ts +26 -3
- package/src/node/build.ts +0 -3
- package/dist/__printPackageTree-3ff3ecd3.cjs +0 -76
- package/dist/__printPackageTree-3ff3ecd3.cjs.map +0 -1
- package/dist/__resolveBuildContext-bc09bff3.cjs.map +0 -1
- package/dist/_build-89aeaf6a.cjs.map +0 -1
- package/dist/_buildAction-8855cb5a.cjs.map +0 -1
- package/dist/_check-0ebe9af4.cjs +0 -118
- package/dist/_check-0ebe9af4.cjs.map +0 -1
- package/dist/_checkAction-a96c4021.cjs.map +0 -1
- package/dist/_index-0e8b664d.cjs.map +0 -1
- package/dist/_watch-cf0df170.cjs +0 -219
- package/dist/_watch-cf0df170.cjs.map +0 -1
- package/dist/_watchAction-bd901b01.cjs.map +0 -1
- package/src/node/_resolveEsTarget.ts +0 -39
package/dist/index.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
const _excluded = ["_path"];
|
|
2
|
+
|
|
3
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
4
|
+
|
|
5
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
6
|
+
|
|
7
|
+
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; }
|
|
8
|
+
|
|
9
|
+
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; }
|
|
10
|
+
|
|
11
|
+
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; }
|
|
12
|
+
|
|
1
13
|
import path from 'path';
|
|
2
14
|
import { register } from 'esbuild-register/dist/node';
|
|
3
15
|
import findConfig from 'find-config';
|
|
@@ -17,27 +29,22 @@ import { TSDocConfigFile } from '@microsoft/tsdoc-config';
|
|
|
17
29
|
import { parse } from 'jsonc-parser';
|
|
18
30
|
import { rollup, watch as watch$1 } from 'rollup';
|
|
19
31
|
import alias from '@rollup/plugin-alias';
|
|
32
|
+
import { getBabelOutputPlugin } from '@rollup/plugin-babel';
|
|
20
33
|
import commonjs from '@rollup/plugin-commonjs';
|
|
21
34
|
import json from '@rollup/plugin-json';
|
|
22
35
|
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
23
36
|
import replace from '@rollup/plugin-replace';
|
|
24
37
|
import esbuild from 'rollup-plugin-esbuild';
|
|
25
|
-
import
|
|
26
|
-
import prettyBytes from 'pretty-bytes';
|
|
38
|
+
import { terser } from 'rollup-plugin-terser';
|
|
27
39
|
import browserslist from 'browserslist';
|
|
28
|
-
import ora from 'ora';
|
|
29
40
|
import esbuild$1 from 'esbuild';
|
|
41
|
+
import treeify from 'treeify';
|
|
42
|
+
import prettyBytes from 'pretty-bytes';
|
|
30
43
|
import { scan, startWith, distinctUntilChanged } from 'rxjs/operators';
|
|
31
44
|
import globby from 'globby';
|
|
32
45
|
import chokidar from 'chokidar';
|
|
33
|
-
|
|
34
46
|
const _DEFAULTS = {
|
|
35
|
-
browserslist: [
|
|
36
|
-
"> 0.2% and supports es6-module and supports es6-module-dynamic-import",
|
|
37
|
-
"not dead",
|
|
38
|
-
"not IE 11",
|
|
39
|
-
"maintained node versions"
|
|
40
|
-
]
|
|
47
|
+
browserslist: ["> 0.2% and supports es6-module and supports es6-module-dynamic-import", "not dead", "not IE 11", "maintained node versions"]
|
|
41
48
|
};
|
|
42
49
|
|
|
43
50
|
function _isRecord(value) {
|
|
@@ -45,40 +52,68 @@ function _isRecord(value) {
|
|
|
45
52
|
}
|
|
46
53
|
|
|
47
54
|
async function _loadConfig(options) {
|
|
48
|
-
const {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
55
|
+
const {
|
|
56
|
+
cwd
|
|
57
|
+
} = options;
|
|
58
|
+
const pkgPath = await pkgUp({
|
|
59
|
+
cwd
|
|
60
|
+
});
|
|
61
|
+
if (!pkgPath) return void 0;
|
|
52
62
|
const root = path.dirname(pkgPath);
|
|
63
|
+
|
|
53
64
|
const configFile = _findConfigFile(root);
|
|
65
|
+
|
|
54
66
|
if (!configFile) {
|
|
55
67
|
return void 0;
|
|
56
68
|
}
|
|
69
|
+
|
|
70
|
+
if (!configFile.path.startsWith(cwd)) {
|
|
71
|
+
return void 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
57
74
|
try {
|
|
58
|
-
const {
|
|
75
|
+
const {
|
|
76
|
+
unregister
|
|
77
|
+
} = configFile.transform ? register({
|
|
78
|
+
extensions: [".js", ".ts"]
|
|
79
|
+
}) : {
|
|
80
|
+
unregister: () => void 0
|
|
81
|
+
};
|
|
82
|
+
|
|
59
83
|
const mod = require(configFile.path);
|
|
84
|
+
|
|
60
85
|
unregister();
|
|
61
86
|
return (mod == null ? void 0 : mod.default) || mod || void 0;
|
|
62
87
|
} catch (_) {
|
|
63
88
|
return void 0;
|
|
64
89
|
}
|
|
65
90
|
}
|
|
91
|
+
|
|
66
92
|
function _findConfigFile(cwd) {
|
|
67
|
-
const ts = findConfig("package.config.ts", {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
93
|
+
const ts = findConfig("package.config.ts", {
|
|
94
|
+
cwd
|
|
95
|
+
});
|
|
96
|
+
if (ts) return {
|
|
97
|
+
path: ts,
|
|
98
|
+
transform: true
|
|
99
|
+
};
|
|
100
|
+
const cjs = findConfig("package.config.cjs", {
|
|
101
|
+
cwd
|
|
102
|
+
});
|
|
103
|
+
if (cjs) return {
|
|
104
|
+
path: cjs,
|
|
105
|
+
transform: false
|
|
106
|
+
};
|
|
73
107
|
return null;
|
|
74
108
|
}
|
|
75
109
|
|
|
76
110
|
function _resolveConfigProperty(prop, initialValue) {
|
|
77
|
-
if (!prop)
|
|
78
|
-
|
|
111
|
+
if (!prop) return initialValue;
|
|
112
|
+
|
|
79
113
|
if (typeof prop === "function") {
|
|
80
114
|
return prop(initialValue);
|
|
81
115
|
}
|
|
116
|
+
|
|
82
117
|
return prop;
|
|
83
118
|
}
|
|
84
119
|
|
|
@@ -99,35 +134,32 @@ const pkgSchema = z.object({
|
|
|
99
134
|
browser: z.optional(z.record(z.string())),
|
|
100
135
|
module: z.optional(z.string()),
|
|
101
136
|
types: z.optional(z.string()),
|
|
102
|
-
exports: z.optional(
|
|
103
|
-
z.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
),
|
|
118
|
-
require: z.optional(z.string()),
|
|
119
|
-
import: z.optional(z.string()),
|
|
120
|
-
types: z.optional(z.string())
|
|
121
|
-
})
|
|
122
|
-
)
|
|
123
|
-
),
|
|
137
|
+
exports: z.optional(z.record(z.object({
|
|
138
|
+
types: z.optional(z.string()),
|
|
139
|
+
source: z.string(),
|
|
140
|
+
browser: z.optional(z.object({
|
|
141
|
+
require: z.optional(z.string()),
|
|
142
|
+
import: z.optional(z.string())
|
|
143
|
+
})),
|
|
144
|
+
node: z.optional(z.object({
|
|
145
|
+
require: z.optional(z.string()),
|
|
146
|
+
import: z.optional(z.string())
|
|
147
|
+
})),
|
|
148
|
+
require: z.optional(z.string()),
|
|
149
|
+
import: z.optional(z.string()),
|
|
150
|
+
default: z.string()
|
|
151
|
+
}))),
|
|
124
152
|
browserslist: z.optional(z.array(z.string()))
|
|
125
153
|
});
|
|
154
|
+
|
|
126
155
|
async function _loadPkg(options) {
|
|
127
|
-
const {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
156
|
+
const {
|
|
157
|
+
cwd
|
|
158
|
+
} = options;
|
|
159
|
+
const pkgPath = await pkgUp({
|
|
160
|
+
cwd
|
|
161
|
+
});
|
|
162
|
+
if (!pkgPath) throw new Error("no package.json found");
|
|
131
163
|
const buf = await fs.readFile(pkgPath);
|
|
132
164
|
return pkgSchema.parse(JSON.parse(buf.toString()));
|
|
133
165
|
}
|
|
@@ -139,46 +171,47 @@ async function _loadPkgWithReporting(options) {
|
|
|
139
171
|
if (err instanceof ZodError) {
|
|
140
172
|
for (const issue of err.issues) {
|
|
141
173
|
if (issue.code === "invalid_type") {
|
|
142
|
-
console.log(
|
|
143
|
-
`${chalk.red("invalid type")} in ./package.json at ${chalk.magenta(
|
|
144
|
-
`\`${issue.path.join("")}\``
|
|
145
|
-
)} (expected ${issue.expected}, received ${issue.received})`
|
|
146
|
-
);
|
|
174
|
+
console.log("".concat(chalk.red("invalid type"), " in ./package.json at ").concat(chalk.magenta("`".concat(issue.path.join(""), "`")), " (expected ").concat(issue.expected, ", received ").concat(issue.received, ")"));
|
|
147
175
|
}
|
|
148
176
|
}
|
|
149
177
|
} else {
|
|
150
178
|
console.error(err);
|
|
151
179
|
}
|
|
180
|
+
|
|
152
181
|
process.exit(1);
|
|
153
182
|
}
|
|
154
183
|
}
|
|
155
184
|
|
|
156
185
|
function _parseExports(options) {
|
|
157
|
-
const {
|
|
186
|
+
const {
|
|
187
|
+
pkg
|
|
188
|
+
} = options;
|
|
158
189
|
const rootExport = {
|
|
159
190
|
_exported: true,
|
|
160
191
|
_path: ".",
|
|
192
|
+
types: pkg.types,
|
|
193
|
+
source: pkg.source || "index.js",
|
|
161
194
|
browser: pkg.browser && {
|
|
162
195
|
require: pkg.main && pkg.browser[pkg.main],
|
|
163
196
|
import: pkg.module && pkg.browser[pkg.module]
|
|
164
197
|
},
|
|
165
|
-
source: pkg.source || "index.js",
|
|
166
|
-
require: pkg.main,
|
|
167
198
|
import: pkg.module,
|
|
168
|
-
|
|
199
|
+
require: pkg.main,
|
|
200
|
+
default: pkg.module || pkg.main || "./index.js"
|
|
169
201
|
};
|
|
170
202
|
const extraExports = [];
|
|
203
|
+
|
|
171
204
|
if (pkg.exports) {
|
|
172
205
|
for (const [exportPath, exportEntry] of Object.entries(pkg.exports)) {
|
|
173
206
|
if (_isRecord(exportEntry)) {
|
|
174
207
|
if (exportPath === ".") {
|
|
175
208
|
Object.assign(rootExport, exportEntry);
|
|
176
209
|
} else {
|
|
177
|
-
const extraExport = {
|
|
210
|
+
const extraExport = _objectSpread({
|
|
178
211
|
_exported: true,
|
|
179
|
-
_path: exportPath
|
|
180
|
-
|
|
181
|
-
|
|
212
|
+
_path: exportPath
|
|
213
|
+
}, exportEntry);
|
|
214
|
+
|
|
182
215
|
extraExports.push(extraExport);
|
|
183
216
|
}
|
|
184
217
|
} else {
|
|
@@ -186,52 +219,46 @@ function _parseExports(options) {
|
|
|
186
219
|
}
|
|
187
220
|
}
|
|
188
221
|
}
|
|
222
|
+
|
|
189
223
|
return [rootExport, ...extraExports];
|
|
190
224
|
}
|
|
191
225
|
|
|
192
226
|
async function _loadTSConfig(options) {
|
|
193
|
-
const {
|
|
227
|
+
const {
|
|
228
|
+
cwd,
|
|
229
|
+
tsconfigPath
|
|
230
|
+
} = options;
|
|
194
231
|
const configPath = ts.findConfigFile(cwd, ts.sys.fileExists, tsconfigPath);
|
|
232
|
+
|
|
195
233
|
if (!configPath) {
|
|
196
|
-
throw new Error(
|
|
234
|
+
throw new Error("could not find a valid '".concat(tsconfigPath, "'"));
|
|
197
235
|
}
|
|
236
|
+
|
|
198
237
|
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
199
238
|
return ts.parseJsonConfigFileContent(configFile.config, ts.sys, cwd);
|
|
200
239
|
}
|
|
201
240
|
|
|
202
|
-
const TS_TARGETS = {
|
|
203
|
-
0: "es3",
|
|
204
|
-
1: "es5",
|
|
205
|
-
2: "es2015",
|
|
206
|
-
3: "es2016",
|
|
207
|
-
4: "es2017",
|
|
208
|
-
5: "es2018",
|
|
209
|
-
6: "es2019",
|
|
210
|
-
7: "es2020",
|
|
211
|
-
8: "es2021",
|
|
212
|
-
9: "es2022",
|
|
213
|
-
99: "esnext",
|
|
214
|
-
100: "esnext"
|
|
215
|
-
};
|
|
216
|
-
function _resolveEsTarget(ctx) {
|
|
217
|
-
var _a;
|
|
218
|
-
const { ts } = ctx;
|
|
219
|
-
const tsTarget = ((_a = ts.config) == null ? void 0 : _a.options.target) || 99;
|
|
220
|
-
return TS_TARGETS[tsTarget] || "esnext";
|
|
221
|
-
}
|
|
222
|
-
|
|
223
241
|
function _resolveBuildTasks(ctx) {
|
|
224
242
|
var _a, _b, _c, _d, _e;
|
|
225
|
-
|
|
226
|
-
const
|
|
243
|
+
|
|
244
|
+
const {
|
|
245
|
+
cwd,
|
|
246
|
+
pkg,
|
|
247
|
+
target
|
|
248
|
+
} = ctx;
|
|
227
249
|
const tasks = [];
|
|
228
|
-
const exports = Object.entries(ctx.exports || {}).map(
|
|
229
|
-
|
|
230
|
-
|
|
250
|
+
const exports = Object.entries(ctx.exports || {}).map(_ref => {
|
|
251
|
+
let [_path, exp] = _ref;
|
|
252
|
+
return _objectSpread({
|
|
253
|
+
_path
|
|
254
|
+
}, exp);
|
|
255
|
+
});
|
|
231
256
|
const dtsTasks = {};
|
|
232
257
|
const rollupTasks = {};
|
|
258
|
+
|
|
233
259
|
function _addRollupTaskEntry(format, runtime, entry) {
|
|
234
|
-
const buildId =
|
|
260
|
+
const buildId = "".concat(format, ":").concat(runtime);
|
|
261
|
+
|
|
235
262
|
if (!rollupTasks[buildId]) {
|
|
236
263
|
rollupTasks[buildId] = {
|
|
237
264
|
type: "build:js",
|
|
@@ -239,14 +266,16 @@ function _resolveBuildTasks(ctx) {
|
|
|
239
266
|
entries: [entry],
|
|
240
267
|
runtime,
|
|
241
268
|
format,
|
|
242
|
-
target:
|
|
269
|
+
target: target[runtime]
|
|
243
270
|
};
|
|
244
271
|
} else {
|
|
245
272
|
rollupTasks[buildId].entries.push(entry);
|
|
246
273
|
}
|
|
247
274
|
}
|
|
275
|
+
|
|
248
276
|
for (const exp of exports) {
|
|
249
277
|
const importId = path.join(pkg.name, exp._path);
|
|
278
|
+
|
|
250
279
|
if (exp.types) {
|
|
251
280
|
if (!dtsTasks[importId]) {
|
|
252
281
|
dtsTasks[importId] = {
|
|
@@ -259,106 +288,99 @@ function _resolveBuildTasks(ctx) {
|
|
|
259
288
|
}
|
|
260
289
|
}
|
|
261
290
|
}
|
|
291
|
+
|
|
262
292
|
for (const exp of exports) {
|
|
263
293
|
const output = exp.require;
|
|
264
|
-
if (!output)
|
|
265
|
-
|
|
294
|
+
if (!output) continue;
|
|
295
|
+
|
|
266
296
|
_addRollupTaskEntry("commonjs", ctx.runtime, {
|
|
267
297
|
path: exp._path,
|
|
268
298
|
source: exp.source,
|
|
269
299
|
output
|
|
270
300
|
});
|
|
271
301
|
}
|
|
302
|
+
|
|
272
303
|
for (const exp of exports) {
|
|
273
304
|
const output = (_a = exp.browser) == null ? void 0 : _a.require;
|
|
274
|
-
if (!output)
|
|
275
|
-
|
|
305
|
+
if (!output) continue;
|
|
306
|
+
|
|
276
307
|
_addRollupTaskEntry("commonjs", "browser", {
|
|
277
308
|
path: exp._path,
|
|
278
309
|
source: ((_b = exp.browser) == null ? void 0 : _b.source) || exp.source,
|
|
279
310
|
output
|
|
280
311
|
});
|
|
281
312
|
}
|
|
313
|
+
|
|
282
314
|
for (const exp of exports) {
|
|
283
315
|
const output = exp.import;
|
|
284
|
-
if (!output)
|
|
285
|
-
|
|
316
|
+
if (!output) continue;
|
|
317
|
+
|
|
286
318
|
_addRollupTaskEntry("esm", ctx.runtime, {
|
|
287
319
|
path: exp._path,
|
|
288
320
|
source: exp.source,
|
|
289
321
|
output
|
|
290
322
|
});
|
|
291
323
|
}
|
|
324
|
+
|
|
292
325
|
for (const exp of exports) {
|
|
293
326
|
const output = (_c = exp.browser) == null ? void 0 : _c.import;
|
|
294
|
-
if (!output)
|
|
295
|
-
|
|
327
|
+
if (!output) continue;
|
|
328
|
+
|
|
296
329
|
_addRollupTaskEntry("esm", "browser", {
|
|
297
330
|
path: exp._path,
|
|
298
331
|
source: ((_d = exp.browser) == null ? void 0 : _d.source) || exp.source,
|
|
299
332
|
output
|
|
300
333
|
});
|
|
301
334
|
}
|
|
335
|
+
|
|
302
336
|
tasks.push(...Object.values(dtsTasks));
|
|
303
337
|
tasks.push(...Object.values(rollupTasks));
|
|
338
|
+
|
|
304
339
|
for (const exp of exports) {
|
|
305
340
|
if (exp._exported && exp._path !== ".") {
|
|
306
341
|
const relativeTargetPath = (((_e = exp.browser) == null ? void 0 : _e.import) || exp.import || "").replace(/\.[^/.]+$/, "");
|
|
342
|
+
|
|
307
343
|
if (relativeTargetPath) {
|
|
308
|
-
fs$1.writeFileSync(
|
|
309
|
-
path.resolve(cwd, `${exp._path}.js`),
|
|
310
|
-
[
|
|
311
|
-
`// AUTO-GENERATED \u2013 DO NOT EDIT`,
|
|
312
|
-
``,
|
|
313
|
-
`export * from '${relativeTargetPath}'`,
|
|
314
|
-
``
|
|
315
|
-
].join("\n")
|
|
316
|
-
);
|
|
344
|
+
fs$1.writeFileSync(path.resolve(cwd, "".concat(exp._path, ".js")), ["// AUTO-GENERATED \u2013 DO NOT EDIT", "", "export * from '".concat(relativeTargetPath, "'"), ""].join("\n"));
|
|
317
345
|
}
|
|
318
346
|
}
|
|
319
347
|
}
|
|
348
|
+
|
|
320
349
|
return tasks;
|
|
321
350
|
}
|
|
322
351
|
|
|
323
352
|
function _printExtractMessages(ctx, messages) {
|
|
324
|
-
const {
|
|
325
|
-
|
|
353
|
+
const {
|
|
354
|
+
cwd,
|
|
355
|
+
logger
|
|
356
|
+
} = ctx;
|
|
357
|
+
const warnings = messages.filter(msg => msg.logLevel === "warning");
|
|
358
|
+
|
|
326
359
|
if (warnings.length) {
|
|
327
360
|
logger.log();
|
|
328
361
|
}
|
|
362
|
+
|
|
329
363
|
for (const msg of warnings) {
|
|
330
364
|
const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath);
|
|
365
|
+
|
|
331
366
|
if (msg.messageId === "TS6307") {
|
|
332
367
|
continue;
|
|
333
368
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
`${chalk.cyan(sourceFilePath || "?")}`,
|
|
337
|
-
`:${chalk.yellow(msg.sourceFileLine)}:${chalk.yellow(msg.sourceFileColumn)}`,
|
|
338
|
-
` - ${chalk.yellow("warning")} ${chalk.gray(msg.messageId)}
|
|
339
|
-
`,
|
|
340
|
-
msg.text,
|
|
341
|
-
"\n"
|
|
342
|
-
].join("")
|
|
343
|
-
);
|
|
369
|
+
|
|
370
|
+
logger.log(["".concat(chalk.cyan(sourceFilePath || "?")), ":".concat(chalk.yellow(msg.sourceFileLine), ":").concat(chalk.yellow(msg.sourceFileColumn)), " - ".concat(chalk.yellow("warning"), " ").concat(chalk.gray(msg.messageId), "\n"), msg.text, "\n"].join(""));
|
|
344
371
|
}
|
|
345
|
-
|
|
372
|
+
|
|
373
|
+
const errors = messages.filter(msg => msg.logLevel === "error");
|
|
374
|
+
|
|
346
375
|
if (!warnings.length && errors.length) {
|
|
347
376
|
logger.log("");
|
|
348
377
|
}
|
|
378
|
+
|
|
349
379
|
for (const msg of errors) {
|
|
350
380
|
const sourceFilePath = msg.sourceFilePath && path.relative(cwd, msg.sourceFilePath);
|
|
351
|
-
logger.log(
|
|
352
|
-
[
|
|
353
|
-
`${chalk.cyan(sourceFilePath || "?")}`,
|
|
354
|
-
`:${chalk.yellow(msg.sourceFileLine)}:${chalk.yellow(msg.sourceFileColumn)}`,
|
|
355
|
-
` - ${chalk.red("error")} ${chalk.gray(msg.messageId)}
|
|
356
|
-
`,
|
|
357
|
-
msg.text,
|
|
358
|
-
"\n"
|
|
359
|
-
].join("")
|
|
360
|
-
);
|
|
381
|
+
logger.log(["".concat(chalk.cyan(sourceFilePath || "?")), ":".concat(chalk.yellow(msg.sourceFileLine), ":").concat(chalk.yellow(msg.sourceFileColumn)), " - ".concat(chalk.red("error"), " ").concat(chalk.gray(msg.messageId), "\n"), msg.text, "\n"].join(""));
|
|
361
382
|
}
|
|
383
|
+
|
|
362
384
|
if (errors.length) {
|
|
363
385
|
process.exit(1);
|
|
364
386
|
}
|
|
@@ -367,49 +389,62 @@ function _printExtractMessages(ctx, messages) {
|
|
|
367
389
|
const formatHost = {
|
|
368
390
|
getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
|
|
369
391
|
getNewLine: () => ts.sys.newLine,
|
|
370
|
-
getCanonicalFileName: ts.sys.useCaseSensitiveFileNames ?
|
|
392
|
+
getCanonicalFileName: ts.sys.useCaseSensitiveFileNames ? f => f : f => f.toLowerCase()
|
|
371
393
|
};
|
|
394
|
+
|
|
372
395
|
async function _buildTypes(options) {
|
|
373
|
-
const {
|
|
374
|
-
|
|
375
|
-
|
|
396
|
+
const {
|
|
397
|
+
cwd,
|
|
398
|
+
outDir,
|
|
399
|
+
sourcePath,
|
|
400
|
+
tsconfig
|
|
401
|
+
} = options;
|
|
402
|
+
|
|
403
|
+
const compilerOptions = _objectSpread(_objectSpread({}, tsconfig.options), {}, {
|
|
376
404
|
declaration: true,
|
|
377
405
|
declarationDir: outDir,
|
|
378
406
|
emitDeclarationOnly: true,
|
|
379
407
|
noEmit: false,
|
|
380
408
|
outDir
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
compilerOptions.rootDir ? path.resolve(cwd, compilerOptions.rootDir) : path.dirname(path.resolve(cwd, sourcePath))
|
|
385
|
-
) || ".";
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
const rootDir = path.relative(cwd, compilerOptions.rootDir ? path.resolve(cwd, compilerOptions.rootDir) : path.dirname(path.resolve(cwd, sourcePath))) || ".";
|
|
386
412
|
const program = ts.createProgram(tsconfig.fileNames, compilerOptions);
|
|
387
413
|
const sourceFiles = program.getSourceFiles();
|
|
388
|
-
const sourceFile = sourceFiles.find(
|
|
414
|
+
const sourceFile = sourceFiles.find(f => f.fileName === path.resolve(cwd, sourcePath));
|
|
415
|
+
|
|
389
416
|
if (!sourceFile) {
|
|
390
|
-
throw new Error(
|
|
417
|
+
throw new Error("source file not found: ".concat(sourcePath));
|
|
391
418
|
}
|
|
419
|
+
|
|
392
420
|
const emitResult = program.emit();
|
|
393
421
|
const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
394
|
-
allDiagnostics.forEach(
|
|
422
|
+
allDiagnostics.forEach(diagnostic => {
|
|
395
423
|
if (diagnostic.file && diagnostic.start) {
|
|
396
|
-
const {
|
|
424
|
+
const {
|
|
425
|
+
line,
|
|
426
|
+
character
|
|
427
|
+
} = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
|
|
397
428
|
const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
398
|
-
console.log(
|
|
399
|
-
${message}`);
|
|
429
|
+
console.log("".concat(diagnostic.file.fileName, " ").concat(line + 1, ":").concat(character + 1, "\n").concat(message));
|
|
400
430
|
} else {
|
|
401
431
|
console.log(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
|
|
402
432
|
}
|
|
403
433
|
});
|
|
434
|
+
|
|
404
435
|
if (emitResult.emitSkipped) {
|
|
405
|
-
const errors = allDiagnostics.filter(
|
|
436
|
+
const errors = allDiagnostics.filter(diag => diag.category === ts.DiagnosticCategory.Error);
|
|
437
|
+
|
|
406
438
|
if (errors.length) {
|
|
407
439
|
console.error(ts.formatDiagnostics(errors, formatHost));
|
|
408
440
|
throw new Error("failed to compile");
|
|
409
441
|
}
|
|
410
442
|
}
|
|
443
|
+
|
|
411
444
|
const typesPath = path.resolve(outDir, path.relative(rootDir, path.resolve(cwd, sourcePath))).replace(/\.[jt]sx?$/, ".d.ts");
|
|
412
|
-
return {
|
|
445
|
+
return {
|
|
446
|
+
path: typesPath
|
|
447
|
+
};
|
|
413
448
|
}
|
|
414
449
|
|
|
415
450
|
class _DtsError extends Error {
|
|
@@ -417,10 +452,19 @@ class _DtsError extends Error {
|
|
|
417
452
|
super(message);
|
|
418
453
|
this.messages = messages;
|
|
419
454
|
}
|
|
455
|
+
|
|
420
456
|
}
|
|
421
457
|
|
|
422
458
|
function _createApiExtractorConfig(options) {
|
|
423
|
-
const {
|
|
459
|
+
const {
|
|
460
|
+
distPath,
|
|
461
|
+
exportPath,
|
|
462
|
+
filePath,
|
|
463
|
+
messages,
|
|
464
|
+
projectPath,
|
|
465
|
+
sourcePath,
|
|
466
|
+
tsconfigPath
|
|
467
|
+
} = options;
|
|
424
468
|
return {
|
|
425
469
|
apiReport: {
|
|
426
470
|
enabled: false,
|
|
@@ -431,7 +475,7 @@ function _createApiExtractorConfig(options) {
|
|
|
431
475
|
},
|
|
432
476
|
docModel: {
|
|
433
477
|
enabled: false,
|
|
434
|
-
apiJsonFilePath: path.resolve(distPath,
|
|
478
|
+
apiJsonFilePath: path.resolve(distPath, "".concat(exportPath, ".api.json"))
|
|
435
479
|
},
|
|
436
480
|
dtsRollup: {
|
|
437
481
|
enabled: true,
|
|
@@ -447,31 +491,33 @@ function _createApiExtractorConfig(options) {
|
|
|
447
491
|
}
|
|
448
492
|
|
|
449
493
|
async function _createTSDocConfig(opts) {
|
|
450
|
-
const {
|
|
494
|
+
const {
|
|
495
|
+
customTags
|
|
496
|
+
} = opts;
|
|
497
|
+
|
|
451
498
|
if (customTags.length === 0) {
|
|
452
499
|
return void 0;
|
|
453
500
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
);
|
|
501
|
+
|
|
502
|
+
const tsDocBaseBuf = await readFile(require.resolve("@microsoft/api-extractor/extends/tsdoc-base.json"));
|
|
457
503
|
const tsDocBaseConfig = parse(tsDocBaseBuf.toString());
|
|
458
|
-
const tagDefinitions = (tsDocBaseConfig.tagDefinitions || []).concat(
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
);
|
|
465
|
-
|
|
504
|
+
const tagDefinitions = (tsDocBaseConfig.tagDefinitions || []).concat(customTags.map(t => ({
|
|
505
|
+
tagName: "@".concat(t.name),
|
|
506
|
+
syntaxKind: t.syntaxKind,
|
|
507
|
+
allowMultiple: t.allowMultiple
|
|
508
|
+
})));
|
|
509
|
+
|
|
510
|
+
const supportForTags = _objectSpread({}, tsDocBaseConfig.supportForTags);
|
|
511
|
+
|
|
466
512
|
for (const customTag of customTags) {
|
|
467
|
-
supportForTags[
|
|
513
|
+
supportForTags["@".concat(customTag.name)] = true;
|
|
468
514
|
}
|
|
469
|
-
|
|
470
|
-
|
|
515
|
+
|
|
516
|
+
return TSDocConfigFile.loadFromObject(_objectSpread(_objectSpread({}, tsDocBaseConfig), {}, {
|
|
471
517
|
noStandardTags: false,
|
|
472
518
|
tagDefinitions,
|
|
473
519
|
supportForTags
|
|
474
|
-
});
|
|
520
|
+
}));
|
|
475
521
|
}
|
|
476
522
|
|
|
477
523
|
const _LOG_LEVELS = {
|
|
@@ -480,15 +526,27 @@ const _LOG_LEVELS = {
|
|
|
480
526
|
off: "none",
|
|
481
527
|
warn: "warning"
|
|
482
528
|
};
|
|
529
|
+
|
|
483
530
|
async function _extractTypes(options) {
|
|
484
|
-
const {
|
|
531
|
+
const {
|
|
532
|
+
distPath,
|
|
533
|
+
exportPath,
|
|
534
|
+
files,
|
|
535
|
+
filePath,
|
|
536
|
+
projectPath,
|
|
537
|
+
rules,
|
|
538
|
+
sourcePath,
|
|
539
|
+
tsconfigPath
|
|
540
|
+
} = options;
|
|
485
541
|
const tsdocConfigFile = await _createTSDocConfig({
|
|
486
542
|
customTags: []
|
|
487
543
|
});
|
|
544
|
+
|
|
488
545
|
function _ruleToLogLevel(key, defaultLevel) {
|
|
489
546
|
const r = rules == null ? void 0 : rules[key];
|
|
490
547
|
return r ? _LOG_LEVELS[r] : defaultLevel || "warning";
|
|
491
548
|
}
|
|
549
|
+
|
|
492
550
|
const messagesConfig = {
|
|
493
551
|
compilerMessageReporting: {
|
|
494
552
|
default: {
|
|
@@ -546,35 +604,46 @@ async function _extractTypes(options) {
|
|
|
546
604
|
const extractorResult = Extractor.invoke(extractorConfig, {
|
|
547
605
|
localBuild: true,
|
|
548
606
|
showVerboseMessages: true,
|
|
607
|
+
|
|
549
608
|
messageCallback(message) {
|
|
550
609
|
messages.push(message);
|
|
551
610
|
message.handled = true;
|
|
552
611
|
}
|
|
612
|
+
|
|
553
613
|
});
|
|
554
614
|
const typesPath = path.resolve(distPath, filePath);
|
|
555
615
|
const typesBuf = await fs.readFile(typesPath);
|
|
556
616
|
const prettierConfig = await prettier.resolveConfig(typesPath);
|
|
557
617
|
await mkdirp(path.dirname(typesPath));
|
|
558
|
-
await fs.writeFile(
|
|
559
|
-
typesPath
|
|
560
|
-
|
|
561
|
-
...prettierConfig,
|
|
562
|
-
filepath: typesPath
|
|
563
|
-
})
|
|
564
|
-
);
|
|
618
|
+
await fs.writeFile(typesPath, prettier.format(typesBuf.toString(), _objectSpread(_objectSpread({}, prettierConfig), {}, {
|
|
619
|
+
filepath: typesPath
|
|
620
|
+
})));
|
|
565
621
|
files.push({
|
|
566
622
|
type: "types",
|
|
567
623
|
path: typesPath
|
|
568
624
|
});
|
|
569
|
-
return {
|
|
625
|
+
return {
|
|
626
|
+
extractorResult,
|
|
627
|
+
messages
|
|
628
|
+
};
|
|
570
629
|
}
|
|
571
630
|
|
|
572
631
|
const rimraf = promisify(rimrafCallback);
|
|
632
|
+
|
|
573
633
|
async function _doExtract(ctx, task) {
|
|
574
634
|
var _a;
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
635
|
+
|
|
636
|
+
const {
|
|
637
|
+
config,
|
|
638
|
+
cwd,
|
|
639
|
+
dist,
|
|
640
|
+
files,
|
|
641
|
+
ts
|
|
642
|
+
} = ctx;
|
|
643
|
+
if (!ts.config || !ts.configPath) return {
|
|
644
|
+
type: "dts",
|
|
645
|
+
messages: []
|
|
646
|
+
};
|
|
578
647
|
const sourcePath = task.sourcePath;
|
|
579
648
|
const exportPath = task.exportPath === "." ? "./index" : task.exportPath;
|
|
580
649
|
const distPath = path.resolve(cwd, dist);
|
|
@@ -590,7 +659,9 @@ async function _doExtract(ctx, task) {
|
|
|
590
659
|
sourcePath,
|
|
591
660
|
tsconfig: ts.config
|
|
592
661
|
});
|
|
593
|
-
const {
|
|
662
|
+
const {
|
|
663
|
+
messages
|
|
664
|
+
} = await _extractTypes({
|
|
594
665
|
cwd,
|
|
595
666
|
exportPath,
|
|
596
667
|
files,
|
|
@@ -602,23 +673,25 @@ async function _doExtract(ctx, task) {
|
|
|
602
673
|
distPath
|
|
603
674
|
});
|
|
604
675
|
await tmpDir.removeCallback();
|
|
605
|
-
|
|
676
|
+
|
|
677
|
+
if (messages.some(msg => msg.logLevel === "error")) {
|
|
606
678
|
throw new _DtsError("encountered errors when extracting types", messages);
|
|
607
679
|
}
|
|
608
|
-
|
|
680
|
+
|
|
681
|
+
return {
|
|
682
|
+
type: "dts",
|
|
683
|
+
messages
|
|
684
|
+
};
|
|
609
685
|
}
|
|
610
686
|
|
|
611
687
|
const _dtsTask = {
|
|
612
|
-
name: (_ctx, task) => [
|
|
613
|
-
`build type definitions`,
|
|
614
|
-
` ${chalk.blue(task.importId)}: ${task.sourcePath} -> ${task.targetPath}`
|
|
615
|
-
].join("\n"),
|
|
688
|
+
name: (_ctx, task) => ["build type definitions", " ".concat(chalk.blue(task.importId), ": ").concat(task.sourcePath, " -> ").concat(task.targetPath)].join("\n"),
|
|
616
689
|
exec: (ctx, task) => {
|
|
617
|
-
return new Observable(
|
|
618
|
-
_doExtract(ctx, task).then(
|
|
690
|
+
return new Observable(observer => {
|
|
691
|
+
_doExtract(ctx, task).then(result => {
|
|
619
692
|
observer.next(result);
|
|
620
693
|
observer.complete();
|
|
621
|
-
}).catch(
|
|
694
|
+
}).catch(err => {
|
|
622
695
|
observer.error(err);
|
|
623
696
|
});
|
|
624
697
|
});
|
|
@@ -627,7 +700,10 @@ const _dtsTask = {
|
|
|
627
700
|
_printExtractMessages(ctx, result.messages);
|
|
628
701
|
},
|
|
629
702
|
error: (ctx, _task, err) => {
|
|
630
|
-
const {
|
|
703
|
+
const {
|
|
704
|
+
logger
|
|
705
|
+
} = ctx;
|
|
706
|
+
|
|
631
707
|
if (err instanceof _DtsError) {
|
|
632
708
|
_printExtractMessages(ctx, err.messages);
|
|
633
709
|
} else if (err instanceof Error) {
|
|
@@ -635,28 +711,31 @@ const _dtsTask = {
|
|
|
635
711
|
}
|
|
636
712
|
}
|
|
637
713
|
};
|
|
638
|
-
|
|
639
714
|
const _dtsWatchTask = {
|
|
640
|
-
name: (_ctx, task) => [
|
|
641
|
-
`build type definitions`,
|
|
642
|
-
` ${chalk.blue(task.importId)}: ${task.sourcePath} -> ${task.targetPath}`
|
|
643
|
-
].join("\n"),
|
|
715
|
+
name: (_ctx, task) => ["build type definitions", " ".concat(chalk.blue(task.importId), ": ").concat(task.sourcePath, " -> ").concat(task.targetPath)].join("\n"),
|
|
644
716
|
exec: (ctx, task) => {
|
|
645
|
-
return new Observable(
|
|
646
|
-
_doExtract(ctx, task).then(
|
|
717
|
+
return new Observable(observer => {
|
|
718
|
+
_doExtract(ctx, task).then(result => {
|
|
647
719
|
observer.next(result);
|
|
648
720
|
observer.complete();
|
|
649
|
-
}).catch(
|
|
721
|
+
}).catch(err => observer.error(err));
|
|
650
722
|
});
|
|
651
723
|
},
|
|
652
724
|
complete: (ctx, _task, result) => {
|
|
653
|
-
const {
|
|
725
|
+
const {
|
|
726
|
+
logger
|
|
727
|
+
} = ctx;
|
|
728
|
+
|
|
654
729
|
_printExtractMessages(ctx, result.messages);
|
|
730
|
+
|
|
655
731
|
logger.warn("watching typescript definitions is currently not supported");
|
|
656
732
|
logger.log();
|
|
657
733
|
},
|
|
658
734
|
error: (ctx, _task, err) => {
|
|
659
|
-
const {
|
|
735
|
+
const {
|
|
736
|
+
logger
|
|
737
|
+
} = ctx;
|
|
738
|
+
|
|
660
739
|
if (err instanceof _DtsError) {
|
|
661
740
|
_printExtractMessages(ctx, err.messages);
|
|
662
741
|
} else if (err instanceof Error) {
|
|
@@ -666,124 +745,163 @@ const _dtsWatchTask = {
|
|
|
666
745
|
};
|
|
667
746
|
|
|
668
747
|
function _resolveRollupConfig(ctx, buildTask) {
|
|
669
|
-
var
|
|
670
|
-
|
|
671
|
-
|
|
748
|
+
var _ref2, _ref4, _ref5, _ref6, _ref7, _ref8;
|
|
749
|
+
|
|
750
|
+
var _a;
|
|
751
|
+
|
|
752
|
+
const {
|
|
753
|
+
format,
|
|
754
|
+
runtime,
|
|
755
|
+
target
|
|
756
|
+
} = buildTask;
|
|
757
|
+
const {
|
|
758
|
+
config,
|
|
759
|
+
cwd,
|
|
760
|
+
external,
|
|
761
|
+
dist: outDir,
|
|
762
|
+
pkg,
|
|
763
|
+
ts
|
|
764
|
+
} = ctx;
|
|
672
765
|
const outputExt = format === "commonjs" ? ".cjs" : pkg.type === "module" ? ".mjs" : ".js";
|
|
673
|
-
const
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
766
|
+
const minify = (_ref2 = config == null ? void 0 : config.minify) !== null && _ref2 !== void 0 ? _ref2 : true;
|
|
767
|
+
const pathAliases = Object.fromEntries(Object.entries(((_a = ts.config) == null ? void 0 : _a.options.paths) || {}).map(_ref3 => {
|
|
768
|
+
let [key, val] = _ref3;
|
|
769
|
+
|
|
770
|
+
var _a2;
|
|
771
|
+
|
|
772
|
+
return [key, path.resolve(cwd, ((_a2 = ts.config) == null ? void 0 : _a2.options.baseUrl) || ".", val[0])];
|
|
773
|
+
}));
|
|
774
|
+
const entries = buildTask.entries.map(entry => {
|
|
775
|
+
return _objectSpread(_objectSpread({}, entry), {}, {
|
|
682
776
|
name: path.relative(outDir, entry.output).replace(/\.[^/.]+$/, "")
|
|
683
|
-
};
|
|
777
|
+
});
|
|
684
778
|
}, {});
|
|
685
779
|
return {
|
|
686
780
|
inputOptions: {
|
|
687
781
|
context: cwd,
|
|
688
|
-
external:
|
|
782
|
+
external: id => {
|
|
689
783
|
const idParts = id.split("/");
|
|
690
|
-
const name = idParts[0].startsWith("@") ?
|
|
784
|
+
const name = idParts[0].startsWith("@") ? "".concat(idParts[0], "/").concat(idParts[1]) : idParts[0];
|
|
785
|
+
|
|
691
786
|
if (name && external.includes(name)) {
|
|
692
787
|
return true;
|
|
693
788
|
}
|
|
789
|
+
|
|
694
790
|
return false;
|
|
695
791
|
},
|
|
696
792
|
input: entries.reduce((acc, entry) => {
|
|
697
|
-
return {
|
|
793
|
+
return _objectSpread(_objectSpread({}, acc), {}, {
|
|
794
|
+
[entry.name]: entry.source
|
|
795
|
+
});
|
|
698
796
|
}, {}),
|
|
797
|
+
|
|
699
798
|
onwarn(warning, rollupWarn) {
|
|
700
799
|
if (!warning.code || !["CIRCULAR_DEPENDENCY"].includes(warning.code)) {
|
|
701
800
|
rollupWarn(warning);
|
|
702
801
|
}
|
|
703
802
|
},
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
}
|
|
715
|
-
return JSON.stringify(
|
|
716
|
-
path.relative(cwd, path.resolve(outDir, entry.name + outputExt))
|
|
717
|
-
);
|
|
718
|
-
},
|
|
719
|
-
"process.env.PKG_FORMAT": JSON.stringify(format),
|
|
720
|
-
"process.env.PKG_RUNTIME": JSON.stringify(runtime),
|
|
721
|
-
"process.env.PKG_VERSION": JSON.stringify(process.env.PKG_VERSION || pkg.version)
|
|
803
|
+
|
|
804
|
+
plugins: [replace({
|
|
805
|
+
preventAssignment: true,
|
|
806
|
+
values: _objectSpread({}, pkg.name === "@sanity/pkg-utils" ? {} : {
|
|
807
|
+
"process.env.PKG_FILE_PATH": arg => {
|
|
808
|
+
const sourcePath = "./" + path.relative(cwd, arg);
|
|
809
|
+
const entry = entries.find(e => e.source === sourcePath);
|
|
810
|
+
|
|
811
|
+
if (!entry) {
|
|
812
|
+
throw new Error("could not find source entry: ".concat(sourcePath));
|
|
722
813
|
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
browser: runtime === "browser",
|
|
730
|
-
extensions: [".cjs", ".mjs", ".js", ".jsx", ".json", ".node"],
|
|
731
|
-
preferBuiltins: true
|
|
732
|
-
}),
|
|
733
|
-
commonjs({
|
|
734
|
-
esmExternals: false,
|
|
735
|
-
extensions: [".js"]
|
|
736
|
-
}),
|
|
737
|
-
json(),
|
|
738
|
-
esbuild({
|
|
739
|
-
minify: (_b = config == null ? void 0 : config.minify) != null ? _b : true,
|
|
740
|
-
jsx: (_c = config == null ? void 0 : config.jsx) != null ? _c : "automatic",
|
|
741
|
-
jsxFactory: (_d = config == null ? void 0 : config.jsxFactory) != null ? _d : "createElement",
|
|
742
|
-
jsxFragment: (_e = config == null ? void 0 : config.jsxFragment) != null ? _e : "Fragment",
|
|
743
|
-
jsxImportSource: (_f = config == null ? void 0 : config.jsxImportSource) != null ? _f : "react",
|
|
744
|
-
target,
|
|
745
|
-
tsconfig: ctx.ts.configPath || "tsconfig.json"
|
|
814
|
+
|
|
815
|
+
return JSON.stringify(path.relative(cwd, path.resolve(outDir, entry.name + outputExt)));
|
|
816
|
+
},
|
|
817
|
+
"process.env.PKG_FORMAT": JSON.stringify(format),
|
|
818
|
+
"process.env.PKG_RUNTIME": JSON.stringify(runtime),
|
|
819
|
+
"process.env.PKG_VERSION": JSON.stringify(process.env.PKG_VERSION || pkg.version)
|
|
746
820
|
})
|
|
747
|
-
|
|
821
|
+
}), alias({
|
|
822
|
+
entries: _objectSpread({}, pathAliases)
|
|
823
|
+
}), nodeResolve({
|
|
824
|
+
browser: runtime === "browser",
|
|
825
|
+
extensions: [".cjs", ".mjs", ".js", ".jsx", ".json", ".node"],
|
|
826
|
+
preferBuiltins: true
|
|
827
|
+
}), commonjs({
|
|
828
|
+
esmExternals: false,
|
|
829
|
+
extensions: [".js"]
|
|
830
|
+
}), json(), esbuild({
|
|
831
|
+
jsx: (_ref4 = config == null ? void 0 : config.jsx) !== null && _ref4 !== void 0 ? _ref4 : "automatic",
|
|
832
|
+
jsxFactory: (_ref5 = config == null ? void 0 : config.jsxFactory) !== null && _ref5 !== void 0 ? _ref5 : "createElement",
|
|
833
|
+
jsxFragment: (_ref6 = config == null ? void 0 : config.jsxFragment) !== null && _ref6 !== void 0 ? _ref6 : "Fragment",
|
|
834
|
+
jsxImportSource: (_ref7 = config == null ? void 0 : config.jsxImportSource) !== null && _ref7 !== void 0 ? _ref7 : "react",
|
|
835
|
+
target,
|
|
836
|
+
tsconfig: ctx.ts.configPath || "tsconfig.json"
|
|
837
|
+
}), getBabelOutputPlugin({
|
|
838
|
+
plugins: ["@babel/plugin-proposal-object-rest-spread"],
|
|
839
|
+
presets: [["@babel/preset-env", {
|
|
840
|
+
targets: pkg.browserslist || _DEFAULTS.browserslist
|
|
841
|
+
}]]
|
|
842
|
+
}), minify && terser({
|
|
843
|
+
output: {
|
|
844
|
+
comments: (_node, comment) => {
|
|
845
|
+
const text = comment.value;
|
|
846
|
+
const type = comment.type;
|
|
847
|
+
|
|
848
|
+
if (type == "comment2") {
|
|
849
|
+
return /@preserve|@license|@cc_on/i.test(text);
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
return false;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
})].filter(Boolean),
|
|
748
856
|
treeshake: {
|
|
749
857
|
propertyReadSideEffects: false
|
|
750
858
|
}
|
|
751
859
|
},
|
|
752
860
|
outputOptions: {
|
|
753
|
-
chunkFileNames: () =>
|
|
861
|
+
chunkFileNames: () => "_[name]-[hash]".concat(outputExt),
|
|
754
862
|
dir: outDir,
|
|
755
|
-
entryFileNames: () =>
|
|
863
|
+
entryFileNames: () => "[name]".concat(outputExt),
|
|
756
864
|
format,
|
|
757
865
|
exports: "auto",
|
|
758
|
-
sourcemap: (
|
|
866
|
+
sourcemap: (_ref8 = config == null ? void 0 : config.sourcemap) !== null && _ref8 !== void 0 ? _ref8 : true
|
|
759
867
|
}
|
|
760
868
|
};
|
|
761
869
|
}
|
|
762
870
|
|
|
763
871
|
const _rollupTask = {
|
|
764
|
-
name: (ctx, task) =>
|
|
765
|
-
${task.entries.map((e) => `${chalk.blue(path.join(ctx.pkg.name, e.path))}: ${e.source} -> ${e.output}`).join("\n ")}`,
|
|
872
|
+
name: (ctx, task) => "build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk.blue(path.join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")),
|
|
766
873
|
exec: (ctx, task) => {
|
|
767
|
-
return new Observable(
|
|
768
|
-
_execPromise(ctx, task).then(
|
|
874
|
+
return new Observable(observer => {
|
|
875
|
+
_execPromise(ctx, task).then(result => {
|
|
769
876
|
observer.next(result);
|
|
770
877
|
observer.complete();
|
|
771
|
-
}).catch(
|
|
878
|
+
}).catch(err => observer.error(err));
|
|
772
879
|
});
|
|
773
880
|
},
|
|
774
|
-
complete: () => {
|
|
775
|
-
},
|
|
881
|
+
complete: () => {},
|
|
776
882
|
error: (_ctx, _task, err) => {
|
|
777
883
|
if (err instanceof Error) {
|
|
778
884
|
console.log(err);
|
|
779
885
|
}
|
|
780
886
|
}
|
|
781
887
|
};
|
|
888
|
+
|
|
782
889
|
async function _execPromise(ctx, task) {
|
|
783
|
-
const {
|
|
784
|
-
|
|
890
|
+
const {
|
|
891
|
+
files,
|
|
892
|
+
dist: outDir
|
|
893
|
+
} = ctx;
|
|
894
|
+
|
|
895
|
+
const {
|
|
896
|
+
inputOptions,
|
|
897
|
+
outputOptions
|
|
898
|
+
} = _resolveRollupConfig(ctx, task);
|
|
899
|
+
|
|
785
900
|
const bundle = await rollup(inputOptions);
|
|
786
|
-
const {
|
|
901
|
+
const {
|
|
902
|
+
output
|
|
903
|
+
} = await bundle.generate(outputOptions);
|
|
904
|
+
|
|
787
905
|
for (const chunkOrAsset of output) {
|
|
788
906
|
if (chunkOrAsset.type === "asset") {
|
|
789
907
|
files.push({
|
|
@@ -797,22 +915,26 @@ async function _execPromise(ctx, task) {
|
|
|
797
915
|
});
|
|
798
916
|
}
|
|
799
917
|
}
|
|
918
|
+
|
|
800
919
|
await bundle.write(outputOptions);
|
|
801
920
|
await bundle.close();
|
|
802
921
|
}
|
|
803
922
|
|
|
804
923
|
const _rollupWatchTask = {
|
|
805
|
-
name: (ctx, task) =>
|
|
806
|
-
${task.entries.map((e) => `${chalk.blue(path.join(ctx.pkg.name, e.path))}: ${e.source} -> ${e.output}`).join("\n ")}`,
|
|
924
|
+
name: (ctx, task) => "build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk.blue(path.join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")),
|
|
807
925
|
exec: (ctx, task) => {
|
|
808
|
-
const {
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
926
|
+
const {
|
|
927
|
+
inputOptions,
|
|
928
|
+
outputOptions
|
|
929
|
+
} = _resolveRollupConfig(ctx, task);
|
|
930
|
+
|
|
931
|
+
return new Observable(observer => {
|
|
932
|
+
const watchOptions = _objectSpread(_objectSpread({}, inputOptions), {}, {
|
|
812
933
|
output: outputOptions
|
|
813
|
-
};
|
|
934
|
+
});
|
|
935
|
+
|
|
814
936
|
const watcher = watch$1(watchOptions);
|
|
815
|
-
watcher.on("event",
|
|
937
|
+
watcher.on("event", event => {
|
|
816
938
|
observer.next(event);
|
|
817
939
|
});
|
|
818
940
|
return () => {
|
|
@@ -821,37 +943,43 @@ const _rollupWatchTask = {
|
|
|
821
943
|
});
|
|
822
944
|
},
|
|
823
945
|
complete: (ctx, task, event) => {
|
|
824
|
-
const {
|
|
946
|
+
const {
|
|
947
|
+
logger
|
|
948
|
+
} = ctx;
|
|
949
|
+
|
|
825
950
|
if (event.code === "BUNDLE_END") {
|
|
826
|
-
logger.success(
|
|
827
|
-
`build javascript files (target ${task.target.join(" + ")}, format ${task.format})
|
|
828
|
-
${task.entries.map((e) => `${chalk.blue(path.join(ctx.pkg.name, e.path))}: ${e.source} -> ${e.output}`).join("\n ")}`
|
|
829
|
-
);
|
|
951
|
+
logger.success("build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk.blue(path.join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")));
|
|
830
952
|
logger.log("");
|
|
831
953
|
return;
|
|
832
954
|
}
|
|
955
|
+
|
|
833
956
|
if (event.code === "BUNDLE_START") {
|
|
834
957
|
return;
|
|
835
958
|
}
|
|
959
|
+
|
|
836
960
|
if (event.code === "END") {
|
|
837
961
|
return;
|
|
838
962
|
}
|
|
963
|
+
|
|
839
964
|
if (event.code === "ERROR") {
|
|
840
965
|
logger.error(event.code, event);
|
|
841
966
|
return;
|
|
842
967
|
}
|
|
968
|
+
|
|
843
969
|
if (event.code === "START") {
|
|
844
970
|
return;
|
|
845
971
|
}
|
|
846
972
|
},
|
|
847
973
|
error: (ctx, _task, err) => {
|
|
848
|
-
const {
|
|
974
|
+
const {
|
|
975
|
+
logger
|
|
976
|
+
} = ctx;
|
|
977
|
+
|
|
849
978
|
if (err instanceof Error) {
|
|
850
979
|
logger.log(err);
|
|
851
980
|
}
|
|
852
981
|
}
|
|
853
982
|
};
|
|
854
|
-
|
|
855
983
|
const _buildTaskHandlers = {
|
|
856
984
|
"build:dts": _dtsTask,
|
|
857
985
|
"build:js": _rollupTask
|
|
@@ -861,91 +989,38 @@ const _watchTaskHandlers = {
|
|
|
861
989
|
"watch:js": _rollupWatchTask
|
|
862
990
|
};
|
|
863
991
|
|
|
864
|
-
function _getFilesize(file) {
|
|
865
|
-
const stats = statSync(file);
|
|
866
|
-
return prettyBytes(stats.size);
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
function _fileExists(file) {
|
|
870
|
-
try {
|
|
871
|
-
fs$1.accessSync(file);
|
|
872
|
-
return true;
|
|
873
|
-
} catch (_) {
|
|
874
|
-
return false;
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
function _getFileInfo(cwd, filePath) {
|
|
878
|
-
const p = path.resolve(cwd, filePath);
|
|
879
|
-
const exists = _fileExists(p);
|
|
880
|
-
const size = exists ? _getFilesize(p) : void 0;
|
|
881
|
-
return { exists, size };
|
|
882
|
-
}
|
|
883
|
-
function _printPackageTree(ctx) {
|
|
884
|
-
const { cwd, exports, logger, pkg } = ctx;
|
|
885
|
-
if (!exports)
|
|
886
|
-
return;
|
|
887
|
-
logger.log(`${chalk.blue(pkg.name)}@${chalk.green(pkg.version)}`);
|
|
888
|
-
const tree = {};
|
|
889
|
-
if (pkg.bin) {
|
|
890
|
-
tree.bin = pkg.bin;
|
|
891
|
-
}
|
|
892
|
-
function _fileInfo(file) {
|
|
893
|
-
const info = _getFileInfo(cwd, file);
|
|
894
|
-
if (!info.size) {
|
|
895
|
-
return `${chalk.gray(file)} ${chalk.red("does not exist")}`;
|
|
896
|
-
}
|
|
897
|
-
return `${file} ${chalk.gray(info.size)}`;
|
|
898
|
-
}
|
|
899
|
-
tree.exports = Object.fromEntries(
|
|
900
|
-
Object.entries(exports).filter(([, entry]) => entry._exported).map(([exportPath, entry]) => {
|
|
901
|
-
const exp = { source: entry.source };
|
|
902
|
-
if (entry.browser) {
|
|
903
|
-
exp.browser = {};
|
|
904
|
-
if (entry.browser.import)
|
|
905
|
-
exp.browser.import = _fileInfo(entry.browser.import);
|
|
906
|
-
if (entry.browser.require)
|
|
907
|
-
exp.browser.import = _fileInfo(entry.browser.require);
|
|
908
|
-
}
|
|
909
|
-
if (entry.import)
|
|
910
|
-
exp.import = _fileInfo(entry.import);
|
|
911
|
-
if (entry.require)
|
|
912
|
-
exp.require = _fileInfo(entry.require);
|
|
913
|
-
if (entry.types)
|
|
914
|
-
exp.types = _fileInfo(entry.types);
|
|
915
|
-
return [chalk.green(path.join(pkg.name, exportPath)), exp];
|
|
916
|
-
})
|
|
917
|
-
);
|
|
918
|
-
logger.log(treeify.asTree(tree, true, true));
|
|
919
|
-
}
|
|
920
|
-
|
|
921
992
|
function _sortAsNumber(a, b) {
|
|
922
993
|
const aVersion = Number(a);
|
|
923
994
|
const bVersion = Number(b);
|
|
924
995
|
return aVersion - bVersion;
|
|
925
996
|
}
|
|
997
|
+
|
|
926
998
|
function _resolveBrowserslistVersions(query) {
|
|
927
999
|
const result = browserslist(query);
|
|
928
|
-
const entries = result.map(
|
|
1000
|
+
const entries = result.map(key => {
|
|
929
1001
|
const [name, version] = key.split(" ");
|
|
930
|
-
return {
|
|
1002
|
+
return {
|
|
1003
|
+
name,
|
|
1004
|
+
version: version.split("-")[0].split(".")[0]
|
|
1005
|
+
};
|
|
931
1006
|
});
|
|
932
|
-
const andChr = entries.filter(
|
|
933
|
-
const andFf = entries.filter(
|
|
934
|
-
const chrome = entries.filter(
|
|
935
|
-
const edge = entries.filter(
|
|
936
|
-
const ff = entries.filter(
|
|
937
|
-
const iosSaf = entries.filter(
|
|
938
|
-
const saf = entries.filter(
|
|
939
|
-
const opera = entries.filter(
|
|
940
|
-
const node = entries.filter(
|
|
1007
|
+
const andChr = entries.filter(b => b.name === "and_chr");
|
|
1008
|
+
const andFf = entries.filter(b => b.name === "and_ff");
|
|
1009
|
+
const chrome = entries.filter(b => b.name === "chrome");
|
|
1010
|
+
const edge = entries.filter(b => b.name === "edge");
|
|
1011
|
+
const ff = entries.filter(b => b.name === "firefox");
|
|
1012
|
+
const iosSaf = entries.filter(b => b.name === "ios_saf");
|
|
1013
|
+
const saf = entries.filter(b => b.name === "safari");
|
|
1014
|
+
const opera = entries.filter(b => b.name === "opera");
|
|
1015
|
+
const node = entries.filter(b => b.name === "node");
|
|
941
1016
|
const versions = {
|
|
942
|
-
chrome: andChr.concat(chrome).map(
|
|
943
|
-
ff: andFf.concat(ff).map(
|
|
944
|
-
edge: edge.map(
|
|
945
|
-
iosSaf: iosSaf.map(
|
|
946
|
-
saf: saf.map(
|
|
947
|
-
opera: opera.map(
|
|
948
|
-
node: node.map(
|
|
1017
|
+
chrome: andChr.concat(chrome).map(b => b.version),
|
|
1018
|
+
ff: andFf.concat(ff).map(b => b.version),
|
|
1019
|
+
edge: edge.map(b => b.version),
|
|
1020
|
+
iosSaf: iosSaf.map(b => b.version),
|
|
1021
|
+
saf: saf.map(b => b.version),
|
|
1022
|
+
opera: opera.map(b => b.version),
|
|
1023
|
+
node: node.map(b => b.version)
|
|
949
1024
|
};
|
|
950
1025
|
versions.chrome.sort(_sortAsNumber);
|
|
951
1026
|
versions.ff.sort(_sortAsNumber);
|
|
@@ -959,71 +1034,108 @@ function _resolveBrowserslistVersions(query) {
|
|
|
959
1034
|
|
|
960
1035
|
function _resolveBrowserTarget(versions) {
|
|
961
1036
|
const target = [];
|
|
1037
|
+
|
|
962
1038
|
if (versions.chrome.length) {
|
|
963
|
-
target.push(
|
|
1039
|
+
target.push("chrome".concat(versions.chrome[0]));
|
|
964
1040
|
}
|
|
1041
|
+
|
|
965
1042
|
if (versions.ff.length) {
|
|
966
|
-
target.push(
|
|
1043
|
+
target.push("firefox".concat(versions.ff[0]));
|
|
967
1044
|
}
|
|
1045
|
+
|
|
968
1046
|
if (versions.edge.length) {
|
|
969
|
-
target.push(
|
|
1047
|
+
target.push("edge".concat(versions.edge[0]));
|
|
970
1048
|
}
|
|
1049
|
+
|
|
971
1050
|
if (versions.iosSaf.length) {
|
|
972
|
-
target.push(
|
|
1051
|
+
target.push("ios".concat(versions.iosSaf[0]));
|
|
973
1052
|
}
|
|
1053
|
+
|
|
974
1054
|
if (versions.saf.length) {
|
|
975
|
-
target.push(
|
|
1055
|
+
target.push("safari".concat(versions.saf[0]));
|
|
976
1056
|
}
|
|
1057
|
+
|
|
977
1058
|
if (versions.opera.length) {
|
|
978
|
-
target.push(
|
|
1059
|
+
target.push("opera".concat(versions.opera[0]));
|
|
979
1060
|
}
|
|
1061
|
+
|
|
980
1062
|
if (target.length === 0) {
|
|
981
1063
|
return void 0;
|
|
982
1064
|
}
|
|
1065
|
+
|
|
983
1066
|
return target;
|
|
984
1067
|
}
|
|
985
1068
|
|
|
986
1069
|
function _resolveNodeTarget(versions) {
|
|
987
1070
|
const target = [];
|
|
1071
|
+
|
|
988
1072
|
if (versions.node.length) {
|
|
989
|
-
target.push(
|
|
1073
|
+
target.push("node".concat(versions.node[0]));
|
|
990
1074
|
}
|
|
1075
|
+
|
|
991
1076
|
if (target.length === 0) {
|
|
992
1077
|
return void 0;
|
|
993
1078
|
}
|
|
1079
|
+
|
|
994
1080
|
return target;
|
|
995
1081
|
}
|
|
996
1082
|
|
|
997
1083
|
async function _resolveBuildContext(options) {
|
|
998
|
-
var
|
|
999
|
-
|
|
1000
|
-
const
|
|
1084
|
+
var _ref9;
|
|
1085
|
+
|
|
1086
|
+
const {
|
|
1087
|
+
config,
|
|
1088
|
+
cwd,
|
|
1089
|
+
pkg,
|
|
1090
|
+
tsconfig: tsconfigPath
|
|
1091
|
+
} = options;
|
|
1092
|
+
const tsconfig = await _loadTSConfig({
|
|
1093
|
+
cwd,
|
|
1094
|
+
tsconfigPath
|
|
1095
|
+
});
|
|
1096
|
+
|
|
1001
1097
|
const targetVersions = _resolveBrowserslistVersions(pkg.browserslist || _DEFAULTS.browserslist);
|
|
1098
|
+
|
|
1002
1099
|
const srcPath = path.resolve(cwd, (config == null ? void 0 : config.src) || "src");
|
|
1003
1100
|
const distPath = path.resolve(cwd, (config == null ? void 0 : config.dist) || "dist");
|
|
1101
|
+
|
|
1004
1102
|
const nodeTarget = _resolveNodeTarget(targetVersions);
|
|
1103
|
+
|
|
1005
1104
|
const webTarget = _resolveBrowserTarget(targetVersions);
|
|
1105
|
+
|
|
1006
1106
|
if (!nodeTarget) {
|
|
1007
1107
|
throw new Error("no matching `node` target");
|
|
1008
1108
|
}
|
|
1109
|
+
|
|
1009
1110
|
if (!webTarget) {
|
|
1010
1111
|
throw new Error("no matching `web` target");
|
|
1011
1112
|
}
|
|
1113
|
+
|
|
1012
1114
|
const target = {
|
|
1013
1115
|
"*": webTarget.concat(nodeTarget),
|
|
1014
1116
|
browser: webTarget,
|
|
1015
1117
|
node: nodeTarget
|
|
1016
1118
|
};
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1119
|
+
|
|
1120
|
+
const parsedExports = _parseExports({
|
|
1121
|
+
pkg
|
|
1122
|
+
}).reduce((acc, x) => {
|
|
1123
|
+
const {
|
|
1124
|
+
_path: exportPath
|
|
1125
|
+
} = x,
|
|
1126
|
+
exportEntry = _objectWithoutProperties(x, _excluded);
|
|
1127
|
+
|
|
1128
|
+
return _objectSpread(_objectSpread({}, acc), {}, {
|
|
1129
|
+
[exportPath]: exportEntry
|
|
1130
|
+
});
|
|
1020
1131
|
}, {});
|
|
1132
|
+
|
|
1021
1133
|
const exports = _resolveConfigProperty(config == null ? void 0 : config.exports, parsedExports);
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
];
|
|
1134
|
+
|
|
1135
|
+
const parsedExternal = [...(pkg.dependencies ? Object.keys(pkg.dependencies) : []), ...(pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : [])];
|
|
1136
|
+
|
|
1026
1137
|
const external = _resolveConfigProperty(config == null ? void 0 : config.external, parsedExternal);
|
|
1138
|
+
|
|
1027
1139
|
const ctx = {
|
|
1028
1140
|
config,
|
|
1029
1141
|
cwd,
|
|
@@ -1032,25 +1144,41 @@ async function _resolveBuildContext(options) {
|
|
|
1032
1144
|
external,
|
|
1033
1145
|
files: [],
|
|
1034
1146
|
logger: {
|
|
1035
|
-
log: (
|
|
1036
|
-
console.log(...
|
|
1147
|
+
log: function () {
|
|
1148
|
+
console.log(...arguments);
|
|
1037
1149
|
},
|
|
1038
|
-
info: (
|
|
1150
|
+
info: function () {
|
|
1151
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1152
|
+
args[_key] = arguments[_key];
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1039
1155
|
console.log(chalk.blue(" info"), ...args);
|
|
1040
1156
|
},
|
|
1041
|
-
warn: (
|
|
1157
|
+
warn: function () {
|
|
1158
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
1159
|
+
args[_key2] = arguments[_key2];
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1042
1162
|
console.log(chalk.yellow(" warn"), ...args);
|
|
1043
1163
|
},
|
|
1044
|
-
error: (
|
|
1164
|
+
error: function () {
|
|
1165
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
1166
|
+
args[_key3] = arguments[_key3];
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1045
1169
|
console.log(chalk.red(" fail"), ...args);
|
|
1046
1170
|
},
|
|
1047
|
-
success: (
|
|
1171
|
+
success: function () {
|
|
1172
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
1173
|
+
args[_key4] = arguments[_key4];
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1048
1176
|
console.log(chalk.green(" ok "), ...args);
|
|
1049
1177
|
}
|
|
1050
1178
|
},
|
|
1051
1179
|
pkg,
|
|
1052
1180
|
src: path.relative(cwd, srcPath),
|
|
1053
|
-
runtime: (
|
|
1181
|
+
runtime: (_ref9 = config == null ? void 0 : config.runtime) !== null && _ref9 !== void 0 ? _ref9 : "*",
|
|
1054
1182
|
target,
|
|
1055
1183
|
ts: {
|
|
1056
1184
|
config: tsconfig,
|
|
@@ -1062,34 +1190,43 @@ async function _resolveBuildContext(options) {
|
|
|
1062
1190
|
|
|
1063
1191
|
function _spinner(msg) {
|
|
1064
1192
|
const startTime = Date.now();
|
|
1065
|
-
|
|
1066
|
-
spinner: "dots",
|
|
1067
|
-
text: `${chalk.yellow("run ")} ${msg}`
|
|
1068
|
-
});
|
|
1069
|
-
spinner.color = "yellow";
|
|
1070
|
-
spinner.start();
|
|
1193
|
+
console.log("".concat(chalk.yellow("run "), " ").concat(msg));
|
|
1071
1194
|
return {
|
|
1072
1195
|
complete: () => {
|
|
1073
|
-
|
|
1074
|
-
spinner.succeed(`${chalk.green("ok ")} ${msg} ${chalk.gray(`${Date.now() - startTime}ms`)}`);
|
|
1196
|
+
console.log("".concat(chalk.green("ok "), " ").concat(chalk.gray("".concat(Date.now() - startTime, "ms"))));
|
|
1075
1197
|
},
|
|
1076
1198
|
error: () => {
|
|
1077
|
-
|
|
1078
|
-
spinner.fail(chalk.red(`${msg} failed ${chalk.gray(`${Date.now() - startTime}ms`)}`));
|
|
1199
|
+
console.log("".concat(chalk.red("failed"), " ").concat(chalk.gray("".concat(Date.now() - startTime, "ms"))));
|
|
1079
1200
|
}
|
|
1080
1201
|
};
|
|
1081
1202
|
}
|
|
1082
1203
|
|
|
1083
1204
|
async function build(options) {
|
|
1084
|
-
const {
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1205
|
+
const {
|
|
1206
|
+
cwd,
|
|
1207
|
+
tsconfig = "tsconfig.json"
|
|
1208
|
+
} = options;
|
|
1209
|
+
const pkg = await _loadPkgWithReporting({
|
|
1210
|
+
cwd
|
|
1211
|
+
});
|
|
1212
|
+
const config = await _loadConfig({
|
|
1213
|
+
cwd
|
|
1214
|
+
});
|
|
1215
|
+
const ctx = await _resolveBuildContext({
|
|
1216
|
+
config,
|
|
1217
|
+
cwd,
|
|
1218
|
+
pkg,
|
|
1219
|
+
tsconfig
|
|
1220
|
+
});
|
|
1221
|
+
|
|
1088
1222
|
const buildTasks = _resolveBuildTasks(ctx);
|
|
1223
|
+
|
|
1089
1224
|
for (const task of buildTasks) {
|
|
1090
1225
|
const handler = _buildTaskHandlers[task.type];
|
|
1091
1226
|
const taskName = handler.name(ctx, task);
|
|
1227
|
+
|
|
1092
1228
|
const spinner = _spinner(taskName);
|
|
1229
|
+
|
|
1093
1230
|
try {
|
|
1094
1231
|
const result = await handler.exec(ctx, task).toPromise();
|
|
1095
1232
|
spinner.complete();
|
|
@@ -1097,60 +1234,157 @@ async function build(options) {
|
|
|
1097
1234
|
handler.complete(ctx, task, result);
|
|
1098
1235
|
} catch (err) {
|
|
1099
1236
|
spinner.error();
|
|
1237
|
+
|
|
1100
1238
|
if (err instanceof Error) {
|
|
1101
|
-
const RE_CWD = new RegExp(
|
|
1239
|
+
const RE_CWD = new RegExp("".concat(cwd), "g");
|
|
1102
1240
|
ctx.logger.error(err.message.replace(RE_CWD, "."));
|
|
1103
1241
|
ctx.logger.log();
|
|
1104
1242
|
}
|
|
1243
|
+
|
|
1105
1244
|
handler.error(ctx, task, err);
|
|
1106
1245
|
process.exit(1);
|
|
1107
1246
|
}
|
|
1108
1247
|
}
|
|
1109
|
-
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
function _getFilesize(file) {
|
|
1251
|
+
const stats = statSync(file);
|
|
1252
|
+
return prettyBytes(stats.size);
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
function _fileExists(file) {
|
|
1256
|
+
try {
|
|
1257
|
+
fs$1.accessSync(file);
|
|
1258
|
+
return true;
|
|
1259
|
+
} catch (_) {
|
|
1260
|
+
return false;
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
function _getFileInfo(cwd, filePath) {
|
|
1265
|
+
const p = path.resolve(cwd, filePath);
|
|
1266
|
+
|
|
1267
|
+
const exists = _fileExists(p);
|
|
1268
|
+
|
|
1269
|
+
const size = exists ? _getFilesize(p) : void 0;
|
|
1270
|
+
return {
|
|
1271
|
+
exists,
|
|
1272
|
+
size
|
|
1273
|
+
};
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
function _printPackageTree(ctx) {
|
|
1277
|
+
const {
|
|
1278
|
+
cwd,
|
|
1279
|
+
exports,
|
|
1280
|
+
logger,
|
|
1281
|
+
pkg
|
|
1282
|
+
} = ctx;
|
|
1283
|
+
if (!exports) return;
|
|
1284
|
+
logger.log("".concat(chalk.blue(pkg.name), "@").concat(chalk.green(pkg.version)));
|
|
1285
|
+
const tree = {};
|
|
1286
|
+
|
|
1287
|
+
if (pkg.bin) {
|
|
1288
|
+
tree.bin = pkg.bin;
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
function _fileInfo(file) {
|
|
1292
|
+
const info = _getFileInfo(cwd, file);
|
|
1293
|
+
|
|
1294
|
+
if (!info.size) {
|
|
1295
|
+
return "".concat(chalk.gray(file), " ").concat(chalk.red("does not exist"));
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
return "".concat(file, " ").concat(chalk.gray(info.size));
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
tree.exports = Object.fromEntries(Object.entries(exports).filter(_ref10 => {
|
|
1302
|
+
let [, entry] = _ref10;
|
|
1303
|
+
return entry._exported;
|
|
1304
|
+
}).map(_ref11 => {
|
|
1305
|
+
let [exportPath, entry] = _ref11;
|
|
1306
|
+
const exp = {
|
|
1307
|
+
source: entry.source,
|
|
1308
|
+
default: entry.default
|
|
1309
|
+
};
|
|
1310
|
+
|
|
1311
|
+
if (entry.browser) {
|
|
1312
|
+
exp.browser = {};
|
|
1313
|
+
if (entry.browser.import) exp.browser.import = _fileInfo(entry.browser.import);
|
|
1314
|
+
if (entry.browser.require) exp.browser.import = _fileInfo(entry.browser.require);
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
if (entry.import) exp.import = _fileInfo(entry.import);
|
|
1318
|
+
if (entry.require) exp.require = _fileInfo(entry.require);
|
|
1319
|
+
if (entry.types) exp.types = _fileInfo(entry.types);
|
|
1320
|
+
exp.default = _fileInfo(entry.default);
|
|
1321
|
+
return [chalk.green(path.join(pkg.name, exportPath)), exp];
|
|
1322
|
+
}));
|
|
1323
|
+
logger.log(treeify.asTree(tree, true, true));
|
|
1110
1324
|
}
|
|
1111
1325
|
|
|
1112
1326
|
async function check(options) {
|
|
1113
|
-
const {
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1327
|
+
const {
|
|
1328
|
+
cwd,
|
|
1329
|
+
strict,
|
|
1330
|
+
tsconfig = "tsconfig.json"
|
|
1331
|
+
} = options;
|
|
1332
|
+
const pkg = await _loadPkgWithReporting({
|
|
1333
|
+
cwd
|
|
1334
|
+
});
|
|
1335
|
+
const config = await _loadConfig({
|
|
1336
|
+
cwd
|
|
1337
|
+
});
|
|
1338
|
+
const ctx = await _resolveBuildContext({
|
|
1339
|
+
config,
|
|
1340
|
+
cwd,
|
|
1341
|
+
pkg,
|
|
1342
|
+
tsconfig
|
|
1343
|
+
});
|
|
1344
|
+
|
|
1117
1345
|
_printPackageTree(ctx);
|
|
1346
|
+
|
|
1118
1347
|
if (strict) {
|
|
1119
1348
|
const missingFiles = [];
|
|
1349
|
+
|
|
1120
1350
|
for (const [, exp] of Object.entries(ctx.exports || {})) {
|
|
1121
1351
|
if (exp.source && !_fileExists(path.resolve(cwd, exp.source))) {
|
|
1122
1352
|
missingFiles.push(exp.source);
|
|
1123
1353
|
}
|
|
1354
|
+
|
|
1124
1355
|
if (exp.require && !_fileExists(path.resolve(cwd, exp.require))) {
|
|
1125
1356
|
missingFiles.push(exp.require);
|
|
1126
1357
|
}
|
|
1358
|
+
|
|
1127
1359
|
if (exp.import && !_fileExists(path.resolve(cwd, exp.import))) {
|
|
1128
1360
|
missingFiles.push(exp.import);
|
|
1129
1361
|
}
|
|
1362
|
+
|
|
1130
1363
|
if (exp.types && !_fileExists(path.resolve(cwd, exp.types))) {
|
|
1131
1364
|
missingFiles.push(exp.types);
|
|
1132
1365
|
}
|
|
1133
1366
|
}
|
|
1367
|
+
|
|
1134
1368
|
if (missingFiles.length) {
|
|
1135
1369
|
throw new Error("missing files");
|
|
1136
1370
|
}
|
|
1371
|
+
|
|
1137
1372
|
const _paths = {
|
|
1138
1373
|
require: [],
|
|
1139
1374
|
import: []
|
|
1140
1375
|
};
|
|
1376
|
+
|
|
1141
1377
|
for (const [exportPath, exp] of Object.entries(ctx.exports || {})) {
|
|
1142
|
-
if (!exp._exported)
|
|
1143
|
-
|
|
1144
|
-
if (exp.
|
|
1145
|
-
_paths.require.push(exportPath);
|
|
1146
|
-
if (exp.import)
|
|
1147
|
-
_paths.import.push(exportPath);
|
|
1378
|
+
if (!exp._exported) continue;
|
|
1379
|
+
if (exp.require) _paths.require.push(exportPath);
|
|
1380
|
+
if (exp.import) _paths.import.push(exportPath);
|
|
1148
1381
|
}
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1382
|
+
|
|
1383
|
+
const external = Object.keys(pkg.dependencies || {}).concat(Object.keys(pkg.devDependencies || {}));
|
|
1384
|
+
|
|
1152
1385
|
if (_paths.import.length) {
|
|
1153
|
-
const code = _paths.import.map(
|
|
1386
|
+
const code = _paths.import.map(id => "import('".concat(id, "')")).join("\n");
|
|
1387
|
+
|
|
1154
1388
|
try {
|
|
1155
1389
|
const esbuildResult = await esbuild$1.build({
|
|
1156
1390
|
external,
|
|
@@ -1165,29 +1399,34 @@ async function check(options) {
|
|
|
1165
1399
|
outfile: "/dev/null",
|
|
1166
1400
|
platform: "node"
|
|
1167
1401
|
});
|
|
1402
|
+
|
|
1168
1403
|
if (esbuildResult.warnings.length > 0) {
|
|
1169
1404
|
console.warn(...esbuildResult.warnings);
|
|
1170
1405
|
}
|
|
1171
1406
|
} catch (err) {
|
|
1172
|
-
const {
|
|
1407
|
+
const {
|
|
1408
|
+
errors
|
|
1409
|
+
} = err;
|
|
1410
|
+
|
|
1173
1411
|
for (const _err of errors) {
|
|
1174
1412
|
if (_err.location) {
|
|
1175
1413
|
console.log(chalk.red("error"), _err.detail || _err.text);
|
|
1176
|
-
console.log(
|
|
1177
|
-
console.log(
|
|
1178
|
-
"in",
|
|
1179
|
-
`./${_err.location.file}:${_err.location.line}:${_err.location.column}`
|
|
1180
|
-
);
|
|
1414
|
+
console.log("".concat(_err.location.line, " | ").concat(_err.location.lineText));
|
|
1415
|
+
console.log("in", "./".concat(_err.location.file, ":").concat(_err.location.line, ":").concat(_err.location.column));
|
|
1181
1416
|
} else {
|
|
1182
1417
|
console.log(_err.detail || _err.text);
|
|
1183
1418
|
}
|
|
1419
|
+
|
|
1184
1420
|
console.log();
|
|
1185
1421
|
}
|
|
1422
|
+
|
|
1186
1423
|
process.exit(1);
|
|
1187
1424
|
}
|
|
1188
1425
|
}
|
|
1426
|
+
|
|
1189
1427
|
if (_paths.require.length) {
|
|
1190
|
-
const code = _paths.require.map(
|
|
1428
|
+
const code = _paths.require.map(id => "require('".concat(id, "')")).join("\n");
|
|
1429
|
+
|
|
1191
1430
|
const esbuildResult = await esbuild$1.build({
|
|
1192
1431
|
external,
|
|
1193
1432
|
stdin: {
|
|
@@ -1200,9 +1439,11 @@ async function check(options) {
|
|
|
1200
1439
|
outfile: "/dev/null",
|
|
1201
1440
|
platform: "node"
|
|
1202
1441
|
});
|
|
1442
|
+
|
|
1203
1443
|
if (esbuildResult.errors.length > 0) {
|
|
1204
1444
|
throw new Error(esbuildResult.errors.join(", "));
|
|
1205
1445
|
}
|
|
1446
|
+
|
|
1206
1447
|
if (esbuildResult.warnings.length > 0) {
|
|
1207
1448
|
console.warn(...esbuildResult.warnings);
|
|
1208
1449
|
}
|
|
@@ -1212,16 +1453,25 @@ async function check(options) {
|
|
|
1212
1453
|
|
|
1213
1454
|
function _resolveWatchTasks(ctx) {
|
|
1214
1455
|
var _a, _b, _c, _d, _e;
|
|
1215
|
-
|
|
1216
|
-
const
|
|
1456
|
+
|
|
1457
|
+
const {
|
|
1458
|
+
cwd,
|
|
1459
|
+
pkg,
|
|
1460
|
+
target
|
|
1461
|
+
} = ctx;
|
|
1217
1462
|
const tasks = [];
|
|
1218
|
-
const exports = Object.entries(ctx.exports || {}).map(
|
|
1219
|
-
|
|
1220
|
-
|
|
1463
|
+
const exports = Object.entries(ctx.exports || {}).map(_ref12 => {
|
|
1464
|
+
let [_path, exp] = _ref12;
|
|
1465
|
+
return _objectSpread({
|
|
1466
|
+
_path
|
|
1467
|
+
}, exp);
|
|
1468
|
+
});
|
|
1221
1469
|
const dtsTasks = {};
|
|
1222
1470
|
const rollupTasks = {};
|
|
1471
|
+
|
|
1223
1472
|
function _addRollupTaskEntry(format, runtime, entry) {
|
|
1224
|
-
const buildId =
|
|
1473
|
+
const buildId = "".concat(format, ":").concat(runtime);
|
|
1474
|
+
|
|
1225
1475
|
if (!rollupTasks[buildId]) {
|
|
1226
1476
|
rollupTasks[buildId] = {
|
|
1227
1477
|
type: "watch:js",
|
|
@@ -1229,14 +1479,16 @@ function _resolveWatchTasks(ctx) {
|
|
|
1229
1479
|
entries: [entry],
|
|
1230
1480
|
runtime,
|
|
1231
1481
|
format,
|
|
1232
|
-
target:
|
|
1482
|
+
target: target[runtime]
|
|
1233
1483
|
};
|
|
1234
1484
|
} else {
|
|
1235
1485
|
rollupTasks[buildId].entries.push(entry);
|
|
1236
1486
|
}
|
|
1237
1487
|
}
|
|
1488
|
+
|
|
1238
1489
|
for (const exp of exports) {
|
|
1239
1490
|
const importId = path.join(pkg.name, exp._path);
|
|
1491
|
+
|
|
1240
1492
|
if (exp.types) {
|
|
1241
1493
|
if (!dtsTasks[importId]) {
|
|
1242
1494
|
dtsTasks[importId] = {
|
|
@@ -1249,65 +1501,64 @@ function _resolveWatchTasks(ctx) {
|
|
|
1249
1501
|
}
|
|
1250
1502
|
}
|
|
1251
1503
|
}
|
|
1504
|
+
|
|
1252
1505
|
for (const exp of exports) {
|
|
1253
1506
|
const output = exp.require;
|
|
1254
|
-
if (!output)
|
|
1255
|
-
|
|
1507
|
+
if (!output) continue;
|
|
1508
|
+
|
|
1256
1509
|
_addRollupTaskEntry("commonjs", ctx.runtime, {
|
|
1257
1510
|
path: exp._path,
|
|
1258
1511
|
source: exp.source,
|
|
1259
1512
|
output
|
|
1260
1513
|
});
|
|
1261
1514
|
}
|
|
1515
|
+
|
|
1262
1516
|
for (const exp of exports) {
|
|
1263
1517
|
const output = (_a = exp.browser) == null ? void 0 : _a.require;
|
|
1264
|
-
if (!output)
|
|
1265
|
-
|
|
1518
|
+
if (!output) continue;
|
|
1519
|
+
|
|
1266
1520
|
_addRollupTaskEntry("commonjs", "browser", {
|
|
1267
1521
|
path: exp._path,
|
|
1268
1522
|
source: ((_b = exp.browser) == null ? void 0 : _b.source) || exp.source,
|
|
1269
1523
|
output
|
|
1270
1524
|
});
|
|
1271
1525
|
}
|
|
1526
|
+
|
|
1272
1527
|
for (const exp of exports) {
|
|
1273
1528
|
const output = exp.import;
|
|
1274
|
-
if (!output)
|
|
1275
|
-
|
|
1529
|
+
if (!output) continue;
|
|
1530
|
+
|
|
1276
1531
|
_addRollupTaskEntry("esm", ctx.runtime, {
|
|
1277
1532
|
path: exp._path,
|
|
1278
1533
|
source: exp.source,
|
|
1279
1534
|
output
|
|
1280
1535
|
});
|
|
1281
1536
|
}
|
|
1537
|
+
|
|
1282
1538
|
for (const exp of exports) {
|
|
1283
1539
|
const output = (_c = exp.browser) == null ? void 0 : _c.import;
|
|
1284
|
-
if (!output)
|
|
1285
|
-
|
|
1540
|
+
if (!output) continue;
|
|
1541
|
+
|
|
1286
1542
|
_addRollupTaskEntry("esm", "browser", {
|
|
1287
1543
|
path: exp._path,
|
|
1288
1544
|
source: ((_d = exp.browser) == null ? void 0 : _d.source) || exp.source,
|
|
1289
1545
|
output
|
|
1290
1546
|
});
|
|
1291
1547
|
}
|
|
1548
|
+
|
|
1292
1549
|
tasks.push(...Object.values(dtsTasks));
|
|
1293
1550
|
tasks.push(...Object.values(rollupTasks));
|
|
1551
|
+
|
|
1294
1552
|
for (const exp of exports) {
|
|
1295
1553
|
if (exp._exported && exp._path !== ".") {
|
|
1296
1554
|
const relativeTargetPath = (((_e = exp.browser) == null ? void 0 : _e.import) || exp.import || "").replace(/\.[^/.]+$/, "");
|
|
1555
|
+
|
|
1297
1556
|
if (relativeTargetPath) {
|
|
1298
|
-
fs$1.writeFileSync(
|
|
1299
|
-
path.resolve(cwd, `${exp._path}.js`),
|
|
1300
|
-
[
|
|
1301
|
-
`// AUTO-GENERATED \u2013 DO NOT EDIT`,
|
|
1302
|
-
``,
|
|
1303
|
-
`export {default} from '${relativeTargetPath}'`,
|
|
1304
|
-
`export * from '${relativeTargetPath}'`,
|
|
1305
|
-
``
|
|
1306
|
-
].join("\n")
|
|
1307
|
-
);
|
|
1557
|
+
fs$1.writeFileSync(path.resolve(cwd, "".concat(exp._path, ".js")), ["// AUTO-GENERATED \u2013 DO NOT EDIT", "", "export {default} from '".concat(relativeTargetPath, "'"), "export * from '".concat(relativeTargetPath, "'"), ""].join("\n"));
|
|
1308
1558
|
}
|
|
1309
1559
|
}
|
|
1310
1560
|
}
|
|
1561
|
+
|
|
1311
1562
|
return tasks;
|
|
1312
1563
|
}
|
|
1313
1564
|
|
|
@@ -1316,13 +1567,18 @@ function _globFiles(patterns) {
|
|
|
1316
1567
|
}
|
|
1317
1568
|
|
|
1318
1569
|
function _watchFiles(patterns) {
|
|
1319
|
-
return new Observable(
|
|
1570
|
+
return new Observable(observer => {
|
|
1320
1571
|
const watcher = chokidar.watch(patterns, {
|
|
1321
1572
|
ignoreInitial: true
|
|
1322
1573
|
});
|
|
1574
|
+
|
|
1323
1575
|
function _handleFileEvent(type, file) {
|
|
1324
|
-
observer.next({
|
|
1576
|
+
observer.next({
|
|
1577
|
+
type,
|
|
1578
|
+
file
|
|
1579
|
+
});
|
|
1325
1580
|
}
|
|
1581
|
+
|
|
1326
1582
|
watcher.on("all", _handleFileEvent);
|
|
1327
1583
|
return () => {
|
|
1328
1584
|
watcher.off("all", _handleFileEvent);
|
|
@@ -1332,69 +1588,76 @@ function _watchFiles(patterns) {
|
|
|
1332
1588
|
}
|
|
1333
1589
|
|
|
1334
1590
|
async function _watchConfigFiles(options) {
|
|
1335
|
-
const {
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
console.log(chalk.blue("info "), path.relative(cwd, fileEvent.file), "changed");
|
|
1361
|
-
console.log("");
|
|
1362
|
-
return files.slice(0);
|
|
1363
|
-
}
|
|
1364
|
-
return files;
|
|
1365
|
-
}, initialFiles),
|
|
1366
|
-
startWith(initialFiles),
|
|
1367
|
-
distinctUntilChanged()
|
|
1368
|
-
);
|
|
1591
|
+
const {
|
|
1592
|
+
cwd
|
|
1593
|
+
} = options;
|
|
1594
|
+
const initialFiles = await _globFiles([path.resolve(cwd, "package.json"), path.resolve(cwd, "package.config.cjs"), path.resolve(cwd, "package.config.js"), path.resolve(cwd, "package.config.ts")]);
|
|
1595
|
+
|
|
1596
|
+
const fileEvent$ = _watchFiles([path.resolve(cwd, "package.json"), path.resolve(cwd, "package.config.cjs"), path.resolve(cwd, "package.config.js"), path.resolve(cwd, "package.config.ts")]);
|
|
1597
|
+
|
|
1598
|
+
return fileEvent$.pipe(scan((files, fileEvent) => {
|
|
1599
|
+
if (fileEvent.type === "add") {
|
|
1600
|
+
return files.concat(fileEvent.file);
|
|
1601
|
+
}
|
|
1602
|
+
|
|
1603
|
+
if (fileEvent.type === "unlink") {
|
|
1604
|
+
return files.filter(f => f !== fileEvent.file);
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
if (fileEvent.type === "change") {
|
|
1608
|
+
console.log("--------------------------------------------------------------------------------");
|
|
1609
|
+
console.log(chalk.blue("info "), path.relative(cwd, fileEvent.file), "changed");
|
|
1610
|
+
console.log("");
|
|
1611
|
+
return files.slice(0);
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
return files;
|
|
1615
|
+
}, initialFiles), startWith(initialFiles), distinctUntilChanged());
|
|
1369
1616
|
}
|
|
1370
1617
|
|
|
1371
1618
|
async function watch(options) {
|
|
1372
|
-
const {
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1619
|
+
const {
|
|
1620
|
+
cwd,
|
|
1621
|
+
tsconfig = "tsconfig.json"
|
|
1622
|
+
} = options;
|
|
1623
|
+
const configFiles$ = await _watchConfigFiles({
|
|
1624
|
+
cwd
|
|
1625
|
+
});
|
|
1626
|
+
const ctx$ = configFiles$.pipe(switchMap(async configFiles => {
|
|
1627
|
+
const _files = configFiles.map(f => path.relative(cwd, f));
|
|
1628
|
+
|
|
1629
|
+
const packageJsonPath = _files.find(f => f === "package.json");
|
|
1630
|
+
|
|
1631
|
+
if (!packageJsonPath) {
|
|
1632
|
+
throw new Error("missing package.json");
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
const pkg = await _loadPkgWithReporting({
|
|
1636
|
+
cwd
|
|
1637
|
+
});
|
|
1638
|
+
const config = await _loadConfig({
|
|
1639
|
+
cwd
|
|
1640
|
+
});
|
|
1641
|
+
return _resolveBuildContext({
|
|
1642
|
+
config,
|
|
1643
|
+
cwd,
|
|
1644
|
+
pkg,
|
|
1645
|
+
tsconfig
|
|
1646
|
+
});
|
|
1647
|
+
}));
|
|
1648
|
+
ctx$.subscribe(async ctx => {
|
|
1387
1649
|
const watchTasks = _resolveWatchTasks(ctx);
|
|
1650
|
+
|
|
1388
1651
|
for (const task of watchTasks) {
|
|
1389
1652
|
const handler = _watchTaskHandlers[task.type];
|
|
1390
1653
|
const result$ = handler.exec(ctx, task);
|
|
1391
1654
|
result$.subscribe({
|
|
1392
|
-
error:
|
|
1655
|
+
error: err => {
|
|
1393
1656
|
ctx.logger.error(err);
|
|
1394
1657
|
ctx.logger.log();
|
|
1395
1658
|
process.exit(1);
|
|
1396
1659
|
},
|
|
1397
|
-
next:
|
|
1660
|
+
next: result => {
|
|
1398
1661
|
handler.complete(ctx, task, result);
|
|
1399
1662
|
},
|
|
1400
1663
|
complete: () => {
|