@esportsplus/typescript 0.17.6 → 0.18.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/build/transformer/constants.d.ts +1 -3
- package/build/transformer/constants.js +1 -3
- package/build/transformer/index.d.ts +1 -0
- package/build/transformer/index.js +1 -0
- package/build/transformer/plugins/index.d.ts +16 -0
- package/build/transformer/plugins/index.js +3 -0
- package/build/transformer/plugins/tsc.d.ts +4 -0
- package/build/transformer/plugins/tsc.js +10 -0
- package/build/transformer/plugins/vite.d.ts +15 -0
- package/build/transformer/plugins/vite.js +36 -0
- package/build/transformer/types.d.ts +13 -1
- package/package.json +4 -1
- package/src/transformer/constants.ts +1 -8
- package/src/transformer/index.ts +1 -0
- package/src/transformer/plugins/index.ts +5 -0
- package/src/transformer/plugins/tsc.ts +15 -0
- package/src/transformer/plugins/vite.ts +48 -0
- package/src/transformer/types.ts +18 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
tsc: (transform: import("../index.js").TransformFn) => (program: import("typescript").Program) => import("typescript").TransformerFactory<import("typescript").SourceFile>;
|
|
3
|
+
vite: ({ name, onWatchChange, transform }: import("../index.js").VitePluginOptions) => ({ root }?: {
|
|
4
|
+
root?: string;
|
|
5
|
+
}) => {
|
|
6
|
+
configResolved(config: import("vite").ResolvedConfig): void;
|
|
7
|
+
enforce: string;
|
|
8
|
+
name: string;
|
|
9
|
+
transform(code: string, id: string): {
|
|
10
|
+
code: string;
|
|
11
|
+
map: null;
|
|
12
|
+
} | null;
|
|
13
|
+
watchChange(id: string): void;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export default _default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ResolvedConfig } from 'vite';
|
|
2
|
+
import type { VitePluginOptions } from '../types.js';
|
|
3
|
+
declare const _default: ({ name, onWatchChange, transform }: VitePluginOptions) => ({ root }?: {
|
|
4
|
+
root?: string;
|
|
5
|
+
}) => {
|
|
6
|
+
configResolved(config: ResolvedConfig): void;
|
|
7
|
+
enforce: string;
|
|
8
|
+
name: string;
|
|
9
|
+
transform(code: string, id: string): {
|
|
10
|
+
code: string;
|
|
11
|
+
map: null;
|
|
12
|
+
} | null;
|
|
13
|
+
watchChange(id: string): void;
|
|
14
|
+
};
|
|
15
|
+
export default _default;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ts } from '../../index.js';
|
|
2
|
+
import program from '../program.js';
|
|
3
|
+
const FILE_REGEX = /\.[tj]sx?$/;
|
|
4
|
+
export default ({ name, onWatchChange, transform }) => {
|
|
5
|
+
return ({ root } = {}) => {
|
|
6
|
+
return {
|
|
7
|
+
configResolved(config) {
|
|
8
|
+
root ??= config.root;
|
|
9
|
+
},
|
|
10
|
+
enforce: 'pre',
|
|
11
|
+
name: `${name}/plugin-vite`,
|
|
12
|
+
transform(code, id) {
|
|
13
|
+
if (!FILE_REGEX.test(id) || id.includes('node_modules')) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
let result = transform(ts.createSourceFile(id, code, ts.ScriptTarget.Latest, true), program.get(root || ''));
|
|
18
|
+
if (!result.changed) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
return { code: result.code, map: null };
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
console.error(`${name}: error transforming ${id}:`, error);
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
watchChange(id) {
|
|
29
|
+
if (FILE_REGEX.test(id)) {
|
|
30
|
+
onWatchChange?.();
|
|
31
|
+
program.delete(root || '');
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type ts from 'typescript';
|
|
1
2
|
type QuickCheckPattern = {
|
|
2
3
|
patterns?: string[];
|
|
3
4
|
regex?: RegExp;
|
|
@@ -9,4 +10,15 @@ type Range = {
|
|
|
9
10
|
type Replacement = Range & {
|
|
10
11
|
newText: string;
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
+
type TransformFn = (sourceFile: ts.SourceFile, program: ts.Program) => TransformResult;
|
|
14
|
+
type TransformResult = {
|
|
15
|
+
changed: boolean;
|
|
16
|
+
code: string;
|
|
17
|
+
sourceFile: ts.SourceFile;
|
|
18
|
+
};
|
|
19
|
+
type VitePluginOptions = {
|
|
20
|
+
name: string;
|
|
21
|
+
onWatchChange?: () => void;
|
|
22
|
+
transform: TransformFn;
|
|
23
|
+
};
|
|
24
|
+
export type { QuickCheckPattern, Range, Replacement, TransformFn, TransformResult, VitePluginOptions };
|
package/package.json
CHANGED
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
"tsc-alias": "^1.8.16",
|
|
12
12
|
"typescript": "^5.9.3"
|
|
13
13
|
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"vite": "^6.0.7"
|
|
16
|
+
},
|
|
14
17
|
"exports": {
|
|
15
18
|
"./package.json": "./package.json",
|
|
16
19
|
"./tsconfig.browser.json": "./tsconfig.browser.json",
|
|
@@ -34,7 +37,7 @@
|
|
|
34
37
|
},
|
|
35
38
|
"type": "module",
|
|
36
39
|
"types": "build/index.d.ts",
|
|
37
|
-
"version": "0.
|
|
40
|
+
"version": "0.18.0",
|
|
38
41
|
"scripts": {
|
|
39
42
|
"build": "tsc && tsc-alias",
|
|
40
43
|
"-": "-"
|
package/src/transformer/index.ts
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TransformFn } from '../types';
|
|
2
|
+
import { ts } from '../..';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export default (transform: TransformFn): (program: ts.Program) => ts.TransformerFactory<ts.SourceFile> => {
|
|
6
|
+
return (program) => {
|
|
7
|
+
return () => {
|
|
8
|
+
return (sourceFile) => {
|
|
9
|
+
let result = transform(sourceFile, program);
|
|
10
|
+
|
|
11
|
+
return result.changed ? result.sourceFile : sourceFile;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { ResolvedConfig } from 'vite';
|
|
2
|
+
import type { VitePluginOptions } from '../types';
|
|
3
|
+
import { ts } from '../..';
|
|
4
|
+
import program from '../program';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const FILE_REGEX = /\.[tj]sx?$/;
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export default ({ name, onWatchChange, transform }: VitePluginOptions) => {
|
|
11
|
+
return ({ root }: { root?: string } = {}) => {
|
|
12
|
+
return {
|
|
13
|
+
configResolved(config: ResolvedConfig) {
|
|
14
|
+
root ??= config.root;
|
|
15
|
+
},
|
|
16
|
+
enforce: 'pre',
|
|
17
|
+
name: `${name}/plugin-vite`,
|
|
18
|
+
transform(code: string, id: string) {
|
|
19
|
+
if (!FILE_REGEX.test(id) || id.includes('node_modules')) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
let result = transform(
|
|
25
|
+
ts.createSourceFile(id, code, ts.ScriptTarget.Latest, true),
|
|
26
|
+
program.get(root || '')
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
if (!result.changed) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return { code: result.code, map: null };
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
console.error(`${name}: error transforming ${id}:`, error);
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
watchChange(id: string) {
|
|
41
|
+
if (FILE_REGEX.test(id)) {
|
|
42
|
+
onWatchChange?.();
|
|
43
|
+
program.delete(root || '');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
package/src/transformer/types.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type ts from 'typescript';
|
|
2
|
+
|
|
3
|
+
|
|
1
4
|
type QuickCheckPattern = {
|
|
2
5
|
patterns?: string[];
|
|
3
6
|
regex?: RegExp;
|
|
@@ -12,5 +15,19 @@ type Replacement = Range & {
|
|
|
12
15
|
newText: string;
|
|
13
16
|
};
|
|
14
17
|
|
|
18
|
+
type TransformFn = (sourceFile: ts.SourceFile, program: ts.Program) => TransformResult;
|
|
19
|
+
|
|
20
|
+
type TransformResult = {
|
|
21
|
+
changed: boolean;
|
|
22
|
+
code: string;
|
|
23
|
+
sourceFile: ts.SourceFile;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
type VitePluginOptions = {
|
|
27
|
+
name: string;
|
|
28
|
+
onWatchChange?: () => void;
|
|
29
|
+
transform: TransformFn;
|
|
30
|
+
};
|
|
31
|
+
|
|
15
32
|
|
|
16
|
-
export type { QuickCheckPattern, Range, Replacement };
|
|
33
|
+
export type { QuickCheckPattern, Range, Replacement, TransformFn, TransformResult, VitePluginOptions };
|