@threenative/runtime-native 0.3.1 → 0.3.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threenative/runtime-native",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "ThreeNative-owned native host for desktop, Android, and iOS",
5
5
  "keywords": [
6
6
  "threenative",
@@ -62,7 +62,7 @@
62
62
  "publint": "0.3.22",
63
63
  "three": "0.185.1",
64
64
  "vitest": "4.1.10",
65
- "@threenative/playtest": "0.3.1"
65
+ "@threenative/playtest": "0.3.2"
66
66
  },
67
67
  "dependencies": {
68
68
  "pngjs": "7.0.0"
@@ -117,6 +117,27 @@ function isLoopbackFixture(url) {
117
117
  !url.username && !url.password;
118
118
  }
119
119
 
120
+ /**
121
+ * The keys a manifest declares it advertises.
122
+ *
123
+ * A manifest may carry `requiredKeys`; absent, the strict full-cohort default below is unchanged, so
124
+ * the official CI release keeps its guarantee. A scoped manifest is how a local release states which
125
+ * of the platform matrices this host actually built, without claiming the rest.
126
+ */
127
+ function declaredRequiredKeys(manifest) {
128
+ if (manifest.requiredKeys === undefined) return undefined;
129
+ if (!Array.isArray(manifest.requiredKeys) || manifest.requiredKeys.length === 0 ||
130
+ manifest.requiredKeys.some((key) => typeof key !== 'string')) {
131
+ throw new Error('Prebuilt manifest requiredKeys must be a non-empty array of prebuilt release keys.');
132
+ }
133
+ for (const key of manifest.requiredKeys) {
134
+ if (!Object.hasOwn(PREBUILT_ASSET_NAMES, key)) {
135
+ throw new Error(`Unknown prebuilt release key '${key}' in manifest requiredKeys.`);
136
+ }
137
+ }
138
+ return manifest.requiredKeys;
139
+ }
140
+
120
141
  function validateManifestEnvelope(manifest, options) {
121
142
  if (manifest?.schemaVersion !== 1) throw new Error('Unsupported or missing prebuilt manifest schemaVersion.');
122
143
  const version = options.version ?? packageVersion;
@@ -129,6 +150,7 @@ function validateManifestEnvelope(manifest, options) {
129
150
  if (options.sourceSha !== undefined && manifest.sourceSha !== options.sourceSha) {
130
151
  throw new Error(`Prebuilt source SHA mismatch: expected ${options.sourceSha}, received ${manifest.sourceSha}.`);
131
152
  }
153
+ declaredRequiredKeys(manifest);
132
154
  if (!manifest.artifacts || typeof manifest.artifacts !== 'object' || Array.isArray(manifest.artifacts)) {
133
155
  throw new Error('Prebuilt manifest artifacts must be an object.');
134
156
  }
@@ -151,23 +173,39 @@ function validateManifestArtifact(manifest, key, version) {
151
173
  /** Validate the entire advertised cohort before selecting even one consumer artifact. */
152
174
  export function validateReleaseManifest(manifest, options = {}) {
153
175
  const version = validateManifestEnvelope(manifest, options);
154
- // iOS retains its separate release gate; it is not a prerequisite for a non-iOS consumer.
155
- const requiredKeys = options.requiredKeys ??
176
+ // A caller's explicit scope wins; then the manifest's own advertised keys; then the strict
177
+ // non-iOS cohort. iOS retains its separate release gate, so it is not a prerequisite for a
178
+ // non-iOS consumer, and a scoped local manifest is accepted for exactly the keys it names.
179
+ const requiredKeys = options.requiredKeys ?? declaredRequiredKeys(manifest) ??
156
180
  PUBLISHED_PREBUILT_KEYS.filter((key) => !key.startsWith('ios-'));
157
181
  for (const key of requiredKeys) releaseFromManifest(manifest, key);
158
182
  for (const key of Object.keys(manifest.artifacts)) validateManifestArtifact(manifest, key, version);
159
183
  return manifest;
160
184
  }
161
185
 
162
- /** The release workflow uses this same validator, including its existing iOS requirement. */
163
- export function generateReleaseManifest(directory, { repository, tag, sourceSha }) {
186
+ /**
187
+ * The release workflow uses this same validator, including its existing iOS requirement.
188
+ *
189
+ * `keys` narrows the matrix to the artifacts this caller staged: the lock then advertises exactly
190
+ * those keys (`requiredKeys`) and refuses if one is missing from the directory. Omitted, the full
191
+ * published matrix is required and the lock carries no `requiredKeys`, so every consumer keeps the
192
+ * strict default.
193
+ */
194
+ export function generateReleaseManifest(directory, { repository, tag, sourceSha, keys }) {
164
195
  if (repository !== RELEASE_REPOSITORY) {
165
196
  throw new Error(`Prebuilt releases must be published by ${RELEASE_REPOSITORY}, received ${repository}.`);
166
197
  }
167
- if (tag !== `runtime-native-v${packageVersion}`) {
168
- throw new Error(`Prebuilt release tag must be runtime-native-v${packageVersion}, received ${tag}.`);
198
+ if (tag !== releaseTag()) {
199
+ throw new Error(`Prebuilt release tag must be ${releaseTag()}, received ${tag}.`);
169
200
  }
170
- const published = PUBLISHED_PREBUILT_KEYS.map((key) => [key, PREBUILT_ASSET_NAMES[key]]);
201
+ const selectedKeys = keys === undefined ? [...PUBLISHED_PREBUILT_KEYS] : keys;
202
+ if (!Array.isArray(selectedKeys) || selectedKeys.length === 0) {
203
+ throw new Error('Prebuilt release keys must be a non-empty array.');
204
+ }
205
+ const published = selectedKeys.map((key) => {
206
+ if (!Object.hasOwn(PREBUILT_ASSET_NAMES, key)) throw new Error(`Unknown prebuilt release key '${key}'.`);
207
+ return [key, PREBUILT_ASSET_NAMES[key]];
208
+ });
171
209
  const expected = published.map(([, name]) => name).sort();
172
210
  const actual = readdirSync(directory).sort();
173
211
  if (JSON.stringify(actual) !== JSON.stringify(expected)) {
@@ -179,8 +217,11 @@ export function generateReleaseManifest(directory, { repository, tag, sourceSha
179
217
  return [key, { sha256: sha256(contents), size: contents.length,
180
218
  url: `${releaseManifestUrl().replace('/prebuilt-lock.json', '')}/${name}` }];
181
219
  }));
182
- return validateReleaseManifest({ schemaVersion: 1, version: packageVersion, sourceSha, artifacts },
183
- { sourceSha, requiredKeys: PUBLISHED_PREBUILT_KEYS });
220
+ return validateReleaseManifest(
221
+ { schemaVersion: 1, version: packageVersion, sourceSha, artifacts,
222
+ ...(keys === undefined ? {} : { requiredKeys: [...selectedKeys] }) },
223
+ { sourceSha, requiredKeys: selectedKeys },
224
+ );
184
225
  }
185
226
 
186
227
  export function readRelease(manifestPath, key) {
@@ -198,8 +239,13 @@ export function readRelease(manifestPath, key) {
198
239
  return releaseFromManifest(manifest, key);
199
240
  }
200
241
 
242
+ /** The GitHub release tag a version's prebuilt payload is published under. */
243
+ export function releaseTag(version = packageVersion) {
244
+ return `runtime-native-v${version}`;
245
+ }
246
+
201
247
  export function releaseManifestUrl(version = packageVersion) {
202
- return `https://github.com/${RELEASE_REPOSITORY}/releases/download/runtime-native-v${encodeURIComponent(version)}/prebuilt-lock.json`;
248
+ return `https://github.com/${RELEASE_REPOSITORY}/releases/download/${releaseTag(version)}/prebuilt-lock.json`;
203
249
  }
204
250
 
205
251
  export function writeInstallStatus(status, statusPath = join(packageRoot, 'prebuilt', 'install-status.json')) {