Skip to content

Commit 1792d7a

Browse files
authored
feat: import svelte types (#105)
* feat: import svelte types * fix: force export type
1 parent 57a592c commit 1792d7a

File tree

3 files changed

+18
-56
lines changed

3 files changed

+18
-56
lines changed

.changeset/famous-lemons-draw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/vite-plugin-svelte': patch
3+
---
4+
5+
import svelte types instead of duplicating them

packages/vite-plugin-svelte/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"scripts": {
2525
"dev": "pnpm run build:ci -- --watch src",
2626
"build:ci": "rimraf dist && tsup-node src/index.ts --format esm,cjs --no-splitting",
27-
"build": "pnpm run build:ci -- --dts --dts-resolve --sourcemap"
27+
"build": "pnpm run build:ci -- --dts --sourcemap"
2828
},
2929
"engines": {
3030
"node": "^12.20 || ^14.13.1 || >= 16"

packages/vite-plugin-svelte/src/utils/options.ts

Lines changed: 12 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ import { ConfigEnv, UserConfig, ViteDevServer } from 'vite';
33
import { log } from './log';
44
import { loadSvelteConfig } from './load-svelte-config';
55
import { SVELTE_HMR_IMPORTS, SVELTE_IMPORTS, SVELTE_RESOLVE_MAIN_FIELDS } from './constants';
6+
// eslint-disable-next-line node/no-missing-import
7+
import { CompileOptions } from 'svelte/types/compiler/interfaces';
8+
import {
9+
MarkupPreprocessor,
10+
Preprocessor,
11+
PreprocessorGroup,
12+
Processed
13+
// eslint-disable-next-line node/no-missing-import
14+
} from 'svelte/types/compiler/preprocess';
615

716
const knownOptions = new Set([
817
'configFile',
@@ -420,63 +429,11 @@ export interface ResolvedOptions extends Options {
420429
server?: ViteDevServer;
421430
}
422431

423-
// TODO import from appropriate places
424-
export declare type ModuleFormat = 'esm' | 'cjs';
432+
export type { CompileOptions, Processed, MarkupPreprocessor, Preprocessor, PreprocessorGroup };
425433

426-
export interface CompileOptions {
427-
format?: ModuleFormat;
428-
name?: string;
429-
filename?: string;
430-
generate?: 'dom' | 'ssr' | false;
431-
sourcemap?: object | string;
432-
outputFilename?: string;
433-
cssOutputFilename?: string;
434-
sveltePath?: string;
435-
dev?: boolean;
436-
accessors?: boolean;
437-
immutable?: boolean;
438-
hydratable?: boolean;
439-
legacy?: boolean;
440-
customElement?: boolean;
441-
tag?: string;
442-
css?: boolean;
443-
loopGuardTimeout?: number;
444-
namespace?: string;
445-
preserveComments?: boolean;
446-
preserveWhitespace?: boolean;
447-
cssHash?: CssHashGetter;
448-
}
449-
450-
export interface Processed {
451-
code: string;
452-
map?: string | object;
453-
dependencies?: string[];
454-
toString?: () => string;
455-
}
456-
457-
export declare type CssHashGetter = (args: {
458-
name: string;
459-
filename: string | undefined;
460-
css: string;
461-
hash: (input: string) => string;
462-
}) => string;
463-
464-
export declare type MarkupPreprocessor = (options: {
465-
content: string;
466-
filename: string;
467-
}) => Processed | Promise<Processed>;
468-
469-
export declare type Preprocessor = (options: {
470-
content: string;
471-
attributes: Record<string, string | boolean>;
472-
filename?: string;
473-
}) => Processed | Promise<Processed>;
434+
export type ModuleFormat = NonNullable<CompileOptions['format']>;
474435

475-
export interface PreprocessorGroup {
476-
markup?: MarkupPreprocessor;
477-
style?: Preprocessor;
478-
script?: Preprocessor;
479-
}
436+
export type CssHashGetter = NonNullable<CompileOptions['cssHash']>;
480437

481438
export type Arrayable<T> = T | T[];
482439

0 commit comments

Comments
 (0)