adnbn 0.0.15 → 0.0.16

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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  var cac = require('cac');
4
4
  var webpack = require('webpack');
5
- var path = require('path');
5
+ var path2 = require('path');
6
6
  var fs = require('fs');
7
7
  var c12 = require('c12');
8
8
  var VirtualModulesPlugin = require('webpack-virtual-modules');
@@ -15,7 +15,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
15
15
 
16
16
  var cac__default = /*#__PURE__*/_interopDefault(cac);
17
17
  var webpack__default = /*#__PURE__*/_interopDefault(webpack);
18
- var path__default = /*#__PURE__*/_interopDefault(path);
18
+ var path2__default = /*#__PURE__*/_interopDefault(path2);
19
19
  var VirtualModulesPlugin__default = /*#__PURE__*/_interopDefault(VirtualModulesPlugin);
20
20
  var ___default = /*#__PURE__*/_interopDefault(_);
21
21
  var TsconfigPathsPlugin__default = /*#__PURE__*/_interopDefault(TsconfigPathsPlugin);
@@ -124,7 +124,7 @@ var require_package = __commonJS({
124
124
  var require_main = __commonJS({
125
125
  "node_modules/dotenv/lib/main.js"(exports, module) {
126
126
  var fs = __require("fs");
127
- var path7 = __require("path");
127
+ var path6 = __require("path");
128
128
  var os = __require("os");
129
129
  var crypto = __require("crypto");
130
130
  var packageJson = require_package();
@@ -238,7 +238,7 @@ var require_main = __commonJS({
238
238
  possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
239
239
  }
240
240
  } else {
241
- possibleVaultPath = path7.resolve(process.cwd(), ".env.vault");
241
+ possibleVaultPath = path6.resolve(process.cwd(), ".env.vault");
242
242
  }
243
243
  if (fs.existsSync(possibleVaultPath)) {
244
244
  return possibleVaultPath;
@@ -246,7 +246,7 @@ var require_main = __commonJS({
246
246
  return null;
247
247
  }
248
248
  function _resolveHome(envPath) {
249
- return envPath[0] === "~" ? path7.join(os.homedir(), envPath.slice(1)) : envPath;
249
+ return envPath[0] === "~" ? path6.join(os.homedir(), envPath.slice(1)) : envPath;
250
250
  }
251
251
  function _configVault(options) {
252
252
  _log("Loading env from encrypted .env.vault");
@@ -259,7 +259,7 @@ var require_main = __commonJS({
259
259
  return { parsed };
260
260
  }
261
261
  function configDotenv(options) {
262
- const dotenvPath = path7.resolve(process.cwd(), ".env");
262
+ const dotenvPath = path6.resolve(process.cwd(), ".env");
263
263
  let encoding = "utf8";
264
264
  const debug = Boolean(options && options.debug);
265
265
  if (options && options.encoding) {
@@ -282,13 +282,13 @@ var require_main = __commonJS({
282
282
  }
283
283
  let lastError;
284
284
  const parsedAll = {};
285
- for (const path8 of optionPaths) {
285
+ for (const path7 of optionPaths) {
286
286
  try {
287
- const parsed = DotenvModule.parse(fs.readFileSync(path8, { encoding }));
287
+ const parsed = DotenvModule.parse(fs.readFileSync(path7, { encoding }));
288
288
  DotenvModule.populate(parsedAll, parsed, options);
289
289
  } catch (e) {
290
290
  if (debug) {
291
- _debug(`Failed to load ${path8} ${e.message}`);
291
+ _debug(`Failed to load ${path7} ${e.message}`);
292
292
  }
293
293
  lastError = e;
294
294
  }
@@ -1364,6 +1364,55 @@ var require_dist = __commonJS({
1364
1364
  }
1365
1365
  });
1366
1366
 
1367
+ // src/cli/builders/app/command.ts
1368
+ var build = (compiler) => {
1369
+ compiler.run((err, stats) => {
1370
+ if (err) {
1371
+ console.error("Webpack compilation error:", err);
1372
+ process.exit(1);
1373
+ }
1374
+ if (stats == null ? void 0 : stats.hasErrors()) {
1375
+ console.error(stats.toString({
1376
+ colors: true,
1377
+ errors: true
1378
+ }));
1379
+ process.exit(1);
1380
+ }
1381
+ console.log(stats == null ? void 0 : stats.toString({ colors: true }));
1382
+ compiler.close((closeErr) => {
1383
+ if (closeErr) {
1384
+ console.error("Webpack close error:", closeErr);
1385
+ process.exit(1);
1386
+ }
1387
+ });
1388
+ });
1389
+ };
1390
+ var watch = (compiler) => {
1391
+ const watching = compiler.watch({
1392
+ aggregateTimeout: 300,
1393
+ ignored: /node_modules/
1394
+ }, (err, stats) => {
1395
+ if (err) {
1396
+ console.error("Webpack watch error:", err);
1397
+ process.exit(1);
1398
+ }
1399
+ if (stats == null ? void 0 : stats.hasErrors()) {
1400
+ console.error(stats.toString({
1401
+ colors: true,
1402
+ errors: true
1403
+ }));
1404
+ return;
1405
+ }
1406
+ console.log(stats == null ? void 0 : stats.toString({ colors: true }));
1407
+ });
1408
+ process.on("SIGINT", () => {
1409
+ watching.close(() => {
1410
+ console.log("Webpack watch mode stopped");
1411
+ process.exit(0);
1412
+ });
1413
+ });
1414
+ };
1415
+
1367
1416
  // src/cli/resolvers/config.ts
1368
1417
  var import_dotenv = __toESM(require_main());
1369
1418
 
@@ -1385,51 +1434,86 @@ var dotenv_default = definePlugin((options) => {
1385
1434
  }
1386
1435
  };
1387
1436
  });
1388
- var getRootPath = (to) => {
1389
- return path__default.default.resolve(process.cwd(), to);
1390
- };
1391
- var getConfigFile = (config) => {
1392
- return path__default.default.resolve(config.inputDir, config.configFile);
1393
- };
1394
- var getSharedPath = (config) => {
1395
- return path__default.default.resolve(config.inputDir, config.srcDir, config.sharedDir);
1396
- };
1397
- var getAppsPath = (config) => {
1398
- return path__default.default.resolve(config.inputDir, config.srcDir, config.appsDir, config.app);
1437
+
1438
+ // src/cli/webpack/plugins/WatchPlugin.ts
1439
+ var WatchPlugin = class {
1440
+ key;
1441
+ entry;
1442
+ callback;
1443
+ constructor({ key, entry = {}, callback }) {
1444
+ this.entry = entry;
1445
+ this.callback = callback;
1446
+ this.key = "watch-plugin:" + (key || Object.keys(this.entry).join(","));
1447
+ }
1448
+ apply(compiler) {
1449
+ compiler.hooks.watchRun.tapAsync("WatchPlugin", async (compiler2, callback) => {
1450
+ try {
1451
+ const { modifiedFiles = /* @__PURE__ */ new Set() } = compiler2;
1452
+ const has = this.files.size === 0 || Array.from(modifiedFiles).some((file) => this.files.has(file));
1453
+ if (has) {
1454
+ const entry = await this.callback(modifiedFiles);
1455
+ if (entry) {
1456
+ for (const name in this.entry) {
1457
+ delete compiler2.options.entry[name];
1458
+ }
1459
+ for (const name in entry) {
1460
+ compiler2.options.entry[name] = entry[name];
1461
+ }
1462
+ this.entry = entry;
1463
+ }
1464
+ }
1465
+ callback();
1466
+ } catch (e) {
1467
+ callback(e);
1468
+ }
1469
+ });
1470
+ }
1471
+ get files() {
1472
+ return new Set(Object.values(this.entry).flatMap((value) => Array.isArray(value) ? value : [value]));
1473
+ }
1399
1474
  };
1475
+ var WatchPlugin_default = WatchPlugin;
1400
1476
 
1401
- // src/cli/plugins/content.ts
1402
- var content_default = definePlugin(() => {
1403
- const contentScripts = [];
1404
- return {
1405
- webpack: async ({ config }) => {
1406
- const p = path__default.default.resolve(getAppsPath(config), "src/some.ts");
1407
- return {
1408
- entry: {
1409
- some: p
1410
- },
1411
- plugins: [
1412
- new VirtualModulesPlugin__default.default({
1413
- [p]: 'console.log("Hello, World!")'
1414
- })
1415
- ]
1416
- };
1417
- },
1418
- manifest: ({ manifest }) => {
1419
- manifest.pushContentScript(...contentScripts);
1477
+ // src/cli/webpack/merge.ts
1478
+ var import_webpack_merge = __toESM(require_dist());
1479
+ var merge_default = (0, import_webpack_merge.mergeWithCustomize)({
1480
+ customizeArray: (a, b, key) => {
1481
+ if (key === "plugins") {
1482
+ const names = /* @__PURE__ */ new Set();
1483
+ return [...a, ...b].filter((plugin) => {
1484
+ var _a;
1485
+ let name = (_a = plugin == null ? void 0 : plugin.constructor) == null ? void 0 : _a.name;
1486
+ if (plugin instanceof WatchPlugin_default) {
1487
+ name = plugin.key;
1488
+ }
1489
+ if (names.has(name)) return false;
1490
+ names.add(name);
1491
+ return true;
1492
+ });
1420
1493
  }
1421
- };
1422
- });
1423
-
1424
- // src/cli/utils/option.ts
1425
- var isValidEntrypointOptions = (options, config) => {
1426
- var _a, _b, _c, _d;
1427
- const { browser, app } = config;
1428
- if (((_a = options.includeBrowser) == null ? void 0 : _a.includes(browser)) || ((_b = options.includeApp) == null ? void 0 : _b.includes(app))) {
1429
- return true;
1494
+ if (key === "resolve.plugins") {
1495
+ const names = /* @__PURE__ */ new Set();
1496
+ return [...a, ...b].filter((plugin) => {
1497
+ var _a;
1498
+ const name = (_a = plugin == null ? void 0 : plugin.constructor) == null ? void 0 : _a.name;
1499
+ if (names.has(name)) return false;
1500
+ names.add(name);
1501
+ return true;
1502
+ });
1503
+ }
1504
+ if (key === "module.rules") {
1505
+ const tests = /* @__PURE__ */ new Set();
1506
+ return [...a, ...b].filter((rule) => {
1507
+ var _a;
1508
+ const test = (_a = rule == null ? void 0 : rule.test) == null ? void 0 : _a.toString();
1509
+ if (tests.has(test)) return false;
1510
+ tests.add(test);
1511
+ return true;
1512
+ });
1513
+ }
1514
+ return void 0;
1430
1515
  }
1431
- return !(((_c = options.excludeBrowser) == null ? void 0 : _c.includes(browser)) || ((_d = options.excludeApp) == null ? void 0 : _d.includes(app)));
1432
- };
1516
+ });
1433
1517
  var EntryFile = class _EntryFile {
1434
1518
  constructor(file) {
1435
1519
  this.file = file;
@@ -1464,7 +1548,7 @@ var EntryFile = class _EntryFile {
1464
1548
  if (node.importClause && node.importClause.namedBindings && typescript.isNamedImports(node.importClause.namedBindings)) {
1465
1549
  node.importClause.namedBindings.elements.forEach((el) => {
1466
1550
  var _a;
1467
- (_a = this.imports) == null ? void 0 : _a.set(el.name.text, path__default.default.resolve(path__default.default.dirname(this.file), importPath + ".ts"));
1551
+ (_a = this.imports) == null ? void 0 : _a.set(el.name.text, path2__default.default.resolve(path2__default.default.dirname(this.file), importPath + ".ts"));
1468
1552
  });
1469
1553
  }
1470
1554
  }
@@ -1665,6 +1749,21 @@ var commonProperties = [
1665
1749
  var getBackgroundOptions = (file) => {
1666
1750
  return OptionFile_default.make(file).setDefinition("defineBackground").setProperties([...commonProperties, "persistent"]).getOptions();
1667
1751
  };
1752
+ var getRootPath = (to) => {
1753
+ return path2__default.default.resolve(process.cwd(), to);
1754
+ };
1755
+ var getConfigFile = (config) => {
1756
+ return path2__default.default.resolve(config.inputDir, config.configFile);
1757
+ };
1758
+ var getSharedPath = (config) => {
1759
+ return path2__default.default.resolve(config.inputDir, config.srcDir, config.sharedDir);
1760
+ };
1761
+ var getAppsPath = (config) => {
1762
+ return path2__default.default.resolve(config.inputDir, config.srcDir, config.appsDir, config.app);
1763
+ };
1764
+ var getOutputPath = (config) => {
1765
+ return path2__default.default.resolve(config.outputDir, `${config.app}-${config.browser}-mv${config.manifestVersion}`);
1766
+ };
1668
1767
  var escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1669
1768
  var findEntrypointFiles = (directory, entrypoint) => {
1670
1769
  const files = [];
@@ -1680,12 +1779,12 @@ var findEntrypointFiles = (directory, entrypoint) => {
1680
1779
  return;
1681
1780
  }
1682
1781
  for (const entry of entries) {
1683
- const fullPath = path__default.default.join(dir, entry.name);
1782
+ const fullPath = path2__default.default.join(dir, entry.name);
1684
1783
  if (entry.isDirectory()) {
1685
1784
  if (entry.name === entrypoint || entry.name.endsWith(`.${entrypoint}`)) {
1686
1785
  const possibleIndexFiles = ["index.ts", "index.tsx", "index.js"];
1687
1786
  for (const indexFile of possibleIndexFiles) {
1688
- const indexPath = path__default.default.join(fullPath, indexFile);
1787
+ const indexPath = path2__default.default.join(fullPath, indexFile);
1689
1788
  try {
1690
1789
  const stat = fs.statSync(indexPath);
1691
1790
  if (stat.isFile()) {
@@ -1730,6 +1829,16 @@ var processPluginHandler = async function* (config, key, options) {
1730
1829
  }
1731
1830
  };
1732
1831
 
1832
+ // src/cli/utils/option.ts
1833
+ var isValidEntrypointOptions = (options, config) => {
1834
+ var _a, _b, _c, _d;
1835
+ const { browser, app } = config;
1836
+ if (((_a = options.includeBrowser) == null ? void 0 : _a.includes(browser)) || ((_b = options.includeApp) == null ? void 0 : _b.includes(app))) {
1837
+ return true;
1838
+ }
1839
+ return !(((_c = options.excludeBrowser) == null ? void 0 : _c.includes(browser)) || ((_d = options.excludeApp) == null ? void 0 : _d.includes(app)));
1840
+ };
1841
+
1733
1842
  // src/cli/plugins/background/background.ts
1734
1843
  var backgroundFilesToEntries = (files) => {
1735
1844
  const entries = /* @__PURE__ */ new Map();
@@ -1772,16 +1881,63 @@ var getBackgroundEntries = async (config) => {
1772
1881
  }
1773
1882
  return entries;
1774
1883
  };
1884
+ var background_default = async (config) => {
1885
+ const entries = Array.from(await getBackgroundEntries(config)).filter(([_3, options]) => isValidEntrypointOptions(options, config));
1886
+ const files = entries.map(([file]) => file);
1887
+ const persistent = entries.some(([_3, { persistent: persistent2 }]) => persistent2);
1888
+ return { files, persistent };
1889
+ };
1890
+
1891
+ // raw-loader:./background.ts?raw
1892
+ var background_default2 = `//@ts-nocheck
1893
+ import {BackgroundDefinition} from "adnbn";
1894
+
1895
+ import * as module from "virtual:background-entrypoint";
1896
+
1897
+ import _isFunction from "lodash/isFunction";
1898
+ import _isPlainObject from "lodash/isPlainObject";
1899
+
1900
+ try {
1901
+ const {default: defaultDefinition, ...otherDefinition} = module;
1902
+
1903
+ let definition: BackgroundDefinition = otherDefinition;
1904
+
1905
+ if (_isPlainObject(defaultDefinition)) {
1906
+ definition = {...definition, ...defaultDefinition};
1907
+ } else if (_isFunction(defaultDefinition)) {
1908
+ definition = {...definition, main: defaultDefinition};
1909
+ }
1910
+
1911
+ const {main, ...options} = definition;
1912
+
1913
+ if (_isFunction(main)) {
1914
+ Promise.resolve(main(options)).catch((e) => {
1915
+ console.error('The background main function crashed:', e);
1916
+ });
1917
+ }
1918
+ } catch (e) {
1919
+ console.error('The background crashed on startup:', e);
1920
+ }
1921
+ `;
1922
+
1923
+ // src/cli/virtual/index.ts
1924
+ console.log(background_default2);
1925
+ var getVirtualModule = (file, template) => {
1926
+ return background_default2.replace(`virtual:${template}-entrypoint`, file.replace(".ts", ""));
1927
+ };
1928
+ var virtualBackgroundModule = (file) => {
1929
+ return getVirtualModule(file, "background");
1930
+ };
1775
1931
 
1776
1932
  // src/cli/plugins/background/index.ts
1777
- var background_default = definePlugin((options) => {
1933
+ var background_default3 = definePlugin((options) => {
1778
1934
  const { name = "background" } = options || {};
1779
1935
  let hasBackground = false;
1780
1936
  let persistent;
1781
1937
  return {
1782
1938
  webpack: async ({ config, webpack: webpack4 }) => {
1783
- const backgroundEntries = Array.from(await getBackgroundEntries(config)).filter(([_3, options2]) => isValidEntrypointOptions(options2, config));
1784
- const files = backgroundEntries.map(([file]) => file);
1939
+ const { files: backgroundFiles, persistent: backgroundPersistent } = await background_default(config);
1940
+ const files = backgroundFiles;
1785
1941
  if (files.length === 0) {
1786
1942
  if (config.debug) {
1787
1943
  console.warn("Background entries not found");
@@ -1789,16 +1945,14 @@ var background_default = definePlugin((options) => {
1789
1945
  return {};
1790
1946
  }
1791
1947
  hasBackground = true;
1792
- if (backgroundEntries.some(([_3, { persistent: isPersistent }]) => isPersistent)) {
1793
- persistent = true;
1794
- }
1795
- if (config.debug) {
1796
- console.info("Background entries:", new Map(backgroundEntries));
1797
- }
1798
- return {
1799
- entry: {
1800
- [name]: files
1801
- },
1948
+ persistent = backgroundPersistent;
1949
+ const m = files.reduce((m2, file) => ({ ...m2, ["virtual" + file]: virtualBackgroundModule(file) }), {});
1950
+ console.log("m", m);
1951
+ const virtualModules = new VirtualModulesPlugin__default.default(m);
1952
+ const entry = { [name]: Object.keys(m) };
1953
+ let resolvedWebpack = {
1954
+ entry,
1955
+ plugins: [virtualModules],
1802
1956
  optimization: {
1803
1957
  splitChunks: {
1804
1958
  chunks(chunk) {
@@ -1812,6 +1966,28 @@ var background_default = definePlugin((options) => {
1812
1966
  }
1813
1967
  }
1814
1968
  };
1969
+ if (config.mode === "development" /* Development */) {
1970
+ resolvedWebpack = merge_default(resolvedWebpack, {
1971
+ plugins: [
1972
+ new WatchPlugin_default({
1973
+ key: name,
1974
+ entry,
1975
+ callback: async () => {
1976
+ const {
1977
+ files: backgroundFiles2,
1978
+ persistent: backgroundPersistent2
1979
+ } = await background_default(config);
1980
+ persistent = backgroundPersistent2;
1981
+ for (const file of files) {
1982
+ virtualModules.writeModule(file, `console.log("${file}")`);
1983
+ }
1984
+ return { [name]: backgroundFiles2 };
1985
+ }
1986
+ })
1987
+ ]
1988
+ });
1989
+ }
1990
+ return resolvedWebpack;
1815
1991
  },
1816
1992
  manifest: ({ manifest }) => {
1817
1993
  if (hasBackground) {
@@ -1868,7 +2044,7 @@ var loadDotenv = (config) => {
1868
2044
  `.env.${mode}`,
1869
2045
  `.env.local`,
1870
2046
  `.env`
1871
- ].map((file) => path__default.default.join(getRootPath(config.inputDir), file));
2047
+ ].map((file) => path2__default.default.join(getRootPath(config.inputDir), file));
1872
2048
  const { parsed: fileVars = {} } = import_dotenv.default.config({ path: paths });
1873
2049
  return { ...fileVars, ...updateLocalDotenv(config) };
1874
2050
  };
@@ -1923,8 +2099,8 @@ var config_default = async (config) => {
1923
2099
  vars = { ...vars, ...loadDotenv(resolvedConfig) };
1924
2100
  const corePlugins = [
1925
2101
  dotenv_default({ vars }),
1926
- content_default(),
1927
- background_default()
2102
+ // contentPlugin(),
2103
+ background_default3()
1928
2104
  ];
1929
2105
  return {
1930
2106
  ...resolvedConfig,
@@ -2025,7 +2201,7 @@ var ManifestV2_default = class extends ManifestBase_default {
2025
2201
  throw new ManifestError(`Background entry "${entry}" has no dependencies`);
2026
2202
  }
2027
2203
  const scripts = Array.from(dependencies.js);
2028
- return { background: { scripts, persistent } };
2204
+ return { background: { scripts, persistent: persistent || void 0 } };
2029
2205
  }
2030
2206
  }
2031
2207
  buildContentScripts() {
@@ -2150,44 +2326,6 @@ var ManifestPlugin = class {
2150
2326
  };
2151
2327
  var ManifestPlugin_default = ManifestPlugin;
2152
2328
 
2153
- // src/cli/webpack/merge.ts
2154
- var import_webpack_merge = __toESM(require_dist());
2155
- var merge_default = (0, import_webpack_merge.mergeWithCustomize)({
2156
- customizeArray: (a, b, key) => {
2157
- if (key === "plugins") {
2158
- const names = /* @__PURE__ */ new Set();
2159
- return [...a, ...b].filter((plugin) => {
2160
- var _a;
2161
- const name = (_a = plugin == null ? void 0 : plugin.constructor) == null ? void 0 : _a.name;
2162
- if (names.has(name)) return false;
2163
- names.add(name);
2164
- return true;
2165
- });
2166
- }
2167
- if (key === "resolve.plugins") {
2168
- const names = /* @__PURE__ */ new Set();
2169
- return [...a, ...b].filter((plugin) => {
2170
- var _a;
2171
- const name = (_a = plugin == null ? void 0 : plugin.constructor) == null ? void 0 : _a.name;
2172
- if (names.has(name)) return false;
2173
- names.add(name);
2174
- return true;
2175
- });
2176
- }
2177
- if (key === "module.rules") {
2178
- const tests = /* @__PURE__ */ new Set();
2179
- return [...a, ...b].filter((rule) => {
2180
- var _a;
2181
- const test = (_a = rule == null ? void 0 : rule.test) == null ? void 0 : _a.toString();
2182
- if (tests.has(test)) return false;
2183
- tests.add(test);
2184
- return true;
2185
- });
2186
- }
2187
- return void 0;
2188
- }
2189
- });
2190
-
2191
2329
  // src/cli/resolvers/webpack.ts
2192
2330
  var getConfigFromPlugins = async (webpack4, config) => {
2193
2331
  let mergedConfig = {};
@@ -2196,21 +2334,30 @@ var getConfigFromPlugins = async (webpack4, config) => {
2196
2334
  }
2197
2335
  return mergedConfig;
2198
2336
  };
2199
- var getConfigForManifest = async (webpack4, config) => {
2337
+ var getConfigForManifest = async (config) => {
2200
2338
  const manifest = manifest_default(config.browser, config.manifestVersion);
2201
- await Array.fromAsync(processPluginHandler(config, "manifest", { manifest, config }));
2202
- return {
2203
- plugins: [new ManifestPlugin_default(manifest)]
2204
- };
2339
+ const update = async () => await Array.fromAsync(processPluginHandler(config, "manifest", { manifest, config }));
2340
+ await update();
2341
+ const plugins = [];
2342
+ if (config.mode === "development" /* Development */) {
2343
+ plugins.push(new WatchPlugin_default({
2344
+ key: "manifest",
2345
+ callback: async () => {
2346
+ await update();
2347
+ }
2348
+ }));
2349
+ }
2350
+ plugins.push(new ManifestPlugin_default(manifest));
2351
+ return { plugins };
2205
2352
  };
2206
- var webpack_default = async (config) => {
2353
+ var webpack_default = async (command, config) => {
2207
2354
  let webpack4 = {
2208
2355
  mode: config.mode,
2209
2356
  cache: false,
2210
2357
  output: {
2211
- path: getRootPath(path__default.default.join(config.outputDir, `${config.app}-${config.browser}-mv${config.manifestVersion}`)),
2212
- filename: path__default.default.join(config.jsDir, "[name].js"),
2213
- assetModuleFilename: path__default.default.join(config.assetsDir, "[name]-[hash:4][ext]")
2358
+ path: getRootPath(getOutputPath(config)),
2359
+ filename: path2__default.default.join(config.jsDir, "[name].js"),
2360
+ assetModuleFilename: path2__default.default.join(config.assetsDir, "[name]-[hash:4][ext]")
2214
2361
  },
2215
2362
  resolve: {
2216
2363
  extensions: [".ts", ".tsx", ".js", ".scss"],
@@ -2253,27 +2400,36 @@ var webpack_default = async (config) => {
2253
2400
  webpack4 = merge_default(
2254
2401
  webpack4,
2255
2402
  await getConfigFromPlugins(webpack4, config),
2256
- await getConfigForManifest(webpack4, config)
2403
+ await getConfigForManifest(config)
2257
2404
  );
2405
+ if (command == "watch" /* Watch */) {
2406
+ webpack4 = merge_default(webpack4, {
2407
+ devtool: "inline-source-map"
2408
+ });
2409
+ }
2258
2410
  return webpack4;
2259
2411
  };
2260
2412
 
2261
- // src/cli/builders/app.ts
2262
- var app_default = async (config) => {
2413
+ // src/cli/builders/app/index.ts
2414
+ var app_default = async (command, config) => {
2263
2415
  const resolverConfig = await config_default(config);
2264
- const webpackConfig = await webpack_default(resolverConfig);
2416
+ const webpackConfig = await webpack_default(command, resolverConfig);
2265
2417
  const compiler = webpack__default.default(webpackConfig);
2266
- compiler.run((err, stats) => {
2267
- if (err) {
2268
- console.error("Webpack compilation error");
2418
+ switch (command) {
2419
+ case "build" /* Build */:
2420
+ build(compiler);
2421
+ break;
2422
+ case "watch" /* Watch */:
2423
+ watch(compiler);
2424
+ break;
2425
+ default:
2426
+ console.error("Unknown command");
2269
2427
  process.exit(1);
2270
- }
2271
- console.log(stats == null ? void 0 : stats.toString({ colors: true }));
2272
- });
2428
+ }
2273
2429
  };
2274
2430
 
2275
2431
  // package.json
2276
- var version = "0.0.14";
2432
+ var version = "0.0.15";
2277
2433
 
2278
2434
  // src/cli/index.ts
2279
2435
  var cli = cac__default.default("adnbn");
@@ -2281,18 +2437,27 @@ cli.option("--debug", "Enable debug mode");
2281
2437
  cli.command("init", "Initialize a new project").action(() => {
2282
2438
  console.log("init is good in cli");
2283
2439
  });
2284
- cli.command("dev [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((root, options) => {
2285
- console.log(options);
2440
+ 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 (root, options) => {
2441
+ await app_default("watch" /* Watch */, {
2442
+ mode: options.mode,
2443
+ debug: options.debug,
2444
+ app: options.app,
2445
+ browser: options.browser,
2446
+ manifestVersion: options.mv2 ? 2 : 3,
2447
+ inputDir: root,
2448
+ configFile: options.config
2449
+ });
2286
2450
  });
2287
2451
  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 (root, options) => {
2288
- await app_default({
2452
+ await app_default("build" /* Build */, {
2289
2453
  mode: options.mode,
2290
2454
  debug: options.debug,
2291
2455
  app: options.app,
2292
2456
  browser: options.browser,
2293
2457
  manifestVersion: options.mv2 ? 2 : 3,
2294
2458
  inputDir: root,
2295
- configFile: options.config
2459
+ configFile: options.config,
2460
+ analyze: options.analyze
2296
2461
  });
2297
2462
  });
2298
2463
  cli.version(version);