Skip to content

Commit 716160a

Browse files
authored
Merge pull request #5 from neilcampbell/npmrc-path
Adding support for specifying an output path for the npmrc file
2 parents f17306b + 5647fff commit 716160a

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

README.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ To read the value from an environment variable named `MY_TOKEN` when the plugin
1717
steps:
1818
- command: yarn install
1919
plugins:
20-
- seek-oss/private-npm#v1.1.2:
20+
- seek-oss/private-npm#v1.2.0:
2121
env: "MY_TOKEN"
2222
```
2323
@@ -27,7 +27,7 @@ To read the value from a file named `my_token_file`, use the `file` field.
2727
steps:
2828
- command: yarn install
2929
plugins:
30-
- seek-oss/private-npm#v1.1.2:
30+
- seek-oss/private-npm#v1.2.0:
3131
file: "my_token_file"
3232
```
3333

@@ -39,7 +39,7 @@ approach is discoraged in favour of using with the `env` or `file` fields. This
3939
steps:
4040
- command: yarn install
4141
plugins:
42-
- seek-oss/private-npm#v1.1.2:
42+
- seek-oss/private-npm#v1.2.0:
4343
token: ${MY_TOKEN}
4444
```
4545

@@ -50,7 +50,7 @@ You can also specify a custom npm registry if you are using your own mirror.
5050
steps:
5151
- command: yarn install
5252
plugins:
53-
- seek-oss/private-npm#v1.1.2:
53+
- seek-oss/private-npm#v1.2.0:
5454
env: "MY_TOKEN"
5555
registry: //myprivatenpm.com/
5656
```
@@ -94,5 +94,10 @@ The path to a private npm repository. Please ensure you supply the trailing `/`
9494

9595
Example: `//myprivatenpm.com/`
9696

97+
### `output-path` (optional)
98+
The path to the .npmrc that will be created. Please ensure you supply the trailing `/`!
99+
100+
Example: `./project/path/`
101+
97102
## License
98103
MIT (see [LICENSE](./LICENSE))

hooks/pre-command

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ SEEK_OSS_PRIVATE_NPM_REGISTRY=${BUILDKITE_PLUGIN_PRIVATE_NPM_REGISTRY:-'//regist
66
SEEK_OSS_PRIVATE_NPM_TOKEN=${BUILDKITE_PLUGIN_PRIVATE_NPM_TOKEN:-''}
77
SEEK_OSS_PRIVATE_NPM_FILE=${BUILDKITE_PLUGIN_PRIVATE_NPM_FILE:-''}
88
SEEK_OSS_PRIVATE_NPM_ENV=${BUILDKITE_PLUGIN_PRIVATE_NPM_ENV:-''}
9+
SEEK_OSS_PRIVATE_NPM_OUTPUT_PATH=${BUILDKITE_PLUGIN_PRIVATE_NPM_OUTPUT_PATH:-'./'}
910

1011
if { [[ -n "${SEEK_OSS_PRIVATE_NPM_FILE}" ]] && [[ -n "${SEEK_OSS_PRIVATE_NPM_ENV}" ]]; } \
1112
|| { [[ -n "${SEEK_OSS_PRIVATE_NPM_FILE}" ]] && [[ -n "${SEEK_OSS_PRIVATE_NPM_TOKEN}" ]]; } \
@@ -31,7 +32,9 @@ fi
3132

3233
echo '--- Setting up access for :no_entry_sign: :npm: :package:'
3334

34-
cat > .npmrc << EOF
35+
OUTPUT_FILE="${SEEK_OSS_PRIVATE_NPM_OUTPUT_PATH}.npmrc"
36+
37+
mkdir -p "${OUTPUT_FILE%/*}" && cat > $OUTPUT_FILE << EOF
3538
${SEEK_OSS_PRIVATE_NPM_REGISTRY}:_authToken=${SEEK_OSS_PRIVATE_NPM_TOKEN}
3639
save-exact=true
3740
EOF

plugin.yml

+2
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ configuration:
1414
type: string
1515
file:
1616
type: string
17+
output-path:
18+
type: string
1719

tests/pre-command.bats

+12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
load "$BATS_PATH/load.bash"
44
teardown() {
55
rm -f .npmrc
6+
rm -f ./tests/path/to/project/.npmrc
67
unset BUILDKITE_PLUGIN_PRIVATE_NPM_ENV
78
unset BUILDKITE_PLUGIN_PRIVATE_NPM_TOKEN
89
unset BUILDKITE_PLUGIN_PRIVATE_NPM_FILE
@@ -116,6 +117,17 @@ teardown() {
116117
assert_equal "$(head -n1 .npmrc)" '//myprivateregistry.org/:_authToken=abc123'
117118
}
118119

120+
@test "creates a npmrc file with supplied output path and token" {
121+
export BUILDKITE_PLUGIN_PRIVATE_NPM_TOKEN='abc123'
122+
export BUILDKITE_PLUGIN_PRIVATE_NPM_OUTPUT_PATH='./tests/path/to/project/'
123+
124+
run $PWD/hooks/pre-command
125+
126+
assert_success
127+
assert [ -e './tests/path/to/project/.npmrc' ]
128+
assert_equal "$(head -n1 ./tests/path/to/project/.npmrc)" '//registry.npmjs.org/:_authToken=abc123'
129+
}
130+
119131
@test "the command fails if none of the fields are not set" {
120132
run $PWD/hooks/pre-command
121133

0 commit comments

Comments
 (0)