From 57945ac2fecc7320c73091be899e5cb969230096 Mon Sep 17 00:00:00 2001 From: Spaceman Date: Wed, 19 Feb 2025 11:57:33 +0800 Subject: [PATCH 1/2] File path compatibility with Windows --- packages/docs/run-typedoc.mjs | 4 +++- packages/docs/typedoc-markdown.mjs | 4 +++- packages/router/size-checks/rollup.config.mjs | 4 +++- scripts/check-size.mjs | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/docs/run-typedoc.mjs b/packages/docs/run-typedoc.mjs index e69935587..915bcc47a 100644 --- a/packages/docs/run-typedoc.mjs +++ b/packages/docs/run-typedoc.mjs @@ -1,7 +1,9 @@ import path from 'node:path' +import { fileURLToPath } from 'node:url' import { createTypeDocApp } from './typedoc-markdown.mjs' -const __dirname = path.dirname(new URL(import.meta.url).pathname) +const pathname = process.platform === 'win32' ? fileURLToPath(import.meta.url) : new URL(import.meta.url).pathname +const __dirname = path.dirname(pathname) createTypeDocApp({ name: 'API Documentation', diff --git a/packages/docs/typedoc-markdown.mjs b/packages/docs/typedoc-markdown.mjs index 90513b832..1f233e56a 100644 --- a/packages/docs/typedoc-markdown.mjs +++ b/packages/docs/typedoc-markdown.mjs @@ -1,9 +1,11 @@ // @ts-check import fs from 'node:fs/promises' import path from 'node:path' +import {fileURLToPath} from 'node:url' import { Application, PageEvent, TSConfigReader } from 'typedoc' -const __dirname = path.dirname(new URL(import.meta.url).pathname) +const pathname = process.platform === 'win32' ? fileURLToPath(import.meta.url) : new URL(import.meta.url).pathname +const __dirname = path.dirname(pathname) const DEFAULT_OPTIONS = { // disableOutputCheck: true, diff --git a/packages/router/size-checks/rollup.config.mjs b/packages/router/size-checks/rollup.config.mjs index 9b3f07071..3bec206af 100644 --- a/packages/router/size-checks/rollup.config.mjs +++ b/packages/router/size-checks/rollup.config.mjs @@ -1,4 +1,5 @@ import path from 'node:path' +import {fileURLToPath} from 'node:url' import ts from 'rollup-plugin-typescript2' import replace from '@rollup/plugin-replace' import resolve from '@rollup/plugin-node-resolve' @@ -6,7 +7,8 @@ import commonjs from '@rollup/plugin-commonjs' import terser from '@rollup/plugin-terser' import { defineConfig } from 'rollup' -const __dirname = path.dirname(new URL(import.meta.url).pathname) +const pathname = process.platform === 'win32' ? fileURLToPath(import.meta.url) : new URL(import.meta.url).pathname +const __dirname = path.dirname(pathname) const config = defineConfig({ external: ['vue'], diff --git a/scripts/check-size.mjs b/scripts/check-size.mjs index 59a5bbc8d..6477bbca6 100644 --- a/scripts/check-size.mjs +++ b/scripts/check-size.mjs @@ -1,10 +1,12 @@ import fs from 'node:fs/promises' import path from 'node:path' +import {fileURLToPath} from 'node:url' import chalk from 'chalk' import { gzipSync } from 'zlib' import { compress } from 'brotli' -const __dirname = path.dirname(new URL(import.meta.url).pathname) +const pathname = process.platform === 'win32' ? fileURLToPath(import.meta.url) : new URL(import.meta.url).pathname +const __dirname = path.dirname(pathname) async function checkFileSize(filePath) { const stat = await fs.stat(filePath).catch(() => null) From 5acfc2224532a607ab86c492112733bdf396f565 Mon Sep 17 00:00:00 2001 From: Spaceman Date: Wed, 19 Feb 2025 18:02:16 +0800 Subject: [PATCH 2/2] Simplify the file path and Windows compatibility code. --- packages/docs/run-typedoc.mjs | 3 +-- packages/docs/typedoc-markdown.mjs | 3 +-- packages/router/size-checks/rollup.config.mjs | 3 +-- scripts/check-size.mjs | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/docs/run-typedoc.mjs b/packages/docs/run-typedoc.mjs index 915bcc47a..790b14b9a 100644 --- a/packages/docs/run-typedoc.mjs +++ b/packages/docs/run-typedoc.mjs @@ -2,8 +2,7 @@ import path from 'node:path' import { fileURLToPath } from 'node:url' import { createTypeDocApp } from './typedoc-markdown.mjs' -const pathname = process.platform === 'win32' ? fileURLToPath(import.meta.url) : new URL(import.meta.url).pathname -const __dirname = path.dirname(pathname) +const __dirname = path.dirname(fileURLToPath(import.meta.url)) createTypeDocApp({ name: 'API Documentation', diff --git a/packages/docs/typedoc-markdown.mjs b/packages/docs/typedoc-markdown.mjs index 1f233e56a..02cd0ae06 100644 --- a/packages/docs/typedoc-markdown.mjs +++ b/packages/docs/typedoc-markdown.mjs @@ -4,8 +4,7 @@ import path from 'node:path' import {fileURLToPath} from 'node:url' import { Application, PageEvent, TSConfigReader } from 'typedoc' -const pathname = process.platform === 'win32' ? fileURLToPath(import.meta.url) : new URL(import.meta.url).pathname -const __dirname = path.dirname(pathname) +const __dirname = path.dirname(fileURLToPath(import.meta.url)) const DEFAULT_OPTIONS = { // disableOutputCheck: true, diff --git a/packages/router/size-checks/rollup.config.mjs b/packages/router/size-checks/rollup.config.mjs index 3bec206af..73485959a 100644 --- a/packages/router/size-checks/rollup.config.mjs +++ b/packages/router/size-checks/rollup.config.mjs @@ -7,8 +7,7 @@ import commonjs from '@rollup/plugin-commonjs' import terser from '@rollup/plugin-terser' import { defineConfig } from 'rollup' -const pathname = process.platform === 'win32' ? fileURLToPath(import.meta.url) : new URL(import.meta.url).pathname -const __dirname = path.dirname(pathname) +const __dirname = path.dirname(fileURLToPath(import.meta.url)) const config = defineConfig({ external: ['vue'], diff --git a/scripts/check-size.mjs b/scripts/check-size.mjs index 6477bbca6..22d62db7d 100644 --- a/scripts/check-size.mjs +++ b/scripts/check-size.mjs @@ -5,8 +5,7 @@ import chalk from 'chalk' import { gzipSync } from 'zlib' import { compress } from 'brotli' -const pathname = process.platform === 'win32' ? fileURLToPath(import.meta.url) : new URL(import.meta.url).pathname -const __dirname = path.dirname(pathname) +const __dirname = path.dirname(fileURLToPath(import.meta.url)) async function checkFileSize(filePath) { const stat = await fs.stat(filePath).catch(() => null)