Skip to content

Commit

Permalink
chore: make 'http' param required (#1030)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: isomorphic-git no longer has a node HTTP client hard-coded into the `main` file and a browser HTTP client hard-coded into the `module` file. The HTTP clients are now in their own files; users pick one, import it, and provide it to functions that make requests.
  • Loading branch information
billiegoose committed Feb 7, 2020
1 parent 8aaa232 commit 47abb7a
Show file tree
Hide file tree
Showing 30 changed files with 124 additions and 65 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -64,7 +64,7 @@ At the time of writing, the following breaking changes are planned:
- [ ] To go along with that, I'm experimenting with a way to make the API more aesthetic, eliminating the `emitter` plugin/argument and letting you chain event listeners onto running commands directly. NOTE: need to make sure there's no race condition between adding the event listeners and starting running the command.
- [ ] This also provides an aesthetic way to cancel / stop running commands.
- [x] break `config` into `getConfig` and `setConfig` or something.
- [ ] Make `http` an external required dependency just like `fs` [#938](https://github.com/isomorphic-git/isomorphic-git/issues/938)
- [x] Make `http` an external required dependency just like `fs` [#938](https://github.com/isomorphic-git/isomorphic-git/issues/938)
- [ ] I should probably normalize on timestamps and get rid of the `date` options.
- [x] Remove the `noOverwrite` option from `init` and make that the new behavior.
- [ ] Oh, and I should move all the error strings into a separate JSON file that can be fetched lazily in production.
Expand Down
6 changes: 4 additions & 2 deletions __tests__/__helpers__/generate-docs.js
Expand Up @@ -148,9 +148,10 @@ async function gendoc (file, filepath) {
if (param.name === '_' || param.name === 'args') continue

let name = param.name.replace('_.', '').replace('args.', '')
const shouldLink = name.startsWith('on')
const actualName = name
const shouldLink =
actualName.startsWith('on') || name === 'http' || name === 'fs'
if (!param.optional) name = `**${name}**`
if (shouldLink) name = `[${name}](./${name})`

let type = param.type.names.map(escapeType).join(' | ')
if (param.type.names[0] === 'function') {
Expand Down Expand Up @@ -180,6 +181,7 @@ async function gendoc (file, filepath) {
name = `**${name}**`
}
}
if (shouldLink) name = `[${name}](./${actualName})`
rows.push([name, escapeType(type), escapeType(description)])
}
}
Expand Down
7 changes: 7 additions & 0 deletions __tests__/test-clone.js
Expand Up @@ -2,6 +2,7 @@
const { makeFixture } = require('./__helpers__/FixtureFS.js')

const { clone } = require('isomorphic-git')
const { http } = require('isomorphic-git/http')

// this is so it works with either Node local tests or Browser WAN tests
const localhost =
Expand All @@ -16,6 +17,7 @@ describe('clone', () => {
const { fs, dir, gitdir } = await makeFixture('isomorphic-git')
await clone({
fs,
http,
dir,
gitdir,
depth: 1,
Expand All @@ -37,6 +39,7 @@ describe('clone', () => {
const { fs, dir, gitdir } = await makeFixture('isomorphic-git')
await clone({
fs,
http,
dir,
gitdir,
depth: 1,
Expand All @@ -58,6 +61,7 @@ describe('clone', () => {
const { fs, dir, gitdir } = await makeFixture('isomorphic-git')
await clone({
fs,
http,
dir,
gitdir,
depth: 1,
Expand All @@ -82,6 +86,7 @@ describe('clone', () => {
try {
await clone({
fs,
http,
dir,
gitdir,
depth: 1,
Expand All @@ -101,6 +106,7 @@ describe('clone', () => {
const { fs, dir, gitdir } = await makeFixture('test-clone-karma')
await clone({
fs,
http,
dir,
gitdir,
depth: 1,
Expand All @@ -123,6 +129,7 @@ describe('clone', () => {
const { fs, dir, gitdir } = await makeFixture('test-clone-empty')
await clone({
fs,
http,
dir,
gitdir,
depth: 1,
Expand Down
20 changes: 17 additions & 3 deletions __tests__/test-fetch.js
Expand Up @@ -2,6 +2,7 @@
const { makeFixture } = require('./__helpers__/FixtureFS.js')

const { sleep } = require('isomorphic-git/internal-apis')
const { http } = require('isomorphic-git/http')
const { E, setConfig, fetch } = require('isomorphic-git')

// this is so it works with either Node local tests or Browser WAN tests
Expand All @@ -20,6 +21,7 @@ describe('fetch', () => {
// Smoke Test
await fetch({
fs,
http,
gitdir,
singleBranch: true,
remote: 'origin',
Expand All @@ -44,6 +46,7 @@ describe('fetch', () => {
// Test
await fetch({
fs,
http,
gitdir,
onMessage: async x => {
output.push(x)
Expand All @@ -65,6 +68,7 @@ describe('fetch', () => {
// Now test deepen
await fetch({
fs,
http,
gitdir,
depth: 2,
singleBranch: true,
Expand All @@ -89,6 +93,7 @@ describe('fetch', () => {
try {
await fetch({
fs,
http,
gitdir,
depth: 1,
singleBranch: true,
Expand All @@ -115,6 +120,7 @@ describe('fetch', () => {
try {
await fetch({
fs,
http,
gitdir,
depth: 1,
singleBranch: true,
Expand Down Expand Up @@ -142,6 +148,7 @@ describe('fetch', () => {
// Test
await fetch({
fs,
http,
gitdir,
since: new Date(1506571200000),
singleBranch: true,
Expand All @@ -164,6 +171,7 @@ describe('fetch', () => {
// Test
await fetch({
fs,
http,
gitdir,
exclude: ['v0.0.5'],
singleBranch: true,
Expand All @@ -186,6 +194,7 @@ describe('fetch', () => {
// Test
await fetch({
fs,
http,
gitdir,
depth: 1,
singleBranch: true,
Expand All @@ -198,6 +207,7 @@ describe('fetch', () => {
// Now test deepen
await fetch({
fs,
http,
gitdir,
relative: true,
depth: 1,
Expand All @@ -223,6 +233,7 @@ describe('fetch', () => {
try {
await fetch({
fs,
http,
gitdir,
since: new Date(1506571200000),
singleBranch: true,
Expand All @@ -239,8 +250,9 @@ describe('fetch', () => {
it('fetch empty repository from git-http-mock-server', async () => {
const { fs, dir, gitdir } = await makeFixture('test-empty')
await fetch({
dir,
fs,
http,
dir,
gitdir,
depth: 1,
url: `http://${localhost}:8888/test-empty.git`
Expand All @@ -265,8 +277,9 @@ describe('fetch', () => {
true
)
const { pruned } = await fetch({
dir,
fs,
http,
dir,
gitdir,
depth: 1,
prune: true
Expand All @@ -289,8 +302,9 @@ describe('fetch', () => {
const oldValue = await fs.read(`${gitdir}/refs/tags/v1.0.0`, 'utf8')
try {
await fetch({
dir,
fs,
http,
dir,
gitdir,
depth: 1,
tags: true,
Expand Down
3 changes: 3 additions & 0 deletions __tests__/test-getRemoteInfo.js
Expand Up @@ -3,6 +3,7 @@
const snapshots = require('./__snapshots__/test-getRemoteInfo.js.snap')
const registerSnapshots = require('./__helpers__/jasmine-snapshots')
const { E, getRemoteInfo } = require('isomorphic-git')
const { http } = require('isomorphic-git/http')

// this is so it works with either Node local tests or Browser WAN tests
const localhost =
Expand All @@ -14,6 +15,7 @@ describe('getRemoteInfo', () => {
})
it('getRemoteInfo', async () => {
const info = await getRemoteInfo({
http,
url: `http://${localhost}:8888/test-dumb-http-server.git`
})
expect(info).not.toBeNull()
Expand All @@ -27,6 +29,7 @@ describe('getRemoteInfo', () => {
let error = null
try {
await getRemoteInfo({
http,
url: `http://${localhost}:9876/base/__tests__/__fixtures__/test-dumb-http-server.git`
})
} catch (err) {
Expand Down
11 changes: 11 additions & 0 deletions __tests__/test-hosting-providers.js
Expand Up @@ -2,6 +2,7 @@
const { makeFixture } = require('./__helpers__/FixtureFS.js')

const { fetch, push } = require('isomorphic-git')
const { http } = require('isomorphic-git/http')

// this is so it works with either Node local tests or Browser WAN tests
const localhost =
Expand All @@ -23,6 +24,7 @@ describe('Hosting Providers', () => {
// Test
const res = await fetch({
fs,
http,
gitdir,
corsProxy: process.browser ? `http://${localhost}:9999` : undefined,
username: 'tester-at-260687965765',
Expand All @@ -48,6 +50,7 @@ describe('Hosting Providers', () => {
// Test
const res = await push({
fs,
http,
gitdir,
corsProxy: process.browser ? `http://${localhost}:9999` : undefined,
username: 'tester-at-260687965765',
Expand Down Expand Up @@ -75,6 +78,7 @@ describe('Hosting Providers', () => {
// Test
const res = await fetch({
fs,
http,
noGitSuffix: true,
gitdir,
// corsProxy: process.browser ? `http://${localhost}:9999` : undefined,
Expand All @@ -99,6 +103,7 @@ describe('Hosting Providers', () => {
// Test
const res = await push({
fs,
http,
noGitSuffix: true,
gitdir,
// corsProxy: process.browser ? `http://${localhost}:9999` : undefined,
Expand Down Expand Up @@ -129,6 +134,7 @@ describe('Hosting Providers', () => {
// Test
const res = await push({
fs,
http,
gitdir,
corsProxy: process.browser ? `http://${localhost}:9999` : undefined,
username: 'isomorphic-git',
Expand Down Expand Up @@ -156,6 +162,7 @@ describe('Hosting Providers', () => {
// Test
const res = await fetch({
fs,
http,
gitdir,
corsProxy: process.browser ? `http://${localhost}:9999` : undefined,
username: 'isomorphic-git',
Expand Down Expand Up @@ -183,6 +190,7 @@ describe('Hosting Providers', () => {
// Test
const res = await fetch({
fs,
http,
gitdir,
corsProxy: process.browser ? `http://${localhost}:9999` : undefined,
token: token,
Expand All @@ -207,6 +215,7 @@ describe('Hosting Providers', () => {
// Test
const res = await push({
fs,
http,
gitdir,
corsProxy: process.browser ? `http://${localhost}:9999` : undefined,
token: token,
Expand Down Expand Up @@ -235,6 +244,7 @@ describe('Hosting Providers', () => {
// Test
const res = await fetch({
fs,
http,
gitdir,
corsProxy: process.browser ? `http://${localhost}:9999` : undefined,
username: 'isomorphic-git-test-push',
Expand All @@ -260,6 +270,7 @@ describe('Hosting Providers', () => {
// Test
const res = await push({
fs,
http,
gitdir,
corsProxy: process.browser ? `http://${localhost}:9999` : undefined,
username: 'isomorphic-git-test-push',
Expand Down
2 changes: 1 addition & 1 deletion __tests__/test-plugin-http.js
Expand Up @@ -2,7 +2,7 @@
const { makeFixture } = require('./__helpers__/FixtureFS.js')

const { clone } = require('isomorphic-git')
const { http } = require('isomorphic-git/internal-apis')
const { http } = require('isomorphic-git/http')

// this is so it works with either Node local tests or Browser WAN tests
const localhost =
Expand Down
3 changes: 3 additions & 0 deletions __tests__/test-plugin_credentialManager.js
Expand Up @@ -2,6 +2,7 @@
const { makeFixture } = require('./__helpers__/FixtureFS.js')

const { setConfig, push, E } = require('isomorphic-git')
const { http } = require('isomorphic-git/http')

// this is so it works with either Node local tests or Browser WAN tests
const localhost =
Expand All @@ -23,6 +24,7 @@ describe('credentialManager', () => {
let rejectedCalled = false
await push({
fs,
http,
gitdir,
remote: 'auth',
ref: 'master',
Expand Down Expand Up @@ -61,6 +63,7 @@ describe('credentialManager', () => {
try {
await push({
fs,
http,
gitdir,
remote: 'auth',
ref: 'master',
Expand Down

0 comments on commit 47abb7a

Please sign in to comment.