Skip to content

Commit

Permalink
Merge pull request #2350 from opral/svelte-5-render
Browse files Browse the repository at this point in the history
Make svelte a peer-dependency
  • Loading branch information
LorisSigrist authored Mar 11, 2024
2 parents 1b0febf + 1000451 commit 1bff876
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 205 deletions.
5 changes: 5 additions & 0 deletions .changeset/short-otters-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@inlang/paraglide-js-adapter-sveltekit": patch
---

fix: make `svelte` a peer dependency
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
{
"name": "@inlang/paraglide-js-adapter-sveltekit",
"version": "0.5.5",
"type": "module",
"main": "./dist/runtime/index.js",
"types": "./dist/runtime/index.d.ts",
"publishConfig": {
"access": "public"
},
"scripts": {
"test": "vitest run --passWithNoTests --test-timeout 30000 --dir src",
"build": "svelte-package -i src -o dist",
"dev": "svelte-package -w -i src -o dist",
"lint": "eslint ./src --fix",
"format": "prettier ./src --write",
"clean": "rm -rf ./dist ./node_modules"
},
"dependencies": {
"@inlang/paraglide-js-adapter-vite": "workspace:*",
"dedent": "1.5.1",
"devalue": "^4.3.2",
"magic-string": "^0.30.5",
"svelte": "^4.2.8"
},
"peerDependencies": {
"@sveltejs/kit": "^2.4.3"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-virtual": "3.0.1",
"@sveltejs/package": "^2.2.3",
"@sveltejs/vite-plugin-svelte": "^3.0.1",
"prettier-plugin-svelte": "^3.1.2",
"rollup": "3.29.1",
"rollup-plugin-svelte": "^7.1.6",
"typescript": "^5.3.2",
"vite": "^5.0.4",
"vitest": "^0.34.6"
},
"files": [
"dist"
],
"exports": {
".": {
"import": "./dist/runtime/index.js",
"svelte": "./dist/runtime/index.js",
"types": "./dist/runtime/index.d.ts"
},
"./vite": {
"import": "./dist/vite/index.js",
"types": "./dist/vite/index.d.ts"
}
}
"name": "@inlang/paraglide-js-adapter-sveltekit",
"version": "0.5.5",
"type": "module",
"main": "./dist/runtime/index.js",
"types": "./dist/runtime/index.d.ts",
"publishConfig": {
"access": "public"
},
"scripts": {
"test": "vitest run --passWithNoTests --test-timeout 30000 --dir src",
"build": "svelte-package -i src -o dist",
"dev": "svelte-package -w -i src -o dist",
"lint": "eslint ./src --fix",
"format": "prettier ./src --write",
"clean": "rm -rf ./dist ./node_modules"
},
"dependencies": {
"@inlang/paraglide-js-adapter-vite": "workspace:*",
"dedent": "1.5.1",
"devalue": "^4.3.2",
"magic-string": "^0.30.5"
},
"peerDependencies": {
"@sveltejs/kit": "^2.4.3",
"svelte": "^5.0.0 || ^5.0.0-next.1 || ^4.0.0 || ^3.0.0"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-virtual": "3.0.1",
"@sveltejs/package": "^2.2.3",
"@sveltejs/vite-plugin-svelte": "^3.0.2",
"prettier-plugin-svelte": "^3.1.2",
"rollup": "3.29.1",
"rollup-plugin-svelte": "^7.1.6",
"typescript": "^5.3.2",
"vite": "^5.0.4",
"vitest": "^0.34.6"
},
"files": [
"dist"
],
"exports": {
".": {
"import": "./dist/runtime/index.js",
"svelte": "./dist/runtime/index.js",
"types": "./dist/runtime/index.d.ts"
},
"./vite": {
"import": "./dist/vite/index.js",
"types": "./dist/vite/index.d.ts"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import MagicString from "magic-string"
import type { Ast } from "./types.js"
import { shouldApply } from "./precheck.js"
import { rewrite } from "./rewrite.js"
import dedent from "dedent"

export type PreprocessorConfig = Record<string, never>

Expand Down Expand Up @@ -49,7 +50,19 @@ export function preprocessor(_config: PreprocessorConfig): PreprocessorGroup {
if (!shouldApply(content, TRANSLATIONS)) return NOOP

//Parse the file
const ast = parse(content)
let ast: Ast
try {
ast = parse(content)
} catch (error) {
throw new Error(
dedent`
[@inlang/paraglide-js-adapter-sveltekit] Failed to parse ${filename}.
This may be because you are using a signifficantly newer version of the "svelte" package.
Try forcing "@inlang/paraglide-js-adapter-sveltekit" to use your version of "svelte" using pnpm overrides`,
{ cause: error }
)
}

const code = new MagicString(content)

const passResult = rewrite({ ast, code, originalCode: content, translations: TRANSLATIONS })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "**/*.test.ts"],
"exclude": ["node_modules", "**/*.test.ts", "examples"],
"compilerOptions": {
"target": "ESNext",
"outDir": "./dist",
Expand Down
Loading

0 comments on commit 1bff876

Please sign in to comment.