ttsc 0.0.4 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,2 +1,2 @@
1
- # Change Log
2
-
1
+ # Change Log
2
+
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 sunrabbit123
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2023 sunrabbit123
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,396 +1,396 @@
1
- # ttsc
2
-
3
- [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/solar-religion/ttsc/blob/main/LICENSE)
4
- [![npm version](https://img.shields.io/npm/v/ttsc.svg)](https://www.npmjs.com/package/ttsc)
5
- [![Downloads](https://img.shields.io/npm/dm/ttsc.svg)](https://www.npmjs.com/package/ttsc)
6
-
7
- This repository was created due to a perceived lack of management of `ttypescript`.
8
-
9
- Also, we don't currently support `ts-node` and `cache systems`, as they weren't supported in the original, and we need time to figure out a way around that.
10
-
11
- And it supports TS5.
12
-
13
- [![npm version](https://badge.fury.io/js/ttypescript.svg)](https://badge.fury.io/js/ttypescript) [![Build Status](https://travis-ci.org/cevek/ttypescript.svg?branch=master)](https://travis-ci.org/cevek/ttypescript)
14
-
15
- # ttypescript
16
-
17
- ## Existing contributors
18
-
19
- - @cevek
20
- - @zerkalica
21
- - @SalvatorePreviti
22
- - @timocov
23
- - @SlurpTheo
24
- - @samchon
25
- - @henriquehbr
26
- - @JiangWeixian
27
- - @mdmitry01
28
- - @jirutka
29
- - @alexgorbatchev
30
- - @oscard0m
31
- - @sveyret
32
- - @Jack-Works
33
- - @MicahZoltu
34
- - @Igorbek
35
- - @gfx
36
- - @danielpza
37
- - @mikeyhew
38
- - @huafu
39
- - @dsherret
40
- - @SupernaviX
41
- - @HitkoDev
42
-
43
- ## What it is
44
-
45
- Currently TypeScript doesn't support custom transformers in the tsconfig.json, but supports it programmatically.
46
-
47
- And there is no way to compile your files using custom transformers using `tsc` command.
48
-
49
- TTypescript (Transformer TypeScript) solves this problem by patching on the fly the compile module to use transformers from `tsconfig.json`.
50
-
51
- <!---
52
- TTypescript is a drop-in replacement for all typescript modules, located in ``` node_modules/typescript/lib ``` directory:
53
-
54
- ```ts
55
- import * as ts from 'ttypescript'
56
- import * as tsServer from 'ttypescript/lib/tsserver'
57
- import * as watchGuard from 'ttypescript/lib/watchGuard'
58
- ```
59
- --->
60
-
61
- Instead of tsc and tsserver, use ttsc and ttsserver wrappers. This wrappers try to use locally installed typescript first.
62
-
63
- No version lock-ins - typescript used as peer dependency.
64
-
65
- ## How to install
66
-
67
- ```
68
- npm i ttypescript -D
69
- ```
70
-
71
- ttypescript uses your installed `typescript` in your `node_modules`
72
-
73
- ## How to use
74
-
75
- ### tsconfig.json
76
-
77
- Set a transformer path to the `tsconfig.json` in `compilerOptions` section `plugin` array:
78
-
79
- ```
80
- {
81
- "compilerOptions": {
82
- "plugins": [
83
- { "transform": "transformer-module" },
84
- ]
85
- }
86
- }
87
- ```
88
-
89
- plugin entries described in `PluginConfig`:
90
-
91
- ```ts
92
- export interface PluginConfig {
93
- /**
94
- * Path to transformer or transformer module name
95
- */
96
- transform?: string;
97
-
98
- /**
99
- * The optional name of the exported transform plugin in the transform module.
100
- */
101
- import?: string;
102
-
103
- /**
104
- * Plugin entry point format type, default is program
105
- */
106
- type?: 'program' | 'config' | 'checker' | 'raw' | 'compilerOptions';
107
-
108
- /**
109
- * Should transformer applied after all ones
110
- */
111
- after?: boolean;
112
-
113
- /**
114
- * Should transformer applied for d.ts files, supports from TS2.9
115
- */
116
- afterDeclarations?: boolean;
117
- /**
118
- * any other properties provided to the transformer as config argument
119
- * */
120
- [options: string]: any;
121
- }
122
- ```
123
-
124
- You just need to add the `transform` block with optional `import`, `type`, `after`, `afterDeclarations` and plugin-related options.
125
-
126
- `transform` can accept npm module or local file path (.ts or .js) related to `tsconfig.json`
127
-
128
- ### PluginConfig.type
129
-
130
- Because currently transformers can run only programmatically, most of them use factory wrapper with different signatures.
131
- For the possible to work with any of them you can specify `type` in the plugin config.
132
-
133
- By default will be used a `program` type.
134
-
135
- <!---
136
-
137
- Most of transformers exports ``` ts.TransformerFactory<ts.SourceFile> ```.
138
- But better to export TransformerBasePlugin, described below. In most cases it's a plugin responsibility to when run a transformer.
139
-
140
- ```ts
141
- export interface TransformerBasePlugin {
142
- before?: ts.TransformerFactory<ts.SourceFile>;
143
- after?: ts.TransformerFactory<ts.SourceFile>;
144
- afterDeclarations?: ts.TransformerFactory<ts.SourceFile>;
145
- }
146
-
147
- export type TransformerPlugin = TransformerBasePlugin | ts.TransformerFactory<ts.SourceFile>;
148
- ```
149
- --->
150
-
151
- #### program
152
-
153
- If the transformer has a factory signature using `program` as first argument:
154
-
155
- ```ts
156
- (program: ts.Program, config?: PluginConfig) => ts.TransformerFactory;
157
- where;
158
- ts.TransformerFactory = (context: ts.TransformationContext) => (sourceFile: ts.SourceFile) => ts.SourceFile;
159
- ```
160
-
161
- Plugin config entry: `{ "transform": "transformer-module" }`.
162
-
163
- #### config
164
-
165
- For the signature with transformer's config:
166
-
167
- ```ts
168
- (config: PluginConfig) => ts.TransformerFactory;
169
- ```
170
-
171
- Plugin config entry: `{ "transform": "transformer-module", type: "config" }`.
172
-
173
- #### checker
174
-
175
- For the signature with ts.TypeChecker:
176
-
177
- ```ts
178
- (checker: ts.TypeChecker, config?: PluginConfig) => ts.TransformerFactory;
179
- ```
180
-
181
- Plugin config entry: `{ "transform": "transformer-module", type: "checker" }`.
182
-
183
- #### raw
184
-
185
- For the signature without factory wrapper:
186
-
187
- ```ts
188
- ts.TransformerFactory;
189
- ```
190
-
191
- Plugin config entry: `{ "transform": "transformer-module", type: "raw" }`.
192
-
193
- #### compilerOptions
194
-
195
- ```ts
196
- (compilerOpts: ts.CompilerOptions, config?: PluginConfig) => ts.TransformerFactory;
197
- ```
198
-
199
- Plugin config entry: `{ "transform": "transformer-module", type: "compilerOptions" }`.
200
-
201
- ```json
202
- {
203
- "compilerOptions": {
204
- "plugins": [
205
- { "transform": "transformer-module", "someOption1": 123, "someOption2": 321 },
206
- { "transform": "./transformers/my-transformer.ts" },
207
- { "transform": "transformer-module", "after": true },
208
- { "transform": "transformer-module", "afterDeclarations": true },
209
- { "transform": "transformer-module", "type": "ls" }
210
- ]
211
- }
212
- }
213
- ```
214
-
215
- ### Command line
216
-
217
- Like usual `tsc`, all arguments work the same way.
218
-
219
- ```
220
- ttsc
221
- ```
222
-
223
- ### ts-node
224
-
225
- ```
226
- ts-node --compiler ttypescript index.ts
227
- or
228
- ts-node -C ttypescript index.ts
229
- ```
230
-
231
- ### Parcel
232
-
233
- Just install a parcel plugin
234
-
235
- ```
236
- npm i parcel-plugin-ttypescript
237
- ```
238
-
239
- ### Webpack
240
-
241
- ```js
242
- {
243
- test: /\.(ts|tsx)$/,
244
- loader: require.resolve('awesome-typescript-loader'),
245
- // or
246
- loader: require.resolve('ts-loader'),
247
- options: {
248
- compiler: 'ttypescript'
249
- }
250
- }
251
- ```
252
-
253
- ### Rollup
254
-
255
- ```js
256
- // rollup.config.js
257
- import ttypescript from 'ttypescript';
258
- import tsPlugin from 'rollup-plugin-typescript2';
259
-
260
- export default {
261
- // ...
262
- plugins: [
263
- // ...
264
- tsPlugin({
265
- typescript: ttypescript,
266
- }),
267
- ],
268
- };
269
- ```
270
-
271
- ### VS Code
272
-
273
- If you want to compile your project with VS Code task runner you need to overwrite the config `typescript.tsdk` to path of the installed `ttypescript`:
274
-
275
- ```
276
- "typescript.tsdk": "/usr/local/lib/node_modules/ttypescript/lib",
277
- or
278
- "typescript.tsdk": "node_modules/ttypescript/lib",
279
- ```
280
-
281
- ### Jest, ts-jest
282
-
283
- ```js
284
- module.exports = {
285
- // [...]
286
- globals: {
287
- 'ts-jest': {
288
- compiler: 'ttypescript',
289
- },
290
- },
291
- };
292
- ```
293
-
294
- or in `package.json`
295
-
296
- ```json
297
- {
298
- "jest": {
299
- "globals": {
300
- "ts-jest": {
301
- "compiler": "ttypescript"
302
- }
303
- }
304
- }
305
- }
306
- ```
307
-
308
- ## Transformers
309
-
310
- You can use transformers written in ts or js
311
-
312
- ```ts
313
- // transformer1-module
314
- import * as ts from 'typescript';
315
- export default function (program: ts.Program, pluginOptions: {}) {
316
- return (ctx: ts.TransformationContext) => {
317
- return (sourceFile: ts.SourceFile) => {
318
- function visitor(node: ts.Node): ts.Node {
319
- // if (ts.isCallExpression(node)) {
320
- // return ts.createLiteral('call');
321
- // }
322
- return ts.visitEachChild(node, visitor, ctx);
323
- }
324
- return ts.visitEachChild(sourceFile, visitor, ctx);
325
- };
326
- };
327
- }
328
- ```
329
-
330
- Examples of transformers:
331
-
332
- [`{ "transform": "ts-nameof", type: "raw"}`](https://github.com/dsherret/ts-nameof)
333
-
334
- [`{ "transform": "ts-optchain/transform" }`](https://github.com/rimeto/ts-optchain)
335
-
336
- [`{ "transform": "ts-transform-asset" }`](https://github.com/slune-org/ts-transform-asset)
337
-
338
- [`{ "transform": "ts-transform-auto-require" }`](https://github.com/slune-org/ts-transform-auto-require)
339
-
340
- [`{ "transform": "ts-transform-css-modules/dist/transform", type: "config" }`](https://github.com/longlho/ts-transform-css-modules)
341
-
342
- [`{ "transform": "ts-transform-graphql-tag/dist/transformer" }`](https://github.com/firede/ts-transform-graphql-tag)
343
-
344
- [`{ "transform": "ts-transform-img/dist/transform", type: "config" }`](https://github.com/longlho/ts-transform-img)
345
-
346
- [`{ "transform": "ts-transform-react-intl/dist/transform", import: "transform", type: "config" }`](https://github.com/longlho/ts-transform-react-intl)
347
-
348
- [`{ "transform": "ts-transformer-enumerate/transformer" }`](https://github.com/kimamula/ts-transformer-enumerate)
349
-
350
- [`{ "transform": "ts-transformer-keys/transformer" }`](https://github.com/kimamula/ts-transformer-keys)
351
-
352
- [`{ "transform": "ts-transformer-minify-privates" }`](https://github.com/timocov/ts-transformer-minify-privates)
353
-
354
- [`{ "transform": "typescript-is/lib/transform-inline/transformer" }`](https://github.com/woutervh-/typescript-is)
355
-
356
- [`{ "transform": "typescript-plugin-styled-components", type: "config" }`](https://github.com/Igorbek/typescript-plugin-styled-components#ttypescript-compiler)
357
-
358
- [`{ "transform": "typescript-transform-jsx" }`](https://github.com/LeDDGroup/typescript-transform-jsx)
359
-
360
- [`{ "transform": "typescript-transform-macros" }`](https://github.com/LeDDGroup/typescript-transform-macros)
361
-
362
- [`{ "transform": "typescript-transform-paths" }`](https://github.com/LeDDGroup/typescript-transform-paths)
363
-
364
- [`{ "transform": "@zerollup/ts-transform-paths" }`](https://github.com/zerkalica/zerollup/tree/master/packages/ts-transform-paths)
365
-
366
- [`{ "transform": "@zoltu/typescript-transformer-append-js-extension" }`](https://github.com/Zoltu/typescript-transformer-append-js-extension)
367
-
368
- [`{ "transform": "@magic-works/ttypescript-browser-like-import-transformer" }`](https://github.com/Jack-Works/ttypescript-browser-like-import-transformer)
369
-
370
- [`{ "transform": "typescript-transform-react-jsx-source" }`](https://github.com/alexgorbatchev/typescript-transform-react-jsx-source)
371
-
372
- [`{ "transform": "ts-transformer-remove-named-export" }`](https://github.com/dominguezcelada/ts-transformer-remove-named-export)
373
-
374
- [`{ "transform": "ts-transformer-export-default-name" }`](https://github.com/jirutka/ts-transformer-export-default-name)
375
-
376
- [`{ "transform": "ts-transformer-inline-file/transformer" }`](https://github.com/jirutka/ts-transformer-inline-file)
377
-
378
- [`{ "transform": "ts-transformer-strip-const-enums", "entrySourceFiles": ["./src/index.ts" }`](https://github.com/timocov/ts-transformer-strip-const-enums)
379
-
380
- [`{ "transform": "ts-transformer-properties-rename", "entrySourceFiles": ["./src/index.ts"] }`](https://github.com/timocov/ts-transformer-properties-rename)
381
-
382
- [`{ "transform": "tsc-progress", "name": "TSC", "color": "green" }`](https://github.com/JiangWeixian/tsc-progress)
383
-
384
- [Tutorial how to write a typescript transformer](https://dev.doctorevidence.com/how-to-write-a-typescript-transform-plugin-fc5308fdd943)
385
-
386
- - [Tutorial how to write a typescript transformer](https://dev.doctorevidence.com/how-to-write-a-typescript-transform-plugin-fc5308fdd943)
387
- - [Transformer framework](https://github.com/slune-org/simple-ts-transform)
388
- - [Unit testing transformer compiler](https://github.com/slune-org/ts-transform-test-compiler)
389
-
390
- ## Example
391
-
392
- An example project is in the [example](./packages/ttypescript-examples) directory
393
-
394
- ## License
395
-
396
- MIT License
1
+ # ttsc
2
+
3
+ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/solar-religion/ttsc/blob/main/LICENSE)
4
+ [![npm version](https://img.shields.io/npm/v/ttsc.svg)](https://www.npmjs.com/package/ttsc)
5
+ [![Downloads](https://img.shields.io/npm/dm/ttsc.svg)](https://www.npmjs.com/package/ttsc)
6
+
7
+ This repository was created due to a perceived lack of management of `ttypescript`.
8
+
9
+ Also, we don't currently support `ts-node` and `cache systems`, as they weren't supported in the original, and we need time to figure out a way around that.
10
+
11
+ And it supports TS5.
12
+
13
+ [![npm version](https://badge.fury.io/js/ttypescript.svg)](https://badge.fury.io/js/ttypescript) [![Build Status](https://travis-ci.org/cevek/ttypescript.svg?branch=master)](https://travis-ci.org/cevek/ttypescript)
14
+
15
+ # ttypescript
16
+
17
+ ## Existing contributors
18
+
19
+ - @cevek
20
+ - @zerkalica
21
+ - @SalvatorePreviti
22
+ - @timocov
23
+ - @SlurpTheo
24
+ - @samchon
25
+ - @henriquehbr
26
+ - @JiangWeixian
27
+ - @mdmitry01
28
+ - @jirutka
29
+ - @alexgorbatchev
30
+ - @oscard0m
31
+ - @sveyret
32
+ - @Jack-Works
33
+ - @MicahZoltu
34
+ - @Igorbek
35
+ - @gfx
36
+ - @danielpza
37
+ - @mikeyhew
38
+ - @huafu
39
+ - @dsherret
40
+ - @SupernaviX
41
+ - @HitkoDev
42
+
43
+ ## What it is
44
+
45
+ Currently TypeScript doesn't support custom transformers in the tsconfig.json, but supports it programmatically.
46
+
47
+ And there is no way to compile your files using custom transformers using `tsc` command.
48
+
49
+ TTypescript (Transformer TypeScript) solves this problem by patching on the fly the compile module to use transformers from `tsconfig.json`.
50
+
51
+ <!---
52
+ TTypescript is a drop-in replacement for all typescript modules, located in ``` node_modules/typescript/lib ``` directory:
53
+
54
+ ```ts
55
+ import * as ts from 'ttypescript'
56
+ import * as tsServer from 'ttypescript/lib/tsserver'
57
+ import * as watchGuard from 'ttypescript/lib/watchGuard'
58
+ ```
59
+ --->
60
+
61
+ Instead of tsc and tsserver, use ttsc and ttsserver wrappers. This wrappers try to use locally installed typescript first.
62
+
63
+ No version lock-ins - typescript used as peer dependency.
64
+
65
+ ## How to install
66
+
67
+ ```
68
+ npm i ttypescript -D
69
+ ```
70
+
71
+ ttypescript uses your installed `typescript` in your `node_modules`
72
+
73
+ ## How to use
74
+
75
+ ### tsconfig.json
76
+
77
+ Set a transformer path to the `tsconfig.json` in `compilerOptions` section `plugin` array:
78
+
79
+ ```
80
+ {
81
+ "compilerOptions": {
82
+ "plugins": [
83
+ { "transform": "transformer-module" },
84
+ ]
85
+ }
86
+ }
87
+ ```
88
+
89
+ plugin entries described in `PluginConfig`:
90
+
91
+ ```ts
92
+ export interface PluginConfig {
93
+ /**
94
+ * Path to transformer or transformer module name
95
+ */
96
+ transform?: string;
97
+
98
+ /**
99
+ * The optional name of the exported transform plugin in the transform module.
100
+ */
101
+ import?: string;
102
+
103
+ /**
104
+ * Plugin entry point format type, default is program
105
+ */
106
+ type?: 'program' | 'config' | 'checker' | 'raw' | 'compilerOptions';
107
+
108
+ /**
109
+ * Should transformer applied after all ones
110
+ */
111
+ after?: boolean;
112
+
113
+ /**
114
+ * Should transformer applied for d.ts files, supports from TS2.9
115
+ */
116
+ afterDeclarations?: boolean;
117
+ /**
118
+ * any other properties provided to the transformer as config argument
119
+ * */
120
+ [options: string]: any;
121
+ }
122
+ ```
123
+
124
+ You just need to add the `transform` block with optional `import`, `type`, `after`, `afterDeclarations` and plugin-related options.
125
+
126
+ `transform` can accept npm module or local file path (.ts or .js) related to `tsconfig.json`
127
+
128
+ ### PluginConfig.type
129
+
130
+ Because currently transformers can run only programmatically, most of them use factory wrapper with different signatures.
131
+ For the possible to work with any of them you can specify `type` in the plugin config.
132
+
133
+ By default will be used a `program` type.
134
+
135
+ <!---
136
+
137
+ Most of transformers exports ``` ts.TransformerFactory<ts.SourceFile> ```.
138
+ But better to export TransformerBasePlugin, described below. In most cases it's a plugin responsibility to when run a transformer.
139
+
140
+ ```ts
141
+ export interface TransformerBasePlugin {
142
+ before?: ts.TransformerFactory<ts.SourceFile>;
143
+ after?: ts.TransformerFactory<ts.SourceFile>;
144
+ afterDeclarations?: ts.TransformerFactory<ts.SourceFile>;
145
+ }
146
+
147
+ export type TransformerPlugin = TransformerBasePlugin | ts.TransformerFactory<ts.SourceFile>;
148
+ ```
149
+ --->
150
+
151
+ #### program
152
+
153
+ If the transformer has a factory signature using `program` as first argument:
154
+
155
+ ```ts
156
+ (program: ts.Program, config?: PluginConfig) => ts.TransformerFactory;
157
+ where;
158
+ ts.TransformerFactory = (context: ts.TransformationContext) => (sourceFile: ts.SourceFile) => ts.SourceFile;
159
+ ```
160
+
161
+ Plugin config entry: `{ "transform": "transformer-module" }`.
162
+
163
+ #### config
164
+
165
+ For the signature with transformer's config:
166
+
167
+ ```ts
168
+ (config: PluginConfig) => ts.TransformerFactory;
169
+ ```
170
+
171
+ Plugin config entry: `{ "transform": "transformer-module", type: "config" }`.
172
+
173
+ #### checker
174
+
175
+ For the signature with ts.TypeChecker:
176
+
177
+ ```ts
178
+ (checker: ts.TypeChecker, config?: PluginConfig) => ts.TransformerFactory;
179
+ ```
180
+
181
+ Plugin config entry: `{ "transform": "transformer-module", type: "checker" }`.
182
+
183
+ #### raw
184
+
185
+ For the signature without factory wrapper:
186
+
187
+ ```ts
188
+ ts.TransformerFactory;
189
+ ```
190
+
191
+ Plugin config entry: `{ "transform": "transformer-module", type: "raw" }`.
192
+
193
+ #### compilerOptions
194
+
195
+ ```ts
196
+ (compilerOpts: ts.CompilerOptions, config?: PluginConfig) => ts.TransformerFactory;
197
+ ```
198
+
199
+ Plugin config entry: `{ "transform": "transformer-module", type: "compilerOptions" }`.
200
+
201
+ ```json
202
+ {
203
+ "compilerOptions": {
204
+ "plugins": [
205
+ { "transform": "transformer-module", "someOption1": 123, "someOption2": 321 },
206
+ { "transform": "./transformers/my-transformer.ts" },
207
+ { "transform": "transformer-module", "after": true },
208
+ { "transform": "transformer-module", "afterDeclarations": true },
209
+ { "transform": "transformer-module", "type": "ls" }
210
+ ]
211
+ }
212
+ }
213
+ ```
214
+
215
+ ### Command line
216
+
217
+ Like usual `tsc`, all arguments work the same way.
218
+
219
+ ```
220
+ ttsc
221
+ ```
222
+
223
+ ### ts-node
224
+
225
+ ```
226
+ ts-node --compiler ttypescript index.ts
227
+ or
228
+ ts-node -C ttypescript index.ts
229
+ ```
230
+
231
+ ### Parcel
232
+
233
+ Just install a parcel plugin
234
+
235
+ ```
236
+ npm i parcel-plugin-ttypescript
237
+ ```
238
+
239
+ ### Webpack
240
+
241
+ ```js
242
+ {
243
+ test: /\.(ts|tsx)$/,
244
+ loader: require.resolve('awesome-typescript-loader'),
245
+ // or
246
+ loader: require.resolve('ts-loader'),
247
+ options: {
248
+ compiler: 'ttypescript'
249
+ }
250
+ }
251
+ ```
252
+
253
+ ### Rollup
254
+
255
+ ```js
256
+ // rollup.config.js
257
+ import ttypescript from 'ttypescript';
258
+ import tsPlugin from 'rollup-plugin-typescript2';
259
+
260
+ export default {
261
+ // ...
262
+ plugins: [
263
+ // ...
264
+ tsPlugin({
265
+ typescript: ttypescript,
266
+ }),
267
+ ],
268
+ };
269
+ ```
270
+
271
+ ### VS Code
272
+
273
+ If you want to compile your project with VS Code task runner you need to overwrite the config `typescript.tsdk` to path of the installed `ttypescript`:
274
+
275
+ ```
276
+ "typescript.tsdk": "/usr/local/lib/node_modules/ttypescript/lib",
277
+ or
278
+ "typescript.tsdk": "node_modules/ttypescript/lib",
279
+ ```
280
+
281
+ ### Jest, ts-jest
282
+
283
+ ```js
284
+ module.exports = {
285
+ // [...]
286
+ globals: {
287
+ 'ts-jest': {
288
+ compiler: 'ttypescript',
289
+ },
290
+ },
291
+ };
292
+ ```
293
+
294
+ or in `package.json`
295
+
296
+ ```json
297
+ {
298
+ "jest": {
299
+ "globals": {
300
+ "ts-jest": {
301
+ "compiler": "ttypescript"
302
+ }
303
+ }
304
+ }
305
+ }
306
+ ```
307
+
308
+ ## Transformers
309
+
310
+ You can use transformers written in ts or js
311
+
312
+ ```ts
313
+ // transformer1-module
314
+ import * as ts from 'typescript';
315
+ export default function (program: ts.Program, pluginOptions: {}) {
316
+ return (ctx: ts.TransformationContext) => {
317
+ return (sourceFile: ts.SourceFile) => {
318
+ function visitor(node: ts.Node): ts.Node {
319
+ // if (ts.isCallExpression(node)) {
320
+ // return ts.createLiteral('call');
321
+ // }
322
+ return ts.visitEachChild(node, visitor, ctx);
323
+ }
324
+ return ts.visitEachChild(sourceFile, visitor, ctx);
325
+ };
326
+ };
327
+ }
328
+ ```
329
+
330
+ Examples of transformers:
331
+
332
+ [`{ "transform": "ts-nameof", type: "raw"}`](https://github.com/dsherret/ts-nameof)
333
+
334
+ [`{ "transform": "ts-optchain/transform" }`](https://github.com/rimeto/ts-optchain)
335
+
336
+ [`{ "transform": "ts-transform-asset" }`](https://github.com/slune-org/ts-transform-asset)
337
+
338
+ [`{ "transform": "ts-transform-auto-require" }`](https://github.com/slune-org/ts-transform-auto-require)
339
+
340
+ [`{ "transform": "ts-transform-css-modules/dist/transform", type: "config" }`](https://github.com/longlho/ts-transform-css-modules)
341
+
342
+ [`{ "transform": "ts-transform-graphql-tag/dist/transformer" }`](https://github.com/firede/ts-transform-graphql-tag)
343
+
344
+ [`{ "transform": "ts-transform-img/dist/transform", type: "config" }`](https://github.com/longlho/ts-transform-img)
345
+
346
+ [`{ "transform": "ts-transform-react-intl/dist/transform", import: "transform", type: "config" }`](https://github.com/longlho/ts-transform-react-intl)
347
+
348
+ [`{ "transform": "ts-transformer-enumerate/transformer" }`](https://github.com/kimamula/ts-transformer-enumerate)
349
+
350
+ [`{ "transform": "ts-transformer-keys/transformer" }`](https://github.com/kimamula/ts-transformer-keys)
351
+
352
+ [`{ "transform": "ts-transformer-minify-privates" }`](https://github.com/timocov/ts-transformer-minify-privates)
353
+
354
+ [`{ "transform": "typescript-is/lib/transform-inline/transformer" }`](https://github.com/woutervh-/typescript-is)
355
+
356
+ [`{ "transform": "typescript-plugin-styled-components", type: "config" }`](https://github.com/Igorbek/typescript-plugin-styled-components#ttypescript-compiler)
357
+
358
+ [`{ "transform": "typescript-transform-jsx" }`](https://github.com/LeDDGroup/typescript-transform-jsx)
359
+
360
+ [`{ "transform": "typescript-transform-macros" }`](https://github.com/LeDDGroup/typescript-transform-macros)
361
+
362
+ [`{ "transform": "typescript-transform-paths" }`](https://github.com/LeDDGroup/typescript-transform-paths)
363
+
364
+ [`{ "transform": "@zerollup/ts-transform-paths" }`](https://github.com/zerkalica/zerollup/tree/master/packages/ts-transform-paths)
365
+
366
+ [`{ "transform": "@zoltu/typescript-transformer-append-js-extension" }`](https://github.com/Zoltu/typescript-transformer-append-js-extension)
367
+
368
+ [`{ "transform": "@magic-works/ttypescript-browser-like-import-transformer" }`](https://github.com/Jack-Works/ttypescript-browser-like-import-transformer)
369
+
370
+ [`{ "transform": "typescript-transform-react-jsx-source" }`](https://github.com/alexgorbatchev/typescript-transform-react-jsx-source)
371
+
372
+ [`{ "transform": "ts-transformer-remove-named-export" }`](https://github.com/dominguezcelada/ts-transformer-remove-named-export)
373
+
374
+ [`{ "transform": "ts-transformer-export-default-name" }`](https://github.com/jirutka/ts-transformer-export-default-name)
375
+
376
+ [`{ "transform": "ts-transformer-inline-file/transformer" }`](https://github.com/jirutka/ts-transformer-inline-file)
377
+
378
+ [`{ "transform": "ts-transformer-strip-const-enums", "entrySourceFiles": ["./src/index.ts" }`](https://github.com/timocov/ts-transformer-strip-const-enums)
379
+
380
+ [`{ "transform": "ts-transformer-properties-rename", "entrySourceFiles": ["./src/index.ts"] }`](https://github.com/timocov/ts-transformer-properties-rename)
381
+
382
+ [`{ "transform": "tsc-progress", "name": "TSC", "color": "green" }`](https://github.com/JiangWeixian/tsc-progress)
383
+
384
+ [Tutorial how to write a typescript transformer](https://dev.doctorevidence.com/how-to-write-a-typescript-transform-plugin-fc5308fdd943)
385
+
386
+ - [Tutorial how to write a typescript transformer](https://dev.doctorevidence.com/how-to-write-a-typescript-transform-plugin-fc5308fdd943)
387
+ - [Transformer framework](https://github.com/slune-org/simple-ts-transform)
388
+ - [Unit testing transformer compiler](https://github.com/slune-org/ts-transform-test-compiler)
389
+
390
+ ## Example
391
+
392
+ An example project is in the [example](./packages/ttypescript-examples) directory
393
+
394
+ ## License
395
+
396
+ MIT License
package/bin/tsc CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env node
2
- require('../lib/tsc.js')
1
+ #!/usr/bin/env node
2
+ require('../lib/tsc.js')
package/bin/tsserver CHANGED
@@ -1,2 +1,2 @@
1
- #!/usr/bin/env node
2
- require('../lib/tsserver.js')
1
+ #!/usr/bin/env node
2
+ require('../lib/tsserver.js')
package/package.json CHANGED
@@ -1,65 +1,65 @@
1
- {
2
- "name": "ttsc",
3
- "bin": {
4
- "ttsc": "./bin/tsc",
5
- "ttsserver": "./bin/tsserver"
6
- },
7
- "scripts": {
8
- "build": "tsc",
9
- "clean": "rm -rf packages/*/dist packages/*/lib",
10
- "clean.all": "lerna clean --yes && rm -rf package-lock.json packages/*/package-lock.json node_modules packages/*/lib packages/*/dist",
11
- "debug": "node --inspect-brk ./node_modules/jest/bin/jest --runInBand --no-cache --no-watchman",
12
- "test": "npm run build && jest",
13
- "test.watch": "npm run build && jest --watch",
14
- "prettier": "npx prettier --config .prettierrc.js --check .",
15
- "prettier:fix": "npx prettier --config .prettierrc.js --write ."
16
- },
17
- "version": "0.0.4",
18
- "description": "Over TypeScript tool to use custom transformers in the tsconfig.json",
19
- "main": "lib/typescript.js",
20
- "files": [
21
- "*.md",
22
- "bin",
23
- "lib",
24
- "ts-node-config"
25
- ],
26
- "author": "sunrabbit123",
27
- "repository": {
28
- "type": "git",
29
- "url": "https://github.com/solar-religion/ttsc.git"
30
- },
31
- "homepage": "https://github.com/solar-religion/ttsc",
32
- "keywords": [
33
- "typescript",
34
- "wrapper",
35
- "transform",
36
- "transformer",
37
- "plugin",
38
- "config"
39
- ],
40
- "license": "MIT",
41
- "dependencies": {
42
- "resolve": ">=1.9.0"
43
- },
44
- "devDependencies": {
45
- "@types/jest": ">=23.3.11",
46
- "@types/node": ">=10.12.18",
47
- "@types/resolve": ">=0.0.8",
48
- "jest": ">=23.6.0",
49
- "lerna": ">=3.8.1",
50
- "ts-jest": ">=23.10.5",
51
- "ts-nameof": ">=2.0.0",
52
- "ts-node": ">=8.0.2",
53
- "ts-transform-css-modules": ">=0.3.3",
54
- "ts-transform-img": ">=0.3.2",
55
- "ts-transform-react-intl": ">=0.4.0",
56
- "ts-transformer-enumerate": ">=0.3.1",
57
- "ts-transformer-keys": ">=0.3.4",
58
- "ttsc": "file:.",
59
- "typescript": ">=3.2.2"
60
- },
61
- "peerDependencies": {
62
- "ts-node": ">=8.0.2",
63
- "typescript": ">=3.2.2"
64
- }
65
- }
1
+ {
2
+ "name": "ttsc",
3
+ "bin": {
4
+ "ttsc": "./bin/tsc",
5
+ "ttsserver": "./bin/tsserver"
6
+ },
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "clean": "rm -rf packages/*/dist packages/*/lib",
10
+ "clean.all": "lerna clean --yes && rm -rf package-lock.json packages/*/package-lock.json node_modules packages/*/lib packages/*/dist",
11
+ "debug": "node --inspect-brk ./node_modules/jest/bin/jest --runInBand --no-cache --no-watchman",
12
+ "test": "npm run build && jest",
13
+ "test.watch": "npm run build && jest --watch",
14
+ "prettier": "npx prettier --config .prettierrc.js --check .",
15
+ "prettier:fix": "npx prettier --config .prettierrc.js --write ."
16
+ },
17
+ "version": "0.1.0",
18
+ "description": "Over TypeScript tool to use custom transformers in the tsconfig.json",
19
+ "main": "lib/typescript.js",
20
+ "files": [
21
+ "*.md",
22
+ "bin",
23
+ "lib",
24
+ "ts-node-config"
25
+ ],
26
+ "author": "sunrabbit123",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/solar-religion/ttsc.git"
30
+ },
31
+ "homepage": "https://github.com/solar-religion/ttsc",
32
+ "keywords": [
33
+ "typescript",
34
+ "wrapper",
35
+ "transform",
36
+ "transformer",
37
+ "plugin",
38
+ "config"
39
+ ],
40
+ "license": "MIT",
41
+ "dependencies": {
42
+ "resolve": ">=1.9.0"
43
+ },
44
+ "devDependencies": {
45
+ "@types/jest": ">=23.3.11",
46
+ "@types/node": ">=10.12.18",
47
+ "@types/resolve": ">=0.0.8",
48
+ "jest": ">=23.6.0",
49
+ "lerna": ">=3.8.1",
50
+ "ts-jest": ">=23.10.5",
51
+ "ts-nameof": ">=2.0.0",
52
+ "ts-node": ">=8.0.2",
53
+ "ts-transform-css-modules": ">=0.3.3",
54
+ "ts-transform-img": ">=0.3.2",
55
+ "ts-transform-react-intl": ">=0.4.0",
56
+ "ts-transformer-enumerate": ">=0.3.1",
57
+ "ts-transformer-keys": ">=0.3.4",
58
+ "ttsc": "file:.",
59
+ "typescript": ">=3.2.2"
60
+ },
61
+ "peerDependencies": {
62
+ "ts-node": ">=8.0.2",
63
+ "typescript": ">=3.2.2"
64
+ }
65
+ }