Skip to content

Commit

Permalink
Convert CommonJS to ES Modules
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Jul 17, 2021
1 parent 0568d3e commit 179708a
Show file tree
Hide file tree
Showing 49 changed files with 299 additions and 335 deletions.
8 changes: 4 additions & 4 deletions bin/release-it.js
@@ -1,9 +1,9 @@
#!/usr/bin/env node

const updater = require('update-notifier');
const parseArgs = require('yargs-parser');
const pkg = require('../package.json');
const release = require('../lib');
import updater from 'update-notifier';
import parseArgs from 'yargs-parser';
import pkg from '../package.json';
import release from '../lib/index.js';

const aliases = {
c: 'config',
Expand Down
8 changes: 4 additions & 4 deletions lib/cli.js
@@ -1,5 +1,5 @@
const pkg = require('../package.json');
const Log = require('./log');
import pkg from '../package.json';
import Log from './log';

const log = new Log();

Expand All @@ -22,6 +22,6 @@ const helpText = `Release It! v${pkg.version}
For more details, please see https://github.com/release-it/release-it`;

module.exports.version = () => log.log(`v${pkg.version}`);
export let version = () => log.log(`v${pkg.version}`);

module.exports.help = () => log.log(helpText);
export let help = () => log.log(helpText);
22 changes: 12 additions & 10 deletions lib/config.js
@@ -1,12 +1,14 @@
const { cosmiconfigSync } = require('cosmiconfig');
const parseJson = require('parse-json');
const parseToml = require('@iarna/toml/parse-string');
const yaml = require('yaml');
const _ = require('lodash');
const isCI = require('is-ci');
const debug = require('debug')('release-it:config');
const defaultConfig = require('../config/release-it.json');
const { getSystemInfo } = require('./util');
import { cosmiconfigSync } from 'cosmiconfig';
import parseJson from 'parse-json';
import parseToml from '@iarna/toml/parse-string';
import yaml from 'yaml';
import _ from 'lodash';
import isCI from 'is-ci';
import _debug from 'debug';
import defaultConfig from '../config/release-it.json';
import { getSystemInfo } from './util';

const debug = _debug('release-it:config');

const searchPlaces = [
'package.json',
Expand Down Expand Up @@ -128,4 +130,4 @@ class Config {
}
}

module.exports = Config;
export default Config;
8 changes: 4 additions & 4 deletions lib/deprecated.js
@@ -1,8 +1,8 @@
const Deprecated = require('deprecated-obj');
const deprecated = require('../config/deprecated.json');
const Log = require('./log');
import Deprecated from 'deprecated-obj';
import deprecated from '../config/deprecated.json';
import Log from './log';

module.exports = (config, log = new Log()) => {
export default (config, log = new Log()) => {
const deprecations = new Deprecated(deprecated, config);
const compliant = deprecations.getCompliant();
const violations = deprecations.getViolations();
Expand Down
10 changes: 5 additions & 5 deletions lib/index.js
@@ -1,8 +1,8 @@
const { version, help } = require('./cli');
const runTasks = require('./tasks');
const Plugin = require('./plugin/Plugin');
import { version, help } from './cli';
import runTasks from './tasks';
import Plugin from './plugin/Plugin';

module.exports = async options => {
export default async options => {
if (options.version) {
version();
} else if (options.help) {
Expand All @@ -13,4 +13,4 @@ module.exports = async options => {
return Promise.resolve();
};

module.exports.Plugin = Plugin;
export { Plugin };
8 changes: 4 additions & 4 deletions lib/log.js
@@ -1,6 +1,6 @@
const { EOL } = require('os');
const chalk = require('chalk');
const { isObject, last, filter, isString, lowerCase, upperFirst, isArray } = require('lodash');
import { EOL } from 'os';
import chalk from 'chalk';
import { isObject, last, filter, isString, lowerCase, upperFirst, isArray } from 'lodash';

class Logger {
constructor({ isCI = true, isVerbose = false, verbosityLevel = 0, isDryRun = false } = {}) {
Expand Down Expand Up @@ -64,4 +64,4 @@ class Logger {
}
}

module.exports = Logger;
export default Logger;
18 changes: 10 additions & 8 deletions lib/metrics.js
@@ -1,10 +1,12 @@
const { EOL } = require('os');
const got = require('got');
const { v4: uuidv4 } = require('uuid');
const osName = require('os-name');
const isCi = require('is-ci');
const debug = require('debug')('release-it:metrics');
const pkg = require('../package.json');
import { EOL } from 'os';
import got from 'got';
import { v4 as uuidv4 } from 'uuid';
import osName from 'os-name';
import isCi from 'is-ci';
import _debug from 'debug';
import pkg from '../package.json';

const debug = _debug('release-it:metrics');

const noop = Promise.resolve();

Expand Down Expand Up @@ -70,4 +72,4 @@ class Metrics {
}
}

module.exports = Metrics;
export default Metrics;
8 changes: 4 additions & 4 deletions lib/plugin/GitBase.js
@@ -1,6 +1,6 @@
const { EOL } = require('os');
const { format, parseGitUrl } = require('../util');
const Plugin = require('./Plugin');
import { EOL } from 'os';
import { format, parseGitUrl } from '../util';
import Plugin from './Plugin';

const options = { write: false };
const changelogFallback = 'git log --pretty=format:"* %s (%h)"';
Expand Down Expand Up @@ -102,4 +102,4 @@ class GitBase extends Plugin {
}
}

module.exports = GitBase;
export default GitBase;
8 changes: 4 additions & 4 deletions lib/plugin/GitRelease.js
@@ -1,6 +1,6 @@
const _ = require('lodash');
const defaultConfig = require('../../config/release-it.json');
const GitBase = require('./GitBase');
import _ from 'lodash';
import defaultConfig from '../../config/release-it.json';
import GitBase from './GitBase';

class GitRelease extends GitBase {
static isEnabled(options) {
Expand Down Expand Up @@ -37,4 +37,4 @@ class GitRelease extends GitBase {
}
}

module.exports = GitRelease;
export default GitRelease;
6 changes: 3 additions & 3 deletions lib/plugin/Plugin.js
@@ -1,5 +1,5 @@
const debug = require('debug');
const _ = require('lodash');
import debug from 'debug';
import _ from 'lodash';

class Plugin {
static isEnabled() {
Expand Down Expand Up @@ -69,4 +69,4 @@ class Plugin {
}
}

module.exports = Plugin;
export default Plugin;
22 changes: 12 additions & 10 deletions lib/plugin/factory.js
@@ -1,12 +1,14 @@
const path = require('path');
const _ = require('lodash');
const requireCwd = require('import-cwd');
const debug = require('debug')('release-it:plugins');
const Version = require('./version/Version');
const Git = require('./git/Git');
const GitLab = require('./gitlab/GitLab');
const GitHub = require('./github/GitHub');
const npm = require('./npm/npm');
import path from 'path';
import _ from 'lodash';
import requireCwd from 'import-cwd';
import _debug from 'debug';
import Version from './version/Version';
import Git from './git/Git';
import GitLab from './gitlab/GitLab';
import GitHub from './github/GitHub';
import npm from './npm/npm';

const debug = _debug('release-it:plugins');

const pluginNames = ['npm', 'git', 'github', 'gitlab', 'version'];

Expand All @@ -28,7 +30,7 @@ const load = pluginName => {
return [path.parse(pluginName).name, plugin];
};

module.exports.getPlugins = async (config, container) => {
export let getPlugins = async (config, container) => {
const context = config.getContext();
const disabledPlugins = [];

Expand Down
14 changes: 7 additions & 7 deletions lib/plugin/git/Git.js
@@ -1,9 +1,9 @@
const { EOL } = require('os');
const _ = require('lodash');
const findUp = require('find-up');
const { format, e } = require('../../util');
const GitBase = require('../GitBase');
const prompts = require('./prompts');
import { EOL } from 'os';
import _ from 'lodash';
import findUp from 'find-up';
import { format, e } from '../../util';
import GitBase from '../GitBase';
import prompts from './prompts';

const noop = Promise.resolve();
const invalidPushRepoRe = /^\S+@/;
Expand Down Expand Up @@ -201,4 +201,4 @@ class Git extends GitBase {
}
}

module.exports = Git;
export default Git;
4 changes: 2 additions & 2 deletions lib/plugin/git/prompts.js
@@ -1,6 +1,6 @@
const { format, truncateLines } = require('../../util');
import { format, truncateLines } from '../../util';

module.exports = {
export default {
commit: {
type: 'confirm',
message: context => `Commit (${truncateLines(format(context.git.commitMessage, context), 1, ' [...]')})?`,
Expand Down
24 changes: 12 additions & 12 deletions lib/plugin/github/GitHub.js
@@ -1,14 +1,14 @@
const fs = require('fs');
const path = require('path');
const { Octokit } = require('@octokit/rest');
const globby = require('globby');
const mime = require('mime-types');
const _ = require('lodash');
const retry = require('async-retry');
const pkg = require('../../../package.json');
const { format, parseVersion, e } = require('../../util');
const Release = require('../GitRelease');
const prompts = require('./prompts');
import fs from 'fs';
import path from 'path';
import { Octokit } from '@octokit/rest';
import globby from 'globby';
import mime from 'mime-types';
import _ from 'lodash';
import retry from 'async-retry';
import pkg from '../../../package.json';
import { format, parseVersion, e } from '../../util';
import Release from '../GitRelease';
import prompts from './prompts';

const docs = 'https://git.io/release-it-github';

Expand Down Expand Up @@ -308,4 +308,4 @@ class GitHub extends Release {
}
}

module.exports = GitHub;
export default GitHub;
4 changes: 2 additions & 2 deletions lib/plugin/github/prompts.js
@@ -1,4 +1,4 @@
const { format } = require('../../util');
import { format } from '../../util';

const message = context => {
const { isPreRelease, isUpdate, github } = context;
Expand All @@ -7,7 +7,7 @@ const message = context => {
return `${isUpdate ? 'Update' : 'Create a'} ${isPreRelease ? 'pre-' : ''}release on GitHub (${name})?`;
};

module.exports = {
export default {
release: {
type: 'confirm',
message,
Expand Down
20 changes: 10 additions & 10 deletions lib/plugin/gitlab/GitLab.js
@@ -1,12 +1,12 @@
const fs = require('fs');
const path = require('path');
const got = require('got');
const globby = require('globby');
const FormData = require('form-data');
const _ = require('lodash');
const Release = require('../GitRelease');
const { format, e } = require('../../util');
const prompts = require('./prompts');
import fs from 'fs';
import path from 'path';
import got from 'got';
import globby from 'globby';
import FormData from 'form-data';
import _ from 'lodash';
import Release from '../GitRelease';
import { format, e } from '../../util';
import prompts from './prompts';

const docs = 'https://git.io/release-it-gitlab';

Expand Down Expand Up @@ -215,4 +215,4 @@ class GitLab extends Release {
}
}

module.exports = GitLab;
export default GitLab;
4 changes: 2 additions & 2 deletions lib/plugin/gitlab/prompts.js
@@ -1,6 +1,6 @@
const { format } = require('../../util');
import { format } from '../../util';

module.exports = {
export default {
release: {
type: 'confirm',
message: context => `Create a release on GitLab (${format(context.gitlab.releaseName, context)})?`,
Expand Down
14 changes: 7 additions & 7 deletions lib/plugin/npm/npm.js
@@ -1,9 +1,9 @@
const path = require('path');
const semver = require('semver');
const urlJoin = require('url-join');
const Plugin = require('../Plugin');
const { hasAccess, rejectAfter, parseVersion, e } = require('../../util');
const prompts = require('./prompts');
import path from 'path';
import semver from 'semver';
import urlJoin from 'url-join';
import Plugin from '../Plugin';
import { hasAccess, rejectAfter, parseVersion, e } from '../../util';
import prompts from './prompts';

const docs = 'https://git.io/release-it-npm';

Expand Down Expand Up @@ -255,4 +255,4 @@ class npm extends Plugin {
}
}

module.exports = npm;
export default npm;
2 changes: 1 addition & 1 deletion lib/plugin/npm/prompts.js
@@ -1,4 +1,4 @@
module.exports = {
export default {
publish: {
type: 'confirm',
message: context =>
Expand Down
8 changes: 4 additions & 4 deletions lib/plugin/version/Version.js
@@ -1,6 +1,6 @@
const semver = require('semver');
const chalk = require('chalk');
const Plugin = require('../Plugin');
import semver from 'semver';
import chalk from 'chalk';
import Plugin from '../Plugin';

const { green, red, redBright } = chalk;

Expand Down Expand Up @@ -126,4 +126,4 @@ class Version extends Plugin {
}
}

module.exports = Version;
export default Version;
4 changes: 2 additions & 2 deletions lib/prompt.js
@@ -1,4 +1,4 @@
const inquirer = require('inquirer');
import inquirer from 'inquirer';

class Prompt {
constructor({ container }) {
Expand Down Expand Up @@ -30,4 +30,4 @@ class Prompt {
}
}

module.exports = Prompt;
export default Prompt;

0 comments on commit 179708a

Please sign in to comment.