sourcemonkey 0.0.0-stage → 0.5.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 +21 -0
- package/README.md +87 -2
- package/dist/bytes.js +37 -0
- package/dist/channel-placeholder.js +5 -0
- package/dist/collection-scan.js +17 -0
- package/dist/collections.html +353 -0
- package/dist/compare.html +358 -0
- package/dist/composed-source.js +205 -0
- package/dist/connect-prompt.html +47 -0
- package/dist/debug/icons.html +211 -0
- package/dist/debug/storage.html +163 -0
- package/dist/debug-log.js +75 -0
- package/dist/diagnostic-location.js +64 -0
- package/dist/eval-hook.js +308 -0
- package/dist/extension/background.js +5263 -0
- package/dist/extension/channel.js +133 -0
- package/dist/extension/code-links.js +187 -0
- package/dist/extension/code-tabs.js +460 -0
- package/dist/extension/collection-dialog.js +619 -0
- package/dist/extension/collection-display.js +322 -0
- package/dist/extension/collections.js +2905 -0
- package/dist/extension/compare.js +867 -0
- package/dist/extension/concurrency.js +186 -0
- package/dist/extension/connect-grants.js +109 -0
- package/dist/extension/connect-prompt-page.js +70 -0
- package/dist/extension/connect-prompt.js +266 -0
- package/dist/extension/copy-button.js +63 -0
- package/dist/extension/copy-dialog.js +502 -0
- package/dist/extension/copy-preference.js +66 -0
- package/dist/extension/debug/icons.js +203 -0
- package/dist/extension/debug/storage.js +365 -0
- package/dist/extension/deep-link.js +77 -0
- package/dist/extension/delete-dialog.js +432 -0
- package/dist/extension/delete-icon.js +40 -0
- package/dist/extension/details-tooltips.js +66 -0
- package/dist/extension/directories.js +679 -0
- package/dist/extension/export-backup.js +407 -0
- package/dist/extension/export-dialog.js +142 -0
- package/dist/extension/file-access.js +74 -0
- package/dist/extension/file-changes.js +346 -0
- package/dist/extension/frame-info.js +85 -0
- package/dist/extension/github-provider.js +336 -0
- package/dist/extension/glyph.js +84 -0
- package/dist/extension/gm-bindings.js +601 -0
- package/dist/extension/gm-download.js +419 -0
- package/dist/extension/gm-menu.js +228 -0
- package/dist/extension/gm-notification.js +141 -0
- package/dist/extension/gm-originator-map.js +23 -0
- package/dist/extension/gm-tab-data.js +121 -0
- package/dist/extension/gm-tab.js +160 -0
- package/dist/extension/gm-url-change.js +111 -0
- package/dist/extension/gm-url-scheme.js +27 -0
- package/dist/extension/gm-values.js +176 -0
- package/dist/extension/gm-window-control.js +104 -0
- package/dist/extension/gm-xhr-headers.js +333 -0
- package/dist/extension/gm-xhr.js +584 -0
- package/dist/extension/injector.js +3145 -0
- package/dist/extension/install-capture.js +277 -0
- package/dist/extension/line-diff.js +233 -0
- package/dist/extension/local-copy.js +560 -0
- package/dist/extension/local-delete.js +276 -0
- package/dist/extension/location-kinds.js +108 -0
- package/dist/extension/log-format.js +158 -0
- package/dist/extension/managed-changes.js +361 -0
- package/dist/extension/managed-items.js +57 -0
- package/dist/extension/match-index.js +375 -0
- package/dist/extension/missing-scripts.js +66 -0
- package/dist/extension/more-menu.js +109 -0
- package/dist/extension/move-dialog.js +197 -0
- package/dist/extension/offscreen.js +37 -0
- package/dist/extension/options.js +504 -0
- package/dist/extension/page-heading.js +170 -0
- package/dist/extension/page-links.js +199 -0
- package/dist/extension/parse-check-client.js +70 -0
- package/dist/extension/parse-check.js +161 -0
- package/dist/extension/parse-sandbox-host.js +172 -0
- package/dist/extension/parse-sandbox.js +175 -0
- package/dist/extension/popup-commands-open.js +41 -0
- package/dist/extension/popup-view.js +387 -0
- package/dist/extension/popup.js +703 -0
- package/dist/extension/prism-userscript.js +53 -0
- package/dist/extension/refresh-error.js +136 -0
- package/dist/extension/refresh-targets.js +160 -0
- package/dist/extension/related-versions.js +1144 -0
- package/dist/extension/resize-observer-loop.js +19 -0
- package/dist/extension/row-cache.js +387 -0
- package/dist/extension/script-blobs.js +413 -0
- package/dist/extension/script-details.js +658 -0
- package/dist/extension/script-enablement.js +285 -0
- package/dist/extension/script-identity.js +310 -0
- package/dist/extension/script-keys.js +54 -0
- package/dist/extension/script-log-id.js +155 -0
- package/dist/extension/script-log.js +290 -0
- package/dist/extension/script-rejection.js +104 -0
- package/dist/extension/script-sites.js +158 -0
- package/dist/extension/script-store.js +3507 -0
- package/dist/extension/script-updater.js +991 -0
- package/dist/extension/script-url-hash.js +61 -0
- package/dist/extension/select-all.js +37 -0
- package/dist/extension/select-open-guard.js +90 -0
- package/dist/extension/site-icon.js +1261 -0
- package/dist/extension/sm-dev-link.js +302 -0
- package/dist/extension/solo-click.js +58 -0
- package/dist/extension/sticky-numbers.js +188 -0
- package/dist/extension/storage-breakdown.js +253 -0
- package/dist/extension/storage-scan.js +86 -0
- package/dist/extension/storage-usage.js +194 -0
- package/dist/extension/structural-keys.js +29 -0
- package/dist/extension/sw-teardown.js +36 -0
- package/dist/extension/tab-status.js +403 -0
- package/dist/extension/toolbar-summary.js +105 -0
- package/dist/extension/user-scripts-access.js +43 -0
- package/dist/extension/userscript.js +3672 -0
- package/dist/extension/value-store.js +204 -0
- package/dist/extension/version-probe-fetch.js +68 -0
- package/dist/extension/worker-client.js +109 -0
- package/dist/extension/worker-ops.js +171 -0
- package/dist/extension/zip-writer.js +24 -0
- package/dist/external-files.js +878 -0
- package/dist/file-loader.js +436 -0
- package/dist/file-locations.js +439 -0
- package/dist/generated-wrappers.js +5 -0
- package/dist/github-auth.js +148 -0
- package/dist/github-urls.js +46 -0
- package/dist/gm-api-catalog.js +217 -0
- package/dist/gm-connect.js +273 -0
- package/dist/gm-xhr-types.js +5 -0
- package/dist/http-read.js +142 -0
- package/dist/icons/icon-128.png +0 -0
- package/dist/icons/icon-16.png +0 -0
- package/dist/icons/icon-48.png +0 -0
- package/dist/local-file-overrides.js +558 -0
- package/dist/manifest.json +38 -0
- package/dist/markup-response.js +126 -0
- package/dist/match-targets.js +305 -0
- package/dist/menu-captions.js +22 -0
- package/dist/offscreen.html +39 -0
- package/dist/options.html +197 -0
- package/dist/parse-check-protocol.js +51 -0
- package/dist/parse-location.js +171 -0
- package/dist/parse-sandbox.html +56 -0
- package/dist/phase-timing.js +155 -0
- package/dist/popup.html +197 -0
- package/dist/public-suffixes.js +6957 -0
- package/dist/run-context.js +31 -0
- package/dist/runtime-messages.js +34 -0
- package/dist/sandboxed-page.js +35 -0
- package/dist/script-build.js +787 -0
- package/dist/script-display.js +383 -0
- package/dist/script-icon.js +43 -0
- package/dist/script-links.js +204 -0
- package/dist/script-source-url.js +214 -0
- package/dist/script-world.js +65 -0
- package/dist/sm-dev-protocol.js +84 -0
- package/dist/source-map.js +177 -0
- package/dist/stack-link.js +138 -0
- package/dist/styles.css +825 -0
- package/dist/unsafe-window-use.js +229 -0
- package/dist/url-match.js +734 -0
- package/dist/userscript-header.js +248 -0
- package/dist/userscript.html +1165 -0
- package/dist/vendor/fflate.LICENSE +21 -0
- package/dist/vendor/fflate.js +2692 -0
- package/dist/vendor/prism/prism-line-numbers.css +1 -0
- package/dist/vendor/prism/prism-line-numbers.js +1 -0
- package/dist/vendor/prism/prism.css +1 -0
- package/dist/vendor/prism/prism.js +1946 -0
- package/dist/version-compare.js +141 -0
- package/dist/version-probe.js +120 -0
- package/lib/build-info.json +1 -0
- package/lib/bytes.d.ts +3 -0
- package/lib/bytes.js +37 -0
- package/lib/channel-placeholder.d.ts +1 -0
- package/lib/channel-placeholder.js +5 -0
- package/lib/collection-scan.d.ts +8 -0
- package/lib/collection-scan.js +17 -0
- package/lib/composed-source.d.ts +28 -0
- package/lib/composed-source.js +205 -0
- package/lib/debug-log.d.ts +9 -0
- package/lib/debug-log.js +75 -0
- package/lib/diagnostic-location.d.ts +8 -0
- package/lib/diagnostic-location.js +64 -0
- package/lib/eval-hook.d.ts +34 -0
- package/lib/eval-hook.js +308 -0
- package/lib/external-files.d.ts +111 -0
- package/lib/external-files.js +878 -0
- package/lib/file-loader.d.ts +48 -0
- package/lib/file-loader.js +436 -0
- package/lib/file-locations.d.ts +44 -0
- package/lib/file-locations.js +439 -0
- package/lib/generated-wrappers.d.ts +11 -0
- package/lib/generated-wrappers.js +5 -0
- package/lib/github-auth.d.ts +12 -0
- package/lib/github-auth.js +148 -0
- package/lib/github-urls.d.ts +1 -0
- package/lib/github-urls.js +46 -0
- package/lib/gm-api-catalog.d.ts +24 -0
- package/lib/gm-api-catalog.js +217 -0
- package/lib/gm-connect.d.ts +34 -0
- package/lib/gm-connect.js +273 -0
- package/lib/gm-xhr-types.d.ts +68 -0
- package/lib/gm-xhr-types.js +5 -0
- package/lib/harness/browser-extensions.d.ts +73 -0
- package/lib/harness/browser-extensions.js +285 -0
- package/lib/harness/browser-lang.d.ts +20 -0
- package/lib/harness/browser-lang.js +86 -0
- package/lib/harness/browser-launch.d.ts +14 -0
- package/lib/harness/browser-launch.js +184 -0
- package/lib/harness/checks.d.ts +110 -0
- package/lib/harness/checks.js +321 -0
- package/lib/harness/cli.d.ts +2 -0
- package/lib/harness/cli.js +2259 -0
- package/lib/harness/command-args.d.ts +91 -0
- package/lib/harness/command-args.js +369 -0
- package/lib/harness/command-lines.d.ts +80 -0
- package/lib/harness/command-lines.js +180 -0
- package/lib/harness/command-list.d.ts +206 -0
- package/lib/harness/command-list.js +1475 -0
- package/lib/harness/console-commands.d.ts +463 -0
- package/lib/harness/console-commands.js +3216 -0
- package/lib/harness/download-watch.d.ts +21 -0
- package/lib/harness/download-watch.js +156 -0
- package/lib/harness/extension-backend.d.ts +41 -0
- package/lib/harness/extension-backend.js +100 -0
- package/lib/harness/extension-host.d.ts +112 -0
- package/lib/harness/extension-host.js +552 -0
- package/lib/harness/extension-launch.d.ts +67 -0
- package/lib/harness/extension-launch.js +285 -0
- package/lib/harness/extension-link.d.ts +315 -0
- package/lib/harness/extension-link.js +607 -0
- package/lib/harness/external-manager.d.ts +146 -0
- package/lib/harness/external-manager.js +414 -0
- package/lib/harness/fixture.d.ts +165 -0
- package/lib/harness/fixture.js +461 -0
- package/lib/harness/frame-sessions.d.ts +71 -0
- package/lib/harness/frame-sessions.js +248 -0
- package/lib/harness/frames.d.ts +68 -0
- package/lib/harness/frames.js +216 -0
- package/lib/harness/help-format.d.ts +17 -0
- package/lib/harness/help-format.js +127 -0
- package/lib/harness/host.d.ts +352 -0
- package/lib/harness/host.js +423 -0
- package/lib/harness/index.d.ts +8 -0
- package/lib/harness/index.js +10 -0
- package/lib/harness/input-file.d.ts +18 -0
- package/lib/harness/input-file.js +61 -0
- package/lib/harness/json-output.d.ts +565 -0
- package/lib/harness/json-output.js +71 -0
- package/lib/harness/manager-actions.d.ts +21 -0
- package/lib/harness/manager-actions.js +129 -0
- package/lib/harness/manager-commands.d.ts +142 -0
- package/lib/harness/manager-commands.js +1196 -0
- package/lib/harness/manager-fetch.d.ts +33 -0
- package/lib/harness/manager-fetch.js +239 -0
- package/lib/harness/managers.d.ts +24 -0
- package/lib/harness/managers.js +27 -0
- package/lib/harness/output-style.d.ts +125 -0
- package/lib/harness/output-style.js +322 -0
- package/lib/harness/page-commands.d.ts +134 -0
- package/lib/harness/page-commands.js +1141 -0
- package/lib/harness/page-output.d.ts +67 -0
- package/lib/harness/page-output.js +139 -0
- package/lib/harness/page-watch.d.ts +171 -0
- package/lib/harness/page-watch.js +607 -0
- package/lib/harness/parse-check-node.d.ts +3 -0
- package/lib/harness/parse-check-node.js +132 -0
- package/lib/harness/path-args.d.ts +22 -0
- package/lib/harness/path-args.js +148 -0
- package/lib/harness/playwright-chromium.d.ts +16 -0
- package/lib/harness/playwright-chromium.js +86 -0
- package/lib/harness/prepare.d.ts +168 -0
- package/lib/harness/prepare.js +364 -0
- package/lib/harness/prompt-editor.d.ts +17 -0
- package/lib/harness/prompt-editor.js +354 -0
- package/lib/harness/prompt-history.d.ts +13 -0
- package/lib/harness/prompt-history.js +89 -0
- package/lib/harness/rebuild-advice.d.ts +6 -0
- package/lib/harness/rebuild-advice.js +39 -0
- package/lib/harness/run-log.d.ts +47 -0
- package/lib/harness/run-log.js +140 -0
- package/lib/harness/run-logs.d.ts +132 -0
- package/lib/harness/run-logs.js +241 -0
- package/lib/harness/run.d.ts +194 -0
- package/lib/harness/run.js +1973 -0
- package/lib/harness/runs.d.ts +229 -0
- package/lib/harness/runs.js +726 -0
- package/lib/harness/save-html.d.ts +39 -0
- package/lib/harness/save-html.js +89 -0
- package/lib/harness/saved-pages.d.ts +120 -0
- package/lib/harness/saved-pages.js +275 -0
- package/lib/harness/script-mark.d.ts +17 -0
- package/lib/harness/script-mark.js +56 -0
- package/lib/harness/snapshot.d.ts +143 -0
- package/lib/harness/snapshot.js +474 -0
- package/lib/harness/stuck-tabs.d.ts +19 -0
- package/lib/harness/stuck-tabs.js +131 -0
- package/lib/harness/tab-refs.d.ts +20 -0
- package/lib/harness/tab-refs.js +80 -0
- package/lib/harness/tampermonkey.d.ts +71 -0
- package/lib/harness/tampermonkey.js +356 -0
- package/lib/harness/tm-ids.d.ts +18 -0
- package/lib/harness/tm-ids.js +88 -0
- package/lib/harness/violentmonkey.d.ts +34 -0
- package/lib/harness/violentmonkey.js +162 -0
- package/lib/harness/wait.d.ts +77 -0
- package/lib/harness/wait.js +458 -0
- package/lib/http-read.d.ts +30 -0
- package/lib/http-read.js +142 -0
- package/lib/local-file-overrides.d.ts +35 -0
- package/lib/local-file-overrides.js +558 -0
- package/lib/manifest.json +38 -0
- package/lib/markup-response.d.ts +11 -0
- package/lib/markup-response.js +126 -0
- package/lib/match-targets.d.ts +18 -0
- package/lib/match-targets.js +305 -0
- package/lib/menu-captions.d.ts +1 -0
- package/lib/menu-captions.js +22 -0
- package/lib/parse-check-protocol.d.ts +27 -0
- package/lib/parse-check-protocol.js +51 -0
- package/lib/parse-location.d.ts +12 -0
- package/lib/parse-location.js +171 -0
- package/lib/phase-timing.d.ts +12 -0
- package/lib/phase-timing.js +155 -0
- package/lib/public-suffixes.d.ts +1 -0
- package/lib/public-suffixes.js +6957 -0
- package/lib/run-context.d.ts +2 -0
- package/lib/run-context.js +31 -0
- package/lib/runtime-messages.d.ts +10 -0
- package/lib/runtime-messages.js +34 -0
- package/lib/sandboxed-page.d.ts +5 -0
- package/lib/sandboxed-page.js +35 -0
- package/lib/script-build.d.ts +111 -0
- package/lib/script-build.js +787 -0
- package/lib/script-display.d.ts +51 -0
- package/lib/script-display.js +383 -0
- package/lib/script-icon.d.ts +16 -0
- package/lib/script-icon.js +43 -0
- package/lib/script-links.d.ts +24 -0
- package/lib/script-links.js +204 -0
- package/lib/script-source-url.d.ts +8 -0
- package/lib/script-source-url.js +214 -0
- package/lib/script-world.d.ts +6 -0
- package/lib/script-world.js +65 -0
- package/lib/sm-dev-protocol.d.ts +251 -0
- package/lib/sm-dev-protocol.js +84 -0
- package/lib/source-map.d.ts +32 -0
- package/lib/source-map.js +177 -0
- package/lib/stack-link.d.ts +15 -0
- package/lib/stack-link.js +138 -0
- package/lib/unsafe-window-use.d.ts +1 -0
- package/lib/unsafe-window-use.js +229 -0
- package/lib/url-match.d.ts +40 -0
- package/lib/url-match.js +734 -0
- package/lib/userscript-header.d.ts +33 -0
- package/lib/userscript-header.js +248 -0
- package/lib/version-compare.d.ts +6 -0
- package/lib/version-compare.js +141 -0
- package/lib/version-probe.d.ts +17 -0
- package/lib/version-probe.js +120 -0
- package/package.json +55 -3
- package/skills/SourceMonkey-dev/SKILL.md +868 -0
- package/skills/SourceMonkey-dev/references/cdp.md +293 -0
- package/skills/SourceMonkey-dev/references/commands.md +297 -0
- package/skills/SourceMonkey-dev/references/other-managers.md +63 -0
- package/skills/SourceMonkey-dev/references/specs.md +46 -0
- package/skills/SourceMonkey-friction/SKILL.md +103 -0
- package/skills/SourceMonkey-friction/references/template.md +59 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
// Styled output lines: sm-dev's text marked up by what each piece is
|
|
2
|
+
// (an ID, a URL, a command), shown in color at a terminal that has it
|
|
3
|
+
// and as plain text otherwise. Help has its own form (help-format.ts).
|
|
4
|
+
//
|
|
5
|
+
// The markup is XML-like tags naming roles, not looks: `<id>T1</id>`.
|
|
6
|
+
// A line holding markup starts with MARKUP; anything before it is
|
|
7
|
+
// plain text, so `'[sm-dev] ' + ui`...`` works, and a
|
|
8
|
+
// line without it is plain and passes through untouched. Plain text
|
|
9
|
+
// put in markup is escaped (`ui` and the role helpers do it), so a
|
|
10
|
+
// script name or page text holding `<` or `&` can't break a line.
|
|
11
|
+
//
|
|
12
|
+
// sm-dev's own messages need no markup to be told apart: a line
|
|
13
|
+
// starting with one of MESSAGE_PREFIXES is an error, a warning or a
|
|
14
|
+
// note by that prefix, and its `backticked` spans are commands (see
|
|
15
|
+
// `message`). So a run from an older build, sending plain text, still
|
|
16
|
+
// shows its errors in color.
|
|
17
|
+
//
|
|
18
|
+
// A run sends markup only to clients that ask for it; the log file and
|
|
19
|
+
// older clients get plain text (`plainLine`). The client paints each
|
|
20
|
+
// line for its own terminal (`paintOutput`).
|
|
21
|
+
/**
|
|
22
|
+
* Starts a line's markup: a control character and a private-use one, a
|
|
23
|
+
* pair page text won't hold by chance (icon fonts use U+E000 alone),
|
|
24
|
+
* and invisible if it ever leaks.
|
|
25
|
+
*/
|
|
26
|
+
export const MARKUP = '\u0002\ue000';
|
|
27
|
+
// Each role's look in color. Palette colors, which terminal themes set
|
|
28
|
+
// to read on their own background, light or dark.
|
|
29
|
+
const STYLES = {
|
|
30
|
+
prompt: ['bold', 'green'],
|
|
31
|
+
typed: ['cyan'],
|
|
32
|
+
cmd: ['cyan'],
|
|
33
|
+
code: ['cyan'],
|
|
34
|
+
err: ['bold', 'red'],
|
|
35
|
+
warn: ['bold', 'magenta'],
|
|
36
|
+
h: ['bold'],
|
|
37
|
+
sel: ['bold'],
|
|
38
|
+
id: ['green'],
|
|
39
|
+
dim: ['dim'],
|
|
40
|
+
url: ['underline'],
|
|
41
|
+
name: ['italic'],
|
|
42
|
+
};
|
|
43
|
+
// Each look's SGR codes, on and off.
|
|
44
|
+
const SGR = {
|
|
45
|
+
bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24],
|
|
46
|
+
red: [31, 39], green: [32, 39], magenta: [35, 39], cyan: [36, 39],
|
|
47
|
+
};
|
|
48
|
+
const ROLES = new Set(Object.keys(STYLES));
|
|
49
|
+
/**
|
|
50
|
+
* A role's SGR codes, on and off, for text painted elsewhere (help's
|
|
51
|
+
* code and headings). Off undoes only that role's looks, so it can
|
|
52
|
+
* nest inside another (code in a bold heading), as long as the two
|
|
53
|
+
* share no look: were `cmd` bold too, its off would end the heading's
|
|
54
|
+
* bold.
|
|
55
|
+
*/
|
|
56
|
+
export function styleCodes(roleName) {
|
|
57
|
+
const looks = STYLES[roleName];
|
|
58
|
+
return [looks.map((look) => `\x1b[${SGR[look][0]}m`).join(''), [...new Set(looks.map((look) => `\x1b[${SGR[look][1]}m`))].join('')];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Whether a code span keeps its backticks in plain text (help, and sm-dev's messages): one of several
|
|
62
|
+
* words (`--lang zh-CN`), a lowercase word that reads as English (a
|
|
63
|
+
* command, `all`), or punctuation (`{{`). A flag, ID, number, path or
|
|
64
|
+
* name reads as code without them.
|
|
65
|
+
*/
|
|
66
|
+
export function keepsBackticks(span) {
|
|
67
|
+
// Spaces may be held as help-format.ts's KEPT_SPACE (U+0002) while wrapping. A capitalized name
|
|
68
|
+
// (`Shift`, `Method`) or one letter (`N`) reads as code already.
|
|
69
|
+
return /[\s\u0002]/.test(span) || /^[a-z][a-z-]+$/.test(span) || !/[A-Za-z0-9]/.test(span);
|
|
70
|
+
}
|
|
71
|
+
/** Starts sm-dev's own messages. */
|
|
72
|
+
export const SM_DEV_PREFIX = '[sm-dev] ';
|
|
73
|
+
/** Starts the client's line for a command given wrongly. */
|
|
74
|
+
export const ERROR_PREFIX = 'ERROR: ';
|
|
75
|
+
/** Starts a run's line for a command given wrongly (exit code 2). */
|
|
76
|
+
export const MISTAKE_PREFIX = `${SM_DEV_PREFIX}${ERROR_PREFIX}`;
|
|
77
|
+
/** Starts a warning about the browser. */
|
|
78
|
+
export const WARNING_PREFIX = 'Warning: ';
|
|
79
|
+
/** Starts a script's warning from preparing it (`warningLines`). */
|
|
80
|
+
export const WARNING_LEVEL = 'warn: ';
|
|
81
|
+
/** Starts a script's warning from preparing it, as a run prints it. */
|
|
82
|
+
export const SCRIPT_WARNING_PREFIX = `${SM_DEV_PREFIX}${WARNING_LEVEL}`;
|
|
83
|
+
/** Starts a failed `wait`. */
|
|
84
|
+
export const WAIT_FAILED = '[sm-dev] Wait failed: ';
|
|
85
|
+
/** Starts `validate`'s line for an invalid script, and a run's. */
|
|
86
|
+
export const INVALID_PREFIX = 'INVALID ';
|
|
87
|
+
// sm-dev's own lines, by how they start, and the role of the whole line:
|
|
88
|
+
// none for a note.
|
|
89
|
+
const MESSAGE_PREFIXES = [
|
|
90
|
+
[MISTAKE_PREFIX, 'err'], [WAIT_FAILED, 'err'], [SCRIPT_WARNING_PREFIX, 'warn'], [`${SM_DEV_PREFIX}${WARNING_PREFIX}`, 'warn'], [SM_DEV_PREFIX, null],
|
|
91
|
+
[ERROR_PREFIX, 'err'], [INVALID_PREFIX, 'err'], [WARNING_PREFIX, 'warn'],
|
|
92
|
+
];
|
|
93
|
+
/**
|
|
94
|
+
* Text in backticks, for a message: a command, flag or the user's input
|
|
95
|
+
* (`` Use `tabs` ``). Shown as a command in color, and plain with its
|
|
96
|
+
* backticks where they help it read (see keepsBackticks). Text holding a
|
|
97
|
+
* backtick itself (a selector, say) goes in double ones, as Markdown
|
|
98
|
+
* does: ``` `` a`b `` ```.
|
|
99
|
+
*/
|
|
100
|
+
export function quoted(text) {
|
|
101
|
+
const shown = String(text);
|
|
102
|
+
return shown.includes('`') ? `\`\` ${shown} \`\`` : `\`${shown}\``;
|
|
103
|
+
}
|
|
104
|
+
// A quoted span: in double backticks (with a space inside each), or in single ones.
|
|
105
|
+
const QUOTED_SPAN = /(``\s.*?\s``|`[^`\n]+`)/;
|
|
106
|
+
// A quoted span's text, its backticks taken off.
|
|
107
|
+
const unquoted = (span) => (span.startsWith('``') ? span.slice(3, -3) : span.slice(1, -1));
|
|
108
|
+
/** Text escaped for markup. */
|
|
109
|
+
export function escapeMarkup(text) {
|
|
110
|
+
return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
111
|
+
}
|
|
112
|
+
// A line's markup: plain text before MARKUP escaped, markup after it as is.
|
|
113
|
+
function markupOf(text) {
|
|
114
|
+
const at = text.indexOf(MARKUP);
|
|
115
|
+
if (at < 0)
|
|
116
|
+
return escapeMarkup(text);
|
|
117
|
+
return escapeMarkup(text.slice(0, at)) + text.slice(at + MARKUP.length).replaceAll(MARKUP, '');
|
|
118
|
+
}
|
|
119
|
+
/** A cell of plain text. */
|
|
120
|
+
export const textCell = (text) => ({ plain: text, styled: escapeMarkup(text) });
|
|
121
|
+
/** A cell in a role: `roleCell(url, 'https://x/')`. */
|
|
122
|
+
export const roleCell = (style, text) => ({ plain: text, styled: style(text) });
|
|
123
|
+
/**
|
|
124
|
+
* Rows as lines: columns two spaces apart, each as wide as its widest
|
|
125
|
+
* cell. The last column isn't padded, so no line ends in spaces. As
|
|
126
|
+
* markup, or with `markup: false`, as plain text.
|
|
127
|
+
*/
|
|
128
|
+
export function tableLines(rows, { markup = true } = {}) {
|
|
129
|
+
const widths = (rows[0] ?? []).map((_, i) => Math.max(...rows.map((row) => row[i].plain.length)));
|
|
130
|
+
return rows.map((row) => {
|
|
131
|
+
const line = (text) => row.map((cell, i) => text(cell) + (i < row.length - 1 ? ' '.repeat(widths[i] - cell.plain.length) : '')).join(' ').trimEnd();
|
|
132
|
+
return markup ? MARKUP + line((cell) => cell.styled) : line((cell) => cell.plain);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/** Text as a role: `role('id', 'T1')`. Text that is markup already stays markup. */
|
|
136
|
+
export function role(name, text) {
|
|
137
|
+
return `${MARKUP}<${name}>${markupOf(String(text))}</${name}>`;
|
|
138
|
+
}
|
|
139
|
+
export const id = (text) => role('id', text);
|
|
140
|
+
export const name = (text) => role('name', text);
|
|
141
|
+
export const url = (text) => role('url', text);
|
|
142
|
+
export const cmd = (text) => role('cmd', text);
|
|
143
|
+
export const code = (text) => role('code', text);
|
|
144
|
+
export const heading = (text) => role('h', text);
|
|
145
|
+
export const selected = (text) => role('sel', text);
|
|
146
|
+
export const dim = (text) => role('dim', text);
|
|
147
|
+
/** A message we wrote, as an error: its `backticked` spans are commands (see `message`). */
|
|
148
|
+
export const err = (text) => role('err', message(text));
|
|
149
|
+
/** A message we wrote, as a warning. */
|
|
150
|
+
export const warn = (text) => role('warn', message(text));
|
|
151
|
+
/** Text we didn't write (a script's console line, a page's error), as an error, taken as it is. */
|
|
152
|
+
export const asError = (text) => role('err', text);
|
|
153
|
+
/** Text we didn't write, as a warning. */
|
|
154
|
+
export const asWarning = (text) => role('warn', text);
|
|
155
|
+
/**
|
|
156
|
+
* A line of markup, from a template: what is put in is escaped, unless
|
|
157
|
+
* it is markup already (from `ui` or a role helper).
|
|
158
|
+
*/
|
|
159
|
+
export function ui(strings, ...values) {
|
|
160
|
+
let out = escapeMarkup(strings[0]);
|
|
161
|
+
values.forEach((value, i) => {
|
|
162
|
+
out += markupOf(String(value)) + escapeMarkup(strings[i + 1]);
|
|
163
|
+
});
|
|
164
|
+
return MARKUP + out;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* A message we wrote, as markup: each `backticked` span is a command
|
|
168
|
+
* (`Use `tabs` to list them`), shown in color, or with its backticks
|
|
169
|
+
* where they help it read (see keepsBackticks). Text that is markup
|
|
170
|
+
* already stays as it is.
|
|
171
|
+
*/
|
|
172
|
+
export function message(text) {
|
|
173
|
+
const at = text.indexOf(MARKUP);
|
|
174
|
+
const plain = at < 0 ? text : text.slice(0, at);
|
|
175
|
+
const marked = plain.split(QUOTED_SPAN).map((part, i) => (i % 2 === 1 ? `<cmd>${escapeMarkup(unquoted(part))}</cmd>` : escapeMarkup(part))).join('');
|
|
176
|
+
return MARKUP + marked + (at < 0 ? '' : text.slice(at + MARKUP.length).replaceAll(MARKUP, ''));
|
|
177
|
+
}
|
|
178
|
+
function pieces(markup) {
|
|
179
|
+
const out = [];
|
|
180
|
+
for (const m of markup.matchAll(/<(\/?)([a-z]+)>|&(lt|gt|amp);|[^<&]+|[<&]/g)) {
|
|
181
|
+
if (m[2] !== undefined && ROLES.has(m[2]))
|
|
182
|
+
out.push(m[1] ? { close: m[2] } : { open: m[2] });
|
|
183
|
+
else if (m[3] !== undefined)
|
|
184
|
+
out.push({ text: { lt: '<', gt: '>', amp: '&' }[m[3]] });
|
|
185
|
+
else
|
|
186
|
+
out.push({ text: m[0] });
|
|
187
|
+
}
|
|
188
|
+
return out;
|
|
189
|
+
}
|
|
190
|
+
// A line as markup, with sm-dev's own messages told by their prefix;
|
|
191
|
+
// null for plain text that is none.
|
|
192
|
+
function markupLine(line) {
|
|
193
|
+
const at = line.indexOf(MARKUP);
|
|
194
|
+
if (at >= 0) {
|
|
195
|
+
const head = line.slice(0, at);
|
|
196
|
+
const rest = line.slice(at + MARKUP.length).replaceAll(MARKUP, '');
|
|
197
|
+
// A prefix before an error or warning (`[sm-dev] ` + err(...)) is part of it.
|
|
198
|
+
const whole = /^<(err|warn)>/.exec(rest);
|
|
199
|
+
return whole ? `<${whole[1]}>${escapeMarkup(head)}${rest.slice(whole[0].length)}` : escapeMarkup(head) + rest;
|
|
200
|
+
}
|
|
201
|
+
const kind = MESSAGE_PREFIXES.find(([prefix]) => line.startsWith(prefix));
|
|
202
|
+
if (!kind)
|
|
203
|
+
return null;
|
|
204
|
+
const text = message(line).slice(MARKUP.length);
|
|
205
|
+
return kind[1] ? `<${kind[1]}>${text}</${kind[1]}>` : text;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* A line as shown: painted for a terminal with color, or plain. Plain
|
|
209
|
+
* text that is not one of sm-dev's messages is returned as it is.
|
|
210
|
+
*/
|
|
211
|
+
export function paintOutput(line, color) {
|
|
212
|
+
const markup = markupLine(line);
|
|
213
|
+
return markup === null ? line : paintMarkup(markup, color);
|
|
214
|
+
}
|
|
215
|
+
function paintMarkup(markup, color) {
|
|
216
|
+
const roles = [];
|
|
217
|
+
const on = (rs) => rs.flatMap((r) => STYLES[r]).map((look) => `\x1b[${SGR[look][0]}m`).join('');
|
|
218
|
+
let out = '';
|
|
219
|
+
// Plain, a command keeps its backticks where they help it read.
|
|
220
|
+
let cmdText = '';
|
|
221
|
+
for (const piece of pieces(markup)) {
|
|
222
|
+
if ('text' in piece) {
|
|
223
|
+
if (!color && roles.includes('cmd'))
|
|
224
|
+
cmdText += piece.text;
|
|
225
|
+
else
|
|
226
|
+
out += piece.text;
|
|
227
|
+
}
|
|
228
|
+
else if ('open' in piece) {
|
|
229
|
+
roles.push(piece.open);
|
|
230
|
+
if (color)
|
|
231
|
+
out += on([piece.open]);
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
const i = roles.lastIndexOf(piece.close);
|
|
235
|
+
if (i >= 0)
|
|
236
|
+
roles.splice(i, 1);
|
|
237
|
+
if (color)
|
|
238
|
+
out += `\x1b[0m${on(roles)}`;
|
|
239
|
+
else if (piece.close === 'cmd' && !roles.includes('cmd')) {
|
|
240
|
+
out += keepsBackticks(cmdText) ? quoted(cmdText) : cmdText;
|
|
241
|
+
cmdText = '';
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return out + cmdText + (color && roles.length > 0 ? '\x1b[0m' : '');
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Output that may span lines (a stack trace in one error) as lines that
|
|
249
|
+
* each stand alone, for a reader that paints line by line. A role open
|
|
250
|
+
* at a line break is closed there and opened again on the next line, so
|
|
251
|
+
* every line is markup of its own; without that, the lines after the
|
|
252
|
+
* first would show their tags and escapes as text.
|
|
253
|
+
* - Plain text before the markup stays as it is at the start of its
|
|
254
|
+
* line, where readers look for a prefix (`[sm-dev] `).
|
|
255
|
+
* - Plain text with no markup is just split: each line is read on its
|
|
256
|
+
* own, by its own prefix.
|
|
257
|
+
*/
|
|
258
|
+
export function markupLines(line) {
|
|
259
|
+
if (!line.includes('\n'))
|
|
260
|
+
return [line];
|
|
261
|
+
const at = line.indexOf(MARKUP);
|
|
262
|
+
if (at < 0)
|
|
263
|
+
return line.split('\n');
|
|
264
|
+
const headLines = line.slice(0, at).split('\n');
|
|
265
|
+
const out = headLines.slice(0, -1);
|
|
266
|
+
const markup = line.slice(at + MARKUP.length).replaceAll(MARKUP, '');
|
|
267
|
+
const open = [];
|
|
268
|
+
let current = '';
|
|
269
|
+
let prefix = headLines[headLines.length - 1];
|
|
270
|
+
const reopen = () => open.map((r) => `<${r}>`).join('');
|
|
271
|
+
const close = () => [...open].reverse().map((r) => `</${r}>`).join('');
|
|
272
|
+
for (const piece of pieces(markup)) {
|
|
273
|
+
if ('open' in piece) {
|
|
274
|
+
open.push(piece.open);
|
|
275
|
+
current += `<${piece.open}>`;
|
|
276
|
+
}
|
|
277
|
+
else if ('close' in piece) {
|
|
278
|
+
const i = open.lastIndexOf(piece.close);
|
|
279
|
+
if (i >= 0)
|
|
280
|
+
open.splice(i, 1);
|
|
281
|
+
current += `</${piece.close}>`;
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
const parts = piece.text.split('\n');
|
|
285
|
+
parts.forEach((part, i) => {
|
|
286
|
+
if (i > 0) {
|
|
287
|
+
out.push(prefix + MARKUP + current + close());
|
|
288
|
+
prefix = '';
|
|
289
|
+
current = reopen();
|
|
290
|
+
}
|
|
291
|
+
current += escapeMarkup(part);
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
out.push(prefix + MARKUP + current);
|
|
296
|
+
return out;
|
|
297
|
+
}
|
|
298
|
+
/** A line as plain text: for the log file, and for clients that didn't ask for markup. */
|
|
299
|
+
export function plainLine(line) {
|
|
300
|
+
return paintOutput(line, false);
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Whether output to `stream` is painted: at a terminal that has color.
|
|
304
|
+
* FORCE_COLOR asks for it anyway (or, as 0 or false, not), as Node
|
|
305
|
+
* reads it; NO_COLOR is honored by hasColors.
|
|
306
|
+
*/
|
|
307
|
+
export function streamHasColor(stream) {
|
|
308
|
+
const forced = process.env.FORCE_COLOR;
|
|
309
|
+
if (forced !== undefined)
|
|
310
|
+
return forced !== '0' && forced !== 'false';
|
|
311
|
+
return stream.isTTY === true && stream.hasColors();
|
|
312
|
+
}
|
|
313
|
+
/** A command echoed before its output, as the prompt shows it: `arg > status`. */
|
|
314
|
+
export function echoLine(mark, text) {
|
|
315
|
+
return `${MARKUP}<prompt>${escapeMarkup(mark)}</prompt> <typed>${escapeMarkup(text)}</typed>`;
|
|
316
|
+
}
|
|
317
|
+
/** Text painted as one role, for a terminal with color: the prompt and typed commands. */
|
|
318
|
+
export function paintAs(roleName, text) {
|
|
319
|
+
if (!text)
|
|
320
|
+
return text;
|
|
321
|
+
return STYLES[roleName].map((look) => `\x1b[${SGR[look][0]}m`).join('') + text + '\x1b[0m';
|
|
322
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { Frame, Page } from '@playwright/test';
|
|
2
|
+
import type { ParsedArgs } from './command-args.js';
|
|
3
|
+
import type { ControlledTab } from './console-commands.js';
|
|
4
|
+
import { type ScriptScope } from './page-watch.js';
|
|
5
|
+
import { type FrameIds } from './frames.js';
|
|
6
|
+
export declare const PAGE_COMMANDS: Set<string>;
|
|
7
|
+
/**
|
|
8
|
+
* A quick yes/no from the page, false when it doesn't answer in time:
|
|
9
|
+
* a page stopped by a dialog or busy in a long script never does.
|
|
10
|
+
*/
|
|
11
|
+
export declare function pageSays(page: Page, check: () => boolean): Promise<boolean>;
|
|
12
|
+
declare const MODIFIERS: readonly ["Alt", "Control", "ControlOrMeta", "Meta", "Shift"];
|
|
13
|
+
/**
|
|
14
|
+
* A page command's arguments, read by its syntax (command-args.ts), the
|
|
15
|
+
* tab already taken from them. `userscripts`: the ones running in the
|
|
16
|
+
* tab's page now, as a saved file's header names them
|
|
17
|
+
* (`userscriptLabel`).
|
|
18
|
+
*/
|
|
19
|
+
export interface PageInput extends ParsedArgs {
|
|
20
|
+
userscripts: string[];
|
|
21
|
+
/** Where `eval` runs, resolved from its flags (see `EvalIn`). */
|
|
22
|
+
evalIn?: EvalIn;
|
|
23
|
+
/** Print the result as JSON (`--json`), for the commands with a JSON form. */
|
|
24
|
+
json?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Where `eval` runs: a script's own scope, with its name for messages
|
|
28
|
+
* and whether a missing scope falls back to the page (a bare `eval`) or
|
|
29
|
+
* is a failure (`--script`); or the page (`--page`, or no run script
|
|
30
|
+
* selected).
|
|
31
|
+
*/
|
|
32
|
+
export type EvalIn = {
|
|
33
|
+
scope: ScriptScope | null;
|
|
34
|
+
name: string;
|
|
35
|
+
inPageIfMissing: boolean;
|
|
36
|
+
manager?: string;
|
|
37
|
+
} | 'page';
|
|
38
|
+
/**
|
|
39
|
+
* Runs one of `PAGE_COMMANDS` on `tab`. Reports through `out`, and
|
|
40
|
+
* resolves once the command and what it set off are done, or once a
|
|
41
|
+
* dialog it opened is waiting for an answer: the page stops until then,
|
|
42
|
+
* and `accept` or `dismiss` can't run while this does. False when it
|
|
43
|
+
* failed (no element, a timeout, an expression that threw), so a line
|
|
44
|
+
* of several commands stops there. A mistake in how it was typed is an
|
|
45
|
+
* `ERROR:` line, which stops the line too.
|
|
46
|
+
*/
|
|
47
|
+
export declare function runPageCommand(command: string, input: PageInput, tab: ControlledTab, out: (line: string) => void, cwd?: string): Promise<boolean | void>;
|
|
48
|
+
type CdpCall = {
|
|
49
|
+
method: string;
|
|
50
|
+
params: object;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* `cdp`'s calls (on its line, in a `{{` block, or in a `--file`): one
|
|
54
|
+
* per line, all in one session. Not split into words first, which would
|
|
55
|
+
* take the quotes out of JSON strings. Blank lines and `#` comments are
|
|
56
|
+
* skipped.
|
|
57
|
+
* - `lines`: for a block or file, how to name a line in a message, from
|
|
58
|
+
* its number. A block's first line is the command's own, line 0.
|
|
59
|
+
*/
|
|
60
|
+
export declare function cdpCallsTyped(raw: string, lines?: {
|
|
61
|
+
first: number;
|
|
62
|
+
name: (n: number) => string;
|
|
63
|
+
}): CdpCall[] | string;
|
|
64
|
+
/**
|
|
65
|
+
* A typed key, or combination (`ctrl+home`), as Playwright names it.
|
|
66
|
+
* A single character stays as typed, since its case is the key (`A` is
|
|
67
|
+
* Shift+a). A name it doesn't know is passed on, for Playwright's error.
|
|
68
|
+
*/
|
|
69
|
+
export declare function keyName(typed: string): string;
|
|
70
|
+
interface ClickFlags {
|
|
71
|
+
button?: 'left' | 'right' | 'middle';
|
|
72
|
+
modifiers?: (typeof MODIFIERS)[number][];
|
|
73
|
+
clickCount?: number;
|
|
74
|
+
position?: {
|
|
75
|
+
x: number;
|
|
76
|
+
y: number;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Which parts of the page `snapshot` shows, from its flags: the
|
|
81
|
+
* `--find` text, and how much around each match (see `treeParts`).
|
|
82
|
+
* Null for all of it (no selector or --find); what's wrong, if anything
|
|
83
|
+
* is.
|
|
84
|
+
*/
|
|
85
|
+
export declare function partOptions(flags: Record<string, string | true>, selector: boolean): {
|
|
86
|
+
text?: string;
|
|
87
|
+
up: number;
|
|
88
|
+
context: boolean;
|
|
89
|
+
limit: number;
|
|
90
|
+
} | null | string;
|
|
91
|
+
/**
|
|
92
|
+
* `snapshot`'s parts as shown: one bare; more numbered, a blank line
|
|
93
|
+
* apart, the first `limit` of them (0: all), and what wasn't shown.
|
|
94
|
+
* When only some of a selector's matches were looked at: `total`, all
|
|
95
|
+
* the matches; or for --find, `unsearched`, how many weren't searched.
|
|
96
|
+
*/
|
|
97
|
+
export declare function partsText(parts: string[], limit: number, { total, unsearched }?: {
|
|
98
|
+
total?: number;
|
|
99
|
+
unsearched?: number;
|
|
100
|
+
}): string;
|
|
101
|
+
/**
|
|
102
|
+
* `click`'s or `hover`'s flags as Playwright's options for them, with
|
|
103
|
+
* its selector, and how the action differs from a plain one, as said
|
|
104
|
+
* after it (`the right button`). Or what's wrong with them. Which flags
|
|
105
|
+
* each takes is its syntax's (command-list.ts).
|
|
106
|
+
*/
|
|
107
|
+
export declare function clickOptions(given: Record<string, string | true>, selector: string): {
|
|
108
|
+
selector: string;
|
|
109
|
+
click: ClickFlags;
|
|
110
|
+
how: string[];
|
|
111
|
+
} | string;
|
|
112
|
+
export declare function plain(err: Error): string;
|
|
113
|
+
export declare function countOf(page: Page, selector: string, within?: Frame): Promise<number | string>;
|
|
114
|
+
/**
|
|
115
|
+
* With `--frame` (`within`), why a ref doesn't do there: it names an
|
|
116
|
+
* element in another frame. Null when it's in that frame, or isn't a
|
|
117
|
+
* ref, or can't be found (which the count says).
|
|
118
|
+
*/
|
|
119
|
+
export declare function refFrameProblem(page: Page, selector: string, within: Frame | undefined, ids: FrameIds): Promise<string | null>;
|
|
120
|
+
/**
|
|
121
|
+
* The iframe a `--frame` flag names in `tab`: undefined for none given,
|
|
122
|
+
* or the tab's own (its top frame); null, having said why, for one that
|
|
123
|
+
* isn't there. It takes `F2`, `T1.F2`, the tab's own `T1`, or a CDP id
|
|
124
|
+
* as the output shows it (`frameId=...` or `targetId=...`, or the start
|
|
125
|
+
* of one).
|
|
126
|
+
*/
|
|
127
|
+
export declare function pickFrame(word: string | true | undefined, tab: ControlledTab, say: (line: string) => void): Promise<Frame | undefined | null>;
|
|
128
|
+
/**
|
|
129
|
+
* A frame's CDP id as given, copied from the output or typed: `frameId=`
|
|
130
|
+
* or `targetId=`, with its brackets or not, or the start of one long
|
|
131
|
+
* enough not to be a slip.
|
|
132
|
+
*/
|
|
133
|
+
export declare const CDP_FRAME_ARG: RegExp;
|
|
134
|
+
export {};
|