From bb1f7b0a2fd8eb37e94843f6ef7337a61f5f3d83 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Wed, 22 Aug 2018 11:48:50 -0700 Subject: [PATCH 1/3] Always provide a devResourcePath in load settings --- src/main-process/main.js | 24 ++++++++++++++---------- src/main-process/parse-command-line.js | 19 ++----------------- src/main-process/start.js | 4 ++-- 3 files changed, 18 insertions(+), 29 deletions(-) diff --git a/src/main-process/main.js b/src/main-process/main.js index ea4dac79f..33f7d88ed 100644 --- a/src/main-process/main.js +++ b/src/main-process/main.js @@ -27,27 +27,31 @@ function isAtomRepoPath (repoPath) { } let resourcePath +let devResourcePath if (args.resourcePath) { resourcePath = args.resourcePath + devResourcePath = resourcePath } else { const stableResourcePath = path.dirname(path.dirname(__dirname)) const defaultRepositoryPath = path.join(electron.app.getPath('home'), 'github', 'atom') + if (process.env.ATOM_DEV_RESOURCE_PATH) { + devResourcePath = process.env.ATOM_DEV_RESOURCE_PATH + } else if (isAtomRepoPath(process.cwd())) { + devResourcePath = process.cwd() + } else if (fs.statSyncNoException(defaultRepositoryPath)) { + devResourcePath = defaultRepositoryPath + } else { + devResourcePath = stableResourcePath + } + if (args.dev || args.test || args.benchmark || args.benchmarkTest) { - if (process.env.ATOM_DEV_RESOURCE_PATH) { - resourcePath = process.env.ATOM_DEV_RESOURCE_PATH - } else if (isAtomRepoPath(process.cwd())) { - resourcePath = process.cwd() - } else if (fs.statSyncNoException(defaultRepositoryPath)) { - resourcePath = defaultRepositoryPath - } else { - resourcePath = stableResourcePath - } + resourcePath = devResourcePath } else { resourcePath = stableResourcePath } } const start = require(path.join(resourcePath, 'src', 'main-process', 'start')) -start(resourcePath, startTime) +start(resourcePath, devResourcePath, startTime) diff --git a/src/main-process/parse-command-line.js b/src/main-process/parse-command-line.js index 55aa7c900..93a98607c 100644 --- a/src/main-process/parse-command-line.js +++ b/src/main-process/parse-command-line.js @@ -6,7 +6,7 @@ const {app} = require('electron') const path = require('path') const fs = require('fs-plus') -module.exports = function parseCommandLine (processArgs, initialResourcePath) { +module.exports = function parseCommandLine (processArgs, resourcePath, devResourcePath) { const options = yargs(processArgs).wrap(yargs.terminalWidth()) const version = app.getVersion() options.usage( @@ -119,8 +119,6 @@ module.exports = function parseCommandLine (processArgs, initialResourcePath) { let pathsToOpen = [] let urlsToOpen = [] let devMode = args['dev'] - let devResourcePath = initialResourcePath - let resourcePath = null for (const path of args._) { if (path.startsWith('atom://')) { @@ -130,21 +128,8 @@ module.exports = function parseCommandLine (processArgs, initialResourcePath) { } } - if (args['resource-path']) { + if (args['resource-path'] || test) { devMode = true - devResourcePath = args['resource-path'] - } - - if (test) { - devMode = true - } - - if (devMode) { - resourcePath = devResourcePath - } - - if (!fs.statSyncNoException(resourcePath)) { - resourcePath = path.dirname(path.dirname(__dirname)) } if (args['path-environment']) { diff --git a/src/main-process/start.js b/src/main-process/start.js index 460b58e6e..8eead3d1e 100644 --- a/src/main-process/start.js +++ b/src/main-process/start.js @@ -9,7 +9,7 @@ const fs = require('fs') const CSON = require('season') const Config = require('../config') -module.exports = function start (initialResourcePath, startTime) { +module.exports = function start (resourcePath, devResourcePath, startTime) { global.shellStartTime = startTime process.on('uncaughtException', function (error = {}) { @@ -37,7 +37,7 @@ module.exports = function start (initialResourcePath, startTime) { app.commandLine.appendSwitch('enable-experimental-web-platform-features') - const args = parseCommandLine(process.argv.slice(1), initialResourcePath) + const args = parseCommandLine(process.argv.slice(1), resourcePath, devResourcePath) atomPaths.setAtomHome(app.getPath('home')) atomPaths.setUserData(app) setupCompileCache() From f31471707d4ace1562af2f0afb2efcf16f5eab00 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Wed, 22 Aug 2018 12:41:36 -0700 Subject: [PATCH 2/3] Remove resourcePath and devResourcePath assignment from parseCommandLine --- src/main-process/parse-command-line.js | 19 ++----------------- src/main-process/start.js | 13 ++++++++++++- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/main-process/parse-command-line.js b/src/main-process/parse-command-line.js index 93a98607c..5d7849eac 100644 --- a/src/main-process/parse-command-line.js +++ b/src/main-process/parse-command-line.js @@ -3,10 +3,8 @@ const dedent = require('dedent') const yargs = require('yargs') const {app} = require('electron') -const path = require('path') -const fs = require('fs-plus') -module.exports = function parseCommandLine (processArgs, resourcePath, devResourcePath) { +module.exports = function parseCommandLine (processArgs) { const options = yargs(processArgs).wrap(yargs.terminalWidth()) const version = app.getVersion() options.usage( @@ -128,7 +126,7 @@ module.exports = function parseCommandLine (processArgs, resourcePath, devResour } } - if (args['resource-path'] || test) { + if (args.resourcePath || test) { devMode = true } @@ -138,12 +136,7 @@ module.exports = function parseCommandLine (processArgs, resourcePath, devResour process.env.PATH = args['path-environment'] } - resourcePath = normalizeDriveLetterName(resourcePath) - devResourcePath = normalizeDriveLetterName(devResourcePath) - return { - resourcePath, - devResourcePath, pathsToOpen, urlsToOpen, executedFrom, @@ -166,11 +159,3 @@ module.exports = function parseCommandLine (processArgs, resourcePath, devResour env: process.env } } - -function normalizeDriveLetterName (filePath) { - if (process.platform === 'win32' && filePath) { - return filePath.replace(/^([a-z]):/, ([driveLetter]) => driveLetter.toUpperCase() + ':') - } else { - return filePath - } -} diff --git a/src/main-process/start.js b/src/main-process/start.js index 8eead3d1e..10713fa4b 100644 --- a/src/main-process/start.js +++ b/src/main-process/start.js @@ -37,7 +37,10 @@ module.exports = function start (resourcePath, devResourcePath, startTime) { app.commandLine.appendSwitch('enable-experimental-web-platform-features') - const args = parseCommandLine(process.argv.slice(1), resourcePath, devResourcePath) + const args = parseCommandLine(process.argv.slice(1)) + args.resourcePath = normalizeDriveLetterName(resourcePath) + args.devResourcePath = normalizeDriveLetterName(devResourcePath) + atomPaths.setAtomHome(app.getPath('home')) atomPaths.setUserData(app) setupCompileCache() @@ -124,3 +127,11 @@ function getConfig () { return config } + +function normalizeDriveLetterName (filePath) { + if (process.platform === 'win32' && filePath) { + return filePath.replace(/^([a-z]):/, ([driveLetter]) => driveLetter.toUpperCase() + ':') + } else { + return filePath + } +} From c1f58e797139299ce948ab26a07318f9ebe53077 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Wed, 22 Aug 2018 12:42:15 -0700 Subject: [PATCH 3/3] Recognize short form argument -r of --resource-path in main.js --- src/main-process/main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main-process/main.js b/src/main-process/main.js index 33f7d88ed..11703bf3f 100644 --- a/src/main-process/main.js +++ b/src/main-process/main.js @@ -14,6 +14,7 @@ const args = yargs(process.argv) .alias('d', 'dev') .alias('t', 'test') + .alias('r', 'resource-path') .argv function isAtomRepoPath (repoPath) {