Skip to content

Commit bf6548b

Browse files
ljy-1351claude
andauthored
fix(plugins): filter .d.mts and .d.cts declaration files in extension discovery (#107994)
* fix(plugins): filter .d.mts and .d.cts declaration files in extension discovery isExtensionFile only checked for .d.ts but not .d.mts or .d.cts. path.extname('.d.mts') returns '.mts' so these declaration files passed through all checks and were treated as valid plugin entries. Replaced the single .d.ts check with a regex covering all TS declaration file variants. Co-Authored-By: Claude <[email protected]> * fix: update d.mts test to use distinct filenames so it fails on old code --------- Co-authored-by: Claude <[email protected]>
1 parent 618f329 commit bf6548b

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎src/plugins/discovery.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,30 @@ describe("discoverOpenClawPlugins", () => {
508508
expect(diagnostics).toStrictEqual([]);
509509
});
510510

511+
it("ignores TypeScript declaration files (.d.ts, .d.mts, .d.cts) in extension roots", async () => {
512+
const stateDir = makeTempDir();
513+
const workspaceDir = path.join(stateDir, "workspace");
514+
const globalExt = path.join(stateDir, "extensions");
515+
mkdirSafe(globalExt);
516+
517+
fs.writeFileSync(path.join(globalExt, "alpha.d.ts"), "export type Foo = string;", "utf-8");
518+
fs.writeFileSync(path.join(globalExt, "bravo.d.mts"), "export type Bar = number;", "utf-8");
519+
fs.writeFileSync(path.join(globalExt, "charlie.d.cts"), "export type Baz = boolean;", "utf-8");
520+
fs.writeFileSync(path.join(globalExt, "delta.mts"), "export default {};", "utf-8");
521+
fs.writeFileSync(path.join(globalExt, "echo.cts"), "export default {};", "utf-8");
522+
523+
const { candidates, diagnostics } = await discoverWithStateDir(stateDir, {
524+
workspaceDir,
525+
extraPaths: [globalExt],
526+
});
527+
528+
expectCandidateIds(candidates, {
529+
includes: ["delta", "echo"],
530+
excludes: ["alpha.d", "bravo.d", "charlie.d"],
531+
});
532+
expect(diagnostics).toStrictEqual([]);
533+
});
534+
511535
it("warns without blocking when a plugin requires a missing plugin", async () => {
512536
const stateDir = makeTempDir();
513537
const pluginDir = path.join(stateDir, "extensions", "diffs-language-pack");

‎src/plugins/discovery.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ function isExtensionFile(filePath: string): boolean {
303303
if (!EXTENSION_EXTS.has(ext)) {
304304
return false;
305305
}
306-
if (filePath.endsWith(".d.ts")) {
306+
if (/\.d\.[cm]?ts$/.test(filePath)) {
307307
return false;
308308
}
309309
const baseName = normalizeLowercaseStringOrEmpty(path.basename(filePath));

0 commit comments

Comments
 (0)