-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(build): replace pika with esbuild and tsc (#297)
Pika has been deprecated for a while now, and the project has now been archived, and because of that any released npm package is missing most of the files generated by the build step. Uses esbuild to transpile the TS source code into an ESM source, NodeJs bundle, and a browser bundle Uses the TypeScript compiler to generate the types
- Loading branch information
Showing
8 changed files
with
1,410 additions
and
3,455 deletions.
There are no files selected for viewing
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
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,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(); |
This file was deleted.
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
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/**/*"] | ||
} |