diff --git a/package.json b/package.json index b198940..f2d7695 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "test:multipleTsconfigs": "eslint --ext ts,tsx tests/multipleTsconfigs", "test:withJsExtension": "node tests/withJsExtension/test.js && eslint --ext ts,tsx tests/withJsExtension", "test:withPaths": "eslint --ext ts,tsx tests/withPaths", + "test:withQuerystring": "eslint --ext ts,tsx tests/withQuerystring", "test:withoutPaths": "eslint --ext ts,tsx tests/withoutPaths", "type-coverage": "type-coverage --cache --detail --ignore-catch --strict --update" }, diff --git a/src/index.ts b/src/index.ts index 89ee9a4..fe63fdb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -51,6 +51,8 @@ export function resolve( log('looking for:', source) + source = removeQuerystring(source) + // don't worry about core node modules if (isCore(source)) { log('matched core:', source) @@ -136,6 +138,15 @@ function tsResolve(id: string, opts?: SyncOpts): string { } } +/** Remove any trailing querystring from module id. */ +function removeQuerystring(id: string) { + const querystringIndex = id.lastIndexOf('?') + if (querystringIndex >= 0) { + return id.slice(0, querystringIndex) + } + return id +} + /** Remove .js or .jsx extension from module id. */ function removeJsExtension(id: string) { return id.replace(/\.jsx?$/, '') diff --git a/tests/withQuerystring/.eslintrc.js b/tests/withQuerystring/.eslintrc.js new file mode 100644 index 0000000..cc90fb8 --- /dev/null +++ b/tests/withQuerystring/.eslintrc.js @@ -0,0 +1 @@ +module.exports = require('../baseEslintConfig')(__dirname) diff --git a/tests/withQuerystring/image.svg b/tests/withQuerystring/image.svg new file mode 100644 index 0000000..582f744 --- /dev/null +++ b/tests/withQuerystring/image.svg @@ -0,0 +1,3 @@ + + + diff --git a/tests/withQuerystring/index.ts b/tests/withQuerystring/index.ts new file mode 100644 index 0000000..cd73fdb --- /dev/null +++ b/tests/withQuerystring/index.ts @@ -0,0 +1,7 @@ +// import svg without querystring +import './image.svg' +import './subfolder/image.svg' + +// import svg with querystring +import './image.svg?raw' +import './subfolder/image.svg?raw' diff --git a/tests/withQuerystring/subfolder/image.svg b/tests/withQuerystring/subfolder/image.svg new file mode 100644 index 0000000..582f744 --- /dev/null +++ b/tests/withQuerystring/subfolder/image.svg @@ -0,0 +1,3 @@ + + + diff --git a/tests/withQuerystring/tsconfig.json b/tests/withQuerystring/tsconfig.json new file mode 100644 index 0000000..abdb5af --- /dev/null +++ b/tests/withQuerystring/tsconfig.json @@ -0,0 +1,4 @@ +{ + "compilerOptions": {}, + "files": ["index.ts"] +}