Skip to content

Commit

Permalink
Get the blog example working after pnpm switch
Browse files Browse the repository at this point in the history
pnpm does not play nice with a workspace package depending on an external package which then depends on a workspace package again by default. To restore the fancy setup that uses this local example package, we can hoist all the packages so they are all sourced from the same root level node-modules folder, which is how yarn worked before. A bit less sealed, but worth it to have a local playground to work with. I couldn't figure out any way to get pnpm to drop the right structure in the example folder such that vite could find api-client-core otherwise.
  • Loading branch information
airhorns committed Jun 24, 2023
1 parent 3b945a5 commit 8c0bb22
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 35 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ jobs:
run: pnpm build
- name: Test
run: pnpm test
- name: Build example package
run: pnpm --filter=blog-example build-vite
lint:
runs-on: ubuntu-latest
steps:
Expand Down
5 changes: 4 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
recursive-install = true
prefer-workspace-packages = true
recursive-install = true
link-workspace-packages = deep
shamefully-hoist = true
node-linker = hoisted
14 changes: 5 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
"author": "Gadget Authors",
"license": "MIT",
"private": true,
"workspaces": [
"packages/api-client-core",
"packages/react",
"packages/react-shopify-app-bridge",
"packages/blog-example"
],
"scripts": {
"lint": "pnpm lint:prettier && pnpm lint:eslint",
"lint:prettier": "NODE_OPTIONS=\"--max-old-space-size=4096\" prettier --check \"(packages|scripts)/**/*.{js,ts,tsx}\"",
Expand All @@ -26,8 +20,8 @@
"preinstall": "npx only-allow pnpm"
},
"devDependencies": {
"@gadget-client/bulk-actions-test": "^1.101.0",
"@gadget-client/related-products-example": "^1.844.0",
"@gadget-client/bulk-actions-test": "^1.102.0",
"@gadget-client/related-products-example": "^1.848.0",
"@gadgetinc/eslint-config": "^0.6.1",
"@gadgetinc/prettier-config": "^0.4.0",
"@swc/core": "^1.3.42",
Expand All @@ -46,7 +40,9 @@
"semver": "^7.3.8",
"ts-node": "^10.9.1",
"typescript": "5.0.4",
"zx": "^7.1.1"
"zx": "^7.1.1",
"@gadgetinc/api-client-core": "workspace:*",
"@gadgetinc/react": "workspace:*"
},
"pnpm": {
"overrides": {
Expand Down
11 changes: 6 additions & 5 deletions packages/blog-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "blog-example",
"version": "0.1.0",
"source": "src/index.ts",
"private": "true",
"files": [
"README.md",
"dist/src/**/*"
Expand All @@ -11,13 +12,13 @@
"homepage": "https://github.com/gadget-inc/js-clients/tree/main/packages/blog-example",
"scripts": {
"typecheck": "tsc --noEmit",
"dev": "vite",
"build": "true",
"preview": "vite preview"
"dev": "rm -rf node_modules/.vite && vite --clearScreen=false",
"preview": "vite preview",
"build-vite": "vite build"
},
"dependencies": {
"@gadget-client/simple-blog": "^1.130.0",
"@gadgetinc/react": "*",
"@gadget-client/blog": "^1.42.0",
"@gadgetinc/react": "workspace:*",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
43 changes: 40 additions & 3 deletions packages/blog-example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useFetch, useFindMany } from "@gadgetinc/react";
import { useEffect, useState } from "react";
import { Suspense, useEffect, useState } from "react";
import { api } from "./api";
import "./styles/App.css";

Expand Down Expand Up @@ -42,12 +42,49 @@ function ExampleFindMany() {
);
}

let suspended = false;
function SuspenseFallback() {
suspended = true;
return <div>suspended...</div>;
}
function ExampleSuspense() {
return (
<section className="card">
<h2>Example Suspense</h2>
<p>Ever suspended: {String(suspended)}</p>
<Suspense fallback={<SuspenseFallback />}>
<ExampleSuspenseInner />
</Suspense>
</section>
);
}

function ExampleSuspenseInner() {
const [history, setHistory] = useState<any[]>([]);
const [result, send] = useFindMany(api.post, { suspense: true, sort: { id: "Descending" } });

useEffect(() => {
const { operation, ...keep } = result;
setHistory([...history, keep]);
}, [result]);

return (
<>
<code>
<pre>{JSON.stringify(history, null, 2)}</pre>
</code>
<button onClick={() => send()}>Refetch</button>
</>
);
}

function App() {
return (
<div className="App">
<h1>Vite + Gadget</h1>
<ExampleFetch />
<ExampleFindMany />
{/* <ExampleFetch />
<ExampleFindMany /> */}
<ExampleSuspense />
</div>
);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/blog-example/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { Client } from "@gadget-client/simple-blog";
import { Client } from "@gadget-client/blog";

export const api = new Client();
export const api = new Client({ environment: "Development" });
36 changes: 21 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions scripts/check-dependency-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { fs, globby } from "zx";

for (const filepath of await globby("packages/*/package.json")) {
const manifest = await fs.readJSON(filepath);
if (manifest.private) continue;
for (const key of ["dependencies", "peerDependencies"]) {
for (const [target, requiredVersion] of Object.entries(targets)) {
const dependencyVersion = manifest[key]?.[target];
Expand Down

0 comments on commit 8c0bb22

Please sign in to comment.