Skip to content

Commit

Permalink
fix(ci): vendor deno for builds (#3020)
Browse files Browse the repository at this point in the history
add deno source files (vendor them) for more reproducible builds. these
files are being committed to the repo to help stabilize the CI process,
which as been failing for 24 hours.

the stencil team still considers deno to be experimental, this commit
does not mean to imply further development on deno support

STENCIL-87: Resolve CI failing due to Deno
  • Loading branch information
rwaskiewicz committed Aug 24, 2021
1 parent 925d4e9 commit 6d8a61d
Show file tree
Hide file tree
Showing 63 changed files with 8,672 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ coverage/

/build/
/scripts/build/
!/scripts/build/deno-cache
dist/

# submodule packages
Expand Down
15 changes: 15 additions & 0 deletions scripts/build/deno-cache/deno_land_std_0_63_0__util_assert_ts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.

export class DenoStdInternalError extends Error {
constructor(message: string) {
super(message);
this.name = "DenoStdInternalError";
}
}

/** Make an assertion, if not `true`, then throw. */
export function assert(expr: unknown, msg = ""): asserts expr {
if (!expr) {
throw new DenoStdInternalError(msg);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.

/**
* Converts given data with base64 encoding
* @param data input to encode
*/
export function encode(data: string | ArrayBuffer): string {
if (typeof data === "string") {
return btoa(data);
} else {
const d = new Uint8Array(data);
let dataString = "";
for (let i = 0; i < d.length; ++i) {
dataString += String.fromCharCode(d[i]);
}

return btoa(dataString);
}
}

/**
* Converts given base64 encoded data back to original
* @param data input to decode
*/
export function decode(data: string): ArrayBuffer {
const binaryString = decodeString(data);
const binary = new Uint8Array(binaryString.length);
for (let i = 0; i < binary.length; ++i) {
binary[i] = binaryString.charCodeAt(i);
}

return binary.buffer;
}

/**
* Decodes data assuming the output is in string type
* @param data input to decode
*/
export function decodeString(data: string): string {
return atob(data);
}
106 changes: 106 additions & 0 deletions scripts/build/deno-cache/deno_land_std_0_63_0_encoding_hex_ts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// Ported from Go
// https://github.com/golang/go/blob/go1.12.5/src/encoding/hex/hex.go
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.

const hextable = new TextEncoder().encode("0123456789abcdef");

export function errInvalidByte(byte: number): Error {
return new Error(
"encoding/hex: invalid byte: " +
new TextDecoder().decode(new Uint8Array([byte])),
);
}

export function errLength(): Error {
return new Error("encoding/hex: odd length hex string");
}

// fromHexChar converts a hex character into its value.
function fromHexChar(byte: number): number {
// '0' <= byte && byte <= '9'
if (48 <= byte && byte <= 57) return byte - 48;
// 'a' <= byte && byte <= 'f'
if (97 <= byte && byte <= 102) return byte - 97 + 10;
// 'A' <= byte && byte <= 'F'
if (65 <= byte && byte <= 70) return byte - 65 + 10;

throw errInvalidByte(byte);
}

/**
* EncodedLen returns the length of an encoding of n source bytes. Specifically,
* it returns n * 2.
* @param n
*/
export function encodedLen(n: number): number {
return n * 2;
}

/**
* Encode encodes `src` into `encodedLen(src.length)` bytes.
* @param src
*/
export function encode(src: Uint8Array): Uint8Array {
const dst = new Uint8Array(encodedLen(src.length));
for (let i = 0; i < dst.length; i++) {
const v = src[i];
dst[i * 2] = hextable[v >> 4];
dst[i * 2 + 1] = hextable[v & 0x0f];
}
return dst;
}

/**
* EncodeToString returns the hexadecimal encoding of `src`.
* @param src
*/
export function encodeToString(src: Uint8Array): string {
return new TextDecoder().decode(encode(src));
}

/**
* Decode decodes `src` into `decodedLen(src.length)` bytes
* If the input is malformed an error will be thrown
* the error.
* @param src
*/
export function decode(src: Uint8Array): Uint8Array {
const dst = new Uint8Array(decodedLen(src.length));
for (let i = 0; i < dst.length; i++) {
const a = fromHexChar(src[i * 2]);
const b = fromHexChar(src[i * 2 + 1]);
dst[i] = (a << 4) | b;
}

if (src.length % 2 == 1) {
// Check for invalid char before reporting bad length,
// since the invalid char (if present) is an earlier problem.
fromHexChar(src[dst.length * 2]);
throw errLength();
}

return dst;
}

/**
* DecodedLen returns the length of decoding `x` source bytes.
* Specifically, it returns `x / 2`.
* @param x
*/
export function decodedLen(x: number): number {
return x >>> 1;
}

/**
* DecodeString returns the bytes represented by the hexadecimal string `s`.
* DecodeString expects that src contains only hexadecimal characters and that
* src has even length.
* If the input is malformed, DecodeString will throw an error.
* @param s the `string` to decode to `Uint8Array`
*/
export function decodeString(s: string): Uint8Array {
return decode(new TextEncoder().encode(s));
}
Loading

0 comments on commit 6d8a61d

Please sign in to comment.