Skip to content

Commit d315d05

Browse files
committed
feat(external): add TypeScript type definitions for external modules
Add comprehensive type definitions for external dependencies to improve type safety and IDE support: - Add type definitions for 13 external modules (fast-glob, has-flag, normalize-package-data, npm-package-arg, pony-cause, signal-exit, spdx-correct, spdx-expression-parse, streaming-iterables, supports-color, validate-npm-package-name, which, external-pack) - Update npm-pack.d.ts to include normalizePackageData, npmPackageArg, semver, and validateNpmPackageName - Add pony-cause external stub for error cause chain handling - Update build-externals config to include pony-cause
1 parent bb45736 commit d315d05

16 files changed

Lines changed: 106 additions & 1 deletion

scripts/build-externals/config.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ export const externalPackages = [
2626
{ name: 'debug', bundle: true },
2727
// pico-pack: picomatch, del, fast-glob
2828
{ name: 'pico-pack', bundle: true },
29-
// pico-pack internals - individual packages now just re-export from pico-pack bundle (no bundling needed)
3029
{ name: 'del', bundle: false },
3130
{ name: 'fast-glob', bundle: false },
3231
{ name: 'fast-sort', bundle: true },
3332
{ name: 'get-east-asian-width', bundle: true },
3433
{ name: 'has-flag', bundle: false },
3534
{ name: 'picomatch', bundle: false },
35+
// pony-cause
36+
{ name: 'pony-cause', bundle: true },
3637
// spdx-pack: Bundle spdx-correct, spdx-expression-parse, and dependencies together.
3738
{ name: 'spdx-pack', bundle: true },
3839
{ name: 'spdx-correct', bundle: false },

src/external/external-pack.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { default as hasFlag } from 'has-flag'
2+
import type { default as signalExit } from 'signal-exit'
3+
import type { default as supportsColor } from 'supports-color'
4+
5+
export interface ExternalPack {
6+
hasFlag: typeof hasFlag
7+
signalExit: typeof signalExit
8+
supportsColor: typeof supportsColor
9+
}
10+
11+
declare const externalPack: ExternalPack
12+
export default externalPack

src/external/fast-glob.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import type { PicoPack } from './pico-pack'
2+
3+
export type FastGlob = PicoPack['glob']
4+
5+
declare const fastGlob: FastGlob
6+
export default fastGlob
7+
8+
export const { glob, globStream, globSync } = fastGlob

src/external/has-flag.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { hasFlag as default } from './external-pack'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import type { NpmPack } from './npm-pack'
2+
3+
declare const normalizePackageData: NpmPack['normalizePackageData']
4+
export default normalizePackageData

src/external/npm-pack.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@ import type libnpmpack from 'libnpmpack'
33
import type * as cacache from 'cacache'
44
import type makeFetchHappen from 'make-fetch-happen'
55
import type Arborist from '@npmcli/arborist'
6+
import type normalizePackageData from 'normalize-package-data'
7+
import type npmPackageArg from 'npm-package-arg'
8+
import type * as semver from 'semver'
9+
import type validateNpmPackageName from 'validate-npm-package-name'
610

711
export interface NpmPack {
812
Arborist: typeof Arborist
913
pacote: Pick<typeof pacote, 'extract'>
1014
libnpmpack: typeof libnpmpack
1115
cacache: Pick<typeof cacache, 'get' | 'put' | 'rm' | 'ls' | 'tmp'>
1216
makeFetchHappen: Pick<typeof makeFetchHappen, 'defaults'>
17+
normalizePackageData: typeof normalizePackageData
18+
npmPackageArg: typeof npmPackageArg
19+
semver: typeof semver
20+
validateNpmPackageName: typeof validateNpmPackageName
1321
}
1422

1523
declare const npmPack: NpmPack

src/external/npm-package-arg.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import type { NpmPack } from './npm-pack'
2+
3+
declare const npmPackageArg: NpmPack['npmPackageArg']
4+
export default npmPackageArg

src/external/pony-cause.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export class ErrorWithCause extends Error {
2+
constructor(message: string, options?: { cause?: unknown })
3+
}
4+
5+
export function findCauseByReference(
6+
error: Error,
7+
reference: Error,
8+
): Error | undefined
9+
10+
export function getErrorCause(error: Error): Error | undefined
11+
12+
export function stackWithCauses(error: Error): string
13+
14+
export function messageWithCauses(error: Error): string

src/external/pony-cause.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
module.exports = require('pony-cause')

src/external/signal-exit.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { signalExit as default } from './external-pack'

0 commit comments

Comments
 (0)