Skip to content
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

refactor: split path into per-os modules #3649

Merged
merged 6 commits into from
Sep 28, 2023

Conversation

jollytoad
Copy link
Contributor

Splits path functions into a module per platform and common fns.
Also applied the pattern to glob.

As discussed in #3553
Also see #3600

@CLAassistant
Copy link

CLAassistant commented Sep 18, 2023

CLA assistant check
All committers have signed the CLA.

Comment on lines +16 to +23
const constants: GlobConstants = {
sep: "/+",
sepMaybe: "/*",
seps: ["/"],
globstar: "(?:[^/]*(?:/|$)+)*",
wildcard: "[^/]*",
escapePrefix: "\\",
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks nice

@kt3k
Copy link
Member

kt3k commented Sep 19, 2023

Maybe web can move normalizeGlob and joinGlobs to _common like isGlob?

Comment on lines +21 to 22
export type GlobToRegExpOptions = GlobOptions & {
os?: OSType;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this kept because of backward compatibility? Do you think it's good idea to keep this option in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was mainly so that the tests still work, personally I think the os option should be ditched entirely otherwise it's inconsistent with the other path fns, but the tests will need reworking to account for that.

path/mod.ts Outdated Show resolved Hide resolved
path/win32.ts Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should also deprecate this path (and also path/posix.ts).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be useful to be able to deprecate an entire module, so that it's import statement and/or all imported members display with usual deprecated strike-through, but I'm not sure there is a way to do that is there?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need to alias items and deprecate the aliases.

import * as path from "./windows/mod.ts";
/** @deprecated (will be removed after 0.210.0) Import from `path/windows/mod.ts` instead. */
export const sep = path.sep;
/** @deprecated (will be removed after 0.210.0) Import from `path/windows/mod.ts` instead. */
export const delimiter = path.delimiter;
/** @deprecated (will be removed after 0.210.0) Import from `path/windows/mod.ts` instead. */
export const resolve = path.resolve;
...

@kt3k
Copy link
Member

kt3k commented Sep 19, 2023

This should be backward compatible from my understanding. Mostly looks good to me.

I wonder if it makes sense to have path/posix/to_namespaced_path.ts as it doesn't have effect in non-window platforms.

@jollytoad
Copy link
Contributor Author

I wonder if it makes sense to have path/posix/to_namespaced_path.ts as it doesn't have effect in non-window platforms.

I think it makes sense to keep it purely for the sake of API consistency between /path, /path/posix & /path/windows.

@kt3k
Copy link
Member

kt3k commented Sep 19, 2023

I think it makes sense to keep it purely for the sake of API consistency between /path, /path/posix & /path/windows.

Ok. Makes sense.

@kt3k
Copy link
Member

kt3k commented Sep 25, 2023

Is there anything remaining with this PR?

@jollytoad
Copy link
Contributor Author

Maybe web can move normalizeGlob and joinGlobs to _common like isGlob?

I was just looking into this and noticed that there is an inconsistency in the options. The GlobOptions jsdoc says globstar defaults to true, which is the case for globToRegExp, but in normalizeGlob & joinGlob it actually defaults to false!

Also, these fns are pretty simple and rely on platform specific imports (eg. SEP, SEP_PATTERN, normalize, join), which would have to be passed into a common fn, I think it may just be simplier to retain the platform specific implementations of each.

@jollytoad jollytoad marked this pull request as ready for review September 27, 2023 21:58
Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants