Skip to content

Commit

Permalink
Exclude extension in module names
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit0 committed Nov 15, 2024
1 parent d0a5ebf commit 04e7498
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 3.0.2 (2024-10-15)

- Do not include the file extension in derived module names.

### 3.0.1 (2024-10-15)

- Fixed an issue where modules could be created by this plugin with names
Expand Down
12 changes: 9 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ export function load(app: Application) {
const symbol = context.project.getSymbolFromReflection(refl);
const file = symbol?.declarations?.find(ts.isSourceFile);
if (file && /^".*"$/.test(refl.name)) {
refl.name = relative(
app.options.getValue("basePath") || process.cwd(),
refl.name = getModuleName(
file.fileName,
).replace(/\\/g, "/");
app.options.getValue("basePath") || process.cwd(),
);
}
},
);
Expand Down Expand Up @@ -267,3 +267,9 @@ function shouldConvertSymbol(symbol: ts.Symbol, checker: ts.TypeChecker) {

return true;
}

function getModuleName(fileName: string, baseDir: string) {
return relative(baseDir, fileName)
.replace(/\\/g, "/")
.replace(/(\/index)?(\.d)?\.([cm]?[tj]s|[tj]sx?)$/, "");
}
4 changes: 2 additions & 2 deletions test/packages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ test("Issue #12", () => {

const hierarchy = outdent`
Module <internal>
Namespace test/packages/gh12/mod.ts
Namespace test/packages/gh12/mod
Variable ReferencesModule
`;

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

const hierarchy2 = outdent`
Module <internal>
Namespace gh12/mod.ts
Namespace gh12/mod
Variable ReferencesModule
`;

Expand Down

0 comments on commit 04e7498

Please sign in to comment.