Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@stencil/angular-output-target

Package Overview
Dependencies
Maintainers
13
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stencil/angular-output-target - npm Package Compare versions

Comparing version 0.0.7 to 0.1.0

19

angular-component-lib/utils.ts

@@ -0,1 +1,3 @@

/* eslint-disable */
/* tslint:disable */
import { fromEvent } from 'rxjs';

@@ -5,3 +7,3 @@

const Prototype = Cmp.prototype;
inputs.forEach((item) => {
inputs.forEach(item => {
Object.defineProperty(Prototype, item, {

@@ -13,3 +15,3 @@ get() {

this.z.runOutsideAngular(() => (this.el[item] = val));
},
}
});

@@ -21,6 +23,8 @@ });

const Prototype = Cmp.prototype;
methods.forEach((methodName) => {
methods.forEach(methodName => {
Prototype[methodName] = function () {
const args = arguments;
return this.z.runOutsideAngular(() => this.el[methodName].apply(this.el, args));
return this.z.runOutsideAngular(() =>
this.el[methodName].apply(this.el, args)
);
};

@@ -31,8 +35,7 @@ });

export const proxyOutputs = (instance: any, el: any, events: string[]) => {
events.forEach((eventName) => (instance[eventName] = fromEvent(el, eventName)));
};
events.forEach(eventName => instance[eventName] = fromEvent(el, eventName));
}
// tslint:disable-next-line: only-arrow-functions
export function ProxyCmp(opts: { inputs?: any; methods?: any }) {
const decorator = function (cls: any) {
const decorator = function(cls: any) {
if (opts.inputs) {

@@ -39,0 +42,0 @@ proxyInputs(cls, opts.inputs);

import path from 'path';
import { dashToPascalCase, normalizePath } from './utils';
import { dashToPascalCase, isRelativePath, normalizePath } from './utils';
export const createComponentDefinition = (componentCorePackage, distTypesDir, rootDir) => (cmpMeta) => {

@@ -28,8 +28,24 @@ // Collect component meta

const importPath = normalizePath(path.join(typePath.dir, typePath.name));
const outputsInterface = outputs.length > 0
? `import { ${cmpMeta.componentClassName} as I${cmpMeta.componentClassName} } from '${importPath}';`
: '';
const outputsInterface = new Set();
const outputReferenceRemap = {};
outputs.forEach((output) => {
Object.entries(output.complexType.references).forEach(([reference, refObject]) => {
// Add import line for each local/import reference, and add new mapping name
// outputReferenceRemap should be updated only if the import interface is set in outputsInterface
// This will prevent global types to be remapped
const remappedReference = `I${cmpMeta.componentClassName}${reference}`;
if (refObject.location === 'local') {
outputReferenceRemap[reference] = remappedReference;
outputsInterface.add(`import { ${reference} as ${remappedReference} } from '${importPath}';`);
}
else if (refObject.location === 'import') {
outputReferenceRemap[reference] = remappedReference;
const interfacePath = normalizePath(isRelativePath(refObject.path) ? path.join(typePath.dir, refObject.path) : refObject.path);
outputsInterface.add(`import { ${reference} as ${remappedReference} } from '${interfacePath}';`);
}
});
});
const lines = [
`
${outputsInterface}
'',
`${[...outputsInterface].join('\n')}
export declare interface ${tagNameAsPascal} extends Components.${tagNameAsPascal} {}

@@ -45,3 +61,16 @@ ${getProxyCmp(inputs, methods)}

lines.push(` /** ${output.docs.text} ${output.docs.tags.map((tag) => `@${tag.name} ${tag.text}`)}*/`);
lines.push(` ${output.name}!: I${cmpMeta.componentClassName}['${output.method}'];`);
/**
* The original attribute contains the original type defined by the devs.
* This regexp normalizes the reference, by removing linebreaks,
* replacing consecutive spaces with a single space, and adding a single space after commas.
**/
const outputTypeRemapped = Object.entries(outputReferenceRemap).reduce((type, [src, dst]) => {
return type
.replace(new RegExp(`^${src}$`, 'g'), `${dst}`)
.replace(new RegExp(`([^\\w])${src}([^\\w])`, 'g'), (v, p1, p2) => [p1, dst, p2].join(''));
}, output.complexType.original
.replace(/\n/g, ' ')
.replace(/\s{2,}/g, ' ')
.replace(/,\s*/g, ', '));
lines.push(` ${output.name}!: EventEmitter<CustomEvent<${outputTypeRemapped.trim()}>>;`);
});

@@ -48,0 +77,0 @@ lines.push(' protected el: HTMLElement;');

@@ -16,3 +16,3 @@ import { dashToPascalCase, relativeImport } from './utils';

export const DIRECTIVES = [
${directives}
${directives}
];

@@ -19,0 +19,0 @@ `;

@@ -69,2 +69,5 @@ 'use strict';

}
function isRelativePath(path) {
return path && path.startsWith('.');
}
async function readPackageJson(rootDir) {

@@ -117,8 +120,24 @@ const pkgJsonPath = path__default['default'].join(rootDir, 'package.json');

const importPath = normalizePath(path__default['default'].join(typePath.dir, typePath.name));
const outputsInterface = outputs.length > 0
? `import { ${cmpMeta.componentClassName} as I${cmpMeta.componentClassName} } from '${importPath}';`
: '';
const outputsInterface = new Set();
const outputReferenceRemap = {};
outputs.forEach((output) => {
Object.entries(output.complexType.references).forEach(([reference, refObject]) => {
// Add import line for each local/import reference, and add new mapping name
// outputReferenceRemap should be updated only if the import interface is set in outputsInterface
// This will prevent global types to be remapped
const remappedReference = `I${cmpMeta.componentClassName}${reference}`;
if (refObject.location === 'local') {
outputReferenceRemap[reference] = remappedReference;
outputsInterface.add(`import { ${reference} as ${remappedReference} } from '${importPath}';`);
}
else if (refObject.location === 'import') {
outputReferenceRemap[reference] = remappedReference;
const interfacePath = normalizePath(isRelativePath(refObject.path) ? path__default['default'].join(typePath.dir, refObject.path) : refObject.path);
outputsInterface.add(`import { ${reference} as ${remappedReference} } from '${interfacePath}';`);
}
});
});
const lines = [
`
${outputsInterface}
'',
`${[...outputsInterface].join('\n')}
export declare interface ${tagNameAsPascal} extends Components.${tagNameAsPascal} {}

@@ -134,3 +153,16 @@ ${getProxyCmp(inputs, methods)}

lines.push(` /** ${output.docs.text} ${output.docs.tags.map((tag) => `@${tag.name} ${tag.text}`)}*/`);
lines.push(` ${output.name}!: I${cmpMeta.componentClassName}['${output.method}'];`);
/**
* The original attribute contains the original type defined by the devs.
* This regexp normalizes the reference, by removing linebreaks,
* replacing consecutive spaces with a single space, and adding a single space after commas.
**/
const outputTypeRemapped = Object.entries(outputReferenceRemap).reduce((type, [src, dst]) => {
return type
.replace(new RegExp(`^${src}$`, 'g'), `${dst}`)
.replace(new RegExp(`([^\\w])${src}([^\\w])`, 'g'), (v, p1, p2) => [p1, dst, p2].join(''));
}, output.complexType.original
.replace(/\n/g, ' ')
.replace(/\s{2,}/g, ' ')
.replace(/,\s*/g, ', '));
lines.push(` ${output.name}!: EventEmitter<CustomEvent<${outputTypeRemapped.trim()}>>;`);
});

@@ -176,3 +208,3 @@ lines.push(' protected el: HTMLElement;');

export const DIRECTIVES = [
${directives}
${directives}
];

@@ -277,3 +309,3 @@ `;

/* auto-generated angular directive proxies */
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, NgZone } from '@angular/core';
import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;

@@ -280,0 +312,0 @@ const typeImports = !outputTarget.componentCorePackage

@@ -60,2 +60,5 @@ import path from 'path';

}
function isRelativePath(path) {
return path && path.startsWith('.');
}
async function readPackageJson(rootDir) {

@@ -108,8 +111,24 @@ const pkgJsonPath = path.join(rootDir, 'package.json');

const importPath = normalizePath(path.join(typePath.dir, typePath.name));
const outputsInterface = outputs.length > 0
? `import { ${cmpMeta.componentClassName} as I${cmpMeta.componentClassName} } from '${importPath}';`
: '';
const outputsInterface = new Set();
const outputReferenceRemap = {};
outputs.forEach((output) => {
Object.entries(output.complexType.references).forEach(([reference, refObject]) => {
// Add import line for each local/import reference, and add new mapping name
// outputReferenceRemap should be updated only if the import interface is set in outputsInterface
// This will prevent global types to be remapped
const remappedReference = `I${cmpMeta.componentClassName}${reference}`;
if (refObject.location === 'local') {
outputReferenceRemap[reference] = remappedReference;
outputsInterface.add(`import { ${reference} as ${remappedReference} } from '${importPath}';`);
}
else if (refObject.location === 'import') {
outputReferenceRemap[reference] = remappedReference;
const interfacePath = normalizePath(isRelativePath(refObject.path) ? path.join(typePath.dir, refObject.path) : refObject.path);
outputsInterface.add(`import { ${reference} as ${remappedReference} } from '${interfacePath}';`);
}
});
});
const lines = [
`
${outputsInterface}
'',
`${[...outputsInterface].join('\n')}
export declare interface ${tagNameAsPascal} extends Components.${tagNameAsPascal} {}

@@ -125,3 +144,16 @@ ${getProxyCmp(inputs, methods)}

lines.push(` /** ${output.docs.text} ${output.docs.tags.map((tag) => `@${tag.name} ${tag.text}`)}*/`);
lines.push(` ${output.name}!: I${cmpMeta.componentClassName}['${output.method}'];`);
/**
* The original attribute contains the original type defined by the devs.
* This regexp normalizes the reference, by removing linebreaks,
* replacing consecutive spaces with a single space, and adding a single space after commas.
**/
const outputTypeRemapped = Object.entries(outputReferenceRemap).reduce((type, [src, dst]) => {
return type
.replace(new RegExp(`^${src}$`, 'g'), `${dst}`)
.replace(new RegExp(`([^\\w])${src}([^\\w])`, 'g'), (v, p1, p2) => [p1, dst, p2].join(''));
}, output.complexType.original
.replace(/\n/g, ' ')
.replace(/\s{2,}/g, ' ')
.replace(/,\s*/g, ', '));
lines.push(` ${output.name}!: EventEmitter<CustomEvent<${outputTypeRemapped.trim()}>>;`);
});

@@ -167,3 +199,3 @@ lines.push(' protected el: HTMLElement;');

export const DIRECTIVES = [
${directives}
${directives}
];

@@ -268,3 +300,3 @@ `;

/* auto-generated angular directive proxies */
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, NgZone } from '@angular/core';
import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;

@@ -271,0 +303,0 @@ const typeImports = !outputTarget.componentCorePackage

@@ -42,3 +42,3 @@ import path from 'path';

/* auto-generated angular directive proxies */
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, NgZone } from '@angular/core';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, EventEmitter, NgZone } from '@angular/core';
import { ProxyCmp, proxyOutputs } from './angular-component-lib/utils';\n`;

@@ -45,0 +45,0 @@ const typeImports = !outputTarget.componentCorePackage

@@ -7,2 +7,3 @@ import type { PackageJSON } from './types';

export declare function relativeImport(pathFrom: string, pathTo: string, ext?: string): string;
export declare function isRelativePath(path: string): boolean | "";
export declare function readPackageJson(rootDir: string): Promise<PackageJSON>;

@@ -58,2 +58,5 @@ import path from 'path';

}
export function isRelativePath(path) {
return path && path.startsWith('.');
}
export async function readPackageJson(rootDir) {

@@ -60,0 +63,0 @@ const pkgJsonPath = path.join(rootDir, 'package.json');

{
"name": "@stencil/angular-output-target",
"version": "0.0.7",
"version": "0.1.0",
"description": "Angular output target for @stencil/core components.",

@@ -5,0 +5,0 @@ "main": "dist/index.cjs.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc