GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — [WIP] fs: feature detection for recursive mkdir[Sync] by MylesBorins · Pull Request #22302 · nodejs/node Conversation
|
|
@MylesBorins build started: https://ci.nodejs.org/blue/organizations/jenkins/node-test-pull-request-lite-pipeline/detail/node-test-pull-request-lite-pipeline/551/pipeline |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I don’t think we should encourage that kind of Symbol-digging, and I don’t really see a reason for this to be non-enumerable (or non-writable, since writability might be nice for tests). What’s the motivation for making it so hard, instead of having |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| can be used to detect if the recursive feature is available | ||
|
|
||
| ```js | ||
| Object.getOwnPropertySymbols(fs.mkdir).map((sym) => { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
What if instead of a symbol specific to this feature we exposed a "feature" symbol? It could be reused in other methods, and would be well known, so it wouldn't require looping over properties.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Sounds interesting! Are you imagining that Symbol('features') would then have an array with a list of all features? Can you share a code example of how userland feature detection would look?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I was thinking that Symbol('features') would be public API, which is how users would know to access it. Then, I'd do something like:
fs.mkdir[kFeaturesSymbol] = { recursive: true };
Open to suggestions on that implementation, but I'd go with an object over an array because it's a bit more flexible to work with IMO.
From a user's perspective:
const features = `require('util').FEATURES_SYMBOL;` // also open to suggestions here. const { mkdir } = require('fs'); if (typeof features == 'symbol' && mkdir[features].recursive) { // use the new thing } else { // do the old thing }
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Just pushed a commit to take this approach, lmk what you think
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@addaleax I was thinking that this would be a good place to start for a discussion about how to do feature detection. The biggest reason for making this a symbol and non-enumerable rather than just an extension to the object was that this method is unlikely to break any current workflows or monkey patching of the object. This could scale across the entire code base without disrupting or extending any object in a noticeable way. While the symbol digging is a bit verbose it could easily be abstracted into a user land lib to function hasFeature(obj, feature) { Object.getOwnPropertySymbols(obj).map((sym) => { return sym.toString(); }).includes(`Symbol(${feature})`); } |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
+1 for well known property names ...or, we could take another look at exposing the node version in a programmatic way. i tried to do this a few times and i think it was reverted but maybe we can come up with something else. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@devsnek it hasn't landed in a release yet. If you think that is the case we still have time to rebase it out of 10.x and land another change. That being said I disagree with the sentiment and don't feel that we need another API just for this case. Feature detection is a larger problem in core, and I personally like the idea of using symbols for features as opposed to sniffing semver or for specific bits on the object. If we follow @cjihrig's suggestion about and make a // in common common.features = Symbol('features'); // in fs Object.defineProperty(mkdir, common.features, { value: ['recursive'], writable: false, enumerable: false }); // in userland fs.mkdir[common.features].includes('recursive'); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
What about |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Check for capabilities, not for versions. 👎 to any solution involving SemVer |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Quick update... I've taken @cjihrig's suggestion and made a well known symbol exposed on util and made the value an object rather than an array... for the most part this hides all the symbol bits and makes the userland code much more readable fs.mkdir[util.features].recursive; // true @addaleax does this alleviate some of your concerns? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| --> | ||
|
|
||
| * {symbol} that can be used to do feature detection. | ||
|
|
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
😍😻😍
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is definitely fine with me. 👍
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| ``` | ||
|
|
||
| The `util.features` symbol can be used to feature detect if | ||
| recusion is available. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
typo: recursion
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I wanted to recuse myself 😅
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| This is the synchronous version of [`fs.mkdir()`][]. | ||
|
|
||
| The `util.features` symbol can be used to feature detect if | ||
| recusion is available. |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
ditto
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I've added this to the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
As @boneskull pointed out we already have Is this PR a better alternative? Possibly. I think |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I agree with that statement. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| ### util.features | ||
| <!-- YAML | ||
| added: REPlACEME |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
l -> L
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| callbackify, | ||
| debuglog, | ||
| deprecate, | ||
| features: Symbol('features'), |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
can the description be node.util.features
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
One drawback of this approach is that users will need to do recursive nesting checks to avoid getting errors in older Node versions. For this feature specifically, you'd have to do: util.features && fs.mkdir[util.features].recursive However, in the future, it gets even worse; if you're checking for hypothetical util.features && modulex.methody[util.features] && modulex.methody[util.features].featurez It works, but it's a pretty long-winded feature detection check IMO. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Synchronously creates a directory. Returns `undefined`. | ||
| This is the synchronous version of [`fs.mkdir()`][]. | ||
|
|
||
| The `util.features` symbol can be used to feature detect if |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Link to util.features?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I don't see why the first conditional is necessary. This should work fine + cache: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Alternative approach and less verbose |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
TBH, I'm not a fan of this approach when we could just have a separate |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@jasnell it doesn't seem scalable to me to make a new API for every new flag or feature we add to an API |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I don't like this approach. While feature detection is a good thing to have, and I am not against landing this per se, this does not solve the recursive mkdir problem. And I am against landing this as a solution to the recursive mkdir feature detection problem. The thing is -- users (ok, almost all users) won't care about complex feature detection. If they care about old versions -- they will use userland And this is what would happen on old versions (e.g. when someone would try to use old Node.js to run a module which expects new API): > fs.mkdir('./foo/sdfsd/df', { recursive: true }, (...args) => console.log(args)) undefined > [ { Error: ENOENT: no such file or directory, mkdir './foo/sdfsd/df' errno: -2, code: 'ENOENT', syscall: 'mkdir', path: './foo/sdfsd/df' } ] This error message is completely unhelpful for the end user, and looks like there is a bug somewhere, either in their code or their deps. With > fs.mkdirp('./foo/sdfsd/df', (...args) => console.log(args)) TypeError: fs.mkdirp is not a function This is much more understandable, imo. Why not just a one-line It would be shorter, easier to support, would involve less code and doc changes, and will provide both the ability to feature-detect and a more simple way to use it while giving sensible errors to users of unsupported Node.js versions. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@bcoe That's certainly better if we can't have a feature detection flag. I still dislike version sniffing because it's brittle; if |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
ok folks, should I back mkdirp out of the v10.9.0 release going out tomorrow so we don't bake in something difficult to revert? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
@rvagg I think so. There's no rush on getting that feature into 10.9.0. If it waits until 10.10.0, that should be fine. That gives us the opportunity to consider changing the API as some are suggesting here. As I wrote in another issue, better to go slow and get this right then rush it out and get it wrong. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Perhaps determining support for a new feature can be punted to a userland module. I've mocked up such a module here: https://github.com/bengl/core-features
If its data was consistently updated (and backfilled for previous features), it could be a useful alternative to building this functionality into core. In addition, this can work for older versions, prior to any version detection efforts. Such a module could be adopted/blessed into the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Making my objection explicit.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return false; | ||
| } | ||
|
|
||
| const kCustomFeatureDetectionSymbol = Symbol('node.util.features'); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I think this should be a Symbol.for('node.util.features'). It makes things a lot simpler for people maintaining isomorphic modules.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
@bcoe It does just a bit, because certain features gets backported across multiple lines, which makes anything related to version checking hard. It works well just for semver-major changes, not for things like this. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
FWIW python also takes the different-function-name approach ( |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I agree with the above by @isaacs and @gabrielschulhof. Also the suggestion of an external package maintained and published by the org seems appealing to me (among other reasons, since it can be backwards compatible unlike something added to core). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Discussed at TSC meeting. Will open a new issue to come to a decision about how we want to do feature detection and mark this one as blocked until that gets resolved. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Yes it does.
Il giorno mer 29 ago 2018 alle 23:52 Christopher Hiller <
[email protected]> ha scritto:
… @Trott <https://github.com/Trott> Does this block #21875
<#21875> from being released?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#22302 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AADL40Wb4Jo8yH_w-oarjB21WstUj87pks5uVw0RgaJpZM4V7dWv>
.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I don't think we are moving forward with this, closing. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I understand why the options route to extend |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@sam-github This was a point raised above in #22302 (comment). Ultimately, I think the thing we may be learning is that feature detection for stuff like this isn't nearly as widely needed as we imagine. That too is a point made by others above, though. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I'm curious where the data from that came from. I mean, if there is no way to detect certain features as a module author, I'm just going to have to publish modules that are brittle and do version sniffing instead. In the past, I felt like the Node.js project said that it was bad to version sniff the It would be awesome, though, if we're expected to version sniff, if logic such as the module |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
It's anecdotal and I could certainly be drawing the wrong conclusion. A reasonable alternative conclusion would be "people aren't using the feature widely yet". The data/anecdotal information is this: We had a lot of debate and discussion about how to do feature detection, whether we should release the feature before we had that sorted out, etc. When we did release the feature without feature detection? Nothing bad seems to have happened. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
That's just because I gave up and just assumed no feature detection would ever be delivered and just went with version sniffing. Like I said, if version sniffing is the correct solution, so be it, as it's the only option I have. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.