-
Notifications
You must be signed in to change notification settings - Fork 39
Switch to esbuild and tsc instead of pika #603
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b6d7efc
Switch to esbuild and tsc instead of pika
kfcampbell d522b15
Fix linting errors
kfcampbell 6d965b5
Bump tsconfig
kfcampbell 9ce259b
Merge branch 'main' into switch-to-esbuild
kfcampbell a867d17
Update scripts/build.mjs
kfcampbell e32eaa9
Update package.json
kfcampbell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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", | ||
kfcampbell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,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/**/*" | ||
] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.