From 54d2306a9983da856cdb006b8b29bc1f29caa32e Mon Sep 17 00:00:00 2001 From: TuringCodeOne <1962732398@qq.com> Date: Fri, 28 Oct 2022 22:41:50 +0800 Subject: [PATCH] fix: An building error on windows platform which caused by esmodule __dirname --- scripts/extract-indices.mjs | 3 ++- scripts/extract-syntax.mjs | 3 ++- scripts/extract-tocs.mjs | 3 ++- scripts/test-examples.mjs | 3 ++- scripts/test-hrefs.mjs | 3 ++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/scripts/extract-indices.mjs b/scripts/extract-indices.mjs index d730e0e15..628ba3e70 100644 --- a/scripts/extract-indices.mjs +++ b/scripts/extract-indices.mjs @@ -14,7 +14,8 @@ import path from "path"; import fs from "fs"; import { URL } from 'url'; -const __dirname = new URL('.', import.meta.url).pathname; +const pathname = new URL('.', import.meta.url).pathname; +const __dirname = process.platform !== 'win32' ? pathname : pathname.substring(1) const headers = options => (tree, file) => { const headers = []; diff --git a/scripts/extract-syntax.mjs b/scripts/extract-syntax.mjs index 2b9575aca..b292fa37a 100644 --- a/scripts/extract-syntax.mjs +++ b/scripts/extract-syntax.mjs @@ -4,7 +4,8 @@ import path from "path"; import fs from "fs"; import { URL } from 'url'; -const __dirname = new URL('.', import.meta.url).pathname; +const pathname = new URL('.', import.meta.url).pathname; +const __dirname = process.platform !== 'win32' ? pathname : pathname.substring(1) const processFile = filepath => { const raw = fs.readFileSync(filepath, "utf8"); diff --git a/scripts/extract-tocs.mjs b/scripts/extract-tocs.mjs index 85d4aaeb3..8facc177b 100644 --- a/scripts/extract-tocs.mjs +++ b/scripts/extract-tocs.mjs @@ -12,7 +12,8 @@ import path from "path"; import fs from "fs"; import { URL } from 'url'; -const __dirname = new URL('.', import.meta.url).pathname; +const pathname = new URL('.', import.meta.url).pathname; +const __dirname = process.platform !== 'win32' ? pathname : pathname.substring(1) // orderArr: ["introduction", "overview",,...] const orderFiles = (filepaths, orderArr) => { diff --git a/scripts/test-examples.mjs b/scripts/test-examples.mjs index ccdcf851e..aa3d85ca1 100644 --- a/scripts/test-examples.mjs +++ b/scripts/test-examples.mjs @@ -4,7 +4,8 @@ import child_process from "child_process"; import path from "path"; import { URL } from 'url'; -const __dirname = new URL('.', import.meta.url).pathname; +const pathname = new URL('.', import.meta.url).pathname; +const __dirname = process.platform !== 'win32' ? pathname : pathname.substring(1) let tempFileName = path.join(__dirname, '..', '_tempFile.res') let tempFileNameRegex = /_tempFile\.res/g diff --git a/scripts/test-hrefs.mjs b/scripts/test-hrefs.mjs index 91e4c8a7d..783cd0d5e 100644 --- a/scripts/test-hrefs.mjs +++ b/scripts/test-hrefs.mjs @@ -16,7 +16,8 @@ import urlModule from "url"; import { URL } from 'url'; import {getAllPosts, blogPathToSlug} from '../src/common/BlogApi.mjs' -const __dirname = new URL('.', import.meta.url).pathname; +const pathname = new URL('.', import.meta.url).pathname; +const __dirname = process.platform !== 'win32' ? pathname : pathname.substring(1) const mapBlogFilePath = path => { const match = path.match(/\.\/_blogposts\/(.*\.mdx)/);