@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
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getHelpMenu = getHelpMenu;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const strip_ansi_1 = __importDefault(require("strip-ansi"));
9
+ const commands_1 = require("./commands");
10
+ const options_1 = require("./options");
11
+ /* ****************************************************************************************************************** */
12
+ // region: Config
13
+ /* ****************************************************************************************************************** */
14
+ const LINE_INDENT = '\r\n\t';
15
+ const COL_WIDTH = 45;
16
+ // endregion
17
+ /* ****************************************************************************************************************** */
18
+ // region: Utils
19
+ /* ****************************************************************************************************************** */
20
+ function getHelpMenu() {
21
+ return LINE_INDENT + chalk_1.default.bold.blue('ts-patch [command] ') + chalk_1.default.blue('<options>') + '\r\n' + LINE_INDENT +
22
+ // Commands
23
+ Object
24
+ .entries(commands_1.cliCommandsConfig)
25
+ .map(([cmd, { short, caption, paramCaption }]) => formatLine([cmd, short], caption, paramCaption))
26
+ .join(LINE_INDENT) +
27
+ // Options
28
+ '\r\n' + LINE_INDENT + chalk_1.default.bold('Options') + LINE_INDENT +
29
+ Object
30
+ .entries(options_1.cliOptionsConfig)
31
+ .map(([long, { short, inverse, caption, paramCaption }]) => formatLine([
32
+ short && `${chalk_1.default.cyanBright('-' + short)}`,
33
+ long && `${chalk_1.default.cyanBright(`${inverse ? '--no-' : '--'}${long}`)}`
34
+ ], caption, paramCaption))
35
+ .join(LINE_INDENT);
36
+ function formatLine(left, caption, paramCaption = '') {
37
+ const leftCol = left.filter(Boolean).join(chalk_1.default.blue(', ')) + ' ' + chalk_1.default.yellow(paramCaption);
38
+ const dots = chalk_1.default.grey('.'.repeat(COL_WIDTH - (0, strip_ansi_1.default)(leftCol).length));
39
+ return `${leftCol} ${dots} ${caption}`;
40
+ }
41
+ }
42
+ // endregion
43
+ //# sourceMappingURL=help-menu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"help-menu.js","sourceRoot":"","sources":["../../../projects/core/src/cli/help-menu.ts"],"names":[],"mappings":";;;;;AAoBA,kCAyBC;AA7CD,kDAA0B;AAC1B,4DAAmC;AACnC,yCAA+C;AAC/C,uCAA6C;AAG7C,wHAAwH;AACxH,iBAAiB;AACjB,wHAAwH;AAExH,MAAM,WAAW,GAAG,QAAQ,CAAC;AAC7B,MAAM,SAAS,GAAG,EAAE,CAAC;AAErB,YAAY;AAGZ,wHAAwH;AACxH,gBAAgB;AAChB,wHAAwH;AAExH,SAAgB,WAAW;IACzB,OAAO,WAAW,GAAG,eAAK,CAAC,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,GAAG,eAAK,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,MAAM,GAAG,WAAW;QAE1G,WAAW;QACX,MAAM;aACH,OAAO,CAAC,4BAAiB,CAAC;aAC1B,GAAG,CAAC,CAAC,CAAE,GAAG,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,CAAE,EAAE,EAAE,CAAC,UAAU,CAAC,CAAE,GAAG,EAAE,KAAK,CAAE,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;aACrG,IAAI,CAAC,WAAW,CAAC;QAEpB,UAAU;QACV,MAAM,GAAG,WAAW,GAAG,eAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,WAAW;QAC1D,MAAM;aACH,OAAO,CAAC,0BAAgB,CAAC;aACzB,GAAG,CAAC,CAAC,CAAE,IAAI,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,CAAE,EAAE,EAAE,CAAC,UAAU,CAAC;YACvE,KAAK,IAAI,GAAG,eAAK,CAAC,UAAU,CAAC,GAAG,GAAG,KAAK,CAAC,EAAE;YAC3C,IAAI,IAAI,GAAG,eAAK,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,EAAE,CAAC,EAAE;SACpE,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;aACzB,IAAI,CAAC,WAAW,CAAC,CAAC;IAEvB,SAAS,UAAU,CAAC,IAA4B,EAAE,OAAe,EAAE,eAAuB,EAAE;QAC1F,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,eAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,GAAG,GAAG,eAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;QAC/F,MAAM,IAAI,GAAG,eAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,GAAG,IAAA,oBAAS,EAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;QAE3E,OAAO,GAAG,OAAO,IAAI,IAAI,IAAI,OAAO,EAAE,CAAC;IACzC,CAAC;AACH,CAAC;AAED,YAAY"}
@@ -0,0 +1,14 @@
1
+ import minimist from 'minimist';
2
+ import type { CliConfig } from './cli';
3
+ import { InstallerOptions } from "../options";
4
+ export interface CliOptions {
5
+ silent: boolean;
6
+ global: boolean;
7
+ verbose: boolean;
8
+ dir: string;
9
+ color: boolean;
10
+ }
11
+ /** @internal */
12
+ export declare const cliOptionsConfig: CliConfig;
13
+ export declare function getCliOptions(args: minimist.ParsedArgs): CliOptions;
14
+ export declare function getInstallerOptionsFromCliOptions(cliOptions: CliOptions): InstallerOptions;
package/cli/options.js ADDED
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.cliOptionsConfig = void 0;
4
+ exports.getCliOptions = getCliOptions;
5
+ exports.getInstallerOptionsFromCliOptions = getInstallerOptionsFromCliOptions;
6
+ const system_1 = require("../system");
7
+ const options_1 = require("../options");
8
+ const utils_1 = require("../utils");
9
+ // endregion
10
+ /* ****************************************************************************************************************** */
11
+ // region: Config
12
+ /* ****************************************************************************************************************** */
13
+ /** @internal */
14
+ exports.cliOptionsConfig = {
15
+ silent: { short: 's', caption: 'Run silently' },
16
+ global: { short: 'g', caption: 'Target global TypeScript installation' },
17
+ verbose: { short: 'v', caption: 'Chat it up' },
18
+ cache: { inverse: true, caption: 'Skip cache' },
19
+ dir: {
20
+ short: 'd',
21
+ paramCaption: '<dir>',
22
+ caption: 'TypeScript directory or directory to resolve typescript package from'
23
+ },
24
+ color: { inverse: true, caption: 'Strip ansi colours from output' }
25
+ };
26
+ // endregion
27
+ /* ****************************************************************************************************************** */
28
+ // region: Utils
29
+ /* ****************************************************************************************************************** */
30
+ function getCliOptions(args) {
31
+ let res = {};
32
+ for (const [key, { short }] of Object.entries(exports.cliOptionsConfig)) {
33
+ if (args.hasOwnProperty(key) || (short && args.hasOwnProperty(short))) {
34
+ res[key] = args.hasOwnProperty(key) ? args[key] : args[short];
35
+ }
36
+ }
37
+ return res;
38
+ }
39
+ function getInstallerOptionsFromCliOptions(cliOptions) {
40
+ let partialOptions = {};
41
+ /* Dir option */
42
+ if (cliOptions.global && cliOptions.dir)
43
+ throw new system_1.OptionsError(`Cannot specify both --global and --dir`);
44
+ if ('dir' in cliOptions)
45
+ partialOptions.dir = cliOptions.dir;
46
+ if ('global' in cliOptions)
47
+ partialOptions.dir = (0, utils_1.getGlobalTsDir)();
48
+ /* LogLevel option */
49
+ if (cliOptions.silent && cliOptions.verbose)
50
+ throw new system_1.OptionsError(`Cannot specify both --silent and --verbose`);
51
+ if (cliOptions.silent) {
52
+ partialOptions.logLevel = system_1.LogLevel.system;
53
+ partialOptions.silent = true;
54
+ }
55
+ else if (cliOptions.verbose)
56
+ partialOptions.logLevel = system_1.LogLevel.verbose;
57
+ /* Color option */
58
+ if (cliOptions.color)
59
+ partialOptions.useColor = cliOptions.color;
60
+ return (0, options_1.getInstallerOptions)(partialOptions);
61
+ }
62
+ // endregion
63
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../../../projects/core/src/cli/options.ts"],"names":[],"mappings":";;;AAgDA,sCAUC;AAED,8EAoBC;AA9ED,sCAAmD;AACnD,wCAAmE;AACnE,oCAA0C;AAe1C,YAAY;AAGZ,wHAAwH;AACxH,iBAAiB;AACjB,wHAAwH;AAExH,gBAAgB;AACH,QAAA,gBAAgB,GAAc;IACzC,MAAM,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,cAAc,EAAE;IAC/C,MAAM,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,uCAAuC,EAAE;IACxE,OAAO,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,YAAY,EAAE;IAC9C,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE;IAC/C,GAAG,EAAE;QACH,KAAK,EAAE,GAAG;QACV,YAAY,EAAE,OAAO;QACrB,OAAO,EAAE,sEAAsE;KAChF;IACD,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,gCAAgC,EAAE;CACpE,CAAC;AAGF,YAAY;AAGZ,wHAAwH;AACxH,gBAAgB;AAChB,wHAAwH;AAExH,SAAgB,aAAa,CAAC,IAAyB;IACrD,IAAI,GAAG,GAA2B,EAAE,CAAC;IAErC,KAAK,MAAM,CAAE,GAAG,EAAE,EAAE,KAAK,EAAE,CAAE,IAAI,MAAM,CAAC,OAAO,CAAC,wBAAgB,CAAC,EAAE,CAAC;QAClE,IAAI,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,C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"
4
+ }
@@ -0,0 +1,19 @@
1
+ const indexPath = '../';
2
+ const path = require('path');
3
+ const { getLiveModule } = require(indexPath);
4
+ const { runInThisContext } = require("vm");
5
+
6
+
7
+ /* ****************************************************************************************************************** *
8
+ * Entry
9
+ * ****************************************************************************************************************** */
10
+
11
+ const { js, tsModule } = getLiveModule('tsc.js');
12
+
13
+ const script = runInThisContext(`
14
+ (function (exports, require, module, __filename, __dirname) {
15
+ ${js}
16
+ });
17
+ `);
18
+
19
+ script.call(exports, exports, require, module, tsModule.modulePath, path.dirname(tsModule.modulePath));
@@ -0,0 +1,19 @@
1
+ const indexPath = '../';
2
+ const path = require('path');
3
+ const { getLiveModule } = require(indexPath);
4
+ const { runInThisContext } = require("vm");
5
+
6
+
7
+ /* ****************************************************************************************************************** *
8
+ * Entry
9
+ * ****************************************************************************************************************** */
10
+
11
+ const { js, tsModule } = getLiveModule('tsserver.js');
12
+
13
+ const script = runInThisContext(`
14
+ (function (exports, require, module, __filename, __dirname) {
15
+ ${js}
16
+ });
17
+ `);
18
+
19
+ script.call(exports, exports, require, module, tsModule.modulePath, path.dirname(tsModule.modulePath));
@@ -0,0 +1,19 @@
1
+ const indexPath = '../';
2
+ const path = require('path');
3
+ const { getLiveModule } = require(indexPath);
4
+ const { runInThisContext } = require("vm");
5
+
6
+
7
+ /* ****************************************************************************************************************** *
8
+ * Entry
9
+ * ****************************************************************************************************************** */
10
+
11
+ const { js, tsModule } = getLiveModule('tsserverlibrary.js');
12
+
13
+ const script = runInThisContext(`
14
+ (function (exports, require, module, __filename, __dirname) {
15
+ ${js}
16
+ });
17
+ `);
18
+
19
+ script.call(exports, exports, require, module, tsModule.modulePath, path.dirname(tsModule.modulePath));
@@ -0,0 +1,19 @@
1
+ const indexPath = '../';
2
+ const path = require('path');
3
+ const { getLiveModule } = require(indexPath);
4
+ const { runInThisContext } = require("vm");
5
+
6
+
7
+ /* ****************************************************************************************************************** *
8
+ * Entry
9
+ * ****************************************************************************************************************** */
10
+
11
+ const { js, tsModule } = getLiveModule('typescript.js');
12
+
13
+ const script = runInThisContext(`
14
+ (function (exports, require, module, __filename, __dirname) {
15
+ ${js}
16
+ });
17
+ `);
18
+
19
+ script.call(exports, exports, require, module, tsModule.modulePath, path.dirname(tsModule.modulePath));
package/config.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import ts from 'typescript';
2
+ /**
3
+ * Root directory for ts-patch
4
+ */
5
+ export declare const appRoot: string;
6
+ /**
7
+ * Package json for ts-patch
8
+ */
9
+ export declare const tspPackageJSON: any;
10
+ export declare const RESOURCES_PATH: string;
11
+ export declare const defaultNodePrinterOptions: ts.PrinterOptions;
12
+ export declare const defaultInstallLibraries: string[];
13
+ export declare const corePatchName = "<core>";
14
+ export declare const modulePatchFilePath: string;
15
+ export declare const dtsPatchFilePath: string;
16
+ export declare const execTscCmd = "execTsc";
17
+ export declare const cachedFilePatchedPrefix = "patched.";
18
+ export declare const lockFileDir = "locks";
package/config.js ADDED
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.lockFileDir = exports.cachedFilePatchedPrefix = exports.execTscCmd = exports.dtsPatchFilePath = exports.modulePatchFilePath = exports.corePatchName = exports.defaultInstallLibraries = exports.defaultNodePrinterOptions = exports.RESOURCES_PATH = exports.tspPackageJSON = exports.appRoot = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const typescript_1 = __importDefault(require("typescript"));
10
+ /* ****************************************************************************************************************** */
11
+ // region: Library Config
12
+ /* ****************************************************************************************************************** */
13
+ /**
14
+ * Root directory for ts-patch
15
+ */
16
+ // TODO - This should be improved at some point
17
+ exports.appRoot = (() => {
18
+ const moduleDir = __dirname;
19
+ const chkFile = (pkgFile) => (fs_1.default.existsSync(pkgFile) && (require(pkgFile).name === 'ts-patch')) ? path_1.default.dirname(pkgFile) : void 0;
20
+ const res = chkFile(path_1.default.join(moduleDir, 'package.json')) || chkFile(path_1.default.join(moduleDir, '../../../package.json'));
21
+ if (!res)
22
+ throw new Error(`Error getting app root. No valid ts-patch package file found in ` + moduleDir);
23
+ return res;
24
+ })();
25
+ /**
26
+ * Package json for ts-patch
27
+ */
28
+ exports.tspPackageJSON = require(path_1.default.resolve(exports.appRoot, 'package.json'));
29
+ exports.RESOURCES_PATH = path_1.default.join(exports.appRoot, exports.tspPackageJSON.directories.resources);
30
+ exports.defaultNodePrinterOptions = {
31
+ newLine: typescript_1.default.NewLineKind.LineFeed,
32
+ removeComments: false
33
+ };
34
+ // endregion
35
+ /* ****************************************************************************************************************** */
36
+ // region: Patch Config
37
+ /* ****************************************************************************************************************** */
38
+ exports.defaultInstallLibraries = ['tsc.js', 'typescript.js', '_tsc.js'];
39
+ exports.corePatchName = `<core>`;
40
+ exports.modulePatchFilePath = path_1.default.resolve(exports.appRoot, exports.tspPackageJSON.directories.resources, 'module-patch.js');
41
+ exports.dtsPatchFilePath = path_1.default.resolve(exports.appRoot, exports.tspPackageJSON.directories.resources, 'module-patch.d.ts');
42
+ exports.execTscCmd = 'execTsc';
43
+ // endregion
44
+ /* ****************************************************************************************************************** */
45
+ // region: Cache Config
46
+ /* ****************************************************************************************************************** */
47
+ exports.cachedFilePatchedPrefix = 'patched.';
48
+ exports.lockFileDir = 'locks';
49
+ // endregion
50
+ //# sourceMappingURL=config.js.map
package/config.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../projects/core/src/config.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,4CAAoB;AACpB,4DAA4B;AAG5B,wHAAwH;AACxH,yBAAyB;AACzB,wHAAwH;AAExH;;GAEG;AACH,+CAA+C;AAClC,QAAA,OAAO,GAAG,CAAC,GAAG,EAAE;IAC3B,MAAM,SAAS,GAAG,SAAS,CAAC;IAE5B,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O,CAAC,eAAO,EAAE,sBAAc,CAAC,WAAW,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;AAEpG,QAAA,UAAU,GAAG,SAAS,CAAC;AAEpC,YAAY;AAGZ,wHAAwH;AACxH,uBAAuB;AACvB,wHAAwH;AAE3G,QAAA,uBAAuB,GAAG,UAAU,CAAC;AACrC,QAAA,WAAW,GAAG,OAAO,CAAC;AAEnC,YAAY"}
package/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { InstallerOptions, getInstallerOptions } from './options';
2
+ export { install, uninstall, patch, check } from './actions';
3
+ export { getLiveModule } from './module';
4
+ export * from './plugin-types';
package/index.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.getLiveModule = exports.check = exports.patch = exports.uninstall = exports.install = exports.getInstallerOptions = exports.InstallerOptions = void 0;
18
+ var options_1 = require("./options");
19
+ Object.defineProperty(exports, "InstallerOptions", { enumerable: true, get: function () { return options_1.InstallerOptions; } });
20
+ Object.defineProperty(exports, "getInstallerOptions", { enumerable: true, get: function () { return options_1.getInstallerOptions; } });
21
+ var actions_1 = require("./actions");
22
+ Object.defineProperty(exports, "install", { enumerable: true, get: function () { return actions_1.install; } });
23
+ Object.defineProperty(exports, "uninstall", { enumerable: true, get: function () { return actions_1.uninstall; } });
24
+ Object.defineProperty(exports, "patch", { enumerable: true, get: function () { return actions_1.patch; } });
25
+ Object.defineProperty(exports, "check", { enumerable: true, get: function () { return actions_1.check; } });
26
+ var module_1 = require("./module");
27
+ Object.defineProperty(exports, "getLiveModule", { enumerable: true, get: function () { return module_1.getLiveModule; } });
28
+ __exportStar(require("./plugin-types"), exports);
29
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../projects/core/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,qCAAkE;AAAzD,2GAAA,gBAAgB,OAAA;AAAE,8GAAA,mBAAmB,OAAA;AAC9C,qCAA4D;AAAnD,kGAAA,OAAO,OAAA;AAAE,oGAAA,SAAS,OAAA;AAAE,gGAAA,KAAK,OAAA;AAAE,gGAAA,KAAK,OAAA;AACzC,mCAAwC;AAA/B,uGAAA,aAAa,OAAA;AACtB,iDAA8B"}
@@ -0,0 +1,5 @@
1
+ import { TsModule } from './ts-module';
2
+ export declare function getLiveModule(moduleName: TsModule.Name): {
3
+ js: string;
4
+ tsModule: TsModule;
5
+ };
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getLiveModule = getLiveModule;
7
+ const path_1 = __importDefault(require("path"));
8
+ const ts_module_1 = require("./ts-module");
9
+ const ts_package_1 = require("../ts-package");
10
+ const get_patched_source_1 = require("../patch/get-patched-source");
11
+ /* ****************************************************************************************************************** */
12
+ // region: Utils
13
+ /* ****************************************************************************************************************** */
14
+ function getLiveModule(moduleName) {
15
+ const skipCache = process.env.TSP_SKIP_CACHE === 'true';
16
+ const tsPath = process.env.TSP_COMPILER_TS_PATH ? path_1.default.resolve(process.env.TSP_COMPILER_TS_PATH) : require.resolve('typescript');
17
+ /* Open the TypeScript module */
18
+ const tsPackage = (0, ts_package_1.getTsPackage)(tsPath);
19
+ const tsModule = (0, ts_module_1.getTsModule)(tsPackage, moduleName, { skipCache });
20
+ /* Get patched version */
21
+ const { js } = (0, get_patched_source_1.getPatchedSource)(tsModule, { skipCache, skipDts: true });
22
+ return { js, tsModule };
23
+ }
24
+ // endregion
25
+ //# sourceMappingURL=get-live-module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-live-module.js","sourceRoot":"","sources":["../../../projects/core/src/module/get-live-module.ts"],"names":[],"mappings":";;;;;AAUA,sCAYC;AAtBD,gDAAwB;AACxB,2CAAoD;AACpD,8CAA6C;AAC7C,oEAA+D;AAG/D,wHAAwH;AACxH,gBAAgB;AAChB,wHAAwH;AAExH,SAAgB,aAAa,CAAC,UAAyB;IACrD,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,KAAK,MAAM,CAAC;IACxD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC,cAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAEjI,gCAAgC;IAChC,MAAM,SAAS,GAAG,IAAA,yBAAY,EAAC,MAAM,CAAC,CAAC;IACvC,MAAM,QAAQ,GAAG,IAAA,uBAAW,EAAC,SAAS,EAAE,UAAU,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;IAEnE,yBAAyB;IACzB,MAAM,EAAE,EAAE,EAAE,GAAG,IAAA,qCAAgB,EAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAExE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC;AAC1B,CAAC;AAED,YAAY"}
@@ -0,0 +1,4 @@
1
+ export * from './ts-module';
2
+ export * from './module-source';
3
+ export * from './module-file';
4
+ export * from './get-live-module';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./ts-module"), exports);
18
+ __exportStar(require("./module-source"), exports);
19
+ __exportStar(require("./module-file"), exports);
20
+ __exportStar(require("./get-live-module"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../projects/core/src/module/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,kDAAgC;AAChC,gDAA8B;AAC9B,oDAAkC"}
@@ -0,0 +1,9 @@
1
+ import { PatchDetail } from '../patch/patch-detail';
2
+ export interface ModuleFile {
3
+ moduleName: string;
4
+ patchDetail?: PatchDetail;
5
+ filePath: string;
6
+ get content(): string;
7
+ getHash(): string;
8
+ }
9
+ export declare function getModuleFile(filePath: string, loadFullContent?: boolean): ModuleFile;
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getModuleFile = getModuleFile;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const patch_detail_1 = require("../patch/patch-detail");
9
+ const path_1 = __importDefault(require("path"));
10
+ const utils_1 = require("../utils");
11
+ /* ****************************************************************************************************************** */
12
+ // region: Config
13
+ /* ****************************************************************************************************************** */
14
+ const SHORT_CHUNK_SIZE = 1024;
15
+ const LONG_CHUNK_SIZE = 64536;
16
+ // endregion
17
+ /* ****************************************************************************************************************** */
18
+ // region: Helpers
19
+ /* ****************************************************************************************************************** */
20
+ function readFile(filePath, headersOnly) {
21
+ return (0, utils_1.withFileLock)(filePath, () => {
22
+ let CHUNK_SIZE = headersOnly ? SHORT_CHUNK_SIZE : LONG_CHUNK_SIZE;
23
+ let result = '';
24
+ let doneReadingHeaders = false;
25
+ let bytesRead;
26
+ let buffer = Buffer.alloc(CHUNK_SIZE);
27
+ const headerLines = [];
28
+ let isLastHeaderIncomplete = false;
29
+ const fd = fs_1.default.openSync(filePath, 'r');
30
+ try {
31
+ readFileLoop: while ((bytesRead = fs_1.default.readSync(fd, buffer, 0, CHUNK_SIZE, null)) > 0) {
32
+ const chunkString = buffer.toString('utf-8', 0, bytesRead);
33
+ /* Handle Header */
34
+ if (!doneReadingHeaders) {
35
+ const lines = chunkString.split('\n');
36
+ lineLoop: for (let i = 0; i < lines.length; i++) {
37
+ const line = lines[i];
38
+ if (i === 0 && isLastHeaderIncomplete) {
39
+ headerLines[headerLines.length - 1] += line;
40
+ }
41
+ else {
42
+ if (line.startsWith('///')) {
43
+ headerLines.push(line);
44
+ }
45
+ else {
46
+ doneReadingHeaders = true;
47
+ if (!headersOnly) {
48
+ result += lines.slice(i).join('\n');
49
+ CHUNK_SIZE = LONG_CHUNK_SIZE;
50
+ buffer = Buffer.alloc(CHUNK_SIZE);
51
+ break lineLoop;
52
+ }
53
+ else {
54
+ break readFileLoop;
55
+ }
56
+ }
57
+ }
58
+ }
59
+ if (!doneReadingHeaders)
60
+ isLastHeaderIncomplete = !chunkString.endsWith('\n');
61
+ }
62
+ else {
63
+ /* Handle content */
64
+ result += chunkString;
65
+ }
66
+ }
67
+ return { headerLines, content: headersOnly ? undefined : result };
68
+ }
69
+ finally {
70
+ fs_1.default.closeSync(fd);
71
+ }
72
+ });
73
+ }
74
+ // endregion
75
+ /* ****************************************************************************************************************** */
76
+ // region: Utils
77
+ /* ****************************************************************************************************************** */
78
+ function getModuleFile(filePath, loadFullContent) {
79
+ let { headerLines, content } = readFile(filePath, !loadFullContent);
80
+ /* Get PatchDetail */
81
+ const patchDetail = patch_detail_1.PatchDetail.fromHeader(headerLines);
82
+ return {
83
+ moduleName: path_1.default.basename(filePath),
84
+ filePath,
85
+ patchDetail,
86
+ get content() {
87
+ if (content == null)
88
+ content = readFile(this.filePath, false).content;
89
+ return content;
90
+ },
91
+ getHash() {
92
+ return (0, utils_1.getHash)(this.content);
93
+ }
94
+ };
95
+ }
96
+ // endregion
97
+ //# sourceMappingURL=module-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-file.js","sourceRoot":"","sources":["../../../projects/core/src/module/module-file.ts"],"names":[],"mappings":";;;;;AAoGA,sCAkBC;AAtHD,4CAAoB;AACpB,wDAAoD;AACpD,gDAAwB;AACxB,oCAAiD;AAGjD,wHAAwH;AACxH,iBAAiB;AACjB,wHAAwH;AAExH,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAC9B,MAAM,eAAe,GAAG,KAAM,CAAC;AAkB/B,YAAY;AAGZ,wHAAwH;AACxH,kBAAkB;AAClB,wHAAwH;AAExH,SAAS,QAAQ,CAAC,QAAgB,EAAE,WAAqB;IACvD,OAAO,IAAA,oBAAY,EAAC,QAAQ,EAAE,GAAG,EAAE;QACjC,IAAI,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,eAAe,CAAC;QAClE,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,IAAI,kBAAkB,GAAG,KAAK,CAAC;QAC/B,IAAI,SAAS,CAAC;QACd,IAAI,MAAM,GAAG,MA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AC,CAAC;QAC/B,CAAC;KACF,CAAC;AACJ,CAAC;AAED,YAAY"}
@@ -0,0 +1,15 @@
1
+ import { SourceSection } from './source-section';
2
+ import { TsModule } from './ts-module';
3
+ export interface ModuleSource {
4
+ fileHeader: SourceSection;
5
+ bodyHeader?: SourceSection;
6
+ body: SourceSection[];
7
+ fileFooter?: SourceSection;
8
+ usesTsNamespace: boolean;
9
+ getSections(): [sectionName: SourceSection['sectionName'], section: SourceSection | undefined][];
10
+ bodyWrapper?: {
11
+ start: string;
12
+ end: string;
13
+ };
14
+ }
15
+ export declare function getModuleSource(tsModule: TsModule): ModuleSource;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getModuleSource = getModuleSource;
4
+ const source_section_1 = require("./source-section");
5
+ const module_slice_1 = require("../slice/module-slice");
6
+ // endregion
7
+ /* ****************************************************************************************************************** */
8
+ // region: Utils
9
+ /* ****************************************************************************************************************** */
10
+ function getModuleSource(tsModule) {
11
+ const moduleFile = tsModule.getUnpatchedModuleFile();
12
+ const { firstSourceFileStart, fileEnd, wrapperPos, bodyPos, sourceFileStarts, bodyWrapper } = (0, module_slice_1.sliceModule)(moduleFile, tsModule.package.version);
13
+ const fileHeaderEnd = wrapperPos?.start ?? firstSourceFileStart;
14
+ return {
15
+ fileHeader: (0, source_section_1.createSourceSection)(moduleFile, 'file-header', 0, fileHeaderEnd),
16
+ bodyHeader: wrapperPos && (0, source_section_1.createSourceSection)(moduleFile, 'body-header', bodyPos.start, firstSourceFileStart, 2),
17
+ body: sourceFileStarts.map(([srcFileName, startPos], i) => {
18
+ const endPos = sourceFileStarts[i + 1]?.[1] ?? bodyPos?.end ?? fileEnd;
19
+ return (0, source_section_1.createSourceSection)(moduleFile, 'body', startPos, endPos, wrapperPos != null ? 2 : 0, srcFileName);
20
+ }),
21
+ fileFooter: wrapperPos && (0, source_section_1.createSourceSection)(moduleFile, 'file-footer', wrapperPos.end, fileEnd),
22
+ usesTsNamespace: wrapperPos != null,
23
+ getSections() {
24
+ return [
25
+ ['file-header', this.fileHeader],
26
+ ['body-header', this.bodyHeader],
27
+ ...this.body.map((section, i) => [`body`, section]),
28
+ ['file-footer', this.fileFooter],
29
+ ];
30
+ },
31
+ bodyWrapper,
32
+ };
33
+ }
34
+ // endregion
35
+ //# sourceMappingURL=module-source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-source.js","sourceRoot":"","sources":["../../../projects/core/src/module/module-source.ts"],"names":[],"mappings":";;AA6BA,0CA2BC;AAxDD,qDAAsE;AAEtE,wDAAoD;AAoBpD,YAAY;AAGZ,wHAAwH;AACxH,gBAAgB;AAChB,wHAAwH;AAExH,SAAgB,eAAe,CAAC,QAAkB;IAChD,MAAM,UAAU,GAAG,QAAQ,CAAC,sBAAsB,EAAE,CAAC;IAErD,MAAM,EAAE,oBAAoB,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,GACzF,IAAA,0BAAW,EAAC,UAAU,EAAE,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpD,MAAM,aAAa,GAAG,UAAU,EAAE,KAAK,IAAI,oBAAoB,CAAC;IAEhE,OAAO;QACL,UAAU,EAAE,IAAA,oCAAmB,EAAC,UAAU,EAAE,aAAa,EAAE,CAAC,EAAE,aAAa,CAAC;QAC5E,UAAU,EAAE,UAAU,IAAI,IAAA,oCAAmB,EAAC,UAAU,EAAE,aAAa,EAAE,OAAO,CAAC,KAAK,EAAE,oBAAoB,EAAE,CAAC,CAAC;QAChH,IAAI,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAE,WAAW,EAAE,QAAQ,CAAE,EAAE,CAAC,EAAE,EAAE;YAC1D,MAAM,MAAM,GAAG,gBAAgB,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,OAAO,EAAE,GAAG,IAAI,OAAO,CAAC;YACvE,OAAO,IAAA,oCAAmB,EAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA,CAAC,EAAE,WAAW,CAAC,CAAC;QAC3G,CAAC,CAAC;QACF,UAAU,EAAE,UAAU,IAAI,IAAA,oCAAmB,EAAC,UAAU,EAAE,aAAa,EAAE,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC;QACjG,eAAe,EAAE,UAAU,IAAI,IAAI;QACnC,WAAW;YACT,OAAO;gBACL,CAAE,aAAa,EAAE,IAAI,CAAC,UAAU,CAAE;gBAClC,CAAE,aAAa,EAAE,IAAI,CAAC,UAAU,CAAE;gBAClC,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC,CAAE,MAAM,EAAE,OAAO,CAAqD,CAAC;gBACxG,CAAE,aAAa,EAAE,IAAI,CAAC,UAAU,CAAE;aACnC,CAAC;QACJ,CAAC;QACD,WAAW;KACZ,CAAA;AACH,CAAC;AAED,YAAY"}
@@ -0,0 +1,20 @@
1
+ import ts from 'typescript';
2
+ import { ModuleFile } from './module-file';
3
+ export interface SourceSection {
4
+ readonly sectionName: 'file-header' | 'body-header' | 'body' | 'file-footer';
5
+ readonly srcFileName?: string;
6
+ readonly pos: {
7
+ start: number;
8
+ end: number;
9
+ };
10
+ indentLevel: number;
11
+ hasTransformed?: boolean;
12
+ hasUpdatedSourceText?: boolean;
13
+ get sourceText(): string;
14
+ updateSourceText(newText: string): void;
15
+ getSourceFile(): ts.SourceFile;
16
+ getOriginalSourceFile(): ts.SourceFile;
17
+ transform(transformers: ts.TransformerFactory<ts.SourceFile>[]): void;
18
+ print(printer?: ts.Printer): string;
19
+ }
20
+ export declare function createSourceSection(moduleFile: ModuleFile, sectionName: SourceSection['sectionName'], startPos: number, endPos: number, indentLevel?: number, srcFileName?: string): SourceSection;