adnbn 0.0.21 → 0.0.22

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.
@@ -4,22 +4,23 @@ var cac = require('cac');
4
4
  var webpack = require('webpack');
5
5
  var fs = require('fs');
6
6
  var c12 = require('c12');
7
- var VirtualModulesPlugin = require('webpack-virtual-modules');
8
- var _ = require('lodash');
9
- var ts2 = require('typescript');
7
+ var _2 = require('lodash');
10
8
  var path = require('path');
9
+ var ts2 = require('typescript');
10
+ var VirtualModulesPlugin = require('webpack-virtual-modules');
11
11
  var TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
12
12
  var MiniCssExtractPlugin = require('mini-css-extract-plugin');
13
+ var cleanWebpackPlugin = require('clean-webpack-plugin');
13
14
 
14
15
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
15
16
 
16
17
  var cac__default = /*#__PURE__*/_interopDefault(cac);
17
18
  var webpack__default = /*#__PURE__*/_interopDefault(webpack);
18
19
  var fs__default = /*#__PURE__*/_interopDefault(fs);
19
- var VirtualModulesPlugin__default = /*#__PURE__*/_interopDefault(VirtualModulesPlugin);
20
- var ___default = /*#__PURE__*/_interopDefault(_);
21
- var ts2__default = /*#__PURE__*/_interopDefault(ts2);
20
+ var _2__default = /*#__PURE__*/_interopDefault(_2);
22
21
  var path__default = /*#__PURE__*/_interopDefault(path);
22
+ var ts2__default = /*#__PURE__*/_interopDefault(ts2);
23
+ var VirtualModulesPlugin__default = /*#__PURE__*/_interopDefault(VirtualModulesPlugin);
23
24
  var TsconfigPathsPlugin__default = /*#__PURE__*/_interopDefault(TsconfigPathsPlugin);
24
25
  var MiniCssExtractPlugin__default = /*#__PURE__*/_interopDefault(MiniCssExtractPlugin);
25
26
 
@@ -42,8 +43,8 @@ var __commonJS = (cb, mod) => function __require2() {
42
43
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
43
44
  };
44
45
  var __export = (target, all) => {
45
- for (var name2 in all)
46
- __defProp(target, name2, { get: all[name2], enumerable: true });
46
+ for (var name3 in all)
47
+ __defProp(target, name3, { get: all[name3], enumerable: true });
47
48
  };
48
49
  var __copyProps = (to, from, except, desc) => {
49
50
  if (from && typeof from === "object" || typeof from === "function") {
@@ -134,7 +135,7 @@ var require_package = __commonJS({
134
135
  var require_main = __commonJS({
135
136
  "node_modules/dotenv/lib/main.js"(exports, module) {
136
137
  var fs4 = __require("fs");
137
- var path6 = __require("path");
138
+ var path7 = __require("path");
138
139
  var os = __require("os");
139
140
  var crypto = __require("crypto");
140
141
  var packageJson = require_package();
@@ -248,7 +249,7 @@ var require_main = __commonJS({
248
249
  possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
249
250
  }
250
251
  } else {
251
- possibleVaultPath = path6.resolve(process.cwd(), ".env.vault");
252
+ possibleVaultPath = path7.resolve(process.cwd(), ".env.vault");
252
253
  }
253
254
  if (fs4.existsSync(possibleVaultPath)) {
254
255
  return possibleVaultPath;
@@ -256,7 +257,7 @@ var require_main = __commonJS({
256
257
  return null;
257
258
  }
258
259
  function _resolveHome(envPath) {
259
- return envPath[0] === "~" ? path6.join(os.homedir(), envPath.slice(1)) : envPath;
260
+ return envPath[0] === "~" ? path7.join(os.homedir(), envPath.slice(1)) : envPath;
260
261
  }
261
262
  function _configVault(options) {
262
263
  _log("Loading env from encrypted .env.vault");
@@ -269,7 +270,7 @@ var require_main = __commonJS({
269
270
  return { parsed };
270
271
  }
271
272
  function configDotenv(options) {
272
- const dotenvPath = path6.resolve(process.cwd(), ".env");
273
+ const dotenvPath = path7.resolve(process.cwd(), ".env");
273
274
  let encoding = "utf8";
274
275
  const debug = Boolean(options && options.debug);
275
276
  if (options && options.encoding) {
@@ -292,13 +293,13 @@ var require_main = __commonJS({
292
293
  }
293
294
  let lastError;
294
295
  const parsedAll = {};
295
- for (const path7 of optionPaths) {
296
+ for (const path8 of optionPaths) {
296
297
  try {
297
- const parsed = DotenvModule.parse(fs4.readFileSync(path7, { encoding }));
298
+ const parsed = DotenvModule.parse(fs4.readFileSync(path8, { encoding }));
298
299
  DotenvModule.populate(parsedAll, parsed, options);
299
300
  } catch (e) {
300
301
  if (debug) {
301
- _debug(`Failed to load ${path7} ${e.message}`);
302
+ _debug(`Failed to load ${path8} ${e.message}`);
302
303
  }
303
304
  lastError = e;
304
305
  }
@@ -403,12 +404,12 @@ var require_filesystem = __commonJS({
403
404
  Object.defineProperty(exports, "__esModule", { value: true });
404
405
  exports.removeExtension = exports.fileExistsAsync = exports.readJsonFromDiskAsync = exports.readJsonFromDiskSync = exports.fileExistsSync = void 0;
405
406
  var fs4 = __require("fs");
406
- function fileExistsSync(path6) {
407
- if (!fs4.existsSync(path6)) {
407
+ function fileExistsSync(path7) {
408
+ if (!fs4.existsSync(path7)) {
408
409
  return false;
409
410
  }
410
411
  try {
411
- var stats = fs4.statSync(path6);
412
+ var stats = fs4.statSync(path7);
412
413
  return stats.isFile();
413
414
  } catch (err) {
414
415
  return false;
@@ -422,8 +423,8 @@ var require_filesystem = __commonJS({
422
423
  return __require(packageJsonPath);
423
424
  }
424
425
  exports.readJsonFromDiskSync = readJsonFromDiskSync;
425
- function readJsonFromDiskAsync(path6, callback) {
426
- fs4.readFile(path6, "utf8", function(err, result) {
426
+ function readJsonFromDiskAsync(path7, callback) {
427
+ fs4.readFile(path7, "utf8", function(err, result) {
427
428
  if (err || !result) {
428
429
  return callback();
429
430
  }
@@ -441,8 +442,8 @@ var require_filesystem = __commonJS({
441
442
  });
442
443
  }
443
444
  exports.fileExistsAsync = fileExistsAsync;
444
- function removeExtension(path6) {
445
- return path6.substring(0, path6.lastIndexOf(".")) || path6;
445
+ function removeExtension(path7) {
446
+ return path7.substring(0, path7.lastIndexOf(".")) || path7;
446
447
  }
447
448
  exports.removeExtension = removeExtension;
448
449
  }
@@ -453,7 +454,7 @@ var require_mapping_entry = __commonJS({
453
454
  "node_modules/tsconfig-paths/lib/mapping-entry.js"(exports) {
454
455
  Object.defineProperty(exports, "__esModule", { value: true });
455
456
  exports.getAbsoluteMappingEntries = void 0;
456
- var path6 = __require("path");
457
+ var path7 = __require("path");
457
458
  function getAbsoluteMappingEntries(absoluteBaseUrl, paths, addMatchAll) {
458
459
  var sortedKeys = sortByLongestPrefix(Object.keys(paths));
459
460
  var absolutePaths = [];
@@ -462,7 +463,7 @@ var require_mapping_entry = __commonJS({
462
463
  absolutePaths.push({
463
464
  pattern: key2,
464
465
  paths: paths[key2].map(function(pathToResolve) {
465
- return path6.resolve(absoluteBaseUrl, pathToResolve);
466
+ return path7.resolve(absoluteBaseUrl, pathToResolve);
466
467
  })
467
468
  });
468
469
  }
@@ -492,7 +493,7 @@ var require_try_path = __commonJS({
492
493
  "node_modules/tsconfig-paths/lib/try-path.js"(exports) {
493
494
  Object.defineProperty(exports, "__esModule", { value: true });
494
495
  exports.exhaustiveTypeException = exports.getStrippedPath = exports.getPathsToTry = void 0;
495
- var path6 = __require("path");
496
+ var path7 = __require("path");
496
497
  var path_1 = __require("path");
497
498
  var filesystem_1 = require_filesystem();
498
499
  function getPathsToTry(extensions, absolutePathMappings, requestedModule) {
@@ -512,9 +513,9 @@ var require_try_path = __commonJS({
512
513
  }));
513
514
  pathsToTry.push({
514
515
  type: "package",
515
- path: path6.join(physicalPath, "/package.json")
516
+ path: path7.join(physicalPath, "/package.json")
516
517
  });
517
- var indexPath = path6.join(physicalPath, "/index");
518
+ var indexPath = path7.join(physicalPath, "/index");
518
519
  pathsToTry.push.apply(pathsToTry, extensions.map(function(e) {
519
520
  return { type: "index", path: indexPath + e };
520
521
  }));
@@ -565,7 +566,7 @@ var require_match_path_sync = __commonJS({
565
566
  "node_modules/tsconfig-paths/lib/match-path-sync.js"(exports) {
566
567
  Object.defineProperty(exports, "__esModule", { value: true });
567
568
  exports.matchFromAbsolutePaths = exports.createMatchPath = void 0;
568
- var path6 = __require("path");
569
+ var path7 = __require("path");
569
570
  var Filesystem = require_filesystem();
570
571
  var MappingEntry = require_mapping_entry();
571
572
  var TryPath = require_try_path();
@@ -609,7 +610,7 @@ var require_match_path_sync = __commonJS({
609
610
  return obj[key2];
610
611
  }, packageJson);
611
612
  if (candidateMapping && typeof candidateMapping === "string") {
612
- var candidateFilePath = path6.join(path6.dirname(packageJsonPath), candidateMapping);
613
+ var candidateFilePath = path7.join(path7.dirname(packageJsonPath), candidateMapping);
613
614
  if (fileExists(candidateFilePath)) {
614
615
  return candidateFilePath;
615
616
  }
@@ -652,7 +653,7 @@ var require_match_path_async = __commonJS({
652
653
  "node_modules/tsconfig-paths/lib/match-path-async.js"(exports) {
653
654
  Object.defineProperty(exports, "__esModule", { value: true });
654
655
  exports.matchFromAbsolutePathsAsync = exports.createMatchPathAsync = void 0;
655
- var path6 = __require("path");
656
+ var path7 = __require("path");
656
657
  var TryPath = require_try_path();
657
658
  var MappingEntry = require_mapping_entry();
658
659
  var Filesystem = require_filesystem();
@@ -706,7 +707,7 @@ var require_match_path_async = __commonJS({
706
707
  if (typeof mainFieldMapping !== "string") {
707
708
  return tryNext();
708
709
  }
709
- var mappedFilePath = path6.join(path6.dirname(packageJsonPath), mainFieldMapping);
710
+ var mappedFilePath = path7.join(path7.dirname(packageJsonPath), mainFieldMapping);
710
711
  fileExistsAsync(mappedFilePath, function(err, exists) {
711
712
  if (err) {
712
713
  return doneCallback(err);
@@ -768,8 +769,8 @@ var dist_exports = {};
768
769
  __export(dist_exports, {
769
770
  default: () => dist_default
770
771
  });
771
- function internalize(holder, name2, reviver) {
772
- const value = holder[name2];
772
+ function internalize(holder, name3, reviver) {
773
+ const value = holder[name3];
773
774
  if (value != null && typeof value === "object") {
774
775
  if (Array.isArray(value)) {
775
776
  for (let i = 0; i < value.length; i++) {
@@ -802,7 +803,7 @@ function internalize(holder, name2, reviver) {
802
803
  }
803
804
  }
804
805
  }
805
- return reviver.call(holder, name2, value);
806
+ return reviver.call(holder, name3, value);
806
807
  }
807
808
  function lex() {
808
809
  lexState = "default";
@@ -1874,7 +1875,7 @@ var require_tsconfig_loader = __commonJS({
1874
1875
  };
1875
1876
  Object.defineProperty(exports, "__esModule", { value: true });
1876
1877
  exports.loadTsconfig = exports.walkForTsConfig = exports.tsConfigLoader = void 0;
1877
- var path6 = __require("path");
1878
+ var path7 = __require("path");
1878
1879
  var fs4 = __require("fs");
1879
1880
  var JSON52 = (init_dist(), __toCommonJS(dist_exports));
1880
1881
  var StripBom = require_strip_bom();
@@ -1904,14 +1905,14 @@ var require_tsconfig_loader = __commonJS({
1904
1905
  }
1905
1906
  function resolveConfigPath(cwd, filename) {
1906
1907
  if (filename) {
1907
- var absolutePath = fs4.lstatSync(filename).isDirectory() ? path6.resolve(filename, "./tsconfig.json") : path6.resolve(cwd, filename);
1908
+ var absolutePath = fs4.lstatSync(filename).isDirectory() ? path7.resolve(filename, "./tsconfig.json") : path7.resolve(cwd, filename);
1908
1909
  return absolutePath;
1909
1910
  }
1910
1911
  if (fs4.statSync(cwd).isFile()) {
1911
- return path6.resolve(cwd);
1912
+ return path7.resolve(cwd);
1912
1913
  }
1913
1914
  var configAbsolutePath = walkForTsConfig(cwd);
1914
- return configAbsolutePath ? path6.resolve(configAbsolutePath) : void 0;
1915
+ return configAbsolutePath ? path7.resolve(configAbsolutePath) : void 0;
1915
1916
  }
1916
1917
  function walkForTsConfig(directory, readdirSync) {
1917
1918
  if (readdirSync === void 0) {
@@ -1922,10 +1923,10 @@ var require_tsconfig_loader = __commonJS({
1922
1923
  for (var _i = 0, filesToCheck_1 = filesToCheck; _i < filesToCheck_1.length; _i++) {
1923
1924
  var fileToCheck = filesToCheck_1[_i];
1924
1925
  if (files.indexOf(fileToCheck) !== -1) {
1925
- return path6.join(directory, fileToCheck);
1926
+ return path7.join(directory, fileToCheck);
1926
1927
  }
1927
1928
  }
1928
- var parentDirectory = path6.dirname(directory);
1929
+ var parentDirectory = path7.dirname(directory);
1929
1930
  if (directory === parentDirectory) {
1930
1931
  return void 0;
1931
1932
  }
@@ -1972,15 +1973,15 @@ var require_tsconfig_loader = __commonJS({
1972
1973
  if (typeof extendedConfigValue === "string" && extendedConfigValue.indexOf(".json") === -1) {
1973
1974
  extendedConfigValue += ".json";
1974
1975
  }
1975
- var currentDir = path6.dirname(configFilePath);
1976
- var extendedConfigPath = path6.join(currentDir, extendedConfigValue);
1976
+ var currentDir = path7.dirname(configFilePath);
1977
+ var extendedConfigPath = path7.join(currentDir, extendedConfigValue);
1977
1978
  if (extendedConfigValue.indexOf("/") !== -1 && extendedConfigValue.indexOf(".") !== -1 && !existsSync2(extendedConfigPath)) {
1978
- extendedConfigPath = path6.join(currentDir, "node_modules", extendedConfigValue);
1979
+ extendedConfigPath = path7.join(currentDir, "node_modules", extendedConfigValue);
1979
1980
  }
1980
1981
  var config = loadTsconfig(extendedConfigPath, existsSync2, readFileSync) || {};
1981
1982
  if ((_a = config.compilerOptions) === null || _a === void 0 ? void 0 : _a.baseUrl) {
1982
- var extendsDir = path6.dirname(extendedConfigValue);
1983
- config.compilerOptions.baseUrl = path6.join(extendsDir, config.compilerOptions.baseUrl);
1983
+ var extendsDir = path7.dirname(extendedConfigValue);
1984
+ config.compilerOptions.baseUrl = path7.join(extendsDir, config.compilerOptions.baseUrl);
1984
1985
  }
1985
1986
  return config;
1986
1987
  }
@@ -1998,7 +1999,7 @@ var require_config_loader = __commonJS({
1998
1999
  Object.defineProperty(exports, "__esModule", { value: true });
1999
2000
  exports.configLoader = exports.loadConfig = void 0;
2000
2001
  var TsConfigLoader2 = require_tsconfig_loader();
2001
- var path6 = __require("path");
2002
+ var path7 = __require("path");
2002
2003
  function loadConfig2(cwd) {
2003
2004
  if (cwd === void 0) {
2004
2005
  cwd = process.cwd();
@@ -2009,7 +2010,7 @@ var require_config_loader = __commonJS({
2009
2010
  function configLoader(_a) {
2010
2011
  var cwd = _a.cwd, explicitParams = _a.explicitParams, _b = _a.tsConfigLoader, tsConfigLoader = _b === void 0 ? TsConfigLoader2.tsConfigLoader : _b;
2011
2012
  if (explicitParams) {
2012
- var absoluteBaseUrl = path6.isAbsolute(explicitParams.baseUrl) ? explicitParams.baseUrl : path6.join(cwd, explicitParams.baseUrl);
2013
+ var absoluteBaseUrl = path7.isAbsolute(explicitParams.baseUrl) ? explicitParams.baseUrl : path7.join(cwd, explicitParams.baseUrl);
2013
2014
  return {
2014
2015
  resultType: "success",
2015
2016
  configFileAbsolutePath: "",
@@ -2036,7 +2037,7 @@ var require_config_loader = __commonJS({
2036
2037
  resultType: "success",
2037
2038
  configFileAbsolutePath: loadResult.tsConfigPath,
2038
2039
  baseUrl: loadResult.baseUrl,
2039
- absoluteBaseUrl: path6.resolve(path6.dirname(loadResult.tsConfigPath), loadResult.baseUrl || ""),
2040
+ absoluteBaseUrl: path7.resolve(path7.dirname(loadResult.tsConfigPath), loadResult.baseUrl || ""),
2040
2041
  paths: loadResult.paths || {},
2041
2042
  addMatchAll: loadResult.baseUrl !== void 0
2042
2043
  };
@@ -2604,8 +2605,8 @@ var require_kind_of = __commonJS({
2604
2605
  if (val instanceof RegExp) return true;
2605
2606
  return typeof val.flags === "string" && typeof val.ignoreCase === "boolean" && typeof val.multiline === "boolean" && typeof val.global === "boolean";
2606
2607
  }
2607
- function isGeneratorFn(name2, val) {
2608
- return ctorName(name2) === "GeneratorFunction";
2608
+ function isGeneratorFn(name3, val) {
2609
+ return ctorName(name3) === "GeneratorFunction";
2609
2610
  }
2610
2611
  function isGeneratorObj(val) {
2611
2612
  return typeof val.throw === "function" && typeof val.return === "function" && typeof val.next === "function";
@@ -3440,6 +3441,7 @@ function definePlugin(plugin) {
3440
3441
  var dotenv_default = definePlugin((options) => {
3441
3442
  const { vars = {} } = options || {};
3442
3443
  return {
3444
+ name: undefined,
3443
3445
  webpack: {
3444
3446
  plugins: [
3445
3447
  new webpack__default.default.DefinePlugin({
@@ -3530,6 +3532,11 @@ var Mode = /* @__PURE__ */ ((Mode2) => {
3530
3532
  Mode2["Production"] = "production";
3531
3533
  return Mode2;
3532
3534
  })(Mode || {});
3535
+ var Command = /* @__PURE__ */ ((Command2) => {
3536
+ Command2["Build"] = "build";
3537
+ Command2["Watch"] = "watch";
3538
+ return Command2;
3539
+ })(Command || {});
3533
3540
 
3534
3541
  // src/cli/parsers/entrypoint/resolvers/core.ts
3535
3542
  var name = "adnbn";
@@ -3551,16 +3558,24 @@ var core_default = () => {
3551
3558
  value
3552
3559
  });
3553
3560
  });
3561
+ Object.entries(Command).forEach(([key2, value]) => {
3562
+ resolvers.push({
3563
+ from: name,
3564
+ target: "Command",
3565
+ name: key2,
3566
+ value
3567
+ });
3568
+ });
3554
3569
  return resolvers;
3555
3570
  };
3556
3571
 
3557
3572
  // src/cli/parsers/entrypoint/resolvers/index.ts
3558
- var resolvers_default = (resolvers) => (form, target, name2) => {
3573
+ var resolvers_default = (resolvers) => (form, target, name3) => {
3559
3574
  var _a;
3560
3575
  return (_a = [
3561
3576
  ...resolvers,
3562
3577
  ...core_default()
3563
- ].find((resolver) => resolver.from === form && resolver.target === target && resolver.name === name2)) == null ? void 0 : _a.value;
3578
+ ].find((resolver) => resolver.from === form && resolver.target === target && resolver.name === name3)) == null ? void 0 : _a.value;
3564
3579
  };
3565
3580
 
3566
3581
  // src/cli/parsers/entrypoint/SourceFile.ts
@@ -3641,10 +3656,10 @@ var EntryFile = class _EntryFile {
3641
3656
  node.declarationList.declarations.forEach((declaration) => {
3642
3657
  var _a2;
3643
3658
  if (ts2__default.default.isIdentifier(declaration.name) && declaration.initializer) {
3644
- const name2 = declaration.name.text;
3659
+ const name3 = declaration.name.text;
3645
3660
  const value = this.parseNode(declaration.initializer);
3646
- (_a2 = this.variables) == null ? void 0 : _a2.set(name2, {
3647
- name: name2,
3661
+ (_a2 = this.variables) == null ? void 0 : _a2.set(name3, {
3662
+ name: name3,
3648
3663
  value,
3649
3664
  exported: isExported || false
3650
3665
  });
@@ -3654,11 +3669,11 @@ var EntryFile = class _EntryFile {
3654
3669
  if (ts2__default.default.isExportDeclaration(node) && node.exportClause && ts2__default.default.isNamedExports(node.exportClause)) {
3655
3670
  node.exportClause.elements.forEach((el) => {
3656
3671
  var _a2, _b2, _c2;
3657
- const name2 = el.name.text;
3658
- if ((_a2 = this.variables) == null ? void 0 : _a2.has(name2)) {
3659
- const variable = (_b2 = this.variables) == null ? void 0 : _b2.get(name2);
3660
- (_c2 = this.variables) == null ? void 0 : _c2.set(name2, {
3661
- name: name2,
3672
+ const name3 = el.name.text;
3673
+ if ((_a2 = this.variables) == null ? void 0 : _a2.has(name3)) {
3674
+ const variable = (_b2 = this.variables) == null ? void 0 : _b2.get(name3);
3675
+ (_c2 = this.variables) == null ? void 0 : _c2.set(name3, {
3676
+ name: name3,
3662
3677
  value: variable.value,
3663
3678
  exported: true
3664
3679
  });
@@ -3669,9 +3684,9 @@ var EntryFile = class _EntryFile {
3669
3684
  const expr = node.expression;
3670
3685
  if (ts2__default.default.isIdentifier(expr) && ((_b = this.variables) == null ? void 0 : _b.has(expr.text))) {
3671
3686
  const variable = (_c = this.variables) == null ? void 0 : _c.get(expr.text);
3672
- const name2 = "default";
3673
- (_d = this.variables) == null ? void 0 : _d.set(name2, {
3674
- name: name2,
3687
+ const name3 = "default";
3688
+ (_d = this.variables) == null ? void 0 : _d.set(name3, {
3689
+ name: name3,
3675
3690
  value: variable.value,
3676
3691
  exported: true
3677
3692
  });
@@ -3682,8 +3697,8 @@ var EntryFile = class _EntryFile {
3682
3697
  parse3(this.getSourceFile());
3683
3698
  return this.variables;
3684
3699
  }
3685
- resolveValue(from, target, name2) {
3686
- return resolvers_default([])(from, target, name2);
3700
+ resolveValue(from, target, name3) {
3701
+ return resolvers_default([])(from, target, name3);
3687
3702
  }
3688
3703
  findPropertyAccessValue(property) {
3689
3704
  if (ts2__default.default.isPropertyAccessExpression(property)) {
@@ -3772,7 +3787,7 @@ var OptionFile_default = class extends EntryFile {
3772
3787
  return { ...this.getOptionsFromVariables(), ...this.getOptionsFromDefinition() };
3773
3788
  }
3774
3789
  getOptionsFromVariables() {
3775
- return Array.from(this.getVariables().values()).filter(({ name: name2, exported }) => exported && this.properties.includes(name2)).reduce((config, { name: name2, value }) => ({ ...config, [name2]: value }), {});
3790
+ return Array.from(this.getVariables().values()).filter(({ name: name3, exported }) => exported && this.properties.includes(name3)).reduce((config, { name: name3, value }) => ({ ...config, [name3]: value }), {});
3776
3791
  }
3777
3792
  getOptionsFromDefinition() {
3778
3793
  let options = {};
@@ -3806,77 +3821,8 @@ var commonProperties = [
3806
3821
  var getBackgroundOptions = (file) => {
3807
3822
  return OptionFile_default.make(file).setDefinition("defineBackground").setProperties([...commonProperties, "persistent"]).getOptions();
3808
3823
  };
3809
- var getRootPath = (to) => {
3810
- return path__default.default.resolve(process.cwd(), to);
3811
- };
3812
- var getSharedPath = (config, to) => {
3813
- return path__default.default.join(config.inputDir, config.srcDir, config.sharedDir, "");
3814
- };
3815
- var getAppsPath = (config, to) => {
3816
- return path__default.default.join(config.inputDir, config.srcDir, config.appsDir, config.app, to ?? "");
3817
- };
3818
- var getInputPath = (config, to) => {
3819
- return path__default.default.join(config.inputDir, to ?? "");
3820
- };
3821
- var getOutputPath = (config) => {
3822
- return path__default.default.join(config.outputDir, `${config.app}-${config.browser}-mv${config.manifestVersion}`);
3823
- };
3824
- var getConfigFile = (config) => {
3825
- return getInputPath(config, config.configFile);
3826
- };
3827
- var escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3828
- var pathToImport = (filePath) => {
3829
- const { dir, name: name2, ext } = path__default.default.parse(filePath);
3830
- if (name2 === "index" && (ext === ".ts" || ext === ".tsx")) {
3831
- return dir;
3832
- }
3833
- return path__default.default.join(dir, name2);
3834
- };
3835
- var findEntrypointFiles = (directory, entrypoint) => {
3836
- const files = [];
3837
- const regex = new RegExp(
3838
- `^(?:.*\\.)?${escapeRegExp(entrypoint)}\\.(ts|tsx)$`
3839
- );
3840
- const finder = (dir) => {
3841
- let entries;
3842
- try {
3843
- entries = fs__default.default.readdirSync(dir, { withFileTypes: true });
3844
- } catch (e) {
3845
- console.log("Error reading entrypoint directory:", dir);
3846
- return;
3847
- }
3848
- for (const entry of entries) {
3849
- const fullPath = path__default.default.join(dir, entry.name);
3850
- if (entry.isDirectory()) {
3851
- if (entry.name === entrypoint || entry.name.endsWith(`.${entrypoint}`)) {
3852
- const possibleIndexFiles = ["index.ts", "index.tsx"];
3853
- for (const indexFile of possibleIndexFiles) {
3854
- const indexPath = path__default.default.join(fullPath, indexFile);
3855
- try {
3856
- const stat = fs__default.default.statSync(indexPath);
3857
- if (stat.isFile()) {
3858
- files.push({ file: indexPath, import: pathToImport(indexPath) });
3859
- }
3860
- } catch (e) {
3861
- }
3862
- }
3863
- }
3864
- finder(fullPath);
3865
- } else if (entry.isFile()) {
3866
- if (regex.test(entry.name)) {
3867
- files.push({ file: fullPath, import: pathToImport(fullPath) });
3868
- }
3869
- }
3870
- }
3871
- };
3872
- finder(directory);
3873
- return files;
3874
- };
3875
- var findBackgroundFiles = (directory) => {
3876
- return findEntrypointFiles(directory, "background");
3877
- };
3878
3824
  var resolvePluginHandler = async (handler, options) => {
3879
- if (___default.default.isFunction(handler)) {
3825
+ if (_2__default.default.isFunction(handler)) {
3880
3826
  const result = handler(options);
3881
3827
  if (result instanceof Promise) {
3882
3828
  return await result;
@@ -3906,7 +3852,7 @@ var isValidEntrypointOptions = (options, config) => {
3906
3852
  return !(((_c = options.excludeBrowser) == null ? void 0 : _c.includes(browser)) || ((_d = options.excludeApp) == null ? void 0 : _d.includes(app)));
3907
3853
  };
3908
3854
 
3909
- // src/cli/plugins/background/background.ts
3855
+ // src/cli/plugins/background/entrypoint/background.ts
3910
3856
  var backgroundFilesToEntries = (files) => {
3911
3857
  const entries = /* @__PURE__ */ new Map();
3912
3858
  for (const file of files) {
@@ -3914,62 +3860,53 @@ var backgroundFilesToEntries = (files) => {
3914
3860
  }
3915
3861
  return entries;
3916
3862
  };
3917
- var findBackgroundEntriesByDir = (dir) => {
3918
- console.log("QQQQQQQQQ", findBackgroundFiles(dir));
3919
- return backgroundFilesToEntries(findBackgroundFiles(dir));
3920
- };
3921
- var getBackgroundEntries = async (config) => {
3863
+ var background_default = async (config) => {
3922
3864
  let entries = /* @__PURE__ */ new Map();
3923
- const appBackgroundEntries = findBackgroundEntriesByDir(getAppsPath(config));
3924
- if (appBackgroundEntries.size > 0) {
3925
- entries = new Map([...entries, ...appBackgroundEntries]);
3926
- if (config.debug) {
3927
- console.info("App background added:", appBackgroundEntries);
3928
- }
3929
- }
3930
- if (appBackgroundEntries.size > 0 && config.mergeBackground || appBackgroundEntries.size === 0) {
3931
- const sharedBackgroundEntries = findBackgroundEntriesByDir(getSharedPath(config));
3932
- if (sharedBackgroundEntries.size > 0) {
3933
- entries = new Map([...entries, ...sharedBackgroundEntries]);
3934
- if (config.debug) {
3935
- console.info("Shared background added:", sharedBackgroundEntries);
3936
- }
3937
- }
3938
- }
3939
3865
  const pluginBackgroundResult = await Array.fromAsync(processPluginHandler(config, "background", {
3940
- config,
3941
- entries
3866
+ config
3942
3867
  }));
3943
3868
  if (pluginBackgroundResult.length > 0) {
3944
- const pluginBackgroundFiles = pluginBackgroundResult.map(({ name: name2, result: endpoint }) => {
3945
- if (___default.default.isBoolean(endpoint)) {
3946
- endpoint = "background";
3869
+ const pluginBackgroundFiles = pluginBackgroundResult.reduce((files, { name: name3, result }) => {
3870
+ let endpoints = [];
3871
+ if (_2__default.default.isBoolean(result)) {
3872
+ endpoints = ["background"];
3873
+ } else if (_2__default.default.isString(result) || _2__default.default.isPlainObject(result)) {
3874
+ endpoints = [result];
3875
+ } else if (_2__default.default.isArray(result)) {
3876
+ endpoints = result;
3877
+ }
3878
+ let next = [];
3879
+ for (const endpoint of endpoints) {
3880
+ if (_2__default.default.isString(endpoint)) {
3881
+ const resolved = path__default.default.join(name3, endpoint);
3882
+ next.push({
3883
+ file: __require.resolve(resolved, { paths: [process.cwd()] }),
3884
+ import: resolved,
3885
+ external: true
3886
+ });
3887
+ } else {
3888
+ next.push(endpoint);
3889
+ }
3947
3890
  }
3948
- const resolved = `${name2}/${endpoint}`;
3949
- return {
3950
- file: __require.resolve(resolved, { paths: [process.cwd()] }),
3951
- import: resolved
3952
- };
3953
- });
3891
+ return [...files, ...next];
3892
+ }, []);
3954
3893
  const pluginBackgroundEntries = backgroundFilesToEntries(pluginBackgroundFiles);
3955
- entries = new Map([...entries, ...pluginBackgroundEntries]);
3894
+ entries = new Map(
3895
+ [...pluginBackgroundEntries].filter(([_5, options]) => isValidEntrypointOptions(options, config))
3896
+ );
3956
3897
  if (config.debug) {
3957
- console.info("Plugin background added:", pluginBackgroundEntries);
3898
+ console.info("Plugin background entries:", pluginBackgroundEntries);
3958
3899
  }
3959
3900
  }
3960
3901
  return entries;
3961
3902
  };
3962
- var background_default = async (config) => {
3963
- const entries = Array.from(await getBackgroundEntries(config)).filter(([_4, options]) => isValidEntrypointOptions(options, config));
3964
- const files = entries.map(([file]) => file);
3965
- const persistent = entries.some(([_4, { persistent: persistent2 }]) => persistent2);
3966
- return { files, persistent };
3967
- };
3968
3903
 
3969
3904
  // raw-loader:./background.ts?raw
3970
- var background_default2 = `import * as module from "virtual:background-entrypoint";
3905
+ var background_default2 = `//@ts-ignore
3971
3906
  import {type BackgroundDefinition} from "adnbn";
3972
3907
 
3908
+ import * as module from "virtual:background-entrypoint";
3909
+
3973
3910
  import _isFunction from "lodash/isFunction";
3974
3911
  import _isPlainObject from "lodash/isPlainObject";
3975
3912
 
@@ -3984,7 +3921,6 @@ try {
3984
3921
  definition = {...definition, main: defaultDefinition};
3985
3922
  }
3986
3923
 
3987
- // @ts-ignore
3988
3924
  const {main, ...options} = definition;
3989
3925
 
3990
3926
  if (_isFunction(main)) {
@@ -3998,42 +3934,274 @@ try {
3998
3934
  `;
3999
3935
 
4000
3936
  // src/cli/virtual/index.ts
3937
+ var templates = { background: background_default2 };
4001
3938
  var getVirtualModule = (file, template) => {
4002
- return background_default2.replace(`virtual:${template}-entrypoint`, file);
3939
+ return templates[template].replace(`virtual:${template}-entrypoint`, file);
4003
3940
  };
4004
3941
  var virtualBackgroundModule = (file) => {
4005
3942
  return getVirtualModule(file, "background");
4006
3943
  };
4007
- var background_default3 = definePlugin((options) => {
4008
- const { name: name2 = "background" } = options || {};
3944
+ var EntrypointPlugin = class _EntrypointPlugin {
3945
+ constructor(entries = {}, key2) {
3946
+ this.entries = entries;
3947
+ this.key = key2;
3948
+ }
3949
+ _plugin;
3950
+ _modules;
3951
+ template;
3952
+ update;
3953
+ static filename(file) {
3954
+ let name3 = file.file;
3955
+ if (file.external) {
3956
+ const { ext } = path__default.default.parse(name3);
3957
+ name3 = file.import + ext;
3958
+ }
3959
+ return path__default.default.join("virtual", name3);
3960
+ }
3961
+ get plugin() {
3962
+ if (this._plugin) {
3963
+ return this._plugin;
3964
+ }
3965
+ const modules = Object.fromEntries(this.getModuleContents(this.modules));
3966
+ return this._plugin = new VirtualModulesPlugin__default.default(modules);
3967
+ }
3968
+ get modules() {
3969
+ return this._modules ?? (this._modules = this.createModules(this.entries));
3970
+ }
3971
+ get watchFiles() {
3972
+ const files = Array.from(this.modules.values()).flatMap((modules) => Array.from(modules.keys())).filter(({ external }) => !external).map(({ file }) => file);
3973
+ return new Set(files);
3974
+ }
3975
+ virtual(template) {
3976
+ this.template = template;
3977
+ return this;
3978
+ }
3979
+ watch(update) {
3980
+ this.update = update;
3981
+ return this;
3982
+ }
3983
+ apply(compiler) {
3984
+ this.plugin.apply(compiler);
3985
+ compiler.hooks.entryOption.tap("EntrypointPlugin", (_5, entry) => {
3986
+ this.hookEntryOption(entry);
3987
+ });
3988
+ if (this.update) {
3989
+ compiler.hooks.watchRun.tapAsync("EntrypointPlugin", (compiler2, callback) => {
3990
+ this.hookWatchRun(compiler2).then(() => callback()).catch(callback);
3991
+ });
3992
+ }
3993
+ }
3994
+ hookEntryOption(entry) {
3995
+ if (_2__default.default.isPlainObject(entry)) {
3996
+ this.modules.entries().forEach(([name3, modules]) => {
3997
+ let currentFiles = structuredClone(entry[name3] ?? []);
3998
+ if ("import" in currentFiles) {
3999
+ currentFiles = currentFiles.import;
4000
+ }
4001
+ currentFiles.push(...Array.from(modules.values(), ({ name: name4 }) => name4));
4002
+ entry[name3] = {
4003
+ import: _2__default.default.uniq(currentFiles)
4004
+ };
4005
+ });
4006
+ } else {
4007
+ throw new Error("EntrypointPlugin: entry is not an object");
4008
+ }
4009
+ }
4010
+ async hookWatchRun(compiler) {
4011
+ const { modifiedFiles = /* @__PURE__ */ new Set() } = compiler;
4012
+ const watchFiles = this.watchFiles;
4013
+ const needUpdate = Array.from(modifiedFiles).some((file) => {
4014
+ if (path__default.default.isAbsolute(file)) {
4015
+ file = path__default.default.relative(compiler.context, file);
4016
+ }
4017
+ return watchFiles.has(file);
4018
+ });
4019
+ if (!needUpdate) {
4020
+ return;
4021
+ }
4022
+ const updatedEntries = await this.update(modifiedFiles);
4023
+ const updatedModules = this.createModules(updatedEntries);
4024
+ const currentContents = this.getModuleContents(this.modules);
4025
+ const updatedContents = this.getModuleContents(updatedModules);
4026
+ const removedContents = new Map(
4027
+ Array.from(currentContents).filter(([key2]) => !updatedContents.has(key2))
4028
+ );
4029
+ const addedContents = new Map(
4030
+ Array.from(updatedContents).filter(([key2]) => !currentContents.has(key2))
4031
+ );
4032
+ if (removedContents.size > 0 || addedContents.size > 0) {
4033
+ removedContents.keys().forEach((name3) => {
4034
+ this.plugin.writeModule(name3, "");
4035
+ });
4036
+ addedContents.forEach((content, name3) => {
4037
+ this.plugin.writeModule(name3, content);
4038
+ });
4039
+ updatedModules.entries().forEach(([name3, modules]) => {
4040
+ let entry = structuredClone(compiler.options.entry[name3]);
4041
+ if ("import" in entry) {
4042
+ entry = entry.import;
4043
+ }
4044
+ entry = entry.filter((file) => !removedContents.has(file));
4045
+ entry.push(...Array.from(modules.values(), ({ name: name4 }) => name4));
4046
+ compiler.options.entry[name3] = _2__default.default.uniq(entry);
4047
+ });
4048
+ }
4049
+ this._modules = updatedModules;
4050
+ }
4051
+ createModules(entries) {
4052
+ const entryModules = /* @__PURE__ */ new Map();
4053
+ _2__default.default.forEach(entries, (files, name3) => {
4054
+ const modules = /* @__PURE__ */ new Map();
4055
+ _2__default.default.forEach(files, (file) => {
4056
+ modules.set(file, {
4057
+ name: _EntrypointPlugin.filename(file),
4058
+ module: this.template ? this.template(file) : ""
4059
+ });
4060
+ });
4061
+ entryModules.set(name3, modules);
4062
+ });
4063
+ return entryModules;
4064
+ }
4065
+ getModuleContents(modules) {
4066
+ const content = /* @__PURE__ */ new Map();
4067
+ modules.values().forEach((modules2) => {
4068
+ modules2.forEach(({ name: name3, module }) => {
4069
+ content.set(name3, module);
4070
+ });
4071
+ });
4072
+ return content;
4073
+ }
4074
+ };
4075
+ var EntrypointPlugin_default = EntrypointPlugin;
4076
+ var getRootPath = (to) => {
4077
+ return path__default.default.resolve(process.cwd(), to);
4078
+ };
4079
+ var getSharedPath = (config, to) => {
4080
+ return path__default.default.join(config.inputDir, config.srcDir, config.sharedDir, "");
4081
+ };
4082
+ var getAppsPath = (config, to) => {
4083
+ return path__default.default.join(config.inputDir, config.srcDir, config.appsDir, config.app, to ?? "");
4084
+ };
4085
+ var getInputPath = (config, to) => {
4086
+ return path__default.default.join(config.inputDir, to ?? "");
4087
+ };
4088
+ var getOutputPath = (config) => {
4089
+ return path__default.default.join(config.outputDir, `${config.app}-${config.browser}-mv${config.manifestVersion}`);
4090
+ };
4091
+ var getConfigFile = (config) => {
4092
+ return getInputPath(config, config.configFile);
4093
+ };
4094
+
4095
+ // src/cli/resolvers/entrypoint.ts
4096
+ var escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4097
+ var pathToImport = (filePath) => {
4098
+ const { dir, name: name3, ext } = path__default.default.parse(filePath);
4099
+ if (name3 === "index" && (ext === ".ts" || ext === ".tsx")) {
4100
+ return dir;
4101
+ }
4102
+ return path__default.default.join(dir, name3);
4103
+ };
4104
+ var findEntrypointFiles = (directory, entrypoint) => {
4105
+ const files = [];
4106
+ const regex = new RegExp(
4107
+ `^(?:.*\\.)?${escapeRegExp(entrypoint)}\\.(ts|tsx)$`
4108
+ );
4109
+ const finder = (dir) => {
4110
+ let entries;
4111
+ try {
4112
+ entries = fs__default.default.readdirSync(dir, { withFileTypes: true });
4113
+ } catch (e) {
4114
+ console.log("Error reading entrypoint directory:", dir);
4115
+ return;
4116
+ }
4117
+ for (const entry of entries) {
4118
+ const fullPath = path__default.default.join(dir, entry.name);
4119
+ if (entry.isDirectory()) {
4120
+ if (entry.name === entrypoint || entry.name.endsWith(`.${entrypoint}`)) {
4121
+ const possibleIndexFiles = ["index.ts", "index.tsx"];
4122
+ for (const indexFile of possibleIndexFiles) {
4123
+ const indexPath = path__default.default.join(fullPath, indexFile);
4124
+ try {
4125
+ const stat = fs__default.default.statSync(indexPath);
4126
+ if (stat.isFile()) {
4127
+ files.push({ file: indexPath, import: pathToImport(indexPath) });
4128
+ }
4129
+ } catch (e) {
4130
+ }
4131
+ }
4132
+ }
4133
+ finder(fullPath);
4134
+ } else if (entry.isFile()) {
4135
+ if (regex.test(entry.name)) {
4136
+ files.push({ file: fullPath, import: pathToImport(fullPath) });
4137
+ }
4138
+ }
4139
+ }
4140
+ };
4141
+ finder(directory);
4142
+ return files;
4143
+ };
4144
+ var getEntrypointFiles = (config, entrypoint) => {
4145
+ let files = [];
4146
+ const appFiles = findEntrypointFiles(getAppsPath(config), entrypoint);
4147
+ if (appFiles.length > 0) {
4148
+ files.push(...appFiles);
4149
+ if (config.debug) {
4150
+ console.info("App files added:", appFiles);
4151
+ }
4152
+ }
4153
+ if (appFiles.length > 0 && config.mergeBackground || appFiles.length === 0) {
4154
+ const sharedFiles = findEntrypointFiles(getSharedPath(config), entrypoint);
4155
+ if (sharedFiles.length > 0) {
4156
+ files.push(...sharedFiles);
4157
+ if (config.debug) {
4158
+ console.info("Shared files added:", sharedFiles);
4159
+ }
4160
+ }
4161
+ }
4162
+ return files;
4163
+ };
4164
+
4165
+ // src/cli/plugins/background/index.ts
4166
+ var name2 = "background";
4167
+ var isPersistent = (background) => {
4168
+ return Array.from(background.values()).some(({ persistent }) => persistent);
4169
+ };
4170
+ var getEntry = (background) => {
4171
+ return { [name2]: Array.from(background.keys()) };
4172
+ };
4173
+ var background_default3 = definePlugin(() => {
4009
4174
  let hasBackground = false;
4010
4175
  let persistent;
4011
4176
  return {
4012
4177
  name: undefined,
4178
+ background: ({ config }) => getEntrypointFiles(config, "background"),
4013
4179
  webpack: async ({ config, webpack: webpack4 }) => {
4014
- const { files: backgroundFiles, persistent: backgroundPersistent } = await background_default(config);
4015
- const files = backgroundFiles;
4016
- if (files.length === 0) {
4180
+ const backgroundEntrypoint = await background_default(config);
4181
+ if (backgroundEntrypoint.size === 0) {
4017
4182
  if (config.debug) {
4018
4183
  console.warn("Background entries not found");
4019
4184
  }
4020
4185
  return {};
4021
4186
  }
4022
4187
  hasBackground = true;
4023
- persistent = backgroundPersistent;
4024
- const m = files.reduce((m2, file) => ({ ...m2, [path__default.default.join("virtual", file.import)]: virtualBackgroundModule(file.import) }), {});
4025
- console.log("m", m);
4026
- const virtualModules = new VirtualModulesPlugin__default.default(m);
4027
- const entry = { [name2]: Object.keys(m) };
4188
+ persistent = isPersistent(backgroundEntrypoint);
4189
+ const backgroundEntrypointPlugin = new EntrypointPlugin_default(getEntry(backgroundEntrypoint), "background-entrypoint").virtual((file) => virtualBackgroundModule(file.import));
4190
+ if (config.command === "watch" /* Watch */) {
4191
+ backgroundEntrypointPlugin.watch(async () => {
4192
+ const backgroundEntrypoint2 = await background_default(config);
4193
+ persistent = isPersistent(backgroundEntrypoint2);
4194
+ return getEntry(backgroundEntrypoint2);
4195
+ });
4196
+ }
4028
4197
  let resolvedWebpack = {
4029
- entry,
4030
- plugins: [virtualModules],
4198
+ plugins: [backgroundEntrypointPlugin],
4031
4199
  optimization: {
4032
4200
  splitChunks: {
4033
4201
  chunks(chunk) {
4034
4202
  var _a;
4035
4203
  const { chunks } = ((_a = webpack4.optimization) == null ? void 0 : _a.splitChunks) || {};
4036
- if (___default.default.isFunction(chunks) && !chunks(chunk)) {
4204
+ if (_2__default.default.isFunction(chunks) && !chunks(chunk)) {
4037
4205
  return false;
4038
4206
  }
4039
4207
  return chunk.name !== name2;
@@ -4045,7 +4213,7 @@ var background_default3 = definePlugin((options) => {
4045
4213
  },
4046
4214
  manifest: ({ manifest }) => {
4047
4215
  if (hasBackground) {
4048
- manifest.resetBackground({
4216
+ manifest.setBackground({
4049
4217
  entry: name2,
4050
4218
  persistent
4051
4219
  });
@@ -4102,8 +4270,9 @@ var loadDotenv = (config) => {
4102
4270
  };
4103
4271
  var config_default = async (config) => {
4104
4272
  let {
4273
+ command = "build" /* Build */,
4105
4274
  debug = false,
4106
- configFile = "addonbone.config.ts",
4275
+ configFile = "adnbn.config.ts",
4107
4276
  app = "myapp",
4108
4277
  browser = "chrome" /* Chrome */,
4109
4278
  inputDir = ".",
@@ -4124,6 +4293,7 @@ var config_default = async (config) => {
4124
4293
  concatContentScripts = true
4125
4294
  } = config;
4126
4295
  let resolvedConfig = {
4296
+ command,
4127
4297
  debug,
4128
4298
  mode,
4129
4299
  app,
@@ -4179,10 +4349,11 @@ var ManifestBase_default = class {
4179
4349
  description = "__MSG_app_description__";
4180
4350
  version = "0.0.0";
4181
4351
  background;
4352
+ commands = /* @__PURE__ */ new Set();
4182
4353
  contentScripts = /* @__PURE__ */ new Map();
4183
4354
  dependencies = /* @__PURE__ */ new Map();
4184
- setName(name2) {
4185
- this.name = name2;
4355
+ setName(name3) {
4356
+ this.name = name3;
4186
4357
  return this;
4187
4358
  }
4188
4359
  setShortName(shortName) {
@@ -4197,14 +4368,16 @@ var ManifestBase_default = class {
4197
4368
  this.version = version2;
4198
4369
  return this;
4199
4370
  }
4200
- resetBackground(background) {
4371
+ setBackground(background) {
4201
4372
  this.background = background;
4202
4373
  return this;
4203
4374
  }
4204
- pushContentScript(...content) {
4205
- for (const script of content) {
4206
- this.contentScripts.set(script.entry, script);
4207
- }
4375
+ setCommands(commands) {
4376
+ this.commands = commands;
4377
+ return this;
4378
+ }
4379
+ setContentScript(contentScripts) {
4380
+ this.contentScripts = contentScripts;
4208
4381
  return this;
4209
4382
  }
4210
4383
  setDependencies(dependencies) {
@@ -4226,9 +4399,33 @@ var ManifestBase_default = class {
4226
4399
  version: this.version,
4227
4400
  manifest_version: this.getManifestVersion()
4228
4401
  };
4229
- manifest = this.marge(manifest, this.buildBackground(), this.buildContentScripts());
4402
+ manifest = this.marge(
4403
+ manifest,
4404
+ this.buildBackground(),
4405
+ this.buildCommands(),
4406
+ this.buildContentScripts()
4407
+ );
4230
4408
  return manifest;
4231
4409
  }
4410
+ buildCommands() {
4411
+ if (this.commands.size > 0) {
4412
+ const commands = Array.from(this.commands).reduce((commands2, command) => {
4413
+ const item = {
4414
+ suggested_key: {
4415
+ default: command == null ? void 0 : command.defaultKey,
4416
+ windows: command == null ? void 0 : command.windowsKey,
4417
+ mac: command == null ? void 0 : command.macKey,
4418
+ chromeos: command == null ? void 0 : command.chromeosKey,
4419
+ linux: command == null ? void 0 : command.linuxKey
4420
+ },
4421
+ description: command == null ? void 0 : command.description,
4422
+ global: command == null ? void 0 : command.global
4423
+ };
4424
+ return { ...commands2, [command.name]: item };
4425
+ }, {});
4426
+ return { commands };
4427
+ }
4428
+ }
4232
4429
  get() {
4233
4430
  return this.build();
4234
4431
  }
@@ -4258,7 +4455,7 @@ var ManifestV2_default = class extends ManifestBase_default {
4258
4455
  }
4259
4456
  buildContentScripts() {
4260
4457
  if (this.contentScripts.size > 0) {
4261
- const contentScripts = Array.from(this.contentScripts, ([_4, contentScript]) => ({
4458
+ const contentScripts = Array.from(this.contentScripts, ([_5, contentScript]) => ({
4262
4459
  matches: contentScript.matches,
4263
4460
  exclude_matches: contentScript.excludeMatches,
4264
4461
  all_frames: contentScript.allFrames,
@@ -4298,7 +4495,7 @@ var ManifestV3_default = class extends ManifestBase_default {
4298
4495
  }
4299
4496
  buildContentScripts() {
4300
4497
  if (this.contentScripts.size > 0) {
4301
- const contentScripts = Array.from(this.contentScripts, ([_4, contentScript]) => ({
4498
+ const contentScripts = Array.from(this.contentScripts, ([_5, contentScript]) => ({
4302
4499
  matches: contentScript.matches,
4303
4500
  exclude_matches: contentScript.excludeMatches,
4304
4501
  all_frames: contentScript.allFrames,
@@ -4380,57 +4577,38 @@ var ManifestPlugin_default = ManifestPlugin;
4380
4577
 
4381
4578
  // src/cli/webpack/plugins/WatchPlugin.ts
4382
4579
  var WatchPlugin = class {
4383
- key;
4384
- entry;
4385
- callback;
4386
- constructor({ key: key2, entry = {}, callback }) {
4387
- this.entry = entry;
4580
+ constructor(callback, key2) {
4388
4581
  this.callback = callback;
4389
- this.key = "watch-plugin:" + (key2 || Object.keys(this.entry).join(","));
4582
+ this.key = key2;
4390
4583
  }
4391
4584
  apply(compiler) {
4392
4585
  compiler.hooks.watchRun.tapAsync("WatchPlugin", async (compiler2, callback) => {
4393
4586
  try {
4394
4587
  const { modifiedFiles = /* @__PURE__ */ new Set() } = compiler2;
4395
- const has = this.files.size === 0 || Array.from(modifiedFiles).some((file) => this.files.has(file));
4396
- if (has) {
4397
- const entry = await this.callback(modifiedFiles);
4398
- if (entry) {
4399
- for (const name2 in this.entry) {
4400
- delete compiler2.options.entry[name2];
4401
- }
4402
- for (const name2 in entry) {
4403
- compiler2.options.entry[name2] = entry[name2];
4404
- }
4405
- this.entry = entry;
4406
- }
4407
- }
4588
+ await this.callback(modifiedFiles);
4408
4589
  callback();
4409
4590
  } catch (e) {
4410
4591
  callback(e);
4411
4592
  }
4412
4593
  });
4413
4594
  }
4414
- get files() {
4415
- return new Set(Object.values(this.entry).flatMap((value) => Array.isArray(value) ? value : [value]));
4416
- }
4417
4595
  };
4418
4596
  var WatchPlugin_default = WatchPlugin;
4419
4597
 
4420
- // src/cli/webpack/merge.ts
4598
+ // src/cli/webpack/utils/mergeConfig.ts
4421
4599
  var import_webpack_merge = __toESM(require_dist());
4422
- var merge_default = (0, import_webpack_merge.mergeWithCustomize)({
4600
+ var mergeConfig_default = (0, import_webpack_merge.mergeWithCustomize)({
4423
4601
  customizeArray: (a, b, key2) => {
4424
4602
  if (key2 === "plugins") {
4425
4603
  const names = /* @__PURE__ */ new Set();
4426
4604
  return [...a, ...b].filter((plugin) => {
4427
4605
  var _a;
4428
- let name2 = (_a = plugin == null ? void 0 : plugin.constructor) == null ? void 0 : _a.name;
4429
- if (plugin instanceof WatchPlugin_default) {
4430
- name2 = plugin.key;
4606
+ let name3 = (_a = plugin == null ? void 0 : plugin.constructor) == null ? void 0 : _a.name;
4607
+ if (plugin instanceof WatchPlugin_default || plugin instanceof EntrypointPlugin_default) {
4608
+ name3 = plugin.key;
4431
4609
  }
4432
- if (names.has(name2)) return false;
4433
- names.add(name2);
4610
+ if (names.has(name3)) return false;
4611
+ names.add(name3);
4434
4612
  return true;
4435
4613
  });
4436
4614
  }
@@ -4438,9 +4616,9 @@ var merge_default = (0, import_webpack_merge.mergeWithCustomize)({
4438
4616
  const names = /* @__PURE__ */ new Set();
4439
4617
  return [...a, ...b].filter((plugin) => {
4440
4618
  var _a;
4441
- const name2 = (_a = plugin == null ? void 0 : plugin.constructor) == null ? void 0 : _a.name;
4442
- if (names.has(name2)) return false;
4443
- names.add(name2);
4619
+ const name3 = (_a = plugin == null ? void 0 : plugin.constructor) == null ? void 0 : _a.name;
4620
+ if (names.has(name3)) return false;
4621
+ names.add(name3);
4444
4622
  return true;
4445
4623
  });
4446
4624
  }
@@ -4462,7 +4640,7 @@ var merge_default = (0, import_webpack_merge.mergeWithCustomize)({
4462
4640
  var getConfigFromPlugins = async (webpack4, config) => {
4463
4641
  let mergedConfig = {};
4464
4642
  for await (const { result: pluginConfig } of processPluginHandler(config, "webpack", { webpack: webpack4, config })) {
4465
- mergedConfig = merge_default(mergedConfig, pluginConfig);
4643
+ mergedConfig = mergeConfig_default(mergedConfig, pluginConfig);
4466
4644
  }
4467
4645
  return mergedConfig;
4468
4646
  };
@@ -4471,19 +4649,17 @@ var getConfigForManifest = async (config) => {
4471
4649
  const update = async () => await Array.fromAsync(processPluginHandler(config, "manifest", { manifest, config }));
4472
4650
  await update();
4473
4651
  const plugins = [];
4474
- if (config.mode === "development" /* Development */) {
4475
- plugins.push(new WatchPlugin_default({
4476
- key: "manifest",
4477
- callback: async () => {
4478
- await update();
4479
- }
4480
- }));
4652
+ if (config.command === "watch" /* Watch */) {
4653
+ plugins.push(new WatchPlugin_default(async () => {
4654
+ await update();
4655
+ }, "manifest"));
4481
4656
  }
4482
4657
  plugins.push(new ManifestPlugin_default(manifest));
4483
4658
  return { plugins };
4484
4659
  };
4485
- var webpack_default = async (command, config) => {
4660
+ var webpack_default = async (config) => {
4486
4661
  let webpack4 = {
4662
+ entry: {},
4487
4663
  mode: config.mode,
4488
4664
  cache: false,
4489
4665
  output: {
@@ -4528,25 +4704,32 @@ var webpack_default = async (command, config) => {
4528
4704
  ]
4529
4705
  }
4530
4706
  };
4531
- webpack4 = merge_default(
4707
+ webpack4 = mergeConfig_default(
4532
4708
  webpack4,
4533
4709
  await getConfigFromPlugins(webpack4, config),
4534
4710
  await getConfigForManifest(config)
4535
4711
  );
4536
- if (command == "watch" /* Watch */) {
4537
- webpack4 = merge_default(webpack4, {
4712
+ if (config.command == "watch" /* Watch */) {
4713
+ webpack4 = mergeConfig_default(webpack4, {
4538
4714
  devtool: "inline-source-map"
4539
4715
  });
4540
4716
  }
4717
+ if (config.command == "build" /* Build */) {
4718
+ webpack4 = mergeConfig_default(webpack4, {
4719
+ plugins: [
4720
+ new cleanWebpackPlugin.CleanWebpackPlugin()
4721
+ ]
4722
+ });
4723
+ }
4541
4724
  return webpack4;
4542
4725
  };
4543
4726
 
4544
4727
  // src/cli/builders/app/index.ts
4545
- var app_default = async (command, config) => {
4728
+ var app_default = async (config) => {
4546
4729
  const resolverConfig = await config_default(config);
4547
- const webpackConfig = await webpack_default(command, resolverConfig);
4730
+ const webpackConfig = await webpack_default(resolverConfig);
4548
4731
  const compiler = webpack__default.default(webpackConfig);
4549
- switch (command) {
4732
+ switch (resolverConfig.command) {
4550
4733
  case "build" /* Build */:
4551
4734
  build(compiler);
4552
4735
  break;
@@ -4560,7 +4743,7 @@ var app_default = async (command, config) => {
4560
4743
  };
4561
4744
 
4562
4745
  // package.json
4563
- var version = "0.0.20";
4746
+ var version = "0.0.22";
4564
4747
 
4565
4748
  // src/cli/index.ts
4566
4749
  var cli = cac__default.default("adnbn");
@@ -4569,7 +4752,8 @@ cli.command("init", "Initialize a new project").action(() => {
4569
4752
  console.log("init is good in cli");
4570
4753
  });
4571
4754
  cli.command("watch [root]", "Start watch mode").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("--mv2", "Target manifest v2").action(async (root2, options) => {
4572
- await app_default("watch" /* Watch */, {
4755
+ await app_default({
4756
+ command: "watch" /* Watch */,
4573
4757
  mode: options.mode,
4574
4758
  debug: options.debug,
4575
4759
  app: options.app,
@@ -4580,7 +4764,8 @@ cli.command("watch [root]", "Start watch mode").option("-m, --mode <mode>", "Set
4580
4764
  });
4581
4765
  });
4582
4766
  cli.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: "chrome" /* Chrome */ }).option("--mv2", "Target manifest v2").option("--analyze", "Visualize extension bundle").action(async (root2, options) => {
4583
- await app_default("build" /* Build */, {
4767
+ await app_default({
4768
+ command: "build" /* Build */,
4584
4769
  mode: options.mode,
4585
4770
  debug: options.debug,
4586
4771
  app: options.app,