Skip to content
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

Feature: Add Extension Option to Support Custom Suffixes (useful for ESM builds) #174

Closed
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
50 changes: 35 additions & 15 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,51 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"version": "2.0.0",
"command": "npm",
"isShellCommand": true,
"showOutput": "always",
"suppressTaskName": true,
"echoCommand": true,
"tasks": [
{
"taskName": "install",
"args": ["install"]
"label": "install",
"type": "shell",
"args": [
"install"
],
"problemMatcher": []
},
{
"taskName": "update",
"args": ["update"]
"label": "update",
"type": "shell",
"args": [
"update"
],
"problemMatcher": []
},
{
"taskName": "test",
"args": ["run", "test"],
"problemMatcher": "$tsc"
"label": "test",
"type": "shell",
"args": [
"run",
"test"
],
"problemMatcher": "$tsc",
"group": {
"_id": "test",
"isDefault": false
}
},
{
"taskName": "build",
"args": ["run", "build"],
"isBuildCommand": true,
"problemMatcher": "$tsc"
"label": "build",
"type": "shell",
"args": [
"run",
"build"
],
"problemMatcher": "$tsc",
"group": {
"_id": "build",
"isDefault": false
}
}
]
}
31 changes: 31 additions & 0 deletions .vscode/tasks.json.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"showOutput": "always",
"suppressTaskName": true,
"echoCommand": true,
"tasks": [
{
"taskName": "install",
"args": ["install"]
},
{
"taskName": "update",
"args": ["update"]
},
{
"taskName": "test",
"args": ["run", "test"],
"problemMatcher": "$tsc"
},
{
"taskName": "build",
"args": ["run", "build"],
"isBuildCommand": true,
"problemMatcher": "$tsc"
}
]
}
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ than recursively searching child directories.

### `-n [name]` or `--name [name]`

Specifies the name to use for creating new barrels (and identifying old ones). `.ts` wil be
Specifies the name to use for creating new barrels (and identifying old ones). `.ts` will be
appended if not included in the name. Barrels names will be defaulted to `index.ts`.

### `-s [mode]` or `--structure [mode]`
Expand Down Expand Up @@ -212,6 +212,16 @@ Display the barrelsby version number.

Display additional debug information.

### `-x [extension]`or `--extension [extension]`
Add extension suffix to exports (e.g. '.js'). Useful for ESM modules.
BitForger marked this conversation as resolved.
Show resolved Hide resolved

```TypeScript
// Without --extension
export * from "./Slider";
// With --extension
export * from "./Slider.js";
```

## Requirements

Requires node v6.0.0 or greater for ES6 syntax.
Expand Down
3 changes: 2 additions & 1 deletion barrelsby.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"structure": "filesystem",
"verbose": true,
"include": [".ts$"],
"exclude": ["zeta.ts$"]
"exclude": ["zeta.ts$"],
"extension": ""
}
8 changes: 4 additions & 4 deletions bin/builder.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { SemicolonCharacter } from "./options/noSemicolon";
import { StructureOption } from "./options/options";
import { QuoteCharacter } from "./options/quoteCharacter";
import { Directory, Location } from "./utilities";
export declare function buildBarrels(destinations: Directory[], quoteCharacter: QuoteCharacter, semicolonCharacter: SemicolonCharacter, barrelName: string, logger: Logger, baseUrl: BaseUrl, exportDefault: boolean, structure: StructureOption | undefined, local: boolean, include: string[], exclude: string[]): void;
export declare type BarrelBuilder = (directory: Directory, modules: Location[], quoteCharacter: QuoteCharacter, semicolonCharacter: SemicolonCharacter, logger: Logger, baseUrl: BaseUrl, exportDefault: boolean) => string;
export declare function buildBarrels(destinations: Directory[], quoteCharacter: QuoteCharacter, semicolonCharacter: SemicolonCharacter, barrelName: string, logger: Logger, baseUrl: BaseUrl, exportDefault: boolean, structure: StructureOption | undefined, local: boolean, include: string[], exclude: string[], extension: boolean): void;
export declare type BarrelBuilder = (directory: Directory, modules: Location[], quoteCharacter: QuoteCharacter, semicolonCharacter: SemicolonCharacter, logger: Logger, baseUrl: BaseUrl, exportDefault: boolean, extension: boolean) => string;
/** Builds the TypeScript */
export declare function buildImportPath(directory: Directory, target: Location, baseUrl: BaseUrl): string;
export declare function buildImportPath(directory: Directory, target: Location, baseUrl: BaseUrl, extension: boolean): string;
/** Strips the .ts or .tsx file extension from a path and returns the base filename. */
export declare function getBasename(relativePath: string): string;
export declare function getBaseNameWithoutExtension(relativePath: string): string;
43 changes: 32 additions & 11 deletions bin/builder.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bin/builder.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading