feat(esm): convert to esm (#2569)

for #2543

BREAKING CHANGE: semantic-release is now ESM-only. since it is used through its own executable, the impact on consuming projects should be minimal

BREAKING CHANGE: references to plugin files in configs need to include the file extension because of executing in an ESM context
This commit is contained in:
Matt Travi
2022-11-11 09:24:06 -06:00
committed by GitHub
parent 4012f75386
commit 9eab1adb9d
67 changed files with 3001 additions and 1761 deletions
+9 -9
View File
@@ -1,12 +1,12 @@
const {identity, isPlainObject, omit, castArray, isNil, isString} = require('lodash');
const AggregateError = require('aggregate-error');
const getError = require('../get-error');
const PLUGINS_DEFINITIONS = require('../definitions/plugins');
const {validatePlugin, validateStep, loadPlugin, parseConfig} = require('./utils');
const pipeline = require('./pipeline');
const normalize = require('./normalize');
import {castArray, identity, isNil, isPlainObject, isString, omit} from 'lodash-es';
import AggregateError from 'aggregate-error';
import getError from '../get-error.js';
import PLUGINS_DEFINITIONS from '../definitions/plugins.js';
import {loadPlugin, parseConfig, validatePlugin, validateStep} from './utils.js';
import pipeline from './pipeline.js';
import normalize from './normalize.js';
module.exports = async (context, pluginsPath) => {
export default async (context, pluginsPath) => {
let {options, logger} = context;
const errors = [];
@@ -100,4 +100,4 @@ module.exports = async (context, pluginsPath) => {
}
return pluginsConfig;
};
}
+10 -8
View File
@@ -1,11 +1,13 @@
const {isPlainObject, isFunction, noop, cloneDeep, omit} = require('lodash');
const debug = require('debug')('semantic-release:plugins');
const getError = require('../get-error');
const {extractErrors} = require('../utils');
const PLUGINS_DEFINITIONS = require('../definitions/plugins');
const {loadPlugin, parseConfig} = require('./utils');
import {cloneDeep, isFunction, isPlainObject, noop, omit} from 'lodash-es';
import debugPlugins from 'debug';
import getError from '../get-error.js';
import {extractErrors} from '../utils.js';
import PLUGINS_DEFINITIONS from '../definitions/plugins.js';
import {loadPlugin, parseConfig} from './utils.js';
module.exports = async (context, type, pluginOpt, pluginsPath) => {
const debug = debugPlugins('semantic-release:plugins');
export default async (context, type, pluginOpt, pluginsPath) => {
const {stdout, stderr, options, logger} = context;
if (!pluginOpt) {
return noop;
@@ -64,4 +66,4 @@ module.exports = async (context, type, pluginOpt, pluginsPath) => {
}
return validator;
};
}
+6 -6
View File
@@ -1,7 +1,7 @@
const {identity} = require('lodash');
const pReduce = require('p-reduce');
const AggregateError = require('aggregate-error');
const {extractErrors} = require('../utils');
import {identity} from 'lodash-es';
import pReduce from 'p-reduce';
import AggregateError from 'aggregate-error';
import {extractErrors} from '../utils.js';
/**
* A Function that execute a list of function sequencially. If at least one Function ins the pipeline throws an Error or rejects, the pipeline function rejects as well.
@@ -25,7 +25,7 @@ const {extractErrors} = require('../utils');
*
* @return {Pipeline} A Function that execute the `steps` sequencially
*/
module.exports = (steps, {settleAll = false, getNextInput = identity, transform = identity} = {}) => async (input) => {
export default (steps, {settleAll = false, getNextInput = identity, transform = identity} = {}) => async (input) => {
const results = [];
const errors = [];
await pReduce(
@@ -55,4 +55,4 @@ module.exports = (steps, {settleAll = false, getNextInput = identity, transform
}
return results;
};
}
+10 -9
View File
@@ -1,6 +1,9 @@
const {dirname} = require('path');
const {isString, isFunction, castArray, isArray, isPlainObject, isNil} = require('lodash');
const resolveFrom = require('resolve-from');
import {dirname} from 'node:path';
import {fileURLToPath} from 'node:url';
import {castArray, isArray, isFunction, isNil, isPlainObject, isString} from 'lodash-es';
import resolveFrom from 'resolve-from';
const __dirname = dirname(fileURLToPath(import.meta.url));
const validateSteps = (conf) => {
return conf.every((conf) => {
@@ -24,7 +27,7 @@ const validateSteps = (conf) => {
});
};
function validatePlugin(conf) {
export function validatePlugin(conf) {
return (
isString(conf) ||
(isArray(conf) &&
@@ -35,7 +38,7 @@ function validatePlugin(conf) {
);
}
function validateStep({required}, conf) {
export function validateStep({required}, conf) {
conf = castArray(conf).filter(Boolean);
if (required) {
return conf.length >= 1 && validateSteps(conf);
@@ -44,7 +47,7 @@ function validateStep({required}, conf) {
return conf.length === 0 || validateSteps(conf);
}
async function loadPlugin({cwd}, name, pluginsPath) {
export async function loadPlugin({cwd}, name, pluginsPath) {
const basePath = pluginsPath[name]
? dirname(resolveFrom.silent(__dirname, pluginsPath[name]) || resolveFrom(cwd, pluginsPath[name]))
: __dirname;
@@ -54,7 +57,7 @@ async function loadPlugin({cwd}, name, pluginsPath) {
return isFunction(name) ? name : (await import(resolveFrom.silent(basePath, name) || resolveFrom(cwd, name))).default;
}
function parseConfig(plugin) {
export function parseConfig(plugin) {
let path;
let config;
if (isArray(plugin)) {
@@ -67,5 +70,3 @@ function parseConfig(plugin) {
return [path, config || {}];
}
module.exports = {validatePlugin, validateStep, loadPlugin, parseConfig};