File tree Expand file tree Collapse file tree 5 files changed +64
-6
lines changed
integration-tests/lockfile Expand file tree Collapse file tree 5 files changed +64
-6
lines changed Original file line number Diff line number Diff line change
1
+ # make sure errors stop the script
2
+ set -e
3
+
4
+ echo " add patch-package"
5
+ npm i $1
6
+ alias patch-package=./node_modules/.bin/patch-package
7
+
8
+ echo " Add left-pad"
9
+
10
+
11
+ testLockFile () {
12
+ echo " Version test $1 "
13
+ npm i --lockfile-version $1
14
+
15
+ echo " cleanup patches"
16
+ npx rimraf patches
17
+
18
+ echo " replace pad with yarn in left-pad/index.js"
19
+ npx replace pad npm node_modules/left-pad/index.js
20
+
21
+ echo " patch-package should run"
22
+ patch-package left-pad
23
+
24
+ echo " check that the patch is created"
25
+ test -f patches/left-pad+1.3.0.patch || exit 1
26
+ }
27
+
28
+ echo " test lockfile v2"
29
+ testLockFile 2
30
+
31
+ echo " test lockfile v3"
32
+ testLockFile 3
Original file line number Diff line number Diff line change
1
+ import { runIntegrationTest } from "../runIntegrationTest"
2
+ runIntegrationTest ( { projectName : "lockfile" , shouldProduceSnapshots : false } )
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " lockfile" ,
3
+ "version" : " 1.0.0" ,
4
+ "description" : " integration test for patch-package" ,
5
+ "main" : " index.js" ,
6
+ "author" : " anas10" ,
7
+ "license" : " ISC" ,
8
+ "dependencies" : {
9
+ "left-pad" : " 1.3.0"
10
+ }
11
+ }
Original file line number Diff line number Diff line change
1
+ # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2
+ # yarn lockfile v1
3
+
4
+
5
+ " left-pad@^1.1.3 " :
6
+ " integrity" " sha512-XI5MPzVNApjAyhQzphX8BkmKsKUxD4LdyK24iZeQGinBN9yTQT3bFlCBy/aVx2HrNcqQGsdot8ghrjyrvMCoEA=="
7
+ " resolved" " https://registry.npmjs.org/left-pad/-/left-pad-1.3.0.tgz"
8
+ " version" " 1.3.0"
Original file line number Diff line number Diff line change @@ -106,11 +106,17 @@ export function getPackageResolution({
106
106
}
107
107
}
108
108
lockFileStack . reverse ( )
109
- const relevantStackEntry = lockFileStack . find (
110
- ( entry ) =>
111
- entry . dependencies && packageDetails . name in entry . dependencies ,
112
- )
113
- const pkg = relevantStackEntry . dependencies [ packageDetails . name ]
109
+ const relevantStackEntry = lockFileStack . find ( ( entry ) => {
110
+ if ( entry . dependencies ) {
111
+ return entry . dependencies && packageDetails . name in entry . dependencies
112
+ } else if ( entry . packages ) {
113
+ return entry . packages && packageDetails . path in entry . packages
114
+ }
115
+ throw new Error ( "Cannot find dependencies or packages in lockfile" )
116
+ } )
117
+ const pkg = relevantStackEntry . dependencies
118
+ ? relevantStackEntry . dependencies [ packageDetails . name ]
119
+ : relevantStackEntry . packages [ packageDetails . path ]
114
120
return pkg . resolved || pkg . version || pkg . from
115
121
}
116
122
}
@@ -120,7 +126,6 @@ if (require.main === module) {
120
126
if ( ! packageDetails ) {
121
127
console . error ( `Can't find package ${ process . argv [ 2 ] } ` )
122
128
process . exit ( 1 )
123
- throw new Error ( )
124
129
}
125
130
console . log (
126
131
getPackageResolution ( {
You can’t perform that action at this time.
0 commit comments