Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove any querystring from imports #67

Merged
merged 1 commit into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
11 changes: 11 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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?$/, '')
Expand Down
1 change: 1 addition & 0 deletions tests/withQuerystring/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../baseEslintConfig')(__dirname)
3 changes: 3 additions & 0 deletions tests/withQuerystring/image.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions tests/withQuerystring/index.ts
Original file line number Diff line number Diff line change
@@ -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'
3 changes: 3 additions & 0 deletions tests/withQuerystring/subfolder/image.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions tests/withQuerystring/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"compilerOptions": {},
"files": ["index.ts"]
}