Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b97a1f4

Browse files
Add build script to configure esmodules
1 parent e61baa2 commit b97a1f4

File tree

2 files changed

+35
-10
lines changed

2 files changed

+35
-10
lines changed

‎package.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
"name": "deep-object-diff",
33
"version": "1.1.3",
44
"description": "Deep diffs two objects, including nested structures of arrays and objects, and return the difference.",
5-
"main": "dist/index.js",
6-
"module": "dist-es/index.js",
5+
"main": "cjs/index.js",
6+
"module": "mjs/index.js",
7+
"exports": {
8+
".": {
9+
"import": "./cjs/index.js",
10+
"require": "./mjs/index.js"
11+
}
12+
},
713
"types": "./index.d.ts",
8-
"files": [
9-
"dist",
10-
"dist-es",
11-
"index.d.ts",
12-
"README.md"
13-
],
1414
"scripts": {
15-
"build": "babel src -d dist && yarn build:esmodule",
16-
"build:esmodule": "rm -rf dist-es && mkdir dist-es && cp -r src/* dist-es && rm -rf dist-es/**/*.test.js",
15+
"build": "rm -rf dist && babel src -d dist/cjs && node scripts/build.mjs",
1716
"prepublish": "yarn build",
1817
"lint": "eslint src",
1918
"test": "jest",

‎scripts/build.mjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as path from "path";
2+
import * as fs from "fs";
3+
4+
const DIST = "dist";
5+
const SRC = "src";
6+
const MJS = "mjs";
7+
const CJS = "cjs";
8+
const PKG = "package.json";
9+
const FILES = ["index.d.ts", "README.md", "LICENSE"];
10+
11+
fs.mkdirSync(path.join(DIST, MJS));
12+
fs.readdirSync("./src").forEach((file) => fs.copyFileSync(path.join(SRC, file), path.join(DIST, MJS, file)));
13+
14+
fs.writeFileSync(path.join(DIST, CJS, PKG), JSON.stringify({ type: "commonjs" }, null, 2));
15+
fs.writeFileSync(path.join(DIST, MJS, PKG), JSON.stringify({ type: "module" }, null, 2));
16+
17+
const pkg = fs.readFileSync(PKG, "utf-8");
18+
const json = JSON.parse(pkg);
19+
20+
delete json.scripts;
21+
delete json.devDependencies;
22+
delete json.babel;
23+
24+
fs.writeFileSync(path.join(DIST, PKG), JSON.stringify(json, null, 2));
25+
26+
FILES.forEach((file) => fs.copyFileSync(file, path.join(DIST, file)));

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /