@sveltejs/vite-plugin-svelte
Advanced tools
Comparing version 1.0.0-next.43 to 1.0.0-next.44
@@ -29,3 +29,3 @@ var __defProp = Object.defineProperty; | ||
// src/index.ts | ||
import fs7 from "fs"; | ||
import fs8 from "fs"; | ||
@@ -575,3 +575,3 @@ // src/utils/log.ts | ||
} | ||
function getSvelteDependencies(deps, pkgDir, path8 = []) { | ||
function getSvelteDependencies(deps, pkgDir, path9 = []) { | ||
const result = []; | ||
@@ -584,14 +584,14 @@ const localRequire = createRequire2(`${pkgDir}/package.json`); | ||
continue; | ||
result.push({ name: pkg.name, type, pkg, dir, path: path8 }); | ||
result.push({ name: pkg.name, type, pkg, dir, path: path9 }); | ||
if (type === "component-library" && pkg.dependencies) { | ||
let dependencyNames = Object.keys(pkg.dependencies); | ||
const circular = dependencyNames.filter((name) => path8.includes(name)); | ||
const circular = dependencyNames.filter((name) => path9.includes(name)); | ||
if (circular.length > 0) { | ||
log.warn.enabled && log.warn(`skipping circular svelte dependencies in automated vite optimizeDeps handling`, circular.map((x) => path8.concat(x).join(">"))); | ||
dependencyNames = dependencyNames.filter((name) => !path8.includes(name)); | ||
log.warn.enabled && log.warn(`skipping circular svelte dependencies in automated vite optimizeDeps handling`, circular.map((x) => path9.concat(x).join(">"))); | ||
dependencyNames = dependencyNames.filter((name) => !path9.includes(name)); | ||
} | ||
if (path8.length === 3) { | ||
log.debug.once(`encountered deep svelte dependency tree: ${path8.join(">")}`); | ||
if (path9.length === 3) { | ||
log.debug.once(`encountered deep svelte dependency tree: ${path9.join(">")}`); | ||
} | ||
result.push(...getSvelteDependencies(dependencyNames, dir, path8.concat(pkg.name))); | ||
result.push(...getSvelteDependencies(dependencyNames, dir, path9.concat(pkg.name))); | ||
} | ||
@@ -1346,4 +1346,4 @@ } | ||
} | ||
getDependants(path8) { | ||
const dependants = this._dependants.get(path8); | ||
getDependants(path9) { | ||
const dependants = this._dependants.get(path9); | ||
return dependants ? [...dependants] : []; | ||
@@ -1513,3 +1513,6 @@ } | ||
// src/ui/inspector/plugin.ts | ||
import { createRequire as createRequire5 } from "module"; | ||
import { normalizePath as normalizePath3 } from "vite"; | ||
import path8 from "path"; | ||
import { fileURLToPath } from "url"; | ||
import fs7 from "fs"; | ||
var defaultInspectorOptions = { | ||
@@ -1522,7 +1525,12 @@ toggleKeyCombo: process.platform === "win32" ? "control-shift" : "meta-shift", | ||
}; | ||
function getInspectorPath() { | ||
const pluginPath = normalizePath3(path8.dirname(fileURLToPath(import.meta.url))); | ||
return pluginPath.replace(/\/vite-plugin-svelte\/dist$/, "/vite-plugin-svelte/src/ui/inspector/"); | ||
} | ||
function svelteInspector() { | ||
let root; | ||
let rootRequire; | ||
const inspectorPath = getInspectorPath(); | ||
log.debug.enabled && log.debug(`svelte inspector path: ${inspectorPath}`); | ||
let inspectorOptions; | ||
let append_to; | ||
let appendTo; | ||
let disabled = false; | ||
return { | ||
@@ -1539,7 +1547,5 @@ name: "vite-plugin-svelte:inspector", | ||
if (!vps || !inspectorOptions) { | ||
this.resolveId = this.load = this.transformIndexHtml = this.transform = () => { | ||
}; | ||
log.debug("inspector disabled, could not find config"); | ||
disabled = true; | ||
} else { | ||
root = config.root || process.cwd(); | ||
rootRequire = createRequire5(root); | ||
if (vps.api.options.kit && !inspectorOptions.appendTo) { | ||
@@ -1549,38 +1555,38 @@ const out_dir = vps.api.options.kit.outDir || ".svelte-kit"; | ||
} | ||
append_to = inspectorOptions.appendTo; | ||
appendTo = inspectorOptions.appendTo; | ||
} | ||
}, | ||
async resolveId(importee, importer, options) { | ||
if (options == null ? void 0 : options.ssr) { | ||
if ((options == null ? void 0 : options.ssr) || disabled) { | ||
return; | ||
} | ||
if (importee === "virtual:svelte-inspector-options") { | ||
if (importee.startsWith("virtual:svelte-inspector-options")) { | ||
return importee; | ||
} else if (importee.startsWith("virtual:svelte-inspector-path:")) { | ||
const resolved = importee.replace("virtual:svelte-inspector-path:", inspectorPath); | ||
log.debug.enabled && log.debug(`resolved ${importee} with ${resolved}`); | ||
return resolved; | ||
} | ||
if (importee.startsWith("virtual:svelte-inspector:")) { | ||
const file = importee.replace("virtual:svelte-inspector:", "@sveltejs/vite-plugin-svelte/src/ui/inspector/"); | ||
const path8 = rootRequire.resolve(file); | ||
if (path8) { | ||
return path8; | ||
} else { | ||
log.error.once(`failed to resolve ${file} for ${importee} from ${root}`); | ||
} | ||
}, | ||
async load(id, options) { | ||
if ((options == null ? void 0 : options.ssr) || disabled) { | ||
return; | ||
} | ||
}, | ||
load(id) { | ||
if (id === "virtual:svelte-inspector-options") { | ||
return `export default ${JSON.stringify(inspectorOptions ?? {})}`; | ||
} else if (id.startsWith(inspectorPath)) { | ||
return await fs7.promises.readFile(id, "utf-8"); | ||
} | ||
}, | ||
transform(code, id, options) { | ||
if ((options == null ? void 0 : options.ssr) || !append_to) { | ||
if ((options == null ? void 0 : options.ssr) || disabled || !appendTo) { | ||
return; | ||
} | ||
if (id.endsWith(append_to)) { | ||
if (id.endsWith(appendTo)) { | ||
return { code: `${code} | ||
import 'virtual:svelte-inspector:load-inspector.ts'` }; | ||
import 'virtual:svelte-inspector-path:load-inspector.js'` }; | ||
} | ||
}, | ||
transformIndexHtml(html) { | ||
if (append_to) { | ||
if (disabled || appendTo) { | ||
return; | ||
@@ -1596,3 +1602,3 @@ } | ||
type: "module", | ||
src: "/@id/virtual:svelte-inspector:load-inspector.ts" | ||
src: "/@id/virtual:svelte-inspector-path:load-inspector.js" | ||
} | ||
@@ -1671,3 +1677,3 @@ } | ||
log.debug(`load returns raw content for ${filename}`); | ||
return fs7.readFileSync(filename, "utf-8"); | ||
return fs8.readFileSync(filename, "utf-8"); | ||
} | ||
@@ -1674,0 +1680,0 @@ } |
{ | ||
"name": "@sveltejs/vite-plugin-svelte", | ||
"version": "1.0.0-next.43", | ||
"version": "1.0.0-next.44", | ||
"license": "MIT", | ||
@@ -65,14 +65,13 @@ "author": "dominikg", | ||
"diff-match-patch": "^1.0.5", | ||
"esbuild": "^0.14.36", | ||
"rollup": "^2.70.2", | ||
"svelte": "^3.47.0", | ||
"tsup": "^5.12.5", | ||
"esbuild": "^0.14.38", | ||
"rollup": "^2.72.1", | ||
"svelte": "^3.48.0", | ||
"tsup": "^5.12.7", | ||
"vite": "^2.9.8" | ||
}, | ||
"scripts": { | ||
"dev": "pnpm run build:ci -- --sourcemap --watch src", | ||
"dev": "pnpm build:ci --sourcemap --watch src", | ||
"build:ci": "rimraf dist && tsup-node src/index.ts --format esm,cjs --no-splitting --target node14", | ||
"build": "pnpm run build:ci -- --dts --sourcemap" | ||
}, | ||
"readme": "# @sveltejs/vite-plugin-svelte\n\nThe official [Svelte](https://svelte.dev) plugin for [Vite](https://vitejs.dev).\n\n## Usage\n\n```js\n// vite.config.js\nimport { defineConfig } from 'vite';\nimport { svelte } from '@sveltejs/vite-plugin-svelte';\n\nexport default defineConfig({\n plugins: [\n svelte({\n /* plugin options */\n })\n ]\n});\n```\n\n## Documentation\n\n- [Plugin options](../../docs/config.md)\n- [FAQ](../../docs/faq.md)\n\n## License\n\n[MIT](./LICENSE)\n" | ||
"build": "pnpm build:ci --dts --sourcemap" | ||
} | ||
} |
@@ -1,5 +0,7 @@ | ||
import { createRequire } from 'module'; | ||
import { Plugin } from 'vite'; | ||
import { Plugin, normalizePath } from 'vite'; | ||
import { log } from '../../utils/log'; | ||
import { InspectorOptions } from '../../utils/options'; | ||
import path from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
import fs from 'fs'; | ||
@@ -14,7 +16,13 @@ const defaultInspectorOptions: InspectorOptions = { | ||
function getInspectorPath() { | ||
const pluginPath = normalizePath(path.dirname(fileURLToPath(import.meta.url))); | ||
return pluginPath.replace(/\/vite-plugin-svelte\/dist$/, '/vite-plugin-svelte/src/ui/inspector/'); | ||
} | ||
export function svelteInspector(): Plugin { | ||
let root: string; | ||
let rootRequire: NodeRequire; | ||
const inspectorPath = getInspectorPath(); | ||
log.debug.enabled && log.debug(`svelte inspector path: ${inspectorPath}`); | ||
let inspectorOptions: InspectorOptions; | ||
let append_to: string | undefined; | ||
let appendTo: string | undefined; | ||
let disabled = false; | ||
@@ -35,7 +43,5 @@ return { | ||
if (!vps || !inspectorOptions) { | ||
// disabled, turn all hooks into noops | ||
this.resolveId = this.load = this.transformIndexHtml = this.transform = () => {}; | ||
log.debug('inspector disabled, could not find config'); | ||
disabled = true; | ||
} else { | ||
root = config.root || process.cwd(); | ||
rootRequire = createRequire(root); | ||
if (vps.api.options.kit && !inspectorOptions.appendTo) { | ||
@@ -45,3 +51,3 @@ const out_dir = vps.api.options.kit.outDir || '.svelte-kit'; | ||
} | ||
append_to = inspectorOptions.appendTo; | ||
appendTo = inspectorOptions.appendTo; | ||
} | ||
@@ -51,37 +57,36 @@ }, | ||
async resolveId(importee: string, importer, options) { | ||
if (options?.ssr) { | ||
if (options?.ssr || disabled) { | ||
return; | ||
} | ||
if (importee === 'virtual:svelte-inspector-options') { | ||
if (importee.startsWith('virtual:svelte-inspector-options')) { | ||
return importee; | ||
} else if (importee.startsWith('virtual:svelte-inspector-path:')) { | ||
const resolved = importee.replace('virtual:svelte-inspector-path:', inspectorPath); | ||
log.debug.enabled && log.debug(`resolved ${importee} with ${resolved}`); | ||
return resolved; | ||
} | ||
if (importee.startsWith('virtual:svelte-inspector:')) { | ||
// this is needed because the plugin itself is not a dependency of the app so regular resolve may not find it | ||
const file = importee.replace( | ||
'virtual:svelte-inspector:', | ||
'@sveltejs/vite-plugin-svelte/src/ui/inspector/' | ||
); | ||
const path = rootRequire.resolve(file); | ||
if (path) { | ||
return path; | ||
} else { | ||
log.error.once(`failed to resolve ${file} for ${importee} from ${root}`); | ||
} | ||
}, | ||
async load(id, options) { | ||
if (options?.ssr || disabled) { | ||
return; | ||
} | ||
}, | ||
load(id) { | ||
if (id === 'virtual:svelte-inspector-options') { | ||
return `export default ${JSON.stringify(inspectorOptions ?? {})}`; | ||
} else if (id.startsWith(inspectorPath)) { | ||
// read file ourselves to avoid getting shut out by vites fs.allow check | ||
return await fs.promises.readFile(id, 'utf-8'); | ||
} | ||
}, | ||
transform(code: string, id: string, options?: { ssr?: boolean }) { | ||
if (options?.ssr || !append_to) { | ||
if (options?.ssr || disabled || !appendTo) { | ||
return; | ||
} | ||
if (id.endsWith(append_to)) { | ||
return { code: `${code}\nimport 'virtual:svelte-inspector:load-inspector.ts'` }; | ||
if (id.endsWith(appendTo)) { | ||
return { code: `${code}\nimport 'virtual:svelte-inspector-path:load-inspector.js'` }; | ||
} | ||
}, | ||
transformIndexHtml(html) { | ||
if (append_to) { | ||
if (disabled || appendTo) { | ||
return; | ||
@@ -98,3 +103,3 @@ } | ||
// /@id/ is needed, otherwise the virtual: is seen as protocol by browser and cors error happens | ||
src: '/@id/virtual:svelte-inspector:load-inspector.ts' | ||
src: '/@id/virtual:svelte-inspector-path:load-inspector.js' | ||
} | ||
@@ -101,0 +106,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 not supported yet
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
481400
6223
31