This repository has been archived by the owner on Dec 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(package-manager): determined manager when not provided in results
- Loading branch information
Showing
10 changed files
with
131 additions
and
4 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
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 * as core from '@form8ion/core'; | ||
import {packageManagers} from '@form8ion/javascript-core'; | ||
import any from '@travi/any'; | ||
import {assert} from 'chai'; | ||
import sinon from 'sinon'; | ||
import derive from './package-manager'; | ||
|
||
suite('package manager', () => { | ||
let sandbox; | ||
const projectRoot = any.string(); | ||
|
||
setup(() => { | ||
sandbox = sinon.createSandbox(); | ||
|
||
sandbox.stub(core, 'fileExists'); | ||
}); | ||
|
||
teardown(() => sandbox.restore()); | ||
|
||
test('that an already defined manager is returned directly', async () => { | ||
const packageManager = any.word(); | ||
|
||
assert.equal(await derive({packageManager}), packageManager); | ||
}); | ||
|
||
test('that `npm` is returned when a package lockfile exists', async () => { | ||
core.fileExists.withArgs(`${projectRoot}/package-lock.json`).resolves(true); | ||
|
||
assert.equal(await derive({projectRoot}), packageManagers.NPM); | ||
}); | ||
|
||
test('that `yarn` is returned when a yarn lockfile exists', async () => { | ||
core.fileExists.withArgs(`${projectRoot}/yarn.lock`).resolves(true); | ||
|
||
assert.equal(await derive({projectRoot}), packageManagers.YARN); | ||
}); | ||
|
||
test('that an error is thrown when no manager is provided and no lockfile is found', async () => { | ||
try { | ||
await derive({projectRoot}); | ||
|
||
throw new Error('test should have thrown before this point'); | ||
} catch (e) { | ||
assert.equal(e.message, 'Package-manager could not be determined'); | ||
} | ||
}); | ||
}); |
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,16 @@ | ||
import {fileExists} from '@form8ion/core'; | ||
import {packageManagers} from '@form8ion/javascript-core'; | ||
|
||
export default async function ({projectRoot, packageManager}) { | ||
if (packageManager) return packageManager; | ||
|
||
if (await fileExists(`${projectRoot}/package-lock.json`)) { | ||
return packageManagers.NPM; | ||
} | ||
|
||
if (await fileExists(`${projectRoot}/yarn.lock`)) { | ||
return packageManagers.YARN; | ||
} | ||
|
||
throw new Error('Package-manager could not be determined'); | ||
} |
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
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
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