vscode-apollo 2.3.1 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/sampleWorkspace/configFileTypes/cjsConfig/apollo.config.cjs +8 -0
- package/sampleWorkspace/configFileTypes/cjsConfig/package.json +4 -0
- package/sampleWorkspace/configFileTypes/cjsConfig/src/test.js +8 -0
- package/sampleWorkspace/configFileTypes/jsConfigWithCJS/apollo.config.js +8 -0
- package/sampleWorkspace/configFileTypes/jsConfigWithCJS/package.json +4 -0
- package/sampleWorkspace/configFileTypes/jsConfigWithCJS/src/test.js +8 -0
- package/sampleWorkspace/configFileTypes/jsConfigWithESM/apollo.config.js +8 -0
- package/sampleWorkspace/configFileTypes/jsConfigWithESM/package.json +4 -0
- package/sampleWorkspace/configFileTypes/jsConfigWithESM/src/test.js +8 -0
- package/sampleWorkspace/configFileTypes/mjsConfig/apollo.config.mjs +8 -0
- package/sampleWorkspace/configFileTypes/mjsConfig/package.json +4 -0
- package/sampleWorkspace/configFileTypes/mjsConfig/src/test.js +8 -0
- package/sampleWorkspace/configFileTypes/tsConfigWithCJS/apollo.config.ts +8 -0
- package/sampleWorkspace/configFileTypes/tsConfigWithCJS/package.json +4 -0
- package/sampleWorkspace/configFileTypes/tsConfigWithCJS/src/test.js +8 -0
- package/sampleWorkspace/configFileTypes/tsConfigWithESM/apollo.config.ts +8 -0
- package/sampleWorkspace/configFileTypes/tsConfigWithESM/package.json +4 -0
- package/sampleWorkspace/configFileTypes/tsConfigWithESM/src/test.js +8 -0
- package/sampleWorkspace/sampleWorkspace.code-workspace +3 -0
- package/src/language-server/__e2e__/configFileTypes.e2e.ts +37 -0
- package/src/language-server/__e2e__/utils.ts +2 -1
- package/src/language-server/config/cache-busting-resolver.js +4 -12
- package/src/language-server/config/cache-busting-resolver.types.ts +1 -1
- package/src/language-server/config/loadTsConfig.ts +33 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 2.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#211](https://github.com/apollographql/vscode-graphql/pull/211) [`9aa1fc1b`](https://github.com/apollographql/vscode-graphql/commit/9aa1fc1b9b419a5e72216f032e64aa5f86f15b59) Thanks [@phryneas](https://github.com/phryneas)! - Avoid detection if .js config file is ESM or CommonJs, just try both.
|
|
8
|
+
|
|
3
9
|
## 2.3.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "vscode-apollo",
|
|
3
3
|
"displayName": "Apollo GraphQL",
|
|
4
4
|
"description": "Rich editor support for GraphQL client and server development that seamlessly integrates with the Apollo platform",
|
|
5
|
-
"version": "2.3.
|
|
5
|
+
"version": "2.3.2",
|
|
6
6
|
"referenceID": "87197759-7617-40d0-b32e-46d378e907c7",
|
|
7
7
|
"author": "Apollo GraphQL <opensource@apollographql.com>",
|
|
8
8
|
"license": "MIT",
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { writeFile } from "fs/promises";
|
|
2
|
+
import {
|
|
3
|
+
reloadService,
|
|
4
|
+
waitForLSP,
|
|
5
|
+
resolveRelativeToSampleWorkspace,
|
|
6
|
+
} from "./utils";
|
|
7
|
+
|
|
8
|
+
test.each([
|
|
9
|
+
["cjsConfig", "commonjs"],
|
|
10
|
+
["cjsConfig", "module"],
|
|
11
|
+
["mjsConfig", "module"],
|
|
12
|
+
["mjsConfig", "commonjs"],
|
|
13
|
+
["jsConfigWithCJS", "commonjs"],
|
|
14
|
+
["jsConfigWithCJS", "module"],
|
|
15
|
+
["jsConfigWithESM", "module"],
|
|
16
|
+
["jsConfigWithESM", "commonjs"],
|
|
17
|
+
["tsConfigWithCJS", "commonjs"],
|
|
18
|
+
["tsConfigWithCJS", "module"],
|
|
19
|
+
["tsConfigWithESM", "module"],
|
|
20
|
+
["tsConfigWithESM", "commonjs"],
|
|
21
|
+
] as const)("%s with `type: '%s'`", async (project, moduleType) => {
|
|
22
|
+
await writeFile(
|
|
23
|
+
resolveRelativeToSampleWorkspace(`configFileTypes/${project}/package.json`),
|
|
24
|
+
JSON.stringify(
|
|
25
|
+
{
|
|
26
|
+
name: "test",
|
|
27
|
+
type: moduleType,
|
|
28
|
+
},
|
|
29
|
+
undefined,
|
|
30
|
+
2,
|
|
31
|
+
),
|
|
32
|
+
"utf-8",
|
|
33
|
+
);
|
|
34
|
+
await reloadService();
|
|
35
|
+
const stats = await waitForLSP(`configFileTypes/${project}/src/test.js`);
|
|
36
|
+
expect(stats.serviceId).toBe(project);
|
|
37
|
+
});
|
|
@@ -7,6 +7,7 @@ import { VSCodeGraphQLExtension } from "src/extension";
|
|
|
7
7
|
function resolve(file: string) {
|
|
8
8
|
return join(__dirname, "..", "..", "..", "sampleWorkspace", file);
|
|
9
9
|
}
|
|
10
|
+
export { resolve as resolveRelativeToSampleWorkspace };
|
|
10
11
|
|
|
11
12
|
export type GetPositionFn = ReturnType<typeof getPositionForEditor>;
|
|
12
13
|
export function getPositionForEditor(editor: vscode.TextEditor) {
|
|
@@ -65,7 +66,7 @@ export function waitForLSP(file: string) {
|
|
|
65
66
|
uri.toString(),
|
|
66
67
|
);
|
|
67
68
|
expect(stats.loaded).toBe(true);
|
|
68
|
-
return stats;
|
|
69
|
+
return stats as ProjectStats & { loaded: true };
|
|
69
70
|
});
|
|
70
71
|
}
|
|
71
72
|
|
|
@@ -24,20 +24,12 @@ async function resolve(specifier, context, nextResolve) {
|
|
|
24
24
|
if (context.importAttributes.as !== "cachebust") {
|
|
25
25
|
return nextResolve(specifier, context);
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
// no need to resolve at all, we have all necessary information
|
|
29
|
-
return {
|
|
30
|
-
url: bustFileName(specifier),
|
|
31
|
-
format: context.importAttributes.format,
|
|
32
|
-
importAttributes: context.importAttributes,
|
|
33
|
-
shortCircuit: true,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
const result = await nextResolve(specifier, context);
|
|
27
|
+
// no need to resolve at all, we have all necessary information
|
|
37
28
|
return {
|
|
38
|
-
|
|
39
|
-
|
|
29
|
+
url: bustFileName(specifier),
|
|
30
|
+
format: context.importAttributes.format,
|
|
40
31
|
importAttributes: context.importAttributes,
|
|
32
|
+
shortCircuit: true,
|
|
41
33
|
};
|
|
42
34
|
}
|
|
43
35
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Loader } from "cosmiconfig";
|
|
2
|
-
import { dirname } from "node:path";
|
|
2
|
+
import { dirname, extname } from "node:path";
|
|
3
3
|
import typescript from "typescript";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
5
|
import { register } from "node:module";
|
|
@@ -59,19 +59,7 @@ async function load(
|
|
|
59
59
|
error.message = `TypeScript Error in ${filepath}:\n${error.message}`;
|
|
60
60
|
throw error;
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
const imported = await import(
|
|
64
|
-
filepath,
|
|
65
|
-
//@ts-ignore
|
|
66
|
-
{
|
|
67
|
-
with: {
|
|
68
|
-
as: "cachebust",
|
|
69
|
-
contents: transpiledContent,
|
|
70
|
-
format: type,
|
|
71
|
-
} satisfies ImportAttributes,
|
|
72
|
-
}
|
|
73
|
-
);
|
|
74
|
-
return imported.default;
|
|
62
|
+
return loadCachebustedJs(filepath, transpiledContent, type);
|
|
75
63
|
}
|
|
76
64
|
|
|
77
65
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -92,15 +80,44 @@ function resolveTsConfig(directory: string): any {
|
|
|
92
80
|
}
|
|
93
81
|
|
|
94
82
|
export const loadJs: Loader = async function loadJs(filepath, contents) {
|
|
83
|
+
const extension = extname(filepath);
|
|
84
|
+
if (extension === ".mjs") {
|
|
85
|
+
return loadCachebustedJs(filepath, contents, "module");
|
|
86
|
+
}
|
|
87
|
+
if (extension === ".cjs") {
|
|
88
|
+
return loadCachebustedJs(filepath, contents, "commonjs");
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
return await loadCachebustedJs(filepath, contents, "module");
|
|
92
|
+
} catch (error) {
|
|
93
|
+
if (
|
|
94
|
+
error instanceof Error &&
|
|
95
|
+
// [ERROR] ReferenceError: module is not defined in ES module scope
|
|
96
|
+
error.message.includes("module is not defined")
|
|
97
|
+
) {
|
|
98
|
+
return loadCachebustedJs(filepath, contents, "commonjs");
|
|
99
|
+
} else {
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
async function loadCachebustedJs(
|
|
106
|
+
filename: string,
|
|
107
|
+
contents: string,
|
|
108
|
+
type: "module" | "commonjs",
|
|
109
|
+
) {
|
|
95
110
|
return (
|
|
96
111
|
await import(
|
|
97
|
-
|
|
112
|
+
filename,
|
|
113
|
+
// @ts-ignore
|
|
98
114
|
{
|
|
99
115
|
with: {
|
|
100
116
|
as: "cachebust",
|
|
101
117
|
contents,
|
|
118
|
+
format: type,
|
|
102
119
|
} satisfies ImportAttributes,
|
|
103
120
|
}
|
|
104
121
|
)
|
|
105
122
|
).default;
|
|
106
|
-
}
|
|
123
|
+
}
|