Skip to content
This repository was archived by the owner on Jan 20, 2023. It is now read-only.

Commit 047c1a1

Browse files
committed
fix: Convert package to ESM
1 parent 79904ea commit 047c1a1

File tree

16 files changed

+1301
-315
lines changed

16 files changed

+1301
-315
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ jobs:
2525
node-version: ${{ matrix.node-version }}
2626
cache: npm
2727
- run: npm ci
28-
- name: Ensure dependencies are compatible with the version of node
29-
run: npx ls-engines
28+
# waiting on https://github.com/ljharb/ls-engines/pull/23 to be fixed
29+
# - name: Ensure dependencies are compatible with the version of node
30+
# run: npx ls-engines
3031
- run: npm run test:ci
3132
test:
3233
runs-on: ubuntu-latest

index.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/* eslint require-atomic-updates: off */
22

3-
const AggregateError = require('aggregate-error');
4-
const getPkg = require('./lib/get-pkg.js');
5-
const verifyApm = require('./lib/verify.js');
6-
const prepareApm = require('./lib/prepare.js');
7-
const publishApm = require('./lib/publish.js');
3+
import AggregateError from 'aggregate-error';
4+
import getPkg from './lib/get-pkg.js';
5+
import verifyApm from './lib/verify.js';
6+
import prepareApm from './lib/prepare.js';
7+
import publishApm from './lib/publish.js';
88

99
let verified;
1010
let prepared;
1111

12-
async function verifyConditions(pluginConfig, context) {
12+
export async function verifyConditions(pluginConfig, context) {
1313
const errors = await verifyApm(pluginConfig, context);
1414

1515
try {
@@ -25,7 +25,7 @@ async function verifyConditions(pluginConfig, context) {
2525
verified = true;
2626
}
2727

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

3131
try {
@@ -43,7 +43,7 @@ async function prepare(pluginConfig, context) {
4343
prepared = true;
4444
}
4545

46-
async function publish(pluginConfig, context) {
46+
export async function publish(pluginConfig, context) {
4747
let pkg;
4848
const errors = verified ? [] : await verifyApm(pluginConfig, context);
4949

@@ -64,5 +64,3 @@ async function publish(pluginConfig, context) {
6464

6565
return publishApm(pluginConfig, pkg, context);
6666
}
67-
68-
module.exports = {verifyConditions, prepare, publish};

lib/definitions/errors.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,46 @@
1-
const pkg = require('../../package.json');
1+
import {dirname, resolve} from 'node:path';
2+
import {fileURLToPath} from 'node:url';
3+
import {readPackageSync} from 'read-pkg';
24

5+
const __dirname = dirname(fileURLToPath(import.meta.url));
6+
const pkg = readPackageSync({cwd: resolve(__dirname, '../../')});
37
const [homepage] = pkg.homepage.split('#');
48
const linkify = (file) => `${homepage}/blob/master/${file}`;
59

6-
module.exports = {
7-
ENOAPMTOKEN: () => ({
10+
export function ENOAPMTOKEN() {
11+
return {
812
message: 'No apm token specified.',
913
details: `An [apm token](${linkify(
1014
'README.md#atom-authentication'
1115
)}) must be created and set in the \`ATOM_ACCESS_TOKEN\` environment variable on your CI environment.
1216
1317
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.`,
14-
}),
15-
ENOAPMCLI: () => ({
18+
};
19+
}
20+
21+
export function ENOAPMCL() {
22+
return {
1623
message: 'The apm CLI must be installed.',
1724
details: `The \`apm\` command line has to be installed in your CI environment and available in the \`PATH\` environment varialbe.
1825
1926
See [Atom installation](${linkify('README.md#atom-installation')}) for more details.`,
20-
}),
21-
ENOPKGNAME: () => ({
27+
};
28+
}
29+
30+
export function ENOPKGNAM() {
31+
return {
2232
message: 'Missing `name` property in `package.json`.',
2333
details: `The \`package.json\`'s [name](https://docs.npmjs.com/files/package.json#name) property is required in order to publish an Atom package.
2434
2535
Please make sure to add a valid \`name\` for your package in your \`package.json\`.`,
26-
}),
27-
ENOPKG: () => ({
36+
};
37+
}
38+
39+
export function ENOPK() {
40+
return {
2841
message: 'Missing `package.json` file.',
2942
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.
3043
3144
Please follow the [npm guideline](https://docs.npmjs.com/getting-started/creating-node-modules) to create a valid \`package.json\` file.`,
32-
}),
33-
};
45+
};
46+
}

lib/get-error.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
const SemanticReleaseError = require('@semantic-release/error');
2-
const ERROR_DEFINITIONS = require('./definitions/errors.js');
1+
import SemanticReleaseError from '@semantic-release/error';
2+
import * as ERROR_DEFINITIONS from './definitions/errors.js';
33

4-
module.exports = (code, ctx = {}) => {
4+
export default function getError(code, ctx = {}) {
55
const {message, details} = ERROR_DEFINITIONS[code](ctx);
66
return new SemanticReleaseError(message, code, details);
7-
};
7+
}

lib/get-pkg.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const readPkg = require('read-pkg');
2-
const AggregateError = require('aggregate-error');
3-
const getError = require('./get-error.js');
1+
import {readPackage} from 'read-pkg';
2+
import AggregateError from 'aggregate-error';
3+
import getError from './get-error.js';
44

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

99
if (!pkg.name) {
1010
throw getError('ENOPKGNAME');
@@ -15,4 +15,4 @@ module.exports = async (pluginConfig, {cwd}) => {
1515
const error_ = error.code === 'ENOENT' ? new AggregateError([getError('ENOPKG')]) : new AggregateError([error]);
1616
throw error_;
1717
}
18-
};
18+
}

lib/prepare.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
const execa = require('execa');
1+
import execa from 'execa';
22

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

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

1010
await versionResult;
11-
};
11+
}

lib/publish.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const execa = require('execa');
1+
import execa from 'execa';
22

3-
module.exports = async (pluginConfig, {name}, context) => {
3+
export default async function publishApm(pluginConfig, {name}, context) {
44
const {
55
cwd,
66
env,
@@ -22,4 +22,4 @@ module.exports = async (pluginConfig, {name}, context) => {
2222

2323
logger.log(`Published ${name}@${version}`);
2424
return {name: 'Atom package', url: `https://atom.io/packages/${name}`};
25-
};
25+
}

lib/resolve-config.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
module.exports = (pluginConfig, {env}) => ({
2-
apmToken: env.ATOM_ACCESS_TOKEN,
3-
});
1+
export default function resolveConfig(pluginConfig, {env}) {
2+
return {
3+
apmToken: env.ATOM_ACCESS_TOKEN,
4+
};
5+
}

lib/verify.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const execa = require('execa');
2-
const resolveConfig = require('./resolve-config.js');
3-
const getError = require('./get-error.js');
1+
import execa from 'execa';
2+
import resolveConfig from './resolve-config.js';
3+
import getError from './get-error.js';
44

5-
module.exports = async (pluginConfig, context) => {
5+
export default async function verifyApm(pluginConfig, context) {
66
const {cwd, env} = context;
77
const errors = [];
88
const {apmToken} = resolveConfig(pluginConfig, context);
@@ -16,4 +16,4 @@ module.exports = async (pluginConfig, context) => {
1616
}
1717

1818
return errors;
19-
};
19+
}

0 commit comments

Comments
 (0)