mirror of
https://github.com/HeyPuter/puter.git
synced 2026-08-23 22:47:19 +00:00
Changes are: - global egress metering - remove file egress cost - introduce file op cost for the per request cost s3 has - enforce fs read/download etc to through 402 when out of usage; allow for subdomains - enforce kv metering when out of usage through 402; allow for workers - jsdoc as source of truth for puter.js types - kv driver caching for get and batchget operations with decreased costs
74 lines
2.4 KiB
JavaScript
74 lines
2.4 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Type-checks the declarations puter.js publishes.
|
|
*
|
|
* The JSDoc in src/puter-js/src is the source of truth for the SDK's types;
|
|
* src/puter-js/types is `tsc --emitDeclarationOnly` output, generated by the
|
|
* SDK build and shipped in the npm tarball but never committed. So this
|
|
* generates it and checks the result, rather than diffing against something
|
|
* checked in.
|
|
*
|
|
* The check runs *without* `skipLibCheck`, which is the point: that flag is on
|
|
* everywhere else, and it is how the hand-maintained declarations used to hide
|
|
* broken re-exports — the root index.d.ts named types no module exported, and
|
|
* nothing ever looked.
|
|
*
|
|
* Usage:
|
|
* node tools/checkPuterjsTypes.mjs
|
|
*/
|
|
|
|
import { execFileSync } from 'node:child_process';
|
|
import { dirname, join, sep } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
|
|
const SDK = join(ROOT, 'src', 'puter-js');
|
|
|
|
const tsc = (args) => {
|
|
try {
|
|
execFileSync('npx', ['tsc', ...args], {
|
|
cwd: ROOT,
|
|
encoding: 'utf8',
|
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
});
|
|
return { ok: true, output: '' };
|
|
} catch (e) {
|
|
if (e.stdout === undefined && e.stderr === undefined) throw e;
|
|
return { ok: false, output: `${e.stdout ?? ''}${e.stderr ?? ''}` };
|
|
}
|
|
};
|
|
|
|
const generated = tsc(['-p', join(SDK, 'tsconfig.types.json')]);
|
|
if (!generated.ok) {
|
|
console.error('Generating declarations from the puter.js JSDoc failed:\n');
|
|
console.error(generated.output);
|
|
process.exit(1);
|
|
}
|
|
|
|
const checked = tsc([
|
|
'--noEmit',
|
|
'--strict',
|
|
'--target', 'es2022',
|
|
'--module', 'nodenext',
|
|
'--moduleResolution', 'nodenext',
|
|
join(SDK, 'index.d.ts'),
|
|
]);
|
|
|
|
// Errors inside third-party `@types` packages are not this project's to fix.
|
|
const errors = checked.output
|
|
.split('\n')
|
|
.filter((line) => /error TS\d+/.test(line))
|
|
.filter((line) => !line.includes(`node_modules${sep}@types`));
|
|
|
|
if (errors.length) {
|
|
console.error(
|
|
'The declarations generated from the puter.js JSDoc do not type-check.' +
|
|
' Fix the JSDoc in src/puter-js/src — src/puter-js/types is generated' +
|
|
' output and editing it there would be overwritten by the next build.\n',
|
|
);
|
|
for (const line of errors) console.error(` ${line}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log('puter.js declarations generate and type-check cleanly.');
|