From f1b0de505dcd3c9c7c5ed8c46f5d196e40f4d4f4 Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Sun, 21 Jan 2024 23:06:37 +0200 Subject: [PATCH 1/7] Add ESM/CJS double-publishing --- package.json | 19 ++++++++++++++----- index.js => src/index.js | 0 2 files changed, 14 insertions(+), 5 deletions(-) rename index.js => src/index.js (100%) diff --git a/package.json b/package.json index f1e7847..e361f99 100644 --- a/package.json +++ b/package.json @@ -20,21 +20,30 @@ "type": "git", "url": "git://github.com/brianloveswords/buffer-crc32.git" }, - "main": "index.js", "scripts": { - "test": "tap tests/*.test.js --reporter classic" + "test": "tap tests/*.test.js --reporter classic", + "build": "unbuild", + "prepublishOnly": "npm run build" }, - "type": "commonjs", "dependencies": {}, "devDependencies": { - "tap": "~11.1.5" + "tap": "~11.1.5", + "unbuild": "^2.0.0" }, "optionalDependencies": {}, "engines": { "node": ">=8.0.0" }, "license": "MIT", + "type": "module", + "exports": { + ".": { + "import": "./dist/index.mjs", + "require": "./dist/index.cjs" + } + }, + "main": "./dist/index.cjs", "files": [ - "index.js" + "dist" ] } diff --git a/index.js b/src/index.js similarity index 100% rename from index.js rename to src/index.js From 3381144f79538b136eefa056a4da2b74949ea0d5 Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Sun, 21 Jan 2024 23:21:36 +0200 Subject: [PATCH 2/7] Adjust configuration --- build.config.js | 6 ++++++ src/index.js => index.js | 0 package.json | 1 - tests/crc.test.js | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 build.config.js rename src/index.js => index.js (100%) diff --git a/build.config.js b/build.config.js new file mode 100644 index 0000000..6ad5e9d --- /dev/null +++ b/build.config.js @@ -0,0 +1,6 @@ +export default { + entries: ["./index.js"], + rollup: { + emitCJS: true, + }, +}; \ No newline at end of file diff --git a/src/index.js b/index.js similarity index 100% rename from src/index.js rename to index.js diff --git a/package.json b/package.json index e361f99..a3d553d 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,6 @@ "node": ">=8.0.0" }, "license": "MIT", - "type": "module", "exports": { ".": { "import": "./dist/index.mjs", diff --git a/tests/crc.test.js b/tests/crc.test.js index 048801b..9b8cb27 100644 --- a/tests/crc.test.js +++ b/tests/crc.test.js @@ -1,4 +1,4 @@ -const crc32 = require('..'); +const crc32 = require('../index.js'); const test = require('tap').test; test('simple crc32 is no problem', function (t) { From daa1acaf87d887b2bf0e97a77ac1c05176caa5ba Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Sun, 21 Jan 2024 23:23:51 +0200 Subject: [PATCH 3/7] Remove redundant import --- tests/crc.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/crc.test.js b/tests/crc.test.js index 9b8cb27..048801b 100644 --- a/tests/crc.test.js +++ b/tests/crc.test.js @@ -1,4 +1,4 @@ -const crc32 = require('../index.js'); +const crc32 = require('..'); const test = require('tap').test; test('simple crc32 is no problem', function (t) { From 8b3aeb32ae70c8e6a1add0df0a10bfd33f340920 Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Sun, 21 Jan 2024 23:31:16 +0200 Subject: [PATCH 4/7] Do not install unbuild as a dependency to avoid breaking Node 8 --- package.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index a3d553d..4fe3919 100644 --- a/package.json +++ b/package.json @@ -22,13 +22,12 @@ }, "scripts": { "test": "tap tests/*.test.js --reporter classic", - "build": "unbuild", + "build": "npx unbuild@2.0.0", "prepublishOnly": "npm run build" }, "dependencies": {}, "devDependencies": { - "tap": "~11.1.5", - "unbuild": "^2.0.0" + "tap": "~11.1.5" }, "optionalDependencies": {}, "engines": { From 5807b367622b19e5e186fb30716184c4a90a55dd Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Sat, 3 Feb 2024 02:01:16 +0200 Subject: [PATCH 5/7] Make arethetypeswrong happy --- build.config.js | 11 +++++----- index.d.ts | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 11 +++++++--- 3 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 index.d.ts diff --git a/build.config.js b/build.config.js index 6ad5e9d..210e364 100644 --- a/build.config.js +++ b/build.config.js @@ -1,6 +1,7 @@ export default { - entries: ["./index.js"], - rollup: { - emitCJS: true, - }, -}; \ No newline at end of file + entries: ['./index.js'], + rollup: { + emitCJS: true, + }, + failOnWarn: false, +}; diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..890c396 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,56 @@ +/// + +/** + * These definitions were written by BendingBender (https://github.com/BendingBender) + */ + +export = crc32; + +/** + * crc32 that works with binary data and fancy character sets. + * + * @example + * import crc32 = require('buffer-crc32'); + * + * // works with buffers + * const buf = Buffer.from([0x00, 0x73, 0x75, 0x70, 0x20, 0x62, 0x72, 0x6f, 0x00]); + * crc32(buf); // -> + * + * // will cast to buffer if given a string, so you can + * // directly use foreign characters safely + * crc32('自動販売機'); // -> + * + * // and works in append mode too + * let partialCrc = crc32('hey'); + * partialCrc = crc32(' ', partialCrc); + * partialCrc = crc32('sup', partialCrc); + * partialCrc = crc32(' ', partialCrc); + * const finalCrc = crc32('bros', partialCrc); // -> + */ +declare function crc32(input: string | Buffer, partialCrc?: Buffer | number): Buffer; + +declare namespace crc32 { + /** + * Convenience method that returns a signed int instead of a `Buffer`. + * + * @example + * import crc32 = require('buffer-crc32'); + * + * // works with buffers + * const buf = Buffer.from([0x00, 0x73, 0x75, 0x70, 0x20, 0x62, 0x72, 0x6f, 0x00]); + * crc32.signed(buf); // -> -1805997238 + */ + function signed(buffer: string | Buffer, partialCrc?: Buffer | number): number; + + /** + * Convenience method that returns an unsigned int instead of a `Buffer`. + * + * @example + * import crc32 = require('buffer-crc32'); + * + * // works with buffers + * const buf = Buffer.from([0x00, 0x73, 0x75, 0x70, 0x20, 0x62, 0x72, 0x6f, 0x00]); + * crc32.unsigned(buf); // -> 2488970058 + */ + function unsigned(buffer: string | Buffer, partialCrc?: Buffer | number): number; +} diff --git a/package.json b/package.json index 5023474..4ee918e 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Brian J. Brennan ", "name": "buffer-crc32", "description": "A pure javascript CRC32 algorithm that plays nice with binary data", - "version": "0.2.13", + "version": "1.0.0-RC9", "licenses": [ { "type": "MIT", @@ -22,7 +22,7 @@ }, "scripts": { "test": "tap tests/*.test.js --reporter classic", - "build": "npx unbuild@2.0.0", + "build": "npx unbuild@2.0.0 && npx cpy-cli index.d.ts dist --rename=index.d.cts && npx cpy-cli index.d.ts dist --rename=index.d.mts", "prepublishOnly": "npm run build", "format": "prettier --write --log-level warn \"**/*.{json,md,js}\"" }, @@ -36,6 +36,7 @@ "node": ">=8.0.0" }, "license": "MIT", + "type": "commonjs", "exports": { ".": { "import": "./dist/index.mjs", @@ -43,7 +44,11 @@ } }, "main": "./dist/index.cjs", + "types": "./index.d.ts", "files": [ - "dist" + "dist", + "index.d.ts", + "LICENSE", + "README.md" ] } From 7a8551ccb95b292abc29f71c5986a2be9e9e748d Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Sat, 3 Feb 2024 02:07:24 +0200 Subject: [PATCH 6/7] Remove redundant docs --- index.d.ts | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/index.d.ts b/index.d.ts index 890c396..ac8fb58 100644 --- a/index.d.ts +++ b/index.d.ts @@ -6,27 +6,6 @@ export = crc32; -/** - * crc32 that works with binary data and fancy character sets. - * - * @example - * import crc32 = require('buffer-crc32'); - * - * // works with buffers - * const buf = Buffer.from([0x00, 0x73, 0x75, 0x70, 0x20, 0x62, 0x72, 0x6f, 0x00]); - * crc32(buf); // -> - * - * // will cast to buffer if given a string, so you can - * // directly use foreign characters safely - * crc32('自動販売機'); // -> - * - * // and works in append mode too - * let partialCrc = crc32('hey'); - * partialCrc = crc32(' ', partialCrc); - * partialCrc = crc32('sup', partialCrc); - * partialCrc = crc32(' ', partialCrc); - * const finalCrc = crc32('bros', partialCrc); // -> - */ declare function crc32(input: string | Buffer, partialCrc?: Buffer | number): Buffer; declare namespace crc32 { From 8fc08ed442e82ab2f7aa908e9515d682d40120c7 Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Sat, 3 Feb 2024 02:08:08 +0200 Subject: [PATCH 7/7] Restore original version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4ee918e..dc29702 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Brian J. Brennan ", "name": "buffer-crc32", "description": "A pure javascript CRC32 algorithm that plays nice with binary data", - "version": "1.0.0-RC9", + "version": "0.2.13", "licenses": [ { "type": "MIT",