File tree Expand file tree Collapse file tree 3 files changed +64
-0
lines changed
src/core/resources/plugin Expand file tree Collapse file tree 3 files changed +64
-0
lines changed Original file line number Diff line number Diff line change
1
+ import type * as ts from 'typescript' ;
2
+ import {
3
+ ResourceReadonlyVisitor ,
4
+ ResourceVisitor ,
5
+ // @ts -expect-error the .cts extension is ok and needed for this one spot.
6
+ // This allows Nest CLI to CJS load it via ts-node
7
+ } from './resources.visitor.cts' ;
8
+
9
+ const visitor = new ResourceVisitor ( ) ;
10
+
11
+ // For ts-patch
12
+ // eslint-disable-next-line import/no-default-export
13
+ export default function ( program : ts . Program ) {
14
+ return before ( undefined , program ) ;
15
+ }
16
+
17
+ // For Nest CLI
18
+ export { ResourceReadonlyVisitor as ReadonlyVisitor } ;
19
+ export const before = ( _ : unknown , program : ts . Program ) => {
20
+ return ( ctx : ts . TransformationContext ) => {
21
+ return ( sf : ts . SourceFile ) => {
22
+ return visitor . visit ( sf , ctx , program ) ;
23
+ } ;
24
+ } ;
25
+ } ;
Original file line number Diff line number Diff line change
1
+ import type { ReadonlyVisitor } from '@nestjs/cli/lib/compiler/interfaces/readonly-visitor.interface' ;
2
+ import * as ts from 'typescript' ;
3
+
4
+ export class ResourceVisitor {
5
+ constructor ( readonly readonly = false ) { }
6
+
7
+ visit ( sf : ts . SourceFile , ctx : ts . TransformationContext , program : ts . Program ) {
8
+ const visitNode = ( node : ts . Node ) : ts . Node => {
9
+ // TODO logic
10
+
11
+ if ( this . readonly ) {
12
+ ts . forEachChild ( node , visitNode ) ;
13
+ } else {
14
+ return ts . visitEachChild ( node , visitNode , ctx ) ;
15
+ }
16
+ return node ;
17
+ } ;
18
+ return ts . visitNode ( sf , visitNode ) ;
19
+ }
20
+ }
21
+
22
+ export class ResourceReadonlyVisitor implements ReadonlyVisitor {
23
+ readonly key = '@cord/resources' ;
24
+ private readonly visitor = new ResourceVisitor ( true ) ;
25
+
26
+ get typeImports ( ) {
27
+ return { } ;
28
+ }
29
+
30
+ visit ( program : ts . Program , sf : ts . SourceFile ) {
31
+ const factoryHost = { factory : ts . factory } as any ;
32
+ return this . visitor . visit ( sf , factoryHost , program ) ;
33
+ }
34
+
35
+ collect ( ) {
36
+ return { } ;
37
+ }
38
+ }
Original file line number Diff line number Diff line change 36
36
// Transform plugins
37
37
"plugins" : [
38
38
{ "transform" : " typescript-transform-paths" },
39
+ { "transform" : " ./src/core/resources/plugin/index.cts" },
39
40
{ "transform" : " ts-transformer-keys/transformer" },
40
41
],
41
42
You can’t perform that action at this time.
0 commit comments