Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/plugin-vite/demo/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export default defineConfig({
}),
tailwind(),
],
future: "warn",
});
2 changes: 1 addition & 1 deletion packages/plugin-vite/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@babel/preset-react": "npm:@babel/preset-react@^7.27.1",
"@deno/loader": "jsr:@deno/loader@^0.3.10",
"@marvinh-test/import-json": "jsr:@marvinh-test/import-json@^0.0.1",
"@mjackson/node-fetch-server": "npm:@mjackson/node-fetch-server@^0.7.0",
"@remix-run/node-fetch-server": "npm:@remix-run/node-fetch-server@^0.12.0",
"@prefresh/vite": "npm:@prefresh/vite@^2.4.8",
"@radix-ui/themes": "npm:@radix-ui/themes@^3.2.1",
"@tailwindcss/vite": "npm:@tailwindcss/vite@^4.1.12",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-vite/src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,6 @@ async function loadEnvFile(envPath: string) {
try {
await stdLoadEnv({ envPath, export: true });
} catch {
// Ignoe
// Ignore
}
}
2 changes: 1 addition & 1 deletion packages/plugin-vite/src/plugins/client_entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function clientEntryPlugin(options: ResolvedFreshViteConfig): Plugin {
isDev = env.command === "serve";
},
applyToEnvironment(env) {
return env.name === "client";
return env.config.consumer === "client";
},
configResolved(config) {
clientEntry = pathWithRoot(options.clientEntry, config.root);
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-vite/src/plugins/client_snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function clientSnapshot(options: ResolvedFreshViteConfig): Plugin[] {
name: "fresh:client-snapshot",
sharedDuringBuild: true,
applyToEnvironment(env) {
return env.name === "client";
return env.config.consumer === "client";
},

async config(cfg, env) {
Expand Down
18 changes: 11 additions & 7 deletions packages/plugin-vite/src/plugins/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ export function deno(): Plugin {
external: true,
};
}
const loader = options?.ssr ? ssrLoader : browserLoader;
const loader = this.environment.config.consumer === "server"
? ssrLoader
: browserLoader;

const original = id;

Expand Down Expand Up @@ -154,8 +156,10 @@ export function deno(): Plugin {
// ignore
}
},
async load(id, options) {
const loader = options?.ssr ? ssrLoader : browserLoader;
async load(id) {
const loader = this.environment.config.consumer === "server"
? ssrLoader
: browserLoader;

if (isDenoSpecifier(id)) {
const { type, specifier } = parseDenoSpecifier(id);
Expand All @@ -168,7 +172,7 @@ export function deno(): Plugin {
const code = new TextDecoder().decode(result.code);

const maybeJsx = babelTransform({
ssr: !!options?.ssr,
ssr: this.environment.config.consumer === "server",
media: result.mediaType,
code,
id: specifier,
Expand Down Expand Up @@ -212,7 +216,7 @@ export function deno(): Plugin {
const code = new TextDecoder().decode(result.code);

const maybeJsx = babelTransform({
ssr: !!options?.ssr,
ssr: this.environment.config.consumer === "server",
media: result.mediaType,
id,
code,
Expand All @@ -230,10 +234,10 @@ export function deno(): Plugin {
filter: {
id: JSX_REG,
},
async handler(_, id, options) {
async handler(_, id) {
// This transform is a hack to be able to re-use Deno's precompile
// jsx transform.
if (!options?.ssr) {
if (this.environment.name === "client") {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-vite/src/plugins/dev_server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { DevEnvironment, Plugin } from "vite";
import * as path from "@std/path";
import { ASSET_CACHE_BUST_KEY } from "fresh/internal";
import { createRequest, sendResponse } from "@mjackson/node-fetch-server";
import { createRequest, sendResponse } from "@remix-run/node-fetch-server";
import { hashCode } from "../shared.ts";

export function devServer(): Plugin[] {
Expand Down Expand Up @@ -118,7 +118,7 @@ export function devServer(): Plugin[] {
{
name: "fresh:server_hmr",
applyToEnvironment(env) {
return env.name === "ssr";
return env.config.consumer === "server";
},
hotUpdate(options) {
const clientMod = options.server.environments.client.moduleGraph
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-vite/src/plugins/patches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export function patches(): Plugin {
filter: {
id: JS_REG,
},
handler(code, id, options) {
handler(code, id) {
const presets = [];
if (!options?.ssr && JSX_REG.test(id)) {
if (this.environment.config.consumer === "client" && JSX_REG.test(id)) {
presets.push([babelReact, {
runtime: "automatic",
importSource: "preact",
Expand All @@ -40,7 +40,7 @@ export function patches(): Plugin {
const env = isDev ? "development" : "production";

const plugins: babel.PluginItem[] = [
codeEvalPlugin(options?.ssr ? "ssr" : "client", env),
codeEvalPlugin(this.environment.config.consumer, env),
cjsPlugin,
removePolyfills,
jsxComments,
Expand Down
10 changes: 5 additions & 5 deletions packages/plugin-vite/src/plugins/patches/code_eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { PluginObj, PluginPass, types } from "@babel/core";
const APPLY_PG_QUIRKS = "applyPgQuirks";

export function codeEvalPlugin(
env: "ssr" | "client",
env: "server" | "client",
mode: string,
) {
return (
Expand Down Expand Up @@ -41,7 +41,7 @@ export function codeEvalPlugin(

function evaluateExpr(
t: typeof types,
env: "client" | "ssr",
env: "server" | "client",
mode: string,
node: types.Node,
state: PluginPass,
Expand Down Expand Up @@ -76,9 +76,9 @@ function evaluateExpr(
node.right.value === "undefined"
) {
if (node.operator === "==" || node.operator === "===") {
return env !== "ssr";
return env !== "server";
} else if (node.operator === "!=" || node.operator === "!==") {
return env === "ssr";
return env === "server";
}
} else if (
// Workaround for npm:pg
Expand Down Expand Up @@ -125,7 +125,7 @@ function evaluateExpr(
if (result !== null) return result;
} else if (
// Check: process.foo === "bar"
env === "ssr" && t.isMemberExpression(node.left) &&
env === "server" && t.isMemberExpression(node.left) &&
t.isIdentifier(node.left.object) && node.left.object.name === "process" &&
t.isIdentifier(node.left.property) &&
!PROCESS_PROPERTIES.has(node.left.property.name)
Expand Down
12 changes: 6 additions & 6 deletions packages/plugin-vite/src/plugins/patches/code_eval_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function runTest(
options: {
input: string;
expected: string;
env: "client" | "ssr";
env: "client" | "server";
mode: "development" | "production";
},
) {
Expand Down Expand Up @@ -45,7 +45,7 @@ Deno.test("code eval - resolve runtime conditional detection", () => {
});

runTest({
env: "ssr",
env: "server",
mode: "development",
input: `if (typeof process === 'undefined') {
module.exports = require('./browser.js');
Expand All @@ -56,7 +56,7 @@ Deno.test("code eval - resolve runtime conditional detection", () => {
});

runTest({
env: "ssr",
env: "server",
mode: "development",
input: `if (typeof process !== 'undefined') {
module.exports = require('./node.js');
Expand Down Expand Up @@ -93,7 +93,7 @@ Deno.test("code eval - resolve process.env.NODE_ENV", () => {

Deno.test("code eval - npm:debug", () => {
runTest({
env: "ssr",
env: "server",
mode: "development",
input:
`if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) {
Expand All @@ -107,7 +107,7 @@ Deno.test("code eval - npm:debug", () => {

Deno.test("code eval - npm:pg", () => {
runTest({
env: "ssr",
env: "server",
mode: "development",
input: `if (typeof process.env.NODE_PG_FORCE_NATIVE !== "undefined") {
module.exports = require('./native.js');
Expand All @@ -120,7 +120,7 @@ Deno.test("code eval - npm:pg", () => {

Deno.test("code eval - npm:pg #2", () => {
runTest({
env: "ssr",
env: "server",
mode: "development",
input:
`const useLegacyCrypto = parseInt(process.versions && process.versions.node && process.versions.node.split('.')[0]) < 15
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-vite/src/plugins/server_entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function serverEntryPlugin(
name: "fresh:server_entry",
sharedDuringBuild: true,
applyToEnvironment(env) {
return env.name === "ssr";
return env.config.consumer === "server";
},
config(_, env) {
isDev = env.command === "serve";
Expand Down Expand Up @@ -77,7 +77,7 @@ export function serverEntryPlugin(
});

code += `

export function registerStaticFile(prepared) {
snapshot.staticFiles.set(prepared.name, {
name: prepared.name,
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-vite/src/plugins/server_snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function serverSnapshot(options: ResolvedFreshViteConfig): Plugin[] {
name: "fresh:server-snapshot",
sharedDuringBuild: true,
applyToEnvironment(env) {
return env.name === "ssr";
return env.config.consumer === "server";
},
config(_, env) {
isDev = env.command === "serve";
Expand Down Expand Up @@ -348,7 +348,7 @@ export function serverSnapshot(options: ResolvedFreshViteConfig): Plugin[] {
filter: {
id: /\.(css|less|sass|scss)(\?.*)?$/,
},
handler(_code, id, _options) {
handler(_code, id) {
if (server) {
const ssrGraph = server.environments.ssr.moduleGraph;
const mod = ssrGraph.getModuleById(id);
Expand Down Expand Up @@ -452,7 +452,7 @@ export default ${JSON.stringify(route.css)}
name: "fresh-route-css-build-ssr",
sharedDuringBuild: true,
applyToEnvironment(env) {
return env.name === "ssr";
return env.config.consumer === "server";
},
async writeBundle(_, bundle) {
const asset = bundle[".vite/manifest.json"];
Expand Down
Loading
Loading