Code Monkey home page Code Monkey logo

es-shims / disposablestack Goto Github PK

View Code? Open in Web Editor NEW
17.0 3.0 3.0 153 KB

An ESnext spec-compliant `DisposableStack`, `AsyncDisposableStack`, `Symbol.dispose`, and `Symbol.asyncDispose` shim/polyfill/replacement that works as far down as ES3.

Home Page: https://tc39.es/proposal-explicit-resource-management/#sec-disposablestack-constructor

License: MIT License

JavaScript 100.00%
dispose ecmascript javascript management polyfill resource shim using disposablestack

disposablestack's Introduction

disposablestack Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

An ESnext spec-compliant DisposableStack, AsyncDisposableStack, Symbol.dispose, and Symbol.asyncDispose shim/polyfill/replacement that works as far down as ES3.

Its root auto entrypoint also provides SuppressedError, via the suppressed-error package.

This package implements the es-shim API β€œmulti” interface. It works in an ES3-supported environment and complies with the proposed spec.

Getting started

npm install --save disposablestack

Usage/Examples

const assert = require('assert');

require('disposablestack/auto');

assert.equal(typeof Symbol.dispose, 'symbol');
assert.equal(typeof Symbol.asyncDispose, 'symbol');

const error = new SuppressedError();
assert.ok(error instanceof Error);

const stack = new DisposableStack();

const asyncStack = new AsyncDisposableStack();

// examples of stack methods

stack.dispose();

await asyncStack.disposeAsync();

// assert disposal was done

Tests

Clone the repo, npm install, and run npm test

disposablestack's People

Contributors

ljharb avatar sebmck avatar soulofmischief avatar teatimeguest avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

disposablestack's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Pending Approval

These branches will be created by Renovate only once you click their checkbox below.

  • [Deps] Update Update eslint to v8.57.0
  • [Deps] Update Update eslint to v9
  • [Deps] Update Update nyc to v15
  • [Deps] Update Update semver to v7
  • πŸ” Create all pending approval PRs at once πŸ”

Detected dependencies

github-actions
.github/workflows/node-aught.yml
.github/workflows/node-pretest.yml
.github/workflows/node-tens.yml
.github/workflows/rebase.yml
.github/workflows/require-allow-edits.yml
npm
package.json
  • call-bind ^1.0.7
  • define-properties ^1.2.1
  • es-abstract ^1.23.3
  • es-errors ^1.3.0
  • es-set-tostringtag ^2.0.3
  • get-intrinsic ^1.2.4
  • globalthis ^1.0.4
  • has-symbols ^1.0.3
  • hasown ^2.0.2
  • internal-slot ^1.0.7
  • suppressed-error ^1.0.3
  • @es-shims/api ^2.5.0
  • @ljharb/eslint-config ^21.1.1
  • aud ^2.0.4
  • auto-changelog ^2.4.0
  • es-value-fixtures ^1.4.2
  • eslint =8.8.0
  • foreach ^2.0.6
  • has-property-descriptors ^1.0.2
  • has-tostringtag ^1.0.2
  • in-publish ^2.0.1
  • is-registered-symbol ^1.0.1
  • is-symbol ^1.0.4
  • npmignore ^0.3.1
  • nyc ^10.3.2
  • object-inspect ^1.13.1
  • safe-publish-latest ^2.0.0
  • semver ^6.3.1
  • tape ^5.7.5
  • node >= 0.4

  • Check this box to trigger a request for Renovate to run again on this repository

Missing call-bind dependency

Recent versions of Yarn (e.g., 4.2.2) detect that disposablestack attempts to access call-bind, but call-bind is not listed as a dependency. It fails as follows:

% yarn add disposablestack

% yarn node -e "require('disposablestack/auto')"
/private/tmp/.pnp.cjs:6414
    throw firstError;
    ^

Error: disposablestack tried to access call-bind, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: call-bind
Required by: disposablestack@npm:1.1.4 (via /Users/mark/.yarn/berry/cache/disposablestack-npm-1.1.4-cd1f88f9e7-10c0.zip/node_modules/disposablestack/DisposableStack/)

Require stack:
- /Users/mark/.yarn/berry/cache/disposablestack-npm-1.1.4-cd1f88f9e7-10c0.zip/node_modules/disposablestack/DisposableStack/implementation.js
- /Users/mark/.yarn/berry/cache/disposablestack-npm-1.1.4-cd1f88f9e7-10c0.zip/node_modules/disposablestack/DisposableStack/polyfill.js
- /Users/mark/.yarn/berry/cache/disposablestack-npm-1.1.4-cd1f88f9e7-10c0.zip/node_modules/disposablestack/DisposableStack/shim.js
- /Users/mark/.yarn/berry/cache/disposablestack-npm-1.1.4-cd1f88f9e7-10c0.zip/node_modules/disposablestack/shim.js
- /Users/mark/.yarn/berry/cache/disposablestack-npm-1.1.4-cd1f88f9e7-10c0.zip/node_modules/disposablestack/auto.js
- /private/tmp/[eval]
    at require$$0.Module._resolveFilename (/private/tmp/.pnp.cjs:6413:13)
    at Module._load (node:internal/modules/cjs/loader:984:27)
    at require$$0.Module._load (/private/tmp/.pnp.cjs:6304:31)
    at Module.require (node:internal/modules/cjs/loader:1231:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/Users/mark/.yarn/berry/cache/disposablestack-npm-1.1.4-cd1f88f9e7-10c0.zip/node_modules/disposablestack/DisposableStack/implementation.js:17:16)
    at Module._compile (node:internal/modules/cjs/loader:1369:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
    at require$$0.Module._extensions..js (/private/tmp/.pnp.cjs:6456:33)
    at Module.load (node:internal/modules/cjs/loader:1206:32)

Node.js v20.12.2

This can be worked around with a package extension

% cat .yarnrc.yml
packageExtensions:
  "disposablestack@*":
    dependencies:
      call-bind: "*"

% yarn install

% yarn node -e "require('disposablestack/auto')"

However, can we add call-bind to disposablestack's dependencies to avoid this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.