@sanity/pkg-utils 5.1.0 → 5.1.1

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,535 @@
1
+ import type {ExtractorMessage} from '@microsoft/api-extractor'
2
+ import {IExtractorMessagesConfig} from '@microsoft/api-extractor'
3
+ import type {NormalizedOutputOptions} from 'rollup'
4
+ import {Observable} from 'rxjs'
5
+ import type {PluginItem} from '@babel/core'
6
+ import type {Plugin as RollupPlugin} from 'rollup'
7
+ import {RollupWatcherEvent} from 'rollup'
8
+ import type {TreeshakingOptions} from 'rollup'
9
+ import ts from 'typescript'
10
+
11
+ /**
12
+ * Build the distribution files of a npm package.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * import {build} from '@sanity/pkg-utils'
17
+ *
18
+ * build({
19
+ * cwd: process.cwd(),
20
+ * tsconfig: 'tsconfig.dist.json,
21
+ * }).then(() => {
22
+ * console.log('successfully built')
23
+ * }).catch((err) => {
24
+ * console.log(`build error: ${err.message}`)
25
+ * })
26
+ * ```
27
+ *
28
+ * @public
29
+ */
30
+ export declare function build(options: {
31
+ cwd: string
32
+ emitDeclarationOnly?: boolean
33
+ strict?: boolean
34
+ tsconfig?: string
35
+ }): Promise<void>
36
+
37
+ /** @internal */
38
+ export declare interface BuildContext {
39
+ config?: PkgConfigOptions
40
+ cwd: string
41
+ distPath: string
42
+ emitDeclarationOnly: boolean
43
+ exports: PkgExports | undefined
44
+ extMap: PkgExtMap
45
+ external: string[]
46
+ files: BuildFile[]
47
+ logger: Logger
48
+ pkg: PackageJSON
49
+ runtime: PkgRuntime
50
+ strict: boolean
51
+ target: Record<PkgRuntime, string[]>
52
+ ts: {
53
+ config?: ts.ParsedCommandLine
54
+ configPath?: string
55
+ }
56
+ }
57
+
58
+ /** @internal */
59
+ export declare interface BuildFile {
60
+ type: 'asset' | 'chunk' | 'types'
61
+ path: string
62
+ }
63
+
64
+ /** @internal */
65
+ export declare type BuildTask = DtsTask | RollupTask
66
+
67
+ /** @internal */
68
+ export declare interface BuildTaskHandlers {
69
+ 'build:dts': TaskHandler<DtsTask, DtsResult>
70
+ 'build:js': TaskHandler<RollupTask>
71
+ }
72
+
73
+ /** @internal */
74
+ export declare const buildTaskHandlers: BuildTaskHandlers
75
+
76
+ /** @public */
77
+ export declare function check(options: {
78
+ cwd: string
79
+ strict?: boolean
80
+ tsconfig?: string
81
+ }): Promise<void>
82
+
83
+ /** @internal */
84
+ export declare function createFromTemplate(options: {
85
+ cwd: string
86
+ logger: Logger
87
+ packagePath: string
88
+ template: PkgTemplate
89
+ }): Promise<void>
90
+
91
+ /** @internal */
92
+ export declare function createLogger(): Logger
93
+
94
+ /** @public */
95
+ export declare const DEFAULT_BROWSERSLIST_QUERY: string[]
96
+
97
+ /** @internal */
98
+ export declare const DEFAULT_PKG_EXT_MAP: PkgExtMap
99
+
100
+ /** @public */
101
+ export declare function defineConfig(configOptions: PkgConfigOptions): PkgConfigOptions
102
+
103
+ /** @public */
104
+ export declare function defineTemplateOption<T>(option: PkgTemplateOption<T>): PkgTemplateOption<T>
105
+
106
+ /** @internal */
107
+ export declare interface DtsResult {
108
+ type: 'dts'
109
+ messages: ExtractorMessage[]
110
+ results: {
111
+ sourcePath: string
112
+ filePaths: string[]
113
+ }[]
114
+ }
115
+
116
+ /** @internal */
117
+ export declare interface DtsTask {
118
+ type: 'build:dts'
119
+ entries: {
120
+ exportPath: string
121
+ importId: string
122
+ sourcePath: string
123
+ targetPaths: string[]
124
+ }[]
125
+ }
126
+
127
+ /** @internal */
128
+ export declare const dtsTask: TaskHandler<DtsTask, DtsResult>
129
+
130
+ /** @internal */
131
+ export declare interface DtsWatchTask {
132
+ type: 'watch:dts'
133
+ entries: {
134
+ exportPath: string
135
+ importId: string
136
+ sourcePath: string
137
+ targetPaths: string[]
138
+ }[]
139
+ }
140
+
141
+ /** @internal */
142
+ export declare const dtsWatchTask: TaskHandler<DtsWatchTask, DtsResult>
143
+
144
+ /** @internal */
145
+ export declare function getExtractMessagesConfig(options: {
146
+ rules: NonNullable<PkgConfigOptions['extract']>['rules']
147
+ }): IExtractorMessagesConfig
148
+
149
+ /** @internal */
150
+ export declare function getPkgExtMap(options: {legacyExports: boolean}): PkgExtMap
151
+
152
+ /** @public */
153
+ export declare function init(options: {cwd: string; path: string}): Promise<void>
154
+
155
+ /** @internal */
156
+ export declare function isRecord(value: unknown): value is Record<string, unknown>
157
+
158
+ /** @internal */
159
+ export declare function loadConfig(options: {cwd: string}): Promise<PkgConfigOptions | undefined>
160
+
161
+ /** @internal */
162
+ export declare function loadPkg(options: {cwd: string}): Promise<PackageJSON>
163
+
164
+ /** @internal */
165
+ export declare function loadPkgWithReporting(options: {
166
+ cwd: string
167
+ logger: Logger
168
+ }): Promise<PackageJSON>
169
+
170
+ /** @internal */
171
+ export declare function loadTSConfig(options: {
172
+ cwd: string
173
+ tsconfigPath: string
174
+ }): Promise<ts.ParsedCommandLine | undefined>
175
+
176
+ /** @internal */
177
+ export declare interface Logger {
178
+ log: (...args: unknown[]) => void
179
+ info: (...args: unknown[]) => void
180
+ warn: (...args: unknown[]) => void
181
+ error: (...args: unknown[]) => void
182
+ success: (...args: unknown[]) => void
183
+ }
184
+
185
+ /** @internal */
186
+ export declare interface PackageJSON {
187
+ type?: 'commonjs' | 'module'
188
+ version: string
189
+ private?: boolean
190
+ author?:
191
+ | string
192
+ | {
193
+ name: string
194
+ email?: string
195
+ url?: string
196
+ }
197
+ name: string
198
+ description?: string
199
+ keywords?: string[]
200
+ bin?: Record<string, string>
201
+ dependencies?: Record<string, string | undefined>
202
+ devDependencies?: Record<string, string | undefined>
203
+ peerDependencies?: Record<string, string | undefined>
204
+ exports?: Record<
205
+ string,
206
+ | `./${string}.json`
207
+ | {
208
+ source: string
209
+ types?: string
210
+ browser?: {
211
+ source: string
212
+ import?: string
213
+ require?: string
214
+ }
215
+ node?: {
216
+ source?: string
217
+ module?: string
218
+ import?: string
219
+ require?: string
220
+ }
221
+ module?: string
222
+ import?: string
223
+ require?: string
224
+ default: string
225
+ }
226
+ | {
227
+ types?: string
228
+ svelte: string
229
+ default?: string
230
+ }
231
+ >
232
+ main?: string
233
+ browser?: Record<string, string>
234
+ source?: string
235
+ module?: string
236
+ types?: string
237
+ files?: string[]
238
+ scripts?: Record<string, string | undefined>
239
+ browserslist?: string | string[]
240
+ sideEffects?: boolean | string[]
241
+ engines?: {
242
+ node?: string
243
+ npm?: string
244
+ }
245
+ repository?:
246
+ | string
247
+ | {
248
+ type: 'git'
249
+ url: string
250
+ }
251
+ bugs?:
252
+ | string
253
+ | {
254
+ url: string
255
+ email?: string
256
+ }
257
+ homepage?: string
258
+ license?: string
259
+ }
260
+
261
+ /** @internal */
262
+ export declare function parseExports(options: {
263
+ extMap: PkgExtMap
264
+ pkg: PackageJSON
265
+ strict: boolean
266
+ }): (PkgExport & {
267
+ _path: string
268
+ })[]
269
+
270
+ /** @public */
271
+ export declare interface PkgBundle {
272
+ source: string
273
+ import?: string
274
+ require?: string
275
+ runtime?: PkgRuntime
276
+ }
277
+
278
+ /** @public */
279
+ export declare interface PkgConfigOptions {
280
+ /** @alpha */
281
+ babel?: {
282
+ plugins?: PluginItem[] | null | undefined
283
+ }
284
+ bundles?: PkgBundle[]
285
+ /** @alpha */
286
+ define?: Record<string, string | number | boolean | undefined | null>
287
+ /**
288
+ * Directory of distributed & bundled files.
289
+ */
290
+ dist?: string
291
+ exports?: PkgConfigProperty<PkgExports>
292
+ extract?: {
293
+ bundledPackages?: string[]
294
+ customTags?: TSDocCustomTag[]
295
+ rules?: {
296
+ 'ae-forgotten-export'?: PkgRuleLevel
297
+ 'ae-incompatible-release-tags'?: PkgRuleLevel
298
+ 'ae-internal-missing-underscore'?: PkgRuleLevel
299
+ 'ae-missing-release-tag'?: PkgRuleLevel
300
+ 'tsdoc-link-tag-unescaped-text'?: PkgRuleLevel
301
+ 'tsdoc-undefined-tag'?: PkgRuleLevel
302
+ 'tsdoc-unsupported-tag'?: PkgRuleLevel
303
+ }
304
+ }
305
+ /**
306
+ * Packages to exclude from bundles.
307
+ */
308
+ external?: PkgConfigProperty<string[]>
309
+ /**
310
+ * Defaults to `"automatic"`
311
+ */
312
+ jsx?: 'transform' | 'preserve' | 'automatic'
313
+ /**
314
+ * Defaults to `"createElement"`
315
+ */
316
+ jsxFactory?: string
317
+ /**
318
+ * Defaults to `"Fragment"`
319
+ */
320
+ jsxFragment?: string
321
+ /**
322
+ * Defaults to `"react"`
323
+ */
324
+ jsxImportSource?: string
325
+ /**
326
+ * Build package with support for legacy exports (writes root `<export>.js` files)
327
+ */
328
+ legacyExports?: boolean
329
+ minify?: boolean
330
+ /** @alpha */
331
+ rollup?: {
332
+ plugins?: PkgConfigProperty<RollupPlugin[]>
333
+ output?: Partial<NormalizedOutputOptions>
334
+ /**
335
+ * Default options are `preset: 'recommended'` and `propertyReadSideEffects: false`
336
+ * @alpha
337
+ */
338
+ treeshake?: TreeshakingOptions
339
+ /** @alpha */
340
+ experimentalLogSideEffects?: boolean
341
+ /**
342
+ * Adds [hash] to chunk filenames, generally only useful if `@sanity/pkg-utils` is used to deploy a package directly to a CDN.
343
+ * It's not needed when publishing to npm for consumption by other libraries, bundlers and frameworks.
344
+ * @defaultValue false
345
+ */
346
+ hashChunkFileNames?: boolean
347
+ }
348
+ /**
349
+ * Default runtime of package exports
350
+ */
351
+ runtime?: PkgRuntime
352
+ sourcemap?: boolean
353
+ /**
354
+ * Directory of source files.
355
+ */
356
+ src?: string
357
+ tsconfig?: string
358
+ }
359
+
360
+ /** @public */
361
+ export declare type PkgConfigProperty<T> = PkgConfigPropertyResolver<T> | T
362
+
363
+ /** @public */
364
+ export declare type PkgConfigPropertyResolver<T> = (prev: T) => T
365
+
366
+ /** @public */
367
+ export declare interface PkgExport {
368
+ /** @internal */
369
+ _exported?: boolean
370
+ browser?: {
371
+ source: string
372
+ import?: string
373
+ require?: string
374
+ }
375
+ node?: {
376
+ source?: string
377
+ import?: string
378
+ require?: string
379
+ }
380
+ types?: string
381
+ source: string
382
+ import?: string
383
+ require?: string
384
+ default: string
385
+ }
386
+
387
+ /** @public */
388
+ export declare interface PkgExports {
389
+ [path: string]: PkgExport
390
+ }
391
+
392
+ /** @internal */
393
+ export declare interface PkgExtMap {
394
+ commonjs: {
395
+ commonjs: string
396
+ esm: string
397
+ }
398
+ module: {
399
+ commonjs: string
400
+ esm: string
401
+ }
402
+ }
403
+
404
+ /** @public */
405
+ export declare type PkgFormat = 'commonjs' | 'esm'
406
+
407
+ /** @public */
408
+ export declare type PkgRuleLevel = 'error' | 'warn' | 'info' | 'off'
409
+
410
+ /** @public */
411
+ export declare type PkgRuntime = '*' | 'browser' | 'node'
412
+
413
+ /** @public */
414
+ export declare type PkgTemplate = PkgTemplateDefinition | PkgTemplateResolver
415
+
416
+ /** @public */
417
+ export declare interface PkgTemplateDefinition {
418
+ options: PkgTemplateStringOption<any>[]
419
+ features: {
420
+ name: string
421
+ optional: boolean
422
+ initial: boolean
423
+ }[]
424
+ getFiles: (
425
+ options: Record<string, any>,
426
+ features: Record<string, boolean>,
427
+ ) => Promise<PkgTemplateFile[]>
428
+ }
429
+
430
+ /** @public */
431
+ export declare interface PkgTemplateFile {
432
+ name: string
433
+ contents: string
434
+ }
435
+
436
+ /** @public */
437
+ export declare type PkgTemplateOption<T = string> = PkgTemplateStringOption<T>
438
+
439
+ /** @public */
440
+ export declare type PkgTemplateResolver = (options: {
441
+ cwd: string
442
+ /** @internal */
443
+ logger: Logger
444
+ packagePath: string
445
+ }) => PkgTemplateDefinition | Promise<PkgTemplateDefinition>
446
+
447
+ /** @public */
448
+ export declare interface PkgTemplateStringOption<T = string> {
449
+ name: string
450
+ type: 'string'
451
+ description: string
452
+ initial?: T | ((options: Record<string, any>) => T)
453
+ parse?: (v: string) => T | null
454
+ validate?: (v: string) => string | true
455
+ }
456
+
457
+ /** @internal */
458
+ export declare function resolveBuildTasks(ctx: BuildContext): BuildTask[]
459
+
460
+ /** @internal */
461
+ export declare function resolveConfigProperty<T>(
462
+ prop: PkgConfigProperty<T> | undefined,
463
+ initialValue: T,
464
+ ): T
465
+
466
+ export {RollupPlugin}
467
+
468
+ /** @internal */
469
+ export declare interface RollupTask {
470
+ type: 'build:js'
471
+ buildId: string
472
+ entries: RollupTaskEntry[]
473
+ runtime: PkgRuntime
474
+ format: 'commonjs' | 'esm'
475
+ target: string[]
476
+ }
477
+
478
+ /** @internal */
479
+ export declare const rollupTask: TaskHandler<RollupTask>
480
+
481
+ /** @internal */
482
+ export declare interface RollupTaskEntry {
483
+ path: string
484
+ source: string
485
+ output: string
486
+ }
487
+
488
+ /** @internal */
489
+ export declare interface RollupWatchTask {
490
+ type: 'watch:js'
491
+ buildId: string
492
+ entries: RollupTaskEntry[]
493
+ runtime: PkgRuntime
494
+ format: 'commonjs' | 'esm'
495
+ target: string[]
496
+ }
497
+
498
+ /** @internal */
499
+ export declare const rollupWatchTask: TaskHandler<RollupWatchTask, RollupWatcherEvent>
500
+
501
+ /** @internal */
502
+ export declare type TaskHandler<Task, Result = void> = {
503
+ name: (ctx: BuildContext, task: Task) => string
504
+ exec: (ctx: BuildContext, task: Task) => Observable<Result>
505
+ complete: (ctx: BuildContext, task: Task, result: Result) => void
506
+ error: (ctx: BuildContext, task: Task, error: unknown) => void
507
+ }
508
+
509
+ /** @public */
510
+ export declare interface TSDocCustomTag {
511
+ name: string
512
+ syntaxKind: 'block' | 'modifier'
513
+ allowMultiple?: boolean
514
+ }
515
+
516
+ /** @public */
517
+ export declare function watch(options: {
518
+ cwd: string
519
+ strict?: boolean
520
+ tsconfig?: string
521
+ }): Promise<void>
522
+
523
+ /** @internal */
524
+ export declare type WatchTask = DtsWatchTask | RollupWatchTask
525
+
526
+ /** @internal */
527
+ export declare interface WatchTaskHandlers {
528
+ 'watch:dts': TaskHandler<DtsWatchTask, DtsResult>
529
+ 'watch:js': TaskHandler<RollupWatchTask, RollupWatcherEvent>
530
+ }
531
+
532
+ /** @internal */
533
+ export declare const watchTaskHandlers: WatchTaskHandlers
534
+
535
+ export {}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import {ExtractorMessage} from '@microsoft/api-extractor'
1
+ import type {ExtractorMessage} from '@microsoft/api-extractor'
2
2
  import {IExtractorMessagesConfig} from '@microsoft/api-extractor'
3
3
  import type {NormalizedOutputOptions} from 'rollup'
4
4
  import {Observable} from 'rxjs'
@@ -109,7 +109,7 @@ export declare interface DtsResult {
109
109
  messages: ExtractorMessage[]
110
110
  results: {
111
111
  sourcePath: string
112
- filePath: string
112
+ filePaths: string[]
113
113
  }[]
114
114
  }
115
115
 
@@ -120,7 +120,7 @@ export declare interface DtsTask {
120
120
  exportPath: string
121
121
  importId: string
122
122
  sourcePath: string
123
- targetPath: string
123
+ targetPaths: string[]
124
124
  }[]
125
125
  }
126
126
 
@@ -134,7 +134,7 @@ export declare interface DtsWatchTask {
134
134
  exportPath: string
135
135
  importId: string
136
136
  sourcePath: string
137
- targetPath: string
137
+ targetPaths: string[]
138
138
  }[]
139
139
  }
140
140