@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.
Files changed (50) hide show
  1. package/dist/_chunks-es/buildAction.js +147 -2
  2. package/dist/_chunks-es/buildAction.js.map +1 -1
  3. package/dist/_chunks-es/checkAction.js +179 -2
  4. package/dist/_chunks-es/checkAction.js.map +1 -1
  5. package/dist/_chunks-es/createApiExtractorConfig.js +52 -0
  6. package/dist/_chunks-es/createApiExtractorConfig.js.map +1 -0
  7. package/dist/_chunks-es/createTSDocConfig.js +31 -0
  8. package/dist/_chunks-es/createTSDocConfig.js.map +1 -0
  9. package/dist/_chunks-es/defaults.js +39 -0
  10. package/dist/_chunks-es/defaults.js.map +1 -0
  11. package/dist/_chunks-es/define.js +7 -0
  12. package/dist/_chunks-es/define.js.map +1 -0
  13. package/dist/_chunks-es/fileExists.js +12 -0
  14. package/dist/_chunks-es/fileExists.js.map +1 -0
  15. package/dist/_chunks-es/getExtractMessagesConfig.js +83 -0
  16. package/dist/_chunks-es/getExtractMessagesConfig.js.map +1 -0
  17. package/dist/_chunks-es/handleError.js +25 -1
  18. package/dist/_chunks-es/handleError.js.map +1 -1
  19. package/dist/_chunks-es/index.js +8 -212
  20. package/dist/_chunks-es/index.js.map +1 -1
  21. package/dist/_chunks-es/initAction.js +515 -2
  22. package/dist/_chunks-es/initAction.js.map +1 -1
  23. package/dist/_chunks-es/printExtractMessages.js +44 -0
  24. package/dist/_chunks-es/printExtractMessages.js.map +1 -0
  25. package/dist/_chunks-es/{consoleSpy.js → resolveBuildContext.js} +68 -95
  26. package/dist/_chunks-es/resolveBuildContext.js.map +1 -0
  27. package/dist/_chunks-es/resolveRolldownConfig.js +1 -1
  28. package/dist/_chunks-es/watchAction.js +106 -2
  29. package/dist/_chunks-es/watchAction.js.map +1 -1
  30. package/dist/cli.js +1 -1
  31. package/dist/index.d.ts +2 -183
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +3 -18
  34. package/dist/index.js.map +1 -1
  35. package/package.json +3 -10
  36. package/dist/_chunks-es/build.js +0 -150
  37. package/dist/_chunks-es/build.js.map +0 -1
  38. package/dist/_chunks-es/check.js +0 -189
  39. package/dist/_chunks-es/check.js.map +0 -1
  40. package/dist/_chunks-es/consoleSpy.js.map +0 -1
  41. package/dist/_chunks-es/init.js +0 -520
  42. package/dist/_chunks-es/init.js.map +0 -1
  43. package/dist/_chunks-es/isRecord.js +0 -37
  44. package/dist/_chunks-es/isRecord.js.map +0 -1
  45. package/dist/_chunks-es/watch.js +0 -109
  46. package/dist/_chunks-es/watch.js.map +0 -1
  47. package/tsconfig/isolated-declarations.json +0 -11
  48. package/tsconfig/recommended.json +0 -24
  49. package/tsconfig/strict.json +0 -15
  50. package/tsconfig/strictest.json +0 -16
@@ -1,109 +0,0 @@
1
- import path from "node:path";
2
- import { switchMap } from "rxjs";
3
- import { getTargetPaths, loadConfig, loadPkgWithReporting, resolveBuildContext } from "./consoleSpy.js";
4
- import { createLogger } from "./isRecord.js";
5
- import { watchTaskHandlers } from "./index.js";
6
- function resolveWatchTasks(ctx) {
7
- const { pkg, target } = ctx, tasks = [], exports$1 = Object.entries(ctx.exports || {}).map(
8
- ([_path, exp]) => ({ _path, ...exp })
9
- ), dtsTask = {
10
- type: "watch:dts",
11
- entries: []
12
- }, rollupTasks = {};
13
- function addRollupTaskEntry(format, runtime, entry) {
14
- const buildId = `${format}:${runtime}`;
15
- rollupTasks[buildId] ? rollupTasks[buildId].entries.push(entry) : rollupTasks[buildId] = {
16
- type: "watch:js",
17
- buildId,
18
- entries: [entry],
19
- runtime,
20
- format,
21
- target: target[runtime]
22
- };
23
- }
24
- for (const exp of exports$1) {
25
- const importId = path.join(pkg.name, exp._path);
26
- exp.source?.endsWith(".ts") && dtsTask.entries.push({
27
- importId,
28
- exportPath: exp._path,
29
- sourcePath: exp.source,
30
- targetPaths: getTargetPaths(pkg.type, exp)
31
- }), exp.browser?.source?.endsWith(".ts") && dtsTask.entries.push({
32
- importId,
33
- exportPath: exp._path,
34
- sourcePath: exp.browser.source,
35
- targetPaths: getTargetPaths(pkg.type, exp.browser)
36
- }), exp.node?.source?.endsWith(".ts") && dtsTask.entries.push({
37
- importId,
38
- exportPath: exp._path,
39
- sourcePath: exp.node.source,
40
- targetPaths: getTargetPaths(pkg.type, exp.node)
41
- });
42
- }
43
- for (const exp of exports$1) {
44
- const output = exp.require;
45
- output && addRollupTaskEntry("commonjs", ctx.runtime, {
46
- path: exp._path,
47
- source: exp.source,
48
- output
49
- });
50
- }
51
- for (const exp of exports$1) {
52
- const output = exp.browser?.require;
53
- output && addRollupTaskEntry("commonjs", "browser", {
54
- path: exp._path,
55
- source: exp.browser?.source || exp.source,
56
- output
57
- });
58
- }
59
- for (const exp of exports$1) {
60
- const output = exp.import;
61
- output && addRollupTaskEntry("esm", ctx.runtime, {
62
- path: exp._path,
63
- source: exp.source,
64
- output
65
- });
66
- }
67
- for (const exp of exports$1) {
68
- const output = exp.browser?.import;
69
- output && addRollupTaskEntry("esm", "browser", {
70
- path: exp._path,
71
- source: exp.browser?.source || exp.source,
72
- output
73
- });
74
- }
75
- return dtsTask.entries.length && tasks.push(dtsTask), tasks.push(...Object.values(rollupTasks)), tasks;
76
- }
77
- async function watch(options) {
78
- const { cwd, strict = !1, tsconfig: tsconfigOption } = options, logger = createLogger(), { watchConfigFiles } = await import("./watchConfigFiles.js");
79
- (await watchConfigFiles({ cwd, logger })).pipe(
80
- switchMap(async (configFiles) => {
81
- if (!configFiles.map((f) => path.relative(cwd, f)).find((f) => f === "package.json"))
82
- throw new Error("missing package.json");
83
- const config = await loadConfig({ cwd }), { parseStrictOptions } = await import("./consoleSpy.js").then(function(n) {
84
- return n.strict;
85
- }), strictOptions = parseStrictOptions(config?.strictOptions ?? {}), pkg = await loadPkgWithReporting({ cwd, logger, strict, strictOptions }), tsconfig = tsconfigOption || config?.tsconfig || "tsconfig.json";
86
- return resolveBuildContext({ config, cwd, logger, pkg, strict, tsconfig });
87
- })
88
- ).subscribe(async (ctx) => {
89
- const watchTasks = resolveWatchTasks(ctx);
90
- for (const task of watchTasks) {
91
- const handler = watchTaskHandlers[task.type];
92
- handler.exec(ctx, task).subscribe({
93
- error: (err) => {
94
- ctx.logger.error(err), ctx.logger.log(), process.exit(1);
95
- },
96
- next: (result) => {
97
- handler.complete(ctx, task, result);
98
- },
99
- complete: () => {
100
- ctx.logger.success(handler.name(ctx, task)), ctx.logger.log();
101
- }
102
- });
103
- }
104
- });
105
- }
106
- export {
107
- watch
108
- };
109
- //# sourceMappingURL=watch.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"watch.js","sources":["../../src/node/resolveWatchTasks.ts","../../src/node/watch.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 {DtsWatchTask} from './tasks/dts/types.ts'\nimport type {RollupTaskEntry, RollupWatchTask, WatchTask} from './tasks/types.ts'\n\n/** @internal */\nexport function resolveWatchTasks(ctx: BuildContext): WatchTask[] {\n const {pkg, target} = ctx\n const tasks: WatchTask[] = []\n\n const exports = Object.entries(ctx.exports || {}).map(\n ([_path, exp]) => ({_path, ...exp}) as PkgExport & {_path: string},\n )\n\n const dtsTask: DtsWatchTask = {\n type: 'watch:dts',\n entries: [],\n }\n\n const rollupTasks: Record<string, RollupWatchTask> = {}\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: 'watch: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 // 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: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:* 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: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 if (dtsTask.entries.length) {\n tasks.push(dtsTask)\n }\n\n tasks.push(...Object.values(rollupTasks))\n\n return tasks\n}\n","import path from 'node:path'\nimport {switchMap} from 'rxjs'\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 {resolveWatchTasks} from './resolveWatchTasks.ts'\nimport {watchTaskHandlers} from './tasks/index.ts'\nimport {type TaskHandler, type WatchTask} from './tasks/types.ts'\n\n/** @public */\nexport async function watch(options: {\n cwd: string\n strict?: boolean\n tsconfig?: string\n}): Promise<void> {\n const {cwd, strict = false, tsconfig: tsconfigOption} = options\n\n const logger = createLogger()\n\n const {watchConfigFiles} = await import('./watchConfigFiles.ts')\n const configFiles$ = await watchConfigFiles({cwd, logger})\n\n const ctx$ = configFiles$.pipe(\n switchMap(async (configFiles) => {\n const files = configFiles.map((f) => path.relative(cwd, f))\n\n const packageJsonPath = files.find((f) => f === 'package.json')\n\n if (!packageJsonPath) {\n throw new Error('missing package.json')\n }\n\n const config = await loadConfig({cwd})\n const {parseStrictOptions} = await import('./strict.ts')\n const strictOptions = parseStrictOptions(config?.strictOptions ?? {})\n const pkg = await loadPkgWithReporting({cwd, logger, strict, strictOptions})\n const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'\n\n return resolveBuildContext({config, cwd, logger, pkg, strict, tsconfig})\n }),\n )\n\n ctx$.subscribe(async (ctx) => {\n const watchTasks = resolveWatchTasks(ctx)\n\n for (const task of watchTasks) {\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 = watchTaskHandlers[task.type] as TaskHandler<WatchTask, unknown>\n const result$ = handler.exec(ctx, task)\n\n result$.subscribe({\n error: (err) => {\n ctx.logger.error(err)\n ctx.logger.log()\n\n process.exit(1)\n },\n next: (result) => {\n handler.complete(ctx, task, result)\n },\n complete: () => {\n ctx.logger.success(handler.name(ctx, task))\n ctx.logger.log()\n },\n })\n }\n })\n}\n"],"names":["exports"],"mappings":";;;;;AAQO,SAAS,kBAAkB,KAAgC;AAChE,QAAM,EAAC,KAAK,OAAA,IAAU,KAChB,QAAqB,CAAA,GAErBA,YAAU,OAAO,QAAQ,IAAI,WAAW,CAAA,CAAE,EAAE;AAAA,IAChD,CAAC,CAAC,OAAO,GAAG,OAAO,EAAC,OAAO,GAAG,IAAA;AAAA,EAAG,GAG7B,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AQ,iBAAiB,CAAA,CAAE,GAC9D,MAAM,MAAM,qBAAqB,EAAC,KAAK,QAAQ,QAAQ,eAAc,GACrE,WAAW,kBAAkB,QAAQ,YAAY;AAEvD,aAAO,oBAAoB,EAAC,QAAQ,KAAK,QAAQ,KAAK,QAAQ,UAAS;AAAA,IACzE,CAAC;AAAA,EAAA,EAGE,UAAU,OAAO,QAAQ;AAC5B,UAAM,aAAa,kBAAkB,GAAG;AAExC,eAAW,QAAQ,YAAY;AAE7B,YAAM,UAAU,kBAAkB,KAAK,IAAI;AAC3B,cAAQ,KAAK,KAAK,IAAI,EAE9B,UAAU;AAAA,QAChB,OAAO,CAAC,QAAQ;AACd,cAAI,OAAO,MAAM,GAAG,GACpB,IAAI,OAAO,IAAA,GAEX,QAAQ,KAAK,CAAC;AAAA,QAChB;AAAA,QACA,MAAM,CAAC,WAAW;AAChB,kBAAQ,SAAS,KAAK,MAAM,MAAM;AAAA,QACpC;AAAA,QACA,UAAU,MAAM;AACd,cAAI,OAAO,QAAQ,QAAQ,KAAK,KAAK,IAAI,CAAC,GAC1C,IAAI,OAAO,IAAA;AAAA,QACb;AAAA,MAAA,CACD;AAAA,IACH;AAAA,EACF,CAAC;AACH;"}
@@ -1,11 +0,0 @@
1
- {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "description": "Sets the right settings for isolated declarations when also extending from presets such as strictest.json.",
4
- "compilerOptions": {
5
- "allowJs": false,
6
- "checkJs": false,
7
- "isolatedDeclarations": true,
8
- "declaration": true,
9
- "noCheck": true
10
- }
11
- }
@@ -1,24 +0,0 @@
1
- {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "description": "Sets the right defaults for usage with @sanity/pkg-utils and that JSX is compiled with esbuild, and ESM and CJS with rollup.",
4
- "compilerOptions": {
5
- "target": "esnext",
6
- "lib": ["esnext", "dom", "dom.iterable"],
7
- "jsx": "preserve",
8
- "module": "preserve",
9
- "moduleDetection": "force",
10
- "moduleResolution": "bundler",
11
- "allowImportingTsExtensions": true,
12
- "resolveJsonModule": true,
13
- "allowJs": true,
14
- "noEmit": true,
15
- "allowSyntheticDefaultImports": true,
16
- "esModuleInterop": true,
17
- "forceConsistentCasingInFileNames": true,
18
- "skipLibCheck": true,
19
- "noUncheckedIndexedAccess": true,
20
- "exactOptionalPropertyTypes": true,
21
- "isolatedModules": true,
22
- "erasableSyntaxOnly": true
23
- }
24
- }
@@ -1,15 +0,0 @@
1
- {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "description": "Extends the recommended preset with stricter settings.",
4
- "extends": "./recommended.json",
5
- "compilerOptions": {
6
- "checkJs": true,
7
- "isolatedModules": true,
8
- "verbatimModuleSyntax": true,
9
- "strict": true,
10
- "noUnusedLocals": true,
11
- "noUnusedParameters": true,
12
- "noFallthroughCasesInSwitch": true,
13
- "noPropertyAccessFromIndexSignature": true
14
- }
15
- }
@@ -1,16 +0,0 @@
1
- {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "description": "Stricter than strict",
4
- "extends": "./strict.json",
5
- "compilerOptions": {
6
- "strictNullChecks": true,
7
- "strictFunctionTypes": true,
8
- "strictPropertyInitialization": true,
9
- "alwaysStrict": true,
10
- "noImplicitAny": true,
11
- "noImplicitThis": true,
12
- "noImplicitReturns": true,
13
- "noImplicitOverride": true,
14
- "noUncheckedSideEffectImports": true
15
- }
16
- }