2021-02-26 12:21:42 +03:00
class DenoStdInternalError extends Error {
2021-10-21 08:12:50 +03:00
constructor ( message1 ) {
super ( message1 ) ;
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-10-21 08:12:50 +03:00
function parse ( args , { "--" : doubleDash = false , alias : alias2 = {
2021-02-26 12:21:42 +03:00
} , boolean : __boolean = false , default : defaults = {
} , stopEarly = false , string = [ ] , unknown = ( i ) = > i
} = {
} ) {
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-10-21 08:12:50 +03:00
if ( alias2 !== undefined ) {
for ( const key in alias2 ) {
const val = getForce ( alias2 , 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 ( "--" ) ) ;
}
for ( let i = 0 ; i < args . length ; i ++ ) {
const arg = args [ i ] ;
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-02-26 12:21:42 +03:00
const next = args [ i + 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-02-26 12:21:42 +03:00
i ++ ;
} else if ( /^(true|false)$/ . test ( next ) ) {
2021-09-01 16:11:55 +03:00
setArg ( key , next === "true" , arg ) ;
2021-02-26 12:21:42 +03:00
i ++ ;
} 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 !== "-" ) {
if ( args [ i + 1 ] && ! /^(-|--)[^-]/ . test ( args [ i + 1 ] ) && ! get ( flags . bools , key ) && ( get ( aliases , key ) ? ! aliasIsBoolean ( key ) : true ) ) {
setArg ( key , args [ i + 1 ] , arg ) ;
2021-02-26 12:21:42 +03:00
i ++ ;
} else if ( args [ i + 1 ] && /^(true|false)$/ . test ( args [ i + 1 ] ) ) {
2021-09-01 16:11:55 +03:00
setArg ( key , args [ i + 1 ] === "true" , arg ) ;
2021-02-26 12:21:42 +03:00
i ++ ;
} 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 ) {
argv . _ . push ( . . . args . slice ( i + 1 ) ) ;
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_FORWARD_SLASH = 47 ;
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-02-26 12:21:42 +03:00
function assertPath ( path ) {
if ( typeof path !== "string" ) {
throw new TypeError ( ` Path must be a string. Received ${ JSON . stringify ( path ) } ` ) ;
}
}
function isPosixPathSeparator ( code ) {
return code === 47 ;
}
2021-10-21 08:12:50 +03:00
function isPathSeparator1 ( code ) {
2021-02-26 12:21:42 +03:00
return isPosixPathSeparator ( code ) || code === 92 ;
}
function isWindowsDeviceRoot ( code ) {
return code >= 97 && code <= 122 || code >= 65 && code <= 90 ;
}
2021-09-01 16:11:55 +03:00
function normalizeString ( path , allowAboveRoot , separator , isPathSeparator ) {
2021-02-26 12:21:42 +03:00
let res = "" ;
let lastSegmentLength = 0 ;
let lastSlash = - 1 ;
let dots = 0 ;
let code ;
for ( let i = 0 , len = path . length ; i <= len ; ++ i ) {
if ( i < len ) code = path . charCodeAt ( i ) ;
2021-09-01 16:11:55 +03:00
else if ( isPathSeparator ( code ) ) break ;
2021-02-26 12:21:42 +03:00
else code = CHAR_FORWARD_SLASH ;
2021-09-01 16:11:55 +03:00
if ( isPathSeparator ( code ) ) {
2021-02-26 12:21:42 +03:00
if ( lastSlash === i - 1 || dots === 1 ) {
} else if ( lastSlash !== i - 1 && dots === 2 ) {
if ( res . length < 2 || lastSegmentLength !== 2 || res . charCodeAt ( res . length - 1 ) !== 46 || res . charCodeAt ( res . length - 2 ) !== 46 ) {
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 ) ;
}
lastSlash = i ;
dots = 0 ;
continue ;
} else if ( res . length === 2 || res . length === 1 ) {
res = "" ;
lastSegmentLength = 0 ;
lastSlash = i ;
dots = 0 ;
continue ;
}
}
if ( allowAboveRoot ) {
if ( res . length > 0 ) res += ` ${ separator } .. ` ;
else res = ".." ;
lastSegmentLength = 2 ;
}
} else {
if ( res . length > 0 ) res += separator + path . slice ( lastSlash + 1 , i ) ;
else res = path . slice ( lastSlash + 1 , i ) ;
lastSegmentLength = i - lastSlash - 1 ;
}
lastSlash = i ;
dots = 0 ;
} else if ( code === 46 && dots !== - 1 ) {
++ dots ;
} else {
dots = - 1 ;
}
}
return res ;
}
function _format ( sep , pathObject ) {
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 ;
return dir + sep + base ;
}
2021-09-01 16:11:55 +03:00
const sep3 = "\\" ;
2021-02-26 12:21:42 +03:00
const delimiter = ";" ;
function resolve ( . . . pathSegments ) {
let resolvedDevice = "" ;
let resolvedTail = "" ;
let resolvedAbsolute = false ;
for ( let i = pathSegments . length - 1 ; i >= - 1 ; i -- ) {
let path ;
if ( i >= 0 ) {
path = pathSegments [ i ] ;
} else if ( ! resolvedDevice ) {
if ( globalThis . Deno == null ) {
throw new TypeError ( "Resolved a drive-letter-less path without a CWD." ) ;
}
path = Deno . cwd ( ) ;
} else {
if ( globalThis . Deno == null ) {
throw new TypeError ( "Resolved a relative path without a CWD." ) ;
}
path = Deno . env . get ( ` = ${ resolvedDevice } ` ) || Deno . cwd ( ) ;
if ( path === undefined || path . slice ( 0 , 3 ) . toLowerCase ( ) !== ` ${ resolvedDevice . toLowerCase ( ) } \\ ` ) {
path = ` ${ resolvedDevice } \\ ` ;
}
}
assertPath ( path ) ;
const len = path . length ;
if ( len === 0 ) continue ;
let rootEnd = 0 ;
let device = "" ;
let isAbsolute = false ;
const code = path . charCodeAt ( 0 ) ;
if ( len > 1 ) {
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( code ) ) {
2021-02-26 12:21:42 +03:00
isAbsolute = true ;
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( path . charCodeAt ( 1 ) ) ) {
2021-02-26 12:21:42 +03:00
let j = 2 ;
let last = j ;
for ( ; j < len ; ++ j ) {
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( path . charCodeAt ( j ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( j < len && j !== last ) {
const firstPart = path . slice ( last , j ) ;
last = j ;
for ( ; j < len ; ++ j ) {
2021-10-21 08:12:50 +03:00
if ( ! isPathSeparator1 ( path . charCodeAt ( j ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( j < len && j !== last ) {
last = j ;
for ( ; j < len ; ++ j ) {
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( path . charCodeAt ( j ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( j === len ) {
device = ` \\ \\ ${ firstPart } \\ ${ path . slice ( last ) } ` ;
rootEnd = j ;
} else if ( j !== last ) {
device = ` \\ \\ ${ firstPart } \\ ${ path . slice ( last , j ) } ` ;
rootEnd = j ;
}
}
}
} else {
rootEnd = 1 ;
}
} else if ( isWindowsDeviceRoot ( code ) ) {
if ( path . charCodeAt ( 1 ) === 58 ) {
device = path . slice ( 0 , 2 ) ;
rootEnd = 2 ;
if ( len > 2 ) {
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( path . charCodeAt ( 2 ) ) ) {
2021-02-26 12:21:42 +03:00
isAbsolute = true ;
rootEnd = 3 ;
}
}
}
}
2021-10-21 08:12:50 +03:00
} else if ( isPathSeparator1 ( code ) ) {
2021-02-26 12:21:42 +03:00
rootEnd = 1 ;
isAbsolute = true ;
}
if ( device . length > 0 && resolvedDevice . length > 0 && device . toLowerCase ( ) !== resolvedDevice . toLowerCase ( ) ) {
continue ;
}
if ( resolvedDevice . length === 0 && device . length > 0 ) {
resolvedDevice = device ;
}
if ( ! resolvedAbsolute ) {
resolvedTail = ` ${ path . slice ( rootEnd ) } \\ ${ resolvedTail } ` ;
resolvedAbsolute = isAbsolute ;
}
if ( resolvedAbsolute && resolvedDevice . length > 0 ) break ;
}
2021-10-21 08:12:50 +03:00
resolvedTail = normalizeString ( resolvedTail , ! resolvedAbsolute , "\\" , isPathSeparator1 ) ;
2021-02-26 12:21:42 +03:00
return resolvedDevice + ( resolvedAbsolute ? "\\" : "" ) + resolvedTail || "." ;
}
function normalize ( path ) {
assertPath ( path ) ;
const len = path . length ;
if ( len === 0 ) return "." ;
let rootEnd = 0 ;
let device ;
let isAbsolute = false ;
const code = path . charCodeAt ( 0 ) ;
if ( len > 1 ) {
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( code ) ) {
2021-02-26 12:21:42 +03:00
isAbsolute = true ;
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( path . charCodeAt ( 1 ) ) ) {
2021-02-26 12:21:42 +03:00
let j = 2 ;
let last = j ;
for ( ; j < len ; ++ j ) {
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( path . charCodeAt ( j ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( j < len && j !== last ) {
const firstPart = path . slice ( last , j ) ;
last = j ;
for ( ; j < len ; ++ j ) {
2021-10-21 08:12:50 +03:00
if ( ! isPathSeparator1 ( path . charCodeAt ( j ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( j < len && j !== last ) {
last = j ;
for ( ; j < len ; ++ j ) {
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( path . charCodeAt ( j ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( j === len ) {
return ` \\ \\ ${ firstPart } \\ ${ path . slice ( last ) } \\ ` ;
} else if ( j !== last ) {
device = ` \\ \\ ${ firstPart } \\ ${ path . slice ( last , j ) } ` ;
rootEnd = j ;
}
}
}
} else {
rootEnd = 1 ;
}
} else if ( isWindowsDeviceRoot ( code ) ) {
if ( path . charCodeAt ( 1 ) === 58 ) {
device = path . slice ( 0 , 2 ) ;
rootEnd = 2 ;
if ( len > 2 ) {
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( path . charCodeAt ( 2 ) ) ) {
2021-02-26 12:21:42 +03:00
isAbsolute = true ;
rootEnd = 3 ;
}
}
}
}
2021-10-21 08:12:50 +03:00
} else if ( isPathSeparator1 ( code ) ) {
2021-02-26 12:21:42 +03:00
return "\\" ;
}
let tail ;
if ( rootEnd < len ) {
2021-10-21 08:12:50 +03:00
tail = normalizeString ( path . slice ( rootEnd ) , ! isAbsolute , "\\" , isPathSeparator1 ) ;
2021-02-26 12:21:42 +03:00
} else {
tail = "" ;
}
if ( tail . length === 0 && ! isAbsolute ) tail = "." ;
2021-10-21 08:12:50 +03:00
if ( tail . length > 0 && isPathSeparator1 ( path . charCodeAt ( len - 1 ) ) ) {
2021-02-26 12:21:42 +03:00
tail += "\\" ;
}
if ( device === undefined ) {
if ( isAbsolute ) {
if ( tail . length > 0 ) return ` \\ ${ tail } ` ;
else return "\\" ;
} else if ( tail . length > 0 ) {
return tail ;
} else {
return "" ;
}
} else if ( isAbsolute ) {
if ( tail . length > 0 ) return ` ${ device } \\ ${ tail } ` ;
else return ` ${ device } \\ ` ;
} else if ( tail . length > 0 ) {
return device + tail ;
} else {
return device ;
}
}
2021-10-21 08:12:50 +03:00
function isAbsolute3 ( path ) {
2021-02-26 12:21:42 +03:00
assertPath ( path ) ;
const len = path . length ;
if ( len === 0 ) return false ;
const code = path . charCodeAt ( 0 ) ;
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( code ) ) {
2021-02-26 12:21:42 +03:00
return true ;
} else if ( isWindowsDeviceRoot ( code ) ) {
if ( len > 2 && path . charCodeAt ( 1 ) === 58 ) {
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( path . 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 ;
for ( let i = 0 ; i < pathsCount ; ++ i ) {
const path = paths [ i ] ;
assertPath ( path ) ;
if ( path . length > 0 ) {
if ( joined === undefined ) joined = firstPart = path ;
else joined += ` \\ ${ path } ` ;
}
}
if ( joined === undefined ) return "." ;
let needsReplace = true ;
let slashCount = 0 ;
assert ( firstPart != null ) ;
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( firstPart . charCodeAt ( 0 ) ) ) {
2021-02-26 12:21:42 +03:00
++ slashCount ;
const firstLen = firstPart . length ;
if ( firstLen > 1 ) {
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( firstPart . charCodeAt ( 1 ) ) ) {
2021-02-26 12:21:42 +03:00
++ slashCount ;
if ( firstLen > 2 ) {
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( firstPart . charCodeAt ( 2 ) ) ) ++ slashCount ;
2021-02-26 12:21:42 +03:00
else {
needsReplace = false ;
}
}
}
}
}
if ( needsReplace ) {
for ( ; slashCount < joined . length ; ++ slashCount ) {
2021-10-21 08:12:50 +03:00
if ( ! isPathSeparator1 ( 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 ) !== 92 ) break ;
}
for ( ; fromEnd - 1 > fromStart ; -- fromEnd ) {
if ( from . charCodeAt ( fromEnd - 1 ) !== 92 ) break ;
}
const fromLen = fromEnd - fromStart ;
let toStart = 0 ;
let toEnd = to . length ;
for ( ; toStart < toEnd ; ++ toStart ) {
if ( to . charCodeAt ( toStart ) !== 92 ) break ;
}
for ( ; toEnd - 1 > toStart ; -- toEnd ) {
if ( to . charCodeAt ( toEnd - 1 ) !== 92 ) break ;
}
const toLen = toEnd - toStart ;
const length = fromLen < toLen ? fromLen : toLen ;
let lastCommonSep = - 1 ;
let i = 0 ;
for ( ; i <= length ; ++ i ) {
if ( i === length ) {
if ( toLen > length ) {
if ( to . charCodeAt ( toStart + i ) === 92 ) {
return toOrig . slice ( toStart + i + 1 ) ;
} else if ( i === 2 ) {
return toOrig . slice ( toStart + i ) ;
}
}
if ( fromLen > length ) {
if ( from . charCodeAt ( fromStart + i ) === 92 ) {
lastCommonSep = i ;
} else if ( i === 2 ) {
lastCommonSep = 3 ;
}
}
break ;
}
const fromCode = from . charCodeAt ( fromStart + i ) ;
const toCode = to . charCodeAt ( toStart + i ) ;
if ( fromCode !== toCode ) break ;
else if ( fromCode === 92 ) lastCommonSep = i ;
}
if ( i !== length && lastCommonSep === - 1 ) {
return toOrig ;
}
let out = "" ;
if ( lastCommonSep === - 1 ) lastCommonSep = 0 ;
for ( i = fromStart + lastCommonSep + 1 ; i <= fromEnd ; ++ i ) {
if ( i === fromEnd || from . charCodeAt ( i ) === 92 ) {
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 ) === 92 ) ++ toStart ;
return toOrig . slice ( toStart , toEnd ) ;
}
}
function toNamespacedPath ( path ) {
if ( typeof path !== "string" ) return path ;
if ( path . length === 0 ) return "" ;
const resolvedPath = resolve ( path ) ;
if ( resolvedPath . length >= 3 ) {
if ( resolvedPath . charCodeAt ( 0 ) === 92 ) {
if ( resolvedPath . charCodeAt ( 1 ) === 92 ) {
const code = resolvedPath . charCodeAt ( 2 ) ;
if ( code !== 63 && code !== 46 ) {
return ` \\ \\ ? \\ UNC \\ ${ resolvedPath . slice ( 2 ) } ` ;
}
}
} else if ( isWindowsDeviceRoot ( resolvedPath . charCodeAt ( 0 ) ) ) {
if ( resolvedPath . charCodeAt ( 1 ) === 58 && resolvedPath . charCodeAt ( 2 ) === 92 ) {
return ` \\ \\ ? \\ ${ resolvedPath } ` ;
}
}
}
return path ;
}
function dirname ( path ) {
assertPath ( path ) ;
const len = path . length ;
if ( len === 0 ) return "." ;
let rootEnd = - 1 ;
let end = - 1 ;
let matchedSlash = true ;
let offset = 0 ;
const code = path . charCodeAt ( 0 ) ;
if ( len > 1 ) {
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( code ) ) {
2021-02-26 12:21:42 +03:00
rootEnd = offset = 1 ;
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( path . charCodeAt ( 1 ) ) ) {
2021-02-26 12:21:42 +03:00
let j = 2 ;
let last = j ;
for ( ; j < len ; ++ j ) {
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( path . charCodeAt ( j ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( j < len && j !== last ) {
last = j ;
for ( ; j < len ; ++ j ) {
2021-10-21 08:12:50 +03:00
if ( ! isPathSeparator1 ( path . charCodeAt ( j ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( j < len && j !== last ) {
last = j ;
for ( ; j < len ; ++ j ) {
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( path . charCodeAt ( j ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( j === len ) {
return path ;
}
if ( j !== last ) {
rootEnd = offset = j + 1 ;
}
}
}
}
} else if ( isWindowsDeviceRoot ( code ) ) {
if ( path . charCodeAt ( 1 ) === 58 ) {
rootEnd = offset = 2 ;
if ( len > 2 ) {
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( path . charCodeAt ( 2 ) ) ) rootEnd = offset = 3 ;
2021-02-26 12:21:42 +03:00
}
}
}
2021-10-21 08:12:50 +03:00
} else if ( isPathSeparator1 ( code ) ) {
2021-02-26 12:21:42 +03:00
return path ;
}
for ( let i = len - 1 ; i >= offset ; -- i ) {
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( path . charCodeAt ( i ) ) ) {
2021-02-26 12:21:42 +03:00
if ( ! matchedSlash ) {
end = i ;
break ;
}
} else {
matchedSlash = false ;
}
}
if ( end === - 1 ) {
if ( rootEnd === - 1 ) return "." ;
else end = rootEnd ;
}
return path . slice ( 0 , end ) ;
}
function basename ( path , ext = "" ) {
if ( ext !== undefined && typeof ext !== "string" ) {
throw new TypeError ( '"ext" argument must be a string' ) ;
}
assertPath ( path ) ;
let start = 0 ;
let end = - 1 ;
let matchedSlash = true ;
let i ;
if ( path . length >= 2 ) {
const drive = path . charCodeAt ( 0 ) ;
if ( isWindowsDeviceRoot ( drive ) ) {
if ( path . charCodeAt ( 1 ) === 58 ) start = 2 ;
}
}
if ( ext !== undefined && ext . length > 0 && ext . length <= path . length ) {
if ( ext . length === path . length && ext === path ) return "" ;
let extIdx = ext . length - 1 ;
let firstNonSlashEnd = - 1 ;
for ( i = path . length - 1 ; i >= start ; -- i ) {
const code = path . charCodeAt ( i ) ;
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( code ) ) {
2021-02-26 12:21:42 +03:00
if ( ! matchedSlash ) {
start = i + 1 ;
break ;
}
} else {
if ( firstNonSlashEnd === - 1 ) {
matchedSlash = false ;
firstNonSlashEnd = i + 1 ;
}
if ( extIdx >= 0 ) {
if ( code === ext . charCodeAt ( extIdx ) ) {
2021-07-22 10:33:00 +03:00
if ( -- extIdx === - 1 ) {
2021-02-26 12:21:42 +03:00
end = i ;
}
} else {
extIdx = - 1 ;
end = firstNonSlashEnd ;
}
}
}
}
if ( start === end ) end = firstNonSlashEnd ;
else if ( end === - 1 ) end = path . length ;
return path . slice ( start , end ) ;
} else {
for ( i = path . length - 1 ; i >= start ; -- i ) {
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( path . charCodeAt ( i ) ) ) {
2021-02-26 12:21:42 +03:00
if ( ! matchedSlash ) {
start = i + 1 ;
break ;
}
} else if ( end === - 1 ) {
matchedSlash = false ;
end = i + 1 ;
}
}
if ( end === - 1 ) return "" ;
return path . slice ( start , end ) ;
}
}
function extname ( path ) {
assertPath ( path ) ;
let start = 0 ;
let startDot = - 1 ;
let startPart = 0 ;
let end = - 1 ;
let matchedSlash = true ;
let preDotState = 0 ;
if ( path . length >= 2 && path . charCodeAt ( 1 ) === 58 && isWindowsDeviceRoot ( path . charCodeAt ( 0 ) ) ) {
start = startPart = 2 ;
}
for ( let i = path . length - 1 ; i >= start ; -- i ) {
const code = path . charCodeAt ( i ) ;
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( code ) ) {
2021-02-26 12:21:42 +03:00
if ( ! matchedSlash ) {
startPart = i + 1 ;
break ;
}
continue ;
}
if ( end === - 1 ) {
matchedSlash = false ;
end = i + 1 ;
}
if ( code === 46 ) {
if ( startDot === - 1 ) startDot = i ;
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 "" ;
}
return path . slice ( startDot , end ) ;
}
2021-09-01 16:11:55 +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 ) ;
}
function parse1 ( path ) {
assertPath ( path ) ;
const ret = {
root : "" ,
dir : "" ,
base : "" ,
ext : "" ,
name : ""
} ;
const len = path . length ;
if ( len === 0 ) return ret ;
let rootEnd = 0 ;
let code = path . charCodeAt ( 0 ) ;
if ( len > 1 ) {
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( code ) ) {
2021-02-26 12:21:42 +03:00
rootEnd = 1 ;
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( path . charCodeAt ( 1 ) ) ) {
2021-02-26 12:21:42 +03:00
let j = 2 ;
let last = j ;
for ( ; j < len ; ++ j ) {
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( path . charCodeAt ( j ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( j < len && j !== last ) {
last = j ;
for ( ; j < len ; ++ j ) {
2021-10-21 08:12:50 +03:00
if ( ! isPathSeparator1 ( path . charCodeAt ( j ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( j < len && j !== last ) {
last = j ;
for ( ; j < len ; ++ j ) {
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( path . charCodeAt ( j ) ) ) break ;
2021-02-26 12:21:42 +03:00
}
if ( j === len ) {
rootEnd = j ;
} else if ( j !== last ) {
rootEnd = j + 1 ;
}
}
}
}
} else if ( isWindowsDeviceRoot ( code ) ) {
if ( path . charCodeAt ( 1 ) === 58 ) {
rootEnd = 2 ;
if ( len > 2 ) {
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( path . charCodeAt ( 2 ) ) ) {
2021-02-26 12:21:42 +03:00
if ( len === 3 ) {
ret . root = ret . dir = path ;
return ret ;
}
rootEnd = 3 ;
}
} else {
ret . root = ret . dir = path ;
return ret ;
}
}
}
2021-10-21 08:12:50 +03:00
} else if ( isPathSeparator1 ( code ) ) {
2021-02-26 12:21:42 +03:00
ret . root = ret . dir = path ;
return ret ;
}
if ( rootEnd > 0 ) ret . root = path . slice ( 0 , rootEnd ) ;
let startDot = - 1 ;
let startPart = rootEnd ;
let end = - 1 ;
let matchedSlash = true ;
let i = path . length - 1 ;
let preDotState = 0 ;
for ( ; i >= rootEnd ; -- i ) {
code = path . charCodeAt ( i ) ;
2021-10-21 08:12:50 +03:00
if ( isPathSeparator1 ( code ) ) {
2021-02-26 12:21:42 +03:00
if ( ! matchedSlash ) {
startPart = i + 1 ;
break ;
}
continue ;
}
if ( end === - 1 ) {
matchedSlash = false ;
end = i + 1 ;
}
if ( code === 46 ) {
if ( startDot === - 1 ) startDot = i ;
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 ) {
ret . base = ret . name = path . slice ( startPart , end ) ;
}
} else {
ret . name = path . slice ( startPart , startDot ) ;
ret . base = path . slice ( startPart , end ) ;
ret . ext = path . slice ( startDot , end ) ;
}
if ( startPart > 0 && startPart !== rootEnd ) {
ret . dir = path . slice ( 0 , startPart - 1 ) ;
} 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." ) ;
}
let path = decodeURIComponent ( url . pathname . replace ( /\//g , "\\" ) . replace ( /%(?![0-9A-Fa-f]{2})/g , "%25" ) ) . replace ( /^\\*([A-Za-z]:)(\\|$)/ , "$1\\" ) ;
if ( url . hostname != "" ) {
path = ` \\ \\ ${ url . hostname } ${ path } ` ;
}
return path ;
}
function toFileUrl ( path ) {
2021-10-21 08:12:50 +03:00
if ( ! isAbsolute3 ( path ) ) {
2021-02-26 12:21:42 +03:00
throw new TypeError ( "Must be an absolute path." ) ;
}
const [ , hostname , pathname ] = path . match ( /^(?:[/\\]{2}([^/\\]+)(?=[/\\][^/\\]))?(.*)/ ) ;
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 = {
sep : sep3 ,
delimiter : delimiter ,
resolve : resolve ,
normalize : normalize ,
2021-10-21 08:12:50 +03:00
isAbsolute : isAbsolute3 ,
2021-10-08 10:47:01 +03:00
join : join ,
relative : relative ,
toNamespacedPath : toNamespacedPath ,
dirname : dirname ,
basename : basename ,
extname : extname ,
format : format ,
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 ;
for ( let i = pathSegments . length - 1 ; i >= - 1 && ! resolvedAbsolute ; i -- ) {
let path ;
if ( i >= 0 ) path = pathSegments [ i ] ;
else {
if ( globalThis . Deno == null ) {
throw new TypeError ( "Resolved a relative path without a CWD." ) ;
}
path = Deno . cwd ( ) ;
}
assertPath ( path ) ;
if ( path . length === 0 ) {
continue ;
}
resolvedPath = ` ${ path } / ${ resolvedPath } ` ;
resolvedAbsolute = path . charCodeAt ( 0 ) === CHAR_FORWARD_SLASH ;
}
resolvedPath = normalizeString ( resolvedPath , ! resolvedAbsolute , "/" , isPosixPathSeparator ) ;
if ( resolvedAbsolute ) {
if ( resolvedPath . length > 0 ) return ` / ${ resolvedPath } ` ;
else return "/" ;
} else if ( resolvedPath . length > 0 ) return resolvedPath ;
else return "." ;
}
function normalize1 ( path ) {
assertPath ( path ) ;
if ( path . length === 0 ) return "." ;
2021-09-01 16:11:55 +03:00
const isAbsolute = path . charCodeAt ( 0 ) === 47 ;
2021-02-26 12:21:42 +03:00
const trailingSeparator = path . charCodeAt ( path . length - 1 ) === 47 ;
2021-09-01 16:11:55 +03:00
path = normalizeString ( path , ! isAbsolute , "/" , isPosixPathSeparator ) ;
if ( path . length === 0 && ! isAbsolute ) path = "." ;
2021-02-26 12:21:42 +03:00
if ( path . length > 0 && trailingSeparator ) path += "/" ;
2021-09-01 16:11:55 +03:00
if ( isAbsolute ) return ` / ${ path } ` ;
2021-02-26 12:21:42 +03:00
return path ;
}
function isAbsolute1 ( path ) {
assertPath ( path ) ;
return path . length > 0 && path . charCodeAt ( 0 ) === 47 ;
}
function join1 ( . . . paths ) {
if ( paths . length === 0 ) return "." ;
let joined ;
for ( let i = 0 , len = paths . length ; i < len ; ++ i ) {
const path = paths [ i ] ;
assertPath ( path ) ;
if ( path . length > 0 ) {
if ( ! joined ) joined = path ;
else joined += ` / ${ path } ` ;
}
}
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 ) !== 47 ) break ;
}
const fromLen = fromEnd - fromStart ;
let toStart = 1 ;
const toEnd = to . length ;
for ( ; toStart < toEnd ; ++ toStart ) {
if ( to . charCodeAt ( toStart ) !== 47 ) break ;
}
const toLen = toEnd - toStart ;
const length = fromLen < toLen ? fromLen : toLen ;
let lastCommonSep = - 1 ;
let i = 0 ;
for ( ; i <= length ; ++ i ) {
if ( i === length ) {
if ( toLen > length ) {
if ( to . charCodeAt ( toStart + i ) === 47 ) {
return to . slice ( toStart + i + 1 ) ;
} else if ( i === 0 ) {
return to . slice ( toStart + i ) ;
}
} else if ( fromLen > length ) {
if ( from . charCodeAt ( fromStart + i ) === 47 ) {
lastCommonSep = i ;
} else if ( i === 0 ) {
lastCommonSep = 0 ;
}
}
break ;
}
const fromCode = from . charCodeAt ( fromStart + i ) ;
const toCode = to . charCodeAt ( toStart + i ) ;
if ( fromCode !== toCode ) break ;
else if ( fromCode === 47 ) lastCommonSep = i ;
}
let out = "" ;
for ( i = fromStart + lastCommonSep + 1 ; i <= fromEnd ; ++ i ) {
if ( i === fromEnd || from . charCodeAt ( i ) === 47 ) {
if ( out . length === 0 ) out += ".." ;
else out += "/.." ;
}
}
if ( out . length > 0 ) return out + to . slice ( toStart + lastCommonSep ) ;
else {
toStart += lastCommonSep ;
if ( to . charCodeAt ( toStart ) === 47 ) ++ toStart ;
return to . slice ( toStart ) ;
}
}
function toNamespacedPath1 ( path ) {
return path ;
}
function dirname1 ( path ) {
assertPath ( path ) ;
if ( path . length === 0 ) return "." ;
const hasRoot = path . charCodeAt ( 0 ) === 47 ;
let end = - 1 ;
let matchedSlash = true ;
for ( let i = path . length - 1 ; i >= 1 ; -- i ) {
if ( path . charCodeAt ( i ) === 47 ) {
if ( ! matchedSlash ) {
end = i ;
break ;
}
} else {
matchedSlash = false ;
}
}
if ( end === - 1 ) return hasRoot ? "/" : "." ;
if ( hasRoot && end === 1 ) return "//" ;
return path . slice ( 0 , end ) ;
}
function basename1 ( path , ext = "" ) {
if ( ext !== undefined && typeof ext !== "string" ) {
throw new TypeError ( '"ext" argument must be a string' ) ;
}
assertPath ( path ) ;
let start = 0 ;
let end = - 1 ;
let matchedSlash = true ;
let i ;
if ( ext !== undefined && ext . length > 0 && ext . length <= path . length ) {
if ( ext . length === path . length && ext === path ) return "" ;
let extIdx = ext . length - 1 ;
let firstNonSlashEnd = - 1 ;
for ( i = path . length - 1 ; i >= 0 ; -- i ) {
const code = path . charCodeAt ( i ) ;
if ( code === 47 ) {
if ( ! matchedSlash ) {
start = i + 1 ;
break ;
}
} else {
if ( firstNonSlashEnd === - 1 ) {
matchedSlash = false ;
firstNonSlashEnd = i + 1 ;
}
if ( extIdx >= 0 ) {
if ( code === ext . charCodeAt ( extIdx ) ) {
2021-07-22 10:33:00 +03:00
if ( -- extIdx === - 1 ) {
2021-02-26 12:21:42 +03:00
end = i ;
}
} else {
extIdx = - 1 ;
end = firstNonSlashEnd ;
}
}
}
}
if ( start === end ) end = firstNonSlashEnd ;
else if ( end === - 1 ) end = path . length ;
return path . slice ( start , end ) ;
} else {
for ( i = path . length - 1 ; i >= 0 ; -- i ) {
if ( path . charCodeAt ( i ) === 47 ) {
if ( ! matchedSlash ) {
start = i + 1 ;
break ;
}
} else if ( end === - 1 ) {
matchedSlash = false ;
end = i + 1 ;
}
}
if ( end === - 1 ) return "" ;
return path . slice ( start , end ) ;
}
}
function extname1 ( path ) {
assertPath ( path ) ;
let startDot = - 1 ;
let startPart = 0 ;
let end = - 1 ;
let matchedSlash = true ;
let preDotState = 0 ;
for ( let i = path . length - 1 ; i >= 0 ; -- i ) {
const code = path . charCodeAt ( i ) ;
if ( code === 47 ) {
if ( ! matchedSlash ) {
startPart = i + 1 ;
break ;
}
continue ;
}
if ( end === - 1 ) {
matchedSlash = false ;
end = i + 1 ;
}
if ( code === 46 ) {
if ( startDot === - 1 ) startDot = i ;
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 "" ;
}
return path . slice ( startDot , end ) ;
}
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 ) ;
}
function parse2 ( path ) {
assertPath ( path ) ;
const ret = {
root : "" ,
dir : "" ,
base : "" ,
ext : "" ,
name : ""
} ;
if ( path . length === 0 ) return ret ;
2021-09-01 16:11:55 +03:00
const isAbsolute = path . charCodeAt ( 0 ) === 47 ;
2021-02-26 12:21:42 +03:00
let start ;
2021-09-01 16:11:55 +03:00
if ( isAbsolute ) {
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 ;
let i = path . length - 1 ;
let preDotState = 0 ;
for ( ; i >= start ; -- i ) {
const code = path . charCodeAt ( i ) ;
if ( code === 47 ) {
if ( ! matchedSlash ) {
startPart = i + 1 ;
break ;
}
continue ;
}
if ( end === - 1 ) {
matchedSlash = false ;
end = i + 1 ;
}
if ( code === 46 ) {
if ( startDot === - 1 ) startDot = i ;
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-09-01 16:11:55 +03:00
if ( startPart === 0 && isAbsolute ) {
2021-02-26 12:21:42 +03:00
ret . base = ret . name = path . slice ( 1 , end ) ;
} else {
ret . base = ret . name = path . slice ( startPart , end ) ;
}
}
} else {
2021-09-01 16:11:55 +03:00
if ( startPart === 0 && isAbsolute ) {
2021-02-26 12:21:42 +03:00
ret . name = path . slice ( 1 , startDot ) ;
ret . base = path . slice ( 1 , end ) ;
} else {
ret . name = path . slice ( startPart , startDot ) ;
ret . base = path . slice ( startPart , end ) ;
}
ret . ext = path . slice ( startDot , end ) ;
}
if ( startPart > 0 ) ret . dir = path . slice ( 0 , startPart - 1 ) ;
2021-09-01 16:11:55 +03:00
else if ( isAbsolute ) 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" ) ) ;
}
function toFileUrl1 ( path ) {
if ( ! isAbsolute1 ( path ) ) {
throw new TypeError ( "Must be an absolute path." ) ;
}
const url = new URL ( "file:///" ) ;
url . pathname = path . replace ( /%/g , "%25" ) . replace ( /\\/g , "%5C" ) ;
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-09-01 16:11:55 +03:00
function common ( paths , sep = SEP ) {
2021-02-26 12:21:42 +03:00
const [ first = "" , . . . remaining ] = paths ;
if ( first === "" || remaining . length === 0 ) {
2021-09-01 16:11:55 +03:00
return first . substring ( 0 , first . lastIndexOf ( sep ) + 1 ) ;
2021-02-26 12:21:42 +03:00
}
2021-09-01 16:11:55 +03:00
const parts = first . split ( sep ) ;
2021-02-26 12:21:42 +03:00
let endOfPrefix = parts . length ;
2021-07-01 15:56:08 +03:00
for ( const path of remaining ) {
2021-09-01 16:11:55 +03:00
const compare = path . split ( sep ) ;
2021-02-26 12:21:42 +03:00
for ( let i = 0 ; i < endOfPrefix ; i ++ ) {
if ( compare [ i ] !== parts [ i ] ) {
endOfPrefix = i ;
}
}
if ( endOfPrefix === 0 ) {
return "" ;
}
}
2021-09-01 16:11:55 +03:00
const prefix = parts . slice ( 0 , endOfPrefix ) . join ( sep ) ;
return prefix . endsWith ( sep ) ? prefix : ` ${ prefix } ${ sep } ` ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
const path1 = isWindows ? mod1 : mod2 ;
2021-07-01 15:56:08 +03:00
const regExpEscapeChars = [
"!" ,
"$" ,
"(" ,
")" ,
"*" ,
"+" ,
"." ,
"=" ,
"?" ,
"[" ,
"\\" ,
"^" ,
"{" ,
"|"
] ;
2021-10-21 08:12:50 +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 , } = path1 ;
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-09-01 16:11:55 +03:00
const sep = 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 ;
let i = j ;
for ( ; i < glob . length && ! seps . includes ( glob [ i ] ) ; i ++ ) {
if ( inEscape ) {
inEscape = false ;
const escapeChars = inRange ? rangeEscapeChars : regExpEscapeChars ;
segment += escapeChars . includes ( glob [ i ] ) ? ` \\ ${ glob [ i ] } ` : glob [ i ] ;
continue ;
}
if ( glob [ i ] == escapePrefix ) {
inEscape = true ;
continue ;
}
if ( glob [ i ] == "[" ) {
if ( ! inRange ) {
inRange = true ;
segment += "[" ;
if ( glob [ i + 1 ] == "!" ) {
i ++ ;
segment += "^" ;
} else if ( glob [ i + 1 ] == "^" ) {
i ++ ;
segment += "\\^" ;
}
continue ;
} else if ( glob [ i + 1 ] == ":" ) {
let k = i + 1 ;
let value = "" ;
while ( glob [ k + 1 ] != null && glob [ k + 1 ] != ":" ) {
value += glob [ k + 1 ] ;
k ++ ;
}
if ( glob [ k + 1 ] == ":" && glob [ k + 2 ] == "]" ) {
i = k + 2 ;
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 ;
}
}
}
if ( glob [ i ] == "]" && inRange ) {
inRange = false ;
segment += "]" ;
continue ;
}
if ( inRange ) {
if ( glob [ i ] == "\\" ) {
segment += ` \\ \\ ` ;
} else {
segment += glob [ i ] ;
}
continue ;
}
if ( glob [ i ] == ")" && groupStack . length > 0 && groupStack [ groupStack . length - 1 ] != "BRACE" ) {
segment += ")" ;
const type = groupStack . pop ( ) ;
if ( type == "!" ) {
segment += wildcard ;
} else if ( type != "@" ) {
segment += type ;
}
continue ;
}
if ( glob [ i ] == "|" && groupStack . length > 0 && groupStack [ groupStack . length - 1 ] != "BRACE" ) {
segment += "|" ;
continue ;
}
if ( glob [ i ] == "+" && extended && glob [ i + 1 ] == "(" ) {
i ++ ;
groupStack . push ( "+" ) ;
segment += "(?:" ;
continue ;
}
if ( glob [ i ] == "@" && extended && glob [ i + 1 ] == "(" ) {
i ++ ;
groupStack . push ( "@" ) ;
segment += "(?:" ;
continue ;
}
if ( glob [ i ] == "?" ) {
if ( extended && glob [ i + 1 ] == "(" ) {
i ++ ;
groupStack . push ( "?" ) ;
segment += "(?:" ;
} else {
segment += "." ;
}
continue ;
}
if ( glob [ i ] == "!" && extended && glob [ i + 1 ] == "(" ) {
i ++ ;
groupStack . push ( "!" ) ;
segment += "(?!" ;
continue ;
}
if ( glob [ i ] == "{" ) {
groupStack . push ( "BRACE" ) ;
segment += "(?:" ;
continue ;
}
if ( glob [ i ] == "}" && groupStack [ groupStack . length - 1 ] == "BRACE" ) {
groupStack . pop ( ) ;
segment += ")" ;
continue ;
}
if ( glob [ i ] == "," && groupStack [ groupStack . length - 1 ] == "BRACE" ) {
segment += "|" ;
continue ;
}
if ( glob [ i ] == "*" ) {
if ( extended && glob [ i + 1 ] == "(" ) {
i ++ ;
groupStack . push ( "*" ) ;
segment += "(?:" ;
} else {
const prevChar = glob [ i - 1 ] ;
let numStars = 1 ;
while ( glob [ i + 1 ] == "*" ) {
i ++ ;
numStars ++ ;
}
const nextChar = glob [ i + 1 ] ;
if ( globstarOption && numStars == 2 && [
. . . seps ,
undefined
] . includes ( prevChar ) && [
. . . seps ,
undefined
] . includes ( nextChar ) ) {
segment += globstar ;
endsWithSep = true ;
} else {
segment += wildcard ;
}
}
continue ;
}
segment += regExpEscapeChars . includes ( glob [ i ] ) ? ` \\ ${ glob [ i ] } ` : glob [ i ] ;
}
if ( groupStack . length > 0 || inRange || inEscape ) {
segment = "" ;
for ( const c of glob . slice ( j , i ) ) {
segment += regExpEscapeChars . includes ( c ) ? ` \\ ${ c } ` : c ;
endsWithSep = false ;
}
}
regExpString += segment ;
if ( ! endsWithSep ) {
2021-09-01 16:11:55 +03:00
regExpString += i < glob . length ? sep : sepMaybe ;
2021-02-26 12:21:42 +03:00
endsWithSep = true ;
}
while ( seps . includes ( glob [ i ] ) ) i ++ ;
if ( ! ( i > j ) ) {
throw new Error ( "Assertion failure: i > j (potential infinite loop)" ) ;
}
j = i ;
}
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-09-01 16:11:55 +03:00
const path = glob ;
if ( path . length > 0 ) {
if ( ! joined ) joined = path ;
else joined += ` ${ SEP } ${ path } ` ;
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 : mod1 ,
posix : mod2 ,
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-10-21 08:12:50 +03:00
var LogLevels1 ;
2021-09-01 16:11:55 +03:00
( function ( LogLevels ) {
LogLevels [ LogLevels [ "NOTSET" ] = 0 ] = "NOTSET" ;
LogLevels [ LogLevels [ "DEBUG" ] = 10 ] = "DEBUG" ;
LogLevels [ LogLevels [ "INFO" ] = 20 ] = "INFO" ;
LogLevels [ LogLevels [ "WARNING" ] = 30 ] = "WARNING" ;
LogLevels [ LogLevels [ "ERROR" ] = 40 ] = "ERROR" ;
LogLevels [ LogLevels [ "CRITICAL" ] = 50 ] = "CRITICAL" ;
2021-10-21 08:12:50 +03:00
} ) ( LogLevels1 || ( LogLevels1 = {
2021-02-26 12:21:42 +03:00
} ) ) ;
2021-10-21 08:12:50 +03:00
Object . keys ( LogLevels1 ) . filter ( ( key ) = > isNaN ( Number ( key ) )
2021-10-08 10:47:01 +03:00
) ;
2021-02-26 12:21:42 +03:00
const byLevel = {
2021-10-21 08:12:50 +03:00
[ String ( LogLevels1 . NOTSET ) ] : "NOTSET" ,
[ String ( LogLevels1 . DEBUG ) ] : "DEBUG" ,
[ String ( LogLevels1 . INFO ) ] : "INFO" ,
[ String ( LogLevels1 . WARNING ) ] : "WARNING" ,
[ String ( LogLevels1 . ERROR ) ] : "ERROR" ,
[ String ( LogLevels1 . CRITICAL ) ] : "CRITICAL"
2021-02-26 12:21:42 +03:00
} ;
function getLevelByName ( name ) {
switch ( name ) {
case "NOTSET" :
2021-10-21 08:12:50 +03:00
return LogLevels1 . NOTSET ;
2021-02-26 12:21:42 +03:00
case "DEBUG" :
2021-10-21 08:12:50 +03:00
return LogLevels1 . DEBUG ;
2021-02-26 12:21:42 +03:00
case "INFO" :
2021-10-21 08:12:50 +03:00
return LogLevels1 . INFO ;
2021-02-26 12:21:42 +03:00
case "WARNING" :
2021-10-21 08:12:50 +03:00
return LogLevels1 . WARNING ;
2021-02-26 12:21:42 +03:00
case "ERROR" :
2021-10-21 08:12:50 +03:00
return LogLevels1 . ERROR ;
2021-02-26 12:21:42 +03:00
case "CRITICAL" :
2021-10-21 08:12:50 +03:00
return LogLevels1 . 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-10-21 08:12:50 +03:00
constructor ( options5 ) {
this . msg = options5 . msg ;
2021-02-26 12:21:42 +03:00
this . # args = [
2021-10-21 08:12:50 +03:00
. . . options5 . args
2021-02-26 12:21:42 +03:00
] ;
2021-10-21 08:12:50 +03:00
this . level = options5 . level ;
this . loggerName = options5 . loggerName ;
2021-02-26 12:21:42 +03:00
this . # datetime = new Date ( ) ;
2021-10-21 08:12:50 +03:00
this . levelName = getLevelName ( options5 . 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-10-21 08:12:50 +03:00
constructor ( loggerName1 , levelName5 , options1 = {
2021-02-26 12:21:42 +03:00
} ) {
2021-10-21 08:12:50 +03:00
this . # loggerName = loggerName1 ;
this . # level = getLevelByName ( levelName5 ) ;
this . # handlers = options1 . 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-10-21 08:12:50 +03:00
set levelName ( levelName1 ) {
this . # level = getLevelByName ( levelName1 ) ;
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-10-21 08:12:50 +03:00
_log ( level1 , msg9 , . . . args6 ) {
if ( this . level > level1 ) {
return msg9 instanceof Function ? undefined : msg9 ;
2021-02-26 12:21:42 +03:00
}
let fnResult ;
let logMessage ;
2021-10-21 08:12:50 +03:00
if ( msg9 instanceof Function ) {
fnResult = msg9 ( ) ;
2021-02-26 12:21:42 +03:00
logMessage = this . asString ( fnResult ) ;
} else {
2021-10-21 08:12:50 +03:00
logMessage = this . asString ( msg9 ) ;
2021-02-26 12:21:42 +03:00
}
const record = new LogRecord ( {
msg : logMessage ,
2021-10-21 08:12:50 +03:00
args : args6 ,
level : level1 ,
2021-02-26 12:21:42 +03:00
loggerName : this.loggerName
} ) ;
this . # handlers . forEach ( ( handler ) = > {
handler . handle ( record ) ;
} ) ;
2021-10-21 08:12:50 +03:00
return msg9 instanceof Function ? fnResult : msg9 ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
asString ( data3 ) {
if ( typeof data3 === "string" ) {
return data3 ;
} else if ( data3 === null || typeof data3 === "number" || typeof data3 === "bigint" || typeof data3 === "boolean" || typeof data3 === "undefined" || typeof data3 === "symbol" ) {
return String ( data3 ) ;
} else if ( typeof data3 === "object" ) {
return JSON . stringify ( data3 ) ;
2021-02-26 12:21:42 +03:00
}
return "undefined" ;
}
2021-10-21 08:12:50 +03:00
debug ( msg1 , . . . args1 ) {
return this . _log ( LogLevels1 . DEBUG , msg1 , . . . args1 ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
info ( msg2 , . . . args2 ) {
return this . _log ( LogLevels1 . INFO , msg2 , . . . args2 ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
warning ( msg3 , . . . args3 ) {
return this . _log ( LogLevels1 . WARNING , msg3 , . . . args3 ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
error ( msg4 , . . . args4 ) {
return this . _log ( LogLevels1 . ERROR , msg4 , . . . args4 ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
critical ( msg5 , . . . args5 ) {
return this . _log ( LogLevels1 . CRITICAL , msg5 , . . . args5 ) ;
2021-02-26 12:21:42 +03:00
}
}
const noColor = globalThis . Deno ? . noColor ? ? true ;
let enabled = ! noColor ;
2021-10-21 08:12:50 +03:00
function code1 ( 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-10-21 08:12:50 +03:00
function run1 ( str , code ) {
2021-09-01 16:11:55 +03:00
return enabled ? ` ${ code . open } ${ str . replace ( code . regexp , code . open ) } ${ code . close } ` : str ;
2021-02-26 12:21:42 +03:00
}
function bold ( str ) {
2021-10-21 08:12:50 +03:00
return run1 ( str , code1 ( [
2021-02-26 12:21:42 +03:00
1
] , 22 ) ) ;
}
function red ( str ) {
2021-10-21 08:12:50 +03:00
return run1 ( str , code1 ( [
2021-02-26 12:21:42 +03:00
31
] , 39 ) ) ;
}
function yellow ( str ) {
2021-10-21 08:12:50 +03:00
return run1 ( str , code1 ( [
2021-02-26 12:21:42 +03:00
33
] , 39 ) ) ;
}
function blue ( str ) {
2021-10-21 08:12:50 +03:00
return run1 ( str , code1 ( [
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 ;
}
}
function copyBytes ( src , dst , off = 0 ) {
off = Math . max ( 0 , Math . min ( off , dst . byteLength ) ) ;
const dstBytesAvailable = dst . byteLength - off ;
if ( src . byteLength > dstBytesAvailable ) {
src = src . subarray ( 0 , dstBytesAvailable ) ;
}
dst . set ( src , off ) ;
return src . byteLength ;
}
const DEFAULT_BUF_SIZE = 4096 ;
const MIN_BUF_SIZE = 16 ;
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-10-21 08:12:50 +03:00
static create ( r2 , size6 = 4096 ) {
return r2 instanceof BufReader ? r2 : new BufReader ( r2 , size6 ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
constructor ( rd , size1 = 4096 ) {
2021-03-21 16:31:35 +03:00
this . r = 0 ;
this . w = 0 ;
this . eof = false ;
2021-10-21 08:12:50 +03:00
if ( size1 < 16 ) {
size1 = MIN_BUF_SIZE ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
this . _reset ( new Uint8Array ( size1 ) , 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" ) ;
}
for ( let i = 100 ; i > 0 ; i -- ) {
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 ${ 100 } read() calls ` ) ;
}
2021-10-21 08:12:50 +03:00
reset ( r1 ) {
this . _reset ( this . buf , r1 ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
_reset ( buf1 , rd1 ) {
this . buf = buf1 ;
this . rd = rd1 ;
2021-02-26 12:21:42 +03:00
this . eof = false ;
}
2021-10-21 08:12:50 +03:00
async read ( p2 ) {
let rr = p2 . byteLength ;
if ( p2 . byteLength === 0 ) return rr ;
2021-02-26 12:21:42 +03:00
if ( this . r === this . w ) {
2021-10-21 08:12:50 +03:00
if ( p2 . byteLength >= this . buf . byteLength ) {
const rr = await this . rd . read ( p2 ) ;
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-10-21 08:12:50 +03:00
const copied = copyBytes ( this . buf . subarray ( this . r , this . w ) , p2 , 0 ) ;
2021-02-26 12:21:42 +03:00
this . r += copied ;
return copied ;
}
2021-10-21 08:12:50 +03:00
async readFull ( p1 ) {
2021-02-26 12:21:42 +03:00
let bytesRead = 0 ;
2021-10-21 08:12:50 +03:00
while ( bytesRead < p1 . length ) {
2021-02-26 12:21:42 +03:00
try {
2021-10-21 08:12:50 +03:00
const rr = await this . read ( p1 . 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-10-21 08:12:50 +03:00
err . partial = p1 . subarray ( 0 , bytesRead ) ;
2021-02-26 12:21:42 +03:00
throw err ;
}
}
2021-10-21 08:12:50 +03:00
return p1 ;
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-10-21 08:12:50 +03:00
async readSlice ( delim1 ) {
2021-02-26 12:21:42 +03:00
let s = 0 ;
let slice ;
while ( true ) {
2021-10-21 08:12:50 +03:00
let i = this . buf . subarray ( this . r + s , this . w ) . indexOf ( delim1 ) ;
2021-02-26 12:21:42 +03:00
if ( i >= 0 ) {
i += s ;
slice = this . buf . subarray ( this . r , this . r + i + 1 ) ;
this . r += i + 1 ;
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-10-21 08:12:50 +03:00
async peek ( n1 ) {
if ( n1 < 0 ) {
2021-02-26 12:21:42 +03:00
throw Error ( "negative count" ) ;
}
let avail = this . w - this . r ;
2021-10-21 08:12:50 +03:00
while ( avail < n1 && 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-10-21 08:12:50 +03:00
} else if ( avail < n1 && this . eof ) {
2021-02-26 12:21:42 +03:00
return this . buf . subarray ( this . r , this . r + avail ) ;
2021-10-21 08:12:50 +03:00
} else if ( avail < n1 ) {
2021-02-26 12:21:42 +03:00
throw new BufferFullError ( this . buf . subarray ( this . r , this . w ) ) ;
}
2021-10-21 08:12:50 +03:00
return this . buf . subarray ( this . r , this . r + n1 ) ;
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-10-21 08:12:50 +03:00
static create ( writer , size2 = 4096 ) {
return writer instanceof BufWriter ? writer : new BufWriter ( writer , size2 ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
constructor ( writer1 , size3 = 4096 ) {
2021-02-26 12:21:42 +03:00
super ( ) ;
2021-10-21 08:12:50 +03:00
this . writer = writer1 ;
if ( size3 <= 0 ) {
size3 = DEFAULT_BUF_SIZE ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
this . buf = new Uint8Array ( size3 ) ;
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-10-21 08:12:50 +03:00
async write ( data1 ) {
2021-02-26 12:21:42 +03:00
if ( this . err !== null ) throw this . err ;
2021-10-21 08:12:50 +03:00
if ( data1 . length === 0 ) return 0 ;
2021-02-26 12:21:42 +03:00
let totalBytesWritten = 0 ;
let numBytesWritten = 0 ;
2021-10-21 08:12:50 +03:00
while ( data1 . byteLength > this . available ( ) ) {
2021-02-26 12:21:42 +03:00
if ( this . buffered ( ) === 0 ) {
try {
2021-10-21 08:12:50 +03:00
numBytesWritten = await this . writer . write ( data1 ) ;
2021-02-26 12:21:42 +03:00
} catch ( e ) {
this . err = e ;
throw e ;
}
} else {
2021-10-21 08:12:50 +03:00
numBytesWritten = copyBytes ( data1 , this . buf , this . usedBufferBytes ) ;
2021-02-26 12:21:42 +03:00
this . usedBufferBytes += numBytesWritten ;
await this . flush ( ) ;
}
totalBytesWritten += numBytesWritten ;
2021-10-21 08:12:50 +03:00
data1 = data1 . subarray ( numBytesWritten ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
numBytesWritten = copyBytes ( data1 , this . buf , this . usedBufferBytes ) ;
2021-02-26 12:21:42 +03:00
this . usedBufferBytes += numBytesWritten ;
totalBytesWritten += numBytesWritten ;
return totalBytesWritten ;
}
}
class BufWriterSync extends AbstractBufBase {
2021-10-21 08:12:50 +03:00
static create ( writer2 , size4 = 4096 ) {
return writer2 instanceof BufWriterSync ? writer2 : new BufWriterSync ( writer2 , size4 ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
constructor ( writer3 , size5 = 4096 ) {
2021-02-26 12:21:42 +03:00
super ( ) ;
2021-10-21 08:12:50 +03:00
this . writer = writer3 ;
if ( size5 <= 0 ) {
size5 = DEFAULT_BUF_SIZE ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
this . buf = new Uint8Array ( size5 ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
reset ( w1 ) {
2021-02-26 12:21:42 +03:00
this . err = null ;
this . usedBufferBytes = 0 ;
2021-10-21 08:12:50 +03:00
this . writer = w1 ;
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-10-21 08:12:50 +03:00
writeSync ( data2 ) {
2021-02-26 12:21:42 +03:00
if ( this . err !== null ) throw this . err ;
2021-10-21 08:12:50 +03:00
if ( data2 . length === 0 ) return 0 ;
2021-02-26 12:21:42 +03:00
let totalBytesWritten = 0 ;
let numBytesWritten = 0 ;
2021-10-21 08:12:50 +03:00
while ( data2 . byteLength > this . available ( ) ) {
2021-02-26 12:21:42 +03:00
if ( this . buffered ( ) === 0 ) {
try {
2021-10-21 08:12:50 +03:00
numBytesWritten = this . writer . writeSync ( data2 ) ;
2021-02-26 12:21:42 +03:00
} catch ( e ) {
this . err = e ;
throw e ;
}
} else {
2021-10-21 08:12:50 +03:00
numBytesWritten = copyBytes ( data2 , this . buf , this . usedBufferBytes ) ;
2021-02-26 12:21:42 +03:00
this . usedBufferBytes += numBytesWritten ;
this . flush ( ) ;
}
totalBytesWritten += numBytesWritten ;
2021-10-21 08:12:50 +03:00
data2 = data2 . subarray ( numBytesWritten ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
numBytesWritten = copyBytes ( data2 , 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-10-21 08:12:50 +03:00
constructor ( levelName2 , options2 = {
2021-02-26 12:21:42 +03:00
} ) {
2021-10-21 08:12:50 +03:00
this . level = getLevelByName ( levelName2 ) ;
this . levelName = levelName2 ;
this . formatter = options2 . 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-10-21 08:12:50 +03:00
format ( logRecord1 ) {
2021-02-26 12:21:42 +03:00
if ( this . formatter instanceof Function ) {
2021-10-21 08:12:50 +03:00
return this . formatter ( logRecord1 ) ;
2021-02-26 12:21:42 +03:00
}
return this . formatter . replace ( /{(\S+)}/g , ( match , p1 ) = > {
2021-10-21 08:12:50 +03:00
const value = logRecord1 [ 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-10-21 08:12:50 +03:00
format ( logRecord2 ) {
let msg = super . format ( logRecord2 ) ;
switch ( logRecord2 . level ) {
case LogLevels1 . INFO :
2021-02-26 12:21:42 +03:00
msg = blue ( msg ) ;
break ;
2021-10-21 08:12:50 +03:00
case LogLevels1 . WARNING :
2021-02-26 12:21:42 +03:00
msg = yellow ( msg ) ;
break ;
2021-10-21 08:12:50 +03:00
case LogLevels1 . ERROR :
2021-02-26 12:21:42 +03:00
msg = red ( msg ) ;
break ;
2021-10-21 08:12:50 +03:00
case LogLevels1 . 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-10-21 08:12:50 +03:00
log ( msg6 ) {
console . log ( msg6 ) ;
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-10-21 08:12:50 +03:00
constructor ( levelName3 , options3 ) {
super ( levelName3 , options3 ) ;
2021-03-21 16:31:35 +03:00
this . _encoder = new TextEncoder ( ) ;
2021-10-21 08:12:50 +03:00
this . _filename = options3 . filename ;
this . _mode = options3 . mode ? options3 . 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-10-21 08:12:50 +03:00
handle ( logRecord3 ) {
super . handle ( logRecord3 ) ;
if ( logRecord3 . level > LogLevels1 . ERROR ) {
2021-02-26 12:21:42 +03:00
this . flush ( ) ;
}
}
2021-10-21 08:12:50 +03:00
log ( msg7 ) {
this . _buf . writeSync ( this . _encoder . encode ( msg7 + "\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-10-21 08:12:50 +03:00
constructor ( levelName4 , options4 ) {
super ( levelName4 , options4 ) ;
this . # maxBytes = options4 . maxBytes ;
this . # maxBackupCount = options4 . 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" ) {
for ( let i = 1 ; i <= this . # maxBackupCount ; i ++ ) {
if ( await exists ( this . _filename + "." + i ) ) {
await Deno . remove ( this . _filename + "." + i ) ;
}
}
} else if ( this . _mode === "x" ) {
for ( let i = 1 ; i <= this . # maxBackupCount ; i ++ ) {
if ( await exists ( this . _filename + "." + i ) ) {
this . destroy ( ) ;
throw new Deno . errors . AlreadyExists ( "Backup log file " + this . _filename + "." + i + " already exists" ) ;
}
}
} else {
this . # currentFileSize = ( await Deno . stat ( this . _filename ) ) . size ;
}
}
2021-10-21 08:12:50 +03:00
log ( msg8 ) {
const msgByteLength = this . _encoder . encode ( msg8 ) . byteLength + 1 ;
2021-02-26 12:21:42 +03:00
if ( this . # currentFileSize + msgByteLength > this . # maxBytes ) {
this . rotateLogFiles ( ) ;
this . # currentFileSize = 0 ;
}
2021-10-21 08:12:50 +03:00
this . _buf . writeSync ( this . _encoder . encode ( msg8 + "\n" ) ) ;
2021-02-26 12:21:42 +03:00
this . # currentFileSize += msgByteLength ;
}
rotateLogFiles() {
this . _buf . flush ( ) ;
Deno . close ( this . _file . rid ) ;
for ( let i = this . # maxBackupCount - 1 ; i >= 0 ; i -- ) {
const source = this . _filename + ( i === 0 ? "" : "." + i ) ;
const dest = this . _filename + "." + ( i + 1 ) ;
if ( existsSync ( source ) ) {
Deno . renameSync ( source , dest ) ;
}
}
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-10-21 08:12:50 +03:00
const handlers1 = {
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-10-21 08:12:50 +03:00
function info1 ( 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-10-21 08:12:50 +03:00
function error1 ( 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-09-01 16:11:55 +03:00
const handlers = state . config . handlers || {
2021-02-26 12:21:42 +03:00
} ;
2021-10-21 08:12:50 +03:00
for ( const handlerName1 in handlers ) {
const handler = handlers [ 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-09-01 16:11:55 +03:00
const handlers = [ ] ;
handlerNames . forEach ( ( handlerName ) = > {
const handler = state . handlers . get ( handlerName ) ;
2021-02-26 12:21:42 +03:00
if ( handler ) {
2021-09-01 16:11:55 +03:00
handlers . 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 , {
handlers : handlers
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-10-21 08:12:50 +03:00
LogLevels : LogLevels1 ,
2021-02-26 12:21:42 +03:00
Logger : Logger ,
LoggerConfig : LoggerConfig ,
2021-10-21 08:12:50 +03:00
handlers : handlers1 ,
2021-02-26 12:21:42 +03:00
getLogger : getLogger ,
debug : debug ,
2021-10-21 08:12:50 +03:00
info : info1 ,
2021-02-26 12:21:42 +03:00
warning : warning ,
2021-10-21 08:12:50 +03:00
error : error1 ,
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-09-01 16:11:55 +03:00
function isSubdir ( src , dest , sep = sep2 ) {
2021-02-26 12:21:42 +03:00
if ( src === dest ) {
return false ;
}
2021-09-01 16:11:55 +03:00
const srcArray = src . split ( sep ) ;
const destArray = dest . split ( sep ) ;
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 ;
}
}
async function ensureLink ( src , dest ) {
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 ) ) ;
await Deno . link ( src , dest ) ;
}
function ensureLinkSync ( src , dest ) {
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 ) ) ;
Deno . linkSync ( src , dest ) ;
}
async function ensureSymlink ( src , dest ) {
const srcStatInfo = await Deno . lstat ( src ) ;
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" ) {
await Deno . symlink ( src , dest , {
type : srcFilePathType === "dir" ? "dir" : "file"
} ) ;
} else {
await Deno . symlink ( src , dest ) ;
}
}
function ensureSymlinkSync ( src , dest ) {
const srcStatInfo = Deno . lstatSync ( src ) ;
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" ) {
Deno . symlinkSync ( src , dest , {
type : srcFilePathType === "dir" ? "dir" : "file"
} ) ;
} else {
Deno . symlinkSync ( src , dest ) ;
}
}
2021-09-01 16:11:55 +03:00
function _createWalkEntrySync ( path ) {
path = normalize2 ( path ) ;
const name = basename2 ( path ) ;
const info = Deno . statSync ( path ) ;
2021-02-26 12:21:42 +03:00
return {
2021-09-01 16:11:55 +03:00
path ,
2021-02-26 12:21:42 +03:00
name ,
2021-09-01 16:11:55 +03:00
isFile : info.isFile ,
isDirectory : info.isDirectory ,
isSymlink : info.isSymlink
2021-02-26 12:21:42 +03:00
} ;
}
2021-09-01 16:11:55 +03:00
async function _createWalkEntry ( path ) {
path = normalize2 ( path ) ;
const name = basename2 ( path ) ;
const info = await Deno . stat ( path ) ;
2021-02-26 12:21:42 +03:00
return {
2021-09-01 16:11:55 +03:00
path ,
2021-02-26 12:21:42 +03:00
name ,
2021-09-01 16:11:55 +03:00
isFile : info.isFile ,
isDirectory : info.isDirectory ,
isSymlink : info.isSymlink
2021-02-26 12:21:42 +03:00
} ;
}
2021-09-01 16:11:55 +03:00
function include ( path , exts , match , skip ) {
if ( exts && ! exts . some ( ( ext ) = > path . endsWith ( ext )
2021-02-26 12:21:42 +03:00
) ) {
return false ;
}
2021-09-01 16:11:55 +03:00
if ( match && ! match . some ( ( pattern ) = > ! ! path . match ( pattern )
2021-02-26 12:21:42 +03:00
) ) {
return false ;
}
2021-09-01 16:11:55 +03:00
if ( skip && skip . some ( ( pattern ) = > ! ! path . 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-09-01 16:11:55 +03:00
const path = join2 ( root , entry . name ) ;
2021-02-26 12:21:42 +03:00
if ( entry . isFile ) {
2021-09-01 16:11:55 +03:00
if ( includeFiles && include ( path , exts , match , skip ) ) {
2021-02-26 12:21:42 +03:00
yield {
2021-09-01 16:11:55 +03:00
path ,
2021-02-26 12:21:42 +03:00
. . . entry
} ;
}
} else {
2021-09-01 16:11:55 +03:00
yield * walk ( path , {
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-09-01 16:11:55 +03:00
const path = join2 ( root , entry . name ) ;
2021-02-26 12:21:42 +03:00
if ( entry . isFile ) {
2021-09-01 16:11:55 +03:00
if ( includeFiles && include ( path , exts , match , skip ) ) {
2021-02-26 12:21:42 +03:00
yield {
2021-09-01 16:11:55 +03:00
path ,
2021-02-26 12:21:42 +03:00
. . . entry
} ;
}
} else {
2021-09-01 16:11:55 +03:00
yield * walkSync ( path , {
2021-02-26 12:21:42 +03:00
maxDepth : maxDepth - 1 ,
includeFiles ,
includeDirs ,
followSymlinks ,
exts ,
match ,
skip
} ) ;
}
}
}
const isWindows1 = Deno . build . os == "windows" ;
2021-09-01 16:11:55 +03:00
function split ( path ) {
2021-02-26 12:21:42 +03:00
const s = SEP_PATTERN . source ;
2021-09-01 16:11:55 +03:00
const segments = path . replace ( new RegExp ( ` ^ ${ s } | ${ s } $ ` , "g" ) , "" ) . split ( SEP_PATTERN ) ;
const isAbsolute_ = isAbsolute2 ( path ) ;
2021-02-26 12:21:42 +03:00
return {
segments ,
isAbsolute : isAbsolute_ ,
2021-09-01 16:11:55 +03:00
hasTrailingSep : ! ! path . match ( new RegExp ( ` ${ s } $ ` ) ) ,
2021-02-26 12:21:42 +03:00
winRoot : isWindows1 && isAbsolute_ ? segments . shift ( ) : undefined
} ;
}
2021-09-01 16:11:55 +03:00
function throwUnlessNotFound ( error ) {
if ( ! ( error instanceof Deno . errors . NotFound ) ) {
throw error ;
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-09-01 16:11:55 +03:00
const resolveFromRoot = ( path ) = > isAbsolute2 ( path ) ? normalize2 ( path ) : joinGlobs ( [
2021-02-26 12:21:42 +03:00
absRoot ,
2021-09-01 16:11:55 +03:00
path
2021-02-26 12:21:42 +03:00
] , globOptions )
;
const excludePatterns = exclude . map ( resolveFromRoot ) . map ( ( s ) = > globToRegExp ( s , globOptions )
) ;
2021-09-01 16:11:55 +03:00
const shouldInclude = ( path ) = > ! excludePatterns . some ( ( p ) = > ! ! path . 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-09-01 16:11:55 +03:00
} catch ( error ) {
throwUnlessNotFound ( error ) ;
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-09-01 16:11:55 +03:00
const resolveFromRoot = ( path ) = > isAbsolute2 ( path ) ? normalize2 ( path ) : joinGlobs ( [
2021-02-26 12:21:42 +03:00
absRoot ,
2021-09-01 16:11:55 +03:00
path
2021-02-26 12:21:42 +03:00
] , globOptions )
;
const excludePatterns = exclude . map ( resolveFromRoot ) . map ( ( s ) = > globToRegExp ( s , globOptions )
) ;
2021-09-01 16:11:55 +03:00
const shouldInclude = ( path ) = > ! excludePatterns . some ( ( p ) = > ! ! path . 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-10-21 08:12:50 +03:00
} catch ( error3 ) {
return throwUnlessNotFound ( error3 ) ;
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-09-01 16:11:55 +03:00
} catch ( error ) {
throwUnlessNotFound ( error ) ;
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 ;
}
async function move ( src , dest , { overwrite = false } = {
} ) {
const srcStat = await Deno . stat ( src ) ;
if ( srcStat . isDirectory && isSubdir ( src , dest ) ) {
throw new Error ( ` Cannot move ' ${ src } ' to a subdirectory of itself, ' ${ dest } '. ` ) ;
}
if ( overwrite ) {
if ( await exists ( dest ) ) {
await Deno . remove ( dest , {
recursive : true
} ) ;
}
await Deno . rename ( src , dest ) ;
} else {
if ( await exists ( dest ) ) {
throw new Error ( "dest already exists." ) ;
}
await Deno . rename ( src , dest ) ;
}
return ;
}
function moveSync ( src , dest , { overwrite = false } = {
} ) {
const srcStat = Deno . statSync ( src ) ;
if ( srcStat . isDirectory && isSubdir ( src , dest ) ) {
throw new Error ( ` Cannot move ' ${ src } ' to a subdirectory of itself, ' ${ dest } '. ` ) ;
}
if ( overwrite ) {
if ( existsSync ( dest ) ) {
Deno . removeSync ( dest , {
recursive : true
} ) ;
}
Deno . renameSync ( src , dest ) ;
} else {
if ( existsSync ( dest ) ) {
throw new Error ( "dest already exists." ) ;
}
Deno . renameSync ( src , dest ) ;
}
}
const isWindows2 = Deno . build . os === "windows" ;
2021-09-01 16:11:55 +03:00
async function ensureValidCopy ( src , 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 ) {
throw new Error ( ` Cannot overwrite non-directory ' ${ dest } ' with directory ' ${ src } '. ` ) ;
}
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-09-01 16:11:55 +03:00
function ensureValidCopySync ( src , 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 ) {
throw new Error ( ` Cannot overwrite non-directory ' ${ dest } ' with directory ' ${ src } '. ` ) ;
}
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-09-01 16:11:55 +03:00
async function copyFile ( src , dest , options ) {
await ensureValidCopy ( src , dest , options ) ;
2021-02-26 12:21:42 +03:00
await Deno . copyFile ( src , dest ) ;
2021-09-01 16:11:55 +03:00
if ( options . preserveTimestamps ) {
2021-02-26 12:21:42 +03:00
const statInfo = await Deno . stat ( src ) ;
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-09-01 16:11:55 +03:00
function copyFileSync ( src , dest , options ) {
ensureValidCopySync ( src , dest , options ) ;
2021-02-26 12:21:42 +03:00
Deno . copyFileSync ( src , dest ) ;
2021-09-01 16:11:55 +03:00
if ( options . preserveTimestamps ) {
2021-02-26 12:21:42 +03:00
const statInfo = Deno . statSync ( src ) ;
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-09-01 16:11:55 +03:00
async function copySymLink ( src , dest , options ) {
await ensureValidCopy ( src , dest , options ) ;
2021-02-26 12:21:42 +03:00
const originSrcFilePath = await Deno . readLink ( src ) ;
const type = getFileInfoType ( await Deno . lstat ( src ) ) ;
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-02-26 12:21:42 +03:00
const statInfo = await Deno . lstat ( src ) ;
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-09-01 16:11:55 +03:00
function copySymlinkSync ( src , dest , options ) {
ensureValidCopySync ( src , dest , options ) ;
2021-02-26 12:21:42 +03:00
const originSrcFilePath = Deno . readLinkSync ( src ) ;
const type = getFileInfoType ( Deno . lstatSync ( src ) ) ;
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-02-26 12:21:42 +03:00
const statInfo = Deno . lstatSync ( src ) ;
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-09-01 16:11:55 +03:00
async function copyDir ( src , dest , options ) {
const destStat = await ensureValidCopy ( src , 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-02-26 12:21:42 +03:00
const srcStatInfo = await Deno . stat ( src ) ;
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 ) ;
}
for await ( const entry of Deno . readDir ( src ) ) {
const srcPath = join2 ( src , entry . name ) ;
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-09-01 16:11:55 +03:00
function copyDirSync ( src , dest , options ) {
const destStat = ensureValidCopySync ( src , 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-02-26 12:21:42 +03:00
const srcStatInfo = Deno . statSync ( src ) ;
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 ) ;
}
for ( const entry of Deno . readDirSync ( src ) ) {
assert ( entry . name != null , "file.name must be set" ) ;
const srcPath = join2 ( src , entry . name ) ;
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-09-01 16:11:55 +03:00
async function copy ( src , dest , options = {
2021-02-26 12:21:42 +03:00
} ) {
src = resolve2 ( src ) ;
dest = resolve2 ( dest ) ;
if ( src === dest ) {
throw new Error ( "Source and destination cannot be the same." ) ;
}
const srcStat = await Deno . lstat ( src ) ;
if ( srcStat . isDirectory && isSubdir ( src , dest ) ) {
throw new Error ( ` Cannot copy ' ${ src } ' to a subdirectory of itself, ' ${ dest } '. ` ) ;
}
if ( srcStat . isSymlink ) {
2021-09-01 16:11:55 +03:00
await copySymLink ( src , dest , options ) ;
2021-02-26 12:21:42 +03:00
} else if ( srcStat . isDirectory ) {
2021-09-01 16:11:55 +03:00
await copyDir ( src , dest , options ) ;
2021-02-26 12:21:42 +03:00
} else if ( srcStat . isFile ) {
2021-09-01 16:11:55 +03:00
await copyFile ( src , dest , options ) ;
2021-02-26 12:21:42 +03:00
}
}
2021-09-01 16:11:55 +03:00
function copySync ( src , dest , options = {
2021-02-26 12:21:42 +03:00
} ) {
src = resolve2 ( src ) ;
dest = resolve2 ( dest ) ;
if ( src === dest ) {
throw new Error ( "Source and destination cannot be the same." ) ;
}
const srcStat = Deno . lstatSync ( src ) ;
if ( srcStat . isDirectory && isSubdir ( src , dest ) ) {
throw new Error ( ` Cannot copy ' ${ src } ' to a subdirectory of itself, ' ${ dest } '. ` ) ;
}
if ( srcStat . isSymlink ) {
2021-09-01 16:11:55 +03:00
copySymlinkSync ( src , dest , options ) ;
2021-02-26 12:21:42 +03:00
} else if ( srcStat . isDirectory ) {
2021-09-01 16:11:55 +03:00
copyDirSync ( src , dest , options ) ;
2021-02-26 12:21:42 +03:00
} else if ( srcStat . isFile ) {
2021-09-01 16:11:55 +03:00
copyFileSync ( src , dest , options ) ;
2021-02-26 12:21:42 +03:00
}
}
2021-10-21 08:12:50 +03:00
var EOL1 ;
2021-09-01 16:11:55 +03:00
( function ( EOL ) {
EOL [ "LF" ] = "\n" ;
EOL [ "CRLF" ] = "\r\n" ;
2021-10-21 08:12:50 +03:00
} ) ( EOL1 || ( EOL1 = {
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-10-21 08:12:50 +03:00
const crlf = d . filter ( ( x ) = > x === EOL1 . CRLF
2021-02-26 12:21:42 +03:00
) ;
if ( crlf . length > 0 ) {
2021-10-21 08:12:50 +03:00
return EOL1 . CRLF ;
2021-02-26 12:21:42 +03:00
} else {
2021-10-21 08:12:50 +03:00
return EOL1 . 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-10-21 08:12:50 +03:00
EOL : EOL1 ,
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 ) ;
let result = "" , i ;
const l = uint8 . length ;
for ( i = 2 ; i < l ; i += 3 ) {
result += base64abc [ uint8 [ i - 2 ] >> 2 ] ;
result += base64abc [ ( uint8 [ i - 2 ] & 3 ) << 4 | uint8 [ i - 1 ] >> 4 ] ;
result += base64abc [ ( uint8 [ i - 1 ] & 15 ) << 2 | uint8 [ i ] >> 6 ] ;
result += base64abc [ uint8 [ i ] & 63 ] ;
}
if ( i === l + 1 ) {
result += base64abc [ uint8 [ i - 2 ] >> 2 ] ;
result += base64abc [ ( uint8 [ i - 2 ] & 3 ) << 4 ] ;
result += "==" ;
}
if ( i === l ) {
result += base64abc [ uint8 [ i - 2 ] >> 2 ] ;
result += base64abc [ ( uint8 [ i - 2 ] & 3 ) << 4 | uint8 [ i - 1 ] >> 4 ] ;
result += base64abc [ ( uint8 [ i - 1 ] & 15 ) << 2 ] ;
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 ) ;
for ( let i = 0 ; i < size ; i ++ ) {
2021-02-26 12:21:42 +03:00
bytes [ i ] = binString . charCodeAt ( i ) ;
}
return bytes ;
}
const importMeta = {
url : "<https://deno.land/std@0.77.0/hash/_wasm/wasm.js>" ,
main : false
} ;
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
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-09-01 16:11:55 +03:00
const code = arg . charCodeAt ( offset ) ;
if ( code > 127 ) break ;
mem [ ptr + offset ] = code ;
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 ;
}
function encode1 ( src ) {
const dst = new Uint8Array ( encodedLen ( src . length ) ) ;
for ( let i = 0 ; i < dst . length ; i ++ ) {
const v = src [ i ] ;
dst [ i * 2 ] = hextable [ v >> 4 ] ;
dst [ i * 2 + 1 ] = hextable [ v & 15 ] ;
}
return dst ;
}
function encodeToString ( src ) {
return new TextDecoder ( ) . decode ( encode1 ( src ) ) ;
}
await init ( source ) ;
const TYPE_ERROR_MSG = "hash: `data` is invalid type" ;
class Hash {
# hash ;
# digested ;
2021-10-21 08:12:50 +03:00
constructor ( algorithm1 ) {
this . # hash = create_hash ( algorithm1 ) ;
2021-02-26 12:21:42 +03:00
this . # digested = false ;
}
2021-10-21 08:12:50 +03:00
update ( data6 ) {
2021-02-26 12:21:42 +03:00
let msg ;
2021-10-21 08:12:50 +03:00
if ( typeof data6 === "string" ) {
msg = new TextEncoder ( ) . encode ( data6 ) ;
} else if ( typeof data6 === "object" ) {
if ( data6 instanceof ArrayBuffer || ArrayBuffer . isView ( data6 ) ) {
msg = new Uint8Array ( data6 ) ;
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-10-21 08:12:50 +03:00
toString ( format4 = "hex" ) {
2021-02-26 12:21:42 +03:00
const finalized = new Uint8Array ( this . digest ( ) ) ;
2021-10-21 08:12:50 +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_SAFE_COMPONENT_LENGTH = 16 ;
const re = [ ] ;
2021-10-21 08:12:50 +03:00
const src1 = [ ] ;
2021-02-26 12:21:42 +03:00
let R = 0 ;
const NUMERICIDENTIFIER = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ NUMERICIDENTIFIER ] = "0|[1-9]\\d*" ;
2021-02-26 12:21:42 +03:00
const NUMERICIDENTIFIERLOOSE = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ NUMERICIDENTIFIERLOOSE ] = "[0-9]+" ;
2021-02-26 12:21:42 +03:00
const NONNUMERICIDENTIFIER = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ NONNUMERICIDENTIFIER ] = "\\d*[a-zA-Z-][a-zA-Z0-9-]*" ;
2021-02-26 12:21:42 +03:00
const MAINVERSION = R ++ ;
2021-10-21 08:12:50 +03:00
const nid = src1 [ NUMERICIDENTIFIER ] ;
src1 [ MAINVERSION ] = ` ( ${ nid } ) \\ .( ${ nid } ) \\ .( ${ nid } ) ` ;
2021-02-26 12:21:42 +03:00
const MAINVERSIONLOOSE = R ++ ;
2021-10-21 08:12:50 +03:00
const nidl = src1 [ NUMERICIDENTIFIERLOOSE ] ;
src1 [ MAINVERSIONLOOSE ] = ` ( ${ nidl } ) \\ .( ${ nidl } ) \\ .( ${ nidl } ) ` ;
2021-02-26 12:21:42 +03:00
const PRERELEASEIDENTIFIER = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ PRERELEASEIDENTIFIER ] = "(?:" + src1 [ NUMERICIDENTIFIER ] + "|" + src1 [ NONNUMERICIDENTIFIER ] + ")" ;
2021-02-26 12:21:42 +03:00
const PRERELEASEIDENTIFIERLOOSE = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ PRERELEASEIDENTIFIERLOOSE ] = "(?:" + src1 [ NUMERICIDENTIFIERLOOSE ] + "|" + src1 [ NONNUMERICIDENTIFIER ] + ")" ;
2021-02-26 12:21:42 +03:00
const PRERELEASE = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ PRERELEASE ] = "(?:-(" + src1 [ PRERELEASEIDENTIFIER ] + "(?:\\." + src1 [ PRERELEASEIDENTIFIER ] + ")*))" ;
2021-02-26 12:21:42 +03:00
const PRERELEASELOOSE = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ PRERELEASELOOSE ] = "(?:-?(" + src1 [ PRERELEASEIDENTIFIERLOOSE ] + "(?:\\." + src1 [ PRERELEASEIDENTIFIERLOOSE ] + ")*))" ;
2021-02-26 12:21:42 +03:00
const BUILDIDENTIFIER = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ BUILDIDENTIFIER ] = "[0-9A-Za-z-]+" ;
2021-02-26 12:21:42 +03:00
const BUILD = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ BUILD ] = "(?:\\+(" + src1 [ BUILDIDENTIFIER ] + "(?:\\." + src1 [ BUILDIDENTIFIER ] + ")*))" ;
2021-02-26 12:21:42 +03:00
const FULL = R ++ ;
2021-10-21 08:12:50 +03:00
const FULLPLAIN = "v?" + src1 [ MAINVERSION ] + src1 [ PRERELEASE ] + "?" + src1 [ BUILD ] + "?" ;
src1 [ FULL ] = "^" + FULLPLAIN + "$" ;
const LOOSEPLAIN = "[v=\\s]*" + src1 [ MAINVERSIONLOOSE ] + src1 [ PRERELEASELOOSE ] + "?" + src1 [ BUILD ] + "?" ;
2021-02-26 12:21:42 +03:00
const LOOSE = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ LOOSE ] = "^" + LOOSEPLAIN + "$" ;
2021-02-26 12:21:42 +03:00
const GTLT = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ GTLT ] = "((?:<|>)?=?)" ;
2021-02-26 12:21:42 +03:00
const XRANGEIDENTIFIERLOOSE = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ XRANGEIDENTIFIERLOOSE ] = src1 [ NUMERICIDENTIFIERLOOSE ] + "|x|X|\\*" ;
2021-02-26 12:21:42 +03:00
const XRANGEIDENTIFIER = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ XRANGEIDENTIFIER ] = src1 [ NUMERICIDENTIFIER ] + "|x|X|\\*" ;
2021-02-26 12:21:42 +03:00
const XRANGEPLAIN = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ XRANGEPLAIN ] = "[v=\\s]*(" + src1 [ XRANGEIDENTIFIER ] + ")" + "(?:\\.(" + src1 [ XRANGEIDENTIFIER ] + ")" + "(?:\\.(" + src1 [ XRANGEIDENTIFIER ] + ")" + "(?:" + src1 [ PRERELEASE ] + ")?" + src1 [ BUILD ] + "?" + ")?)?" ;
2021-02-26 12:21:42 +03:00
const XRANGEPLAINLOOSE = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ XRANGEPLAINLOOSE ] = "[v=\\s]*(" + src1 [ XRANGEIDENTIFIERLOOSE ] + ")" + "(?:\\.(" + src1 [ XRANGEIDENTIFIERLOOSE ] + ")" + "(?:\\.(" + src1 [ XRANGEIDENTIFIERLOOSE ] + ")" + "(?:" + src1 [ PRERELEASELOOSE ] + ")?" + src1 [ BUILD ] + "?" + ")?)?" ;
2021-02-26 12:21:42 +03:00
const XRANGE = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ XRANGE ] = "^" + src1 [ GTLT ] + "\\s*" + src1 [ XRANGEPLAIN ] + "$" ;
2021-02-26 12:21:42 +03:00
const XRANGELOOSE = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ XRANGELOOSE ] = "^" + src1 [ GTLT ] + "\\s*" + src1 [ XRANGEPLAINLOOSE ] + "$" ;
2021-02-26 12:21:42 +03:00
const COERCE = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ 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-10-21 08:12:50 +03:00
src1 [ LONETILDE ] = "(?:~>?)" ;
2021-02-26 12:21:42 +03:00
const TILDETRIM = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ TILDETRIM ] = "(\\s*)" + src1 [ LONETILDE ] + "\\s+" ;
re [ TILDETRIM ] = new RegExp ( src1 [ TILDETRIM ] , "g" ) ;
2021-02-26 12:21:42 +03:00
const tildeTrimReplace = "$1~" ;
const TILDE = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ TILDE ] = "^" + src1 [ LONETILDE ] + src1 [ XRANGEPLAIN ] + "$" ;
2021-02-26 12:21:42 +03:00
const TILDELOOSE = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ TILDELOOSE ] = "^" + src1 [ LONETILDE ] + src1 [ XRANGEPLAINLOOSE ] + "$" ;
2021-02-26 12:21:42 +03:00
const LONECARET = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ LONECARET ] = "(?:\\^)" ;
2021-02-26 12:21:42 +03:00
const CARETTRIM = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ CARETTRIM ] = "(\\s*)" + src1 [ LONECARET ] + "\\s+" ;
re [ CARETTRIM ] = new RegExp ( src1 [ CARETTRIM ] , "g" ) ;
2021-02-26 12:21:42 +03:00
const caretTrimReplace = "$1^" ;
const CARET = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ CARET ] = "^" + src1 [ LONECARET ] + src1 [ XRANGEPLAIN ] + "$" ;
2021-02-26 12:21:42 +03:00
const CARETLOOSE = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ CARETLOOSE ] = "^" + src1 [ LONECARET ] + src1 [ XRANGEPLAINLOOSE ] + "$" ;
2021-02-26 12:21:42 +03:00
const COMPARATORLOOSE = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ COMPARATORLOOSE ] = "^" + src1 [ GTLT ] + "\\s*(" + LOOSEPLAIN + ")$|^$" ;
2021-02-26 12:21:42 +03:00
const COMPARATOR = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ COMPARATOR ] = "^" + src1 [ GTLT ] + "\\s*(" + FULLPLAIN + ")$|^$" ;
2021-02-26 12:21:42 +03:00
const COMPARATORTRIM = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ COMPARATORTRIM ] = "(\\s*)" + src1 [ GTLT ] + "\\s*(" + LOOSEPLAIN + "|" + src1 [ XRANGEPLAIN ] + ")" ;
re [ COMPARATORTRIM ] = new RegExp ( src1 [ COMPARATORTRIM ] , "g" ) ;
2021-02-26 12:21:42 +03:00
const comparatorTrimReplace = "$1$2$3" ;
const HYPHENRANGE = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ HYPHENRANGE ] = "^\\s*(" + src1 [ XRANGEPLAIN ] + ")" + "\\s+-\\s+" + "(" + src1 [ XRANGEPLAIN ] + ")" + "\\s*$" ;
2021-02-26 12:21:42 +03:00
const HYPHENRANGELOOSE = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ HYPHENRANGELOOSE ] = "^\\s*(" + src1 [ XRANGEPLAINLOOSE ] + ")" + "\\s+-\\s+" + "(" + src1 [ XRANGEPLAINLOOSE ] + ")" + "\\s*$" ;
2021-02-26 12:21:42 +03:00
const STAR = R ++ ;
2021-10-21 08:12:50 +03:00
src1 [ STAR ] = "(<|>)?=?\\s*\\*" ;
for ( let i1 = 0 ; i1 < R ; i1 ++ ) {
if ( ! re [ i1 ] ) {
re [ i1 ] = new RegExp ( src1 [ i1 ] ) ;
2021-02-26 12:21:42 +03:00
}
}
function parse4 ( version , optionsOrLoose ) {
if ( ! optionsOrLoose || typeof optionsOrLoose !== "object" ) {
optionsOrLoose = {
loose : ! ! optionsOrLoose ,
includePrerelease : false
} ;
}
if ( version instanceof SemVer ) {
return version ;
}
if ( typeof version !== "string" ) {
return null ;
}
if ( version . length > 256 ) {
return null ;
}
const r = optionsOrLoose . loose ? re [ LOOSE ] : re [ FULL ] ;
if ( ! r . test ( version ) ) {
return null ;
}
try {
return new SemVer ( version , optionsOrLoose ) ;
} catch ( er ) {
return null ;
}
}
function valid ( version , optionsOrLoose ) {
if ( version === null ) return null ;
const v = parse4 ( version , optionsOrLoose ) ;
return v ? v.version : null ;
}
function clean ( version , optionsOrLoose ) {
const s = parse4 ( version . trim ( ) . replace ( /^[=v]+/ , "" ) , optionsOrLoose ) ;
return s ? s.version : null ;
}
class SemVer {
2021-10-21 08:12:50 +03:00
constructor ( version2 , optionsOrLoose1 ) {
if ( ! optionsOrLoose1 || typeof optionsOrLoose1 !== "object" ) {
optionsOrLoose1 = {
loose : ! ! optionsOrLoose1 ,
2021-02-26 12:21:42 +03:00
includePrerelease : false
} ;
}
2021-10-21 08:12:50 +03:00
if ( version2 instanceof SemVer ) {
if ( version2 . loose === optionsOrLoose1 . loose ) {
return version2 ;
2021-02-26 12:21:42 +03:00
} else {
2021-10-21 08:12:50 +03:00
version2 = version2 . version ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
} else if ( typeof version2 !== "string" ) {
throw new TypeError ( "Invalid Version: " + version2 ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
if ( version2 . length > 256 ) {
2021-02-26 12:21:42 +03:00
throw new TypeError ( "version is longer than " + 256 + " characters" ) ;
}
if ( ! ( this instanceof SemVer ) ) {
2021-10-21 08:12:50 +03:00
return new SemVer ( version2 , optionsOrLoose1 ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
this . options = optionsOrLoose1 ;
this . loose = ! ! optionsOrLoose1 . loose ;
const m = version2 . trim ( ) . match ( optionsOrLoose1 . loose ? re [ LOOSE ] : re [ FULL ] ) ;
2021-02-26 12:21:42 +03:00
if ( ! m ) {
2021-10-21 08:12:50 +03:00
throw new TypeError ( "Invalid Version: " + version2 ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
this . raw = version2 ;
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-10-21 08:12:50 +03:00
compareMain ( other1 ) {
if ( ! ( other1 instanceof SemVer ) ) {
other1 = new SemVer ( other1 , this . options ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
return compareIdentifiers ( this . major , other1 . major ) || compareIdentifiers ( this . minor , other1 . minor ) || compareIdentifiers ( this . patch , other1 . patch ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
comparePre ( other2 ) {
if ( ! ( other2 instanceof SemVer ) ) {
other2 = new SemVer ( other2 , this . options ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
if ( this . prerelease . length && ! other2 . prerelease . length ) {
2021-02-26 12:21:42 +03:00
return - 1 ;
2021-10-21 08:12:50 +03:00
} else if ( ! this . prerelease . length && other2 . prerelease . length ) {
2021-02-26 12:21:42 +03:00
return 1 ;
2021-10-21 08:12:50 +03:00
} else if ( ! this . prerelease . length && ! other2 . prerelease . length ) {
2021-02-26 12:21:42 +03:00
return 0 ;
}
2021-09-01 16:11:55 +03:00
let i = 0 ;
2021-02-26 12:21:42 +03:00
do {
2021-09-01 16:11:55 +03:00
const a = this . prerelease [ i ] ;
2021-10-21 08:12:50 +03:00
const b = other2 . prerelease [ i ] ;
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-09-01 16:11:55 +03:00
} while ( ++ i )
2021-02-26 12:21:42 +03:00
return 1 ;
}
2021-10-21 08:12:50 +03:00
compareBuild ( other3 ) {
if ( ! ( other3 instanceof SemVer ) ) {
other3 = new SemVer ( other3 , this . options ) ;
2021-02-26 12:21:42 +03:00
}
2021-09-01 16:11:55 +03:00
let i = 0 ;
2021-02-26 12:21:42 +03:00
do {
2021-09-01 16:11:55 +03:00
const a = this . build [ i ] ;
2021-10-21 08:12:50 +03:00
const b = other3 . build [ i ] ;
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-09-01 16:11:55 +03:00
} while ( ++ i )
2021-02-26 12:21:42 +03:00
return 1 ;
}
2021-10-21 08:12:50 +03:00
inc ( release1 , identifier1 ) {
switch ( release1 ) {
2021-02-26 12:21:42 +03:00
case "premajor" :
this . prerelease . length = 0 ;
this . patch = 0 ;
this . minor = 0 ;
this . major ++ ;
2021-10-21 08:12:50 +03:00
this . inc ( "pre" , identifier1 ) ;
2021-02-26 12:21:42 +03:00
break ;
case "preminor" :
this . prerelease . length = 0 ;
this . patch = 0 ;
this . minor ++ ;
2021-10-21 08:12:50 +03:00
this . inc ( "pre" , identifier1 ) ;
2021-02-26 12:21:42 +03:00
break ;
case "prepatch" :
this . prerelease . length = 0 ;
2021-10-21 08:12:50 +03:00
this . inc ( "patch" , identifier1 ) ;
this . inc ( "pre" , identifier1 ) ;
2021-02-26 12:21:42 +03:00
break ;
case "prerelease" :
if ( this . prerelease . length === 0 ) {
2021-10-21 08:12:50 +03:00
this . inc ( "patch" , identifier1 ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
this . inc ( "pre" , identifier1 ) ;
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-09-01 16:11:55 +03:00
let i = this . prerelease . length ;
while ( -- i >= 0 ) {
if ( typeof this . prerelease [ i ] === "number" ) {
this . prerelease [ i ] ++ ;
i = - 2 ;
2021-02-26 12:21:42 +03:00
}
}
2021-09-01 16:11:55 +03:00
if ( i === - 1 ) {
2021-02-26 12:21:42 +03:00
this . prerelease . push ( 0 ) ;
}
}
2021-10-21 08:12:50 +03:00
if ( identifier1 ) {
if ( this . prerelease [ 0 ] === identifier1 ) {
2021-02-26 12:21:42 +03:00
if ( isNaN ( this . prerelease [ 1 ] ) ) {
this . prerelease = [
2021-10-21 08:12:50 +03:00
identifier1 ,
2021-02-26 12:21:42 +03:00
0
] ;
}
} else {
this . prerelease = [
2021-10-21 08:12:50 +03:00
identifier1 ,
2021-02-26 12:21:42 +03:00
0
] ;
}
}
break ;
default :
2021-10-21 08:12:50 +03:00
throw new Error ( "invalid increment argument: " + release1 ) ;
2021-02-26 12:21:42 +03:00
}
this . format ( ) ;
this . raw = this . version ;
return this ;
}
toString() {
return this . version ;
}
}
2021-09-01 16:11:55 +03:00
function inc ( version , release , optionsOrLoose , identifier ) {
if ( typeof optionsOrLoose === "string" ) {
identifier = optionsOrLoose ;
optionsOrLoose = undefined ;
2021-02-26 12:21:42 +03:00
}
try {
2021-09-01 16:11:55 +03:00
return new SemVer ( version , 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-10-21 08:12:50 +03:00
function compare1 ( 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-10-21 08:12:50 +03:00
return compare1 ( 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-10-21 08:12:50 +03:00
return compare1 ( 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-10-21 08:12:50 +03:00
return compare1 ( 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-10-21 08:12:50 +03:00
return compare1 ( 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-10-21 08:12:50 +03:00
return compare1 ( 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-10-21 08:12:50 +03:00
return compare1 ( 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-10-21 08:12:50 +03:00
return compare1 ( 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-10-21 08:12:50 +03:00
return compare1 ( 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-10-21 08:12:50 +03:00
constructor ( comp3 , optionsOrLoose5 ) {
if ( ! optionsOrLoose5 || typeof optionsOrLoose5 !== "object" ) {
optionsOrLoose5 = {
loose : ! ! optionsOrLoose5 ,
2021-02-26 12:21:42 +03:00
includePrerelease : false
} ;
}
2021-10-21 08:12:50 +03:00
if ( comp3 instanceof Comparator ) {
if ( comp3 . loose === ! ! optionsOrLoose5 . loose ) {
return comp3 ;
2021-02-26 12:21:42 +03:00
} else {
2021-10-21 08:12:50 +03:00
comp3 = comp3 . value ;
2021-02-26 12:21:42 +03:00
}
}
if ( ! ( this instanceof Comparator ) ) {
2021-10-21 08:12:50 +03:00
return new Comparator ( comp3 , optionsOrLoose5 ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
this . options = optionsOrLoose5 ;
this . loose = ! ! optionsOrLoose5 . loose ;
this . parse ( comp3 ) ;
2021-02-26 12:21:42 +03:00
if ( this . semver === ANY ) {
this . value = "" ;
} else {
this . value = this . operator + this . semver . version ;
}
}
2021-10-21 08:12:50 +03:00
parse ( comp1 ) {
2021-02-26 12:21:42 +03:00
const r = this . options . loose ? re [ COMPARATORLOOSE ] : re [ COMPARATOR ] ;
2021-10-21 08:12:50 +03:00
const m = comp1 . match ( r ) ;
2021-09-01 16:11:55 +03:00
if ( ! m ) {
2021-10-21 08:12:50 +03:00
throw new TypeError ( "Invalid comparator: " + comp1 ) ;
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-10-21 08:12:50 +03:00
test ( version4 ) {
if ( this . semver === ANY || version4 === ANY ) {
2021-02-26 12:21:42 +03:00
return true ;
}
2021-10-21 08:12:50 +03:00
if ( typeof version4 === "string" ) {
version4 = new SemVer ( version4 , this . options ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
return cmp ( version4 , this . operator , this . semver , this . options ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
intersects ( comp2 , optionsOrLoose2 ) {
if ( ! ( comp2 instanceof Comparator ) ) {
2021-02-26 12:21:42 +03:00
throw new TypeError ( "a Comparator is required" ) ;
}
2021-10-21 08:12:50 +03:00
if ( ! optionsOrLoose2 || typeof optionsOrLoose2 !== "object" ) {
optionsOrLoose2 = {
loose : ! ! optionsOrLoose2 ,
2021-02-26 12:21:42 +03:00
includePrerelease : false
} ;
}
let rangeTmp ;
if ( this . operator === "" ) {
if ( this . value === "" ) {
return true ;
}
2021-10-21 08:12:50 +03:00
rangeTmp = new Range ( comp2 . value , optionsOrLoose2 ) ;
return satisfies ( this . value , rangeTmp , optionsOrLoose2 ) ;
} else if ( comp2 . operator === "" ) {
if ( comp2 . value === "" ) {
2021-02-26 12:21:42 +03:00
return true ;
}
2021-10-21 08:12:50 +03:00
rangeTmp = new Range ( this . value , optionsOrLoose2 ) ;
return satisfies ( comp2 . semver , rangeTmp , optionsOrLoose2 ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
const sameDirectionIncreasing = ( this . operator === ">=" || this . operator === ">" ) && ( comp2 . operator === ">=" || comp2 . operator === ">" ) ;
const sameDirectionDecreasing = ( this . operator === "<=" || this . operator === "<" ) && ( comp2 . operator === "<=" || comp2 . operator === "<" ) ;
const sameSemVer = this . semver . version === comp2 . semver . version ;
const differentDirectionsInclusive = ( this . operator === ">=" || this . operator === "<=" ) && ( comp2 . operator === ">=" || comp2 . operator === "<=" ) ;
const oppositeDirectionsLessThan = cmp ( this . semver , "<" , comp2 . semver , optionsOrLoose2 ) && ( this . operator === ">=" || this . operator === ">" ) && ( comp2 . operator === "<=" || comp2 . operator === "<" ) ;
const oppositeDirectionsGreaterThan = cmp ( this . semver , ">" , comp2 . semver , optionsOrLoose2 ) && ( this . operator === "<=" || this . operator === "<" ) && ( comp2 . operator === ">=" || comp2 . 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-10-21 08:12:50 +03:00
constructor ( range1 , optionsOrLoose3 ) {
if ( ! optionsOrLoose3 || typeof optionsOrLoose3 !== "object" ) {
optionsOrLoose3 = {
loose : ! ! optionsOrLoose3 ,
2021-02-26 12:21:42 +03:00
includePrerelease : false
} ;
}
2021-10-21 08:12:50 +03:00
if ( range1 instanceof Range ) {
if ( range1 . loose === ! ! optionsOrLoose3 . loose && range1 . includePrerelease === ! ! optionsOrLoose3 . includePrerelease ) {
return range1 ;
2021-02-26 12:21:42 +03:00
} else {
2021-10-21 08:12:50 +03:00
return new Range ( range1 . raw , optionsOrLoose3 ) ;
2021-02-26 12:21:42 +03:00
}
}
2021-10-21 08:12:50 +03:00
if ( range1 instanceof Comparator ) {
return new Range ( range1 . value , optionsOrLoose3 ) ;
2021-02-26 12:21:42 +03:00
}
2021-09-01 16:11:55 +03:00
if ( ! ( this instanceof Range ) ) {
2021-10-21 08:12:50 +03:00
return new Range ( range1 , optionsOrLoose3 ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
this . options = optionsOrLoose3 ;
this . loose = ! ! optionsOrLoose3 . loose ;
this . includePrerelease = ! ! optionsOrLoose3 . includePrerelease ;
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-10-21 08:12:50 +03:00
parseRange ( range3 ) {
2021-02-26 12:21:42 +03:00
const loose = this . options . loose ;
2021-10-21 08:12:50 +03:00
range3 = range3 . trim ( ) ;
2021-02-26 12:21:42 +03:00
const hr = loose ? re [ HYPHENRANGELOOSE ] : re [ HYPHENRANGE ] ;
2021-10-21 08:12:50 +03:00
range3 = range3 . replace ( hr , hyphenReplace ) ;
range3 = range3 . replace ( re [ COMPARATORTRIM ] , comparatorTrimReplace ) ;
range3 = range3 . replace ( re [ TILDETRIM ] , tildeTrimReplace ) ;
range3 = range3 . replace ( re [ CARETTRIM ] , caretTrimReplace ) ;
range3 = range3 . split ( /\s+/ ) . join ( " " ) ;
2021-02-26 12:21:42 +03:00
const compRe = loose ? re [ COMPARATORLOOSE ] : re [ COMPARATOR ] ;
2021-10-21 08:12:50 +03:00
let set = range3 . 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-10-21 08:12:50 +03:00
test ( version3 ) {
if ( typeof version3 === "string" ) {
version3 = new SemVer ( version3 , this . options ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
for ( var i = 0 ; i < this . set . length ; i ++ ) {
if ( testSet ( this . set [ i ] , version3 , this . options ) ) {
2021-02-26 12:21:42 +03:00
return true ;
}
}
return false ;
}
2021-10-21 08:12:50 +03:00
intersects ( range2 , optionsOrLoose4 ) {
if ( ! ( range2 instanceof Range ) ) {
2021-02-26 12:21:42 +03:00
throw new TypeError ( "a Range is required" ) ;
}
return this . set . some ( ( thisComparators ) = > {
2021-10-21 08:12:50 +03:00
return isSatisfiable ( thisComparators , optionsOrLoose4 ) && range2 . set . some ( ( rangeComparators ) = > {
return isSatisfiable ( rangeComparators , optionsOrLoose4 ) && thisComparators . every ( ( thisComparator ) = > {
2021-02-26 12:21:42 +03:00
return rangeComparators . every ( ( rangeComparator ) = > {
2021-10-21 08:12:50 +03:00
return thisComparator . intersects ( rangeComparator , optionsOrLoose4 ) ;
2021-02-26 12:21:42 +03:00
} ) ;
} ) ;
} ) ;
} ) ;
}
toString() {
return this . range ;
}
}
2021-09-01 16:11:55 +03:00
function testSet ( set , version , options ) {
for ( let i = 0 ; i < set . length ; i ++ ) {
if ( ! set [ i ] . test ( version ) ) {
2021-02-26 12:21:42 +03:00
return false ;
}
}
2021-09-01 16:11:55 +03:00
if ( version . prerelease . length && ! options . includePrerelease ) {
for ( let i = 0 ; i < set . length ; i ++ ) {
if ( set [ i ] . semver === ANY ) {
2021-02-26 12:21:42 +03:00
continue ;
}
2021-09-01 16:11:55 +03:00
if ( set [ i ] . semver . prerelease . length > 0 ) {
const allowed = set [ i ] . semver ;
if ( allowed . major === version . major && allowed . minor === version . minor && allowed . patch === version . 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-10-21 08:12:50 +03:00
function replaceTildes ( comp4 , options ) {
return comp4 . 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-10-21 08:12:50 +03:00
function replaceCarets ( comp5 , options ) {
return comp5 . 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-10-21 08:12:50 +03:00
function replaceXRanges ( comp6 , options ) {
return comp6 . 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-09-01 16:11:55 +03:00
function satisfies ( version , 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-09-01 16:11:55 +03:00
return range . test ( version ) ;
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-10-21 08:12:50 +03:00
for ( var i = 0 ; i < range . set . length ; ++ i ) {
var comparators = range . set [ i ] ;
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-09-01 16:11:55 +03:00
function ltr ( version , range , optionsOrLoose ) {
return outside ( version , range , "<" , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
}
2021-09-01 16:11:55 +03:00
function gtr ( version , range , optionsOrLoose ) {
return outside ( version , range , ">" , optionsOrLoose ) ;
2021-02-26 12:21:42 +03:00
}
2021-09-01 16:11:55 +03:00
function outside ( version , range , hilo , optionsOrLoose ) {
version = new SemVer ( version , optionsOrLoose ) ;
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-09-01 16:11:55 +03:00
if ( satisfies ( version , range , optionsOrLoose ) ) {
2021-02-26 12:21:42 +03:00
return false ;
}
2021-09-01 16:11:55 +03:00
for ( let i = 0 ; i < range . set . length ; ++ i ) {
const comparators = range . set [ i ] ;
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-09-01 16:11:55 +03:00
if ( ( ! low . operator || low . operator === comp ) && ltefn ( version , low . semver ) ) {
2021-02-26 12:21:42 +03:00
return false ;
2021-09-01 16:11:55 +03:00
} else if ( low . operator === ecomp && ltfn ( version , low . semver ) ) {
2021-02-26 12:21:42 +03:00
return false ;
}
}
return true ;
}
2021-09-01 16:11:55 +03:00
function prerelease ( version , optionsOrLoose ) {
var parsed = parse4 ( version , 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-09-01 16:11:55 +03:00
function coerce ( version , optionsOrLoose ) {
if ( version instanceof SemVer ) {
return version ;
2021-02-26 12:21:42 +03:00
}
2021-09-01 16:11:55 +03:00
if ( typeof version !== "string" ) {
2021-02-26 12:21:42 +03:00
return null ;
}
2021-09-01 16:11:55 +03:00
const match = version . 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-10-21 08:12:50 +03:00
compare : compare1 ,
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-09-01 16:11:55 +03:00
const version1 = "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-09-01 16:11:55 +03:00
jarr . forEach ( ( eljson , i ) = > {
2021-02-26 12:21:42 +03:00
try {
result . push ( elementBinding ( ) . fromJson ( eljson ) ) ;
} catch ( e ) {
if ( isJsonParseException ( e ) ) {
2021-09-01 16:11:55 +03:00
e . pushIndex ( i ) ;
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-09-01 16:11:55 +03:00
union . fields . forEach ( ( field , i ) = > {
2021-02-26 12:21:42 +03:00
fieldSerializedNames . push ( field . serializedName ) ;
2021-09-01 16:11:55 +03:00
fieldNumbers [ field . serializedName ] = i ;
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-09-01 16:11:55 +03:00
function once ( run ) {
2021-02-26 12:21:42 +03:00
let result = null ;
return ( ) = > {
if ( result === null ) {
2021-09-01 16:11:55 +03:00
result = run ( ) ;
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-10-21 08:12:50 +03:00
constructor ( data4 , isEqual ) {
this . data = data4 ;
2021-02-26 12:21:42 +03:00
this . isEqual = isEqual ;
}
has ( k ) {
return this . findIndex ( k ) !== - 1 ;
}
2021-10-21 08:12:50 +03:00
get ( k1 ) {
const ind = this . findIndex ( k1 ) ;
2021-02-26 12:21:42 +03:00
if ( ind === - 1 ) {
return undefined ;
}
return this . data [ ind ] . v2 ;
}
2021-10-21 08:12:50 +03:00
getOrInsert ( k2 , v ) {
const existing = this . get ( k2 ) ;
2021-02-26 12:21:42 +03:00
if ( existing === undefined ) {
2021-10-21 08:12:50 +03:00
this . set ( k2 , v ) ;
2021-02-26 12:21:42 +03:00
return v ;
}
return existing ;
}
2021-10-21 08:12:50 +03:00
set ( k3 , v1 ) {
const ind = this . findIndex ( k3 ) ;
2021-02-26 12:21:42 +03:00
if ( ind === - 1 ) {
this . data . push ( {
2021-10-21 08:12:50 +03:00
v1 : k3 ,
v2 : v1
2021-02-26 12:21:42 +03:00
} ) ;
}
this . data [ ind ] = {
2021-10-21 08:12:50 +03:00
v1 : k3 ,
v2 : v1
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-10-21 08:12:50 +03:00
findIndex ( k4 ) {
return this . data . findIndex ( ( p ) = > this . isEqual ( p . v1 , k4 )
2021-02-26 12:21:42 +03:00
) ;
}
}
class TaskManifest {
2021-10-21 08:12:50 +03:00
constructor ( data5 ) {
2021-03-21 16:31:35 +03:00
this . lastExecution = null ;
this . trackedFiles = new ADLMap ( [ ] , ( k1 , k2 ) = > k1 === k2
) ;
2021-10-21 08:12:50 +03:00
this . trackedFiles = new ADLMap ( data5 . trackedFiles , ( k1 , k2 ) = > k1 === k2
2021-02-26 12:21:42 +03:00
) ;
2021-10-21 08:12:50 +03:00
this . lastExecution = data5 . lastExecution ;
2021-02-26 12:21:42 +03:00
}
getFileData ( fn ) {
return this . trackedFiles . get ( fn ) ;
}
2021-10-21 08:12:50 +03:00
setFileData ( fn1 , d ) {
this . trackedFiles . set ( fn1 , 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-09-01 16:11:55 +03:00
async function statPath ( path ) {
2021-02-26 12:21:42 +03:00
try {
2021-09-01 16:11:55 +03:00
const fileInfo = await Deno . stat ( path ) ;
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-10-21 08:12:50 +03:00
getTrackedFiles ( deps1 ) {
return deps1 . filter ( isTrackedFile ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
getTrackedFilesAsync ( deps2 ) {
return deps2 . 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-10-21 08:12:50 +03:00
async exec ( ctx1 ) {
if ( ctx1 . doneTasks . has ( this ) ) {
2021-02-26 12:21:42 +03:00
return ;
}
2021-10-21 08:12:50 +03:00
if ( ctx1 . inprogressTasks . has ( this ) ) {
2021-02-26 12:21:42 +03:00
return ;
}
2021-10-21 08:12:50 +03:00
ctx1 . 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-10-21 08:12:50 +03:00
const t = ctx1 . targetRegister . get ( fd . path ) ;
2021-02-26 12:21:42 +03:00
if ( t !== undefined ) {
this . task_deps . add ( t ) ;
}
}
2021-10-21 08:12:50 +03:00
await this . execDependencies ( ctx1 ) ;
2021-02-26 12:21:42 +03:00
let actualUpToDate = true ;
2021-10-21 08:12:50 +03:00
actualUpToDate = actualUpToDate && await this . checkFileDeps ( ctx1 ) ;
ctx1 . internalLogger . info ( ` ${ this . name } checkFileDeps ${ actualUpToDate } ` ) ;
actualUpToDate = actualUpToDate && await this . targetsExist ( ctx1 ) ;
ctx1 . internalLogger . info ( ` ${ this . name } targetsExist ${ actualUpToDate } ` ) ;
2021-02-26 12:21:42 +03:00
if ( this . uptodate !== undefined ) {
2021-10-21 08:12:50 +03:00
actualUpToDate = actualUpToDate && await this . uptodate ( taskContext ( ctx1 , this ) ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
ctx1 . internalLogger . info ( ` ${ this . name } uptodate ${ actualUpToDate } ` ) ;
2021-02-26 12:21:42 +03:00
if ( actualUpToDate ) {
2021-10-21 08:12:50 +03:00
ctx1 . taskLogger . info ( ` --- ${ this . name } ` ) ;
2021-02-26 12:21:42 +03:00
} else {
2021-10-21 08:12:50 +03:00
ctx1 . taskLogger . info ( ` ... ${ this . name } ` ) ;
await this . action ( taskContext ( ctx1 , this ) ) ;
ctx1 . 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-10-21 08:12:50 +03:00
promisesInProgress . push ( ctx1 . asyncQueue . schedule ( async ( ) = > {
const trackedFileData = await fdep . getFileData ( ctx1 ) ;
2021-02-26 12:21:42 +03:00
this . taskManifest ? . setFileData ( fdep . path , trackedFileData ) ;
} ) ) ;
}
await Promise . all ( promisesInProgress ) ;
}
}
2021-10-21 08:12:50 +03:00
ctx1 . doneTasks . add ( this ) ;
ctx1 . inprogressTasks . delete ( this ) ;
2021-02-26 12:21:42 +03:00
}
2021-10-21 08:12:50 +03:00
async targetsExist ( ctx2 ) {
const tex = await Promise . all ( Array . from ( this . targets ) . map ( async ( tf ) = > ctx2 . asyncQueue . schedule ( ( ) = > tf . exists ( )
2021-02-26 12:21:42 +03:00
)
) ) ;
return ! tex . some ( ( t ) = > ! t
) ;
}
2021-10-21 08:12:50 +03:00
async checkFileDeps ( ctx3 ) {
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-10-21 08:12:50 +03:00
promisesInProgress . push ( ctx3 . asyncQueue . schedule ( async ( ) = > {
const r = await fdep . getFileDataOrCached ( ctx3 , 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-10-21 08:12:50 +03:00
async execDependencies ( ctx4 ) {
2021-02-26 12:21:42 +03:00
for ( const dep of this . task_deps ) {
2021-10-21 08:12:50 +03:00
if ( ! ctx4 . doneTasks . has ( dep ) && ! ctx4 . inprogressTasks . has ( dep ) ) {
await dep . exec ( ctx4 ) ;
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-10-21 08:12:50 +03:00
async getHash ( statInput1 ) {
let statResult = statInput1 ;
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-10-21 08:12:50 +03:00
async getTimestamp ( statInput2 ) {
let statResult = statInput2 ;
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-10-21 08:12:50 +03:00
async isUpToDate ( ctx5 , tData , statInput3 ) {
2021-02-26 12:21:42 +03:00
if ( tData === undefined ) {
return false ;
}
2021-10-21 08:12:50 +03:00
let statResult = statInput3 ;
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-10-21 08:12:50 +03:00
async getFileData ( ctx6 , statInput4 ) {
let statResult = statInput4 ;
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-10-21 08:12:50 +03:00
async getFileDataOrCached ( ctx7 , tData1 , statInput5 ) {
let statResult = statInput5 ;
2021-02-26 12:21:42 +03:00
if ( statResult === undefined ) {
statResult = await this . stat ( ) ;
}
2021-10-21 08:12:50 +03:00
if ( tData1 !== undefined && await this . isUpToDate ( ctx7 , tData1 , statResult ) ) {
2021-02-26 12:21:42 +03:00
return {
2021-10-21 08:12:50 +03:00
tData : tData1 ,
2021-02-26 12:21:42 +03:00
upToDate : true
} ;
}
return {
2021-10-21 08:12:50 +03:00
tData : await this . getFileData ( ctx7 , 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-10-21 08:12:50 +03:00
log ( msg10 ) {
Deno . stderr . writeSync ( new TextEncoder ( ) . encode ( msg10 + "\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 ) {
console . log ( ` dnit ${ version1 } ` ) ;
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-09-01 16:11:55 +03:00
internalLogger . info ( ` starting dnit launch using version: ${ version1 } ` ) ;
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 } ;