-
Notifications
You must be signed in to change notification settings - Fork 21
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
Avoid detection if .js config file is ESM or CommonJs, just try both. #211
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"vscode-apollo": patch | ||
--- | ||
|
||
Avoid detection if .js config file is ESM or CommonJs, just try both. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
client: { | ||
service: { | ||
name: "cjsConfig", | ||
localSchemaFile: "./starwarsSchema.graphql", | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "test", | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import gql from "graphql-tag"; | ||
gql` | ||
query Test { | ||
droid(id: "2000") { | ||
name | ||
} | ||
} | ||
`; |
1 change: 1 addition & 0 deletions
1
sampleWorkspace/configFileTypes/cjsConfig/starwarsSchema.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../fixtures/starwarsSchema.graphql |
8 changes: 8 additions & 0 deletions
8
sampleWorkspace/configFileTypes/jsConfigWithCJS/apollo.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
client: { | ||
service: { | ||
name: "jsConfigWithCJS", | ||
localSchemaFile: "./starwarsSchema.graphql", | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "test", | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import gql from "graphql-tag"; | ||
gql` | ||
query Test { | ||
droid(id: "2000") { | ||
name | ||
} | ||
} | ||
`; |
1 change: 1 addition & 0 deletions
1
sampleWorkspace/configFileTypes/jsConfigWithCJS/starwarsSchema.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../fixtures/starwarsSchema.graphql |
8 changes: 8 additions & 0 deletions
8
sampleWorkspace/configFileTypes/jsConfigWithESM/apollo.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default { | ||
client: { | ||
service: { | ||
name: "jsConfigWithESM", | ||
localSchemaFile: "./starwarsSchema.graphql", | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "test", | ||
"type": "commonjs" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import gql from "graphql-tag"; | ||
gql` | ||
query Test { | ||
droid(id: "2000") { | ||
name | ||
} | ||
} | ||
`; |
1 change: 1 addition & 0 deletions
1
sampleWorkspace/configFileTypes/jsConfigWithESM/starwarsSchema.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../fixtures/starwarsSchema.graphql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default { | ||
client: { | ||
service: { | ||
name: "mjsConfig", | ||
localSchemaFile: "./starwarsSchema.graphql", | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "test", | ||
"type": "commonjs" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import gql from "graphql-tag"; | ||
gql` | ||
query Test { | ||
droid(id: "2000") { | ||
name | ||
} | ||
} | ||
`; |
1 change: 1 addition & 0 deletions
1
sampleWorkspace/configFileTypes/mjsConfig/starwarsSchema.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../fixtures/starwarsSchema.graphql |
8 changes: 8 additions & 0 deletions
8
sampleWorkspace/configFileTypes/tsConfigWithCJS/apollo.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
client: { | ||
service: { | ||
name: "tsConfigWithCJS", | ||
localSchemaFile: "./starwarsSchema.graphql", | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "test", | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import gql from "graphql-tag"; | ||
gql` | ||
query Test { | ||
droid(id: "2000") { | ||
name | ||
} | ||
} | ||
`; |
1 change: 1 addition & 0 deletions
1
sampleWorkspace/configFileTypes/tsConfigWithCJS/starwarsSchema.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../fixtures/starwarsSchema.graphql |
8 changes: 8 additions & 0 deletions
8
sampleWorkspace/configFileTypes/tsConfigWithESM/apollo.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default { | ||
client: { | ||
service: { | ||
name: "tsConfigWithESM", | ||
localSchemaFile: "./starwarsSchema.graphql", | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "test", | ||
"type": "commonjs" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import gql from "graphql-tag"; | ||
gql` | ||
query Test { | ||
droid(id: "2000") { | ||
name | ||
} | ||
} | ||
`; |
1 change: 1 addition & 0 deletions
1
sampleWorkspace/configFileTypes/tsConfigWithESM/starwarsSchema.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../fixtures/starwarsSchema.graphql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { writeFile } from "fs/promises"; | ||
import { | ||
reloadService, | ||
waitForLSP, | ||
resolveRelativeToSampleWorkspace, | ||
} from "./utils"; | ||
|
||
test.each([ | ||
["cjsConfig", "commonjs"], | ||
["cjsConfig", "module"], | ||
["mjsConfig", "module"], | ||
["mjsConfig", "commonjs"], | ||
["jsConfigWithCJS", "commonjs"], | ||
["jsConfigWithCJS", "module"], | ||
["jsConfigWithESM", "module"], | ||
["jsConfigWithESM", "commonjs"], | ||
["tsConfigWithCJS", "commonjs"], | ||
["tsConfigWithCJS", "module"], | ||
["tsConfigWithESM", "module"], | ||
["tsConfigWithESM", "commonjs"], | ||
] as const)("%s with `type: '%s'`", async (project, moduleType) => { | ||
await writeFile( | ||
resolveRelativeToSampleWorkspace(`configFileTypes/${project}/package.json`), | ||
JSON.stringify( | ||
{ | ||
name: "test", | ||
type: moduleType, | ||
}, | ||
undefined, | ||
2, | ||
), | ||
"utf-8", | ||
); | ||
await reloadService(); | ||
const stats = await waitForLSP(`configFileTypes/${project}/src/test.js`); | ||
expect(stats.serviceId).toBe(project); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,20 +24,12 @@ async function resolve(specifier, context, nextResolve) { | |
if (context.importAttributes.as !== "cachebust") { | ||
return nextResolve(specifier, context); | ||
} | ||
if (context.importAttributes.format) { | ||
// no need to resolve at all, we have all necessary information | ||
return { | ||
url: bustFileName(specifier), | ||
format: context.importAttributes.format, | ||
importAttributes: context.importAttributes, | ||
shortCircuit: true, | ||
}; | ||
} | ||
const result = await nextResolve(specifier, context); | ||
// no need to resolve at all, we have all necessary information | ||
return { | ||
...result, | ||
url: bustFileName(result.url), | ||
url: bustFileName(specifier), | ||
format: context.importAttributes.format, | ||
importAttributes: context.importAttributes, | ||
shortCircuit: true, | ||
Comment on lines
+29
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't trust the original detection algorithm at all anymore, |
||
}; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deliberately specifying the opposite here - the config file is
.js
with ESM contents, the package here hastype: commonjs
, we still want it to work.The E2E tests will try all possible combinations on top.