forked from sergiodxa/remix-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate package.json exports (sergiodxa#246)
I noticed that there are some broken `package.json` exports. This is something that can be automatically checked. This PR adds a new script to run [`attw`](https://arethetypeswrong.github.io/) CLI to check if `package.json` exports are valid. --------- Co-authored-by: Sergio Xalambrí <hello@sergiodxa.com>
- Loading branch information
1 parent
c799523
commit b8d5637
Showing
7 changed files
with
86 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* eslint-disable unicorn/no-process-exit */ | ||
|
||
async function main() { | ||
const proc = Bun.spawn([ | ||
"bunx", | ||
"attw", | ||
"-f", | ||
"table-flipped", | ||
"--no-emoji", | ||
"--no-color", | ||
"--pack", | ||
]); | ||
|
||
const text = await new Response(proc.stdout).text(); | ||
|
||
const entrypointLines = text | ||
.slice(text.indexOf('"remix-utils/')) | ||
.split("\n") | ||
.filter(Boolean) | ||
.filter((line) => !line.includes("─")) | ||
.map((line) => | ||
line | ||
.replaceAll(/[^\d "()/A-Za-z│-]/g, "") | ||
.replaceAll("90m│39m", "│") | ||
.replaceAll(/^│/g, "") | ||
.replaceAll(/│$/g, ""), | ||
); | ||
|
||
const pkg = await Bun.file("package.json").json(); | ||
const entrypoints = entrypointLines.map((entrypointLine) => { | ||
const [entrypoint, ...resolutionColumns] = entrypointLine.split("│"); | ||
return { | ||
entrypoint: entrypoint.replace(pkg.name, ".").trim(), | ||
esm: resolutionColumns[2].trim(), | ||
bundler: resolutionColumns[3].trim(), | ||
}; | ||
}); | ||
|
||
const entrypointsWithProblems = entrypoints.filter( | ||
(item) => item.esm.includes("fail") || item.bundler.includes("fail"), | ||
); | ||
if (entrypointsWithProblems.length > 0) { | ||
console.error("Entrypoints with problems:"); | ||
console.log( | ||
`---\n${entrypointsWithProblems | ||
.map( | ||
({ entrypoint, esm, bundler }) => | ||
`entrypoint: ${entrypoint}\nesm: ${esm}\nbundler: ${bundler}`, | ||
) | ||
.join("\n---\n")}\n---`, | ||
); | ||
process.exit(1); | ||
} else { | ||
console.log("No problems found."); | ||
} | ||
} | ||
|
||
await main().catch((error) => { | ||
console.error(error); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"types": ["bun-types"] | ||
}, | ||
"include": ["./*.ts"] | ||
} |