@sanity/pkg-utils 5.1.1 → 5.1.2

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": "5.1.1",
3
+ "version": "5.1.2",
4
4
  "description": "Simple utilities for modern npm packages.",
5
5
  "keywords": [
6
6
  "sanity-io",
@@ -132,7 +132,7 @@
132
132
  "typescript": "5.4.2",
133
133
  "vitest": "^1.4.0",
134
134
  "vitest-github-actions-reporter": "^0.11.1",
135
- "@sanity/pkg-utils": "5.1.1"
135
+ "@sanity/pkg-utils": "5.1.2"
136
136
  },
137
137
  "peerDependencies": {
138
138
  "typescript": "5.4.2"
package/src/node/build.ts CHANGED
@@ -33,7 +33,8 @@ export async function build(options: {
33
33
  const {cwd, emitDeclarationOnly, strict = false, tsconfig: tsconfigOption} = options
34
34
  const logger = createLogger()
35
35
 
36
- const pkg = await loadPkgWithReporting({cwd, logger})
36
+ const pkg = await loadPkgWithReporting({cwd, logger, strict})
37
+
37
38
  const config = await loadConfig({cwd})
38
39
  const extMap = getPkgExtMap({legacyExports: config?.legacyExports ?? false})
39
40
  const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'
package/src/node/check.ts CHANGED
@@ -1,10 +1,10 @@
1
- import esbuild, {BuildFailure} from 'esbuild'
1
+ import esbuild, {type BuildFailure} from 'esbuild'
2
2
  import path from 'path'
3
3
 
4
4
  import {createConsoleSpy} from './consoleSpy'
5
5
  import {getPkgExtMap, loadConfig, loadPkgWithReporting} from './core'
6
6
  import {fileExists} from './fileExists'
7
- import {createLogger, Logger} from './logger'
7
+ import {createLogger, type Logger} from './logger'
8
8
  import {printPackageTree} from './printPackageTree'
9
9
  import {resolveBuildContext} from './resolveBuildContext'
10
10
 
@@ -17,7 +17,7 @@ export async function check(options: {
17
17
  const {cwd, strict = false, tsconfig: tsconfigOption} = options
18
18
  const logger = createLogger()
19
19
 
20
- const pkg = await loadPkgWithReporting({cwd, logger})
20
+ const pkg = await loadPkgWithReporting({cwd, logger, strict})
21
21
  const config = await loadConfig({cwd})
22
22
  const extMap = getPkgExtMap({legacyExports: config?.legacyExports ?? false})
23
23
  const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'
@@ -10,13 +10,21 @@ import type {PackageJSON} from './types'
10
10
  export async function loadPkgWithReporting(options: {
11
11
  cwd: string
12
12
  logger: Logger
13
+ strict: boolean
13
14
  }): Promise<PackageJSON> {
14
- const {cwd, logger} = options
15
+ const {cwd, logger, strict} = options
15
16
 
16
17
  try {
17
18
  const pkg = await loadPkg({cwd})
18
19
  let shouldError = false
19
20
 
21
+ if (strict && !pkg.type) {
22
+ shouldError = true
23
+ logger.error(
24
+ `the \`type\` field in \`./package.json\` must be either "module" or "commonjs")`,
25
+ )
26
+ }
27
+
20
28
  // validate exports
21
29
  if (pkg.exports) {
22
30
  const _exports = Object.entries(pkg.exports)
@@ -30,7 +30,7 @@ export function parseExports(options: {
30
30
 
31
31
  const errors: string[] = []
32
32
 
33
- if (strict && !pkg.types && pkg.source?.endsWith('.ts')) {
33
+ if (strict && !pkg.types && pkg.source?.endsWith('.ts') && pkg.exports) {
34
34
  errors.push(
35
35
  'package.json: `types` must be declared for the npm listing to show as a TypeScript module.',
36
36
  )
package/src/node/watch.ts CHANGED
@@ -30,7 +30,7 @@ export async function watch(options: {
30
30
  throw new Error('missing package.json')
31
31
  }
32
32
 
33
- const pkg = await loadPkgWithReporting({cwd, logger})
33
+ const pkg = await loadPkgWithReporting({cwd, logger, strict})
34
34
  const config = await loadConfig({cwd})
35
35
  const extMap = getPkgExtMap({legacyExports: config?.legacyExports ?? false})
36
36
  const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'