From 11c6be8fba1438ee9a07f1a231f68fe63e5fd2fe Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Mon, 10 Sep 2018 09:38:03 +0200
Subject: [PATCH] refactor: deprecate copyLocalLibs

This can/should be enabled by default now.
---
 lib/config/definitions.js                     |  7 ---
 lib/config/validation.js                      |  1 +
 lib/manager/npm/post-update/index.js          | 59 +++++++++----------
 test/workers/branch/lock-files/index.spec.js  |  3 -
 .../__snapshots__/flatten.spec.js.snap        |  8 ---
 website/docs/configuration-options.md         |  4 --
 6 files changed, 30 insertions(+), 52 deletions(-)

diff --git a/lib/config/definitions.js b/lib/config/definitions.js
index 8a9dec8539..8a076d4fff 100644
--- a/lib/config/definitions.js
+++ b/lib/config/definitions.js
@@ -248,13 +248,6 @@ const options = [
     stage: 'branch',
     type: 'string',
   },
-  {
-    name: 'copyLocalLibs',
-    description:
-      'enable copy local libraries found in package.json like `"lib1: file:../path/to/folder"`, warning: feature may be deprecated in future.',
-    type: 'boolean',
-    default: false,
-  },
   {
     name: 'updateLockFiles',
     description: 'Set to false to disable lock file updating',
diff --git a/lib/config/validation.js b/lib/config/validation.js
index 09e25d7cda..ad4f074a67 100644
--- a/lib/config/validation.js
+++ b/lib/config/validation.js
@@ -42,6 +42,7 @@ async function validateConfig(config, isPreset, parentPath) {
       'forkToken',
       'repository',
       'vulnerabilityAlertsOnly',
+      'copyLocalLibs', // deprecated - functinoality is now enabled by default
     ];
     return ignoredNodes.includes(key);
   }
diff --git a/lib/manager/npm/post-update/index.js b/lib/manager/npm/post-update/index.js
index 4143906cc2..fe8843c4b7 100644
--- a/lib/manager/npm/post-update/index.js
+++ b/lib/manager/npm/post-update/index.js
@@ -128,41 +128,40 @@ async function writeExistingFiles(config, packageFiles) {
       JSON.stringify(massagedFile)
     );
 
-    if (config.copyLocalLibs) {
-      const toCopy = listLocalLibs(massagedFile.dependencies);
-      toCopy.push(...listLocalLibs(massagedFile.devDependencies));
-      if (toCopy.length !== 0) {
-        logger.debug(`listOfNeededLocalFiles files to copy: ${toCopy}`);
-        await Promise.all(
-          toCopy.map(async localPath => {
-            const resolvedLocalPath = upath.join(
-              path.resolve(basedir, localPath)
+    // copyLocalLibs
+    const toCopy = listLocalLibs(massagedFile.dependencies);
+    toCopy.push(...listLocalLibs(massagedFile.devDependencies));
+    if (toCopy.length !== 0) {
+      logger.debug(`listOfNeededLocalFiles files to copy: ${toCopy}`);
+      await Promise.all(
+        toCopy.map(async localPath => {
+          const resolvedLocalPath = upath.join(
+            path.resolve(basedir, localPath)
+          );
+          if (!resolvedLocalPath.startsWith(upath.join(config.tmpDir.path))) {
+            logger.info(
+              `local lib '${toCopy}' will not be copied because it's out of the repo.`
             );
-            if (!resolvedLocalPath.startsWith(upath.join(config.tmpDir.path))) {
-              logger.info(
-                `local lib '${toCopy}' will not be copied because it's out of the repo.`
+          } else {
+            // at the root of local Lib we should find a package.json so that yarn/npm will use it to update *lock file
+            const resolvedRepoPath = upath.join(
+              resolvedLocalPath.substring(config.tmpDir.path.length + 1),
+              'package.json'
+            );
+            const fileContent = await platform.getFile(resolvedRepoPath);
+            if (fileContent !== null) {
+              await fs.outputFile(
+                upath.join(resolvedLocalPath, 'package.json'),
+                fileContent
               );
             } else {
-              // at the root of local Lib we should find a package.json so that yarn/npm will use it to update *lock file
-              const resolvedRepoPath = upath.join(
-                resolvedLocalPath.substring(config.tmpDir.path.length + 1),
-                'package.json'
+              logger.info(
+                `listOfNeededLocalFiles - file '${resolvedRepoPath}' not found.`
               );
-              const fileContent = await platform.getFile(resolvedRepoPath);
-              if (fileContent !== null) {
-                await fs.outputFile(
-                  upath.join(resolvedLocalPath, 'package.json'),
-                  fileContent
-                );
-              } else {
-                logger.info(
-                  `listOfNeededLocalFiles - file '${resolvedRepoPath}' not found.`
-                );
-              }
             }
-          })
-        );
-      }
+          }
+        })
+      );
     }
     const npmrc = packageFile.npmrc || config.npmrc;
     if (npmrc) {
diff --git a/test/workers/branch/lock-files/index.spec.js b/test/workers/branch/lock-files/index.spec.js
index 1bf8151545..ad3f12ab0d 100644
--- a/test/workers/branch/lock-files/index.spec.js
+++ b/test/workers/branch/lock-files/index.spec.js
@@ -167,7 +167,6 @@ describe('manager/npm/post-update', () => {
     });
     it('writes package.json of local lib', async () => {
       const renoPath = upath.join(__dirname, '../../../');
-      config.copyLocalLibs = true;
       config.tmpDir = { path: renoPath };
       const packageFiles = {
         npm: [
@@ -192,7 +191,6 @@ describe('manager/npm/post-update', () => {
     });
     it('Try to write package.json of local lib, but file not found', async () => {
       const renoPath = upath.join(__dirname, '../../../');
-      config.copyLocalLibs = true;
       config.tmpDir = { path: renoPath };
       const packageFiles = {
         npm: [
@@ -217,7 +215,6 @@ describe('manager/npm/post-update', () => {
     });
     it('detect malicious intent (error config in package.json) local lib is not in the repo', async () => {
       const renoPath = upath.join(__dirname, '../../../');
-      config.copyLocalLibs = true;
       config.tmpDir = { path: renoPath };
       const packageFiles = {
         npm: [
diff --git a/test/workers/repository/updates/__snapshots__/flatten.spec.js.snap b/test/workers/repository/updates/__snapshots__/flatten.spec.js.snap
index 89f78fd815..fcabbe95ef 100644
--- a/test/workers/repository/updates/__snapshots__/flatten.spec.js.snap
+++ b/test/workers/repository/updates/__snapshots__/flatten.spec.js.snap
@@ -18,7 +18,6 @@ Array [
     "commitMessagePrefix": null,
     "commitMessageSuffix": null,
     "commitMessageTopic": "dependency {{depName}}",
-    "copyLocalLibs": false,
     "depName": "@org/a",
     "depNameSanitized": "org-a",
     "errors": Array [],
@@ -89,7 +88,6 @@ Array [
     "commitMessagePrefix": null,
     "commitMessageSuffix": null,
     "commitMessageTopic": "dependency {{depName}}",
-    "copyLocalLibs": false,
     "depName": "foo",
     "depNameSanitized": "foo",
     "errors": Array [],
@@ -160,7 +158,6 @@ Array [
     "commitMessagePrefix": null,
     "commitMessageSuffix": null,
     "commitMessageTopic": null,
-    "copyLocalLibs": false,
     "errors": Array [],
     "gitAuthor": null,
     "gitPrivateKey": null,
@@ -231,7 +228,6 @@ Array [
     "commitMessagePrefix": null,
     "commitMessageSuffix": null,
     "commitMessageTopic": "dependency {{depName}}",
-    "copyLocalLibs": false,
     "depName": "bar",
     "depNameSanitized": "bar",
     "errors": Array [],
@@ -302,7 +298,6 @@ Array [
     "commitMessagePrefix": null,
     "commitMessageSuffix": null,
     "commitMessageTopic": null,
-    "copyLocalLibs": false,
     "errors": Array [],
     "gitAuthor": null,
     "gitPrivateKey": null,
@@ -373,7 +368,6 @@ Array [
     "commitMessagePrefix": null,
     "commitMessageSuffix": null,
     "commitMessageTopic": "dependency {{depName}}",
-    "copyLocalLibs": false,
     "depName": "baz",
     "depNameSanitized": "baz",
     "errors": Array [],
@@ -444,7 +438,6 @@ Array [
     "commitMessagePrefix": null,
     "commitMessageSuffix": null,
     "commitMessageTopic": "{{{depName}}} Docker tag",
-    "copyLocalLibs": false,
     "depName": "amd64/node",
     "depNameSanitized": "node",
     "errors": Array [],
@@ -515,7 +508,6 @@ Array [
     "commitMessagePrefix": null,
     "commitMessageSuffix": null,
     "commitMessageTopic": "{{{depName}}} Docker tag",
-    "copyLocalLibs": false,
     "depName": "calico/node",
     "depNameSanitized": "calico-node",
     "errors": Array [],
diff --git a/website/docs/configuration-options.md b/website/docs/configuration-options.md
index 2eab49318b..13947bcd41 100644
--- a/website/docs/configuration-options.md
+++ b/website/docs/configuration-options.md
@@ -132,10 +132,6 @@ This is used to alter `commitMessage` and `prTitle` without needing to copy/past
 
 Warning: composer support is in alpha stage so you probably only want to run this if you are helping get it feature-ready.
 
-## copyLocalLibs
-
-Set to true if repository package.json files contain any local (file) dependencies + lock files. The `package.json` files from each will be copied to disk before lock file generation, even if they are within ignored directories.
-
 ## description
 
 The description field is used by config presets to describe what they do. They are then collated as part of the onboarding description.
-- 
GitLab