Remove turbolinks integration (#8186)
This commit is contained in:
parent
732111cdce
commit
b8ad9a2499
8 changed files with 0 additions and 317 deletions
|
@ -1,59 +0,0 @@
|
|||
import type { TsConfigJson } from 'tsconfig-resolver';
|
||||
import type { AstroRenderer } from '../@types/astro';
|
||||
import { parseNpmName } from '../core/util.js';
|
||||
|
||||
export async function detectImportSource(
|
||||
code: string,
|
||||
jsxRenderers: Map<string, AstroRenderer>,
|
||||
tsConfig?: TsConfigJson
|
||||
): Promise<string | undefined> {
|
||||
let importSource = detectImportSourceFromComments(code);
|
||||
if (!importSource && /import/.test(code)) {
|
||||
importSource = await detectImportSourceFromImports(code, jsxRenderers);
|
||||
}
|
||||
if (!importSource && tsConfig) {
|
||||
importSource = tsConfig.compilerOptions?.jsxImportSource;
|
||||
}
|
||||
return importSource;
|
||||
}
|
||||
|
||||
// Matches import statements and dynamic imports. Captures import specifiers only.
|
||||
// Adapted from: https://github.com/vitejs/vite/blob/97f8b4df3c9eb817ab2669e5c10b700802eec900/packages/vite/src/node/optimizer/scan.ts#L47-L48
|
||||
const importsRE =
|
||||
/(?<!\/\/.*)(?<=^|;|\*\/)\s*(?:import(?!\s+type)(?:[\w*{}\n\r\t, ]+from)?\s*("[^"]+"|'[^']+')\s*(?=$|;|\/\/|\/\*)|import\s*\(\s*("[^"]+"|'[^']+')\s*\))/gm;
|
||||
|
||||
/**
|
||||
* Scan a file's imports to detect which renderer it may need.
|
||||
* ex: if the file imports "preact", it's safe to assume the
|
||||
* component should be built as a Preact component.
|
||||
* If no relevant imports found, return undefined.
|
||||
*/
|
||||
async function detectImportSourceFromImports(
|
||||
code: string,
|
||||
jsxRenderers: Map<string, AstroRenderer>
|
||||
): Promise<string | undefined> {
|
||||
let m;
|
||||
importsRE.lastIndex = 0;
|
||||
while ((m = importsRE.exec(code)) != null) {
|
||||
const spec = (m[1] || m[2]).slice(1, -1);
|
||||
const pkg = parseNpmName(spec);
|
||||
if (pkg && jsxRenderers.has(pkg.name)) {
|
||||
return pkg.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan a file for an explicit @jsxImportSource comment.
|
||||
* If one is found, return it's value. Otherwise, return undefined.
|
||||
*/
|
||||
function detectImportSourceFromComments(code: string): string | undefined {
|
||||
// if no imports were found, look for @jsxImportSource comment
|
||||
const multiline = code.match(/\/\*\*?[\S\s]*\*\//gm) || [];
|
||||
for (const comment of multiline) {
|
||||
const [, lib] = comment.slice(0, -2).match(/@jsxImportSource\s*(\S+)/) || [];
|
||||
if (lib) {
|
||||
return lib.trim();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
# @astrojs/turbolinks
|
||||
|
||||
## 0.3.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.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
|
||||
|
||||
- [#6419](https://github.com/withastro/astro/pull/6419) [`0de08773f`](https://github.com/withastro/astro/commit/0de08773f30cef0e131e42f2068ff56f826b41c0) Thanks [@Yan-Thomas](https://github.com/Yan-Thomas)! - Make Tailwind & Turbolinks integration descriptions more consistent
|
||||
|
||||
## 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.5
|
||||
|
||||
### 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.4
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#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.1.3
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#3383](https://github.com/withastro/astro/pull/3383) [`387ed0cf`](https://github.com/withastro/astro/commit/387ed0cfa1ed73e0025dd81f221ea7c95d724a59) Thanks [@tony-sull](https://github.com/tony-sull)! - The @astrojs/turbolinks integration has been deprecated
|
||||
|
||||
## 0.1.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#3283](https://github.com/withastro/astro/pull/3283) [`9ad8aefd`](https://github.com/withastro/astro/commit/9ad8aefdd79a039062f5a0510fabb2b5e535603f) Thanks [@tony-sull](https://github.com/tony-sull)! - Fixes an issue that prevented client components from rehydrating when navigating back to a page
|
||||
|
||||
## 0.1.1
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [`815d62f1`](https://github.com/withastro/astro/commit/815d62f151a36fef7d09590d4962ca71bda61b32) Thanks [@FredKSchott](https://github.com/FredKSchott)! - no changes.
|
||||
|
||||
## 0.1.0
|
||||
|
||||
### Minor Changes
|
||||
|
||||
- [#2979](https://github.com/withastro/astro/pull/2979) [`9d7a4b59`](https://github.com/withastro/astro/commit/9d7a4b59b53f8cb274266f5036d1cef841750252) Thanks [@FredKSchott](https://github.com/FredKSchott)! - Welcome to the Astro v1.0.0 Beta! Read the [official announcement](https://astro.build/blog/astro-1-beta-release/) for more details.
|
||||
|
||||
## 0.0.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#2885](https://github.com/withastro/astro/pull/2885) [`6b004363`](https://github.com/withastro/astro/commit/6b004363f99f27e581d1e2d53a2ebff39d7afb8a) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Add README across Astro built-in integrations
|
||||
|
||||
* [#2847](https://github.com/withastro/astro/pull/2847) [`3b621f7a`](https://github.com/withastro/astro/commit/3b621f7a613b45983b090794fa7c015f23ed6140) Thanks [@tony-sull](https://github.com/tony-sull)! - Adds keywords to the official integrations to support discoverability on Astro's Integrations site
|
||||
|
||||
## 0.0.2-next.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- [#2847](https://github.com/withastro/astro/pull/2847) [`3b621f7a`](https://github.com/withastro/astro/commit/3b621f7a613b45983b090794fa7c015f23ed6140) Thanks [@tony-sull](https://github.com/tony-sull)! - Adds keywords to the official integrations to support discoverability on Astro's Integrations site
|
|
@ -1,78 +0,0 @@
|
|||
# This integration is no longer actively supported
|
||||
|
||||
[Turbolinks](https://github.com/turbolinks/turbolinks) is no longer under active development. The `@astrojs/turbolinks` integration has been deprecated.
|
||||
|
||||
## Looking for an alternative?
|
||||
|
||||
Check out [swup](https://swup.js.org/)! If you are using any `client:*` script for partial hydration, make sure to install the `@swup/scripts-plugin` to ensure components are rehydrated after a page navigation.
|
||||
|
||||
# @astrojs/turbolinks ⚡️
|
||||
|
||||
This **[Astro integration][astro-integration]** brings [Turbo](https://github.com/hotwired/turbo) to your Astro project.
|
||||
|
||||
Turbolinks is a plug-and-play solution to bring single page app (SPA) routing to your site. This brings performant navigation without the added complexity of a client-side JavaScript framework.
|
||||
|
||||
## Installation
|
||||
|
||||
There are two ways to add integrations to your project. Let's try the most convenient option first!
|
||||
|
||||
### (experimental) `astro add` command
|
||||
|
||||
Astro includes a CLI tool for adding first party integrations: `astro add`. This command will:
|
||||
|
||||
1. (Optionally) Install all necessary dependencies and peer dependencies
|
||||
2. (Also optionally) Update your `astro.config.*` file to apply this integration
|
||||
|
||||
To install `@astrojs/turbolinks`, run the following from your project directory and follow the prompts:
|
||||
|
||||
```sh
|
||||
# Using NPM
|
||||
npx astro add turbolinks
|
||||
# Using Yarn
|
||||
yarn astro add turbolinks
|
||||
# Using PNPM
|
||||
pnpm astro add turbolinks
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
### Install dependencies manually
|
||||
|
||||
First, install the `@astrojs/turbolinks` integration like so:
|
||||
|
||||
```sh
|
||||
npm install @astrojs/turbolinks
|
||||
```
|
||||
|
||||
Then, apply this integration to your `astro.config.*` file using the `integrations` property:
|
||||
|
||||
**`astro.config.mjs`**
|
||||
|
||||
```js
|
||||
import { defineConfig } from 'astro/config';
|
||||
import turbolinks from '@astrojs/turbolinks';
|
||||
|
||||
export default defineConfig({
|
||||
// ...
|
||||
integrations: [turbolinks()],
|
||||
});
|
||||
```
|
||||
|
||||
## Getting started
|
||||
|
||||
Turbo links, frames, and more should be ready-to-use with zero config. For instance, try navigating between different pages via links. You should no longer see browser refreshes! You will also find each page request passing through `turbolinks` under the "Network" tab in [your browser's dev tools](https://developer.chrome.com/docs/devtools/).
|
||||
|
||||
Head to [the Turbo handbook](https://turbo.hotwired.dev/handbook/introduction) for all options and features available. You can also check our [Astro Integration Documentation][astro-integration] for more on integrations.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
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!
|
||||
|
||||
[astro-integration]: https://docs.astro.build/en/guides/integrations-guide/
|
||||
[astro-ui-frameworks]: https://docs.astro.build/en/core-concepts/framework-components/#using-framework-components
|
|
@ -1,18 +0,0 @@
|
|||
import Turbolinks from 'turbolinks';
|
||||
export { Turbolinks };
|
||||
|
||||
// Before every page navigation, remove any previously added component hydration scripts
|
||||
document.addEventListener('turbolinks:before-render', function () {
|
||||
const scripts = document.querySelectorAll('script[data-astro-component-hydration]');
|
||||
for (const script of scripts) {
|
||||
script.remove();
|
||||
}
|
||||
});
|
||||
|
||||
// After every page navigation, move the bundled styles into the body
|
||||
document.addEventListener('turbolinks:render', function () {
|
||||
const styles = document.querySelectorAll('link[href^="/assets/asset"][href$=".css"]');
|
||||
for (const style of styles) {
|
||||
document.body.append(style);
|
||||
}
|
||||
});
|
|
@ -1,42 +0,0 @@
|
|||
{
|
||||
"name": "@astrojs/turbolinks",
|
||||
"description": "Deprecated — Use Turbolinks to speed up page navigation in your Astro site",
|
||||
"version": "0.3.0-beta.0",
|
||||
"type": "module",
|
||||
"types": "./dist/index.d.ts",
|
||||
"author": "withastro",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/withastro/astro.git",
|
||||
"directory": "packages/integrations/turbolinks"
|
||||
},
|
||||
"keywords": [
|
||||
"astro-integration",
|
||||
"astro-component",
|
||||
"performance"
|
||||
],
|
||||
"bugs": "https://github.com/withastro/astro/issues",
|
||||
"homepage": "https://astro.build",
|
||||
"exports": {
|
||||
".": "./dist/index.js",
|
||||
"./client.js": "./client.js",
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"client.js"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "astro-scripts build \"src/**/*.ts\" && tsc",
|
||||
"build:ci": "astro-scripts build \"src/**/*.ts\"",
|
||||
"dev": "astro-scripts dev \"src/**/*.ts\""
|
||||
},
|
||||
"dependencies": {
|
||||
"turbolinks": "^5.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"astro": "workspace:*",
|
||||
"astro-scripts": "workspace:*"
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
import type { AstroIntegration } from 'astro';
|
||||
|
||||
export default function createPlugin(): AstroIntegration {
|
||||
return {
|
||||
name: '@astrojs/turbolinks',
|
||||
hooks: {
|
||||
'astro:config:setup': ({ injectScript }) => {
|
||||
// This gets injected into the user's page, so we need to re-export Turbolinks
|
||||
// from our own package so that package managers like pnpm don't get mad and
|
||||
// can follow the import correctly.
|
||||
injectScript(
|
||||
'page',
|
||||
`import {Turbolinks} from "@astrojs/turbolinks/client.js"; Turbolinks.start();`
|
||||
);
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"extends": "../../../tsconfig.base.json",
|
||||
"include": ["src"],
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"module": "ES2022",
|
||||
"outDir": "./dist",
|
||||
"target": "ES2022"
|
||||
}
|
||||
}
|
|
@ -4691,19 +4691,6 @@ importers:
|
|||
specifier: ^4.4.6
|
||||
version: 4.4.6(@types/node@18.16.18)(sass@1.63.4)
|
||||
|
||||
packages/integrations/turbolinks:
|
||||
dependencies:
|
||||
turbolinks:
|
||||
specifier: ^5.2.0
|
||||
version: 5.2.0
|
||||
devDependencies:
|
||||
astro:
|
||||
specifier: workspace:*
|
||||
version: link:../../astro
|
||||
astro-scripts:
|
||||
specifier: workspace:*
|
||||
version: link:../../../scripts
|
||||
|
||||
packages/integrations/vercel:
|
||||
dependencies:
|
||||
'@astrojs/internal-helpers':
|
||||
|
@ -16821,10 +16808,6 @@ packages:
|
|||
turbo-windows-arm64: 1.10.3
|
||||
dev: true
|
||||
|
||||
/turbolinks@5.2.0:
|
||||
resolution: {integrity: sha512-pMiez3tyBo6uRHFNNZoYMmrES/IaGgMhQQM+VFF36keryjb5ms0XkVpmKHkfW/4Vy96qiGW3K9bz0tF5sK9bBw==}
|
||||
dev: false
|
||||
|
||||
/type-check@0.3.2:
|
||||
resolution: {integrity: sha512-ZCmOJdvOWDBYJlzAoFkC+Q0+bUyEOS1ltgp1MGU03fqHG+dbi9tBFU2Rd9QKiDZFAYrhPh2JUf7rZRIuHRKtOg==}
|
||||
engines: {node: '>= 0.8.0'}
|
||||
|
|
Loading…
Reference in a new issue