Skip to content

Commit

Permalink
wip(esm): initial module type conversion
Browse files Browse the repository at this point in the history
for #2543
  • Loading branch information
travi committed Aug 27, 2022
1 parent 2a2db0c commit 21a7b60
Show file tree
Hide file tree
Showing 64 changed files with 574 additions and 567 deletions.
47 changes: 25 additions & 22 deletions index.js
@@ -1,24 +1,27 @@
const {pick} = require('lodash');
const marked = require('marked');
const envCi = require('env-ci');
const hookStd = require('hook-std');
const semver = require('semver');
const AggregateError = require('aggregate-error');
import {createRequire} from 'node:module';
import {pick} from 'lodash-es';
import * as marked from 'marked';
import envCi from 'env-ci';
import hookStd from 'hook-std';
import semver from 'semver';
import AggregateError from 'aggregate-error';
import hideSensitive from './lib/hide-sensitive.js';
import getConfig from './lib/get-config.js';
import verify from './lib/verify.js';
import getNextVersion from './lib/get-next-version.js';
import getCommits from './lib/get-commits.js';
import getLastRelease from './lib/get-last-release.js';
import getReleaseToAdd from './lib/get-release-to-add.js';
import {extractErrors, makeTag} from './lib/utils.js';
import getGitAuthUrl from './lib/get-git-auth-url.js';
import getBranches from './lib/branches/index.js';
import getLogger from './lib/get-logger.js';
import {addNote, getGitHead, getTagHead, isBranchUpToDate, push, pushNotes, tag, verifyAuth} from './lib/git.js';
import getError from './lib/get-error.js';
import {COMMIT_EMAIL, COMMIT_NAME} from './lib/definitions/constants.js';

const require = createRequire(import.meta.url);
const pkg = require('./package.json');
const hideSensitive = require('./lib/hide-sensitive');
const getConfig = require('./lib/get-config');
const verify = require('./lib/verify');
const getNextVersion = require('./lib/get-next-version');
const getCommits = require('./lib/get-commits');
const getLastRelease = require('./lib/get-last-release');
const getReleaseToAdd = require('./lib/get-release-to-add');
const {extractErrors, makeTag} = require('./lib/utils');
const getGitAuthUrl = require('./lib/get-git-auth-url');
const getBranches = require('./lib/branches');
const getLogger = require('./lib/get-logger');
const {verifyAuth, isBranchUpToDate, getGitHead, tag, push, pushNotes, getTagHead, addNote} = require('./lib/git');
const getError = require('./lib/get-error');
const {COMMIT_NAME, COMMIT_EMAIL} = require('./lib/definitions/constants');

let markedOptionsSet = false;
async function terminalOutput(text) {
Expand Down Expand Up @@ -247,7 +250,7 @@ async function callFail(context, plugins, err) {
}
}

module.exports = async (cliOptions = {}, {cwd = process.cwd(), env = process.env, stdout, stderr} = {}) => {
export default async (cliOptions = {}, {cwd = process.cwd(), env = process.env, stdout, stderr} = {}) => {
const {unhook} = hookStd(
{silent: false, streams: [process.stdout, process.stderr, stdout, stderr].filter(Boolean)},
hideSensitive(env)
Expand Down Expand Up @@ -278,4 +281,4 @@ module.exports = async (cliOptions = {}, {cwd = process.cwd(), env = process.env
unhook();
throw error;
}
};
}
10 changes: 5 additions & 5 deletions lib/branches/expand.js
@@ -1,8 +1,8 @@
const {isString, remove, omit, mapValues, template} = require('lodash');
const micromatch = require('micromatch');
const {getBranches} = require('../git');
import {isString, mapValues, omit, remove, template} from 'lodash-es';
import micromatch from 'micromatch';
import {getBranches} from '../git.js';

module.exports = async (repositoryUrl, {cwd}, branches) => {
export default async (repositoryUrl, {cwd}, branches) => {
const gitBranches = await getBranches(repositoryUrl, {cwd});

return branches.reduce(
Expand All @@ -15,4 +15,4 @@ module.exports = async (repositoryUrl, {cwd}, branches) => {
],
[]
);
};
}
17 changes: 10 additions & 7 deletions lib/branches/get-tags.js
@@ -1,10 +1,13 @@
const {template, escapeRegExp} = require('lodash');
const semver = require('semver');
const pReduce = require('p-reduce');
const debug = require('debug')('semantic-release:get-tags');
const {getTags, getNote} = require('../../lib/git');
import {escapeRegExp, template} from 'lodash-es';
import semver from 'semver';
import pReduce from 'p-reduce';
import debugTags from 'debug';
import {getNote, getTags} from '../../lib/git.js';

module.exports = async ({cwd, env, options: {tagFormat}}, branches) => {
const debug = debugTags('semantic-release:get-tags');


export default async ({cwd, env, options: {tagFormat}}, branches) => {
// Generate a regex to parse tags formatted with `tagFormat`
// by replacing the `version` variable in the template by `(.+)`.
// The `tagFormat` is compiled with space as the `version` as it's an invalid tag character,
Expand All @@ -30,4 +33,4 @@ module.exports = async ({cwd, env, options: {tagFormat}}, branches) => {
},
[]
);
};
}
22 changes: 11 additions & 11 deletions lib/branches/index.js
@@ -1,14 +1,14 @@
const {isString, isRegExp} = require('lodash');
const AggregateError = require('aggregate-error');
const pEachSeries = require('p-each-series');
const DEFINITIONS = require('../definitions/branches');
const getError = require('../get-error');
const {fetch, fetchNotes, verifyBranchName} = require('../git');
const expand = require('./expand');
const getTags = require('./get-tags');
const normalize = require('./normalize');
import {isRegExp, isString} from 'lodash-es';
import AggregateError from 'aggregate-error';
import pEachSeries from 'p-each-series';
import * as DEFINITIONS from '../definitions/branches.js';
import getError from '../get-error.js';
import {fetch, fetchNotes, verifyBranchName} from '../git.js';
import expand from './expand.js';
import getTags from './get-tags.js';
import * as normalize from './normalize.js';

module.exports = async (repositoryUrl, ciBranch, context) => {
export default async (repositoryUrl, ciBranch, context) => {
const {cwd, env} = context;

const remoteBranches = await expand(
Expand Down Expand Up @@ -68,4 +68,4 @@ module.exports = async (repositoryUrl, ciBranch, context) => {
}

return [...result.maintenance, ...result.release, ...result.prerelease];
};
}
29 changes: 13 additions & 16 deletions lib/branches/normalize.js
@@ -1,19 +1,18 @@
const {sortBy, isNil} = require('lodash');
const semverDiff = require('semver-diff');
const {FIRST_RELEASE, RELEASE_TYPE} = require('../definitions/constants');
const {
tagsToVersions,
isMajorRange,
import {isNil, sortBy} from 'lodash-es';
import semverDiff from 'semver-diff';
import {FIRST_RELEASE, RELEASE_TYPE} from '../definitions/constants.js';
import {
getFirstVersion,
getLatestVersion,
getLowerBound, getRange,
getUpperBound,
getLowerBound,
highest,
isMajorRange,
lowest,
getLatestVersion,
getFirstVersion,
getRange,
} = require('../utils');
tagsToVersions
} from '../utils.js';

function maintenance({maintenance, release}) {
export function maintenance({maintenance, release}) {
return sortBy(
maintenance.map(({name, range, channel, ...rest}) => ({
...rest,
Expand Down Expand Up @@ -55,7 +54,7 @@ function maintenance({maintenance, release}) {
});
}

function release({release}) {
export function release({release}) {
if (release.length === 0) {
return release;
}
Expand Down Expand Up @@ -89,7 +88,7 @@ function release({release}) {
});
}

function prerelease({prerelease}) {
export function prerelease({prerelease}) {
return prerelease.map(({name, prerelease, channel, tags, ...rest}) => {
const preid = prerelease === true ? name : prerelease;
return {
Expand All @@ -102,5 +101,3 @@ function prerelease({prerelease}) {
};
});
}

module.exports = {maintenance, release, prerelease};
14 changes: 6 additions & 8 deletions lib/definitions/branches.js
@@ -1,24 +1,22 @@
const {isNil, uniqBy} = require('lodash');
const semver = require('semver');
const {isMaintenanceRange} = require('../utils');
import {isNil, uniqBy} from 'lodash-es';
import semver from 'semver';
import {isMaintenanceRange} from '../utils.js';

const maintenance = {
export const maintenance = {
filter: ({name, range}) => (!isNil(range) && range !== false) || isMaintenanceRange(name),
branchValidator: ({range}) => (isNil(range) ? true : isMaintenanceRange(range)),
branchesValidator: (branches) => uniqBy(branches, ({range}) => semver.validRange(range)).length === branches.length,
};

const prerelease = {
export const prerelease = {
filter: ({prerelease}) => !isNil(prerelease) && prerelease !== false,
branchValidator: ({name, prerelease}) =>
Boolean(prerelease) && Boolean(semver.valid(`1.0.0-${prerelease === true ? name : prerelease}.1`)),
branchesValidator: (branches) => uniqBy(branches, 'prerelease').length === branches.length,
};

const release = {
export const release = {
// eslint-disable-next-line unicorn/no-fn-reference-in-iterator
filter: (branch) => !maintenance.filter(branch) && !prerelease.filter(branch),
branchesValidator: (branches) => branches.length <= 3 && branches.length > 0,
};

module.exports = {maintenance, prerelease, release};
30 changes: 9 additions & 21 deletions lib/definitions/constants.js
@@ -1,29 +1,17 @@
const RELEASE_TYPE = ['patch', 'minor', 'major'];
export const RELEASE_TYPE = ['patch', 'minor', 'major'];

const FIRST_RELEASE = '1.0.0';
export const FIRST_RELEASE = '1.0.0';

const FIRSTPRERELEASE = '1';
export const FIRSTPRERELEASE = '1';

const COMMIT_NAME = 'semantic-release-bot';
export const COMMIT_NAME = 'semantic-release-bot';

const COMMIT_EMAIL = 'semantic-release-bot@martynus.net';
export const COMMIT_EMAIL = 'semantic-release-bot@martynus.net';

const RELEASE_NOTES_SEPARATOR = '\n\n';
export const RELEASE_NOTES_SEPARATOR = '\n\n';

const SECRET_REPLACEMENT = '[secure]';
export const SECRET_REPLACEMENT = '[secure]';

const SECRET_MIN_SIZE = 5;
export const SECRET_MIN_SIZE = 5;

const GIT_NOTE_REF = 'semantic-release';

module.exports = {
RELEASE_TYPE,
FIRST_RELEASE,
FIRSTPRERELEASE,
COMMIT_NAME,
COMMIT_EMAIL,
RELEASE_NOTES_SEPARATOR,
SECRET_REPLACEMENT,
SECRET_MIN_SIZE,
GIT_NOTE_REF,
};
export const GIT_NOTE_REF = 'semantic-release';

0 comments on commit 21a7b60

Please sign in to comment.