Skip to content

Commit

Permalink
TSC Migration
Browse files Browse the repository at this point in the history
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.

microsoft/TypeScript#37832
https://stackoverflow.com/questions/60009092/declaration-will-not-emit-due-to-private-name-usage
microsoft/TypeScript#2719

Super bowl!!!!! aaaeaaeggh, 380 green hut, AA
  • Loading branch information
Offroaders123 committed Feb 11, 2024
1 parent 61fcc64 commit 0504d16
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
dist/
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -14,6 +16,8 @@
"vows": "^0.8.0"
},
"scripts": {
"build": "tsc --project ./tsconfig.build.json",
"dev": "tsc --watch",
"test": "vows --spec"
},
"keywords": [
Expand Down
4 changes: 3 additions & 1 deletion src/readable-cdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ 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);

this.fd = null;
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;

Expand Down
4 changes: 3 additions & 1 deletion src/writable-cdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

Expand Down
17 changes: 17 additions & 0 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
"noEmit": false,
"declaration": true,
"sourceMap": true
},
"include": [
"./src/**/*"
],
"exclude": [
"./test",
"./benchmark"
]
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"module": "NodeNext",
"module": "CommonJS",
"target": "ESNext",
"isolatedModules": true,
"noEmit": true,
Expand Down

0 comments on commit 0504d16

Please sign in to comment.