Skip to content

Commit

Permalink
feat: support esm (#16)
Browse files Browse the repository at this point in the history
* feat: support esm import

* remove rollup
  • Loading branch information
yeonjuan committed May 29, 2023
1 parent 5d6d193 commit de39e39
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 126 deletions.
15 changes: 15 additions & 0 deletions fixup.sh
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

cat > build/cjs/package.json <<!EOF
{
"version": "$(node -p 'require("./package.json").version')",
"type": "commonjs"
}
!EOF

cat >build/mjs/package.json <<!EOF
{
"version": "$(node -p 'require("./package.json").version')",
"type": "module"
}
!EOF
3 changes: 3 additions & 0 deletions jest.config.js
Expand Up @@ -3,4 +3,7 @@ module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['<rootDir>/**/*.test.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1',
},
};
34 changes: 20 additions & 14 deletions package.json
Expand Up @@ -2,19 +2,32 @@
"name": "parse-git-diff",
"version": "0.0.9",
"description": "A parser for git diff",
"main": "build/index.umd.js",
"module": "build/index.module.js",
"types": "build/index.d.ts",
"main": "./build/cjs/index.js",
"module": "./build/mjs/index.js",
"types": "./build/types/index.d.ts",
"scripts": {
"prepublish": "yarn build",
"build": "rimraf build && rollup -c rollup.config.js && tsc --declaration",
"build": "rimraf build && tsc -p tsconfig.json && tsc -p tsconfig-esm.json",
"postbuild": "bash fixup.sh",
"format": "prettier . --write",
"test": "jest --coverage",
"prebuild": "yarn check:all",
"publish:demo": "gh-pages -d demo/build",
"check:all": "prettier --check . && tsc --noEmit && yarn test",
"build:readme": "node scripts/build-readme.js && yarn format"
},
"exports": {
".": {
"import": {
"types": "./build/mjs/index.d.ts",
"default": "./build/mjs/index.js"
},
"require": {
"types": "./build/cjs/index.d.ts",
"default": "./build/cjs/index.js"
}
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/yeonjuan/parse-git-diff.git"
Expand All @@ -26,26 +39,19 @@
},
"homepage": "https://github.com/yeonjuan/parse-git-diff#readme",
"devDependencies": {
"@rollup/plugin-node-resolve": "^13.0.6",
"@rollup/plugin-typescript": "^8.3.0",
"@types/jest": "^27.0.2",
"gh-pages": "^4.0.0",
"husky": "^7.0.2",
"jest": "^29.3.1",
"md-replacer": "^0.0.4",
"prettier": "^2.4.1",
"rimraf": "^4.0.5",
"rollup": "^2.58.0",
"rimraf": "^5.0.1",
"ts-jest": "^29.0.5",
"tslib": "^2.3.1",
"typescript": "^4.4.3"
"typescript": "^5.0.4"
},
"files": [
"build",
"tsconfig.json",
"README.md",
"yarn.lock",
"package.json"
"build"
],
"keywords": [
"git",
Expand Down
17 changes: 0 additions & 17 deletions rollup.config.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/index.ts
@@ -1,4 +1,4 @@
import parseGitDiff from './parse-git-diff';
import parseGitDiff from './parse-git-diff.js';
export default parseGitDiff;

export type {
Expand All @@ -17,4 +17,4 @@ export type {
RenamedFile,
AnyFileChange,
GitDiff,
} from './types';
} from './types.js';
6 changes: 3 additions & 3 deletions src/parse-git-diff.ts
@@ -1,4 +1,4 @@
import Context from './context';
import Context from './context.js';
import type {
GitDiff,
AnyFileChange,
Expand All @@ -7,13 +7,13 @@ import type {
ChunkRange,
CombinedChunk,
AnyChunk,
} from './types';
} from './types.js';
import {
ExtendedHeader,
ExtendedHeaderValues,
FileType,
LineType,
} from './constants';
} from './constants.js';

export default function parseGitDiff(diff: string): GitDiff {
const ctx = new Context(diff);
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
@@ -1,4 +1,4 @@
import { LineType, FileType } from './constants';
import { LineType, FileType } from './constants.js';

export interface Base<Type extends string> {
readonly type: Type;
Expand Down
25 changes: 25 additions & 0 deletions tsconfig-base.json
@@ -0,0 +1,25 @@
{
"exclude": [
"src/__tests__",
"src/__fixtures__",
"build",
"node_modules",
"demo"
],
"include": ["src/**/*.ts"],
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": true,
"declarationMap": true,
"inlineSources": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"sourceMap": true,
"strict": true,
"skipLibCheck": true,
"target": "es2022"
}
}
7 changes: 7 additions & 0 deletions tsconfig-esm.json
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "esnext",
"outDir": "build/mjs"
}
}
17 changes: 5 additions & 12 deletions tsconfig.json
@@ -1,15 +1,8 @@
{
"extends": "./tsconfig-base.json",
"compilerOptions": {
"target": "ES2017",
"module": "ES2015",
"strict": true,
"noImplicitAny": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"declaration": true,
"outDir": "build",
"rootDir": "src",
"moduleResolution": "node"
},
"exclude": ["src/**/*.test.ts", "build", "node_modules", "demo"]
"module": "CommonJS",
"outDir": "build/cjs",
"moduleResolution": "Node"
}
}

0 comments on commit de39e39

Please sign in to comment.