File tree Expand file tree Collapse file tree 3 files changed +13
-4
lines changed
Expand file tree Collapse file tree 3 files changed +13
-4
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " @gaubee/node" ,
3- "version" : " 0.2.2 " ,
3+ "version" : " 0.2.3 " ,
44 "exports" : {
55 "./env" : " ./src/env.ts" ,
66 "./path" : " ./src/path.ts" ,
Original file line number Diff line number Diff line change @@ -43,10 +43,19 @@ export const cwdResolver: PathResolver = /*@__PURE__*/ createResolver(process.cw
4343/**
4444 * 向上寻找某一个文件名,以它所在的目录创建 resolver
4545 */
46- export const createResolverByRootFile = ( fromPath : string | URL = process . cwd ( ) , rootFilename = "package.json" ) : PathResolver => {
46+ export const createResolverByRootFile = ( fromPath : string | URL = process . cwd ( ) , rootFilename = "package.json" , else_fn ?: ( ) => string ) : PathResolver => {
4747 let rootDirname = normalizeFilePath ( fromPath ) ;
4848 while ( false === fs . existsSync ( node_path . resolve ( rootDirname , rootFilename ) ) ) {
49- rootDirname = node_path . resolve ( rootDirname , ".." ) ;
49+ const parentDirname = node_path . dirname ( rootDirname ) ;
50+ if ( parentDirname === rootDirname ) {
51+ const customDirname = else_fn ?.( ) ;
52+ if ( null == customDirname ) {
53+ throw new Error ( `Cannot find ${ rootFilename } from ${ fromPath } ` ) ;
54+ }
55+ rootDirname = customDirname ;
56+ } else {
57+ rootDirname = parentDirname ;
58+ }
5059 }
5160 return createResolver ( rootDirname ) ;
5261} ;
Original file line number Diff line number Diff line change 11{
22 "name" : " @gaubee/nodekit" ,
3- "version" : " 0.10.1 " ,
3+ "version" : " 0.10.2 " ,
44 "exports" : {
55 "./colors" : " ./src/colors.ts" ,
66 "./config_file" : " ./src/config_file.ts" ,
You can’t perform that action at this time.
0 commit comments