@@ -33,7 +33,7 @@ export async function installAddon<Addons extends AddonMap>({
33
33
cwd,
34
34
options,
35
35
packageManager = 'npm'
36
- } : InstallOptions < Addons > ) : Promise < string [ ] > {
36
+ } : InstallOptions < Addons > ) : Promise < ReturnType < typeof applyAddons > > {
37
37
const workspace = createWorkspace ( { cwd, packageManager } ) ;
38
38
const addonSetupResults = setupAddons ( Object . values ( addons ) , workspace ) ;
39
39
@@ -51,20 +51,33 @@ export async function applyAddons({
51
51
workspace,
52
52
addonSetupResults,
53
53
options
54
- } : ApplyAddonOptions ) : Promise < string [ ] > {
54
+ } : ApplyAddonOptions ) : Promise < {
55
+ filesToFormat : string [ ] ;
56
+ pnpmBuildDependencies : string [ ] ;
57
+ } > {
55
58
const filesToFormat = new Set < string > ( ) ;
59
+ const allPnpmBuildDependencies : string [ ] = [ ] ;
56
60
57
61
const mapped = Object . entries ( addons ) . map ( ( [ , addon ] ) => addon ) ;
58
62
const ordered = orderAddons ( mapped , addonSetupResults ) ;
59
63
60
64
for ( const addon of ordered ) {
61
65
workspace = createWorkspace ( { ...workspace , options : options [ addon . id ] } ) ;
62
66
63
- const files = await runAddon ( { workspace, addon, multiple : ordered . length > 1 } ) ;
67
+ const { files, pnpmBuildDependencies } = await runAddon ( {
68
+ workspace,
69
+ addon,
70
+ multiple : ordered . length > 1
71
+ } ) ;
72
+
64
73
files . forEach ( ( f ) => filesToFormat . add ( f ) ) ;
74
+ pnpmBuildDependencies . forEach ( ( s ) => allPnpmBuildDependencies . push ( s ) ) ;
65
75
}
66
76
67
- return Array . from ( filesToFormat ) ;
77
+ return {
78
+ filesToFormat : Array . from ( filesToFormat ) ,
79
+ pnpmBuildDependencies : allPnpmBuildDependencies
80
+ } ;
68
81
}
69
82
70
83
export function setupAddons (
@@ -91,7 +104,7 @@ type RunAddon = {
91
104
addon : Addon < Record < string , Question > > ;
92
105
multiple : boolean ;
93
106
} ;
94
- async function runAddon ( { addon, multiple, workspace } : RunAddon ) : Promise < string [ ] > {
107
+ async function runAddon ( { addon, multiple, workspace } : RunAddon ) {
95
108
const files = new Set < string > ( ) ;
96
109
97
110
// apply default addon options
@@ -103,6 +116,7 @@ async function runAddon({ addon, multiple, workspace }: RunAddon): Promise<strin
103
116
}
104
117
105
118
const dependencies : Array < { pkg : string ; version : string ; dev : boolean } > = [ ] ;
119
+ const pnpmBuildDependencies : string [ ] = [ ] ;
106
120
const sv : SvApi = {
107
121
file : ( path , content ) => {
108
122
try {
@@ -150,14 +164,20 @@ async function runAddon({ addon, multiple, workspace }: RunAddon): Promise<strin
150
164
} ,
151
165
devDependency : ( pkg , version ) => {
152
166
dependencies . push ( { pkg, version, dev : true } ) ;
167
+ } ,
168
+ pnpmBuildDependendency : ( pkg ) => {
169
+ pnpmBuildDependencies . push ( pkg ) ;
153
170
}
154
171
} ;
155
172
await addon . run ( { ...workspace , sv } ) ;
156
173
157
174
const pkgPath = installPackages ( dependencies , workspace ) ;
158
175
files . add ( pkgPath ) ;
159
176
160
- return Array . from ( files ) ;
177
+ return {
178
+ files : Array . from ( files ) ,
179
+ pnpmBuildDependencies
180
+ } ;
161
181
}
162
182
163
183
// sorts them to their execution order
0 commit comments