@sanity/pkg-utils 1.12.0 → 1.13.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.
@@ -0,0 +1,774 @@
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
+ async function _extractTypes(options) {
255
+ const {
256
+ distPath,
257
+ exportPath,
258
+ files,
259
+ filePath,
260
+ projectPath,
261
+ rules,
262
+ sourceTypesPath,
263
+ tsconfigPath
264
+ } = options;
265
+ const tsdocConfigFile = await _createTSDocConfig({
266
+ customTags: []
267
+ });
268
+
269
+ function _ruleToLogLevel(key, defaultLevel) {
270
+ const r = rules == null ? void 0 : rules[key];
271
+ return r ? _LOG_LEVELS[r] : defaultLevel || "warning";
272
+ }
273
+
274
+ const messagesConfig = {
275
+ compilerMessageReporting: {
276
+ default: {
277
+ logLevel: "warning"
278
+ }
279
+ },
280
+ extractorMessageReporting: {
281
+ default: {
282
+ logLevel: "warning",
283
+ addToApiReportFile: false
284
+ },
285
+ "ae-forgotten-export": {
286
+ logLevel: _ruleToLogLevel("ae-forgotten-export", "error"),
287
+ addToApiReportFile: false
288
+ },
289
+ "ae-incompatible-release-tags": {
290
+ logLevel: _ruleToLogLevel("ae-incompatible-release-tags", "error"),
291
+ addToApiReportFile: false
292
+ },
293
+ "ae-internal-missing-underscore": {
294
+ logLevel: _ruleToLogLevel("ae-internal-missing-underscore"),
295
+ addToApiReportFile: false
296
+ },
297
+ "ae-missing-release-tag": {
298
+ logLevel: _ruleToLogLevel("ae-missing-release-tag", "error"),
299
+ addToApiReportFile: false
300
+ },
301
+ "ae-wrong-input-file-type": {
302
+ logLevel: "none",
303
+ addToApiReportFile: false
304
+ }
305
+ },
306
+ tsdocMessageReporting: {
307
+ default: {
308
+ logLevel: "warning",
309
+ addToApiReportFile: false
310
+ },
311
+ "tsdoc-link-tag-unescaped-text": {
312
+ logLevel: _ruleToLogLevel("tsdoc-link-tag-unescaped-text", "warning"),
313
+ addToApiReportFile: false
314
+ },
315
+ "tsdoc-undefined-tag": {
316
+ logLevel: _ruleToLogLevel("tsdoc-undefined-tag", "error"),
317
+ addToApiReportFile: false
318
+ },
319
+ "tsdoc-unsupported-tag": {
320
+ logLevel: _ruleToLogLevel("tsdoc-unsupported-tag", "none"),
321
+ addToApiReportFile: false
322
+ }
323
+ }
324
+ };
325
+ const extractorConfig = apiExtractor.ExtractorConfig.prepare({
326
+ configObject: _createApiExtractorConfig({
327
+ distPath,
328
+ exportPath,
329
+ filePath,
330
+ messages: messagesConfig,
331
+ projectFolder: projectPath,
332
+ mainEntryPointFilePath: sourceTypesPath,
333
+ tsconfigPath
334
+ }),
335
+ configObjectFullPath: void 0,
336
+ tsdocConfigFile,
337
+ packageJsonFullPath: path__default["default"].resolve(projectPath, "package.json")
338
+ });
339
+ const messages = [];
340
+ const extractorResult = apiExtractor.Extractor.invoke(extractorConfig, {
341
+ localBuild: true,
342
+ showVerboseMessages: true,
343
+
344
+ messageCallback(message) {
345
+ messages.push(message);
346
+ message.handled = true;
347
+ }
348
+
349
+ });
350
+ const typesPath = path__default["default"].resolve(distPath, filePath);
351
+ const typesBuf = await fs__default["default"].readFile(typesPath);
352
+ const prettierConfig = await prettier__default["default"].resolveConfig(typesPath);
353
+ await mkdirp__default["default"](path__default["default"].dirname(typesPath));
354
+ await fs__default["default"].writeFile(typesPath, prettier__default["default"].format(typesBuf.toString(), _objectSpread(_objectSpread({}, prettierConfig), {}, {
355
+ filepath: typesPath
356
+ })));
357
+ files.push({
358
+ type: "types",
359
+ path: typesPath
360
+ });
361
+ return {
362
+ extractorResult,
363
+ messages
364
+ };
365
+ }
366
+
367
+ const rimraf = util.promisify(rimrafCallback__default["default"]);
368
+
369
+ async function _doExtract(ctx, task) {
370
+ var _a;
371
+
372
+ const {
373
+ config,
374
+ cwd,
375
+ files,
376
+ ts
377
+ } = ctx;
378
+
379
+ if (!ts.config || !ts.configPath) {
380
+ return {
381
+ type: "dts",
382
+ messages: [],
383
+ results: []
384
+ };
385
+ }
386
+
387
+ const {
388
+ outDir,
389
+ rootDir = cwd
390
+ } = ts.config.options;
391
+
392
+ if (!outDir) {
393
+ throw new Error("tsconfig.json is missing `compilerOptions.outDir`");
394
+ }
395
+
396
+ const tmpPath = path__default["default"].resolve(outDir, "__tmp__");
397
+ await _buildTypes({
398
+ cwd,
399
+ outDir: tmpPath,
400
+ tsconfig: ts.config
401
+ });
402
+ const messages = [];
403
+ const results = [];
404
+
405
+ for (const entry of task.entries) {
406
+ const exportPath = entry.exportPath === "." ? "./index" : entry.exportPath;
407
+ const sourceTypesPath = path__default["default"].resolve(tmpPath, path__default["default"].relative(rootDir, path__default["default"].resolve(cwd, entry.sourcePath)).replace(/\.ts$/, ".d.ts"));
408
+ const targetPath = path__default["default"].resolve(cwd, entry.targetPath);
409
+ const result = await _extractTypes({
410
+ cwd,
411
+ exportPath,
412
+ files,
413
+ filePath: path__default["default"].relative(outDir, targetPath),
414
+ projectPath: cwd,
415
+ rules: (_a = config == null ? void 0 : config.extract) == null ? void 0 : _a.rules,
416
+ sourceTypesPath,
417
+ tsconfigPath: path__default["default"].resolve(cwd, ts.configPath || "tsconfig.json"),
418
+ distPath: outDir
419
+ });
420
+ messages.push(...result.messages);
421
+
422
+ if (result.messages.some(msg => msg.logLevel === "error")) {
423
+ await rimraf(tmpPath);
424
+ throw new _DtsError("encountered errors when extracting types", result.messages);
425
+ }
426
+
427
+ results.push({
428
+ sourcePath: path__default["default"].resolve(cwd, entry.sourcePath),
429
+ filePath: targetPath
430
+ });
431
+ }
432
+
433
+ await rimraf(tmpPath);
434
+ return {
435
+ type: "dts",
436
+ messages,
437
+ results
438
+ };
439
+ }
440
+
441
+ const _dtsTask = {
442
+ 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"),
443
+ exec: (ctx, task) => {
444
+ return new rxjs.Observable(observer => {
445
+ _doExtract(ctx, task).then(result => {
446
+ observer.next(result);
447
+ observer.complete();
448
+ }).catch(err => {
449
+ observer.error(err);
450
+ });
451
+ });
452
+ },
453
+ complete: (ctx, _task, result) => {
454
+ _printExtractMessages(ctx, result.messages);
455
+ },
456
+ error: (ctx, _task, err) => {
457
+ const {
458
+ logger
459
+ } = ctx;
460
+
461
+ if (err instanceof _DtsError) {
462
+ _printExtractMessages(ctx, err.messages);
463
+ } else if (err instanceof Error) {
464
+ logger.error(err);
465
+ }
466
+ }
467
+ };
468
+ const _dtsWatchTask = {
469
+ 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"),
470
+ exec: (ctx, task) => {
471
+ return new rxjs.Observable(observer => {
472
+ _doExtract(ctx, task).then(result => {
473
+ observer.next(result);
474
+ observer.complete();
475
+ }).catch(err => observer.error(err));
476
+ });
477
+ },
478
+ complete: (ctx, _task, result) => {
479
+ const {
480
+ logger
481
+ } = ctx;
482
+
483
+ _printExtractMessages(ctx, result.messages);
484
+
485
+ logger.warn("watching typescript definitions is currently not supported");
486
+ logger.log();
487
+ },
488
+ error: (ctx, _task, err) => {
489
+ const {
490
+ logger
491
+ } = ctx;
492
+
493
+ if (err instanceof _DtsError) {
494
+ _printExtractMessages(ctx, err.messages);
495
+ } else if (err instanceof Error) {
496
+ logger.error(err);
497
+ }
498
+ }
499
+ };
500
+
501
+ function _resolveRollupConfig(ctx, buildTask) {
502
+ var _ref, _ref3, _ref4, _ref5, _ref6, _ref7;
503
+
504
+ var _a, _b;
505
+
506
+ const {
507
+ format,
508
+ runtime,
509
+ target
510
+ } = buildTask;
511
+ const {
512
+ config,
513
+ cwd,
514
+ exports: _exports,
515
+ external,
516
+ distPath,
517
+ logger,
518
+ pkg,
519
+ ts
520
+ } = ctx;
521
+ const outputExt = _resolveBuildContext._MODULE_EXT[pkg.type][format];
522
+ const minify = (_ref = config == null ? void 0 : config.minify) !== null && _ref !== void 0 ? _ref : true;
523
+ const outDir = path__default["default"].relative(cwd, distPath);
524
+ const pathAliases = Object.fromEntries(Object.entries(((_a = ts.config) == null ? void 0 : _a.options.paths) || {}).map(_ref2 => {
525
+ let [key, val] = _ref2;
526
+
527
+ var _a2;
528
+
529
+ return [key, path__default["default"].resolve(cwd, ((_a2 = ts.config) == null ? void 0 : _a2.options.baseUrl) || ".", val[0])];
530
+ }));
531
+ const entries = buildTask.entries.map(entry => {
532
+ return _objectSpread(_objectSpread({}, entry), {}, {
533
+ name: path__default["default"].relative(outDir, entry.output).replace(/\.[^/.]+$/, "")
534
+ });
535
+ }, {});
536
+
537
+ const exportIds = _exports && Object.keys(_exports).map(exportPath => path__default["default"].join(pkg.name, exportPath));
538
+
539
+ const sourcePaths = _exports && Object.values(_exports).map(e => path__default["default"].resolve(cwd, e.source));
540
+
541
+ return {
542
+ inputOptions: {
543
+ context: cwd,
544
+ external: (id, importer) => {
545
+ if (exportIds == null ? void 0 : exportIds.includes(id)) {
546
+ return true;
547
+ }
548
+
549
+ if (importer && (id.startsWith(".") || id.startsWith("/"))) {
550
+ const idPath = path__default["default"].resolve(path__default["default"].dirname(importer), id);
551
+
552
+ if (sourcePaths == null ? void 0 : sourcePaths.includes(idPath)) {
553
+ logger.warn("detected self-referencing import \u2013 treating as external: ".concat(path__default["default"].relative(cwd, idPath)));
554
+ return true;
555
+ }
556
+ }
557
+
558
+ const idParts = id.split("/");
559
+ const name = idParts[0].startsWith("@") ? "".concat(idParts[0], "/").concat(idParts[1]) : idParts[0];
560
+
561
+ if (name && external.includes(name)) {
562
+ return true;
563
+ }
564
+
565
+ return false;
566
+ },
567
+ input: entries.reduce((acc, entry) => {
568
+ return _objectSpread(_objectSpread({}, acc), {}, {
569
+ [entry.name]: entry.source
570
+ });
571
+ }, {}),
572
+
573
+ onwarn(warning, rollupWarn) {
574
+ if (!warning.code || !["CIRCULAR_DEPENDENCY"].includes(warning.code)) {
575
+ rollupWarn(warning);
576
+ }
577
+ },
578
+
579
+ plugins: [replace__default["default"]({
580
+ preventAssignment: true,
581
+ values: _objectSpread({}, pkg.name === "@sanity/pkg-utils" ? {} : {
582
+ "process.env.PKG_FILE_PATH": arg => {
583
+ const sourcePath = "./" + path__default["default"].relative(cwd, arg);
584
+ const entry = entries.find(e => e.source === sourcePath);
585
+
586
+ if (!entry) {
587
+ throw new Error("could not find source entry: ".concat(sourcePath));
588
+ }
589
+
590
+ return JSON.stringify(path__default["default"].relative(cwd, path__default["default"].resolve(outDir, entry.name + outputExt)));
591
+ },
592
+ "process.env.PKG_FORMAT": JSON.stringify(format),
593
+ "process.env.PKG_RUNTIME": JSON.stringify(runtime),
594
+ "process.env.PKG_VERSION": JSON.stringify(process.env.PKG_VERSION || pkg.version)
595
+ })
596
+ }), alias__default["default"]({
597
+ entries: _objectSpread({}, pathAliases)
598
+ }), pluginNodeResolve.nodeResolve({
599
+ browser: runtime === "browser",
600
+ extensions: [".cjs", ".mjs", ".js", ".jsx", ".json", ".node"],
601
+ preferBuiltins: true
602
+ }), commonjs__default["default"]({
603
+ esmExternals: false,
604
+ extensions: [".js"]
605
+ }), json__default["default"](), esbuild__default["default"]({
606
+ jsx: (_ref3 = config == null ? void 0 : config.jsx) !== null && _ref3 !== void 0 ? _ref3 : "automatic",
607
+ jsxFactory: (_ref4 = config == null ? void 0 : config.jsxFactory) !== null && _ref4 !== void 0 ? _ref4 : "createElement",
608
+ jsxFragment: (_ref5 = config == null ? void 0 : config.jsxFragment) !== null && _ref5 !== void 0 ? _ref5 : "Fragment",
609
+ jsxImportSource: (_ref6 = config == null ? void 0 : config.jsxImportSource) !== null && _ref6 !== void 0 ? _ref6 : "react",
610
+ target,
611
+ tsconfig: ctx.ts.configPath || "tsconfig.json"
612
+ }), pluginBabel.getBabelOutputPlugin({
613
+ babelrc: false,
614
+ plugins: ["@babel/plugin-proposal-object-rest-spread"],
615
+ presets: [["@babel/preset-env", {
616
+ targets: pkg.browserslist || _resolveBuildContext._DEFAULTS.browserslist
617
+ }]]
618
+ }), minify && rollupPluginTerser.terser({
619
+ output: {
620
+ comments: (_node, comment) => {
621
+ const text = comment.value;
622
+ const type = comment.type;
623
+
624
+ if (type == "comment2") {
625
+ return /@preserve|@license|@cc_on/i.test(text);
626
+ }
627
+
628
+ return false;
629
+ }
630
+ }
631
+ }), ...(((_b = config == null ? void 0 : config.rollup) == null ? void 0 : _b.plugins) || [])].filter(Boolean),
632
+ treeshake: {
633
+ propertyReadSideEffects: false
634
+ }
635
+ },
636
+ outputOptions: {
637
+ chunkFileNames: () => "_chunks/[name]-[hash]".concat(outputExt),
638
+ dir: outDir,
639
+ entryFileNames: () => outputExt === ".esm.js" ? "[name].js" : "[name]".concat(outputExt),
640
+ format,
641
+ exports: "auto",
642
+ sourcemap: (_ref7 = config == null ? void 0 : config.sourcemap) !== null && _ref7 !== void 0 ? _ref7 : true
643
+ }
644
+ };
645
+ }
646
+
647
+ const _rollupTask = {
648
+ 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 ")),
649
+ exec: (ctx, task) => {
650
+ return new rxjs.Observable(observer => {
651
+ _execPromise(ctx, task).then(result => {
652
+ observer.next(result);
653
+ observer.complete();
654
+ }).catch(err => observer.error(err));
655
+ });
656
+ },
657
+ complete: () => {},
658
+ error: (_ctx, _task, err) => {
659
+ if (err instanceof Error) {
660
+ console.log(err);
661
+ }
662
+ }
663
+ };
664
+
665
+ async function _execPromise(ctx, task) {
666
+ const {
667
+ files,
668
+ distPath
669
+ } = ctx;
670
+ const outDir = path__default["default"].relative(ctx.cwd, distPath);
671
+
672
+ const {
673
+ inputOptions,
674
+ outputOptions
675
+ } = _resolveRollupConfig(ctx, task);
676
+
677
+ const bundle = await rollup.rollup(inputOptions);
678
+ const {
679
+ output
680
+ } = await bundle.generate(outputOptions);
681
+
682
+ for (const chunkOrAsset of output) {
683
+ if (chunkOrAsset.type === "asset") {
684
+ files.push({
685
+ type: "asset",
686
+ path: path__default["default"].resolve(outDir, chunkOrAsset.fileName)
687
+ });
688
+ } else {
689
+ files.push({
690
+ type: "chunk",
691
+ path: path__default["default"].resolve(outDir, chunkOrAsset.fileName)
692
+ });
693
+ }
694
+ }
695
+
696
+ await bundle.write(outputOptions);
697
+ await bundle.close();
698
+ }
699
+
700
+ const _rollupWatchTask = {
701
+ 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 ")),
702
+ exec: (ctx, task) => {
703
+ const {
704
+ inputOptions,
705
+ outputOptions
706
+ } = _resolveRollupConfig(ctx, task);
707
+
708
+ return new rxjs.Observable(observer => {
709
+ const watchOptions = _objectSpread(_objectSpread({}, inputOptions), {}, {
710
+ output: outputOptions
711
+ });
712
+
713
+ const watcher = rollup.watch(watchOptions);
714
+ watcher.on("event", event => {
715
+ observer.next(event);
716
+ });
717
+ return () => {
718
+ watcher.close();
719
+ };
720
+ });
721
+ },
722
+ complete: (ctx, task, event) => {
723
+ const {
724
+ logger
725
+ } = ctx;
726
+
727
+ if (event.code === "BUNDLE_END") {
728
+ 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 ")));
729
+ logger.log("");
730
+ return;
731
+ }
732
+
733
+ if (event.code === "BUNDLE_START") {
734
+ return;
735
+ }
736
+
737
+ if (event.code === "END") {
738
+ return;
739
+ }
740
+
741
+ if (event.code === "ERROR") {
742
+ logger.error(event.code, event);
743
+ return;
744
+ }
745
+
746
+ if (event.code === "START") {
747
+ return;
748
+ }
749
+ },
750
+ error: (ctx, _task, err) => {
751
+ const {
752
+ logger
753
+ } = ctx;
754
+
755
+ if (err instanceof Error) {
756
+ logger.log(err);
757
+ }
758
+ }
759
+ };
760
+ const _buildTaskHandlers = {
761
+ "build:dts": _dtsTask,
762
+ "build:js": _rollupTask
763
+ };
764
+ const _watchTaskHandlers = {
765
+ "watch:dts": _dtsWatchTask,
766
+ "watch:js": _rollupWatchTask
767
+ };
768
+ exports._buildTaskHandlers = _buildTaskHandlers;
769
+ exports._dtsTask = _dtsTask;
770
+ exports._dtsWatchTask = _dtsWatchTask;
771
+ exports._rollupTask = _rollupTask;
772
+ exports._rollupWatchTask = _rollupWatchTask;
773
+ exports._watchTaskHandlers = _watchTaskHandlers;
774
+ //# sourceMappingURL=index-340fbb6a.js.map