@sanity/pkg-utils 1.12.0 → 1.14.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/{build-8b5bd627.js → build-83c36253.js} +2 -2
- package/dist/_chunks/build-83c36253.js.map +1 -0
- package/dist/_chunks/{buildAction-87c64945.js → buildAction-19b87a46.js} +4 -6
- package/dist/_chunks/{buildAction-87c64945.js.map → buildAction-19b87a46.js.map} +1 -1
- package/dist/_chunks/index-33f2afe8.js +789 -0
- package/dist/_chunks/index-33f2afe8.js.map +1 -0
- package/dist/_chunks/{watch-ccb7daf2.js → watch-12e6eafa.js} +2 -2
- package/dist/_chunks/watch-12e6eafa.js.map +1 -0
- package/dist/_chunks/{watchAction-b7c1e241.js → watchAction-d4ae9e80.js} +4 -6
- package/dist/_chunks/{watchAction-b7c1e241.js.map → watchAction-d4ae9e80.js.map} +1 -1
- package/dist/cli.js +3 -3
- package/dist/index.d.ts +45 -1
- package/dist/index.esm.js +121 -3565
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +5 -6
- package/dist/index.js.map +1 -1
- package/package.json +6 -4
- package/src/node/_core/config/types.ts +22 -0
- package/src/node/_resolveBuildTasks.ts +1 -1
- package/src/node/_resolveWatchTasks.ts +1 -1
- package/src/node/_tasks/dts/_doExtract.ts +1 -0
- package/src/node/_tasks/dts/_extractTypes.ts +16 -85
- package/src/node/_tasks/dts/_getExtractMessagesConfig.ts +87 -0
- package/src/node/_tasks/dts/index.ts +1 -0
- package/src/node/_tasks/rollup/_resolveRollupConfig.ts +8 -1
- package/src/node/build.ts +19 -1
- package/dist/_chunks/build-8b5bd627.js.map +0 -1
- package/dist/_chunks/index-4a1fe6d6.js +0 -4239
- package/dist/_chunks/index-4a1fe6d6.js.map +0 -1
- package/dist/_chunks/watch-ccb7daf2.js.map +0 -1
|
@@ -0,0 +1,789 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
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
|
+
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
|
+
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
|
+
var chalk = require('chalk');
|
|
10
|
+
|
|
11
|
+
var rxjs = require('rxjs');
|
|
12
|
+
|
|
13
|
+
var path = require('path');
|
|
14
|
+
|
|
15
|
+
var util = require('util');
|
|
16
|
+
|
|
17
|
+
var rimrafCallback = require('rimraf');
|
|
18
|
+
|
|
19
|
+
var ts = require('typescript');
|
|
20
|
+
|
|
21
|
+
var fs = require('fs/promises');
|
|
22
|
+
|
|
23
|
+
var apiExtractor = require('@microsoft/api-extractor');
|
|
24
|
+
|
|
25
|
+
var mkdirp = require('mkdirp');
|
|
26
|
+
|
|
27
|
+
var prettier = require('prettier');
|
|
28
|
+
|
|
29
|
+
var tsdocConfig = require('@microsoft/tsdoc-config');
|
|
30
|
+
|
|
31
|
+
var jsoncParser = require('jsonc-parser');
|
|
32
|
+
|
|
33
|
+
var rollup = require('rollup');
|
|
34
|
+
|
|
35
|
+
var alias = require('@rollup/plugin-alias');
|
|
36
|
+
|
|
37
|
+
var pluginBabel = require('@rollup/plugin-babel');
|
|
38
|
+
|
|
39
|
+
var commonjs = require('@rollup/plugin-commonjs');
|
|
40
|
+
|
|
41
|
+
var json = require('@rollup/plugin-json');
|
|
42
|
+
|
|
43
|
+
var pluginNodeResolve = require('@rollup/plugin-node-resolve');
|
|
44
|
+
|
|
45
|
+
var replace = require('@rollup/plugin-replace');
|
|
46
|
+
|
|
47
|
+
var esbuild = require('rollup-plugin-esbuild');
|
|
48
|
+
|
|
49
|
+
var rollupPluginTerser = require('rollup-plugin-terser');
|
|
50
|
+
|
|
51
|
+
var _resolveBuildContext = require('./_resolveBuildContext-ef196a3e.js');
|
|
52
|
+
|
|
53
|
+
require('esbuild-register/dist/node');
|
|
54
|
+
|
|
55
|
+
require('pkg-up');
|
|
56
|
+
|
|
57
|
+
require('find-config');
|
|
58
|
+
|
|
59
|
+
require('zod');
|
|
60
|
+
|
|
61
|
+
function _interopDefaultLegacy(e) {
|
|
62
|
+
return e && typeof e === 'object' && 'default' in e ? e : {
|
|
63
|
+
'default': e
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
|
|
68
|
+
|
|
69
|
+
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
70
|
+
|
|
71
|
+
var rimrafCallback__default = /*#__PURE__*/_interopDefaultLegacy(rimrafCallback);
|
|
72
|
+
|
|
73
|
+
var ts__default = /*#__PURE__*/_interopDefaultLegacy(ts);
|
|
74
|
+
|
|
75
|
+
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
76
|
+
|
|
77
|
+
var mkdirp__default = /*#__PURE__*/_interopDefaultLegacy(mkdirp);
|
|
78
|
+
|
|
79
|
+
var prettier__default = /*#__PURE__*/_interopDefaultLegacy(prettier);
|
|
80
|
+
|
|
81
|
+
var alias__default = /*#__PURE__*/_interopDefaultLegacy(alias);
|
|
82
|
+
|
|
83
|
+
var commonjs__default = /*#__PURE__*/_interopDefaultLegacy(commonjs);
|
|
84
|
+
|
|
85
|
+
var json__default = /*#__PURE__*/_interopDefaultLegacy(json);
|
|
86
|
+
|
|
87
|
+
var replace__default = /*#__PURE__*/_interopDefaultLegacy(replace);
|
|
88
|
+
|
|
89
|
+
var esbuild__default = /*#__PURE__*/_interopDefaultLegacy(esbuild);
|
|
90
|
+
|
|
91
|
+
function _printExtractMessages(ctx, messages) {
|
|
92
|
+
const {
|
|
93
|
+
cwd,
|
|
94
|
+
logger
|
|
95
|
+
} = ctx;
|
|
96
|
+
const warnings = messages.filter(msg => msg.logLevel === "warning");
|
|
97
|
+
|
|
98
|
+
if (warnings.length) {
|
|
99
|
+
logger.log();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
for (const msg of warnings) {
|
|
103
|
+
const sourceFilePath = msg.sourceFilePath && path__default["default"].relative(cwd, msg.sourceFilePath);
|
|
104
|
+
|
|
105
|
+
if (msg.messageId === "TS6307") {
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
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
|
+
}
|
|
111
|
+
|
|
112
|
+
const errors = messages.filter(msg => msg.logLevel === "error");
|
|
113
|
+
|
|
114
|
+
if (!warnings.length && errors.length) {
|
|
115
|
+
logger.log("");
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
for (const msg of errors) {
|
|
119
|
+
const sourceFilePath = msg.sourceFilePath && path__default["default"].relative(cwd, msg.sourceFilePath);
|
|
120
|
+
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
|
+
}
|
|
122
|
+
|
|
123
|
+
if (errors.length) {
|
|
124
|
+
process.exit(1);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const formatHost = {
|
|
129
|
+
getCurrentDirectory: () => ts__default["default"].sys.getCurrentDirectory(),
|
|
130
|
+
getNewLine: () => ts__default["default"].sys.newLine,
|
|
131
|
+
getCanonicalFileName: ts__default["default"].sys.useCaseSensitiveFileNames ? f => f : f => f.toLowerCase()
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
async function _buildTypes(options) {
|
|
135
|
+
const {
|
|
136
|
+
outDir,
|
|
137
|
+
tsconfig
|
|
138
|
+
} = options;
|
|
139
|
+
|
|
140
|
+
const compilerOptions = _objectSpread(_objectSpread({}, tsconfig.options), {}, {
|
|
141
|
+
declaration: true,
|
|
142
|
+
declarationDir: outDir,
|
|
143
|
+
emitDeclarationOnly: true,
|
|
144
|
+
noEmit: false,
|
|
145
|
+
outDir
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
const program = ts__default["default"].createProgram(tsconfig.fileNames, compilerOptions);
|
|
149
|
+
const emitResult = program.emit();
|
|
150
|
+
const allDiagnostics = ts__default["default"].getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
151
|
+
allDiagnostics.forEach(diagnostic => {
|
|
152
|
+
if (diagnostic.file && diagnostic.start) {
|
|
153
|
+
const {
|
|
154
|
+
line,
|
|
155
|
+
character
|
|
156
|
+
} = ts__default["default"].getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
|
|
157
|
+
const message = ts__default["default"].flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
158
|
+
console.log("".concat(diagnostic.file.fileName, " ").concat(line + 1, ":").concat(character + 1, "\n").concat(message));
|
|
159
|
+
} else {
|
|
160
|
+
console.log(ts__default["default"].flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
if (emitResult.emitSkipped) {
|
|
165
|
+
const errors = allDiagnostics.filter(diag => diag.category === ts__default["default"].DiagnosticCategory.Error);
|
|
166
|
+
|
|
167
|
+
if (errors.length) {
|
|
168
|
+
console.error(ts__default["default"].formatDiagnostics(errors, formatHost));
|
|
169
|
+
throw new Error("failed to compile");
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
class _DtsError extends Error {
|
|
175
|
+
constructor(message, messages) {
|
|
176
|
+
super(message);
|
|
177
|
+
this.messages = messages;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function _createApiExtractorConfig(options) {
|
|
183
|
+
const {
|
|
184
|
+
distPath,
|
|
185
|
+
exportPath,
|
|
186
|
+
filePath,
|
|
187
|
+
messages,
|
|
188
|
+
projectFolder,
|
|
189
|
+
mainEntryPointFilePath,
|
|
190
|
+
tsconfigPath
|
|
191
|
+
} = options;
|
|
192
|
+
return {
|
|
193
|
+
apiReport: {
|
|
194
|
+
enabled: false,
|
|
195
|
+
reportFileName: "<unscopedPackageName>.api.md"
|
|
196
|
+
},
|
|
197
|
+
compiler: {
|
|
198
|
+
tsconfigFilePath: tsconfigPath
|
|
199
|
+
},
|
|
200
|
+
docModel: {
|
|
201
|
+
enabled: false,
|
|
202
|
+
apiJsonFilePath: path__default["default"].resolve(distPath, "".concat(exportPath, ".api.json"))
|
|
203
|
+
},
|
|
204
|
+
dtsRollup: {
|
|
205
|
+
enabled: true,
|
|
206
|
+
untrimmedFilePath: path__default["default"].resolve(distPath, filePath)
|
|
207
|
+
},
|
|
208
|
+
tsdocMetadata: {
|
|
209
|
+
enabled: false
|
|
210
|
+
},
|
|
211
|
+
messages,
|
|
212
|
+
mainEntryPointFilePath,
|
|
213
|
+
projectFolder
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
async function _createTSDocConfig(opts) {
|
|
218
|
+
const {
|
|
219
|
+
customTags
|
|
220
|
+
} = opts;
|
|
221
|
+
|
|
222
|
+
if (customTags.length === 0) {
|
|
223
|
+
return void 0;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const tsDocBaseBuf = await fs.readFile(require.resolve("@microsoft/api-extractor/extends/tsdoc-base.json"));
|
|
227
|
+
const tsDocBaseConfig = jsoncParser.parse(tsDocBaseBuf.toString());
|
|
228
|
+
const tagDefinitions = (tsDocBaseConfig.tagDefinitions || []).concat(customTags.map(t => ({
|
|
229
|
+
tagName: "@".concat(t.name),
|
|
230
|
+
syntaxKind: t.syntaxKind,
|
|
231
|
+
allowMultiple: t.allowMultiple
|
|
232
|
+
})));
|
|
233
|
+
|
|
234
|
+
const supportForTags = _objectSpread({}, tsDocBaseConfig.supportForTags);
|
|
235
|
+
|
|
236
|
+
for (const customTag of customTags) {
|
|
237
|
+
supportForTags["@".concat(customTag.name)] = true;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return tsdocConfig.TSDocConfigFile.loadFromObject(_objectSpread(_objectSpread({}, tsDocBaseConfig), {}, {
|
|
241
|
+
noStandardTags: false,
|
|
242
|
+
tagDefinitions,
|
|
243
|
+
supportForTags
|
|
244
|
+
}));
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const _LOG_LEVELS = {
|
|
248
|
+
error: "error",
|
|
249
|
+
info: "info",
|
|
250
|
+
off: "none",
|
|
251
|
+
warn: "warning"
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
function _getExtractMessagesConfig(options) {
|
|
255
|
+
const {
|
|
256
|
+
rules
|
|
257
|
+
} = options;
|
|
258
|
+
|
|
259
|
+
function _ruleToLogLevel(key, defaultLevel) {
|
|
260
|
+
const r = rules == null ? void 0 : rules[key];
|
|
261
|
+
return r ? _LOG_LEVELS[r] : defaultLevel || "warning";
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return {
|
|
265
|
+
compilerMessageReporting: {
|
|
266
|
+
default: {
|
|
267
|
+
logLevel: "warning"
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
extractorMessageReporting: {
|
|
271
|
+
default: {
|
|
272
|
+
logLevel: "warning",
|
|
273
|
+
addToApiReportFile: false
|
|
274
|
+
},
|
|
275
|
+
"ae-forgotten-export": {
|
|
276
|
+
logLevel: _ruleToLogLevel("ae-forgotten-export", "error"),
|
|
277
|
+
addToApiReportFile: false
|
|
278
|
+
},
|
|
279
|
+
"ae-incompatible-release-tags": {
|
|
280
|
+
logLevel: _ruleToLogLevel("ae-incompatible-release-tags", "error"),
|
|
281
|
+
addToApiReportFile: false
|
|
282
|
+
},
|
|
283
|
+
"ae-internal-missing-underscore": {
|
|
284
|
+
logLevel: _ruleToLogLevel("ae-internal-missing-underscore"),
|
|
285
|
+
addToApiReportFile: false
|
|
286
|
+
},
|
|
287
|
+
"ae-missing-release-tag": {
|
|
288
|
+
logLevel: _ruleToLogLevel("ae-missing-release-tag", "error"),
|
|
289
|
+
addToApiReportFile: false
|
|
290
|
+
},
|
|
291
|
+
"ae-wrong-input-file-type": {
|
|
292
|
+
logLevel: "none",
|
|
293
|
+
addToApiReportFile: false
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
tsdocMessageReporting: {
|
|
297
|
+
default: {
|
|
298
|
+
logLevel: "warning",
|
|
299
|
+
addToApiReportFile: false
|
|
300
|
+
},
|
|
301
|
+
"tsdoc-link-tag-unescaped-text": {
|
|
302
|
+
logLevel: _ruleToLogLevel("tsdoc-link-tag-unescaped-text", "warning"),
|
|
303
|
+
addToApiReportFile: false
|
|
304
|
+
},
|
|
305
|
+
"tsdoc-undefined-tag": {
|
|
306
|
+
logLevel: _ruleToLogLevel("tsdoc-undefined-tag", "error"),
|
|
307
|
+
addToApiReportFile: false
|
|
308
|
+
},
|
|
309
|
+
"tsdoc-unsupported-tag": {
|
|
310
|
+
logLevel: _ruleToLogLevel("tsdoc-unsupported-tag", "none"),
|
|
311
|
+
addToApiReportFile: false
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
async function _extractTypes(options) {
|
|
318
|
+
const {
|
|
319
|
+
customTags,
|
|
320
|
+
distPath,
|
|
321
|
+
exportPath,
|
|
322
|
+
files,
|
|
323
|
+
filePath,
|
|
324
|
+
projectPath,
|
|
325
|
+
rules,
|
|
326
|
+
sourceTypesPath,
|
|
327
|
+
tsconfigPath
|
|
328
|
+
} = options;
|
|
329
|
+
const tsdocConfigFile = await _createTSDocConfig({
|
|
330
|
+
customTags: customTags || []
|
|
331
|
+
});
|
|
332
|
+
const extractorConfig = apiExtractor.ExtractorConfig.prepare({
|
|
333
|
+
configObject: _createApiExtractorConfig({
|
|
334
|
+
distPath,
|
|
335
|
+
exportPath,
|
|
336
|
+
filePath,
|
|
337
|
+
messages: _getExtractMessagesConfig({
|
|
338
|
+
rules
|
|
339
|
+
}),
|
|
340
|
+
projectFolder: projectPath,
|
|
341
|
+
mainEntryPointFilePath: sourceTypesPath,
|
|
342
|
+
tsconfigPath
|
|
343
|
+
}),
|
|
344
|
+
configObjectFullPath: void 0,
|
|
345
|
+
tsdocConfigFile,
|
|
346
|
+
packageJsonFullPath: path__default["default"].resolve(projectPath, "package.json")
|
|
347
|
+
});
|
|
348
|
+
const messages = [];
|
|
349
|
+
const extractorResult = apiExtractor.Extractor.invoke(extractorConfig, {
|
|
350
|
+
localBuild: true,
|
|
351
|
+
showVerboseMessages: true,
|
|
352
|
+
|
|
353
|
+
messageCallback(message) {
|
|
354
|
+
messages.push(message);
|
|
355
|
+
message.handled = true;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
});
|
|
359
|
+
const typesPath = path__default["default"].resolve(distPath, filePath);
|
|
360
|
+
const typesBuf = await fs__default["default"].readFile(typesPath);
|
|
361
|
+
const prettierConfig = await prettier__default["default"].resolveConfig(typesPath);
|
|
362
|
+
await mkdirp__default["default"](path__default["default"].dirname(typesPath));
|
|
363
|
+
await fs__default["default"].writeFile(typesPath, prettier__default["default"].format(typesBuf.toString(), _objectSpread(_objectSpread({}, prettierConfig), {}, {
|
|
364
|
+
filepath: typesPath
|
|
365
|
+
})));
|
|
366
|
+
files.push({
|
|
367
|
+
type: "types",
|
|
368
|
+
path: typesPath
|
|
369
|
+
});
|
|
370
|
+
return {
|
|
371
|
+
extractorResult,
|
|
372
|
+
messages
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const rimraf = util.promisify(rimrafCallback__default["default"]);
|
|
377
|
+
|
|
378
|
+
async function _doExtract(ctx, task) {
|
|
379
|
+
var _a, _b;
|
|
380
|
+
|
|
381
|
+
const {
|
|
382
|
+
config,
|
|
383
|
+
cwd,
|
|
384
|
+
files,
|
|
385
|
+
ts
|
|
386
|
+
} = ctx;
|
|
387
|
+
|
|
388
|
+
if (!ts.config || !ts.configPath) {
|
|
389
|
+
return {
|
|
390
|
+
type: "dts",
|
|
391
|
+
messages: [],
|
|
392
|
+
results: []
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
const {
|
|
397
|
+
outDir,
|
|
398
|
+
rootDir = cwd
|
|
399
|
+
} = ts.config.options;
|
|
400
|
+
|
|
401
|
+
if (!outDir) {
|
|
402
|
+
throw new Error("tsconfig.json is missing `compilerOptions.outDir`");
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
const tmpPath = path__default["default"].resolve(outDir, "__tmp__");
|
|
406
|
+
await _buildTypes({
|
|
407
|
+
cwd,
|
|
408
|
+
outDir: tmpPath,
|
|
409
|
+
tsconfig: ts.config
|
|
410
|
+
});
|
|
411
|
+
const messages = [];
|
|
412
|
+
const results = [];
|
|
413
|
+
|
|
414
|
+
for (const entry of task.entries) {
|
|
415
|
+
const exportPath = entry.exportPath === "." ? "./index" : entry.exportPath;
|
|
416
|
+
const sourceTypesPath = path__default["default"].resolve(tmpPath, path__default["default"].relative(rootDir, path__default["default"].resolve(cwd, entry.sourcePath)).replace(/\.ts$/, ".d.ts"));
|
|
417
|
+
const targetPath = path__default["default"].resolve(cwd, entry.targetPath);
|
|
418
|
+
const result = await _extractTypes({
|
|
419
|
+
customTags: (_a = config == null ? void 0 : config.extract) == null ? void 0 : _a.customTags,
|
|
420
|
+
cwd,
|
|
421
|
+
exportPath,
|
|
422
|
+
files,
|
|
423
|
+
filePath: path__default["default"].relative(outDir, targetPath),
|
|
424
|
+
projectPath: cwd,
|
|
425
|
+
rules: (_b = config == null ? void 0 : config.extract) == null ? void 0 : _b.rules,
|
|
426
|
+
sourceTypesPath,
|
|
427
|
+
tsconfigPath: path__default["default"].resolve(cwd, ts.configPath || "tsconfig.json"),
|
|
428
|
+
distPath: outDir
|
|
429
|
+
});
|
|
430
|
+
messages.push(...result.messages);
|
|
431
|
+
|
|
432
|
+
if (result.messages.some(msg => msg.logLevel === "error")) {
|
|
433
|
+
await rimraf(tmpPath);
|
|
434
|
+
throw new _DtsError("encountered errors when extracting types", result.messages);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
results.push({
|
|
438
|
+
sourcePath: path__default["default"].resolve(cwd, entry.sourcePath),
|
|
439
|
+
filePath: targetPath
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
await rimraf(tmpPath);
|
|
444
|
+
return {
|
|
445
|
+
type: "dts",
|
|
446
|
+
messages,
|
|
447
|
+
results
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
const _dtsTask = {
|
|
452
|
+
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"),
|
|
453
|
+
exec: (ctx, task) => {
|
|
454
|
+
return new rxjs.Observable(observer => {
|
|
455
|
+
_doExtract(ctx, task).then(result => {
|
|
456
|
+
observer.next(result);
|
|
457
|
+
observer.complete();
|
|
458
|
+
}).catch(err => {
|
|
459
|
+
observer.error(err);
|
|
460
|
+
});
|
|
461
|
+
});
|
|
462
|
+
},
|
|
463
|
+
complete: (ctx, _task, result) => {
|
|
464
|
+
_printExtractMessages(ctx, result.messages);
|
|
465
|
+
},
|
|
466
|
+
error: (ctx, _task, err) => {
|
|
467
|
+
const {
|
|
468
|
+
logger
|
|
469
|
+
} = ctx;
|
|
470
|
+
|
|
471
|
+
if (err instanceof _DtsError) {
|
|
472
|
+
_printExtractMessages(ctx, err.messages);
|
|
473
|
+
} else if (err instanceof Error) {
|
|
474
|
+
logger.error(err);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
const _dtsWatchTask = {
|
|
479
|
+
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"),
|
|
480
|
+
exec: (ctx, task) => {
|
|
481
|
+
return new rxjs.Observable(observer => {
|
|
482
|
+
_doExtract(ctx, task).then(result => {
|
|
483
|
+
observer.next(result);
|
|
484
|
+
observer.complete();
|
|
485
|
+
}).catch(err => observer.error(err));
|
|
486
|
+
});
|
|
487
|
+
},
|
|
488
|
+
complete: (ctx, _task, result) => {
|
|
489
|
+
const {
|
|
490
|
+
logger
|
|
491
|
+
} = ctx;
|
|
492
|
+
|
|
493
|
+
_printExtractMessages(ctx, result.messages);
|
|
494
|
+
|
|
495
|
+
logger.warn("watching typescript definitions is currently not supported");
|
|
496
|
+
logger.log();
|
|
497
|
+
},
|
|
498
|
+
error: (ctx, _task, err) => {
|
|
499
|
+
const {
|
|
500
|
+
logger
|
|
501
|
+
} = ctx;
|
|
502
|
+
|
|
503
|
+
if (err instanceof _DtsError) {
|
|
504
|
+
_printExtractMessages(ctx, err.messages);
|
|
505
|
+
} else if (err instanceof Error) {
|
|
506
|
+
logger.error(err);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
function _resolveRollupConfig(ctx, buildTask) {
|
|
512
|
+
var _ref, _ref4, _ref5, _ref6, _ref7, _ref8;
|
|
513
|
+
|
|
514
|
+
var _a, _b;
|
|
515
|
+
|
|
516
|
+
const {
|
|
517
|
+
format,
|
|
518
|
+
runtime,
|
|
519
|
+
target
|
|
520
|
+
} = buildTask;
|
|
521
|
+
const {
|
|
522
|
+
config,
|
|
523
|
+
cwd,
|
|
524
|
+
exports: _exports,
|
|
525
|
+
external,
|
|
526
|
+
distPath,
|
|
527
|
+
logger,
|
|
528
|
+
pkg,
|
|
529
|
+
ts
|
|
530
|
+
} = ctx;
|
|
531
|
+
const outputExt = _resolveBuildContext._MODULE_EXT[pkg.type][format];
|
|
532
|
+
const minify = (_ref = config == null ? void 0 : config.minify) !== null && _ref !== void 0 ? _ref : true;
|
|
533
|
+
const outDir = path__default["default"].relative(cwd, distPath);
|
|
534
|
+
const pathAliases = Object.fromEntries(Object.entries(((_a = ts.config) == null ? void 0 : _a.options.paths) || {}).map(_ref2 => {
|
|
535
|
+
let [key, val] = _ref2;
|
|
536
|
+
|
|
537
|
+
var _a2;
|
|
538
|
+
|
|
539
|
+
return [key, path__default["default"].resolve(cwd, ((_a2 = ts.config) == null ? void 0 : _a2.options.baseUrl) || ".", val[0])];
|
|
540
|
+
}));
|
|
541
|
+
const entries = buildTask.entries.map(entry => {
|
|
542
|
+
return _objectSpread(_objectSpread({}, entry), {}, {
|
|
543
|
+
name: path__default["default"].relative(outDir, entry.output).replace(/\.[^/.]+$/, "")
|
|
544
|
+
});
|
|
545
|
+
}, {});
|
|
546
|
+
|
|
547
|
+
const exportIds = _exports && Object.keys(_exports).map(exportPath => path__default["default"].join(pkg.name, exportPath));
|
|
548
|
+
|
|
549
|
+
const sourcePaths = _exports && Object.values(_exports).map(e => path__default["default"].resolve(cwd, e.source));
|
|
550
|
+
|
|
551
|
+
const replacements = Object.fromEntries(Object.entries((config == null ? void 0 : config.define) || {}).map(_ref3 => {
|
|
552
|
+
let [key, val] = _ref3;
|
|
553
|
+
return [key, JSON.stringify(val)];
|
|
554
|
+
}));
|
|
555
|
+
return {
|
|
556
|
+
inputOptions: {
|
|
557
|
+
context: cwd,
|
|
558
|
+
external: (id, importer) => {
|
|
559
|
+
if (exportIds == null ? void 0 : exportIds.includes(id)) {
|
|
560
|
+
return true;
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
if (importer && (id.startsWith(".") || id.startsWith("/"))) {
|
|
564
|
+
const idPath = path__default["default"].resolve(path__default["default"].dirname(importer), id);
|
|
565
|
+
|
|
566
|
+
if (sourcePaths == null ? void 0 : sourcePaths.includes(idPath)) {
|
|
567
|
+
logger.warn("detected self-referencing import \u2013 treating as external: ".concat(path__default["default"].relative(cwd, idPath)));
|
|
568
|
+
return true;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
const idParts = id.split("/");
|
|
573
|
+
const name = idParts[0].startsWith("@") ? "".concat(idParts[0], "/").concat(idParts[1]) : idParts[0];
|
|
574
|
+
|
|
575
|
+
if (name && external.includes(name)) {
|
|
576
|
+
return true;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
return false;
|
|
580
|
+
},
|
|
581
|
+
input: entries.reduce((acc, entry) => {
|
|
582
|
+
return _objectSpread(_objectSpread({}, acc), {}, {
|
|
583
|
+
[entry.name]: entry.source
|
|
584
|
+
});
|
|
585
|
+
}, {}),
|
|
586
|
+
|
|
587
|
+
onwarn(warning, rollupWarn) {
|
|
588
|
+
if (!warning.code || !["CIRCULAR_DEPENDENCY"].includes(warning.code)) {
|
|
589
|
+
rollupWarn(warning);
|
|
590
|
+
}
|
|
591
|
+
},
|
|
592
|
+
|
|
593
|
+
plugins: [replace__default["default"]({
|
|
594
|
+
preventAssignment: true,
|
|
595
|
+
values: _objectSpread({}, pkg.name === "@sanity/pkg-utils" ? _objectSpread({}, replacements) : _objectSpread({
|
|
596
|
+
"process.env.PKG_FILE_PATH": arg => {
|
|
597
|
+
const sourcePath = "./" + path__default["default"].relative(cwd, arg);
|
|
598
|
+
const entry = entries.find(e => e.source === sourcePath);
|
|
599
|
+
|
|
600
|
+
if (!entry) {
|
|
601
|
+
throw new Error("could not find source entry: ".concat(sourcePath));
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
return JSON.stringify(path__default["default"].relative(cwd, path__default["default"].resolve(outDir, entry.name + outputExt)));
|
|
605
|
+
},
|
|
606
|
+
"process.env.PKG_FORMAT": JSON.stringify(format),
|
|
607
|
+
"process.env.PKG_RUNTIME": JSON.stringify(runtime),
|
|
608
|
+
"process.env.PKG_VERSION": JSON.stringify(process.env.PKG_VERSION || pkg.version)
|
|
609
|
+
}, replacements))
|
|
610
|
+
}), alias__default["default"]({
|
|
611
|
+
entries: _objectSpread({}, pathAliases)
|
|
612
|
+
}), pluginNodeResolve.nodeResolve({
|
|
613
|
+
browser: runtime === "browser",
|
|
614
|
+
extensions: [".cjs", ".mjs", ".js", ".jsx", ".json", ".node"],
|
|
615
|
+
preferBuiltins: true
|
|
616
|
+
}), commonjs__default["default"]({
|
|
617
|
+
esmExternals: false,
|
|
618
|
+
extensions: [".js"]
|
|
619
|
+
}), json__default["default"](), esbuild__default["default"]({
|
|
620
|
+
jsx: (_ref4 = config == null ? void 0 : config.jsx) !== null && _ref4 !== void 0 ? _ref4 : "automatic",
|
|
621
|
+
jsxFactory: (_ref5 = config == null ? void 0 : config.jsxFactory) !== null && _ref5 !== void 0 ? _ref5 : "createElement",
|
|
622
|
+
jsxFragment: (_ref6 = config == null ? void 0 : config.jsxFragment) !== null && _ref6 !== void 0 ? _ref6 : "Fragment",
|
|
623
|
+
jsxImportSource: (_ref7 = config == null ? void 0 : config.jsxImportSource) !== null && _ref7 !== void 0 ? _ref7 : "react",
|
|
624
|
+
target,
|
|
625
|
+
tsconfig: ctx.ts.configPath || "tsconfig.json"
|
|
626
|
+
}), pluginBabel.getBabelOutputPlugin({
|
|
627
|
+
babelrc: false,
|
|
628
|
+
plugins: ["@babel/plugin-proposal-object-rest-spread"],
|
|
629
|
+
presets: [["@babel/preset-env", {
|
|
630
|
+
targets: pkg.browserslist || _resolveBuildContext._DEFAULTS.browserslist
|
|
631
|
+
}]]
|
|
632
|
+
}), minify && rollupPluginTerser.terser({
|
|
633
|
+
output: {
|
|
634
|
+
comments: (_node, comment) => {
|
|
635
|
+
const text = comment.value;
|
|
636
|
+
const type = comment.type;
|
|
637
|
+
|
|
638
|
+
if (type == "comment2") {
|
|
639
|
+
return /@preserve|@license|@cc_on/i.test(text);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
return false;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}), ...(((_b = config == null ? void 0 : config.rollup) == null ? void 0 : _b.plugins) || [])].filter(Boolean),
|
|
646
|
+
treeshake: {
|
|
647
|
+
propertyReadSideEffects: false
|
|
648
|
+
}
|
|
649
|
+
},
|
|
650
|
+
outputOptions: {
|
|
651
|
+
chunkFileNames: () => "_chunks/[name]-[hash]".concat(outputExt),
|
|
652
|
+
dir: outDir,
|
|
653
|
+
entryFileNames: () => outputExt === ".esm.js" ? "[name].js" : "[name]".concat(outputExt),
|
|
654
|
+
format,
|
|
655
|
+
exports: "auto",
|
|
656
|
+
sourcemap: (_ref8 = config == null ? void 0 : config.sourcemap) !== null && _ref8 !== void 0 ? _ref8 : true
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
const _rollupTask = {
|
|
662
|
+
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 ")),
|
|
663
|
+
exec: (ctx, task) => {
|
|
664
|
+
return new rxjs.Observable(observer => {
|
|
665
|
+
_execPromise(ctx, task).then(result => {
|
|
666
|
+
observer.next(result);
|
|
667
|
+
observer.complete();
|
|
668
|
+
}).catch(err => observer.error(err));
|
|
669
|
+
});
|
|
670
|
+
},
|
|
671
|
+
complete: () => {},
|
|
672
|
+
error: (_ctx, _task, err) => {
|
|
673
|
+
if (err instanceof Error) {
|
|
674
|
+
console.log(err);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
|
|
679
|
+
async function _execPromise(ctx, task) {
|
|
680
|
+
const {
|
|
681
|
+
files,
|
|
682
|
+
distPath
|
|
683
|
+
} = ctx;
|
|
684
|
+
const outDir = path__default["default"].relative(ctx.cwd, distPath);
|
|
685
|
+
|
|
686
|
+
const {
|
|
687
|
+
inputOptions,
|
|
688
|
+
outputOptions
|
|
689
|
+
} = _resolveRollupConfig(ctx, task);
|
|
690
|
+
|
|
691
|
+
const bundle = await rollup.rollup(inputOptions);
|
|
692
|
+
const {
|
|
693
|
+
output
|
|
694
|
+
} = await bundle.generate(outputOptions);
|
|
695
|
+
|
|
696
|
+
for (const chunkOrAsset of output) {
|
|
697
|
+
if (chunkOrAsset.type === "asset") {
|
|
698
|
+
files.push({
|
|
699
|
+
type: "asset",
|
|
700
|
+
path: path__default["default"].resolve(outDir, chunkOrAsset.fileName)
|
|
701
|
+
});
|
|
702
|
+
} else {
|
|
703
|
+
files.push({
|
|
704
|
+
type: "chunk",
|
|
705
|
+
path: path__default["default"].resolve(outDir, chunkOrAsset.fileName)
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
await bundle.write(outputOptions);
|
|
711
|
+
await bundle.close();
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
const _rollupWatchTask = {
|
|
715
|
+
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 ")),
|
|
716
|
+
exec: (ctx, task) => {
|
|
717
|
+
const {
|
|
718
|
+
inputOptions,
|
|
719
|
+
outputOptions
|
|
720
|
+
} = _resolveRollupConfig(ctx, task);
|
|
721
|
+
|
|
722
|
+
return new rxjs.Observable(observer => {
|
|
723
|
+
const watchOptions = _objectSpread(_objectSpread({}, inputOptions), {}, {
|
|
724
|
+
output: outputOptions
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
const watcher = rollup.watch(watchOptions);
|
|
728
|
+
watcher.on("event", event => {
|
|
729
|
+
observer.next(event);
|
|
730
|
+
});
|
|
731
|
+
return () => {
|
|
732
|
+
watcher.close();
|
|
733
|
+
};
|
|
734
|
+
});
|
|
735
|
+
},
|
|
736
|
+
complete: (ctx, task, event) => {
|
|
737
|
+
const {
|
|
738
|
+
logger
|
|
739
|
+
} = ctx;
|
|
740
|
+
|
|
741
|
+
if (event.code === "BUNDLE_END") {
|
|
742
|
+
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 ")));
|
|
743
|
+
logger.log("");
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
if (event.code === "BUNDLE_START") {
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
if (event.code === "END") {
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
if (event.code === "ERROR") {
|
|
756
|
+
logger.error(event.code, event);
|
|
757
|
+
return;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
if (event.code === "START") {
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
},
|
|
764
|
+
error: (ctx, _task, err) => {
|
|
765
|
+
const {
|
|
766
|
+
logger
|
|
767
|
+
} = ctx;
|
|
768
|
+
|
|
769
|
+
if (err instanceof Error) {
|
|
770
|
+
logger.log(err);
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
const _buildTaskHandlers = {
|
|
775
|
+
"build:dts": _dtsTask,
|
|
776
|
+
"build:js": _rollupTask
|
|
777
|
+
};
|
|
778
|
+
const _watchTaskHandlers = {
|
|
779
|
+
"watch:dts": _dtsWatchTask,
|
|
780
|
+
"watch:js": _rollupWatchTask
|
|
781
|
+
};
|
|
782
|
+
exports._buildTaskHandlers = _buildTaskHandlers;
|
|
783
|
+
exports._dtsTask = _dtsTask;
|
|
784
|
+
exports._dtsWatchTask = _dtsWatchTask;
|
|
785
|
+
exports._getExtractMessagesConfig = _getExtractMessagesConfig;
|
|
786
|
+
exports._rollupTask = _rollupTask;
|
|
787
|
+
exports._rollupWatchTask = _rollupWatchTask;
|
|
788
|
+
exports._watchTaskHandlers = _watchTaskHandlers;
|
|
789
|
+
//# sourceMappingURL=index-33f2afe8.js.map
|