Skip to content

Commit

Permalink
Use the version number as the source of truth for the release channel…
Browse files Browse the repository at this point in the history
…instead of the hodgepodge of methods we've been using.

This should ensure we're using the right versions of the `pulsar` and `ppm` executables for the current release channel — no matter how the user launched the app.
  • Loading branch information
savetheclocktower committed Jan 6, 2025
1 parent f0a21a4 commit d9ef212
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 36 deletions.
39 changes: 22 additions & 17 deletions src/atom-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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 => {
Expand All @@ -80,5 +85,5 @@ module.exports = {
}
},

getAppDirectory: getAppDirectory
getAppDirectory
};
28 changes: 12 additions & 16 deletions src/command-installer.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -18,6 +19,10 @@ module.exports = class CommandInstaller {
return process.resourcesPath;
}

getReleaseChannel() {
return getReleaseChannel(this.appVersion);
}

getScriptBaseName() {
if (this.scriptBaseName) {
return this.scriptBaseName;
Expand All @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion src/main-process/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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.
Expand Down
11 changes: 9 additions & 2 deletions src/package-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -208,7 +215,7 @@ module.exports = class PackageManager {
return configPath || this.apmPath;
} else {
this.apmPath = PackageManager.possibleApmPaths();
return this.apmPath
return this.apmPath;
}
}

Expand Down

0 comments on commit d9ef212

Please sign in to comment.