Skip to content

Commit

Permalink
Merge pull request #95 from godaddy/esm
Browse files Browse the repository at this point in the history
[MAJOR] Convert to ES Modules
  • Loading branch information
decompil3d committed Aug 16, 2021
2 parents 75cef8e + f1694a9 commit 1c83802
Show file tree
Hide file tree
Showing 31 changed files with 5,606 additions and 8,023 deletions.
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
"env": {
"node": true
},
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": 9
"ecmaVersion": 2020
},
"plugins": [
"eslint-plugin-import",
"eslint-plugin-json"
],
"rules": {
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
node-version: [14.x, 16.x]

steps:
- uses: actions/checkout@v2
Expand All @@ -28,9 +28,9 @@ jobs:
- run: npm run build --if-present
- run: npm test
- run: npm run coverage
if: ${{ matrix.node-version == '14.x' }} # only report coverage on latest Node
if: ${{ matrix.node-version == '14.x' }} # only report coverage on latest Node LTS
- name: Coveralls
if: ${{ matrix.node-version == '14.x' }} # only report coverage on latest Node
if: ${{ matrix.node-version == '14.x' }} # only report coverage on latest Node LTS
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 6.0.0-alpha.0

- **MAJOR:** Convert to ES Modules

## 5.0.1

- Update dependencies
Expand Down Expand Up @@ -132,4 +136,3 @@
## 1.0.0

- Birth of pullie

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ tickets, requesting reviews, and commenting about a missing required file change

## System requirements

Pullie runs on public GitHub or on GitHub Enterprise 2.14 or later.
Pullie runs on public GitHub or on GitHub Enterprise 2.14 or later. It requires Node.js 14 or later.

## How to run/deploy

Expand Down
9 changes: 9 additions & 0 deletions babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
presets: [
['@babel/preset-env', {
targets: {
node: 'current'
}
}]
]
};
30 changes: 14 additions & 16 deletions commenter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Commenter {
export default class Commenter {
/**
* Unified commenter module
*
Expand Down Expand Up @@ -48,19 +48,17 @@ class Commenter {

return commentList;
}
}

/**
* Priority options to pass to `addComment`
*
* @enum {Number}
* @readonly
* @public
*/
Commenter.priority = {
Low: 0,
Medium: 1,
High: 2
};

module.exports = Commenter;
/**
* Priority options to pass to `addComment`
*
* @enum {Number}
* @readonly
* @public
*/
static priority = {
Low: 0,
Medium: 1,
High: 2
};
}
18 changes: 7 additions & 11 deletions config-processor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @typedef {import('./plugins/base')} BasePlugin
* @typedef {import('./plugins/base.js')} BasePlugin
* @typedef {{[key: string]: BasePlugin}} PluginManager
*/
/**
Expand Down Expand Up @@ -28,8 +28,8 @@
* @param {string} name The name of the invalid plugin
*/

const deepClone = require('clone-deep');
const deepMerge = require('deepmerge');
import deepClone from 'clone-deep';
import deepMerge from 'deepmerge';

/**
* Process the specified org-level and repo-level config into a merged configuration
Expand All @@ -41,7 +41,7 @@ const deepMerge = require('deepmerge');
* @returns {PullieConfig} The merged config
* @public
*/
const processConfig = module.exports = function processConfig(pluginManager, orgConfig, repoConfig, onInvalidPlugin) {
export default function processConfig(pluginManager, orgConfig, repoConfig, onInvalidPlugin) {
if (!orgConfig) {
// Set up a default orgConfig so we can properly transform the repo config below
orgConfig = {
Expand Down Expand Up @@ -83,7 +83,7 @@ const processConfig = module.exports = function processConfig(pluginManager, org
config.plugins = plugins;

return config;
};
}

/**
* Apply the include list of plugin names and return the merged plugin list
Expand All @@ -96,7 +96,7 @@ const processConfig = module.exports = function processConfig(pluginManager, org
* @returns {PluginList} The filtered list of plugins
*/
// eslint-disable-next-line max-statements, complexity
function applyIncludeList({ pluginManager, orgPlugins, repoIncludeList, onInvalidPlugin }) {
export function applyIncludeList({ pluginManager, orgPlugins, repoIncludeList, onInvalidPlugin }) {
const pluginEqual = {
literal(x, y) {
if (typeof x !== 'string') return false;
Expand Down Expand Up @@ -153,7 +153,7 @@ function applyIncludeList({ pluginManager, orgPlugins, repoIncludeList, onInvali
* @param {string[]} opts.repoExcludeList A list of plugin names to exclude
* @returns {PluginList} The filtered list of plugins
*/
function applyExcludeList({ orgPlugins, repoExcludeList }) {
export function applyExcludeList({ orgPlugins, repoExcludeList }) {
return orgPlugins.filter(plugin => {
if (typeof plugin === 'string') {
return !repoExcludeList.includes(plugin);
Expand All @@ -165,7 +165,3 @@ function applyExcludeList({ orgPlugins, repoExcludeList }) {
return true;
});
}

// For unit testing
processConfig._applyIncludeList = applyIncludeList;
processConfig._applyExcludeList = applyExcludeList;
25 changes: 16 additions & 9 deletions docs.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
const handlebars = require('handlebars');
const fs = require('fs');
import express from 'express';
import handlebars from 'handlebars';
import fs from 'fs';
import path from 'path';
import Prism from 'prismjs';
import loadLanguages from 'prismjs/components/index.js';
loadLanguages(['json']);
import resolveCwd from 'resolve-cwd';
import { fileURLToPath } from 'url';

import { createRequire } from 'module';
const require = createRequire(import.meta.url);
const packageJson = require('./package.json');
const path = require('path');
const Prism = require('prismjs');
require('prismjs/components/')(['json']);
const resolveCwd = require('resolve-cwd');

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

router.use('/static', require('express').static(path.join(__dirname, 'static')));
router.use('/static', express.static(path.join(__dirname, 'static')));
router.get('/', (req, res) => {
res.send(docsHtml);
});
Expand All @@ -35,4 +42,4 @@ module.exports = function setupDocsRoutes(router) {
router.get('/healthcheck(.html)?', (req, res) => {
res.send('page ok');
});
};
}
9 changes: 4 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const processPR = require('./processor');
const setupDocsRoutes = require('./docs');
import processPR from './processor.js';
import setupDocsRoutes from './docs.js';

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

appFn.setupDocsRoutes = setupDocsRoutes;
module.exports = appFn;
export { setupDocsRoutes };

0 comments on commit 1c83802

Please sign in to comment.