Skip to content

Commit 04e7498

Browse files
committed
Exclude extension in module names
1 parent d0a5ebf commit 04e7498

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 3.0.2 (2024-10-15)
2+
3+
- Do not include the file extension in derived module names.
4+
15
### 3.0.1 (2024-10-15)
26

37
- Fixed an issue where modules could be created by this plugin with names

index.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ export function load(app: Application) {
136136
const symbol = context.project.getSymbolFromReflection(refl);
137137
const file = symbol?.declarations?.find(ts.isSourceFile);
138138
if (file && /^".*"$/.test(refl.name)) {
139-
refl.name = relative(
140-
app.options.getValue("basePath") || process.cwd(),
139+
refl.name = getModuleName(
141140
file.fileName,
142-
).replace(/\\/g, "/");
141+
app.options.getValue("basePath") || process.cwd(),
142+
);
143143
}
144144
},
145145
);
@@ -267,3 +267,9 @@ function shouldConvertSymbol(symbol: ts.Symbol, checker: ts.TypeChecker) {
267267

268268
return true;
269269
}
270+
271+
function getModuleName(fileName: string, baseDir: string) {
272+
return relative(baseDir, fileName)
273+
.replace(/\\/g, "/")
274+
.replace(/(\/index)?(\.d)?\.([cm]?[tj]s|[tj]sx?)$/, "");
275+
}

test/packages.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ test("Issue #12", () => {
166166

167167
const hierarchy = outdent`
168168
Module <internal>
169-
Namespace test/packages/gh12/mod.ts
169+
Namespace test/packages/gh12/mod
170170
Variable ReferencesModule
171171
`;
172172

@@ -177,7 +177,7 @@ test("Issue #12", () => {
177177

178178
const hierarchy2 = outdent`
179179
Module <internal>
180-
Namespace gh12/mod.ts
180+
Namespace gh12/mod
181181
Variable ReferencesModule
182182
`;
183183

0 commit comments

Comments
 (0)