2021-02-26 12:21:42 +03:00
class DenoStdInternalError extends Error {
2021-12-02 10:28:09 +03:00
constructor ( message ) {
super ( message ) ;
2021-02-26 12:21:42 +03:00
this . name = "DenoStdInternalError" ;
}
}
function assert ( expr , msg = "" ) {
if ( ! expr ) {
throw new DenoStdInternalError ( msg ) ;
}
}
function get ( obj , key ) {
if ( Object . prototype . hasOwnProperty . call ( obj , key ) ) {
return obj [ key ] ;
}
}
function getForce ( obj , key ) {
const v = get ( obj , key ) ;
assert ( v != null ) ;
return v ;
}
function isNumber ( x ) {
if ( typeof x === "number" ) return true ;
if ( /^0x[0-9a-f]+$/i . test ( String ( x ) ) ) return true ;
return /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/ . test ( String ( x ) ) ;
}
function hasKey ( obj , keys ) {
let o = obj ;
keys . slice ( 0 , - 1 ) . forEach ( ( key ) = > {
o = get ( o , key ) ? ? {
} ;
} ) ;
2021-10-21 08:12:50 +03:00
const key1 = keys [ keys . length - 1 ] ;
return key1 in o ;
2021-02-26 12:21:42 +03:00
}
2021-12-21 17:52:13 +03:00
function parse ( args , { "--" : doubleDash = false , alias : alias3 = {
2021-02-26 12:21:42 +03:00
} , boolean : __boolean = false , default : defaults = {
2021-12-03 19:55:27 +03:00
} , stopEarly = false , string = [ ] , unknown = ( i1 ) = > i1
2021-02-26 12:21:42 +03:00
} = {
} ) {
const flags = {
bools : {
} ,
strings : {
} ,
unknownFn : unknown ,
allBools : false
} ;
if ( __boolean !== undefined ) {
if ( typeof __boolean === "boolean" ) {
flags . allBools = ! ! __boolean ;
} else {
const booleanArgs = typeof __boolean === "string" ? [
__boolean
] : __boolean ;
for ( const key of booleanArgs . filter ( Boolean ) ) {
flags . bools [ key ] = true ;
}
}
}
const aliases = {
} ;
2021-12-21 17:52:13 +03:00
if ( alias3 !== undefined ) {
for ( const key in alias3 ) {
const val = getForce ( alias3 , key ) ;
2021-02-26 12:21:42 +03:00
if ( typeof val === "string" ) {
aliases [ key ] = [
val
] ;
} else {
aliases [ key ] = val ;
}
for ( const alias1 of getForce ( aliases , key ) ) {
aliases [ alias1 ] = [
key
] . concat ( aliases [ key ] . filter ( ( y ) = > alias1 !== y
) ) ;
}
}
}
if ( string !== undefined ) {
const stringArgs = typeof string === "string" ? [
string
] : string ;
for ( const key of stringArgs . filter ( Boolean ) ) {
flags . strings [ key ] = true ;
2021-09-01 16:11:55 +03:00
const alias = get ( aliases , key ) ;
if ( alias ) {
for ( const al of alias ) {
2021-02-26 12:21:42 +03:00
flags . strings [ al ] = true ;
}
}
}
}
const argv = {
_ : [ ]
} ;
function argDefined ( key , arg ) {
return flags . allBools && /^--[^=]+$/ . test ( arg ) || get ( flags . bools , key ) || ! ! get ( flags . strings , key ) || ! ! get ( aliases , key ) ;
}
function setKey ( obj , keys , value ) {
let o = obj ;
keys . slice ( 0 , - 1 ) . forEach ( function ( key ) {
if ( get ( o , key ) === undefined ) {
o [ key ] = {
} ;
}
o = get ( o , key ) ;
} ) ;
2021-10-21 08:12:50 +03:00
const key4 = keys [ keys . length - 1 ] ;
if ( get ( o , key4 ) === undefined || get ( flags . bools , key4 ) || typeof get ( o , key4 ) === "boolean" ) {
o [ key4 ] = value ;
} else if ( Array . isArray ( get ( o , key4 ) ) ) {
o [ key4 ] . push ( value ) ;
2021-02-26 12:21:42 +03:00
} else {
2021-10-21 08:12:50 +03:00
o [ key4 ] = [
get ( o , key4 ) ,
2021-02-26 12:21:42 +03:00
value
] ;
}
}
function setArg ( key , val , arg = undefined ) {
if ( arg && flags . unknownFn && ! argDefined ( key , arg ) ) {
if ( flags . unknownFn ( arg , key , val ) === false ) return ;
}
const value = ! get ( flags . strings , key ) && isNumber ( val ) ? Number ( val ) : val ;
setKey ( argv , key . split ( "." ) , value ) ;
2021-09-01 16:11:55 +03:00
const alias = get ( aliases , key ) ;
if ( alias ) {
for ( const x of alias ) {
2021-02-26 12:21:42 +03:00
setKey ( argv , x . split ( "." ) , value ) ;
}
}
}
function aliasIsBoolean ( key ) {
return getForce ( aliases , key ) . some ( ( x ) = > typeof get ( flags . bools , x ) === "boolean"
) ;
}
2021-10-21 08:12:50 +03:00
for ( const key3 of Object . keys ( flags . bools ) ) {
setArg ( key3 , defaults [ key3 ] === undefined ? false : defaults [ key3 ] ) ;
2021-02-26 12:21:42 +03:00
}
let notFlags = [ ] ;
if ( args . includes ( "--" ) ) {
notFlags = args . slice ( args . indexOf ( "--" ) + 1 ) ;
args = args . slice ( 0 , args . indexOf ( "--" ) ) ;
}
2021-12-03 19:55:27 +03:00
for ( let i2 = 0 ; i2 < args . length ; i2 ++ ) {
const arg = args [ i2 ] ;
2021-02-26 12:21:42 +03:00
if ( /^--.+=/ . test ( arg ) ) {
const m = arg . match ( / ^ - - ( [ ^ = ] + ) = ( . * ) $ / s ) ;
assert ( m != null ) ;
2021-09-01 16:11:55 +03:00
const [ , key , value ] = m ;
if ( flags . bools [ key ] ) {
2021-02-26 12:21:42 +03:00
const booleanValue = value !== "false" ;
2021-09-01 16:11:55 +03:00
setArg ( key , booleanValue , arg ) ;
2021-02-26 12:21:42 +03:00
} else {
2021-09-01 16:11:55 +03:00
setArg ( key , value , arg ) ;
2021-02-26 12:21:42 +03:00
}
} else if ( /^--no-.+/ . test ( arg ) ) {
const m = arg . match ( /^--no-(.+)/ ) ;
assert ( m != null ) ;
setArg ( m [ 1 ] , false , arg ) ;
} else if ( /^--.+/ . test ( arg ) ) {
const m = arg . match ( /^--(.+)/ ) ;
assert ( m != null ) ;
2021-09-01 16:11:55 +03:00
const [ , key ] = m ;
2021-12-03 19:55:27 +03:00
const next = args [ i2 + 1 ] ;
2021-09-01 16:11:55 +03:00
if ( next !== undefined && ! /^-/ . test ( next ) && ! get ( flags . bools , key ) && ! flags . allBools && ( get ( aliases , key ) ? ! aliasIsBoolean ( key ) : true ) ) {
setArg ( key , next , arg ) ;
2021-12-03 19:55:27 +03:00
i2 ++ ;
2021-02-26 12:21:42 +03:00
} else if ( /^(true|false)$/ . test ( next ) ) {
2021-09-01 16:11:55 +03:00
setArg ( key , next === "true" , arg ) ;
2021-12-03 19:55:27 +03:00
i2 ++ ;
2021-02-26 12:21:42 +03:00
} else {
2021-09-01 16:11:55 +03:00
setArg ( key , get ( flags . strings , key ) ? "" : true , arg ) ;
2021-02-26 12:21:42 +03:00
}
} else if ( /^-[^-]+/ . test ( arg ) ) {
const letters = arg . slice ( 1 , - 1 ) . split ( "" ) ;
let broken = false ;
for ( let j = 0 ; j < letters . length ; j ++ ) {
const next = arg . slice ( j + 2 ) ;
if ( next === "-" ) {
setArg ( letters [ j ] , next , arg ) ;
continue ;
}
if ( /[A-Za-z]/ . test ( letters [ j ] ) && /=/ . test ( next ) ) {
setArg ( letters [ j ] , next . split ( /=(.+)/ ) [ 1 ] , arg ) ;
broken = true ;
break ;
}
if ( /[A-Za-z]/ . test ( letters [ j ] ) && /-?\d+(\.\d*)?(e-?\d+)?$/ . test ( next ) ) {
setArg ( letters [ j ] , next , arg ) ;
broken = true ;
break ;
}
if ( letters [ j + 1 ] && letters [ j + 1 ] . match ( /\W/ ) ) {
setArg ( letters [ j ] , arg . slice ( j + 2 ) , arg ) ;
broken = true ;
break ;
} else {
setArg ( letters [ j ] , get ( flags . strings , letters [ j ] ) ? "" : true , arg ) ;
}
}
2021-09-01 16:11:55 +03:00
const [ key ] = arg . slice ( - 1 ) ;
if ( ! broken && key !== "-" ) {
2021-12-03 19:55:27 +03:00
if ( args [ i2 + 1 ] && ! /^(-|--)[^-]/ . test ( args [ i2 + 1 ] ) && ! get ( flags . bools , key ) && ( get ( aliases , key ) ? ! aliasIsBoolean ( key ) : true ) ) {
setArg ( key , args [ i2 + 1 ] , arg ) ;
i2 ++ ;
} else if ( args [ i2 + 1 ] && /^(true|false)$/ . test ( args [ i2 + 1 ] ) ) {
setArg ( key , args [ i2 + 1 ] === "true" , arg ) ;
i2 ++ ;
2021-02-26 12:21:42 +03:00
} else {
2021-09-01 16:11:55 +03:00
setArg ( key , get ( flags . strings , key ) ? "" : true , arg ) ;
2021-02-26 12:21:42 +03:00
}
}
} else {
if ( ! flags . unknownFn || flags . unknownFn ( arg ) !== false ) {
argv . _ . push ( flags . strings [ "_" ] ? ? ! isNumber ( arg ) ? arg : Number ( arg ) ) ;
}
if ( stopEarly ) {
2021-12-03 19:55:27 +03:00
argv . _ . push ( . . . args . slice ( i2 + 1 ) ) ;
2021-02-26 12:21:42 +03:00
break ;
}
}
}
2021-10-21 08:12:50 +03:00
for ( const key2 of Object . keys ( defaults ) ) {
if ( ! hasKey ( argv , key2 . split ( "." ) ) ) {
setKey ( argv , key2 . split ( "." ) , defaults [ key2 ] ) ;
if ( aliases [ key2 ] ) {
for ( const x of aliases [ key2 ] ) {
setKey ( argv , x . split ( "." ) , defaults [ key2 ] ) ;
2021-02-26 12:21:42 +03:00
}
}
}
}
if ( doubleDash ) {
argv [ "--" ] = [ ] ;
2021-09-01 16:11:55 +03:00
for ( const key of notFlags ) {
argv [ "--" ] . push ( key ) ;
2021-02-26 12:21:42 +03:00
}
} else {
2021-09-01 16:11:55 +03:00
for ( const key of notFlags ) {
argv . _ . push ( key ) ;
2021-02-26 12:21:42 +03:00
}
}
return argv ;
}
2021-10-08 10:47:01 +03:00
const mod = {
parse : parse
} ;
2021-02-26 12:21:42 +03:00
const CHAR_UPPERCASE_A = 65 ;
const CHAR_LOWERCASE_A = 97 ;
const CHAR_UPPERCASE_Z = 90 ;
const CHAR_LOWERCASE_Z = 122 ;
const CHAR_DOT = 46 ;
const CHAR_FORWARD_SLASH = 47 ;
const CHAR_BACKWARD_SLASH = 92 ;
const CHAR_COLON = 58 ;
const CHAR_QUESTION_MARK = 63 ;
let NATIVE_OS = "linux" ;
const navigator = globalThis . navigator ;
if ( globalThis . Deno != null ) {
NATIVE_OS = Deno . build . os ;
} else if ( navigator ? . appVersion ? . includes ? . ( "Win" ) ? ? false ) {
NATIVE_OS = "windows" ;
}
const isWindows = NATIVE_OS == "windows" ;
2021-07-01 15:56:08 +03:00
const SEP = isWindows ? "\\" : "/" ;
const SEP_PATTERN = isWindows ? /[\\/]+/ : /\/+/ ;
2021-12-03 19:55:27 +03:00
function assertPath ( path1 ) {
if ( typeof path1 !== "string" ) {
throw new TypeError ( ` Path must be a string. Received ${ JSON . stringify ( path1 ) } ` ) ;
2021-02-26 12:21:42 +03:00
}
}
2021-12-03 19:55:27 +03:00
function isPosixPathSeparator ( code1 ) {
return code1 === CHAR_FORWARD_SLASH ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
function isPathSeparator ( code2 ) {
return isPosixPathSeparator ( code2 ) || code2 === CHAR_BACKWARD_SLASH ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
function isWindowsDeviceRoot ( code3 ) {
return code3 >= CHAR_LOWERCASE_A && code3 <= CHAR_LOWERCASE_Z || code3 >= CHAR_UPPERCASE_A && code3 <= CHAR_UPPERCASE_Z ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
function normalizeString ( path2 , allowAboveRoot , separator , isPathSeparator1 ) {
2021-02-26 12:21:42 +03:00
let res = "" ;
let lastSegmentLength = 0 ;
let lastSlash = - 1 ;
let dots = 0 ;
2021-12-03 19:55:27 +03:00
let code4 ;
for ( let i3 = 0 , len = path2 . length ; i3 <= len ; ++ i3 ) {
if ( i3 < len ) code4 = path2 . charCodeAt ( i3 ) ;
else if ( isPathSeparator1 ( code4 ) ) break ;
else code4 = CHAR_FORWARD_SLASH ;
if ( isPathSeparator1 ( code4 ) ) {
if ( lastSlash === i3 - 1 || dots === 1 ) {
} else if ( lastSlash !== i3 - 1 && dots === 2 ) {
2021-02-26 12:21:42 +03:00
if ( res . length < 2 || lastSegmentLength !== 2 || res . charCodeAt ( res . length - 1 ) !== CHAR_DOT || res . charCodeAt ( res . length - 2 ) !== CHAR_DOT ) {
if ( res . length > 2 ) {
const lastSlashIndex = res . lastIndexOf ( separator ) ;
if ( lastSlashIndex === - 1 ) {
res = "" ;
lastSegmentLength = 0 ;
} else {
res = res . slice ( 0 , lastSlashIndex ) ;
lastSegmentLength = res . length - 1 - res . lastIndexOf ( separator ) ;
}
2021-12-03 19:55:27 +03:00
lastSlash = i3 ;
2021-02-26 12:21:42 +03:00
dots = 0 ;
continue ;
} else if ( res . length === 2 || res . length === 1 ) {
res = "" ;
lastSegmentLength = 0 ;
2021-12-03 19:55:27 +03:00
lastSlash = i3 ;
2021-02-26 12:21:42 +03:00
dots = 0 ;
continue ;
}
}
if ( allowAboveRoot ) {
if ( res . length > 0 ) res += ` ${ separator } .. ` ;
else res = ".." ;
lastSegmentLength = 2 ;
}
} else {
2021-12-03 19:55:27 +03:00
if ( res . length > 0 ) res += separator + path2 . slice ( lastSlash + 1 , i3 ) ;
else res = path2 . slice ( lastSlash + 1 , i3 ) ;
lastSegmentLength = i3 - lastSlash - 1 ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
lastSlash = i3 ;
2021-02-26 12:21:42 +03:00
dots = 0 ;
2021-12-03 19:55:27 +03:00
} else if ( code4 === CHAR_DOT && dots !== - 1 ) {
2021-02-26 12:21:42 +03:00
++ dots ;
} else {
dots = - 1 ;
}
}
return res ;
}
2021-12-03 19:55:27 +03:00
function _format ( sep3 , pathObject ) {
2021-02-26 12:21:42 +03:00
const dir = pathObject . dir || pathObject . root ;
const base = pathObject . base || ( pathObject . name || "" ) + ( pathObject . ext || "" ) ;
if ( ! dir ) return base ;
if ( dir === pathObject . root ) return dir + base ;
2021-12-03 19:55:27 +03:00
return dir + sep3 + base ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
const sep = "\\" ;
2021-02-26 12:21:42 +03:00
const delimiter = ";" ;
function resolve ( . . . pathSegments ) {
let resolvedDevice = "" ;
let resolvedTail = "" ;
let resolvedAbsolute = false ;
2021-12-03 19:55:27 +03:00
for ( let i4 = pathSegments . length - 1 ; i4 >= - 1 ; i4 -- ) {
let path3 ;
if ( i4 >= 0 ) {
path3 = pathSegments [ i4 ] ;
2021-02-26 12:21:42 +03:00
} else if ( ! resolvedDevice ) {
if ( globalThis . Deno == null ) {
throw new TypeError ( "Resolved a drive-letter-less path without a CWD." ) ;
}
2021-12-03 19:55:27 +03:00
path3 = Deno . cwd ( ) ;
2021-02-26 12:21:42 +03:00
} else {
if ( globalThis . Deno == null ) {
throw new TypeError ( "Resolved a relative path without a CWD." ) ;
}
2021-12-03 19:55:27 +03:00
path3 = Deno . env . get ( ` = ${ resolvedDevice } ` ) || Deno . cwd ( ) ;
if ( path3 === undefined || path3 . slice ( 0 , 3 ) . toLowerCase ( ) !== ` ${ resolvedDevice . toLowerCase ( ) } \\ ` ) {
path3 = ` ${ resolvedDevice } \\ ` ;
2021-02-26 12:21:42 +03:00
}
}
2021-12-03 19:55:27 +03:00
assertPath ( path3 ) ;
const len = path3 . length ;
2021-02-26 12:21:42 +03:00
if ( len === 0 ) continue ;
let rootEnd = 0 ;
let device = "" ;
2021-12-03 19:55:27 +03:00
let isAbsolute3 = false ;
const code5 = path3 . charCodeAt ( 0 ) ;
2021-02-26 12:21:42 +03:00
if ( len > 1 ) {
2021-12-03 19:55:27 +03:00
if ( isPathSeparator ( code5 ) ) {
isAbsolute3 = true ;
if ( isPathSeparator ( path3 . charCodeAt ( 1 ) ) ) {
2021-02-26 12:21:42 +03:00
let j = 2 ;
let last = j ;
for ( ; j < len ; ++ j ) {
2021-12-03 19:55:27 +03:00
if ( isPathSeparator ( path3 . charCodeAt ( j ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( j < len && j !== last ) {
2021-12-03 19:55:27 +03:00
const firstPart = path3 . slice ( last , j ) ;
2021-02-26 12:21:42 +03:00
last = j ;
for ( ; j < len ; ++ j ) {
2021-12-03 19:55:27 +03:00
if ( ! isPathSeparator ( path3 . charCodeAt ( j ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( j < len && j !== last ) {
last = j ;
for ( ; j < len ; ++ j ) {
2021-12-03 19:55:27 +03:00
if ( isPathSeparator ( path3 . charCodeAt ( j ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( j === len ) {
2021-12-03 19:55:27 +03:00
device = ` \\ \\ ${ firstPart } \\ ${ path3 . slice ( last ) } ` ;
2021-02-26 12:21:42 +03:00
rootEnd = j ;
} else if ( j !== last ) {
2021-12-03 19:55:27 +03:00
device = ` \\ \\ ${ firstPart } \\ ${ path3 . slice ( last , j ) } ` ;
2021-02-26 12:21:42 +03:00
rootEnd = j ;
}
}
}
} else {
rootEnd = 1 ;
}
2021-12-03 19:55:27 +03:00
} else if ( isWindowsDeviceRoot ( code5 ) ) {
if ( path3 . charCodeAt ( 1 ) === CHAR_COLON ) {
device = path3 . slice ( 0 , 2 ) ;
2021-02-26 12:21:42 +03:00
rootEnd = 2 ;
if ( len > 2 ) {
2021-12-03 19:55:27 +03:00
if ( isPathSeparator ( path3 . charCodeAt ( 2 ) ) ) {
isAbsolute3 = true ;
2021-02-26 12:21:42 +03:00
rootEnd = 3 ;
}
}
}
}
2021-12-03 19:55:27 +03:00
} else if ( isPathSeparator ( code5 ) ) {
2021-02-26 12:21:42 +03:00
rootEnd = 1 ;
2021-12-03 19:55:27 +03:00
isAbsolute3 = true ;
2021-02-26 12:21:42 +03:00
}
if ( device . length > 0 && resolvedDevice . length > 0 && device . toLowerCase ( ) !== resolvedDevice . toLowerCase ( ) ) {
continue ;
}
if ( resolvedDevice . length === 0 && device . length > 0 ) {
resolvedDevice = device ;
}
if ( ! resolvedAbsolute ) {
2021-12-03 19:55:27 +03:00
resolvedTail = ` ${ path3 . slice ( rootEnd ) } \\ ${ resolvedTail } ` ;
resolvedAbsolute = isAbsolute3 ;
2021-02-26 12:21:42 +03:00
}
if ( resolvedAbsolute && resolvedDevice . length > 0 ) break ;
}
2021-12-03 19:55:27 +03:00
resolvedTail = normalizeString ( resolvedTail , ! resolvedAbsolute , "\\" , isPathSeparator ) ;
2021-02-26 12:21:42 +03:00
return resolvedDevice + ( resolvedAbsolute ? "\\" : "" ) + resolvedTail || "." ;
}
2021-12-03 19:55:27 +03:00
function normalize ( path4 ) {
assertPath ( path4 ) ;
const len = path4 . length ;
2021-02-26 12:21:42 +03:00
if ( len === 0 ) return "." ;
let rootEnd = 0 ;
let device ;
2021-12-03 19:55:27 +03:00
let isAbsolute4 = false ;
const code6 = path4 . charCodeAt ( 0 ) ;
2021-02-26 12:21:42 +03:00
if ( len > 1 ) {
2021-12-03 19:55:27 +03:00
if ( isPathSeparator ( code6 ) ) {
isAbsolute4 = true ;
if ( isPathSeparator ( path4 . charCodeAt ( 1 ) ) ) {
2021-02-26 12:21:42 +03:00
let j = 2 ;
let last = j ;
for ( ; j < len ; ++ j ) {
2021-12-03 19:55:27 +03:00
if ( isPathSeparator ( path4 . charCodeAt ( j ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( j < len && j !== last ) {
2021-12-03 19:55:27 +03:00
const firstPart = path4 . slice ( last , j ) ;
2021-02-26 12:21:42 +03:00
last = j ;
for ( ; j < len ; ++ j ) {
2021-12-03 19:55:27 +03:00
if ( ! isPathSeparator ( path4 . charCodeAt ( j ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( j < len && j !== last ) {
last = j ;
for ( ; j < len ; ++ j ) {
2021-12-03 19:55:27 +03:00
if ( isPathSeparator ( path4 . charCodeAt ( j ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( j === len ) {
2021-12-03 19:55:27 +03:00
return ` \\ \\ ${ firstPart } \\ ${ path4 . slice ( last ) } \\ ` ;
2021-02-26 12:21:42 +03:00
} else if ( j !== last ) {
2021-12-03 19:55:27 +03:00
device = ` \\ \\ ${ firstPart } \\ ${ path4 . slice ( last , j ) } ` ;
2021-02-26 12:21:42 +03:00
rootEnd = j ;
}
}
}
} else {
rootEnd = 1 ;
}
2021-12-03 19:55:27 +03:00
} else if ( isWindowsDeviceRoot ( code6 ) ) {
if ( path4 . charCodeAt ( 1 ) === CHAR_COLON ) {
device = path4 . slice ( 0 , 2 ) ;
2021-02-26 12:21:42 +03:00
rootEnd = 2 ;
if ( len > 2 ) {
2021-12-03 19:55:27 +03:00
if ( isPathSeparator ( path4 . charCodeAt ( 2 ) ) ) {
isAbsolute4 = true ;
2021-02-26 12:21:42 +03:00
rootEnd = 3 ;
}
}
}
}
2021-12-03 19:55:27 +03:00
} else if ( isPathSeparator ( code6 ) ) {
2021-02-26 12:21:42 +03:00
return "\\" ;
}
let tail ;
if ( rootEnd < len ) {
2021-12-03 19:55:27 +03:00
tail = normalizeString ( path4 . slice ( rootEnd ) , ! isAbsolute4 , "\\" , isPathSeparator ) ;
2021-02-26 12:21:42 +03:00
} else {
tail = "" ;
}
2021-12-03 19:55:27 +03:00
if ( tail . length === 0 && ! isAbsolute4 ) tail = "." ;
if ( tail . length > 0 && isPathSeparator ( path4 . charCodeAt ( len - 1 ) ) ) {
2021-02-26 12:21:42 +03:00
tail += "\\" ;
}
if ( device === undefined ) {
2021-12-03 19:55:27 +03:00
if ( isAbsolute4 ) {
2021-02-26 12:21:42 +03:00
if ( tail . length > 0 ) return ` \\ ${ tail } ` ;
else return "\\" ;
} else if ( tail . length > 0 ) {
return tail ;
} else {
return "" ;
}
2021-12-03 19:55:27 +03:00
} else if ( isAbsolute4 ) {
2021-02-26 12:21:42 +03:00
if ( tail . length > 0 ) return ` ${ device } \\ ${ tail } ` ;
else return ` ${ device } \\ ` ;
} else if ( tail . length > 0 ) {
return device + tail ;
} else {
return device ;
}
}
2021-12-03 19:55:27 +03:00
function isAbsolute ( path5 ) {
assertPath ( path5 ) ;
const len = path5 . length ;
2021-02-26 12:21:42 +03:00
if ( len === 0 ) return false ;
2021-12-03 19:55:27 +03:00
const code7 = path5 . charCodeAt ( 0 ) ;
if ( isPathSeparator ( code7 ) ) {
2021-02-26 12:21:42 +03:00
return true ;
2021-12-03 19:55:27 +03:00
} else if ( isWindowsDeviceRoot ( code7 ) ) {
if ( len > 2 && path5 . charCodeAt ( 1 ) === CHAR_COLON ) {
if ( isPathSeparator ( path5 . charCodeAt ( 2 ) ) ) return true ;
2021-02-26 12:21:42 +03:00
}
}
return false ;
}
function join ( . . . paths ) {
const pathsCount = paths . length ;
if ( pathsCount === 0 ) return "." ;
let joined ;
let firstPart = null ;
2021-12-03 19:55:27 +03:00
for ( let i5 = 0 ; i5 < pathsCount ; ++ i5 ) {
const path6 = paths [ i5 ] ;
assertPath ( path6 ) ;
if ( path6 . length > 0 ) {
if ( joined === undefined ) joined = firstPart = path6 ;
else joined += ` \\ ${ path6 } ` ;
2021-02-26 12:21:42 +03:00
}
}
if ( joined === undefined ) return "." ;
let needsReplace = true ;
let slashCount = 0 ;
assert ( firstPart != null ) ;
2021-12-03 19:55:27 +03:00
if ( isPathSeparator ( firstPart . charCodeAt ( 0 ) ) ) {
2021-02-26 12:21:42 +03:00
++ slashCount ;
const firstLen = firstPart . length ;
if ( firstLen > 1 ) {
2021-12-03 19:55:27 +03:00
if ( isPathSeparator ( firstPart . charCodeAt ( 1 ) ) ) {
2021-02-26 12:21:42 +03:00
++ slashCount ;
if ( firstLen > 2 ) {
2021-12-03 19:55:27 +03:00
if ( isPathSeparator ( firstPart . charCodeAt ( 2 ) ) ) ++ slashCount ;
2021-02-26 12:21:42 +03:00
else {
needsReplace = false ;
}
}
}
}
}
if ( needsReplace ) {
for ( ; slashCount < joined . length ; ++ slashCount ) {
2021-12-03 19:55:27 +03:00
if ( ! isPathSeparator ( joined . charCodeAt ( slashCount ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( slashCount >= 2 ) joined = ` \\ ${ joined . slice ( slashCount ) } ` ;
}
return normalize ( joined ) ;
}
function relative ( from , to ) {
assertPath ( from ) ;
assertPath ( to ) ;
if ( from === to ) return "" ;
const fromOrig = resolve ( from ) ;
const toOrig = resolve ( to ) ;
if ( fromOrig === toOrig ) return "" ;
from = fromOrig . toLowerCase ( ) ;
to = toOrig . toLowerCase ( ) ;
if ( from === to ) return "" ;
let fromStart = 0 ;
let fromEnd = from . length ;
for ( ; fromStart < fromEnd ; ++ fromStart ) {
if ( from . charCodeAt ( fromStart ) !== CHAR_BACKWARD_SLASH ) break ;
}
for ( ; fromEnd - 1 > fromStart ; -- fromEnd ) {
if ( from . charCodeAt ( fromEnd - 1 ) !== CHAR_BACKWARD_SLASH ) break ;
}
const fromLen = fromEnd - fromStart ;
let toStart = 0 ;
let toEnd = to . length ;
for ( ; toStart < toEnd ; ++ toStart ) {
if ( to . charCodeAt ( toStart ) !== CHAR_BACKWARD_SLASH ) break ;
}
for ( ; toEnd - 1 > toStart ; -- toEnd ) {
if ( to . charCodeAt ( toEnd - 1 ) !== CHAR_BACKWARD_SLASH ) break ;
}
const toLen = toEnd - toStart ;
const length = fromLen < toLen ? fromLen : toLen ;
let lastCommonSep = - 1 ;
2021-12-03 19:55:27 +03:00
let i6 = 0 ;
for ( ; i6 <= length ; ++ i6 ) {
if ( i6 === length ) {
2021-02-26 12:21:42 +03:00
if ( toLen > length ) {
2021-12-03 19:55:27 +03:00
if ( to . charCodeAt ( toStart + i6 ) === CHAR_BACKWARD_SLASH ) {
return toOrig . slice ( toStart + i6 + 1 ) ;
} else if ( i6 === 2 ) {
return toOrig . slice ( toStart + i6 ) ;
2021-02-26 12:21:42 +03:00
}
}
if ( fromLen > length ) {
2021-12-03 19:55:27 +03:00
if ( from . charCodeAt ( fromStart + i6 ) === CHAR_BACKWARD_SLASH ) {
lastCommonSep = i6 ;
} else if ( i6 === 2 ) {
2021-02-26 12:21:42 +03:00
lastCommonSep = 3 ;
}
}
break ;
}
2021-12-03 19:55:27 +03:00
const fromCode = from . charCodeAt ( fromStart + i6 ) ;
const toCode = to . charCodeAt ( toStart + i6 ) ;
2021-02-26 12:21:42 +03:00
if ( fromCode !== toCode ) break ;
2021-12-03 19:55:27 +03:00
else if ( fromCode === CHAR_BACKWARD_SLASH ) lastCommonSep = i6 ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
if ( i6 !== length && lastCommonSep === - 1 ) {
2021-02-26 12:21:42 +03:00
return toOrig ;
}
let out = "" ;
if ( lastCommonSep === - 1 ) lastCommonSep = 0 ;
2021-12-03 19:55:27 +03:00
for ( i6 = fromStart + lastCommonSep + 1 ; i6 <= fromEnd ; ++ i6 ) {
if ( i6 === fromEnd || from . charCodeAt ( i6 ) === CHAR_BACKWARD_SLASH ) {
2021-02-26 12:21:42 +03:00
if ( out . length === 0 ) out += ".." ;
else out += "\\.." ;
}
}
if ( out . length > 0 ) {
return out + toOrig . slice ( toStart + lastCommonSep , toEnd ) ;
} else {
toStart += lastCommonSep ;
if ( toOrig . charCodeAt ( toStart ) === CHAR_BACKWARD_SLASH ) ++ toStart ;
return toOrig . slice ( toStart , toEnd ) ;
}
}
2021-12-03 19:55:27 +03:00
function toNamespacedPath ( path7 ) {
if ( typeof path7 !== "string" ) return path7 ;
if ( path7 . length === 0 ) return "" ;
const resolvedPath = resolve ( path7 ) ;
2021-02-26 12:21:42 +03:00
if ( resolvedPath . length >= 3 ) {
if ( resolvedPath . charCodeAt ( 0 ) === CHAR_BACKWARD_SLASH ) {
if ( resolvedPath . charCodeAt ( 1 ) === CHAR_BACKWARD_SLASH ) {
2021-12-03 19:55:27 +03:00
const code8 = resolvedPath . charCodeAt ( 2 ) ;
if ( code8 !== CHAR_QUESTION_MARK && code8 !== CHAR_DOT ) {
2021-02-26 12:21:42 +03:00
return ` \\ \\ ? \\ UNC \\ ${ resolvedPath . slice ( 2 ) } ` ;
}
}
} else if ( isWindowsDeviceRoot ( resolvedPath . charCodeAt ( 0 ) ) ) {
if ( resolvedPath . charCodeAt ( 1 ) === CHAR_COLON && resolvedPath . charCodeAt ( 2 ) === CHAR_BACKWARD_SLASH ) {
return ` \\ \\ ? \\ ${ resolvedPath } ` ;
}
}
}
2021-12-03 19:55:27 +03:00
return path7 ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
function dirname ( path8 ) {
assertPath ( path8 ) ;
const len = path8 . length ;
2021-02-26 12:21:42 +03:00
if ( len === 0 ) return "." ;
let rootEnd = - 1 ;
let end = - 1 ;
let matchedSlash = true ;
let offset = 0 ;
2021-12-03 19:55:27 +03:00
const code9 = path8 . charCodeAt ( 0 ) ;
2021-02-26 12:21:42 +03:00
if ( len > 1 ) {
2021-12-03 19:55:27 +03:00
if ( isPathSeparator ( code9 ) ) {
2021-02-26 12:21:42 +03:00
rootEnd = offset = 1 ;
2021-12-03 19:55:27 +03:00
if ( isPathSeparator ( path8 . charCodeAt ( 1 ) ) ) {
2021-02-26 12:21:42 +03:00
let j = 2 ;
let last = j ;
for ( ; j < len ; ++ j ) {
2021-12-03 19:55:27 +03:00
if ( isPathSeparator ( path8 . charCodeAt ( j ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( j < len && j !== last ) {
last = j ;
for ( ; j < len ; ++ j ) {
2021-12-03 19:55:27 +03:00
if ( ! isPathSeparator ( path8 . charCodeAt ( j ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( j < len && j !== last ) {
last = j ;
for ( ; j < len ; ++ j ) {
2021-12-03 19:55:27 +03:00
if ( isPathSeparator ( path8 . charCodeAt ( j ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( j === len ) {
2021-12-03 19:55:27 +03:00
return path8 ;
2021-02-26 12:21:42 +03:00
}
if ( j !== last ) {
rootEnd = offset = j + 1 ;
}
}
}
}
2021-12-03 19:55:27 +03:00
} else if ( isWindowsDeviceRoot ( code9 ) ) {
if ( path8 . charCodeAt ( 1 ) === CHAR_COLON ) {
2021-02-26 12:21:42 +03:00
rootEnd = offset = 2 ;
if ( len > 2 ) {
2021-12-03 19:55:27 +03:00
if ( isPathSeparator ( path8 . charCodeAt ( 2 ) ) ) rootEnd = offset = 3 ;
2021-02-26 12:21:42 +03:00
}
}
}
2021-12-03 19:55:27 +03:00
} else if ( isPathSeparator ( code9 ) ) {
return path8 ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
for ( let i7 = len - 1 ; i7 >= offset ; -- i7 ) {
if ( isPathSeparator ( path8 . charCodeAt ( i7 ) ) ) {
2021-02-26 12:21:42 +03:00
if ( ! matchedSlash ) {
2021-12-03 19:55:27 +03:00
end = i7 ;
2021-02-26 12:21:42 +03:00
break ;
}
} else {
matchedSlash = false ;
}
}
if ( end === - 1 ) {
if ( rootEnd === - 1 ) return "." ;
else end = rootEnd ;
}
2021-12-03 19:55:27 +03:00
return path8 . slice ( 0 , end ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
function basename ( path9 , ext = "" ) {
2021-02-26 12:21:42 +03:00
if ( ext !== undefined && typeof ext !== "string" ) {
throw new TypeError ( '"ext" argument must be a string' ) ;
}
2021-12-03 19:55:27 +03:00
assertPath ( path9 ) ;
2021-02-26 12:21:42 +03:00
let start = 0 ;
let end = - 1 ;
let matchedSlash = true ;
2021-12-03 19:55:27 +03:00
let i8 ;
if ( path9 . length >= 2 ) {
const drive = path9 . charCodeAt ( 0 ) ;
2021-02-26 12:21:42 +03:00
if ( isWindowsDeviceRoot ( drive ) ) {
2021-12-03 19:55:27 +03:00
if ( path9 . charCodeAt ( 1 ) === CHAR_COLON ) start = 2 ;
2021-02-26 12:21:42 +03:00
}
}
2021-12-03 19:55:27 +03:00
if ( ext !== undefined && ext . length > 0 && ext . length <= path9 . length ) {
if ( ext . length === path9 . length && ext === path9 ) return "" ;
2021-02-26 12:21:42 +03:00
let extIdx = ext . length - 1 ;
let firstNonSlashEnd = - 1 ;
2021-12-03 19:55:27 +03:00
for ( i8 = path9 . length - 1 ; i8 >= start ; -- i8 ) {
const code10 = path9 . charCodeAt ( i8 ) ;
if ( isPathSeparator ( code10 ) ) {
2021-02-26 12:21:42 +03:00
if ( ! matchedSlash ) {
2021-12-03 19:55:27 +03:00
start = i8 + 1 ;
2021-02-26 12:21:42 +03:00
break ;
}
} else {
if ( firstNonSlashEnd === - 1 ) {
matchedSlash = false ;
2021-12-03 19:55:27 +03:00
firstNonSlashEnd = i8 + 1 ;
2021-02-26 12:21:42 +03:00
}
if ( extIdx >= 0 ) {
2021-12-03 19:55:27 +03:00
if ( code10 === ext . charCodeAt ( extIdx ) ) {
2021-07-22 10:33:00 +03:00
if ( -- extIdx === - 1 ) {
2021-12-03 19:55:27 +03:00
end = i8 ;
2021-02-26 12:21:42 +03:00
}
} else {
extIdx = - 1 ;
end = firstNonSlashEnd ;
}
}
}
}
if ( start === end ) end = firstNonSlashEnd ;
2021-12-03 19:55:27 +03:00
else if ( end === - 1 ) end = path9 . length ;
return path9 . slice ( start , end ) ;
2021-02-26 12:21:42 +03:00
} else {
2021-12-03 19:55:27 +03:00
for ( i8 = path9 . length - 1 ; i8 >= start ; -- i8 ) {
if ( isPathSeparator ( path9 . charCodeAt ( i8 ) ) ) {
2021-02-26 12:21:42 +03:00
if ( ! matchedSlash ) {
2021-12-03 19:55:27 +03:00
start = i8 + 1 ;
2021-02-26 12:21:42 +03:00
break ;
}
} else if ( end === - 1 ) {
matchedSlash = false ;
2021-12-03 19:55:27 +03:00
end = i8 + 1 ;
2021-02-26 12:21:42 +03:00
}
}
if ( end === - 1 ) return "" ;
2021-12-03 19:55:27 +03:00
return path9 . slice ( start , end ) ;
2021-02-26 12:21:42 +03:00
}
}
2021-12-03 19:55:27 +03:00
function extname ( path10 ) {
assertPath ( path10 ) ;
2021-02-26 12:21:42 +03:00
let start = 0 ;
let startDot = - 1 ;
let startPart = 0 ;
let end = - 1 ;
let matchedSlash = true ;
let preDotState = 0 ;
2021-12-03 19:55:27 +03:00
if ( path10 . length >= 2 && path10 . charCodeAt ( 1 ) === CHAR_COLON && isWindowsDeviceRoot ( path10 . charCodeAt ( 0 ) ) ) {
2021-02-26 12:21:42 +03:00
start = startPart = 2 ;
}
2021-12-03 19:55:27 +03:00
for ( let i9 = path10 . length - 1 ; i9 >= start ; -- i9 ) {
const code11 = path10 . charCodeAt ( i9 ) ;
if ( isPathSeparator ( code11 ) ) {
2021-02-26 12:21:42 +03:00
if ( ! matchedSlash ) {
2021-12-03 19:55:27 +03:00
startPart = i9 + 1 ;
2021-02-26 12:21:42 +03:00
break ;
}
continue ;
}
if ( end === - 1 ) {
matchedSlash = false ;
2021-12-03 19:55:27 +03:00
end = i9 + 1 ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
if ( code11 === CHAR_DOT ) {
if ( startDot === - 1 ) startDot = i9 ;
2021-02-26 12:21:42 +03:00
else if ( preDotState !== 1 ) preDotState = 1 ;
} else if ( startDot !== - 1 ) {
preDotState = - 1 ;
}
}
if ( startDot === - 1 || end === - 1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1 ) {
return "" ;
}
2021-12-03 19:55:27 +03:00
return path10 . slice ( startDot , end ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
function format ( pathObject ) {
2021-02-26 12:21:42 +03:00
if ( pathObject === null || typeof pathObject !== "object" ) {
throw new TypeError ( ` The "pathObject" argument must be of type Object. Received type ${ typeof pathObject } ` ) ;
}
return _format ( "\\" , pathObject ) ;
}
2021-12-03 19:55:27 +03:00
function parse1 ( path11 ) {
assertPath ( path11 ) ;
2021-02-26 12:21:42 +03:00
const ret = {
root : "" ,
dir : "" ,
base : "" ,
ext : "" ,
name : ""
} ;
2021-12-03 19:55:27 +03:00
const len = path11 . length ;
2021-02-26 12:21:42 +03:00
if ( len === 0 ) return ret ;
let rootEnd = 0 ;
2021-12-03 19:55:27 +03:00
let code12 = path11 . charCodeAt ( 0 ) ;
2021-02-26 12:21:42 +03:00
if ( len > 1 ) {
2021-12-03 19:55:27 +03:00
if ( isPathSeparator ( code12 ) ) {
2021-02-26 12:21:42 +03:00
rootEnd = 1 ;
2021-12-03 19:55:27 +03:00
if ( isPathSeparator ( path11 . charCodeAt ( 1 ) ) ) {
2021-02-26 12:21:42 +03:00
let j = 2 ;
let last = j ;
for ( ; j < len ; ++ j ) {
2021-12-03 19:55:27 +03:00
if ( isPathSeparator ( path11 . charCodeAt ( j ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( j < len && j !== last ) {
last = j ;
for ( ; j < len ; ++ j ) {
2021-12-03 19:55:27 +03:00
if ( ! isPathSeparator ( path11 . charCodeAt ( j ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( j < len && j !== last ) {
last = j ;
for ( ; j < len ; ++ j ) {
2021-12-03 19:55:27 +03:00
if ( isPathSeparator ( path11 . charCodeAt ( j ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( j === len ) {
rootEnd = j ;
} else if ( j !== last ) {
rootEnd = j + 1 ;
}
}
}
}
2021-12-03 19:55:27 +03:00
} else if ( isWindowsDeviceRoot ( code12 ) ) {
if ( path11 . charCodeAt ( 1 ) === CHAR_COLON ) {
2021-02-26 12:21:42 +03:00
rootEnd = 2 ;
if ( len > 2 ) {
2021-12-03 19:55:27 +03:00
if ( isPathSeparator ( path11 . charCodeAt ( 2 ) ) ) {
2021-02-26 12:21:42 +03:00
if ( len === 3 ) {
2021-12-03 19:55:27 +03:00
ret . root = ret . dir = path11 ;
2021-02-26 12:21:42 +03:00
return ret ;
}
rootEnd = 3 ;
}
} else {
2021-12-03 19:55:27 +03:00
ret . root = ret . dir = path11 ;
2021-02-26 12:21:42 +03:00
return ret ;
}
}
}
2021-12-03 19:55:27 +03:00
} else if ( isPathSeparator ( code12 ) ) {
ret . root = ret . dir = path11 ;
2021-02-26 12:21:42 +03:00
return ret ;
}
2021-12-03 19:55:27 +03:00
if ( rootEnd > 0 ) ret . root = path11 . slice ( 0 , rootEnd ) ;
2021-02-26 12:21:42 +03:00
let startDot = - 1 ;
let startPart = rootEnd ;
let end = - 1 ;
let matchedSlash = true ;
2021-12-03 19:55:27 +03:00
let i10 = path11 . length - 1 ;
2021-02-26 12:21:42 +03:00
let preDotState = 0 ;
2021-12-03 19:55:27 +03:00
for ( ; i10 >= rootEnd ; -- i10 ) {
code12 = path11 . charCodeAt ( i10 ) ;
if ( isPathSeparator ( code12 ) ) {
2021-02-26 12:21:42 +03:00
if ( ! matchedSlash ) {
2021-12-03 19:55:27 +03:00
startPart = i10 + 1 ;
2021-02-26 12:21:42 +03:00
break ;
}
continue ;
}
if ( end === - 1 ) {
matchedSlash = false ;
2021-12-03 19:55:27 +03:00
end = i10 + 1 ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
if ( code12 === CHAR_DOT ) {
if ( startDot === - 1 ) startDot = i10 ;
2021-02-26 12:21:42 +03:00
else if ( preDotState !== 1 ) preDotState = 1 ;
} else if ( startDot !== - 1 ) {
preDotState = - 1 ;
}
}
if ( startDot === - 1 || end === - 1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1 ) {
if ( end !== - 1 ) {
2021-12-03 19:55:27 +03:00
ret . base = ret . name = path11 . slice ( startPart , end ) ;
2021-02-26 12:21:42 +03:00
}
} else {
2021-12-03 19:55:27 +03:00
ret . name = path11 . slice ( startPart , startDot ) ;
ret . base = path11 . slice ( startPart , end ) ;
ret . ext = path11 . slice ( startDot , end ) ;
2021-02-26 12:21:42 +03:00
}
if ( startPart > 0 && startPart !== rootEnd ) {
2021-12-03 19:55:27 +03:00
ret . dir = path11 . slice ( 0 , startPart - 1 ) ;
2021-02-26 12:21:42 +03:00
} else ret . dir = ret . root ;
return ret ;
}
function fromFileUrl ( url ) {
url = url instanceof URL ? url : new URL ( url ) ;
if ( url . protocol != "file:" ) {
throw new TypeError ( "Must be a file URL." ) ;
}
2021-12-03 19:55:27 +03:00
let path12 = decodeURIComponent ( url . pathname . replace ( /\//g , "\\" ) . replace ( /%(?![0-9A-Fa-f]{2})/g , "%25" ) ) . replace ( /^\\*([A-Za-z]:)(\\|$)/ , "$1\\" ) ;
2021-02-26 12:21:42 +03:00
if ( url . hostname != "" ) {
2021-12-03 19:55:27 +03:00
path12 = ` \\ \\ ${ url . hostname } ${ path12 } ` ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
return path12 ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
function toFileUrl ( path13 ) {
if ( ! isAbsolute ( path13 ) ) {
2021-02-26 12:21:42 +03:00
throw new TypeError ( "Must be an absolute path." ) ;
}
2021-12-03 19:55:27 +03:00
const [ , hostname , pathname ] = path13 . match ( /^(?:[/\\]{2}([^/\\]+)(?=[/\\][^/\\]))?(.*)/ ) ;
2021-02-26 12:21:42 +03:00
const url = new URL ( "file:///" ) ;
url . pathname = pathname . replace ( /%/g , "%25" ) ;
if ( hostname != null ) {
url . hostname = hostname ;
if ( ! url . hostname ) {
throw new TypeError ( "Invalid hostname." ) ;
}
}
return url ;
}
2021-10-08 10:47:01 +03:00
const mod1 = {
2021-12-03 19:55:27 +03:00
sep : sep ,
2021-10-08 10:47:01 +03:00
delimiter : delimiter ,
resolve : resolve ,
normalize : normalize ,
2021-12-03 19:55:27 +03:00
isAbsolute : isAbsolute ,
2021-10-08 10:47:01 +03:00
join : join ,
relative : relative ,
toNamespacedPath : toNamespacedPath ,
dirname : dirname ,
basename : basename ,
extname : extname ,
2021-12-03 19:55:27 +03:00
format : format ,
2021-10-08 10:47:01 +03:00
parse : parse1 ,
fromFileUrl : fromFileUrl ,
toFileUrl : toFileUrl
} ;
2021-02-26 12:21:42 +03:00
const sep1 = "/" ;
const delimiter1 = ":" ;
function resolve1 ( . . . pathSegments ) {
let resolvedPath = "" ;
let resolvedAbsolute = false ;
2021-12-03 19:55:27 +03:00
for ( let i11 = pathSegments . length - 1 ; i11 >= - 1 && ! resolvedAbsolute ; i11 -- ) {
let path14 ;
if ( i11 >= 0 ) path14 = pathSegments [ i11 ] ;
2021-02-26 12:21:42 +03:00
else {
if ( globalThis . Deno == null ) {
throw new TypeError ( "Resolved a relative path without a CWD." ) ;
}
2021-12-03 19:55:27 +03:00
path14 = Deno . cwd ( ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
assertPath ( path14 ) ;
if ( path14 . length === 0 ) {
2021-02-26 12:21:42 +03:00
continue ;
}
2021-12-03 19:55:27 +03:00
resolvedPath = ` ${ path14 } / ${ resolvedPath } ` ;
resolvedAbsolute = path14 . charCodeAt ( 0 ) === CHAR_FORWARD_SLASH ;
2021-02-26 12:21:42 +03:00
}
resolvedPath = normalizeString ( resolvedPath , ! resolvedAbsolute , "/" , isPosixPathSeparator ) ;
if ( resolvedAbsolute ) {
if ( resolvedPath . length > 0 ) return ` / ${ resolvedPath } ` ;
else return "/" ;
} else if ( resolvedPath . length > 0 ) return resolvedPath ;
else return "." ;
}
2021-12-03 19:55:27 +03:00
function normalize1 ( path15 ) {
assertPath ( path15 ) ;
if ( path15 . length === 0 ) return "." ;
const isAbsolute5 = path15 . charCodeAt ( 0 ) === CHAR_FORWARD_SLASH ;
const trailingSeparator = path15 . charCodeAt ( path15 . length - 1 ) === CHAR_FORWARD_SLASH ;
path15 = normalizeString ( path15 , ! isAbsolute5 , "/" , isPosixPathSeparator ) ;
if ( path15 . length === 0 && ! isAbsolute5 ) path15 = "." ;
if ( path15 . length > 0 && trailingSeparator ) path15 += "/" ;
if ( isAbsolute5 ) return ` / ${ path15 } ` ;
return path15 ;
}
function isAbsolute1 ( path16 ) {
assertPath ( path16 ) ;
return path16 . length > 0 && path16 . charCodeAt ( 0 ) === CHAR_FORWARD_SLASH ;
2021-02-26 12:21:42 +03:00
}
function join1 ( . . . paths ) {
if ( paths . length === 0 ) return "." ;
let joined ;
2021-12-03 19:55:27 +03:00
for ( let i12 = 0 , len = paths . length ; i12 < len ; ++ i12 ) {
const path17 = paths [ i12 ] ;
assertPath ( path17 ) ;
if ( path17 . length > 0 ) {
if ( ! joined ) joined = path17 ;
else joined += ` / ${ path17 } ` ;
2021-02-26 12:21:42 +03:00
}
}
if ( ! joined ) return "." ;
return normalize1 ( joined ) ;
}
function relative1 ( from , to ) {
assertPath ( from ) ;
assertPath ( to ) ;
if ( from === to ) return "" ;
from = resolve1 ( from ) ;
to = resolve1 ( to ) ;
if ( from === to ) return "" ;
let fromStart = 1 ;
const fromEnd = from . length ;
for ( ; fromStart < fromEnd ; ++ fromStart ) {
if ( from . charCodeAt ( fromStart ) !== CHAR_FORWARD_SLASH ) break ;
}
const fromLen = fromEnd - fromStart ;
let toStart = 1 ;
const toEnd = to . length ;
for ( ; toStart < toEnd ; ++ toStart ) {
if ( to . charCodeAt ( toStart ) !== CHAR_FORWARD_SLASH ) break ;
}
const toLen = toEnd - toStart ;
const length = fromLen < toLen ? fromLen : toLen ;
let lastCommonSep = - 1 ;
2021-12-03 19:55:27 +03:00
let i13 = 0 ;
for ( ; i13 <= length ; ++ i13 ) {
if ( i13 === length ) {
2021-02-26 12:21:42 +03:00
if ( toLen > length ) {
2021-12-03 19:55:27 +03:00
if ( to . charCodeAt ( toStart + i13 ) === CHAR_FORWARD_SLASH ) {
return to . slice ( toStart + i13 + 1 ) ;
} else if ( i13 === 0 ) {
return to . slice ( toStart + i13 ) ;
2021-02-26 12:21:42 +03:00
}
} else if ( fromLen > length ) {
2021-12-03 19:55:27 +03:00
if ( from . charCodeAt ( fromStart + i13 ) === CHAR_FORWARD_SLASH ) {
lastCommonSep = i13 ;
} else if ( i13 === 0 ) {
2021-02-26 12:21:42 +03:00
lastCommonSep = 0 ;
}
}
break ;
}
2021-12-03 19:55:27 +03:00
const fromCode = from . charCodeAt ( fromStart + i13 ) ;
const toCode = to . charCodeAt ( toStart + i13 ) ;
2021-02-26 12:21:42 +03:00
if ( fromCode !== toCode ) break ;
2021-12-03 19:55:27 +03:00
else if ( fromCode === CHAR_FORWARD_SLASH ) lastCommonSep = i13 ;
2021-02-26 12:21:42 +03:00
}
let out = "" ;
2021-12-03 19:55:27 +03:00
for ( i13 = fromStart + lastCommonSep + 1 ; i13 <= fromEnd ; ++ i13 ) {
if ( i13 === fromEnd || from . charCodeAt ( i13 ) === CHAR_FORWARD_SLASH ) {
2021-02-26 12:21:42 +03:00
if ( out . length === 0 ) out += ".." ;
else out += "/.." ;
}
}
if ( out . length > 0 ) return out + to . slice ( toStart + lastCommonSep ) ;
else {
toStart += lastCommonSep ;
if ( to . charCodeAt ( toStart ) === CHAR_FORWARD_SLASH ) ++ toStart ;
return to . slice ( toStart ) ;
}
}
2021-12-03 19:55:27 +03:00
function toNamespacedPath1 ( path18 ) {
return path18 ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
function dirname1 ( path19 ) {
assertPath ( path19 ) ;
if ( path19 . length === 0 ) return "." ;
const hasRoot = path19 . charCodeAt ( 0 ) === CHAR_FORWARD_SLASH ;
2021-02-26 12:21:42 +03:00
let end = - 1 ;
let matchedSlash = true ;
2021-12-03 19:55:27 +03:00
for ( let i14 = path19 . length - 1 ; i14 >= 1 ; -- i14 ) {
if ( path19 . charCodeAt ( i14 ) === CHAR_FORWARD_SLASH ) {
2021-02-26 12:21:42 +03:00
if ( ! matchedSlash ) {
2021-12-03 19:55:27 +03:00
end = i14 ;
2021-02-26 12:21:42 +03:00
break ;
}
} else {
matchedSlash = false ;
}
}
if ( end === - 1 ) return hasRoot ? "/" : "." ;
if ( hasRoot && end === 1 ) return "//" ;
2021-12-03 19:55:27 +03:00
return path19 . slice ( 0 , end ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
function basename1 ( path20 , ext = "" ) {
2021-02-26 12:21:42 +03:00
if ( ext !== undefined && typeof ext !== "string" ) {
throw new TypeError ( '"ext" argument must be a string' ) ;
}
2021-12-03 19:55:27 +03:00
assertPath ( path20 ) ;
2021-02-26 12:21:42 +03:00
let start = 0 ;
let end = - 1 ;
let matchedSlash = true ;
2021-12-03 19:55:27 +03:00
let i15 ;
if ( ext !== undefined && ext . length > 0 && ext . length <= path20 . length ) {
if ( ext . length === path20 . length && ext === path20 ) return "" ;
2021-02-26 12:21:42 +03:00
let extIdx = ext . length - 1 ;
let firstNonSlashEnd = - 1 ;
2021-12-03 19:55:27 +03:00
for ( i15 = path20 . length - 1 ; i15 >= 0 ; -- i15 ) {
const code13 = path20 . charCodeAt ( i15 ) ;
if ( code13 === CHAR_FORWARD_SLASH ) {
2021-02-26 12:21:42 +03:00
if ( ! matchedSlash ) {
2021-12-03 19:55:27 +03:00
start = i15 + 1 ;
2021-02-26 12:21:42 +03:00
break ;
}
} else {
if ( firstNonSlashEnd === - 1 ) {
matchedSlash = false ;
2021-12-03 19:55:27 +03:00
firstNonSlashEnd = i15 + 1 ;
2021-02-26 12:21:42 +03:00
}
if ( extIdx >= 0 ) {
2021-12-03 19:55:27 +03:00
if ( code13 === ext . charCodeAt ( extIdx ) ) {
2021-07-22 10:33:00 +03:00
if ( -- extIdx === - 1 ) {
2021-12-03 19:55:27 +03:00
end = i15 ;
2021-02-26 12:21:42 +03:00
}
} else {
extIdx = - 1 ;
end = firstNonSlashEnd ;
}
}
}
}
if ( start === end ) end = firstNonSlashEnd ;
2021-12-03 19:55:27 +03:00
else if ( end === - 1 ) end = path20 . length ;
return path20 . slice ( start , end ) ;
2021-02-26 12:21:42 +03:00
} else {
2021-12-03 19:55:27 +03:00
for ( i15 = path20 . length - 1 ; i15 >= 0 ; -- i15 ) {
if ( path20 . charCodeAt ( i15 ) === CHAR_FORWARD_SLASH ) {
2021-02-26 12:21:42 +03:00
if ( ! matchedSlash ) {
2021-12-03 19:55:27 +03:00
start = i15 + 1 ;
2021-02-26 12:21:42 +03:00
break ;
}
} else if ( end === - 1 ) {
matchedSlash = false ;
2021-12-03 19:55:27 +03:00
end = i15 + 1 ;
2021-02-26 12:21:42 +03:00
}
}
if ( end === - 1 ) return "" ;
2021-12-03 19:55:27 +03:00
return path20 . slice ( start , end ) ;
2021-02-26 12:21:42 +03:00
}
}
2021-12-03 19:55:27 +03:00
function extname1 ( path21 ) {
assertPath ( path21 ) ;
2021-02-26 12:21:42 +03:00
let startDot = - 1 ;
let startPart = 0 ;
let end = - 1 ;
let matchedSlash = true ;
let preDotState = 0 ;
2021-12-03 19:55:27 +03:00
for ( let i16 = path21 . length - 1 ; i16 >= 0 ; -- i16 ) {
const code14 = path21 . charCodeAt ( i16 ) ;
if ( code14 === CHAR_FORWARD_SLASH ) {
2021-02-26 12:21:42 +03:00
if ( ! matchedSlash ) {
2021-12-03 19:55:27 +03:00
startPart = i16 + 1 ;
2021-02-26 12:21:42 +03:00
break ;
}
continue ;
}
if ( end === - 1 ) {
matchedSlash = false ;
2021-12-03 19:55:27 +03:00
end = i16 + 1 ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
if ( code14 === CHAR_DOT ) {
if ( startDot === - 1 ) startDot = i16 ;
2021-02-26 12:21:42 +03:00
else if ( preDotState !== 1 ) preDotState = 1 ;
} else if ( startDot !== - 1 ) {
preDotState = - 1 ;
}
}
if ( startDot === - 1 || end === - 1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1 ) {
return "" ;
}
2021-12-03 19:55:27 +03:00
return path21 . slice ( startDot , end ) ;
2021-02-26 12:21:42 +03:00
}
function format1 ( pathObject ) {
if ( pathObject === null || typeof pathObject !== "object" ) {
throw new TypeError ( ` The "pathObject" argument must be of type Object. Received type ${ typeof pathObject } ` ) ;
}
return _format ( "/" , pathObject ) ;
}
2021-12-03 19:55:27 +03:00
function parse2 ( path22 ) {
assertPath ( path22 ) ;
2021-02-26 12:21:42 +03:00
const ret = {
root : "" ,
dir : "" ,
base : "" ,
ext : "" ,
name : ""
} ;
2021-12-03 19:55:27 +03:00
if ( path22 . length === 0 ) return ret ;
const isAbsolute6 = path22 . charCodeAt ( 0 ) === CHAR_FORWARD_SLASH ;
2021-02-26 12:21:42 +03:00
let start ;
2021-12-03 19:55:27 +03:00
if ( isAbsolute6 ) {
2021-02-26 12:21:42 +03:00
ret . root = "/" ;
start = 1 ;
} else {
start = 0 ;
}
let startDot = - 1 ;
let startPart = 0 ;
let end = - 1 ;
let matchedSlash = true ;
2021-12-03 19:55:27 +03:00
let i17 = path22 . length - 1 ;
2021-02-26 12:21:42 +03:00
let preDotState = 0 ;
2021-12-03 19:55:27 +03:00
for ( ; i17 >= start ; -- i17 ) {
const code15 = path22 . charCodeAt ( i17 ) ;
if ( code15 === CHAR_FORWARD_SLASH ) {
2021-02-26 12:21:42 +03:00
if ( ! matchedSlash ) {
2021-12-03 19:55:27 +03:00
startPart = i17 + 1 ;
2021-02-26 12:21:42 +03:00
break ;
}
continue ;
}
if ( end === - 1 ) {
matchedSlash = false ;
2021-12-03 19:55:27 +03:00
end = i17 + 1 ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
if ( code15 === CHAR_DOT ) {
if ( startDot === - 1 ) startDot = i17 ;
2021-02-26 12:21:42 +03:00
else if ( preDotState !== 1 ) preDotState = 1 ;
} else if ( startDot !== - 1 ) {
preDotState = - 1 ;
}
}
if ( startDot === - 1 || end === - 1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1 ) {
if ( end !== - 1 ) {
2021-12-03 19:55:27 +03:00
if ( startPart === 0 && isAbsolute6 ) {
ret . base = ret . name = path22 . slice ( 1 , end ) ;
2021-02-26 12:21:42 +03:00
} else {
2021-12-03 19:55:27 +03:00
ret . base = ret . name = path22 . slice ( startPart , end ) ;
2021-02-26 12:21:42 +03:00
}
}
} else {
2021-12-03 19:55:27 +03:00
if ( startPart === 0 && isAbsolute6 ) {
ret . name = path22 . slice ( 1 , startDot ) ;
ret . base = path22 . slice ( 1 , end ) ;
2021-02-26 12:21:42 +03:00
} else {
2021-12-03 19:55:27 +03:00
ret . name = path22 . slice ( startPart , startDot ) ;
ret . base = path22 . slice ( startPart , end ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
ret . ext = path22 . slice ( startDot , end ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
if ( startPart > 0 ) ret . dir = path22 . slice ( 0 , startPart - 1 ) ;
else if ( isAbsolute6 ) ret . dir = "/" ;
2021-02-26 12:21:42 +03:00
return ret ;
}
function fromFileUrl1 ( url ) {
url = url instanceof URL ? url : new URL ( url ) ;
if ( url . protocol != "file:" ) {
throw new TypeError ( "Must be a file URL." ) ;
}
return decodeURIComponent ( url . pathname . replace ( /%(?![0-9A-Fa-f]{2})/g , "%25" ) ) ;
}
2021-12-03 19:55:27 +03:00
function toFileUrl1 ( path23 ) {
if ( ! isAbsolute1 ( path23 ) ) {
2021-02-26 12:21:42 +03:00
throw new TypeError ( "Must be an absolute path." ) ;
}
const url = new URL ( "file:///" ) ;
2021-12-03 19:55:27 +03:00
url . pathname = path23 . replace ( /%/g , "%25" ) . replace ( /\\/g , "%5C" ) ;
2021-02-26 12:21:42 +03:00
return url ;
}
2021-10-08 10:47:01 +03:00
const mod2 = {
sep : sep1 ,
delimiter : delimiter1 ,
resolve : resolve1 ,
normalize : normalize1 ,
isAbsolute : isAbsolute1 ,
join : join1 ,
relative : relative1 ,
toNamespacedPath : toNamespacedPath1 ,
dirname : dirname1 ,
basename : basename1 ,
extname : extname1 ,
format : format1 ,
parse : parse2 ,
fromFileUrl : fromFileUrl1 ,
toFileUrl : toFileUrl1
} ;
2021-12-03 19:55:27 +03:00
function common ( paths , sep4 = SEP ) {
2021-02-26 12:21:42 +03:00
const [ first = "" , . . . remaining ] = paths ;
if ( first === "" || remaining . length === 0 ) {
2021-12-03 19:55:27 +03:00
return first . substring ( 0 , first . lastIndexOf ( sep4 ) + 1 ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
const parts = first . split ( sep4 ) ;
2021-02-26 12:21:42 +03:00
let endOfPrefix = parts . length ;
2021-12-03 19:55:27 +03:00
for ( const path24 of remaining ) {
const compare1 = path24 . split ( sep4 ) ;
for ( let i18 = 0 ; i18 < endOfPrefix ; i18 ++ ) {
if ( compare1 [ i18 ] !== parts [ i18 ] ) {
endOfPrefix = i18 ;
2021-02-26 12:21:42 +03:00
}
}
if ( endOfPrefix === 0 ) {
return "" ;
}
}
2021-12-03 19:55:27 +03:00
const prefix = parts . slice ( 0 , endOfPrefix ) . join ( sep4 ) ;
return prefix . endsWith ( sep4 ) ? prefix : ` ${ prefix } ${ sep4 } ` ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
const path = isWindows ? mod1 : mod2 ;
2021-07-01 15:56:08 +03:00
const regExpEscapeChars = [
"!" ,
"$" ,
"(" ,
")" ,
"*" ,
"+" ,
"." ,
"=" ,
"?" ,
"[" ,
"\\" ,
"^" ,
"{" ,
"|"
] ;
2021-02-26 12:21:42 +03:00
const win32 = mod1 ;
const posix = mod2 ;
2021-12-03 19:55:27 +03:00
const { basename : basename2 , delimiter : delimiter2 , dirname : dirname2 , extname : extname2 , format : format2 , fromFileUrl : fromFileUrl2 , isAbsolute : isAbsolute2 , join : join2 , normalize : normalize2 , parse : parse3 , relative : relative2 , resolve : resolve2 , sep : sep2 , toFileUrl : toFileUrl2 , toNamespacedPath : toNamespacedPath2 , } = path ;
2021-02-26 12:21:42 +03:00
const rangeEscapeChars = [
"-" ,
"\\" ,
"]"
] ;
function globToRegExp ( glob , { extended = true , globstar : globstarOption = true , os = NATIVE_OS } = {
} ) {
if ( glob == "" ) {
return /(?!)/ ;
}
2021-12-03 19:55:27 +03:00
const sep5 = os == "windows" ? "(?:\\\\|/)+" : "/+" ;
2021-02-26 12:21:42 +03:00
const sepMaybe = os == "windows" ? "(?:\\\\|/)*" : "/*" ;
const seps = os == "windows" ? [
"\\" ,
"/"
] : [
"/"
] ;
const globstar = os == "windows" ? "(?:[^\\\\/]*(?:\\\\|/|$)+)*" : "(?:[^/]*(?:/|$)+)*" ;
const wildcard = os == "windows" ? "[^\\\\/]*" : "[^/]*" ;
const escapePrefix = os == "windows" ? "`" : "\\" ;
let newLength = glob . length ;
for ( ; newLength > 1 && seps . includes ( glob [ newLength - 1 ] ) ; newLength -- ) ;
glob = glob . slice ( 0 , newLength ) ;
let regExpString = "" ;
for ( let j = 0 ; j < glob . length ; ) {
let segment = "" ;
const groupStack = [ ] ;
let inRange = false ;
let inEscape = false ;
let endsWithSep = false ;
2021-12-03 19:55:27 +03:00
let i19 = j ;
for ( ; i19 < glob . length && ! seps . includes ( glob [ i19 ] ) ; i19 ++ ) {
2021-02-26 12:21:42 +03:00
if ( inEscape ) {
inEscape = false ;
const escapeChars = inRange ? rangeEscapeChars : regExpEscapeChars ;
2021-12-03 19:55:27 +03:00
segment += escapeChars . includes ( glob [ i19 ] ) ? ` \\ ${ glob [ i19 ] } ` : glob [ i19 ] ;
2021-02-26 12:21:42 +03:00
continue ;
}
2021-12-03 19:55:27 +03:00
if ( glob [ i19 ] == escapePrefix ) {
2021-02-26 12:21:42 +03:00
inEscape = true ;
continue ;
}
2021-12-03 19:55:27 +03:00
if ( glob [ i19 ] == "[" ) {
2021-02-26 12:21:42 +03:00
if ( ! inRange ) {
inRange = true ;
segment += "[" ;
2021-12-03 19:55:27 +03:00
if ( glob [ i19 + 1 ] == "!" ) {
i19 ++ ;
2021-02-26 12:21:42 +03:00
segment += "^" ;
2021-12-03 19:55:27 +03:00
} else if ( glob [ i19 + 1 ] == "^" ) {
i19 ++ ;
2021-02-26 12:21:42 +03:00
segment += "\\^" ;
}
continue ;
2021-12-03 19:55:27 +03:00
} else if ( glob [ i19 + 1 ] == ":" ) {
let k = i19 + 1 ;
2021-02-26 12:21:42 +03:00
let value = "" ;
while ( glob [ k + 1 ] != null && glob [ k + 1 ] != ":" ) {
value += glob [ k + 1 ] ;
k ++ ;
}
if ( glob [ k + 1 ] == ":" && glob [ k + 2 ] == "]" ) {
2021-12-03 19:55:27 +03:00
i19 = k + 2 ;
2021-02-26 12:21:42 +03:00
if ( value == "alnum" ) segment += "\\dA-Za-z" ;
else if ( value == "alpha" ) segment += "A-Za-z" ;
else if ( value == "ascii" ) segment += "\x00-\x7F" ;
else if ( value == "blank" ) segment += "\t " ;
else if ( value == "cntrl" ) segment += "\x00-\x1F\x7F" ;
else if ( value == "digit" ) segment += "\\d" ;
else if ( value == "graph" ) segment += "\x21-\x7E" ;
else if ( value == "lower" ) segment += "a-z" ;
else if ( value == "print" ) segment += "\x20-\x7E" ;
else if ( value == "punct" ) {
segment += "!\"#$%&'()*+,\\-./:;<=>?@[\\\\\\]^_‘ {|}~" ;
} else if ( value == "space" ) segment += "\\s\v" ;
else if ( value == "upper" ) segment += "A-Z" ;
else if ( value == "word" ) segment += "\\w" ;
else if ( value == "xdigit" ) segment += "\\dA-Fa-f" ;
continue ;
}
}
}
2021-12-03 19:55:27 +03:00
if ( glob [ i19 ] == "]" && inRange ) {
2021-02-26 12:21:42 +03:00
inRange = false ;
segment += "]" ;
continue ;
}
if ( inRange ) {
2021-12-03 19:55:27 +03:00
if ( glob [ i19 ] == "\\" ) {
2021-02-26 12:21:42 +03:00
segment += ` \\ \\ ` ;
} else {
2021-12-03 19:55:27 +03:00
segment += glob [ i19 ] ;
2021-02-26 12:21:42 +03:00
}
continue ;
}
2021-12-03 19:55:27 +03:00
if ( glob [ i19 ] == ")" && groupStack . length > 0 && groupStack [ groupStack . length - 1 ] != "BRACE" ) {
2021-02-26 12:21:42 +03:00
segment += ")" ;
const type = groupStack . pop ( ) ;
if ( type == "!" ) {
segment += wildcard ;
} else if ( type != "@" ) {
segment += type ;
}
continue ;
}
2021-12-03 19:55:27 +03:00
if ( glob [ i19 ] == "|" && groupStack . length > 0 && groupStack [ groupStack . length - 1 ] != "BRACE" ) {
2021-02-26 12:21:42 +03:00
segment += "|" ;
continue ;
}
2021-12-03 19:55:27 +03:00
if ( glob [ i19 ] == "+" && extended && glob [ i19 + 1 ] == "(" ) {
i19 ++ ;
2021-02-26 12:21:42 +03:00
groupStack . push ( "+" ) ;
segment += "(?:" ;
continue ;
}
2021-12-03 19:55:27 +03:00
if ( glob [ i19 ] == "@" && extended && glob [ i19 + 1 ] == "(" ) {
i19 ++ ;
2021-02-26 12:21:42 +03:00
groupStack . push ( "@" ) ;
segment += "(?:" ;
continue ;
}
2021-12-03 19:55:27 +03:00
if ( glob [ i19 ] == "?" ) {
if ( extended && glob [ i19 + 1 ] == "(" ) {
i19 ++ ;
2021-02-26 12:21:42 +03:00
groupStack . push ( "?" ) ;
segment += "(?:" ;
} else {
segment += "." ;
}
continue ;
}
2021-12-03 19:55:27 +03:00
if ( glob [ i19 ] == "!" && extended && glob [ i19 + 1 ] == "(" ) {
i19 ++ ;
2021-02-26 12:21:42 +03:00
groupStack . push ( "!" ) ;
segment += "(?!" ;
continue ;
}
2021-12-03 19:55:27 +03:00
if ( glob [ i19 ] == "{" ) {
2021-02-26 12:21:42 +03:00
groupStack . push ( "BRACE" ) ;
segment += "(?:" ;
continue ;
}
2021-12-03 19:55:27 +03:00
if ( glob [ i19 ] == "}" && groupStack [ groupStack . length - 1 ] == "BRACE" ) {
2021-02-26 12:21:42 +03:00
groupStack . pop ( ) ;
segment += ")" ;
continue ;
}
2021-12-03 19:55:27 +03:00
if ( glob [ i19 ] == "," && groupStack [ groupStack . length - 1 ] == "BRACE" ) {
2021-02-26 12:21:42 +03:00
segment += "|" ;
continue ;
}
2021-12-03 19:55:27 +03:00
if ( glob [ i19 ] == "*" ) {
if ( extended && glob [ i19 + 1 ] == "(" ) {
i19 ++ ;
2021-02-26 12:21:42 +03:00
groupStack . push ( "*" ) ;
segment += "(?:" ;
} else {
2021-12-03 19:55:27 +03:00
const prevChar = glob [ i19 - 1 ] ;
2021-02-26 12:21:42 +03:00
let numStars = 1 ;
2021-12-03 19:55:27 +03:00
while ( glob [ i19 + 1 ] == "*" ) {
i19 ++ ;
2021-02-26 12:21:42 +03:00
numStars ++ ;
}
2021-12-03 19:55:27 +03:00
const nextChar = glob [ i19 + 1 ] ;
2021-02-26 12:21:42 +03:00
if ( globstarOption && numStars == 2 && [
. . . seps ,
undefined
] . includes ( prevChar ) && [
. . . seps ,
undefined
] . includes ( nextChar ) ) {
segment += globstar ;
endsWithSep = true ;
} else {
segment += wildcard ;
}
}
continue ;
}
2021-12-03 19:55:27 +03:00
segment += regExpEscapeChars . includes ( glob [ i19 ] ) ? ` \\ ${ glob [ i19 ] } ` : glob [ i19 ] ;
2021-02-26 12:21:42 +03:00
}
if ( groupStack . length > 0 || inRange || inEscape ) {
segment = "" ;
2021-12-03 19:55:27 +03:00
for ( const c of glob . slice ( j , i19 ) ) {
2021-02-26 12:21:42 +03:00
segment += regExpEscapeChars . includes ( c ) ? ` \\ ${ c } ` : c ;
endsWithSep = false ;
}
}
regExpString += segment ;
if ( ! endsWithSep ) {
2021-12-03 19:55:27 +03:00
regExpString += i19 < glob . length ? sep5 : sepMaybe ;
2021-02-26 12:21:42 +03:00
endsWithSep = true ;
}
2021-12-03 19:55:27 +03:00
while ( seps . includes ( glob [ i19 ] ) ) i19 ++ ;
if ( ! ( i19 > j ) ) {
2021-02-26 12:21:42 +03:00
throw new Error ( "Assertion failure: i > j (potential infinite loop)" ) ;
}
2021-12-03 19:55:27 +03:00
j = i19 ;
2021-02-26 12:21:42 +03:00
}
regExpString = ` ^ ${ regExpString } $ ` ;
return new RegExp ( regExpString ) ;
}
function isGlob ( str ) {
const chars = {
"{" : "}" ,
"(" : ")" ,
"[" : "]"
} ;
const regex = /\\(.)|(^!|\*|[\].+)]\?|\[[^\\\]]+\]|\{[^\\}]+\}|\(\?[:!=][^\\)]+\)|\([^|]+\|[^\\)]+\))/ ;
if ( str === "" ) {
return false ;
}
let match ;
while ( match = regex . exec ( str ) ) {
if ( match [ 2 ] ) return true ;
let idx = match . index + match [ 0 ] . length ;
const open = match [ 1 ] ;
const close = open ? chars [ open ] : null ;
if ( open && close ) {
const n = str . indexOf ( close , idx ) ;
if ( n !== - 1 ) {
idx = n + 1 ;
}
}
str = str . slice ( idx ) ;
}
return false ;
}
function normalizeGlob ( glob , { globstar = false } = {
} ) {
if ( glob . match ( /\0/g ) ) {
throw new Error ( ` Glob contains invalid characters: " ${ glob } " ` ) ;
}
if ( ! globstar ) {
return normalize2 ( glob ) ;
}
const s = SEP_PATTERN . source ;
const badParentPattern = new RegExp ( ` (?<=( ${ s } |^) \\ * \\ * ${ s } ) \\ . \\ .(?= ${ s } | $ ) ` , "g" ) ;
return normalize2 ( glob . replace ( badParentPattern , "\0" ) ) . replace ( /\0/g , ".." ) ;
}
function joinGlobs ( globs , { extended = false , globstar = false } = {
} ) {
if ( ! globstar || globs . length == 0 ) {
return join2 ( . . . globs ) ;
}
if ( globs . length === 0 ) return "." ;
let joined ;
for ( const glob of globs ) {
2021-12-03 19:55:27 +03:00
const path25 = glob ;
if ( path25 . length > 0 ) {
if ( ! joined ) joined = path25 ;
else joined += ` ${ SEP } ${ path25 } ` ;
2021-02-26 12:21:42 +03:00
}
}
if ( ! joined ) return "." ;
return normalizeGlob ( joined , {
extended ,
globstar
} ) ;
}
2021-10-08 10:47:01 +03:00
const mod3 = {
SEP : SEP ,
SEP_PATTERN : SEP_PATTERN ,
win32 : win32 ,
posix : posix ,
basename : basename2 ,
delimiter : delimiter2 ,
dirname : dirname2 ,
extname : extname2 ,
format : format2 ,
fromFileUrl : fromFileUrl2 ,
isAbsolute : isAbsolute2 ,
join : join2 ,
normalize : normalize2 ,
parse : parse3 ,
relative : relative2 ,
resolve : resolve2 ,
sep : sep2 ,
toFileUrl : toFileUrl2 ,
toNamespacedPath : toNamespacedPath2 ,
common ,
globToRegExp ,
isGlob ,
normalizeGlob ,
joinGlobs
} ;
2021-12-03 19:55:27 +03:00
var LogLevels ;
( function ( LogLevels1 ) {
LogLevels1 [ LogLevels1 [ "NOTSET" ] = 0 ] = "NOTSET" ;
LogLevels1 [ LogLevels1 [ "DEBUG" ] = 10 ] = "DEBUG" ;
LogLevels1 [ LogLevels1 [ "INFO" ] = 20 ] = "INFO" ;
LogLevels1 [ LogLevels1 [ "WARNING" ] = 30 ] = "WARNING" ;
LogLevels1 [ LogLevels1 [ "ERROR" ] = 40 ] = "ERROR" ;
LogLevels1 [ LogLevels1 [ "CRITICAL" ] = 50 ] = "CRITICAL" ;
} ) ( LogLevels || ( LogLevels = {
2021-02-26 12:21:42 +03:00
} ) ) ;
2021-12-03 19:55:27 +03:00
Object . keys ( LogLevels ) . filter ( ( key ) = > isNaN ( Number ( key ) )
2021-10-08 10:47:01 +03:00
) ;
2021-02-26 12:21:42 +03:00
const byLevel = {
2021-12-03 19:55:27 +03:00
[ String ( LogLevels . NOTSET ) ] : "NOTSET" ,
[ String ( LogLevels . DEBUG ) ] : "DEBUG" ,
[ String ( LogLevels . INFO ) ] : "INFO" ,
[ String ( LogLevels . WARNING ) ] : "WARNING" ,
[ String ( LogLevels . ERROR ) ] : "ERROR" ,
[ String ( LogLevels . CRITICAL ) ] : "CRITICAL"
2021-02-26 12:21:42 +03:00
} ;
function getLevelByName ( name ) {
switch ( name ) {
case "NOTSET" :
2021-12-03 19:55:27 +03:00
return LogLevels . NOTSET ;
2021-02-26 12:21:42 +03:00
case "DEBUG" :
2021-12-03 19:55:27 +03:00
return LogLevels . DEBUG ;
2021-02-26 12:21:42 +03:00
case "INFO" :
2021-12-03 19:55:27 +03:00
return LogLevels . INFO ;
2021-02-26 12:21:42 +03:00
case "WARNING" :
2021-12-03 19:55:27 +03:00
return LogLevels . WARNING ;
2021-02-26 12:21:42 +03:00
case "ERROR" :
2021-12-03 19:55:27 +03:00
return LogLevels . ERROR ;
2021-02-26 12:21:42 +03:00
case "CRITICAL" :
2021-12-03 19:55:27 +03:00
return LogLevels . CRITICAL ;
2021-02-26 12:21:42 +03:00
default :
throw new Error ( ` no log level found for " ${ name } " ` ) ;
}
}
function getLevelName ( level ) {
const levelName = byLevel [ level ] ;
if ( levelName ) {
return levelName ;
}
throw new Error ( ` no level name found for level: ${ level } ` ) ;
}
class LogRecord {
# args ;
# datetime ;
2021-12-02 10:28:09 +03:00
constructor ( options ) {
this . msg = options . msg ;
2021-02-26 12:21:42 +03:00
this . # args = [
2021-12-02 10:28:09 +03:00
. . . options . args
2021-02-26 12:21:42 +03:00
] ;
2021-12-02 10:28:09 +03:00
this . level = options . level ;
this . loggerName = options . loggerName ;
2021-02-26 12:21:42 +03:00
this . # datetime = new Date ( ) ;
2021-12-02 10:28:09 +03:00
this . levelName = getLevelName ( options . level ) ;
2021-02-26 12:21:42 +03:00
}
get args() {
return [
. . . this . # args
] ;
}
get datetime() {
return new Date ( this . # datetime . getTime ( ) ) ;
}
}
class Logger {
# level ;
# handlers ;
# loggerName ;
2021-12-02 10:28:09 +03:00
constructor ( loggerName , levelName , options = {
2021-02-26 12:21:42 +03:00
} ) {
2021-12-02 10:28:09 +03:00
this . # loggerName = loggerName ;
this . # level = getLevelByName ( levelName ) ;
this . # handlers = options . handlers || [ ] ;
2021-02-26 12:21:42 +03:00
}
get level() {
return this . # level ;
}
set level ( level ) {
this . # level = level ;
}
get levelName() {
return getLevelName ( this . # level ) ;
}
2021-12-02 10:28:09 +03:00
set levelName ( levelName ) {
this . # level = getLevelByName ( levelName ) ;
2021-02-26 12:21:42 +03:00
}
get loggerName() {
return this . # loggerName ;
}
set handlers ( hndls ) {
this . # handlers = hndls ;
}
get handlers() {
return this . # handlers ;
}
2021-12-02 10:28:09 +03:00
_log ( level , msg , . . . args ) {
if ( this . level > level ) {
return msg instanceof Function ? undefined : msg ;
2021-02-26 12:21:42 +03:00
}
let fnResult ;
let logMessage ;
2021-12-02 10:28:09 +03:00
if ( msg instanceof Function ) {
fnResult = msg ( ) ;
2021-02-26 12:21:42 +03:00
logMessage = this . asString ( fnResult ) ;
} else {
2021-12-02 10:28:09 +03:00
logMessage = this . asString ( msg ) ;
2021-02-26 12:21:42 +03:00
}
const record = new LogRecord ( {
msg : logMessage ,
2021-12-02 10:28:09 +03:00
args : args ,
level : level ,
2021-02-26 12:21:42 +03:00
loggerName : this.loggerName
} ) ;
this . # handlers . forEach ( ( handler ) = > {
handler . handle ( record ) ;
} ) ;
2021-12-02 10:28:09 +03:00
return msg instanceof Function ? fnResult : msg ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
asString ( data ) {
if ( typeof data === "string" ) {
return data ;
} else if ( data === null || typeof data === "number" || typeof data === "bigint" || typeof data === "boolean" || typeof data === "undefined" || typeof data === "symbol" ) {
return String ( data ) ;
} else if ( typeof data === "object" ) {
return JSON . stringify ( data ) ;
2021-02-26 12:21:42 +03:00
}
return "undefined" ;
}
2021-12-02 10:28:09 +03:00
debug ( msg , . . . args ) {
2021-12-03 19:55:27 +03:00
return this . _log ( LogLevels . DEBUG , msg , . . . args ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
info ( msg , . . . args ) {
2021-12-03 19:55:27 +03:00
return this . _log ( LogLevels . INFO , msg , . . . args ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
warning ( msg , . . . args ) {
2021-12-03 19:55:27 +03:00
return this . _log ( LogLevels . WARNING , msg , . . . args ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
error ( msg , . . . args ) {
2021-12-03 19:55:27 +03:00
return this . _log ( LogLevels . ERROR , msg , . . . args ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
critical ( msg , . . . args ) {
2021-12-03 19:55:27 +03:00
return this . _log ( LogLevels . CRITICAL , msg , . . . args ) ;
2021-02-26 12:21:42 +03:00
}
}
const noColor = globalThis . Deno ? . noColor ? ? true ;
let enabled = ! noColor ;
2021-12-03 19:55:27 +03:00
function code ( open , close ) {
2021-02-26 12:21:42 +03:00
return {
open : ` \ x1b[ ${ open . join ( ";" ) } m ` ,
close : ` \ x1b[ ${ close } m ` ,
regexp : new RegExp ( ` \\ x1b \\ [ ${ close } m ` , "g" )
} ;
}
2021-12-03 19:55:27 +03:00
function run ( str , code16 ) {
return enabled ? ` ${ code16 . open } ${ str . replace ( code16 . regexp , code16 . open ) } ${ code16 . close } ` : str ;
2021-02-26 12:21:42 +03:00
}
function bold ( str ) {
2021-12-03 19:55:27 +03:00
return run ( str , code ( [
2021-02-26 12:21:42 +03:00
1
] , 22 ) ) ;
}
function red ( str ) {
2021-12-03 19:55:27 +03:00
return run ( str , code ( [
2021-02-26 12:21:42 +03:00
31
] , 39 ) ) ;
}
function yellow ( str ) {
2021-12-03 19:55:27 +03:00
return run ( str , code ( [
2021-02-26 12:21:42 +03:00
33
] , 39 ) ) ;
}
function blue ( str ) {
2021-12-03 19:55:27 +03:00
return run ( str , code ( [
2021-02-26 12:21:42 +03:00
34
] , 39 ) ) ;
}
2021-10-08 10:47:01 +03:00
new RegExp ( [
2021-02-26 12:21:42 +03:00
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)" ,
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))" ,
] . join ( "|" ) , "g" ) ;
async function exists ( filePath ) {
try {
await Deno . lstat ( filePath ) ;
return true ;
} catch ( err ) {
if ( err instanceof Deno . errors . NotFound ) {
return false ;
}
throw err ;
}
}
function existsSync ( filePath ) {
try {
Deno . lstatSync ( filePath ) ;
return true ;
} catch ( err ) {
if ( err instanceof Deno . errors . NotFound ) {
return false ;
}
throw err ;
}
}
2021-12-03 19:55:27 +03:00
function copyBytes ( src1 , dst , off = 0 ) {
2021-02-26 12:21:42 +03:00
off = Math . max ( 0 , Math . min ( off , dst . byteLength ) ) ;
const dstBytesAvailable = dst . byteLength - off ;
2021-12-03 19:55:27 +03:00
if ( src1 . byteLength > dstBytesAvailable ) {
src1 = src1 . subarray ( 0 , dstBytesAvailable ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
dst . set ( src1 , off ) ;
return src1 . byteLength ;
2021-02-26 12:21:42 +03:00
}
const DEFAULT_BUF_SIZE = 4096 ;
const MIN_BUF_SIZE = 16 ;
const MAX_CONSECUTIVE_EMPTY_READS = 100 ;
const CR = "\r" . charCodeAt ( 0 ) ;
const LF = "\n" . charCodeAt ( 0 ) ;
class BufferFullError extends Error {
constructor ( partial ) {
super ( "Buffer full" ) ;
this . partial = partial ;
2021-03-21 16:31:35 +03:00
this . name = "BufferFullError" ;
2021-02-26 12:21:42 +03:00
}
}
class PartialReadError extends Deno . errors . UnexpectedEof {
constructor ( ) {
super ( "Encountered UnexpectedEof, data only partially read" ) ;
2021-03-21 16:31:35 +03:00
this . name = "PartialReadError" ;
2021-02-26 12:21:42 +03:00
}
}
class BufReader {
2021-12-02 10:28:09 +03:00
static create ( r , size = DEFAULT_BUF_SIZE ) {
return r instanceof BufReader ? r : new BufReader ( r , size ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
constructor ( rd , size = DEFAULT_BUF_SIZE ) {
2021-03-21 16:31:35 +03:00
this . r = 0 ;
this . w = 0 ;
this . eof = false ;
2021-12-02 10:28:09 +03:00
if ( size < MIN_BUF_SIZE ) {
size = MIN_BUF_SIZE ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
this . _reset ( new Uint8Array ( size ) , rd ) ;
2021-02-26 12:21:42 +03:00
}
size() {
return this . buf . byteLength ;
}
buffered() {
return this . w - this . r ;
}
async _fill() {
if ( this . r > 0 ) {
this . buf . copyWithin ( 0 , this . r , this . w ) ;
this . w -= this . r ;
this . r = 0 ;
}
if ( this . w >= this . buf . byteLength ) {
throw Error ( "bufio: tried to fill full buffer" ) ;
}
2021-12-03 19:55:27 +03:00
for ( let i20 = MAX_CONSECUTIVE_EMPTY_READS ; i20 > 0 ; i20 -- ) {
2021-02-26 12:21:42 +03:00
const rr = await this . rd . read ( this . buf . subarray ( this . w ) ) ;
if ( rr === null ) {
this . eof = true ;
return ;
}
assert ( rr >= 0 , "negative read" ) ;
this . w += rr ;
if ( rr > 0 ) {
return ;
}
}
throw new Error ( ` No progress after ${ MAX_CONSECUTIVE_EMPTY_READS } read() calls ` ) ;
}
2021-12-02 10:28:09 +03:00
reset ( r ) {
this . _reset ( this . buf , r ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
_reset ( buf , rd ) {
this . buf = buf ;
this . rd = rd ;
2021-02-26 12:21:42 +03:00
this . eof = false ;
}
2021-12-02 10:28:09 +03:00
async read ( p ) {
let rr = p . byteLength ;
if ( p . byteLength === 0 ) return rr ;
2021-02-26 12:21:42 +03:00
if ( this . r === this . w ) {
2021-12-02 10:28:09 +03:00
if ( p . byteLength >= this . buf . byteLength ) {
const rr = await this . rd . read ( p ) ;
2021-09-01 16:11:55 +03:00
const nread = rr ? ? 0 ;
2021-02-26 12:21:42 +03:00
assert ( nread >= 0 , "negative read" ) ;
2021-09-01 16:11:55 +03:00
return rr ;
2021-02-26 12:21:42 +03:00
}
this . r = 0 ;
this . w = 0 ;
rr = await this . rd . read ( this . buf ) ;
if ( rr === 0 || rr === null ) return rr ;
assert ( rr >= 0 , "negative read" ) ;
this . w += rr ;
}
2021-12-02 10:28:09 +03:00
const copied = copyBytes ( this . buf . subarray ( this . r , this . w ) , p , 0 ) ;
2021-02-26 12:21:42 +03:00
this . r += copied ;
return copied ;
}
2021-12-02 10:28:09 +03:00
async readFull ( p ) {
2021-02-26 12:21:42 +03:00
let bytesRead = 0 ;
2021-12-02 10:28:09 +03:00
while ( bytesRead < p . length ) {
2021-02-26 12:21:42 +03:00
try {
2021-12-02 10:28:09 +03:00
const rr = await this . read ( p . subarray ( bytesRead ) ) ;
2021-02-26 12:21:42 +03:00
if ( rr === null ) {
if ( bytesRead === 0 ) {
return null ;
} else {
throw new PartialReadError ( ) ;
}
}
bytesRead += rr ;
} catch ( err ) {
2021-12-02 10:28:09 +03:00
err . partial = p . subarray ( 0 , bytesRead ) ;
2021-02-26 12:21:42 +03:00
throw err ;
}
}
2021-12-02 10:28:09 +03:00
return p ;
2021-02-26 12:21:42 +03:00
}
async readByte() {
while ( this . r === this . w ) {
if ( this . eof ) return null ;
await this . _fill ( ) ;
}
const c = this . buf [ this . r ] ;
this . r ++ ;
return c ;
}
async readString ( delim ) {
if ( delim . length !== 1 ) {
throw new Error ( "Delimiter should be a single character" ) ;
}
const buffer = await this . readSlice ( delim . charCodeAt ( 0 ) ) ;
if ( buffer === null ) return null ;
return new TextDecoder ( ) . decode ( buffer ) ;
}
async readLine() {
let line ;
try {
line = await this . readSlice ( LF ) ;
} catch ( err ) {
2021-09-01 16:11:55 +03:00
let { partial } = err ;
assert ( partial instanceof Uint8Array , "bufio: caught error from `readSlice()` without `partial` property" ) ;
2021-02-26 12:21:42 +03:00
if ( ! ( err instanceof BufferFullError ) ) {
throw err ;
}
2021-09-01 16:11:55 +03:00
if ( ! this . eof && partial . byteLength > 0 && partial [ partial . byteLength - 1 ] === CR ) {
2021-02-26 12:21:42 +03:00
assert ( this . r > 0 , "bufio: tried to rewind past start of buffer" ) ;
this . r -- ;
2021-09-01 16:11:55 +03:00
partial = partial . subarray ( 0 , partial . byteLength - 1 ) ;
2021-02-26 12:21:42 +03:00
}
return {
2021-09-01 16:11:55 +03:00
line : partial ,
2021-02-26 12:21:42 +03:00
more : ! this . eof
} ;
}
if ( line === null ) {
return null ;
}
if ( line . byteLength === 0 ) {
return {
line ,
more : false
} ;
}
if ( line [ line . byteLength - 1 ] == LF ) {
let drop = 1 ;
if ( line . byteLength > 1 && line [ line . byteLength - 2 ] === CR ) {
drop = 2 ;
}
line = line . subarray ( 0 , line . byteLength - drop ) ;
}
return {
line ,
more : false
} ;
}
2021-12-02 10:28:09 +03:00
async readSlice ( delim ) {
2021-02-26 12:21:42 +03:00
let s = 0 ;
let slice ;
while ( true ) {
2021-12-03 19:55:27 +03:00
let i21 = this . buf . subarray ( this . r + s , this . w ) . indexOf ( delim ) ;
if ( i21 >= 0 ) {
i21 += s ;
slice = this . buf . subarray ( this . r , this . r + i21 + 1 ) ;
this . r += i21 + 1 ;
2021-02-26 12:21:42 +03:00
break ;
}
if ( this . eof ) {
if ( this . r === this . w ) {
return null ;
}
slice = this . buf . subarray ( this . r , this . w ) ;
this . r = this . w ;
break ;
}
if ( this . buffered ( ) >= this . buf . byteLength ) {
this . r = this . w ;
const oldbuf = this . buf ;
const newbuf = this . buf . slice ( 0 ) ;
this . buf = newbuf ;
throw new BufferFullError ( oldbuf ) ;
}
s = this . w - this . r ;
try {
await this . _fill ( ) ;
} catch ( err ) {
err . partial = slice ;
throw err ;
}
}
return slice ;
}
2021-12-02 10:28:09 +03:00
async peek ( n ) {
if ( n < 0 ) {
2021-02-26 12:21:42 +03:00
throw Error ( "negative count" ) ;
}
let avail = this . w - this . r ;
2021-12-02 10:28:09 +03:00
while ( avail < n && avail < this . buf . byteLength && ! this . eof ) {
2021-02-26 12:21:42 +03:00
try {
await this . _fill ( ) ;
} catch ( err ) {
err . partial = this . buf . subarray ( this . r , this . w ) ;
throw err ;
}
avail = this . w - this . r ;
}
if ( avail === 0 && this . eof ) {
return null ;
2021-12-02 10:28:09 +03:00
} else if ( avail < n && this . eof ) {
2021-02-26 12:21:42 +03:00
return this . buf . subarray ( this . r , this . r + avail ) ;
2021-12-02 10:28:09 +03:00
} else if ( avail < n ) {
2021-02-26 12:21:42 +03:00
throw new BufferFullError ( this . buf . subarray ( this . r , this . w ) ) ;
}
2021-12-02 10:28:09 +03:00
return this . buf . subarray ( this . r , this . r + n ) ;
2021-02-26 12:21:42 +03:00
}
}
class AbstractBufBase {
size() {
return this . buf . byteLength ;
}
available() {
return this . buf . byteLength - this . usedBufferBytes ;
}
buffered() {
return this . usedBufferBytes ;
}
2021-03-21 16:31:35 +03:00
constructor ( ) {
this . usedBufferBytes = 0 ;
this . err = null ;
}
2021-02-26 12:21:42 +03:00
}
class BufWriter extends AbstractBufBase {
2021-12-02 10:28:09 +03:00
static create ( writer , size = DEFAULT_BUF_SIZE ) {
return writer instanceof BufWriter ? writer : new BufWriter ( writer , size ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
constructor ( writer , size = DEFAULT_BUF_SIZE ) {
2021-02-26 12:21:42 +03:00
super ( ) ;
2021-12-02 10:28:09 +03:00
this . writer = writer ;
if ( size <= 0 ) {
size = DEFAULT_BUF_SIZE ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
this . buf = new Uint8Array ( size ) ;
2021-02-26 12:21:42 +03:00
}
reset ( w ) {
this . err = null ;
this . usedBufferBytes = 0 ;
this . writer = w ;
}
async flush() {
if ( this . err !== null ) throw this . err ;
if ( this . usedBufferBytes === 0 ) return ;
try {
await Deno . writeAll ( this . writer , this . buf . subarray ( 0 , this . usedBufferBytes ) ) ;
} catch ( e ) {
this . err = e ;
throw e ;
}
this . buf = new Uint8Array ( this . buf . length ) ;
this . usedBufferBytes = 0 ;
}
2021-12-02 10:28:09 +03:00
async write ( data ) {
2021-02-26 12:21:42 +03:00
if ( this . err !== null ) throw this . err ;
2021-12-02 10:28:09 +03:00
if ( data . length === 0 ) return 0 ;
2021-02-26 12:21:42 +03:00
let totalBytesWritten = 0 ;
let numBytesWritten = 0 ;
2021-12-02 10:28:09 +03:00
while ( data . byteLength > this . available ( ) ) {
2021-02-26 12:21:42 +03:00
if ( this . buffered ( ) === 0 ) {
try {
2021-12-02 10:28:09 +03:00
numBytesWritten = await this . writer . write ( data ) ;
2021-02-26 12:21:42 +03:00
} catch ( e ) {
this . err = e ;
throw e ;
}
} else {
2021-12-02 10:28:09 +03:00
numBytesWritten = copyBytes ( data , this . buf , this . usedBufferBytes ) ;
2021-02-26 12:21:42 +03:00
this . usedBufferBytes += numBytesWritten ;
await this . flush ( ) ;
}
totalBytesWritten += numBytesWritten ;
2021-12-02 10:28:09 +03:00
data = data . subarray ( numBytesWritten ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
numBytesWritten = copyBytes ( data , this . buf , this . usedBufferBytes ) ;
2021-02-26 12:21:42 +03:00
this . usedBufferBytes += numBytesWritten ;
totalBytesWritten += numBytesWritten ;
return totalBytesWritten ;
}
}
class BufWriterSync extends AbstractBufBase {
2021-12-02 10:28:09 +03:00
static create ( writer , size = DEFAULT_BUF_SIZE ) {
return writer instanceof BufWriterSync ? writer : new BufWriterSync ( writer , size ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
constructor ( writer , size = DEFAULT_BUF_SIZE ) {
2021-02-26 12:21:42 +03:00
super ( ) ;
2021-12-02 10:28:09 +03:00
this . writer = writer ;
if ( size <= 0 ) {
size = DEFAULT_BUF_SIZE ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
this . buf = new Uint8Array ( size ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
reset ( w ) {
2021-02-26 12:21:42 +03:00
this . err = null ;
this . usedBufferBytes = 0 ;
2021-12-02 10:28:09 +03:00
this . writer = w ;
2021-02-26 12:21:42 +03:00
}
flush() {
if ( this . err !== null ) throw this . err ;
if ( this . usedBufferBytes === 0 ) return ;
try {
Deno . writeAllSync ( this . writer , this . buf . subarray ( 0 , this . usedBufferBytes ) ) ;
} catch ( e ) {
this . err = e ;
throw e ;
}
this . buf = new Uint8Array ( this . buf . length ) ;
this . usedBufferBytes = 0 ;
}
2021-12-02 10:28:09 +03:00
writeSync ( data ) {
2021-02-26 12:21:42 +03:00
if ( this . err !== null ) throw this . err ;
2021-12-02 10:28:09 +03:00
if ( data . length === 0 ) return 0 ;
2021-02-26 12:21:42 +03:00
let totalBytesWritten = 0 ;
let numBytesWritten = 0 ;
2021-12-02 10:28:09 +03:00
while ( data . byteLength > this . available ( ) ) {
2021-02-26 12:21:42 +03:00
if ( this . buffered ( ) === 0 ) {
try {
2021-12-02 10:28:09 +03:00
numBytesWritten = this . writer . writeSync ( data ) ;
2021-02-26 12:21:42 +03:00
} catch ( e ) {
this . err = e ;
throw e ;
}
} else {
2021-12-02 10:28:09 +03:00
numBytesWritten = copyBytes ( data , this . buf , this . usedBufferBytes ) ;
2021-02-26 12:21:42 +03:00
this . usedBufferBytes += numBytesWritten ;
this . flush ( ) ;
}
totalBytesWritten += numBytesWritten ;
2021-12-02 10:28:09 +03:00
data = data . subarray ( numBytesWritten ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
numBytesWritten = copyBytes ( data , this . buf , this . usedBufferBytes ) ;
2021-02-26 12:21:42 +03:00
this . usedBufferBytes += numBytesWritten ;
totalBytesWritten += numBytesWritten ;
return totalBytesWritten ;
}
}
const DEFAULT_FORMATTER = "{levelName} {msg}" ;
class BaseHandler {
2021-12-02 10:28:09 +03:00
constructor ( levelName , options = {
2021-02-26 12:21:42 +03:00
} ) {
2021-12-02 10:28:09 +03:00
this . level = getLevelByName ( levelName ) ;
this . levelName = levelName ;
this . formatter = options . formatter || DEFAULT_FORMATTER ;
2021-02-26 12:21:42 +03:00
}
handle ( logRecord ) {
if ( this . level > logRecord . level ) return ;
const msg = this . format ( logRecord ) ;
return this . log ( msg ) ;
}
2021-12-02 10:28:09 +03:00
format ( logRecord ) {
2021-02-26 12:21:42 +03:00
if ( this . formatter instanceof Function ) {
2021-12-02 10:28:09 +03:00
return this . formatter ( logRecord ) ;
2021-02-26 12:21:42 +03:00
}
return this . formatter . replace ( /{(\S+)}/g , ( match , p1 ) = > {
2021-12-02 10:28:09 +03:00
const value = logRecord [ p1 ] ;
2021-02-26 12:21:42 +03:00
if ( value == null ) {
return match ;
}
return String ( value ) ;
} ) ;
}
log ( _msg ) {
}
async setup() {
}
async destroy() {
}
}
class ConsoleHandler extends BaseHandler {
2021-12-02 10:28:09 +03:00
format ( logRecord ) {
let msg = super . format ( logRecord ) ;
switch ( logRecord . level ) {
2021-12-03 19:55:27 +03:00
case LogLevels . INFO :
2021-02-26 12:21:42 +03:00
msg = blue ( msg ) ;
break ;
2021-12-03 19:55:27 +03:00
case LogLevels . WARNING :
2021-02-26 12:21:42 +03:00
msg = yellow ( msg ) ;
break ;
2021-12-03 19:55:27 +03:00
case LogLevels . ERROR :
2021-02-26 12:21:42 +03:00
msg = red ( msg ) ;
break ;
2021-12-03 19:55:27 +03:00
case LogLevels . CRITICAL :
2021-02-26 12:21:42 +03:00
msg = bold ( red ( msg ) ) ;
break ;
2021-10-08 10:47:01 +03:00
default :
break ;
2021-02-26 12:21:42 +03:00
}
return msg ;
}
2021-12-02 10:28:09 +03:00
log ( msg ) {
console . log ( msg ) ;
2021-02-26 12:21:42 +03:00
}
}
class WriterHandler extends BaseHandler {
2021-03-30 06:09:11 +03:00
# encoder = new TextEncoder ( ) ;
2021-02-26 12:21:42 +03:00
}
class FileHandler extends WriterHandler {
2021-03-30 06:09:11 +03:00
# unloadCallback = ( ) = > this . destroy ( )
2021-02-26 12:21:42 +03:00
;
2021-12-02 10:28:09 +03:00
constructor ( levelName , options ) {
super ( levelName , options ) ;
2021-03-21 16:31:35 +03:00
this . _encoder = new TextEncoder ( ) ;
2021-12-02 10:28:09 +03:00
this . _filename = options . filename ;
this . _mode = options . mode ? options . mode : "a" ;
2021-02-26 12:21:42 +03:00
this . _openOptions = {
createNew : this._mode === "x" ,
create : this._mode !== "x" ,
append : this._mode === "a" ,
truncate : this._mode !== "a" ,
write : true
} ;
}
async setup() {
this . _file = await Deno . open ( this . _filename , this . _openOptions ) ;
this . _writer = this . _file ;
this . _buf = new BufWriterSync ( this . _file ) ;
addEventListener ( "unload" , this . # unloadCallback ) ;
}
2021-12-02 10:28:09 +03:00
handle ( logRecord ) {
super . handle ( logRecord ) ;
2021-12-03 19:55:27 +03:00
if ( logRecord . level > LogLevels . ERROR ) {
2021-02-26 12:21:42 +03:00
this . flush ( ) ;
}
}
2021-12-02 10:28:09 +03:00
log ( msg ) {
this . _buf . writeSync ( this . _encoder . encode ( msg + "\n" ) ) ;
2021-02-26 12:21:42 +03:00
}
flush() {
if ( this . _buf ? . buffered ( ) > 0 ) {
this . _buf . flush ( ) ;
}
}
destroy() {
this . flush ( ) ;
this . _file ? . close ( ) ;
this . _file = undefined ;
removeEventListener ( "unload" , this . # unloadCallback ) ;
return Promise . resolve ( ) ;
}
}
class RotatingFileHandler extends FileHandler {
# maxBytes ;
# maxBackupCount ;
2021-03-30 06:09:11 +03:00
# currentFileSize = 0 ;
2021-12-02 10:28:09 +03:00
constructor ( levelName , options ) {
super ( levelName , options ) ;
this . # maxBytes = options . maxBytes ;
this . # maxBackupCount = options . maxBackupCount ;
2021-02-26 12:21:42 +03:00
}
async setup() {
if ( this . # maxBytes < 1 ) {
this . destroy ( ) ;
throw new Error ( "maxBytes cannot be less than 1" ) ;
}
if ( this . # maxBackupCount < 1 ) {
this . destroy ( ) ;
throw new Error ( "maxBackupCount cannot be less than 1" ) ;
}
await super . setup ( ) ;
if ( this . _mode === "w" ) {
2021-12-03 19:55:27 +03:00
for ( let i22 = 1 ; i22 <= this . # maxBackupCount ; i22 ++ ) {
if ( await exists ( this . _filename + "." + i22 ) ) {
await Deno . remove ( this . _filename + "." + i22 ) ;
2021-02-26 12:21:42 +03:00
}
}
} else if ( this . _mode === "x" ) {
2021-12-03 19:55:27 +03:00
for ( let i23 = 1 ; i23 <= this . # maxBackupCount ; i23 ++ ) {
if ( await exists ( this . _filename + "." + i23 ) ) {
2021-02-26 12:21:42 +03:00
this . destroy ( ) ;
2021-12-03 19:55:27 +03:00
throw new Deno . errors . AlreadyExists ( "Backup log file " + this . _filename + "." + i23 + " already exists" ) ;
2021-02-26 12:21:42 +03:00
}
}
} else {
this . # currentFileSize = ( await Deno . stat ( this . _filename ) ) . size ;
}
}
2021-12-02 10:28:09 +03:00
log ( msg ) {
const msgByteLength = this . _encoder . encode ( msg ) . byteLength + 1 ;
2021-02-26 12:21:42 +03:00
if ( this . # currentFileSize + msgByteLength > this . # maxBytes ) {
this . rotateLogFiles ( ) ;
this . # currentFileSize = 0 ;
}
2021-12-02 10:28:09 +03:00
this . _buf . writeSync ( this . _encoder . encode ( msg + "\n" ) ) ;
2021-02-26 12:21:42 +03:00
this . # currentFileSize += msgByteLength ;
}
rotateLogFiles() {
this . _buf . flush ( ) ;
Deno . close ( this . _file . rid ) ;
2021-12-03 19:55:27 +03:00
for ( let i24 = this . # maxBackupCount - 1 ; i24 >= 0 ; i24 -- ) {
const source1 = this . _filename + ( i24 === 0 ? "" : "." + i24 ) ;
const dest = this . _filename + "." + ( i24 + 1 ) ;
if ( existsSync ( source1 ) ) {
Deno . renameSync ( source1 , dest ) ;
2021-02-26 12:21:42 +03:00
}
}
this . _file = Deno . openSync ( this . _filename , this . _openOptions ) ;
this . _writer = this . _file ;
this . _buf = new BufWriterSync ( this . _file ) ;
}
}
class LoggerConfig {
}
const DEFAULT_LEVEL = "INFO" ;
const DEFAULT_CONFIG = {
handlers : {
default : new ConsoleHandler ( DEFAULT_LEVEL )
} ,
loggers : {
default : {
level : DEFAULT_LEVEL ,
handlers : [
"default"
]
}
}
} ;
const state = {
handlers : new Map ( ) ,
loggers : new Map ( ) ,
config : DEFAULT_CONFIG
} ;
2021-12-03 19:55:27 +03:00
const handlers = {
2021-02-26 12:21:42 +03:00
BaseHandler ,
ConsoleHandler ,
WriterHandler ,
FileHandler ,
RotatingFileHandler
} ;
function getLogger ( name ) {
if ( ! name ) {
const d = state . loggers . get ( "default" ) ;
assert ( d != null , ` "default" logger must be set for getting logger without name ` ) ;
return d ;
}
const result = state . loggers . get ( name ) ;
if ( ! result ) {
const logger = new Logger ( name , "NOTSET" , {
handlers : [ ]
} ) ;
state . loggers . set ( name , logger ) ;
return logger ;
}
return result ;
}
function debug ( msg , . . . args ) {
if ( msg instanceof Function ) {
return getLogger ( "default" ) . debug ( msg , . . . args ) ;
}
return getLogger ( "default" ) . debug ( msg , . . . args ) ;
}
2021-12-03 19:55:27 +03:00
function info ( msg , . . . args ) {
2021-02-26 12:21:42 +03:00
if ( msg instanceof Function ) {
return getLogger ( "default" ) . info ( msg , . . . args ) ;
}
return getLogger ( "default" ) . info ( msg , . . . args ) ;
}
function warning ( msg , . . . args ) {
if ( msg instanceof Function ) {
return getLogger ( "default" ) . warning ( msg , . . . args ) ;
}
return getLogger ( "default" ) . warning ( msg , . . . args ) ;
}
2021-12-03 19:55:27 +03:00
function error ( msg , . . . args ) {
2021-02-26 12:21:42 +03:00
if ( msg instanceof Function ) {
return getLogger ( "default" ) . error ( msg , . . . args ) ;
}
return getLogger ( "default" ) . error ( msg , . . . args ) ;
}
function critical ( msg , . . . args ) {
if ( msg instanceof Function ) {
return getLogger ( "default" ) . critical ( msg , . . . args ) ;
}
return getLogger ( "default" ) . critical ( msg , . . . args ) ;
}
async function setup ( config ) {
state . config = {
handlers : {
. . . DEFAULT_CONFIG . handlers ,
. . . config . handlers
} ,
loggers : {
. . . DEFAULT_CONFIG . loggers ,
. . . config . loggers
}
} ;
state . handlers . forEach ( ( handler ) = > {
handler . destroy ( ) ;
} ) ;
state . handlers . clear ( ) ;
2021-12-03 19:55:27 +03:00
const handlers1 = state . config . handlers || {
2021-02-26 12:21:42 +03:00
} ;
2021-12-03 19:55:27 +03:00
for ( const handlerName1 in handlers1 ) {
const handler = handlers1 [ handlerName1 ] ;
2021-02-26 12:21:42 +03:00
await handler . setup ( ) ;
2021-10-21 08:12:50 +03:00
state . handlers . set ( handlerName1 , handler ) ;
2021-02-26 12:21:42 +03:00
}
state . loggers . clear ( ) ;
const loggers = state . config . loggers || {
} ;
2021-09-01 16:11:55 +03:00
for ( const loggerName in loggers ) {
const loggerConfig = loggers [ loggerName ] ;
2021-02-26 12:21:42 +03:00
const handlerNames = loggerConfig . handlers || [ ] ;
2021-12-03 19:55:27 +03:00
const handlers2 = [ ] ;
2021-09-01 16:11:55 +03:00
handlerNames . forEach ( ( handlerName ) = > {
const handler = state . handlers . get ( handlerName ) ;
2021-02-26 12:21:42 +03:00
if ( handler ) {
2021-12-03 19:55:27 +03:00
handlers2 . push ( handler ) ;
2021-02-26 12:21:42 +03:00
}
} ) ;
2021-09-01 16:11:55 +03:00
const levelName = loggerConfig . level || DEFAULT_LEVEL ;
const logger = new Logger ( loggerName , levelName , {
2021-12-03 19:55:27 +03:00
handlers : handlers2
2021-02-26 12:21:42 +03:00
} ) ;
2021-09-01 16:11:55 +03:00
state . loggers . set ( loggerName , logger ) ;
2021-02-26 12:21:42 +03:00
}
}
await setup ( DEFAULT_CONFIG ) ;
const mod4 = await async function ( ) {
return {
2021-12-03 19:55:27 +03:00
LogLevels : LogLevels ,
2021-02-26 12:21:42 +03:00
Logger : Logger ,
LoggerConfig : LoggerConfig ,
2021-12-03 19:55:27 +03:00
handlers : handlers ,
2021-02-26 12:21:42 +03:00
getLogger : getLogger ,
debug : debug ,
2021-12-03 19:55:27 +03:00
info : info ,
2021-02-26 12:21:42 +03:00
warning : warning ,
2021-12-03 19:55:27 +03:00
error : error ,
2021-02-26 12:21:42 +03:00
critical : critical ,
setup : setup
} ;
} ( ) ;
async function emptyDir ( dir ) {
try {
const items = [ ] ;
for await ( const dirEntry of Deno . readDir ( dir ) ) {
items . push ( dirEntry ) ;
}
while ( items . length ) {
const item = items . shift ( ) ;
if ( item && item . name ) {
const filepath = join2 ( dir , item . name ) ;
await Deno . remove ( filepath , {
recursive : true
} ) ;
}
}
} catch ( err ) {
if ( ! ( err instanceof Deno . errors . NotFound ) ) {
throw err ;
}
await Deno . mkdir ( dir , {
recursive : true
} ) ;
}
}
function emptyDirSync ( dir ) {
try {
const items = [
. . . Deno . readDirSync ( dir )
] ;
while ( items . length ) {
const item = items . shift ( ) ;
if ( item && item . name ) {
const filepath = join2 ( dir , item . name ) ;
Deno . removeSync ( filepath , {
recursive : true
} ) ;
}
}
} catch ( err ) {
if ( ! ( err instanceof Deno . errors . NotFound ) ) {
throw err ;
}
Deno . mkdirSync ( dir , {
recursive : true
} ) ;
return ;
}
}
2021-12-03 19:55:27 +03:00
function isSubdir ( src2 , dest , sep6 = sep2 ) {
if ( src2 === dest ) {
2021-02-26 12:21:42 +03:00
return false ;
}
2021-12-03 19:55:27 +03:00
const srcArray = src2 . split ( sep6 ) ;
const destArray = dest . split ( sep6 ) ;
2021-02-26 12:21:42 +03:00
return srcArray . every ( ( current , i ) = > destArray [ i ] === current
) ;
}
function getFileInfoType ( fileInfo ) {
return fileInfo . isFile ? "file" : fileInfo . isDirectory ? "dir" : fileInfo . isSymlink ? "symlink" : undefined ;
}
async function ensureDir ( dir ) {
try {
const fileInfo = await Deno . lstat ( dir ) ;
if ( ! fileInfo . isDirectory ) {
throw new Error ( ` Ensure path exists, expected 'dir', got ' ${ getFileInfoType ( fileInfo ) } ' ` ) ;
}
} catch ( err ) {
if ( err instanceof Deno . errors . NotFound ) {
await Deno . mkdir ( dir , {
recursive : true
} ) ;
return ;
}
throw err ;
}
}
function ensureDirSync ( dir ) {
try {
const fileInfo = Deno . lstatSync ( dir ) ;
if ( ! fileInfo . isDirectory ) {
throw new Error ( ` Ensure path exists, expected 'dir', got ' ${ getFileInfoType ( fileInfo ) } ' ` ) ;
}
} catch ( err ) {
if ( err instanceof Deno . errors . NotFound ) {
Deno . mkdirSync ( dir , {
recursive : true
} ) ;
return ;
}
throw err ;
}
}
async function ensureFile ( filePath ) {
try {
const stat = await Deno . lstat ( filePath ) ;
if ( ! stat . isFile ) {
throw new Error ( ` Ensure path exists, expected 'file', got ' ${ getFileInfoType ( stat ) } ' ` ) ;
}
} catch ( err ) {
if ( err instanceof Deno . errors . NotFound ) {
await ensureDir ( dirname2 ( filePath ) ) ;
await Deno . writeFile ( filePath , new Uint8Array ( ) ) ;
return ;
}
throw err ;
}
}
function ensureFileSync ( filePath ) {
try {
const stat = Deno . lstatSync ( filePath ) ;
if ( ! stat . isFile ) {
throw new Error ( ` Ensure path exists, expected 'file', got ' ${ getFileInfoType ( stat ) } ' ` ) ;
}
} catch ( err ) {
if ( err instanceof Deno . errors . NotFound ) {
ensureDirSync ( dirname2 ( filePath ) ) ;
Deno . writeFileSync ( filePath , new Uint8Array ( ) ) ;
return ;
}
throw err ;
}
}
2021-12-03 19:55:27 +03:00
async function ensureLink ( src3 , dest ) {
2021-02-26 12:21:42 +03:00
if ( await exists ( dest ) ) {
const destStatInfo = await Deno . lstat ( dest ) ;
const destFilePathType = getFileInfoType ( destStatInfo ) ;
if ( destFilePathType !== "file" ) {
throw new Error ( ` Ensure path exists, expected 'file', got ' ${ destFilePathType } ' ` ) ;
}
return ;
}
await ensureDir ( dirname2 ( dest ) ) ;
2021-12-03 19:55:27 +03:00
await Deno . link ( src3 , dest ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
function ensureLinkSync ( src4 , dest ) {
2021-02-26 12:21:42 +03:00
if ( existsSync ( dest ) ) {
const destStatInfo = Deno . lstatSync ( dest ) ;
const destFilePathType = getFileInfoType ( destStatInfo ) ;
if ( destFilePathType !== "file" ) {
throw new Error ( ` Ensure path exists, expected 'file', got ' ${ destFilePathType } ' ` ) ;
}
return ;
}
ensureDirSync ( dirname2 ( dest ) ) ;
2021-12-03 19:55:27 +03:00
Deno . linkSync ( src4 , dest ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
async function ensureSymlink ( src5 , dest ) {
const srcStatInfo = await Deno . lstat ( src5 ) ;
2021-02-26 12:21:42 +03:00
const srcFilePathType = getFileInfoType ( srcStatInfo ) ;
if ( await exists ( dest ) ) {
const destStatInfo = await Deno . lstat ( dest ) ;
const destFilePathType = getFileInfoType ( destStatInfo ) ;
if ( destFilePathType !== "symlink" ) {
throw new Error ( ` Ensure path exists, expected 'symlink', got ' ${ destFilePathType } ' ` ) ;
}
return ;
}
await ensureDir ( dirname2 ( dest ) ) ;
if ( Deno . build . os === "windows" ) {
2021-12-03 19:55:27 +03:00
await Deno . symlink ( src5 , dest , {
2021-02-26 12:21:42 +03:00
type : srcFilePathType === "dir" ? "dir" : "file"
} ) ;
} else {
2021-12-03 19:55:27 +03:00
await Deno . symlink ( src5 , dest ) ;
2021-02-26 12:21:42 +03:00
}
}
2021-12-03 19:55:27 +03:00
function ensureSymlinkSync ( src6 , dest ) {
const srcStatInfo = Deno . lstatSync ( src6 ) ;
2021-02-26 12:21:42 +03:00
const srcFilePathType = getFileInfoType ( srcStatInfo ) ;
if ( existsSync ( dest ) ) {
const destStatInfo = Deno . lstatSync ( dest ) ;
const destFilePathType = getFileInfoType ( destStatInfo ) ;
if ( destFilePathType !== "symlink" ) {
throw new Error ( ` Ensure path exists, expected 'symlink', got ' ${ destFilePathType } ' ` ) ;
}
return ;
}
ensureDirSync ( dirname2 ( dest ) ) ;
if ( Deno . build . os === "windows" ) {
2021-12-03 19:55:27 +03:00
Deno . symlinkSync ( src6 , dest , {
2021-02-26 12:21:42 +03:00
type : srcFilePathType === "dir" ? "dir" : "file"
} ) ;
} else {
2021-12-03 19:55:27 +03:00
Deno . symlinkSync ( src6 , dest ) ;
2021-02-26 12:21:42 +03:00
}
}
2021-12-03 19:55:27 +03:00
function _createWalkEntrySync ( path26 ) {
path26 = normalize2 ( path26 ) ;
const name = basename2 ( path26 ) ;
const info1 = Deno . statSync ( path26 ) ;
2021-02-26 12:21:42 +03:00
return {
2021-12-03 19:55:27 +03:00
path : path26 ,
2021-02-26 12:21:42 +03:00
name ,
2021-12-03 19:55:27 +03:00
isFile : info1.isFile ,
isDirectory : info1.isDirectory ,
isSymlink : info1.isSymlink
2021-02-26 12:21:42 +03:00
} ;
}
2021-12-03 19:55:27 +03:00
async function _createWalkEntry ( path27 ) {
path27 = normalize2 ( path27 ) ;
const name = basename2 ( path27 ) ;
const info2 = await Deno . stat ( path27 ) ;
2021-02-26 12:21:42 +03:00
return {
2021-12-03 19:55:27 +03:00
path : path27 ,
2021-02-26 12:21:42 +03:00
name ,
2021-12-03 19:55:27 +03:00
isFile : info2.isFile ,
isDirectory : info2.isDirectory ,
isSymlink : info2.isSymlink
2021-02-26 12:21:42 +03:00
} ;
}
2021-12-03 19:55:27 +03:00
function include ( path28 , exts , match , skip ) {
if ( exts && ! exts . some ( ( ext ) = > path28 . endsWith ( ext )
2021-02-26 12:21:42 +03:00
) ) {
return false ;
}
2021-12-03 19:55:27 +03:00
if ( match && ! match . some ( ( pattern ) = > ! ! path28 . match ( pattern )
2021-02-26 12:21:42 +03:00
) ) {
return false ;
}
2021-12-03 19:55:27 +03:00
if ( skip && skip . some ( ( pattern ) = > ! ! path28 . match ( pattern )
2021-02-26 12:21:42 +03:00
) ) {
return false ;
}
return true ;
}
async function * walk ( root , { maxDepth = Infinity , includeFiles = true , includeDirs = true , followSymlinks = false , exts = undefined , match = undefined , skip = undefined } = {
} ) {
if ( maxDepth < 0 ) {
return ;
}
if ( includeDirs && include ( root , exts , match , skip ) ) {
yield await _createWalkEntry ( root ) ;
}
if ( maxDepth < 1 || ! include ( root , undefined , undefined , skip ) ) {
return ;
}
for await ( const entry of Deno . readDir ( root ) ) {
if ( entry . isSymlink ) {
if ( followSymlinks ) {
throw new Error ( "unimplemented" ) ;
} else {
continue ;
}
}
assert ( entry . name != null ) ;
2021-12-03 19:55:27 +03:00
const path29 = join2 ( root , entry . name ) ;
2021-02-26 12:21:42 +03:00
if ( entry . isFile ) {
2021-12-03 19:55:27 +03:00
if ( includeFiles && include ( path29 , exts , match , skip ) ) {
2021-02-26 12:21:42 +03:00
yield {
2021-12-03 19:55:27 +03:00
path : path29 ,
2021-02-26 12:21:42 +03:00
. . . entry
} ;
}
} else {
2021-12-03 19:55:27 +03:00
yield * walk ( path29 , {
2021-02-26 12:21:42 +03:00
maxDepth : maxDepth - 1 ,
includeFiles ,
includeDirs ,
followSymlinks ,
exts ,
match ,
skip
} ) ;
}
}
}
function * walkSync ( root , { maxDepth = Infinity , includeFiles = true , includeDirs = true , followSymlinks = false , exts = undefined , match = undefined , skip = undefined } = {
} ) {
if ( maxDepth < 0 ) {
return ;
}
if ( includeDirs && include ( root , exts , match , skip ) ) {
yield _createWalkEntrySync ( root ) ;
}
if ( maxDepth < 1 || ! include ( root , undefined , undefined , skip ) ) {
return ;
}
for ( const entry of Deno . readDirSync ( root ) ) {
if ( entry . isSymlink ) {
if ( followSymlinks ) {
throw new Error ( "unimplemented" ) ;
} else {
continue ;
}
}
assert ( entry . name != null ) ;
2021-12-03 19:55:27 +03:00
const path30 = join2 ( root , entry . name ) ;
2021-02-26 12:21:42 +03:00
if ( entry . isFile ) {
2021-12-03 19:55:27 +03:00
if ( includeFiles && include ( path30 , exts , match , skip ) ) {
2021-02-26 12:21:42 +03:00
yield {
2021-12-03 19:55:27 +03:00
path : path30 ,
2021-02-26 12:21:42 +03:00
. . . entry
} ;
}
} else {
2021-12-03 19:55:27 +03:00
yield * walkSync ( path30 , {
2021-02-26 12:21:42 +03:00
maxDepth : maxDepth - 1 ,
includeFiles ,
includeDirs ,
followSymlinks ,
exts ,
match ,
skip
} ) ;
}
}
}
const isWindows1 = Deno . build . os == "windows" ;
2021-12-03 19:55:27 +03:00
function split ( path31 ) {
2021-02-26 12:21:42 +03:00
const s = SEP_PATTERN . source ;
2021-12-03 19:55:27 +03:00
const segments = path31 . replace ( new RegExp ( ` ^ ${ s } | ${ s } $ ` , "g" ) , "" ) . split ( SEP_PATTERN ) ;
const isAbsolute_ = isAbsolute2 ( path31 ) ;
2021-02-26 12:21:42 +03:00
return {
segments ,
isAbsolute : isAbsolute_ ,
2021-12-03 19:55:27 +03:00
hasTrailingSep : ! ! path31 . match ( new RegExp ( ` ${ s } $ ` ) ) ,
2021-02-26 12:21:42 +03:00
winRoot : isWindows1 && isAbsolute_ ? segments . shift ( ) : undefined
} ;
}
2021-12-03 19:55:27 +03:00
function throwUnlessNotFound ( error1 ) {
if ( ! ( error1 instanceof Deno . errors . NotFound ) ) {
throw error1 ;
2021-02-26 12:21:42 +03:00
}
}
function comparePath ( a , b ) {
if ( a . path < b . path ) return - 1 ;
if ( a . path > b . path ) return 1 ;
return 0 ;
}
async function * expandGlob ( glob , { root = Deno . cwd ( ) , exclude = [ ] , includeDirs = true , extended = false , globstar = false } = {
} ) {
const globOptions = {
extended ,
globstar
} ;
const absRoot = isAbsolute2 ( root ) ? normalize2 ( root ) : joinGlobs ( [
Deno . cwd ( ) ,
root
] , globOptions ) ;
2021-12-03 19:55:27 +03:00
const resolveFromRoot = ( path32 ) = > isAbsolute2 ( path32 ) ? normalize2 ( path32 ) : joinGlobs ( [
2021-02-26 12:21:42 +03:00
absRoot ,
2021-12-03 19:55:27 +03:00
path32
2021-02-26 12:21:42 +03:00
] , globOptions )
;
const excludePatterns = exclude . map ( resolveFromRoot ) . map ( ( s ) = > globToRegExp ( s , globOptions )
) ;
2021-12-03 19:55:27 +03:00
const shouldInclude = ( path33 ) = > ! excludePatterns . some ( ( p ) = > ! ! path33 . match ( p )
2021-02-26 12:21:42 +03:00
)
;
const { segments , hasTrailingSep , winRoot } = split ( resolveFromRoot ( glob ) ) ;
let fixedRoot = winRoot != undefined ? winRoot : "/" ;
while ( segments . length > 0 && ! isGlob ( segments [ 0 ] ) ) {
const seg = segments . shift ( ) ;
assert ( seg != null ) ;
fixedRoot = joinGlobs ( [
fixedRoot ,
seg
] , globOptions ) ;
}
let fixedRootInfo ;
try {
fixedRootInfo = await _createWalkEntry ( fixedRoot ) ;
2021-10-21 08:12:50 +03:00
} catch ( error2 ) {
return throwUnlessNotFound ( error2 ) ;
2021-02-26 12:21:42 +03:00
}
async function * advanceMatch ( walkInfo , globSegment ) {
if ( ! walkInfo . isDirectory ) {
return ;
} else if ( globSegment == ".." ) {
const parentPath = joinGlobs ( [
walkInfo . path ,
".."
] , globOptions ) ;
try {
if ( shouldInclude ( parentPath ) ) {
return yield await _createWalkEntry ( parentPath ) ;
}
2021-12-03 19:55:27 +03:00
} catch ( error3 ) {
throwUnlessNotFound ( error3 ) ;
2021-02-26 12:21:42 +03:00
}
return ;
} else if ( globSegment == "**" ) {
return yield * walk ( walkInfo . path , {
includeFiles : false ,
skip : excludePatterns
} ) ;
}
yield * walk ( walkInfo . path , {
maxDepth : 1 ,
match : [
globToRegExp ( joinGlobs ( [
walkInfo . path ,
globSegment
] , globOptions ) , globOptions ) ,
] ,
skip : excludePatterns
} ) ;
}
let currentMatches = [
fixedRootInfo
] ;
for ( const segment of segments ) {
const nextMatchMap = new Map ( ) ;
for ( const currentMatch of currentMatches ) {
for await ( const nextMatch of advanceMatch ( currentMatch , segment ) ) {
nextMatchMap . set ( nextMatch . path , nextMatch ) ;
}
}
currentMatches = [
. . . nextMatchMap . values ( )
] . sort ( comparePath ) ;
}
if ( hasTrailingSep ) {
currentMatches = currentMatches . filter ( ( entry ) = > entry . isDirectory
) ;
}
if ( ! includeDirs ) {
currentMatches = currentMatches . filter ( ( entry ) = > ! entry . isDirectory
) ;
}
yield * currentMatches ;
}
function * expandGlobSync ( glob , { root = Deno . cwd ( ) , exclude = [ ] , includeDirs = true , extended = false , globstar = false } = {
} ) {
const globOptions = {
extended ,
globstar
} ;
const absRoot = isAbsolute2 ( root ) ? normalize2 ( root ) : joinGlobs ( [
Deno . cwd ( ) ,
root
] , globOptions ) ;
2021-12-03 19:55:27 +03:00
const resolveFromRoot = ( path34 ) = > isAbsolute2 ( path34 ) ? normalize2 ( path34 ) : joinGlobs ( [
2021-02-26 12:21:42 +03:00
absRoot ,
2021-12-03 19:55:27 +03:00
path34
2021-02-26 12:21:42 +03:00
] , globOptions )
;
const excludePatterns = exclude . map ( resolveFromRoot ) . map ( ( s ) = > globToRegExp ( s , globOptions )
) ;
2021-12-03 19:55:27 +03:00
const shouldInclude = ( path35 ) = > ! excludePatterns . some ( ( p ) = > ! ! path35 . match ( p )
2021-02-26 12:21:42 +03:00
)
;
const { segments , hasTrailingSep , winRoot } = split ( resolveFromRoot ( glob ) ) ;
let fixedRoot = winRoot != undefined ? winRoot : "/" ;
while ( segments . length > 0 && ! isGlob ( segments [ 0 ] ) ) {
const seg = segments . shift ( ) ;
assert ( seg != null ) ;
fixedRoot = joinGlobs ( [
fixedRoot ,
seg
] , globOptions ) ;
}
let fixedRootInfo ;
try {
fixedRootInfo = _createWalkEntrySync ( fixedRoot ) ;
2021-12-03 19:55:27 +03:00
} catch ( error4 ) {
return throwUnlessNotFound ( error4 ) ;
2021-02-26 12:21:42 +03:00
}
function * advanceMatch ( walkInfo , globSegment ) {
if ( ! walkInfo . isDirectory ) {
return ;
} else if ( globSegment == ".." ) {
const parentPath = joinGlobs ( [
walkInfo . path ,
".."
] , globOptions ) ;
try {
if ( shouldInclude ( parentPath ) ) {
return yield _createWalkEntrySync ( parentPath ) ;
}
2021-12-03 19:55:27 +03:00
} catch ( error5 ) {
throwUnlessNotFound ( error5 ) ;
2021-02-26 12:21:42 +03:00
}
return ;
} else if ( globSegment == "**" ) {
return yield * walkSync ( walkInfo . path , {
includeFiles : false ,
skip : excludePatterns
} ) ;
}
yield * walkSync ( walkInfo . path , {
maxDepth : 1 ,
match : [
globToRegExp ( joinGlobs ( [
walkInfo . path ,
globSegment
] , globOptions ) , globOptions ) ,
] ,
skip : excludePatterns
} ) ;
}
let currentMatches = [
fixedRootInfo
] ;
for ( const segment of segments ) {
const nextMatchMap = new Map ( ) ;
for ( const currentMatch of currentMatches ) {
for ( const nextMatch of advanceMatch ( currentMatch , segment ) ) {
nextMatchMap . set ( nextMatch . path , nextMatch ) ;
}
}
currentMatches = [
. . . nextMatchMap . values ( )
] . sort ( comparePath ) ;
}
if ( hasTrailingSep ) {
currentMatches = currentMatches . filter ( ( entry ) = > entry . isDirectory
) ;
}
if ( ! includeDirs ) {
currentMatches = currentMatches . filter ( ( entry ) = > ! entry . isDirectory
) ;
}
yield * currentMatches ;
}
2021-12-03 19:55:27 +03:00
async function move ( src7 , dest , { overwrite = false } = {
2021-02-26 12:21:42 +03:00
} ) {
2021-12-03 19:55:27 +03:00
const srcStat = await Deno . stat ( src7 ) ;
if ( srcStat . isDirectory && isSubdir ( src7 , dest ) ) {
throw new Error ( ` Cannot move ' ${ src7 } ' to a subdirectory of itself, ' ${ dest } '. ` ) ;
2021-02-26 12:21:42 +03:00
}
if ( overwrite ) {
if ( await exists ( dest ) ) {
await Deno . remove ( dest , {
recursive : true
} ) ;
}
2021-12-03 19:55:27 +03:00
await Deno . rename ( src7 , dest ) ;
2021-02-26 12:21:42 +03:00
} else {
if ( await exists ( dest ) ) {
throw new Error ( "dest already exists." ) ;
}
2021-12-03 19:55:27 +03:00
await Deno . rename ( src7 , dest ) ;
2021-02-26 12:21:42 +03:00
}
return ;
}
2021-12-03 19:55:27 +03:00
function moveSync ( src8 , dest , { overwrite = false } = {
2021-02-26 12:21:42 +03:00
} ) {
2021-12-03 19:55:27 +03:00
const srcStat = Deno . statSync ( src8 ) ;
if ( srcStat . isDirectory && isSubdir ( src8 , dest ) ) {
throw new Error ( ` Cannot move ' ${ src8 } ' to a subdirectory of itself, ' ${ dest } '. ` ) ;
2021-02-26 12:21:42 +03:00
}
if ( overwrite ) {
if ( existsSync ( dest ) ) {
Deno . removeSync ( dest , {
recursive : true
} ) ;
}
2021-12-03 19:55:27 +03:00
Deno . renameSync ( src8 , dest ) ;
2021-02-26 12:21:42 +03:00
} else {
if ( existsSync ( dest ) ) {
throw new Error ( "dest already exists." ) ;
}
2021-12-03 19:55:27 +03:00
Deno . renameSync ( src8 , dest ) ;
2021-02-26 12:21:42 +03:00
}
}
const isWindows2 = Deno . build . os === "windows" ;
2021-12-03 19:55:27 +03:00
async function ensureValidCopy ( src9 , dest , options , isCopyFolder = false ) {
2021-02-26 12:21:42 +03:00
let destStat ;
try {
destStat = await Deno . lstat ( dest ) ;
} catch ( err ) {
if ( err instanceof Deno . errors . NotFound ) {
return ;
}
throw err ;
}
if ( isCopyFolder && ! destStat . isDirectory ) {
2021-12-03 19:55:27 +03:00
throw new Error ( ` Cannot overwrite non-directory ' ${ dest } ' with directory ' ${ src9 } '. ` ) ;
2021-02-26 12:21:42 +03:00
}
2021-09-01 16:11:55 +03:00
if ( ! options . overwrite ) {
2021-02-26 12:21:42 +03:00
throw new Error ( ` ' ${ dest } ' already exists. ` ) ;
}
return destStat ;
}
2021-12-03 19:55:27 +03:00
function ensureValidCopySync ( src10 , dest , options , isCopyFolder = false ) {
2021-02-26 12:21:42 +03:00
let destStat ;
try {
destStat = Deno . lstatSync ( dest ) ;
} catch ( err ) {
if ( err instanceof Deno . errors . NotFound ) {
return ;
}
throw err ;
}
if ( isCopyFolder && ! destStat . isDirectory ) {
2021-12-03 19:55:27 +03:00
throw new Error ( ` Cannot overwrite non-directory ' ${ dest } ' with directory ' ${ src10 } '. ` ) ;
2021-02-26 12:21:42 +03:00
}
2021-09-01 16:11:55 +03:00
if ( ! options . overwrite ) {
2021-02-26 12:21:42 +03:00
throw new Error ( ` ' ${ dest } ' already exists. ` ) ;
}
return destStat ;
}
2021-12-03 19:55:27 +03:00
async function copyFile ( src11 , dest , options ) {
await ensureValidCopy ( src11 , dest , options ) ;
await Deno . copyFile ( src11 , dest ) ;
2021-09-01 16:11:55 +03:00
if ( options . preserveTimestamps ) {
2021-12-03 19:55:27 +03:00
const statInfo = await Deno . stat ( src11 ) ;
2021-02-26 12:21:42 +03:00
assert ( statInfo . atime instanceof Date , ` statInfo.atime is unavailable ` ) ;
assert ( statInfo . mtime instanceof Date , ` statInfo.mtime is unavailable ` ) ;
await Deno . utime ( dest , statInfo . atime , statInfo . mtime ) ;
}
}
2021-12-03 19:55:27 +03:00
function copyFileSync ( src12 , dest , options ) {
ensureValidCopySync ( src12 , dest , options ) ;
Deno . copyFileSync ( src12 , dest ) ;
2021-09-01 16:11:55 +03:00
if ( options . preserveTimestamps ) {
2021-12-03 19:55:27 +03:00
const statInfo = Deno . statSync ( src12 ) ;
2021-02-26 12:21:42 +03:00
assert ( statInfo . atime instanceof Date , ` statInfo.atime is unavailable ` ) ;
assert ( statInfo . mtime instanceof Date , ` statInfo.mtime is unavailable ` ) ;
Deno . utimeSync ( dest , statInfo . atime , statInfo . mtime ) ;
}
}
2021-12-03 19:55:27 +03:00
async function copySymLink ( src13 , dest , options ) {
await ensureValidCopy ( src13 , dest , options ) ;
const originSrcFilePath = await Deno . readLink ( src13 ) ;
const type = getFileInfoType ( await Deno . lstat ( src13 ) ) ;
2021-02-26 12:21:42 +03:00
if ( isWindows2 ) {
await Deno . symlink ( originSrcFilePath , dest , {
type : type === "dir" ? "dir" : "file"
} ) ;
} else {
await Deno . symlink ( originSrcFilePath , dest ) ;
}
2021-09-01 16:11:55 +03:00
if ( options . preserveTimestamps ) {
2021-12-03 19:55:27 +03:00
const statInfo = await Deno . lstat ( src13 ) ;
2021-02-26 12:21:42 +03:00
assert ( statInfo . atime instanceof Date , ` statInfo.atime is unavailable ` ) ;
assert ( statInfo . mtime instanceof Date , ` statInfo.mtime is unavailable ` ) ;
await Deno . utime ( dest , statInfo . atime , statInfo . mtime ) ;
}
}
2021-12-03 19:55:27 +03:00
function copySymlinkSync ( src14 , dest , options ) {
ensureValidCopySync ( src14 , dest , options ) ;
const originSrcFilePath = Deno . readLinkSync ( src14 ) ;
const type = getFileInfoType ( Deno . lstatSync ( src14 ) ) ;
2021-02-26 12:21:42 +03:00
if ( isWindows2 ) {
Deno . symlinkSync ( originSrcFilePath , dest , {
type : type === "dir" ? "dir" : "file"
} ) ;
} else {
Deno . symlinkSync ( originSrcFilePath , dest ) ;
}
2021-09-01 16:11:55 +03:00
if ( options . preserveTimestamps ) {
2021-12-03 19:55:27 +03:00
const statInfo = Deno . lstatSync ( src14 ) ;
2021-02-26 12:21:42 +03:00
assert ( statInfo . atime instanceof Date , ` statInfo.atime is unavailable ` ) ;
assert ( statInfo . mtime instanceof Date , ` statInfo.mtime is unavailable ` ) ;
Deno . utimeSync ( dest , statInfo . atime , statInfo . mtime ) ;
}
}
2021-12-03 19:55:27 +03:00
async function copyDir ( src15 , dest , options ) {
const destStat = await ensureValidCopy ( src15 , dest , options , true ) ;
2021-02-26 12:21:42 +03:00
if ( ! destStat ) {
await ensureDir ( dest ) ;
}
2021-09-01 16:11:55 +03:00
if ( options . preserveTimestamps ) {
2021-12-03 19:55:27 +03:00
const srcStatInfo = await Deno . stat ( src15 ) ;
2021-02-26 12:21:42 +03:00
assert ( srcStatInfo . atime instanceof Date , ` statInfo.atime is unavailable ` ) ;
assert ( srcStatInfo . mtime instanceof Date , ` statInfo.mtime is unavailable ` ) ;
await Deno . utime ( dest , srcStatInfo . atime , srcStatInfo . mtime ) ;
}
2021-12-03 19:55:27 +03:00
for await ( const entry of Deno . readDir ( src15 ) ) {
const srcPath = join2 ( src15 , entry . name ) ;
2021-02-26 12:21:42 +03:00
const destPath = join2 ( dest , basename2 ( srcPath ) ) ;
if ( entry . isSymlink ) {
2021-09-01 16:11:55 +03:00
await copySymLink ( srcPath , destPath , options ) ;
2021-02-26 12:21:42 +03:00
} else if ( entry . isDirectory ) {
2021-09-01 16:11:55 +03:00
await copyDir ( srcPath , destPath , options ) ;
2021-02-26 12:21:42 +03:00
} else if ( entry . isFile ) {
2021-09-01 16:11:55 +03:00
await copyFile ( srcPath , destPath , options ) ;
2021-02-26 12:21:42 +03:00
}
}
}
2021-12-03 19:55:27 +03:00
function copyDirSync ( src16 , dest , options ) {
const destStat = ensureValidCopySync ( src16 , dest , options , true ) ;
2021-02-26 12:21:42 +03:00
if ( ! destStat ) {
ensureDirSync ( dest ) ;
}
2021-09-01 16:11:55 +03:00
if ( options . preserveTimestamps ) {
2021-12-03 19:55:27 +03:00
const srcStatInfo = Deno . statSync ( src16 ) ;
2021-02-26 12:21:42 +03:00
assert ( srcStatInfo . atime instanceof Date , ` statInfo.atime is unavailable ` ) ;
assert ( srcStatInfo . mtime instanceof Date , ` statInfo.mtime is unavailable ` ) ;
Deno . utimeSync ( dest , srcStatInfo . atime , srcStatInfo . mtime ) ;
}
2021-12-03 19:55:27 +03:00
for ( const entry of Deno . readDirSync ( src16 ) ) {
2021-02-26 12:21:42 +03:00
assert ( entry . name != null , "file.name must be set" ) ;
2021-12-03 19:55:27 +03:00
const srcPath = join2 ( src16 , entry . name ) ;
2021-02-26 12:21:42 +03:00
const destPath = join2 ( dest , basename2 ( srcPath ) ) ;
if ( entry . isSymlink ) {
2021-09-01 16:11:55 +03:00
copySymlinkSync ( srcPath , destPath , options ) ;
2021-02-26 12:21:42 +03:00
} else if ( entry . isDirectory ) {
2021-09-01 16:11:55 +03:00
copyDirSync ( srcPath , destPath , options ) ;
2021-02-26 12:21:42 +03:00
} else if ( entry . isFile ) {
2021-09-01 16:11:55 +03:00
copyFileSync ( srcPath , destPath , options ) ;
2021-02-26 12:21:42 +03:00
}
}
}
2021-12-03 19:55:27 +03:00
async function copy ( src17 , dest , options = {
2021-02-26 12:21:42 +03:00
} ) {
2021-12-03 19:55:27 +03:00
src17 = resolve2 ( src17 ) ;
2021-02-26 12:21:42 +03:00
dest = resolve2 ( dest ) ;
2021-12-03 19:55:27 +03:00
if ( src17 === dest ) {
2021-02-26 12:21:42 +03:00
throw new Error ( "Source and destination cannot be the same." ) ;
}
2021-12-03 19:55:27 +03:00
const srcStat = await Deno . lstat ( src17 ) ;
if ( srcStat . isDirectory && isSubdir ( src17 , dest ) ) {
throw new Error ( ` Cannot copy ' ${ src17 } ' to a subdirectory of itself, ' ${ dest } '. ` ) ;
2021-02-26 12:21:42 +03:00
}
if ( srcStat . isSymlink ) {
2021-12-03 19:55:27 +03:00
await copySymLink ( src17 , dest , options ) ;
2021-02-26 12:21:42 +03:00
} else if ( srcStat . isDirectory ) {
2021-12-03 19:55:27 +03:00
await copyDir ( src17 , dest , options ) ;
2021-02-26 12:21:42 +03:00
} else if ( srcStat . isFile ) {
2021-12-03 19:55:27 +03:00
await copyFile ( src17 , dest , options ) ;
2021-02-26 12:21:42 +03:00
}
}
2021-12-03 19:55:27 +03:00
function copySync ( src18 , dest , options = {
2021-02-26 12:21:42 +03:00
} ) {
2021-12-03 19:55:27 +03:00
src18 = resolve2 ( src18 ) ;
2021-02-26 12:21:42 +03:00
dest = resolve2 ( dest ) ;
2021-12-03 19:55:27 +03:00
if ( src18 === dest ) {
2021-02-26 12:21:42 +03:00
throw new Error ( "Source and destination cannot be the same." ) ;
}
2021-12-03 19:55:27 +03:00
const srcStat = Deno . lstatSync ( src18 ) ;
if ( srcStat . isDirectory && isSubdir ( src18 , dest ) ) {
throw new Error ( ` Cannot copy ' ${ src18 } ' to a subdirectory of itself, ' ${ dest } '. ` ) ;
2021-02-26 12:21:42 +03:00
}
if ( srcStat . isSymlink ) {
2021-12-03 19:55:27 +03:00
copySymlinkSync ( src18 , dest , options ) ;
2021-02-26 12:21:42 +03:00
} else if ( srcStat . isDirectory ) {
2021-12-03 19:55:27 +03:00
copyDirSync ( src18 , dest , options ) ;
2021-02-26 12:21:42 +03:00
} else if ( srcStat . isFile ) {
2021-12-03 19:55:27 +03:00
copyFileSync ( src18 , dest , options ) ;
2021-02-26 12:21:42 +03:00
}
}
2021-12-03 19:55:27 +03:00
var EOL ;
( function ( EOL1 ) {
EOL1 [ "LF" ] = "\n" ;
EOL1 [ "CRLF" ] = "\r\n" ;
} ) ( EOL || ( EOL = {
2021-02-26 12:21:42 +03:00
} ) ) ;
const regDetect = /(?:\r?\n)/g ;
function detect ( content ) {
const d = content . match ( regDetect ) ;
if ( ! d || d . length === 0 ) {
return null ;
}
2021-12-03 19:55:27 +03:00
const crlf = d . filter ( ( x ) = > x === EOL . CRLF
2021-02-26 12:21:42 +03:00
) ;
if ( crlf . length > 0 ) {
2021-12-03 19:55:27 +03:00
return EOL . CRLF ;
2021-02-26 12:21:42 +03:00
} else {
2021-12-03 19:55:27 +03:00
return EOL . LF ;
2021-02-26 12:21:42 +03:00
}
}
function format3 ( content , eol ) {
return content . replace ( regDetect , eol ) ;
}
2021-10-08 10:47:01 +03:00
const mod5 = {
exists ,
existsSync ,
emptyDir ,
emptyDirSync ,
ensureDir ,
ensureDirSync ,
ensureFile ,
ensureFileSync ,
ensureLink ,
ensureLinkSync ,
ensureSymlink ,
ensureSymlinkSync ,
expandGlob ,
expandGlobSync ,
_createWalkEntrySync ,
_createWalkEntry ,
walk ,
walkSync ,
move ,
moveSync ,
copy ,
copySync ,
2021-12-03 19:55:27 +03:00
EOL ,
2021-10-08 10:47:01 +03:00
detect ,
format : format3
} ;
2021-02-26 12:21:42 +03:00
const base64abc = [
"A" ,
"B" ,
"C" ,
"D" ,
"E" ,
"F" ,
"G" ,
"H" ,
"I" ,
"J" ,
"K" ,
"L" ,
"M" ,
"N" ,
"O" ,
"P" ,
"Q" ,
"R" ,
"S" ,
"T" ,
"U" ,
"V" ,
"W" ,
"X" ,
"Y" ,
"Z" ,
"a" ,
"b" ,
"c" ,
"d" ,
"e" ,
"f" ,
"g" ,
"h" ,
"i" ,
"j" ,
"k" ,
"l" ,
"m" ,
"n" ,
"o" ,
"p" ,
"q" ,
"r" ,
"s" ,
"t" ,
"u" ,
"v" ,
"w" ,
"x" ,
"y" ,
"z" ,
"0" ,
"1" ,
"2" ,
"3" ,
"4" ,
"5" ,
"6" ,
"7" ,
"8" ,
"9" ,
"+" ,
"/"
] ;
function encode ( data ) {
const uint8 = typeof data === "string" ? new TextEncoder ( ) . encode ( data ) : data instanceof Uint8Array ? data : new Uint8Array ( data ) ;
2021-12-03 19:55:27 +03:00
let result = "" , i25 ;
2021-02-26 12:21:42 +03:00
const l = uint8 . length ;
2021-12-03 19:55:27 +03:00
for ( i25 = 2 ; i25 < l ; i25 += 3 ) {
result += base64abc [ uint8 [ i25 - 2 ] >> 2 ] ;
result += base64abc [ ( uint8 [ i25 - 2 ] & 3 ) << 4 | uint8 [ i25 - 1 ] >> 4 ] ;
result += base64abc [ ( uint8 [ i25 - 1 ] & 15 ) << 2 | uint8 [ i25 ] >> 6 ] ;
result += base64abc [ uint8 [ i25 ] & 63 ] ;
}
if ( i25 === l + 1 ) {
result += base64abc [ uint8 [ i25 - 2 ] >> 2 ] ;
result += base64abc [ ( uint8 [ i25 - 2 ] & 3 ) << 4 ] ;
2021-02-26 12:21:42 +03:00
result += "==" ;
}
2021-12-03 19:55:27 +03:00
if ( i25 === l ) {
result += base64abc [ uint8 [ i25 - 2 ] >> 2 ] ;
result += base64abc [ ( uint8 [ i25 - 2 ] & 3 ) << 4 | uint8 [ i25 - 1 ] >> 4 ] ;
result += base64abc [ ( uint8 [ i25 - 1 ] & 15 ) << 2 ] ;
2021-02-26 12:21:42 +03:00
result += "=" ;
}
return result ;
}
function decode ( b64 ) {
const binString = atob ( b64 ) ;
2021-09-01 16:11:55 +03:00
const size = binString . length ;
const bytes = new Uint8Array ( size ) ;
2021-12-03 19:55:27 +03:00
for ( let i26 = 0 ; i26 < size ; i26 ++ ) {
bytes [ i26 ] = binString . charCodeAt ( i26 ) ;
2021-02-26 12:21:42 +03:00
}
return bytes ;
}
const importMeta = {
url : "<https://deno.land/std@0.77.0/hash/_wasm/wasm.js>" ,
main : false
} ;
2021-12-03 19:55:27 +03:00
const source = decode ( " AGFzbQEAAAABSQxgAn9 / AGACf38Bf2ADf39 / AGADf39 / AX9gAX8AYAF / AX9gAABgBH9 / f38Bf2AFf39 / f38AYAV / f39 / fwF / YAJ + fwF / YAF / AX4CTQMDd2JnFV9fd2JpbmRnZW5fc3RyaW5nX25ldwABA3diZxBfX3diaW5kZ2VuX3Rocm93AAADd2JnEl9fd2JpbmRnZW5fcmV0aHJvdwAEA6sBqQEAAgEAAAIFAAACAAQABAADAAAAAQcJAAAAAAAAAAAAAAAAAAAAAAICAgIAAAAAAAAAAAAAAAAAAAACAgICBAAAAgAAAQAAAAAAAAAAAAAAAAAECgEEAQIAAAAAAgIAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAQEAgICAAEGAAMEAgcEAgQEAwMFBAQAAwQDAQEBAQQABwYBBgYBAAELBQUFBQUFBQAEBAUBcAFpaQUDAQARBgkBfwFBgIDAAAsHoQEJBm1lbW9yeQIAE19fd2JnX2Rlbm9oYXNoX2ZyZWUAhAELY3JlYXRlX2hhc2gABQt1cGRhdGVfaGFzaACFAQtkaWdlc3RfaGFzaACCARFfX3diaW5kZ2VuX21hbGxvYwCNARJfX3diaW5kZ2VuX3JlYWxsb2MAkwETX193YmluZGdlbl9leHBvcnRfMgMAD19fd2JpbmRnZW5fZnJlZQCZAQmPAQEAQQELaJcBqgGcAZYBnwFYqwFDDy5XowE3PEFIkgGjAWA / QkliPi9EjgGlAVI9GSiHAaQBR2EwRY8BU18nOooBqAFQIS2JAakBUVkTHnunAUsVJnqmAUoqNjiYAagBcSkyNJgBqQF1LBocmAGnAXQrIiSYAaYBdzU5cDEzeBsddiMlc4wBVoABlQGiAZQBCsixBqkBjEwBVn4gACABKQN4IgIgASkDSCIaIAEpAwAiFyABKQMIIgtCOIkgC0IHiIUgC0I / iYV8fCABKQNwIgNCA4kgA0IGiIUgA0ItiYV8IgRCOIkgBEIHiIUgBEI / iYV8IAEpA1AiPiABKQMQIglCOIkgCUIHiIUgCUI / iYUgC3x8IAJCBoggAkIDiYUgAkItiYV8IgcgASkDQCITIBpCB4ggGkI4iYUgGkI / iYV8fCABKQMwIhQgASkDOCJCQjiJIEJCB4iFIEJCP4mFfCACfCABKQNoIkQgASkDICIVIAEpAygiQ0I4iSBDQgeIhSBDQj + JhXx8IAEpA1giPyABKQMYIgpCOIkgCkIHiIUgCkI / iYUgCXx8IARCBoggBEIDiYUgBEItiYV8IgZCA4kgBkIGiIUgBkItiYV8IgVCA4kgBUIGiIUgBUItiYV8IghCA4kgCEIGiIUgCEItiYV8Igx8IANCB4ggA0I4iYUgA0I / iYUgRHwgCHwgASkDYCJAQjiJIEBCB4iFIEBCP4mFID98IAV8ID5CB4ggPkI4iYUgPkI / iYUgGnwgBnwgE0IHiCATQjiJhSATQj + JhSBCfCAEfCAUQgeIIBRCOImFIBRCP4mFIEN8IAN8IBVCB4ggFUI4iYUgFUI / iYUgCnwgQHwgB0IGiCAHQgOJhSAHQi2JhXwiDUIDiSANQgaIhSANQi2JhXwiDkIDiSAOQgaIhSAOQi2JhXwiEEIDiSAQQgaIhSAQQi2JhXwiEUIDiSARQgaIhSARQi2JhXwiFkIDiSAWQgaIhSAWQi2JhXwiGEIDiSAYQgaIhSAYQi2JhXwiGUI4iSAZQgeIhSAZQj + JhSACQgeIIAJCOImFIAJCP4mFIAN8IBB8IERCB4ggREI4iYUgREI / iYUgQHwgDnwgP0IHiCA / QjiJhSA / Qj + JhSA + fCANfCAMQgaIIAxCA4mFIAxCLYmFfCIbQgOJIBtCBoiFIBtCLYmFfCIcQgOJIBxCBoiFIBxCLYmFfCIdfCAHQgeIIAdCOImFIAdCP4mFIAR8IBF8IB1CBoggHUIDiYUgHUItiYV8Ih4gDEIHiCAMQjiJhSAMQj + JhSAQfHwgCEIHiCAIQjiJhSAIQj + JhSAOfCAdfCAFQgeIIAVCOImFIAVCP4mFIA18IBx8IAZCB4ggBkI4iYUgBkI / iYUgB3wgG3wgGUIGiCAZQgOJhSAZQi2JhXwiH0IDiSAfQgaIhSAfQi2JhXwiIEIDiSAgQgaIhSAgQi2JhXwiIUIDiSAhQgaIhSAhQi2JhXwiInwgGEIHiCAYQjiJhSAYQj + JhSAcfCAhfCAWQgeIIBZCOImFIBZCP4mFIBt8ICB8IBFCB4ggEUI4iYUgEUI / iYUgDHwgH3wgEEIHiCAQQjiJhSAQQj + JhSAIfCAZfCAOQgeIIA5COImFIA5CP4mFIAV8IBh8IA1CB4ggDUI4iYUgDUI / iYUgBnwgFnwgHkIGiCAeQgOJhSAeQi2JhXwiI0IDiSAjQgaIhSAjQi2JhXwiJEIDiSAkQgaIhSAkQi2JhXwiJUIDiSAlQgaIhSAlQi2JhXwiJkIDiSAmQgaIhSAmQi2JhXwiJ0IDiSAnQgaIhSAnQi2JhXwiKEIDiSAoQgaIhSAoQi2JhXwiKUI4iSApQgeIhSApQj + JhSAdQgeIIB1COImFIB1CP4mFIBh8ICV8IBxCB4ggHEI4iYUgHEI / iYUgFnwgJHwgG0IHiCAbQjiJhSAbQj + JhSARfCAjfCAiQgaIICJCA4mFICJCLYmFfCIqQgOJICpCBoiFICpCLYmFfCIrQgOJICtCBoiFICtCLYmFfCIsfCAeQgeIIB5COImFIB5CP4mFIBl8ICZ8ICxCBoggLEIDiYUgLEItiYV8Ii0gIkIHiCAiQjiJhSAiQj + JhSAlfHwgIUIHiCAhQjiJhSAhQj + JhSAkfCAsfCAgQgeIICBCOImFICBCP4mFICN8ICt8IB9CB4ggH0I4iYUgH0I / iYUgHnwgKnwgKUIGiCApQgOJhSApQi2JhXwiLkIDiSAuQgaIhSAuQi2JhXwiL0IDiSAvQgaIhSAvQi2JhXwiMEIDiSAwQgaIhSAwQi2JhXwiMXwgKEIHiCAoQjiJhSAoQj + JhSArfCAwfCAnQgeIICdCOImFICdCP4mFICp8IC98ICZCB4ggJkI4iYUgJkI / iYUgInwgLnwgJUIHiCAlQjiJhSAlQj + JhSAhfCApfCAkQgeIICRCOImFICRCP4mFICB8ICh8ICNCB4ggI0I4iYUgI0I / iYUgH3wgJ3wgLUIGiCAtQgOJhSAtQi2JhXwiMkIDiSAyQgaIhSAyQi2JhXwiM0IDiSAzQgaIhSAzQi2JhXwiNEIDiSA0QgaIhSA0Qi2JhXwiNUIDiSA1QgaIhSA1Qi2JhXwiNkIDiSA2QgaIhSA2Qi2JhXwiN0IDiSA3QgaIhSA3Qi2JhXwiOEI4iSA4QgeIhSA4Qj + JhSAsQgeIICxCOImFICxCP4mFICh8IDR8ICtCB4ggK0I4iYUgK0I / iYUgJ3wgM3wgKkIHiCAqQjiJhSAqQj + JhSAmfCAyfCAxQgaIIDFCA4mFIDFCLYmFfCI5QgOJIDlCBoiFIDlCLYmFfCI6QgOJIDpCBoiFIDpCLYmFfCI7fCAtQgeIIC1COImFIC1CP4mFICl8IDV8IDtCBoggO0IDiYUgO0ItiYV8IjwgMUIHiCAxQjiJhSAxQj + JhSA0fHwgMEIHiCAwQjiJhSAwQj + JhSAzfCA7fCAvQgeIIC9COImFIC9CP4mFIDJ8IDp8IC5CB4ggLkI4iYUgLkI / iYUgLXwgOXwgOEIGiCA4QgOJhSA4Qi2JhXwiPUIDiSA9QgaIhSA9Qi2JhXwiRkIDiSBGQgaIhSBGQi2JhXwiR0IDiSBHQgaIhSBHQi2JhXwiSHwgN0IHiCA3QjiJhSA3Qj + JhSA6fCBHfCA2QgeIIDZCOImFIDZCP4mFIDl8IEZ8IDVCB4ggNUI4iYUgNUI / iYUgMXwgPXwgNEIHiCA0QjiJhSA0Qj + JhSAwfCA4fCAzQgeIIDNCOImFIDNCP4mFIC98IDd8IDJCB4ggMkI4iYUgMkI / iYUgLnwgNnwgPEIGiCA8QgOJhSA8Qi2JhXwiQUIDiSBBQgaIhSBBQi2JhXwiSUID
2021-02-26 12:21:42 +03:00
let wasm ;
let cachedTextDecoder = new TextDecoder ( 'utf-8' , {
ignoreBOM : true ,
fatal : true
} ) ;
cachedTextDecoder . decode ( ) ;
let cachegetUint8Memory0 = null ;
function getUint8Memory0() {
if ( cachegetUint8Memory0 === null || cachegetUint8Memory0 . buffer !== wasm . memory . buffer ) {
cachegetUint8Memory0 = new Uint8Array ( wasm . memory . buffer ) ;
}
return cachegetUint8Memory0 ;
}
function getStringFromWasm0 ( ptr , len ) {
return cachedTextDecoder . decode ( getUint8Memory0 ( ) . subarray ( ptr , ptr + len ) ) ;
}
const heap = new Array ( 32 ) . fill ( undefined ) ;
heap . push ( undefined , null , true , false ) ;
let heap_next = heap . length ;
function addHeapObject ( obj ) {
if ( heap_next === heap . length ) heap . push ( heap . length + 1 ) ;
const idx = heap_next ;
heap_next = heap [ idx ] ;
heap [ idx ] = obj ;
return idx ;
}
function getObject ( idx ) {
return heap [ idx ] ;
}
function dropObject ( idx ) {
if ( idx < 36 ) return ;
heap [ idx ] = heap_next ;
heap_next = idx ;
}
function takeObject ( idx ) {
const ret = getObject ( idx ) ;
dropObject ( idx ) ;
return ret ;
}
let WASM_VECTOR_LEN = 0 ;
let cachedTextEncoder = new TextEncoder ( 'utf-8' ) ;
const encodeString = typeof cachedTextEncoder . encodeInto === 'function' ? function ( arg , view ) {
return cachedTextEncoder . encodeInto ( arg , view ) ;
} : function ( arg , view ) {
const buf = cachedTextEncoder . encode ( arg ) ;
view . set ( buf ) ;
return {
read : arg.length ,
written : buf.length
} ;
} ;
function passStringToWasm0 ( arg , malloc , realloc ) {
if ( realloc === undefined ) {
const buf = cachedTextEncoder . encode ( arg ) ;
const ptr = malloc ( buf . length ) ;
getUint8Memory0 ( ) . subarray ( ptr , ptr + buf . length ) . set ( buf ) ;
WASM_VECTOR_LEN = buf . length ;
return ptr ;
}
let len = arg . length ;
let ptr = malloc ( len ) ;
const mem = getUint8Memory0 ( ) ;
let offset = 0 ;
for ( ; offset < len ; offset ++ ) {
2021-12-03 19:55:27 +03:00
const code17 = arg . charCodeAt ( offset ) ;
if ( code17 > 127 ) break ;
mem [ ptr + offset ] = code17 ;
2021-02-26 12:21:42 +03:00
}
if ( offset !== len ) {
if ( offset !== 0 ) {
arg = arg . slice ( offset ) ;
}
ptr = realloc ( ptr , len , len = offset + arg . length * 3 ) ;
const view = getUint8Memory0 ( ) . subarray ( ptr + offset , ptr + len ) ;
const ret = encodeString ( arg , view ) ;
offset += ret . written ;
}
WASM_VECTOR_LEN = offset ;
return ptr ;
}
function create_hash ( algorithm ) {
var ptr0 = passStringToWasm0 ( algorithm , wasm . __wbindgen_malloc , wasm . __wbindgen_realloc ) ;
var len0 = WASM_VECTOR_LEN ;
var ret = wasm . create_hash ( ptr0 , len0 ) ;
return DenoHash . __wrap ( ret ) ;
}
function _assertClass ( instance , klass ) {
if ( ! ( instance instanceof klass ) ) {
throw new Error ( ` expected instance of ${ klass . name } ` ) ;
}
return instance . ptr ;
}
function passArray8ToWasm0 ( arg , malloc ) {
const ptr = malloc ( arg . length * 1 ) ;
getUint8Memory0 ( ) . set ( arg , ptr / 1 ) ;
WASM_VECTOR_LEN = arg . length ;
return ptr ;
}
function update_hash ( hash , data ) {
_assertClass ( hash , DenoHash ) ;
var ptr0 = passArray8ToWasm0 ( data , wasm . __wbindgen_malloc ) ;
var len0 = WASM_VECTOR_LEN ;
wasm . update_hash ( hash . ptr , ptr0 , len0 ) ;
}
let cachegetInt32Memory0 = null ;
function getInt32Memory0() {
if ( cachegetInt32Memory0 === null || cachegetInt32Memory0 . buffer !== wasm . memory . buffer ) {
cachegetInt32Memory0 = new Int32Array ( wasm . memory . buffer ) ;
}
return cachegetInt32Memory0 ;
}
function getArrayU8FromWasm0 ( ptr , len ) {
return getUint8Memory0 ( ) . subarray ( ptr / 1 , ptr / 1 + len ) ;
}
function digest_hash ( hash ) {
try {
const retptr = wasm . __wbindgen_export_2 . value - 16 ;
wasm . __wbindgen_export_2 . value = retptr ;
_assertClass ( hash , DenoHash ) ;
wasm . digest_hash ( retptr , hash . ptr ) ;
var r0 = getInt32Memory0 ( ) [ retptr / 4 + 0 ] ;
var r1 = getInt32Memory0 ( ) [ retptr / 4 + 1 ] ;
var v0 = getArrayU8FromWasm0 ( r0 , r1 ) . slice ( ) ;
wasm . __wbindgen_free ( r0 , r1 * 1 ) ;
return v0 ;
} finally {
wasm . __wbindgen_export_2 . value += 16 ;
}
}
class DenoHash {
static __wrap ( ptr ) {
const obj = Object . create ( DenoHash . prototype ) ;
obj . ptr = ptr ;
return obj ;
}
free() {
const ptr = this . ptr ;
this . ptr = 0 ;
wasm . __wbg_denohash_free ( ptr ) ;
}
}
async function load ( module , imports ) {
if ( typeof Response === 'function' && module instanceof Response ) {
if ( typeof WebAssembly . instantiateStreaming === 'function' ) {
try {
return await WebAssembly . instantiateStreaming ( module , imports ) ;
} catch ( e ) {
if ( module .headers.get ( 'Content-Type' ) != 'application/wasm' ) {
console . warn ( "`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n" , e ) ;
} else {
throw e ;
}
}
}
const bytes = await module .arrayBuffer ( ) ;
return await WebAssembly . instantiate ( bytes , imports ) ;
} else {
const instance = await WebAssembly . instantiate ( module , imports ) ;
if ( instance instanceof WebAssembly . Instance ) {
return {
instance ,
module
} ;
} else {
return instance ;
}
}
}
async function init ( input ) {
if ( typeof input === 'undefined' ) {
input = importMeta . url . replace ( /\.js$/ , '_bg.wasm' ) ;
}
const imports = {
} ;
imports . wbg = {
} ;
imports . wbg . __wbindgen_string_new = function ( arg0 , arg1 ) {
var ret = getStringFromWasm0 ( arg0 , arg1 ) ;
return addHeapObject ( ret ) ;
} ;
imports . wbg . __wbindgen_throw = function ( arg0 , arg1 ) {
throw new Error ( getStringFromWasm0 ( arg0 , arg1 ) ) ;
} ;
imports . wbg . __wbindgen_rethrow = function ( arg0 ) {
throw takeObject ( arg0 ) ;
} ;
if ( typeof input === 'string' || typeof Request === 'function' && input instanceof Request || typeof URL === 'function' && input instanceof URL ) {
input = fetch ( input ) ;
}
const { instance , module } = await load ( await input , imports ) ;
wasm = instance . exports ;
init . __wbindgen_wasm_module = module ;
return wasm ;
}
const hextable = new TextEncoder ( ) . encode ( "0123456789abcdef" ) ;
function encodedLen ( n ) {
return n * 2 ;
}
2021-12-03 19:55:27 +03:00
function encode1 ( src19 ) {
const dst = new Uint8Array ( encodedLen ( src19 . length ) ) ;
for ( let i27 = 0 ; i27 < dst . length ; i27 ++ ) {
const v = src19 [ i27 ] ;
dst [ i27 * 2 ] = hextable [ v >> 4 ] ;
dst [ i27 * 2 + 1 ] = hextable [ v & 15 ] ;
2021-02-26 12:21:42 +03:00
}
return dst ;
}
2021-12-03 19:55:27 +03:00
function encodeToString ( src20 ) {
return new TextDecoder ( ) . decode ( encode1 ( src20 ) ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
await init ( source ) ;
2021-02-26 12:21:42 +03:00
const TYPE_ERROR_MSG = "hash: `data` is invalid type" ;
class Hash {
# hash ;
# digested ;
2021-12-02 10:28:09 +03:00
constructor ( algorithm ) {
this . # hash = create_hash ( algorithm ) ;
2021-02-26 12:21:42 +03:00
this . # digested = false ;
}
2021-12-02 10:28:09 +03:00
update ( data ) {
2021-02-26 12:21:42 +03:00
let msg ;
2021-12-02 10:28:09 +03:00
if ( typeof data === "string" ) {
msg = new TextEncoder ( ) . encode ( data ) ;
} else if ( typeof data === "object" ) {
if ( data instanceof ArrayBuffer || ArrayBuffer . isView ( data ) ) {
msg = new Uint8Array ( data ) ;
2021-02-26 12:21:42 +03:00
} else {
throw new Error ( TYPE_ERROR_MSG ) ;
}
} else {
throw new Error ( TYPE_ERROR_MSG ) ;
}
update_hash ( this . # hash , msg ) ;
return this ;
}
digest() {
if ( this . # digested ) throw new Error ( "hash: already digested" ) ;
this . # digested = true ;
return digest_hash ( this . # hash ) ;
}
2021-12-03 19:55:27 +03:00
toString ( format4 = "hex" ) {
2021-02-26 12:21:42 +03:00
const finalized = new Uint8Array ( this . digest ( ) ) ;
2021-12-03 19:55:27 +03:00
switch ( format4 ) {
2021-02-26 12:21:42 +03:00
case "hex" :
return encodeToString ( finalized ) ;
case "base64" :
return encode ( finalized ) ;
default :
throw new Error ( "hash: invalid format" ) ;
}
}
}
2021-09-01 16:11:55 +03:00
function createHash ( algorithm ) {
return new Hash ( algorithm ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-08 10:47:01 +03:00
const mod6 = {
createHash : createHash
} ;
2021-02-26 12:21:42 +03:00
const SEMVER_SPEC_VERSION = "2.0.0" ;
const MAX_LENGTH = 256 ;
const MAX_SAFE_COMPONENT_LENGTH = 16 ;
const re = [ ] ;
2021-12-03 19:55:27 +03:00
const src = [ ] ;
2021-02-26 12:21:42 +03:00
let R = 0 ;
const NUMERICIDENTIFIER = R ++ ;
2021-12-03 19:55:27 +03:00
src [ NUMERICIDENTIFIER ] = "0|[1-9]\\d*" ;
2021-02-26 12:21:42 +03:00
const NUMERICIDENTIFIERLOOSE = R ++ ;
2021-12-03 19:55:27 +03:00
src [ NUMERICIDENTIFIERLOOSE ] = "[0-9]+" ;
2021-02-26 12:21:42 +03:00
const NONNUMERICIDENTIFIER = R ++ ;
2021-12-03 19:55:27 +03:00
src [ NONNUMERICIDENTIFIER ] = "\\d*[a-zA-Z-][a-zA-Z0-9-]*" ;
2021-02-26 12:21:42 +03:00
const MAINVERSION = R ++ ;
2021-12-03 19:55:27 +03:00
const nid = src [ NUMERICIDENTIFIER ] ;
src [ MAINVERSION ] = ` ( ${ nid } ) \\ .( ${ nid } ) \\ .( ${ nid } ) ` ;
2021-02-26 12:21:42 +03:00
const MAINVERSIONLOOSE = R ++ ;
2021-12-03 19:55:27 +03:00
const nidl = src [ NUMERICIDENTIFIERLOOSE ] ;
src [ MAINVERSIONLOOSE ] = ` ( ${ nidl } ) \\ .( ${ nidl } ) \\ .( ${ nidl } ) ` ;
2021-02-26 12:21:42 +03:00
const PRERELEASEIDENTIFIER = R ++ ;
2021-12-03 19:55:27 +03:00
src [ PRERELEASEIDENTIFIER ] = "(?:" + src [ NUMERICIDENTIFIER ] + "|" + src [ NONNUMERICIDENTIFIER ] + ")" ;
2021-02-26 12:21:42 +03:00
const PRERELEASEIDENTIFIERLOOSE = R ++ ;
2021-12-03 19:55:27 +03:00
src [ PRERELEASEIDENTIFIERLOOSE ] = "(?:" + src [ NUMERICIDENTIFIERLOOSE ] + "|" + src [ NONNUMERICIDENTIFIER ] + ")" ;
2021-02-26 12:21:42 +03:00
const PRERELEASE = R ++ ;
2021-12-03 19:55:27 +03:00
src [ PRERELEASE ] = "(?:-(" + src [ PRERELEASEIDENTIFIER ] + "(?:\\." + src [ PRERELEASEIDENTIFIER ] + ")*))" ;
2021-02-26 12:21:42 +03:00
const PRERELEASELOOSE = R ++ ;
2021-12-03 19:55:27 +03:00
src [ PRERELEASELOOSE ] = "(?:-?(" + src [ PRERELEASEIDENTIFIERLOOSE ] + "(?:\\." + src [ PRERELEASEIDENTIFIERLOOSE ] + ")*))" ;
2021-02-26 12:21:42 +03:00
const BUILDIDENTIFIER = R ++ ;
2021-12-03 19:55:27 +03:00
src [ BUILDIDENTIFIER ] = "[0-9A-Za-z-]+" ;
2021-02-26 12:21:42 +03:00
const BUILD = R ++ ;
2021-12-03 19:55:27 +03:00
src [ BUILD ] = "(?:\\+(" + src [ BUILDIDENTIFIER ] + "(?:\\." + src [ BUILDIDENTIFIER ] + ")*))" ;
2021-02-26 12:21:42 +03:00
const FULL = R ++ ;
2021-12-03 19:55:27 +03:00
const FULLPLAIN = "v?" + src [ MAINVERSION ] + src [ PRERELEASE ] + "?" + src [ BUILD ] + "?" ;
src [ FULL ] = "^" + FULLPLAIN + "$" ;
const LOOSEPLAIN = "[v=\\s]*" + src [ MAINVERSIONLOOSE ] + src [ PRERELEASELOOSE ] + "?" + src [ BUILD ] + "?" ;
2021-02-26 12:21:42 +03:00
const LOOSE = R ++ ;
2021-12-03 19:55:27 +03:00
src [ LOOSE ] = "^" + LOOSEPLAIN + "$" ;
2021-02-26 12:21:42 +03:00
const GTLT = R ++ ;
2021-12-03 19:55:27 +03:00
src [ GTLT ] = "((?:<|>)?=?)" ;
2021-02-26 12:21:42 +03:00
const XRANGEIDENTIFIERLOOSE = R ++ ;
2021-12-03 19:55:27 +03:00
src [ XRANGEIDENTIFIERLOOSE ] = src [ NUMERICIDENTIFIERLOOSE ] + "|x|X|\\*" ;
2021-02-26 12:21:42 +03:00
const XRANGEIDENTIFIER = R ++ ;
2021-12-03 19:55:27 +03:00
src [ XRANGEIDENTIFIER ] = src [ NUMERICIDENTIFIER ] + "|x|X|\\*" ;
2021-02-26 12:21:42 +03:00
const XRANGEPLAIN = R ++ ;
2021-12-03 19:55:27 +03:00
src [ XRANGEPLAIN ] = "[v=\\s]*(" + src [ XRANGEIDENTIFIER ] + ")" + "(?:\\.(" + src [ XRANGEIDENTIFIER ] + ")" + "(?:\\.(" + src [ XRANGEIDENTIFIER ] + ")" + "(?:" + src [ PRERELEASE ] + ")?" + src [ BUILD ] + "?" + ")?)?" ;
2021-02-26 12:21:42 +03:00
const XRANGEPLAINLOOSE = R ++ ;
2021-12-03 19:55:27 +03:00
src [ XRANGEPLAINLOOSE ] = "[v=\\s]*(" + src [ XRANGEIDENTIFIERLOOSE ] + ")" + "(?:\\.(" + src [ XRANGEIDENTIFIERLOOSE ] + ")" + "(?:\\.(" + src [ XRANGEIDENTIFIERLOOSE ] + ")" + "(?:" + src [ PRERELEASELOOSE ] + ")?" + src [ BUILD ] + "?" + ")?)?" ;
2021-02-26 12:21:42 +03:00
const XRANGE = R ++ ;
2021-12-03 19:55:27 +03:00
src [ XRANGE ] = "^" + src [ GTLT ] + "\\s*" + src [ XRANGEPLAIN ] + "$" ;
2021-02-26 12:21:42 +03:00
const XRANGELOOSE = R ++ ;
2021-12-03 19:55:27 +03:00
src [ XRANGELOOSE ] = "^" + src [ GTLT ] + "\\s*" + src [ XRANGEPLAINLOOSE ] + "$" ;
2021-02-26 12:21:42 +03:00
const COERCE = R ++ ;
2021-12-03 19:55:27 +03:00
src [ COERCE ] = "(?:^|[^\\d])" + "(\\d{1," + MAX_SAFE_COMPONENT_LENGTH + "})" + "(?:\\.(\\d{1," + MAX_SAFE_COMPONENT_LENGTH + "}))?" + "(?:\\.(\\d{1," + MAX_SAFE_COMPONENT_LENGTH + "}))?" + "(?:$|[^\\d])" ;
2021-02-26 12:21:42 +03:00
const LONETILDE = R ++ ;
2021-12-03 19:55:27 +03:00
src [ LONETILDE ] = "(?:~>?)" ;
2021-02-26 12:21:42 +03:00
const TILDETRIM = R ++ ;
2021-12-03 19:55:27 +03:00
src [ TILDETRIM ] = "(\\s*)" + src [ LONETILDE ] + "\\s+" ;
re [ TILDETRIM ] = new RegExp ( src [ TILDETRIM ] , "g" ) ;
2021-02-26 12:21:42 +03:00
const tildeTrimReplace = "$1~" ;
const TILDE = R ++ ;
2021-12-03 19:55:27 +03:00
src [ TILDE ] = "^" + src [ LONETILDE ] + src [ XRANGEPLAIN ] + "$" ;
2021-02-26 12:21:42 +03:00
const TILDELOOSE = R ++ ;
2021-12-03 19:55:27 +03:00
src [ TILDELOOSE ] = "^" + src [ LONETILDE ] + src [ XRANGEPLAINLOOSE ] + "$" ;
2021-02-26 12:21:42 +03:00
const LONECARET = R ++ ;
2021-12-03 19:55:27 +03:00
src [ LONECARET ] = "(?:\\^)" ;
2021-02-26 12:21:42 +03:00
const CARETTRIM = R ++ ;
2021-12-03 19:55:27 +03:00
src [ CARETTRIM ] = "(\\s*)" + src [ LONECARET ] + "\\s+" ;
re [ CARETTRIM ] = new RegExp ( src [ CARETTRIM ] , "g" ) ;
2021-02-26 12:21:42 +03:00
const caretTrimReplace = "$1^" ;
const CARET = R ++ ;
2021-12-03 19:55:27 +03:00
src [ CARET ] = "^" + src [ LONECARET ] + src [ XRANGEPLAIN ] + "$" ;
2021-02-26 12:21:42 +03:00
const CARETLOOSE = R ++ ;
2021-12-03 19:55:27 +03:00
src [ CARETLOOSE ] = "^" + src [ LONECARET ] + src [ XRANGEPLAINLOOSE ] + "$" ;
2021-02-26 12:21:42 +03:00
const COMPARATORLOOSE = R ++ ;
2021-12-03 19:55:27 +03:00
src [ COMPARATORLOOSE ] = "^" + src [ GTLT ] + "\\s*(" + LOOSEPLAIN + ")$|^$" ;
2021-02-26 12:21:42 +03:00
const COMPARATOR = R ++ ;
2021-12-03 19:55:27 +03:00
src [ COMPARATOR ] = "^" + src [ GTLT ] + "\\s*(" + FULLPLAIN + ")$|^$" ;
2021-02-26 12:21:42 +03:00
const COMPARATORTRIM = R ++ ;
2021-12-03 19:55:27 +03:00
src [ COMPARATORTRIM ] = "(\\s*)" + src [ GTLT ] + "\\s*(" + LOOSEPLAIN + "|" + src [ XRANGEPLAIN ] + ")" ;
re [ COMPARATORTRIM ] = new RegExp ( src [ COMPARATORTRIM ] , "g" ) ;
2021-02-26 12:21:42 +03:00
const comparatorTrimReplace = "$1$2$3" ;
const HYPHENRANGE = R ++ ;
2021-12-03 19:55:27 +03:00
src [ HYPHENRANGE ] = "^\\s*(" + src [ XRANGEPLAIN ] + ")" + "\\s+-\\s+" + "(" + src [ XRANGEPLAIN ] + ")" + "\\s*$" ;
2021-02-26 12:21:42 +03:00
const HYPHENRANGELOOSE = R ++ ;
2021-12-03 19:55:27 +03:00
src [ HYPHENRANGELOOSE ] = "^\\s*(" + src [ XRANGEPLAINLOOSE ] + ")" + "\\s+-\\s+" + "(" + src [ XRANGEPLAINLOOSE ] + ")" + "\\s*$" ;
2021-02-26 12:21:42 +03:00
const STAR = R ++ ;
2021-12-03 19:55:27 +03:00
src [ STAR ] = "(<|>)?=?\\s*\\*" ;
for ( let i = 0 ; i < R ; i ++ ) {
if ( ! re [ i ] ) {
re [ i ] = new RegExp ( src [ i ] ) ;
2021-02-26 12:21:42 +03:00
}
}
2021-12-03 19:55:27 +03:00
function parse4 ( version1 , optionsOrLoose ) {
2021-02-26 12:21:42 +03:00
if ( ! optionsOrLoose || typeof optionsOrLoose !== "object" ) {
optionsOrLoose = {
loose : ! ! optionsOrLoose ,
includePrerelease : false
} ;
}
2021-12-03 19:55:27 +03:00
if ( version1 instanceof SemVer ) {
return version1 ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
if ( typeof version1 !== "string" ) {
2021-02-26 12:21:42 +03:00
return null ;
}
2021-12-03 19:55:27 +03:00
if ( version1 . length > MAX_LENGTH ) {
2021-02-26 12:21:42 +03:00
return null ;
}
const r = optionsOrLoose . loose ? re [ LOOSE ] : re [ FULL ] ;
2021-12-03 19:55:27 +03:00
if ( ! r . test ( version1 ) ) {
2021-02-26 12:21:42 +03:00
return null ;
}
try {
2021-12-03 19:55:27 +03:00
return new SemVer ( version1 , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
} catch ( er ) {
return null ;
}
}
2021-12-03 19:55:27 +03:00
function valid ( version2 , optionsOrLoose ) {
if ( version2 === null ) return null ;
const v = parse4 ( version2 , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
return v ? v.version : null ;
}
2021-12-03 19:55:27 +03:00
function clean ( version3 , optionsOrLoose ) {
const s = parse4 ( version3 . trim ( ) . replace ( /^[=v]+/ , "" ) , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
return s ? s.version : null ;
}
class SemVer {
2021-12-03 19:55:27 +03:00
constructor ( version4 , optionsOrLoose ) {
2021-12-02 10:28:09 +03:00
if ( ! optionsOrLoose || typeof optionsOrLoose !== "object" ) {
optionsOrLoose = {
loose : ! ! optionsOrLoose ,
2021-02-26 12:21:42 +03:00
includePrerelease : false
} ;
}
2021-12-03 19:55:27 +03:00
if ( version4 instanceof SemVer ) {
if ( version4 . loose === optionsOrLoose . loose ) {
return version4 ;
2021-02-26 12:21:42 +03:00
} else {
2021-12-03 19:55:27 +03:00
version4 = version4 . version ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
} else if ( typeof version4 !== "string" ) {
throw new TypeError ( "Invalid Version: " + version4 ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
if ( version4 . length > MAX_LENGTH ) {
2021-02-26 12:21:42 +03:00
throw new TypeError ( "version is longer than " + MAX_LENGTH + " characters" ) ;
}
if ( ! ( this instanceof SemVer ) ) {
2021-12-03 19:55:27 +03:00
return new SemVer ( version4 , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
this . options = optionsOrLoose ;
this . loose = ! ! optionsOrLoose . loose ;
2021-12-03 19:55:27 +03:00
const m = version4 . trim ( ) . match ( optionsOrLoose . loose ? re [ LOOSE ] : re [ FULL ] ) ;
2021-02-26 12:21:42 +03:00
if ( ! m ) {
2021-12-03 19:55:27 +03:00
throw new TypeError ( "Invalid Version: " + version4 ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
this . raw = version4 ;
2021-02-26 12:21:42 +03:00
this . major = + m [ 1 ] ;
this . minor = + m [ 2 ] ;
this . patch = + m [ 3 ] ;
if ( this . major > Number . MAX_SAFE_INTEGER || this . major < 0 ) {
throw new TypeError ( "Invalid major version" ) ;
}
if ( this . minor > Number . MAX_SAFE_INTEGER || this . minor < 0 ) {
throw new TypeError ( "Invalid minor version" ) ;
}
if ( this . patch > Number . MAX_SAFE_INTEGER || this . patch < 0 ) {
throw new TypeError ( "Invalid patch version" ) ;
}
if ( ! m [ 4 ] ) {
this . prerelease = [ ] ;
} else {
this . prerelease = m [ 4 ] . split ( "." ) . map ( ( id ) = > {
if ( /^[0-9]+$/ . test ( id ) ) {
const num = + id ;
if ( num >= 0 && num < Number . MAX_SAFE_INTEGER ) {
return num ;
}
}
return id ;
} ) ;
}
this . build = m [ 5 ] ? m [ 5 ] . split ( "." ) : [ ] ;
this . format ( ) ;
}
format() {
this . version = this . major + "." + this . minor + "." + this . patch ;
if ( this . prerelease . length ) {
this . version += "-" + this . prerelease . join ( "." ) ;
}
return this . version ;
}
compare ( other ) {
if ( ! ( other instanceof SemVer ) ) {
other = new SemVer ( other , this . options ) ;
}
return this . compareMain ( other ) || this . comparePre ( other ) ;
}
2021-12-02 10:28:09 +03:00
compareMain ( other ) {
if ( ! ( other instanceof SemVer ) ) {
other = new SemVer ( other , this . options ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
return compareIdentifiers ( this . major , other . major ) || compareIdentifiers ( this . minor , other . minor ) || compareIdentifiers ( this . patch , other . patch ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
comparePre ( other ) {
if ( ! ( other instanceof SemVer ) ) {
other = new SemVer ( other , this . options ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
if ( this . prerelease . length && ! other . prerelease . length ) {
2021-02-26 12:21:42 +03:00
return - 1 ;
2021-12-02 10:28:09 +03:00
} else if ( ! this . prerelease . length && other . prerelease . length ) {
2021-02-26 12:21:42 +03:00
return 1 ;
2021-12-02 10:28:09 +03:00
} else if ( ! this . prerelease . length && ! other . prerelease . length ) {
2021-02-26 12:21:42 +03:00
return 0 ;
}
2021-12-03 19:55:27 +03:00
let i28 = 0 ;
2021-02-26 12:21:42 +03:00
do {
2021-12-03 19:55:27 +03:00
const a = this . prerelease [ i28 ] ;
const b = other . prerelease [ i28 ] ;
2021-02-26 12:21:42 +03:00
if ( a === undefined && b === undefined ) {
return 0 ;
} else if ( b === undefined ) {
return 1 ;
} else if ( a === undefined ) {
return - 1 ;
} else if ( a === b ) {
continue ;
} else {
return compareIdentifiers ( a , b ) ;
}
2021-12-03 19:55:27 +03:00
} while ( ++ i28 )
2021-02-26 12:21:42 +03:00
return 1 ;
}
2021-12-02 10:28:09 +03:00
compareBuild ( other ) {
if ( ! ( other instanceof SemVer ) ) {
other = new SemVer ( other , this . options ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
let i29 = 0 ;
2021-02-26 12:21:42 +03:00
do {
2021-12-03 19:55:27 +03:00
const a = this . build [ i29 ] ;
const b = other . build [ i29 ] ;
2021-02-26 12:21:42 +03:00
if ( a === undefined && b === undefined ) {
return 0 ;
} else if ( b === undefined ) {
return 1 ;
} else if ( a === undefined ) {
return - 1 ;
} else if ( a === b ) {
continue ;
} else {
return compareIdentifiers ( a , b ) ;
}
2021-12-03 19:55:27 +03:00
} while ( ++ i29 )
2021-02-26 12:21:42 +03:00
return 1 ;
}
2021-12-02 10:28:09 +03:00
inc ( release , identifier ) {
switch ( release ) {
2021-02-26 12:21:42 +03:00
case "premajor" :
this . prerelease . length = 0 ;
this . patch = 0 ;
this . minor = 0 ;
this . major ++ ;
2021-12-02 10:28:09 +03:00
this . inc ( "pre" , identifier ) ;
2021-02-26 12:21:42 +03:00
break ;
case "preminor" :
this . prerelease . length = 0 ;
this . patch = 0 ;
this . minor ++ ;
2021-12-02 10:28:09 +03:00
this . inc ( "pre" , identifier ) ;
2021-02-26 12:21:42 +03:00
break ;
case "prepatch" :
this . prerelease . length = 0 ;
2021-12-02 10:28:09 +03:00
this . inc ( "patch" , identifier ) ;
this . inc ( "pre" , identifier ) ;
2021-02-26 12:21:42 +03:00
break ;
case "prerelease" :
if ( this . prerelease . length === 0 ) {
2021-12-02 10:28:09 +03:00
this . inc ( "patch" , identifier ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
this . inc ( "pre" , identifier ) ;
2021-02-26 12:21:42 +03:00
break ;
case "major" :
if ( this . minor !== 0 || this . patch !== 0 || this . prerelease . length === 0 ) {
this . major ++ ;
}
this . minor = 0 ;
this . patch = 0 ;
this . prerelease = [ ] ;
break ;
case "minor" :
if ( this . patch !== 0 || this . prerelease . length === 0 ) {
this . minor ++ ;
}
this . patch = 0 ;
this . prerelease = [ ] ;
break ;
case "patch" :
if ( this . prerelease . length === 0 ) {
this . patch ++ ;
}
this . prerelease = [ ] ;
break ;
case "pre" :
if ( this . prerelease . length === 0 ) {
this . prerelease = [
0
] ;
} else {
2021-12-03 19:55:27 +03:00
let i30 = this . prerelease . length ;
while ( -- i30 >= 0 ) {
if ( typeof this . prerelease [ i30 ] === "number" ) {
this . prerelease [ i30 ] ++ ;
i30 = - 2 ;
2021-02-26 12:21:42 +03:00
}
}
2021-12-03 19:55:27 +03:00
if ( i30 === - 1 ) {
2021-02-26 12:21:42 +03:00
this . prerelease . push ( 0 ) ;
}
}
2021-12-02 10:28:09 +03:00
if ( identifier ) {
if ( this . prerelease [ 0 ] === identifier ) {
2021-02-26 12:21:42 +03:00
if ( isNaN ( this . prerelease [ 1 ] ) ) {
this . prerelease = [
2021-12-02 10:28:09 +03:00
identifier ,
2021-02-26 12:21:42 +03:00
0
] ;
}
} else {
this . prerelease = [
2021-12-02 10:28:09 +03:00
identifier ,
2021-02-26 12:21:42 +03:00
0
] ;
}
}
break ;
default :
2021-12-02 10:28:09 +03:00
throw new Error ( "invalid increment argument: " + release ) ;
2021-02-26 12:21:42 +03:00
}
this . format ( ) ;
this . raw = this . version ;
return this ;
}
toString() {
return this . version ;
}
}
2021-12-03 19:55:27 +03:00
function inc ( version5 , release , optionsOrLoose , identifier ) {
2021-09-01 16:11:55 +03:00
if ( typeof optionsOrLoose === "string" ) {
identifier = optionsOrLoose ;
optionsOrLoose = undefined ;
2021-02-26 12:21:42 +03:00
}
try {
2021-12-03 19:55:27 +03:00
return new SemVer ( version5 , optionsOrLoose ) . inc ( release , identifier ) . version ;
2021-02-26 12:21:42 +03:00
} catch ( er ) {
return null ;
}
}
2021-09-01 16:11:55 +03:00
function diff ( version1 , version2 , optionsOrLoose ) {
if ( eq ( version1 , version2 , optionsOrLoose ) ) {
2021-02-26 12:21:42 +03:00
return null ;
} else {
const v1 = parse4 ( version1 ) ;
const v2 = parse4 ( version2 ) ;
let prefix = "" ;
let defaultResult = null ;
if ( v1 && v2 ) {
if ( v1 . prerelease . length || v2 . prerelease . length ) {
prefix = "pre" ;
defaultResult = "prerelease" ;
}
for ( const key in v1 ) {
if ( key === "major" || key === "minor" || key === "patch" ) {
if ( v1 [ key ] !== v2 [ key ] ) {
return prefix + key ;
}
}
}
}
return defaultResult ;
}
}
const numeric = /^[0-9]+$/ ;
function compareIdentifiers ( a , b ) {
const anum = numeric . test ( a ) ;
const bnum = numeric . test ( b ) ;
if ( a === null || b === null ) throw "Comparison against null invalid" ;
if ( anum && bnum ) {
a = + a ;
b = + b ;
}
return a === b ? 0 : anum && ! bnum ? - 1 : bnum && ! anum ? 1 : a < b ? - 1 : 1 ;
}
function rcompareIdentifiers ( a , b ) {
return compareIdentifiers ( b , a ) ;
}
2021-09-01 16:11:55 +03:00
function major ( v , optionsOrLoose ) {
return new SemVer ( v , optionsOrLoose ) . major ;
2021-02-26 12:21:42 +03:00
}
2021-09-01 16:11:55 +03:00
function minor ( v , optionsOrLoose ) {
return new SemVer ( v , optionsOrLoose ) . minor ;
2021-02-26 12:21:42 +03:00
}
2021-09-01 16:11:55 +03:00
function patch ( v , optionsOrLoose ) {
return new SemVer ( v , optionsOrLoose ) . patch ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
function compare ( v1 , v2 , optionsOrLoose ) {
2021-09-01 16:11:55 +03:00
return new SemVer ( v1 , optionsOrLoose ) . compare ( new SemVer ( v2 , optionsOrLoose ) ) ;
2021-02-26 12:21:42 +03:00
}
function compareLoose ( a , b ) {
2021-12-03 19:55:27 +03:00
return compare ( a , b , true ) ;
2021-02-26 12:21:42 +03:00
}
function compareBuild ( a , b , loose ) {
var versionA = new SemVer ( a , loose ) ;
var versionB = new SemVer ( b , loose ) ;
return versionA . compare ( versionB ) || versionA . compareBuild ( versionB ) ;
}
2021-09-01 16:11:55 +03:00
function rcompare ( v1 , v2 , optionsOrLoose ) {
2021-12-03 19:55:27 +03:00
return compare ( v2 , v1 , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
}
2021-09-01 16:11:55 +03:00
function sort ( list , optionsOrLoose ) {
2021-02-26 12:21:42 +03:00
return list . sort ( ( a , b ) = > {
2021-09-01 16:11:55 +03:00
return compareBuild ( a , b , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
} ) ;
}
2021-09-01 16:11:55 +03:00
function rsort ( list , optionsOrLoose ) {
2021-02-26 12:21:42 +03:00
return list . sort ( ( a , b ) = > {
2021-09-01 16:11:55 +03:00
return compareBuild ( b , a , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
} ) ;
}
2021-09-01 16:11:55 +03:00
function gt ( v1 , v2 , optionsOrLoose ) {
2021-12-03 19:55:27 +03:00
return compare ( v1 , v2 , optionsOrLoose ) > 0 ;
2021-02-26 12:21:42 +03:00
}
2021-09-01 16:11:55 +03:00
function lt ( v1 , v2 , optionsOrLoose ) {
2021-12-03 19:55:27 +03:00
return compare ( v1 , v2 , optionsOrLoose ) < 0 ;
2021-02-26 12:21:42 +03:00
}
2021-09-01 16:11:55 +03:00
function eq ( v1 , v2 , optionsOrLoose ) {
2021-12-03 19:55:27 +03:00
return compare ( v1 , v2 , optionsOrLoose ) === 0 ;
2021-02-26 12:21:42 +03:00
}
2021-09-01 16:11:55 +03:00
function neq ( v1 , v2 , optionsOrLoose ) {
2021-12-03 19:55:27 +03:00
return compare ( v1 , v2 , optionsOrLoose ) !== 0 ;
2021-02-26 12:21:42 +03:00
}
2021-09-01 16:11:55 +03:00
function gte ( v1 , v2 , optionsOrLoose ) {
2021-12-03 19:55:27 +03:00
return compare ( v1 , v2 , optionsOrLoose ) >= 0 ;
2021-02-26 12:21:42 +03:00
}
2021-09-01 16:11:55 +03:00
function lte ( v1 , v2 , optionsOrLoose ) {
2021-12-03 19:55:27 +03:00
return compare ( v1 , v2 , optionsOrLoose ) <= 0 ;
2021-02-26 12:21:42 +03:00
}
2021-09-01 16:11:55 +03:00
function cmp ( v1 , operator , v2 , optionsOrLoose ) {
2021-02-26 12:21:42 +03:00
switch ( operator ) {
case "===" :
if ( typeof v1 === "object" ) v1 = v1 . version ;
if ( typeof v2 === "object" ) v2 = v2 . version ;
return v1 === v2 ;
case "!==" :
if ( typeof v1 === "object" ) v1 = v1 . version ;
if ( typeof v2 === "object" ) v2 = v2 . version ;
return v1 !== v2 ;
case "" :
case "=" :
case "==" :
2021-09-01 16:11:55 +03:00
return eq ( v1 , v2 , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
case "!=" :
2021-09-01 16:11:55 +03:00
return neq ( v1 , v2 , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
case ">" :
2021-09-01 16:11:55 +03:00
return gt ( v1 , v2 , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
case ">=" :
2021-09-01 16:11:55 +03:00
return gte ( v1 , v2 , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
case "<" :
2021-09-01 16:11:55 +03:00
return lt ( v1 , v2 , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
case "<=" :
2021-09-01 16:11:55 +03:00
return lte ( v1 , v2 , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
default :
throw new TypeError ( "Invalid operator: " + operator ) ;
}
}
const ANY = {
} ;
class Comparator {
2021-12-02 10:28:09 +03:00
constructor ( comp , optionsOrLoose ) {
if ( ! optionsOrLoose || typeof optionsOrLoose !== "object" ) {
optionsOrLoose = {
loose : ! ! optionsOrLoose ,
2021-02-26 12:21:42 +03:00
includePrerelease : false
} ;
}
2021-12-02 10:28:09 +03:00
if ( comp instanceof Comparator ) {
if ( comp . loose === ! ! optionsOrLoose . loose ) {
return comp ;
2021-02-26 12:21:42 +03:00
} else {
2021-12-02 10:28:09 +03:00
comp = comp . value ;
2021-02-26 12:21:42 +03:00
}
}
if ( ! ( this instanceof Comparator ) ) {
2021-12-02 10:28:09 +03:00
return new Comparator ( comp , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
this . options = optionsOrLoose ;
this . loose = ! ! optionsOrLoose . loose ;
this . parse ( comp ) ;
2021-02-26 12:21:42 +03:00
if ( this . semver === ANY ) {
this . value = "" ;
} else {
this . value = this . operator + this . semver . version ;
}
}
2021-12-02 10:28:09 +03:00
parse ( comp ) {
2021-02-26 12:21:42 +03:00
const r = this . options . loose ? re [ COMPARATORLOOSE ] : re [ COMPARATOR ] ;
2021-12-02 10:28:09 +03:00
const m = comp . match ( r ) ;
2021-09-01 16:11:55 +03:00
if ( ! m ) {
2021-12-02 10:28:09 +03:00
throw new TypeError ( "Invalid comparator: " + comp ) ;
2021-02-26 12:21:42 +03:00
}
2021-09-01 16:11:55 +03:00
const m1 = m [ 1 ] ;
this . operator = m1 !== undefined ? m1 : "" ;
2021-02-26 12:21:42 +03:00
if ( this . operator === "=" ) {
this . operator = "" ;
}
2021-09-01 16:11:55 +03:00
if ( ! m [ 2 ] ) {
2021-02-26 12:21:42 +03:00
this . semver = ANY ;
} else {
2021-09-01 16:11:55 +03:00
this . semver = new SemVer ( m [ 2 ] , this . options . loose ) ;
2021-02-26 12:21:42 +03:00
}
}
2021-12-03 19:55:27 +03:00
test ( version6 ) {
if ( this . semver === ANY || version6 === ANY ) {
2021-02-26 12:21:42 +03:00
return true ;
}
2021-12-03 19:55:27 +03:00
if ( typeof version6 === "string" ) {
version6 = new SemVer ( version6 , this . options ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
return cmp ( version6 , this . operator , this . semver , this . options ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
intersects ( comp , optionsOrLoose ) {
if ( ! ( comp instanceof Comparator ) ) {
2021-02-26 12:21:42 +03:00
throw new TypeError ( "a Comparator is required" ) ;
}
2021-12-02 10:28:09 +03:00
if ( ! optionsOrLoose || typeof optionsOrLoose !== "object" ) {
optionsOrLoose = {
loose : ! ! optionsOrLoose ,
2021-02-26 12:21:42 +03:00
includePrerelease : false
} ;
}
let rangeTmp ;
if ( this . operator === "" ) {
if ( this . value === "" ) {
return true ;
}
2021-12-02 10:28:09 +03:00
rangeTmp = new Range ( comp . value , optionsOrLoose ) ;
return satisfies ( this . value , rangeTmp , optionsOrLoose ) ;
} else if ( comp . operator === "" ) {
if ( comp . value === "" ) {
2021-02-26 12:21:42 +03:00
return true ;
}
2021-12-02 10:28:09 +03:00
rangeTmp = new Range ( this . value , optionsOrLoose ) ;
return satisfies ( comp . semver , rangeTmp , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
const sameDirectionIncreasing = ( this . operator === ">=" || this . operator === ">" ) && ( comp . operator === ">=" || comp . operator === ">" ) ;
const sameDirectionDecreasing = ( this . operator === "<=" || this . operator === "<" ) && ( comp . operator === "<=" || comp . operator === "<" ) ;
const sameSemVer = this . semver . version === comp . semver . version ;
const differentDirectionsInclusive = ( this . operator === ">=" || this . operator === "<=" ) && ( comp . operator === ">=" || comp . operator === "<=" ) ;
const oppositeDirectionsLessThan = cmp ( this . semver , "<" , comp . semver , optionsOrLoose ) && ( this . operator === ">=" || this . operator === ">" ) && ( comp . operator === "<=" || comp . operator === "<" ) ;
const oppositeDirectionsGreaterThan = cmp ( this . semver , ">" , comp . semver , optionsOrLoose ) && ( this . operator === "<=" || this . operator === "<" ) && ( comp . operator === ">=" || comp . operator === ">" ) ;
2021-02-26 12:21:42 +03:00
return sameDirectionIncreasing || sameDirectionDecreasing || sameSemVer && differentDirectionsInclusive || oppositeDirectionsLessThan || oppositeDirectionsGreaterThan ;
}
toString() {
return this . value ;
}
}
2021-09-01 16:11:55 +03:00
class Range {
2021-12-02 10:28:09 +03:00
constructor ( range1 , optionsOrLoose ) {
if ( ! optionsOrLoose || typeof optionsOrLoose !== "object" ) {
optionsOrLoose = {
loose : ! ! optionsOrLoose ,
2021-02-26 12:21:42 +03:00
includePrerelease : false
} ;
}
2021-10-21 08:12:50 +03:00
if ( range1 instanceof Range ) {
2021-12-02 10:28:09 +03:00
if ( range1 . loose === ! ! optionsOrLoose . loose && range1 . includePrerelease === ! ! optionsOrLoose . includePrerelease ) {
2021-10-21 08:12:50 +03:00
return range1 ;
2021-02-26 12:21:42 +03:00
} else {
2021-12-02 10:28:09 +03:00
return new Range ( range1 . raw , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
}
}
2021-10-21 08:12:50 +03:00
if ( range1 instanceof Comparator ) {
2021-12-02 10:28:09 +03:00
return new Range ( range1 . value , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
}
2021-09-01 16:11:55 +03:00
if ( ! ( this instanceof Range ) ) {
2021-12-02 10:28:09 +03:00
return new Range ( range1 , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
this . options = optionsOrLoose ;
this . loose = ! ! optionsOrLoose . loose ;
this . includePrerelease = ! ! optionsOrLoose . includePrerelease ;
2021-10-21 08:12:50 +03:00
this . raw = range1 ;
this . set = range1 . split ( /\s*\|\|\s*/ ) . map ( ( range ) = > this . parseRange ( range . trim ( ) )
2021-02-26 12:21:42 +03:00
) . filter ( ( c ) = > {
return c . length ;
} ) ;
if ( ! this . set . length ) {
2021-10-21 08:12:50 +03:00
throw new TypeError ( "Invalid SemVer Range: " + range1 ) ;
2021-02-26 12:21:42 +03:00
}
this . format ( ) ;
}
format() {
this . range = this . set . map ( ( comps ) = > comps . join ( " " ) . trim ( )
) . join ( "||" ) . trim ( ) ;
return this . range ;
}
2021-12-02 10:28:09 +03:00
parseRange ( range ) {
2021-02-26 12:21:42 +03:00
const loose = this . options . loose ;
2021-12-02 10:28:09 +03:00
range = range . trim ( ) ;
2021-02-26 12:21:42 +03:00
const hr = loose ? re [ HYPHENRANGELOOSE ] : re [ HYPHENRANGE ] ;
2021-12-02 10:28:09 +03:00
range = range . replace ( hr , hyphenReplace ) ;
range = range . replace ( re [ COMPARATORTRIM ] , comparatorTrimReplace ) ;
range = range . replace ( re [ TILDETRIM ] , tildeTrimReplace ) ;
range = range . replace ( re [ CARETTRIM ] , caretTrimReplace ) ;
range = range . split ( /\s+/ ) . join ( " " ) ;
2021-02-26 12:21:42 +03:00
const compRe = loose ? re [ COMPARATORLOOSE ] : re [ COMPARATOR ] ;
2021-12-02 10:28:09 +03:00
let set = range . split ( " " ) . map ( ( comp ) = > parseComparator ( comp , this . options )
2021-02-26 12:21:42 +03:00
) . join ( " " ) . split ( /\s+/ ) ;
if ( this . options . loose ) {
2021-09-01 16:11:55 +03:00
set = set . filter ( ( comp ) = > {
return ! ! comp . match ( compRe ) ;
2021-02-26 12:21:42 +03:00
} ) ;
}
2021-09-01 16:11:55 +03:00
return set . map ( ( comp ) = > new Comparator ( comp , this . options )
2021-02-26 12:21:42 +03:00
) ;
}
2021-12-03 19:55:27 +03:00
test ( version7 ) {
if ( typeof version7 === "string" ) {
version7 = new SemVer ( version7 , this . options ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
for ( var i31 = 0 ; i31 < this . set . length ; i31 ++ ) {
if ( testSet ( this . set [ i31 ] , version7 , this . options ) ) {
2021-02-26 12:21:42 +03:00
return true ;
}
}
return false ;
}
2021-12-02 10:28:09 +03:00
intersects ( range , optionsOrLoose ) {
if ( ! ( range instanceof Range ) ) {
2021-02-26 12:21:42 +03:00
throw new TypeError ( "a Range is required" ) ;
}
return this . set . some ( ( thisComparators ) = > {
2021-12-02 10:28:09 +03:00
return isSatisfiable ( thisComparators , optionsOrLoose ) && range . set . some ( ( rangeComparators ) = > {
return isSatisfiable ( rangeComparators , optionsOrLoose ) && thisComparators . every ( ( thisComparator ) = > {
2021-02-26 12:21:42 +03:00
return rangeComparators . every ( ( rangeComparator ) = > {
2021-12-02 10:28:09 +03:00
return thisComparator . intersects ( rangeComparator , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
} ) ;
} ) ;
} ) ;
} ) ;
}
toString() {
return this . range ;
}
}
2021-12-03 19:55:27 +03:00
function testSet ( set , version8 , options ) {
for ( let i32 = 0 ; i32 < set . length ; i32 ++ ) {
if ( ! set [ i32 ] . test ( version8 ) ) {
2021-02-26 12:21:42 +03:00
return false ;
}
}
2021-12-03 19:55:27 +03:00
if ( version8 . prerelease . length && ! options . includePrerelease ) {
for ( let i33 = 0 ; i33 < set . length ; i33 ++ ) {
if ( set [ i33 ] . semver === ANY ) {
2021-02-26 12:21:42 +03:00
continue ;
}
2021-12-03 19:55:27 +03:00
if ( set [ i33 ] . semver . prerelease . length > 0 ) {
const allowed = set [ i33 ] . semver ;
if ( allowed . major === version8 . major && allowed . minor === version8 . minor && allowed . patch === version8 . patch ) {
2021-02-26 12:21:42 +03:00
return true ;
}
}
}
return false ;
}
return true ;
}
2021-09-01 16:11:55 +03:00
function isSatisfiable ( comparators , options ) {
2021-02-26 12:21:42 +03:00
let result = true ;
const remainingComparators = comparators . slice ( ) ;
let testComparator = remainingComparators . pop ( ) ;
while ( result && remainingComparators . length ) {
result = remainingComparators . every ( ( otherComparator ) = > {
2021-09-01 16:11:55 +03:00
return testComparator ? . intersects ( otherComparator , options ) ;
2021-02-26 12:21:42 +03:00
} ) ;
testComparator = remainingComparators . pop ( ) ;
}
return result ;
}
2021-09-01 16:11:55 +03:00
function toComparators ( range , optionsOrLoose ) {
return new Range ( range , optionsOrLoose ) . set . map ( ( comp ) = > {
return comp . map ( ( c ) = > c . value
2021-02-26 12:21:42 +03:00
) . join ( " " ) . trim ( ) . split ( " " ) ;
} ) ;
}
2021-09-01 16:11:55 +03:00
function parseComparator ( comp , options ) {
comp = replaceCarets ( comp , options ) ;
comp = replaceTildes ( comp , options ) ;
comp = replaceXRanges ( comp , options ) ;
comp = replaceStars ( comp , options ) ;
return comp ;
2021-02-26 12:21:42 +03:00
}
function isX ( id ) {
return ! id || id . toLowerCase ( ) === "x" || id === "*" ;
}
2021-12-02 10:28:09 +03:00
function replaceTildes ( comp1 , options ) {
return comp1 . trim ( ) . split ( /\s+/ ) . map ( ( comp ) = > replaceTilde ( comp , options )
2021-02-26 12:21:42 +03:00
) . join ( " " ) ;
}
2021-09-01 16:11:55 +03:00
function replaceTilde ( comp , options ) {
const r = options . loose ? re [ TILDELOOSE ] : re [ TILDE ] ;
return comp . replace ( r , ( _ , M , m , p , pr ) = > {
2021-02-26 12:21:42 +03:00
let ret ;
if ( isX ( M ) ) {
ret = "" ;
2021-09-01 16:11:55 +03:00
} else if ( isX ( m ) ) {
2021-02-26 12:21:42 +03:00
ret = ">=" + M + ".0.0 <" + ( + M + 1 ) + ".0.0" ;
} else if ( isX ( p ) ) {
2021-09-01 16:11:55 +03:00
ret = ">=" + M + "." + m + ".0 <" + M + "." + ( + m + 1 ) + ".0" ;
2021-02-26 12:21:42 +03:00
} else if ( pr ) {
2021-09-01 16:11:55 +03:00
ret = ">=" + M + "." + m + "." + p + "-" + pr + " <" + M + "." + ( + m + 1 ) + ".0" ;
2021-02-26 12:21:42 +03:00
} else {
2021-09-01 16:11:55 +03:00
ret = ">=" + M + "." + m + "." + p + " <" + M + "." + ( + m + 1 ) + ".0" ;
2021-02-26 12:21:42 +03:00
}
return ret ;
} ) ;
}
2021-12-02 10:28:09 +03:00
function replaceCarets ( comp2 , options ) {
return comp2 . trim ( ) . split ( /\s+/ ) . map ( ( comp ) = > replaceCaret ( comp , options )
2021-02-26 12:21:42 +03:00
) . join ( " " ) ;
}
2021-09-01 16:11:55 +03:00
function replaceCaret ( comp , options ) {
const r = options . loose ? re [ CARETLOOSE ] : re [ CARET ] ;
return comp . replace ( r , ( _ , M , m , p , pr ) = > {
2021-02-26 12:21:42 +03:00
let ret ;
if ( isX ( M ) ) {
ret = "" ;
2021-09-01 16:11:55 +03:00
} else if ( isX ( m ) ) {
2021-02-26 12:21:42 +03:00
ret = ">=" + M + ".0.0 <" + ( + M + 1 ) + ".0.0" ;
} else if ( isX ( p ) ) {
if ( M === "0" ) {
2021-09-01 16:11:55 +03:00
ret = ">=" + M + "." + m + ".0 <" + M + "." + ( + m + 1 ) + ".0" ;
2021-02-26 12:21:42 +03:00
} else {
2021-09-01 16:11:55 +03:00
ret = ">=" + M + "." + m + ".0 <" + ( + M + 1 ) + ".0.0" ;
2021-02-26 12:21:42 +03:00
}
} else if ( pr ) {
if ( M === "0" ) {
2021-09-01 16:11:55 +03:00
if ( m === "0" ) {
ret = ">=" + M + "." + m + "." + p + "-" + pr + " <" + M + "." + m + "." + ( + p + 1 ) ;
2021-02-26 12:21:42 +03:00
} else {
2021-09-01 16:11:55 +03:00
ret = ">=" + M + "." + m + "." + p + "-" + pr + " <" + M + "." + ( + m + 1 ) + ".0" ;
2021-02-26 12:21:42 +03:00
}
} else {
2021-09-01 16:11:55 +03:00
ret = ">=" + M + "." + m + "." + p + "-" + pr + " <" + ( + M + 1 ) + ".0.0" ;
2021-02-26 12:21:42 +03:00
}
} else {
if ( M === "0" ) {
2021-09-01 16:11:55 +03:00
if ( m === "0" ) {
ret = ">=" + M + "." + m + "." + p + " <" + M + "." + m + "." + ( + p + 1 ) ;
2021-02-26 12:21:42 +03:00
} else {
2021-09-01 16:11:55 +03:00
ret = ">=" + M + "." + m + "." + p + " <" + M + "." + ( + m + 1 ) + ".0" ;
2021-02-26 12:21:42 +03:00
}
} else {
2021-09-01 16:11:55 +03:00
ret = ">=" + M + "." + m + "." + p + " <" + ( + M + 1 ) + ".0.0" ;
2021-02-26 12:21:42 +03:00
}
}
return ret ;
} ) ;
}
2021-12-02 10:28:09 +03:00
function replaceXRanges ( comp3 , options ) {
return comp3 . split ( /\s+/ ) . map ( ( comp ) = > replaceXRange ( comp , options )
2021-02-26 12:21:42 +03:00
) . join ( " " ) ;
}
2021-09-01 16:11:55 +03:00
function replaceXRange ( comp , options ) {
comp = comp . trim ( ) ;
const r = options . loose ? re [ XRANGELOOSE ] : re [ XRANGE ] ;
return comp . replace ( r , ( ret , gtlt , M , m , p , pr ) = > {
2021-02-26 12:21:42 +03:00
const xM = isX ( M ) ;
2021-09-01 16:11:55 +03:00
const xm = xM || isX ( m ) ;
2021-02-26 12:21:42 +03:00
const xp = xm || isX ( p ) ;
const anyX = xp ;
if ( gtlt === "=" && anyX ) {
gtlt = "" ;
}
if ( xM ) {
if ( gtlt === ">" || gtlt === "<" ) {
ret = "<0.0.0" ;
} else {
ret = "*" ;
}
} else if ( gtlt && anyX ) {
if ( xm ) {
2021-09-01 16:11:55 +03:00
m = 0 ;
2021-02-26 12:21:42 +03:00
}
p = 0 ;
if ( gtlt === ">" ) {
gtlt = ">=" ;
if ( xm ) {
M = + M + 1 ;
2021-09-01 16:11:55 +03:00
m = 0 ;
2021-02-26 12:21:42 +03:00
p = 0 ;
} else {
2021-09-01 16:11:55 +03:00
m = + m + 1 ;
2021-02-26 12:21:42 +03:00
p = 0 ;
}
} else if ( gtlt === "<=" ) {
gtlt = "<" ;
if ( xm ) {
M = + M + 1 ;
} else {
2021-09-01 16:11:55 +03:00
m = + m + 1 ;
2021-02-26 12:21:42 +03:00
}
}
2021-09-01 16:11:55 +03:00
ret = gtlt + M + "." + m + "." + p ;
2021-02-26 12:21:42 +03:00
} else if ( xm ) {
ret = ">=" + M + ".0.0 <" + ( + M + 1 ) + ".0.0" ;
} else if ( xp ) {
2021-09-01 16:11:55 +03:00
ret = ">=" + M + "." + m + ".0 <" + M + "." + ( + m + 1 ) + ".0" ;
2021-02-26 12:21:42 +03:00
}
return ret ;
} ) ;
}
2021-09-01 16:11:55 +03:00
function replaceStars ( comp , options ) {
return comp . trim ( ) . replace ( re [ STAR ] , "" ) ;
2021-02-26 12:21:42 +03:00
}
function hyphenReplace ( $0 , from , fM , fm , fp , fpr , fb , to , tM , tm , tp , tpr , tb ) {
if ( isX ( fM ) ) {
from = "" ;
} else if ( isX ( fm ) ) {
from = ">=" + fM + ".0.0" ;
} else if ( isX ( fp ) ) {
from = ">=" + fM + "." + fm + ".0" ;
} else {
from = ">=" + from ;
}
if ( isX ( tM ) ) {
to = "" ;
} else if ( isX ( tm ) ) {
to = "<" + ( + tM + 1 ) + ".0.0" ;
} else if ( isX ( tp ) ) {
to = "<" + tM + "." + ( + tm + 1 ) + ".0" ;
} else if ( tpr ) {
to = "<=" + tM + "." + tm + "." + tp + "-" + tpr ;
} else {
to = "<=" + to ;
}
return ( from + " " + to ) . trim ( ) ;
}
2021-12-03 19:55:27 +03:00
function satisfies ( version9 , range , optionsOrLoose ) {
2021-02-26 12:21:42 +03:00
try {
2021-09-01 16:11:55 +03:00
range = new Range ( range , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
} catch ( er ) {
return false ;
}
2021-12-03 19:55:27 +03:00
return range . test ( version9 ) ;
2021-02-26 12:21:42 +03:00
}
2021-09-01 16:11:55 +03:00
function maxSatisfying ( versions , range , optionsOrLoose ) {
2021-02-26 12:21:42 +03:00
var max = null ;
var maxSV = null ;
try {
2021-09-01 16:11:55 +03:00
var rangeObj = new Range ( range , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
} catch ( er ) {
return null ;
}
versions . forEach ( ( v ) = > {
if ( rangeObj . test ( v ) ) {
if ( ! max || maxSV && maxSV . compare ( v ) === - 1 ) {
max = v ;
2021-09-01 16:11:55 +03:00
maxSV = new SemVer ( max , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
}
}
} ) ;
return max ;
}
2021-09-01 16:11:55 +03:00
function minSatisfying ( versions , range , optionsOrLoose ) {
2021-02-26 12:21:42 +03:00
var min = null ;
var minSV = null ;
try {
2021-09-01 16:11:55 +03:00
var rangeObj = new Range ( range , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
} catch ( er ) {
return null ;
}
versions . forEach ( ( v ) = > {
if ( rangeObj . test ( v ) ) {
if ( ! min || minSV . compare ( v ) === 1 ) {
min = v ;
2021-09-01 16:11:55 +03:00
minSV = new SemVer ( min , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
}
}
} ) ;
return min ;
}
2021-09-01 16:11:55 +03:00
function minVersion ( range , optionsOrLoose ) {
range = new Range ( range , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
var minver = new SemVer ( "0.0.0" ) ;
2021-09-01 16:11:55 +03:00
if ( range . test ( minver ) ) {
2021-02-26 12:21:42 +03:00
return minver ;
}
minver = new SemVer ( "0.0.0-0" ) ;
2021-09-01 16:11:55 +03:00
if ( range . test ( minver ) ) {
2021-02-26 12:21:42 +03:00
return minver ;
}
minver = null ;
2021-12-03 19:55:27 +03:00
for ( var i34 = 0 ; i34 < range . set . length ; ++ i34 ) {
var comparators = range . set [ i34 ] ;
2021-02-26 12:21:42 +03:00
comparators . forEach ( ( comparator ) = > {
var compver = new SemVer ( comparator . semver . version ) ;
switch ( comparator . operator ) {
case ">" :
if ( compver . prerelease . length === 0 ) {
compver . patch ++ ;
} else {
compver . prerelease . push ( 0 ) ;
}
compver . raw = compver . format ( ) ;
case "" :
case ">=" :
if ( ! minver || gt ( minver , compver ) ) {
minver = compver ;
}
break ;
case "<" :
2021-10-08 10:47:01 +03:00
case "<=" :
break ;
2021-02-26 12:21:42 +03:00
default :
throw new Error ( "Unexpected operation: " + comparator . operator ) ;
}
} ) ;
}
2021-09-01 16:11:55 +03:00
if ( minver && range . test ( minver ) ) {
2021-02-26 12:21:42 +03:00
return minver ;
}
return null ;
}
2021-09-01 16:11:55 +03:00
function validRange ( range , optionsOrLoose ) {
2021-02-26 12:21:42 +03:00
try {
2021-09-01 16:11:55 +03:00
if ( range === null ) return null ;
return new Range ( range , optionsOrLoose ) . range || "*" ;
2021-02-26 12:21:42 +03:00
} catch ( er ) {
return null ;
}
}
2021-12-03 19:55:27 +03:00
function ltr ( version10 , range , optionsOrLoose ) {
return outside ( version10 , range , "<" , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
function gtr ( version11 , range , optionsOrLoose ) {
return outside ( version11 , range , ">" , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
function outside ( version12 , range , hilo , optionsOrLoose ) {
version12 = new SemVer ( version12 , optionsOrLoose ) ;
2021-09-01 16:11:55 +03:00
range = new Range ( range , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
let gtfn ;
let ltefn ;
let ltfn ;
2021-09-01 16:11:55 +03:00
let comp ;
2021-02-26 12:21:42 +03:00
let ecomp ;
switch ( hilo ) {
case ">" :
gtfn = gt ;
ltefn = lte ;
ltfn = lt ;
2021-09-01 16:11:55 +03:00
comp = ">" ;
2021-02-26 12:21:42 +03:00
ecomp = ">=" ;
break ;
case "<" :
gtfn = lt ;
ltefn = gte ;
ltfn = gt ;
2021-09-01 16:11:55 +03:00
comp = "<" ;
2021-02-26 12:21:42 +03:00
ecomp = "<=" ;
break ;
default :
throw new TypeError ( 'Must provide a hilo val of "<" or ">"' ) ;
}
2021-12-03 19:55:27 +03:00
if ( satisfies ( version12 , range , optionsOrLoose ) ) {
2021-02-26 12:21:42 +03:00
return false ;
}
2021-12-03 19:55:27 +03:00
for ( let i35 = 0 ; i35 < range . set . length ; ++ i35 ) {
const comparators = range . set [ i35 ] ;
2021-02-26 12:21:42 +03:00
let high = null ;
let low = null ;
comparators . forEach ( ( comparator ) = > {
if ( comparator . semver === ANY ) {
comparator = new Comparator ( ">=0.0.0" ) ;
}
high = high || comparator ;
low = low || comparator ;
2021-09-01 16:11:55 +03:00
if ( gtfn ( comparator . semver , high . semver , optionsOrLoose ) ) {
2021-02-26 12:21:42 +03:00
high = comparator ;
2021-09-01 16:11:55 +03:00
} else if ( ltfn ( comparator . semver , low . semver , optionsOrLoose ) ) {
2021-02-26 12:21:42 +03:00
low = comparator ;
}
} ) ;
if ( high === null || low === null ) return true ;
2021-09-01 16:11:55 +03:00
if ( high . operator === comp || high . operator === ecomp ) {
2021-02-26 12:21:42 +03:00
return false ;
}
2021-12-03 19:55:27 +03:00
if ( ( ! low . operator || low . operator === comp ) && ltefn ( version12 , low . semver ) ) {
2021-02-26 12:21:42 +03:00
return false ;
2021-12-03 19:55:27 +03:00
} else if ( low . operator === ecomp && ltfn ( version12 , low . semver ) ) {
2021-02-26 12:21:42 +03:00
return false ;
}
}
return true ;
}
2021-12-03 19:55:27 +03:00
function prerelease ( version13 , optionsOrLoose ) {
var parsed = parse4 ( version13 , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
return parsed && parsed . prerelease . length ? parsed.prerelease : null ;
}
2021-09-01 16:11:55 +03:00
function intersects ( range1 , range2 , optionsOrLoose ) {
range1 = new Range ( range1 , optionsOrLoose ) ;
range2 = new Range ( range2 , optionsOrLoose ) ;
return range1 . intersects ( range2 ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
function coerce ( version14 , optionsOrLoose ) {
if ( version14 instanceof SemVer ) {
return version14 ;
2021-02-26 12:21:42 +03:00
}
2021-12-03 19:55:27 +03:00
if ( typeof version14 !== "string" ) {
2021-02-26 12:21:42 +03:00
return null ;
}
2021-12-03 19:55:27 +03:00
const match = version14 . match ( re [ COERCE ] ) ;
2021-02-26 12:21:42 +03:00
if ( match == null ) {
return null ;
}
2021-09-01 16:11:55 +03:00
return parse4 ( match [ 1 ] + "." + ( match [ 2 ] || "0" ) + "." + ( match [ 3 ] || "0" ) , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-08 10:47:01 +03:00
const mod7 = {
SEMVER_SPEC_VERSION : SEMVER_SPEC_VERSION ,
parse : parse4 ,
valid : valid ,
clean : clean ,
SemVer : SemVer ,
inc : inc ,
diff : diff ,
compareIdentifiers : compareIdentifiers ,
rcompareIdentifiers : rcompareIdentifiers ,
major : major ,
minor : minor ,
patch : patch ,
2021-12-03 19:55:27 +03:00
compare : compare ,
2021-10-08 10:47:01 +03:00
compareLoose : compareLoose ,
compareBuild : compareBuild ,
rcompare : rcompare ,
sort : sort ,
rsort : rsort ,
gt : gt ,
lt : lt ,
eq : eq ,
neq : neq ,
gte : gte ,
lte : lte ,
cmp : cmp ,
Comparator : Comparator ,
Range : Range ,
toComparators : toComparators ,
satisfies : satisfies ,
maxSatisfying : maxSatisfying ,
minSatisfying : minSatisfying ,
minVersion : minVersion ,
validRange : validRange ,
ltr : ltr ,
gtr : gtr ,
outside : outside ,
prerelease : prerelease ,
intersects : intersects ,
coerce : coerce ,
default : SemVer
} ;
2021-12-03 19:55:27 +03:00
const version = "1.11.0" ;
2021-02-26 12:21:42 +03:00
const TaskName_AST = {
"moduleName" : "dnit.manifest" ,
"decl" : {
"annotations" : [ ] ,
"type_" : {
"kind" : "newtype_" ,
"value" : {
"typeParams" : [ ] ,
"default" : {
"kind" : "nothing"
} ,
"typeExpr" : {
"typeRef" : {
"kind" : "primitive" ,
"value" : "String"
} ,
"parameters" : [ ]
}
}
} ,
"name" : "TaskName" ,
"version" : {
"kind" : "nothing"
}
}
} ;
const TrackedFileName_AST = {
"moduleName" : "dnit.manifest" ,
"decl" : {
"annotations" : [ ] ,
"type_" : {
"kind" : "newtype_" ,
"value" : {
"typeParams" : [ ] ,
"default" : {
"kind" : "nothing"
} ,
"typeExpr" : {
"typeRef" : {
"kind" : "primitive" ,
"value" : "String"
} ,
"parameters" : [ ]
}
}
} ,
"name" : "TrackedFileName" ,
"version" : {
"kind" : "nothing"
}
}
} ;
const TrackedFileHash_AST = {
"moduleName" : "dnit.manifest" ,
"decl" : {
"annotations" : [ ] ,
"type_" : {
"kind" : "newtype_" ,
"value" : {
"typeParams" : [ ] ,
"default" : {
"kind" : "nothing"
} ,
"typeExpr" : {
"typeRef" : {
"kind" : "primitive" ,
"value" : "String"
} ,
"parameters" : [ ]
}
}
} ,
"name" : "TrackedFileHash" ,
"version" : {
"kind" : "nothing"
}
}
} ;
const Timestamp_AST = {
"moduleName" : "dnit.manifest" ,
"decl" : {
"annotations" : [ ] ,
"type_" : {
"kind" : "newtype_" ,
"value" : {
"typeParams" : [ ] ,
"default" : {
"kind" : "nothing"
} ,
"typeExpr" : {
"typeRef" : {
"kind" : "primitive" ,
"value" : "String"
} ,
"parameters" : [ ]
}
}
} ,
"name" : "Timestamp" ,
"version" : {
"kind" : "nothing"
}
}
} ;
const TaskData_AST = {
"moduleName" : "dnit.manifest" ,
"decl" : {
"annotations" : [ ] ,
"type_" : {
"kind" : "struct_" ,
"value" : {
"typeParams" : [ ] ,
"fields" : [
{
"annotations" : [ ] ,
"serializedName" : "lastExecution" ,
"default" : {
"kind" : "just" ,
"value" : null
} ,
"name" : "lastExecution" ,
"typeExpr" : {
"typeRef" : {
"kind" : "primitive" ,
"value" : "Nullable"
} ,
"parameters" : [
{
"typeRef" : {
"kind" : "reference" ,
"value" : {
"moduleName" : "dnit.manifest" ,
"name" : "Timestamp"
}
} ,
"parameters" : [ ]
}
]
}
} ,
{
"annotations" : [ ] ,
"serializedName" : "trackedFiles" ,
"default" : {
"kind" : "nothing"
} ,
"name" : "trackedFiles" ,
"typeExpr" : {
"typeRef" : {
"kind" : "reference" ,
"value" : {
"moduleName" : "sys.types" ,
"name" : "Map"
}
} ,
"parameters" : [
{
"typeRef" : {
"kind" : "reference" ,
"value" : {
"moduleName" : "dnit.manifest" ,
"name" : "TrackedFileName"
}
} ,
"parameters" : [ ]
} ,
{
"typeRef" : {
"kind" : "reference" ,
"value" : {
"moduleName" : "dnit.manifest" ,
"name" : "TrackedFileData"
}
} ,
"parameters" : [ ]
}
]
}
}
]
}
} ,
"name" : "TaskData" ,
"version" : {
"kind" : "nothing"
}
}
} ;
const TrackedFileData_AST = {
"moduleName" : "dnit.manifest" ,
"decl" : {
"annotations" : [ ] ,
"type_" : {
"kind" : "struct_" ,
"value" : {
"typeParams" : [ ] ,
"fields" : [
{
"annotations" : [ ] ,
"serializedName" : "hash" ,
"default" : {
"kind" : "nothing"
} ,
"name" : "hash" ,
"typeExpr" : {
"typeRef" : {
"kind" : "reference" ,
"value" : {
"moduleName" : "dnit.manifest" ,
"name" : "TrackedFileHash"
}
} ,
"parameters" : [ ]
}
} ,
{
"annotations" : [ ] ,
"serializedName" : "timestamp" ,
"default" : {
"kind" : "nothing"
} ,
"name" : "timestamp" ,
"typeExpr" : {
"typeRef" : {
"kind" : "reference" ,
"value" : {
"moduleName" : "dnit.manifest" ,
"name" : "Timestamp"
}
} ,
"parameters" : [ ]
}
}
]
}
} ,
"name" : "TrackedFileData" ,
"version" : {
"kind" : "nothing"
}
}
} ;
const Manifest_AST = {
"moduleName" : "dnit.manifest" ,
"decl" : {
"annotations" : [ ] ,
"type_" : {
"kind" : "struct_" ,
"value" : {
"typeParams" : [ ] ,
"fields" : [
{
"annotations" : [ ] ,
"serializedName" : "tasks" ,
"default" : {
"kind" : "just" ,
"value" : [ ]
} ,
"name" : "tasks" ,
"typeExpr" : {
"typeRef" : {
"kind" : "reference" ,
"value" : {
"moduleName" : "sys.types" ,
"name" : "Map"
}
} ,
"parameters" : [
{
"typeRef" : {
"kind" : "reference" ,
"value" : {
"moduleName" : "dnit.manifest" ,
"name" : "TaskName"
}
} ,
"parameters" : [ ]
} ,
{
"typeRef" : {
"kind" : "reference" ,
"value" : {
"moduleName" : "dnit.manifest" ,
"name" : "TaskData"
}
} ,
"parameters" : [ ]
}
]
}
}
]
}
} ,
"name" : "Manifest" ,
"version" : {
"kind" : "nothing"
}
}
} ;
const _AST_MAP = {
"dnit.manifest.TaskName" : TaskName_AST ,
"dnit.manifest.TrackedFileName" : TrackedFileName_AST ,
"dnit.manifest.TrackedFileHash" : TrackedFileHash_AST ,
"dnit.manifest.Timestamp" : Timestamp_AST ,
"dnit.manifest.TaskData" : TaskData_AST ,
"dnit.manifest.TrackedFileData" : TrackedFileData_AST ,
"dnit.manifest.Manifest" : Manifest_AST
} ;
function isEnum ( union ) {
for ( let field of union . fields ) {
if ( ! isVoid ( field . typeExpr ) ) {
return false ;
}
}
return true ;
}
function isVoid ( texpr ) {
if ( texpr . typeRef . kind === "primitive" ) {
return texpr . typeRef . value === "Void" ;
}
return false ;
}
2021-10-08 10:47:01 +03:00
Symbol ( ) ;
Symbol ( ) ;
Symbol ( ) ;
Symbol ( ) ;
2021-02-26 12:21:42 +03:00
function asJsonObject ( jv ) {
if ( jv instanceof Object && ! ( jv instanceof Array ) ) {
return jv ;
}
return undefined ;
}
function asJsonArray ( jv ) {
if ( jv instanceof Array ) {
return jv ;
}
return undefined ;
}
2021-09-01 16:11:55 +03:00
function jsonParseException ( message ) {
2021-02-26 12:21:42 +03:00
const context = [ ] ;
let createContextString = ( ) = > {
const rcontext = context . slice ( 0 ) ;
rcontext . push ( '$' ) ;
rcontext . reverse ( ) ;
return rcontext . join ( '.' ) ;
} ;
return {
kind : 'JsonParseException' ,
getMessage ( ) {
2021-09-01 16:11:55 +03:00
return message + ' at ' + createContextString ( ) ;
2021-02-26 12:21:42 +03:00
} ,
pushField ( fieldName ) {
context . push ( fieldName ) ;
} ,
pushIndex ( index ) {
context . push ( '[' + index + ']' ) ;
} ,
toString ( ) {
return this . getMessage ( ) ;
}
} ;
}
function isJsonParseException ( exception ) {
return exception . kind === 'JsonParseException' ;
}
function buildJsonBinding ( dresolver , texpr , boundTypeParams ) {
if ( texpr . typeRef . kind === "primitive" ) {
return primitiveJsonBinding ( dresolver , texpr . typeRef . value , texpr . parameters , boundTypeParams ) ;
} else if ( texpr . typeRef . kind === "reference" ) {
const ast = dresolver ( texpr . typeRef . value ) ;
if ( ast . decl . type_ . kind === "struct_" ) {
return structJsonBinding ( dresolver , ast . decl . type_ . value , texpr . parameters , boundTypeParams ) ;
} else if ( ast . decl . type_ . kind === "union_" ) {
const union = ast . decl . type_ . value ;
if ( isEnum ( union ) ) {
return enumJsonBinding ( dresolver , union , texpr . parameters , boundTypeParams ) ;
} else {
return unionJsonBinding ( dresolver , union , texpr . parameters , boundTypeParams ) ;
}
} else if ( ast . decl . type_ . kind === "newtype_" ) {
return newtypeJsonBinding ( dresolver , ast . decl . type_ . value , texpr . parameters , boundTypeParams ) ;
} else if ( ast . decl . type_ . kind === "type_" ) {
return typedefJsonBinding ( dresolver , ast . decl . type_ . value , texpr . parameters , boundTypeParams ) ;
}
} else if ( texpr . typeRef . kind === "typeParam" ) {
return boundTypeParams [ texpr . typeRef . value ] ;
}
throw new Error ( "buildJsonBinding : unimplemented ADL type" ) ;
}
function primitiveJsonBinding ( dresolver , ptype , params , boundTypeParams ) {
if ( ptype === "String" ) {
return identityJsonBinding ( "a string" , ( v ) = > typeof v === 'string'
) ;
} else if ( ptype === "Int8" ) {
return identityJsonBinding ( "a number" , ( v ) = > typeof v === 'number'
) ;
} else if ( ptype === "Void" ) {
return identityJsonBinding ( "a null" , ( v ) = > v === null
) ;
} else if ( ptype === "Bool" ) {
return identityJsonBinding ( "a bool" , ( v ) = > typeof v === 'boolean'
) ;
} else if ( ptype === "Int8" ) {
return identityJsonBinding ( "a number" , ( v ) = > typeof v === 'number'
) ;
} else if ( ptype === "Int16" ) {
return identityJsonBinding ( "a number" , ( v ) = > typeof v === 'number'
) ;
} else if ( ptype === "Int32" ) {
return identityJsonBinding ( "a number" , ( v ) = > typeof v === 'number'
) ;
} else if ( ptype === "Int64" ) {
return identityJsonBinding ( "a number" , ( v ) = > typeof v === 'number'
) ;
} else if ( ptype === "Word8" ) {
return identityJsonBinding ( "a number" , ( v ) = > typeof v === 'number'
) ;
} else if ( ptype === "Word16" ) {
return identityJsonBinding ( "a number" , ( v ) = > typeof v === 'number'
) ;
} else if ( ptype === "Word32" ) {
return identityJsonBinding ( "a number" , ( v ) = > typeof v === 'number'
) ;
} else if ( ptype === "Word64" ) {
return identityJsonBinding ( "a number" , ( v ) = > typeof v === 'number'
) ;
} else if ( ptype === "Float" ) {
return identityJsonBinding ( "a number" , ( v ) = > typeof v === 'number'
) ;
} else if ( ptype === "Double" ) {
return identityJsonBinding ( "a number" , ( v ) = > typeof v === 'number'
) ;
} else if ( ptype === "Json" ) {
return identityJsonBinding ( "a json value" , ( _v ) = > true
) ;
} else if ( ptype === "Bytes" ) {
return bytesJsonBinding ( ) ;
} else if ( ptype === "Vector" ) {
return vectorJsonBinding ( dresolver , params [ 0 ] , boundTypeParams ) ;
} else if ( ptype === "StringMap" ) {
return stringMapJsonBinding ( dresolver , params [ 0 ] , boundTypeParams ) ;
} else if ( ptype === "Nullable" ) {
return nullableJsonBinding ( dresolver , params [ 0 ] , boundTypeParams ) ;
} else throw new Error ( "Unimplemented json binding for primitive " + ptype ) ;
}
function identityJsonBinding ( expected , predicate ) {
function toJson ( v ) {
return v ;
}
function fromJson ( json ) {
if ( ! predicate ( json ) ) {
throw jsonParseException ( "expected " + expected ) ;
}
return json ;
}
return {
toJson ,
fromJson
} ;
}
function bytesJsonBinding() {
function toJson ( v ) {
throw new Error ( "bytesJsonBinding not implemented" ) ;
}
function fromJson ( json ) {
if ( typeof json != 'string' ) {
throw jsonParseException ( 'expected a string' ) ;
}
throw new Error ( "bytesJsonBinding not implemented" ) ;
}
return {
toJson ,
fromJson
} ;
}
function vectorJsonBinding ( dresolver , texpr , boundTypeParams ) {
const elementBinding = once ( ( ) = > buildJsonBinding ( dresolver , texpr , boundTypeParams )
) ;
function toJson ( v ) {
return v . map ( elementBinding ( ) . toJson ) ;
}
function fromJson ( json ) {
const jarr = asJsonArray ( json ) ;
if ( jarr == undefined ) {
throw jsonParseException ( 'expected an array' ) ;
}
let result = [ ] ;
2021-12-03 19:55:27 +03:00
jarr . forEach ( ( eljson , i36 ) = > {
2021-02-26 12:21:42 +03:00
try {
result . push ( elementBinding ( ) . fromJson ( eljson ) ) ;
} catch ( e ) {
if ( isJsonParseException ( e ) ) {
2021-12-03 19:55:27 +03:00
e . pushIndex ( i36 ) ;
2021-02-26 12:21:42 +03:00
}
throw e ;
}
} ) ;
return result ;
}
return {
toJson ,
fromJson
} ;
}
function stringMapJsonBinding ( dresolver , texpr , boundTypeParams ) {
const elementBinding = once ( ( ) = > buildJsonBinding ( dresolver , texpr , boundTypeParams )
) ;
function toJson ( v ) {
const result = {
} ;
for ( let k in v ) {
result [ k ] = elementBinding ( ) . toJson ( v [ k ] ) ;
}
return result ;
}
function fromJson ( json ) {
const jobj = asJsonObject ( json ) ;
if ( ! jobj ) {
throw jsonParseException ( 'expected an object' ) ;
}
let result = {
} ;
for ( let k in jobj ) {
try {
result [ k ] = elementBinding ( ) . fromJson ( jobj [ k ] ) ;
} catch ( e ) {
if ( isJsonParseException ( e ) ) {
e . pushField ( k ) ;
}
}
}
return result ;
}
return {
toJson ,
fromJson
} ;
}
function nullableJsonBinding ( dresolver , texpr , boundTypeParams ) {
const elementBinding = once ( ( ) = > buildJsonBinding ( dresolver , texpr , boundTypeParams )
) ;
function toJson ( v ) {
if ( v === null ) {
return null ;
}
return elementBinding ( ) . toJson ( v ) ;
}
function fromJson ( json ) {
if ( json === null ) {
return null ;
}
return elementBinding ( ) . fromJson ( json ) ;
}
return {
toJson ,
fromJson
} ;
}
function structJsonBinding ( dresolver , struct , params , boundTypeParams ) {
const newBoundTypeParams = createBoundTypeParams ( dresolver , struct . typeParams , params , boundTypeParams ) ;
const fieldDetails = [ ] ;
struct . fields . forEach ( ( field ) = > {
let buildDefault = once ( ( ) = > {
if ( field . default . kind === "just" ) {
const json = field . default . value ;
return {
'value' : buildJsonBinding ( dresolver , field . typeExpr , newBoundTypeParams ) . fromJson ( json )
} ;
} else {
return null ;
}
} ) ;
fieldDetails . push ( {
field : field ,
jsonBinding : once ( ( ) = > buildJsonBinding ( dresolver , field . typeExpr , newBoundTypeParams )
) ,
buildDefault : buildDefault
} ) ;
} ) ;
function toJson ( v0 ) {
const v = v0 ;
const json = {
} ;
fieldDetails . forEach ( ( fd ) = > {
json [ fd . field . serializedName ] = fd . jsonBinding ( ) . toJson ( v && v [ fd . field . name ] ) ;
} ) ;
return json ;
}
function fromJson ( json ) {
const jobj = asJsonObject ( json ) ;
if ( ! jobj ) {
throw jsonParseException ( "expected an object" ) ;
}
const v = {
} ;
fieldDetails . forEach ( ( fd ) = > {
if ( jobj [ fd . field . serializedName ] === undefined ) {
const defaultv = fd . buildDefault ( ) ;
if ( defaultv === null ) {
throw jsonParseException ( "missing struct field " + fd . field . serializedName ) ;
} else {
v [ fd . field . name ] = defaultv . value ;
}
} else {
try {
v [ fd . field . name ] = fd . jsonBinding ( ) . fromJson ( jobj [ fd . field . serializedName ] ) ;
} catch ( e ) {
if ( isJsonParseException ( e ) ) {
e . pushField ( fd . field . serializedName ) ;
}
throw e ;
}
}
} ) ;
return v ;
}
return {
toJson ,
fromJson
} ;
}
function enumJsonBinding ( _dresolver , union , _params , _boundTypeParams ) {
const fieldSerializedNames = [ ] ;
const fieldNumbers = {
} ;
2021-12-03 19:55:27 +03:00
union . fields . forEach ( ( field , i37 ) = > {
2021-02-26 12:21:42 +03:00
fieldSerializedNames . push ( field . serializedName ) ;
2021-12-03 19:55:27 +03:00
fieldNumbers [ field . serializedName ] = i37 ;
2021-02-26 12:21:42 +03:00
} ) ;
function toJson ( v ) {
return fieldSerializedNames [ v ] ;
}
function fromJson ( json ) {
if ( typeof json !== 'string' ) {
throw jsonParseException ( "expected a string for enum" ) ;
}
const result = fieldNumbers [ json ] ;
if ( result === undefined ) {
throw jsonParseException ( "invalid string for enum: " + json ) ;
}
return result ;
}
return {
toJson ,
fromJson
} ;
}
function unionJsonBinding ( dresolver , union , params , boundTypeParams ) {
const newBoundTypeParams = createBoundTypeParams ( dresolver , union . typeParams , params , boundTypeParams ) ;
const detailsByName = {
} ;
const detailsBySerializedName = {
} ;
union . fields . forEach ( ( field ) = > {
const details = {
field : field ,
isVoid : isVoid ( field . typeExpr ) ,
jsonBinding : once ( ( ) = > buildJsonBinding ( dresolver , field . typeExpr , newBoundTypeParams )
)
} ;
detailsByName [ field . name ] = details ;
detailsBySerializedName [ field . serializedName ] = details ;
} ) ;
function toJson ( v0 ) {
const v = v0 ;
const details = detailsByName [ v . kind ] ;
if ( details . isVoid ) {
return details . field . serializedName ;
} else {
const result = {
} ;
result [ details . field . serializedName ] = details . jsonBinding ( ) . toJson ( v . value ) ;
return result ;
}
}
function lookupDetails ( serializedName ) {
let details = detailsBySerializedName [ serializedName ] ;
if ( details === undefined ) {
throw jsonParseException ( "invalid union field " + serializedName ) ;
}
return details ;
}
function fromJson ( json ) {
if ( typeof json === "string" ) {
let details = lookupDetails ( json ) ;
if ( ! details . isVoid ) {
throw jsonParseException ( "union field " + json + "needs an associated value" ) ;
}
return {
kind : details.field.name
} ;
}
const jobj = asJsonObject ( json ) ;
if ( jobj ) {
for ( let k in jobj ) {
let details = lookupDetails ( k ) ;
try {
return {
kind : details.field.name ,
value : details.jsonBinding ( ) . fromJson ( jobj [ k ] )
} ;
} catch ( e ) {
if ( isJsonParseException ( e ) ) {
e . pushField ( k ) ;
}
throw e ;
}
}
throw jsonParseException ( "union without a property" ) ;
} else {
throw jsonParseException ( "expected an object or string" ) ;
}
}
return {
toJson ,
fromJson
} ;
}
function newtypeJsonBinding ( dresolver , newtype , params , boundTypeParams ) {
const newBoundTypeParams = createBoundTypeParams ( dresolver , newtype . typeParams , params , boundTypeParams ) ;
return buildJsonBinding ( dresolver , newtype . typeExpr , newBoundTypeParams ) ;
}
function typedefJsonBinding ( dresolver , typedef , params , boundTypeParams ) {
const newBoundTypeParams = createBoundTypeParams ( dresolver , typedef . typeParams , params , boundTypeParams ) ;
return buildJsonBinding ( dresolver , typedef . typeExpr , newBoundTypeParams ) ;
}
function createBoundTypeParams ( dresolver , paramNames , paramTypes , boundTypeParams ) {
let result = {
} ;
2021-09-01 16:11:55 +03:00
paramNames . forEach ( ( paramName , i ) = > {
result [ paramName ] = buildJsonBinding ( dresolver , paramTypes [ i ] , boundTypeParams ) ;
2021-02-26 12:21:42 +03:00
} ) ;
return result ;
}
2021-12-03 19:55:27 +03:00
function once ( run1 ) {
2021-02-26 12:21:42 +03:00
let result = null ;
return ( ) = > {
if ( result === null ) {
2021-12-03 19:55:27 +03:00
result = run1 ( ) ;
2021-02-26 12:21:42 +03:00
}
return result ;
} ;
}
function declResolver ( . . . astMaps ) {
const astMap = {
} ;
for ( let map of astMaps ) {
for ( let scopedName in map ) {
astMap [ scopedName ] = map [ scopedName ] ;
}
}
function resolver ( scopedName ) {
const scopedNameStr = scopedName . module Name + "." + scopedName . name ;
const result = astMap [ scopedNameStr ] ;
if ( result === undefined ) {
throw new Error ( "Unable to resolve ADL type " + scopedNameStr ) ;
}
return result ;
}
return resolver ;
}
const Pair_AST = {
"moduleName" : "sys.types" ,
"decl" : {
"annotations" : [ ] ,
"type_" : {
"kind" : "struct_" ,
"value" : {
"typeParams" : [
"T1" ,
"T2"
] ,
"fields" : [
{
"annotations" : [ ] ,
"serializedName" : "v1" ,
"default" : {
"kind" : "nothing"
} ,
"name" : "v1" ,
"typeExpr" : {
"typeRef" : {
"kind" : "typeParam" ,
"value" : "T1"
} ,
"parameters" : [ ]
}
} ,
{
"annotations" : [ ] ,
"serializedName" : "v2" ,
"default" : {
"kind" : "nothing"
} ,
"name" : "v2" ,
"typeExpr" : {
"typeRef" : {
"kind" : "typeParam" ,
"value" : "T2"
} ,
"parameters" : [ ]
}
}
]
}
} ,
"name" : "Pair" ,
"version" : {
"kind" : "nothing"
}
}
} ;
const Either_AST = {
"moduleName" : "sys.types" ,
"decl" : {
"annotations" : [ ] ,
"type_" : {
"kind" : "union_" ,
"value" : {
"typeParams" : [
"T1" ,
"T2"
] ,
"fields" : [
{
"annotations" : [ ] ,
"serializedName" : "left" ,
"default" : {
"kind" : "nothing"
} ,
"name" : "left" ,
"typeExpr" : {
"typeRef" : {
"kind" : "typeParam" ,
"value" : "T1"
} ,
"parameters" : [ ]
}
} ,
{
"annotations" : [ ] ,
"serializedName" : "right" ,
"default" : {
"kind" : "nothing"
} ,
"name" : "right" ,
"typeExpr" : {
"typeRef" : {
"kind" : "typeParam" ,
"value" : "T2"
} ,
"parameters" : [ ]
}
}
]
}
} ,
"name" : "Either" ,
"version" : {
"kind" : "nothing"
}
}
} ;
const Maybe_AST = {
"moduleName" : "sys.types" ,
"decl" : {
"annotations" : [ ] ,
"type_" : {
"kind" : "union_" ,
"value" : {
"typeParams" : [
"T"
] ,
"fields" : [
{
"annotations" : [ ] ,
"serializedName" : "nothing" ,
"default" : {
"kind" : "nothing"
} ,
"name" : "nothing" ,
"typeExpr" : {
"typeRef" : {
"kind" : "primitive" ,
"value" : "Void"
} ,
"parameters" : [ ]
}
} ,
{
"annotations" : [ ] ,
"serializedName" : "just" ,
"default" : {
"kind" : "nothing"
} ,
"name" : "just" ,
"typeExpr" : {
"typeRef" : {
"kind" : "typeParam" ,
"value" : "T"
} ,
"parameters" : [ ]
}
}
]
}
} ,
"name" : "Maybe" ,
"version" : {
"kind" : "nothing"
}
}
} ;
const Error_AST = {
"moduleName" : "sys.types" ,
"decl" : {
"annotations" : [ ] ,
"type_" : {
"kind" : "union_" ,
"value" : {
"typeParams" : [
"T"
] ,
"fields" : [
{
"annotations" : [ ] ,
"serializedName" : "value" ,
"default" : {
"kind" : "nothing"
} ,
"name" : "value" ,
"typeExpr" : {
"typeRef" : {
"kind" : "typeParam" ,
"value" : "T"
} ,
"parameters" : [ ]
}
} ,
{
"annotations" : [ ] ,
"serializedName" : "error" ,
"default" : {
"kind" : "nothing"
} ,
"name" : "error" ,
"typeExpr" : {
"typeRef" : {
"kind" : "primitive" ,
"value" : "String"
} ,
"parameters" : [ ]
}
}
]
}
} ,
"name" : "Error" ,
"version" : {
"kind" : "nothing"
}
}
} ;
const MapEntry_AST = {
"moduleName" : "sys.types" ,
"decl" : {
"annotations" : [ ] ,
"type_" : {
"kind" : "struct_" ,
"value" : {
"typeParams" : [
"K" ,
"V"
] ,
"fields" : [
{
"annotations" : [ ] ,
"serializedName" : "k" ,
"default" : {
"kind" : "nothing"
} ,
"name" : "key" ,
"typeExpr" : {
"typeRef" : {
"kind" : "typeParam" ,
"value" : "K"
} ,
"parameters" : [ ]
}
} ,
{
"annotations" : [ ] ,
"serializedName" : "v" ,
"default" : {
"kind" : "nothing"
} ,
"name" : "value" ,
"typeExpr" : {
"typeRef" : {
"kind" : "typeParam" ,
"value" : "V"
} ,
"parameters" : [ ]
}
}
]
}
} ,
"name" : "MapEntry" ,
"version" : {
"kind" : "nothing"
}
}
} ;
const Map_AST = {
"moduleName" : "sys.types" ,
"decl" : {
"annotations" : [ ] ,
"type_" : {
"kind" : "newtype_" ,
"value" : {
"typeParams" : [
"K" ,
"V"
] ,
"default" : {
"kind" : "nothing"
} ,
"typeExpr" : {
"typeRef" : {
"kind" : "primitive" ,
"value" : "Vector"
} ,
"parameters" : [
{
"typeRef" : {
"kind" : "reference" ,
"value" : {
"moduleName" : "sys.types" ,
"name" : "Pair"
}
} ,
"parameters" : [
{
"typeRef" : {
"kind" : "typeParam" ,
"value" : "K"
} ,
"parameters" : [ ]
} ,
{
"typeRef" : {
"kind" : "typeParam" ,
"value" : "V"
} ,
"parameters" : [ ]
}
]
}
]
}
}
} ,
"name" : "Map" ,
"version" : {
"kind" : "nothing"
}
}
} ;
const Set_AST = {
"moduleName" : "sys.types" ,
"decl" : {
"annotations" : [ ] ,
"type_" : {
"kind" : "newtype_" ,
"value" : {
"typeParams" : [
"T"
] ,
"default" : {
"kind" : "nothing"
} ,
"typeExpr" : {
"typeRef" : {
"kind" : "primitive" ,
"value" : "Vector"
} ,
"parameters" : [
{
"typeRef" : {
"kind" : "typeParam" ,
"value" : "T"
} ,
"parameters" : [ ]
}
]
}
}
} ,
"name" : "Set" ,
"version" : {
"kind" : "nothing"
}
}
} ;
const _AST_MAP1 = {
"sys.types.Pair" : Pair_AST ,
"sys.types.Either" : Either_AST ,
"sys.types.Maybe" : Maybe_AST ,
"sys.types.Error" : Error_AST ,
"sys.types.MapEntry" : MapEntry_AST ,
"sys.types.Map" : Map_AST ,
"sys.types.Set" : Set_AST
} ;
const ADL = {
. . . _AST_MAP ,
. . . _AST_MAP1
} ;
2021-10-08 10:47:01 +03:00
declResolver ( ADL ) ;
2021-02-26 12:21:42 +03:00
class ADLMap {
2021-12-02 10:28:09 +03:00
constructor ( data , isEqual ) {
this . data = data ;
2021-02-26 12:21:42 +03:00
this . isEqual = isEqual ;
}
has ( k ) {
return this . findIndex ( k ) !== - 1 ;
}
2021-12-02 10:28:09 +03:00
get ( k ) {
const ind = this . findIndex ( k ) ;
2021-02-26 12:21:42 +03:00
if ( ind === - 1 ) {
return undefined ;
}
return this . data [ ind ] . v2 ;
}
2021-12-02 10:28:09 +03:00
getOrInsert ( k , v ) {
const existing = this . get ( k ) ;
2021-02-26 12:21:42 +03:00
if ( existing === undefined ) {
2021-12-02 10:28:09 +03:00
this . set ( k , v ) ;
2021-02-26 12:21:42 +03:00
return v ;
}
return existing ;
}
2021-12-02 10:28:09 +03:00
set ( k , v ) {
const ind = this . findIndex ( k ) ;
2021-02-26 12:21:42 +03:00
if ( ind === - 1 ) {
this . data . push ( {
2021-12-02 10:28:09 +03:00
v1 : k ,
v2 : v
2021-02-26 12:21:42 +03:00
} ) ;
}
this . data [ ind ] = {
2021-12-02 10:28:09 +03:00
v1 : k ,
v2 : v
2021-02-26 12:21:42 +03:00
} ;
return this ;
}
keys() {
return this . data . map ( ( p ) = > p . v1
) ;
}
values() {
return this . data . map ( ( p ) = > p . v2
) ;
}
entries() {
return this . data . map ( ( p ) = > [
p . v1 ,
p . v2
]
) ;
}
toData() {
return this . data ;
}
2021-12-02 10:28:09 +03:00
findIndex ( k ) {
return this . data . findIndex ( ( p ) = > this . isEqual ( p . v1 , k )
2021-02-26 12:21:42 +03:00
) ;
}
}
class TaskManifest {
2021-12-02 10:28:09 +03:00
constructor ( data ) {
2021-03-21 16:31:35 +03:00
this . lastExecution = null ;
this . trackedFiles = new ADLMap ( [ ] , ( k1 , k2 ) = > k1 === k2
) ;
2021-12-02 10:28:09 +03:00
this . trackedFiles = new ADLMap ( data . trackedFiles , ( k1 , k2 ) = > k1 === k2
2021-02-26 12:21:42 +03:00
) ;
2021-12-02 10:28:09 +03:00
this . lastExecution = data . lastExecution ;
2021-02-26 12:21:42 +03:00
}
getFileData ( fn ) {
return this . trackedFiles . get ( fn ) ;
}
2021-12-02 10:28:09 +03:00
setFileData ( fn , d ) {
this . trackedFiles . set ( fn , d ) ;
2021-02-26 12:21:42 +03:00
}
setExecutionTimestamp() {
this . lastExecution = new Date ( ) . toISOString ( ) ;
}
toData() {
return {
lastExecution : this.lastExecution ,
trackedFiles : this.trackedFiles.toData ( )
} ;
}
}
function taskContext ( ctx , task ) {
return {
logger : ctx.taskLogger ,
task ,
args : ctx.args
} ;
}
function isTask ( dep ) {
return dep instanceof Task ;
}
function isTrackedFile ( dep ) {
return dep instanceof TrackedFile ;
}
function isTrackedFileAsync ( dep ) {
return dep instanceof TrackedFilesAsync ;
}
2021-12-03 19:55:27 +03:00
async function statPath ( path36 ) {
2021-02-26 12:21:42 +03:00
try {
2021-12-03 19:55:27 +03:00
const fileInfo = await Deno . stat ( path36 ) ;
2021-02-26 12:21:42 +03:00
return {
kind : 'fileInfo' ,
fileInfo
} ;
} catch ( err ) {
if ( err instanceof Deno . errors . NotFound ) {
return {
kind : 'nonExistent'
} ;
}
throw err ;
}
}
class Task {
constructor ( taskParams ) {
2021-03-21 16:31:35 +03:00
this . taskManifest = null ;
2021-02-26 12:21:42 +03:00
this . name = taskParams . name ;
this . action = taskParams . action ;
this . description = taskParams . description ;
this . task_deps = new Set ( this . getTaskDeps ( taskParams . deps || [ ] ) ) ;
this . file_deps = new Set ( this . getTrackedFiles ( taskParams . deps || [ ] ) ) ;
this . async_files_deps = new Set ( this . getTrackedFilesAsync ( taskParams . deps || [ ] ) ) ;
this . targets = new Set ( taskParams . targets || [ ] ) ;
this . uptodate = taskParams . uptodate ;
for ( const f of this . targets ) {
f . setTask ( this ) ;
}
}
getTaskDeps ( deps ) {
return deps . filter ( isTask ) ;
}
2021-12-02 10:28:09 +03:00
getTrackedFiles ( deps ) {
return deps . filter ( isTrackedFile ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
getTrackedFilesAsync ( deps ) {
return deps . filter ( isTrackedFileAsync ) ;
2021-02-26 12:21:42 +03:00
}
async setup ( ctx ) {
if ( this . taskManifest === null ) {
for ( const t of this . targets ) {
ctx . targetRegister . set ( t . path , this ) ;
}
this . taskManifest = ctx . manifest . tasks . getOrInsert ( this . name , new TaskManifest ( {
lastExecution : null ,
trackedFiles : [ ]
} ) ) ;
for ( const taskDep of this . task_deps ) {
await taskDep . setup ( ctx ) ;
}
for ( const fDep of this . file_deps ) {
const fDepTask = fDep . getTask ( ) ;
if ( fDepTask !== null ) {
await fDepTask . setup ( ctx ) ;
}
}
}
}
2021-12-02 10:28:09 +03:00
async exec ( ctx ) {
if ( ctx . doneTasks . has ( this ) ) {
2021-02-26 12:21:42 +03:00
return ;
}
2021-12-02 10:28:09 +03:00
if ( ctx . inprogressTasks . has ( this ) ) {
2021-02-26 12:21:42 +03:00
return ;
}
2021-12-02 10:28:09 +03:00
ctx . inprogressTasks . add ( this ) ;
2021-02-26 12:21:42 +03:00
for ( const afd of this . async_files_deps ) {
const file_deps = await afd . getTrackedFiles ( ) ;
for ( const fd of file_deps ) {
this . file_deps . add ( fd ) ;
}
}
for ( const fd of this . file_deps ) {
2021-12-02 10:28:09 +03:00
const t = ctx . targetRegister . get ( fd . path ) ;
2021-02-26 12:21:42 +03:00
if ( t !== undefined ) {
this . task_deps . add ( t ) ;
}
}
2021-12-02 10:28:09 +03:00
await this . execDependencies ( ctx ) ;
2021-02-26 12:21:42 +03:00
let actualUpToDate = true ;
2021-12-02 10:28:09 +03:00
actualUpToDate = actualUpToDate && await this . checkFileDeps ( ctx ) ;
ctx . internalLogger . info ( ` ${ this . name } checkFileDeps ${ actualUpToDate } ` ) ;
actualUpToDate = actualUpToDate && await this . targetsExist ( ctx ) ;
ctx . internalLogger . info ( ` ${ this . name } targetsExist ${ actualUpToDate } ` ) ;
2021-02-26 12:21:42 +03:00
if ( this . uptodate !== undefined ) {
2021-12-02 10:28:09 +03:00
actualUpToDate = actualUpToDate && await this . uptodate ( taskContext ( ctx , this ) ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
ctx . internalLogger . info ( ` ${ this . name } uptodate ${ actualUpToDate } ` ) ;
2021-02-26 12:21:42 +03:00
if ( actualUpToDate ) {
2021-12-02 10:28:09 +03:00
ctx . taskLogger . info ( ` --- ${ this . name } ` ) ;
2021-02-26 12:21:42 +03:00
} else {
2021-12-02 10:28:09 +03:00
ctx . taskLogger . info ( ` ... ${ this . name } ` ) ;
await this . action ( taskContext ( ctx , this ) ) ;
ctx . taskLogger . info ( ` === ${ this . name } ` ) ;
2021-02-26 12:21:42 +03:00
{
this . taskManifest ? . setExecutionTimestamp ( ) ;
let promisesInProgress = [ ] ;
for ( const fdep of this . file_deps ) {
2021-12-02 10:28:09 +03:00
promisesInProgress . push ( ctx . asyncQueue . schedule ( async ( ) = > {
const trackedFileData = await fdep . getFileData ( ctx ) ;
2021-02-26 12:21:42 +03:00
this . taskManifest ? . setFileData ( fdep . path , trackedFileData ) ;
} ) ) ;
}
await Promise . all ( promisesInProgress ) ;
}
}
2021-12-02 10:28:09 +03:00
ctx . doneTasks . add ( this ) ;
ctx . inprogressTasks . delete ( this ) ;
2021-02-26 12:21:42 +03:00
}
2021-12-02 10:28:09 +03:00
async targetsExist ( ctx ) {
const tex = await Promise . all ( Array . from ( this . targets ) . map ( async ( tf ) = > ctx . asyncQueue . schedule ( ( ) = > tf . exists ( )
2021-02-26 12:21:42 +03:00
)
) ) ;
return ! tex . some ( ( t ) = > ! t
) ;
}
2021-12-02 10:28:09 +03:00
async checkFileDeps ( ctx ) {
2021-02-26 12:21:42 +03:00
let fileDepsUpToDate = true ;
let promisesInProgress = [ ] ;
const taskManifest = this . taskManifest ;
if ( taskManifest === null ) {
throw new Error ( ` Invalid null taskManifest on ${ this . name } ` ) ;
}
for ( const fdep of this . file_deps ) {
2021-12-02 10:28:09 +03:00
promisesInProgress . push ( ctx . asyncQueue . schedule ( async ( ) = > {
const r = await fdep . getFileDataOrCached ( ctx , taskManifest . getFileData ( fdep . path ) ) ;
2021-02-26 12:21:42 +03:00
taskManifest . setFileData ( fdep . path , r . tData ) ;
fileDepsUpToDate = fileDepsUpToDate && r . upToDate ;
} ) ) ;
}
await Promise . all ( promisesInProgress ) ;
promisesInProgress = [ ] ;
return fileDepsUpToDate ;
}
2021-12-02 10:28:09 +03:00
async execDependencies ( ctx ) {
2021-02-26 12:21:42 +03:00
for ( const dep of this . task_deps ) {
2021-12-02 10:28:09 +03:00
if ( ! ctx . doneTasks . has ( dep ) && ! ctx . inprogressTasks . has ( dep ) ) {
await dep . exec ( ctx ) ;
2021-02-26 12:21:42 +03:00
}
}
}
}
class TrackedFile {
# getHash ;
# getTimestamp ;
constructor ( fileParams ) {
2021-03-21 16:31:35 +03:00
this . path = "" ;
this . fromTask = null ;
2021-02-26 12:21:42 +03:00
this . path = mod3 . posix . resolve ( fileParams . path ) ;
this . # getHash = fileParams . getHash || getFileSha1Sum ;
this . # getTimestamp = fileParams . getTimestamp || getFileTimestamp ;
}
async stat() {
mod4 . getLogger ( 'internal' ) . info ( ` checking file ${ this . path } ` ) ;
return await statPath ( this . path ) ;
}
async exists ( statInput ) {
let statResult = statInput ;
if ( statResult === undefined ) {
statResult = await this . stat ( ) ;
}
return statResult . kind === 'fileInfo' ;
}
2021-12-02 10:28:09 +03:00
async getHash ( statInput ) {
let statResult = statInput ;
2021-02-26 12:21:42 +03:00
if ( statResult === undefined ) {
statResult = await this . stat ( ) ;
}
if ( statResult . kind !== 'fileInfo' ) {
return "" ;
}
mod4 . getLogger ( 'internal' ) . info ( ` checking hash on ${ this . path } ` ) ;
return this . # getHash ( this . path , statResult . fileInfo ) ;
}
2021-12-02 10:28:09 +03:00
async getTimestamp ( statInput ) {
let statResult = statInput ;
2021-02-26 12:21:42 +03:00
if ( statResult === undefined ) {
statResult = await this . stat ( ) ;
}
if ( statResult . kind !== 'fileInfo' ) {
return "" ;
}
return this . # getTimestamp ( this . path , statResult . fileInfo ) ;
}
2021-12-02 10:28:09 +03:00
async isUpToDate ( ctx , tData , statInput ) {
2021-02-26 12:21:42 +03:00
if ( tData === undefined ) {
return false ;
}
2021-12-02 10:28:09 +03:00
let statResult = statInput ;
2021-02-26 12:21:42 +03:00
if ( statResult === undefined ) {
statResult = await this . stat ( ) ;
}
const mtime = await this . getTimestamp ( statResult ) ;
if ( mtime === tData . timestamp ) {
return true ;
}
const hash = await this . getHash ( statResult ) ;
return hash === tData . hash ;
}
2021-12-02 10:28:09 +03:00
async getFileData ( ctx , statInput ) {
let statResult = statInput ;
2021-02-26 12:21:42 +03:00
if ( statResult === undefined ) {
statResult = await this . stat ( ) ;
}
return {
hash : await this . getHash ( statResult ) ,
timestamp : await this . getTimestamp ( statResult )
} ;
}
2021-12-02 10:28:09 +03:00
async getFileDataOrCached ( ctx , tData , statInput ) {
let statResult = statInput ;
2021-02-26 12:21:42 +03:00
if ( statResult === undefined ) {
statResult = await this . stat ( ) ;
}
2021-12-02 10:28:09 +03:00
if ( tData !== undefined && await this . isUpToDate ( ctx , tData , statResult ) ) {
2021-02-26 12:21:42 +03:00
return {
2021-12-02 10:28:09 +03:00
tData ,
2021-02-26 12:21:42 +03:00
upToDate : true
} ;
}
return {
2021-12-02 10:28:09 +03:00
tData : await this . getFileData ( ctx , statResult ) ,
2021-02-26 12:21:42 +03:00
upToDate : false
} ;
}
setTask ( t ) {
if ( this . fromTask === null ) {
this . fromTask = t ;
} else {
throw new Error ( "Duplicate tasks generating TrackedFile as target - " + this . path ) ;
}
}
getTask() {
return this . fromTask ;
}
}
class TrackedFilesAsync {
constructor ( gen ) {
this . gen = gen ;
2021-03-21 16:31:35 +03:00
this . kind = 'trackedfilesasync' ;
2021-02-26 12:21:42 +03:00
}
async getTrackedFiles() {
return this . gen ( ) ;
}
}
2021-09-01 16:11:55 +03:00
async function getFileSha1Sum ( filename ) {
const data = await Deno . readFile ( filename ) ;
2021-02-26 12:21:42 +03:00
const hashsha1 = mod6 . createHash ( "sha1" ) ;
2021-09-01 16:11:55 +03:00
hashsha1 . update ( data ) ;
2021-02-26 12:21:42 +03:00
const hashInHex = hashsha1 . toString ( ) ;
return hashInHex ;
}
2021-09-01 16:11:55 +03:00
async function getFileTimestamp ( filename , stat ) {
2021-02-26 12:21:42 +03:00
const mtime = stat . mtime ;
return mtime ? . toISOString ( ) || "" ;
}
class StdErrPlainHandler extends mod4 . handlers . BaseHandler {
2021-09-21 15:21:49 +03:00
constructor ( levelName ) {
super ( levelName , {
2021-02-26 12:21:42 +03:00
formatter : "{msg}"
} ) ;
}
log ( msg ) {
Deno . stderr . writeSync ( new TextEncoder ( ) . encode ( msg + "\n" ) ) ;
}
}
class StdErrHandler extends mod4 . handlers . ConsoleHandler {
2021-12-02 10:28:09 +03:00
log ( msg ) {
Deno . stderr . writeSync ( new TextEncoder ( ) . encode ( msg + "\n" ) ) ;
2021-02-26 12:21:42 +03:00
}
}
async function setupLogging() {
await mod4 . setup ( {
handlers : {
stderr : new StdErrHandler ( "DEBUG" ) ,
stderrPlain : new StdErrPlainHandler ( "DEBUG" )
} ,
loggers : {
internal : {
level : "WARNING" ,
handlers : [
"stderrPlain"
]
} ,
task : {
level : "INFO" ,
handlers : [
"stderrPlain"
]
} ,
user : {
level : "INFO" ,
handlers : [
"stderrPlain"
]
}
}
} ) ;
}
2021-09-01 16:11:55 +03:00
function findUserSourceContext ( dir ) {
2021-10-08 10:47:01 +03:00
dir . split ( mod3 . SEP ) ;
2021-02-26 12:21:42 +03:00
return {
2021-09-01 16:11:55 +03:00
path : dir ,
stat : Deno.lstatSync ( dir )
2021-02-26 12:21:42 +03:00
} ;
}
2021-09-01 16:11:55 +03:00
function findUserSource ( dir , startCtxArg ) {
const startCtx = startCtxArg === null ? findUserSourceContext ( dir ) : startCtxArg ;
const dirStat = Deno . lstatSync ( dir ) ;
2021-02-26 12:21:42 +03:00
if ( dirStat . dev !== startCtx . stat . dev ) {
return null ;
}
2021-09-01 16:11:55 +03:00
if ( mod3 . resolve ( mod3 . join ( dir , ".." ) ) === dir ) {
2021-02-26 12:21:42 +03:00
return null ;
}
const subdirs = [
"dnit"
] ;
const defaultSources = [
"main.ts" ,
"dnit.ts" ,
] ;
const importmaps = [
"import_map.json" ,
".import_map.json"
] ;
for ( const subdir of subdirs ) {
for ( const sourceName of defaultSources ) {
const res = {
2021-09-01 16:11:55 +03:00
baseDir : mod3.resolve ( dir ) ,
dnitDir : mod3.resolve ( mod3 . join ( dir , subdir ) ) ,
mainSrc : mod3.resolve ( mod3 . join ( dir , subdir , sourceName ) )
2021-02-26 12:21:42 +03:00
} ;
if ( mod5 . existsSync ( res . mainSrc ) ) {
for ( const importMapFile of importmaps ) {
2021-09-01 16:11:55 +03:00
const importmap = mod3 . resolve ( mod3 . join ( dir , subdir , importMapFile ) ) ;
2021-02-26 12:21:42 +03:00
if ( mod5 . existsSync ( importmap ) ) {
return {
. . . res ,
importmap
} ;
}
}
return {
. . . res ,
importmap : null
} ;
}
}
}
2021-09-01 16:11:55 +03:00
return findUserSource ( mod3 . join ( dir , ".." ) , startCtx ) ;
2021-02-26 12:21:42 +03:00
}
async function parseDotDenoVersionFile ( fname ) {
const denoReqSemverRange = await Deno . readTextFile ( fname ) ;
return denoReqSemverRange ;
}
async function getDenoVersion() {
const proc = Deno . run ( {
cmd : [
"deno" ,
"--version"
] ,
stdout : 'piped'
} ) ;
const [ status , output ] = await Promise . all ( [
proc . status ( ) ,
proc . output ( )
] ) ;
const decoder = new TextDecoder ( ) ;
const denoVersionStr = decoder . decode ( output ) ;
const regmatch = denoVersionStr . match ( /deno[ ]+([0-9.]+)/ ) ;
if ( regmatch ) {
return regmatch [ 1 ] ;
}
throw new Error ( "Invalid parse of deno version output" ) ;
}
function checkValidDenoVersion ( denoVersion , denoReqSemverRange ) {
return mod7 . satisfies ( denoVersion , denoReqSemverRange ) ;
}
async function launch ( logger ) {
const userSource = findUserSource ( Deno . cwd ( ) , null ) ;
if ( userSource !== null ) {
logger . info ( "running source:" + userSource . mainSrc ) ;
logger . info ( "running wd:" + userSource . baseDir ) ;
logger . info ( "running importmap:" + userSource . importmap ) ;
logger . info ( "running dnitDir:" + userSource . dnitDir ) ;
const denoVersion = await getDenoVersion ( ) ;
logger . info ( "deno version:" + denoVersion ) ;
const dotDenoVersionFile = mod3 . join ( userSource . dnitDir , '.denoversion' ) ;
if ( mod5 . existsSync ( dotDenoVersionFile ) ) {
const reqDenoVerStr = await parseDotDenoVersionFile ( dotDenoVersionFile ) ;
const validDenoVer = checkValidDenoVersion ( denoVersion , reqDenoVerStr ) ;
if ( ! validDenoVer ) {
throw new Error ( "Requires deno version " + reqDenoVerStr ) ;
}
logger . info ( "deno version ok:" + denoVersion + " for " + reqDenoVerStr ) ;
}
Deno . chdir ( userSource . baseDir ) ;
const permissions = [
"--allow-read" ,
"--allow-write" ,
"--allow-run" ,
"--allow-env" ,
"--allow-net" ,
] ;
const flags = [
"--quiet" ,
"--unstable" ,
] ;
const importmap = userSource . importmap ? [
"--importmap" ,
userSource . importmap ,
] : [ ] ;
const proc = Deno . run ( {
cmd : [
"deno" ,
"run"
] . concat ( flags ) . concat ( permissions ) . concat ( importmap ) . concat ( [
userSource . mainSrc
] ) . concat ( [
"--dnitDir" ,
userSource . dnitDir
] ) . concat ( Deno . args )
} ) ;
const status = await proc . status ( ) ;
return status ;
} else {
logger . error ( "No dnit.ts or dnit directory found" ) ;
return {
success : false ,
code : 1
} ;
}
}
2021-10-21 08:12:50 +03:00
async function main() {
2021-09-01 16:11:55 +03:00
const args = mod . parse ( Deno . args ) ;
if ( args [ "version" ] === true ) {
2021-12-03 19:55:27 +03:00
console . log ( ` dnit ${ version } ` ) ;
2021-02-26 12:21:42 +03:00
Deno . exit ( 0 ) ;
}
await setupLogging ( ) ;
const internalLogger = mod4 . getLogger ( "internal" ) ;
2021-09-01 16:11:55 +03:00
if ( args [ "verbose" ] !== undefined ) {
2021-02-26 12:21:42 +03:00
internalLogger . levelName = "INFO" ;
}
2021-12-03 19:55:27 +03:00
internalLogger . info ( ` starting dnit launch using version: ${ version } ` ) ;
2021-02-26 12:21:42 +03:00
launch ( internalLogger ) . then ( ( st ) = > {
Deno . exit ( st . code ) ;
} ) ;
}
2021-10-21 08:12:50 +03:00
main ( ) ;
export { main as main } ;