Skip to content

Commit

Permalink
chore: correct package-lock.json to work with npm quirks (#3339)
Browse files Browse the repository at this point in the history
Apparently, `npm` tends to choke when local package references have
dependencies on other local package references, if those are included in
the lockfile though the `requires` and `dependencies` section of a root
dependency item.

Stops emitting those, and confirmed `npm` seems happy with the outcome.
  • Loading branch information
RomainMuller authored Jul 18, 2019
1 parent da7fe0c commit 305fed6
Show file tree
Hide file tree
Showing 121 changed files with 1,062,984 additions and 128 deletions.
8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/alexa-ask/package-lock.json

Large diffs are not rendered by default.

8,818 changes: 8,817 additions & 1 deletion packages/@aws-cdk/app-delivery/package-lock.json

Large diffs are not rendered by default.

8,537 changes: 8,536 additions & 1 deletion packages/@aws-cdk/assert/package-lock.json

Large diffs are not rendered by default.

8,818 changes: 8,817 additions & 1 deletion packages/@aws-cdk/assets/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-amazonmq/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-amplify/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-apigateway/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-applicationautoscaling/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-appmesh/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-appstream/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-appsync/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-athena/package-lock.json

Large diffs are not rendered by default.

8,818 changes: 8,817 additions & 1 deletion packages/@aws-cdk/aws-autoscaling-common/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-autoscaling-hooktargets/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-autoscaling/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-autoscalingplans/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-batch/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-budgets/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-certificatemanager/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-cloud9/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-cloudformation/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-cloudfront/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-cloudtrail/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-cloudwatch-actions/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-cloudwatch/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-codebuild/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-codecommit/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-codedeploy/package-lock.json

Large diffs are not rendered by default.

8,818 changes: 8,817 additions & 1 deletion packages/@aws-cdk/aws-codepipeline-actions/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-codepipeline/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-cognito/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-config/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-datapipeline/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-dax/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-directoryservice/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-dlm/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-dms/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-docdb/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-dynamodb-global/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-dynamodb/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-ec2/package-lock.json

Large diffs are not rendered by default.

8,818 changes: 8,817 additions & 1 deletion packages/@aws-cdk/aws-ecr-assets/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-ecr/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-ecs-patterns/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-ecs/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-efs/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-eks/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-elasticache/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-elasticbeanstalk/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-elasticloadbalancing/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-elasticloadbalancingv2/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-elasticsearch/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-emr/package-lock.json

Large diffs are not rendered by default.

8,818 changes: 8,817 additions & 1 deletion packages/@aws-cdk/aws-events-targets/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-events/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-fsx/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-gamelift/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-glue/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-greengrass/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-guardduty/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-iam/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-inspector/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-iot/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-iot1click/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-iotanalytics/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-iotthingsgraph/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-kinesis/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-kinesisanalytics/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-kinesisfirehose/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-kms/package-lock.json

Large diffs are not rendered by default.

8,818 changes: 8,817 additions & 1 deletion packages/@aws-cdk/aws-lambda-event-sources/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-lambda/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-logs-destinations/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-logs/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-mediastore/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-msk/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-neptune/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-opsworks/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-opsworkscm/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-pinpoint/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-pinpointemail/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-ram/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-rds/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-redshift/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-robomaker/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-route53-targets/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-route53/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-route53resolver/package-lock.json

Large diffs are not rendered by default.

8,818 changes: 8,817 additions & 1 deletion packages/@aws-cdk/aws-s3-assets/package-lock.json

Large diffs are not rendered by default.

8,818 changes: 8,817 additions & 1 deletion packages/@aws-cdk/aws-s3-deployment/package-lock.json

Large diffs are not rendered by default.

8,818 changes: 8,817 additions & 1 deletion packages/@aws-cdk/aws-s3-notifications/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-s3/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-sagemaker/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-sam/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-sdb/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-secretsmanager/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-servicecatalog/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-servicediscovery/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-ses/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-sns-subscriptions/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-sns/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-sqs/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-ssm/package-lock.json

Large diffs are not rendered by default.

8,818 changes: 8,817 additions & 1 deletion packages/@aws-cdk/aws-stepfunctions-tasks/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/aws-stepfunctions/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-transfer/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-waf/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-wafregional/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/aws-workspaces/package-lock.json

Large diffs are not rendered by default.

8,537 changes: 8,536 additions & 1 deletion packages/@aws-cdk/cfnspec/package-lock.json

Large diffs are not rendered by default.

8,537 changes: 8,536 additions & 1 deletion packages/@aws-cdk/cloudformation-diff/package-lock.json

Large diffs are not rendered by default.

8,860 changes: 8,859 additions & 1 deletion packages/@aws-cdk/core/package-lock.json

Large diffs are not rendered by default.

9,141 changes: 9,140 additions & 1 deletion packages/@aws-cdk/custom-resources/package-lock.json

Large diffs are not rendered by default.

8,537 changes: 8,536 additions & 1 deletion packages/@aws-cdk/cx-api/package-lock.json

Large diffs are not rendered by default.

8,537 changes: 8,536 additions & 1 deletion packages/@aws-cdk/region-info/package-lock.json

Large diffs are not rendered by default.

8,537 changes: 8,536 additions & 1 deletion packages/aws-cdk/package-lock.json

Large diffs are not rendered by default.

50 changes: 41 additions & 9 deletions scripts/install-local-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,20 @@ function installDeps(location, ...depLists) {

const path = matched[1];
const modulePath = resolve(location, path);
const requires = installDependency(nodeModules, modulePath);
const { requires, dependencies } = installDependency(nodeModules, modulePath);

linked.add(name);
paths.push(path);

if (locks) {
locks.dependencies[name] = { version, dev, requires: rewriteLocalPaths(requires, modulePath, location) };
fixupDependencies(dependencies, dev);

locks.dependencies[name] = {
version,
dev,
requires: removeLocalPackages(requires),
dependencies,
};
}
}
}
Expand All @@ -71,7 +78,7 @@ function installDeps(location, ...depLists) {
* @param {string} localPath the path of the "installed" module
*/
function installDependency(nodeModules, localPath) {
const packageInfo = readJsonSync(`${localPath}/package.json`);
const packageInfo = readJsonSync(join(localPath, 'package.json'));

const linkLocation = join(nodeModules, packageInfo.name);

Expand Down Expand Up @@ -102,7 +109,15 @@ function installDependency(nodeModules, localPath) {
}
}

return packageInfo.dependencies;
const lockFilePath = join(localPath, 'package-lock.json');
const lockFile = pathExistsSync(lockFilePath)
? readJsonSync(lockFilePath)
: undefined;

return {
requires: packageInfo.dependencies,
dependencies: lockFile && lockFile.dependencies,
};
}

function sortKeys(object) {
Expand All @@ -116,17 +131,14 @@ function sortKeys(object) {
return sorted;
}

function rewriteLocalPaths(dependencies, moduleRoot, newRoot) {
function removeLocalPackages(dependencies) {
if (!dependencies) {
return dependencies;
}
for (const [name, version] of Object.entries(dependencies)) {
const matched = version.match(LOCAL_PACKAGE_REGEX);
if (!matched) { continue; }
const path = matched[1];
const absolutePath = resolve(moduleRoot, path);
const localRelativePath = relative(newRoot, absolutePath);
dependencies[name] = `file:${localRelativePath}`;
delete dependencies[name];
}
return dependencies;
}
Expand All @@ -140,3 +152,23 @@ function pathExistsSync(path) {
return false;
}
}

function fixupDependencies(deps, dev) {
if (!deps) {
return deps;
}
for (const [name, dep] of Object.entries(deps)) {
if (!dev && dep.dev) {
delete deps[name];
continue;
}
if (dev) { dep.dev = true; }
const matched = dep.version.match(LOCAL_PACKAGE_REGEX);
if (matched) {
delete deps[name];
continue;
}
dep.requires = removeLocalPackages(dep.requires);
fixupDependencies(dep.dependencies, dev);
}
}
Loading

0 comments on commit 305fed6

Please sign in to comment.