Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
31 changes: 31 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Resolve a relative path against `process.cwd()` (the process's current working directory) and return an absolute path. This will throw if the resulting resolution seems malicious. The following are malicious:
*
* - The relative path is an absolute path
* - The relative path contains a NULL byte
* - The relative path resolves to a path outside of `process.cwd()`
* - The relative path traverses above `process.cwd()` and back down
*
* @param {string} relativePath
* @return {string}
*/
declare function resolvePath(relativePath: string): string;

/**
* Resolve a relative path against the provided root path and return an absolute path. This will throw if the resulting resolution seems malicious. The following are malicious:
*
* - The relative path is an absolute path
* - The relative path contains a NULL byte
* - The relative path resolves to a path outside of the root path
* - The relative path traverses above the root and back down
*
* @param {string} rootPath
* @param {string} relativePath
* @return {string}
*/
declare function resolvePath(rootPath: string, relativePath: string): string;

declare namespace resolvePath {
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this do? Sorry not familiar with typings.

Copy link
Author

Choose a reason for hiding this comment

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

It's for typescript.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, but I mean what exactly does an empty namespace so for typescript?

Copy link
Author

Choose a reason for hiding this comment

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

Removing the empty namespace will raise a type-check error in older version. It seems useless for current version. See the issue microsoft/TypeScript#5073

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, gotcha. I would have never known that, thank you. I would have accepted someone's PR removing it by accident. Can we add a test for this to prevent accidental removal?

Copy link
Author

Choose a reason for hiding this comment

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

How to test?

Copy link
Contributor

Choose a reason for hiding this comment

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

Idk, I'm not familiar with typescript. That's why I'm asking you :) if you're not sure, do you know someone who may be who van come and help out here?

Copy link
Author

Choose a reason for hiding this comment

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

}

export = resolvePath;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@
"resolve",
"path",
"safe"
]
],
"typings": "index.d.ts"
}