feat(cli): build the patch tools with a command instead of a script path - #186
Merged
Conversation
Building hdiffz and hpatchz meant running node_modules/@bravemobile/react-native-code-push/scripts/binary-patch/build-hdiffpatch.sh by hand - a path into the package's own layout - and overriding where it installs, because the script's default is the package root, which sits below the project where the CLI never looks. `npx code-push build-patch-tools` runs the shipped script itself and installs where `release` will look: `HDIFFPATCH_TOOLS_DIR` when it is set, and otherwise `.hdiffpatch-tools` in the working directory. `--tools-dir` overrides both and `--force` passes through.
… builds them The error named `scripts/binary-patch/build-hdiffpatch.sh`, a path relative to the package root that does not run from a project directory.
The prerequisites paragraph no longer has to explain that the script installs where the CLI does not look, or how to point HDIFFPATCH_TOOLS_DIR into node_modules.
A CI cache of the installed tools is keyed by a checksum of the build script, which is what the script pins the sources and build flags in. Computing it meant naming the script's path inside node_modules - the path the command exists to hide. `--print-hash` prints the SHA-256 of the shipped script and exits without building.
jest runs babel in CJS mode and cannot load the modules that use `import.meta`, so nothing exercised the compiled CLI before publish - the relative path `build-patch-tools` resolves its script by could break without a test noticing. Building the CLI and starting one command proves it resolves its own files, on every push.
…e shipped script runs Without the install the shipped script clones and compiles for minutes, and `spawnSync` holds the worker past any jest timeout. Also reads `HDIFFPATCH_TOOLS_DIR` with `||`, as the CLI and `jest.globalSetup.ts` do.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
Building the binary patch generator meant reaching into the package's own layout: running
node_modules/@bravemobile/react-native-code-push/scripts/binary-patch/build-hdiffpatch.shby hand, and overriding where it installs, because the script's default is the package
root - which under
node_modulessits below the project, where the CLI never looks. TheREADME explained the mismatch and how to point
HDIFFPATCH_TOOLS_DIRaround it. A CI cacheof the built tools was keyed by a checksum of the same path. And the error a release raises
when the tools are missing named
scripts/binary-patch/build-hdiffpatch.sh, a path relativeto the package root that does not run from a project directory.
The path into
node_modulesis not part of the CLI's interface, and it is not evenreliable: in a workspace that hoists the package it does not exist at the project directory.
Changes
npx code-push build-patch-toolsRuns the shipped script itself and installs where
releasewill look:HDIFFPATCH_TOOLS_DIRwhen it is set, and otherwise
.hdiffpatch-toolsin the working directory - the first placethe lookup checks.
--tools-diroverrides both,--forcepasses through. The script'soutput streams to the terminal, since a first build clones and compiles for about a minute.
--print-hashprints the SHA-256 of the shipped script and exits without building. Thescript pins the sources and the build flags, so the hash changes only with a version of this
package that changes them - what a CI cache of the install directory needs as a key, without
the path.
The command does not check the version of an already installed pair, which is the script's
existing behavior; the README says to
--forceafter an upgrade that pins a differentHDiffPatch.
The missing-tools error
Names the command instead of the script path.
CI
unit-test.ymlnow builds the CLI and starts one command (build-patch-tools --print-hash)on every push. jest runs babel in CJS mode and cannot load the modules that use
import.meta, so this is the one check that the compiled CLI resolves its own files.Docs
The prerequisites paragraph under
releaseis down to the one command, andbuild-patch-toolshas a section of its own, in both languages. The heading anchorsdocs/diff-updates.mdlinks to are unchanged.What existing CLI users see
release --binary-bundle-pathscripts/binary-patch/build-hdiffpatch.shbuild-patch-toolscommand.For a project that today runs the script by its
node_modulespath withHDIFFPATCH_TOOLS_DIRset to<project>/.hdiffpatch-tools:and for a CI cache keyed by the script's checksum:
Verification
that records what it was handed, so the install directory and
--forceare proven withoutcloning; the shipped script is run once against an install it already finds complete.
tsc --noEmitpasses.import.meta.url, which the jest setup (babel, CJS)cannot evaluate, so it has no unit test. It was verified by running the compiled CLI:
--help, the default directory from the repository root, and--tools-dirfrom anotherworking directory.
installed
hdiffz(1.0 MB) andhpatchz(240 KB), exit 0.--print-hashoutput equalsshasum -a 256 scripts/binary-patch/build-hdiffpatch.sh,one line on stdout.
npm run build:cli && node bin/code-push.js build-patch-tools --print-hash > /dev/nullexits 0.