-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] fs: feature detection for recursive mkdir[Sync] #22302
Changes from 8 commits
f9dd8fd
84c1d45
c7c0853
9cf4630
c3ee316
7e4ab5d
efc9adf
96ddc47
7a7d800
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,7 @@ const { | |
|
||
const { FSReqCallback, statValues } = binding; | ||
const internalFS = require('internal/fs/utils'); | ||
const { getPathFromURL } = require('internal/url'); | ||
const { addFeatureDetection, getPathFromURL } = require('internal/url'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bah... I BROKE IT |
||
const internalUtil = require('internal/util'); | ||
const { | ||
copyObject, | ||
|
@@ -745,6 +745,10 @@ function mkdir(path, options, callback) { | |
validateMode(mode, 'mode', 0o777), recursive, req); | ||
} | ||
|
||
addFeatureDetection(mkdir, { | ||
recursive: true | ||
}); | ||
|
||
function mkdirSync(path, options) { | ||
if (typeof options === 'number' || typeof options === 'string') { | ||
options = { mode: options }; | ||
|
@@ -766,6 +770,10 @@ function mkdirSync(path, options) { | |
handleErrorFromBinding(ctx); | ||
} | ||
|
||
addFeatureDetection(mkdirSync, { | ||
recursive: true | ||
}); | ||
|
||
function readdir(path, options, callback) { | ||
callback = makeCallback(typeof options === 'function' ? options : callback); | ||
options = getOptions(options, {}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -366,8 +366,20 @@ function isInsideNodeModules() { | |
return false; | ||
} | ||
|
||
const kCustomFeatureDetectionSymbol = Symbol('node.util.features'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be a |
||
|
||
function addFeatureDetection(obj, value) { | ||
Object.defineProperty(obj, kCustomFeatureDetectionSymbol, { | ||
value, | ||
writable: false, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
} | ||
|
||
|
||
module.exports = { | ||
addFeatureDetection, | ||
assertCrypto, | ||
cachedResult, | ||
convertToValidSignal, | ||
|
@@ -394,6 +406,9 @@ module.exports = { | |
// alternative to using 'inspect' | ||
customInspectSymbol: Symbol('util.inspect.custom'), | ||
|
||
// Symbol used to do feature detection | ||
featureDetectionSymbol: kCustomFeatureDetectionSymbol, | ||
|
||
// Used by the buffer module to capture an internal reference to the | ||
// default isEncoding implementation, just in case userland overrides it. | ||
kIsEncodingSymbol: Symbol('kIsEncodingSymbol'), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ const common = require('../common'); | |
const assert = require('assert'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { features } = require('util'); | ||
|
||
const tmpdir = require('../common/tmpdir'); | ||
tmpdir.refresh(); | ||
|
@@ -172,6 +173,14 @@ if (common.isMainThread && (common.isLinux || common.isOSX)) { | |
}); | ||
} | ||
|
||
// mkdirp and mkdirSyncp feature detection | ||
{ | ||
assert.strictEqual(fs.mkdir[features].recursive, true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's add a test for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. which undefined case? where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, I think it would be good to demonstrate that this will work fine for feature detection when
|
||
assert.strictEqual(fs.mkdir[features].fhwdgads, undefined); | ||
assert.strictEqual(fs.mkdirSync[features].recursive, true); | ||
assert.strictEqual(fs.mkdirSync[features].fhwdgads, undefined); | ||
} | ||
|
||
// Keep the event loop alive so the async mkdir() requests | ||
// have a chance to run (since they don't ref the event loop). | ||
process.nextTick(() => {}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Flags: --expose-internals | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
const { addFeatureDetection } = require('internal/util'); | ||
const { features } = require('util'); | ||
|
||
function myFunction() { | ||
return true; | ||
} | ||
|
||
addFeatureDetection(myFunction, { | ||
works: true, | ||
}); | ||
|
||
assert.strictEqual(typeof myFunction, 'function'); | ||
assert.strictEqual(myFunction(), true); | ||
assert.strictEqual(myFunction[features].works, true); | ||
assert.strictEqual(myFunction[features].doesNotWork, undefined); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😍😻😍