From 6e5acc94b1bdf44fe4d4c29a4219e01d63050663 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 31 Aug 2020 11:36:44 +0000 Subject: [PATCH 1/3] fix(deps): update dependency read-pkg-up to v7 --- package-lock.json | 19 ++++++------------- package.json | 2 +- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index 620e6dae9ba..c8116dd94c2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11915,20 +11915,13 @@ } }, "read-pkg-up": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-6.0.0.tgz", - "integrity": "sha512-odtTvLl+EXo1eTsMnoUHRmg/XmXdTkwXVxy4VFE9Kp6cCq7b3l7QMdBndND3eAFzrbSAXC/WCUOQQ9rLjifKZw==", + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-7.0.1.tgz", + "integrity": "sha512-zK0TB7Xd6JpCLmlLmufqykGE+/TlOePD6qKClNW7hHDKFh/J7/7gCWGR7joEQEW1bKq3a3yUZSObOoWLFQ4ohg==", "requires": { - "find-up": "^4.0.0", - "read-pkg": "^5.1.1", - "type-fest": "^0.5.0" - }, - "dependencies": { - "type-fest": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.5.2.tgz", - "integrity": "sha512-DWkS49EQKVX//Tbupb9TFa19c7+MK1XmzkrZUR8TAktmE/DizXoaoJV6TZ/tSIPXipqNiRI6CyAe7x69Jb6RSw==" - } + "find-up": "^4.1.0", + "read-pkg": "^5.2.0", + "type-fest": "^0.8.1" } }, "readable-stream": { diff --git a/package.json b/package.json index 281a4de901c..fe8bc3bf9ca 100644 --- a/package.json +++ b/package.json @@ -135,7 +135,7 @@ "prettyjson": "^1.2.1", "random-item": "^1.0.0", "raw-body": "^2.4.1", - "read-pkg-up": "^6.0.0", + "read-pkg-up": "^7.0.0", "require-package-name": "^2.0.1", "resolve": "^1.12.0", "safe-join": "^0.1.3", From 34170c4ee0461abf7e508eccc826f0cc13fbe111 Mon Sep 17 00:00:00 2001 From: erezrokah Date: Mon, 31 Aug 2020 14:13:54 +0200 Subject: [PATCH 2/3] chore(deps): remove unused function and deps --- package-lock.json | 41 --------------- package.json | 4 -- src/utils/finders.js | 122 +------------------------------------------ 3 files changed, 1 insertion(+), 166 deletions(-) diff --git a/package-lock.json b/package-lock.json index c8116dd94c2..2d4a27050a5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8299,14 +8299,6 @@ "integrity": "sha1-SMptcvbGo68Aqa1K5odr44ieKwk=", "dev": true }, - "ignore-walk": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/ignore-walk/-/ignore-walk-3.0.3.tgz", - "integrity": "sha512-m7o6xuOaT1aqheYHKf8W6J5pYH85ZI9w077erOzLje3JsB1gkafkAhHHY19dqjulgIZHFm32Cp5uNZgcQqdJKw==", - "requires": { - "minimatch": "^3.0.4" - } - }, "import-fresh": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.2.1.tgz", @@ -10409,14 +10401,6 @@ "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.0.tgz", "integrity": "sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ==" }, - "npm-bundled": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/npm-bundled/-/npm-bundled-1.1.1.tgz", - "integrity": "sha512-gqkfgGePhTpAEgUsGEgcq1rqPXA+tv/aVBlgEzfXwA1yiUJF7xtEt3CtVwOjNYQOVknDk0F20w58Fnm3EtG0fA==", - "requires": { - "npm-normalize-package-bin": "^1.0.1" - } - }, "npm-conf": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/npm-conf/-/npm-conf-1.1.3.tgz", @@ -10433,21 +10417,6 @@ } } }, - "npm-normalize-package-bin": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/npm-normalize-package-bin/-/npm-normalize-package-bin-1.0.1.tgz", - "integrity": "sha512-EPfafl6JL5/rU+ot6P3gRSCpPDW5VmIzX959Ob1+ySFUuuYHWHekXpwdUZcKP5C+DS4GEtdJluwBjnsNDl+fSA==" - }, - "npm-packlist": { - "version": "1.4.8", - "resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-1.4.8.tgz", - "integrity": "sha512-5+AZgwru5IevF5ZdnFglB5wNlHG1AOOuw28WhUq8/8emhBmLv6jX5by4WJCh7lW0uSYZYS6DXqIsyZVIXRZU9A==", - "requires": { - "ignore-walk": "^3.0.1", - "npm-bundled": "^1.0.1", - "npm-normalize-package-bin": "^1.0.1" - } - }, "npm-run-all": { "version": "4.1.5", "resolved": "https://registry.npmjs.org/npm-run-all/-/npm-run-all-4.1.5.tgz", @@ -11914,16 +11883,6 @@ } } }, - "read-pkg-up": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-7.0.1.tgz", - "integrity": "sha512-zK0TB7Xd6JpCLmlLmufqykGE+/TlOePD6qKClNW7hHDKFh/J7/7gCWGR7joEQEW1bKq3a3yUZSObOoWLFQ4ohg==", - "requires": { - "find-up": "^4.1.0", - "read-pkg": "^5.2.0", - "type-fest": "^0.8.1" - } - }, "readable-stream": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", diff --git a/package.json b/package.json index fe8bc3bf9ca..9f2120bc0e9 100644 --- a/package.json +++ b/package.json @@ -125,18 +125,14 @@ "netlify-redirect-parser": "^2.5.0", "netlify-redirector": "^0.2.0", "node-fetch": "^2.6.0", - "npm-packlist": "^1.4.4", "open": "^6.4.0", "ora": "^4.1.1", "p-wait-for": "^3.0.0", "parse-github-url": "^1.0.2", "parse-gitignore": "^1.0.1", - "precinct": "^6.1.2", "prettyjson": "^1.2.1", "random-item": "^1.0.0", "raw-body": "^2.4.1", - "read-pkg-up": "^7.0.0", - "require-package-name": "^2.0.1", "resolve": "^1.12.0", "safe-join": "^0.1.3", "static-server": "^2.2.1", diff --git a/src/utils/finders.js b/src/utils/finders.js index c4379de862b..0a3ecc13995 100644 --- a/src/utils/finders.js +++ b/src/utils/finders.js @@ -1,12 +1,6 @@ const path = require('path') const fs = require('fs') -const packList = require('npm-packlist') -const precinct = require('precinct') -const resolve = require('resolve') -const readPkgUp = require('read-pkg-up') -const requirePackageName = require('require-package-name') const alwaysIgnored = new Set(['aws-sdk']) -const debug = require('debug')('netlify-dev-plugin:src/utils/finders') const ignoredExtensions = new Set([ '.log', @@ -35,120 +29,6 @@ function includeModuleFile(packageJson, moduleFilePath) { return !ignoredExtensions.has(path.extname(moduleFilePath)) } -function getDependencies(filename, basedir) { - const servicePath = basedir - - const filePaths = new Set() - const modulePaths = new Set() - const pkgs = {} - - const modulesToProcess = [] - const localFilesToProcess = [filename] - - function handle(name, basedir, optionalDependencies) { - const moduleName = requirePackageName(name.replace(/\\/g, '/')) - - if (alwaysIgnored.has(moduleName)) { - return - } - - try { - const pathToModule = resolve.sync(path.join(moduleName, 'package.json'), { - basedir, - }) - const pkg = readPkgUp.sync({ cwd: pathToModule }) - - if (pkg) { - modulesToProcess.push(pkg) - } - } catch (e) { - if (e.code === 'MODULE_NOT_FOUND') { - if (ignoreMissing(moduleName, optionalDependencies)) { - debug(`WARNING missing optional dependency: ${moduleName}`) - return null - } - try { - // this resolves the requested import also against any set up NODE_PATH extensions, etc. - const resolved = require.resolve(name) - localFilesToProcess.push(resolved) - return - } catch (e) { - throw new Error(`Could not find "${moduleName}" module in file: ${filename.replace( - path.dirname(basedir), - '' - )}. - -Please ensure "${moduleName}" is installed in the project.`) - } - } - throw e - } - } - - while (localFilesToProcess.length) { - const currentLocalFile = localFilesToProcess.pop() - - if (filePaths.has(currentLocalFile)) { - continue - } - - filePaths.add(currentLocalFile) - precinct.paperwork(currentLocalFile, { includeCore: false }).forEach(dependency => { - if (dependency.indexOf('.') === 0) { - const abs = resolve.sync(dependency, { - basedir: path.dirname(currentLocalFile), - }) - localFilesToProcess.push(abs) - } else { - handle(dependency, servicePath) - } - }) - } - - while (modulesToProcess.length) { - const currentModule = modulesToProcess.pop() - const currentModulePath = path.join(currentModule.path, '..') - const packageJson = currentModule.pkg - - if (modulePaths.has(currentModulePath)) { - continue - } - modulePaths.add(currentModulePath) - pkgs[currentModulePath] = packageJson - ;['dependencies', 'peerDependencies', 'optionalDependencies'].forEach(key => { - const dependencies = packageJson[key] - - if (dependencies) { - Object.keys(dependencies).forEach(dependency => { - handle(dependency, currentModulePath, packageJson.optionalDependencies) - }) - } - }) - } - - modulePaths.forEach(modulePath => { - const packageJson = pkgs[modulePath] - const moduleFilePaths = packList.sync({ path: modulePath }) - - moduleFilePaths.forEach(moduleFilePath => { - if (includeModuleFile(packageJson, moduleFilePath)) { - filePaths.add(path.join(modulePath, moduleFilePath)) - } - }) - }) - - // TODO: get rid of this - const sizes = {} - filePaths.forEach(filepath => { - const stat = fs.lstatSync(filepath) - const ext = path.extname(filepath) - sizes[ext] = (sizes[ext] || 0) + stat.size - }) - debug('Sizes per extension: ', sizes) - - return [...filePaths] -} - function findModuleDir(dir) { let basedir = dir while (!fs.existsSync(path.join(basedir, 'package.json'))) { @@ -173,4 +53,4 @@ function findHandler(functionPath) { return handlerPath } -module.exports = { getDependencies, findModuleDir, findHandler } +module.exports = { findModuleDir, findHandler } From 8792e18a3d8c108e7b4cddd82243547e96198bcf Mon Sep 17 00:00:00 2001 From: erezrokah Date: Mon, 31 Aug 2020 14:20:39 +0200 Subject: [PATCH 3/3] chore(deps): remove unused functions --- src/utils/finders.js | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/src/utils/finders.js b/src/utils/finders.js index 0a3ecc13995..56c7f54e308 100644 --- a/src/utils/finders.js +++ b/src/utils/finders.js @@ -1,33 +1,5 @@ const path = require('path') const fs = require('fs') -const alwaysIgnored = new Set(['aws-sdk']) - -const ignoredExtensions = new Set([ - '.log', - '.lock', - '.html', - '.md', - '.map', - '.ts', - '.png', - '.jpeg', - '.jpg', - '.gif', - '.css', - '.patch', -]) - -function ignoreMissing(dependency, optional) { - return alwaysIgnored.has(dependency) || (optional && dependency in optional) -} - -function includeModuleFile(packageJson, moduleFilePath) { - if (packageJson.files) { - return true - } - - return !ignoredExtensions.has(path.extname(moduleFilePath)) -} function findModuleDir(dir) { let basedir = dir