Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate package.json exports #246

Merged
merged 8 commits into from
Oct 13, 2023
Merged
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
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ jobs:
- run: bun install
- run: bun run build

exports:
name: Verify Exports
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- run: bun install
- run: bun run test:exports

typecheck:
name: Typechecker
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
- uses: oven-sh/setup-bun@v1
- run: bun install
- run: bun run build
- run: bun run test:exports

- uses: actions/setup-node@v3
with:
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ return (
This hook allows you to read the value of `transition.state`, every `fetcher.state` in the app, and `revalidator.state`.

```ts
import { useGlobalNavigationState } from "remix-utils/use-global-pending-state";
import { useGlobalNavigationState } from "remix-utils/use-global-navigation-state";

export function GlobalPendingUI() {
let states = useGlobalNavigationState();
Expand Down Expand Up @@ -744,7 +744,7 @@ The return value of `useGlobalNavigationState` can be `"idle"`, `"loading"` or `
This hook lets you know if the global navigation, if one of any active fetchers is either loading or submitting, or if the revalidator is running.

```ts
import { useGlobalPendingState } from "remix-utils/use-global-pending-state";
import { useGlobalPendingState } from "remix-utils/use-global-navigation-state";

export function GlobalPendingUI() {
let globalState = useGlobalPendingState();
Expand All @@ -767,7 +767,7 @@ The return value of `useGlobalPendingState` is either `"idle"` or `"pending"`.
This hook lets you know if the global transition or if one of any active fetchers is submitting.

```ts
import { useGlobalSubmittingState } from "remix-utils/use-global-pending-state";
import { useGlobalSubmittingState } from "remix-utils/use-global-navigation-state";

export function GlobalPendingUI() {
let globalState = useGlobalSubmittingState();
Expand All @@ -786,7 +786,7 @@ The return value of `useGlobalSubmittingState` is either `"idle"` or `"submittin
This hook lets you know if the global transition, if one of any active fetchers is loading, or if the revalidator is running

```ts
import { useGlobalLoadingState } from "remix-utils/use-global-pending-state";
import { useGlobalLoadingState } from "remix-utils/use-global-navigation-state";

export function GlobalPendingUI() {
let globalState = useGlobalLoadingState();
Expand Down
Binary file modified bun.lockb
Binary file not shown.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@
"prepare": "npm run build",
"build": "tsc --project tsconfig.json --outDir ./build",
"postbuild": "prettier --write \"build/**/*.js\" \"build/**/*.d.ts\"",
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.tsx\" \"test/**/*.ts\" \"test/**/*.tsx\" \"*.md\"",
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.tsx\" \"test/**/*.ts\" \"test/**/*.tsx\" \"*.md\" \"package.json\"",
"typecheck": "tsc --project tsconfig.json --noEmit",
"lint": "eslint --ext .ts,.tsx src/",
"test": "vitest --run",
"test:watch": "vitest",
"test:coverage": "vitest --coverage"
"test:coverage": "vitest --coverage",
"test:exports": "bun scripts/check-pkg-exports.ts"
},
"author": {
"name": "Sergio Xalambrí",
Expand Down Expand Up @@ -132,6 +133,7 @@
}
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.12.1",
"@remix-run/node": "^2.0.0",
"@remix-run/react": "^2.0.0",
"@remix-run/router": "^1.7.2",
Expand Down
61 changes: 61 additions & 0 deletions scripts/check-pkg-exports.ts
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);
});
7 changes: 7 additions & 0 deletions scripts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"types": ["bun-types"]
},
"include": ["./*.ts"]
}