@stacksjs/browser-extension 0.70.148 → 0.70.150
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/README.md +12 -1
- package/dist/build.js +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/manifest.d.ts +1 -1
- package/dist/manifest.js +6 -2
- package/dist/scaffold.d.ts +22 -0
- package/dist/scaffold.js +92 -0
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,13 +11,24 @@ packaging owned by the framework.
|
|
|
11
11
|
## Quick start
|
|
12
12
|
|
|
13
13
|
```sh
|
|
14
|
-
buddy extension:init # scaffold
|
|
14
|
+
buddy extension:init # scaffold Chrome + Firefox + Safari, including the Xcode app
|
|
15
|
+
buddy extension:init --target safari --name "My Extension" --bundle-id com.example.MyExtension
|
|
15
16
|
buddy extension:build # build all targets → dist/ (+ dist-firefox/)
|
|
16
17
|
buddy extension:build --target chrome
|
|
17
18
|
buddy extension:build --target safari # → dist-safari/ (browser.* namespace, safari manifest)
|
|
18
19
|
buddy extension:package # build + zip store-ready archives
|
|
19
20
|
```
|
|
20
21
|
|
|
22
|
+
Use `icons` for full-color store/app branding and `actionIcons` for separate,
|
|
23
|
+
usually neutral artwork in the browser toolbar:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
defineExtension({
|
|
27
|
+
icons: { 16: 'icons/icon-16.png', 128: 'icons/icon-128.png' },
|
|
28
|
+
actionIcons: { 16: 'icons/toolbar-16.png', 32: 'icons/toolbar-32.png' },
|
|
29
|
+
})
|
|
30
|
+
```
|
|
31
|
+
|
|
21
32
|
## Store publishing
|
|
22
33
|
|
|
23
34
|
Stacks owns the store-specific upload clients as well as the builds. Chrome
|
package/dist/build.js
CHANGED
|
@@ -69,12 +69,12 @@ export async function buildExtension(config, options) {
|
|
|
69
69
|
const pages = pageEntries(config.pages);
|
|
70
70
|
await Promise.all(pages.filter((p) => p.page.script).map((p) => buildScript(p.page.script, `${p.name}.js`, outdir, cwd, minify)));
|
|
71
71
|
if (pages.length) {
|
|
72
|
-
const { default: stxPlugin } = await import("bun-plugin-stx"), result = await Bun.build({
|
|
72
|
+
const { default: stxPlugin } = await import("bun-plugin-stx"), resourcesPartials = resolve(cwd, "resources/partials"), legacyPartials = resolve(cwd, "partials"), partialsDir = existsSync(resourcesPartials) ? resourcesPartials : legacyPartials, result = await Bun.build({
|
|
73
73
|
entrypoints: pages.map((p) => resolve(cwd, p.page.template)),
|
|
74
74
|
outdir,
|
|
75
75
|
minify,
|
|
76
76
|
naming: { entry: "[name].html" },
|
|
77
|
-
plugins: [stxPlugin()]
|
|
77
|
+
plugins: [stxPlugin({ partialsDir })]
|
|
78
78
|
});
|
|
79
79
|
if (!result.success)
|
|
80
80
|
throw Error(`[browser-extension] failed to build pages: ${result.logs.join(`
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/manifest.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare interface GeneratedManifest {
|
|
|
17
17
|
description: string
|
|
18
18
|
version: string
|
|
19
19
|
minimum_chrome_version?: string
|
|
20
|
-
action?: { default_title?: string, default_popup?: string }
|
|
20
|
+
action?: { default_title?: string, default_popup?: string, default_icon?: Record<string, string> }
|
|
21
21
|
options_page?: string
|
|
22
22
|
background?: { service_worker: string, type?: 'module' } | { scripts: string[], type?: 'module' }
|
|
23
23
|
browser_specific_settings?: {
|
package/dist/manifest.js
CHANGED
|
@@ -11,8 +11,12 @@ export function generateManifest(config, opts) {
|
|
|
11
11
|
};
|
|
12
12
|
if (!isFirefox && !isSafari && m.minimumChromeVersion)
|
|
13
13
|
manifest.minimum_chrome_version = m.minimumChromeVersion;
|
|
14
|
-
if (config.pages?.popup)
|
|
15
|
-
manifest.action = {
|
|
14
|
+
if (config.pages?.popup || config.actionIcons)
|
|
15
|
+
manifest.action = {
|
|
16
|
+
default_title: config.name,
|
|
17
|
+
...config.pages?.popup ? { default_popup: "popup.html" } : {},
|
|
18
|
+
...config.actionIcons ? { default_icon: Object.fromEntries(Object.entries(config.actionIcons).map(([size, path]) => [String(size), path])) } : {}
|
|
19
|
+
};
|
|
16
20
|
if (config.pages?.options)
|
|
17
21
|
manifest.options_page = "options.html";
|
|
18
22
|
if (config.background)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { scaffoldSafariApp } from './safari';
|
|
2
|
+
import type { ExtensionConfig, ExtensionTarget, SafariPlatform } from './types';
|
|
3
|
+
export declare function resolveExtensionScaffoldTargets(target?: ExtensionScaffoldTarget): ExtensionTarget[];
|
|
4
|
+
/** Scaffold a complete cross-browser extension, including Safari's container app. */
|
|
5
|
+
export declare function scaffoldExtensionProject(options?: ExtensionProjectScaffoldOptions): Promise<ExtensionProjectScaffoldResult>;
|
|
6
|
+
export declare interface ExtensionProjectScaffoldOptions {
|
|
7
|
+
cwd?: string
|
|
8
|
+
name?: string
|
|
9
|
+
target?: ExtensionScaffoldTarget
|
|
10
|
+
bundleId?: string
|
|
11
|
+
teamId?: string
|
|
12
|
+
platforms?: SafariPlatform[]
|
|
13
|
+
version?: string
|
|
14
|
+
force?: boolean
|
|
15
|
+
}
|
|
16
|
+
export declare interface ExtensionProjectScaffoldResult {
|
|
17
|
+
config: ExtensionConfig
|
|
18
|
+
written: string[]
|
|
19
|
+
skipped: string[]
|
|
20
|
+
safari?: Awaited<ReturnType<typeof scaffoldSafariApp>>
|
|
21
|
+
}
|
|
22
|
+
export type ExtensionScaffoldTarget = ExtensionTarget | 'all';
|
package/dist/scaffold.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { mkdir } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import process from "node:process";
|
|
5
|
+
import { scaffoldSafariApp } from "./safari";
|
|
6
|
+
export function resolveExtensionScaffoldTargets(target = "all") {
|
|
7
|
+
return target === "all" ? ["chrome", "firefox", "safari"] : [target];
|
|
8
|
+
}
|
|
9
|
+
function safariAppName(name) {
|
|
10
|
+
return name.replace(/[^A-Za-z0-9]/g, "") || "MyExtension";
|
|
11
|
+
}
|
|
12
|
+
function quotedList(values) {
|
|
13
|
+
return `[${values.map((value) => `'${value}'`).join(", ")}]`;
|
|
14
|
+
}
|
|
15
|
+
function extensionConfigSource(config) {
|
|
16
|
+
const safari = config.targets?.includes("safari") ? `
|
|
17
|
+
safariBundleId: '${config.safariBundleId}',
|
|
18
|
+
safariPlatforms: ${quotedList(config.safariPlatforms ?? ["macos", "ios"])},
|
|
19
|
+
safariAppCategory: 'public.app-category.utilities',${config.safariTeamId ? `
|
|
20
|
+
safariTeamId: '${config.safariTeamId}',` : ""}` : "", firefox = config.targets?.includes("firefox") ? `
|
|
21
|
+
// Replace this before publishing to Mozilla Add-ons.
|
|
22
|
+
geckoId: 'extension@example.com',` : "";
|
|
23
|
+
return `import { defineExtension } from '@stacksjs/browser-extension'
|
|
24
|
+
|
|
25
|
+
export default defineExtension({
|
|
26
|
+
name: ${JSON.stringify(config.name)},
|
|
27
|
+
description: 'A browser extension built with Stacks.',
|
|
28
|
+
targets: ${quotedList(config.targets ?? [])},${firefox}${safari}
|
|
29
|
+
background: 'src/background/index.ts',
|
|
30
|
+
content: [
|
|
31
|
+
{ entry: 'src/content/index.ts', matches: ['<all_urls>'], runAt: 'document_start' },
|
|
32
|
+
],
|
|
33
|
+
pages: {
|
|
34
|
+
popup: { template: 'resources/views/popup.stx', script: 'resources/scripts/popup.ts' },
|
|
35
|
+
},
|
|
36
|
+
public: 'public',
|
|
37
|
+
manifest: {
|
|
38
|
+
permissions: ['storage', 'tabs'],
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
`;
|
|
42
|
+
}
|
|
43
|
+
export async function scaffoldExtensionProject(options = {}) {
|
|
44
|
+
const cwd = options.cwd ?? process.cwd(), name = options.name ?? "My Extension", targets = resolveExtensionScaffoldTargets(options.target), appName = safariAppName(name), config = {
|
|
45
|
+
name,
|
|
46
|
+
description: "A browser extension built with Stacks.",
|
|
47
|
+
targets,
|
|
48
|
+
background: "src/background/index.ts",
|
|
49
|
+
content: [{ entry: "src/content/index.ts", matches: ["<all_urls>"], runAt: "document_start" }],
|
|
50
|
+
pages: { popup: { template: "resources/views/popup.stx", script: "resources/scripts/popup.ts" } },
|
|
51
|
+
public: "public",
|
|
52
|
+
manifest: { permissions: ["storage", "tabs"] },
|
|
53
|
+
...targets.includes("firefox") && { geckoId: "extension@example.com" },
|
|
54
|
+
...targets.includes("safari") && {
|
|
55
|
+
safariBundleId: options.bundleId ?? `com.example.${appName}`,
|
|
56
|
+
safariTeamId: options.teamId,
|
|
57
|
+
safariPlatforms: options.platforms ?? ["macos", "ios"],
|
|
58
|
+
safariAppCategory: "public.app-category.utilities"
|
|
59
|
+
}
|
|
60
|
+
}, written = [], skipped = [], write = async (relative, content) => {
|
|
61
|
+
const absolute = join(cwd, relative);
|
|
62
|
+
if (existsSync(absolute) && !options.force) {
|
|
63
|
+
skipped.push(relative);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
await mkdir(dirname(absolute), { recursive: !0 });
|
|
67
|
+
await Bun.write(absolute, content);
|
|
68
|
+
written.push(relative);
|
|
69
|
+
};
|
|
70
|
+
await write("config/extension.ts", extensionConfigSource(config));
|
|
71
|
+
await write("src/background/index.ts", `console.log(${JSON.stringify(`[${name}] background ready`)})
|
|
72
|
+
`);
|
|
73
|
+
await write("src/content/index.ts", `console.log(${JSON.stringify(`[${name}] content script loaded`)})
|
|
74
|
+
`);
|
|
75
|
+
await write("resources/scripts/popup.ts", `console.log(${JSON.stringify(`[${name}] popup ready`)})
|
|
76
|
+
`);
|
|
77
|
+
await write("resources/views/popup.stx", `<main class="popup">
|
|
78
|
+
<h1>${name}</h1>
|
|
79
|
+
<p>Edit resources/views/popup.stx to build your popup.</p>
|
|
80
|
+
<script src="/popup.js"></script>
|
|
81
|
+
</main>
|
|
82
|
+
`);
|
|
83
|
+
await mkdir(join(cwd, "public"), { recursive: !0 });
|
|
84
|
+
const safari = targets.includes("safari") ? await scaffoldSafariApp(config, {
|
|
85
|
+
cwd,
|
|
86
|
+
bundleId: config.safariBundleId,
|
|
87
|
+
teamId: config.safariTeamId,
|
|
88
|
+
version: options.version,
|
|
89
|
+
force: options.force
|
|
90
|
+
}) : void 0;
|
|
91
|
+
return { config, written, skipped, safari };
|
|
92
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -144,6 +144,7 @@ export declare interface ExtensionConfig {
|
|
|
144
144
|
content?: ContentScript[]
|
|
145
145
|
pages?: ExtensionPages
|
|
146
146
|
icons?: Record<number, string>
|
|
147
|
+
actionIcons?: Record<number, string>
|
|
147
148
|
public?: string
|
|
148
149
|
assets?: Record<string, string>
|
|
149
150
|
rules?: RuleResource[]
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/browser-extension",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.70.
|
|
4
|
+
"version": "0.70.150",
|
|
5
5
|
"description": "Build MV3 browser extensions (Chrome, Firefox, Safari) the Stacks way — manifest, content/background scripts, DNR rules, packaging, Safari container app, all config-driven.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
7
|
"contributors": [
|