adnbn 0.0.2 → 0.0.4
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/bin/adnbn.mjs +2 -0
- package/dist/src/cli/builders/app.js +20 -0
- package/dist/src/cli/builders/manifest/ManifestBase.js +63 -0
- package/dist/src/cli/builders/manifest/ManifestV2.js +35 -0
- package/dist/src/cli/builders/manifest/ManifestV3.js +35 -0
- package/dist/src/cli/builders/manifest/index.js +13 -0
- package/dist/src/cli/index.js +47 -0
- package/dist/src/cli/parsers/entrypoint/OptionFile.js +48 -0
- package/dist/src/cli/parsers/entrypoint/SourceFile.js +180 -0
- package/dist/src/cli/parsers/entrypoint/index.js +20 -0
- package/dist/src/cli/plugins/background.js +96 -0
- package/dist/src/cli/plugins/content.js +32 -0
- package/dist/src/cli/resolvers/config.js +105 -0
- package/dist/src/cli/resolvers/path.js +23 -0
- package/dist/src/cli/resolvers/webpack.js +108 -0
- package/dist/src/cli/utils/entrypoint.js +60 -0
- package/dist/src/cli/utils/option.js +14 -0
- package/dist/src/cli/utils/plugin.js +29 -0
- package/dist/src/cli/webpack/plugins/EntryDependenciesPlugin.js +56 -0
- package/dist/src/core/define.js +15 -0
- package/dist/src/index.js +11 -0
- package/dist/src/types/background.js +2 -0
- package/dist/src/types/base.js +2 -0
- package/dist/src/types/config.js +18 -0
- package/dist/src/types/content.js +2 -0
- package/dist/src/types/manifest.js +2 -0
- package/dist/src/types/plugin.js +2 -0
- package/package.json +7 -4
- package/bin/cli.mjs +0 -1
package/bin/adnbn.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const webpack_1 = __importDefault(require("webpack"));
|
|
7
|
+
const config_1 = __importDefault(require("../resolvers/config"));
|
|
8
|
+
const webpack_2 = __importDefault(require("../resolvers/webpack"));
|
|
9
|
+
exports.default = async (config) => {
|
|
10
|
+
const resolverConfig = await (0, config_1.default)(config);
|
|
11
|
+
const webpackConfig = await (0, webpack_2.default)(resolverConfig);
|
|
12
|
+
const compiler = (0, webpack_1.default)(webpackConfig);
|
|
13
|
+
compiler.run((err, stats) => {
|
|
14
|
+
if (err) {
|
|
15
|
+
console.error('Webpack compilation error');
|
|
16
|
+
process.exit(1);
|
|
17
|
+
}
|
|
18
|
+
console.log(stats?.toString({ colors: true }));
|
|
19
|
+
});
|
|
20
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const config_1 = require("@typing/config");
|
|
4
|
+
class default_1 {
|
|
5
|
+
browser;
|
|
6
|
+
name = "__MSG_app_name__";
|
|
7
|
+
shortName = "__MSG_app_short_name__";
|
|
8
|
+
description = "__MSG_app_description__";
|
|
9
|
+
version = "0.0.0";
|
|
10
|
+
background;
|
|
11
|
+
contentScripts = new Map();
|
|
12
|
+
constructor(browser = config_1.Browser.Chrome) {
|
|
13
|
+
this.browser = browser;
|
|
14
|
+
}
|
|
15
|
+
setName(name) {
|
|
16
|
+
this.name = name;
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
setShortName(shortName) {
|
|
20
|
+
this.shortName = shortName;
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
setDescription(description) {
|
|
24
|
+
this.description = description;
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
setVersion(version) {
|
|
28
|
+
this.version = version;
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
resetBackground(background) {
|
|
32
|
+
this.background = background;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
pushContentScript(...content) {
|
|
36
|
+
for (const script of content) {
|
|
37
|
+
this.contentScripts.set(script.entry, script);
|
|
38
|
+
}
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
marge(manifest, ...sources) {
|
|
42
|
+
sources = sources.filter((source) => source !== undefined);
|
|
43
|
+
if (sources.length === 0) {
|
|
44
|
+
return manifest;
|
|
45
|
+
}
|
|
46
|
+
return Object.assign({}, manifest, ...sources);
|
|
47
|
+
}
|
|
48
|
+
build() {
|
|
49
|
+
let manifest = {
|
|
50
|
+
name: this.name,
|
|
51
|
+
short_name: this.shortName,
|
|
52
|
+
description: this.description,
|
|
53
|
+
version: this.version,
|
|
54
|
+
manifest_version: this.getManifestVersion(),
|
|
55
|
+
};
|
|
56
|
+
manifest = this.marge(manifest, this.buildBackground(), this.buildContentScripts());
|
|
57
|
+
return manifest;
|
|
58
|
+
}
|
|
59
|
+
get() {
|
|
60
|
+
return this.build();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.default = default_1;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const ManifestBase_1 = __importDefault(require("./ManifestBase"));
|
|
7
|
+
class default_1 extends ManifestBase_1.default {
|
|
8
|
+
constructor(browser) {
|
|
9
|
+
super(browser);
|
|
10
|
+
}
|
|
11
|
+
getManifestVersion() {
|
|
12
|
+
return 2;
|
|
13
|
+
}
|
|
14
|
+
buildBackground() {
|
|
15
|
+
if (this.background) {
|
|
16
|
+
const { file, persistent } = this.background;
|
|
17
|
+
return { background: { scripts: [file], persistent } };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
buildContentScripts() {
|
|
21
|
+
if (this.contentScripts.size > 0) {
|
|
22
|
+
const contentScripts = Array.from(this.contentScripts, ([_, contentScript]) => ({
|
|
23
|
+
matches: contentScript.matches,
|
|
24
|
+
js: [contentScript.file],
|
|
25
|
+
exclude_matches: contentScript.excludeMatches,
|
|
26
|
+
all_frames: contentScript.allFrames,
|
|
27
|
+
run_at: contentScript.runAt,
|
|
28
|
+
exclude_globs: contentScript.excludeGlobs,
|
|
29
|
+
include_globs: contentScript.includeGlobs,
|
|
30
|
+
}));
|
|
31
|
+
return { content_scripts: contentScripts };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.default = default_1;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const ManifestBase_1 = __importDefault(require("./ManifestBase"));
|
|
7
|
+
class default_1 extends ManifestBase_1.default {
|
|
8
|
+
constructor(browser) {
|
|
9
|
+
super(browser);
|
|
10
|
+
}
|
|
11
|
+
getManifestVersion() {
|
|
12
|
+
return 3;
|
|
13
|
+
}
|
|
14
|
+
buildBackground() {
|
|
15
|
+
if (this.background) {
|
|
16
|
+
return { background: { service_worker: this.background.file } };
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
buildContentScripts() {
|
|
20
|
+
if (this.contentScripts.size > 0) {
|
|
21
|
+
const contentScripts = Array.from(this.contentScripts, ([_, contentScript]) => ({
|
|
22
|
+
matches: contentScript.matches,
|
|
23
|
+
exclude_matches: contentScript.excludeMatches,
|
|
24
|
+
js: [contentScript.file],
|
|
25
|
+
all_frames: contentScript.allFrames,
|
|
26
|
+
run_at: contentScript.runAt,
|
|
27
|
+
exclude_globs: contentScript.excludeGlobs,
|
|
28
|
+
include_globs: contentScript.includeGlobs,
|
|
29
|
+
world: contentScript.world,
|
|
30
|
+
}));
|
|
31
|
+
return { content_scripts: contentScripts };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.default = default_1;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const ManifestV2_1 = __importDefault(require("./ManifestV2"));
|
|
7
|
+
const ManifestV3_1 = __importDefault(require("./ManifestV3"));
|
|
8
|
+
exports.default = (browser, manifestVersion) => {
|
|
9
|
+
if (manifestVersion === 2) {
|
|
10
|
+
return new ManifestV2_1.default(browser);
|
|
11
|
+
}
|
|
12
|
+
return new ManifestV3_1.default(browser);
|
|
13
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const cac_1 = __importDefault(require("cac"));
|
|
7
|
+
const config_1 = require("@typing/config");
|
|
8
|
+
const app_1 = __importDefault(require("./builders/app"));
|
|
9
|
+
const cli = (0, cac_1.default)('addonbone');
|
|
10
|
+
cli.option('--debug', 'Enable debug mode');
|
|
11
|
+
cli
|
|
12
|
+
.command('init', 'Initialize a new project')
|
|
13
|
+
.action(() => {
|
|
14
|
+
console.log('init');
|
|
15
|
+
});
|
|
16
|
+
cli
|
|
17
|
+
.command('[root]', 'Start dev server')
|
|
18
|
+
.option('-m, --mode <mode>', 'Set env mode', { default: 'development', })
|
|
19
|
+
.option('-c, --config <config>', 'Path to config file')
|
|
20
|
+
.option('-a, --app <app>', 'Specify an app to run', { default: 'myapp' })
|
|
21
|
+
.option('-b, --browser <browser>', 'Specify a browser')
|
|
22
|
+
.option('-p, --port <port>', 'Specify a port for the dev server')
|
|
23
|
+
.option('--mv2', 'Target manifest v2')
|
|
24
|
+
.action((root, options) => {
|
|
25
|
+
console.log(options);
|
|
26
|
+
});
|
|
27
|
+
cli
|
|
28
|
+
.command('build [root]', 'Build for production')
|
|
29
|
+
.option('-m, --mode <mode>', 'Set env mode', { default: 'production' })
|
|
30
|
+
.option('-c, --config <config>', 'Path to config file')
|
|
31
|
+
.option('-a, --app <app>', 'Specify an app to run', { default: 'myapp' })
|
|
32
|
+
.option('-b, --browser <browser>', 'Specify a browser', { default: config_1.Browser.Chrome })
|
|
33
|
+
.option('--mv2', 'Target manifest v2')
|
|
34
|
+
.option('--analyze', 'Visualize extension bundle')
|
|
35
|
+
.action(async (root, options) => {
|
|
36
|
+
await (0, app_1.default)({
|
|
37
|
+
mode: options.mode,
|
|
38
|
+
debug: options.debug,
|
|
39
|
+
app: options.app,
|
|
40
|
+
browser: options.browser,
|
|
41
|
+
manifestVersion: options.mv2 ? 2 : 3,
|
|
42
|
+
inputDir: root,
|
|
43
|
+
configFile: options.config,
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
cli.help();
|
|
47
|
+
cli.parse();
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const typescript_1 = require("typescript");
|
|
7
|
+
const SourceFile_1 = __importDefault(require("./SourceFile"));
|
|
8
|
+
class default_1 extends SourceFile_1.default {
|
|
9
|
+
definition;
|
|
10
|
+
properties = [];
|
|
11
|
+
setDefinition(definition) {
|
|
12
|
+
this.definition = definition;
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
setProperties(properties) {
|
|
16
|
+
this.properties = properties;
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
getOptions() {
|
|
20
|
+
return { ...this.getOptionsFromVariables(), ...this.getOptionsFromDefinition() };
|
|
21
|
+
}
|
|
22
|
+
getOptionsFromVariables() {
|
|
23
|
+
return Array.from(this.getVariables().values())
|
|
24
|
+
.filter(({ name, exported }) => exported && this.properties.includes(name))
|
|
25
|
+
.reduce((config, { name, value }) => ({ ...config, [name]: value }), {});
|
|
26
|
+
}
|
|
27
|
+
getOptionsFromDefinition() {
|
|
28
|
+
let options = {};
|
|
29
|
+
const parse = (node) => {
|
|
30
|
+
if ((0, typescript_1.isExportAssignment)(node)) {
|
|
31
|
+
const expr = node.expression;
|
|
32
|
+
if ((0, typescript_1.isCallExpression)(expr) && (0, typescript_1.isIdentifier)(expr.expression)) {
|
|
33
|
+
const functionName = expr.expression.text;
|
|
34
|
+
if (functionName === this.definition && expr.arguments.length > 0) {
|
|
35
|
+
const arg = expr.arguments[0];
|
|
36
|
+
if ((0, typescript_1.isObjectLiteralExpression)(arg)) {
|
|
37
|
+
options = this.parseNode(arg);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
(0, typescript_1.forEachChild)(node, parse);
|
|
43
|
+
};
|
|
44
|
+
parse(this.getSourceFile());
|
|
45
|
+
return options;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.default = default_1;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const typescript_1 = require("typescript");
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
class EntryFile {
|
|
10
|
+
file;
|
|
11
|
+
sourceFile;
|
|
12
|
+
variables;
|
|
13
|
+
imports;
|
|
14
|
+
enums;
|
|
15
|
+
static make(file) {
|
|
16
|
+
return new this(file);
|
|
17
|
+
}
|
|
18
|
+
constructor(file) {
|
|
19
|
+
this.file = file;
|
|
20
|
+
}
|
|
21
|
+
getSourceFile() {
|
|
22
|
+
if (this.sourceFile) {
|
|
23
|
+
return this.sourceFile;
|
|
24
|
+
}
|
|
25
|
+
const sourceCode = (0, fs_1.readFileSync)(this.file, 'utf8');
|
|
26
|
+
return this.sourceFile = (0, typescript_1.createSourceFile)(this.file, sourceCode, typescript_1.ScriptTarget.ESNext, true);
|
|
27
|
+
}
|
|
28
|
+
getImports() {
|
|
29
|
+
if (this.imports) {
|
|
30
|
+
return this.imports;
|
|
31
|
+
}
|
|
32
|
+
this.imports = new Map();
|
|
33
|
+
const parse = (node) => {
|
|
34
|
+
if ((0, typescript_1.isImportDeclaration)(node) && node.moduleSpecifier) {
|
|
35
|
+
const importPath = node.moduleSpecifier.text;
|
|
36
|
+
if (node.importClause && node.importClause.namedBindings && (0, typescript_1.isNamedImports)(node.importClause.namedBindings)) {
|
|
37
|
+
node.importClause.namedBindings.elements.forEach(el => {
|
|
38
|
+
this.imports?.set(el.name.text, path_1.default.resolve(path_1.default.dirname(this.file), importPath + '.ts'));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
(0, typescript_1.forEachChild)(node, parse);
|
|
43
|
+
};
|
|
44
|
+
parse(this.getSourceFile());
|
|
45
|
+
return this.imports;
|
|
46
|
+
}
|
|
47
|
+
getEnums() {
|
|
48
|
+
if (this.enums) {
|
|
49
|
+
return this.enums;
|
|
50
|
+
}
|
|
51
|
+
this.enums = new Map();
|
|
52
|
+
const parse = (node) => {
|
|
53
|
+
if ((0, typescript_1.isEnumDeclaration)(node)) {
|
|
54
|
+
const enumName = node.name.text;
|
|
55
|
+
const enumProperties = new Map();
|
|
56
|
+
node.members.forEach(member => {
|
|
57
|
+
const key = member.name.getText();
|
|
58
|
+
const value = member.initializer ? member.initializer.getText().replace(/['"]/g, '') : key;
|
|
59
|
+
enumProperties.set(key, value);
|
|
60
|
+
});
|
|
61
|
+
this.enums?.set(enumName, enumProperties);
|
|
62
|
+
}
|
|
63
|
+
(0, typescript_1.forEachChild)(node, parse);
|
|
64
|
+
};
|
|
65
|
+
parse(this.getSourceFile());
|
|
66
|
+
return this.enums;
|
|
67
|
+
}
|
|
68
|
+
getVariables() {
|
|
69
|
+
if (this.variables) {
|
|
70
|
+
return this.variables;
|
|
71
|
+
}
|
|
72
|
+
this.variables = new Map();
|
|
73
|
+
const parse = (node) => {
|
|
74
|
+
if ((0, typescript_1.isVariableStatement)(node)) {
|
|
75
|
+
const isExported = node.modifiers?.some(modifier => modifier.kind === typescript_1.SyntaxKind.ExportKeyword);
|
|
76
|
+
node.declarationList.declarations.forEach(declaration => {
|
|
77
|
+
if ((0, typescript_1.isIdentifier)(declaration.name) && declaration.initializer) {
|
|
78
|
+
const name = declaration.name.text;
|
|
79
|
+
const value = this.parseNode(declaration.initializer);
|
|
80
|
+
this.variables?.set(name, {
|
|
81
|
+
name,
|
|
82
|
+
value,
|
|
83
|
+
exported: isExported || false
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if ((0, typescript_1.isExportDeclaration)(node) && node.exportClause && (0, typescript_1.isNamedExports)(node.exportClause)) {
|
|
89
|
+
node.exportClause.elements.forEach(el => {
|
|
90
|
+
const name = el.name.text;
|
|
91
|
+
if (this.variables?.has(name)) {
|
|
92
|
+
const variable = this.variables?.get(name);
|
|
93
|
+
this.variables?.set(name, {
|
|
94
|
+
name,
|
|
95
|
+
value: variable.value,
|
|
96
|
+
exported: true
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
if ((0, typescript_1.isExportAssignment)(node)) {
|
|
102
|
+
const expr = node.expression;
|
|
103
|
+
if ((0, typescript_1.isIdentifier)(expr) && this.variables?.has(expr.text)) {
|
|
104
|
+
const variable = this.variables?.get(expr.text);
|
|
105
|
+
const name = "default";
|
|
106
|
+
this.variables?.set(name, {
|
|
107
|
+
name,
|
|
108
|
+
value: variable.value,
|
|
109
|
+
exported: true
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
(0, typescript_1.forEachChild)(node, parse);
|
|
114
|
+
};
|
|
115
|
+
parse(this.getSourceFile());
|
|
116
|
+
return this.variables;
|
|
117
|
+
}
|
|
118
|
+
findPropertyAccessValue(property) {
|
|
119
|
+
if ((0, typescript_1.isPropertyAccessExpression)(property)) {
|
|
120
|
+
const objectName = property.expression.getText();
|
|
121
|
+
const propertyName = property.name.getText();
|
|
122
|
+
const varItem = this.getVariables().get(objectName);
|
|
123
|
+
if (varItem) {
|
|
124
|
+
return varItem.value;
|
|
125
|
+
}
|
|
126
|
+
const enumItem = this.getEnums().get(objectName);
|
|
127
|
+
if (enumItem) {
|
|
128
|
+
return enumItem.get(propertyName);
|
|
129
|
+
}
|
|
130
|
+
const importItem = this.getImports().get(objectName);
|
|
131
|
+
if (importItem) {
|
|
132
|
+
return EntryFile.make(importItem).findPropertyAccessValue(property);
|
|
133
|
+
}
|
|
134
|
+
return `${objectName}.${propertyName}`;
|
|
135
|
+
}
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
parseNode(node) {
|
|
139
|
+
if (!node) {
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
switch (node.kind) {
|
|
143
|
+
case typescript_1.SyntaxKind.StringLiteral:
|
|
144
|
+
return node.text;
|
|
145
|
+
case typescript_1.SyntaxKind.TrueKeyword:
|
|
146
|
+
return true;
|
|
147
|
+
case typescript_1.SyntaxKind.FalseKeyword:
|
|
148
|
+
return false;
|
|
149
|
+
case typescript_1.SyntaxKind.NullKeyword:
|
|
150
|
+
return null;
|
|
151
|
+
case typescript_1.SyntaxKind.NumericLiteral:
|
|
152
|
+
return parseFloat(node.text);
|
|
153
|
+
case typescript_1.SyntaxKind.Identifier:
|
|
154
|
+
return this.variables?.get(node.text)?.value ?? node.text;
|
|
155
|
+
case typescript_1.SyntaxKind.ArrayLiteralExpression:
|
|
156
|
+
return node.elements.map(element => this.parseNode(element));
|
|
157
|
+
case typescript_1.SyntaxKind.ObjectLiteralExpression:
|
|
158
|
+
return node.properties
|
|
159
|
+
.filter((property) => (0, typescript_1.isPropertyAssignment)(property) || (0, typescript_1.isShorthandPropertyAssignment)(property))
|
|
160
|
+
.reduce((acc, property) => {
|
|
161
|
+
if ((0, typescript_1.isComputedPropertyName)(property.name)) {
|
|
162
|
+
return acc;
|
|
163
|
+
}
|
|
164
|
+
const key = property.name.text;
|
|
165
|
+
let value = this.parseNode(property.initializer);
|
|
166
|
+
if (typeof value === 'string' && this.variables?.has(value)) {
|
|
167
|
+
value = this.variables?.get(value)?.value;
|
|
168
|
+
}
|
|
169
|
+
acc[key] = value;
|
|
170
|
+
return acc;
|
|
171
|
+
}, {});
|
|
172
|
+
case typescript_1.SyntaxKind.PropertyAccessExpression: {
|
|
173
|
+
return this.findPropertyAccessValue(node);
|
|
174
|
+
}
|
|
175
|
+
default:
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
exports.default = EntryFile;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getBackgroundOptions = void 0;
|
|
7
|
+
const OptionFile_1 = __importDefault(require("./OptionFile"));
|
|
8
|
+
const commonProperties = [
|
|
9
|
+
'includeApp',
|
|
10
|
+
'excludeApp',
|
|
11
|
+
'includeBrowser',
|
|
12
|
+
'excludeBrowser',
|
|
13
|
+
];
|
|
14
|
+
const getBackgroundOptions = (file) => {
|
|
15
|
+
return OptionFile_1.default.make(file)
|
|
16
|
+
.setDefinition('defineBackground')
|
|
17
|
+
.setProperties([...commonProperties, 'persistent'])
|
|
18
|
+
.getOptions();
|
|
19
|
+
};
|
|
20
|
+
exports.getBackgroundOptions = getBackgroundOptions;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const isFunction_1 = __importDefault(require("lodash/isFunction"));
|
|
8
|
+
const entrypoint_1 = require("../parsers/entrypoint");
|
|
9
|
+
const path_2 = require("../resolvers/path");
|
|
10
|
+
const plugin_1 = require("../utils/plugin");
|
|
11
|
+
const option_1 = require("../utils/option");
|
|
12
|
+
const entrypoint_2 = require("../utils/entrypoint");
|
|
13
|
+
const backgroundFilesToEntries = (files) => {
|
|
14
|
+
const entries = new Map;
|
|
15
|
+
for (const file of files) {
|
|
16
|
+
entries.set(file, (0, entrypoint_1.getBackgroundOptions)(file));
|
|
17
|
+
}
|
|
18
|
+
return entries;
|
|
19
|
+
};
|
|
20
|
+
const findBackgroundEntries = (dir) => {
|
|
21
|
+
return backgroundFilesToEntries((0, entrypoint_2.findBackgroundFiles)(dir));
|
|
22
|
+
};
|
|
23
|
+
exports.default = (options) => {
|
|
24
|
+
const { name = 'background' } = options || {};
|
|
25
|
+
let hasBackground = false;
|
|
26
|
+
return {
|
|
27
|
+
webpack: async ({ config, webpack }) => {
|
|
28
|
+
let entries = new Map;
|
|
29
|
+
const appBackgroundEntries = findBackgroundEntries((0, path_2.getAppsPath)(config));
|
|
30
|
+
if (appBackgroundEntries.size > 0) {
|
|
31
|
+
entries = new Map([...entries, ...appBackgroundEntries]);
|
|
32
|
+
if (config.debug) {
|
|
33
|
+
console.info('App background added:', appBackgroundEntries);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (appBackgroundEntries.size > 0 && config.mergeBackground || appBackgroundEntries.size === 0) {
|
|
37
|
+
const sharedBackgroundEntries = findBackgroundEntries((0, path_2.getSharedPath)(config));
|
|
38
|
+
if (sharedBackgroundEntries.size > 0) {
|
|
39
|
+
entries = new Map([...entries, ...sharedBackgroundEntries]);
|
|
40
|
+
if (config.debug) {
|
|
41
|
+
console.info('Shared background added:', sharedBackgroundEntries);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const pluginBackgroundFiles = await Array.fromAsync((0, plugin_1.processPluginHandler)(config, 'background', {
|
|
46
|
+
config,
|
|
47
|
+
entries
|
|
48
|
+
}));
|
|
49
|
+
console.log('pluginBackgroundFiles', pluginBackgroundFiles);
|
|
50
|
+
if (pluginBackgroundFiles.length > 0) {
|
|
51
|
+
const pluginBackgroundEntries = backgroundFilesToEntries(pluginBackgroundFiles);
|
|
52
|
+
entries = new Map([...entries, ...pluginBackgroundEntries]);
|
|
53
|
+
if (config.debug) {
|
|
54
|
+
console.info('Plugin background added:', pluginBackgroundEntries);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const files = Array.from(entries)
|
|
58
|
+
.filter(([_, options]) => (0, option_1.isValidEntrypointOptions)(options, config))
|
|
59
|
+
.map(([file]) => file);
|
|
60
|
+
if (files.length === 0) {
|
|
61
|
+
if (config.debug) {
|
|
62
|
+
console.warn('Background entries not found');
|
|
63
|
+
}
|
|
64
|
+
return {};
|
|
65
|
+
}
|
|
66
|
+
hasBackground = true;
|
|
67
|
+
if (config.debug) {
|
|
68
|
+
console.info('Background entries:', entries);
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
entry: {
|
|
72
|
+
[name]: files,
|
|
73
|
+
},
|
|
74
|
+
optimization: {
|
|
75
|
+
splitChunks: {
|
|
76
|
+
chunks(chunk) {
|
|
77
|
+
const { chunks } = webpack.optimization?.splitChunks || {};
|
|
78
|
+
if ((0, isFunction_1.default)(chunks) && !chunks(chunk)) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
return chunk.name !== name;
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
manifest: ({ manifest, config }) => {
|
|
88
|
+
if (hasBackground) {
|
|
89
|
+
manifest.resetBackground({
|
|
90
|
+
entry: name,
|
|
91
|
+
file: path_1.default.join(config.jsDir, name + '.js'),
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const path_1 = __importDefault(require("path"));
|
|
7
|
+
const webpack_virtual_modules_1 = __importDefault(require("webpack-virtual-modules"));
|
|
8
|
+
const path_2 = require("@cli/resolvers/path");
|
|
9
|
+
exports.default = () => {
|
|
10
|
+
const contentScripts = [];
|
|
11
|
+
return {
|
|
12
|
+
webpack: async ({ config }) => {
|
|
13
|
+
//
|
|
14
|
+
// console.log(findContentFiles(getAppsPath(config)));
|
|
15
|
+
// console.log(findContentFiles(getSharedPath(config)));
|
|
16
|
+
const p = path_1.default.resolve((0, path_2.getAppsPath)(config), 'src/some.ts');
|
|
17
|
+
return {
|
|
18
|
+
entry: {
|
|
19
|
+
some: p,
|
|
20
|
+
},
|
|
21
|
+
plugins: [
|
|
22
|
+
new webpack_virtual_modules_1.default({
|
|
23
|
+
[p]: 'console.log("Hello, World!")'
|
|
24
|
+
})
|
|
25
|
+
]
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
manifest: ({ manifest }) => {
|
|
29
|
+
manifest.pushContentScript(...contentScripts);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const fs_1 = require("fs");
|
|
40
|
+
const isFunction_1 = __importDefault(require("lodash/isFunction"));
|
|
41
|
+
const isPlainObject_1 = __importDefault(require("lodash/isPlainObject"));
|
|
42
|
+
const content_1 = __importDefault(require("@cli/plugins/content"));
|
|
43
|
+
const background_1 = __importDefault(require("@cli/plugins/background"));
|
|
44
|
+
const path_1 = require("@cli/resolvers/path");
|
|
45
|
+
const config_1 = require("@typing/config");
|
|
46
|
+
const getUserConfig = async (config) => {
|
|
47
|
+
const configFilePath = (0, path_1.getConfigFile)(config);
|
|
48
|
+
let resolvedUserConfig = {};
|
|
49
|
+
if ((0, fs_1.existsSync)(configFilePath)) {
|
|
50
|
+
let { default: userConfigDefinition = undefined } = await Promise.resolve(`${configFilePath}`).then(s => __importStar(require(s)));
|
|
51
|
+
if ((0, isFunction_1.default)(userConfigDefinition)) {
|
|
52
|
+
let userConfigCallback = userConfigDefinition(config);
|
|
53
|
+
resolvedUserConfig = await userConfigCallback(config);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
resolvedUserConfig = userConfigDefinition;
|
|
57
|
+
}
|
|
58
|
+
if ((0, isPlainObject_1.default)(resolvedUserConfig) && config.debug) {
|
|
59
|
+
console.log('Loaded user config:', configFilePath);
|
|
60
|
+
}
|
|
61
|
+
else if (config.debug) {
|
|
62
|
+
console.error('Invalid user config:', configFilePath);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else if (config.debug) {
|
|
66
|
+
console.warn('Config file not found:', configFilePath);
|
|
67
|
+
}
|
|
68
|
+
return resolvedUserConfig;
|
|
69
|
+
};
|
|
70
|
+
exports.default = async (config) => {
|
|
71
|
+
let { debug = false, configFile = 'addonbone.config.ts', app = 'myapp', browser = config_1.Browser.Chrome, inputDir = '.', outputDir = 'dist', srcDir = 'src', sharedDir = 'shared', appsDir = 'apps', jsDir = 'js', cssDir = 'css', assetsDir = 'assets', htmlDir = '.', manifestVersion = [config_1.Browser.Firefox, config_1.Browser.Safari].includes(browser) ? 2 : 3, mode = config_1.Mode.Development, analyze = false, plugins = [], mergeBackground = false, mergeContentScripts = false, concatContentScripts = true, } = config;
|
|
72
|
+
let resolvedConfig = {
|
|
73
|
+
debug,
|
|
74
|
+
mode,
|
|
75
|
+
app,
|
|
76
|
+
browser,
|
|
77
|
+
manifestVersion,
|
|
78
|
+
inputDir,
|
|
79
|
+
outputDir,
|
|
80
|
+
srcDir,
|
|
81
|
+
sharedDir,
|
|
82
|
+
appsDir,
|
|
83
|
+
jsDir,
|
|
84
|
+
cssDir,
|
|
85
|
+
assetsDir,
|
|
86
|
+
htmlDir,
|
|
87
|
+
plugins,
|
|
88
|
+
analyze,
|
|
89
|
+
configFile,
|
|
90
|
+
mergeBackground,
|
|
91
|
+
mergeContentScripts,
|
|
92
|
+
concatContentScripts,
|
|
93
|
+
};
|
|
94
|
+
const { plugins: userPlugins = [], ...userConfig } = await getUserConfig(resolvedConfig);
|
|
95
|
+
const corePlugins = [(0, content_1.default)(), (0, background_1.default)()];
|
|
96
|
+
return {
|
|
97
|
+
...resolvedConfig,
|
|
98
|
+
...userConfig,
|
|
99
|
+
plugins: [
|
|
100
|
+
...plugins,
|
|
101
|
+
...userPlugins,
|
|
102
|
+
...corePlugins,
|
|
103
|
+
]
|
|
104
|
+
};
|
|
105
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getAppsPath = exports.getSharedPath = exports.getConfigFile = exports.getRootPath = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const getRootPath = (to) => {
|
|
9
|
+
return path_1.default.resolve(process.cwd(), to);
|
|
10
|
+
};
|
|
11
|
+
exports.getRootPath = getRootPath;
|
|
12
|
+
const getConfigFile = (config) => {
|
|
13
|
+
return path_1.default.resolve(config.inputDir, config.configFile);
|
|
14
|
+
};
|
|
15
|
+
exports.getConfigFile = getConfigFile;
|
|
16
|
+
const getSharedPath = (config) => {
|
|
17
|
+
return path_1.default.resolve(config.inputDir, config.srcDir, config.sharedDir);
|
|
18
|
+
};
|
|
19
|
+
exports.getSharedPath = getSharedPath;
|
|
20
|
+
const getAppsPath = (config) => {
|
|
21
|
+
return path_1.default.resolve(config.inputDir, config.srcDir, config.appsDir, config.app);
|
|
22
|
+
};
|
|
23
|
+
exports.getAppsPath = getAppsPath;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const webpack_merge_1 = require("webpack-merge");
|
|
40
|
+
const path_1 = __importDefault(require("path"));
|
|
41
|
+
const tsconfig_paths_webpack_plugin_1 = __importDefault(require("tsconfig-paths-webpack-plugin"));
|
|
42
|
+
const mini_css_extract_plugin_1 = __importDefault(require("mini-css-extract-plugin"));
|
|
43
|
+
const manifest_1 = __importDefault(require("@cli/builders/manifest"));
|
|
44
|
+
const path_2 = require("./path");
|
|
45
|
+
const plugin_1 = require("@cli/utils/plugin");
|
|
46
|
+
const getConfigFromPlugins = async (webpack, config) => {
|
|
47
|
+
let mergedConfig = {};
|
|
48
|
+
for await (const webpackFromPlugin of (0, plugin_1.processPluginHandler)(config, 'webpack', { webpack, config })) {
|
|
49
|
+
mergedConfig = (0, webpack_merge_1.merge)(mergedConfig, webpackFromPlugin);
|
|
50
|
+
}
|
|
51
|
+
return mergedConfig;
|
|
52
|
+
};
|
|
53
|
+
const getConfigForManifest = async (webpack, config, manifest) => {
|
|
54
|
+
await Array.fromAsync((0, plugin_1.processPluginHandler)(config, 'manifest', { manifest, config }));
|
|
55
|
+
console.log(manifest.get());
|
|
56
|
+
return webpack;
|
|
57
|
+
};
|
|
58
|
+
exports.default = async (config) => {
|
|
59
|
+
const manifest = (0, manifest_1.default)(config.browser, config.manifestVersion);
|
|
60
|
+
let webpack = {
|
|
61
|
+
mode: config.mode,
|
|
62
|
+
cache: false,
|
|
63
|
+
output: {
|
|
64
|
+
path: (0, path_2.getRootPath)(config.outputDir),
|
|
65
|
+
filename: path_1.default.join(config.jsDir, '[name].js'),
|
|
66
|
+
assetModuleFilename: path_1.default.join(config.assetsDir, '[name]-[hash:4][ext]'),
|
|
67
|
+
},
|
|
68
|
+
resolve: {
|
|
69
|
+
extensions: [".ts", ".tsx", ".js", ".scss"],
|
|
70
|
+
plugins: [new tsconfig_paths_webpack_plugin_1.default()],
|
|
71
|
+
},
|
|
72
|
+
module: {
|
|
73
|
+
rules: [
|
|
74
|
+
{
|
|
75
|
+
test: /\.tsx?$/,
|
|
76
|
+
use: "ts-loader",
|
|
77
|
+
exclude: /node_modules/,
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
test: /\.(scss|css)$/,
|
|
81
|
+
use: [
|
|
82
|
+
mini_css_extract_plugin_1.default.loader,
|
|
83
|
+
{
|
|
84
|
+
loader: "css-loader",
|
|
85
|
+
options: {
|
|
86
|
+
modules: {
|
|
87
|
+
localIdentName: "[local]"
|
|
88
|
+
},
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
loader: "sass-loader",
|
|
93
|
+
options: {
|
|
94
|
+
implementation: Promise.resolve().then(() => __importStar(require("sass"))),
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
test: /\.(png|apng|jpe?g|gif|webp|svg])$/i,
|
|
101
|
+
type: "asset/resource",
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
webpack = (0, webpack_merge_1.merge)(webpack, await getConfigFromPlugins(webpack, config), await getConfigForManifest(webpack, config, manifest));
|
|
107
|
+
return webpack;
|
|
108
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.findContentFiles = exports.findBackgroundFiles = exports.findEntrypointFiles = void 0;
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
10
|
+
const findEntrypointFiles = (directory, entrypoint) => {
|
|
11
|
+
const files = [];
|
|
12
|
+
const regex = new RegExp(`^(?:.*\\.)?${escapeRegExp(entrypoint)}\\.(ts|tsx|js)$`);
|
|
13
|
+
const finder = (dir) => {
|
|
14
|
+
let entries;
|
|
15
|
+
try {
|
|
16
|
+
entries = (0, fs_1.readdirSync)(dir, { withFileTypes: true });
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
console.log('Error reading entrypoint directory:', dir);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
for (const entry of entries) {
|
|
23
|
+
const fullPath = path_1.default.join(dir, entry.name);
|
|
24
|
+
if (entry.isDirectory()) {
|
|
25
|
+
if (entry.name === entrypoint || entry.name.endsWith(`.${entrypoint}`)) {
|
|
26
|
+
const possibleIndexFiles = ['index.ts', 'index.tsx', 'index.js'];
|
|
27
|
+
for (const indexFile of possibleIndexFiles) {
|
|
28
|
+
const indexPath = path_1.default.join(fullPath, indexFile);
|
|
29
|
+
try {
|
|
30
|
+
const stat = (0, fs_1.statSync)(indexPath);
|
|
31
|
+
if (stat.isFile()) {
|
|
32
|
+
files.push(indexPath);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
//console.log('Error reading entrypoint index file:', indexPath);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
finder(fullPath);
|
|
41
|
+
}
|
|
42
|
+
else if (entry.isFile()) {
|
|
43
|
+
if (regex.test(entry.name)) {
|
|
44
|
+
files.push(fullPath);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
finder(directory);
|
|
50
|
+
return files;
|
|
51
|
+
};
|
|
52
|
+
exports.findEntrypointFiles = findEntrypointFiles;
|
|
53
|
+
const findBackgroundFiles = (directory) => {
|
|
54
|
+
return (0, exports.findEntrypointFiles)(directory, 'background');
|
|
55
|
+
};
|
|
56
|
+
exports.findBackgroundFiles = findBackgroundFiles;
|
|
57
|
+
const findContentFiles = (directory) => {
|
|
58
|
+
return (0, exports.findEntrypointFiles)(directory, 'content');
|
|
59
|
+
};
|
|
60
|
+
exports.findContentFiles = findContentFiles;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidEntrypointOptions = void 0;
|
|
4
|
+
const isValidEntrypointOptions = (options, config) => {
|
|
5
|
+
const { browser, app } = config;
|
|
6
|
+
if (options.includeBrowser?.includes(browser) || options.includeApp?.includes(app)) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
if (options.excludeBrowser?.includes(browser) || options.excludeApp?.includes(app)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
return true;
|
|
13
|
+
};
|
|
14
|
+
exports.isValidEntrypointOptions = isValidEntrypointOptions;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.processPluginHandler = exports.resolvePluginHandler = void 0;
|
|
7
|
+
const isFunction_1 = __importDefault(require("lodash/isFunction"));
|
|
8
|
+
const resolvePluginHandler = async (handler, options) => {
|
|
9
|
+
if ((0, isFunction_1.default)(handler)) {
|
|
10
|
+
const result = handler(options);
|
|
11
|
+
if (result instanceof Promise) {
|
|
12
|
+
return await result;
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
return handler;
|
|
17
|
+
};
|
|
18
|
+
exports.resolvePluginHandler = resolvePluginHandler;
|
|
19
|
+
const processPluginHandler = async function* (config, key, options) {
|
|
20
|
+
const { plugins = [] } = config;
|
|
21
|
+
for await (const plugin of plugins) {
|
|
22
|
+
const handler = plugin[key];
|
|
23
|
+
const result = await (0, exports.resolvePluginHandler)(handler, options);
|
|
24
|
+
if (result !== undefined) {
|
|
25
|
+
yield result;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.processPluginHandler = processPluginHandler;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const webpack_1 = require("webpack");
|
|
4
|
+
class EntryDependenciesPlugin {
|
|
5
|
+
callback;
|
|
6
|
+
dependencyMap = new Map();
|
|
7
|
+
constructor(callback) {
|
|
8
|
+
this.callback = callback;
|
|
9
|
+
}
|
|
10
|
+
apply(compiler) {
|
|
11
|
+
compiler.hooks.compilation.tap('EntryDependenciesPlugin', (compilation) => {
|
|
12
|
+
compilation.hooks.processAssets.tapPromise({
|
|
13
|
+
name: 'EntryDependenciesPlugin',
|
|
14
|
+
stage: webpack_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_HASH,
|
|
15
|
+
}, async () => {
|
|
16
|
+
const { entrypoints } = compilation;
|
|
17
|
+
for (const [entryName, entrypoint] of entrypoints) {
|
|
18
|
+
const chunks = new Set();
|
|
19
|
+
const visitedChunks = new Set();
|
|
20
|
+
const collectChunks = (chunk) => {
|
|
21
|
+
if (visitedChunks.has(chunk))
|
|
22
|
+
return;
|
|
23
|
+
visitedChunks.add(chunk);
|
|
24
|
+
chunks.add(chunk);
|
|
25
|
+
for (const child of chunk.getAllAsyncChunks()) {
|
|
26
|
+
collectChunks(child);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const entryChunk = entrypoint.getEntrypointChunk();
|
|
30
|
+
collectChunks(entryChunk);
|
|
31
|
+
const files = new Set();
|
|
32
|
+
for (const chunk of chunks) {
|
|
33
|
+
for (const file of chunk.files) {
|
|
34
|
+
files.add(file);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
this.dependencyMap[entryName] = Array.from(files);
|
|
38
|
+
}
|
|
39
|
+
if (this.callback) {
|
|
40
|
+
this.callback(this.dependencyMap);
|
|
41
|
+
}
|
|
42
|
+
// const outputContent = JSON.stringify(
|
|
43
|
+
// this.dependencyMap,
|
|
44
|
+
// null,
|
|
45
|
+
// 2
|
|
46
|
+
// );
|
|
47
|
+
//
|
|
48
|
+
// compilation.emitAsset(
|
|
49
|
+
// this.options.outputFileName!,
|
|
50
|
+
// new compiler.webpack.sources.RawSource(outputContent)
|
|
51
|
+
// );
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.default = EntryDependenciesPlugin;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineContentScript = exports.defineBackground = exports.defineConfig = void 0;
|
|
4
|
+
const defineConfig = (config) => {
|
|
5
|
+
return config;
|
|
6
|
+
};
|
|
7
|
+
exports.defineConfig = defineConfig;
|
|
8
|
+
const defineBackground = (options) => {
|
|
9
|
+
return options;
|
|
10
|
+
};
|
|
11
|
+
exports.defineBackground = defineBackground;
|
|
12
|
+
const defineContentScript = (options) => {
|
|
13
|
+
return options;
|
|
14
|
+
};
|
|
15
|
+
exports.defineContentScript = defineContentScript;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const webpack_1 = __importDefault(require("webpack"));
|
|
7
|
+
(0, webpack_1.default)({
|
|
8
|
+
entry: './src/index.ts',
|
|
9
|
+
output: {}
|
|
10
|
+
});
|
|
11
|
+
console.log('awdawda');
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Mode = exports.Browser = void 0;
|
|
4
|
+
var Browser;
|
|
5
|
+
(function (Browser) {
|
|
6
|
+
Browser["Chrome"] = "chrome";
|
|
7
|
+
Browser["Chromium"] = "chromium";
|
|
8
|
+
Browser["Edge"] = "edge";
|
|
9
|
+
Browser["Firefox"] = "firefox";
|
|
10
|
+
Browser["Opera"] = "opera";
|
|
11
|
+
Browser["Safari"] = "safari";
|
|
12
|
+
})(Browser || (exports.Browser = Browser = {}));
|
|
13
|
+
var Mode;
|
|
14
|
+
(function (Mode) {
|
|
15
|
+
Mode["None"] = "none";
|
|
16
|
+
Mode["Development"] = "development";
|
|
17
|
+
Mode["Production"] = "production";
|
|
18
|
+
})(Mode || (exports.Mode = Mode = {}));
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adnbn",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.4",
|
|
5
5
|
"description": "Cross browser web extension framework with shared code base",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"homepage": "https://github.com/addonbone/addonbone",
|
|
@@ -24,12 +24,13 @@
|
|
|
24
24
|
"url": "https://github.com/addonbone/addonbone/issues"
|
|
25
25
|
},
|
|
26
26
|
"files": [
|
|
27
|
-
"bin"
|
|
27
|
+
"bin",
|
|
28
|
+
"dist"
|
|
28
29
|
],
|
|
29
30
|
"bin": {
|
|
30
|
-
"adnbn": "./bin/
|
|
31
|
+
"adnbn": "./bin/adnbn.mjs"
|
|
31
32
|
},
|
|
32
|
-
"module": "./bin/
|
|
33
|
+
"module": "./bin/adnbn.mjs",
|
|
33
34
|
"scripts": {
|
|
34
35
|
"build": "webpack --stats-error-details"
|
|
35
36
|
},
|
|
@@ -37,6 +38,8 @@
|
|
|
37
38
|
"@types/generate-json-webpack-plugin": "^0.3.7",
|
|
38
39
|
"@types/lodash": "^4.17.14",
|
|
39
40
|
"@types/node": "^22.13.1",
|
|
41
|
+
"enhanced-resolve": "^5.18.1",
|
|
42
|
+
"fs-extra": "^11.3.0",
|
|
40
43
|
"ts-node": "^10.9.2",
|
|
41
44
|
"tsconfig-paths-webpack-plugin": "^4.2.0",
|
|
42
45
|
"tsup": "^8.3.6",
|
package/bin/cli.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(()=>{var e={525:function(e,t,r){"use strict";var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=i(r(807)),n=i(r(431)),o=i(r(686));t.default=async e=>{const t=await(0,n.default)(e),r=await(0,o.default)(t);(0,s.default)(r).run(((e,t)=>{e&&(console.error("Webpack compilation error"),process.exit(1)),console.log(t?.toString({colors:!0}))}))}},292:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const i=r(434);t.default=class{browser;name="__MSG_app_name__";shortName="__MSG_app_short_name__";description="__MSG_app_description__";version="0.0.0";background;contentScripts=new Map;constructor(e=i.Browser.Chrome){this.browser=e}setName(e){return this.name=e,this}setShortName(e){return this.shortName=e,this}setDescription(e){return this.description=e,this}setVersion(e){return this.version=e,this}resetBackground(e){return this.background=e,this}pushContentScript(...e){for(const t of e)this.contentScripts.set(t.entry,t);return this}marge(e,...t){return 0===(t=t.filter((e=>void 0!==e))).length?e:Object.assign({},e,...t)}build(){let e={name:this.name,short_name:this.shortName,description:this.description,version:this.version,manifest_version:this.getManifestVersion()};return e=this.marge(e,this.buildBackground(),this.buildContentScripts()),e}get(){return this.build()}}},617:function(e,t,r){"use strict";var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=i(r(292));class n extends s.default{constructor(e){super(e)}getManifestVersion(){return 2}buildBackground(){if(this.background){const{file:e,persistent:t}=this.background;return{background:{scripts:[e],persistent:t}}}}buildContentScripts(){if(this.contentScripts.size>0)return{content_scripts:Array.from(this.contentScripts,(([e,t])=>({matches:t.matches,js:[t.file],exclude_matches:t.excludeMatches,all_frames:t.allFrames,run_at:t.runAt,exclude_globs:t.excludeGlobs,include_globs:t.includeGlobs})))}}}t.default=n},154:function(e,t,r){"use strict";var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=i(r(292));class n extends s.default{constructor(e){super(e)}getManifestVersion(){return 3}buildBackground(){if(this.background)return{background:{service_worker:this.background.file}}}buildContentScripts(){if(this.contentScripts.size>0)return{content_scripts:Array.from(this.contentScripts,(([e,t])=>({matches:t.matches,exclude_matches:t.excludeMatches,js:[t.file],all_frames:t.allFrames,run_at:t.runAt,exclude_globs:t.excludeGlobs,include_globs:t.includeGlobs,world:t.world})))}}}t.default=n},494:function(e,t,r){"use strict";var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=i(r(617)),n=i(r(154));t.default=(e,t)=>2===t?new s.default(e):new n.default(e)},625:function(e,t,r){"use strict";var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=i(r(13)),n=r(434),o=i(r(525)),a=(0,s.default)("addonbone");a.option("--debug","Enable debug mode"),a.command("init","Initialize a new project").action((()=>{console.log("init")})),a.command("[root]","Start dev server").option("-m, --mode <mode>","Set env mode",{default:"development"}).option("-c, --config <config>","Path to config file").option("-a, --app <app>","Specify an app to run",{default:"myapp"}).option("-b, --browser <browser>","Specify a browser").option("-p, --port <port>","Specify a port for the dev server").option("--mv2","Target manifest v2").action(((e,t)=>{console.log(t)})),a.command("build [root]","Build for production").option("-m, --mode <mode>","Set env mode",{default:"production"}).option("-c, --config <config>","Path to config file").option("-a, --app <app>","Specify an app to run",{default:"myapp"}).option("-b, --browser <browser>","Specify a browser",{default:n.Browser.Chrome}).option("--mv2","Target manifest v2").option("--analyze","Visualize extension bundle").action((async(e,t)=>{await(0,o.default)({mode:t.mode,debug:t.debug,app:t.app,browser:t.browser,manifestVersion:t.mv2?2:3,inputDir:e,configFile:t.config})})),a.help(),a.parse()},218:function(e,t,r){"use strict";var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=r(899),n=i(r(566));class o extends n.default{definition;properties=[];setDefinition(e){return this.definition=e,this}setProperties(e){return this.properties=e,this}getOptions(){return{...this.getOptionsFromVariables(),...this.getOptionsFromDefinition()}}getOptionsFromVariables(){return Array.from(this.getVariables().values()).filter((({name:e,exported:t})=>t&&this.properties.includes(e))).reduce(((e,{name:t,value:r})=>({...e,[t]:r})),{})}getOptionsFromDefinition(){let e={};const t=r=>{if((0,s.isExportAssignment)(r)){const t=r.expression;if((0,s.isCallExpression)(t)&&(0,s.isIdentifier)(t.expression)&&t.expression.text===this.definition&&t.arguments.length>0){const r=t.arguments[0];(0,s.isObjectLiteralExpression)(r)&&(e=this.parseNode(r))}}(0,s.forEachChild)(r,t)};return t(this.getSourceFile()),e}}t.default=o},566:function(e,t,r){"use strict";var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=r(899),n=r(896),o=i(r(928));class a{file;sourceFile;variables;imports;enums;static make(e){return new this(e)}constructor(e){this.file=e}getSourceFile(){if(this.sourceFile)return this.sourceFile;const e=(0,n.readFileSync)(this.file,"utf8");return this.sourceFile=(0,s.createSourceFile)(this.file,e,s.ScriptTarget.ESNext,!0)}getImports(){if(this.imports)return this.imports;this.imports=new Map;const e=t=>{if((0,s.isImportDeclaration)(t)&&t.moduleSpecifier){const e=t.moduleSpecifier.text;t.importClause&&t.importClause.namedBindings&&(0,s.isNamedImports)(t.importClause.namedBindings)&&t.importClause.namedBindings.elements.forEach((t=>{this.imports?.set(t.name.text,o.default.resolve(o.default.dirname(this.file),e+".ts"))}))}(0,s.forEachChild)(t,e)};return e(this.getSourceFile()),this.imports}getEnums(){if(this.enums)return this.enums;this.enums=new Map;const e=t=>{if((0,s.isEnumDeclaration)(t)){const e=t.name.text,r=new Map;t.members.forEach((e=>{const t=e.name.getText(),i=e.initializer?e.initializer.getText().replace(/['"]/g,""):t;r.set(t,i)})),this.enums?.set(e,r)}(0,s.forEachChild)(t,e)};return e(this.getSourceFile()),this.enums}getVariables(){if(this.variables)return this.variables;this.variables=new Map;const e=t=>{if((0,s.isVariableStatement)(t)){const e=t.modifiers?.some((e=>e.kind===s.SyntaxKind.ExportKeyword));t.declarationList.declarations.forEach((t=>{if((0,s.isIdentifier)(t.name)&&t.initializer){const r=t.name.text,i=this.parseNode(t.initializer);this.variables?.set(r,{name:r,value:i,exported:e||!1})}}))}if((0,s.isExportDeclaration)(t)&&t.exportClause&&(0,s.isNamedExports)(t.exportClause)&&t.exportClause.elements.forEach((e=>{const t=e.name.text;if(this.variables?.has(t)){const e=this.variables?.get(t);this.variables?.set(t,{name:t,value:e.value,exported:!0})}})),(0,s.isExportAssignment)(t)){const e=t.expression;if((0,s.isIdentifier)(e)&&this.variables?.has(e.text)){const t=this.variables?.get(e.text),r="default";this.variables?.set(r,{name:r,value:t.value,exported:!0})}}(0,s.forEachChild)(t,e)};return e(this.getSourceFile()),this.variables}findPropertyAccessValue(e){if((0,s.isPropertyAccessExpression)(e)){const t=e.expression.getText(),r=e.name.getText(),i=this.getVariables().get(t);if(i)return i.value;const s=this.getEnums().get(t);if(s)return s.get(r);const n=this.getImports().get(t);return n?a.make(n).findPropertyAccessValue(e):`${t}.${r}`}}parseNode(e){if(e)switch(e.kind){case s.SyntaxKind.StringLiteral:return e.text;case s.SyntaxKind.TrueKeyword:return!0;case s.SyntaxKind.FalseKeyword:return!1;case s.SyntaxKind.NullKeyword:return null;case s.SyntaxKind.NumericLiteral:return parseFloat(e.text);case s.SyntaxKind.Identifier:return this.variables?.get(e.text)?.value??e.text;case s.SyntaxKind.ArrayLiteralExpression:return e.elements.map((e=>this.parseNode(e)));case s.SyntaxKind.ObjectLiteralExpression:return e.properties.filter((e=>(0,s.isPropertyAssignment)(e)||(0,s.isShorthandPropertyAssignment)(e))).reduce(((e,t)=>{if((0,s.isComputedPropertyName)(t.name))return e;const r=t.name.text;let i=this.parseNode(t.initializer);return"string"==typeof i&&this.variables?.has(i)&&(i=this.variables?.get(i)?.value),e[r]=i,e}),{});case s.SyntaxKind.PropertyAccessExpression:return this.findPropertyAccessValue(e);default:return}}}t.default=a},401:function(e,t,r){"use strict";var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getBackgroundOptions=void 0;const s=i(r(218)),n=["includeApp","excludeApp","includeBrowser","excludeBrowser"];t.getBackgroundOptions=e=>s.default.make(e).setDefinition("defineBackground").setProperties([...n,"persistent"]).getOptions()},920:function(e,t,r){"use strict";var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=i(r(928)),n=i(r(14)),o=r(401),a=r(542),u=r(316),c=r(54),l=r(901),d=e=>{const t=new Map;for(const r of e)t.set(r,(0,o.getBackgroundOptions)(r));return t},p=e=>d((0,l.findBackgroundFiles)(e));t.default=e=>{const{name:t="background"}=e||{};let r=!1;return{webpack:async({config:e,webpack:i})=>{let s=new Map;const o=p((0,a.getAppsPath)(e));if(o.size>0&&(s=new Map([...s,...o]),e.debug&&console.info("App background added:",o)),o.size>0&&e.mergeBackground||0===o.size){const t=p((0,a.getSharedPath)(e));t.size>0&&(s=new Map([...s,...t]),e.debug&&console.info("Shared background added:",t))}const l=await Array.fromAsync((0,u.processPluginHandler)(e,"background",{config:e,entries:s}));if(console.log("pluginBackgroundFiles",l),l.length>0){const t=d(l);s=new Map([...s,...t]),e.debug&&console.info("Plugin background added:",t)}const f=Array.from(s).filter((([t,r])=>(0,c.isValidEntrypointOptions)(r,e))).map((([e])=>e));return 0===f.length?(e.debug&&console.warn("Background entries not found"),{}):(r=!0,e.debug&&console.info("Background entries:",s),{entry:{[t]:f},optimization:{splitChunks:{chunks(e){const{chunks:r}=i.optimization?.splitChunks||{};return!((0,n.default)(r)&&!r(e))&&e.name!==t}}}})},manifest:({manifest:e,config:i})=>{r&&e.resetBackground({entry:t,file:s.default.join(i.jsDir,t+".js")})}}}},159:function(e,t,r){"use strict";var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const s=i(r(928)),n=i(r(733)),o=r(542);t.default=()=>{const e=[];return{webpack:async({config:e})=>{const t=s.default.resolve((0,o.getAppsPath)(e),"src/some.ts");return{entry:{some:t},plugins:[new n.default({[t]:'console.log("Hello, World!")'})]}},manifest:({manifest:t})=>{t.pushContentScript(...e)}}}},431:function(e,t,r){"use strict";var i,s=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var s=Object.getOwnPropertyDescriptor(t,r);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,s)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||(i=function(e){return i=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},i(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=i(e),o=0;o<r.length;o++)"default"!==r[o]&&s(t,e,r[o]);return n(t,e),t}),a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const u=r(896),c=a(r(14)),l=a(r(813)),d=a(r(159)),p=a(r(920)),f=r(542),h=r(434);t.default=async e=>{let{debug:t=!1,configFile:i="addonbone.config.ts",app:s="myapp",browser:n=h.Browser.Chrome,inputDir:a=".",outputDir:m="dist",srcDir:g="src",sharedDir:_="shared",appsDir:b="apps",jsDir:v="js",cssDir:y="css",assetsDir:x="assets",htmlDir:w=".",manifestVersion:P=([h.Browser.Firefox,h.Browser.Safari].includes(n)?2:3),mode:S=h.Mode.Development,analyze:D=!1,plugins:M=[],mergeBackground:O=!1,mergeContentScripts:j=!1,concatContentScripts:k=!0}=e,F={debug:t,mode:S,app:s,browser:n,manifestVersion:P,inputDir:a,outputDir:m,srcDir:g,sharedDir:_,appsDir:b,jsDir:v,cssDir:y,assetsDir:x,htmlDir:w,plugins:M,analyze:D,configFile:i,mergeBackground:O,mergeContentScripts:j,concatContentScripts:k};const{plugins:C=[],...E}=await(async e=>{const t=(0,f.getConfigFile)(e);let i={};if((0,u.existsSync)(t)){let{default:s}=await Promise.resolve(`${t}`).then((e=>o(r(152)(e))));if((0,c.default)(s)){let t=s(e);i=await t(e)}else i=s;(0,l.default)(i)&&e.debug?console.log("Loaded user config:",t):e.debug&&console.error("Invalid user config:",t)}else e.debug&&console.warn("Config file not found:",t);return i})(F),B=[(0,d.default)(),(0,p.default)()];return{...F,...E,plugins:[...M,...C,...B]}}},542:function(e,t,r){"use strict";var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getAppsPath=t.getSharedPath=t.getConfigFile=t.getRootPath=void 0;const s=i(r(928));t.getRootPath=e=>s.default.resolve(process.cwd(),e),t.getConfigFile=e=>s.default.resolve(e.inputDir,e.configFile),t.getSharedPath=e=>s.default.resolve(e.inputDir,e.srcDir,e.sharedDir),t.getAppsPath=e=>s.default.resolve(e.inputDir,e.srcDir,e.appsDir,e.app)},686:function(e,t,r){"use strict";var i,s=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var s=Object.getOwnPropertyDescriptor(t,r);s&&!("get"in s?!t.__esModule:s.writable||s.configurable)||(s={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,s)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),n=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),o=this&&this.__importStar||(i=function(e){return i=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t},i(e)},function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r=i(e),o=0;o<r.length;o++)"default"!==r[o]&&s(t,e,r[o]);return n(t,e),t}),a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const u=r(870),c=a(r(928)),l=a(r(144)),d=a(r(95)),p=a(r(494)),f=r(542),h=r(316);t.default=async e=>{const t=(0,p.default)(e.browser,e.manifestVersion);let i={mode:e.mode,cache:!1,output:{path:(0,f.getRootPath)(e.outputDir),filename:c.default.join(e.jsDir,"[name].js"),assetModuleFilename:c.default.join(e.assetsDir,"[name]-[hash:4][ext]")},resolve:{extensions:[".ts",".tsx",".js",".scss"],plugins:[new l.default]},module:{rules:[{test:/\.tsx?$/,use:"ts-loader",exclude:/node_modules/},{test:/\.(scss|css)$/,use:[d.default.loader,{loader:"css-loader",options:{modules:{localIdentName:"[local]"}}},{loader:"sass-loader",options:{implementation:Promise.resolve().then((()=>o(r(878))))}}]},{test:/\.(png|apng|jpe?g|gif|webp|svg])$/i,type:"asset/resource"}]}};return i=(0,u.merge)(i,await(async(e,t)=>{let r={};for await(const i of(0,h.processPluginHandler)(t,"webpack",{webpack:e,config:t}))r=(0,u.merge)(r,i);return r})(i,e),await(async(e,t,r)=>(await Array.fromAsync((0,h.processPluginHandler)(t,"manifest",{manifest:r,config:t})),console.log(r.get()),e))(i,e,t)),i}},901:function(e,t,r){"use strict";var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.findContentFiles=t.findBackgroundFiles=t.findEntrypointFiles=void 0;const s=r(896),n=i(r(928));t.findEntrypointFiles=(e,t)=>{const r=[],i=new RegExp(`^(?:.*\\.)?${o=t,o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\.(ts|tsx|js)$`);var o;const a=e=>{let o;try{o=(0,s.readdirSync)(e,{withFileTypes:!0})}catch(t){return void console.log("Error reading entrypoint directory:",e)}for(const u of o){const o=n.default.join(e,u.name);if(u.isDirectory()){if(u.name===t||u.name.endsWith(`.${t}`)){const e=["index.ts","index.tsx","index.js"];for(const t of e){const e=n.default.join(o,t);try{(0,s.statSync)(e).isFile()&&r.push(e)}catch(e){}}}a(o)}else u.isFile()&&i.test(u.name)&&r.push(o)}};return a(e),r},t.findBackgroundFiles=e=>(0,t.findEntrypointFiles)(e,"background"),t.findContentFiles=e=>(0,t.findEntrypointFiles)(e,"content")},54:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.isValidEntrypointOptions=void 0,t.isValidEntrypointOptions=(e,t)=>{const{browser:r,app:i}=t;return!(!e.includeBrowser?.includes(r)&&!e.includeApp?.includes(i))||!e.excludeBrowser?.includes(r)&&!e.excludeApp?.includes(i)}},316:function(e,t,r){"use strict";var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.processPluginHandler=t.resolvePluginHandler=void 0;const s=i(r(14));t.resolvePluginHandler=async(e,t)=>{if((0,s.default)(e)){const r=e(t);return r instanceof Promise?await r:r}return e},t.processPluginHandler=async function*(e,r,i){const{plugins:s=[]}=e;for await(const e of s){const s=e[r],n=await(0,t.resolvePluginHandler)(s,i);void 0!==n&&(yield n)}}},434:(e,t)=>{"use strict";var r,i;Object.defineProperty(t,"__esModule",{value:!0}),t.Mode=t.Browser=void 0,function(e){e.Chrome="chrome",e.Chromium="chromium",e.Edge="edge",e.Firefox="firefox",e.Opera="opera",e.Safari="safari"}(r||(t.Browser=r={})),function(e){e.None="none",e.Development="development",e.Production="production"}(i||(t.Mode=i={}))},152:e=>{function t(e){var t=new Error("Cannot find module '"+e+"'");throw t.code="MODULE_NOT_FOUND",t}t.keys=()=>[],t.resolve=t,t.id=152,e.exports=t},13:e=>{"use strict";e.exports=require("cac")},14:e=>{"use strict";e.exports=require("lodash/isFunction")},813:e=>{"use strict";e.exports=require("lodash/isPlainObject")},95:e=>{"use strict";e.exports=require("mini-css-extract-plugin")},878:e=>{"use strict";e.exports=require("sass")},144:e=>{"use strict";e.exports=require("tsconfig-paths-webpack-plugin")},899:e=>{"use strict";e.exports=require("typescript")},807:e=>{"use strict";e.exports=require("webpack")},870:e=>{"use strict";e.exports=require("webpack-merge")},733:e=>{"use strict";e.exports=require("webpack-virtual-modules")},896:e=>{"use strict";e.exports=require("fs")},928:e=>{"use strict";e.exports=require("path")}},t={};function r(i){var s=t[i];if(void 0!==s)return s.exports;var n=t[i]={exports:{}};return e[i].call(n.exports,n,n.exports,r),n.exports}r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r(625)})();
|