-
Notifications
You must be signed in to change notification settings - Fork 393
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(engine-dom): make feature flags work #2812
Changes from 9 commits
3799eb9
9f6afe1
43efa19
e2b74c9
76c66b6
72afdc0
79a41c8
8c08a6e
01c9664
a18f086
61f1eb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
import features from '@lwc/features'; | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
if (features.ENABLE_TEST_EXCEPTION) { | ||
throw new Error('Compile-time processing of feature flags is broken.'); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It'd be great if we didn't have to ship this code even in dev mode, but I can't think of a good way to add code that only matters for our Karma tests. I could also abstract this into a shared utility in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about adding a compilation-time feature flag that is forever configured to For example:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I think this is a much simpler solution than mine. Let's do it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah wait, except what this doesn't cover is if the features Babel plugin doesn't run at all. In that case, the flag will just silently not work, and no error will be thrown. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You know what, maybe that's fine, if a feature flag is not working in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reverted due to some confusion about what the tests were doing. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ const path = require('path'); | |
const { nodeResolve } = require('@rollup/plugin-node-resolve'); | ||
const typescript = require('../../../../scripts/rollup/typescript'); | ||
const writeDistAndTypes = require('../../../../scripts/rollup/writeDistAndTypes'); | ||
const lwcFeatures = require('../../../../scripts/rollup/lwcFeatures'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need the same change in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't bother to make this change for engine-server. I guess I should go ahead and do that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I could make the change to engine-server, but then the problem is that there's no way to test it. The karma tests don't test engine-server, and the unit tests use the I'll just make the change without a test. |
||
const { version } = require('../package.json'); | ||
|
||
const banner = `/* proxy-compat-disable */`; | ||
|
@@ -35,6 +36,7 @@ module.exports = { | |
}), | ||
typescript(), | ||
writeDistAndTypes(), | ||
lwcFeatures(), | ||
], | ||
|
||
onwarn({ code, message }) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
import features from '@lwc/features'; | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
if (features.ENABLE_TEST_EXCEPTION) { | ||
throw new Error('Compile-time processing of feature flags is broken.'); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright (c) 2018, salesforce.com, inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
|
||
import features from '@lwc/features'; | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
if (features.ENABLE_TEST_EXCEPTION) { | ||
throw new Error('Compile-time processing of feature flags is broken.'); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,13 @@ module.exports = function lwcFeatures() { | |
return { | ||
id: 'rollup-plugin-lwc-features', | ||
transform(source, id) { | ||
if (id.includes('/node_modules/') || !source.includes('@lwc/features')) { | ||
if ( | ||
id.includes('/node_modules/') || | ||
id.includes('/dist/') || | ||
!source.includes('@lwc/features') | ||
) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was the key to making the feature flags work. |
||
// Skip 3rd-party files and files that don't mention @lwc/features | ||
// Also skip /dist/ files because these have presumably already been run through lwcFeatures | ||
return null; | ||
} | ||
return babel.transform(source, { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this test designed to work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also had a question about this, when would
features.ENABLE_TEST_EXCEPTION
be set to true?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's never set to true. The point is just that, if the compilation pipeline is broken, then this will throw an error. It was previously throwing an error because
@lwc/engine-dom
's Rollup scripts were not configured properly.I can add a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was this throwing the error at runtime?
I tried to insert these statements and run
yarn build
locally and it didn't throw. Test Branch: https://github.com/salesforce/lwc/tree/ravi/test-feature-flagThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ravijayaramappa In your branch, the feature flags don't actually work. 🙂 If you try doing
setFeatureFlagForTest
then nothing will happen, because the LWC features Babel plugin is not being applied to the code.Whereas if you do apply the Babel plugin, it breaks because it runs twice on both
@lwc/engine-dom
and@lwc/engine-core
... that's what this PR is fixing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Thanks for clarifying.