-
Notifications
You must be signed in to change notification settings - Fork 27
/
build_npm.ts
53 lines (48 loc) · 1.49 KB
/
build_npm.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { build, emptyDir } from "jsr:@deno/[email protected]";
await emptyDir("./npm");
Deno.mkdirSync("npm/esm", { recursive: true });
Deno.mkdirSync("npm/script");
Deno.copyFileSync("js/eszip_wasm_bg.wasm", "npm/esm/eszip_wasm_bg.wasm");
// todo(dsherret): how to not include two copies of this in the npm
// package? Does using a symlink work?
Deno.copyFileSync("js/eszip_wasm_bg.wasm", "npm/script/eszip_wasm_bg.wasm");
await build({
entryPoints: ["./js/mod.ts"],
outDir: "./npm",
shims: {
deno: true,
undici: true,
},
scriptModule: false,
package: {
name: "@deno/eszip",
version: Deno.args[0],
description:
"A utility that can download JavaScript and TypeScript module graphs and store them locally in a special zip file",
license: "MIT",
repository: {
type: "git",
url: "git+https://github.com/denoland/eszip.git",
},
bugs: {
url: "https://github.com/denoland/eszip/issues",
},
},
compilerOptions: {
lib: ["DOM", "ES2021"],
},
postBuild() {
addWebCryptoGlobal("npm/esm/mod.js");
},
});
function addWebCryptoGlobal(filePath: string) {
const fileText = Deno.readTextFileSync(filePath);
// https://docs.rs/getrandom/latest/getrandom/#nodejs-es-module-support
Deno.writeTextFileSync(
filePath,
`import { webcrypto } from 'node:crypto';\nif (!globalThis.crypto) {\n globalThis.crypto = webcrypto;\n}\n` +
fileText,
);
}
Deno.copyFileSync("LICENSE", "npm/LICENSE");
Deno.copyFileSync("README.md", "npm/README.md");