@stencil/angular-output-target 1.5.0 → 1.5.1
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 +54 -37
- package/dist/index.js +54 -37
- package/dist/output-angular.d.ts +6 -0
- package/dist/output-angular.js +42 -33
- package/dist/plugin.d.ts +7 -2
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +3 -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 exportMaps Import through the package's `exports` map instead of a deep path.
|
|
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, exportMaps?: boolean) => 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 exportMaps Import through the package's `exports` map instead of a deep path.
|
|
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, exportMaps = false) => {
|
|
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
|
+
exportMaps,
|
|
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,9 @@ const createComponentEventTypeImports = (componentTagName, events, options) => {
|
|
|
126
126
|
const imports = [];
|
|
127
127
|
const namedImports = new Set();
|
|
128
128
|
const isCustomElementsBuild = isOutputTypeCustomElementsBuild(options.outputType);
|
|
129
|
-
const
|
|
129
|
+
const exportMapEntry = isCustomElementsBuild ? '/standalone' : '/loader';
|
|
130
|
+
const importPathName = normalizePath(componentCorePackage) +
|
|
131
|
+
(options.exportMaps ? exportMapEntry : isCustomElementsBuild ? `/${customElementsDir}` : '');
|
|
130
132
|
/**
|
|
131
133
|
* Each component's events are typed with the per-component CustomEvent type
|
|
132
134
|
* generated by Stencil (e.g. `MyComponentCustomEvent<Detail>`), which carries a
|
|
@@ -366,14 +368,16 @@ const createDocComment = (doc) => {
|
|
|
366
368
|
* @param events The events to generate the interface properties for.
|
|
367
369
|
* @param componentCorePackage The component core package.
|
|
368
370
|
* @param customElementsDir The custom elements directory.
|
|
371
|
+
* @param exportMaps Import through the package's `exports` map instead of a deep path.
|
|
369
372
|
* @returns The component interface type definition as a string.
|
|
370
373
|
*/
|
|
371
|
-
const createComponentTypeDefinition = (outputType, tagNameAsPascal, events, componentCorePackage, customElementsDir) => {
|
|
374
|
+
const createComponentTypeDefinition = (outputType, tagNameAsPascal, events, componentCorePackage, customElementsDir, exportMaps = false) => {
|
|
372
375
|
const publicEvents = events.filter((ev) => !ev.internal);
|
|
373
376
|
const eventTypeImports = createComponentEventTypeImports(tagNameAsPascal, publicEvents, {
|
|
374
377
|
componentCorePackage,
|
|
375
378
|
customElementsDir,
|
|
376
379
|
outputType,
|
|
380
|
+
exportMaps,
|
|
377
381
|
});
|
|
378
382
|
const eventTypes = publicEvents.map((event) => createPropertyDeclaration(event, `EventEmitter<${tagNameAsPascal}CustomEvent<${formatOutputType(tagNameAsPascal, event)}>>`));
|
|
379
383
|
const interfaceDeclaration = `export declare interface ${tagNameAsPascal} extends Components.${tagNameAsPascal} {`;
|
|
@@ -491,10 +495,14 @@ export class ${moduleClassName} { }`;
|
|
|
491
495
|
* This script patches component selectors in the built Angular library to use the
|
|
492
496
|
* transformed tag names (e.g., 'my-component' -> 'v1-my-component').
|
|
493
497
|
*/
|
|
494
|
-
async function generateTransformTagScript(compilerCtx, components, outputTarget,
|
|
498
|
+
async function generateTransformTagScript(compilerCtx, components, outputTarget,
|
|
499
|
+
/** Import through the package's `exports` map (`<pkg>/standalone`) instead of a deep path. */
|
|
500
|
+
exportMaps = false) {
|
|
495
501
|
const scriptsDirectory = path__default["default"].join(path__default["default"].dirname(outputTarget.directivesProxyFile), '../../scripts');
|
|
496
502
|
const customElementsDir = outputTarget.customElementsDir || 'dist/components';
|
|
497
|
-
const stencilImportPath =
|
|
503
|
+
const stencilImportPath = exportMaps
|
|
504
|
+
? `${outputTarget.componentCorePackage}/standalone`
|
|
505
|
+
: `${outputTarget.componentCorePackage}/${customElementsDir}/index.js`;
|
|
498
506
|
// Generate the mappings object
|
|
499
507
|
const mappings = components
|
|
500
508
|
.map((component) => {
|
|
@@ -832,6 +840,35 @@ const mapInputProp = (prop, booleanAttributes = false) => ({
|
|
|
832
840
|
* @returns `true` when at least one property is transformed.
|
|
833
841
|
*/
|
|
834
842
|
const usesInputTransform = (components, booleanAttributes) => components.some((cmpMeta) => (cmpMeta.properties ?? []).filter(filterInternalProps).some((prop) => isTransformedProp(prop, booleanAttributes)));
|
|
843
|
+
/**
|
|
844
|
+
* Whether the Stencil project generates a package.json `exports` map. Deep `dist/` imports are
|
|
845
|
+
* blocked for consumers then, so the proxies import through the map's entries instead
|
|
846
|
+
* (`<pkg>/<tag>`, `<pkg>/loader`, `<pkg>/standalone`).
|
|
847
|
+
*/
|
|
848
|
+
function usesExportMaps(config) {
|
|
849
|
+
// Stencil v5 only: v4's map has no `./standalone` entry, and its root types aren't
|
|
850
|
+
// guaranteed to export the component types.
|
|
851
|
+
const isV5 = (config.outputTargets || []).some((o) => ['loader-bundle', 'standalone', 'ssr', 'types'].includes(o.type));
|
|
852
|
+
return isV5 && config.generateExportMaps === true;
|
|
853
|
+
}
|
|
854
|
+
/**
|
|
855
|
+
* The module specifier a proxy imports a component's `defineCustomElement` from.
|
|
856
|
+
*/
|
|
857
|
+
function getComponentModule(config, outputTarget, tagName) {
|
|
858
|
+
const basePkg = normalizePath(outputTarget.componentCorePackage);
|
|
859
|
+
if (usesExportMaps(config)) {
|
|
860
|
+
return `${basePkg}/${tagName}`;
|
|
861
|
+
}
|
|
862
|
+
return `${basePkg}/${outputTarget.customElementsDir}/${tagName}.js`;
|
|
863
|
+
}
|
|
864
|
+
/**
|
|
865
|
+
* The relative import of the project's own `components.d.ts`, for when there's no
|
|
866
|
+
* `componentCorePackage`. Only resolved when needed: package.json may have no `types` field.
|
|
867
|
+
*/
|
|
868
|
+
function getComponentsTypeFile(pkgData, outputTarget, rootDir) {
|
|
869
|
+
const dtsFilePath = path__default["default"].join(rootDir, path__default["default"].dirname(pkgData.types), GENERATED_DTS);
|
|
870
|
+
return relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
|
|
871
|
+
}
|
|
835
872
|
async function angularDirectiveProxyOutput(compilerCtx, outputTarget, components, config) {
|
|
836
873
|
const filteredComponents = getFilteredComponents(outputTarget.excludeComponents, components);
|
|
837
874
|
const rootDir = config.rootDir;
|
|
@@ -865,27 +902,7 @@ async function angularDirectiveProxyOutput(compilerCtx, outputTarget, components
|
|
|
865
902
|
}
|
|
866
903
|
// Generate transformer script if transformTag is enabled
|
|
867
904
|
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));
|
|
905
|
+
tasks.push(generateTransformTagScript(compilerCtx, filteredComponents, outputTarget, usesExportMaps(config)));
|
|
889
906
|
}
|
|
890
907
|
await Promise.all(tasks);
|
|
891
908
|
}
|
|
@@ -909,10 +926,7 @@ async function copyResources(config, outputTarget) {
|
|
|
909
926
|
], srcDirectory);
|
|
910
927
|
}
|
|
911
928
|
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
929
|
const { outputType } = outputTarget;
|
|
915
|
-
const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
|
|
916
930
|
const includeSingleComponentAngularModules = outputType === OutputTypes.Scam;
|
|
917
931
|
const isCustomElementsBuild = isOutputTypeCustomElementsBuild(outputType);
|
|
918
932
|
const isStandaloneBuild = outputType === OutputTypes.Standalone;
|
|
@@ -954,7 +968,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
954
968
|
const generateTypeImports = () => {
|
|
955
969
|
const importLocation = outputTarget.componentCorePackage
|
|
956
970
|
? getPathToComponentTypes(config, outputTarget)
|
|
957
|
-
: normalizePath(
|
|
971
|
+
: normalizePath(getComponentsTypeFile(pkgData, outputTarget, rootDir));
|
|
958
972
|
return `import ${isCustomElementsBuild ? 'type ' : ''}{ ${IMPORT_TYPES} } from '${importLocation}';\n`;
|
|
959
973
|
};
|
|
960
974
|
const typeImports = generateTypeImports();
|
|
@@ -968,7 +982,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
968
982
|
if (isCustomElementsBuild && outputTarget.componentCorePackage !== undefined) {
|
|
969
983
|
const cmpImports = components.map((component) => {
|
|
970
984
|
const pascalImport = dashToPascalCase(component.tagName);
|
|
971
|
-
return `import { defineCustomElement as define${pascalImport} } from '${
|
|
985
|
+
return `import { defineCustomElement as define${pascalImport} } from '${getComponentModule(config, outputTarget, component.tagName)}';`;
|
|
972
986
|
});
|
|
973
987
|
sourceImports = cmpImports.join('\n');
|
|
974
988
|
}
|
|
@@ -998,7 +1012,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
998
1012
|
*/
|
|
999
1013
|
const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, orderedInputs, methods, isCustomElementsBuild, isStandaloneBuild, inlineComponentProps, cmpMeta.events || []);
|
|
1000
1014
|
const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
|
|
1001
|
-
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir);
|
|
1015
|
+
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir, usesExportMaps(config));
|
|
1002
1016
|
proxyFileOutput.push(componentDefinition, '\n');
|
|
1003
1017
|
if (includeSingleComponentAngularModules) {
|
|
1004
1018
|
proxyFileOutput.push(moduleDefinition, '\n');
|
|
@@ -1013,9 +1027,6 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
1013
1027
|
*/
|
|
1014
1028
|
function generateComponentProxy(cmpMeta, pkgData, outputTarget, rootDir, config) {
|
|
1015
1029
|
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
1030
|
const includeSingleComponentAngularModules = outputType === OutputTypes.Scam;
|
|
1020
1031
|
const isCustomElementsBuild = isOutputTypeCustomElementsBuild(outputType);
|
|
1021
1032
|
const isStandaloneBuild = outputType === OutputTypes.Standalone;
|
|
@@ -1044,12 +1055,12 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
1044
1055
|
// Type imports
|
|
1045
1056
|
const importLocation = componentCorePackage
|
|
1046
1057
|
? getPathToComponentTypes(config, outputTarget)
|
|
1047
|
-
: normalizePath(
|
|
1058
|
+
: normalizePath(getComponentsTypeFile(pkgData, outputTarget, rootDir));
|
|
1048
1059
|
const typeImports = `import ${isCustomElementsBuild ? 'type ' : ''}{ ${IMPORT_TYPES} } from '${importLocation}';\n`;
|
|
1049
1060
|
// defineCustomElement import
|
|
1050
1061
|
let sourceImport = '';
|
|
1051
1062
|
if (isCustomElementsBuild && componentCorePackage !== undefined) {
|
|
1052
|
-
sourceImport = `import { defineCustomElement as define${tagNameAsPascal} } from '${
|
|
1063
|
+
sourceImport = `import { defineCustomElement as define${tagNameAsPascal} } from '${getComponentModule(config, outputTarget, cmpMeta.tagName)}';\n`;
|
|
1053
1064
|
}
|
|
1054
1065
|
// Generate component definition
|
|
1055
1066
|
const internalProps = [];
|
|
@@ -1068,7 +1079,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
1068
1079
|
const inlineComponentProps = outputTarget.inlineProperties ? internalProps : [];
|
|
1069
1080
|
const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, orderedInputs, methods, isCustomElementsBuild, isStandaloneBuild, inlineComponentProps, cmpMeta.events || []);
|
|
1070
1081
|
const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
|
|
1071
|
-
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir);
|
|
1082
|
+
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir, usesExportMaps(config));
|
|
1072
1083
|
const proxyFileOutput = [componentDefinition, '\n'];
|
|
1073
1084
|
if (includeSingleComponentAngularModules) {
|
|
1074
1085
|
proxyFileOutput.push(moduleDefinition, '\n');
|
|
@@ -1099,6 +1110,12 @@ function generateBarrelFile(components, outputTarget) {
|
|
|
1099
1110
|
}
|
|
1100
1111
|
function getPathToComponentTypes(config, outputTarget) {
|
|
1101
1112
|
const basePkg = outputTarget.componentCorePackage || '';
|
|
1113
|
+
// The entry of the output the proxies are built on always exports the component types - the
|
|
1114
|
+
// package root only does when the project has no `src/index.ts`, or that file re-exports them
|
|
1115
|
+
if (usesExportMaps(config)) {
|
|
1116
|
+
const entry = isOutputTypeCustomElementsBuild(outputTarget.outputType) ? 'standalone' : 'loader';
|
|
1117
|
+
return `${normalizePath(basePkg)}/${entry}`;
|
|
1118
|
+
}
|
|
1102
1119
|
// in v5, all types (including components.d.ts) are generated in the dist/types directory
|
|
1103
1120
|
const typesTarget = config.outputTargets?.find((o) => o.type === 'types');
|
|
1104
1121
|
if (typesTarget) {
|
package/dist/index.js
CHANGED
|
@@ -118,7 +118,9 @@ const createComponentEventTypeImports = (componentTagName, events, options) => {
|
|
|
118
118
|
const imports = [];
|
|
119
119
|
const namedImports = new Set();
|
|
120
120
|
const isCustomElementsBuild = isOutputTypeCustomElementsBuild(options.outputType);
|
|
121
|
-
const
|
|
121
|
+
const exportMapEntry = isCustomElementsBuild ? '/standalone' : '/loader';
|
|
122
|
+
const importPathName = normalizePath(componentCorePackage) +
|
|
123
|
+
(options.exportMaps ? exportMapEntry : isCustomElementsBuild ? `/${customElementsDir}` : '');
|
|
122
124
|
/**
|
|
123
125
|
* Each component's events are typed with the per-component CustomEvent type
|
|
124
126
|
* generated by Stencil (e.g. `MyComponentCustomEvent<Detail>`), which carries a
|
|
@@ -358,14 +360,16 @@ const createDocComment = (doc) => {
|
|
|
358
360
|
* @param events The events to generate the interface properties for.
|
|
359
361
|
* @param componentCorePackage The component core package.
|
|
360
362
|
* @param customElementsDir The custom elements directory.
|
|
363
|
+
* @param exportMaps Import through the package's `exports` map instead of a deep path.
|
|
361
364
|
* @returns The component interface type definition as a string.
|
|
362
365
|
*/
|
|
363
|
-
const createComponentTypeDefinition = (outputType, tagNameAsPascal, events, componentCorePackage, customElementsDir) => {
|
|
366
|
+
const createComponentTypeDefinition = (outputType, tagNameAsPascal, events, componentCorePackage, customElementsDir, exportMaps = false) => {
|
|
364
367
|
const publicEvents = events.filter((ev) => !ev.internal);
|
|
365
368
|
const eventTypeImports = createComponentEventTypeImports(tagNameAsPascal, publicEvents, {
|
|
366
369
|
componentCorePackage,
|
|
367
370
|
customElementsDir,
|
|
368
371
|
outputType,
|
|
372
|
+
exportMaps,
|
|
369
373
|
});
|
|
370
374
|
const eventTypes = publicEvents.map((event) => createPropertyDeclaration(event, `EventEmitter<${tagNameAsPascal}CustomEvent<${formatOutputType(tagNameAsPascal, event)}>>`));
|
|
371
375
|
const interfaceDeclaration = `export declare interface ${tagNameAsPascal} extends Components.${tagNameAsPascal} {`;
|
|
@@ -483,10 +487,14 @@ export class ${moduleClassName} { }`;
|
|
|
483
487
|
* This script patches component selectors in the built Angular library to use the
|
|
484
488
|
* transformed tag names (e.g., 'my-component' -> 'v1-my-component').
|
|
485
489
|
*/
|
|
486
|
-
async function generateTransformTagScript(compilerCtx, components, outputTarget,
|
|
490
|
+
async function generateTransformTagScript(compilerCtx, components, outputTarget,
|
|
491
|
+
/** Import through the package's `exports` map (`<pkg>/standalone`) instead of a deep path. */
|
|
492
|
+
exportMaps = false) {
|
|
487
493
|
const scriptsDirectory = path.join(path.dirname(outputTarget.directivesProxyFile), '../../scripts');
|
|
488
494
|
const customElementsDir = outputTarget.customElementsDir || 'dist/components';
|
|
489
|
-
const stencilImportPath =
|
|
495
|
+
const stencilImportPath = exportMaps
|
|
496
|
+
? `${outputTarget.componentCorePackage}/standalone`
|
|
497
|
+
: `${outputTarget.componentCorePackage}/${customElementsDir}/index.js`;
|
|
490
498
|
// Generate the mappings object
|
|
491
499
|
const mappings = components
|
|
492
500
|
.map((component) => {
|
|
@@ -824,6 +832,35 @@ const mapInputProp = (prop, booleanAttributes = false) => ({
|
|
|
824
832
|
* @returns `true` when at least one property is transformed.
|
|
825
833
|
*/
|
|
826
834
|
const usesInputTransform = (components, booleanAttributes) => components.some((cmpMeta) => (cmpMeta.properties ?? []).filter(filterInternalProps).some((prop) => isTransformedProp(prop, booleanAttributes)));
|
|
835
|
+
/**
|
|
836
|
+
* Whether the Stencil project generates a package.json `exports` map. Deep `dist/` imports are
|
|
837
|
+
* blocked for consumers then, so the proxies import through the map's entries instead
|
|
838
|
+
* (`<pkg>/<tag>`, `<pkg>/loader`, `<pkg>/standalone`).
|
|
839
|
+
*/
|
|
840
|
+
function usesExportMaps(config) {
|
|
841
|
+
// Stencil v5 only: v4's map has no `./standalone` entry, and its root types aren't
|
|
842
|
+
// guaranteed to export the component types.
|
|
843
|
+
const isV5 = (config.outputTargets || []).some((o) => ['loader-bundle', 'standalone', 'ssr', 'types'].includes(o.type));
|
|
844
|
+
return isV5 && config.generateExportMaps === true;
|
|
845
|
+
}
|
|
846
|
+
/**
|
|
847
|
+
* The module specifier a proxy imports a component's `defineCustomElement` from.
|
|
848
|
+
*/
|
|
849
|
+
function getComponentModule(config, outputTarget, tagName) {
|
|
850
|
+
const basePkg = normalizePath(outputTarget.componentCorePackage);
|
|
851
|
+
if (usesExportMaps(config)) {
|
|
852
|
+
return `${basePkg}/${tagName}`;
|
|
853
|
+
}
|
|
854
|
+
return `${basePkg}/${outputTarget.customElementsDir}/${tagName}.js`;
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* The relative import of the project's own `components.d.ts`, for when there's no
|
|
858
|
+
* `componentCorePackage`. Only resolved when needed: package.json may have no `types` field.
|
|
859
|
+
*/
|
|
860
|
+
function getComponentsTypeFile(pkgData, outputTarget, rootDir) {
|
|
861
|
+
const dtsFilePath = path.join(rootDir, path.dirname(pkgData.types), GENERATED_DTS);
|
|
862
|
+
return relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
|
|
863
|
+
}
|
|
827
864
|
async function angularDirectiveProxyOutput(compilerCtx, outputTarget, components, config) {
|
|
828
865
|
const filteredComponents = getFilteredComponents(outputTarget.excludeComponents, components);
|
|
829
866
|
const rootDir = config.rootDir;
|
|
@@ -857,27 +894,7 @@ async function angularDirectiveProxyOutput(compilerCtx, outputTarget, components
|
|
|
857
894
|
}
|
|
858
895
|
// Generate transformer script if transformTag is enabled
|
|
859
896
|
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));
|
|
897
|
+
tasks.push(generateTransformTagScript(compilerCtx, filteredComponents, outputTarget, usesExportMaps(config)));
|
|
881
898
|
}
|
|
882
899
|
await Promise.all(tasks);
|
|
883
900
|
}
|
|
@@ -901,10 +918,7 @@ async function copyResources(config, outputTarget) {
|
|
|
901
918
|
], srcDirectory);
|
|
902
919
|
}
|
|
903
920
|
function generateProxies(components, pkgData, outputTarget, rootDir, config) {
|
|
904
|
-
const distTypesDir = path.dirname(pkgData.types);
|
|
905
|
-
const dtsFilePath = path.join(rootDir, distTypesDir, GENERATED_DTS);
|
|
906
921
|
const { outputType } = outputTarget;
|
|
907
|
-
const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
|
|
908
922
|
const includeSingleComponentAngularModules = outputType === OutputTypes.Scam;
|
|
909
923
|
const isCustomElementsBuild = isOutputTypeCustomElementsBuild(outputType);
|
|
910
924
|
const isStandaloneBuild = outputType === OutputTypes.Standalone;
|
|
@@ -946,7 +960,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
946
960
|
const generateTypeImports = () => {
|
|
947
961
|
const importLocation = outputTarget.componentCorePackage
|
|
948
962
|
? getPathToComponentTypes(config, outputTarget)
|
|
949
|
-
: normalizePath(
|
|
963
|
+
: normalizePath(getComponentsTypeFile(pkgData, outputTarget, rootDir));
|
|
950
964
|
return `import ${isCustomElementsBuild ? 'type ' : ''}{ ${IMPORT_TYPES} } from '${importLocation}';\n`;
|
|
951
965
|
};
|
|
952
966
|
const typeImports = generateTypeImports();
|
|
@@ -960,7 +974,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
960
974
|
if (isCustomElementsBuild && outputTarget.componentCorePackage !== undefined) {
|
|
961
975
|
const cmpImports = components.map((component) => {
|
|
962
976
|
const pascalImport = dashToPascalCase(component.tagName);
|
|
963
|
-
return `import { defineCustomElement as define${pascalImport} } from '${
|
|
977
|
+
return `import { defineCustomElement as define${pascalImport} } from '${getComponentModule(config, outputTarget, component.tagName)}';`;
|
|
964
978
|
});
|
|
965
979
|
sourceImports = cmpImports.join('\n');
|
|
966
980
|
}
|
|
@@ -990,7 +1004,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
990
1004
|
*/
|
|
991
1005
|
const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, orderedInputs, methods, isCustomElementsBuild, isStandaloneBuild, inlineComponentProps, cmpMeta.events || []);
|
|
992
1006
|
const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
|
|
993
|
-
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir);
|
|
1007
|
+
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir, usesExportMaps(config));
|
|
994
1008
|
proxyFileOutput.push(componentDefinition, '\n');
|
|
995
1009
|
if (includeSingleComponentAngularModules) {
|
|
996
1010
|
proxyFileOutput.push(moduleDefinition, '\n');
|
|
@@ -1005,9 +1019,6 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
1005
1019
|
*/
|
|
1006
1020
|
function generateComponentProxy(cmpMeta, pkgData, outputTarget, rootDir, config) {
|
|
1007
1021
|
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
1022
|
const includeSingleComponentAngularModules = outputType === OutputTypes.Scam;
|
|
1012
1023
|
const isCustomElementsBuild = isOutputTypeCustomElementsBuild(outputType);
|
|
1013
1024
|
const isStandaloneBuild = outputType === OutputTypes.Standalone;
|
|
@@ -1036,12 +1047,12 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
1036
1047
|
// Type imports
|
|
1037
1048
|
const importLocation = componentCorePackage
|
|
1038
1049
|
? getPathToComponentTypes(config, outputTarget)
|
|
1039
|
-
: normalizePath(
|
|
1050
|
+
: normalizePath(getComponentsTypeFile(pkgData, outputTarget, rootDir));
|
|
1040
1051
|
const typeImports = `import ${isCustomElementsBuild ? 'type ' : ''}{ ${IMPORT_TYPES} } from '${importLocation}';\n`;
|
|
1041
1052
|
// defineCustomElement import
|
|
1042
1053
|
let sourceImport = '';
|
|
1043
1054
|
if (isCustomElementsBuild && componentCorePackage !== undefined) {
|
|
1044
|
-
sourceImport = `import { defineCustomElement as define${tagNameAsPascal} } from '${
|
|
1055
|
+
sourceImport = `import { defineCustomElement as define${tagNameAsPascal} } from '${getComponentModule(config, outputTarget, cmpMeta.tagName)}';\n`;
|
|
1045
1056
|
}
|
|
1046
1057
|
// Generate component definition
|
|
1047
1058
|
const internalProps = [];
|
|
@@ -1060,7 +1071,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
1060
1071
|
const inlineComponentProps = outputTarget.inlineProperties ? internalProps : [];
|
|
1061
1072
|
const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, orderedInputs, methods, isCustomElementsBuild, isStandaloneBuild, inlineComponentProps, cmpMeta.events || []);
|
|
1062
1073
|
const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
|
|
1063
|
-
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir);
|
|
1074
|
+
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir, usesExportMaps(config));
|
|
1064
1075
|
const proxyFileOutput = [componentDefinition, '\n'];
|
|
1065
1076
|
if (includeSingleComponentAngularModules) {
|
|
1066
1077
|
proxyFileOutput.push(moduleDefinition, '\n');
|
|
@@ -1091,6 +1102,12 @@ function generateBarrelFile(components, outputTarget) {
|
|
|
1091
1102
|
}
|
|
1092
1103
|
function getPathToComponentTypes(config, outputTarget) {
|
|
1093
1104
|
const basePkg = outputTarget.componentCorePackage || '';
|
|
1105
|
+
// The entry of the output the proxies are built on always exports the component types - the
|
|
1106
|
+
// package root only does when the project has no `src/index.ts`, or that file re-exports them
|
|
1107
|
+
if (usesExportMaps(config)) {
|
|
1108
|
+
const entry = isOutputTypeCustomElementsBuild(outputTarget.outputType) ? 'standalone' : 'loader';
|
|
1109
|
+
return `${normalizePath(basePkg)}/${entry}`;
|
|
1110
|
+
}
|
|
1094
1111
|
// in v5, all types (including components.d.ts) are generated in the dist/types directory
|
|
1095
1112
|
const typesTarget = config.outputTargets?.find((o) => o.type === 'types');
|
|
1096
1113
|
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>/loader`, `<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,35 @@ 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>/loader`, `<pkg>/standalone`).
|
|
53
|
+
*/
|
|
54
|
+
export function usesExportMaps(config) {
|
|
55
|
+
// Stencil v5 only: v4's map has no `./standalone` entry, and its root types aren't
|
|
56
|
+
// guaranteed to export the component types.
|
|
57
|
+
const isV5 = (config.outputTargets || []).some((o) => ['loader-bundle', 'standalone', 'ssr', 'types'].includes(o.type));
|
|
58
|
+
return isV5 && config.generateExportMaps === true;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The module specifier a proxy imports a component's `defineCustomElement` from.
|
|
62
|
+
*/
|
|
63
|
+
function getComponentModule(config, outputTarget, tagName) {
|
|
64
|
+
const basePkg = normalizePath(outputTarget.componentCorePackage);
|
|
65
|
+
if (usesExportMaps(config)) {
|
|
66
|
+
return `${basePkg}/${tagName}`;
|
|
67
|
+
}
|
|
68
|
+
return `${basePkg}/${outputTarget.customElementsDir}/${tagName}.js`;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The relative import of the project's own `components.d.ts`, for when there's no
|
|
72
|
+
* `componentCorePackage`. Only resolved when needed: package.json may have no `types` field.
|
|
73
|
+
*/
|
|
74
|
+
function getComponentsTypeFile(pkgData, outputTarget, rootDir) {
|
|
75
|
+
const dtsFilePath = path.join(rootDir, path.dirname(pkgData.types), GENERATED_DTS);
|
|
76
|
+
return relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
|
|
77
|
+
}
|
|
49
78
|
export async function angularDirectiveProxyOutput(compilerCtx, outputTarget, components, config) {
|
|
50
79
|
const filteredComponents = getFilteredComponents(outputTarget.excludeComponents, components);
|
|
51
80
|
const rootDir = config.rootDir;
|
|
@@ -79,27 +108,7 @@ export async function angularDirectiveProxyOutput(compilerCtx, outputTarget, com
|
|
|
79
108
|
}
|
|
80
109
|
// Generate transformer script if transformTag is enabled
|
|
81
110
|
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));
|
|
111
|
+
tasks.push(generateTransformTagScript(compilerCtx, filteredComponents, outputTarget, usesExportMaps(config)));
|
|
103
112
|
}
|
|
104
113
|
await Promise.all(tasks);
|
|
105
114
|
}
|
|
@@ -123,10 +132,7 @@ async function copyResources(config, outputTarget) {
|
|
|
123
132
|
], srcDirectory);
|
|
124
133
|
}
|
|
125
134
|
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
135
|
const { outputType } = outputTarget;
|
|
129
|
-
const componentsTypeFile = relativeImport(outputTarget.directivesProxyFile, dtsFilePath, '.d.ts');
|
|
130
136
|
const includeSingleComponentAngularModules = outputType === OutputTypes.Scam;
|
|
131
137
|
const isCustomElementsBuild = isOutputTypeCustomElementsBuild(outputType);
|
|
132
138
|
const isStandaloneBuild = outputType === OutputTypes.Standalone;
|
|
@@ -168,7 +174,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
168
174
|
const generateTypeImports = () => {
|
|
169
175
|
const importLocation = outputTarget.componentCorePackage
|
|
170
176
|
? getPathToComponentTypes(config, outputTarget)
|
|
171
|
-
: normalizePath(
|
|
177
|
+
: normalizePath(getComponentsTypeFile(pkgData, outputTarget, rootDir));
|
|
172
178
|
return `import ${isCustomElementsBuild ? 'type ' : ''}{ ${IMPORT_TYPES} } from '${importLocation}';\n`;
|
|
173
179
|
};
|
|
174
180
|
const typeImports = generateTypeImports();
|
|
@@ -182,7 +188,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
182
188
|
if (isCustomElementsBuild && outputTarget.componentCorePackage !== undefined) {
|
|
183
189
|
const cmpImports = components.map((component) => {
|
|
184
190
|
const pascalImport = dashToPascalCase(component.tagName);
|
|
185
|
-
return `import { defineCustomElement as define${pascalImport} } from '${
|
|
191
|
+
return `import { defineCustomElement as define${pascalImport} } from '${getComponentModule(config, outputTarget, component.tagName)}';`;
|
|
186
192
|
});
|
|
187
193
|
sourceImports = cmpImports.join('\n');
|
|
188
194
|
}
|
|
@@ -212,7 +218,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
212
218
|
*/
|
|
213
219
|
const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, orderedInputs, methods, isCustomElementsBuild, isStandaloneBuild, inlineComponentProps, cmpMeta.events || []);
|
|
214
220
|
const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
|
|
215
|
-
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir);
|
|
221
|
+
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir, usesExportMaps(config));
|
|
216
222
|
proxyFileOutput.push(componentDefinition, '\n');
|
|
217
223
|
if (includeSingleComponentAngularModules) {
|
|
218
224
|
proxyFileOutput.push(moduleDefinition, '\n');
|
|
@@ -227,9 +233,6 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
227
233
|
*/
|
|
228
234
|
export function generateComponentProxy(cmpMeta, pkgData, outputTarget, rootDir, config) {
|
|
229
235
|
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
236
|
const includeSingleComponentAngularModules = outputType === OutputTypes.Scam;
|
|
234
237
|
const isCustomElementsBuild = isOutputTypeCustomElementsBuild(outputType);
|
|
235
238
|
const isStandaloneBuild = outputType === OutputTypes.Standalone;
|
|
@@ -258,12 +261,12 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
258
261
|
// Type imports
|
|
259
262
|
const importLocation = componentCorePackage
|
|
260
263
|
? getPathToComponentTypes(config, outputTarget)
|
|
261
|
-
: normalizePath(
|
|
264
|
+
: normalizePath(getComponentsTypeFile(pkgData, outputTarget, rootDir));
|
|
262
265
|
const typeImports = `import ${isCustomElementsBuild ? 'type ' : ''}{ ${IMPORT_TYPES} } from '${importLocation}';\n`;
|
|
263
266
|
// defineCustomElement import
|
|
264
267
|
let sourceImport = '';
|
|
265
268
|
if (isCustomElementsBuild && componentCorePackage !== undefined) {
|
|
266
|
-
sourceImport = `import { defineCustomElement as define${tagNameAsPascal} } from '${
|
|
269
|
+
sourceImport = `import { defineCustomElement as define${tagNameAsPascal} } from '${getComponentModule(config, outputTarget, cmpMeta.tagName)}';\n`;
|
|
267
270
|
}
|
|
268
271
|
// Generate component definition
|
|
269
272
|
const internalProps = [];
|
|
@@ -282,7 +285,7 @@ ${createImportStatement(componentLibImports, './angular-component-lib/utils')}${
|
|
|
282
285
|
const inlineComponentProps = outputTarget.inlineProperties ? internalProps : [];
|
|
283
286
|
const componentDefinition = createAngularComponentDefinition(cmpMeta.tagName, orderedInputs, methods, isCustomElementsBuild, isStandaloneBuild, inlineComponentProps, cmpMeta.events || []);
|
|
284
287
|
const moduleDefinition = generateAngularModuleForComponent(cmpMeta.tagName);
|
|
285
|
-
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir);
|
|
288
|
+
const componentTypeDefinition = createComponentTypeDefinition(outputType, tagNameAsPascal, cmpMeta.events, componentCorePackage, customElementsDir, usesExportMaps(config));
|
|
286
289
|
const proxyFileOutput = [componentDefinition, '\n'];
|
|
287
290
|
if (includeSingleComponentAngularModules) {
|
|
288
291
|
proxyFileOutput.push(moduleDefinition, '\n');
|
|
@@ -313,6 +316,12 @@ export function generateBarrelFile(components, outputTarget) {
|
|
|
313
316
|
}
|
|
314
317
|
export function getPathToComponentTypes(config, outputTarget) {
|
|
315
318
|
const basePkg = outputTarget.componentCorePackage || '';
|
|
319
|
+
// The entry of the output the proxies are built on always exports the component types - the
|
|
320
|
+
// package root only does when the project has no `src/index.ts`, or that file re-exports them
|
|
321
|
+
if (usesExportMaps(config)) {
|
|
322
|
+
const entry = isOutputTypeCustomElementsBuild(outputTarget.outputType) ? 'standalone' : 'loader';
|
|
323
|
+
return `${normalizePath(basePkg)}/${entry}`;
|
|
324
|
+
}
|
|
316
325
|
// in v5, all types (including components.d.ts) are generated in the dist/types directory
|
|
317
326
|
const typesTarget = config.outputTargets?.find((o) => o.type === 'types');
|
|
318
327
|
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,6 @@ export declare const createComponentEventTypeImports: (componentTagName: string,
|
|
|
44
44
|
componentCorePackage: string;
|
|
45
45
|
customElementsDir?: string;
|
|
46
46
|
outputType: OutputType;
|
|
47
|
+
/** Import through the package's `exports` map (`./standalone` or `./loader`) instead of a deep path. */
|
|
48
|
+
exportMaps?: boolean;
|
|
47
49
|
}) => string;
|
package/dist/utils.js
CHANGED
|
@@ -118,7 +118,9 @@ 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
|
|
121
|
+
const exportMapEntry = isCustomElementsBuild ? '/standalone' : '/loader';
|
|
122
|
+
const importPathName = normalizePath(componentCorePackage) +
|
|
123
|
+
(options.exportMaps ? exportMapEntry : isCustomElementsBuild ? `/${customElementsDir}` : '');
|
|
122
124
|
/**
|
|
123
125
|
* Each component's events are typed with the per-component CustomEvent type
|
|
124
126
|
* 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.1",
|
|
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.16 <5.0.0-next.0",
|
|
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.16 <5.0.0-next.0"
|
|
73
73
|
},
|
|
74
74
|
"gitHead": "a3588e905186a0e86e7f88418fd5b2f9531b55e0"
|
|
75
75
|
}
|