Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 19 additions & 67 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ permissions:
contents: read

jobs:
build:
name: Build libllhttp.a
ci:
name: Build, Test and Lint
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -29,90 +29,42 @@ jobs:
# Scoop modifies the PATH so we make the modified PATH global.
echo $env:PATH >> $env:GITHUB_PATH

- name: Fetch code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20.18.0

- name: Setup Docker
uses: docker/setup-buildx-action@v1
if: runner.os == 'Linux'

- name: Fetch
uses: actions/checkout@v4
with:
fetch-depth: 1

# Skip macOS & Windows, cache there is slower
- name: Restore node_modules cache for Linux
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
if: runner.os == 'Linux'
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-

- name: Install dependencies
run: npm ci --ignore-scripts
run: npm ci

- name: Build libllhttp.a
shell: bash
run: |
make build/libllhttp.a

test:
name: Run tests
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- macos-latest
- ubuntu-latest
- windows-latest
steps:
- name: Install clang for Windows
if: runner.os == 'Windows'
run: |
iwr -useb get.scoop.sh -outfile 'install.ps1'
.\install.ps1 -RunAsAdmin
scoop install llvm --global

# Scoop modifies the PATH so we make the modified PATH global.
echo $env:PATH >> $env:GITHUB_PATH

- name: Fetch code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 1

# Skip macOS & Windows, cache there is slower
- name: Restore node_modules cache for Linux
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
- name: Build WebAssembly
run: npm run build-wasm
if: runner.os == 'Linux'
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-

- name: Install dependencies
run: npm ci --ignore-scripts

# Custom script, because progress looks not good in CI
- name: Run tests
run: npm run test

lint:
name: Run ESLint
runs-on: ubuntu-latest
steps:
- name: Fetch code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 1

- name: Restore node_modules cache
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-

- name: Install dependencies
run: npm ci --ignore-scripts

- name: Run lint command
- name: Lint Code
run: npm run lint
if: runner.os == 'Linux'
10 changes: 6 additions & 4 deletions bench/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @stylistic/max-len */

import assert from "assert";
import { spawnSync } from "child_process";
import { existsSync } from "fs";
Expand Down Expand Up @@ -54,18 +56,18 @@ if (process.argv[2] === "loop") {
const request = httpRequests[reqName]!;

assert(request, `Unknown request name: "${reqName}"`);
spawnSync(httpExecutable, ["loop", request], { stdio: "inherit" });
spawnSync(httpExecutable, [ "loop", request ], { stdio: "inherit" });
process.exit(0);
}

if (!process.argv[2] || process.argv[2] === "url") {
console.log("url (C)");
spawnSync(urlExecutable, ["bench", urlRequest], { stdio: "inherit" });
spawnSync(urlExecutable, [ "bench", urlRequest ], { stdio: "inherit" });
}

if (!process.argv[2] || process.argv[2] === "http") {
for (const [name, request] of Object.entries(httpRequests)) {
for (const [ name, request ] of Object.entries(httpRequests)) {
console.log('http: "%s" (C)', name);
spawnSync(httpExecutable, ["bench", request], { stdio: "inherit" });
spawnSync(httpExecutable, [ "bench", request ], { stdio: "inherit" });
}
}
2 changes: 1 addition & 1 deletion bin/build_wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if (process.argv[2] === '--setup') {
}

if (process.argv[2] === '--docker') {
let cmd = `docker run --rm -it --platform=${platform.toString().trim()}`;
let cmd = `docker run --rm --platform=${platform.toString().trim()}`;
// Try to avoid root permission problems on compiled assets
// when running on linux.
// It will work flawessly if uid === gid === 1000
Expand Down
2 changes: 1 addition & 1 deletion bin/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { dirname, resolve } from 'path';
import { CHeaders, HTTP } from '../src/llhttp';

// https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
// eslint-disable-next-line @stylistic/js/max-len
// eslint-disable-next-line @stylistic/max-len
const semverRE = /^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;

const C_FILE = resolve(__dirname, '../build/c/llhttp.c');
Expand Down
95 changes: 41 additions & 54 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,66 +1,53 @@
import stylisticJs from '@stylistic/eslint-plugin-js'
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import globals from 'globals';
// @ts-check

import eslint from "@eslint/js";
import tseslint from "typescript-eslint";
import stylistic from "@stylistic/eslint-plugin";

export default tseslint.config(
{ ignores: ["build", "lib", "examples", "bench"] },
eslint.configs.recommended,
...tseslint.configs.recommended,
...tseslint.configs.stylistic,
{
"languageOptions": {
"parser": tseslint.parser,
"parserOptions": {
"lib": ["es2023"],
"module": "commonjs",
"moduleResolution": "node",
"target": "es2022",

"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"include": [
"bin/**/*.ts",
"src/**/*.ts",
"test/**/*.ts"
],
"outDir": "./lib",
"declaration": true,
"pretty": true,
"sourceMap": true
},
"globals": {
...globals.commonjs,
...globals.node,
...globals.es6
},
},
ignores: ["build", "lib"],
},
{
plugins: {
'@stylistic/js': stylisticJs
},
files: [
"bin/**/*.ts",
'bench/**/*.ts',
'src/**/*.ts',
'test/**/*.ts',
],
"bench/**/*.ts",
"src/**/*.ts",
"test/**/*.ts",
"eslint.config.js",
],
plugins: {
"@stylistic": stylistic,
},
languageOptions: {
parser: tseslint.parser,
parserOptions: {
project: "./tsconfig.test.json",
},
},
rules: {
'@stylistic/js/max-len': [ 2, {
'code': 120,
'ignoreComments': true
} ],
"@stylistic/js/array-bracket-spacing": ["error", "always"],
"@stylistic/js/operator-linebreak": ["error", "after"],
"@stylistic/js/linebreak-style": ["error", "unix"],
"@stylistic/js/brace-style": ["error", "1tbs", { "allowSingleLine": true }],
'@stylistic/js/indent': ["error", 2, {
"SwitchCase": 1,
"FunctionDeclaration": { "parameters": "first" },
"FunctionExpression": { "parameters": "first" }
}],
}
"@stylistic/max-len": [
2,
{
code: 120,
ignoreComments: true,
},
],
"@stylistic/array-bracket-spacing": ["error", "always"],
"@stylistic/operator-linebreak": ["error", "after"],
"@stylistic/linebreak-style": ["error", "unix"],
"@stylistic/brace-style": ["error", "1tbs", { allowSingleLine: true }],
"@stylistic/indent": [
"error",
2,
{
SwitchCase: 1,
FunctionDeclaration: { parameters: "first" },
FunctionExpression: { parameters: "first" },
},
],
},
}
);
4 changes: 3 additions & 1 deletion examples/wasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const inst = new WebAssembly.Instance(mod, {
},
});

const memory = inst.exports.memory as any;
const memory = inst.exports.memory as WebAssembly.Memory;
const alloc = inst.exports.llhttp_alloc as CallableFunction;
const malloc = inst.exports.malloc as CallableFunction;
const execute = inst.exports.llhttp_execute as CallableFunction;
Expand Down Expand Up @@ -171,12 +171,14 @@ class HTTPParser {
return 0;
}

/* eslint-disable @typescript-eslint/no-unused-vars */
[kOnHeaders](rawHeaders: [string]) {}

[kOnHeadersComplete](versionMajor: number, versionMinor: number, rawHeaders: [string], method: string,
url: string, statusCode: number, statusMessage: string, upgrade: boolean, shouldKeepAlive: boolean) {
return 0;
}
/* eslint-enable @typescript-eslint/no-unused-vars */

[kOnBody](body: Buffer) {
this[kBody] = body;
Expand Down
Loading
Loading