@esportsplus/typescript 0.17.5 → 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.
@@ -1,4 +1,2 @@
1
- declare const TRAILING_SEMICOLON: RegExp;
2
- declare const TRANSFORM_PATTERN: RegExp;
3
1
  declare const UUID_REGEX: RegExp;
4
- export { TRAILING_SEMICOLON, TRANSFORM_PATTERN, UUID_REGEX, };
2
+ export { UUID_REGEX };
@@ -1,4 +1,2 @@
1
- const TRAILING_SEMICOLON = /;$/;
2
- const TRANSFORM_PATTERN = /\.[tj]sx?$/;
3
1
  const UUID_REGEX = /[^A-Za-z0-9_$]/g;
4
- export { TRAILING_SEMICOLON, TRANSFORM_PATTERN, UUID_REGEX, };
2
+ export { UUID_REGEX };
@@ -1,5 +1,6 @@
1
1
  export { default as code } from './code.js';
2
2
  export { default as program } from './program.js';
3
+ export { default as plugin } from './plugins/index.js';
3
4
  export { default as uid } from './uid.js';
4
5
  export type * from './types.js';
5
6
  export * from './constants.js';
@@ -1,4 +1,5 @@
1
1
  export { default as code } from './code.js';
2
2
  export { default as program } from './program.js';
3
+ export { default as plugin } from './plugins/index.js';
3
4
  export { default as uid } from './uid.js';
4
5
  export * from './constants.js';
@@ -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,3 @@
1
+ import tsc from './tsc.js';
2
+ import vite from './vite.js';
3
+ export default { tsc, vite };
@@ -0,0 +1,4 @@
1
+ import type { TransformFn } from '../types.js';
2
+ import { ts } from '../../index.js';
3
+ declare const _default: (transform: TransformFn) => (program: ts.Program) => ts.TransformerFactory<ts.SourceFile>;
4
+ export default _default;
@@ -0,0 +1,10 @@
1
+ export default (transform) => {
2
+ return (program) => {
3
+ return () => {
4
+ return (sourceFile) => {
5
+ let result = transform(sourceFile, program);
6
+ return result.changed ? result.sourceFile : sourceFile;
7
+ };
8
+ };
9
+ };
10
+ };
@@ -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
- export type { QuickCheckPattern, Range, Replacement };
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.17.5",
40
+ "version": "0.18.0",
38
41
  "scripts": {
39
42
  "build": "tsc && tsc-alias",
40
43
  "-": "-"
@@ -1,11 +1,4 @@
1
- const TRAILING_SEMICOLON = /;$/;
2
-
3
- const TRANSFORM_PATTERN = /\.[tj]sx?$/;
4
-
5
1
  const UUID_REGEX = /[^A-Za-z0-9_$]/g;
6
2
 
7
3
 
8
- export {
9
- TRAILING_SEMICOLON, TRANSFORM_PATTERN,
10
- UUID_REGEX,
11
- };
4
+ export { UUID_REGEX };
@@ -1,5 +1,6 @@
1
1
  export { default as code } from './code';
2
2
  export { default as program } from './program';
3
+ export { default as plugin } from './plugins';
3
4
  export { default as uid } from './uid';
4
5
  export type * from './types';
5
6
  export * from './constants';
@@ -0,0 +1,5 @@
1
+ import tsc from './tsc';
2
+ import vite from './vite';
3
+
4
+
5
+ export default { tsc, vite };
@@ -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
+ };
@@ -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 };
@@ -1,5 +1,5 @@
1
1
  import { uuid } from '@esportsplus/utilities';
2
- import { UUID_REGEX } from './constants.js';
2
+ import { UUID_REGEX } from './constants';
3
3
 
4
4
 
5
5
  let cache = uuid().replace(UUID_REGEX, ''),