Skip to content

Commit 49eddbd

Browse files
committed
Patch graceful-fs
1 parent 41c9814 commit 49eddbd

5 files changed

Lines changed: 154 additions & 1 deletion

File tree

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
diff --git a/graceful-fs.js b/graceful-fs.js
2+
index 8d5b89e4fa7fdbaebf58556cc044d2a912bce5de..7c34dcf6400831d186c8d6eb5726224bf6f3b1a0 100644
3+
--- a/graceful-fs.js
4+
+++ b/graceful-fs.js
5+
@@ -5,28 +5,10 @@ var clone = require('./clone.js')
6+
7+
var util = require('util')
8+
9+
-/* istanbul ignore next - node 0.x polyfill */
10+
-var gracefulQueue
11+
-var previousSymbol
12+
-
13+
-/* istanbul ignore else - node 0.x polyfill */
14+
-if (typeof Symbol === 'function' && typeof Symbol.for === 'function') {
15+
- gracefulQueue = Symbol.for('graceful-fs.queue')
16+
- // This is used in testing by future versions
17+
- previousSymbol = Symbol.for('graceful-fs.previous')
18+
-} else {
19+
- gracefulQueue = '___graceful-fs.queue'
20+
- previousSymbol = '___graceful-fs.previous'
21+
-}
22+
-
23+
function noop () {}
24+
25+
function publishQueue(context, queue) {
26+
- Object.defineProperty(context, gracefulQueue, {
27+
- get: function() {
28+
- return queue
29+
- }
30+
- })
31+
+ context['___graceful-fs_queue'] = queue
32+
}
33+
34+
var debug = noop
35+
@@ -40,9 +22,9 @@ else if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || ''))
36+
}
37+
38+
// Once time initialization
39+
-if (!fs[gracefulQueue]) {
40+
+if (!fs['___graceful-fs_queue']) {
41+
// This queue can be shared by multiple loaded instances
42+
- var queue = global[gracefulQueue] || []
43+
+ var queue = global['___graceful-fs_queue'] || []
44+
publishQueue(fs, queue)
45+
46+
// Patch fs.close/closeSync to shared queue version, because we need
47+
@@ -62,7 +44,7 @@ if (!fs[gracefulQueue]) {
48+
})
49+
}
50+
51+
- Object.defineProperty(close, previousSymbol, {
52+
+ Object.defineProperty(close, '___graceful-fs_previous', {
53+
value: fs$close
54+
})
55+
return close
56+
@@ -75,7 +57,7 @@ if (!fs[gracefulQueue]) {
57+
resetQueue()
58+
}
59+
60+
- Object.defineProperty(closeSync, previousSymbol, {
61+
+ Object.defineProperty(closeSync, '___graceful-fs_previous', {
62+
value: fs$closeSync
63+
})
64+
return closeSync
65+
@@ -83,14 +65,14 @@ if (!fs[gracefulQueue]) {
66+
67+
if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || '')) {
68+
process.on('exit', function() {
69+
- debug(fs[gracefulQueue])
70+
- require('assert').equal(fs[gracefulQueue].length, 0)
71+
+ debug(fs['___graceful-fs_queue'])
72+
+ require('assert').equal(fs['___graceful-fs_queue'].length, 0)
73+
})
74+
}
75+
}
76+
77+
-if (!global[gracefulQueue]) {
78+
- publishQueue(global, fs[gracefulQueue]);
79+
+if (!global['___graceful-fs_queue']) {
80+
+ publishQueue(global, fs['___graceful-fs_queue']);
81+
}
82+
83+
module.exports = patch(clone(fs))
84+
@@ -370,7 +352,7 @@ function patch (fs) {
85+
86+
function enqueue (elem) {
87+
debug('ENQUEUE', elem[0].name, elem[1])
88+
- fs[gracefulQueue].push(elem)
89+
+ fs['___graceful-fs_queue'].push(elem)
90+
retry()
91+
}
92+
93+
@@ -382,12 +364,12 @@ var retryTimer
94+
// delay between attempts so that we'll retry these jobs sooner
95+
function resetQueue () {
96+
var now = Date.now()
97+
- for (var i = 0; i < fs[gracefulQueue].length; ++i) {
98+
+ for (var i = 0; i < fs['___graceful-fs_queue'].length; ++i) {
99+
// entries that are only a length of 2 are from an older version, don't
100+
// bother modifying those since they'll be retried anyway.
101+
- if (fs[gracefulQueue][i].length > 2) {
102+
- fs[gracefulQueue][i][3] = now // startTime
103+
- fs[gracefulQueue][i][4] = now // lastTime
104+
+ if (fs['___graceful-fs_queue'][i].length > 2) {
105+
+ fs['___graceful-fs_queue'][i][3] = now // startTime
106+
+ fs['___graceful-fs_queue'][i][4] = now // lastTime
107+
}
108+
}
109+
// call retry to make sure we're actively processing the queue
110+
@@ -399,10 +381,10 @@ function retry () {
111+
clearTimeout(retryTimer)
112+
retryTimer = undefined
113+
114+
- if (fs[gracefulQueue].length === 0)
115+
+ if (fs['___graceful-fs_queue'].length === 0)
116+
return
117+
118+
- var elem = fs[gracefulQueue].shift()
119+
+ var elem = fs['___graceful-fs_queue'].shift()
120+
var fn = elem[0]
121+
var args = elem[1]
122+
// these items may be unset if they were added by an older graceful-fs
123+
@@ -437,7 +419,7 @@ function retry () {
124+
} else {
125+
// if we can't do this job yet, push it to the end of the queue
126+
// and let the next iteration check again
127+
- fs[gracefulQueue].push(elem)
128+
+ fs['___graceful-fs_queue'].push(elem)
129+
}
130+
}
131+

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@
6464
"@types/glob@*": "patch:@types/glob@npm%3A7.1.4#./.yarn/patches/@types-glob-npm-7.1.4-d45247eaa2.patch",
6565
"@types/glob@^7.1.1": "patch:@types/glob@npm%3A7.1.4#./.yarn/patches/@types-glob-npm-7.1.4-d45247eaa2.patch",
6666
"@types/mocha@^10.0.1": "patch:@types/mocha@npm:10.0.1#.yarn/patches/@types-mocha-npm-10.0.1-7c94e9e170.patch",
67+
"graceful-fs@npm:^4.1.2": "patch:graceful-fs@npm%3A4.2.11#~/.yarn/patches/graceful-fs-npm-4.2.11-24bb648a68.patch",
68+
"graceful-fs@npm:^4.1.6": "patch:graceful-fs@npm%3A4.2.11#~/.yarn/patches/graceful-fs-npm-4.2.11-24bb648a68.patch",
69+
"graceful-fs@npm:^4.2.0": "patch:graceful-fs@npm%3A4.2.11#~/.yarn/patches/graceful-fs-npm-4.2.11-24bb648a68.patch",
70+
"graceful-fs@npm:^4.2.11": "patch:graceful-fs@npm%3A4.2.11#~/.yarn/patches/graceful-fs-npm-4.2.11-24bb648a68.patch",
71+
"graceful-fs@npm:^4.2.4": "patch:graceful-fs@npm%3A4.2.11#~/.yarn/patches/graceful-fs-npm-4.2.11-24bb648a68.patch",
72+
"graceful-fs@npm:^4.2.6": "patch:graceful-fs@npm%3A4.2.11#~/.yarn/patches/graceful-fs-npm-4.2.11-24bb648a68.patch",
73+
"graceful-fs@npm:^4.2.9": "patch:graceful-fs@npm%3A4.2.11#~/.yarn/patches/graceful-fs-npm-4.2.11-24bb648a68.patch",
6774
"jest-fetch-mock@^3.0.3": "patch:jest-fetch-mock@npm:3.0.3#.yarn/patches/jest-fetch-mock-npm-3.0.3-ac072ca8af.patch",
6875
"jest-util@^29.5.0": "patch:jest-util@npm%3A29.6.3#./.yarn/patches/jest-util-npm-29.6.3-6ffdea2c1c.patch",
6976
"jest-util@^29.6.3": "patch:jest-util@npm%3A29.6.3#./.yarn/patches/jest-util-npm-29.6.3-6ffdea2c1c.patch",

packages/snaps-execution-environments/lavamoat/build-system/policy-override.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
}
1818
},
1919
"typescript": {},
20+
"webpack>graceful-fs": {
21+
"globals": {
22+
"___graceful-fs_previous": "write",
23+
"___graceful-fs_queue": "write"
24+
}
25+
},
2026
"webpack>loader-runner": {
2127
"packages": {
2228
"html-webpack-plugin": true,

packages/snaps-execution-environments/lavamoat/build-system/policy.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@
273273
"util": true
274274
},
275275
"globals": {
276+
"___graceful-fs_previous": "write",
277+
"___graceful-fs_queue": "write",
276278
"clearTimeout": true,
277279
"console.error": true,
278280
"process": true,

yarn.lock

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12243,13 +12243,20 @@ __metadata:
1224312243
languageName: node
1224412244
linkType: hard
1224512245

12246-
"graceful-fs@npm:^4.1.2, graceful-fs@npm:^4.1.6, graceful-fs@npm:^4.2.0, graceful-fs@npm:^4.2.11, graceful-fs@npm:^4.2.4, graceful-fs@npm:^4.2.6, graceful-fs@npm:^4.2.9":
12246+
"graceful-fs@npm:4.2.11":
1224712247
version: 4.2.11
1224812248
resolution: "graceful-fs@npm:4.2.11"
1224912249
checksum: 10/bf152d0ed1dc159239db1ba1f74fdbc40cb02f626770dcd5815c427ce0688c2635a06ed69af364396da4636d0408fcf7d4afdf7881724c3307e46aff30ca49e2
1225012250
languageName: node
1225112251
linkType: hard
1225212252

12253+
"graceful-fs@patch:graceful-fs@npm%3A4.2.11#~/.yarn/patches/graceful-fs-npm-4.2.11-24bb648a68.patch":
12254+
version: 4.2.11
12255+
resolution: "graceful-fs@patch:graceful-fs@npm%3A4.2.11#~/.yarn/patches/graceful-fs-npm-4.2.11-24bb648a68.patch::version=4.2.11&hash=053b86"
12256+
checksum: 10/0afcf8a9541c4f149b604528e95e970c86876a7f1fce88865ea40deb17732c0446cad45d934bdccb553ad8fed6bf53649848874b541748f5f492c4792681f498
12257+
languageName: node
12258+
linkType: hard
12259+
1225312260
"graphemer@npm:^1.4.0":
1225412261
version: 1.4.0
1225512262
resolution: "graphemer@npm:1.4.0"

0 commit comments

Comments
 (0)