Add @tsus/plugin (webpack/vite/esbuild/bun adapters) and Next.js, Astro, Bun examples
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Changed files
35 files changed941 additions0 deletionsagainst 0eb2eae
- ChangedREADME.md+10−0
- Addedexamples/27-nextjs/.gitignore+2−0
- Addedexamples/27-nextjs/example.json+8−0
- Addedexamples/27-nextjs/lib/channel.tsus+1−0
- Addedexamples/27-nextjs/lib/greeting.tsus+11−0
- Addedexamples/27-nextjs/next.config.mjs+17−0
- Addedexamples/27-nextjs/package-lock.json+459−0
- Addedexamples/27-nextjs/package.json+14−0
- Addedexamples/27-nextjs/pages/index.jsx+5−0
- Addedexamples/28-astro/.gitignore+2−0
- Addedexamples/28-astro/astro.config.mjs+8−0
- Addedexamples/28-astro/example.json+8−0
- Addedexamples/28-astro/package-lock.json
- Addedexamples/28-astro/package.json+12−0
- Addedexamples/28-astro/src/env.d.ts+1−0
- Addedexamples/28-astro/src/lib/banner.tsus+11−0
- Addedexamples/28-astro/src/lib/suffix.tsus+1−0
- Addedexamples/28-astro/src/pages/index.astro+11−0
- Addedexamples/29-bun/bunfig.toml+1−0
- Addedexamples/29-bun/example.json+6−0
- Addedexamples/29-bun/package-lock.json+156−0
- Addedexamples/29-bun/package.json+7−0
- Addedexamples/29-bun/src/app.tsus+10−0
- Addedexamples/29-bun/src/main.ts+4−0
- Addedexamples/29-bun/src/meta.tsus+1−0
- Addedexamples/29-bun/tsus-preload.js+7−0
- Changedpackage-lock.json+12−0
- Changedpackages/cli/package.json+5−0
- Addedpackages/plugin/bun.js+7−0
- Addedpackages/plugin/core.js+45−0
- Addedpackages/plugin/esbuild.js+16−0
- Addedpackages/plugin/package.json+16−0
- Addedpackages/plugin/vite.js+17−0
- Addedpackages/plugin/webpack.cjs+11−0
- Changedscripts/run-examples.mjs+39−0
ChangedREADME.md+10−0
| @@ -53,6 +53,16 @@ | ||
| }; | ||
| ``` | ||
| +### Framework integrations | ||
| + | ||
| +`packages/plugin` (@tsus/plugin) is one transform core with a thin adapter per host, all sharing the CLI's preprocessor and checker: | ||
| + | ||
| +- `@tsus/plugin/webpack`: a loader. In Next.js, one rule in `next.config.mjs` makes `.tsus` importable from any page or component (`examples/27-nextjs`, verified by `next build` emitting the rendered string into static HTML). | ||
| +- `@tsus/plugin/vite`: a Vite plugin, which also covers Astro, SvelteKit, and Nuxt through their `vite.plugins` config (`examples/28-astro`). | ||
| +- `@tsus/plugin/esbuild`: an esbuild plugin. Bun's plugin API is esbuild-shaped, so the same object registers with `Bun.plugin`; with a one-line `bunfig.toml` preload, `bun run` executes `.tsus` imports natively with no build step (`examples/29-bun`). | ||
| + | ||
| +The adapters deliberately leave import specifiers untouched: the host bundler resolves `.tsus` to `.tsus` chains through its own pipeline and each hop hits the transform again. The `tsus` CLI stays the standalone path (and the CI path, via `tsus check --json`). | ||
| + | ||
| Tooling: | ||
| - `tsus build` compiles to JS, `tsus check` type-checks without emitting. Both run as an esbuild/swc plugin so existing bundler setups pick up `.tsus` files without config changes. | ||
Addedexamples/27-nextjs/.gitignore+2−0
| @@ -0,0 +1,2 @@ | ||
| +.next/ | ||
| +out/ | ||
Addedexamples/27-nextjs/example.json+8−0
| @@ -0,0 +1,8 @@ | ||
| +{ | ||
| + "expect": "command", | ||
| + "install": true, | ||
| + "command": ["npm", "run", "build"], | ||
| + "fileContains": [ | ||
| + { "file": "out/index.html", "contains": "Hello from tsus inside Next.js" } | ||
| + ] | ||
| +} | ||
Addedexamples/27-nextjs/lib/channel.tsus+1−0
| @@ -0,0 +1 @@ | ||
| +export const channelName = (): string => "the webpack loader"; | ||
Addedexamples/27-nextjs/lib/greeting.tsus+11−0
| @@ -0,0 +1,11 @@ | ||
| +import { Some, None, type Option } from "@tsus/runtime"; | ||
| +import { channelName } from "./channel.tsus"; | ||
| + | ||
| +const emblem = (framework: string): Option<string> => | ||
| + framework === "Next.js" ? Some("▲") : None; | ||
| + | ||
| +export const pageTitle = (framework: string): string => | ||
| + match (emblem(framework)) { | ||
| + Some(mark) => `Hello from tsus inside ${framework} ${mark} via ${channelName()}`, | ||
| + None => `Hello from tsus inside ${framework} via ${channelName()}`, | ||
| + }; | ||
Addedexamples/27-nextjs/next.config.mjs+17−0
| @@ -0,0 +1,17 @@ | ||
| +import { createRequire } from "node:module"; | ||
| + | ||
| +const require = createRequire(import.meta.url); | ||
| + | ||
| +/** @type {import('next').NextConfig} */ | ||
| +const nextConfig = { | ||
| + output: "export", | ||
| + webpack: (config) => { | ||
| + config.module.rules.push({ | ||
| + test: /\.tsus$/, | ||
| + use: require.resolve("@tsus/plugin/webpack"), | ||
| + }); | ||
| + return config; | ||
| + }, | ||
| +}; | ||
| + | ||
| +export default nextConfig; | ||
Addedexamples/27-nextjs/package-lock.jsonLong diff, collapsed+459−0
| @@ -0,0 +1,459 @@ | ||
| +{ | ||
| + "name": "example-nextjs", | ||
| + "lockfileVersion": 3, | ||
| + "requires": true, | ||
| + "packages": { | ||
| + "": { | ||
| + "name": "example-nextjs", | ||
| + "dependencies": { | ||
| + "@tsus/plugin": "file:../../packages/plugin", | ||
| + "@tsus/runtime": "file:../../packages/runtime", | ||
| + "next": "14.2.5", | ||
| + "react": "18.3.1", | ||
| + "react-dom": "18.3.1" | ||
| + } | ||
| + }, | ||
| + "../../packages/plugin": { | ||
| + "name": "@tsus/plugin", | ||
| + "version": "0.1.0", | ||
| + "dependencies": { | ||
| + "@tsus/cli": "file:../cli", | ||
| + "typescript": "^5.5.0" | ||
| + } | ||
| + }, | ||
| + "../../packages/runtime": { | ||
| + "name": "@tsus/runtime", | ||
| + "version": "0.1.0" | ||
| + }, | ||
| + "node_modules/@next/env": { | ||
| + "version": "14.2.5", | ||
| + "resolved": "https://registry.npmjs.org/@next/env/-/env-14.2.5.tgz", | ||
| + "integrity": "sha512-/zZGkrTOsraVfYjGP8uM0p6r0BDT6xWpkjdVbcz66PJVSpwXX3yNiRycxAuDfBKGWBrZBXRuK/YVlkNgxHGwmA==", | ||
| + "license": "MIT" | ||
| + }, | ||
| + "node_modules/@next/swc-darwin-arm64": { | ||
| + "version": "14.2.5", | ||
| + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.5.tgz", | ||
| + "integrity": "sha512-/9zVxJ+K9lrzSGli1///ujyRfon/ZneeZ+v4ptpiPoOU+GKZnm8Wj8ELWU1Pm7GHltYRBklmXMTUqM/DqQ99FQ==", | ||
| + "cpu": [ | ||
| + "arm64" | ||
| + ], | ||
| + "license": "MIT", | ||
| + "optional": true, | ||
| + "os": [ | ||
| + "darwin" | ||
| + ], | ||
| + "engines": { | ||
| + "node": ">= 10" | ||
| + } | ||
| + }, | ||
| + "node_modules/@next/swc-darwin-x64": { | ||
| + "version": "14.2.5", | ||
| + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.5.tgz", | ||
| + "integrity": "sha512-vXHOPCwfDe9qLDuq7U1OYM2wUY+KQ4Ex6ozwsKxp26BlJ6XXbHleOUldenM67JRyBfVjv371oneEvYd3H2gNSA==", | ||
| + "cpu": [ | ||
| + "x64" | ||
| + ], | ||
| + "license": "MIT", | ||
| + "optional": true, | ||
| + "os": [ | ||
| + "darwin" | ||
| + ], | ||
| + "engines": { | ||
| + "node": ">= 10" | ||
| + } | ||
| + }, | ||
| + "node_modules/@next/swc-linux-arm64-gnu": { | ||
| + "version": "14.2.5", | ||
| + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.5.tgz", | ||
| + "integrity": "sha512-vlhB8wI+lj8q1ExFW8lbWutA4M2ZazQNvMWuEDqZcuJJc78iUnLdPPunBPX8rC4IgT6lIx/adB+Cwrl99MzNaA==", | ||
| + "cpu": [ | ||
| + "arm64" | ||
| + ], | ||
| + "libc": [ | ||
| + "glibc" | ||
| + ], | ||
| + "license": "MIT", | ||
| + "optional": true, | ||
| + "os": [ | ||
| + "linux" | ||
| + ], | ||
| + "engines": { | ||
| + "node": ">= 10" | ||
| + } | ||
| + }, | ||
| + "node_modules/@next/swc-linux-arm64-musl": { | ||
| + "version": "14.2.5", | ||
| + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.5.tgz", | ||
| + "integrity": "sha512-NpDB9NUR2t0hXzJJwQSGu1IAOYybsfeB+LxpGsXrRIb7QOrYmidJz3shzY8cM6+rO4Aojuef0N/PEaX18pi9OA==", | ||
| + "cpu": [ | ||
| + "arm64" | ||
| + ], | ||
| + "libc": [ | ||
| + "musl" | ||
| + ], | ||
| + "license": "MIT", | ||
| + "optional": true, | ||
| + "os": [ | ||
| + "linux" | ||
| + ], | ||
| + "engines": { | ||
| + "node": ">= 10" | ||
| + } | ||
| + }, | ||
| + "node_modules/@next/swc-linux-x64-gnu": { | ||
| + "version": "14.2.5", | ||
| + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.5.tgz", | ||
| + "integrity": "sha512-8XFikMSxWleYNryWIjiCX+gU201YS+erTUidKdyOVYi5qUQo/gRxv/3N1oZFCgqpesN6FPeqGM72Zve+nReVXQ==", | ||
| + "cpu": [ | ||
| + "x64" | ||
| + ], | ||
| + "libc": [ | ||
| + "glibc" | ||
| + ], | ||
| + "license": "MIT", | ||
| + "optional": true, | ||
| + "os": [ | ||
| + "linux" | ||
| + ], | ||
| + "engines": { | ||
| + "node": ">= 10" | ||
| + } | ||
| + }, | ||
| + "node_modules/@next/swc-linux-x64-musl": { | ||
| + "version": "14.2.5", | ||
| + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.5.tgz", | ||
| + "integrity": "sha512-6QLwi7RaYiQDcRDSU/os40r5o06b5ue7Jsk5JgdRBGGp8l37RZEh9JsLSM8QF0YDsgcosSeHjglgqi25+m04IQ==", | ||
| + "cpu": [ | ||
| + "x64" | ||
| + ], | ||
| + "libc": [ | ||
| + "musl" | ||
| + ], | ||
| + "license": "MIT", | ||
| + "optional": true, | ||
| + "os": [ | ||
| + "linux" | ||
| + ], | ||
| + "engines": { | ||
| + "node": ">= 10" | ||
| + } | ||
| + }, | ||
| + "node_modules/@next/swc-win32-arm64-msvc": { | ||
| + "version": "14.2.5", | ||
| + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.5.tgz", | ||
| + "integrity": "sha512-1GpG2VhbspO+aYoMOQPQiqc/tG3LzmsdBH0LhnDS3JrtDx2QmzXe0B6mSZZiN3Bq7IOMXxv1nlsjzoS1+9mzZw==", | ||
| + "cpu": [ | ||
| + "arm64" | ||
| + ], | ||
| + "license": "MIT", | ||
| + "optional": true, | ||
| + "os": [ | ||
| + "win32" | ||
| + ], | ||
| + "engines": { | ||
| + "node": ">= 10" | ||
| + } | ||
| + }, | ||
| + "node_modules/@next/swc-win32-ia32-msvc": { | ||
| + "version": "14.2.5", | ||
| + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.5.tgz", | ||
| + "integrity": "sha512-Igh9ZlxwvCDsu6438FXlQTHlRno4gFpJzqPjSIBZooD22tKeI4fE/YMRoHVJHmrQ2P5YL1DoZ0qaOKkbeFWeMg==", | ||
| + "cpu": [ | ||
| + "ia32" | ||
| + ], | ||
| + "license": "MIT", | ||
| + "optional": true, | ||
| + "os": [ | ||
| + "win32" | ||
| + ], | ||
| + "engines": { | ||
| + "node": ">= 10" | ||
| + } | ||
| + }, | ||
| + "node_modules/@next/swc-win32-x64-msvc": { | ||
| + "version": "14.2.5", | ||
| + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.5.tgz", | ||
| + "integrity": "sha512-tEQ7oinq1/CjSG9uSTerca3v4AZ+dFa+4Yu6ihaG8Ud8ddqLQgFGcnwYls13H5X5CPDPZJdYxyeMui6muOLd4g==", | ||
| + "cpu": [ | ||
| + "x64" | ||
| + ], | ||
| + "license": "MIT", | ||
| + "optional": true, | ||
| + "os": [ | ||
| + "win32" | ||
| + ], | ||
| + "engines": { | ||
| + "node": ">= 10" | ||
| + } | ||
| + }, | ||
| + "node_modules/@swc/counter": { | ||
| + "version": "0.1.3", | ||
| + "resolved": "https://registry.npmjs.org/@swc/counter/-/counter-0.1.3.tgz", | ||
| + "integrity": "sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==", | ||
| + "license": "Apache-2.0" | ||
| + }, | ||
| + "node_modules/@swc/helpers": { | ||
| + "version": "0.5.5", | ||
| + "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.5.tgz", | ||
| + "integrity": "sha512-KGYxvIOXcceOAbEk4bi/dVLEK9z8sZ0uBB3Il5b1rhfClSpcX0yfRO0KmTkqR2cnQDymwLB+25ZyMzICg/cm/A==", | ||
| + "license": "Apache-2.0", | ||
| + "dependencies": { | ||
| + "@swc/counter": "^0.1.3", | ||
| + "tslib": "^2.4.0" | ||
| + } | ||
| + }, | ||
| + "node_modules/@tsus/plugin": { | ||
| + "resolved": "../../packages/plugin", | ||
| + "link": true | ||
| + }, | ||
| + "node_modules/@tsus/runtime": { | ||
| + "resolved": "../../packages/runtime", | ||
| + "link": true | ||
| + }, | ||
| + "node_modules/busboy": { | ||
| + "version": "1.6.0", | ||
| + "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", | ||
| + "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==", | ||
| + "dependencies": { | ||
| + "streamsearch": "^1.1.0" | ||
| + }, | ||
| + "engines": { | ||
| + "node": ">=10.16.0" | ||
| + } | ||
| + }, | ||
| + "node_modules/caniuse-lite": { | ||
| + "version": "1.0.30001806", | ||
| + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001806.tgz", | ||
| + "integrity": "sha512-72Cuvd95zbSYPKq6Fhg8eDJRlzgWDf7/mtoZv6Qe/DYNCEBdNxoA3+rZAU2ZhGCpZlns3EssFavaZomckT5Uuw==", | ||
| + "funding": [ | ||
| + { | ||
| + "type": "opencollective", | ||
| + "url": "https://opencollective.com/browserslist" | ||
| + }, | ||
| + { | ||
| + "type": "tidelift", | ||
| + "url": "https://tidelift.com/funding/github/npm/caniuse-lite" | ||
| + }, | ||
| + { | ||
| + "type": "github", | ||
| + "url": "https://github.com/sponsors/ai" | ||
| + } | ||
| + ], | ||
| + "license": "CC-BY-4.0" | ||
| + }, | ||
| + "node_modules/client-only": { | ||
| + "version": "0.0.1", | ||
| + "resolved": "https://registry.npmjs.org/client-only/-/client-only-0.0.1.tgz", | ||
| + "integrity": "sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==", | ||
| + "license": "MIT" | ||
| + }, | ||
| + "node_modules/graceful-fs": { | ||
| + "version": "4.2.11", | ||
| + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", | ||
| + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", | ||
| + "license": "ISC" | ||
| + }, | ||
| + "node_modules/js-tokens": { | ||
| + "version": "4.0.0", | ||
| + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", | ||
| + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", | ||
| + "license": "MIT" | ||
| + }, | ||
| + "node_modules/loose-envify": { | ||
| + "version": "1.4.0", | ||
| + "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", | ||
| + "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", | ||
| + "license": "MIT", | ||
| + "dependencies": { | ||
| + "js-tokens": "^3.0.0 || ^4.0.0" | ||
| + }, | ||
| + "bin": { | ||
| + "loose-envify": "cli.js" | ||
| + } | ||
| + }, | ||
| + "node_modules/nanoid": { | ||
| + "version": "3.3.16", | ||
| + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.16.tgz", | ||
| + "integrity": "sha512-bzlKTyNJ7+LdGIIwy8ijFpIqEQIvafahV7eYykJ8Cvh42EdJeODoJ6gUJXpQJvej1BddH8OqTXZNE/KfbWAu8Q==", | ||
| + "funding": [ | ||
| + { | ||
| + "type": "github", | ||
| + "url": "https://github.com/sponsors/ai" | ||
| + } | ||
| + ], | ||
| + "license": "MIT", | ||
| + "bin": { | ||
| + "nanoid": "bin/nanoid.cjs" | ||
| + }, | ||
| + "engines": { | ||
| + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" | ||
| + } | ||
| + }, | ||
| + "node_modules/next": { | ||
| + "version": "14.2.5", | ||
| + "resolved": "https://registry.npmjs.org/next/-/next-14.2.5.tgz", | ||
| + "integrity": "sha512-0f8aRfBVL+mpzfBjYfQuLWh2WyAwtJXCRfkPF4UJ5qd2YwrHczsrSzXU4tRMV0OAxR8ZJZWPFn6uhSC56UTsLA==", | ||
| + "deprecated": "This version has a security vulnerability. Please upgrade to a patched version. See https://nextjs.org/blog/security-update-2025-12-11 for more details.", | ||
| + "license": "MIT", | ||
| + "dependencies": { | ||
| + "@next/env": "14.2.5", | ||
| + "@swc/helpers": "0.5.5", | ||
| + "busboy": "1.6.0", | ||
| + "caniuse-lite": "^1.0.30001579", | ||
| + "graceful-fs": "^4.2.11", | ||
| + "postcss": "8.4.31", | ||
| + "styled-jsx": "5.1.1" | ||
| + }, | ||
| + "bin": { | ||
| + "next": "dist/bin/next" | ||
| + }, | ||
| + "engines": { | ||
| + "node": ">=18.17.0" | ||
| + }, | ||
| + "optionalDependencies": { | ||
| + "@next/swc-darwin-arm64": "14.2.5", | ||
| + "@next/swc-darwin-x64": "14.2.5", | ||
| + "@next/swc-linux-arm64-gnu": "14.2.5", | ||
| + "@next/swc-linux-arm64-musl": "14.2.5", | ||
| + "@next/swc-linux-x64-gnu": "14.2.5", | ||
| + "@next/swc-linux-x64-musl": "14.2.5", | ||
| + "@next/swc-win32-arm64-msvc": "14.2.5", | ||
| + "@next/swc-win32-ia32-msvc": "14.2.5", | ||
| + "@next/swc-win32-x64-msvc": "14.2.5" | ||
| + }, | ||
| + "peerDependencies": { | ||
| + "@opentelemetry/api": "^1.1.0", | ||
| + "@playwright/test": "^1.41.2", | ||
| + "react": "^18.2.0", | ||
| + "react-dom": "^18.2.0", | ||
| + "sass": "^1.3.0" | ||
| + }, | ||
| + "peerDependenciesMeta": { | ||
| + "@opentelemetry/api": { | ||
| + "optional": true | ||
| + }, | ||
| + "@playwright/test": { | ||
| + "optional": true | ||
| + }, | ||
| + "sass": { | ||
| + "optional": true | ||
| + } | ||
| + } | ||
| + }, | ||
| + "node_modules/picocolors": { | ||
| + "version": "1.1.1", | ||
| + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", | ||
| + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", | ||
| + "license": "ISC" | ||
| + }, | ||
| + "node_modules/postcss": { | ||
| + "version": "8.4.31", | ||
| + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz", | ||
| + "integrity": "sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==", | ||
| + "funding": [ | ||
| + { | ||
| + "type": "opencollective", | ||
| + "url": "https://opencollective.com/postcss/" | ||
| + }, | ||
| + { | ||
| + "type": "tidelift", | ||
| + "url": "https://tidelift.com/funding/github/npm/postcss" | ||
| + }, | ||
| + { | ||
| + "type": "github", | ||
| + "url": "https://github.com/sponsors/ai" | ||
| + } | ||
| + ], | ||
| + "license": "MIT", | ||
| + "dependencies": { | ||
| + "nanoid": "^3.3.6", | ||
| + "picocolors": "^1.0.0", | ||
| + "source-map-js": "^1.0.2" | ||
| + }, | ||
| + "engines": { | ||
| + "node": "^10 || ^12 || >=14" | ||
| + } | ||
| + }, | ||
| + "node_modules/react": { | ||
| + "version": "18.3.1", | ||
| + "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", | ||
| + "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", | ||
| + "license": "MIT", | ||
| + "dependencies": { | ||
| + "loose-envify": "^1.1.0" | ||
| + }, | ||
| + "engines": { | ||
| + "node": ">=0.10.0" | ||
| + } | ||
| + }, | ||
| + "node_modules/react-dom": { | ||
| + "version": "18.3.1", | ||
| + "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz", | ||
| + "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==", | ||
| + "license": "MIT", | ||
| + "dependencies": { | ||
| + "loose-envify": "^1.1.0", | ||
| + "scheduler": "^0.23.2" | ||
| + }, | ||
| + "peerDependencies": { | ||
| + "react": "^18.3.1" | ||
| + } | ||
| + }, | ||
| + "node_modules/scheduler": { | ||
| + "version": "0.23.2", | ||
| + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.23.2.tgz", | ||
| + "integrity": "sha512-UOShsPwz7NrMUqhR6t0hWjFduvOzbtv7toDH1/hIrfRNIDBnnBWd0CwJTGvTpngVlmwGCdP9/Zl/tVrDqcuYzQ==", | ||
| + "license": "MIT", | ||
| + "dependencies": { | ||
| + "loose-envify": "^1.1.0" | ||
| + } | ||
| + }, | ||
| + "node_modules/source-map-js": { | ||
| + "version": "1.2.1", | ||
| + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz", | ||
| + "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==", | ||
| + "license": "BSD-3-Clause", | ||
| + "engines": { | ||
| + "node": ">=0.10.0" | ||
| + } | ||
| + }, | ||
| + "node_modules/streamsearch": { | ||
| + "version": "1.1.0", | ||
| + "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", | ||
| + "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==", | ||
| + "engines": { | ||
| + "node": ">=10.0.0" | ||
| + } | ||
| + }, | ||
| + "node_modules/styled-jsx": { | ||
| + "version": "5.1.1", | ||
| + "resolved": "https://registry.npmjs.org/styled-jsx/-/styled-jsx-5.1.1.tgz", | ||
| + "integrity": "sha512-pW7uC1l4mBZ8ugbiZrcIsiIvVx1UmTfw7UkC3Um2tmfUq9Bhk8IiyEIPl6F8agHgjzku6j0xQEZbfA5uSgSaCw==", | ||
| + "license": "MIT", | ||
| + "dependencies": { | ||
| + "client-only": "0.0.1" | ||
| + }, | ||
| + "engines": { | ||
| + "node": ">= 12.0.0" | ||
| + }, | ||
| + "peerDependencies": { | ||
| + "react": ">= 16.8.0 || 17.x.x || ^18.0.0-0" | ||
| + }, | ||
| + "peerDependenciesMeta": { | ||
| + "@babel/core": { | ||
| + "optional": true | ||
| + }, | ||
| + "babel-plugin-macros": { | ||
| + "optional": true | ||
| + } | ||
| + } | ||
| + }, | ||
| + "node_modules/tslib": { | ||
| + "version": "2.8.1", | ||
| + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", | ||
| + "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", | ||
| + "license": "0BSD" | ||
| + } | ||
| + } | ||
| +} | ||
Addedexamples/27-nextjs/package.json+14−0
| @@ -0,0 +1,14 @@ | ||
| +{ | ||
| + "name": "example-nextjs", | ||
| + "private": true, | ||
| + "scripts": { | ||
| + "build": "next build" | ||
| + }, | ||
| + "dependencies": { | ||
| + "@tsus/plugin": "file:../../packages/plugin", | ||
| + "@tsus/runtime": "file:../../packages/runtime", | ||
| + "next": "14.2.5", | ||
| + "react": "18.3.1", | ||
| + "react-dom": "18.3.1" | ||
| + } | ||
| +} | ||
Addedexamples/27-nextjs/pages/index.jsx+5−0
| @@ -0,0 +1,5 @@ | ||
| +import { pageTitle } from "../lib/greeting.tsus"; | ||
| + | ||
| +export default function Home() { | ||
| + return <main>{pageTitle("Next.js")}</main>; | ||
| +} | ||
Addedexamples/28-astro/.gitignore+2−0
| @@ -0,0 +1,2 @@ | ||
| +dist/ | ||
| +.astro/ | ||
Addedexamples/28-astro/astro.config.mjs+8−0
| @@ -0,0 +1,8 @@ | ||
| +import { defineConfig } from "astro/config"; | ||
| +import tsus from "@tsus/plugin/vite"; | ||
| + | ||
| +export default defineConfig({ | ||
| + vite: { | ||
| + plugins: [tsus()], | ||
| + }, | ||
| +}); | ||
Addedexamples/28-astro/example.json+8−0
| @@ -0,0 +1,8 @@ | ||
| +{ | ||
| + "expect": "command", | ||
| + "install": true, | ||
| + "command": ["npm", "run", "build"], | ||
| + "fileContains": [ | ||
| + { "file": "dist/index.html", "contains": "Astro says: tsus works through the Vite plugin" } | ||
| + ] | ||
| +} | ||
Addedexamples/28-astro/package-lock.json
This change is too large to show here (more than 1,000 changed lines). View the file or the raw file.
Addedexamples/28-astro/package.json+12−0
| @@ -0,0 +1,12 @@ | ||
| +{ | ||
| + "name": "example-astro", | ||
| + "private": true, | ||
| + "scripts": { | ||
| + "build": "astro build" | ||
| + }, | ||
| + "dependencies": { | ||
| + "@tsus/plugin": "file:../../packages/plugin", | ||
| + "@tsus/runtime": "file:../../packages/runtime", | ||
| + "astro": "4.16.18" | ||
| + } | ||
| +} | ||
Addedexamples/28-astro/src/env.d.ts+1−0
| @@ -0,0 +1 @@ | ||
| +/// <reference path="../.astro/types.d.ts" /> | ||
| \ No newline at end of file | ||
Addedexamples/28-astro/src/lib/banner.tsus+11−0
| @@ -0,0 +1,11 @@ | ||
| +import { Ok, Err, type Result } from "@tsus/runtime"; | ||
| +import { suffix } from "./suffix.tsus"; | ||
| + | ||
| +const checkFramework = (name: string): Result<string, string> => | ||
| + name.length > 0 ? Ok(name) : Err("unnamed framework"); | ||
| + | ||
| +export const headline = (name: string): string => | ||
| + match (checkFramework(name)) { | ||
| + Ok(framework) => `${framework} says: tsus works ${suffix()}`, | ||
| + Err(reason) => `broken: ${reason}`, | ||
| + }; | ||
Addedexamples/28-astro/src/lib/suffix.tsus+1−0
| @@ -0,0 +1 @@ | ||
| +export const suffix = (): string => "through the Vite plugin"; | ||
Addedexamples/28-astro/src/pages/index.astro+11−0
| @@ -0,0 +1,11 @@ | ||
| +--- | ||
| +import { headline } from "../lib/banner.tsus"; | ||
| +--- | ||
| +<html lang="en"> | ||
| + <head> | ||
| + <title>tsus + Astro</title> | ||
| + </head> | ||
| + <body> | ||
| + <h1>{headline("Astro")}</h1> | ||
| + </body> | ||
| +</html> | ||
Addedexamples/29-bun/bunfig.toml+1−0
| @@ -0,0 +1 @@ | ||
| +preload = ["./tsus-preload.js"] | ||
Addedexamples/29-bun/example.json+6−0
| @@ -0,0 +1,6 @@ | ||
| +{ | ||
| + "expect": "command", | ||
| + "install": true, | ||
| + "command": ["npx", "--no-install", "bun", "src/main.ts"], | ||
| + "output": ["bun is fast and runs .tsus natively"] | ||
| +} | ||
Addedexamples/29-bun/package-lock.json+156−0
| @@ -0,0 +1,156 @@ | ||
| +{ | ||
| + "name": "example-bun", | ||
| + "lockfileVersion": 3, | ||
| + "requires": true, | ||
| + "packages": { | ||
| + "": { | ||
| + "name": "example-bun", | ||
| + "devDependencies": { | ||
| + "bun": "1.1.34" | ||
| + } | ||
| + }, | ||
| + "node_modules/@oven/bun-darwin-aarch64": { | ||
| + "version": "1.1.34", | ||
| + "resolved": "https://registry.npmjs.org/@oven/bun-darwin-aarch64/-/bun-darwin-aarch64-1.1.34.tgz", | ||
| + "integrity": "sha512-p+E2CkJhCYsQyzRcuUsTA5HIHSRMq0J+aX6fiPo5iheFQAZCrhdfeAWmlU8cjZmIBvmZYbNZ96g1VVlx+ooJkg==", | ||
| + "cpu": [ | ||
| + "arm64" | ||
| + ], | ||
| + "dev": true, | ||
| + "license": "MIT", | ||
| + "optional": true, | ||
| + "os": [ | ||
| + "darwin" | ||
| + ] | ||
| + }, | ||
| + "node_modules/@oven/bun-darwin-x64": { | ||
| + "version": "1.1.34", | ||
| + "resolved": "https://registry.npmjs.org/@oven/bun-darwin-x64/-/bun-darwin-x64-1.1.34.tgz", | ||
| + "integrity": "sha512-B6FC7EjRCEMMs7DxAEULqCgr8Td+A1ZI8YHWpBGhHZ2+Th/3QTM0IbfWg1cbBkgipKokiyVS/lx15iBAN4njFA==", | ||
| + "cpu": [ | ||
| + "x64" | ||
| + ], | ||
| + "dev": true, | ||
| + "license": "MIT", | ||
| + "optional": true, | ||
| + "os": [ | ||
| + "darwin" | ||
| + ] | ||
| + }, | ||
| + "node_modules/@oven/bun-darwin-x64-baseline": { | ||
| + "version": "1.1.34", | ||
| + "resolved": "https://registry.npmjs.org/@oven/bun-darwin-x64-baseline/-/bun-darwin-x64-baseline-1.1.34.tgz", | ||
| + "integrity": "sha512-Uugg1eANnEfdma6TDZt5T2A3cHcOjnxSoGnQp8AY300olImd6QGvx5NfWMbo86/mvnFqfCN5YFR+behhHqekWQ==", | ||
| + "cpu": [ | ||
| + "x64" | ||
| + ], | ||
| + "dev": true, | ||
| + "license": "MIT", | ||
| + "optional": true, | ||
| + "os": [ | ||
| + "darwin" | ||
| + ] | ||
| + }, | ||
| + "node_modules/@oven/bun-linux-aarch64": { | ||
| + "version": "1.1.34", | ||
| + "resolved": "https://registry.npmjs.org/@oven/bun-linux-aarch64/-/bun-linux-aarch64-1.1.34.tgz", | ||
| + "integrity": "sha512-A81KHRU+8CRFrbyIGikxS+VZO5E0LW4V6a5gRBuK4gJUZ4CsC9uEeXNfHtSwT288dnfwnlR3dtOTwI4kUSsIVQ==", | ||
| + "cpu": [ | ||
| + "arm64" | ||
| + ], | ||
| + "dev": true, | ||
| + "license": "MIT", | ||
| + "optional": true, | ||
| + "os": [ | ||
| + "linux" | ||
| + ] | ||
| + }, | ||
| + "node_modules/@oven/bun-linux-x64": { | ||
| + "version": "1.1.34", | ||
| + "resolved": "https://registry.npmjs.org/@oven/bun-linux-x64/-/bun-linux-x64-1.1.34.tgz", | ||
| + "integrity": "sha512-3J3G/BVolxO/YFC8Q9PvhjtQvT5VSbK2qqxXwZbgvUug1GxaEHc4KxV6ZSRZRmdadCoPfhcljQdoPCePbT4WrQ==", | ||
| + "cpu": [ | ||
| + "x64" | ||
| + ], | ||
| + "dev": true, | ||
| + "license": "MIT", | ||
| + "optional": true, | ||
| + "os": [ | ||
| + "linux" | ||
| + ] | ||
| + }, | ||
| + "node_modules/@oven/bun-linux-x64-baseline": { | ||
| + "version": "1.1.34", | ||
| + "resolved": "https://registry.npmjs.org/@oven/bun-linux-x64-baseline/-/bun-linux-x64-baseline-1.1.34.tgz", | ||
| + "integrity": "sha512-BosC6W9WWU8rBsxpvCrs59LQ2DAjqafxZ5dXbP3MSzNn6HyN496Cj+jcYzM8UUkYnzkQJDXOPIJhvto69mQ2VQ==", | ||
| + "cpu": [ | ||
| + "x64" | ||
| + ], | ||
| + "dev": true, | ||
| + "license": "MIT", | ||
| + "optional": true, | ||
| + "os": [ | ||
| + "linux" | ||
| + ] | ||
| + }, | ||
| + "node_modules/@oven/bun-windows-x64": { | ||
| + "version": "1.1.34", | ||
| + "resolved": "https://registry.npmjs.org/@oven/bun-windows-x64/-/bun-windows-x64-1.1.34.tgz", | ||
| + "integrity": "sha512-wJOsC5mB1qBLmRwV61F1KHL0MOjEHtK/xJ7ddktcWc05+W2U4Y60j100VwdUVcCaRh0wCcehLilCnUpjjGng3Q==", | ||
| + "cpu": [ | ||
| + "x64" | ||
| + ], | ||
| + "dev": true, | ||
| + "license": "MIT", | ||
| + "optional": true, | ||
| + "os": [ | ||
| + "win32" | ||
| + ] | ||
| + }, | ||
| + "node_modules/@oven/bun-windows-x64-baseline": { | ||
| + "version": "1.1.34", | ||
| + "resolved": "https://registry.npmjs.org/@oven/bun-windows-x64-baseline/-/bun-windows-x64-baseline-1.1.34.tgz", | ||
| + "integrity": "sha512-kPtszE3NUM9Rd3GTJKD2TugoyjwPjMjbiMRX3wZE/YQBFRyATLGzKmxThwN1d2JPwTQGENrttpb15Qf95doSbA==", | ||
| + "cpu": [ | ||
| + "x64" | ||
| + ], | ||
| + "dev": true, | ||
| + "license": "MIT", | ||
| + "optional": true, | ||
| + "os": [ | ||
| + "win32" | ||
| + ] | ||
| + }, | ||
| + "node_modules/bun": { | ||
| + "version": "1.1.34", | ||
| + "resolved": "https://registry.npmjs.org/bun/-/bun-1.1.34.tgz", | ||
| + "integrity": "sha512-ULiiLQG+bQC6YHW6u9jisGtwVn8msgqvDvurwsEs26mKtcAl7lRS+5yKfo/xxxnrcSIqx1QFM4vqki42s6GDVw==", | ||
| + "cpu": [ | ||
| + "arm64", | ||
| + "x64" | ||
| + ], | ||
| + "dev": true, | ||
| + "hasInstallScript": true, | ||
| + "license": "MIT", | ||
| + "os": [ | ||
| + "darwin", | ||
| + "linux", | ||
| + "win32" | ||
| + ], | ||
| + "bin": { | ||
| + "bun": "bin/bun.exe", | ||
| + "bunx": "bin/bun.exe" | ||
| + }, | ||
| + "optionalDependencies": { | ||
| + "@oven/bun-darwin-aarch64": "1.1.34", | ||
| + "@oven/bun-darwin-x64": "1.1.34", | ||
| + "@oven/bun-darwin-x64-baseline": "1.1.34", | ||
| + "@oven/bun-linux-aarch64": "1.1.34", | ||
| + "@oven/bun-linux-x64": "1.1.34", | ||
| + "@oven/bun-linux-x64-baseline": "1.1.34", | ||
| + "@oven/bun-windows-x64": "1.1.34", | ||
| + "@oven/bun-windows-x64-baseline": "1.1.34" | ||
| + } | ||
| + } | ||
| + } | ||
| +} | ||
Addedexamples/29-bun/package.json+7−0
| @@ -0,0 +1,7 @@ | ||
| +{ | ||
| + "name": "example-bun", | ||
| + "private": true, | ||
| + "devDependencies": { | ||
| + "bun": "1.1.34" | ||
| + } | ||
| +} | ||
Addedexamples/29-bun/src/app.tsus+10−0
| @@ -0,0 +1,10 @@ | ||
| +import { Some, None, type Option } from "@tsus/runtime"; | ||
| +import { runtimeName } from "./meta.tsus"; | ||
| + | ||
| +const flavor: Option<string> = Some("fast"); | ||
| + | ||
| +export const banner = (): string => | ||
| + match (flavor) { | ||
| + Some(adjective) => `bun is ${adjective} and runs ${runtimeName()} natively`, | ||
| + None => "bun has no flavor", | ||
| + }; | ||
Addedexamples/29-bun/src/main.ts+4−0
| @@ -0,0 +1,4 @@ | ||
| +// Plain TS entrypoint; the .tsus import is handled by the preloaded plugin. | ||
| +import { banner } from "./app.tsus"; | ||
| + | ||
| +console.log(banner()); | ||
Addedexamples/29-bun/src/meta.tsus+1−0
| @@ -0,0 +1 @@ | ||
| +export const runtimeName = (): string => ".tsus"; | ||
Addedexamples/29-bun/tsus-preload.js+7−0
| @@ -0,0 +1,7 @@ | ||
| +// Registers the tsus transform with Bun's runtime, so `bun src/main.ts` | ||
| +// resolves .tsus imports natively. Bun's plugin API is esbuild-shaped, so the | ||
| +// esbuild adapter is reused as-is. | ||
| +import { plugin } from "bun"; | ||
| +import tsusPlugin from "../../packages/plugin/esbuild.js"; | ||
| + | ||
| +plugin(tsusPlugin()); | ||
Changedpackage-lock.json+12−0
| @@ -17,6 +17,10 @@ | ||
| "resolved": "packages/cli", | ||
| "link": true | ||
| }, | ||
| + "node_modules/@tsus/plugin": { | ||
| + "resolved": "packages/plugin", | ||
| + "link": true | ||
| + }, | ||
| "node_modules/@tsus/runtime": { | ||
| "resolved": "packages/runtime", | ||
| "link": true | ||
| @@ -51,6 +55,14 @@ | ||
| }, | ||
| "bin": { | ||
| "tsus": "bin/tsus.js" | ||
| + } | ||
| + }, | ||
| + "packages/plugin": { | ||
| + "name": "@tsus/plugin", | ||
| + "version": "0.1.0", | ||
| + "dependencies": { | ||
| + "@tsus/cli": "file:../cli", | ||
| + "typescript": "^5.5.0" | ||
| } | ||
| }, | ||
| "packages/runtime": { | ||
Changedpackages/cli/package.json+5−0
| @@ -5,6 +5,11 @@ | ||
| "bin": { | ||
| "tsus": "./bin/tsus.js" | ||
| }, | ||
| + "exports": { | ||
| + "./preprocess": "./src/preprocess.js", | ||
| + "./check": "./src/check.js", | ||
| + "./build": "./src/build.js" | ||
| + }, | ||
| "dependencies": { | ||
| "typescript": "^5.5.0" | ||
| } | ||
Addedpackages/plugin/bun.js+7−0
| @@ -0,0 +1,7 @@ | ||
| +// Bun preload module: add `preload = ["@tsus/plugin/bun"]` to bunfig.toml | ||
| +// (or preload a local file that does the same) and Bun runs .tsus imports | ||
| +// natively, dev server included. | ||
| +import { plugin } from "bun"; | ||
| +import tsusPlugin from "./esbuild.js"; | ||
| + | ||
| +plugin(tsusPlugin()); | ||
Addedpackages/plugin/core.js+45−0
| @@ -0,0 +1,45 @@ | ||
| +// Shared transform behind every bundler adapter: preprocess the match macro, | ||
| +// enforce the strictness rules, strip types. Emits plain JS but leaves import | ||
| +// specifiers untouched so the host bundler resolves .tsus -> .tsus chains | ||
| +// through its own pipeline (each hop hits this transform again). | ||
| +import ts from "typescript"; | ||
| +import { preprocess, PreprocessError } from "@tsus/cli/preprocess"; | ||
| +import { checkSource } from "@tsus/cli/check"; | ||
| + | ||
| +const RUNTIME_IMPORT = `import { __tsus_match } from "@tsus/runtime";\n`; | ||
| + | ||
| +export class TsusTransformError extends Error { | ||
| + constructor(message, diagnostics) { | ||
| + super(message); | ||
| + this.name = "TsusTransformError"; | ||
| + this.diagnostics = diagnostics; | ||
| + } | ||
| +} | ||
| + | ||
| +export const transformSource = (source, fileName) => { | ||
| + let pre; | ||
| + try { | ||
| + pre = preprocess(source); | ||
| + } catch (error) { | ||
| + if (error instanceof PreprocessError) { | ||
| + throw new TsusTransformError(`${fileName}: ${error.message}`, [ | ||
| + { code: error.code, message: error.message, file: fileName }, | ||
| + ]); | ||
| + } | ||
| + throw error; | ||
| + } | ||
| + const diagnostics = checkSource(fileName, pre.code); | ||
| + if (diagnostics.length > 0) { | ||
| + const summary = diagnostics | ||
| + .map((d) => `${d.code} ${d.file}:${d.line}:${d.col} ${d.message}`) | ||
| + .join("\n"); | ||
| + throw new TsusTransformError(summary, diagnostics); | ||
| + } | ||
| + const tsCode = pre.changed ? RUNTIME_IMPORT + pre.code : pre.code; | ||
| + return ts.transpileModule(tsCode, { | ||
| + compilerOptions: { | ||
| + module: ts.ModuleKind.ESNext, | ||
| + target: ts.ScriptTarget.ES2022, | ||
| + }, | ||
| + }).outputText; | ||
| +}; | ||
Addedpackages/plugin/esbuild.js+16−0
| @@ -0,0 +1,16 @@ | ||
| +// esbuild plugin. Bun's plugin API is esbuild-shaped, so this same object | ||
| +// works for Bun.plugin (see bun.js). | ||
| +import fs from "node:fs/promises"; | ||
| +import { transformSource } from "./core.js"; | ||
| + | ||
| +const tsusPlugin = () => ({ | ||
| + name: "tsus", | ||
| + setup(build) { | ||
| + build.onLoad({ filter: /\.tsus$/ }, async (args) => ({ | ||
| + contents: transformSource(await fs.readFile(args.path, "utf8"), args.path), | ||
| + loader: "js", | ||
| + })); | ||
| + }, | ||
| +}); | ||
| + | ||
| +export default tsusPlugin; | ||
Addedpackages/plugin/package.json+16−0
| @@ -0,0 +1,16 @@ | ||
| +{ | ||
| + "name": "@tsus/plugin", | ||
| + "version": "0.1.0", | ||
| + "type": "module", | ||
| + "exports": { | ||
| + ".": "./core.js", | ||
| + "./vite": "./vite.js", | ||
| + "./esbuild": "./esbuild.js", | ||
| + "./bun": "./bun.js", | ||
| + "./webpack": "./webpack.cjs" | ||
| + }, | ||
| + "dependencies": { | ||
| + "@tsus/cli": "file:../cli", | ||
| + "typescript": "^5.5.0" | ||
| + } | ||
| +} | ||
Addedpackages/plugin/vite.js+17−0
| @@ -0,0 +1,17 @@ | ||
| +// Vite plugin. Also covers Astro, SvelteKit, Nuxt, and anything else | ||
| +// Vite-based via their vite.plugins config. | ||
| +import fs from "node:fs"; | ||
| +import { transformSource } from "./core.js"; | ||
| + | ||
| +export default function tsus() { | ||
| + return { | ||
| + name: "tsus", | ||
| + enforce: "pre", | ||
| + load(id) { | ||
| + if (!id.endsWith(".tsus")) { | ||
| + return null; | ||
| + } | ||
| + return transformSource(fs.readFileSync(id, "utf8"), id); | ||
| + }, | ||
| + }; | ||
| +} | ||
Addedpackages/plugin/webpack.cjs+11−0
| @@ -0,0 +1,11 @@ | ||
| +// Webpack loader. CommonJS entry (webpack requires loaders synchronously) | ||
| +// that hands off to the ESM core via the async loader API. Works in Next.js | ||
| +// through next.config webpack(config) — see examples/27-nextjs. | ||
| +module.exports = function tsusLoader(source) { | ||
| + const callback = this.async(); | ||
| + import("./core.js") | ||
| + .then(({ transformSource }) => { | ||
| + callback(null, transformSource(source, this.resourcePath)); | ||
| + }) | ||
| + .catch(callback); | ||
| +}; | ||
Changedscripts/run-examples.mjs+39−0
| @@ -36,6 +36,45 @@ | ||
| const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8")); | ||
| let failure = ""; | ||
| + if (manifest.expect === "command") { | ||
| + // Framework examples: install their own deps, run their own build/run | ||
| + // command, then assert on stdout and/or produced files. | ||
| + if (manifest.install && !fs.existsSync(path.join(dir, "node_modules"))) { | ||
| + const ri = spawnSync("npm", ["install", "--no-audit", "--no-fund"], { | ||
| + cwd: dir, | ||
| + encoding: "utf8", | ||
| + timeout: 600_000, | ||
| + }); | ||
| + if (ri.status !== 0) { | ||
| + failure = `npm install failed:\n${(ri.stderr || ri.stdout || "").trim().slice(-2000)}`; | ||
| + } | ||
| + } | ||
| + if (failure === "") { | ||
| + const rc = spawnSync(manifest.command[0], manifest.command.slice(1), { | ||
| + cwd: dir, | ||
| + encoding: "utf8", | ||
| + timeout: 600_000, | ||
| + }); | ||
| + if (rc.status !== 0) { | ||
| + failure = `command failed:\n${(rc.stderr || rc.stdout || "").trim().slice(-2000)}`; | ||
| + } else { | ||
| + if (manifest.output) { | ||
| + failure = checkLines(rc.stdout, manifest.output); | ||
| + } | ||
| + for (const fc of manifest.fileContains ?? []) { | ||
| + const produced = path.join(dir, fc.file); | ||
| + if (!fs.existsSync(produced)) { | ||
| + failure = `expected output file ${fc.file} was not produced`; | ||
| + } else if (!fs.readFileSync(produced, "utf8").includes(fc.contains)) { | ||
| + failure = `${fc.file} does not contain ${JSON.stringify(fc.contains)}`; | ||
| + } | ||
| + } | ||
| + } | ||
| + } | ||
| + results.push({ name, ok: failure === "", failure }); | ||
| + continue; | ||
| + } | ||
| + | ||
| if (manifest.expect === "check-fail") { | ||
| const r = runNode([cliBin, "check", dir, "--json"], repoRoot); | ||
| if (r.status === 0) { | ||
Checks
No checks reported for this commit.
Runs
No runs for this commit.