Skip to content

Commit bd9fc79

Browse files
committed
first cut better errorhandling
1 parent f3d2c47 commit bd9fc79

File tree

2 files changed

+96
-43
lines changed

2 files changed

+96
-43
lines changed

util/local_verdaccio_publish

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,55 @@
1-
#!/bin/bash
1+
#!/usr/bin/env node
2+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3+
// SPDX-License-Identifier: Apache-2.0
24

3-
# Always clear storage so the latest versions are published
4-
# I am not worried about _what_ version number is published
5-
# Only that it is the latest code
6-
rm -rf verdaccio/storage/@aws-crypto
5+
// This is done in a node script for 2 reasons
6+
// 1. Potability: I will need to run this in windows
7+
// 2. Errors. If the main command fails, the script needs to clean up
8+
// but and exit with this error.
9+
// this _can_ be done from bash or shell,
10+
// but now the portability problems loom large.
711

8-
# Start verdaccio in the background
9-
verdaccio -c verdaccio/config.yaml &
12+
const { spawn, execSync } = require('child_process')
13+
const pipeStdIo = { stdio: [process.stdin, process.stdout, process.stderr] }
1014

11-
# Publish all changed packages the local verdaccio server.
12-
# Anything that has not been changed will match what is in npm
13-
npx lerna publish prepatch \
14-
--registry http://localhost:4873/ \
15-
--yes \
16-
--no-changelog \
17-
--no-git-tag-version \
18-
--no-push \
19-
--no-git-reset \
20-
--ignore-scripts \
21-
--preid ci \
22-
--no-verify-access
15+
// Always clear storage so the latest versions are published
16+
// I am not worried about _what_ version number is published
17+
// Only that it is the latest code
18+
execSync('rm -rf verdaccio/storage/@aws-crypto')
2319

24-
# The above command will make some modifications,
25-
# Roll them back
26-
# Idealy, we would find a way to not have to do this
27-
git checkout -- modules/**/package-lock.json
28-
git checkout -- modules/**/package.json
20+
// Start verdaccio in the background
21+
const verdaccio = spawn('npx', ['verdaccio', '-c', 'verdaccio/config.yaml'], pipeStdIo)
22+
.on('error', e => {
23+
throw e
24+
})
2925

30-
# Kill everying
31-
# Especialy the background verdaccio server
32-
kill $(jobs -pr)
26+
// Publish all changed packages the local verdaccio server.
27+
// Anything that has not been changed will match what is in npm
28+
const args = [
29+
'lerna', 'publish', 'prepatch',
30+
'--registry', 'http://localhost:4873/',
31+
'--yes',
32+
'--no-changelog',
33+
'--no-git-tag-version',
34+
'--no-push',
35+
'--no-git-reset',
36+
'--ignore-scripts',
37+
'--preid', 'ci',
38+
'--no-verify-access'
39+
]
40+
spawn('npx', args, pipeStdIo)
41+
.on('close', (code) => {
42+
// The above command will make some modifications,
43+
// Roll them back
44+
// Ideally, we would find a way to not have to do this
45+
execSync('git checkout -- modules/**/package-lock.json')
46+
execSync('git checkout -- modules/**/package.json')
47+
48+
// Kill the background verdaccio server
49+
verdaccio.kill()
50+
51+
// If this command had an error,
52+
// we need to forward this.
53+
// Otherwise the entire CI build may think that things succeeded.
54+
if (code !== 0) throw Error(`Exit code: ${code}`)
55+
})

util/npx_verdaccio

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,50 @@
1-
#!/bin/bash
1+
#!/usr/bin/env node
2+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3+
// SPDX-License-Identifier: Apache-2.0
24

3-
# I am assumeing that you used `local_verdaccio_publish`
4-
# But either way,
5-
# this is to facilitate running `npx`
6-
# and interacting with a local verdaccio server
7-
# So... I need a running server
8-
verdaccio -c verdaccio/config.yaml &
5+
// This is done in a node script for 2 reasons
6+
// 1. Potability: I will need to run this in windows
7+
// 2. Errors. If the main command fails, the script needs to clean up
8+
// but and exit with this error.
9+
// this _can_ be done from bash or shell,
10+
// but now the portability problems loom large.
911

10-
# run npx, and stuff an rc file that has _valid_ tokens
11-
# that match the local htpassword
12+
const { spawn } = require('child_process')
13+
const pipeStdIo = { stdio: [process.stdin, process.stdout, process.stderr] }
1214

13-
npm_config_registry=http://localhost:4873/ npx \
14-
--userconfig verdaccio/npmrc \
15-
--ignore-existing \
16-
"$@"
15+
// I am assuming that you used `local_verdaccio_publish`
16+
// But either way,
17+
// this is to facilitate running `npx`
18+
// and interacting with a local verdaccio server
19+
// So... I need a running server
20+
const verdaccio = spawn('npx', ['verdaccio', '-c', 'verdaccio/config.yaml'], pipeStdIo)
21+
.on('error', e => {
22+
throw e
23+
})
1724

18-
# Kill everying
19-
# Especialy the background verdaccio server
20-
kill $(jobs -pr)
25+
const args = [
26+
'--userconfig', 'verdaccio/npmrc',
27+
'--ignore-existing',
28+
// Yes, this is dangerous.
29+
// But I'm trying to replicate _just running npx_
30+
// So if you get here, you should have had access to run npx anyway.
31+
process.argv.slice(2)
32+
]
33+
34+
spawn('npx', args, {
35+
// This instance of npx needs to target the verdaccio server
36+
// so the env var that governs this needs to be updated.
37+
// it is _possible_ for this value to already be set.
38+
// if the command has been executed from an npm script for example
39+
env: { ...process.env, npm_config_registry: 'http://localhost:4873/'},
40+
...pipeStdIo
41+
})
42+
.on('close', (code) => {
43+
// Kill the background verdaccio server
44+
verdaccio.kill()
45+
46+
// If this command had an error,
47+
// we need to forward this.
48+
// Otherwise the entire CI build may think that things succeeded.
49+
if (code !== 0) throw Error(`Exit code: ${code}`)
50+
})

0 commit comments

Comments
 (0)