@esportsplus/typescript 0.27.0 → 0.27.1
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/build/cli/tsc.js +19 -4
- package/build/compiler/plugins/index.d.ts +1 -3
- package/build/compiler/plugins/tsc.d.ts +2 -5
- package/build/compiler/plugins/tsc.js +1 -11
- package/build/compiler/program.js +3 -2
- package/build/constants.d.ts +2 -0
- package/build/constants.js +2 -0
- package/package.json +1 -1
- package/src/cli/tsc.ts +22 -4
- package/src/compiler/plugins/tsc.ts +2 -20
- package/src/compiler/program.ts +3 -2
- package/src/constants.ts +4 -0
package/build/cli/tsc.js
CHANGED
|
@@ -4,6 +4,7 @@ import { pathToFileURL } from 'url';
|
|
|
4
4
|
import path from 'path';
|
|
5
5
|
import ts from 'typescript';
|
|
6
6
|
import coordinator from '../compiler/coordinator.js';
|
|
7
|
+
import { PACKAGE_NAME } from '../constants.js';
|
|
7
8
|
const BACKSLASH_REGEX = /\\/g;
|
|
8
9
|
let require = createRequire(import.meta.url), skipFlags = new Set(['--help', '--init', '--noEmit', '--showConfig', '--version', '-h', '-noEmit', '-v']);
|
|
9
10
|
async function build(config, tsconfig, pluginConfigs) {
|
|
@@ -54,6 +55,9 @@ async function build(config, tsconfig, pluginConfigs) {
|
|
|
54
55
|
}
|
|
55
56
|
return runTscAlias(process.argv.slice(2)).then((code) => process.exit(code));
|
|
56
57
|
}
|
|
58
|
+
function isPlugin(value) {
|
|
59
|
+
return typeof value === 'object' && value !== null && 'transform' in value && typeof value.transform === 'function';
|
|
60
|
+
}
|
|
57
61
|
async function loadPlugins(configs, root) {
|
|
58
62
|
let plugins = [], promises = [];
|
|
59
63
|
for (let i = 0, n = configs.length; i < n; i++) {
|
|
@@ -69,8 +73,19 @@ async function loadPlugins(configs, root) {
|
|
|
69
73
|
if (typeof plugin === 'function') {
|
|
70
74
|
plugin = plugin();
|
|
71
75
|
}
|
|
72
|
-
if (
|
|
73
|
-
|
|
76
|
+
if (Array.isArray(plugin)) {
|
|
77
|
+
for (let j = 0, m = plugin.length; j < m; j++) {
|
|
78
|
+
if (isPlugin(plugin[j])) {
|
|
79
|
+
plugins.push(plugin[j]);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
console.error(`${PACKAGE_NAME}: plugin ${config.transform}[${j}] uses an invalid plugin format`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (!isPlugin(plugin)) {
|
|
88
|
+
console.error(`${PACKAGE_NAME}: plugin ${config.transform} uses an invalid plugin format, expected { transform: Function } or Plugin[]`);
|
|
74
89
|
return;
|
|
75
90
|
}
|
|
76
91
|
plugins.push(plugin);
|
|
@@ -92,9 +107,9 @@ function main() {
|
|
|
92
107
|
if (pluginConfigs.length === 0) {
|
|
93
108
|
return passthrough();
|
|
94
109
|
}
|
|
95
|
-
console.log(
|
|
110
|
+
console.log(`${PACKAGE_NAME}: found ${pluginConfigs.length} transformer plugin(s), using coordinated build...`);
|
|
96
111
|
build(config, tsconfig, pluginConfigs).catch((err) => {
|
|
97
|
-
console.error(err);
|
|
112
|
+
console.error(`${PACKAGE_NAME}: ${err}`);
|
|
98
113
|
process.exit(1);
|
|
99
114
|
});
|
|
100
115
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
tsc: (plugins: import("../index.js").Plugin[]) => (
|
|
3
|
-
transform: import("typescript").TransformerFactory<import("typescript").SourceFile>;
|
|
4
|
-
};
|
|
2
|
+
tsc: (plugins: import("../index.js").Plugin[]) => () => import("../index.js").Plugin[];
|
|
5
3
|
vite: ({ name, onWatchChange, plugins }: {
|
|
6
4
|
name: string;
|
|
7
5
|
onWatchChange?: () => void;
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import type { Plugin
|
|
2
|
-
|
|
3
|
-
declare const _default: (plugins: Plugin[]) => (program: ts.Program, shared: SharedContext) => {
|
|
4
|
-
transform: ts.TransformerFactory<ts.SourceFile>;
|
|
5
|
-
};
|
|
1
|
+
import type { Plugin } from '../types.js';
|
|
2
|
+
declare const _default: (plugins: Plugin[]) => () => Plugin[];
|
|
6
3
|
export default _default;
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
import coordinator from '../coordinator.js';
|
|
2
1
|
export default (plugins) => {
|
|
3
|
-
return (
|
|
4
|
-
return {
|
|
5
|
-
transform: (() => {
|
|
6
|
-
return (sourceFile) => {
|
|
7
|
-
let result = coordinator.transform(plugins, sourceFile.getFullText(), sourceFile, program, shared);
|
|
8
|
-
return result.changed ? result.sourceFile : sourceFile;
|
|
9
|
-
};
|
|
10
|
-
})
|
|
11
|
-
};
|
|
12
|
-
};
|
|
2
|
+
return () => plugins;
|
|
13
3
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import ts from 'typescript';
|
|
3
|
+
import { PACKAGE_NAME } from '../constants.js';
|
|
3
4
|
let cache = new Map();
|
|
4
5
|
function create(root) {
|
|
5
6
|
let tsconfig = ts.findConfigFile(root, ts.sys.fileExists, 'tsconfig.json');
|
|
@@ -8,11 +9,11 @@ function create(root) {
|
|
|
8
9
|
}
|
|
9
10
|
let file = ts.readConfigFile(tsconfig, ts.sys.readFile);
|
|
10
11
|
if (file.error) {
|
|
11
|
-
throw new Error(
|
|
12
|
+
throw new Error(`${PACKAGE_NAME}: error reading tsconfig.json ${file.error.messageText}`);
|
|
12
13
|
}
|
|
13
14
|
let parsed = ts.parseJsonConfigFileContent(file.config, ts.sys, path.dirname(tsconfig));
|
|
14
15
|
if (parsed.errors.length > 0) {
|
|
15
|
-
throw new Error(
|
|
16
|
+
throw new Error(`${PACKAGE_NAME}: error parsing tsconfig.json ${parsed.errors[0].messageText}`);
|
|
16
17
|
}
|
|
17
18
|
return ts.createProgram({
|
|
18
19
|
options: parsed.options,
|
package/package.json
CHANGED
package/src/cli/tsc.ts
CHANGED
|
@@ -5,6 +5,7 @@ import path from 'path';
|
|
|
5
5
|
import ts from 'typescript';
|
|
6
6
|
import coordinator from '~/compiler/coordinator';
|
|
7
7
|
import type { Plugin, SharedContext } from '~/compiler/types';
|
|
8
|
+
import { PACKAGE_NAME } from '~/constants';
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
type PluginConfig = {
|
|
@@ -109,6 +110,10 @@ async function build(config: object, tsconfig: string, pluginConfigs: PluginConf
|
|
|
109
110
|
return runTscAlias(process.argv.slice(2)).then((code) => process.exit(code));
|
|
110
111
|
}
|
|
111
112
|
|
|
113
|
+
function isPlugin(value: unknown): value is Plugin {
|
|
114
|
+
return typeof value === 'object' && value !== null && 'transform' in value && typeof (value as Plugin).transform === 'function';
|
|
115
|
+
}
|
|
116
|
+
|
|
112
117
|
async function loadPlugins(configs: PluginConfig[], root: string): Promise<Plugin[]> {
|
|
113
118
|
let plugins: Plugin[] = [],
|
|
114
119
|
promises: Promise<void>[] = [];
|
|
@@ -132,8 +137,21 @@ async function loadPlugins(configs: PluginConfig[], root: string): Promise<Plugi
|
|
|
132
137
|
plugin = plugin();
|
|
133
138
|
}
|
|
134
139
|
|
|
135
|
-
if (
|
|
136
|
-
|
|
140
|
+
if (Array.isArray(plugin)) {
|
|
141
|
+
for (let j = 0, m = plugin.length; j < m; j++) {
|
|
142
|
+
if (isPlugin(plugin[j])) {
|
|
143
|
+
plugins.push(plugin[j]);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
console.error(`${PACKAGE_NAME}: plugin ${config.transform}[${j}] uses an invalid plugin format`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (!isPlugin(plugin)) {
|
|
154
|
+
console.error(`${PACKAGE_NAME}: plugin ${config.transform} uses an invalid plugin format, expected { transform: Function } or Plugin[]`);
|
|
137
155
|
return;
|
|
138
156
|
}
|
|
139
157
|
|
|
@@ -168,10 +186,10 @@ function main(): void {
|
|
|
168
186
|
return passthrough();
|
|
169
187
|
}
|
|
170
188
|
|
|
171
|
-
console.log(
|
|
189
|
+
console.log(`${PACKAGE_NAME}: found ${pluginConfigs.length} transformer plugin(s), using coordinated build...`);
|
|
172
190
|
|
|
173
191
|
build(config, tsconfig, pluginConfigs).catch((err) => {
|
|
174
|
-
console.error(err);
|
|
192
|
+
console.error(`${PACKAGE_NAME}: ${err}`);
|
|
175
193
|
process.exit(1);
|
|
176
194
|
});
|
|
177
195
|
}
|
|
@@ -1,24 +1,6 @@
|
|
|
1
|
-
import type { Plugin
|
|
2
|
-
import type ts from 'typescript';
|
|
3
|
-
import coordinator from '../coordinator';
|
|
1
|
+
import type { Plugin } from '../types';
|
|
4
2
|
|
|
5
3
|
|
|
6
4
|
export default (plugins: Plugin[]) => {
|
|
7
|
-
return (
|
|
8
|
-
return {
|
|
9
|
-
transform: (() => {
|
|
10
|
-
return (sourceFile: ts.SourceFile) => {
|
|
11
|
-
let result = coordinator.transform(
|
|
12
|
-
plugins,
|
|
13
|
-
sourceFile.getFullText(),
|
|
14
|
-
sourceFile,
|
|
15
|
-
program,
|
|
16
|
-
shared
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
return result.changed ? result.sourceFile : sourceFile;
|
|
20
|
-
};
|
|
21
|
-
}) as ts.TransformerFactory<ts.SourceFile>
|
|
22
|
-
};
|
|
23
|
-
};
|
|
5
|
+
return () => plugins;
|
|
24
6
|
};
|
package/src/compiler/program.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import ts from 'typescript';
|
|
3
|
+
import { PACKAGE_NAME } from '~/constants';
|
|
3
4
|
|
|
4
5
|
|
|
5
6
|
let cache = new Map<string, ts.Program>();
|
|
@@ -15,7 +16,7 @@ function create(root: string): ts.Program {
|
|
|
15
16
|
let file = ts.readConfigFile(tsconfig, ts.sys.readFile);
|
|
16
17
|
|
|
17
18
|
if (file.error) {
|
|
18
|
-
throw new Error(
|
|
19
|
+
throw new Error(`${PACKAGE_NAME}: error reading tsconfig.json ${file.error.messageText}`);
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
let parsed = ts.parseJsonConfigFileContent(
|
|
@@ -25,7 +26,7 @@ function create(root: string): ts.Program {
|
|
|
25
26
|
);
|
|
26
27
|
|
|
27
28
|
if (parsed.errors.length > 0) {
|
|
28
|
-
throw new Error(
|
|
29
|
+
throw new Error(`${PACKAGE_NAME}: error parsing tsconfig.json ${parsed.errors[0].messageText}`);
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
return ts.createProgram({
|
package/src/constants.ts
ADDED