mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 20:14:01 -06:00
Allow only package names as plugin names
This commit is contained in:
parent
2ae8d9f7e7
commit
2be3fd8863
@ -1383,6 +1383,10 @@ namespace ts.server {
|
||||
|
||||
protected enablePlugin(pluginConfigEntry: PluginImport, searchPaths: string[], pluginConfigOverrides: Map<any> | undefined) {
|
||||
this.projectService.logger.info(`Enabling plugin ${pluginConfigEntry.name} from candidate paths: ${searchPaths.join(",")}`);
|
||||
if (parsePackageName(pluginConfigEntry.name).rest) {
|
||||
this.projectService.logger.info(`kipped loading plugin ${pluginConfigEntry.name} because only package name is allowed plugin name`);
|
||||
return;
|
||||
}
|
||||
|
||||
const log = (message: string) => this.projectService.logger.info(message);
|
||||
let errorLogs: string[] | undefined;
|
||||
|
||||
@ -155,6 +155,7 @@
|
||||
"unittests/tsserver/occurences.ts",
|
||||
"unittests/tsserver/openFile.ts",
|
||||
"unittests/tsserver/packageJsonInfo.ts",
|
||||
"unittests/tsserver/plugins.ts",
|
||||
"unittests/tsserver/projectErrors.ts",
|
||||
"unittests/tsserver/projectReferenceCompileOnSave.ts",
|
||||
"unittests/tsserver/projectReferenceErrors.ts",
|
||||
|
||||
50
src/testRunner/unittests/tsserver/plugins.ts
Normal file
50
src/testRunner/unittests/tsserver/plugins.ts
Normal file
@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user