Skip to content

Commit

Permalink
feat: add extension option to support ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
c-eberling committed Oct 29, 2021
1 parent 6ba1db5 commit 1577149
Show file tree
Hide file tree
Showing 39 changed files with 347 additions and 99 deletions.
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.

```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

0 comments on commit 1577149

Please sign in to comment.