-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update implementation to throw errors
- Loading branch information
Showing
8 changed files
with
207 additions
and
123 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'resolve.imports': major | ||
--- | ||
|
||
Throwing errors as in Node.js implementation. | ||
|
||
The API have changed to receive a manifest object so that it can throw errors as in Node.js. |
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 |
---|---|---|
|
@@ -41,6 +41,7 @@ | |
"cjs", | ||
"esm", | ||
"ts", | ||
"!**/testutils", | ||
"!cjs/**/*.d.ts", | ||
"!**/*.test.*", | ||
"!**/*.spec.*", | ||
|
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,29 @@ | ||
export const ERR_INVALID_MODULE_SPECIFIER = createErrorType( | ||
`ERR_INVALID_MODULE_SPECIFIER`, | ||
(request, reason, base = undefined) => `Invalid module "${request}" ${reason}${base ? ` imported from ${base}` : ``}`, | ||
TypeError | ||
) | ||
|
||
export const ERR_PACKAGE_IMPORT_NOT_DEFINED = createErrorType( | ||
'ERR_PACKAGE_IMPORT_NOT_DEFINED', | ||
(specifier: string, packagePath?: string, base?: string) => `Package import specifier "${specifier}" is not defined${packagePath | ||
? ` in package ${packagePath}package.json` | ||
: '' | ||
}${base ? ` imported from ${base}` : ``}`, | ||
TypeError | ||
) | ||
|
||
function createErrorType(code: string, messageCreator: (...args: any[]) => string, errorType: new (...args: any[]) => Error) { | ||
return class extends errorType { | ||
code: string | ||
constructor(...args: any[]) { | ||
super(messageCreator(...args)) | ||
this.code = code | ||
this.name = `${errorType.name} [${code}]` | ||
} | ||
} | ||
} | ||
|
||
export function assert(condition: boolean, message?: string) { | ||
if (!condition) throw new Error(message) | ||
} |
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
Oops, something went wrong.