From d83991ae8b51a304405330b4af8e9cc502f9bc57 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Fri, 1 Dec 2023 23:50:15 +0800 Subject: [PATCH] Remove @astrojs/prefetch integration (#9241) --- .changeset/pre.json | 1 - README.md | 1 - .../prefetch/@types/network-information.d.ts | 15 - packages/integrations/prefetch/CHANGELOG.md | 140 ---------- packages/integrations/prefetch/README.md | 148 ---------- packages/integrations/prefetch/package.json | 47 ---- .../prefetch/playwright.config.js | 44 --- packages/integrations/prefetch/src/client.ts | 155 ----------- packages/integrations/prefetch/src/index.ts | 19 -- .../prefetch/src/requestIdleCallback.ts | 16 -- .../prefetch/test/basic-prefetch.test.js | 130 --------- .../prefetch/test/custom-selectors.test.js | 260 ------------------ .../fixtures/basic-prefetch/astro.config.mjs | 7 - .../test/fixtures/basic-prefetch/package.json | 9 - .../basic-prefetch/src/pages/about.astro | 11 - .../basic-prefetch/src/pages/admin.astro | 11 - .../basic-prefetch/src/pages/conditions.astro | 11 - .../basic-prefetch/src/pages/contact.astro | 11 - .../basic-prefetch/src/pages/index.astro | 34 --- .../basic-prefetch/src/pages/terms.astro | 11 - .../basic-prefetch/src/pages/uses.astro | 11 - .../fixtures/style-prefetch/astro.config.mjs | 7 - .../test/fixtures/style-prefetch/package.json | 9 - .../style-prefetch/src/pages/index.astro | 18 -- .../style-prefetch/src/pages/style1.astro | 15 - .../style-prefetch/src/pages/style2.astro | 15 - .../prefetch/test/style-prefetch.test.js | 55 ---- .../integrations/prefetch/test/test-utils.js | 30 -- packages/integrations/prefetch/tsconfig.json | 7 - pnpm-lock.yaml | 39 --- 30 files changed, 1287 deletions(-) delete mode 100644 packages/integrations/prefetch/@types/network-information.d.ts delete mode 100644 packages/integrations/prefetch/CHANGELOG.md delete mode 100644 packages/integrations/prefetch/README.md delete mode 100644 packages/integrations/prefetch/package.json delete mode 100644 packages/integrations/prefetch/playwright.config.js delete mode 100644 packages/integrations/prefetch/src/client.ts delete mode 100644 packages/integrations/prefetch/src/index.ts delete mode 100644 packages/integrations/prefetch/src/requestIdleCallback.ts delete mode 100644 packages/integrations/prefetch/test/basic-prefetch.test.js delete mode 100644 packages/integrations/prefetch/test/custom-selectors.test.js delete mode 100644 packages/integrations/prefetch/test/fixtures/basic-prefetch/astro.config.mjs delete mode 100644 packages/integrations/prefetch/test/fixtures/basic-prefetch/package.json delete mode 100644 packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/about.astro delete mode 100644 packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/admin.astro delete mode 100644 packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/conditions.astro delete mode 100644 packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/contact.astro delete mode 100644 packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/index.astro delete mode 100644 packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/terms.astro delete mode 100644 packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/uses.astro delete mode 100644 packages/integrations/prefetch/test/fixtures/style-prefetch/astro.config.mjs delete mode 100644 packages/integrations/prefetch/test/fixtures/style-prefetch/package.json delete mode 100644 packages/integrations/prefetch/test/fixtures/style-prefetch/src/pages/index.astro delete mode 100644 packages/integrations/prefetch/test/fixtures/style-prefetch/src/pages/style1.astro delete mode 100644 packages/integrations/prefetch/test/fixtures/style-prefetch/src/pages/style2.astro delete mode 100644 packages/integrations/prefetch/test/style-prefetch.test.js delete mode 100644 packages/integrations/prefetch/test/test-utils.js delete mode 100644 packages/integrations/prefetch/tsconfig.json diff --git a/.changeset/pre.json b/.changeset/pre.json index da91f9c8cf..7005bc884b 100644 --- a/.changeset/pre.json +++ b/.changeset/pre.json @@ -15,7 +15,6 @@ "@astrojs/node": "6.0.4", "@astrojs/partytown": "2.0.2", "@astrojs/preact": "3.0.1", - "@astrojs/prefetch": "0.4.1", "@astrojs/react": "3.0.5", "@astrojs/sitemap": "3.0.3", "@astrojs/solid-js": "3.0.2", diff --git a/README.md b/README.md index b608a3026a..7b4c9b00f7 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,6 @@ Join us on [Discord](https://astro.build/chat) to meet other maintainers. We'll | [@astrojs/tailwind](packages/integrations/tailwind) | [![astro version](https://img.shields.io/npm/v/@astrojs/tailwind.svg?label=%20)](packages/integrations/tailwind/CHANGELOG.md) | | [@astrojs/alpinejs](packages/integrations/alpinejs) | [![astro version](https://img.shields.io/npm/v/@astrojs/alpinejs.svg?label=%20)](packages/integrations/alpinejs/CHANGELOG.md) | | [@astrojs/mdx](packages/integrations/mdx) | [![astro version](https://img.shields.io/npm/v/@astrojs/mdx.svg?label=%20)](packages/integrations/mdx/CHANGELOG.md) | -| [@astrojs/prefetch](packages/integrations/prefetch) | [![astro version](https://img.shields.io/npm/v/@astrojs/prefetch.svg?label=%20)](packages/integrations/prefetch/CHANGELOG.md) | [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/6178/badge)](https://bestpractices.coreinfrastructure.org/projects/6178) diff --git a/packages/integrations/prefetch/@types/network-information.d.ts b/packages/integrations/prefetch/@types/network-information.d.ts deleted file mode 100644 index bf1d787f3f..0000000000 --- a/packages/integrations/prefetch/@types/network-information.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -export {}; - -declare global { - interface NetworkInformation { - // http://wicg.github.io/netinfo/#effectiveconnectiontype-enum - readonly effectiveType: '2g' | '3g' | '4g' | 'slow-2g'; - // http://wicg.github.io/netinfo/#savedata-attribute - readonly saveData?: boolean; - } - - var NetworkInformation: { - prototype: NetworkInformation; - new (): NetworkInformation; - }; -} diff --git a/packages/integrations/prefetch/CHANGELOG.md b/packages/integrations/prefetch/CHANGELOG.md deleted file mode 100644 index de7ba588e7..0000000000 --- a/packages/integrations/prefetch/CHANGELOG.md +++ /dev/null @@ -1,140 +0,0 @@ -# @astrojs/prefetch - -## 0.4.1 - -### Patch Changes - -- [#8737](https://github.com/withastro/astro/pull/8737) [`6f60da805`](https://github.com/withastro/astro/commit/6f60da805e0014bc50dd07bef972e91c73560c3c) Thanks [@ematipico](https://github.com/ematipico)! - Add provenance statement when publishing the library from CI - -## 0.4.0 - -### Minor Changes - -- [#8188](https://github.com/withastro/astro/pull/8188) [`d0679a666`](https://github.com/withastro/astro/commit/d0679a666f37da0fca396d42b9b32bbb25d29312) Thanks [@ematipico](https://github.com/ematipico)! - Remove support for Node 16. The lowest supported version by Astro and all integrations is now v18.14.1. As a reminder, Node 16 will be deprecated on the 11th September 2023. - -- [#8179](https://github.com/withastro/astro/pull/8179) [`6011d52d3`](https://github.com/withastro/astro/commit/6011d52d38e43c3e3d52bc3bc41a60e36061b7b7) Thanks [@matthewp](https://github.com/matthewp)! - Astro 3.0 Release Candidate - -## 0.4.0-rc.1 - -### Minor Changes - -- [#8179](https://github.com/withastro/astro/pull/8179) [`6011d52d3`](https://github.com/withastro/astro/commit/6011d52d38e43c3e3d52bc3bc41a60e36061b7b7) Thanks [@matthewp](https://github.com/matthewp)! - Astro 3.0 Release Candidate - -## 0.4.0-beta.0 - -### Minor Changes - -- [`1eae2e3f7`](https://github.com/withastro/astro/commit/1eae2e3f7d693c9dfe91c8ccfbe606d32bf2fb81) Thanks [@Princesseuh](https://github.com/Princesseuh)! - Remove support for Node 16. The lowest supported version by Astro and all integrations is now v18.14.1. As a reminder, Node 16 will be deprecated on the 11th September 2023. - -## 0.3.0 - -### Minor Changes - -- [#6585](https://github.com/withastro/astro/pull/6585) [`9807e4dc2`](https://github.com/withastro/astro/commit/9807e4dc22355f0b3b2ff65b0724a95af8e9702d) Thanks [@kory-smith](https://github.com/kory-smith)! - Adds the option to prefetch a link only when it is hovered or focused. - -### Patch Changes - -- [#7613](https://github.com/withastro/astro/pull/7613) [`131c92279`](https://github.com/withastro/astro/commit/131c92279ee8a282e71a09523870bb0e7df80627) Thanks [@Yan-Thomas](https://github.com/Yan-Thomas)! - Update prefetch README filename syntax - -## 0.2.3 - -### Patch Changes - -- [#7123](https://github.com/withastro/astro/pull/7123) [`147373722`](https://github.com/withastro/astro/commit/147373722b37126af949bb054a1cdfb0aed6c2ff) Thanks [@connor-baer](https://github.com/connor-baer)! - Fix the inclusion of `@types/network-information`. - -## 0.2.2 - -### Patch Changes - -- [#7104](https://github.com/withastro/astro/pull/7104) [`826e02890`](https://github.com/withastro/astro/commit/826e0289005f645b902375b98d5549c6a95ccafa) Thanks [@bluwy](https://github.com/bluwy)! - Specify `"files"` field to only publish necessary files - -## 0.2.1 - -### Patch Changes - -- [#6494](https://github.com/withastro/astro/pull/6494) [`a13e9d7e3`](https://github.com/withastro/astro/commit/a13e9d7e33baccf51e7d4815f99b481ad174bc57) Thanks [@Yan-Thomas](https://github.com/Yan-Thomas)! - Consistency improvements to several package descriptions - -## 0.2.0 - -### Minor Changes - -- [#6213](https://github.com/withastro/astro/pull/6213) [`afbbc4d5b`](https://github.com/withastro/astro/commit/afbbc4d5bfafc1779bac00b41c2a1cb1c90f2808) Thanks [@Princesseuh](https://github.com/Princesseuh)! - Updated compilation settings to disable downlevelling for Node 14 - -## 0.1.2 - -### Patch Changes - -- [#5478](https://github.com/withastro/astro/pull/5478) [`1c7eef308`](https://github.com/withastro/astro/commit/1c7eef308e808aa5ed4662b53e67ec8d1b814d1f) Thanks [@nemo0](https://github.com/nemo0)! - Update READMEs for consistency - -## 0.1.1 - -### Patch Changes - -- [#5244](https://github.com/withastro/astro/pull/5244) [`6ad91bd80`](https://github.com/withastro/astro/commit/6ad91bd80dae935b67a5c18b8dfbb95f2cfe10ef) Thanks [@deeprobin](https://github.com/deeprobin)! - Do not prefetch if browser is offline or uses 3G - -- [#5271](https://github.com/withastro/astro/pull/5271) [`b6afe2c1d`](https://github.com/withastro/astro/commit/b6afe2c1db613aabf3139fb58e0fc2ab60322f37) Thanks [@tony-sull](https://github.com/tony-sull)! - Adds additional package.json keywords used for discoverability in the Integrations catalog - -## 0.1.0 - -### Minor Changes - -- [#5125](https://github.com/withastro/astro/pull/5125) [`5a674f976`](https://github.com/withastro/astro/commit/5a674f976d6138ec5c87441a579c2ccf37713e73) Thanks [@Jelenkee](https://github.com/Jelenkee)! - Prefetch CSS files once - -## 0.0.8 - -### Patch Changes - -- [#5009](https://github.com/withastro/astro/pull/5009) [`92b27e9c9`](https://github.com/withastro/astro/commit/92b27e9c9253cea3d00f1f81223de19ff75c2c74) Thanks [@panwauu](https://github.com/panwauu)! - Prevents prefetching the current page - -## 0.0.7 - -### Patch Changes - -- [#4207](https://github.com/withastro/astro/pull/4207) [`ceb0eef94`](https://github.com/withastro/astro/commit/ceb0eef944f2f867cb2dba04adfb6b028cf8c228) Thanks [@jablonski](https://github.com/jablonski)! - Use `passive` event listeners for performance - -## 0.0.6 - -### Patch Changes - -- [#4004](https://github.com/withastro/astro/pull/4004) [`ef9c4152b`](https://github.com/withastro/astro/commit/ef9c4152b2b399e25bf4e8aa7b37adcf6d0d8f17) Thanks [@sarah11918](https://github.com/sarah11918)! - [READMEs] removed "experimental" from astro add instructions - -## 0.0.5 - -### Patch Changes - -- [#3885](https://github.com/withastro/astro/pull/3885) [`bf5d1cc1e`](https://github.com/withastro/astro/commit/bf5d1cc1e71da38a14658c615e9481f2145cc6e7) Thanks [@delucis](https://github.com/delucis)! - Integration README fixes - -## 0.0.4 - -### Patch Changes - -- [#3865](https://github.com/withastro/astro/pull/3865) [`1f9e4857`](https://github.com/withastro/astro/commit/1f9e4857ff2b2cb7db89d619618cdf546cd3b3dc) Thanks [@delucis](https://github.com/delucis)! - Small README fixes - -* [#3854](https://github.com/withastro/astro/pull/3854) [`b012ee55`](https://github.com/withastro/astro/commit/b012ee55b107dea0730286263b27d83e530fad5d) Thanks [@bholmesdev](https://github.com/bholmesdev)! - [astro add] Support adapters and third party packages - -## 0.0.3 - -### Patch Changes - -- [#3778](https://github.com/withastro/astro/pull/3778) [`91635f05`](https://github.com/withastro/astro/commit/91635f05df207d33ee8b50a2afe970b94b24ba7b) Thanks [@hippotastic](https://github.com/hippotastic)! - Fix integration name (`prefetch` instead of `lit`) - -## 0.0.2 - -### Patch Changes - -- [#3736](https://github.com/withastro/astro/pull/3736) [`bd4dac0e`](https://github.com/withastro/astro/commit/bd4dac0e1a8598045f10c42faf08abff96ed6766) Thanks [@tony-sull](https://github.com/tony-sull)! - Adds a new `@astrojs/prefetch` integration with the goal of adding near-instant page navigation for Astro projects. HTML and CSS for visible links marked with `rel="prefetch"` will be preloaded in the browser when the browser is idle. - - **astro.config.mjs** - - ```js - import prefetch from '@astrojs/prefetch'; - export default { - // ... - integrations: [prefetch()], - }; - ``` - - ```html - - All Products - ``` diff --git a/packages/integrations/prefetch/README.md b/packages/integrations/prefetch/README.md deleted file mode 100644 index a357618e4f..0000000000 --- a/packages/integrations/prefetch/README.md +++ /dev/null @@ -1,148 +0,0 @@ -# @astrojs/prefetch 🔗 - -> NOTE: `@astrojs/prefetch` is deprecated. Use the `prefetch` feature in Astro 3.5 instead. Check out the [migration guide](https://docs.astro.build/en/guides/prefetch/#migrating-from-astrojsprefetch). - -- [Why Prefetch?](#why-prefetch) -- [Installation](#installation) -- [Usage](#usage) -- [Configuration](#configuration) -- [Troubleshooting](#troubleshooting) -- [Contributing](#contributing) -- [Changelog](#changelog) - -## Why Prefetch? - -Page load times play a big role in usability and overall enjoyment of a site. This integration brings the benefits of near-instant page navigations to your multi-page application (MPA) by prefetching page links when they are visible on screen. - -To further improve the experience, especially on similar pages, stylesheets are also prefetched along with the HTML. This is particularly useful when navigating between tabs on a static site, where most of the page's content and styles don't change. - -## Installation - -### Quick Install - -The `astro add` command-line tool automates the installation for you. Run one of the following commands in a new terminal window. (If you aren't sure which package manager you're using, run the first command.) Then, follow the prompts, and type "y" in the terminal (meaning "yes") for each one. - -```sh -# Using NPM -npx astro add prefetch -# Using Yarn -yarn astro add prefetch -# Using PNPM -pnpm astro add prefetch -``` - -If you run into any issues, [feel free to report them to us on GitHub](https://github.com/withastro/astro/issues) and try the manual installation steps below. - -### Manual Install - -First, install the `@astrojs/prefetch` package using your package manager. If you're using npm or aren't sure, run this in the terminal: - -```sh -npm install @astrojs/prefetch -``` - -Then, apply this integration to your `astro.config.*` file using the `integrations` property: - -```diff lang="js" "prefetch()" - // astro.config.mjs - import { defineConfig } from 'astro/config'; -+ import prefetch from '@astrojs/prefetch'; - - export default defineConfig({ - // ... - integrations: [prefetch()], - // ^^^^^^^^^^ - }); -``` - -## Usage - -When you install the integration, the prefetch script is automatically added to every page in the project. Just add `rel="prefetch"` to any `` links on your page and you're ready to go! - -In addition, you can add `rel="prefetch-intent"` to any `` links on your page to prefetch them only when they are hovered over, touched, or focused. This is especially useful to conserve data usage when viewing your site. - -## Configuration - -The Astro Prefetch integration handles which links on the site are prefetched and it has its own options. Change these in the `astro.config.mjs` file which is where your project's integration settings live. - -### config.selector - -By default the prefetch script searches the page for any links that include a `rel="prefetch"` attribute, ex: `` or ``. This behavior can be changed in your `astro.config.*` file to use a custom query selector when finding prefetch links. - -```js -// astro.config.mjs -import { defineConfig } from 'astro/config'; -import prefetch from '@astrojs/prefetch'; - -export default defineConfig({ - // ... - integrations: [ - prefetch({ - // Only prefetch links with an href that begins with `/products` - selector: "a[href^='/products']", - }), - ], -}); -``` - -### config.intentSelector - -By default, the prefetch script also searches the page for any links that include a `rel="prefetch-intent"` attribute, ex: ``. This behavior can be changed in your `astro.config.*` file to use a custom query selector when finding prefetch-intent links. - -```js -// astro.config.mjs -import { defineConfig } from 'astro/config'; -import prefetch from '@astrojs/prefetch'; - -export default defineConfig({ - // ... - integrations: [ - prefetch({ - // Only prefetch links with an href that begins with `/products` or `/coupons` - intentSelector: ["a[href^='/products']", "a[href^='/coupons']"], - - // Use a string to prefetch a single selector - // intentSelector: "a[href^='/products']" - }), - ], -}); -``` - -### config.throttle - -By default the prefetch script will only prefetch one link at a time. This behavior can be changed in your `astro.config.*` file to increase the limit for concurrent downloads. - -```js -// astro.config.mjs -import { defineConfig } from 'astro/config'; -import prefetch from '@astrojs/prefetch'; - -export default defineConfig({ - // ... - integrations: [ - prefetch({ - // Allow up to three links to be prefetched concurrently - throttle: 3, - }), - ], -}); -``` - -## Troubleshooting - -- If your installation doesn't seem to be working, try restarting the dev server. -- If a link doesn't seem to be prefetching, make sure that the link is pointing to a page on the same domain and matches the integration's `selector` option. - -For help, check out the `#support` channel on [Discord](https://astro.build/chat). Our friendly Support Squad members are here to help! - -You can also check our [Astro Integration Documentation][astro-integration] for more on integrations. - -## Contributing - -This package is maintained by Astro's Core team. You're welcome to submit an issue or PR! - -## Changelog - -See [CHANGELOG.md](CHANGELOG.md) for a history of changes to this integration. - -[astro-integration]: https://docs.astro.build/en/guides/integrations-guide/ diff --git a/packages/integrations/prefetch/package.json b/packages/integrations/prefetch/package.json deleted file mode 100644 index 3291eb1a7c..0000000000 --- a/packages/integrations/prefetch/package.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "name": "@astrojs/prefetch", - "description": "Prefetch page navigations in your Astro site", - "version": "0.4.1", - "type": "module", - "types": "./dist/index.d.ts", - "author": "withastro", - "license": "MIT", - "repository": { - "type": "git", - "url": "https://github.com/withastro/astro.git", - "directory": "packages/astro-prefetch" - }, - "keywords": [ - "astro-integration", - "performance", - "withastro" - ], - "bugs": "https://github.com/withastro/astro/issues", - "homepage": "https://docs.astro.build/en/guides/integrations-guide/prefetch/", - "exports": { - ".": "./dist/index.js", - "./client.js": "./dist/client.js", - "./package.json": "./package.json" - }, - "files": [ - "dist" - ], - "scripts": { - "build": "astro-scripts build \"src/**/*.ts\" && tsc", - "build:ci": "astro-scripts build \"src/**/*.ts\"", - "dev": "astro-scripts dev \"src/**/*.ts\"", - "test": "playwright test", - "test:match": "playwright test -g" - }, - "devDependencies": { - "@playwright/test": "^1.40.0", - "astro": "workspace:*", - "astro-scripts": "workspace:*" - }, - "dependencies": { - "throttles": "^1.0.1" - }, - "publishConfig": { - "provenance": true - } -} diff --git a/packages/integrations/prefetch/playwright.config.js b/packages/integrations/prefetch/playwright.config.js deleted file mode 100644 index 7fb92ae0c0..0000000000 --- a/packages/integrations/prefetch/playwright.config.js +++ /dev/null @@ -1,44 +0,0 @@ -// NOTE: Prefetch tests fail with `TypeError: process.stdout.clearLine is not a function` -// for some reason. This comes from Vite, and is conditionally called based on `isTTY`. -// We set it to false here to skip this odd behavior. -process.stdout.isTTY = false; - -const config = { - testMatch: 'test/*.test.js', - /* Maximum time one test can run for. */ - timeout: 30 * 1000, - expect: { - /** - * Maximum time expect() should wait for the condition to be met. - * For example in `await expect(locator).toHaveText();` - */ - timeout: 5000, - }, - /* Fail the build on CI if you accidentally left test in the source code. */ - forbidOnly: !!process.env.CI, - /* Retry on CI only */ - retries: process.env.CI ? 5 : 0, - /* Opt out of parallel tests on CI. */ - workers: 1, - /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ - use: { - /* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */ - actionTimeout: 0, - /* Base URL to use in actions like `await page.goto('/')`. */ - baseURL: process.env.PLAYWRIGHT_TEST_BASE_URL || 'http://localhost:4321', - - /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ - trace: 'on-first-retry', - }, - projects: [ - { - name: 'Chrome Stable', - use: { - browserName: 'chromium', - channel: 'chrome', - }, - }, - ], -}; - -export default config; diff --git a/packages/integrations/prefetch/src/client.ts b/packages/integrations/prefetch/src/client.ts deleted file mode 100644 index dc05cb84b0..0000000000 --- a/packages/integrations/prefetch/src/client.ts +++ /dev/null @@ -1,155 +0,0 @@ -/// -import throttles from 'throttles'; -import requestIdleCallback from './requestIdleCallback.js'; - -const events = ['mouseenter', 'touchstart', 'focus']; - -const preloaded = new Set(); -const loadedStyles = new Set(); - -function shouldPreload({ href }: { href: string }) { - try { - const url = new URL(href); - return ( - window.location.origin === url.origin && - window.location.pathname !== url.pathname && - !preloaded.has(href) - ); - } catch {} - - return false; -} - -let parser: DOMParser; -let observer: IntersectionObserver; - -function observe(link: HTMLAnchorElement) { - preloaded.add(link.href); - observer.observe(link); - events.map((event) => link.addEventListener(event, onLinkEvent, { passive: true, once: true })); -} - -function unobserve(link: HTMLAnchorElement) { - observer.unobserve(link); - events.map((event) => link.removeEventListener(event, onLinkEvent)); -} - -function onLinkEvent({ target }: Event) { - if (!(target instanceof HTMLAnchorElement)) { - return; - } - - preloadHref(target); -} - -async function preloadHref(link: HTMLAnchorElement) { - unobserve(link); - const { href } = link; - - try { - const contents = await fetch(href).then((res) => res.text()); - parser ||= new DOMParser(); - - const html = parser.parseFromString(contents, 'text/html'); - const styles = Array.from(html.querySelectorAll('link[rel="stylesheet"]')); - - await Promise.all( - styles - .filter((el) => !loadedStyles.has(el.href)) - .map((el) => { - loadedStyles.add(el.href); - return fetch(el.href); - }) - ); - } catch {} -} - -export interface PrefetchOptions { - /** - * Element selector used to find all links on the page that should be prefetched. - * - * @default 'a[href][rel~="prefetch"]' - */ - selector?: string; - /** - * The number of pages that can be prefetched concurrently. - * - * @default 1 - */ - throttle?: number; - /** - * Element selector used to find all links on the page that should be prefetched on user interaction. - * - * @default 'a[href][rel~="prefetch-intent"]' - */ - intentSelector?: string | string[]; -} - -export default function prefetch({ - selector = 'a[href][rel~="prefetch"]', - throttle = 1, - intentSelector = 'a[href][rel~="prefetch-intent"]', -}: PrefetchOptions) { - // If the navigator is offline, it is very unlikely that a request can be made successfully - if (!navigator.onLine) { - return Promise.reject(new Error('Cannot prefetch, no network connection')); - } - - // `Navigator.connection` is an experimental API and is not supported in every browser. - if ('connection' in navigator) { - const connection = (navigator as any).connection; - // Don't prefetch if Save-Data is enabled. - if (connection.saveData) { - return Promise.reject(new Error('Cannot prefetch, Save-Data is enabled')); - } - - // Do not prefetch if using 2G or 3G - if (/(2|3)g/.test(connection.effectiveType)) { - return Promise.reject(new Error('Cannot prefetch, network conditions are poor')); - } - } - - const [toAdd, isDone] = throttles(throttle); - - observer = - observer || - new IntersectionObserver((entries) => { - entries.forEach((entry) => { - if (entry.isIntersecting && entry.target instanceof HTMLAnchorElement) { - const relAttributeValue = entry.target.getAttribute('rel') || ''; - let matchesIntentSelector = false; - // Check if intentSelector is an array - if (Array.isArray(intentSelector)) { - // If intentSelector is an array, use .some() to check for matches - matchesIntentSelector = intentSelector.some((intent) => - relAttributeValue.includes(intent) - ); - } else { - // If intentSelector is a string, use .includes() to check for a match - matchesIntentSelector = relAttributeValue.includes(intentSelector); - } - if (!matchesIntentSelector) { - toAdd(() => preloadHref(entry.target as HTMLAnchorElement).finally(isDone)); - } - } - }); - }); - - requestIdleCallback(() => { - const links = [...document.querySelectorAll(selector)].filter(shouldPreload); - links.forEach(observe); - - const intentSelectorFinal = Array.isArray(intentSelector) - ? intentSelector.join(',') - : intentSelector; - // Observe links with prefetch-intent - const intentLinks = [ - ...document.querySelectorAll(intentSelectorFinal), - ].filter(shouldPreload); - intentLinks.forEach((link) => { - events.map((event) => - link.addEventListener(event, onLinkEvent, { passive: true, once: true }) - ); - }); - }); -} diff --git a/packages/integrations/prefetch/src/index.ts b/packages/integrations/prefetch/src/index.ts deleted file mode 100644 index 74ec5186e6..0000000000 --- a/packages/integrations/prefetch/src/index.ts +++ /dev/null @@ -1,19 +0,0 @@ -import type { AstroIntegration } from 'astro'; -import type { PrefetchOptions } from './client.js'; - -export default function (options: PrefetchOptions = {}): AstroIntegration { - return { - name: '@astrojs/prefetch', - hooks: { - 'astro:config:setup': ({ injectScript }) => { - // Inject the necessary polyfills on every page (inlined for speed). - injectScript( - 'page', - `import prefetch from "@astrojs/prefetch/client.js"; prefetch(${JSON.stringify( - options - )});` - ); - }, - }, - }; -} diff --git a/packages/integrations/prefetch/src/requestIdleCallback.ts b/packages/integrations/prefetch/src/requestIdleCallback.ts deleted file mode 100644 index 9435bd41d7..0000000000 --- a/packages/integrations/prefetch/src/requestIdleCallback.ts +++ /dev/null @@ -1,16 +0,0 @@ -function shim(callback: IdleRequestCallback, options?: IdleRequestOptions) { - const timeout = options?.timeout ?? 50; - const start = Date.now(); - - return setTimeout(function () { - callback({ - didTimeout: false, - timeRemaining: function () { - return Math.max(0, timeout - (Date.now() - start)); - }, - }); - }, 1); -} - -const requestIdleCallback = window.requestIdleCallback || shim; -export default requestIdleCallback; diff --git a/packages/integrations/prefetch/test/basic-prefetch.test.js b/packages/integrations/prefetch/test/basic-prefetch.test.js deleted file mode 100644 index 5fab536aa8..0000000000 --- a/packages/integrations/prefetch/test/basic-prefetch.test.js +++ /dev/null @@ -1,130 +0,0 @@ -import { expect } from '@playwright/test'; -import { testFactory } from './test-utils.js'; - -const test = testFactory({ root: './fixtures/basic-prefetch/' }); - -test.describe('Basic prefetch', () => { - test.describe('dev', () => { - let devServer; - - test.beforeEach(async ({ astro }) => { - devServer = await astro.startDevServer(); - }); - - test.afterEach(async () => { - await devServer.stop(); - }); - - test.describe('prefetches rel="prefetch" links', () => { - test('skips /admin', async ({ page, astro }) => { - const requests = []; - - page.on('request', (request) => requests.push(request.url())); - - await page.goto(astro.resolveUrl('/')); - - await page.waitForLoadState('networkidle'); - - expect(requests.includes(astro.resolveUrl('/about')), '/about was prefetched').toBeTruthy(); - expect( - requests.includes(astro.resolveUrl('/contact')), - '/contact was prefetched' - ).toBeTruthy(); - expect(requests.includes(astro.resolveUrl('/admin')), '/admin was skipped').toBeFalsy(); - expect( - requests.filter((r) => r === astro.resolveUrl('/')).length === 1, - '/ was skipped by prefetch and only queried once' - ).toBeTruthy(); - }); - }); - - test.describe('prefetches rel="prefetch-intent" links only on hover', () => { - test('prefetches /uses on hover', async ({ page, astro }) => { - const requests = []; - - page.on('request', (request) => requests.push(request.url())); - - await page.goto(astro.resolveUrl('/')); - - await page.waitForLoadState('networkidle'); - - expect( - requests.includes(astro.resolveUrl('/uses')), - '/uses was not prefetched' - ).toBeFalsy(); - - await page.hover('a[href="/uses"]'); - - await page.waitForLoadState('networkidle'); - - expect( - requests.includes(astro.resolveUrl('/uses')), - '/uses was prefetched on hover' - ).toBeTruthy(); - }); - }); - }); - - test.describe('build', () => { - let previewServer; - - test.beforeEach(async ({ astro }) => { - await astro.build(); - previewServer = await astro.preview(); - }); - - // important: close preview server (free up port and connection) - test.afterEach(async () => { - await previewServer.stop(); - }); - - test.describe('prefetches rel="prefetch" links', () => { - test('skips /admin', async ({ page, astro }) => { - const requests = []; - - page.on('request', (request) => requests.push(request.url())); - - await page.goto(astro.resolveUrl('/')); - - await page.waitForLoadState('networkidle'); - - expect(requests.includes(astro.resolveUrl('/about')), '/about was prefetched').toBeTruthy(); - expect( - requests.includes(astro.resolveUrl('/contact')), - '/contact was prefetched' - ).toBeTruthy(); - expect(requests.includes(astro.resolveUrl('/admin')), '/admin was skipped').toBeFalsy(); - expect( - requests.filter((r) => r === astro.resolveUrl('/')).length === 1, - '/ was skipped by prefetch and only queried once' - ).toBeTruthy(); - }); - }); - - test.describe('prefetches rel="prefetch-intent" links only on hover', () => { - test('prefetches /uses on hover', async ({ page, astro }) => { - const requests = []; - - page.on('request', (request) => requests.push(request.url())); - - await page.goto(astro.resolveUrl('/')); - - await page.waitForLoadState('networkidle'); - - expect( - requests.includes(astro.resolveUrl('/uses')), - '/uses was not prefetched' - ).toBeFalsy(); - - await page.hover('a[href="/uses"]'); - - await page.waitForLoadState('networkidle'); - - expect( - requests.includes(astro.resolveUrl('/uses')), - '/uses was prefetched on hover' - ).toBeTruthy(); - }); - }); - }); -}); diff --git a/packages/integrations/prefetch/test/custom-selectors.test.js b/packages/integrations/prefetch/test/custom-selectors.test.js deleted file mode 100644 index b680388dfa..0000000000 --- a/packages/integrations/prefetch/test/custom-selectors.test.js +++ /dev/null @@ -1,260 +0,0 @@ -import { expect } from '@playwright/test'; -import { testFactory } from './test-utils.js'; -import prefetch from '../dist/index.js'; - -const customSelector = 'a[href="/contact"]'; -const customIntentSelector = [ - 'a[href][rel~="custom-intent"]', - 'a[href][rel~="customer-intent"]', - 'a[href][rel~="customest-intent"]', -]; - -const test = testFactory({ - // pass custom prefetch configuration - configFile: false, - root: './fixtures/basic-prefetch/', - integrations: [ - prefetch({ - selector: customSelector, - intentSelector: customIntentSelector, - }), - ], -}); - -test.describe('Custom prefetch selectors', () => { - test.describe('dev', () => { - let devServer; - - test.beforeEach(async ({ astro }) => { - devServer = await astro.startDevServer(); - }); - - test.afterEach(async () => { - await devServer.stop(); - }); - - test.describe('prefetches links by custom selector', () => { - test('only prefetches /contact', async ({ page, astro }) => { - const requests = []; - - page.on('request', (request) => requests.push(request.url())); - - await page.goto(astro.resolveUrl('/')); - - await page.waitForLoadState('networkidle'); - - expect(requests.includes(astro.resolveUrl('/about')), '/about was skipped').toBeFalsy(); - expect( - requests.includes(astro.resolveUrl('/contact')), - '/contact was prefetched' - ).toBeTruthy(); - expect(requests.includes(astro.resolveUrl('/admin')), '/admin was skipped').toBeFalsy(); - expect( - requests.filter((r) => r === astro.resolveUrl('/')).length === 1, - '/ was skipped by prefetch and only queried once' - ).toBeTruthy(); - }); - }); - }); - - test.describe('build', () => { - let previewServer; - - test.beforeEach(async ({ astro }) => { - await astro.build(); - previewServer = await astro.preview(); - }); - - // important: close preview server (free up port and connection) - test.afterEach(async () => { - await previewServer.stop(); - }); - - test.describe('prefetches links by custom selector', () => { - test('only prefetches /contact', async ({ page, astro }) => { - const requests = []; - - page.on('request', (request) => requests.push(request.url())); - - await page.goto(astro.resolveUrl('/')); - - await page.waitForLoadState('networkidle'); - - expect(requests.includes(astro.resolveUrl('/about')), '/about was skipped').toBeFalsy(); - expect( - requests.includes(astro.resolveUrl('/contact')), - '/contact was prefetched' - ).toBeTruthy(); - expect(requests.includes(astro.resolveUrl('/admin')), '/admin was skipped').toBeFalsy(); - expect( - requests.filter((r) => r === astro.resolveUrl('/')).length === 1, - '/ was skipped by prefetch and only queried once' - ).toBeTruthy(); - }); - }); - }); -}); - -test.describe('Custom prefetch intent selectors', () => { - test.describe('dev', () => { - let devServer; - - test.beforeEach(async ({ astro }) => { - devServer = await astro.startDevServer(); - }); - - test.afterEach(async () => { - await devServer.stop(); - }); - - test('prefetches custom intent links only on hover if provided an array', async ({ - page, - astro, - }) => { - const requests = []; - - page.on('request', (request) => requests.push(request.url())); - - await page.goto(astro.resolveUrl('/')); - - await page.waitForLoadState('networkidle'); - - expect( - requests.includes(astro.resolveUrl('/terms')), - '/terms was not prefetched initially' - ).toBeFalsy(); - - expect( - requests.includes(astro.resolveUrl('/conditions')), - '/conditions was not prefetched initially' - ).toBeFalsy(); - - const combinedIntentSelectors = customIntentSelector.join(','); - const intentElements = await page.$$(combinedIntentSelectors); - - for (const element of intentElements) { - await element.hover(); - } - - await page.waitForLoadState('networkidle'); - - expect( - requests.includes(astro.resolveUrl('/terms')), - '/terms was prefetched on hover' - ).toBeTruthy(); - expect( - requests.includes(astro.resolveUrl('/conditions')), - '/conditions was prefetched on hover' - ).toBeTruthy(); - }); - - test('prefetches custom intent links only on hover if provided a string', async ({ - page, - astro, - }) => { - const requests = []; - - page.on('request', (request) => requests.push(request.url())); - - await page.goto(astro.resolveUrl('/')); - - await page.waitForLoadState('networkidle'); - - expect( - requests.includes(astro.resolveUrl('/terms')), - '/terms was not prefetched initially' - ).toBeFalsy(); - - await page.hover(customIntentSelector[0]); - - await page.waitForLoadState('networkidle'); - - expect( - requests.includes(astro.resolveUrl('/terms')), - '/terms was prefetched on hover' - ).toBeTruthy(); - }); - }); - - test.describe('build', () => { - let previewServer; - - test.beforeEach(async ({ astro }) => { - await astro.build(); - previewServer = await astro.preview(); - }); - - // important: close preview server (free up port and connection) - test.afterEach(async () => { - await previewServer.stop(); - }); - - test('prefetches custom intent links only on hover if provided an array', async ({ - page, - astro, - }) => { - const requests = []; - - page.on('request', (request) => requests.push(request.url())); - - await page.goto(astro.resolveUrl('/')); - - await page.waitForLoadState('networkidle'); - - expect( - requests.includes(astro.resolveUrl('/terms')), - '/terms was not prefetched initially' - ).toBeFalsy(); - - expect( - requests.includes(astro.resolveUrl('/conditions')), - '/conditions was not prefetched initially' - ).toBeFalsy(); - - const combinedIntentSelectors = customIntentSelector.join(','); - const intentElements = await page.$$(combinedIntentSelectors); - - for (const element of intentElements) { - await element.hover(); - } - - await page.waitForLoadState('networkidle'); - - expect( - requests.includes(astro.resolveUrl('/terms')), - '/terms was prefetched on hover' - ).toBeTruthy(); - expect( - requests.includes(astro.resolveUrl('/conditions')), - '/conditions was prefetched on hover' - ).toBeTruthy(); - }); - - test('prefetches custom intent links only on hover if provided a string', async ({ - page, - astro, - }) => { - const requests = []; - - page.on('request', (request) => requests.push(request.url())); - - await page.goto(astro.resolveUrl('/')); - - await page.waitForLoadState('networkidle'); - - expect( - requests.includes(astro.resolveUrl('/terms')), - '/terms was not prefetched initially' - ).toBeFalsy(); - - await page.hover(customIntentSelector[0]); - - await page.waitForLoadState('networkidle'); - - expect( - requests.includes(astro.resolveUrl('/terms')), - '/terms was prefetched on hover' - ).toBeTruthy(); - }); - }); -}); diff --git a/packages/integrations/prefetch/test/fixtures/basic-prefetch/astro.config.mjs b/packages/integrations/prefetch/test/fixtures/basic-prefetch/astro.config.mjs deleted file mode 100644 index 092813b22f..0000000000 --- a/packages/integrations/prefetch/test/fixtures/basic-prefetch/astro.config.mjs +++ /dev/null @@ -1,7 +0,0 @@ -import { defineConfig } from 'astro/config'; -import prefetch from '@astrojs/prefetch'; - -// https://astro.build/config -export default defineConfig({ - integrations: [prefetch()], -}); diff --git a/packages/integrations/prefetch/test/fixtures/basic-prefetch/package.json b/packages/integrations/prefetch/test/fixtures/basic-prefetch/package.json deleted file mode 100644 index cf10d74712..0000000000 --- a/packages/integrations/prefetch/test/fixtures/basic-prefetch/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "@test/astro-prefetch", - "version": "0.0.0", - "private": true, - "dependencies": { - "@astrojs/prefetch": "workspace:*", - "astro": "workspace:*" - } -} diff --git a/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/about.astro b/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/about.astro deleted file mode 100644 index dc2aeb8fee..0000000000 --- a/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/about.astro +++ /dev/null @@ -1,11 +0,0 @@ ---- ---- - - - -About Us - - -

About Us

- - diff --git a/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/admin.astro b/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/admin.astro deleted file mode 100644 index 7e44fc97d1..0000000000 --- a/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/admin.astro +++ /dev/null @@ -1,11 +0,0 @@ ---- ---- - - - -Admin - - -

Admin

- - diff --git a/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/conditions.astro b/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/conditions.astro deleted file mode 100644 index 345abaa384..0000000000 --- a/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/conditions.astro +++ /dev/null @@ -1,11 +0,0 @@ ---- ---- - - - -Conditions - - -

Conditions

- - diff --git a/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/contact.astro b/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/contact.astro deleted file mode 100644 index b565db9125..0000000000 --- a/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/contact.astro +++ /dev/null @@ -1,11 +0,0 @@ ---- ---- - - - -Contact Us - - -

Contact Us

- - diff --git a/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/index.astro b/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/index.astro deleted file mode 100644 index b78e395530..0000000000 --- a/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/index.astro +++ /dev/null @@ -1,34 +0,0 @@ ---- ---- - - - -Home - - -

Home

- -
- - - - diff --git a/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/terms.astro b/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/terms.astro deleted file mode 100644 index a0fcc10047..0000000000 --- a/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/terms.astro +++ /dev/null @@ -1,11 +0,0 @@ ---- ---- - - - -Terms - - -

Terms

- - diff --git a/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/uses.astro b/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/uses.astro deleted file mode 100644 index 15b050061e..0000000000 --- a/packages/integrations/prefetch/test/fixtures/basic-prefetch/src/pages/uses.astro +++ /dev/null @@ -1,11 +0,0 @@ ---- ---- - - - -Uses - - -

Uses

- - diff --git a/packages/integrations/prefetch/test/fixtures/style-prefetch/astro.config.mjs b/packages/integrations/prefetch/test/fixtures/style-prefetch/astro.config.mjs deleted file mode 100644 index 092813b22f..0000000000 --- a/packages/integrations/prefetch/test/fixtures/style-prefetch/astro.config.mjs +++ /dev/null @@ -1,7 +0,0 @@ -import { defineConfig } from 'astro/config'; -import prefetch from '@astrojs/prefetch'; - -// https://astro.build/config -export default defineConfig({ - integrations: [prefetch()], -}); diff --git a/packages/integrations/prefetch/test/fixtures/style-prefetch/package.json b/packages/integrations/prefetch/test/fixtures/style-prefetch/package.json deleted file mode 100644 index dce71e357b..0000000000 --- a/packages/integrations/prefetch/test/fixtures/style-prefetch/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "@test/astro-style-prefetch", - "version": "0.0.0", - "private": true, - "dependencies": { - "@astrojs/prefetch": "workspace:*", - "astro": "workspace:*" - } -} diff --git a/packages/integrations/prefetch/test/fixtures/style-prefetch/src/pages/index.astro b/packages/integrations/prefetch/test/fixtures/style-prefetch/src/pages/index.astro deleted file mode 100644 index 9b8b84eec1..0000000000 --- a/packages/integrations/prefetch/test/fixtures/style-prefetch/src/pages/index.astro +++ /dev/null @@ -1,18 +0,0 @@ ---- ---- - - - - - - - Home - - -

Home

- - - \ No newline at end of file diff --git a/packages/integrations/prefetch/test/fixtures/style-prefetch/src/pages/style1.astro b/packages/integrations/prefetch/test/fixtures/style-prefetch/src/pages/style1.astro deleted file mode 100644 index def02918c9..0000000000 --- a/packages/integrations/prefetch/test/fixtures/style-prefetch/src/pages/style1.astro +++ /dev/null @@ -1,15 +0,0 @@ ---- ---- - - - - - - - Style1 - - - -

Style1

- - \ No newline at end of file diff --git a/packages/integrations/prefetch/test/fixtures/style-prefetch/src/pages/style2.astro b/packages/integrations/prefetch/test/fixtures/style-prefetch/src/pages/style2.astro deleted file mode 100644 index 2e3b6949c7..0000000000 --- a/packages/integrations/prefetch/test/fixtures/style-prefetch/src/pages/style2.astro +++ /dev/null @@ -1,15 +0,0 @@ ---- ---- - - - - - - - Style2 - - - -

Style2

- - \ No newline at end of file diff --git a/packages/integrations/prefetch/test/style-prefetch.test.js b/packages/integrations/prefetch/test/style-prefetch.test.js deleted file mode 100644 index b9bb0b0436..0000000000 --- a/packages/integrations/prefetch/test/style-prefetch.test.js +++ /dev/null @@ -1,55 +0,0 @@ -import { expect } from '@playwright/test'; -import { testFactory } from './test-utils.js'; - -const test = testFactory({ root: './fixtures/style-prefetch/' }); - -test.describe('Style prefetch', () => { - test.describe('dev', () => { - let devServer; - - test.beforeEach(async ({ astro }) => { - devServer = await astro.startDevServer(); - }); - - test.afterEach(async () => { - await devServer.stop(); - }); - - testPrefetch(); - }); - - test.describe('build', () => { - let previewServer; - - test.beforeAll(async ({ astro }) => { - await astro.build(); - previewServer = await astro.preview(); - }); - - // important: close preview server (free up port and connection) - test.afterAll(async () => { - await previewServer.stop(); - }); - - testPrefetch(); - }); - - function testPrefetch() { - test.describe('prefetches rel="prefetch" links', () => { - test('style fetching', async ({ page, astro }) => { - const requests = []; - - page.on('request', (request) => requests.push(request.url())); - - await page.goto(astro.resolveUrl('/')); - - await page.waitForLoadState('networkidle'); - - await expect(requests.filter((req) => req.includes('/style1'))).toBeTruthy(); - await expect(requests.filter((req) => req.includes('/style2'))).toBeTruthy(); - const cssRequestCount = requests.filter((req) => req.includes('/main.css')).length; - await expect(cssRequestCount).toBe(1); - }); - }); - } -}); diff --git a/packages/integrations/prefetch/test/test-utils.js b/packages/integrations/prefetch/test/test-utils.js deleted file mode 100644 index 0b5de1f9db..0000000000 --- a/packages/integrations/prefetch/test/test-utils.js +++ /dev/null @@ -1,30 +0,0 @@ -import { test as testBase } from '@playwright/test'; -import { loadFixture as baseLoadFixture } from '../../../astro/test/test-utils.js'; - -export function loadFixture(inlineConfig) { - if (!inlineConfig?.root) throw new Error("Must provide { root: './fixtures/...' }"); - - // resolve the relative root (i.e. "./fixtures/tailwindcss") to a full filepath - // without this, the main `loadFixture` helper will resolve relative to `packages/astro/test` - return baseLoadFixture({ - ...inlineConfig, - root: new URL(inlineConfig.root, import.meta.url).toString(), - }); -} - -export function testFactory(inlineConfig) { - let fixture; - - const test = testBase.extend({ - astro: async ({}, use) => { - fixture = await loadFixture(inlineConfig); - await use(fixture); - }, - }); - - test.afterEach(() => { - fixture.resetAllFiles(); - }); - - return test; -} diff --git a/packages/integrations/prefetch/tsconfig.json b/packages/integrations/prefetch/tsconfig.json deleted file mode 100644 index dadc37a826..0000000000 --- a/packages/integrations/prefetch/tsconfig.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "../../../tsconfig.base.json", - "include": ["src", "@types"], - "compilerOptions": { - "outDir": "./dist" - } -} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d338d3d81b..2489b5a5be 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4415,40 +4415,6 @@ importers: specifier: ^10.19.2 version: 10.19.2 - packages/integrations/prefetch: - dependencies: - throttles: - specifier: ^1.0.1 - version: 1.0.1 - devDependencies: - '@playwright/test': - specifier: ^1.40.0 - version: 1.40.0 - astro: - specifier: workspace:* - version: link:../../astro - astro-scripts: - specifier: workspace:* - version: link:../../../scripts - - packages/integrations/prefetch/test/fixtures/basic-prefetch: - dependencies: - '@astrojs/prefetch': - specifier: workspace:* - version: link:../../.. - astro: - specifier: workspace:* - version: link:../../../../../astro - - packages/integrations/prefetch/test/fixtures/style-prefetch: - dependencies: - '@astrojs/prefetch': - specifier: workspace:* - version: link:../../.. - astro: - specifier: workspace:* - version: link:../../../../../astro - packages/integrations/react: dependencies: '@vitejs/plugin-react': @@ -18067,11 +18033,6 @@ packages: optional: true dev: true - /throttles@1.0.1: - resolution: {integrity: sha512-fab7Xg+zELr9KOv4fkaBoe/b3L0GMGLd0IBSCn16GoE/Qx6/OfCr1eGNyEcDU2pUA79qQfZ8kPQWlRuok4YwTw==} - engines: {node: '>=6'} - dev: false - /timestring@6.0.0: resolution: {integrity: sha512-wMctrWD2HZZLuIlchlkE2dfXJh7J2KDI9Dwl+2abPYg0mswQHfOAyQW3jJg1pY5VfttSINZuKcXoB3FGypVklA==} engines: {node: '>=8'}