@scenetest/vite-plugin 0.0.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/LICENSE +21 -0
- package/dist/__tests__/strip.test.d.ts +2 -0
- package/dist/__tests__/strip.test.d.ts.map +1 -0
- package/dist/__tests__/strip.test.js +434 -0
- package/dist/__tests__/strip.test.js.map +1 -0
- package/dist/config.d.ts +33 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +71 -0
- package/dist/config.js.map +1 -0
- package/dist/dev-panel.generated.d.ts +9 -0
- package/dist/dev-panel.generated.d.ts.map +1 -0
- package/dist/dev-panel.generated.js +9 -0
- package/dist/dev-panel.generated.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +137 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware.d.ts +14 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +121 -0
- package/dist/middleware.js.map +1 -0
- package/dist/strip.d.ts +26 -0
- package/dist/strip.d.ts.map +1 -0
- package/dist/strip.js +195 -0
- package/dist/strip.js.map +1 -0
- package/dist/transform.d.ts +52 -0
- package/dist/transform.d.ts.map +1 -0
- package/dist/transform.js +477 -0
- package/dist/transform.js.map +1 -0
- package/dist/virtual-module.d.ts +36 -0
- package/dist/virtual-module.d.ts.map +1 -0
- package/dist/virtual-module.js +72 -0
- package/dist/virtual-module.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strip.d.ts","sourceRoot":"","sources":["../src/strip.ts"],"names":[],"mappings":"AAGA,OAAO,WAAW,MAAM,cAAc,CAAA;AAKtC,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,GAAG,IAAI,CAAA;CACnD;AAED,MAAM,WAAW,YAAY;IAC3B,0CAA0C;IAC1C,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,+BAA+B;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAkBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,WAAW,GAAG,IAAI,CA6K3F"}
|
package/dist/strip.js
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { parse } from '@babel/parser';
|
|
2
|
+
import _traverse from '@babel/traverse';
|
|
3
|
+
import * as t from '@babel/types';
|
|
4
|
+
import MagicString from 'magic-string';
|
|
5
|
+
// Handle ESM/CJS interop for @babel/traverse
|
|
6
|
+
const traverse = (typeof _traverse === 'function' ? _traverse : _traverse.default);
|
|
7
|
+
// All scenetest packages that should be stripped
|
|
8
|
+
const SCENETEST_PACKAGES = [
|
|
9
|
+
'@scenetest/core',
|
|
10
|
+
'@scenetest/react',
|
|
11
|
+
'@scenetest/vue',
|
|
12
|
+
'@scenetest/solid',
|
|
13
|
+
'@scenetest/svelte',
|
|
14
|
+
];
|
|
15
|
+
/**
|
|
16
|
+
* Check if a module source is a scenetest package
|
|
17
|
+
*/
|
|
18
|
+
function isScenetestPackage(source) {
|
|
19
|
+
return SCENETEST_PACKAGES.includes(source);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Strip all scenetest imports and function calls from source code.
|
|
23
|
+
*
|
|
24
|
+
* This function:
|
|
25
|
+
* 1. Parses the code with Babel (handles JS, TS, JSX)
|
|
26
|
+
* 2. Finds and tracks all imports from scenetest packages
|
|
27
|
+
* 3. Removes those import statements
|
|
28
|
+
* 4. Removes all calls to the imported functions
|
|
29
|
+
*
|
|
30
|
+
* @param code Source code to transform
|
|
31
|
+
* @param options Transform options
|
|
32
|
+
* @returns Transformed code and optional source map
|
|
33
|
+
*/
|
|
34
|
+
export function stripScenetest(code, options = {}) {
|
|
35
|
+
const { sourceMap = true, filename = 'unknown.js' } = options;
|
|
36
|
+
// Quick check - if no scenetest import, skip parsing
|
|
37
|
+
if (!code.includes('scenetest')) {
|
|
38
|
+
return null; // This catches all scenetest-* packages too
|
|
39
|
+
}
|
|
40
|
+
// Track imported names from scenetest
|
|
41
|
+
// Map from local name → imported name (handles aliases)
|
|
42
|
+
const scenetestImports = new Map();
|
|
43
|
+
// Parse with Babel
|
|
44
|
+
const parserOptions = {
|
|
45
|
+
sourceType: 'module',
|
|
46
|
+
plugins: [
|
|
47
|
+
'jsx',
|
|
48
|
+
'typescript',
|
|
49
|
+
// Support modern syntax
|
|
50
|
+
'decorators',
|
|
51
|
+
'classProperties',
|
|
52
|
+
'classPrivateProperties',
|
|
53
|
+
'classPrivateMethods',
|
|
54
|
+
'dynamicImport',
|
|
55
|
+
'nullishCoalescingOperator',
|
|
56
|
+
'optionalChaining',
|
|
57
|
+
],
|
|
58
|
+
};
|
|
59
|
+
let ast;
|
|
60
|
+
try {
|
|
61
|
+
ast = parse(code, parserOptions);
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
// If parsing fails, return null (don't transform)
|
|
65
|
+
console.warn(`[vite-plugin-scenetest] Failed to parse ${filename}:`, e);
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
const s = new MagicString(code);
|
|
69
|
+
let hasChanges = false;
|
|
70
|
+
// Ranges to remove (we collect them first, then remove to avoid index shifting issues)
|
|
71
|
+
const rangesToRemove = [];
|
|
72
|
+
traverse(ast, {
|
|
73
|
+
// Collect scenetest package imports and mark for removal
|
|
74
|
+
ImportDeclaration(path) {
|
|
75
|
+
const source = path.node.source.value;
|
|
76
|
+
if (!isScenetestPackage(source)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
// Track all imported names
|
|
80
|
+
for (const specifier of path.node.specifiers) {
|
|
81
|
+
if (t.isImportSpecifier(specifier)) {
|
|
82
|
+
const imported = t.isIdentifier(specifier.imported)
|
|
83
|
+
? specifier.imported.name
|
|
84
|
+
: specifier.imported.value;
|
|
85
|
+
const local = specifier.local.name;
|
|
86
|
+
scenetestImports.set(local, imported);
|
|
87
|
+
}
|
|
88
|
+
else if (t.isImportDefaultSpecifier(specifier)) {
|
|
89
|
+
// import scenetest from 'scenetest' - unlikely but handle it
|
|
90
|
+
scenetestImports.set(specifier.local.name, 'default');
|
|
91
|
+
}
|
|
92
|
+
else if (t.isImportNamespaceSpecifier(specifier)) {
|
|
93
|
+
// import * as scenetest from 'scenetest' - track namespace
|
|
94
|
+
scenetestImports.set(specifier.local.name, '*');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// Mark entire import for removal
|
|
98
|
+
const start = path.node.start;
|
|
99
|
+
const end = path.node.end;
|
|
100
|
+
rangesToRemove.push({ start, end, type: 'import' });
|
|
101
|
+
hasChanges = true;
|
|
102
|
+
},
|
|
103
|
+
// Remove function calls to imported scenetest functions
|
|
104
|
+
CallExpression(path) {
|
|
105
|
+
const callee = path.node.callee;
|
|
106
|
+
let isScenetestCall = false;
|
|
107
|
+
// Functions to strip (from all framework packages)
|
|
108
|
+
const strippableFunctions = [
|
|
109
|
+
'should',
|
|
110
|
+
'failed',
|
|
111
|
+
'assert',
|
|
112
|
+
'match',
|
|
113
|
+
'useAssert', // React, Vue
|
|
114
|
+
'createAssert', // Solid
|
|
115
|
+
'runAssert', // Svelte
|
|
116
|
+
];
|
|
117
|
+
// Direct call: should(...), failed(...), assert(...), useAssert(...)
|
|
118
|
+
if (t.isIdentifier(callee)) {
|
|
119
|
+
if (scenetestImports.has(callee.name)) {
|
|
120
|
+
const imported = scenetestImports.get(callee.name);
|
|
121
|
+
if (imported && strippableFunctions.includes(imported)) {
|
|
122
|
+
isScenetestCall = true;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// Member call: scenetest.should(...) (namespace import)
|
|
127
|
+
else if (t.isMemberExpression(callee) && t.isIdentifier(callee.object)) {
|
|
128
|
+
const objectName = callee.object.name;
|
|
129
|
+
if (scenetestImports.get(objectName) === '*') {
|
|
130
|
+
if (t.isIdentifier(callee.property)) {
|
|
131
|
+
const propName = callee.property.name;
|
|
132
|
+
if (strippableFunctions.includes(propName)) {
|
|
133
|
+
isScenetestCall = true;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (!isScenetestCall) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
// Check if this call is an ExpressionStatement (standalone call)
|
|
142
|
+
const parent = path.parentPath;
|
|
143
|
+
if (parent && t.isExpressionStatement(parent.node)) {
|
|
144
|
+
// Remove the entire statement
|
|
145
|
+
const start = parent.node.start;
|
|
146
|
+
const end = parent.node.end;
|
|
147
|
+
rangesToRemove.push({ start, end, type: 'statement' });
|
|
148
|
+
hasChanges = true;
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
// Call is in an expression context - replace with void 0
|
|
152
|
+
// This is unusual for should/failed since they return void, but handle defensively
|
|
153
|
+
const start = path.node.start;
|
|
154
|
+
const end = path.node.end;
|
|
155
|
+
rangesToRemove.push({ start, end, type: 'expression' });
|
|
156
|
+
hasChanges = true;
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
if (!hasChanges) {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
// Sort ranges by start position (descending) to process from end to start
|
|
164
|
+
// This prevents index shifting issues
|
|
165
|
+
rangesToRemove.sort((a, b) => b.start - a.start);
|
|
166
|
+
for (const range of rangesToRemove) {
|
|
167
|
+
if (range.type === 'expression') {
|
|
168
|
+
// Replace with void 0 to maintain expression validity
|
|
169
|
+
s.overwrite(range.start, range.end, 'void 0');
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
// For imports and statements, remove entirely
|
|
173
|
+
// Also try to remove trailing newline for cleaner output
|
|
174
|
+
let end = range.end;
|
|
175
|
+
if (code[end] === '\n') {
|
|
176
|
+
end++;
|
|
177
|
+
}
|
|
178
|
+
else if (code[end] === '\r' && code[end + 1] === '\n') {
|
|
179
|
+
end += 2;
|
|
180
|
+
}
|
|
181
|
+
s.remove(range.start, end);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
code: s.toString(),
|
|
186
|
+
map: sourceMap
|
|
187
|
+
? s.generateMap({
|
|
188
|
+
source: filename,
|
|
189
|
+
file: filename,
|
|
190
|
+
includeContent: true,
|
|
191
|
+
})
|
|
192
|
+
: null,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=strip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strip.js","sourceRoot":"","sources":["../src/strip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAsB,MAAM,eAAe,CAAA;AACzD,OAAO,SAA4B,MAAM,iBAAiB,CAAA;AAC1D,OAAO,KAAK,CAAC,MAAM,cAAc,CAAA;AACjC,OAAO,WAAW,MAAM,cAAc,CAAA;AAEtC,6CAA6C;AAC7C,MAAM,QAAQ,GAAG,CAAC,OAAO,SAAS,KAAK,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAE,SAAiB,CAAC,OAAO,CAAqB,CAAA;AAc/G,iDAAiD;AACjD,MAAM,kBAAkB,GAAG;IACzB,iBAAiB;IACjB,kBAAkB;IAClB,gBAAgB;IAChB,kBAAkB;IAClB,mBAAmB;CACpB,CAAA;AAED;;GAEG;AACH,SAAS,kBAAkB,CAAC,MAAc;IACxC,OAAO,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;AAC5C,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,UAAwB,EAAE;IACrE,MAAM,EAAE,SAAS,GAAG,IAAI,EAAE,QAAQ,GAAG,YAAY,EAAE,GAAG,OAAO,CAAA;IAE7D,qDAAqD;IACrD,IAAI,CAAC,IAAI,CAAC,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C,KAAK,IAAI,IAAI,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;gBACxD,GAAG,IAAI,CAAC,CAAA;YACV,CAAC;YACD,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;QAC5B,CAAC;IACH,CAAC;IAED,OAAO;QACL,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE;QAClB,GAAG,EAAE,SAAS;YACZ,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;gBACZ,MAAM,EAAE,QAAQ;gBAChB,IAAI,EAAE,QAAQ;gBACd,cAAc,EAAE,IAAI;aACrB,CAAC;YACJ,CAAC,CAAC,IAAI;KACT,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import MagicString from 'magic-string';
|
|
2
|
+
/**
|
|
3
|
+
* Extracted assertion from an assert() or useAssert() call
|
|
4
|
+
*/
|
|
5
|
+
export interface ExtractedAssertion {
|
|
6
|
+
/** Unique identifier (filename:line:col:key?) */
|
|
7
|
+
id: string;
|
|
8
|
+
/** Human-readable title from the config */
|
|
9
|
+
title: string;
|
|
10
|
+
/** Optional key for disambiguation */
|
|
11
|
+
key?: string;
|
|
12
|
+
/** The serverFn body code (without function wrapper) */
|
|
13
|
+
serverFnBodyCode: string;
|
|
14
|
+
/** Source location */
|
|
15
|
+
location: {
|
|
16
|
+
file: string;
|
|
17
|
+
line: number;
|
|
18
|
+
column: number;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export interface TransformResult {
|
|
22
|
+
/** Transformed code */
|
|
23
|
+
code: string;
|
|
24
|
+
/** Source map */
|
|
25
|
+
map: ReturnType<MagicString['generateMap']> | null;
|
|
26
|
+
/** Extracted assertions */
|
|
27
|
+
extractedAssertions: ExtractedAssertion[];
|
|
28
|
+
}
|
|
29
|
+
export interface TransformOptions {
|
|
30
|
+
/** Generate source map (default: true) */
|
|
31
|
+
sourceMap?: boolean;
|
|
32
|
+
/** File path for source map and assertion IDs */
|
|
33
|
+
filename?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Transform assert() and useAssert() calls in source code.
|
|
37
|
+
*
|
|
38
|
+
* For assert() calls:
|
|
39
|
+
* 1. Extract the serverFn to be run on the server
|
|
40
|
+
* 2. Replace the call with __scenetest_rpc({ id, title, key?, withData })
|
|
41
|
+
*
|
|
42
|
+
* For useAssert() calls:
|
|
43
|
+
* 1. Extract the serverFn from the config object
|
|
44
|
+
* 2. Replace serverFn property with __assertionId
|
|
45
|
+
* 3. Replace useAssert with __useAssert
|
|
46
|
+
*
|
|
47
|
+
* @param code Source code to transform
|
|
48
|
+
* @param options Transform options
|
|
49
|
+
* @returns Transformed code, source map, and extracted assertions
|
|
50
|
+
*/
|
|
51
|
+
export declare function transformAssertions(code: string, options?: TransformOptions): TransformResult | null;
|
|
52
|
+
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":"AAGA,OAAO,WAAW,MAAM,cAAc,CAAA;AAKtC;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,iDAAiD;IACjD,EAAE,EAAE,MAAM,CAAA;IACV,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAA;IACb,sCAAsC;IACtC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,wDAAwD;IACxD,gBAAgB,EAAE,MAAM,CAAA;IACxB,sBAAsB;IACtB,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAA;QACZ,IAAI,EAAE,MAAM,CAAA;QACZ,MAAM,EAAE,MAAM,CAAA;KACf,CAAA;CACF;AAED,MAAM,WAAW,eAAe;IAC9B,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,iBAAiB;IACjB,GAAG,EAAE,UAAU,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,GAAG,IAAI,CAAA;IAClD,2BAA2B;IAC3B,mBAAmB,EAAE,kBAAkB,EAAE,CAAA;CAC1C;AAED,MAAM,WAAW,gBAAgB;IAC/B,0CAA0C;IAC1C,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,iDAAiD;IACjD,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAyDD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,eAAe,GAAG,IAAI,CAudxG"}
|