fix(ext/node): allow absolute path in createRequire (#16853)

Co-authored-by: David Sherret <dsherret@gmail.com>
This commit is contained in:
Yoshiya Hinosawa 2022-11-29 14:13:14 +09:00 committed by GitHub
parent d3299c2d6c
commit e4fe5ee72a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 37 additions and 3 deletions

View file

@ -1,6 +1,12 @@
[WILDCARD]
function
function
function
function
function
function
The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received https://example.com/
The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received https://example.com/
The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received 1
The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received foo
The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received ./foo

View file

@ -2,6 +2,10 @@ import { createRequire } from "module";
console.log(typeof createRequire(import.meta.url));
console.log(typeof createRequire(new URL(import.meta.url)));
console.log(typeof createRequire("/"));
console.log(typeof createRequire("/foo"));
console.log(typeof createRequire("/foo/"));
console.log(typeof createRequire("c:\\foo"));
try {
createRequire("https://example.com/");
} catch (e) {
@ -17,3 +21,13 @@ try {
} catch (e) {
console.log(e.message);
}
try {
createRequire("foo");
} catch (e) {
console.log(e.message);
}
try {
createRequire("./foo");
} catch (e) {
console.log(e.message);
}