@stencil/angular-output-target 1.5.0 → 1.5.2
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 -1
- package/dist/generate-angular-component.js +3 -1
- package/dist/generate-transformtag-script.d.ts +3 -1
- package/dist/generate-transformtag-script.js +6 -2
- package/dist/index.cjs +59 -37
- package/dist/index.js +59 -37
- package/dist/output-angular.d.ts +6 -0
- package/dist/output-angular.js +49 -33
- package/dist/plugin.d.ts +7 -2
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +1 -1
- package/dist/wizard.js +14 -1
- package/package.json +3 -3
|
@@ -25,6 +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 typesModule The module every component type is imported from (Stencil v5 only).
|
|
28
29
|
* @returns The component interface type definition as a string.
|
|
29
30
|
*/
|
|
30
|
-
export declare const createComponentTypeDefinition: (outputType: OutputType, tagNameAsPascal: string, events: readonly ComponentCompilerEvent[], componentCorePackage: string, customElementsDir?: string) => string;
|
|
31
|
+
export declare const createComponentTypeDefinition: (outputType: OutputType, tagNameAsPascal: string, events: readonly ComponentCompilerEvent[], componentCorePackage: string, customElementsDir?: string, typesModule?: string) => string;
|
|
@@ -212,14 +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 typesModule The module every component type is imported from (Stencil v5 only).
|
|
215
216
|
* @returns The component interface type definition as a string.
|
|
216
217
|
*/
|
|
217
|
-
export const createComponentTypeDefinition = (outputType, tagNameAsPascal, events, componentCorePackage, customElementsDir) => {
|
|
218
|
+
export const createComponentTypeDefinition = (outputType, tagNameAsPascal, events, componentCorePackage, customElementsDir, typesModule) => {
|
|
218
219
|
const publicEvents = events.filter((ev) => !ev.internal);
|
|
219
220
|
const eventTypeImports = createComponentEventTypeImports(tagNameAsPascal, publicEvents, {
|
|
220
221
|
componentCorePackage,
|
|
221
222
|
customElementsDir,
|
|
222
223
|
outputType,
|
|
224
|
+
typesModule,
|
|
223
225
|
});
|
|
224
226
|
const eventTypes = publicEvents.map((event) => createPropertyDeclaration(event, `EventEmitter<${tagNameAsPascal}CustomEvent<${formatOutputType(tagNameAsPascal, event)}>>`));
|
|
225
227
|
const interfaceDeclaration = `export declare interface ${tagNameAsPascal} extends Components.${tagNameAsPascal} {`;
|
|
@@ -5,4 +5,6 @@ import type { OutputTargetAngular } from './types';
|
|
|
5
5
|
* This script patches component selectors in the built Angular library to use the
|
|
6
6
|
* transformed tag names (e.g., 'my-component' -> 'v1-my-component').
|
|
7
7
|
*/
|
|
8
|
-
export declare function generateTransformTagScript(compilerCtx: CompilerCtx, components: ComponentCompilerMeta[], outputTarget: OutputTargetAngular,
|
|
8
|
+
export declare function generateTransformTagScript(compilerCtx: CompilerCtx, components: ComponentCompilerMeta[], outputTarget: OutputTargetAngular,
|
|
9
|
+
/** Import through the package's `exports` map (`<pkg>/standalone`) instead of a deep path. */
|
|
10
|
+
exportMaps?: boolean): Promise<void>;
|
|
@@ -5,10 +5,14 @@ import { dashToPascalCase } from './utils';
|
|
|
5
5
|
* This script patches component selectors in the built Angular library to use the
|
|
6
6
|
* transformed tag names (e.g., 'my-component' -> 'v1-my-component').
|
|
7
7
|
*/
|
|
8
|
-
export async function generateTransformTagScript(compilerCtx, components, outputTarget,
|
|
8
|
+
export async function generateTransformTagScript(compilerCtx, components, outputTarget,
|
|
9
|
+
/** Import through the package's `exports` map (`<pkg>/standalone`) instead of a deep path. */
|
|
10
|
+
exportMaps = false) {
|
|
9
11
|
const scriptsDirectory = path.join(path.dirname(outputTarget.directivesProxyFile), '../../scripts');
|
|
10
12
|
const customElementsDir = outputTarget.customElementsDir || 'dist/components';
|
|
11
|
-
const stencilImportPath =
|
|
13
|
+
const stencilImportPath = exportMaps
|
|
14
|
+
? `${outputTarget.componentCorePackage}/standalone`
|
|
15
|
+
: `${outputTarget.componentCorePackage}/${customElementsDir}/index.js`;
|
|
12
16
|
// Generate the mappings object
|
|
13
17
|
const mappings = components
|
|
14
18
|
.map((component) => {
|
package/dist/index.cjs
CHANGED
|
@@ -126,7 +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 importPathName = normalizePath(componentCorePackage) + (isCustomElementsBuild ? `/${customElementsDir}` : '');
|
|
129
|
+
const importPathName = options.typesModule ?? normalizePath(componentCorePackage) + (isCustomElementsBuild ? `/${customElementsDir}` : '');
|
|
130
130
|
/**
|
|
131
131
|
* Each component's events are typed with the per-component CustomEvent type
|
|
132
132
|
* generated by Stencil (e.g. `MyComponentCustomEvent<Detail>`), which carries a
|
|
@@ -366,14 +366,16 @@ const createDocComment = (doc) => {
|
|
|
366
366
|
* @param events The events to generate the interface properties for.
|
|
367
367
|
* @param componentCorePackage The component core package.
|
|
368
368
|
* @param customElementsDir The custom elements directory.
|
|
369
|
+
* @param typesModule The module every component type is imported from (Stencil v5 only).
|
|
369
370
|
* @returns The component interface type definition as a string.
|
|
370
371
|
*/
|
|
371
|
-
const createComponentTypeDefinition = (outputType, tagNameAsPascal, events, componentCorePackage, customElementsDir) => {
|
|
372
|
+
const createComponentTypeDefinition = (outputType, tagNameAsPascal, events, componentCorePackage, customElementsDir, typesModule) => {
|
|
372
373
|
const publicEvents = events.filter((ev) => !ev.internal);
|
|
373
374
|
const eventTypeImports = createComponentEventTypeImports(tagNameAsPascal, publicEvents, {
|
|
374
375
|
componentCorePackage,
|
|
375
376
|
customElementsDir,
|
|
376
377
|
outputType,
|
|
378
|
+
typesModule,
|
|
377
379
|
});
|
|
378
380
|
const eventTypes = publicEvents.map((event) => createPropertyDeclaration(event, `EventEmitter<${tagNameAsPascal}CustomEvent<${formatOutputType(tagNameAsPascal, event)}>>`));
|
|
379
381
|
const interfaceDeclaration = `export declare interface ${tagNameAsPascal} extends Components.${tagNameAsPascal} {`;
|
|
@@ -491,10 +493,14 @@ export class ${moduleClassName} { }`;
|
|
|
491
493
|
* This script patches component selectors in the built Angular library to use the
|
|
492
494
|
* transformed tag names (e.g., 'my-component' -> 'v1-my-component').
|
|
493
495
|
*/
|
|
494
|
-
async function generateTransformTagScript(compilerCtx, components, outputTarget,
|
|
496
|
+
async function generateTransformTagScript(compilerCtx, components, outputTarget,
|
|
497
|
+
/** Import through the package's `exports` map (`<pkg>/standalone`) instead of a deep path. */
|
|
498
|
+
exportMaps = false) {
|
|
495
499
|
const scriptsDirectory = path__default["default"].join(path__default["default"].dirname(outputTarget.directivesProxyFile), '../../scripts');
|
|
496
500
|
const customElementsDir = outputTarget.customElementsDir || 'dist/components';
|
|
497
|
-
const stencilImportPath =
|
|
501
|
+
const stencilImportPath = exportMaps
|
|
502
|
+
? `${outputTarget.componentCorePackage}/standalone`
|
|
503
|
+
: `${outputTarget.componentCorePackage}/${customElementsDir}/index.js`;
|
|
498
504
|
// Generate the mappings object
|
|
499
505
|
const mappings = components
|
|
500
506
|
.map((component) => {
|
|
@@ -832,6 +838,44 @@ const mapInputProp = (prop, booleanAttributes = false) => ({
|
|
|
832
838
|
* @returns `true` when at least one property is transformed.
|
|
833
839
|
*/
|
|
834
840
|
const usesInputTransform = (components, booleanAttributes) => components.some((cmpMeta) => (cmpMeta.properties ?? []).filter(filterInternalProps).some((prop) => isTransformedProp(prop, booleanAttributes)));
|
|
841
|
+
/**
|
|
842
|
+
* Whether the Stencil project generates a package.json `exports` map. Deep `dist/` imports are
|
|
843
|
+
* blocked for consumers then, so the proxies import through the map's entries instead
|
|
844
|
+
* (`<pkg>/<tag>`, `<pkg>/components`, `<pkg>/standalone`).
|
|
845
|
+
*/
|
|
846
|
+
function usesExportMaps(config) {
|
|
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;
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* The module specifier a proxy imports a component's `defineCustomElement` from.
|
|
863
|
+
*/
|
|
864
|
+
function getComponentModule(config, outputTarget, tagName) {
|
|
865
|
+
const basePkg = normalizePath(outputTarget.componentCorePackage);
|
|
866
|
+
if (usesExportMaps(config)) {
|
|
867
|
+
return `${basePkg}/${tagName}`;
|
|
868
|
+
}
|
|
869
|
+
return `${basePkg}/${outputTarget.customElementsDir}/${tagName}.js`;
|
|
870
|
+
}
|
|
871
|
+
/**
|
|
872
|
+
* The relative import of the project's own `components.d.ts`, for when there's no
|
|
873
|
+
* `componentCorePackage`. Only resolved when needed: package.json may have no `types` field.
|
|
874
|
+
*/
|
|
875
|
+
function getComponentsTypeFile(pkgData, outputTarget, rootDir) {
|
|
876
|
+
const dtsFilePath = path__default["default"].join(rootDir, path__default["default"].dirname(pkgData.types), GENERATED_DTS);
|
|
877
|
+
return relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
|
|
878
|
+
}
|
|
835
879
|
async function angularDirectiveProxyOutput(compilerCtx, outputTarget, components, config) {
|
|
836
880
|
const filteredComponents = getFilteredComponents(outputTarget.excludeComponents, components);
|
|
837
881
|
const rootDir = config.rootDir;
|
|
@@ -865,27 +909,7 @@ async function angularDirectiveProxyOutput(compilerCtx, outputTarget, components
|
|
|
865
909
|
}
|
|
866
910
|
// Generate transformer script if transformTag is enabled
|
|
867
911
|
if (outputTarget.transformTag) {
|
|
868
|
-
|
|
869
|
-
// directivesProxyFile is like: projects/library/src/directives/proxies.ts
|
|
870
|
-
// We need to go up to: projects/library/package.json
|
|
871
|
-
const angularLibraryDir = path__default["default"].dirname(path__default["default"].dirname(path__default["default"].dirname(outputTarget.directivesProxyFile)));
|
|
872
|
-
const angularPkgJsonPath = path__default["default"].join(angularLibraryDir, 'package.json');
|
|
873
|
-
let angularPackageName = '';
|
|
874
|
-
try {
|
|
875
|
-
const angularPkgJson = JSON.parse(await compilerCtx.fs.readFile(angularPkgJsonPath));
|
|
876
|
-
if (angularPkgJson.name) {
|
|
877
|
-
angularPackageName = angularPkgJson.name;
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
catch (e) {
|
|
881
|
-
throw new Error(`Could not read Angular library package.json at ${angularPkgJsonPath}. ` +
|
|
882
|
-
`The package name is required to generate the transformTag patch script.`);
|
|
883
|
-
}
|
|
884
|
-
if (!angularPackageName) {
|
|
885
|
-
throw new Error(`Angular library package.json at ${angularPkgJsonPath} does not have a "name" field. ` +
|
|
886
|
-
`The package name is required to generate the transformTag patch script.`);
|
|
887
|
-
}
|
|
888
|
-
tasks.push(generateTransformTagScript(compilerCtx, filteredComponents, outputTarget));
|
|
912
|
+
tasks.push(generateTransformTagScript(compilerCtx, filteredComponents, outputTarget, usesExportMaps(config)));
|
|
889
913
|
}
|
|
890
914
|
await Promise.all(tasks);
|
|
891
915
|
}
|
|
@@ -909,10 +933,7 @@ async function copyResources(config, outputTarget) {
|
|
|
909
933
|
], srcDirectory);
|
|
910
934
|
}
|
|
911
935
|
function generateProxies(components, pkgData, outputTarget, rootDir, config) {
|
|
912
|
-
const distTypesDir = path__default["default"].dirname(pkgData.types);
|
|
913
|
-
const dtsFilePath = path__default["default"].join(rootDir, distTypesDir, GENERATED_DTS);
|
|
914
936
|
const { outputType } = outputTarget;
|
|
915
|
-
const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
|
|
916
937
|
const includeSingleComponentAngularModules = outputType === OutputTypes.Scam;
|
|
917
938
|
const isCustomElementsBuild = isOutputTypeCustomElementsBuild(outputType);
|
|
918
939
|
const isStandaloneBuild = outputType === OutputTypes.Standalone;
|
|
@@ -954,7 +975,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
954
975
|
const generateTypeImports = () => {
|
|
955
976
|
const importLocation = outputTarget.componentCorePackage
|
|
956
977
|
? getPathToComponentTypes(config, outputTarget)
|
|
957
|
-
: normalizePath(
|
|
978
|
+
: normalizePath(getComponentsTypeFile(pkgData, outputTarget, rootDir));
|
|
958
979
|
return `import ${isCustomElementsBuild ? 'type ' : ''}{ ${IMPORT_TYPES} } from '${importLocation}';\n`;
|
|
959
980
|
};
|
|
960
981
|
const typeImports = generateTypeImports();
|
|
@@ -968,7 +989,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
968
989
|
if (isCustomElementsBuild && outputTarget.componentCorePackage !== undefined) {
|
|
969
990
|
const cmpImports = components.map((component) => {
|
|
970
991
|
const pascalImport = dashToPascalCase(component.tagName);
|
|
971
|
-
return `import { defineCustomElement as define${pascalImport} } from '${
|
|
992
|
+
return `import { defineCustomElement as define${pascalImport} } from '${getComponentModule(config, outputTarget, component.tagName)}';`;
|
|
972
993
|
});
|
|
973
994
|
sourceImports = cmpImports.join('\n');
|
|
974
995
|
}
|
|
@@ -998,7 +1019,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
998
1019
|
*/
|
|
999
1020
|
const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, orderedInputs, methods, isCustomElementsBuild, isStandaloneBuild, inlineComponentProps, cmpMeta.events || []);
|
|
1000
1021
|
const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
|
|
1001
|
-
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir);
|
|
1022
|
+
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir, getEventTypesModule(config, outputTarget));
|
|
1002
1023
|
proxyFileOutput.push(componentDefinition, '\n');
|
|
1003
1024
|
if (includeSingleComponentAngularModules) {
|
|
1004
1025
|
proxyFileOutput.push(moduleDefinition, '\n');
|
|
@@ -1013,9 +1034,6 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
1013
1034
|
*/
|
|
1014
1035
|
function generateComponentProxy(cmpMeta, pkgData, outputTarget, rootDir, config) {
|
|
1015
1036
|
const { outputType, componentCorePackage, customElementsDir } = outputTarget;
|
|
1016
|
-
const distTypesDir = path__default["default"].dirname(pkgData.types);
|
|
1017
|
-
const dtsFilePath = path__default["default"].join(rootDir, distTypesDir, GENERATED_DTS);
|
|
1018
|
-
const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
|
|
1019
1037
|
const includeSingleComponentAngularModules = outputType === OutputTypes.Scam;
|
|
1020
1038
|
const isCustomElementsBuild = isOutputTypeCustomElementsBuild(outputType);
|
|
1021
1039
|
const isStandaloneBuild = outputType === OutputTypes.Standalone;
|
|
@@ -1044,12 +1062,12 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
1044
1062
|
// Type imports
|
|
1045
1063
|
const importLocation = componentCorePackage
|
|
1046
1064
|
? getPathToComponentTypes(config, outputTarget)
|
|
1047
|
-
: normalizePath(
|
|
1065
|
+
: normalizePath(getComponentsTypeFile(pkgData, outputTarget, rootDir));
|
|
1048
1066
|
const typeImports = `import ${isCustomElementsBuild ? 'type ' : ''}{ ${IMPORT_TYPES} } from '${importLocation}';\n`;
|
|
1049
1067
|
// defineCustomElement import
|
|
1050
1068
|
let sourceImport = '';
|
|
1051
1069
|
if (isCustomElementsBuild && componentCorePackage !== undefined) {
|
|
1052
|
-
sourceImport = `import { defineCustomElement as define${tagNameAsPascal} } from '${
|
|
1070
|
+
sourceImport = `import { defineCustomElement as define${tagNameAsPascal} } from '${getComponentModule(config, outputTarget, cmpMeta.tagName)}';\n`;
|
|
1053
1071
|
}
|
|
1054
1072
|
// Generate component definition
|
|
1055
1073
|
const internalProps = [];
|
|
@@ -1068,7 +1086,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
1068
1086
|
const inlineComponentProps = outputTarget.inlineProperties ? internalProps : [];
|
|
1069
1087
|
const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, orderedInputs, methods, isCustomElementsBuild, isStandaloneBuild, inlineComponentProps, cmpMeta.events || []);
|
|
1070
1088
|
const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
|
|
1071
|
-
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir);
|
|
1089
|
+
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir, getEventTypesModule(config, outputTarget));
|
|
1072
1090
|
const proxyFileOutput = [componentDefinition, '\n'];
|
|
1073
1091
|
if (includeSingleComponentAngularModules) {
|
|
1074
1092
|
proxyFileOutput.push(moduleDefinition, '\n');
|
|
@@ -1099,6 +1117,10 @@ function generateBarrelFile(components, outputTarget) {
|
|
|
1099
1117
|
}
|
|
1100
1118
|
function getPathToComponentTypes(config, outputTarget) {
|
|
1101
1119
|
const basePkg = outputTarget.componentCorePackage || '';
|
|
1120
|
+
// for Stencil v5 use the `<pkg>/components` export entry when `generateExportMaps` is enabled
|
|
1121
|
+
if (usesExportMaps(config)) {
|
|
1122
|
+
return `${normalizePath(basePkg)}/components`;
|
|
1123
|
+
}
|
|
1102
1124
|
// in v5, all types (including components.d.ts) are generated in the dist/types directory
|
|
1103
1125
|
const typesTarget = config.outputTargets?.find((o) => o.type === 'types');
|
|
1104
1126
|
if (typesTarget) {
|
package/dist/index.js
CHANGED
|
@@ -118,7 +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 importPathName = normalizePath(componentCorePackage) + (isCustomElementsBuild ? `/${customElementsDir}` : '');
|
|
121
|
+
const importPathName = options.typesModule ?? normalizePath(componentCorePackage) + (isCustomElementsBuild ? `/${customElementsDir}` : '');
|
|
122
122
|
/**
|
|
123
123
|
* Each component's events are typed with the per-component CustomEvent type
|
|
124
124
|
* generated by Stencil (e.g. `MyComponentCustomEvent<Detail>`), which carries a
|
|
@@ -358,14 +358,16 @@ const createDocComment = (doc) => {
|
|
|
358
358
|
* @param events The events to generate the interface properties for.
|
|
359
359
|
* @param componentCorePackage The component core package.
|
|
360
360
|
* @param customElementsDir The custom elements directory.
|
|
361
|
+
* @param typesModule The module every component type is imported from (Stencil v5 only).
|
|
361
362
|
* @returns The component interface type definition as a string.
|
|
362
363
|
*/
|
|
363
|
-
const createComponentTypeDefinition = (outputType, tagNameAsPascal, events, componentCorePackage, customElementsDir) => {
|
|
364
|
+
const createComponentTypeDefinition = (outputType, tagNameAsPascal, events, componentCorePackage, customElementsDir, typesModule) => {
|
|
364
365
|
const publicEvents = events.filter((ev) => !ev.internal);
|
|
365
366
|
const eventTypeImports = createComponentEventTypeImports(tagNameAsPascal, publicEvents, {
|
|
366
367
|
componentCorePackage,
|
|
367
368
|
customElementsDir,
|
|
368
369
|
outputType,
|
|
370
|
+
typesModule,
|
|
369
371
|
});
|
|
370
372
|
const eventTypes = publicEvents.map((event) => createPropertyDeclaration(event, `EventEmitter<${tagNameAsPascal}CustomEvent<${formatOutputType(tagNameAsPascal, event)}>>`));
|
|
371
373
|
const interfaceDeclaration = `export declare interface ${tagNameAsPascal} extends Components.${tagNameAsPascal} {`;
|
|
@@ -483,10 +485,14 @@ export class ${moduleClassName} { }`;
|
|
|
483
485
|
* This script patches component selectors in the built Angular library to use the
|
|
484
486
|
* transformed tag names (e.g., 'my-component' -> 'v1-my-component').
|
|
485
487
|
*/
|
|
486
|
-
async function generateTransformTagScript(compilerCtx, components, outputTarget,
|
|
488
|
+
async function generateTransformTagScript(compilerCtx, components, outputTarget,
|
|
489
|
+
/** Import through the package's `exports` map (`<pkg>/standalone`) instead of a deep path. */
|
|
490
|
+
exportMaps = false) {
|
|
487
491
|
const scriptsDirectory = path.join(path.dirname(outputTarget.directivesProxyFile), '../../scripts');
|
|
488
492
|
const customElementsDir = outputTarget.customElementsDir || 'dist/components';
|
|
489
|
-
const stencilImportPath =
|
|
493
|
+
const stencilImportPath = exportMaps
|
|
494
|
+
? `${outputTarget.componentCorePackage}/standalone`
|
|
495
|
+
: `${outputTarget.componentCorePackage}/${customElementsDir}/index.js`;
|
|
490
496
|
// Generate the mappings object
|
|
491
497
|
const mappings = components
|
|
492
498
|
.map((component) => {
|
|
@@ -824,6 +830,44 @@ const mapInputProp = (prop, booleanAttributes = false) => ({
|
|
|
824
830
|
* @returns `true` when at least one property is transformed.
|
|
825
831
|
*/
|
|
826
832
|
const usesInputTransform = (components, booleanAttributes) => components.some((cmpMeta) => (cmpMeta.properties ?? []).filter(filterInternalProps).some((prop) => isTransformedProp(prop, booleanAttributes)));
|
|
833
|
+
/**
|
|
834
|
+
* Whether the Stencil project generates a package.json `exports` map. Deep `dist/` imports are
|
|
835
|
+
* blocked for consumers then, so the proxies import through the map's entries instead
|
|
836
|
+
* (`<pkg>/<tag>`, `<pkg>/components`, `<pkg>/standalone`).
|
|
837
|
+
*/
|
|
838
|
+
function usesExportMaps(config) {
|
|
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;
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* The module specifier a proxy imports a component's `defineCustomElement` from.
|
|
855
|
+
*/
|
|
856
|
+
function getComponentModule(config, outputTarget, tagName) {
|
|
857
|
+
const basePkg = normalizePath(outputTarget.componentCorePackage);
|
|
858
|
+
if (usesExportMaps(config)) {
|
|
859
|
+
return `${basePkg}/${tagName}`;
|
|
860
|
+
}
|
|
861
|
+
return `${basePkg}/${outputTarget.customElementsDir}/${tagName}.js`;
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* The relative import of the project's own `components.d.ts`, for when there's no
|
|
865
|
+
* `componentCorePackage`. Only resolved when needed: package.json may have no `types` field.
|
|
866
|
+
*/
|
|
867
|
+
function getComponentsTypeFile(pkgData, outputTarget, rootDir) {
|
|
868
|
+
const dtsFilePath = path.join(rootDir, path.dirname(pkgData.types), GENERATED_DTS);
|
|
869
|
+
return relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
|
|
870
|
+
}
|
|
827
871
|
async function angularDirectiveProxyOutput(compilerCtx, outputTarget, components, config) {
|
|
828
872
|
const filteredComponents = getFilteredComponents(outputTarget.excludeComponents, components);
|
|
829
873
|
const rootDir = config.rootDir;
|
|
@@ -857,27 +901,7 @@ async function angularDirectiveProxyOutput(compilerCtx, outputTarget, components
|
|
|
857
901
|
}
|
|
858
902
|
// Generate transformer script if transformTag is enabled
|
|
859
903
|
if (outputTarget.transformTag) {
|
|
860
|
-
|
|
861
|
-
// directivesProxyFile is like: projects/library/src/directives/proxies.ts
|
|
862
|
-
// We need to go up to: projects/library/package.json
|
|
863
|
-
const angularLibraryDir = path.dirname(path.dirname(path.dirname(outputTarget.directivesProxyFile)));
|
|
864
|
-
const angularPkgJsonPath = path.join(angularLibraryDir, 'package.json');
|
|
865
|
-
let angularPackageName = '';
|
|
866
|
-
try {
|
|
867
|
-
const angularPkgJson = JSON.parse(await compilerCtx.fs.readFile(angularPkgJsonPath));
|
|
868
|
-
if (angularPkgJson.name) {
|
|
869
|
-
angularPackageName = angularPkgJson.name;
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
catch (e) {
|
|
873
|
-
throw new Error(`Could not read Angular library package.json at ${angularPkgJsonPath}. ` +
|
|
874
|
-
`The package name is required to generate the transformTag patch script.`);
|
|
875
|
-
}
|
|
876
|
-
if (!angularPackageName) {
|
|
877
|
-
throw new Error(`Angular library package.json at ${angularPkgJsonPath} does not have a "name" field. ` +
|
|
878
|
-
`The package name is required to generate the transformTag patch script.`);
|
|
879
|
-
}
|
|
880
|
-
tasks.push(generateTransformTagScript(compilerCtx, filteredComponents, outputTarget));
|
|
904
|
+
tasks.push(generateTransformTagScript(compilerCtx, filteredComponents, outputTarget, usesExportMaps(config)));
|
|
881
905
|
}
|
|
882
906
|
await Promise.all(tasks);
|
|
883
907
|
}
|
|
@@ -901,10 +925,7 @@ async function copyResources(config, outputTarget) {
|
|
|
901
925
|
], srcDirectory);
|
|
902
926
|
}
|
|
903
927
|
function generateProxies(components, pkgData, outputTarget, rootDir, config) {
|
|
904
|
-
const distTypesDir = path.dirname(pkgData.types);
|
|
905
|
-
const dtsFilePath = path.join(rootDir, distTypesDir, GENERATED_DTS);
|
|
906
928
|
const { outputType } = outputTarget;
|
|
907
|
-
const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
|
|
908
929
|
const includeSingleComponentAngularModules = outputType === OutputTypes.Scam;
|
|
909
930
|
const isCustomElementsBuild = isOutputTypeCustomElementsBuild(outputType);
|
|
910
931
|
const isStandaloneBuild = outputType === OutputTypes.Standalone;
|
|
@@ -946,7 +967,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
946
967
|
const generateTypeImports = () => {
|
|
947
968
|
const importLocation = outputTarget.componentCorePackage
|
|
948
969
|
? getPathToComponentTypes(config, outputTarget)
|
|
949
|
-
: normalizePath(
|
|
970
|
+
: normalizePath(getComponentsTypeFile(pkgData, outputTarget, rootDir));
|
|
950
971
|
return `import ${isCustomElementsBuild ? 'type ' : ''}{ ${IMPORT_TYPES} } from '${importLocation}';\n`;
|
|
951
972
|
};
|
|
952
973
|
const typeImports = generateTypeImports();
|
|
@@ -960,7 +981,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
960
981
|
if (isCustomElementsBuild && outputTarget.componentCorePackage !== undefined) {
|
|
961
982
|
const cmpImports = components.map((component) => {
|
|
962
983
|
const pascalImport = dashToPascalCase(component.tagName);
|
|
963
|
-
return `import { defineCustomElement as define${pascalImport} } from '${
|
|
984
|
+
return `import { defineCustomElement as define${pascalImport} } from '${getComponentModule(config, outputTarget, component.tagName)}';`;
|
|
964
985
|
});
|
|
965
986
|
sourceImports = cmpImports.join('\n');
|
|
966
987
|
}
|
|
@@ -990,7 +1011,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
990
1011
|
*/
|
|
991
1012
|
const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, orderedInputs, methods, isCustomElementsBuild, isStandaloneBuild, inlineComponentProps, cmpMeta.events || []);
|
|
992
1013
|
const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
|
|
993
|
-
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir);
|
|
1014
|
+
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir, getEventTypesModule(config, outputTarget));
|
|
994
1015
|
proxyFileOutput.push(componentDefinition, '\n');
|
|
995
1016
|
if (includeSingleComponentAngularModules) {
|
|
996
1017
|
proxyFileOutput.push(moduleDefinition, '\n');
|
|
@@ -1005,9 +1026,6 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
1005
1026
|
*/
|
|
1006
1027
|
function generateComponentProxy(cmpMeta, pkgData, outputTarget, rootDir, config) {
|
|
1007
1028
|
const { outputType, componentCorePackage, customElementsDir } = outputTarget;
|
|
1008
|
-
const distTypesDir = path.dirname(pkgData.types);
|
|
1009
|
-
const dtsFilePath = path.join(rootDir, distTypesDir, GENERATED_DTS);
|
|
1010
|
-
const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
|
|
1011
1029
|
const includeSingleComponentAngularModules = outputType === OutputTypes.Scam;
|
|
1012
1030
|
const isCustomElementsBuild = isOutputTypeCustomElementsBuild(outputType);
|
|
1013
1031
|
const isStandaloneBuild = outputType === OutputTypes.Standalone;
|
|
@@ -1036,12 +1054,12 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
1036
1054
|
// Type imports
|
|
1037
1055
|
const importLocation = componentCorePackage
|
|
1038
1056
|
? getPathToComponentTypes(config, outputTarget)
|
|
1039
|
-
: normalizePath(
|
|
1057
|
+
: normalizePath(getComponentsTypeFile(pkgData, outputTarget, rootDir));
|
|
1040
1058
|
const typeImports = `import ${isCustomElementsBuild ? 'type ' : ''}{ ${IMPORT_TYPES} } from '${importLocation}';\n`;
|
|
1041
1059
|
// defineCustomElement import
|
|
1042
1060
|
let sourceImport = '';
|
|
1043
1061
|
if (isCustomElementsBuild && componentCorePackage !== undefined) {
|
|
1044
|
-
sourceImport = `import { defineCustomElement as define${tagNameAsPascal} } from '${
|
|
1062
|
+
sourceImport = `import { defineCustomElement as define${tagNameAsPascal} } from '${getComponentModule(config, outputTarget, cmpMeta.tagName)}';\n`;
|
|
1045
1063
|
}
|
|
1046
1064
|
// Generate component definition
|
|
1047
1065
|
const internalProps = [];
|
|
@@ -1060,7 +1078,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
1060
1078
|
const inlineComponentProps = outputTarget.inlineProperties ? internalProps : [];
|
|
1061
1079
|
const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, orderedInputs, methods, isCustomElementsBuild, isStandaloneBuild, inlineComponentProps, cmpMeta.events || []);
|
|
1062
1080
|
const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
|
|
1063
|
-
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir);
|
|
1081
|
+
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir, getEventTypesModule(config, outputTarget));
|
|
1064
1082
|
const proxyFileOutput = [componentDefinition, '\n'];
|
|
1065
1083
|
if (includeSingleComponentAngularModules) {
|
|
1066
1084
|
proxyFileOutput.push(moduleDefinition, '\n');
|
|
@@ -1091,6 +1109,10 @@ function generateBarrelFile(components, outputTarget) {
|
|
|
1091
1109
|
}
|
|
1092
1110
|
function getPathToComponentTypes(config, outputTarget) {
|
|
1093
1111
|
const basePkg = outputTarget.componentCorePackage || '';
|
|
1112
|
+
// for Stencil v5 use the `<pkg>/components` export entry when `generateExportMaps` is enabled
|
|
1113
|
+
if (usesExportMaps(config)) {
|
|
1114
|
+
return `${normalizePath(basePkg)}/components`;
|
|
1115
|
+
}
|
|
1094
1116
|
// in v5, all types (including components.d.ts) are generated in the dist/types directory
|
|
1095
1117
|
const typesTarget = config.outputTargets?.find((o) => o.type === 'types');
|
|
1096
1118
|
if (typesTarget) {
|
package/dist/output-angular.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { CompilerCtx, ComponentCompilerMeta, Config } from '@stencil/core/internal';
|
|
2
2
|
import type { OutputTargetAngular, PackageJSON } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Whether the Stencil project generates a package.json `exports` map. Deep `dist/` imports are
|
|
5
|
+
* blocked for consumers then, so the proxies import through the map's entries instead
|
|
6
|
+
* (`<pkg>/<tag>`, `<pkg>/components`, `<pkg>/standalone`).
|
|
7
|
+
*/
|
|
8
|
+
export declare function usesExportMaps(config: Config): boolean;
|
|
3
9
|
export declare function angularDirectiveProxyOutput(compilerCtx: CompilerCtx, outputTarget: OutputTargetAngular, components: ComponentCompilerMeta[], config: Config): Promise<void>;
|
|
4
10
|
export declare function generateProxies(components: ComponentCompilerMeta[], pkgData: PackageJSON, outputTarget: OutputTargetAngular, rootDir: string, config: Config): string;
|
|
5
11
|
/**
|
package/dist/output-angular.js
CHANGED
|
@@ -46,6 +46,44 @@ const mapInputProp = (prop, booleanAttributes = false) => ({
|
|
|
46
46
|
* @returns `true` when at least one property is transformed.
|
|
47
47
|
*/
|
|
48
48
|
const usesInputTransform = (components, booleanAttributes) => components.some((cmpMeta) => (cmpMeta.properties ?? []).filter(filterInternalProps).some((prop) => isTransformedProp(prop, booleanAttributes)));
|
|
49
|
+
/**
|
|
50
|
+
* Whether the Stencil project generates a package.json `exports` map. Deep `dist/` imports are
|
|
51
|
+
* blocked for consumers then, so the proxies import through the map's entries instead
|
|
52
|
+
* (`<pkg>/<tag>`, `<pkg>/components`, `<pkg>/standalone`).
|
|
53
|
+
*/
|
|
54
|
+
export function usesExportMaps(config) {
|
|
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;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The module specifier a proxy imports a component's `defineCustomElement` from.
|
|
71
|
+
*/
|
|
72
|
+
function getComponentModule(config, outputTarget, tagName) {
|
|
73
|
+
const basePkg = normalizePath(outputTarget.componentCorePackage);
|
|
74
|
+
if (usesExportMaps(config)) {
|
|
75
|
+
return `${basePkg}/${tagName}`;
|
|
76
|
+
}
|
|
77
|
+
return `${basePkg}/${outputTarget.customElementsDir}/${tagName}.js`;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* The relative import of the project's own `components.d.ts`, for when there's no
|
|
81
|
+
* `componentCorePackage`. Only resolved when needed: package.json may have no `types` field.
|
|
82
|
+
*/
|
|
83
|
+
function getComponentsTypeFile(pkgData, outputTarget, rootDir) {
|
|
84
|
+
const dtsFilePath = path.join(rootDir, path.dirname(pkgData.types), GENERATED_DTS);
|
|
85
|
+
return relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
|
|
86
|
+
}
|
|
49
87
|
export async function angularDirectiveProxyOutput(compilerCtx, outputTarget, components, config) {
|
|
50
88
|
const filteredComponents = getFilteredComponents(outputTarget.excludeComponents, components);
|
|
51
89
|
const rootDir = config.rootDir;
|
|
@@ -79,27 +117,7 @@ export async function angularDirectiveProxyOutput(compilerCtx, outputTarget, com
|
|
|
79
117
|
}
|
|
80
118
|
// Generate transformer script if transformTag is enabled
|
|
81
119
|
if (outputTarget.transformTag) {
|
|
82
|
-
|
|
83
|
-
// directivesProxyFile is like: projects/library/src/directives/proxies.ts
|
|
84
|
-
// We need to go up to: projects/library/package.json
|
|
85
|
-
const angularLibraryDir = path.dirname(path.dirname(path.dirname(outputTarget.directivesProxyFile)));
|
|
86
|
-
const angularPkgJsonPath = path.join(angularLibraryDir, 'package.json');
|
|
87
|
-
let angularPackageName = '';
|
|
88
|
-
try {
|
|
89
|
-
const angularPkgJson = JSON.parse(await compilerCtx.fs.readFile(angularPkgJsonPath));
|
|
90
|
-
if (angularPkgJson.name) {
|
|
91
|
-
angularPackageName = angularPkgJson.name;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
catch (e) {
|
|
95
|
-
throw new Error(`Could not read Angular library package.json at ${angularPkgJsonPath}. ` +
|
|
96
|
-
`The package name is required to generate the transformTag patch script.`);
|
|
97
|
-
}
|
|
98
|
-
if (!angularPackageName) {
|
|
99
|
-
throw new Error(`Angular library package.json at ${angularPkgJsonPath} does not have a "name" field. ` +
|
|
100
|
-
`The package name is required to generate the transformTag patch script.`);
|
|
101
|
-
}
|
|
102
|
-
tasks.push(generateTransformTagScript(compilerCtx, filteredComponents, outputTarget, angularPackageName));
|
|
120
|
+
tasks.push(generateTransformTagScript(compilerCtx, filteredComponents, outputTarget, usesExportMaps(config)));
|
|
103
121
|
}
|
|
104
122
|
await Promise.all(tasks);
|
|
105
123
|
}
|
|
@@ -123,10 +141,7 @@ async function copyResources(config, outputTarget) {
|
|
|
123
141
|
], srcDirectory);
|
|
124
142
|
}
|
|
125
143
|
export function generateProxies(components, pkgData, outputTarget, rootDir, config) {
|
|
126
|
-
const distTypesDir = path.dirname(pkgData.types);
|
|
127
|
-
const dtsFilePath = path.join(rootDir, distTypesDir, GENERATED_DTS);
|
|
128
144
|
const { outputType } = outputTarget;
|
|
129
|
-
const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
|
|
130
145
|
const includeSingleComponentAngularModules = outputType === OutputTypes.Scam;
|
|
131
146
|
const isCustomElementsBuild = isOutputTypeCustomElementsBuild(outputType);
|
|
132
147
|
const isStandaloneBuild = outputType === OutputTypes.Standalone;
|
|
@@ -168,7 +183,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
168
183
|
const generateTypeImports = () => {
|
|
169
184
|
const importLocation = outputTarget.componentCorePackage
|
|
170
185
|
? getPathToComponentTypes(config, outputTarget)
|
|
171
|
-
: normalizePath(
|
|
186
|
+
: normalizePath(getComponentsTypeFile(pkgData, outputTarget, rootDir));
|
|
172
187
|
return `import ${isCustomElementsBuild ? 'type ' : ''}{ ${IMPORT_TYPES} } from '${importLocation}';\n`;
|
|
173
188
|
};
|
|
174
189
|
const typeImports = generateTypeImports();
|
|
@@ -182,7 +197,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
182
197
|
if (isCustomElementsBuild && outputTarget.componentCorePackage !== undefined) {
|
|
183
198
|
const cmpImports = components.map((component) => {
|
|
184
199
|
const pascalImport = dashToPascalCase(component.tagName);
|
|
185
|
-
return `import { defineCustomElement as define${pascalImport} } from '${
|
|
200
|
+
return `import { defineCustomElement as define${pascalImport} } from '${getComponentModule(config, outputTarget, component.tagName)}';`;
|
|
186
201
|
});
|
|
187
202
|
sourceImports = cmpImports.join('\n');
|
|
188
203
|
}
|
|
@@ -212,7 +227,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
212
227
|
*/
|
|
213
228
|
const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, orderedInputs, methods, isCustomElementsBuild, isStandaloneBuild, inlineComponentProps, cmpMeta.events || []);
|
|
214
229
|
const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
|
|
215
|
-
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir);
|
|
230
|
+
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir, getEventTypesModule(config, outputTarget));
|
|
216
231
|
proxyFileOutput.push(componentDefinition, '\n');
|
|
217
232
|
if (includeSingleComponentAngularModules) {
|
|
218
233
|
proxyFileOutput.push(moduleDefinition, '\n');
|
|
@@ -227,9 +242,6 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
227
242
|
*/
|
|
228
243
|
export function generateComponentProxy(cmpMeta, pkgData, outputTarget, rootDir, config) {
|
|
229
244
|
const { outputType, componentCorePackage, customElementsDir } = outputTarget;
|
|
230
|
-
const distTypesDir = path.dirname(pkgData.types);
|
|
231
|
-
const dtsFilePath = path.join(rootDir, distTypesDir, GENERATED_DTS);
|
|
232
|
-
const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
|
|
233
245
|
const includeSingleComponentAngularModules = outputType === OutputTypes.Scam;
|
|
234
246
|
const isCustomElementsBuild = isOutputTypeCustomElementsBuild(outputType);
|
|
235
247
|
const isStandaloneBuild = outputType === OutputTypes.Standalone;
|
|
@@ -258,12 +270,12 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
258
270
|
// Type imports
|
|
259
271
|
const importLocation = componentCorePackage
|
|
260
272
|
? getPathToComponentTypes(config, outputTarget)
|
|
261
|
-
: normalizePath(
|
|
273
|
+
: normalizePath(getComponentsTypeFile(pkgData, outputTarget, rootDir));
|
|
262
274
|
const typeImports = `import ${isCustomElementsBuild ? 'type ' : ''}{ ${IMPORT_TYPES} } from '${importLocation}';\n`;
|
|
263
275
|
// defineCustomElement import
|
|
264
276
|
let sourceImport = '';
|
|
265
277
|
if (isCustomElementsBuild && componentCorePackage !== undefined) {
|
|
266
|
-
sourceImport = `import { defineCustomElement as define${tagNameAsPascal} } from '${
|
|
278
|
+
sourceImport = `import { defineCustomElement as define${tagNameAsPascal} } from '${getComponentModule(config, outputTarget, cmpMeta.tagName)}';\n`;
|
|
267
279
|
}
|
|
268
280
|
// Generate component definition
|
|
269
281
|
const internalProps = [];
|
|
@@ -282,7 +294,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
282
294
|
const inlineComponentProps = outputTarget.inlineProperties ? internalProps : [];
|
|
283
295
|
const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, orderedInputs, methods, isCustomElementsBuild, isStandaloneBuild, inlineComponentProps, cmpMeta.events || []);
|
|
284
296
|
const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
|
|
285
|
-
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir);
|
|
297
|
+
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir, getEventTypesModule(config, outputTarget));
|
|
286
298
|
const proxyFileOutput = [componentDefinition, '\n'];
|
|
287
299
|
if (includeSingleComponentAngularModules) {
|
|
288
300
|
proxyFileOutput.push(moduleDefinition, '\n');
|
|
@@ -313,6 +325,10 @@ export function generateBarrelFile(components, outputTarget) {
|
|
|
313
325
|
}
|
|
314
326
|
export function getPathToComponentTypes(config, outputTarget) {
|
|
315
327
|
const basePkg = outputTarget.componentCorePackage || '';
|
|
328
|
+
// for Stencil v5 use the `<pkg>/components` export entry when `generateExportMaps` is enabled
|
|
329
|
+
if (usesExportMaps(config)) {
|
|
330
|
+
return `${normalizePath(basePkg)}/components`;
|
|
331
|
+
}
|
|
316
332
|
// in v5, all types (including components.d.ts) are generated in the dist/types directory
|
|
317
333
|
const typesTarget = config.outputTargets?.find((o) => o.type === 'types');
|
|
318
334
|
if (typesTarget) {
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type { Config
|
|
1
|
+
import type { Config } from '@stencil/core';
|
|
2
2
|
import type { OutputTargetAngular } from './types';
|
|
3
|
+
type OutputTargetCustom = Extract<NonNullable<Config['outputTargets']>[number], {
|
|
4
|
+
type: 'custom';
|
|
5
|
+
}>;
|
|
6
|
+
type PluginConfig = Parameters<OutputTargetCustom['generator']>[0];
|
|
3
7
|
export declare const angularOutputTarget: (outputTarget: OutputTargetAngular) => OutputTargetCustom;
|
|
4
|
-
export declare function normalizeOutputTarget(config:
|
|
8
|
+
export declare function normalizeOutputTarget(config: PluginConfig, outputTarget: OutputTargetAngular): OutputTargetAngular;
|
|
9
|
+
export {};
|
package/dist/utils.d.ts
CHANGED
|
@@ -44,4 +44,9 @@ export declare const createComponentEventTypeImports: (componentTagName: string,
|
|
|
44
44
|
componentCorePackage: string;
|
|
45
45
|
customElementsDir?: string;
|
|
46
46
|
outputType: OutputType;
|
|
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;
|
|
47
52
|
}) => string;
|
package/dist/utils.js
CHANGED
|
@@ -118,7 +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 importPathName = normalizePath(componentCorePackage) + (isCustomElementsBuild ? `/${customElementsDir}` : '');
|
|
121
|
+
const importPathName = options.typesModule ?? normalizePath(componentCorePackage) + (isCustomElementsBuild ? `/${customElementsDir}` : '');
|
|
122
122
|
/**
|
|
123
123
|
* Each component's events are typed with the per-component CustomEvent type
|
|
124
124
|
* generated by Stencil (e.g. `MyComponentCustomEvent<Detail>`), which carries a
|
package/dist/wizard.js
CHANGED
|
@@ -49,6 +49,19 @@ async function allowPnpmBuild(pkg, rootDir, workspaceRoot) {
|
|
|
49
49
|
// ---------------------------------------------------------------------------
|
|
50
50
|
// Wrapper package scaffolding
|
|
51
51
|
// ---------------------------------------------------------------------------
|
|
52
|
+
/**
|
|
53
|
+
* The core package's real npm name. This is not always its lowercased namespace
|
|
54
|
+
* (`testy-test` vs `testytest`), and it's what the wrapper has to depend on and import from.
|
|
55
|
+
*/
|
|
56
|
+
async function readCorePackageName(rootDir, fallback) {
|
|
57
|
+
try {
|
|
58
|
+
const { name } = JSON.parse(await readFile(join(rootDir, 'package.json'), 'utf8'));
|
|
59
|
+
return typeof name === 'string' && name ? name : fallback;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return fallback;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
52
65
|
async function pathExists(p) {
|
|
53
66
|
try {
|
|
54
67
|
await access(p);
|
|
@@ -212,7 +225,7 @@ export const wizard = {
|
|
|
212
225
|
const directivesArrayFile = selectedOutputType === 'component'
|
|
213
226
|
? relative(config.rootDir, join(wrapperDir, 'src', 'lib', 'directives.array.ts')).replace(/\\/g, '/')
|
|
214
227
|
: undefined;
|
|
215
|
-
const componentCorePackage = config.fsNamespace;
|
|
228
|
+
const componentCorePackage = await readCorePackageName(config.rootDir, config.fsNamespace);
|
|
216
229
|
// Scaffold wrapper package if the directory doesn't exist yet
|
|
217
230
|
const shouldScaffold = !(await pathExists(wrapperDir));
|
|
218
231
|
if (shouldScaffold) {
|
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.2",
|
|
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-
|
|
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-
|
|
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
|
}
|