Skip to content

Commit

Permalink
refactor: move to ESM
Browse files Browse the repository at this point in the history
BREAKING CHANGE: require Node.js v12
  • Loading branch information
antongolub committed Mar 5, 2022
1 parent 795aa24 commit 99fffa9
Show file tree
Hide file tree
Showing 35 changed files with 192 additions and 177 deletions.
7 changes: 4 additions & 3 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env node

const meow = require("meow");
const { toPairs, set } = require("lodash");
const runner = require("./runner");
import meow from "meow";
import { toPairs, set } from "lodash-es";
import runner from "./runner.js";

const cli = meow(
`
Usage
Expand Down
10 changes: 7 additions & 3 deletions bin/runner.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
module.exports = (flags) => {
import {createRequire} from "module";

export default async (flags) => {
const require = createRequire(import.meta.url);

if (flags.debug) {
require("debug").enable("msr:*");
}

// Imports.
const getPackagePaths = require("../lib/getPackagePaths");
const multiSemanticRelease = require("../lib/multiSemanticRelease");
const getPackagePaths = (await import("../lib/getPackagePaths.js")).default;
const multiSemanticRelease = (await import("../lib/multiSemanticRelease.js")).default;
const multisemrelPkgJson = require("../package.json");
const semrelPkgJson = require("semantic-release/package.json");

Expand Down
6 changes: 3 additions & 3 deletions lib/RescopedStream.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { Writable } = require("stream");
const { check } = require("./blork");
import { Writable } from "stream";
import { check } from "./blork.js";

/**
* Create a stream that passes messages through while rewriting scope.
Expand Down Expand Up @@ -29,4 +29,4 @@ class RescopedStream extends Writable {
}

// Exports.
module.exports = RescopedStream;
export default RescopedStream;
10 changes: 5 additions & 5 deletions lib/blork.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { existsSync, lstatSync } = require("fs");
const { checker, check, add, ValueError } = require("blork");
const { Writable } = require("stream");
const { WritableStreamBuffer } = require("stream-buffers");
import { existsSync, lstatSync } from "fs";
import { checker, check, add, ValueError } from "blork";
import { Writable } from "stream";
import { WritableStreamBuffer } from "stream-buffers";

// Get some checkers.
const isAbsolute = checker("absolute");
Expand All @@ -22,4 +22,4 @@ add(
);

// Exports.
module.exports = { checker, check, ValueError };
export { checker, check, ValueError };
6 changes: 3 additions & 3 deletions lib/cleanPath.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { normalize, isAbsolute, join } = require("path");
const { check } = require("./blork");
import { normalize, isAbsolute, join } from "path";
import { check } from "./blork.js";

/**
* Normalize and make a path absolute, optionally using a custom CWD.
Expand All @@ -21,4 +21,4 @@ function cleanPath(path, cwd = process.cwd()) {
}

// Exports.
module.exports = cleanPath;
export default cleanPath;
18 changes: 9 additions & 9 deletions lib/createInlinePluginCreator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const debug = require("debug")("msr:inlinePlugin");
const getCommitsFiltered = require("./getCommitsFiltered");
const { updateManifestDeps, resolveReleaseType } = require("./updateDeps");
import dbg from "debug";
import getCommitsFiltered from "./getCommitsFiltered.js";
import { updateManifestDeps, resolveReleaseType } from "./updateDeps.js";

const debug = dbg("msr:inlinePlugin");

/**
* Create an inline plugin creator for a multirelease.
Expand Down Expand Up @@ -212,13 +214,11 @@ function createInlinePluginCreator(packages, multiContext, synchronizer, flags)
};

const publish = async (pluginOptions, context) => {
const resPromise = plugins.publish(context);
next();

const res = await resPromise;
const res = await plugins.publish(context);
pkg._published = true;

debug(debugPrefix, "published");

next();
await waitForAll("_published", (p) => p._nextType);

// istanbul ignore next
Expand Down Expand Up @@ -252,4 +252,4 @@ function createInlinePluginCreator(packages, multiContext, synchronizer, flags)
}

// Exports.
module.exports = createInlinePluginCreator;
export default createInlinePluginCreator;
18 changes: 10 additions & 8 deletions lib/getCommitsFiltered.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const { relative, resolve } = require("path");
const gitLogParser = require("git-log-parser");
const execa = require("execa");
const { check, ValueError } = require("./blork");
const getStream = require("get-stream");
const cleanPath = require("./cleanPath");
const debug = require("debug")("msr:commitsFilter");
import { relative, resolve } from "path";
import gitLogParser from "git-log-parser";
import getStream from "get-stream";
import execa from "execa";
import { check, ValueError } from "./blork.js";
import cleanPath from "./cleanPath.js";
import dbg from "debug";

const debug = dbg("msr:commitsFilter");

/**
* Retrieve the list of commits on the current branch since the commit sha associated with the last release, or all the commits of the current branch if there is no last released version.
Expand Down Expand Up @@ -63,4 +65,4 @@ async function getCommitsFiltered(cwd, dir, lastHead = undefined, firstParentBra
}

// Exports.
module.exports = getCommitsFiltered;
export default getCommitsFiltered;
4 changes: 2 additions & 2 deletions lib/getConfig.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { cosmiconfig } = require("cosmiconfig");
import { cosmiconfig } from "cosmiconfig";

// Copied from get-config.js in semantic-release
const CONFIG_NAME = "release";
Expand All @@ -22,7 +22,7 @@ const CONFIG_FILES = [
*
* @internal
*/
module.exports = async function getConfig(cwd) {
export default async function getConfig(cwd) {
// Call cosmiconfig.
const config = await cosmiconfig(CONFIG_NAME, { searchPlaces: CONFIG_FILES }).search(cwd);

Expand Down
10 changes: 6 additions & 4 deletions lib/getConfigSemantic.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const semanticGetConfig = require("semantic-release/lib/get-config");
const { WritableStreamBuffer } = require("stream-buffers");
const { Signale } = require("signale");
import semanticGetConfig from "semantic-release/lib/get-config.js";
import { WritableStreamBuffer } from "stream-buffers";
import signale from "signale";

const { Signale } = signale;

/**
* Get the release configuration options for a given directory.
Expand Down Expand Up @@ -29,4 +31,4 @@ async function getConfigSemantic({ cwd, env, stdout, stderr, logger }, options)
}

// Exports.
module.exports = getConfigSemantic;
export default getConfigSemantic;
5 changes: 3 additions & 2 deletions lib/getLogger.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { Signale } = require("signale");
import signale from "signale";
const { Signale } = signale;

/**
* Return a new Signale instance.
Expand All @@ -25,4 +26,4 @@ function getLogger({ stdout, stderr }) {
}

// Exports.
module.exports = getLogger;
export default getLogger;
4 changes: 2 additions & 2 deletions lib/getManifest.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { existsSync, lstatSync, readFileSync } = require("fs");
import { existsSync, lstatSync, readFileSync } from "fs";

/**
* Read the content of target package.json if exists.
Expand Down Expand Up @@ -79,4 +79,4 @@ function getManifest(path) {
}

// Exports.
module.exports = getManifest;
export default getManifest;
12 changes: 6 additions & 6 deletions lib/getPackagePaths.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const getManifest = require("./getManifest");
const glob = require("./glob");
const { slash } = require("./utils");
const path = require("path");
const { getPackagesSync } = require("@manypkg/get-packages");
import path from "path";
import { getPackagesSync } from "@manypkg/get-packages";
import getManifest from "./getManifest.js";
import glob from "./glob.js";
import { slash } from "./utils.js";

/**
* Return array of package.json for workspace packages.
Expand Down Expand Up @@ -54,4 +54,4 @@ function getPackagePaths(cwd, ignorePackages = null) {
}

// Exports.
module.exports = getPackagePaths;
export default getPackagePaths;
10 changes: 6 additions & 4 deletions lib/getSynchronizer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const EventEmitter = require("promise-events");
const { identity } = require("lodash");
const debug = require("debug")("msr:synchronizer");
import EventEmitter from "promise-events";
import { identity } from "lodash-es";
import dbg from "debug";

const debug = dbg("msr:synchronizer");

/**
* Cross-packages synchronization context.
Expand Down Expand Up @@ -93,4 +95,4 @@ const getSynchronizer = (packages) => {
};
};

module.exports = getSynchronizer;
export default getSynchronizer;
6 changes: 2 additions & 4 deletions lib/git.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const execa = require("execa");
import execa from "execa";

/**
* Get all the tags for a given branch.
Expand All @@ -25,6 +25,4 @@ function getTags(branch, execaOptions, filters) {
return tags.filter((tag) => validateSubstr(tag, filters));
}

module.exports = {
getTags,
};
export { getTags };
4 changes: 2 additions & 2 deletions lib/glob.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const globby = require("globby");
import globby from "globby";

module.exports = (...args) => {
export default (...args) => {
const [pattern, ...options] = args;

return globby.sync(pattern, ...options);
Expand Down
2 changes: 1 addition & 1 deletion lib/isCyclicProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ const isCyclicProject = (pkgs) => {
);
};

module.exports = isCyclicProject;
export default isCyclicProject;
31 changes: 16 additions & 15 deletions lib/multiSemanticRelease.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
const { dirname } = require("path");
const semanticRelease = require("semantic-release");
const { uniq, template } = require("lodash");
const { check, ValueError } = require("./blork");
const getLogger = require("./getLogger");
const getSynchronizer = require("./getSynchronizer");
const getConfig = require("./getConfig");
const getConfigSemantic = require("./getConfigSemantic");
const getManifest = require("./getManifest");
const cleanPath = require("./cleanPath");
const RescopedStream = require("./RescopedStream");
const createInlinePluginCreator = require("./createInlinePluginCreator");
const isCyclicProject = require("./isCyclicProject");
import { dirname } from "path";
import semanticRelease from "semantic-release";
import { uniq, template } from "lodash-es";
import { check, ValueError } from "./blork.js";
import getLogger from "./getLogger.js";
import getSynchronizer from "./getSynchronizer.js";
import getConfig from "./getConfig.js";
import getConfigSemantic from "./getConfigSemantic.js";
import getManifest from "./getManifest.js";
import cleanPath from "./cleanPath.js";
import RescopedStream from "./RescopedStream.js";
import createInlinePluginCreator from "./createInlinePluginCreator.js";
import isCyclicProject from "./isCyclicProject.js";

/**
* The multirelease context.
Expand Down Expand Up @@ -111,8 +111,6 @@ async function multiSemanticRelease(
return packages;
}

// Exports.
module.exports = multiSemanticRelease;

/**
* Load details about a package.
Expand Down Expand Up @@ -217,3 +215,6 @@ function normalizeFlags(_flags) {
..._flags,
};
}

// Exports.
export default multiSemanticRelease;
6 changes: 3 additions & 3 deletions lib/recognizeFormat.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const detectNewline = require("detect-newline");
const detectIndent = require("detect-indent");
import detectNewline from "detect-newline";
import detectIndent from "detect-indent";

/**
* Information about the format of a file.
Expand All @@ -22,4 +22,4 @@ function recognizeFormat(contents) {
}

// Exports.
module.exports = recognizeFormat;
export default recognizeFormat;
20 changes: 11 additions & 9 deletions lib/updateDeps.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const { writeFileSync } = require("fs");
const semver = require("semver");
const { isObject, isEqual, transform } = require("lodash");
const recognizeFormat = require("./recognizeFormat");
const getManifest = require("./getManifest");
const { getHighestVersion, getLatestVersion } = require("./utils");
const { getTags } = require("./git");
const debug = require("debug")("msr:updateDeps");
import { writeFileSync } from "fs";
import dbg from "debug";
import semver from "semver";
import { isObject, isEqual, transform } from "lodash-es";
import recognizeFormat from "./recognizeFormat.js";
import getManifest from "./getManifest.js";
import { getHighestVersion, getLatestVersion } from "./utils.js";
import { getTags } from "./git.js";

const debug = dbg("msr:updateDeps");

/**
* Resolve next package version.
Expand Down Expand Up @@ -329,7 +331,7 @@ const auditManifestChanges = (actualManifest, path) => {
return false;
};

module.exports = {
export {
getNextVersion,
getNextPreVersion,
getPreReleaseTag,
Expand Down
5 changes: 3 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* https://github.com/semantic-release/semantic-release/blob/master/lib/utils.js
*/

const { gt, lt, prerelease, rcompare } = require("semver");
import semver from "semver";
const { gt, lt, prerelease, rcompare } = semver;

/**
* Get tag objects and convert them to a list of stringified versions.
Expand Down Expand Up @@ -64,7 +65,7 @@ function slash(path) {
return path.replace(/\\/g, "/");
}

module.exports = {
export {
tagsToVersions,
getHighestVersion,
getLowestVersion,
Expand Down
Loading

0 comments on commit 99fffa9

Please sign in to comment.