diff --git a/bin/cli.js b/bin/cli.js index d545d1e..c914077 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -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 diff --git a/bin/runner.js b/bin/runner.js index a052230..8f7a8cf 100644 --- a/bin/runner.js +++ b/bin/runner.js @@ -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"); diff --git a/lib/RescopedStream.js b/lib/RescopedStream.js index 3fa29cf..93efd05 100644 --- a/lib/RescopedStream.js +++ b/lib/RescopedStream.js @@ -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. @@ -29,4 +29,4 @@ class RescopedStream extends Writable { } // Exports. -module.exports = RescopedStream; +export default RescopedStream; diff --git a/lib/blork.js b/lib/blork.js index 0ba0c12..0d5f2f0 100644 --- a/lib/blork.js +++ b/lib/blork.js @@ -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"); @@ -22,4 +22,4 @@ add( ); // Exports. -module.exports = { checker, check, ValueError }; +export { checker, check, ValueError }; diff --git a/lib/cleanPath.js b/lib/cleanPath.js index 7a36674..b4a125a 100644 --- a/lib/cleanPath.js +++ b/lib/cleanPath.js @@ -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. @@ -21,4 +21,4 @@ function cleanPath(path, cwd = process.cwd()) { } // Exports. -module.exports = cleanPath; +export default cleanPath; diff --git a/lib/createInlinePluginCreator.js b/lib/createInlinePluginCreator.js index af44736..baf78da 100644 --- a/lib/createInlinePluginCreator.js +++ b/lib/createInlinePluginCreator.js @@ -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. @@ -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 @@ -252,4 +252,4 @@ function createInlinePluginCreator(packages, multiContext, synchronizer, flags) } // Exports. -module.exports = createInlinePluginCreator; +export default createInlinePluginCreator; diff --git a/lib/getCommitsFiltered.js b/lib/getCommitsFiltered.js index 7bb0d5b..cb2ae1a 100644 --- a/lib/getCommitsFiltered.js +++ b/lib/getCommitsFiltered.js @@ -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. @@ -63,4 +65,4 @@ async function getCommitsFiltered(cwd, dir, lastHead = undefined, firstParentBra } // Exports. -module.exports = getCommitsFiltered; +export default getCommitsFiltered; diff --git a/lib/getConfig.js b/lib/getConfig.js index 002c13e..194a6af 100644 --- a/lib/getConfig.js +++ b/lib/getConfig.js @@ -1,4 +1,4 @@ -const { cosmiconfig } = require("cosmiconfig"); +import { cosmiconfig } from "cosmiconfig"; // Copied from get-config.js in semantic-release const CONFIG_NAME = "release"; @@ -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); diff --git a/lib/getConfigSemantic.js b/lib/getConfigSemantic.js index 020b3d7..9072915 100644 --- a/lib/getConfigSemantic.js +++ b/lib/getConfigSemantic.js @@ -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. @@ -29,4 +31,4 @@ async function getConfigSemantic({ cwd, env, stdout, stderr, logger }, options) } // Exports. -module.exports = getConfigSemantic; +export default getConfigSemantic; diff --git a/lib/getLogger.js b/lib/getLogger.js index 65d3328..a00084b 100644 --- a/lib/getLogger.js +++ b/lib/getLogger.js @@ -1,4 +1,5 @@ -const { Signale } = require("signale"); +import signale from "signale"; +const { Signale } = signale; /** * Return a new Signale instance. @@ -25,4 +26,4 @@ function getLogger({ stdout, stderr }) { } // Exports. -module.exports = getLogger; +export default getLogger; diff --git a/lib/getManifest.js b/lib/getManifest.js index 116a25f..c2fb50e 100644 --- a/lib/getManifest.js +++ b/lib/getManifest.js @@ -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. @@ -79,4 +79,4 @@ function getManifest(path) { } // Exports. -module.exports = getManifest; +export default getManifest; diff --git a/lib/getPackagePaths.js b/lib/getPackagePaths.js index c83cdab..39b9036 100644 --- a/lib/getPackagePaths.js +++ b/lib/getPackagePaths.js @@ -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. @@ -54,4 +54,4 @@ function getPackagePaths(cwd, ignorePackages = null) { } // Exports. -module.exports = getPackagePaths; +export default getPackagePaths; diff --git a/lib/getSynchronizer.js b/lib/getSynchronizer.js index 4577306..9537856 100644 --- a/lib/getSynchronizer.js +++ b/lib/getSynchronizer.js @@ -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. @@ -93,4 +95,4 @@ const getSynchronizer = (packages) => { }; }; -module.exports = getSynchronizer; +export default getSynchronizer; diff --git a/lib/git.js b/lib/git.js index 95e432a..55469eb 100644 --- a/lib/git.js +++ b/lib/git.js @@ -1,4 +1,4 @@ -const execa = require("execa"); +import execa from "execa"; /** * Get all the tags for a given branch. @@ -25,6 +25,4 @@ function getTags(branch, execaOptions, filters) { return tags.filter((tag) => validateSubstr(tag, filters)); } -module.exports = { - getTags, -}; +export { getTags }; diff --git a/lib/glob.js b/lib/glob.js index 1dfe023..107493d 100644 --- a/lib/glob.js +++ b/lib/glob.js @@ -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); diff --git a/lib/isCyclicProject.js b/lib/isCyclicProject.js index 5141463..b36bd70 100644 --- a/lib/isCyclicProject.js +++ b/lib/isCyclicProject.js @@ -9,4 +9,4 @@ const isCyclicProject = (pkgs) => { ); }; -module.exports = isCyclicProject; +export default isCyclicProject; diff --git a/lib/multiSemanticRelease.js b/lib/multiSemanticRelease.js index aaae267..2046ac5 100644 --- a/lib/multiSemanticRelease.js +++ b/lib/multiSemanticRelease.js @@ -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. @@ -111,8 +111,6 @@ async function multiSemanticRelease( return packages; } -// Exports. -module.exports = multiSemanticRelease; /** * Load details about a package. @@ -217,3 +215,6 @@ function normalizeFlags(_flags) { ..._flags, }; } + +// Exports. +export default multiSemanticRelease; diff --git a/lib/recognizeFormat.js b/lib/recognizeFormat.js index 883d409..507f12a 100644 --- a/lib/recognizeFormat.js +++ b/lib/recognizeFormat.js @@ -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. @@ -22,4 +22,4 @@ function recognizeFormat(contents) { } // Exports. -module.exports = recognizeFormat; +export default recognizeFormat; diff --git a/lib/updateDeps.js b/lib/updateDeps.js index 455c5ca..6668492 100644 --- a/lib/updateDeps.js +++ b/lib/updateDeps.js @@ -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. @@ -329,7 +331,7 @@ const auditManifestChanges = (actualManifest, path) => { return false; }; -module.exports = { +export { getNextVersion, getNextPreVersion, getPreReleaseTag, diff --git a/lib/utils.js b/lib/utils.js index 53bad1f..97ab786 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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. @@ -64,7 +65,7 @@ function slash(path) { return path.replace(/\\/g, "/"); } -module.exports = { +export { tagsToVersions, getHighestVersion, getLowestVersion, diff --git a/package.json b/package.json index 05da0dc..0d2d678 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,11 @@ "version": "5.0.3", "license": "0BSD", "engines": { - "node": ">=10.18", + "node": ">=12.20", "yarn": ">=1.0.0" }, - "main": "lib/multiSemanticRelease.js", + "type": "module", + "exports": "./lib/multiSemanticRelease.js", "bin": { "multi-semantic-release": "./bin/cli.js" }, @@ -19,7 +20,7 @@ ], "scripts": { "watch": "jest --watchAll", - "jest": "TRAVIS_PULL_REQUEST_BRANCH=master jest --coverage", + "jest": "TRAVIS_PULL_REQUEST_BRANCH=master NODE_OPTIONS=--experimental-vm-modules ./node_modules/.bin/jest --coverage", "lint": "eslint ./", "lint:fix": "eslint --fix ./", "test": "yarn lint && yarn jest", @@ -50,7 +51,7 @@ "modulePathIgnorePatterns": [ "/test/fixtures" ], - "testTimeout": 10000 + "testTimeout": 50000 }, "dependencies": { "blork": "^9.3.0", @@ -63,6 +64,7 @@ "get-stream": "^6.0.1", "git-log-parser": "^1.2.0", "globby": "11.0.4", + "lodash-es": "^4.17.21", "lodash": "^4.17.21", "meow": "^9.0.0", "promise-events": "^0.2.4", diff --git a/test/bin/cli.test.js b/test/bin/cli.test.js index 69c226c..af40566 100644 --- a/test/bin/cli.test.js +++ b/test/bin/cli.test.js @@ -1,6 +1,6 @@ -const execa = require("execa"); -const { copyDirectory } = require("../helpers/file"); -const { +import execa from "execa"; +import { copyDirectory } from "../helpers/file.js"; +import { gitInit, gitAdd, gitCommit, @@ -9,7 +9,11 @@ const { gitPush, gitTag, gitGetTags, -} = require("../helpers/git"); +} from "../helpers/git.js"; +import {dirname} from "node:path"; +import {fileURLToPath} from "node:url"; + +const __dirname = dirname(fileURLToPath(import.meta.url)) // Tests. describe("multi-semantic-release CLI", () => { diff --git a/test/helpers/file.js b/test/helpers/file.js index 48277a7..9a3d9c6 100644 --- a/test/helpers/file.js +++ b/test/helpers/file.js @@ -1,5 +1,5 @@ -const { basename, join } = require("path"); -const { copyFileSync, existsSync, mkdirSync, lstatSync, readdirSync, readFileSync, writeFileSync } = require("fs"); +import { basename, join } from "path"; +import { copyFileSync, existsSync, mkdirSync, lstatSync, readdirSync, readFileSync, writeFileSync } from "fs"; // Deep copy a directory. function copyDirectory(source, target) { @@ -45,7 +45,7 @@ function createNewTestingFiles(folders, cwd) { } // Exports. -module.exports = { +export { copyDirectory, isDirectory, createNewTestingFiles, diff --git a/test/helpers/git.js b/test/helpers/git.js index e615f8a..e2050e8 100644 --- a/test/helpers/git.js +++ b/test/helpers/git.js @@ -3,12 +3,12 @@ * https://github.com/semantic-release/semantic-release/blob/master/test/helpers/git-utils.js */ -const { check } = require("blork"); -const tempy = require("tempy"); -const execa = require("execa"); -const fileUrl = require("file-url"); -const gitLogParser = require("git-log-parser"); -const { array: getStreamArray } = require("get-stream"); +import { check } from "blork"; +import tempy from "tempy"; +import execa from "execa"; +import fileUrl from "file-url"; +import gitLogParser from "git-log-parser"; +import { array as getStreamArray } from "get-stream"; /** * @typedef {Object} Commit @@ -324,7 +324,7 @@ function gitGetLog(cwd, number, hash) { return execa.sync("git", ["log", `-${number}`, hash], { cwd }).stdout; } // Exports. -module.exports = { +export { gitInit, gitInitRemote, gitInitOrigin, diff --git a/test/lib/cleanPath.test.js b/test/lib/cleanPath.test.js index 1afacda..eba6a1e 100644 --- a/test/lib/cleanPath.test.js +++ b/test/lib/cleanPath.test.js @@ -1,4 +1,4 @@ -const cleanPath = require("../../lib/cleanPath"); +import cleanPath from "../../lib/cleanPath.js"; // Tests. describe("cleanPath()", () => { diff --git a/test/lib/getCommitsFiltered.test.js b/test/lib/getCommitsFiltered.test.js index cc48aa3..68ed645 100644 --- a/test/lib/getCommitsFiltered.test.js +++ b/test/lib/getCommitsFiltered.test.js @@ -1,8 +1,8 @@ -const { isAbsolute, join } = require("path"); -const tempy = require("tempy"); -const { readFileSync, writeFileSync, mkdirSync, existsSync } = require("fs"); -const getCommitsFiltered = require("../../lib/getCommitsFiltered"); -const { gitInit, gitCommitAll, gitGetCommits } = require("../helpers/git"); +import { isAbsolute, join } from "path"; +import tempy from "tempy"; +import { readFileSync, writeFileSync, mkdirSync, existsSync } from "fs"; +import getCommitsFiltered from "../../lib/getCommitsFiltered.js"; +import { gitInit, gitCommitAll } from "../helpers/git.js"; // Tests. describe("getCommitsFiltered()", () => { diff --git a/test/lib/getPackagePaths.test.js b/test/lib/getPackagePaths.test.js index 0782afc..d014225 100644 --- a/test/lib/getPackagePaths.test.js +++ b/test/lib/getPackagePaths.test.js @@ -1,5 +1,9 @@ -const { resolve } = require("path"); -const getPackagePaths = require("../../lib/getPackagePaths"); +import { resolve } from "path"; +import getPackagePaths from "../../lib/getPackagePaths.js"; +import {dirname} from "node:path"; +import {fileURLToPath} from "node:url"; + +const __dirname = dirname(fileURLToPath(import.meta.url)) // Tests. describe("getPackagePaths()", () => { diff --git a/test/lib/git.test.js b/test/lib/git.test.js index d437d09..5e1fa49 100644 --- a/test/lib/git.test.js +++ b/test/lib/git.test.js @@ -1,8 +1,10 @@ -const tempy = require("tempy"); -const { WritableStreamBuffer } = require("stream-buffers"); -const { copyDirectory, createNewTestingFiles } = require("../helpers/file"); -const { gitInit, gitCommitAll, gitInitOrigin, gitPush } = require("../helpers/git"); -const { getTags } = require("../../lib/git"); +import tempy from "tempy"; +import { WritableStreamBuffer } from "stream-buffers"; + +import { copyDirectory, createNewTestingFiles } from "../helpers/file.js"; +import { gitInit, gitCommitAll, gitInitOrigin, gitPush } from "../helpers/git.js"; +import { getTags } from "../../lib/git.js"; +import multiSemanticRelease from "../../lib/multiSemanticRelease.js"; test("Fetch all tags on master after two package release", async () => { const packages = ["packages/c/", "packages/d/"]; @@ -19,7 +21,6 @@ test("Fetch all tags on master after two package release", async () => { // Call multiSemanticRelease() // Doesn't include plugins that actually publish. - const multiSemanticRelease = require("../../"); await multiSemanticRelease( packages.map((folder) => `${folder}package.json`), { @@ -47,7 +48,6 @@ test("Fetch only prerelease tags", async () => { // Call multiSemanticRelease() // Doesn't include plugins that actually publish. - const multiSemanticRelease = require("../../"); await multiSemanticRelease( packages.map((folder) => `${folder}package.json`), { diff --git a/test/lib/isCyclicProject.test.js b/test/lib/isCyclicProject.test.js index 8dbb9d8..aeeae1e 100644 --- a/test/lib/isCyclicProject.test.js +++ b/test/lib/isCyclicProject.test.js @@ -1,4 +1,4 @@ -const isCyclicProject = require("../../lib/isCyclicProject"); +import isCyclicProject from "../../lib/isCyclicProject.js"; // Tests. describe("isCyclicProject()", () => { diff --git a/test/lib/multiSemanticRelease.test.js b/test/lib/multiSemanticRelease.test.js index d4a4220..dbe4690 100644 --- a/test/lib/multiSemanticRelease.test.js +++ b/test/lib/multiSemanticRelease.test.js @@ -1,11 +1,14 @@ -const { ValueError } = require("blork"); -const { writeFileSync } = require("fs"); -const { resolve } = require("path"); -const path = require("path"); -const { Signale } = require("signale"); -const { WritableStreamBuffer } = require("stream-buffers"); -const { copyDirectory, createNewTestingFiles } = require("../helpers/file"); -const { +import { ValueError } from "blork"; +import { writeFileSync } from "fs"; +import { dirname } from "node:path"; +import { fileURLToPath } from "node:url"; +import { createRequire } from 'module'; +import {jest} from '@jest/globals'; + +import signale from "signale"; +import { WritableStreamBuffer } from "stream-buffers"; +import { copyDirectory, createNewTestingFiles } from "../helpers/file.js"; +import { gitInit, gitAdd, gitCommit, @@ -15,13 +18,16 @@ const { gitTag, gitGetTags, gitGetLog, -} = require("../helpers/git"); +} from "../helpers/git"; +import multiSemanticRelease from "../../lib/multiSemanticRelease.js"; + +const require = createRequire(import.meta.url); // Clear mocks before tests. beforeEach(() => { - jest.setTimeout(50000); + jest.clearAllMocks(); // Clear all mocks. - require.cache = {}; // Clear the require cache so modules are loaded fresh. + // require.cache = {}; // Clear the require cache so modules are loaded fresh. }); // Tests. @@ -40,7 +46,6 @@ describe("multiSemanticRelease()", () => { // Call multiSemanticRelease() // Doesn't include plugins that actually publish. - const multiSemanticRelease = require("../../"); const result = await multiSemanticRelease( [ `packages/a/package.json`, @@ -160,7 +165,6 @@ describe("multiSemanticRelease()", () => { // Call multiSemanticRelease() // Doesn't include plugins that actually publish. - const multiSemanticRelease = require("../../"); const result = await multiSemanticRelease( [ `packages/a/package.json`, @@ -287,7 +291,6 @@ describe("multiSemanticRelease()", () => { // Call multiSemanticRelease() // Doesn't include plugins that actually publish. - const multiSemanticRelease = require("../../"); let result = await multiSemanticRelease( packages.map((folder) => `${folder}package.json`), { @@ -372,7 +375,6 @@ describe("multiSemanticRelease()", () => { // Call multiSemanticRelease() // Doesn't include plugins that actually publish. - const multiSemanticRelease = require("../../"); let result = await multiSemanticRelease( packages.map((folder) => `${folder}package.json`), { @@ -464,7 +466,6 @@ describe("multiSemanticRelease()", () => { // Call multiSemanticRelease() // Doesn't include plugins that actually publish. - const multiSemanticRelease = require("../../"); let result = await multiSemanticRelease( packages.map((folder) => `${folder}package.json`), { @@ -633,7 +634,6 @@ describe("multiSemanticRelease()", () => { // Call multiSemanticRelease() // Doesn't include plugins that actually publish. - const multiSemanticRelease = require("../../"); const result = await multiSemanticRelease( [ `packages/c/package.json`, @@ -688,7 +688,6 @@ describe("multiSemanticRelease()", () => { // Call multiSemanticRelease() // Doesn't include plugins that actually publish. - const multiSemanticRelease = require("../../"); const result = await multiSemanticRelease( [ `packages/c/package.json`, @@ -824,7 +823,6 @@ describe("multiSemanticRelease()", () => { // Call multiSemanticRelease() // Doesn't include plugins that actually publish. - const multiSemanticRelease = require("../../"); const result = await multiSemanticRelease( [`packages/c/package.json`, `packages/d/package.json`], { @@ -927,7 +925,6 @@ describe("multiSemanticRelease()", () => { // Call multiSemanticRelease() // Doesn't include plugins that actually publish. - const multiSemanticRelease = require("../../"); const result = await multiSemanticRelease( [`packages/c/package.json`, `packages/d/package.json`], {}, @@ -990,7 +987,6 @@ describe("multiSemanticRelease()", () => { // Call multiSemanticRelease() // Doesn't include plugins that actually publish. - const multiSemanticRelease = require("../../"); const result = await multiSemanticRelease( [ `packages/c/package.json`, @@ -1039,7 +1035,6 @@ describe("multiSemanticRelease()", () => { // Call multiSemanticRelease() try { - const multiSemanticRelease = require("../../"); const result = await multiSemanticRelease( [`packages/a/package.json`, `packages/c/package.json`], {}, @@ -1076,7 +1071,6 @@ describe("multiSemanticRelease()", () => { const stderr = new WritableStreamBuffer(); // Call multiSemanticRelease() - const multiSemanticRelease = require("../../"); const result = await multiSemanticRelease( [`packages/d/package.json`], { @@ -1123,7 +1117,6 @@ describe("multiSemanticRelease()", () => { // Call multiSemanticRelease() // Include "@semantic-release/git" for made the git head changed - const multiSemanticRelease = require("../../"); const result = await multiSemanticRelease( [ `packages/c/package.json`, @@ -1159,7 +1152,6 @@ describe("multiSemanticRelease()", () => { const stderr = new WritableStreamBuffer(); // Release. - const multiSemanticRelease = require("../../"); // Call multiSemanticRelease() // Doesn't include plugins that actually publish. @@ -1188,7 +1180,6 @@ describe("multiSemanticRelease()", () => { } }); test("TypeError if CWD is not string", async () => { - const multiSemanticRelease = require("../../"); await expect(multiSemanticRelease()).rejects.toBeInstanceOf(TypeError); await expect(multiSemanticRelease(undefined)).rejects.toBeInstanceOf(TypeError); await expect(multiSemanticRelease(null)).rejects.toBeInstanceOf(TypeError); @@ -1198,7 +1189,6 @@ describe("multiSemanticRelease()", () => { await expect(multiSemanticRelease([null])).rejects.toBeInstanceOf(TypeError); }); test("TypeError if paths is not a list of strings", async () => { - const multiSemanticRelease = require("../../"); await expect(multiSemanticRelease()).rejects.toBeInstanceOf(TypeError); await expect(multiSemanticRelease(undefined)).rejects.toBeInstanceOf(TypeError); await expect(multiSemanticRelease(null)).rejects.toBeInstanceOf(TypeError); @@ -1208,7 +1198,6 @@ describe("multiSemanticRelease()", () => { await expect(multiSemanticRelease([null])).rejects.toBeInstanceOf(TypeError); }); test("ReferenceError if paths points to a non-file", async () => { - const multiSemanticRelease = require("../../"); const stdout = new WritableStreamBuffer(); // Blackhole the output so it doesn't clutter Jest. const r1 = multiSemanticRelease(["test/fixtures/DOESNOTEXIST.json"], {}, { stdout }); await expect(r1).rejects.toBeInstanceOf(ReferenceError); // Path that does not exist. @@ -1218,7 +1207,6 @@ describe("multiSemanticRelease()", () => { await expect(r3).rejects.toBeInstanceOf(ReferenceError); // Directory that exists. }); test("SyntaxError if paths points to package.json with bad syntax", async () => { - const multiSemanticRelease = require("../../"); const stdout = new WritableStreamBuffer(); // Blackhole the output so it doesn't clutter Jest. const r1 = multiSemanticRelease(["test/fixtures/invalidPackage.json"], {}, { stdout }); await expect(r1).rejects.toBeInstanceOf(SyntaxError); @@ -1266,7 +1254,6 @@ describe("multiSemanticRelease()", () => { // Call multiSemanticRelease() // Doesn't include plugins that actually publish. - const multiSemanticRelease = require("../../"); const result = multiSemanticRelease( [ `packages/a/package.json`, @@ -1297,7 +1284,6 @@ describe("multiSemanticRelease()", () => { const stdout = new WritableStreamBuffer(); const stderr = new WritableStreamBuffer(); - const multiSemanticRelease = require("../../"); await multiSemanticRelease( [`packages/a/package.json`], {}, diff --git a/test/lib/recognizeFormat.test.js b/test/lib/recognizeFormat.test.js index a4de167..48a1e8a 100644 --- a/test/lib/recognizeFormat.test.js +++ b/test/lib/recognizeFormat.test.js @@ -1,4 +1,4 @@ -const recognizeFormat = require("../../lib/recognizeFormat"); +import recognizeFormat from "../../lib/recognizeFormat.js"; // Tests. describe("recognizeFormat()", () => { diff --git a/test/lib/resolveReleaseType.test.js b/test/lib/resolveReleaseType.test.js index 868e3ec..44fa31b 100644 --- a/test/lib/resolveReleaseType.test.js +++ b/test/lib/resolveReleaseType.test.js @@ -1,4 +1,4 @@ -const { resolveReleaseType } = require("../../lib/updateDeps"); +import { resolveReleaseType } from "../../lib/updateDeps.js"; // Tests. describe("resolveReleaseType()", () => { diff --git a/test/lib/updateDeps.test.js b/test/lib/updateDeps.test.js index 5ecdcac..0bd8470 100644 --- a/test/lib/updateDeps.test.js +++ b/test/lib/updateDeps.test.js @@ -1,11 +1,11 @@ -const { +import { resolveReleaseType, resolveNextVersion, getNextVersion, getNextPreVersion, getPreReleaseTag, getVersionFromTag, -} = require("../../lib/updateDeps"); +} from "../../lib/updateDeps.js"; describe("resolveNextVersion()", () => { // prettier-ignore diff --git a/test/lib/utils.test.js b/test/lib/utils.test.js index 1990261..d28f658 100644 --- a/test/lib/utils.test.js +++ b/test/lib/utils.test.js @@ -1,13 +1,13 @@ -const { tag } = require("semantic-release/lib/git"); -const { getHighestVersion, getLowestVersion, getLatestVersion, tagsToVersions } = require("../../lib/utils"); +import { tag } from "semantic-release/lib/git.js"; +import { getHighestVersion, getLowestVersion, getLatestVersion, tagsToVersions } from "../../lib/utils.js"; describe("tagsToVersions()", () => { // prettier-ignore const cases = [ - [[{version: "1.0.0"}, {version: "1.1.0"}, {version: "1.2.0"}], ["1.0.0", "1.1.0", "1.2.0"]], - [[],[]], - [undefined, []], - [null, []], + [[{version: "1.0.0"}, {version: "1.1.0"}, {version: "1.2.0"}], ["1.0.0", "1.1.0", "1.2.0"]], + [[],[]], + [undefined, []], + [null, []], ] cases.forEach(([tags, versions]) => { @@ -21,10 +21,10 @@ describe("getHighestVersion()", () => { // prettier-ignore const cases = [ ["1.0.0", "2.0.0", "2.0.0"], - ["1.1.1", "1.0.0", "1.1.1"], - [null, "1.0.0", "1.0.0"], - ["1.0.0", undefined, "1.0.0"], - [undefined, undefined, undefined], + ["1.1.1", "1.0.0", "1.1.1"], + [null, "1.0.0", "1.0.0"], + ["1.0.0", undefined, "1.0.0"], + [undefined, undefined, undefined], ] cases.forEach(([version1, version2, high]) => { @@ -38,10 +38,10 @@ describe("getLowestVersion()", () => { // prettier-ignore const cases = [ ["1.0.0", "2.0.0", "1.0.0"], - ["1.1.1", "1.0.0", "1.0.0"], - [null, "1.0.0", "1.0.0"], - ["1.0.0", undefined, "1.0.0"], - [undefined, undefined, undefined], + ["1.1.1", "1.0.0", "1.0.0"], + [null, "1.0.0", "1.0.0"], + ["1.0.0", undefined, "1.0.0"], + [undefined, undefined, undefined], ] cases.forEach(([version1, version2, low]) => { @@ -55,10 +55,10 @@ describe("getLatestVersion()", () => { // prettier-ignore const cases = [ [["1.2.3-alpha.3", "1.2.0", "1.0.1", "1.0.0-alpha.1"], null, "1.2.0"], - [["1.2.3-alpha.3", "1.2.3-alpha.2"], null, undefined], - [["1.2.3-alpha.3", "1.2.0", "1.0.1", "1.0.0-alpha.1"], true, "1.2.3-alpha.3"], - [["1.2.3-alpha.3", "1.2.3-alpha.2"], true, "1.2.3-alpha.3"], - [[], {}, undefined] + [["1.2.3-alpha.3", "1.2.3-alpha.2"], null, undefined], + [["1.2.3-alpha.3", "1.2.0", "1.0.1", "1.0.0-alpha.1"], true, "1.2.3-alpha.3"], + [["1.2.3-alpha.3", "1.2.3-alpha.2"], true, "1.2.3-alpha.3"], + [[], {}, undefined] ] cases.forEach(([versions, withPrerelease, latest]) => { diff --git a/yarn.lock b/yarn.lock index ff6b1c6..59bfa4e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4379,6 +4379,11 @@ locate-path@^6.0.0: dependencies: p-locate "^5.0.0" +lodash-es@^4.17.21: + version "4.17.21" + resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.21.tgz#43e626c46e6591b7750beb2b50117390c609e3ee" + integrity sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw== + lodash.capitalize@^4.2.1: version "4.2.1" resolved "https://registry.yarnpkg.com/lodash.capitalize/-/lodash.capitalize-4.2.1.tgz#f826c9b4e2a8511d84e3aca29db05e1a4f3b72a9"