Skip to content

Commit

Permalink
adapt changes from app.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Sep 28, 2023
1 parent 6d1390d commit 498872e
Show file tree
Hide file tree
Showing 7 changed files with 8,479 additions and 11,077 deletions.
19,392 changes: 8,345 additions & 11,047 deletions package-lock.json

Large diffs are not rendered by default.

43 changes: 22 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
"name": "@probot/octokit-plugin-config",
"version": "0.0.0-development",
"description": "Get/set persisted configuration using YAML/JSON files in repositories",
"main": "index.js",
"scripts": {
"build": "pika build",
"build": "node scripts/build.mjs && tsc -p tsconfig.json",
"lint": "prettier --check '{src,test}/**/*.ts' README.md package.json",
"lint:fix": "prettier --write '{src,test}/**/*.ts' README.md package.json",
"pretest": "npm run -s lint",
Expand All @@ -20,26 +21,32 @@
"license": "MIT",
"devDependencies": {
"@octokit/core": "^5.0.1",
"@pika/pack": "^0.3.7",
"@pika/plugin-build-node": "^0.9.2",
"@pika/plugin-build-web": "^0.9.2",
"@pika/plugin-ts-standard-pkg": "^0.9.2",
"@octokit/tsconfig": "^2.0.0",
"@types/jest": "^29.0.0",
"@types/node": "^18.7.15",
"esbuild": "^0.19.4",
"fetch-mock": "^9.11.0",
"jest": "^29.0.0",
"prettier": "^2.7.1",
"semantic-release": "^22.0.5",
"semantic-release-plugin-update-version-in-files": "^1.1.0",
"strip-indent": "^3.0.0",
"ts-jest": "^29.0.0",
"typescript": "^4.8.2"
"typescript": "^5.0.0"
},
"peerDependencies": {
"@octokit/core": ">=5"
},
"jest": {
"preset": "ts-jest",
"transform": {
"^.+\\.(ts|tsx)$": [
"ts-jest",
{
"tsconfig": "test/tsconfig.test.json"
}
]
},
"testEnvironment": "node",
"coverageThreshold": {
"global": {
"statements": 100,
Expand All @@ -49,22 +56,15 @@
}
}
},
"@pika/pack": {
"pipeline": [
[
"@pika/plugin-ts-standard-pkg"
],
[
"@pika/plugin-build-node"
],
[
"@pika/plugin-build-web"
]
]
},
"release": {
"branches": [
"main"
"+([0-9]).x",
"main",
"next",
{
"name": "beta",
"prerelease": true
}
],
"plugins": [
"@semantic-release/commit-analyzer",
Expand Down Expand Up @@ -93,6 +93,7 @@
},
"dependencies": {
"@types/js-yaml": "^4.0.5",
"glob": "^10.3.10",
"js-yaml": "^4.1.0"
},
"engines": {
Expand Down
92 changes: 92 additions & 0 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// @ts-check
import esbuild from "esbuild";
import { copyFile, readFile, writeFile, rm } from "fs/promises";
import { glob } from "glob";

/**
* @type {esbuild.BuildOptions}
*/
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,
});

// Remove the types file from the dist-src folder
const typeFiles = await glob([
"./pkg/dist-src/**/types.js.map",
"./pkg/dist-src/**/types.js",
]);
for (const typeFile of typeFiles) {
await rm(typeFile);
}

const entryPoints = ["./pkg/dist-src/index.js"];

await Promise.all([
// Build the a CJS Node.js bundle
esbuild.build({
entryPoints,
outdir: "pkg/dist-node",
bundle: true,
platform: "node",
target: "node14",
format: "cjs",
...sharedOptions,
}),
// Build an ESM browser bundle
esbuild.build({
entryPoints,
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;
delete pkg.jest;
await writeFile(
"pkg/package.json",
JSON.stringify(
{
...pkg,
files: ["dist-*/**", "bin/**"],
main: "dist-node/index.js",
module: "dist-web/index.js",
types: "dist-types/index.d.ts",
source: "dist-src/index.js",
sideEffects: false,
},
null,
2
)
);
}
main();
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Octokit } from "@octokit/core";

import { VERSION } from "./version";
import { composeConfigGet } from "./compose-config-get";
import * as Types from "./types";
import type * as Types from "./types";

/**
* @param octokit Octokit instance
Expand Down
3 changes: 1 addition & 2 deletions test/issues.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { Octokit } from "@octokit/core";
import fetchMock from "fetch-mock";
import stripIndent from "strip-indent";

import { config } from "../src";

const TestOctokit = Octokit.plugin(config);

describe("issues", () => {
it("#91 sets incorrect accept header when media type previews are set", async () => {
const mock = fetchMock.sandbox().getOnce((url, { headers }) => {
const mock = fetchMock.sandbox().getOnce((_url, { headers }) => {
// @ts-ignore TypeScript says we can't do this but turns out we can so there you go
expect(headers["accept"]).toEqual("application/vnd.github.v3.raw");
return true;
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/**/*"]
}
15 changes: 9 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"extends": "@octokit/tsconfig",
"compilerOptions": {
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"strict": true,
"target": "es2018"
"declaration": true,
"outDir": "pkg/dist-types",
"emitDeclarationOnly": true,
"sourceMap": true
},
"include": ["src/**/*"]
}
"include": [
"src/**/*"
]
}

0 comments on commit 498872e

Please sign in to comment.