Skip to content

Commit 0831d2c

Browse files
johnjenkinsJohn Jenkins
andauthored
fix(rollup): proper warn handling (#6357)
Co-authored-by: John Jenkins <[email protected]>
1 parent 57f5683 commit 0831d2c

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/compiler/bundle/bundle-output.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,38 @@ export const getRollupOptions = (
7171
// Investigate if we can use this to leverage Stencil's in-memory fs
7272
};
7373

74+
// @ts-expect-error - this is required now.
75+
nodeResolvePlugin.warn = (log) => {
76+
const onWarn = createOnWarnFn(buildCtx.diagnostics);
77+
if (typeof log === 'string') {
78+
onWarn({ message: log });
79+
} else if (typeof log === 'function') {
80+
const result = log();
81+
if (typeof result === 'string') {
82+
onWarn({ message: result });
83+
} else {
84+
onWarn(result);
85+
}
86+
} else {
87+
onWarn(log);
88+
}
89+
};
90+
7491
assertIsObjectHook(nodeResolvePlugin.resolveId);
7592
// remove default 'post' order
7693
nodeResolvePlugin.resolveId.order = null;
7794
const orgNodeResolveId = nodeResolvePlugin.resolveId.handler;
95+
7896
const orgNodeResolveId2 = (nodeResolvePlugin.resolveId.handler = async function (importee: string, importer: string) {
7997
const [realImportee, query] = importee.split('?');
8098
const resolved = await orgNodeResolveId.call(
8199
nodeResolvePlugin as unknown as PluginContext,
82100
realImportee,
83101
importer,
84-
// @ts-expect-error - missing required properties but works in practice
85-
{},
102+
{
103+
attributes: {},
104+
isEntry: true,
105+
},
86106
);
87107
if (resolved) {
88108
if (isString(resolved)) {

test/wdio/global.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
// `stencil-sibling` test suite
44
import '@test-sibling';
55
import { setMode } from '@stencil/core';
6+
// @ts-expect-error - tests that rollup warnings don't break the build
7+
import { setAssetPath } from '@stencil/core/internal/client/index';
68

79
const globalScript = () => {
810
setMode((elm) => {
911
return (elm as any).colormode || elm.getAttribute('colormode');
1012
});
1113
};
1214

15+
// this doesn't do anything - just stops rollup removing the import
16+
setAssetPath('/base/path');
17+
1318
export default globalScript;

0 commit comments

Comments
 (0)