-
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 1 commit
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 |
---|---|---|
|
@@ -2086,13 +2086,11 @@ fs.mkdir('/tmp/a/apple', { recursive: true }, (err) => { | |
}); | ||
``` | ||
|
||
`fs.mkdir` has non-enumerable non-writable property `Symbol('recursive')` that | ||
can be used to detect if the recursive feature is available | ||
The `util.features` symbol can be used to feature detect if | ||
recusion is available. | ||
|
||
```js | ||
Object.getOwnPropertySymbols(fs.mkdir).map((sym) => { | ||
return sym.toString(); | ||
}).includes('Symbol(recursive)'); | ||
fs.mkdir[util.features].includes('recursive'); | ||
// true | ||
``` | ||
|
||
|
@@ -2116,13 +2114,11 @@ changes: | |
Synchronously creates a directory. Returns `undefined`. | ||
This is the synchronous version of [`fs.mkdir()`][]. | ||
|
||
`fs.mkdirSync` has non-enumerable non-writable property `Symbol('recursive')` | ||
that can be used to detect if the recursive feature is available | ||
The `util.features` symbol can be used to feature detect if | ||
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. Link to |
||
recusion is available. | ||
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. ditto |
||
|
||
```js | ||
Object.getOwnPropertySymbols(fs.mkdirSync).map((sym) => { | ||
return sym.toString(); | ||
}).includes('Symbol(recursive)'); | ||
fs.mkdirSync[util.features].includes('recursive'); | ||
// true | ||
``` | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,6 +179,13 @@ The `--throw-deprecation` command line flag and `process.throwDeprecation` | |
property take precedence over `--trace-deprecation` and | ||
`process.traceDeprecation`. | ||
|
||
### 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. Nit: |
||
<!-- YAML | ||
added: REPlACEME | ||
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. l -> L |
||
--> | ||
|
||
* {symbol} that can be used to do feature detection. | ||
|
||
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. 😍😻😍 |
||
## util.format(format[, ...args]) | ||
<!-- YAML | ||
added: v0.5.3 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ const { | |
O_SYMLINK | ||
} = constants; | ||
|
||
const { _extend } = require('util'); | ||
const { _extend, features } = require('util'); | ||
const pathModule = require('path'); | ||
const { isUint8Array } = require('internal/util/types'); | ||
const binding = process.binding('fs'); | ||
|
@@ -745,12 +745,10 @@ function mkdir(path, options, callback) { | |
validateMode(mode, 'mode', 0o777), recursive, req); | ||
} | ||
|
||
Object.defineProperties(mkdir, { | ||
[Symbol('recursive')]: { | ||
value: true, | ||
writable: false, | ||
enumerable: false | ||
} | ||
Object.defineProperty(mkdir, features, { | ||
value: ['recursive'], | ||
writable: false, | ||
enumerable: false | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
}); | ||
|
||
function mkdirSync(path, options) { | ||
|
@@ -774,12 +772,10 @@ function mkdirSync(path, options) { | |
handleErrorFromBinding(ctx); | ||
} | ||
|
||
Object.defineProperties(mkdirSync, { | ||
[Symbol('recursive')]: { | ||
value: true, | ||
writable: false, | ||
enumerable: false | ||
} | ||
Object.defineProperty(mkdirSync, 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. should we also add this property on 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. I think that once we have consensus on this PR we should make a tracking issue and potentially get a bunch of different APIs properly setup with this 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. oh, I was more specifically thinking we should have the symbol on 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. If we get consensus on this approach, let's pull the
|
||
value: ['recursive'], | ||
writable: false, | ||
enumerable: false | ||
}); | ||
|
||
function readdir(path, options, callback) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1472,6 +1472,7 @@ module.exports = exports = { | |
callbackify, | ||
debuglog, | ||
deprecate, | ||
features: Symbol('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. can the description be
This comment was marked as resolved.
Sorry, something went wrong. |
||
format, | ||
formatWithOptions, | ||
getSystemErrorName, | ||
|
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.
typo: recursion
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.
I wanted to recuse myself 😅