Skip to content

Commit 3eaa10f

Browse files
committed
fix: support lstatSync throwIfNoEntry
1 parent 3762085 commit 3eaa10f

7 files changed

Lines changed: 59 additions & 5 deletions

File tree

js/private/node-patches/fs.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/private/node-patches/src/fs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export const patcher = (fs: any = _fs, roots: string[]) => {
135135
) {
136136
const stats = origLstatSync(...args)
137137

138-
if (!stats.isSymbolicLink()) {
138+
if (!stats?.isSymbolicLink()) {
139139
// the file is not a symbolic link so there is nothing more to do
140140
return stats
141141
}

js/private/node-patches_legacy/fs.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/private/node-patches_legacy/src/fs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export const patcher = (fs: any = _fs, roots: string[]) => {
135135
) {
136136
const stats = origLstatSync(...args)
137137

138-
if (!stats.isSymbolicLink()) {
138+
if (!stats?.isSymbolicLink()) {
139139
// the file is not a symbolic link so there is nothing more to do
140140
return stats
141141
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
9546c440ffbbe36177f305a1aec4bf89fa08eea5926fe828c8e9edd8e08a16a7
2-
f68066745a57eff40fc49b4600cdde860dfa86ab231ebe4ed65097c98cc2df4f
2+
d26b897f8c3e3c3464f5acfd50ad56793f82f1f362e2bc2a78bc6a77204561cc

js/private/test/node-patches/lstat.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,33 @@ describe('testing lstat', async () => {
7070
)
7171
})
7272

73+
await it('can lstatSync throwIfNoEntry:false', async () => {
74+
await withFixtures(
75+
{
76+
a: { g: {} },
77+
b: { file: 'contents' },
78+
},
79+
async (fixturesDir) => {
80+
fixturesDir = fs.realpathSync(fixturesDir)
81+
82+
const patchedFs = Object.assign({}, fs)
83+
patchedFs.promises = Object.assign({}, fs.promises)
84+
patcher(patchedFs, [
85+
path.join(fixturesDir),
86+
path.join(fixturesDir, 'a', 'g'),
87+
])
88+
89+
assert.equal(
90+
undefined,
91+
patchedFs.lstatSync(
92+
path.join(fixturesDir, 'doesnt-exist'),
93+
{ throwIfNoEntry: false }
94+
)
95+
)
96+
}
97+
)
98+
})
99+
73100
await it('can lstat symlink in guard is file', async () => {
74101
await withFixtures(
75102
{

js/private/test/node-patches_legacy/lstat.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,33 @@ describe('testing lstat', async () => {
7070
)
7171
})
7272

73+
await it('can lstatSync throwIfNoEntry:false', async () => {
74+
await withFixtures(
75+
{
76+
a: { g: {} },
77+
b: { file: 'contents' },
78+
},
79+
async (fixturesDir) => {
80+
fixturesDir = fs.realpathSync(fixturesDir)
81+
82+
const patchedFs = Object.assign({}, fs)
83+
patchedFs.promises = Object.assign({}, fs.promises)
84+
patcher(patchedFs, [
85+
path.join(fixturesDir),
86+
path.join(fixturesDir, 'a', 'g'),
87+
])
88+
89+
assert.equal(
90+
undefined,
91+
patchedFs.lstatSync(
92+
path.join(fixturesDir, 'doesnt-exist'),
93+
{ throwIfNoEntry: false }
94+
)
95+
)
96+
}
97+
)
98+
})
99+
73100
await it('can lstat symlink in guard is file', async () => {
74101
await withFixtures(
75102
{

0 commit comments

Comments
 (0)