ttsc 0.0.5 → 0.2.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/lib/PluginCreator.d.ts +67 -67
- package/lib/PluginCreator.js +190 -190
- package/lib/cancelationToken.js +2 -2
- package/lib/loadTypescript.d.ts +7 -7
- package/lib/loadTypescript.js +56 -56
- package/lib/patchCreateProgram.d.ts +21 -21
- package/lib/patchCreateProgram.js +186 -175
- package/lib/tsc.d.ts +1 -1
- package/lib/tsc.js +24 -24
- package/lib/tsserver.js +2 -2
- package/lib/tsserverlibrary.d.ts +3 -3
- package/lib/tsserverlibrary.js +4 -4
- package/lib/typescript.d.ts +3 -3
- package/lib/typescript.js +5 -4
- package/lib/typescriptServices.d.ts +3 -3
- package/lib/typescriptServices.js +4 -4
- package/lib/typingsInstaller.js +2 -2
- package/lib/watchGuard.js +2 -2
- package/package.json +1 -1
package/lib/PluginCreator.d.ts
CHANGED
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
import * as ts from 'typescript';
|
|
2
|
-
export interface PluginConfig {
|
|
3
|
-
/**
|
|
4
|
-
* Language Server TypeScript Plugin name
|
|
5
|
-
*/
|
|
6
|
-
name?: string;
|
|
7
|
-
/**
|
|
8
|
-
* Path to transformer or transformer module name
|
|
9
|
-
*/
|
|
10
|
-
transform?: string;
|
|
11
|
-
/**
|
|
12
|
-
* The optional name of the exported transform plugin in the transform module.
|
|
13
|
-
*/
|
|
14
|
-
import?: string;
|
|
15
|
-
/**
|
|
16
|
-
* Plugin entry point format type, default is program
|
|
17
|
-
*/
|
|
18
|
-
type?: 'ls' | 'program' | 'config' | 'checker' | 'raw' | 'compilerOptions';
|
|
19
|
-
/**
|
|
20
|
-
* Should transformer applied after all ones
|
|
21
|
-
*/
|
|
22
|
-
after?: boolean;
|
|
23
|
-
/**
|
|
24
|
-
* Should transformer applied for d.ts files, supports from TS2.9
|
|
25
|
-
*/
|
|
26
|
-
afterDeclarations?: boolean;
|
|
27
|
-
}
|
|
28
|
-
export interface TransformerBasePlugin {
|
|
29
|
-
before?: ts.TransformerFactory<ts.SourceFile>;
|
|
30
|
-
after?: ts.TransformerFactory<ts.SourceFile>;
|
|
31
|
-
afterDeclarations?: ts.TransformerFactory<ts.SourceFile | ts.Bundle>;
|
|
32
|
-
}
|
|
33
|
-
export type TransformerList = Required<ts.CustomTransformers>;
|
|
34
|
-
export type TransformerPlugin = TransformerBasePlugin | ts.TransformerFactory<ts.SourceFile>;
|
|
35
|
-
export type LSPattern = (ls: ts.LanguageService, config: {}) => TransformerPlugin;
|
|
36
|
-
export type ProgramPattern = (program: ts.Program, config: {}, helpers?: {
|
|
37
|
-
ts: typeof ts;
|
|
38
|
-
addDiagnostic: (diag: ts.Diagnostic) => void;
|
|
39
|
-
}) => TransformerPlugin;
|
|
40
|
-
export type CompilerOptionsPattern = (compilerOpts: ts.CompilerOptions, config: {}) => TransformerPlugin;
|
|
41
|
-
export type ConfigPattern = (config: {}) => TransformerPlugin;
|
|
42
|
-
export type TypeCheckerPattern = (checker: ts.TypeChecker, config: {}) => TransformerPlugin;
|
|
43
|
-
export type RawPattern = (context: ts.TransformationContext, program: ts.Program, config: {}) => ts.Transformer<ts.SourceFile>;
|
|
44
|
-
export type PluginFactory = LSPattern | ProgramPattern | ConfigPattern | CompilerOptionsPattern | TypeCheckerPattern | RawPattern;
|
|
45
|
-
/**
|
|
46
|
-
* @example
|
|
47
|
-
*
|
|
48
|
-
* new PluginCreator([
|
|
49
|
-
* {transform: '@zerollup/ts-transform-paths', someOption: '123'},
|
|
50
|
-
* {transform: '@zerollup/ts-transform-paths', type: 'ls', someOption: '123'},
|
|
51
|
-
* {transform: '@zerollup/ts-transform-paths', type: 'ls', after: true, someOption: '123'}
|
|
52
|
-
* ]).createTransformers({ program })
|
|
53
|
-
*/
|
|
54
|
-
export declare class PluginCreator {
|
|
55
|
-
private typescript;
|
|
56
|
-
private configs;
|
|
57
|
-
private resolveBaseDir;
|
|
58
|
-
constructor(typescript: typeof ts, configs: PluginConfig[], resolveBaseDir?: string);
|
|
59
|
-
mergeTransformers(into: TransformerList, source: ts.CustomTransformers | TransformerBasePlugin): this;
|
|
60
|
-
createTransformers(params: {
|
|
61
|
-
program: ts.Program;
|
|
62
|
-
} | {
|
|
63
|
-
ls: ts.LanguageService;
|
|
64
|
-
}, customTransformers?: ts.CustomTransformers): Required<ts.CustomTransformers>;
|
|
65
|
-
private resolveFactory;
|
|
66
|
-
private validateConfigs;
|
|
67
|
-
}
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
export interface PluginConfig {
|
|
3
|
+
/**
|
|
4
|
+
* Language Server TypeScript Plugin name
|
|
5
|
+
*/
|
|
6
|
+
name?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Path to transformer or transformer module name
|
|
9
|
+
*/
|
|
10
|
+
transform?: string;
|
|
11
|
+
/**
|
|
12
|
+
* The optional name of the exported transform plugin in the transform module.
|
|
13
|
+
*/
|
|
14
|
+
import?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Plugin entry point format type, default is program
|
|
17
|
+
*/
|
|
18
|
+
type?: 'ls' | 'program' | 'config' | 'checker' | 'raw' | 'compilerOptions';
|
|
19
|
+
/**
|
|
20
|
+
* Should transformer applied after all ones
|
|
21
|
+
*/
|
|
22
|
+
after?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Should transformer applied for d.ts files, supports from TS2.9
|
|
25
|
+
*/
|
|
26
|
+
afterDeclarations?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface TransformerBasePlugin {
|
|
29
|
+
before?: ts.TransformerFactory<ts.SourceFile>;
|
|
30
|
+
after?: ts.TransformerFactory<ts.SourceFile>;
|
|
31
|
+
afterDeclarations?: ts.TransformerFactory<ts.SourceFile | ts.Bundle>;
|
|
32
|
+
}
|
|
33
|
+
export type TransformerList = Required<ts.CustomTransformers>;
|
|
34
|
+
export type TransformerPlugin = TransformerBasePlugin | ts.TransformerFactory<ts.SourceFile>;
|
|
35
|
+
export type LSPattern = (ls: ts.LanguageService, config: {}) => TransformerPlugin;
|
|
36
|
+
export type ProgramPattern = (program: ts.Program, config: {}, helpers?: {
|
|
37
|
+
ts: typeof ts;
|
|
38
|
+
addDiagnostic: (diag: ts.Diagnostic) => void;
|
|
39
|
+
}) => TransformerPlugin;
|
|
40
|
+
export type CompilerOptionsPattern = (compilerOpts: ts.CompilerOptions, config: {}) => TransformerPlugin;
|
|
41
|
+
export type ConfigPattern = (config: {}) => TransformerPlugin;
|
|
42
|
+
export type TypeCheckerPattern = (checker: ts.TypeChecker, config: {}) => TransformerPlugin;
|
|
43
|
+
export type RawPattern = (context: ts.TransformationContext, program: ts.Program, config: {}) => ts.Transformer<ts.SourceFile>;
|
|
44
|
+
export type PluginFactory = LSPattern | ProgramPattern | ConfigPattern | CompilerOptionsPattern | TypeCheckerPattern | RawPattern;
|
|
45
|
+
/**
|
|
46
|
+
* @example
|
|
47
|
+
*
|
|
48
|
+
* new PluginCreator([
|
|
49
|
+
* {transform: '@zerollup/ts-transform-paths', someOption: '123'},
|
|
50
|
+
* {transform: '@zerollup/ts-transform-paths', type: 'ls', someOption: '123'},
|
|
51
|
+
* {transform: '@zerollup/ts-transform-paths', type: 'ls', after: true, someOption: '123'}
|
|
52
|
+
* ]).createTransformers({ program })
|
|
53
|
+
*/
|
|
54
|
+
export declare class PluginCreator {
|
|
55
|
+
private typescript;
|
|
56
|
+
private configs;
|
|
57
|
+
private resolveBaseDir;
|
|
58
|
+
constructor(typescript: typeof ts, configs: PluginConfig[], resolveBaseDir?: string);
|
|
59
|
+
mergeTransformers(into: TransformerList, source: ts.CustomTransformers | TransformerBasePlugin): this;
|
|
60
|
+
createTransformers(params: {
|
|
61
|
+
program: ts.Program;
|
|
62
|
+
} | {
|
|
63
|
+
ls: ts.LanguageService;
|
|
64
|
+
}, customTransformers?: ts.CustomTransformers): Required<ts.CustomTransformers>;
|
|
65
|
+
private resolveFactory;
|
|
66
|
+
private validateConfigs;
|
|
67
|
+
}
|
package/lib/PluginCreator.js
CHANGED
|
@@ -1,190 +1,190 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.PluginCreator = void 0;
|
|
15
|
-
var resolve = require("resolve");
|
|
16
|
-
var util_1 = require("util");
|
|
17
|
-
var patchCreateProgram_1 = require("./patchCreateProgram");
|
|
18
|
-
function createTransformerFromPattern(_a) {
|
|
19
|
-
var typescript = _a.typescript, factory = _a.factory, config = _a.config, program = _a.program, ls = _a.ls;
|
|
20
|
-
var transform = config.transform, after = config.after, afterDeclarations = config.afterDeclarations, name = config.name, type = config.type, cleanConfig = __rest(config, ["transform", "after", "afterDeclarations", "name", "type"]);
|
|
21
|
-
if (!transform)
|
|
22
|
-
throw new Error('Not a valid config entry: "transform" key not found');
|
|
23
|
-
var ret;
|
|
24
|
-
switch (config.type) {
|
|
25
|
-
case 'ls':
|
|
26
|
-
if (!ls)
|
|
27
|
-
throw new Error("Plugin ".concat(transform, " need a LanguageService"));
|
|
28
|
-
ret = factory(ls, cleanConfig);
|
|
29
|
-
break;
|
|
30
|
-
case 'config':
|
|
31
|
-
ret = factory(cleanConfig);
|
|
32
|
-
break;
|
|
33
|
-
case 'compilerOptions':
|
|
34
|
-
ret = factory(program.getCompilerOptions(), cleanConfig);
|
|
35
|
-
break;
|
|
36
|
-
case 'checker':
|
|
37
|
-
ret = factory(program.getTypeChecker(), cleanConfig);
|
|
38
|
-
break;
|
|
39
|
-
case undefined:
|
|
40
|
-
case 'program':
|
|
41
|
-
ret = factory(program, cleanConfig, {
|
|
42
|
-
ts: typescript,
|
|
43
|
-
addDiagnostic: (0, patchCreateProgram_1.addDiagnosticFactory)(program),
|
|
44
|
-
});
|
|
45
|
-
break;
|
|
46
|
-
case 'raw':
|
|
47
|
-
ret = function (ctx) { return factory(ctx, program, cleanConfig); };
|
|
48
|
-
break;
|
|
49
|
-
default:
|
|
50
|
-
return never(config.type);
|
|
51
|
-
}
|
|
52
|
-
if (typeof ret === 'function') {
|
|
53
|
-
if (after)
|
|
54
|
-
return { after: ret };
|
|
55
|
-
else if (afterDeclarations) {
|
|
56
|
-
return { afterDeclarations: ret };
|
|
57
|
-
}
|
|
58
|
-
else
|
|
59
|
-
return { before: ret };
|
|
60
|
-
}
|
|
61
|
-
return ret;
|
|
62
|
-
}
|
|
63
|
-
function never(n) {
|
|
64
|
-
throw new Error('Unexpected type: ' + n);
|
|
65
|
-
}
|
|
66
|
-
var tsNodeIncluded = false;
|
|
67
|
-
// to fix recursion bug, see usage below
|
|
68
|
-
var requireStack = [];
|
|
69
|
-
/**
|
|
70
|
-
* @example
|
|
71
|
-
*
|
|
72
|
-
* new PluginCreator([
|
|
73
|
-
* {transform: '@zerollup/ts-transform-paths', someOption: '123'},
|
|
74
|
-
* {transform: '@zerollup/ts-transform-paths', type: 'ls', someOption: '123'},
|
|
75
|
-
* {transform: '@zerollup/ts-transform-paths', type: 'ls', after: true, someOption: '123'}
|
|
76
|
-
* ]).createTransformers({ program })
|
|
77
|
-
*/
|
|
78
|
-
var PluginCreator = /** @class */ (function () {
|
|
79
|
-
function PluginCreator(typescript, configs, resolveBaseDir) {
|
|
80
|
-
if (resolveBaseDir === void 0) { resolveBaseDir = process.cwd(); }
|
|
81
|
-
this.typescript = typescript;
|
|
82
|
-
this.configs = configs;
|
|
83
|
-
this.resolveBaseDir = resolveBaseDir;
|
|
84
|
-
this.validateConfigs(configs);
|
|
85
|
-
}
|
|
86
|
-
PluginCreator.prototype.mergeTransformers = function (into, source) {
|
|
87
|
-
var _a, _b, _c;
|
|
88
|
-
var slice = function (input) { return (Array.isArray(input) ? input.slice() : [input]); };
|
|
89
|
-
if (source.before) {
|
|
90
|
-
(_a = into.before).push.apply(_a, slice(source.before));
|
|
91
|
-
}
|
|
92
|
-
if (source.after) {
|
|
93
|
-
(_b = into.after).push.apply(_b, slice(source.after));
|
|
94
|
-
}
|
|
95
|
-
if (source.afterDeclarations) {
|
|
96
|
-
(_c = into.afterDeclarations).push.apply(_c, slice(source.afterDeclarations));
|
|
97
|
-
}
|
|
98
|
-
return this;
|
|
99
|
-
};
|
|
100
|
-
PluginCreator.prototype.createTransformers = function (params, customTransformers) {
|
|
101
|
-
var chain = {
|
|
102
|
-
before: [],
|
|
103
|
-
after: [],
|
|
104
|
-
afterDeclarations: [],
|
|
105
|
-
};
|
|
106
|
-
var ls;
|
|
107
|
-
var program;
|
|
108
|
-
if ('ls' in params) {
|
|
109
|
-
ls = params.ls;
|
|
110
|
-
program = ls.getProgram();
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
program = params.program;
|
|
114
|
-
}
|
|
115
|
-
for (var _i = 0, _a = this.configs; _i < _a.length; _i++) {
|
|
116
|
-
var config = _a[_i];
|
|
117
|
-
if (!config.transform) {
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
var factory = this.resolveFactory(config.transform, config.import);
|
|
121
|
-
// if recursion
|
|
122
|
-
if (factory === undefined)
|
|
123
|
-
continue;
|
|
124
|
-
var transformer = createTransformerFromPattern({
|
|
125
|
-
typescript: this.typescript,
|
|
126
|
-
factory: factory,
|
|
127
|
-
config: config,
|
|
128
|
-
program: program,
|
|
129
|
-
ls: ls,
|
|
130
|
-
});
|
|
131
|
-
this.mergeTransformers(chain, transformer);
|
|
132
|
-
}
|
|
133
|
-
// if we're given some custom transformers, they must be chained at the end
|
|
134
|
-
if (customTransformers) {
|
|
135
|
-
this.mergeTransformers(chain, customTransformers);
|
|
136
|
-
}
|
|
137
|
-
return chain;
|
|
138
|
-
};
|
|
139
|
-
PluginCreator.prototype.resolveFactory = function (transform, importKey) {
|
|
140
|
-
if (importKey === void 0) { importKey = 'default'; }
|
|
141
|
-
if (!tsNodeIncluded &&
|
|
142
|
-
transform.match(/\.tsx?$/) &&
|
|
143
|
-
(module.parent.parent === null ||
|
|
144
|
-
module.parent.parent.parent === null ||
|
|
145
|
-
module.parent.parent.parent.id.split(/[\/\\]/).indexOf('ts-node') === -1)) {
|
|
146
|
-
require('ts-node').register({
|
|
147
|
-
transpileOnly: true,
|
|
148
|
-
skipProject: true,
|
|
149
|
-
compilerOptions: {
|
|
150
|
-
target: 'ES2018',
|
|
151
|
-
jsx: 'react',
|
|
152
|
-
esModuleInterop: true,
|
|
153
|
-
module: 'commonjs',
|
|
154
|
-
},
|
|
155
|
-
});
|
|
156
|
-
tsNodeIncluded = true;
|
|
157
|
-
}
|
|
158
|
-
var modulePath = resolve.sync(transform, { basedir: this.resolveBaseDir });
|
|
159
|
-
// in ts-node occurs error cause recursion:
|
|
160
|
-
// ts-node file.ts -> createTransformers -> require transformer.ts
|
|
161
|
-
// -> createTransformers -> require transformer.ts -> ...
|
|
162
|
-
// this happens cause ts-node uses to compile transformers the same config included this transformer
|
|
163
|
-
// so this stack checks that if we already required this file we are in the reqursion
|
|
164
|
-
if (requireStack.indexOf(modulePath) > -1)
|
|
165
|
-
return;
|
|
166
|
-
requireStack.push(modulePath);
|
|
167
|
-
var commonjsModule = require(modulePath);
|
|
168
|
-
requireStack.pop();
|
|
169
|
-
var factoryModule = typeof commonjsModule === 'function' ? { default: commonjsModule } : commonjsModule;
|
|
170
|
-
var factory = factoryModule[importKey];
|
|
171
|
-
if (!factory) {
|
|
172
|
-
throw new Error("tsconfig.json > plugins: \"".concat(transform, "\" does not have an export \"").concat(importKey, "\": ") +
|
|
173
|
-
(0, util_1.inspect)(factoryModule));
|
|
174
|
-
}
|
|
175
|
-
if (typeof factory !== 'function') {
|
|
176
|
-
throw new Error("tsconfig.json > plugins: \"".concat(transform, "\" export \"").concat(importKey, "\" is not a plugin: \"").concat((0, util_1.inspect)(factory), "\""));
|
|
177
|
-
}
|
|
178
|
-
return factory;
|
|
179
|
-
};
|
|
180
|
-
PluginCreator.prototype.validateConfigs = function (configs) {
|
|
181
|
-
for (var _i = 0, configs_1 = configs; _i < configs_1.length; _i++) {
|
|
182
|
-
var config = configs_1[_i];
|
|
183
|
-
if (!config.name && !config.transform) {
|
|
184
|
-
throw new Error('tsconfig.json plugins error: transform must be present');
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
return PluginCreator;
|
|
189
|
-
}());
|
|
190
|
-
exports.PluginCreator = PluginCreator;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.PluginCreator = void 0;
|
|
15
|
+
var resolve = require("resolve");
|
|
16
|
+
var util_1 = require("util");
|
|
17
|
+
var patchCreateProgram_1 = require("./patchCreateProgram");
|
|
18
|
+
function createTransformerFromPattern(_a) {
|
|
19
|
+
var typescript = _a.typescript, factory = _a.factory, config = _a.config, program = _a.program, ls = _a.ls;
|
|
20
|
+
var transform = config.transform, after = config.after, afterDeclarations = config.afterDeclarations, name = config.name, type = config.type, cleanConfig = __rest(config, ["transform", "after", "afterDeclarations", "name", "type"]);
|
|
21
|
+
if (!transform)
|
|
22
|
+
throw new Error('Not a valid config entry: "transform" key not found');
|
|
23
|
+
var ret;
|
|
24
|
+
switch (config.type) {
|
|
25
|
+
case 'ls':
|
|
26
|
+
if (!ls)
|
|
27
|
+
throw new Error("Plugin ".concat(transform, " need a LanguageService"));
|
|
28
|
+
ret = factory(ls, cleanConfig);
|
|
29
|
+
break;
|
|
30
|
+
case 'config':
|
|
31
|
+
ret = factory(cleanConfig);
|
|
32
|
+
break;
|
|
33
|
+
case 'compilerOptions':
|
|
34
|
+
ret = factory(program.getCompilerOptions(), cleanConfig);
|
|
35
|
+
break;
|
|
36
|
+
case 'checker':
|
|
37
|
+
ret = factory(program.getTypeChecker(), cleanConfig);
|
|
38
|
+
break;
|
|
39
|
+
case undefined:
|
|
40
|
+
case 'program':
|
|
41
|
+
ret = factory(program, cleanConfig, {
|
|
42
|
+
ts: typescript,
|
|
43
|
+
addDiagnostic: (0, patchCreateProgram_1.addDiagnosticFactory)(program),
|
|
44
|
+
});
|
|
45
|
+
break;
|
|
46
|
+
case 'raw':
|
|
47
|
+
ret = function (ctx) { return factory(ctx, program, cleanConfig); };
|
|
48
|
+
break;
|
|
49
|
+
default:
|
|
50
|
+
return never(config.type);
|
|
51
|
+
}
|
|
52
|
+
if (typeof ret === 'function') {
|
|
53
|
+
if (after)
|
|
54
|
+
return { after: ret };
|
|
55
|
+
else if (afterDeclarations) {
|
|
56
|
+
return { afterDeclarations: ret };
|
|
57
|
+
}
|
|
58
|
+
else
|
|
59
|
+
return { before: ret };
|
|
60
|
+
}
|
|
61
|
+
return ret;
|
|
62
|
+
}
|
|
63
|
+
function never(n) {
|
|
64
|
+
throw new Error('Unexpected type: ' + n);
|
|
65
|
+
}
|
|
66
|
+
var tsNodeIncluded = false;
|
|
67
|
+
// to fix recursion bug, see usage below
|
|
68
|
+
var requireStack = [];
|
|
69
|
+
/**
|
|
70
|
+
* @example
|
|
71
|
+
*
|
|
72
|
+
* new PluginCreator([
|
|
73
|
+
* {transform: '@zerollup/ts-transform-paths', someOption: '123'},
|
|
74
|
+
* {transform: '@zerollup/ts-transform-paths', type: 'ls', someOption: '123'},
|
|
75
|
+
* {transform: '@zerollup/ts-transform-paths', type: 'ls', after: true, someOption: '123'}
|
|
76
|
+
* ]).createTransformers({ program })
|
|
77
|
+
*/
|
|
78
|
+
var PluginCreator = /** @class */ (function () {
|
|
79
|
+
function PluginCreator(typescript, configs, resolveBaseDir) {
|
|
80
|
+
if (resolveBaseDir === void 0) { resolveBaseDir = process.cwd(); }
|
|
81
|
+
this.typescript = typescript;
|
|
82
|
+
this.configs = configs;
|
|
83
|
+
this.resolveBaseDir = resolveBaseDir;
|
|
84
|
+
this.validateConfigs(configs);
|
|
85
|
+
}
|
|
86
|
+
PluginCreator.prototype.mergeTransformers = function (into, source) {
|
|
87
|
+
var _a, _b, _c;
|
|
88
|
+
var slice = function (input) { return (Array.isArray(input) ? input.slice() : [input]); };
|
|
89
|
+
if (source.before) {
|
|
90
|
+
(_a = into.before).push.apply(_a, slice(source.before));
|
|
91
|
+
}
|
|
92
|
+
if (source.after) {
|
|
93
|
+
(_b = into.after).push.apply(_b, slice(source.after));
|
|
94
|
+
}
|
|
95
|
+
if (source.afterDeclarations) {
|
|
96
|
+
(_c = into.afterDeclarations).push.apply(_c, slice(source.afterDeclarations));
|
|
97
|
+
}
|
|
98
|
+
return this;
|
|
99
|
+
};
|
|
100
|
+
PluginCreator.prototype.createTransformers = function (params, customTransformers) {
|
|
101
|
+
var chain = {
|
|
102
|
+
before: [],
|
|
103
|
+
after: [],
|
|
104
|
+
afterDeclarations: [],
|
|
105
|
+
};
|
|
106
|
+
var ls;
|
|
107
|
+
var program;
|
|
108
|
+
if ('ls' in params) {
|
|
109
|
+
ls = params.ls;
|
|
110
|
+
program = ls.getProgram();
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
program = params.program;
|
|
114
|
+
}
|
|
115
|
+
for (var _i = 0, _a = this.configs; _i < _a.length; _i++) {
|
|
116
|
+
var config = _a[_i];
|
|
117
|
+
if (!config.transform) {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
var factory = this.resolveFactory(config.transform, config.import);
|
|
121
|
+
// if recursion
|
|
122
|
+
if (factory === undefined)
|
|
123
|
+
continue;
|
|
124
|
+
var transformer = createTransformerFromPattern({
|
|
125
|
+
typescript: this.typescript,
|
|
126
|
+
factory: factory,
|
|
127
|
+
config: config,
|
|
128
|
+
program: program,
|
|
129
|
+
ls: ls,
|
|
130
|
+
});
|
|
131
|
+
this.mergeTransformers(chain, transformer);
|
|
132
|
+
}
|
|
133
|
+
// if we're given some custom transformers, they must be chained at the end
|
|
134
|
+
if (customTransformers) {
|
|
135
|
+
this.mergeTransformers(chain, customTransformers);
|
|
136
|
+
}
|
|
137
|
+
return chain;
|
|
138
|
+
};
|
|
139
|
+
PluginCreator.prototype.resolveFactory = function (transform, importKey) {
|
|
140
|
+
if (importKey === void 0) { importKey = 'default'; }
|
|
141
|
+
if (!tsNodeIncluded &&
|
|
142
|
+
transform.match(/\.tsx?$/) &&
|
|
143
|
+
(module.parent.parent === null ||
|
|
144
|
+
module.parent.parent.parent === null ||
|
|
145
|
+
module.parent.parent.parent.id.split(/[\/\\]/).indexOf('ts-node') === -1)) {
|
|
146
|
+
require('ts-node').register({
|
|
147
|
+
transpileOnly: true,
|
|
148
|
+
skipProject: true,
|
|
149
|
+
compilerOptions: {
|
|
150
|
+
target: 'ES2018',
|
|
151
|
+
jsx: 'react',
|
|
152
|
+
esModuleInterop: true,
|
|
153
|
+
module: 'commonjs',
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
tsNodeIncluded = true;
|
|
157
|
+
}
|
|
158
|
+
var modulePath = resolve.sync(transform, { basedir: this.resolveBaseDir });
|
|
159
|
+
// in ts-node occurs error cause recursion:
|
|
160
|
+
// ts-node file.ts -> createTransformers -> require transformer.ts
|
|
161
|
+
// -> createTransformers -> require transformer.ts -> ...
|
|
162
|
+
// this happens cause ts-node uses to compile transformers the same config included this transformer
|
|
163
|
+
// so this stack checks that if we already required this file we are in the reqursion
|
|
164
|
+
if (requireStack.indexOf(modulePath) > -1)
|
|
165
|
+
return;
|
|
166
|
+
requireStack.push(modulePath);
|
|
167
|
+
var commonjsModule = require(modulePath);
|
|
168
|
+
requireStack.pop();
|
|
169
|
+
var factoryModule = typeof commonjsModule === 'function' ? { default: commonjsModule } : commonjsModule;
|
|
170
|
+
var factory = factoryModule[importKey];
|
|
171
|
+
if (!factory) {
|
|
172
|
+
throw new Error("tsconfig.json > plugins: \"".concat(transform, "\" does not have an export \"").concat(importKey, "\": ") +
|
|
173
|
+
(0, util_1.inspect)(factoryModule));
|
|
174
|
+
}
|
|
175
|
+
if (typeof factory !== 'function') {
|
|
176
|
+
throw new Error("tsconfig.json > plugins: \"".concat(transform, "\" export \"").concat(importKey, "\" is not a plugin: \"").concat((0, util_1.inspect)(factory), "\""));
|
|
177
|
+
}
|
|
178
|
+
return factory;
|
|
179
|
+
};
|
|
180
|
+
PluginCreator.prototype.validateConfigs = function (configs) {
|
|
181
|
+
for (var _i = 0, configs_1 = configs; _i < configs_1.length; _i++) {
|
|
182
|
+
var config = configs_1[_i];
|
|
183
|
+
if (!config.name && !config.transform) {
|
|
184
|
+
throw new Error('tsconfig.json plugins error: transform must be present');
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
return PluginCreator;
|
|
189
|
+
}());
|
|
190
|
+
exports.PluginCreator = PluginCreator;
|
package/lib/cancelationToken.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
module.exports = require('typescript/lib/cancellationToken');
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = require('typescript/lib/cancellationToken');
|
package/lib/loadTypescript.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as TS from 'typescript';
|
|
2
|
-
type ts = typeof TS;
|
|
3
|
-
export declare function loadTypeScript(filename: string, { folder, forceConfigLoad }?: {
|
|
4
|
-
folder?: string;
|
|
5
|
-
forceConfigLoad?: boolean;
|
|
6
|
-
}): ts;
|
|
7
|
-
export {};
|
|
1
|
+
import * as TS from 'typescript';
|
|
2
|
+
type ts = typeof TS;
|
|
3
|
+
export declare function loadTypeScript(filename: string, { folder, forceConfigLoad }?: {
|
|
4
|
+
folder?: string;
|
|
5
|
+
forceConfigLoad?: boolean;
|
|
6
|
+
}): ts;
|
|
7
|
+
export {};
|
package/lib/loadTypescript.js
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.loadTypeScript = void 0;
|
|
15
|
-
var fs_1 = require("fs");
|
|
16
|
-
var resolve_1 = require("resolve");
|
|
17
|
-
var patchCreateProgram_1 = require("./patchCreateProgram");
|
|
18
|
-
var path_1 = require("path");
|
|
19
|
-
var vm_1 = require("vm");
|
|
20
|
-
var Module = require("module");
|
|
21
|
-
function loadTypeScript(filename, _a) {
|
|
22
|
-
var _b;
|
|
23
|
-
var _c = _a === void 0 ? {} : _a, _d = _c.folder, folder = _d === void 0 ? __dirname : _d, _e = _c.forceConfigLoad, forceConfigLoad = _e === void 0 ? false : _e;
|
|
24
|
-
var libFilename = (0, resolve_1.sync)('typescript/lib/' + filename, { basedir: folder });
|
|
25
|
-
if (!require.cache[libFilename]) {
|
|
26
|
-
var temp = TSModuleFactory(libFilename);
|
|
27
|
-
require.cache = __assign(__assign({}, require.cache), (_b = {}, _b[libFilename] = temp, _b));
|
|
28
|
-
}
|
|
29
|
-
var ts = TSModuleFactory(libFilename).exports;
|
|
30
|
-
var _f = ts.versionMajorMinor.split('.'), major = _f[0], minor = _f[1];
|
|
31
|
-
if (+major < 3 && +minor < 7) {
|
|
32
|
-
throw new Error('ttypescript supports typescript from 2.7 version');
|
|
33
|
-
}
|
|
34
|
-
var result = (0, patchCreateProgram_1.patchCreateProgram)(ts, forceConfigLoad);
|
|
35
|
-
if (+major >= 5 && result.args) {
|
|
36
|
-
result.args.this = result.args.exports;
|
|
37
|
-
}
|
|
38
|
-
return result;
|
|
39
|
-
}
|
|
40
|
-
exports.loadTypeScript = loadTypeScript;
|
|
41
|
-
var typeScriptFactoryCache = new Map();
|
|
42
|
-
function TSModuleFactory(filename) {
|
|
43
|
-
var factory = typeScriptFactoryCache.get(filename);
|
|
44
|
-
if (!factory) {
|
|
45
|
-
var code = (0, fs_1.readFileSync)(filename, 'utf8');
|
|
46
|
-
factory = (0, vm_1.runInThisContext)("(function (exports, require, module, __filename, __dirname) {".concat(code, "\n});"), {
|
|
47
|
-
filename: filename,
|
|
48
|
-
lineOffset: 0,
|
|
49
|
-
displayErrors: true,
|
|
50
|
-
});
|
|
51
|
-
typeScriptFactoryCache.set(filename, factory);
|
|
52
|
-
}
|
|
53
|
-
var newModule = new Module(filename, module);
|
|
54
|
-
factory.call(newModule, newModule.exports, require, newModule, filename, (0, path_1.dirname)(filename));
|
|
55
|
-
return newModule;
|
|
56
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.loadTypeScript = void 0;
|
|
15
|
+
var fs_1 = require("fs");
|
|
16
|
+
var resolve_1 = require("resolve");
|
|
17
|
+
var patchCreateProgram_1 = require("./patchCreateProgram");
|
|
18
|
+
var path_1 = require("path");
|
|
19
|
+
var vm_1 = require("vm");
|
|
20
|
+
var Module = require("module");
|
|
21
|
+
function loadTypeScript(filename, _a) {
|
|
22
|
+
var _b;
|
|
23
|
+
var _c = _a === void 0 ? {} : _a, _d = _c.folder, folder = _d === void 0 ? __dirname : _d, _e = _c.forceConfigLoad, forceConfigLoad = _e === void 0 ? false : _e;
|
|
24
|
+
var libFilename = (0, resolve_1.sync)('typescript/lib/' + filename, { basedir: folder });
|
|
25
|
+
if (!require.cache[libFilename]) {
|
|
26
|
+
var temp = TSModuleFactory(libFilename);
|
|
27
|
+
require.cache = __assign(__assign({}, require.cache), (_b = {}, _b[libFilename] = temp, _b));
|
|
28
|
+
}
|
|
29
|
+
var ts = TSModuleFactory(libFilename).exports;
|
|
30
|
+
var _f = ts.versionMajorMinor.split('.'), major = _f[0], minor = _f[1];
|
|
31
|
+
if (+major < 3 && +minor < 7) {
|
|
32
|
+
throw new Error('ttypescript supports typescript from 2.7 version');
|
|
33
|
+
}
|
|
34
|
+
var result = (0, patchCreateProgram_1.patchCreateProgram)(ts, forceConfigLoad);
|
|
35
|
+
if (+major >= 5 && result.args) {
|
|
36
|
+
result.args.this = result.args.exports;
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
exports.loadTypeScript = loadTypeScript;
|
|
41
|
+
var typeScriptFactoryCache = new Map();
|
|
42
|
+
function TSModuleFactory(filename) {
|
|
43
|
+
var factory = typeScriptFactoryCache.get(filename);
|
|
44
|
+
if (!factory) {
|
|
45
|
+
var code = (0, fs_1.readFileSync)(filename, 'utf8');
|
|
46
|
+
factory = (0, vm_1.runInThisContext)("(function (exports, require, module, __filename, __dirname) {".concat(code, "\n});"), {
|
|
47
|
+
filename: filename,
|
|
48
|
+
lineOffset: 0,
|
|
49
|
+
displayErrors: true,
|
|
50
|
+
});
|
|
51
|
+
typeScriptFactoryCache.set(filename, factory);
|
|
52
|
+
}
|
|
53
|
+
var newModule = new Module(filename, module);
|
|
54
|
+
factory.call(newModule, newModule.exports, require, newModule, filename, (0, path_1.dirname)(filename));
|
|
55
|
+
return newModule;
|
|
56
|
+
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import * as ts from 'typescript';
|
|
2
|
-
import { Diagnostic } from 'typescript/lib/tsserverlibrary';
|
|
3
|
-
declare module 'typescript' {
|
|
4
|
-
interface CreateProgramOptions {
|
|
5
|
-
rootNames: ReadonlyArray<string>;
|
|
6
|
-
options: ts.CompilerOptions;
|
|
7
|
-
projectReferences?: ReadonlyArray<ts.ProjectReference>;
|
|
8
|
-
host?: ts.CompilerHost;
|
|
9
|
-
oldProgram?: ts.Program;
|
|
10
|
-
configFileParsingDiagnostics?: ReadonlyArray<ts.Diagnostic>;
|
|
11
|
-
}
|
|
12
|
-
interface ProjectReference {
|
|
13
|
-
path: string;
|
|
14
|
-
originalPath?: string;
|
|
15
|
-
prepend?: boolean;
|
|
16
|
-
circular?: boolean;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
export declare const transformerErrors: WeakMap<ts.Program, Diagnostic[]>;
|
|
20
|
-
export declare function addDiagnosticFactory(program: ts.Program): (diag: ts.Diagnostic) => void;
|
|
21
|
-
export declare function patchCreateProgram(tsm: typeof ts, forceReadConfig?: boolean, projectDir?: string): typeof ts;
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
import { Diagnostic } from 'typescript/lib/tsserverlibrary';
|
|
3
|
+
declare module 'typescript' {
|
|
4
|
+
interface CreateProgramOptions {
|
|
5
|
+
rootNames: ReadonlyArray<string>;
|
|
6
|
+
options: ts.CompilerOptions;
|
|
7
|
+
projectReferences?: ReadonlyArray<ts.ProjectReference>;
|
|
8
|
+
host?: ts.CompilerHost;
|
|
9
|
+
oldProgram?: ts.Program;
|
|
10
|
+
configFileParsingDiagnostics?: ReadonlyArray<ts.Diagnostic>;
|
|
11
|
+
}
|
|
12
|
+
interface ProjectReference {
|
|
13
|
+
path: string;
|
|
14
|
+
originalPath?: string;
|
|
15
|
+
prepend?: boolean;
|
|
16
|
+
circular?: boolean;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export declare const transformerErrors: WeakMap<ts.Program, Diagnostic[]>;
|
|
20
|
+
export declare function addDiagnosticFactory(program: ts.Program): (diag: ts.Diagnostic) => void;
|
|
21
|
+
export declare function patchCreateProgram(tsm: typeof ts, forceReadConfig?: boolean, projectDir?: string): typeof ts;
|
|
@@ -1,175 +1,186 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
-
var t = {};
|
|
15
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
-
t[p] = s[p];
|
|
17
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
-
t[p[i]] = s[p[i]];
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
};
|
|
24
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
25
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
26
|
-
if (ar || !(i in from)) {
|
|
27
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
28
|
-
ar[i] = from[i];
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
32
|
-
};
|
|
33
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
-
exports.patchCreateProgram = exports.addDiagnosticFactory = exports.transformerErrors = void 0;
|
|
35
|
-
var path_1 = require("path");
|
|
36
|
-
var
|
|
37
|
-
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
exports.transformerErrors.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
var
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
* The
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
+
var t = {};
|
|
15
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
+
t[p] = s[p];
|
|
17
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
+
t[p[i]] = s[p[i]];
|
|
21
|
+
}
|
|
22
|
+
return t;
|
|
23
|
+
};
|
|
24
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
25
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
26
|
+
if (ar || !(i in from)) {
|
|
27
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
28
|
+
ar[i] = from[i];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
32
|
+
};
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports.patchCreateProgram = exports.addDiagnosticFactory = exports.transformerErrors = void 0;
|
|
35
|
+
var path_1 = require("path");
|
|
36
|
+
var ts = require("typescript");
|
|
37
|
+
var PluginCreator_1 = require("./PluginCreator");
|
|
38
|
+
var _a = ts.version.split('.').map(function (str) { return Number(str); }), major = _a[0], minor = _a[1];
|
|
39
|
+
exports.transformerErrors = new WeakMap();
|
|
40
|
+
function addDiagnosticFactory(program) {
|
|
41
|
+
return function (diag) {
|
|
42
|
+
var arr = exports.transformerErrors.get(program) || [];
|
|
43
|
+
arr.push(diag);
|
|
44
|
+
exports.transformerErrors.set(program, arr);
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
exports.addDiagnosticFactory = addDiagnosticFactory;
|
|
48
|
+
function patchCreateProgram(tsm, forceReadConfig, projectDir) {
|
|
49
|
+
if (forceReadConfig === void 0) { forceReadConfig = false; }
|
|
50
|
+
if (projectDir === void 0) { projectDir = process.cwd(); }
|
|
51
|
+
var originCreateProgram = tsm.createProgram;
|
|
52
|
+
var _ = tsm.createProgram, rest1 = __rest(tsm, ["createProgram"]);
|
|
53
|
+
function hackCreateProgram(rootNamesOrOptions, options, host, oldProgram, configFileParsingDiagnostics) {
|
|
54
|
+
var rootNames;
|
|
55
|
+
var createOpts;
|
|
56
|
+
if (!Array.isArray(rootNamesOrOptions)) {
|
|
57
|
+
createOpts = rootNamesOrOptions;
|
|
58
|
+
}
|
|
59
|
+
if (createOpts) {
|
|
60
|
+
rootNames = createOpts.rootNames;
|
|
61
|
+
options = createOpts.options;
|
|
62
|
+
host = createOpts.host;
|
|
63
|
+
oldProgram = createOpts.oldProgram;
|
|
64
|
+
configFileParsingDiagnostics = createOpts.configFileParsingDiagnostics;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
options = options;
|
|
68
|
+
rootNames = rootNamesOrOptions;
|
|
69
|
+
}
|
|
70
|
+
if (forceReadConfig) {
|
|
71
|
+
var info = getConfig(tsm, options, rootNames, projectDir);
|
|
72
|
+
options = info.compilerOptions;
|
|
73
|
+
if (createOpts) {
|
|
74
|
+
createOpts.options = options;
|
|
75
|
+
}
|
|
76
|
+
projectDir = info.projectDir;
|
|
77
|
+
}
|
|
78
|
+
var program = createOpts
|
|
79
|
+
? originCreateProgram(createOpts)
|
|
80
|
+
: originCreateProgram(rootNames, options, host, oldProgram, configFileParsingDiagnostics);
|
|
81
|
+
var plugins = preparePluginsFromCompilerOptions(options.plugins);
|
|
82
|
+
var pluginCreator = new PluginCreator_1.PluginCreator(tsm, plugins, projectDir);
|
|
83
|
+
var originEmit = program.emit;
|
|
84
|
+
/**
|
|
85
|
+
* The emit method has the following declaration:
|
|
86
|
+
* https://github.com/microsoft/TypeScript/blob/bfc55b5762443c37ecdef08a3b5a4e057b4d1e85/src/compiler/builderPublic.ts#L101
|
|
87
|
+
* The declaration specifies 5 arguments, but it's not true. Sometimes the emit method takes 6 arguments.
|
|
88
|
+
*/
|
|
89
|
+
program.emit = function newEmit(targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers, arg) {
|
|
90
|
+
var mergedTransformers = pluginCreator.createTransformers({ program: program }, customTransformers);
|
|
91
|
+
var result = originEmit(targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, mergedTransformers, arg);
|
|
92
|
+
// todo: doesn't work with 3.7
|
|
93
|
+
// result.diagnostics = [...result.diagnostics, ...transformerErrors.get(program)!];
|
|
94
|
+
return result;
|
|
95
|
+
};
|
|
96
|
+
return program;
|
|
97
|
+
}
|
|
98
|
+
rest1.createProgram = hackCreateProgram;
|
|
99
|
+
return injectionShadowedValues(rest1);
|
|
100
|
+
}
|
|
101
|
+
exports.patchCreateProgram = patchCreateProgram;
|
|
102
|
+
function getConfig(tsm, compilerOptions, rootFileNames, defaultDir) {
|
|
103
|
+
if (compilerOptions.configFilePath === undefined) {
|
|
104
|
+
var dir = rootFileNames.length > 0 ? (0, path_1.dirname)(rootFileNames[0]) : defaultDir;
|
|
105
|
+
var tsconfigPath = tsm.findConfigFile(dir, tsm.sys.fileExists);
|
|
106
|
+
if (tsconfigPath) {
|
|
107
|
+
var projectDir = (0, path_1.dirname)(tsconfigPath);
|
|
108
|
+
var config = readConfig(tsm, tsconfigPath, (0, path_1.dirname)(tsconfigPath));
|
|
109
|
+
compilerOptions = __assign(__assign({}, config.options), compilerOptions);
|
|
110
|
+
return {
|
|
111
|
+
projectDir: projectDir,
|
|
112
|
+
compilerOptions: compilerOptions,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
projectDir: (0, path_1.dirname)(compilerOptions.configFilePath),
|
|
118
|
+
compilerOptions: compilerOptions,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function readConfig(tsm, configFileNamePath, projectDir) {
|
|
122
|
+
var result = tsm.readConfigFile(configFileNamePath, tsm.sys.readFile);
|
|
123
|
+
if (result.error) {
|
|
124
|
+
throw new Error('tsconfig.json error: ' + result.error.messageText);
|
|
125
|
+
}
|
|
126
|
+
return tsm.parseJsonConfigFileContent(result.config, tsm.sys, projectDir, undefined, configFileNamePath);
|
|
127
|
+
}
|
|
128
|
+
function preparePluginsFromCompilerOptions(plugins) {
|
|
129
|
+
if (!plugins)
|
|
130
|
+
return [];
|
|
131
|
+
// old transformers system
|
|
132
|
+
if (plugins.length === 1 && plugins[0].customTransformers) {
|
|
133
|
+
var _a = plugins[0].customTransformers, _b = _a.before, before = _b === void 0 ? [] : _b, _c = _a.after, after = _c === void 0 ? [] : _c;
|
|
134
|
+
return __spreadArray(__spreadArray([], before.map(function (item) { return ({ transform: item }); }), true), after.map(function (item) { return ({ transform: item, after: true }); }), true);
|
|
135
|
+
}
|
|
136
|
+
return plugins;
|
|
137
|
+
}
|
|
138
|
+
function injectionShadowedValues(target) {
|
|
139
|
+
target.getDefaultCompilerOptions2 = function getDefaultCompilerOptions2() {
|
|
140
|
+
return {
|
|
141
|
+
target: 1 /* ES5 */,
|
|
142
|
+
jsx: 1 /* Preserve */,
|
|
143
|
+
};
|
|
144
|
+
};
|
|
145
|
+
function fail(message, stackCrawlMark) {
|
|
146
|
+
debugger;
|
|
147
|
+
var e = new Error(message ? "Debug Failure. ".concat(message) : 'Debug Failure.');
|
|
148
|
+
if (Error.captureStackTrace) {
|
|
149
|
+
Error.captureStackTrace(e, stackCrawlMark || fail);
|
|
150
|
+
}
|
|
151
|
+
throw e;
|
|
152
|
+
}
|
|
153
|
+
function assertEqual(a, b, msg, msg2, stackCrawlMark) {
|
|
154
|
+
if (a !== b) {
|
|
155
|
+
var message = msg ? (msg2 ? "".concat(msg, " ").concat(msg2) : msg) : '';
|
|
156
|
+
fail("Expected ".concat(a, " === ").concat(b, ". ").concat(message), stackCrawlMark || assertEqual);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
target.assertEqual = assertEqual;
|
|
160
|
+
function fileExtensionIs(path, extension) {
|
|
161
|
+
return path.length > extension.length && path.endsWith(extension);
|
|
162
|
+
}
|
|
163
|
+
try {
|
|
164
|
+
var originTranspileModule = major >= 5
|
|
165
|
+
? target.transpileModule
|
|
166
|
+
.toString()
|
|
167
|
+
.replace(/(?<!function)\s([a-z][A-Za-z0-9]+)\(/g, ' target.$1(')
|
|
168
|
+
.replace('hasProperty', 'target.hasProperty')
|
|
169
|
+
.replace(/Debug\./g, 'target.')
|
|
170
|
+
.replace('transpileOptionValueCompilerOptions', 'target.transpileOptionValueCompilerOptions')
|
|
171
|
+
: target.transpileModule
|
|
172
|
+
.toString()
|
|
173
|
+
.replace(/(?<!function)\s([a-z][A-Za-z0-9]+)\(/g, ' target.$1(')
|
|
174
|
+
.replace(/ts\./g, 'target.')
|
|
175
|
+
.replace(/Debug\./g, 'target.')
|
|
176
|
+
.replace(/target\.target\./g, 'target.');
|
|
177
|
+
var __ = target.transpileModule, _target = __rest(target, ["transpileModule"]);
|
|
178
|
+
console.log(originTranspileModule);
|
|
179
|
+
_target.transpileModule = eval('(' + originTranspileModule + ')');
|
|
180
|
+
return _target;
|
|
181
|
+
}
|
|
182
|
+
catch (e) {
|
|
183
|
+
console.log(e);
|
|
184
|
+
return target;
|
|
185
|
+
}
|
|
186
|
+
}
|
package/lib/tsc.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/lib/tsc.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var fs = require("fs");
|
|
4
|
-
var resolve = require("resolve");
|
|
5
|
-
var loadTypescript_1 = require("./loadTypescript");
|
|
6
|
-
var path_1 = require("path");
|
|
7
|
-
var vm_1 = require("vm");
|
|
8
|
-
var ts = (0, loadTypescript_1.loadTypeScript)('typescript', { folder: process.cwd(), forceConfigLoad: true });
|
|
9
|
-
var tscFileName = resolve.sync('typescript/lib/tsc', { basedir: process.cwd() });
|
|
10
|
-
var _a = ts.version.split('.').map(function (str) { return Number(str); }), major = _a[0], minor = _a[1];
|
|
11
|
-
var commandLineTsCode = fs
|
|
12
|
-
.readFileSync(tscFileName, 'utf8')
|
|
13
|
-
.replace(major >= 4 && minor >= 9
|
|
14
|
-
? /^[\s\S]+(\(function \(ts\) {\s+var StatisticType;[\s\S]+)$/
|
|
15
|
-
: /^[\s\S]+(\(function \(ts\)
|
|
16
|
-
if (major >= 5) {
|
|
17
|
-
commandLineTsCode = commandLineTsCode.replace(/\= createProgram\(/g, '= ts.createProgram(');
|
|
18
|
-
}
|
|
19
|
-
var globalCode = (fs.readFileSync(tscFileName, 'utf8').match(/^([\s\S]*?)var ts;/) || ['', ''])[1];
|
|
20
|
-
(0, vm_1.runInThisContext)("(function (exports, require, module, __filename, __dirname, ts) {".concat(globalCode).concat(commandLineTsCode, "\n});"), {
|
|
21
|
-
filename: tscFileName,
|
|
22
|
-
lineOffset: 0,
|
|
23
|
-
displayErrors: true,
|
|
24
|
-
}).call(ts, ts, require, { exports: ts }, tscFileName, (0, path_1.dirname)(tscFileName), ts);
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var fs = require("fs");
|
|
4
|
+
var resolve = require("resolve");
|
|
5
|
+
var loadTypescript_1 = require("./loadTypescript");
|
|
6
|
+
var path_1 = require("path");
|
|
7
|
+
var vm_1 = require("vm");
|
|
8
|
+
var ts = (0, loadTypescript_1.loadTypeScript)('typescript', { folder: process.cwd(), forceConfigLoad: true });
|
|
9
|
+
var tscFileName = resolve.sync('typescript/lib/tsc', { basedir: process.cwd() });
|
|
10
|
+
var _a = ts.version.split('.').map(function (str) { return Number(str); }), major = _a[0], minor = _a[1];
|
|
11
|
+
var commandLineTsCode = fs
|
|
12
|
+
.readFileSync(tscFileName, 'utf8')
|
|
13
|
+
.replace(major >= 4 && minor >= 9
|
|
14
|
+
? /^[\s\S]+(\(function \(ts\) {\s+var StatisticType;[\s\S]+)$/
|
|
15
|
+
: /^[\s\S]+(\(function \(ts\) {\s+function countLines[\s\S]+)$/, '$1');
|
|
16
|
+
if (major >= 5) {
|
|
17
|
+
commandLineTsCode = commandLineTsCode.replace(/\= createProgram\(/g, '= ts.createProgram(');
|
|
18
|
+
}
|
|
19
|
+
var globalCode = (fs.readFileSync(tscFileName, 'utf8').match(/^([\s\S]*?)var ts;/) || ['', ''])[1];
|
|
20
|
+
(0, vm_1.runInThisContext)("(function (exports, require, module, __filename, __dirname, ts) {".concat(globalCode).concat(commandLineTsCode, "\n});"), {
|
|
21
|
+
filename: tscFileName,
|
|
22
|
+
lineOffset: 0,
|
|
23
|
+
displayErrors: true,
|
|
24
|
+
}).call(ts, ts, require, { exports: ts }, tscFileName, (0, path_1.dirname)(tscFileName), ts);
|
package/lib/tsserver.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
module.exports = require('typescript/lib/tsserver');
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = require('typescript/lib/tsserver');
|
package/lib/tsserverlibrary.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import * as TSSL from 'typescript/lib/tsserverlibrary';
|
|
2
|
-
declare const ts: typeof TSSL;
|
|
3
|
-
export = ts;
|
|
1
|
+
import * as TSSL from 'typescript/lib/tsserverlibrary';
|
|
2
|
+
declare const ts: typeof TSSL;
|
|
3
|
+
export = ts;
|
package/lib/tsserverlibrary.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var loadTypescript_1 = require("./loadTypescript");
|
|
3
|
-
var ts = (0, loadTypescript_1.loadTypeScript)('tsserverlibrary');
|
|
4
|
-
module.exports = ts;
|
|
1
|
+
"use strict";
|
|
2
|
+
var loadTypescript_1 = require("./loadTypescript");
|
|
3
|
+
var ts = (0, loadTypescript_1.loadTypeScript)('tsserverlibrary');
|
|
4
|
+
module.exports = ts;
|
package/lib/typescript.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import * as TS from 'typescript';
|
|
2
|
-
declare const ts: typeof TS;
|
|
3
|
-
export = ts;
|
|
1
|
+
import * as TS from 'typescript';
|
|
2
|
+
declare const ts: typeof TS;
|
|
3
|
+
export = ts;
|
package/lib/typescript.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var loadTypescript_1 = require("./loadTypescript");
|
|
3
|
-
var ts = (0, loadTypescript_1.loadTypeScript)('typescript');
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var loadTypescript_1 = require("./loadTypescript");
|
|
3
|
+
var ts = (0, loadTypescript_1.loadTypeScript)('typescript');
|
|
4
|
+
console.log('origin', ts.createProgram);
|
|
5
|
+
module.exports = ts;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import * as TS from 'typescript';
|
|
2
|
-
declare const ts: typeof TS;
|
|
3
|
-
export = ts;
|
|
1
|
+
import * as TS from 'typescript';
|
|
2
|
+
declare const ts: typeof TS;
|
|
3
|
+
export = ts;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var loadTypescript_1 = require("./loadTypescript");
|
|
3
|
-
var ts = (0, loadTypescript_1.loadTypeScript)('typescriptServices');
|
|
4
|
-
module.exports = ts;
|
|
1
|
+
"use strict";
|
|
2
|
+
var loadTypescript_1 = require("./loadTypescript");
|
|
3
|
+
var ts = (0, loadTypescript_1.loadTypeScript)('typescriptServices');
|
|
4
|
+
module.exports = ts;
|
package/lib/typingsInstaller.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
module.exports = require('typescript/lib/typingsInstaller');
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = require('typescript/lib/typingsInstaller');
|
package/lib/watchGuard.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
module.exports = require('typescript/lib/watchGuard');
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = require('typescript/lib/watchGuard');
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"prettier": "npx prettier --config .prettierrc.js --check .",
|
|
15
15
|
"prettier:fix": "npx prettier --config .prettierrc.js --write ."
|
|
16
16
|
},
|
|
17
|
-
"version": "0.0
|
|
17
|
+
"version": "0.2.0",
|
|
18
18
|
"description": "Over TypeScript tool to use custom transformers in the tsconfig.json",
|
|
19
19
|
"main": "lib/typescript.js",
|
|
20
20
|
"files": [
|