@node-loaders/core
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -17,1 +17,8 @@ export declare const createCheckUrl: (name: string) => string; | ||
export declare const convertUrlDriveLetterToUpperCase: (url: string) => string; | ||
/** | ||
* Resolves a file specifier to a file path | ||
* @param specifier accepts an absolute path, an relative path or and file url | ||
* @param parentURL required for relative specifier, ignored otherwise | ||
* @returns resolved file path | ||
*/ | ||
export declare const specifierToFilePath: (specifier: string, parentURL?: string) => string; |
import { builtinModules } from 'node:module'; | ||
import { isAbsolute } from 'node:path'; | ||
import { dirname, isAbsolute, join } from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
import validateNpmPackageName from 'validate-npm-package-name'; | ||
@@ -42,2 +43,20 @@ const nodeProtocol = 'node:'; | ||
}; | ||
/** | ||
* Resolves a file specifier to a file path | ||
* @param specifier accepts an absolute path, an relative path or and file url | ||
* @param parentURL required for relative specifier, ignored otherwise | ||
* @returns resolved file path | ||
*/ | ||
export const specifierToFilePath = (specifier, parentURL) => { | ||
if (isAbsolute(specifier)) { | ||
return specifier; | ||
} | ||
if (specifier.startsWith('.')) { | ||
if (!parentURL) { | ||
throw new Error(`Error resolving module ${specifier} without a parentUrl`); | ||
} | ||
return join(dirname(fileURLToPath(parentURL)), specifier); | ||
} | ||
return fileURLToPath(specifier); | ||
}; | ||
//# sourceMappingURL=specifier.js.map |
{ | ||
"name": "@node-loaders/core", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"private": false, | ||
@@ -51,3 +51,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "b3b07fa92591c620c422bf3345fdcc600cb19912" | ||
"gitHead": "2839739754eb82b94488fe9e0765cd8623fff860" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44507
632