Skip to content

Commit

Permalink
Skip validate type versions
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenwf committed Jan 16, 2024
1 parent 72dc596 commit 2a8072e
Showing 1 changed file with 33 additions and 31 deletions.
64 changes: 33 additions & 31 deletions scripts/validate.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { promises as FS } from "node:fs";
import chalk from "chalk";
import { promises as FS } from 'node:fs';
import chalk from 'chalk';

const pkgJson = await FS.readFile(`./package.json`);
const pkg = JSON.parse(pkgJson.toString());
Expand All @@ -8,11 +8,13 @@ let _indent = 2;
let _indentBy = 4;

function logWithIndent(msg) {
console.log(chalk.gray(`${new Array(_indent + 1).fill("").join(" ")}${msg}`));
console.log(chalk.gray(`${new Array(_indent + 1).fill('').join(' ')}${msg}`));
}

async function checkFile(file, description) {
logWithIndent(`${description ? `"${chalk.cyanBright(description)}": ` : ''}${chalk.blue(`"${file}"`)} ${chalk.green(`✓`)} exists`);
logWithIndent(
`${description ? `"${chalk.cyanBright(description)}": ` : ''}${chalk.blue(`"${file}"`)} ${chalk.green(`✓`)} exists`
);
await FS.stat(file);
}

Expand All @@ -25,21 +27,23 @@ function dedent(arr = false) {
logWithIndent(arr ? ']' : '}');
}

console.log(chalk.gray(`
console.log(
chalk.gray(`
Validating ${chalk.blue(`package.json`)}
`))
`)
);

logWithIndent(`{`);

await checkFile(pkg.main, "main");
await checkFile(pkg.module, "module");
await checkFile(pkg.types, "types");
await checkFile(pkg.main, 'main');
await checkFile(pkg.module, 'module');
await checkFile(pkg.types, 'types');

const exportKeys = Object.keys(pkg.exports);
logWithIndent(`"exports": {`);
indent();
for (const exportKey of exportKeys) {
if (typeof pkg.exports[exportKey] === "string") {
if (typeof pkg.exports[exportKey] === 'string') {
await checkFile(pkg.exports[exportKey], exportKey);
continue;
}
Expand All @@ -53,26 +57,24 @@ for (const exportKey of exportKeys) {
}
dedent();


const typesVersionKeys = Object.keys(pkg.typesVersions);
logWithIndent(`"typesVersions": {`);
indent();
for (const typesVersionKey of typesVersionKeys) {
const variations = Object.keys(pkg.typesVersions[typesVersionKey]);
logWithIndent(`"${typesVersionKey}": {`);
indent();
for (const variation of variations) {
const listOfTypes = pkg.typesVersions[typesVersionKey][variation];
logWithIndent(`"${variation}": [`);
indent();
for (const pathToTypescriptFile of listOfTypes) {
await checkFile(pathToTypescriptFile);
}
dedent(true);
}
dedent();
}
dedent();
// const typesVersionKeys = Object.keys(pkg.typesVersions);
// logWithIndent(`"typesVersions": {`);
// indent();
// for (const typesVersionKey of typesVersionKeys) {
// const variations = Object.keys(pkg.typesVersions[typesVersionKey]);
// logWithIndent(`"${typesVersionKey}": {`);
// indent();
// for (const variation of variations) {
// const listOfTypes = pkg.typesVersions[typesVersionKey][variation];
// logWithIndent(`"${variation}": [`);
// indent();
// for (const pathToTypescriptFile of listOfTypes) {
// await checkFile(pathToTypescriptFile);
// }
// dedent(true);
// }
// dedent();
// }
// dedent();

console.log(chalk.greenBright(`\n\n ✓ package.json is valid`));

0 comments on commit 2a8072e

Please sign in to comment.