Skip to content

Commit

Permalink
fix(cli): handle missing dependencies correctly (#4818)
Browse files Browse the repository at this point in the history
* fix(cli): handle missing dependencies correctly

* chore: changeset

* test: update check for missing dependency
  • Loading branch information
merceyz committed Sep 29, 2020
1 parent ef0e7c4 commit 2900ee2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/twenty-dingos-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-codegen/cli': patch
---

Check the error code instead of the error message to determine if a package wasn't found
2 changes: 1 addition & 1 deletion packages/graphql-codegen-cli/src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export async function getPluginByName(
try {
return await pluginLoader(moduleName);
} catch (err) {
if (err.message.indexOf(`Cannot find module '${moduleName}'`) === -1) {
if (err.code !== 'MODULE_NOT_FOUND') {
throw new DetailedError(
`Unable to load template plugin matching ${name}`,
`
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-codegen-cli/src/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function getPresetByName(

return loaded as Types.OutputPreset;
} catch (err) {
if (err.message.indexOf(`Cannot find module '${moduleName}'`) === -1) {
if (err.code !== 'MODULE_NOT_FOUND') {
throw new DetailedError(
`Unable to load preset matching ${name}`,
`
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-codegen-cli/tests/cli-flags.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ describe('CLI Flags', () => {
await createContext(parseArgv(args));
expect(true).toBeFalsy();
} catch (e) {
expect(e.message).toContain(`Cannot find module 'my-extension'`);
expect(e.code).toEqual('MODULE_NOT_FOUND');
}
});
});

0 comments on commit 2900ee2

Please sign in to comment.