mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2026-03-10 00:00:07 +08:00
BREAKING CHANGE: Minimum Angular version requirement updated to 19.2.14 - Angular Core: 19.0.5 → 19.2.14 (latest Angular 19 LTS) - Zone.js: 0.15.0 → 0.15.1 (latest compatibility) - TypeScript: 5.6.3 (latest supported by Angular 19) Testing Infrastructure Modernization: - Jest: 27.5.1 → 29.7.0 (major upgrade for better performance) - ts-jest: 27.1.5 → 29.3.4 (TypeScript 5.6+ compatibility) - @types/jest: 27.5.2 → 29.5.14 (latest type definitions) - jest-environment-jsdom: Added 29.7.0 (required for Jest 29) - RxJS: 7.8.1 → 7.8.2 (latest patch version) Package Generator Improvements: - Fixed package.json generator to use correct author from main package.json - Updated RxJS peer dependency to ^7.8.0 (modern version range) - Updated core version dependency to use current package version dynamically - Ensured consistency across all generated plugin package.json files This update brings the project to the latest Angular 19 LTS with enhanced testing capabilities, improved build performance, and modernized dependency management. All builds and tests passing successfully.
84 lines
2.4 KiB
TypeScript
84 lines
2.4 KiB
TypeScript
import {
|
|
Decorator,
|
|
factory,
|
|
SourceFile,
|
|
SyntaxKind,
|
|
TransformationContext,
|
|
TransformerFactory,
|
|
visitEachChild,
|
|
} from 'typescript';
|
|
|
|
import { Logger } from '../../logger';
|
|
import { convertValueToLiteral, getDecorator, getDecoratorArgs, getDecoratorName } from '../helpers';
|
|
import { transformMembers } from './members';
|
|
|
|
function transformClass(cls: any, ngcBuild?: boolean) {
|
|
Logger.profile('transformClass: ' + cls.name.text);
|
|
|
|
const pluginStatics = [];
|
|
const dec: Decorator = getDecorator(cls);
|
|
|
|
if (dec) {
|
|
const pluginDecoratorArgs = getDecoratorArgs(dec);
|
|
|
|
// add plugin decorator args as static properties of the plugin's class
|
|
for (const prop in pluginDecoratorArgs) {
|
|
pluginStatics.push(
|
|
factory.createPropertyDeclaration(
|
|
[factory.createToken(SyntaxKind.StaticKeyword)],
|
|
factory.createIdentifier(prop),
|
|
undefined,
|
|
undefined,
|
|
convertValueToLiteral(pluginDecoratorArgs[prop])
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
const decorators =
|
|
ngcBuild && cls.decorators && cls.decorators.length
|
|
? cls.decorators.filter((d: any) => getDecoratorName(d) === 'Injectable')
|
|
: undefined;
|
|
|
|
const modifiers = [factory.createToken(SyntaxKind.ExportKeyword)];
|
|
|
|
cls = factory.createClassDeclaration(
|
|
[...(decorators || []), ...modifiers], // combined decorators and modifiers
|
|
cls.name,
|
|
cls.typeParameters,
|
|
cls.heritageClauses,
|
|
[...transformMembers(cls), ...pluginStatics]
|
|
);
|
|
|
|
Logger.profile('transformClass: ' + cls.name.text);
|
|
return cls;
|
|
}
|
|
|
|
function transformClasses(file: SourceFile, ctx: TransformationContext, ngcBuild?: boolean) {
|
|
Logger.silly('Transforming file: ' + file.fileName);
|
|
return visitEachChild(
|
|
file,
|
|
(node) => {
|
|
if (
|
|
node.kind !== SyntaxKind.ClassDeclaration ||
|
|
((node as any).modifiers && (node as any).modifiers.find((v: any) => v.kind === SyntaxKind.DeclareKeyword))
|
|
) {
|
|
return node;
|
|
}
|
|
return transformClass(node, ngcBuild);
|
|
},
|
|
ctx
|
|
);
|
|
}
|
|
|
|
export function pluginClassTransformer(ngcBuild?: boolean): TransformerFactory<SourceFile> {
|
|
return (ctx: TransformationContext) => {
|
|
return (tsSourceFile) => {
|
|
if (tsSourceFile.fileName.indexOf('src/@awesome-cordova-plugins/plugins') > -1) {
|
|
return transformClasses(tsSourceFile, ctx, ngcBuild);
|
|
}
|
|
return tsSourceFile;
|
|
};
|
|
};
|
|
}
|