Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/csv-stringify/dist/esm/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/// <reference types="node" />

import * as stream from "stream";

export type Callback = (err: Error | undefined, output: string) => void;
Expand Down
5 changes: 3 additions & 2 deletions packages/csv-stringify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@
"build": "npm run build:rollup && npm run build:ts",
"build:rollup": "npx rollup -c",
"build:ts": "cp lib/index.d.ts dist/cjs/index.d.cts && cp lib/sync.d.ts dist/cjs/sync.d.cts && cp lib/*.ts dist/esm",
"postbuild:ts": "find dist/cjs -name '*.d.cts' -exec sh -c \"sed -i \"s/\\.js'/\\.cjs'/g\" {} || sed -i '' \"s/\\.js'/\\.cjs'/g\" {}\" \\;",
"postbuild:ts": "node scripts/postbuild-types.js",
"lint:check": "eslint",
"lint:fix": "eslint --fix",
"lint:ts": "tsc --noEmit true",
"preversion": "npm run build && git add dist",
"test": "npx tsc --noEmit && mocha 'test/**/*.{js,ts}'",
"test": "npx tsc --noEmit && npm run test:browser-types && mocha 'test/**/*.{js,ts}'",
"test:browser-types": "npx tsc --project test/browser-types/tsconfig.json",
"test:16": "mocha 'test/**/*.js'",
"test:legacy": "mocha --ignore test/api.callback.js --ignore test/api.web_stream.js 'test/**/*.{js,ts}'"
},
Expand Down
17 changes: 17 additions & 0 deletions packages/csv-stringify/scripts/postbuild-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { readFile, readdir, writeFile } from "node:fs/promises";

const cjsDirectory = new URL("../dist/cjs/", import.meta.url);
for (const entry of await readdir(cjsDirectory)) {
if (!entry.endsWith(".d.cts")) continue;
const declaration = new URL(entry, cjsDirectory);
const source = await readFile(declaration, "utf8");
await writeFile(declaration, source.replace(/\.js(["'])/g, ".cjs$1"));
}

const browserDeclaration = new URL("../dist/esm/index.d.ts", import.meta.url);
const nodeReference = '/// <reference types="node" />\n\n';
const source = await readFile(browserDeclaration, "utf8");
if (!source.startsWith(nodeReference)) {
throw new Error("Expected the Node type reference in the source declaration");
}
await writeFile(browserDeclaration, source.slice(nodeReference.length));
6 changes: 6 additions & 0 deletions packages/csv-stringify/test/browser-types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { stringify } from "csv-stringify/browser/esm";

const timeout: number = setTimeout(() => {}, 0);

void stringify;
void timeout;
13 changes: 13 additions & 0 deletions packages/csv-stringify/test/browser-types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"lib": ["DOM", "ES2022"],
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noEmit": true,
"skipLibCheck": true,
"strict": true,
"target": "ES2022",
"types": []
},
"include": ["index.ts"]
}
3 changes: 2 additions & 1 deletion packages/csv-stringify/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"strict": true,
"target": "esnext",
// Prevent error "Cannot find name 'it'"
"types": ["mocha"],
"types": ["mocha"]
},
"exclude": ["test/browser-types"]
}