sh3-core 0.21.0 → 0.21.2

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.
@@ -111,6 +111,8 @@
111
111
  for (const p of installed) {
112
112
  if (p.type === 'shard' || p.type === 'combo') known.add(p.id);
113
113
  }
114
+ // A combo package provides its own shard — don't block it on its own id.
115
+ if (pkg.entry.type === 'combo') known.add(pkg.entry.id);
114
116
  return required.filter((id: string) => !known.has(id));
115
117
  }
116
118
 
package/dist/build.d.ts CHANGED
@@ -82,4 +82,9 @@ export declare function composeArtifactVersion(pkgVersion: string, suffix: strin
82
82
  * Exported for testing; used internally by sh3Artifact.
83
83
  */
84
84
  export declare function extractRequiredShardsFromBundle(bundleSource: string): string[];
85
+ /**
86
+ * Collect all shard ids present in a bundle by scanning every `views: [` block.
87
+ * Exported for testing.
88
+ */
89
+ export declare function extractBundledShardIds(bundleSource: string): Set<string>;
85
90
  export declare function sh3Artifact(options?: Sh3ArtifactOptions): Plugin;
package/dist/build.js CHANGED
@@ -159,6 +159,50 @@ export function extractRequiredShardsFromBundle(bundleSource) {
159
159
  ids.push(m[1]);
160
160
  return ids;
161
161
  }
162
+ /**
163
+ * Collect all shard ids present in a bundle by scanning every `views: [` block.
164
+ * Exported for testing.
165
+ */
166
+ export function extractBundledShardIds(bundleSource) {
167
+ const ids = new Set();
168
+ const viewsRe = /\bviews\s*:\s*\[/g;
169
+ let m;
170
+ while ((m = viewsRe.exec(bundleSource)) !== null) {
171
+ // Walk back to the enclosing `{`.
172
+ let depth = 0;
173
+ let blockStart = m.index;
174
+ for (let i = m.index - 1; i >= 0; i--) {
175
+ if (bundleSource[i] === '}')
176
+ depth++;
177
+ if (bundleSource[i] === '{') {
178
+ if (depth === 0) {
179
+ blockStart = i;
180
+ break;
181
+ }
182
+ depth--;
183
+ }
184
+ }
185
+ // Walk forward to the matching `}`.
186
+ depth = 0;
187
+ let blockEnd = bundleSource.length;
188
+ for (let i = blockStart; i < bundleSource.length; i++) {
189
+ if (bundleSource[i] === '{')
190
+ depth++;
191
+ if (bundleSource[i] === '}') {
192
+ depth--;
193
+ if (depth === 0) {
194
+ blockEnd = i + 1;
195
+ break;
196
+ }
197
+ }
198
+ }
199
+ const block = bundleSource.slice(blockStart, blockEnd);
200
+ const idMatch = block.match(/\bid\s*:\s*["']([^"']+)["']/);
201
+ if (idMatch)
202
+ ids.add(idMatch[1]);
203
+ }
204
+ return ids;
205
+ }
162
206
  export function sh3Artifact(options = {}) {
163
207
  let outDir = '';
164
208
  let entryFileName = '';
@@ -265,7 +309,13 @@ export function sh3Artifact(options = {}) {
265
309
  }
266
310
  // App first, then Shard.
267
311
  const extracted = (_a = extractFromBlock(/\brequiredShards\s*:\s*\[/)) !== null && _a !== void 0 ? _a : extractFromBlock(/\bviews\s*:\s*\[/);
268
- const { id, label, requiredShards } = extracted;
312
+ const { id, label } = extracted;
313
+ let { requiredShards } = extracted;
314
+ // Strip any shard ids that are bundled in this artifact from requiredShards.
315
+ const bundledShardIds = extractBundledShardIds(source);
316
+ if (bundledShardIds.size > 0) {
317
+ requiredShards = requiredShards.filter(s => !bundledShardIds.has(s));
318
+ }
269
319
  // --- Optional server bundle ---
270
320
  let hasServer = false;
271
321
  if (options.serverEntry && existsSync(options.serverEntry)) {
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect } from 'vitest';
2
- import { composeArtifactVersion, extractRequiredShardsFromBundle } from './build';
2
+ import { composeArtifactVersion, extractRequiredShardsFromBundle, extractBundledShardIds } from './build';
3
3
  describe('composeArtifactVersion', () => {
4
4
  it('returns pkgVersion unchanged when suffix is undefined', () => {
5
5
  expect(composeArtifactVersion('1.2.3', undefined)).toBe('1.2.3');
@@ -55,3 +55,32 @@ describe('extractRequiredShardsFromBundle', () => {
55
55
  expect(extractRequiredShardsFromBundle(src)).toEqual(['guml.core', 'other-shard']);
56
56
  });
57
57
  });
58
+ describe('extractBundledShardIds', () => {
59
+ it('returns empty set when no shard blocks are present', () => {
60
+ const src = `const App = { id: "my-app", requiredShards: ["sh3-file-explorer"] };`;
61
+ expect(extractBundledShardIds(src)).toEqual(new Set());
62
+ });
63
+ it('extracts a single bundled shard id', () => {
64
+ const src = `const Shard = { id: "sh3-file-explorer", views: [] };`;
65
+ expect(extractBundledShardIds(src)).toEqual(new Set(['sh3-file-explorer']));
66
+ });
67
+ it('extracts multiple bundled shard ids', () => {
68
+ const src = `
69
+ const A = { id: "shard-a", views: [] };
70
+ const B = { id: "shard-b", views: [] };
71
+ `;
72
+ expect(extractBundledShardIds(src)).toEqual(new Set(['shard-a', 'shard-b']));
73
+ });
74
+ it('bundled shard ids are filtered from requiredShards', () => {
75
+ // Simulate a combo bundle: app requires shard-a and external-dep,
76
+ // but shard-a is present in the same bundle.
77
+ const src = `
78
+ const App = { id: "my-app", requiredShards: ["shard-a", "external-dep"] };
79
+ const Shard = { id: "shard-a", views: [] };
80
+ `;
81
+ const bundled = extractBundledShardIds(src);
82
+ const required = extractRequiredShardsFromBundle(src);
83
+ const filtered = required.filter(s => !bundled.has(s));
84
+ expect(filtered).toEqual(['external-dep']);
85
+ });
86
+ });
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  /** Auto-generated from package.json — do not edit manually. */
2
- export declare const VERSION = "0.21.0";
2
+ export declare const VERSION = "0.21.2";
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
1
  /** Auto-generated from package.json — do not edit manually. */
2
- export const VERSION = '0.21.0';
2
+ export const VERSION = '0.21.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sh3-core",
3
- "version": "0.21.0",
3
+ "version": "0.21.2",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"