Skip to content
This repository was archived by the owner on Jul 29, 2025. It is now read-only.

Commit 3b4462d

Browse files
committed
feat: remove vite deps
1 parent 97397a8 commit 3b4462d

File tree

5 files changed

+80
-32
lines changed

5 files changed

+80
-32
lines changed

packages/vite-plugin-cloudflare-functions/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,13 @@
7575
},
7676
"dependencies": {
7777
"@cloudflare/workers-types": "^3.14.1",
78+
"debug": "^4.3.4",
7879
"fast-glob": "^3.2.11",
7980
"mlly": "^0.5.13",
8081
"picocolors": "^1.0.0"
8182
},
8283
"devDependencies": {
84+
"@types/debug": "^4.1.7",
8385
"@types/node": "^18.0.0",
8486
"axios": "^0.27.2",
8587
"ohmyfetch": "^0.4.18",

packages/vite-plugin-cloudflare-functions/src/vite/generate.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import * as path from 'node:path';
22
import { promises as fs } from 'node:fs';
33

44
import fg from 'fast-glob';
5-
import { normalizePath } from 'vite';
65
import { findExportNames } from 'mlly';
76

7+
import { normalizePath } from './utils';
8+
89
export async function generate(functionsRoot: string, dtsPath: string) {
910
const files = await fg(['**/*.ts', '**/*.js', '!**/*.d.ts', '!node_modules/**/*'], {
1011
cwd: functionsRoot

packages/vite-plugin-cloudflare-functions/src/vite/index.ts

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import * as path from 'node:path';
55
import { spawn } from 'node:child_process';
66

77
import colors from 'picocolors';
8-
import { normalizePath } from 'vite';
98

109
import type { UserConfig } from './types';
1110

1211
import { prepare } from './prepare';
1312
import { generate } from './generate';
13+
import { normalizePath, debug } from './utils';
1414

1515
export { prepare };
1616

@@ -59,6 +59,8 @@ export function CloudflarePagesFunctions(userConfig: UserConfig = {}): Plugin {
5959
: path.resolve(resolvedConfig.root, 'functions')
6060
);
6161

62+
debug(`Functions root: ${functionsRoot}`);
63+
6264
if (!functionsRoot.endsWith('functions') && functionsRoot.endsWith('functions/')) {
6365
console.log('You should put your worker in directory named as functions/');
6466
}
@@ -107,33 +109,32 @@ export function CloudflarePagesFunctions(userConfig: UserConfig = {}): Plugin {
107109
}
108110
}
109111

110-
const proxy = spawn(
111-
'npx',
112-
[
113-
'wrangler',
114-
'pages',
115-
'dev',
116-
'--experimental-enable-local-persistence',
117-
'--ip',
118-
'localhost',
119-
'--port',
120-
String(wranglerPort),
121-
'--proxy',
122-
String(port),
123-
'--',
124-
'npm',
125-
'--version'
126-
],
127-
{
128-
shell: process.platform === 'win32',
129-
stdio: ['inherit', 'pipe', 'pipe'],
130-
env: {
131-
BROWSER: 'none',
132-
...process.env
133-
},
134-
cwd: path.dirname(functionsRoot)
135-
}
136-
);
112+
const command = [
113+
'wrangler',
114+
'pages',
115+
'dev',
116+
'--experimental-enable-local-persistence',
117+
'--ip',
118+
'localhost',
119+
'--port',
120+
String(wranglerPort),
121+
'--proxy',
122+
String(port),
123+
'--',
124+
'npm',
125+
'--version'
126+
];
127+
debug(command);
128+
129+
const proxy = spawn('npx', command, {
130+
shell: process.platform === 'win32',
131+
stdio: ['inherit', 'pipe', 'pipe'],
132+
env: {
133+
BROWSER: 'none',
134+
...process.env
135+
},
136+
cwd: path.dirname(functionsRoot)
137+
});
137138

138139
let firstTime = true;
139140
proxy.stdout.on('data', (chunk) => {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { win32, posix } from 'node:path';
2+
3+
import createDebug from 'debug';
4+
5+
export const debug = createDebug('cloudflare-functions');
6+
7+
export function normalizePath(filename: string) {
8+
return filename.split(win32.sep).join(posix.sep);
9+
}

pnpm-lock.yaml

Lines changed: 38 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)