Skip to content

Commit 3831cdb

Browse files
authored
Merge pull request #6 from ember-cli/pichfl/skip-read-only
Skip getter-only properties so Node 24.6 doesn't freak out
2 parents e5c14bf + 323606d commit 3831cdb

File tree

1 file changed

+62
-52
lines changed

1 file changed

+62
-52
lines changed

index.js

Lines changed: 62 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -78,65 +78,75 @@ class FSMonitor {
7878
let monitor = this;
7979

8080
for (let member in fs) {
81-
if (this.blacklist.indexOf(member) === -1) {
82-
let old = fs[member];
83-
if (typeof old === 'function') {
84-
fs[member] = (function(old, member) {
85-
return function() {
86-
if (monitor.shouldMeasure()) {
87-
let args = new Array(arguments.length);
88-
for (let i = 0; i < arguments.length; i++) {
89-
args[i] = arguments[i];
90-
}
81+
if (this.blacklist.indexOf(member) > -1) {
82+
continue;
83+
}
84+
85+
const descriptor = Object.getOwnPropertyDescriptor(fs, member);
86+
87+
if (descriptor && descriptor.get && !descriptor.set) {
88+
// Skip getter-only properties (like Utf8Stream, F_OK, etc. in Node.js 24+)
89+
continue;
90+
}
91+
92+
let old = fs[member];
9193

92-
let location;
93-
94-
if(monitor.captureTracing) {
95-
try {
96-
/*
97-
Uses error to build a stack of where the fs call was coming from.
98-
99-
An example output of what this will look like is
100-
101-
{
102-
fileName: '~/heimdall-fs-monitor/tests.js',
103-
lineNumber: 87,
104-
stackTrace: ' at Object.readFileSync (~/heimdall-fs-monitor/index.js:115:35)\n' +
105-
' at Context.<anonymous> (~/heimdall-fs-monitor/tests.js:87:8)\n' +
106-
' at callFn (~/heimdall-fs-monitor/node_modules/mocha/lib/runnable.js:383:21)\n' +
107-
' at Test.Runnable.run (~/heimdall-fs-monitor/node_modules/mocha/lib/runnable.js:375:7)\n' +
108-
' at Runner.runTest (~/heimdall-fs-monitor/node_modules/mocha/lib/runner.js:446:10)\n' +
109-
' at ~/heimdall-fs-monitor/node_modules/mocha/lib/runner.js:564:12\n' +
110-
' at next (~/heimdall-fs-monitor/node_modules/mocha/lib/runner.js:360:14)\n' +
111-
' at ~/heimdall-fs-monitor/node_modules/mocha/lib/runner.js:370:7\n' +
112-
' at next (~/heimdall-fs-monitor/node_modules/mocha/lib/runner.js:294:14)\n' +
113-
' at Immediate._onImmediate (~/heimdall-fs-monitor/node_modules/mocha/lib/runner.js:338:5)'
114-
}
115-
*/
116-
const error = new Error();
117-
const calls = callsites();
118-
119-
location = {
120-
fileName: calls[1].getFileName(),
121-
lineNumber: calls[1].getLineNumber(),
122-
stackTrace: cleanStack(extractStack(error), { pretty: true }),
94+
if (typeof old === 'function') {
95+
fs[member] = (function(old, member) {
96+
return function() {
97+
if (monitor.shouldMeasure()) {
98+
let args = new Array(arguments.length);
99+
for (let i = 0; i < arguments.length; i++) {
100+
args[i] = arguments[i];
101+
}
102+
103+
let location;
104+
105+
if(monitor.captureTracing) {
106+
try {
107+
/*
108+
Uses error to build a stack of where the fs call was coming from.
109+
110+
An example output of what this will look like is
111+
112+
{
113+
fileName: '~/heimdall-fs-monitor/tests.js',
114+
lineNumber: 87,
115+
stackTrace: ' at Object.readFileSync (~/heimdall-fs-monitor/index.js:115:35)\n' +
116+
' at Context.<anonymous> (~/heimdall-fs-monitor/tests.js:87:8)\n' +
117+
' at callFn (~/heimdall-fs-monitor/node_modules/mocha/lib/runnable.js:383:21)\n' +
118+
' at Test.Runnable.run (~/heimdall-fs-monitor/node_modules/mocha/lib/runnable.js:375:7)\n' +
119+
' at Runner.runTest (~/heimdall-fs-monitor/node_modules/mocha/lib/runner.js:446:10)\n' +
120+
' at ~/heimdall-fs-monitor/node_modules/mocha/lib/runner.js:564:12\n' +
121+
' at next (~/heimdall-fs-monitor/node_modules/mocha/lib/runner.js:360:14)\n' +
122+
' at ~/heimdall-fs-monitor/node_modules/mocha/lib/runner.js:370:7\n' +
123+
' at next (~/heimdall-fs-monitor/node_modules/mocha/lib/runner.js:294:14)\n' +
124+
' at Immediate._onImmediate (~/heimdall-fs-monitor/node_modules/mocha/lib/runner.js:338:5)'
123125
}
124-
} catch(ex) {
125-
debug(`could not generate stack because: ${ex.message}`)
126+
*/
127+
const error = new Error();
128+
const calls = callsites();
129+
130+
location = {
131+
fileName: calls[1].getFileName(),
132+
lineNumber: calls[1].getLineNumber(),
133+
stackTrace: cleanStack(extractStack(error), { pretty: true }),
126134
}
135+
} catch(ex) {
136+
debug(`could not generate stack because: ${ex.message}`)
127137
}
128-
129-
return monitor._measure(member, old, fs, args, location);
130-
} else {
131-
return old.apply(fs, arguments);
132138
}
133-
};
134-
}(old, member));
135139

136-
fs[member].__restore = function() {
137-
fs[member] = old;
140+
return monitor._measure(member, old, fs, args, location);
141+
} else {
142+
return old.apply(fs, arguments);
143+
}
138144
};
139-
}
145+
}(old, member));
146+
147+
fs[member].__restore = function() {
148+
fs[member] = old;
149+
};
140150
}
141151
}
142152
}

0 commit comments

Comments
 (0)