@elliots/typical 0.2.3 → 0.2.5
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/LICENSE +21 -0
- package/README.md +102 -33
- package/bin/typical +0 -0
- package/dist/src/cli.js +15 -15
- package/dist/src/cli.js.map +1 -1
- package/dist/src/config.d.ts +0 -7
- package/dist/src/config.js +6 -7
- package/dist/src/config.js.map +1 -1
- package/dist/src/esm-loader-register.js +2 -2
- package/dist/src/esm-loader-register.js.map +1 -1
- package/dist/src/esm-loader.js +11 -11
- package/dist/src/esm-loader.js.map +1 -1
- package/dist/src/index.d.ts +5 -5
- package/dist/src/index.js +3 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/timing.d.ts +18 -11
- package/dist/src/timing.js +39 -51
- package/dist/src/timing.js.map +1 -1
- package/dist/src/transformer.d.ts +3 -3
- package/dist/src/transformer.js +8 -8
- package/dist/src/transformer.js.map +1 -1
- package/package.json +5 -5
- package/src/cli.ts +31 -31
- package/src/config.ts +28 -36
- package/src/esm-loader-register.ts +2 -2
- package/src/esm-loader.ts +26 -26
- package/src/index.ts +5 -5
- package/src/patch-fs.cjs +14 -14
- package/src/timing.ts +43 -57
- package/src/transformer.ts +35 -30
- package/dist/src/cli.typical.ts +0 -136
- package/dist/src/config.typical.ts +0 -287
- package/dist/src/file-filter.d.ts +0 -13
- package/dist/src/file-filter.js +0 -42
- package/dist/src/file-filter.js.map +0 -1
- package/dist/src/program-manager.d.ts +0 -27
- package/dist/src/program-manager.js +0 -121
- package/dist/src/program-manager.js.map +0 -1
- package/dist/src/regex-hoister.d.ts +0 -11
- package/dist/src/regex-hoister.js +0 -150
- package/dist/src/regex-hoister.js.map +0 -1
- package/dist/src/setup.d.ts +0 -2
- package/dist/src/setup.js +0 -20
- package/dist/src/setup.js.map +0 -1
- package/dist/src/source-map.d.ts +0 -78
- package/dist/src/source-map.js +0 -133
- package/dist/src/source-map.js.map +0 -1
- package/dist/src/source-map.typical.ts +0 -216
- package/dist/src/transformer.typical.ts +0 -2552
- package/dist/src/tsc-plugin.d.ts +0 -10
- package/dist/src/tsc-plugin.js +0 -13
- package/dist/src/tsc-plugin.js.map +0 -1
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
import typia from "typia";
|
|
2
|
-
//@L:1
|
|
3
|
-
import MagicString from 'magic-string';
|
|
4
|
-
//@L:2
|
|
5
|
-
import remapping from '@ampproject/remapping';
|
|
6
|
-
//@L:3
|
|
7
|
-
import type { DecodedSourceMap, EncodedSourceMap } from '@ampproject/remapping';
|
|
8
|
-
/**
|
|
9
|
-
* Result of a transformation that includes source map information.
|
|
10
|
-
*/
|
|
11
|
-
//@L:8
|
|
12
|
-
export interface TransformResult {
|
|
13
|
-
//@L:9
|
|
14
|
-
code: string;
|
|
15
|
-
//@L:10
|
|
16
|
-
map: EncodedSourceMap | null;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Configuration options for source map generation.
|
|
20
|
-
*/
|
|
21
|
-
//@L:16
|
|
22
|
-
export interface SourceMapOptions {
|
|
23
|
-
/** Generate source maps. Default: true */
|
|
24
|
-
//@L:18
|
|
25
|
-
enabled?: boolean;
|
|
26
|
-
/** Include source content in map. Default: true */
|
|
27
|
-
//@L:20
|
|
28
|
-
includeContent?: boolean;
|
|
29
|
-
/** Use inline source maps (data URL). Default: false */
|
|
30
|
-
//@L:22
|
|
31
|
-
inline?: boolean;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Default source map options.
|
|
35
|
-
*/
|
|
36
|
-
//@L:28
|
|
37
|
-
export const defaultSourceMapOptions: Required<SourceMapOptions> = {
|
|
38
|
-
enabled: true,
|
|
39
|
-
includeContent: true,
|
|
40
|
-
inline: false,
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Compose multiple source maps together.
|
|
44
|
-
* Given maps [A->B, B->C], produces A->C.
|
|
45
|
-
* Maps are applied in order: first map is closest to original source.
|
|
46
|
-
*/
|
|
47
|
-
//@L:39
|
|
48
|
-
export function composeSourceMaps(maps: (EncodedSourceMap | DecodedSourceMap | string | null | undefined)[], originalFileName: string): EncodedSourceMap | null {
|
|
49
|
-
// Filter out null/undefined maps
|
|
50
|
-
//@L:44
|
|
51
|
-
const validMaps = maps.filter((m): m is EncodedSourceMap | DecodedSourceMap | string => m !== null && m !== undefined);
|
|
52
|
-
//@L:48
|
|
53
|
-
if (validMaps.length === 0)
|
|
54
|
-
return null;
|
|
55
|
-
//@L:49
|
|
56
|
-
if (validMaps.length === 1) {
|
|
57
|
-
//@L:50
|
|
58
|
-
const map = validMaps[0];
|
|
59
|
-
//@L:51
|
|
60
|
-
if (typeof map === 'string') {
|
|
61
|
-
//@L:52
|
|
62
|
-
return typia.json.assertParse<EncodedSourceMap>(map) as EncodedSourceMap;
|
|
63
|
-
}
|
|
64
|
-
//@L:54
|
|
65
|
-
return map as EncodedSourceMap;
|
|
66
|
-
}
|
|
67
|
-
// remapping expects maps in reverse order (final output first)
|
|
68
|
-
// and a loader function that returns the source map for a given file
|
|
69
|
-
//@L:59
|
|
70
|
-
const reversedMaps = [...validMaps].reverse();
|
|
71
|
-
//@L:61
|
|
72
|
-
try {
|
|
73
|
-
const result = remapping(reversedMaps, () => null);
|
|
74
|
-
return result as EncodedSourceMap;
|
|
75
|
-
}
|
|
76
|
-
catch (e) {
|
|
77
|
-
// If remapping fails, return the last valid map
|
|
78
|
-
console.warn('Source map composition failed:', e);
|
|
79
|
-
const lastMap = validMaps[validMaps.length - 1];
|
|
80
|
-
if (typeof lastMap === 'string') {
|
|
81
|
-
return typia.json.assertParse<EncodedSourceMap>(lastMap) as EncodedSourceMap;
|
|
82
|
-
}
|
|
83
|
-
return lastMap as EncodedSourceMap;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Generate an inline source map comment (data URL).
|
|
88
|
-
*/
|
|
89
|
-
//@L:78
|
|
90
|
-
export function inlineSourceMapComment(map: EncodedSourceMap | string): string {
|
|
91
|
-
//@L:79
|
|
92
|
-
const mapString = typeof map === 'string' ? map : typia.json.stringify(map);
|
|
93
|
-
//@L:80
|
|
94
|
-
const base64 = Buffer.from(mapString).toString('base64');
|
|
95
|
-
//@L:81
|
|
96
|
-
return `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64}`;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Generate an external source map URL comment.
|
|
100
|
-
*/
|
|
101
|
-
//@L:87
|
|
102
|
-
export function externalSourceMapComment(mapFileName: string): string {
|
|
103
|
-
//@L:88
|
|
104
|
-
return `//# sourceMappingURL=${mapFileName}`;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Create a MagicString instance for tracking source modifications.
|
|
108
|
-
*/
|
|
109
|
-
//@L:94
|
|
110
|
-
export function createMagicString(source: string, filename?: string): MagicString {
|
|
111
|
-
//@L:95
|
|
112
|
-
return new MagicString(source, {
|
|
113
|
-
filename,
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Generate a source map from a MagicString instance.
|
|
118
|
-
*/
|
|
119
|
-
//@L:103
|
|
120
|
-
export function generateSourceMap(ms: MagicString, options: {
|
|
121
|
-
source: string;
|
|
122
|
-
file?: string;
|
|
123
|
-
includeContent?: boolean;
|
|
124
|
-
hires?: boolean | 'boundary';
|
|
125
|
-
}): EncodedSourceMap {
|
|
126
|
-
//@L:112
|
|
127
|
-
return ms.generateMap({
|
|
128
|
-
source: options.source,
|
|
129
|
-
file: options.file ?? options.source,
|
|
130
|
-
includeContent: options.includeContent ?? true,
|
|
131
|
-
hires: options.hires ?? true,
|
|
132
|
-
}) as EncodedSourceMap;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Create an identity source map (maps each position to itself).
|
|
136
|
-
* Useful as a placeholder when no transformation occurred.
|
|
137
|
-
*/
|
|
138
|
-
//@L:124
|
|
139
|
-
export function createIdentityMap(source: string, fileName: string, includeContent: boolean = true): EncodedSourceMap {
|
|
140
|
-
//@L:129
|
|
141
|
-
const ms = new MagicString(source);
|
|
142
|
-
//@L:130
|
|
143
|
-
return ms.generateMap({
|
|
144
|
-
source: fileName,
|
|
145
|
-
file: fileName,
|
|
146
|
-
includeContent,
|
|
147
|
-
hires: true,
|
|
148
|
-
}) as EncodedSourceMap;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Represents a tracked modification to source code.
|
|
152
|
-
*/
|
|
153
|
-
//@L:141
|
|
154
|
-
export interface SourceModification {
|
|
155
|
-
/** Start position in original source */
|
|
156
|
-
//@L:143
|
|
157
|
-
start: number;
|
|
158
|
-
/** End position in original source */
|
|
159
|
-
//@L:145
|
|
160
|
-
end: number;
|
|
161
|
-
/** The replacement text */
|
|
162
|
-
//@L:147
|
|
163
|
-
replacement: string;
|
|
164
|
-
/** Type of modification */
|
|
165
|
-
//@L:149
|
|
166
|
-
type: 'insert-before' | 'insert-after' | 'replace' | 'prepend' | 'append';
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Apply a list of modifications to source code using MagicString.
|
|
170
|
-
* Returns the modified code and source map.
|
|
171
|
-
*/
|
|
172
|
-
//@L:156
|
|
173
|
-
export function applyModifications(source: string, fileName: string, modifications: SourceModification[], includeContent: boolean = true): TransformResult {
|
|
174
|
-
//@L:162
|
|
175
|
-
const ms = createMagicString(source, fileName);
|
|
176
|
-
// Sort modifications by position (descending) to apply from end to start
|
|
177
|
-
// This prevents position shifts from affecting subsequent modifications
|
|
178
|
-
//@L:166
|
|
179
|
-
const sorted = [...modifications].sort((a, b) => b.start - a.start);
|
|
180
|
-
//@L:168
|
|
181
|
-
for (const mod of sorted) {
|
|
182
|
-
switch (mod.type) {
|
|
183
|
-
case 'insert-before':
|
|
184
|
-
ms.prependLeft(mod.start, mod.replacement);
|
|
185
|
-
break;
|
|
186
|
-
case 'insert-after':
|
|
187
|
-
ms.appendRight(mod.end, mod.replacement);
|
|
188
|
-
break;
|
|
189
|
-
case 'replace':
|
|
190
|
-
ms.overwrite(mod.start, mod.end, mod.replacement);
|
|
191
|
-
break;
|
|
192
|
-
case 'prepend':
|
|
193
|
-
ms.prepend(mod.replacement);
|
|
194
|
-
break;
|
|
195
|
-
case 'append':
|
|
196
|
-
ms.append(mod.replacement);
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
//@L:188
|
|
201
|
-
return {
|
|
202
|
-
code: ms.toString(),
|
|
203
|
-
map: generateSourceMap(ms, {
|
|
204
|
-
source: fileName,
|
|
205
|
-
includeContent,
|
|
206
|
-
}),
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Strip any existing source map comments from code.
|
|
211
|
-
*/
|
|
212
|
-
//@L:200
|
|
213
|
-
export function stripSourceMapComment(code: string): string {
|
|
214
|
-
//@L:201
|
|
215
|
-
return code.replace(/\/\/[#@]\s*sourceMappingURL=.*/g, '');
|
|
216
|
-
}
|