Skip to content

Commit b8ed386

Browse files
tanner-reitsrwaskiewicz
authored andcommitted
feat(compiler): moves autoDefineCustomElements to an export behavior (#3615)
This commit moves `autoDefineCustomElements` from a config flag to a `customElementsExportBehavior` option on the `dist-custom-elements` output target. This prevents treeshaking issues that were possible when barrel exporting and this option were both enabled. This is some initial work before we move into STENCIL-457
1 parent 8158b88 commit b8ed386

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

src/cli/telemetry/test/telemetry.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ describe('anonymizeConfigForTelemetry', () => {
286286
outputTargets: [
287287
{ type: WWW, baseUrl: 'https://example.com' },
288288
{ type: DIST_HYDRATE_SCRIPT, external: ['beep', 'boop'], dir: 'shoud/go/away' },
289-
{ type: DIST_CUSTOM_ELEMENTS, autoDefineCustomElements: false },
289+
{ type: DIST_CUSTOM_ELEMENTS },
290290
{ type: DIST_CUSTOM_ELEMENTS, generateTypeDeclarations: true },
291291
{ type: DIST, typesDir: 'my-types' },
292292
],
@@ -295,7 +295,7 @@ describe('anonymizeConfigForTelemetry', () => {
295295
expect(anonymizedConfig.outputTargets).toEqual([
296296
{ type: WWW, baseUrl: 'omitted' },
297297
{ type: DIST_HYDRATE_SCRIPT, external: ['beep', 'boop'], dir: 'omitted' },
298-
{ type: DIST_CUSTOM_ELEMENTS, autoDefineCustomElements: false },
298+
{ type: DIST_CUSTOM_ELEMENTS },
299299
{ type: DIST_CUSTOM_ELEMENTS, generateTypeDeclarations: true },
300300
{ type: DIST, typesDir: 'omitted' },
301301
]);

src/compiler/transformers/component-native/add-define-custom-element-function.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const addDefineCustomElementFunctions = (
4242
setupComponentDependencies(moduleFile, components, newStatements, caseStatements, tagNames);
4343
addDefineCustomElementFunction(tagNames, newStatements, caseStatements);
4444

45-
if (outputTarget.autoDefineCustomElements) {
45+
if (outputTarget.customElementsExportBehavior === 'auto-define-custom-elements') {
4646
const conditionalDefineCustomElementCall = createAutoDefinitionExpression(
4747
principalComponent.componentClassName
4848
);

src/declarations/stencil-public-compiler.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,9 +2032,16 @@ export interface OutputTargetBaseNext {
20322032
* output target configuration for `customElementsExportBehavior`.
20332033
*
20342034
* - `default`: No additional export or definition behavior will happen.
2035+
* - `auto-define-custom-elements`: Enables the auto-definition of a component and its children (recursively) in the custom elements registry. This
2036+
* functionality allows consumers to bypass the explicit call to define a component, its children, its children's
2037+
* children, etc. Users of this flag should be aware that enabling this functionality may increase bundle size.
20352038
* - `single-export-module`: All components will be re-exported from the specified directory's root `index.js` file.
20362039
*/
2037-
export const CustomElementsExportBehaviorOptions = ['default', 'single-export-module'] as const;
2040+
export const CustomElementsExportBehaviorOptions = [
2041+
'default',
2042+
'auto-define-custom-elements',
2043+
'single-export-module',
2044+
] as const;
20382045

20392046
/**
20402047
* This type is auto-generated based on the values in `CustomElementsExportBehaviorOptions` array.
@@ -2056,12 +2063,6 @@ export interface OutputTargetDistCustomElements extends OutputTargetBaseNext {
20562063
inlineDynamicImports?: boolean;
20572064
includeGlobalScripts?: boolean;
20582065
minify?: boolean;
2059-
/**
2060-
* Enables the auto-definition of a component and its children (recursively) in the custom elements registry. This
2061-
* functionality allows consumers to bypass the explicit call to define a component, its children, its children's
2062-
* children, etc. Users of this flag should be aware that enabling this functionality may increase bundle size.
2063-
*/
2064-
autoDefineCustomElements?: boolean;
20652066
/**
20662067
* Enables the generation of type definition files for the output target.
20672068
*/

0 commit comments

Comments
 (0)