From c6498cf0b428dea8df4da1f6a69a42a544a1d38d Mon Sep 17 00:00:00 2001 From: Oliver Eyton-Williams Date: Fri, 19 Sep 2025 19:36:20 +0200 Subject: [PATCH] refactor: remove invariant (#62275) --- curriculum/package.json | 1 - docker/api/Dockerfile | 4 +--- knip.jsonc | 3 --- pnpm-lock.yaml | 17 +---------------- shared/package.json | 6 +----- shared/utils/polyvinyl.ts | 22 +++++----------------- 6 files changed, 8 insertions(+), 45 deletions(-) diff --git a/curriculum/package.json b/curriculum/package.json index 92157c2a6a1..7d03a30e68e 100644 --- a/curriculum/package.json +++ b/curriculum/package.json @@ -47,7 +47,6 @@ "@vitest/ui": "^3.2.4", "chai": "4.4.1", "glob": "8.1.0", - "invariant": "2.2.4", "joi": "17.12.2", "joi-objectid": "3.0.1", "js-yaml": "4.0.0", diff --git a/docker/api/Dockerfile b/docker/api/Dockerfile index 7a9f0a8c76a..f1095ff6f39 100644 --- a/docker/api/Dockerfile +++ b/docker/api/Dockerfile @@ -38,14 +38,13 @@ WORKDIR /home/node/build COPY --chown=node:node pnpm*.yaml . COPY --chown=node:node package.json . COPY --chown=node:node api/ api/ -COPY --chown=node:node shared/ shared/ RUN npm i -g pnpm@10 # Weirdly this config does not seem necessary for the new api (the same number # of deps are installed in both cases), but I'm including it just for # consistency. RUN pnpm config set dedupe-peer-dependents false -RUN pnpm install --prod --ignore-scripts -F=shared -F=api --frozen-lockfile +RUN pnpm install --prod --ignore-scripts -F=api --frozen-lockfile RUN cd api && npx prisma@$(jq -r '.devDependencies.prisma' < package.json) generate FROM node:22-bookworm @@ -56,7 +55,6 @@ COPY --from=builder --chown=node:node /home/node/build/api/package.json api/ COPY --from=builder --chown=node:node /home/node/build/shared/config/curriculum.json shared/config/ COPY --from=deps --chown=node:node /home/node/build/node_modules/ node_modules/ -COPY --from=deps --chown=node:node /home/node/build/shared/node_modules/ shared/node_modules/ COPY --from=deps --chown=node:node /home/node/build/api/node_modules/ api/node_modules/ CMD ["node", "api/src/server.js"] diff --git a/knip.jsonc b/knip.jsonc index 0ae08f87490..23973d70dbc 100644 --- a/knip.jsonc +++ b/knip.jsonc @@ -26,9 +26,6 @@ "@redux-saga/core" // Not referenced, something seems off related to peer dep and types ] }, - "curriculum": { - "ignoreDependencies": ["invariant"] // Used from another workspace: shared/utils/polyvinyl.js - }, "shared": { "ignore": ["{config,utils}/*.ts"] // Using the same dir for src + outDir files with tsc confuses Knip }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2167fceb061..1fd5275bc3d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -736,9 +736,6 @@ importers: glob: specifier: 8.1.0 version: 8.1.0 - invariant: - specifier: 2.2.4 - version: 2.2.4 joi: specifier: 17.12.2 version: 17.12.2 @@ -782,14 +779,7 @@ importers: specifier: ^3.2.4 version: 3.2.4(@types/node@20.12.8)(@vitest/ui@3.2.4)(jsdom@16.7.0)(msw@2.8.7(@types/node@20.12.8)(typescript@5.8.2))(terser@5.28.1)(tsx@4.19.1)(yaml@2.8.0) - shared: - dependencies: - '@types/invariant': - specifier: ^2.2.37 - version: 2.2.37 - invariant: - specifier: 2.2.4 - version: 2.2.4 + shared: {} tools/challenge-editor/api: dependencies: @@ -4610,9 +4600,6 @@ packages: '@types/inquirer@8.2.11': resolution: {integrity: sha512-15UboTvxb9SOaPG7CcXZ9dkv8lNqfiAwuh/5WxJDLjmElBt9tbx1/FDsEnJddUBKvN4mlPKvr8FyO1rAmBanzg==} - '@types/invariant@2.2.37': - resolution: {integrity: sha512-IwpIMieE55oGWiXkQPSBY1nw1nFs6bsKXTFskNY8sdS17K24vyEBRQZEwlRS7ZmXCWnJcQtbxWzly+cODWGs2A==} - '@types/istanbul-lib-coverage@2.0.4': resolution: {integrity: sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==} @@ -19615,8 +19602,6 @@ snapshots: '@types/through': 0.0.33 rxjs: 7.8.1 - '@types/invariant@2.2.37': {} - '@types/istanbul-lib-coverage@2.0.4': {} '@types/istanbul-lib-report@3.0.1': diff --git a/shared/package.json b/shared/package.json index a212d7e1a62..b896772fa54 100644 --- a/shared/package.json +++ b/shared/package.json @@ -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" } diff --git a/shared/utils/polyvinyl.ts b/shared/utils/polyvinyl.ts index 768ada3514c..f1f76c4a02f 100644 --- a/shared/utils/polyvinyl.ts +++ b/shared/utils/polyvinyl.ts @@ -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({ 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