@sanity/pkg-utils 5.1.5 → 5.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks-cjs/build.cjs +1 -1
- package/dist/_chunks-cjs/build.cjs.map +1 -1
- package/dist/_chunks-cjs/check.cjs +1 -1
- package/dist/_chunks-cjs/check.cjs.map +1 -1
- package/dist/_chunks-cjs/consoleSpy.cjs +5 -3
- package/dist/_chunks-cjs/consoleSpy.cjs.map +1 -1
- package/dist/_chunks-cjs/watch.cjs +1 -1
- package/dist/_chunks-cjs/watch.cjs.map +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +8 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/node/build.ts +3 -2
- package/src/node/check.ts +2 -1
- package/src/node/core/pkg/loadPkgWithReporting.ts +16 -6
- package/src/node/watch.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/pkg-utils",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.6",
|
|
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.
|
|
135
|
+
"@sanity/pkg-utils": "5.1.6"
|
|
136
136
|
},
|
|
137
137
|
"peerDependencies": {
|
|
138
138
|
"typescript": "5.4.2"
|
package/src/node/build.ts
CHANGED
|
@@ -33,9 +33,10 @@ 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, strict})
|
|
37
|
-
|
|
38
36
|
const config = await loadConfig({cwd})
|
|
37
|
+
const legacyExports = config?.legacyExports ?? false
|
|
38
|
+
const pkg = await loadPkgWithReporting({cwd, logger, strict, legacyExports})
|
|
39
|
+
|
|
39
40
|
const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'
|
|
40
41
|
|
|
41
42
|
const ctx = await resolveBuildContext({
|
package/src/node/check.ts
CHANGED
|
@@ -17,8 +17,9 @@ 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, strict})
|
|
21
20
|
const config = await loadConfig({cwd})
|
|
21
|
+
const legacyExports = config?.legacyExports ?? false
|
|
22
|
+
const pkg = await loadPkgWithReporting({cwd, logger, strict, legacyExports})
|
|
22
23
|
const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'
|
|
23
24
|
const ctx = await resolveBuildContext({config, cwd, logger, pkg, strict, tsconfig})
|
|
24
25
|
|
|
@@ -11,18 +11,28 @@ export async function loadPkgWithReporting(options: {
|
|
|
11
11
|
cwd: string
|
|
12
12
|
logger: Logger
|
|
13
13
|
strict: boolean
|
|
14
|
+
legacyExports: boolean
|
|
14
15
|
}): Promise<PackageJSON> {
|
|
15
|
-
const {cwd, logger, strict} = options
|
|
16
|
+
const {cwd, logger, strict, legacyExports} = options
|
|
16
17
|
|
|
17
18
|
try {
|
|
18
19
|
const pkg = await loadPkg({cwd})
|
|
19
20
|
let shouldError = false
|
|
20
21
|
|
|
21
|
-
if (strict
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
if (strict) {
|
|
23
|
+
if (legacyExports && pkg.type === 'commonjs') {
|
|
24
|
+
shouldError = true
|
|
25
|
+
logger.error(
|
|
26
|
+
`the \`type\` field in \`./package.json\` shouldn't be "commonjs" when \`legacyExports\` is set to true)`,
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!legacyExports && !pkg.type) {
|
|
31
|
+
shouldError = true
|
|
32
|
+
logger.error(
|
|
33
|
+
`the \`type\` field in \`./package.json\` must be either "module" or "commonjs")`,
|
|
34
|
+
)
|
|
35
|
+
}
|
|
26
36
|
}
|
|
27
37
|
|
|
28
38
|
// validate exports
|
package/src/node/watch.ts
CHANGED
|
@@ -30,8 +30,9 @@ export async function watch(options: {
|
|
|
30
30
|
throw new Error('missing package.json')
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
const pkg = await loadPkgWithReporting({cwd, logger, strict})
|
|
34
33
|
const config = await loadConfig({cwd})
|
|
34
|
+
const legacyExports = config?.legacyExports ?? false
|
|
35
|
+
const pkg = await loadPkgWithReporting({cwd, logger, strict, legacyExports})
|
|
35
36
|
const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'
|
|
36
37
|
|
|
37
38
|
return resolveBuildContext({config, cwd, logger, pkg, strict, tsconfig})
|