Skip to content

Commit

Permalink
Improve how projectRoot is computed
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jun 25, 2020
1 parent 9384068 commit 92f4157
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
"postinstall": "node ./scripts/postinstall.js"
},
"dependencies": {
"@netlify/build": "^2.0.20",
"@netlify/config": "^1.2.5",
"@netlify/build": "^2.0.21-1",
"@netlify/config": "^1.2.6-1",
"@netlify/zip-it-and-ship-it": "^1.3.1",
"@oclif/command": "^1.5.18",
"@oclif/config": "^1.13.2",
Expand Down
15 changes: 7 additions & 8 deletions src/utils/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ class BaseCommand extends Command {
super(...args)
}
// Initialize context
async init(_projectRoot) {
async init(_stateRoot) {
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()
const stateRoot = findRoot(_stateRoot || 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(stateRoot)

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 +50,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 +71,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
5 changes: 2 additions & 3 deletions src/utils/state-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ const statePath = 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(stateRoot) {
this.path = path.join(stateRoot, statePath)
}

get all() {
Expand Down

0 comments on commit 92f4157

Please sign in to comment.