@sanity/pkg-utils 6.10.1 → 6.10.2-canary.1
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/consoleSpy.cjs +16 -1
- package/dist/_chunks-cjs/consoleSpy.cjs.map +1 -1
- package/dist/_chunks-cjs/index.cjs +2 -2
- package/dist/_chunks-cjs/index.cjs.map +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +18 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/node/core/config/types.ts +8 -1
- package/src/node/core/contexts/buildContext.ts +1 -0
- package/src/node/resolveBuildContext.ts +28 -0
- package/src/node/tasks/dts/doExtract.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/pkg-utils",
|
|
3
|
-
"version": "6.10.1",
|
|
3
|
+
"version": "6.10.2-canary.1",
|
|
4
4
|
"description": "Simple utilities for modern npm packages.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity-io",
|
|
@@ -146,7 +146,7 @@
|
|
|
146
146
|
"typescript": "5.5.3",
|
|
147
147
|
"vitest": "^1.6.0",
|
|
148
148
|
"vitest-github-actions-reporter": "^0.11.1",
|
|
149
|
-
"@sanity/pkg-utils": "6.10.1"
|
|
149
|
+
"@sanity/pkg-utils": "6.10.2-canary.1"
|
|
150
150
|
},
|
|
151
151
|
"peerDependencies": {
|
|
152
152
|
"typescript": "5.4.x || 5.5.x"
|
|
@@ -179,7 +179,14 @@ export interface PkgConfigOptions {
|
|
|
179
179
|
dist?: string
|
|
180
180
|
exports?: PkgConfigProperty<PkgExports>
|
|
181
181
|
extract?: {
|
|
182
|
-
|
|
182
|
+
/**
|
|
183
|
+
* Packages in `devDependencies` that are not in `external` are automatically added to the `bundledPackages` config.
|
|
184
|
+
* You can exclude a package from being bundled by using a callback:
|
|
185
|
+
* ```
|
|
186
|
+
* bundledPackages: (prev) => prev.filter(package => package !== 'sanity')
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
bundledPackages?: PkgConfigProperty<string[]>
|
|
183
190
|
customTags?: TSDocCustomTag[]
|
|
184
191
|
rules?: {
|
|
185
192
|
'ae-forgotten-export'?: PkgRuleLevel
|
|
@@ -116,6 +116,18 @@ export async function resolveBuildContext(options: {
|
|
|
116
116
|
config && Array.isArray(config.external)
|
|
117
117
|
? [...parsedExternal, ...config.external]
|
|
118
118
|
: resolveConfigProperty(config?.external, parsedExternal)
|
|
119
|
+
// Merge bundledPackages with dev deps, replace if it's a function
|
|
120
|
+
const externalWithTypes = new Set([pkg.name, ...external, ...external.map(transformPackageName)])
|
|
121
|
+
const bundledDependencies = [
|
|
122
|
+
...(pkg.devDependencies ? Object.keys(pkg.devDependencies) : []),
|
|
123
|
+
].filter(
|
|
124
|
+
// Do not bundle anything that is marked as external
|
|
125
|
+
(_) => !externalWithTypes.has(_),
|
|
126
|
+
)
|
|
127
|
+
const bundledPackages =
|
|
128
|
+
config && Array.isArray(config.extract?.bundledPackages)
|
|
129
|
+
? [...bundledDependencies, ...config.extract.bundledPackages]
|
|
130
|
+
: resolveConfigProperty(config?.extract?.bundledPackages, bundledDependencies)
|
|
119
131
|
|
|
120
132
|
const outputPaths = Object.values(exports)
|
|
121
133
|
.flatMap((exportEntry) => {
|
|
@@ -170,6 +182,7 @@ export async function resolveBuildContext(options: {
|
|
|
170
182
|
emitDeclarationOnly,
|
|
171
183
|
exports,
|
|
172
184
|
external,
|
|
185
|
+
bundledPackages,
|
|
173
186
|
files: [],
|
|
174
187
|
logger,
|
|
175
188
|
pkg,
|
|
@@ -184,3 +197,18 @@ export async function resolveBuildContext(options: {
|
|
|
184
197
|
|
|
185
198
|
return ctx
|
|
186
199
|
}
|
|
200
|
+
|
|
201
|
+
function transformPackageName(packageName: string): string {
|
|
202
|
+
if (packageName.startsWith('@types/')) {
|
|
203
|
+
// If it already starts with @types, return it as is
|
|
204
|
+
return packageName
|
|
205
|
+
} else if (packageName.startsWith('@')) {
|
|
206
|
+
// Handle scoped packages
|
|
207
|
+
const [scope, name] = packageName.split('/')
|
|
208
|
+
|
|
209
|
+
return `@types/${scope.slice(1)}__${name}`
|
|
210
|
+
} else {
|
|
211
|
+
// Handle regular packages
|
|
212
|
+
return `@types/${packageName}`
|
|
213
|
+
}
|
|
214
|
+
}
|
|
@@ -18,7 +18,7 @@ export async function doExtract(
|
|
|
18
18
|
ctx: BuildContext,
|
|
19
19
|
task: DtsTask | DtsWatchTask,
|
|
20
20
|
): Promise<DtsResult> {
|
|
21
|
-
const {config, cwd, files, logger, strict, ts} = ctx
|
|
21
|
+
const {config, cwd, files, logger, strict, ts, bundledPackages} = ctx
|
|
22
22
|
|
|
23
23
|
if (!ts.config || !ts.configPath) {
|
|
24
24
|
return {type: 'dts', messages: [], results: []}
|
|
@@ -48,7 +48,7 @@ export async function doExtract(
|
|
|
48
48
|
const targetPaths = entry.targetPaths.map((targetPath) => path.resolve(cwd, targetPath))
|
|
49
49
|
const filePaths = targetPaths.map((targetPath) => path.relative(outDir, targetPath))
|
|
50
50
|
const result = await extractTypes({
|
|
51
|
-
bundledPackages:
|
|
51
|
+
bundledPackages: bundledPackages || [],
|
|
52
52
|
customTags: config?.extract?.customTags,
|
|
53
53
|
cwd,
|
|
54
54
|
distPath: outDir,
|