Skip to content

Commit

Permalink
support yarn detection as well
Browse files Browse the repository at this point in the history
  • Loading branch information
sebas2day committed Mar 3, 2021
1 parent ebc6e62 commit 2eda166
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ async function getYarnProductionDependencies(root: string, manifest: Manifest, p
return result;
}

async function getYarnDependencies(cwd: string, manifest: Manifest, packagedDependencies?: string[]): Promise<SourceAndDestination[]> {
const root = findWorkspaceRoot(cwd) || cwd;
async function getYarnDependencies(cwd: string, root: string, manifest: Manifest, packagedDependencies?: string[]): Promise<SourceAndDestination[]> {
const result: SourceAndDestination[] = [{
src: cwd,
dest: ''
Expand All @@ -203,9 +202,9 @@ async function getYarnDependencies(cwd: string, manifest: Manifest, packagedDepe
return _.uniqBy(result, 'src');
}

export async function detectYarn(cwd: string) {
export async function detectYarn(root: string) {
for (const file of ['yarn.lock', '.yarnrc']) {
if (await exists(path.join(cwd, file))) {
if (await exists(path.join(root, file))) {
if (!process.env['VSCE_TESTS']) {
log.info(
`Detected presence of ${file}. Using 'yarn' instead of 'npm' (to override this pass '--no-yarn' on the command line).`
Expand All @@ -223,8 +222,9 @@ export async function getDependencies(
useYarn?: boolean,
packagedDependencies?: string[]
): Promise<SourceAndDestination[]> {
return (useYarn !== undefined ? useYarn : await detectYarn(cwd))
? await getYarnDependencies(cwd, manifest, packagedDependencies)
const root = findWorkspaceRoot(cwd) || cwd;
return (useYarn !== undefined ? useYarn : await detectYarn(root))
? await getYarnDependencies(cwd, root, manifest, packagedDependencies)
: await getNpmDependencies(cwd);
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ describe('collect', function () {

assert.equal(manifest.name, 'package-b');

const files = await collect(manifest, { cwd, useYarn: true }) as ILocalFile[];
const files = await collect(manifest, { cwd }) as ILocalFile[];

[
{
Expand Down

0 comments on commit 2eda166

Please sign in to comment.