Skip to content

Commit 8192614

Browse files
wardpeetpieh
authored andcommitted
fix(gatsby): fix eperm when cache getting cleared (#35154)
(cherry picked from commit 6684c60)
1 parent f080b46 commit 8192614

File tree

3 files changed

+43
-35
lines changed

3 files changed

+43
-35
lines changed

packages/gatsby/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
"date-fns": "^2.25.0",
5656
"debug": "^3.2.7",
5757
"deepmerge": "^4.2.2",
58-
"del": "^5.1.0",
5958
"detect-port": "^1.3.0",
6059
"devcert": "^1.2.0",
6160
"dotenv": "^8.6.0",
@@ -93,6 +92,7 @@
9392
"gatsby-telemetry": "^3.10.0",
9493
"gatsby-worker": "^1.10.0",
9594
"glob": "^7.2.0",
95+
"globby": "^11.1.0",
9696
"got": "^11.8.2",
9797
"graphql": "^15.7.2",
9898
"graphql-compose": "^9.0.7",

packages/gatsby/src/services/initialize.ts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import * as fs from "fs-extra"
44
import { releaseAllMutexes } from "gatsby-core-utils/mutex"
55
import md5File from "md5-file"
66
import crypto from "crypto"
7-
import del from "del"
87
import path from "path"
98
import telemetry from "gatsby-telemetry"
9+
import glob from "globby"
1010

1111
import apiRunnerNode from "../utils/api-runner-node"
1212
import { getBrowsersList } from "../utils/browserslist"
@@ -284,12 +284,18 @@ export async function initialize({
284284
}
285285
)
286286
activity.start()
287-
await del([
288-
`public/**/*.{html,css}`,
289-
`!public/page-data/**/*`,
290-
`!public/static`,
291-
`!public/static/**/*.{html,css}`,
292-
])
287+
const files = await glob(
288+
[
289+
`public/**/*.{html,css}`,
290+
`!public/page-data/**/*`,
291+
`!public/static`,
292+
`!public/static/**/*.{html,css}`,
293+
],
294+
{
295+
cwd: program.directory,
296+
}
297+
)
298+
await Promise.all(files.map(file => fs.remove(file)))
293299
activity.end()
294300
}
295301

@@ -429,28 +435,30 @@ export async function initialize({
429435

430436
const deleteGlobs = [
431437
// By default delete all files & subdirectories
432-
`${cacheDirectory}/**`,
433-
`!${cacheDirectory}/data`,
434-
`${cacheDirectory}/data/**`,
435-
`!${cacheDirectory}/data/gatsby-core-utils/`,
436-
`!${cacheDirectory}/data/gatsby-core-utils/**`,
437-
`!${cacheDirectory}/compiled`,
438+
`.cache/**`,
439+
`.cache/data/**`,
440+
`!.cache/data/gatsby-core-utils/**`,
441+
`!.cache/compiled`,
438442
]
439443

440444
if (process.env.GATSBY_EXPERIMENTAL_PRESERVE_FILE_DOWNLOAD_CACHE) {
441445
// Stop the caches directory from being deleted, add all sub directories,
442446
// but remove gatsby-source-filesystem
443-
deleteGlobs.push(`!${cacheDirectory}/caches`)
444-
deleteGlobs.push(`${cacheDirectory}/caches/*`)
445-
deleteGlobs.push(`!${cacheDirectory}/caches/gatsby-source-filesystem`)
447+
deleteGlobs.push(`!.cache/caches`)
448+
deleteGlobs.push(`.cache/caches/*`)
449+
deleteGlobs.push(`!.cache/caches/gatsby-source-filesystem`)
446450
}
447451

448452
if (process.env.GATSBY_EXPERIMENTAL_PRESERVE_WEBPACK_CACHE) {
449453
// Add webpack
450-
deleteGlobs.push(`!${cacheDirectory}/webpack`)
454+
deleteGlobs.push(`!.cache/webpack`)
451455
}
452456

453-
await del(deleteGlobs)
457+
const files = await glob(deleteGlobs, {
458+
cwd: program.directory,
459+
})
460+
461+
await Promise.all(files.map(file => fs.remove(file)))
454462
} catch (e) {
455463
reporter.error(`Failed to remove .cache files.`, e)
456464
}

yarn.lock

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10772,7 +10772,7 @@ fast-glob@^2.2.6:
1077210772
merge2 "^1.2.3"
1077310773
micromatch "^3.1.10"
1077410774

10775-
fast-glob@^3.0.3, fast-glob@^3.1.1, fast-glob@^3.2.11, fast-glob@^3.2.4:
10775+
fast-glob@^3.0.3, fast-glob@^3.1.1, fast-glob@^3.2.11, fast-glob@^3.2.4, fast-glob@^3.2.9:
1077610776
version "3.2.11"
1077710777
resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.2.11.tgz#a1172ad95ceb8a16e20caa5c5e56480e5129c1d9"
1077810778
integrity sha512-xrO3+1bxSo3ZVHAnqzyuewYT6aMFHRAd4Kcs92MAonjwQZLsK9d0SF1IyQ3k5PoirxTW0Oe/RqFgMQ6TcNE5Ew==
@@ -11849,16 +11849,16 @@ globby@^10.0.1:
1184911849
merge2 "^1.2.3"
1185011850
slash "^3.0.0"
1185111851

11852-
globby@^11.0.1, globby@^11.0.3, globby@^11.0.4:
11853-
version "11.0.4"
11854-
resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.4.tgz#2cbaff77c2f2a62e71e9b2813a67b97a3a3001a5"
11855-
integrity sha512-9O4MVG9ioZJ08ffbcyVYyLOJLk5JQ688pJ4eMGLpdWLHq/Wr1D9BlriLQyL0E+jbkuePVZXYFj47QM/v093wHg==
11852+
globby@^11.0.1, globby@^11.0.3, globby@^11.0.4, globby@^11.1.0:
11853+
version "11.1.0"
11854+
resolved "https://registry.yarnpkg.com/globby/-/globby-11.1.0.tgz#bd4be98bb042f83d796f7e3811991fbe82a0d34b"
11855+
integrity sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==
1185611856
dependencies:
1185711857
array-union "^2.1.0"
1185811858
dir-glob "^3.0.1"
11859-
fast-glob "^3.1.1"
11860-
ignore "^5.1.4"
11861-
merge2 "^1.3.0"
11859+
fast-glob "^3.2.9"
11860+
ignore "^5.2.0"
11861+
merge2 "^1.4.1"
1186211862
slash "^3.0.0"
1186311863

1186411864
globby@^6.1.0:
@@ -12890,10 +12890,10 @@ ignore@^4.0.3, ignore@^4.0.6:
1289012890
version "4.0.6"
1289112891
resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc"
1289212892

12893-
ignore@^5.0.0, ignore@^5.1.1, ignore@^5.1.4, ignore@^5.1.8:
12894-
version "5.1.8"
12895-
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.1.8.tgz#f150a8b50a34289b33e22f5889abd4d8016f0e57"
12896-
integrity sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==
12893+
ignore@^5.0.0, ignore@^5.1.1, ignore@^5.1.4, ignore@^5.1.8, ignore@^5.2.0:
12894+
version "5.2.0"
12895+
resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.2.0.tgz#6d3bac8fa7fe0d45d9f9be7bac2fc279577e345a"
12896+
integrity sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==
1289712897

1289812898
image-q@^1.1.1:
1289912899
version "1.1.1"
@@ -16324,10 +16324,10 @@ merge-stream@^2.0.0:
1632416324
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
1632516325
integrity sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==
1632616326

16327-
merge2@^1.2.3, merge2@^1.3.0:
16328-
version "1.3.0"
16329-
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.3.0.tgz#5b366ee83b2f1582c48f87e47cf1a9352103ca81"
16330-
integrity sha512-2j4DAdlBOkiSZIsaXk4mTE3sRS02yBHAtfy127xRV3bQUFqXkjHCHLW6Scv7DwNRbIWNHH8zpnz9zMaKXIdvYw==
16327+
merge2@^1.2.3, merge2@^1.3.0, merge2@^1.4.1:
16328+
version "1.4.1"
16329+
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae"
16330+
integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==
1633116331

1633216332
meros@^1.1.2:
1633316333
version "1.1.4"

0 commit comments

Comments
 (0)