Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

revertable-globals

jaydenseric111MIT4.0.0

Sets globals that can be easily reverted to restore the original environment; useful for testing code that relies on the presence of certain globals.

revertable, temporary, global, globals, esm, mjs

readme

revertable-globals

Sets globals in a JavaScript environment that can be easily reverted to restore the original environment; useful for testing code that relies on the presence of certain globals.

Installation

For Node.js, to install revertable-globals with npm, run:

npm install revertable-globals --save-dev

For Deno, an example import map:

{
  "imports": {
    "revertable-globals": "https://unpkg.com/revertable-globals@4.0.0/revertableGlobals.mjs"
  }
}

Then, import and use the function revertableGlobals.

Requirements

Supported runtime environments:

  • Node.js versions ^14.17.0 || ^16.0.0 || >= 18.0.0.
  • Deno.

Non Deno projects must configure TypeScript to use types from the ECMAScript modules that have a // @ts-check comment:

Exports

The npm package revertable-globals features optimal JavaScript module design. These ECMAScript modules are exported via the package.json field exports:

changelog

revertable-globals changelog

4.0.0

Major

  • Updated Node.js support to ^14.17.0 || ^16.0.0 || >= 18.0.0.
  • Updated dev dependencies, some of which require newer Node.js versions than previously supported.
  • Removed the package main field.
  • Use the node: URL scheme for Node.js builtin module imports in tests.

Patch

  • Simplified dev dependencies and config for ESLint.
  • Updated jsconfig.json:
    • Set compilerOptions.maxNodeModuleJsDepth to 10.
    • Set compilerOptions.module to nodenext.
  • Updated GitHub Actions CI config:
    • Run tests with Node.js v14, v16, v18.
    • Updated actions/checkout to v3.
    • Updated actions/setup-node to v3.
  • Replaced TypeScript Record types with index signatures.
  • Updated the JSDoc code examples.
  • Revamped the readme:
    • Removed the badges.
    • Removed the detailed API docs. The JSDoc comments and TypeScript types in the exported modules are now the primary documentation.
    • Added a “Requirements” section.
    • Added information about Deno, import maps, TypeScript config and optimal JavaScript module design.

3.0.0

Major

  • Updated Node.js support to ^12.22.0 || ^14.17.0 || >= 16.0.0.
  • Updated dev dependencies, some of which require newer Node.js versions than previously supported.
  • Removed ./package from the package exports field; the full package.json filename must be used in a require path.
  • Renamed index.mjs to revertableGlobals.mjs and added it to the package exports field.
  • Implemented TypeScript types via JSDoc comments.

Patch

  • Also run GitHub Actions CI with Node.js v17.
  • Simplified package scripts.
  • Check TypeScript types via a new package types script.
  • Removed the jsdoc-md dev dependency and the related package scripts, replacing the readme “API” section with a manually written “Exports” section.
  • Configured Prettier option singleQuote to the default, false.
  • Documentation tweaks.

2.0.0

Major

  • Updated Node.js support to ^12.20 || >= 14.13.
  • Updated dev dependencies, some of which require newer Node.js versions than were previously supported.
  • Added a package exports field.
  • The API is now ESM in .mjs files instead of CJS in .js files, accessible via import but not require.
  • Default the function revertableGlobals argument 2 namespace to the universal globalThis instead of the Node.js global.

Patch

  • Stop using hard-rejection to detect unhandled Promise rejections in tests, as Node.js v15+ does this natively.
  • Simplified the package scripts now that jsdoc-md v10 automatically generates a Prettier formatted readme.
  • Updated GitHub Actions CI config:
    • Also run tests with Node.js v16.
    • Updated actions/checkout to v2.
    • Updated actions/setup-node to v2.
    • Don’t specify the CI environment variable as it’s set by default.
  • Readme tweaks.

1.1.0

Minor

  • Allow the global namespace to be specified and add an example for how to set and revert an environment variable at runtime.

Patch

  • Updated dependencies.
  • Also test Node.js v15 in GitHub Actions CI.

1.0.1

Patch

1.0.0

Initial release.