11
11
12
12
const fs = require ( "fs" ) ;
13
13
const path = require ( "path" ) ;
14
+ const { fork } = require ( "child_process" ) ;
14
15
const { spawnProcess } = require ( "../../scripts/utils/spawn-process" ) ;
15
16
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" ) ;
19
21
22
+ ( async ( ) => {
20
23
if ( fs . existsSync ( testWorkspace ) ) {
21
24
await spawnProcess ( "rm" , [ "-rf" , testWorkspace ] , { } ) ;
22
25
}
@@ -27,14 +30,71 @@ const { spawnProcess } = require("../../scripts/utils/spawn-process");
27
30
cwd : testWorkspace ,
28
31
} ) ;
29
32
33
+ verdaccioFork = await runRegistry ( [ "-c" , path . join ( jsv3_root , "verdaccio" , "config.yaml" ) ] ) ;
34
+ await localPublishChangedPackages ( jsv3_root ) ;
35
+
30
36
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
+ } ) ;
34
46
35
47
fs . writeFileSync ( path . join ( testWorkspace , "app.js" ) , fs . readFileSync ( path . join ( __dirname , "canary-test-2.js" ) ) ) ;
36
48
37
49
await spawnProcess ( "node" , [ "app.js" ] , {
38
50
cwd : testWorkspace ,
39
51
} ) ;
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