Skip to content

Commit

Permalink
fix: allow to skip git check
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Bekrin committed Apr 23, 2019
1 parent 46129dc commit 3237eb3
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
7 changes: 5 additions & 2 deletions packages/spire-test-utils/lib/create-fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ const { outputFile, remove } = require('fs-extra');
const execa = require('execa');
const shortid = require('shortid');

async function createFixture(structure = {}, identifier = shortid.generate()) {
async function createFixture(
structure = {},
{ identifier = shortid.generate(), git = true } = {}
) {
const cwd = join(tmpdir(), identifier);
const files = Object.keys(structure);
await Promise.all(
files.map(file => outputFile(join(cwd, file), structure[file], 'utf8'))
);
await execa('git', ['init'], { cwd });
if (git) await execa('git', ['init'], { cwd });
return {
get cwd() {
return cwd;
Expand Down
11 changes: 10 additions & 1 deletion packages/spire/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Extensible JavaScript toolbox management.
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->


- [Motivation](#motivation)
- [Quick Start](#quick-start)
- [Configuration](#configuration)
Expand All @@ -16,6 +15,7 @@ Extensible JavaScript toolbox management.
- [Writing a Config](#writing-a-config)
- [Writing a Plugin](#writing-a-plugin)
- [Migrating to Spire](#migrating-to-spire)
- [Using without Git](#using-without-git)
- [API](#api)
- [CLI](#cli)
- [`spire`](#spire)
Expand Down Expand Up @@ -265,6 +265,14 @@ how to do this.
projects and [setup Spire](#quick-start) with it. Make sure to delete the
dependencies it replaces. At this point you're done!

### Using without Git

At the moment Spire has a hard dependency on a Git repository to resolve
monorepo project root. This most likely to be reviewed in the future, but
meanwhile it is part of the core, you can export `SKIP_PREFLIGHT_CHECK=true`
environment variable to disable this check. The idea and name of this flag is
borrowed from [create-react-app].

## API

### CLI
Expand Down Expand Up @@ -369,3 +377,4 @@ MIT &copy; [ResearchGate](https://github.com/researchgate)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
[symbol]:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol
[create-react-app]: https://github.com/facebook/create-react-app
15 changes: 12 additions & 3 deletions packages/spire/lib/plugins/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,25 @@ function git(
) {
return {
name: 'spire-git-support',
async setup({ cwd }) {
// Make sure project is a Git repo
async setup({ cwd, env }) {
try {
setState({
root: await execa.stdout('git', ['rev-parse', '--show-toplevel'], {
cwd,
}),
});
} catch (reason) {
throw new SpireError('Project needs to be in a Git repository');
if (Boolean(env.SKIP_PREFLIGHT_CHECK)) {
setState({ root: cwd });
} else {
throw new SpireError(
[
'Project is not in a Git repository.',
'Set `SKIP_PREFLIGHT_CHECK=true` to disable this check,',
'but be advised that some plugins may fail.',
].join(' ')
);
}
}
},
async skip({ logger }) {
Expand Down
18 changes: 17 additions & 1 deletion packages/spire/tests/verify.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,24 @@ describe('spire', () => {
}),
});
await expect(fixture.run('spire', ['--debug'])).rejects.toMatchObject({
stderr: /Project needs to be in a Git repository/,
stderr: /Project is not in a Git repository\. Set `SKIP_PREFLIGHT_CHECK=true` to disable this check, but be advised that some plugins may fail\./,
});
await fixture.clean();
});

it('allows to skip git check', async () => {
const fixture = await createFixture(
{
'package.json': JSON.stringify({
name: 'spire-verify',
spire: { extends: [] },
}),
},
{ git: false }
);
await expect(
fixture.run('spire', ['--help'], { env: { SKIP_PREFLIGHT_CHECK: true } })
).resolves.toBeDefined();
await fixture.clean();
});
});

0 comments on commit 3237eb3

Please sign in to comment.