/
plugins.ts
55 lines (53 loc) · 2.52 KB
/
plugins.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
namespace ts.projectSystem {
describe("unittests:: tsserver:: plugins loading", () => {
function createHostWithPlugin(files: readonly File[]) {
const host = createServerHost(files);
const pluginsLoaded: string[] = [];
host.require = (_initialPath, moduleName) => {
pluginsLoaded.push(moduleName);
return {
module: () => ({
create(info: server.PluginCreateInfo) {
return Harness.LanguageService.makeDefaultProxy(info);
}
}),
error: undefined
};
};
return { host, pluginsLoaded };
}
it("With local plugins", () => {
const expectedToLoad = ["@myscoped/plugin", "unscopedPlugin"];
const notToLoad = ["../myPlugin", "myPlugin/../malicious"];
const aTs: File = { path: "/a.ts", content: `class c { prop = "hello"; foo() { return this.prop; } }` };
const tsconfig: File = {
path: "/tsconfig.json",
content: JSON.stringify({
compilerOptions: {
plugins: [
...[...expectedToLoad, ...notToLoad].map(name => ({ name })),
{ transform: "some-transform" }
]
}
})
};
const { host, pluginsLoaded } = createHostWithPlugin([aTs, tsconfig, libFile]);
const service = createProjectService(host);
service.openClientFile(aTs.path);
assert.deepEqual(pluginsLoaded, expectedToLoad);
});
it("With global plugins", () => {
const expectedToLoad = ["@myscoped/plugin", "unscopedPlugin"];
const notToLoad = ["../myPlugin", "myPlugin/../malicious"];
const aTs: File = { path: "/a.ts", content: `class c { prop = "hello"; foo() { return this.prop; } }` };
const tsconfig: File = {
path: "/tsconfig.json",
content: "{}"
};
const { host, pluginsLoaded } = createHostWithPlugin([aTs, tsconfig, libFile]);
const service = createProjectService(host, /*parameters*/ undefined, { globalPlugins: [...expectedToLoad, ...notToLoad] });
service.openClientFile(aTs.path);
assert.deepEqual(pluginsLoaded, expectedToLoad);
});
});
}