Skip to content

Commit 82ef357

Browse files
authored
feat: remove any querystring from imports (#67)
1 parent 2029cae commit 82ef357

File tree

7 files changed

+30
-0
lines changed

7 files changed

+30
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"test:multipleTsconfigs": "eslint --ext ts,tsx tests/multipleTsconfigs",
4343
"test:withJsExtension": "node tests/withJsExtension/test.js && eslint --ext ts,tsx tests/withJsExtension",
4444
"test:withPaths": "eslint --ext ts,tsx tests/withPaths",
45+
"test:withQuerystring": "eslint --ext ts,tsx tests/withQuerystring",
4546
"test:withoutPaths": "eslint --ext ts,tsx tests/withoutPaths",
4647
"type-coverage": "type-coverage --cache --detail --ignore-catch --strict --update"
4748
},

src/index.ts

+11
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export function resolve(
5151

5252
log('looking for:', source)
5353

54+
source = removeQuerystring(source)
55+
5456
// don't worry about core node modules
5557
if (isCore(source)) {
5658
log('matched core:', source)
@@ -136,6 +138,15 @@ function tsResolve(id: string, opts?: SyncOpts): string {
136138
}
137139
}
138140

141+
/** Remove any trailing querystring from module id. */
142+
function removeQuerystring(id: string) {
143+
const querystringIndex = id.lastIndexOf('?')
144+
if (querystringIndex >= 0) {
145+
return id.slice(0, querystringIndex)
146+
}
147+
return id
148+
}
149+
139150
/** Remove .js or .jsx extension from module id. */
140151
function removeJsExtension(id: string) {
141152
return id.replace(/\.jsx?$/, '')

tests/withQuerystring/.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('../baseEslintConfig')(__dirname)

tests/withQuerystring/image.svg

+3
Loading

tests/withQuerystring/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// import svg without querystring
2+
import './image.svg'
3+
import './subfolder/image.svg'
4+
5+
// import svg with querystring
6+
import './image.svg?raw'
7+
import './subfolder/image.svg?raw'
Loading

tests/withQuerystring/tsconfig.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"compilerOptions": {},
3+
"files": ["index.ts"]
4+
}

0 commit comments

Comments
 (0)