@sanity/pkg-utils 6.13.3-canary.4 → 6.13.4

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.13.3-canary.4",
3
+ "version": "6.13.4",
4
4
  "description": "Simple utilities for modern npm packages.",
5
5
  "keywords": [
6
6
  "sanity-io",
@@ -70,7 +70,7 @@
70
70
  "@babel/core": "^7.26.0",
71
71
  "@babel/preset-typescript": "^7.26.0",
72
72
  "@babel/types": "^7.26.3",
73
- "@microsoft/api-extractor": "7.49.0",
73
+ "@microsoft/api-extractor": "7.48.1",
74
74
  "@microsoft/tsdoc-config": "0.17.1",
75
75
  "@optimize-lodash/rollup-plugin": "5.0.0",
76
76
  "@rollup/plugin-alias": "^5.1.1",
@@ -81,7 +81,7 @@
81
81
  "@rollup/plugin-replace": "^6.0.2",
82
82
  "@rollup/plugin-terser": "^0.4.4",
83
83
  "@sanity/browserslist-config": "^1.0.5",
84
- "browserslist": "^4.24.3",
84
+ "browserslist": "^4.24.4",
85
85
  "cac": "^6.7.14",
86
86
  "chalk": "^4.1.2",
87
87
  "chokidar": "^4.0.3",
@@ -126,7 +126,6 @@
126
126
  "@types/uuid": "^10.0.0",
127
127
  "@typescript-eslint/eslint-plugin": "^7.18.0",
128
128
  "@typescript-eslint/parser": "^7.18.0",
129
- "babel-plugin-react-compiler": "beta",
130
129
  "browserslist-to-esbuild": "2.1.1",
131
130
  "commitizen": "^4.3.1",
132
131
  "cpx": "^1.5.0",
@@ -143,9 +142,9 @@
143
142
  "rollup-plugin-visualizer": "^5.13.1",
144
143
  "semver": "^7.6.0",
145
144
  "ts-node": "^10.9.2",
146
- "typescript": "5.7.2",
145
+ "typescript": "5.7.3",
147
146
  "vitest": "^2.1.8",
148
- "@sanity/pkg-utils": "6.13.3-canary.4"
147
+ "@sanity/pkg-utils": "6.13.4"
149
148
  },
150
149
  "peerDependencies": {
151
150
  "babel-plugin-react-compiler": "*",
@@ -16,30 +16,26 @@ export type PkgRuntime = '*' | 'browser' | 'node'
16
16
  /** @public */
17
17
  export interface PkgExport {
18
18
  /** @internal */
19
- '_exported'?: boolean
20
- 'browser'?: {
19
+ _exported?: boolean
20
+ browser?: {
21
21
  source: string
22
22
  import?: string
23
23
  require?: string
24
24
  }
25
- 'react-compiler'?: {
26
- source?: string
27
- default: string
28
- }
29
25
  // electron?: {
30
26
  // node?: string
31
27
  // default?: string
32
28
  // }
33
- 'node'?: {
29
+ node?: {
34
30
  source?: string
35
31
  import?: string
36
32
  require?: string
37
33
  }
38
- 'types'?: string
39
- 'source': string
40
- 'import'?: string
41
- 'require'?: string
42
- 'default': string
34
+ types?: string
35
+ source: string
36
+ import?: string
37
+ require?: string
38
+ default: string
43
39
  }
44
40
 
45
41
  /** @public */
@@ -223,7 +219,7 @@ export interface PkgConfigOptions {
223
219
  customTags?: TSDocCustomTag[]
224
220
  rules?: {
225
221
  /**
226
- * @deprecated no longer needed since TypeScript 5.5 https://devblogs.microsoft.com/typescript/announcing-typescript-5-5/#consulting-package.json-dependencies-for-declaration-file-generation
222
+ * @deprecated as it's no longer needed since TypeScript 5.5 https://github.com/microsoft/TypeScript/issues/42873
227
223
  */
228
224
  'ae-forgotten-export'?: PkgRuleLevel
229
225
  'ae-incompatible-release-tags'?: PkgRuleLevel
@@ -260,6 +256,7 @@ export interface PkgConfigOptions {
260
256
  jsxImportSource?: string
261
257
  /**
262
258
  * Build package with support for legacy exports (writes root `<export>.js` files)
259
+ * @deprecated - will be removed in the next major version
263
260
  */
264
261
  legacyExports?: boolean
265
262
  minify?: boolean
@@ -22,35 +22,25 @@ const pkgSchema = z.object({
22
22
  z.custom<`./${string}.json`>((val) => /^\.\/.*\.json$/.test(val as string)),
23
23
  z.custom<`./${string}.css`>((val) => /^\.\/.*\.css$/.test(val as string)),
24
24
  z.object({
25
- 'types': z.optional(z.string()),
26
- 'source': z.optional(z.string()),
27
- 'browser': z.optional(
25
+ types: z.optional(z.string()),
26
+ source: z.optional(z.string()),
27
+ browser: z.optional(
28
28
  z.object({
29
29
  source: z.string(),
30
30
  import: z.optional(z.string()),
31
31
  require: z.optional(z.string()),
32
32
  }),
33
33
  ),
34
- 'react-compiler': z.optional(
35
- // z.union([
36
- // @TODO add support for a string shortcut
37
- // z.string(),
38
- z.object({
39
- source: z.optional(z.string()),
40
- default: z.string(),
41
- }),
42
- // ]),
43
- ),
44
- 'node': z.optional(
34
+ node: z.optional(
45
35
  z.object({
46
36
  source: z.optional(z.string()),
47
37
  import: z.optional(z.string()),
48
38
  require: z.optional(z.string()),
49
39
  }),
50
40
  ),
51
- 'import': z.optional(z.string()),
52
- 'require': z.optional(z.string()),
53
- 'default': z.string(),
41
+ import: z.optional(z.string()),
42
+ require: z.optional(z.string()),
43
+ default: z.string(),
54
44
  }),
55
45
  z.object({
56
46
  types: z.optional(z.string()),
@@ -139,8 +139,6 @@ export async function resolveBuildContext(options: {
139
139
  exportEntry.browser?.require,
140
140
  exportEntry.node?.source && exportEntry.node.import,
141
141
  exportEntry.node?.source && exportEntry.node.require,
142
- // @TODO implement this
143
- // exportEntry['react-compiler']?.source && exportEntry['react-compiler']?.default,
144
142
  ].filter(Boolean) as string[]
145
143
  })
146
144
  .map((p) => path.resolve(cwd, p))
@@ -2,14 +2,7 @@ import fs from 'node:fs'
2
2
  import path from 'node:path'
3
3
 
4
4
  import type {BuildContext, PkgExport, PkgFormat, PkgRuntime} from './core'
5
- import type {
6
- BuildTask,
7
- DtsTask,
8
- RollupLegacyTask,
9
- RollupReactCompilerTask,
10
- RollupTask,
11
- RollupTaskEntry,
12
- } from './tasks'
5
+ import type {BuildTask, DtsTask, RollupLegacyTask, RollupTask, RollupTaskEntry} from './tasks'
13
6
  import {fileEnding, getTargetPaths, legacyEnding} from './tasks/dts/getTargetPaths'
14
7
 
15
8
  /** @internal */
@@ -31,13 +24,6 @@ export function resolveBuildTasks(ctx: BuildContext): BuildTask[] {
31
24
 
32
25
  const rollupTasks: Record<string, RollupTask> = {}
33
26
  const rollupLegacyTasks: Record<string, RollupLegacyTask> = {}
34
- const rollupReactCompilerTask: RollupReactCompilerTask = {
35
- type: 'build:react-compiler',
36
- runtime: 'browser',
37
- format: 'esm',
38
- entries: [],
39
- target: target.browser,
40
- }
41
27
 
42
28
  function addRollupTaskEntry(format: PkgFormat, runtime: PkgRuntime, entry: RollupTaskEntry) {
43
29
  const buildId = `${format}:${runtime}`
@@ -74,10 +60,6 @@ export function resolveBuildTasks(ctx: BuildContext): BuildTask[] {
74
60
  }
75
61
  }
76
62
 
77
- function addRollupReactCompilerTaskEntry(entry: RollupTaskEntry) {
78
- rollupReactCompilerTask.entries.push(entry)
79
- }
80
-
81
63
  // Parse `dts` tasks
82
64
  for (const exp of exports) {
83
65
  const importId = path.join(pkg.name, exp._path)
@@ -108,16 +90,6 @@ export function resolveBuildTasks(ctx: BuildContext): BuildTask[] {
108
90
  targetPaths: getTargetPaths(pkg.type, exp.node),
109
91
  })
110
92
  }
111
-
112
- // @TODO implement this
113
- // if (exp['react-compiler']?.source?.endsWith('.ts')) {
114
- // dtsTask.entries.push({
115
- // importId,
116
- // exportPath: exp._path,
117
- // sourcePath: exp['react-compiler'].source,
118
- // targetPaths: getTargetPaths(pkg.type, exp['react-compiler']),
119
- // })
120
- // }
121
93
  }
122
94
 
123
95
  // Handle dts tasks for bundles
@@ -196,24 +168,6 @@ export function resolveBuildTasks(ctx: BuildContext): BuildTask[] {
196
168
  })
197
169
  }
198
170
 
199
- // Parse rollup:react-compiler tasks
200
- for (const exp of exports) {
201
- const output = exp['react-compiler']?.default
202
-
203
- if (!output) continue
204
-
205
- addRollupReactCompilerTaskEntry({
206
- path: exp._path,
207
- source: exp['react-compiler']?.source || exp.source,
208
- output,
209
- })
210
- }
211
-
212
- // Add react-compiler task
213
- if (rollupReactCompilerTask.entries.length) {
214
- tasks.push(rollupReactCompilerTask)
215
- }
216
-
217
171
  // Create rollup bundles that legacy export files will re-export
218
172
  if (config?.legacyExports) {
219
173
  for (const exp of exports) {
@@ -26,24 +26,45 @@ export function createApiExtractorConfig(options: {
26
26
  tsconfigPath,
27
27
  } = options
28
28
 
29
+ // When the module is 'preserve' it's necessary to override the tsconfig file as api-extractor doesn't handle it out of the box
30
+ const workaroundModulePreserve = tsconfig.options.module === ts.ModuleKind.Preserve
31
+ // If `paths` are used for self-referencing imports (e.g. the module is named `sanity`, and the `sanity/structure` export is also importing from `sanity/router`),
32
+ const workaroundPaths = !!tsconfig.options.paths
33
+
34
+ const overrideTsconfig = {
35
+ extends: tsconfigPath,
36
+ compilerOptions: {},
37
+ }
38
+
39
+ if (workaroundModulePreserve) {
40
+ Object.assign(overrideTsconfig.compilerOptions, {
41
+ // Set the equivalent options to `module: 'Preserve'`
42
+ // https://github.com/microsoft/TypeScript/pull/56785/files?file-filters%5B%5D=.js&file-filters%5B%5D=.json&file-filters%5B%5D=.symbols&file-filters%5B%5D=.ts&file-filters%5B%5D=.types&show-viewed-files=true#diff-31d3c12bafea26bc9e8c8a77920c41af0c593206442add70c45a06c063767445
43
+ module: 'ESNext',
44
+ moduleResolution: 'Bundler',
45
+ esModuleInterop: true,
46
+ resolveJsonModule: true,
47
+ })
48
+ }
49
+
50
+ if (workaroundPaths) {
51
+ Object.assign(overrideTsconfig.compilerOptions, {
52
+ // An empty object replaces whatever is in the original tsconfig file
53
+ paths: {},
54
+ })
55
+ }
56
+
29
57
  return {
30
58
  apiReport: {
31
59
  enabled: false,
32
60
  reportFileName: '<unscopedPackageName>.api.md',
33
61
  },
34
62
  bundledPackages,
35
- // If `paths` are used for self-referencing imports (e.g. the module is named `sanity`, and the `sanity/structure` export is also importing from `sanity/router`),
36
- compiler: tsconfig.options.paths
37
- ? {
38
- overrideTsconfig: {
39
- extends: tsconfigPath,
40
- compilerOptions: {
41
- // An empty object replaces whatever is in the original tsconfig file
42
- paths: {},
43
- },
44
- },
45
- }
46
- : {tsconfigFilePath: tsconfigPath},
63
+
64
+ compiler:
65
+ workaroundModulePreserve || workaroundPaths
66
+ ? {overrideTsconfig}
67
+ : {tsconfigFilePath: tsconfigPath},
47
68
 
48
69
  docModel: {
49
70
  enabled: false,
@@ -63,17 +63,6 @@ export function getTargetPaths(
63
63
  )
64
64
  }
65
65
  }
66
-
67
- if (!expOrBundle['react-compiler']?.source) {
68
- if (expOrBundle['react-compiler']?.default) {
69
- set.add(
70
- expOrBundle['react-compiler'].default.replace(
71
- fileEnding,
72
- type === 'module' ? dtsEnding : mtsEnding,
73
- ),
74
- )
75
- }
76
- }
77
66
  }
78
67
 
79
68
  return Array.from(set)
@@ -1,5 +1,5 @@
1
1
  import {dtsTask, dtsWatchTask} from './dts'
2
- import {rollupLegacyTask, rollupReactCompilerTask, rollupTask, rollupWatchTask} from './rollup'
2
+ import {rollupLegacyTask, rollupTask, rollupWatchTask} from './rollup'
3
3
  import type {BuildTaskHandlers, WatchTaskHandlers} from './types'
4
4
 
5
5
  export * from './dts'
@@ -11,7 +11,6 @@ export const buildTaskHandlers: BuildTaskHandlers = {
11
11
  'build:dts': dtsTask,
12
12
  'build:js': rollupTask,
13
13
  'build:legacy': rollupLegacyTask,
14
- 'build:react-compiler': rollupReactCompilerTask,
15
14
  }
16
15
 
17
16
  /** @internal */
@@ -1,4 +1,3 @@
1
1
  export * from './rollupLegacyTask'
2
- export * from './rollupReactCompilerTask'
3
2
  export * from './rollupTask'
4
3
  export * from './rollupWatchTask'
@@ -14,7 +14,7 @@ import esbuild from 'rollup-plugin-esbuild'
14
14
 
15
15
  import {pkgExtMap as extMap} from '../../../node/core/pkg/pkgExt'
16
16
  import {type BuildContext, type PackageJSON, resolveConfigProperty} from '../../core'
17
- import type {RollupLegacyTask, RollupReactCompilerTask, RollupTask, RollupWatchTask} from '../types'
17
+ import type {RollupLegacyTask, RollupTask, RollupWatchTask} from '../types'
18
18
 
19
19
  export interface RollupConfig {
20
20
  inputOptions: InputOptions
@@ -24,12 +24,11 @@ export interface RollupConfig {
24
24
  /** @internal */
25
25
  export function resolveRollupConfig(
26
26
  ctx: BuildContext,
27
- buildTask: RollupTask | RollupLegacyTask | RollupReactCompilerTask | RollupWatchTask,
27
+ buildTask: RollupTask | RollupLegacyTask | RollupWatchTask,
28
28
  ): RollupConfig {
29
29
  const {format, runtime, target} = buildTask
30
30
  const {config, cwd, exports: _exports, external, distPath, logger, pkg, ts} = ctx
31
31
  const isLegacyExports = buildTask.type === 'build:legacy'
32
- const isReactCompiler = buildTask.type === 'build:react-compiler'
33
32
  const outputExt = isLegacyExports ? extMap.legacy : extMap[pkg.type || 'commonjs'][format]
34
33
  const minify = config?.minify ?? false
35
34
  const outDir = path.relative(cwd, distPath)
@@ -97,7 +96,7 @@ export function resolveRollupConfig(
97
96
  }),
98
97
  commonjs(),
99
98
  json(),
100
- (isReactCompiler || config?.babel?.reactCompiler || config?.babel?.styledComponents) &&
99
+ (config?.babel?.reactCompiler || config?.babel?.styledComponents) &&
101
100
  babel({
102
101
  babelrc: false,
103
102
  presets: ['@babel/preset-typescript'],
@@ -121,7 +120,7 @@ export function resolveRollupConfig(
121
120
  : {}),
122
121
  },
123
122
  ],
124
- (isReactCompiler || config?.babel?.reactCompiler) && [
123
+ config?.babel?.reactCompiler && [
125
124
  'babel-plugin-react-compiler',
126
125
  config?.reactCompilerOptions || {},
127
126
  ],
@@ -181,13 +180,11 @@ export function resolveRollupConfig(
181
180
  : resolveConfigProperty(config?.rollup?.plugins, defaultPlugins)
182
181
 
183
182
  const hashChunkFileNames = config?.rollup?.hashChunkFileNames ?? false
184
- const chunksFolder = isReactCompiler
185
- ? '_compiled'
186
- : isLegacyExports
187
- ? '_legacy'
188
- : hashChunkFileNames
189
- ? '_chunks'
190
- : '_chunks-[format]'
183
+ const chunksFolder = isLegacyExports
184
+ ? '_legacy'
185
+ : hashChunkFileNames
186
+ ? '_chunks'
187
+ : '_chunks-[format]'
191
188
  const chunkFileNames = `${chunksFolder}/${hashChunkFileNames ? '[name]-[hash]' : '[name]'}${outputExt}`
192
189
  const entryFileNames = isLegacyExports ? '[name].js' : `[name]${outputExt}`
193
190
 
@@ -31,15 +31,6 @@ export interface RollupLegacyTask {
31
31
  target: string[]
32
32
  }
33
33
 
34
- /** @internal */
35
- export interface RollupReactCompilerTask {
36
- type: 'build:react-compiler'
37
- entries: RollupTaskEntry[]
38
- runtime: 'browser'
39
- format: 'esm'
40
- target: string[]
41
- }
42
-
43
34
  /** @internal */
44
35
  export interface RollupWatchTask {
45
36
  type: 'watch:js'
@@ -51,7 +42,7 @@ export interface RollupWatchTask {
51
42
  }
52
43
 
53
44
  /** @internal */
54
- export type BuildTask = DtsTask | RollupTask | RollupLegacyTask | RollupReactCompilerTask
45
+ export type BuildTask = DtsTask | RollupTask | RollupLegacyTask
55
46
 
56
47
  /** @internal */
57
48
  export type WatchTask = DtsWatchTask | RollupWatchTask
@@ -68,7 +59,6 @@ export type TaskHandler<Task, Result = void> = {
68
59
  export interface BuildTaskHandlers {
69
60
  'build:dts': TaskHandler<DtsTask, DtsResult>
70
61
  'build:js': TaskHandler<RollupTask>
71
- 'build:react-compiler': TaskHandler<RollupReactCompilerTask>
72
62
  'build:legacy': TaskHandler<RollupLegacyTask>
73
63
  }
74
64
 
@@ -1,140 +0,0 @@
1
- import path from 'node:path'
2
-
3
- import chalk from 'chalk'
4
- import {rollup} from 'rollup'
5
- import {Observable} from 'rxjs'
6
-
7
- import {createConsoleSpy} from '../../consoleSpy'
8
- import type {BuildContext} from '../../core'
9
- import type {RollupReactCompilerTask, TaskHandler} from '../types'
10
- import {resolveRollupConfig} from './resolveRollupConfig'
11
-
12
- /** @internal */
13
- export const rollupReactCompilerTask: TaskHandler<RollupReactCompilerTask> = {
14
- name: (ctx, task) => {
15
- const entries = task.entries.filter((e) => !e.path.includes('__$$bundle_'))
16
-
17
- const targetLines = task.target.length
18
- ? [' target:', ...task.target.map((t) => ` - ${chalk.yellow(t)}`)]
19
- : []
20
-
21
- const entriesLines = entries.length
22
- ? [
23
- ' entries:',
24
- ...entries.map((e) =>
25
- [
26
- ' - ',
27
- `${chalk.cyan(path.join(ctx.pkg.name, e.path))}: `,
28
- `${chalk.yellow(e.source)} ${chalk.gray('→')} ${chalk.yellow(e.output)}`,
29
- ].join(''),
30
- ),
31
- ]
32
- : []
33
-
34
- // @TODO list out the root level files that are generated
35
-
36
- return ['Build react compiler exports...', ...targetLines, ...entriesLines].join('\n')
37
- },
38
- exec: (ctx, task) => {
39
- return new Observable((observer) => {
40
- execPromise(ctx, task)
41
- .then((result) => {
42
- observer.next(result)
43
- observer.complete()
44
- })
45
- .catch((err) => observer.error(err))
46
- })
47
- },
48
- complete: () => {
49
- //
50
- },
51
- error: (_ctx, _task, err) => {
52
- // eslint-disable-next-line no-console
53
- console.error(err)
54
- },
55
- }
56
-
57
- async function execPromise(ctx: BuildContext, task: RollupReactCompilerTask) {
58
- const {distPath, files, logger} = ctx
59
- const outDir = path.relative(ctx.cwd, distPath)
60
-
61
- // Prevent rollup from printing directly to the console
62
- const consoleSpy = createConsoleSpy({
63
- onRestored: (messages) => {
64
- for (const msg of messages) {
65
- const text = String(msg.args[0])
66
-
67
- if (msg.code === 'CIRCULAR_DEPENDENCY') {
68
- continue // ignore
69
- }
70
-
71
- if (text.startsWith('Dynamic import can only')) {
72
- continue // ignore
73
- }
74
-
75
- if (text.startsWith('Sourcemap is likely to be incorrect')) {
76
- continue // ignore
77
- }
78
-
79
- if (msg.type === 'log') {
80
- logger.info(...msg.args)
81
- }
82
-
83
- if (msg.type === 'warn') {
84
- logger.warn(...msg.args)
85
- }
86
-
87
- if (msg.type === 'error') {
88
- logger.error(...msg.args)
89
- }
90
- }
91
- },
92
- })
93
-
94
- try {
95
- const {inputOptions, outputOptions} = resolveRollupConfig(ctx, task)
96
-
97
- // Create bundle
98
- const bundle = await rollup({
99
- ...inputOptions,
100
- onwarn(warning) {
101
- consoleSpy.messages.push({
102
- type: 'warn',
103
- code: warning.code,
104
- args: [warning.message],
105
- })
106
- },
107
- })
108
-
109
- // generate output specific code in-memory
110
- // you can call this function multiple times on the same bundle object
111
- const {output} = await bundle.generate(outputOptions)
112
-
113
- for (const chunkOrAsset of output) {
114
- if (chunkOrAsset.type === 'asset') {
115
- files.push({
116
- type: 'asset',
117
- path: path.resolve(outDir, chunkOrAsset.fileName),
118
- })
119
- } else {
120
- files.push({
121
- type: 'chunk',
122
- path: path.resolve(outDir, chunkOrAsset.fileName),
123
- })
124
- }
125
- }
126
-
127
- // or write the bundle to disk
128
- await bundle.write(outputOptions)
129
-
130
- // closes the bundle
131
- await bundle.close()
132
-
133
- // Restore console
134
- consoleSpy.restore()
135
- } catch (err) {
136
- // Restore console
137
- consoleSpy.restore()
138
- throw err
139
- }
140
- }