Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
heikomat committed Feb 28, 2018
2 parents fd11218 + 0685e68 commit f3e5235
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 8 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 3.3.0
### New Features
- new Flag `--no-hoist <dependency>`. Setting this makes minstall not hoist that
dependency. `<dependency>` has the form name@versionRange, e.g.
`--no-hoist aurelia-cli@^0.30.1`. If you omit the versionRange, no version of
that dependency will be hoisted. The name can be a glob expression (see
[minimatch](https://www.npmjs.com/package/minimatch)), e.g.
`--no-hoist aurelia-*`. This is useful for dependencies that don't play nice
when hoisted/linked. This flag can be added multiple times.

# 3.2.0
### New Features
- new Flag `--assume-local-modules-satisfy-non-semver-dependency-versions` (aka
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ Minstall knows the following flags:
- `--dependency-check-only` makes install print the dependency-check only, without touching any files or installing anything
- `--assume-local-modules-satisfy-non-semver-dependency-versions` (aka `--trust-local-modules`) makes minstall assume that a local module satisfies every requested version of that module that is not valid semver (like github-urls and tag-names)
- `--loglevel <loglevel>` sets the loglevel (`error`, `warn`, `info` `verbose`, `debug`, `silly`)
- `--no-hoist <dependency>`. makes minstall not hoist that dependency. `<dependency>` has the form name@versionRange, e.g. `--no-hoist aurelia-cli@^0.30.1`. If you omit the versionRange, no version of that dependency will be hoisted.
The name can be a glob expression (see [minimatch](https://www.npmjs.com/package/minimatch)), e.g. `--no-hoist aurelia-*`. This is useful for dependencies that don't play nice when hoisted/linked. This flag can be added multiple times.

## In collaboration with

Expand Down
65 changes: 58 additions & 7 deletions lib/minstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const readline = require('readline');
const logger = require('winston');
const intersect = require('semver-intersect').intersect;
const semver = require('semver');
const minimatch = require("minimatch")

const cwd = process.cwd();

Expand All @@ -30,6 +31,7 @@ let cleanup = false;
let dependencyCheckOnly = false;
let linkOnly = false;
let assumeLocalModulesSatisfyNonSemverDependencyVersions = false;
const noHoistList = [];

function logVerbose() {
return ['verbose', 'debug', 'silly'].indexOf(logger.level) >= 0;
Expand Down Expand Up @@ -306,6 +308,17 @@ function dependenciesToArray(dependencies) {
return result;
}

function _dontHoistDependency(optimalDependencyTargetFolder, requestedDependency) {
for (const installationTarget of requestedDependency.requestedBy) {

if (!optimalDependencyTargetFolder[installationTarget]) {
optimalDependencyTargetFolder[installationTarget] = [];
}

optimalDependencyTargetFolder[installationTarget].push(requestedDependency);
}
}

function determineDependencyTargetFolder(requestedDependencyArray, alreadyInstalledDependencies) {

const optimalDependencyTargetFolder = {};
Expand All @@ -320,16 +333,45 @@ function determineDependencyTargetFolder(requestedDependencyArray, alreadyInstal
return `.${requestedByPath.substr(cwd.length)}`;
}).join('\n ');

logger.warn(`${requestedDependency.requestedBy.length} modules request ${requestedDependency.identifier}. This dependency won't get optimized (hoisted), because '${requestedDependency.versionRange}' is not a vaild semver-range. If ${requestedDependency.name} is one of your local modules, you can try the --trust-loca-modules flag. These modules all get their own copy of that Dependency:\n ${requestedByString}`);
for (const installationTarget of requestedDependency.requestedBy) {
logger.warn(`${requestedDependency.requestedBy.length} modules request ${requestedDependency.identifier}. This dependency won't get optimized (hoisted), because '${requestedDependency.versionRange}' is not a vaild semver-range. If ${requestedDependency.name} is one of your local modules, you can try the --trust-local-modules flag. These modules all get their own copy of that Dependency:\n ${requestedByString}`);
_dontHoistDependency(optimalDependencyTargetFolder, requestedDependency);
continue;
}

const matchingNoHoistEntry = noHoistList.find((noHoistEntry) => {
// if the name of the requrested dependency doesn't match the noHoistEntry, then this noHoistEntry should
// not affect the hoisting of that dependency
if (!minimatch(requestedDependency.name, noHoistEntry.name)) {
return false;
}

if (!optimalDependencyTargetFolder[installationTarget]) {
optimalDependencyTargetFolder[installationTarget] = [];
}
if (noHoistEntry.versionRange === undefined) {
return true;
}

optimalDependencyTargetFolder[installationTarget].push(requestedDependency);
if (requestedDependency.versionRange === noHoistEntry.versionRange) {
return true;
}
continue;

try {
const intersection = intersect(requestedDependency.versionRange, noHoistEntry.versionRange);
} catch (error) {
// the versions didn't intersect
return false;
}

// the versions do intersect
return true;
});

if (matchingNoHoistEntry !== undefined) {
// The requested dependency is flagged as "should not get hoisted", so we don't hoist it.
const requestedByString = requestedDependency.requestedBy.map((requestedByPath) => {
return `.${requestedByPath.substr(cwd.length)}`;
}).join('\n ');

logger.info(`${requestedDependency.identifier} instersects with no-hoist-flag ${matchingNoHoistEntry.identifier}, so it won't get hoisted for the following modules:\n ${requestedByString}`);
_dontHoistDependency(optimalDependencyTargetFolder, requestedDependency);
}

// If we work with valid semver, it doesn't matter where the dependency
Expand Down Expand Up @@ -799,6 +841,15 @@ function parseProcessArguments() {
assumeLocalModulesSatisfyNonSemverDependencyVersions = true;
} else if (process.argv[i] === '--link-only') {
linkOnly = true;
} else if (process.argv[i] === '--no-hoist') {
const noHoistEntry = process.argv[i + 1].split('@');
noHoistList.push({
name: noHoistEntry[0],
versionRange: noHoistEntry[1],
identifier: `${noHoistEntry[0]}@${noHoistEntry[1]}`,
});

i++;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minstall",
"version": "3.2.1",
"version": "3.3.0",
"description": "local module installer",
"main": "lib/minstall.js",
"bin": "lib/minstall.js",
Expand Down Expand Up @@ -35,6 +35,7 @@
"dependencies": {
"bluebird": "^3.4.6",
"fs-extra": "^2.1.2",
"minimatch": "^3.0.4",
"semver": "^5.3.0",
"semver-intersect": "^1.3.1",
"winston": "^2.3.1"
Expand Down

0 comments on commit f3e5235

Please sign in to comment.