From 0504d161a3ccdf6f9dbc8033e747eafc2bf4f58e Mon Sep 17 00:00:00 2001 From: Offroaders123 <65947371+Offroaders123@users.noreply.github.com> Date: Sun, 11 Feb 2024 14:27:47 -0800 Subject: [PATCH] TSC Migration Not sure how to default export from JSDoc-powered JS, when in CommonJS. Once I move to ESM and or TS it's not an issue, but I was kind of surprised that this didn't work already, since it's an existing practice for Node packages that have been around for a while. I'm probably just doing it wrong, but I'm not totally sure. I thought it might've been the part where it was assigning both the variable and the `module.exports` in the same line, but that didn't fix the errors either. https://github.com/microsoft/TypeScript/issues/37832 https://stackoverflow.com/questions/60009092/declaration-will-not-emit-due-to-private-name-usage https://github.com/microsoft/TypeScript/issues/2719 Super bowl!!!!! aaaeaaeggh, 380 green hut, AA --- .gitignore | 1 + package.json | 6 +++++- src/readable-cdb.js | 4 +++- src/writable-cdb.js | 4 +++- tsconfig.build.json | 17 +++++++++++++++++ tsconfig.json | 2 +- 6 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 tsconfig.build.json diff --git a/.gitignore b/.gitignore index c2658d7..b947077 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules/ +dist/ diff --git a/package.json b/package.json index 70657e5..bb3df6e 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,9 @@ "version": "2.0.4", "description": "A cdb implementation for node.js", "author": "Eric Norris", - "main": "./src/index.js", + "type": "commonjs", + "main": "./dist/index.js", + "types": "./dist/index.d.ts", "repository": { "type": "git", "url": "https://github.com/ericnorris/node-cdb.git" @@ -14,6 +16,8 @@ "vows": "^0.8.0" }, "scripts": { + "build": "tsc --project ./tsconfig.build.json", + "dev": "tsc --watch", "test": "vows --spec" }, "keywords": [ diff --git a/src/readable-cdb.js b/src/readable-cdb.js index dacd5cc..6a087be 100644 --- a/src/readable-cdb.js +++ b/src/readable-cdb.js @@ -5,7 +5,7 @@ var fs = require('fs'), HEADER_SIZE = 2048, TABLE_SIZE = 256; -var readable = module.exports = function(/** @type {string} */ file) { +var readable = function(/** @type {string} */ file) { this.file = file; this.header = new Array(TABLE_SIZE); @@ -13,6 +13,8 @@ var readable = module.exports = function(/** @type {string} */ file) { this.bookmark = /** @type {((callback: (error: Error | null, buffer?: Buffer | null) => void) => void) | null} */ (null); }; +module.exports = readable; + readable.prototype.open = function(/** @type {(error: NodeJS.ErrnoException, readable?: typeof this) => void} */ callback) { var self = this; diff --git a/src/writable-cdb.js b/src/writable-cdb.js index cd59ed8..a657ad9 100644 --- a/src/writable-cdb.js +++ b/src/writable-cdb.js @@ -8,7 +8,7 @@ var events = require('events'), TABLE_SIZE = 256; // Writable CDB definition -var writable = module.exports = function(/** @type {string} */ file) { +var writable = function(/** @type {string} */ file) { this.file = file; this.filePosition = 0; @@ -19,6 +19,8 @@ var writable = module.exports = function(/** @type {string} */ file) { this.hashtableStream = /** @type {fs.WriteStream | null} */ (null); }; +module.exports = writable; + // extend EventEmitter for emit() util.inherits(writable, events.EventEmitter); diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..5b1ef29 --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,17 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "./dist", + "noEmit": false, + "declaration": true, + "sourceMap": true + }, + "include": [ + "./src/**/*" + ], + "exclude": [ + "./test", + "./benchmark" + ] +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 63f827a..64e42b5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "allowJs": true, "checkJs": true, - "module": "NodeNext", + "module": "CommonJS", "target": "ESNext", "isolatedModules": true, "noEmit": true,