# Javascript Node CircleCI 2.0 configuration file # # Check https://circleci.com/docs/2.0/language-javascript/ for more details # version: 2.1 parameters: full-run: # Set by the daily master schedule (or a manual trigger) to run every job # despite a tree-passed marker, so a path-filter mistake can't hide for long type: boolean default: false executors: node: docker: &docker - image: cimg/node:26.13 environment: # the whole CI is reset each time anyway, so only track local cache YARN_ENABLE_GLOBAL_CACHE: false YARN_ENABLE_MIRROR: false # Don't waste io YARN_ENABLE_PROGRESS_BARS: false YARN_ENABLE_INLINE_BUILDS: true # Don't revalidate YARN_ENABLE_SCRIPTS: false # Keep install cache YARN_ENABLE_IMMUTABLE_INSTALLS: true commands: halt-unless-relevant-change: # Reads a flag computed once in the `setup` job. Transported via cache # (not the workspace) so jobs can halt before paying attach_workspace. parameters: flag: type: enum enum: ["esmodule", "tests"] steps: - restore_cache: keys: - &relevance-cache-key ci-relevant-v4-{{ .Environment.CIRCLE_WORKFLOW_ID }} - run: name: Skip job if only non-<< parameters.flag >> paths changed command: | FLAG="$(cat ~/project/.ci-<< parameters.flag >>-relevant 2>/dev/null)" || FLAG='' if [ "${FLAG}" = "false" ]; then echo "No << parameters.flag >>-relevant changes; halting this job." circleci-agent step halt elif [ "${FLAG}" = "true" ]; then echo "Relevant changes detected; continuing job." else echo "No relevance flag found; failing open (continuing job)." fi restore-yarn-cache: # The workspace skips the yarn cache (~130 MiB) to keep setup's upload # short; only jobs that re-resolve dependencies (`yarn up`/`add`) need it. steps: - restore_cache: keys: - v16-dependencies-{{ checksum ".ci-deps-key" }} - v16-dependencies- jobs: setup: executor: node resource_class: large steps: - checkout - run: name: Check tree-passed requires every job # Otherwise a tree gets marked passed without the missing job, and # the merge queue and master skip it command: | # Temp files, not <(...): a failed yq must fail the step yq '[.workflows.validation.jobs[] | (select(tag == "!!map") | keys | .[0]) // .] - ["setup", "tree-passed"] | sort | .[]' .circleci/config.yml > /tmp/ci-jobs yq '.workflows.validation.jobs[].["tree-passed"].requires | select(.) | sort | .[]' .circleci/config.yml > /tmp/ci-tree-passed-requires diff -u --label 'workflow jobs' --label 'tree-passed requires' /tmp/ci-jobs /tmp/ci-tree-passed-requires - run: name: Hash source tree # File contents, not the commit: a squash merge and the merge queue # commit it came from share a tree, so the same code runs once command: git rev-parse 'HEAD^{tree}' > ~/project/.ci-tree - restore_cache: keys: - ci-passed-v1-{{ checksum ".ci-tree" }} - run: name: Detect relevant changes command: | # Compare against the default branch. # Use CIRCLE_DEFAULT_BRANCH so this stays correct if the default branch changes. BASE_BRANCH="${CIRCLE_DEFAULT_BRANCH:-master}" # Fail open: run jobs unless we can prove irrelevance. ESMODULE_RELEVANT=true TESTS_RELEVANT=true BASE_TREE='' # Only the queue and master trust a marker; PR reruns still run if [ "<< pipeline.parameters.full-run >>" = "false" ] && [ -f ~/project/.ci-tree-passed ] \ && [[ "${CIRCLE_BRANCH}" == "${BASE_BRANCH}" || "${CIRCLE_BRANCH}" == gh-readonly-queue/* ]]; then # Saved by `tree-passed` once every job passed on this exact tree echo "Every job already passed on tree $(cat ~/project/.ci-tree); halting all jobs." ESMODULE_RELEVANT=false TESTS_RELEVANT=false DIFF_RANGE="" elif [ "${CIRCLE_BRANCH}" = "${BASE_BRANCH}" ]; then # A push can land several commits (rebase-merge), so HEAD~1 isn't # the whole change; always run everything on the default branch. echo "On ${BASE_BRANCH}; running all jobs." DIFF_RANGE="" else # NOTE: never fetch with --depth here: a shallow fetch severs the # merge base, making the three-dot diff fail (and thus previously # silently skipping these checks on every PR branch). # blob:none keeps the commit/tree graph (enough for merge-base and # --name-only diffs) without transferring file contents. git fetch --force --filter=blob:none origin "${BASE_BRANCH}:refs/remotes/origin/${BASE_BRANCH}" || true DIFF_RANGE="origin/${BASE_BRANCH}...HEAD" # The tree the diff runs from: if it passed, `tree-passed` can # vouch for this tree even when the diff halted jobs # (rev-parse prints its argument when it fails, hence the reset) BASE_TREE="$(git rev-parse "$(git merge-base "origin/${BASE_BRANCH}" HEAD)^{tree}")" || BASE_TREE='' fi # Grep a file, not a pipe: CircleCI runs bash with pipefail, so an # early-exiting `grep -q` could SIGPIPE the writer and flip a check. # (No here-strings either: CircleCI reads their angle brackets as parameter syntax.) # --no-renames: a move out of packages/ must list the old path too. if [ -z "${DIFF_RANGE}" ]; then : elif git -c core.quotePath=off diff --no-renames --name-only "${DIFF_RANGE}" > /tmp/ci-changed-files; then echo "Changed files:" cat /tmp/ci-changed-files # A flag goes false only when grep cleanly proves it; a grep error # (exit 2, e.g. a bad regex) counts as relevant. all_match() { local rc=0; grep -Evq "$1" /tmp/ci-changed-files || rc=$?; [ "${rc}" -eq 1 ]; } any_match() { local rc=0; grep -Eq "$1" /tmp/ci-changed-files || rc=$?; [ "${rc}" -ne 1 ]; } # Docs/website/tooling paths; both flags below are denylists over it. DOCS_ONLY='website/|docs/|\.changeset/|\.cursor/|\.agents/|\.claude/|\.github/|[^/]+\.md$' # Denylist (fail open): only paths provably outside every esmodule # job's inputs can skip them, so a new input dir runs by default. if all_match "^(${DOCS_ONLY}|\.vscode/|plans/|__tests__/|eslint\.config\.mjs$|jest\.config\.js$|examples/[^/]+\.md$|examples/(benchmark|benchmark-react|coin-app|nextjs|normalizr-github|normalizr-redux|test-bundlesize|vue-todo-app)/)"; then echo "No relevant esmodule-related changes; downstream esmodule jobs will halt." ESMODULE_RELEVANT=false fi # Test jobs read only setup's workspace, so a change inside it always # counts, even under a docs/website path (the Playground tests). yq '.jobs.setup.steps[] | select(tag == "!!map" and has("persist_to_workspace")) | .persist_to_workspace.paths[]' .circleci/config.yml > /tmp/ci-persisted PERSISTED="$(sed -e 's#^project/##' -e 's/[][\\.^$*+?(){}|]/\\&/g' /tmp/ci-persisted | paste -sd'|')" [ -n "${PERSISTED}" ] || { echo "No paths found in persist_to_workspace"; exit 1; } if all_match "^(${DOCS_ONLY})" && ! any_match "^(${PERSISTED})(/|$)"; then echo "Only docs/website/tooling paths outside the workspace changed; test jobs will halt." TESTS_RELEVANT=false fi else echo "Could not diff ${DIFF_RANGE}; treating as relevant." fi echo "${ESMODULE_RELEVANT}" > ~/project/.ci-esmodule-relevant echo "${TESTS_RELEVANT}" > ~/project/.ci-tests-relevant echo "${BASE_TREE}" > ~/project/.ci-base-tree # Later setup steps read these; the files are for downstream jobs. echo "export ESMODULE_RELEVANT=${ESMODULE_RELEVANT} TESTS_RELEVANT=${TESTS_RELEVANT}" >> "${BASH_ENV}" - save_cache: key: *relevance-cache-key paths: - .ci-esmodule-relevant - .ci-tests-relevant - .ci-tree # tree-passed marks this - .ci-base-tree - run: name: Halt setup if nothing downstream is relevant command: | if [ "${TESTS_RELEVANT}" = "false" ] && [ "${ESMODULE_RELEVANT}" = "false" ]; then echo "Every downstream job will halt; skipping install and build." circleci-agent step halt fi - run: name: Add examples/* to yarn workspace command: | npm pkg delete workspaces[6] npm pkg delete workspaces[5] npm pkg delete workspaces[4] npm pkg delete workspaces[3] npm pkg delete workspaces[2] npm pkg delete workspaces[1] npm pkg set 'workspaces[]'='examples/todo-app' npm pkg set 'workspaces[]'='examples/github-app' npm pkg set 'workspaces[]'='examples/normalizr-relationships' - run: # Hash the manifests before trimming and `yarn up` rewrite them, # so the same key restores and saves. name: Compute dependency cache key command: | git show HEAD:package.json HEAD:yarn.lock HEAD:examples/todo-app/package.json HEAD:examples/github-app/package.json HEAD:examples/normalizr-relationships/package.json | sha256sum > .ci-deps-key - restore-yarn-cache - run: name: yarn install command: | yarn up @data-client/endpoint@workspace:^ @data-client/react@workspace:^ @data-client/rest@workspace:^ @data-client/img@workspace:^ @data-client/graphql@workspace:^ - save_cache: paths: - .yarn/cache key: v16-dependencies-{{ checksum ".ci-deps-key" }} - run: # These are independent (babel/rollup compile from src, not tsc output), # so run them concurrently to shorten the critical path. Legacy types # (for the esmodule-types TS matrix) are built here rather than in a # separate job to save a job hop on the critical path. name: Build types and test lib (parallel) command: | if [ "${ESMODULE_RELEVANT}" = "false" ]; then yarn run ci:build:setup else yarn run ci:build:setup:esmodule fi - persist_to_workspace: root: ~/ paths: # explicitly list so we can ignore some directories that are not needed; # setup's relevance check counts any change under these as a test input # .yarn/cache is left out; see restore-yarn-cache - project/.yarn/releases - project/.yarn/plugins - project/.yarn/install-state.gz - project/.ci-deps-key - project/__tests__ - project/examples/todo-app - project/examples/github-app - project/examples/normalizr-relationships - project/node_modules - project/packages - project/scripts # Website inputs of the unit tests (Playground and motion tests, and the # utils Playground imports) - project/website/src/components/Playground - project/website/src/components/motion - project/website/src/utils - project/.yarnrc.yml - project/babel.config.js - project/eslint.config.mjs - project/jest.config.js - project/package.json - project/tsconfig-base.json - project/tsconfig.json - project/tsconfig.test.json - project/yarn.lock lint: executor: node resource_class: medium steps: - halt-unless-relevant-change: flag: tests - attach_workspace: at: ~/ - run: command: | yarn lint --quiet packages/*/src typecheck: executor: node steps: - halt-unless-relevant-change: flag: tests - attach_workspace: at: ~/ - run: command: | yarn run tsc --project tsconfig.test.json --noEmit - run: # See scripts/typeperf/README.md name: Type-check perf budget command: yarn run check:typeperf unit_tests: parameters: react-version: type: string executor: node resource_class: large steps: - halt-unless-relevant-change: flag: tests - attach_workspace: at: ~/ - unless: # `latest` uses the installed React as-is condition: equal: ["latest", << parameters.react-version >>] steps: - restore-yarn-cache - run: name: Installing React Version command: | if [ "<< parameters.react-version >>" == "^17" ]; then npm pkg delete resolutions.react resolutions.react-dom resolutions.react-test-renderer yarn up react@<< parameters.react-version >> react-dom@<< parameters.react-version >> react-test-renderer@<< parameters.react-version >> @react-navigation/native@^6.0.0 @react-navigation/native-stack@^6.0.0 react-native-screens@^3.0.0 @testing-library/react@^12.0.0 yarn workspace @data-client/test add --dev @testing-library/react-hooks elif [ "<< parameters.react-version >>" == "^18" ]; then npm pkg delete resolutions.react resolutions.react-dom resolutions.react-test-renderer yarn up react@<< parameters.react-version >> react-dom@<< parameters.react-version >> react-test-renderer@<< parameters.react-version >> yarn workspace @data-client/test add --dev @testing-library/react-hooks fi - run: name: Running Jest # --maxWorkers matches resource_class (large = 4 vCPU); Jest's # os.cpus() sees the host's CPUs in docker and would oversubscribe. command: | if [ "<< parameters.react-version >>" == "^17" ] || [ "<< parameters.react-version >>" == "^18" ]; then yarn test:ci --maxWorkers=4 --selectProjects ReactDOM --testPathPatterns packages/react packages/use-enhanced-reducer packages/img elif [ "<< parameters.react-version >>" == "native" ]; then # No --maxWorkers here: the ReactNative suites are dominated by # fake-timer waits, and capping workers makes the heavy hook # suites contend enough to flake 5s test timeouts. # React Native 0.88 bundles the React 19.3 renderer, so run on the installed React yarn test:ci --selectProjects ReactNative # Previous React minor (19.2): these suites assert per-minor React behavior, # and none of them load react-native, whose 0.88 peer is react ^19.3 V=19.2.3 npm pkg delete resolutions.react resolutions.react-dom resolutions.react-test-renderer # test-renderer's minor tracks React's (1.2 pairs with React 19.2) yarn up react@$V react-dom@$V react-test-renderer@$V test-renderer@~1.2.0 V=$V node -e "for (const p of ['react','react-dom','react-test-renderer']) { const v=require(p+'/package.json').version; if (v !== process.env.V) throw new Error(p+' resolved to '+v) }" yarn test:ci --maxWorkers=4 --selectProjects ReactDOM --testPathPatterns 'packages/react/src/__tests__/concurrent-.*\.web\.tsx' 'packages/react/src/hooks/__tests__/useCacheState.web.tsx' elif [ "<< parameters.react-version >>" == "latest" ]; then # Coverage floors and projects live in the test:coverage script yarn run test:coverage --ci --maxWorkers=4 --coverageReporters=lcovonly --coverageReporters=text-summary else echo "Unknown react-version << parameters.react-version >>" exit 1 fi - when: condition: equal: [latest, << parameters.react-version >>] steps: - run: name: Upload coverage to Codecov # Upload even when the coverage floors fail, so Codecov shows what dropped when: always command: | # Pinned CLI, checked against Codecov's signing key fingerprint # before it ever sees CODECOV_TOKEN. # https://docs.codecov.com/docs/codecov-uploader#integrity-checking-the-uploader # renovate: datasource=github-releases depName=codecov/codecov-cli CLI=https://cli.codecov.io/v11.3.2/linux/codecov KEY_FINGERPRINT=27034E7FDB850E0BBC2C62FF806BB28AED779869 if [ ! -f coverage/lcov.info ]; then echo "No coverage report; skipping upload" exit 0 fi DIR="$(mktemp -d)" export GNUPGHOME="$DIR" # gpg status goes to a file, not a pipe: CircleCI's pipefail would # flip the check if an early-exiting grep SIGPIPEd gpg. if curl -fsS --retry 3 --output-dir "$DIR" -O "$CLI" -O "$CLI.SHA256SUM" -O "$CLI.SHA256SUM.sig" \ -o key.asc https://keybase.io/codecovsecops/pgp_keys.asc \ && gpg --batch --import "$DIR/key.asc" \ && gpg --batch --status-file "$DIR/status" --verify "$DIR/codecov.SHA256SUM.sig" "$DIR/codecov.SHA256SUM" \ && grep -q "VALIDSIG .*$KEY_FINGERPRINT" "$DIR/status" \ && (cd "$DIR" && sha256sum -c codecov.SHA256SUM); then chmod +x "$DIR/codecov" # Fork PRs have no token; Codecov accepts tokenless uploads from them "$DIR/codecov" upload-coverage ${CODECOV_TOKEN:+-t "$CODECOV_TOKEN"} --git-service github \ --file coverage/lcov.info --disable-search --plugin noop \ || echo "Codecov upload failed" else echo "Codecov CLI download or signature check failed; skipping upload" fi node_matrix: parameters: node-version: type: string executor: node docker: - image: cimg/node:<< parameters.node-version >> steps: - halt-unless-relevant-change: flag: tests - attach_workspace: at: ~/ - restore-yarn-cache - run: command: | node --version - run: name: Install testing packages compatible with Node command: | yarn workspace @data-client/react add --dev @testing-library/react-hooks yarn workspace @data-client/test add --dev @testing-library/react-hooks yarn up react@^18 react-dom@^18 react-test-renderer@^18 - run: # --maxWorkers matches resource_class (default medium = 2 vCPU); see unit_tests command: | ANANSI_JEST_TYPECHECK=false yarn test --ci --maxWorkers=2 --selectProjects Node esmodule-types: parameters: typescript-version: type: string executor: node steps: - halt-unless-relevant-change: flag: esmodule - attach_workspace: at: ~/ - restore-yarn-cache - run: name: Install TypeScript Version command: | # Default install uses typescript=@typescript/typescript6 (API) + # @typescript/native=typescript@7 (tsc). For the compatibility matrix, # replace both with the requested compiler release so `tsc` matches. yarn up typescript@~<< parameters.typescript-version >> yarn up '@typescript/native@npm:typescript@~<< parameters.typescript-version >>' if [[ "<< parameters.typescript-version >>" == "4.0" || \ "<< parameters.typescript-version >>" == "4.1" || \ "<< parameters.typescript-version >>" == "4.3" ]]; then yarn up @types/react@ts<< parameters.typescript-version >> fi # TS < 5.0 doesn't support moduleResolution: "bundler" if [[ "<< parameters.typescript-version >>" < "5.0" ]]; then node -e "for (const f of ['examples/todo-app/tsconfig.json','examples/github-app/tsconfig.json']) { const c=JSON.parse(require('fs').readFileSync(f,'utf8')); c.compilerOptions.moduleResolution='node'; require('fs').writeFileSync(f,JSON.stringify(c,null,2)); }" fi # TS < 4.1 requires baseUrl when paths is set if [[ "<< parameters.typescript-version >>" < "4.1" ]]; then node -e "for (const f of ['examples/todo-app/tsconfig.json','examples/github-app/tsconfig.json']) { const c=JSON.parse(require('fs').readFileSync(f,'utf8')); c.compilerOptions.baseUrl='.'; require('fs').writeFileSync(f,JSON.stringify(c,null,2)); }" fi - run: name: Run Typecheck command: | # Full apps import linaria, whose types need TypeScript 5.0+ if [[ ! "<< parameters.typescript-version >>" < "5.0" ]]; then yarn run tsc --project examples/todo-app/tsconfig.json yarn run tsc --project examples/github-app/tsconfig.json fi if [ "<< parameters.typescript-version >>" != "4.0" ]; then yarn run tsc --project examples/todo-app/tsconfig.typetest41.json fi yarn run tsc --project examples/todo-app/tsconfig.typetest.json yarn run tsc --project examples/github-app/tsconfig.typetest.json # skipLibCheck: false, so the legacy typesVersions outputs get checked too yarn run tsc --project examples/todo-app/tsconfig.typetest-libcheck.json # Every published entry point's declarations must parse on this TypeScript node scripts/check-dts-parse.mjs # Vue's own types need TypeScript 4.5+ if [[ ! "<< parameters.typescript-version >>" < "4.5" ]]; then yarn run tsc --project examples/todo-app/tsconfig.typetest-vue.json fi esmodule-types-latest: executor: node steps: - halt-unless-relevant-change: flag: esmodule - attach_workspace: at: ~/ - run: name: Run Typecheck command: | yarn run tsc --project examples/todo-app/tsconfig.json yarn run tsc --project examples/github-app/tsconfig.json yarn run tsc --project examples/todo-app/tsconfig.typetest.json yarn run tsc --project examples/github-app/tsconfig.typetest.json yarn run tsc --project examples/todo-app/tsconfig.typetest41.json yarn run tsc --project examples/todo-app/tsconfig.json --strictNullChecks false yarn run tsc --project examples/github-app/tsconfig.json --strictNullChecks false yarn run tsc --project examples/todo-app/tsconfig.typetest.json --strictNullChecks false yarn run tsc --project examples/github-app/tsconfig.typetest.json --strictNullChecks false yarn run tsc --project examples/todo-app/tsconfig.typetest41.json --strictNullChecks false yarn run tsc --project examples/todo-app/tsconfig.typetest.json --exactOptionalPropertyTypes true yarn run tsc --project examples/github-app/tsconfig.typetest.json --exactOptionalPropertyTypes true yarn run tsc --project examples/todo-app/tsconfig.typetest41.json --exactOptionalPropertyTypes true # skipLibCheck: false on lib/ too (TS 7 removed moduleResolution node) yarn run tsc --project examples/todo-app/tsconfig.typetest-libcheck.json --moduleResolution bundler yarn run tsc --project examples/todo-app/tsconfig.typetest-vue.json --moduleResolution bundler validate-esmodule-browser-build: executor: node steps: - halt-unless-relevant-change: flag: esmodule - attach_workspace: at: ~/ - run: yarn run ci:build:esmodule - run: command: | cd examples/todo-app yarn run build:browser --env readable - run: command: | cd examples/normalizr-relationships yarn run start package-exports: executor: node resource_class: large steps: - halt-unless-relevant-change: flag: esmodule - attach_workspace: at: ~/ # prepack reads files setup's workspace leaves out (skills in .agents/; # persisting them would make skill-only changes rerun every test job). # Checked out beside the project, since checkout refuses a non-empty # directory, then copied in without replacing the workspace's files. - checkout: path: ~/repo - run: cp -R --update=none ~/repo/. ~/project/ - run: name: Check published package entry points command: yarn run check:package-exports tree-passed: # Runs only once every job passed (a halted job counts), so later # pipelines on the same tree (the merge queue, then master) skip the work docker: *docker resource_class: small steps: - restore_cache: keys: - *relevance-cache-key - run: # So the key below always has a file to hash name: Default the diff base tree command: touch .ci-base-tree - restore_cache: # Restores the base tree's own marker as .ci-tree-passed, if it passed keys: - ci-passed-v1-{{ checksum ".ci-base-tree" }} - run: name: Mark tree passed command: | halt() { echo "$1; not marking this tree passed."; circleci-agent step halt; exit 0; } # Never for fork PRs (CIRCLE_PR_NUMBER is only set on those) [ -z "${CIRCLE_PR_NUMBER:-}" ] || halt "Fork PR" # Missing or odd flags prove nothing, so fail closed TESTS="$(cat .ci-tests-relevant 2>/dev/null)" || TESTS='' ESMODULE="$(cat .ci-esmodule-relevant 2>/dev/null)" || ESMODULE='' FLAGS="${TESTS} ${ESMODULE}" [[ "${FLAGS}" =~ ^(true|false)\ (true|false)$ ]] && [ -s .ci-tree ] || halt "No relevance flags or tree hash" if [ "${FLAGS}" = "true true" ]; then echo "Every job ran and passed." # A path-filtered run proves only that the change since the diff # base is irrelevant to the halted jobs, so it needs the base's marker elif cmp -s .ci-base-tree .ci-tree-passed; then echo "Halted jobs passed on base tree $(cat .ci-base-tree), and nothing they read changed since." else halt "Some jobs halted and the base tree has no marker" fi cp .ci-tree .ci-tree-passed - save_cache: key: ci-passed-v1-{{ checksum ".ci-tree" }} paths: - .ci-tree-passed workflows: version: 2 validation: jobs: - setup - unit_tests: matrix: parameters: react-version: ["^17", "^18", "native", "latest"] requires: - setup - node_matrix: matrix: parameters: # Babel 8 (our test transform) needs Node ^22.18 || >=24.11 node-version: ["22.18", "24.11"] requires: - setup - lint: requires: - setup - typecheck: requires: - setup - validate-esmodule-browser-build: requires: - setup - esmodule-types-latest: requires: - setup - package-exports: requires: - setup - esmodule-types: matrix: parameters: # 3.7 is min version for 'full enforcement' (TODO: we need to do a test without rest lib for this to work) # 4.0 is min version for rest package working # 4.1 is min version for rest package working well # 4.3 # 4.7 (but its broken so we do 4.8) lets you apply a generic type to a function type to see its return value typescript-version: ["4.0", "4.1", "4.3", "4.8", "5.3"] requires: - setup - tree-passed: requires: - unit_tests - node_matrix - lint - typecheck - validate-esmodule-browser-build - esmodule-types-latest - esmodule-types - package-exports