Skip to content

path: Make os an option argument #687

@nayeemrmn

Description

@nayeemrmn

The export structure of the path module looks like this:

export const posix = {
  basename,
  dirname,
  extname,
  ...
};

export const win32 = {
  basename,
  dirname,
  extname,
  ...
};

export {
  basename,
  dirname, 
  extname,
  ...,
  globToRegExp,
  normalizeGlob,
  SEP,
  SEP_PATTERN,
  ...
};

This seems archaic and overly bound to where we vendored the implementation. It forces us to put group every function by OS in just path/posix.ts and path/win32.ts, rather than having modules like path/join.ts, path/file_url.ts, etc. It's hard to maintain and the test modules don't match it.

We should instead export one set of functions which each have an options interface containing the OS. They all have few enough positional arguments. This is modelled already by path/glob.ts, which gets to have its own module, containing:

export interface GlobOptions {
  ...,
  /** Operating system. Defaults to the native OS. */
  os?: typeof Deno.build.os;
}

These functions can branch by OS individually.

The current structure allows importing one namespace of functions for another OS, but this is niche enough that users should make such an abstraction themselves if they need it (in reality they can just import it from the node/ polyfill).

Ref https://github.com/denoland/deno/discussions/8405.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions