@xlinklight/browser-extension-tools 1.0.0-rc.0 → 1.0.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 CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 zopenge
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 zopenge
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,33 +1,33 @@
1
- # Browser extension tools
2
-
3
- This development package owns the reusable browser runtime assets, unpacked development preparation, profile management, reload companion and deterministic ZIP packager. Product extensions and their tests belong to the consuming repository. This package has no business extension list or default selection.
4
-
5
- Install it as a development dependency. Both commands require an explicit source collection below the current repository and an explicit selection:
6
-
7
- ```sh
8
- link-light-extension-dev --extension-root=extensions --extension=neutral-capture --app-url=http://localhost:3000 --watch-extension
9
- link-light-extension-package --extension-root=extensions --extension=neutral-capture
10
- ```
11
-
12
- `--extensions=one,two` and `--extensions=all` select multiple extensions from that same explicit collection. `--with-next` is rejected; the backend is an explicit independent application URL. The existing Chrome discovery and optional Chrome for Testing installation controls remain available.
13
-
14
- Each extension directory owns its manifest and every other product asset. The tools copy every owned file, including additional workflow files and binary icons; the reserved top-level `shared` directory comes only from this package. Linked source entries are rejected. Public resources resolve through `@xlinklight/browser-extension-tools/shared/js/<file>.js` and `shared/css/<file>.css`; consumers do not read another repository's source.
15
-
16
- The packager reads `config/local/extension.local.json`:
17
-
18
- ```json
19
- {
20
- "origin": "https://application.example",
21
- "pluginToken": "local-secret",
22
- "outputDir": ".tmp/browser-extensions/package/unpacked",
23
- "zipFile": ".tmp/browser-extensions/package/extension.zip"
24
- }
25
- ```
26
-
27
- Outputs must stay below this repository's `.tmp/` or `dist/`. A single selection uses the configured paths exactly. Multiple selections use `<outputDir>/<name>/` and `<zipFile stem>-<name>.zip`. The manifest and configuration are generated for the explicit HTTPS origin; the ZIP has deterministic entry order and metadata. Source configuration is never changed.
28
-
29
- Development output uses fixed `.tmp/browser-extensions/<name>/unpacked` directories and `.tmp/browser-extensions/profiles/<name>` (or `multiple`) profiles. Chrome for Testing uses `.tmp/browser-extensions/chrome-for-testing`. Repeated preparation replaces the same output; the visible build label derives from source bytes. Profiles remain until an explicit `--reset-profile` request. Watchers, reload servers and installer cancellation retain their owned cleanup behavior.
30
-
31
- Public JavaScript entrypoints are `/dev`, `/cli`, `/package` and `/installer`. `packageChromeExtension({rootDir, extensionRoot, extensionNames, config?, logger?})` and `prepareDevExtension({rootDir, extensionRoot, extensionName, appUrl, reloadPort?, signal?})` also support controlled callers with explicit inputs.
32
-
33
- Run `pnpm --filter @xlinklight/browser-extension-tools test` for filesystem and public API controls. Root extension tooling tests cover browser launch selection, profiles, cancellation and reload behavior without downloading a browser.
1
+ # Browser extension tools
2
+
3
+ This development package owns the reusable browser runtime assets, unpacked development preparation, profile management, reload companion and deterministic ZIP packager. Product extensions and their tests belong to the consuming repository. This package has no business extension list or default selection.
4
+
5
+ Install it as a development dependency. Both commands require an explicit source collection below the current repository and an explicit selection:
6
+
7
+ ```sh
8
+ link-light-extension-dev --extension-root=extensions --extension=neutral-capture --app-url=http://localhost:3000 --watch-extension
9
+ link-light-extension-package --extension-root=extensions --extension=neutral-capture
10
+ ```
11
+
12
+ `--extensions=one,two` and `--extensions=all` select multiple extensions from that same explicit collection. `--with-next` is rejected; the backend is an explicit independent application URL. The existing Chrome discovery and optional Chrome for Testing installation controls remain available.
13
+
14
+ Each extension directory owns its manifest and every other product asset. The tools copy every owned file, including additional workflow files and binary icons; the reserved top-level `shared` directory comes only from this package. Linked source entries are rejected. Public resources resolve through `@xlinklight/browser-extension-tools/shared/js/<file>.js` and `shared/css/<file>.css`; consumers do not read another repository's source.
15
+
16
+ The packager reads `config/local/extension.local.json`:
17
+
18
+ ```json
19
+ {
20
+ "origin": "https://application.example",
21
+ "pluginToken": "local-secret",
22
+ "outputDir": ".tmp/browser-extensions/package/unpacked",
23
+ "zipFile": ".tmp/browser-extensions/package/extension.zip"
24
+ }
25
+ ```
26
+
27
+ Outputs must stay below this repository's `.tmp/` or `dist/`. A single selection uses the configured paths exactly. Multiple selections use `<outputDir>/<name>/` and `<zipFile stem>-<name>.zip`. The manifest and configuration are generated for the explicit HTTPS origin; the ZIP has deterministic entry order and metadata. Source configuration is never changed.
28
+
29
+ Development output uses fixed `.tmp/browser-extensions/<name>/unpacked` directories and `.tmp/browser-extensions/profiles/<name>` (or `multiple`) profiles. Chrome for Testing uses `.tmp/browser-extensions/chrome-for-testing`. Repeated preparation replaces the same output; the visible build label derives from source bytes. Profiles remain until an explicit `--reset-profile` request. Watchers, reload servers and installer cancellation retain their owned cleanup behavior.
30
+
31
+ Public JavaScript entrypoints are `/dev`, `/cli`, `/package` and `/installer`. `packageChromeExtension({rootDir, extensionRoot, extensionNames, config?, logger?})` and `prepareDevExtension({rootDir, extensionRoot, extensionName, appUrl, reloadPort?, signal?})` also support controlled callers with explicit inputs.
32
+
33
+ Run `pnpm --filter @xlinklight/browser-extension-tools test` for filesystem and public API controls. Root extension tooling tests cover browser launch selection, profiles, cancellation and reload behavior without downloading a browser.
@@ -1,94 +1,94 @@
1
- :root {
2
- color-scheme: light;
3
- }
4
-
5
- * {
6
- box-sizing: border-box;
7
- }
8
-
9
- body {
10
- margin: 0;
11
- }
12
-
13
- button,
14
- input,
15
- select,
16
- textarea {
17
- font: inherit;
18
- }
19
-
20
- .ll-tab-page[hidden],
21
- .ll-user-menu[hidden] {
22
- display: none;
23
- }
24
-
25
- .ll-account {
26
- display: grid;
27
- place-items: center;
28
- width: 38px;
29
- height: 38px;
30
- margin-top: auto;
31
- border: 0;
32
- border-radius: 999px;
33
- color: #ffffff;
34
- background: var(--ll-account-color, #0f766e);
35
- cursor: pointer;
36
- font-size: 12px;
37
- font-weight: 800;
38
- }
39
-
40
- .ll-user-menu {
41
- position: fixed;
42
- right: 62px;
43
- bottom: 14px;
44
- z-index: 10;
45
- display: grid;
46
- gap: 8px;
47
- width: min(260px, calc(100vw - 84px));
48
- padding: 12px;
49
- border: 1px solid #e2e8f0;
50
- border-radius: 14px;
51
- background: #ffffff;
52
- box-shadow: 0 18px 45px rgb(15 23 42 / 18%);
53
- }
54
-
55
- .ll-user-profile {
56
- display: grid;
57
- gap: 2px;
58
- padding-bottom: 8px;
59
- border-bottom: 1px solid #eef2f7;
60
- }
61
-
62
- .ll-user-email {
63
- color: #0f172a;
64
- font-size: 13px;
65
- font-weight: 700;
66
- }
67
-
68
- .ll-user-workspace,
69
- .ll-user-plan {
70
- color: #64748b;
71
- font-size: 12px;
72
- }
73
-
74
- .ll-user-plan {
75
- padding: 9px;
76
- border-radius: 10px;
77
- color: var(--ll-account-plan-color, #0f766e);
78
- background: var(--ll-account-plan-bg, #ecfeff);
79
- font-weight: 700;
80
- }
81
-
82
- .ll-menu-action {
83
- min-height: 32px;
84
- border: 0;
85
- border-radius: 8px;
86
- color: #172033;
87
- background: transparent;
88
- text-align: left;
89
- cursor: pointer;
90
- }
91
-
92
- .ll-menu-action:hover {
93
- background: #f8fafc;
94
- }
1
+ :root {
2
+ color-scheme: light;
3
+ }
4
+
5
+ * {
6
+ box-sizing: border-box;
7
+ }
8
+
9
+ body {
10
+ margin: 0;
11
+ }
12
+
13
+ button,
14
+ input,
15
+ select,
16
+ textarea {
17
+ font: inherit;
18
+ }
19
+
20
+ .ll-tab-page[hidden],
21
+ .ll-user-menu[hidden] {
22
+ display: none;
23
+ }
24
+
25
+ .ll-account {
26
+ display: grid;
27
+ place-items: center;
28
+ width: 38px;
29
+ height: 38px;
30
+ margin-top: auto;
31
+ border: 0;
32
+ border-radius: 999px;
33
+ color: #ffffff;
34
+ background: var(--ll-account-color, #0f766e);
35
+ cursor: pointer;
36
+ font-size: 12px;
37
+ font-weight: 800;
38
+ }
39
+
40
+ .ll-user-menu {
41
+ position: fixed;
42
+ right: 62px;
43
+ bottom: 14px;
44
+ z-index: 10;
45
+ display: grid;
46
+ gap: 8px;
47
+ width: min(260px, calc(100vw - 84px));
48
+ padding: 12px;
49
+ border: 1px solid #e2e8f0;
50
+ border-radius: 14px;
51
+ background: #ffffff;
52
+ box-shadow: 0 18px 45px rgb(15 23 42 / 18%);
53
+ }
54
+
55
+ .ll-user-profile {
56
+ display: grid;
57
+ gap: 2px;
58
+ padding-bottom: 8px;
59
+ border-bottom: 1px solid #eef2f7;
60
+ }
61
+
62
+ .ll-user-email {
63
+ color: #0f172a;
64
+ font-size: 13px;
65
+ font-weight: 700;
66
+ }
67
+
68
+ .ll-user-workspace,
69
+ .ll-user-plan {
70
+ color: #64748b;
71
+ font-size: 12px;
72
+ }
73
+
74
+ .ll-user-plan {
75
+ padding: 9px;
76
+ border-radius: 10px;
77
+ color: var(--ll-account-plan-color, #0f766e);
78
+ background: var(--ll-account-plan-bg, #ecfeff);
79
+ font-weight: 700;
80
+ }
81
+
82
+ .ll-menu-action {
83
+ min-height: 32px;
84
+ border: 0;
85
+ border-radius: 8px;
86
+ color: #172033;
87
+ background: transparent;
88
+ text-align: left;
89
+ cursor: pointer;
90
+ }
91
+
92
+ .ll-menu-action:hover {
93
+ background: #f8fafc;
94
+ }
@@ -1,87 +1,87 @@
1
- (function initializeLinkLightChromeRuntime(global) {
2
- function normalizeOrigin(value) {
3
- return String(value || "http://localhost:3000").replace(/\/+$/, "");
4
- }
5
-
6
- function normalizeLocale(locale) {
7
- const normalized = String(locale || "").toLowerCase();
8
- if (normalized.startsWith("en")) return "en-US";
9
- return "zh-CN";
10
- }
11
-
12
- function createChromeRuntime(options = {}) {
13
- const chromeApi = options.chromeApi || global.chrome;
14
- const config = options.config || global.LINK_LIGHT_CONFIG || {};
15
- const origin = normalizeOrigin(config.origin);
16
- const pluginToken = String(config.pluginToken || "");
17
-
18
- const storage = {
19
- async get(keys) {
20
- return (await chromeApi?.storage?.local?.get?.(keys)) || {};
21
- },
22
- async set(values) {
23
- await chromeApi?.storage?.local?.set?.(values);
24
- },
25
- async remove(keys) {
26
- await chromeApi?.storage?.local?.remove?.(keys);
27
- },
28
- };
29
-
30
- async function loadLocaleMessages(directory) {
31
- const url = chromeApi?.runtime?.getURL
32
- ? chromeApi.runtime.getURL(`_locales/${directory}/messages.json`)
33
- : `_locales/${directory}/messages.json`;
34
- const response = await global.fetch(url);
35
- return response.json();
36
- }
37
-
38
- async function sendMessage(message) {
39
- return chromeApi?.runtime?.sendMessage?.(message);
40
- }
41
-
42
- async function requestOrigins(origins) {
43
- if (!chromeApi?.permissions?.request) return true;
44
- return chromeApi.permissions.request({ origins });
45
- }
46
-
47
- async function containsOrigins(origins) {
48
- if (!chromeApi?.permissions?.contains) return false;
49
- return chromeApi.permissions.contains({ origins });
50
- }
51
-
52
- function openPopup(url, options = {}) {
53
- const width = options.width || 1280;
54
- const height = options.height || 820;
55
- if (chromeApi?.windows?.create) {
56
- chromeApi.windows.create({ url, type: "popup", width, height }).catch(() => {
57
- global.open(url, "_blank", "noopener");
58
- });
59
- return;
60
- }
61
- global.open(url, "_blank", "noopener");
62
- }
63
-
64
- function getUILocale() {
65
- return normalizeLocale(chromeApi?.i18n?.getMessage?.("@@ui_locale"));
66
- }
67
-
68
- function getExtensionUrl(path) {
69
- return chromeApi?.runtime?.getURL ? chromeApi.runtime.getURL(path) : path;
70
- }
71
-
72
- return {
73
- containsOrigins,
74
- getExtensionUrl,
75
- getUILocale,
76
- loadLocaleMessages,
77
- openPopup,
78
- origin,
79
- pluginToken,
80
- requestOrigins,
81
- sendMessage,
82
- storage,
83
- };
84
- }
85
-
86
- global.LinkLightChromeRuntime = { createChromeRuntime };
87
- })(globalThis);
1
+ (function initializeLinkLightChromeRuntime(global) {
2
+ function normalizeOrigin(value) {
3
+ return String(value || "http://localhost:3000").replace(/\/+$/, "");
4
+ }
5
+
6
+ function normalizeLocale(locale) {
7
+ const normalized = String(locale || "").toLowerCase();
8
+ if (normalized.startsWith("en")) return "en-US";
9
+ return "zh-CN";
10
+ }
11
+
12
+ function createChromeRuntime(options = {}) {
13
+ const chromeApi = options.chromeApi || global.chrome;
14
+ const config = options.config || global.LINK_LIGHT_CONFIG || {};
15
+ const origin = normalizeOrigin(config.origin);
16
+ const pluginToken = String(config.pluginToken || "");
17
+
18
+ const storage = {
19
+ async get(keys) {
20
+ return (await chromeApi?.storage?.local?.get?.(keys)) || {};
21
+ },
22
+ async set(values) {
23
+ await chromeApi?.storage?.local?.set?.(values);
24
+ },
25
+ async remove(keys) {
26
+ await chromeApi?.storage?.local?.remove?.(keys);
27
+ },
28
+ };
29
+
30
+ async function loadLocaleMessages(directory) {
31
+ const url = chromeApi?.runtime?.getURL
32
+ ? chromeApi.runtime.getURL(`_locales/${directory}/messages.json`)
33
+ : `_locales/${directory}/messages.json`;
34
+ const response = await global.fetch(url);
35
+ return response.json();
36
+ }
37
+
38
+ async function sendMessage(message) {
39
+ return chromeApi?.runtime?.sendMessage?.(message);
40
+ }
41
+
42
+ async function requestOrigins(origins) {
43
+ if (!chromeApi?.permissions?.request) return true;
44
+ return chromeApi.permissions.request({ origins });
45
+ }
46
+
47
+ async function containsOrigins(origins) {
48
+ if (!chromeApi?.permissions?.contains) return false;
49
+ return chromeApi.permissions.contains({ origins });
50
+ }
51
+
52
+ function openPopup(url, options = {}) {
53
+ const width = options.width || 1280;
54
+ const height = options.height || 820;
55
+ if (chromeApi?.windows?.create) {
56
+ chromeApi.windows.create({ url, type: "popup", width, height }).catch(() => {
57
+ global.open(url, "_blank", "noopener");
58
+ });
59
+ return;
60
+ }
61
+ global.open(url, "_blank", "noopener");
62
+ }
63
+
64
+ function getUILocale() {
65
+ return normalizeLocale(chromeApi?.i18n?.getMessage?.("@@ui_locale"));
66
+ }
67
+
68
+ function getExtensionUrl(path) {
69
+ return chromeApi?.runtime?.getURL ? chromeApi.runtime.getURL(path) : path;
70
+ }
71
+
72
+ return {
73
+ containsOrigins,
74
+ getExtensionUrl,
75
+ getUILocale,
76
+ loadLocaleMessages,
77
+ openPopup,
78
+ origin,
79
+ pluginToken,
80
+ requestOrigins,
81
+ sendMessage,
82
+ storage,
83
+ };
84
+ }
85
+
86
+ global.LinkLightChromeRuntime = { createChromeRuntime };
87
+ })(globalThis);