Skip to content

Commit

Permalink
chore: use es6 modules syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
mjeanroy committed Apr 5, 2020
1 parent 64c4960 commit 2da0917
Show file tree
Hide file tree
Showing 33 changed files with 166 additions and 166 deletions.
10 changes: 9 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{
"presets": [
"@babel/preset-env"
[
"@babel/preset-env", {
"modules": "cjs"
}
]
],

"plugins": [
"add-module-exports"
]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@babel/core": "7.9.0",
"@babel/preset-env": "7.9.0",
"@babel/register": "7.9.0",
"babel-plugin-add-module-exports": "^1.0.2",
"eslint": "6.8.0",
"eslint-config-google": "0.14.0",
"fancy-log": "1.3.3",
Expand Down
2 changes: 0 additions & 2 deletions scripts/log/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
* THE SOFTWARE.
*/

'use strict';

const log = require('fancy-log');
const colors = require('ansi-colors');

Expand Down
5 changes: 5 additions & 0 deletions src/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"parserOptions": {
"sourceType": "module"
}
}
12 changes: 5 additions & 7 deletions src/dependency.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@
* SOFTWARE.
*/

'use strict';

const _ = require('lodash');
const EOL = require('./eol.js');
const Person = require('./person.js');
import _ from 'lodash';
import {EOL} from './eol.js';
import {Person} from './person.js';

/**
* Dependency structure.
*/
module.exports = class Dependency {
export class Dependency {
/**
* Create new dependency from package description.
*
Expand Down Expand Up @@ -118,4 +116,4 @@ module.exports = class Dependency {

return lines.join(EOL);
}
};
}
4 changes: 1 addition & 3 deletions src/eol.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,4 @@
* SOFTWARE.
*/

'use strict';

module.exports = '\n';
export const EOL = '\n';
8 changes: 2 additions & 6 deletions src/format-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@
* SOFTWARE.
*/

'use strict';

const _ = require('lodash');
import _ from 'lodash';

/**
* Format given array of path to a human readable path.
*
* @param {Array<string|number>} paths List of paths.
* @return {string} The full path.
*/
function formatPath(paths) {
export function formatPath(paths) {
let str = '';

_.forEach(paths, (p) => {
Expand All @@ -47,5 +45,3 @@ function formatPath(paths) {

return str;
}

module.exports = formatPath;
8 changes: 3 additions & 5 deletions src/generate-block-comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
* SOFTWARE.
*/

'use strict';

const commenting = require('commenting');
import commenting from 'commenting';

/**
* Generate block comment from given text content.
Expand All @@ -33,7 +31,7 @@ const commenting = require('commenting');
* @param {Object} commentStyle The comment style setting.
* @return {string} Block comment.
*/
module.exports = function generateBlockComment(text, commentStyle) {
export function generateBlockComment(text, commentStyle) {
const options = {
extension: '.js',
};
Expand All @@ -47,4 +45,4 @@ module.exports = function generateBlockComment(text, commentStyle) {
}

return commenting(text.trim(), options);
};
}
16 changes: 10 additions & 6 deletions src/index-rollup-legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@
* SOFTWARE.
*/

'use strict';
import _ from 'lodash';
import {licensePlugin} from './license-plugin.js';

const _ = require('lodash');
const licensePlugin = require('./license-plugin.js');

module.exports = (options = {}) => {
/**
* Create rollup plugin compatible with rollup < 1.0.0
*
* @param {Object} options Plugin options.
* @return {Object} Plugin instance.
*/
export function licensePluginLegacy(options = {}) {
const plugin = licensePlugin(options);

return {
Expand Down Expand Up @@ -96,4 +100,4 @@ module.exports = (options = {}) => {
plugin.scanThirdParties();
},
};
};
}
16 changes: 10 additions & 6 deletions src/index-rollup-stable.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@
* SOFTWARE.
*/

'use strict';
import _ from 'lodash';
import {licensePlugin} from './license-plugin.js';

const _ = require('lodash');
const licensePlugin = require('./license-plugin.js');

module.exports = (options = {}) => {
/**
* Create rollup plugin compatible with rollup >= 1.0.0
*
* @param {Object} options Plugin options.
* @return {Object} Plugin instance.
*/
export function licensePluginStable(options = {}) {
const plugin = licensePlugin(options);

return {
Expand Down Expand Up @@ -70,4 +74,4 @@ module.exports = (options = {}) => {
plugin.scanThirdParties();
},
};
};
}
9 changes: 6 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
* SOFTWARE.
*/

'use strict';

const rollup = require('rollup');
import * as rollup from 'rollup';
import {licensePluginLegacy} from './index-rollup-legacy';
import {licensePluginStable} from './index-rollup-stable';

const VERSION = rollup.VERSION;
const MAJOR_VERSION = VERSION ? Number(VERSION.split('.')[0]) : 0;
const IS_ROLLUP_LEGACY = MAJOR_VERSION === 0;
const plugin = IS_ROLLUP_LEGACY ? licensePluginLegacy : licensePluginStable;

module.exports = IS_ROLLUP_LEGACY ? require('./index-rollup-legacy') : require('./index-rollup-stable');
export default plugin;
4 changes: 1 addition & 3 deletions src/license-plugin-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
* SOFTWARE.
*/

'use strict';

/**
* The plugin name.
* @type {string}
*/
module.exports = 'rollup-plugin-license';
export const PLUGIN_NAME = 'rollup-plugin-license';
16 changes: 7 additions & 9 deletions src/license-plugin-option.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
* SOFTWARE.
*/

'use strict';

const _ = require('lodash');
const PLUGIN_NAME = require('./license-plugin-name.js');
const validators = require('./schema-validators.js');
const validateSchema = require('./schema-validator.js');
const formatPath = require('./format-path.js');
import _ from 'lodash';
import {PLUGIN_NAME} from './license-plugin-name.js';
import {validators} from './schema-validators.js';
import {validateSchema} from './schema-validator.js';
import {formatPath} from './format-path.js';

/**
* The option object schema.
Expand Down Expand Up @@ -299,10 +297,10 @@ function validateOptions(options) {
* @param {Object} options Option object to validate.
* @return {Object} New normalized options.
*/
module.exports = function licensePluginOption(options) {
export function licensePluginOptions(options) {
const normalizedOptions = normalizeOptions(options);

validateOptions(normalizedOptions);

return normalizedOptions;
};
}
34 changes: 16 additions & 18 deletions src/license-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,20 @@
* SOFTWARE.
*/

'use strict';

const fs = require('fs');
const path = require('path');
const mkdirp = require('mkdirp');
const _ = require('lodash');
const moment = require('moment');
const MagicString = require('magic-string');
const glob = require('glob');

const Dependency = require('./dependency.js');
const generateBlockComment = require('./generate-block-comment.js');
const licensePluginOptions = require('./license-plugin-option.js');
const licenseValidator = require('./license-validator');
const PLUGIN_NAME = require('./license-plugin-name.js');
const EOL = require('./eol.js');
import fs from 'fs';
import path from 'path';
import mkdirp from 'mkdirp';
import _ from 'lodash';
import moment from 'moment';
import MagicString from 'magic-string';
import glob from 'glob';

import {Dependency} from './dependency.js';
import {generateBlockComment} from './generate-block-comment.js';
import {licensePluginOptions} from './license-plugin-option.js';
import {licenseValidator} from './license-validator';
import {PLUGIN_NAME} from './license-plugin-name.js';
import {EOL} from './eol.js';

/**
* Pre-Defined comment style:
Expand Down Expand Up @@ -544,8 +542,8 @@ class LicensePlugin {
* @param {Object} options Option object.
* @return {LicensePlugin} The new instance.
*/
module.exports = function licensePlugin(options) {
export function licensePlugin(options) {
return new LicensePlugin(
licensePluginOptions(options)
);
};
}
6 changes: 3 additions & 3 deletions src/license-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
* SOFTWARE.
*/

const spdxExpressionValidate = require('spdx-expression-validate');
const spdxSatisfies = require('spdx-satisfies');
import spdxExpressionValidate from 'spdx-expression-validate';
import spdxSatisfies from 'spdx-satisfies';

/**
* Normalize license name:
Expand Down Expand Up @@ -78,7 +78,7 @@ function isValid(dependency, allow) {
return spdxExpressionValidate(license) && spdxSatisfies(license, allow);
}

module.exports = {
export const licenseValidator = {
isUnlicensed,
isValid,
};
8 changes: 3 additions & 5 deletions src/person.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@
* SOFTWARE.
*/

'use strict';

const _ = require('lodash');
import _ from 'lodash';

/**
* Person, defined by:
* - A name.
* - An email (optional).
* - An URL (optional).
*/
module.exports = class Person {
export class Person {
/**
* Create the person.
*
Expand Down Expand Up @@ -94,4 +92,4 @@ module.exports = class Person {

return text;
}
};
}
18 changes: 13 additions & 5 deletions src/schema-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
* SOFTWARE.
*/

'use strict';

const _ = require('lodash');
const formatPath = require('./format-path.js');
import _ from 'lodash';
import {formatPath} from './format-path.js';

/**
* Validate value against given schema.
Expand Down Expand Up @@ -147,4 +145,14 @@ function validate(obj, schema, current = []) {
return _.isArray(obj) ? validateArray(obj, schema, current) : validateObject(obj, schema, current);
}

module.exports = validate;
/**
* Validate given object against given schema.
*
* @param {Object} obj Object to validate.
* @param {Object} schema The schema against the given object will be validated.
* @param {Array<string>} current The current path context of given object, useful to validate against subobject.
* @return {Array<Object>} Found errors.
*/
export function validateSchema(obj, schema, current) {
return validate(obj, schema, current);
}
6 changes: 2 additions & 4 deletions src/schema-validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
* SOFTWARE.
*/

'use strict';

const _ = require('lodash');
import _ from 'lodash';

/**
* Check if given value is a `string`.
Expand Down Expand Up @@ -96,7 +94,7 @@ function isObject(value) {
return _.isObject(value) && !isArray(value) && !isFunction(value) && !isNil(value) && !isString(value) && !isNumber(value);
}

module.exports = {
export const validators = {
string() {
return {
type: 'object.type.string',
Expand Down
3 changes: 3 additions & 0 deletions test/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"parserOptions": {
"sourceType": "module"
},
"env": {
"jasmine": true
},
Expand Down
Loading

0 comments on commit 2da0917

Please sign in to comment.