@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,121 +0,0 @@
|
|
|
1
|
-
import ts from 'typescript';
|
|
2
|
-
import { resolve, dirname } from 'path';
|
|
3
|
-
import { buildTimer } from './timing.js';
|
|
4
|
-
/**
|
|
5
|
-
* Manages a shared TypeScript program across file transformations.
|
|
6
|
-
* This avoids the expensive cost of creating a new program for each file.
|
|
7
|
-
*/
|
|
8
|
-
export class ProgramManager {
|
|
9
|
-
program;
|
|
10
|
-
compilerOptions;
|
|
11
|
-
sourceContents = new Map(); // Virtual file contents (transformed by bundler)
|
|
12
|
-
sourceFileCache = new Map(); // Cached source files from disk
|
|
13
|
-
host;
|
|
14
|
-
/**
|
|
15
|
-
* Get or create a program with the given source content for a file.
|
|
16
|
-
* Uses incremental compilation to reuse data from previous program.
|
|
17
|
-
*/
|
|
18
|
-
getProgram(id, source) {
|
|
19
|
-
const resolvedId = resolve(id);
|
|
20
|
-
// Update virtual source content
|
|
21
|
-
this.sourceContents.set(resolvedId, source);
|
|
22
|
-
// Invalidate cached source file for this file (since content changed)
|
|
23
|
-
this.sourceFileCache.delete(resolvedId);
|
|
24
|
-
// Ensure we have compiler options and host
|
|
25
|
-
if (!this.compilerOptions) {
|
|
26
|
-
buildTimer.start('load-compiler-options');
|
|
27
|
-
this.compilerOptions = this.loadCompilerOptions();
|
|
28
|
-
buildTimer.end('load-compiler-options');
|
|
29
|
-
}
|
|
30
|
-
if (!this.host) {
|
|
31
|
-
this.host = this.createHost();
|
|
32
|
-
}
|
|
33
|
-
// Get current root files, adding the new file if not present
|
|
34
|
-
const rootFiles = this.program?.getRootFileNames() ?? [];
|
|
35
|
-
const rootFileSet = new Set(rootFiles);
|
|
36
|
-
if (!rootFileSet.has(resolvedId)) {
|
|
37
|
-
rootFileSet.add(resolvedId);
|
|
38
|
-
}
|
|
39
|
-
// Create program, reusing old program for incremental compilation
|
|
40
|
-
buildTimer.start('create-program-incremental');
|
|
41
|
-
this.program = ts.createProgram(Array.from(rootFileSet), this.compilerOptions, this.host, this.program);
|
|
42
|
-
buildTimer.end('create-program-incremental');
|
|
43
|
-
return this.program;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Get the source file for a given ID from the current program.
|
|
47
|
-
*/
|
|
48
|
-
getSourceFile(id) {
|
|
49
|
-
const resolvedId = resolve(id);
|
|
50
|
-
return this.program?.getSourceFile(resolvedId);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Reset the program manager state (e.g., at build start).
|
|
54
|
-
*/
|
|
55
|
-
reset() {
|
|
56
|
-
this.program = undefined;
|
|
57
|
-
this.sourceContents.clear();
|
|
58
|
-
// Keep sourceFileCache and compilerOptions since they don't change
|
|
59
|
-
}
|
|
60
|
-
loadCompilerOptions() {
|
|
61
|
-
const configPath = ts.findConfigFile(process.cwd(), f => ts.sys.fileExists(f), 'tsconfig.json');
|
|
62
|
-
if (!configPath) {
|
|
63
|
-
return {
|
|
64
|
-
target: ts.ScriptTarget.ES2020,
|
|
65
|
-
module: ts.ModuleKind.ESNext,
|
|
66
|
-
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
67
|
-
esModuleInterop: true,
|
|
68
|
-
strict: true,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
const configFile = ts.readConfigFile(configPath, f => ts.sys.readFile(f));
|
|
72
|
-
if (configFile.error) {
|
|
73
|
-
throw new Error(ts.flattenDiagnosticMessageText(configFile.error.messageText, '\n'));
|
|
74
|
-
}
|
|
75
|
-
const parsed = ts.parseJsonConfigFileContent(configFile.config, ts.sys, dirname(configPath));
|
|
76
|
-
return parsed.options;
|
|
77
|
-
}
|
|
78
|
-
createHost() {
|
|
79
|
-
const baseHost = ts.createCompilerHost(this.compilerOptions);
|
|
80
|
-
const originalGetSourceFile = baseHost.getSourceFile.bind(baseHost);
|
|
81
|
-
return {
|
|
82
|
-
...baseHost,
|
|
83
|
-
getSourceFile: (fileName, languageVersion, onError, shouldCreateNewSourceFile) => {
|
|
84
|
-
const resolvedFileName = resolve(fileName);
|
|
85
|
-
// Return virtual content if we have transformed source
|
|
86
|
-
const virtualContent = this.sourceContents.get(resolvedFileName);
|
|
87
|
-
if (virtualContent !== undefined) {
|
|
88
|
-
// Check if we have a cached source file with the same content
|
|
89
|
-
const cached = this.sourceFileCache.get(resolvedFileName);
|
|
90
|
-
if (cached && cached.text === virtualContent) {
|
|
91
|
-
return cached;
|
|
92
|
-
}
|
|
93
|
-
// Create new source file from virtual content
|
|
94
|
-
const sourceFile = ts.createSourceFile(resolvedFileName, virtualContent, languageVersion, true);
|
|
95
|
-
this.sourceFileCache.set(resolvedFileName, sourceFile);
|
|
96
|
-
return sourceFile;
|
|
97
|
-
}
|
|
98
|
-
// Check cache for files loaded from disk
|
|
99
|
-
const cachedDisk = this.sourceFileCache.get(resolvedFileName);
|
|
100
|
-
if (cachedDisk) {
|
|
101
|
-
return cachedDisk;
|
|
102
|
-
}
|
|
103
|
-
// Load from disk and cache
|
|
104
|
-
const result = originalGetSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile);
|
|
105
|
-
if (result) {
|
|
106
|
-
this.sourceFileCache.set(resolvedFileName, result);
|
|
107
|
-
}
|
|
108
|
-
return result;
|
|
109
|
-
},
|
|
110
|
-
fileExists: fileName => {
|
|
111
|
-
const resolvedFileName = resolve(fileName);
|
|
112
|
-
return this.sourceContents.has(resolvedFileName) || baseHost.fileExists(fileName);
|
|
113
|
-
},
|
|
114
|
-
readFile: fileName => {
|
|
115
|
-
const resolvedFileName = resolve(fileName);
|
|
116
|
-
return this.sourceContents.get(resolvedFileName) ?? baseHost.readFile(fileName);
|
|
117
|
-
},
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
//# sourceMappingURL=program-manager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|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attern/).test(x) -> __regex_N.test(x)
|
|
5
|
-
* where __regex_N is a hoisted constant: const __regex_N = /pattern/;
|
|
6
|
-
*
|
|
7
|
-
* Due to typia's quirky AST structure where identifiers contain full expressions
|
|
8
|
-
* (e.g., identifier text is "RegExp(/pattern/).test"), we extract patterns from
|
|
9
|
-
* the identifier text directly.
|
|
10
|
-
*/
|
|
11
|
-
export declare function hoistRegexConstructors(sourceFile: ts.SourceFile, tsInstance: typeof ts, factory: ts.NodeFactory): ts.SourceFile;
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hoists RegExp constructor calls to top-level constants.
|
|
3
|
-
* Transforms: RegExp(/pattern/).test(x) -> __regex_N.test(x)
|
|
4
|
-
* where __regex_N is a hoisted constant: const __regex_N = /pattern/;
|
|
5
|
-
*
|
|
6
|
-
* Due to typia's quirky AST structure where identifiers contain full expressions
|
|
7
|
-
* (e.g., identifier text is "RegExp(/pattern/).test"), we extract patterns from
|
|
8
|
-
* the identifier text directly.
|
|
9
|
-
*/
|
|
10
|
-
export function hoistRegexConstructors(sourceFile, tsInstance, factory) {
|
|
11
|
-
const regexPatterns = new Map(); // full RegExp(...) -> variable name
|
|
12
|
-
let regexCounter = 0;
|
|
13
|
-
// Extract regex pattern from identifier text like "RegExp(/pattern/).test"
|
|
14
|
-
// The pattern can contain escaped characters and parentheses
|
|
15
|
-
function extractRegexFromIdText(idText) {
|
|
16
|
-
// Match RegExp(/.../) where the regex can contain any characters except unescaped /
|
|
17
|
-
// We look for RegExp( followed by / then find the matching closing / and )
|
|
18
|
-
if (!idText.startsWith('RegExp(/'))
|
|
19
|
-
return null;
|
|
20
|
-
let inCharClass = false;
|
|
21
|
-
let escaped = false;
|
|
22
|
-
// Start after "RegExp(/"
|
|
23
|
-
const start = 7; // "RegExp(/" = 7 chars, but we want to include the /
|
|
24
|
-
for (let i = 8; i < idText.length; i++) {
|
|
25
|
-
const char = idText[i];
|
|
26
|
-
if (escaped) {
|
|
27
|
-
escaped = false;
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
if (char === '\\') {
|
|
31
|
-
escaped = true;
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
if (char === '[' && !inCharClass) {
|
|
35
|
-
inCharClass = true;
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
if (char === ']' && inCharClass) {
|
|
39
|
-
inCharClass = false;
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
// End of regex pattern (unescaped /)
|
|
43
|
-
if (char === '/' && !inCharClass) {
|
|
44
|
-
// Check for flags after the /
|
|
45
|
-
let j = i + 1;
|
|
46
|
-
while (j < idText.length && /[gimsuy]/.test(idText[j])) {
|
|
47
|
-
j++;
|
|
48
|
-
}
|
|
49
|
-
// Should be followed by )
|
|
50
|
-
if (idText[j] === ')') {
|
|
51
|
-
return idText.substring(start, j); // Include /pattern/flags
|
|
52
|
-
}
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
// First pass: collect all unique RegExp patterns from identifier texts
|
|
59
|
-
// Only collect from inside __typical_* declarations (our generated code)
|
|
60
|
-
function collectRegexPatterns(node, insideTypical) {
|
|
61
|
-
// Check if we're entering a __typical_* variable declaration
|
|
62
|
-
let nowInsideTypical = insideTypical;
|
|
63
|
-
if (tsInstance.isVariableDeclaration(node)) {
|
|
64
|
-
const name = node.name;
|
|
65
|
-
if (tsInstance.isIdentifier(name)) {
|
|
66
|
-
const varName = name.escapedText;
|
|
67
|
-
if (process.env.DEBUG && sourceFile.fileName.includes('object-types')) {
|
|
68
|
-
console.log(`REGEX HOISTER: found var decl: ${varName.substring(0, 50)}`);
|
|
69
|
-
}
|
|
70
|
-
if (varName.startsWith('__typical_') || varName.startsWith('___typical_')) {
|
|
71
|
-
nowInsideTypical = true;
|
|
72
|
-
if (process.env.DEBUG) {
|
|
73
|
-
console.log(`REGEX HOISTER: entering __typical_ declaration: ${varName}`);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (nowInsideTypical && tsInstance.isIdentifier(node)) {
|
|
79
|
-
const idText = node.escapedText;
|
|
80
|
-
if (idText.startsWith('RegExp(')) {
|
|
81
|
-
if (process.env.DEBUG) {
|
|
82
|
-
console.log(`REGEX HOISTER: found RegExp identifier: ${idText.substring(0, 50)}...`);
|
|
83
|
-
}
|
|
84
|
-
const pattern = extractRegexFromIdText(idText);
|
|
85
|
-
if (pattern) {
|
|
86
|
-
const fullMatch = `RegExp(${pattern})`;
|
|
87
|
-
if (!regexPatterns.has(fullMatch)) {
|
|
88
|
-
regexPatterns.set(fullMatch, `__regex_${regexCounter++}`);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
node.forEachChild(child => collectRegexPatterns(child, nowInsideTypical));
|
|
94
|
-
}
|
|
95
|
-
collectRegexPatterns(sourceFile, false);
|
|
96
|
-
if (process.env.DEBUG) {
|
|
97
|
-
console.log(`REGEX HOISTER: ${sourceFile.fileName} - found ${regexPatterns.size} unique RegExp patterns`);
|
|
98
|
-
}
|
|
99
|
-
// No patterns found, return original
|
|
100
|
-
if (regexPatterns.size === 0) {
|
|
101
|
-
return sourceFile;
|
|
102
|
-
}
|
|
103
|
-
// Second pass: replace identifiers that start with RegExp(...)
|
|
104
|
-
function replaceRegexIdentifiers(node) {
|
|
105
|
-
if (tsInstance.isIdentifier(node)) {
|
|
106
|
-
const idText = node.escapedText;
|
|
107
|
-
if (idText.startsWith('RegExp(')) {
|
|
108
|
-
const pattern = extractRegexFromIdText(idText);
|
|
109
|
-
if (pattern) {
|
|
110
|
-
const fullMatch = `RegExp(${pattern})`;
|
|
111
|
-
const varName = regexPatterns.get(fullMatch);
|
|
112
|
-
if (varName) {
|
|
113
|
-
// Replace "RegExp(/pattern/).test" with "__regex_N.test"
|
|
114
|
-
const newIdText = idText.replace(fullMatch, varName);
|
|
115
|
-
return factory.createIdentifier(newIdText);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return tsInstance.visitEachChild(node, replaceRegexIdentifiers, undefined);
|
|
121
|
-
}
|
|
122
|
-
// Create hoisted const declarations for each unique regex
|
|
123
|
-
const hoistedDeclarations = [];
|
|
124
|
-
for (const [fullMatch, varName] of regexPatterns) {
|
|
125
|
-
// Extract regex literal from "RegExp(/pattern/)"
|
|
126
|
-
const regexLiteral = fullMatch.slice(7, -1); // Remove "RegExp(" and ")"
|
|
127
|
-
const constDecl = factory.createVariableStatement(undefined, factory.createVariableDeclarationList([factory.createVariableDeclaration(factory.createIdentifier(varName), undefined, undefined, factory.createRegularExpressionLiteral(regexLiteral))], tsInstance.NodeFlags.Const));
|
|
128
|
-
hoistedDeclarations.push(constDecl);
|
|
129
|
-
}
|
|
130
|
-
// Transform all statements (replacing RegExp identifiers)
|
|
131
|
-
const transformedStatements = [];
|
|
132
|
-
for (const stmt of sourceFile.statements) {
|
|
133
|
-
const transformed = replaceRegexIdentifiers(stmt);
|
|
134
|
-
transformedStatements.push(transformed);
|
|
135
|
-
}
|
|
136
|
-
// Find insertion point: after imports but before other code
|
|
137
|
-
let insertIndex = 0;
|
|
138
|
-
for (let i = 0; i < transformedStatements.length; i++) {
|
|
139
|
-
if (tsInstance.isImportDeclaration(transformedStatements[i])) {
|
|
140
|
-
insertIndex = i + 1;
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
break;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
// Insert hoisted declarations after imports
|
|
147
|
-
const finalStatements = [...transformedStatements.slice(0, insertIndex), ...hoistedDeclarations, ...transformedStatements.slice(insertIndex)];
|
|
148
|
-
return factory.updateSourceFile(sourceFile, finalStatements, sourceFile.isDeclarationFile, sourceFile.referencedFiles, sourceFile.typeReferenceDirectives, sourceFile.hasNoDefaultLib, sourceFile.libReferenceDirectives);
|
|
149
|
-
}
|
|
150
|
-
//# sourceMappingURL=regex-hoister.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"regex-hoister.js","sourceRoot":"","sources":["../../src/regex-hoister.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,UAAU,sBAAsB,CAAC,UAAyB,EAAE,UAAqB,EAAE,OAAuB;IAC9G,MAAM,aAAa,GAAG,IAAI,GAAG,EAAkB,CAAA,CAAC,oCAAoC;IACpF,IAAI,YAAY,GAAG,CAAC,CAAA;IAEpB,2EAA2E;IAC3E,6DAA6D;IAC7D,SAAS,sBAAsB,CAAC,MAAc;QAC5C,oFAAoF;QACpF,2EAA2E;QAC3E,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC;YAAE,OAAO,IAAI,CAAA;QAE/C,IAAI,WAAW,GAAG,KAAK,CAAA;QACvB,IAAI,OAAO,GAAG,KAAK,CAAA;QAEnB,yBAAyB;QACzB,MAAM,KAAK,GAAG,CAAC,CAAA,CAAC,qDAAqD;QAErE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACvC,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,CAAA;YAEtB,IAAI,OAAO,EAAE,CAAC;gBACZ,OAAO,GAAG,KAAK,CAAA;gBACf,SAAQ;YACV,CAAC;YAED,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;gBAClB,OAAO,GAAG,IAAI,CAAA;gBACd,SAAQ;YACV,CAAC;YAED,IAAI,IAAI,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;gBACjC,WAAW,GAAG,IAAI,CAAA;gBAClB,SAAQ;YACV,CAAC;YAED,IAAI,IAAI,KAAK,GAAG,IAAI,WAAW,EAAE,CAAC;gBAChC,WAAW,GAAG,KAAK,CAAA;gBACnB,SAAQ;YACV,CAAC;Y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
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export function setupTsProgram(tsInstance) {
|
|
2
|
-
// Find tsconfig.json
|
|
3
|
-
const tsConfigPath = tsInstance.findConfigFile(process.cwd(), f => tsInstance.sys.fileExists(f), 'tsconfig.json');
|
|
4
|
-
if (!tsConfigPath) {
|
|
5
|
-
throw new Error('Could not find tsconfig.json');
|
|
6
|
-
}
|
|
7
|
-
if (process.env.DEBUG) {
|
|
8
|
-
console.log(`SETUP: Using tsconfig at ${tsConfigPath}`);
|
|
9
|
-
}
|
|
10
|
-
// Load and parse tsconfig.json
|
|
11
|
-
const configFile = tsInstance.readConfigFile(tsConfigPath, f => tsInstance.sys.readFile(f));
|
|
12
|
-
const parsedConfig = tsInstance.parseJsonConfigFileContent(configFile.config, tsInstance.sys, process.cwd());
|
|
13
|
-
if (process.env.DEBUG) {
|
|
14
|
-
console.log(`SETUP: Parsed tsconfig with ${parsedConfig.fileNames.length} files`);
|
|
15
|
-
}
|
|
16
|
-
// Create the TypeScript program with all project files
|
|
17
|
-
const tsProgram = tsInstance.createProgram(parsedConfig.fileNames, parsedConfig.options);
|
|
18
|
-
return tsProgram;
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=setup.js.map
|
package/dist/src/setup.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/setup.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,cAAc,CAAC,UAAqB;IAClD,qBAAqB;IACrB,MAAM,YAAY,GAAG,UAAU,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,eAAe,CAAC,CAAA;IACjH,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;IACjD,CAAC;IAED,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;QACtB,OAAO,CAAC,GAAG,CAAC,4BAA4B,YAAY,EAAE,CAAC,CAAA;IACzD,CAAC;IAED,+BAA+B;IAC/B,MAAM,UAAU,GAAG,UAAU,CAAC,cAAc,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAA;IAC3F,MAAM,YAAY,GAAG,UAAU,CAAC,0BAA0B,CAAC,UAAU,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;IAE5G,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;QACtB,OAAO,CAAC,GAAG,CAAC,+BAA+B,YAAY,CAAC,SAAS,CAAC,MAAM,QAAQ,CAAC,CAAA;IACnF,CAAC;IAED,uDAAuD;IACvD,MAAM,SAAS,GAAG,UAAU,CAAC,aAAa,CAAC,YAAY,CAAC,SAAS,EAAE,YAAY,CAAC,OAAO,CAAC,CAAA;IAExF,OAAO,SAAS,CAAA;AAClB,CAAC"}
|
package/dist/src/source-map.d.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import MagicString from 'magic-string';
|
|
2
|
-
import type { DecodedSourceMap, EncodedSourceMap } from '@ampproject/remapping';
|
|
3
|
-
/**
|
|
4
|
-
* Result of a transformation that includes source map information.
|
|
5
|
-
*/
|
|
6
|
-
export interface TransformResult {
|
|
7
|
-
code: string;
|
|
8
|
-
map: EncodedSourceMap | null;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Configuration options for source map generation.
|
|
12
|
-
*/
|
|
13
|
-
export interface SourceMapOptions {
|
|
14
|
-
/** Generate source maps. Default: true */
|
|
15
|
-
enabled?: boolean;
|
|
16
|
-
/** Include source content in map. Default: true */
|
|
17
|
-
includeContent?: boolean;
|
|
18
|
-
/** Use inline source maps (data URL). Default: false */
|
|
19
|
-
inline?: boolean;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Default source map options.
|
|
23
|
-
*/
|
|
24
|
-
export declare const defaultSourceMapOptions: Required<SourceMapOptions>;
|
|
25
|
-
/**
|
|
26
|
-
* Compose multiple source maps together.
|
|
27
|
-
* Given maps [A->B, B->C], produces A->C.
|
|
28
|
-
* Maps are applied in order: first map is closest to original source.
|
|
29
|
-
*/
|
|
30
|
-
export declare function composeSourceMaps(maps: (EncodedSourceMap | DecodedSourceMap | string | null | undefined)[], _originalFileName: string): EncodedSourceMap | null;
|
|
31
|
-
/**
|
|
32
|
-
* Generate an inline source map comment (data URL).
|
|
33
|
-
*/
|
|
34
|
-
export declare function inlineSourceMapComment(map: EncodedSourceMap | string): string;
|
|
35
|
-
/**
|
|
36
|
-
* Generate an external source map URL comment.
|
|
37
|
-
*/
|
|
38
|
-
export declare function externalSourceMapComment(mapFileName: string): string;
|
|
39
|
-
/**
|
|
40
|
-
* Create a MagicString instance for tracking source modifications.
|
|
41
|
-
*/
|
|
42
|
-
export declare function createMagicString(source: string, filename?: string): MagicString;
|
|
43
|
-
/**
|
|
44
|
-
* Generate a source map from a MagicString instance.
|
|
45
|
-
*/
|
|
46
|
-
export declare function generateSourceMap(ms: MagicString, options: {
|
|
47
|
-
source: string;
|
|
48
|
-
file?: string;
|
|
49
|
-
includeContent?: boolean;
|
|
50
|
-
hires?: boolean | 'boundary';
|
|
51
|
-
}): EncodedSourceMap;
|
|
52
|
-
/**
|
|
53
|
-
* Create an identity source map (maps each position to itself).
|
|
54
|
-
* Useful as a placeholder when no transformation occurred.
|
|
55
|
-
*/
|
|
56
|
-
export declare function createIdentityMap(source: string, fileName: string, includeContent?: boolean): EncodedSourceMap;
|
|
57
|
-
/**
|
|
58
|
-
* Represents a tracked modification to source code.
|
|
59
|
-
*/
|
|
60
|
-
export interface SourceModification {
|
|
61
|
-
/** Start position in original source */
|
|
62
|
-
start: number;
|
|
63
|
-
/** End position in original source */
|
|
64
|
-
end: number;
|
|
65
|
-
/** The replacement text */
|
|
66
|
-
replacement: string;
|
|
67
|
-
/** Type of modification */
|
|
68
|
-
type: 'insert-before' | 'insert-after' | 'replace' | 'prepend' | 'append';
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Apply a list of modifications to source code using MagicString.
|
|
72
|
-
* Returns the modified code and source map.
|
|
73
|
-
*/
|
|
74
|
-
export declare function applyModifications(source: string, fileName: string, modifications: SourceModification[], includeContent?: boolean): TransformResult;
|
|
75
|
-
/**
|
|
76
|
-
* Strip any existing source map comments from code.
|
|
77
|
-
*/
|
|
78
|
-
export declare function stripSourceMapComment(code: string): string;
|
package/dist/src/source-map.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import MagicString from 'magic-string';
|
|
2
|
-
import remapping from '@ampproject/remapping';
|
|
3
|
-
/**
|
|
4
|
-
* Default source map options.
|
|
5
|
-
*/
|
|
6
|
-
export const defaultSourceMapOptions = {
|
|
7
|
-
enabled: true,
|
|
8
|
-
includeContent: true,
|
|
9
|
-
inline: false,
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Compose multiple source maps together.
|
|
13
|
-
* Given maps [A->B, B->C], produces A->C.
|
|
14
|
-
* Maps are applied in order: first map is closest to original source.
|
|
15
|
-
*/
|
|
16
|
-
export function composeSourceMaps(maps, _originalFileName) {
|
|
17
|
-
// Filter out null/undefined maps
|
|
18
|
-
const validMaps = maps.filter((m) => m !== null && m !== undefined);
|
|
19
|
-
if (validMaps.length === 0)
|
|
20
|
-
return null;
|
|
21
|
-
if (validMaps.length === 1) {
|
|
22
|
-
const map = validMaps[0];
|
|
23
|
-
if (typeof map === 'string') {
|
|
24
|
-
return JSON.parse(map);
|
|
25
|
-
}
|
|
26
|
-
return map;
|
|
27
|
-
}
|
|
28
|
-
// remapping expects maps in reverse order (final output first)
|
|
29
|
-
// and a loader function that returns the source map for a given file
|
|
30
|
-
const reversedMaps = [...validMaps].reverse();
|
|
31
|
-
try {
|
|
32
|
-
const result = remapping(reversedMaps, () => null);
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
35
|
-
catch (e) {
|
|
36
|
-
// If remapping fails, return the last valid map
|
|
37
|
-
console.warn('Source map composition failed:', e);
|
|
38
|
-
const lastMap = validMaps[validMaps.length - 1];
|
|
39
|
-
if (typeof lastMap === 'string') {
|
|
40
|
-
return JSON.parse(lastMap);
|
|
41
|
-
}
|
|
42
|
-
return lastMap;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Generate an inline source map comment (data URL).
|
|
47
|
-
*/
|
|
48
|
-
export function inlineSourceMapComment(map) {
|
|
49
|
-
const mapString = typeof map === 'string' ? map : JSON.stringify(map);
|
|
50
|
-
const base64 = Buffer.from(mapString).toString('base64');
|
|
51
|
-
return `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64}`;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Generate an external source map URL comment.
|
|
55
|
-
*/
|
|
56
|
-
export function externalSourceMapComment(mapFileName) {
|
|
57
|
-
return `//# sourceMappingURL=${mapFileName}`;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Create a MagicString instance for tracking source modifications.
|
|
61
|
-
*/
|
|
62
|
-
export function createMagicString(source, filename) {
|
|
63
|
-
return new MagicString(source, {
|
|
64
|
-
filename,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Generate a source map from a MagicString instance.
|
|
69
|
-
*/
|
|
70
|
-
export function generateSourceMap(ms, options) {
|
|
71
|
-
return ms.generateMap({
|
|
72
|
-
source: options.source,
|
|
73
|
-
file: options.file ?? options.source,
|
|
74
|
-
includeContent: options.includeContent ?? true,
|
|
75
|
-
hires: options.hires ?? true,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Create an identity source map (maps each position to itself).
|
|
80
|
-
* Useful as a placeholder when no transformation occurred.
|
|
81
|
-
*/
|
|
82
|
-
export function createIdentityMap(source, fileName, includeContent = true) {
|
|
83
|
-
const ms = new MagicString(source);
|
|
84
|
-
return ms.generateMap({
|
|
85
|
-
source: fileName,
|
|
86
|
-
file: fileName,
|
|
87
|
-
includeContent,
|
|
88
|
-
hires: true,
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Apply a list of modifications to source code using MagicString.
|
|
93
|
-
* Returns the modified code and source map.
|
|
94
|
-
*/
|
|
95
|
-
export function applyModifications(source, fileName, modifications, includeContent = true) {
|
|
96
|
-
const ms = createMagicString(source, fileName);
|
|
97
|
-
// Sort modifications by position (descending) to apply from end to start
|
|
98
|
-
// This prevents position shifts from affecting subsequent modifications
|
|
99
|
-
const sorted = [...modifications].sort((a, b) => b.start - a.start);
|
|
100
|
-
for (const mod of sorted) {
|
|
101
|
-
switch (mod.type) {
|
|
102
|
-
case 'insert-before':
|
|
103
|
-
ms.prependLeft(mod.start, mod.replacement);
|
|
104
|
-
break;
|
|
105
|
-
case 'insert-after':
|
|
106
|
-
ms.appendRight(mod.end, mod.replacement);
|
|
107
|
-
break;
|
|
108
|
-
case 'replace':
|
|
109
|
-
ms.overwrite(mod.start, mod.end, mod.replacement);
|
|
110
|
-
break;
|
|
111
|
-
case 'prepend':
|
|
112
|
-
ms.prepend(mod.replacement);
|
|
113
|
-
break;
|
|
114
|
-
case 'append':
|
|
115
|
-
ms.append(mod.replacement);
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return {
|
|
120
|
-
code: ms.toString(),
|
|
121
|
-
map: generateSourceMap(ms, {
|
|
122
|
-
source: fileName,
|
|
123
|
-
includeContent,
|
|
124
|
-
}),
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Strip any existing source map comments from code.
|
|
129
|
-
*/
|
|
130
|
-
export function stripSourceMapComment(code) {
|
|
131
|
-
return code.replace(/\/\/[#@]\s*sourceMappingURL=.*/g, '');
|
|
132
|
-
}
|
|
133
|
-
//# sourceMappingURL=source-map.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"source-map.js","sourceRoot":"","sources":["../../src/source-map.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,cAAc,CAAA;AACtC,OAAO,SAAS,MAAM,uBAAuB,CAAA;AAuB7C;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAA+B;IACjE,OAAO,EAAE,IAAI;IACb,cAAc,EAAE,IAAI;IACpB,MAAM,EAAE,KAAK;CACd,CAAA;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAyE,EAAE,iBAAyB;IACpI,iCAAiC;IACjC,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAqD,EAAE,CAAC,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,SAAS,CAAC,CAAA;IAEtH,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IACvC,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,MAAM,GAAG,GAAG,SAAS,CAAC,CAAC,CAAC,CAAA;QACxB,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAqB,CAAA;QAC5C,CAAC;QACD,OAAO,GAAuB,CAAA;IAChC,CAAC;IAED,+DAA+D;IAC/D,qEAAqE;IACrE,MAAM,YAAY,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC,OAAO,EAAE,CAAA;IAE7C,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,SAAS,CAAC,YAAY,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,CAAA;QAClD,OAAO,MAA0B,CAAA;IACnC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,gDAAgD;QAChD,OAAO,CA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