@techninja/staticart 0.1.11 → 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.11",
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}/`);
@@ -50,11 +50,10 @@ export default define({
50
50
  .filter(
51
51
  (p) =>
52
52
  p.sku !== currentSku &&
53
- p.stock > 0 &&
53
+ p.stock !== 0 &&
54
54
  (!excludeSeries || p.metadata?.seriesTitle !== excludeSeries),
55
55
  )
56
56
  .map((p) => ({ product: p, score: relevanceScore(current, p) }))
57
- .filter((r) => r.score > 0)
58
57
  .sort((a, b) => b.score - a.score)
59
58
  .slice(0, MAX_RELATED)
60
59
  .map((r) => r.product);
@@ -26,7 +26,7 @@ export default define({
26
26
  value: ({ series, currentSku, products }) => {
27
27
  if (!series || !(/** @type {any} */ (store).ready(products))) return html``;
28
28
  const related = /** @type {any[]} */ (products)
29
- .filter((p) => p.metadata?.seriesTitle === series && p.sku !== currentSku && p.stock > 0)
29
+ .filter((p) => p.metadata?.seriesTitle === series && p.sku !== currentSku && p.stock !== 0)
30
30
  .sort((a, b) => a.name.localeCompare(b.name));
31
31
  if (!related.length) return html``;
32
32
  return html`
@@ -49,8 +49,15 @@ export function renderNotFound(CatalogView) {
49
49
 
50
50
  /** @param {number} s */
51
51
  export function stockBadge(s) {
52
- const label = s <= 0 ? 'product.outOfStock' : s <= 5 ? 'product.lowStock' : 'product.inStock';
53
- const color = s <= 0 ? 'danger' : s <= 5 ? 'warning' : 'success';
52
+ const label =
53
+ s < 0
54
+ ? 'product.inStock'
55
+ : s === 0
56
+ ? 'product.outOfStock'
57
+ : s <= 5
58
+ ? 'product.lowStock'
59
+ : 'product.inStock';
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
  }
56
63
 
@@ -59,7 +66,7 @@ export function handleAdd(host) {
59
66
  if (!store.ready(host.cart) || !store.ready(host.product)) return;
60
67
  const { product: p, selectedVariant: vid, qty } = host;
61
68
  const stock = vid ? (p.variants.find((v) => v.id === vid)?.stock ?? 0) : p.stock;
62
- if (qty <= stock && stock > 0) addToCart(host.cart, p.sku, vid, qty);
69
+ if (stock < 0 || (qty <= stock && stock > 0)) addToCart(host.cart, p.sku, vid, qty);
63
70
  }
64
71
 
65
72
  /** @param {any} host */
@@ -50,11 +50,10 @@ export default define({
50
50
  .filter(
51
51
  (p) =>
52
52
  p.sku !== currentSku &&
53
- p.stock > 0 &&
53
+ p.stock !== 0 &&
54
54
  (!excludeSeries || p.metadata?.seriesTitle !== excludeSeries),
55
55
  )
56
56
  .map((p) => ({ product: p, score: relevanceScore(current, p) }))
57
- .filter((r) => r.score > 0)
58
57
  .sort((a, b) => b.score - a.score)
59
58
  .slice(0, MAX_RELATED)
60
59
  .map((r) => r.product);
@@ -26,7 +26,7 @@ export default define({
26
26
  value: ({ series, currentSku, products }) => {
27
27
  if (!series || !(/** @type {any} */ (store).ready(products))) return html``;
28
28
  const related = /** @type {any[]} */ (products)
29
- .filter((p) => p.metadata?.seriesTitle === series && p.sku !== currentSku && p.stock > 0)
29
+ .filter((p) => p.metadata?.seriesTitle === series && p.sku !== currentSku && p.stock !== 0)
30
30
  .sort((a, b) => a.name.localeCompare(b.name));
31
31
  if (!related.length) return html``;
32
32
  return html`
@@ -49,8 +49,15 @@ export function renderNotFound(CatalogView) {
49
49
 
50
50
  /** @param {number} s */
51
51
  export function stockBadge(s) {
52
- const label = s <= 0 ? 'product.outOfStock' : s <= 5 ? 'product.lowStock' : 'product.inStock';
53
- const color = s <= 0 ? 'danger' : s <= 5 ? 'warning' : 'success';
52
+ const label =
53
+ s < 0
54
+ ? 'product.inStock'
55
+ : s === 0
56
+ ? 'product.outOfStock'
57
+ : s <= 5
58
+ ? 'product.lowStock'
59
+ : 'product.inStock';
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
  }
56
63
 
@@ -59,7 +66,7 @@ export function handleAdd(host) {
59
66
  if (!store.ready(host.cart) || !store.ready(host.product)) return;
60
67
  const { product: p, selectedVariant: vid, qty } = host;
61
68
  const stock = vid ? (p.variants.find((v) => v.id === vid)?.stock ?? 0) : p.stock;
62
- if (qty <= stock && stock > 0) addToCart(host.cart, p.sku, vid, qty);
69
+ if (stock < 0 || (qty <= stock && stock > 0)) addToCart(host.cart, p.sku, vid, qty);
63
70
  }
64
71
 
65
72
  /** @param {any} host */