@saywright/vite 0.0.0-stage → 0.1.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/LICENSE +201 -0
- package/README.md +74 -2
- package/dist/bridge.js +6582 -0
- package/dist/index.js +478 -0
- package/dist/protocol.d.ts +667 -0
- package/dist/protocol.js +64 -0
- package/package.json +65 -4
- package/types/index.d.ts +18 -0
package/dist/protocol.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
//#region src/protocol.ts
|
|
2
|
+
/**
|
|
3
|
+
* Message protocol between the Saywright studio (parent window) and the
|
|
4
|
+
* bridge running inside the target app (iframe). Both sides check `ns` and the
|
|
5
|
+
* message source before trusting anything.
|
|
6
|
+
*/
|
|
7
|
+
var NS = "saywright";
|
|
8
|
+
/**
|
|
9
|
+
* The plugin in an app and the studio are updated separately, so each side
|
|
10
|
+
* says which version of this protocol it speaks (`v`, in hello and ready) and
|
|
11
|
+
* the oldest of the other side's it still works with (`oldest`). Raise
|
|
12
|
+
* PROTOCOL_VERSION when a message changes in a way an older side can't follow,
|
|
13
|
+
* and OLDEST_PROTOCOL when this side stops understanding an older one; adding
|
|
14
|
+
* a message or an optional field needs neither (unknown ones are ignored).
|
|
15
|
+
*/
|
|
16
|
+
var PROTOCOL_VERSION = 1;
|
|
17
|
+
var OLDEST_PROTOCOL = 1;
|
|
18
|
+
/** Which side has to be updated for a studio and an app's bridge to work together: the app's plugin, the studio, or neither. */
|
|
19
|
+
function outdated(studio, bridge) {
|
|
20
|
+
if (bridge.v < (studio.oldest ?? studio.v)) return "plugin";
|
|
21
|
+
if (studio.v < (bridge.oldest ?? bridge.v)) return "studio";
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
/** Where the studio runs unless told otherwise. Not 5173: that is Vite's own default, where your app likely runs. */
|
|
25
|
+
var STUDIO_PORT = 7357;
|
|
26
|
+
var STUDIO_URL = `http://localhost:${STUDIO_PORT}`;
|
|
27
|
+
/** Attribute names injected by the Vite plugin at compile time. */
|
|
28
|
+
var SRC_ATTR = "data-ds-src";
|
|
29
|
+
var NAME_ATTR = "data-ds-name";
|
|
30
|
+
function isStudioMessage(data) {
|
|
31
|
+
return !!data && typeof data === "object" && data.ns === "saywright" && typeof data.type === "string";
|
|
32
|
+
}
|
|
33
|
+
var JS_ESCAPES = {
|
|
34
|
+
"\\": "\\\\",
|
|
35
|
+
"'": "\\'",
|
|
36
|
+
"\n": "\\n",
|
|
37
|
+
"\r": "\\r",
|
|
38
|
+
"\u2028": "\\u2028",
|
|
39
|
+
"\u2029": "\\u2029"
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Text from a page as a single-quoted JavaScript string, for the locators and
|
|
43
|
+
* tests Saywright writes: quotes, backslashes and every kind of line break are
|
|
44
|
+
* escaped, so no text can end the string or the line it is on.
|
|
45
|
+
*/
|
|
46
|
+
function jsString(s) {
|
|
47
|
+
return `'${s.replace(/[\\'\n\r\u2028\u2029]/g, (c) => JS_ESCAPES[c])}'`;
|
|
48
|
+
}
|
|
49
|
+
/** Text from a page in a `//` comment: on one line, whatever line breaks it had. */
|
|
50
|
+
function jsComment(s) {
|
|
51
|
+
return s.replace(/[\r\n\u2028\u2029]+/g, " ");
|
|
52
|
+
}
|
|
53
|
+
/** Parse "path/to/File.tsx:12:5" into parts. Paths may contain colons on Windows drive letters, so split from the right. */
|
|
54
|
+
function parseSrc(src) {
|
|
55
|
+
const m = /^(.*):(\d+):(\d+)$/.exec(src);
|
|
56
|
+
if (!m) return null;
|
|
57
|
+
return {
|
|
58
|
+
file: m[1],
|
|
59
|
+
line: Number(m[2]),
|
|
60
|
+
col: Number(m[3])
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
export { NAME_ATTR, NS, OLDEST_PROTOCOL, PROTOCOL_VERSION, SRC_ATTR, STUDIO_PORT, STUDIO_URL, isStudioMessage, jsComment, jsString, outdated, parseSrc };
|
package/package.json
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saywright/vite",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Vite plugin for Saywright: traces every element of your running React app to its file and line, so you can point at it and say what to change. Dev server only.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"vite",
|
|
7
|
+
"vite-plugin",
|
|
8
|
+
"react",
|
|
9
|
+
"saywright",
|
|
10
|
+
"click-to-source",
|
|
11
|
+
"click-to-component",
|
|
12
|
+
"open-in-editor",
|
|
13
|
+
"source-location",
|
|
14
|
+
"developer-tools",
|
|
15
|
+
"devtools",
|
|
16
|
+
"visual-editing"
|
|
17
|
+
],
|
|
18
|
+
"license": "Apache-2.0",
|
|
19
|
+
"homepage": "https://github.com/ahmedbakr/saywright/tree/main/packages/vite#readme",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/ahmedbakr/saywright.git",
|
|
23
|
+
"directory": "packages/vite"
|
|
24
|
+
},
|
|
25
|
+
"bugs": "https://github.com/ahmedbakr/saywright/issues",
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"types": "./types/index.d.ts",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./types/index.d.ts",
|
|
32
|
+
"default": "./dist/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./protocol": {
|
|
35
|
+
"source": "./src/protocol.ts",
|
|
36
|
+
"types": "./dist/protocol.d.ts",
|
|
37
|
+
"default": "./dist/protocol.js"
|
|
38
|
+
},
|
|
39
|
+
"./client": {
|
|
40
|
+
"source": "./src/client/index.ts"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"dist",
|
|
45
|
+
"types",
|
|
46
|
+
"README.md",
|
|
47
|
+
"LICENSE"
|
|
48
|
+
],
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": "^22.18.0 || >=24.11.0"
|
|
51
|
+
},
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "node build.mjs",
|
|
57
|
+
"prepack": "node build.mjs",
|
|
58
|
+
"typecheck": "tsc -p tsconfig.json"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@babel/parser": "^8.0.7",
|
|
62
|
+
"magic-string": "^1.4.3"
|
|
63
|
+
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"vite": ">=4"
|
|
66
|
+
}
|
|
67
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
export interface SaywrightOptions {
|
|
4
|
+
/** Files to annotate. Default: .jsx and .tsx files. */
|
|
5
|
+
include?: RegExp;
|
|
6
|
+
/** Files to skip. Default: node_modules. */
|
|
7
|
+
exclude?: RegExp;
|
|
8
|
+
/** Extra studio origins allowed to talk to the bridge (the studio that announced itself, or the default address, always is). */
|
|
9
|
+
studioOrigins?: string[];
|
|
10
|
+
/** Where the studio runs. Default: what the studio announces when it starts, else http://localhost:7357. */
|
|
11
|
+
studio?: string;
|
|
12
|
+
/** Show the test-session recorder when the app is open in its own tab. Default: true. */
|
|
13
|
+
widget?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Makes a Vite + React app pointable from Saywright (dev server only). */
|
|
17
|
+
export default function saywright(options?: SaywrightOptions): Plugin;
|
|
18
|
+
export { saywright };
|