-
Notifications
You must be signed in to change notification settings - Fork 26
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 instead of pika (#421)
* Switch to esbuild instead of pika * Regenerate package-lock.json with Node v14
- Loading branch information
1 parent
604fc9a
commit 7fd20a0
Showing
11 changed files
with
1,596 additions
and
18,447 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
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 { | ||
EndpointDefaults, | ||
RequestMethod, | ||
RequestOptions, | ||
|
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 { | ||
EndpointInterface, | ||
RequestParameters, | ||
EndpointDefaults, | ||
|
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/**/*"] | ||
} |