mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-06 11:10:10 +00:00
Merge pull request #1982 from balena-io/allow-shrinkwrap-rebase
Allow rebasing of npm-shrinkwrap
This commit is contained in:
commit
54cceb688f
3
.gitattributes
vendored
3
.gitattributes
vendored
@ -10,6 +10,3 @@ doc/cli.markdown text eol=lf
|
|||||||
# crlf for the eol conversion test files
|
# crlf for the eol conversion test files
|
||||||
tests/test-data/projects/docker-compose/basic/service2/file2-crlf.sh eol=crlf
|
tests/test-data/projects/docker-compose/basic/service2/file2-crlf.sh eol=crlf
|
||||||
tests/test-data/projects/no-docker-compose/basic/src/windows-crlf.sh eol=crlf
|
tests/test-data/projects/no-docker-compose/basic/src/windows-crlf.sh eol=crlf
|
||||||
|
|
||||||
# Prevent auto merging of the npm-shrinkwrap.json file: see notes in CONTRIBUTING.md
|
|
||||||
/npm-shrinkwrap.json merge=binary
|
|
||||||
|
@ -98,27 +98,18 @@ Meanwhile, as a text (JSON) file, `git` is capable of merging the `npm-shrinkwra
|
|||||||
operations like `rebase`, `cherry-pick` and `pull`. But git's automated merge is not the
|
operations like `rebase`, `cherry-pick` and `pull`. But git's automated merge is not the
|
||||||
recommended way of updating the `npm-shrinkwrap.json` file, because it does not take into account
|
recommended way of updating the `npm-shrinkwrap.json` file, because it does not take into account
|
||||||
duplicates or conflicts in the dependency tree, or indeed the state of the `package.json` file
|
duplicates or conflicts in the dependency tree, or indeed the state of the `package.json` file
|
||||||
(which may have just been merged). In extreme cases, the automated merge may actually result in a
|
(which may have just been merged). You can improve this by installing the npm merge driver with:
|
||||||
broken installation. For these reasons, automatic merging of the `npm-shrinkwrap.json` was disabled
|
```
|
||||||
through the `.gitattributes` file (the "binary merge driver" allows diff'ing but prevents automatic
|
npx npm-merge-driver install -g
|
||||||
merging). Operations like `git rebase` may then result in an error like:
|
|
||||||
|
|
||||||
```text
|
|
||||||
$ git rebase master
|
|
||||||
warning: Cannot merge binary files: npm-shrinkwrap.json (HEAD vs. c34942b9... test)
|
|
||||||
Auto-merging npm-shrinkwrap.json
|
|
||||||
CONFLICT (content): Merge conflict in npm-shrinkwrap.json
|
|
||||||
error: Failed to merge in the changes.
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Whether or not there is a merge error, the following commands are the recommended way of updating
|
Whether or not there is a merge error, the following commands are the recommended way of updating
|
||||||
and committing the `npm-shrinkwrap.json` file:
|
and committing the `npm-shrinkwrap.json` file:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ rm -rf node_modules # Linux / Mac
|
$ npm install # fetch the latest modules update the npm-shrinkwrap.json file
|
||||||
$ rmdir /s node_modules # Windows Command Prompt
|
$ npm dedupe # deduplicate dependencies from the npm-shrinkwrap.json file
|
||||||
$ npm checkout master -- npm-shrinkwrap.json # revert it to the master branch state
|
$ npm install # re-add optional dependencies for other platforms that may have been removed by dedupe
|
||||||
$ npm install # "cleanly" update the npm-shrinkwrap.json file
|
|
||||||
$ git add npm-shrinkwrap.json # add it for committing (solve merge errors)
|
$ git add npm-shrinkwrap.json # add it for committing (solve merge errors)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -409,3 +409,12 @@ export async function catchUncommitted(): Promise<void> {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function testShrinkwrap(): Promise<void> {
|
||||||
|
if (process.env.DEBUG) {
|
||||||
|
console.error(`[debug] platform=${process.platform}`);
|
||||||
|
}
|
||||||
|
if (process.platform !== 'win32') {
|
||||||
|
await whichSpawn(path.resolve(__dirname, 'test-lock-deduplicated.sh'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -21,6 +21,7 @@ import {
|
|||||||
buildOclifInstaller,
|
buildOclifInstaller,
|
||||||
buildStandaloneZip,
|
buildStandaloneZip,
|
||||||
catchUncommitted,
|
catchUncommitted,
|
||||||
|
testShrinkwrap,
|
||||||
} from './build-bin';
|
} from './build-bin';
|
||||||
import {
|
import {
|
||||||
release,
|
release,
|
||||||
@ -63,6 +64,7 @@ export async function run(args?: string[]) {
|
|||||||
'build:installer': buildOclifInstaller,
|
'build:installer': buildOclifInstaller,
|
||||||
'build:standalone': buildStandaloneZip,
|
'build:standalone': buildStandaloneZip,
|
||||||
'catch-uncommitted': catchUncommitted,
|
'catch-uncommitted': catchUncommitted,
|
||||||
|
'test-shrinkwrap': testShrinkwrap,
|
||||||
fix1359: updateDescriptionOfReleasesAffectedByIssue1359,
|
fix1359: updateDescriptionOfReleasesAffectedByIssue1359,
|
||||||
release,
|
release,
|
||||||
};
|
};
|
||||||
|
17
automation/test-lock-deduplicated.sh
Executable file
17
automation/test-lock-deduplicated.sh
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
cp npm-shrinkwrap.json npm-shrinkwrap.json.old
|
||||||
|
npm i
|
||||||
|
npm dedupe
|
||||||
|
npm i
|
||||||
|
|
||||||
|
if ! diff -q npm-shrinkwrap.json npm-shrinkwrap.json.old > /dev/null; then
|
||||||
|
rm npm-shrinkwrap.json.old
|
||||||
|
echo "** npm-shrinkwrap.json was not deduplicated or not fully committed - FAIL **";
|
||||||
|
echo "** Please run 'npm ci', followed by 'npm dedupe' **";
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm npm-shrinkwrap.json.old
|
@ -206,7 +206,7 @@ export async function which(program: string): Promise<string> {
|
|||||||
*/
|
*/
|
||||||
export async function whichSpawn(
|
export async function whichSpawn(
|
||||||
programName: string,
|
programName: string,
|
||||||
args: string[],
|
args?: string[],
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const program = await which(programName);
|
const program = await which(programName);
|
||||||
let error: Error | undefined;
|
let error: Error | undefined;
|
||||||
|
@ -58,7 +58,8 @@
|
|||||||
"package": "npm run build:fast && npm run build:standalone && npm run build:installer",
|
"package": "npm run build:fast && npm run build:standalone && npm run build:installer",
|
||||||
"release": "ts-node --transpile-only automation/run.ts release",
|
"release": "ts-node --transpile-only automation/run.ts release",
|
||||||
"pretest": "npm run build",
|
"pretest": "npm run build",
|
||||||
"test": "npm run test:source && npm run test:standalone",
|
"test": "npm run test:shrinkwrap && npm run test:source && npm run test:standalone",
|
||||||
|
"test:shrinkwrap": "ts-node --transpile-only automation/run.ts test-shrinkwrap",
|
||||||
"test:source": "cross-env BALENA_CLI_TEST_TYPE=source mocha",
|
"test:source": "cross-env BALENA_CLI_TEST_TYPE=source mocha",
|
||||||
"test:standalone": "npm run build:standalone && npm run test:standalone:fast",
|
"test:standalone": "npm run build:standalone && npm run test:standalone:fast",
|
||||||
"test:standalone:fast": "cross-env BALENA_CLI_TEST_TYPE=standalone mocha",
|
"test:standalone:fast": "cross-env BALENA_CLI_TEST_TYPE=standalone mocha",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user