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 de39e39

Browse files
feat: support esm (#16)
* feat: support esm import * remove rollup
1 parent 5d6d193 commit de39e39

File tree

11 files changed

+224
-126
lines changed

11 files changed

+224
-126
lines changed

‎fixup.sh‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
cat > build/cjs/package.json <<!EOF
4+
{
5+
"version": "$(node -p 'require("./package.json").version')",
6+
"type": "commonjs"
7+
}
8+
!EOF
9+
10+
cat >build/mjs/package.json <<!EOF
11+
{
12+
"version": "$(node -p 'require("./package.json").version')",
13+
"type": "module"
14+
}
15+
!EOF

‎jest.config.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ module.exports = {
33
preset: 'ts-jest',
44
testEnvironment: 'node',
55
testMatch: ['<rootDir>/**/*.test.ts'],
6+
moduleNameMapper: {
7+
'^(\\.{1,2}/.*)\\.js$': '1ドル',
8+
},
69
};

‎package.json‎

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,32 @@
22
"name": "parse-git-diff",
33
"version": "0.0.9",
44
"description": "A parser for git diff",
5-
"main": "build/index.umd.js",
6-
"module": "build/index.module.js",
7-
"types": "build/index.d.ts",
5+
"main": "./build/cjs/index.js",
6+
"module": "./build/mjs/index.js",
7+
"types": "./build/types/index.d.ts",
88
"scripts": {
99
"prepublish": "yarn build",
10-
"build": "rimraf build && rollup -c rollup.config.js && tsc --declaration",
10+
"build": "rimraf build && tsc -p tsconfig.json && tsc -p tsconfig-esm.json",
11+
"postbuild": "bash fixup.sh",
1112
"format": "prettier . --write",
1213
"test": "jest --coverage",
1314
"prebuild": "yarn check:all",
1415
"publish:demo": "gh-pages -d demo/build",
1516
"check:all": "prettier --check . && tsc --noEmit && yarn test",
1617
"build:readme": "node scripts/build-readme.js && yarn format"
1718
},
19+
"exports": {
20+
".": {
21+
"import": {
22+
"types": "./build/mjs/index.d.ts",
23+
"default": "./build/mjs/index.js"
24+
},
25+
"require": {
26+
"types": "./build/cjs/index.d.ts",
27+
"default": "./build/cjs/index.js"
28+
}
29+
}
30+
},
1831
"repository": {
1932
"type": "git",
2033
"url": "git+https://github.com/yeonjuan/parse-git-diff.git"
@@ -26,26 +39,19 @@
2639
},
2740
"homepage": "https://github.com/yeonjuan/parse-git-diff#readme",
2841
"devDependencies": {
29-
"@rollup/plugin-node-resolve": "^13.0.6",
30-
"@rollup/plugin-typescript": "^8.3.0",
3142
"@types/jest": "^27.0.2",
3243
"gh-pages": "^4.0.0",
3344
"husky": "^7.0.2",
3445
"jest": "^29.3.1",
3546
"md-replacer": "^0.0.4",
3647
"prettier": "^2.4.1",
37-
"rimraf": "^4.0.5",
38-
"rollup": "^2.58.0",
48+
"rimraf": "^5.0.1",
3949
"ts-jest": "^29.0.5",
4050
"tslib": "^2.3.1",
41-
"typescript": "^4.4.3"
51+
"typescript": "^5.0.4"
4252
},
4353
"files": [
44-
"build",
45-
"tsconfig.json",
46-
"README.md",
47-
"yarn.lock",
48-
"package.json"
54+
"build"
4955
],
5056
"keywords": [
5157
"git",

‎rollup.config.js‎

Lines changed: 0 additions & 17 deletions
This file was deleted.

‎src/index.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import parseGitDiff from './parse-git-diff';
1+
import parseGitDiff from './parse-git-diff.js';
22
export default parseGitDiff;
33

44
export type {
@@ -17,4 +17,4 @@ export type {
1717
RenamedFile,
1818
AnyFileChange,
1919
GitDiff,
20-
} from './types';
20+
} from './types.js';

‎src/parse-git-diff.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Context from './context';
1+
import Context from './context.js';
22
import type {
33
GitDiff,
44
AnyFileChange,
@@ -7,13 +7,13 @@ import type {
77
ChunkRange,
88
CombinedChunk,
99
AnyChunk,
10-
} from './types';
10+
} from './types.js';
1111
import {
1212
ExtendedHeader,
1313
ExtendedHeaderValues,
1414
FileType,
1515
LineType,
16-
} from './constants';
16+
} from './constants.js';
1717

1818
export default function parseGitDiff(diff: string): GitDiff {
1919
const ctx = new Context(diff);

‎src/types.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LineType, FileType } from './constants';
1+
import { LineType, FileType } from './constants.js';
22

33
export interface Base<Type extends string> {
44
readonly type: Type;

‎tsconfig-base.json‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"exclude": [
3+
"src/__tests__",
4+
"src/__fixtures__",
5+
"build",
6+
"node_modules",
7+
"demo"
8+
],
9+
"include": ["src/**/*.ts"],
10+
"compilerOptions": {
11+
"allowSyntheticDefaultImports": true,
12+
"declaration": true,
13+
"declarationMap": true,
14+
"inlineSources": true,
15+
"esModuleInterop": true,
16+
"forceConsistentCasingInFileNames": true,
17+
"isolatedModules": true,
18+
"moduleResolution": "node",
19+
"resolveJsonModule": true,
20+
"sourceMap": true,
21+
"strict": true,
22+
"skipLibCheck": true,
23+
"target": "es2022"
24+
}
25+
}

‎tsconfig-esm.json‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"module": "esnext",
5+
"outDir": "build/mjs"
6+
}
7+
}

‎tsconfig.json‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
{
2+
"extends": "./tsconfig-base.json",
23
"compilerOptions": {
3-
"target": "ES2017",
4-
"module": "ES2015",
5-
"strict": true,
6-
"noImplicitAny": true,
7-
"esModuleInterop": true,
8-
"forceConsistentCasingInFileNames": true,
9-
"declaration": true,
10-
"outDir": "build",
11-
"rootDir": "src",
12-
"moduleResolution": "node"
13-
},
14-
"exclude": ["src/**/*.test.ts", "build", "node_modules", "demo"]
4+
"module": "CommonJS",
5+
"outDir": "build/cjs",
6+
"moduleResolution": "Node"
7+
}
158
}

0 commit comments

Comments
(0)

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