From 39527b761d7cb5e480c9c38841f887d6d69a1cfa Mon Sep 17 00:00:00 2001 From: Andrea Luzzardi Date: Sat, 29 May 2021 01:21:52 -0700 Subject: [PATCH] stdlib: yarn: support cwd, args and packages Signed-off-by: Andrea Luzzardi --- stdlib/js/yarn/yarn.cue | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/stdlib/js/yarn/yarn.cue b/stdlib/js/yarn/yarn.cue index 81b9bbed..cefb2f29 100644 --- a/stdlib/js/yarn/yarn.cue +++ b/stdlib/js/yarn/yarn.cue @@ -15,6 +15,14 @@ import ( // Application source code source: dagger.#Artifact @dagger(input) + // Extra alpine packages to install + package: { + [string]: true | false | string @dagger(input) + } + + // working directory to use + cwd: *"." | string @dagger(input) + // Environment variables env: { [string]: string @dagger(input) @@ -31,6 +39,9 @@ import ( // Run this yarn script script: string | *"build" @dagger(input) + // Optional arguments for the script + args: [...string] | *[] @dagger(input) + build: os.#Dir & { from: ctr path: "/build" @@ -38,7 +49,7 @@ import ( ctr: os.#Container & { image: alpine.#Image & { - package: { + "package": package & { bash: "=~5.1" yarn: "=~1.22" } @@ -46,13 +57,17 @@ import ( shell: path: "/bin/bash" command: """ [ -n "$ENVFILE_NAME" ] && echo "$ENVFILE" > "$ENVFILE_NAME" - yarn install --production false - yarn run "$YARN_BUILD_SCRIPT" + yarn --cwd "$YARN_CWD" install --production false + + opts=( $(echo $YARN_ARGS) ) + yarn --cwd "$YARN_CWD" run "$YARN_BUILD_SCRIPT" ${opts[@]} mv "$YARN_BUILD_DIRECTORY" /build """ "env": env & { YARN_BUILD_SCRIPT: script + YARN_ARGS: strings.Join(args, "\n") YARN_CACHE_FOLDER: "/cache/yarn" + YARN_CWD: cwd YARN_BUILD_DIRECTORY: buildDir if writeEnvFile != "" { ENVFILE_NAME: writeEnvFile