Skip to content

Commit aab239e

Browse files
fix: An building error on windows platform which caused by esmodule __dirname (#584)
Co-authored-by: TuringCodeOne <1962732398@qq.com>
1 parent c7d02ea commit aab239e

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

scripts/extract-indices.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import path from "path";
1414
import fs from "fs";
1515
import { URL } from 'url';
1616

17-
const __dirname = new URL('.', import.meta.url).pathname;
17+
const pathname = new URL('.', import.meta.url).pathname;
18+
const __dirname = process.platform !== 'win32' ? pathname : pathname.substring(1)
1819

1920
const headers = options => (tree, file) => {
2021
const headers = [];

scripts/extract-syntax.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import path from "path";
44
import fs from "fs";
55
import { URL } from 'url';
66

7-
const __dirname = new URL('.', import.meta.url).pathname;
7+
const pathname = new URL('.', import.meta.url).pathname;
8+
const __dirname = process.platform !== 'win32' ? pathname : pathname.substring(1)
89

910
const processFile = filepath => {
1011
const raw = fs.readFileSync(filepath, "utf8");

scripts/extract-tocs.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import path from "path";
1212
import fs from "fs";
1313
import { URL } from 'url';
1414

15-
const __dirname = new URL('.', import.meta.url).pathname;
15+
const pathname = new URL('.', import.meta.url).pathname;
16+
const __dirname = process.platform !== 'win32' ? pathname : pathname.substring(1)
1617

1718
// orderArr: ["introduction", "overview",,...]
1819
const orderFiles = (filepaths, orderArr) => {

scripts/test-examples.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import child_process from "child_process";
44
import path from "path";
55
import { URL } from 'url';
66

7-
const __dirname = new URL('.', import.meta.url).pathname;
7+
const pathname = new URL('.', import.meta.url).pathname;
8+
const __dirname = process.platform !== 'win32' ? pathname : pathname.substring(1)
89

910
let tempFileName = path.join(__dirname, '..', '_tempFile.res')
1011
let tempFileNameRegex = /_tempFile\.res/g

scripts/test-hrefs.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import urlModule from "url";
1616
import { URL } from 'url';
1717
import {getAllPosts, blogPathToSlug} from '../src/common/BlogApi.mjs'
1818

19-
const __dirname = new URL('.', import.meta.url).pathname;
19+
const pathname = new URL('.', import.meta.url).pathname;
20+
const __dirname = process.platform !== 'win32' ? pathname : pathname.substring(1)
2021

2122
const mapBlogFilePath = path => {
2223
const match = path.match(/\.\/_blogposts\/(.*\.mdx)/);

0 commit comments

Comments
 (0)