You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This object contains denormalized data between base, name and ext key values.
Now let's try to replace file extension.
importPathfrom"path";import{assoc}from"ramda"letpath="/Users/ivankleshnin/Projects/demo/config.js";letpathP=assoc("ext",".json",Path.parse(path));/* {... base: 'config.js', -- these two are ext: '.json', -- unsynced!...} */console.log(Path.format(pathP));// extension weren't changed :(
The simplest task is going to be not so simple?!
Now if format took into consideration ext and name rather than base this could lead to an equal problem with changes to base key being ignored.
Can we get rid of this base key? It's always parsed.name + parsed.ext formula, not a big deal to make it manually. Example of hidden file parse: { base: '.gitignore', ext: '', name: '.gitignore' } - same rule apply.
We can probably also implement it in a backward-compatibile way,
keeping base but using JS getter / setter for it's evaluation.
Should be fully backward compatible, unless I miss something.
To be precise: will break code which depends on base changes not propagated to name and ext i.e. on the "buggy" aspect of current behavior. Hard to imagine such code IMO.
Platform Requirements
(of possible feature implementation, not a provided gist)
IMO this sort of functionality should be implemented in user-land (npm). The path.parse function is just a convenient way to split a path into its main components and path.format is mainly for completeness so we can return the path components to the original path string (see the original issue).
does work like the url module now, so it outputs 'some/dir/index.html'. Also, path.format() is documented well enough now that people should know what to expect when using it.
@nwoltman Is your suggestion to deprecate the path module and promote an npm module to take its place?
I didn't mean to suggest to deprecate the path module. What I meant was that "extended" functionality (such as having getters/setters on the object returned by path.parse()) should be provided by an npm module. There's a similar situation with the querystring core module where there's an npm module called qs that provides more functionality than the core module.
I have a faint memory that all the logic was in parse and the others just projected parts of the parse resault... Now I'm confused why is there quadruple duplication (win/posix × parse/specific)?
I think the general consensus established in #12818 was that Object.defineProperty was too slow to be used per-run on the returned object, and defining the getter on the returned object's prototype would cause too many breakages due to Object.keys() no longer returning that property. While I agree that making base an accessor property would be a better API design, I think we are stuck with it unfortunately.
#12511 is half way there. It keeps blinking in and out of my focus... AFAICT it's a less complicated issue than Stats but a thorough breakage analysis will need to be done.
[rant warning]
Now I remember what happened... scope-creep...
and it's really a pain developing on Windows doing a change-compile-test cycle takes ~30 minutes, which got me focusing more and more or solving that, and puff there goes productivity...
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.
Activity
benjamingr commentedon Jun 17, 2015
So your suggestion is that base becomes a getter/setter?
That doesn't sound too bad but I wonder what the impact on backwards compatibility is
ivan-kleshnin commentedon Jun 17, 2015
Examples:
Proof implementation:
Self-contained working gist
Should be fully backward compatible, unless I miss something.
To be precise: will break code which depends on
basechanges not propagated tonameandexti.e. on the "buggy" aspect of current behavior. Hard to imagine such code IMO.Platform Requirements
(of possible feature implementation, not a provided gist)
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty#Configurable_attribute
Basically: IE 9+
Note: I'm not aware of platform support requirements of IO JS.
nwoltman commentedon Feb 9, 2016
IMO this sort of functionality should be implemented in user-land (npm). The
path.parsefunction is just a convenient way to split a path into its main components andpath.formatis mainly for completeness so we can return the path components to the original path string (see the original issue).benjamingr commentedon Apr 17, 2017
@nodejs/collaborators anyone wants to promote this or should we close the issue?
sam-github commentedon Apr 17, 2017
The current behaviour is indeed bizarre, it one of the things I talk about in https://www.youtube.com/watch?v=jJaIwea8r2A
Its not only strange in and of itself, its also inconsistent with node's url.parse/url.format.
@nwoltman Is your suggestion to deprecate the
pathmodule and promote an npm module to take its place?refack commentedon Apr 17, 2017
I'm interested.
nwoltman commentedon Apr 17, 2017
@sam-github In case it helps, the example you gave from your talk:
does work like the
urlmodule now, so it outputs'some/dir/index.html'. Also,path.format()is documented well enough now that people should know what to expect when using it.I didn't mean to suggest to deprecate the path module. What I meant was that "extended" functionality (such as having getters/setters on the object returned by
path.parse()) should be provided by an npm module. There's a similar situation with thequerystringcore module where there's an npm module calledqsthat provides more functionality than the core module.refack commentedon Apr 17, 2017
I have a faint memory that all the logic was in
parseand the others just projected parts of theparseresault... Now I'm confused why is there quadruple duplication (win/posix×parse/specific)?4 remaining items
Trott commentedon Aug 15, 2017
Is the consensus here that this should be a userland npm module? Or is this a bug in Node.js that should be fixed?
TimothyGu commentedon Aug 16, 2017
I think the general consensus established in #12818 was that
Object.definePropertywas too slow to be used per-run on the returned object, and defining the getter on the returned object's prototype would cause too many breakages due toObject.keys()no longer returning that property. While I agree that makingbasean accessor property would be a better API design, I think we are stuck with it unfortunately.@tniessen @refack Thoughts?
refack commentedon Aug 16, 2017
#12511 is half way there. It keeps blinking in and out of my focus... AFAICT it's a less complicated issue than
Statsbut a thorough breakage analysis will need to be done.refack commentedon Aug 16, 2017
[rant warning]

Now I remember what happened... scope-creep...
and it's really a pain developing on Windows doing a change-compile-test cycle takes ~30 minutes, which got me focusing more and more or solving that, and puff there goes productivity...
github-actions commentedon Aug 17, 2022
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.
For more information on how the project manages feature requests, please consult the feature request management document.
github-actions commentedon Sep 17, 2022
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.
For more information on how the project manages feature requests, please consult the feature request management document.