Skip to content

Commit 4bdb0b3

Browse files
committed
chore: revert "chore: remove nx plugin"
1 parent 5a19c6e commit 4bdb0b3

File tree

5 files changed

+3140
-48
lines changed

5 files changed

+3140
-48
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,5 @@ fabric.properties
7777
.idea/httpRequests
7878

7979
pnpm-lock.yaml
80+
81+
.nx/

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,30 @@ import { sum } from "@utils/sum";
6060
### 3. Usage
6161

6262
- **Compile with `tsc`** — Use [ts-patch](https://github.com/nonara/ts-patch)
63-
- **ts-node** — See [wiki](https://github.com/LeDDGroup/typescript-transform-paths/wiki/Integration-with-nx)
64-
- **nx** — See [wiki](https://github.com/LeDDGroup/typescript-transform-paths/wiki/Integration-with-ts%E2%80%90node)
63+
- **ts-node** — See [wiki](https://github.com/LeDDGroup/typescript-transform-paths/wiki/Integration-with-ts%E2%80%90node)
64+
- **Use with NX** — Add the `typescript-transform-paths/nx-transformer` to project config
65+
66+
`project.json`
67+
68+
```jsonc
69+
{
70+
/* ... */
71+
"targets": {
72+
"build": {
73+
/* ... */
74+
"options": {
75+
/* ... */
76+
"transformers": [
77+
{
78+
"name": "typescript-transform-paths/plugins/nx",
79+
"options": { "afterDeclarations": true },
80+
},
81+
],
82+
},
83+
},
84+
},
85+
}
86+
```
6587

6688
## Virtual Directories
6789

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
".": {
88
"types": "./dist/index.d.ts",
99
"default": "./dist/index.js"
10-
}
10+
},
11+
"./plugins/nx": "./dist/plugins/nx.js"
1112
},
1213
"files": [
1314
"dist",

src/plugins/nx.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// See nx-transformer-plugin.ts
2+
// https://github.com/nrwl/nx/blob/229f71ef1758ee625869aaa6fa6355dc3284fa5b/packages/js/src/utils/typescript/types.ts#L19-L32
3+
// https://github.com/nrwl/nx/blob/master/packages/js/src/utils/typescript/load-ts-transformers.ts
4+
import ts from "typescript";
5+
6+
import transformer from "../transformer.ts";
7+
8+
export interface TsTransformPathsConfig {
9+
readonly useRootDirs?: boolean;
10+
readonly exclude?: string[];
11+
readonly afterDeclarations?: boolean;
12+
readonly tsConfig?: string;
13+
readonly transform?: string;
14+
}
15+
16+
export type NxTransformerFactory = (
17+
config?: Omit<TsTransformPathsConfig, "transform">,
18+
program?: ts.Program,
19+
) => ts.TransformerFactory<ts.SourceFile>;
20+
21+
export interface NxTransformerPlugin {
22+
before: NxTransformerFactory;
23+
afterDeclarations: NxTransformerFactory;
24+
}
25+
26+
/* ****************************************************************************************************************** *
27+
* Locals
28+
* ****************************************************************************************************************** */
29+
30+
const voidTransformer: ts.TransformerFactory<ts.SourceFile> = () => (s: ts.SourceFile) => s;
31+
32+
/* ****************************************************************************************************************** *
33+
* Transformer
34+
* ****************************************************************************************************************** */
35+
36+
export const before: NxTransformerFactory = (pluginConfig, program) =>
37+
pluginConfig?.afterDeclarations ? voidTransformer : transformer(program, { ...pluginConfig });
38+
39+
export const afterDeclarations: NxTransformerFactory = (pluginConfig, program) =>
40+
pluginConfig?.afterDeclarations ? transformer(program, { ...pluginConfig }) : voidTransformer;

0 commit comments

Comments
 (0)