@sanity/pkg-utils 6.13.4 → 7.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.
Files changed (39) hide show
  1. package/dist/_chunks-cjs/build.cjs +6 -41
  2. package/dist/_chunks-cjs/build.cjs.map +1 -1
  3. package/dist/_chunks-cjs/check.cjs +3 -3
  4. package/dist/_chunks-cjs/check.cjs.map +1 -1
  5. package/dist/_chunks-cjs/consoleSpy.cjs +22 -59
  6. package/dist/_chunks-cjs/consoleSpy.cjs.map +1 -1
  7. package/dist/_chunks-cjs/index.cjs +20 -86
  8. package/dist/_chunks-cjs/index.cjs.map +1 -1
  9. package/dist/_chunks-cjs/logger.cjs +2 -2
  10. package/dist/_chunks-cjs/logger.cjs.map +1 -1
  11. package/dist/_chunks-cjs/watch.cjs +5 -21
  12. package/dist/_chunks-cjs/watch.cjs.map +1 -1
  13. package/dist/cli.cjs +1 -1
  14. package/dist/index.cjs +0 -1
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +4 -23
  17. package/dist/index.d.ts +4 -23
  18. package/dist/index.js +49 -201
  19. package/dist/index.js.map +1 -1
  20. package/package.json +3 -3
  21. package/src/node/build.ts +1 -2
  22. package/src/node/check.ts +1 -2
  23. package/src/node/core/config/types.ts +3 -4
  24. package/src/node/core/pkg/loadPkgWithReporting.ts +2 -10
  25. package/src/node/core/pkg/parseExports.ts +7 -46
  26. package/src/node/core/pkg/pkgExt.ts +1 -4
  27. package/src/node/core/pkg/validateExports.ts +0 -1
  28. package/src/node/resolveBuildContext.ts +0 -1
  29. package/src/node/resolveBuildTasks.ts +4 -62
  30. package/src/node/resolveWatchTasks.ts +1 -23
  31. package/src/node/tasks/dts/createApiExtractorConfig.ts +12 -32
  32. package/src/node/tasks/dts/getExtractMessagesConfig.ts +5 -1
  33. package/src/node/tasks/dts/getTargetPaths.ts +0 -2
  34. package/src/node/tasks/index.ts +1 -2
  35. package/src/node/tasks/rollup/index.ts +0 -1
  36. package/src/node/tasks/rollup/resolveRollupConfig.ts +5 -10
  37. package/src/node/tasks/types.ts +1 -12
  38. package/src/node/watch.ts +1 -2
  39. package/src/node/tasks/rollup/rollupLegacyTask.ts +0 -145
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
- var path = require("node:path"), rimraf = require("rimraf"), consoleSpy = require("./consoleSpy.cjs"), logger = require("./logger.cjs"), fs = require("node:fs"), chalk = require("chalk"), index = require("./index.cjs");
2
+ var path = require("node:path"), rimraf = require("rimraf"), consoleSpy = require("./consoleSpy.cjs"), logger = require("./logger.cjs"), chalk = require("chalk"), index = require("./index.cjs");
3
3
  function _interopDefaultCompat(e) {
4
4
  return e && typeof e == "object" && "default" in e ? e : { default: e };
5
5
  }
6
- var path__default = /* @__PURE__ */ _interopDefaultCompat(path), rimraf__default = /* @__PURE__ */ _interopDefaultCompat(rimraf), fs__default = /* @__PURE__ */ _interopDefaultCompat(fs), chalk__default = /* @__PURE__ */ _interopDefaultCompat(chalk);
6
+ var path__default = /* @__PURE__ */ _interopDefaultCompat(path), rimraf__default = /* @__PURE__ */ _interopDefaultCompat(rimraf), chalk__default = /* @__PURE__ */ _interopDefaultCompat(chalk);
7
7
  function resolveBuildTasks(ctx) {
8
- const { config, cwd, pkg, target } = ctx, bundles = config?.bundles || [], tasks = [], exports2 = Object.entries(ctx.exports || {}).map(
8
+ const { config, pkg, target } = ctx, bundles = config?.bundles || [], tasks = [], exports2 = Object.entries(ctx.exports || {}).map(
9
9
  ([_path, exp]) => ({ _path, ...exp })
10
10
  ), dtsTask = {
11
11
  type: "build:dts",
12
12
  entries: []
13
- }, rollupTasks = {}, rollupLegacyTasks = {};
13
+ }, rollupTasks = {};
14
14
  function addRollupTaskEntry(format, runtime, entry) {
15
15
  const buildId = `${format}:${runtime}`;
16
16
  rollupTasks[buildId] ? rollupTasks[buildId].entries.push(entry) : rollupTasks[buildId] = {
@@ -22,18 +22,6 @@ function resolveBuildTasks(ctx) {
22
22
  target: target[runtime]
23
23
  };
24
24
  }
25
- function addRollupLegacyTaskEntry(runtime, entry) {
26
- const buildId = `esm:${runtime}`;
27
- rollupLegacyTasks[buildId] ? rollupLegacyTasks[buildId].entries.push(entry) : rollupLegacyTasks[buildId] = {
28
- type: "build:legacy",
29
- buildId,
30
- entries: [entry],
31
- runtime,
32
- format: "esm",
33
- // @TODO set a different target here that is compatible with legacy bundlers and testing tools like brownfield jest
34
- target: target[runtime]
35
- };
36
- }
37
25
  for (const exp of exports2) {
38
26
  const importId = path__default.default.join(pkg.name, exp._path);
39
27
  exp.source?.endsWith(".ts") && dtsTask.entries.push({
@@ -96,17 +84,6 @@ function resolveBuildTasks(ctx) {
96
84
  output
97
85
  });
98
86
  }
99
- if (config?.legacyExports)
100
- for (const exp of exports2) {
101
- const runtime = exp.browser?.import ? "browser" : ctx.runtime, output = exp.browser?.import || exp.import;
102
- if (!output) continue;
103
- const legacyOutput = output.replace(consoleSpy.fileEnding, consoleSpy.legacyEnding);
104
- addRollupLegacyTaskEntry(runtime, {
105
- path: exp._path,
106
- source: exp.browser?.source || exp.source,
107
- output: legacyOutput
108
- });
109
- }
110
87
  for (const bundle of bundles) {
111
88
  const idx = bundles.indexOf(bundle);
112
89
  bundle.require && addRollupTaskEntry("commonjs", bundle.runtime || ctx.runtime, {
@@ -119,19 +96,7 @@ function resolveBuildTasks(ctx) {
119
96
  output: bundle.import
120
97
  });
121
98
  }
122
- if (tasks.push(...Object.values(rollupTasks), ...Object.values(rollupLegacyTasks)), config?.legacyExports) {
123
- for (const exp of exports2)
124
- if (exp._exported && exp._path !== ".") {
125
- const relativeTargetPath = (exp.browser?.import || exp.import || "").replace(consoleSpy.fileEnding, consoleSpy.legacyEnding).replace(/\.[^/.]+$/, "");
126
- relativeTargetPath && fs__default.default.writeFileSync(
127
- path__default.default.resolve(cwd, `${exp._path}.js`),
128
- ["// AUTO-GENERATED \u2013 DO NOT EDIT", `export * from '${relativeTargetPath}'`, ""].join(
129
- `
130
- `
131
- )
132
- );
133
- }
134
- }
99
+ tasks.push(...Object.values(rollupTasks));
135
100
  }
136
101
  return tasks;
137
102
  }
@@ -153,7 +118,7 @@ async function build(options) {
153
118
  strict = !1,
154
119
  tsconfig: tsconfigOption,
155
120
  clean = !1
156
- } = options, logger$1 = logger.createLogger(), config = await consoleSpy.loadConfig({ cwd }), legacyExports = config?.legacyExports ?? !1, pkg = await consoleSpy.loadPkgWithReporting({ cwd, logger: logger$1, strict, legacyExports }), tsconfig = tsconfigOption || config?.tsconfig || "tsconfig.json", ctx = await consoleSpy.resolveBuildContext({
121
+ } = options, logger$1 = logger.createLogger(), config = await consoleSpy.loadConfig({ cwd }), pkg = await consoleSpy.loadPkgWithReporting({ cwd, logger: logger$1, strict }), tsconfig = tsconfigOption || config?.tsconfig || "tsconfig.json", ctx = await consoleSpy.resolveBuildContext({
157
122
  config,
158
123
  cwd,
159
124
  emitDeclarationOnly,
@@ -1 +1 @@
1
- {"version":3,"file":"build.cjs","sources":["../../src/node/resolveBuildTasks.ts","../../src/node/spinner.ts","../../src/node/build.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\n\nimport type {BuildContext, PkgExport, PkgFormat, PkgRuntime} from './core'\nimport type {BuildTask, DtsTask, RollupLegacyTask, RollupTask, RollupTaskEntry} from './tasks'\nimport {fileEnding, getTargetPaths, legacyEnding} from './tasks/dts/getTargetPaths'\n\n/** @internal */\nexport function resolveBuildTasks(ctx: BuildContext): BuildTask[] {\n const {config, cwd, 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 rollupTasks: Record<string, RollupTask> = {}\n const rollupLegacyTasks: Record<string, RollupLegacyTask> = {}\n\n function addRollupTaskEntry(format: PkgFormat, runtime: PkgRuntime, entry: RollupTaskEntry) {\n const buildId = `${format}:${runtime}`\n\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 function addRollupLegacyTaskEntry(runtime: PkgRuntime, entry: RollupTaskEntry) {\n const buildId = `esm:${runtime}`\n\n if (rollupLegacyTasks[buildId]) {\n rollupLegacyTasks[buildId].entries.push(entry)\n } else {\n rollupLegacyTasks[buildId] = {\n type: 'build:legacy',\n buildId,\n entries: [entry],\n runtime,\n format: 'esm',\n // @TODO set a different target here that is compatible with legacy bundlers and testing tools like brownfield jest\n target: target[runtime],\n }\n }\n }\n\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 if (!ctx.emitDeclarationOnly) {\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 // Create rollup bundles that legacy export files will re-export\n if (config?.legacyExports) {\n for (const exp of exports) {\n const runtime = exp.browser?.import ? 'browser' : ctx.runtime\n const output = exp.browser?.import || exp.import\n\n if (!output) continue\n\n // Change the suffix to what the legacy exports will use\n const legacyOutput = output.replace(fileEnding, legacyEnding)\n\n addRollupLegacyTaskEntry(runtime, {\n path: exp._path,\n source: exp.browser?.source || exp.source,\n output: legacyOutput,\n })\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 tasks.push(...Object.values(rollupTasks), ...Object.values(rollupLegacyTasks))\n\n // Write legacy exports files\n if (config?.legacyExports) {\n for (const exp of exports) {\n if (exp._exported && exp._path !== '.') {\n const output = (exp.browser?.import || exp.import || '').replace(fileEnding, legacyEnding)\n const relativeTargetPath = output.replace(/\\.[^/.]+$/, '')\n\n if (relativeTargetPath) {\n fs.writeFileSync(\n path.resolve(cwd, `${exp._path}.js`),\n ['// AUTO-GENERATED – DO NOT EDIT', `export * from '${relativeTargetPath}'`, ''].join(\n '\\n',\n ),\n )\n }\n }\n }\n }\n }\n\n return tasks\n}\n","/* eslint-disable no-console */\n\nimport chalk from 'chalk'\n\nexport function createSpinner(msg: string): {complete: () => void; error: () => void} {\n const startTime = Date.now()\n\n console.log(msg)\n\n return {\n complete: () => {\n console.log(`${chalk.green('[success]')} ${chalk.gray(`${Date.now() - startTime}ms`)}`)\n },\n error: () => {\n console.log(`${chalk.red('[error]')} ${chalk.gray(`${Date.now() - startTime}ms`)}`)\n },\n }\n}\n","import path from 'node:path'\n\nimport rimraf from 'rimraf'\n\nimport {loadConfig, loadPkgWithReporting} from './core'\nimport {createLogger} from './logger'\nimport {resolveBuildContext} from './resolveBuildContext'\nimport {resolveBuildTasks} from './resolveBuildTasks'\nimport {createSpinner} from './spinner'\nimport {type BuildTask, buildTaskHandlers, type TaskHandler} from './tasks'\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}): Promise<void> {\n const {\n cwd,\n emitDeclarationOnly,\n strict = false,\n tsconfig: tsconfigOption,\n clean = false,\n } = options\n const logger = createLogger()\n\n const config = await loadConfig({cwd})\n\n const legacyExports = config?.legacyExports ?? false\n const pkg = await loadPkgWithReporting({cwd, logger, strict, legacyExports})\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 logger.log(\n `Deleting the \\`dist\\` folder: './${path.relative(cwd, ctx.distPath)}' before building...`,\n )\n await rimraf(ctx.distPath)\n }\n\n const buildTasks = resolveBuildTasks(ctx)\n\n for (const task of buildTasks) {\n const handler = buildTaskHandlers[task.type] as TaskHandler<BuildTask>\n const taskName = handler.name(ctx, task)\n\n const spinner = createSpinner(taskName)\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","path","getTargetPaths","fileEnding","legacyEnding","fs","chalk","logger","createLogger","loadConfig","loadPkgWithReporting","resolveBuildContext","rimraf","buildTaskHandlers"],"mappings":";;;;;;AAQO,SAAS,kBAAkB,KAAgC;AAC1D,QAAA,EAAC,QAAQ,KAAK,KAAK,WAAU,KAE7B,UAAU,QAAQ,WAAW,IAE7B,QAAqB,CAAA,GAErBA,WAAU,OAAO,QAAQ,IAAI,WAAW,CAAE,CAAA,EAAE;AAAA,IAChD,CAAC,CAAC,OAAO,GAAG,OAAO,EAAC,OAAO,GAAG,IAAG;AAAA,KAG7B,UAAmB;AAAA,IACvB,MAAM;AAAA,IACN,SAAS,CAAA;AAAA,EAAC,GAGN,cAA0C,IAC1C,oBAAsD,CAAC;AAEpD,WAAA,mBAAmB,QAAmB,SAAqB,OAAwB;AAC1F,UAAM,UAAU,GAAG,MAAM,IAAI,OAAO;AAEhC,gBAAY,OAAO,IACrB,YAAY,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AA,SAAA,GACR,IAAI,OAAO,OAEX,QAAQ,SAAS,KAAK,MAAM,MAAM;AAAA,aAC3B,KAAK;AAGZ,UAFA,QAAQ,SAEJ,eAAe,OAAO;AACxB,cAAM,SAAS,IAAI,OAAO,GAAG,GAAG,IAAI,GAAG;AAEnC,YAAA,OAAO,MAAM,IAAI,QAAQ,QAAQ,QAAQ,GAAG,CAAC,GACjD,IAAI,OAAO,IAAI;AAAA,MAAA;AAGjB,cAAQ,MAAM,KAAK,MAAM,GAAG,GAE5B,QAAQ,KAAK,CAAC;AAAA,IAAA;AAAA,EAChB;AAEJ;;;"}
1
+ {"version":3,"file":"build.cjs","sources":["../../src/node/resolveBuildTasks.ts","../../src/node/spinner.ts","../../src/node/build.ts"],"sourcesContent":["import path from 'node:path'\n\nimport type {BuildContext, PkgExport, PkgFormat, PkgRuntime} from './core'\nimport type {BuildTask, DtsTask, RollupTask, RollupTaskEntry} from './tasks'\nimport {getTargetPaths} from './tasks/dts/getTargetPaths'\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 rollupTasks: Record<string, RollupTask> = {}\n\n function addRollupTaskEntry(format: PkgFormat, runtime: PkgRuntime, entry: RollupTaskEntry) {\n const buildId = `${format}:${runtime}`\n\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 // 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 if (!ctx.emitDeclarationOnly) {\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 tasks.push(...Object.values(rollupTasks))\n }\n\n return tasks\n}\n","/* eslint-disable no-console */\n\nimport chalk from 'chalk'\n\nexport function createSpinner(msg: string): {complete: () => void; error: () => void} {\n const startTime = Date.now()\n\n console.log(msg)\n\n return {\n complete: () => {\n console.log(`${chalk.green('[success]')} ${chalk.gray(`${Date.now() - startTime}ms`)}`)\n },\n error: () => {\n console.log(`${chalk.red('[error]')} ${chalk.gray(`${Date.now() - startTime}ms`)}`)\n },\n }\n}\n","import path from 'node:path'\n\nimport rimraf from 'rimraf'\n\nimport {loadConfig, loadPkgWithReporting} from './core'\nimport {createLogger} from './logger'\nimport {resolveBuildContext} from './resolveBuildContext'\nimport {resolveBuildTasks} from './resolveBuildTasks'\nimport {createSpinner} from './spinner'\nimport {type BuildTask, buildTaskHandlers, type TaskHandler} from './tasks'\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}): Promise<void> {\n const {\n cwd,\n emitDeclarationOnly,\n strict = false,\n tsconfig: tsconfigOption,\n clean = false,\n } = options\n const logger = createLogger()\n\n const config = await loadConfig({cwd})\n\n const pkg = await loadPkgWithReporting({cwd, logger, strict})\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 logger.log(\n `Deleting the \\`dist\\` folder: './${path.relative(cwd, ctx.distPath)}' before building...`,\n )\n await rimraf(ctx.distPath)\n }\n\n const buildTasks = resolveBuildTasks(ctx)\n\n for (const task of buildTasks) {\n const handler = buildTaskHandlers[task.type] as TaskHandler<BuildTask>\n const taskName = handler.name(ctx, task)\n\n const spinner = createSpinner(taskName)\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","path","getTargetPaths","chalk","logger","createLogger","loadConfig","loadPkgWithReporting","resolveBuildContext","rimraf","buildTaskHandlers"],"mappings":";;;;;;AAOO,SAAS,kBAAkB,KAAgC;AAC1D,QAAA,EAAC,QAAQ,KAAK,OAAA,IAAU,KAExB,UAAU,QAAQ,WAAW,CAAA,GAE7B,QAAqB,IAErBA,WAAU,OAAO,QAAQ,IAAI,WAAW,CAAE,CAAA,EAAE;AAAA,IAChD,CAAC,CAAC,OAAO,GAAG,OAAO,EAAC,OAAO,GAAG,IAAG;AAAA,KAG7B,UAAmB;AAAA,IACvB,MAAM;AAAA,IACN,SAAS,CAAA;AAAA,EACX,GAEM,cAA0C,CAAC;AAExC,WAAA,mBAAmB,QAAmB,SAAqB,OAAwB;AAC1F,UAAM,UAAU,GAAG,MAAM,IAAI,OAAO;AAEhC,gBAAY,OAAO,IACrB,YAAY,OAAO,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AAQ;AAElC,QAAA;AACF,YAAM,SAAS,MAAM,QAAQ,KAAK,KAAK,IAAI,EAAE,UAAU;AAE/C,cAAA,SAAA,GACR,IAAI,OAAO,OAEX,QAAQ,SAAS,KAAK,MAAM,MAAM;AAAA,aAC3B,KAAK;AAGZ,UAFA,QAAQ,SAEJ,eAAe,OAAO;AACxB,cAAM,SAAS,IAAI,OAAO,GAAG,GAAG,IAAI,GAAG;AAEnC,YAAA,OAAO,MAAM,IAAI,QAAQ,QAAQ,QAAQ,GAAG,CAAC,GACjD,IAAI,OAAO,IAAI;AAAA,MAAA;AAGjB,cAAQ,MAAM,KAAK,MAAM,GAAG,GAE5B,QAAQ,KAAK,CAAC;AAAA,IAAA;AAAA,EAChB;AAEJ;;;"}
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
- var path = require("node:path"), esbuild = require("esbuild"), consoleSpy = require("./consoleSpy.cjs"), logger = require("./logger.cjs"), chalk = require("chalk"), treeify = require("treeify"), fs = require("node:fs"), prettyBytes = require("pretty-bytes");
2
+ var path = require("node:path"), esbuild = require("esbuild"), consoleSpy = require("./consoleSpy.cjs"), logger = require("./logger.cjs"), chalk = require("chalk"), treeify = require("treeify"), node_fs = require("node:fs"), prettyBytes = require("pretty-bytes");
3
3
  function _interopDefaultCompat(e) {
4
4
  return e && typeof e == "object" && "default" in e ? e : { default: e };
5
5
  }
6
6
  var path__default = /* @__PURE__ */ _interopDefaultCompat(path), esbuild__default = /* @__PURE__ */ _interopDefaultCompat(esbuild), chalk__default = /* @__PURE__ */ _interopDefaultCompat(chalk), treeify__default = /* @__PURE__ */ _interopDefaultCompat(treeify), prettyBytes__default = /* @__PURE__ */ _interopDefaultCompat(prettyBytes);
7
7
  function getFilesize(file) {
8
- const stats = fs.statSync(file);
8
+ const stats = node_fs.statSync(file);
9
9
  return prettyBytes__default.default(stats.size);
10
10
  }
11
11
  function getFileInfo(cwd, filePath) {
@@ -39,7 +39,7 @@ function printPackageTree(ctx) {
39
39
  ), logger2.log(treeify__default.default.asTree(tree, !0, !0));
40
40
  }
41
41
  async function check(options) {
42
- const { cwd, strict = !1, tsconfig: tsconfigOption } = options, logger$1 = logger.createLogger(), config = await consoleSpy.loadConfig({ cwd }), legacyExports = config?.legacyExports ?? !1, pkg = await consoleSpy.loadPkgWithReporting({ cwd, logger: logger$1, strict, legacyExports }), tsconfig = tsconfigOption || config?.tsconfig || "tsconfig.json", ctx = await consoleSpy.resolveBuildContext({ config, cwd, logger: logger$1, pkg, strict, tsconfig });
42
+ const { cwd, strict = !1, tsconfig: tsconfigOption } = options, logger$1 = logger.createLogger(), config = await consoleSpy.loadConfig({ cwd }), pkg = await consoleSpy.loadPkgWithReporting({ cwd, logger: logger$1, strict }), tsconfig = tsconfigOption || config?.tsconfig || "tsconfig.json", ctx = await consoleSpy.resolveBuildContext({ config, cwd, logger: logger$1, pkg, strict, tsconfig });
43
43
  if (printPackageTree(ctx), strict) {
44
44
  const missingFiles = [];
45
45
  for (const [, exp] of Object.entries(ctx.exports || {}))
@@ -1 +1 @@
1
- {"version":3,"file":"check.cjs","sources":["../../src/node/getFilesize.ts","../../src/node/printPackageTree.ts","../../src/node/check.ts"],"sourcesContent":["import {statSync} from 'node:fs'\n\nimport prettyBytes from 'pretty-bytes'\n\nexport function getFilesize(file: string): string {\n const stats = statSync(file)\n\n return prettyBytes(stats.size)\n}\n","import path from 'node:path'\n\nimport chalk from 'chalk'\nimport treeify from 'treeify'\n\nimport type {BuildContext, PkgExport} from './core'\nimport {fileExists} from './fileExists'\nimport {getFilesize} from './getFilesize'\n\nfunction getFileInfo(cwd: string, filePath: string) {\n const p = path.resolve(cwd, filePath)\n const exists = fileExists(p)\n const size = exists ? getFilesize(p) : undefined\n\n return {exists, size}\n}\n\nexport function printPackageTree(ctx: BuildContext): void {\n const {cwd, exports, logger, pkg} = ctx\n\n if (!exports) return\n\n logger.log(`${chalk.blue(pkg.name)}@${chalk.green(pkg.version)}`)\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const tree: Record<string, unknown> = {}\n\n if (pkg.type) {\n tree['type'] = chalk.yellow(pkg.type)\n }\n\n if (pkg.bin) {\n tree['bin'] = Object.fromEntries(\n Object.entries(pkg.bin).map(([name, file]) => [chalk.cyan(name), fileInfo(file)]),\n )\n }\n\n function fileInfo(file: string) {\n const info = getFileInfo(cwd, file)\n\n if (!info.size) {\n return `${chalk.gray(file)} ${chalk.red('does not exist')}`\n }\n\n return `${chalk.yellow(file)} ${chalk.gray(info.size)}`\n }\n\n tree['exports'] = Object.fromEntries(\n Object.entries(exports)\n .filter(([, entry]) => entry._exported)\n .map(([exportPath, entry]) => {\n const exp: Omit<PkgExport, '_exported'> = {\n source: fileInfo(entry.source),\n browser: undefined,\n require: undefined,\n node: undefined,\n import: undefined,\n default: fileInfo(entry.default),\n }\n\n if (entry.browser) {\n exp.browser = {source: fileInfo(entry.browser.source)}\n\n if (entry.browser.import) exp.browser.import = fileInfo(entry.browser.import)\n if (entry.browser.require) exp.browser.require = fileInfo(entry.browser.require)\n } else {\n delete exp.browser\n }\n\n if (entry.require) {\n exp.require = fileInfo(entry.require)\n } else {\n delete exp.require\n }\n\n if (entry.node) {\n exp.node = {}\n\n if (entry.node.source) exp.node.source = fileInfo(entry.node.source)\n if (entry.node.import) exp.node.import = fileInfo(entry.node.import)\n if (entry.node.require) exp.node.require = fileInfo(entry.node.require)\n } else {\n delete exp.node\n }\n\n if (entry.import) {\n exp.import = fileInfo(entry.import)\n } else {\n delete exp.import\n }\n\n return [chalk.cyan(path.join(pkg.name, exportPath)), exp]\n }),\n )\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n logger.log(treeify.asTree(tree as Record<string, any>, true, true))\n}\n","import path from 'node:path'\n\nimport esbuild, {type BuildFailure, type Message} from 'esbuild'\n\nimport {createConsoleSpy} from './consoleSpy'\nimport {loadConfig, loadPkgWithReporting} from './core'\nimport {fileExists} from './fileExists'\nimport {createLogger, type Logger} from './logger'\nimport {printPackageTree} from './printPackageTree'\nimport {resolveBuildContext} from './resolveBuildContext'\n\n/** @public */\nexport async function check(options: {\n cwd: string\n strict?: boolean\n tsconfig?: string\n}): Promise<void> {\n const {cwd, strict = false, tsconfig: tsconfigOption} = options\n const logger = createLogger()\n\n const config = await loadConfig({cwd})\n const legacyExports = config?.legacyExports ?? false\n const pkg = await loadPkgWithReporting({cwd, logger, strict, legacyExports})\n const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'\n const ctx = await resolveBuildContext({config, cwd, logger, pkg, strict, tsconfig})\n\n printPackageTree(ctx)\n\n if (strict) {\n const missingFiles: string[] = []\n\n // Check if there are missing files\n for (const [, exp] of Object.entries(ctx.exports || {})) {\n if (exp.source && !fileExists(path.resolve(cwd, exp.source))) {\n missingFiles.push(exp.source)\n }\n\n if (exp.require && !fileExists(path.resolve(cwd, exp.require))) {\n missingFiles.push(exp.require)\n }\n\n if (exp.import && !fileExists(path.resolve(cwd, exp.import))) {\n missingFiles.push(exp.import)\n }\n }\n\n if (ctx.pkg.types && !fileExists(path.resolve(cwd, ctx.pkg.types))) {\n missingFiles.push(ctx.pkg.types)\n }\n\n if (missingFiles.length) {\n logger.error(`missing files: ${missingFiles.join(', ')}`)\n process.exit(1)\n }\n\n // Check if the files are resolved\n const exportPaths: {require: string[]; import: string[]} = {\n require: [],\n import: [],\n }\n\n for (const exp of Object.values(ctx.exports || {})) {\n if (!exp._exported) continue\n if (exp.require) exportPaths.require.push(exp.require)\n if (exp.import) exportPaths.import.push(exp.import)\n }\n\n const external = [\n ...Object.keys(pkg.dependencies || {}),\n ...Object.keys(pkg.devDependencies || {}),\n ]\n\n const consoleSpy = createConsoleSpy()\n\n if (exportPaths.import.length) {\n checkExports(exportPaths.import, {cwd, external, format: 'esm', logger})\n }\n\n if (exportPaths.require.length) {\n checkExports(exportPaths.require, {cwd, external, format: 'cjs', logger})\n }\n\n consoleSpy.restore()\n }\n}\n\nasync function checkExports(\n exportPaths: string[],\n options: {cwd: string; external: string[]; format: 'esm' | 'cjs'; logger: Logger},\n) {\n const {cwd, external, format, logger} = options\n\n const code = exportPaths\n .map((id) => (format ? `import('${id}');` : `require('${id}');`))\n .join('\\n')\n\n try {\n const esbuildResult = await esbuild.build({\n bundle: true,\n external,\n format,\n logLevel: 'silent',\n // otherwise output maps to stdout as we're using stdin\n outfile: '/dev/null',\n platform: 'node',\n stdin: {\n contents: code,\n loader: 'js',\n resolveDir: cwd,\n },\n })\n\n if (esbuildResult.errors.length > 0) {\n for (const msg of esbuildResult.errors) {\n printEsbuildMessage(logger.warn, msg)\n\n logger.log()\n }\n\n process.exit(1)\n }\n\n const esbuildWarnings = esbuildResult.warnings.filter((msg) => {\n !(msg.detail || msg.text).includes(`does not affect esbuild's own target setting`)\n })\n\n for (const msg of esbuildWarnings) {\n printEsbuildMessage(logger.warn, msg)\n\n logger.log()\n }\n } catch (err) {\n if (isEsbuildFailure(err)) {\n const {errors} = err\n\n for (const msg of errors) {\n printEsbuildMessage(logger.error, msg)\n\n logger.log()\n }\n } else if (err instanceof Error) {\n logger.error(err.stack || err.message)\n\n logger.log()\n } else {\n logger.error(`${err}`)\n\n logger.log()\n }\n\n process.exit(1)\n }\n}\n\nfunction printEsbuildMessage(log: (...args: unknown[]) => void, msg: esbuild.Message) {\n if (msg.location) {\n log(\n [\n `${msg.detail || msg.text}\\n`,\n `${msg.location.line} | ${msg.location.lineText}\\n`,\n `in ./${msg.location.file}:${msg.location.line}:${msg.location.column}`,\n ].join(''),\n )\n } else {\n log(msg.detail || msg.text)\n }\n}\n\nfunction isEsbuildFailure(err: unknown): err is BuildFailure {\n return (\n err instanceof Error &&\n 'errors' in err &&\n Array.isArray(err.errors) &&\n err.errors.every(isEsbuildMessage) &&\n 'warnings' in err &&\n Array.isArray(err.warnings) &&\n err.warnings.every(isEsbuildMessage)\n )\n}\n\nfunction isEsbuildMessage(msg: unknown): msg is Message {\n return (\n typeof msg === 'object' &&\n msg !== null &&\n 'text' in msg &&\n typeof msg.text === 'string' &&\n 'location' in msg &&\n (msg.location === null || typeof msg.location === 'object')\n )\n}\n"],"names":["statSync","prettyBytes","path","fileExists","exports","logger","chalk","treeify","createLogger","loadConfig","loadPkgWithReporting","resolveBuildContext","consoleSpy","createConsoleSpy","esbuild"],"mappings":";;;;;;AAIO,SAAS,YAAY,MAAsB;AAC1C,QAAA,QAAQA,YAAS,IAAI;AAEpB,SAAAC,qBAAA,QAAY,MAAM,IAAI;AAC/B;ACCA,SAAS,YAAY,KAAa,UAAkB;AAClD,QAAM,IAAIC,cAAAA,QAAK,QAAQ,KAAK,QAAQ,GAC9B,SAASC,OAAW,WAAA,CAAC,GACrB,OAAO,SAAS,YAAY,CAAC,IAAI;AAEhC,SAAA,EAAC,QAAQ,KAAI;AACtB;AAEO,SAAS,iBAAiB,KAAyB;AACxD,QAAM,EAAC,KAAK,SAAAC,UAAS,QAAAC,SAAQ,IAAO,IAAA;AAEpC,MAAI,CAACD,SAAS;AAEd,EAAAC,QAAO,IAAI,GAAGC,eAAAA,QAAM,KAAK,IAAI,IAAI,CAAC,IAAIA,eAAM,QAAA,MAAM,IAAI,OAAO,CAAC,EAAE;AAGhE,QAAM,OAAgC,CAAC;AAEnC,MAAI,SACN,KAAK,OAAUA,eAAM,QAAA,OAAO,IAAI,IAAI,IAGlC,IAAI,QACN,KAAK,MAAS,OAAO;AAAA,IACnB,OAAO,QAAQ,IAAI,GAAG,EAAE,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,CAACA,uBAAM,KAAK,IAAI,GAAG,SAAS,IAAI,CAAC,CAAC;AAAA,EAAA;AAIpF,WAAS,SAAS,MAAc;AACxB,UAAA,OAAO,YAAY,KAAK,IAAI;AAE7B,WAAA,KAAK,OAIH,GAAGA,uBAAM,OAAO,IAAI,CAAC,IAAIA,uBAAM,KAAK,KAAK,IAAI,CAAC,KAH5C,GAAGA,eAAA,QAAM,KAAK,IAAI,CAAC,IAAIA,eAAA,QAAM,IAAI,gBAAgB,CAAC;AAAA,EAAA;AAM7D,OAAK,UAAa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jB,iBAAW,OAAO;AAChB,4BAAoBA,QAAO,OAAO,GAAG,GAErCA,QAAO,IAAI;AAAA,IAAA,MAEJ,gBAAe,SACxBA,QAAO,MAAM,IAAI,SAAS,IAAI,OAAO,GAErCA,QAAO,UAEPA,QAAO,MAAM,GAAG,GAAG,EAAE,GAErBA,QAAO;AAGT,YAAQ,KAAK,CAAC;AAAA,EAAA;AAElB;AAEA,SAAS,oBAAoB,KAAmC,KAAsB;AAChF,MAAI,WACN;AAAA,IACE;AAAA,MACE,GAAG,IAAI,UAAU,IAAI,IAAI;AAAA;AAAA,MACzB,GAAG,IAAI,SAAS,IAAI,MAAM,IAAI,SAAS,QAAQ;AAAA;AAAA,MAC/C,QAAQ,IAAI,SAAS,IAAI,IAAI,IAAI,SAAS,IAAI,IAAI,IAAI,SAAS,MAAM;AAAA,IACvE,EAAE,KAAK,EAAE;AAAA,EAGX,IAAA,IAAI,IAAI,UAAU,IAAI,IAAI;AAE9B;AAEA,SAAS,iBAAiB,KAAmC;AAEzD,SAAA,eAAe,SACf,YAAY,OACZ,MAAM,QAAQ,IAAI,MAAM,KACxB,IAAI,OAAO,MAAM,gBAAgB,KACjC,cAAc,OACd,MAAM,QAAQ,IAAI,QAAQ,KAC1B,IAAI,SAAS,MAAM,gBAAgB;AAEvC;AAEA,SAAS,iBAAiB,KAA8B;AACtD,SACE,OAAO,OAAQ,YACf,QAAQ,QACR,UAAU,OACV,OAAO,IAAI,QAAS,YACpB,cAAc,QACb,IAAI,aAAa,QAAQ,OAAO,IAAI,YAAa;AAEtD;;"}
1
+ {"version":3,"file":"check.cjs","sources":["../../src/node/getFilesize.ts","../../src/node/printPackageTree.ts","../../src/node/check.ts"],"sourcesContent":["import {statSync} from 'node:fs'\n\nimport prettyBytes from 'pretty-bytes'\n\nexport function getFilesize(file: string): string {\n const stats = statSync(file)\n\n return prettyBytes(stats.size)\n}\n","import path from 'node:path'\n\nimport chalk from 'chalk'\nimport treeify from 'treeify'\n\nimport type {BuildContext, PkgExport} from './core'\nimport {fileExists} from './fileExists'\nimport {getFilesize} from './getFilesize'\n\nfunction getFileInfo(cwd: string, filePath: string) {\n const p = path.resolve(cwd, filePath)\n const exists = fileExists(p)\n const size = exists ? getFilesize(p) : undefined\n\n return {exists, size}\n}\n\nexport function printPackageTree(ctx: BuildContext): void {\n const {cwd, exports, logger, pkg} = ctx\n\n if (!exports) return\n\n logger.log(`${chalk.blue(pkg.name)}@${chalk.green(pkg.version)}`)\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const tree: Record<string, unknown> = {}\n\n if (pkg.type) {\n tree['type'] = chalk.yellow(pkg.type)\n }\n\n if (pkg.bin) {\n tree['bin'] = Object.fromEntries(\n Object.entries(pkg.bin).map(([name, file]) => [chalk.cyan(name), fileInfo(file)]),\n )\n }\n\n function fileInfo(file: string) {\n const info = getFileInfo(cwd, file)\n\n if (!info.size) {\n return `${chalk.gray(file)} ${chalk.red('does not exist')}`\n }\n\n return `${chalk.yellow(file)} ${chalk.gray(info.size)}`\n }\n\n tree['exports'] = Object.fromEntries(\n Object.entries(exports)\n .filter(([, entry]) => entry._exported)\n .map(([exportPath, entry]) => {\n const exp: Omit<PkgExport, '_exported'> = {\n source: fileInfo(entry.source),\n browser: undefined,\n require: undefined,\n node: undefined,\n import: undefined,\n default: fileInfo(entry.default),\n }\n\n if (entry.browser) {\n exp.browser = {source: fileInfo(entry.browser.source)}\n\n if (entry.browser.import) exp.browser.import = fileInfo(entry.browser.import)\n if (entry.browser.require) exp.browser.require = fileInfo(entry.browser.require)\n } else {\n delete exp.browser\n }\n\n if (entry.require) {\n exp.require = fileInfo(entry.require)\n } else {\n delete exp.require\n }\n\n if (entry.node) {\n exp.node = {}\n\n if (entry.node.source) exp.node.source = fileInfo(entry.node.source)\n if (entry.node.import) exp.node.import = fileInfo(entry.node.import)\n if (entry.node.require) exp.node.require = fileInfo(entry.node.require)\n } else {\n delete exp.node\n }\n\n if (entry.import) {\n exp.import = fileInfo(entry.import)\n } else {\n delete exp.import\n }\n\n return [chalk.cyan(path.join(pkg.name, exportPath)), exp]\n }),\n )\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n logger.log(treeify.asTree(tree as Record<string, any>, true, true))\n}\n","import path from 'node:path'\n\nimport esbuild, {type BuildFailure, type Message} from 'esbuild'\n\nimport {createConsoleSpy} from './consoleSpy'\nimport {loadConfig, loadPkgWithReporting} from './core'\nimport {fileExists} from './fileExists'\nimport {createLogger, type Logger} from './logger'\nimport {printPackageTree} from './printPackageTree'\nimport {resolveBuildContext} from './resolveBuildContext'\n\n/** @public */\nexport async function check(options: {\n cwd: string\n strict?: boolean\n tsconfig?: string\n}): Promise<void> {\n const {cwd, strict = false, tsconfig: tsconfigOption} = options\n const logger = createLogger()\n\n const config = await loadConfig({cwd})\n const pkg = await loadPkgWithReporting({cwd, logger, strict})\n const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'\n const ctx = await resolveBuildContext({config, cwd, logger, pkg, strict, tsconfig})\n\n printPackageTree(ctx)\n\n if (strict) {\n const missingFiles: string[] = []\n\n // Check if there are missing files\n for (const [, exp] of Object.entries(ctx.exports || {})) {\n if (exp.source && !fileExists(path.resolve(cwd, exp.source))) {\n missingFiles.push(exp.source)\n }\n\n if (exp.require && !fileExists(path.resolve(cwd, exp.require))) {\n missingFiles.push(exp.require)\n }\n\n if (exp.import && !fileExists(path.resolve(cwd, exp.import))) {\n missingFiles.push(exp.import)\n }\n }\n\n if (ctx.pkg.types && !fileExists(path.resolve(cwd, ctx.pkg.types))) {\n missingFiles.push(ctx.pkg.types)\n }\n\n if (missingFiles.length) {\n logger.error(`missing files: ${missingFiles.join(', ')}`)\n process.exit(1)\n }\n\n // Check if the files are resolved\n const exportPaths: {require: string[]; import: string[]} = {\n require: [],\n import: [],\n }\n\n for (const exp of Object.values(ctx.exports || {})) {\n if (!exp._exported) continue\n if (exp.require) exportPaths.require.push(exp.require)\n if (exp.import) exportPaths.import.push(exp.import)\n }\n\n const external = [\n ...Object.keys(pkg.dependencies || {}),\n ...Object.keys(pkg.devDependencies || {}),\n ]\n\n const consoleSpy = createConsoleSpy()\n\n if (exportPaths.import.length) {\n checkExports(exportPaths.import, {cwd, external, format: 'esm', logger})\n }\n\n if (exportPaths.require.length) {\n checkExports(exportPaths.require, {cwd, external, format: 'cjs', logger})\n }\n\n consoleSpy.restore()\n }\n}\n\nasync function checkExports(\n exportPaths: string[],\n options: {cwd: string; external: string[]; format: 'esm' | 'cjs'; logger: Logger},\n) {\n const {cwd, external, format, logger} = options\n\n const code = exportPaths\n .map((id) => (format ? `import('${id}');` : `require('${id}');`))\n .join('\\n')\n\n try {\n const esbuildResult = await esbuild.build({\n bundle: true,\n external,\n format,\n logLevel: 'silent',\n // otherwise output maps to stdout as we're using stdin\n outfile: '/dev/null',\n platform: 'node',\n stdin: {\n contents: code,\n loader: 'js',\n resolveDir: cwd,\n },\n })\n\n if (esbuildResult.errors.length > 0) {\n for (const msg of esbuildResult.errors) {\n printEsbuildMessage(logger.warn, msg)\n\n logger.log()\n }\n\n process.exit(1)\n }\n\n const esbuildWarnings = esbuildResult.warnings.filter((msg) => {\n !(msg.detail || msg.text).includes(`does not affect esbuild's own target setting`)\n })\n\n for (const msg of esbuildWarnings) {\n printEsbuildMessage(logger.warn, msg)\n\n logger.log()\n }\n } catch (err) {\n if (isEsbuildFailure(err)) {\n const {errors} = err\n\n for (const msg of errors) {\n printEsbuildMessage(logger.error, msg)\n\n logger.log()\n }\n } else if (err instanceof Error) {\n logger.error(err.stack || err.message)\n\n logger.log()\n } else {\n logger.error(`${err}`)\n\n logger.log()\n }\n\n process.exit(1)\n }\n}\n\nfunction printEsbuildMessage(log: (...args: unknown[]) => void, msg: esbuild.Message) {\n if (msg.location) {\n log(\n [\n `${msg.detail || msg.text}\\n`,\n `${msg.location.line} | ${msg.location.lineText}\\n`,\n `in ./${msg.location.file}:${msg.location.line}:${msg.location.column}`,\n ].join(''),\n )\n } else {\n log(msg.detail || msg.text)\n }\n}\n\nfunction isEsbuildFailure(err: unknown): err is BuildFailure {\n return (\n err instanceof Error &&\n 'errors' in err &&\n Array.isArray(err.errors) &&\n err.errors.every(isEsbuildMessage) &&\n 'warnings' in err &&\n Array.isArray(err.warnings) &&\n err.warnings.every(isEsbuildMessage)\n )\n}\n\nfunction isEsbuildMessage(msg: unknown): msg is Message {\n return (\n typeof msg === 'object' &&\n msg !== null &&\n 'text' in msg &&\n typeof msg.text === 'string' &&\n 'location' in msg &&\n (msg.location === null || typeof msg.location === 'object')\n )\n}\n"],"names":["statSync","prettyBytes","path","fileExists","exports","logger","chalk","treeify","createLogger","loadConfig","loadPkgWithReporting","resolveBuildContext","consoleSpy","createConsoleSpy","esbuild"],"mappings":";;;;;;AAIO,SAAS,YAAY,MAAsB;AAC1C,QAAA,QAAQA,iBAAS,IAAI;AAEpB,SAAAC,qBAAA,QAAY,MAAM,IAAI;AAC/B;ACCA,SAAS,YAAY,KAAa,UAAkB;AAClD,QAAM,IAAIC,cAAAA,QAAK,QAAQ,KAAK,QAAQ,GAC9B,SAASC,OAAW,WAAA,CAAC,GACrB,OAAO,SAAS,YAAY,CAAC,IAAI;AAEhC,SAAA,EAAC,QAAQ,KAAI;AACtB;AAEO,SAAS,iBAAiB,KAAyB;AACxD,QAAM,EAAC,KAAK,SAAAC,UAAS,QAAAC,SAAQ,IAAO,IAAA;AAEpC,MAAI,CAACD,SAAS;AAEd,EAAAC,QAAO,IAAI,GAAGC,eAAAA,QAAM,KAAK,IAAI,IAAI,CAAC,IAAIA,eAAM,QAAA,MAAM,IAAI,OAAO,CAAC,EAAE;AAGhE,QAAM,OAAgC,CAAC;AAEnC,MAAI,SACN,KAAK,OAAUA,eAAM,QAAA,OAAO,IAAI,IAAI,IAGlC,IAAI,QACN,KAAK,MAAS,OAAO;AAAA,IACnB,OAAO,QAAQ,IAAI,GAAG,EAAE,IAAI,CAAC,CAAC,MAAM,IAAI,MAAM,CAACA,uBAAM,KAAK,IAAI,GAAG,SAAS,IAAI,CA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
1
  "use strict";
2
- var path = require("node:path"), node = require("esbuild-register/dist/node"), pkgUp = require("pkg-up"), findConfig = require("find-config"), logger = require("./logger.cjs"), chalk = require("chalk"), zod = require("zod"), fs = require("node:fs/promises"), browserslist = require("browserslist"), config = require("@sanity/browserslist-config"), fs$1 = require("node:fs"), ts = require("typescript"), zodValidationError = require("zod-validation-error");
2
+ var path = require("node:path"), node = require("esbuild-register/dist/node"), pkgUp = require("pkg-up"), findConfig = require("find-config"), logger = require("./logger.cjs"), chalk = require("chalk"), zod = require("zod"), fs = require("node:fs/promises"), browserslist = require("browserslist"), config = require("@sanity/browserslist-config"), node_fs = require("node:fs"), ts = require("typescript"), zodValidationError = require("zod-validation-error");
3
3
  function _interopDefaultCompat(e) {
4
4
  return e && typeof e == "object" && "default" in e ? e : { default: e };
5
5
  }
@@ -49,13 +49,11 @@ function assertOrder(a, b, arr) {
49
49
  return aIdx === -1 || bIdx === -1 ? !0 : aIdx < bIdx;
50
50
  }
51
51
  async function loadPkgWithReporting(options) {
52
- const { cwd, logger: logger2, strict, legacyExports } = options;
52
+ const { cwd, logger: logger2, strict } = options;
53
53
  try {
54
54
  const pkg = await loadPkg({ cwd });
55
55
  let shouldError = !1;
56
- if (strict && (legacyExports && pkg.type === "commonjs" && (shouldError = !0, logger2.error(
57
- 'the `type` field in `./package.json` shouldn\'t be "commonjs" when `legacyExports` is set to true)'
58
- )), !legacyExports && !pkg.type && (shouldError = !0, logger2.error(
56
+ if (strict && (pkg.type || (shouldError = !0, logger2.error(
59
57
  'the `type` field in `./package.json` must be either "module" or "commonjs")'
60
58
  ))), pkg.exports) {
61
59
  const _exports = Object.entries(pkg.exports);
@@ -108,7 +106,7 @@ async function loadPkgWithReporting(options) {
108
106
  function formatPath(segments) {
109
107
  return segments.map((s, idx) => idx === 0 ? s : typeof s == "number" ? `[${s}]` : s.startsWith(".") ? `["${s}"]` : `.${s}`).join("");
110
108
  }
111
- const fileEnding = /\.[mc]?js$/, dtsEnding = ".d.ts", defaultEnding = ".js", legacyEnding = `.esm${defaultEnding}`, mjsEnding = ".mjs", cjsEnding = ".cjs", mtsEnding = ".d.mts", ctsEnding = ".d.cts";
109
+ const fileEnding = /\.[mc]?js$/, dtsEnding = ".d.ts", defaultEnding = ".js", mjsEnding = ".mjs", cjsEnding = ".cjs", mtsEnding = ".d.mts", ctsEnding = ".d.cts";
112
110
  function getTargetPaths(_type, expOrBundle) {
113
111
  const type = _type === "module" ? "module" : "commonjs", set = /* @__PURE__ */ new Set();
114
112
  return expOrBundle?.import && set.add(expOrBundle.import.replace(fileEnding, type === "module" ? dtsEnding : mtsEnding)), expOrBundle?.require && set.add(expOrBundle.require.replace(fileEnding, type === "commonjs" ? dtsEnding : ctsEnding)), isPkgExport$1(expOrBundle) && (expOrBundle.browser?.source || (expOrBundle.browser?.import && set.add(
@@ -137,9 +135,7 @@ const pkgExtMap = {
137
135
  module: {
138
136
  commonjs: cjsEnding,
139
137
  esm: defaultEnding
140
- },
141
- // package.config.legacyExports: true
142
- legacy: legacyEnding
138
+ }
143
139
  };
144
140
  function validateExports(_exports, options) {
145
141
  const { pkg } = options, type = pkg.type || "commonjs", ext = pkgExtMap[type], errors = [];
@@ -152,7 +148,7 @@ function validateExports(_exports, options) {
152
148
  return errors;
153
149
  }
154
150
  function parseExports(options) {
155
- const { cwd, pkg, strict, strictOptions: strictOptions2, legacyExports, logger: logger$1 } = options, type = pkg.type || "commonjs", errors = [], report = (kind, message) => {
151
+ const { cwd, pkg, strict, strictOptions: strictOptions2, logger: logger$1 } = options, type = pkg.type || "commonjs", errors = [], report = (kind, message) => {
156
152
  kind === "warn" ? logger$1.warn(message) : errors.push(message);
157
153
  };
158
154
  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(
@@ -167,27 +163,13 @@ function parseExports(options) {
167
163
  const extMap = pkgExtMap[type], importExport = pkg.main.replace(fileEnding, extMap.esm), requireExport = pkg.main.replace(fileEnding, extMap.commonjs), defaultExport = pkg.main.replace(fileEnding, defaultEnding), maybeBrowserCondition = [];
168
164
  if (pkg.browser) {
169
165
  const browserConditions = [];
170
- if (pkg.module && pkg.browser?.[pkg.module])
171
- browserConditions.push(
172
- ` "import": ${JSON.stringify(pkg.browser[pkg.module].replace(fileEnding, extMap.esm))}`
173
- );
174
- else if (pkg.browser?.[pkg.main])
175
- browserConditions.push(
176
- ` "import": ${JSON.stringify(pkg.browser?.[pkg.main].replace(fileEnding, extMap.esm))}`
177
- );
178
- else if (legacyExports) {
179
- const browserImport = pkg.main.replace(fileEnding, `.browser${extMap.esm}`);
180
- browserConditions.push(` "import": ${JSON.stringify(browserImport)}`);
181
- }
182
- if (pkg.browser?.[pkg.main])
183
- browserConditions.push(
184
- ` "require": ${JSON.stringify(pkg.browser[pkg.main].replace(fileEnding, extMap.commonjs))}`
185
- );
186
- else if (legacyExports) {
187
- const browserRequire = pkg.main.replace(fileEnding, `.browser${extMap.commonjs}`);
188
- browserConditions.push(` "require": ${JSON.stringify(browserRequire)}`);
189
- }
190
- browserConditions.length && maybeBrowserCondition.push(
166
+ pkg.module && pkg.browser?.[pkg.module] ? browserConditions.push(
167
+ ` "import": ${JSON.stringify(pkg.browser[pkg.module].replace(fileEnding, extMap.esm))}`
168
+ ) : pkg.browser?.[pkg.main] && browserConditions.push(
169
+ ` "import": ${JSON.stringify(pkg.browser?.[pkg.main].replace(fileEnding, extMap.esm))}`
170
+ ), pkg.browser?.[pkg.main] && browserConditions.push(
171
+ ` "require": ${JSON.stringify(pkg.browser[pkg.main].replace(fileEnding, extMap.commonjs))}`
172
+ ), browserConditions.length && maybeBrowserCondition.push(
191
173
  ' "browser": {',
192
174
  ` "source": ${JSON.stringify(pkg.browser?.[pkg.source] || pkg.source)},`,
193
175
  ...browserConditions,
@@ -202,9 +184,8 @@ function parseExports(options) {
202
184
  ` "source": ${JSON.stringify(pkg.source)},`,
203
185
  // If browser conditions are detected then add them to the suggestion
204
186
  ...maybeBrowserCondition.length > 0 ? maybeBrowserCondition : [],
205
- // If legacy exports are enabled we suggest the full list of exports, if not we can use the terse version
206
- (legacyExports || type === "commonjs") && ` "import": ${JSON.stringify(importExport)},`,
207
- (legacyExports || type === "module") && ` "require": ${JSON.stringify(requireExport)},`,
187
+ type === "commonjs" && ` "import": ${JSON.stringify(importExport)},`,
188
+ type === "module" && ` "require": ${JSON.stringify(requireExport)},`,
208
189
  ` "default": ${JSON.stringify(defaultExport)}`,
209
190
  " },",
210
191
  ' "./package.json": "./package.json"',
@@ -241,7 +222,7 @@ function parseExports(options) {
241
222
  if (exportPath.endsWith(".json") || typeof exportEntry == "string" && exportEntry.endsWith(".json"))
242
223
  exportPath === "./package.json" && exportEntry !== "./package.json" && errors.push('package.json: `exports["./package.json"]` must be "./package.json".');
243
224
  else if (exportPath.endsWith(".css"))
244
- typeof exportEntry == "string" && !fs$1.existsSync(path.resolve(cwd, exportEntry)) ? errors.push(
225
+ typeof exportEntry == "string" && !node_fs.existsSync(path.resolve(cwd, exportEntry)) ? errors.push(
245
226
  `package.json: \`exports[${JSON.stringify(exportPath)}]\`: file does not exist.`
246
227
  ) : typeof exportEntry != "string" && errors.push(
247
228
  `package.json: \`exports[${JSON.stringify(exportPath)}]\`: export conditions not supported for CSS files.`
@@ -255,28 +236,13 @@ function parseExports(options) {
255
236
  };
256
237
  if (!exp.default) {
257
238
  const fallback = type === "module" ? exp.import : exp.require;
258
- fallback && (exp.default = fallback), legacyExports && (fallback ? errors.push(
259
- `package.json - \`exports["${exp._path}"].default\` should be set to "${fallback}" when "legacyExports" is true`
260
- ) : errors.push(
261
- `package.json - \`exports["${exp._path}"].default\` should be specified when "legacyExports" is true`
262
- ));
239
+ fallback && (exp.default = fallback);
263
240
  }
264
- if (!exp.require && type === "commonjs" && exp.default && (exp.require = exp.default), !exp.import && type === "module" && exp.default && (exp.import = exp.default), exportPath === ".")
265
- if (exportEntry.require && pkg.main && exportEntry.require !== pkg.main && errors.push(
266
- 'package.json: mismatch between "main" and "exports.require". These must be equal.'
267
- ), legacyExports) {
268
- const indexLegacyExport = (exportEntry.import || exportEntry.require || "").replace(
269
- /(\.esm)?\.[mc]?js$/,
270
- legacyEnding
271
- );
272
- indexLegacyExport !== pkg.module && errors.push(
273
- `package.json: "module" should be "${indexLegacyExport}" when "legacyExports" is true`
274
- );
275
- } else
276
- exportEntry.import && pkg.module && exportEntry.import !== pkg.module && errors.push(
277
- 'package.json: mismatch between "module" and "exports.import" These must be equal.'
278
- );
279
- _exports.push(exp);
241
+ !exp.require && type === "commonjs" && exp.default && (exp.require = exp.default), !exp.import && type === "module" && exp.default && (exp.import = exp.default), exportPath === "." && (exportEntry.require && pkg.main && exportEntry.require !== pkg.main && errors.push(
242
+ 'package.json: mismatch between "main" and "exports.require". These must be equal.'
243
+ ), exportEntry.import && pkg.module && exportEntry.import !== pkg.module && errors.push(
244
+ 'package.json: mismatch between "module" and "exports.import" These must be equal.'
245
+ )), _exports.push(exp);
280
246
  } else logger.isRecord(exportEntry) || errors.push("package.json: exports must be an object");
281
247
  if (errors.push(...validateExports(_exports, { pkg })), errors.length)
282
248
  throw new Error(`
@@ -407,7 +373,6 @@ async function resolveBuildContext(options) {
407
373
  cwd,
408
374
  pkg,
409
375
  strict,
410
- legacyExports: config2?.legacyExports ?? !1,
411
376
  strictOptions: strictOptions2,
412
377
  logger: logger2
413
378
  }).reduce((acc, x) => {
@@ -485,9 +450,7 @@ function createConsoleSpy(options) {
485
450
  }
486
451
  exports.DEFAULT_BROWSERSLIST_QUERY = DEFAULT_BROWSERSLIST_QUERY;
487
452
  exports.createConsoleSpy = createConsoleSpy;
488
- exports.fileEnding = fileEnding;
489
453
  exports.getTargetPaths = getTargetPaths;
490
- exports.legacyEnding = legacyEnding;
491
454
  exports.loadConfig = loadConfig;
492
455
  exports.loadPkg = loadPkg;
493
456
  exports.loadPkgWithReporting = loadPkgWithReporting;