@sanity/pkg-utils 5.1.3-canary.0 → 5.1.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/dist/_chunks-cjs/build.cjs +1 -2
- 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 +18 -25
- package/dist/_chunks-cjs/consoleSpy.cjs.map +1 -1
- package/dist/_chunks-cjs/index.cjs +2 -10
- package/dist/_chunks-cjs/index.cjs.map +1 -1
- package/dist/_chunks-cjs/watch.cjs +2 -2
- package/dist/_chunks-cjs/watch.cjs.map +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/index.cjs +0 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -8
- package/dist/index.d.ts +0 -8
- package/dist/index.js +24 -40
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/node/build.ts +1 -3
- package/src/node/check.ts +2 -3
- package/src/node/core/contexts/buildContext.ts +4 -5
- package/src/node/core/pkg/parseExports.ts +4 -7
- package/src/node/core/pkg/pkgExt.ts +0 -8
- package/src/node/core/pkg/validateExports.ts +3 -3
- package/src/node/resolveBuildContext.ts +6 -11
- package/src/node/tasks/rollup/resolveRollupConfig.ts +2 -11
- package/src/node/watch.ts +2 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/pkg-utils",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.4",
|
|
4
4
|
"description": "Simple utilities for modern npm packages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity-io",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
},
|
|
60
60
|
"browserslist": "extends @sanity/browserslist-config",
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@babel/core": "^7.24.
|
|
62
|
+
"@babel/core": "^7.24.3",
|
|
63
63
|
"@babel/types": "^7.24.0",
|
|
64
64
|
"@microsoft/api-extractor": "7.43.0",
|
|
65
65
|
"@microsoft/tsdoc-config": "^0.16.2",
|
|
@@ -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.4"
|
|
136
136
|
},
|
|
137
137
|
"peerDependencies": {
|
|
138
138
|
"typescript": "5.4.2"
|
package/src/node/build.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {loadConfig, loadPkgWithReporting} from './core'
|
|
2
2
|
import {createLogger} from './logger'
|
|
3
3
|
import {resolveBuildContext} from './resolveBuildContext'
|
|
4
4
|
import {resolveBuildTasks} from './resolveBuildTasks'
|
|
@@ -36,14 +36,12 @@ export async function build(options: {
|
|
|
36
36
|
const pkg = await loadPkgWithReporting({cwd, logger, strict})
|
|
37
37
|
|
|
38
38
|
const config = await loadConfig({cwd})
|
|
39
|
-
const extMap = getPkgExtMap()
|
|
40
39
|
const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'
|
|
41
40
|
|
|
42
41
|
const ctx = await resolveBuildContext({
|
|
43
42
|
config,
|
|
44
43
|
cwd,
|
|
45
44
|
emitDeclarationOnly,
|
|
46
|
-
extMap,
|
|
47
45
|
logger,
|
|
48
46
|
pkg,
|
|
49
47
|
strict,
|
package/src/node/check.ts
CHANGED
|
@@ -2,7 +2,7 @@ import esbuild, {type BuildFailure} from 'esbuild'
|
|
|
2
2
|
import path from 'path'
|
|
3
3
|
|
|
4
4
|
import {createConsoleSpy} from './consoleSpy'
|
|
5
|
-
import {
|
|
5
|
+
import {loadConfig, loadPkgWithReporting} from './core'
|
|
6
6
|
import {fileExists} from './fileExists'
|
|
7
7
|
import {createLogger, type Logger} from './logger'
|
|
8
8
|
import {printPackageTree} from './printPackageTree'
|
|
@@ -19,9 +19,8 @@ export async function check(options: {
|
|
|
19
19
|
|
|
20
20
|
const pkg = await loadPkgWithReporting({cwd, logger, strict})
|
|
21
21
|
const config = await loadConfig({cwd})
|
|
22
|
-
const extMap = getPkgExtMap()
|
|
23
22
|
const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'
|
|
24
|
-
const ctx = await resolveBuildContext({config, cwd,
|
|
23
|
+
const ctx = await resolveBuildContext({config, cwd, logger, pkg, strict, tsconfig})
|
|
25
24
|
|
|
26
25
|
printPackageTree(ctx)
|
|
27
26
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import ts from 'typescript'
|
|
1
|
+
import type ts from 'typescript'
|
|
2
2
|
|
|
3
|
-
import {Logger} from '../../logger'
|
|
4
|
-
import {PkgConfigOptions, PkgExports, PkgRuntime} from '../config'
|
|
5
|
-
import {PackageJSON
|
|
3
|
+
import type {Logger} from '../../logger'
|
|
4
|
+
import type {PkgConfigOptions, PkgExports, PkgRuntime} from '../config'
|
|
5
|
+
import type {PackageJSON} from '../pkg'
|
|
6
6
|
|
|
7
7
|
/** @internal */
|
|
8
8
|
export interface BuildFile {
|
|
@@ -17,7 +17,6 @@ export interface BuildContext {
|
|
|
17
17
|
distPath: string
|
|
18
18
|
emitDeclarationOnly: boolean
|
|
19
19
|
exports: PkgExports | undefined
|
|
20
|
-
extMap: PkgExtMap
|
|
21
20
|
external: string[]
|
|
22
21
|
files: BuildFile[]
|
|
23
22
|
logger: Logger
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {legacyEnding} from '../../tasks/dts/getTargetPaths'
|
|
2
2
|
import type {PkgExport} from '../config'
|
|
3
3
|
import {isRecord} from '../isRecord'
|
|
4
|
-
import type {PkgExtMap} from './pkgExt'
|
|
5
4
|
import type {PackageJSON} from './types'
|
|
6
5
|
import {validateExports} from './validateExports'
|
|
7
6
|
|
|
8
7
|
/** @internal */
|
|
9
8
|
export function parseExports(options: {
|
|
10
|
-
extMap: PkgExtMap
|
|
11
9
|
pkg: PackageJSON
|
|
12
10
|
strict: boolean
|
|
13
11
|
legacyExports: boolean
|
|
14
12
|
}): (PkgExport & {_path: string})[] {
|
|
15
|
-
const {
|
|
13
|
+
const {pkg, strict, legacyExports} = options
|
|
16
14
|
|
|
17
15
|
const rootExport: PkgExport & {_path: string} = {
|
|
18
16
|
_exported: true,
|
|
@@ -70,7 +68,6 @@ export function parseExports(options: {
|
|
|
70
68
|
)
|
|
71
69
|
}
|
|
72
70
|
|
|
73
|
-
// @TODO do not run this check when legacyExports is true
|
|
74
71
|
if (legacyExports) {
|
|
75
72
|
const indexLegacyExport = (
|
|
76
73
|
exportEntry.browser?.import ||
|
|
@@ -78,7 +75,7 @@ export function parseExports(options: {
|
|
|
78
75
|
exportEntry.browser?.require ||
|
|
79
76
|
exportEntry.require ||
|
|
80
77
|
''
|
|
81
|
-
).replace(
|
|
78
|
+
).replace(/(\.esm)?\.[mc]?js$/, legacyEnding)
|
|
82
79
|
|
|
83
80
|
if (indexLegacyExport !== rootExport.import) {
|
|
84
81
|
errors.push(
|
|
@@ -121,7 +118,7 @@ export function parseExports(options: {
|
|
|
121
118
|
|
|
122
119
|
const _exports = [rootExport, ...extraExports]
|
|
123
120
|
|
|
124
|
-
errors.push(...validateExports(_exports, {
|
|
121
|
+
errors.push(...validateExports(_exports, {pkg}))
|
|
125
122
|
|
|
126
123
|
if (errors.length) {
|
|
127
124
|
throw new Error('\n- ' + errors.join('\n- '))
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type {PkgExport} from '../config'
|
|
2
|
-
import
|
|
2
|
+
import {pkgExtMap as extMap} from './pkgExt'
|
|
3
3
|
import type {PackageJSON} from './types'
|
|
4
4
|
|
|
5
5
|
export function validateExports(
|
|
6
6
|
_exports: (PkgExport & {_path: string})[],
|
|
7
|
-
options: {
|
|
7
|
+
options: {pkg: PackageJSON},
|
|
8
8
|
): string[] {
|
|
9
|
-
const {
|
|
9
|
+
const {pkg} = options
|
|
10
10
|
const ext = extMap[pkg.type || 'commonjs']
|
|
11
11
|
|
|
12
12
|
const errors: string[] = []
|
|
@@ -2,19 +2,18 @@ import browserslistToEsbuild from 'browserslist-to-esbuild'
|
|
|
2
2
|
import path from 'path'
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
-
BuildContext,
|
|
5
|
+
type BuildContext,
|
|
6
6
|
DEFAULT_BROWSERSLIST_QUERY,
|
|
7
7
|
loadTSConfig,
|
|
8
|
-
PackageJSON,
|
|
8
|
+
type PackageJSON,
|
|
9
9
|
parseExports,
|
|
10
|
-
PkgConfigOptions,
|
|
11
|
-
PkgExports,
|
|
12
|
-
|
|
13
|
-
PkgRuntime,
|
|
10
|
+
type PkgConfigOptions,
|
|
11
|
+
type PkgExports,
|
|
12
|
+
type PkgRuntime,
|
|
14
13
|
resolveConfigProperty,
|
|
15
14
|
} from './core'
|
|
16
15
|
import {findCommonDirPath, pathContains} from './core/findCommonPath'
|
|
17
|
-
import {Logger} from './logger'
|
|
16
|
+
import type {Logger} from './logger'
|
|
18
17
|
import {resolveBrowserTarget} from './resolveBrowserTarget'
|
|
19
18
|
import {resolveNodeTarget} from './resolveNodeTarget'
|
|
20
19
|
|
|
@@ -22,7 +21,6 @@ export async function resolveBuildContext(options: {
|
|
|
22
21
|
config?: PkgConfigOptions
|
|
23
22
|
cwd: string
|
|
24
23
|
emitDeclarationOnly?: boolean
|
|
25
|
-
extMap: PkgExtMap
|
|
26
24
|
logger: Logger
|
|
27
25
|
pkg: PackageJSON
|
|
28
26
|
strict: boolean
|
|
@@ -32,7 +30,6 @@ export async function resolveBuildContext(options: {
|
|
|
32
30
|
config,
|
|
33
31
|
cwd,
|
|
34
32
|
emitDeclarationOnly = false,
|
|
35
|
-
extMap,
|
|
36
33
|
logger,
|
|
37
34
|
pkg,
|
|
38
35
|
strict,
|
|
@@ -77,7 +74,6 @@ export async function resolveBuildContext(options: {
|
|
|
77
74
|
}
|
|
78
75
|
|
|
79
76
|
const parsedExports = parseExports({
|
|
80
|
-
extMap,
|
|
81
77
|
pkg,
|
|
82
78
|
strict,
|
|
83
79
|
legacyExports: config?.legacyExports ?? false,
|
|
@@ -151,7 +147,6 @@ export async function resolveBuildContext(options: {
|
|
|
151
147
|
emitDeclarationOnly,
|
|
152
148
|
exports,
|
|
153
149
|
external,
|
|
154
|
-
extMap,
|
|
155
150
|
files: [],
|
|
156
151
|
logger,
|
|
157
152
|
pkg,
|
|
@@ -85,11 +85,9 @@ export function resolveRollupConfig(
|
|
|
85
85
|
entries: {...pathAliases},
|
|
86
86
|
}),
|
|
87
87
|
nodeResolve({
|
|
88
|
-
// mainFields: ['module', 'jsnext', 'main'],
|
|
89
88
|
browser: runtime === 'browser',
|
|
90
|
-
// exportConditions: [runtime === 'node' ? 'node' : 'browser'],
|
|
91
89
|
extensions: ['.cjs', '.mjs', '.js', '.jsx', '.json', '.node'],
|
|
92
|
-
preferBuiltins: true,
|
|
90
|
+
preferBuiltins: true,
|
|
93
91
|
}),
|
|
94
92
|
commonjs(),
|
|
95
93
|
json(),
|
|
@@ -109,7 +107,7 @@ export function resolveRollupConfig(
|
|
|
109
107
|
Array.isArray(config?.babel?.plugins) &&
|
|
110
108
|
getBabelOutputPlugin({
|
|
111
109
|
babelrc: false,
|
|
112
|
-
plugins: config
|
|
110
|
+
plugins: config.babel.plugins,
|
|
113
111
|
}),
|
|
114
112
|
minify &&
|
|
115
113
|
terser({
|
|
@@ -137,13 +135,6 @@ export function resolveRollupConfig(
|
|
|
137
135
|
? defaultPlugins.concat(userPlugins)
|
|
138
136
|
: resolveConfigProperty(config?.rollup?.plugins, defaultPlugins)
|
|
139
137
|
|
|
140
|
-
// When using legacyExports then we need to hash the chunk file names to avoid chunks overwriting each other
|
|
141
|
-
if (config?.rollup?.hashChunkFileNames === false && config.legacyExports) {
|
|
142
|
-
throw new TypeError(
|
|
143
|
-
"when `legacyExports: true` you can't set `rollup.hashChunkFileNames: false` – this would cause chunks to overwrite each other. Please remove the `hashChunkFileNames` option or set it to `true",
|
|
144
|
-
)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
138
|
const hashChunkFileNames = config?.rollup?.hashChunkFileNames ?? false
|
|
148
139
|
const chunksFolder = isLegacyExports
|
|
149
140
|
? '_legacy'
|
package/src/node/watch.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from 'path'
|
|
2
2
|
import {switchMap} from 'rxjs'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {loadConfig, loadPkgWithReporting} from './core'
|
|
5
5
|
import {createLogger} from './logger'
|
|
6
6
|
import {resolveBuildContext} from './resolveBuildContext'
|
|
7
7
|
import {resolveWatchTasks} from './resolveWatchTasks'
|
|
@@ -32,10 +32,9 @@ export async function watch(options: {
|
|
|
32
32
|
|
|
33
33
|
const pkg = await loadPkgWithReporting({cwd, logger, strict})
|
|
34
34
|
const config = await loadConfig({cwd})
|
|
35
|
-
const extMap = getPkgExtMap()
|
|
36
35
|
const tsconfig = tsconfigOption || config?.tsconfig || 'tsconfig.json'
|
|
37
36
|
|
|
38
|
-
return resolveBuildContext({config, cwd,
|
|
37
|
+
return resolveBuildContext({config, cwd, logger, pkg, strict, tsconfig})
|
|
39
38
|
}),
|
|
40
39
|
)
|
|
41
40
|
|