Skip to content

Commit

Permalink
Updates from upstream.
Browse files Browse the repository at this point in the history
  • Loading branch information
danfuzz committed Sep 28, 2023
1 parent c30a375 commit d382c90
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
40 changes: 18 additions & 22 deletions scripts/lib/bashy-node/node-project/build-main-module
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -63,8 +63,8 @@ process-args "$@" || usage --short
# Helper functions
#

# The main actions of this script. The "main module" is taken to be `main-<name>`.
function build-js-project {
# The main actions of this script.
function build-project {
local projectName="$1"
local modulesDir="$2"
local destDir="$3"
Expand Down Expand Up @@ -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 "$?"
Expand Down Expand Up @@ -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...'

Expand All @@ -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 "$?"
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions scripts/lib/bashy-node/node-project/find-module-dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ 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.
If a dependency cycle is detected, this prints a diagnostic message and
exits with an error.
--modules-dir=<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/<name>` where
<name> names the directory the module is in.
Expand Down Expand Up @@ -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
Expand All @@ -86,6 +89,7 @@ while true; do

state="$(
jget --file="${pkgFile}" \
moduleDir="${moduleDir}" \
oneDep="${oneDep}" \
state:json="${state}" '
((.dependencies // {}) | to_entries) as $allDeps
Expand All @@ -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) }
Expand Down Expand Up @@ -168,6 +173,7 @@ fi
jget "${state}" '{
main,
localDeps,
localDirs,
extDeps:
(.extDeps | map(split("@") | { key: .[0], value: .[1] }) | from_entries)
}'

0 comments on commit d382c90

Please sign in to comment.