From b402d39a1b7cb2624a9507a2313f74200648b4a1 Mon Sep 17 00:00:00 2001 From: ota-meshi Date: Sat, 6 Aug 2022 09:41:56 +0900 Subject: [PATCH 1/3] Chore: Fix `docs:watch` to work on Windows --- docs-svelte-kit/build-system/build.mts | 9 ++++++--- svelte.config.mjs | 3 ++- vite.config.mts | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/docs-svelte-kit/build-system/build.mts b/docs-svelte-kit/build-system/build.mts index 3a335ffe1..c441ae58e 100644 --- a/docs-svelte-kit/build-system/build.mts +++ b/docs-svelte-kit/build-system/build.mts @@ -1,14 +1,16 @@ import esbuild from "esbuild" import path from "path" import fs from "fs" +import { fileURLToPath } from "url" // const babelCore = require("@babel/core") // const t = require("@babel/types") -const dirname = path.dirname( +const dirname = fileURLToPath( new URL( + ".", // @ts-expect-error -- Cannot change `module` option import.meta.url, - ).pathname, + ), ) build( @@ -32,13 +34,14 @@ function build(input: string, out: string, injects: string[] = []) { /** bundle */ function bundle(entryPoint: string, externals: string[]) { + const injectPath = path.join(dirname, "./src/process-shim.mjs") const result = esbuild.buildSync({ entryPoints: [entryPoint], format: "esm", bundle: true, external: externals, write: false, - inject: [path.join(dirname, "./src/process-shim.mjs")], + inject: [injectPath], }) return `${result.outputFiles[0].text}` diff --git a/svelte.config.mjs b/svelte.config.mjs index cbc87fb67..aefab1708 100644 --- a/svelte.config.mjs +++ b/svelte.config.mjs @@ -1,13 +1,14 @@ import ghpagesAdapter from "svelte-adapter-ghpages" import path from "path" import fs from "fs" +import { fileURLToPath } from "url" // eslint-disable-next-line no-undef -- There seems to be a package that uses `self`. if (typeof self === "undefined") { globalThis.self = globalThis } -const dirname = path.dirname(new URL(import.meta.url).pathname) +const dirname = fileURLToPath(new URL(".", import.meta.url)) // This project can't be ESM yet, so hack it to get svelte-kit to work. // A hack that treats files in the `.svelte-kit` directory as ESM. diff --git a/vite.config.mts b/vite.config.mts index 06ae343e2..17a220f28 100644 --- a/vite.config.mts +++ b/vite.config.mts @@ -6,12 +6,14 @@ import svelteMdOption from "./docs-svelte-kit/tools/vite-plugin-svelte-md-option import "./docs-svelte-kit/build-system/build.mts" import type { UserConfig } from "vite" +import { fileURLToPath } from "url" -const dirname = path.dirname( +const dirname = fileURLToPath( new URL( + ".", // @ts-expect-error -- Cannot change `module` option import.meta.url, - ).pathname, + ), ) /** @type {import('vite').UserConfig} */ From 6b185d1a44478d66876928090a74919ab973b9d3 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Sat, 6 Aug 2022 01:05:32 +0000 Subject: [PATCH 2/3] update --- docs-svelte-kit/build-system/build.mts | 5 ++--- svelte.config.mjs | 2 +- vite.config.mts | 5 ++--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/docs-svelte-kit/build-system/build.mts b/docs-svelte-kit/build-system/build.mts index c441ae58e..34f4b44b7 100644 --- a/docs-svelte-kit/build-system/build.mts +++ b/docs-svelte-kit/build-system/build.mts @@ -5,9 +5,8 @@ import { fileURLToPath } from "url" // const babelCore = require("@babel/core") // const t = require("@babel/types") -const dirname = fileURLToPath( - new URL( - ".", +const dirname = path.dirname( + fileURLToPath( // @ts-expect-error -- Cannot change `module` option import.meta.url, ), diff --git a/svelte.config.mjs b/svelte.config.mjs index aefab1708..6a9f61cc2 100644 --- a/svelte.config.mjs +++ b/svelte.config.mjs @@ -8,7 +8,7 @@ if (typeof self === "undefined") { globalThis.self = globalThis } -const dirname = fileURLToPath(new URL(".", import.meta.url)) +const dirname = path.dirname(fileURLToPath(import.meta.url)) // This project can't be ESM yet, so hack it to get svelte-kit to work. // A hack that treats files in the `.svelte-kit` directory as ESM. diff --git a/vite.config.mts b/vite.config.mts index 17a220f28..3cde8bd42 100644 --- a/vite.config.mts +++ b/vite.config.mts @@ -8,9 +8,8 @@ import "./docs-svelte-kit/build-system/build.mts" import type { UserConfig } from "vite" import { fileURLToPath } from "url" -const dirname = fileURLToPath( - new URL( - ".", +const dirname = path.dirname( + fileURLToPath( // @ts-expect-error -- Cannot change `module` option import.meta.url, ), From f83a3badccfb1d5e8073c3be9fc5ae9eb66095d4 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Sat, 6 Aug 2022 02:59:43 +0000 Subject: [PATCH 3/3] revert --- docs-svelte-kit/build-system/build.mts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs-svelte-kit/build-system/build.mts b/docs-svelte-kit/build-system/build.mts index 34f4b44b7..d9fa3e7ce 100644 --- a/docs-svelte-kit/build-system/build.mts +++ b/docs-svelte-kit/build-system/build.mts @@ -33,14 +33,13 @@ function build(input: string, out: string, injects: string[] = []) { /** bundle */ function bundle(entryPoint: string, externals: string[]) { - const injectPath = path.join(dirname, "./src/process-shim.mjs") const result = esbuild.buildSync({ entryPoints: [entryPoint], format: "esm", bundle: true, external: externals, write: false, - inject: [injectPath], + inject: [path.join(dirname, "./src/process-shim.mjs")], }) return `${result.outputFiles[0].text}`