Skip to content

Commit

Permalink
Merge branch 'main' into remove-eol-node-versions
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfy1339 authored Jun 9, 2023
2 parents 81a1e11 + 87a3f99 commit 691c3a8
Show file tree
Hide file tree
Showing 8 changed files with 14,274 additions and 3,444 deletions.
17,565 changes: 14,155 additions & 3,410 deletions package-lock.json

Large diffs are not rendered by default.

44 changes: 14 additions & 30 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"version": "0.0.0-development",
"description": "Methods to handle GitHub Webhook requests",
"scripts": {
"build": "pika-pack build",
"lint": "prettier --check '{src,test}/**/*' README.md package.json",
"lint:fix": "prettier --write '{src,test}/**/*' README.md package.json",
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
"lint": "prettier --check '{src,test,scripts}/**/*' README.md package.json",
"lint:fix": "prettier --write '{src,test,scripts}/**/*' README.md package.json",
"pretest": "npm run -s lint",
"test": "npm run -s test:node && npm run -s test:web",
"test:node": "jest --coverage",
Expand All @@ -26,18 +26,12 @@
],
"author": "Gregor Martynus (https://dev.to/gr2m)",
"license": "MIT",
"browser": {
"./pkg/dist-src/index.js": "./pkg/dist-src/web.js"
},
"dependencies": {},
"devDependencies": {
"@gr2m/pika-plugin-build-web": "^0.6.0-issue-84.2",
"@octokit/tsconfig": "^1.0.2",
"@pika/pack": "^0.5.0",
"@pika/plugin-build-node": "^0.9.2",
"@pika/plugin-ts-standard-pkg": "^0.9.2",
"@octokit/tsconfig": "^2.0.0",
"@types/jest": "^29.0.0",
"@types/node": "^18.0.0",
"esbuild": "^0.17.19",
"glob": "^10.2.6",
"jest": "^29.0.0",
"prettier": "2.8.8",
"puppeteer": "^20.0.0",
Expand All @@ -46,9 +40,15 @@
"ts-jest": "^29.0.0",
"typescript": "^5.0.0"
},
"peerDependencies": {},
"jest": {
"preset": "ts-jest",
"transform": {
"^.+\\.(ts|tsx)$": [
"ts-jest",
{
"tsconfig": "test/tsconfig.test.json"
}
]
},
"coverageThreshold": {
"global": {
"statements": 100,
Expand All @@ -62,22 +62,6 @@
"<rootDir>/test/deno/"
]
},
"@pika/pack": {
"pipeline": [
[
"@pika/plugin-ts-standard-pkg"
],
[
"@pika/plugin-build-node",
{
"minNodeVersion": 18
}
],
[
"@gr2m/pika-plugin-build-web"
]
]
},
"release": {
"branches": [
"+([0-9]).x",
Expand Down
76 changes: 76 additions & 0 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import esbuild from "esbuild";
import { copyFile, readFile, writeFile, rm } from "fs/promises";
import { glob } from "glob";

const sharedOptions = {
sourcemap: "external",
sourcesContent: true,
minify: false,
allowOverwrite: true,
packages: "external",
};

async function main() {
// Start with a clean slate
await rm("pkg", { recursive: true, force: true });
// Build the source code for a neutral platform as ESM
await esbuild.build({
entryPoints: await glob(["./src/*.ts", "./src/**/*.ts"]),
outdir: "pkg/dist-src",
bundle: false,
platform: "neutral",
format: "esm",
...sharedOptions,
sourcemap: false,
});

await Promise.all([
// Build the a CJS Node.js bundle
esbuild.build({
entryPoints: ["./pkg/dist-src/index.js"],
outdir: "pkg/dist-node",
bundle: true,
platform: "node",
target: "node14",
format: "cjs",
...sharedOptions,
}),
// Build an ESM browser bundle
esbuild.build({
entryPoints: [{ in: "./pkg/dist-src/web.js", out: "index" }],
outdir: "pkg/dist-web",
bundle: true,
platform: "browser",
format: "esm",
...sharedOptions,
}),
]);

// Copy the README, LICENSE to the pkg folder
await copyFile("LICENSE", "pkg/LICENSE");
await copyFile("README.md", "pkg/README.md");

// Handle the package.json
let pkg = JSON.parse((await readFile("package.json", "utf8")).toString());
// Remove unnecessary fields from the package.json
delete pkg.scripts;
delete pkg.prettier;
delete pkg.release;
await writeFile(
"pkg/package.json",
JSON.stringify(
{
...pkg,
files: ["dist-*/**"],
main: "dist-node/index.js",
browser: "dist-web/index.js",
types: "dist-types/index.d.ts",
module: "dist-src/index.js",
sideEffects: false,
},
null,
2
)
);
}
main();
2 changes: 1 addition & 1 deletion src/node/sign.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createHmac } from "crypto";
import { Algorithm, SignOptions } from "../types";
import { Algorithm, type SignOptions } from "../types";
import { VERSION } from "../version";

export async function sign(
Expand Down
2 changes: 1 addition & 1 deletion src/web.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Algorithm, AlgorithmLike, SignOptions } from "./types";
import { Algorithm, type AlgorithmLike, type SignOptions } from "./types";
import { getAlgorithm } from "./utils";

const enc = new TextEncoder();
Expand Down
8 changes: 7 additions & 1 deletion test/browser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ async function runTests() {
await page.goto("file:///");

await page.addScriptTag({
content: script.replace("export { sign, verify };", ""),
content: script.replace(
`export {
sign,
verify
};`,
""
),
});

const [signature, verified] = await page.evaluate(async function () {
Expand Down
9 changes: 9 additions & 0 deletions test/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"emitDeclarationOnly": false,
"noEmit": true,
"verbatimModuleSyntax": false
},
"include": ["src/**/*"]
}
12 changes: 11 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
{ "extends": "@octokit/tsconfig", "include": ["src/**/*"] }
{
"extends": "@octokit/tsconfig",
"compilerOptions": {
"esModuleInterop": true,
"declaration": true,
"outDir": "pkg/dist-types",
"emitDeclarationOnly": true,
"sourceMap": true
},
"include": ["src/**/*"]
}

0 comments on commit 691c3a8

Please sign in to comment.