プレイグラウンド、サンドボックス、使い捨てスクリプト置き場
0

Configure Feed

Select the types of activity you want to include in your feed.

update deno example

Kohei Watanabe (Nov 24, 2021, 5:53 PM +0900) 58d3e74c fb81affd

+24 -5650
+6
deno/.vscode/settings.json
··· 1 + { 2 + "deno.enable": true, 3 + "deno.lint": true, 4 + "deno.unstable": false, 5 + "deno.importMap": "importmap.json" 6 + }
+7
deno/app.ts
··· 1 + import { Handler, ServeInit, serve } from "http/server.ts"; 2 + 3 + const handler: Handler = () => new Response("Hello World\n"); 4 + const options: ServeInit = { addr: "localhost:8080" }; 5 + 6 + serve(handler, options); 7 + console.log(`Server running on http://${options.addr}`);
+5
deno/importmap.json
··· 1 + { 2 + "imports": { 3 + "http/": "https://deno.land/std@0.115.1/http/" 4 + } 5 + }
+6
deno/scripts.yml
··· 1 + # yaml-language-server: $schema=https://deno.land/x/denon@2.4.10/schema.json 2 + importmap: importmap.json 3 + scripts: 4 + start: 5 + cmd: "deno run app.ts" 6 + allow: [net]
-5640
deno/server.bundle.js
··· 1 - // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 2 - 3 - // This is a specialised implementation of a System module loader. 4 - 5 - "use strict"; 6 - 7 - // @ts-nocheck 8 - /* eslint-disable */ 9 - let System, __instantiateAsync, __instantiate; 10 - 11 - (() => { 12 - const r = new Map(); 13 - 14 - System = { 15 - register(id, d, f) { 16 - r.set(id, { d, f, exp: {} }); 17 - }, 18 - }; 19 - 20 - async function dI(mid, src) { 21 - let id = mid.replace(/\.\w+$/i, ""); 22 - if (id.includes("./")) { 23 - const [o, ...ia] = id.split("/").reverse(), 24 - [, ...sa] = src.split("/").reverse(), 25 - oa = [o]; 26 - let s = 0, 27 - i; 28 - while ((i = ia.shift())) { 29 - if (i === "..") s++; 30 - else if (i === ".") break; 31 - else oa.push(i); 32 - } 33 - if (s < sa.length) oa.push(...sa.slice(s)); 34 - id = oa.reverse().join("/"); 35 - } 36 - return r.has(id) ? gExpA(id) : import(mid); 37 - } 38 - 39 - function gC(id, main) { 40 - return { 41 - id, 42 - import: (m) => dI(m, id), 43 - meta: { url: id, main }, 44 - }; 45 - } 46 - 47 - function gE(exp) { 48 - return (id, v) => { 49 - v = typeof id === "string" ? { [id]: v } : id; 50 - for (const [id, value] of Object.entries(v)) { 51 - Object.defineProperty(exp, id, { 52 - value, 53 - writable: true, 54 - enumerable: true, 55 - }); 56 - } 57 - }; 58 - } 59 - 60 - function rF(main) { 61 - for (const [id, m] of r.entries()) { 62 - const { f, exp } = m; 63 - const { execute: e, setters: s } = f(gE(exp), gC(id, id === main)); 64 - delete m.f; 65 - m.e = e; 66 - m.s = s; 67 - } 68 - } 69 - 70 - async function gExpA(id) { 71 - if (!r.has(id)) return; 72 - const m = r.get(id); 73 - if (m.s) { 74 - const { d, e, s } = m; 75 - delete m.s; 76 - delete m.e; 77 - for (let i = 0; i < s.length; i++) s[i](await gExpA(d[i])); 78 - const r = e(); 79 - if (r) await r; 80 - } 81 - return m.exp; 82 - } 83 - 84 - function gExp(id) { 85 - if (!r.has(id)) return; 86 - const m = r.get(id); 87 - if (m.s) { 88 - const { d, e, s } = m; 89 - delete m.s; 90 - delete m.e; 91 - for (let i = 0; i < s.length; i++) s[i](gExp(d[i])); 92 - e(); 93 - } 94 - return m.exp; 95 - } 96 - 97 - __instantiateAsync = async (m) => { 98 - System = __instantiateAsync = __instantiate = undefined; 99 - rF(m); 100 - return gExpA(m); 101 - }; 102 - 103 - __instantiate = (m) => { 104 - System = __instantiateAsync = __instantiate = undefined; 105 - rF(m); 106 - return gExp(m); 107 - }; 108 - })(); 109 - 110 - System.register( 111 - "https://deno.land/std@0.56.0/encoding/utf8", 112 - [], 113 - function (exports_1, context_1) { 114 - "use strict"; 115 - var encoder, decoder; 116 - var __moduleName = context_1 && context_1.id; 117 - /** Shorthand for new TextEncoder().encode() */ 118 - function encode(input) { 119 - return encoder.encode(input); 120 - } 121 - exports_1("encode", encode); 122 - /** Shorthand for new TextDecoder().decode() */ 123 - function decode(input) { 124 - return decoder.decode(input); 125 - } 126 - exports_1("decode", decode); 127 - return { 128 - setters: [], 129 - execute: function () { 130 - /** A default TextEncoder instance */ 131 - exports_1("encoder", encoder = new TextEncoder()); 132 - /** A default TextDecoder instance */ 133 - exports_1("decoder", decoder = new TextDecoder()); 134 - }, 135 - }; 136 - }, 137 - ); 138 - // Copyright the Browserify authors. MIT License. 139 - // Ported from https://github.com/browserify/path-browserify/ 140 - /** This module is browser compatible. */ 141 - System.register( 142 - "https://deno.land/std@0.56.0/path/_constants", 143 - [], 144 - function (exports_2, context_2) { 145 - "use strict"; 146 - var CHAR_UPPERCASE_A, 147 - CHAR_LOWERCASE_A, 148 - CHAR_UPPERCASE_Z, 149 - CHAR_LOWERCASE_Z, 150 - CHAR_DOT, 151 - CHAR_FORWARD_SLASH, 152 - CHAR_BACKWARD_SLASH, 153 - CHAR_VERTICAL_LINE, 154 - CHAR_COLON, 155 - CHAR_QUESTION_MARK, 156 - CHAR_UNDERSCORE, 157 - CHAR_LINE_FEED, 158 - CHAR_CARRIAGE_RETURN, 159 - CHAR_TAB, 160 - CHAR_FORM_FEED, 161 - CHAR_EXCLAMATION_MARK, 162 - CHAR_HASH, 163 - CHAR_SPACE, 164 - CHAR_NO_BREAK_SPACE, 165 - CHAR_ZERO_WIDTH_NOBREAK_SPACE, 166 - CHAR_LEFT_SQUARE_BRACKET, 167 - CHAR_RIGHT_SQUARE_BRACKET, 168 - CHAR_LEFT_ANGLE_BRACKET, 169 - CHAR_RIGHT_ANGLE_BRACKET, 170 - CHAR_LEFT_CURLY_BRACKET, 171 - CHAR_RIGHT_CURLY_BRACKET, 172 - CHAR_HYPHEN_MINUS, 173 - CHAR_PLUS, 174 - CHAR_DOUBLE_QUOTE, 175 - CHAR_SINGLE_QUOTE, 176 - CHAR_PERCENT, 177 - CHAR_SEMICOLON, 178 - CHAR_CIRCUMFLEX_ACCENT, 179 - CHAR_GRAVE_ACCENT, 180 - CHAR_AT, 181 - CHAR_AMPERSAND, 182 - CHAR_EQUAL, 183 - CHAR_0, 184 - CHAR_9, 185 - navigator, 186 - isWindows; 187 - var __moduleName = context_2 && context_2.id; 188 - return { 189 - setters: [], 190 - execute: function () { 191 - // Alphabet chars. 192 - exports_2("CHAR_UPPERCASE_A", CHAR_UPPERCASE_A = 65); /* A */ 193 - exports_2("CHAR_LOWERCASE_A", CHAR_LOWERCASE_A = 97); /* a */ 194 - exports_2("CHAR_UPPERCASE_Z", CHAR_UPPERCASE_Z = 90); /* Z */ 195 - exports_2("CHAR_LOWERCASE_Z", CHAR_LOWERCASE_Z = 122); /* z */ 196 - // Non-alphabetic chars. 197 - exports_2("CHAR_DOT", CHAR_DOT = 46); /* . */ 198 - exports_2("CHAR_FORWARD_SLASH", CHAR_FORWARD_SLASH = 47); /* / */ 199 - exports_2("CHAR_BACKWARD_SLASH", CHAR_BACKWARD_SLASH = 92); /* \ */ 200 - exports_2("CHAR_VERTICAL_LINE", CHAR_VERTICAL_LINE = 124); /* | */ 201 - exports_2("CHAR_COLON", CHAR_COLON = 58); /* : */ 202 - exports_2("CHAR_QUESTION_MARK", CHAR_QUESTION_MARK = 63); /* ? */ 203 - exports_2("CHAR_UNDERSCORE", CHAR_UNDERSCORE = 95); /* _ */ 204 - exports_2("CHAR_LINE_FEED", CHAR_LINE_FEED = 10); /* \n */ 205 - exports_2("CHAR_CARRIAGE_RETURN", CHAR_CARRIAGE_RETURN = 13); /* \r */ 206 - exports_2("CHAR_TAB", CHAR_TAB = 9); /* \t */ 207 - exports_2("CHAR_FORM_FEED", CHAR_FORM_FEED = 12); /* \f */ 208 - exports_2("CHAR_EXCLAMATION_MARK", CHAR_EXCLAMATION_MARK = 33); /* ! */ 209 - exports_2("CHAR_HASH", CHAR_HASH = 35); /* # */ 210 - exports_2("CHAR_SPACE", CHAR_SPACE = 32); /* */ 211 - exports_2( 212 - "CHAR_NO_BREAK_SPACE", 213 - CHAR_NO_BREAK_SPACE = 160, 214 - ); /* \u00A0 */ 215 - exports_2( 216 - "CHAR_ZERO_WIDTH_NOBREAK_SPACE", 217 - CHAR_ZERO_WIDTH_NOBREAK_SPACE = 65279, 218 - ); /* \uFEFF */ 219 - exports_2( 220 - "CHAR_LEFT_SQUARE_BRACKET", 221 - CHAR_LEFT_SQUARE_BRACKET = 91, 222 - ); /* [ */ 223 - exports_2( 224 - "CHAR_RIGHT_SQUARE_BRACKET", 225 - CHAR_RIGHT_SQUARE_BRACKET = 93, 226 - ); /* ] */ 227 - exports_2( 228 - "CHAR_LEFT_ANGLE_BRACKET", 229 - CHAR_LEFT_ANGLE_BRACKET = 60, 230 - ); /* < */ 231 - exports_2( 232 - "CHAR_RIGHT_ANGLE_BRACKET", 233 - CHAR_RIGHT_ANGLE_BRACKET = 62, 234 - ); /* > */ 235 - exports_2( 236 - "CHAR_LEFT_CURLY_BRACKET", 237 - CHAR_LEFT_CURLY_BRACKET = 123, 238 - ); /* { */ 239 - exports_2( 240 - "CHAR_RIGHT_CURLY_BRACKET", 241 - CHAR_RIGHT_CURLY_BRACKET = 125, 242 - ); /* } */ 243 - exports_2("CHAR_HYPHEN_MINUS", CHAR_HYPHEN_MINUS = 45); /* - */ 244 - exports_2("CHAR_PLUS", CHAR_PLUS = 43); /* + */ 245 - exports_2("CHAR_DOUBLE_QUOTE", CHAR_DOUBLE_QUOTE = 34); /* " */ 246 - exports_2("CHAR_SINGLE_QUOTE", CHAR_SINGLE_QUOTE = 39); /* ' */ 247 - exports_2("CHAR_PERCENT", CHAR_PERCENT = 37); /* % */ 248 - exports_2("CHAR_SEMICOLON", CHAR_SEMICOLON = 59); /* ; */ 249 - exports_2( 250 - "CHAR_CIRCUMFLEX_ACCENT", 251 - CHAR_CIRCUMFLEX_ACCENT = 94, 252 - ); /* ^ */ 253 - exports_2("CHAR_GRAVE_ACCENT", CHAR_GRAVE_ACCENT = 96); /* ` */ 254 - exports_2("CHAR_AT", CHAR_AT = 64); /* @ */ 255 - exports_2("CHAR_AMPERSAND", CHAR_AMPERSAND = 38); /* & */ 256 - exports_2("CHAR_EQUAL", CHAR_EQUAL = 61); /* = */ 257 - // Digits 258 - exports_2("CHAR_0", CHAR_0 = 48); /* 0 */ 259 - exports_2("CHAR_9", CHAR_9 = 57); /* 9 */ 260 - // eslint-disable-next-line @typescript-eslint/no-explicit-any 261 - navigator = globalThis.navigator; 262 - isWindows = false; 263 - exports_2("isWindows", isWindows); 264 - if (globalThis.Deno != null) { 265 - exports_2("isWindows", isWindows = Deno.build.os == "windows"); 266 - } else if (navigator?.appVersion != null) { 267 - exports_2( 268 - "isWindows", 269 - isWindows = navigator.appVersion.includes("Win"), 270 - ); 271 - } 272 - }, 273 - }; 274 - }, 275 - ); 276 - /** This module is browser compatible. */ 277 - System.register( 278 - "https://deno.land/std@0.56.0/path/_interface", 279 - [], 280 - function (exports_3, context_3) { 281 - "use strict"; 282 - var __moduleName = context_3 && context_3.id; 283 - return { 284 - setters: [], 285 - execute: function () { 286 - }, 287 - }; 288 - }, 289 - ); 290 - // Copyright the Browserify authors. MIT License. 291 - // Ported from https://github.com/browserify/path-browserify/ 292 - /** This module is browser compatible. */ 293 - System.register( 294 - "https://deno.land/std@0.56.0/path/_util", 295 - ["https://deno.land/std@0.56.0/path/_constants"], 296 - function (exports_4, context_4) { 297 - "use strict"; 298 - var _constants_ts_1; 299 - var __moduleName = context_4 && context_4.id; 300 - function assertPath(path) { 301 - if (typeof path !== "string") { 302 - throw new TypeError( 303 - `Path must be a string. Received ${JSON.stringify(path)}`, 304 - ); 305 - } 306 - } 307 - exports_4("assertPath", assertPath); 308 - function isPosixPathSeparator(code) { 309 - return code === _constants_ts_1.CHAR_FORWARD_SLASH; 310 - } 311 - exports_4("isPosixPathSeparator", isPosixPathSeparator); 312 - function isPathSeparator(code) { 313 - return isPosixPathSeparator(code) || 314 - code === _constants_ts_1.CHAR_BACKWARD_SLASH; 315 - } 316 - exports_4("isPathSeparator", isPathSeparator); 317 - function isWindowsDeviceRoot(code) { 318 - return ((code >= _constants_ts_1.CHAR_LOWERCASE_A && 319 - code <= _constants_ts_1.CHAR_LOWERCASE_Z) || 320 - (code >= _constants_ts_1.CHAR_UPPERCASE_A && 321 - code <= _constants_ts_1.CHAR_UPPERCASE_Z)); 322 - } 323 - exports_4("isWindowsDeviceRoot", isWindowsDeviceRoot); 324 - // Resolves . and .. elements in a path with directory names 325 - function normalizeString(path, allowAboveRoot, separator, isPathSeparator) { 326 - let res = ""; 327 - let lastSegmentLength = 0; 328 - let lastSlash = -1; 329 - let dots = 0; 330 - let code; 331 - for (let i = 0, len = path.length; i <= len; ++i) { 332 - if (i < len) { 333 - code = path.charCodeAt(i); 334 - } else if (isPathSeparator(code)) { 335 - break; 336 - } else { 337 - code = _constants_ts_1.CHAR_FORWARD_SLASH; 338 - } 339 - if (isPathSeparator(code)) { 340 - if (lastSlash === i - 1 || dots === 1) { 341 - // NOOP 342 - } else if (lastSlash !== i - 1 && dots === 2) { 343 - if ( 344 - res.length < 2 || 345 - lastSegmentLength !== 2 || 346 - res.charCodeAt(res.length - 1) !== _constants_ts_1.CHAR_DOT || 347 - res.charCodeAt(res.length - 2) !== _constants_ts_1.CHAR_DOT 348 - ) { 349 - if (res.length > 2) { 350 - const lastSlashIndex = res.lastIndexOf(separator); 351 - if (lastSlashIndex === -1) { 352 - res = ""; 353 - lastSegmentLength = 0; 354 - } else { 355 - res = res.slice(0, lastSlashIndex); 356 - lastSegmentLength = res.length - 1 - 357 - res.lastIndexOf(separator); 358 - } 359 - lastSlash = i; 360 - dots = 0; 361 - continue; 362 - } else if (res.length === 2 || res.length === 1) { 363 - res = ""; 364 - lastSegmentLength = 0; 365 - lastSlash = i; 366 - dots = 0; 367 - continue; 368 - } 369 - } 370 - if (allowAboveRoot) { 371 - if (res.length > 0) { 372 - res += `${separator}..`; 373 - } else { 374 - res = ".."; 375 - } 376 - lastSegmentLength = 2; 377 - } 378 - } else { 379 - if (res.length > 0) { 380 - res += separator + path.slice(lastSlash + 1, i); 381 - } else { 382 - res = path.slice(lastSlash + 1, i); 383 - } 384 - lastSegmentLength = i - lastSlash - 1; 385 - } 386 - lastSlash = i; 387 - dots = 0; 388 - } else if (code === _constants_ts_1.CHAR_DOT && dots !== -1) { 389 - ++dots; 390 - } else { 391 - dots = -1; 392 - } 393 - } 394 - return res; 395 - } 396 - exports_4("normalizeString", normalizeString); 397 - function _format(sep, pathObject) { 398 - const dir = pathObject.dir || pathObject.root; 399 - const base = pathObject.base || 400 - (pathObject.name || "") + (pathObject.ext || ""); 401 - if (!dir) { 402 - return base; 403 - } 404 - if (dir === pathObject.root) { 405 - return dir + base; 406 - } 407 - return dir + sep + base; 408 - } 409 - exports_4("_format", _format); 410 - return { 411 - setters: [ 412 - function (_constants_ts_1_1) { 413 - _constants_ts_1 = _constants_ts_1_1; 414 - }, 415 - ], 416 - execute: function () { 417 - }, 418 - }; 419 - }, 420 - ); 421 - // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 422 - /** A module to print ANSI terminal colors. Inspired by chalk, kleur, and colors 423 - * on npm. 424 - * 425 - * ``` 426 - * import { bgBlue, red, bold } from "https://deno.land/std/fmt/colors.ts"; 427 - * console.log(bgBlue(red(bold("Hello world!")))); 428 - * ``` 429 - * 430 - * This module supports `NO_COLOR` environmental variable disabling any coloring 431 - * if `NO_COLOR` is set. 432 - * 433 - * This module is browser compatible. */ 434 - System.register( 435 - "https://deno.land/std@0.56.0/fmt/colors", 436 - [], 437 - function (exports_5, context_5) { 438 - "use strict"; 439 - var noColor, enabled, ANSI_PATTERN; 440 - var __moduleName = context_5 && context_5.id; 441 - function setColorEnabled(value) { 442 - if (noColor) { 443 - return; 444 - } 445 - enabled = value; 446 - } 447 - exports_5("setColorEnabled", setColorEnabled); 448 - function getColorEnabled() { 449 - return enabled; 450 - } 451 - exports_5("getColorEnabled", getColorEnabled); 452 - function code(open, close) { 453 - return { 454 - open: `\x1b[${open.join(";")}m`, 455 - close: `\x1b[${close}m`, 456 - regexp: new RegExp(`\\x1b\\[${close}m`, "g"), 457 - }; 458 - } 459 - function run(str, code) { 460 - return enabled 461 - ? `${code.open}${str.replace(code.regexp, code.open)}${code.close}` 462 - : str; 463 - } 464 - function reset(str) { 465 - return run(str, code([0], 0)); 466 - } 467 - exports_5("reset", reset); 468 - function bold(str) { 469 - return run(str, code([1], 22)); 470 - } 471 - exports_5("bold", bold); 472 - function dim(str) { 473 - return run(str, code([2], 22)); 474 - } 475 - exports_5("dim", dim); 476 - function italic(str) { 477 - return run(str, code([3], 23)); 478 - } 479 - exports_5("italic", italic); 480 - function underline(str) { 481 - return run(str, code([4], 24)); 482 - } 483 - exports_5("underline", underline); 484 - function inverse(str) { 485 - return run(str, code([7], 27)); 486 - } 487 - exports_5("inverse", inverse); 488 - function hidden(str) { 489 - return run(str, code([8], 28)); 490 - } 491 - exports_5("hidden", hidden); 492 - function strikethrough(str) { 493 - return run(str, code([9], 29)); 494 - } 495 - exports_5("strikethrough", strikethrough); 496 - function black(str) { 497 - return run(str, code([30], 39)); 498 - } 499 - exports_5("black", black); 500 - function red(str) { 501 - return run(str, code([31], 39)); 502 - } 503 - exports_5("red", red); 504 - function green(str) { 505 - return run(str, code([32], 39)); 506 - } 507 - exports_5("green", green); 508 - function yellow(str) { 509 - return run(str, code([33], 39)); 510 - } 511 - exports_5("yellow", yellow); 512 - function blue(str) { 513 - return run(str, code([34], 39)); 514 - } 515 - exports_5("blue", blue); 516 - function magenta(str) { 517 - return run(str, code([35], 39)); 518 - } 519 - exports_5("magenta", magenta); 520 - function cyan(str) { 521 - return run(str, code([36], 39)); 522 - } 523 - exports_5("cyan", cyan); 524 - function white(str) { 525 - return run(str, code([37], 39)); 526 - } 527 - exports_5("white", white); 528 - function gray(str) { 529 - return run(str, code([90], 39)); 530 - } 531 - exports_5("gray", gray); 532 - function bgBlack(str) { 533 - return run(str, code([40], 49)); 534 - } 535 - exports_5("bgBlack", bgBlack); 536 - function bgRed(str) { 537 - return run(str, code([41], 49)); 538 - } 539 - exports_5("bgRed", bgRed); 540 - function bgGreen(str) { 541 - return run(str, code([42], 49)); 542 - } 543 - exports_5("bgGreen", bgGreen); 544 - function bgYellow(str) { 545 - return run(str, code([43], 49)); 546 - } 547 - exports_5("bgYellow", bgYellow); 548 - function bgBlue(str) { 549 - return run(str, code([44], 49)); 550 - } 551 - exports_5("bgBlue", bgBlue); 552 - function bgMagenta(str) { 553 - return run(str, code([45], 49)); 554 - } 555 - exports_5("bgMagenta", bgMagenta); 556 - function bgCyan(str) { 557 - return run(str, code([46], 49)); 558 - } 559 - exports_5("bgCyan", bgCyan); 560 - function bgWhite(str) { 561 - return run(str, code([47], 49)); 562 - } 563 - exports_5("bgWhite", bgWhite); 564 - /* Special Color Sequences */ 565 - function clampAndTruncate(n, max = 255, min = 0) { 566 - return Math.trunc(Math.max(Math.min(n, max), min)); 567 - } 568 - /** Set text color using paletted 8bit colors. 569 - * https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit */ 570 - function rgb8(str, color) { 571 - return run(str, code([38, 5, clampAndTruncate(color)], 39)); 572 - } 573 - exports_5("rgb8", rgb8); 574 - /** Set background color using paletted 8bit colors. 575 - * https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit */ 576 - function bgRgb8(str, color) { 577 - return run(str, code([48, 5, clampAndTruncate(color)], 49)); 578 - } 579 - exports_5("bgRgb8", bgRgb8); 580 - /** Set text color using 24bit rgb. 581 - * `color` can be a number in range `0x000000` to `0xffffff` or 582 - * an `Rgb`. 583 - * 584 - * To produce the color magenta: 585 - * 586 - * rgba24("foo", 0xff00ff); 587 - * rgba24("foo", {r: 255, g: 0, b: 255}); 588 - */ 589 - function rgb24(str, color) { 590 - if (typeof color === "number") { 591 - return run( 592 - str, 593 - code( 594 - [38, 2, (color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff], 595 - 39, 596 - ), 597 - ); 598 - } 599 - return run( 600 - str, 601 - code([ 602 - 38, 603 - 2, 604 - clampAndTruncate(color.r), 605 - clampAndTruncate(color.g), 606 - clampAndTruncate(color.b), 607 - ], 39), 608 - ); 609 - } 610 - exports_5("rgb24", rgb24); 611 - /** Set background color using 24bit rgb. 612 - * `color` can be a number in range `0x000000` to `0xffffff` or 613 - * an `Rgb`. 614 - * 615 - * To produce the color magenta: 616 - * 617 - * bgRgba24("foo", 0xff00ff); 618 - * bgRgba24("foo", {r: 255, g: 0, b: 255}); 619 - */ 620 - function bgRgb24(str, color) { 621 - if (typeof color === "number") { 622 - return run( 623 - str, 624 - code( 625 - [48, 2, (color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff], 626 - 49, 627 - ), 628 - ); 629 - } 630 - return run( 631 - str, 632 - code([ 633 - 48, 634 - 2, 635 - clampAndTruncate(color.r), 636 - clampAndTruncate(color.g), 637 - clampAndTruncate(color.b), 638 - ], 49), 639 - ); 640 - } 641 - exports_5("bgRgb24", bgRgb24); 642 - function stripColor(string) { 643 - return string.replace(ANSI_PATTERN, ""); 644 - } 645 - exports_5("stripColor", stripColor); 646 - return { 647 - setters: [], 648 - execute: function () { 649 - noColor = globalThis.Deno?.noColor ?? true; 650 - enabled = !noColor; 651 - // https://github.com/chalk/ansi-regex/blob/2b56fb0c7a07108e5b54241e8faec160d393aedb/index.js 652 - ANSI_PATTERN = new RegExp( 653 - [ 654 - "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)", 655 - "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))", 656 - ].join("|"), 657 - "g", 658 - ); 659 - }, 660 - }; 661 - }, 662 - ); 663 - // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 664 - /** This module is browser compatible. */ 665 - System.register( 666 - "https://deno.land/std@0.56.0/testing/diff", 667 - [], 668 - function (exports_6, context_6) { 669 - "use strict"; 670 - var DiffType, REMOVED, COMMON, ADDED; 671 - var __moduleName = context_6 && context_6.id; 672 - function createCommon(A, B, reverse) { 673 - const common = []; 674 - if (A.length === 0 || B.length === 0) { 675 - return []; 676 - } 677 - for (let i = 0; i < Math.min(A.length, B.length); i += 1) { 678 - if ( 679 - A[reverse ? A.length - i - 1 : i] === 680 - B[reverse ? B.length - i - 1 : i] 681 - ) { 682 - common.push(A[reverse ? A.length - i - 1 : i]); 683 - } else { 684 - return common; 685 - } 686 - } 687 - return common; 688 - } 689 - function diff(A, B) { 690 - const prefixCommon = createCommon(A, B); 691 - const suffixCommon = createCommon( 692 - A.slice(prefixCommon.length), 693 - B.slice(prefixCommon.length), 694 - true, 695 - ).reverse(); 696 - A = suffixCommon.length 697 - ? A.slice(prefixCommon.length, -suffixCommon.length) 698 - : A.slice(prefixCommon.length); 699 - B = suffixCommon.length 700 - ? B.slice(prefixCommon.length, -suffixCommon.length) 701 - : B.slice(prefixCommon.length); 702 - const swapped = B.length > A.length; 703 - [A, B] = swapped ? [B, A] : [A, B]; 704 - const M = A.length; 705 - const N = B.length; 706 - if (!M && !N && !suffixCommon.length && !prefixCommon.length) { 707 - return []; 708 - } 709 - if (!N) { 710 - return [ 711 - ...prefixCommon.map((c) => ({ type: DiffType.common, value: c })), 712 - ...A.map((a) => ({ 713 - type: swapped ? DiffType.added : DiffType.removed, 714 - value: a, 715 - })), 716 - ...suffixCommon.map((c) => ({ type: DiffType.common, value: c })), 717 - ]; 718 - } 719 - const offset = N; 720 - const delta = M - N; 721 - const size = M + N + 1; 722 - const fp = new Array(size).fill({ y: -1 }); 723 - /** 724 - * INFO: 725 - * This buffer is used to save memory and improve performance. 726 - * The first half is used to save route and last half is used to save diff 727 - * type. 728 - * This is because, when I kept new uint8array area to save type,performance 729 - * worsened. 730 - */ 731 - const routes = new Uint32Array((M * N + size + 1) * 2); 732 - const diffTypesPtrOffset = routes.length / 2; 733 - let ptr = 0; 734 - let p = -1; 735 - function backTrace(A, B, current, swapped) { 736 - const M = A.length; 737 - const N = B.length; 738 - const result = []; 739 - let a = M - 1; 740 - let b = N - 1; 741 - let j = routes[current.id]; 742 - let type = routes[current.id + diffTypesPtrOffset]; 743 - while (true) { 744 - if (!j && !type) { 745 - break; 746 - } 747 - const prev = j; 748 - if (type === REMOVED) { 749 - result.unshift({ 750 - type: swapped ? DiffType.removed : DiffType.added, 751 - value: B[b], 752 - }); 753 - b -= 1; 754 - } else if (type === ADDED) { 755 - result.unshift({ 756 - type: swapped ? DiffType.added : DiffType.removed, 757 - value: A[a], 758 - }); 759 - a -= 1; 760 - } else { 761 - result.unshift({ type: DiffType.common, value: A[a] }); 762 - a -= 1; 763 - b -= 1; 764 - } 765 - j = routes[prev]; 766 - type = routes[prev + diffTypesPtrOffset]; 767 - } 768 - return result; 769 - } 770 - function createFP(slide, down, k, M) { 771 - if (slide && slide.y === -1 && down && down.y === -1) { 772 - return { y: 0, id: 0 }; 773 - } 774 - if ( 775 - (down && down.y === -1) || 776 - k === M || 777 - (slide && slide.y) > (down && down.y) + 1 778 - ) { 779 - const prev = slide.id; 780 - ptr++; 781 - routes[ptr] = prev; 782 - routes[ptr + diffTypesPtrOffset] = ADDED; 783 - return { y: slide.y, id: ptr }; 784 - } else { 785 - const prev = down.id; 786 - ptr++; 787 - routes[ptr] = prev; 788 - routes[ptr + diffTypesPtrOffset] = REMOVED; 789 - return { y: down.y + 1, id: ptr }; 790 - } 791 - } 792 - function snake(k, slide, down, _offset, A, B) { 793 - const M = A.length; 794 - const N = B.length; 795 - if (k < -N || M < k) { 796 - return { y: -1, id: -1 }; 797 - } 798 - const fp = createFP(slide, down, k, M); 799 - while (fp.y + k < M && fp.y < N && A[fp.y + k] === B[fp.y]) { 800 - const prev = fp.id; 801 - ptr++; 802 - fp.id = ptr; 803 - fp.y += 1; 804 - routes[ptr] = prev; 805 - routes[ptr + diffTypesPtrOffset] = COMMON; 806 - } 807 - return fp; 808 - } 809 - while (fp[delta + offset].y < N) { 810 - p = p + 1; 811 - for (let k = -p; k < delta; ++k) { 812 - fp[k + offset] = snake( 813 - k, 814 - fp[k - 1 + offset], 815 - fp[k + 1 + offset], 816 - offset, 817 - A, 818 - B, 819 - ); 820 - } 821 - for (let k = delta + p; k > delta; --k) { 822 - fp[k + offset] = snake( 823 - k, 824 - fp[k - 1 + offset], 825 - fp[k + 1 + offset], 826 - offset, 827 - A, 828 - B, 829 - ); 830 - } 831 - fp[delta + offset] = snake( 832 - delta, 833 - fp[delta - 1 + offset], 834 - fp[delta + 1 + offset], 835 - offset, 836 - A, 837 - B, 838 - ); 839 - } 840 - return [ 841 - ...prefixCommon.map((c) => ({ type: DiffType.common, value: c })), 842 - ...backTrace(A, B, fp[delta + offset], swapped), 843 - ...suffixCommon.map((c) => ({ type: DiffType.common, value: c })), 844 - ]; 845 - } 846 - exports_6("default", diff); 847 - return { 848 - setters: [], 849 - execute: function () { 850 - (function (DiffType) { 851 - DiffType["removed"] = "removed"; 852 - DiffType["common"] = "common"; 853 - DiffType["added"] = "added"; 854 - })(DiffType || (DiffType = {})); 855 - exports_6("DiffType", DiffType); 856 - REMOVED = 1; 857 - COMMON = 2; 858 - ADDED = 3; 859 - }, 860 - }; 861 - }, 862 - ); 863 - // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 864 - /** This module is browser compatible. Do not rely on good formatting of values 865 - * for AssertionError messages in browsers. */ 866 - System.register( 867 - "https://deno.land/std@0.56.0/testing/asserts", 868 - [ 869 - "https://deno.land/std@0.56.0/fmt/colors", 870 - "https://deno.land/std@0.56.0/testing/diff", 871 - ], 872 - function (exports_7, context_7) { 873 - "use strict"; 874 - var colors_ts_1, diff_ts_1, CAN_NOT_DISPLAY, AssertionError; 875 - var __moduleName = context_7 && context_7.id; 876 - function format(v) { 877 - let string = globalThis.Deno ? Deno.inspect(v) : String(v); 878 - if (typeof v == "string") { 879 - string = `"${string.replace(/(?=["\\])/g, "\\")}"`; 880 - } 881 - return string; 882 - } 883 - function createColor(diffType) { 884 - switch (diffType) { 885 - case diff_ts_1.DiffType.added: 886 - return (s) => colors_ts_1.green(colors_ts_1.bold(s)); 887 - case diff_ts_1.DiffType.removed: 888 - return (s) => colors_ts_1.red(colors_ts_1.bold(s)); 889 - default: 890 - return colors_ts_1.white; 891 - } 892 - } 893 - function createSign(diffType) { 894 - switch (diffType) { 895 - case diff_ts_1.DiffType.added: 896 - return "+ "; 897 - case diff_ts_1.DiffType.removed: 898 - return "- "; 899 - default: 900 - return " "; 901 - } 902 - } 903 - function buildMessage(diffResult) { 904 - const messages = []; 905 - messages.push(""); 906 - messages.push(""); 907 - messages.push( 908 - ` ${colors_ts_1.gray(colors_ts_1.bold("[Diff]"))} ${ 909 - colors_ts_1.red(colors_ts_1.bold("Actual")) 910 - } / ${colors_ts_1.green(colors_ts_1.bold("Expected"))}`, 911 - ); 912 - messages.push(""); 913 - messages.push(""); 914 - diffResult.forEach((result) => { 915 - const c = createColor(result.type); 916 - messages.push(c(`${createSign(result.type)}${result.value}`)); 917 - }); 918 - messages.push(""); 919 - return messages; 920 - } 921 - function isKeyedCollection(x) { 922 - return [Symbol.iterator, "size"].every((k) => k in x); 923 - } 924 - function equal(c, d) { 925 - const seen = new Map(); 926 - return (function compare(a, b) { 927 - // Have to render RegExp & Date for string comparison 928 - // unless it's mistreated as object 929 - if ( 930 - a && 931 - b && 932 - ((a instanceof RegExp && b instanceof RegExp) || 933 - (a instanceof Date && b instanceof Date)) 934 - ) { 935 - return String(a) === String(b); 936 - } 937 - if (Object.is(a, b)) { 938 - return true; 939 - } 940 - if (a && typeof a === "object" && b && typeof b === "object") { 941 - if (seen.get(a) === b) { 942 - return true; 943 - } 944 - if (Object.keys(a || {}).length !== Object.keys(b || {}).length) { 945 - return false; 946 - } 947 - if (isKeyedCollection(a) && isKeyedCollection(b)) { 948 - if (a.size !== b.size) { 949 - return false; 950 - } 951 - let unmatchedEntries = a.size; 952 - for (const [aKey, aValue] of a.entries()) { 953 - for (const [bKey, bValue] of b.entries()) { 954 - /* Given that Map keys can be references, we need 955 - * to ensure that they are also deeply equal */ 956 - if ( 957 - (aKey === aValue && bKey === bValue && compare(aKey, bKey)) || 958 - (compare(aKey, bKey) && compare(aValue, bValue)) 959 - ) { 960 - unmatchedEntries--; 961 - } 962 - } 963 - } 964 - return unmatchedEntries === 0; 965 - } 966 - const merged = { ...a, ...b }; 967 - for (const key in merged) { 968 - if (!compare(a && a[key], b && b[key])) { 969 - return false; 970 - } 971 - } 972 - seen.set(a, b); 973 - return true; 974 - } 975 - return false; 976 - })(c, d); 977 - } 978 - exports_7("equal", equal); 979 - /** Make an assertion, if not `true`, then throw. */ 980 - function assert(expr, msg = "") { 981 - if (!expr) { 982 - throw new AssertionError(msg); 983 - } 984 - } 985 - exports_7("assert", assert); 986 - /** 987 - * Make an assertion that `actual` and `expected` are equal, deeply. If not 988 - * deeply equal, then throw. 989 - */ 990 - function assertEquals(actual, expected, msg) { 991 - if (equal(actual, expected)) { 992 - return; 993 - } 994 - let message = ""; 995 - const actualString = format(actual); 996 - const expectedString = format(expected); 997 - try { 998 - const diffResult = diff_ts_1.default( 999 - actualString.split("\n"), 1000 - expectedString.split("\n"), 1001 - ); 1002 - const diffMsg = buildMessage(diffResult).join("\n"); 1003 - message = `Values are not equal:\n${diffMsg}`; 1004 - } catch (e) { 1005 - message = `\n${colors_ts_1.red(CAN_NOT_DISPLAY)} + \n\n`; 1006 - } 1007 - if (msg) { 1008 - message = msg; 1009 - } 1010 - throw new AssertionError(message); 1011 - } 1012 - exports_7("assertEquals", assertEquals); 1013 - /** 1014 - * Make an assertion that `actual` and `expected` are not equal, deeply. 1015 - * If not then throw. 1016 - */ 1017 - function assertNotEquals(actual, expected, msg) { 1018 - if (!equal(actual, expected)) { 1019 - return; 1020 - } 1021 - let actualString; 1022 - let expectedString; 1023 - try { 1024 - actualString = String(actual); 1025 - } catch (e) { 1026 - actualString = "[Cannot display]"; 1027 - } 1028 - try { 1029 - expectedString = String(expected); 1030 - } catch (e) { 1031 - expectedString = "[Cannot display]"; 1032 - } 1033 - if (!msg) { 1034 - msg = `actual: ${actualString} expected: ${expectedString}`; 1035 - } 1036 - throw new AssertionError(msg); 1037 - } 1038 - exports_7("assertNotEquals", assertNotEquals); 1039 - /** 1040 - * Make an assertion that `actual` and `expected` are strictly equal. If 1041 - * not then throw. 1042 - */ 1043 - function assertStrictEq(actual, expected, msg) { 1044 - if (actual === expected) { 1045 - return; 1046 - } 1047 - let message; 1048 - if (msg) { 1049 - message = msg; 1050 - } else { 1051 - const actualString = format(actual); 1052 - const expectedString = format(expected); 1053 - if (actualString === expectedString) { 1054 - const withOffset = actualString 1055 - .split("\n") 1056 - .map((l) => ` ${l}`) 1057 - .join("\n"); 1058 - message = 1059 - `Values have the same structure but are not reference-equal:\n\n${ 1060 - colors_ts_1.red(withOffset) 1061 - }\n`; 1062 - } else { 1063 - try { 1064 - const diffResult = diff_ts_1.default( 1065 - actualString.split("\n"), 1066 - expectedString.split("\n"), 1067 - ); 1068 - const diffMsg = buildMessage(diffResult).join("\n"); 1069 - message = `Values are not strictly equal:\n${diffMsg}`; 1070 - } catch (e) { 1071 - message = `\n${colors_ts_1.red(CAN_NOT_DISPLAY)} + \n\n`; 1072 - } 1073 - } 1074 - } 1075 - throw new AssertionError(message); 1076 - } 1077 - exports_7("assertStrictEq", assertStrictEq); 1078 - /** 1079 - * Make an assertion that actual contains expected. If not 1080 - * then thrown. 1081 - */ 1082 - function assertStrContains(actual, expected, msg) { 1083 - if (!actual.includes(expected)) { 1084 - if (!msg) { 1085 - msg = `actual: "${actual}" expected to contain: "${expected}"`; 1086 - } 1087 - throw new AssertionError(msg); 1088 - } 1089 - } 1090 - exports_7("assertStrContains", assertStrContains); 1091 - /** 1092 - * Make an assertion that `actual` contains the `expected` values 1093 - * If not then thrown. 1094 - */ 1095 - function assertArrayContains(actual, expected, msg) { 1096 - const missing = []; 1097 - for (let i = 0; i < expected.length; i++) { 1098 - let found = false; 1099 - for (let j = 0; j < actual.length; j++) { 1100 - if (equal(expected[i], actual[j])) { 1101 - found = true; 1102 - break; 1103 - } 1104 - } 1105 - if (!found) { 1106 - missing.push(expected[i]); 1107 - } 1108 - } 1109 - if (missing.length === 0) { 1110 - return; 1111 - } 1112 - if (!msg) { 1113 - msg = `actual: "${format(actual)}" expected to contain: "${ 1114 - format(expected) 1115 - }"\nmissing: ${format(missing)}`; 1116 - } 1117 - throw new AssertionError(msg); 1118 - } 1119 - exports_7("assertArrayContains", assertArrayContains); 1120 - /** 1121 - * Make an assertion that `actual` match RegExp `expected`. If not 1122 - * then thrown 1123 - */ 1124 - function assertMatch(actual, expected, msg) { 1125 - if (!expected.test(actual)) { 1126 - if (!msg) { 1127 - msg = `actual: "${actual}" expected to match: "${expected}"`; 1128 - } 1129 - throw new AssertionError(msg); 1130 - } 1131 - } 1132 - exports_7("assertMatch", assertMatch); 1133 - /** 1134 - * Forcefully throws a failed assertion 1135 - */ 1136 - function fail(msg) { 1137 - // eslint-disable-next-line @typescript-eslint/no-use-before-define 1138 - assert(false, `Failed assertion${msg ? `: ${msg}` : "."}`); 1139 - } 1140 - exports_7("fail", fail); 1141 - /** Executes a function, expecting it to throw. If it does not, then it 1142 - * throws. An error class and a string that should be included in the 1143 - * error message can also be asserted. 1144 - */ 1145 - function assertThrows(fn, ErrorClass, msgIncludes = "", msg) { 1146 - let doesThrow = false; 1147 - let error = null; 1148 - try { 1149 - fn(); 1150 - } catch (e) { 1151 - if ( 1152 - ErrorClass && !(Object.getPrototypeOf(e) === ErrorClass.prototype) 1153 - ) { 1154 - msg = 1155 - `Expected error to be instance of "${ErrorClass.name}", but was "${e.constructor.name}"${ 1156 - msg ? `: ${msg}` : "." 1157 - }`; 1158 - throw new AssertionError(msg); 1159 - } 1160 - if ( 1161 - msgIncludes && 1162 - !colors_ts_1.stripColor(e.message).includes( 1163 - colors_ts_1.stripColor(msgIncludes), 1164 - ) 1165 - ) { 1166 - msg = 1167 - `Expected error message to include "${msgIncludes}", but got "${e.message}"${ 1168 - msg ? `: ${msg}` : "." 1169 - }`; 1170 - throw new AssertionError(msg); 1171 - } 1172 - doesThrow = true; 1173 - error = e; 1174 - } 1175 - if (!doesThrow) { 1176 - msg = `Expected function to throw${msg ? `: ${msg}` : "."}`; 1177 - throw new AssertionError(msg); 1178 - } 1179 - return error; 1180 - } 1181 - exports_7("assertThrows", assertThrows); 1182 - async function assertThrowsAsync(fn, ErrorClass, msgIncludes = "", msg) { 1183 - let doesThrow = false; 1184 - let error = null; 1185 - try { 1186 - await fn(); 1187 - } catch (e) { 1188 - if ( 1189 - ErrorClass && !(Object.getPrototypeOf(e) === ErrorClass.prototype) 1190 - ) { 1191 - msg = 1192 - `Expected error to be instance of "${ErrorClass.name}", but got "${e.name}"${ 1193 - msg ? `: ${msg}` : "." 1194 - }`; 1195 - throw new AssertionError(msg); 1196 - } 1197 - if ( 1198 - msgIncludes && 1199 - !colors_ts_1.stripColor(e.message).includes( 1200 - colors_ts_1.stripColor(msgIncludes), 1201 - ) 1202 - ) { 1203 - msg = 1204 - `Expected error message to include "${msgIncludes}", but got "${e.message}"${ 1205 - msg ? `: ${msg}` : "." 1206 - }`; 1207 - throw new AssertionError(msg); 1208 - } 1209 - doesThrow = true; 1210 - error = e; 1211 - } 1212 - if (!doesThrow) { 1213 - msg = `Expected function to throw${msg ? `: ${msg}` : "."}`; 1214 - throw new AssertionError(msg); 1215 - } 1216 - return error; 1217 - } 1218 - exports_7("assertThrowsAsync", assertThrowsAsync); 1219 - /** Use this to stub out methods that will throw when invoked. */ 1220 - function unimplemented(msg) { 1221 - throw new AssertionError(msg || "unimplemented"); 1222 - } 1223 - exports_7("unimplemented", unimplemented); 1224 - /** Use this to assert unreachable code. */ 1225 - function unreachable() { 1226 - throw new AssertionError("unreachable"); 1227 - } 1228 - exports_7("unreachable", unreachable); 1229 - return { 1230 - setters: [ 1231 - function (colors_ts_1_1) { 1232 - colors_ts_1 = colors_ts_1_1; 1233 - }, 1234 - function (diff_ts_1_1) { 1235 - diff_ts_1 = diff_ts_1_1; 1236 - }, 1237 - ], 1238 - execute: function () { 1239 - CAN_NOT_DISPLAY = "[Cannot display]"; 1240 - AssertionError = class AssertionError extends Error { 1241 - constructor(message) { 1242 - super(message); 1243 - this.name = "AssertionError"; 1244 - } 1245 - }; 1246 - exports_7("AssertionError", AssertionError); 1247 - }, 1248 - }; 1249 - }, 1250 - ); 1251 - // Copyright the Browserify authors. MIT License. 1252 - // Ported from https://github.com/browserify/path-browserify/ 1253 - /** This module is browser compatible. */ 1254 - System.register( 1255 - "https://deno.land/std@0.56.0/path/win32", 1256 - [ 1257 - "https://deno.land/std@0.56.0/path/_constants", 1258 - "https://deno.land/std@0.56.0/path/_util", 1259 - "https://deno.land/std@0.56.0/testing/asserts", 1260 - ], 1261 - function (exports_8, context_8) { 1262 - "use strict"; 1263 - var _constants_ts_2, _util_ts_1, asserts_ts_1, sep, delimiter; 1264 - var __moduleName = context_8 && context_8.id; 1265 - function resolve(...pathSegments) { 1266 - let resolvedDevice = ""; 1267 - let resolvedTail = ""; 1268 - let resolvedAbsolute = false; 1269 - for (let i = pathSegments.length - 1; i >= -1; i--) { 1270 - let path; 1271 - if (i >= 0) { 1272 - path = pathSegments[i]; 1273 - } else if (!resolvedDevice) { 1274 - if (globalThis.Deno == null) { 1275 - throw new TypeError( 1276 - "Resolved a drive-letter-less path without a CWD.", 1277 - ); 1278 - } 1279 - path = Deno.cwd(); 1280 - } else { 1281 - if (globalThis.Deno == null) { 1282 - throw new TypeError("Resolved a relative path without a CWD."); 1283 - } 1284 - // Windows has the concept of drive-specific current working 1285 - // directories. If we've resolved a drive letter but not yet an 1286 - // absolute path, get cwd for that drive, or the process cwd if 1287 - // the drive cwd is not available. We're sure the device is not 1288 - // a UNC path at this points, because UNC paths are always absolute. 1289 - path = Deno.env.get(`=${resolvedDevice}`) || Deno.cwd(); 1290 - // Verify that a cwd was found and that it actually points 1291 - // to our drive. If not, default to the drive's root. 1292 - if ( 1293 - path === undefined || 1294 - path.slice(0, 3).toLowerCase() !== 1295 - `${resolvedDevice.toLowerCase()}\\` 1296 - ) { 1297 - path = `${resolvedDevice}\\`; 1298 - } 1299 - } 1300 - _util_ts_1.assertPath(path); 1301 - const len = path.length; 1302 - // Skip empty entries 1303 - if (len === 0) { 1304 - continue; 1305 - } 1306 - let rootEnd = 0; 1307 - let device = ""; 1308 - let isAbsolute = false; 1309 - const code = path.charCodeAt(0); 1310 - // Try to match a root 1311 - if (len > 1) { 1312 - if (_util_ts_1.isPathSeparator(code)) { 1313 - // Possible UNC root 1314 - // If we started with a separator, we know we at least have an 1315 - // absolute path of some kind (UNC or otherwise) 1316 - isAbsolute = true; 1317 - if (_util_ts_1.isPathSeparator(path.charCodeAt(1))) { 1318 - // Matched double path separator at beginning 1319 - let j = 2; 1320 - let last = j; 1321 - // Match 1 or more non-path separators 1322 - for (; j < len; ++j) { 1323 - if (_util_ts_1.isPathSeparator(path.charCodeAt(j))) { 1324 - break; 1325 - } 1326 - } 1327 - if (j < len && j !== last) { 1328 - const firstPart = path.slice(last, j); 1329 - // Matched! 1330 - last = j; 1331 - // Match 1 or more path separators 1332 - for (; j < len; ++j) { 1333 - if (!_util_ts_1.isPathSeparator(path.charCodeAt(j))) { 1334 - break; 1335 - } 1336 - } 1337 - if (j < len && j !== last) { 1338 - // Matched! 1339 - last = j; 1340 - // Match 1 or more non-path separators 1341 - for (; j < len; ++j) { 1342 - if (_util_ts_1.isPathSeparator(path.charCodeAt(j))) { 1343 - break; 1344 - } 1345 - } 1346 - if (j === len) { 1347 - // We matched a UNC root only 1348 - device = `\\\\${firstPart}\\${path.slice(last)}`; 1349 - rootEnd = j; 1350 - } else if (j !== last) { 1351 - // We matched a UNC root with leftovers 1352 - device = `\\\\${firstPart}\\${path.slice(last, j)}`; 1353 - rootEnd = j; 1354 - } 1355 - } 1356 - } 1357 - } else { 1358 - rootEnd = 1; 1359 - } 1360 - } else if (_util_ts_1.isWindowsDeviceRoot(code)) { 1361 - // Possible device root 1362 - if (path.charCodeAt(1) === _constants_ts_2.CHAR_COLON) { 1363 - device = path.slice(0, 2); 1364 - rootEnd = 2; 1365 - if (len > 2) { 1366 - if (_util_ts_1.isPathSeparator(path.charCodeAt(2))) { 1367 - // Treat separator following drive name as an absolute path 1368 - // indicator 1369 - isAbsolute = true; 1370 - rootEnd = 3; 1371 - } 1372 - } 1373 - } 1374 - } 1375 - } else if (_util_ts_1.isPathSeparator(code)) { 1376 - // `path` contains just a path separator 1377 - rootEnd = 1; 1378 - isAbsolute = true; 1379 - } 1380 - if ( 1381 - device.length > 0 && 1382 - resolvedDevice.length > 0 && 1383 - device.toLowerCase() !== resolvedDevice.toLowerCase() 1384 - ) { 1385 - // This path points to another device so it is not applicable 1386 - continue; 1387 - } 1388 - if (resolvedDevice.length === 0 && device.length > 0) { 1389 - resolvedDevice = device; 1390 - } 1391 - if (!resolvedAbsolute) { 1392 - resolvedTail = `${path.slice(rootEnd)}\\${resolvedTail}`; 1393 - resolvedAbsolute = isAbsolute; 1394 - } 1395 - if (resolvedAbsolute && resolvedDevice.length > 0) { 1396 - break; 1397 - } 1398 - } 1399 - // At this point the path should be resolved to a full absolute path, 1400 - // but handle relative paths to be safe (might happen when process.cwd() 1401 - // fails) 1402 - // Normalize the tail path 1403 - resolvedTail = _util_ts_1.normalizeString( 1404 - resolvedTail, 1405 - !resolvedAbsolute, 1406 - "\\", 1407 - _util_ts_1.isPathSeparator, 1408 - ); 1409 - return resolvedDevice + (resolvedAbsolute ? "\\" : "") + resolvedTail || 1410 - "."; 1411 - } 1412 - exports_8("resolve", resolve); 1413 - function normalize(path) { 1414 - _util_ts_1.assertPath(path); 1415 - const len = path.length; 1416 - if (len === 0) { 1417 - return "."; 1418 - } 1419 - let rootEnd = 0; 1420 - let device; 1421 - let isAbsolute = false; 1422 - const code = path.charCodeAt(0); 1423 - // Try to match a root 1424 - if (len > 1) { 1425 - if (_util_ts_1.isPathSeparator(code)) { 1426 - // Possible UNC root 1427 - // If we started with a separator, we know we at least have an absolute 1428 - // path of some kind (UNC or otherwise) 1429 - isAbsolute = true; 1430 - if (_util_ts_1.isPathSeparator(path.charCodeAt(1))) { 1431 - // Matched double path separator at beginning 1432 - let j = 2; 1433 - let last = j; 1434 - // Match 1 or more non-path separators 1435 - for (; j < len; ++j) { 1436 - if (_util_ts_1.isPathSeparator(path.charCodeAt(j))) { 1437 - break; 1438 - } 1439 - } 1440 - if (j < len && j !== last) { 1441 - const firstPart = path.slice(last, j); 1442 - // Matched! 1443 - last = j; 1444 - // Match 1 or more path separators 1445 - for (; j < len; ++j) { 1446 - if (!_util_ts_1.isPathSeparator(path.charCodeAt(j))) { 1447 - break; 1448 - } 1449 - } 1450 - if (j < len && j !== last) { 1451 - // Matched! 1452 - last = j; 1453 - // Match 1 or more non-path separators 1454 - for (; j < len; ++j) { 1455 - if (_util_ts_1.isPathSeparator(path.charCodeAt(j))) { 1456 - break; 1457 - } 1458 - } 1459 - if (j === len) { 1460 - // We matched a UNC root only 1461 - // Return the normalized version of the UNC root since there 1462 - // is nothing left to process 1463 - return `\\\\${firstPart}\\${path.slice(last)}\\`; 1464 - } else if (j !== last) { 1465 - // We matched a UNC root with leftovers 1466 - device = `\\\\${firstPart}\\${path.slice(last, j)}`; 1467 - rootEnd = j; 1468 - } 1469 - } 1470 - } 1471 - } else { 1472 - rootEnd = 1; 1473 - } 1474 - } else if (_util_ts_1.isWindowsDeviceRoot(code)) { 1475 - // Possible device root 1476 - if (path.charCodeAt(1) === _constants_ts_2.CHAR_COLON) { 1477 - device = path.slice(0, 2); 1478 - rootEnd = 2; 1479 - if (len > 2) { 1480 - if (_util_ts_1.isPathSeparator(path.charCodeAt(2))) { 1481 - // Treat separator following drive name as an absolute path 1482 - // indicator 1483 - isAbsolute = true; 1484 - rootEnd = 3; 1485 - } 1486 - } 1487 - } 1488 - } 1489 - } else if (_util_ts_1.isPathSeparator(code)) { 1490 - // `path` contains just a path separator, exit early to avoid unnecessary 1491 - // work 1492 - return "\\"; 1493 - } 1494 - let tail; 1495 - if (rootEnd < len) { 1496 - tail = _util_ts_1.normalizeString( 1497 - path.slice(rootEnd), 1498 - !isAbsolute, 1499 - "\\", 1500 - _util_ts_1.isPathSeparator, 1501 - ); 1502 - } else { 1503 - tail = ""; 1504 - } 1505 - if (tail.length === 0 && !isAbsolute) { 1506 - tail = "."; 1507 - } 1508 - if ( 1509 - tail.length > 0 && 1510 - _util_ts_1.isPathSeparator(path.charCodeAt(len - 1)) 1511 - ) { 1512 - tail += "\\"; 1513 - } 1514 - if (device === undefined) { 1515 - if (isAbsolute) { 1516 - if (tail.length > 0) { 1517 - return `\\${tail}`; 1518 - } else { 1519 - return "\\"; 1520 - } 1521 - } else if (tail.length > 0) { 1522 - return tail; 1523 - } else { 1524 - return ""; 1525 - } 1526 - } else if (isAbsolute) { 1527 - if (tail.length > 0) { 1528 - return `${device}\\${tail}`; 1529 - } else { 1530 - return `${device}\\`; 1531 - } 1532 - } else if (tail.length > 0) { 1533 - return device + tail; 1534 - } else { 1535 - return device; 1536 - } 1537 - } 1538 - exports_8("normalize", normalize); 1539 - function isAbsolute(path) { 1540 - _util_ts_1.assertPath(path); 1541 - const len = path.length; 1542 - if (len === 0) { 1543 - return false; 1544 - } 1545 - const code = path.charCodeAt(0); 1546 - if (_util_ts_1.isPathSeparator(code)) { 1547 - return true; 1548 - } else if (_util_ts_1.isWindowsDeviceRoot(code)) { 1549 - // Possible device root 1550 - if (len > 2 && path.charCodeAt(1) === _constants_ts_2.CHAR_COLON) { 1551 - if (_util_ts_1.isPathSeparator(path.charCodeAt(2))) { 1552 - return true; 1553 - } 1554 - } 1555 - } 1556 - return false; 1557 - } 1558 - exports_8("isAbsolute", isAbsolute); 1559 - function join(...paths) { 1560 - const pathsCount = paths.length; 1561 - if (pathsCount === 0) { 1562 - return "."; 1563 - } 1564 - let joined; 1565 - let firstPart = null; 1566 - for (let i = 0; i < pathsCount; ++i) { 1567 - const path = paths[i]; 1568 - _util_ts_1.assertPath(path); 1569 - if (path.length > 0) { 1570 - if (joined === undefined) { 1571 - joined = firstPart = path; 1572 - } else { 1573 - joined += `\\${path}`; 1574 - } 1575 - } 1576 - } 1577 - if (joined === undefined) { 1578 - return "."; 1579 - } 1580 - // Make sure that the joined path doesn't start with two slashes, because 1581 - // normalize() will mistake it for an UNC path then. 1582 - // 1583 - // This step is skipped when it is very clear that the user actually 1584 - // intended to point at an UNC path. This is assumed when the first 1585 - // non-empty string arguments starts with exactly two slashes followed by 1586 - // at least one more non-slash character. 1587 - // 1588 - // Note that for normalize() to treat a path as an UNC path it needs to 1589 - // have at least 2 components, so we don't filter for that here. 1590 - // This means that the user can use join to construct UNC paths from 1591 - // a server name and a share name; for example: 1592 - // path.join('//server', 'share') -> '\\\\server\\share\\') 1593 - let needsReplace = true; 1594 - let slashCount = 0; 1595 - asserts_ts_1.assert(firstPart != null); 1596 - if (_util_ts_1.isPathSeparator(firstPart.charCodeAt(0))) { 1597 - ++slashCount; 1598 - const firstLen = firstPart.length; 1599 - if (firstLen > 1) { 1600 - if (_util_ts_1.isPathSeparator(firstPart.charCodeAt(1))) { 1601 - ++slashCount; 1602 - if (firstLen > 2) { 1603 - if (_util_ts_1.isPathSeparator(firstPart.charCodeAt(2))) { 1604 - ++slashCount; 1605 - } else { 1606 - // We matched a UNC path in the first part 1607 - needsReplace = false; 1608 - } 1609 - } 1610 - } 1611 - } 1612 - } 1613 - if (needsReplace) { 1614 - // Find any more consecutive slashes we need to replace 1615 - for (; slashCount < joined.length; ++slashCount) { 1616 - if (!_util_ts_1.isPathSeparator(joined.charCodeAt(slashCount))) { 1617 - break; 1618 - } 1619 - } 1620 - // Replace the slashes if needed 1621 - if (slashCount >= 2) { 1622 - joined = `\\${joined.slice(slashCount)}`; 1623 - } 1624 - } 1625 - return normalize(joined); 1626 - } 1627 - exports_8("join", join); 1628 - // It will solve the relative path from `from` to `to`, for instance: 1629 - // from = 'C:\\orandea\\test\\aaa' 1630 - // to = 'C:\\orandea\\impl\\bbb' 1631 - // The output of the function should be: '..\\..\\impl\\bbb' 1632 - function relative(from, to) { 1633 - _util_ts_1.assertPath(from); 1634 - _util_ts_1.assertPath(to); 1635 - if (from === to) { 1636 - return ""; 1637 - } 1638 - const fromOrig = resolve(from); 1639 - const toOrig = resolve(to); 1640 - if (fromOrig === toOrig) { 1641 - return ""; 1642 - } 1643 - from = fromOrig.toLowerCase(); 1644 - to = toOrig.toLowerCase(); 1645 - if (from === to) { 1646 - return ""; 1647 - } 1648 - // Trim any leading backslashes 1649 - let fromStart = 0; 1650 - let fromEnd = from.length; 1651 - for (; fromStart < fromEnd; ++fromStart) { 1652 - if ( 1653 - from.charCodeAt(fromStart) !== _constants_ts_2.CHAR_BACKWARD_SLASH 1654 - ) { 1655 - break; 1656 - } 1657 - } 1658 - // Trim trailing backslashes (applicable to UNC paths only) 1659 - for (; fromEnd - 1 > fromStart; --fromEnd) { 1660 - if ( 1661 - from.charCodeAt(fromEnd - 1) !== _constants_ts_2.CHAR_BACKWARD_SLASH 1662 - ) { 1663 - break; 1664 - } 1665 - } 1666 - const fromLen = fromEnd - fromStart; 1667 - // Trim any leading backslashes 1668 - let toStart = 0; 1669 - let toEnd = to.length; 1670 - for (; toStart < toEnd; ++toStart) { 1671 - if (to.charCodeAt(toStart) !== _constants_ts_2.CHAR_BACKWARD_SLASH) { 1672 - break; 1673 - } 1674 - } 1675 - // Trim trailing backslashes (applicable to UNC paths only) 1676 - for (; toEnd - 1 > toStart; --toEnd) { 1677 - if (to.charCodeAt(toEnd - 1) !== _constants_ts_2.CHAR_BACKWARD_SLASH) { 1678 - break; 1679 - } 1680 - } 1681 - const toLen = toEnd - toStart; 1682 - // Compare paths to find the longest common path from root 1683 - const length = fromLen < toLen ? fromLen : toLen; 1684 - let lastCommonSep = -1; 1685 - let i = 0; 1686 - for (; i <= length; ++i) { 1687 - if (i === length) { 1688 - if (toLen > length) { 1689 - if ( 1690 - to.charCodeAt(toStart + i) === _constants_ts_2.CHAR_BACKWARD_SLASH 1691 - ) { 1692 - // We get here if `from` is the exact base path for `to`. 1693 - // For example: from='C:\\foo\\bar'; to='C:\\foo\\bar\\baz' 1694 - return toOrig.slice(toStart + i + 1); 1695 - } else if (i === 2) { 1696 - // We get here if `from` is the device root. 1697 - // For example: from='C:\\'; to='C:\\foo' 1698 - return toOrig.slice(toStart + i); 1699 - } 1700 - } 1701 - if (fromLen > length) { 1702 - if ( 1703 - from.charCodeAt(fromStart + i) === 1704 - _constants_ts_2.CHAR_BACKWARD_SLASH 1705 - ) { 1706 - // We get here if `to` is the exact base path for `from`. 1707 - // For example: from='C:\\foo\\bar'; to='C:\\foo' 1708 - lastCommonSep = i; 1709 - } else if (i === 2) { 1710 - // We get here if `to` is the device root. 1711 - // For example: from='C:\\foo\\bar'; to='C:\\' 1712 - lastCommonSep = 3; 1713 - } 1714 - } 1715 - break; 1716 - } 1717 - const fromCode = from.charCodeAt(fromStart + i); 1718 - const toCode = to.charCodeAt(toStart + i); 1719 - if (fromCode !== toCode) { 1720 - break; 1721 - } else if (fromCode === _constants_ts_2.CHAR_BACKWARD_SLASH) { 1722 - lastCommonSep = i; 1723 - } 1724 - } 1725 - // We found a mismatch before the first common path separator was seen, so 1726 - // return the original `to`. 1727 - if (i !== length && lastCommonSep === -1) { 1728 - return toOrig; 1729 - } 1730 - let out = ""; 1731 - if (lastCommonSep === -1) { 1732 - lastCommonSep = 0; 1733 - } 1734 - // Generate the relative path based on the path difference between `to` and 1735 - // `from` 1736 - for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) { 1737 - if ( 1738 - i === fromEnd || 1739 - from.charCodeAt(i) === _constants_ts_2.CHAR_BACKWARD_SLASH 1740 - ) { 1741 - if (out.length === 0) { 1742 - out += ".."; 1743 - } else { 1744 - out += "\\.."; 1745 - } 1746 - } 1747 - } 1748 - // Lastly, append the rest of the destination (`to`) path that comes after 1749 - // the common path parts 1750 - if (out.length > 0) { 1751 - return out + toOrig.slice(toStart + lastCommonSep, toEnd); 1752 - } else { 1753 - toStart += lastCommonSep; 1754 - if ( 1755 - toOrig.charCodeAt(toStart) === _constants_ts_2.CHAR_BACKWARD_SLASH 1756 - ) { 1757 - ++toStart; 1758 - } 1759 - return toOrig.slice(toStart, toEnd); 1760 - } 1761 - } 1762 - exports_8("relative", relative); 1763 - function toNamespacedPath(path) { 1764 - // Note: this will *probably* throw somewhere. 1765 - if (typeof path !== "string") { 1766 - return path; 1767 - } 1768 - if (path.length === 0) { 1769 - return ""; 1770 - } 1771 - const resolvedPath = resolve(path); 1772 - if (resolvedPath.length >= 3) { 1773 - if ( 1774 - resolvedPath.charCodeAt(0) === _constants_ts_2.CHAR_BACKWARD_SLASH 1775 - ) { 1776 - // Possible UNC root 1777 - if ( 1778 - resolvedPath.charCodeAt(1) === _constants_ts_2.CHAR_BACKWARD_SLASH 1779 - ) { 1780 - const code = resolvedPath.charCodeAt(2); 1781 - if ( 1782 - code !== _constants_ts_2.CHAR_QUESTION_MARK && 1783 - code !== _constants_ts_2.CHAR_DOT 1784 - ) { 1785 - // Matched non-long UNC root, convert the path to a long UNC path 1786 - return `\\\\?\\UNC\\${resolvedPath.slice(2)}`; 1787 - } 1788 - } 1789 - } else if (_util_ts_1.isWindowsDeviceRoot(resolvedPath.charCodeAt(0))) { 1790 - // Possible device root 1791 - if ( 1792 - resolvedPath.charCodeAt(1) === _constants_ts_2.CHAR_COLON && 1793 - resolvedPath.charCodeAt(2) === _constants_ts_2.CHAR_BACKWARD_SLASH 1794 - ) { 1795 - // Matched device root, convert the path to a long UNC path 1796 - return `\\\\?\\${resolvedPath}`; 1797 - } 1798 - } 1799 - } 1800 - return path; 1801 - } 1802 - exports_8("toNamespacedPath", toNamespacedPath); 1803 - function dirname(path) { 1804 - _util_ts_1.assertPath(path); 1805 - const len = path.length; 1806 - if (len === 0) { 1807 - return "."; 1808 - } 1809 - let rootEnd = -1; 1810 - let end = -1; 1811 - let matchedSlash = true; 1812 - let offset = 0; 1813 - const code = path.charCodeAt(0); 1814 - // Try to match a root 1815 - if (len > 1) { 1816 - if (_util_ts_1.isPathSeparator(code)) { 1817 - // Possible UNC root 1818 - rootEnd = offset = 1; 1819 - if (_util_ts_1.isPathSeparator(path.charCodeAt(1))) { 1820 - // Matched double path separator at beginning 1821 - let j = 2; 1822 - let last = j; 1823 - // Match 1 or more non-path separators 1824 - for (; j < len; ++j) { 1825 - if (_util_ts_1.isPathSeparator(path.charCodeAt(j))) { 1826 - break; 1827 - } 1828 - } 1829 - if (j < len && j !== last) { 1830 - // Matched! 1831 - last = j; 1832 - // Match 1 or more path separators 1833 - for (; j < len; ++j) { 1834 - if (!_util_ts_1.isPathSeparator(path.charCodeAt(j))) { 1835 - break; 1836 - } 1837 - } 1838 - if (j < len && j !== last) { 1839 - // Matched! 1840 - last = j; 1841 - // Match 1 or more non-path separators 1842 - for (; j < len; ++j) { 1843 - if (_util_ts_1.isPathSeparator(path.charCodeAt(j))) { 1844 - break; 1845 - } 1846 - } 1847 - if (j === len) { 1848 - // We matched a UNC root only 1849 - return path; 1850 - } 1851 - if (j !== last) { 1852 - // We matched a UNC root with leftovers 1853 - // Offset by 1 to include the separator after the UNC root to 1854 - // treat it as a "normal root" on top of a (UNC) root 1855 - rootEnd = offset = j + 1; 1856 - } 1857 - } 1858 - } 1859 - } 1860 - } else if (_util_ts_1.isWindowsDeviceRoot(code)) { 1861 - // Possible device root 1862 - if (path.charCodeAt(1) === _constants_ts_2.CHAR_COLON) { 1863 - rootEnd = offset = 2; 1864 - if (len > 2) { 1865 - if (_util_ts_1.isPathSeparator(path.charCodeAt(2))) { 1866 - rootEnd = offset = 3; 1867 - } 1868 - } 1869 - } 1870 - } 1871 - } else if (_util_ts_1.isPathSeparator(code)) { 1872 - // `path` contains just a path separator, exit early to avoid 1873 - // unnecessary work 1874 - return path; 1875 - } 1876 - for (let i = len - 1; i >= offset; --i) { 1877 - if (_util_ts_1.isPathSeparator(path.charCodeAt(i))) { 1878 - if (!matchedSlash) { 1879 - end = i; 1880 - break; 1881 - } 1882 - } else { 1883 - // We saw the first non-path separator 1884 - matchedSlash = false; 1885 - } 1886 - } 1887 - if (end === -1) { 1888 - if (rootEnd === -1) { 1889 - return "."; 1890 - } else { 1891 - end = rootEnd; 1892 - } 1893 - } 1894 - return path.slice(0, end); 1895 - } 1896 - exports_8("dirname", dirname); 1897 - function basename(path, ext = "") { 1898 - if (ext !== undefined && typeof ext !== "string") { 1899 - throw new TypeError('"ext" argument must be a string'); 1900 - } 1901 - _util_ts_1.assertPath(path); 1902 - let start = 0; 1903 - let end = -1; 1904 - let matchedSlash = true; 1905 - let i; 1906 - // Check for a drive letter prefix so as not to mistake the following 1907 - // path separator as an extra separator at the end of the path that can be 1908 - // disregarded 1909 - if (path.length >= 2) { 1910 - const drive = path.charCodeAt(0); 1911 - if (_util_ts_1.isWindowsDeviceRoot(drive)) { 1912 - if (path.charCodeAt(1) === _constants_ts_2.CHAR_COLON) { 1913 - start = 2; 1914 - } 1915 - } 1916 - } 1917 - if (ext !== undefined && ext.length > 0 && ext.length <= path.length) { 1918 - if (ext.length === path.length && ext === path) { 1919 - return ""; 1920 - } 1921 - let extIdx = ext.length - 1; 1922 - let firstNonSlashEnd = -1; 1923 - for (i = path.length - 1; i >= start; --i) { 1924 - const code = path.charCodeAt(i); 1925 - if (_util_ts_1.isPathSeparator(code)) { 1926 - // If we reached a path separator that was not part of a set of path 1927 - // separators at the end of the string, stop now 1928 - if (!matchedSlash) { 1929 - start = i + 1; 1930 - break; 1931 - } 1932 - } else { 1933 - if (firstNonSlashEnd === -1) { 1934 - // We saw the first non-path separator, remember this index in case 1935 - // we need it if the extension ends up not matching 1936 - matchedSlash = false; 1937 - firstNonSlashEnd = i + 1; 1938 - } 1939 - if (extIdx >= 0) { 1940 - // Try to match the explicit extension 1941 - if (code === ext.charCodeAt(extIdx)) { 1942 - if (--extIdx === -1) { 1943 - // We matched the extension, so mark this as the end of our path 1944 - // component 1945 - end = i; 1946 - } 1947 - } else { 1948 - // Extension does not match, so our result is the entire path 1949 - // component 1950 - extIdx = -1; 1951 - end = firstNonSlashEnd; 1952 - } 1953 - } 1954 - } 1955 - } 1956 - if (start === end) { 1957 - end = firstNonSlashEnd; 1958 - } else if (end === -1) { 1959 - end = path.length; 1960 - } 1961 - return path.slice(start, end); 1962 - } else { 1963 - for (i = path.length - 1; i >= start; --i) { 1964 - if (_util_ts_1.isPathSeparator(path.charCodeAt(i))) { 1965 - // If we reached a path separator that was not part of a set of path 1966 - // separators at the end of the string, stop now 1967 - if (!matchedSlash) { 1968 - start = i + 1; 1969 - break; 1970 - } 1971 - } else if (end === -1) { 1972 - // We saw the first non-path separator, mark this as the end of our 1973 - // path component 1974 - matchedSlash = false; 1975 - end = i + 1; 1976 - } 1977 - } 1978 - if (end === -1) { 1979 - return ""; 1980 - } 1981 - return path.slice(start, end); 1982 - } 1983 - } 1984 - exports_8("basename", basename); 1985 - function extname(path) { 1986 - _util_ts_1.assertPath(path); 1987 - let start = 0; 1988 - let startDot = -1; 1989 - let startPart = 0; 1990 - let end = -1; 1991 - let matchedSlash = true; 1992 - // Track the state of characters (if any) we see before our first dot and 1993 - // after any path separator we find 1994 - let preDotState = 0; 1995 - // Check for a drive letter prefix so as not to mistake the following 1996 - // path separator as an extra separator at the end of the path that can be 1997 - // disregarded 1998 - if ( 1999 - path.length >= 2 && 2000 - path.charCodeAt(1) === _constants_ts_2.CHAR_COLON && 2001 - _util_ts_1.isWindowsDeviceRoot(path.charCodeAt(0)) 2002 - ) { 2003 - start = startPart = 2; 2004 - } 2005 - for (let i = path.length - 1; i >= start; --i) { 2006 - const code = path.charCodeAt(i); 2007 - if (_util_ts_1.isPathSeparator(code)) { 2008 - // If we reached a path separator that was not part of a set of path 2009 - // separators at the end of the string, stop now 2010 - if (!matchedSlash) { 2011 - startPart = i + 1; 2012 - break; 2013 - } 2014 - continue; 2015 - } 2016 - if (end === -1) { 2017 - // We saw the first non-path separator, mark this as the end of our 2018 - // extension 2019 - matchedSlash = false; 2020 - end = i + 1; 2021 - } 2022 - if (code === _constants_ts_2.CHAR_DOT) { 2023 - // If this is our first dot, mark it as the start of our extension 2024 - if (startDot === -1) { 2025 - startDot = i; 2026 - } else if (preDotState !== 1) { 2027 - preDotState = 1; 2028 - } 2029 - } else if (startDot !== -1) { 2030 - // We saw a non-dot and non-path separator before our dot, so we should 2031 - // have a good chance at having a non-empty extension 2032 - preDotState = -1; 2033 - } 2034 - } 2035 - if ( 2036 - startDot === -1 || 2037 - end === -1 || 2038 - // We saw a non-dot character immediately before the dot 2039 - preDotState === 0 || 2040 - // The (right-most) trimmed path component is exactly '..' 2041 - (preDotState === 1 && startDot === end - 1 && 2042 - startDot === startPart + 1) 2043 - ) { 2044 - return ""; 2045 - } 2046 - return path.slice(startDot, end); 2047 - } 2048 - exports_8("extname", extname); 2049 - function format(pathObject) { 2050 - /* eslint-disable max-len */ 2051 - if (pathObject === null || typeof pathObject !== "object") { 2052 - throw new TypeError( 2053 - `The "pathObject" argument must be of type Object. Received type ${typeof pathObject}`, 2054 - ); 2055 - } 2056 - return _util_ts_1._format("\\", pathObject); 2057 - } 2058 - exports_8("format", format); 2059 - function parse(path) { 2060 - _util_ts_1.assertPath(path); 2061 - const ret = { root: "", dir: "", base: "", ext: "", name: "" }; 2062 - const len = path.length; 2063 - if (len === 0) { 2064 - return ret; 2065 - } 2066 - let rootEnd = 0; 2067 - let code = path.charCodeAt(0); 2068 - // Try to match a root 2069 - if (len > 1) { 2070 - if (_util_ts_1.isPathSeparator(code)) { 2071 - // Possible UNC root 2072 - rootEnd = 1; 2073 - if (_util_ts_1.isPathSeparator(path.charCodeAt(1))) { 2074 - // Matched double path separator at beginning 2075 - let j = 2; 2076 - let last = j; 2077 - // Match 1 or more non-path separators 2078 - for (; j < len; ++j) { 2079 - if (_util_ts_1.isPathSeparator(path.charCodeAt(j))) { 2080 - break; 2081 - } 2082 - } 2083 - if (j < len && j !== last) { 2084 - // Matched! 2085 - last = j; 2086 - // Match 1 or more path separators 2087 - for (; j < len; ++j) { 2088 - if (!_util_ts_1.isPathSeparator(path.charCodeAt(j))) { 2089 - break; 2090 - } 2091 - } 2092 - if (j < len && j !== last) { 2093 - // Matched! 2094 - last = j; 2095 - // Match 1 or more non-path separators 2096 - for (; j < len; ++j) { 2097 - if (_util_ts_1.isPathSeparator(path.charCodeAt(j))) { 2098 - break; 2099 - } 2100 - } 2101 - if (j === len) { 2102 - // We matched a UNC root only 2103 - rootEnd = j; 2104 - } else if (j !== last) { 2105 - // We matched a UNC root with leftovers 2106 - rootEnd = j + 1; 2107 - } 2108 - } 2109 - } 2110 - } 2111 - } else if (_util_ts_1.isWindowsDeviceRoot(code)) { 2112 - // Possible device root 2113 - if (path.charCodeAt(1) === _constants_ts_2.CHAR_COLON) { 2114 - rootEnd = 2; 2115 - if (len > 2) { 2116 - if (_util_ts_1.isPathSeparator(path.charCodeAt(2))) { 2117 - if (len === 3) { 2118 - // `path` contains just a drive root, exit early to avoid 2119 - // unnecessary work 2120 - ret.root = ret.dir = path; 2121 - return ret; 2122 - } 2123 - rootEnd = 3; 2124 - } 2125 - } else { 2126 - // `path` contains just a drive root, exit early to avoid 2127 - // unnecessary work 2128 - ret.root = ret.dir = path; 2129 - return ret; 2130 - } 2131 - } 2132 - } 2133 - } else if (_util_ts_1.isPathSeparator(code)) { 2134 - // `path` contains just a path separator, exit early to avoid 2135 - // unnecessary work 2136 - ret.root = ret.dir = path; 2137 - return ret; 2138 - } 2139 - if (rootEnd > 0) { 2140 - ret.root = path.slice(0, rootEnd); 2141 - } 2142 - let startDot = -1; 2143 - let startPart = rootEnd; 2144 - let end = -1; 2145 - let matchedSlash = true; 2146 - let i = path.length - 1; 2147 - // Track the state of characters (if any) we see before our first dot and 2148 - // after any path separator we find 2149 - let preDotState = 0; 2150 - // Get non-dir info 2151 - for (; i >= rootEnd; --i) { 2152 - code = path.charCodeAt(i); 2153 - if (_util_ts_1.isPathSeparator(code)) { 2154 - // If we reached a path separator that was not part of a set of path 2155 - // separators at the end of the string, stop now 2156 - if (!matchedSlash) { 2157 - startPart = i + 1; 2158 - break; 2159 - } 2160 - continue; 2161 - } 2162 - if (end === -1) { 2163 - // We saw the first non-path separator, mark this as the end of our 2164 - // extension 2165 - matchedSlash = false; 2166 - end = i + 1; 2167 - } 2168 - if (code === _constants_ts_2.CHAR_DOT) { 2169 - // If this is our first dot, mark it as the start of our extension 2170 - if (startDot === -1) { 2171 - startDot = i; 2172 - } else if (preDotState !== 1) { 2173 - preDotState = 1; 2174 - } 2175 - } else if (startDot !== -1) { 2176 - // We saw a non-dot and non-path separator before our dot, so we should 2177 - // have a good chance at having a non-empty extension 2178 - preDotState = -1; 2179 - } 2180 - } 2181 - if ( 2182 - startDot === -1 || 2183 - end === -1 || 2184 - // We saw a non-dot character immediately before the dot 2185 - preDotState === 0 || 2186 - // The (right-most) trimmed path component is exactly '..' 2187 - (preDotState === 1 && startDot === end - 1 && 2188 - startDot === startPart + 1) 2189 - ) { 2190 - if (end !== -1) { 2191 - ret.base = ret.name = path.slice(startPart, end); 2192 - } 2193 - } else { 2194 - ret.name = path.slice(startPart, startDot); 2195 - ret.base = path.slice(startPart, end); 2196 - ret.ext = path.slice(startDot, end); 2197 - } 2198 - // If the directory is the root, use the entire root as the `dir` including 2199 - // the trailing slash if any (`C:\abc` -> `C:\`). Otherwise, strip out the 2200 - // trailing slash (`C:\abc\def` -> `C:\abc`). 2201 - if (startPart > 0 && startPart !== rootEnd) { 2202 - ret.dir = path.slice(0, startPart - 1); 2203 - } else { 2204 - ret.dir = ret.root; 2205 - } 2206 - return ret; 2207 - } 2208 - exports_8("parse", parse); 2209 - /** Converts a file URL to a path string. 2210 - * 2211 - * fromFileUrl("file:///C:/Users/foo"); // "C:\\Users\\foo" 2212 - * fromFileUrl("file:///home/foo"); // "\\home\\foo" 2213 - * 2214 - * Note that non-file URLs are treated as file URLs and irrelevant components 2215 - * are ignored. 2216 - */ 2217 - function fromFileUrl(url) { 2218 - return new URL(url).pathname 2219 - .replace(/^\/*([A-Za-z]:)(\/|$)/, "$1/") 2220 - .replace(/\//g, "\\"); 2221 - } 2222 - exports_8("fromFileUrl", fromFileUrl); 2223 - return { 2224 - setters: [ 2225 - function (_constants_ts_2_1) { 2226 - _constants_ts_2 = _constants_ts_2_1; 2227 - }, 2228 - function (_util_ts_1_1) { 2229 - _util_ts_1 = _util_ts_1_1; 2230 - }, 2231 - function (asserts_ts_1_1) { 2232 - asserts_ts_1 = asserts_ts_1_1; 2233 - }, 2234 - ], 2235 - execute: function () { 2236 - exports_8("sep", sep = "\\"); 2237 - exports_8("delimiter", delimiter = ";"); 2238 - }, 2239 - }; 2240 - }, 2241 - ); 2242 - // Copyright the Browserify authors. MIT License. 2243 - // Ported from https://github.com/browserify/path-browserify/ 2244 - /** This module is browser compatible. */ 2245 - System.register( 2246 - "https://deno.land/std@0.56.0/path/posix", 2247 - [ 2248 - "https://deno.land/std@0.56.0/path/_constants", 2249 - "https://deno.land/std@0.56.0/path/_util", 2250 - ], 2251 - function (exports_9, context_9) { 2252 - "use strict"; 2253 - var _constants_ts_3, _util_ts_2, sep, delimiter; 2254 - var __moduleName = context_9 && context_9.id; 2255 - // path.resolve([from ...], to) 2256 - function resolve(...pathSegments) { 2257 - let resolvedPath = ""; 2258 - let resolvedAbsolute = false; 2259 - for (let i = pathSegments.length - 1; i >= -1 && !resolvedAbsolute; i--) { 2260 - let path; 2261 - if (i >= 0) { 2262 - path = pathSegments[i]; 2263 - } else { 2264 - if (globalThis.Deno == null) { 2265 - throw new TypeError("Resolved a relative path without a CWD."); 2266 - } 2267 - path = Deno.cwd(); 2268 - } 2269 - _util_ts_2.assertPath(path); 2270 - // Skip empty entries 2271 - if (path.length === 0) { 2272 - continue; 2273 - } 2274 - resolvedPath = `${path}/${resolvedPath}`; 2275 - resolvedAbsolute = 2276 - path.charCodeAt(0) === _constants_ts_3.CHAR_FORWARD_SLASH; 2277 - } 2278 - // At this point the path should be resolved to a full absolute path, but 2279 - // handle relative paths to be safe (might happen when process.cwd() fails) 2280 - // Normalize the path 2281 - resolvedPath = _util_ts_2.normalizeString( 2282 - resolvedPath, 2283 - !resolvedAbsolute, 2284 - "/", 2285 - _util_ts_2.isPosixPathSeparator, 2286 - ); 2287 - if (resolvedAbsolute) { 2288 - if (resolvedPath.length > 0) { 2289 - return `/${resolvedPath}`; 2290 - } else { 2291 - return "/"; 2292 - } 2293 - } else if (resolvedPath.length > 0) { 2294 - return resolvedPath; 2295 - } else { 2296 - return "."; 2297 - } 2298 - } 2299 - exports_9("resolve", resolve); 2300 - function normalize(path) { 2301 - _util_ts_2.assertPath(path); 2302 - if (path.length === 0) { 2303 - return "."; 2304 - } 2305 - const isAbsolute = 2306 - path.charCodeAt(0) === _constants_ts_3.CHAR_FORWARD_SLASH; 2307 - const trailingSeparator = 2308 - path.charCodeAt(path.length - 1) === _constants_ts_3.CHAR_FORWARD_SLASH; 2309 - // Normalize the path 2310 - path = _util_ts_2.normalizeString( 2311 - path, 2312 - !isAbsolute, 2313 - "/", 2314 - _util_ts_2.isPosixPathSeparator, 2315 - ); 2316 - if (path.length === 0 && !isAbsolute) { 2317 - path = "."; 2318 - } 2319 - if (path.length > 0 && trailingSeparator) { 2320 - path += "/"; 2321 - } 2322 - if (isAbsolute) { 2323 - return `/${path}`; 2324 - } 2325 - return path; 2326 - } 2327 - exports_9("normalize", normalize); 2328 - function isAbsolute(path) { 2329 - _util_ts_2.assertPath(path); 2330 - return path.length > 0 && 2331 - path.charCodeAt(0) === _constants_ts_3.CHAR_FORWARD_SLASH; 2332 - } 2333 - exports_9("isAbsolute", isAbsolute); 2334 - function join(...paths) { 2335 - if (paths.length === 0) { 2336 - return "."; 2337 - } 2338 - let joined; 2339 - for (let i = 0, len = paths.length; i < len; ++i) { 2340 - const path = paths[i]; 2341 - _util_ts_2.assertPath(path); 2342 - if (path.length > 0) { 2343 - if (!joined) { 2344 - joined = path; 2345 - } else { 2346 - joined += `/${path}`; 2347 - } 2348 - } 2349 - } 2350 - if (!joined) { 2351 - return "."; 2352 - } 2353 - return normalize(joined); 2354 - } 2355 - exports_9("join", join); 2356 - function relative(from, to) { 2357 - _util_ts_2.assertPath(from); 2358 - _util_ts_2.assertPath(to); 2359 - if (from === to) { 2360 - return ""; 2361 - } 2362 - from = resolve(from); 2363 - to = resolve(to); 2364 - if (from === to) { 2365 - return ""; 2366 - } 2367 - // Trim any leading backslashes 2368 - let fromStart = 1; 2369 - const fromEnd = from.length; 2370 - for (; fromStart < fromEnd; ++fromStart) { 2371 - if (from.charCodeAt(fromStart) !== _constants_ts_3.CHAR_FORWARD_SLASH) { 2372 - break; 2373 - } 2374 - } 2375 - const fromLen = fromEnd - fromStart; 2376 - // Trim any leading backslashes 2377 - let toStart = 1; 2378 - const toEnd = to.length; 2379 - for (; toStart < toEnd; ++toStart) { 2380 - if (to.charCodeAt(toStart) !== _constants_ts_3.CHAR_FORWARD_SLASH) { 2381 - break; 2382 - } 2383 - } 2384 - const toLen = toEnd - toStart; 2385 - // Compare paths to find the longest common path from root 2386 - const length = fromLen < toLen ? fromLen : toLen; 2387 - let lastCommonSep = -1; 2388 - let i = 0; 2389 - for (; i <= length; ++i) { 2390 - if (i === length) { 2391 - if (toLen > length) { 2392 - if ( 2393 - to.charCodeAt(toStart + i) === _constants_ts_3.CHAR_FORWARD_SLASH 2394 - ) { 2395 - // We get here if `from` is the exact base path for `to`. 2396 - // For example: from='/foo/bar'; to='/foo/bar/baz' 2397 - return to.slice(toStart + i + 1); 2398 - } else if (i === 0) { 2399 - // We get here if `from` is the root 2400 - // For example: from='/'; to='/foo' 2401 - return to.slice(toStart + i); 2402 - } 2403 - } else if (fromLen > length) { 2404 - if ( 2405 - from.charCodeAt(fromStart + i) === 2406 - _constants_ts_3.CHAR_FORWARD_SLASH 2407 - ) { 2408 - // We get here if `to` is the exact base path for `from`. 2409 - // For example: from='/foo/bar/baz'; to='/foo/bar' 2410 - lastCommonSep = i; 2411 - } else if (i === 0) { 2412 - // We get here if `to` is the root. 2413 - // For example: from='/foo'; to='/' 2414 - lastCommonSep = 0; 2415 - } 2416 - } 2417 - break; 2418 - } 2419 - const fromCode = from.charCodeAt(fromStart + i); 2420 - const toCode = to.charCodeAt(toStart + i); 2421 - if (fromCode !== toCode) { 2422 - break; 2423 - } else if (fromCode === _constants_ts_3.CHAR_FORWARD_SLASH) { 2424 - lastCommonSep = i; 2425 - } 2426 - } 2427 - let out = ""; 2428 - // Generate the relative path based on the path difference between `to` 2429 - // and `from` 2430 - for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) { 2431 - if ( 2432 - i === fromEnd || 2433 - from.charCodeAt(i) === _constants_ts_3.CHAR_FORWARD_SLASH 2434 - ) { 2435 - if (out.length === 0) { 2436 - out += ".."; 2437 - } else { 2438 - out += "/.."; 2439 - } 2440 - } 2441 - } 2442 - // Lastly, append the rest of the destination (`to`) path that comes after 2443 - // the common path parts 2444 - if (out.length > 0) { 2445 - return out + to.slice(toStart + lastCommonSep); 2446 - } else { 2447 - toStart += lastCommonSep; 2448 - if (to.charCodeAt(toStart) === _constants_ts_3.CHAR_FORWARD_SLASH) { 2449 - ++toStart; 2450 - } 2451 - return to.slice(toStart); 2452 - } 2453 - } 2454 - exports_9("relative", relative); 2455 - function toNamespacedPath(path) { 2456 - // Non-op on posix systems 2457 - return path; 2458 - } 2459 - exports_9("toNamespacedPath", toNamespacedPath); 2460 - function dirname(path) { 2461 - _util_ts_2.assertPath(path); 2462 - if (path.length === 0) { 2463 - return "."; 2464 - } 2465 - const hasRoot = path.charCodeAt(0) === _constants_ts_3.CHAR_FORWARD_SLASH; 2466 - let end = -1; 2467 - let matchedSlash = true; 2468 - for (let i = path.length - 1; i >= 1; --i) { 2469 - if (path.charCodeAt(i) === _constants_ts_3.CHAR_FORWARD_SLASH) { 2470 - if (!matchedSlash) { 2471 - end = i; 2472 - break; 2473 - } 2474 - } else { 2475 - // We saw the first non-path separator 2476 - matchedSlash = false; 2477 - } 2478 - } 2479 - if (end === -1) { 2480 - return hasRoot ? "/" : "."; 2481 - } 2482 - if (hasRoot && end === 1) { 2483 - return "//"; 2484 - } 2485 - return path.slice(0, end); 2486 - } 2487 - exports_9("dirname", dirname); 2488 - function basename(path, ext = "") { 2489 - if (ext !== undefined && typeof ext !== "string") { 2490 - throw new TypeError('"ext" argument must be a string'); 2491 - } 2492 - _util_ts_2.assertPath(path); 2493 - let start = 0; 2494 - let end = -1; 2495 - let matchedSlash = true; 2496 - let i; 2497 - if (ext !== undefined && ext.length > 0 && ext.length <= path.length) { 2498 - if (ext.length === path.length && ext === path) { 2499 - return ""; 2500 - } 2501 - let extIdx = ext.length - 1; 2502 - let firstNonSlashEnd = -1; 2503 - for (i = path.length - 1; i >= 0; --i) { 2504 - const code = path.charCodeAt(i); 2505 - if (code === _constants_ts_3.CHAR_FORWARD_SLASH) { 2506 - // If we reached a path separator that was not part of a set of path 2507 - // separators at the end of the string, stop now 2508 - if (!matchedSlash) { 2509 - start = i + 1; 2510 - break; 2511 - } 2512 - } else { 2513 - if (firstNonSlashEnd === -1) { 2514 - // We saw the first non-path separator, remember this index in case 2515 - // we need it if the extension ends up not matching 2516 - matchedSlash = false; 2517 - firstNonSlashEnd = i + 1; 2518 - } 2519 - if (extIdx >= 0) { 2520 - // Try to match the explicit extension 2521 - if (code === ext.charCodeAt(extIdx)) { 2522 - if (--extIdx === -1) { 2523 - // We matched the extension, so mark this as the end of our path 2524 - // component 2525 - end = i; 2526 - } 2527 - } else { 2528 - // Extension does not match, so our result is the entire path 2529 - // component 2530 - extIdx = -1; 2531 - end = firstNonSlashEnd; 2532 - } 2533 - } 2534 - } 2535 - } 2536 - if (start === end) { 2537 - end = firstNonSlashEnd; 2538 - } else if (end === -1) { 2539 - end = path.length; 2540 - } 2541 - return path.slice(start, end); 2542 - } else { 2543 - for (i = path.length - 1; i >= 0; --i) { 2544 - if (path.charCodeAt(i) === _constants_ts_3.CHAR_FORWARD_SLASH) { 2545 - // If we reached a path separator that was not part of a set of path 2546 - // separators at the end of the string, stop now 2547 - if (!matchedSlash) { 2548 - start = i + 1; 2549 - break; 2550 - } 2551 - } else if (end === -1) { 2552 - // We saw the first non-path separator, mark this as the end of our 2553 - // path component 2554 - matchedSlash = false; 2555 - end = i + 1; 2556 - } 2557 - } 2558 - if (end === -1) { 2559 - return ""; 2560 - } 2561 - return path.slice(start, end); 2562 - } 2563 - } 2564 - exports_9("basename", basename); 2565 - function extname(path) { 2566 - _util_ts_2.assertPath(path); 2567 - let startDot = -1; 2568 - let startPart = 0; 2569 - let end = -1; 2570 - let matchedSlash = true; 2571 - // Track the state of characters (if any) we see before our first dot and 2572 - // after any path separator we find 2573 - let preDotState = 0; 2574 - for (let i = path.length - 1; i >= 0; --i) { 2575 - const code = path.charCodeAt(i); 2576 - if (code === _constants_ts_3.CHAR_FORWARD_SLASH) { 2577 - // If we reached a path separator that was not part of a set of path 2578 - // separators at the end of the string, stop now 2579 - if (!matchedSlash) { 2580 - startPart = i + 1; 2581 - break; 2582 - } 2583 - continue; 2584 - } 2585 - if (end === -1) { 2586 - // We saw the first non-path separator, mark this as the end of our 2587 - // extension 2588 - matchedSlash = false; 2589 - end = i + 1; 2590 - } 2591 - if (code === _constants_ts_3.CHAR_DOT) { 2592 - // If this is our first dot, mark it as the start of our extension 2593 - if (startDot === -1) { 2594 - startDot = i; 2595 - } else if (preDotState !== 1) { 2596 - preDotState = 1; 2597 - } 2598 - } else if (startDot !== -1) { 2599 - // We saw a non-dot and non-path separator before our dot, so we should 2600 - // have a good chance at having a non-empty extension 2601 - preDotState = -1; 2602 - } 2603 - } 2604 - if ( 2605 - startDot === -1 || 2606 - end === -1 || 2607 - // We saw a non-dot character immediately before the dot 2608 - preDotState === 0 || 2609 - // The (right-most) trimmed path component is exactly '..' 2610 - (preDotState === 1 && startDot === end - 1 && 2611 - startDot === startPart + 1) 2612 - ) { 2613 - return ""; 2614 - } 2615 - return path.slice(startDot, end); 2616 - } 2617 - exports_9("extname", extname); 2618 - function format(pathObject) { 2619 - /* eslint-disable max-len */ 2620 - if (pathObject === null || typeof pathObject !== "object") { 2621 - throw new TypeError( 2622 - `The "pathObject" argument must be of type Object. Received type ${typeof pathObject}`, 2623 - ); 2624 - } 2625 - return _util_ts_2._format("/", pathObject); 2626 - } 2627 - exports_9("format", format); 2628 - function parse(path) { 2629 - _util_ts_2.assertPath(path); 2630 - const ret = { root: "", dir: "", base: "", ext: "", name: "" }; 2631 - if (path.length === 0) { 2632 - return ret; 2633 - } 2634 - const isAbsolute = 2635 - path.charCodeAt(0) === _constants_ts_3.CHAR_FORWARD_SLASH; 2636 - let start; 2637 - if (isAbsolute) { 2638 - ret.root = "/"; 2639 - start = 1; 2640 - } else { 2641 - start = 0; 2642 - } 2643 - let startDot = -1; 2644 - let startPart = 0; 2645 - let end = -1; 2646 - let matchedSlash = true; 2647 - let i = path.length - 1; 2648 - // Track the state of characters (if any) we see before our first dot and 2649 - // after any path separator we find 2650 - let preDotState = 0; 2651 - // Get non-dir info 2652 - for (; i >= start; --i) { 2653 - const code = path.charCodeAt(i); 2654 - if (code === _constants_ts_3.CHAR_FORWARD_SLASH) { 2655 - // If we reached a path separator that was not part of a set of path 2656 - // separators at the end of the string, stop now 2657 - if (!matchedSlash) { 2658 - startPart = i + 1; 2659 - break; 2660 - } 2661 - continue; 2662 - } 2663 - if (end === -1) { 2664 - // We saw the first non-path separator, mark this as the end of our 2665 - // extension 2666 - matchedSlash = false; 2667 - end = i + 1; 2668 - } 2669 - if (code === _constants_ts_3.CHAR_DOT) { 2670 - // If this is our first dot, mark it as the start of our extension 2671 - if (startDot === -1) { 2672 - startDot = i; 2673 - } else if (preDotState !== 1) { 2674 - preDotState = 1; 2675 - } 2676 - } else if (startDot !== -1) { 2677 - // We saw a non-dot and non-path separator before our dot, so we should 2678 - // have a good chance at having a non-empty extension 2679 - preDotState = -1; 2680 - } 2681 - } 2682 - if ( 2683 - startDot === -1 || 2684 - end === -1 || 2685 - // We saw a non-dot character immediately before the dot 2686 - preDotState === 0 || 2687 - // The (right-most) trimmed path component is exactly '..' 2688 - (preDotState === 1 && startDot === end - 1 && 2689 - startDot === startPart + 1) 2690 - ) { 2691 - if (end !== -1) { 2692 - if (startPart === 0 && isAbsolute) { 2693 - ret.base = ret.name = path.slice(1, end); 2694 - } else { 2695 - ret.base = ret.name = path.slice(startPart, end); 2696 - } 2697 - } 2698 - } else { 2699 - if (startPart === 0 && isAbsolute) { 2700 - ret.name = path.slice(1, startDot); 2701 - ret.base = path.slice(1, end); 2702 - } else { 2703 - ret.name = path.slice(startPart, startDot); 2704 - ret.base = path.slice(startPart, end); 2705 - } 2706 - ret.ext = path.slice(startDot, end); 2707 - } 2708 - if (startPart > 0) { 2709 - ret.dir = path.slice(0, startPart - 1); 2710 - } else if (isAbsolute) { 2711 - ret.dir = "/"; 2712 - } 2713 - return ret; 2714 - } 2715 - exports_9("parse", parse); 2716 - /** Converts a file URL to a path string. 2717 - * 2718 - * fromFileUrl("file:///home/foo"); // "/home/foo" 2719 - * 2720 - * Note that non-file URLs are treated as file URLs and irrelevant components 2721 - * are ignored. 2722 - */ 2723 - function fromFileUrl(url) { 2724 - return new URL(url).pathname; 2725 - } 2726 - exports_9("fromFileUrl", fromFileUrl); 2727 - return { 2728 - setters: [ 2729 - function (_constants_ts_3_1) { 2730 - _constants_ts_3 = _constants_ts_3_1; 2731 - }, 2732 - function (_util_ts_2_1) { 2733 - _util_ts_2 = _util_ts_2_1; 2734 - }, 2735 - ], 2736 - execute: function () { 2737 - exports_9("sep", sep = "/"); 2738 - exports_9("delimiter", delimiter = ":"); 2739 - }, 2740 - }; 2741 - }, 2742 - ); 2743 - // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 2744 - /** This module is browser compatible. */ 2745 - System.register( 2746 - "https://deno.land/std@0.56.0/path/separator", 2747 - ["https://deno.land/std@0.56.0/path/_constants"], 2748 - function (exports_10, context_10) { 2749 - "use strict"; 2750 - var _constants_ts_4, SEP, SEP_PATTERN; 2751 - var __moduleName = context_10 && context_10.id; 2752 - return { 2753 - setters: [ 2754 - function (_constants_ts_4_1) { 2755 - _constants_ts_4 = _constants_ts_4_1; 2756 - }, 2757 - ], 2758 - execute: function () { 2759 - exports_10("SEP", SEP = _constants_ts_4.isWindows ? "\\" : "/"); 2760 - exports_10( 2761 - "SEP_PATTERN", 2762 - SEP_PATTERN = _constants_ts_4.isWindows ? /[\\/]+/ : /\/+/, 2763 - ); 2764 - }, 2765 - }; 2766 - }, 2767 - ); 2768 - // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 2769 - /** This module is browser compatible. */ 2770 - System.register( 2771 - "https://deno.land/std@0.56.0/path/common", 2772 - ["https://deno.land/std@0.56.0/path/separator"], 2773 - function (exports_11, context_11) { 2774 - "use strict"; 2775 - var separator_ts_1; 2776 - var __moduleName = context_11 && context_11.id; 2777 - /** Determines the common path from a set of paths, using an optional separator, 2778 - * which defaults to the OS default separator. 2779 - * 2780 - * import { common } from "https://deno.land/std/path/mod.ts"; 2781 - * const p = common([ 2782 - * "./deno/std/path/mod.ts", 2783 - * "./deno/std/fs/mod.ts", 2784 - * ]); 2785 - * console.log(p); // "./deno/std/" 2786 - * 2787 - */ 2788 - function common(paths, sep = separator_ts_1.SEP) { 2789 - const [first = "", ...remaining] = paths; 2790 - if (first === "" || remaining.length === 0) { 2791 - return first.substring(0, first.lastIndexOf(sep) + 1); 2792 - } 2793 - const parts = first.split(sep); 2794 - let endOfPrefix = parts.length; 2795 - for (const path of remaining) { 2796 - const compare = path.split(sep); 2797 - for (let i = 0; i < endOfPrefix; i++) { 2798 - if (compare[i] !== parts[i]) { 2799 - endOfPrefix = i; 2800 - } 2801 - } 2802 - if (endOfPrefix === 0) { 2803 - return ""; 2804 - } 2805 - } 2806 - const prefix = parts.slice(0, endOfPrefix).join(sep); 2807 - return prefix.endsWith(sep) ? prefix : `${prefix}${sep}`; 2808 - } 2809 - exports_11("common", common); 2810 - return { 2811 - setters: [ 2812 - function (separator_ts_1_1) { 2813 - separator_ts_1 = separator_ts_1_1; 2814 - }, 2815 - ], 2816 - execute: function () { 2817 - }, 2818 - }; 2819 - }, 2820 - ); 2821 - // This file is ported from globrex@0.1.2 2822 - // MIT License 2823 - // Copyright (c) 2018 Terkel Gjervig Nielsen 2824 - /** This module is browser compatible. */ 2825 - System.register( 2826 - "https://deno.land/std@0.56.0/path/_globrex", 2827 - ["https://deno.land/std@0.56.0/path/_constants"], 2828 - function (exports_12, context_12) { 2829 - "use strict"; 2830 - var _constants_ts_5, 2831 - SEP, 2832 - SEP_ESC, 2833 - SEP_RAW, 2834 - GLOBSTAR, 2835 - WILDCARD, 2836 - GLOBSTAR_SEGMENT, 2837 - WILDCARD_SEGMENT; 2838 - var __moduleName = context_12 && context_12.id; 2839 - /** 2840 - * Convert any glob pattern to a JavaScript Regexp object 2841 - * @param glob Glob pattern to convert 2842 - * @param opts Configuration object 2843 - * @returns Converted object with string, segments and RegExp object 2844 - */ 2845 - function globrex( 2846 - glob, 2847 - { 2848 - extended = false, 2849 - globstar = false, 2850 - strict = false, 2851 - filepath = false, 2852 - flags = "", 2853 - } = {}, 2854 - ) { 2855 - const sepPattern = new RegExp(`^${SEP}${strict ? "" : "+"}$`); 2856 - let regex = ""; 2857 - let segment = ""; 2858 - let pathRegexStr = ""; 2859 - const pathSegments = []; 2860 - // If we are doing extended matching, this boolean is true when we are inside 2861 - // a group (eg {*.html,*.js}), and false otherwise. 2862 - let inGroup = false; 2863 - let inRange = false; 2864 - // extglob stack. Keep track of scope 2865 - const ext = []; 2866 - // Helper function to build string and segments 2867 - function add(str, options = { split: false, last: false, only: "" }) { 2868 - const { split, last, only } = options; 2869 - if (only !== "path") { 2870 - regex += str; 2871 - } 2872 - if (filepath && only !== "regex") { 2873 - pathRegexStr += str.match(sepPattern) ? SEP : str; 2874 - if (split) { 2875 - if (last) { 2876 - segment += str; 2877 - } 2878 - if (segment !== "") { 2879 - // change it 'includes' 2880 - if (!flags.includes("g")) { 2881 - segment = `^${segment}$`; 2882 - } 2883 - pathSegments.push(new RegExp(segment, flags)); 2884 - } 2885 - segment = ""; 2886 - } else { 2887 - segment += str; 2888 - } 2889 - } 2890 - } 2891 - let c, n; 2892 - for (let i = 0; i < glob.length; i++) { 2893 - c = glob[i]; 2894 - n = glob[i + 1]; 2895 - if (["\\", "$", "^", ".", "="].includes(c)) { 2896 - add(`\\${c}`); 2897 - continue; 2898 - } 2899 - if (c.match(sepPattern)) { 2900 - add(SEP, { split: true }); 2901 - if (n != null && n.match(sepPattern) && !strict) { 2902 - regex += "?"; 2903 - } 2904 - continue; 2905 - } 2906 - if (c === "(") { 2907 - if (ext.length) { 2908 - add(`${c}?:`); 2909 - continue; 2910 - } 2911 - add(`\\${c}`); 2912 - continue; 2913 - } 2914 - if (c === ")") { 2915 - if (ext.length) { 2916 - add(c); 2917 - const type = ext.pop(); 2918 - if (type === "@") { 2919 - add("{1}"); 2920 - } else if (type === "!") { 2921 - add(WILDCARD); 2922 - } else { 2923 - add(type); 2924 - } 2925 - continue; 2926 - } 2927 - add(`\\${c}`); 2928 - continue; 2929 - } 2930 - if (c === "|") { 2931 - if (ext.length) { 2932 - add(c); 2933 - continue; 2934 - } 2935 - add(`\\${c}`); 2936 - continue; 2937 - } 2938 - if (c === "+") { 2939 - if (n === "(" && extended) { 2940 - ext.push(c); 2941 - continue; 2942 - } 2943 - add(`\\${c}`); 2944 - continue; 2945 - } 2946 - if (c === "@" && extended) { 2947 - if (n === "(") { 2948 - ext.push(c); 2949 - continue; 2950 - } 2951 - } 2952 - if (c === "!") { 2953 - if (extended) { 2954 - if (inRange) { 2955 - add("^"); 2956 - continue; 2957 - } 2958 - if (n === "(") { 2959 - ext.push(c); 2960 - add("(?!"); 2961 - i++; 2962 - continue; 2963 - } 2964 - add(`\\${c}`); 2965 - continue; 2966 - } 2967 - add(`\\${c}`); 2968 - continue; 2969 - } 2970 - if (c === "?") { 2971 - if (extended) { 2972 - if (n === "(") { 2973 - ext.push(c); 2974 - } else { 2975 - add("."); 2976 - } 2977 - continue; 2978 - } 2979 - add(`\\${c}`); 2980 - continue; 2981 - } 2982 - if (c === "[") { 2983 - if (inRange && n === ":") { 2984 - i++; // skip [ 2985 - let value = ""; 2986 - while (glob[++i] !== ":") { 2987 - value += glob[i]; 2988 - } 2989 - if (value === "alnum") { 2990 - add("(?:\\w|\\d)"); 2991 - } else if (value === "space") { 2992 - add("\\s"); 2993 - } else if (value === "digit") { 2994 - add("\\d"); 2995 - } 2996 - i++; // skip last ] 2997 - continue; 2998 - } 2999 - if (extended) { 3000 - inRange = true; 3001 - add(c); 3002 - continue; 3003 - } 3004 - add(`\\${c}`); 3005 - continue; 3006 - } 3007 - if (c === "]") { 3008 - if (extended) { 3009 - inRange = false; 3010 - add(c); 3011 - continue; 3012 - } 3013 - add(`\\${c}`); 3014 - continue; 3015 - } 3016 - if (c === "{") { 3017 - if (extended) { 3018 - inGroup = true; 3019 - add("(?:"); 3020 - continue; 3021 - } 3022 - add(`\\${c}`); 3023 - continue; 3024 - } 3025 - if (c === "}") { 3026 - if (extended) { 3027 - inGroup = false; 3028 - add(")"); 3029 - continue; 3030 - } 3031 - add(`\\${c}`); 3032 - continue; 3033 - } 3034 - if (c === ",") { 3035 - if (inGroup) { 3036 - add("|"); 3037 - continue; 3038 - } 3039 - add(`\\${c}`); 3040 - continue; 3041 - } 3042 - if (c === "*") { 3043 - if (n === "(" && extended) { 3044 - ext.push(c); 3045 - continue; 3046 - } 3047 - // Move over all consecutive "*"'s. 3048 - // Also store the previous and next characters 3049 - const prevChar = glob[i - 1]; 3050 - let starCount = 1; 3051 - while (glob[i + 1] === "*") { 3052 - starCount++; 3053 - i++; 3054 - } 3055 - const nextChar = glob[i + 1]; 3056 - if (!globstar) { 3057 - // globstar is disabled, so treat any number of "*" as one 3058 - add(".*"); 3059 - } else { 3060 - // globstar is enabled, so determine if this is a globstar segment 3061 - const isGlobstar = starCount > 1 && // multiple "*"'s 3062 - // from the start of the segment 3063 - [SEP_RAW, "/", undefined].includes(prevChar) && 3064 - // to the end of the segment 3065 - [SEP_RAW, "/", undefined].includes(nextChar); 3066 - if (isGlobstar) { 3067 - // it's a globstar, so match zero or more path segments 3068 - add(GLOBSTAR, { only: "regex" }); 3069 - add(GLOBSTAR_SEGMENT, { only: "path", last: true, split: true }); 3070 - i++; // move over the "/" 3071 - } else { 3072 - // it's not a globstar, so only match one path segment 3073 - add(WILDCARD, { only: "regex" }); 3074 - add(WILDCARD_SEGMENT, { only: "path" }); 3075 - } 3076 - } 3077 - continue; 3078 - } 3079 - add(c); 3080 - } 3081 - // When regexp 'g' flag is specified don't 3082 - // constrain the regular expression with ^ & $ 3083 - if (!flags.includes("g")) { 3084 - regex = `^${regex}$`; 3085 - segment = `^${segment}$`; 3086 - if (filepath) { 3087 - pathRegexStr = `^${pathRegexStr}$`; 3088 - } 3089 - } 3090 - const result = { regex: new RegExp(regex, flags) }; 3091 - // Push the last segment 3092 - if (filepath) { 3093 - pathSegments.push(new RegExp(segment, flags)); 3094 - result.path = { 3095 - regex: new RegExp(pathRegexStr, flags), 3096 - segments: pathSegments, 3097 - globstar: new RegExp( 3098 - !flags.includes("g") ? `^${GLOBSTAR_SEGMENT}$` : GLOBSTAR_SEGMENT, 3099 - flags, 3100 - ), 3101 - }; 3102 - } 3103 - return result; 3104 - } 3105 - exports_12("globrex", globrex); 3106 - return { 3107 - setters: [ 3108 - function (_constants_ts_5_1) { 3109 - _constants_ts_5 = _constants_ts_5_1; 3110 - }, 3111 - ], 3112 - execute: function () { 3113 - SEP = _constants_ts_5.isWindows ? `(?:\\\\|\\/)` : `\\/`; 3114 - SEP_ESC = _constants_ts_5.isWindows ? `\\\\` : `/`; 3115 - SEP_RAW = _constants_ts_5.isWindows ? `\\` : `/`; 3116 - GLOBSTAR = `(?:(?:[^${SEP_ESC}/]*(?:${SEP_ESC}|\/|$))*)`; 3117 - WILDCARD = `(?:[^${SEP_ESC}/]*)`; 3118 - GLOBSTAR_SEGMENT = `((?:[^${SEP_ESC}/]*(?:${SEP_ESC}|\/|$))*)`; 3119 - WILDCARD_SEGMENT = `(?:[^${SEP_ESC}/]*)`; 3120 - }, 3121 - }; 3122 - }, 3123 - ); 3124 - // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 3125 - /** This module is browser compatible. */ 3126 - System.register( 3127 - "https://deno.land/std@0.56.0/path/glob", 3128 - [ 3129 - "https://deno.land/std@0.56.0/path/separator", 3130 - "https://deno.land/std@0.56.0/path/_globrex", 3131 - "https://deno.land/std@0.56.0/path/mod", 3132 - "https://deno.land/std@0.56.0/testing/asserts", 3133 - ], 3134 - function (exports_13, context_13) { 3135 - "use strict"; 3136 - var separator_ts_2, _globrex_ts_1, mod_ts_1, asserts_ts_2; 3137 - var __moduleName = context_13 && context_13.id; 3138 - /** 3139 - * Generate a regex based on glob pattern and options 3140 - * This was meant to be using the the `fs.walk` function 3141 - * but can be used anywhere else. 3142 - * Examples: 3143 - * 3144 - * Looking for all the `ts` files: 3145 - * walkSync(".", { 3146 - * match: [globToRegExp("*.ts")] 3147 - * }) 3148 - * 3149 - * Looking for all the `.json` files in any subfolder: 3150 - * walkSync(".", { 3151 - * match: [globToRegExp(join("a", "**", "*.json"),{ 3152 - * flags: "g", 3153 - * extended: true, 3154 - * globstar: true 3155 - * })] 3156 - * }) 3157 - * 3158 - * @param glob - Glob pattern to be used 3159 - * @param options - Specific options for the glob pattern 3160 - * @returns A RegExp for the glob pattern 3161 - */ 3162 - function globToRegExp(glob, { extended = false, globstar = true } = {}) { 3163 - const result = _globrex_ts_1.globrex(glob, { 3164 - extended, 3165 - globstar, 3166 - strict: false, 3167 - filepath: true, 3168 - }); 3169 - asserts_ts_2.assert(result.path != null); 3170 - return result.path.regex; 3171 - } 3172 - exports_13("globToRegExp", globToRegExp); 3173 - /** Test whether the given string is a glob */ 3174 - function isGlob(str) { 3175 - const chars = { "{": "}", "(": ")", "[": "]" }; 3176 - /* eslint-disable-next-line max-len */ 3177 - const regex = 3178 - /\\(.)|(^!|\*|[\].+)]\?|\[[^\\\]]+\]|\{[^\\}]+\}|\(\?[:!=][^\\)]+\)|\([^|]+\|[^\\)]+\))/; 3179 - if (str === "") { 3180 - return false; 3181 - } 3182 - let match; 3183 - while ((match = regex.exec(str))) { 3184 - if (match[2]) { 3185 - return true; 3186 - } 3187 - let idx = match.index + match[0].length; 3188 - // if an open bracket/brace/paren is escaped, 3189 - // set the index to the next closing character 3190 - const open = match[1]; 3191 - const close = open ? chars[open] : null; 3192 - if (open && close) { 3193 - const n = str.indexOf(close, idx); 3194 - if (n !== -1) { 3195 - idx = n + 1; 3196 - } 3197 - } 3198 - str = str.slice(idx); 3199 - } 3200 - return false; 3201 - } 3202 - exports_13("isGlob", isGlob); 3203 - /** Like normalize(), but doesn't collapse "**\/.." when `globstar` is true. */ 3204 - function normalizeGlob(glob, { globstar = false } = {}) { 3205 - if (!!glob.match(/\0/g)) { 3206 - throw new Error(`Glob contains invalid characters: "${glob}"`); 3207 - } 3208 - if (!globstar) { 3209 - return mod_ts_1.normalize(glob); 3210 - } 3211 - const s = separator_ts_2.SEP_PATTERN.source; 3212 - const badParentPattern = new RegExp( 3213 - `(?<=(${s}|^)\\*\\*${s})\\.\\.(?=${s}|$)`, 3214 - "g", 3215 - ); 3216 - return mod_ts_1.normalize(glob.replace(badParentPattern, "\0")).replace( 3217 - /\0/g, 3218 - "..", 3219 - ); 3220 - } 3221 - exports_13("normalizeGlob", normalizeGlob); 3222 - /** Like join(), but doesn't collapse "**\/.." when `globstar` is true. */ 3223 - function joinGlobs(globs, { extended = false, globstar = false } = {}) { 3224 - if (!globstar || globs.length == 0) { 3225 - return mod_ts_1.join(...globs); 3226 - } 3227 - if (globs.length === 0) { 3228 - return "."; 3229 - } 3230 - let joined; 3231 - for (const glob of globs) { 3232 - const path = glob; 3233 - if (path.length > 0) { 3234 - if (!joined) { 3235 - joined = path; 3236 - } else { 3237 - joined += `${separator_ts_2.SEP}${path}`; 3238 - } 3239 - } 3240 - } 3241 - if (!joined) { 3242 - return "."; 3243 - } 3244 - return normalizeGlob(joined, { extended, globstar }); 3245 - } 3246 - exports_13("joinGlobs", joinGlobs); 3247 - return { 3248 - setters: [ 3249 - function (separator_ts_2_1) { 3250 - separator_ts_2 = separator_ts_2_1; 3251 - }, 3252 - function (_globrex_ts_1_1) { 3253 - _globrex_ts_1 = _globrex_ts_1_1; 3254 - }, 3255 - function (mod_ts_1_1) { 3256 - mod_ts_1 = mod_ts_1_1; 3257 - }, 3258 - function (asserts_ts_2_1) { 3259 - asserts_ts_2 = asserts_ts_2_1; 3260 - }, 3261 - ], 3262 - execute: function () { 3263 - }, 3264 - }; 3265 - }, 3266 - ); 3267 - // Copyright the Browserify authors. MIT License. 3268 - // Ported mostly from https://github.com/browserify/path-browserify/ 3269 - /** This module is browser compatible. */ 3270 - System.register( 3271 - "https://deno.land/std@0.56.0/path/mod", 3272 - [ 3273 - "https://deno.land/std@0.56.0/path/_constants", 3274 - "https://deno.land/std@0.56.0/path/win32", 3275 - "https://deno.land/std@0.56.0/path/posix", 3276 - "https://deno.land/std@0.56.0/path/common", 3277 - "https://deno.land/std@0.56.0/path/separator", 3278 - "https://deno.land/std@0.56.0/path/_interface", 3279 - "https://deno.land/std@0.56.0/path/glob", 3280 - ], 3281 - function (exports_14, context_14) { 3282 - "use strict"; 3283 - var _constants_ts_6, 3284 - _win32, 3285 - _posix, 3286 - path, 3287 - win32, 3288 - posix, 3289 - basename, 3290 - delimiter, 3291 - dirname, 3292 - extname, 3293 - format, 3294 - fromFileUrl, 3295 - isAbsolute, 3296 - join, 3297 - normalize, 3298 - parse, 3299 - relative, 3300 - resolve, 3301 - sep, 3302 - toNamespacedPath; 3303 - var __moduleName = context_14 && context_14.id; 3304 - var exportedNames_1 = { 3305 - "win32": true, 3306 - "posix": true, 3307 - "basename": true, 3308 - "delimiter": true, 3309 - "dirname": true, 3310 - "extname": true, 3311 - "format": true, 3312 - "fromFileUrl": true, 3313 - "isAbsolute": true, 3314 - "join": true, 3315 - "normalize": true, 3316 - "parse": true, 3317 - "relative": true, 3318 - "resolve": true, 3319 - "sep": true, 3320 - "toNamespacedPath": true, 3321 - "SEP": true, 3322 - "SEP_PATTERN": true, 3323 - }; 3324 - function exportStar_1(m) { 3325 - var exports = {}; 3326 - for (var n in m) { 3327 - if (n !== "default" && !exportedNames_1.hasOwnProperty(n)) { 3328 - exports[n] = m[n]; 3329 - } 3330 - } 3331 - exports_14(exports); 3332 - } 3333 - return { 3334 - setters: [ 3335 - function (_constants_ts_6_1) { 3336 - _constants_ts_6 = _constants_ts_6_1; 3337 - }, 3338 - function (_win32_1) { 3339 - _win32 = _win32_1; 3340 - }, 3341 - function (_posix_1) { 3342 - _posix = _posix_1; 3343 - }, 3344 - function (common_ts_1_1) { 3345 - exportStar_1(common_ts_1_1); 3346 - }, 3347 - function (separator_ts_3_1) { 3348 - exports_14({ 3349 - "SEP": separator_ts_3_1["SEP"], 3350 - "SEP_PATTERN": separator_ts_3_1["SEP_PATTERN"], 3351 - }); 3352 - }, 3353 - function (_interface_ts_1_1) { 3354 - exportStar_1(_interface_ts_1_1); 3355 - }, 3356 - function (glob_ts_1_1) { 3357 - exportStar_1(glob_ts_1_1); 3358 - }, 3359 - ], 3360 - execute: function () { 3361 - path = _constants_ts_6.isWindows ? _win32 : _posix; 3362 - exports_14("win32", win32 = _win32); 3363 - exports_14("posix", posix = _posix); 3364 - exports_14("basename", basename = path.basename), 3365 - exports_14("delimiter", delimiter = path.delimiter), 3366 - exports_14("dirname", dirname = path.dirname), 3367 - exports_14("extname", extname = path.extname), 3368 - exports_14("format", format = path.format), 3369 - exports_14("fromFileUrl", fromFileUrl = path.fromFileUrl), 3370 - exports_14("isAbsolute", isAbsolute = path.isAbsolute), 3371 - exports_14("join", join = path.join), 3372 - exports_14("normalize", normalize = path.normalize), 3373 - exports_14("parse", parse = path.parse), 3374 - exports_14("relative", relative = path.relative), 3375 - exports_14("resolve", resolve = path.resolve), 3376 - exports_14("sep", sep = path.sep), 3377 - exports_14( 3378 - "toNamespacedPath", 3379 - toNamespacedPath = path.toNamespacedPath, 3380 - ); 3381 - }, 3382 - }; 3383 - }, 3384 - ); 3385 - System.register( 3386 - "https://deno.land/std@0.56.0/io/util", 3387 - [ 3388 - "https://deno.land/std@0.56.0/path/mod", 3389 - "https://deno.land/std@0.56.0/encoding/utf8", 3390 - ], 3391 - function (exports_15, context_15) { 3392 - "use strict"; 3393 - var Buffer, mkdir, open, path, utf8_ts_1; 3394 - var __moduleName = context_15 && context_15.id; 3395 - /** 3396 - * Copy bytes from one Uint8Array to another. Bytes from `src` which don't fit 3397 - * into `dst` will not be copied. 3398 - * 3399 - * @param src Source byte array 3400 - * @param dst Destination byte array 3401 - * @param off Offset into `dst` at which to begin writing values from `src`. 3402 - * @return number of bytes copied 3403 - */ 3404 - function copyBytes(src, dst, off = 0) { 3405 - off = Math.max(0, Math.min(off, dst.byteLength)); 3406 - const dstBytesAvailable = dst.byteLength - off; 3407 - if (src.byteLength > dstBytesAvailable) { 3408 - src = src.subarray(0, dstBytesAvailable); 3409 - } 3410 - dst.set(src, off); 3411 - return src.byteLength; 3412 - } 3413 - exports_15("copyBytes", copyBytes); 3414 - function charCode(s) { 3415 - return s.charCodeAt(0); 3416 - } 3417 - exports_15("charCode", charCode); 3418 - function stringsReader(s) { 3419 - return new Buffer(utf8_ts_1.encode(s).buffer); 3420 - } 3421 - exports_15("stringsReader", stringsReader); 3422 - /** Create or open a temporal file at specified directory with prefix and 3423 - * postfix 3424 - * */ 3425 - async function tempFile(dir, opts = { prefix: "", postfix: "" }) { 3426 - const r = Math.floor(Math.random() * 1000000); 3427 - const filepath = path.resolve( 3428 - `${dir}/${opts.prefix || ""}${r}${opts.postfix || ""}`, 3429 - ); 3430 - await mkdir(path.dirname(filepath), { recursive: true }); 3431 - const file = await open(filepath, { 3432 - create: true, 3433 - read: true, 3434 - write: true, 3435 - append: true, 3436 - }); 3437 - return { file, filepath }; 3438 - } 3439 - exports_15("tempFile", tempFile); 3440 - return { 3441 - setters: [ 3442 - function (path_1) { 3443 - path = path_1; 3444 - }, 3445 - function (utf8_ts_1_1) { 3446 - utf8_ts_1 = utf8_ts_1_1; 3447 - }, 3448 - ], 3449 - execute: function () { 3450 - // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 3451 - Buffer = Deno.Buffer, mkdir = Deno.mkdir, open = Deno.open; 3452 - }, 3453 - }; 3454 - }, 3455 - ); 3456 - // Based on https://github.com/golang/go/blob/891682/src/bufio/bufio.go 3457 - // Copyright 2009 The Go Authors. All rights reserved. 3458 - // Use of this source code is governed by a BSD-style 3459 - // license that can be found in the LICENSE file. 3460 - System.register( 3461 - "https://deno.land/std@0.56.0/io/bufio", 3462 - [ 3463 - "https://deno.land/std@0.56.0/io/util", 3464 - "https://deno.land/std@0.56.0/testing/asserts", 3465 - ], 3466 - function (exports_16, context_16) { 3467 - "use strict"; 3468 - var util_ts_1, 3469 - asserts_ts_3, 3470 - DEFAULT_BUF_SIZE, 3471 - MIN_BUF_SIZE, 3472 - MAX_CONSECUTIVE_EMPTY_READS, 3473 - CR, 3474 - LF, 3475 - BufferFullError, 3476 - PartialReadError, 3477 - BufReader, 3478 - AbstractBufBase, 3479 - BufWriter, 3480 - BufWriterSync; 3481 - var __moduleName = context_16 && context_16.id; 3482 - /** Generate longest proper prefix which is also suffix array. */ 3483 - function createLPS(pat) { 3484 - const lps = new Uint8Array(pat.length); 3485 - lps[0] = 0; 3486 - let prefixEnd = 0; 3487 - let i = 1; 3488 - while (i < lps.length) { 3489 - if (pat[i] == pat[prefixEnd]) { 3490 - prefixEnd++; 3491 - lps[i] = prefixEnd; 3492 - i++; 3493 - } else if (prefixEnd === 0) { 3494 - lps[i] = 0; 3495 - i++; 3496 - } else { 3497 - prefixEnd = pat[prefixEnd - 1]; 3498 - } 3499 - } 3500 - return lps; 3501 - } 3502 - /** Read delimited bytes from a Reader. */ 3503 - async function* readDelim(reader, delim) { 3504 - // Avoid unicode problems 3505 - const delimLen = delim.length; 3506 - const delimLPS = createLPS(delim); 3507 - let inputBuffer = new Deno.Buffer(); 3508 - const inspectArr = new Uint8Array(Math.max(1024, delimLen + 1)); 3509 - // Modified KMP 3510 - let inspectIndex = 0; 3511 - let matchIndex = 0; 3512 - while (true) { 3513 - const result = await reader.read(inspectArr); 3514 - if (result === null) { 3515 - // Yield last chunk. 3516 - yield inputBuffer.bytes(); 3517 - return; 3518 - } 3519 - if (result < 0) { 3520 - // Discard all remaining and silently fail. 3521 - return; 3522 - } 3523 - const sliceRead = inspectArr.subarray(0, result); 3524 - await Deno.writeAll(inputBuffer, sliceRead); 3525 - let sliceToProcess = inputBuffer.bytes(); 3526 - while (inspectIndex < sliceToProcess.length) { 3527 - if (sliceToProcess[inspectIndex] === delim[matchIndex]) { 3528 - inspectIndex++; 3529 - matchIndex++; 3530 - if (matchIndex === delimLen) { 3531 - // Full match 3532 - const matchEnd = inspectIndex - delimLen; 3533 - const readyBytes = sliceToProcess.subarray(0, matchEnd); 3534 - // Copy 3535 - const pendingBytes = sliceToProcess.slice(inspectIndex); 3536 - yield readyBytes; 3537 - // Reset match, different from KMP. 3538 - sliceToProcess = pendingBytes; 3539 - inspectIndex = 0; 3540 - matchIndex = 0; 3541 - } 3542 - } else { 3543 - if (matchIndex === 0) { 3544 - inspectIndex++; 3545 - } else { 3546 - matchIndex = delimLPS[matchIndex - 1]; 3547 - } 3548 - } 3549 - } 3550 - // Keep inspectIndex and matchIndex. 3551 - inputBuffer = new Deno.Buffer(sliceToProcess); 3552 - } 3553 - } 3554 - exports_16("readDelim", readDelim); 3555 - /** Read delimited strings from a Reader. */ 3556 - async function* readStringDelim(reader, delim) { 3557 - const encoder = new TextEncoder(); 3558 - const decoder = new TextDecoder(); 3559 - for await (const chunk of readDelim(reader, encoder.encode(delim))) { 3560 - yield decoder.decode(chunk); 3561 - } 3562 - } 3563 - exports_16("readStringDelim", readStringDelim); 3564 - /** Read strings line-by-line from a Reader. */ 3565 - // eslint-disable-next-line require-await 3566 - async function* readLines(reader) { 3567 - yield* readStringDelim(reader, "\n"); 3568 - } 3569 - exports_16("readLines", readLines); 3570 - return { 3571 - setters: [ 3572 - function (util_ts_1_1) { 3573 - util_ts_1 = util_ts_1_1; 3574 - }, 3575 - function (asserts_ts_3_1) { 3576 - asserts_ts_3 = asserts_ts_3_1; 3577 - }, 3578 - ], 3579 - execute: function () { 3580 - DEFAULT_BUF_SIZE = 4096; 3581 - MIN_BUF_SIZE = 16; 3582 - MAX_CONSECUTIVE_EMPTY_READS = 100; 3583 - CR = util_ts_1.charCode("\r"); 3584 - LF = util_ts_1.charCode("\n"); 3585 - BufferFullError = class BufferFullError extends Error { 3586 - constructor(partial) { 3587 - super("Buffer full"); 3588 - this.partial = partial; 3589 - this.name = "BufferFullError"; 3590 - } 3591 - }; 3592 - exports_16("BufferFullError", BufferFullError); 3593 - PartialReadError = class PartialReadError 3594 - extends Deno.errors.UnexpectedEof { 3595 - constructor() { 3596 - super("Encountered UnexpectedEof, data only partially read"); 3597 - this.name = "PartialReadError"; 3598 - } 3599 - }; 3600 - exports_16("PartialReadError", PartialReadError); 3601 - /** BufReader implements buffering for a Reader object. */ 3602 - BufReader = class BufReader { 3603 - constructor(rd, size = DEFAULT_BUF_SIZE) { 3604 - this.r = 0; // buf read position. 3605 - this.w = 0; // buf write position. 3606 - this.eof = false; 3607 - if (size < MIN_BUF_SIZE) { 3608 - size = MIN_BUF_SIZE; 3609 - } 3610 - this._reset(new Uint8Array(size), rd); 3611 - } 3612 - // private lastByte: number; 3613 - // private lastCharSize: number; 3614 - /** return new BufReader unless r is BufReader */ 3615 - static create(r, size = DEFAULT_BUF_SIZE) { 3616 - return r instanceof BufReader ? r : new BufReader(r, size); 3617 - } 3618 - /** Returns the size of the underlying buffer in bytes. */ 3619 - size() { 3620 - return this.buf.byteLength; 3621 - } 3622 - buffered() { 3623 - return this.w - this.r; 3624 - } 3625 - // Reads a new chunk into the buffer. 3626 - async _fill() { 3627 - // Slide existing data to beginning. 3628 - if (this.r > 0) { 3629 - this.buf.copyWithin(0, this.r, this.w); 3630 - this.w -= this.r; 3631 - this.r = 0; 3632 - } 3633 - if (this.w >= this.buf.byteLength) { 3634 - throw Error("bufio: tried to fill full buffer"); 3635 - } 3636 - // Read new data: try a limited number of times. 3637 - for (let i = MAX_CONSECUTIVE_EMPTY_READS; i > 0; i--) { 3638 - const rr = await this.rd.read(this.buf.subarray(this.w)); 3639 - if (rr === null) { 3640 - this.eof = true; 3641 - return; 3642 - } 3643 - asserts_ts_3.assert(rr >= 0, "negative read"); 3644 - this.w += rr; 3645 - if (rr > 0) { 3646 - return; 3647 - } 3648 - } 3649 - throw new Error( 3650 - `No progress after ${MAX_CONSECUTIVE_EMPTY_READS} read() calls`, 3651 - ); 3652 - } 3653 - /** Discards any buffered data, resets all state, and switches 3654 - * the buffered reader to read from r. 3655 - */ 3656 - reset(r) { 3657 - this._reset(this.buf, r); 3658 - } 3659 - _reset(buf, rd) { 3660 - this.buf = buf; 3661 - this.rd = rd; 3662 - this.eof = false; 3663 - // this.lastByte = -1; 3664 - // this.lastCharSize = -1; 3665 - } 3666 - /** reads data into p. 3667 - * It returns the number of bytes read into p. 3668 - * The bytes are taken from at most one Read on the underlying Reader, 3669 - * hence n may be less than len(p). 3670 - * To read exactly len(p) bytes, use io.ReadFull(b, p). 3671 - */ 3672 - async read(p) { 3673 - let rr = p.byteLength; 3674 - if (p.byteLength === 0) { 3675 - return rr; 3676 - } 3677 - if (this.r === this.w) { 3678 - if (p.byteLength >= this.buf.byteLength) { 3679 - // Large read, empty buffer. 3680 - // Read directly into p to avoid copy. 3681 - const rr = await this.rd.read(p); 3682 - const nread = rr ?? 0; 3683 - asserts_ts_3.assert(nread >= 0, "negative read"); 3684 - // if (rr.nread > 0) { 3685 - // this.lastByte = p[rr.nread - 1]; 3686 - // this.lastCharSize = -1; 3687 - // } 3688 - return rr; 3689 - } 3690 - // One read. 3691 - // Do not use this.fill, which will loop. 3692 - this.r = 0; 3693 - this.w = 0; 3694 - rr = await this.rd.read(this.buf); 3695 - if (rr === 0 || rr === null) { 3696 - return rr; 3697 - } 3698 - asserts_ts_3.assert(rr >= 0, "negative read"); 3699 - this.w += rr; 3700 - } 3701 - // copy as much as we can 3702 - const copied = util_ts_1.copyBytes( 3703 - this.buf.subarray(this.r, this.w), 3704 - p, 3705 - 0, 3706 - ); 3707 - this.r += copied; 3708 - // this.lastByte = this.buf[this.r - 1]; 3709 - // this.lastCharSize = -1; 3710 - return copied; 3711 - } 3712 - /** reads exactly `p.length` bytes into `p`. 3713 - * 3714 - * If successful, `p` is returned. 3715 - * 3716 - * If the end of the underlying stream has been reached, and there are no more 3717 - * bytes available in the buffer, `readFull()` returns `null` instead. 3718 - * 3719 - * An error is thrown if some bytes could be read, but not enough to fill `p` 3720 - * entirely before the underlying stream reported an error or EOF. Any error 3721 - * thrown will have a `partial` property that indicates the slice of the 3722 - * buffer that has been successfully filled with data. 3723 - * 3724 - * Ported from https://golang.org/pkg/io/#ReadFull 3725 - */ 3726 - async readFull(p) { 3727 - let bytesRead = 0; 3728 - while (bytesRead < p.length) { 3729 - try { 3730 - const rr = await this.read(p.subarray(bytesRead)); 3731 - if (rr === null) { 3732 - if (bytesRead === 0) { 3733 - return null; 3734 - } else { 3735 - throw new PartialReadError(); 3736 - } 3737 - } 3738 - bytesRead += rr; 3739 - } catch (err) { 3740 - err.partial = p.subarray(0, bytesRead); 3741 - throw err; 3742 - } 3743 - } 3744 - return p; 3745 - } 3746 - /** Returns the next byte [0, 255] or `null`. */ 3747 - async readByte() { 3748 - while (this.r === this.w) { 3749 - if (this.eof) { 3750 - return null; 3751 - } 3752 - await this._fill(); // buffer is empty. 3753 - } 3754 - const c = this.buf[this.r]; 3755 - this.r++; 3756 - // this.lastByte = c; 3757 - return c; 3758 - } 3759 - /** readString() reads until the first occurrence of delim in the input, 3760 - * returning a string containing the data up to and including the delimiter. 3761 - * If ReadString encounters an error before finding a delimiter, 3762 - * it returns the data read before the error and the error itself 3763 - * (often `null`). 3764 - * ReadString returns err != nil if and only if the returned data does not end 3765 - * in delim. 3766 - * For simple uses, a Scanner may be more convenient. 3767 - */ 3768 - async readString(delim) { 3769 - if (delim.length !== 1) { 3770 - throw new Error("Delimiter should be a single character"); 3771 - } 3772 - const buffer = await this.readSlice(delim.charCodeAt(0)); 3773 - if (buffer === null) { 3774 - return null; 3775 - } 3776 - return new TextDecoder().decode(buffer); 3777 - } 3778 - /** `readLine()` is a low-level line-reading primitive. Most callers should 3779 - * use `readString('\n')` instead or use a Scanner. 3780 - * 3781 - * `readLine()` tries to return a single line, not including the end-of-line 3782 - * bytes. If the line was too long for the buffer then `more` is set and the 3783 - * beginning of the line is returned. The rest of the line will be returned 3784 - * from future calls. `more` will be false when returning the last fragment 3785 - * of the line. The returned buffer is only valid until the next call to 3786 - * `readLine()`. 3787 - * 3788 - * The text returned from ReadLine does not include the line end ("\r\n" or 3789 - * "\n"). 3790 - * 3791 - * When the end of the underlying stream is reached, the final bytes in the 3792 - * stream are returned. No indication or error is given if the input ends 3793 - * without a final line end. When there are no more trailing bytes to read, 3794 - * `readLine()` returns `null`. 3795 - * 3796 - * Calling `unreadByte()` after `readLine()` will always unread the last byte 3797 - * read (possibly a character belonging to the line end) even if that byte is 3798 - * not part of the line returned by `readLine()`. 3799 - */ 3800 - async readLine() { 3801 - let line; 3802 - try { 3803 - line = await this.readSlice(LF); 3804 - } catch (err) { 3805 - let { partial } = err; 3806 - asserts_ts_3.assert( 3807 - partial instanceof Uint8Array, 3808 - "bufio: caught error from `readSlice()` without `partial` property", 3809 - ); 3810 - // Don't throw if `readSlice()` failed with `BufferFullError`, instead we 3811 - // just return whatever is available and set the `more` flag. 3812 - if (!(err instanceof BufferFullError)) { 3813 - throw err; 3814 - } 3815 - // Handle the case where "\r\n" straddles the buffer. 3816 - if ( 3817 - !this.eof && 3818 - partial.byteLength > 0 && 3819 - partial[partial.byteLength - 1] === CR 3820 - ) { 3821 - // Put the '\r' back on buf and drop it from line. 3822 - // Let the next call to ReadLine check for "\r\n". 3823 - asserts_ts_3.assert( 3824 - this.r > 0, 3825 - "bufio: tried to rewind past start of buffer", 3826 - ); 3827 - this.r--; 3828 - partial = partial.subarray(0, partial.byteLength - 1); 3829 - } 3830 - return { line: partial, more: !this.eof }; 3831 - } 3832 - if (line === null) { 3833 - return null; 3834 - } 3835 - if (line.byteLength === 0) { 3836 - return { line, more: false }; 3837 - } 3838 - if (line[line.byteLength - 1] == LF) { 3839 - let drop = 1; 3840 - if (line.byteLength > 1 && line[line.byteLength - 2] === CR) { 3841 - drop = 2; 3842 - } 3843 - line = line.subarray(0, line.byteLength - drop); 3844 - } 3845 - return { line, more: false }; 3846 - } 3847 - /** `readSlice()` reads until the first occurrence of `delim` in the input, 3848 - * returning a slice pointing at the bytes in the buffer. The bytes stop 3849 - * being valid at the next read. 3850 - * 3851 - * If `readSlice()` encounters an error before finding a delimiter, or the 3852 - * buffer fills without finding a delimiter, it throws an error with a 3853 - * `partial` property that contains the entire buffer. 3854 - * 3855 - * If `readSlice()` encounters the end of the underlying stream and there are 3856 - * any bytes left in the buffer, the rest of the buffer is returned. In other 3857 - * words, EOF is always treated as a delimiter. Once the buffer is empty, 3858 - * it returns `null`. 3859 - * 3860 - * Because the data returned from `readSlice()` will be overwritten by the 3861 - * next I/O operation, most clients should use `readString()` instead. 3862 - */ 3863 - async readSlice(delim) { 3864 - let s = 0; // search start index 3865 - let slice; 3866 - while (true) { 3867 - // Search buffer. 3868 - let i = this.buf.subarray(this.r + s, this.w).indexOf(delim); 3869 - if (i >= 0) { 3870 - i += s; 3871 - slice = this.buf.subarray(this.r, this.r + i + 1); 3872 - this.r += i + 1; 3873 - break; 3874 - } 3875 - // EOF? 3876 - if (this.eof) { 3877 - if (this.r === this.w) { 3878 - return null; 3879 - } 3880 - slice = this.buf.subarray(this.r, this.w); 3881 - this.r = this.w; 3882 - break; 3883 - } 3884 - // Buffer full? 3885 - if (this.buffered() >= this.buf.byteLength) { 3886 - this.r = this.w; 3887 - // #4521 The internal buffer should not be reused across reads because it causes corruption of data. 3888 - const oldbuf = this.buf; 3889 - const newbuf = this.buf.slice(0); 3890 - this.buf = newbuf; 3891 - throw new BufferFullError(oldbuf); 3892 - } 3893 - s = this.w - this.r; // do not rescan area we scanned before 3894 - // Buffer is not full. 3895 - try { 3896 - await this._fill(); 3897 - } catch (err) { 3898 - err.partial = slice; 3899 - throw err; 3900 - } 3901 - } 3902 - // Handle last byte, if any. 3903 - // const i = slice.byteLength - 1; 3904 - // if (i >= 0) { 3905 - // this.lastByte = slice[i]; 3906 - // this.lastCharSize = -1 3907 - // } 3908 - return slice; 3909 - } 3910 - /** `peek()` returns the next `n` bytes without advancing the reader. The 3911 - * bytes stop being valid at the next read call. 3912 - * 3913 - * When the end of the underlying stream is reached, but there are unread 3914 - * bytes left in the buffer, those bytes are returned. If there are no bytes 3915 - * left in the buffer, it returns `null`. 3916 - * 3917 - * If an error is encountered before `n` bytes are available, `peek()` throws 3918 - * an error with the `partial` property set to a slice of the buffer that 3919 - * contains the bytes that were available before the error occurred. 3920 - */ 3921 - async peek(n) { 3922 - if (n < 0) { 3923 - throw Error("negative count"); 3924 - } 3925 - let avail = this.w - this.r; 3926 - while (avail < n && avail < this.buf.byteLength && !this.eof) { 3927 - try { 3928 - await this._fill(); 3929 - } catch (err) { 3930 - err.partial = this.buf.subarray(this.r, this.w); 3931 - throw err; 3932 - } 3933 - avail = this.w - this.r; 3934 - } 3935 - if (avail === 0 && this.eof) { 3936 - return null; 3937 - } else if (avail < n && this.eof) { 3938 - return this.buf.subarray(this.r, this.r + avail); 3939 - } else if (avail < n) { 3940 - throw new BufferFullError(this.buf.subarray(this.r, this.w)); 3941 - } 3942 - return this.buf.subarray(this.r, this.r + n); 3943 - } 3944 - }; 3945 - exports_16("BufReader", BufReader); 3946 - AbstractBufBase = class AbstractBufBase { 3947 - constructor() { 3948 - this.usedBufferBytes = 0; 3949 - this.err = null; 3950 - } 3951 - /** Size returns the size of the underlying buffer in bytes. */ 3952 - size() { 3953 - return this.buf.byteLength; 3954 - } 3955 - /** Returns how many bytes are unused in the buffer. */ 3956 - available() { 3957 - return this.buf.byteLength - this.usedBufferBytes; 3958 - } 3959 - /** buffered returns the number of bytes that have been written into the 3960 - * current buffer. 3961 - */ 3962 - buffered() { 3963 - return this.usedBufferBytes; 3964 - } 3965 - checkBytesWritten(numBytesWritten) { 3966 - if (numBytesWritten < this.usedBufferBytes) { 3967 - if (numBytesWritten > 0) { 3968 - this.buf.copyWithin(0, numBytesWritten, this.usedBufferBytes); 3969 - this.usedBufferBytes -= numBytesWritten; 3970 - } 3971 - this.err = new Error("Short write"); 3972 - throw this.err; 3973 - } 3974 - } 3975 - }; 3976 - /** BufWriter implements buffering for an deno.Writer object. 3977 - * If an error occurs writing to a Writer, no more data will be 3978 - * accepted and all subsequent writes, and flush(), will return the error. 3979 - * After all data has been written, the client should call the 3980 - * flush() method to guarantee all data has been forwarded to 3981 - * the underlying deno.Writer. 3982 - */ 3983 - BufWriter = class BufWriter extends AbstractBufBase { 3984 - constructor(writer, size = DEFAULT_BUF_SIZE) { 3985 - super(); 3986 - this.writer = writer; 3987 - if (size <= 0) { 3988 - size = DEFAULT_BUF_SIZE; 3989 - } 3990 - this.buf = new Uint8Array(size); 3991 - } 3992 - /** return new BufWriter unless writer is BufWriter */ 3993 - static create(writer, size = DEFAULT_BUF_SIZE) { 3994 - return writer instanceof BufWriter ? writer 3995 - : new BufWriter(writer, size); 3996 - } 3997 - /** Discards any unflushed buffered data, clears any error, and 3998 - * resets buffer to write its output to w. 3999 - */ 4000 - reset(w) { 4001 - this.err = null; 4002 - this.usedBufferBytes = 0; 4003 - this.writer = w; 4004 - } 4005 - /** Flush writes any buffered data to the underlying io.Writer. */ 4006 - async flush() { 4007 - if (this.err !== null) { 4008 - throw this.err; 4009 - } 4010 - if (this.usedBufferBytes === 0) { 4011 - return; 4012 - } 4013 - let numBytesWritten = 0; 4014 - try { 4015 - numBytesWritten = await this.writer.write( 4016 - this.buf.subarray(0, this.usedBufferBytes), 4017 - ); 4018 - } catch (e) { 4019 - this.err = e; 4020 - throw e; 4021 - } 4022 - this.checkBytesWritten(numBytesWritten); 4023 - this.usedBufferBytes = 0; 4024 - } 4025 - /** Writes the contents of `data` into the buffer. If the contents won't fully 4026 - * fit into the buffer, those bytes that can are copied into the buffer, the 4027 - * buffer is the flushed to the writer and the remaining bytes are copied into 4028 - * the now empty buffer. 4029 - * 4030 - * @return the number of bytes written to the buffer. 4031 - */ 4032 - async write(data) { 4033 - if (this.err !== null) { 4034 - throw this.err; 4035 - } 4036 - if (data.length === 0) { 4037 - return 0; 4038 - } 4039 - let totalBytesWritten = 0; 4040 - let numBytesWritten = 0; 4041 - while (data.byteLength > this.available()) { 4042 - if (this.buffered() === 0) { 4043 - // Large write, empty buffer. 4044 - // Write directly from data to avoid copy. 4045 - try { 4046 - numBytesWritten = await this.writer.write(data); 4047 - } catch (e) { 4048 - this.err = e; 4049 - throw e; 4050 - } 4051 - } else { 4052 - numBytesWritten = util_ts_1.copyBytes( 4053 - data, 4054 - this.buf, 4055 - this.usedBufferBytes, 4056 - ); 4057 - this.usedBufferBytes += numBytesWritten; 4058 - await this.flush(); 4059 - } 4060 - totalBytesWritten += numBytesWritten; 4061 - data = data.subarray(numBytesWritten); 4062 - } 4063 - numBytesWritten = util_ts_1.copyBytes( 4064 - data, 4065 - this.buf, 4066 - this.usedBufferBytes, 4067 - ); 4068 - this.usedBufferBytes += numBytesWritten; 4069 - totalBytesWritten += numBytesWritten; 4070 - return totalBytesWritten; 4071 - } 4072 - }; 4073 - exports_16("BufWriter", BufWriter); 4074 - /** BufWriterSync implements buffering for a deno.WriterSync object. 4075 - * If an error occurs writing to a WriterSync, no more data will be 4076 - * accepted and all subsequent writes, and flush(), will return the error. 4077 - * After all data has been written, the client should call the 4078 - * flush() method to guarantee all data has been forwarded to 4079 - * the underlying deno.WriterSync. 4080 - */ 4081 - BufWriterSync = class BufWriterSync extends AbstractBufBase { 4082 - constructor(writer, size = DEFAULT_BUF_SIZE) { 4083 - super(); 4084 - this.writer = writer; 4085 - if (size <= 0) { 4086 - size = DEFAULT_BUF_SIZE; 4087 - } 4088 - this.buf = new Uint8Array(size); 4089 - } 4090 - /** return new BufWriterSync unless writer is BufWriterSync */ 4091 - static create(writer, size = DEFAULT_BUF_SIZE) { 4092 - return writer instanceof BufWriterSync 4093 - ? writer 4094 - : new BufWriterSync(writer, size); 4095 - } 4096 - /** Discards any unflushed buffered data, clears any error, and 4097 - * resets buffer to write its output to w. 4098 - */ 4099 - reset(w) { 4100 - this.err = null; 4101 - this.usedBufferBytes = 0; 4102 - this.writer = w; 4103 - } 4104 - /** Flush writes any buffered data to the underlying io.WriterSync. */ 4105 - flush() { 4106 - if (this.err !== null) { 4107 - throw this.err; 4108 - } 4109 - if (this.usedBufferBytes === 0) { 4110 - return; 4111 - } 4112 - let numBytesWritten = 0; 4113 - try { 4114 - numBytesWritten = this.writer.writeSync( 4115 - this.buf.subarray(0, this.usedBufferBytes), 4116 - ); 4117 - } catch (e) { 4118 - this.err = e; 4119 - throw e; 4120 - } 4121 - this.checkBytesWritten(numBytesWritten); 4122 - this.usedBufferBytes = 0; 4123 - } 4124 - /** Writes the contents of `data` into the buffer. If the contents won't fully 4125 - * fit into the buffer, those bytes that can are copied into the buffer, the 4126 - * buffer is the flushed to the writer and the remaining bytes are copied into 4127 - * the now empty buffer. 4128 - * 4129 - * @return the number of bytes written to the buffer. 4130 - */ 4131 - writeSync(data) { 4132 - if (this.err !== null) { 4133 - throw this.err; 4134 - } 4135 - if (data.length === 0) { 4136 - return 0; 4137 - } 4138 - let totalBytesWritten = 0; 4139 - let numBytesWritten = 0; 4140 - while (data.byteLength > this.available()) { 4141 - if (this.buffered() === 0) { 4142 - // Large write, empty buffer. 4143 - // Write directly from data to avoid copy. 4144 - try { 4145 - numBytesWritten = this.writer.writeSync(data); 4146 - } catch (e) { 4147 - this.err = e; 4148 - throw e; 4149 - } 4150 - } else { 4151 - numBytesWritten = util_ts_1.copyBytes( 4152 - data, 4153 - this.buf, 4154 - this.usedBufferBytes, 4155 - ); 4156 - this.usedBufferBytes += numBytesWritten; 4157 - this.flush(); 4158 - } 4159 - totalBytesWritten += numBytesWritten; 4160 - data = data.subarray(numBytesWritten); 4161 - } 4162 - numBytesWritten = util_ts_1.copyBytes( 4163 - data, 4164 - this.buf, 4165 - this.usedBufferBytes, 4166 - ); 4167 - this.usedBufferBytes += numBytesWritten; 4168 - totalBytesWritten += numBytesWritten; 4169 - return totalBytesWritten; 4170 - } 4171 - }; 4172 - exports_16("BufWriterSync", BufWriterSync); 4173 - }, 4174 - }; 4175 - }, 4176 - ); 4177 - System.register( 4178 - "https://deno.land/std@0.56.0/async/deferred", 4179 - [], 4180 - function (exports_17, context_17) { 4181 - "use strict"; 4182 - var __moduleName = context_17 && context_17.id; 4183 - /** Creates a Promise with the `reject` and `resolve` functions 4184 - * placed as methods on the promise object itself. It allows you to do: 4185 - * 4186 - * const p = deferred<number>(); 4187 - * // ... 4188 - * p.resolve(42); 4189 - */ 4190 - function deferred() { 4191 - let methods; 4192 - const promise = new Promise((resolve, reject) => { 4193 - methods = { resolve, reject }; 4194 - }); 4195 - return Object.assign(promise, methods); 4196 - } 4197 - exports_17("deferred", deferred); 4198 - return { 4199 - setters: [], 4200 - execute: function () { 4201 - }, 4202 - }; 4203 - }, 4204 - ); 4205 - System.register( 4206 - "https://deno.land/std@0.56.0/async/delay", 4207 - [], 4208 - function (exports_18, context_18) { 4209 - "use strict"; 4210 - var __moduleName = context_18 && context_18.id; 4211 - // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 4212 - /* Resolves after the given number of milliseconds. */ 4213 - function delay(ms) { 4214 - return new Promise((res) => 4215 - setTimeout(() => { 4216 - res(); 4217 - }, ms) 4218 - ); 4219 - } 4220 - exports_18("delay", delay); 4221 - return { 4222 - setters: [], 4223 - execute: function () { 4224 - }, 4225 - }; 4226 - }, 4227 - ); 4228 - System.register( 4229 - "https://deno.land/std@0.56.0/async/mux_async_iterator", 4230 - ["https://deno.land/std@0.56.0/async/deferred"], 4231 - function (exports_19, context_19) { 4232 - "use strict"; 4233 - var deferred_ts_1, MuxAsyncIterator; 4234 - var __moduleName = context_19 && context_19.id; 4235 - return { 4236 - setters: [ 4237 - function (deferred_ts_1_1) { 4238 - deferred_ts_1 = deferred_ts_1_1; 4239 - }, 4240 - ], 4241 - execute: function () { 4242 - /** The MuxAsyncIterator class multiplexes multiple async iterators into a 4243 - * single stream. It currently makes a few assumptions: 4244 - * - The iterators do not throw. 4245 - * - The final result (the value returned and not yielded from the iterator) 4246 - * does not matter; if there is any, it is discarded. 4247 - */ 4248 - MuxAsyncIterator = class MuxAsyncIterator { 4249 - constructor() { 4250 - this.iteratorCount = 0; 4251 - this.yields = []; 4252 - this.signal = deferred_ts_1.deferred(); 4253 - } 4254 - add(iterator) { 4255 - ++this.iteratorCount; 4256 - this.callIteratorNext(iterator); 4257 - } 4258 - async callIteratorNext(iterator) { 4259 - const { value, done } = await iterator.next(); 4260 - if (done) { 4261 - --this.iteratorCount; 4262 - } else { 4263 - this.yields.push({ iterator, value }); 4264 - } 4265 - this.signal.resolve(); 4266 - } 4267 - async *iterate() { 4268 - while (this.iteratorCount > 0) { 4269 - // Sleep until any of the wrapped iterators yields. 4270 - await this.signal; 4271 - // Note that while we're looping over `yields`, new items may be added. 4272 - for (let i = 0; i < this.yields.length; i++) { 4273 - const { iterator, value } = this.yields[i]; 4274 - yield value; 4275 - this.callIteratorNext(iterator); 4276 - } 4277 - // Clear the `yields` list and reset the `signal` promise. 4278 - this.yields.length = 0; 4279 - this.signal = deferred_ts_1.deferred(); 4280 - } 4281 - } 4282 - [Symbol.asyncIterator]() { 4283 - return this.iterate(); 4284 - } 4285 - }; 4286 - exports_19("MuxAsyncIterator", MuxAsyncIterator); 4287 - }, 4288 - }; 4289 - }, 4290 - ); 4291 - System.register( 4292 - "https://deno.land/std@0.56.0/async/mod", 4293 - [ 4294 - "https://deno.land/std@0.56.0/async/deferred", 4295 - "https://deno.land/std@0.56.0/async/delay", 4296 - "https://deno.land/std@0.56.0/async/mux_async_iterator", 4297 - ], 4298 - function (exports_20, context_20) { 4299 - "use strict"; 4300 - var __moduleName = context_20 && context_20.id; 4301 - function exportStar_2(m) { 4302 - var exports = {}; 4303 - for (var n in m) { 4304 - if (n !== "default") exports[n] = m[n]; 4305 - } 4306 - exports_20(exports); 4307 - } 4308 - return { 4309 - setters: [ 4310 - function (deferred_ts_2_1) { 4311 - exportStar_2(deferred_ts_2_1); 4312 - }, 4313 - function (delay_ts_1_1) { 4314 - exportStar_2(delay_ts_1_1); 4315 - }, 4316 - function (mux_async_iterator_ts_1_1) { 4317 - exportStar_2(mux_async_iterator_ts_1_1); 4318 - }, 4319 - ], 4320 - execute: function () { 4321 - }, 4322 - }; 4323 - }, 4324 - ); 4325 - System.register( 4326 - "https://deno.land/std@0.56.0/bytes/mod", 4327 - ["https://deno.land/std@0.56.0/io/util"], 4328 - function (exports_21, context_21) { 4329 - "use strict"; 4330 - var util_ts_2; 4331 - var __moduleName = context_21 && context_21.id; 4332 - /** Find first index of binary pattern from a. If not found, then return -1 4333 - * @param source soruce array 4334 - * @param pat pattern to find in source array 4335 - */ 4336 - function findIndex(source, pat) { 4337 - const s = pat[0]; 4338 - for (let i = 0; i < source.length; i++) { 4339 - if (source[i] !== s) { 4340 - continue; 4341 - } 4342 - const pin = i; 4343 - let matched = 1; 4344 - let j = i; 4345 - while (matched < pat.length) { 4346 - j++; 4347 - if (source[j] !== pat[j - pin]) { 4348 - break; 4349 - } 4350 - matched++; 4351 - } 4352 - if (matched === pat.length) { 4353 - return pin; 4354 - } 4355 - } 4356 - return -1; 4357 - } 4358 - exports_21("findIndex", findIndex); 4359 - /** Find last index of binary pattern from a. If not found, then return -1. 4360 - * @param source soruce array 4361 - * @param pat pattern to find in source array 4362 - */ 4363 - function findLastIndex(source, pat) { 4364 - const e = pat[pat.length - 1]; 4365 - for (let i = source.length - 1; i >= 0; i--) { 4366 - if (source[i] !== e) { 4367 - continue; 4368 - } 4369 - const pin = i; 4370 - let matched = 1; 4371 - let j = i; 4372 - while (matched < pat.length) { 4373 - j--; 4374 - if (source[j] !== pat[pat.length - 1 - (pin - j)]) { 4375 - break; 4376 - } 4377 - matched++; 4378 - } 4379 - if (matched === pat.length) { 4380 - return pin - pat.length + 1; 4381 - } 4382 - } 4383 - return -1; 4384 - } 4385 - exports_21("findLastIndex", findLastIndex); 4386 - /** Check whether binary arrays are equal to each other. 4387 - * @param source first array to check equality 4388 - * @param match second array to check equality 4389 - */ 4390 - function equal(source, match) { 4391 - if (source.length !== match.length) { 4392 - return false; 4393 - } 4394 - for (let i = 0; i < match.length; i++) { 4395 - if (source[i] !== match[i]) { 4396 - return false; 4397 - } 4398 - } 4399 - return true; 4400 - } 4401 - exports_21("equal", equal); 4402 - /** Check whether binary array starts with prefix. 4403 - * @param source srouce array 4404 - * @param prefix prefix array to check in source 4405 - */ 4406 - function hasPrefix(source, prefix) { 4407 - for (let i = 0, max = prefix.length; i < max; i++) { 4408 - if (source[i] !== prefix[i]) { 4409 - return false; 4410 - } 4411 - } 4412 - return true; 4413 - } 4414 - exports_21("hasPrefix", hasPrefix); 4415 - /** Check whether binary array ends with suffix. 4416 - * @param source srouce array 4417 - * @param suffix suffix array to check in source 4418 - */ 4419 - function hasSuffix(source, suffix) { 4420 - for ( 4421 - let srci = source.length - 1, sfxi = suffix.length - 1; 4422 - sfxi >= 0; 4423 - srci--, sfxi-- 4424 - ) { 4425 - if (source[srci] !== suffix[sfxi]) { 4426 - return false; 4427 - } 4428 - } 4429 - return true; 4430 - } 4431 - exports_21("hasSuffix", hasSuffix); 4432 - /** Repeat bytes. returns a new byte slice consisting of `count` copies of `b`. 4433 - * @param origin The origin bytes 4434 - * @param count The count you want to repeat. 4435 - */ 4436 - function repeat(origin, count) { 4437 - if (count === 0) { 4438 - return new Uint8Array(); 4439 - } 4440 - if (count < 0) { 4441 - throw new Error("bytes: negative repeat count"); 4442 - } else if ((origin.length * count) / count !== origin.length) { 4443 - throw new Error("bytes: repeat count causes overflow"); 4444 - } 4445 - const int = Math.floor(count); 4446 - if (int !== count) { 4447 - throw new Error("bytes: repeat count must be an integer"); 4448 - } 4449 - const nb = new Uint8Array(origin.length * count); 4450 - let bp = util_ts_2.copyBytes(origin, nb); 4451 - for (; bp < nb.length; bp *= 2) { 4452 - util_ts_2.copyBytes(nb.slice(0, bp), nb, bp); 4453 - } 4454 - return nb; 4455 - } 4456 - exports_21("repeat", repeat); 4457 - /** Concatenate two binary arrays and return new one. 4458 - * @param origin origin array to concatenate 4459 - * @param b array to concatenate with origin 4460 - */ 4461 - function concat(origin, b) { 4462 - const output = new Uint8Array(origin.length + b.length); 4463 - output.set(origin, 0); 4464 - output.set(b, origin.length); 4465 - return output; 4466 - } 4467 - exports_21("concat", concat); 4468 - /** Check srouce array contains pattern array. 4469 - * @param source srouce array 4470 - * @param pat patter array 4471 - */ 4472 - function contains(source, pat) { 4473 - return findIndex(source, pat) != -1; 4474 - } 4475 - exports_21("contains", contains); 4476 - return { 4477 - setters: [ 4478 - function (util_ts_2_1) { 4479 - util_ts_2 = util_ts_2_1; 4480 - }, 4481 - ], 4482 - execute: function () { 4483 - }, 4484 - }; 4485 - }, 4486 - ); 4487 - // Based on https://github.com/golang/go/tree/master/src/net/textproto 4488 - // Copyright 2009 The Go Authors. All rights reserved. 4489 - // Use of this source code is governed by a BSD-style 4490 - // license that can be found in the LICENSE file. 4491 - System.register( 4492 - "https://deno.land/std@0.56.0/textproto/mod", 4493 - [ 4494 - "https://deno.land/std@0.56.0/io/util", 4495 - "https://deno.land/std@0.56.0/bytes/mod", 4496 - "https://deno.land/std@0.56.0/encoding/utf8", 4497 - ], 4498 - function (exports_22, context_22) { 4499 - "use strict"; 4500 - var util_ts_3, mod_ts_2, utf8_ts_2, invalidHeaderCharRegex, TextProtoReader; 4501 - var __moduleName = context_22 && context_22.id; 4502 - function str(buf) { 4503 - if (buf == null) { 4504 - return ""; 4505 - } else { 4506 - return utf8_ts_2.decode(buf); 4507 - } 4508 - } 4509 - return { 4510 - setters: [ 4511 - function (util_ts_3_1) { 4512 - util_ts_3 = util_ts_3_1; 4513 - }, 4514 - function (mod_ts_2_1) { 4515 - mod_ts_2 = mod_ts_2_1; 4516 - }, 4517 - function (utf8_ts_2_1) { 4518 - utf8_ts_2 = utf8_ts_2_1; 4519 - }, 4520 - ], 4521 - execute: function () { 4522 - // FROM https://github.com/denoland/deno/blob/b34628a26ab0187a827aa4ebe256e23178e25d39/cli/js/web/headers.ts#L9 4523 - invalidHeaderCharRegex = /[^\t\x20-\x7e\x80-\xff]/g; 4524 - TextProtoReader = class TextProtoReader { 4525 - constructor(r) { 4526 - this.r = r; 4527 - } 4528 - /** readLine() reads a single line from the TextProtoReader, 4529 - * eliding the final \n or \r\n from the returned string. 4530 - */ 4531 - async readLine() { 4532 - const s = await this.readLineSlice(); 4533 - if (s === null) { 4534 - return null; 4535 - } 4536 - return str(s); 4537 - } 4538 - /** ReadMIMEHeader reads a MIME-style header from r. 4539 - * The header is a sequence of possibly continued Key: Value lines 4540 - * ending in a blank line. 4541 - * The returned map m maps CanonicalMIMEHeaderKey(key) to a 4542 - * sequence of values in the same order encountered in the input. 4543 - * 4544 - * For example, consider this input: 4545 - * 4546 - * My-Key: Value 1 4547 - * Long-Key: Even 4548 - * Longer Value 4549 - * My-Key: Value 2 4550 - * 4551 - * Given that input, ReadMIMEHeader returns the map: 4552 - * 4553 - * map[string][]string{ 4554 - * "My-Key": {"Value 1", "Value 2"}, 4555 - * "Long-Key": {"Even Longer Value"}, 4556 - * } 4557 - */ 4558 - async readMIMEHeader() { 4559 - const m = new Headers(); 4560 - let line; 4561 - // The first line cannot start with a leading space. 4562 - let buf = await this.r.peek(1); 4563 - if (buf === null) { 4564 - return null; 4565 - } else if ( 4566 - buf[0] == util_ts_3.charCode(" ") || 4567 - buf[0] == util_ts_3.charCode("\t") 4568 - ) { 4569 - line = (await this.readLineSlice()); 4570 - } 4571 - buf = await this.r.peek(1); 4572 - if (buf === null) { 4573 - throw new Deno.errors.UnexpectedEof(); 4574 - } else if ( 4575 - buf[0] == util_ts_3.charCode(" ") || 4576 - buf[0] == util_ts_3.charCode("\t") 4577 - ) { 4578 - throw new Deno.errors.InvalidData( 4579 - `malformed MIME header initial line: ${str(line)}`, 4580 - ); 4581 - } 4582 - while (true) { 4583 - const kv = await this.readLineSlice(); // readContinuedLineSlice 4584 - if (kv === null) { 4585 - throw new Deno.errors.UnexpectedEof(); 4586 - } 4587 - if (kv.byteLength === 0) { 4588 - return m; 4589 - } 4590 - // Key ends at first colon 4591 - let i = kv.indexOf(util_ts_3.charCode(":")); 4592 - if (i < 0) { 4593 - throw new Deno.errors.InvalidData( 4594 - `malformed MIME header line: ${str(kv)}`, 4595 - ); 4596 - } 4597 - //let key = canonicalMIMEHeaderKey(kv.subarray(0, endKey)); 4598 - const key = str(kv.subarray(0, i)); 4599 - // As per RFC 7230 field-name is a token, 4600 - // tokens consist of one or more chars. 4601 - // We could throw `Deno.errors.InvalidData` here, 4602 - // but better to be liberal in what we 4603 - // accept, so if we get an empty key, skip it. 4604 - if (key == "") { 4605 - continue; 4606 - } 4607 - // Skip initial spaces in value. 4608 - i++; // skip colon 4609 - while ( 4610 - i < kv.byteLength && 4611 - (kv[i] == util_ts_3.charCode(" ") || 4612 - kv[i] == util_ts_3.charCode("\t")) 4613 - ) { 4614 - i++; 4615 - } 4616 - const value = str(kv.subarray(i)).replace( 4617 - invalidHeaderCharRegex, 4618 - encodeURI, 4619 - ); 4620 - // In case of invalid header we swallow the error 4621 - // example: "Audio Mode" => invalid due to space in the key 4622 - try { 4623 - m.append(key, value); 4624 - } catch {} 4625 - } 4626 - } 4627 - async readLineSlice() { 4628 - // this.closeDot(); 4629 - let line; 4630 - while (true) { 4631 - const r = await this.r.readLine(); 4632 - if (r === null) { 4633 - return null; 4634 - } 4635 - const { line: l, more } = r; 4636 - // Avoid the copy if the first call produced a full line. 4637 - if (!line && !more) { 4638 - // TODO(ry): 4639 - // This skipSpace() is definitely misplaced, but I don't know where it 4640 - // comes from nor how to fix it. 4641 - if (this.skipSpace(l) === 0) { 4642 - return new Uint8Array(0); 4643 - } 4644 - return l; 4645 - } 4646 - line = line ? mod_ts_2.concat(line, l) : l; 4647 - if (!more) { 4648 - break; 4649 - } 4650 - } 4651 - return line; 4652 - } 4653 - skipSpace(l) { 4654 - let n = 0; 4655 - for (let i = 0; i < l.length; i++) { 4656 - if ( 4657 - l[i] === util_ts_3.charCode(" ") || 4658 - l[i] === util_ts_3.charCode("\t") 4659 - ) { 4660 - continue; 4661 - } 4662 - n++; 4663 - } 4664 - return n; 4665 - } 4666 - }; 4667 - exports_22("TextProtoReader", TextProtoReader); 4668 - }, 4669 - }; 4670 - }, 4671 - ); 4672 - // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. 4673 - System.register( 4674 - "https://deno.land/std@0.56.0/http/http_status", 4675 - [], 4676 - function (exports_23, context_23) { 4677 - "use strict"; 4678 - var Status, STATUS_TEXT; 4679 - var __moduleName = context_23 && context_23.id; 4680 - return { 4681 - setters: [], 4682 - execute: function () { 4683 - /** HTTP status codes */ 4684 - (function (Status) { 4685 - /** RFC 7231, 6.2.1 */ 4686 - Status[Status["Continue"] = 100] = "Continue"; 4687 - /** RFC 7231, 6.2.2 */ 4688 - Status[Status["SwitchingProtocols"] = 101] = "SwitchingProtocols"; 4689 - /** RFC 2518, 10.1 */ 4690 - Status[Status["Processing"] = 102] = "Processing"; 4691 - /** RFC 8297 **/ 4692 - Status[Status["EarlyHints"] = 103] = "EarlyHints"; 4693 - /** RFC 7231, 6.3.1 */ 4694 - Status[Status["OK"] = 200] = "OK"; 4695 - /** RFC 7231, 6.3.2 */ 4696 - Status[Status["Created"] = 201] = "Created"; 4697 - /** RFC 7231, 6.3.3 */ 4698 - Status[Status["Accepted"] = 202] = "Accepted"; 4699 - /** RFC 7231, 6.3.4 */ 4700 - Status[Status["NonAuthoritativeInfo"] = 203] = "NonAuthoritativeInfo"; 4701 - /** RFC 7231, 6.3.5 */ 4702 - Status[Status["NoContent"] = 204] = "NoContent"; 4703 - /** RFC 7231, 6.3.6 */ 4704 - Status[Status["ResetContent"] = 205] = "ResetContent"; 4705 - /** RFC 7233, 4.1 */ 4706 - Status[Status["PartialContent"] = 206] = "PartialContent"; 4707 - /** RFC 4918, 11.1 */ 4708 - Status[Status["MultiStatus"] = 207] = "MultiStatus"; 4709 - /** RFC 5842, 7.1 */ 4710 - Status[Status["AlreadyReported"] = 208] = "AlreadyReported"; 4711 - /** RFC 3229, 10.4.1 */ 4712 - Status[Status["IMUsed"] = 226] = "IMUsed"; 4713 - /** RFC 7231, 6.4.1 */ 4714 - Status[Status["MultipleChoices"] = 300] = "MultipleChoices"; 4715 - /** RFC 7231, 6.4.2 */ 4716 - Status[Status["MovedPermanently"] = 301] = "MovedPermanently"; 4717 - /** RFC 7231, 6.4.3 */ 4718 - Status[Status["Found"] = 302] = "Found"; 4719 - /** RFC 7231, 6.4.4 */ 4720 - Status[Status["SeeOther"] = 303] = "SeeOther"; 4721 - /** RFC 7232, 4.1 */ 4722 - Status[Status["NotModified"] = 304] = "NotModified"; 4723 - /** RFC 7231, 6.4.5 */ 4724 - Status[Status["UseProxy"] = 305] = "UseProxy"; 4725 - /** RFC 7231, 6.4.7 */ 4726 - Status[Status["TemporaryRedirect"] = 307] = "TemporaryRedirect"; 4727 - /** RFC 7538, 3 */ 4728 - Status[Status["PermanentRedirect"] = 308] = "PermanentRedirect"; 4729 - /** RFC 7231, 6.5.1 */ 4730 - Status[Status["BadRequest"] = 400] = "BadRequest"; 4731 - /** RFC 7235, 3.1 */ 4732 - Status[Status["Unauthorized"] = 401] = "Unauthorized"; 4733 - /** RFC 7231, 6.5.2 */ 4734 - Status[Status["PaymentRequired"] = 402] = "PaymentRequired"; 4735 - /** RFC 7231, 6.5.3 */ 4736 - Status[Status["Forbidden"] = 403] = "Forbidden"; 4737 - /** RFC 7231, 6.5.4 */ 4738 - Status[Status["NotFound"] = 404] = "NotFound"; 4739 - /** RFC 7231, 6.5.5 */ 4740 - Status[Status["MethodNotAllowed"] = 405] = "MethodNotAllowed"; 4741 - /** RFC 7231, 6.5.6 */ 4742 - Status[Status["NotAcceptable"] = 406] = "NotAcceptable"; 4743 - /** RFC 7235, 3.2 */ 4744 - Status[Status["ProxyAuthRequired"] = 407] = "ProxyAuthRequired"; 4745 - /** RFC 7231, 6.5.7 */ 4746 - Status[Status["RequestTimeout"] = 408] = "RequestTimeout"; 4747 - /** RFC 7231, 6.5.8 */ 4748 - Status[Status["Conflict"] = 409] = "Conflict"; 4749 - /** RFC 7231, 6.5.9 */ 4750 - Status[Status["Gone"] = 410] = "Gone"; 4751 - /** RFC 7231, 6.5.10 */ 4752 - Status[Status["LengthRequired"] = 411] = "LengthRequired"; 4753 - /** RFC 7232, 4.2 */ 4754 - Status[Status["PreconditionFailed"] = 412] = "PreconditionFailed"; 4755 - /** RFC 7231, 6.5.11 */ 4756 - Status[Status["RequestEntityTooLarge"] = 413] = 4757 - "RequestEntityTooLarge"; 4758 - /** RFC 7231, 6.5.12 */ 4759 - Status[Status["RequestURITooLong"] = 414] = "RequestURITooLong"; 4760 - /** RFC 7231, 6.5.13 */ 4761 - Status[Status["UnsupportedMediaType"] = 415] = "UnsupportedMediaType"; 4762 - /** RFC 7233, 4.4 */ 4763 - Status[Status["RequestedRangeNotSatisfiable"] = 416] = 4764 - "RequestedRangeNotSatisfiable"; 4765 - /** RFC 7231, 6.5.14 */ 4766 - Status[Status["ExpectationFailed"] = 417] = "ExpectationFailed"; 4767 - /** RFC 7168, 2.3.3 */ 4768 - Status[Status["Teapot"] = 418] = "Teapot"; 4769 - /** RFC 7540, 9.1.2 */ 4770 - Status[Status["MisdirectedRequest"] = 421] = "MisdirectedRequest"; 4771 - /** RFC 4918, 11.2 */ 4772 - Status[Status["UnprocessableEntity"] = 422] = "UnprocessableEntity"; 4773 - /** RFC 4918, 11.3 */ 4774 - Status[Status["Locked"] = 423] = "Locked"; 4775 - /** RFC 4918, 11.4 */ 4776 - Status[Status["FailedDependency"] = 424] = "FailedDependency"; 4777 - /** RFC 8470, 5.2 */ 4778 - Status[Status["TooEarly"] = 425] = "TooEarly"; 4779 - /** RFC 7231, 6.5.15 */ 4780 - Status[Status["UpgradeRequired"] = 426] = "UpgradeRequired"; 4781 - /** RFC 6585, 3 */ 4782 - Status[Status["PreconditionRequired"] = 428] = "PreconditionRequired"; 4783 - /** RFC 6585, 4 */ 4784 - Status[Status["TooManyRequests"] = 429] = "TooManyRequests"; 4785 - /** RFC 6585, 5 */ 4786 - Status[Status["RequestHeaderFieldsTooLarge"] = 431] = 4787 - "RequestHeaderFieldsTooLarge"; 4788 - /** RFC 7725, 3 */ 4789 - Status[Status["UnavailableForLegalReasons"] = 451] = 4790 - "UnavailableForLegalReasons"; 4791 - /** RFC 7231, 6.6.1 */ 4792 - Status[Status["InternalServerError"] = 500] = "InternalServerError"; 4793 - /** RFC 7231, 6.6.2 */ 4794 - Status[Status["NotImplemented"] = 501] = "NotImplemented"; 4795 - /** RFC 7231, 6.6.3 */ 4796 - Status[Status["BadGateway"] = 502] = "BadGateway"; 4797 - /** RFC 7231, 6.6.4 */ 4798 - Status[Status["ServiceUnavailable"] = 503] = "ServiceUnavailable"; 4799 - /** RFC 7231, 6.6.5 */ 4800 - Status[Status["GatewayTimeout"] = 504] = "GatewayTimeout"; 4801 - /** RFC 7231, 6.6.6 */ 4802 - Status[Status["HTTPVersionNotSupported"] = 505] = 4803 - "HTTPVersionNotSupported"; 4804 - /** RFC 2295, 8.1 */ 4805 - Status[Status["VariantAlsoNegotiates"] = 506] = 4806 - "VariantAlsoNegotiates"; 4807 - /** RFC 4918, 11.5 */ 4808 - Status[Status["InsufficientStorage"] = 507] = "InsufficientStorage"; 4809 - /** RFC 5842, 7.2 */ 4810 - Status[Status["LoopDetected"] = 508] = "LoopDetected"; 4811 - /** RFC 2774, 7 */ 4812 - Status[Status["NotExtended"] = 510] = "NotExtended"; 4813 - /** RFC 6585, 6 */ 4814 - Status[Status["NetworkAuthenticationRequired"] = 511] = 4815 - "NetworkAuthenticationRequired"; 4816 - })(Status || (Status = {})); 4817 - exports_23("Status", Status); 4818 - exports_23( 4819 - "STATUS_TEXT", 4820 - STATUS_TEXT = new Map([ 4821 - [Status.Continue, "Continue"], 4822 - [Status.SwitchingProtocols, "Switching Protocols"], 4823 - [Status.Processing, "Processing"], 4824 - [Status.EarlyHints, "Early Hints"], 4825 - [Status.OK, "OK"], 4826 - [Status.Created, "Created"], 4827 - [Status.Accepted, "Accepted"], 4828 - [Status.NonAuthoritativeInfo, "Non-Authoritative Information"], 4829 - [Status.NoContent, "No Content"], 4830 - [Status.ResetContent, "Reset Content"], 4831 - [Status.PartialContent, "Partial Content"], 4832 - [Status.MultiStatus, "Multi-Status"], 4833 - [Status.AlreadyReported, "Already Reported"], 4834 - [Status.IMUsed, "IM Used"], 4835 - [Status.MultipleChoices, "Multiple Choices"], 4836 - [Status.MovedPermanently, "Moved Permanently"], 4837 - [Status.Found, "Found"], 4838 - [Status.SeeOther, "See Other"], 4839 - [Status.NotModified, "Not Modified"], 4840 - [Status.UseProxy, "Use Proxy"], 4841 - [Status.TemporaryRedirect, "Temporary Redirect"], 4842 - [Status.PermanentRedirect, "Permanent Redirect"], 4843 - [Status.BadRequest, "Bad Request"], 4844 - [Status.Unauthorized, "Unauthorized"], 4845 - [Status.PaymentRequired, "Payment Required"], 4846 - [Status.Forbidden, "Forbidden"], 4847 - [Status.NotFound, "Not Found"], 4848 - [Status.MethodNotAllowed, "Method Not Allowed"], 4849 - [Status.NotAcceptable, "Not Acceptable"], 4850 - [Status.ProxyAuthRequired, "Proxy Authentication Required"], 4851 - [Status.RequestTimeout, "Request Timeout"], 4852 - [Status.Conflict, "Conflict"], 4853 - [Status.Gone, "Gone"], 4854 - [Status.LengthRequired, "Length Required"], 4855 - [Status.PreconditionFailed, "Precondition Failed"], 4856 - [Status.RequestEntityTooLarge, "Request Entity Too Large"], 4857 - [Status.RequestURITooLong, "Request URI Too Long"], 4858 - [Status.UnsupportedMediaType, "Unsupported Media Type"], 4859 - [ 4860 - Status.RequestedRangeNotSatisfiable, 4861 - "Requested Range Not Satisfiable", 4862 - ], 4863 - [Status.ExpectationFailed, "Expectation Failed"], 4864 - [Status.Teapot, "I'm a teapot"], 4865 - [Status.MisdirectedRequest, "Misdirected Request"], 4866 - [Status.UnprocessableEntity, "Unprocessable Entity"], 4867 - [Status.Locked, "Locked"], 4868 - [Status.FailedDependency, "Failed Dependency"], 4869 - [Status.TooEarly, "Too Early"], 4870 - [Status.UpgradeRequired, "Upgrade Required"], 4871 - [Status.PreconditionRequired, "Precondition Required"], 4872 - [Status.TooManyRequests, "Too Many Requests"], 4873 - [ 4874 - Status.RequestHeaderFieldsTooLarge, 4875 - "Request Header Fields Too Large", 4876 - ], 4877 - [ 4878 - Status.UnavailableForLegalReasons, 4879 - "Unavailable For Legal Reasons", 4880 - ], 4881 - [Status.InternalServerError, "Internal Server Error"], 4882 - [Status.NotImplemented, "Not Implemented"], 4883 - [Status.BadGateway, "Bad Gateway"], 4884 - [Status.ServiceUnavailable, "Service Unavailable"], 4885 - [Status.GatewayTimeout, "Gateway Timeout"], 4886 - [Status.HTTPVersionNotSupported, "HTTP Version Not Supported"], 4887 - [Status.VariantAlsoNegotiates, "Variant Also Negotiates"], 4888 - [Status.InsufficientStorage, "Insufficient Storage"], 4889 - [Status.LoopDetected, "Loop Detected"], 4890 - [Status.NotExtended, "Not Extended"], 4891 - [ 4892 - Status.NetworkAuthenticationRequired, 4893 - "Network Authentication Required", 4894 - ], 4895 - ]), 4896 - ); 4897 - }, 4898 - }; 4899 - }, 4900 - ); 4901 - System.register( 4902 - "https://deno.land/std@0.56.0/http/_io", 4903 - [ 4904 - "https://deno.land/std@0.56.0/io/bufio", 4905 - "https://deno.land/std@0.56.0/textproto/mod", 4906 - "https://deno.land/std@0.56.0/testing/asserts", 4907 - "https://deno.land/std@0.56.0/encoding/utf8", 4908 - "https://deno.land/std@0.56.0/http/server", 4909 - "https://deno.land/std@0.56.0/http/http_status", 4910 - ], 4911 - function (exports_24, context_24) { 4912 - "use strict"; 4913 - var bufio_ts_1, 4914 - mod_ts_3, 4915 - asserts_ts_4, 4916 - utf8_ts_3, 4917 - server_ts_1, 4918 - http_status_ts_1; 4919 - var __moduleName = context_24 && context_24.id; 4920 - function emptyReader() { 4921 - return { 4922 - read(_) { 4923 - return Promise.resolve(null); 4924 - }, 4925 - }; 4926 - } 4927 - exports_24("emptyReader", emptyReader); 4928 - function bodyReader(contentLength, r) { 4929 - let totalRead = 0; 4930 - let finished = false; 4931 - async function read(buf) { 4932 - if (finished) { 4933 - return null; 4934 - } 4935 - let result; 4936 - const remaining = contentLength - totalRead; 4937 - if (remaining >= buf.byteLength) { 4938 - result = await r.read(buf); 4939 - } else { 4940 - const readBuf = buf.subarray(0, remaining); 4941 - result = await r.read(readBuf); 4942 - } 4943 - if (result !== null) { 4944 - totalRead += result; 4945 - } 4946 - finished = totalRead === contentLength; 4947 - return result; 4948 - } 4949 - return { read }; 4950 - } 4951 - exports_24("bodyReader", bodyReader); 4952 - function chunkedBodyReader(h, r) { 4953 - // Based on https://tools.ietf.org/html/rfc2616#section-19.4.6 4954 - const tp = new mod_ts_3.TextProtoReader(r); 4955 - let finished = false; 4956 - const chunks = []; 4957 - async function read(buf) { 4958 - if (finished) { 4959 - return null; 4960 - } 4961 - const [chunk] = chunks; 4962 - if (chunk) { 4963 - const chunkRemaining = chunk.data.byteLength - chunk.offset; 4964 - const readLength = Math.min(chunkRemaining, buf.byteLength); 4965 - for (let i = 0; i < readLength; i++) { 4966 - buf[i] = chunk.data[chunk.offset + i]; 4967 - } 4968 - chunk.offset += readLength; 4969 - if (chunk.offset === chunk.data.byteLength) { 4970 - chunks.shift(); 4971 - // Consume \r\n; 4972 - if ((await tp.readLine()) === null) { 4973 - throw new Deno.errors.UnexpectedEof(); 4974 - } 4975 - } 4976 - return readLength; 4977 - } 4978 - const line = await tp.readLine(); 4979 - if (line === null) { 4980 - throw new Deno.errors.UnexpectedEof(); 4981 - } 4982 - // TODO: handle chunk extension 4983 - const [chunkSizeString] = line.split(";"); 4984 - const chunkSize = parseInt(chunkSizeString, 16); 4985 - if (Number.isNaN(chunkSize) || chunkSize < 0) { 4986 - throw new Error("Invalid chunk size"); 4987 - } 4988 - if (chunkSize > 0) { 4989 - if (chunkSize > buf.byteLength) { 4990 - let eof = await r.readFull(buf); 4991 - if (eof === null) { 4992 - throw new Deno.errors.UnexpectedEof(); 4993 - } 4994 - const restChunk = new Uint8Array(chunkSize - buf.byteLength); 4995 - eof = await r.readFull(restChunk); 4996 - if (eof === null) { 4997 - throw new Deno.errors.UnexpectedEof(); 4998 - } else { 4999 - chunks.push({ 5000 - offset: 0, 5001 - data: restChunk, 5002 - }); 5003 - } 5004 - return buf.byteLength; 5005 - } else { 5006 - const bufToFill = buf.subarray(0, chunkSize); 5007 - const eof = await r.readFull(bufToFill); 5008 - if (eof === null) { 5009 - throw new Deno.errors.UnexpectedEof(); 5010 - } 5011 - // Consume \r\n 5012 - if ((await tp.readLine()) === null) { 5013 - throw new Deno.errors.UnexpectedEof(); 5014 - } 5015 - return chunkSize; 5016 - } 5017 - } else { 5018 - asserts_ts_4.assert(chunkSize === 0); 5019 - // Consume \r\n 5020 - if ((await r.readLine()) === null) { 5021 - throw new Deno.errors.UnexpectedEof(); 5022 - } 5023 - await readTrailers(h, r); 5024 - finished = true; 5025 - return null; 5026 - } 5027 - } 5028 - return { read }; 5029 - } 5030 - exports_24("chunkedBodyReader", chunkedBodyReader); 5031 - function isProhibidedForTrailer(key) { 5032 - const s = new Set(["transfer-encoding", "content-length", "trailer"]); 5033 - return s.has(key.toLowerCase()); 5034 - } 5035 - /** 5036 - * Read trailer headers from reader and append values to headers. 5037 - * "trailer" field will be deleted. 5038 - * */ 5039 - async function readTrailers(headers, r) { 5040 - const headerKeys = parseTrailer(headers.get("trailer")); 5041 - if (!headerKeys) { 5042 - return; 5043 - } 5044 - const tp = new mod_ts_3.TextProtoReader(r); 5045 - const result = await tp.readMIMEHeader(); 5046 - asserts_ts_4.assert(result !== null, "trailer must be set"); 5047 - for (const [k, v] of result) { 5048 - if (!headerKeys.has(k)) { 5049 - throw new Error("Undeclared trailer field"); 5050 - } 5051 - headerKeys.delete(k); 5052 - headers.append(k, v); 5053 - } 5054 - asserts_ts_4.assert( 5055 - Array.from(headerKeys).length === 0, 5056 - "Missing trailers", 5057 - ); 5058 - headers.delete("trailer"); 5059 - } 5060 - exports_24("readTrailers", readTrailers); 5061 - function parseTrailer(field) { 5062 - if (field == null) { 5063 - return undefined; 5064 - } 5065 - const keys = field.split(",").map((v) => v.trim().toLowerCase()); 5066 - if (keys.length === 0) { 5067 - throw new Error("Empty trailer"); 5068 - } 5069 - for (const key of keys) { 5070 - if (isProhibidedForTrailer(key)) { 5071 - throw new Error(`Prohibited field for trailer`); 5072 - } 5073 - } 5074 - return new Headers(keys.map((key) => [key, ""])); 5075 - } 5076 - async function writeChunkedBody(w, r) { 5077 - const writer = bufio_ts_1.BufWriter.create(w); 5078 - for await (const chunk of Deno.iter(r)) { 5079 - if (chunk.byteLength <= 0) { 5080 - continue; 5081 - } 5082 - const start = utf8_ts_3.encoder.encode( 5083 - `${chunk.byteLength.toString(16)}\r\n`, 5084 - ); 5085 - const end = utf8_ts_3.encoder.encode("\r\n"); 5086 - await writer.write(start); 5087 - await writer.write(chunk); 5088 - await writer.write(end); 5089 - } 5090 - const endChunk = utf8_ts_3.encoder.encode("0\r\n\r\n"); 5091 - await writer.write(endChunk); 5092 - } 5093 - exports_24("writeChunkedBody", writeChunkedBody); 5094 - /** write trailer headers to writer. it mostly should be called after writeResponse */ 5095 - async function writeTrailers(w, headers, trailers) { 5096 - const trailer = headers.get("trailer"); 5097 - if (trailer === null) { 5098 - throw new Error('response headers must have "trailer" header field'); 5099 - } 5100 - const transferEncoding = headers.get("transfer-encoding"); 5101 - if (transferEncoding === null || !transferEncoding.match(/^chunked/)) { 5102 - throw new Error( 5103 - `trailer headers is only allowed for "transfer-encoding: chunked": got "${transferEncoding}"`, 5104 - ); 5105 - } 5106 - const writer = bufio_ts_1.BufWriter.create(w); 5107 - const trailerHeaderFields = trailer 5108 - .split(",") 5109 - .map((s) => s.trim().toLowerCase()); 5110 - for (const f of trailerHeaderFields) { 5111 - asserts_ts_4.assert( 5112 - !isProhibidedForTrailer(f), 5113 - `"${f}" is prohibited for trailer header`, 5114 - ); 5115 - } 5116 - for (const [key, value] of trailers) { 5117 - asserts_ts_4.assert( 5118 - trailerHeaderFields.includes(key), 5119 - `Not trailer header field: ${key}`, 5120 - ); 5121 - await writer.write(utf8_ts_3.encoder.encode(`${key}: ${value}\r\n`)); 5122 - } 5123 - await writer.write(utf8_ts_3.encoder.encode("\r\n")); 5124 - await writer.flush(); 5125 - } 5126 - exports_24("writeTrailers", writeTrailers); 5127 - async function writeResponse(w, r) { 5128 - const protoMajor = 1; 5129 - const protoMinor = 1; 5130 - const statusCode = r.status || 200; 5131 - const statusText = http_status_ts_1.STATUS_TEXT.get(statusCode); 5132 - const writer = bufio_ts_1.BufWriter.create(w); 5133 - if (!statusText) { 5134 - throw new Deno.errors.InvalidData("Bad status code"); 5135 - } 5136 - if (!r.body) { 5137 - r.body = new Uint8Array(); 5138 - } 5139 - if (typeof r.body === "string") { 5140 - r.body = utf8_ts_3.encoder.encode(r.body); 5141 - } 5142 - let out = 5143 - `HTTP/${protoMajor}.${protoMinor} ${statusCode} ${statusText}\r\n`; 5144 - const headers = r.headers ?? new Headers(); 5145 - if (r.body && !headers.get("content-length")) { 5146 - if (r.body instanceof Uint8Array) { 5147 - out += `content-length: ${r.body.byteLength}\r\n`; 5148 - } else if (!headers.get("transfer-encoding")) { 5149 - out += "transfer-encoding: chunked\r\n"; 5150 - } 5151 - } 5152 - for (const [key, value] of headers) { 5153 - out += `${key}: ${value}\r\n`; 5154 - } 5155 - out += `\r\n`; 5156 - const header = utf8_ts_3.encoder.encode(out); 5157 - const n = await writer.write(header); 5158 - asserts_ts_4.assert(n === header.byteLength); 5159 - if (r.body instanceof Uint8Array) { 5160 - const n = await writer.write(r.body); 5161 - asserts_ts_4.assert(n === r.body.byteLength); 5162 - } else if (headers.has("content-length")) { 5163 - const contentLength = headers.get("content-length"); 5164 - asserts_ts_4.assert(contentLength != null); 5165 - const bodyLength = parseInt(contentLength); 5166 - const n = await Deno.copy(r.body, writer); 5167 - asserts_ts_4.assert(n === bodyLength); 5168 - } else { 5169 - await writeChunkedBody(writer, r.body); 5170 - } 5171 - if (r.trailers) { 5172 - const t = await r.trailers(); 5173 - await writeTrailers(writer, headers, t); 5174 - } 5175 - await writer.flush(); 5176 - } 5177 - exports_24("writeResponse", writeResponse); 5178 - /** 5179 - * ParseHTTPVersion parses a HTTP version string. 5180 - * "HTTP/1.0" returns (1, 0). 5181 - * Ported from https://github.com/golang/go/blob/f5c43b9/src/net/http/request.go#L766-L792 5182 - */ 5183 - function parseHTTPVersion(vers) { 5184 - switch (vers) { 5185 - case "HTTP/1.1": 5186 - return [1, 1]; 5187 - case "HTTP/1.0": 5188 - return [1, 0]; 5189 - default: { 5190 - const Big = 1000000; // arbitrary upper bound 5191 - if (!vers.startsWith("HTTP/")) { 5192 - break; 5193 - } 5194 - const dot = vers.indexOf("."); 5195 - if (dot < 0) { 5196 - break; 5197 - } 5198 - const majorStr = vers.substring(vers.indexOf("/") + 1, dot); 5199 - const major = Number(majorStr); 5200 - if (!Number.isInteger(major) || major < 0 || major > Big) { 5201 - break; 5202 - } 5203 - const minorStr = vers.substring(dot + 1); 5204 - const minor = Number(minorStr); 5205 - if (!Number.isInteger(minor) || minor < 0 || minor > Big) { 5206 - break; 5207 - } 5208 - return [major, minor]; 5209 - } 5210 - } 5211 - throw new Error(`malformed HTTP version ${vers}`); 5212 - } 5213 - exports_24("parseHTTPVersion", parseHTTPVersion); 5214 - async function readRequest(conn, bufr) { 5215 - const tp = new mod_ts_3.TextProtoReader(bufr); 5216 - const firstLine = await tp.readLine(); // e.g. GET /index.html HTTP/1.0 5217 - if (firstLine === null) { 5218 - return null; 5219 - } 5220 - const headers = await tp.readMIMEHeader(); 5221 - if (headers === null) { 5222 - throw new Deno.errors.UnexpectedEof(); 5223 - } 5224 - const req = new server_ts_1.ServerRequest(); 5225 - req.conn = conn; 5226 - req.r = bufr; 5227 - [req.method, req.url, req.proto] = firstLine.split(" ", 3); 5228 - [req.protoMinor, req.protoMajor] = parseHTTPVersion(req.proto); 5229 - req.headers = headers; 5230 - fixLength(req); 5231 - return req; 5232 - } 5233 - exports_24("readRequest", readRequest); 5234 - function fixLength(req) { 5235 - const contentLength = req.headers.get("Content-Length"); 5236 - if (contentLength) { 5237 - const arrClen = contentLength.split(","); 5238 - if (arrClen.length > 1) { 5239 - const distinct = [...new Set(arrClen.map((e) => e.trim()))]; 5240 - if (distinct.length > 1) { 5241 - throw Error("cannot contain multiple Content-Length headers"); 5242 - } else { 5243 - req.headers.set("Content-Length", distinct[0]); 5244 - } 5245 - } 5246 - const c = req.headers.get("Content-Length"); 5247 - if (req.method === "HEAD" && c && c !== "0") { 5248 - throw Error("http: method cannot contain a Content-Length"); 5249 - } 5250 - if (c && req.headers.has("transfer-encoding")) { 5251 - // A sender MUST NOT send a Content-Length header field in any message 5252 - // that contains a Transfer-Encoding header field. 5253 - // rfc: https://tools.ietf.org/html/rfc7230#section-3.3.2 5254 - throw new Error( 5255 - "http: Transfer-Encoding and Content-Length cannot be send together", 5256 - ); 5257 - } 5258 - } 5259 - } 5260 - return { 5261 - setters: [ 5262 - function (bufio_ts_1_1) { 5263 - bufio_ts_1 = bufio_ts_1_1; 5264 - }, 5265 - function (mod_ts_3_1) { 5266 - mod_ts_3 = mod_ts_3_1; 5267 - }, 5268 - function (asserts_ts_4_1) { 5269 - asserts_ts_4 = asserts_ts_4_1; 5270 - }, 5271 - function (utf8_ts_3_1) { 5272 - utf8_ts_3 = utf8_ts_3_1; 5273 - }, 5274 - function (server_ts_1_1) { 5275 - server_ts_1 = server_ts_1_1; 5276 - }, 5277 - function (http_status_ts_1_1) { 5278 - http_status_ts_1 = http_status_ts_1_1; 5279 - }, 5280 - ], 5281 - execute: function () { 5282 - }, 5283 - }; 5284 - }, 5285 - ); 5286 - System.register( 5287 - "https://deno.land/std@0.56.0/http/server", 5288 - [ 5289 - "https://deno.land/std@0.56.0/encoding/utf8", 5290 - "https://deno.land/std@0.56.0/io/bufio", 5291 - "https://deno.land/std@0.56.0/testing/asserts", 5292 - "https://deno.land/std@0.56.0/async/mod", 5293 - "https://deno.land/std@0.56.0/http/_io", 5294 - ], 5295 - function (exports_25, context_25) { 5296 - "use strict"; 5297 - var utf8_ts_4, 5298 - bufio_ts_2, 5299 - asserts_ts_5, 5300 - mod_ts_4, 5301 - _io_ts_1, 5302 - listen, 5303 - listenTls, 5304 - ServerRequest, 5305 - Server; 5306 - var __moduleName = context_25 && context_25.id; 5307 - /** 5308 - * Create a HTTP server 5309 - * 5310 - * import { serve } from "https://deno.land/std/http/server.ts"; 5311 - * const body = "Hello World\n"; 5312 - * const server = serve({ port: 8000 }); 5313 - * for await (const req of server) { 5314 - * req.respond({ body }); 5315 - * } 5316 - */ 5317 - function serve(addr) { 5318 - if (typeof addr === "string") { 5319 - const [hostname, port] = addr.split(":"); 5320 - addr = { hostname, port: Number(port) }; 5321 - } 5322 - const listener = listen(addr); 5323 - return new Server(listener); 5324 - } 5325 - exports_25("serve", serve); 5326 - /** 5327 - * Start an HTTP server with given options and request handler 5328 - * 5329 - * const body = "Hello World\n"; 5330 - * const options = { port: 8000 }; 5331 - * listenAndServe(options, (req) => { 5332 - * req.respond({ body }); 5333 - * }); 5334 - * 5335 - * @param options Server configuration 5336 - * @param handler Request handler 5337 - */ 5338 - async function listenAndServe(addr, handler) { 5339 - const server = serve(addr); 5340 - for await (const request of server) { 5341 - handler(request); 5342 - } 5343 - } 5344 - exports_25("listenAndServe", listenAndServe); 5345 - /** 5346 - * Create an HTTPS server with given options 5347 - * 5348 - * const body = "Hello HTTPS"; 5349 - * const options = { 5350 - * hostname: "localhost", 5351 - * port: 443, 5352 - * certFile: "./path/to/localhost.crt", 5353 - * keyFile: "./path/to/localhost.key", 5354 - * }; 5355 - * for await (const req of serveTLS(options)) { 5356 - * req.respond({ body }); 5357 - * } 5358 - * 5359 - * @param options Server configuration 5360 - * @return Async iterable server instance for incoming requests 5361 - */ 5362 - function serveTLS(options) { 5363 - const tlsOptions = { 5364 - ...options, 5365 - transport: "tcp", 5366 - }; 5367 - const listener = listenTls(tlsOptions); 5368 - return new Server(listener); 5369 - } 5370 - exports_25("serveTLS", serveTLS); 5371 - /** 5372 - * Start an HTTPS server with given options and request handler 5373 - * 5374 - * const body = "Hello HTTPS"; 5375 - * const options = { 5376 - * hostname: "localhost", 5377 - * port: 443, 5378 - * certFile: "./path/to/localhost.crt", 5379 - * keyFile: "./path/to/localhost.key", 5380 - * }; 5381 - * listenAndServeTLS(options, (req) => { 5382 - * req.respond({ body }); 5383 - * }); 5384 - * 5385 - * @param options Server configuration 5386 - * @param handler Request handler 5387 - */ 5388 - async function listenAndServeTLS(options, handler) { 5389 - const server = serveTLS(options); 5390 - for await (const request of server) { 5391 - handler(request); 5392 - } 5393 - } 5394 - exports_25("listenAndServeTLS", listenAndServeTLS); 5395 - return { 5396 - setters: [ 5397 - function (utf8_ts_4_1) { 5398 - utf8_ts_4 = utf8_ts_4_1; 5399 - }, 5400 - function (bufio_ts_2_1) { 5401 - bufio_ts_2 = bufio_ts_2_1; 5402 - }, 5403 - function (asserts_ts_5_1) { 5404 - asserts_ts_5 = asserts_ts_5_1; 5405 - }, 5406 - function (mod_ts_4_1) { 5407 - mod_ts_4 = mod_ts_4_1; 5408 - }, 5409 - function (_io_ts_1_1) { 5410 - _io_ts_1 = _io_ts_1_1; 5411 - }, 5412 - ], 5413 - execute: function () { 5414 - listen = Deno.listen, listenTls = Deno.listenTls; 5415 - ServerRequest = class ServerRequest { 5416 - constructor() { 5417 - this.done = mod_ts_4.deferred(); 5418 - this._contentLength = undefined; 5419 - this._body = null; 5420 - this.finalized = false; 5421 - } 5422 - /** 5423 - * Value of Content-Length header. 5424 - * If null, then content length is invalid or not given (e.g. chunked encoding). 5425 - */ 5426 - get contentLength() { 5427 - // undefined means not cached. 5428 - // null means invalid or not provided. 5429 - if (this._contentLength === undefined) { 5430 - const cl = this.headers.get("content-length"); 5431 - if (cl) { 5432 - this._contentLength = parseInt(cl); 5433 - // Convert NaN to null (as NaN harder to test) 5434 - if (Number.isNaN(this._contentLength)) { 5435 - this._contentLength = null; 5436 - } 5437 - } else { 5438 - this._contentLength = null; 5439 - } 5440 - } 5441 - return this._contentLength; 5442 - } 5443 - /** 5444 - * Body of the request. The easiest way to consume the body is: 5445 - * 5446 - * const buf: Uint8Array = await Deno.readAll(req.body); 5447 - */ 5448 - get body() { 5449 - if (!this._body) { 5450 - if (this.contentLength != null) { 5451 - this._body = _io_ts_1.bodyReader(this.contentLength, this.r); 5452 - } else { 5453 - const transferEncoding = this.headers.get("transfer-encoding"); 5454 - if (transferEncoding != null) { 5455 - const parts = transferEncoding 5456 - .split(",") 5457 - .map((e) => e.trim().toLowerCase()); 5458 - asserts_ts_5.assert( 5459 - parts.includes("chunked"), 5460 - 'transfer-encoding must include "chunked" if content-length is not set', 5461 - ); 5462 - this._body = _io_ts_1.chunkedBodyReader(this.headers, this.r); 5463 - } else { 5464 - // Neither content-length nor transfer-encoding: chunked 5465 - this._body = _io_ts_1.emptyReader(); 5466 - } 5467 - } 5468 - } 5469 - return this._body; 5470 - } 5471 - async respond(r) { 5472 - let err; 5473 - try { 5474 - // Write our response! 5475 - await _io_ts_1.writeResponse(this.w, r); 5476 - } catch (e) { 5477 - try { 5478 - // Eagerly close on error. 5479 - this.conn.close(); 5480 - } catch {} 5481 - err = e; 5482 - } 5483 - // Signal that this request has been processed and the next pipelined 5484 - // request on the same connection can be accepted. 5485 - this.done.resolve(err); 5486 - if (err) { 5487 - // Error during responding, rethrow. 5488 - throw err; 5489 - } 5490 - } 5491 - async finalize() { 5492 - if (this.finalized) { 5493 - return; 5494 - } 5495 - // Consume unread body 5496 - const body = this.body; 5497 - const buf = new Uint8Array(1024); 5498 - while ((await body.read(buf)) !== null) {} 5499 - this.finalized = true; 5500 - } 5501 - }; 5502 - exports_25("ServerRequest", ServerRequest); 5503 - Server = class Server { 5504 - constructor(listener) { 5505 - this.listener = listener; 5506 - this.closing = false; 5507 - this.connections = []; 5508 - } 5509 - close() { 5510 - this.closing = true; 5511 - this.listener.close(); 5512 - for (const conn of this.connections) { 5513 - try { 5514 - conn.close(); 5515 - } catch (e) { 5516 - // Connection might have been already closed 5517 - if (!(e instanceof Deno.errors.BadResource)) { 5518 - throw e; 5519 - } 5520 - } 5521 - } 5522 - } 5523 - // Yields all HTTP requests on a single TCP connection. 5524 - async *iterateHttpRequests(conn) { 5525 - const reader = new bufio_ts_2.BufReader(conn); 5526 - const writer = new bufio_ts_2.BufWriter(conn); 5527 - while (!this.closing) { 5528 - let request; 5529 - try { 5530 - request = await _io_ts_1.readRequest(conn, reader); 5531 - } catch (error) { 5532 - if ( 5533 - error instanceof Deno.errors.InvalidData || 5534 - error instanceof Deno.errors.UnexpectedEof 5535 - ) { 5536 - // An error was thrown while parsing request headers. 5537 - await _io_ts_1.writeResponse(writer, { 5538 - status: 400, 5539 - body: utf8_ts_4.encode(`${error.message}\r\n\r\n`), 5540 - }); 5541 - } 5542 - break; 5543 - } 5544 - if (request === null) { 5545 - break; 5546 - } 5547 - request.w = writer; 5548 - yield request; 5549 - // Wait for the request to be processed before we accept a new request on 5550 - // this connection. 5551 - const responseError = await request.done; 5552 - if (responseError) { 5553 - // Something bad happened during response. 5554 - // (likely other side closed during pipelined req) 5555 - // req.done implies this connection already closed, so we can just return. 5556 - this.untrackConnection(request.conn); 5557 - return; 5558 - } 5559 - // Consume unread body and trailers if receiver didn't consume those data 5560 - await request.finalize(); 5561 - } 5562 - this.untrackConnection(conn); 5563 - try { 5564 - conn.close(); 5565 - } catch (e) { 5566 - // might have been already closed 5567 - } 5568 - } 5569 - trackConnection(conn) { 5570 - this.connections.push(conn); 5571 - } 5572 - untrackConnection(conn) { 5573 - const index = this.connections.indexOf(conn); 5574 - if (index !== -1) { 5575 - this.connections.splice(index, 1); 5576 - } 5577 - } 5578 - // Accepts a new TCP connection and yields all HTTP requests that arrive on 5579 - // it. When a connection is accepted, it also creates a new iterator of the 5580 - // same kind and adds it to the request multiplexer so that another TCP 5581 - // connection can be accepted. 5582 - async *acceptConnAndIterateHttpRequests(mux) { 5583 - if (this.closing) { 5584 - return; 5585 - } 5586 - // Wait for a new connection. 5587 - let conn; 5588 - try { 5589 - conn = await this.listener.accept(); 5590 - } catch (error) { 5591 - if (error instanceof Deno.errors.BadResource) { 5592 - return; 5593 - } 5594 - throw error; 5595 - } 5596 - this.trackConnection(conn); 5597 - // Try to accept another connection and add it to the multiplexer. 5598 - mux.add(this.acceptConnAndIterateHttpRequests(mux)); 5599 - // Yield the requests that arrive on the just-accepted connection. 5600 - yield* this.iterateHttpRequests(conn); 5601 - } 5602 - [Symbol.asyncIterator]() { 5603 - const mux = new mod_ts_4.MuxAsyncIterator(); 5604 - mux.add(this.acceptConnAndIterateHttpRequests(mux)); 5605 - return mux.iterate(); 5606 - } 5607 - }; 5608 - exports_25("Server", Server); 5609 - }, 5610 - }; 5611 - }, 5612 - ); 5613 - System.register( 5614 - "file:///home/kou029w/deno-example/server", 5615 - ["https://deno.land/std@0.56.0/http/server"], 5616 - function (exports_26, context_26) { 5617 - "use strict"; 5618 - var server_ts_2; 5619 - var __moduleName = context_26 && context_26.id; 5620 - async function main() { 5621 - const port = 8000; 5622 - console.log(`http://localhost:${port}/`); 5623 - for await (const req of server_ts_2.serve({ port })) { 5624 - req.respond({ body: "Hello World\n" }); 5625 - } 5626 - } 5627 - return { 5628 - setters: [ 5629 - function (server_ts_2_1) { 5630 - server_ts_2 = server_ts_2_1; 5631 - }, 5632 - ], 5633 - execute: function () { 5634 - main(); 5635 - }, 5636 - }; 5637 - }, 5638 - ); 5639 - 5640 - __instantiate("file:///home/kou029w/deno-example/server");
-10
deno/server.ts
··· 1 - import { serve } from "https://deno.land/std@0.56.0/http/server.ts"; 2 - 3 - async function main() { 4 - const port = 8000; 5 - console.log(`http://localhost:${port}/`); 6 - for await (const req of serve({ port })) { 7 - req.respond({ body: "Hello World\n" }); 8 - } 9 - } 10 - main();