Skip to content

Commit b47aa19

Browse files
authored
Changeset and version management with changesets (#747)
Use `changesets` as version and changelog manager * Publish `simple-git` from the package root by including `/dist/` in export paths once published. * Use named root import in (deprecated) `simple-git/promise` types * Use `filterType` in `parseLogOptions` to provide the type guard for passing in a standard `Options` object as well as a `LogOptions` object
1 parent 1eec6e4 commit b47aa19

File tree

16 files changed

+742
-135
lines changed

16 files changed

+742
-135
lines changed

.changeset/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)

.changeset/config.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3+
"changelog": "@changesets/cli/changelog",
4+
"commit": false,
5+
"linked": [],
6+
"access": "public",
7+
"baseBranch": "main",
8+
"updateInternalDependencies": "patch",
9+
"ignore": []
10+
}

.changeset/tiny-dolls-impress.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"simple-git": minor
3+
---
4+
5+
Switch to `changesets` as version and changelog manager

.github/workflows/changesets.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: release-changesets
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout Repo
13+
uses: actions/checkout@v2
14+
with:
15+
fetch-depth: 0
16+
17+
- uses: actions/setup-node@v2
18+
with:
19+
node-version: 16
20+
21+
- run: yarn --frozen-lockfile
22+
- run: yarn build
23+
24+
- uses: changesets/action@v1
25+
env:
26+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27+
NPM_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}

.github/workflows/ci.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ jobs:
1818
uses: actions/setup-node@v1
1919
with:
2020
node-version: ${{ matrix.node-version }}
21-
- name: Node Version
22-
run: node --version
23-
- name: Git Version
24-
run: git --version
21+
- run: node --version
22+
- run: git --version
2523
- name: Cache node_modules
2624
id: cache-modules
2725
uses: actions/cache@v1

.github/workflows/release-please.yml

-37
This file was deleted.

.release-please-manifest.json

-1
This file was deleted.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"clean": "git clean -fxd -e .idea -e node_modules",
1515
"test": "lerna run test"
1616
},
17-
"devDependencies": {
17+
"dependencies": {
18+
"@changesets/changelog-github": "^0.4.2",
19+
"@changesets/cli": "^2.20.0",
1820
"lerna": "^4.0.0"
1921
}
2022
}

packages/babel-config/babel.config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ const {existsSync} = require('fs');
33

44
function resolver () {
55
const root = resolve(__dirname, '../..', 'simple-git');
6-
const dist = resolve(root, 'dist');
6+
const dist = resolve(root, 'dist', 'cjs');
77

88
const pkg = existsSync(dist) ? dist : root;
99

1010
return ['module-resolver', {
1111
root: [pkg],
1212
alias: {
13+
'simple-git/promise': resolve(root, 'promise'),
1314
'simple-git': pkg,
1415
},
1516
}];

packages/test-typescript-consumer/tsconfig.json

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
"esModuleInterop": true,
99
"baseUrl": ".",
1010
"paths": {
11-
"simple-git": ["../../simple-git/dist", "../../simple-git"],
12-
"simple-git/*": ["../../simple-git/dist/*", "../../simple-git/*"],
1311
}
1412
}
1513
}

release-please-config.json

-18
This file was deleted.

simple-git/package.json

+9-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"name": "simple-git",
33
"description": "Simple GIT interface for node.js",
4-
"private": true,
54
"version": "3.1.1",
65
"author": "Steve King <[email protected]>",
76
"contributors": [
@@ -55,30 +54,26 @@
5554
},
5655
"types": "./typings/index.d.ts",
5756
"files": [
58-
"promise.js",
59-
"promise.d.ts",
60-
"src/**/*.d.ts",
61-
"typings",
57+
"promise.*",
6258
"dist"
6359
],
6460
"scripts": {
65-
"build": "yarn build:compile && yarn build:defs && yarn build:promise && yarn build:docs && yarn build:pkg",
61+
"build": "yarn build:compile && yarn build:defs",
6662
"build:compile": "node scripts/build.js",
6763
"build:defs": "tsc -p tsconfig.release.json --outDir dist && cp -r typings dist",
6864
"build:pkg": "node scripts/package-json.js",
69-
"build:promise": "cp promise.* dist",
70-
"build:docs": "cp ../*.md ../LICENSE dist",
71-
"preversion": "yarn test && yarn build",
65+
"build:docs": "cp ../readme.md .",
66+
"prepublishOnly": "yarn build:docs && yarn build:pkg",
7267
"test": "jest --coverage"
7368
},
7469
"publish": {
75-
"private": false,
76-
"main": "cjs/index.js",
77-
"module": "esm/index.js",
70+
"main": "dist/cjs/index.js",
71+
"module": "dist/esm/index.js",
72+
"types": "./dist/typings/index.d.ts",
7873
"exports": {
7974
".": {
80-
"import": "./esm/index.js",
81-
"require": "./cjs/index.js"
75+
"import": "./dist/esm/index.js",
76+
"require": "./dist/cjs/index.js"
8277
},
8378
"./promise": {
8479
"require": "./promise.js"

simple-git/promise.d.ts

+22-25
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import * as errors from './typings/errors';
2-
import * as types from './typings/types';
3-
import * as resp from './typings/response';
4-
import * as simpleGit from './typings/simple-git';
1+
import * as SimpleGitTypes from 'simple-git';
52

63
/**
74
* @deprecated
@@ -17,7 +14,7 @@ declare const simplegit: simplegit.SimpleGitExport;
1714
declare namespace simplegit {
1815

1916
type SimpleGitExport = ((basePath?: string) => simplegit.SimpleGit) & {
20-
CleanOptions: typeof types.CleanOptions
17+
CleanOptions: typeof SimpleGitTypes.CleanOptions
2118
};
2219

2320
/**
@@ -29,36 +26,36 @@ declare namespace simplegit {
2926
*
3027
* To upgrade, change all 'simple-git/promise' imports to just 'simple-git'
3128
*/
32-
type SimpleGit = simpleGit.SimpleGit;
29+
type SimpleGit = SimpleGitTypes.SimpleGit;
3330

3431
// errors
35-
type GitError = errors.GitError;
36-
type GitConstructError = errors.GitConstructError;
37-
type GitResponseError<T> = errors.GitResponseError<T>;
38-
type TaskConfigurationError = errors.TaskConfigurationError;
32+
type GitError = SimpleGitTypes.GitError;
33+
type GitConstructError = SimpleGitTypes.GitConstructError;
34+
type GitResponseError<T> = SimpleGitTypes.GitResponseError<T>;
35+
type TaskConfigurationError = SimpleGitTypes.TaskConfigurationError;
3936

4037
// responses
41-
type BranchSummary = resp.BranchSummary
42-
type CleanSummary = resp.CleanSummary;
43-
type CleanMode = types.CleanMode;
44-
type DiffResult = resp.DiffResult;
45-
type FetchResult = resp.FetchResult;
46-
type CommitResult = resp.CommitResult;
47-
type MergeResult = resp.MergeResult;
48-
type PullResult = resp.PullResult;
49-
type StatusResult = resp.StatusResult;
50-
type TagResult = resp.TagResult;
38+
type BranchSummary = SimpleGitTypes.BranchSummary
39+
type CleanSummary = SimpleGitTypes.CleanSummary;
40+
type CleanMode = SimpleGitTypes.CleanMode;
41+
type DiffResult = SimpleGitTypes.DiffResult;
42+
type FetchResult = SimpleGitTypes.FetchResult;
43+
type CommitResult = SimpleGitTypes.CommitResult;
44+
type MergeResult = SimpleGitTypes.MergeResult;
45+
type PullResult = SimpleGitTypes.PullResult;
46+
type StatusResult = SimpleGitTypes.StatusResult;
47+
type TagResult = SimpleGitTypes.TagResult;
5148

5249
// types
53-
type outputHandler = types.outputHandler
54-
type LogOptions<T = types.DefaultLogFields> = types.LogOptions<T>;
55-
type Options = types.Options;
50+
type outputHandler = SimpleGitTypes.outputHandler
51+
type LogOptions<T = SimpleGitTypes.DefaultLogFields> = SimpleGitTypes.LogOptions<T>;
52+
type Options = SimpleGitTypes.Options;
5653

5754
// deprecated
5855
/** @deprecated use MergeResult */
59-
type MergeSummary = resp.MergeSummary;
56+
type MergeSummary = SimpleGitTypes.MergeSummary;
6057
/** @deprecated use CommitResult */
61-
type CommitSummary = resp.CommitResult;
58+
type CommitSummary = SimpleGitTypes.CommitResult;
6259
}
6360

6461
/**

simple-git/scripts/package-json.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const { logger } = require('./log');
44

55
const log = logger('package.json');
66
const src = resolve(__dirname, '..', 'package.json');
7-
const out = resolve(__dirname, '..', 'dist', 'package.json');
87

98
(async function () {
109
log('Generating content');
@@ -16,14 +15,14 @@ const out = resolve(__dirname, '..', 'dist', 'package.json');
1615

1716
function save (content) {
1817
return new Promise((done, fail) =>
19-
writeFile(out, JSON.stringify(content, null, 2), 'utf8', (err) => {
18+
writeFile(src, JSON.stringify(content, null, 2), 'utf8', (err) => {
2019
err ? fail(err) : done();
2120
})
2221
);
2322
}
2423

2524
function createPackageJson() {
26-
const { publish, scripts, files, ...pkg } = require(src);
25+
const { publish, scripts, ...pkg } = require(src);
2726

2827
return {
2928
...pkg,

simple-git/src/lib/tasks/log.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import {
1010
appendTaskOptions,
1111
filterArray,
12+
filterPrimitives,
1213
filterString,
1314
filterType,
1415
trailingFunctionArgument,
@@ -62,7 +63,7 @@ interface ParsedLogOptions {
6263
commands: string[]
6364
}
6465

65-
function prettyFormat(format: { [key: string]: string | unknown }, splitter: string): [string[], string] {
66+
function prettyFormat(format: Record<string, string | unknown>, splitter: string): [string[], string] {
6667
const fields: string[] = [];
6768
const formatStr: string[] = [];
6869

@@ -76,19 +77,18 @@ function prettyFormat(format: { [key: string]: string | unknown }, splitter: str
7677
];
7778
}
7879

79-
function userOptions<T>(input: T): Exclude<Omit<T, keyof typeof excludeOptions>, undefined> {
80-
const output = {...input};
81-
Object.keys(input).forEach(key => {
82-
if (key in excludeOptions) {
83-
delete output[key as keyof T];
80+
function userOptions<T extends Options>(input: T): Options {
81+
return Object.keys(input).reduce((out, key) => {
82+
if (!(key in excludeOptions)) {
83+
out[key] = input[key];
8484
}
85-
});
86-
return output;
85+
return out;
86+
}, {} as Options);
8787
}
8888

89-
export function parseLogOptions<T extends Options>(opt: LogOptions<T> = {}, customArgs: string[] = []): ParsedLogOptions {
90-
const splitter = opt.splitter || SPLITTER;
91-
const format = opt.format || {
89+
export function parseLogOptions<T extends Options>(opt: Options | LogOptions<T> = {}, customArgs: string[] = []): ParsedLogOptions {
90+
const splitter = filterType(opt.splitter, filterString, SPLITTER);
91+
const format = !filterPrimitives(opt.format) && opt.format ? opt.format : {
9292
hash: '%H',
9393
date: opt.strictDate === false ? '%ai' : '%aI',
9494
message: '%s',
@@ -116,11 +116,11 @@ export function parseLogOptions<T extends Options>(opt: LogOptions<T> = {}, cust
116116
suffix.push(`${opt.from}${rangeOperator}${opt.to}`);
117117
}
118118

119-
if (opt.file) {
119+
if (filterString(opt.file)) {
120120
suffix.push('--follow', opt.file);
121121
}
122122

123-
appendTaskOptions(userOptions(opt), command);
123+
appendTaskOptions(userOptions(opt as Options), command);
124124

125125
return {
126126
fields,

0 commit comments

Comments
 (0)