Skip to content

Commit

Permalink
fix: recover from missing pkg.name
Browse files Browse the repository at this point in the history
Fallback to dirname if pkg.name is not provided
  • Loading branch information
medikoo committed May 27, 2019
1 parent 5cd4539 commit 7016c53
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
19 changes: 10 additions & 9 deletions install.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"use strict";

const toPlainObject = require("es5-ext/object/normalize-options")
, ensureString = require("es5-ext/object/validate-stringifiable-value")
, { resolve } = require("path")
, NpmCrossLinkError = require("./lib/npm-cross-link-error")
, ensureConfiguration = require("./lib/private/ensure-user-configuration")
, createProgressData = require("./lib/private/create-progress-data")
, install = require("./lib/private/install")
, getPackageJson = require("./lib/get-package-json");
const toPlainObject = require("es5-ext/object/normalize-options")
, ensureString = require("es5-ext/object/validate-stringifiable-value")
, { resolve, basename } = require("path")
, NpmCrossLinkError = require("./lib/npm-cross-link-error")
, ensureConfiguration = require("./lib/private/ensure-user-configuration")
, createProgressData = require("./lib/private/create-progress-data")
, install = require("./lib/private/install")
, getPackageJson = require("./lib/get-package-json");

module.exports = (path, userConfiguration, inputOptions = {}) => {
path = resolve(ensureString(path));
Expand All @@ -17,7 +17,8 @@ module.exports = (path, userConfiguration, inputOptions = {}) => {
if (!packageContext.packageJson) {
return Promise.reject(new NpmCrossLinkError(`Could not find package.json at ${ path }`));
}
progressData.topPackageName = packageContext.name = packageContext.packageJson.name;
progressData.topPackageName = packageContext.name =
packageContext.packageJson.name || basename(path);
const promise = install(
packageContext, ensureConfiguration(userConfiguration), toPlainObject(inputOptions),
progressData
Expand Down
5 changes: 3 additions & 2 deletions lib/private/install.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

const { resolve } = require("path")
const { basename, resolve } = require("path")
, wait = require("timers-ext/promise/sleep")
, cleanupNpmInstall = require("./cleanup-npm-install")
, getPackageJson = require("../get-package-json")
Expand All @@ -15,7 +15,8 @@ module.exports = async (packageContext, userConfiguration, inputOptions, progres
if (!packageContext.packageJson) packageContext.packageJson = getPackageJson(path);
const { packageJson } = packageContext;
if (!packageJson) return;
let name = (packageContext.name = packageJson.name);
if (!packageContext.name) packageContext.name = packageJson.name || basename(path);
let { name } = packageContext;

if (packagesMeta[name] && resolve(packagesPath, name) === path) {
await installMaintainedPackage(
Expand Down

0 comments on commit 7016c53

Please sign in to comment.