@sanity/pkg-utils 6.11.14 → 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/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import path, { relative, resolve, dirname } from "node:path";
1
+ import path, { resolve, relative, dirname } from "node:path";
2
2
  import rimraf from "rimraf";
3
3
  import { register } from "esbuild-register/dist/node";
4
4
  import pkgUp from "pkg-up";
5
5
  import findConfig from "find-config";
6
- import fs$1, { statSync } from "node:fs";
6
+ import fs$1, { statSync, existsSync } from "node:fs";
7
7
  import { z, ZodError } from "zod";
8
8
  import chalk from "chalk";
9
9
  import fs, { writeFile, readFile, readdir, lstat } from "node:fs/promises";
@@ -101,6 +101,7 @@ const pkgSchema = z.object({
101
101
  z.record(
102
102
  z.union([
103
103
  z.custom((val) => /^\.\/.*\.json$/.test(val)),
104
+ z.custom((val) => /^\.\/.*\.css$/.test(val)),
104
105
  z.object({
105
106
  types: z.optional(z.string()),
106
107
  source: z.optional(z.string()),
@@ -282,7 +283,7 @@ function validateExports(_exports, options) {
282
283
  return errors;
283
284
  }
284
285
  function parseExports(options) {
285
- const { pkg, strict, strictOptions: strictOptions2, legacyExports, logger } = options, type = pkg.type || "commonjs", errors = [], report = (kind, message) => {
286
+ const { cwd, pkg, strict, strictOptions: strictOptions2, legacyExports, logger } = options, type = pkg.type || "commonjs", errors = [], report = (kind, message) => {
286
287
  kind === "warn" ? logger.warn(message) : errors.push(message);
287
288
  };
288
289
  if (!pkg.main && strict && strictOptions2.alwaysPackageJsonMain !== "off" && report(strictOptions2.alwaysPackageJsonMain, "package.json: `main` must be declared"), !Array.isArray(pkg.files) && strict && strictOptions2.alwaysPackageJsonFiles !== "off" && report(
@@ -369,7 +370,13 @@ function parseExports(options) {
369
370
  ), strict && !pkg.exports["./package.json"] && errors.push('package.json: `exports["./package.json"] must be declared.');
370
371
  for (const [exportPath, exportEntry] of Object.entries(pkg.exports))
371
372
  if (exportPath.endsWith(".json") || typeof exportEntry == "string" && exportEntry.endsWith(".json"))
372
- exportPath === "./package.json" && exportEntry !== "./package.json" && errors.push('package.json: `exports["./package.json"] must be "./package.json".');
373
+ exportPath === "./package.json" && exportEntry !== "./package.json" && errors.push('package.json: `exports["./package.json"]` must be "./package.json".');
374
+ else if (exportPath.endsWith(".css"))
375
+ typeof exportEntry == "string" && !existsSync(resolve(cwd, exportEntry)) ? errors.push(
376
+ `package.json: \`exports[${JSON.stringify(exportPath)}]\`: file does not exist.`
377
+ ) : typeof exportEntry != "string" && errors.push(
378
+ `package.json: \`exports[${JSON.stringify(exportPath)}]\`: export conditions not supported for CSS files.`
379
+ );
373
380
  else if (!(isRecord(exportEntry) && "svelte" in exportEntry))
374
381
  if (isPkgExport(exportEntry)) {
375
382
  const exp = {
@@ -593,6 +600,7 @@ async function resolveBuildContext(options) {
593
600
  browser: webTarget,
594
601
  node: nodeTarget
595
602
  }, parsedExports = parseExports({
603
+ cwd,
596
604
  pkg,
597
605
  strict,
598
606
  legacyExports: config2?.legacyExports ?? !1,