Skip to content
Open
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
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@
"default": true,
"description": "Specify if you want to enable/disable the usage of semis in the barrel file."
},
"exportall.config.keepExtensions": {
"type": "boolean",
"default": false,
"description": "Whether to keep file extensions (for use with Deno/ESM)."
},
"exportall.config.quote": {
"type": "string",
"default": "'",
Expand Down
17 changes: 12 additions & 5 deletions src/commands/ExportAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export class ExportAll {
const includeFolders: boolean | undefined = config.get(
CONFIG_INCLUDE_FOLDERS
);
const keepExtensions: boolean | undefined = config.get(
CONFIG_KEEP_EXTENSIONS
);
const semis: boolean | undefined = config.get(CONFIG_SEMIS);
const quote: '"' | "'" = config.get(CONFIG_QUOTE) ?? "'";
const message: string | string[] | undefined = config.get<
Expand Down Expand Up @@ -124,11 +127,15 @@ export class ExportAll {
// Check if there are still files after the filter
if (filesToExport && filesToExport.length > 0) {
let output = filesToExport.map((item) => {
const fileWithoutExtension =
item.type === "folder" ? item.name : path.parse(item.name).name;
return `export * from ${quote}./${fileWithoutExtension}${quote}${
semis ? ";" : ""
}\n`;
let filePath: string;
if (keepExtensions) {
filePath =
item.type === "folder" ? path.join(item.name, "index.ts") : item.name;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is this issue it will default to index.ts if it's importing a folder in the barrel, so perhaps somehow it needs to work for .js and other extensions. Not sure what is the right solution here, maybe a configuration or else check the file system and try all extensions until one succeeds. There might be a lib for that.

} else {
filePath =
item.type === "folder" ? item.name : path.parse(item.name).name;
}
return `export * from ${quote}./${filePath}${quote}${semis ? ";" : ""}\n`;
});

if (output && output.length > 0) {
Expand Down
1 change: 1 addition & 0 deletions src/constants/Extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const CONFIG_FOLDERS = 'config.folderListener';
export const CONFIG_EXCLUDE = 'config.exclude';
export const CONFIG_RELATIVE_EXCLUDE = 'config.relExclusion';
export const CONFIG_INCLUDE_FOLDERS = 'config.includeFoldersToExport';
export const CONFIG_KEEP_EXTENSIONS = 'config.keepExtensions';
export const CONFIG_SEMIS = 'config.semis';
export const CONFIG_QUOTE = 'config.quote';
export const CONFIG_MESSAGE = 'config.message';
Expand Down