@sanity/pkg-utils 9.1.5 → 9.2.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.
|
@@ -52,7 +52,7 @@ function resolveRolldownConfig(ctx, buildTask) {
|
|
|
52
52
|
dts({
|
|
53
53
|
emitDtsOnly: !0,
|
|
54
54
|
tsconfig: ctx.ts.configPath || "tsconfig.json",
|
|
55
|
-
tsgo: typeof pkg.devDependencies == "object" && "@typescript/native-preview" in pkg.devDependencies,
|
|
55
|
+
tsgo: config?.tsgo !== void 0 ? config.tsgo : typeof pkg.devDependencies == "object" && "@typescript/native-preview" in pkg.devDependencies,
|
|
56
56
|
// Enable the resolver by giving an allow list of packages to dig through node_modules.
|
|
57
57
|
// If there are none that should be resolved, then this process is skipped and our build is faster.
|
|
58
58
|
// If there's a match then it'll call the resolver function defined on `inputOptions.external`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveRolldownConfig.js","sources":["../../src/node/tasks/rolldown/resolveRolldownConfig.ts"],"sourcesContent":["import path from 'node:path'\nimport type {InputOptions, OutputOptions} from 'rolldown'\nimport {dts as dtsPlugin} from 'rolldown-plugin-dts'\nimport type {BuildContext} from '../../core/contexts/buildContext.ts'\nimport {pkgExtMap as extMap} from '../../core/pkg/pkgExt.ts'\nimport type {RolldownDtsTask} from '../types.ts'\n\nexport interface RolldownConfig {\n inputOptions: InputOptions\n outputOptions: OutputOptions\n}\n\nexport function resolveRolldownConfig(\n ctx: BuildContext,\n buildTask: RolldownDtsTask,\n): RolldownConfig {\n const {format, runtime} = buildTask\n const {config, cwd, exports: _exports, external, distPath, logger, pkg, ts} = ctx\n const outputExt = extMap[pkg.type || 'commonjs'][format]\n const outDir = path.relative(cwd, distPath)\n\n const pathAliases = Object.fromEntries(\n Object.entries(ts.config?.options.paths || {}).map(([key, val]) => {\n return [key, path.resolve(cwd, ts.config?.options.baseUrl || '.', val[0]!)]\n }),\n )\n\n const entries = buildTask.entries.map((entry) => {\n return {\n ...entry,\n name: path.relative(outDir, entry.output).replace(/\\.[^/.]+$/, ''),\n }\n }, {})\n\n const exportIds =\n _exports && Object.keys(_exports).map((exportPath) => path.join(pkg.name, exportPath))\n\n const sourcePaths = _exports && Object.values(_exports).map((e) => path.resolve(cwd, e.source))\n\n const replacements = Object.fromEntries(\n Object.entries(config?.define || {}).map(([key, val]) => [key, JSON.stringify(val)]),\n )\n\n const entryFileNames = `[name]${outputExt}`\n\n const inputOptions = {\n cwd,\n transform: {\n define:\n pkg.name === '@sanity/pkg-utils'\n ? {...replacements}\n : {\n 'process.env.PKG_FORMAT': JSON.stringify(format),\n 'process.env.PKG_RUNTIME': JSON.stringify(runtime),\n 'process.env.PKG_VERSION': JSON.stringify(process.env['PKG_VERSION'] || pkg.version),\n ...replacements,\n },\n },\n\n platform:\n buildTask.type === 'rolldown:dts'\n ? 'node'\n : runtime === 'node'\n ? 'node'\n : runtime === 'browser'\n ? 'browser'\n : 'neutral',\n\n resolve: {\n alias: pathAliases,\n },\n tsconfig: ctx.ts.configPath || 'tsconfig.json',\n experimental: {\n attachDebugInfo: 'none',\n },\n\n external: (id, importer) => {\n if (\n buildTask.type === 'rolldown:dts' &&\n ctx.bundledPackages.length > 0 &&\n !id.startsWith('.') &&\n (id.includes('/node_modules/') || id.split('/').length < 3)\n ) {\n return !ctx.bundledPackages.some((name) => name === id || id.includes(`/${name}/`))\n }\n\n // Check if the id is a self-referencing import\n if (exportIds?.includes(id)) {\n return true\n }\n\n // Check if the id is a file path that points to an exported source file\n if (importer && (id.startsWith('.') || id.startsWith('/'))) {\n const idPath = path.resolve(path.dirname(importer), id)\n\n if (sourcePaths?.includes(idPath)) {\n logger.warn(\n `detected self-referencing import – treating as external: ${path.relative(\n cwd,\n idPath,\n )}`,\n )\n\n return true\n }\n }\n\n return external.some((name) => name === id || id.includes(`/node_modules/${name}/`))\n },\n\n input: entries.reduce<{[entryAlias: string]: string}>(\n (acc, entry) => Object.assign(acc, {[entry.name]: entry.source}),\n {},\n ),\n\n plugins: [\n dtsPlugin({\n emitDtsOnly: true,\n tsconfig: ctx.ts.configPath || 'tsconfig.json',\n tsgo:\n typeof pkg.devDependencies === 'object' &&\n
|
|
1
|
+
{"version":3,"file":"resolveRolldownConfig.js","sources":["../../src/node/tasks/rolldown/resolveRolldownConfig.ts"],"sourcesContent":["import path from 'node:path'\nimport type {InputOptions, OutputOptions} from 'rolldown'\nimport {dts as dtsPlugin} from 'rolldown-plugin-dts'\nimport type {BuildContext} from '../../core/contexts/buildContext.ts'\nimport {pkgExtMap as extMap} from '../../core/pkg/pkgExt.ts'\nimport type {RolldownDtsTask} from '../types.ts'\n\nexport interface RolldownConfig {\n inputOptions: InputOptions\n outputOptions: OutputOptions\n}\n\nexport function resolveRolldownConfig(\n ctx: BuildContext,\n buildTask: RolldownDtsTask,\n): RolldownConfig {\n const {format, runtime} = buildTask\n const {config, cwd, exports: _exports, external, distPath, logger, pkg, ts} = ctx\n const outputExt = extMap[pkg.type || 'commonjs'][format]\n const outDir = path.relative(cwd, distPath)\n\n const pathAliases = Object.fromEntries(\n Object.entries(ts.config?.options.paths || {}).map(([key, val]) => {\n return [key, path.resolve(cwd, ts.config?.options.baseUrl || '.', val[0]!)]\n }),\n )\n\n const entries = buildTask.entries.map((entry) => {\n return {\n ...entry,\n name: path.relative(outDir, entry.output).replace(/\\.[^/.]+$/, ''),\n }\n }, {})\n\n const exportIds =\n _exports && Object.keys(_exports).map((exportPath) => path.join(pkg.name, exportPath))\n\n const sourcePaths = _exports && Object.values(_exports).map((e) => path.resolve(cwd, e.source))\n\n const replacements = Object.fromEntries(\n Object.entries(config?.define || {}).map(([key, val]) => [key, JSON.stringify(val)]),\n )\n\n const entryFileNames = `[name]${outputExt}`\n\n const inputOptions = {\n cwd,\n transform: {\n define:\n pkg.name === '@sanity/pkg-utils'\n ? {...replacements}\n : {\n 'process.env.PKG_FORMAT': JSON.stringify(format),\n 'process.env.PKG_RUNTIME': JSON.stringify(runtime),\n 'process.env.PKG_VERSION': JSON.stringify(process.env['PKG_VERSION'] || pkg.version),\n ...replacements,\n },\n },\n\n platform:\n buildTask.type === 'rolldown:dts'\n ? 'node'\n : runtime === 'node'\n ? 'node'\n : runtime === 'browser'\n ? 'browser'\n : 'neutral',\n\n resolve: {\n alias: pathAliases,\n },\n tsconfig: ctx.ts.configPath || 'tsconfig.json',\n experimental: {\n attachDebugInfo: 'none',\n },\n\n external: (id, importer) => {\n if (\n buildTask.type === 'rolldown:dts' &&\n ctx.bundledPackages.length > 0 &&\n !id.startsWith('.') &&\n (id.includes('/node_modules/') || id.split('/').length < 3)\n ) {\n return !ctx.bundledPackages.some((name) => name === id || id.includes(`/${name}/`))\n }\n\n // Check if the id is a self-referencing import\n if (exportIds?.includes(id)) {\n return true\n }\n\n // Check if the id is a file path that points to an exported source file\n if (importer && (id.startsWith('.') || id.startsWith('/'))) {\n const idPath = path.resolve(path.dirname(importer), id)\n\n if (sourcePaths?.includes(idPath)) {\n logger.warn(\n `detected self-referencing import – treating as external: ${path.relative(\n cwd,\n idPath,\n )}`,\n )\n\n return true\n }\n }\n\n return external.some((name) => name === id || id.includes(`/node_modules/${name}/`))\n },\n\n input: entries.reduce<{[entryAlias: string]: string}>(\n (acc, entry) => Object.assign(acc, {[entry.name]: entry.source}),\n {},\n ),\n\n plugins: [\n dtsPlugin({\n emitDtsOnly: true,\n tsconfig: ctx.ts.configPath || 'tsconfig.json',\n tsgo:\n config?.tsgo !== undefined\n ? config.tsgo\n : typeof pkg.devDependencies === 'object' &&\n '@typescript/native-preview' in pkg.devDependencies,\n // Enable the resolver by giving an allow list of packages to dig through node_modules.\n // If there are none that should be resolved, then this process is skipped and our build is faster.\n // If there's a match then it'll call the resolver function defined on `inputOptions.external`\n resolve: ctx.bundledPackages,\n // Always create dts from scratch, don't reuse contexts from previous builds\n newContext: true,\n }),\n ],\n\n treeshake: {\n moduleSideEffects: 'no-external',\n unknownGlobalSideEffects: false,\n annotations: true,\n },\n } satisfies InputOptions\n const outputOptions = {\n dir: outDir,\n entryFileNames,\n chunkFileNames:\n buildTask.type === 'rolldown:dts' ? `_chunks-dts/[name]${outputExt}` : undefined,\n esModule: true,\n format: buildTask.type === 'rolldown:dts' ? 'es' : format,\n sourcemap: buildTask.type === 'rolldown:dts' ? false : (config?.sourcemap ?? true),\n hoistTransitiveImports: false,\n /**\n * rolldown doesn't permit disabling chunks, we can only choose between automatic chunking (the default)\n * and manual chunking (using advancedChunks).\n * This matters for how we generate dts files.\n * While we use rolldown for dts generation, and rollup for the rest, we want to reduce the amount of dts files emitted as chunks,\n * and to make them predictable in how they're generated.\n */\n // @TODO the following breaks the dts generation, report bug to rolldown\n // advancedChunks:\n // buildTask.type === 'rolldown:dts'\n // ? {\n // groups: [\n // {\n // /**\n // * Groups all inlined typings specified by bundledPackages in extract.bundledPackages to its own chunk.\n // */\n // name: 'bundled-packages',\n // test: (id) => ctx.bundledPackages.includes(id),\n // priority: 1,\n // },\n // {\n // /**\n // * Put all other shared chunks into a single chunk.\n // */\n // name: 'shared',\n // minShareCount: 1,\n // },\n // ],\n // }\n // : {},\n } satisfies OutputOptions\n\n return {inputOptions, outputOptions}\n}\n"],"names":["extMap","dtsPlugin"],"mappings":";;;AAYO,SAAS,sBACd,KACA,WACgB;AAChB,QAAM,EAAC,QAAQ,QAAA,IAAW,WACpB,EAAC,QAAQ,KAAK,SAAS,UAAU,UAAU,UAAU,QAAQ,KAAK,GAAA,IAAM,KACxE,YAAYA,UAAO,IAAI,QAAQ,UAAU,EAAE,MAAM,GACjD,SAAS,KAAK,SAAS,KAAK,QAAQ,GAEpC,cAAc,OAAO;AAAA,IACzB,OAAO,QAAQ,GAAG,QAAQ,QAAQ,SAAS,CAAA,CAAE,EAAE,IAAI,CAAC,CAAC,KAAK,GAAG,MACpD,CAAC,KAAK,KAAK,QAAQ,KAAK,GAAG,QAAQ,QAAQ,WAAW,KAAK,IAAI,CAAC,CAAE,CAAC,CAC3E;AAAA,EAAA,GAGG,U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Q,aAAa;AAAA,IAC7E,wBAAwB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAAA;AAiC1B,SAAO,EAAC,cAAc,cAAA;AACxB;"}
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { cac } from "cac";
|
|
2
|
-
var version = "9.
|
|
2
|
+
var version = "9.2.0";
|
|
3
3
|
const cli = cac();
|
|
4
4
|
cli.command("", "Check").alias("check").option("--strict", "Strict mode").option("--tsconfig [tsconfig]", "[string] tsconfig.json").action(async (options) => {
|
|
5
5
|
const { checkAction } = await import("./_chunks-es/checkAction.js");
|
package/dist/index.d.ts
CHANGED
|
@@ -311,6 +311,13 @@ interface PkgConfigOptions {
|
|
|
311
311
|
* @defaultValue 'api-extractor'
|
|
312
312
|
*/
|
|
313
313
|
dts?: DtsType;
|
|
314
|
+
/**
|
|
315
|
+
* When using `dts: 'rolldown'`, enables the use of `@typescript/native-preview` for type generation.
|
|
316
|
+
* By default, `tsgo` is automatically enabled if `@typescript/native-preview` is found in `devDependencies`.
|
|
317
|
+
* Set to `true` to explicitly enable or `false` to explicitly disable.
|
|
318
|
+
* @alpha
|
|
319
|
+
*/
|
|
320
|
+
tsgo?: boolean;
|
|
314
321
|
}
|
|
315
322
|
/** @public */
|
|
316
323
|
declare function defineConfig<const T extends PkgConfigOptions>(configOptions: T): T;
|