@@ -64,17 +64,34 @@ export function help (): string {
64
64
} )
65
65
}
66
66
67
- export async function handler (
68
- opts : Pick < UniversalOptions , 'dir' > & Pick < Config , 'catalogs' | 'ignoreScripts' | 'rawConfig' | 'embedReadme' | 'packGzipLevel' | 'nodeLinker' > & Partial < Pick < Config , 'extraBinPaths' | 'extraEnv' > > & {
69
- argv : {
70
- original : string [ ]
71
- }
72
- engineStrict ?: boolean
73
- packDestination ?: string
74
- workspaceDir ?: string
75
- json ?: boolean
67
+ export type PackOptions = Pick < UniversalOptions , 'dir' > & Pick < Config , 'catalogs' | 'ignoreScripts' | 'rawConfig' | 'embedReadme' | 'packGzipLevel' | 'nodeLinker' > & Partial < Pick < Config , 'extraBinPaths' | 'extraEnv' > > & {
68
+ argv : {
69
+ original : string [ ]
70
+ }
71
+ engineStrict ?: boolean
72
+ packDestination ?: string
73
+ workspaceDir ?: string
74
+ json ?: boolean
75
+ }
76
+
77
+ export async function handler ( opts : PackOptions ) : Promise < string > {
78
+ const { publishedManifest, tarballPath, contents } = await api ( opts )
79
+ if ( opts . json ) {
80
+ return JSON . stringify ( {
81
+ name : publishedManifest . name ,
82
+ version : publishedManifest . version ,
83
+ filename : tarballPath ,
84
+ files : contents . map ( ( path ) => ( { path } ) ) ,
85
+ } , null , 2 )
76
86
}
77
- ) : Promise < string > {
87
+ return `${ chalk . blueBright ( 'Tarball Contents' ) }
88
+ ${ contents . join ( '\n' ) }
89
+
90
+ ${ chalk . blueBright ( 'Tarball Details' ) }
91
+ ${ tarballPath } `
92
+ }
93
+
94
+ export async function api ( opts : PackOptions ) : Promise < PackResult > {
78
95
const { manifest : entryManifest , fileName : manifestFileName } = await readProjectManifest ( opts . dir , opts )
79
96
preventBundledDependenciesWithoutHoistedNodeLinker ( opts . nodeLinker , entryManifest )
80
97
const _runScriptsIfPresent = runScriptsIfPresent . bind ( null , {
@@ -152,19 +169,17 @@ export async function handler (
152
169
packedTarballPath = path . relative ( opts . dir , path . join ( dir , tarballName ) )
153
170
}
154
171
const packedContents = files . sort ( ( a , b ) => a . localeCompare ( b , 'en' ) )
155
- if ( opts . json ) {
156
- return JSON . stringify ( {
157
- name : publishManifest . name ,
158
- version : publishManifest . version ,
159
- filename : packedTarballPath ,
160
- files : packedContents . map ( ( path ) => ( { path } ) ) ,
161
- } , null , 2 )
172
+ return {
173
+ publishedManifest : publishManifest ,
174
+ contents : packedContents ,
175
+ tarballPath : packedTarballPath ,
162
176
}
163
- return `${ chalk . blueBright ( 'Tarball Contents' ) }
164
- ${ packedContents . join ( '\n' ) }
177
+ }
165
178
166
- ${ chalk . blueBright ( 'Tarball Details' ) }
167
- ${ packedTarballPath } `
179
+ export interface PackResult {
180
+ publishedManifest : ProjectManifest
181
+ contents : string [ ]
182
+ tarballPath : string
168
183
}
169
184
170
185
function preventBundledDependenciesWithoutHoistedNodeLinker ( nodeLinker : Config [ 'nodeLinker' ] , manifest : ProjectManifest ) : void {
0 commit comments