@chromahq/manifest 0.0.1
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/dist/defineExtension.d.ts +23 -0
- package/dist/index.d.ts +2 -0
- package/dist/inferPermissions.d.ts +2 -0
- package/dist/manifest.cjs.js +84 -0
- package/dist/manifest.es.js +81 -0
- package/dist/plugin.d.ts +3 -0
- package/package.json +50 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface ExtensionConfig {
|
|
2
|
+
/** Visible name (dev overrides add suffix) */
|
|
3
|
+
name: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
version?: string;
|
|
6
|
+
popup?: boolean;
|
|
7
|
+
icons?: 'auto' | Record<string, string>;
|
|
8
|
+
permissions?: string[];
|
|
9
|
+
hostPermissions?: string[];
|
|
10
|
+
background?: {
|
|
11
|
+
service_worker: string;
|
|
12
|
+
};
|
|
13
|
+
contentScripts?: {
|
|
14
|
+
js: string[];
|
|
15
|
+
matches: string[];
|
|
16
|
+
}[];
|
|
17
|
+
dev?: Partial<ExtensionConfig>;
|
|
18
|
+
content_security_policy?: {
|
|
19
|
+
extension_pages?: string;
|
|
20
|
+
sandbox?: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export declare function defineExtension(config: ExtensionConfig): ExtensionConfig;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var unplugin = require('unplugin');
|
|
4
|
+
var fs = require('node:fs');
|
|
5
|
+
var path = require('node:path');
|
|
6
|
+
|
|
7
|
+
function defineExtension(config) {
|
|
8
|
+
return config;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function inferPermissions(base) {
|
|
12
|
+
const perms = new Set(base.permissions ?? []);
|
|
13
|
+
return Array.from(perms);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const bootstrapPath = path.join('src', 'bootstrap.ts');
|
|
17
|
+
const popupPath = path.resolve(process.cwd(), 'index.html');
|
|
18
|
+
const configFilePath = path.resolve(process.cwd(), 'chroma.config.js');
|
|
19
|
+
const chroma = unplugin.createVitePlugin((options) => {
|
|
20
|
+
let config;
|
|
21
|
+
let backgroundAbs;
|
|
22
|
+
let popupAbs;
|
|
23
|
+
return {
|
|
24
|
+
name: 'chroma-manifest',
|
|
25
|
+
async buildStart() { },
|
|
26
|
+
async options(rollupOpts) {
|
|
27
|
+
const configPath = options?.configFile ?? configFilePath;
|
|
28
|
+
const userConfig = await import(configPath);
|
|
29
|
+
config = { ...(userConfig.default ?? userConfig) };
|
|
30
|
+
backgroundAbs = path.resolve(path.join(path.dirname(configPath), bootstrapPath));
|
|
31
|
+
popupAbs = popupPath;
|
|
32
|
+
rollupOpts.input = { sw: backgroundAbs, popup: popupAbs };
|
|
33
|
+
return rollupOpts;
|
|
34
|
+
},
|
|
35
|
+
generateBundle(_outOpts, bundle) {
|
|
36
|
+
let iconMap = {};
|
|
37
|
+
if (config.icons) {
|
|
38
|
+
const icons = typeof config.icons === 'string' ? [config.icons] : Object.values(config.icons);
|
|
39
|
+
icons.forEach((icon) => {
|
|
40
|
+
const iconPath = path.resolve(process.cwd(), icon);
|
|
41
|
+
if (fs.existsSync(iconPath)) {
|
|
42
|
+
const iconName = path.basename(iconPath);
|
|
43
|
+
iconMap[icon] = `icons/${iconName}`;
|
|
44
|
+
this.emitFile({
|
|
45
|
+
type: 'asset',
|
|
46
|
+
fileName: `icons/${iconName}`,
|
|
47
|
+
source: fs.readFileSync(iconPath),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
Object.values(bundle).forEach((chunk) => {
|
|
53
|
+
if ('facadeModuleId' in chunk && chunk.facadeModuleId === backgroundAbs) {
|
|
54
|
+
chunk.fileName = 'sw.js';
|
|
55
|
+
}
|
|
56
|
+
if ('facadeModuleId' in chunk && chunk.facadeModuleId === popupAbs) {
|
|
57
|
+
chunk.fileName = 'popup.js';
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
const pkgPath = path.resolve(process.cwd(), 'package.json');
|
|
61
|
+
const pkg = fs.existsSync(pkgPath) ? JSON.parse(fs.readFileSync(pkgPath, 'utf-8')) : {};
|
|
62
|
+
config.version = config.version ? config.version : (pkg.version ?? '0.0.1');
|
|
63
|
+
const manifest = {
|
|
64
|
+
manifest_version: 3,
|
|
65
|
+
name: config.name,
|
|
66
|
+
version: config.version,
|
|
67
|
+
description: config.description,
|
|
68
|
+
content_security_policy: config.content_security_policy ?? undefined,
|
|
69
|
+
action: config.popup ? { default_popup: 'index.html' } : undefined,
|
|
70
|
+
icons: Object.fromEntries(Object.entries(config.icons ?? {}).map(([size, icon]) => [size, iconMap[icon] || icon])),
|
|
71
|
+
background: { type: 'module', service_worker: 'sw.js' },
|
|
72
|
+
permissions: inferPermissions(config),
|
|
73
|
+
};
|
|
74
|
+
this.emitFile({
|
|
75
|
+
type: 'asset',
|
|
76
|
+
fileName: 'manifest.json',
|
|
77
|
+
source: JSON.stringify(manifest, null, 2),
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
exports.chroma = chroma;
|
|
84
|
+
exports.defineExtension = defineExtension;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { createVitePlugin } from 'unplugin';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
function defineExtension(config) {
|
|
6
|
+
return config;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function inferPermissions(base) {
|
|
10
|
+
const perms = new Set(base.permissions ?? []);
|
|
11
|
+
return Array.from(perms);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const bootstrapPath = path.join('src', 'bootstrap.ts');
|
|
15
|
+
const popupPath = path.resolve(process.cwd(), 'index.html');
|
|
16
|
+
const configFilePath = path.resolve(process.cwd(), 'chroma.config.js');
|
|
17
|
+
const chroma = createVitePlugin((options) => {
|
|
18
|
+
let config;
|
|
19
|
+
let backgroundAbs;
|
|
20
|
+
let popupAbs;
|
|
21
|
+
return {
|
|
22
|
+
name: 'chroma-manifest',
|
|
23
|
+
async buildStart() { },
|
|
24
|
+
async options(rollupOpts) {
|
|
25
|
+
const configPath = options?.configFile ?? configFilePath;
|
|
26
|
+
const userConfig = await import(configPath);
|
|
27
|
+
config = { ...(userConfig.default ?? userConfig) };
|
|
28
|
+
backgroundAbs = path.resolve(path.join(path.dirname(configPath), bootstrapPath));
|
|
29
|
+
popupAbs = popupPath;
|
|
30
|
+
rollupOpts.input = { sw: backgroundAbs, popup: popupAbs };
|
|
31
|
+
return rollupOpts;
|
|
32
|
+
},
|
|
33
|
+
generateBundle(_outOpts, bundle) {
|
|
34
|
+
let iconMap = {};
|
|
35
|
+
if (config.icons) {
|
|
36
|
+
const icons = typeof config.icons === 'string' ? [config.icons] : Object.values(config.icons);
|
|
37
|
+
icons.forEach((icon) => {
|
|
38
|
+
const iconPath = path.resolve(process.cwd(), icon);
|
|
39
|
+
if (fs.existsSync(iconPath)) {
|
|
40
|
+
const iconName = path.basename(iconPath);
|
|
41
|
+
iconMap[icon] = `icons/${iconName}`;
|
|
42
|
+
this.emitFile({
|
|
43
|
+
type: 'asset',
|
|
44
|
+
fileName: `icons/${iconName}`,
|
|
45
|
+
source: fs.readFileSync(iconPath),
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
Object.values(bundle).forEach((chunk) => {
|
|
51
|
+
if ('facadeModuleId' in chunk && chunk.facadeModuleId === backgroundAbs) {
|
|
52
|
+
chunk.fileName = 'sw.js';
|
|
53
|
+
}
|
|
54
|
+
if ('facadeModuleId' in chunk && chunk.facadeModuleId === popupAbs) {
|
|
55
|
+
chunk.fileName = 'popup.js';
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
const pkgPath = path.resolve(process.cwd(), 'package.json');
|
|
59
|
+
const pkg = fs.existsSync(pkgPath) ? JSON.parse(fs.readFileSync(pkgPath, 'utf-8')) : {};
|
|
60
|
+
config.version = config.version ? config.version : (pkg.version ?? '0.0.1');
|
|
61
|
+
const manifest = {
|
|
62
|
+
manifest_version: 3,
|
|
63
|
+
name: config.name,
|
|
64
|
+
version: config.version,
|
|
65
|
+
description: config.description,
|
|
66
|
+
content_security_policy: config.content_security_policy ?? undefined,
|
|
67
|
+
action: config.popup ? { default_popup: 'index.html' } : undefined,
|
|
68
|
+
icons: Object.fromEntries(Object.entries(config.icons ?? {}).map(([size, icon]) => [size, iconMap[icon] || icon])),
|
|
69
|
+
background: { type: 'module', service_worker: 'sw.js' },
|
|
70
|
+
permissions: inferPermissions(config),
|
|
71
|
+
};
|
|
72
|
+
this.emitFile({
|
|
73
|
+
type: 'asset',
|
|
74
|
+
fileName: 'manifest.json',
|
|
75
|
+
source: JSON.stringify(manifest, null, 2),
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
export { chroma, defineExtension };
|
package/dist/plugin.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@chromahq/manifest",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Manifest generation and build tooling for Chroma Chrome extensions",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/manifest.cjs.js",
|
|
7
|
+
"module": "dist/manifest.es.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/manifest.es.js",
|
|
15
|
+
"types": "./dist/index.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "https://github.com/chromaHQ/chroma.git",
|
|
24
|
+
"directory": "packages/manifest"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"chrome-extension",
|
|
28
|
+
"browser-extension",
|
|
29
|
+
"manifest",
|
|
30
|
+
"build-tools",
|
|
31
|
+
"vite-plugin",
|
|
32
|
+
"typescript"
|
|
33
|
+
],
|
|
34
|
+
"author": "Chroma Team",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"homepage": "https://github.com/chromaHQ/chroma#readme",
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/chromaHQ/chroma/issues"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@rollup/plugin-typescript": "^12.1.3",
|
|
42
|
+
"fast-glob": "^3.3.2",
|
|
43
|
+
"inversify": "^7.5.2",
|
|
44
|
+
"unplugin": "^2.3.5"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "rollup -c",
|
|
48
|
+
"dev": "rollup -c --watch"
|
|
49
|
+
}
|
|
50
|
+
}
|