Skip to content

Commit

Permalink
module level directive warning should not cause bundling to fail
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffersonRibeiro committed Feb 15, 2024
1 parent eca364c commit f7de065
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
4 changes: 4 additions & 0 deletions packages/pluggable-widgets-tools/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions packages/pluggable-widgets-tools/configs/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -280,26 +280,26 @@ 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}) `
: "") +
`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);
}
};

Expand Down
4 changes: 2 additions & 2 deletions packages/pluggable-widgets-tools/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/pluggable-widgets-tools/package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit f7de065

Please sign in to comment.