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

Commit e813180

Browse files
committed
chore: export functions
1 parent bb472a1 commit e813180

File tree

4 files changed

+47
-52
lines changed

4 files changed

+47
-52
lines changed

index.js

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,62 +9,58 @@ import publishApm from './lib/publish.js';
99
let verified;
1010
let prepared;
1111

12-
const plugin = {
13-
async verifyConditions(pluginConfig, context) {
14-
const errors = await verifyApm(pluginConfig, context);
12+
export async function verifyConditions(pluginConfig, context) {
13+
const errors = await verifyApm(pluginConfig, context);
1514

16-
try {
17-
await getPkg(pluginConfig, context);
18-
} catch (error) {
19-
errors.push(...error.errors);
20-
}
15+
try {
16+
await getPkg(pluginConfig, context);
17+
} catch (error) {
18+
errors.push(...error.errors);
19+
}
2120

22-
if (errors.length > 0) {
23-
throw new AggregateError(errors);
24-
}
21+
if (errors.length > 0) {
22+
throw new AggregateError(errors);
23+
}
2524

26-
verified = true;
27-
},
25+
verified = true;
26+
};
2827

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

32-
try {
33-
await getPkg(pluginConfig, context);
34-
} catch (error) {
35-
errors.push(...error.errors);
36-
}
31+
try {
32+
await getPkg(pluginConfig, context);
33+
} catch (error) {
34+
errors.push(...error.errors);
35+
}
3736

38-
if (errors.length > 0) {
39-
throw new AggregateError(errors);
40-
}
37+
if (errors.length > 0) {
38+
throw new AggregateError(errors);
39+
}
4140

42-
await prepareApm(pluginConfig, context);
41+
await prepareApm(pluginConfig, context);
4342

44-
prepared = true;
45-
},
43+
prepared = true;
44+
};
4645

47-
async publish(pluginConfig, context) {
48-
let pkg;
49-
const errors = verified ? [] : await verifyApm(pluginConfig, context);
46+
export async function publish(pluginConfig, context) {
47+
let pkg;
48+
const errors = verified ? [] : await verifyApm(pluginConfig, context);
5049

51-
try {
52-
pkg = await getPkg(pluginConfig, context);
53-
} catch (error) {
54-
errors.push(...error.errors);
55-
}
50+
try {
51+
pkg = await getPkg(pluginConfig, context);
52+
} catch (error) {
53+
errors.push(...error.errors);
54+
}
5655

57-
if (errors.length > 0) {
58-
throw new AggregateError(errors);
59-
}
56+
if (errors.length > 0) {
57+
throw new AggregateError(errors);
58+
}
6059

61-
if (!prepared) {
62-
await prepareApm(pluginConfig, context);
63-
prepared = true;
64-
}
60+
if (!prepared) {
61+
await prepareApm(pluginConfig, context);
62+
prepared = true;
63+
}
6564

66-
return publishApm(pluginConfig, pkg, context);
67-
},
65+
return publishApm(pluginConfig, pkg, context);
6866
};
69-
70-
export default plugin;

lib/definitions/errors.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import {dirname, resolve} from 'node:path';
2-
import {fileURLToPath} from 'node:url';
3-
import {readPackageSync} from 'read-pkg';
1+
import {createRequire} from 'node:module';
2+
3+
const require = createRequire(import.meta.url);
4+
const pkg = require('../../package.json');
45

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
],
5858
"license": "MIT",
5959
"type": "module",
60-
"main": "index.js",
60+
"exports": "./index.js",
6161
"nyc": {
6262
"include": [
6363
"lib/**/*.js",

test/integration.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ test.after.always(async () => {
2626
test.beforeEach(async (t) => {
2727
// Math.random used to load a fresh module each time.
2828
// eslint-disable-next-line node/no-unsupported-features/es-syntax
29-
t.context.m = (await import(`../index.js?${Math.random().toString(36)}`)).default;
29+
t.context.m = await import(`../index.js?${Math.random().toString(36)}`);
3030
t.context.log = sinon.spy();
3131
t.context.stdout = new WritableStreamBuffer();
3232
t.context.stderr = new WritableStreamBuffer();

0 commit comments

Comments
 (0)