diff --git a/README.md b/README.md index b534d3b8..f016ff45 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,5 @@ _Personalize headless CMSs without compromising on SEO._ - **astro-client-interaction** - load and hydrate framework components on first interaction. [README](https://github.com/lilnasy/gratelets/tree/main/packages/client-interaction) | [NPM](https://www.npmjs.com/package/astro-client-interaction) - **astro-emotion** - CSS-in-Zero-JS using [Emotion](https://emotion.sh/). [README](https://github.com/lilnasy/gratelets/tree/main/packages/emotion) | [NPM](https://www.npmjs.com/package/astro-emotion) - **astro-global** - use the Astro global directly inside framework components and MDX pages. [README](https://github.com/lilnasy/gratelets/tree/main/packages/global) | [NPM](https://www.npmjs.com/package/astro-global) -- **astro-prerender-patterns** - control rendering modes for all pages and endpoints right from the configuration. [README](https://github.com/lilnasy/gratelets/tree/main/packages/prerender-patterns) | [NPM](https://www.npmjs.com/package/astro-prerender-patterns) - **astro-scope** - get the hash used by the astro compiler to scope css rules. [README](https://github.com/lilnasy/gratelets/tree/main/packages/scope) | [NPM](https://www.npmjs.com/package/astro-scope) - **astro-server-only-modules** - prevent certain modules from being imported into client-side code. [README](https://github.com/lilnasy/gratelets/tree/main/packages/server-only-modules) | [NPM](https://www.npmjs.com/package/astro-server-only-modules) diff --git a/package.json b/package.json index 6d49c455..c1faf58a 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "install:chromium": "pnpm --filter tests-e2e exec playwright install chromium", "test:e2e": "pnpm --filter tests-e2e exec node --no-warnings --experimental-loader playwright/lib/transform/esmLoader node_modules/playwright/cli.js test --workers=1 --timeout 5000 -x" }, - "packageManager": "pnpm@10.17.0", + "packageManager": "pnpm@10.24.0", "devDependencies": { "@changesets/changelog-github": "0.5", "@changesets/cli": "2", diff --git a/packages/prerender-patterns/CHANGELOG.md b/packages/prerender-patterns/CHANGELOG.md deleted file mode 100644 index d46e2f3e..00000000 --- a/packages/prerender-patterns/CHANGELOG.md +++ /dev/null @@ -1,17 +0,0 @@ -# astro-prerender-patterns - -## 1.0.1 - -### Patch Changes - -- [#161](https://github.com/lilnasy/gratelets/pull/161) [`2894884`](https://github.com/lilnasy/gratelets/commit/2894884712498db4b710fdf4398d6e51b225a816) Thanks [@lilnasy](https://github.com/lilnasy)! - To mitigate the possibility of supply chain attacks, the publishing automation for the package is now managed completely without NPM tokens and API keys. The github actions workflow responsible for building and releasing the packages is directly hooked up to NPM as a [Trusted Publisher](https://docs.npmjs.com/trusted-publishers#how-trusted-publishing-works). The author @lilnasy's NPM and GitHub account is secured with two factor authentication. E-mail is NOT one of the used authentication factors. - - A provenance statement are generated every time the package is built and published, viewable on the NPM page. The statement includes auditable metadata such as the source commit, the exact workflow description, and logs from the run. Given how provenance is presented in the UI as green check mark, it's important to point out that it is NOT an indication that there is nothing malicious going on. It simply allows you to track the progress of building the source code into the published package you will download. - - Additionally, the package manager for this repo, pnpm, is configured to only allow dependencies that have been released for at least 7 days. This is a precaution against installing a compromised dependency before the author or the registry has had the time to identify and unpublish it. Note that this configuration only defends the maintainers and contributors of the package from supply chain attacks; users of the package must implement their own defenses. - -## 1.0.0 - -### Major Changes - -- [#6](https://github.com/lilnasy/gratelets/pull/6) [`2f61e49`](https://github.com/lilnasy/gratelets/commit/2f61e49c5518767122f4bfb5c318ae454d18c829) Thanks [@lilnasy](https://github.com/lilnasy)! - Initial release diff --git a/packages/prerender-patterns/README.md b/packages/prerender-patterns/README.md deleted file mode 100644 index 3f4e4021..00000000 --- a/packages/prerender-patterns/README.md +++ /dev/null @@ -1,91 +0,0 @@ -# astro-prerender-patterns💈 - -This **[Astro integration][astro-integration]** allows you control rendering modes for all pages and endpoints in a single place. - -- [Why astro-prerender-patterns?](#why-astro-prerender-patterns) -- [Installation](#installation) -- [Usage](#usage) -- [Troubleshooting](#troubleshooting) -- [Contributing](#contributing) -- [Changelog](#changelog) - -## Why astro-prerender-patterns? - -If you are using astro for server side rendering, you can opt-in individual pages to be prerendered. However, you must do it by editing each file. This integration lets you control the rendering mode for all pages and endpoints right from the configuration file. - -## Installation - -### Manual Install - -First, install the `astro-prerender-patterns` package using your package manager. If you're using npm or aren't sure, run this in the terminal: - -```sh -npm install astro-prerender-patterns -``` - -Then, apply this integration to your `astro.config.*` file using the `integrations` property: - -```diff lang="js" - // astro.config.mjs - import { defineConfig } from 'astro/config'; -+ import prerenderPatterns from 'astro-prerender-patterns'; - - export default defineConfig({ - // ... -+ integrations: [prerenderPatterns()], - // ^^^^^^^^^^^^^^^^^^^ - }); -``` - -## Usage - -Once the integration is installed and added to the configuration file, you can pass it a function that lets you decide which routes get prerendered. - -```js -export default defineConfig({ - // ... - integrations: [ - prerenderPatterns(filePath => { - if (filePath.endsWith(".astro")) return "prerender" - if (filePath.endsWith(".ts")) return "render on demand" - }) - ], - // ... -}); -``` - -The callback function receives the path of the file being rendered, relative to the root of your project. To override the current rendering mode, return either `"prerender"`, or `"render on demand"`. If neither of these two strings are returned, Astro's regular behavior as documented in [On⁠-⁠demand Rendering Adapters](https://docs.astro.build/en/guides/server-side-rendering/) applies. - -If you would like to take into account the current rendering mode, you can read the second argument passed to the callback function: - -```js -export default defineConfig({ - // ... - integrations: [ - prerenderPatterns((file, currentMode) => { - if (currentMode === "prerender") return "render on demand" - }) - ], - // ... -}); -``` - -For convenience, the strings `"prerender"` and `"render on demand"` are exported from the package as `prerender` and `renderOnDemand` respectively. You can use these to prevent typing mistakes: - -```js -import prerenderPatterns, { prerender, renderOnDemand } from "astro-prerender-patterns"; -``` - -## Troubleshooting - -For help, check out the `Discussions` tab on the [GitHub repo](https://github.com/lilnasy/gratelets/discussions). - -## Contributing - -This package is maintained by [lilnasy](https://github.com/lilnasy) independently from Astro. The integration code is located at [packages/prerender-patterns/integration.ts](https://github.com/lilnasy/gratelets/blob/main/packages/prerender-patterns/integration.ts). You're welcome to contribute by opening a PR or submitting an issue! - -## Changelog - -See [CHANGELOG.md](https://github.com/lilnasy/gratelets/blob/main/packages/prerender-patterns/CHANGELOG.md) for a history of changes to this integration. - -[astro-integration]: https://docs.astro.build/en/guides/integrations-guide/ diff --git a/packages/prerender-patterns/integration.ts b/packages/prerender-patterns/integration.ts deleted file mode 100644 index f522aa2f..00000000 --- a/packages/prerender-patterns/integration.ts +++ /dev/null @@ -1,85 +0,0 @@ -import type { AstroIntegration, AstroConfig } from "astro" -import url from "node:url" -import { parseAstroRequest } from "./node_modules/astro/dist/vite-plugin-astro/query.js" - -export const prerender = "prerender" -export const renderOnDemand = "render on demand" - -type Directive = - | typeof prerender - | typeof renderOnDemand - -interface Callback { - (path: string, currentDecision: Directive): Directive | undefined | null | void -} - -export default function (callback?: Callback): AstroIntegration { - const cache = new Map> - return { - name: "prerender-patterns", - hooks: { - "astro:config:setup" ({ logger, config, updateConfig }) { - if (callback === undefined) { - return logger.warn("No callback was provided. This integration will not do anything.") - } - else if (typeof callback !== "function") { - return logger.error(`The argument to this integration must be a function, but ${typeof callback} was provided instead.`) - } - updateConfig({ vite: { plugins: [{ - name: "prerender-patterns", - outputOptions() { - const absolutePathPrefix = url.fileURLToPath(config.root).replaceAll("\\", "/") - - for (const moduleId of this.getModuleIds()) { - if (moduleId.startsWith(absolutePathPrefix) === false) continue - const moduleInfo = this.getModuleInfo(moduleId) - - const pageOptions = moduleInfo?.meta?.astro?.pageOptions - if (pageOptions === undefined) continue - - const current: boolean = pageOptions.prerender - const { filename } = parseAstroRequest(moduleId) - const relativePath = filename.slice(absolutePathPrefix.length) - - let override: ReturnType - - if (cache.has(relativePath)) { - override = cache.get(relativePath) - } else { - override = callback(relativePath, current ? prerender : renderOnDemand) - cache.set(relativePath, override) - } - - if (override === undefined || override === null) continue - - else if (override === prerender) { - if (current === true) logger.debug(`${relativePath} is already prerendered.`) - else { - pageOptions.prerender = true - logger.debug(`${relativePath} will now be prerendered.`) - } - } - - else if (override === "render on demand") { - if (current === false) logger.debug(`${relativePath} is already being rendered on demand.`) - else { - pageOptions.prerender = false - logger.debug(`${relativePath} will now be rendered on demand.`) - } - } - - else if (typeof override === "boolean") { - logger.error(`Directive for ${relativePath} is not recognised: ${override}. Did you mean to return ${override ? `"${prerender}"` : `"${renderOnDemand}"`} instead?`) - } - - else { - logger.error(`Directive for ${relativePath} is not recognised. This will have no effect. Please make sure the directive is either "${prerender}" or "${renderOnDemand}".`) - console.error("Provided directive:", override) - } - } - } - }] } }) - } - } - } -} diff --git a/packages/prerender-patterns/package.json b/packages/prerender-patterns/package.json deleted file mode 100644 index cd03e51c..00000000 --- a/packages/prerender-patterns/package.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "name": "astro-prerender-patterns", - "version": "1.0.1", - "description": "Control rendering modes for all pages and endpoints in your Astro project right from the configuration.", - "author": { - "name": "Arsh", - "email": "hi@arsh.sh", - "url": "https://arsh.sh" - }, - "license": "Public Domain", - "keywords": [ - "withastro", - "astro-component" - ], - "homepage": "https://github.com/lilnasy/gratelets/tree/main/packages/prerender-patterns", - "repository": { - "type": "git", - "url": "https://github.com/lilnasy/gratelets", - "directory": "packages/prerender-patterns" - }, - "files": [ - "integration.ts" - ], - "exports": { - ".": "./integration.ts" - }, - "scripts": { - "test": "pnpm -w test prerender-patterns.test.ts" - }, - "type": "module", - "devDependencies": { - "@types/node": "22", - "astro": "5" - } -} \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 12b209c8..bf116457 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -195,15 +195,6 @@ importers: specifier: ^1.0.4 version: 1.0.4 - packages/prerender-patterns: - devDependencies: - '@types/node': - specifier: '22' - version: 22.17.0 - astro: - specifier: '5' - version: 5.12.6(@types/node@22.17.0)(jiti@2.5.1)(lightningcss@1.30.1)(rollup@4.46.2)(typescript@5.7.3) - packages/scope: devDependencies: '@types/node': @@ -452,15 +443,6 @@ importers: specifier: '10' version: 10.27.0 - tests/fixtures/prerender-patterns: - dependencies: - astro: - specifier: '5' - version: 5.12.6(@types/node@22.17.0)(jiti@2.5.1)(lightningcss@1.30.1)(rollup@4.46.2)(typescript@5.7.3) - astro-prerender-patterns: - specifier: workspace:* - version: link:../../../packages/prerender-patterns - tests/fixtures/scope: dependencies: astro: @@ -1524,67 +1506,79 @@ packages: resolution: {integrity: sha512-9B+taZ8DlyyqzZQnoeIvDVR/2F4EbMepXMc/NdVbkzsJbzkUjhXv/70GQJ7tdLA4YJgNP25zukcxpX2/SueNrA==} cpu: [arm64] os: [linux] + libc: [glibc] '@img/sharp-libvips-linux-arm@1.0.5': resolution: {integrity: sha512-gvcC4ACAOPRNATg/ov8/MnbxFDJqf/pDePbBnuBDcjsI8PssmjoKMAz4LtLaVi+OnSb5FK/yIOamqDwGmXW32g==} cpu: [arm] os: [linux] + libc: [glibc] '@img/sharp-libvips-linux-s390x@1.0.4': resolution: {integrity: sha512-u7Wz6ntiSSgGSGcjZ55im6uvTrOxSIS8/dgoVMoiGE9I6JAfU50yH5BoDlYA1tcuGS7g/QNtetJnxA6QEsCVTA==} cpu: [s390x] os: [linux] + libc: [glibc] '@img/sharp-libvips-linux-x64@1.0.4': resolution: {integrity: sha512-MmWmQ3iPFZr0Iev+BAgVMb3ZyC4KeFc3jFxnNbEPas60e1cIfevbtuyf9nDGIzOaW9PdnDciJm+wFFaTlj5xYw==} cpu: [x64] os: [linux] + libc: [glibc] '@img/sharp-libvips-linuxmusl-arm64@1.0.4': resolution: {integrity: sha512-9Ti+BbTYDcsbp4wfYib8Ctm1ilkugkA/uscUn6UXK1ldpC1JjiXbLfFZtRlBhjPZ5o1NCLiDbg8fhUPKStHoTA==} cpu: [arm64] os: [linux] + libc: [musl] '@img/sharp-libvips-linuxmusl-x64@1.0.4': resolution: {integrity: sha512-viYN1KX9m+/hGkJtvYYp+CCLgnJXwiQB39damAO7WMdKWlIhmYTfHjwSbQeUK/20vY154mwezd9HflVFM1wVSw==} cpu: [x64] os: [linux] + libc: [musl] '@img/sharp-linux-arm64@0.33.5': resolution: {integrity: sha512-JMVv+AMRyGOHtO1RFBiJy/MBsgz0x4AWrT6QoEVVTyh1E39TrCUpTRI7mx9VksGX4awWASxqCYLCV4wBZHAYxA==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [arm64] os: [linux] + libc: [glibc] '@img/sharp-linux-arm@0.33.5': resolution: {integrity: sha512-JTS1eldqZbJxjvKaAkxhZmBqPRGmxgu+qFKSInv8moZ2AmT5Yib3EQ1c6gp493HvrvV8QgdOXdyaIBrhvFhBMQ==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [arm] os: [linux] + libc: [glibc] '@img/sharp-linux-s390x@0.33.5': resolution: {integrity: sha512-y/5PCd+mP4CA/sPDKl2961b+C9d+vPAveS33s6Z3zfASk2j5upL6fXVPZi7ztePZ5CuH+1kW8JtvxgbuXHRa4Q==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [s390x] os: [linux] + libc: [glibc] '@img/sharp-linux-x64@0.33.5': resolution: {integrity: sha512-opC+Ok5pRNAzuvq1AG0ar+1owsu842/Ab+4qvU879ippJBHvyY5n2mxF1izXqkPYlGuP/M556uh53jRLJmzTWA==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [x64] os: [linux] + libc: [glibc] '@img/sharp-linuxmusl-arm64@0.33.5': resolution: {integrity: sha512-XrHMZwGQGvJg2V/oRSUfSAfjfPxO+4DkiRh6p2AFjLQztWUuY/o8Mq0eMQVIY7HJ1CDQUJlxGGZRw1a5bqmd1g==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [arm64] os: [linux] + libc: [musl] '@img/sharp-linuxmusl-x64@0.33.5': resolution: {integrity: sha512-WT+d/cgqKkkKySYmqoZ8y3pxx7lx9vVejxW/W4DOFMYVSkErR+w7mf2u8m/y4+xHe7yY9DAXQMWQhpnMuFfScw==} engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0} cpu: [x64] os: [linux] + libc: [musl] '@img/sharp-wasm32@0.33.5': resolution: {integrity: sha512-ykUW4LVGaMcU9lu9thv85CbRMAwfeadCJHRsg2GmeRa/cJxsVY9Rbd57JcMxBkKHag5U/x7TSBpScF4U8ElVzg==} @@ -2111,56 +2105,67 @@ packages: resolution: {integrity: sha512-EtP8aquZ0xQg0ETFcxUbU71MZlHaw9MChwrQzatiE8U/bvi5uv/oChExXC4mWhjiqK7azGJBqU0tt5H123SzVA==} cpu: [arm] os: [linux] + libc: [glibc] '@rollup/rollup-linux-arm-musleabihf@4.46.2': resolution: {integrity: sha512-qO7F7U3u1nfxYRPM8HqFtLd+raev2K137dsV08q/LRKRLEc7RsiDWihUnrINdsWQxPR9jqZ8DIIZ1zJJAm5PjQ==} cpu: [arm] os: [linux] + libc: [musl] '@rollup/rollup-linux-arm64-gnu@4.46.2': resolution: {integrity: sha512-3dRaqLfcOXYsfvw5xMrxAk9Lb1f395gkoBYzSFcc/scgRFptRXL9DOaDpMiehf9CO8ZDRJW2z45b6fpU5nwjng==} cpu: [arm64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-arm64-musl@4.46.2': resolution: {integrity: sha512-fhHFTutA7SM+IrR6lIfiHskxmpmPTJUXpWIsBXpeEwNgZzZZSg/q4i6FU4J8qOGyJ0TR+wXBwx/L7Ho9z0+uDg==} cpu: [arm64] os: [linux] + libc: [musl] '@rollup/rollup-linux-loongarch64-gnu@4.46.2': resolution: {integrity: sha512-i7wfGFXu8x4+FRqPymzjD+Hyav8l95UIZ773j7J7zRYc3Xsxy2wIn4x+llpunexXe6laaO72iEjeeGyUFmjKeA==} cpu: [loong64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-ppc64-gnu@4.46.2': resolution: {integrity: sha512-B/l0dFcHVUnqcGZWKcWBSV2PF01YUt0Rvlurci5P+neqY/yMKchGU8ullZvIv5e8Y1C6wOn+U03mrDylP5q9Yw==} cpu: [ppc64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-riscv64-gnu@4.46.2': resolution: {integrity: sha512-32k4ENb5ygtkMwPMucAb8MtV8olkPT03oiTxJbgkJa7lJ7dZMr0GCFJlyvy+K8iq7F/iuOr41ZdUHaOiqyR3iQ==} cpu: [riscv64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-riscv64-musl@4.46.2': resolution: {integrity: sha512-t5B2loThlFEauloaQkZg9gxV05BYeITLvLkWOkRXogP4qHXLkWSbSHKM9S6H1schf/0YGP/qNKtiISlxvfmmZw==} cpu: [riscv64] os: [linux] + libc: [musl] '@rollup/rollup-linux-s390x-gnu@4.46.2': resolution: {integrity: sha512-YKjekwTEKgbB7n17gmODSmJVUIvj8CX7q5442/CK80L8nqOUbMtf8b01QkG3jOqyr1rotrAnW6B/qiHwfcuWQA==} cpu: [s390x] os: [linux] + libc: [glibc] '@rollup/rollup-linux-x64-gnu@4.46.2': resolution: {integrity: sha512-Jj5a9RUoe5ra+MEyERkDKLwTXVu6s3aACP51nkfnK9wJTraCC8IMe3snOfALkrjTYd2G1ViE1hICj0fZ7ALBPA==} cpu: [x64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-x64-musl@4.46.2': resolution: {integrity: sha512-7kX69DIrBeD7yNp4A5b81izs8BqoZkCIaxQaOpumcJ1S/kmqNFjPhDu1LHeVXv0SexfHQv5cqHsxLOjETuqDuA==} cpu: [x64] os: [linux] + libc: [musl] '@rollup/rollup-win32-arm64-msvc@4.46.2': resolution: {integrity: sha512-wiJWMIpeaak/jsbaq2HMh/rzZxHVW1rU6coyeNNpMwk5isiPjSTx0a4YLSlYDwBH/WBvLz+EtsNqQScZTLJy3g==} @@ -2270,24 +2275,28 @@ packages: engines: {node: '>= 10'} cpu: [arm64] os: [linux] + libc: [glibc] '@tailwindcss/oxide-linux-arm64-musl@4.1.11': resolution: {integrity: sha512-m/NVRFNGlEHJrNVk3O6I9ggVuNjXHIPoD6bqay/pubtYC9QIdAMpS+cswZQPBLvVvEF6GtSNONbDkZrjWZXYNQ==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] + libc: [musl] '@tailwindcss/oxide-linux-x64-gnu@4.1.11': resolution: {integrity: sha512-YW6sblI7xukSD2TdbbaeQVDysIm/UPJtObHJHKxDEcW2exAtY47j52f8jZXkqE1krdnkhCMGqP3dbniu1Te2Fg==} engines: {node: '>= 10'} cpu: [x64] os: [linux] + libc: [glibc] '@tailwindcss/oxide-linux-x64-musl@4.1.11': resolution: {integrity: sha512-e3C/RRhGunWYNC3aSF7exsQkdXzQ/M+aYuZHKnw4U7KQwTJotnWsGOIVih0s2qQzmEzOFIJ3+xt7iq67K/p56Q==} engines: {node: '>= 10'} cpu: [x64] os: [linux] + libc: [musl] '@tailwindcss/oxide-wasm32-wasi@4.1.11': resolution: {integrity: sha512-Xo1+/GU0JEN/C/dvcammKHzeM6NqKovG+6921MR6oadee5XPBaKOumrJCXvopJ/Qb5TH7LX/UAywbqrP4lax0g==} @@ -3650,24 +3659,28 @@ packages: engines: {node: '>= 12.0.0'} cpu: [arm64] os: [linux] + libc: [glibc] lightningcss-linux-arm64-musl@1.30.1: resolution: {integrity: sha512-jmUQVx4331m6LIX+0wUhBbmMX7TCfjF5FoOH6SD1CttzuYlGNVpA7QnrmLxrsub43ClTINfGSYyHe2HWeLl5CQ==} engines: {node: '>= 12.0.0'} cpu: [arm64] os: [linux] + libc: [musl] lightningcss-linux-x64-gnu@1.30.1: resolution: {integrity: sha512-piWx3z4wN8J8z3+O5kO74+yr6ze/dKmPnI7vLqfSqI8bccaTGY5xiSGVIJBDd5K5BHlvVLpUB3S2YCfelyJ1bw==} engines: {node: '>= 12.0.0'} cpu: [x64] os: [linux] + libc: [glibc] lightningcss-linux-x64-musl@1.30.1: resolution: {integrity: sha512-rRomAK7eIkL+tHY0YPxbc5Dra2gXlI63HL+v1Pdi1a3sC+tJTcFrHX+E86sulgAXeI7rSzDYhPSeHHjqFhqfeQ==} engines: {node: '>= 12.0.0'} cpu: [x64] os: [linux] + libc: [musl] lightningcss-win32-arm64-msvc@1.30.1: resolution: {integrity: sha512-mSL4rqPi4iXq5YVqzSsJgMVFENoa4nGTT/GjO2c0Yl9OuQfPsIfncvLrEW6RbbB24WtZ3xP/2CCmI3tNkNV4oA==} diff --git a/tests/bun-websocket.test.ts b/tests/bun-websocket.test.ts index 268706d3..697f66cc 100644 --- a/tests/bun-websocket.test.ts +++ b/tests/bun-websocket.test.ts @@ -27,7 +27,7 @@ describe("dev", { await promise }) - test("endpoint can reject upgrade request", async () => { + test("endpoint can reject upgrade request", { skip: typeof WebSocket === "undefined" || process.version.startsWith("v24") }, async () => { const ws = new WebSocket(`ws://localhost:${server.address.port}/ws`, "unsupported-protocol") const { promise, resolve } = Promise.withResolvers() ws.onerror = e => { @@ -108,7 +108,7 @@ describe("build", { await promise }) - test("endpoint can reject upgrade request", async () => { + test("endpoint can reject upgrade request", { skip: typeof WebSocket === "undefined" || process.version.startsWith("v24") }, async () => { const ws = new WebSocket(`ws://localhost:4321/ws`, "unsupported-protocol") const { promise, resolve } = Promise.withResolvers() ws.onerror = e => { diff --git a/tests/cloudflare-websocket.test.ts b/tests/cloudflare-websocket.test.ts index c0e81ddd..97cff5e2 100644 --- a/tests/cloudflare-websocket.test.ts +++ b/tests/cloudflare-websocket.test.ts @@ -1,4 +1,3 @@ -import { platform } from "node:os" import { spawn, type ChildProcessWithoutNullStreams } from "node:child_process" import { describe, beforeAll, test, expect, afterAll } from "vitest" import { dev, type DevServer, build } from "./utils.ts" @@ -28,7 +27,7 @@ describe("dev", { await promise }) - test("endpoint can reject upgrade request", async () => { + test("endpoint can reject upgrade request", { skip: typeof WebSocket === "undefined" || process.version.startsWith("v24") }, async () => { const ws = new WebSocket(`ws://localhost:${server.address.port}/ws`, "unsupported-protocol") const { promise, resolve } = Promise.withResolvers() ws.onerror = e => { @@ -73,7 +72,7 @@ describe("dev", { describe("build", { timeout: 500, - skip: typeof WebSocket === "undefined" || platform() === "win32" + skip: typeof WebSocket === "undefined" || process.platform === "win32" }, () => { let wrangler: ChildProcessWithoutNullStreams @@ -127,7 +126,7 @@ describe("build", { await promise }) - test("endpoint can reject upgrade request", async () => { + test("endpoint can reject upgrade request", { skip: typeof WebSocket === "undefined" || process.platform === "win32" || process.version.startsWith("v24") }, async () => { const ws = new WebSocket(`ws://localhost:8788/ws`, "unsupported-protocol") const { promise, resolve } = Promise.withResolvers() ws.onerror = e => { @@ -150,8 +149,7 @@ describe("build", { await promise }) - if (false) - test("handles binary data with blob binaryType", { timeout: 1000 }, async () => { + test("handles binary data with blob binaryType", { timeout: 1000, skip: true }, async () => { const ws = new WebSocket("ws://localhost:8788/blob") const { promise, resolve, reject } = Promise.withResolvers() ws.onopen = () => ws.send(new TextEncoder().encode("Hello")) diff --git a/tests/deno-websocket.test.ts b/tests/deno-websocket.test.ts index edeb5ea3..50b454d3 100644 --- a/tests/deno-websocket.test.ts +++ b/tests/deno-websocket.test.ts @@ -27,7 +27,7 @@ describe("dev", { await promise }) - test("endpoint can reject upgrade request", async () => { + test("endpoint can reject upgrade request", { skip: typeof WebSocket === "undefined" || process.version.startsWith("v24") }, async () => { const ws = new WebSocket(`ws://localhost:${server.address.port}/ws`, "unsupported-protocol") const { promise, resolve } = Promise.withResolvers() ws.onerror = e => { @@ -114,7 +114,7 @@ describe("build", { await promise }) - test("endpoint can reject upgrade request", async () => { + test("endpoint can reject upgrade request", { skip: typeof WebSocket === "undefined" || process.version.startsWith("v24") }, async () => { const ws = new WebSocket(`ws://localhost:8085/ws`, "unsupported-protocol") const { promise, resolve } = Promise.withResolvers() ws.onerror = e => { diff --git a/tests/fixtures/prerender-patterns/astro.config.ts b/tests/fixtures/prerender-patterns/astro.config.ts deleted file mode 100644 index 9d56b2d8..00000000 --- a/tests/fixtures/prerender-patterns/astro.config.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { defineConfig } from "astro/config" -import prerenderPatterns, { prerender, renderOnDemand } from "astro-prerender-patterns" -import { testAdapter } from "../../utils.ts" - -// https://astro.build/config -export default defineConfig({ - output: "static", - adapter: testAdapter, - /* uncomment to test manually */ - // integrations: [ - // prerenderPatterns((path) => { - // console.log(path) - // if (path === "src/pages/page-default.astro") return renderOnDemand - // }) - // ] -}) diff --git a/tests/fixtures/prerender-patterns/package.json b/tests/fixtures/prerender-patterns/package.json deleted file mode 100644 index a92a97be..00000000 --- a/tests/fixtures/prerender-patterns/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "@test/prerender-patterns", - "private": true, - "dependencies": { - "astro": "5", - "astro-prerender-patterns": "workspace:*" - } -} \ No newline at end of file diff --git a/tests/fixtures/prerender-patterns/source/env.d.ts b/tests/fixtures/prerender-patterns/source/env.d.ts deleted file mode 100644 index 8c34fb45..00000000 --- a/tests/fixtures/prerender-patterns/source/env.d.ts +++ /dev/null @@ -1 +0,0 @@ -/// \ No newline at end of file diff --git a/tests/fixtures/prerender-patterns/src/not-pages/added-by-integration.astro b/tests/fixtures/prerender-patterns/src/not-pages/added-by-integration.astro deleted file mode 100644 index 39e48bb2..00000000 --- a/tests/fixtures/prerender-patterns/src/not-pages/added-by-integration.astro +++ /dev/null @@ -1,5 +0,0 @@ - - -

Hello world!

- - diff --git a/tests/fixtures/prerender-patterns/src/pages/404.astro b/tests/fixtures/prerender-patterns/src/pages/404.astro deleted file mode 100644 index a21f89e2..00000000 --- a/tests/fixtures/prerender-patterns/src/pages/404.astro +++ /dev/null @@ -1,5 +0,0 @@ - - -

Not Found

- - diff --git a/tests/fixtures/prerender-patterns/src/pages/500.astro b/tests/fixtures/prerender-patterns/src/pages/500.astro deleted file mode 100644 index 49ce34eb..00000000 --- a/tests/fixtures/prerender-patterns/src/pages/500.astro +++ /dev/null @@ -1,5 +0,0 @@ - - -

Something went wrong

- - diff --git a/tests/fixtures/prerender-patterns/src/pages/endpoint-default.ts b/tests/fixtures/prerender-patterns/src/pages/endpoint-default.ts deleted file mode 100644 index 21d54149..00000000 --- a/tests/fixtures/prerender-patterns/src/pages/endpoint-default.ts +++ /dev/null @@ -1,3 +0,0 @@ -import type { APIRoute } from "astro" - -export const GET: APIRoute = ctx => new Response(ctx.request.url) diff --git a/tests/fixtures/prerender-patterns/src/pages/endpoint-set-to-prerender.ts b/tests/fixtures/prerender-patterns/src/pages/endpoint-set-to-prerender.ts deleted file mode 100644 index 6da8d131..00000000 --- a/tests/fixtures/prerender-patterns/src/pages/endpoint-set-to-prerender.ts +++ /dev/null @@ -1,5 +0,0 @@ -import type { APIRoute } from "astro" - -export const prerender = true - -export const GET: APIRoute = ctx => new Response(ctx.request.url) diff --git a/tests/fixtures/prerender-patterns/src/pages/endpoint-set-to-render-on-demand.ts b/tests/fixtures/prerender-patterns/src/pages/endpoint-set-to-render-on-demand.ts deleted file mode 100644 index a207bd51..00000000 --- a/tests/fixtures/prerender-patterns/src/pages/endpoint-set-to-render-on-demand.ts +++ /dev/null @@ -1,5 +0,0 @@ -import type { APIRoute } from "astro" - -export const prerender = false - -export const GET: APIRoute = ctx => new Response(ctx.request.url) diff --git a/tests/fixtures/prerender-patterns/src/pages/page-default.astro b/tests/fixtures/prerender-patterns/src/pages/page-default.astro deleted file mode 100644 index 39e48bb2..00000000 --- a/tests/fixtures/prerender-patterns/src/pages/page-default.astro +++ /dev/null @@ -1,5 +0,0 @@ - - -

Hello world!

- - diff --git a/tests/fixtures/prerender-patterns/src/pages/page-set-to-prerender.astro b/tests/fixtures/prerender-patterns/src/pages/page-set-to-prerender.astro deleted file mode 100644 index c3d90879..00000000 --- a/tests/fixtures/prerender-patterns/src/pages/page-set-to-prerender.astro +++ /dev/null @@ -1,8 +0,0 @@ ---- -export const prerender = true ---- - - -

Hello world!

- - diff --git a/tests/fixtures/prerender-patterns/src/pages/page-set-to-render-on-demand.astro b/tests/fixtures/prerender-patterns/src/pages/page-set-to-render-on-demand.astro deleted file mode 100644 index 59a76954..00000000 --- a/tests/fixtures/prerender-patterns/src/pages/page-set-to-render-on-demand.astro +++ /dev/null @@ -1,8 +0,0 @@ ---- -export const prerender = false ---- - - -

Hello world!

- - diff --git a/tests/fixtures/prerender-patterns/src/pages/page-with-script.astro b/tests/fixtures/prerender-patterns/src/pages/page-with-script.astro deleted file mode 100644 index 3e7aaf60..00000000 --- a/tests/fixtures/prerender-patterns/src/pages/page-with-script.astro +++ /dev/null @@ -1,4 +0,0 @@ -This page is necessary to make sure "astro:build:setup" hooks runs for the client build. Without a client script, there is no client setup. - diff --git a/tests/node-websocket.test.ts b/tests/node-websocket.test.ts index 40fef4d7..018fa58e 100644 --- a/tests/node-websocket.test.ts +++ b/tests/node-websocket.test.ts @@ -27,7 +27,7 @@ describe("dev", { await promise }) - test("endpoint can reject upgrade request", async () => { + test("endpoint can reject upgrade request", { skip: typeof WebSocket === "undefined" || process.version.startsWith("v24") }, async () => { const ws = new WebSocket(`ws://localhost:${server.address.port}/ws`, "unsupported-protocol") const { promise, resolve } = Promise.withResolvers() ws.onerror = e => { @@ -108,7 +108,7 @@ describe("build", { await promise }) - test("endpoint can reject upgrade request", async () => { + test("endpoint can reject upgrade request", { skip: typeof WebSocket === "undefined" || process.version.startsWith("v24") }, async () => { const ws = new WebSocket(`ws://localhost:${server.server.port}/ws`, "unsupported-protocol") const { promise, resolve } = Promise.withResolvers() ws.onerror = e => { diff --git a/tests/prerender-patterns.test.ts b/tests/prerender-patterns.test.ts deleted file mode 100644 index 772480db..00000000 --- a/tests/prerender-patterns.test.ts +++ /dev/null @@ -1,269 +0,0 @@ -import { describe, beforeAll, test, expect } from "vitest" -import { build, type BuildFixture, testAdapter } from "./utils.ts" -import prerenderPatterns from "../packages/prerender-patterns/integration.ts" -import type { SSRManifest } from "astro" - -describe("with server output", () => { - let manifest: SSRManifest - let fixture: BuildFixture - const currentDecisions: Record = {} - - beforeAll(async () => { - fixture = await build("./fixtures/prerender-patterns", { - output: "server", - adapter: testAdapter, - integrations: [ prerenderPatterns((path, currentDecision) => { - currentDecisions[path] = currentDecision - if (path === "src/pages/page-default.astro") return "prerender" - if (path === "src/pages/endpoint-default.ts") return "prerender" - if (path === "src/pages/page-set-to-prerender.astro") return "render on demand" - if (path === "src/pages/endpoint-set-to-prerender.ts") return "render on demand" - if (path === "src/pages/page-set-to-render-on-demand.astro") return "prerender" - if (path === "src/pages/endpoint-set-to-render-on-demand.ts") return "prerender" - if (path === "src/not-pages/added-by-integration.astro") return "prerender" - }), { - name: "test-inject-route", - hooks: { - "astro:config:setup" ({ injectRoute }) { - injectRoute({ - entrypoint: "./src/not-pages/added-by-integration.astro", - pattern: "/added-by-integration" - }) - } - } - } ] - }) - const exports = await import(fixture.serverEntry) - manifest = exports.manifest - }) - - test("provides the current decision to the callback", () => { - expect(currentDecisions).to.deep.include({ - "src/pages/404.astro" : "render on demand", - "src/pages/500.astro" : "render on demand", - "src/pages/endpoint-default.ts" : "render on demand", - "src/pages/endpoint-set-to-prerender.ts" : "prerender", - "src/pages/endpoint-set-to-render-on-demand.ts": "render on demand", - "src/pages/page-default.astro" : "render on demand", - "src/pages/page-set-to-prerender.astro" : "prerender", - "src/pages/page-set-to-render-on-demand.astro" : "render on demand", - "src/not-pages/added-by-integration.astro" : "render on demand", - }) - }) - - test("page: unspecified -> prerendered", async () => { - // static file is created - expect( - fixture.fileExists("client/page-default/index.html") - ).to.equal(true) - - // check that ssr chunk exports an empty module - const compiledPage = await manifest.pageMap!.get("src/pages/page-default.astro")!() - expect(Object.keys(compiledPage)).toStrictEqual([]) - }) - - test("page: prerender -> rendered on demand", async () => { - // static file is not created - expect( - fixture.fileExists("client/page-set-to-prerender/index.html") - ).to.equal(false) - - // ssr chunk is functional - const { page } = await manifest.pageMap!.get("src/pages/page-set-to-prerender.astro")!() - const { default: factory } = await page() - expect(factory).to.deep.include({ isAstroComponentFactory: true }) - }) - - test("page: render on demand -> prerendered", async () => { - // static file is created - expect( - fixture.fileExists("client/page-set-to-render-on-demand/index.html") - ).to.equal(true) - - // check that ssr chunk exports an empty module - const compiledPage = await manifest.pageMap!.get("src/pages/page-set-to-render-on-demand.astro")!() - expect(Object.keys(compiledPage)).toStrictEqual([]) - }) - - test("endpoint: unspecified -> prerendered", async () => { - // static file is created - expect( - fixture.fileExists("client/endpoint-default") - ).to.equal(true) - - // check that ssr chunk exports an empty module - const compiledPage = await manifest.pageMap!.get("src/pages/endpoint-default.ts")!() - expect(Object.keys(compiledPage)).toStrictEqual([]) - }) - - test("endpoint: prerendered -> rendered on demand", async () => { - // static file is not created - expect( - fixture.fileExists("client/endpoint-set-to-prerender") - ).to.equal(false) - - // ssr chunk is functional - const { page } = await manifest.pageMap!.get("src/pages/endpoint-set-to-prerender.ts")!() - // @ts-ignore - const { GET } = await page() - const response = GET({ request: { url: "" } }) - expect(response).to.be.an.instanceof(Response) - }) - - test("endpoint: render on demand -> prerendered", async () => { - // static file is created - expect( - fixture.fileExists("client/endpoint-set-to-render-on-demand") - ).to.equal(true) - - // check that ssr chunk exports an empty module - const compiledPage = await manifest.pageMap!.get("src/pages/endpoint-set-to-render-on-demand.ts")!() - expect(Object.keys(compiledPage)).toStrictEqual([]) - }) - - test("injected page: render on demand -> prerendered", async () => { - // static file is created - expect( - fixture.fileExists("client/added-by-integration/index.html") - ).to.equal(true) - - // check that ssr chunk exports an empty module - const compiledPage = await manifest.pageMap!.get("src/not-pages/added-by-integration.astro")!() - expect(Object.keys(compiledPage)).toStrictEqual([]) - }) -}) - -describe("static output", () => { - let manifest: SSRManifest - let fixture: BuildFixture - const currentDecisions: Record = {} - - beforeAll(async () => { - fixture = await build("./fixtures/prerender-patterns", { - output: "static", - adapter: testAdapter, - integrations: [ prerenderPatterns((path, currentDecision) => { - currentDecisions[path] = currentDecision - if (path === "src/pages/page-default.astro") return "render on demand" - if (path === "src/pages/endpoint-default.ts") return "render on demand" - if (path === "src/pages/page-set-to-prerender.astro") return "render on demand" - if (path === "src/pages/endpoint-set-to-prerender.ts") return "render on demand" - if (path === "src/pages/page-set-to-render-on-demand.astro") return "prerender" - if (path === "src/pages/endpoint-set-to-render-on-demand.ts") return "prerender" - if (path === "src/not-pages/added-by-integration.astro") return "render on demand" - }), { - name: "test-inject-route", - hooks: { - "astro:config:setup" ({ injectRoute }) { - injectRoute({ - entrypoint: "./src/not-pages/added-by-integration.astro", - pattern: "/added-by-integration" - }) - } - } - } ] - }) - const exports = await import(fixture.serverEntry) - manifest = exports.manifest - }) - - test("provides the current decision to the callback", () => { - expect(currentDecisions).to.deep.include({ - "src/pages/404.astro" : "prerender", - "src/pages/500.astro" : "prerender", - "src/pages/endpoint-default.ts" : "prerender", - "src/pages/endpoint-set-to-prerender.ts" : "prerender", - "src/pages/endpoint-set-to-render-on-demand.ts": "render on demand", - "src/pages/page-default.astro" : "prerender", - "src/pages/page-set-to-prerender.astro" : "prerender", - "src/pages/page-set-to-render-on-demand.astro" : "render on demand", - "src/not-pages/added-by-integration.astro" : "prerender", - }) - }) - - test("page: unspecified -> rendered on demand", async () => { - // static file is created - expect( - fixture.fileExists("client/page-default/index.html") - ).to.equal(false) - - // ssr chunk is functional - const { page } = await manifest.pageMap!.get("src/pages/page-default.astro")!() - const { default: factory } = await page() - expect(factory).to.deep.include({ isAstroComponentFactory: true }) - }) - - test("page: prerender -> rendered on demand", async () => { - // static file is not created - expect( - fixture.fileExists("client/page-set-to-prerender/index.html") - ).to.equal(false) - - // ssr chunk is functional - const { page } = await manifest.pageMap!.get("src/pages/page-set-to-prerender.astro")!() - const { default: factory } = await page() - expect(factory).to.deep.include({ isAstroComponentFactory: true }) - }) - - test("page: render on demand -> prerendered", async () => { - // static file is created - expect( - fixture.fileExists("client/page-set-to-render-on-demand/index.html") - ).to.equal(true) - - // check that ssr chunk exports an empty module - const compiledPage = await manifest.pageMap!.get("src/pages/page-set-to-render-on-demand.astro")!() - expect(Object.keys(compiledPage)).toStrictEqual([]) - }) - - test("endpoint: unspecified -> rendered on demand", async () => { - // static file is created - expect( - fixture.fileExists("client/endpoint-default") - ).to.equal(false) - - // ssr chunk is functional - const { page } = await manifest.pageMap!.get("src/pages/endpoint-default.ts")!() - // @ts-ignore - const { GET } = await page() - const response = GET({ request: { url: "" } }) - expect(response).to.be.an.instanceof(Response) - }) - - test("endpoint: prerender -> rendered on demand", async () => { - // static file is not created - expect( - fixture.fileExists("client/endpoint-set-to-prerender") - ).to.equal(false) - - // ssr chunk is functional - const { page } = await manifest.pageMap!.get("src/pages/endpoint-set-to-prerender.ts")!() - // @ts-ignore - const { GET } = await page() - const response = GET({ request: { url: "" } }) - expect(response).to.be.an.instanceof(Response) - }) - - test("endpoint: render on demand -> prerendered", async () => { - // static file is created - expect( - fixture.fileExists("client/endpoint-set-to-render-on-demand") - ).to.equal(true) - - // check that ssr chunk exports an empty module - const compiledPage = await manifest.pageMap!.get("src/pages/endpoint-set-to-render-on-demand.ts")!() - expect(Object.keys(compiledPage)).toStrictEqual([]) - }) - - test("injected page: prerendered -> render on demand", async () => { - // static file is not created - expect( - fixture.fileExists("client/added-by-integration/index.html") - ).to.equal(false) - - // ssr chunk is functional - const { page } = await manifest.pageMap!.get("src/not-pages/added-by-integration.astro")!() - const { default: factory } = await page() - expect(factory).to.deep.include({ isAstroComponentFactory: true }) - }) -}) diff --git a/tsconfig.json b/tsconfig.json index 95ff37a3..499af173 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,6 +8,7 @@ "tests/fixtures/emotion-extract" ], "compilerOptions": { - "jsx": "preserve" - } + "jsx": "preserve", + "types": [ "astro/client" ] + }, } \ No newline at end of file