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