Skip to content

Commit

Permalink
refactor(urlSlug): remove urlSlug as a dependency and update packages…
Browse files Browse the repository at this point in the history
… to remove security alert (#120)
  • Loading branch information
Pmyl authored Dec 16, 2019
1 parent 84d1663 commit 6702f81
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 92 deletions.
93 changes: 16 additions & 77 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
},
"dependencies": {
"lodash-es": "^4.17.15",
"url-slug": "^2.2.0",
"winston": "^3.2.1"
},
"peerDependencies": {
Expand Down
6 changes: 2 additions & 4 deletions src/transformer/mockDefiner/factoryUniqueName.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import * as ts from 'typescript';
import { KeyCounter } from './keyCounter';
// tslint:disable-next-line:no-any
const urlSlug: any = require('url-slug');

export type PossibleDeclaration = ts.InterfaceDeclaration | ts.ClassDeclaration | ts.TypeAliasDeclaration;

Expand All @@ -14,7 +12,7 @@ export class FactoryUniqueName {

public createForDeclaration(declaration: PossibleDeclaration): string {
const declarationNameIdentifier: ts.Identifier = declaration.name;
const declarationNameSanitized: string = urlSlug((declarationNameIdentifier && declarationNameIdentifier.text) || 'Anonymous', '_');
const declarationNameSanitized: string = (declarationNameIdentifier && declarationNameIdentifier.text) || 'Anonymous';
const baseFactoryName: string = `create__${declarationNameSanitized}__mock`;
const count: number = this._keyCounter.getFor(baseFactoryName);

Expand All @@ -34,7 +32,7 @@ export class FactoryUniqueName {
return acc;
}, '');

const declarationNameSanitized: string = urlSlug(nameOfDeclarations || 'Anonymous', '_');
const declarationNameSanitized: string = nameOfDeclarations || 'Anonymous';
const baseFactoryName: string = `create__${declarationNameSanitized}__mock`;
const count: number = this._keyCounter.getFor(baseFactoryName);

Expand Down
13 changes: 3 additions & 10 deletions src/transformer/mockDefiner/mockDefiner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ import { ModuleName } from './modules/moduleName';
import { ModuleNameIdentifier } from './modules/moduleNameIdentifier';
import { ModulesImportUrl } from './modules/modulesImportUrl';

// tslint:disable-next-line:no-any
const urlSlug: any = require('url-slug');

interface FactoryRegistrationPerFile {
[key: string]: Array<{
key: ts.Declaration;
Expand Down Expand Up @@ -69,9 +66,9 @@ export class MockDefiner {
}

this._internalModuleImportIdentifierPerFile[this._fileName] = {
[ModuleName.Extension]: this._createUniqueFileName(ModuleName.Extension),
[ModuleName.Merge]: this._createUniqueFileName(ModuleName.Merge),
[ModuleName.Repository]: this._createUniqueFileName(ModuleName.Repository),
[ModuleName.Extension]: ts.createFileLevelUniqueName(ModuleName.Extension),
[ModuleName.Merge]: ts.createFileLevelUniqueName(ModuleName.Merge),
[ModuleName.Repository]: ts.createFileLevelUniqueName(ModuleName.Repository),
};

this._neededImportIdentifierPerFile[this._fileName] = this._neededImportIdentifierPerFile[this._fileName] || [];
Expand Down Expand Up @@ -140,10 +137,6 @@ export class MockDefiner {
return this._declarationCache.get(declaration);
}

private _createUniqueFileName(name: string): ts.Identifier {
return ts.createFileLevelUniqueName(`${urlSlug(this._fileName, '_')}_${name}`);
}

private _mockRepositoryAccess(filename: string): ts.Expression {
const repository: ts.Identifier = this._getModuleIdentifier(filename, ModuleName.Repository);

Expand Down

0 comments on commit 6702f81

Please sign in to comment.