@sanity/pkg-utils 5.1.1-canary.0 → 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/dist/_chunks-cjs/build.cjs +11 -10
- 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/index.cjs +1 -1
- package/dist/_chunks-cjs/index.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 +19 -16
- package/dist/index.js.map +1 -1
- package/package.json +20 -26
- package/src/node/build.ts +2 -1
- package/src/node/check.ts +3 -3
- package/src/node/core/pkg/loadPkgWithReporting.ts +9 -1
- package/src/node/core/pkg/parseExports.ts +1 -1
- package/src/node/resolveBuildTasks.ts +14 -13
- package/src/node/tasks/dts/extractTypes.ts +0 -2
- package/src/node/watch.ts +1 -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.2",
|
|
4
4
|
"description": "Simple utilities for modern npm packages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity-io",
|
|
@@ -46,24 +46,6 @@
|
|
|
46
46
|
"!dist/stats.html",
|
|
47
47
|
"src"
|
|
48
48
|
],
|
|
49
|
-
"scripts": {
|
|
50
|
-
"build": "run-s clean build:pkg check:pkg",
|
|
51
|
-
"build:pkg": "node -r esbuild-register scripts/build",
|
|
52
|
-
"check:pkg": "node -r esbuild-register scripts/check",
|
|
53
|
-
"check:types": "tsc --build",
|
|
54
|
-
"clean": "rimraf dist test/env/__tmp__",
|
|
55
|
-
"commit": "cz",
|
|
56
|
-
"extract": "sanity-tsdoc etl --outDir etc/api/@sanity/pkg-utils --tsconfig tsconfig.dist.json",
|
|
57
|
-
"format": "prettier --write --cache --ignore-unknown . && eslint . --ext .cjs,.js,.ts,.tsx --fix --quiet",
|
|
58
|
-
"lint": "eslint . --ext .cjs,.js,.ts,.tsx",
|
|
59
|
-
"playground:build": "pnpm --filter './playground/**' build",
|
|
60
|
-
"playground:clean": "pnpm --filter './playground/**' --silent clean",
|
|
61
|
-
"prepublishOnly": "pnpm run build",
|
|
62
|
-
"test": "run-s playground:clean test:clean vitest:run",
|
|
63
|
-
"test:clean": "rimraf test/env/__tmp__",
|
|
64
|
-
"vitest:run": "vitest run",
|
|
65
|
-
"watch": "node -r esbuild-register scripts/watch"
|
|
66
|
-
},
|
|
67
49
|
"commitlint": {
|
|
68
50
|
"extends": [
|
|
69
51
|
"@commitlint/config-conventional"
|
|
@@ -119,7 +101,6 @@
|
|
|
119
101
|
"devDependencies": {
|
|
120
102
|
"@commitlint/cli": "^19.2.1",
|
|
121
103
|
"@commitlint/config-conventional": "^19.1.0",
|
|
122
|
-
"@sanity/pkg-utils": "workspace:*",
|
|
123
104
|
"@types/babel__core": "^7.20.5",
|
|
124
105
|
"@types/cpx": "^1.5.5",
|
|
125
106
|
"@types/find-config": "^1.0.4",
|
|
@@ -150,7 +131,8 @@
|
|
|
150
131
|
"ts-node": "^10.9.2",
|
|
151
132
|
"typescript": "5.4.2",
|
|
152
133
|
"vitest": "^1.4.0",
|
|
153
|
-
"vitest-github-actions-reporter": "^0.11.1"
|
|
134
|
+
"vitest-github-actions-reporter": "^0.11.1",
|
|
135
|
+
"@sanity/pkg-utils": "5.1.2"
|
|
154
136
|
},
|
|
155
137
|
"peerDependencies": {
|
|
156
138
|
"typescript": "5.4.2"
|
|
@@ -162,9 +144,21 @@
|
|
|
162
144
|
"publishConfig": {
|
|
163
145
|
"access": "public"
|
|
164
146
|
},
|
|
165
|
-
"
|
|
166
|
-
"
|
|
167
|
-
|
|
168
|
-
|
|
147
|
+
"scripts": {
|
|
148
|
+
"build": "run-s clean build:pkg check:pkg",
|
|
149
|
+
"build:pkg": "node -r esbuild-register scripts/build",
|
|
150
|
+
"check:pkg": "node -r esbuild-register scripts/check",
|
|
151
|
+
"check:types": "tsc --build",
|
|
152
|
+
"clean": "rimraf dist test/env/__tmp__",
|
|
153
|
+
"commit": "cz",
|
|
154
|
+
"extract": "sanity-tsdoc etl --outDir etc/api/@sanity/pkg-utils --tsconfig tsconfig.dist.json",
|
|
155
|
+
"format": "prettier --write --cache --ignore-unknown . && eslint . --ext .cjs,.js,.ts,.tsx --fix --quiet",
|
|
156
|
+
"lint": "eslint . --ext .cjs,.js,.ts,.tsx",
|
|
157
|
+
"playground:build": "pnpm --filter './playground/**' build",
|
|
158
|
+
"playground:clean": "pnpm --filter './playground/**' --silent clean",
|
|
159
|
+
"test": "run-s playground:clean test:clean vitest:run",
|
|
160
|
+
"test:clean": "rimraf test/env/__tmp__",
|
|
161
|
+
"vitest:run": "vitest run",
|
|
162
|
+
"watch": "node -r esbuild-register scripts/watch"
|
|
169
163
|
}
|
|
170
|
-
}
|
|
164
|
+
}
|
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
|
)
|
|
@@ -75,18 +75,20 @@ export function resolveBuildTasks(ctx: BuildContext): BuildTask[] {
|
|
|
75
75
|
|
|
76
76
|
// Handle dts tasks for bundles
|
|
77
77
|
for (const bundle of bundles) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
78
|
+
if (bundle.source?.endsWith('.ts')) {
|
|
79
|
+
// importId needs to be how the bundle is used, like `@sanity/pkg-utils/dist/cli`
|
|
80
|
+
// exportPath needs to be the path to the bundle, like `./dist/cli`
|
|
81
|
+
// targetPaths is then: [./dist/cli.d.ts, ./dist/cli.d.cts]
|
|
82
|
+
const exportPath = (bundle.import || bundle.require)!.replace(/\.[mc]?js$/, '')
|
|
83
|
+
const importId = path.join(pkg.name, exportPath)
|
|
84
|
+
|
|
85
|
+
dtsTask.entries.push({
|
|
86
|
+
importId,
|
|
87
|
+
exportPath,
|
|
88
|
+
sourcePath: bundle.source,
|
|
89
|
+
targetPaths: getTargetPaths(pkg.type, bundle),
|
|
90
|
+
})
|
|
91
|
+
}
|
|
90
92
|
}
|
|
91
93
|
|
|
92
94
|
// Add dts task
|
|
@@ -147,7 +149,6 @@ export function resolveBuildTasks(ctx: BuildContext): BuildTask[] {
|
|
|
147
149
|
})
|
|
148
150
|
}
|
|
149
151
|
|
|
150
|
-
// @TODO also handle bundles
|
|
151
152
|
for (const bundle of bundles) {
|
|
152
153
|
const idx = bundles.indexOf(bundle)
|
|
153
154
|
|
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'
|