-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow only package names as plugin names
- Loading branch information
1 parent
2ae8d9f
commit 2be3fd8
Showing
3 changed files
with
55 additions
and
0 deletions.
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
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,50 @@ | ||
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 })) } | ||
}) | ||
}; | ||
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); | ||
}); | ||
}); | ||
} |