@techninja/staticart 0.1.12 → 0.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@techninja/staticart",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "StatiCart — a full-featured e-commerce platform built 99% on static hosting",
5
5
  "repository": {
6
6
  "type": "git",
@@ -8,17 +8,29 @@
8
8
  import { cpSync, mkdirSync } from 'node:fs';
9
9
  import { resolve, dirname } from 'node:path';
10
10
  import { fileURLToPath } from 'node:url';
11
+ import { createRequire } from 'node:module';
11
12
 
12
13
  const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
13
14
  const VENDOR_DIR = resolve(ROOT, 'src/vendor');
15
+ const require = createRequire(import.meta.url);
14
16
 
15
- /** @type {{ name: string, src: string }[]} */
16
- const DEPS = [{ name: 'hybrids', src: 'node_modules/hybrids/src' }];
17
+ /** Resolve a package's source dir, handling npm hoisting. */
18
+ function findPkgSrc(pkg, subdir) {
19
+ try {
20
+ const entry = require.resolve(`${pkg}/package.json`);
21
+ return resolve(dirname(entry), subdir);
22
+ } catch {
23
+ return resolve(ROOT, 'node_modules', pkg, subdir);
24
+ }
25
+ }
26
+
27
+ /** @type {{ name: string, src: string, subdir: string }[]} */
28
+ const DEPS = [{ name: 'hybrids', src: 'hybrids', subdir: 'src' }];
17
29
 
18
30
  mkdirSync(VENDOR_DIR, { recursive: true });
19
31
 
20
32
  for (const dep of DEPS) {
21
- const src = resolve(ROOT, dep.src);
33
+ const src = findPkgSrc(dep.src, dep.subdir);
22
34
  const dest = resolve(VENDOR_DIR, dep.name);
23
35
  cpSync(src, dest, { recursive: true });
24
36
  console.log(`✓ Vendored: ${dep.name} → src/vendor/${dep.name}/`);
@@ -49,7 +49,14 @@ export function renderNotFound(CatalogView) {
49
49
 
50
50
  /** @param {number} s */
51
51
  export function stockBadge(s) {
52
- const label = s < 0 ? 'product.inStock' : s === 0 ? 'product.outOfStock' : s <= 5 ? 'product.lowStock' : 'product.inStock';
52
+ const label =
53
+ s < 0
54
+ ? 'product.inStock'
55
+ : s === 0
56
+ ? 'product.outOfStock'
57
+ : s <= 5
58
+ ? 'product.lowStock'
59
+ : 'product.inStock';
53
60
  const color = s < 0 ? 'success' : s === 0 ? 'danger' : s <= 5 ? 'warning' : 'success';
54
61
  return html`<app-badge label="${t(label)}" color="${color}"></app-badge>`;
55
62
  }