-
-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To enable support for ES modules in TypeScript >=4.7 (enabled with `m…
…odule` and `moduleResolution` of `node16` or `nodenext` in the `tsconfig`), export `simpleGit` as a named export instead of as the default export from the `simple-git` package. Add `simpleGit` to the TypeScript types while keeping default export for backward compatibility.
- Loading branch information
Showing
27 changed files
with
272 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { strictEqual } from "assert"; | ||
|
||
export async function suite(name, simpleGit, ResetMode) { | ||
exec(`${name}: imports default`, async () => { | ||
strictEqual( | ||
await simpleGit().checkIsRepo(), | ||
true, | ||
'expected the current directory to be a valid git root', | ||
); | ||
}); | ||
|
||
exec(`${name}: imports named exports`, async () => { | ||
strictEqual( | ||
/hard/.test(ResetMode.HARD), | ||
true, | ||
'expected valid ResetMode enum' | ||
); | ||
}); | ||
} | ||
|
||
function exec (name, runner) { | ||
runner() | ||
.then(() => console.log(`${ name }: OK`)) | ||
.catch((e) => { | ||
console.error(`${ name }: ${ e.message }`); | ||
throw e; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { simpleGit, ResetMode } from 'simple-git'; | ||
import { suite } from './suite.mjs'; | ||
|
||
await suite('import named', simpleGit, ResetMode); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import simpleGit, { ResetMode } from 'simple-git'; | ||
import { suite } from './suite.mjs'; | ||
|
||
await suite('import default', simpleGit, ResetMode); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { default as simpleGit, ResetMode } from 'simple-git'; | ||
import { suite } from './suite.mjs'; | ||
|
||
await suite('import default-as', simpleGit, ResetMode); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,3 @@ | ||
import { strictEqual } from 'assert'; | ||
import simpleGit, { ResetMode } from 'simple-git'; | ||
|
||
exec('imports default', async () => { | ||
strictEqual( | ||
await simpleGit().checkIsRepo(), | ||
true, | ||
'expected the current directory to be a valid git root', | ||
); | ||
}); | ||
|
||
exec('imports named exports', async () => { | ||
strictEqual( | ||
/hard/.test(ResetMode.HARD), | ||
true, | ||
'expected valid ResetMode enum' | ||
); | ||
}); | ||
|
||
function exec (name, runner) { | ||
runner() | ||
.then(() => console.log(`${ name }: OK`)) | ||
.catch((e) => { | ||
console.error(`${ name }: ${ e.message }`); | ||
throw e; | ||
}); | ||
} | ||
import './test-default.mjs'; | ||
import './test-default-as.mjs'; | ||
import './test-named.mjs'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const {strictEqual} = require('assert'); | ||
|
||
module.exports = { | ||
async suite (name, simpleGit, ResetMode) { | ||
exec(`${ name }: imports default`, async () => { | ||
strictEqual( | ||
await simpleGit().checkIsRepo(), | ||
true, | ||
'expected the current directory to be a valid git root', | ||
); | ||
}); | ||
|
||
exec(`${ name }: imports named exports`, async () => { | ||
strictEqual( | ||
/hard/.test(ResetMode.HARD), | ||
true, | ||
'expected valid ResetMode enum' | ||
); | ||
}); | ||
} | ||
}; | ||
|
||
function exec (name, runner) { | ||
runner() | ||
.then(() => console.log(`${ name }: OK`)) | ||
.catch((e) => { | ||
console.error(`${ name }: ${ e.message }`); | ||
throw e; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const {default: simpleGit, ResetMode} = require('simple-git'); | ||
const {suite} = require('./suite'); | ||
|
||
(async () => { | ||
await suite('require default-as', simpleGit, ResetMode); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,7 @@ | ||
const {default: simpleGit, ResetMode} = require('simple-git'); | ||
const {strictEqual} = require("assert"); | ||
const simpleGit = require('simple-git'); | ||
const {suite} = require('./suite'); | ||
|
||
exec('requires default', async () => { | ||
strictEqual( | ||
await simpleGit().checkIsRepo(), | ||
true, | ||
'expected the current directory to be a valid git root', | ||
); | ||
}); | ||
(async () => { | ||
await suite('require default', simpleGit, simpleGit.ResetMode); | ||
})(); | ||
|
||
exec('imports named exports', async () => { | ||
strictEqual( | ||
/hard/.test(ResetMode.HARD), | ||
true, | ||
'expected valid ResetMode enum' | ||
); | ||
}); | ||
|
||
function exec (name, runner) { | ||
runner() | ||
.then(() => console.log(`${ name }: OK`)) | ||
.catch((e) => { | ||
console.error(`${ name }: ${ e.message }`); | ||
throw e; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const {simpleGit, ResetMode} = require('simple-git'); | ||
const {suite} = require('./suite'); | ||
|
||
(async () => { | ||
await suite('require named', simpleGit, ResetMode); | ||
})(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,3 @@ | ||
const simpleGit = require('simple-git'); | ||
const {strictEqual} = require("assert"); | ||
|
||
exec('requires default', async () => { | ||
strictEqual( | ||
await simpleGit().checkIsRepo(), | ||
true, | ||
'expected the current directory to be a valid git root', | ||
); | ||
}); | ||
|
||
exec('imports named exports', async () => { | ||
strictEqual( | ||
/hard/.test(simpleGit.ResetMode.HARD), | ||
true, | ||
'expected valid ResetMode enum' | ||
); | ||
}); | ||
|
||
function exec (name, runner) { | ||
runner() | ||
.then(() => console.log(`${ name }: OK`)) | ||
.catch((e) => { | ||
console.error(`${ name }: ${ e.message }`); | ||
throw e; | ||
}); | ||
} | ||
require('./test-default'); | ||
require('./test-default-as'); | ||
require('./test-named'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/test-typescript-consumer/test/ts-named-import.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import simpleGit, { gitP, CleanOptions, SimpleGit, TaskConfigurationError } from 'simple-git'; | ||
|
||
describe('simple-git', () => { | ||
|
||
describe('default export', () => { | ||
it('is the simple-git factory', async () => { | ||
expect(await simpleGit().checkIsRepo()).toBe(true); | ||
}); | ||
|
||
it('builds exported types', async () => { | ||
const git: SimpleGit = simpleGit(); | ||
|
||
expect(git).not.toBeUndefined(); | ||
}); | ||
}); | ||
|
||
describe('gitP export', () => { | ||
it('is the simple-git factory', async () => { | ||
expect(await gitP().checkIsRepo()).toBe(true); | ||
}); | ||
|
||
it('builds exported types', async () => { | ||
const git: SimpleGit = gitP(); | ||
|
||
expect(git).not.toBeUndefined(); | ||
}); | ||
}); | ||
|
||
it('default export is the simple-git factory', async () => { | ||
expect(await simpleGit().checkIsRepo()).toBe(true); | ||
}); | ||
|
||
it('named type exports', async () => { | ||
const git: SimpleGit = simpleGit(); | ||
|
||
expect(git).not.toBeUndefined(); | ||
}); | ||
|
||
it('named class constructors', async () => { | ||
expect(new TaskConfigurationError('foo')).toBeInstanceOf(TaskConfigurationError); | ||
}); | ||
|
||
it('named enums', async () => { | ||
expect(CleanOptions.DRY_RUN).toBe('n'); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('@simple-git/babel-config')(true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "@simple-git/test-typescript-esm-consumer", | ||
"private": true, | ||
"version": "1.0.0", | ||
"jest": { | ||
"roots": [ | ||
"<rootDir>/test/" | ||
], | ||
"testMatch": [ | ||
"**/test/*.spec.ts" | ||
] | ||
}, | ||
"scripts": { | ||
"test": "jest" | ||
}, | ||
"dependencies": { | ||
"@simple-git/babel-config": "^1.0.0", | ||
"simple-git": "^3.0.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/steveukx/git-js.git", | ||
"directory": "packages/test-typescript-consumer" | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
packages/test-typescript-esm-consumer/test/ts-default-renamed-import.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { default as simpleGit, CleanOptions, SimpleGit, TaskConfigurationError } from 'simple-git'; | ||
|
||
describe('simple-git', () => { | ||
|
||
describe('renamed default export', () => { | ||
it('is the simple-git factory', async () => { | ||
expect(await simpleGit().checkIsRepo()).toBe(true); | ||
}); | ||
|
||
it('builds exported types', async () => { | ||
const git: SimpleGit = simpleGit(); | ||
|
||
expect(git).not.toBeUndefined(); | ||
}); | ||
}); | ||
|
||
it('named type exports', async () => { | ||
const git: SimpleGit = simpleGit(); | ||
|
||
expect(git).not.toBeUndefined(); | ||
}); | ||
|
||
it('named class constructors', async () => { | ||
expect(new TaskConfigurationError('foo')).toBeInstanceOf(TaskConfigurationError); | ||
}); | ||
|
||
it('named enums', async () => { | ||
expect(CleanOptions.DRY_RUN).toBe('n'); | ||
}); | ||
|
||
}); |
31 changes: 31 additions & 0 deletions
31
packages/test-typescript-esm-consumer/test/ts-named-import.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { simpleGit, CleanOptions, SimpleGit, TaskConfigurationError } from 'simple-git'; | ||
|
||
describe('simple-git', () => { | ||
|
||
describe('named export', () => { | ||
it('is the simple-git factory', async () => { | ||
expect(await simpleGit().checkIsRepo()).toBe(true); | ||
}); | ||
|
||
it('builds exported types', async () => { | ||
const git: SimpleGit = simpleGit(); | ||
|
||
expect(git).not.toBeUndefined(); | ||
}); | ||
}); | ||
|
||
it('named type exports', async () => { | ||
const git: SimpleGit = simpleGit(); | ||
|
||
expect(git).not.toBeUndefined(); | ||
}); | ||
|
||
it('named class constructors', async () => { | ||
expect(new TaskConfigurationError('foo')).toBeInstanceOf(TaskConfigurationError); | ||
}); | ||
|
||
it('named enums', async () => { | ||
expect(CleanOptions.DRY_RUN).toBe('n'); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2020", | ||
"module": "node16", | ||
"moduleResolution": "node16", | ||
"noEmit": true, | ||
"allowSyntheticDefaultImports": true, | ||
"baseUrl": ".", | ||
// "emitDecoratorMetadata": true, | ||
// "experimentalDecorators": true, | ||
// "forceConsistentCasingInFileNames": true, | ||
// "incremental": true, | ||
// "noFallthroughCasesInSwitch": false, | ||
// "noImplicitAny": false, | ||
// "outDir": "./dist", | ||
// "removeComments": true, | ||
// "skipLibCheck": true, | ||
// "sourceMap": true, | ||
// "strictBindCallApply": true, | ||
// "strictNullChecks": false, | ||
} | ||
} |
Oops, something went wrong.