fix(vite): remove Deno global check (#3401)
Ultimately, it causes more problems than it solves.
This commit is contained in:
@@ -6,7 +6,6 @@ import babelReact from "@babel/preset-react";
|
|||||||
import { inlineEnvVarsPlugin } from "./patches/inline_env_vars.ts";
|
import { inlineEnvVarsPlugin } from "./patches/inline_env_vars.ts";
|
||||||
import { removePolyfills } from "./patches/remove_polyfills.ts";
|
import { removePolyfills } from "./patches/remove_polyfills.ts";
|
||||||
import { JS_REG, JSX_REG } from "../utils.ts";
|
import { JS_REG, JSX_REG } from "../utils.ts";
|
||||||
import { denoGlobal } from "./patches/deno_global.ts";
|
|
||||||
import { codeEvalPlugin } from "./patches/code_eval.ts";
|
import { codeEvalPlugin } from "./patches/code_eval.ts";
|
||||||
|
|
||||||
export function patches(): Plugin {
|
export function patches(): Plugin {
|
||||||
@@ -44,10 +43,6 @@ export function patches(): Plugin {
|
|||||||
inlineEnvVarsPlugin(env, Deno.env.toObject()),
|
inlineEnvVarsPlugin(env, Deno.env.toObject()),
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!options?.ssr) {
|
|
||||||
plugins.push(denoGlobal);
|
|
||||||
}
|
|
||||||
|
|
||||||
const res = babel.transformSync(code, {
|
const res = babel.transformSync(code, {
|
||||||
filename: id,
|
filename: id,
|
||||||
babelrc: false,
|
babelrc: false,
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
import type { PluginObj, types } from "@babel/core";
|
|
||||||
|
|
||||||
export function denoGlobal({ types: t }: { types: typeof types }): PluginObj {
|
|
||||||
return {
|
|
||||||
name: "fresh-deno-global",
|
|
||||||
visitor: {
|
|
||||||
Identifier(path) {
|
|
||||||
if (path.node.name === "Deno") {
|
|
||||||
// Ignore `Deno.env.get()` calls. Those will be inlined.
|
|
||||||
if (
|
|
||||||
t.isMemberExpression(path.parent) &&
|
|
||||||
path.parent.object === path.node &&
|
|
||||||
t.isIdentifier(path.parent.property) &&
|
|
||||||
path.parent.property.name === "env" &&
|
|
||||||
t.isMemberExpression(path.parentPath?.parent) &&
|
|
||||||
t.isIdentifier(path.parentPath?.parent.property) &&
|
|
||||||
path.parentPath?.parent.property.name === "get"
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Ignore `Deno?.thing` expression. Those will result in undefined, and that might be used for shims.
|
|
||||||
if (
|
|
||||||
t.isOptionalMemberExpression(path.parent) &&
|
|
||||||
path.parent.object === path.node
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw path.buildCodeFrameError(
|
|
||||||
`The Deno.* global cannot be used in the browser.`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -408,30 +408,6 @@ Deno.test({
|
|||||||
sanitizeResources: false,
|
sanitizeResources: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test({
|
|
||||||
name: "vite build - throw when using Deno.* global inside an island",
|
|
||||||
fn: async () => {
|
|
||||||
const fixture = path.join(FIXTURE_DIR, "deno_global_island");
|
|
||||||
|
|
||||||
await expect(buildVite(fixture)).rejects.toThrow(
|
|
||||||
"The Deno.* global cannot be used in the browser",
|
|
||||||
);
|
|
||||||
},
|
|
||||||
sanitizeOps: false,
|
|
||||||
sanitizeResources: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
Deno.test({
|
|
||||||
name: "vite build - don't throw when using Deno.* global in ssr",
|
|
||||||
fn: async () => {
|
|
||||||
const fixture = path.join(FIXTURE_DIR, "deno_global_ssr");
|
|
||||||
|
|
||||||
await buildVite(fixture);
|
|
||||||
},
|
|
||||||
sanitizeOps: false,
|
|
||||||
sanitizeResources: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "vite build - static index.html",
|
name: "vite build - static index.html",
|
||||||
fn: async () => {
|
fn: async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user