ts-prune
ts-prune copied to clipboard
[BUG] Error message on file parse failures doesn't include file name
Describe the bug
This is the start of the error stack you get for running ts-prune
on a file that includes invalid module syntax:
$ yarn ts-prune --project tsconfig.base.json
yarn run v1.22.19
$ /path/to/repo/node_modules/.bin/ts-prune --project tsconfig.base.json
/path/to/repo/node_modules/ts-morph/dist/ts-morph.js:12305
throw new common.errors.InvalidOperationError("Expected the module specifier to be a string literal.");
^
InvalidOperationError: Expected the module specifier to be a string literal.
at ImportDeclaration.getModuleSpecifier (/path/to/repo/node_modules/ts-morph/dist/ts-morph.js:12305:19)
at ImportDeclaration.getModuleSpecifierSourceFile (/path/to/repo/node_modules/ts-morph/dist/ts-morph.js:12316:29)
at Object.getModuleSourceFile (/path/to/repo/node_modules/ts-prune/lib/util/getModuleSourceFile.js:4:81)
at /path/to/repo/node_modules/ts-prune/lib/analyzer.js:133:49
at Array.map (<anonymous>)
at ...
To Reproduce
- Create a file with contents like
import { {{ a }} } from "./b";
- Run
ts-prune
on a project including that file
Expected behavior
ts-prune
should mention which file is crashing when an error is thrown. Maybe like...
$ yarn ts-prune --project tsconfig.base.json
yarn run v1.22.19
$ /path/to/repo/node_modules/.bin/ts-prune --project tsconfig.base.json
Error running ts-prune on file /path/to/repo/path/to/file.ts!
/path/to/repo/node_modules/ts-morph/dist/ts-morph.js:12305
throw new common.errors.InvalidOperationError("Expected the module specifier to be a string literal.");
^
InvalidOperationError: Expected the module specifier to be a string literal.
at ImportDeclaration.getModuleSpecifier (/path/to/repo/node_modules/ts-morph/dist/ts-morph.js:12305:19)
at ImportDeclaration.getModuleSpecifierSourceFile (/path/to/repo/node_modules/ts-morph/dist/ts-morph.js:12316:29)
at Object.getModuleSourceFile (/path/to/repo/node_modules/ts-prune/lib/util/getModuleSourceFile.js:4:81)
at /path/to/repo/node_modules/ts-prune/lib/analyzer.js:133:49
at Array.map (<anonymous>)
at ...
Additional context
I found this by accidentally running ts-prune
on some mustache templates used to generate .ts
files. Including file name
Stale issue message