@stencil/angular-output-target 0.6.1-dev.11650990404.1c4facf3 → 0.6.1-dev.11655483906.1e51ded4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { dashToPascalCase, normalizePath } from './utils';
1
+ import { dashToPascalCase, formatCustomEventInterfaceName, normalizePath } from './utils';
2
2
  export const createComponentDefinition = (componentCorePackage, distTypesDir, rootDir, includeImportCustomElements = false, customElementsDir = 'components') => (cmpMeta) => {
3
3
  // Collect component meta
4
4
  const inputs = [
@@ -59,7 +59,13 @@ export const createComponentDefinition = (componentCorePackage, distTypesDir, ro
59
59
  .replace(/\n/g, ' ')
60
60
  .replace(/\s{2,}/g, ' ')
61
61
  .replace(/,\s*/g, ', '));
62
- componentEvents.push(` ${output.name}: EventEmitter<CustomEvent<${outputTypeRemapped.trim()}>>;`);
62
+ /**
63
+ * Starting in Stencil 2.16.0, the compiler will generate a CustomEvent interface
64
+ * for each component with custom events.
65
+ *
66
+ * The name of this custom event is "ComponentTagNameCustomEvent".
67
+ */
68
+ componentEvents.push(` ${output.name}: EventEmitter<${formatCustomEventInterfaceName(cmpMeta.tagName)}<${outputTypeRemapped.trim()}>>;`);
63
69
  if (index === outputs.length - 1) {
64
70
  // Empty line to push end `}` to new line
65
71
  componentEvents.push('\n');
package/dist/index.cjs.js CHANGED
@@ -81,6 +81,16 @@ async function readPackageJson(config, rootDir) {
81
81
  }
82
82
  return pkgData;
83
83
  }
84
+ /**
85
+ * Returns the formatted custom event interface name for the component.
86
+ * With a tag of "my-cmp", it will return "MyCmpCustomEvent".
87
+ *
88
+ * @param componentTagName The tag selector of the component (i.e. my-cmp)
89
+ * @returns The formatted custom event interface name.
90
+ */
91
+ function formatCustomEventInterfaceName(componentTagName) {
92
+ return `${dashToPascalCase(componentTagName)}CustomEvent`;
93
+ }
84
94
  const EXTENDED_PATH_REGEX = /^\\\\\?\\/;
85
95
  const NON_ASCII_REGEX = /[^\x00-\x80]+/;
86
96
  const SLASH_REGEX = /\\/g;
@@ -145,7 +155,13 @@ const createComponentDefinition = (componentCorePackage, distTypesDir, rootDir,
145
155
  .replace(/\n/g, ' ')
146
156
  .replace(/\s{2,}/g, ' ')
147
157
  .replace(/,\s*/g, ', '));
148
- componentEvents.push(` ${output.name}: EventEmitter<CustomEvent<${outputTypeRemapped.trim()}>>;`);
158
+ /**
159
+ * Starting in Stencil 2.16.0, the compiler will generate a CustomEvent interface
160
+ * for each component with custom events.
161
+ *
162
+ * The name of this custom event is "ComponentTagNameCustomEvent".
163
+ */
164
+ componentEvents.push(` ${output.name}: EventEmitter<${formatCustomEventInterfaceName(cmpMeta.tagName)}<${outputTypeRemapped.trim()}>>;`);
149
165
  if (index === outputs.length - 1) {
150
166
  // Empty line to push end `}` to new line
151
167
  componentEvents.push('\n');
@@ -302,6 +318,7 @@ function generateProxies(components, pkgData, outputTarget, rootDir) {
302
318
  /* auto-generated angular directive proxies */
303
319
  import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, NgZone } from '@angular/core';
304
320
  import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
321
+ const importLocation = getImportPackageName(outputTarget, componentsTypeFile);
305
322
  /**
306
323
  * Generate JSX import type from correct location.
307
324
  * When using custom elements build, we need to import from
@@ -309,11 +326,21 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
309
326
  * otherwise we risk bundlers pulling in lazy loaded imports.
310
327
  */
311
328
  const generateTypeImports = () => {
312
- let importLocation = outputTarget.componentCorePackage ? normalizePath(outputTarget.componentCorePackage) : normalizePath(componentsTypeFile);
313
- importLocation += outputTarget.includeImportCustomElements ? `/${outputTarget.customElementsDir || 'components'}` : '';
314
329
  return `import ${outputTarget.includeImportCustomElements ? 'type ' : ''}{ ${IMPORT_TYPES} } from '${importLocation}';\n`;
315
330
  };
316
- const typeImports = generateTypeImports();
331
+ /**
332
+ * Components that have custom events have uniquely generated interfaces as of
333
+ * Stencil 2.16.0. We import these interfaces so they can be used in the generate
334
+ * functions for the @Output() events.
335
+ */
336
+ const customEventInterfaces = components.filter(c => c.events.filter(e => !e.internal).length > 0).map(c => {
337
+ return formatCustomEventInterfaceName(c.tagName);
338
+ });
339
+ const customEventImports = `import type { ${customEventInterfaces.join(', ')} } from '${importLocation}';\n`;
340
+ const typeImports = [
341
+ generateTypeImports(),
342
+ customEventImports,
343
+ ];
317
344
  let sourceImports = '';
318
345
  /**
319
346
  * Build an array of Custom Elements build imports and namespace them
@@ -331,7 +358,7 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
331
358
  }
332
359
  const final = [
333
360
  imports,
334
- typeImports,
361
+ typeImports.join('\n'),
335
362
  sourceImports,
336
363
  components
337
364
  .map(createComponentDefinition(outputTarget.componentCorePackage, distTypesDir, rootDir, outputTarget.includeImportCustomElements, outputTarget.customElementsDir))
@@ -339,6 +366,14 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
339
366
  ];
340
367
  return final.join('\n') + '\n';
341
368
  }
369
+ /**
370
+ * Returns the path to import the file from.
371
+ */
372
+ const getImportPackageName = (outputTarget, componentsTypeFile) => {
373
+ let importLocation = outputTarget.componentCorePackage ? normalizePath(outputTarget.componentCorePackage) : normalizePath(componentsTypeFile);
374
+ importLocation += outputTarget.includeImportCustomElements ? `/${outputTarget.customElementsDir || 'components'}` : '';
375
+ return importLocation;
376
+ };
342
377
  const GENERATED_DTS = 'components.d.ts';
343
378
  const IMPORT_TYPES = 'Components';
344
379
 
package/dist/index.js CHANGED
@@ -73,6 +73,16 @@ async function readPackageJson(config, rootDir) {
73
73
  }
74
74
  return pkgData;
75
75
  }
76
+ /**
77
+ * Returns the formatted custom event interface name for the component.
78
+ * With a tag of "my-cmp", it will return "MyCmpCustomEvent".
79
+ *
80
+ * @param componentTagName The tag selector of the component (i.e. my-cmp)
81
+ * @returns The formatted custom event interface name.
82
+ */
83
+ function formatCustomEventInterfaceName(componentTagName) {
84
+ return `${dashToPascalCase(componentTagName)}CustomEvent`;
85
+ }
76
86
  const EXTENDED_PATH_REGEX = /^\\\\\?\\/;
77
87
  const NON_ASCII_REGEX = /[^\x00-\x80]+/;
78
88
  const SLASH_REGEX = /\\/g;
@@ -137,7 +147,13 @@ const createComponentDefinition = (componentCorePackage, distTypesDir, rootDir,
137
147
  .replace(/\n/g, ' ')
138
148
  .replace(/\s{2,}/g, ' ')
139
149
  .replace(/,\s*/g, ', '));
140
- componentEvents.push(` ${output.name}: EventEmitter<CustomEvent<${outputTypeRemapped.trim()}>>;`);
150
+ /**
151
+ * Starting in Stencil 2.16.0, the compiler will generate a CustomEvent interface
152
+ * for each component with custom events.
153
+ *
154
+ * The name of this custom event is "ComponentTagNameCustomEvent".
155
+ */
156
+ componentEvents.push(` ${output.name}: EventEmitter<${formatCustomEventInterfaceName(cmpMeta.tagName)}<${outputTypeRemapped.trim()}>>;`);
141
157
  if (index === outputs.length - 1) {
142
158
  // Empty line to push end `}` to new line
143
159
  componentEvents.push('\n');
@@ -294,6 +310,7 @@ function generateProxies(components, pkgData, outputTarget, rootDir) {
294
310
  /* auto-generated angular directive proxies */
295
311
  import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, NgZone } from '@angular/core';
296
312
  import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
313
+ const importLocation = getImportPackageName(outputTarget, componentsTypeFile);
297
314
  /**
298
315
  * Generate JSX import type from correct location.
299
316
  * When using custom elements build, we need to import from
@@ -301,11 +318,21 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
301
318
  * otherwise we risk bundlers pulling in lazy loaded imports.
302
319
  */
303
320
  const generateTypeImports = () => {
304
- let importLocation = outputTarget.componentCorePackage ? normalizePath(outputTarget.componentCorePackage) : normalizePath(componentsTypeFile);
305
- importLocation += outputTarget.includeImportCustomElements ? `/${outputTarget.customElementsDir || 'components'}` : '';
306
321
  return `import ${outputTarget.includeImportCustomElements ? 'type ' : ''}{ ${IMPORT_TYPES} } from '${importLocation}';\n`;
307
322
  };
308
- const typeImports = generateTypeImports();
323
+ /**
324
+ * Components that have custom events have uniquely generated interfaces as of
325
+ * Stencil 2.16.0. We import these interfaces so they can be used in the generate
326
+ * functions for the @Output() events.
327
+ */
328
+ const customEventInterfaces = components.filter(c => c.events.filter(e => !e.internal).length > 0).map(c => {
329
+ return formatCustomEventInterfaceName(c.tagName);
330
+ });
331
+ const customEventImports = `import type { ${customEventInterfaces.join(', ')} } from '${importLocation}';\n`;
332
+ const typeImports = [
333
+ generateTypeImports(),
334
+ customEventImports,
335
+ ];
309
336
  let sourceImports = '';
310
337
  /**
311
338
  * Build an array of Custom Elements build imports and namespace them
@@ -323,7 +350,7 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
323
350
  }
324
351
  const final = [
325
352
  imports,
326
- typeImports,
353
+ typeImports.join('\n'),
327
354
  sourceImports,
328
355
  components
329
356
  .map(createComponentDefinition(outputTarget.componentCorePackage, distTypesDir, rootDir, outputTarget.includeImportCustomElements, outputTarget.customElementsDir))
@@ -331,6 +358,14 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
331
358
  ];
332
359
  return final.join('\n') + '\n';
333
360
  }
361
+ /**
362
+ * Returns the path to import the file from.
363
+ */
364
+ const getImportPackageName = (outputTarget, componentsTypeFile) => {
365
+ let importLocation = outputTarget.componentCorePackage ? normalizePath(outputTarget.componentCorePackage) : normalizePath(componentsTypeFile);
366
+ importLocation += outputTarget.includeImportCustomElements ? `/${outputTarget.customElementsDir || 'components'}` : '';
367
+ return importLocation;
368
+ };
334
369
  const GENERATED_DTS = 'components.d.ts';
335
370
  const IMPORT_TYPES = 'Components';
336
371
 
@@ -1,5 +1,5 @@
1
1
  import path from 'path';
2
- import { relativeImport, normalizePath, sortBy, readPackageJson, dashToPascalCase } from './utils';
2
+ import { relativeImport, normalizePath, sortBy, readPackageJson, dashToPascalCase, formatCustomEventInterfaceName } from './utils';
3
3
  import { createComponentDefinition } from './generate-angular-component';
4
4
  import { generateAngularDirectivesFile } from './generate-angular-directives-file';
5
5
  import generateValueAccessors from './generate-value-accessors';
@@ -41,6 +41,7 @@ export function generateProxies(components, pkgData, outputTarget, rootDir) {
41
41
  /* auto-generated angular directive proxies */
42
42
  import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, NgZone } from '@angular/core';
43
43
  import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
44
+ const importLocation = getImportPackageName(outputTarget, componentsTypeFile);
44
45
  /**
45
46
  * Generate JSX import type from correct location.
46
47
  * When using custom elements build, we need to import from
@@ -48,11 +49,21 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
48
49
  * otherwise we risk bundlers pulling in lazy loaded imports.
49
50
  */
50
51
  const generateTypeImports = () => {
51
- let importLocation = outputTarget.componentCorePackage ? normalizePath(outputTarget.componentCorePackage) : normalizePath(componentsTypeFile);
52
- importLocation += outputTarget.includeImportCustomElements ? `/${outputTarget.customElementsDir || 'components'}` : '';
53
52
  return `import ${outputTarget.includeImportCustomElements ? 'type ' : ''}{ ${IMPORT_TYPES} } from '${importLocation}';\n`;
54
53
  };
55
- const typeImports = generateTypeImports();
54
+ /**
55
+ * Components that have custom events have uniquely generated interfaces as of
56
+ * Stencil 2.16.0. We import these interfaces so they can be used in the generate
57
+ * functions for the @Output() events.
58
+ */
59
+ const customEventInterfaces = components.filter(c => c.events.filter(e => !e.internal).length > 0).map(c => {
60
+ return formatCustomEventInterfaceName(c.tagName);
61
+ });
62
+ const customEventImports = `import type { ${customEventInterfaces.join(', ')} } from '${importLocation}';\n`;
63
+ const typeImports = [
64
+ generateTypeImports(),
65
+ customEventImports,
66
+ ];
56
67
  let sourceImports = '';
57
68
  /**
58
69
  * Build an array of Custom Elements build imports and namespace them
@@ -70,7 +81,7 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
70
81
  }
71
82
  const final = [
72
83
  imports,
73
- typeImports,
84
+ typeImports.join('\n'),
74
85
  sourceImports,
75
86
  components
76
87
  .map(createComponentDefinition(outputTarget.componentCorePackage, distTypesDir, rootDir, outputTarget.includeImportCustomElements, outputTarget.customElementsDir))
@@ -78,5 +89,13 @@ import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;
78
89
  ];
79
90
  return final.join('\n') + '\n';
80
91
  }
92
+ /**
93
+ * Returns the path to import the file from.
94
+ */
95
+ const getImportPackageName = (outputTarget, componentsTypeFile) => {
96
+ let importLocation = outputTarget.componentCorePackage ? normalizePath(outputTarget.componentCorePackage) : normalizePath(componentsTypeFile);
97
+ importLocation += outputTarget.includeImportCustomElements ? `/${outputTarget.customElementsDir || 'components'}` : '';
98
+ return importLocation;
99
+ };
81
100
  const GENERATED_DTS = 'components.d.ts';
82
101
  const IMPORT_TYPES = 'Components';
package/dist/utils.d.ts CHANGED
@@ -7,3 +7,11 @@ export declare function normalizePath(str: string): string;
7
7
  export declare function relativeImport(pathFrom: string, pathTo: string, ext?: string): string;
8
8
  export declare function isRelativePath(path: string): boolean | "";
9
9
  export declare function readPackageJson(config: Config, rootDir: string): Promise<PackageJSON>;
10
+ /**
11
+ * Returns the formatted custom event interface name for the component.
12
+ * With a tag of "my-cmp", it will return "MyCmpCustomEvent".
13
+ *
14
+ * @param componentTagName The tag selector of the component (i.e. my-cmp)
15
+ * @returns The formatted custom event interface name.
16
+ */
17
+ export declare function formatCustomEventInterfaceName(componentTagName: string): string;
package/dist/utils.js CHANGED
@@ -74,6 +74,16 @@ export async function readPackageJson(config, rootDir) {
74
74
  }
75
75
  return pkgData;
76
76
  }
77
+ /**
78
+ * Returns the formatted custom event interface name for the component.
79
+ * With a tag of "my-cmp", it will return "MyCmpCustomEvent".
80
+ *
81
+ * @param componentTagName The tag selector of the component (i.e. my-cmp)
82
+ * @returns The formatted custom event interface name.
83
+ */
84
+ export function formatCustomEventInterfaceName(componentTagName) {
85
+ return `${dashToPascalCase(componentTagName)}CustomEvent`;
86
+ }
77
87
  const EXTENDED_PATH_REGEX = /^\\\\\?\\/;
78
88
  const NON_ASCII_REGEX = /[^\x00-\x80]+/;
79
89
  const SLASH_REGEX = /\\/g;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stencil/angular-output-target",
3
- "version": "0.6.1-dev.11650990404.1c4facf3",
3
+ "version": "0.6.1-dev.11655483906.1e51ded4",
4
4
  "description": "Angular output target for @stencil/core components.",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.js",
@@ -39,7 +39,7 @@
39
39
  "@angular/forms": "8.2.14"
40
40
  },
41
41
  "peerDependencies": {
42
- "@stencil/core": "^2.9.0"
42
+ "@stencil/core": "^2.16.0"
43
43
  },
44
44
  "jest": {
45
45
  "transform": {
@@ -55,5 +55,5 @@
55
55
  ],
56
56
  "testURL": "http://localhost"
57
57
  },
58
- "gitHead": "c4facf34607b1500dd33dd5c5d1ba5685edd90d4"
58
+ "gitHead": "e51ded46a46fbcd7d0f191a9dc237bef362aab9f"
59
59
  }