mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
90ae1993e0
* chore: remove readme code for sponsors this will be done manually from here on out * docs: added agents.md
4.2 KiB
4.2 KiB
AGENTS.md
Setup And Safety
- Use
npm ci; repo.npmrcsetsignore-scripts=true, and CI also usesnpm ci --ignore-scripts. - Do not remove
ignore-scripts=true; if git hooks are needed after a fresh install, runnpm rebuild husky && npx huskyonce. - Adding or updating dependencies is security-sensitive;
package-lock.jsonis checked bylockfile-lintfor npm HTTPS hosts and integrity hashes. - Build/test/lint tools still execute dependency code despite
ignore-scripts; avoid unnecessary full builds when a focused check proves the change.
Commands
- Build published artifacts:
npm run build(gulp cleardeletesdist/, then Rollup writes browser ESM/UMD/CJS and Node CJS bundles). - Lint source only:
npm run lint; focused lint:npx eslint lib/path/to/file.js. - Unit tests:
npm run test:vitest:unit; focused unit test:npm run test:vitest:unit -- tests/unit/path.test.js. - Browser tests need Playwright installed first (
npx playwright installlocally; CI usesnpx playwright install --with-deps); runnpm run test:vitest:browser:headlessfor CI parity. - Smoke/module compatibility suites test the packed package, not the source tree: run
npm run build,npm pack, install the tarball into the relevanttests/smoke/*ortests/module/*package, then run that suite's npm script. - CI order is install -> build -> Playwright install -> unit -> browser headless -> pack -> CJS/ESM module and smoke tests -> Bun/Deno smoke tests.
Package Shape
- Source is ESM (
type: module); public ESM entry isindex.js, which re-exports the default instance fromlib/axios.js. - Do not edit
dist/by hand; it is ignored and generated fromlib/by Rollup. - Runtime package exports are split by environment: browser/react-native map Node HTTP/platform files to browser/null replacements, while Node CJS ships as
dist/node/axios.cjs. - Keep public runtime exports,
index.d.ts(ESM types), andindex.d.cts(CJSexport = axiostypes) in sync for API changes. lib/env/data.jsis version-generated bygulp version; do not edit it for normal feature work.
Architecture Boundaries
lib/core/is axios domain logic: request dispatch, config merge, interceptors, headers, errors.lib/adapters/performs I/O; default adapter preference is['xhr', 'http', 'fetch'], with capability selection inlib/adapters/adapters.js.lib/platform/selects Node by default; browser builds rely on package/rollup aliasing tolib/platform/browser.lib/helpers/should stay generic and reusable outside axios; do not put axios-specific request lifecycle logic there.- New
lib/**/*.jsfiles should match existing source style: ESM imports with explicit.jsextensions,'use strict';where current library files use it, andAxiosErrorfor axios-originated failures.
Tests
- Test layout is runtime-first:
tests/unit/**/*.test.js,tests/browser/**/*.browser.test.js,tests/smoke/esm/**/*.smoke.test.js,tests/smoke/cjs/**/*.smoke.test.cjs. - Use
tests/setup/server.jsfor local HTTP servers and cleanup withtry/finally; leaking servers causes Vitest hangs. - Keep CJS and ESM smoke coverage aligned when behavior is packaging/import related.
- Type compatibility is exercised through
tests/module/cjswith TypeScript 4.9 andtests/module/esmwith TypeScript 5.x; run the matching module suite for declaration changes. - Browser tests replace globals such as XHR; restore globals and reset spies in cleanup hooks.
Security-Sensitive Code
- For config reads that affect behavior, do not use prototype-walking reads (
in, destructuring, or directconfig.fooon untrusted config); guard with own-property checks as inutils.hasOwnProp/ localown()helpers. - New merge or object materialization code must continue filtering
__proto__,constructor, andprototype; regressions here are security bugs. - Changes touching URL construction, redirects, proxy/env handling, XSRF, socket paths, decompression limits, or adapters should consult
THREATMODEL.mdand add focused regression tests. - Keep
withXSRFTokencross-origin behavior explicit: onlytrueforces cross-origin XSRF header attachment. - Do not weaken
beforeRedirect, proxy, orsocketPathsafeguards without tests covering credential leakage or SSRF-style cases.