-
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ruleset-migrator): resolve npm packages correctly
- Loading branch information
Showing
13 changed files
with
95 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions
2
packages/ruleset-migrator/src/__tests__/__fixtures__/extends-variant-9/ruleset.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
extends: | ||
- some-npm-ruleset-i-will-have-to-add-somehow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/ruleset-migrator/src/utils/__tests__/isPackageImport.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { isPackageImport } from '../isPackageImport'; | ||
|
||
describe('isPackageImport util', () => { | ||
it.each([ | ||
'nimma/legacy', | ||
'nimma', | ||
'lodash', | ||
'lodash/get', | ||
'lodash/get.js', | ||
'@stoplight/path', | ||
'@stoplight/spectral-core', | ||
'@stoplight/spectral-core/dist/file.js', | ||
])('given valid %s package import, should return true', input => { | ||
expect(isPackageImport(input)).toBe(true); | ||
}); | ||
|
||
it.each(['', '/nimma/legacy', 'path', 'https://cdn.skypack.dev/@stoplight/spectral-core'])( | ||
'given invalid %s import, should return false', | ||
input => { | ||
expect(isPackageImport(input)).toBe(false); | ||
}, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as validate from 'validate-npm-package-name'; | ||
|
||
const isValidPackageName = (packageName: string): boolean => validate(packageName).validForNewPackages; | ||
|
||
export const isPackageImport = (packageName: string): boolean => { | ||
const fragments = packageName.split('/'); | ||
if (packageName.startsWith('@') && fragments.length >= 2) { | ||
fragments.splice(0, 2, `${fragments[0]}/${fragments[1]}`); | ||
} | ||
|
||
return fragments.every(isValidPackageName); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters