Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/Jakets.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions lib/Jakets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ export * from "./task/Helpers";
export * from "./Exec";
export * from "./Log";
export {
MakeRelativeToWorkingDir,
CreateMakeRelative,
LocalDir,
BuildDir,
CreateMakeRelative,
CurrentPackageJson,
CurrentPackageName,
CurrentPackageVersion,
IsWorkingDir,
LoadJson,
LocalDir,
MakeRelativeToBaseDir,
MakeRelativeToWorkingDir,
NodeModulesUpdateIndicator,
LoadJson,
IsWorkingDir
PathResolverFrom,
} from "./Util";

export * from "./Command";

export * from "./Dedup";
export * from "./Dedup";
26 changes: 21 additions & 5 deletions lib/Util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 21 additions & 4 deletions lib/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ export function MakeRelativeToBaseDir(baseDir: string, fullpath: string): string
}
return Path.relative(baseDir, fullpath)
.replace(/\\/g, "/") //Convert \ to / on windows
|| '.' //in case the answer is empty
|| "." //in case the answer is empty
;
// return path.relative(LocalDir, fullpath) || '.';
}

export function MakeRelativeToWorkingDir(fullpath: string): string {
Expand All @@ -31,10 +30,28 @@ export function IsWorkingDir(dirname: string): boolean {
return MakeRelativeToWorkingDir(dirname) === MakeRelativeToWorkingDir(LocalDir);
}

export function CreateMakeRelative(dirname: string) {
return (path: string) => MakeRelativeToWorkingDir(Path.isAbsolute(path) ? path : Path.join(dirname, path));
/**
* Returns a function that resolves a filepath relative to the
* given dirname.
*
* For example, say the file /my/proj/subdir/Example.ts has:
*
* const Here = PathResolverFrom(__dirname);
* console.log(Here("child/item"));
*
* The intent is to refer to /my/proj/subdir/child/item, and if
* you run subdir/Example.ts from cwd /my/proj, it will print
*
* subdir/child/file
*/
export function PathResolverFrom(dirname: string): (path: string) => string {
return (path: string) =>
MakeRelativeToWorkingDir(Path.resolve(dirname, path));
}

/** Deprecated, use PathResolverFrom */
export const CreateMakeRelative = PathResolverFrom;

export const NodeModulesUpdateIndicator = MakeRelativeToWorkingDir("node_modules/.node_modules_updated");

export const JaketsDir = MakeRelativeToWorkingDir(__dirname.replace("bootstrap", ""));
Expand Down
Loading