Skip to content

Commit 2efd69f

Browse files
Killusionskfenner
authored andcommitted
build(docs-builder): make sure it works also on Windows
1 parent 9755ede commit 2efd69f

File tree

1 file changed

+13
-8
lines changed
  • projects/element-docs-builder/mkdocs_element_docs_builder

1 file changed

+13
-8
lines changed

projects/element-docs-builder/mkdocs_element_docs_builder/index.mjs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import fs from 'fs';
66

77
const currentDir = dirname(fileURLToPath(import.meta.url));
88
const cwd = process.cwd();
9-
let relativeCwd = relative(currentDir, cwd);
10-
let nodeModulesPath = join(currentDir, relativeCwd, 'node_modules');
9+
10+
const nodeModulesDirName = 'node_modules';
11+
let basePath = cwd;
1112
let maxLevels = 10;
12-
while (!fs.existsSync(join(currentDir, nodeModulesPath))) {
13-
nodeModulesPath = join('..', nodeModulesPath);
13+
while (!fs.existsSync(join(basePath, nodeModulesDirName))) {
14+
basePath = dirname(basePath);
1415
maxLevels -= 1;
1516
if (maxLevels <= 0) {
1617
throw new Error(
@@ -21,13 +22,17 @@ while (!fs.existsSync(join(currentDir, nodeModulesPath))) {
2122
const packagePath =
2223
process.env.DOCS_COMPOSER_DEV &&
2324
['true', '1', 'yes', 'y'].includes(process.env.DOCS_COMPOSER_DEV.toLowerCase())
24-
? relativeCwd
25-
: join(nodeModulesPath, '@simpl', 'docs-composer');
26-
if (!fs.existsSync(join(currentDir, packagePath))) {
25+
? cwd
26+
: join(basePath, nodeModulesDirName, '@simpl', 'docs-composer');
27+
if (!fs.existsSync(packagePath)) {
2728
throw new Error(
2829
`Package path '${packagePath}' does not exist, please ensure you have installed the '@simpl/docs-composer' package.`
2930
);
3031
}
31-
const entrypointPath = join(packagePath, 'dist', 'index.js');
32+
const relativePackagePath = relative(currentDir, packagePath);
33+
const entrypointPath = join(relativePackagePath, 'dist', 'index.js').replace(
34+
/(?<!\\)\\(?!\\)/g,
35+
'/'
36+
); // Convert unescaped backslashes.
3237

3338
export default import(entrypointPath);

0 commit comments

Comments
 (0)