From f7de0652a4a4c727a7943826235345444196b929 Mon Sep 17 00:00:00 2001 From: Jefferson Ribeiro Date: Thu, 15 Feb 2024 10:24:07 +0100 Subject: [PATCH] module level directive warning should not cause bundling to fail --- packages/pluggable-widgets-tools/CHANGELOG.md | 4 +++ .../configs/rollup.config.js | 28 +++++++++---------- .../pluggable-widgets-tools/package-lock.json | 4 +-- packages/pluggable-widgets-tools/package.json | 2 +- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/packages/pluggable-widgets-tools/CHANGELOG.md b/packages/pluggable-widgets-tools/CHANGELOG.md index 223a96d3..bb8dc5a3 100644 --- a/packages/pluggable-widgets-tools/CHANGELOG.md +++ b/packages/pluggable-widgets-tools/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +### Fixed + +- We fixed an issue where rollup warnings about `use client` and `use server` were causing bundling failures. + ## [10.7.0] - 2024-01-31 ### Changed diff --git a/packages/pluggable-widgets-tools/configs/rollup.config.js b/packages/pluggable-widgets-tools/configs/rollup.config.js index dc79c866..ca45fee0 100644 --- a/packages/pluggable-widgets-tools/configs/rollup.config.js +++ b/packages/pluggable-widgets-tools/configs/rollup.config.js @@ -9,7 +9,7 @@ import image from "@rollup/plugin-image"; import { nodeResolve } from "@rollup/plugin-node-resolve"; import replace from "rollup-plugin-re"; import typescript from "@rollup/plugin-typescript"; -import { red, yellow, blue } from "ansi-colors"; +import { red, blue } from "ansi-colors"; import postcssImport from "postcss-import"; import postcssUrl from "postcss-url"; import loadConfigFile from "rollup/dist/loadConfigFile"; @@ -280,8 +280,17 @@ export default async args => { ]; } - function onwarn(warning) { - const description = + function onwarn(warning, warn) { + if (warning.code === "MODULE_LEVEL_DIRECTIVE") return; + + // Many rollup warnings are indication of some critical issue, so we should treat them as errors, + // except a short white-list which we know is safe _and_ not easily fixable. + const safeWarnings = ["CIRCULAR_DEPENDENCY", "THIS_IS_UNDEFINED", "UNUSED_EXTERNAL_IMPORT"]; + if (safeWarnings.includes(warning.code)) { + return warn(warning); + } + + const error = (warning.plugin ? `(${warning.plugin} plugin) ` : "") + (warning.loc ? `${relative(sourcePath, warning.loc.file)} (${warning.loc.line}:${warning.loc.column}) ` @@ -289,17 +298,8 @@ export default async args => { `Error: ${warning.message}` + (warning.frame ? warning.frame : ""); - // Many rollup warnings are indication of some critical issue, so we should treat them as errors, - // except a short white-list which we know is safe _and_ not easily fixable. - if (["CIRCULAR_DEPENDENCY", "THIS_IS_UNDEFINED", "UNUSED_EXTERNAL_IMPORT"].includes(warning.code)) { - console.warn(yellow(description)); - } else if (args.watch) { - // Do not break watch mode because of an error. Also don't use console.error, since it is overwritten by rollup - console.warn(red(description)); - } else { - console.error(red(description)); - process.exit(1); - } + console.error(red(error)); + process.exit(1); } }; diff --git a/packages/pluggable-widgets-tools/package-lock.json b/packages/pluggable-widgets-tools/package-lock.json index fe2732a2..5e1b1060 100644 --- a/packages/pluggable-widgets-tools/package-lock.json +++ b/packages/pluggable-widgets-tools/package-lock.json @@ -1,12 +1,12 @@ { "name": "@mendix/pluggable-widgets-tools", - "version": "10.7.0", + "version": "10.7.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@mendix/pluggable-widgets-tools", - "version": "10.7.0", + "version": "10.7.1", "license": "Apache-2.0", "dependencies": { "@babel/core": "^7.12.3", diff --git a/packages/pluggable-widgets-tools/package.json b/packages/pluggable-widgets-tools/package.json index 37d61fa9..fe706b57 100644 --- a/packages/pluggable-widgets-tools/package.json +++ b/packages/pluggable-widgets-tools/package.json @@ -1,6 +1,6 @@ { "name": "@mendix/pluggable-widgets-tools", - "version": "10.7.0", + "version": "10.7.1", "description": "Mendix Pluggable Widgets Tools", "engines": { "node": ">=16"