yarn-pnp-test
Advanced tools
Comparing version 0.1.0-beta.24 to 0.1.0-beta.25
@@ -18,3 +18,3 @@ { | ||
}, | ||
"version": "0.1.0-beta.24" | ||
"version": "0.1.0-beta.25" | ||
} |
37
pnp.js
@@ -1,6 +0,10 @@ | ||
#!/usr/bin/env node | ||
import path from 'path'; | ||
const path = require('path'); | ||
import { isObject, isObjectWithStringProp } from './validation'; | ||
const getBinPath = (packageJson, binName) => { | ||
const getPartialBinPath = (packageJson, binName) => { | ||
if (!isObject(packageJson)) { | ||
throw new Error('package.json not found'); | ||
} | ||
if (typeof packageJson.bin === 'string') { | ||
@@ -10,15 +14,10 @@ return packageJson.bin; | ||
if ( | ||
typeof packageJson.bin === 'object' && | ||
packageJson.bin !== null && | ||
typeof binName !== 'undefined' && | ||
typeof packageJson.bin[binName] === 'string' | ||
) { | ||
if (isObjectWithStringProp(packageJson.bin, binName)) { | ||
return packageJson.bin[binName]; | ||
} | ||
throw new Error('package.json#/bin is invalid'); | ||
throw new Error('package.json#/bin invalid'); | ||
}; | ||
const bin = () => { | ||
const runBinary = (packageName, binName) => { | ||
const { createRequire } = require('module'); | ||
@@ -28,4 +27,2 @@ | ||
const packageName = process.argv[2]; | ||
const packagePath = path.join(packageName, 'package'); | ||
@@ -35,12 +32,6 @@ | ||
const package = targetRequire(packageResolved); | ||
const packageJson = targetRequire(packageResolved); | ||
if (typeof package !== 'object' || package === null) { | ||
throw new Error('package.json not found'); | ||
} | ||
const partialBinPath = getPartialBinPath(packageJson, binName); | ||
const binName = process.argv[3]; | ||
const partialBinPath = getBinPath(package, binName); | ||
const binPath = path.join(packageName, partialBinPath); | ||
@@ -55,2 +46,4 @@ | ||
bin(); | ||
const [packageName, binName] = process.argv.slice(2); | ||
runBinary(packageName, binName); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2018
6
37