diff --git a/src/cli/init-config/build-config.cjs b/src/cli/init-config/build-config.mjs similarity index 75% rename from src/cli/init-config/build-config.cjs rename to src/cli/init-config/build-config.mjs index 36114065e..f7d2167be 100644 --- a/src/cli/init-config/build-config.cjs +++ b/src/cli/init-config/build-config.mjs @@ -1,9 +1,9 @@ // @ts-check -const Handlebars = require("handlebars/runtime"); -const { folderNameArrayToRE } = require("./utl.cjs"); +import Handlebars from "handlebars/runtime.js"; +import { folderNameArrayToRE } from "./utl.mjs"; /* eslint import/no-unassigned-import: 0 */ -require("./config.js.template"); +await import("./config.js.template.js"); /** * @param {string} pString @@ -28,12 +28,12 @@ function extensionsToString(pExtensions) { * Creates a .dependency-cruiser config with a set of basic validations * to the current directory. * - * @param {import("./types").IInitConfig} pNormalizedInitOptions Options that influence the shape of + * @param {import("./types.js").IInitConfig} pNormalizedInitOptions Options that influence the shape of * the configuration * @returns {string} the configuration as a string */ -module.exports = function buildConfig(pNormalizedInitOptions) { +export default function buildConfig(pNormalizedInitOptions) { return Handlebars.templates["config.js.template.hbs"]({ ...pNormalizedInitOptions, @@ -45,4 +45,4 @@ module.exports = function buildConfig(pNormalizedInitOptions) { pNormalizedInitOptions.resolutionExtensions ), }); -}; +} diff --git a/src/cli/init-config/index.mjs b/src/cli/init-config/index.mjs index adb51f88a..16ff98969 100644 --- a/src/cli/init-config/index.mjs +++ b/src/cli/init-config/index.mjs @@ -1,7 +1,7 @@ // @ts-check import { PACKAGE_MANIFEST as _PACKAGE_MANIFEST } from "../defaults.mjs"; import normalizeInitOptions from "./normalize-init-options.mjs"; -import buildConfig from "./build-config.cjs"; +import buildConfig from "./build-config.mjs"; import writeConfig from "./write-config.mjs"; import getUserInput from "./get-user-input.mjs"; import { diff --git a/src/cli/init-config/utl.cjs b/src/cli/init-config/utl.cjs deleted file mode 100644 index 2757d586f..000000000 --- a/src/cli/init-config/utl.cjs +++ /dev/null @@ -1,6 +0,0 @@ -function folderNameArrayToRE(pArrayOfStrings) { - return `^(${pArrayOfStrings.join("|")})`; -} -module.exports = { - folderNameArrayToRE, -}; diff --git a/src/cli/init-config/utl.mjs b/src/cli/init-config/utl.mjs new file mode 100644 index 000000000..96212f550 --- /dev/null +++ b/src/cli/init-config/utl.mjs @@ -0,0 +1,3 @@ +export function folderNameArrayToRE(pArrayOfStrings) { + return `^(${pArrayOfStrings.join("|")})`; +} diff --git a/src/cli/init-config/write-run-scripts-to-manifest.mjs b/src/cli/init-config/write-run-scripts-to-manifest.mjs index 4faeec308..341742eea 100644 --- a/src/cli/init-config/write-run-scripts-to-manifest.mjs +++ b/src/cli/init-config/write-run-scripts-to-manifest.mjs @@ -6,7 +6,7 @@ import chalk from "chalk"; import wrapAndIndent from "../../utl/wrap-and-indent.mjs"; import { PACKAGE_MANIFEST as _PACKAGE_MANIFEST } from "../defaults.mjs"; import { readManifest } from "./environment-helpers.mjs"; -import { folderNameArrayToRE } from "./utl.cjs"; +import { folderNameArrayToRE } from "./utl.mjs"; const PACKAGE_MANIFEST = `./${_PACKAGE_MANIFEST}`; diff --git a/test/cli/init-config/create-config.spec.mjs b/test/cli/init-config/create-config.spec.mjs index 5eca8a2e8..3e7199f8c 100644 --- a/test/cli/init-config/create-config.spec.mjs +++ b/test/cli/init-config/create-config.spec.mjs @@ -3,7 +3,7 @@ import { tmpdir } from "node:os"; import { join } from "node:path/posix"; import { expect, use } from "chai"; import chaiJsonSchema from "chai-json-schema"; -import buildConfig from "../../../src/cli/init-config/build-config.cjs"; +import buildConfig from "../../../src/cli/init-config/build-config.mjs"; import normalizeInitOptions from "../../../src/cli/init-config/normalize-init-options.mjs"; import configurationSchema from "../../../src/schema/configuration.schema.mjs"; import deleteDammit from "../delete-dammit.utl.cjs"; diff --git a/test/cli/init-config/utl.spec.mjs b/test/cli/init-config/utl.spec.mjs index 161d6b43d..d8bc92aad 100644 --- a/test/cli/init-config/utl.spec.mjs +++ b/test/cli/init-config/utl.spec.mjs @@ -1,15 +1,15 @@ import { expect } from "chai"; -import utl from "../../../src/cli/init-config/utl.cjs"; +import { folderNameArrayToRE } from "../../../src/cli/init-config/utl.mjs"; describe("[U] cli/init-config/utl - folderNameArrayToRE", () => { it("transforms an array of folder names into a regex string - empty", () => { - expect(utl.folderNameArrayToRE([])).to.equal("^()"); + expect(folderNameArrayToRE([])).to.equal("^()"); }); it("transforms an array of folder names into a regex string - one entry", () => { - expect(utl.folderNameArrayToRE(["src"])).to.equal("^(src)"); + expect(folderNameArrayToRE(["src"])).to.equal("^(src)"); }); it("transforms an array of folder names into a regex string - more than one entry", () => { - expect(utl.folderNameArrayToRE(["bin", "src", "lib"])).to.equal( + expect(folderNameArrayToRE(["bin", "src", "lib"])).to.equal( "^(bin|src|lib)" ); });