Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
15 changes: 6 additions & 9 deletions src/utils/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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) {
Expand All @@ -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')
Expand All @@ -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,
siteId: state.get('siteId'),
token,
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
24 changes: 0 additions & 24 deletions src/utils/find-root/index.js

This file was deleted.

38 changes: 0 additions & 38 deletions src/utils/find-root/index.test.js

This file was deleted.

19 changes: 15 additions & 4 deletions src/utils/state-config.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down