@sanity/pkg-utils 6.11.15 → 6.12.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/pkg-utils",
3
- "version": "6.11.15",
3
+ "version": "6.12.0",
4
4
  "description": "Simple utilities for modern npm packages.",
5
5
  "keywords": [
6
6
  "sanity-io",
@@ -146,7 +146,7 @@
146
146
  "typescript": "5.7.2",
147
147
  "vitest": "^2.1.6",
148
148
  "vitest-github-actions-reporter": "^0.11.1",
149
- "@sanity/pkg-utils": "6.11.15"
149
+ "@sanity/pkg-utils": "6.12.0"
150
150
  },
151
151
  "peerDependencies": {
152
152
  "babel-plugin-react-compiler": "*",
@@ -1,3 +1,6 @@
1
+ import {existsSync} from 'node:fs'
2
+ import {resolve as resolvePath} from 'node:path'
3
+
1
4
  import type {Logger} from '../../logger'
2
5
  import type {InferredStrictOptions} from '../../strict'
3
6
  import {defaultEnding, fileEnding, legacyEnding} from '../../tasks/dts/getTargetPaths'
@@ -9,13 +12,14 @@ import {validateExports} from './validateExports'
9
12
 
10
13
  /** @internal */
11
14
  export function parseExports(options: {
15
+ cwd: string
12
16
  pkg: PackageJSON
13
17
  strict: boolean
14
18
  strictOptions: InferredStrictOptions
15
19
  legacyExports: boolean
16
20
  logger: Logger
17
21
  }): (PkgExport & {_path: string})[] {
18
- const {pkg, strict, strictOptions, legacyExports, logger} = options
22
+ const {cwd, pkg, strict, strictOptions, legacyExports, logger} = options
19
23
  const type = pkg.type || 'commonjs'
20
24
  const errors: string[] = []
21
25
 
@@ -169,9 +173,19 @@ export function parseExports(options: {
169
173
  ) {
170
174
  if (exportPath === './package.json') {
171
175
  if (exportEntry !== './package.json') {
172
- errors.push('package.json: `exports["./package.json"] must be "./package.json".')
176
+ errors.push('package.json: `exports["./package.json"]` must be "./package.json".')
173
177
  }
174
178
  }
179
+ } else if (exportPath.endsWith('.css')) {
180
+ if (typeof exportEntry === 'string' && !existsSync(resolvePath(cwd, exportEntry))) {
181
+ errors.push(
182
+ `package.json: \`exports[${JSON.stringify(exportPath)}]\`: file does not exist.`,
183
+ )
184
+ } else if (typeof exportEntry !== 'string') {
185
+ errors.push(
186
+ `package.json: \`exports[${JSON.stringify(exportPath)}]\`: export conditions not supported for CSS files.`,
187
+ )
188
+ }
175
189
  } else if (isRecord(exportEntry) && 'svelte' in exportEntry) {
176
190
  // @TODO should we report a warning or a debug message here about a detected svelte export that is ignored?
177
191
  } else if (isPkgExport(exportEntry)) {
@@ -14,6 +14,7 @@ export interface PackageJSON {
14
14
  exports?: Record<
15
15
  string,
16
16
  | `./${string}.json`
17
+ | `./${string}.css`
17
18
  | {
18
19
  source?: string
19
20
  types?: string
@@ -20,6 +20,7 @@ const pkgSchema = z.object({
20
20
  z.record(
21
21
  z.union([
22
22
  z.custom<`./${string}.json`>((val) => /^\.\/.*\.json$/.test(val as string)),
23
+ z.custom<`./${string}.css`>((val) => /^\.\/.*\.css$/.test(val as string)),
23
24
  z.object({
24
25
  'types': z.optional(z.string()),
25
26
  'source': z.optional(z.string()),
@@ -93,6 +93,7 @@ export async function resolveBuildContext(options: {
93
93
  }
94
94
 
95
95
  const parsedExports = parseExports({
96
+ cwd,
96
97
  pkg,
97
98
  strict,
98
99
  legacyExports: config?.legacyExports ?? false,