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,251 @@
|
|
|
1
|
+
import type { PendingOnDisk } from './script-display.js';
|
|
2
|
+
/** The first argument of every event's console line. */
|
|
3
|
+
export declare const SM_DEV_EVENT = "sm-dev-event";
|
|
4
|
+
/**
|
|
5
|
+
* Refusals of the `managed` calls (managed-changes.ts), which sm-dev
|
|
6
|
+
* also checks before asking for `--force`.
|
|
7
|
+
*/
|
|
8
|
+
export declare const RUN_COLLECTION_LOCKED = "An sm-dev run's test collection is changed only by its run";
|
|
9
|
+
export declare const LISTED_BY_LOCATION = "This script is listed by a directory or manifest collection, so it stays there while its file does. Only a script in a container collection can be moved or uninstalled.";
|
|
10
|
+
export declare const CONTAINER_TARGET_ONLY = "Scripts can only be installed or moved into a container collection";
|
|
11
|
+
/**
|
|
12
|
+
* Why a manual script (`@run-at context-menu`) can't be run on a tab
|
|
13
|
+
* now: `runManualScript`'s answers, which the popup logs and sm-dev
|
|
14
|
+
* prints after the script's name. See docs/manual-scripts.md.
|
|
15
|
+
*/
|
|
16
|
+
export declare const MANUAL_RUN_NOT_INSTALLED = "This script is not installed";
|
|
17
|
+
export declare const MANUAL_RUN_NOT_MANUAL = "This script runs when a page loads. Only a script with @run-at context-menu is run on request.";
|
|
18
|
+
export declare const MANUAL_RUN_SCRIPT_OFF = "This script is turned off";
|
|
19
|
+
export declare const MANUAL_RUN_COLLECTION_OFF = "This script's collection is turned off";
|
|
20
|
+
export declare const MANUAL_RUN_NOT_HERE = "This script's @match and @include rules don't cover this page";
|
|
21
|
+
export declare const MANUAL_RUN_PAGE = "SourceMonkey can't run scripts on this page";
|
|
22
|
+
export declare const MANUAL_RUN_TAB_GONE = "The tab was closed";
|
|
23
|
+
export declare const MANUAL_RUN_PAGE_CHANGED = "The page changed before the script could run. Try again.";
|
|
24
|
+
export declare const MANUAL_RUN_SM_DEV = "The sm-dev run controlling this tab keeps this script out";
|
|
25
|
+
/**
|
|
26
|
+
* The event types of the markers sm-dev puts in its browser's pages,
|
|
27
|
+
* which tell a `document-start` wrapper whether it can run without
|
|
28
|
+
* asking the extension (`smDevMarker` in userscript-prelude.js, which
|
|
29
|
+
* has its own copy). See docs/sm-dev-design.md#making-wrappers-ask.
|
|
30
|
+
* - `present`: in every page. sm-dev is connected, so any tab may be
|
|
31
|
+
* claimed.
|
|
32
|
+
* - `vouchPrefix` + the run's id: in a tab that run claims, while its
|
|
33
|
+
* scripts are on.
|
|
34
|
+
*/
|
|
35
|
+
export declare const SM_DEV_MARKERS: {
|
|
36
|
+
readonly present: "sourcemonkey-sm-dev";
|
|
37
|
+
readonly vouchPrefix: "sourcemonkey-sm-dev-run:";
|
|
38
|
+
};
|
|
39
|
+
/** The reason a skipped wrapper reports for a tab an sm-dev run controls. */
|
|
40
|
+
export declare const SKIP_REASON_SM_DEV = "tab controlled by sm-dev";
|
|
41
|
+
/**
|
|
42
|
+
* The version of the calls and events between sm-dev and the extension,
|
|
43
|
+
* which each side has its own copy of: sm-dev from a repo's install, the
|
|
44
|
+
* extension from the person's browser. A run compares them as it
|
|
45
|
+
* connects (extension-link.ts). See CLAUDE.md for when to bump which.
|
|
46
|
+
* - `major`: a change that needs both sides updated. A run refuses an
|
|
47
|
+
* extension whose major differs.
|
|
48
|
+
* - `minor`: an addition. An extension ahead is fine. An sm-dev ahead
|
|
49
|
+
* checks the extension's minor before using what came later
|
|
50
|
+
* (`ExtensionLink.requireMinor`).
|
|
51
|
+
*/
|
|
52
|
+
export declare const SM_DEV_PROTOCOL: {
|
|
53
|
+
readonly major: 3;
|
|
54
|
+
readonly minor: 0;
|
|
55
|
+
};
|
|
56
|
+
export interface ProtocolVersion {
|
|
57
|
+
major: number;
|
|
58
|
+
minor: number;
|
|
59
|
+
}
|
|
60
|
+
/** A collection, as the extension's `managedCollections` lists it. */
|
|
61
|
+
export interface ManagedCollection {
|
|
62
|
+
/** The extension's own id for it. */
|
|
63
|
+
id: string;
|
|
64
|
+
/** Its number (sm-dev's `C3`); absent for a run's test collection. */
|
|
65
|
+
number?: number;
|
|
66
|
+
name: string;
|
|
67
|
+
kind: 'container' | 'directory' | 'manifest';
|
|
68
|
+
/** A directory's or manifest's location; none for a container. */
|
|
69
|
+
location?: string;
|
|
70
|
+
/** A run's test collection: the run's id in the extension (`D1-ab12`). */
|
|
71
|
+
run?: string;
|
|
72
|
+
enabled: boolean;
|
|
73
|
+
/** Why its last scan failed. */
|
|
74
|
+
error?: string;
|
|
75
|
+
scriptCount: number;
|
|
76
|
+
}
|
|
77
|
+
/** An installed script, as the extension's `managedScripts` lists it. */
|
|
78
|
+
export interface ManagedScript {
|
|
79
|
+
/** The extension's own id for it. */
|
|
80
|
+
id: string;
|
|
81
|
+
/**
|
|
82
|
+
* Its number (sm-dev's `E12`); absent in a run's test collection, and
|
|
83
|
+
* until the worker gives it one.
|
|
84
|
+
*/
|
|
85
|
+
number?: number;
|
|
86
|
+
name: string;
|
|
87
|
+
namespace?: string;
|
|
88
|
+
version?: string;
|
|
89
|
+
/** Where it is loaded from: for a run's script, its `scratch:` URL. */
|
|
90
|
+
location: string;
|
|
91
|
+
/** A run's script: the file it was read from, as a `file://` URL. */
|
|
92
|
+
sourceFile?: string;
|
|
93
|
+
/** A run's script: its path as the run was given it, often relative. */
|
|
94
|
+
loadedAs?: string;
|
|
95
|
+
collectionId: string;
|
|
96
|
+
enabled: boolean;
|
|
97
|
+
status: 'ok' | 'invalid';
|
|
98
|
+
/** Why it is invalid. */
|
|
99
|
+
error?: string;
|
|
100
|
+
/** Why its last refresh failed, while its last good copy still runs. */
|
|
101
|
+
refreshError?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Set by sm-dev, under another manager (external-manager.ts): a
|
|
104
|
+
* run's script, whose run is live (`D1`).
|
|
105
|
+
*/
|
|
106
|
+
run?: string;
|
|
107
|
+
/** Set by sm-dev, under another manager: a run's script, left by that run when it ended (`D1`). */
|
|
108
|
+
leftBy?: string;
|
|
109
|
+
}
|
|
110
|
+
/** A `@require` or `@resource`, as `managed.scriptDetails` gives it. */
|
|
111
|
+
export interface ManagedFile {
|
|
112
|
+
/** As the header gives it. */
|
|
113
|
+
url: string;
|
|
114
|
+
/** `@resource`'s name. */
|
|
115
|
+
name?: string;
|
|
116
|
+
/** Loaded, or not: a script that failed to load has none. Absent when the manager doesn't say. */
|
|
117
|
+
loaded?: boolean;
|
|
118
|
+
/** The local file read in its place. */
|
|
119
|
+
local?: string;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* A `@require` or `@resource` file's installed contents, for `script
|
|
123
|
+
* print --file` and `script save` (`managed.scriptFiles`). sm-dev puts
|
|
124
|
+
* a script's `@icon` in this shape too.
|
|
125
|
+
*/
|
|
126
|
+
export interface ManagedFileContent {
|
|
127
|
+
kind: 'require' | 'resource' | 'icon';
|
|
128
|
+
/** Its URL, resolved. */
|
|
129
|
+
url: string;
|
|
130
|
+
/** `@resource`'s name. */
|
|
131
|
+
name?: string;
|
|
132
|
+
/**
|
|
133
|
+
* Where `script save` writes it, relative to the script: an http(s)
|
|
134
|
+
* URL's `<host>/<path>`, as the viewer's local copy lays it out, or a
|
|
135
|
+
* `file:` URL's file name. Absent when there is none (a `data:` URL).
|
|
136
|
+
*/
|
|
137
|
+
path?: string;
|
|
138
|
+
/** Its bytes. */
|
|
139
|
+
base64: string;
|
|
140
|
+
contentType?: string;
|
|
141
|
+
}
|
|
142
|
+
/** A script's icons, for `script show`, `print` and `save` (`managed.scriptIcons`). */
|
|
143
|
+
export interface ManagedScriptIcons {
|
|
144
|
+
/** Its own `@icon` (or an alias); absent for none. */
|
|
145
|
+
icon?: {
|
|
146
|
+
/** Resolved against the script's own location. */
|
|
147
|
+
url: string;
|
|
148
|
+
/** Where `script save` writes it, as `ManagedFileContent.path`. */
|
|
149
|
+
path?: string;
|
|
150
|
+
/** The local file that stands in for it, as for a `@require`. */
|
|
151
|
+
local?: string;
|
|
152
|
+
/** Its bytes, when asked to load them and they could be read. */
|
|
153
|
+
base64?: string;
|
|
154
|
+
contentType?: string;
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* The site icons a page heading shows for it, merged and in order.
|
|
158
|
+
* Absent when not all were in the cache and it wasn't asked to load
|
|
159
|
+
* them.
|
|
160
|
+
*/
|
|
161
|
+
siteIcons?: ManagedSiteIcon[];
|
|
162
|
+
}
|
|
163
|
+
/** What `managed.scriptIcons` reads or looks up, beyond what it has at hand. */
|
|
164
|
+
export interface ScriptIconsLoad {
|
|
165
|
+
icon?: boolean;
|
|
166
|
+
sites?: boolean;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Where a discovered site icon came from: Chrome's `/_favicon/` DB, the
|
|
170
|
+
* page's `<link rel="icon">`, the site's `/favicon.ico`, or Google S2.
|
|
171
|
+
*/
|
|
172
|
+
export type IconSource = 'favicon-store' | 'page' | 'favicon.ico' | 'google';
|
|
173
|
+
/** One of a script's site icons: absent bytes for the globe (none found). */
|
|
174
|
+
export interface ManagedSiteIcon {
|
|
175
|
+
/** The sites it stands for, by the URL its icon links to, its own first. */
|
|
176
|
+
sites: string[];
|
|
177
|
+
/**
|
|
178
|
+
* What `script save` names it, without the extension: its site's
|
|
179
|
+
* host (`github.com`), with the page's path when the icon is that
|
|
180
|
+
* page's own (`npmjs.com/package`).
|
|
181
|
+
*/
|
|
182
|
+
name: string;
|
|
183
|
+
/** Where it came from; absent for an icon cached before that was kept. */
|
|
184
|
+
source?: IconSource;
|
|
185
|
+
base64?: string;
|
|
186
|
+
contentType?: string;
|
|
187
|
+
}
|
|
188
|
+
/** An installed script in full, for `script show` (`managed.scriptDetails`). */
|
|
189
|
+
export interface ManagedScriptDetails extends ManagedScript {
|
|
190
|
+
description?: string;
|
|
191
|
+
author?: string;
|
|
192
|
+
/** When its current text was loaded, in epoch ms; absent if never. */
|
|
193
|
+
updatedAt?: number;
|
|
194
|
+
match: string[];
|
|
195
|
+
include: string[];
|
|
196
|
+
exclude: string[];
|
|
197
|
+
excludeMatch: string[];
|
|
198
|
+
/** As the header gives it; absent for none (`document-idle`). */
|
|
199
|
+
runAt?: string;
|
|
200
|
+
grants: string[];
|
|
201
|
+
requires: ManagedFile[];
|
|
202
|
+
resources: ManagedFile[];
|
|
203
|
+
/** Absent when the manager doesn't say. */
|
|
204
|
+
valueCount?: number;
|
|
205
|
+
}
|
|
206
|
+
/** What `managed.refreshScript` did. */
|
|
207
|
+
export interface ScriptRefresh {
|
|
208
|
+
script: ManagedScript;
|
|
209
|
+
/** It loaded different text. */
|
|
210
|
+
updated: boolean;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* What the disk says of the local scripts and collections, as the
|
|
214
|
+
* collections page's chips show it: `managed.onDisk`. Only those that
|
|
215
|
+
* differ are listed.
|
|
216
|
+
*/
|
|
217
|
+
export interface ManagedOnDisk {
|
|
218
|
+
/** By script id: its file changed, or is gone, since it was loaded. */
|
|
219
|
+
scripts: Record<string, 'modified' | 'deleted'>;
|
|
220
|
+
/** By collection id: what a refresh would load (script-display.ts). */
|
|
221
|
+
collections: Record<string, PendingOnDisk>;
|
|
222
|
+
}
|
|
223
|
+
/** What `managed.refreshCollection` did. */
|
|
224
|
+
export interface CollectionRefresh {
|
|
225
|
+
collection: ManagedCollection;
|
|
226
|
+
/** Its scripts after: added or with different text (`updated`), unchanged, and removed (as they were). */
|
|
227
|
+
updated: ManagedScript[];
|
|
228
|
+
unchanged: number;
|
|
229
|
+
removed: ManagedScript[];
|
|
230
|
+
/**
|
|
231
|
+
* Its scripts that couldn't be refreshed, each with `refreshError`.
|
|
232
|
+
* Set by sm-dev under another manager, never sent by the extension.
|
|
233
|
+
*/
|
|
234
|
+
failed?: ManagedScript[];
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* What turning a script on did: `managed.setScriptEnabled`,
|
|
238
|
+
* `moveScript` and `installScript`.
|
|
239
|
+
*/
|
|
240
|
+
export interface ScriptEnable {
|
|
241
|
+
script: ManagedScript;
|
|
242
|
+
/** Its other copies that were running, turned off as the viewer does. */
|
|
243
|
+
turnedOff: ManagedScript[];
|
|
244
|
+
}
|
|
245
|
+
/** What `managed.installScript` did. */
|
|
246
|
+
export interface ScriptInstall extends ScriptEnable {
|
|
247
|
+
/** It was already installed in that collection, so nothing changed. */
|
|
248
|
+
already?: true;
|
|
249
|
+
/** Set by sm-dev, under another manager: it replaced the script with the same name and namespace. */
|
|
250
|
+
replaced?: true;
|
|
251
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// What the extension and sm-dev both use. Their own module so the
|
|
2
|
+
// harness can name them without loading the claim code in
|
|
3
|
+
// sm-dev-link.ts.
|
|
4
|
+
/** The first argument of every event's console line. */
|
|
5
|
+
export const SM_DEV_EVENT = 'sm-dev-event';
|
|
6
|
+
/**
|
|
7
|
+
* Refusals of the `managed` calls (managed-changes.ts), which sm-dev
|
|
8
|
+
* also checks before asking for `--force`.
|
|
9
|
+
*/
|
|
10
|
+
export const RUN_COLLECTION_LOCKED = 'An sm-dev run\'s test collection is changed only by its run';
|
|
11
|
+
export const LISTED_BY_LOCATION = 'This script is listed by a directory or manifest collection, so it stays there while its file does. Only a script in a container collection can be moved or uninstalled.';
|
|
12
|
+
export const CONTAINER_TARGET_ONLY = 'Scripts can only be installed or moved into a container collection';
|
|
13
|
+
/**
|
|
14
|
+
* Why a manual script (`@run-at context-menu`) can't be run on a tab
|
|
15
|
+
* now: `runManualScript`'s answers, which the popup logs and sm-dev
|
|
16
|
+
* prints after the script's name. See docs/manual-scripts.md.
|
|
17
|
+
*/
|
|
18
|
+
export const MANUAL_RUN_NOT_INSTALLED = 'This script is not installed';
|
|
19
|
+
export const MANUAL_RUN_NOT_MANUAL = 'This script runs when a page loads. Only a script with @run-at context-menu is run on request.';
|
|
20
|
+
export const MANUAL_RUN_SCRIPT_OFF = 'This script is turned off';
|
|
21
|
+
export const MANUAL_RUN_COLLECTION_OFF = 'This script\'s collection is turned off';
|
|
22
|
+
export const MANUAL_RUN_NOT_HERE = 'This script\'s @match and @include rules don\'t cover this page';
|
|
23
|
+
export const MANUAL_RUN_PAGE = 'SourceMonkey can\'t run scripts on this page';
|
|
24
|
+
export const MANUAL_RUN_TAB_GONE = 'The tab was closed';
|
|
25
|
+
export const MANUAL_RUN_PAGE_CHANGED = 'The page changed before the script could run. Try again.';
|
|
26
|
+
export const MANUAL_RUN_SM_DEV = 'The sm-dev run controlling this tab keeps this script out';
|
|
27
|
+
/**
|
|
28
|
+
* The event types of the markers sm-dev puts in its browser's pages,
|
|
29
|
+
* which tell a `document-start` wrapper whether it can run without
|
|
30
|
+
* asking the extension (`smDevMarker` in userscript-prelude.js, which
|
|
31
|
+
* has its own copy). See docs/sm-dev-design.md#making-wrappers-ask.
|
|
32
|
+
* - `present`: in every page. sm-dev is connected, so any tab may be
|
|
33
|
+
* claimed.
|
|
34
|
+
* - `vouchPrefix` + the run's id: in a tab that run claims, while its
|
|
35
|
+
* scripts are on.
|
|
36
|
+
*/
|
|
37
|
+
export const SM_DEV_MARKERS = {
|
|
38
|
+
present: 'sourcemonkey-sm-dev',
|
|
39
|
+
vouchPrefix: 'sourcemonkey-sm-dev-run:',
|
|
40
|
+
};
|
|
41
|
+
/** The reason a skipped wrapper reports for a tab an sm-dev run controls. */
|
|
42
|
+
export const SKIP_REASON_SM_DEV = 'tab controlled by sm-dev';
|
|
43
|
+
/**
|
|
44
|
+
* The version of the calls and events between sm-dev and the extension,
|
|
45
|
+
* which each side has its own copy of: sm-dev from a repo's install, the
|
|
46
|
+
* extension from the person's browser. A run compares them as it
|
|
47
|
+
* connects (extension-link.ts). See CLAUDE.md for when to bump which.
|
|
48
|
+
* - `major`: a change that needs both sides updated. A run refuses an
|
|
49
|
+
* extension whose major differs.
|
|
50
|
+
* - `minor`: an addition. An extension ahead is fine. An sm-dev ahead
|
|
51
|
+
* checks the extension's minor before using what came later
|
|
52
|
+
* (`ExtensionLink.requireMinor`).
|
|
53
|
+
*/
|
|
54
|
+
// 1.1: `scriptsOnTab` rows carry the script's number.
|
|
55
|
+
// 1.2: `managedCollections` and `managedScripts`; `writeRunScript`
|
|
56
|
+
// takes the script's `source` file, which `managedScripts` gives back.
|
|
57
|
+
// 1.3: permission prompts: `connect-prompt` events, `answerConnectPrompt`.
|
|
58
|
+
// 1.4: a report event can carry `detail`: why a script had no decision.
|
|
59
|
+
// 1.5: `managed`, the calls that change collections and installed
|
|
60
|
+
// scripts (`managed.setScriptEnabled` and the rest), and
|
|
61
|
+
// `managed.scriptDetails` / `managed.scriptText` (managed-changes.ts).
|
|
62
|
+
// 1.6: manual scripts (`@run-at context-menu`): `runManualScript`, and
|
|
63
|
+
// the `sm:manual` report for one waiting in a new document.
|
|
64
|
+
// 1.7: a script's badge status can be `UNTRACKED`: its page loaded
|
|
65
|
+
// before the extension started.
|
|
66
|
+
// 2.0: wrappers no longer all ask while a claim is live; sm-dev marks
|
|
67
|
+
// the pages of its browser instead (`SM_DEV_MARKERS`), which an older
|
|
68
|
+
// sm-dev doesn't, so the extension would run scripts in its tabs.
|
|
69
|
+
// 2.1: scripts run in iframes, so report and menu events now come from
|
|
70
|
+
// frames too (`topFrame: false`); `fireActionContextMenuItem` takes
|
|
71
|
+
// the command's `documentId`.
|
|
72
|
+
// 2.2: `request`, `download`, `values` and a shown `notification` event
|
|
73
|
+
// carry the sending document's `documentId`, which says which frame.
|
|
74
|
+
// 2.3: `managed.scriptFiles`, a script's `@require` and `@resource`
|
|
75
|
+
// files as installed.
|
|
76
|
+
// 2.4: `managed.scriptIcons`, a script's `@icon` and its site icons.
|
|
77
|
+
// 3.0: every script runs in the page's world unless it asks to be
|
|
78
|
+
// isolated. sm-dev works out each script's world itself, for
|
|
79
|
+
// `eval --script` and for whose error a page error could be, so an
|
|
80
|
+
// older one would look in the wrong world. On a page whose CSP
|
|
81
|
+
// `sandbox` turns off script in its own world, the page-world scripts
|
|
82
|
+
// run isolated instead, which sm-dev notes rather than warning that
|
|
83
|
+
// they can't run.
|
|
84
|
+
export const SM_DEV_PROTOCOL = { major: 3, minor: 0 };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare function encodeVlq(value: number): string;
|
|
2
|
+
export interface MappedSegment {
|
|
3
|
+
url: string;
|
|
4
|
+
content: string;
|
|
5
|
+
generatedLine: number;
|
|
6
|
+
lineCount: number;
|
|
7
|
+
}
|
|
8
|
+
export interface SourceMapV3 {
|
|
9
|
+
version: 3;
|
|
10
|
+
file: string;
|
|
11
|
+
sources: string[];
|
|
12
|
+
sourcesContent: string[];
|
|
13
|
+
names: never[];
|
|
14
|
+
mappings: string;
|
|
15
|
+
}
|
|
16
|
+
export declare function buildSourceMap(args: {
|
|
17
|
+
file: string;
|
|
18
|
+
segments: readonly MappedSegment[];
|
|
19
|
+
totalLines: number;
|
|
20
|
+
}): SourceMapV3;
|
|
21
|
+
export interface OriginalPosition {
|
|
22
|
+
url: string;
|
|
23
|
+
line: number;
|
|
24
|
+
}
|
|
25
|
+
export declare function lookupGeneratedLine(segments: readonly MappedSegment[], generatedLine: number): OriginalPosition | null;
|
|
26
|
+
export interface StackRef {
|
|
27
|
+
url: string;
|
|
28
|
+
line: number;
|
|
29
|
+
col: number;
|
|
30
|
+
}
|
|
31
|
+
export declare function remapStackRef(ref: StackRef, entryUrl: string, segments: readonly MappedSegment[]): StackRef | null;
|
|
32
|
+
export declare function inlineSourceMapComment(map: SourceMapV3): string;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// Minimal Source Map v3 generator for the concatenated injection entry.
|
|
2
|
+
//
|
|
3
|
+
// Why: in Mode A (see docs/injection-modes.md) a script's `@require`
|
|
4
|
+
// bodies and its own body are concatenated into ONE `js[]` entry so
|
|
5
|
+
// they share a lexical scope. That's what makes a library's top-level
|
|
6
|
+
// `const`/`class` visible to the main body, exactly as in TM/VM — but
|
|
7
|
+
// it also means the main body's line N no longer lands at physical
|
|
8
|
+
// line N, and every require loses the devtools file it used to have.
|
|
9
|
+
//
|
|
10
|
+
// A source map buys both back: devtools splits the single generated
|
|
11
|
+
// script into the original files and reports original line numbers.
|
|
12
|
+
//
|
|
13
|
+
// Scope of this generator:
|
|
14
|
+
//
|
|
15
|
+
// - **Line-level only.** One mapping per generated line, always at
|
|
16
|
+
// column 0. We never move code within a line, so column fidelity
|
|
17
|
+
// would be busywork; line granularity is what stack traces and
|
|
18
|
+
// breakpoints need.
|
|
19
|
+
// - **`sourcesContent` is always embedded.** Our sources are
|
|
20
|
+
// synthetic `sourcemonkey://…` URLs, which devtools cannot fetch,
|
|
21
|
+
// so embedding the text is the only way the mapped files are
|
|
22
|
+
// viewable. It is also the expensive part: the sources ship a
|
|
23
|
+
// second time, base64'd, so the entry grows by ~1.6× their size.
|
|
24
|
+
//
|
|
25
|
+
// There is deliberately no size cap on this. The only constraint
|
|
26
|
+
// that actually binds is whether `chrome.userScripts.register()`
|
|
27
|
+
// accepts the payload, and that failure is already visible:
|
|
28
|
+
// `registerWithFallback` in src/extension/injector.ts drops from batch to
|
|
29
|
+
// per-script registration on rejection and records the reason
|
|
30
|
+
// against that script (which then reads REJECTED, with Chrome's
|
|
31
|
+
// wording), so an oversized script fails loudly and by name. A preemptive cap would trade that for silently degrading
|
|
32
|
+
// the feature the map exists to provide. The map does NOT touch
|
|
33
|
+
// our `chrome.storage.local` quota — it's generated at
|
|
34
|
+
// registration time from sources already stored.
|
|
35
|
+
//
|
|
36
|
+
// What V8 does NOT do for us: map `Error.stack` *strings*. It maps
|
|
37
|
+
// source positions for the devtools UI, but `err.stack` keeps
|
|
38
|
+
// generated coordinates, and SourceMonkey parses those strings for the
|
|
39
|
+
// viewer's Log tab (src/stack-link.ts). `remapStackRef` below is the
|
|
40
|
+
// other half — the Log tab applies the same segment list itself, so a
|
|
41
|
+
// logged frame names the same file and line devtools shows. See
|
|
42
|
+
// docs/script-log.md#stack-refs-are-source-mapped-first.
|
|
43
|
+
// Base64 VLQ, per the Source Map v3 spec.
|
|
44
|
+
const B64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
45
|
+
// Domain: |value| < 2^30. Above that the `<< 1` wraps negative and the
|
|
46
|
+
// loop emits a single wrong digit. Every caller here passes a line or
|
|
47
|
+
// source index, so this is unreachable — noted so nobody reuses the
|
|
48
|
+
// function for byte offsets.
|
|
49
|
+
export function encodeVlq(value) {
|
|
50
|
+
// Sign goes in the low bit, magnitude above it.
|
|
51
|
+
let vlq = value < 0 ? ((-value) << 1) | 1 : value << 1;
|
|
52
|
+
let out = '';
|
|
53
|
+
do {
|
|
54
|
+
let digit = vlq & 0b11111;
|
|
55
|
+
vlq >>>= 5;
|
|
56
|
+
// Continuation bit: more 5-bit groups follow.
|
|
57
|
+
if (vlq > 0)
|
|
58
|
+
digit |= 0b100000;
|
|
59
|
+
out += B64[digit];
|
|
60
|
+
} while (vlq > 0);
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
// Build the map object. `totalLines` is the generated entry's line
|
|
64
|
+
// count; generated lines not covered by any segment (the wrap's head
|
|
65
|
+
// and tail, the `;` separators) get an empty group, which devtools
|
|
66
|
+
// reads as "no original position" and leaves attributed to the
|
|
67
|
+
// generated file.
|
|
68
|
+
//
|
|
69
|
+
// `file` is deliberately the same URL as the entry's own
|
|
70
|
+
// `//# sourceURL=`, which is also `sources[last]` (the script's own
|
|
71
|
+
// body). Bundlers avoid that collision — devtools keys files by URL,
|
|
72
|
+
// so a mapped source sharing its generated script's URL could in
|
|
73
|
+
// principle show up twice, or empty. Verified in Chrome's Sources
|
|
74
|
+
// panel that it doesn't: the mapped file shadows the generated one,
|
|
75
|
+
// and a script with one `@require` shows exactly two entries — the
|
|
76
|
+
// `.user.js` and the require nested under a `<host>/<path>` subtree —
|
|
77
|
+
// both with their original text. Keeping the URLs identical is what
|
|
78
|
+
// lets the Log tab's stack-ref linkification match on one string.
|
|
79
|
+
export function buildSourceMap(args) {
|
|
80
|
+
const sources = args.segments.map((s) => s.url);
|
|
81
|
+
// generatedLine → {sourceIndex, originalLine}. Later segments win on
|
|
82
|
+
// overlap, which can't happen for the layouts we generate but keeps
|
|
83
|
+
// the function total.
|
|
84
|
+
const perLine = new Map();
|
|
85
|
+
args.segments.forEach((seg, srcIdx) => {
|
|
86
|
+
for (let k = 0; k < seg.lineCount; k++) {
|
|
87
|
+
perLine.set(seg.generatedLine + k, { srcIdx, origLine: k });
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
// VLQ fields after the first are deltas against the previous
|
|
91
|
+
// segment, carried across line groups (only the generated column
|
|
92
|
+
// resets per line — and ours is always 0, so it never contributes).
|
|
93
|
+
let prevSrcIdx = 0;
|
|
94
|
+
let prevOrigLine = 0;
|
|
95
|
+
const groups = [];
|
|
96
|
+
for (let gen = 0; gen < args.totalLines; gen++) {
|
|
97
|
+
const hit = perLine.get(gen);
|
|
98
|
+
if (!hit) {
|
|
99
|
+
groups.push('');
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
groups.push(encodeVlq(0) +
|
|
103
|
+
encodeVlq(hit.srcIdx - prevSrcIdx) +
|
|
104
|
+
encodeVlq(hit.origLine - prevOrigLine) +
|
|
105
|
+
encodeVlq(0));
|
|
106
|
+
prevSrcIdx = hit.srcIdx;
|
|
107
|
+
prevOrigLine = hit.origLine;
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
version: 3,
|
|
111
|
+
file: args.file,
|
|
112
|
+
sources,
|
|
113
|
+
sourcesContent: args.segments.map((seg) => seg.content),
|
|
114
|
+
names: [],
|
|
115
|
+
mappings: groups.join(';'),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
// Look up the original file + line for a 1-based generated line.
|
|
119
|
+
// Returns null for lines no segment covers. In 1-based terms those are
|
|
120
|
+
// line 1 (the wrap head), each `// @require` marker line, each `;` ASI
|
|
121
|
+
// guard between requires, and the closing `});`. They are ours, not
|
|
122
|
+
// the user's, so leaving them unmapped is correct — the caller drops
|
|
123
|
+
// the link rather than pointing at a neighbouring line.
|
|
124
|
+
export function lookupGeneratedLine(segments, generatedLine) {
|
|
125
|
+
const gen0 = generatedLine - 1;
|
|
126
|
+
for (const seg of segments) {
|
|
127
|
+
if (gen0 >= seg.generatedLine && gen0 < seg.generatedLine + seg.lineCount) {
|
|
128
|
+
return { url: seg.url, line: gen0 - seg.generatedLine + 1 };
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
// Rewrite a stack ref that points into the concatenated entry so it
|
|
134
|
+
// names the original `@require` (or the body) at its own line.
|
|
135
|
+
//
|
|
136
|
+
// Every frame from the combined entry carries `entryUrl` — the
|
|
137
|
+
// script's own `//# sourceURL=`, which V8 stamps on the whole entry
|
|
138
|
+
// regardless of which concatenated file the code came from. So the
|
|
139
|
+
// URL match is the test for "is this frame ours to remap"; refs to
|
|
140
|
+
// anything else (the page, another userscript, `__prelude.js`) pass
|
|
141
|
+
// through untouched.
|
|
142
|
+
//
|
|
143
|
+
// Columns pass through unchanged, and that is exact rather than
|
|
144
|
+
// approximate: composition only ever moves whole lines, never code
|
|
145
|
+
// within a line. A script with NO requires has no segments at all, so
|
|
146
|
+
// it returns early — see the layout notes in composed-source.ts for
|
|
147
|
+
// the column caveat that applies to that case.
|
|
148
|
+
export function remapStackRef(ref, entryUrl, segments) {
|
|
149
|
+
if (segments.length === 0)
|
|
150
|
+
return null;
|
|
151
|
+
if (ref.url !== entryUrl)
|
|
152
|
+
return null;
|
|
153
|
+
const orig = lookupGeneratedLine(segments, ref.line);
|
|
154
|
+
if (!orig)
|
|
155
|
+
return null;
|
|
156
|
+
return { url: orig.url, line: orig.line, col: ref.col };
|
|
157
|
+
}
|
|
158
|
+
// UTF-8 → base64. `btoa` alone throws on any code point above U+00FF,
|
|
159
|
+
// and userscripts are full of them (the script that prompted Mode A is
|
|
160
|
+
// half Chinese). Encode to bytes first, then base64 the byte string.
|
|
161
|
+
function base64Utf8(text) {
|
|
162
|
+
const bytes = new TextEncoder().encode(text);
|
|
163
|
+
let binary = '';
|
|
164
|
+
// Chunked so a large source doesn't blow the argument limit on
|
|
165
|
+
// String.fromCharCode.apply.
|
|
166
|
+
const CHUNK = 0x8000;
|
|
167
|
+
for (let i = 0; i < bytes.length; i += CHUNK) {
|
|
168
|
+
binary += String.fromCharCode(...bytes.subarray(i, i + CHUNK));
|
|
169
|
+
}
|
|
170
|
+
return btoa(binary);
|
|
171
|
+
}
|
|
172
|
+
// The `//# sourceMappingURL=` line to append to the generated entry.
|
|
173
|
+
// Inline data URI because a `sourcemonkey://` map URL would be no more
|
|
174
|
+
// fetchable than the sources themselves.
|
|
175
|
+
export function inlineSourceMapComment(map) {
|
|
176
|
+
return `//# sourceMappingURL=data:application/json;charset=utf-8;base64,${base64Utf8(JSON.stringify(map))}`;
|
|
177
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { StackLayout } from './composed-source.js';
|
|
2
|
+
export type RefRun = {
|
|
3
|
+
kind: 'text';
|
|
4
|
+
text: string;
|
|
5
|
+
} | {
|
|
6
|
+
kind: 'ref';
|
|
7
|
+
text: string;
|
|
8
|
+
url: string;
|
|
9
|
+
line: number;
|
|
10
|
+
col: number;
|
|
11
|
+
};
|
|
12
|
+
export declare function parseStackRefs(text: string): RefRun[];
|
|
13
|
+
export declare function displayRefText(text: string, url: string): string;
|
|
14
|
+
export declare function remapStackText(text: string, layouts: Iterable<StackLayout>): string;
|
|
15
|
+
export declare const WRAPPER_FILE = "__wrapper.js";
|