@sanity/pkg-utils 1.17.3 → 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/dist/_chunks/_handleError-869dec25.js +0 -5
- package/dist/_chunks/_handleError-869dec25.js.map +1 -1
- package/dist/_chunks/_resolveBuildContext-7ca7e64e.js +3 -122
- package/dist/_chunks/_resolveBuildContext-7ca7e64e.js.map +1 -1
- package/dist/_chunks/{build-6fac40bf.js → build-f39a3550.js} +2 -46
- package/dist/_chunks/{build-6fac40bf.js.map → build-f39a3550.js.map} +1 -1
- package/dist/_chunks/{buildAction-ff3e6d24.js → buildAction-8f449d1d.js} +5 -35
- package/dist/_chunks/{buildAction-ff3e6d24.js.map → buildAction-8f449d1d.js.map} +1 -1
- package/dist/_chunks/check-87cbb6cc.js +0 -55
- package/dist/_chunks/check-87cbb6cc.js.map +1 -1
- package/dist/_chunks/checkAction-e7e455d4.js +0 -17
- package/dist/_chunks/checkAction-e7e455d4.js.map +1 -1
- package/dist/_chunks/{index-fbba5480.js → index-7a851efa.js} +47 -224
- package/dist/_chunks/index-7a851efa.js.map +1 -0
- package/dist/_chunks/{watch-2ea1243e.js → watch-f6cf9246.js} +2 -57
- package/dist/_chunks/{watch-2ea1243e.js.map → watch-f6cf9246.js.map} +1 -1
- package/dist/_chunks/{watchAction-10e52cbc.js → watchAction-4cf253a0.js} +5 -38
- package/dist/_chunks/{watchAction-10e52cbc.js.map → watchAction-4cf253a0.js.map} +1 -1
- package/dist/cli.js +3 -6
- package/dist/cli.js.map +1 -1
- package/dist/index.esm.js +56 -397
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +5 -43
- package/dist/index.js.map +1 -1
- package/package.json +3 -1
- package/src/node/_tasks/dts/_doExtract.ts +2 -8
- package/src/node/_tasks/dts/_extractModuleBlocks.ts +45 -0
- package/src/node/_tasks/dts/_extractTypes.ts +11 -1
- package/dist/_chunks/index-fbba5480.js.map +0 -1
- package/src/node/_tasks/dts/_declareModuleFix.ts +0 -99
|
@@ -1,143 +1,93 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
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; }
|
|
4
|
-
|
|
5
4
|
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; }
|
|
6
|
-
|
|
7
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
-
|
|
9
6
|
var chalk = require('chalk');
|
|
10
|
-
|
|
11
7
|
var rxjs = require('rxjs');
|
|
12
|
-
|
|
13
8
|
var path = require('path');
|
|
14
|
-
|
|
15
9
|
var util = require('util');
|
|
16
|
-
|
|
17
10
|
var rimrafCallback = require('rimraf');
|
|
18
|
-
|
|
19
11
|
var ts = require('typescript');
|
|
20
|
-
|
|
21
12
|
var fs = require('fs/promises');
|
|
22
|
-
|
|
23
13
|
var apiExtractor = require('@microsoft/api-extractor');
|
|
24
|
-
|
|
25
14
|
var mkdirp = require('mkdirp');
|
|
26
|
-
|
|
27
15
|
var prettier = require('prettier');
|
|
28
|
-
|
|
29
16
|
var tsdocConfig = require('@microsoft/tsdoc-config');
|
|
30
|
-
|
|
31
17
|
var jsoncParser = require('jsonc-parser');
|
|
32
|
-
|
|
18
|
+
var recast = require('recast');
|
|
19
|
+
var typeScriptParser = require('recast/parsers/typescript');
|
|
33
20
|
var rollup = require('rollup');
|
|
34
|
-
|
|
35
21
|
var alias = require('@rollup/plugin-alias');
|
|
36
|
-
|
|
37
22
|
var pluginBabel = require('@rollup/plugin-babel');
|
|
38
|
-
|
|
39
23
|
var commonjs = require('@rollup/plugin-commonjs');
|
|
40
|
-
|
|
41
24
|
var json = require('@rollup/plugin-json');
|
|
42
|
-
|
|
43
25
|
var pluginNodeResolve = require('@rollup/plugin-node-resolve');
|
|
44
|
-
|
|
45
26
|
var replace = require('@rollup/plugin-replace');
|
|
46
|
-
|
|
47
27
|
var esbuild = require('rollup-plugin-esbuild');
|
|
48
|
-
|
|
49
28
|
var rollupPluginTerser = require('rollup-plugin-terser');
|
|
50
|
-
|
|
51
29
|
var _resolveBuildContext = require('./_resolveBuildContext-7ca7e64e.js');
|
|
52
|
-
|
|
53
30
|
require('esbuild-register/dist/node');
|
|
54
|
-
|
|
55
31
|
require('pkg-up');
|
|
56
|
-
|
|
57
32
|
require('find-config');
|
|
58
|
-
|
|
59
33
|
require('zod');
|
|
60
|
-
|
|
61
34
|
function _interopDefaultLegacy(e) {
|
|
62
35
|
return e && typeof e === 'object' && 'default' in e ? e : {
|
|
63
36
|
'default': e
|
|
64
37
|
};
|
|
65
38
|
}
|
|
66
|
-
|
|
67
39
|
var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
|
|
68
|
-
|
|
69
40
|
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
70
|
-
|
|
71
41
|
var rimrafCallback__default = /*#__PURE__*/_interopDefaultLegacy(rimrafCallback);
|
|
72
|
-
|
|
73
42
|
var ts__default = /*#__PURE__*/_interopDefaultLegacy(ts);
|
|
74
|
-
|
|
75
43
|
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
76
|
-
|
|
77
44
|
var mkdirp__default = /*#__PURE__*/_interopDefaultLegacy(mkdirp);
|
|
78
|
-
|
|
79
45
|
var prettier__default = /*#__PURE__*/_interopDefaultLegacy(prettier);
|
|
80
|
-
|
|
46
|
+
var typeScriptParser__default = /*#__PURE__*/_interopDefaultLegacy(typeScriptParser);
|
|
81
47
|
var alias__default = /*#__PURE__*/_interopDefaultLegacy(alias);
|
|
82
|
-
|
|
83
48
|
var commonjs__default = /*#__PURE__*/_interopDefaultLegacy(commonjs);
|
|
84
|
-
|
|
85
49
|
var json__default = /*#__PURE__*/_interopDefaultLegacy(json);
|
|
86
|
-
|
|
87
50
|
var replace__default = /*#__PURE__*/_interopDefaultLegacy(replace);
|
|
88
|
-
|
|
89
51
|
var esbuild__default = /*#__PURE__*/_interopDefaultLegacy(esbuild);
|
|
90
|
-
|
|
91
52
|
function _printExtractMessages(ctx, messages) {
|
|
92
53
|
const {
|
|
93
54
|
cwd,
|
|
94
55
|
logger
|
|
95
56
|
} = ctx;
|
|
96
57
|
const warnings = messages.filter(msg => msg.logLevel === "warning");
|
|
97
|
-
|
|
98
58
|
if (warnings.length) {
|
|
99
59
|
logger.log();
|
|
100
60
|
}
|
|
101
|
-
|
|
102
61
|
for (const msg of warnings) {
|
|
103
62
|
const sourceFilePath = msg.sourceFilePath && path__default["default"].relative(cwd, msg.sourceFilePath);
|
|
104
|
-
|
|
105
63
|
if (msg.messageId === "TS6307") {
|
|
106
64
|
continue;
|
|
107
65
|
}
|
|
108
|
-
|
|
109
66
|
logger.log(["".concat(chalk__default["default"].cyan(sourceFilePath || "?")), ":".concat(chalk__default["default"].yellow(msg.sourceFileLine), ":").concat(chalk__default["default"].yellow(msg.sourceFileColumn)), " - ".concat(chalk__default["default"].yellow("warning"), " ").concat(chalk__default["default"].gray(msg.messageId), "\n"), msg.text, "\n"].join(""));
|
|
110
67
|
}
|
|
111
|
-
|
|
112
68
|
const errors = messages.filter(msg => msg.logLevel === "error");
|
|
113
|
-
|
|
114
69
|
if (!warnings.length && errors.length) {
|
|
115
70
|
logger.log("");
|
|
116
71
|
}
|
|
117
|
-
|
|
118
72
|
for (const msg of errors) {
|
|
119
73
|
const sourceFilePath = msg.sourceFilePath && path__default["default"].relative(cwd, msg.sourceFilePath);
|
|
120
74
|
logger.log(["".concat(chalk__default["default"].cyan(sourceFilePath || "?")), ":".concat(chalk__default["default"].yellow(msg.sourceFileLine), ":").concat(chalk__default["default"].yellow(msg.sourceFileColumn)), " - ".concat(chalk__default["default"].red("error"), " ").concat(chalk__default["default"].gray(msg.messageId), "\n"), msg.text, "\n"].join(""));
|
|
121
75
|
}
|
|
122
|
-
|
|
123
76
|
if (errors.length) {
|
|
124
77
|
process.exit(1);
|
|
125
78
|
}
|
|
126
79
|
}
|
|
127
|
-
|
|
128
80
|
const formatHost = {
|
|
129
81
|
getCurrentDirectory: () => ts__default["default"].sys.getCurrentDirectory(),
|
|
130
82
|
getNewLine: () => ts__default["default"].sys.newLine,
|
|
131
83
|
getCanonicalFileName: ts__default["default"].sys.useCaseSensitiveFileNames ? f => f : f => f.toLowerCase()
|
|
132
84
|
};
|
|
133
|
-
|
|
134
85
|
async function _buildTypes(options) {
|
|
135
86
|
const {
|
|
136
87
|
outDir,
|
|
137
88
|
tsconfig,
|
|
138
89
|
strict = false
|
|
139
90
|
} = options;
|
|
140
|
-
|
|
141
91
|
const compilerOptions = _objectSpread(_objectSpread({}, tsconfig.options), {}, {
|
|
142
92
|
declaration: true,
|
|
143
93
|
declarationDir: outDir,
|
|
@@ -145,7 +95,6 @@ async function _buildTypes(options) {
|
|
|
145
95
|
noEmit: false,
|
|
146
96
|
outDir
|
|
147
97
|
});
|
|
148
|
-
|
|
149
98
|
const program = ts__default["default"].createProgram(tsconfig.fileNames, compilerOptions);
|
|
150
99
|
const emitResult = program.emit();
|
|
151
100
|
const allDiagnostics = ts__default["default"].getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
@@ -161,109 +110,22 @@ async function _buildTypes(options) {
|
|
|
161
110
|
console.log(ts__default["default"].flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
|
|
162
111
|
}
|
|
163
112
|
});
|
|
164
|
-
|
|
165
113
|
if (emitResult.emitSkipped) {
|
|
166
114
|
const errors = allDiagnostics.filter(diag => diag.category === ts__default["default"].DiagnosticCategory.Error);
|
|
167
|
-
|
|
168
115
|
if (errors.length) {
|
|
169
116
|
console.error(ts__default["default"].formatDiagnostics(errors, formatHost));
|
|
170
|
-
|
|
171
117
|
if (strict) {
|
|
172
118
|
throw new Error("failed to compile TypeScript definitions");
|
|
173
119
|
}
|
|
174
120
|
}
|
|
175
121
|
}
|
|
176
122
|
}
|
|
177
|
-
|
|
178
|
-
async function _appendModuleBlocks(_ref) {
|
|
179
|
-
let {
|
|
180
|
-
tsOutDir,
|
|
181
|
-
extractResult,
|
|
182
|
-
extractTypesOutFile
|
|
183
|
-
} = _ref;
|
|
184
|
-
const moduleBlocks = await _extractModuleBlocksFromTypes({
|
|
185
|
-
tsOutDir,
|
|
186
|
-
extractResult
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
if (moduleBlocks.length) {
|
|
190
|
-
await fs__default["default"].appendFile(extractTypesOutFile, "\n" + moduleBlocks.join("\n\n"));
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
async function _extractModuleBlocksFromTypes(_ref2) {
|
|
195
|
-
let {
|
|
196
|
-
tsOutDir,
|
|
197
|
-
extractResult
|
|
198
|
-
} = _ref2;
|
|
199
|
-
const moduleBlocks = [];
|
|
200
|
-
const program = extractResult.compilerState.program;
|
|
201
|
-
const allProgramFiles = [...program.getSourceFiles()];
|
|
202
|
-
const sourceFiles = allProgramFiles.filter(sourceFile => sourceFile.fileName.includes(tsOutDir));
|
|
203
|
-
|
|
204
|
-
for (const sourceFile of sourceFiles) {
|
|
205
|
-
if (sourceFile.text.includes("declare module")) {
|
|
206
|
-
moduleBlocks.push(..._extractModuleBlocks(sourceFile.text));
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return moduleBlocks;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
function _extractModuleBlocks(fileContent) {
|
|
214
|
-
var _a;
|
|
215
|
-
|
|
216
|
-
const moduleBlocks = [];
|
|
217
|
-
let moduleIndentLevel = 0;
|
|
218
|
-
let insideComment = false;
|
|
219
|
-
let moduleLines = [];
|
|
220
|
-
const lines = fileContent.split("\n");
|
|
221
|
-
|
|
222
|
-
for (const line of lines) {
|
|
223
|
-
if (insideComment && line.includes("*/")) {
|
|
224
|
-
insideComment = false;
|
|
225
|
-
continue;
|
|
226
|
-
} else if (!insideComment && line.includes("/*") && line.includes("*/")) {
|
|
227
|
-
continue;
|
|
228
|
-
} else if (!insideComment && line.includes("/*")) {
|
|
229
|
-
insideComment = true;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (insideComment) {
|
|
233
|
-
continue;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (!moduleLines.length) {
|
|
237
|
-
const isModuleDeclaration = (_a = line.match(/^\s*declare module.+$/)) == null ? void 0 : _a.length;
|
|
238
|
-
const moduleIndex = line.indexOf("declare module");
|
|
239
|
-
const isModuleStart = isModuleDeclaration && moduleIndex > -1;
|
|
240
|
-
|
|
241
|
-
if (isModuleStart) {
|
|
242
|
-
moduleIndentLevel = moduleIndex;
|
|
243
|
-
moduleLines = [line];
|
|
244
|
-
}
|
|
245
|
-
} else {
|
|
246
|
-
moduleLines.push(line);
|
|
247
|
-
const blockEndIndex = line.indexOf("}");
|
|
248
|
-
|
|
249
|
-
if (blockEndIndex === moduleIndentLevel) {
|
|
250
|
-
moduleBlocks.push(moduleLines.map(l => l.substring(moduleIndentLevel, l.length)).join("\n"));
|
|
251
|
-
moduleLines = [];
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
return moduleBlocks;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
123
|
class _DtsError extends Error {
|
|
260
124
|
constructor(message, messages) {
|
|
261
125
|
super(message);
|
|
262
126
|
this.messages = messages;
|
|
263
127
|
}
|
|
264
|
-
|
|
265
128
|
}
|
|
266
|
-
|
|
267
129
|
function _createApiExtractorConfig(options) {
|
|
268
130
|
const {
|
|
269
131
|
distPath,
|
|
@@ -298,16 +160,13 @@ function _createApiExtractorConfig(options) {
|
|
|
298
160
|
projectFolder
|
|
299
161
|
};
|
|
300
162
|
}
|
|
301
|
-
|
|
302
163
|
async function _createTSDocConfig(opts) {
|
|
303
164
|
const {
|
|
304
165
|
customTags
|
|
305
166
|
} = opts;
|
|
306
|
-
|
|
307
167
|
if (customTags.length === 0) {
|
|
308
168
|
return void 0;
|
|
309
169
|
}
|
|
310
|
-
|
|
311
170
|
const tsDocBaseBuf = await fs.readFile(require.resolve("@microsoft/api-extractor/extends/tsdoc-base.json"));
|
|
312
171
|
const tsDocBaseConfig = jsoncParser.parse(tsDocBaseBuf.toString());
|
|
313
172
|
const tagDefinitions = (tsDocBaseConfig.tagDefinitions || []).concat(customTags.map(t => ({
|
|
@@ -315,37 +174,52 @@ async function _createTSDocConfig(opts) {
|
|
|
315
174
|
syntaxKind: t.syntaxKind,
|
|
316
175
|
allowMultiple: t.allowMultiple
|
|
317
176
|
})));
|
|
318
|
-
|
|
319
177
|
const supportForTags = _objectSpread({}, tsDocBaseConfig.supportForTags);
|
|
320
|
-
|
|
321
178
|
for (const customTag of customTags) {
|
|
322
179
|
supportForTags["@".concat(customTag.name)] = true;
|
|
323
180
|
}
|
|
324
|
-
|
|
325
181
|
return tsdocConfig.TSDocConfigFile.loadFromObject(_objectSpread(_objectSpread({}, tsDocBaseConfig), {}, {
|
|
326
182
|
noStandardTags: false,
|
|
327
183
|
tagDefinitions,
|
|
328
184
|
supportForTags
|
|
329
185
|
}));
|
|
330
186
|
}
|
|
331
|
-
|
|
187
|
+
async function _extractModuleBlocksFromTypes(_ref) {
|
|
188
|
+
let {
|
|
189
|
+
tsOutDir,
|
|
190
|
+
extractResult
|
|
191
|
+
} = _ref;
|
|
192
|
+
const program = extractResult.compilerState.program;
|
|
193
|
+
const moduleBlocks = [];
|
|
194
|
+
const allProgramFiles = [...program.getSourceFiles()];
|
|
195
|
+
const sourceFiles = allProgramFiles.filter(sourceFile => sourceFile.fileName.includes(tsOutDir));
|
|
196
|
+
for (const sourceFile of sourceFiles) {
|
|
197
|
+
if (sourceFile.text.includes("declare module")) {
|
|
198
|
+
moduleBlocks.push(..._extractModuleBlocks(sourceFile.text));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return moduleBlocks;
|
|
202
|
+
}
|
|
203
|
+
function _extractModuleBlocks(fileContent) {
|
|
204
|
+
const ast = recast.parse(fileContent, {
|
|
205
|
+
parser: typeScriptParser__default["default"]
|
|
206
|
+
});
|
|
207
|
+
return ast.program.body.filter(node => node.type === "TSModuleDeclaration").map(node => recast.print(node).code);
|
|
208
|
+
}
|
|
332
209
|
const _LOG_LEVELS = {
|
|
333
210
|
error: "error",
|
|
334
211
|
info: "info",
|
|
335
212
|
off: "none",
|
|
336
213
|
warn: "warning"
|
|
337
214
|
};
|
|
338
|
-
|
|
339
215
|
function _getExtractMessagesConfig(options) {
|
|
340
216
|
const {
|
|
341
217
|
rules
|
|
342
218
|
} = options;
|
|
343
|
-
|
|
344
219
|
function _ruleToLogLevel(key, defaultLevel) {
|
|
345
220
|
const r = rules == null ? void 0 : rules[key];
|
|
346
221
|
return r ? _LOG_LEVELS[r] : defaultLevel || "warning";
|
|
347
222
|
}
|
|
348
|
-
|
|
349
223
|
return {
|
|
350
224
|
compilerMessageReporting: {
|
|
351
225
|
default: {
|
|
@@ -398,7 +272,6 @@ function _getExtractMessagesConfig(options) {
|
|
|
398
272
|
}
|
|
399
273
|
};
|
|
400
274
|
}
|
|
401
|
-
|
|
402
275
|
async function _extractTypes(options) {
|
|
403
276
|
const {
|
|
404
277
|
customTags,
|
|
@@ -409,6 +282,7 @@ async function _extractTypes(options) {
|
|
|
409
282
|
projectPath,
|
|
410
283
|
rules,
|
|
411
284
|
sourceTypesPath,
|
|
285
|
+
tmpPath,
|
|
412
286
|
tsconfigPath
|
|
413
287
|
} = options;
|
|
414
288
|
const tsdocConfigFile = await _createTSDocConfig({
|
|
@@ -434,18 +308,21 @@ async function _extractTypes(options) {
|
|
|
434
308
|
const extractorResult = apiExtractor.Extractor.invoke(extractorConfig, {
|
|
435
309
|
localBuild: true,
|
|
436
310
|
showVerboseMessages: true,
|
|
437
|
-
|
|
438
311
|
messageCallback(message) {
|
|
439
312
|
messages.push(message);
|
|
440
313
|
message.handled = true;
|
|
441
314
|
}
|
|
442
|
-
|
|
443
315
|
});
|
|
444
316
|
const typesPath = path__default["default"].resolve(distPath, filePath);
|
|
445
317
|
const typesBuf = await fs__default["default"].readFile(typesPath);
|
|
446
318
|
const prettierConfig = await prettier__default["default"].resolveConfig(typesPath);
|
|
447
319
|
await mkdirp__default["default"](path__default["default"].dirname(typesPath));
|
|
448
|
-
|
|
320
|
+
const moduleBlocks = await _extractModuleBlocksFromTypes({
|
|
321
|
+
extractResult: extractorResult,
|
|
322
|
+
tsOutDir: tmpPath
|
|
323
|
+
});
|
|
324
|
+
const code = [typesBuf.toString(), ...moduleBlocks].join("\n\n");
|
|
325
|
+
await fs__default["default"].writeFile(typesPath, prettier__default["default"].format(code, _objectSpread(_objectSpread({}, prettierConfig), {}, {
|
|
449
326
|
filepath: typesPath
|
|
450
327
|
})));
|
|
451
328
|
files.push({
|
|
@@ -457,12 +334,9 @@ async function _extractTypes(options) {
|
|
|
457
334
|
messages
|
|
458
335
|
};
|
|
459
336
|
}
|
|
460
|
-
|
|
461
337
|
const rimraf = util.promisify(rimrafCallback__default["default"]);
|
|
462
|
-
|
|
463
338
|
async function _doExtract(ctx, task) {
|
|
464
339
|
var _a, _b;
|
|
465
|
-
|
|
466
340
|
const {
|
|
467
341
|
config,
|
|
468
342
|
cwd,
|
|
@@ -470,7 +344,6 @@ async function _doExtract(ctx, task) {
|
|
|
470
344
|
strict,
|
|
471
345
|
ts
|
|
472
346
|
} = ctx;
|
|
473
|
-
|
|
474
347
|
if (!ts.config || !ts.configPath) {
|
|
475
348
|
return {
|
|
476
349
|
type: "dts",
|
|
@@ -478,16 +351,13 @@ async function _doExtract(ctx, task) {
|
|
|
478
351
|
results: []
|
|
479
352
|
};
|
|
480
353
|
}
|
|
481
|
-
|
|
482
354
|
const {
|
|
483
355
|
outDir,
|
|
484
356
|
rootDir = cwd
|
|
485
357
|
} = ts.config.options;
|
|
486
|
-
|
|
487
358
|
if (!outDir) {
|
|
488
359
|
throw new Error("tsconfig.json is missing `compilerOptions.outDir`");
|
|
489
360
|
}
|
|
490
|
-
|
|
491
361
|
const tmpPath = path__default["default"].resolve(outDir, "__tmp__");
|
|
492
362
|
await _buildTypes({
|
|
493
363
|
cwd,
|
|
@@ -497,7 +367,6 @@ async function _doExtract(ctx, task) {
|
|
|
497
367
|
});
|
|
498
368
|
const messages = [];
|
|
499
369
|
const results = [];
|
|
500
|
-
|
|
501
370
|
for (const entry of task.entries) {
|
|
502
371
|
const exportPath = entry.exportPath === "." ? "./index" : entry.exportPath;
|
|
503
372
|
const sourceTypesPath = path__default["default"].resolve(tmpPath, path__default["default"].relative(rootDir, path__default["default"].resolve(cwd, entry.sourcePath)).replace(/\.ts$/, ".d.ts"));
|
|
@@ -506,33 +375,26 @@ async function _doExtract(ctx, task) {
|
|
|
506
375
|
const result = await _extractTypes({
|
|
507
376
|
customTags: (_a = config == null ? void 0 : config.extract) == null ? void 0 : _a.customTags,
|
|
508
377
|
cwd,
|
|
378
|
+
distPath: outDir,
|
|
509
379
|
exportPath,
|
|
510
380
|
files,
|
|
511
381
|
filePath,
|
|
512
382
|
projectPath: cwd,
|
|
513
383
|
rules: (_b = config == null ? void 0 : config.extract) == null ? void 0 : _b.rules,
|
|
514
384
|
sourceTypesPath,
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
});
|
|
518
|
-
await _appendModuleBlocks({
|
|
519
|
-
tsOutDir: tmpPath,
|
|
520
|
-
extractResult: result.extractorResult,
|
|
521
|
-
extractTypesOutFile: path__default["default"].resolve(outDir, targetPath)
|
|
385
|
+
tmpPath,
|
|
386
|
+
tsconfigPath: path__default["default"].resolve(cwd, ts.configPath || "tsconfig.json")
|
|
522
387
|
});
|
|
523
388
|
messages.push(...result.messages);
|
|
524
|
-
|
|
525
389
|
if (result.messages.some(msg => msg.logLevel === "error")) {
|
|
526
390
|
await rimraf(tmpPath);
|
|
527
391
|
throw new _DtsError("encountered errors when extracting types", result.messages);
|
|
528
392
|
}
|
|
529
|
-
|
|
530
393
|
results.push({
|
|
531
394
|
sourcePath: path__default["default"].resolve(cwd, entry.sourcePath),
|
|
532
395
|
filePath: targetPath
|
|
533
396
|
});
|
|
534
397
|
}
|
|
535
|
-
|
|
536
398
|
await rimraf(tmpPath);
|
|
537
399
|
return {
|
|
538
400
|
type: "dts",
|
|
@@ -540,7 +402,6 @@ async function _doExtract(ctx, task) {
|
|
|
540
402
|
results
|
|
541
403
|
};
|
|
542
404
|
}
|
|
543
|
-
|
|
544
405
|
const _dtsTask = {
|
|
545
406
|
name: (_ctx, task) => ["build type definitions", ...task.entries.map(entry => " ".concat(chalk__default["default"].blue(entry.importId), ": ").concat(entry.sourcePath, " -> ").concat(entry.targetPath))].join("\n"),
|
|
546
407
|
exec: (ctx, task) => {
|
|
@@ -560,7 +421,6 @@ const _dtsTask = {
|
|
|
560
421
|
const {
|
|
561
422
|
logger
|
|
562
423
|
} = ctx;
|
|
563
|
-
|
|
564
424
|
if (err instanceof _DtsError) {
|
|
565
425
|
_printExtractMessages(ctx, err.messages);
|
|
566
426
|
} else if (err instanceof Error) {
|
|
@@ -582,9 +442,7 @@ const _dtsWatchTask = {
|
|
|
582
442
|
const {
|
|
583
443
|
logger
|
|
584
444
|
} = ctx;
|
|
585
|
-
|
|
586
445
|
_printExtractMessages(ctx, result.messages);
|
|
587
|
-
|
|
588
446
|
logger.warn("watching typescript definitions is currently not supported");
|
|
589
447
|
logger.log();
|
|
590
448
|
},
|
|
@@ -592,7 +450,6 @@ const _dtsWatchTask = {
|
|
|
592
450
|
const {
|
|
593
451
|
logger
|
|
594
452
|
} = ctx;
|
|
595
|
-
|
|
596
453
|
if (err instanceof _DtsError) {
|
|
597
454
|
_printExtractMessages(ctx, err.messages);
|
|
598
455
|
} else if (err instanceof Error) {
|
|
@@ -600,12 +457,9 @@ const _dtsWatchTask = {
|
|
|
600
457
|
}
|
|
601
458
|
}
|
|
602
459
|
};
|
|
603
|
-
|
|
604
460
|
function _resolveRollupConfig(ctx, buildTask) {
|
|
605
|
-
var
|
|
606
|
-
|
|
461
|
+
var _ref2, _ref5, _ref6, _ref7, _ref8, _ref9;
|
|
607
462
|
var _a, _b, _c;
|
|
608
|
-
|
|
609
463
|
const {
|
|
610
464
|
format,
|
|
611
465
|
runtime,
|
|
@@ -622,13 +476,11 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
622
476
|
ts
|
|
623
477
|
} = ctx;
|
|
624
478
|
const outputExt = _resolveBuildContext._MODULE_EXT[pkg.type][format];
|
|
625
|
-
const minify = (
|
|
479
|
+
const minify = (_ref2 = config == null ? void 0 : config.minify) !== null && _ref2 !== void 0 ? _ref2 : true;
|
|
626
480
|
const outDir = path__default["default"].relative(cwd, distPath);
|
|
627
|
-
const pathAliases = Object.fromEntries(Object.entries(((_a = ts.config) == null ? void 0 : _a.options.paths) || {}).map(
|
|
628
|
-
let [key, val] =
|
|
629
|
-
|
|
481
|
+
const pathAliases = Object.fromEntries(Object.entries(((_a = ts.config) == null ? void 0 : _a.options.paths) || {}).map(_ref3 => {
|
|
482
|
+
let [key, val] = _ref3;
|
|
630
483
|
var _a2;
|
|
631
|
-
|
|
632
484
|
return [key, path__default["default"].resolve(cwd, ((_a2 = ts.config) == null ? void 0 : _a2.options.baseUrl) || ".", val[0])];
|
|
633
485
|
}));
|
|
634
486
|
const entries = buildTask.entries.map(entry => {
|
|
@@ -636,13 +488,10 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
636
488
|
name: path__default["default"].relative(outDir, entry.output).replace(/\.[^/.]+$/, "")
|
|
637
489
|
});
|
|
638
490
|
}, {});
|
|
639
|
-
|
|
640
491
|
const exportIds = _exports && Object.keys(_exports).map(exportPath => path__default["default"].join(pkg.name, exportPath));
|
|
641
|
-
|
|
642
492
|
const sourcePaths = _exports && Object.values(_exports).map(e => path__default["default"].resolve(cwd, e.source));
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
let [key, val] = _ref5;
|
|
493
|
+
const replacements = Object.fromEntries(Object.entries((config == null ? void 0 : config.define) || {}).map(_ref4 => {
|
|
494
|
+
let [key, val] = _ref4;
|
|
646
495
|
return [key, JSON.stringify(val)];
|
|
647
496
|
}));
|
|
648
497
|
const defaultPlugins = [replace__default["default"]({
|
|
@@ -651,12 +500,10 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
651
500
|
"process.env.PKG_FILE_PATH": arg => {
|
|
652
501
|
const sourcePath = "./" + path__default["default"].relative(cwd, arg);
|
|
653
502
|
const entry = entries.find(e => e.source === sourcePath);
|
|
654
|
-
|
|
655
503
|
if (!entry) {
|
|
656
504
|
console.error("could not find source entry: ".concat(sourcePath));
|
|
657
505
|
return "null";
|
|
658
506
|
}
|
|
659
|
-
|
|
660
507
|
return JSON.stringify(path__default["default"].relative(cwd, path__default["default"].resolve(outDir, entry.name + outputExt)));
|
|
661
508
|
},
|
|
662
509
|
"process.env.PKG_FORMAT": JSON.stringify(format),
|
|
@@ -673,10 +520,10 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
673
520
|
esmExternals: false,
|
|
674
521
|
extensions: [".js"]
|
|
675
522
|
}), json__default["default"](), esbuild__default["default"]({
|
|
676
|
-
jsx: (
|
|
677
|
-
jsxFactory: (
|
|
678
|
-
jsxFragment: (
|
|
679
|
-
jsxImportSource: (
|
|
523
|
+
jsx: (_ref5 = config == null ? void 0 : config.jsx) !== null && _ref5 !== void 0 ? _ref5 : "automatic",
|
|
524
|
+
jsxFactory: (_ref6 = config == null ? void 0 : config.jsxFactory) !== null && _ref6 !== void 0 ? _ref6 : "createElement",
|
|
525
|
+
jsxFragment: (_ref7 = config == null ? void 0 : config.jsxFragment) !== null && _ref7 !== void 0 ? _ref7 : "Fragment",
|
|
526
|
+
jsxImportSource: (_ref8 = config == null ? void 0 : config.jsxImportSource) !== null && _ref8 !== void 0 ? _ref8 : "react",
|
|
680
527
|
target,
|
|
681
528
|
tsconfig: ctx.ts.configPath || "tsconfig.json"
|
|
682
529
|
}), pluginBabel.getBabelOutputPlugin({
|
|
@@ -690,11 +537,9 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
690
537
|
comments: (_node, comment) => {
|
|
691
538
|
const text = comment.value;
|
|
692
539
|
const type = comment.type;
|
|
693
|
-
|
|
694
540
|
if (type == "comment2") {
|
|
695
541
|
return /@preserve|@license|@cc_on/i.test(text);
|
|
696
542
|
}
|
|
697
|
-
|
|
698
543
|
return false;
|
|
699
544
|
}
|
|
700
545
|
}
|
|
@@ -708,23 +553,18 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
708
553
|
if (exportIds == null ? void 0 : exportIds.includes(id)) {
|
|
709
554
|
return true;
|
|
710
555
|
}
|
|
711
|
-
|
|
712
556
|
if (importer && (id.startsWith(".") || id.startsWith("/"))) {
|
|
713
557
|
const idPath = path__default["default"].resolve(path__default["default"].dirname(importer), id);
|
|
714
|
-
|
|
715
558
|
if (sourcePaths == null ? void 0 : sourcePaths.includes(idPath)) {
|
|
716
559
|
logger.warn("detected self-referencing import \u2013 treating as external: ".concat(path__default["default"].relative(cwd, idPath)));
|
|
717
560
|
return true;
|
|
718
561
|
}
|
|
719
562
|
}
|
|
720
|
-
|
|
721
563
|
const idParts = id.split("/");
|
|
722
564
|
const name = idParts[0].startsWith("@") ? "".concat(idParts[0], "/").concat(idParts[1]) : idParts[0];
|
|
723
|
-
|
|
724
565
|
if (name && external.includes(name)) {
|
|
725
566
|
return true;
|
|
726
567
|
}
|
|
727
|
-
|
|
728
568
|
return false;
|
|
729
569
|
},
|
|
730
570
|
input: entries.reduce((acc, entry) => {
|
|
@@ -732,13 +572,11 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
732
572
|
[entry.name]: entry.source
|
|
733
573
|
});
|
|
734
574
|
}, {}),
|
|
735
|
-
|
|
736
575
|
onwarn(warning, rollupWarn) {
|
|
737
576
|
if (!warning.code || !["CIRCULAR_DEPENDENCY"].includes(warning.code)) {
|
|
738
577
|
rollupWarn(warning);
|
|
739
578
|
}
|
|
740
579
|
},
|
|
741
|
-
|
|
742
580
|
plugins,
|
|
743
581
|
treeshake: {
|
|
744
582
|
propertyReadSideEffects: false
|
|
@@ -750,11 +588,10 @@ function _resolveRollupConfig(ctx, buildTask) {
|
|
|
750
588
|
entryFileNames: () => outputExt === ".esm.js" ? "[name].js" : "[name]".concat(outputExt),
|
|
751
589
|
format,
|
|
752
590
|
exports: "auto",
|
|
753
|
-
sourcemap: (
|
|
591
|
+
sourcemap: (_ref9 = config == null ? void 0 : config.sourcemap) !== null && _ref9 !== void 0 ? _ref9 : true
|
|
754
592
|
}
|
|
755
593
|
};
|
|
756
594
|
}
|
|
757
|
-
|
|
758
595
|
const _rollupTask = {
|
|
759
596
|
name: (ctx, task) => "build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk__default["default"].blue(path__default["default"].join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")),
|
|
760
597
|
exec: (ctx, task) => {
|
|
@@ -772,24 +609,20 @@ const _rollupTask = {
|
|
|
772
609
|
}
|
|
773
610
|
}
|
|
774
611
|
};
|
|
775
|
-
|
|
776
612
|
async function _execPromise(ctx, task) {
|
|
777
613
|
const {
|
|
778
614
|
files,
|
|
779
615
|
distPath
|
|
780
616
|
} = ctx;
|
|
781
617
|
const outDir = path__default["default"].relative(ctx.cwd, distPath);
|
|
782
|
-
|
|
783
618
|
const {
|
|
784
619
|
inputOptions,
|
|
785
620
|
outputOptions
|
|
786
621
|
} = _resolveRollupConfig(ctx, task);
|
|
787
|
-
|
|
788
622
|
const bundle = await rollup.rollup(inputOptions);
|
|
789
623
|
const {
|
|
790
624
|
output
|
|
791
625
|
} = await bundle.generate(outputOptions);
|
|
792
|
-
|
|
793
626
|
for (const chunkOrAsset of output) {
|
|
794
627
|
if (chunkOrAsset.type === "asset") {
|
|
795
628
|
files.push({
|
|
@@ -803,11 +636,9 @@ async function _execPromise(ctx, task) {
|
|
|
803
636
|
});
|
|
804
637
|
}
|
|
805
638
|
}
|
|
806
|
-
|
|
807
639
|
await bundle.write(outputOptions);
|
|
808
640
|
await bundle.close();
|
|
809
641
|
}
|
|
810
|
-
|
|
811
642
|
const _rollupWatchTask = {
|
|
812
643
|
name: (ctx, task) => "build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk__default["default"].blue(path__default["default"].join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")),
|
|
813
644
|
exec: (ctx, task) => {
|
|
@@ -815,12 +646,10 @@ const _rollupWatchTask = {
|
|
|
815
646
|
inputOptions,
|
|
816
647
|
outputOptions
|
|
817
648
|
} = _resolveRollupConfig(ctx, task);
|
|
818
|
-
|
|
819
649
|
return new rxjs.Observable(observer => {
|
|
820
650
|
const watchOptions = _objectSpread(_objectSpread({}, inputOptions), {}, {
|
|
821
651
|
output: outputOptions
|
|
822
652
|
});
|
|
823
|
-
|
|
824
653
|
const watcher = rollup.watch(watchOptions);
|
|
825
654
|
watcher.on("event", event => {
|
|
826
655
|
observer.next(event);
|
|
@@ -834,26 +663,21 @@ const _rollupWatchTask = {
|
|
|
834
663
|
const {
|
|
835
664
|
logger
|
|
836
665
|
} = ctx;
|
|
837
|
-
|
|
838
666
|
if (event.code === "BUNDLE_END") {
|
|
839
667
|
logger.success("build javascript files (target ".concat(task.target.join(" + "), ", format ").concat(task.format, ")\n ").concat(task.entries.map(e => "".concat(chalk__default["default"].blue(path__default["default"].join(ctx.pkg.name, e.path)), ": ").concat(e.source, " -> ").concat(e.output)).join("\n ")));
|
|
840
668
|
logger.log("");
|
|
841
669
|
return;
|
|
842
670
|
}
|
|
843
|
-
|
|
844
671
|
if (event.code === "BUNDLE_START") {
|
|
845
672
|
return;
|
|
846
673
|
}
|
|
847
|
-
|
|
848
674
|
if (event.code === "END") {
|
|
849
675
|
return;
|
|
850
676
|
}
|
|
851
|
-
|
|
852
677
|
if (event.code === "ERROR") {
|
|
853
678
|
logger.error(event.code, event);
|
|
854
679
|
return;
|
|
855
680
|
}
|
|
856
|
-
|
|
857
681
|
if (event.code === "START") {
|
|
858
682
|
return;
|
|
859
683
|
}
|
|
@@ -862,7 +686,6 @@ const _rollupWatchTask = {
|
|
|
862
686
|
const {
|
|
863
687
|
logger
|
|
864
688
|
} = ctx;
|
|
865
|
-
|
|
866
689
|
if (err instanceof Error) {
|
|
867
690
|
logger.log(err);
|
|
868
691
|
}
|
|
@@ -883,4 +706,4 @@ exports._getExtractMessagesConfig = _getExtractMessagesConfig;
|
|
|
883
706
|
exports._rollupTask = _rollupTask;
|
|
884
707
|
exports._rollupWatchTask = _rollupWatchTask;
|
|
885
708
|
exports._watchTaskHandlers = _watchTaskHandlers;
|
|
886
|
-
//# sourceMappingURL=index-
|
|
709
|
+
//# sourceMappingURL=index-7a851efa.js.map
|