Skip to content
Permalink
Browse files

fix(headless): don't skip optional deps during forced install

  • Loading branch information...
zkochan committed Jan 18, 2019
1 parent dc9c627 commit 3f0cb79ccca17aa260eb4cf835c40740c399698f
@@ -24,6 +24,7 @@ export default function filterByImportersAndEngine (
engineStrict: boolean,
defaultRegistry: string,
include: { [dependenciesField in DependenciesField]: boolean },
includeIncompatiblePackages?: boolean,
failOnMissingDependencies: boolean,
prefix: string,
skipped: Set<string>,
@@ -48,6 +49,7 @@ export default function filterByImportersAndEngine (
engineStrict: opts.engineStrict,
failOnMissingDependencies: opts.failOnMissingDependencies,
include: opts.include,
includeIncompatiblePackages: opts.includeIncompatiblePackages === true,
prefix: opts.prefix,
skipped: opts.skipped,
}) || {}
@@ -85,6 +87,7 @@ function pickPkgsWithAllDeps (
engineStrict: boolean,
failOnMissingDependencies: boolean,
include: { [dependenciesField in DependenciesField]: boolean },
includeIncompatiblePackages: boolean,
prefix: string,
skipped: Set<string>,
},
@@ -110,6 +113,7 @@ function pkgAllDeps (
engineStrict: boolean,
failOnMissingDependencies: boolean,
include: { [dependenciesField in DependenciesField]: boolean },
includeIncompatiblePackages: boolean,
prefix: string,
skipped: Set<string>,
},
@@ -142,7 +146,7 @@ function pkgAllDeps (
os: pkgSnapshot.os,
}
// TODO: relDepPath is not the package ID. Should be fixed
installable = packageIsInstallable(pkgSnapshot.id || relDepPath, pkg, {
installable = opts.includeIncompatiblePackages || packageIsInstallable(pkgSnapshot.id || relDepPath, pkg, {
engineStrict: opts.engineStrict,
nodeVersion: opts.currentEngine.nodeVersion,
optional: pkgSnapshot.optional === true,
@@ -176,6 +176,7 @@ export default async (opts: HeadlessOptions) => {
currentEngine: opts.currentEngine,
engineStrict: opts.engineStrict,
failOnMissingDependencies: true,
includeIncompatiblePackages: opts.force === true,
prefix: shrinkwrapDirectory,
})
const res = await shrinkwrapToDepGraph(
@@ -192,9 +192,13 @@ test('optional subdependency is skipped', async (t: tape.Test) => {

await addDependenciesToPackage(['pkg-with-optional', 'dep-of-optional-pkg'], await testDefaults({ reporter }))

const modulesInfo = await readYamlFile<{ skipped: string[] }>(path.join('node_modules', '.modules.yaml'))
{
const modulesInfo = await readYamlFile<{ skipped: string[] }>(path.join('node_modules', '.modules.yaml'))
t.deepEqual(modulesInfo.skipped, ['localhost+4873/not-compatible-with-any-os/1.0.0'], 'optional subdep skipped')
}

t.deepEqual(modulesInfo.skipped, ['localhost+4873/not-compatible-with-any-os/1.0.0'], 'optional subdep skipped')
t.ok(await exists('node_modules/.localhost+4873/pkg-with-optional/1.0.0'), 'regular dependency linked')
t.notOk(await exists('node_modules/.localhost+4873/not-compatible-with-any-os/1.0.0'), 'optional dependency not linked')

const logMatcher = sinon.match({
package: {
@@ -206,6 +210,25 @@ test('optional subdependency is skipped', async (t: tape.Test) => {
})
const reportedTimes = reporter.withArgs(logMatcher).callCount
t.equal(reportedTimes, 1, 'skipping optional dependency is logged')

// TODO: move next case to @pnpm/headless tests
await mutateModules(
[
{
buildIndex: 0,
mutation: 'install',
prefix: process.cwd(),
},
],
await testDefaults({ force: true, frozenShrinkwrap: true }),
)

t.ok(await exists('node_modules/.localhost+4873/not-compatible-with-any-os/1.0.0'), 'optional dependency linked after forced headless install')

{
const modulesInfo = await readYamlFile<{ skipped: string[] }>(path.join('node_modules', '.modules.yaml'))
t.deepEqual(modulesInfo.skipped, [], 'optional subdep removed from skipped list')
}
})

test('not installing optional dependencies when optional is false', async (t: tape.Test) => {

0 comments on commit 3f0cb79

Please sign in to comment.
You can’t perform that action at this time.