Skip to content

Commit

Permalink
strip package scope in safePackageName function
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyan Mandian committed Jun 17, 2019
1 parent 2fb7e05 commit 7b48d39
Show file tree
Hide file tree
Showing 5 changed files with 520 additions and 909 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
"@types/camelcase": "^5.2.0",
"@types/execa": "^0.9.0",
"@types/fs-extra": "^7.0.0",
"@types/jest": "^24.0.15",
"@types/mkdirp": "^0.5.2",
"@types/ms": "^0.7.30",
"@types/node": "^12.0.2",
Expand Down
4 changes: 3 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export const safeVariableName = (name: string) =>
);

export const safePackageName = (name: string) =>
name.toLowerCase().replace(/((^[^a-zA-Z]+)|[^\w.-])|([^a-zA-Z0-9]+$)/g, '');
name
.toLowerCase()
.replace(/(^@.*\/)|((^[^a-zA-Z]+)|[^\w.-])|([^a-zA-Z0-9]+$)/g, '');

export const external = (id: string) =>
!id.startsWith('.') && !path.isAbsolute(id);
Expand Down
9 changes: 5 additions & 4 deletions test/jest.config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"roots": ["<rootDir>/tests"],
"collectCoverageFrom": ["**/*.js"],
"testMatch": [
"<rootDir>/tests/**/?(*.)(spec|test).(ts|js)?(x)"
]
}
"transform": {
"^.+\\.ts?$": "ts-jest"
},
"testMatch": ["<rootDir>/tests/**/?(*.)(spec|test).(ts|js)?(x)"]
}
9 changes: 9 additions & 0 deletions test/tests/utils-safePackageName.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { safePackageName } = require('../../src/utils');

describe('utils | safePackageName', () => {
it('should generate safe package name', () => {
expect(safePackageName('@babel/core')).toBe('core');
expect(safePackageName('react')).toBe('react');
expect(safePackageName('react-dom')).toBe('react-dom');
});
});
Loading

0 comments on commit 7b48d39

Please sign in to comment.