From d382c90966521de61ea2667d85fa82389a63dad2 Mon Sep 17 00:00:00 2001 From: Dan Bornstein Date: Thu, 28 Sep 2023 15:01:14 -0700 Subject: [PATCH] Updates from upstream. --- .../bashy-node/node-project/build-main-module | 40 +++++++++---------- .../node-project/find-module-dependencies | 10 ++++- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/scripts/lib/bashy-node/node-project/build-main-module b/scripts/lib/bashy-node/node-project/build-main-module index 209b9f505..e8d0b15b8 100755 --- a/scripts/lib/bashy-node/node-project/build-main-module +++ b/scripts/lib/bashy-node/node-project/build-main-module @@ -44,7 +44,7 @@ opt-action --call='{ usage; exit }' help/h # Allow the build to be platform-specific? opt-toggle --var=platformSpecific allow-platform-specific-files -# Directory containing all the modules +# Directory containing all the modules. opt-value --required --var=modulesDir --filter='/./' modules-dir # Built output directory. @@ -63,8 +63,8 @@ process-args "$@" || usage --short # Helper functions # -# The main actions of this script. The "main module" is taken to be `main-`. -function build-js-project { +# The main actions of this script. +function build-project { local projectName="$1" local modulesDir="$2" local destDir="$3" @@ -130,7 +130,7 @@ function build-js-project { true \ && make-index-js "${destLocalCode}" \ && copy-scripts "${srcMainModule}" "${destDir}" \ - && copy-local-modules "${modulesDir}" "${destLocalModules}" "${deps}" \ + && copy-local-modules "${destLocalModules}" "${deps}" \ && remove-dead-local-modules "${destLocalModules}" "${deps}" \ && npm-install "${destLibDir}" \ || return "$?" @@ -159,9 +159,8 @@ function commit-info { # Copies all the local modules for a project. function copy-local-modules { - local moduleSrcDir="$1" - local moduleDestDir="$2" - local deps="$3" + local moduleDestDir="$1" + local deps="$2" progress-msg 'Copying local modules...' @@ -172,24 +171,21 @@ function copy-local-modules { copyCmd="$( jget --output=raw "${deps}" \ cmd='lib rsync-local' \ - fromDir="${moduleSrcDir}" \ toDir="${moduleDestDir}" ' - .localDeps - | - map({ - fromPath: ($fromDir + "/" + (. | sub("^[^/]*/"; "") + "/") | @sh), - toPath: ($toDir + "/" + . | @sh) - } - | + .localDirs + | to_entries + | map({ name: .key, fromPath: .value }) + | map({ + fromPath: ("\(.fromPath)/" | @sh), + toPath: ("\($toDir)/\(.name)" | @sh) + }) + | map( "mkdir -p " + .toPath, $cmd + " " + .fromPath + " " + .toPath - | - "&& " + . + " \\" ) - | - ["true \\"] + . + ["&& true"] - | - join("\n") + | map("&& " + . + " \\") + | ["true \\"] + . + ["&& true"] + | join("\n") ' )" \ || return "$?" @@ -389,7 +385,7 @@ if [[ ! -d ${outProjectDir} ]]; then || exit "$?" fi -build-js-project "${projectName}" "${modulesDir}" "${outProjectDir}" \ +build-project "${projectName}" "${modulesDir}" "${outProjectDir}" \ || exit "$?" if (( !platformSpecific )); then diff --git a/scripts/lib/bashy-node/node-project/find-module-dependencies b/scripts/lib/bashy-node/node-project/find-module-dependencies index a5961c765..7270faae6 100755 --- a/scripts/lib/bashy-node/node-project/find-module-dependencies +++ b/scripts/lib/bashy-node/node-project/find-module-dependencies @@ -19,6 +19,8 @@ define-usage $' * `main: string` -- The originally requested module. * `localDeps: [name, ...]` -- Local module dependencies. + * `localDirs: { name: path, ... }` -- Mapping from each local module name to + the source directory it lives in. * `extDeps: { name: version, ... }` -- External (e.g. npm) module dependencies. @@ -26,7 +28,7 @@ define-usage $' exits with an error. --modules-dir= - Directory containing all source modules. Required. *Note:* Each of the + Directory containing all source modules. Required. **Note:** Each of the modules is expected to be defined to have the name `@this/` where names the directory the module is in. @@ -77,7 +79,8 @@ while true; do # Reminder: `${var##*/}` removes everything up to the last slash. In this # case, it's trimming `@this/` off of `oneDep`. - pkgFile="${modulesDir}/${oneDep##*/}/package.json" + moduleDir="${modulesDir}/${oneDep##*/}" + pkgFile="${moduleDir}/package.json" if [[ ! -r "${pkgFile}" ]]; then echo "Not readable: ${pkgFile}" 1>&2 @@ -86,6 +89,7 @@ while true; do state="$( jget --file="${pkgFile}" \ + moduleDir="${moduleDir}" \ oneDep="${oneDep}" \ state:json="${state}" ' ((.dependencies // {}) | to_entries) as $allDeps @@ -98,6 +102,7 @@ while true; do graph: ($state.graph + ($localDeps | map({ from: $oneDep, to: .}))), unprocessed: (($state.unprocessed + $localDeps) | unique), localDeps: (($state.localDeps + [$oneDep]) | unique), + localDirs: (($state.localDirs + { ($oneDep): $moduleDir })), extDeps: (($state.extDeps + $extDeps) | unique) } | . + { unprocessed: (.unprocessed - .localDeps) } @@ -168,6 +173,7 @@ fi jget "${state}" '{ main, localDeps, + localDirs, extDeps: (.extDeps | map(split("@") | { key: .[0], value: .[1] }) | from_entries) }'