Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check peerDependenciesMeta for Optional Dependencies #83

Merged
merged 1 commit into from Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/finders.js
Expand Up @@ -117,6 +117,16 @@ function getDependencies(filename, basedir) {
const currentModulePath = path.join(currentModule.path, '..')
const packageJson = currentModule.packageJson

if (packageJson.peerDependenciesMeta) {
packageJson.optionalDependencies = packageJson.optionalDependencies || {}

for (const depKey in packageJson.peerDependenciesMeta) {
if (packageJson.peerDependenciesMeta[depKey].optional) {
packageJson.optionalDependencies[depKey] = packageJson.peerDependencies[depKey]
}
}
}

if (modulePaths.has(currentModulePath)) {
continue
}
Expand Down
7 changes: 7 additions & 0 deletions src/fixtures/node-module-peer-optional/function.js
@@ -0,0 +1,7 @@
try {
// eslint-disable-next-line node/no-missing-require
require('consistent-ids')
// eslint-disable-next-line no-empty
} catch (error) {}

module.exports = true
11 changes: 11 additions & 0 deletions src/fixtures/node-module-peer-optional/package.json
@@ -0,0 +1,11 @@
{
"peerDependencies": {
"consistent-ids": "0.1.1"
},
"peerDependenciesMeta": {
"consistent-ids": {
"optional": true
}
}
}

4 changes: 4 additions & 0 deletions src/main.test.js
Expand Up @@ -68,6 +68,10 @@ test.skip('Ignore missing whitelisted optional dependencies', async t => {
await zipNode(t, 'node-module-optional-whitelist')
})

test.skip('Ignore missing optional peer dependencies', async t => {
await zipNode(t, 'node-module-peer-optional')
})

test('Can require local files', async t => {
await zipNode(t, 'local-require')
})
Expand Down