@samchon/ts-patch 3.2.2-dev.20241204

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.
Files changed (150) hide show
  1. package/CHANGELOG.md +268 -0
  2. package/LICENSE.md +13 -0
  3. package/README.md +348 -0
  4. package/actions/check.d.ts +11 -0
  5. package/actions/check.js +45 -0
  6. package/actions/check.js.map +1 -0
  7. package/actions/index.d.ts +5 -0
  8. package/actions/index.js +22 -0
  9. package/actions/index.js.map +1 -0
  10. package/actions/install.d.ts +5 -0
  11. package/actions/install.js +25 -0
  12. package/actions/install.js.map +1 -0
  13. package/actions/patch.d.ts +6 -0
  14. package/actions/patch.js +82 -0
  15. package/actions/patch.js.map +1 -0
  16. package/actions/uninstall.d.ts +5 -0
  17. package/actions/uninstall.js +26 -0
  18. package/actions/uninstall.js.map +1 -0
  19. package/actions/unpatch.d.ts +3 -0
  20. package/actions/unpatch.js +82 -0
  21. package/actions/unpatch.js.map +1 -0
  22. package/bin/ts-patch.d.ts +1 -0
  23. package/bin/ts-patch.js +33 -0
  24. package/bin/ts-patch.js.map +1 -0
  25. package/bin/tspc.d.ts +0 -0
  26. package/bin/tspc.js +14 -0
  27. package/bin/tspc.js.map +1 -0
  28. package/cli/cli.d.ts +14 -0
  29. package/cli/cli.js +96 -0
  30. package/cli/cli.js.map +1 -0
  31. package/cli/commands.d.ts +5 -0
  32. package/cli/commands.js +49 -0
  33. package/cli/commands.js.map +1 -0
  34. package/cli/help-menu.d.ts +1 -0
  35. package/cli/help-menu.js +43 -0
  36. package/cli/help-menu.js.map +1 -0
  37. package/cli/options.d.ts +14 -0
  38. package/cli/options.js +63 -0
  39. package/cli/options.js.map +1 -0
  40. package/compiler/package.json +4 -0
  41. package/compiler/tsc.js +19 -0
  42. package/compiler/tsserver.js +19 -0
  43. package/compiler/tsserverlibrary.js +19 -0
  44. package/compiler/typescript.js +19 -0
  45. package/config.d.ts +18 -0
  46. package/config.js +50 -0
  47. package/config.js.map +1 -0
  48. package/index.d.ts +4 -0
  49. package/index.js +29 -0
  50. package/index.js.map +1 -0
  51. package/module/get-live-module.d.ts +5 -0
  52. package/module/get-live-module.js +25 -0
  53. package/module/get-live-module.js.map +1 -0
  54. package/module/index.d.ts +4 -0
  55. package/module/index.js +21 -0
  56. package/module/index.js.map +1 -0
  57. package/module/module-file.d.ts +9 -0
  58. package/module/module-file.js +97 -0
  59. package/module/module-file.js.map +1 -0
  60. package/module/module-source.d.ts +15 -0
  61. package/module/module-source.js +35 -0
  62. package/module/module-source.js.map +1 -0
  63. package/module/source-section.d.ts +20 -0
  64. package/module/source-section.js +73 -0
  65. package/module/source-section.js.map +1 -0
  66. package/module/ts-module.d.ts +35 -0
  67. package/module/ts-module.js +100 -0
  68. package/module/ts-module.js.map +1 -0
  69. package/options.d.ts +19 -0
  70. package/options.js +32 -0
  71. package/options.js.map +1 -0
  72. package/package.json +107 -0
  73. package/patch/get-patched-source.d.ts +12 -0
  74. package/patch/get-patched-source.js +69 -0
  75. package/patch/get-patched-source.js.map +1 -0
  76. package/patch/patch-detail.d.ts +36 -0
  77. package/patch/patch-detail.js +67 -0
  78. package/patch/patch-detail.js.map +1 -0
  79. package/patch/patch-module.d.ts +5 -0
  80. package/patch/patch-module.js +182 -0
  81. package/patch/patch-module.js.map +1 -0
  82. package/patch/transformers/add-original-create-program.d.ts +3 -0
  83. package/patch/transformers/add-original-create-program.js +71 -0
  84. package/patch/transformers/add-original-create-program.js.map +1 -0
  85. package/patch/transformers/fix-ts-early-return.d.ts +2 -0
  86. package/patch/transformers/fix-ts-early-return.js +51 -0
  87. package/patch/transformers/fix-ts-early-return.js.map +1 -0
  88. package/patch/transformers/hook-tsc-exec.d.ts +2 -0
  89. package/patch/transformers/hook-tsc-exec.js +32 -0
  90. package/patch/transformers/hook-tsc-exec.js.map +1 -0
  91. package/patch/transformers/index.d.ts +6 -0
  92. package/patch/transformers/index.js +23 -0
  93. package/patch/transformers/index.js.map +1 -0
  94. package/patch/transformers/merge-statements.d.ts +2 -0
  95. package/patch/transformers/merge-statements.js +60 -0
  96. package/patch/transformers/merge-statements.js.map +1 -0
  97. package/patch/transformers/patch-create-program.d.ts +2 -0
  98. package/patch/transformers/patch-create-program.js +36 -0
  99. package/patch/transformers/patch-create-program.js.map +1 -0
  100. package/patch/transformers/patch-emitter.d.ts +2 -0
  101. package/patch/transformers/patch-emitter.js +44 -0
  102. package/patch/transformers/patch-emitter.js.map +1 -0
  103. package/plugin-types.d.ts +95 -0
  104. package/plugin-types.js +4 -0
  105. package/plugin-types.js.map +1 -0
  106. package/resources/module-patch.d.ts +50 -0
  107. package/resources/module-patch.js +609 -0
  108. package/slice/module-slice.d.ts +19 -0
  109. package/slice/module-slice.js +37 -0
  110. package/slice/module-slice.js.map +1 -0
  111. package/slice/ts54.d.ts +6 -0
  112. package/slice/ts54.js +70 -0
  113. package/slice/ts54.js.map +1 -0
  114. package/slice/ts55.d.ts +6 -0
  115. package/slice/ts55.js +70 -0
  116. package/slice/ts55.js.map +1 -0
  117. package/slice/ts552.d.ts +6 -0
  118. package/slice/ts552.js +70 -0
  119. package/slice/ts552.js.map +1 -0
  120. package/system/cache.d.ts +3 -0
  121. package/system/cache.js +69 -0
  122. package/system/cache.js.map +1 -0
  123. package/system/errors.d.ts +35 -0
  124. package/system/errors.js +82 -0
  125. package/system/errors.js.map +1 -0
  126. package/system/index.d.ts +4 -0
  127. package/system/index.js +21 -0
  128. package/system/index.js.map +1 -0
  129. package/system/logger.d.ts +7 -0
  130. package/system/logger.js +48 -0
  131. package/system/logger.js.map +1 -0
  132. package/system/types.d.ts +4 -0
  133. package/system/types.js +7 -0
  134. package/system/types.js.map +1 -0
  135. package/ts-package.d.ts +18 -0
  136. package/ts-package.js +73 -0
  137. package/ts-package.js.map +1 -0
  138. package/tsconfig.tsbuildinfo +1 -0
  139. package/utils/file-utils.d.ts +9 -0
  140. package/utils/file-utils.js +98 -0
  141. package/utils/file-utils.js.map +1 -0
  142. package/utils/find-cache-dir.d.ts +23 -0
  143. package/utils/find-cache-dir.js +93 -0
  144. package/utils/find-cache-dir.js.map +1 -0
  145. package/utils/general.d.ts +5 -0
  146. package/utils/general.js +16 -0
  147. package/utils/general.js.map +1 -0
  148. package/utils/index.d.ts +3 -0
  149. package/utils/index.js +20 -0
  150. package/utils/index.js.map +1 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,268 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
+
5
+ ### [3.2.1](https://github.com/nonara/ts-patch/compare/v3.2.0...v3.2.1) (2024-06-26)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * Added TS 5.5.2 support ([31eb80f](https://github.com/nonara/ts-patch/commit/31eb80f1dcca45d15917e4b6621769f80e57ebe1))
11
+
12
+ ## [3.2.0](https://github.com/nonara/ts-patch/compare/v3.1.2...v3.2.0) (2024-06-03)
13
+
14
+
15
+ ### Features
16
+
17
+ * Added support for TS 5.5 ([2c4954d](https://github.com/nonara/ts-patch/commit/2c4954d91def5f0654804bfbf64704720f605840))
18
+
19
+ ### [3.1.2](https://github.com/nonara/ts-patch/compare/v3.1.1...v3.1.2) (2024-01-10)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * don't break if other plugin is added ([f2b591e](https://github.com/nonara/ts-patch/commit/f2b591e1a78636d009af048689f2ae1c0bb89bea))
25
+
26
+ ### [3.1.1](https://github.com/nonara/ts-patch/compare/v3.1.0...v3.1.1) (2023-12-06)
27
+
28
+
29
+ ### Bug Fixes
30
+
31
+ * parseAllJsDoc breaking with < ts 5.3 ([d21e02e](https://github.com/nonara/ts-patch/commit/d21e02ef6401f04301972f8f107799b8c287275b))
32
+
33
+ ## [3.1.0](https://github.com/nonara/ts-patch/compare/v3.0.2...v3.1.0) (2023-12-05)
34
+
35
+
36
+ ### Features
37
+
38
+ * Added Plugin Package Configuration + parseAllJsDoc (closes [#134](https://github.com/nonara/ts-patch/issues/134) closes [#133](https://github.com/nonara/ts-patch/issues/133)) ([15570d0](https://github.com/nonara/ts-patch/commit/15570d05e422dd02635eb3c63dc6b3a036cb543a))
39
+ * Added support for chaining transformers in single factory (closes [#122](https://github.com/nonara/ts-patch/issues/122) closes [#120](https://github.com/nonara/ts-patch/issues/120)) ([aabf389](https://github.com/nonara/ts-patch/commit/aabf3894a610047fade6d2d9fb9949f17afe09df))
40
+
41
+
42
+ ### Bug Fixes
43
+
44
+ * TsExtras 'ts' type registering as 'any' (fixes [#127](https://github.com/nonara/ts-patch/issues/127)) ([069411e](https://github.com/nonara/ts-patch/commit/069411e49819aa87c880c7c5ff2ab04ecb68eea3))
45
+ * tsp.currentLibrary was not set (detail) ([24d8031](https://github.com/nonara/ts-patch/commit/24d8031bafcd6483fa762ed9ad8437c4a4070093))
46
+
47
+ ### [3.0.2](https://github.com/nonara/ts-patch/compare/v3.0.1...v3.0.2) (2023-07-20)
48
+
49
+
50
+ ### Bug Fixes
51
+
52
+ * Plugins returning TransformerBasePlugin not supported (fixes [#113](https://github.com/nonara/ts-patch/issues/113)) ([12ee3a2](https://github.com/nonara/ts-patch/commit/12ee3a23b9afebb6a42c046b33f257a2bde2467c))
53
+
54
+ ### [3.0.1](https://github.com/nonara/ts-patch/compare/v3.0.0...v3.0.1) (2023-06-22)
55
+
56
+
57
+ ### Bug Fixes
58
+
59
+ * Added explicit error if ts is patched and cached backup is removed ([ac25743](https://github.com/nonara/ts-patch/commit/ac25743140f8f3954aceb8c0e43a731eeeab03a1))
60
+ * ESM temp files not cleaned up ([8802054](https://github.com/nonara/ts-patch/commit/8802054481a9f2b4847001cb227db029e0475a72))
61
+ * Lock file deletion check ([#102](https://github.com/nonara/ts-patch/issues/102)) ([cacf908](https://github.com/nonara/ts-patch/commit/cacf9084fd4e5a2a1263103f8dc52d2dd7062402))
62
+
63
+ ## [3.0.0](https://github.com/nonara/ts-patch/compare/v2.1.0...v3.0.0) (2023-06-13)
64
+
65
+
66
+ ### ⚠ BREAKING CHANGES
67
+
68
+ * Rewrote for new major v3 (see detail) ([cd69c1c](https://github.com/nonara/ts-patch/commit/cd69c1c02b2e4674731178def7d217d5699bde25)), closes [#58](https://github.com/nonara/ts-patch/issues/58) [#75](https://github.com/nonara/ts-patch/issues/75) [#83](https://github.com/nonara/ts-patch/issues/83) [#93](https://github.com/nonara/ts-patch/issues/93) [#85](https://github.com/nonara/ts-patch/issues/85)
69
+
70
+ ### Features
71
+
72
+ * Added Live Compiler (on-the-fly, in-memory patching), which allows ttypescript migration
73
+ * Added experimental ES Module support (closes #58)
74
+ * Added mutex locks (closes #75)
75
+ * Updated to support TS v5+ (closes #83 closes #93)
76
+ * Added caching
77
+
78
+ ### Bug Fixes
79
+
80
+ * Fixed patching for non-standard libraries (cannot guarantee they will work as expected in IDEs) (closes #85)
81
+
82
+ ## [2.1.0](https://github.com/nonara/ts-patch/compare/v2.0.2...v2.1.0) (2022-12-08)
83
+
84
+
85
+ ### Features
86
+
87
+ * Updated to support TS 4.9 ([26f6099](https://github.com/nonara/ts-patch/commit/26f6099543d258a2a430f8344b482aba85ac9b0e))
88
+
89
+ ### [2.0.2](https://github.com/nonara/ts-patch/compare/v2.0.1...v2.0.2) (2022-08-10)
90
+
91
+
92
+ ### Changes
93
+
94
+ * Upgraded dependencies ([a878131](https://github.com/nonara/ts-patch/commit/a87813190eb31b918574509e4dfe4ef3b427b212))
95
+
96
+ ### [2.0.1](https://github.com/nonara/ts-patch/compare/v1.4.5...v2.0.1) (2021-11-01)
97
+
98
+ ### Bug Fixes
99
+
100
+ * Corrected path error in previous release ([7c56d56](https://github.com/nonara/ts-patch/commit/7c56d56b5165affb9c58a3c65c2753391f3e967a))
101
+
102
+ ## [2.0.0](https://github.com/nonara/ts-patch/compare/v1.4.5...v2.0.0) (2021-11-01)
103
+
104
+
105
+ ### Summary
106
+
107
+ This is not the planned rewrite, but the codebase was in desperate need of an update. The patch build system with rollup was failing with newer versions and was hacky under the best of circumstances, anyway. This new version has a proper custom build system that produces a much leaner patch. Additionally, I reorganized the codebase, improved tests, and dropped old TS support.
108
+
109
+ _Note: If you absolutely need it, it will still work with older TS. Simply fork and remove the version check_
110
+
111
+ ### Changes
112
+
113
+ - Soft deprecated `--basedir` (use `--dir`)
114
+ - Zero bundled dependencies in patch (much lighter)
115
+ - ⚠️ Hard deprecated `--persist` option (use `package.json` -> `prepare` script)
116
+ - ⚠️ Requires TS >= 4.0
117
+
118
+ _(⚠️ denotes potential "breaking" change)_
119
+
120
+ ### Development Changes
121
+
122
+ - Removed rollup and created light-weight custom build system
123
+ - Cleaned up file structure
124
+ - Improved test speed & methodology
125
+ - Changed patch detection signature
126
+
127
+ ### [1.4.5](https://github.com/nonara/ts-patch/compare/v1.4.4...v1.4.5) (2021-10-25)
128
+
129
+
130
+ ### Bug Fixes
131
+
132
+ * compilation fails if basedir resolves to cwd ([#65](https://github.com/nonara/ts-patch/issues/65)) ([9bac698](https://github.com/nonara/ts-patch/commit/9bac698993cd287de6d62caba48205bf53b4e52e))
133
+
134
+ ### [1.4.4](https://github.com/nonara/ts-patch/compare/v1.4.3...v1.4.4) (2021-08-27)
135
+
136
+
137
+ ### Bug Fixes
138
+
139
+ * `--basedir` flag fails if dir is not a subdir of a package ([5912288](https://github.com/nonara/ts-patch/commit/5912288f36f98a1722252d150a456c139e3f8382))
140
+
141
+ ### [1.4.3](https://github.com/nonara/ts-patch/compare/v1.4.2...v1.4.3) (2021-08-23)
142
+
143
+
144
+ ### Bug Fixes
145
+
146
+ * Relative transform paths do not resolve from project root dir with compiler API (fixes [#59](https://github.com/nonara/ts-patch/issues/59)) ([e38655a](https://github.com/nonara/ts-patch/commit/e38655ac20f3905e61bcf8bfc03b97a5386b76f8))
147
+ * ts 3.6.5 does not patch properly (fixes [#55](https://github.com/nonara/ts-patch/issues/55)) ([1babac9](https://github.com/nonara/ts-patch/commit/1babac9284d330983a9658794680a5058e7c64c0))
148
+
149
+ ### [1.4.2](https://github.com/nonara/ts-patch/compare/v1.4.1...v1.4.2) (2021-08-01)
150
+
151
+
152
+ ### Bug Fixes
153
+
154
+ * Patch fails on ts v3.1 - 3.5 (fixes [#54](https://github.com/nonara/ts-patch/issues/54)) ([0fabe3c](https://github.com/nonara/ts-patch/commit/0fabe3c85129357a6ad453e48739dd1759efe18d))
155
+
156
+ ### [1.4.1](https://github.com/nonara/ts-patch/compare/v1.4.0...v1.4.1) (2021-07-13)
157
+
158
+
159
+ ### Bug Fixes
160
+
161
+ * Only patch 'tsc.js' and 'typescript.js' by default (closes [#52](https://github.com/nonara/ts-patch/issues/52)) ([4d029f6](https://github.com/nonara/ts-patch/commit/4d029f666abdf5e2862c773eeba97eeddbb80089))
162
+
163
+ ## [1.4.0](https://github.com/nonara/ts-patch/compare/v1.3.4...v1.4.0) (2021-07-13)
164
+
165
+
166
+ ### Features
167
+
168
+ * Add tsserver.js to supported libraries ([08262ed](https://github.com/nonara/ts-patch/commit/08262ede07c6e69b178751013988da772661ef02))
169
+
170
+
171
+ ### Bug Fixes
172
+
173
+ * Require ts-node installation to be handled by user (fixes [#51](https://github.com/nonara/ts-patch/issues/51)) ([979338c](https://github.com/nonara/ts-patch/commit/979338ca5f0642b233de46dd6d293daa7f552ac4))
174
+
175
+ ### [1.3.4](https://github.com/nonara/ts-patch/compare/v1.3.3...v1.3.4) (2021-06-30)
176
+
177
+
178
+ ### Bug Fixes
179
+
180
+ * Install adds ts-node to deps instead of devDeps (fixes [#38](https://github.com/nonara/ts-patch/issues/38)) ([a2d586b](https://github.com/nonara/ts-patch/commit/a2d586b286a4af0650faf69d3163115442aec8ab))
181
+
182
+ ### [1.3.3](https://github.com/nonara/ts-patch/compare/v1.3.2...v1.3.3) (2021-04-23)
183
+
184
+
185
+ ### Bug Fixes
186
+
187
+ * **patch:** Patched emit does not pass all arguments (fixes [#36](https://github.com/nonara/ts-patch/issues/36)) ([9b130bc](https://github.com/nonara/ts-patch/commit/9b130bc8fd1a5bf3e7b33f796990ed7383aa5449))
188
+
189
+ ### [1.3.2](https://github.com/nonara/ts-patch/compare/v1.3.1...v1.3.2) (2021-01-31)
190
+
191
+ ## [1.3.1] (11-25-2020)
192
+
193
+ ### Fixed
194
+ - Fixed #21 (Could not specify `--basedir` with dir name other than `typescript` - affected yarn aliasing)
195
+
196
+ ## [1.3.0] (07-26-2020)
197
+
198
+ ### Added
199
+ - Added ability to specify tsconfig.json file for transformer (`tsConfig` option)
200
+ Note: This opens up the door to specify compilerOptions, which can be useful
201
+ - Added path mapping support (requires [tsconfig-paths](https://npmjs.com/tsconfig-paths))
202
+
203
+ ## [1.2.2] (05-23-2020)
204
+
205
+ ### Fixed
206
+ - Possible recursion issue with program transformer
207
+ - In some older TS versions, tsc wasn't passing diagnostics array
208
+ - Various CLI bugs
209
+
210
+ ### Added
211
+ - Added 'library' to TspExtras
212
+ - install and patch actions now will proceed to run if already patched but current version is out-dated
213
+
214
+ ### Code
215
+ - Substantial re-design of certain parts (see release commit message for more)
216
+
217
+ ## [1.2.0] (05-20-2020)
218
+
219
+ ### Changed: `beforeEmit` -> `tranformProgram`
220
+
221
+ The mechanism of action for `Program` transformation has been moved from inside
222
+ `program.emit()` to `ts.createProgram()`.
223
+
224
+ In the new methodology, the `Program` instance is transformed at the point of creation _before_ it is returned from the
225
+ factory function, which is a far better approach.
226
+
227
+ While the option name has been updated to reflect the new behaviour, the old `beforeEmit` can still function as an alias
228
+ to the new behaviour, so this is not a breaking change.
229
+
230
+ ### Added: Inspect or alter diagnostics
231
+
232
+ Using the `program` type entry point, the `extras` field has been revised.
233
+
234
+ | property | status | description |
235
+ | -------- | ------ | ----------- |
236
+ | diagnostics | _new_ | Reference to `Diagnostic[]` created during `ts.emitFilesAndReportErrors()` (works with tsc also)
237
+ | addDiagnostic | _changed_ | Directly add `Diagnostic` to `diagnostics` array |
238
+ | removeDiagnostic | _new_ | Directly remove `Diagnostic` from `diagnostics` array (uses splice, for safe removal)
239
+
240
+ See `README.md` for full detail.
241
+
242
+ ## [1.1.0] (05-08-2020)
243
+
244
+ ### Added
245
+ - Added `beforeEmit` option, which allows 'transforming' `Program` instance before `program.emit()` is called.
246
+
247
+ ## [1.0] (2019 - 2020)
248
+
249
+ ### Fixed
250
+ - Updated for Node v14
251
+ _(Addresses [#7](https://github.com/nonara/ts-patch/issues/8), [shelljs/shelljs#991](https://github.com/shelljs/shelljs/issues/991))_
252
+ - Adjusted ts-node compilerOptions to ES2018
253
+ _(Fixes [#7](https://github.com/nonara/ts-patch/issues/7))_
254
+ - Exposed & fixed `addDiagnostic` helper
255
+ _(Fixes [#6](https://github.com/nonara/ts-patch/issues/6))_
256
+ - Rolled `resolve` package into patch
257
+ _(Fixes [#5](https://github.com/nonara/ts-patch/issues/5))_
258
+ - Converted EOL to LF (MacOS support)
259
+ _(Fixes [#3](https://github.com/nonara/ts-patch/issues/3) [#4](https://github.com/nonara/ts-patch/issues/4))_
260
+ - Edge cases occurred in which TypeScript based transformers using CommonJS were not being interpretted properly.
261
+ _(Should address [issue #1](https://github.com/nonara/ts-patch/issues/1))_
262
+
263
+ [1.3.1]: https://github.com/nonara/ts-patch/compare/v1.3.0...v1.3.1
264
+ [1.3.0]: https://github.com/nonara/ts-patch/compare/v1.2.2...v1.3.0
265
+ [1.2.2]: https://github.com/nonara/ts-patch/compare/v1.1.0...v1.2.2
266
+ [1.2.0]: https://github.com/nonara/ts-patch/compare/v1.1.0...v1.2.0
267
+ [1.1.0]: https://github.com/nonara/ts-patch/compare/v1.0.10...v1.1.0
268
+ [1.0]: https://github.com/nonara/ts-patch/releases/tag/v1.0.0...v1.0.10
package/LICENSE.md ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2021 Ron Spickenagel
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
4
+ files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use,
5
+ copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom
6
+ the Software is furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
11
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
12
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
13
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,348 @@
1
+ [![npm version](https://badge.fury.io/js/ts-patch.svg)](https://badge.fury.io/js/ts-patch)
2
+ [![NPM Downloads](https://img.shields.io/npm/dm/ts-patch.svg?style=flat)](https://npmjs.org/package/ts-patch)
3
+ ![Build Status](https://github.com/nonara/ts-patch/workflows/Build/badge.svg)
4
+
5
+ # ts-patch
6
+
7
+ Patch typescript to allow custom transformers (plugins) during build.
8
+
9
+ Plugins are specified in `tsconfig.json`, or provided programmatically in `CompilerOptions`.
10
+
11
+ _Migrating from ttypescript is easy! See: [Method 1: Live Compiler](#method-1-live-compiler)_
12
+
13
+ ## Features
14
+
15
+ * Patch typescript installation via on-the-fly, in-memory patching _or_ as a persistent patch
16
+ * Can patch individual libraries (see `ts-patch /?`)
17
+ * Hook build process by transforming the `Program` (see: [Transforming Program](#transforming-program))
18
+ * Add, remove, or modify diagnostics (see: [Altering Diagnostics](#altering-diagnostics))
19
+ * Fully compatible with legacy [ttypescript](https://github.com/cevek/ttypescript) projects
20
+ * **(new)** Experimental support for ES Module based transformers
21
+
22
+ # Table of Contents
23
+
24
+ <!-- TOC -->
25
+ * [ts-patch](#ts-patch)
26
+ * [Features](#features)
27
+ * [Table of Contents](#table-of-contents)
28
+ * [Installation](#installation)
29
+ * [Usage](#usage)
30
+ * [Method 1: Live Compiler](#method-1-live-compiler)
31
+ * [Method 2: Persistent Patch](#method-2-persistent-patch)
32
+ * [Configuration](#configuration)
33
+ * [Plugin Options](#plugin-options)
34
+ * [Writing Transformers](#writing-transformers)
35
+ * [Source Transformers](#source-transformers)
36
+ * [Source Transformer Entry Point](#source-transformer-entry-point)
37
+ * [Source Transformer Example](#source-transformer-example)
38
+ * [Altering Diagnostics](#altering-diagnostics)
39
+ * [Note](#note)
40
+ * [Program Transformers](#program-transformers)
41
+ * [Program Transformer Entry Point](#program-transformer-entry-point)
42
+ * [Configuring Program Transformers](#configuring-program-transformers)
43
+ * [Program Transformer Example](#program-transformer-example)
44
+ * [Plugin Package Configuration](#plugin-package-configuration)
45
+ * [Example](#example)
46
+ * [Resources](#resources)
47
+ * [Recommended Reading](#recommended-reading)
48
+ * [Recommended Tools](#recommended-tools)
49
+ * [Discussion](#discussion)
50
+ * [Advanced Options](#advanced-options)
51
+ * [Maintainers](#maintainers)
52
+ * [Help Wanted](#help-wanted)
53
+ * [License](#license)
54
+ <!-- TOC -->
55
+
56
+ # Installation
57
+
58
+ 1. Install package
59
+ ```sh
60
+ <yarn|npm|pnpm> add -D ts-patch
61
+ ```
62
+
63
+ # Usage
64
+
65
+ ## Method 1: Live Compiler
66
+
67
+ The live compiler patches on-the-fly, each time it is run.
68
+
69
+ **Via commandline:** Simply use `tspc` (instead of `tsc`)
70
+
71
+ **With tools such as ts-node, webpack, ts-jest, etc:** specify the compiler as `ts-patch/compiler`
72
+
73
+ ## Method 2: Persistent Patch
74
+
75
+ Persistent patch modifies the typescript installation within the node_modules path. It requires additional configuration
76
+ to remain persisted, but it carries less load time and complexity compared to the live compiler.
77
+
78
+ 1. Install the patch
79
+
80
+ ```shell
81
+ # For advanced options, see: ts-patch /?
82
+ ts-patch install
83
+ ```
84
+
85
+ 2. Add `prepare` script (keeps patch persisted after npm install)
86
+
87
+ `package.json`
88
+ ```jsonc
89
+ {
90
+ /* ... */
91
+ "scripts": {
92
+ "prepare": "ts-patch install -s"
93
+ }
94
+ }
95
+ ```
96
+
97
+ # Configuration
98
+
99
+ **tsconfig.json**: Add transformers to `compilerOptions` in `plugins` array.
100
+
101
+ **Examples**
102
+ ```jsonc
103
+ {
104
+ "compilerOptions": {
105
+ "plugins": [
106
+ // Source Transformers
107
+ { "transform": "transformer-module" },
108
+ { "transform": "transformer2", "extraOption": 123 },
109
+ { "transform": "trans-with-mapping", "resolvePathAliases": true },
110
+ { "transform": "esm-transformer", "isEsm": true },
111
+
112
+ // Program Transformer
113
+ { "transform": "transformer-module5", "transformProgram": true }
114
+ ]
115
+ }
116
+ }
117
+ ```
118
+
119
+ ## Plugin Options
120
+
121
+ | Option | Type | Description |
122
+ |--------------------|---------|:--------------------------------------------------------------------------------------------------------------|
123
+ | **transform** | string | Module name or path to transformer _(*.ts or *.js)_ |
124
+ | after | boolean | Apply transformer after stock TS transformers |
125
+ | afterDeclarations | boolean | Apply transformer to declaration (*.d.ts) files |
126
+ | transformProgram | boolean | Transform `Program` during `ts.createProgram()` _(see: [Program Transformers](#program-transformers))_ |
127
+ | isEsm | boolean | Transformer is ES Module (_note: experimental_ — requires [esm](https://www.npmjs.com/package/esm)) |
128
+ | resolvePathAliases | boolean | Resolve path aliases in transformer (requires [tsconfig-paths](https://www.npmjs.com/package/tsconfig-paths)) |
129
+ | type | string | See: [Source Transformer Entry Point](#source-transformer-entry-point) (default: 'program') |
130
+ | import | string | Name of exported transformer function _(defaults to `default` export)_ |
131
+ | tsConfig | string | tsconfig.json file _for transformer_ (allows specifying compileOptions, path mapping support, etc) |
132
+ | _..._ | | Provide your own custom options, which will be passed to the transformer |
133
+
134
+ _Note: Required options are bold_
135
+
136
+ # Writing Transformers
137
+
138
+ For an overview of the typescript compiler (such as what a `SourceFile` and `Program` is) see: [Typescript Compiler Notes](https://github.com/microsoft/TypeScript-Compiler-Notes).
139
+
140
+ ## Source Transformers
141
+
142
+ Source Transformers will transform the AST of SourceFiles during compilation, allowing you to alter the output of the JS or declarations files.
143
+
144
+ ### Source Transformer Entry Point
145
+
146
+ ```ts
147
+ (program: ts.Program, config: PluginConfig, extras: TransformerExtras) => ts.TransformerFactory
148
+ ```
149
+
150
+ **PluginConfig**: [Type Declaration](https://github.com/nonara/ts-patch/blob/master/projects/core/shared/plugin-types.ts)
151
+ **TransformerExtras**: [Type Declaration](https://github.com/nonara/ts-patch/blob/master/projects/core/shared/plugin-types.ts)
152
+ **ts.TransformerFactory**: `(context: ts.TransformationContext) => (sourceFile: ts.SourceFile) => ts.SourceFile`
153
+
154
+ _Note: Additional [legacy signatures](https://github.com/cevek/ttypescript#pluginconfigtype) are supported, but it is not recommended to develop a new transformer using them._
155
+
156
+ ### Source Transformer Example
157
+
158
+ Transformers can be written in JS or TS.
159
+
160
+ ```ts
161
+ import type * as ts from 'typescript';
162
+ import type { TransformerExtras, PluginConfig } from 'ts-patch';
163
+
164
+ /** Changes string literal 'before' to 'after' */
165
+ export default function (program: ts.Program, pluginConfig: PluginConfig, { ts: tsInstance }: TransformerExtras) {
166
+ return (ctx: ts.TransformationContext) => {
167
+ const { factory } = ctx;
168
+
169
+ return (sourceFile: ts.SourceFile) => {
170
+ function visit(node: ts.Node): ts.Node {
171
+ if (tsInstance.isStringLiteral(node) && node.text === 'before') {
172
+ return factory.createStringLiteral('after');
173
+ }
174
+ return tsInstance.visitEachChild(node, visit, ctx);
175
+ }
176
+ return tsInstance.visitNode(sourceFile, visit);
177
+ };
178
+ };
179
+ }
180
+
181
+ ```
182
+
183
+ **Live Examples**:
184
+
185
+ [`{ transform: "typescript-transform-paths" }`](https://github.com/LeDDGroup/typescript-transform-paths)
186
+
187
+ [`{ transform: "typescript-is/lib/transform-inline/transformer" }`](https://github.com/woutervh-/typescript-is)
188
+
189
+ [`{ transform: "typia/lib/transform" }`](https://github.com/samchon/typia) ([💻playground](https://typia.io/playground))
190
+
191
+ [`{ transform: "@nestia/core/lib/transform" }`](https://github.com/samchon/nestia)
192
+
193
+ ### Altering Diagnostics
194
+
195
+ Diagnostics can be altered in a Source Transformer.
196
+
197
+ To alter diagnostics you can use the following, provided from the `TransformerExtras` parameter:
198
+
199
+ | property | description |
200
+ |--------------------|-----------------------------------------------------|
201
+ | diagnostics | Reference to `Diagnostic` array |
202
+ | addDiagnostic() | Safely add `Diagnostic` to `diagnostics` array |
203
+ | removeDiagnostic() | Safely remove `Diagnostic` from `diagnostics` array |
204
+
205
+ ### Note
206
+
207
+ _This alters diagnostics during _emit only_. If you want to alter diagnostics in your IDE as well, you'll need to create a LanguageService plugin to accompany your source transformer_
208
+
209
+ ## Program Transformers
210
+
211
+ Sometimes you want to do more than just transform source code. For example you may want to:
212
+
213
+ - TypeCheck code after it's been transformed
214
+ - Generate code and add it to the program
215
+ - Add or remove emit files during transformation
216
+
217
+ For this, we've introduced what we call a Program Transformer. The transform action takes place during `ts.createProgram`, and allows
218
+ re-creating the `Program` instance that typescript uses.
219
+
220
+ ### Program Transformer Entry Point
221
+
222
+ ```ts
223
+ (program: ts.Program, host: ts.CompilerHost | undefined, options: PluginConfig, extras: ProgramTransformerExtras) => ts.Program
224
+ ```
225
+
226
+ **ProgramTransformerExtras** >>> [Type Declaration](https://github.com/nonara/ts-patch/blob/master/projects/core/shared/plugin-types.ts)
227
+
228
+ ### Configuring Program Transformers
229
+
230
+ To configure a Program Transformer, supply `"transformProgram": true` in the config transformer entry.
231
+
232
+ _Note: The `before`, `after`, and `afterDeclarations` options do not apply to a Program Transformer and will be ignored_
233
+
234
+ [See Config Example](#configuration)
235
+
236
+ ### Program Transformer Example
237
+ ```TypeScript
238
+ /**
239
+ * Add a file to Program
240
+ */
241
+ import * as path from 'path';
242
+ import type * as ts from 'typescript';
243
+ import type { ProgramTransformerExtras, PluginConfig } from 'ts-patch';
244
+
245
+ export const newFile = path.resolve(__dirname, 'added-file.ts');
246
+
247
+ export default function (
248
+ program: ts.Program,
249
+ host: ts.CompilerHost | undefined,
250
+ options: PluginConfig,
251
+ { ts: tsInstance }: ProgramTransformerExtras
252
+ ) {
253
+ return tsInstance.createProgram(
254
+ /* rootNames */ program.getRootFileNames().concat([ newFile ]),
255
+ program.getCompilerOptions(),
256
+ host,
257
+ /* oldProgram */ program
258
+ );
259
+ }
260
+ ```
261
+
262
+ **Note:** For a more complete example, see [Transforming Program with additional AST transformations](https://github.com/nonara/ts-patch/discussions/29#discussioncomment-325979)
263
+
264
+ **Live Examples**:
265
+
266
+ [`{ transform: "@typescript-virtual-barrel/compiler-plugin", transformProgram: true }`](https://github.com/zaguiini/typescript-virtual-barrel)
267
+
268
+ [`{ transform: "ts-overrides-plugin", transformProgram: true }`](https://github.com/DiFuks/ts-overrides-plugin)
269
+
270
+ ## Plugin Package Configuration
271
+
272
+ The plugin package configuration allows you to specify custom options for your TypeScript plugin.
273
+ This configuration is defined in the `package.json` of your plugin under the `tsp` property.
274
+
275
+ An example use case is enabling `parseAllJsDoc` if you require full JSDoc parsing in tsc for your transformer in TS v5.3+. (see: [5.3 JSDoc parsing changes](https://devblogs.microsoft.com/typescript/announcing-typescript-5-3/#optimizations-by-skipping-jsdoc-parsing))
276
+
277
+ For all available options, see the `PluginPackageConfig` type in [plugin-types.ts](https://github.com/nonara/ts-patch/blob/master/projects/core/shared/plugin-types.ts)
278
+
279
+ ### Example
280
+
281
+ ```jsonc
282
+ {
283
+ "name": "your-plugin-name",
284
+ "version": "1.0.0",
285
+ "tsp": {
286
+ "tscOptions": {
287
+ "parseAllJsDoc": true
288
+ }
289
+ }
290
+ }
291
+ ```
292
+
293
+ ## Resources
294
+
295
+ ### Recommended Reading
296
+
297
+ - How-To: [Advice for working with the TS Compiler API](https://github.com/nonara/ts-patch/discussions/31)
298
+ - How-To: [TypeScript Transformer Handbook](https://github.com/madou/typescript-transformer-handbook)
299
+ - Article: [How to Write a TypeScript Transform (Plugin)](https://dev.doctorevidence.com/how-to-write-a-typescript-transform-plugin-fc5308fdd943)
300
+ - Article: [Creating a TypeScript Transformer](https://43081j.com/2018/08/creating-a-typescript-transform?source=post_page-----731e2b0b66e6----------------------)
301
+
302
+ ### Recommended Tools
303
+
304
+ | Tool | Type | Description |
305
+ |----------------------------------------------------------------------|-------------|---------------------------------------------------------------------------------------------|
306
+ | [TS AST Viewer](https://ts-ast-viewer.com/) | Web App | Allows you to see the `Node` structure and other TS properties of your source code. |
307
+ | [ts-expose-internals](https://github.com/nonara/ts-expose-internals) | NPM Package | Exposes internal types and methods of the TS compiler API |
308
+
309
+ ### Discussion
310
+
311
+ - `#compiler-internals-and-api` on [TypeScript Discord Server](https://discord.com/invite/typescript)
312
+ - TSP [Discussions](https://github.com/nonara/ts-patch/discussions) Board
313
+
314
+ # Advanced Options
315
+
316
+ **(env) `TSP_SKIP_CACHE`**
317
+
318
+ Skips patch cache when patching via cli or live compiler.
319
+
320
+ **(env) `TSP_COMPILER_TS_PATH`**
321
+
322
+ Specify typescript library path to use for `ts-patch/compiler` (defaults to `require.resolve('typescript')`)
323
+
324
+ **(env) `TSP_CACHE_DIR`**
325
+
326
+ Override patch cache directory
327
+
328
+ **(cli) `ts-patch clear-cache`**
329
+
330
+ Cleans patch cache & lockfiles
331
+
332
+ # Maintainers
333
+
334
+ <!-- prettier-ignore-start -->
335
+ <!-- markdownlint-disable -->
336
+ <table>
337
+ <tr>
338
+ <td align="center"><a href="https://github.com/nonara"><img src="https://avatars0.githubusercontent.com/u/1427565?v=4" width="100px;" alt=""/><br /><sub><b>Ron S.</b></sub></a></td>
339
+ </tr>
340
+ </table>
341
+
342
+ ## Help Wanted
343
+
344
+ If you're interested in helping and are knowledgeable with the TS compiler codebase, feel free to reach out!
345
+
346
+ # License
347
+
348
+ This project is licensed under the MIT License, as described in `LICENSE.md`
@@ -0,0 +1,11 @@
1
+ import { PatchDetail } from "../patch/patch-detail";
2
+ import { InstallerOptions } from "../options";
3
+ interface CheckResult {
4
+ [moduleName: string]: PatchDetail | undefined;
5
+ }
6
+ /**
7
+ * Check if files can be patched
8
+ */
9
+ export declare function check(moduleName?: string | string[], opts?: Partial<InstallerOptions>): CheckResult;
10
+ export declare function check(moduleNames?: string[], opts?: Partial<InstallerOptions>): CheckResult;
11
+ export {};