From b00cd4f2307a5ebf34ff70667c30c4231b72a79d Mon Sep 17 00:00:00 2001 From: Patrick Pircher Date: Thu, 14 Dec 2023 17:21:41 +0100 Subject: [PATCH] fix vite on windows --- packages/shared-internals/src/package-cache.ts | 8 ++++---- packages/vite/src/bin/run-tests.mjs | 10 +++++++--- packages/vite/src/esbuild-request.ts | 2 -- tests/vite-app/app/components/fancy.gts | 1 + tests/vite-app/package.json | 2 +- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/packages/shared-internals/src/package-cache.ts b/packages/shared-internals/src/package-cache.ts index 870727dbfa..98dafa6e59 100644 --- a/packages/shared-internals/src/package-cache.ts +++ b/packages/shared-internals/src/package-cache.ts @@ -2,7 +2,7 @@ import Package from './package'; import { existsSync, realpathSync } from 'fs'; import { getOrCreate } from './get-or-create'; import resolvePackagePath from 'resolve-package-path'; -import { dirname, sep } from 'path'; +import { dirname, posix } from 'path'; const realpathSyncCache = new Map(); @@ -67,7 +67,7 @@ export default class PackageCache { } ownerOfFile(filename: string): Package | undefined { - let segments = filename.split(sep); + let segments = filename.replace(/\\/g, '/').split(posix.sep); // first we look through our cached packages for any that are rooted right // at or above the file. @@ -79,11 +79,11 @@ export default class PackageCache { } let usedSegments = segments.slice(0, length); - let candidate = usedSegments.join(sep); + let candidate = usedSegments.join(posix.sep); if (this.rootCache.has(candidate)) { return this.rootCache.get(candidate); } - if (getCachedExists([...usedSegments, 'package.json'].join(sep))) { + if (getCachedExists([...usedSegments, 'package.json'].join(posix.sep))) { return this.get(candidate); } } diff --git a/packages/vite/src/bin/run-tests.mjs b/packages/vite/src/bin/run-tests.mjs index 9e0aeb2e6e..f7073701a9 100644 --- a/packages/vite/src/bin/run-tests.mjs +++ b/packages/vite/src/bin/run-tests.mjs @@ -11,9 +11,13 @@ async function run() { await /** @type {Promise} */ ( new Promise(fulfill => { - const runvite = child.spawn(resolve(__root, 'node_modules', '.bin', 'vite'), ['--port', '60173', '--no-open'], { - stdio: 'pipe', - }); + const runvite = child.fork( + resolve(__root, 'node_modules', 'vite', 'bin', 'vite.js'), + ['--port', '60173', '--no-open'], + { + stdio: 'pipe', + } + ); process.on('exit', () => runvite.kill()); diff --git a/packages/vite/src/esbuild-request.ts b/packages/vite/src/esbuild-request.ts index 3a86fb9c9a..e93e740371 100644 --- a/packages/vite/src/esbuild-request.ts +++ b/packages/vite/src/esbuild-request.ts @@ -1,7 +1,5 @@ import { type ModuleRequest, cleanUrl } from '@embroider/core'; -export const virtualNamespace = 'embroider'; - export class EsBuildModuleRequest implements ModuleRequest { static from( source: string, diff --git a/tests/vite-app/app/components/fancy.gts b/tests/vite-app/app/components/fancy.gts index 6b2819db4d..b66c973055 100644 --- a/tests/vite-app/app/components/fancy.gts +++ b/tests/vite-app/app/components/fancy.gts @@ -1 +1,2 @@ + diff --git a/tests/vite-app/package.json b/tests/vite-app/package.json index 7481f628c2..babe68c731 100644 --- a/tests/vite-app/package.json +++ b/tests/vite-app/package.json @@ -22,7 +22,7 @@ "lint:js": "eslint . --cache", "lint:js:fix": "eslint . --fix", "start:prebuild": "ember build --watch", - "start:dev": "pnpm start:prebuild & vite --force", + "start:dev": "vite", "start:test": "vite --open /tests/", "test": "concurrently \"npm:lint\" \"npm:test:*\" --names \"lint,test:\"", "test:ember": "node ./node_modules/@embroider/vite/src/bin/run-tests.mjs"