@@ -64,7 +64,7 @@ const optionsSchema = z
6464 '--apply cannot be combined with --exact or --release-type, as it will always read from code/package.json#deferredNextVersion' ,
6565 } ) ;
6666 }
67- if ( ( hasExact && hasReleaseType ) || ( ! hasExact && ! hasReleaseType ) ) {
67+ if ( ! hasApply && ( ( hasExact && hasReleaseType ) || ( ! hasExact && ! hasReleaseType ) ) ) {
6868 ctx . addIssue ( {
6969 code : z . ZodIssueCode . custom ,
7070 message :
@@ -211,9 +211,9 @@ const bumpAllPackageJsons = async ({
211211
212212const bumpDeferred = async ( nextVersion : string ) => {
213213 console . log (
214- `⏳ Setting a ${ chalk . cyan (
215- 'deferred '
216- ) } version bump with code/package.json#deferredNextVersion = ${ chalk . yellow ( nextVersion ) } ...`
214+ `⏳ Setting a ${ chalk . cyan ( 'deferred' ) } version bump with ${ chalk . blue (
215+ 'code/package.json#deferredNextVersion '
216+ ) } = ${ chalk . yellow ( nextVersion ) } ...`
217217 ) ;
218218 const codePkgJson = await readJson ( CODE_PACKAGE_JSON_PATH ) ;
219219
@@ -223,14 +223,40 @@ const bumpDeferred = async (nextVersion: string) => {
223223 console . log ( `✅ Set a ${ chalk . cyan ( 'deferred' ) } version bump. Not bumping any packages.` ) ;
224224} ;
225225
226+ const applyDeferredVersionBump = async ( ) => {
227+ console . log (
228+ `⏩ Applying previously deferred version bump set at ${ chalk . blue (
229+ 'code/package.json#deferredNextVersion'
230+ ) } ...`
231+ ) ;
232+ const codePkgJson = await readJson ( CODE_PACKAGE_JSON_PATH ) ;
233+
234+ const { deferredNextVersion } = codePkgJson ;
235+
236+ if ( ! deferredNextVersion ) {
237+ throw new Error (
238+ "The 'deferredNextVersion' property in code/package.json is unset. This is necessary to apply a deferred version bump"
239+ ) ;
240+ }
241+
242+ delete codePkgJson . deferredNextVersion ;
243+ await writeJson ( CODE_PACKAGE_JSON_PATH , codePkgJson , { spaces : 2 } ) ;
244+
245+ console . log (
246+ `✅ Extracted and removed deferred version ${ chalk . green (
247+ deferredNextVersion
248+ ) } from ${ chalk . blue ( 'code/package.json#deferredNextVersion' ) } `
249+ ) ;
250+
251+ return deferredNextVersion ;
252+ } ;
253+
226254export const run = async ( options : unknown ) => {
227255 if ( ! validateOptions ( options ) ) {
228256 return ;
229257 }
230258 const { verbose } = options ;
231259
232- // TODO: if apply, set next version from deferred and removed deferred version
233-
234260 console . log ( `🚛 Finding Storybook packages...` ) ;
235261
236262 const [ packages , currentVersion ] = await Promise . all ( [ getWorkspaces ( ) , getCurrentVersion ( ) ] ) ;
@@ -248,7 +274,9 @@ export const run = async (options: unknown) => {
248274
249275 let nextVersion : string ;
250276
251- if ( 'exact' in options && options . exact ) {
277+ if ( 'apply' in options && options . apply ) {
278+ nextVersion = await applyDeferredVersionBump ( ) ;
279+ } else if ( 'exact' in options && options . exact ) {
252280 console . log ( `📈 Exact version selected: ${ chalk . green ( options . exact ) } ` ) ;
253281 nextVersion = options . exact ;
254282 } else {
0 commit comments