@@ -8,7 +8,6 @@ import { ConverterEvents } from "../converter-events.js";
88import type { Converter } from "../converter.js" ;
99import { type GlobString , i18n , MinimalSourceFile , type NormalizedPath } from "#utils" ;
1010import {
11- discoverInParentDir ,
1211 discoverPackageJson ,
1312 type EntryPointStrategy ,
1413 getCommonDirectory ,
@@ -17,6 +16,7 @@ import {
1716 Option ,
1817 readFile ,
1918} from "#node-utils" ;
19+ import { existsSync } from "fs" ;
2020
2121/**
2222 * A handler that tries to find the package.json and readme.md files of the
@@ -82,10 +82,11 @@ export class PackagePlugin extends ConverterComponent {
8282 Path . resolve ( getCommonDirectory ( this . entryPoints . map ( g => `${ g } /` ) ) ) ;
8383
8484 this . application . logger . verbose (
85- `Begin readme.md/ package.json search at ${ nicePath ( dirName ) } ` ,
85+ `Begin package.json search at ${ nicePath ( dirName ) } ` ,
8686 ) ;
8787
88- this . packageJson = discoverPackageJson ( dirName ) ?. content ;
88+ const packageJson = discoverPackageJson ( dirName ) ;
89+ this . packageJson = packageJson ?. content ;
8990
9091 // Path will be resolved already. This is kind of ugly, but...
9192 if ( this . readme . endsWith ( "none" ) ) {
@@ -105,17 +106,22 @@ export class PackagePlugin extends ConverterComponent {
105106 ) ,
106107 ) ;
107108 }
108- } else {
109+ } else if ( packageJson ) {
109110 // No readme provided, automatically find the readme
110- const result = discoverInParentDir (
111+ const possibleReadmePaths = [
112+ "README.md" ,
111113 "readme.md" ,
112- dirName ,
113- ( content ) => content ,
114- ) ;
114+ "Readme.md" ,
115+ ] . map ( name => Path . join ( Path . dirname ( packageJson . file ) , name ) ) ;
116+
117+ const readmePath = possibleReadmePaths . find ( path => {
118+ this . application . watchFile ( path ) ;
119+ return existsSync ( path ) ;
120+ } ) ;
115121
116- if ( result ) {
117- this . readmeFile = normalizePath ( result . file ) ;
118- this . readmeContents = result . content ;
122+ if ( readmePath ) {
123+ this . readmeFile = normalizePath ( readmePath ) ;
124+ this . readmeContents = readFile ( readmePath ) ;
119125 this . application . watchFile ( this . readmeFile ) ;
120126 }
121127 }
0 commit comments