From 0e6a4fc20455a3688b15ccb56ef0aaf2565bc436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Goetz?= Date: Mon, 7 Aug 2023 22:43:01 +0200 Subject: [PATCH] Switch crafty-preset-images-simple to esm --- packages/crafty-preset-images-simple/index.js | 4 ++-- packages/crafty-preset-images-simple/package.json | 1 + packages/crafty-runner-gulp/src/index.js | 14 +++++++++----- packages/crafty/src/bin.cjs | 1 - .../__tests__/crafty-preset-images-simple.js | 5 ++--- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/crafty-preset-images-simple/index.js b/packages/crafty-preset-images-simple/index.js index 1a51d1d9c..455cb98c1 100644 --- a/packages/crafty-preset-images-simple/index.js +++ b/packages/crafty-preset-images-simple/index.js @@ -1,6 +1,6 @@ -const path = require("path"); +import path from "path"; -module.exports = { +export default { defaultConfig() { return { bundleTypes: { img: "images" }, diff --git a/packages/crafty-preset-images-simple/package.json b/packages/crafty-preset-images-simple/package.json index 1eed86a7d..eba56b088 100644 --- a/packages/crafty-preset-images-simple/package.json +++ b/packages/crafty-preset-images-simple/package.json @@ -4,6 +4,7 @@ "repository": "https://github.com/swissquote/crafty.git", "description": "Compress images with Crafty", "license": "Apache-2.0", + "type": "module", "publishConfig": { "registry": "https://registry.npmjs.org", "access": "public" diff --git a/packages/crafty-runner-gulp/src/index.js b/packages/crafty-runner-gulp/src/index.js index 40945c3fb..bc9698d69 100644 --- a/packages/crafty-runner-gulp/src/index.js +++ b/packages/crafty-runner-gulp/src/index.js @@ -1,21 +1,25 @@ const StreamHandler = require("./StreamHandler"); const Gulp = require("./Gulp.js"); -let gulp; +const gulpSymbol = Symbol.for("gulp"); + +function getGulp(crafty) { + return crafty[gulpSymbol]; +} module.exports = { init(crafty) { - gulp = new Gulp(crafty); - StreamHandler.init(crafty, gulp); + crafty[gulpSymbol] = new Gulp(crafty); + StreamHandler.init(crafty, getGulp(crafty)); }, bundleCreator(/*crafty*/) { return { __gulp(craftyAgain, bundle, creator) { - creator(craftyAgain, bundle, gulp, StreamHandler); + creator(craftyAgain, bundle, getGulp(craftyAgain), StreamHandler); } }; }, tasks(crafty) { - crafty.runAllSync("gulp", crafty, gulp, StreamHandler); + crafty.runAllSync("gulp", crafty, getGulp(crafty), StreamHandler); } }; diff --git a/packages/crafty/src/bin.cjs b/packages/crafty/src/bin.cjs index 559f87d9b..7331f2c7f 100755 --- a/packages/crafty/src/bin.cjs +++ b/packages/crafty/src/bin.cjs @@ -29,7 +29,6 @@ configuration.getCrafty( // Get all possible commands const commands = getCommands(crafty); - try { // Run the user selected command const exitCode = await cli(crafty, commands) diff --git a/packages/integration/__tests__/crafty-preset-images-simple.js b/packages/integration/__tests__/crafty-preset-images-simple.js index ab0071516..139f7b316 100644 --- a/packages/integration/__tests__/crafty-preset-images-simple.js +++ b/packages/integration/__tests__/crafty-preset-images-simple.js @@ -21,7 +21,7 @@ test("Loads crafty-preset-images-simple and does not register gulp tasks", async t.deepEqual(Object.keys(crafty.undertaker._registry.tasks()), []); }); -test("Fails if both crafty-preset-images-simple and crafty-preset-images-simple are loaded", async t => { +test("Fails if both crafty-preset-images and crafty-preset-images-simple are loaded", async t => { const crafty = await getCrafty( [ "@swissquote/crafty-preset-images", @@ -39,8 +39,7 @@ test("Fails if both crafty-preset-images-simple and crafty-preset-images-simple t.truthy(loadedPresets.includes("@swissquote/crafty-runner-gulp")); t.throws(() => crafty.createTasks(), { - message: - "Failed registering 'crafty-preset-images-simple' a task with this name already exists" + message: /a task with this name already exists/ }); });