@stencil/angular-output-target 1.5.1 → 1.5.3
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.
- package/dist/generate-angular-component.d.ts +2 -2
- package/dist/generate-angular-component.js +3 -3
- package/dist/index.cjs +22 -17
- package/dist/index.js +22 -17
- package/dist/output-angular.d.ts +1 -1
- package/dist/output-angular.js +18 -11
- package/dist/utils.d.ts +5 -2
- package/dist/utils.js +1 -3
- package/dist/wizard.js +47 -6
- package/package.json +3 -3
|
@@ -25,7 +25,7 @@ export declare const createAngularComponentDefinition: (tagName: string, inputs:
|
|
|
25
25
|
* @param events The events to generate the interface properties for.
|
|
26
26
|
* @param componentCorePackage The component core package.
|
|
27
27
|
* @param customElementsDir The custom elements directory.
|
|
28
|
-
* @param
|
|
28
|
+
* @param typesModule The module every component type is imported from (Stencil v5 only).
|
|
29
29
|
* @returns The component interface type definition as a string.
|
|
30
30
|
*/
|
|
31
|
-
export declare const createComponentTypeDefinition: (outputType: OutputType, tagNameAsPascal: string, events: readonly ComponentCompilerEvent[], componentCorePackage: string, customElementsDir?: string,
|
|
31
|
+
export declare const createComponentTypeDefinition: (outputType: OutputType, tagNameAsPascal: string, events: readonly ComponentCompilerEvent[], componentCorePackage: string, customElementsDir?: string, typesModule?: string) => string;
|
|
@@ -212,16 +212,16 @@ const createDocComment = (doc) => {
|
|
|
212
212
|
* @param events The events to generate the interface properties for.
|
|
213
213
|
* @param componentCorePackage The component core package.
|
|
214
214
|
* @param customElementsDir The custom elements directory.
|
|
215
|
-
* @param
|
|
215
|
+
* @param typesModule The module every component type is imported from (Stencil v5 only).
|
|
216
216
|
* @returns The component interface type definition as a string.
|
|
217
217
|
*/
|
|
218
|
-
export const createComponentTypeDefinition = (outputType, tagNameAsPascal, events, componentCorePackage, customElementsDir,
|
|
218
|
+
export const createComponentTypeDefinition = (outputType, tagNameAsPascal, events, componentCorePackage, customElementsDir, typesModule) => {
|
|
219
219
|
const publicEvents = events.filter((ev) => !ev.internal);
|
|
220
220
|
const eventTypeImports = createComponentEventTypeImports(tagNameAsPascal, publicEvents, {
|
|
221
221
|
componentCorePackage,
|
|
222
222
|
customElementsDir,
|
|
223
223
|
outputType,
|
|
224
|
-
|
|
224
|
+
typesModule,
|
|
225
225
|
});
|
|
226
226
|
const eventTypes = publicEvents.map((event) => createPropertyDeclaration(event, `EventEmitter<${tagNameAsPascal}CustomEvent<${formatOutputType(tagNameAsPascal, event)}>>`));
|
|
227
227
|
const interfaceDeclaration = `export declare interface ${tagNameAsPascal} extends Components.${tagNameAsPascal} {`;
|
package/dist/index.cjs
CHANGED
|
@@ -126,9 +126,7 @@ const createComponentEventTypeImports = (componentTagName, events, options) => {
|
|
|
126
126
|
const imports = [];
|
|
127
127
|
const namedImports = new Set();
|
|
128
128
|
const isCustomElementsBuild = isOutputTypeCustomElementsBuild(options.outputType);
|
|
129
|
-
const
|
|
130
|
-
const importPathName = normalizePath(componentCorePackage) +
|
|
131
|
-
(options.exportMaps ? exportMapEntry : isCustomElementsBuild ? `/${customElementsDir}` : '');
|
|
129
|
+
const importPathName = options.typesModule ?? normalizePath(componentCorePackage) + (isCustomElementsBuild ? `/${customElementsDir}` : '');
|
|
132
130
|
/**
|
|
133
131
|
* Each component's events are typed with the per-component CustomEvent type
|
|
134
132
|
* generated by Stencil (e.g. `MyComponentCustomEvent<Detail>`), which carries a
|
|
@@ -368,16 +366,16 @@ const createDocComment = (doc) => {
|
|
|
368
366
|
* @param events The events to generate the interface properties for.
|
|
369
367
|
* @param componentCorePackage The component core package.
|
|
370
368
|
* @param customElementsDir The custom elements directory.
|
|
371
|
-
* @param
|
|
369
|
+
* @param typesModule The module every component type is imported from (Stencil v5 only).
|
|
372
370
|
* @returns The component interface type definition as a string.
|
|
373
371
|
*/
|
|
374
|
-
const createComponentTypeDefinition = (outputType, tagNameAsPascal, events, componentCorePackage, customElementsDir,
|
|
372
|
+
const createComponentTypeDefinition = (outputType, tagNameAsPascal, events, componentCorePackage, customElementsDir, typesModule) => {
|
|
375
373
|
const publicEvents = events.filter((ev) => !ev.internal);
|
|
376
374
|
const eventTypeImports = createComponentEventTypeImports(tagNameAsPascal, publicEvents, {
|
|
377
375
|
componentCorePackage,
|
|
378
376
|
customElementsDir,
|
|
379
377
|
outputType,
|
|
380
|
-
|
|
378
|
+
typesModule,
|
|
381
379
|
});
|
|
382
380
|
const eventTypes = publicEvents.map((event) => createPropertyDeclaration(event, `EventEmitter<${tagNameAsPascal}CustomEvent<${formatOutputType(tagNameAsPascal, event)}>>`));
|
|
383
381
|
const interfaceDeclaration = `export declare interface ${tagNameAsPascal} extends Components.${tagNameAsPascal} {`;
|
|
@@ -843,13 +841,22 @@ const usesInputTransform = (components, booleanAttributes) => components.some((c
|
|
|
843
841
|
/**
|
|
844
842
|
* Whether the Stencil project generates a package.json `exports` map. Deep `dist/` imports are
|
|
845
843
|
* blocked for consumers then, so the proxies import through the map's entries instead
|
|
846
|
-
* (`<pkg>/<tag>`, `<pkg>/
|
|
844
|
+
* (`<pkg>/<tag>`, `<pkg>/components`, `<pkg>/standalone`).
|
|
847
845
|
*/
|
|
848
846
|
function usesExportMaps(config) {
|
|
849
|
-
// Stencil v5 only: v4's map has no `./standalone` entry
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
847
|
+
// Stencil v5 only: v4's map has no `./components` or `./standalone` entry.
|
|
848
|
+
return isStencilV5(config) && config.generateExportMaps === true;
|
|
849
|
+
}
|
|
850
|
+
function isStencilV5(config) {
|
|
851
|
+
return (config.outputTargets || []).some((o) => ['loader-bundle', 'standalone', 'ssr', 'types'].includes(o.type));
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* For Stencil v5 only, use the `types/components.d.ts`
|
|
855
|
+
*/
|
|
856
|
+
function getEventTypesModule(config, outputTarget) {
|
|
857
|
+
return isStencilV5(config) && outputTarget.componentCorePackage
|
|
858
|
+
? getPathToComponentTypes(config, outputTarget)
|
|
859
|
+
: undefined;
|
|
853
860
|
}
|
|
854
861
|
/**
|
|
855
862
|
* The module specifier a proxy imports a component's `defineCustomElement` from.
|
|
@@ -1012,7 +1019,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
1012
1019
|
*/
|
|
1013
1020
|
const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, orderedInputs, methods, isCustomElementsBuild, isStandaloneBuild, inlineComponentProps, cmpMeta.events || []);
|
|
1014
1021
|
const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
|
|
1015
|
-
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir,
|
|
1022
|
+
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir, getEventTypesModule(config, outputTarget));
|
|
1016
1023
|
proxyFileOutput.push(componentDefinition, '\n');
|
|
1017
1024
|
if (includeSingleComponentAngularModules) {
|
|
1018
1025
|
proxyFileOutput.push(moduleDefinition, '\n');
|
|
@@ -1079,7 +1086,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
1079
1086
|
const inlineComponentProps = outputTarget.inlineProperties ? internalProps : [];
|
|
1080
1087
|
const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, orderedInputs, methods, isCustomElementsBuild, isStandaloneBuild, inlineComponentProps, cmpMeta.events || []);
|
|
1081
1088
|
const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
|
|
1082
|
-
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir,
|
|
1089
|
+
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir, getEventTypesModule(config, outputTarget));
|
|
1083
1090
|
const proxyFileOutput = [componentDefinition, '\n'];
|
|
1084
1091
|
if (includeSingleComponentAngularModules) {
|
|
1085
1092
|
proxyFileOutput.push(moduleDefinition, '\n');
|
|
@@ -1110,11 +1117,9 @@ function generateBarrelFile(components, outputTarget) {
|
|
|
1110
1117
|
}
|
|
1111
1118
|
function getPathToComponentTypes(config, outputTarget) {
|
|
1112
1119
|
const basePkg = outputTarget.componentCorePackage || '';
|
|
1113
|
-
//
|
|
1114
|
-
// package root only does when the project has no `src/index.ts`, or that file re-exports them
|
|
1120
|
+
// for Stencil v5 use the `<pkg>/components` export entry when `generateExportMaps` is enabled
|
|
1115
1121
|
if (usesExportMaps(config)) {
|
|
1116
|
-
|
|
1117
|
-
return `${normalizePath(basePkg)}/${entry}`;
|
|
1122
|
+
return `${normalizePath(basePkg)}/components`;
|
|
1118
1123
|
}
|
|
1119
1124
|
// in v5, all types (including components.d.ts) are generated in the dist/types directory
|
|
1120
1125
|
const typesTarget = config.outputTargets?.find((o) => o.type === 'types');
|
package/dist/index.js
CHANGED
|
@@ -118,9 +118,7 @@ const createComponentEventTypeImports = (componentTagName, events, options) => {
|
|
|
118
118
|
const imports = [];
|
|
119
119
|
const namedImports = new Set();
|
|
120
120
|
const isCustomElementsBuild = isOutputTypeCustomElementsBuild(options.outputType);
|
|
121
|
-
const
|
|
122
|
-
const importPathName = normalizePath(componentCorePackage) +
|
|
123
|
-
(options.exportMaps ? exportMapEntry : isCustomElementsBuild ? `/${customElementsDir}` : '');
|
|
121
|
+
const importPathName = options.typesModule ?? normalizePath(componentCorePackage) + (isCustomElementsBuild ? `/${customElementsDir}` : '');
|
|
124
122
|
/**
|
|
125
123
|
* Each component's events are typed with the per-component CustomEvent type
|
|
126
124
|
* generated by Stencil (e.g. `MyComponentCustomEvent<Detail>`), which carries a
|
|
@@ -360,16 +358,16 @@ const createDocComment = (doc) => {
|
|
|
360
358
|
* @param events The events to generate the interface properties for.
|
|
361
359
|
* @param componentCorePackage The component core package.
|
|
362
360
|
* @param customElementsDir The custom elements directory.
|
|
363
|
-
* @param
|
|
361
|
+
* @param typesModule The module every component type is imported from (Stencil v5 only).
|
|
364
362
|
* @returns The component interface type definition as a string.
|
|
365
363
|
*/
|
|
366
|
-
const createComponentTypeDefinition = (outputType, tagNameAsPascal, events, componentCorePackage, customElementsDir,
|
|
364
|
+
const createComponentTypeDefinition = (outputType, tagNameAsPascal, events, componentCorePackage, customElementsDir, typesModule) => {
|
|
367
365
|
const publicEvents = events.filter((ev) => !ev.internal);
|
|
368
366
|
const eventTypeImports = createComponentEventTypeImports(tagNameAsPascal, publicEvents, {
|
|
369
367
|
componentCorePackage,
|
|
370
368
|
customElementsDir,
|
|
371
369
|
outputType,
|
|
372
|
-
|
|
370
|
+
typesModule,
|
|
373
371
|
});
|
|
374
372
|
const eventTypes = publicEvents.map((event) => createPropertyDeclaration(event, `EventEmitter<${tagNameAsPascal}CustomEvent<${formatOutputType(tagNameAsPascal, event)}>>`));
|
|
375
373
|
const interfaceDeclaration = `export declare interface ${tagNameAsPascal} extends Components.${tagNameAsPascal} {`;
|
|
@@ -835,13 +833,22 @@ const usesInputTransform = (components, booleanAttributes) => components.some((c
|
|
|
835
833
|
/**
|
|
836
834
|
* Whether the Stencil project generates a package.json `exports` map. Deep `dist/` imports are
|
|
837
835
|
* blocked for consumers then, so the proxies import through the map's entries instead
|
|
838
|
-
* (`<pkg>/<tag>`, `<pkg>/
|
|
836
|
+
* (`<pkg>/<tag>`, `<pkg>/components`, `<pkg>/standalone`).
|
|
839
837
|
*/
|
|
840
838
|
function usesExportMaps(config) {
|
|
841
|
-
// Stencil v5 only: v4's map has no `./standalone` entry
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
839
|
+
// Stencil v5 only: v4's map has no `./components` or `./standalone` entry.
|
|
840
|
+
return isStencilV5(config) && config.generateExportMaps === true;
|
|
841
|
+
}
|
|
842
|
+
function isStencilV5(config) {
|
|
843
|
+
return (config.outputTargets || []).some((o) => ['loader-bundle', 'standalone', 'ssr', 'types'].includes(o.type));
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* For Stencil v5 only, use the `types/components.d.ts`
|
|
847
|
+
*/
|
|
848
|
+
function getEventTypesModule(config, outputTarget) {
|
|
849
|
+
return isStencilV5(config) && outputTarget.componentCorePackage
|
|
850
|
+
? getPathToComponentTypes(config, outputTarget)
|
|
851
|
+
: undefined;
|
|
845
852
|
}
|
|
846
853
|
/**
|
|
847
854
|
* The module specifier a proxy imports a component's `defineCustomElement` from.
|
|
@@ -1004,7 +1011,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
1004
1011
|
*/
|
|
1005
1012
|
const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, orderedInputs, methods, isCustomElementsBuild, isStandaloneBuild, inlineComponentProps, cmpMeta.events || []);
|
|
1006
1013
|
const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
|
|
1007
|
-
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir,
|
|
1014
|
+
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir, getEventTypesModule(config, outputTarget));
|
|
1008
1015
|
proxyFileOutput.push(componentDefinition, '\n');
|
|
1009
1016
|
if (includeSingleComponentAngularModules) {
|
|
1010
1017
|
proxyFileOutput.push(moduleDefinition, '\n');
|
|
@@ -1071,7 +1078,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
1071
1078
|
const inlineComponentProps = outputTarget.inlineProperties ? internalProps : [];
|
|
1072
1079
|
const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, orderedInputs, methods, isCustomElementsBuild, isStandaloneBuild, inlineComponentProps, cmpMeta.events || []);
|
|
1073
1080
|
const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
|
|
1074
|
-
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir,
|
|
1081
|
+
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir, getEventTypesModule(config, outputTarget));
|
|
1075
1082
|
const proxyFileOutput = [componentDefinition, '\n'];
|
|
1076
1083
|
if (includeSingleComponentAngularModules) {
|
|
1077
1084
|
proxyFileOutput.push(moduleDefinition, '\n');
|
|
@@ -1102,11 +1109,9 @@ function generateBarrelFile(components, outputTarget) {
|
|
|
1102
1109
|
}
|
|
1103
1110
|
function getPathToComponentTypes(config, outputTarget) {
|
|
1104
1111
|
const basePkg = outputTarget.componentCorePackage || '';
|
|
1105
|
-
//
|
|
1106
|
-
// package root only does when the project has no `src/index.ts`, or that file re-exports them
|
|
1112
|
+
// for Stencil v5 use the `<pkg>/components` export entry when `generateExportMaps` is enabled
|
|
1107
1113
|
if (usesExportMaps(config)) {
|
|
1108
|
-
|
|
1109
|
-
return `${normalizePath(basePkg)}/${entry}`;
|
|
1114
|
+
return `${normalizePath(basePkg)}/components`;
|
|
1110
1115
|
}
|
|
1111
1116
|
// in v5, all types (including components.d.ts) are generated in the dist/types directory
|
|
1112
1117
|
const typesTarget = config.outputTargets?.find((o) => o.type === 'types');
|
package/dist/output-angular.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { OutputTargetAngular, PackageJSON } from './types';
|
|
|
3
3
|
/**
|
|
4
4
|
* Whether the Stencil project generates a package.json `exports` map. Deep `dist/` imports are
|
|
5
5
|
* blocked for consumers then, so the proxies import through the map's entries instead
|
|
6
|
-
* (`<pkg>/<tag>`, `<pkg>/
|
|
6
|
+
* (`<pkg>/<tag>`, `<pkg>/components`, `<pkg>/standalone`).
|
|
7
7
|
*/
|
|
8
8
|
export declare function usesExportMaps(config: Config): boolean;
|
|
9
9
|
export declare function angularDirectiveProxyOutput(compilerCtx: CompilerCtx, outputTarget: OutputTargetAngular, components: ComponentCompilerMeta[], config: Config): Promise<void>;
|
package/dist/output-angular.js
CHANGED
|
@@ -49,13 +49,22 @@ const usesInputTransform = (components, booleanAttributes) => components.some((c
|
|
|
49
49
|
/**
|
|
50
50
|
* Whether the Stencil project generates a package.json `exports` map. Deep `dist/` imports are
|
|
51
51
|
* blocked for consumers then, so the proxies import through the map's entries instead
|
|
52
|
-
* (`<pkg>/<tag>`, `<pkg>/
|
|
52
|
+
* (`<pkg>/<tag>`, `<pkg>/components`, `<pkg>/standalone`).
|
|
53
53
|
*/
|
|
54
54
|
export function usesExportMaps(config) {
|
|
55
|
-
// Stencil v5 only: v4's map has no `./standalone` entry
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
// Stencil v5 only: v4's map has no `./components` or `./standalone` entry.
|
|
56
|
+
return isStencilV5(config) && config.generateExportMaps === true;
|
|
57
|
+
}
|
|
58
|
+
function isStencilV5(config) {
|
|
59
|
+
return (config.outputTargets || []).some((o) => ['loader-bundle', 'standalone', 'ssr', 'types'].includes(o.type));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* For Stencil v5 only, use the `types/components.d.ts`
|
|
63
|
+
*/
|
|
64
|
+
function getEventTypesModule(config, outputTarget) {
|
|
65
|
+
return isStencilV5(config) && outputTarget.componentCorePackage
|
|
66
|
+
? getPathToComponentTypes(config, outputTarget)
|
|
67
|
+
: undefined;
|
|
59
68
|
}
|
|
60
69
|
/**
|
|
61
70
|
* The module specifier a proxy imports a component's `defineCustomElement` from.
|
|
@@ -218,7 +227,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
218
227
|
*/
|
|
219
228
|
const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, orderedInputs, methods, isCustomElementsBuild, isStandaloneBuild, inlineComponentProps, cmpMeta.events || []);
|
|
220
229
|
const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
|
|
221
|
-
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir,
|
|
230
|
+
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir, getEventTypesModule(config, outputTarget));
|
|
222
231
|
proxyFileOutput.push(componentDefinition, '\n');
|
|
223
232
|
if (includeSingleComponentAngularModules) {
|
|
224
233
|
proxyFileOutput.push(moduleDefinition, '\n');
|
|
@@ -285,7 +294,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
285
294
|
const inlineComponentProps = outputTarget.inlineProperties ? internalProps : [];
|
|
286
295
|
const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, orderedInputs, methods, isCustomElementsBuild, isStandaloneBuild, inlineComponentProps, cmpMeta.events || []);
|
|
287
296
|
const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
|
|
288
|
-
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir,
|
|
297
|
+
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir, getEventTypesModule(config, outputTarget));
|
|
289
298
|
const proxyFileOutput = [componentDefinition, '\n'];
|
|
290
299
|
if (includeSingleComponentAngularModules) {
|
|
291
300
|
proxyFileOutput.push(moduleDefinition, '\n');
|
|
@@ -316,11 +325,9 @@ export function generateBarrelFile(components, outputTarget) {
|
|
|
316
325
|
}
|
|
317
326
|
export function getPathToComponentTypes(config, outputTarget) {
|
|
318
327
|
const basePkg = outputTarget.componentCorePackage || '';
|
|
319
|
-
//
|
|
320
|
-
// package root only does when the project has no `src/index.ts`, or that file re-exports them
|
|
328
|
+
// for Stencil v5 use the `<pkg>/components` export entry when `generateExportMaps` is enabled
|
|
321
329
|
if (usesExportMaps(config)) {
|
|
322
|
-
|
|
323
|
-
return `${normalizePath(basePkg)}/${entry}`;
|
|
330
|
+
return `${normalizePath(basePkg)}/components`;
|
|
324
331
|
}
|
|
325
332
|
// in v5, all types (including components.d.ts) are generated in the dist/types directory
|
|
326
333
|
const typesTarget = config.outputTargets?.find((o) => o.type === 'types');
|
package/dist/utils.d.ts
CHANGED
|
@@ -44,6 +44,9 @@ export declare const createComponentEventTypeImports: (componentTagName: string,
|
|
|
44
44
|
componentCorePackage: string;
|
|
45
45
|
customElementsDir?: string;
|
|
46
46
|
outputType: OutputType;
|
|
47
|
-
/**
|
|
48
|
-
|
|
47
|
+
/**
|
|
48
|
+
* The module every component type is imported from (Stencil v5: the `types` output's
|
|
49
|
+
* `components.d.ts`). When not set, v4's own locations are used.
|
|
50
|
+
*/
|
|
51
|
+
typesModule?: string;
|
|
49
52
|
}) => string;
|
package/dist/utils.js
CHANGED
|
@@ -118,9 +118,7 @@ export const createComponentEventTypeImports = (componentTagName, events, option
|
|
|
118
118
|
const imports = [];
|
|
119
119
|
const namedImports = new Set();
|
|
120
120
|
const isCustomElementsBuild = isOutputTypeCustomElementsBuild(options.outputType);
|
|
121
|
-
const
|
|
122
|
-
const importPathName = normalizePath(componentCorePackage) +
|
|
123
|
-
(options.exportMaps ? exportMapEntry : isCustomElementsBuild ? `/${customElementsDir}` : '');
|
|
121
|
+
const importPathName = options.typesModule ?? normalizePath(componentCorePackage) + (isCustomElementsBuild ? `/${customElementsDir}` : '');
|
|
124
122
|
/**
|
|
125
123
|
* Each component's events are typed with the per-component CustomEvent type
|
|
126
124
|
* generated by Stencil (e.g. `MyComponentCustomEvent<Detail>`), which carries a
|
package/dist/wizard.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { access, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { join, relative, dirname } from 'node:path';
|
|
2
|
+
import { join, relative, dirname, isAbsolute } from 'node:path';
|
|
3
3
|
// ---------------------------------------------------------------------------
|
|
4
4
|
// pnpm build approval
|
|
5
5
|
// ---------------------------------------------------------------------------
|
|
@@ -77,7 +77,22 @@ function toPascalCase(s) {
|
|
|
77
77
|
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
78
78
|
.join('');
|
|
79
79
|
}
|
|
80
|
-
|
|
80
|
+
/**
|
|
81
|
+
* The module the lazy loader's `defineCustomElements()` is imported from: the `./loader` entry
|
|
82
|
+
* when the project generates an `exports` map, otherwise its place in the `loader-bundle` output.
|
|
83
|
+
*/
|
|
84
|
+
function getLoaderModule(config, corePackageName) {
|
|
85
|
+
if (config.generateExportMaps === true) {
|
|
86
|
+
return `${corePackageName}/loader`;
|
|
87
|
+
}
|
|
88
|
+
const target = config.outputTargets?.find((o) => o.type === 'loader-bundle');
|
|
89
|
+
const rawDir = target?.dir ?? 'dist/loader-bundle';
|
|
90
|
+
const dir = (isAbsolute(rawDir) ? relative(config.rootDir, rawDir) : rawDir).replace(/\\/g, '/');
|
|
91
|
+
return `${corePackageName}/${dir}/${target?.loaderPath || 'loader'}`;
|
|
92
|
+
}
|
|
93
|
+
async function scaffoldWrapperPackage(wrapperDir, packageName, corePackageName, corePkgVersion, namespace, outputType,
|
|
94
|
+
/** For the 'component' type: the module to import the loader's `defineCustomElements()` from. */
|
|
95
|
+
loaderModule) {
|
|
81
96
|
const libDir = join(wrapperDir, 'src', 'lib');
|
|
82
97
|
await mkdir(libDir, { recursive: true });
|
|
83
98
|
const className = toPascalCase(namespace);
|
|
@@ -125,12 +140,23 @@ async function scaffoldWrapperPackage(wrapperDir, packageName, corePackageName,
|
|
|
125
140
|
// NgModule file — only needed for 'component' outputType
|
|
126
141
|
let ngModuleTs;
|
|
127
142
|
if (outputType === 'component') {
|
|
143
|
+
// The 'component' type's wrappers register nothing themselves: this module does it, with the
|
|
144
|
+
// lazy loader, when the consuming app starts. It's written once and never regenerated.
|
|
128
145
|
ngModuleTs =
|
|
129
|
-
`import { NgModule } from '@angular/core';\n` +
|
|
146
|
+
`import { NgModule, provideAppInitializer } from '@angular/core';\n` +
|
|
147
|
+
`import { defineCustomElements } from '${loaderModule}';\n` +
|
|
130
148
|
`import { DIRECTIVES } from './directives.array';\n\n` +
|
|
149
|
+
`/**\n` +
|
|
150
|
+
` * Declares every component, and registers the custom elements when the app starts.\n` +
|
|
151
|
+
` *\n` +
|
|
152
|
+
` * This file is yours to edit - Stencil doesn't regenerate it. Do any setup your library\n` +
|
|
153
|
+
` * needs before the components are defined in the initializer, e.g. \`setNonce()\` or\n` +
|
|
154
|
+
` * \`setTagTransformer()\` (both exported by the loader).\n` +
|
|
155
|
+
` */\n` +
|
|
131
156
|
`@NgModule({\n` +
|
|
132
157
|
` declarations: [...DIRECTIVES],\n` +
|
|
133
158
|
` exports: [...DIRECTIVES],\n` +
|
|
159
|
+
` providers: [provideAppInitializer(() => defineCustomElements())],\n` +
|
|
134
160
|
`})\n` +
|
|
135
161
|
`export class ${className}Module {}\n`;
|
|
136
162
|
}
|
|
@@ -240,7 +266,7 @@ export const wizard = {
|
|
|
240
266
|
const corePkgVersion = supportsWorkspaceProtocol
|
|
241
267
|
? 'workspace:*'
|
|
242
268
|
: `file:${relative(wrapperDir, config.rootDir)}`;
|
|
243
|
-
await scaffoldWrapperPackage(wrapperDir, wrapperPackageName, componentCorePackage, corePkgVersion, config.fsNamespace, selectedOutputType);
|
|
269
|
+
await scaffoldWrapperPackage(wrapperDir, wrapperPackageName, componentCorePackage, corePkgVersion, config.fsNamespace, selectedOutputType, selectedOutputType === 'component' ? getLoaderModule(config, componentCorePackage) : undefined);
|
|
244
270
|
s.stop('Wrapper package scaffolded');
|
|
245
271
|
}
|
|
246
272
|
catch (e) {
|
|
@@ -263,7 +289,8 @@ export const wizard = {
|
|
|
263
289
|
// Build target config
|
|
264
290
|
const lines = [
|
|
265
291
|
`componentCorePackage: '${componentCorePackage}'`,
|
|
266
|
-
`
|
|
292
|
+
// only the types built on the `standalone` output import from it
|
|
293
|
+
...(selectedOutputType !== 'component' ? [`customElementsDir: '${customElementsDir}'`] : []),
|
|
267
294
|
`directivesProxyFile: '${directivesProxyFile}'`,
|
|
268
295
|
...(directivesArrayFile ? [`directivesArrayFile: '${directivesArrayFile}'`] : []),
|
|
269
296
|
...(selectedOutputType !== 'standalone' ? [`outputType: '${selectedOutputType}'`] : []),
|
|
@@ -276,8 +303,18 @@ export const wizard = {
|
|
|
276
303
|
editor.outputTargetsContains('type: "standalone"') ||
|
|
277
304
|
editor.outputTargetsContains("type: 'dist-custom-elements'") ||
|
|
278
305
|
editor.outputTargetsContains('type: "dist-custom-elements"');
|
|
279
|
-
|
|
306
|
+
const hasLoaderBundle = editor.outputTargetsContains("type: 'loader-bundle'") ||
|
|
307
|
+
editor.outputTargetsContains('type: "loader-bundle"') ||
|
|
308
|
+
editor.outputTargetsContains("type: 'dist'") ||
|
|
309
|
+
editor.outputTargetsContains('type: "dist"');
|
|
310
|
+
// 'component' wrappers rely on the lazy loader; the other types import from `standalone`
|
|
311
|
+
if (selectedOutputType === 'component') {
|
|
312
|
+
if (!hasLoaderBundle)
|
|
313
|
+
editor.addOutputTarget("{ type: 'loader-bundle' }");
|
|
314
|
+
}
|
|
315
|
+
else if (!hasStandalone) {
|
|
280
316
|
editor.addOutputTarget("{ type: 'standalone' }");
|
|
317
|
+
}
|
|
281
318
|
if (!editor.replaceOutputTarget('angularOutputTarget(', targetCode)) {
|
|
282
319
|
editor.addOutputTarget(targetCode);
|
|
283
320
|
}
|
|
@@ -306,6 +343,10 @@ export const wizard = {
|
|
|
306
343
|
], { cwd: wrapperDir, dev: true });
|
|
307
344
|
log.success('Angular dependencies installed');
|
|
308
345
|
}
|
|
346
|
+
if (selectedOutputType === 'component' && !shouldScaffold) {
|
|
347
|
+
log.info(`NgModule components: your Angular package's module needs to call defineCustomElements() ` +
|
|
348
|
+
`from '${getLoaderModule(config, componentCorePackage)}' when the app starts, e.g. with provideAppInitializer().`);
|
|
349
|
+
}
|
|
309
350
|
outro('Angular output target configured');
|
|
310
351
|
},
|
|
311
352
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stencil/angular-output-target",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.3",
|
|
4
4
|
"description": "Angular output target for @stencil/core components.",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@angular/core": "8.2.14",
|
|
60
60
|
"@angular/forms": "8.2.14",
|
|
61
|
-
"@stencil/cli": "^5.0.0 || >=5.0.0-beta.
|
|
61
|
+
"@stencil/cli": "^5.0.0 || >=5.0.0-beta.18",
|
|
62
62
|
"@stencil/core": "4.41.0",
|
|
63
63
|
"@types/node": "^18.19.130",
|
|
64
64
|
"npm-run-all2": "^6.2.6",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"vitest": "^2.1.9"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
|
-
"@stencil/core": ">=2.0.0 || >=3 || >=4.0.0 || ^5.0.0 || >=5.0.0-beta.
|
|
72
|
+
"@stencil/core": ">=2.0.0 || >=3 || >=4.0.0 || ^5.0.0 || >=5.0.0-beta.18"
|
|
73
73
|
},
|
|
74
74
|
"gitHead": "a3588e905186a0e86e7f88418fd5b2f9531b55e0"
|
|
75
75
|
}
|