adnbn 0.0.15 → 0.0.17

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);
@@ -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.join(config.inputDir, config.configFile);
1757
+ };
1758
+ var getSharedPath = (config) => {
1759
+ return path2__default.default.join(config.inputDir, config.srcDir, config.sharedDir);
1760
+ };
1761
+ var getAppsPath = (config) => {
1762
+ return path2__default.default.join(config.inputDir, config.srcDir, config.appsDir, config.app);
1763
+ };
1764
+ var getOutputPath = (config) => {
1765
+ return path2__default.default.join(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()) {
@@ -1725,11 +1824,21 @@ var processPluginHandler = async function* (config, key, options) {
1725
1824
  const handler = plugin[key];
1726
1825
  const result = await resolvePluginHandler(handler, options);
1727
1826
  if (result !== void 0) {
1728
- yield result;
1827
+ yield { name: plugin.name, result };
1729
1828
  }
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();
@@ -1759,11 +1868,17 @@ var getBackgroundEntries = async (config) => {
1759
1868
  }
1760
1869
  }
1761
1870
  }
1762
- const pluginBackgroundFiles = await Array.fromAsync(processPluginHandler(config, "background", {
1871
+ const pluginBackgroundResult = await Array.fromAsync(processPluginHandler(config, "background", {
1763
1872
  config,
1764
1873
  entries
1765
1874
  }));
1766
- if (pluginBackgroundFiles.length > 0) {
1875
+ if (pluginBackgroundResult.length > 0) {
1876
+ const pluginBackgroundFiles = pluginBackgroundResult.map(({ name, result: endpoint }) => {
1877
+ if (___default.default.isBoolean(endpoint)) {
1878
+ endpoint = "background";
1879
+ }
1880
+ return `${name}/${endpoint}`;
1881
+ });
1767
1882
  const pluginBackgroundEntries = backgroundFilesToEntries(pluginBackgroundFiles);
1768
1883
  entries = new Map([...entries, ...pluginBackgroundEntries]);
1769
1884
  if (config.debug) {
@@ -1772,16 +1887,61 @@ var getBackgroundEntries = async (config) => {
1772
1887
  }
1773
1888
  return entries;
1774
1889
  };
1890
+ var background_default = async (config) => {
1891
+ const entries = Array.from(await getBackgroundEntries(config)).filter(([_4, options]) => isValidEntrypointOptions(options, config));
1892
+ const files = entries.map(([file]) => file);
1893
+ const persistent = entries.some(([_4, { persistent: persistent2 }]) => persistent2);
1894
+ return { files, persistent };
1895
+ };
1896
+
1897
+ // raw-loader:./background.ts?raw
1898
+ var background_default2 = `import {BackgroundDefinition} from "adnbn";
1899
+
1900
+ import * as module from "virtual:background-entrypoint";
1901
+
1902
+ import _isFunction from "lodash/isFunction";
1903
+ import _isPlainObject from "lodash/isPlainObject";
1904
+
1905
+ try {
1906
+ const {default: defaultDefinition, ...otherDefinition} = module;
1907
+
1908
+ let definition: BackgroundDefinition = otherDefinition;
1909
+
1910
+ if (_isPlainObject(defaultDefinition)) {
1911
+ definition = {...definition, ...defaultDefinition};
1912
+ } else if (_isFunction(defaultDefinition)) {
1913
+ definition = {...definition, main: defaultDefinition};
1914
+ }
1915
+
1916
+ const {main, ...options} = definition;
1775
1917
 
1776
- // src/cli/plugins/background/index.ts
1777
- var background_default = definePlugin((options) => {
1918
+ if (_isFunction(main)) {
1919
+ Promise.resolve(main(options)).catch((e) => {
1920
+ console.error('The background main function crashed:', e);
1921
+ });
1922
+ }
1923
+ } catch (e) {
1924
+ console.error('The background crashed on startup:', e);
1925
+ }
1926
+ `;
1927
+
1928
+ // src/cli/virtual/index.ts
1929
+ console.log(background_default2);
1930
+ var getVirtualModule = (file, template) => {
1931
+ return background_default2.replace(`virtual:${template}-entrypoint`, file.replace(".ts", ""));
1932
+ };
1933
+ var virtualBackgroundModule = (file) => {
1934
+ return getVirtualModule(file, "background");
1935
+ };
1936
+ var background_default3 = definePlugin((options) => {
1778
1937
  const { name = "background" } = options || {};
1779
1938
  let hasBackground = false;
1780
1939
  let persistent;
1781
1940
  return {
1941
+ name: undefined,
1782
1942
  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);
1943
+ const { files: backgroundFiles, persistent: backgroundPersistent } = await background_default(config);
1944
+ const files = backgroundFiles;
1785
1945
  if (files.length === 0) {
1786
1946
  if (config.debug) {
1787
1947
  console.warn("Background entries not found");
@@ -1789,16 +1949,14 @@ var background_default = definePlugin((options) => {
1789
1949
  return {};
1790
1950
  }
1791
1951
  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
- },
1952
+ persistent = backgroundPersistent;
1953
+ const m = files.reduce((m2, file) => ({ ...m2, [path2__default.default.join("virtual", file)]: virtualBackgroundModule(file) }), {});
1954
+ console.log("m", m);
1955
+ const virtualModules = new VirtualModulesPlugin__default.default(m);
1956
+ const entry = { [name]: Object.keys(m) };
1957
+ let resolvedWebpack = {
1958
+ entry,
1959
+ plugins: [virtualModules],
1802
1960
  optimization: {
1803
1961
  splitChunks: {
1804
1962
  chunks(chunk) {
@@ -1812,6 +1970,28 @@ var background_default = definePlugin((options) => {
1812
1970
  }
1813
1971
  }
1814
1972
  };
1973
+ if (config.mode === "development" /* Development */) {
1974
+ resolvedWebpack = merge_default(resolvedWebpack, {
1975
+ plugins: [
1976
+ new WatchPlugin_default({
1977
+ key: name,
1978
+ entry,
1979
+ callback: async () => {
1980
+ const {
1981
+ files: backgroundFiles2,
1982
+ persistent: backgroundPersistent2
1983
+ } = await background_default(config);
1984
+ persistent = backgroundPersistent2;
1985
+ for (const file of files) {
1986
+ virtualModules.writeModule(file, `console.log("${file}")`);
1987
+ }
1988
+ return { [name]: backgroundFiles2 };
1989
+ }
1990
+ })
1991
+ ]
1992
+ });
1993
+ }
1994
+ return resolvedWebpack;
1815
1995
  },
1816
1996
  manifest: ({ manifest }) => {
1817
1997
  if (hasBackground) {
@@ -1868,7 +2048,7 @@ var loadDotenv = (config) => {
1868
2048
  `.env.${mode}`,
1869
2049
  `.env.local`,
1870
2050
  `.env`
1871
- ].map((file) => path__default.default.join(getRootPath(config.inputDir), file));
2051
+ ].map((file) => path2__default.default.join(getRootPath(config.inputDir), file));
1872
2052
  const { parsed: fileVars = {} } = import_dotenv.default.config({ path: paths });
1873
2053
  return { ...fileVars, ...updateLocalDotenv(config) };
1874
2054
  };
@@ -1923,8 +2103,8 @@ var config_default = async (config) => {
1923
2103
  vars = { ...vars, ...loadDotenv(resolvedConfig) };
1924
2104
  const corePlugins = [
1925
2105
  dotenv_default({ vars }),
1926
- content_default(),
1927
- background_default()
2106
+ // contentPlugin(),
2107
+ background_default3()
1928
2108
  ];
1929
2109
  return {
1930
2110
  ...resolvedConfig,
@@ -2025,12 +2205,12 @@ var ManifestV2_default = class extends ManifestBase_default {
2025
2205
  throw new ManifestError(`Background entry "${entry}" has no dependencies`);
2026
2206
  }
2027
2207
  const scripts = Array.from(dependencies.js);
2028
- return { background: { scripts, persistent } };
2208
+ return { background: { scripts, persistent: persistent || void 0 } };
2029
2209
  }
2030
2210
  }
2031
2211
  buildContentScripts() {
2032
2212
  if (this.contentScripts.size > 0) {
2033
- const contentScripts = Array.from(this.contentScripts, ([_3, contentScript]) => ({
2213
+ const contentScripts = Array.from(this.contentScripts, ([_4, contentScript]) => ({
2034
2214
  matches: contentScript.matches,
2035
2215
  exclude_matches: contentScript.excludeMatches,
2036
2216
  all_frames: contentScript.allFrames,
@@ -2070,7 +2250,7 @@ var ManifestV3_default = class extends ManifestBase_default {
2070
2250
  }
2071
2251
  buildContentScripts() {
2072
2252
  if (this.contentScripts.size > 0) {
2073
- const contentScripts = Array.from(this.contentScripts, ([_3, contentScript]) => ({
2253
+ const contentScripts = Array.from(this.contentScripts, ([_4, contentScript]) => ({
2074
2254
  matches: contentScript.matches,
2075
2255
  exclude_matches: contentScript.excludeMatches,
2076
2256
  all_frames: contentScript.allFrames,
@@ -2150,67 +2330,38 @@ var ManifestPlugin = class {
2150
2330
  };
2151
2331
  var ManifestPlugin_default = ManifestPlugin;
2152
2332
 
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
2333
  // src/cli/resolvers/webpack.ts
2192
2334
  var getConfigFromPlugins = async (webpack4, config) => {
2193
2335
  let mergedConfig = {};
2194
- for await (const webpackFromPlugin of processPluginHandler(config, "webpack", { webpack: webpack4, config })) {
2195
- mergedConfig = merge_default(mergedConfig, webpackFromPlugin);
2336
+ for await (const { result: pluginConfig } of processPluginHandler(config, "webpack", { webpack: webpack4, config })) {
2337
+ mergedConfig = merge_default(mergedConfig, pluginConfig);
2196
2338
  }
2197
2339
  return mergedConfig;
2198
2340
  };
2199
- var getConfigForManifest = async (webpack4, config) => {
2341
+ var getConfigForManifest = async (config) => {
2200
2342
  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
- };
2343
+ const update = async () => await Array.fromAsync(processPluginHandler(config, "manifest", { manifest, config }));
2344
+ await update();
2345
+ const plugins = [];
2346
+ if (config.mode === "development" /* Development */) {
2347
+ plugins.push(new WatchPlugin_default({
2348
+ key: "manifest",
2349
+ callback: async () => {
2350
+ await update();
2351
+ }
2352
+ }));
2353
+ }
2354
+ plugins.push(new ManifestPlugin_default(manifest));
2355
+ return { plugins };
2205
2356
  };
2206
- var webpack_default = async (config) => {
2357
+ var webpack_default = async (command, config) => {
2207
2358
  let webpack4 = {
2208
2359
  mode: config.mode,
2209
2360
  cache: false,
2210
2361
  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]")
2362
+ path: getRootPath(getOutputPath(config)),
2363
+ filename: path2__default.default.join(config.jsDir, "[name].js"),
2364
+ assetModuleFilename: path2__default.default.join(config.assetsDir, "[name]-[hash:4][ext]")
2214
2365
  },
2215
2366
  resolve: {
2216
2367
  extensions: [".ts", ".tsx", ".js", ".scss"],
@@ -2253,27 +2404,36 @@ var webpack_default = async (config) => {
2253
2404
  webpack4 = merge_default(
2254
2405
  webpack4,
2255
2406
  await getConfigFromPlugins(webpack4, config),
2256
- await getConfigForManifest(webpack4, config)
2407
+ await getConfigForManifest(config)
2257
2408
  );
2409
+ if (command == "watch" /* Watch */) {
2410
+ webpack4 = merge_default(webpack4, {
2411
+ devtool: "inline-source-map"
2412
+ });
2413
+ }
2258
2414
  return webpack4;
2259
2415
  };
2260
2416
 
2261
- // src/cli/builders/app.ts
2262
- var app_default = async (config) => {
2417
+ // src/cli/builders/app/index.ts
2418
+ var app_default = async (command, config) => {
2263
2419
  const resolverConfig = await config_default(config);
2264
- const webpackConfig = await webpack_default(resolverConfig);
2420
+ const webpackConfig = await webpack_default(command, resolverConfig);
2265
2421
  const compiler = webpack__default.default(webpackConfig);
2266
- compiler.run((err, stats) => {
2267
- if (err) {
2268
- console.error("Webpack compilation error");
2422
+ switch (command) {
2423
+ case "build" /* Build */:
2424
+ build(compiler);
2425
+ break;
2426
+ case "watch" /* Watch */:
2427
+ watch(compiler);
2428
+ break;
2429
+ default:
2430
+ console.error("Unknown command");
2269
2431
  process.exit(1);
2270
- }
2271
- console.log(stats == null ? void 0 : stats.toString({ colors: true }));
2272
- });
2432
+ }
2273
2433
  };
2274
2434
 
2275
2435
  // package.json
2276
- var version = "0.0.14";
2436
+ var version = "0.0.16";
2277
2437
 
2278
2438
  // src/cli/index.ts
2279
2439
  var cli = cac__default.default("adnbn");
@@ -2281,18 +2441,27 @@ cli.option("--debug", "Enable debug mode");
2281
2441
  cli.command("init", "Initialize a new project").action(() => {
2282
2442
  console.log("init is good in cli");
2283
2443
  });
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);
2444
+ 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) => {
2445
+ await app_default("watch" /* Watch */, {
2446
+ mode: options.mode,
2447
+ debug: options.debug,
2448
+ app: options.app,
2449
+ browser: options.browser,
2450
+ manifestVersion: options.mv2 ? 2 : 3,
2451
+ inputDir: root,
2452
+ configFile: options.config
2453
+ });
2286
2454
  });
2287
2455
  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({
2456
+ await app_default("build" /* Build */, {
2289
2457
  mode: options.mode,
2290
2458
  debug: options.debug,
2291
2459
  app: options.app,
2292
2460
  browser: options.browser,
2293
2461
  manifestVersion: options.mv2 ? 2 : 3,
2294
2462
  inputDir: root,
2295
- configFile: options.config
2463
+ configFile: options.config,
2464
+ analyze: options.analyze
2296
2465
  });
2297
2466
  });
2298
2467
  cli.version(version);