generated from wayfair-incubator/oss-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ac733d
commit 3bc1d05
Showing
26 changed files
with
888 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
module.exports = { | ||
"env": { | ||
"commonjs": true, | ||
"es2021": true, | ||
"node": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"parserOptions": { | ||
"ecmaVersion": "latest" | ||
}, | ||
"rules": { | ||
} | ||
} | ||
env: { | ||
commonjs: true, | ||
es2021: true, | ||
node: true, | ||
jest: true, | ||
}, | ||
extends: "eslint:recommended", | ||
parserOptions: { | ||
ecmaVersion: "latest", | ||
}, | ||
rules: {}, | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = | ||
(resolve) => | ||
({ additionalIgnorePatterns = [] } = {}) => ({ | ||
testPathIgnorePatterns: ["/node_modules/", ...additionalIgnorePatterns], | ||
testResultsProcessor: "jest-sonar-reporter", | ||
resetModules: true, | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "mock-app-a", | ||
"version": "1.0.0", | ||
"type": "module", | ||
"devDependencies": { | ||
"cypress": "^2" | ||
}, | ||
"dependencies": { | ||
"eslint": "7.0.1", | ||
"jest": "^27.2", | ||
"react": "^17", | ||
"react-dom": "17" | ||
} | ||
} |
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,14 @@ | ||
{ | ||
"name": "mock-app-b", | ||
"version": "1.0.0", | ||
"type": "module", | ||
"devDependencies": { | ||
"cypress": "^2" | ||
}, | ||
"dependencies": { | ||
"eslint": "7.0.1", | ||
"jest": "^26.5", | ||
"react": "^17", | ||
"react-dom": "16" | ||
} | ||
} |
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,14 @@ | ||
{ | ||
"name": "mock-app-c", | ||
"version": "1.0.0", | ||
"type": "module", | ||
"devDependencies": { | ||
"cypress": "^2" | ||
}, | ||
"dependencies": { | ||
"eslint": "7.0.1", | ||
"jest": "^27.2", | ||
"react": "^17", | ||
"react-dom": "17" | ||
} | ||
} |
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 @@ | ||
{ | ||
"name": "mock-lib-a", | ||
"version": "1.2.0", | ||
"type": "module", | ||
"devDependencies": { | ||
"cypress": "^2" | ||
}, | ||
"peerDependencies": { | ||
"react": "^17", | ||
"react-dom": "17" | ||
} | ||
} |
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,10 @@ | ||
{ | ||
"overrides": { | ||
"jest": { | ||
"^26.5": ["mock-app-b"] | ||
}, | ||
"react-dom": { | ||
"16": ["mock-app-b"] | ||
} | ||
} | ||
} |
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,49 @@ | ||
const { check } = require("../check"); | ||
const { | ||
NO_CHECK_API_ERROR, | ||
FAILED_CHECK_ERROR, | ||
} = require("../shared/constants"); | ||
|
||
const packageManager = "fake-package-manager"; | ||
|
||
const mockGetConfig = () => ({ overrides: {} }); | ||
const mockGetMissingPackageApi = () => {}; | ||
|
||
describe("one-version: check", () => { | ||
it("throws if package manager specified does not have check api", () => { | ||
expect(() => { | ||
check({ | ||
packageManager, | ||
getConfig: mockGetConfig, | ||
getCheckApi: mockGetMissingPackageApi, | ||
}); | ||
}).toThrow(`${NO_CHECK_API_ERROR} ${packageManager}`); | ||
}); | ||
|
||
it("calls check api if found for package manager", () => { | ||
const mockCheckApi = jest.fn(); | ||
mockCheckApi.mockReturnValue({ duplicateDependencies: [] }); | ||
|
||
check({ | ||
packageManager, | ||
getConfig: mockGetConfig, | ||
getCheckApi: () => mockCheckApi, | ||
}); | ||
|
||
expect(mockCheckApi).toHaveBeenCalledWith({ overrides: {} }); | ||
}); | ||
|
||
it("throws if check api finds duplicate dependencies", () => { | ||
const mockCheckApi = jest.fn(); | ||
mockCheckApi.mockReturnValue({ duplicateDependencies: ["foo"] }); | ||
|
||
expect(() => { | ||
check({ | ||
packageManager, | ||
getConfig: mockGetConfig, | ||
getCheckApi: () => mockCheckApi, | ||
prettify: () => {}, | ||
}); | ||
}).toThrow(FAILED_CHECK_ERROR); | ||
}); | ||
}); |
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,61 @@ | ||
/** | ||
One Version to rule them all, One Version to find them, | ||
One Version to bring them all, and in the darkness bind them. | ||
Enforcing only one version of any direct dependency is specified in the repo. | ||
Note: Currently enforces the specifications match exactly, i.e. `^17` != `17`. | ||
*/ | ||
const chalk = require('chalk'); | ||
const {parseConfig} = require('./shared/util'); | ||
const {format} = require('./format-output'); | ||
const {checkYarn} = require('./yarn/check'); | ||
const {checkPnpm} = require('./pnpm/check'); | ||
const {FAILED_CHECK_ERROR, NO_CHECK_API_ERROR} = require('./shared/constants'); | ||
|
||
const PACKAGE_MANGER_API = { | ||
pnpm: checkPnpm, | ||
yarn: checkYarn, | ||
}; | ||
|
||
const getCheckPackageApi = (packageManager) => { | ||
return PACKAGE_MANGER_API[packageManager]; | ||
}; | ||
|
||
const check = ({ | ||
packageManager, | ||
getConfig = parseConfig, | ||
getCheckApi = getCheckPackageApi, | ||
prettify = format, | ||
} = {}) => { | ||
const checkApi = getCheckApi(packageManager); | ||
if (checkApi) { | ||
const {overrides} = getConfig(); | ||
|
||
const {duplicateDependencies} = checkApi({ | ||
overrides, | ||
}); | ||
|
||
if (duplicateDependencies.length > 0) { | ||
console.log( | ||
chalk.dim('You shall not pass!\n'), | ||
chalk.reset( | ||
'🚫 One Version Rule Failure - found multiple versions of the following dependencies:\n' | ||
), | ||
prettify(duplicateDependencies) | ||
); | ||
|
||
throw new Error(FAILED_CHECK_ERROR); | ||
} | ||
|
||
console.log( | ||
chalk.dim('My preciousss\n'), | ||
chalk.reset('✨ One Version Rule Success - found no version conflicts!') | ||
); | ||
} else { | ||
throw new Error(`${NO_CHECK_API_ERROR} ${packageManager}`); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
check, | ||
}; |
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,54 @@ | ||
const chalk = require('chalk'); | ||
|
||
const SINGLE_INDENT = 2; | ||
const DOUBLE_INDENT = SINGLE_INDENT * 2; | ||
|
||
/** | ||
Get a string in the format: | ||
[version]: | ||
[...dependencyTypeStrings] | ||
that is | ||
16 | ||
direct: mock-app-b | ||
*/ | ||
const getVersionString = (version, dependencyTypeStrings) => { | ||
return ( | ||
chalk.magentaBright(version.padStart(SINGLE_INDENT + version.length)) + | ||
'\n' + | ||
dependencyTypeStrings.join('\n') | ||
); | ||
}; | ||
|
||
/** | ||
Get a string in the format: | ||
[type]: [...names], that is: | ||
direct: name1, name2 | ||
*/ | ||
const getTypeString = ({type, names}) => { | ||
const padded = type.padStart(DOUBLE_INDENT + type.length); | ||
return chalk.yellowBright(`${padded}: `) + chalk.white(names.join(', ')); | ||
}; | ||
|
||
const format = (packages) => { | ||
return packages | ||
.map(([name, versions]) => { | ||
const str = chalk.cyanBright.underline(name); | ||
|
||
const versionsStr = Object.entries(versions) | ||
.map(([version, depTypes]) => { | ||
const depTypeStrings = Object.entries(depTypes).map(([type, names]) => | ||
getTypeString({type, names}) | ||
); | ||
|
||
return getVersionString(version, depTypeStrings); | ||
}) | ||
.join('\n'); | ||
|
||
return `${str}\n${versionsStr}`; | ||
}) | ||
.join('\n'); | ||
}; | ||
|
||
module.exports = {format}; |
Oops, something went wrong.