Skip to content

Commit 2900ee2

Browse files
authoredSep 29, 2020
fix(cli): handle missing dependencies correctly (#4818)
* fix(cli): handle missing dependencies correctly * chore: changeset * test: update check for missing dependency
1 parent ef0e7c4 commit 2900ee2

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed
 

‎.changeset/twenty-dingos-remain.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-codegen/cli': patch
3+
---
4+
5+
Check the error code instead of the error message to determine if a package wasn't found

‎packages/graphql-codegen-cli/src/plugins.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export async function getPluginByName(
2222
try {
2323
return await pluginLoader(moduleName);
2424
} catch (err) {
25-
if (err.message.indexOf(`Cannot find module '${moduleName}'`) === -1) {
25+
if (err.code !== 'MODULE_NOT_FOUND') {
2626
throw new DetailedError(
2727
`Unable to load template plugin matching ${name}`,
2828
`

‎packages/graphql-codegen-cli/src/presets.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export async function getPresetByName(
1818

1919
return loaded as Types.OutputPreset;
2020
} catch (err) {
21-
if (err.message.indexOf(`Cannot find module '${moduleName}'`) === -1) {
21+
if (err.code !== 'MODULE_NOT_FOUND') {
2222
throw new DetailedError(
2323
`Unable to load preset matching ${name}`,
2424
`

‎packages/graphql-codegen-cli/tests/cli-flags.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ describe('CLI Flags', () => {
192192
await createContext(parseArgv(args));
193193
expect(true).toBeFalsy();
194194
} catch (e) {
195-
expect(e.message).toContain(`Cannot find module 'my-extension'`);
195+
expect(e.code).toEqual('MODULE_NOT_FOUND');
196196
}
197197
});
198198
});

0 commit comments

Comments
 (0)
Please sign in to comment.