Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

barrelsby

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

barrelsby - npm Package Compare versions

Comparing version 2.7.0 to 2.8.0

3

bin/builder.d.ts

@@ -17,2 +17,3 @@ import { BaseUrl } from './options/baseUrl';

exportDefault: boolean;
fullPathname: boolean;
structure: StructureOption | undefined;

@@ -23,3 +24,3 @@ local: boolean;

}) => void;
export declare type BarrelBuilder = (directory: Directory, modules: FileTreeLocation[], quoteCharacter: QuoteCharacter, semicolonCharacter: SemicolonCharacter, logger: Logger, baseUrl: BaseUrl, exportDefault: boolean) => string;
export type BarrelBuilder = (directory: Directory, modules: FileTreeLocation[], quoteCharacter: QuoteCharacter, semicolonCharacter: SemicolonCharacter, logger: Logger, baseUrl: BaseUrl, exportDefault: boolean) => string;
/** Builds the TypeScript */

@@ -26,0 +27,0 @@ export declare function buildImportPath(directory: Directory, target: FileTreeLocation, baseUrl: BaseUrl): string;

@@ -27,2 +27,3 @@ "use strict";

exportDefault: params.exportDefault,
fullPathname: params.fullPathname,
local: params.local,

@@ -29,0 +30,0 @@ include: params.include,

@@ -7,2 +7,2 @@ import { BaseUrl } from '../options/baseUrl';

import { FileTreeLocation } from '../interfaces/location.interface';
export declare function buildFlatBarrel(directory: Directory, modules: FileTreeLocation[], quoteCharacter: QuoteCharacter, semicolonCharacter: SemicolonCharacter, logger: Logger, baseUrl: BaseUrl, exportDefault: boolean): string;
export declare function buildFlatBarrel(directory: Directory, modules: FileTreeLocation[], quoteCharacter: QuoteCharacter, semicolonCharacter: SemicolonCharacter, logger: Logger, baseUrl: BaseUrl, exportDefault: boolean, fullPathname: boolean): string;

@@ -5,6 +5,14 @@ "use strict";

const builder_1 = require("../builder");
function toCamelCase(str) {
function dotOrDashStrToCamelCase(str) {
// massage any `example.file.name` to `exampleFileName`
return str.replace(/[-_.]([a-z])/g, (_, group) => group.toUpperCase());
}
function buildFlatBarrel(directory, modules, quoteCharacter, semicolonCharacter, logger, baseUrl, exportDefault) {
function arrayToCamelCase(arr) {
let camelCaseStr = arr[0].toLowerCase();
for (let i = 1; i < arr.length; i++) {
camelCaseStr += arr[i].charAt(0).toUpperCase() + arr[i].slice(1);
}
return camelCaseStr;
}
function buildFlatBarrel(directory, modules, quoteCharacter, semicolonCharacter, logger, baseUrl, exportDefault, fullPathname) {
return modules.reduce((previous, current) => {

@@ -15,3 +23,13 @@ const importPath = (0, builder_1.buildImportPath)(directory, current, baseUrl);

const filename = (0, builder_1.getBasename)(current.path);
previous += `export { default as ${toCamelCase(filename)} } from ${quoteCharacter}${importPath}${quoteCharacter}${semicolonCharacter}
// expect if `importPath` is './example/of/path/file.full-name' and split to ['example', 'of', 'path', 'fileFullName']
const arryPath = importPath
.split('/')
.slice(1)
.map(x => dotOrDashStrToCamelCase(x));
// expect ['example', 'of', 'path', 'name'] transform to exampleOfPathName
const camelCaseFullPathname = arrayToCamelCase(arryPath);
const defaultName = fullPathname ? camelCaseFullPathname : dotOrDashStrToCamelCase(filename);
logger.debug(`camelCaseFullPathname: ${camelCaseFullPathname}`);
logger.debug(`Default Name ${defaultName}`);
previous += `export { default as ${defaultName} } from ${quoteCharacter}${importPath}${quoteCharacter}${semicolonCharacter}
`;

@@ -18,0 +36,0 @@ }

@@ -67,2 +67,3 @@ #! /usr/bin/env node

exportDefault: !!args.exportDefault,
fullPathname: !!args.fullPathname,
structure: args.structure,

@@ -69,0 +70,0 @@ local: !!args.local,

@@ -1,2 +0,2 @@

export declare type BaseUrl = string | undefined;
export type BaseUrl = string | undefined;
export declare function getCombinedBaseUrl(rootPath: string, baseUrl: BaseUrl): BaseUrl;
import { Signale } from 'signale';
export declare type Logger = Signale;
export type Logger = Signale;
export declare function getLogger({ isVerbose }?: {
isVerbose: boolean;
}): Logger;

@@ -1,2 +0,2 @@

export declare type SemicolonCharacter = ';' | '';
export type SemicolonCharacter = ';' | '';
export declare function getSemicolonCharacter(omitSemicolon: boolean): SemicolonCharacter;
import { Options } from 'yargs';
export declare type LocationOption = 'top' | 'below' | 'all' | 'replace' | 'branch';
export type LocationOption = 'top' | 'below' | 'all' | 'replace' | 'branch';
export declare enum StructureOption {

@@ -4,0 +4,0 @@ FLAT = "flat",

@@ -45,2 +45,7 @@ "use strict";

},
F: {
type: 'boolean',
alias: 'fullPathname',
description: 'exportDefault with full pathname to create distinct name. Currently works only with the `flat` mode and exportDefault flag.',
},
H: {

@@ -47,0 +52,0 @@ type: 'boolean',

@@ -1,2 +0,2 @@

export declare type QuoteCharacter = '"' | "'";
export type QuoteCharacter = '"' | "'";
export declare function getQuoteCharacter(isSingleQuotes: boolean): QuoteCharacter;

@@ -7,3 +7,3 @@ import { QuoteCharacter } from '../options/quoteCharacter';

import { StructureOption } from '../options/options';
export declare const buildBarrel: ({ addHeader, directory, barrelType, quoteCharacter, semicolonCharacter, barrelName, logger, baseUrl, exportDefault, local, include, exclude, }: {
export declare const buildBarrel: ({ addHeader, directory, barrelType, quoteCharacter, semicolonCharacter, barrelName, logger, baseUrl, exportDefault, fullPathname, local, include, exclude, }: {
addHeader: boolean;

@@ -18,2 +18,3 @@ directory: Directory;

exportDefault: boolean;
fullPathname: boolean;
local: boolean;

@@ -20,0 +21,0 @@ include: string[];

@@ -15,3 +15,3 @@ "use strict";

const options_1 = require("../options/options");
const buildBarrel = ({ addHeader, directory, barrelType, quoteCharacter, semicolonCharacter, barrelName, logger, baseUrl, exportDefault, local, include, exclude, }) => {
const buildBarrel = ({ addHeader, directory, barrelType, quoteCharacter, semicolonCharacter, barrelName, logger, baseUrl, exportDefault, fullPathname, local, include, exclude, }) => {
logger.debug(`Building barrel @ ${directory.path}`);

@@ -23,3 +23,3 @@ let content = '';

else if (barrelType === options_1.StructureOption.FLAT) {
content = (0, flat_1.buildFlatBarrel)(directory, (0, modules_1.loadDirectoryModules)(directory, logger, include, exclude, local), quoteCharacter, semicolonCharacter, logger, baseUrl, exportDefault);
content = (0, flat_1.buildFlatBarrel)(directory, (0, modules_1.loadDirectoryModules)(directory, logger, include, exclude, local), quoteCharacter, semicolonCharacter, logger, baseUrl, exportDefault, fullPathname);
}

@@ -26,0 +26,0 @@ else {

{
"name": "barrelsby",
"version": "2.7.0",
"version": "2.8.0",
"description": "Automatic TypeScript barrels for your entire code base",

@@ -41,3 +41,3 @@ "main": "index.js",

"devDependencies": {
"@types/fs-extra": "^9.0.13",
"@types/fs-extra": "^11.0.1",
"@types/jest": "^27.0.2",

@@ -51,3 +51,3 @@ "@types/mock-fs": "^4.13.1",

"dir-compare": "^4.0.0",
"fs-extra": "^10.0.0",
"fs-extra": "^11.1.1",
"jest": "^27.4.4",

@@ -54,0 +54,0 @@ "mock-fs": "^5.1.2",

@@ -130,2 +130,11 @@ # ![Barrelsby Logo](https://github.com/bencoveney/barrelsby/blob/master/img/logo.png?raw=true)

### `-F` or `--fullPathname`
exportDefault with full pathname to create distinct name. Currently works only with the `flat` mode and exportDefault flag.
```TypeScript
export * from "./example/of/the/path";
export { default as exampleOfThePath } from "./example/of/the/path";
```
### `-h` or `--help`

@@ -132,0 +141,0 @@

@@ -44,2 +44,3 @@ import fs from 'fs';

exportDefault: boolean;
fullPathname: boolean;
local: boolean;

@@ -65,2 +66,3 @@ include: string[];

exportDefault: false,
fullPathname: false,
structure,

@@ -154,2 +156,3 @@ local: false,

exportDefault: false,
fullPathname: false,
structure: StructureOption.FLAT,

@@ -156,0 +159,0 @@ local: false,

@@ -21,2 +21,3 @@ import path from 'path';

exportDefault: boolean;
fullPathname: boolean;
structure: StructureOption | undefined;

@@ -40,2 +41,3 @@ local: boolean;

exportDefault: params.exportDefault,
fullPathname: params.fullPathname,
local: params.local,

@@ -42,0 +44,0 @@ include: params.include,

@@ -25,2 +25,3 @@ import Sinon from 'sinon';

undefined,
false,
false

@@ -77,2 +78,3 @@ );

undefined,
false,
false

@@ -129,2 +131,3 @@ );

undefined,
false,
false

@@ -176,3 +179,4 @@ );

undefined,
true
true,
false
);

@@ -203,3 +207,45 @@ });

});
describe('when using the exportDefault and fullPathname setting', () => {
let output: string;
let spySandbox: sinon.SinonSandbox;
const signale = new Signale();
beforeEach(() => {
const directory = TestUtilities.mockDirectoryTree();
spySandbox = Sinon.createSandbox();
output = Flat.buildFlatBarrel(
directory,
TestUtilities.mockModules(directory),
'"',
';',
signale,
undefined,
true,
true
);
});
afterEach(() => {
spySandbox.restore();
});
it('should produce the correct output', () => {
TestUtilities.assertMultiLine(
output,
`export { default as barrel } from "./barrel";
export * from "./barrel";
export { default as index } from "./index";
export * from "./index";
export { default as directory2Script } from "./directory2/script";
export * from "./directory2/script";
export { default as directory2Directory4DeeplyNested } from "./directory2/directory4/deeplyNested";
export * from "./directory2/directory4/deeplyNested";
export { default as directory3Program } from "./directory3/program";
export * from "./directory3/program";
`
);
});
it('should produce output compatible with the recommended tslint ruleset', () => {
TestUtilities.tslint(output, '"');
});
});
});
});

@@ -9,6 +9,15 @@ import { buildImportPath, getBasename } from '../builder';

function toCamelCase(str: string): string {
function dotOrDashStrToCamelCase(str: string): string {
// massage any `example.file.name` to `exampleFileName`
return str.replace(/[-_.]([a-z])/g, (_, group) => group.toUpperCase());
}
function arrayToCamelCase(arr: string[]) {
let camelCaseStr = arr[0].toLowerCase();
for (let i = 1; i < arr.length; i++) {
camelCaseStr += arr[i].charAt(0).toUpperCase() + arr[i].slice(1);
}
return camelCaseStr;
}
export function buildFlatBarrel(

@@ -21,3 +30,4 @@ directory: Directory,

baseUrl: BaseUrl,
exportDefault: boolean
exportDefault: boolean,
fullPathname: boolean
): string {

@@ -29,5 +39,17 @@ return modules.reduce((previous: string, current: FileTreeLocation) => {

const filename = getBasename(current.path);
previous += `export { default as ${toCamelCase(
filename
)} } from ${quoteCharacter}${importPath}${quoteCharacter}${semicolonCharacter}
// expect if `importPath` is './example/of/path/file.full-name' and split to ['example', 'of', 'path', 'fileFullName']
const arryPath = importPath
.split('/')
.slice(1)
.map(x => dotOrDashStrToCamelCase(x));
// expect ['example', 'of', 'path', 'name'] transform to exampleOfPathName
const camelCaseFullPathname = arrayToCamelCase(arryPath);
const defaultName = fullPathname ? camelCaseFullPathname : dotOrDashStrToCamelCase(filename);
logger.debug(`camelCaseFullPathname: ${camelCaseFullPathname}`);
logger.debug(`Default Name ${defaultName}`);
previous += `export { default as ${defaultName} } from ${quoteCharacter}${importPath}${quoteCharacter}${semicolonCharacter}
`;

@@ -34,0 +56,0 @@ }

@@ -30,2 +30,3 @@ import * as Destinations from './destinations';

exportDefault: false,
fullPathname: false,
include: ['directory2'],

@@ -89,2 +90,3 @@ local: true,

exportDefault: args.exportDefault,
fullPathname: args.fullPathname,
structure: args.structure,

@@ -91,0 +93,0 @@ local: args.local,

@@ -66,2 +66,3 @@ #! /usr/bin/env node

exportDefault: !!args.exportDefault,
fullPathname: !!args.fullPathname,
structure: args.structure,

@@ -68,0 +69,0 @@ local: !!args.local,

@@ -70,2 +70,8 @@ import { Options } from 'yargs';

},
F: {
type: 'boolean',
alias: 'fullPathname',
description:
'exportDefault with full pathname to create distinct name. Currently works only with the `flat` mode and exportDefault flag.',
},
H: {

@@ -72,0 +78,0 @@ type: 'boolean',

@@ -8,3 +8,9 @@ import fs from 'fs';

export function purge(rootTree: Directory, shouldPurge: boolean, noHeader: boolean, barrelName: string, logger: Logger) {
export function purge(
rootTree: Directory,
shouldPurge: boolean,
noHeader: boolean,
barrelName: string,
logger: Logger
) {
// Delete any existing barrels.

@@ -19,3 +25,3 @@ if (shouldPurge) {

.filter(file => {
if(noHeader) {
if (noHeader) {
return true;

@@ -22,0 +28,0 @@ }

@@ -25,2 +25,3 @@ import { convertPathSeparator } from '../utilities';

exportDefault,
fullPathname,
local,

@@ -39,2 +40,3 @@ include,

exportDefault: boolean;
fullPathname: boolean;
local: boolean;

@@ -63,3 +65,4 @@ include: string[];

baseUrl,
exportDefault
exportDefault,
fullPathname
);

@@ -66,0 +69,0 @@ } else {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc