From 27e81f8b82c103a31e58d1c803174909d192006b Mon Sep 17 00:00:00 2001 From: dominikg Date: Sat, 16 Sep 2023 13:25:22 +0200 Subject: [PATCH 01/13] refactor(types): use dts-buddy to generate types with map, cleanup type definitions and tsconfig --- .changeset/many-cows-rescue.md | 5 + .changeset/metal-olives-wait.md | 6 + .github/workflows/ci.yml | 3 + .github/workflows/release.yml | 5 +- .prettierrc.js | 8 +- package.json | 4 +- .../vite-plugin-svelte-inspector/package.json | 10 +- .../vite-plugin-svelte-inspector/src/index.js | 7 +- .../src/options.js | 4 +- .../src/{index.d.ts => public.d.ts} | 5 +- .../tsconfig.json | 10 +- .../types/index.d.ts | 74 +++++++ .../types/index.d.ts.map | 17 ++ packages/vite-plugin-svelte/package.json | 13 +- packages/vite-plugin-svelte/src/index.js | 5 +- packages/vite-plugin-svelte/src/preprocess.js | 13 +- .../src/{index.d.ts => public.d.ts} | 44 +---- .../vite-plugin-svelte/src/types/compile.d.ts | 27 +-- .../vite-plugin-svelte/src/types/log.d.ts | 2 +- .../vite-plugin-svelte/src/types/options.d.ts | 2 +- .../vite-plugin-svelte/src/utils/compile.js | 2 +- .../vite-plugin-svelte/src/utils/esbuild.js | 2 +- packages/vite-plugin-svelte/src/utils/id.js | 4 +- .../src/utils/load-svelte-config.js | 8 +- .../vite-plugin-svelte/src/utils/options.js | 12 +- .../src/utils/preprocess.js | 10 +- packages/vite-plugin-svelte/tsconfig.json | 9 +- packages/vite-plugin-svelte/types/index.d.ts | 187 ++++++++++++++++++ .../vite-plugin-svelte/types/index.d.ts.map | 23 +++ pnpm-lock.yaml | 41 ++++ 30 files changed, 440 insertions(+), 122 deletions(-) create mode 100644 .changeset/many-cows-rescue.md create mode 100644 .changeset/metal-olives-wait.md rename packages/vite-plugin-svelte-inspector/src/{index.d.ts => public.d.ts} (95%) create mode 100644 packages/vite-plugin-svelte-inspector/types/index.d.ts create mode 100644 packages/vite-plugin-svelte-inspector/types/index.d.ts.map rename packages/vite-plugin-svelte/src/{index.d.ts => public.d.ts} (83%) create mode 100644 packages/vite-plugin-svelte/types/index.d.ts create mode 100644 packages/vite-plugin-svelte/types/index.d.ts.map diff --git a/.changeset/many-cows-rescue.md b/.changeset/many-cows-rescue.md new file mode 100644 index 000000000..f85c85f80 --- /dev/null +++ b/.changeset/many-cows-rescue.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/vite-plugin-svelte': major +--- + +breaking: remove package.json export diff --git a/.changeset/metal-olives-wait.md b/.changeset/metal-olives-wait.md new file mode 100644 index 000000000..ed6e42d01 --- /dev/null +++ b/.changeset/metal-olives-wait.md @@ -0,0 +1,6 @@ +--- +'@sveltejs/vite-plugin-svelte-inspector': major +'@sveltejs/vite-plugin-svelte': major +--- + +breaking(types): emit types with dts-buddy to include type map" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 72c978aa0..700188239 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,6 +66,9 @@ jobs: - name: publint if: (${{ success() }} || ${{ failure() }}) run: pnpm check:publint + - name: generated types are up to date + if: (${{ success() }} || ${{ failure() }}) + run: pnpm generate:types && [ "`git status --porcelain=v1`" == "" ] test: timeout-minutes: 10 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ed3c78c5b..f17751cf8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -43,7 +43,10 @@ jobs: cache-dependency-path: '**/pnpm-lock.yaml' - name: install run: pnpm install --frozen-lockfile --prefer-offline --ignore-scripts - + - name: generated types are up to date + run: pnpm generate:types && [ "`git status --porcelain=v1`" == "" ] + - name: publint + run: pnpm check:publint - name: Creating .npmrc run: | cat << EOF > "$HOME/.npmrc" diff --git a/.prettierrc.js b/.prettierrc.js index 81cdfcd4d..aebdedadc 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -14,7 +14,13 @@ module.exports = { options: { parser: 'typescript' } }, { - files: ['**/CHANGELOG.md', '.github/renovate.json5'], + files: [ + '**/CHANGELOG.md', + '.github/renovate.json5', + '**/types/index.d.ts', + '**/types/index.d.ts.map', + '**/pnpm-lock.yaml' + ], options: { requirePragma: true } diff --git a/package.json b/package.json index c6ae2e859..73195b4eb 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ "fixup": "run-s lint format", "release": "pnpm changeset publish", "prepare": "husky install", - "playwright": "playwright-core" + "playwright": "playwright-core", + "generate:types": "pnpm --filter \"./packages/*\" --parallel generate:types" }, "devDependencies": { "@changesets/cli": "^2.26.2", @@ -27,6 +28,7 @@ "@typescript-eslint/eslint-plugin": "^6.7.0", "@typescript-eslint/parser": "^6.7.0", "cross-env": "^7.0.3", + "dts-buddy": "^0.2.4", "eslint": "^8.49.0", "eslint-config-prettier": "^9.0.0", "eslint-plugin-html": "^7.1.0", diff --git a/packages/vite-plugin-svelte-inspector/package.json b/packages/vite-plugin-svelte-inspector/package.json index 4f98402ca..f516a723a 100644 --- a/packages/vite-plugin-svelte-inspector/package.json +++ b/packages/vite-plugin-svelte-inspector/package.json @@ -4,19 +4,21 @@ "license": "MIT", "author": "dominikg", "files": [ - "src" + "src", + "types" ], "type": "module", - "types": "src/index.d.ts", + "types": "types/index.d.ts", "exports": { ".": { - "types": "./src/index.d.ts", + "types": "./types/index.d.ts", "import": "./src/index.js" } }, "scripts": { "check:publint": "publint --strict", - "check:types": "tsc --noEmit" + "check:types": "tsc --noEmit", + "generate:types": "dts-buddy" }, "engines": { "node": "^18.0.0 || >=20" diff --git a/packages/vite-plugin-svelte-inspector/src/index.js b/packages/vite-plugin-svelte-inspector/src/index.js index 0ed33e514..2bad08995 100644 --- a/packages/vite-plugin-svelte-inspector/src/index.js +++ b/packages/vite-plugin-svelte-inspector/src/index.js @@ -14,14 +14,17 @@ function getInspectorPath() { ); } -/** @type {import('.').svelteInspector} */ +/** + * @param {Partial} [options] + * @returns {import('vite').Plugin} + */ export function svelteInspector(options) { const inspectorPath = getInspectorPath(); debug(`svelte inspector path: ${inspectorPath}`); /** @type {import('vite').ResolvedConfig} */ let viteConfig; - /** @type {import('.').Options} */ + /** @type {import('./public.js').Options} */ let inspectorOptions; let disabled = false; diff --git a/packages/vite-plugin-svelte-inspector/src/options.js b/packages/vite-plugin-svelte-inspector/src/options.js index 9283df9b0..370214727 100644 --- a/packages/vite-plugin-svelte-inspector/src/options.js +++ b/packages/vite-plugin-svelte-inspector/src/options.js @@ -1,7 +1,7 @@ import { loadEnv } from 'vite'; import { debug } from './debug.js'; -/** @type {import('.').Options} */ +/** @type {import('./public.js').Options} */ export const defaultInspectorOptions = { toggleKeyCombo: process.platform === 'darwin' ? 'meta-shift' : 'control-shift', navKeys: { parent: 'ArrowUp', child: 'ArrowDown', next: 'ArrowRight', prev: 'ArrowLeft' }, @@ -14,7 +14,7 @@ export const defaultInspectorOptions = { /** * @param {import('vite').ResolvedConfig} config - * @returns {Partial | boolean | void} + * @returns {Partial | boolean | void} */ export function parseEnvironmentOptions(config) { const env = loadEnv(config.mode, config.envDir ?? process.cwd(), 'SVELTE_INSPECTOR'); diff --git a/packages/vite-plugin-svelte-inspector/src/index.d.ts b/packages/vite-plugin-svelte-inspector/src/public.d.ts similarity index 95% rename from packages/vite-plugin-svelte-inspector/src/index.d.ts rename to packages/vite-plugin-svelte-inspector/src/public.d.ts index b5c2ce28b..95983a2f1 100644 --- a/packages/vite-plugin-svelte-inspector/src/index.d.ts +++ b/packages/vite-plugin-svelte-inspector/src/public.d.ts @@ -1,5 +1,3 @@ -import type { Plugin } from 'vite'; - export interface Options { /** * define a key combo to toggle inspector, @@ -63,11 +61,10 @@ export interface Options { /** * internal options that are automatically set, not to be set or used by users + * @internal */ __internal?: { // vite base url base: string; }; } - -export declare function svelteInspector(options?: Options): Plugin; diff --git a/packages/vite-plugin-svelte-inspector/tsconfig.json b/packages/vite-plugin-svelte-inspector/tsconfig.json index 53b8c64ae..90b557e70 100644 --- a/packages/vite-plugin-svelte-inspector/tsconfig.json +++ b/packages/vite-plugin-svelte-inspector/tsconfig.json @@ -1,21 +1,17 @@ { "include": ["src"], - "exclude": ["**/*.spec.ts"], "compilerOptions": { "noEmit": true, "target": "ES2020", - "module": "ES2020", + "module": "ES2022", "moduleResolution": "node", "strict": true, - "declaration": true, - "sourceMap": true, "noUnusedLocals": true, - "esModuleInterop": true, "baseUrl": ".", - "resolveJsonModule": true, // see https://devblogs.microsoft.com/typescript/announcing-typescript-4-4-beta/#use-unknown-catch-variables "useUnknownInCatchVariables": false, "allowJs": true, - "checkJs": true + "checkJs": true, + "allowSyntheticDefaultImports": true } } diff --git a/packages/vite-plugin-svelte-inspector/types/index.d.ts b/packages/vite-plugin-svelte-inspector/types/index.d.ts new file mode 100644 index 000000000..bc86ccf3e --- /dev/null +++ b/packages/vite-plugin-svelte-inspector/types/index.d.ts @@ -0,0 +1,74 @@ +declare module '@sveltejs/vite-plugin-svelte-inspector' { + export function svelteInspector(options?: Partial | undefined): import('vite').Plugin; + interface Options { + /** + * define a key combo to toggle inspector, + * @default 'meta-shift' on mac, 'control-shift' on other os + * + * any number of modifiers `control` `shift` `alt` `meta` followed by zero or one regular key, separated by - + * examples: control-shift, control-o, control-alt-s meta-x control-meta + * Some keys have native behavior (e.g. alt-s opens history menu on firefox). + * To avoid conflicts or accidentally typing into inputs, modifier only combinations are recommended. + */ + toggleKeyCombo?: string; + + /** + * define keys to select elements with via keyboard + * @default {parent: 'ArrowUp', child: 'ArrowDown', next: 'ArrowRight', prev: 'ArrowLeft' } + * + * improves accessibility and also helps when you want to select elements that do not have a hoverable surface area + * due to tight wrapping + * + * A note for users of screen-readers: + * If you are using arrow keys to navigate the page itself, change the navKeys to avoid conflicts. + * e.g. navKeys: {parent: 'w', prev: 'a', child: 's', next: 'd'} + * + * + * parent: select closest parent + * child: select first child (or grandchild) + * next: next sibling (or parent if no next sibling exists) + * prev: previous sibling (or parent if no prev sibling exists) + */ + navKeys?: { parent: string; child: string; next: string; prev: string }; + + /** + * define key to open the editor for the currently selected dom node + * + * @default 'Enter' + */ + openKey?: string; + + /** + * inspector is automatically disabled when releasing toggleKeyCombo after holding it for a longpress + * @default true + */ + holdMode?: boolean; + + /** + * when to show the toggle button + * @default 'active' + */ + showToggleButton?: 'always' | 'active' | 'never'; + + /** + * where to display the toggle button + * @default top-right + */ + toggleButtonPos?: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left'; + + /** + * inject custom styles when inspector is active + */ + customStyles?: boolean; + + /** + * internal options that are automatically set, not to be set or used by users + * */ + __internal?: { + // vite base url + base: string; + }; + } +} + +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/packages/vite-plugin-svelte-inspector/types/index.d.ts.map b/packages/vite-plugin-svelte-inspector/types/index.d.ts.map new file mode 100644 index 000000000..956d409be --- /dev/null +++ b/packages/vite-plugin-svelte-inspector/types/index.d.ts.map @@ -0,0 +1,17 @@ +{ + "version": 3, + "file": "index.d.ts", + "names": [ + "svelteInspector", + "Options" + ], + "sources": [ + "../src/index.js", + "../src/public.d.ts" + ], + "sourcesContent": [ + null, + null + ], + "mappings": ";iBAoBgBA,eAAeA;WCpBdC,OAAOA" +} \ No newline at end of file diff --git a/packages/vite-plugin-svelte/package.json b/packages/vite-plugin-svelte/package.json index 7ad422a83..6c4f28e58 100644 --- a/packages/vite-plugin-svelte/package.json +++ b/packages/vite-plugin-svelte/package.json @@ -4,20 +4,21 @@ "license": "MIT", "author": "dominikg", "files": [ - "src" + "src", + "types" ], "type": "module", - "types": "src/index.d.ts", + "types": "types/index.d.ts", "exports": { ".": { - "types": "./src/index.d.ts", + "types": "./types/index.d.ts", "import": "./src/index.js" - }, - "./package.json": "./package.json" + } }, "scripts": { "check:publint": "publint --strict", - "check:types": "tsc --noEmit" + "check:types": "tsc --noEmit", + "generate:types": "dts-buddy" }, "engines": { "node": "^18.0.0 || >=20" diff --git a/packages/vite-plugin-svelte/src/index.js b/packages/vite-plugin-svelte/src/index.js index f4a9f2daf..340f3fc74 100644 --- a/packages/vite-plugin-svelte/src/index.js +++ b/packages/vite-plugin-svelte/src/index.js @@ -20,7 +20,10 @@ import { saveSvelteMetadata } from './utils/optimizer.js'; import { VitePluginSvelteCache } from './utils/vite-plugin-svelte-cache.js'; import { loadRaw } from './utils/load-raw.js'; -/** @type {import('./index.d.ts').svelte} */ +/** + * @param {Partial} [inlineOptions] + * @returns {import('vite').Plugin[]} + */ export function svelte(inlineOptions) { if (process.env.DEBUG != null) { log.setLevel('debug'); diff --git a/packages/vite-plugin-svelte/src/preprocess.js b/packages/vite-plugin-svelte/src/preprocess.js index ca0da948b..fe2fb56c1 100644 --- a/packages/vite-plugin-svelte/src/preprocess.js +++ b/packages/vite-plugin-svelte/src/preprocess.js @@ -10,9 +10,12 @@ const supportedScriptLangs = ['ts']; export const lang_sep = '.vite-preprocess.'; -/** @type {import('./index.d.ts').vitePreprocess} */ +/** + * @param {import('./public.d.ts').VitePreprocessOptions} opts + * @returns {import('svelte/compiler').PreprocessorGroup} + */ export function vitePreprocess(opts) { - /** @type {import('svelte/types/compiler/preprocess').PreprocessorGroup} */ + /** @type {import('svelte/compiler').PreprocessorGroup} */ const preprocessor = {}; if (opts?.script !== false) { preprocessor.script = viteScript().script; @@ -25,7 +28,7 @@ export function vitePreprocess(opts) { } /** - * @returns {{ script: import('svelte/types/compiler/preprocess').Preprocessor }} + * @returns {{ script: import('svelte/compiler').Preprocessor }} */ function viteScript() { return { @@ -56,12 +59,12 @@ function viteScript() { /** * @param {import('vite').ResolvedConfig | import('vite').InlineConfig} config - * @returns {{ style: import('svelte/types/compiler/preprocess').Preprocessor }} + * @returns {{ style: import('svelte/compiler').Preprocessor }} */ function viteStyle(config = {}) { /** @type {CssTransform} */ let transform; - /** @type {import('svelte/types/compiler/preprocess').Preprocessor} */ + /** @type {import('svelte/compiler').Preprocessor} */ const style = async ({ attributes, content, filename = '' }) => { const lang = /** @type {string} */ (attributes.lang); if (!supportedStyleLangs.includes(lang)) return; diff --git a/packages/vite-plugin-svelte/src/index.d.ts b/packages/vite-plugin-svelte/src/public.d.ts similarity index 83% rename from packages/vite-plugin-svelte/src/index.d.ts rename to packages/vite-plugin-svelte/src/public.d.ts index 52feb0a4b..a1b40fea6 100644 --- a/packages/vite-plugin-svelte/src/index.d.ts +++ b/packages/vite-plugin-svelte/src/public.d.ts @@ -1,11 +1,12 @@ -import type { InlineConfig, ResolvedConfig, UserConfig, Plugin } from 'vite'; -import type { CompileOptions, Warning } from 'svelte/types/compiler/interfaces'; -import type { PreprocessorGroup } from 'svelte/types/compiler/preprocess'; +import type { InlineConfig, ResolvedConfig } from 'vite'; +import type { CompileOptions } from 'svelte/compiler'; +import type { Warning } from 'svelte/types/compiler/interfaces'; +import type { PreprocessorGroup } from 'svelte/compiler'; import type { Options as InspectorOptions } from '@sveltejs/vite-plugin-svelte-inspector'; type Options = Omit & PluginOptionsInline; -interface PluginOptionsInline extends PluginOptions { +export interface PluginOptionsInline extends PluginOptions { /** * Path to a svelte config file, either absolute or relative to Vite root * @@ -172,8 +173,6 @@ interface ExperimentalOptions { disableSvelteResolveWarnings?: boolean; } -type ModuleFormat = NonNullable<'esm'>; -type CssHashGetter = NonNullable; type Arrayable = T | T[]; interface VitePreprocessOptions { @@ -181,35 +180,4 @@ interface VitePreprocessOptions { style?: boolean | InlineConfig | ResolvedConfig; } -declare function vitePreprocess(opts?: VitePreprocessOptions): PreprocessorGroup; - -declare function loadSvelteConfig( - viteConfig?: UserConfig, - inlineOptions?: Partial -): Promise | undefined>; - -declare function svelte(inlineOptions?: Partial): Plugin[]; - -export { - Arrayable, - CssHashGetter, - ModuleFormat, - Options, - PluginOptions, - SvelteOptions, - loadSvelteConfig, - svelte, - VitePreprocessOptions, - vitePreprocess -}; - -// reexported types - -export { CompileOptions, Warning } from 'svelte/types/compiler/interfaces'; - -export { - MarkupPreprocessor, - Preprocessor, - PreprocessorGroup, - Processed -} from 'svelte/types/compiler/preprocess'; +export { Arrayable, Options, PluginOptions, SvelteOptions, VitePreprocessOptions }; diff --git a/packages/vite-plugin-svelte/src/types/compile.d.ts b/packages/vite-plugin-svelte/src/types/compile.d.ts index 64d3e04e8..d6ba48e0f 100644 --- a/packages/vite-plugin-svelte/src/types/compile.d.ts +++ b/packages/vite-plugin-svelte/src/types/compile.d.ts @@ -1,4 +1,4 @@ -import type { Processed } from 'svelte/types/compiler/preprocess'; +import type { Processed, CompileResult } from 'svelte/compiler'; import type { SvelteRequest } from './id.d.ts'; import type { ResolvedOptions } from './options.d.ts'; @@ -14,34 +14,11 @@ export interface Code { dependencies?: any[]; } -export interface Compiled { - js: Code; - css: Code; - ast: any; // TODO type - warnings: any[]; // TODO type - vars: Array<{ - name: string; - export_name: string; - injected: boolean; - module: boolean; - mutated: boolean; - reassigned: boolean; - referenced: boolean; - writable: boolean; - referenced_from_script: boolean; - }>; - stats: { - timings: { - total: number; - }; - }; -} - export interface CompileData { filename: string; normalizedFilename: string; lang: string; - compiled: Compiled; + compiled: CompileResult; ssr: boolean | undefined; dependencies: string[]; preprocessed: Processed; diff --git a/packages/vite-plugin-svelte/src/types/log.d.ts b/packages/vite-plugin-svelte/src/types/log.d.ts index 9c1153c0b..ee712fb69 100644 --- a/packages/vite-plugin-svelte/src/types/log.d.ts +++ b/packages/vite-plugin-svelte/src/types/log.d.ts @@ -1,4 +1,4 @@ -import type { Warning } from '../index.d.ts'; +import type { Warning } from 'svelte/types/compiler/interfaces'; export interface LogFn extends SimpleLogFn { (message: string, payload?: any, namespace?: string): void; diff --git a/packages/vite-plugin-svelte/src/types/options.d.ts b/packages/vite-plugin-svelte/src/types/options.d.ts index 3b52dae5d..ec32b9eb6 100644 --- a/packages/vite-plugin-svelte/src/types/options.d.ts +++ b/packages/vite-plugin-svelte/src/types/options.d.ts @@ -1,7 +1,7 @@ import type { CompileOptions } from 'svelte/types/compiler/interfaces'; import type { ViteDevServer } from 'vite'; import { VitePluginSvelteStats } from '../utils/vite-plugin-svelte-stats.js'; -import type { Options } from '../index.d.ts'; +import type { Options } from '../public.d.ts'; export interface PreResolvedOptions extends Options { // these options are non-nullable after resolve diff --git a/packages/vite-plugin-svelte/src/utils/compile.js b/packages/vite-plugin-svelte/src/utils/compile.js index 943079eec..07b035787 100644 --- a/packages/vite-plugin-svelte/src/utils/compile.js +++ b/packages/vite-plugin-svelte/src/utils/compile.js @@ -47,7 +47,7 @@ export const _createCompileSvelte = (makeHot) => { // also they for hmr updates too } } - /** @type {import('../index.d.ts').CompileOptions} */ + /** @type {import('svelte/compiler').CompileOptions} */ const compileOptions = { ...options.compilerOptions, filename, diff --git a/packages/vite-plugin-svelte/src/utils/esbuild.js b/packages/vite-plugin-svelte/src/utils/esbuild.js index aeae29fb5..f8966cf5b 100644 --- a/packages/vite-plugin-svelte/src/utils/esbuild.js +++ b/packages/vite-plugin-svelte/src/utils/esbuild.js @@ -59,7 +59,7 @@ async function compileSvelte(options, { filename, code }, statsCollection) { // TODO ideally we'd be able to externalize prebundled styles too, but for now always put them in the js css = 'injected'; } - /** @type {import('../index.d.ts').CompileOptions} */ + /** @type {import('svelte/compiler').CompileOptions} */ const compileOptions = { ...options.compilerOptions, css, diff --git a/packages/vite-plugin-svelte/src/utils/id.js b/packages/vite-plugin-svelte/src/utils/id.js index ee7a719d3..8aaa3bdbc 100644 --- a/packages/vite-plugin-svelte/src/utils/id.js +++ b/packages/vite-plugin-svelte/src/utils/id.js @@ -159,8 +159,8 @@ function stripRoot(normalizedFilename, normalizedRoot) { } /** - * @param {import('../index.d.ts').Arrayable | undefined} include - * @param {import('../index.d.ts').Arrayable | undefined} exclude + * @param {import('../public.d.ts').Arrayable | undefined} include + * @param {import('../public.d.ts').Arrayable | undefined} exclude * @param {string[]} extensions * @returns {(filename: string) => boolean} */ diff --git a/packages/vite-plugin-svelte/src/utils/load-svelte-config.js b/packages/vite-plugin-svelte/src/utils/load-svelte-config.js index 8f3896460..d65205d54 100644 --- a/packages/vite-plugin-svelte/src/utils/load-svelte-config.js +++ b/packages/vite-plugin-svelte/src/utils/load-svelte-config.js @@ -25,7 +25,11 @@ const dynamicImportDefault = new Function( 'return import(path + "?t=" + timestamp).then(m => m.default)' ); -/** @type {import('../index.d.ts').loadSvelteConfig} */ +/** + * @param {import('vite').UserConfig} viteConfig + * @param {Partial} inlineOptions + * @returns {Promise | undefined>} + */ export async function loadSvelteConfig(viteConfig, inlineOptions) { if (inlineOptions?.configFile === false) { return; @@ -86,7 +90,7 @@ export async function loadSvelteConfig(viteConfig, inlineOptions) { /** * @param {import('vite').UserConfig | undefined} viteConfig - * @param {Partial | undefined} inlineOptions + * @param {Partial | undefined} inlineOptions * @returns {string | undefined} */ function findConfigToLoad(viteConfig, inlineOptions) { diff --git a/packages/vite-plugin-svelte/src/utils/options.js b/packages/vite-plugin-svelte/src/utils/options.js index aaf0c0390..2b559b897 100644 --- a/packages/vite-plugin-svelte/src/utils/options.js +++ b/packages/vite-plugin-svelte/src/utils/options.js @@ -44,7 +44,7 @@ const knownRootOptions = new Set(['extensions', 'compilerOptions', 'preprocess', const allowedInlineOptions = new Set(['configFile', ...allowedPluginOptions, ...knownRootOptions]); /** - * @param {Partial} [inlineOptions] + * @param {Partial} [inlineOptions] */ export function validateInlineOptions(inlineOptions) { const invalidKeys = Object.keys(inlineOptions || {}).filter( @@ -56,8 +56,8 @@ export function validateInlineOptions(inlineOptions) { } /** - * @param {Partial} [config] - * @returns {Partial | undefined} + * @param {Partial} [config] + * @returns {Partial | undefined} */ function convertPluginOptions(config) { if (!config) { @@ -107,7 +107,7 @@ function convertPluginOptions(config) { delete pluginOptions[unkownOption]; }); } - /** @type {import('../index.d.ts').Options} */ + /** @type {import('../public.d.ts').Options} */ const result = { ...config, ...pluginOptions @@ -120,7 +120,7 @@ function convertPluginOptions(config) { /** * used in config phase, merges the default options, svelte config, and inline options - * @param {Partial | undefined} inlineOptions + * @param {Partial | undefined} inlineOptions * @param {import('vite').UserConfig} viteUserConfig * @param {import('vite').ConfigEnv} viteEnv * @returns {Promise} @@ -190,7 +190,7 @@ function mergeConfigs(...configs) { */ export function resolveOptions(preResolveOptions, viteConfig, cache) { const css = preResolveOptions.emitCss ? 'external' : 'injected'; - /** @type {Partial} */ + /** @type {Partial} */ const defaultOptions = { hot: viteConfig.isProduction ? false diff --git a/packages/vite-plugin-svelte/src/utils/preprocess.js b/packages/vite-plugin-svelte/src/utils/preprocess.js index 7696f7e93..37833c299 100644 --- a/packages/vite-plugin-svelte/src/utils/preprocess.js +++ b/packages/vite-plugin-svelte/src/utils/preprocess.js @@ -8,7 +8,7 @@ import path from 'node:path'; * * only used during dev with enabled css hmr * - * @returns {import('svelte/types/compiler/preprocess').PreprocessorGroup} + * @returns {import('svelte/compiler').PreprocessorGroup} */ export function createInjectScopeEverythingRulePreprocessorGroup() { return { @@ -30,14 +30,14 @@ export function createInjectScopeEverythingRulePreprocessorGroup() { * @param {import('../types/options.d.ts').ResolvedOptions} options * @param {import('vite').ResolvedConfig} config * @returns {{ - * prependPreprocessors: import('svelte/types/compiler/preprocess').PreprocessorGroup[], - * appendPreprocessors: import('svelte/types/compiler/preprocess').PreprocessorGroup[] + * prependPreprocessors: import('svelte/compiler').PreprocessorGroup[], + * appendPreprocessors: import('svelte/compiler').PreprocessorGroup[] * }} */ function buildExtraPreprocessors(options, config) { - /** @type {import('svelte/types/compiler/preprocess').PreprocessorGroup[]} */ + /** @type {import('svelte/compiler').PreprocessorGroup[]} */ const prependPreprocessors = []; - /** @type {import('svelte/types/compiler/preprocess').PreprocessorGroup[]} */ + /** @type {import('svelte/compiler').PreprocessorGroup[]} */ const appendPreprocessors = []; // @ts-ignore diff --git a/packages/vite-plugin-svelte/tsconfig.json b/packages/vite-plugin-svelte/tsconfig.json index 53b8c64ae..753c44ebb 100644 --- a/packages/vite-plugin-svelte/tsconfig.json +++ b/packages/vite-plugin-svelte/tsconfig.json @@ -1,21 +1,18 @@ { "include": ["src"], - "exclude": ["**/*.spec.ts"], "compilerOptions": { "noEmit": true, "target": "ES2020", - "module": "ES2020", + "module": "ES2022", "moduleResolution": "node", "strict": true, - "declaration": true, - "sourceMap": true, "noUnusedLocals": true, - "esModuleInterop": true, "baseUrl": ".", "resolveJsonModule": true, // see https://devblogs.microsoft.com/typescript/announcing-typescript-4-4-beta/#use-unknown-catch-variables "useUnknownInCatchVariables": false, "allowJs": true, - "checkJs": true + "checkJs": true, + "allowSyntheticDefaultImports": true } } diff --git a/packages/vite-plugin-svelte/types/index.d.ts b/packages/vite-plugin-svelte/types/index.d.ts new file mode 100644 index 000000000..7996b2feb --- /dev/null +++ b/packages/vite-plugin-svelte/types/index.d.ts @@ -0,0 +1,187 @@ +declare module '@sveltejs/vite-plugin-svelte' { + import type { InlineConfig, ResolvedConfig } from 'vite'; + import type { CompileOptions, PreprocessorGroup } from 'svelte/compiler'; + import type { Warning } from 'svelte/types/compiler/interfaces'; + import type { Options as InspectorOptions } from '@sveltejs/vite-plugin-svelte-inspector'; + export function svelte(inlineOptions?: Partial | undefined): import('vite').Plugin[]; + type Options = Omit & PluginOptionsInline; + + interface PluginOptionsInline extends PluginOptions { + /** + * Path to a svelte config file, either absolute or relative to Vite root + * + * set to `false` to ignore the svelte config file + * + * @see https://vitejs.dev/config/#root + */ + configFile?: string | false; + } + + interface PluginOptions { + /** + * A `picomatch` pattern, or array of patterns, which specifies the files the plugin should + * operate on. By default, all svelte files are included. + * + * @see https://github.com/micromatch/picomatch + */ + include?: Arrayable; + /** + * A `picomatch` pattern, or array of patterns, which specifies the files to be ignored by the + * plugin. By default, no files are ignored. + * + * @see https://github.com/micromatch/picomatch + */ + exclude?: Arrayable; + /** + * Emit Svelte styles as virtual CSS files for Vite and other plugins to process + * + * @default true + */ + emitCss?: boolean; + /** + * Enable or disable Hot Module Replacement. + * + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * + * DO NOT CUSTOMIZE SVELTE-HMR OPTIONS UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING + * + * YOU HAVE BEEN WARNED + * + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * + * Set an object to pass custom options to svelte-hmr + * + * @see https://github.com/rixo/svelte-hmr#options + * @default true for development, always false for production + */ + hot?: + | boolean + | { + injectCss?: boolean; + partialAccept?: boolean; + [key: string]: any; + }; + /** + * Some Vite plugins can contribute additional preprocessors by defining `api.sveltePreprocess`. + * If you don't want to use them, set this to true to ignore them all or use an array of strings + * with plugin names to specify which. + * + * @default false + */ + ignorePluginPreprocessors?: boolean | string[]; + /** + * vite-plugin-svelte automatically handles excluding svelte libraries and reinclusion of their dependencies + * in vite.optimizeDeps. + * + * `disableDependencyReinclusion: true` disables all reinclusions + * `disableDependencyReinclusion: ['foo','bar']` disables reinclusions for dependencies of foo and bar + * + * This should be used for hybrid packages that contain both node and browser dependencies, eg Routify + * + * @default false + */ + disableDependencyReinclusion?: boolean | string[]; + /** + * Enable support for Vite's dependency optimization to prebundle Svelte libraries. + * + * To disable prebundling for a specific library, add it to `optimizeDeps.exclude`. + * + * @default true for dev, false for build + */ + prebundleSvelteLibraries?: boolean; + /** + * toggle/configure Svelte Inspector + * + * @default unset for dev, always false for build + */ + inspector?: InspectorOptions | boolean; + /** + * These options are considered experimental and breaking changes to them can occur in any release + */ + experimental?: ExperimentalOptions; + } + + interface SvelteOptions { + /** + * A list of file extensions to be compiled by Svelte + * + * @default ['.svelte'] + */ + extensions?: string[]; + /** + * An array of preprocessors to transform the Svelte source code before compilation + * + * @see https://svelte.dev/docs#svelte_preprocess + */ + preprocess?: Arrayable; + /** + * The options to be passed to the Svelte compiler. A few options are set by default, + * including `dev` and `css`. However, some options are non-configurable, like + * `filename`, `format`, `generate`, and `cssHash` (in dev). + * + * @see https://svelte.dev/docs#svelte_compile + */ + compilerOptions?: Omit; + /** + * Handles warning emitted from the Svelte compiler + */ + onwarn?: (warning: Warning, defaultHandler?: (warning: Warning) => void) => void; + /** + * Options for vite-plugin-svelte + */ + vitePlugin?: PluginOptions; + } + + /** + * These options are considered experimental and breaking changes to them can occur in any release + */ + interface ExperimentalOptions { + /** + * A function to update `compilerOptions` before compilation + * + * `data.filename` - The file to be compiled + * `data.code` - The preprocessed Svelte code + * `data.compileOptions` - The current compiler options + * + * To change part of the compiler options, return an object with the changes you need. + * + * @example + * ``` + * ({ filename, compileOptions }) => { + * // Dynamically set hydration per Svelte file + * if (compileWithHydratable(filename) && !compileOptions.hydratable) { + * return { hydratable: true }; + * } + * } + * ``` + */ + dynamicCompileOptions?: (data: { + filename: string; + code: string; + compileOptions: Partial; + }) => Promise | void> | Partial | void; + /** + * send a websocket message with svelte compiler warnings during dev + * + */ + sendWarningsToBrowser?: boolean; + /** + * disable svelte field resolve warnings + * + * @default false + */ + disableSvelteResolveWarnings?: boolean; + } + + + type Arrayable = T | T[]; + + interface VitePreprocessOptions { + script?: boolean; + style?: boolean | InlineConfig | ResolvedConfig; + } + export function vitePreprocess(opts: VitePreprocessOptions): import('svelte/compiler').PreprocessorGroup; + export function loadSvelteConfig(viteConfig: import('vite').UserConfig, inlineOptions: Partial): Promise | undefined>; +} + +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/packages/vite-plugin-svelte/types/index.d.ts.map b/packages/vite-plugin-svelte/types/index.d.ts.map new file mode 100644 index 000000000..6547c0a03 --- /dev/null +++ b/packages/vite-plugin-svelte/types/index.d.ts.map @@ -0,0 +1,23 @@ +{ + "version": 3, + "file": "index.d.ts", + "names": [ + "svelte", + "PluginOptionsInline", + "vitePreprocess", + "loadSvelteConfig" + ], + "sources": [ + "../src/index.js", + "../src/public.d.ts", + "../src/preprocess.js", + "../src/utils/load-svelte-config.js" + ], + "sourcesContent": [ + null, + null, + null, + null + ], + "mappings": ";;;;;iBA0BgBA,MAAMA;;;WChBLC,mBAAmBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCMpBC,cAAcA;iBCgBRC,gBAAgBA" +} \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 49418ec95..83abe3d1e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -36,6 +36,9 @@ importers: cross-env: specifier: ^7.0.3 version: 7.0.3 + dts-buddy: + specifier: ^0.2.4 + version: 0.2.4 eslint: specifier: ^8.49.0 version: 8.49.0 @@ -1539,6 +1542,13 @@ packages: resolution: {integrity: sha512-xnkseuNADM0gt2bs+BvhO0p78Mk762YnZdsuzFV018NoG1Sj1SCQvpSqa7XUaTam5vAGasABV9qXASMKnFMwMw==} engines: {node: '>=6.0.0'} + /@jridgewell/source-map@0.3.5: + resolution: {integrity: sha512-UTYAUj/wviwdsMfzoSJspJxbkH5o1snzwX0//0ENX1u/55kkZZkcTZP6u9bwKGkv+dkk9at4m1Cpt0uY80kcpQ==} + dependencies: + '@jridgewell/gen-mapping': 0.3.3 + '@jridgewell/trace-mapping': 0.3.19 + dev: true + /@jridgewell/sourcemap-codec@1.4.15: resolution: {integrity: sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==} @@ -2850,6 +2860,22 @@ packages: engines: {node: '>=12'} dev: true + /dts-buddy@0.2.4: + resolution: {integrity: sha512-41d7aGv2DXJYlzeKSKHf0GtpCC8OdpEHhz+aqjylKV5aP3fl4APzNmQ5hL5vSKZMaO/lrkrKWC+HQrxl+mcgUw==} + hasBin: true + dependencies: + '@jridgewell/source-map': 0.3.5 + '@jridgewell/sourcemap-codec': 1.4.15 + globrex: 0.1.2 + kleur: 4.1.5 + locate-character: 3.0.0 + magic-string: 0.30.3 + sade: 1.8.1 + tiny-glob: 0.2.9 + ts-api-utils: 1.0.3(typescript@5.0.4) + typescript: 5.0.4 + dev: true + /eastasianwidth@0.2.0: resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} dev: true @@ -6103,6 +6129,15 @@ packages: engines: {node: '>=8'} dev: true + /ts-api-utils@1.0.3(typescript@5.0.4): + resolution: {integrity: sha512-wNMeqtMz5NtwpT/UZGY5alT+VoKdSsOOP/kqHFcUW1P/VRhH2wJ48+DN2WwUliNbQ976ETwDL0Ifd2VVvgonvg==} + engines: {node: '>=16.13.0'} + peerDependencies: + typescript: '>=4.2.0' + dependencies: + typescript: 5.0.4 + dev: true + /ts-api-utils@1.0.3(typescript@5.2.2): resolution: {integrity: sha512-wNMeqtMz5NtwpT/UZGY5alT+VoKdSsOOP/kqHFcUW1P/VRhH2wJ48+DN2WwUliNbQ976ETwDL0Ifd2VVvgonvg==} engines: {node: '>=16.13.0'} @@ -6226,6 +6261,12 @@ packages: hasBin: true dev: true + /typescript@5.0.4: + resolution: {integrity: sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==} + engines: {node: '>=12.20'} + hasBin: true + dev: true + /typescript@5.2.2: resolution: {integrity: sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==} engines: {node: '>=14.17'} From b6f31dd93c6aa3d558fe30f51b63c565199e4ec2 Mon Sep 17 00:00:00 2001 From: dominikg Date: Sat, 16 Sep 2023 13:33:44 +0200 Subject: [PATCH 02/13] chore: update generated types --- packages/vite-plugin-svelte/types/index.d.ts | 1 - packages/vite-plugin-svelte/types/index.d.ts.map | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/vite-plugin-svelte/types/index.d.ts b/packages/vite-plugin-svelte/types/index.d.ts index 7996b2feb..a12f4da56 100644 --- a/packages/vite-plugin-svelte/types/index.d.ts +++ b/packages/vite-plugin-svelte/types/index.d.ts @@ -173,7 +173,6 @@ declare module '@sveltejs/vite-plugin-svelte' { disableSvelteResolveWarnings?: boolean; } - type Arrayable = T | T[]; interface VitePreprocessOptions { diff --git a/packages/vite-plugin-svelte/types/index.d.ts.map b/packages/vite-plugin-svelte/types/index.d.ts.map index 6547c0a03..0aa46cbe2 100644 --- a/packages/vite-plugin-svelte/types/index.d.ts.map +++ b/packages/vite-plugin-svelte/types/index.d.ts.map @@ -19,5 +19,5 @@ null, null ], - "mappings": ";;;;;iBA0BgBA,MAAMA;;;WChBLC,mBAAmBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCMpBC,cAAcA;iBCgBRC,gBAAgBA" + "mappings": ";;;;;iBA0BgBA,MAAMA;;;WClBLC,mBAAmBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCQpBC,cAAcA;iBCgBRC,gBAAgBA" } \ No newline at end of file From 415c9073532cae04b9522c95489aed430ad90506 Mon Sep 17 00:00:00 2001 From: dominikg Date: Sat, 16 Sep 2023 13:41:38 +0200 Subject: [PATCH 03/13] fix: use .d.ts for type imports --- packages/vite-plugin-svelte-inspector/src/index.js | 2 +- packages/vite-plugin-svelte-inspector/src/options.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/vite-plugin-svelte-inspector/src/index.js b/packages/vite-plugin-svelte-inspector/src/index.js index 2bad08995..1f2e6ca4c 100644 --- a/packages/vite-plugin-svelte-inspector/src/index.js +++ b/packages/vite-plugin-svelte-inspector/src/index.js @@ -24,7 +24,7 @@ export function svelteInspector(options) { /** @type {import('vite').ResolvedConfig} */ let viteConfig; - /** @type {import('./public.js').Options} */ + /** @type {import('./public.d.ts').Options} */ let inspectorOptions; let disabled = false; diff --git a/packages/vite-plugin-svelte-inspector/src/options.js b/packages/vite-plugin-svelte-inspector/src/options.js index 370214727..d53561520 100644 --- a/packages/vite-plugin-svelte-inspector/src/options.js +++ b/packages/vite-plugin-svelte-inspector/src/options.js @@ -1,7 +1,7 @@ import { loadEnv } from 'vite'; import { debug } from './debug.js'; -/** @type {import('./public.js').Options} */ +/** @type {import('./public.d.ts').Options} */ export const defaultInspectorOptions = { toggleKeyCombo: process.platform === 'darwin' ? 'meta-shift' : 'control-shift', navKeys: { parent: 'ArrowUp', child: 'ArrowDown', next: 'ArrowRight', prev: 'ArrowLeft' }, @@ -14,7 +14,7 @@ export const defaultInspectorOptions = { /** * @param {import('vite').ResolvedConfig} config - * @returns {Partial | boolean | void} + * @returns {Partial | boolean | void} */ export function parseEnvironmentOptions(config) { const env = loadEnv(config.mode, config.envDir ?? process.cwd(), 'SVELTE_INSPECTOR'); From 106ee52b9ef124dc7f5d8daa55c2397431db999e Mon Sep 17 00:00:00 2001 From: dominikg Date: Sat, 16 Sep 2023 14:44:25 +0200 Subject: [PATCH 04/13] fix: ignore .changesets/pre.json to prevent format check fails on main after release merge --- .prettierrc.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.prettierrc.js b/.prettierrc.js index aebdedadc..0ac2fef8f 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -19,10 +19,11 @@ module.exports = { '.github/renovate.json5', '**/types/index.d.ts', '**/types/index.d.ts.map', - '**/pnpm-lock.yaml' + '**/pnpm-lock.yaml', + '.changeset/pre.json' ], options: { - requirePragma: true + rangeEnd: 0 } }, { From 809c8c2f756a502b3e05e9380b1f1273d095b51b Mon Sep 17 00:00:00 2001 From: dominikg Date: Thu, 28 Sep 2023 17:52:34 +0200 Subject: [PATCH 05/13] fix: move types inside import condition to avoid masquerading as cjs warning --- package.json | 2 +- packages/vite-plugin-svelte-inspector/package.json | 8 +++++--- packages/vite-plugin-svelte/package.json | 8 +++++--- pnpm-lock.yaml | 8 ++++---- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 4610ec07b..49013d991 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "playwright-core": "~1.38.1", "prettier": "^3.0.3", "prettier-plugin-svelte": "^3.0.3", - "publint": "^0.2.2", + "publint": "^0.2.3", "svelte": "^4.2.1", "typescript": "^5.2.2", "vite": "^5.0.0-beta.2", diff --git a/packages/vite-plugin-svelte-inspector/package.json b/packages/vite-plugin-svelte-inspector/package.json index 7393d4a85..1a4fdafff 100644 --- a/packages/vite-plugin-svelte-inspector/package.json +++ b/packages/vite-plugin-svelte-inspector/package.json @@ -11,14 +11,16 @@ "types": "types/index.d.ts", "exports": { ".": { - "types": "./types/index.d.ts", - "import": "./src/index.js" + "import": { + "types": "./types/index.d.ts", + "default": "./src/index.js" + } } }, "scripts": { "check:publint": "publint --strict", "check:types": "tsc --noEmit", - "generate:types": "dts-buddy" + "generate:types": "dts-buddy -m \"@sveltejs/vite-plugin-svelte-inspector:src/index.js\"" }, "engines": { "node": "^18.0.0 || >=20" diff --git a/packages/vite-plugin-svelte/package.json b/packages/vite-plugin-svelte/package.json index 597130af4..a586ed417 100644 --- a/packages/vite-plugin-svelte/package.json +++ b/packages/vite-plugin-svelte/package.json @@ -11,14 +11,16 @@ "types": "types/index.d.ts", "exports": { ".": { - "types": "./types/index.d.ts", - "import": "./src/index.js" + "import": { + "types": "./types/index.d.ts", + "default": "./src/index.js" + } } }, "scripts": { "check:publint": "publint --strict", "check:types": "tsc --noEmit", - "generate:types": "dts-buddy" + "generate:types": "dts-buddy -m \"@sveltejs/vite-plugin-svelte:src/index.js\"" }, "engines": { "node": "^18.0.0 || >=20" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 129ed8735..f0cfee15c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -91,8 +91,8 @@ importers: specifier: ^3.0.3 version: 3.0.3(prettier@3.0.3)(svelte@4.2.1) publint: - specifier: ^0.2.2 - version: 0.2.2 + specifier: ^0.2.3 + version: 0.2.3 svelte: specifier: ^4.2.1 version: 4.2.1 @@ -5170,8 +5170,8 @@ packages: resolution: {integrity: sha512-b/YwNhb8lk1Zz2+bXXpS/LK9OisiZZ1SNsSLxN1x2OXVEhW2Ckr/7mWE5vrC1ZTiJlD9g19jWszTmJsB+oEpFQ==} dev: true - /publint@0.2.2: - resolution: {integrity: sha512-2t2IO6Y8Z+QBNLG89bpRhTQH7Ifn/83Kr0dVVdmOybq7GAT6+M4YGZd5AhtfMJbYPmbT7YD469pDKLCK94Q2+Q==} + /publint@0.2.3: + resolution: {integrity: sha512-Ml/rLotRiRTCbqL8CtWURiWDPzHtjv1SKU2E91R0ZG4mDJS3/rNQXYttM+Wt5t0JZ09MyAXIa/TYOt5OVUlYAQ==} engines: {node: '>=16'} hasBin: true dependencies: From ee005a6a093d4bab3a74c015f4371db9f111df8c Mon Sep 17 00:00:00 2001 From: dominikg Date: Thu, 28 Sep 2023 18:01:12 +0200 Subject: [PATCH 06/13] fix: types --- packages/vite-plugin-svelte/src/utils/error.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite-plugin-svelte/src/utils/error.js b/packages/vite-plugin-svelte/src/utils/error.js index c7f33a6e9..23760916b 100644 --- a/packages/vite-plugin-svelte/src/utils/error.js +++ b/packages/vite-plugin-svelte/src/utils/error.js @@ -104,7 +104,7 @@ function formatFrameForVite(frame) { /** * @param {import('svelte/types/compiler/interfaces').Warning & Error} err a svelte compiler error, which is a mix of Warning and an error * @param {string} originalCode - * @param {import('../index.js').Arrayable} [preprocessors] + * @param {import('../public.d.ts').Arrayable} [preprocessors] */ export function enhanceCompileError(err, originalCode, preprocessors) { preprocessors = arraify(preprocessors ?? []); From 3f6cd6a5f29233da57f0e5ceb2e0fad3e87faef4 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 16 Oct 2023 12:25:38 -0400 Subject: [PATCH 07/13] bump dts-buddy --- package.json | 2 +- pnpm-lock.yaml | 31 +++++++++---------------------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 48a08db67..1557f1ad1 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "@typescript-eslint/eslint-plugin": "^6.7.5", "@typescript-eslint/parser": "^6.7.5", "cross-env": "^7.0.3", - "dts-buddy": "^0.2.4", + "dts-buddy": "^0.3.0", "eslint": "^8.51.0", "eslint-config-prettier": "^9.0.0", "eslint-plugin-html": "^7.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1eaa6b4a9..3c1d8c7fd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -37,8 +37,8 @@ importers: specifier: ^7.0.3 version: 7.0.3 dts-buddy: - specifier: ^0.2.4 - version: 0.2.4 + specifier: ^0.3.0 + version: 0.3.0(typescript@5.2.2) eslint: specifier: ^8.51.0 version: 8.51.0 @@ -2859,20 +2859,22 @@ packages: engines: {node: '>=12'} dev: true - /dts-buddy@0.2.4: - resolution: {integrity: sha512-41d7aGv2DXJYlzeKSKHf0GtpCC8OdpEHhz+aqjylKV5aP3fl4APzNmQ5hL5vSKZMaO/lrkrKWC+HQrxl+mcgUw==} + /dts-buddy@0.3.0(typescript@5.2.2): + resolution: {integrity: sha512-O/l2Sw//bCpqJVWOQ+8xh54QLRGg4dh+42mONTRyxbIPEpXzN9pOJXYNDOWndPGlgJWMNhlQIUGYxnEcZ83c+g==} hasBin: true + peerDependencies: + typescript: '>=5.0.4 <5.3' dependencies: '@jridgewell/source-map': 0.3.5 '@jridgewell/sourcemap-codec': 1.4.15 globrex: 0.1.2 kleur: 4.1.5 locate-character: 3.0.0 - magic-string: 0.30.3 + magic-string: 0.30.5 sade: 1.8.1 tiny-glob: 0.2.9 - ts-api-utils: 1.0.3(typescript@5.0.4) - typescript: 5.0.4 + ts-api-utils: 1.0.3(typescript@5.2.2) + typescript: 5.2.2 dev: true /eastasianwidth@0.2.0: @@ -6242,15 +6244,6 @@ packages: engines: {node: '>=8'} dev: true - /ts-api-utils@1.0.3(typescript@5.0.4): - resolution: {integrity: sha512-wNMeqtMz5NtwpT/UZGY5alT+VoKdSsOOP/kqHFcUW1P/VRhH2wJ48+DN2WwUliNbQ976ETwDL0Ifd2VVvgonvg==} - engines: {node: '>=16.13.0'} - peerDependencies: - typescript: '>=4.2.0' - dependencies: - typescript: 5.0.4 - dev: true - /ts-api-utils@1.0.3(typescript@5.2.2): resolution: {integrity: sha512-wNMeqtMz5NtwpT/UZGY5alT+VoKdSsOOP/kqHFcUW1P/VRhH2wJ48+DN2WwUliNbQ976ETwDL0Ifd2VVvgonvg==} engines: {node: '>=16.13.0'} @@ -6374,12 +6367,6 @@ packages: hasBin: true dev: true - /typescript@5.0.4: - resolution: {integrity: sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==} - engines: {node: '>=12.20'} - hasBin: true - dev: true - /typescript@5.2.2: resolution: {integrity: sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==} engines: {node: '>=14.17'} From 4543ff43843cc9e6da51addb81daec713db8c1b0 Mon Sep 17 00:00:00 2001 From: dominikg Date: Thu, 19 Oct 2023 20:13:50 +0200 Subject: [PATCH 08/13] fix: regenerate types --- packages/vite-plugin-svelte/types/index.d.ts | 28 ++++++++++--------- .../vite-plugin-svelte/types/index.d.ts.map | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/vite-plugin-svelte/types/index.d.ts b/packages/vite-plugin-svelte/types/index.d.ts index a12f4da56..2e463aab0 100644 --- a/packages/vite-plugin-svelte/types/index.d.ts +++ b/packages/vite-plugin-svelte/types/index.d.ts @@ -122,20 +122,7 @@ declare module '@sveltejs/vite-plugin-svelte' { * @see https://svelte.dev/docs#svelte_compile */ compilerOptions?: Omit; - /** - * Handles warning emitted from the Svelte compiler - */ - onwarn?: (warning: Warning, defaultHandler?: (warning: Warning) => void) => void; - /** - * Options for vite-plugin-svelte - */ - vitePlugin?: PluginOptions; - } - /** - * These options are considered experimental and breaking changes to them can occur in any release - */ - interface ExperimentalOptions { /** * A function to update `compilerOptions` before compilation * @@ -160,6 +147,21 @@ declare module '@sveltejs/vite-plugin-svelte' { code: string; compileOptions: Partial; }) => Promise | void> | Partial | void; + + /** + * Handles warning emitted from the Svelte compiler + */ + onwarn?: (warning: Warning, defaultHandler?: (warning: Warning) => void) => void; + /** + * Options for vite-plugin-svelte + */ + vitePlugin?: PluginOptions; + } + + /** + * These options are considered experimental and breaking changes to them can occur in any release + */ + interface ExperimentalOptions { /** * send a websocket message with svelte compiler warnings during dev * diff --git a/packages/vite-plugin-svelte/types/index.d.ts.map b/packages/vite-plugin-svelte/types/index.d.ts.map index 0aa46cbe2..558419051 100644 --- a/packages/vite-plugin-svelte/types/index.d.ts.map +++ b/packages/vite-plugin-svelte/types/index.d.ts.map @@ -19,5 +19,5 @@ null, null ], - "mappings": ";;;;;iBA0BgBA,MAAMA;;;WClBLC,mBAAmBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCQpBC,cAAcA;iBCgBRC,gBAAgBA" + "mappings": ";;;;;iBA0BgBA,MAAMA;;;WClBLC,mBAAmBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCOpBC,cAAcA;iBCiBRC,gBAAgBA" } \ No newline at end of file From b8601372dea2afbfe8e897a966f4a3e2a97b1835 Mon Sep 17 00:00:00 2001 From: dominikg Date: Thu, 19 Oct 2023 21:02:49 +0200 Subject: [PATCH 09/13] fix: use correct type Options for plugin function arg --- .changeset/gorgeous-hats-bathe.md | 5 +++++ packages/vite-plugin-svelte/src/index.js | 2 +- packages/vite-plugin-svelte/types/index.d.ts | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/gorgeous-hats-bathe.md diff --git a/.changeset/gorgeous-hats-bathe.md b/.changeset/gorgeous-hats-bathe.md new file mode 100644 index 000000000..49d304a90 --- /dev/null +++ b/.changeset/gorgeous-hats-bathe.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/vite-plugin-svelte': patch +--- + +fix(types): use correct type Options for svelte function arg diff --git a/packages/vite-plugin-svelte/src/index.js b/packages/vite-plugin-svelte/src/index.js index 49ac59fe9..7b23ad7bf 100644 --- a/packages/vite-plugin-svelte/src/index.js +++ b/packages/vite-plugin-svelte/src/index.js @@ -21,7 +21,7 @@ import { VitePluginSvelteCache } from './utils/vite-plugin-svelte-cache.js'; import { loadRaw } from './utils/load-raw.js'; /** - * @param {Partial} [inlineOptions] + * @param {Partial} [inlineOptions] * @returns {import('vite').Plugin[]} */ export function svelte(inlineOptions) { diff --git a/packages/vite-plugin-svelte/types/index.d.ts b/packages/vite-plugin-svelte/types/index.d.ts index 2e463aab0..ef60a800a 100644 --- a/packages/vite-plugin-svelte/types/index.d.ts +++ b/packages/vite-plugin-svelte/types/index.d.ts @@ -3,7 +3,7 @@ declare module '@sveltejs/vite-plugin-svelte' { import type { CompileOptions, PreprocessorGroup } from 'svelte/compiler'; import type { Warning } from 'svelte/types/compiler/interfaces'; import type { Options as InspectorOptions } from '@sveltejs/vite-plugin-svelte-inspector'; - export function svelte(inlineOptions?: Partial | undefined): import('vite').Plugin[]; + export function svelte(inlineOptions?: Partial | undefined): import('vite').Plugin[]; type Options = Omit & PluginOptionsInline; interface PluginOptionsInline extends PluginOptions { From 26a71377d81abe04266ac399b71bb6903506fce8 Mon Sep 17 00:00:00 2001 From: dominikg Date: Sun, 22 Oct 2023 12:49:06 +0200 Subject: [PATCH 10/13] fix(types): reexport index.js from public.d.ts to ensure types and functions are properly exported through module declaration generated by dts-buddy; move dynamicCompileOptions to PluginOptions, rename SvelteOptions to SvelteConfig --- .changeset/small-pears-accept.md | 5 ++ .../vite-plugin-svelte-inspector/package.json | 2 +- .../src/public.d.ts | 2 + .../types/index.d.ts | 4 +- .../types/index.d.ts.map | 10 +-- packages/vite-plugin-svelte/package.json | 2 +- packages/vite-plugin-svelte/src/public.d.ts | 61 ++++++++++--------- .../vite-plugin-svelte/src/utils/error.js | 2 +- packages/vite-plugin-svelte/src/utils/id.js | 4 +- .../src/utils/load-svelte-config.js | 4 +- .../vite-plugin-svelte/src/utils/options.js | 2 +- packages/vite-plugin-svelte/types/index.d.ts | 61 ++++++++++--------- .../vite-plugin-svelte/types/index.d.ts.map | 8 ++- 13 files changed, 89 insertions(+), 78 deletions(-) create mode 100644 .changeset/small-pears-accept.md diff --git a/.changeset/small-pears-accept.md b/.changeset/small-pears-accept.md new file mode 100644 index 000000000..2738bcbd7 --- /dev/null +++ b/.changeset/small-pears-accept.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/vite-plugin-svelte': major +--- + +breaking(types): rename SvelteOptions to SvelteConfig diff --git a/packages/vite-plugin-svelte-inspector/package.json b/packages/vite-plugin-svelte-inspector/package.json index 2ce695e5d..37d810ab1 100644 --- a/packages/vite-plugin-svelte-inspector/package.json +++ b/packages/vite-plugin-svelte-inspector/package.json @@ -20,7 +20,7 @@ "scripts": { "check:publint": "publint --strict", "check:types": "tsc --noEmit", - "generate:types": "dts-buddy -m \"@sveltejs/vite-plugin-svelte-inspector:src/index.js\"" + "generate:types": "dts-buddy -m \"@sveltejs/vite-plugin-svelte-inspector:src/public.d.ts\"" }, "engines": { "node": "^18.0.0 || >=20" diff --git a/packages/vite-plugin-svelte-inspector/src/public.d.ts b/packages/vite-plugin-svelte-inspector/src/public.d.ts index 95983a2f1..538d7cb42 100644 --- a/packages/vite-plugin-svelte-inspector/src/public.d.ts +++ b/packages/vite-plugin-svelte-inspector/src/public.d.ts @@ -68,3 +68,5 @@ export interface Options { base: string; }; } + +export * from './index.js'; diff --git a/packages/vite-plugin-svelte-inspector/types/index.d.ts b/packages/vite-plugin-svelte-inspector/types/index.d.ts index bc86ccf3e..fbba16c60 100644 --- a/packages/vite-plugin-svelte-inspector/types/index.d.ts +++ b/packages/vite-plugin-svelte-inspector/types/index.d.ts @@ -1,6 +1,5 @@ declare module '@sveltejs/vite-plugin-svelte-inspector' { - export function svelteInspector(options?: Partial | undefined): import('vite').Plugin; - interface Options { + export interface Options { /** * define a key combo to toggle inspector, * @default 'meta-shift' on mac, 'control-shift' on other os @@ -69,6 +68,7 @@ declare module '@sveltejs/vite-plugin-svelte-inspector' { base: string; }; } + export function svelteInspector(options?: Partial | undefined): import('vite').Plugin; } //# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/packages/vite-plugin-svelte-inspector/types/index.d.ts.map b/packages/vite-plugin-svelte-inspector/types/index.d.ts.map index 956d409be..15d752e59 100644 --- a/packages/vite-plugin-svelte-inspector/types/index.d.ts.map +++ b/packages/vite-plugin-svelte-inspector/types/index.d.ts.map @@ -2,16 +2,16 @@ "version": 3, "file": "index.d.ts", "names": [ - "svelteInspector", - "Options" + "Options", + "svelteInspector" ], "sources": [ - "../src/index.js", - "../src/public.d.ts" + "../src/public.d.ts", + "../src/index.js" ], "sourcesContent": [ null, null ], - "mappings": ";iBAoBgBA,eAAeA;WCpBdC,OAAOA" + "mappings": ";kBAAiBA,OAAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCoBRC,eAAeA" } \ No newline at end of file diff --git a/packages/vite-plugin-svelte/package.json b/packages/vite-plugin-svelte/package.json index a351e1497..fa42441bc 100644 --- a/packages/vite-plugin-svelte/package.json +++ b/packages/vite-plugin-svelte/package.json @@ -20,7 +20,7 @@ "scripts": { "check:publint": "publint --strict", "check:types": "tsc --noEmit", - "generate:types": "dts-buddy -m \"@sveltejs/vite-plugin-svelte:src/index.js\"" + "generate:types": "dts-buddy -m \"@sveltejs/vite-plugin-svelte:src/public.d.ts\"" }, "engines": { "node": "^18.0.0 || >=20" diff --git a/packages/vite-plugin-svelte/src/public.d.ts b/packages/vite-plugin-svelte/src/public.d.ts index 6d03e4c3a..672c697a2 100644 --- a/packages/vite-plugin-svelte/src/public.d.ts +++ b/packages/vite-plugin-svelte/src/public.d.ts @@ -4,9 +4,9 @@ import type { Warning } from 'svelte/types/compiler/interfaces'; import type { PreprocessorGroup } from 'svelte/compiler'; import type { Options as InspectorOptions } from '@sveltejs/vite-plugin-svelte-inspector'; -type Options = Omit & PluginOptionsInline; +export type Options = Omit & PluginOptionsInline; -export interface PluginOptionsInline extends PluginOptions { +interface PluginOptionsInline extends PluginOptions { /** * Path to a svelte config file, either absolute or relative to Vite root * @@ -95,13 +95,39 @@ interface PluginOptions { * @default unset for dev, always false for build */ inspector?: InspectorOptions | boolean; + + /** + * A function to update `compilerOptions` before compilation + * + * `data.filename` - The file to be compiled + * `data.code` - The preprocessed Svelte code + * `data.compileOptions` - The current compiler options + * + * To change part of the compiler options, return an object with the changes you need. + * + * @example + * ``` + * ({ filename, compileOptions }) => { + * // Dynamically set hydration per Svelte file + * if (compileWithHydratable(filename) && !compileOptions.hydratable) { + * return { hydratable: true }; + * } + * } + * ``` + */ + dynamicCompileOptions?: (data: { + filename: string; + code: string; + compileOptions: Partial; + }) => Promise | void> | Partial | void; + /** * These options are considered experimental and breaking changes to them can occur in any release */ experimental?: ExperimentalOptions; } -interface SvelteOptions { +export interface SvelteConfig { /** * A list of file extensions to be compiled by Svelte * @@ -123,31 +149,6 @@ interface SvelteOptions { */ compilerOptions?: Omit; - /** - * A function to update `compilerOptions` before compilation - * - * `data.filename` - The file to be compiled - * `data.code` - The preprocessed Svelte code - * `data.compileOptions` - The current compiler options - * - * To change part of the compiler options, return an object with the changes you need. - * - * @example - * ``` - * ({ filename, compileOptions }) => { - * // Dynamically set hydration per Svelte file - * if (compileWithHydratable(filename) && !compileOptions.hydratable) { - * return { hydratable: true }; - * } - * } - * ``` - */ - dynamicCompileOptions?: (data: { - filename: string; - code: string; - compileOptions: Partial; - }) => Promise | void> | Partial | void; - /** * Handles warning emitted from the Svelte compiler */ @@ -177,9 +178,9 @@ interface ExperimentalOptions { type Arrayable = T | T[]; -interface VitePreprocessOptions { +export interface VitePreprocessOptions { script?: boolean; style?: boolean | InlineConfig | ResolvedConfig; } -export { Arrayable, Options, PluginOptions, SvelteOptions, VitePreprocessOptions }; +export * from './index.js'; diff --git a/packages/vite-plugin-svelte/src/utils/error.js b/packages/vite-plugin-svelte/src/utils/error.js index 23760916b..b7ca277fb 100644 --- a/packages/vite-plugin-svelte/src/utils/error.js +++ b/packages/vite-plugin-svelte/src/utils/error.js @@ -104,7 +104,7 @@ function formatFrameForVite(frame) { /** * @param {import('svelte/types/compiler/interfaces').Warning & Error} err a svelte compiler error, which is a mix of Warning and an error * @param {string} originalCode - * @param {import('../public.d.ts').Arrayable} [preprocessors] + * @param {import('../public.d.ts').Options['preprocess']} [preprocessors] */ export function enhanceCompileError(err, originalCode, preprocessors) { preprocessors = arraify(preprocessors ?? []); diff --git a/packages/vite-plugin-svelte/src/utils/id.js b/packages/vite-plugin-svelte/src/utils/id.js index 8aaa3bdbc..8c688db1f 100644 --- a/packages/vite-plugin-svelte/src/utils/id.js +++ b/packages/vite-plugin-svelte/src/utils/id.js @@ -159,8 +159,8 @@ function stripRoot(normalizedFilename, normalizedRoot) { } /** - * @param {import('../public.d.ts').Arrayable | undefined} include - * @param {import('../public.d.ts').Arrayable | undefined} exclude + * @param {import('../public.d.ts').Options['include'] | undefined} include + * @param {import('../public.d.ts').Options['exclude'] | undefined} exclude * @param {string[]} extensions * @returns {(filename: string) => boolean} */ diff --git a/packages/vite-plugin-svelte/src/utils/load-svelte-config.js b/packages/vite-plugin-svelte/src/utils/load-svelte-config.js index d324869ac..f4544e4b1 100644 --- a/packages/vite-plugin-svelte/src/utils/load-svelte-config.js +++ b/packages/vite-plugin-svelte/src/utils/load-svelte-config.js @@ -27,8 +27,8 @@ const dynamicImportDefault = new Function( /** * @param {import('vite').UserConfig} viteConfig - * @param {Partial} inlineOptions - * @returns {Promise | undefined>} + * @param {Partial} inlineOptions + * @returns {Promise | undefined>} */ export async function loadSvelteConfig(viteConfig, inlineOptions) { if (inlineOptions?.configFile === false) { diff --git a/packages/vite-plugin-svelte/src/utils/options.js b/packages/vite-plugin-svelte/src/utils/options.js index 7192d879e..396ecfe64 100644 --- a/packages/vite-plugin-svelte/src/utils/options.js +++ b/packages/vite-plugin-svelte/src/utils/options.js @@ -57,7 +57,7 @@ export function validateInlineOptions(inlineOptions) { } /** - * @param {Partial} [config] + * @param {Partial} [config] * @returns {Partial | undefined} */ function convertPluginOptions(config) { diff --git a/packages/vite-plugin-svelte/types/index.d.ts b/packages/vite-plugin-svelte/types/index.d.ts index ef60a800a..69ee7bf51 100644 --- a/packages/vite-plugin-svelte/types/index.d.ts +++ b/packages/vite-plugin-svelte/types/index.d.ts @@ -3,8 +3,7 @@ declare module '@sveltejs/vite-plugin-svelte' { import type { CompileOptions, PreprocessorGroup } from 'svelte/compiler'; import type { Warning } from 'svelte/types/compiler/interfaces'; import type { Options as InspectorOptions } from '@sveltejs/vite-plugin-svelte-inspector'; - export function svelte(inlineOptions?: Partial | undefined): import('vite').Plugin[]; - type Options = Omit & PluginOptionsInline; + export type Options = Omit & PluginOptionsInline; interface PluginOptionsInline extends PluginOptions { /** @@ -95,13 +94,39 @@ declare module '@sveltejs/vite-plugin-svelte' { * @default unset for dev, always false for build */ inspector?: InspectorOptions | boolean; + + /** + * A function to update `compilerOptions` before compilation + * + * `data.filename` - The file to be compiled + * `data.code` - The preprocessed Svelte code + * `data.compileOptions` - The current compiler options + * + * To change part of the compiler options, return an object with the changes you need. + * + * @example + * ``` + * ({ filename, compileOptions }) => { + * // Dynamically set hydration per Svelte file + * if (compileWithHydratable(filename) && !compileOptions.hydratable) { + * return { hydratable: true }; + * } + * } + * ``` + */ + dynamicCompileOptions?: (data: { + filename: string; + code: string; + compileOptions: Partial; + }) => Promise | void> | Partial | void; + /** * These options are considered experimental and breaking changes to them can occur in any release */ experimental?: ExperimentalOptions; } - interface SvelteOptions { + export interface SvelteConfig { /** * A list of file extensions to be compiled by Svelte * @@ -123,31 +148,6 @@ declare module '@sveltejs/vite-plugin-svelte' { */ compilerOptions?: Omit; - /** - * A function to update `compilerOptions` before compilation - * - * `data.filename` - The file to be compiled - * `data.code` - The preprocessed Svelte code - * `data.compileOptions` - The current compiler options - * - * To change part of the compiler options, return an object with the changes you need. - * - * @example - * ``` - * ({ filename, compileOptions }) => { - * // Dynamically set hydration per Svelte file - * if (compileWithHydratable(filename) && !compileOptions.hydratable) { - * return { hydratable: true }; - * } - * } - * ``` - */ - dynamicCompileOptions?: (data: { - filename: string; - code: string; - compileOptions: Partial; - }) => Promise | void> | Partial | void; - /** * Handles warning emitted from the Svelte compiler */ @@ -177,12 +177,13 @@ declare module '@sveltejs/vite-plugin-svelte' { type Arrayable = T | T[]; - interface VitePreprocessOptions { + export interface VitePreprocessOptions { script?: boolean; style?: boolean | InlineConfig | ResolvedConfig; } + export function svelte(inlineOptions?: Partial | undefined): import('vite').Plugin[]; export function vitePreprocess(opts: VitePreprocessOptions): import('svelte/compiler').PreprocessorGroup; - export function loadSvelteConfig(viteConfig: import('vite').UserConfig, inlineOptions: Partial): Promise | undefined>; + export function loadSvelteConfig(viteConfig: import('vite').UserConfig, inlineOptions: Partial): Promise | undefined>; } //# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/packages/vite-plugin-svelte/types/index.d.ts.map b/packages/vite-plugin-svelte/types/index.d.ts.map index 558419051..9273b9c00 100644 --- a/packages/vite-plugin-svelte/types/index.d.ts.map +++ b/packages/vite-plugin-svelte/types/index.d.ts.map @@ -2,14 +2,16 @@ "version": 3, "file": "index.d.ts", "names": [ + "Options", + "SvelteConfig", + "VitePreprocessOptions", "svelte", - "PluginOptionsInline", "vitePreprocess", "loadSvelteConfig" ], "sources": [ - "../src/index.js", "../src/public.d.ts", + "../src/index.js", "../src/preprocess.js", "../src/utils/load-svelte-config.js" ], @@ -19,5 +21,5 @@ null, null ], - "mappings": ";;;;;iBA0BgBA,MAAMA;;;WClBLC,mBAAmBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCOpBC,cAAcA;iBCiBRC,gBAAgBA" + "mappings": ";;;;;aAMYA,OAAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA2HFC,YAAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAmDZC,qBAAqBA;;;;iBC1JtBC,MAAMA;iBCXNC,cAAcA;iBCiBRC,gBAAgBA" } \ No newline at end of file From 24a14e4d6fe0758d619442cc62efcb24416c1bd4 Mon Sep 17 00:00:00 2001 From: dominikg Date: Sun, 22 Oct 2023 12:51:15 +0200 Subject: [PATCH 11/13] fix: update lockfile --- pnpm-lock.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a41df7712..a043d4473 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1338,7 +1338,7 @@ packages: resolution: {integrity: sha512-UTYAUj/wviwdsMfzoSJspJxbkH5o1snzwX0//0ENX1u/55kkZZkcTZP6u9bwKGkv+dkk9at4m1Cpt0uY80kcpQ==} dependencies: '@jridgewell/gen-mapping': 0.3.3 - '@jridgewell/trace-mapping': 0.3.19 + '@jridgewell/trace-mapping': 0.3.20 dev: true /@jridgewell/sourcemap-codec@1.4.15: From 1cc0cc33ccbda245a89f600acd4b0730a3e4803a Mon Sep 17 00:00:00 2001 From: Dominik G Date: Thu, 26 Oct 2023 18:30:29 +0200 Subject: [PATCH 12/13] Update .changeset/metal-olives-wait.md Co-authored-by: Bjorn Lu --- .changeset/metal-olives-wait.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/metal-olives-wait.md b/.changeset/metal-olives-wait.md index ed6e42d01..bc9a88544 100644 --- a/.changeset/metal-olives-wait.md +++ b/.changeset/metal-olives-wait.md @@ -3,4 +3,4 @@ '@sveltejs/vite-plugin-svelte': major --- -breaking(types): emit types with dts-buddy to include type map" +breaking(types): emit types with dts-buddy to include type map From dfbc0855493d124e04dda7a1a71b8ecd6c1b0bf4 Mon Sep 17 00:00:00 2001 From: dominikg Date: Thu, 26 Oct 2023 19:19:35 +0200 Subject: [PATCH 13/13] fix: update types --- packages/vite-plugin-svelte/types/index.d.ts.map | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vite-plugin-svelte/types/index.d.ts.map b/packages/vite-plugin-svelte/types/index.d.ts.map index 9273b9c00..8355d0629 100644 --- a/packages/vite-plugin-svelte/types/index.d.ts.map +++ b/packages/vite-plugin-svelte/types/index.d.ts.map @@ -21,5 +21,5 @@ null, null ], - "mappings": ";;;;;aAMYA,OAAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA2HFC,YAAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAmDZC,qBAAqBA;;;;iBC1JtBC,MAAMA;iBCXNC,cAAcA;iBCiBRC,gBAAgBA" + "mappings": ";;;;;aAMYA,OAAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA2HFC,YAAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAmDZC,qBAAqBA;;;;iBC1JtBC,MAAMA;iBCXNC,cAAcA;iBCgBRC,gBAAgBA" } \ No newline at end of file