refactor: remove invariant (#62275)

This commit is contained in:
Oliver Eyton-Williams
2025-09-19 19:36:20 +02:00
committed by GitHub
parent 56c34a3bd6
commit c6498cf0b4
6 changed files with 8 additions and 45 deletions
+1 -5
View File
@@ -17,9 +17,5 @@
"bugs": {
"url": "https://github.com/freeCodeCamp/freeCodeCamp/issues"
},
"homepage": "https://github.com/freeCodeCamp/freeCodeCamp#readme",
"dependencies": {
"@types/invariant": "^2.2.37",
"invariant": "2.2.4"
}
"homepage": "https://github.com/freeCodeCamp/freeCodeCamp#readme"
}
+5 -17
View File
@@ -1,6 +1,3 @@
// originally based off of https://github.com/gulpjs/vinyl
import invariant from 'invariant';
const exts = ['js', 'html', 'css', 'jsx', 'ts', 'tsx', 'py'] as const;
export type Ext = (typeof exts)[number];
@@ -48,15 +45,10 @@ export function createPoly<Rest>({
history,
...rest
}: PolyProps & Rest): PolyProps & AddedProperties & Rest {
invariant(typeof name === 'string', 'name must be a string but got %s', name);
invariant(typeof ext === 'string', 'ext must be a string, but was %s', ext);
invariant(
typeof contents === 'string',
'contents must be a string but got %s',
contents
);
if (typeof name !== 'string') throw new TypeError('name must be a string');
if (typeof ext !== 'string') throw new TypeError('ext must be a string');
if (typeof contents !== 'string')
throw new TypeError('contents must be a string');
return {
...rest,
@@ -98,11 +90,7 @@ export function isPoly(poly: unknown): poly is ChallengeFile {
}
function checkPoly(poly: ChallengeFile) {
invariant(
isPoly(poly),
'function should receive a PolyVinyl, but got %s',
JSON.stringify(poly)
);
if (!isPoly(poly)) throw Error('Not a PolyVinyl: ' + JSON.stringify(poly));
}
// setContent will lose source if not supplied