-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(build): switch to esbuild and tsc from pika (#345)
* Switch to esbuild and tsc from pika * Fix linting errors * Explicitly mark imports * Undo overzealous type import * npm i --save-dev @octokit/types * Use node 14 to create lockfile * Redo appropriately zealous type import * Add --verbatimModuleSyntax build option * Move verbatimModuleSyntax to tsconfig * Create tsconfig.test.json * Bump version of octokit/tsconfig * Update tsconfig.test.json Co-authored-by: wolfy1339 <[email protected]> * Move tsconfig.test.json to test directory --------- Co-authored-by: wolfy1339 <[email protected]>
- Loading branch information
1 parent
7cb89fd
commit eaf16ab
Showing
9 changed files
with
1,568 additions
and
18,451 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,88 @@ | ||
import esbuild from "esbuild"; | ||
import { copyFile, readFile, writeFile, rm } from "node: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, | ||
}); | ||
|
||
// 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", | ||
browser: "dist-web/index.js", | ||
types: "dist-types/index.d.ts", | ||
module: "dist-src/index.js", | ||
sideEffects: false, | ||
}, | ||
null, | ||
2 | ||
) | ||
); | ||
} | ||
main(); |
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,4 +1,4 @@ | ||
import { | ||
import type { | ||
AnyResponse, | ||
EndpointDefaults, | ||
EndpointOptions, | ||
|
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,9 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"compilerOptions": { | ||
"emitDeclarationOnly": false, | ||
"noEmit": true, | ||
"verbatimModuleSyntax": false | ||
}, | ||
"include": ["src/**/*"] | ||
} |
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,10 +1,11 @@ | ||
{ | ||
"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/**/*"] | ||
} |