Skip to content

Commit 83a72bd

Browse files
authored
test: illustrate commonjs/node16 combo error (#377)
Typescript requires commonjs type definitions to have a .cts extension when resolving from package.json exports. Add a demo that illustrates the error.
1 parent 466e752 commit 83a72bd

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
import assert from 'assert'
3+
import { stringify, Stringifier } from 'csv-stringify';
4+
5+
let output: string = '';
6+
// Create the parser
7+
const stringifier: Stringifier = stringify({
8+
delimiter: ':',
9+
encoding: 'utf8'
10+
});
11+
// Use the readable stream api to consume records
12+
stringifier.on('readable', function(){
13+
let record; while ((record = stringifier.read()) !== null) {
14+
output += record
15+
}
16+
});
17+
// Catch any error
18+
stringifier.on('error', function(err){
19+
console.error(err.message)
20+
});
21+
// Test that the parsed records matched what's expected
22+
stringifier.on('end', function(){
23+
assert.deepStrictEqual(
24+
output,
25+
'a:b:c\n1:2:3\n'
26+
)
27+
});
28+
// Write data to the stream
29+
stringifier.write(["a", "b", "c"]);
30+
stringifier.write([1, 2, 3]);
31+
// Close the readable stream
32+
stringifier.end();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "csv-demo-ts-moduleresolution-node16-cjs",
3+
"version": "0.2.1",
4+
"main": "index.js",
5+
"license": "MIT",
6+
"private": true,
7+
"devDependencies": {
8+
"typescript": "^4.9.5"
9+
},
10+
"scripts": {
11+
"typecheck": "tsc --noEmit"
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"esModuleInterop": true,
4+
"module": "CommonJS",
5+
"moduleResolution": "node16",
6+
"strict": true
7+
}
8+
}

0 commit comments

Comments
 (0)