1111
1212const fs = require ( "fs" ) ;
1313const path = require ( "path" ) ;
14+ const { fork } = require ( "child_process" ) ;
1415const { spawnProcess } = require ( "../../scripts/utils/spawn-process" ) ;
1516
16- ( async ( ) => {
17- const jsv3_root = path . join ( __dirname , ".." , ".." ) ;
18- const testWorkspace = path . join ( jsv3_root , ".." , "canary-aws-sdk-js-v3" ) ;
17+ let verdaccioFork ;
18+
19+ const jsv3_root = path . join ( __dirname , ".." , ".." ) ;
20+ const testWorkspace = path . join ( jsv3_root , ".." , "canary-aws-sdk-js-v3" ) ;
1921
22+ ( async ( ) => {
2023 if ( fs . existsSync ( testWorkspace ) ) {
2124 await spawnProcess ( "rm" , [ "-rf" , testWorkspace ] , { } ) ;
2225 }
@@ -27,14 +30,71 @@ const { spawnProcess } = require("../../scripts/utils/spawn-process");
2730 cwd : testWorkspace ,
2831 } ) ;
2932
33+ verdaccioFork = await runRegistry ( [ "-c" , path . join ( jsv3_root , "verdaccio" , "config.yaml" ) ] ) ;
34+ await localPublishChangedPackages ( jsv3_root ) ;
35+
3036 await spawnProcess ( "npm" , [ "init" , "-y" ] , { cwd : testWorkspace } ) ;
31- await spawnProcess ( "npm" , [ "install" , `@aws-sdk/client-sts@latest` ] , { cwd : testWorkspace } ) ;
32- await spawnProcess ( "npm" , [ "install" , `@aws-sdk/client-s3@latest` ] , { cwd : testWorkspace } ) ;
33- await spawnProcess ( "npm" , [ "install" , `@aws-sdk/client-lambda@latest` ] , { cwd : testWorkspace } ) ;
37+ await spawnProcess ( "npm" , [ "install" , `@aws-sdk/client-sts@ci` , "--registry" , "http://localhost:4873/" ] , {
38+ cwd : testWorkspace ,
39+ } ) ;
40+ await spawnProcess ( "npm" , [ "install" , `@aws-sdk/client-s3@ci` , "--registry" , "http://localhost:4873/" ] , {
41+ cwd : testWorkspace ,
42+ } ) ;
43+ await spawnProcess ( "npm" , [ "install" , `@aws-sdk/client-lambda@ci` , "--registry" , "http://localhost:4873/" ] , {
44+ cwd : testWorkspace ,
45+ } ) ;
3446
3547 fs . writeFileSync ( path . join ( testWorkspace , "app.js" ) , fs . readFileSync ( path . join ( __dirname , "canary-test-2.js" ) ) ) ;
3648
3749 await spawnProcess ( "node" , [ "app.js" ] , {
3850 cwd : testWorkspace ,
3951 } ) ;
40- } ) ( ) ;
52+ } ) ( ) . finally ( async ( ) => {
53+ if ( verdaccioFork ) {
54+ verdaccioFork . kill ( ) ;
55+ }
56+ await spawnProcess ( "git" , [ "checkout" , "--" , "." ] , {
57+ cwd : jsv3_root ,
58+ } ) ;
59+ } ) ;
60+
61+ function runRegistry ( args = [ ] , childOptions = { } ) {
62+ return new Promise ( ( resolve , reject ) => {
63+ const childFork = fork ( require . resolve ( "verdaccio/bin/verdaccio" ) , args , childOptions ) ;
64+ childFork . on ( "message" , ( msg ) => {
65+ if ( msg . verdaccio_started ) {
66+ resolve ( childFork ) ;
67+ }
68+ } ) ;
69+ childFork . on ( "error" , ( err ) => reject ( [ err ] ) ) ;
70+ childFork . on ( "disconnect" , ( err ) => reject ( [ err ] ) ) ;
71+ } ) ;
72+ }
73+
74+ async function localPublishChangedPackages ( root ) {
75+ await spawnProcess ( "rm" , [ "-rf" , "verdaccio/storage" ] , { cwd : root , stdio : "inherit" } ) ;
76+
77+ const args = [
78+ "lerna" ,
79+ "publish" ,
80+ "prerelease" ,
81+ "--force-publish" ,
82+ "--preid" ,
83+ "ci" ,
84+ "--exact" ,
85+ "--registry" ,
86+ "http://localhost:4873/" ,
87+ "--yes" ,
88+ "--no-changelog" ,
89+ "--no-git-tag-version" ,
90+ "--no-push" ,
91+ "--no-git-reset" ,
92+ "--ignore-scripts" ,
93+ "--no-verify-access" ,
94+ "--concurrency" ,
95+ "8" ,
96+ "--dist-tag" ,
97+ "ci" ,
98+ ] ;
99+ await spawnProcess ( "npx" , args , { cwd : root , stdio : "inherit" } ) ;
100+ }
0 commit comments