Skip to content

Commit b046cb7

Browse files
authored
Add support for installing dependencies through yarn (#55)
Function dependencies are now installed using yarn when yarn.lock is present in the application source code.
1 parent 35c213e commit b046cb7

5 files changed

Lines changed: 21 additions & 3 deletions

File tree

converter/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM gcr.io/gcp-runtimes/ubuntu_18_0_4
22

3-
COPY convert .npmrc /converter/
3+
COPY convert install-function-dependencies .npmrc /converter/
44

55
COPY without-package /converter/without-package
66
COPY with-package-without-framework /converter/with-package-without-framework

converter/convert

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ if [[ ! -f functions/package.json ]]; then
1818
echo 'Handling functions without package.json'
1919
cp /converter/without-package/package.json .
2020
cp /converter/without-package/package-lock.json .
21+
cp /converter/install-function-dependencies .
2122
ln -s node_modules/.bin/functions-framework start-functions-framework
2223
elif ! cat functions/package.json | jq -e ".dependencies.\"@google-cloud/functions-framework\""; then
2324
echo 'Handling functions with package.json without dependency on @google-cloud/functions-framework'
2425
cp /converter/with-package-without-framework/package.json .
2526
cp /converter/with-package-without-framework/package-lock.json .
27+
cp /converter/install-function-dependencies .
2628
ln -s node_modules/.bin/functions-framework start-functions-framework
2729
else
2830
echo 'Handling functions with package.json with dependency on functions-framework'
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
# Installs dependencies specified by the function.
4+
5+
set -euo pipefail
6+
7+
echo 'Installing function dependencies'
8+
9+
if [[ -f functions/yarn.lock ]]; then
10+
echo 'Found yarn.lock; using yarn'
11+
yarn install --cwd functions
12+
else
13+
npm install --prefix functions
14+
fi
15+
16+
echo 'Installing function dependencies done'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"scripts": {
3-
"preinstall": "npm --prefix functions install",
3+
"preinstall": "./install-function-dependencies",
44
"start": "cd functions && node_modules/.bin/functions-framework"
55
}
66
}

converter/with-package-without-framework/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"@google-cloud/functions-framework": "^1.0.0"
44
},
55
"scripts": {
6-
"preinstall": "npm --prefix functions install",
6+
"preinstall": "./install-function-dependencies",
77
"start": "cd functions && functions-framework"
88
}
99
}

0 commit comments

Comments
 (0)