@travetto/transformer
Advanced tools
Comparing version 3.0.2 to 3.0.3
{ | ||
"name": "@travetto/transformer", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"description": "Functionality for AST transformations, with transformer registration, and general utils", | ||
@@ -27,3 +27,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@travetto/manifest": "^3.0.2", | ||
"@travetto/manifest": "^3.0.3", | ||
"tslib": "^2.5.0", | ||
@@ -30,0 +30,0 @@ "typescript": "^4.9.5" |
<!-- This file was generated by @travetto/doc and should not be modified directly --> | ||
<!-- Please modify https://github.com/travetto/travetto/tree/main/module/transformer/DOC.ts and execute "npx trv doc" to rebuild --> | ||
<!-- Please modify https://github.com/travetto/travetto/tree/main/module/transformer/DOC.tsx and execute "npx trv doc" to rebuild --> | ||
# Transformation | ||
## Functionality for AST transformations, with transformer registration, and general utils | ||
@@ -17,5 +18,5 @@ | ||
The module is primarily aimed at extremely advanced usages for things that cannot be detected at runtime. The [Registry](https://github.com/travetto/travetto/tree/main/module/registry#readme "Patterns and utilities for handling registration of metadata and functionality for run-time use") module already has knowledge of all `class`es and `field`s, and is able to listen to changes there. Many of the modules build upon work by some of the foundational transformers defined in [Manifest](https://github.com/travetto/travetto/tree/main/module/manifest#readme "Support for project indexing, manifesting, along with file watching"), [Registry](https://github.com/travetto/travetto/tree/main/module/registry#readme "Patterns and utilities for handling registration of metadata and functionality for run-time use"), [Schema](https://github.com/travetto/travetto/tree/main/module/schema#readme "Data type registry for runtime validation, reflection and binding.") and [Dependency Injection](https://github.com/travetto/travetto/tree/main/module/di#readme "Dependency registration/management and injection support."). These all center around defining a registry of classes, and associated type information. | ||
The module is primarily aimed at extremely advanced usages for things that cannot be detected at runtime. The [Registry](https://github.com/travetto/travetto/tree/main/module/registry#readme "Patterns and utilities for handling registration of metadata and functionality for run-time use") module already has knowledge of all `class`es and `field`s, and is able to listen to changes there. Many of the modules build upon work by some of the foundational transformers defined in [Manifest](https://github.com/travetto/travetto/tree/main/module/manifest#readme "Support for project indexing, manifesting, along with file watching"), [Registry](https://github.com/travetto/travetto/tree/main/module/registry#readme "Patterns and utilities for handling registration of metadata and functionality for run-time use"), [Schema](https://github.com/travetto/travetto/tree/main/module/schema#readme "Data type registry for runtime validation, reflection and binding.") and [Dependency Injection](https://github.com/travetto/travetto/tree/main/module/di#readme "Dependency registration/management and injection support."). These all center around defining a registry of classes, and associated type information. | ||
Because working with the [Typescript](https://typescriptlang.org) API can be delicate (and open to breaking changes), creating new transformers should be done cautiously. | ||
Because working with the [Typescript](https://typescriptlang.org) API can be delicate (and open to breaking changes), creating new transformers should be done cautiously. | ||
@@ -26,5 +27,4 @@ ## Monorepos and Idempotency | ||
## Custom Transformer | ||
Below is an example of a transformer that upper cases all `class`, `method` and `param` declarations. This will break any code that depends upon it as we are redefining all the identifiers at compile time. | ||
Below is an example of a transformer that upper cases all `class`, `method` and `param` declarations. This will break any code that depends upon it as we are redefining all the identifiers at compile time. | ||
**Code: Sample Transformer - Upper case all declarations** | ||
@@ -31,0 +31,0 @@ ```typescript |
import ts from 'typescript'; | ||
import { ManifestIndex, path } from '@travetto/manifest'; | ||
import { ManifestIndex, ManifestModuleUtil, path } from '@travetto/manifest'; | ||
@@ -37,3 +37,5 @@ import type { AnyType, TransformResolver } from './types'; | ||
if (!sourceFile.endsWith('.js') && !sourceFile.endsWith('.ts')) { | ||
const type = ManifestModuleUtil.getFileType(file); | ||
if (type !== 'js' && type !== 'ts') { | ||
sourceFile = `${sourceFile}.ts`; | ||
@@ -43,7 +45,7 @@ } | ||
const imp = | ||
this.#manifestIndex.getEntry(/[.]ts$/.test(sourceFile) ? sourceFile : `${sourceFile}.js`)?.import ?? | ||
this.#manifestIndex.getFromImport(sourceFile.replace(/^.*node_modules\//, '').replace(/[.]ts$/, ''))?.import ?? | ||
this.#manifestIndex.getEntry(ManifestModuleUtil.getFileType(sourceFile) === 'ts' ? sourceFile : `${sourceFile}.js`)?.import ?? | ||
this.#manifestIndex.getFromImport(ManifestModuleUtil.sourceToBlankExt(sourceFile).replace(/^.*node_modules\//, ''))?.import ?? | ||
file; | ||
return removeExt ? imp.replace(/[.]js$/, '') : imp; | ||
return removeExt ? ManifestModuleUtil.sourceToBlankExt(imp) : imp; | ||
} | ||
@@ -50,0 +52,0 @@ |
@@ -15,3 +15,3 @@ import ts from 'typescript'; | ||
static hasJSDoc(o: ts.Node): o is (ts.Node & { jsDoc: ts.JSDoc[] }) { | ||
return 'jsDoc' in o; | ||
return 'jsDoc' in o && o.jsDoc !== null && o.jsDoc !== undefined && Array.isArray(o.jsDoc) && o.jsDoc.length > 0; | ||
} | ||
@@ -18,0 +18,0 @@ |
import ts from 'typescript'; | ||
import { PackageUtil, path } from '@travetto/manifest'; | ||
import { ManifestModuleUtil, PackageUtil, path } from '@travetto/manifest'; | ||
@@ -15,3 +15,3 @@ import { Import } from '../types/shared'; | ||
static optionalResolve(file: string, base?: string): string { | ||
if (base?.endsWith('.ts')) { | ||
if (base && ManifestModuleUtil.getFileType(base) === 'ts') { | ||
base = path.dirname(base); | ||
@@ -18,0 +18,0 @@ } |
@@ -5,2 +5,3 @@ import ts from 'typescript'; | ||
import { CoreUtil } from './util/core'; | ||
import { ManifestModuleUtil } from '@travetto/manifest'; | ||
@@ -81,3 +82,4 @@ /** | ||
return (context: ts.TransformationContext) => (file: ts.SourceFile): ts.SourceFile => { | ||
if (!file.fileName.endsWith('.ts')) { // Skip all non-ts files | ||
const type = ManifestModuleUtil.getFileType(file.fileName); | ||
if (type !== 'ts') { // Skip all non-ts files | ||
return file; | ||
@@ -84,0 +86,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
88733
2226
Updated@travetto/manifest@^3.0.3