@supersdk/supercli 0.3.3 → 0.3.5-staging.52

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.
Files changed (75) hide show
  1. package/dist/build/artifactIntegrity.js +158 -2
  2. package/dist/build/artifactIntegrity.js.map +1 -1
  3. package/dist/build/projectBuild.js +335 -0
  4. package/dist/build/projectBuild.js.map +1 -0
  5. package/dist/cli.js +0 -2
  6. package/dist/cli.js.map +1 -1
  7. package/dist/commands/add.js +35 -29
  8. package/dist/commands/add.js.map +1 -1
  9. package/dist/commands/build.js +407 -105
  10. package/dist/commands/build.js.map +1 -1
  11. package/dist/commands/init.js +22 -29
  12. package/dist/commands/init.js.map +1 -1
  13. package/dist/commands/register.js +62 -217
  14. package/dist/commands/register.js.map +1 -1
  15. package/dist/config/appConfig.js +36 -163
  16. package/dist/config/appConfig.js.map +1 -1
  17. package/dist/config/superConfig.js +213 -185
  18. package/dist/config/superConfig.js.map +1 -1
  19. package/dist/deploy/domainEndpoints.js +142 -0
  20. package/dist/deploy/domainEndpoints.js.map +1 -0
  21. package/dist/deploy/manifest.js +189 -167
  22. package/dist/deploy/manifest.js.map +1 -1
  23. package/dist/deploy/preflight.js +15 -16
  24. package/dist/deploy/preflight.js.map +1 -1
  25. package/dist/deploy/resultWriter.js +95 -9
  26. package/dist/deploy/resultWriter.js.map +1 -1
  27. package/dist/deploy/runAdapter.js +79 -10
  28. package/dist/deploy/runAdapter.js.map +1 -1
  29. package/dist/deploy/siteAdapter.js +54 -8
  30. package/dist/deploy/siteAdapter.js.map +1 -1
  31. package/dist/docker/dockerCli.js +72 -77
  32. package/dist/docker/dockerCli.js.map +1 -1
  33. package/dist/publish/runClient.js +4 -0
  34. package/dist/publish/runClient.js.map +1 -1
  35. package/dist/template/README.md +26 -94
  36. package/dist/template/android/gradle/supersdk-config-reader.gradle +13 -62
  37. package/dist/template/android/scripts/build.sh +11 -0
  38. package/dist/template/ios/project.yml +1 -1
  39. package/dist/template/ios/scripts/build.sh +19 -0
  40. package/dist/template/ios/scripts/render_project.py +60 -0
  41. package/dist/template/ios/supersdk-default.config.json +6 -0
  42. package/dist/template/service/scripts/build.sh +11 -0
  43. package/dist/template/super.json +22 -14
  44. package/dist/template/template_manifest.json +3 -7
  45. package/dist/template/web/package.json +8 -0
  46. package/dist/template/web/scripts/build.sh +8 -0
  47. package/dist/template/web/scripts/web_package.py +490 -0
  48. package/dist/template/web/src/js/app.js +2 -2
  49. package/dist/util/shell.js +3 -3
  50. package/dist/workspace/config.js +3 -79
  51. package/dist/workspace/config.js.map +1 -1
  52. package/dist/workspace/identity.js +6 -15
  53. package/dist/workspace/identity.js.map +1 -1
  54. package/dist/workspace/projectIdentity.js +2 -7
  55. package/dist/workspace/projectIdentity.js.map +1 -1
  56. package/dist/workspace/template.js +205 -77
  57. package/dist/workspace/template.js.map +1 -1
  58. package/package.json +4 -1
  59. package/dist/commands/config.js +0 -170
  60. package/dist/commands/config.js.map +0 -1
  61. package/dist/template/scripts/android_snapshot_canary.py +0 -145
  62. package/dist/template/scripts/build_android.sh +0 -382
  63. package/dist/template/scripts/build_ios.sh +0 -331
  64. package/dist/template/scripts/build_service.sh +0 -89
  65. package/dist/template/scripts/build_site.sh +0 -57
  66. package/dist/template/scripts/lib/workspace.sh +0 -43
  67. package/dist/template/scripts/serve_web.py +0 -78
  68. package/dist/template/scripts/super_build_orchestrator.py +0 -344
  69. package/dist/template/scripts/supersdk_template.py +0 -1394
  70. package/dist/template/scripts/web_host_validator.py +0 -103
  71. package/dist/template/scripts/web_package.py +0 -296
  72. package/dist/template/scripts/ws03_shared_schema_merge_guard.py +0 -73
  73. package/dist/template/super_build.sh +0 -70
  74. package/dist/workspace/inspect.js +0 -275
  75. package/dist/workspace/inspect.js.map +0 -1
@@ -0,0 +1,490 @@
1
+ #!/usr/bin/env python3
2
+ """Build this Web project's publishable directory and offline package."""
3
+
4
+ import argparse
5
+ import hashlib
6
+ import ipaddress
7
+ import json
8
+ import os
9
+ import re
10
+ import secrets
11
+ import shutil
12
+ import stat
13
+ import sys
14
+ import time
15
+ import zipfile
16
+ from dataclasses import dataclass
17
+ from pathlib import Path
18
+ from urllib.parse import urlparse
19
+
20
+
21
+ REQUIRED_ASSETS = ("index.html", "js/app.js", "js/supersdk.js", "css/style.css")
22
+ EXCLUDED_ASSETS = {"__super_meta.json", "js/supersdk.provenance.json"}
23
+ PROVENANCE_FIELDS = {"package", "version", "integrity", "file", "sha256"}
24
+ VERSION_PATTERN = re.compile(r"^[0-9]+\.[0-9]+\.[0-9]+$")
25
+ INTEGRITY_PATTERN = re.compile(r"^sha512-[A-Za-z0-9+/]+={0,2}$")
26
+ SHA256_PATTERN = re.compile(r"^[0-9a-f]{64}$")
27
+ SPID_PATTERN = re.compile(r"^[a-z0-9]{8}$")
28
+
29
+
30
+ class WebBuildError(Exception):
31
+ pass
32
+
33
+
34
+ @dataclass
35
+ class VerifiedDirectory:
36
+ path: Path
37
+ real_path: Path
38
+ device: int
39
+ inode: int
40
+ fd: int
41
+ owned: bool = False
42
+
43
+
44
+ def _directory_open_flags():
45
+ flags = os.O_RDONLY
46
+ flags |= getattr(os, "O_DIRECTORY", 0)
47
+ flags |= getattr(os, "O_NOFOLLOW", 0)
48
+ return flags
49
+
50
+
51
+ def open_verified_root(path):
52
+ try:
53
+ before = os.lstat(path)
54
+ except OSError as exc:
55
+ raise WebBuildError(f"cannot inspect Web project directory: {path}") from exc
56
+ if stat.S_ISLNK(before.st_mode) or not stat.S_ISDIR(before.st_mode):
57
+ raise WebBuildError(f"Web project directory must be a real directory: {path}")
58
+ try:
59
+ fd = os.open(path, _directory_open_flags())
60
+ except OSError as exc:
61
+ raise WebBuildError(f"cannot open Web project directory without following symlinks: {path}") from exc
62
+ try:
63
+ opened = os.fstat(fd)
64
+ real_path = path.resolve(strict=True)
65
+ after = os.lstat(real_path)
66
+ if (before.st_dev, before.st_ino) != (opened.st_dev, opened.st_ino):
67
+ raise WebBuildError(f"Web project directory changed during validation: {path}")
68
+ if (after.st_dev, after.st_ino) != (opened.st_dev, opened.st_ino):
69
+ raise WebBuildError(f"Web project real path changed during validation: {path}")
70
+ return VerifiedDirectory(real_path, real_path, opened.st_dev, opened.st_ino, fd)
71
+ except Exception:
72
+ os.close(fd)
73
+ raise
74
+
75
+
76
+ def assert_verified_directory(directory):
77
+ assert_verified_directory_handle(directory)
78
+ try:
79
+ current = os.lstat(directory.path)
80
+ current_real = directory.path.resolve(strict=True)
81
+ except (OSError, RuntimeError) as exc:
82
+ raise WebBuildError(f"verified directory is no longer accessible: {directory.path}") from exc
83
+ expected = (directory.device, directory.inode)
84
+ if stat.S_ISLNK(current.st_mode) or not stat.S_ISDIR(current.st_mode):
85
+ raise WebBuildError(f"verified directory was replaced by a symlink or non-directory: {directory.path}")
86
+ if (current.st_dev, current.st_ino) != expected:
87
+ raise WebBuildError(f"verified directory identity changed: {directory.path}")
88
+ if current_real != directory.real_path:
89
+ raise WebBuildError(f"verified directory real path changed: {directory.path}")
90
+
91
+
92
+ def assert_verified_directory_handle(directory):
93
+ try:
94
+ opened = os.fstat(directory.fd)
95
+ except OSError as exc:
96
+ raise WebBuildError(f"verified directory handle is no longer accessible: {directory.path}") from exc
97
+ if not stat.S_ISDIR(opened.st_mode) or (opened.st_dev, opened.st_ino) != (directory.device, directory.inode):
98
+ raise WebBuildError(f"verified directory handle identity changed: {directory.path}")
99
+
100
+
101
+ def open_or_create_child_directory(parent, name, mode=0o755, require_new=False):
102
+ assert_verified_directory(parent)
103
+ created = False
104
+ try:
105
+ entry = os.lstat(name, dir_fd=parent.fd)
106
+ if require_new:
107
+ raise WebBuildError(f"scratch directory already exists: {parent.path / name}")
108
+ except FileNotFoundError:
109
+ try:
110
+ os.mkdir(name, mode=mode, dir_fd=parent.fd)
111
+ except FileExistsError as exc:
112
+ raise WebBuildError(f"directory appeared during exclusive creation: {parent.path / name}") from exc
113
+ except OSError as exc:
114
+ raise WebBuildError(f"cannot create directory: {parent.path / name}") from exc
115
+ created = True
116
+ entry = os.lstat(name, dir_fd=parent.fd)
117
+ if stat.S_ISLNK(entry.st_mode) or not stat.S_ISDIR(entry.st_mode):
118
+ raise WebBuildError(f"path component must be a real directory: {parent.path / name}")
119
+ try:
120
+ fd = os.open(name, _directory_open_flags(), dir_fd=parent.fd)
121
+ except OSError as exc:
122
+ raise WebBuildError(f"cannot open path component without following symlinks: {parent.path / name}") from exc
123
+ try:
124
+ opened = os.fstat(fd)
125
+ after = os.lstat(name, dir_fd=parent.fd)
126
+ expected_real = parent.real_path / name
127
+ resolved = (parent.path / name).resolve(strict=True)
128
+ identity = (opened.st_dev, opened.st_ino)
129
+ if identity != (entry.st_dev, entry.st_ino) or identity != (after.st_dev, after.st_ino):
130
+ raise WebBuildError(f"directory identity changed during validation: {parent.path / name}")
131
+ if resolved != expected_real:
132
+ raise WebBuildError(f"directory escaped its verified parent: {parent.path / name}")
133
+ child = VerifiedDirectory(expected_real, expected_real, opened.st_dev, opened.st_ino, fd, owned=created)
134
+ assert_verified_directory(parent)
135
+ assert_verified_directory(child)
136
+ return child
137
+ except Exception:
138
+ os.close(fd)
139
+ raise
140
+
141
+
142
+ def create_owned_scratch(parent):
143
+ for _ in range(16):
144
+ name = f"web-build-{os.getpid()}-{secrets.token_hex(8)}"
145
+ try:
146
+ return open_or_create_child_directory(parent, name, mode=0o700, require_new=True)
147
+ except WebBuildError as exc:
148
+ if "already exists" not in str(exc):
149
+ raise
150
+ raise WebBuildError("cannot allocate a unique Web build scratch directory")
151
+
152
+
153
+ def validate_version(value):
154
+ if not isinstance(value, str) or not VERSION_PATTERN.fullmatch(value):
155
+ raise WebBuildError("package.json version must match x.y.z")
156
+ parts = value.split(".")
157
+ if any(len(part) > 1 and part.startswith("0") for part in parts):
158
+ raise WebBuildError("package.json version must match x.y.z")
159
+ if int(parts[1]) > 99 or int(parts[2]) > 99:
160
+ raise WebBuildError("package.json version minor and patch must be <= 99")
161
+ return value
162
+
163
+
164
+ def normalize_host(value):
165
+ diagnostic = "package.json supersdk.offlineHost must be a deployable domain or HTTP(S) URL"
166
+ if not isinstance(value, str) or not value or value != value.strip() or any(ch.isspace() for ch in value):
167
+ raise WebBuildError(diagnostic)
168
+ try:
169
+ value.encode("ascii")
170
+ except UnicodeEncodeError as exc:
171
+ raise WebBuildError(diagnostic) from exc
172
+ if "://" in value:
173
+ parsed = urlparse(value)
174
+ if parsed.scheme.lower() not in {"http", "https"} or not parsed.hostname:
175
+ raise WebBuildError(diagnostic)
176
+ host = parsed.hostname.lower()
177
+ else:
178
+ if ":" in value:
179
+ raise WebBuildError(diagnostic)
180
+ host = value.lower()
181
+ try:
182
+ ipaddress.ip_address(host)
183
+ except ValueError:
184
+ pass
185
+ else:
186
+ raise WebBuildError(diagnostic)
187
+ if host == "localhost" or host.startswith(".") or host.endswith(".") or ".." in host or len(host) > 253:
188
+ raise WebBuildError(diagnostic)
189
+ labels = host.split(".")
190
+ label_pattern = re.compile(r"^[a-z0-9]([a-z0-9-]*[a-z0-9])?$")
191
+ if len(labels) < 2 or labels[-1].isdigit():
192
+ raise WebBuildError(diagnostic)
193
+ if any(len(label) > 63 or not label_pattern.fullmatch(label) for label in labels):
194
+ raise WebBuildError(diagnostic)
195
+ return host
196
+
197
+
198
+ def read_package_settings(project_root):
199
+ package_path = project_root / "package.json"
200
+ try:
201
+ package = json.loads(package_path.read_text(encoding="utf-8"))
202
+ except FileNotFoundError as exc:
203
+ raise WebBuildError("package.json is missing") from exc
204
+ except (OSError, UnicodeDecodeError, json.JSONDecodeError) as exc:
205
+ raise WebBuildError("package.json is not valid JSON") from exc
206
+ if not isinstance(package, dict):
207
+ raise WebBuildError("package.json must contain a JSON object")
208
+ settings = package.get("supersdk")
209
+ if not isinstance(settings, dict):
210
+ raise WebBuildError("package.json supersdk must contain a JSON object")
211
+ return validate_version(package.get("version")), normalize_host(settings.get("offlineHost"))
212
+
213
+
214
+ def validate_provenance(source_root):
215
+ provenance_path = source_root / "js" / "supersdk.provenance.json"
216
+ vendored_path = source_root / "js" / "supersdk.js"
217
+ try:
218
+ provenance = json.loads(provenance_path.read_text(encoding="utf-8"))
219
+ except FileNotFoundError as exc:
220
+ raise WebBuildError("supersdk.provenance.json is missing") from exc
221
+ except (OSError, UnicodeDecodeError, json.JSONDecodeError) as exc:
222
+ raise WebBuildError("supersdk.provenance.json is not valid JSON") from exc
223
+ if not isinstance(provenance, dict) or set(provenance) != PROVENANCE_FIELDS:
224
+ raise WebBuildError("supersdk.provenance.json fields do not match the public artifact schema")
225
+ if provenance.get("package") != "@supersdk/jssdk":
226
+ raise WebBuildError("supersdk.provenance.json package must be @supersdk/jssdk")
227
+ if not isinstance(provenance.get("version"), str) or not VERSION_PATTERN.fullmatch(provenance["version"]):
228
+ raise WebBuildError("supersdk.provenance.json version must match x.y.z")
229
+ if not isinstance(provenance.get("integrity"), str) or not INTEGRITY_PATTERN.fullmatch(provenance["integrity"]):
230
+ raise WebBuildError("supersdk.provenance.json integrity must be sha512 SRI")
231
+ if provenance.get("file") != "dist/supersdk.js":
232
+ raise WebBuildError("supersdk.provenance.json file must be dist/supersdk.js")
233
+ expected_hash = provenance.get("sha256")
234
+ if not isinstance(expected_hash, str) or not SHA256_PATTERN.fullmatch(expected_hash):
235
+ raise WebBuildError("supersdk.provenance.json sha256 must be 64 lowercase hex characters")
236
+ actual_hash = hashlib.sha256(vendored_path.read_bytes()).hexdigest()
237
+ if actual_hash != expected_hash:
238
+ raise WebBuildError("supersdk.provenance.json sha256 mismatch")
239
+
240
+
241
+ def validate_source(source_root):
242
+ if not source_root.is_dir():
243
+ raise WebBuildError(f"web source directory is missing: {source_root}")
244
+ for relative in REQUIRED_ASSETS:
245
+ path = source_root / relative
246
+ if path.is_symlink() or not path.is_file():
247
+ raise WebBuildError(f"web source asset is missing or not a regular file: {relative}")
248
+ validate_provenance(source_root)
249
+
250
+
251
+ def iter_publishable_files(root):
252
+ files = []
253
+ for path in root.rglob("*"):
254
+ relative = path.relative_to(root).as_posix()
255
+ if path.is_symlink():
256
+ raise WebBuildError(f"web source must not contain symlinks: {relative}")
257
+ if path.is_dir():
258
+ continue
259
+ if not path.is_file():
260
+ raise WebBuildError(f"web source contains a non-regular file: {relative}")
261
+ if relative in EXCLUDED_ASSETS or path.name == ".DS_Store":
262
+ continue
263
+ files.append((relative, path))
264
+ return sorted(files, key=lambda item: item[0])
265
+
266
+
267
+ def render_dist(source_root, staging_dist, spid):
268
+ staging_dist.mkdir(parents=True)
269
+ for relative, source in iter_publishable_files(source_root):
270
+ target = staging_dist / relative
271
+ target.parent.mkdir(parents=True, exist_ok=True)
272
+ shutil.copy2(source, target)
273
+ (staging_dist / "supersdk-config.json").write_text(
274
+ json.dumps({"spid": spid}, separators=(",", ":")) + "\n",
275
+ encoding="utf-8",
276
+ )
277
+ for relative in REQUIRED_ASSETS:
278
+ if not (staging_dist / relative).is_file():
279
+ raise WebBuildError(f"publishable dist asset is missing: {relative}")
280
+ if (staging_dist / "js" / "supersdk.provenance.json").exists():
281
+ raise WebBuildError("publishable dist must not contain supersdk.provenance.json")
282
+
283
+
284
+ def build_offline_zip(staging_dist, target, version):
285
+ files = iter_publishable_files(staging_dist)
286
+ file_map = {relative: {"length": path.stat().st_size} for relative, path in files}
287
+ meta = {
288
+ "__ver": 1,
289
+ "app_version": version,
290
+ "build_time": int(time.time()),
291
+ "file_map": file_map,
292
+ }
293
+ target.parent.mkdir(parents=True, exist_ok=True)
294
+ with zipfile.ZipFile(target, "w", compression=zipfile.ZIP_DEFLATED) as archive:
295
+ for relative, path in files:
296
+ archive.write(path, relative)
297
+ archive.writestr("__super_meta.json", json.dumps(meta, separators=(",", ":")) + "\n")
298
+
299
+
300
+ def install_outputs(scratch, staged_dist, staged_zip, project):
301
+ outputs = [
302
+ (staged_dist.name, project.root, "dist", "directory"),
303
+ (staged_zip.name, project.artifacts, "site-offline.zip", "file"),
304
+ ]
305
+ backups = []
306
+ installed = []
307
+ try:
308
+ for index, (_, parent, target_name, expected_kind) in enumerate(outputs):
309
+ assert_verified_directory_handle(parent)
310
+ try:
311
+ target = os.lstat(target_name, dir_fd=parent.fd)
312
+ except FileNotFoundError:
313
+ continue
314
+ if stat.S_ISLNK(target.st_mode):
315
+ raise WebBuildError(f"refuse to replace symlink output: {parent.path / target_name}")
316
+ if expected_kind == "directory" and not stat.S_ISDIR(target.st_mode):
317
+ raise WebBuildError(f"build output must be a directory: {parent.path / target_name}")
318
+ if expected_kind == "file" and not stat.S_ISREG(target.st_mode):
319
+ raise WebBuildError(f"build output must be a regular file: {parent.path / target_name}")
320
+ backup_name = f"backup-{index}"
321
+ os.replace(target_name, backup_name, src_dir_fd=parent.fd, dst_dir_fd=scratch.fd)
322
+ backups.append((backup_name, parent, target_name))
323
+ for staged_name, parent, target_name, _ in outputs:
324
+ assert_verified_directory_handle(parent)
325
+ assert_verified_directory_handle(scratch)
326
+ os.replace(staged_name, target_name, src_dir_fd=scratch.fd, dst_dir_fd=parent.fd)
327
+ installed.append((parent, target_name))
328
+ except Exception:
329
+ for index, (parent, target_name) in enumerate(reversed(installed)):
330
+ assert_verified_directory_handle(parent)
331
+ assert_verified_directory_handle(scratch)
332
+ os.replace(target_name, f"rollback-installed-{index}", src_dir_fd=parent.fd, dst_dir_fd=scratch.fd)
333
+ for backup_name, parent, target_name in reversed(backups):
334
+ assert_verified_directory_handle(parent)
335
+ assert_verified_directory_handle(scratch)
336
+ try:
337
+ os.lstat(backup_name, dir_fd=scratch.fd)
338
+ except FileNotFoundError:
339
+ continue
340
+ os.replace(backup_name, target_name, src_dir_fd=scratch.fd, dst_dir_fd=parent.fd)
341
+ raise
342
+ for backup_name, _, _ in backups:
343
+ try:
344
+ os.lstat(backup_name, dir_fd=scratch.fd)
345
+ except FileNotFoundError:
346
+ continue
347
+ remove_entry_at(scratch.fd, backup_name)
348
+
349
+
350
+ @dataclass
351
+ class WebOutputDirectories:
352
+ root: VerifiedDirectory
353
+ state: VerifiedDirectory
354
+ artifacts: VerifiedDirectory
355
+
356
+
357
+ def open_output_directories(project_root):
358
+ root = open_verified_root(project_root)
359
+ state_dir = None
360
+ artifacts_dir = None
361
+ try:
362
+ state_dir = open_or_create_child_directory(root, ".supersdk")
363
+ artifacts_dir = open_or_create_child_directory(state_dir, "artifacts")
364
+ return WebOutputDirectories(root, state_dir, artifacts_dir)
365
+ except Exception:
366
+ if artifacts_dir is not None:
367
+ os.close(artifacts_dir.fd)
368
+ if state_dir is not None:
369
+ os.close(state_dir.fd)
370
+ os.close(root.fd)
371
+ raise
372
+
373
+
374
+ def close_output_directories(directories):
375
+ os.close(directories.artifacts.fd)
376
+ os.close(directories.state.fd)
377
+ os.close(directories.root.fd)
378
+
379
+
380
+ def remove_entry_at(directory_fd, name):
381
+ entry = os.lstat(name, dir_fd=directory_fd)
382
+ if stat.S_ISDIR(entry.st_mode) and not stat.S_ISLNK(entry.st_mode):
383
+ child_fd = os.open(name, _directory_open_flags(), dir_fd=directory_fd)
384
+ try:
385
+ opened = os.fstat(child_fd)
386
+ after = os.lstat(name, dir_fd=directory_fd)
387
+ if (opened.st_dev, opened.st_ino) != (entry.st_dev, entry.st_ino):
388
+ raise WebBuildError(f"scratch child changed during cleanup: {name}")
389
+ if (opened.st_dev, opened.st_ino) != (after.st_dev, after.st_ino):
390
+ raise WebBuildError(f"scratch child identity changed during cleanup: {name}")
391
+ remove_directory_contents(child_fd)
392
+ finally:
393
+ os.close(child_fd)
394
+ os.rmdir(name, dir_fd=directory_fd)
395
+ else:
396
+ os.unlink(name, dir_fd=directory_fd)
397
+
398
+
399
+ def remove_directory_contents(directory_fd):
400
+ scan_fd = os.open(".", _directory_open_flags(), dir_fd=directory_fd)
401
+ try:
402
+ names = os.listdir(scan_fd)
403
+ finally:
404
+ os.close(scan_fd)
405
+ for name in names:
406
+ remove_entry_at(directory_fd, name)
407
+
408
+
409
+ def cleanup_owned_scratch(parent, scratch):
410
+ if not scratch.owned:
411
+ raise WebBuildError("refuse to clean a scratch directory not owned by this invocation")
412
+ assert_verified_directory_handle(parent)
413
+ assert_verified_directory_handle(scratch)
414
+ scratch_name = scratch.path.name
415
+ try:
416
+ entry = os.lstat(scratch_name, dir_fd=parent.fd)
417
+ except FileNotFoundError as exc:
418
+ raise WebBuildError("owned scratch entry disappeared before cleanup") from exc
419
+ if stat.S_ISLNK(entry.st_mode) or not stat.S_ISDIR(entry.st_mode):
420
+ raise WebBuildError("owned scratch entry was replaced by a symlink or non-directory")
421
+ if (entry.st_dev, entry.st_ino) != (scratch.device, scratch.inode):
422
+ raise WebBuildError("owned scratch entry identity changed before cleanup")
423
+ try:
424
+ remove_directory_contents(scratch.fd)
425
+ after = os.lstat(scratch_name, dir_fd=parent.fd)
426
+ if (after.st_dev, after.st_ino) != (scratch.device, scratch.inode):
427
+ raise WebBuildError("owned scratch entry identity changed during cleanup")
428
+ os.rmdir(scratch_name, dir_fd=parent.fd)
429
+ finally:
430
+ os.close(scratch.fd)
431
+ scratch.fd = -1
432
+
433
+
434
+ def build(project_root, spid):
435
+ if not SPID_PATTERN.fullmatch(spid):
436
+ raise WebBuildError("spid must be 8 lowercase letters or digits")
437
+ version, host = read_package_settings(project_root)
438
+ source_root = project_root / "src"
439
+ validate_source(source_root)
440
+ original_cwd_fd = os.open(".", _directory_open_flags())
441
+ try:
442
+ directories = open_output_directories(project_root)
443
+ except Exception:
444
+ os.close(original_cwd_fd)
445
+ raise
446
+ scratch = None
447
+ try:
448
+ scratch = create_owned_scratch(directories.state)
449
+ os.fchdir(scratch.fd)
450
+ staged_dist = Path("dist")
451
+ staged_zip = Path("site-offline.zip")
452
+ render_dist(source_root, staged_dist, spid)
453
+ build_offline_zip(staged_dist, staged_zip, version)
454
+ assert_verified_directory_handle(scratch)
455
+ install_outputs(scratch, staged_dist, staged_zip, directories)
456
+ finally:
457
+ try:
458
+ os.fchdir(original_cwd_fd)
459
+ finally:
460
+ os.close(original_cwd_fd)
461
+ try:
462
+ if scratch is not None:
463
+ cleanup_owned_scratch(directories.state, scratch)
464
+ finally:
465
+ close_output_directories(directories)
466
+ return {
467
+ "dist": "dist",
468
+ "offlineArtifact": ".supersdk/artifacts/site-offline.zip",
469
+ "offlineHost": host,
470
+ "version": version,
471
+ }
472
+
473
+
474
+ def main(argv=None):
475
+ parser = argparse.ArgumentParser(description="Build the SuperSDK Simple Web project")
476
+ subcommands = parser.add_subparsers(dest="command", required=True)
477
+ build_command = subcommands.add_parser("build")
478
+ build_command.add_argument("--spid", required=True)
479
+ args = parser.parse_args(argv)
480
+ try:
481
+ result = build(Path(__file__).resolve().parent.parent, args.spid)
482
+ except (WebBuildError, OSError, shutil.Error) as exc:
483
+ print(f"web build failed: {exc}", file=sys.stderr)
484
+ return 1
485
+ print(json.dumps(result, sort_keys=True))
486
+ return 0
487
+
488
+
489
+ if __name__ == "__main__":
490
+ raise SystemExit(main())
@@ -2,7 +2,7 @@
2
2
  "use strict";
3
3
 
4
4
  // Package-root relative on purpose: the file is emitted into <project>/dist by
5
- // scripts/build_site.sh, so the same path resolves in the offline package, on a
5
+ // scripts/build.sh, so the same path resolves in the offline package, on a
6
6
  // published site, and on the local dev server.
7
7
  var CONFIG_PATH = "supersdk-config.json";
8
8
 
@@ -99,7 +99,7 @@
99
99
 
100
100
  function loadConfig() {
101
101
  if (!window.location || window.location.protocol === "file:") {
102
- return Promise.reject(new Error("Run scripts/build_site.sh then serve the built dist over the local HTTP server"));
102
+ return Promise.reject(new Error("Run scripts/build.sh then serve the built dist over the local HTTP server"));
103
103
  }
104
104
  var url = new URL(CONFIG_PATH, window.location.href).toString();
105
105
  return fetch(url).then(function(response) {
@@ -2,12 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.shellQuote = shellQuote;
4
4
  /**
5
- * `shlex.quote()` 的移植 —— 迁移提示 / 建议命令里出现的路径和取值必须能被**照抄进 shell
5
+ * POSIX `shlex.quote()` 语义的移植 —— 建议命令里出现的路径和取值必须能被**照抄进 shell
6
6
  * 直接执行**。
7
7
  *
8
8
  * 🔴 不能用 `JSON.stringify`:它产出的是双引号,shell 会在双引号里展开 `$VAR`、`` `cmd` ``、
9
- * `\`。路径里带 `$` 的目录(`/tmp/a$HOME b`)会被展开成完全不同的路径。Python 权威侧
10
- * (supersdk_template.py 的 migration_hint)用的就是 shlex.quote,这里与之对齐:
9
+ * `\`。路径里带 `$` 的目录(`/tmp/a$HOME b`)会被展开成完全不同的路径。这里采用通用
10
+ * shlex 规则:
11
11
  * 安全字符集直接原样输出,否则单引号包裹,内部单引号用 `'"'"'` 拼接。
12
12
  */
13
13
  const SHELL_SAFE = /^[A-Za-z0-9_@%+=:,./-]+$/;
@@ -41,18 +41,15 @@ exports.findDirConflict = findDirConflict;
41
41
  exports.relativeToRoot = relativeToRoot;
42
42
  exports.describeConfigProblem = describeConfigProblem;
43
43
  exports.loadWorkspace = loadWorkspace;
44
- exports.isValidConfigFile = isValidConfigFile;
45
- exports.legacyConfigIn = legacyConfigIn;
46
44
  exports.createWorkspaceConfig = createWorkspaceConfig;
47
45
  exports.appendProject = appendProject;
48
46
  exports.findEnclosingWorkspace = findEnclosingWorkspace;
49
- exports.legacyMigrationMessage = legacyMigrationMessage;
50
- // `super.json` schema v4 —— **工作空间写侧**(init / add / register)。
47
+ // `super.json` schema v5 —— **工作空间写侧**(init / add / register)。
51
48
  //
52
49
  // 一个 workspace = 一个 spid,`super.json` 所在目录即工作空间根。
53
50
  //
54
51
  // 🔴 这里**不再重写一遍校验**。读侧与写后自证都调用 `config/superConfig.ts`
55
- // 的 strict parser/discovery,与 Python authority 有字节级 parity 测试。
52
+ // 的 strict parser/discovery;不再存在第二套 Python schema authority。
56
53
  //
57
54
  // 本模块只补写侧真正独有的三件事:
58
55
  // 1. 一个**全项目**视角(parseConfig 的产物只暴露站点项目,登记新目录时要跟所有项目比对);
@@ -64,7 +61,6 @@ const node_crypto_1 = require("node:crypto");
64
61
  const appConfig_1 = require("../config/appConfig");
65
62
  const superConfig_1 = require("../config/superConfig");
66
63
  const fsAtomic_1 = require("../util/fsAtomic");
67
- const shell_1 = require("../util/shell");
68
64
  exports.CONFIG_FILENAME = appConfig_1.APP_CONFIG_FILENAME;
69
65
  exports.SCHEMA_VERSION = appConfig_1.APP_CONFIG_SCHEMA_VERSION;
70
66
  class WorkspaceConfigError extends Error {
@@ -178,27 +174,6 @@ function loadWorkspace(startDir, explicitPath) {
178
174
  // ---------------------------------------------------------------------------
179
175
  // 写
180
176
  // ---------------------------------------------------------------------------
181
- /**
182
- * 这个路径上是不是一份**发布侧也认**的合法配置。只回答是/否 —— 调用方(迁移提示)只需要
183
- * 知道「用户是不是已经有一份能用的配置了」,不需要诊断细节。
184
- */
185
- function isValidConfigFile(configPath) {
186
- try {
187
- return (0, superConfig_1.parseSuperConfig)(fs.readFileSync(configPath, 'utf8'), configPath).kind === 'valid';
188
- }
189
- catch {
190
- return false;
191
- }
192
- }
193
- /** 目录里是否残留退役的 YAML 方言配置。 */
194
- function legacyConfigIn(dir) {
195
- for (const name of appConfig_1.LEGACY_APP_CONFIG_FILENAMES) {
196
- const candidate = path.join(dir, name);
197
- if (fs.existsSync(candidate))
198
- return candidate;
199
- }
200
- return undefined;
201
- }
202
177
  /** 锁文件与配置同目录、以 `.` 开头 —— 与发布侧是同一把锁(同名文件即同一把锁)。 */
203
178
  function lockPathFor(configPath) {
204
179
  return path.join(path.dirname(configPath), `.${path.basename(configPath)}.lock`);
@@ -335,7 +310,7 @@ function findEnclosingWorkspace(target) {
335
310
  switch (found.kind) {
336
311
  case 'valid':
337
312
  return found.config.path;
338
- // 写坏的 v4 或 discovery chain 上的 legacy 配置一样会遮蔽。
313
+ // 写坏的 super.json 一样会遮蔽外层工作空间。
339
314
  case 'invalid':
340
315
  return found.path;
341
316
  case 'ambiguous':
@@ -349,55 +324,4 @@ function findEnclosingWorkspace(target) {
349
324
  }
350
325
  }
351
326
  }
352
- // ---------------------------------------------------------------------------
353
- // 退役 YAML 方言的迁移提示
354
- // ---------------------------------------------------------------------------
355
- /**
356
- * Fail-closed diagnostic for a retired YAML config. The snippet is meant to be
357
- * pasted into a shell verbatim — a migration hint that is missing even one
358
- * required field is a dead end, so the skeleton carries the complete set.
359
- *
360
- * 两种情形,动作顺序不同(且不能反):
361
- * - 目录里**已经有一份合法的 super.json** → 没有任何字段需要搬运,只发 `rm <legacy>`。
362
- * 再让人照抄一遍 `cat >` 会用占位值覆盖掉他已经写好的真配置。
363
- * - 没有 → 先写新文件、**再**删旧文件:旧文件是字段的唯一来源,先删就没得抄了。
364
- */
365
- function legacyMigrationMessage(yamlPath, jsonAlreadyValid = false) {
366
- const legacyName = path.basename(yamlPath);
367
- const dir = path.dirname(yamlPath);
368
- const head = [
369
- `${legacyName} is a retired configuration and is no longer read — supercli reads ` +
370
- `${exports.CONFIG_FILENAME} (schemaVersion ${exports.SCHEMA_VERSION}) only, and there is no compatibility fallback.`,
371
- `found: ${yamlPath}`,
372
- '',
373
- ];
374
- if (jsonAlreadyValid) {
375
- return [
376
- ...head,
377
- `your ${exports.CONFIG_FILENAME} is already in place — nothing to migrate, just delete the retired file:`,
378
- '',
379
- `cd ${(0, shell_1.shellQuote)(dir)}`,
380
- `rm ${(0, shell_1.shellQuote)(legacyName)}`,
381
- ].join('\n');
382
- }
383
- if (legacyName === 'supersdk.json') {
384
- return [
385
- ...head,
386
- 'Migrate schema v3 atomically; the source is retained and the target must not already exist:',
387
- '',
388
- `cd ${(0, shell_1.shellQuote)(dir)}`,
389
- `supercli config migrate --from ${(0, shell_1.shellQuote)(legacyName)} --to ${(0, shell_1.shellQuote)(exports.CONFIG_FILENAME)}`,
390
- ].join('\n');
391
- }
392
- return [
393
- ...head,
394
- 'Migrate it once — replace the placeholder values with the ones already in your YAML, then run:',
395
- '',
396
- `cd ${(0, shell_1.shellQuote)(dir)}`,
397
- `cat > ${(0, shell_1.shellQuote)(exports.CONFIG_FILENAME)} <<'SUPERSDK_JSON'`,
398
- (0, appConfig_1.appConfigSkeleton)(),
399
- 'SUPERSDK_JSON',
400
- `rm ${(0, shell_1.shellQuote)(legacyName)}`,
401
- ].join('\n');
402
- }
403
327
  //# sourceMappingURL=config.js.map