Skip to content
This repository was archived by the owner on May 23, 2025. It is now read-only.

Commit 8ac4ced

Browse files
committed
[MAJOR] Convert to ES Modules
1 parent 75cef8e commit 8ac4ced

29 files changed

+5595
-8013
lines changed

.eslintrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
"env": {
44
"node": true
55
},
6+
"parser": "@babel/eslint-parser",
67
"parserOptions": {
7-
"ecmaVersion": 9
8+
"ecmaVersion": 2020
89
},
910
"plugins": [
11+
"eslint-plugin-import",
1012
"eslint-plugin-json"
1113
],
1214
"rules": {

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# CHANGELOG
22

3+
- **MAJOR:** Convert to ES Modules
4+
35
## 5.0.1
46

57
- Update dependencies
@@ -132,4 +134,3 @@
132134
## 1.0.0
133135

134136
- Birth of pullie
135-

babel.config.cjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
"presets": [
3+
["@babel/preset-env", {
4+
"targets": {
5+
"node": "current"
6+
}
7+
}]
8+
]
9+
}

commenter.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class Commenter {
1+
export default class Commenter {
22
/**
33
* Unified commenter module
44
*
@@ -48,19 +48,17 @@ class Commenter {
4848

4949
return commentList;
5050
}
51-
}
52-
53-
/**
54-
* Priority options to pass to `addComment`
55-
*
56-
* @enum {Number}
57-
* @readonly
58-
* @public
59-
*/
60-
Commenter.priority = {
61-
Low: 0,
62-
Medium: 1,
63-
High: 2
64-
};
6551

66-
module.exports = Commenter;
52+
/**
53+
* Priority options to pass to `addComment`
54+
*
55+
* @enum {Number}
56+
* @readonly
57+
* @public
58+
*/
59+
static priority = {
60+
Low: 0,
61+
Medium: 1,
62+
High: 2
63+
};
64+
}

config-processor.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @typedef {import('./plugins/base')} BasePlugin
2+
* @typedef {import('./plugins/base.js')} BasePlugin
33
* @typedef {{[key: string]: BasePlugin}} PluginManager
44
*/
55
/**
@@ -28,8 +28,8 @@
2828
* @param {string} name The name of the invalid plugin
2929
*/
3030

31-
const deepClone = require('clone-deep');
32-
const deepMerge = require('deepmerge');
31+
import deepClone from 'clone-deep';
32+
import deepMerge from 'deepmerge';
3333

3434
/**
3535
* Process the specified org-level and repo-level config into a merged configuration
@@ -41,7 +41,7 @@ const deepMerge = require('deepmerge');
4141
* @returns {PullieConfig} The merged config
4242
* @public
4343
*/
44-
const processConfig = module.exports = function processConfig(pluginManager, orgConfig, repoConfig, onInvalidPlugin) {
44+
export default function processConfig(pluginManager, orgConfig, repoConfig, onInvalidPlugin) {
4545
if (!orgConfig) {
4646
// Set up a default orgConfig so we can properly transform the repo config below
4747
orgConfig = {
@@ -83,7 +83,7 @@ const processConfig = module.exports = function processConfig(pluginManager, org
8383
config.plugins = plugins;
8484

8585
return config;
86-
};
86+
}
8787

8888
/**
8989
* Apply the include list of plugin names and return the merged plugin list
@@ -96,7 +96,7 @@ const processConfig = module.exports = function processConfig(pluginManager, org
9696
* @returns {PluginList} The filtered list of plugins
9797
*/
9898
// eslint-disable-next-line max-statements, complexity
99-
function applyIncludeList({ pluginManager, orgPlugins, repoIncludeList, onInvalidPlugin }) {
99+
export function applyIncludeList({ pluginManager, orgPlugins, repoIncludeList, onInvalidPlugin }) {
100100
const pluginEqual = {
101101
literal(x, y) {
102102
if (typeof x !== 'string') return false;
@@ -153,7 +153,7 @@ function applyIncludeList({ pluginManager, orgPlugins, repoIncludeList, onInvali
153153
* @param {string[]} opts.repoExcludeList A list of plugin names to exclude
154154
* @returns {PluginList} The filtered list of plugins
155155
*/
156-
function applyExcludeList({ orgPlugins, repoExcludeList }) {
156+
export function applyExcludeList({ orgPlugins, repoExcludeList }) {
157157
return orgPlugins.filter(plugin => {
158158
if (typeof plugin === 'string') {
159159
return !repoExcludeList.includes(plugin);
@@ -165,7 +165,3 @@ function applyExcludeList({ orgPlugins, repoExcludeList }) {
165165
return true;
166166
});
167167
}
168-
169-
// For unit testing
170-
processConfig._applyIncludeList = applyIncludeList;
171-
processConfig._applyExcludeList = applyExcludeList;

docs.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
const handlebars = require('handlebars');
2-
const fs = require('fs');
1+
import express from 'express';
2+
import handlebars from 'handlebars';
3+
import fs from 'fs';
4+
import path from 'path';
5+
import Prism from 'prismjs';
6+
import loadLanguages from 'prismjs/components/index.js';
7+
loadLanguages(['json']);
8+
import resolveCwd from 'resolve-cwd';
9+
import { fileURLToPath } from 'url';
10+
11+
import { createRequire } from 'module';
12+
const require = createRequire(import.meta.url);
313
const packageJson = require('./package.json');
4-
const path = require('path');
5-
const Prism = require('prismjs');
6-
require('prismjs/components/')(['json']);
7-
const resolveCwd = require('resolve-cwd');
814

915
/**
1016
* @typedef {import('express').Router} expressRouter
@@ -14,7 +20,8 @@ const resolveCwd = require('resolve-cwd');
1420
*
1521
* @param {expressRouter} router Express router to attach routes to
1622
*/
17-
module.exports = function setupDocsRoutes(router) {
23+
export default function setupDocsRoutes(router) {
24+
const __dirname = fileURLToPath(new URL('.', import.meta.url));
1825
// eslint-disable-next-line no-sync
1926
const docsSource = fs.readFileSync(path.join(__dirname, 'views/home.hbs'), { encoding: 'utf8' });
2027
handlebars.registerHelper('code', options => new handlebars.SafeString(
@@ -25,7 +32,7 @@ module.exports = function setupDocsRoutes(router) {
2532
VERSION: packageJson.version
2633
});
2734

28-
router.use('/static', require('express').static(path.join(__dirname, 'static')));
35+
router.use('/static', express.static(path.join(__dirname, 'static')));
2936
router.get('/', (req, res) => {
3037
res.send(docsHtml);
3138
});
@@ -35,4 +42,4 @@ module.exports = function setupDocsRoutes(router) {
3542
router.get('/healthcheck(.html)?', (req, res) => {
3643
res.send('page ok');
3744
});
38-
};
45+
}

index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const processPR = require('./processor');
2-
const setupDocsRoutes = require('./docs');
1+
import processPR from './processor.js';
2+
import setupDocsRoutes from './docs.js';
33

44
/**
55
* @typedef {import('probot').Application} ProbotApp
@@ -13,7 +13,7 @@ const setupDocsRoutes = require('./docs');
1313
* @param {Object} helpers Helpers
1414
* @param {GetRouterFn} helpers.getRouter Function to get an Express router
1515
*/
16-
function appFn(app, { getRouter }) {
16+
export default function appFn(app, { getRouter }) {
1717
if (!process.env.DISABLE_DOCS_ROUTE) {
1818
const docsPath = process.env.DOCS_PATH || '/docs';
1919
app.log.info('Setting up docs route at ' + docsPath);
@@ -26,5 +26,4 @@ function appFn(app, { getRouter }) {
2626
app.on('pull_request.ready_for_review', processPR);
2727
}
2828

29-
appFn.setupDocsRoutes = setupDocsRoutes;
30-
module.exports = appFn;
29+
export { setupDocsRoutes };

0 commit comments

Comments
 (0)