From 82944f388b75d66ef3fafe18fa512f047164adc7 Mon Sep 17 00:00:00 2001 From: Mark Miro Date: Thu, 11 Sep 2025 12:16:49 -0700 Subject: [PATCH 1/2] WIP ruff work --- package.json | 3 +++ pnpm-lock.yaml | 28 ++++++++++++++++++++++++++++ ruff-test.ts | 27 +++++++++++++++++++++++++++ src/pages/RuffTestPage.tsx | 29 +++++++++++++++++++++++++++++ src/routes.tsx | 2 ++ vite.config.ts | 2 ++ 6 files changed, 91 insertions(+) create mode 100644 ruff-test.ts create mode 100644 src/pages/RuffTestPage.tsx diff --git a/package.json b/package.json index 71e696fb..33687d89 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "start": "echo 'Use `pnpm dev` to run the integrated server (frontend + backend). Legacy `dev:sync` script removed - now using Cloudflare Vite plugin.'" }, "dependencies": { + "@astral-sh/ruff-wasm-bundler": "^0.13.0", "@codemirror/autocomplete": "^6.18.6", "@codemirror/commands": "^6.8.1", "@codemirror/lang-markdown": "^6.3.3", @@ -119,6 +120,7 @@ "zod": "^4.0.17" }, "devDependencies": { + "@astral-sh/ruff-wasm-nodejs": "^0.13.0", "@cloudflare/vite-plugin": "^1.9.6", "@cloudflare/workers-types": "^4.20250813.0", "@effect/vitest": "0.23.7", @@ -156,6 +158,7 @@ "tailwindcss": "^4.1.10", "typescript": "^5.8.3", "vite": "^6.3.5", + "vite-plugin-wasm": "^3.5.0", "vitest": "^3.0.0", "webpack-bundle-analyzer": "^4.10.2", "wrangler": "4.27.0" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a119cb9b..fb978c99 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -19,6 +19,9 @@ importers: .: dependencies: + '@astral-sh/ruff-wasm-bundler': + specifier: ^0.13.0 + version: 0.13.0 '@codemirror/autocomplete': specifier: ^6.18.6 version: 6.18.6 @@ -233,6 +236,9 @@ importers: specifier: ^4.0.17 version: 4.0.17 devDependencies: + '@astral-sh/ruff-wasm-nodejs': + specifier: ^0.13.0 + version: 0.13.0 '@cloudflare/vite-plugin': specifier: ^1.9.6 version: 1.9.6(rollup@4.45.0)(vite@6.3.5(@types/node@24.0.13)(jiti@2.4.2)(lightningcss@1.30.1)(yaml@2.8.1))(workerd@1.20250730.0)(wrangler@4.27.0(@cloudflare/workers-types@4.20250813.0)) @@ -344,6 +350,9 @@ importers: vite: specifier: ^6.3.5 version: 6.3.5(@types/node@24.0.13)(jiti@2.4.2)(lightningcss@1.30.1)(yaml@2.8.1) + vite-plugin-wasm: + specifier: ^3.5.0 + version: 3.5.0(vite@6.3.5(@types/node@24.0.13)(jiti@2.4.2)(lightningcss@1.30.1)(yaml@2.8.1)) vitest: specifier: ^3.0.0 version: 3.2.4(@types/debug@4.1.12)(@types/node@24.0.13)(@vitest/ui@3.2.4)(happy-dom@15.11.7)(jiti@2.4.2)(lightningcss@1.30.1)(yaml@2.8.1) @@ -367,6 +376,12 @@ packages: resolution: {integrity: sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==} engines: {node: '>=6.0.0'} + '@astral-sh/ruff-wasm-bundler@0.13.0': + resolution: {integrity: sha512-t8++k7Vpuzg8zxD5uu1uSm5kgTn/B22MQ5u2DYtYGn+77qcl5zMIRm7WCWB++Fzt31xh9yc530kajYHxYC8GZw==} + + '@astral-sh/ruff-wasm-nodejs@0.13.0': + resolution: {integrity: sha512-+1b/Z3BlLqxARV0/ao7lr5dHJkz97oj8Ge29D7MG4OsFyUQ3v11aO9IqXBFZv0cWpD1JwHmdrt9//q4gbl7reA==} + '@babel/code-frame@7.27.1': resolution: {integrity: sha512-cjQ7ZlQ0Mv3b47hABuTevyTuYN4i+loJKGeV9flcCgIK37cCXRh+L1bd3iBHlynerhQ7BhCkn2BPbQUL+rGqFg==} engines: {node: '>=6.9.0'} @@ -4809,6 +4824,11 @@ packages: engines: {node: ^18.0.0 || ^20.0.0 || >=22.0.0} hasBin: true + vite-plugin-wasm@3.5.0: + resolution: {integrity: sha512-X5VWgCnqiQEGb+omhlBVsvTfxikKtoOgAzQ95+BZ8gQ+VfMHIjSHr0wyvXFQCa0eKQ0fKyaL0kWcEnYqBac4lQ==} + peerDependencies: + vite: ^2 || ^3 || ^4 || ^5 || ^6 || ^7 + vite@6.3.4: resolution: {integrity: sha512-BiReIiMS2fyFqbqNT/Qqt4CVITDU9M9vE+DKcVAsB+ZV0wvTKd+3hMbkpxz1b+NmEDMegpVbisKiAZOnvO92Sw==} engines: {node: ^18.0.0 || ^20.0.0 || >=22.0.0} @@ -5085,6 +5105,10 @@ snapshots: '@jridgewell/gen-mapping': 0.3.12 '@jridgewell/trace-mapping': 0.3.29 + '@astral-sh/ruff-wasm-bundler@0.13.0': {} + + '@astral-sh/ruff-wasm-nodejs@0.13.0': {} + '@babel/code-frame@7.27.1': dependencies: '@babel/helper-validator-identifier': 7.27.1 @@ -9926,6 +9950,10 @@ snapshots: - tsx - yaml + vite-plugin-wasm@3.5.0(vite@6.3.5(@types/node@24.0.13)(jiti@2.4.2)(lightningcss@1.30.1)(yaml@2.8.1)): + dependencies: + vite: 6.3.5(@types/node@24.0.13)(jiti@2.4.2)(lightningcss@1.30.1)(yaml@2.8.1) + vite@6.3.4(@types/node@24.0.13)(jiti@2.4.2)(lightningcss@1.30.1)(yaml@2.8.1): dependencies: esbuild: 0.25.6 diff --git a/ruff-test.ts b/ruff-test.ts new file mode 100644 index 00000000..85155c46 --- /dev/null +++ b/ruff-test.ts @@ -0,0 +1,27 @@ +import { Workspace, type Diagnostic } from "@astral-sh/ruff-wasm-nodejs"; + +const exampleDocument = `print('hello'); print("world")`; + +// await init(); // Initializes WASM module + +// These are default settings just to illustrate configuring Ruff +// Settings info: https://docs.astral.sh/ruff/settings +const workspace = new Workspace({ + "line-length": 88, + "indent-width": 4, + format: { + "indent-style": "space", + "quote-style": "double", + }, + lint: { + select: ["E4", "E7", "E9", "F"], + }, +}); + +// Will contain 1 diagnostic code for E702: Multiple statements on one line +const diagnostics: Diagnostic[] = workspace.check(exampleDocument); + +const formatted = workspace.format(exampleDocument); + +console.log(diagnostics); +console.log(formatted); diff --git a/src/pages/RuffTestPage.tsx b/src/pages/RuffTestPage.tsx new file mode 100644 index 00000000..90519f64 --- /dev/null +++ b/src/pages/RuffTestPage.tsx @@ -0,0 +1,29 @@ +import { Workspace, type Diagnostic } from "@astral-sh/ruff-wasm-bundler"; + +const exampleDocument = `print('hello'); print("world")`; + +// These are default settings just to illustrate configuring Ruff +// Settings info: https://docs.astral.sh/ruff/settings +const workspace = new Workspace({ + "line-length": 88, + "indent-width": 4, + format: { + "indent-style": "space", + "quote-style": "double", + }, + lint: { + select: ["E4", "E7", "E9", "F"], + }, +}); + +// Will contain 1 diagnostic code for E702: Multiple statements on one line +const diagnostics: Diagnostic[] = workspace.check(exampleDocument); + +const formatted = workspace.format(exampleDocument); + +console.log(diagnostics); +console.log(formatted); + +export const RuffTestPage = () => { + return
Ruff Test Page: see console
; +}; diff --git a/src/routes.tsx b/src/routes.tsx index b759c8d3..df3b357b 100644 --- a/src/routes.tsx +++ b/src/routes.tsx @@ -17,6 +17,7 @@ import { NotebooksDashboardPage } from "@/pages/NotebooksDashboardPage.tsx"; import OidcCallbackPage from "@/pages/OidcCallbackPage.tsx"; import { ErrorBoundary } from "react-error-boundary"; import { ErrorFallbackPage } from "./components/ErrorFallbackPage"; +import { RuffTestPage } from "./pages/RuffTestPage"; export const App: React.FC = () => { // Safety net: Auto-remove loading screen if no component has handled it @@ -97,6 +98,7 @@ export const App: React.FC = () => { /> } /> + } /> diff --git a/vite.config.ts b/vite.config.ts index d72bb589..067ad5ad 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,6 +3,7 @@ import { fileURLToPath } from "node:url"; import { execSync } from "child_process"; import { livestoreDevtoolsPlugin } from "@livestore/devtools-vite"; +import wasm from "vite-plugin-wasm"; import react from "@vitejs/plugin-react"; import tailwindcss from "@tailwindcss/vite"; import { defineConfig, loadEnv } from "vite"; @@ -44,6 +45,7 @@ export default defineConfig(({ mode }) => { } const plugins = [ + wasm(), envValidationPlugin(env), injectLoadingScreen(), react({ From c0e452e24cf391ed1ad1b8bafbecdce16b8dd129 Mon Sep 17 00:00:00 2001 From: Mark Miro Date: Thu, 11 Sep 2025 16:09:19 -0700 Subject: [PATCH 2/2] Fix build issue --- package.json | 1 + pnpm-lock.yaml | 170 +++++++++++++++++++++++++++++++++++++++++++++++++ vite.config.ts | 4 ++ 3 files changed, 175 insertions(+) diff --git a/package.json b/package.json index 33687d89..22f2a929 100644 --- a/package.json +++ b/package.json @@ -117,6 +117,7 @@ "tw-animate-css": "^1.3.4", "ulid": "^3.0.1", "uuid": "^11.1.0", + "vite-plugin-top-level-await": "^1.6.0", "zod": "^4.0.17" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fb978c99..7fd7ca23 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -232,6 +232,9 @@ importers: uuid: specifier: ^11.1.0 version: 11.1.0 + vite-plugin-top-level-await: + specifier: ^1.6.0 + version: 1.6.0(rollup@4.45.0)(vite@6.3.5(@types/node@24.0.13)(jiti@2.4.2)(lightningcss@1.30.1)(yaml@2.8.1)) zod: specifier: ^4.0.17 version: 4.0.17 @@ -1985,6 +1988,15 @@ packages: rollup: optional: true + '@rollup/plugin-virtual@3.0.2': + resolution: {integrity: sha512-10monEYsBp3scM4/ND4LNH5Rxvh3e/cVeL3jWTgZ2SrQ+BmUoQcopVQvnaMcOnykb1VkxUFuDAN+0FnpTFRy2A==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0 + peerDependenciesMeta: + rollup: + optional: true + '@rollup/pluginutils@5.2.0': resolution: {integrity: sha512-qWJ2ZTbmumwiLFomfzTyt5Kng4hwPi9rwCYN4SHb6eaRU1KNO4ccxINHr/VhH4GgPlt1XfSTLX2LBTme8ne4Zw==} engines: {node: '>=14.0.0'} @@ -2104,6 +2116,84 @@ packages: '@standard-schema/spec@1.0.0': resolution: {integrity: sha512-m2bOd0f2RT9k8QJx1JN85cZYyH1RqFBdlwtkSlf4tBDYLCiiZnv1fIIwacK6cqwXavOydf0NPToMQgpKq+dVlA==} + '@swc/core-darwin-arm64@1.13.5': + resolution: {integrity: sha512-lKNv7SujeXvKn16gvQqUQI5DdyY8v7xcoO3k06/FJbHJS90zEwZdQiMNRiqpYw/orU543tPaWgz7cIYWhbopiQ==} + engines: {node: '>=10'} + cpu: [arm64] + os: [darwin] + + '@swc/core-darwin-x64@1.13.5': + resolution: {integrity: sha512-ILd38Fg/w23vHb0yVjlWvQBoE37ZJTdlLHa8LRCFDdX4WKfnVBiblsCU9ar4QTMNdeTBEX9iUF4IrbNWhaF1Ng==} + engines: {node: '>=10'} + cpu: [x64] + os: [darwin] + + '@swc/core-linux-arm-gnueabihf@1.13.5': + resolution: {integrity: sha512-Q6eS3Pt8GLkXxqz9TAw+AUk9HpVJt8Uzm54MvPsqp2yuGmY0/sNaPPNVqctCX9fu/Nu8eaWUen0si6iEiCsazQ==} + engines: {node: '>=10'} + cpu: [arm] + os: [linux] + + '@swc/core-linux-arm64-gnu@1.13.5': + resolution: {integrity: sha512-aNDfeN+9af+y+M2MYfxCzCy/VDq7Z5YIbMqRI739o8Ganz6ST+27kjQFd8Y/57JN/hcnUEa9xqdS3XY7WaVtSw==} + engines: {node: '>=10'} + cpu: [arm64] + os: [linux] + + '@swc/core-linux-arm64-musl@1.13.5': + resolution: {integrity: sha512-9+ZxFN5GJag4CnYnq6apKTnnezpfJhCumyz0504/JbHLo+Ue+ZtJnf3RhyA9W9TINtLE0bC4hKpWi8ZKoETyOQ==} + engines: {node: '>=10'} + cpu: [arm64] + os: [linux] + + '@swc/core-linux-x64-gnu@1.13.5': + resolution: {integrity: sha512-WD530qvHrki8Ywt/PloKUjaRKgstQqNGvmZl54g06kA+hqtSE2FTG9gngXr3UJxYu/cNAjJYiBifm7+w4nbHbA==} + engines: {node: '>=10'} + cpu: [x64] + os: [linux] + + '@swc/core-linux-x64-musl@1.13.5': + resolution: {integrity: sha512-Luj8y4OFYx4DHNQTWjdIuKTq2f5k6uSXICqx+FSabnXptaOBAbJHNbHT/06JZh6NRUouaf0mYXN0mcsqvkhd7Q==} + engines: {node: '>=10'} + cpu: [x64] + os: [linux] + + '@swc/core-win32-arm64-msvc@1.13.5': + resolution: {integrity: sha512-cZ6UpumhF9SDJvv4DA2fo9WIzlNFuKSkZpZmPG1c+4PFSEMy5DFOjBSllCvnqihCabzXzpn6ykCwBmHpy31vQw==} + engines: {node: '>=10'} + cpu: [arm64] + os: [win32] + + '@swc/core-win32-ia32-msvc@1.13.5': + resolution: {integrity: sha512-C5Yi/xIikrFUzZcyGj9L3RpKljFvKiDMtyDzPKzlsDrKIw2EYY+bF88gB6oGY5RGmv4DAX8dbnpRAqgFD0FMEw==} + engines: {node: '>=10'} + cpu: [ia32] + os: [win32] + + '@swc/core-win32-x64-msvc@1.13.5': + resolution: {integrity: sha512-YrKdMVxbYmlfybCSbRtrilc6UA8GF5aPmGKBdPvjrarvsmf4i7ZHGCEnLtfOMd3Lwbs2WUZq3WdMbozYeLU93Q==} + engines: {node: '>=10'} + cpu: [x64] + os: [win32] + + '@swc/core@1.13.5': + resolution: {integrity: sha512-WezcBo8a0Dg2rnR82zhwoR6aRNxeTGfK5QCD6TQ+kg3xx/zNT02s/0o+81h/3zhvFSB24NtqEr8FTw88O5W/JQ==} + engines: {node: '>=10'} + peerDependencies: + '@swc/helpers': '>=0.5.17' + peerDependenciesMeta: + '@swc/helpers': + optional: true + + '@swc/counter@0.1.3': + resolution: {integrity: sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==} + + '@swc/types@0.1.25': + resolution: {integrity: sha512-iAoY/qRhNH8a/hBvm3zKj9qQ4oc2+3w1unPJa2XvTK3XjeLXtzcCingVPw/9e5mn1+0yPqxcBGp9Jf0pkfMb1g==} + + '@swc/wasm@1.13.5': + resolution: {integrity: sha512-ZBZcxieydxNwgEU9eFAXGMaDb1Xoh+ZkZcUQ27LNJzc2lPSByoL6CSVqnYiaVo+n9JgqbYyHlMq+i7z0wRNTfA==} + '@tailwindcss/cli@4.1.11': resolution: {integrity: sha512-7RAFOrVaXCFz5ooEG36Kbh+sMJiI2j4+Ozp71smgjnLfBRu7DTfoq8DsTvzse2/6nDeo2M3vS/FGaxfDgr3rtQ==} hasBin: true @@ -4809,6 +4899,10 @@ packages: util-deprecate@1.0.2: resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} + uuid@10.0.0: + resolution: {integrity: sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==} + hasBin: true + uuid@11.1.0: resolution: {integrity: sha512-0/A9rDy9P7cJ+8w1c9WD9V//9Wj15Ce2MPz8Ri6032usz+NfePxx5AcN3bN+r6ZL6jEo066/yNYB3tn4pQEx+A==} hasBin: true @@ -4824,6 +4918,11 @@ packages: engines: {node: ^18.0.0 || ^20.0.0 || >=22.0.0} hasBin: true + vite-plugin-top-level-await@1.6.0: + resolution: {integrity: sha512-bNhUreLamTIkoulCR9aDXbTbhLk6n1YE8NJUTTxl5RYskNRtzOR0ASzSjBVRtNdjIfngDXo11qOsybGLNsrdww==} + peerDependencies: + vite: '>=2.8' + vite-plugin-wasm@3.5.0: resolution: {integrity: sha512-X5VWgCnqiQEGb+omhlBVsvTfxikKtoOgAzQ95+BZ8gQ+VfMHIjSHr0wyvXFQCa0eKQ0fKyaL0kWcEnYqBac4lQ==} peerDependencies: @@ -6861,6 +6960,10 @@ snapshots: optionalDependencies: rollup: 4.45.0 + '@rollup/plugin-virtual@3.0.2(rollup@4.45.0)': + optionalDependencies: + rollup: 4.45.0 + '@rollup/pluginutils@5.2.0(rollup@4.45.0)': dependencies: '@types/estree': 1.0.8 @@ -6935,6 +7038,60 @@ snapshots: '@standard-schema/spec@1.0.0': {} + '@swc/core-darwin-arm64@1.13.5': + optional: true + + '@swc/core-darwin-x64@1.13.5': + optional: true + + '@swc/core-linux-arm-gnueabihf@1.13.5': + optional: true + + '@swc/core-linux-arm64-gnu@1.13.5': + optional: true + + '@swc/core-linux-arm64-musl@1.13.5': + optional: true + + '@swc/core-linux-x64-gnu@1.13.5': + optional: true + + '@swc/core-linux-x64-musl@1.13.5': + optional: true + + '@swc/core-win32-arm64-msvc@1.13.5': + optional: true + + '@swc/core-win32-ia32-msvc@1.13.5': + optional: true + + '@swc/core-win32-x64-msvc@1.13.5': + optional: true + + '@swc/core@1.13.5': + dependencies: + '@swc/counter': 0.1.3 + '@swc/types': 0.1.25 + optionalDependencies: + '@swc/core-darwin-arm64': 1.13.5 + '@swc/core-darwin-x64': 1.13.5 + '@swc/core-linux-arm-gnueabihf': 1.13.5 + '@swc/core-linux-arm64-gnu': 1.13.5 + '@swc/core-linux-arm64-musl': 1.13.5 + '@swc/core-linux-x64-gnu': 1.13.5 + '@swc/core-linux-x64-musl': 1.13.5 + '@swc/core-win32-arm64-msvc': 1.13.5 + '@swc/core-win32-ia32-msvc': 1.13.5 + '@swc/core-win32-x64-msvc': 1.13.5 + + '@swc/counter@0.1.3': {} + + '@swc/types@0.1.25': + dependencies: + '@swc/counter': 0.1.3 + + '@swc/wasm@1.13.5': {} + '@tailwindcss/cli@4.1.11': dependencies: '@parcel/watcher': 2.5.1 @@ -9917,6 +10074,8 @@ snapshots: util-deprecate@1.0.2: {} + uuid@10.0.0: {} + uuid@11.1.0: {} vfile-message@4.0.2: @@ -9950,6 +10109,17 @@ snapshots: - tsx - yaml + vite-plugin-top-level-await@1.6.0(rollup@4.45.0)(vite@6.3.5(@types/node@24.0.13)(jiti@2.4.2)(lightningcss@1.30.1)(yaml@2.8.1)): + dependencies: + '@rollup/plugin-virtual': 3.0.2(rollup@4.45.0) + '@swc/core': 1.13.5 + '@swc/wasm': 1.13.5 + uuid: 10.0.0 + vite: 6.3.5(@types/node@24.0.13)(jiti@2.4.2)(lightningcss@1.30.1)(yaml@2.8.1) + transitivePeerDependencies: + - '@swc/helpers' + - rollup + vite-plugin-wasm@3.5.0(vite@6.3.5(@types/node@24.0.13)(jiti@2.4.2)(lightningcss@1.30.1)(yaml@2.8.1)): dependencies: vite: 6.3.5(@types/node@24.0.13)(jiti@2.4.2)(lightningcss@1.30.1)(yaml@2.8.1) diff --git a/vite.config.ts b/vite.config.ts index 067ad5ad..b78de36c 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,6 +3,7 @@ import { fileURLToPath } from "node:url"; import { execSync } from "child_process"; import { livestoreDevtoolsPlugin } from "@livestore/devtools-vite"; +import topLevelAwait from "vite-plugin-top-level-await"; import wasm from "vite-plugin-wasm"; import react from "@vitejs/plugin-react"; import tailwindcss from "@tailwindcss/vite"; @@ -45,6 +46,9 @@ export default defineConfig(({ mode }) => { } const plugins = [ + // `topLevelAwait()` is needed for wasm, otherwise build errors in GH actions: + // ERROR: Top-level await is not available in the configured target environment + topLevelAwait(), wasm(), envValidationPlugin(env), injectLoadingScreen(),