chore: implement disposable stack polyfill (#10797)

This commit is contained in:
jrandolf 2023-08-29 16:33:54 +02:00 committed by GitHub
parent eb489a64d2
commit 6f2e3db883
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 434 additions and 16 deletions

333
package-lock.json generated
View File

@ -18,6 +18,7 @@
"@microsoft/api-extractor-model": "7.27.6",
"@pptr/testserver": "file:packages/testserver",
"@prettier/sync": "0.3.0",
"@rollup/plugin-commonjs": "25.0.4",
"@rollup/plugin-node-resolve": "15.2.1",
"@rollup/plugin-terser": "0.4.3",
"@types/debug": "4.1.8",
@ -66,6 +67,7 @@
"puppeteer": "file:packages/puppeteer",
"rimraf": "5.0.1",
"rollup": "3.28.1",
"rollup-plugin-polyfill-node": "0.12.0",
"semver": "7.5.4",
"sinon": "15.2.0",
"source-map-support": "0.5.21",
@ -1875,6 +1877,117 @@
"resolved": "packages/ng-schematics",
"link": true
},
"node_modules/@rollup/plugin-commonjs": {
"version": "25.0.4",
"resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-25.0.4.tgz",
"integrity": "sha512-L92Vz9WUZXDnlQQl3EwbypJR4+DM2EbsO+/KOcEkP4Mc6Ct453EeDB2uH9lgRwj4w5yflgNpq9pHOiY8aoUXBQ==",
"dev": true,
"dependencies": {
"@rollup/pluginutils": "^5.0.1",
"commondir": "^1.0.1",
"estree-walker": "^2.0.2",
"glob": "^8.0.3",
"is-reference": "1.2.1",
"magic-string": "^0.27.0"
},
"engines": {
"node": ">=14.0.0"
},
"peerDependencies": {
"rollup": "^2.68.0||^3.0.0"
},
"peerDependenciesMeta": {
"rollup": {
"optional": true
}
}
},
"node_modules/@rollup/plugin-commonjs/node_modules/brace-expansion": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
"integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
"dev": true,
"dependencies": {
"balanced-match": "^1.0.0"
}
},
"node_modules/@rollup/plugin-commonjs/node_modules/glob": {
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz",
"integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==",
"dev": true,
"dependencies": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^5.0.1",
"once": "^1.3.0"
},
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/@rollup/plugin-commonjs/node_modules/magic-string": {
"version": "0.27.0",
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.27.0.tgz",
"integrity": "sha512-8UnnX2PeRAPZuN12svgR9j7M1uWMovg/CEnIwIG0LFkXSJJe4PdfUGiTGl8V9bsBHFUtfVINcSyYxd7q+kx9fA==",
"dev": true,
"dependencies": {
"@jridgewell/sourcemap-codec": "^1.4.13"
},
"engines": {
"node": ">=12"
}
},
"node_modules/@rollup/plugin-commonjs/node_modules/minimatch": {
"version": "5.1.6",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz",
"integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==",
"dev": true,
"dependencies": {
"brace-expansion": "^2.0.1"
},
"engines": {
"node": ">=10"
}
},
"node_modules/@rollup/plugin-inject": {
"version": "5.0.3",
"resolved": "https://registry.npmjs.org/@rollup/plugin-inject/-/plugin-inject-5.0.3.tgz",
"integrity": "sha512-411QlbL+z2yXpRWFXSmw/teQRMkXcAAC8aYTemc15gwJRpvEVDQwoe+N/HTFD8RFG8+88Bme9DK2V9CVm7hJdA==",
"dev": true,
"dependencies": {
"@rollup/pluginutils": "^5.0.1",
"estree-walker": "^2.0.2",
"magic-string": "^0.27.0"
},
"engines": {
"node": ">=14.0.0"
},
"peerDependencies": {
"rollup": "^1.20.0||^2.0.0||^3.0.0"
},
"peerDependenciesMeta": {
"rollup": {
"optional": true
}
}
},
"node_modules/@rollup/plugin-inject/node_modules/magic-string": {
"version": "0.27.0",
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.27.0.tgz",
"integrity": "sha512-8UnnX2PeRAPZuN12svgR9j7M1uWMovg/CEnIwIG0LFkXSJJe4PdfUGiTGl8V9bsBHFUtfVINcSyYxd7q+kx9fA==",
"dev": true,
"dependencies": {
"@jridgewell/sourcemap-codec": "^1.4.13"
},
"engines": {
"node": ">=12"
}
},
"node_modules/@rollup/plugin-node-resolve": {
"version": "15.2.1",
"resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.2.1.tgz",
@ -1957,11 +2070,6 @@
}
}
},
"node_modules/@rollup/pluginutils/node_modules/estree-walker": {
"version": "2.0.2",
"dev": true,
"license": "MIT"
},
"node_modules/@rushstack/node-core-library": {
"version": "3.59.7",
"resolved": "https://registry.npmjs.org/@rushstack/node-core-library/-/node-core-library-3.59.7.tgz",
@ -3433,6 +3541,12 @@
"node": "^12.20.0 || >=14"
}
},
"node_modules/commondir": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz",
"integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==",
"dev": true
},
"node_modules/commonmark": {
"version": "0.30.0",
"dev": true,
@ -3856,6 +3970,21 @@
"node": ">=8"
}
},
"node_modules/disposablestack": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/disposablestack/-/disposablestack-1.1.1.tgz",
"integrity": "sha512-Kt80F3SgFOnAGyUj+VbOhLEdrjnii4sphhqlTgaSiLaVRaKr3QsW6QGgILxiEt2pBOG694f9fcVtuuNP7cFWnQ==",
"dev": true,
"dependencies": {
"define-properties": "^1.2.0",
"es-abstract": "^1.22.1",
"es-set-tostringtag": "^2.0.1",
"get-intrinsic": "^1.2.1",
"has-symbols": "^1.0.3",
"internal-slot": "^1.0.5",
"suppressed-error": "^1.0.0"
}
},
"node_modules/doctrine": {
"version": "3.0.0",
"dev": true,
@ -4723,6 +4852,12 @@
"node": ">=4.0"
}
},
"node_modules/estree-walker": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz",
"integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==",
"dev": true
},
"node_modules/esutils": {
"version": "2.0.3",
"license": "BSD-2-Clause",
@ -6454,6 +6589,15 @@
"node": ">=0.10.0"
}
},
"node_modules/is-reference": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz",
"integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==",
"dev": true,
"dependencies": {
"@types/estree": "*"
}
},
"node_modules/is-regex": {
"version": "1.1.4",
"dev": true,
@ -9398,6 +9542,18 @@
"fsevents": "~2.3.2"
}
},
"node_modules/rollup-plugin-polyfill-node": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/rollup-plugin-polyfill-node/-/rollup-plugin-polyfill-node-0.12.0.tgz",
"integrity": "sha512-PWEVfDxLEKt8JX1nZ0NkUAgXpkZMTb85rO/Ru9AQ69wYW8VUCfDgP4CGRXXWYni5wDF0vIeR1UoF3Jmw/Lt3Ug==",
"dev": true,
"dependencies": {
"@rollup/plugin-inject": "^5.0.1"
},
"peerDependencies": {
"rollup": "^1.20.0 || ^2.0.0 || ^3.0.0"
}
},
"node_modules/run-applescript": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/run-applescript/-/run-applescript-5.0.0.tgz",
@ -9996,6 +10152,27 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/suppressed-error": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/suppressed-error/-/suppressed-error-1.0.0.tgz",
"integrity": "sha512-vSxeOCv6K6F7WEmHp1oLaEkLG88U2nvSTwD+Y63VsyR3tyKLbVCfgmnBIQA5KHH5HtQm+AT3WySUuI1cUnUmuw==",
"dev": true,
"dependencies": {
"define-properties": "^1.1.4",
"es-abstract": "^1.21.1",
"function-bind": "^1.1.1",
"functions-have-names": "^1.2.3",
"get-intrinsic": "^1.2.0",
"globalthis": "^1.0.3",
"has-property-descriptors": "^1.0.0"
},
"engines": {
"node": ">= 0.4"
},
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/symbol-observable": {
"version": "4.0.0",
"dev": true,
@ -10981,6 +11158,7 @@
"ws": "8.13.0"
},
"devDependencies": {
"disposablestack": "1.1.1",
"mitt": "3.0.1",
"parsel-js": "1.1.2",
"rxjs": "7.8.1"
@ -12224,6 +12402,84 @@
}
}
},
"@rollup/plugin-commonjs": {
"version": "25.0.4",
"resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-25.0.4.tgz",
"integrity": "sha512-L92Vz9WUZXDnlQQl3EwbypJR4+DM2EbsO+/KOcEkP4Mc6Ct453EeDB2uH9lgRwj4w5yflgNpq9pHOiY8aoUXBQ==",
"dev": true,
"requires": {
"@rollup/pluginutils": "^5.0.1",
"commondir": "^1.0.1",
"estree-walker": "^2.0.2",
"glob": "^8.0.3",
"is-reference": "1.2.1",
"magic-string": "^0.27.0"
},
"dependencies": {
"brace-expansion": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
"integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
"dev": true,
"requires": {
"balanced-match": "^1.0.0"
}
},
"glob": {
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz",
"integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==",
"dev": true,
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^5.0.1",
"once": "^1.3.0"
}
},
"magic-string": {
"version": "0.27.0",
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.27.0.tgz",
"integrity": "sha512-8UnnX2PeRAPZuN12svgR9j7M1uWMovg/CEnIwIG0LFkXSJJe4PdfUGiTGl8V9bsBHFUtfVINcSyYxd7q+kx9fA==",
"dev": true,
"requires": {
"@jridgewell/sourcemap-codec": "^1.4.13"
}
},
"minimatch": {
"version": "5.1.6",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz",
"integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==",
"dev": true,
"requires": {
"brace-expansion": "^2.0.1"
}
}
}
},
"@rollup/plugin-inject": {
"version": "5.0.3",
"resolved": "https://registry.npmjs.org/@rollup/plugin-inject/-/plugin-inject-5.0.3.tgz",
"integrity": "sha512-411QlbL+z2yXpRWFXSmw/teQRMkXcAAC8aYTemc15gwJRpvEVDQwoe+N/HTFD8RFG8+88Bme9DK2V9CVm7hJdA==",
"dev": true,
"requires": {
"@rollup/pluginutils": "^5.0.1",
"estree-walker": "^2.0.2",
"magic-string": "^0.27.0"
},
"dependencies": {
"magic-string": {
"version": "0.27.0",
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.27.0.tgz",
"integrity": "sha512-8UnnX2PeRAPZuN12svgR9j7M1uWMovg/CEnIwIG0LFkXSJJe4PdfUGiTGl8V9bsBHFUtfVINcSyYxd7q+kx9fA==",
"dev": true,
"requires": {
"@jridgewell/sourcemap-codec": "^1.4.13"
}
}
}
},
"@rollup/plugin-node-resolve": {
"version": "15.2.1",
"resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.2.1.tgz",
@ -12273,12 +12529,6 @@
"@types/estree": "^1.0.0",
"estree-walker": "^2.0.2",
"picomatch": "^2.3.1"
},
"dependencies": {
"estree-walker": {
"version": "2.0.2",
"dev": true
}
}
},
"@rushstack/node-core-library": {
@ -13303,6 +13553,12 @@
"dev": true,
"optional": true
},
"commondir": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz",
"integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==",
"dev": true
},
"commonmark": {
"version": "0.30.0",
"dev": true,
@ -13580,6 +13836,21 @@
"path-type": "^4.0.0"
}
},
"disposablestack": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/disposablestack/-/disposablestack-1.1.1.tgz",
"integrity": "sha512-Kt80F3SgFOnAGyUj+VbOhLEdrjnii4sphhqlTgaSiLaVRaKr3QsW6QGgILxiEt2pBOG694f9fcVtuuNP7cFWnQ==",
"dev": true,
"requires": {
"define-properties": "^1.2.0",
"es-abstract": "^1.22.1",
"es-set-tostringtag": "^2.0.1",
"get-intrinsic": "^1.2.1",
"has-symbols": "^1.0.3",
"internal-slot": "^1.0.5",
"suppressed-error": "^1.0.0"
}
},
"doctrine": {
"version": "3.0.0",
"dev": true,
@ -14189,6 +14460,12 @@
"resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz",
"integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw=="
},
"estree-walker": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz",
"integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==",
"dev": true
},
"esutils": {
"version": "2.0.3"
},
@ -15310,6 +15587,15 @@
"version": "1.1.0",
"dev": true
},
"is-reference": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz",
"integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==",
"dev": true,
"requires": {
"@types/estree": "*"
}
},
"is-regex": {
"version": "1.1.4",
"dev": true,
@ -17019,6 +17305,7 @@
"cross-fetch": "4.0.0",
"debug": "4.3.4",
"devtools-protocol": "0.0.1159816",
"disposablestack": "1.1.1",
"mitt": "3.0.1",
"parsel-js": "1.1.2",
"rxjs": "7.8.1",
@ -17426,6 +17713,15 @@
"fsevents": "~2.3.2"
}
},
"rollup-plugin-polyfill-node": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/rollup-plugin-polyfill-node/-/rollup-plugin-polyfill-node-0.12.0.tgz",
"integrity": "sha512-PWEVfDxLEKt8JX1nZ0NkUAgXpkZMTb85rO/Ru9AQ69wYW8VUCfDgP4CGRXXWYni5wDF0vIeR1UoF3Jmw/Lt3Ug==",
"dev": true,
"requires": {
"@rollup/plugin-inject": "^5.0.1"
}
},
"run-applescript": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/run-applescript/-/run-applescript-5.0.0.tgz",
@ -17828,6 +18124,21 @@
"version": "1.0.0",
"dev": true
},
"suppressed-error": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/suppressed-error/-/suppressed-error-1.0.0.tgz",
"integrity": "sha512-vSxeOCv6K6F7WEmHp1oLaEkLG88U2nvSTwD+Y63VsyR3tyKLbVCfgmnBIQA5KHH5HtQm+AT3WySUuI1cUnUmuw==",
"dev": true,
"requires": {
"define-properties": "^1.1.4",
"es-abstract": "^1.21.1",
"function-bind": "^1.1.1",
"functions-have-names": "^1.2.3",
"get-intrinsic": "^1.2.0",
"globalthis": "^1.0.3",
"has-property-descriptors": "^1.0.0"
}
},
"symbol-observable": {
"version": "4.0.0",
"dev": true

View File

@ -110,6 +110,7 @@
"@microsoft/api-extractor-model": "7.27.6",
"@pptr/testserver": "file:packages/testserver",
"@prettier/sync": "0.3.0",
"@rollup/plugin-commonjs": "25.0.4",
"@rollup/plugin-node-resolve": "15.2.1",
"@rollup/plugin-terser": "0.4.3",
"@types/debug": "4.1.8",
@ -158,6 +159,7 @@
"puppeteer": "file:packages/puppeteer",
"rimraf": "5.0.1",
"rollup": "3.28.1",
"rollup-plugin-polyfill-node": "0.12.0",
"semver": "7.5.4",
"sinon": "15.2.0",
"source-map-support": "0.5.21",

View File

@ -144,16 +144,17 @@
"author": "The Chromium Authors",
"license": "Apache-2.0",
"dependencies": {
"@puppeteer/browsers": "1.7.0",
"chromium-bidi": "0.4.22",
"cross-fetch": "4.0.0",
"debug": "4.3.4",
"devtools-protocol": "0.0.1159816",
"ws": "8.13.0",
"@puppeteer/browsers": "1.7.0"
"ws": "8.13.0"
},
"devDependencies": {
"rxjs": "7.8.1",
"disposablestack": "1.1.1",
"mitt": "3.0.1",
"parsel-js": "1.1.2"
"parsel-js": "1.1.2",
"rxjs": "7.8.1"
}
}

View File

@ -13,9 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import commonjs from '@rollup/plugin-commonjs';
import {nodeResolve} from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
import {globSync} from 'glob';
import nodePolyfills from 'rollup-plugin-polyfill-node';
const configs = [];
@ -34,7 +36,16 @@ for (const file of globSync(`lib/esm/third_party/**/*.js`)) {
format: 'cjs',
},
],
plugins: [terser(), nodeResolve()],
plugins: [
terser(),
nodeResolve(),
// This is used internally within the polyfill. It gets ignored for the
// most part via this plugin.
nodePolyfills({include: ['util']}),
commonjs({
transformMixedEsModules: true,
}),
],
});
}

View File

@ -0,0 +1,93 @@
import 'disposablestack/auto';
declare global {
class DisposableStack implements Disposable {
constructor();
/**
* Gets a value indicating whether the stack has been disposed.
*/
get disposed(): boolean;
/**
* Alias for `[Symbol.dispose]()`.
*/
dispose(): void;
/**
* Adds a resource to the top of the stack. Has no effect if provided `null`
* or `undefined`.
*/
use<T>(value: T): T;
/**
* Adds a non-disposable resource and a disposal callback to the top of the
* stack.
*/
adopt<T>(value: T, onDispose: (value: T) => void): T;
/**
* Adds a disposal callback to the top of the stack.
*/
defer(onDispose: () => void): void;
/**
* Moves all resources currently in this stack into a new `DisposableStack`.
*/
move(): DisposableStack;
/**
* Disposes of resources within this object.
*/
[Symbol.dispose](): void;
}
class AsyncDisposableStack implements AsyncDisposable {
constructor();
/**
* Gets a value indicating whether the stack has been disposed.
*/
get disposed(): boolean;
/**
* Alias for `[Symbol.dispose]()`.
*/
dispose(): void;
/**
* Adds a resource to the top of the stack. Has no effect if provided `null`
* or `undefined`.
*/
use<T>(value: T): T;
/**
* Adds a non-disposable resource and a disposal callback to the top of the
* stack.
*/
adopt<T>(value: T, onDispose: (value: T) => Promise<void>): T;
/**
* Adds a disposal callback to the top of the stack.
*/
defer(onDispose: () => Promise<void>): void;
/**
* Moves all resources currently in this stack into a new `DisposableStack`.
*/
move(): AsyncDisposableStack;
/**
* Disposes of resources within this object.
*/
[Symbol.asyncDispose](): Promise<void>;
}
}
export const Symbol = globalThis.Symbol;
export const DisposableStack = (
globalThis as unknown as {DisposableStack: DisposableStack}
).DisposableStack;
export const AsyncDisposableStack = (
globalThis as unknown as {AsyncDisposableStack: AsyncDisposableStack}
).AsyncDisposableStack;