Skip to content

Commit e7055ca

Browse files
committedFeb 17, 2025·
fix: Separate ESM and UMD type definitions
1 parent 2a9bea9 commit e7055ca

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
npm-debug.*
33
umd/index.js
4+
umd/types.d.ts

‎package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
},
4747
"license": "BSD-3-Clause",
4848
"scripts": {
49-
"build": "esm2umd bcrypt index.js > umd/index.js && prettier --write umd/index.js",
49+
"build": "node scripts/build.js",
5050
"lint": "prettier --check .",
5151
"format": "prettier --write .",
5252
"test": "npm run test:unit && npm run test:typescript",
@@ -56,10 +56,11 @@
5656
"files": [
5757
"index.js",
5858
"index.d.ts",
59+
"types.d.ts",
5960
"umd/index.js",
6061
"umd/index.d.ts",
62+
"umd/types.d.ts",
6163
"umd/package.json",
62-
"types.d.ts",
6364
"LICENSE",
6465
"README.md"
6566
],

‎scripts/build.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import fs from "fs";
2+
import path from "path";
3+
import { fileURLToPath } from "url";
4+
import esm2umd from "esm2umd";
5+
import prettier from "prettier";
6+
7+
const basePath = path.join(path.dirname(fileURLToPath(import.meta.url)), "..");
8+
const esmPath = path.join(basePath, "index.js");
9+
const umdPath = path.join(basePath, "umd", "index.js");
10+
11+
const esmSource = fs.readFileSync(esmPath, "utf8");
12+
const umdSource = esm2umd("bcrypt", esmSource);
13+
14+
async function formatWithPrettier(source, filepath) {
15+
const options = await prettier.resolveConfig(filepath);
16+
return await prettier.format(source, { ...options, filepath });
17+
}
18+
19+
const prettierUmdSource = await formatWithPrettier(umdSource, umdPath);
20+
21+
fs.writeFileSync(umdPath, prettierUmdSource);
22+
23+
fs.copyFileSync(
24+
path.join(basePath, "types.d.ts"),
25+
path.join(basePath, "umd", "types.d.ts"),
26+
);

‎umd/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import * as bcrypt from "../types.js";
1+
import * as bcrypt from "./types.js";
22
export = bcrypt;
33
export as namespace bcrypt;

0 commit comments

Comments
 (0)