Skip to content

Commit

Permalink
add fixup for .d.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Jul 21, 2023
1 parent f35a4d1 commit da99bdd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"test": "test"
},
"scripts": {
"build": "rollup -c",
"build": "rollup -c && node tools/fixup.d.ts.js",
"check": "npm run lint",
"check-ci": "npm run pre-push",
"docs": "typedoc --disableSources src/webgpu-utils.ts",
Expand Down
18 changes: 18 additions & 0 deletions tools/fixup.d.ts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import fs from 'fs';
import path from 'path';
import * as url from 'url';

const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
const readTextFile = n => fs.readFileSync(n, {encoding: 'utf-8'});

const pkg = JSON.parse(readTextFile(path.join(__dirname, '..', 'package.json')));
const majorVersion = pkg.version.split('.')[0];

const dtsFilename = path.join(__dirname, '..', 'dist', `${majorVersion}.x`, 'buffer-views.d.ts');
const s = readTextFile(dtsFilename)
const newS = s.replace(
/export\s+type\s+ArrayBufferViews\s+=\s+{\s+views:\s+TypedArrayOrViews;/m,
`export type ArrayBufferViews = {
views: any; // because otherwise this is too much of a PITA to use in typescript`);
console.assert(s !== newS, `fixup failed: did you build first?\n`);
fs.writeFileSync(dtsFilename, newS);

0 comments on commit da99bdd

Please sign in to comment.