diff --git a/build/build.node.ts b/build/build.node.ts index 97765c6798..e0165b82a5 100644 --- a/build/build.node.ts +++ b/build/build.node.ts @@ -1413,10 +1413,10 @@ namespace $ { const pushFile = (file:$mol_file) => { const start = Date.now() - const target = pack.resolve( `-/${ file.relate( root ) }` ) - // target.buffer( file.buffer() ) - target.copy_src(file.path()) + + const target = file.clone(pack.resolve( `-/${ file.relate( root ) }` ).path()) target.stat() + targets.push( target ) this.logBundle( target , Date.now() - start ) } diff --git a/file/file.node.ts b/file/file.node.ts index 615f22deb3..afa17d4736 100644 --- a/file/file.node.ts +++ b/file/file.node.ts @@ -39,13 +39,6 @@ namespace $ { } export class $mol_file_node extends $mol_file { - - @ $mol_mem_key - static absolute( path : string ) { - return this.make({ - path : $mol_const( path ) - }) - } static relative( path : string ) { return this.absolute( $node.path.resolve( this.base, path ).replace( /\\/g , '/' ) ) @@ -209,7 +202,7 @@ namespace $ { override relate( base = ( this.constructor as typeof $mol_file ).relative( '.' )) { return $node.path.relative( base.path() , this.path() ).replace( /\\/g , '/' ) } - + override append( next : Uint8Array | string ) { const path = this.path() try { diff --git a/file/file.ts b/file/file.ts index 52bd3f5c78..59fa6e0125 100644 --- a/file/file.ts +++ b/file/file.ts @@ -12,11 +12,13 @@ namespace $ { // export class $mol_file_not_found extends Error {} - export abstract class $mol_file extends $mol_object { - + export class $mol_file extends $mol_object { + @ $mol_mem_key - static absolute( path : string ): $mol_file { - throw new Error( 'Not implemented yet' ) + static absolute( path : string ) { + return this.make({ + path : $mol_const( path ) + }) } static relative( path : string ) : $mol_file { @@ -33,7 +35,17 @@ namespace $ { return this.resolve( '..' ) } - abstract stat(next? : $mol_file_stat | null, virt?: 'virt'): null | $mol_file_stat + @ $mol_mem_key + clone(path: string) { + return ( this.constructor as typeof $mol_file ).make({ + path: $mol_const(path), + copy_src: () => this.path() + }) + } + + stat(next? : $mol_file_stat | null, virt?: 'virt'): null | $mol_file_stat { + return null + } reset() { this.stat(null) } reset_schedule() { return this.$.$mol_file.reset_schedule(this.path()) } @@ -66,8 +78,8 @@ namespace $ { return this.stat()?.mtime.getTime().toString( 36 ).toUpperCase() ?? '' } - abstract ensure(): void - abstract drop(): void + ensure() {} + drop() {} watcher(reset?: null) { console.warn('$mol_file_web.watcher() not implemented') @@ -110,7 +122,8 @@ namespace $ { return match ? match[ 1 ].substring( 1 ) : '' } - abstract buffer( next? : Uint8Array ): Uint8Array + @ $mol_mem + buffer( next? : Uint8Array ) { return next ?? new Uint8Array } @ $mol_mem copy_src(path?: string) { @@ -150,13 +163,17 @@ namespace $ { } } - abstract sub(): $mol_file[] + sub() { return [] as $mol_file[] } - abstract resolve(path: string): $mol_file + resolve(path: string): $mol_file { + throw new Error('implement') + } - abstract relate( base?: $mol_file ): string - - abstract append( next : Uint8Array | string ): void + relate( base?: $mol_file ): string { + throw new Error('implement') + } + + append( next : Uint8Array | string ) {} find( include? : RegExp , diff --git a/file/file.web.ts b/file/file.web.ts index 61502e1713..4f739dd213 100644 --- a/file/file.web.ts +++ b/file/file.web.ts @@ -2,14 +2,7 @@ namespace $ { export class $mol_file_web extends $mol_file { - @ $mol_mem_key - static absolute( path : string ) { - return this.make({ - path : $mol_const( path ) - }) - } - - static relative( path : string ) { + static override relative( path : string ) { return this.absolute( new URL( path , this.base ).toString() ) } @@ -18,7 +11,7 @@ namespace $ { : '' @ $mol_mem - buffer( next? : Uint8Array ) { + override buffer( next? : Uint8Array ) { if (next !== undefined) throw new Error(`Saving content not supported: ${this.path}`) const response = $mol_fetch.response(this.path()) @@ -29,7 +22,8 @@ namespace $ { } @ $mol_mem - stat( next? : $mol_file_stat, virt?: 'virt' ) { + override stat( next? : $mol_file_stat, virt?: 'virt' ) { + this.copy_sync() let stat = next if (next === undefined) { const content = this.text() @@ -49,7 +43,7 @@ namespace $ { return stat! } - resolve( path : string ) { + override resolve( path : string ) { let res = this.path() + '/' + path while( true ) { @@ -61,24 +55,24 @@ namespace $ { return ( this.constructor as typeof $mol_file_web ).absolute( res ) } - ensure() { + override ensure() { throw new Error('$mol_file_web.ensure() not implemented') } - drop() { + override drop() { throw new Error('$mol_file_web.drop() not implemented') } @ $mol_mem - sub() : $mol_file[] { + override sub() : $mol_file[] { throw new Error('$mol_file_web.sub() not implemented') } - relate( base = ( this.constructor as typeof $mol_file ).relative( '.' )): string { + override relate( base = ( this.constructor as typeof $mol_file ).relative( '.' )): string { throw new Error('$mol_file_web.relate() not implemented') } - append( next : Uint8Array | string ) { + override append( next : Uint8Array | string ) { throw new Error('$mol_file_web.append() not implemented') } }