Files
scriptc/tests/corpus/2916-path-function-values-cjs.ts
Chris Tate bf6dfb882b Add static Node path function values (#352)
* Add static Node path function values

* Preserve JavaScript builtin alias fences
2026-09-19 12:24:40 -05:00

16 lines
777 B
TypeScript

// The CommonJS namespace and destructured require spellings materialize
// the same exact-arity node:path callable values as ESM imports.
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
const path = require("node:path") as typeof import("node:path");
const { extname, isAbsolute, normalize } = require("node:path") as typeof import("node:path");
const paths = ["/tmp/a.ts", "relative.js", "/root/readme"];
console.log(paths.map(extname).join("|"));
console.log(paths.filter(isAbsolute).join("|"));
console.log(path.extname === extname, path.normalize === normalize);
const transforms: ((value: string) => string)[] = [path.normalize, path.dirname, extname];
console.log(transforms.map((fn) => fn("a//b/../file.ts")).join("|"));