Skip to content

Commit

Permalink
Support import.meta.resolve (resolves #642)
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Jun 12, 2024
1 parent 2ec5189 commit 177baa2
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
Empty file.
4 changes: 4 additions & 0 deletions packages/knip/fixtures/imports/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ const templateStringInternal = () => {
return import('./dir/mod');
};

const importMetaResolve = () => {
return import.meta.resolve('./import-meta-resolve.js');
};

function promiseAll() {
return {
async fn() {
Expand Down
3 changes: 2 additions & 1 deletion packages/knip/fixtures/imports/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"compilerOptions": {
"types": ["node"],
"esModuleInterop": true
"esModuleInterop": true,
"module": "nodenext"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { importVisitor as visit } from '../index.js';
export default visit(
() => true,
node => {
if (isPropertyAccessCall(node, 'require.resolve')) {
if (isPropertyAccessCall(node, 'require.resolve') || isPropertyAccessCall(node, 'import.meta.resolve')) {
// Pattern: require.resolve('specifier')
if (node.arguments[0] && ts.isStringLiteralLike(node.arguments[0])) {
const specifier = node.arguments[0].text;
Expand Down
4 changes: 2 additions & 2 deletions packages/knip/test/imports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test('Support various ways to import modules', async () => {

assert.deepEqual(counters, {
...baseCounters,
processed: 22,
total: 22,
processed: 23,
total: 23,
});
});

0 comments on commit 177baa2

Please sign in to comment.