Skip to content

Commit

Permalink
fix: don't throw when typescript can't be resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaStevens committed Aug 7, 2024
1 parent 542b305 commit afb05bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/utils/conditional-imports/ts-api-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ const require = createRequire(import.meta.url);

export default (typescript === undefined
? undefined
: require("ts-api-utils")) as typeof tsApiUtils | undefined;
: (() => {
try {
return require("ts-api-utils");
} catch {
return undefined;
}
})()) as typeof tsApiUtils | undefined;

// export default (await (() => {
// if (ts !== undefined) {
Expand Down
8 changes: 7 additions & 1 deletion src/utils/conditional-imports/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import type typescript from "typescript";

const require = createRequire(import.meta.url);

export default require("typescript") as typeof typescript | undefined;
export default (() => {
try {
return require("typescript");
} catch {
return undefined;
}
})() as typeof typescript | undefined;

// export default (await import("typescript")
// .then((r) => r.default)
Expand Down

0 comments on commit afb05bd

Please sign in to comment.