Skip to content

Commit

Permalink
test: illustrate commonjs/node16 combo error (#377)
Browse files Browse the repository at this point in the history
Typescript requires commonjs type definitions to have a .cts extension
when resolving from package.json exports. Add a demo that illustrates
the error.
  • Loading branch information
jonmast committed Feb 7, 2023
1 parent 466e752 commit 83a72bd
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
32 changes: 32 additions & 0 deletions demo/ts-moduleresolution-node16-cjs/lib/stringify.ts
@@ -0,0 +1,32 @@

import assert from 'assert'
import { stringify, Stringifier } from 'csv-stringify';

let output: string = '';
// Create the parser
const stringifier: Stringifier = stringify({
delimiter: ':',
encoding: 'utf8'
});
// Use the readable stream api to consume records
stringifier.on('readable', function(){
let record; while ((record = stringifier.read()) !== null) {
output += record
}
});
// Catch any error
stringifier.on('error', function(err){
console.error(err.message)
});
// Test that the parsed records matched what's expected
stringifier.on('end', function(){
assert.deepStrictEqual(
output,
'a:b:c\n1:2:3\n'
)
});
// Write data to the stream
stringifier.write(["a", "b", "c"]);
stringifier.write([1, 2, 3]);
// Close the readable stream
stringifier.end();
13 changes: 13 additions & 0 deletions demo/ts-moduleresolution-node16-cjs/package.json
@@ -0,0 +1,13 @@
{
"name": "csv-demo-ts-moduleresolution-node16-cjs",
"version": "0.2.1",
"main": "index.js",
"license": "MIT",
"private": true,
"devDependencies": {
"typescript": "^4.9.5"
},
"scripts": {
"typecheck": "tsc --noEmit"
}
}
8 changes: 8 additions & 0 deletions demo/ts-moduleresolution-node16-cjs/tsconfig.json
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"esModuleInterop": true,
"module": "CommonJS",
"moduleResolution": "node16",
"strict": true
}
}

0 comments on commit 83a72bd

Please sign in to comment.