File tree Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import type {
15
15
CheckForCacheOptions ,
16
16
Generator ,
17
17
RunOptions ,
18
+ PackageLocationMap ,
18
19
} from './types' ;
19
20
20
21
export const MAIN_BRANCH = config . mainBranch ;
@@ -280,3 +281,43 @@ export async function emptyDirExceptForDotGit(dir: string): Promise<void> {
280
281
}
281
282
}
282
283
}
284
+
285
+ export async function readPackageJson ( dir : string ) : Promise < any > {
286
+ const filePath = toAbsolutePath ( `${ dir } /package.json` ) ;
287
+ return JSON . parse ( ( await fsp . readFile ( filePath ) ) . toString ( ) ) ;
288
+ }
289
+
290
+ export async function getPackageLocationMap ( ) : Promise < PackageLocationMap > {
291
+ return ( await run ( `yarn workspaces list --json` ) )
292
+ . split ( '\n' )
293
+ . reduce ( ( acc , item ) => {
294
+ const { name, location } = JSON . parse ( item ) ;
295
+ return {
296
+ ...acc ,
297
+ [ name ] : location ,
298
+ } ;
299
+ } , { } ) ;
300
+ }
301
+
302
+ export async function updateDependenciesToLocalVersions (
303
+ packageDir : string
304
+ ) : Promise < void > {
305
+ const packageLocationMap = getPackageLocationMap ( ) ;
306
+
307
+ const targetPackageJson = await readPackageJson ( packageDir ) ;
308
+ for ( const packageName of targetPackageJson . dependencies ) {
309
+ if ( ! packageLocationMap [ packageName ] ) {
310
+ // Skip if it's not a local package.
311
+ continue ;
312
+ }
313
+
314
+ targetPackageJson . dependencies [ packageName ] = (
315
+ await readPackageJson ( packageLocationMap [ packageName ] )
316
+ ) . version ;
317
+ }
318
+
319
+ await fsp . writeFile (
320
+ toAbsolutePath ( `${ packageDir } /package.json` ) ,
321
+ `${ JSON . stringify ( targetPackageJson ) } \n`
322
+ ) ;
323
+ }
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import openapitools from '../../openapitools.json';
11
11
import {
12
12
ROOT_ENV_PATH ,
13
13
toAbsolutePath ,
14
+ updateDependenciesToLocalVersions ,
14
15
run ,
15
16
exists ,
16
17
getGitHubUrl ,
@@ -44,6 +45,10 @@ const BEFORE_CLIENT_GENERATION: {
44
45
} = {
45
46
javascript : async ( { releaseType, dir } ) => {
46
47
await run ( `yarn release:bump ${ releaseType } ` , { cwd : dir } ) ;
48
+
49
+ await updateDependenciesToLocalVersions ( 'tests/output/javascript' ) ;
50
+ await updateDependenciesToLocalVersions ( 'playground/javascript/browser' ) ;
51
+ await updateDependenciesToLocalVersions ( 'playground/javascript/node' ) ;
47
52
} ,
48
53
} ;
49
54
Original file line number Diff line number Diff line change @@ -48,6 +48,10 @@ export type Spec = {
48
48
paths : Path [ ] ;
49
49
} ;
50
50
51
+ export type PackageLocationMap = {
52
+ [ packageName : string ] : string ;
53
+ } ;
54
+
51
55
/**
52
56
* Server of a spec.
53
57
*/
You can’t perform that action at this time.
0 commit comments