-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't require optional peerDependencies
`@vue/server-renderer` and `@vue/compiler-dom` were both required in the sense that they will throw regardless of whether or not your are using functionality from those libraries if they weren't installed. I don't believe this was intentional, so I have made them optional and they will now only throw if you try to use them and the package isn't available, and will print a more helpful error message when doing so.
- Loading branch information
1 parent
f0001de
commit e0585e4
Showing
4 changed files
with
37 additions
and
2 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
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
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,27 @@ | ||
import { createRequire } from 'module' | ||
|
||
// @ts-ignore - cjs build will complain about import.meta not being allowed, but its not actually used as __filename will be defined for cjs | ||
const file = typeof __filename !== 'undefined' ? __filename : import.meta.url | ||
const require = createRequire(file) | ||
|
||
export function requireOptional(packageName: string): unknown { | ||
try { | ||
return require(packageName) | ||
} catch { | ||
throw new Error( | ||
`The optional peer-dependency ${packageName} is needed for this test and was not found. Please ensure that it has been installed as a dev-dependency and retry.` | ||
) | ||
} | ||
} | ||
|
||
export function requireVueCompilerDom() { | ||
return requireOptional( | ||
'@vue/compiler-dom' | ||
) as typeof import('@vue/compiler-dom') | ||
} | ||
|
||
export function requireVueServerRenderer() { | ||
return requireOptional( | ||
'@vue/server-renderer' | ||
) as typeof import('@vue/server-renderer') | ||
} |