Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ jobs:
- uses: actions/setup-node@v2
with:
cache: npm
node-version: 16
node-version: 'lts/*'
check-latest: true
- run: npm ci
- run: npx semantic-release
env:
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ jobs:
matrix:
node-version:
- '14.17'
- 16
- 'lts/*'
- '*'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Expand All @@ -24,6 +25,7 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
cache: npm
check-latest: true
- run: npm ci
- name: Ensure dependencies are compatible with the version of node
run: npx ls-engines
Expand All @@ -36,6 +38,7 @@ jobs:
- uses: actions/setup-node@v2
with:
cache: npm
node-version: 16
node-version: 'lts/*'
check-latest: true
- run: npm ci
- run: npm run lint
24 changes: 11 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/* eslint require-atomic-updates: off */

const AggregateError = require('aggregate-error');
const getPkg = require('./lib/get-pkg.js');
const verifyApm = require('./lib/verify.js');
const prepareApm = require('./lib/prepare.js');
const publishApm = require('./lib/publish.js');
import AggregateError from 'aggregate-error';
import getPkg from './lib/get-pkg.js';
import verifyApm from './lib/verify.js';
import prepareApm from './lib/prepare.js';
import publishApm from './lib/publish.js';

let verified;
let prepared;

async function verifyConditions(pluginConfig, context) {
export async function verifyConditions(pluginConfig, context) {
const errors = await verifyApm(pluginConfig, context);

try {
await getPkg(pluginConfig, context);
} catch (error) {
errors.push(...error);
errors.push(...error.errors);
}

if (errors.length > 0) {
Expand All @@ -25,13 +25,13 @@ async function verifyConditions(pluginConfig, context) {
verified = true;
}

async function prepare(pluginConfig, context) {
export async function prepare(pluginConfig, context) {
const errors = verified ? [] : await verifyApm(pluginConfig, context);

try {
await getPkg(pluginConfig, context);
} catch (error) {
errors.push(...error);
errors.push(...error.errors);
}

if (errors.length > 0) {
Expand All @@ -43,14 +43,14 @@ async function prepare(pluginConfig, context) {
prepared = true;
}

async function publish(pluginConfig, context) {
export async function publish(pluginConfig, context) {
let pkg;
const errors = verified ? [] : await verifyApm(pluginConfig, context);

try {
pkg = await getPkg(pluginConfig, context);
} catch (error) {
errors.push(...error);
errors.push(...error.errors);
}

if (errors.length > 0) {
Expand All @@ -64,5 +64,3 @@ async function publish(pluginConfig, context) {

return publishApm(pluginConfig, pkg, context);
}

module.exports = {verifyConditions, prepare, publish};
54 changes: 35 additions & 19 deletions lib/definitions/errors.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,49 @@
import {createRequire} from 'node:module';

const require = createRequire(import.meta.url);
const pkg = require('../../package.json');

const [homepage] = pkg.homepage.split('#');
const linkify = (file) => `${homepage}/blob/master/${file}`;

module.exports = {
ENOAPMTOKEN: () => ({
message: 'No apm token specified.',
details: `An [apm token](${linkify(
'README.md#atom-authentication'
)}) must be created and set in the \`ATOM_ACCESS_TOKEN\` environment variable on your CI environment.
const errors = {
ENOAPMTOKEN() {
return {
message: 'No apm token specified.',
details: `An [apm token](${linkify(
'README.md#atom-authentication'
)}) must be created and set in the \`ATOM_ACCESS_TOKEN\` environment variable on your CI environment.

Please visit your account page on [atom.io](https://atom.io/account) and to set it in the \`ATOM_ACCESS_TOKEN\` environment variable on your CI environment.`,
}),
ENOAPMCLI: () => ({
message: 'The apm CLI must be installed.',
details: `The \`apm\` command line has to be installed in your CI environment and available in the \`PATH\` environment varialbe.
};
},

ENOAPMCLI() {
return {
message: 'The apm CLI must be installed.',
details: `The \`apm\` command line has to be installed in your CI environment and available in the \`PATH\` environment varialbe.

See [Atom installation](${linkify('README.md#atom-installation')}) for more details.`,
}),
ENOPKGNAME: () => ({
message: 'Missing `name` property in `package.json`.',
details: `The \`package.json\`'s [name](https://docs.npmjs.com/files/package.json#name) property is required in order to publish an Atom package.
};
},

ENOPKGNAME() {
return {
message: 'Missing `name` property in `package.json`.',
details: `The \`package.json\`'s [name](https://docs.npmjs.com/files/package.json#name) property is required in order to publish an Atom package.

Please make sure to add a valid \`name\` for your package in your \`package.json\`.`,
}),
ENOPKG: () => ({
message: 'Missing `package.json` file.',
details: `A [package.json file](https://docs.npmjs.com/files/package.json) at the root of your project is required to publish an Atom package.
};
},

ENOPKG() {
return {
message: 'Missing `package.json` file.',
details: `A [package.json file](https://docs.npmjs.com/files/package.json) at the root of your project is required to publish an Atom package.

Please follow the [npm guideline](https://docs.npmjs.com/getting-started/creating-node-modules) to create a valid \`package.json\` file.`,
}),
};
},
};

export default errors;
8 changes: 4 additions & 4 deletions lib/get-error.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const SemanticReleaseError = require('@semantic-release/error');
const ERROR_DEFINITIONS = require('./definitions/errors.js');
import SemanticReleaseError from '@semantic-release/error';
import ERROR_DEFINITIONS from './definitions/errors.js';

module.exports = (code, ctx = {}) => {
export default function getError(code, ctx = {}) {
const {message, details} = ERROR_DEFINITIONS[code](ctx);
return new SemanticReleaseError(message, code, details);
};
}
12 changes: 6 additions & 6 deletions lib/get-pkg.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const readPkg = require('read-pkg');
const AggregateError = require('aggregate-error');
const getError = require('./get-error.js');
import {readPackage} from 'read-pkg';
import AggregateError from 'aggregate-error';
import getError from './get-error.js';

module.exports = async (pluginConfig, {cwd}) => {
export default async function getPkg(pluginConfig, {cwd}) {
try {
const pkg = await readPkg({cwd});
const pkg = await readPackage({cwd});

if (!pkg.name) {
throw getError('ENOPKGNAME');
Expand All @@ -15,4 +15,4 @@ module.exports = async (pluginConfig, {cwd}) => {
const error_ = error.code === 'ENOENT' ? new AggregateError([getError('ENOPKG')]) : new AggregateError([error]);
throw error_;
}
};
}
6 changes: 3 additions & 3 deletions lib/prepare.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const execa = require('execa');
import {execa} from 'execa';

module.exports = async (pluginConfig, {cwd, env, stdout, stderr, nextRelease: {version}, logger}) => {
export default async function prepare(pluginConfig, {cwd, env, stdout, stderr, nextRelease: {version}, logger}) {
logger.log(`Write version ${version} to package.json`);

const versionResult = execa('npm', ['version', version, '--no-git-tag-version'], {cwd, env});
versionResult.stdout.pipe(stdout, {end: false});
versionResult.stderr.pipe(stderr, {end: false});

await versionResult;
};
}
6 changes: 3 additions & 3 deletions lib/publish.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const execa = require('execa');
import {execa} from 'execa';

module.exports = async (pluginConfig, {name}, context) => {
export default async function publish(pluginConfig, {name}, context) {
const {
cwd,
env,
Expand All @@ -22,4 +22,4 @@ module.exports = async (pluginConfig, {name}, context) => {

logger.log(`Published ${name}@${version}`);
return {name: 'Atom package', url: `https://atom.io/packages/${name}`};
};
}
8 changes: 5 additions & 3 deletions lib/resolve-config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module.exports = (pluginConfig, {env}) => ({
apmToken: env.ATOM_ACCESS_TOKEN,
});
export default function resolveConfig(pluginConfig, {env}) {
return {
apmToken: env.ATOM_ACCESS_TOKEN,
};
}
10 changes: 5 additions & 5 deletions lib/verify.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const execa = require('execa');
const resolveConfig = require('./resolve-config.js');
const getError = require('./get-error.js');
import {execa} from 'execa';
import resolveConfig from './resolve-config.js';
import getError from './get-error.js';

module.exports = async (pluginConfig, context) => {
export default async function verify(pluginConfig, context) {
const {cwd, env} = context;
const errors = [];
const {apmToken} = resolveConfig(pluginConfig, context);
Expand All @@ -16,4 +16,4 @@ module.exports = async (pluginConfig, context) => {
}

return errors;
};
}
Loading