Skip to content

Allow only package names as plugin names #42713

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

Merged
merged 4 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/server/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,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(`Skipped 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;
Expand Down
1 change: 1 addition & 0 deletions src/testRunner/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
"unittests/tsserver/openFile.ts",
"unittests/tsserver/packageJsonInfo.ts",
"unittests/tsserver/partialSemanticServer.ts",
"unittests/tsserver/plugins.ts",
"unittests/tsserver/projectErrors.ts",
"unittests/tsserver/projectReferenceCompileOnSave.ts",
"unittests/tsserver/projectReferenceErrors.ts",
Expand Down
50 changes: 50 additions & 0 deletions src/testRunner/unittests/tsserver/plugins.ts
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, { globalPlugins: [...expectedToLoad, ...notToLoad] });
service.openClientFile(aTs.path);
assert.deepEqual(pluginsLoaded, expectedToLoad);
});
});
}