@sanity/pkg-utils 9.2.3 → 10.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/_chunks-es/buildAction.js +147 -2
- package/dist/_chunks-es/buildAction.js.map +1 -1
- package/dist/_chunks-es/checkAction.js +179 -2
- package/dist/_chunks-es/checkAction.js.map +1 -1
- package/dist/_chunks-es/createApiExtractorConfig.js +52 -0
- package/dist/_chunks-es/createApiExtractorConfig.js.map +1 -0
- package/dist/_chunks-es/createTSDocConfig.js +31 -0
- package/dist/_chunks-es/createTSDocConfig.js.map +1 -0
- package/dist/_chunks-es/defaults.js +39 -0
- package/dist/_chunks-es/defaults.js.map +1 -0
- package/dist/_chunks-es/define.js +7 -0
- package/dist/_chunks-es/define.js.map +1 -0
- package/dist/_chunks-es/fileExists.js +12 -0
- package/dist/_chunks-es/fileExists.js.map +1 -0
- package/dist/_chunks-es/getExtractMessagesConfig.js +83 -0
- package/dist/_chunks-es/getExtractMessagesConfig.js.map +1 -0
- package/dist/_chunks-es/handleError.js +25 -1
- package/dist/_chunks-es/handleError.js.map +1 -1
- package/dist/_chunks-es/index.js +8 -212
- package/dist/_chunks-es/index.js.map +1 -1
- package/dist/_chunks-es/initAction.js +515 -2
- package/dist/_chunks-es/initAction.js.map +1 -1
- package/dist/_chunks-es/printExtractMessages.js +44 -0
- package/dist/_chunks-es/printExtractMessages.js.map +1 -0
- package/dist/_chunks-es/{consoleSpy.js → resolveBuildContext.js} +68 -95
- package/dist/_chunks-es/resolveBuildContext.js.map +1 -0
- package/dist/_chunks-es/resolveRolldownConfig.js +1 -1
- package/dist/_chunks-es/watchAction.js +106 -2
- package/dist/_chunks-es/watchAction.js.map +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +2 -183
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -18
- package/dist/index.js.map +1 -1
- package/package.json +3 -10
- package/dist/_chunks-es/build.js +0 -150
- package/dist/_chunks-es/build.js.map +0 -1
- package/dist/_chunks-es/check.js +0 -189
- package/dist/_chunks-es/check.js.map +0 -1
- package/dist/_chunks-es/consoleSpy.js.map +0 -1
- package/dist/_chunks-es/init.js +0 -520
- package/dist/_chunks-es/init.js.map +0 -1
- package/dist/_chunks-es/isRecord.js +0 -37
- package/dist/_chunks-es/isRecord.js.map +0 -1
- package/dist/_chunks-es/watch.js +0 -109
- package/dist/_chunks-es/watch.js.map +0 -1
- package/tsconfig/isolated-declarations.json +0 -11
- package/tsconfig/recommended.json +0 -24
- package/tsconfig/strict.json +0 -15
- package/tsconfig/strictest.json +0 -16
package/dist/index.d.ts
CHANGED
|
@@ -3,40 +3,6 @@ import { OptimizeLodashOptions } from "@optimize-lodash/rollup-plugin";
|
|
|
3
3
|
import { Options } from "@vanilla-extract/rollup-plugin";
|
|
4
4
|
import { PluginOptions } from "babel-plugin-react-compiler";
|
|
5
5
|
import { NormalizedOutputOptions, Plugin, Plugin as RollupPlugin, TreeshakingOptions } from "rollup";
|
|
6
|
-
import { IExtractorMessagesConfig } from "@microsoft/api-extractor";
|
|
7
|
-
/**
|
|
8
|
-
* Build the distribution files of a npm package.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* import {build} from '@sanity/pkg-utils'
|
|
13
|
-
*
|
|
14
|
-
* build({
|
|
15
|
-
* cwd: process.cwd(),
|
|
16
|
-
* tsconfig: 'tsconfig.dist.json,
|
|
17
|
-
* }).then(() => {
|
|
18
|
-
* console.log('successfully built')
|
|
19
|
-
* }).catch((err) => {
|
|
20
|
-
* console.log(`build error: ${err.message}`)
|
|
21
|
-
* })
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* @public
|
|
25
|
-
*/
|
|
26
|
-
declare function build(options: {
|
|
27
|
-
cwd: string;
|
|
28
|
-
emitDeclarationOnly?: boolean;
|
|
29
|
-
strict?: boolean;
|
|
30
|
-
tsconfig?: string;
|
|
31
|
-
clean?: boolean;
|
|
32
|
-
quiet?: boolean;
|
|
33
|
-
}): Promise<void>;
|
|
34
|
-
/** @public */
|
|
35
|
-
declare function check(options: {
|
|
36
|
-
cwd: string;
|
|
37
|
-
strict?: boolean;
|
|
38
|
-
tsconfig?: string;
|
|
39
|
-
}): Promise<void>;
|
|
40
6
|
type ToggleType = 'error' | 'warn' | 'off';
|
|
41
7
|
/**
|
|
42
8
|
* @public
|
|
@@ -76,16 +42,6 @@ interface StrictOptions {
|
|
|
76
42
|
* @defaultValue 'warn'
|
|
77
43
|
*/
|
|
78
44
|
noCheckTypes: ToggleType;
|
|
79
|
-
/**
|
|
80
|
-
* Disallows the `main` field in `package.json` as all modern tools support the `exports` field.
|
|
81
|
-
* @defaultValue 'warn'
|
|
82
|
-
*/
|
|
83
|
-
noPackageJsonMain: ToggleType;
|
|
84
|
-
/**
|
|
85
|
-
* Disallows the `module` field in `package.json` as all modern tools support the `exports` field.
|
|
86
|
-
* @defaultValue 'warn'
|
|
87
|
-
*/
|
|
88
|
-
noPackageJsonModule: ToggleType;
|
|
89
45
|
/**
|
|
90
46
|
* Disallows the `browser` field in `package.json` as the `browser` condition in `exports` is better supported.
|
|
91
47
|
* @defaultValue 'warn'
|
|
@@ -102,8 +58,6 @@ interface StrictOptions {
|
|
|
102
58
|
*/
|
|
103
59
|
preferModuleType: ToggleType;
|
|
104
60
|
}
|
|
105
|
-
/** @alpha */
|
|
106
|
-
declare function parseStrictOptions(input: unknown): StrictOptions;
|
|
107
61
|
/** @public */
|
|
108
62
|
type PkgFormat = 'commonjs' | 'esm';
|
|
109
63
|
/** @public */
|
|
@@ -327,107 +281,6 @@ declare function loadConfig(options: {
|
|
|
327
281
|
}): Promise<PkgConfigOptions | undefined>;
|
|
328
282
|
/** @public */
|
|
329
283
|
declare const DEFAULT_BROWSERSLIST_QUERY: string[];
|
|
330
|
-
/** @alpha */
|
|
331
|
-
interface PackageJSON {
|
|
332
|
-
type?: 'commonjs' | 'module' | undefined;
|
|
333
|
-
version: string;
|
|
334
|
-
private?: boolean;
|
|
335
|
-
author?: string | {
|
|
336
|
-
name: string;
|
|
337
|
-
email?: string;
|
|
338
|
-
url?: string;
|
|
339
|
-
};
|
|
340
|
-
name: string;
|
|
341
|
-
description?: string;
|
|
342
|
-
keywords?: string[];
|
|
343
|
-
bin?: Record<string, string>;
|
|
344
|
-
dependencies?: Record<string, string | undefined>;
|
|
345
|
-
devDependencies?: Record<string, string | undefined>;
|
|
346
|
-
peerDependencies?: Record<string, string | undefined>;
|
|
347
|
-
exports?: Record<string, `./${string}.json` | `./${string}.css` | {
|
|
348
|
-
source?: string;
|
|
349
|
-
types?: string;
|
|
350
|
-
browser?: {
|
|
351
|
-
source: string;
|
|
352
|
-
import?: string;
|
|
353
|
-
require?: string;
|
|
354
|
-
};
|
|
355
|
-
node?: {
|
|
356
|
-
source?: string;
|
|
357
|
-
module?: string;
|
|
358
|
-
import?: string;
|
|
359
|
-
require?: string;
|
|
360
|
-
};
|
|
361
|
-
module?: string;
|
|
362
|
-
import?: string;
|
|
363
|
-
require?: string;
|
|
364
|
-
default: string;
|
|
365
|
-
} | {
|
|
366
|
-
types?: string;
|
|
367
|
-
svelte: string;
|
|
368
|
-
default?: string;
|
|
369
|
-
}>;
|
|
370
|
-
main?: string;
|
|
371
|
-
browser?: Record<string, string>;
|
|
372
|
-
source?: string;
|
|
373
|
-
module?: string;
|
|
374
|
-
types?: string;
|
|
375
|
-
typesVersions?: Record<string, Record<string, string[]>>;
|
|
376
|
-
files?: string[];
|
|
377
|
-
scripts?: Record<string, string | undefined>;
|
|
378
|
-
browserslist?: string | string[];
|
|
379
|
-
sideEffects?: boolean | string[];
|
|
380
|
-
engines?: {
|
|
381
|
-
node?: string;
|
|
382
|
-
npm?: string;
|
|
383
|
-
};
|
|
384
|
-
repository?: string | {
|
|
385
|
-
type: 'git';
|
|
386
|
-
url: string;
|
|
387
|
-
};
|
|
388
|
-
bugs?: string | {
|
|
389
|
-
url: string;
|
|
390
|
-
email?: string;
|
|
391
|
-
};
|
|
392
|
-
homepage?: string;
|
|
393
|
-
license?: string;
|
|
394
|
-
}
|
|
395
|
-
/** @internal */
|
|
396
|
-
declare function loadPkg(options: {
|
|
397
|
-
cwd: string;
|
|
398
|
-
}): Promise<PackageJSON>;
|
|
399
|
-
/** @alpha */
|
|
400
|
-
interface Logger {
|
|
401
|
-
log: (...args: unknown[]) => void;
|
|
402
|
-
info: (...args: unknown[]) => void;
|
|
403
|
-
warn: (...args: unknown[]) => void;
|
|
404
|
-
error: (...args: unknown[]) => void;
|
|
405
|
-
success: (...args: unknown[]) => void;
|
|
406
|
-
}
|
|
407
|
-
/** @alpha */
|
|
408
|
-
declare function createLogger(quiet?: boolean): Logger;
|
|
409
|
-
/** @alpha */
|
|
410
|
-
declare function loadPkgWithReporting(options: {
|
|
411
|
-
cwd: string;
|
|
412
|
-
logger: Logger;
|
|
413
|
-
strict: boolean;
|
|
414
|
-
strictOptions: StrictOptions;
|
|
415
|
-
}): Promise<PackageJSON>;
|
|
416
|
-
/** @alpha */
|
|
417
|
-
declare function parseExports(options: {
|
|
418
|
-
cwd: string;
|
|
419
|
-
pkg: PackageJSON;
|
|
420
|
-
strict: boolean;
|
|
421
|
-
strictOptions: StrictOptions;
|
|
422
|
-
logger: Logger;
|
|
423
|
-
}): (PkgExport & {
|
|
424
|
-
_path: string;
|
|
425
|
-
})[];
|
|
426
|
-
/** @public */
|
|
427
|
-
interface PkgTemplateFile {
|
|
428
|
-
name: string;
|
|
429
|
-
contents: string;
|
|
430
|
-
}
|
|
431
284
|
/** @public */
|
|
432
285
|
interface PkgTemplateStringOption<T = string> {
|
|
433
286
|
name: string;
|
|
@@ -440,40 +293,6 @@ interface PkgTemplateStringOption<T = string> {
|
|
|
440
293
|
/** @public */
|
|
441
294
|
type PkgTemplateOption<T = string> = PkgTemplateStringOption<T>;
|
|
442
295
|
/** @public */
|
|
443
|
-
interface PkgTemplateDefinition {
|
|
444
|
-
options: PkgTemplateStringOption<any>[];
|
|
445
|
-
features: {
|
|
446
|
-
name: string;
|
|
447
|
-
optional: boolean;
|
|
448
|
-
initial: boolean;
|
|
449
|
-
}[];
|
|
450
|
-
getFiles: (options: Record<string, any>, features: Record<string, boolean>) => Promise<PkgTemplateFile[]>;
|
|
451
|
-
}
|
|
452
|
-
/** @public */
|
|
453
|
-
type PkgTemplateResolver = (options: {
|
|
454
|
-
cwd: string;
|
|
455
|
-
/** @internal */
|
|
456
|
-
logger: Logger;
|
|
457
|
-
packagePath: string;
|
|
458
|
-
}) => PkgTemplateDefinition | Promise<PkgTemplateDefinition>;
|
|
459
|
-
/** @public */
|
|
460
|
-
type PkgTemplate = PkgTemplateDefinition | PkgTemplateResolver;
|
|
461
|
-
/** @public */
|
|
462
296
|
declare function defineTemplateOption<T>(option: PkgTemplateOption<T>): PkgTemplateOption<T>;
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
cwd: string;
|
|
466
|
-
path: string;
|
|
467
|
-
}): Promise<void>;
|
|
468
|
-
/** @alpha */
|
|
469
|
-
declare function getExtractMessagesConfig(options: {
|
|
470
|
-
rules: NonNullable<PkgConfigOptions['extract']>['rules'];
|
|
471
|
-
disabled?: boolean;
|
|
472
|
-
}): IExtractorMessagesConfig;
|
|
473
|
-
/** @public */
|
|
474
|
-
declare function watch(options: {
|
|
475
|
-
cwd: string;
|
|
476
|
-
strict?: boolean;
|
|
477
|
-
tsconfig?: string;
|
|
478
|
-
}): Promise<void>;
|
|
479
|
-
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 RollupPlugin, type TSDocCustomTag, build, check, createLogger, defineConfig, defineTemplateOption, getExtractMessagesConfig, init, loadConfig, loadPkg, loadPkgWithReporting, parseExports, parseStrictOptions, watch };
|
|
297
|
+
export { DEFAULT_BROWSERSLIST_QUERY, type PkgBundle, type PkgConfigOptions, type PkgConfigProperty, type PkgConfigPropertyResolver, type PkgExport, type PkgExports, type PkgFormat, type PkgRuleLevel, type PkgRuntime, type RollupPlugin, type TSDocCustomTag, defineConfig, defineTemplateOption, loadConfig };
|
|
298
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["ToggleType","StrictOptions","parseStrictOptions","PluginItem","BabelPluginItem","OptimizeLodashOptions","Options","VanillaExtractOptions","PluginOptions","ReactCompilerOptions","NormalizedOutputOptions","Plugin","RollupPlugin","TreeshakingOptions","StrictOptions","PkgFormat","PkgRuntime","PkgExport","PkgConfigPropertyResolver","T","PkgConfigProperty","PkgBundle","PkgExports","PkgRuleLevel","TSDocCustomTag","DtsType","PkgConfigOptions","Partial","Record","PkgConfigOptions","defineConfig","T","PkgConfigOptions","loadConfig","Promise","DEFAULT_BROWSERSLIST_QUERY","Logger","PkgTemplateFile","PkgTemplateStringOption","T","Record","PkgTemplateOption","PkgTemplateDefinition","Promise","PkgTemplateResolver","PkgTemplate","PkgTemplateOption","defineTemplateOption","T"],"sources":["../src/node/strict.d.ts","../src/node/core/config/types.d.ts","../src/node/core/config/defineConfig.d.ts","../src/node/core/config/loadConfig.d.ts","../src/node/core/defaults.d.ts","../src/node/core/template/types.d.ts","../src/node/core/template/define.d.ts"],"sourcesContent":["type ToggleType = 'error' | 'warn' | 'off';\n/**\n * @public\n */\nexport interface StrictOptions {\n /**\n * Disallows a top level `typings` field in `package.json` if it is equal to `exports['.'].source`.\n * @defaultValue 'error'\n */\n noPackageJsonTypings: ToggleType;\n /**\n * Requires specifying `sideEffects` in `package.json`.\n * @defaultValue 'warn'\n */\n noImplicitSideEffects: ToggleType;\n /**\n * Requires specifying `browserslist` in `package.json`, instead of relying on it implicitly being:\n * @example\n * ```\n * \"browserslist\": \"extends @sanity/browserslist-config\"\n * ```\n * @defaultValue 'warn'\n */\n noImplicitBrowsersList: ToggleType;\n /**\n * If typescript is used then `types` in `package.json` should be specified for npm listings to show the TS icon.\n * @defaultValue 'error'\n */\n alwaysPackageJsonTypes: ToggleType;\n /**\n * Using `.npmignore` is error prone, it's best practice to always declare `files` instead\n * @defaultValue 'error'\n */\n alwaysPackageJsonFiles: ToggleType;\n /**\n * 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`\n * @defaultValue 'warn'\n */\n noCheckTypes: ToggleType;\n /**\n * Disallows the `browser` field in `package.json` as the `browser` condition in `exports` is better supported.\n * @defaultValue 'warn'\n */\n noPackageJsonBrowser: ToggleType;\n /**\n * Disallows the `typesVersions` field in `package.json` as TypeScript has long supported conditional exports and the `types` condition.\n * @defaultValue 'warn'\n */\n noPackageJsonTypesVersions: ToggleType;\n /**\n * Warns if `type` field is missing or set to `commonjs`. Future versions will require `\"type\": \"module\"`.\n * @defaultValue 'warn'\n */\n preferModuleType: ToggleType;\n}\n/** @alpha */\nexport declare function parseStrictOptions(input: unknown): StrictOptions;\nexport {};\n//# sourceMappingURL=strict.d.ts.map","import type { PluginItem as BabelPluginItem } from '@babel/core';\nimport type { OptimizeLodashOptions } from '@optimize-lodash/rollup-plugin';\nimport type { Options as VanillaExtractOptions } from '@vanilla-extract/rollup-plugin';\nimport type { PluginOptions as ReactCompilerOptions } from 'babel-plugin-react-compiler';\nimport type { NormalizedOutputOptions, Plugin as RollupPlugin, TreeshakingOptions } from 'rollup';\nimport type { StrictOptions } from '../../strict.ts';\n/** @public */\nexport type PkgFormat = 'commonjs' | 'esm';\n/** @public */\nexport type PkgRuntime = '*' | 'browser' | 'node';\n/** @public */\nexport interface PkgExport {\n /** @internal */\n _exported?: boolean;\n browser?: {\n source: string;\n import?: string;\n require?: string;\n };\n node?: {\n source?: string;\n import?: string;\n require?: string;\n };\n types?: string;\n source: string;\n import?: string;\n require?: string;\n default: string;\n}\n/** @public */\nexport type PkgConfigPropertyResolver<T> = (prev: T) => T;\n/** @public */\nexport type PkgConfigProperty<T> = PkgConfigPropertyResolver<T> | T;\n/** @public */\nexport interface PkgBundle {\n source: string;\n import?: string;\n require?: string;\n runtime?: PkgRuntime;\n}\n/** @public */\nexport interface PkgExports {\n [path: string]: PkgExport;\n}\n/** @public */\nexport type PkgRuleLevel = 'error' | 'warn' | 'info' | 'off';\n/** @public */\nexport interface TSDocCustomTag {\n name: string;\n syntaxKind: 'block' | 'modifier';\n allowMultiple?: boolean;\n}\nexport type DtsType = 'api-extractor' | 'rolldown';\n/** @public */\nexport interface PkgConfigOptions {\n /** @alpha */\n babel?: {\n plugins?: BabelPluginItem[] | null | undefined;\n /** @alpha */\n reactCompiler?: boolean;\n /** @alpha */\n styledComponents?: boolean | {\n /** @defaultValue true */\n displayName?: boolean;\n /**\n * @defaultValue []\n * @example [\"\\@xstyled/styled-components\", \"\\@xstyled/styled-components/*\"]\n */\n topLevelImportPaths?: string[];\n /** @defaultValue true */\n ssr?: boolean;\n /** @defaultValue fale */\n fileName?: boolean;\n /** @defaultValue [\"index\"] */\n meaninglessFileNames?: string[];\n /** @defaultValue true */\n minify?: boolean;\n /** @defaultValue false */\n transpileTemplateLiterals?: boolean;\n namespace?: string;\n /** @defaultValue true */\n pure?: boolean;\n };\n };\n /**\n * Configure the React Compiler.\n * To enable it set `babel.reactCompiler` to `true`\n * @beta */\n reactCompilerOptions?: Partial<ReactCompilerOptions>;\n bundles?: PkgBundle[];\n /** @alpha */\n define?: Record<string, string | number | boolean | undefined | null>;\n /**\n * Directory of distributed & bundled files.\n */\n dist?: string;\n exports?: PkgConfigProperty<PkgExports>;\n /**\n * Runs `@microsoft/api-extractor` to check that TSDoc tags are valid, and release tags are correct.\n * This is useful for packages that need to be consumed by TSDoc-based tooling.\n * It's enabled by default, it can be disabled by setting `extract: {enabled: false}`\n */\n extract?: {\n /**\n * @defaultValue true\n */\n enabled?: boolean;\n /**\n * Packages in `devDependencies` that are not in `external` are automatically added to the `bundledPackages` config.\n * You can exclude a package from being bundled by using a callback:\n * ```\n * bundledPackages: (prev) => prev.filter(package => package !== 'sanity')\n * ```\n */\n bundledPackages?: PkgConfigProperty<string[]>;\n customTags?: TSDocCustomTag[];\n rules?: {\n /**\n * @deprecated as it's no longer needed since TypeScript 5.5 https://github.com/microsoft/TypeScript/issues/42873\n */\n 'ae-forgotten-export'?: never;\n 'ae-incompatible-release-tags'?: PkgRuleLevel;\n 'ae-internal-missing-underscore'?: PkgRuleLevel;\n 'ae-missing-release-tag'?: PkgRuleLevel;\n 'tsdoc-link-tag-unescaped-text'?: PkgRuleLevel;\n 'tsdoc-undefined-tag'?: PkgRuleLevel;\n 'tsdoc-unsupported-tag'?: PkgRuleLevel;\n };\n };\n /**\n * Packages to exclude from bundles.\n * Provide an array to merge with default exclusions, use a function to replace them:\n * ```\n * exclude: (prev) => prev.filter(package => package !== 'foo')\n * ```\n */\n external?: PkgConfigProperty<string[]>;\n /**\n * Defaults to `\"automatic\"`\n */\n jsx?: 'transform' | 'preserve' | 'automatic';\n /**\n * Defaults to `\"createElement\"`\n */\n jsxFactory?: string;\n /**\n * Defaults to `\"Fragment\"`\n */\n jsxFragment?: string;\n /**\n * Defaults to `\"react\"`\n */\n jsxImportSource?: string;\n /**\n * @deprecated no longer supported\n */\n legacyExports?: never;\n minify?: boolean;\n /** @alpha */\n rollup?: {\n plugins?: PkgConfigProperty<RollupPlugin[]>;\n output?: Partial<NormalizedOutputOptions>;\n /**\n * Default options are `preset: 'recommended'` and `propertyReadSideEffects: false`\n * @alpha\n */\n treeshake?: TreeshakingOptions;\n /** @alpha */\n experimentalLogSideEffects?: boolean;\n /**\n * Adds [hash] to chunk filenames, generally only useful if `@sanity/pkg-utils` is used to deploy a package directly to a CDN.\n * It's not needed when publishing to npm for consumption by other libraries, bundlers and frameworks.\n * @defaultValue false\n */\n hashChunkFileNames?: boolean;\n /**\n * Optimizes lodash imports using `@optimize-lodash/rollup-plugin` when set to `true`.\n * It's enabled if `lodash` is found in `dependencies` or `peerDependencies`.\n * It will use `lodash-es` for ESM targets if found in `dependencies` or `peerDependencies`.\n * @defaultValue true\n * @alpha\n */\n optimizeLodash?: boolean | OptimizeLodashOptions;\n /**\n * Enables \\@vanilla-extract/rollup-plugin to extract CSS into a separate file, with support for minifying the extracted CSS.\n * @alpha\n */\n vanillaExtract?: boolean | (VanillaExtractOptions & {\n minify?: boolean;\n browserslist?: string | string[];\n });\n };\n /**\n * Default runtime of package exports\n */\n runtime?: PkgRuntime;\n sourcemap?: boolean;\n /**\n * Directory of source files.\n */\n src?: string;\n tsconfig?: string;\n /**\n * Configure what checks are made when running `--strict` builds and checks\n */\n strictOptions?: Partial<StrictOptions>;\n /**\n * .d.ts files can be generated either by using `@microsoft/api-extractor` or `rolldown`.\n * `rolldown` is the faster option, but is not yet stable.\n * @defaultValue 'api-extractor'\n */\n dts?: DtsType;\n /**\n * When using `dts: 'rolldown'`, enables the use of `@typescript/native-preview` for type generation.\n * By default, `tsgo` is automatically enabled if `@typescript/native-preview` is found in `devDependencies`.\n * Set to `true` to explicitly enable or `false` to explicitly disable.\n * @alpha\n */\n tsgo?: boolean;\n}\n//# sourceMappingURL=types.d.ts.map","import type { PkgConfigOptions } from './types.ts';\n/** @public */\nexport declare function defineConfig<const T extends PkgConfigOptions>(configOptions: T): T;\n//# sourceMappingURL=defineConfig.d.ts.map","import type { PkgConfigOptions } from './types.ts';\n/** @alpha */\nexport declare function loadConfig(options: {\n cwd: string;\n}): Promise<PkgConfigOptions | undefined>;\n//# sourceMappingURL=loadConfig.d.ts.map","/** @public */\nexport declare const DEFAULT_BROWSERSLIST_QUERY: string[];\n//# sourceMappingURL=defaults.d.ts.map","import type { Logger } from '../../logger.ts';\n/** @public */\nexport interface PkgTemplateFile {\n name: string;\n contents: string;\n}\n/** @public */\nexport interface PkgTemplateStringOption<T = string> {\n name: string;\n type: 'string';\n description: string;\n initial?: T | ((options: Record<string, any>) => T);\n parse?: (v: string) => T | null;\n validate?: (v: string) => string | true;\n}\n/** @public */\nexport type PkgTemplateOption<T = string> = PkgTemplateStringOption<T>;\n/** @public */\nexport interface PkgTemplateDefinition {\n options: PkgTemplateStringOption<any>[];\n features: {\n name: string;\n optional: boolean;\n initial: boolean;\n }[];\n getFiles: (options: Record<string, any>, features: Record<string, boolean>) => Promise<PkgTemplateFile[]>;\n}\n/** @public */\nexport type PkgTemplateResolver = (options: {\n cwd: string;\n /** @internal */\n logger: Logger;\n packagePath: string;\n}) => PkgTemplateDefinition | Promise<PkgTemplateDefinition>;\n/** @public */\nexport type PkgTemplate = PkgTemplateDefinition | PkgTemplateResolver;\n//# sourceMappingURL=types.d.ts.map","import type { PkgTemplateOption } from './types.ts';\n/** @public */\nexport declare function defineTemplateOption<T>(option: PkgTemplateOption<T>): PkgTemplateOption<T>;\n//# sourceMappingURL=define.d.ts.map"],"mappings":";;;;;KAAKA,UAAAA;;;;UAIYC,aAAAA;;;AAAjB;;EAU2BD,oBAAAA,EALDA,UAKCA;EASCA;;;;EAoBFA,qBAAAA,EA7BCA,UA6BDA;EAKMA;;;;ACzChC;AAEA;AAEA;AAoBA;EAEYoB,sBAAiB,EDVDpB,UCUC;EAAgCmB;;;;EAE5CE,sBAAS,EDPErB,UCWdgB;EAGGM;AAIjB;AAEA;AAKA;EAEiBI,sBAAgB,EDtBL1B,UCsBK;EAGfI;;;;EAkCLwB,YAAAA,EDtDK5B,UCsDL4B;EAKmBN;;;;EAyBaC,oBAAAA,ED/EnBvB,UC+EmBuB;EACEA;;;;EAITA,0BAAAA,ED/ENvB,UC+EMuB;EAUvBH;;;;EAyBEO,gBAAAA,ED7GK3B,UC6GL2B;;;AD9JA1B,KCGLc,SAAAA,GDHkB,UAAA,GAAA,KAAA;;AAUHf,KCLfgB,UAAAA,GDKehB,GAAAA,GAAAA,SAAAA,GAAAA,MAAAA;;AAcCA,UCjBXiB,SAAAA,CDiBWjB;EAKAA;EAKVA,SAAAA,CAAA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iBcvC,GAAAA,CAAAA,CAAAA,OAAAA,EKjBCwC,MLiBDxC,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,EAAAA,GKjByBuC,CLiBzBvC,CAAAA;EAKAA,KAAAA,CAAAA,EAAAA,CAAAA,CAAAA,EAAAA,MAAAA,EAAAA,GKrBDuC,CLqBCvC,GAAAA,IAAAA;EAKVA,QAAAA,CAAAA,EAAAA,CAAAA,CAAAA,EAAAA,MAAAA,EAAAA,GAAAA,MAAAA,GAAAA,IAAAA;;;AAeIA,KKrCVyC,iBLqCUzC,CAAAA,IAAAA,MAAAA,CAAAA,GKrCsBsC,uBLqCtBtC,CKrC8CuC,CLqC9CvC,CAAAA;;iBMnDE+C,gCAAgCD,kBAAkBE,KAAKF,kBAAkBE"}
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { DEFAULT_BROWSERSLIST_QUERY, loadConfig, loadPkg, loadPkgWithReporting, parseExports, parseStrictOptions } from "./_chunks-es/consoleSpy.js";
|
|
4
|
-
import { defineTemplateOption, init } from "./_chunks-es/init.js";
|
|
5
|
-
import { createLogger } from "./_chunks-es/isRecord.js";
|
|
6
|
-
import { getExtractMessagesConfig } from "./_chunks-es/index.js";
|
|
7
|
-
import { watch } from "./_chunks-es/watch.js";
|
|
1
|
+
import { DEFAULT_BROWSERSLIST_QUERY, loadConfig } from "./_chunks-es/defaults.js";
|
|
2
|
+
import { defineTemplateOption } from "./_chunks-es/define.js";
|
|
8
3
|
function defineConfig(configOptions) {
|
|
9
4
|
return configOptions;
|
|
10
5
|
}
|
|
11
6
|
export {
|
|
12
7
|
DEFAULT_BROWSERSLIST_QUERY,
|
|
13
|
-
build,
|
|
14
|
-
check,
|
|
15
|
-
createLogger,
|
|
16
8
|
defineConfig,
|
|
17
9
|
defineTemplateOption,
|
|
18
|
-
|
|
19
|
-
init,
|
|
20
|
-
loadConfig,
|
|
21
|
-
loadPkg,
|
|
22
|
-
loadPkgWithReporting,
|
|
23
|
-
parseExports,
|
|
24
|
-
parseStrictOptions,
|
|
25
|
-
watch
|
|
10
|
+
loadConfig
|
|
26
11
|
};
|
|
27
12
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/node/core/config/defineConfig.ts"],"sourcesContent":["import type {PkgConfigOptions} from './types.ts'\n\n/** @public */\nexport function defineConfig<const T extends PkgConfigOptions>(configOptions: T): T {\n return configOptions\n}\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/node/core/config/defineConfig.ts"],"sourcesContent":["import type {PkgConfigOptions} from './types.ts'\n\n/** @public */\nexport function defineConfig<const T extends PkgConfigOptions>(configOptions: T): T {\n return configOptions\n}\n"],"names":[],"mappings":";;AAGO,SAAS,aAA+C,eAAqB;AAClF,SAAO;AACT;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/pkg-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0",
|
|
4
4
|
"description": "Simple utilities for modern npm packages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity-io",
|
|
@@ -29,13 +29,6 @@
|
|
|
29
29
|
"source": "./src/node/index.ts",
|
|
30
30
|
"default": "./dist/index.js"
|
|
31
31
|
},
|
|
32
|
-
"./tsconfig/recommended.json": "./tsconfig/recommended.json",
|
|
33
|
-
"./tsconfig/recommended": "./tsconfig/recommended.json",
|
|
34
|
-
"./tsconfig/strict.json": "./tsconfig/strict.json",
|
|
35
|
-
"./tsconfig/strict": "./tsconfig/strict.json",
|
|
36
|
-
"./tsconfig/strictest.json": "./tsconfig/strictest.json",
|
|
37
|
-
"./tsconfig/isolated-declarations.json": "./tsconfig/isolated-declarations.json",
|
|
38
|
-
"./tsconfig": "./tsconfig/strictest.json",
|
|
39
32
|
"./package.json": "./package.json"
|
|
40
33
|
},
|
|
41
34
|
"main": "./dist/index.js",
|
|
@@ -113,7 +106,8 @@
|
|
|
113
106
|
"rollup-plugin-visualizer": "^6.0.5",
|
|
114
107
|
"semver": "^7.7.3",
|
|
115
108
|
"typescript": "5.9.3",
|
|
116
|
-
"vitest": "^4.0.14"
|
|
109
|
+
"vitest": "^4.0.14",
|
|
110
|
+
"@sanity/tsconfig": "^1.0.0"
|
|
117
111
|
},
|
|
118
112
|
"peerDependencies": {
|
|
119
113
|
"babel-plugin-react-compiler": "*",
|
|
@@ -138,7 +132,6 @@
|
|
|
138
132
|
"extract": "sanity-tsdoc etl --outDir etc/api/@sanity/pkg-utils --tsconfig tsconfig.dist.json",
|
|
139
133
|
"pretest": "pnpm run clean && pnpm run build",
|
|
140
134
|
"test": "vitest run",
|
|
141
|
-
"test:update-snapshots": "pnpm test run -- --update",
|
|
142
135
|
"typecheck": "tsc --build",
|
|
143
136
|
"watch": "tsx scripts/watch.ts"
|
|
144
137
|
}
|
package/dist/_chunks-es/build.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { rimraf } from "rimraf";
|
|
3
|
-
import { getTargetPaths, loadConfig, loadPkgWithReporting, resolveBuildContext } from "./consoleSpy.js";
|
|
4
|
-
import { createLogger } from "./isRecord.js";
|
|
5
|
-
import { createSpinner } from "./spinner.js";
|
|
6
|
-
import { buildTaskHandlers } from "./index.js";
|
|
7
|
-
function resolveBuildTasks(ctx) {
|
|
8
|
-
const { config, pkg, target } = ctx, bundles = config?.bundles || [], tasks = [], exports$1 = Object.entries(ctx.exports || {}).map(
|
|
9
|
-
([_path, exp]) => ({ _path, ...exp })
|
|
10
|
-
), dtsTask = {
|
|
11
|
-
type: "build:dts",
|
|
12
|
-
entries: []
|
|
13
|
-
}, rolldownDtsTask = {}, rollupTasks = {};
|
|
14
|
-
function addRollupTaskEntry(format, runtime, entry) {
|
|
15
|
-
const buildId = `${format}:${runtime}`;
|
|
16
|
-
ctx.dts === "rolldown" && (rolldownDtsTask[buildId] ? rolldownDtsTask[buildId].entries.push(entry) : rolldownDtsTask[buildId] = {
|
|
17
|
-
type: "rolldown:dts",
|
|
18
|
-
buildId,
|
|
19
|
-
entries: [entry],
|
|
20
|
-
runtime,
|
|
21
|
-
format,
|
|
22
|
-
target: target[runtime]
|
|
23
|
-
}), ctx.emitDeclarationOnly || (rollupTasks[buildId] ? rollupTasks[buildId].entries.push(entry) : rollupTasks[buildId] = {
|
|
24
|
-
type: "build:js",
|
|
25
|
-
buildId,
|
|
26
|
-
entries: [entry],
|
|
27
|
-
runtime,
|
|
28
|
-
format,
|
|
29
|
-
target: target[runtime]
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
if (ctx.dts === "api-extractor") {
|
|
33
|
-
for (const exp of exports$1) {
|
|
34
|
-
const importId = path.join(pkg.name, exp._path);
|
|
35
|
-
exp.source?.endsWith(".ts") && dtsTask.entries.push({
|
|
36
|
-
importId,
|
|
37
|
-
exportPath: exp._path,
|
|
38
|
-
sourcePath: exp.source,
|
|
39
|
-
targetPaths: getTargetPaths(pkg.type, exp)
|
|
40
|
-
}), exp.browser?.source?.endsWith(".ts") && dtsTask.entries.push({
|
|
41
|
-
importId,
|
|
42
|
-
exportPath: exp._path,
|
|
43
|
-
sourcePath: exp.browser.source,
|
|
44
|
-
targetPaths: getTargetPaths(pkg.type, exp.browser)
|
|
45
|
-
}), exp.node?.source?.endsWith(".ts") && dtsTask.entries.push({
|
|
46
|
-
importId,
|
|
47
|
-
exportPath: exp._path,
|
|
48
|
-
sourcePath: exp.node.source,
|
|
49
|
-
targetPaths: getTargetPaths(pkg.type, exp.node)
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
for (const bundle of bundles)
|
|
53
|
-
if (bundle.source?.endsWith(".ts")) {
|
|
54
|
-
const exportPath = (bundle.import || bundle.require).replace(/\.[mc]?js$/, ""), importId = path.join(pkg.name, exportPath);
|
|
55
|
-
dtsTask.entries.push({
|
|
56
|
-
importId,
|
|
57
|
-
exportPath,
|
|
58
|
-
sourcePath: bundle.source,
|
|
59
|
-
targetPaths: getTargetPaths(pkg.type, bundle)
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
dtsTask.entries.length && tasks.push(dtsTask);
|
|
63
|
-
}
|
|
64
|
-
for (const exp of exports$1) {
|
|
65
|
-
const output = exp.require;
|
|
66
|
-
output && addRollupTaskEntry("commonjs", ctx.runtime, {
|
|
67
|
-
path: exp._path,
|
|
68
|
-
source: exp.source,
|
|
69
|
-
output
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
for (const exp of exports$1) {
|
|
73
|
-
const output = exp.import;
|
|
74
|
-
output && addRollupTaskEntry("esm", ctx.runtime, {
|
|
75
|
-
path: exp._path,
|
|
76
|
-
source: exp.source,
|
|
77
|
-
output
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
for (const exp of exports$1) {
|
|
81
|
-
const output = exp.browser?.require;
|
|
82
|
-
output && addRollupTaskEntry("commonjs", "browser", {
|
|
83
|
-
path: exp._path,
|
|
84
|
-
source: exp.browser?.source || exp.source,
|
|
85
|
-
output
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
for (const exp of exports$1) {
|
|
89
|
-
const output = exp.browser?.import;
|
|
90
|
-
output && addRollupTaskEntry("esm", "browser", {
|
|
91
|
-
path: exp._path,
|
|
92
|
-
source: exp.browser?.source || exp.source,
|
|
93
|
-
output
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
for (const bundle of bundles) {
|
|
97
|
-
const idx = bundles.indexOf(bundle);
|
|
98
|
-
bundle.require && addRollupTaskEntry("commonjs", bundle.runtime || ctx.runtime, {
|
|
99
|
-
path: `__$$bundle_cjs_${idx}$$__`,
|
|
100
|
-
source: bundle.source,
|
|
101
|
-
output: bundle.require
|
|
102
|
-
}), bundle.import && addRollupTaskEntry("esm", bundle.runtime || ctx.runtime, {
|
|
103
|
-
path: `__$$bundle_esm_${idx}$$__`,
|
|
104
|
-
source: bundle.source,
|
|
105
|
-
output: bundle.import
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
return tasks.push(...Object.values(rolldownDtsTask)), tasks.push(...Object.values(rollupTasks)), tasks;
|
|
109
|
-
}
|
|
110
|
-
async function build(options) {
|
|
111
|
-
const {
|
|
112
|
-
cwd,
|
|
113
|
-
emitDeclarationOnly,
|
|
114
|
-
strict = !1,
|
|
115
|
-
tsconfig: tsconfigOption,
|
|
116
|
-
clean = !1,
|
|
117
|
-
quiet = !1
|
|
118
|
-
} = options, logger = createLogger(quiet), config = await loadConfig({ cwd }), { parseStrictOptions } = await import("./consoleSpy.js").then(function(n) {
|
|
119
|
-
return n.strict;
|
|
120
|
-
}), strictOptions = parseStrictOptions(config?.strictOptions ?? {}), pkg = await loadPkgWithReporting({ cwd, logger, strict, strictOptions }), tsconfig = tsconfigOption || config?.tsconfig || "tsconfig.json", ctx = await resolveBuildContext({
|
|
121
|
-
config,
|
|
122
|
-
cwd,
|
|
123
|
-
emitDeclarationOnly,
|
|
124
|
-
logger,
|
|
125
|
-
pkg,
|
|
126
|
-
strict,
|
|
127
|
-
tsconfig
|
|
128
|
-
});
|
|
129
|
-
clean && (quiet || logger.log(
|
|
130
|
-
`Deleting the \`dist\` folder: './${path.relative(cwd, ctx.distPath)}' before building...`
|
|
131
|
-
), await rimraf(ctx.distPath));
|
|
132
|
-
const buildTasks = resolveBuildTasks(ctx);
|
|
133
|
-
for (const task of buildTasks) {
|
|
134
|
-
const handler = buildTaskHandlers[task.type], taskName = handler.name(ctx, task), spinner = createSpinner(taskName, quiet);
|
|
135
|
-
try {
|
|
136
|
-
const result = await handler.exec(ctx, task).toPromise();
|
|
137
|
-
spinner.complete(), ctx.logger.log(), handler.complete(ctx, task, result);
|
|
138
|
-
} catch (err) {
|
|
139
|
-
if (spinner.error(), err instanceof Error) {
|
|
140
|
-
const RE_CWD = new RegExp(cwd, "g");
|
|
141
|
-
ctx.logger.error(err.message.replace(RE_CWD, ".")), ctx.logger.log();
|
|
142
|
-
}
|
|
143
|
-
handler.error(ctx, task, err), process.exit(1);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
export {
|
|
148
|
-
build
|
|
149
|
-
};
|
|
150
|
-
//# sourceMappingURL=build.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sources":["../../src/node/resolveBuildTasks.ts","../../src/node/build.ts"],"sourcesContent":["import path from 'node:path'\nimport type {PkgExport, PkgFormat, PkgRuntime} from './core/config/types.ts'\nimport type {BuildContext} from './core/contexts/buildContext.ts'\nimport {getTargetPaths} from './tasks/dts/getTargetPaths.ts'\nimport type {DtsTask} from './tasks/dts/types.ts'\nimport type {BuildTask, RolldownDtsTask, RollupTask, RollupTaskEntry} from './tasks/types.ts'\n\n/** @internal */\nexport function resolveBuildTasks(ctx: BuildContext): BuildTask[] {\n const {config, pkg, target} = ctx\n\n const bundles = config?.bundles || []\n\n const tasks: BuildTask[] = []\n\n const exports = Object.entries(ctx.exports || {}).map(\n ([_path, exp]) => ({_path, ...exp}) as PkgExport & {_path: string},\n )\n\n const dtsTask: DtsTask = {\n type: 'build:dts',\n entries: [],\n }\n\n const rolldownDtsTask: Record<string, RolldownDtsTask> = {}\n const rollupTasks: Record<string, RollupTask> = {}\n\n function addRollupTaskEntry(format: PkgFormat, runtime: PkgRuntime, entry: RollupTaskEntry) {\n const buildId = `${format}:${runtime}`\n\n if (ctx.dts === 'rolldown') {\n if (rolldownDtsTask[buildId]) {\n rolldownDtsTask[buildId].entries.push(entry)\n } else {\n rolldownDtsTask[buildId] = {\n type: 'rolldown:dts',\n buildId,\n entries: [entry],\n runtime,\n format,\n target: target[runtime],\n }\n }\n }\n\n if (!ctx.emitDeclarationOnly) {\n if (rollupTasks[buildId]) {\n rollupTasks[buildId].entries.push(entry)\n } else {\n rollupTasks[buildId] = {\n type: 'build:js',\n buildId,\n entries: [entry],\n runtime,\n format,\n target: target[runtime],\n }\n }\n }\n }\n\n if (ctx.dts === 'api-extractor') {\n // Parse `dts` tasks\n for (const exp of exports) {\n const importId = path.join(pkg.name, exp._path)\n\n if (exp.source?.endsWith('.ts')) {\n dtsTask.entries.push({\n importId,\n exportPath: exp._path,\n sourcePath: exp.source,\n targetPaths: getTargetPaths(pkg.type, exp),\n })\n }\n\n if (exp.browser?.source?.endsWith('.ts')) {\n dtsTask.entries.push({\n importId,\n exportPath: exp._path,\n sourcePath: exp.browser.source,\n targetPaths: getTargetPaths(pkg.type, exp.browser),\n })\n }\n\n if (exp.node?.source?.endsWith('.ts')) {\n dtsTask.entries.push({\n importId,\n exportPath: exp._path,\n sourcePath: exp.node.source,\n targetPaths: getTargetPaths(pkg.type, exp.node),\n })\n }\n }\n\n // Handle dts tasks for bundles\n for (const bundle of bundles) {\n if (bundle.source?.endsWith('.ts')) {\n // importId needs to be how the bundle is used, like `@sanity/pkg-utils/dist/cli`\n // exportPath needs to be the path to the bundle, like `./dist/cli`\n // targetPaths is then: [./dist/cli.d.ts, ./dist/cli.d.cts]\n const exportPath = (bundle.import || bundle.require)!.replace(/\\.[mc]?js$/, '')\n const importId = path.join(pkg.name, exportPath)\n\n dtsTask.entries.push({\n importId,\n exportPath,\n sourcePath: bundle.source,\n targetPaths: getTargetPaths(pkg.type, bundle),\n })\n }\n }\n\n // Add dts task\n if (dtsTask.entries.length) {\n tasks.push(dtsTask)\n }\n }\n\n // Parse rollup:commonjs:* tasks\n for (const exp of exports) {\n const output = exp.require\n\n if (!output) continue\n\n addRollupTaskEntry('commonjs', ctx.runtime, {\n path: exp._path,\n source: exp.source,\n output,\n })\n }\n\n // Parse rollup:esm:* tasks\n for (const exp of exports) {\n const output = exp.import\n\n if (!output) continue\n\n addRollupTaskEntry('esm', ctx.runtime, {\n path: exp._path,\n source: exp.source,\n output,\n })\n }\n\n // Parse rollup:commonjs:browser tasks\n for (const exp of exports) {\n const output = exp.browser?.require\n\n if (!output) continue\n\n addRollupTaskEntry('commonjs', 'browser', {\n path: exp._path,\n source: exp.browser?.source || exp.source,\n output,\n })\n }\n\n // Parse rollup:esm:browser tasks\n for (const exp of exports) {\n const output = exp.browser?.import\n\n if (!output) continue\n\n addRollupTaskEntry('esm', 'browser', {\n path: exp._path,\n source: exp.browser?.source || exp.source,\n output,\n })\n }\n\n for (const bundle of bundles) {\n const idx = bundles.indexOf(bundle)\n\n if (bundle.require) {\n addRollupTaskEntry('commonjs', bundle.runtime || ctx.runtime, {\n path: `__$$bundle_cjs_${idx}$$__`,\n source: bundle.source,\n output: bundle.require,\n })\n }\n\n if (bundle.import) {\n addRollupTaskEntry('esm', bundle.runtime || ctx.runtime, {\n path: `__$$bundle_esm_${idx}$$__`,\n source: bundle.source,\n output: bundle.import,\n })\n }\n }\n\n // Perform rolldown dts tasks first, as they have special logic for removing non .d.ts chunks\n tasks.push(...Object.values(rolldownDtsTask))\n // Then run api-extractor tsdoc release tag checking (if rolldown is used for dts bundling, otherwise api-extractor performs both in the build:dts task)\n // @TODO\n // Then run rollup tasks\n tasks.push(...Object.values(rollupTasks))\n\n return tasks\n}\n","import path from 'node:path'\nimport {rimraf} from 'rimraf'\nimport {loadConfig} from './core/config/loadConfig.ts'\nimport {loadPkgWithReporting} from './core/pkg/loadPkgWithReporting.ts'\nimport {createLogger} from './logger.ts'\nimport {resolveBuildContext} from './resolveBuildContext.ts'\nimport {resolveBuildTasks} from './resolveBuildTasks.ts'\nimport {createSpinner} from './spinner.ts'\nimport {buildTaskHandlers} from './tasks/index.ts'\nimport {type BuildTask, type TaskHandler} from './tasks/types.ts'\n\n/**\n * Build the distribution files of a npm package.\n *\n * @example\n * ```ts\n * import {build} from '@sanity/pkg-utils'\n *\n * build({\n * cwd: process.cwd(),\n * tsconfig: 'tsconfig.dist.json,\n * }).then(() => {\n * console.log('successfully built')\n * }).catch((err) => {\n * console.log(`build error: ${err.message}`)\n * })\n * ```\n *\n * @public\n */\nexport async function build(options: {\n cwd: string\n emitDeclarationOnly?: boolean\n strict?: boolean\n tsconfig?: string\n clean?: boolean\n quiet?: boolean\n}): Promise<void> {\n const {\n cwd,\n emitDeclarationOnly,\n strict = false,\n tsconfig: tsconfigOption,\n clean = false,\n quiet = false,\n } = options\n const logger = createLogger(quiet)\n\n const config = await loadConfig({cwd})\n\n const {parseStrictOptions} = await import('./strict.ts')\n const strictOptions = parseStrictOptions(config?.strictOptions ?? {})\n const pkg = await loadPkgWithReporting({cwd, logger, strict, strictOptions})\n\n const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'\n\n const ctx = await resolveBuildContext({\n config,\n cwd,\n emitDeclarationOnly,\n logger,\n pkg,\n strict,\n tsconfig,\n })\n\n if (clean) {\n if (!quiet) {\n logger.log(\n `Deleting the \\`dist\\` folder: './${path.relative(cwd, ctx.distPath)}' before building...`,\n )\n }\n await rimraf(ctx.distPath)\n }\n\n const buildTasks = resolveBuildTasks(ctx)\n\n for (const task of buildTasks) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- TypeScript can't infer the correct handler type from discriminated union\n const handler = buildTaskHandlers[task.type] as TaskHandler<BuildTask>\n const taskName = handler.name(ctx, task)\n\n const spinner = createSpinner(taskName, quiet)\n\n try {\n const result = await handler.exec(ctx, task).toPromise()\n\n spinner.complete()\n ctx.logger.log()\n\n handler.complete(ctx, task, result)\n } catch (err) {\n spinner.error()\n\n if (err instanceof Error) {\n const RE_CWD = new RegExp(cwd, 'g')\n\n ctx.logger.error(err.message.replace(RE_CWD, '.'))\n ctx.logger.log()\n }\n\n handler.error(ctx, task, err)\n\n process.exit(1)\n }\n }\n}\n"],"names":["exports"],"mappings":";;;;;;AAQO,SAAS,kBAAkB,KAAgC;AAChE,QAAM,EAAC,QAAQ,KAAK,OAAA,IAAU,KAExB,UAAU,QAAQ,WAAW,CAAA,GAE7B,QAAqB,CAAA,GAErBA,YAAU,OAAO,QAAQ,IAAI,WAAW,CAAA,CAAE,EAAE;A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