@sanity/pkg-utils 2.4.4 → 2.4.5
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-5f23b148.cjs → build-6f16c228.cjs} +2 -2
- package/dist/_chunks/{build-5f23b148.cjs.map → build-6f16c228.cjs.map} +1 -1
- package/dist/_chunks/{buildAction-d61d273f.cjs → buildAction-d1273553.cjs} +2 -2
- package/dist/_chunks/{buildAction-d61d273f.cjs.map → buildAction-d1273553.cjs.map} +1 -1
- package/dist/_chunks/index-b98cebbf.cjs +2162 -0
- package/dist/_chunks/index-b98cebbf.cjs.map +1 -0
- package/dist/_chunks/{watch-ef2e86b4.cjs → watch-33be835b.cjs} +2 -2
- package/dist/_chunks/{watch-ef2e86b4.cjs.map → watch-33be835b.cjs.map} +1 -1
- package/dist/_chunks/{watchAction-dcaa223b.cjs → watchAction-0874be38.cjs} +2 -2
- package/dist/_chunks/{watchAction-dcaa223b.cjs.map → watchAction-0874be38.cjs.map} +1 -1
- package/dist/cli.cjs +3 -3
- package/dist/index.cjs +3 -3
- package/dist/index.js +2162 -2561
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
- package/dist/_chunks/index-bade3e43.cjs +0 -883
- package/dist/_chunks/index-bade3e43.cjs.map +0 -1
|
@@ -1,883 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
4
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
5
|
-
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
6
|
-
var chalk = require('chalk');
|
|
7
|
-
var rxjs = require('rxjs');
|
|
8
|
-
var path = require('path');
|
|
9
|
-
var rimraf = require('rimraf');
|
|
10
|
-
var ts = require('typescript');
|
|
11
|
-
var apiExtractor = require('@microsoft/api-extractor');
|
|
12
|
-
var fs = require('fs/promises');
|
|
13
|
-
var mkdirp = require('mkdirp');
|
|
14
|
-
var prettier = require('prettier');
|
|
15
|
-
var tsdocConfig = require('@microsoft/tsdoc-config');
|
|
16
|
-
var jsoncParser = require('jsonc-parser');
|
|
17
|
-
var recast = require('recast');
|
|
18
|
-
var typeScriptParser = require('recast/parsers/typescript');
|
|
19
|
-
var rollup = require('rollup');
|
|
20
|
-
var consoleSpy = require('./consoleSpy-5164e16b.cjs');
|
|
21
|
-
var alias = require('@rollup/plugin-alias');
|
|
22
|
-
var pluginBabel = require('@rollup/plugin-babel');
|
|
23
|
-
var commonjs = require('@rollup/plugin-commonjs');
|
|
24
|
-
var json = require('@rollup/plugin-json');
|
|
25
|
-
var pluginNodeResolve = require('@rollup/plugin-node-resolve');
|
|
26
|
-
var replace = require('@rollup/plugin-replace');
|
|
27
|
-
var terser = require('@rollup/plugin-terser');
|
|
28
|
-
var esbuild = require('rollup-plugin-esbuild');
|
|
29
|
-
var preserveDirectives = require('rollup-plugin-preserve-directives');
|
|
30
|
-
require('esbuild-register/dist/node');
|
|
31
|
-
require('pkg-up');
|
|
32
|
-
require('find-config');
|
|
33
|
-
require('fs');
|
|
34
|
-
require('./logger-718e11be.cjs');
|
|
35
|
-
require('zod');
|
|
36
|
-
require('prompts');
|
|
37
|
-
function _interopDefaultCompat(e) {
|
|
38
|
-
return e && typeof e === 'object' && 'default' in e ? e : {
|
|
39
|
-
default: e
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
var chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
|
|
43
|
-
var path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
44
|
-
var rimraf__default = /*#__PURE__*/_interopDefaultCompat(rimraf);
|
|
45
|
-
var ts__default = /*#__PURE__*/_interopDefaultCompat(ts);
|
|
46
|
-
var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
47
|
-
var prettier__default = /*#__PURE__*/_interopDefaultCompat(prettier);
|
|
48
|
-
var typeScriptParser__default = /*#__PURE__*/_interopDefaultCompat(typeScriptParser);
|
|
49
|
-
var alias__default = /*#__PURE__*/_interopDefaultCompat(alias);
|
|
50
|
-
var commonjs__default = /*#__PURE__*/_interopDefaultCompat(commonjs);
|
|
51
|
-
var json__default = /*#__PURE__*/_interopDefaultCompat(json);
|
|
52
|
-
var replace__default = /*#__PURE__*/_interopDefaultCompat(replace);
|
|
53
|
-
var terser__default = /*#__PURE__*/_interopDefaultCompat(terser);
|
|
54
|
-
var esbuild__default = /*#__PURE__*/_interopDefaultCompat(esbuild);
|
|
55
|
-
var preserveDirectives__default = /*#__PURE__*/_interopDefaultCompat(preserveDirectives);
|
|
56
|
-
function printExtractMessages(ctx, messages) {
|
|
57
|
-
const {
|
|
58
|
-
cwd,
|
|
59
|
-
logger
|
|
60
|
-
} = ctx;
|
|
61
|
-
const warnings = messages.filter(msg => msg.logLevel === "warning");
|
|
62
|
-
if (warnings.length) {
|
|
63
|
-
logger.log();
|
|
64
|
-
}
|
|
65
|
-
for (const msg of warnings) {
|
|
66
|
-
const sourceFilePath = msg.sourceFilePath && path__default.default.relative(cwd, msg.sourceFilePath);
|
|
67
|
-
if (msg.messageId === "TS6307") {
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
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(""));
|
|
71
|
-
}
|
|
72
|
-
const errors = messages.filter(msg => msg.logLevel === "error");
|
|
73
|
-
if (!warnings.length && errors.length) {
|
|
74
|
-
logger.log("");
|
|
75
|
-
}
|
|
76
|
-
for (const msg of errors) {
|
|
77
|
-
const sourceFilePath = msg.sourceFilePath && path__default.default.relative(cwd, msg.sourceFilePath);
|
|
78
|
-
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(""));
|
|
79
|
-
}
|
|
80
|
-
if (errors.length) {
|
|
81
|
-
process.exit(1);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
function printDiagnostic(options) {
|
|
85
|
-
const {
|
|
86
|
-
cwd,
|
|
87
|
-
logger,
|
|
88
|
-
diagnostic
|
|
89
|
-
} = options;
|
|
90
|
-
if (diagnostic.file && diagnostic.start) {
|
|
91
|
-
const {
|
|
92
|
-
line,
|
|
93
|
-
character
|
|
94
|
-
} = ts__default.default.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
|
|
95
|
-
const message = ts__default.default.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
|
|
96
|
-
const file = path__default.default.relative(cwd, diagnostic.file.fileName);
|
|
97
|
-
const output = ["".concat(chalk__default.default.yellow(file), ":").concat(chalk__default.default.blue(line + 1), ":").concat(chalk__default.default.blue(character + 1), " - "), "".concat(chalk__default.default.gray("TS".concat(diagnostic.code, ":")), " ").concat(message)].join("");
|
|
98
|
-
if (diagnostic.category === ts__default.default.DiagnosticCategory.Error) {
|
|
99
|
-
logger.error(output);
|
|
100
|
-
}
|
|
101
|
-
if (diagnostic.category === ts__default.default.DiagnosticCategory.Warning) {
|
|
102
|
-
logger.warn(output);
|
|
103
|
-
}
|
|
104
|
-
if (diagnostic.category === ts__default.default.DiagnosticCategory.Message) {
|
|
105
|
-
logger.log(output);
|
|
106
|
-
}
|
|
107
|
-
if (diagnostic.category === ts__default.default.DiagnosticCategory.Suggestion) {
|
|
108
|
-
logger.log(output);
|
|
109
|
-
}
|
|
110
|
-
} else {
|
|
111
|
-
logger.log(ts__default.default.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
async function buildTypes(options) {
|
|
115
|
-
const {
|
|
116
|
-
cwd,
|
|
117
|
-
logger,
|
|
118
|
-
outDir,
|
|
119
|
-
tsconfig,
|
|
120
|
-
strict = false
|
|
121
|
-
} = options;
|
|
122
|
-
const compilerOptions = {
|
|
123
|
-
...tsconfig.options,
|
|
124
|
-
declaration: true,
|
|
125
|
-
declarationDir: outDir,
|
|
126
|
-
emitDeclarationOnly: true,
|
|
127
|
-
noEmit: false,
|
|
128
|
-
outDir
|
|
129
|
-
};
|
|
130
|
-
const program = ts__default.default.createProgram(tsconfig.fileNames, compilerOptions);
|
|
131
|
-
const emitResult = program.emit();
|
|
132
|
-
const allDiagnostics = ts__default.default.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
|
|
133
|
-
for (const diagnostic of allDiagnostics) {
|
|
134
|
-
printDiagnostic({
|
|
135
|
-
cwd,
|
|
136
|
-
logger,
|
|
137
|
-
diagnostic
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
if (emitResult.emitSkipped) {
|
|
141
|
-
const errors = allDiagnostics.filter(diag => diag.category === ts__default.default.DiagnosticCategory.Error);
|
|
142
|
-
if (errors.length) {
|
|
143
|
-
if (strict) {
|
|
144
|
-
throw new Error("failed to compile TypeScript definitions");
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
class DtsError extends Error {
|
|
150
|
-
constructor(message, messages) {
|
|
151
|
-
super(message);
|
|
152
|
-
_defineProperty(this, "messages", void 0);
|
|
153
|
-
this.messages = messages;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
function createApiExtractorConfig(options) {
|
|
157
|
-
const {
|
|
158
|
-
distPath,
|
|
159
|
-
exportPath,
|
|
160
|
-
filePath,
|
|
161
|
-
messages,
|
|
162
|
-
projectFolder,
|
|
163
|
-
mainEntryPointFilePath,
|
|
164
|
-
tsconfigPath
|
|
165
|
-
} = options;
|
|
166
|
-
return {
|
|
167
|
-
apiReport: {
|
|
168
|
-
enabled: false,
|
|
169
|
-
reportFileName: "<unscopedPackageName>.api.md"
|
|
170
|
-
},
|
|
171
|
-
// bundledPackages: [],
|
|
172
|
-
compiler: {
|
|
173
|
-
tsconfigFilePath: tsconfigPath
|
|
174
|
-
},
|
|
175
|
-
docModel: {
|
|
176
|
-
enabled: false,
|
|
177
|
-
apiJsonFilePath: path__default.default.resolve(distPath, "".concat(exportPath, ".api.json"))
|
|
178
|
-
},
|
|
179
|
-
dtsRollup: {
|
|
180
|
-
enabled: true,
|
|
181
|
-
untrimmedFilePath: path__default.default.resolve(distPath, filePath)
|
|
182
|
-
// betaTrimmedFilePath: path.resolve(distPath, filePath.replace('.d.ts', '-beta.d.ts')),
|
|
183
|
-
// publicTrimmedFilePath: path.resolve(distPath, filePath.replace('.d.ts', '-public.d.ts')),
|
|
184
|
-
},
|
|
185
|
-
|
|
186
|
-
tsdocMetadata: {
|
|
187
|
-
enabled: false
|
|
188
|
-
},
|
|
189
|
-
messages,
|
|
190
|
-
mainEntryPointFilePath,
|
|
191
|
-
projectFolder
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
async function createTSDocConfig(opts) {
|
|
195
|
-
const {
|
|
196
|
-
customTags
|
|
197
|
-
} = opts;
|
|
198
|
-
if (customTags.length === 0) {
|
|
199
|
-
return void 0;
|
|
200
|
-
}
|
|
201
|
-
const tsDocBaseBuf = await fs.readFile(require.resolve("@microsoft/api-extractor/extends/tsdoc-base.json"));
|
|
202
|
-
const tsDocBaseConfig = jsoncParser.parse(tsDocBaseBuf.toString());
|
|
203
|
-
const tagDefinitions = (tsDocBaseConfig.tagDefinitions || []).concat(customTags.map(t => ({
|
|
204
|
-
tagName: "@".concat(t.name),
|
|
205
|
-
syntaxKind: t.syntaxKind,
|
|
206
|
-
allowMultiple: t.allowMultiple
|
|
207
|
-
})));
|
|
208
|
-
const supportForTags = {
|
|
209
|
-
...tsDocBaseConfig.supportForTags
|
|
210
|
-
};
|
|
211
|
-
for (const customTag of customTags) {
|
|
212
|
-
supportForTags["@".concat(customTag.name)] = true;
|
|
213
|
-
}
|
|
214
|
-
return tsdocConfig.TSDocConfigFile.loadFromObject({
|
|
215
|
-
...tsDocBaseConfig,
|
|
216
|
-
noStandardTags: false,
|
|
217
|
-
tagDefinitions,
|
|
218
|
-
supportForTags
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
async function extractModuleBlocksFromTypes(_ref) {
|
|
222
|
-
let {
|
|
223
|
-
tsOutDir,
|
|
224
|
-
extractResult
|
|
225
|
-
} = _ref;
|
|
226
|
-
const program = extractResult.compilerState.program;
|
|
227
|
-
const moduleBlocks = [];
|
|
228
|
-
const allProgramFiles = [...program.getSourceFiles()];
|
|
229
|
-
const sourceFiles = allProgramFiles.filter(sourceFile => sourceFile.fileName.includes(tsOutDir));
|
|
230
|
-
for (const sourceFile of sourceFiles) {
|
|
231
|
-
if (sourceFile.text.includes("declare module")) {
|
|
232
|
-
moduleBlocks.push(...extractModuleBlocks(sourceFile.text));
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
return moduleBlocks;
|
|
236
|
-
}
|
|
237
|
-
function extractModuleBlocks(fileContent) {
|
|
238
|
-
const ast = recast.parse(fileContent, {
|
|
239
|
-
parser: typeScriptParser__default.default
|
|
240
|
-
});
|
|
241
|
-
return ast.program.body.filter(node => node.type === "TSModuleDeclaration").map(node => recast.print(node).code);
|
|
242
|
-
}
|
|
243
|
-
const LOG_LEVELS = {
|
|
244
|
-
error: "error",
|
|
245
|
-
info: "info",
|
|
246
|
-
off: "none",
|
|
247
|
-
warn: "warning"
|
|
248
|
-
};
|
|
249
|
-
function getExtractMessagesConfig(options) {
|
|
250
|
-
const {
|
|
251
|
-
rules
|
|
252
|
-
} = options;
|
|
253
|
-
function ruleToLogLevel(key, defaultLevel) {
|
|
254
|
-
const r = rules == null ? void 0 : rules[key];
|
|
255
|
-
return r ? LOG_LEVELS[r] : defaultLevel || "warning";
|
|
256
|
-
}
|
|
257
|
-
return {
|
|
258
|
-
compilerMessageReporting: {
|
|
259
|
-
default: {
|
|
260
|
-
logLevel: "warning"
|
|
261
|
-
}
|
|
262
|
-
},
|
|
263
|
-
extractorMessageReporting: {
|
|
264
|
-
default: {
|
|
265
|
-
logLevel: "warning",
|
|
266
|
-
addToApiReportFile: false
|
|
267
|
-
},
|
|
268
|
-
"ae-forgotten-export": {
|
|
269
|
-
logLevel: ruleToLogLevel("ae-forgotten-export", "error"),
|
|
270
|
-
addToApiReportFile: false
|
|
271
|
-
},
|
|
272
|
-
"ae-incompatible-release-tags": {
|
|
273
|
-
logLevel: ruleToLogLevel("ae-incompatible-release-tags", "error"),
|
|
274
|
-
addToApiReportFile: false
|
|
275
|
-
},
|
|
276
|
-
"ae-internal-missing-underscore": {
|
|
277
|
-
logLevel: ruleToLogLevel("ae-internal-missing-underscore"),
|
|
278
|
-
addToApiReportFile: false
|
|
279
|
-
},
|
|
280
|
-
"ae-missing-release-tag": {
|
|
281
|
-
logLevel: ruleToLogLevel("ae-missing-release-tag", "error"),
|
|
282
|
-
addToApiReportFile: false
|
|
283
|
-
},
|
|
284
|
-
"ae-wrong-input-file-type": {
|
|
285
|
-
logLevel: "none",
|
|
286
|
-
addToApiReportFile: false
|
|
287
|
-
}
|
|
288
|
-
},
|
|
289
|
-
tsdocMessageReporting: {
|
|
290
|
-
default: {
|
|
291
|
-
logLevel: "warning",
|
|
292
|
-
addToApiReportFile: false
|
|
293
|
-
},
|
|
294
|
-
"tsdoc-link-tag-unescaped-text": {
|
|
295
|
-
logLevel: ruleToLogLevel("tsdoc-link-tag-unescaped-text", "warning"),
|
|
296
|
-
addToApiReportFile: false
|
|
297
|
-
},
|
|
298
|
-
"tsdoc-undefined-tag": {
|
|
299
|
-
logLevel: ruleToLogLevel("tsdoc-undefined-tag", "error"),
|
|
300
|
-
addToApiReportFile: false
|
|
301
|
-
},
|
|
302
|
-
"tsdoc-unsupported-tag": {
|
|
303
|
-
logLevel: ruleToLogLevel("tsdoc-unsupported-tag", "none"),
|
|
304
|
-
addToApiReportFile: false
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
async function extractTypes(options) {
|
|
310
|
-
const {
|
|
311
|
-
customTags,
|
|
312
|
-
distPath,
|
|
313
|
-
exportPath,
|
|
314
|
-
files,
|
|
315
|
-
filePath,
|
|
316
|
-
projectPath,
|
|
317
|
-
rules,
|
|
318
|
-
sourceTypesPath,
|
|
319
|
-
tmpPath,
|
|
320
|
-
tsconfigPath
|
|
321
|
-
} = options;
|
|
322
|
-
const tsdocConfigFile = await createTSDocConfig({
|
|
323
|
-
customTags: customTags || []
|
|
324
|
-
});
|
|
325
|
-
const extractorConfig = apiExtractor.ExtractorConfig.prepare({
|
|
326
|
-
configObject: createApiExtractorConfig({
|
|
327
|
-
distPath,
|
|
328
|
-
exportPath,
|
|
329
|
-
filePath,
|
|
330
|
-
messages: getExtractMessagesConfig({
|
|
331
|
-
rules
|
|
332
|
-
}),
|
|
333
|
-
projectFolder: projectPath,
|
|
334
|
-
mainEntryPointFilePath: sourceTypesPath,
|
|
335
|
-
tsconfigPath
|
|
336
|
-
}),
|
|
337
|
-
configObjectFullPath: void 0,
|
|
338
|
-
tsdocConfigFile,
|
|
339
|
-
packageJsonFullPath: path__default.default.resolve(projectPath, "package.json")
|
|
340
|
-
});
|
|
341
|
-
const messages = [];
|
|
342
|
-
const extractorResult = apiExtractor.Extractor.invoke(extractorConfig, {
|
|
343
|
-
// Equivalent to the "--local" command-line parameter
|
|
344
|
-
localBuild: true,
|
|
345
|
-
// Equivalent to the "--verbose" command-line parameter
|
|
346
|
-
showVerboseMessages: true,
|
|
347
|
-
// handle messages
|
|
348
|
-
messageCallback(message) {
|
|
349
|
-
messages.push(message);
|
|
350
|
-
message.handled = true;
|
|
351
|
-
}
|
|
352
|
-
});
|
|
353
|
-
const typesPath = path__default.default.resolve(distPath, filePath);
|
|
354
|
-
const typesBuf = await fs__default.default.readFile(typesPath);
|
|
355
|
-
const prettierConfig = await prettier__default.default.resolveConfig(typesPath);
|
|
356
|
-
await mkdirp.mkdirp(path__default.default.dirname(typesPath));
|
|
357
|
-
const moduleBlocks = await extractModuleBlocksFromTypes({
|
|
358
|
-
extractResult: extractorResult,
|
|
359
|
-
tsOutDir: tmpPath
|
|
360
|
-
});
|
|
361
|
-
const code = [typesBuf.toString(), ...moduleBlocks].join("\n\n");
|
|
362
|
-
await fs__default.default.writeFile(typesPath, await prettier__default.default.format(code, {
|
|
363
|
-
...prettierConfig,
|
|
364
|
-
filepath: typesPath
|
|
365
|
-
}));
|
|
366
|
-
files.push({
|
|
367
|
-
type: "types",
|
|
368
|
-
path: typesPath
|
|
369
|
-
});
|
|
370
|
-
return {
|
|
371
|
-
extractorResult,
|
|
372
|
-
messages
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
async function doExtract(ctx, task) {
|
|
376
|
-
var _a, _b;
|
|
377
|
-
const {
|
|
378
|
-
config,
|
|
379
|
-
cwd,
|
|
380
|
-
files,
|
|
381
|
-
logger,
|
|
382
|
-
strict,
|
|
383
|
-
ts
|
|
384
|
-
} = ctx;
|
|
385
|
-
if (!ts.config || !ts.configPath) {
|
|
386
|
-
return {
|
|
387
|
-
type: "dts",
|
|
388
|
-
messages: [],
|
|
389
|
-
results: []
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
const {
|
|
393
|
-
outDir,
|
|
394
|
-
rootDir = cwd
|
|
395
|
-
} = ts.config.options;
|
|
396
|
-
if (!outDir) {
|
|
397
|
-
throw new Error("tsconfig.json is missing `compilerOptions.outDir`");
|
|
398
|
-
}
|
|
399
|
-
const tmpPath = path__default.default.resolve(outDir, "__tmp__");
|
|
400
|
-
await buildTypes({
|
|
401
|
-
cwd,
|
|
402
|
-
logger,
|
|
403
|
-
outDir: tmpPath,
|
|
404
|
-
strict,
|
|
405
|
-
tsconfig: ts.config
|
|
406
|
-
});
|
|
407
|
-
const messages = [];
|
|
408
|
-
const results = [];
|
|
409
|
-
for (const entry of task.entries) {
|
|
410
|
-
const exportPath = entry.exportPath === "." ? "./index" : entry.exportPath;
|
|
411
|
-
const sourceTypesPath = path__default.default.resolve(tmpPath, path__default.default.relative(rootDir, path__default.default.resolve(cwd, entry.sourcePath)).replace(/\.ts$/, ".d.ts"));
|
|
412
|
-
const targetPath = path__default.default.resolve(cwd, entry.targetPath);
|
|
413
|
-
const filePath = path__default.default.relative(outDir, targetPath);
|
|
414
|
-
const result = await extractTypes({
|
|
415
|
-
customTags: (_a = config == null ? void 0 : config.extract) == null ? void 0 : _a.customTags,
|
|
416
|
-
cwd,
|
|
417
|
-
distPath: outDir,
|
|
418
|
-
exportPath,
|
|
419
|
-
files,
|
|
420
|
-
filePath,
|
|
421
|
-
projectPath: cwd,
|
|
422
|
-
rules: (_b = config == null ? void 0 : config.extract) == null ? void 0 : _b.rules,
|
|
423
|
-
sourceTypesPath,
|
|
424
|
-
tmpPath,
|
|
425
|
-
tsconfigPath: path__default.default.resolve(cwd, ts.configPath || "tsconfig.json")
|
|
426
|
-
});
|
|
427
|
-
messages.push(...result.messages);
|
|
428
|
-
if (result.messages.some(msg => msg.logLevel === "error")) {
|
|
429
|
-
await rimraf__default.default(tmpPath);
|
|
430
|
-
throw new DtsError("encountered errors when extracting types", result.messages);
|
|
431
|
-
}
|
|
432
|
-
results.push({
|
|
433
|
-
sourcePath: path__default.default.resolve(cwd, entry.sourcePath),
|
|
434
|
-
filePath: targetPath
|
|
435
|
-
});
|
|
436
|
-
}
|
|
437
|
-
await rimraf__default.default(tmpPath);
|
|
438
|
-
return {
|
|
439
|
-
type: "dts",
|
|
440
|
-
messages,
|
|
441
|
-
results
|
|
442
|
-
};
|
|
443
|
-
}
|
|
444
|
-
const dtsTask = {
|
|
445
|
-
name: (_ctx, task) => ["Build type definitions...", " entries:", ...task.entries.map(entry => [" - ".concat(chalk__default.default.cyan(entry.importId), ": "), "".concat(chalk__default.default.yellow(entry.sourcePath), " ").concat(chalk__default.default.gray("\u2192"), " ").concat(chalk__default.default.yellow(entry.targetPath))].join(""))].join("\n"),
|
|
446
|
-
exec: (ctx, task) => {
|
|
447
|
-
return new rxjs.Observable(observer => {
|
|
448
|
-
doExtract(ctx, task).then(result => {
|
|
449
|
-
observer.next(result);
|
|
450
|
-
observer.complete();
|
|
451
|
-
}).catch(err => {
|
|
452
|
-
observer.error(err);
|
|
453
|
-
});
|
|
454
|
-
});
|
|
455
|
-
},
|
|
456
|
-
complete: (ctx, _task, result) => {
|
|
457
|
-
printExtractMessages(ctx, result.messages);
|
|
458
|
-
},
|
|
459
|
-
error: (ctx, _task, err) => {
|
|
460
|
-
const {
|
|
461
|
-
logger
|
|
462
|
-
} = ctx;
|
|
463
|
-
if (err instanceof DtsError) {
|
|
464
|
-
printExtractMessages(ctx, err.messages);
|
|
465
|
-
} else if (err instanceof Error) {
|
|
466
|
-
logger.error(err);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
};
|
|
470
|
-
const dtsWatchTask = {
|
|
471
|
-
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"),
|
|
472
|
-
exec: (ctx, task) => {
|
|
473
|
-
return new rxjs.Observable(observer => {
|
|
474
|
-
doExtract(ctx, task).then(result => {
|
|
475
|
-
observer.next(result);
|
|
476
|
-
observer.complete();
|
|
477
|
-
}).catch(err => observer.error(err));
|
|
478
|
-
});
|
|
479
|
-
},
|
|
480
|
-
complete: (ctx, _task, result) => {
|
|
481
|
-
const {
|
|
482
|
-
logger
|
|
483
|
-
} = ctx;
|
|
484
|
-
printExtractMessages(ctx, result.messages);
|
|
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
|
-
if (err instanceof DtsError) {
|
|
493
|
-
printExtractMessages(ctx, err.messages);
|
|
494
|
-
} else if (err instanceof Error) {
|
|
495
|
-
logger.error(err);
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
};
|
|
499
|
-
const nodeReexportCjsTask = {
|
|
500
|
-
name: (_ctx, task) => ["Re-export CommonJS module in ESM wrapper\u2026", " entries:", ...task.entries.map(entry => [" - ".concat(chalk__default.default.cyan(entry.importId), ": "), "".concat(chalk__default.default.yellow(entry.require), " ").concat(chalk__default.default.gray("\u2192"), " ").concat(chalk__default.default.yellow(entry.import))].join(""))].join("\n"),
|
|
501
|
-
exec: (ctx, task) => {
|
|
502
|
-
return rxjs.from(exec(ctx, task));
|
|
503
|
-
},
|
|
504
|
-
complete: () => {},
|
|
505
|
-
error: (_ctx, _task, err) => {
|
|
506
|
-
console.error(err);
|
|
507
|
-
}
|
|
508
|
-
};
|
|
509
|
-
async function exec(ctx, task) {
|
|
510
|
-
const {
|
|
511
|
-
cwd
|
|
512
|
-
} = ctx;
|
|
513
|
-
for (const entry of task.entries) {
|
|
514
|
-
const sourcePath = path__default.default.resolve(cwd, entry.require);
|
|
515
|
-
const targetPath = path__default.default.resolve(cwd, entry.import);
|
|
516
|
-
const targetDir = path__default.default.dirname(targetPath);
|
|
517
|
-
await mkdirp.mkdirp(targetDir);
|
|
518
|
-
const mod = require(sourcePath);
|
|
519
|
-
let relativeImport = "./".concat(path__default.default.relative(targetDir, sourcePath));
|
|
520
|
-
if (relativeImport.startsWith("./.")) {
|
|
521
|
-
relativeImport = relativeImport.slice(2);
|
|
522
|
-
}
|
|
523
|
-
const code = compileESMWrapper(mod, relativeImport);
|
|
524
|
-
await fs.writeFile(targetPath, code, "utf8");
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
function compileESMWrapper(mod, relativeImport) {
|
|
528
|
-
const keys = Object.keys(mod).filter(k => k !== "__esModule");
|
|
529
|
-
let code = "import cjs from '".concat(relativeImport, "';\n");
|
|
530
|
-
if (keys.length) {
|
|
531
|
-
code += "\n";
|
|
532
|
-
code += keys.filter(k => mod.__esModule ? k !== "default" : true).map(k => "export const ".concat(k, " = cjs.").concat(k, ";\n")).join("");
|
|
533
|
-
}
|
|
534
|
-
code += "\n";
|
|
535
|
-
if (mod.__esModule) {
|
|
536
|
-
if ("default" in mod) {
|
|
537
|
-
code += "export default cjs.default;\n";
|
|
538
|
-
}
|
|
539
|
-
} else {
|
|
540
|
-
code += "export default cjs;\n";
|
|
541
|
-
}
|
|
542
|
-
return code;
|
|
543
|
-
}
|
|
544
|
-
function resolveRollupConfig(ctx, buildTask) {
|
|
545
|
-
var _ref2, _ref5, _ref6, _ref7, _ref8, _ref9;
|
|
546
|
-
var _a, _b, _c, _d;
|
|
547
|
-
const {
|
|
548
|
-
format,
|
|
549
|
-
runtime,
|
|
550
|
-
target
|
|
551
|
-
} = buildTask;
|
|
552
|
-
const {
|
|
553
|
-
config,
|
|
554
|
-
cwd,
|
|
555
|
-
exports: _exports,
|
|
556
|
-
extMap,
|
|
557
|
-
external,
|
|
558
|
-
distPath,
|
|
559
|
-
logger,
|
|
560
|
-
pkg,
|
|
561
|
-
ts
|
|
562
|
-
} = ctx;
|
|
563
|
-
const outputExt = extMap[pkg.type || "commonjs"][format];
|
|
564
|
-
const minify = (_ref2 = config == null ? void 0 : config.minify) !== null && _ref2 !== void 0 ? _ref2 : false;
|
|
565
|
-
const outDir = path__default.default.relative(cwd, distPath);
|
|
566
|
-
const pathAliases = Object.fromEntries(Object.entries(((_a = ts.config) == null ? void 0 : _a.options.paths) || {}).map(_ref3 => {
|
|
567
|
-
let [key, val] = _ref3;
|
|
568
|
-
var _a2;
|
|
569
|
-
return [key, path__default.default.resolve(cwd, ((_a2 = ts.config) == null ? void 0 : _a2.options.baseUrl) || ".", val[0])];
|
|
570
|
-
}));
|
|
571
|
-
const entries = buildTask.entries.map(entry => {
|
|
572
|
-
return {
|
|
573
|
-
...entry,
|
|
574
|
-
name: path__default.default.relative(outDir, entry.output).replace(/\.[^/.]+$/, "")
|
|
575
|
-
};
|
|
576
|
-
}, {});
|
|
577
|
-
const exportIds = _exports && Object.keys(_exports).map(exportPath => path__default.default.join(pkg.name, exportPath));
|
|
578
|
-
const sourcePaths = _exports && Object.values(_exports).map(e => path__default.default.resolve(cwd, e.source));
|
|
579
|
-
const replacements = Object.fromEntries(Object.entries((config == null ? void 0 : config.define) || {}).map(_ref4 => {
|
|
580
|
-
let [key, val] = _ref4;
|
|
581
|
-
return [key, JSON.stringify(val)];
|
|
582
|
-
}));
|
|
583
|
-
const defaultPlugins = [replace__default.default({
|
|
584
|
-
preventAssignment: true,
|
|
585
|
-
values: {
|
|
586
|
-
...(pkg.name === "@sanity/pkg-utils" ? {
|
|
587
|
-
...replacements
|
|
588
|
-
} : {
|
|
589
|
-
"process.env.PKG_FILE_PATH": arg => {
|
|
590
|
-
const sourcePath = "./" + path__default.default.relative(cwd, arg);
|
|
591
|
-
const entry = entries.find(e => e.source === sourcePath);
|
|
592
|
-
if (!entry) {
|
|
593
|
-
console.error("could not find source entry: ".concat(sourcePath));
|
|
594
|
-
return "null";
|
|
595
|
-
}
|
|
596
|
-
return JSON.stringify(path__default.default.relative(cwd, path__default.default.resolve(outDir, entry.name + outputExt)));
|
|
597
|
-
},
|
|
598
|
-
"process.env.PKG_FORMAT": JSON.stringify(format),
|
|
599
|
-
"process.env.PKG_RUNTIME": JSON.stringify(runtime),
|
|
600
|
-
"process.env.PKG_VERSION": JSON.stringify(process.env.PKG_VERSION || pkg.version),
|
|
601
|
-
...replacements
|
|
602
|
-
})
|
|
603
|
-
}
|
|
604
|
-
}), alias__default.default({
|
|
605
|
-
entries: {
|
|
606
|
-
...pathAliases
|
|
607
|
-
}
|
|
608
|
-
}), pluginNodeResolve.nodeResolve({
|
|
609
|
-
// mainFields: ['module', 'jsnext', 'main'],
|
|
610
|
-
browser: runtime === "browser",
|
|
611
|
-
// exportConditions: [runtime === 'node' ? 'node' : 'browser'],
|
|
612
|
-
extensions: [".cjs", ".mjs", ".js", ".jsx", ".json", ".node"],
|
|
613
|
-
preferBuiltins: true
|
|
614
|
-
// runtime === 'node',
|
|
615
|
-
}), commonjs__default.default(), json__default.default(), esbuild__default.default({
|
|
616
|
-
jsx: (_ref5 = config == null ? void 0 : config.jsx) !== null && _ref5 !== void 0 ? _ref5 : "automatic",
|
|
617
|
-
jsxFactory: (_ref6 = config == null ? void 0 : config.jsxFactory) !== null && _ref6 !== void 0 ? _ref6 : "createElement",
|
|
618
|
-
jsxFragment: (_ref7 = config == null ? void 0 : config.jsxFragment) !== null && _ref7 !== void 0 ? _ref7 : "Fragment",
|
|
619
|
-
jsxImportSource: (_ref8 = config == null ? void 0 : config.jsxImportSource) !== null && _ref8 !== void 0 ? _ref8 : "react",
|
|
620
|
-
target,
|
|
621
|
-
tsconfig: ctx.ts.configPath || "tsconfig.json"
|
|
622
|
-
}), pluginBabel.getBabelOutputPlugin({
|
|
623
|
-
babelrc: false,
|
|
624
|
-
plugins: (_b = config == null ? void 0 : config.babel) == null ? void 0 : _b.plugins,
|
|
625
|
-
presets: [["@babel/preset-env", {
|
|
626
|
-
targets: pkg.browserslist || consoleSpy.DEFAULT_BROWSERSLIST_QUERY,
|
|
627
|
-
modules: false
|
|
628
|
-
}]]
|
|
629
|
-
}), minify && terser__default.default({
|
|
630
|
-
compress: (config == null ? void 0 : config.preserveModuleDirectives) ? {
|
|
631
|
-
// Needed until https://github.com/terser/terser/issues/1320 is fixed
|
|
632
|
-
directives: false
|
|
633
|
-
} : true,
|
|
634
|
-
output: {
|
|
635
|
-
comments: (_node, comment) => {
|
|
636
|
-
const text = comment.value;
|
|
637
|
-
const type = comment.type;
|
|
638
|
-
if (type == "comment2") {
|
|
639
|
-
return /@preserve|@license|@cc_on/i.test(text);
|
|
640
|
-
}
|
|
641
|
-
return false;
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
}),
|
|
645
|
-
// Allows marking export files with `'use client'` at the top
|
|
646
|
-
(config == null ? void 0 : config.preserveModuleDirectives) && preserveDirectives__default.default()].filter(Boolean);
|
|
647
|
-
const userPlugins = (_c = config == null ? void 0 : config.rollup) == null ? void 0 : _c.plugins;
|
|
648
|
-
const plugins = Array.isArray(userPlugins) ? defaultPlugins.concat(userPlugins) : consoleSpy.resolveConfigProperty((_d = config == null ? void 0 : config.rollup) == null ? void 0 : _d.plugins, defaultPlugins);
|
|
649
|
-
return {
|
|
650
|
-
inputOptions: {
|
|
651
|
-
context: cwd,
|
|
652
|
-
external: (id, importer) => {
|
|
653
|
-
if (exportIds == null ? void 0 : exportIds.includes(id)) {
|
|
654
|
-
return true;
|
|
655
|
-
}
|
|
656
|
-
if (importer && (id.startsWith(".") || id.startsWith("/"))) {
|
|
657
|
-
const idPath = path__default.default.resolve(path__default.default.dirname(importer), id);
|
|
658
|
-
if (sourcePaths == null ? void 0 : sourcePaths.includes(idPath)) {
|
|
659
|
-
logger.warn("detected self-referencing import \u2013 treating as external: ".concat(path__default.default.relative(cwd, idPath)));
|
|
660
|
-
return true;
|
|
661
|
-
}
|
|
662
|
-
}
|
|
663
|
-
const idParts = id.split("/");
|
|
664
|
-
const name = idParts[0].startsWith("@") ? "".concat(idParts[0], "/").concat(idParts[1]) : idParts[0];
|
|
665
|
-
if (name && external.includes(name)) {
|
|
666
|
-
return true;
|
|
667
|
-
}
|
|
668
|
-
return false;
|
|
669
|
-
},
|
|
670
|
-
input: entries.reduce((acc, entry) => {
|
|
671
|
-
return {
|
|
672
|
-
...acc,
|
|
673
|
-
[entry.name]: entry.source
|
|
674
|
-
};
|
|
675
|
-
}, {}),
|
|
676
|
-
plugins,
|
|
677
|
-
treeshake: {
|
|
678
|
-
propertyReadSideEffects: false
|
|
679
|
-
}
|
|
680
|
-
},
|
|
681
|
-
outputOptions: {
|
|
682
|
-
chunkFileNames: () => {
|
|
683
|
-
const parts = outputExt.split(".");
|
|
684
|
-
if (parts.length === 3) {
|
|
685
|
-
return "_chunks/[name]-[hash].".concat(parts[2]);
|
|
686
|
-
}
|
|
687
|
-
return "_chunks/[name]-[hash]".concat(outputExt);
|
|
688
|
-
},
|
|
689
|
-
compact: minify,
|
|
690
|
-
dir: outDir,
|
|
691
|
-
entryFileNames: () => {
|
|
692
|
-
const parts = outputExt.split(".");
|
|
693
|
-
if (parts.length === 3) {
|
|
694
|
-
return "[name].".concat(parts[2]);
|
|
695
|
-
}
|
|
696
|
-
return "[name]".concat(outputExt);
|
|
697
|
-
},
|
|
698
|
-
esModule: true,
|
|
699
|
-
format,
|
|
700
|
-
interop: "compat",
|
|
701
|
-
minifyInternalExports: minify,
|
|
702
|
-
sourcemap: (_ref9 = config == null ? void 0 : config.sourcemap) !== null && _ref9 !== void 0 ? _ref9 : true,
|
|
703
|
-
hoistTransitiveImports: false,
|
|
704
|
-
preserveModules: (config == null ? void 0 : config.preserveModuleDirectives) ? true : false
|
|
705
|
-
}
|
|
706
|
-
};
|
|
707
|
-
}
|
|
708
|
-
const rollupTask = {
|
|
709
|
-
name: (ctx, task) => {
|
|
710
|
-
const bundleEntries = task.entries.filter(e => e.path.includes("__$$bundle_"));
|
|
711
|
-
const entries = task.entries.filter(e => !e.path.includes("__$$bundle_"));
|
|
712
|
-
const targetLines = task.target.length ? [" target:", ...task.target.map(t => " - ".concat(chalk__default.default.yellow(t)))] : [];
|
|
713
|
-
const bundlesLines = bundleEntries.length ? [" bundles:", ...bundleEntries.map(e => [" - ", "".concat(chalk__default.default.yellow(e.source), " ").concat(chalk__default.default.gray("\u2192"), " ").concat(chalk__default.default.yellow(e.output))].join(""))] : [];
|
|
714
|
-
const entriesLines = entries.length ? [" entries:", ...entries.map(e => [" - ", "".concat(chalk__default.default.cyan(path__default.default.join(ctx.pkg.name, e.path)), ": "), "".concat(chalk__default.default.yellow(e.source), " ").concat(chalk__default.default.gray("\u2192"), " ").concat(chalk__default.default.yellow(e.output))].join(""))] : [];
|
|
715
|
-
return ["Build javascript files...", " format: ".concat(chalk__default.default.yellow(task.format)), ...targetLines, ...bundlesLines, ...entriesLines].join("\n");
|
|
716
|
-
},
|
|
717
|
-
exec: (ctx, task) => {
|
|
718
|
-
return new rxjs.Observable(observer => {
|
|
719
|
-
execPromise(ctx, task).then(result => {
|
|
720
|
-
observer.next(result);
|
|
721
|
-
observer.complete();
|
|
722
|
-
}).catch(err => observer.error(err));
|
|
723
|
-
});
|
|
724
|
-
},
|
|
725
|
-
complete: () => {},
|
|
726
|
-
error: (_ctx, _task, err) => {
|
|
727
|
-
console.error(err);
|
|
728
|
-
}
|
|
729
|
-
};
|
|
730
|
-
async function execPromise(ctx, task) {
|
|
731
|
-
const {
|
|
732
|
-
distPath,
|
|
733
|
-
files,
|
|
734
|
-
logger
|
|
735
|
-
} = ctx;
|
|
736
|
-
const outDir = path__default.default.relative(ctx.cwd, distPath);
|
|
737
|
-
const consoleSpy$1 = consoleSpy.createConsoleSpy({
|
|
738
|
-
onRestored: messages => {
|
|
739
|
-
for (const msg of messages) {
|
|
740
|
-
const text = String(msg.args[0]);
|
|
741
|
-
if (msg.code === "CIRCULAR_DEPENDENCY") {
|
|
742
|
-
continue;
|
|
743
|
-
}
|
|
744
|
-
if (text.startsWith("Dynamic import can only")) {
|
|
745
|
-
continue;
|
|
746
|
-
}
|
|
747
|
-
if (text.startsWith("Sourcemap is likely to be incorrect")) {
|
|
748
|
-
continue;
|
|
749
|
-
}
|
|
750
|
-
if (msg.type === "log") {
|
|
751
|
-
logger.info(...msg.args);
|
|
752
|
-
}
|
|
753
|
-
if (msg.type === "warn") {
|
|
754
|
-
logger.warn(...msg.args);
|
|
755
|
-
}
|
|
756
|
-
if (msg.type === "error") {
|
|
757
|
-
logger.error(...msg.args);
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
});
|
|
762
|
-
try {
|
|
763
|
-
const {
|
|
764
|
-
inputOptions,
|
|
765
|
-
outputOptions
|
|
766
|
-
} = resolveRollupConfig(ctx, task);
|
|
767
|
-
const bundle = await rollup.rollup({
|
|
768
|
-
...inputOptions,
|
|
769
|
-
onwarn(warning) {
|
|
770
|
-
var _a;
|
|
771
|
-
if (
|
|
772
|
-
// Ignore the directive warning until the preserveDirectives plugin does it automatically: https://github.com/Ephem/rollup-plugin-preserve-directives#rollup-plugin-preserve-directives-warning
|
|
773
|
-
warning.message.includes('Module level directives cause errors when bundled, "use client" in')) {
|
|
774
|
-
if (!((_a = ctx.config) == null ? void 0 : _a.preserveModuleDirectives)) {
|
|
775
|
-
consoleSpy$1.messages.push({
|
|
776
|
-
type: "warn",
|
|
777
|
-
code: warning.code,
|
|
778
|
-
args: ["".concat(warning.message, " You can preserve it by setting \"preserveModuleDirectives: true\" in your \"package.config.ts\"")]
|
|
779
|
-
});
|
|
780
|
-
}
|
|
781
|
-
return;
|
|
782
|
-
}
|
|
783
|
-
consoleSpy$1.messages.push({
|
|
784
|
-
type: "warn",
|
|
785
|
-
code: warning.code,
|
|
786
|
-
args: [warning.message]
|
|
787
|
-
});
|
|
788
|
-
}
|
|
789
|
-
});
|
|
790
|
-
const {
|
|
791
|
-
output
|
|
792
|
-
} = await bundle.generate(outputOptions);
|
|
793
|
-
for (const chunkOrAsset of output) {
|
|
794
|
-
if (chunkOrAsset.type === "asset") {
|
|
795
|
-
files.push({
|
|
796
|
-
type: "asset",
|
|
797
|
-
path: path__default.default.resolve(outDir, chunkOrAsset.fileName)
|
|
798
|
-
});
|
|
799
|
-
} else {
|
|
800
|
-
files.push({
|
|
801
|
-
type: "chunk",
|
|
802
|
-
path: path__default.default.resolve(outDir, chunkOrAsset.fileName)
|
|
803
|
-
});
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
await bundle.write(outputOptions);
|
|
807
|
-
await bundle.close();
|
|
808
|
-
consoleSpy$1.restore();
|
|
809
|
-
} catch (err) {
|
|
810
|
-
consoleSpy$1.restore();
|
|
811
|
-
throw err;
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
const rollupWatchTask = {
|
|
815
|
-
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 ")),
|
|
816
|
-
exec: (ctx, task) => {
|
|
817
|
-
const {
|
|
818
|
-
inputOptions,
|
|
819
|
-
outputOptions
|
|
820
|
-
} = resolveRollupConfig(ctx, task);
|
|
821
|
-
return new rxjs.Observable(observer => {
|
|
822
|
-
const watchOptions = {
|
|
823
|
-
...inputOptions,
|
|
824
|
-
output: outputOptions
|
|
825
|
-
};
|
|
826
|
-
const watcher = rollup.watch(watchOptions);
|
|
827
|
-
watcher.on("event", event => {
|
|
828
|
-
observer.next(event);
|
|
829
|
-
});
|
|
830
|
-
return () => {
|
|
831
|
-
watcher.close();
|
|
832
|
-
};
|
|
833
|
-
});
|
|
834
|
-
},
|
|
835
|
-
complete: (ctx, task, event) => {
|
|
836
|
-
const {
|
|
837
|
-
logger
|
|
838
|
-
} = ctx;
|
|
839
|
-
if (event.code === "BUNDLE_END") {
|
|
840
|
-
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 ")));
|
|
841
|
-
logger.log("");
|
|
842
|
-
return;
|
|
843
|
-
}
|
|
844
|
-
if (event.code === "BUNDLE_START") {
|
|
845
|
-
return;
|
|
846
|
-
}
|
|
847
|
-
if (event.code === "END") {
|
|
848
|
-
return;
|
|
849
|
-
}
|
|
850
|
-
if (event.code === "ERROR") {
|
|
851
|
-
logger.error(event.code, event);
|
|
852
|
-
return;
|
|
853
|
-
}
|
|
854
|
-
if (event.code === "START") {
|
|
855
|
-
return;
|
|
856
|
-
}
|
|
857
|
-
},
|
|
858
|
-
error: (ctx, _task, err) => {
|
|
859
|
-
const {
|
|
860
|
-
logger
|
|
861
|
-
} = ctx;
|
|
862
|
-
if (err instanceof Error) {
|
|
863
|
-
logger.log(err);
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
};
|
|
867
|
-
const buildTaskHandlers = {
|
|
868
|
-
"build:dts": dtsTask,
|
|
869
|
-
"build:js": rollupTask,
|
|
870
|
-
"node:reexport-cjs": nodeReexportCjsTask
|
|
871
|
-
};
|
|
872
|
-
const watchTaskHandlers = {
|
|
873
|
-
"watch:dts": dtsWatchTask,
|
|
874
|
-
"watch:js": rollupWatchTask
|
|
875
|
-
};
|
|
876
|
-
exports.buildTaskHandlers = buildTaskHandlers;
|
|
877
|
-
exports.dtsTask = dtsTask;
|
|
878
|
-
exports.dtsWatchTask = dtsWatchTask;
|
|
879
|
-
exports.getExtractMessagesConfig = getExtractMessagesConfig;
|
|
880
|
-
exports.rollupTask = rollupTask;
|
|
881
|
-
exports.rollupWatchTask = rollupWatchTask;
|
|
882
|
-
exports.watchTaskHandlers = watchTaskHandlers;
|
|
883
|
-
//# sourceMappingURL=index-bade3e43.cjs.map
|