-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(cli): Add @fern-api/path-utils
- Loading branch information
Showing
16 changed files
with
173 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,3 @@ | ||
import path from "path"; | ||
import { convertToOsPath } from "./osPathConverter"; | ||
|
||
export type AbsoluteFilePath = string & { | ||
__AbsoluteFilePath: void; | ||
}; | ||
|
||
export const AbsoluteFilePath = { | ||
of: (value: string): AbsoluteFilePath => { | ||
if (!path.isAbsolute(value)) { | ||
throw new Error("Filepath is not absolute: " + value); | ||
} | ||
return convertToOsPath(value) as AbsoluteFilePath; | ||
} | ||
}; | ||
// For convenience, we re-export the AbsoluteFilePath type for any caller | ||
// that requires fs-utils. | ||
export { AbsoluteFilePath } from "@fern-api/path-utils"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,3 @@ | ||
import path from "path"; | ||
import { convertToOsPath } from "./osPathConverter"; | ||
|
||
export type RelativeFilePath = string & { | ||
__RelativeFilePath: void; | ||
}; | ||
|
||
export const RelativeFilePath = { | ||
of: (value: string): RelativeFilePath => { | ||
if (path.isAbsolute(value)) { | ||
throw new Error("Filepath is not relative: " + value); | ||
} | ||
return convertToOsPath(value) as RelativeFilePath; | ||
} | ||
}; | ||
// For convenience, we re-export the RelativeFilePath type for any caller= | ||
// that requires fs-utils. | ||
export { RelativeFilePath } from "@fern-api/path-utils"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"ignores": [ | ||
"@types/jest", | ||
"globals" | ||
], | ||
"ignore-patterns": [ | ||
"lib" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require("../../../.prettierrc.json"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "@fern-api/path-utils", | ||
"version": "0.0.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/fern-api/fern.git", | ||
"directory": "packages/commons/path-utils" | ||
}, | ||
"files": [ | ||
"lib" | ||
], | ||
"type": "module", | ||
"source": "src/index.ts", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"sideEffects": false, | ||
"scripts": { | ||
"clean": "rm -rf ./lib && tsc --build --clean", | ||
"compile": "tsc --build", | ||
"test": "vitest --passWithNoTests --run", | ||
"test:update": "vitest --passWithNoTests --run -u", | ||
"lint:eslint": "eslint --max-warnings 0 . --ignore-path=../../../.eslintignore", | ||
"lint:eslint:fix": "yarn lint:eslint --fix", | ||
"format": "prettier --write --ignore-unknown --ignore-path ../../../shared/.prettierignore \"**\"", | ||
"format:check": "prettier --check --ignore-unknown --ignore-path ../../../shared/.prettierignore \"**\"", | ||
"organize-imports": "organize-imports-cli tsconfig.json", | ||
"depcheck": "depcheck" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "^29.5.12", | ||
"depcheck": "^1.4.6", | ||
"eslint": "^8.56.0", | ||
"organize-imports-cli": "^0.10.0", | ||
"prettier": "^2.7.1", | ||
"typescript": "4.6.4", | ||
"vitest": "^2.0.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { getPathModule } from "./getPathModule"; | ||
import { convertToOsPath } from "./convertToOsPath"; | ||
|
||
const path = getPathModule(); | ||
|
||
export type AbsoluteFilePath = string & { | ||
__AbsoluteFilePath: void; | ||
}; | ||
|
||
export const AbsoluteFilePath = { | ||
of: (value: string): AbsoluteFilePath => { | ||
if (!path.isAbsolutePath(value)) { | ||
throw new Error("Filepath is not absolute: " + value); | ||
} | ||
return convertToOsPath(value) as AbsoluteFilePath; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { getPathModule } from "./getPathModule"; | ||
import { convertToOsPath } from "./convertToOsPath"; | ||
|
||
const path = getPathModule(); | ||
|
||
export type RelativeFilePath = string & { | ||
__RelativeFilePath: void; | ||
}; | ||
|
||
export const RelativeFilePath = { | ||
of: (value: string): RelativeFilePath => { | ||
if (path.isAbsolute(value)) { | ||
throw new Error("Filepath is not relative: " + value); | ||
} | ||
return convertToOsPath(value) as RelativeFilePath; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { AbsoluteFilePath } from "./AbsoluteFilePath"; | ||
import { RelativeFilePath } from "./RelativeFilePath"; | ||
import { isBrowser } from "./isBrowser"; | ||
|
||
// in this function, we ignore drive paths and roots, since many strings are passed as partial relative paths | ||
export function convertToOsPath(path: string): string { | ||
if (isBrowser()) { | ||
return path.replace(/\\/g, "/"); | ||
} | ||
if (process.platform === "win32") { | ||
return path.replace(/\//g, "\\"); | ||
} else { | ||
return path.replace(/\\/g, "/"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { isBrowser } from "./isBrowser"; | ||
|
||
export function getPathModule() { | ||
if (isBrowser()) { | ||
return { | ||
isAbsolutePath: (value: string): boolean => { | ||
return value.startsWith("/"); | ||
} | ||
}; | ||
} else { | ||
return require("path"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { AbsoluteFilePath } from "./AbsoluteFilePath"; | ||
export { RelativeFilePath } from "./RelativeFilePath"; | ||
export { convertToOsPath } from "./convertToOsPath"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function isBrowser(): boolean { | ||
return typeof window !== "undefined"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "../../../shared/tsconfig.shared.json", | ||
"compilerOptions": { | ||
"composite": true, | ||
"outDir": "lib", | ||
"rootDir": "src" | ||
}, | ||
"include": [ | ||
"./src/**/*" | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from "../../../shared/vitest.config"; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.