1- import { existsSync , mkdirSync } from "node:fs" ;
1+ import { existsSync , mkdirSync , writeFileSync } from "node:fs" ;
22import { dirname , join } from "node:path" ;
33import { parseUrlPkg } from "@jspm/generator" ;
44import { parseNodeModuleCachePath } from "src/parser" ;
@@ -17,8 +17,7 @@ import { logger } from "src/logger";
1717 * ******************************************************
1818 */
1919
20- const log = logger ( { file : "loader" } ) ;
21- log . setLogger ( IS_DEBUGGING ) ;
20+ const log = logger ( { file : "loader" , isLogging : IS_DEBUGGING } ) ;
2221
2322export const ensureDirSync = ( dirPath : string ) => {
2423 if ( existsSync ( dirPath ) ) return ;
@@ -27,7 +26,17 @@ export const ensureDirSync = (dirPath: string) => {
2726 mkdirSync ( dirPath ) ;
2827} ;
2928
30- export const isNodeOrFileProtocol = ( modulePath : string ) => {
29+ export const ensureFileSync = ( path : string ) => {
30+ const dirPath = dirname ( path ) ;
31+ if ( ! existsSync ( dirPath ) ) ensureDirSync ( dirPath ) ;
32+ try {
33+ writeFileSync ( path , '' , { flag : 'wx' } ) ;
34+ } catch {
35+ log . error ( `ensureDirSync: Failed in creating ${ path } ` )
36+ }
37+ }
38+
39+ export const checkIfNodeOrFileProtocol = ( modulePath : string ) => {
3140 const { protocol = "" } = new URL ( modulePath ) ;
3241 const isNode = protocol === "node:" ;
3342 const isFile = protocol === "file:" ;
@@ -47,7 +56,7 @@ export const resolveNodeModuleCachePath = async (modulePath: string) => {
4756 const version = moduleMetadata ?. pkg ?. version ;
4857 const moduleFile = modulePath . split ( "/" ) . reverse ( ) [ 0 ] || "" ;
4958 const nodeModuleCachePath = join ( cache , `${ name } @${ version } ` , moduleFile ) ;
50- log . debug ( "resolveNodeModuleCachePath:" , { name, version, nodeModuleCachePath } ) ;
59+ log . debug ( "resolveNodeModuleCachePath:" , { moduleMetadata , name, version, nodeModuleCachePath } ) ;
5160 return nodeModuleCachePath ;
5261 } catch ( err ) {
5362 log . error ( "resolveNodeModuleCachePath:" , err ) ;
0 commit comments