diff --git a/package-lock.json b/package-lock.json index 14176a0165e..12e587644e1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -555,17 +555,17 @@ } }, "@netlify/build": { - "version": "2.0.20", - "resolved": "https://registry.npmjs.org/@netlify/build/-/build-2.0.20.tgz", - "integrity": "sha512-Am78wipw/h8/XejsNt8B8ujr1/c9I2OCgGmxmPsjFQ1FiWZ8vuQPRXNKMFIhWSn9FR8LAS7FMGkEmfQd7DCq3Q==", + "version": "2.0.26", + "resolved": "https://registry.npmjs.org/@netlify/build/-/build-2.0.26.tgz", + "integrity": "sha512-WQEMAJPA+rHpRFTK3HtqzXQYzOdi7rHLmu3Lg9MVpYFJMzFfI/hvHwh5Xs0TmIPYDXm2dK8Dr4D5jddY1PBKAA==", "requires": { "@bugsnag/js": "^7.0.0", "@netlify/cache-utils": "^1.0.0", - "@netlify/config": "^1.2.5", + "@netlify/config": "^2.0.3", "@netlify/functions-utils": "^1.2.0", "@netlify/git-utils": "^1.0.0", "@netlify/run-utils": "^0.1.1", - "@netlify/zip-it-and-ship-it": "^1.3.1", + "@netlify/zip-it-and-ship-it": "^1.3.2", "analytics": "0.3.1", "array-flat-polyfill": "^1.0.1", "chalk": "^3.0.0", @@ -741,9 +741,9 @@ } }, "@netlify/config": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/@netlify/config/-/config-1.2.5.tgz", - "integrity": "sha512-TqyVIA/BYWHSVgnpJ7keo2Dg6JZ9AGZWBAVk657yVvGOIEoH0vywJJjtqj3M2i6pHVryQAGU/Pugz+L9MGqx4w==", + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@netlify/config/-/config-2.0.3.tgz", + "integrity": "sha512-YpT89Hi//Z6RkFh3LXyvnjaC7h95CtK/LDJrUHD/CqHfw+0QvH69bFYeguEMDCQE9jSen9ZeldhyfMCK6k3fzA==", "requires": { "array-flat-polyfill": "^1.0.1", "chalk": "^3.0.0", @@ -756,7 +756,7 @@ "indent-string": "^4.0.0", "is-plain-obj": "^2.1.0", "js-yaml": "^3.14.0", - "netlify": "^4.3.3", + "netlify": "^4.3.5", "p-locate": "^4.1.0", "path-exists": "^4.0.0", "path-type": "^4.0.0", @@ -952,9 +952,9 @@ } }, "@netlify/zip-it-and-ship-it": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/@netlify/zip-it-and-ship-it/-/zip-it-and-ship-it-1.3.1.tgz", - "integrity": "sha512-WCmKuTZQul8unUc4R5IoNaiezPzxLnwRuFBOPkPRMIod8jqWZ2bmpbGjxLqG6d1dPm/4HBk+UivbYovQbW14Tw==", + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/@netlify/zip-it-and-ship-it/-/zip-it-and-ship-it-1.3.2.tgz", + "integrity": "sha512-CT/IyXHqFpf4KhegGZUIl9EzIBEVjDL2R8XP2mtKcklo1ob1VASSCf1gr2+Xn8oAz2zpcWUqIdmprjnvdXc/gA==", "requires": { "archiver": "^3.0.0", "common-path-prefix": "^2.0.0", @@ -11258,12 +11258,12 @@ "integrity": "sha512-AO81vsIO1k1sM4Zrd6Hu7regmJN1NSiAja10gc4bX3F0wd+9rQmcuHQaHVQCYIEC8iFXnE+mavh23GOt7wBgug==" }, "netlify": { - "version": "4.3.3", - "resolved": "https://registry.npmjs.org/netlify/-/netlify-4.3.3.tgz", - "integrity": "sha512-5BO10o9v64bb9RgYy2EdQG61DwLWucrYMEA6Q3cgSAi/a5ttAE6r38CJ6kTgoiybp2br+zFhoJQ74d0vjaBcLg==", + "version": "4.3.5", + "resolved": "https://registry.npmjs.org/netlify/-/netlify-4.3.5.tgz", + "integrity": "sha512-Weq2swCfaB3pvQjVrnZmYoTwB8MdkKg/hGRRmHQWWtdh9llBKXf7UsWiIjkmDOD78xMXN9Xym6Vgi2shN+3SzQ==", "requires": { "@netlify/open-api": "^0.15.0", - "@netlify/zip-it-and-ship-it": "^1.3.1", + "@netlify/zip-it-and-ship-it": "^1.3.2", "backoff": "^2.5.0", "clean-deep": "^3.3.0", "filter-obj": "^2.0.1", diff --git a/package.json b/package.json index 2d340ccceb1..e815f21b462 100644 --- a/package.json +++ b/package.json @@ -63,9 +63,9 @@ "postinstall": "node ./scripts/postinstall.js" }, "dependencies": { - "@netlify/build": "^2.0.20", - "@netlify/config": "^1.2.5", - "@netlify/zip-it-and-ship-it": "^1.3.1", + "@netlify/build": "^2.0.26", + "@netlify/config": "^2.0.3", + "@netlify/zip-it-and-ship-it": "^1.3.2", "@oclif/command": "^1.5.18", "@oclif/config": "^1.13.2", "@oclif/errors": "^1.1.2", @@ -122,7 +122,7 @@ "make-dir": "^3.0.0", "minimist": "^1.2.5", "multiparty": "^4.2.1", - "netlify": "^4.3.3", + "netlify": "^4.3.5", "netlify-redirect-parser": "^2.5.0", "netlify-redirector": "^0.2.0", "node-fetch": "^2.6.0", diff --git a/src/utils/command.js b/src/utils/command.js index 63887ab0b17..502962a3596 100644 --- a/src/utils/command.js +++ b/src/utils/command.js @@ -7,7 +7,6 @@ const { track, identify } = require('./telemetry') const openBrowser = require('./open-browser') const StateConfig = require('./state-config') const globalConfig = require('./global-config') -const findRoot = require('./find-root') const chalkInstance = require('./chalk') const resolveConfig = require('@netlify/config') @@ -23,19 +22,18 @@ class BaseCommand extends Command { super(...args) } // Initialize context - async init(_projectRoot) { + async init() { const cwd = argv.cwd || process.cwd() - const projectRoot = findRoot(_projectRoot || cwd) // if calling programmatically, can use a supplied root, else in normal CLI context it just uses process.cwd() // Grab netlify API token const authViaFlag = getAuthArg(argv) const [token] = this.getConfigToken(authViaFlag) // Get site id & build state - const state = new StateConfig(projectRoot) + const state = new StateConfig(cwd) - const cachedConfig = await this.getConfig(cwd, projectRoot, state, token) - const { configPath, config } = cachedConfig + const cachedConfig = await this.getConfig(cwd, state, token) + const { configPath, config, buildDir } = cachedConfig const apiOpts = {} if (NETLIFY_API_URL) { @@ -50,7 +48,7 @@ class BaseCommand extends Command { api: new API(token || '', apiOpts), // current site context site: { - root: projectRoot, + root: buildDir, configPath: configPath, get id() { return state.get('siteId') @@ -71,12 +69,11 @@ class BaseCommand extends Command { } // Find and resolve the Netlify configuration - async getConfig(cwd, projectRoot, state, token) { + async getConfig(cwd, state, token) { try { return await resolveConfig({ config: argv.config, cwd: cwd, - repositoryRoot: projectRoot, context: argv.context, debug: argv.debug, siteId: state.get('siteId'), diff --git a/src/utils/find-root/fixtures/git-project/some/sub/dir/.keep b/src/utils/find-root/fixtures/git-project/some/sub/dir/.keep deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/utils/find-root/fixtures/no-indicator/some/sub/dir/.keep b/src/utils/find-root/fixtures/no-indicator/some/sub/dir/.keep deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/utils/find-root/fixtures/state-folder/.netlify/.keep b/src/utils/find-root/fixtures/state-folder/.netlify/.keep deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/utils/find-root/fixtures/state-folder/some/sub/dir/.keep b/src/utils/find-root/fixtures/state-folder/some/sub/dir/.keep deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/utils/find-root/fixtures/toml-config/netlify.toml b/src/utils/find-root/fixtures/toml-config/netlify.toml deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/utils/find-root/fixtures/toml-config/some/sub/dir/.keep b/src/utils/find-root/fixtures/toml-config/some/sub/dir/.keep deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/utils/find-root/index.js b/src/utils/find-root/index.js deleted file mode 100644 index 80f6e6d83f4..00000000000 --- a/src/utils/find-root/index.js +++ /dev/null @@ -1,24 +0,0 @@ -const path = require('path') -const findUp = require('find-up') -const os = require('os') - -// Finds cwd's parent root directory -function findRoot(cwd = process.cwd(), opts) { - opts = Object.assign( - { - rootIndicators: ['.netlify', 'netlify.toml', '.git'], - }, - opts - ) - - const rootIndicator = findUp.sync(opts.rootIndicators, { cwd: cwd }) - if (typeof rootIndicator !== 'string') return cwd - - const indicatorRoot = path.dirname(rootIndicator) - // To avoid thinking our project root is our global config - const root = indicatorRoot !== os.homedir() ? indicatorRoot : cwd - - return root -} - -module.exports = findRoot diff --git a/src/utils/find-root/index.test.js b/src/utils/find-root/index.test.js deleted file mode 100644 index 7e7993abee1..00000000000 --- a/src/utils/find-root/index.test.js +++ /dev/null @@ -1,38 +0,0 @@ -const test = require('ava') -const findRoot = require('.') -const path = require('path') -const tempy = require('tempy') -const mkdirp = require('mkdirp') - -test('Find root in a git project', t => { - // can't check in .git folders so we just make one as part of the test - mkdirp.sync(path.join(__dirname, 'fixtures', 'git-project', '.git')) - t.is( - findRoot(path.join(__dirname, 'fixtures', 'git-project', 'some', 'sub', 'dir')), - path.join(__dirname, 'fixtures', 'git-project'), - 'Correct project dir with git directory' - ) -}) - -test('Find root in a linked folder', t => { - t.is( - findRoot(path.join(__dirname, 'fixtures', 'state-folder', 'some', 'sub', 'dir')), - path.join(__dirname, 'fixtures', 'state-folder'), - 'Correct project dir with a .netlify folder in it' - ) -}) - -test('Find root in a netlify site folder', t => { - t.is( - findRoot(path.join(__dirname, 'fixtures', 'toml-config', 'some', 'sub', 'dir')), - path.join(__dirname, 'fixtures', 'toml-config'), - 'Defaults to folder with a toml file in it' - ) -}) - -test('Find root with no indicators', t => { - const tmp = tempy.directory() - const subPath = path.join(tmp, 'some', 'sub', 'dir') - mkdirp.sync(subPath) - t.is(findRoot(subPath, { rootIndicators: ['.non-existent'] }), subPath, 'CWD if no indicators are located') -}) diff --git a/src/utils/state-config.js b/src/utils/state-config.js index 6b152ff445d..7bdcfdbebb5 100644 --- a/src/utils/state-config.js +++ b/src/utils/state-config.js @@ -1,16 +1,27 @@ const path = require('path') +const findUp = require('find-up') const makeDir = require('make-dir') const fs = require('fs') const writeFileAtomic = require('write-file-atomic') const dotProp = require('dot-prop') -const statePath = path.join('.netlify', 'state.json') +const STATE_PATH = path.join('.netlify', 'state.json') const permissionError = "You don't have access to this file." class StateConfig { - constructor(projectRoot) { - this.root = projectRoot - this.path = path.join(projectRoot, statePath) + constructor(cwd) { + this.path = this.findStatePath(cwd) + } + + // Finds location of `.netlify/state.json` + findStatePath(cwd) { + const statePath = findUp.sync([STATE_PATH], { cwd }) + + if (!statePath) { + return path.join(cwd, STATE_PATH) + } + + return statePath } get all() {