Skip to content
Open
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
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
"git-utils": "^5.7.2",
"hosted-git-info": "^3.0.7",
"keytar": "^7.7.0",
"mv": "2.1.1",
"ncp": "~2.0.0",
"npm": "https://github.com/pulsar-edit/npm-cli/releases/download/v6.14.19-pulsar2/npm-6.14.19-pulsar2.tgz",
"open": "7.3.0",
"plist": "3",
Expand All @@ -44,7 +42,6 @@
"temp": "^0.9.4",
"underscore-plus": "1.x",
"wordwrap": "1.0.0",
"wrench": "~1.5.1",
"yargs": "^3.32.0"
},
"devDependencies": {
Expand Down
18 changes: 9 additions & 9 deletions script/download-node.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require('fs');
const mv = require('mv');
const fsPromises = require('fs/promises');
const zlib = require('zlib');
const path = require('path');

Expand Down Expand Up @@ -54,19 +54,19 @@ const downloadTarballAndExtract = function(url, location, callback) {
.pipe(zlib.createGunzip()).pipe(stream);
};

//TODO: verbatim copied from fs.js, deduplicate it
async function mv(sourcePath, destinationPath) {
await fsPromises.rm(destinationPath, { recursive: true, force: true });
await fsPromises.mkdir(path.dirname(destinationPath), { mode: 0o755, recursive: true });
await fsPromises.rename(sourcePath, destinationPath);
}

const copyNodeBinToLocation = function(callback, version, targetFilename, fromDirectory) {
const arch = identifyArch();
const subDir = `node-${version}-${process.platform}-${arch}`;
const downloadedNodePath = path.join(fromDirectory, subDir, 'bin', 'node');
return mv(downloadedNodePath, targetFilename, {mkdirp: true}, function(err) {
if (err) {
callback(err);
return;
}

fs.chmodSync(targetFilename, "755");
callback()
});
mv(downloadedNodePath, targetFilename).then(() => void callback(), err => void callback(err));
};

const downloadNode = function(version, done) {
Expand Down
10 changes: 5 additions & 5 deletions spec/ci-spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const path = require('path');
const fs = require('fs');
const fsPromises = require('fs/promises');
const http = require('http');
const temp = require('temp');
const express = require('express');
const wrench = require('wrench');
const CSON = require('season');
const apm = require('../src/apm-cli');
const { nodeVersion } = JSON.parse(fs.readFileSync(path.join(__dirname,'config.json')));
Expand Down Expand Up @@ -123,7 +123,7 @@ describe('apm ci', () => {

it('installs dependency versions as specified by the lockfile', async () => {
const moduleDirectory = path.join(temp.mkdirSync('apm-test-'), 'test-module-with-lockfile');
wrench.copyDirSyncRecursive(path.join(__dirname, 'fixtures', 'test-module-with-lockfile'), moduleDirectory);
await fsPromises.cp(path.join(__dirname, 'fixtures', 'test-module-with-lockfile'), moduleDirectory, { recursive: true });
process.chdir(moduleDirectory);
const callback = jasmine.createSpy('callback');
await apmRun(['ci'], callback);
Expand All @@ -136,7 +136,7 @@ describe('apm ci', () => {

it('builds a native dependency correctly', async () => {
const moduleDirectory = path.join(temp.mkdirSync('apm-test-'), 'test-module-with-native');
wrench.copyDirSyncRecursive(path.join(__dirname, 'fixtures', 'test-module-with-lockfile'), moduleDirectory);
await fsPromises.cp(path.join(__dirname, 'fixtures', 'test-module-with-lockfile'), moduleDirectory, { recursive: true });
process.chdir(moduleDirectory);
const pjsonPath = path.join(moduleDirectory, 'package.json');
const pjson = CSON.readFileSync(pjsonPath);
Expand All @@ -160,7 +160,7 @@ describe('apm ci', () => {

it('fails if the lockfile is not present', async () => {
const moduleDirectory = path.join(temp.mkdirSync('apm-test-'), 'test-module');
wrench.copyDirSyncRecursive(path.join(__dirname, 'fixtures', 'test-module'), moduleDirectory);
await fsPromises.cp(path.join(__dirname, 'fixtures', 'test-module'), moduleDirectory, { recursive: true });
process.chdir(moduleDirectory);

const callback = jasmine.createSpy('callback');
Expand All @@ -171,7 +171,7 @@ describe('apm ci', () => {

it('fails if the lockfile is out of date', async () => {
const moduleDirectory = path.join(temp.mkdirSync('apm-test-'), 'test-module-with-lockfile');
wrench.copyDirSyncRecursive(path.join(__dirname, 'fixtures', 'test-module-with-lockfile'), moduleDirectory);
await fsPromises.cp(path.join(__dirname, 'fixtures', 'test-module-with-lockfile'), moduleDirectory, { recursive: true });
process.chdir(moduleDirectory);
const pjsonPath = path.join(moduleDirectory, 'package.json');
const pjson = CSON.readFileSync(pjsonPath);
Expand Down
6 changes: 3 additions & 3 deletions spec/clean-spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const path = require('path');
const fs = require('fs-plus');
const fsPromises = require('fs/promises');
const temp = require('temp');
const express = require('express');
const http = require('http');
const wrench = require('wrench');
const apm = require('../src/apm-cli');
const { nodeVersion } = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json')));

Expand Down Expand Up @@ -66,14 +66,14 @@ describe('apm clean', () => {
);
server = http.createServer(app);
await new Promise((resolve) => {
server.listen(3000, '127.0.0.1', () => {
server.listen(3000, '127.0.0.1', async () => {
console.log('Server started');
process.env.ATOM_HOME = temp.mkdirSync('apm-home-dir-');
process.env.ATOM_ELECTRON_URL = 'http://localhost:3000/node';
process.env.ATOM_ELECTRON_VERSION = nodeVersion;
process.env.npm_config_registry = 'http://localhost:3000/';
moduleDirectory = path.join(temp.mkdirSync('apm-test-module-'), 'test-module-with-dependencies');
wrench.copyDirSyncRecursive(path.join(__dirname, 'fixtures', 'test-module-with-dependencies'), moduleDirectory);
await fsPromises.cp(path.join(__dirname, 'fixtures', 'test-module-with-dependencies'), moduleDirectory, { recursive: true });
process.chdir(moduleDirectory);
resolve();
});
Expand Down
17 changes: 10 additions & 7 deletions spec/disable-spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require('fs-plus');
const wrench = require('wrench');
const fsPromises = require('fs/promises');
const path = require('path');
const temp = require('temp');
const CSON = require('season');
Expand All @@ -26,17 +26,20 @@ describe('apm disable', () => {
const packagesPath = path.join(atomHome, 'packages');
const packageSrcPath = path.join(__dirname, 'fixtures');
fs.makeTreeSync(packagesPath);
wrench.copyDirSyncRecursive(
await fsPromises.cp(
path.join(packageSrcPath, 'test-module'),
path.join(packagesPath, 'test-module')
path.join(packagesPath, 'test-module'),
{ recursive: true }
);
wrench.copyDirSyncRecursive(
await fsPromises.cp(
path.join(packageSrcPath, 'test-module-two'),
path.join(packagesPath, 'test-module-two')
path.join(packagesPath, 'test-module-two'),
{ recursive: true }
);
wrench.copyDirSyncRecursive(
await fsPromises.cp(
path.join(packageSrcPath, 'test-module-three'),
path.join(packagesPath, 'test-module-three')
path.join(packagesPath, 'test-module-three'),
{ recursive: true }
);

await apmRun(['disable', 'test-module-two', 'not-installed', 'test-module-three']);
Expand Down
9 changes: 5 additions & 4 deletions spec/install-spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const path = require('path');
const CSON = require('season');
const fs = require('../src/fs');
const fsPromises = require('fs/promises');
const temp = require('temp');
const express = require('express');
const http = require('http');
const wrench = require('wrench');
const Install = require('../src/install');
const { nodeVersion } = JSON.parse(fs.readFileSync(path.join(__dirname,'config.json')));

Expand Down Expand Up @@ -279,7 +279,7 @@ describe('apm install', () => {
describe('when no path is specified', () => {
it('installs all dependent modules', async () => {
const moduleDirectory = path.join(temp.mkdirSync('apm-test-module-'), 'test-module-with-dependencies');
wrench.copyDirSyncRecursive(path.join(__dirname, 'fixtures', 'test-module-with-dependencies'), moduleDirectory);
await fsPromises.cp(path.join(__dirname, 'fixtures', 'test-module-with-dependencies'), moduleDirectory, { recursive: true });
process.chdir(moduleDirectory);
const callback = jasmine.createSpy('callback');
await apmRun(['install'], callback);
Expand Down Expand Up @@ -367,9 +367,10 @@ describe('apm install', () => {
});
const packageDirectory = path.join(atomRepoPath, 'packages', 'test-module-with-dependencies');
fs.makeTreeSync(path.join(atomRepoPath, 'packages'));
wrench.copyDirSyncRecursive(
await fsPromises.cp(
path.join(__dirname, 'fixtures', 'test-module-with-dependencies'),
packageDirectory
packageDirectory,
{ recursive: true }
);
const originalPath = process.cwd();
process.chdir(atomRepoPath);
Expand Down
9 changes: 5 additions & 4 deletions spec/list-spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path');
const fs = require('fs-plus');
const fsPromises = require('fs/promises');
const temp = require('temp');
const wrench = require('wrench');
const CSON = require('season');

async function listPackages (...args) {
Expand Down Expand Up @@ -116,12 +116,13 @@ describe('apm list', () => {
}); // ensure invalid packages aren't listed

describe('enabling and disabling packages', () => {
beforeEach(() => {
beforeEach(async () => {
const packagesPath = path.join(atomHome, 'packages');
fs.makeTreeSync(packagesPath);
wrench.copyDirSyncRecursive(
await fsPromises.cp(
path.join(__dirname, 'fixtures', 'test-module'),
path.join(packagesPath, 'test-module')
path.join(packagesPath, 'test-module'),
{ recursive: true }
);
const configPath = path.join(atomHome, 'config.cson');
CSON.writeFileSync(configPath, {
Expand Down
28 changes: 8 additions & 20 deletions src/fs.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

const fs = require('fs-plus');
const fsPromises = require("fs/promises");
const ncp = require('ncp');
const wrench = require('wrench');
const path = require('path');

const fsAdditions = {
Expand All @@ -19,28 +17,18 @@ const fsAdditions = {
},

listRecursive(directoryPath) {
return wrench.readdirSyncRecursive(directoryPath);
return fsPromises.readdir(directoryPath, { recursive: true });
},

cp(sourcePath, destinationPath) {
return new Promise((resolve, reject) => {
fsPromises.rm(destinationPath, { recursive: true, force: true }).then(() => {
ncp(sourcePath, destinationPath, (error, value) => void (error != null ? reject(error) : resolve(value)));
}).catch((error) => {
return reject(error);
});
});
async cp(sourcePath, destinationPath) {
await fsPromises.rm(destinationPath, { recursive: true, force: true });
await fsPromises.cp(sourcePath, destinationPath, { recursive: true, verbatimSymlinks: true });
},

mv(sourcePath, destinationPath) {
return new Promise((resolve, reject) => {
fsPromises.rm(destinationPath, { recursive: true, force: true }).then(() => {
wrench.mkdirSyncRecursive(path.dirname(destinationPath), 0o755);
fs.rename(sourcePath, destinationPath, (error, value) => void (error != null ? reject(error) : resolve(value)));
}).catch((error) => {
return reject(error);
});
});
async mv(sourcePath, destinationPath) {
await fsPromises.rm(destinationPath, { recursive: true, force: true });
await fsPromises.mkdir(path.dirname(destinationPath), { mode: 0o755, recursive: true });
await fsPromises.rename(sourcePath, destinationPath);
}
};

Expand Down
14 changes: 7 additions & 7 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ on the option selected.\
return `You must specify one of ${this.supportedSyntaxes.join(', ')} after the --syntax argument`;
}
templatePath = this.getTemplatePath(options.argv, `package-${syntax}`);
this.generateFromTemplate(packagePath, templatePath);
await this.generateFromTemplate(packagePath, templatePath);
return;
}
if (options.argv.theme?.length > 0) {
Expand All @@ -78,15 +78,15 @@ on the option selected.\
}
const themePath = path.resolve(options.argv.theme);
templatePath = this.getTemplatePath(options.argv, 'theme');
this.generateFromTemplate(themePath, templatePath);
await this.generateFromTemplate(themePath, templatePath);
return;
}
if (options.argv.language?.length > 0) {
let languagePath = path.resolve(options.argv.language);
const languageName = path.basename(languagePath).replace(/^language-/, '');
languagePath = path.join(path.dirname(languagePath), `language-${languageName}`);
templatePath = this.getTemplatePath(options.argv, 'language');
this.generateFromTemplate(languagePath, templatePath, languageName);
await this.generateFromTemplate(languagePath, templatePath, languageName);
return;
}
// If we get this far, something about this command was invalid.
Expand All @@ -112,7 +112,7 @@ on the option selected.\
await converter.convert();
destinationPath = path.resolve(destinationPath);
const templatePath = path.resolve(__dirname, '..', 'templates', 'bundle');
this.generateFromTemplate(destinationPath, templatePath);
await this.generateFromTemplate(destinationPath, templatePath);
}

async convertTheme(sourcePath, destinationPath) {
Expand All @@ -125,18 +125,18 @@ on the option selected.\
await converter.convert();
destinationPath = path.resolve(destinationPath);
const templatePath = path.resolve(__dirname, '..', 'templates', 'theme');
this.generateFromTemplate(destinationPath, templatePath);
await this.generateFromTemplate(destinationPath, templatePath);
fs.removeSync(path.join(destinationPath, 'styles', 'colors.less'));
fs.removeSync(path.join(destinationPath, 'LICENSE.md'));
}

generateFromTemplate(packagePath, templatePath, packageName) {
async generateFromTemplate(packagePath, templatePath, packageName) {
packageName ??= path.basename(packagePath);
const packageAuthor = process.env.GITHUB_USER || 'atom';

fs.makeTreeSync(packagePath);

for (let childPath of Array.from(fs.listRecursive(templatePath))) {
for (let childPath of Array.from(await fs.listRecursive(templatePath))) {
const templateChildPath = path.resolve(templatePath, childPath);
let relativePath = templateChildPath.replace(templatePath, "");
relativePath = relativePath.replace(/^\//, '');
Expand Down
Loading