Skip to content

Commit 2bfcade

Browse files
committed
incorporate ncc into main existing workflows
1 parent e4d63f7 commit 2bfcade

File tree

7 files changed

+102455
-1118
lines changed

7 files changed

+102455
-1118
lines changed

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
SHELL := /bin/bash
55
SRC_DIR := src
66
BUILD_DIR := lib
7-
ENTRY_POINT := $(SRC_DIR)/index.ts
7+
ENTRY_POINT := $(SRC_DIR)/main.ts
88

99
# Binaries
1010
TS_NODE := ./node_modules/.bin/ts-node
1111
TS_C := ./node_modules/.bin/tsc
1212
ESLINT := ./node_modules/.bin/eslint
1313
PRETTIER := ./node_modules/.bin/prettier
14+
NCC := ./node_modules/.bin/ncc
1415

1516
# Targets
1617
.PHONY: all clean install build format
@@ -25,6 +26,12 @@ clean:
2526
install:
2627
npm install
2728

29+
dev:
30+
npm install --save-dev
31+
32+
prepare:
33+
$(NCC) build $(ENTRY_POINT) -o $(BUILD_DIR)
34+
2835
# Build the TypeScript code
2936
build: clean
3037
$(TS_C) --outDir $(BUILD_DIR) --rootDir $(SRC_DIR)

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ branding:
5252
color: "green"
5353
runs:
5454
using: "node20"
55-
main: "dist/index.js"
55+
main: "lib/index.js"

dist/index.js

Lines changed: 1451 additions & 1115 deletions
Large diffs are not rendered by default.

lib/index.js

Lines changed: 100939 additions & 0 deletions
Large diffs are not rendered by default.

lib/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "module"
3+
}

lib/thread.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import fs from 'node:fs';
2+
import crypto from 'node:crypto';
3+
import {parentPort} from 'node:worker_threads';
4+
5+
const handlers = {
6+
hashFile: (algorithm, filePath) => new Promise((resolve, reject) => {
7+
const hasher = crypto.createHash(algorithm);
8+
fs.createReadStream(filePath)
9+
// TODO: Use `Stream.pipeline`.
10+
.on('error', reject)
11+
.pipe(hasher)
12+
.on('error', reject)
13+
.on('finish', () => {
14+
const {buffer} = new Uint8Array(hasher.read());
15+
resolve({value: buffer, transferList: [buffer]});
16+
});
17+
}),
18+
async hash(algorithm, input) {
19+
const hasher = crypto.createHash(algorithm);
20+
21+
for (const part of [input].flat()) {
22+
hasher.update(part);
23+
}
24+
25+
const {buffer} = new Uint8Array(hasher.digest());
26+
return {value: buffer, transferList: [buffer]};
27+
},
28+
};
29+
30+
parentPort.on('message', async message => {
31+
try {
32+
const {method, arguments_} = message;
33+
const handler = handlers[method];
34+
35+
if (handler === undefined) {
36+
throw new Error(`Unknown method '${method}'`);
37+
}
38+
39+
const {value, transferList} = await handler(...arguments_);
40+
parentPort.postMessage({id: message.id, value}, transferList);
41+
} catch (error) {
42+
const newError = {message: error.message, stack: error.stack};
43+
44+
for (const [key, value] of Object.entries(error)) {
45+
if (typeof value !== 'object') {
46+
newError[key] = value;
47+
}
48+
}
49+
50+
parentPort.postMessage({id: message.id, error: newError});
51+
}
52+
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"type": "module",
66
"description": "Install a GitHub release binary in a GitHub Actions build environment",
7-
"main": "dist/index.js",
7+
"main": "lib/index.js",
88
"scripts": {
99
"build": "ncc build src/main.ts"
1010
},

0 commit comments

Comments
 (0)