Socket
Socket
Sign inDemoInstall

@sveltejs/vite-plugin-svelte

Package Overview
Dependencies
Maintainers
4
Versions
107
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sveltejs/vite-plugin-svelte - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

src/utils/__tests__/svelte-version.spec.ts

11

package.json
{
"name": "@sveltejs/vite-plugin-svelte",
"version": "1.1.1",
"version": "1.2.0",
"license": "MIT",

@@ -49,3 +49,4 @@ "author": "dominikg",

"magic-string": "^0.26.7",
"svelte-hmr": "^0.15.0"
"svelte-hmr": "^0.15.1",
"vitefu": "^0.2.1"
},

@@ -66,6 +67,6 @@ "peerDependencies": {

"diff-match-patch": "^1.0.5",
"esbuild": "^0.15.13",
"esbuild": "^0.15.14",
"rollup": "^2.79.1",
"svelte": "^3.52.0",
"tsup": "^6.4.0",
"svelte": "3.53.1",
"tsup": "^6.5.0",
"vite": "^3.2.3"

@@ -72,0 +73,0 @@ },

import fs from 'fs';
import { HmrContext, ModuleNode, Plugin, ResolvedConfig, UserConfig } from 'vite';
// eslint-disable-next-line node/no-missing-import
import { isDepExcluded } from 'vitefu';
import { handleHotUpdate } from './handle-hot-update';

@@ -71,3 +73,3 @@ import { log, logCompilerWarnings } from './utils/log';

// extra vite config
const extraViteConfig = buildExtraViteConfig(options, config);
const extraViteConfig = await buildExtraViteConfig(options, config);
log.debug('additional vite config', extraViteConfig);

@@ -158,17 +160,28 @@ return extraViteConfig;

}
try {
const resolved = resolveViaPackageJsonSvelte(importee, importer, cache);
if (resolved) {
log.debug(
`resolveId resolved ${resolved} via package.json svelte field of ${importee}`
//@ts-expect-error scan
const scan = !!opts?.scan; // scanner phase of optimizeDeps
const isPrebundled =
options.prebundleSvelteLibraries &&
viteConfig.optimizeDeps?.disabled !== true &&
viteConfig.optimizeDeps?.disabled !== (options.isBuild ? 'build' : 'dev') &&
!isDepExcluded(importee, viteConfig.optimizeDeps?.exclude ?? []);
// for prebundled libraries we let vite resolve the prebundling result
// for ssr, during scanning and non-prebundled, we do it
if (ssr || scan || !isPrebundled) {
try {
const resolved = await resolveViaPackageJsonSvelte(importee, importer, cache);
if (resolved) {
log.debug(
`resolveId resolved ${resolved} via package.json svelte field of ${importee}`
);
return resolved;
}
} catch (e) {
log.debug.once(
`error trying to resolve ${importee} from ${importer} via package.json svelte field `,
e
);
return resolved;
// this error most likely happens due to non-svelte related importee/importers so swallow it here
// in case it really way a svelte library, users will notice anyway. (lib not working due to failed resolve)
}
} catch (e) {
log.debug.once(
`error trying to resolve ${importee} from ${importer} via package.json svelte field `,
e
);
// this error most likely happens due to non-svelte related importee/importers so swallow it here
// in case it really way a svelte library, users will notice anyway. (lib not working due to failed resolve)
}

@@ -175,0 +188,0 @@ },

@@ -71,4 +71,5 @@ import { CompileOptions, ResolvedOptions } from './options';

const compiled = compile(finalCode, finalCompileOptions);
if (emitCss && compiled.css.code) {
const hasCss = compiled.css?.code?.trim().length > 0;
// compiler might not emit css with mode none or it may be empty
if (emitCss && hasCss) {
// TODO properly update sourcemap?

@@ -83,3 +84,3 @@ compiled.js.code += `\nimport ${JSON.stringify(cssId)};\n`;

compiledCode: compiled.js.code,
hotOptions: options.hot,
hotOptions: { ...options.hot, injectCss: options.hot?.injectCss === true && hasCss },
compiled,

@@ -86,0 +87,0 @@ originalCode: code,

@@ -1,116 +0,23 @@

import { log } from './log';
import path from 'path';
import fs from 'fs';
import { createRequire } from 'module';
import fs from 'fs/promises';
// eslint-disable-next-line node/no-missing-import
import { findDepPkgJsonPath } from 'vitefu';
export function findRootSvelteDependencies(root: string, cwdFallback = true): SvelteDependency[] {
log.debug(`findSvelteDependencies: searching svelte dependencies in ${root}`);
const pkgFile = path.join(root, 'package.json');
if (!fs.existsSync(pkgFile)) {
if (cwdFallback) {
const cwd = process.cwd();
if (root !== cwd) {
log.debug(`no package.json found in vite root ${root}`);
return findRootSvelteDependencies(cwd, false);
}
}
log.warn(`no package.json found, findRootSvelteDependencies failed`);
return [];
}
const pkg = parsePkg(root);
if (!pkg) {
return [];
}
const deps = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.devDependencies || {})
].filter((dep) => !is_common_without_svelte_field(dep));
return getSvelteDependencies(deps, root);
interface DependencyData {
dir: string;
pkg: Record<string, any>;
}
function getSvelteDependencies(
deps: string[],
pkgDir: string,
path: string[] = []
): SvelteDependency[] {
const result = [];
const localRequire = createRequire(`${pkgDir}/package.json`);
const resolvedDeps = deps
.map((dep) => resolveDependencyData(dep, localRequire))
.filter(Boolean) as DependencyData[];
for (const { pkg, dir } of resolvedDeps) {
const type = getSvelteDependencyType(pkg);
if (!type) continue;
result.push({ name: pkg.name, type, pkg, dir, path });
// continue crawling for component libraries so we can optimize them, js libraries are fine
if (type === 'component-library' && pkg.dependencies) {
let dependencyNames = Object.keys(pkg.dependencies);
const circular = dependencyNames.filter((name) => path.includes(name));
if (circular.length > 0) {
log.warn.enabled &&
log.warn(
`skipping circular svelte dependencies in automated vite optimizeDeps handling`,
circular.map((x) => path.concat(x).join('>'))
);
dependencyNames = dependencyNames.filter((name) => !path.includes(name));
}
if (path.length === 3) {
log.debug.once(`encountered deep svelte dependency tree: ${path.join('>')}`);
}
result.push(...getSvelteDependencies(dependencyNames, dir, path.concat(pkg.name)));
}
}
return result;
}
export function resolveDependencyData(
export async function resolveDependencyData(
dep: string,
localRequire: NodeRequire
): DependencyData | void {
parent: string
): Promise<DependencyData | undefined> {
const depDataPath = await findDepPkgJsonPath(dep, parent);
if (!depDataPath) return undefined;
try {
const pkgJson = `${dep}/package.json`;
const pkg = localRequire(pkgJson);
const dir = path.dirname(localRequire.resolve(pkgJson));
return { dir, pkg };
} catch (e) {
log.debug.once(`dependency ${dep} does not export package.json`, e);
// walk up from default export until we find package.json with name=dep
try {
let dir = path.dirname(localRequire.resolve(dep));
while (dir) {
const pkg = parsePkg(dir, true);
if (pkg && pkg.name === dep) {
return { dir, pkg };
}
const parent = path.dirname(dir);
if (parent === dir) {
break;
}
dir = parent;
}
} catch (e) {
log.debug.once(`error while trying to find package.json of ${dep}`, e);
}
}
log.debug.once(`failed to resolve ${dep}`);
}
function parsePkg(dir: string, silent = false): Pkg | void {
const pkgFile = path.join(dir, 'package.json');
try {
return JSON.parse(fs.readFileSync(pkgFile, 'utf-8'));
} catch (e) {
!silent && log.warn.enabled && log.warn(`failed to parse ${pkgFile}`, e);
}
}
function getSvelteDependencyType(pkg: Pkg): SvelteDependencyType | undefined {
if (isSvelteComponentLib(pkg)) {
return 'component-library';
} else if (isSvelteLib(pkg)) {
return 'js-library';
} else {
return {
dir: path.dirname(depDataPath),
pkg: JSON.parse(await fs.readFile(depDataPath, 'utf-8'))
};
} catch {
return undefined;

@@ -120,10 +27,2 @@ }

function isSvelteComponentLib(pkg: Pkg) {
return !!pkg.svelte;
}
function isSvelteLib(pkg: Pkg) {
return !!pkg.dependencies?.svelte || !!pkg.peerDependencies?.svelte;
}
const COMMON_DEPENDENCIES_WITHOUT_SVELTE_FIELD = [

@@ -177,3 +76,3 @@ '@lukeed/uuid',

*/
export function is_common_without_svelte_field(dependency: string): boolean {
export function isCommonDepWithoutSvelteField(dependency: string): boolean {
return (

@@ -189,56 +88,1 @@ COMMON_DEPENDENCIES_WITHOUT_SVELTE_FIELD.includes(dependency) ||

}
export function needsOptimization(dep: string, localRequire: NodeRequire): boolean {
const depData = resolveDependencyData(dep, localRequire);
if (!depData) return false;
const pkg = depData.pkg;
// only optimize if is cjs, using the below as heuristic
// see https://github.com/sveltejs/vite-plugin-svelte/issues/162
const hasEsmFields = pkg.module || pkg.exports;
if (hasEsmFields) return false;
if (pkg.main) {
// ensure entry is js so vite can prebundle it
// see https://github.com/sveltejs/vite-plugin-svelte/issues/233
const entryExt = path.extname(pkg.main);
return !entryExt || entryExt === '.js' || entryExt === '.cjs';
} else {
// check if has implicit index.js entrypoint
// https://github.com/sveltejs/vite-plugin-svelte/issues/281
try {
localRequire.resolve(`${dep}/index.js`);
return true;
} catch {
return false;
}
}
}
interface DependencyData {
dir: string;
pkg: Pkg;
}
export interface SvelteDependency {
name: string;
type: SvelteDependencyType;
dir: string;
pkg: Pkg;
path: string[];
}
// component-library => exports svelte components
// js-library => only uses svelte api, no components
export type SvelteDependencyType = 'component-library' | 'js-library';
export interface Pkg {
name: string;
svelte?: string;
dependencies?: DependencyList;
devDependencies?: DependencyList;
peerDependencies?: DependencyList;
[key: string]: any;
}
export interface DependencyList {
[key: string]: string;
}

@@ -8,5 +8,7 @@ import { promises as fs } from 'fs';

import { toESBuildError } from './error';
import { atLeastSvelte } from './svelte-version';
type EsbuildOptions = NonNullable<DepOptimizationOptions['esbuildOptions']>;
type EsbuildPlugin = NonNullable<EsbuildOptions['plugins']>[number];
const isCssString = atLeastSvelte('3.53.0');

@@ -43,5 +45,9 @@ export const facadeEsbuildSveltePluginName = 'vite-plugin-svelte:facade';

): Promise<string> {
let css = options.compilerOptions.css;
if (css !== 'none') {
css = isCssString ? 'injected' : true;
}
const compileOptions: CompileOptions = {
...options.compilerOptions,
css: true,
css,
filename,

@@ -48,0 +54,0 @@ format: 'esm',

/* eslint-disable no-unused-vars */
import {
ConfigEnv,
DepOptimizationOptions,
ResolvedConfig,
UserConfig,
ViteDevServer,
normalizePath
} from 'vite';
import { ConfigEnv, ResolvedConfig, UserConfig, ViteDevServer, normalizePath } from 'vite';
import { log } from './log';

@@ -24,8 +17,19 @@ import { loadSvelteConfig } from './load-svelte-config';

import path from 'path';
import { findRootSvelteDependencies, needsOptimization, SvelteDependency } from './dependencies';
import { createRequire } from 'module';
import { esbuildSveltePlugin, facadeEsbuildSveltePluginName } from './esbuild';
import { addExtraPreprocessors } from './preprocess';
import deepmerge from 'deepmerge';
import {
crawlFrameworkPkgs,
isDepExcluded,
isDepExternaled,
isDepIncluded,
isDepNoExternaled
// eslint-disable-next-line node/no-missing-import
} from 'vitefu';
import { atLeastSvelte } from './svelte-version';
import { isCommonDepWithoutSvelteField } from './dependencies';
// svelte 3.53.0 changed compilerOptions.css from boolean to string | boolen, use string when available
const cssAsString = atLeastSvelte('3.53.0');
const allowedPluginOptions = new Set([

@@ -174,2 +178,7 @@ 'include',

): ResolvedOptions {
const css = cssAsString
? preResolveOptions.emitCss
? 'external'
: 'injected'
: !preResolveOptions.emitCss;
const defaultOptions: Partial<Options> = {

@@ -179,7 +188,7 @@ hot: viteConfig.isProduction

: {
injectCss: !preResolveOptions.emitCss,
injectCss: css === true || css === 'injected',
partialAccept: !!viteConfig.experimental?.hmrPartialAccept
},
compilerOptions: {
css: !preResolveOptions.emitCss,
css,
dev: !viteConfig.isProduction

@@ -214,7 +223,9 @@ }

}
if (options.compilerOptions.css) {
const css = options.compilerOptions.css;
if (css === true || css === 'injected') {
const forcedCss = cssAsString ? 'external' : false;
log.warn(
'hmr and emitCss are enabled but compilerOptions.css is true, forcing it to false'
`hmr and emitCss are enabled but compilerOptions.css is ${css}, forcing it to ${forcedCss}`
);
options.compilerOptions.css = false;
options.compilerOptions.css = forcedCss;
}

@@ -232,7 +243,9 @@ } else {

}
if (!options.compilerOptions.css) {
const css = options.compilerOptions.css;
if (!(css === true || css === 'injected')) {
const forcedCss = cssAsString ? 'injected' : true;
log.warn(
'hmr with emitCss disabled requires compilerOptions.css to be enabled, forcing it to true'
`hmr with emitCss disabled requires compilerOptions.css to be enabled, forcing it to ${forcedCss}`
);
options.compilerOptions.css = true;
options.compilerOptions.css = forcedCss;
}

@@ -281,16 +294,5 @@ }

// @ts-expect-error kit is not typed to avoid dependency on sveltekit
if (options?.kit != null) {
// @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 (
options.compilerOptions.hydratable != null &&
options.compilerOptions.hydratable !== hydratable
) {
log.warn(
`Conflicting values "compilerOptions.hydratable: ${options.compilerOptions.hydratable}" and "kit.browser.hydrate: ${kit_browser_hydrate}" in your svelte config. You should remove "compilerOptions.hydratable".`
);
}
log.debug(`Setting compilerOptions.hydratable: ${hydratable} for SvelteKit`);
options.compilerOptions.hydratable = hydratable;
if (options?.kit != null && options.compilerOptions.hydratable == null) {
log.debug(`Setting compilerOptions.hydratable = true for SvelteKit`);
options.compilerOptions.hydratable = true;
}

@@ -315,8 +317,6 @@ }

export function buildExtraViteConfig(
export async function buildExtraViteConfig(
options: PreResolvedOptions,
config: UserConfig
): Partial<UserConfig> {
// extra handling for svelte dependencies in the project
const svelteDeps = findRootSvelteDependencies(options.root);
): Promise<Partial<UserConfig>> {
const extraViteConfig: Partial<UserConfig> = {

@@ -333,26 +333,46 @@ resolve: {

extraViteConfig.optimizeDeps = buildOptimizeDepsForSvelte(
svelteDeps,
options,
config.optimizeDeps
);
const extraSvelteConfig = buildExtraConfigForSvelte(config);
const extraDepsConfig = await buildExtraConfigForDependencies(options, config);
// merge extra svelte and deps config, but make sure dep values are not contradicting svelte
extraViteConfig.optimizeDeps = {
include: [
...extraSvelteConfig.optimizeDeps.include,
...extraDepsConfig.optimizeDeps.include.filter(
(dep) => !isDepExcluded(dep, extraSvelteConfig.optimizeDeps.exclude)
)
],
exclude: [
...extraSvelteConfig.optimizeDeps.exclude,
...extraDepsConfig.optimizeDeps.exclude.filter(
(dep) => !isDepIncluded(dep, extraSvelteConfig.optimizeDeps.include)
)
]
};
extraViteConfig.ssr = {
external: [
...extraSvelteConfig.ssr.external,
...extraDepsConfig.ssr.external.filter(
(dep) => !isDepNoExternaled(dep, extraSvelteConfig.ssr.noExternal)
)
],
noExternal: [
...extraSvelteConfig.ssr.noExternal,
...extraDepsConfig.ssr.noExternal.filter(
(dep) => !isDepExternaled(dep, extraSvelteConfig.ssr.external)
)
]
};
// handle prebundling for svelte files
if (options.prebundleSvelteLibraries) {
extraViteConfig.optimizeDeps = {
...extraViteConfig.optimizeDeps,
// Experimental Vite API to allow these extensions to be scanned and prebundled
// @ts-ignore
extensions: options.extensions ?? ['.svelte'],
// Add esbuild plugin to prebundle Svelte files.
// Currently a placeholder as more information is needed after Vite config is resolved,
// the real Svelte plugin is added in `patchResolvedViteConfig()`
esbuildOptions: {
plugins: [{ name: facadeEsbuildSveltePluginName, setup: () => {} }]
}
extraViteConfig.optimizeDeps.extensions = options.extensions ?? ['.svelte'];
// Add esbuild plugin to prebundle Svelte files.
// Currently a placeholder as more information is needed after Vite config is resolved,
// the real Svelte plugin is added in `patchResolvedViteConfig()`
extraViteConfig.optimizeDeps.esbuildOptions = {
plugins: [{ name: facadeEsbuildSveltePluginName, setup: () => {} }]
};
}
// @ts-ignore
extraViteConfig.ssr = buildSSROptionsForSvelte(svelteDeps, options, config, extraViteConfig);
// enable hmrPartialAccept if not explicitly disabled

@@ -368,24 +388,71 @@ if (

}
return extraViteConfig;
}
function buildOptimizeDepsForSvelte(
svelteDeps: SvelteDependency[],
options: PreResolvedOptions,
optimizeDeps?: DepOptimizationOptions
): DepOptimizationOptions {
async function buildExtraConfigForDependencies(options: PreResolvedOptions, config: UserConfig) {
// extra handling for svelte dependencies in the project
const depsConfig = await crawlFrameworkPkgs({
root: options.root,
isBuild: options.isBuild,
viteUserConfig: config,
isFrameworkPkgByJson(pkgJson) {
return !!pkgJson.svelte;
},
isSemiFrameworkPkgByJson(pkgJson) {
return !!pkgJson.dependencies?.svelte || !!pkgJson.peerDependencies?.svelte;
},
isFrameworkPkgByName(pkgName) {
const isNotSveltePackage = isCommonDepWithoutSvelteField(pkgName);
if (isNotSveltePackage) {
return false;
} else {
return undefined;
}
}
});
log.debug('extra config for dependencies generated by vitefu', depsConfig);
if (options.prebundleSvelteLibraries) {
// prebundling enabled, so we don't need extra dependency excludes
depsConfig.optimizeDeps.exclude = [];
// but keep dependency reinclusions of explicit user excludes
const userExclude = config.optimizeDeps?.exclude;
depsConfig.optimizeDeps.include = !userExclude
? []
: depsConfig.optimizeDeps.include.filter((dep: string) => {
// reincludes look like this: foo > bar > baz
// in case foo or bar are excluded, we have to retain the reinclude even with prebundling
return (
dep.includes('>') &&
dep
.split('>')
.slice(0, -1)
.some((d) => isDepExcluded(d.trim(), userExclude))
);
});
}
if (options.disableDependencyReinclusion === true) {
depsConfig.optimizeDeps.include = depsConfig.optimizeDeps.include.filter(
(dep) => !dep.includes('>')
);
} else if (Array.isArray(options.disableDependencyReinclusion)) {
const disabledDeps = options.disableDependencyReinclusion;
depsConfig.optimizeDeps.include = depsConfig.optimizeDeps.include.filter((dep) => {
if (!dep.includes('>')) return true;
const trimDep = dep.replace(/\s+/g, '');
return disabledDeps.some((disabled) => trimDep.includes(`${disabled}>`));
});
}
log.debug('post-processed extra config for dependencies', depsConfig);
return depsConfig;
}
function buildExtraConfigForSvelte(config: UserConfig) {
// include svelte imports for optimization unless explicitly excluded
const include: string[] = [];
const exclude: string[] = ['svelte-hmr'];
const isIncluded = (dep: string) => include.includes(dep) || optimizeDeps?.include?.includes(dep);
const isExcluded = (dep: string) => {
return (
exclude.includes(dep) ||
// vite optimizeDeps.exclude works for subpackages too
// see https://github.com/vitejs/vite/blob/c87763c1418d1ba876eae13d139eba83ac6f28b2/packages/vite/src/node/optimizer/scan.ts#L293
optimizeDeps?.exclude?.some((id: string) => dep === id || id.startsWith(`${dep}/`))
);
};
if (!isExcluded('svelte')) {
if (!isDepExcluded('svelte', config.optimizeDeps?.exclude ?? [])) {
const svelteImportsToInclude = SVELTE_IMPORTS.filter((x) => x !== 'svelte/ssr'); // not used on clientside

@@ -395,82 +462,14 @@ log.debug(

);
include.push(...svelteImportsToInclude.filter((x) => !isIncluded(x)));
include.push(...svelteImportsToInclude);
} else {
log.debug('"svelte" is excluded in optimizeDeps.exclude, skipped adding it to include.');
}
// If we prebundle svelte libraries, we can skip the whole prebundling dance below
if (options.prebundleSvelteLibraries) {
return { include, exclude };
}
// only svelte component libraries needs to be processed for optimizeDeps, js libraries work fine
svelteDeps = svelteDeps.filter((dep) => dep.type === 'component-library');
const svelteDepsToExclude = Array.from(new Set(svelteDeps.map((dep) => dep.name))).filter(
(dep) => !isIncluded(dep)
);
log.debug(`automatically excluding found svelte dependencies: ${svelteDepsToExclude.join(', ')}`);
exclude.push(...svelteDepsToExclude.filter((x) => !isExcluded(x)));
if (options.disableDependencyReinclusion !== true) {
const disabledReinclusions = options.disableDependencyReinclusion || [];
if (disabledReinclusions.length > 0) {
log.debug(`not reincluding transitive dependencies of`, disabledReinclusions);
}
const transitiveDepsToInclude = svelteDeps
.filter((dep) => !disabledReinclusions.includes(dep.name) && isExcluded(dep.name))
.flatMap((dep) => {
const localRequire = createRequire(`${dep.dir}/package.json`);
return Object.keys(dep.pkg.dependencies || {})
.filter((depOfDep) => !isExcluded(depOfDep) && needsOptimization(depOfDep, localRequire))
.map((depOfDep) => dep.path.concat(dep.name, depOfDep).join(' > '));
});
log.debug(
`reincluding transitive dependencies of excluded svelte dependencies`,
transitiveDepsToInclude
);
include.push(...transitiveDepsToInclude);
}
return { include, exclude };
}
function buildSSROptionsForSvelte(
svelteDeps: SvelteDependency[],
options: ResolvedOptions,
config: UserConfig
): any {
const noExternal: (string | RegExp)[] = [];
const external: string[] = [];
// add svelte to ssr.noExternal unless it is present in ssr.external
// so we can resolve it with svelte/ssr
if (!config.ssr?.external?.includes('svelte')) {
if (!isDepExternaled('svelte', config.ssr?.external ?? [])) {
noExternal.push('svelte', /^svelte\//);
}
// add svelte dependencies to ssr.noExternal unless present in ssr.external
noExternal.push(
...Array.from(new Set(svelteDeps.map((s) => s.name))).filter(
(x) => !config.ssr?.external?.includes(x)
)
);
const ssr = {
noExternal,
external: [] as string[]
};
if (options.isServe) {
// during dev, we have to externalize transitive dependencies, see https://github.com/sveltejs/vite-plugin-svelte/issues/281
ssr.external = Array.from(
new Set(svelteDeps.flatMap((dep) => Object.keys(dep.pkg.dependencies || {})))
).filter(
(dep) =>
!ssr.noExternal.includes(dep) &&
// TODO noExternal can be something different than a string array
//!config.ssr?.noExternal?.includes(dep) &&
!config.ssr?.external?.includes(dep)
);
}
return ssr;
return { optimizeDeps: { include, exclude }, ssr: { noExternal, external } };
}

@@ -477,0 +476,0 @@

import path from 'path';
import { builtinModules, createRequire } from 'module';
import { is_common_without_svelte_field, resolveDependencyData } from './dependencies';
import { builtinModules } from 'module';
import { resolveDependencyData, isCommonDepWithoutSvelteField } from './dependencies';
import { VitePluginSvelteCache } from './vite-plugin-svelte-cache';
export function resolveViaPackageJsonSvelte(
export async function resolveViaPackageJsonSvelte(
importee: string,
importer: string | undefined,
cache: VitePluginSvelteCache
): string | void {
): Promise<string | void> {
if (

@@ -15,3 +15,3 @@ importer &&

!isNodeInternal(importee) &&
!is_common_without_svelte_field(importee)
!isCommonDepWithoutSvelteField(importee)
) {

@@ -22,4 +22,3 @@ const cached = cache.getResolvedSvelteField(importee, importer);

}
const localRequire = createRequire(importer);
const pkgData = resolveDependencyData(importee, localRequire);
const pkgData = await resolveDependencyData(importee, importer);
if (pkgData) {

@@ -26,0 +25,0 @@ const { pkg, dir } = pkgData;

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc