-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5776893
Showing
5 changed files
with
790 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
/dist | ||
|
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,96 @@ | ||
import { writeFile } from "fs/promises"; | ||
import { createContext } from "./src/index.ts"; | ||
import tsc from "tsc-prog"; | ||
|
||
const isDev = process.argv.includes("--dev"); | ||
|
||
const buildContext = createContext({ | ||
bundle: true, | ||
}); | ||
|
||
const common = { | ||
external: ["tiny-glob", "defu", "esbuild"], | ||
entryPoints: ["./src/index.js"], | ||
platform: "node", | ||
target: "node14", | ||
format: "esm", | ||
}; | ||
|
||
buildContext.config({ | ||
...common, | ||
outdir: "./dist/esm", | ||
format: "esm", | ||
outExtension: { | ||
".js": ".mjs", | ||
}, | ||
}); | ||
|
||
buildContext.config({ | ||
...common, | ||
outdir: "./dist/cjs", | ||
format: "cjs", | ||
outExtension: { | ||
".js": ".js", | ||
}, | ||
}); | ||
|
||
buildContext.on("error", (errors) => { | ||
errors.map((x) => process.stdout.write(x.reason.toString() + "\n")); | ||
}); | ||
|
||
buildContext.on("build", async () => { | ||
process.stdout.write("[custom-builder] Built\n"); | ||
await writeFile( | ||
"./dist/cjs/package.json", | ||
JSON.stringify({ type: "commonjs" }), | ||
"utf8" | ||
); | ||
|
||
await writeFile( | ||
"./dist/esm/package.json", | ||
JSON.stringify({ type: "module" }), | ||
"utf8" | ||
); | ||
|
||
tsc.build({ | ||
basePath: process.cwd(), | ||
compilerOptions: { | ||
rootDir: "src", | ||
outDir: "./dist/types", | ||
declaration: true, | ||
moduleResolution: "nodenext", | ||
target: "esnext", | ||
module: "NodeNext", | ||
emitDeclarationOnly: true, | ||
skipLibCheck: true, | ||
}, | ||
include: ["src/**/*"], | ||
exclude: ["**/*.test.ts", "**/*.spec.ts"], | ||
}); | ||
|
||
if (isDev) return; | ||
|
||
process.exit(0); | ||
}); | ||
|
||
function createChain() { | ||
let agg = Promise.resolve(); | ||
const _chainer = (fn) => { | ||
agg = agg.then(fn); | ||
}; | ||
_chainer.value = async () => { | ||
await agg; | ||
return null; | ||
}; | ||
return _chainer; | ||
} | ||
|
||
const chain = createChain(); | ||
|
||
if (isDev) { | ||
chain(() => buildContext.watch()); | ||
} | ||
|
||
chain(() => buildContext.build()); | ||
|
||
await chain.value; |
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,36 @@ | ||
{ | ||
"name": "esbuild-multicontext", | ||
"version": "0.0.0", | ||
"license": "MIT", | ||
"type": "module", | ||
"main": "dist/cjs/index.js", | ||
"module": "dist/esm/index.mjs", | ||
"types": "./dist/types/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./dist/types/index.d.ts", | ||
"import": "./dist/esm/index.mjs", | ||
"require": "./dist/cjs/index.js" | ||
}, | ||
"./cjs": "./dist/esm/index.js", | ||
"./esm": "./dist/esm/index.mjs", | ||
"./package.json": "./package.json" | ||
}, | ||
"scripts": { | ||
"build": "tsx build.js", | ||
"dev": "tsx build.js --dev" | ||
}, | ||
"dependencies": { | ||
"defu": "^6.1.3", | ||
"esbuild": "^0.19.8", | ||
"tiny-glob": "^0.2.9" | ||
}, | ||
"devDependencies": { | ||
"@barelyhuman/prettier-config": "^1.1.0", | ||
"@types/node": "^20.10.2", | ||
"prettier": "^3.1.0", | ||
"tsc-prog": "^2.3.0", | ||
"tsx": "^4.6.1", | ||
"typescript": "^5.3.2" | ||
} | ||
} |
Oops, something went wrong.