forked from vercel/pkg-fetch
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add applyPatches script and some basic patch documentation (vercel#251)
* build: add applyPatches script and docs Adds a new package.json script to only apply patches as well as some basic documentation on applying patches and building binaries * README: add example of patch updates to readme * tests: add simple patch application checker * CI: always run lint in ci job matrix * patches: fix 10.24.1 patch to apply with no offset
- Loading branch information
Showing
8 changed files
with
214 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env node | ||
|
||
import yargs from 'yargs'; | ||
|
||
import { log } from './log'; | ||
import { getNodeVersion } from './index'; | ||
import { version } from '../package.json'; | ||
import { fetchExtractApply, prepBuildPath } from './build'; | ||
|
||
async function applyPatchesOnVersion(nodeRange: string, quietExtraction = false) { | ||
await prepBuildPath(); | ||
await fetchExtractApply(getNodeVersion(nodeRange), quietExtraction); | ||
} | ||
|
||
async function main() { | ||
const { argv } = yargs | ||
.option('node-range', { alias: 'n', default: 'latest', type: 'string' }) | ||
.option('quiet-extraction', { alias: 'q', type: 'boolean' }) | ||
.version(version) | ||
.alias('v', 'version') | ||
.help() | ||
.alias('h', 'help'); | ||
|
||
const { | ||
'node-range': nodeRange, | ||
'quiet-extraction': quietExtraction, | ||
} = argv; | ||
|
||
await applyPatchesOnVersion(nodeRange, quietExtraction); | ||
} | ||
|
||
main().catch((error) => { | ||
if (!error.wasReported) log.error(error); | ||
process.exit(2); | ||
}); |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
node_range=$1 | ||
|
||
if [ -z "$node_range" ]; then | ||
echo "usage: ./test_patch.sh <nodeVersion>" | ||
echo " where nodeVersion is of the form 'node18' or 'node16'" | ||
exit 1 | ||
fi | ||
|
||
echo "Applying patches for $node_range" | ||
|
||
command="npm run applyPatches -- --node-range $node_range --quiet-extraction" | ||
output=$($command) | ||
status=$? | ||
|
||
if [ $status -ne 0 ]; then | ||
echo -e "Command failed:\n$command\n$output" | ||
exit 1 | ||
fi | ||
|
||
echo "Checking output" | ||
|
||
expected_include_strings=("fetching" "extracting" "applying patches" "patching file") | ||
failing_strings=("failed" "offset" "rejects") | ||
|
||
found_all_expected_strings=true | ||
for s in "${expected_include_strings[@]}"; do | ||
if [[ "${output,,}" != *"${s,,}"* ]]; then | ||
found_all_expected_strings=false | ||
echo -e "ERROR: Did not find \"$s\" in output" | ||
fi | ||
done | ||
|
||
if [ "$found_all_expected_strings" = false ]; then | ||
echo -e "\nDid not find the expected text when applying patches.\n\nOutput:\n$output" | ||
exit 1 | ||
fi | ||
|
||
line_errors=0 | ||
while IFS= read -r line; do | ||
for fString in "${failing_strings[@]}"; do | ||
if [[ "${line,,}" == *"${fString,,}"* ]]; then | ||
echo "ERROR: Found \"$fString\" in line: \"$line\""; | ||
line_errors=$((line_errors + 1)) | ||
fi | ||
done | ||
done <<< "$output" | ||
|
||
if [ $line_errors -gt 0 ]; then | ||
echo "ERROR: errors found while attempting to apply patches" | ||
exit $line_errors | ||
fi | ||
|
||
echo "All checks complete" |