diff --git a/src/atom-paths.js b/src/atom-paths.js index 1dde4bd91f..49dc0fb6c4 100644 --- a/src/atom-paths.js +++ b/src/atom-paths.js @@ -27,7 +27,9 @@ const getAppDirectory = () => { module.exports = { setAtomHome: homePath => { - // When a read-writeable .pulsar folder exists above app use that + // When a read-writeable `.pulsar` folder exists above the app directory, + // use that. The portability means that we don't have to use a different + // name to distinguish the release channel. const portableHomePath = path.join(getAppDirectory(), '..', '.pulsar'); if (fs.existsSync(portableHomePath)) { if (hasWriteAccess(portableHomePath)) { @@ -40,27 +42,30 @@ module.exports = { } } - // Check ATOM_HOME environment variable next + // Check the `ATOM_HOME` environment variable next. if (process.env.ATOM_HOME !== undefined) { return; } - // On Windows, we don’t try to set ATOM_HOME in `pulsar.cmd`; but we might - // set ATOM_CHANNEL to signal which location should be inferred as the - // default ATOM_HOME. - if (process.env.ATOM_CHANNEL) { - switch (process.env.ATOM_CHANNEL) { - case 'next': - process.env.ATOM_HOME = path.join(homePath, '.pulsar-next'); - return; - default: - process.env.ATOM_HOME = path.join(homePath, '.pulsar'); - return; - } + // We fall back to a `.pulsar` folder in the user's home folder — or a + // different folder name if we're not on the stable release channel. + // + // On macOS and Linux, `ATOM_HOME` gets set in `pulsar(-next).sh`, so we'd + // only get this far if the user launched via a non-shell method. + // + // On Windows, we don’t try to set `ATOM_HOME` in `pulsar.cmd`, so we'll + // always get this far. + // + // In these cases, we rely on `ATOM_CHANNEL`, which is defined either by + // the launcher script or by the main process shortly after launch + // (inferred via the version number). + // + let folderName = '.pulsar'; + if (process.env.ATOM_CHANNEL === 'next') { + folderName = '.pulsar-next'; } - // Fall back to default .atom folder in users home folder - process.env.ATOM_HOME = path.join(homePath, '.pulsar'); + process.env.ATOM_HOME = path.join(homePath, folderName); }, setUserData: app => { @@ -80,5 +85,5 @@ module.exports = { } }, - getAppDirectory: getAppDirectory + getAppDirectory }; diff --git a/src/command-installer.js b/src/command-installer.js index f48bcd6f8f..0c11ab251c 100644 --- a/src/command-installer.js +++ b/src/command-installer.js @@ -1,5 +1,6 @@ const path = require('path'); const fs = require('fs-plus'); +const { getReleaseChannel } = require('./get-app-details.js'); module.exports = class CommandInstaller { constructor(applicationDelegate) { @@ -18,6 +19,10 @@ module.exports = class CommandInstaller { return process.resourcesPath; } + getReleaseChannel() { + return getReleaseChannel(this.appVersion); + } + getScriptBaseName() { if (this.scriptBaseName) { return this.scriptBaseName; @@ -26,22 +31,13 @@ module.exports = class CommandInstaller { // us the right name. return process.env.ATOM_BASE_NAME; } - // TODO: For now we can infer it from the presence of a file in the - // resources directory, but a better way would be to bake in the right - // metadata at build time. - for (let name in ['pulsar', 'pulsar-next']) { - for (let ext in ['sh', 'cmd']) { - let candidate = path.join( - this.getResourcesDirectory(), - `${name}.${ext}` - ); - if (fs.existsSync(candidate)) { - this.scriptBaseName = name; - return name; - } - } - } - return 'pulsar'; + + // Otherwise we can make an educated guess from the name of the release + // channel. + let releaseChannel = this.getReleaseChannel(); + this.scriptBaseName = releaseChannel === 'next' ? 'pulsar-next' : 'pulsar'; + + return this.scriptBaseName; } async installShellCommandsInteractively() { diff --git a/src/main-process/start.js b/src/main-process/start.js index 829aba60ae..5ce7fe4eb7 100644 --- a/src/main-process/start.js +++ b/src/main-process/start.js @@ -45,6 +45,8 @@ module.exports = function start(resourcePath, devResourcePath, startTime) { args.resourcePath = normalizeDriveLetterName(resourcePath); args.devResourcePath = normalizeDriveLetterName(devResourcePath); + const releaseChannel = getReleaseChannel(app.getVersion()); + process.env.ATOM_CHANNEL ??= releaseChannel; atomPaths.setAtomHome(app.getPath('home')); atomPaths.setUserData(app); @@ -69,7 +71,6 @@ module.exports = function start(resourcePath, devResourcePath, startTime) { return; } - const releaseChannel = getReleaseChannel(app.getVersion()); let appUserModelId = 'dev.pulsar-edit.pulsar.' + process.arch; // If the release channel is not stable, we append it to the app user model id. diff --git a/src/package-manager.js b/src/package-manager.js index 23a8e904dc..4fb6d8a36f 100644 --- a/src/package-manager.js +++ b/src/package-manager.js @@ -177,12 +177,19 @@ module.exports = class PackageManager { return this.emitter.on('did-unload-package', callback); } + // Returns the command needed to invoke PPM for the current release channel. + static getCommandName() { + let releaseChannel = atom.getReleaseChannel(); + let commandName = releaseChannel === 'next' ? 'ppm-next' : 'ppm'; + return process.platform === 'win32' ? `${commandName}.cmd` : commandName; + } + static possibleApmPaths(configPath) { if (process.env.APM_PATH || configPath) { return process.env.APM_PATH || configPath; } - const commandName = process.platform === 'win32' ? 'apm.cmd' : 'apm'; + const commandName = this.getCommandName(); const bundledPPMRoot = path.join(process.resourcesPath, 'app', 'ppm', 'bin', commandName); const unbundledPPMRoot = path.join(__dirname, '..', 'ppm', 'bin', commandName); @@ -208,7 +215,7 @@ module.exports = class PackageManager { return configPath || this.apmPath; } else { this.apmPath = PackageManager.possibleApmPaths(); - return this.apmPath + return this.apmPath; } }