@sanity/pkg-utils 7.11.8 → 8.0.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/index.d.cts DELETED
@@ -1,534 +0,0 @@
1
- import { PluginItem } from "@babel/core";
2
- import { OptimizeLodashOptions } from "@optimize-lodash/rollup-plugin";
3
- import { Options } from "@vanilla-extract/rollup-plugin";
4
- import { NormalizedOutputOptions, Plugin, Plugin as RollupPlugin, TreeshakingOptions } from "rollup";
5
- import { IExtractorMessagesConfig } from "@microsoft/api-extractor";
6
- /**
7
- * Build the distribution files of a npm package.
8
- *
9
- * @example
10
- * ```ts
11
- * import {build} from '@sanity/pkg-utils'
12
- *
13
- * build({
14
- * cwd: process.cwd(),
15
- * tsconfig: 'tsconfig.dist.json,
16
- * }).then(() => {
17
- * console.log('successfully built')
18
- * }).catch((err) => {
19
- * console.log(`build error: ${err.message}`)
20
- * })
21
- * ```
22
- *
23
- * @public
24
- */
25
- declare function build(options: {
26
- cwd: string;
27
- emitDeclarationOnly?: boolean;
28
- strict?: boolean;
29
- tsconfig?: string;
30
- clean?: boolean;
31
- quiet?: boolean;
32
- }): Promise<void>;
33
- /** @public */
34
- declare function check(options: {
35
- cwd: string;
36
- strict?: boolean;
37
- tsconfig?: string;
38
- }): Promise<void>;
39
- type ToggleType = 'error' | 'warn' | 'off';
40
- /**
41
- * @public
42
- */
43
- interface StrictOptions {
44
- /**
45
- * Disallows a top level `typings` field in `package.json` if it is equal to `exports['.'].source`.
46
- * @defaultValue 'error'
47
- */
48
- noPackageJsonTypings: ToggleType;
49
- /**
50
- * Requires specifying `sideEffects` in `package.json`.
51
- * @defaultValue 'warn'
52
- */
53
- noImplicitSideEffects: ToggleType;
54
- /**
55
- * Requires specifying `browserslist` in `package.json`, instead of relying on it implicitly being:
56
- * @example
57
- * ```
58
- * "browserslist": "extends @sanity/browserslist-config"
59
- * ```
60
- * @defaultValue 'warn'
61
- */
62
- noImplicitBrowsersList: ToggleType;
63
- /**
64
- * If typescript is used then `types` in `package.json` should be specified for npm listings to show the TS icon.
65
- * @defaultValue 'error'
66
- */
67
- alwaysPackageJsonTypes: ToggleType;
68
- /**
69
- * A lot of analysis tooling requiers the `main` field to work (like bundlephobia) and so it's best practice to always include it
70
- * @defaultValue 'error'
71
- */
72
- alwaysPackageJsonMain: ToggleType;
73
- /**
74
- * Using `.npmignore` is error prone, it's best practice to always declare `files` instead
75
- * @defaultValue 'error'
76
- */
77
- alwaysPackageJsonFiles: ToggleType;
78
- /**
79
- * It's slow to perform type checking while generating dts files, so it's best practice to disable it with a `"noCheck": true` in the tsconfig.json file used by `package.config.ts`
80
- * @defaultValue 'warn'
81
- */
82
- noCheckTypes: ToggleType;
83
- }
84
- /** @alpha */
85
- declare function parseStrictOptions(input: unknown): StrictOptions;
86
- /** @public */
87
- type PkgFormat = 'commonjs' | 'esm';
88
- /** @public */
89
- type PkgRuntime = '*' | 'browser' | 'node';
90
- /** @public */
91
- interface PkgExport {
92
- /** @internal */
93
- _exported?: boolean;
94
- browser?: {
95
- source: string;
96
- import?: string;
97
- require?: string;
98
- };
99
- // electron?: {
100
- // node?: string
101
- // default?: string
102
- // }
103
- node?: {
104
- source?: string;
105
- import?: string;
106
- require?: string;
107
- };
108
- types?: string;
109
- source: string;
110
- import?: string;
111
- require?: string;
112
- default: string;
113
- }
114
- /** @public */
115
- type PkgConfigPropertyResolver<T> = (prev: T) => T;
116
- /** @public */
117
- type PkgConfigProperty<T> = PkgConfigPropertyResolver<T> | T;
118
- /** @public */
119
- interface PkgBundle {
120
- source: string;
121
- import?: string;
122
- require?: string;
123
- runtime?: PkgRuntime;
124
- }
125
- /** @public */
126
- interface PkgExports {
127
- [path: string]: PkgExport;
128
- }
129
- /** @public */
130
- type PkgRuleLevel = 'error' | 'warn' | 'info' | 'off';
131
- /** @public */
132
- interface TSDocCustomTag {
133
- name: string;
134
- syntaxKind: 'block' | 'modifier';
135
- allowMultiple?: boolean;
136
- }
137
- /**
138
- * Until these types are on npm: https://github.com/facebook/react/blob/0bc30748730063e561d87a24a4617526fdd38349/compiler/packages/babel-plugin-react-compiler/src/Entrypoint/Options.ts#L39-L122
139
- * @alpha
140
- */
141
- interface ReactCompilerOptions {
142
- logger?: ReactCompilerLogger | null;
143
- panicThreshold?: 'ALL_ERRORS' | 'CRITICAL_ERRORS' | 'NONE';
144
- compilationMode?: 'infer' | 'syntax' | 'annotation' | 'all';
145
- /*
146
- * If enabled, Forget will import `useMemoCache` from the given module
147
- * instead of `react/compiler-runtime`.
148
- *
149
- * ```
150
- * // If set to "react-compiler-runtime"
151
- * import {c as useMemoCache} from 'react-compiler-runtime';
152
- * ```
153
- */
154
- runtimeModule?: string | null | undefined;
155
- /**
156
- * By default React Compiler will skip compilation of code that suppresses the default
157
- * React ESLint rules, since this is a strong indication that the code may be breaking React rules
158
- * in some way.
159
- *
160
- * Use eslintSuppressionRules to pass a custom set of rule names: any code which suppresses the
161
- * provided rules will skip compilation. To disable this feature (never bailout of compilation
162
- * even if the default ESLint is suppressed), pass an empty array.
163
- */
164
- eslintSuppressionRules?: Array<string> | null | undefined;
165
- sources?: Array<string> | ((filename: string) => boolean) | null;
166
- /**
167
- * The minimum major version of React that the compiler should emit code for. If the target is 19
168
- * or higher, the compiler emits direct imports of React runtime APIs needed by the compiler. On
169
- * versions prior to 19, an extra runtime package react-compiler-runtime is necessary to provide
170
- * a userspace approximation of runtime APIs.
171
- */
172
- target: '17' | '18' | '19';
173
- }
174
- /**
175
- * @alpha
176
- * Represents 'events' that may occur during compilation. Events are only
177
- * recorded when a logger is set (through the config).
178
- * These are the different types of events:
179
- * CompileError:
180
- * Forget skipped compilation of a function / file due to a known todo,
181
- * invalid input, or compiler invariant being broken.
182
- * CompileSuccess:
183
- * Forget successfully compiled a function.
184
- * PipelineError:
185
- * Unexpected errors that occurred during compilation (e.g. failures in
186
- * babel or other unhandled exceptions).
187
- */
188
- type ReactCompilerLoggerEvent = {
189
- kind: 'CompileError';
190
- fnLoc: unknown;
191
- detail: unknown;
192
- } | {
193
- kind: 'CompileDiagnostic';
194
- fnLoc: unknown;
195
- detail: unknown;
196
- } | {
197
- kind: 'CompileSuccess';
198
- fnLoc: unknown;
199
- fnName: string | null;
200
- memoSlots: number;
201
- memoBlocks: number;
202
- memoValues: number;
203
- prunedMemoBlocks: number;
204
- prunedMemoValues: number;
205
- } | {
206
- kind: 'PipelineError';
207
- fnLoc: unknown;
208
- data: string;
209
- };
210
- /**
211
- * @alpha
212
- */
213
- type ReactCompilerLogger = {
214
- logEvent: (filename: string | null, event: ReactCompilerLoggerEvent) => void;
215
- };
216
- type DtsType = 'api-extractor' | 'rolldown';
217
- /** @public */
218
- interface PkgConfigOptions {
219
- /** @alpha */
220
- babel?: {
221
- plugins?: PluginItem[] | null | undefined;
222
- /** @alpha */
223
- reactCompiler?: boolean;
224
- /** @alpha */
225
- styledComponents?: boolean | {
226
- /** @defaultValue true */
227
- displayName?: boolean;
228
- /**
229
- * @defaultValue []
230
- * @example ["\@xstyled/styled-components", "\@xstyled/styled-components/*"]
231
- */
232
- topLevelImportPaths?: string[];
233
- /** @defaultValue true */
234
- ssr?: boolean;
235
- /** @defaultValue fale */
236
- fileName?: boolean;
237
- /** @defaultValue ["index"] */
238
- meaninglessFileNames?: string[];
239
- /** @defaultValue true */
240
- minify?: boolean;
241
- /** @defaultValue false */
242
- transpileTemplateLiterals?: boolean;
243
- namespace?: string;
244
- /** @defaultValue true */
245
- pure?: boolean;
246
- };
247
- };
248
- /**
249
- * Configure the React Compiler.
250
- * To enable it, either:
251
- * - set `babel.reactCompiler` to `true`
252
- * - add a `react-compiler` export condition, before any `browser`, `require` or `import` conditions. After any `react-server` and `node` conditions
253
- * @alpha */
254
- reactCompilerOptions?: ReactCompilerOptions;
255
- bundles?: PkgBundle[];
256
- /** @alpha */
257
- define?: Record<string, string | number | boolean | undefined | null>;
258
- /**
259
- * Directory of distributed & bundled files.
260
- */
261
- dist?: string;
262
- exports?: PkgConfigProperty<PkgExports>;
263
- /**
264
- * Runs `@microsoft/api-extractor` to check that TSDoc tags are valid, and release tags are correct.
265
- * This is useful for packages that need to be consumed by TSDoc-based tooling.
266
- * It's enabled by default, it can be disabled by setting `extract: {enabled: false}`
267
- */
268
- extract?: {
269
- /**
270
- * @defaultValue true
271
- */
272
- enabled?: boolean;
273
- /**
274
- * Packages in `devDependencies` that are not in `external` are automatically added to the `bundledPackages` config.
275
- * You can exclude a package from being bundled by using a callback:
276
- * ```
277
- * bundledPackages: (prev) => prev.filter(package => package !== 'sanity')
278
- * ```
279
- */
280
- bundledPackages?: PkgConfigProperty<string[]>;
281
- customTags?: TSDocCustomTag[];
282
- rules?: {
283
- /**
284
- * @deprecated as it's no longer needed since TypeScript 5.5 https://github.com/microsoft/TypeScript/issues/42873
285
- */
286
- 'ae-forgotten-export'?: never;
287
- 'ae-incompatible-release-tags'?: PkgRuleLevel;
288
- 'ae-internal-missing-underscore'?: PkgRuleLevel;
289
- 'ae-missing-release-tag'?: PkgRuleLevel;
290
- 'tsdoc-link-tag-unescaped-text'?: PkgRuleLevel;
291
- 'tsdoc-undefined-tag'?: PkgRuleLevel;
292
- 'tsdoc-unsupported-tag'?: PkgRuleLevel;
293
- };
294
- };
295
- /**
296
- * Packages to exclude from bundles.
297
- * Provide an array to merge with default exclusions, use a function to replace them:
298
- * ```
299
- * exclude: (prev) => prev.filter(package => package !== 'foo')
300
- * ```
301
- */
302
- external?: PkgConfigProperty<string[]>;
303
- /**
304
- * Defaults to `"automatic"`
305
- */
306
- jsx?: 'transform' | 'preserve' | 'automatic';
307
- /**
308
- * Defaults to `"createElement"`
309
- */
310
- jsxFactory?: string;
311
- /**
312
- * Defaults to `"Fragment"`
313
- */
314
- jsxFragment?: string;
315
- /**
316
- * Defaults to `"react"`
317
- */
318
- jsxImportSource?: string;
319
- /**
320
- * @deprecated no longer supported
321
- */
322
- legacyExports?: never;
323
- minify?: boolean;
324
- /** @alpha */
325
- rollup?: {
326
- plugins?: PkgConfigProperty<Plugin[]>;
327
- output?: Partial<NormalizedOutputOptions>;
328
- /**
329
- * Default options are `preset: 'recommended'` and `propertyReadSideEffects: false`
330
- * @alpha
331
- */
332
- treeshake?: TreeshakingOptions;
333
- /** @alpha */
334
- experimentalLogSideEffects?: boolean;
335
- /**
336
- * Adds [hash] to chunk filenames, generally only useful if `@sanity/pkg-utils` is used to deploy a package directly to a CDN.
337
- * It's not needed when publishing to npm for consumption by other libraries, bundlers and frameworks.
338
- * @defaultValue false
339
- */
340
- hashChunkFileNames?: boolean;
341
- /**
342
- * Optimizes lodash imports using `@optimize-lodash/rollup-plugin` when set to `true`.
343
- * It's enabled if `lodash` is found in `dependencies` or `peerDependencies`.
344
- * It will use `lodash-es` for ESM targets if found in `dependencies` or `peerDependencies`.
345
- * @defaultValue true
346
- * @alpha
347
- */
348
- optimizeLodash?: boolean | OptimizeLodashOptions;
349
- /**
350
- * Enables \@vanilla-extract/rollup-plugin to extract CSS into a separate file, with support for minifying the extracted CSS.
351
- * @alpha
352
- */
353
- vanillaExtract?: boolean | (Options & {
354
- minify?: boolean;
355
- browserslist?: string | string[];
356
- });
357
- };
358
- /**
359
- * Default runtime of package exports
360
- */
361
- runtime?: PkgRuntime;
362
- sourcemap?: boolean;
363
- /**
364
- * Directory of source files.
365
- */
366
- src?: string;
367
- tsconfig?: string;
368
- /**
369
- * Configure what checks are made when running `--strict` builds and checks
370
- */
371
- strictOptions?: Partial<StrictOptions>;
372
- /**
373
- * .d.ts files can be generated either by using `@microsoft/api-extractor` or `rolldown`.
374
- * `rolldown` is the faster option, but is not yet stable.
375
- * @defaultValue 'api-extractor'
376
- */
377
- dts?: DtsType;
378
- }
379
- /** @public */
380
- declare function defineConfig<const T extends PkgConfigOptions>(configOptions: T): T;
381
- /** @alpha */
382
- declare function loadConfig(options: {
383
- cwd: string;
384
- }): Promise<PkgConfigOptions | undefined>;
385
- /** @public */
386
- declare const DEFAULT_BROWSERSLIST_QUERY: string[];
387
- /** @alpha */
388
- interface PackageJSON {
389
- type?: 'commonjs' | 'module' | undefined;
390
- version: string;
391
- private?: boolean;
392
- author?: string | {
393
- name: string;
394
- email?: string;
395
- url?: string;
396
- };
397
- name: string;
398
- description?: string;
399
- keywords?: string[];
400
- bin?: Record<string, string>;
401
- dependencies?: Record<string, string | undefined>;
402
- devDependencies?: Record<string, string | undefined>;
403
- peerDependencies?: Record<string, string | undefined>;
404
- exports?: Record<string, `./${string}.json` | `./${string}.css` | {
405
- source?: string;
406
- types?: string;
407
- browser?: {
408
- source: string;
409
- import?: string;
410
- require?: string;
411
- };
412
- node?: {
413
- source?: string;
414
- module?: string;
415
- import?: string;
416
- require?: string;
417
- };
418
- module?: string;
419
- import?: string;
420
- require?: string;
421
- default: string;
422
- } | {
423
- types?: string;
424
- svelte: string;
425
- default?: string;
426
- }>;
427
- main?: string;
428
- browser?: Record<string, string>;
429
- source?: string;
430
- module?: string;
431
- types?: string;
432
- files?: string[];
433
- scripts?: Record<string, string | undefined>;
434
- browserslist?: string | string[];
435
- sideEffects?: boolean | string[];
436
- engines?: {
437
- node?: string;
438
- npm?: string;
439
- };
440
- repository?: string | {
441
- type: 'git';
442
- url: string;
443
- };
444
- bugs?: string | {
445
- url: string;
446
- email?: string;
447
- };
448
- homepage?: string;
449
- license?: string;
450
- }
451
- /** @internal */
452
- declare function loadPkg(options: {
453
- cwd: string;
454
- }): Promise<PackageJSON>;
455
- /** @alpha */
456
- interface Logger {
457
- log: (...args: unknown[]) => void;
458
- info: (...args: unknown[]) => void;
459
- warn: (...args: unknown[]) => void;
460
- error: (...args: unknown[]) => void;
461
- success: (...args: unknown[]) => void;
462
- }
463
- /** @alpha */
464
- declare function createLogger(quiet?: boolean): Logger;
465
- /** @alpha */
466
- declare function loadPkgWithReporting(options: {
467
- cwd: string;
468
- logger: Logger;
469
- strict: boolean;
470
- }): Promise<PackageJSON>;
471
- /** @alpha */
472
- declare function parseExports(options: {
473
- cwd: string;
474
- pkg: PackageJSON;
475
- strict: boolean;
476
- strictOptions: StrictOptions;
477
- logger: Logger;
478
- }): (PkgExport & {
479
- _path: string;
480
- })[];
481
- /** @public */
482
- interface PkgTemplateFile {
483
- name: string;
484
- contents: string;
485
- }
486
- /** @public */
487
- interface PkgTemplateStringOption<T = string> {
488
- name: string;
489
- type: 'string';
490
- description: string;
491
- initial?: T | ((options: Record<string, any>) => T);
492
- parse?: (v: string) => T | null;
493
- validate?: (v: string) => string | true;
494
- }
495
- /** @public */
496
- type PkgTemplateOption<T = string> = PkgTemplateStringOption<T>;
497
- /** @public */
498
- interface PkgTemplateDefinition {
499
- options: PkgTemplateStringOption<any>[];
500
- features: {
501
- name: string;
502
- optional: boolean;
503
- initial: boolean;
504
- }[];
505
- getFiles: (options: Record<string, any>, features: Record<string, boolean>) => Promise<PkgTemplateFile[]>;
506
- }
507
- /** @public */
508
- type PkgTemplateResolver = (options: {
509
- cwd: string;
510
- /** @internal */
511
- logger: Logger;
512
- packagePath: string;
513
- }) => PkgTemplateDefinition | Promise<PkgTemplateDefinition>;
514
- /** @public */
515
- type PkgTemplate = PkgTemplateDefinition | PkgTemplateResolver;
516
- /** @public */
517
- declare function defineTemplateOption<T>(option: PkgTemplateOption<T>): PkgTemplateOption<T>;
518
- /** @public */
519
- declare function init(options: {
520
- cwd: string;
521
- path: string;
522
- }): Promise<void>;
523
- /** @alpha */
524
- declare function getExtractMessagesConfig(options: {
525
- rules: NonNullable<PkgConfigOptions['extract']>['rules'];
526
- disabled?: boolean;
527
- }): IExtractorMessagesConfig;
528
- /** @public */
529
- declare function watch(options: {
530
- cwd: string;
531
- strict?: boolean;
532
- tsconfig?: string;
533
- }): Promise<void>;
534
- export { DEFAULT_BROWSERSLIST_QUERY, PackageJSON, type PkgBundle, type PkgConfigOptions, type PkgConfigProperty, type PkgConfigPropertyResolver, type PkgExport, type PkgExports, type PkgFormat, type PkgRuleLevel, type PkgRuntime, type PkgTemplate, type PkgTemplateDefinition, type PkgTemplateFile, type PkgTemplateOption, type PkgTemplateResolver, type PkgTemplateStringOption, type ReactCompilerLogger, type ReactCompilerLoggerEvent, type ReactCompilerOptions, type RollupPlugin, type TSDocCustomTag, build, check, createLogger, defineConfig, defineTemplateOption, getExtractMessagesConfig, init, loadConfig, loadPkg, loadPkgWithReporting, parseExports, parseStrictOptions, watch };