diff options
Diffstat (limited to 'packages/integrations/solid')
-rw-r--r-- | packages/integrations/solid/CHANGELOG.md | 14 | ||||
-rw-r--r-- | packages/integrations/solid/package.json | 7 | ||||
-rw-r--r-- | packages/integrations/solid/src/dependencies.ts | 27 | ||||
-rw-r--r-- | packages/integrations/solid/src/index.ts | 76 | ||||
-rw-r--r-- | packages/integrations/solid/tsconfig.json | 2 |
5 files changed, 55 insertions, 71 deletions
diff --git a/packages/integrations/solid/CHANGELOG.md b/packages/integrations/solid/CHANGELOG.md index a23dd7f7a..6b1e4b012 100644 --- a/packages/integrations/solid/CHANGELOG.md +++ b/packages/integrations/solid/CHANGELOG.md @@ -1,5 +1,19 @@ # @astrojs/solid-js +## 3.0.0-beta.1 + +### Major Changes + +- [#7924](https://github.com/withastro/astro/pull/7924) [`519a1c4e8`](https://github.com/withastro/astro/commit/519a1c4e8407c7abcb8d879b67a9f4b960652cae) Thanks [@matthewp](https://github.com/matthewp)! - New `include` and `exclude` config options + + The Solid integration now has new `include` and `exclude` config options. Use these if you want to use Solid alongside another JSX framework; include specifies files to be compiled for Solid and `exclude` does the opposite. + +## 3.0.0-beta.0 + +### Major 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. + ## 2.2.0 ### Minor Changes diff --git a/packages/integrations/solid/package.json b/packages/integrations/solid/package.json index 991ff579f..5dc00a86e 100644 --- a/packages/integrations/solid/package.json +++ b/packages/integrations/solid/package.json @@ -1,6 +1,6 @@ { "name": "@astrojs/solid-js", - "version": "2.2.0", + "version": "3.0.0-beta.1", "description": "Use Solid components within Astro", "type": "module", "types": "./dist/index.d.ts", @@ -35,8 +35,7 @@ "dev": "astro-scripts dev \"src/**/*.ts\"" }, "dependencies": { - "babel-preset-solid": "^1.7.7", - "vitefu": "^0.2.4" + "vite-plugin-solid": "^2.7.0" }, "devDependencies": { "astro": "workspace:*", @@ -47,6 +46,6 @@ "solid-js": "^1.4.3" }, "engines": { - "node": ">=16.12.0" + "node": ">=18.14.1" } } diff --git a/packages/integrations/solid/src/dependencies.ts b/packages/integrations/solid/src/dependencies.ts deleted file mode 100644 index ac6e5c655..000000000 --- a/packages/integrations/solid/src/dependencies.ts +++ /dev/null @@ -1,27 +0,0 @@ -import type { AstroConfig } from 'astro'; -import { fileURLToPath } from 'node:url'; -import { crawlFrameworkPkgs } from 'vitefu'; - -export async function getSolidPkgsConfig(isBuild: boolean, astroConfig: AstroConfig) { - return await crawlFrameworkPkgs({ - root: fileURLToPath(astroConfig.root), - isBuild, - viteUserConfig: astroConfig.vite, - isFrameworkPkgByJson(pkgJson) { - return containsSolidField(pkgJson.exports || {}); - }, - }); -} - -// Reference vite-plugin-solid heuristic -// https://github.com/solidjs/vite-plugin-solid/blob/5558486b0c63788e1275244256918f80294a8338/src/index.ts#L251-L259 -// License: MIT (https://github.com/solidjs/vite-plugin-solid/blob/5558486b0c63788e1275244256918f80294a8338/package.json#L38) -function containsSolidField(fields: Record<string, any>) { - const keys = Object.keys(fields); - for (const key of keys) { - if (key === 'solid') return true; - if (typeof fields[key] === 'object' && fields[key] != null && containsSolidField(fields[key])) - return true; - } - return false; -} diff --git a/packages/integrations/solid/src/index.ts b/packages/integrations/solid/src/index.ts index cfd38224c..127d9ddb6 100644 --- a/packages/integrations/solid/src/index.ts +++ b/packages/integrations/solid/src/index.ts @@ -1,63 +1,61 @@ -import type { AstroConfig, AstroIntegration, AstroRenderer } from 'astro'; -import { getSolidPkgsConfig } from './dependencies.js'; +import type { AstroIntegration, AstroRenderer } from 'astro'; +import solid, { type Options as ViteSolidPluginOptions } from 'vite-plugin-solid'; -function getRenderer(): AstroRenderer { - return { - name: '@astrojs/solid-js', - clientEntrypoint: '@astrojs/solid-js/client.js', - serverEntrypoint: '@astrojs/solid-js/server.js', - jsxImportSource: 'solid-js', - jsxTransformOptions: async ({ ssr }) => { - // @ts-expect-error types not found - const [{ default: solid }] = await Promise.all([import('babel-preset-solid')]); - const options = { - presets: [solid({}, { generate: ssr ? 'ssr' : 'dom', hydratable: true })], - plugins: [], - // Otherwise, babel will try to consume the source map generated by esbuild - // This causes unexpected issues with newline characters: https://github.com/withastro/astro/issues/3371 - // Note "vite-plugin-solid" does the same: https://github.com/solidjs/vite-plugin-solid/blob/master/src/index.ts#L344-L345 - inputSourceMap: false as any, - }; - - return options; - }, - }; -} - -async function getViteConfiguration(isDev: boolean, astroConfig: AstroConfig) { +async function getViteConfiguration(isDev: boolean, { include, exclude }: Options = {}) { // https://github.com/solidjs/vite-plugin-solid // We inject the dev mode only if the user explicitly wants it or if we are in dev (serve) mode const nestedDeps = ['solid-js', 'solid-js/web', 'solid-js/store', 'solid-js/html', 'solid-js/h']; - const solidPkgsConfig = await getSolidPkgsConfig(!isDev, astroConfig); return { - /** - * We only need esbuild on .ts or .js files. - * .tsx & .jsx files are handled by us - */ - esbuild: { include: /\.ts$/ }, resolve: { conditions: ['solid', ...(isDev ? ['development'] : [])], dedupe: nestedDeps, alias: [{ find: /^solid-refresh$/, replacement: '/@solid-refresh' }], }, optimizeDeps: { - include: [...nestedDeps, ...solidPkgsConfig.optimizeDeps.include], - exclude: ['@astrojs/solid-js/server.js', ...solidPkgsConfig.optimizeDeps.exclude], + include: [...nestedDeps], + exclude: ['@astrojs/solid-js/server.js'], }, + plugins: [ + solid({ include, exclude, dev: isDev, ssr: true }), + { + name: '@astrojs/solid:config-overrides', + enforce: 'post', + config() { + return { + esbuild: { + // To support using alongside other JSX frameworks, still let + // esbuild compile stuff. Solid goes first anyways. + include: /\.(m?ts|[jt]sx)$/, + }, + }; + }, + }, + ], ssr: { - external: ['babel-preset-solid', ...solidPkgsConfig.ssr.external], - noExternal: [...solidPkgsConfig.ssr.noExternal], + external: ['babel-preset-solid'], }, }; } -export default function (): AstroIntegration { +function getRenderer(): AstroRenderer { + return { + name: '@astrojs/solid-js', + clientEntrypoint: '@astrojs/solid-js/client.js', + serverEntrypoint: '@astrojs/solid-js/server.js', + }; +} + +export type Options = Pick<ViteSolidPluginOptions, 'include' | 'exclude'>; + +export default function (opts: Options = {}): AstroIntegration { return { name: '@astrojs/solid-js', hooks: { - 'astro:config:setup': async ({ command, addRenderer, updateConfig, config }) => { + 'astro:config:setup': async ({ command, addRenderer, updateConfig }) => { addRenderer(getRenderer()); - updateConfig({ vite: await getViteConfiguration(command === 'dev', config) }); + updateConfig({ + vite: await getViteConfiguration(command === 'dev', opts), + }); }, }, }; diff --git a/packages/integrations/solid/tsconfig.json b/packages/integrations/solid/tsconfig.json index 64d4ef454..af1b43564 100644 --- a/packages/integrations/solid/tsconfig.json +++ b/packages/integrations/solid/tsconfig.json @@ -5,6 +5,6 @@ "allowJs": true, "module": "ES2022", "outDir": "./dist", - "target": "ES2021" + "target": "ES2022" } } |