mirror of
https://github.com/tenrok/axios.git
synced 2026-06-17 19:21:29 +03:00
13fdbec872
* chore: update changelog and update gitignore * chore: update PR and issue templates * chore: updated docs * chore: update all docs to match * chore: update both files to match * chore: remove un-needed yml * Update docs/fr/pages/advanced/error-handling.md Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * Update docs/es/pages/advanced/x-www-form-urlencoded-format.md Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * Update docs/pages/advanced/error-handling.md Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * Update docs/es/pages/advanced/error-handling.md Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * Update docs/pages/advanced/x-www-form-urlencoded-format.md Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * Update docs/zh/pages/advanced/x-www-form-urlencoded-format.md Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * Update docs/zh/pages/advanced/request-config.md Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * Update docs/zh/pages/advanced/request-config.md Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * Update docs/pages/advanced/request-config.md Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * Update docs/fr/pages/advanced/x-www-form-urlencoded-format.md Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * Update docs/zh/pages/advanced/error-handling.md Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * Update docs/zh/pages/advanced/request-config.md Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --------- Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
3.9 KiB
3.9 KiB
GitHub Copilot Instructions
The canonical contributor guide for this repo is AGENTS.md. It covers setup, commands, package shape, architecture boundaries, naming, error handling, interceptor order, the request lifecycle, cancellation, common pitfalls, tests, and security-sensitive code.
The rules below are a Copilot-facing subset of the load-bearing safety guarantees from AGENTS.md. If they ever drift, AGENTS.md is authoritative — update both.
Setup safety
- Install with
npm ci; the repo's.npmrcsetsignore-scripts=true. Do not remove that flag. If husky hooks are needed after a fresh install, runnpm rebuild husky && npx huskyonce. - Do not add new runtime dependencies without discussion.
package-lock.jsonis verified bylockfile-lintfor npm HTTPS hosts and integrity hashes.
Architecture in one screen
lib/core/— domain logic:Axios,AxiosError,AxiosHeaders,InterceptorManager, config merge, request dispatch.lib/adapters/— I/O:xhr.js,http.js,fetch.js. Default preference['xhr', 'http', 'fetch'], picked by capability detection inlib/adapters/adapters.js. Never branch on environment name.lib/platform/— Node by default; browser builds alias tolib/platform/browser.lib/helpers/— generic, reusable utilities; no axios-specific lifecycle logic here.- Source is ESM (
type: module) with explicit.jsimport extensions.dist/is generated by Rollup — never edit it by hand. Keepindex.d.ts(ESM) andindex.d.cts(CJS) in sync for any public API change.
Error handling
- Throw
AxiosError(message, code, config, request, response)for axios-originated failures; never rawError. - Wrap third-party errors with
AxiosError.from(error, code, config, request, response). - Use a code from
lib/core/AxiosError.js(ERR_NETWORK,ETIMEDOUT,ECONNABORTED,ERR_CANCELED,ERR_BAD_REQUEST,ERR_BAD_RESPONSE,ERR_FR_TOO_MANY_REDIRECTS,ERR_FORM_DATA_DEPTH_EXCEEDED,ERR_INVALID_URL,ERR_BAD_OPTION,ERR_BAD_OPTION_VALUE,ERR_NOT_SUPPORT,ERR_DEPRECATED,ECONNREFUSED).
Interceptor order
- Request interceptors run LIFO (last-registered-first); response interceptors run FIFO. Both support
synchronous: trueandrunWhen(config).
Naming and style
- PascalCase classes (
Axios,AxiosHeaders), camelCase functions (buildURL,mergeConfig), UPPER_SNAKE_CASE error codes. - Internal slots use
Symbol-keyed properties (see$internalsinlib/core/AxiosHeaders.js), not underscore-prefixed names. - Use
lib/helpers/bind.js, notFunction.prototype.bind, when binding library functions — the helper forwardsargumentsviaapply. 'use strict';appears at the top of files that already use it; match the surrounding file rather than blanket-adding it.
Security guarantees that must not regress
- For config reads on potentially untrusted input, use own-property checks (
utils.hasOwnProp/ localown()helpers); neverin, destructuring, or directconfig.fooaccess. - Any merge or object materialization must continue to filter
__proto__,constructor, andprototype. Regressions here are security bugs. - Changes touching URL construction, redirects, proxy/env handling, XSRF, socket paths, decompression limits, or adapters require consulting
THREATMODEL.mdand adding focused regression tests. withXSRFToken === trueis the only thing that forces cross-origin XSRF header attachment — keep that behavior explicit.- Do not weaken
beforeRedirect, proxy, orsocketPathsafeguards without tests covering credential leakage and SSRF-style cases.
Common pitfalls
- Do not mutate config objects in place; return new ones from merges/transforms.
- Do not assume browser- or Node-only globals exist; capability-check first.
- Validate options through the existing
validatorhelper rather than inventing ad-hoc validation paths.