Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add environment variable to disable LWC version mismatch loglines #5187

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export function checkVersionMismatch(
) {
const versionMatcher = func.toString().match(LWC_VERSION_COMMENT_REGEX);
if (!isNull(versionMatcher) && !warned) {
if (process?.env?.SKIP_LWC_VERSION_MISMATCH_CHECK === 'true') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process?.env
Are we expecting to encounter a scenario where the process variable is declared but null/undefined?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was just being extra cautious - I didn't know how things were compiled (and what is shipped to the browser vs whats available in server side engine). Didn't want to unintentionally break something for this one usecase.

warned = true; // skip printing out version mismatch errors when env var is set
return;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'd need a build-time complement to this environment variable. E.g. when we compile @lwc/engine-dom, this code path should turn into if (false) { and be minified away.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@divmain not super familiar with the lwc codebase, can you point me where to make this change?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@divmain is this the right place to do it?

function sharedPlugins() {
const engineBrowserConfig = ['@lwc/engine-server', '@lwc/engine-dom'].includes(packageName) && {
// This is only used inside @lwc/engine-dom and @lwc/engine-server
// Elsewhere, it _not_ be replaced, so that it can be replaced later (e.g. in @lwc/engine-core)
'process.env.IS_BROWSER': packageName === '@lwc/engine-dom' ? 'true' : 'false',
};
return [
typescript({
tsconfig: path.join(packageRoot, 'tsconfig.json'),
exclude: ['**/__tests__/**'],
noEmitOnError: !watchMode, // in watch mode, do not exit with an error if typechecking fails
...(watchMode && {
incremental: true,
outputToFilesystem: true,
}),
declarationDir: 'dist', // must match `output.file` in the overall Rollup config
}),
replace({
values: {
...engineBrowserConfig,
'process.env.LWC_VERSION': JSON.stringify(version),
},
preventAssignment: true,
}),
];
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the replace plugin is correct.


const version = versionMatcher[1];
if (version !== LWC_VERSION) {
warned = true; // only warn once to avoid flooding the console
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,27 @@ describe('compiler version mismatch', () => {
});

afterEach(() => {
process.env.SKIP_LWC_VERSION_MISMATCH_CHECK = 'false';
detachReportingControlDispatcher();
});

it('skip warning during local dev', () => {
process.env.SKIP_LWC_VERSION_MISMATCH_CHECK = 'true';
function tmpl() {
return [];
/*LWC compiler v123.456.789*/
}

expect(() => {
registerTemplate(tmpl);
}).not.toLogErrorDev(
new RegExp(
`LWC WARNING: current engine is v${process.env.LWC_VERSION}, but template was compiled with v123.456.789`
)
);
Comment on lines +64 to +68
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}).not.toLogErrorDev(
new RegExp(
`LWC WARNING: current engine is v${process.env.LWC_VERSION}, but template was compiled with v123.456.789`
)
);
}).not.toLogErrorDev(/v123\.456\.789/);

Checking that we're not logging such a long message feels easy to get an accidental false positive, if the error text ever changes. We should just check for keywords to be more flexible.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure I can make it more generic

expect(dispatcher).not.toHaveBeenCalled();
});

it('template', () => {
function tmpl() {
return [];
Expand Down
Loading