@@ -6,11 +6,12 @@ import fs from 'fs';
66
77const currentDir = dirname ( fileURLToPath ( import . meta. url ) ) ;
88const 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 ;
1112let 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))) {
2122const 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
3338export default import ( entrypointPath ) ;
0 commit comments