diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 3b1cb1b..e58b1c4 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -48,3 +48,12 @@ jobs: node-version: ${{ matrix.node-version }} - run: npm install - run: npm test + + limitations: + name: Package Bulk Limitations + runs-on: ubuntu-latest + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: 20.6.1 + - run: npm run limits diff --git a/.npmignore b/.npmignore index 7433514..59befde 100644 --- a/.npmignore +++ b/.npmignore @@ -1,3 +1,4 @@ test/ test.sh .github/ +limitation.js diff --git a/README.md b/README.md index a4a3aad..212eff4 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,25 @@ # Diagnostics Channel Polyfill -This package provides a polyfill for the `diagnostics_channel` core Node.js module. It aims to be compatible with every single version of Node.js. It also aims to remain simple, ideally one or two files, and with zero dependencies. +This package provides a polyfill for the `diagnostics_channel` core Node.js module for use with older versions of Node.js. It aims to remain simple, with zero dependencies, and only taking up a few kilobytes of space. -The package attempts to backport support for every single feature that is added at later dates in Node.js core, at least assuming these are backwards compatible. +This package attempts to backport every feature and bugfix that is added to Node.js core. If a feature hasn't been backported then please open a Pull Request or create an issue. Whenever the currently running version of Node.js ships with `diagnostics_channel`, **dc-polyfill** will make sure to use the global registry of channels provided by the core module. However, for older versions of Node.js, **dc-polyfill** will instead use a global symbol to track the channels. This symbol will remain the same for all versions of **dc-polyfill** to avoid the issue where multiple versions of an npm library installed in a dependency hierarchy usually provide different singletons. Ideally, this package will forever remain backwards compatible, and there will never be a v2.x release. +## Usage + ```sh npm install dc-polyfill ``` ```javascript const diagnostics_channel = require('dc-polyfill'); +``` + +## Contributing + +When a Pull Request is created the code runs against many different versions of Node.js. Notably, versions right before a change and versions right after a change, the first version of a release line, and the last version of a release line. + +Currently this module tests Node.js >= v12. If you would like to use `dc-polyfill` for versions of Node.js older than this then feel free to submit a Pull Request or open an issue. diff --git a/limitation.js b/limitation.js new file mode 100755 index 0000000..be88d2c --- /dev/null +++ b/limitation.js @@ -0,0 +1,57 @@ +#!/usr/bin/env node + +const { execSync } = require('child_process'); + +const pkg = require('./package.json'); +pkg.dependencies = pkg.dependencies || {}; +pkg.devDependencies = pkg.devDependencies || {}; + +let violations = 0; + +const limits = pkg.limits; + +if (!limits) { + process.exit(0); +} + +if (('packedSize' in limits) || ('unpackedSize' in limits)) { + const { size, unpackedSize } = JSON.parse(execSync(`npm pack --dry-run --json`).toString())[0]; + + console.log(` Packed Size: ${size}\n Unpacked Size: ${unpackedSize}`); + + if ('packedSize' in limits && size > limits.packedSize) { + violations++; + console.error(`The packed size of ${size} exceeds the limit of ${limits.packedSize}!`); + } + + if ('unpackedSize' in limits && unpackedSize > limits.unpackedSize) { + violations++; + console.error(`The unpacked size of ${unpackedSize} exceeds the limit of ${limits.unpackedSize}!`); + } +} + +const depCount = Object.keys(pkg.dependencies).length; +console.log(` Dependencies: ${depCount}`); + +if ('maxDependencies' in limits) { + if (depCount > limits.maxDependencies) { + violations++; + console.error(`The dependency count of ${depCount} exceeds the limit of ${limits.maxDependencies}!`); + } +} + +const devDepCount = Object.keys(pkg.devDependencies).length; +console.log(`Dev Dependencies: ${devDepCount}`); + +if ('maxDevDependencies' in limits) { + if (devDepCount > limits.maxDevDependencies) { + violations++; + console.error(`The dev dependency count of ${devDepCount} exceeds the limit of ${limits.maxDevDependencies}!`); + } +} + +if (violations > 0) { + process.exit(1); +} + +console.log('OK'); diff --git a/package.json b/package.json index fdcc796..c7017a9 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "A polyfill for the internal diagnostics_channel module", "main": "dc-polyfill.js", "scripts": { - "test": "./test.sh" + "test": "./test.sh", + "limits": "./limitation.js" }, "keywords": [ "diagnostics", @@ -17,5 +18,13 @@ "license": "MIT", "devDependencies": { "tape": "^5.6.6" + }, + "limits": { + "packedSize": 10000, + "unpackedSize": 35000, + "maxDependencies": 0 + }, + "engines": { + "node": ">=12" } } diff --git a/primordials.js b/primordials.js index 93d94bf..9518b3e 100644 --- a/primordials.js +++ b/primordials.js @@ -1,6 +1,7 @@ const makeCall = (fn) => (...args) => fn.call(...args); // https://github.com/tc39/proposal-relative-indexing-method#polyfill +// v16.6.0+, v17+ function arrayAtPolyfill(n) { // ToInteger() abstract op n = Math.trunc(n) || 0; diff --git a/test.sh b/test.sh index 84d7b31..5619a72 100755 --- a/test.sh +++ b/test.sh @@ -2,7 +2,7 @@ echo "Node.js version: $(node --version)" errors=0 -for i in test/*.js; do +for i in test/*.spec.js; do node "$i" || ((errors++)) done