-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove es-git and use node.js streams (#2)
- Loading branch information
1 parent
f18bd0f
commit 48f2d44
Showing
52 changed files
with
12,879 additions
and
599 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# @rollingversions/git-core | ||
|
||
Forked from https://github.com/mariusGundersen/es-git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "@rollingversions/git-core", | ||
"version": "0.0.0", | ||
"main": "dist/index.cjs", | ||
"module": "dist/index.mjs", | ||
"types": "lib/index.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.mjs", | ||
"default": "./dist/index.cjs" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"files": [ | ||
"dist/", | ||
"lib/" | ||
], | ||
"scripts": { | ||
"build": "tsc" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": {}, | ||
"peerDependencies": {}, | ||
"engines": { | ||
"node": ">=14.0.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"license": "MIT" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
exports = 'named' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
export { | ||
decode, | ||
encode, | ||
concat, | ||
fromDec, | ||
fromHex, | ||
fromOct, | ||
fromDecChar, | ||
fromHexChar, | ||
toHexChar, | ||
NEWLINE, | ||
} from './utils'; | ||
|
||
export enum Mask { | ||
mask = 0o100000, | ||
blob = 0o140000, | ||
file = 0o160000, | ||
} | ||
|
||
export enum Mode { | ||
tree = 0o040000, | ||
blob = 0o100644, | ||
file = 0o100644, | ||
exec = 0o100755, | ||
sym = 0o120000, | ||
commit = 0o160000, | ||
} | ||
|
||
export enum Type { | ||
unknown = 'unknown', | ||
commit = 'commit', | ||
tree = 'tree', | ||
blob = 'blob', | ||
tag = 'tag', | ||
} | ||
|
||
export function isBlob(mode: number) { | ||
return (mode & Mask.blob) === Mask.mask; | ||
} | ||
|
||
export function isFile(mode: number) { | ||
return (mode & Mask.file) === Mask.mask; | ||
} | ||
|
||
export function toType(mode: number) { | ||
if (mode === Mode.commit) return Type.commit; | ||
if (mode === Mode.tree) return Type.tree; | ||
if ((mode & Mask.blob) === Mask.mask) return Type.blob; | ||
return Type.unknown; | ||
} | ||
|
||
export type Hash = string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {toHexChar} from './utils'; | ||
|
||
for (const [num, hexChar] of [ | ||
[0, '0'], | ||
[1, '1'], | ||
[9, '9'], | ||
[10, 'a'], | ||
[15, 'f'], | ||
] as const) { | ||
test(`toHexChar(${num}) => ${hexChar}`, () => { | ||
expect(String.fromCharCode(toHexChar(num))).toBe(hexChar); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const encoder = new TextEncoder(); | ||
const decoder = new TextDecoder(); | ||
|
||
export const NEWLINE = '\n'.charCodeAt(0); | ||
|
||
export function encode(text: string) { | ||
return encoder.encode(text); | ||
} | ||
|
||
export function decode(binary: Uint8Array, start = 0, end = binary.length) { | ||
if (start !== 0 || end !== binary.length) { | ||
return decoder.decode(binary.subarray(start, end)); | ||
} else { | ||
return decoder.decode(binary); | ||
} | ||
} | ||
|
||
export function concat(...arrays: (Uint8Array | number[])[]): Uint8Array { | ||
const totalLength = arrays.reduce((sum, arr) => sum + arr.length, 0); | ||
const result = new Uint8Array(totalLength); | ||
let offset = 0; | ||
for (const arr of arrays) { | ||
result.set(arr, offset); | ||
offset += arr.length; | ||
} | ||
return result; | ||
} | ||
|
||
export function fromHex(binary: Uint8Array) { | ||
let size = 0; | ||
for (let i = 0; i < 4; i++) { | ||
size = (size << 4) | fromHexChar(binary[i]); | ||
} | ||
return size; | ||
} | ||
|
||
export function fromHexChar(val: number) { | ||
return val < 0x57 ? val - 0x30 : val - 0x57; | ||
} | ||
|
||
export function fromDec(buffer: Uint8Array, start: number, end: number) { | ||
let val = 0; | ||
while (start < end) { | ||
val = val * 10 + fromDecChar(buffer[start++]); | ||
} | ||
return val; | ||
} | ||
|
||
export function fromDecChar(val: number) { | ||
return val - 0x30; | ||
} | ||
|
||
export function fromOct( | ||
buffer: Uint8Array, | ||
start: number, | ||
end: number, | ||
): number { | ||
let val = 0; | ||
while (start < end) { | ||
val = (val << 3) + fromDecChar(buffer[start++]); | ||
} | ||
return val; | ||
} | ||
|
||
export function toHexChar(val: number) { | ||
return val < 10 ? val + 0x30 : val + 0x57; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "@forbeslindesay/tsconfig", | ||
"compilerOptions": { | ||
"outDir": "lib", | ||
"module": "ES2020", | ||
"incremental": true, | ||
"composite": true, | ||
"rootDir": "src", | ||
"tsBuildInfoFile": "lib/.tsbuildinfo", | ||
"lib": ["DOM", "ES2020"] | ||
}, | ||
"include": ["src"], | ||
"references": [], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
export interface HttpResponse { | ||
url: URL; | ||
statusCode: number; | ||
body: NodeJS.ReadableStream; | ||
} | ||
export default interface HttpInterface< | ||
THeaders extends {set(name: string, value: string): unknown} | ||
> { | ||
createHeaders(url: URL): THeaders; | ||
get(url: URL, headers: THeaders): AsyncIterableIterator<Uint8Array>; | ||
get(url: URL, headers: THeaders): Promise<HttpResponse>; | ||
post( | ||
url: URL, | ||
headers: THeaders, | ||
body: AsyncIterableIterator<Uint8Array>, | ||
): AsyncIterableIterator<Uint8Array>; | ||
body: NodeJS.ReadableStream, | ||
): Promise<HttpResponse>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.