@sveltejs/vite-plugin-svelte
Advanced tools
Comparing version 1.0.0-next.49 to 1.0.1
@@ -6,5 +6,5 @@ import { UserConfig, Plugin } from 'vite'; | ||
export { MarkupPreprocessor, Preprocessor, PreprocessorGroup, Processed } from 'svelte/types/compiler/preprocess'; | ||
import { KitConfig } from '@sveltejs/kit'; | ||
interface Options { | ||
declare type Options = Omit<SvelteOptions, 'vitePlugin'> & PluginOptionsInline; | ||
interface PluginOptionsInline extends PluginOptions { | ||
/** | ||
@@ -18,2 +18,4 @@ * Path to a svelte config file, either absolute or relative to Vite root | ||
configFile?: string | false; | ||
} | ||
interface PluginOptions { | ||
/** | ||
@@ -34,14 +36,2 @@ * A `picomatch` pattern, or array of patterns, which specifies the files the plugin should | ||
/** | ||
* 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<PreprocessorGroup>; | ||
/** | ||
* Emit Svelte styles as virtual CSS files for Vite and other plugins to process | ||
@@ -53,14 +43,2 @@ * | ||
/** | ||
* 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<CompileOptions, 'filename' | 'format' | 'generate'>; | ||
/** | ||
* Handles warning emitted from the Svelte compiler | ||
*/ | ||
onwarn?: (warning: Warning, defaultHandler?: (warning: Warning) => void) => void; | ||
/** | ||
* Enable or disable Hot Module Replacement. | ||
@@ -109,6 +87,32 @@ * | ||
experimental?: ExperimentalOptions; | ||
} | ||
interface SvelteOptions { | ||
/** | ||
* Options for SvelteKit | ||
* A list of file extensions to be compiled by Svelte | ||
* | ||
* @default ['.svelte'] | ||
*/ | ||
kit?: KitConfig; | ||
extensions?: string[]; | ||
/** | ||
* An array of preprocessors to transform the Svelte source code before compilation | ||
* | ||
* @see https://svelte.dev/docs#svelte_preprocess | ||
*/ | ||
preprocess?: Arrayable<PreprocessorGroup>; | ||
/** | ||
* 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<CompileOptions, 'filename' | 'format' | 'generate'>; | ||
/** | ||
* Handles warning emitted from the Svelte compiler | ||
*/ | ||
onwarn?: (warning: Warning, defaultHandler?: (warning: Warning) => void) => void; | ||
/** | ||
* Options for vite-plugin-svelte | ||
*/ | ||
vitePlugin?: PluginOptions; | ||
} | ||
@@ -218,3 +222,3 @@ /** | ||
declare function loadSvelteConfig(viteConfig?: UserConfig, inlineOptions?: Partial<Options>): Promise<Partial<Options> | undefined>; | ||
declare function loadSvelteConfig(viteConfig?: UserConfig, inlineOptions?: Partial<Options>): Promise<Partial<SvelteOptions> | undefined>; | ||
@@ -233,2 +237,2 @@ declare type SvelteWarningsMessage = { | ||
export { Arrayable, CssHashGetter, ModuleFormat, Options, SvelteWarningsMessage, loadSvelteConfig, svelte }; | ||
export { Arrayable, CssHashGetter, ModuleFormat, Options, PluginOptions, SvelteOptions, SvelteWarningsMessage, loadSvelteConfig, svelte }; |
{ | ||
"name": "@sveltejs/vite-plugin-svelte", | ||
"version": "1.0.0-next.49", | ||
"version": "1.0.1", | ||
"license": "MIT", | ||
@@ -26,3 +26,3 @@ "author": "dominikg", | ||
"engines": { | ||
"node": "^14.13.1 || >= 16" | ||
"node": "^14.18.0 || >= 16" | ||
}, | ||
@@ -48,3 +48,3 @@ "repository": { | ||
"deepmerge": "^4.2.2", | ||
"kleur": "^4.1.4", | ||
"kleur": "^4.1.5", | ||
"magic-string": "^0.26.2", | ||
@@ -56,3 +56,3 @@ "svelte-hmr": "^0.14.12" | ||
"svelte": "^3.44.0", | ||
"vite": "^2.9.0" | ||
"vite": "^3.0.0" | ||
}, | ||
@@ -65,11 +65,11 @@ "peerDependenciesMeta": { | ||
"devDependencies": { | ||
"@sveltejs/kit": "^1.0.0-next.350", | ||
"@sveltejs/kit": "^1.0.0-next.370", | ||
"@types/debug": "^4.1.7", | ||
"@types/diff-match-patch": "^1.0.32", | ||
"diff-match-patch": "^1.0.5", | ||
"esbuild": "^0.14.42", | ||
"rollup": "^2.75.5", | ||
"svelte": "^3.48.0", | ||
"tsup": "^6.1.0", | ||
"vite": "^2.9.10" | ||
"esbuild": "^0.14.49", | ||
"rollup": "^2.76.0", | ||
"svelte": "^3.49.0", | ||
"tsup": "^6.1.3", | ||
"vite": "^3.0.0" | ||
}, | ||
@@ -76,0 +76,0 @@ "scripts": { |
@@ -93,3 +93,4 @@ import fs from 'fs'; | ||
// Vite's optimizer runs after `buildStart()`. | ||
viteConfig.server.force = true; | ||
// TODO: verify this works in vite3 | ||
viteConfig.optimizeDeps.force = true; | ||
} | ||
@@ -105,5 +106,3 @@ }, | ||
load(id, opts) { | ||
// @ts-expect-error anticipate vite changing second parameter as options object | ||
// see https://github.com/vitejs/vite/discussions/5109 | ||
const ssr: boolean = opts === true || opts?.ssr; | ||
const ssr = !!opts?.ssr; | ||
const svelteRequest = requestParser(id, !!ssr); | ||
@@ -232,2 +231,4 @@ if (svelteRequest) { | ||
Options, | ||
PluginOptions, | ||
SvelteOptions, | ||
Preprocessor, | ||
@@ -234,0 +235,0 @@ PreprocessorGroup, |
@@ -6,3 +6,3 @@ import { createRequire } from 'module'; | ||
import { log } from './log'; | ||
import { Options } from './options'; | ||
import { Options, SvelteOptions } from './options'; | ||
import { UserConfig } from 'vite'; | ||
@@ -33,3 +33,3 @@ | ||
inlineOptions?: Partial<Options> | ||
): Promise<Partial<Options> | undefined> { | ||
): Promise<Partial<SvelteOptions> | undefined> { | ||
if (inlineOptions?.configFile === false) { | ||
@@ -36,0 +36,0 @@ return; |
@@ -22,4 +22,3 @@ /* eslint-disable no-unused-vars */ | ||
} from 'svelte/types/compiler/preprocess'; | ||
// eslint-disable-next-line node/no-missing-import | ||
import type { KitConfig } from '@sveltejs/kit'; | ||
import path from 'path'; | ||
@@ -32,25 +31,89 @@ import { findRootSvelteDependencies, needsOptimization, SvelteDependency } from './dependencies'; | ||
const knownOptions = new Set([ | ||
'configFile', | ||
const allowedPluginOptions = new Set([ | ||
'include', | ||
'exclude', | ||
'extensions', | ||
'emitCss', | ||
'compilerOptions', | ||
'onwarn', | ||
'preprocess', | ||
'hot', | ||
'ignorePluginPreprocessors', | ||
'disableDependencyReinclusion', | ||
'experimental', | ||
'kit' | ||
'experimental' | ||
]); | ||
const knownRootOptions = new Set(['extensions', 'compilerOptions', 'preprocess', 'onwarn']); | ||
const allowedInlineOptions = new Set([ | ||
'configFile', | ||
'kit', // only for internal use by sveltekit | ||
...allowedPluginOptions, | ||
...knownRootOptions | ||
]); | ||
export function validateInlineOptions(inlineOptions?: Partial<Options>) { | ||
const invalidKeys = Object.keys(inlineOptions || {}).filter((key) => !knownOptions.has(key)); | ||
const invalidKeys = Object.keys(inlineOptions || {}).filter( | ||
(key) => !allowedInlineOptions.has(key) | ||
); | ||
if (invalidKeys.length) { | ||
log.warn(`invalid plugin options "${invalidKeys.join(', ')}" in config`, inlineOptions); | ||
log.warn(`invalid plugin options "${invalidKeys.join(', ')}" in inline config`, inlineOptions); | ||
} | ||
} | ||
function convertPluginOptions(config?: Partial<SvelteOptions>): Partial<Options> | undefined { | ||
if (!config) { | ||
return; | ||
} | ||
const invalidRootOptions = Object.keys(config).filter((key) => allowedPluginOptions.has(key)); | ||
if (invalidRootOptions.length > 0) { | ||
throw new Error( | ||
`Invalid options in svelte config. Move the following options into 'vitePlugin:{...}': ${invalidRootOptions.join( | ||
', ' | ||
)}` | ||
); | ||
} | ||
if (!config.vitePlugin) { | ||
return config; | ||
} | ||
const pluginOptions = config.vitePlugin; | ||
const pluginOptionKeys = Object.keys(pluginOptions); | ||
const rootOptionsInPluginOptions = pluginOptionKeys.filter((key) => knownRootOptions.has(key)); | ||
if (rootOptionsInPluginOptions.length > 0) { | ||
throw new Error( | ||
`Invalid options in svelte config under vitePlugin:{...}', move them to the config root : ${rootOptionsInPluginOptions.join( | ||
', ' | ||
)}` | ||
); | ||
} | ||
const duplicateOptions = pluginOptionKeys.filter((key) => | ||
Object.prototype.hasOwnProperty.call(config, key) | ||
); | ||
if (duplicateOptions.length > 0) { | ||
throw new Error( | ||
`Invalid duplicate options in svelte config under vitePlugin:{...}', they are defined in root too and must only exist once: ${duplicateOptions.join( | ||
', ' | ||
)}` | ||
); | ||
} | ||
const unknownPluginOptions = pluginOptionKeys.filter((key) => !allowedPluginOptions.has(key)); | ||
if (unknownPluginOptions.length > 0) { | ||
log.warn( | ||
`ignoring unknown plugin options in svelte config under vitePlugin:{...}: ${unknownPluginOptions.join( | ||
', ' | ||
)}` | ||
); | ||
unknownPluginOptions.forEach((unkownOption) => { | ||
// @ts-ignore | ||
delete pluginOptions[unkownOption]; | ||
}); | ||
} | ||
const result: Options = { | ||
...config, | ||
...pluginOptions | ||
}; | ||
// @ts-expect-error it exists | ||
delete result.vitePlugin; | ||
return result; | ||
} | ||
// used in config phase, merges the default options, svelte config, and inline options | ||
@@ -70,3 +133,6 @@ export async function preResolveOptions( | ||
}; | ||
const svelteConfig = await loadSvelteConfig(viteConfigWithResolvedRoot, inlineOptions); | ||
const svelteConfig = convertPluginOptions( | ||
await loadSvelteConfig(viteConfigWithResolvedRoot, inlineOptions) | ||
); | ||
const extraOptions: Partial<PreResolvedOptions> = { | ||
@@ -205,4 +271,7 @@ root: viteConfigWithResolvedRoot.root!, | ||
function addSvelteKitOptions(options: ResolvedOptions) { | ||
// @ts-expect-error kit is not typed to avoid dependency on sveltekit | ||
if (options?.kit != null) { | ||
const hydratable = options.kit.browser?.hydrate !== false; | ||
// @ts-expect-error kit is not typed to avoid dependency on sveltekit | ||
const kit_browser_hydrate = options.kit.browser?.hydrate; | ||
const hydratable = kit_browser_hydrate !== false; | ||
if ( | ||
@@ -213,3 +282,3 @@ options.compilerOptions.hydratable != null && | ||
log.warn( | ||
`Conflicting values "compilerOptions.hydratable: ${options.compilerOptions.hydratable}" and "kit.browser.hydrate: ${options.kit.browser?.hydrate}" in your svelte config. You should remove "compilerOptions.hydratable".` | ||
`Conflicting values "compilerOptions.hydratable: ${options.compilerOptions.hydratable}" and "kit.browser.hydrate: ${kit_browser_hydrate}" in your svelte config. You should remove "compilerOptions.hydratable".` | ||
); | ||
@@ -246,9 +315,7 @@ } | ||
if (options.isServe) { | ||
extraViteConfig.optimizeDeps = buildOptimizeDepsForSvelte( | ||
svelteDeps, | ||
options, | ||
config.optimizeDeps | ||
); | ||
} | ||
extraViteConfig.optimizeDeps = buildOptimizeDepsForSvelte( | ||
svelteDeps, | ||
options, | ||
config.optimizeDeps | ||
); | ||
@@ -345,28 +412,19 @@ if (options.experimental?.prebundleSvelteLibraries) { | ||
): any { | ||
const noExternal: string[] = []; | ||
const noExternal: (string | RegExp)[] = []; | ||
// add svelte to ssr.noExternal unless it is present in ssr.external | ||
// so we can resolve it with svelte/ssr | ||
if (options.isBuild && config.build?.ssr) { | ||
// @ts-expect-error ssr still flagged in vite | ||
if (!config.ssr?.external?.includes('svelte')) { | ||
noExternal.push('svelte'); | ||
} | ||
} else { | ||
// for non-ssr build, we exclude svelte js library deps to make development faster | ||
// and also because vite doesn't handle them properly. | ||
// see https://github.com/sveltejs/vite-plugin-svelte/issues/168 | ||
// see https://github.com/vitejs/vite/issues/2579 | ||
svelteDeps = svelteDeps.filter((dep) => dep.type === 'component-library'); | ||
if (!config.ssr?.external?.includes('svelte')) { | ||
noExternal.push('svelte', /^svelte\//); | ||
} | ||
// add svelte dependencies to ssr.noExternal unless present in ssr.external or optimizeDeps.include | ||
// add svelte dependencies to ssr.noExternal unless present in ssr.external | ||
noExternal.push( | ||
...Array.from(new Set(svelteDeps.map((s) => s.name))).filter((x) => { | ||
// @ts-expect-error ssr still flagged in vite | ||
return !config.ssr?.external?.includes(x) && !config.optimizeDeps?.include?.includes(x); | ||
}) | ||
...Array.from(new Set(svelteDeps.map((s) => s.name))).filter( | ||
(x) => !config.ssr?.external?.includes(x) | ||
) | ||
); | ||
const ssr = { | ||
noExternal | ||
noExternal, | ||
external: [] as string[] | ||
}; | ||
@@ -376,3 +434,2 @@ | ||
// during dev, we have to externalize transitive dependencies, see https://github.com/sveltejs/vite-plugin-svelte/issues/281 | ||
// @ts-expect-error ssr still flagged in vite | ||
ssr.external = Array.from( | ||
@@ -383,5 +440,4 @@ new Set(svelteDeps.flatMap((dep) => Object.keys(dep.pkg.dependencies || {}))) | ||
!ssr.noExternal.includes(dep) && | ||
// @ts-expect-error ssr still flagged in vite | ||
!config.ssr?.noExternal?.includes(dep) && | ||
// @ts-expect-error ssr still flagged in vite | ||
// TODO noExternal can be something different than a string array | ||
//!config.ssr?.noExternal?.includes(dep) && | ||
!config.ssr?.external?.includes(dep) | ||
@@ -402,3 +458,6 @@ ); | ||
} | ||
export interface Options { | ||
export type Options = Omit<SvelteOptions, 'vitePlugin'> & PluginOptionsInline; | ||
interface PluginOptionsInline extends PluginOptions { | ||
/** | ||
@@ -412,3 +471,5 @@ * Path to a svelte config file, either absolute or relative to Vite root | ||
configFile?: string | false; | ||
} | ||
export interface PluginOptions { | ||
/** | ||
@@ -431,16 +492,2 @@ * A `picomatch` pattern, or array of patterns, which specifies the files the plugin should | ||
/** | ||
* 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<PreprocessorGroup>; | ||
/** | ||
* Emit Svelte styles as virtual CSS files for Vite and other plugins to process | ||
@@ -453,16 +500,2 @@ * | ||
/** | ||
* 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<CompileOptions, 'filename' | 'format' | 'generate'>; | ||
/** | ||
* Handles warning emitted from the Svelte compiler | ||
*/ | ||
onwarn?: (warning: Warning, defaultHandler?: (warning: Warning) => void) => void; | ||
/** | ||
* Enable or disable Hot Module Replacement. | ||
@@ -511,7 +544,37 @@ * | ||
experimental?: ExperimentalOptions; | ||
} | ||
export interface SvelteOptions { | ||
/** | ||
* Options for SvelteKit | ||
* A list of file extensions to be compiled by Svelte | ||
* | ||
* @default ['.svelte'] | ||
*/ | ||
kit?: KitConfig; | ||
extensions?: string[]; | ||
/** | ||
* An array of preprocessors to transform the Svelte source code before compilation | ||
* | ||
* @see https://svelte.dev/docs#svelte_preprocess | ||
*/ | ||
preprocess?: Arrayable<PreprocessorGroup>; | ||
/** | ||
* 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<CompileOptions, 'filename' | 'format' | 'generate'>; | ||
/** | ||
* Handles warning emitted from the Svelte compiler | ||
*/ | ||
onwarn?: (warning: Warning, defaultHandler?: (warning: Warning) => void) => void; | ||
/** | ||
* Options for vite-plugin-svelte | ||
*/ | ||
vitePlugin?: PluginOptions; | ||
} | ||
@@ -518,0 +581,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
516940
6663
0
+ Added@esbuild/android-arm@0.15.18(transitive)
+ Added@esbuild/linux-loong64@0.15.18(transitive)
+ Addedesbuild@0.15.18(transitive)
+ Addedesbuild-android-64@0.15.18(transitive)
+ Addedesbuild-android-arm64@0.15.18(transitive)
+ Addedesbuild-darwin-64@0.15.18(transitive)
+ Addedesbuild-darwin-arm64@0.15.18(transitive)
+ Addedesbuild-freebsd-64@0.15.18(transitive)
+ Addedesbuild-freebsd-arm64@0.15.18(transitive)
+ Addedesbuild-linux-32@0.15.18(transitive)
+ Addedesbuild-linux-64@0.15.18(transitive)
+ Addedesbuild-linux-arm@0.15.18(transitive)
+ Addedesbuild-linux-arm64@0.15.18(transitive)
+ Addedesbuild-linux-mips64le@0.15.18(transitive)
+ Addedesbuild-linux-ppc64le@0.15.18(transitive)
+ Addedesbuild-linux-riscv64@0.15.18(transitive)
+ Addedesbuild-linux-s390x@0.15.18(transitive)
+ Addedesbuild-netbsd-64@0.15.18(transitive)
+ Addedesbuild-openbsd-64@0.15.18(transitive)
+ Addedesbuild-sunos-64@0.15.18(transitive)
+ Addedesbuild-windows-32@0.15.18(transitive)
+ Addedesbuild-windows-64@0.15.18(transitive)
+ Addedesbuild-windows-arm64@0.15.18(transitive)
+ Addedrollup@2.79.2(transitive)
+ Addedvite@3.2.11(transitive)
- Removed@esbuild/linux-loong64@0.14.54(transitive)
- Removedesbuild@0.14.54(transitive)
- Removedesbuild-android-64@0.14.54(transitive)
- Removedesbuild-android-arm64@0.14.54(transitive)
- Removedesbuild-darwin-64@0.14.54(transitive)
- Removedesbuild-darwin-arm64@0.14.54(transitive)
- Removedesbuild-freebsd-64@0.14.54(transitive)
- Removedesbuild-freebsd-arm64@0.14.54(transitive)
- Removedesbuild-linux-32@0.14.54(transitive)
- Removedesbuild-linux-64@0.14.54(transitive)
- Removedesbuild-linux-arm@0.14.54(transitive)
- Removedesbuild-linux-arm64@0.14.54(transitive)
- Removedesbuild-linux-mips64le@0.14.54(transitive)
- Removedesbuild-linux-ppc64le@0.14.54(transitive)
- Removedesbuild-linux-riscv64@0.14.54(transitive)
- Removedesbuild-linux-s390x@0.14.54(transitive)
- Removedesbuild-netbsd-64@0.14.54(transitive)
- Removedesbuild-openbsd-64@0.14.54(transitive)
- Removedesbuild-sunos-64@0.14.54(transitive)
- Removedesbuild-windows-32@0.14.54(transitive)
- Removedesbuild-windows-64@0.14.54(transitive)
- Removedesbuild-windows-arm64@0.14.54(transitive)
- Removedrollup@2.77.3(transitive)
- Removedvite@2.9.18(transitive)
Updatedkleur@^4.1.5