strip dangling svelte imports (#6171)

This commit is contained in:
pngwn 2023-10-31 05:31:33 +00:00 committed by GitHub
parent 287fe67828
commit 28322422cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 33 additions and 17 deletions

View File

@ -0,0 +1,10 @@
---
"@gradio/accordion": minor
"@gradio/file": minor
"@gradio/image": minor
"@gradio/model3d": minor
"@gradio/preview": minor
"gradio": minor
---
feat:strip dangling svelte imports

View File

@ -5,7 +5,7 @@
import type { LoadingStatus } from "@gradio/statustracker";
import Column from "@gradio/column";
import type { Gradio } from "js/utils/src";
import type { Gradio } from "@gradio/utils";
export let label: string;
export let elem_id: string;

View File

@ -10,7 +10,8 @@
"dependencies": {
"@gradio/atoms": "workspace:^",
"@gradio/column": "workspace:^",
"@gradio/statustracker": "workspace:^"
"@gradio/statustracker": "workspace:^",
"@gradio/utils": "workspace:0.2.0-beta.6"
},
"exports": {
".": "./Index.svelte",

View File

@ -3,7 +3,7 @@
import { BlockLabel, Empty } from "@gradio/atoms";
import { File } from "@gradio/icons";
import FilePreview from "./FilePreview.svelte";
import type { I18nFormatter } from "js/utils/src";
import type { I18nFormatter } from "@gradio/utils";
export let value: FileData | FileData[] | null = null;
export let label: string;

View File

@ -6,7 +6,7 @@
import { File } from "@gradio/icons";
import FilePreview from "./FilePreview.svelte";
import type { I18nFormatter } from "js/utils/src";
import type { I18nFormatter } from "@gradio/utils";
export let value: null | FileData | FileData[];

View File

@ -1,7 +1,7 @@
<script lang="ts">
import { createEventDispatcher, onMount, tick } from "svelte";
import { Camera, Circle, Square, DropdownArrow } from "@gradio/icons";
import type { I18nFormatter } from "js/utils/src";
import type { I18nFormatter } from "@gradio/utils";
let video_source: HTMLVideoElement;
let canvas: HTMLCanvasElement;

View File

@ -6,7 +6,7 @@
import { onMount } from "svelte";
import * as BABYLON from "babylonjs";
import * as BABYLON_LOADERS from "babylonjs-loaders";
import type { I18nFormatter } from "js/utils/src";
import type { I18nFormatter } from "@gradio/utils";
export let value: FileData | null;
export let clear_color: [number, number, number, number] = [0, 0, 0, 0];

View File

@ -84,7 +84,7 @@
import * as BABYLON from "babylonjs";
import * as BABYLON_LOADERS from "babylonjs-loaders";
import type { I18nFormatter } from "js/utils/src";
import type { I18nFormatter } from "@gradio/utils";
$: {
if (

View File

@ -12,7 +12,7 @@ const svelte_codes_to_ignore: Record<string, string> = {
const RE_SVELTE_IMPORT =
/import\s+([\w*{},\s]+)\s+from\s+['"](svelte|svelte\/internal)['"]/g;
const RE_BARE_SVELTE_IMPORT = /import ("|')svelte(\/\w+)*("|')(;)*/g;
export const plugins: PluginOption[] = [
viteCommonjs() as Plugin,
svelte({
@ -71,15 +71,17 @@ export function make_gradio_plugin({
name: "gradio",
enforce: "pre",
transform(code) {
const new_code = code.replace(RE_SVELTE_IMPORT, (str, $1, $2) => {
const identifier = $1.trim().startsWith("* as")
? $1.replace("* as", "").trim()
: $1.trim();
return `const ${identifier.replace(
" as ",
": "
)} = window.__gradio__svelte__internal;`;
});
const new_code = code
.replace(RE_SVELTE_IMPORT, (str, $1, $2) => {
const identifier = $1.trim().startsWith("* as")
? $1.replace("* as", "").trim()
: $1.trim();
return `const ${identifier.replace(
" as ",
": "
)} = window.__gradio__svelte__internal;`;
})
.replace(RE_BARE_SVELTE_IMPORT, "");
return {
code: new_code,
map: null

View File

@ -354,6 +354,9 @@ importers:
'@gradio/statustracker':
specifier: workspace:^
version: link:../statustracker
'@gradio/utils':
specifier: workspace:0.2.0-beta.6
version: link:../utils
js/annotatedimage:
dependencies: