Skip to content

Commit 0504d16

Browse files
committed
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. 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
1 parent 61fcc64 commit 0504d16

6 files changed

Lines changed: 30 additions & 4 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules/
2+
dist/

‎package.json‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"version": "2.0.4",
44
"description": "A cdb implementation for node.js",
55
"author": "Eric Norris",
6-
"main": "./src/index.js",
6+
"type": "commonjs",
7+
"main": "./dist/index.js",
8+
"types": "./dist/index.d.ts",
79
"repository": {
810
"type": "git",
911
"url": "https://github.com/ericnorris/node-cdb.git"
@@ -14,6 +16,8 @@
1416
"vows": "^0.8.0"
1517
},
1618
"scripts": {
19+
"build": "tsc --project ./tsconfig.build.json",
20+
"dev": "tsc --watch",
1721
"test": "vows --spec"
1822
},
1923
"keywords": [

‎src/readable-cdb.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ var fs = require('fs'),
55
HEADER_SIZE = 2048,
66
TABLE_SIZE = 256;
77

8-
var readable = module.exports = function(/** @type {string} */ file) {
8+
var readable = function(/** @type {string} */ file) {
99
this.file = file;
1010
this.header = new Array(TABLE_SIZE);
1111

1212
this.fd = null;
1313
this.bookmark = /** @type {((callback: (error: Error | null, buffer?: Buffer | null) => void) => void) | null} */ (null);
1414
};
1515

16+
module.exports = readable;
17+
1618
readable.prototype.open = function(/** @type {(error: NodeJS.ErrnoException, readable?: typeof this) => void} */ callback) {
1719
var self = this;
1820

‎src/writable-cdb.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var events = require('events'),
88
TABLE_SIZE = 256;
99

1010
// Writable CDB definition
11-
var writable = module.exports = function(/** @type {string} */ file) {
11+
var writable = function(/** @type {string} */ file) {
1212
this.file = file;
1313
this.filePosition = 0;
1414

@@ -19,6 +19,8 @@ var writable = module.exports = function(/** @type {string} */ file) {
1919
this.hashtableStream = /** @type {fs.WriteStream | null} */ (null);
2020
};
2121

22+
module.exports = writable;
23+
2224
// extend EventEmitter for emit()
2325
util.inherits(writable, events.EventEmitter);
2426

‎tsconfig.build.json‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"rootDir": "./src",
5+
"outDir": "./dist",
6+
"noEmit": false,
7+
"declaration": true,
8+
"sourceMap": true
9+
},
10+
"include": [
11+
"./src/**/*"
12+
],
13+
"exclude": [
14+
"./test",
15+
"./benchmark"
16+
]
17+
}

‎tsconfig.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"allowJs": true,
44
"checkJs": true,
5-
"module": "NodeNext",
5+
"module": "CommonJS",
66
"target": "ESNext",
77
"isolatedModules": true,
88
"noEmit": true,

0 commit comments

Comments
 (0)