@playcraft/build 0.2.15-test-a → 0.2.16-test
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/dist/base-builder.js +2 -41
- package/dist/engines/engine-detector.js +0 -4
- package/dist/engines/generic-adapter.js +19 -14
- package/dist/engines/playable-scripts-adapter.js +5 -2
- package/dist/index.d.ts +4 -21
- package/dist/index.js +2 -12
- package/dist/platforms/adikteev.js +0 -1
- package/dist/platforms/applovin.js +0 -1
- package/dist/platforms/base.d.ts +0 -4
- package/dist/platforms/base.js +6 -25
- package/dist/platforms/bigo.js +0 -1
- package/dist/platforms/facebook.js +0 -1
- package/dist/platforms/google.js +0 -1
- package/dist/platforms/inmobi.js +0 -1
- package/dist/platforms/ironsource.js +0 -1
- package/dist/platforms/liftoff.js +0 -1
- package/dist/platforms/mintegral.js +0 -1
- package/dist/platforms/moloco.js +0 -1
- package/dist/platforms/playcraft.js +0 -1
- package/dist/platforms/remerge.js +0 -1
- package/dist/platforms/snapchat.js +0 -1
- package/dist/platforms/tiktok.js +0 -1
- package/dist/platforms/unity.js +0 -1
- package/dist/types.d.ts +2 -10
- package/dist/validation/html-validator.d.ts +0 -5
- package/dist/validation/html-validator.js +17 -19
- package/dist/validation/index.d.ts +0 -5
- package/dist/validation/index.js +0 -5
- package/dist/validation/package-validator.d.ts +0 -2
- package/dist/validation/package-validator.js +64 -25
- package/dist/validation/profiles.d.ts +1 -13
- package/dist/validation/profiles.js +0 -27
- package/dist/validation/source-scanner.d.ts +0 -11
- package/dist/validation/source-scanner.js +2 -32
- package/dist/validation/types.d.ts +2 -201
- package/dist/validation/types.js +1 -1
- package/dist/validation/validation-runner.d.ts +2 -22
- package/dist/validation/validation-runner.js +3 -64
- package/dist/validation/zip-reader.d.ts +0 -7
- package/dist/validation/zip-reader.js +26 -159
- package/dist/vite/config-builder-generic.d.ts +1 -3
- package/dist/vite/config-builder-generic.js +7 -9
- package/dist/vite/config-builder.js +1 -1
- package/dist/vite/plugin-platform.js +30 -16
- package/dist/vite/plugin-source-builder.d.ts +14 -2
- package/dist/vite/plugin-source-builder.js +997 -61
- package/dist/vite-builder.d.ts +5 -4
- package/dist/vite-builder.js +34 -33
- package/package.json +4 -30
- package/dist/audio-source-files.d.ts +0 -5
- package/dist/audio-source-files.js +0 -135
- package/dist/delivery/agent-build-runner.d.ts +0 -44
- package/dist/delivery/agent-build-runner.js +0 -365
- package/dist/delivery/agent-build-source.d.ts +0 -8
- package/dist/delivery/agent-build-source.js +0 -25
- package/dist/delivery/artifact-descriptor.d.ts +0 -31
- package/dist/delivery/artifact-descriptor.js +0 -237
- package/dist/delivery/artifact-package.d.ts +0 -43
- package/dist/delivery/artifact-package.js +0 -283
- package/dist/delivery/build-plan.d.ts +0 -4
- package/dist/delivery/build-plan.js +0 -189
- package/dist/delivery/build-plan.types.d.ts +0 -51
- package/dist/delivery/build-plan.types.js +0 -1
- package/dist/delivery/command-isolation.d.ts +0 -21
- package/dist/delivery/command-isolation.js +0 -327
- package/dist/delivery/commands.d.ts +0 -5
- package/dist/delivery/commands.js +0 -146
- package/dist/delivery/files.d.ts +0 -9
- package/dist/delivery/files.js +0 -144
- package/dist/delivery/git-source-fingerprint.d.ts +0 -2
- package/dist/delivery/git-source-fingerprint.js +0 -58
- package/dist/delivery/isolated-source.d.ts +0 -5
- package/dist/delivery/isolated-source.js +0 -131
- package/dist/delivery/output-publication.d.ts +0 -21
- package/dist/delivery/output-publication.js +0 -444
- package/dist/delivery/project-delivery.d.ts +0 -6
- package/dist/delivery/project-delivery.js +0 -287
- package/dist/delivery/recipe-build-plan.d.ts +0 -4
- package/dist/delivery/recipe-build-plan.js +0 -53
- package/dist/delivery/recipe.d.ts +0 -20
- package/dist/delivery/recipe.js +0 -211
- package/dist/delivery/safe-path.d.ts +0 -2
- package/dist/delivery/safe-path.js +0 -18
- package/dist/delivery/types.d.ts +0 -76
- package/dist/delivery/types.js +0 -1
- package/dist/production-animation-presence.d.ts +0 -2
- package/dist/production-animation-presence.js +0 -146
- package/dist/production-inputs.d.ts +0 -30
- package/dist/production-inputs.js +0 -262
- package/dist/production-source-paths.d.ts +0 -5
- package/dist/production-source-paths.js +0 -27
- package/dist/redirect-policy.d.ts +0 -23
- package/dist/redirect-policy.js +0 -25
- package/dist/validation/artifact-qa.d.ts +0 -36
- package/dist/validation/artifact-qa.js +0 -263
- package/dist/validation/artifact-rules.d.ts +0 -39
- package/dist/validation/artifact-rules.js +0 -451
- package/dist/validation/artifact.d.ts +0 -14
- package/dist/validation/artifact.js +0 -188
- package/dist/validation/playwright-driver.d.ts +0 -37
- package/dist/validation/playwright-driver.js +0 -302
- package/dist/validation/runtime-cover.d.ts +0 -32
- package/dist/validation/runtime-cover.js +0 -120
- package/dist/validation/runtime-load.d.ts +0 -141
- package/dist/validation/runtime-load.js +0 -812
- package/dist/vite/source-builder-asset-paths.d.ts +0 -25
- package/dist/vite/source-builder-asset-paths.js +0 -154
- package/dist/vite/source-builder-esm.d.ts +0 -7
- package/dist/vite/source-builder-esm.js +0 -877
- package/dist/vite/source-builder-types.d.ts +0 -14
- package/dist/vite/source-builder-types.js +0 -1
- package/dist/vite/workspace.d.ts +0 -6
- package/dist/vite/workspace.js +0 -41
- package/dist/workspace-css-imports.d.ts +0 -2
- package/dist/workspace-css-imports.js +0 -139
- package/dist/workspace-model-source.d.ts +0 -14
- package/dist/workspace-model-source.js +0 -184
- package/dist/workspace-public-imports.d.ts +0 -11
- package/dist/workspace-public-imports.js +0 -232
- package/dist/workspace-public-source.d.ts +0 -15
- package/dist/workspace-public-source.js +0 -564
- package/templates/patches/playcraft-redirect-policy.js +0 -115
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
import { constants } from 'node:fs';
|
|
2
|
-
import { access, lstat, realpath, stat } from 'node:fs/promises';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { ProjectDeliveryError } from './recipe.js';
|
|
5
|
-
const SYSTEM_PATHS = [
|
|
6
|
-
'/bin',
|
|
7
|
-
'/usr/bin',
|
|
8
|
-
'/usr/lib',
|
|
9
|
-
'/usr/lib64',
|
|
10
|
-
'/usr/libexec',
|
|
11
|
-
'/lib',
|
|
12
|
-
'/lib64',
|
|
13
|
-
'/usr/local/bin',
|
|
14
|
-
'/usr/local/lib',
|
|
15
|
-
'/usr/share/nodejs',
|
|
16
|
-
'/etc/ld.so.cache',
|
|
17
|
-
'/etc/localtime',
|
|
18
|
-
'/etc/nsswitch.conf',
|
|
19
|
-
'/etc/passwd',
|
|
20
|
-
'/etc/group',
|
|
21
|
-
'/etc/ssl/openssl.cnf',
|
|
22
|
-
'/etc/crypto-policies/back-ends/opensslcnf.config',
|
|
23
|
-
'/dev/null',
|
|
24
|
-
'/dev/zero',
|
|
25
|
-
'/dev/random',
|
|
26
|
-
'/dev/urandom',
|
|
27
|
-
];
|
|
28
|
-
const MAC_SYSTEM_PATHS = [
|
|
29
|
-
'/System/Library',
|
|
30
|
-
'/System/Volumes/Preboot/Cryptexes/OS/System/Library',
|
|
31
|
-
'/System/Volumes/Preboot/Cryptexes/OS/usr/lib',
|
|
32
|
-
'/Library/Apple/System/Library',
|
|
33
|
-
'/Library/Developer/CommandLineTools',
|
|
34
|
-
'/Applications/Xcode.app/Contents/Developer',
|
|
35
|
-
'/private/var/db/dyld',
|
|
36
|
-
'/opt/homebrew/bin',
|
|
37
|
-
'/opt/homebrew/lib',
|
|
38
|
-
'/opt/homebrew/opt',
|
|
39
|
-
'/opt/homebrew/Cellar',
|
|
40
|
-
'/opt/homebrew/share',
|
|
41
|
-
'/opt/homebrew/etc/openssl@3/openssl.cnf',
|
|
42
|
-
'/usr/local/Cellar',
|
|
43
|
-
'/usr/local/opt',
|
|
44
|
-
'/usr/local/share',
|
|
45
|
-
'/usr/local/etc/openssl@3/openssl.cnf',
|
|
46
|
-
];
|
|
47
|
-
function inside(root, candidate) {
|
|
48
|
-
return candidate === root || candidate.startsWith(`${root}${path.sep}`);
|
|
49
|
-
}
|
|
50
|
-
function failure(message) {
|
|
51
|
-
throw new ProjectDeliveryError('delivery_isolation_unavailable', message);
|
|
52
|
-
}
|
|
53
|
-
async function allowedPath(value, optional = false) {
|
|
54
|
-
try {
|
|
55
|
-
const canonical = await realpath(value);
|
|
56
|
-
const info = await stat(canonical, { bigint: true });
|
|
57
|
-
if (!info.isDirectory() && !info.isFile() && !info.isCharacterDevice())
|
|
58
|
-
failure('An isolation allowance has an unsupported file type');
|
|
59
|
-
return {
|
|
60
|
-
path: canonical,
|
|
61
|
-
directory: info.isDirectory(),
|
|
62
|
-
dev: info.dev.toString(),
|
|
63
|
-
ino: info.ino.toString(),
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
if (optional && error.code === 'ENOENT')
|
|
68
|
-
return undefined;
|
|
69
|
-
if (error instanceof ProjectDeliveryError)
|
|
70
|
-
throw error;
|
|
71
|
-
failure('An isolation allowance could not be verified');
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
async function executable(value) {
|
|
75
|
-
try {
|
|
76
|
-
await access(value, constants.X_OK);
|
|
77
|
-
if (!(await stat(value)).isFile())
|
|
78
|
-
failure('The isolation launcher is not a file');
|
|
79
|
-
}
|
|
80
|
-
catch {
|
|
81
|
-
failure('The required operating-system isolation launcher is unavailable');
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
// Kernel user API: https://docs.kernel.org/userspace-api/landlock.html .
|
|
85
|
-
// ABI (Application Binary Interface, 应用二进制接口) 3 is required: both
|
|
86
|
-
// cross-directory REFER and TRUNCATE must be handled. A kernel without that ABI
|
|
87
|
-
// (for example a guest kernel built without Landlock) uses the same allowance
|
|
88
|
-
// list through Bubblewrap mount namespaces; without either, nothing executes.
|
|
89
|
-
// The packed path-beneath structure and syscall numbers come from Linux's
|
|
90
|
-
// include/uapi/linux/landlock.h and x86/asm-generic syscall tables.
|
|
91
|
-
const LANDLOCK_LAUNCHER = String.raw `
|
|
92
|
-
import ctypes, json, os, platform, resource, stat, sys
|
|
93
|
-
|
|
94
|
-
BUBBLEWRAP = "/usr/bin/bwrap"
|
|
95
|
-
|
|
96
|
-
def fail(reason):
|
|
97
|
-
sys.stderr.write("delivery_isolation_unavailable:" + reason + "\n")
|
|
98
|
-
sys.exit(125)
|
|
99
|
-
|
|
100
|
-
def verified(item):
|
|
101
|
-
if os.path.realpath(item["path"]) != item["path"]:
|
|
102
|
-
fail("allowance_changed")
|
|
103
|
-
fd = os.open(item["path"], os.O_PATH | os.O_CLOEXEC | os.O_NOFOLLOW)
|
|
104
|
-
info = os.fstat(fd)
|
|
105
|
-
if str(info.st_dev) != item["dev"] or str(info.st_ino) != item["ino"]:
|
|
106
|
-
fail("allowance_changed")
|
|
107
|
-
return fd, info
|
|
108
|
-
|
|
109
|
-
def launch_bubblewrap(policy, command):
|
|
110
|
-
arguments = policy.get("bwrap")
|
|
111
|
-
if not arguments:
|
|
112
|
-
fail("landlock_abi_3_required")
|
|
113
|
-
try:
|
|
114
|
-
info = os.stat(BUBBLEWRAP)
|
|
115
|
-
except OSError:
|
|
116
|
-
fail("landlock_abi_3_required_and_bubblewrap_missing")
|
|
117
|
-
# Never a project-controlled or user-writable launcher.
|
|
118
|
-
if not stat.S_ISREG(info.st_mode) or info.st_uid != 0 or info.st_mode & 0o022 or not os.access(BUBBLEWRAP, os.X_OK):
|
|
119
|
-
fail("bubblewrap_untrusted")
|
|
120
|
-
for item in policy["read"]:
|
|
121
|
-
os.close(verified(item)[0])
|
|
122
|
-
os.environ["TMPDIR"] = policy["temporary"]
|
|
123
|
-
os.environ["TMP"] = policy["temporary"]
|
|
124
|
-
os.environ["TEMP"] = policy["temporary"]
|
|
125
|
-
try:
|
|
126
|
-
os.execv(BUBBLEWRAP, [BUBBLEWRAP] + arguments + ["--"] + command)
|
|
127
|
-
except OSError:
|
|
128
|
-
fail("bubblewrap_exec_failed")
|
|
129
|
-
|
|
130
|
-
try:
|
|
131
|
-
if sys.platform != "linux" or platform.machine() not in ("x86_64", "aarch64", "riscv64"):
|
|
132
|
-
fail("unsupported_landlock_architecture")
|
|
133
|
-
policy = json.loads(sys.argv[1])
|
|
134
|
-
command = sys.argv[2:]
|
|
135
|
-
if not command:
|
|
136
|
-
fail("missing_command")
|
|
137
|
-
# Landlock does not revoke already-open descriptors. Preserve only managed
|
|
138
|
-
# stdio, never an inherited directory/file handle into the original tree.
|
|
139
|
-
ceiling = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
|
|
140
|
-
if ceiling == resource.RLIM_INFINITY:
|
|
141
|
-
ceiling = os.sysconf("SC_OPEN_MAX")
|
|
142
|
-
os.closerange(3, ceiling)
|
|
143
|
-
libc = ctypes.CDLL(None, use_errno=True)
|
|
144
|
-
libc.syscall.restype = ctypes.c_long
|
|
145
|
-
abi = libc.syscall(444, ctypes.c_void_p(), ctypes.c_size_t(0), ctypes.c_uint(1))
|
|
146
|
-
if abi < 3:
|
|
147
|
-
launch_bubblewrap(policy, command)
|
|
148
|
-
handled = (1 << 15) - 1
|
|
149
|
-
if abi >= 5:
|
|
150
|
-
handled |= 1 << 15
|
|
151
|
-
if abi >= 9:
|
|
152
|
-
handled |= 1 << 16
|
|
153
|
-
class Ruleset(ctypes.Structure):
|
|
154
|
-
_fields_ = [("handled_access_fs", ctypes.c_uint64)]
|
|
155
|
-
class Beneath(ctypes.Structure):
|
|
156
|
-
_pack_ = 1
|
|
157
|
-
_fields_ = [("allowed_access", ctypes.c_uint64), ("parent_fd", ctypes.c_int32)]
|
|
158
|
-
attr = Ruleset(handled)
|
|
159
|
-
ruleset = libc.syscall(444, ctypes.byref(attr), ctypes.sizeof(attr), 0)
|
|
160
|
-
if ruleset < 0:
|
|
161
|
-
fail("landlock_ruleset_failed")
|
|
162
|
-
read = (1 << 0) | (1 << 2) | (1 << 3)
|
|
163
|
-
write = (1 << 1) | (1 << 4) | (1 << 5) | (1 << 7) | (1 << 8) | (1 << 9) | (1 << 10) | (1 << 12) | (1 << 13) | (1 << 14)
|
|
164
|
-
file_rights = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 14) | (1 << 15)
|
|
165
|
-
for item in policy["read"]:
|
|
166
|
-
fd, info = verified(item)
|
|
167
|
-
rights = read
|
|
168
|
-
if item["path"] in policy["write"]:
|
|
169
|
-
rights |= write
|
|
170
|
-
if not stat.S_ISDIR(info.st_mode):
|
|
171
|
-
rights &= file_rights
|
|
172
|
-
rule = Beneath(rights & handled, fd)
|
|
173
|
-
result = libc.syscall(445, ruleset, 1, ctypes.byref(rule), 0)
|
|
174
|
-
os.close(fd)
|
|
175
|
-
if result != 0:
|
|
176
|
-
fail("landlock_rule_failed")
|
|
177
|
-
# A fresh, single-threaded launcher applies policy before exec; all future
|
|
178
|
-
# threads/children inherit it. Do not spawn an untracked second executor.
|
|
179
|
-
if libc.prctl(38, 1, 0, 0, 0) != 0:
|
|
180
|
-
fail("no_new_privs_failed")
|
|
181
|
-
if libc.syscall(446, ruleset, 0) != 0:
|
|
182
|
-
fail("landlock_restrict_failed")
|
|
183
|
-
os.close(ruleset)
|
|
184
|
-
os.environ["TMPDIR"] = policy["temporary"]
|
|
185
|
-
os.environ["TMP"] = policy["temporary"]
|
|
186
|
-
os.environ["TEMP"] = policy["temporary"]
|
|
187
|
-
os.execvpe(command[0], command, os.environ)
|
|
188
|
-
except Exception:
|
|
189
|
-
fail("landlock_setup_or_exec_failed")
|
|
190
|
-
`;
|
|
191
|
-
/**
|
|
192
|
-
* Mount-namespace view equivalent to the Landlock rules: only allowances exist,
|
|
193
|
-
* read-only except the snapshot; /dev is the minimal device set and /proc only
|
|
194
|
-
* shows the new PID namespace. The network stays shared, as with Landlock.
|
|
195
|
-
*/
|
|
196
|
-
export function bubblewrapArguments(read, isolated, links) {
|
|
197
|
-
const view = [
|
|
198
|
-
'--unshare-user',
|
|
199
|
-
'--unshare-pid',
|
|
200
|
-
'--unshare-ipc',
|
|
201
|
-
'--unshare-uts',
|
|
202
|
-
'--unshare-cgroup-try',
|
|
203
|
-
'--die-with-parent',
|
|
204
|
-
'--new-session',
|
|
205
|
-
'--cap-drop',
|
|
206
|
-
'ALL',
|
|
207
|
-
'--dev',
|
|
208
|
-
'/dev',
|
|
209
|
-
'--proc',
|
|
210
|
-
'/proc',
|
|
211
|
-
];
|
|
212
|
-
for (const item of read) {
|
|
213
|
-
if (item.path === isolated || item.path === '/dev' || item.path.startsWith('/dev/'))
|
|
214
|
-
continue;
|
|
215
|
-
view.push('--ro-bind', item.path, item.path);
|
|
216
|
-
}
|
|
217
|
-
view.push('--bind', isolated, isolated);
|
|
218
|
-
for (const [alias, target] of links)
|
|
219
|
-
view.push('--symlink', target, alias);
|
|
220
|
-
// The bwrap root is a private tmpfs; keep it unwritable so only the snapshot accepts writes.
|
|
221
|
-
view.push('--remount-ro', '/');
|
|
222
|
-
return view;
|
|
223
|
-
}
|
|
224
|
-
/** Construct argv for the existing managed launcher; never execute or fall back here. */
|
|
225
|
-
export async function wrapDeliveryCommand(argv, options) {
|
|
226
|
-
if (!argv[0] || argv.some((value) => value.includes('\0')))
|
|
227
|
-
failure('The isolated command is invalid');
|
|
228
|
-
if (process.platform !== 'darwin' && process.platform !== 'linux')
|
|
229
|
-
failure('Delivery file isolation is unsupported on this operating system');
|
|
230
|
-
// Loader injection would execute before Python/Seatbelt establishes policy.
|
|
231
|
-
if (['LD_PRELOAD', 'LD_AUDIT', 'DYLD_INSERT_LIBRARIES', 'DYLD_LIBRARY_PATH'].some((key) => process.env[key]))
|
|
232
|
-
failure('Inherited loader injection is incompatible with delivery file isolation');
|
|
233
|
-
const project = await allowedPath(options.projectRoot);
|
|
234
|
-
const isolated = await allowedPath(options.isolatedRoot);
|
|
235
|
-
if (!project?.directory || !isolated?.directory || inside(isolated.path, project.path))
|
|
236
|
-
failure('The snapshot must be a separate directory from its source');
|
|
237
|
-
const temporary = options.temporaryRoot === undefined ? isolated : await allowedPath(options.temporaryRoot);
|
|
238
|
-
if (!temporary?.directory || !inside(isolated.path, temporary.path))
|
|
239
|
-
failure('The temporary directory must be inside the snapshot');
|
|
240
|
-
const dependencies = [];
|
|
241
|
-
for (const candidate of options.dependencyRoots ?? []) {
|
|
242
|
-
if (path.basename(path.resolve(candidate)) !== 'node_modules')
|
|
243
|
-
failure('Only a genuine node_modules directory can be a dependency allowance');
|
|
244
|
-
const info = await lstat(candidate).catch(() => undefined);
|
|
245
|
-
if (!info?.isDirectory() || info.isSymbolicLink())
|
|
246
|
-
failure('Dependency allowances must be real directories');
|
|
247
|
-
const dependency = await allowedPath(candidate);
|
|
248
|
-
if (!dependency?.directory ||
|
|
249
|
-
inside(dependency.path, project.path) ||
|
|
250
|
-
inside(dependency.path, isolated.path) ||
|
|
251
|
-
inside(isolated.path, dependency.path))
|
|
252
|
-
failure('Dependency allowances cannot expose the source or snapshot parent');
|
|
253
|
-
dependencies.push(dependency);
|
|
254
|
-
}
|
|
255
|
-
const roots = new Map();
|
|
256
|
-
for (const value of [isolated, ...dependencies])
|
|
257
|
-
roots.set(value.path, value);
|
|
258
|
-
const node = await allowedPath(process.execPath);
|
|
259
|
-
const nodePrefix = node ? path.dirname(path.dirname(node.path)) : undefined;
|
|
260
|
-
const candidates = [
|
|
261
|
-
...SYSTEM_PATHS,
|
|
262
|
-
...(process.platform === 'darwin' ? MAC_SYSTEM_PATHS : []),
|
|
263
|
-
process.execPath,
|
|
264
|
-
// Accommodate a versioned Node installation without admitting its home directory.
|
|
265
|
-
...(nodePrefix ? [path.join(nodePrefix, 'bin'), path.join(nodePrefix, 'lib')] : []),
|
|
266
|
-
];
|
|
267
|
-
// Merged-/usr aliases such as /bin -> /usr/bin; a mount view must recreate them.
|
|
268
|
-
const links = new Map();
|
|
269
|
-
for (const candidate of candidates) {
|
|
270
|
-
const item = await allowedPath(candidate, true);
|
|
271
|
-
if (!item)
|
|
272
|
-
continue;
|
|
273
|
-
if (inside(item.path, project.path) || inside(project.path, item.path))
|
|
274
|
-
failure('A system toolchain allowance overlaps the original project');
|
|
275
|
-
if (inside(item.path, isolated.path))
|
|
276
|
-
failure('A system toolchain allowance contains the snapshot');
|
|
277
|
-
roots.set(item.path, item);
|
|
278
|
-
const alias = path.resolve(candidate);
|
|
279
|
-
if (alias !== item.path)
|
|
280
|
-
links.set(alias, item.path);
|
|
281
|
-
}
|
|
282
|
-
const read = [...roots.values()];
|
|
283
|
-
const write = [isolated.path, (await realpath('/dev/null'))];
|
|
284
|
-
if (process.platform === 'darwin') {
|
|
285
|
-
await executable('/usr/bin/sandbox-exec');
|
|
286
|
-
const filter = (item) => `(${item.directory ? 'subpath' : 'literal'} ${JSON.stringify(item.path)})`;
|
|
287
|
-
const readable = read.map(filter).join(' ');
|
|
288
|
-
const profile = [
|
|
289
|
-
'(version 1)',
|
|
290
|
-
'(allow default)',
|
|
291
|
-
// Metadata remains visible, as with Landlock. New dyld/libignition also
|
|
292
|
-
// opens / as a directory anchor; literal / grants no descendant access.
|
|
293
|
-
// Deny actions take precedence over allow actions in Seatbelt, so encode
|
|
294
|
-
// the exceptions in the deny predicate rather than an overriding allow.
|
|
295
|
-
`(deny file-read-data (require-not (require-any (literal "/") ${readable})))`,
|
|
296
|
-
`(deny file-read-xattr (require-not (require-any ${readable})))`,
|
|
297
|
-
`(deny file-write* (require-not (require-any (subpath ${JSON.stringify(isolated.path)}) (literal "/dev/null"))))`,
|
|
298
|
-
].join('\n');
|
|
299
|
-
// env is itself sandboxed; it only confines tool temporary files to the snapshot.
|
|
300
|
-
return [
|
|
301
|
-
'/usr/bin/sandbox-exec',
|
|
302
|
-
'-p',
|
|
303
|
-
profile,
|
|
304
|
-
'/usr/bin/env',
|
|
305
|
-
`TMPDIR=${temporary.path}`,
|
|
306
|
-
`TMP=${temporary.path}`,
|
|
307
|
-
`TEMP=${temporary.path}`,
|
|
308
|
-
...argv,
|
|
309
|
-
];
|
|
310
|
-
}
|
|
311
|
-
// Use the OS interpreter, never a project-controlled PATH shim or PYTHONPATH.
|
|
312
|
-
await executable('/usr/bin/python3');
|
|
313
|
-
return [
|
|
314
|
-
'/usr/bin/python3',
|
|
315
|
-
'-I',
|
|
316
|
-
'-S',
|
|
317
|
-
'-c',
|
|
318
|
-
LANDLOCK_LAUNCHER,
|
|
319
|
-
JSON.stringify({
|
|
320
|
-
read,
|
|
321
|
-
write,
|
|
322
|
-
temporary: temporary.path,
|
|
323
|
-
bwrap: bubblewrapArguments(read, isolated.path, links),
|
|
324
|
-
}),
|
|
325
|
-
...argv,
|
|
326
|
-
];
|
|
327
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { DeliveryCommand, ProjectDeliveryOptions } from './types.js';
|
|
2
|
-
import { wrapDeliveryCommand } from './command-isolation.js';
|
|
3
|
-
export type DeliveryCommandIsolation = Parameters<typeof wrapDeliveryCommand>[1];
|
|
4
|
-
export declare function requireExecutable(root: string, executable: string, cwd: string, options: ProjectDeliveryOptions, isolation?: DeliveryCommandIsolation): Promise<string>;
|
|
5
|
-
export declare function runDeliveryCommand(root: string, command: DeliveryCommand, replace: (value: string) => string, options: ProjectDeliveryOptions, isolation?: DeliveryCommandIsolation): Promise<void>;
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { constants } from 'node:fs';
|
|
2
|
-
import { access, stat } from 'node:fs/promises';
|
|
3
|
-
import { spawn } from 'node:child_process';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import { ProjectDeliveryError } from './recipe.js';
|
|
6
|
-
import { safeExistingPath } from './safe-path.js';
|
|
7
|
-
import { wrapDeliveryCommand } from './command-isolation.js';
|
|
8
|
-
function isolationUnavailable(code, output) {
|
|
9
|
-
return code === 125 && output.includes('delivery_isolation_unavailable:') ||
|
|
10
|
-
// Bubblewrap reports its own setup failures as "bwrap: ..." with exit 1.
|
|
11
|
-
code === 1 && /(?:^|\n)bwrap: /.test(output) ||
|
|
12
|
-
/sandbox-exec:.*(?:sandbox_(?:init|apply)|Operation not permitted)/i.test(output);
|
|
13
|
-
}
|
|
14
|
-
/** Keep the launcher's concrete reason so a blocked preparation can be diagnosed. */
|
|
15
|
-
function isolationError(output) {
|
|
16
|
-
const reason = /delivery_isolation_unavailable:(\w{1,80})/.exec(output)?.[1] ??
|
|
17
|
-
/(?:^|\n)bwrap: ([^\n]{1,200})/.exec(output)?.[1]?.replace(/^/, 'bubblewrap: ') ??
|
|
18
|
-
/sandbox-exec: ([^\n]{1,200})/.exec(output)?.[1]?.replace(/^/, 'sandbox-exec: ');
|
|
19
|
-
return new ProjectDeliveryError('delivery_isolation_unavailable', `The operating system could not enforce delivery file isolation${reason ? ` (${reason})` : ''}`);
|
|
20
|
-
}
|
|
21
|
-
export async function requireExecutable(root, executable, cwd, options, isolation) {
|
|
22
|
-
if (options.runCommand) {
|
|
23
|
-
const checkArgv = [
|
|
24
|
-
'/bin/sh',
|
|
25
|
-
'-c',
|
|
26
|
-
'case "$1" in */*) test -f "$1" && test -x "$1" ;; *) command -v "$1" >/dev/null 2>&1 ;; esac',
|
|
27
|
-
'delivery-toolchain',
|
|
28
|
-
executable,
|
|
29
|
-
];
|
|
30
|
-
const check = await options.runCommand({
|
|
31
|
-
argv: isolation ? await wrapDeliveryCommand(checkArgv, isolation) : checkArgv,
|
|
32
|
-
cwd,
|
|
33
|
-
timeoutMs: 10000,
|
|
34
|
-
});
|
|
35
|
-
if (isolation && isolationUnavailable(check.code, `${check.stderr ?? ''}${check.stdout ?? ''}`))
|
|
36
|
-
throw isolationError(`${check.stderr ?? ''}${check.stdout ?? ''}`);
|
|
37
|
-
if (check.code !== 0 || check.canceled || check.timedOut)
|
|
38
|
-
throw new ProjectDeliveryError('delivery_toolchain_missing', `Required executable is unavailable: ${executable}`);
|
|
39
|
-
return executable;
|
|
40
|
-
}
|
|
41
|
-
const search = executable.includes('/') || executable.includes('\\')
|
|
42
|
-
? [path.resolve(cwd, executable)]
|
|
43
|
-
: [
|
|
44
|
-
path.join(cwd, 'node_modules', '.bin', executable),
|
|
45
|
-
path.join(root, 'node_modules', '.bin', executable),
|
|
46
|
-
...(process.env.PATH ?? '')
|
|
47
|
-
.split(path.delimiter)
|
|
48
|
-
.map((directory) => path.join(directory, executable)),
|
|
49
|
-
];
|
|
50
|
-
for (const candidate of search) {
|
|
51
|
-
try {
|
|
52
|
-
await access(candidate, process.platform === 'win32' ? constants.F_OK : constants.X_OK);
|
|
53
|
-
if ((await stat(candidate)).isFile())
|
|
54
|
-
return candidate;
|
|
55
|
-
}
|
|
56
|
-
catch {
|
|
57
|
-
/* Check the next PATH entry. */
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
throw new ProjectDeliveryError('delivery_toolchain_missing', `Required executable is unavailable: ${executable}`);
|
|
61
|
-
}
|
|
62
|
-
export async function runDeliveryCommand(root, command, replace, options, isolation) {
|
|
63
|
-
if (options.signal?.aborted)
|
|
64
|
-
throw new ProjectDeliveryError('delivery_canceled', 'Delivery preparation was canceled');
|
|
65
|
-
const cwd = await safeExistingPath(root, replace(command.cwd ?? '.'));
|
|
66
|
-
const argv = command.argv.map(replace);
|
|
67
|
-
const executable = await requireExecutable(root, argv[0], cwd, options, isolation);
|
|
68
|
-
const isolatedArgv = isolation
|
|
69
|
-
? await wrapDeliveryCommand([executable, ...argv.slice(1)], isolation)
|
|
70
|
-
: undefined;
|
|
71
|
-
const timeoutMs = command.timeoutMs ?? 300000;
|
|
72
|
-
if (options.runCommand) {
|
|
73
|
-
const result = await options.runCommand({ argv: isolatedArgv ?? argv, cwd, timeoutMs });
|
|
74
|
-
if (isolation && isolationUnavailable(result.code, `${result.stderr ?? ''}${result.stdout ?? ''}`))
|
|
75
|
-
throw isolationError(`${result.stderr ?? ''}${result.stdout ?? ''}`);
|
|
76
|
-
if (result.canceled || options.signal?.aborted)
|
|
77
|
-
throw new ProjectDeliveryError('delivery_canceled', 'Delivery preparation was canceled');
|
|
78
|
-
if (result.timedOut)
|
|
79
|
-
throw new ProjectDeliveryError('delivery_command_timeout', `Delivery command exceeded ${timeoutMs}ms`);
|
|
80
|
-
if (result.code !== 0)
|
|
81
|
-
throw new ProjectDeliveryError('delivery_command_failed', `Delivery command exited with ${result.code}: ${(result.stderr || result.stdout || '').slice(-4000)}`);
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
await new Promise((resolve, reject) => {
|
|
85
|
-
let tail = '';
|
|
86
|
-
let timedOut = false;
|
|
87
|
-
const child = spawn(isolatedArgv?.[0] ?? executable, isolatedArgv?.slice(1) ?? argv.slice(1), {
|
|
88
|
-
cwd,
|
|
89
|
-
shell: false,
|
|
90
|
-
detached: process.platform !== 'win32',
|
|
91
|
-
env: {
|
|
92
|
-
...process.env,
|
|
93
|
-
CI: 'true',
|
|
94
|
-
PLAYCRAFT_DELIVERY_EXECUTING: '1',
|
|
95
|
-
PATH: [
|
|
96
|
-
path.join(cwd, 'node_modules', '.bin'),
|
|
97
|
-
path.join(root, 'node_modules', '.bin'),
|
|
98
|
-
process.env.PATH ?? '',
|
|
99
|
-
].join(path.delimiter),
|
|
100
|
-
},
|
|
101
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
102
|
-
});
|
|
103
|
-
const stop = () => {
|
|
104
|
-
try {
|
|
105
|
-
if (process.platform !== 'win32' && child.pid)
|
|
106
|
-
process.kill(-child.pid, 'SIGTERM');
|
|
107
|
-
else
|
|
108
|
-
child.kill('SIGTERM');
|
|
109
|
-
}
|
|
110
|
-
catch {
|
|
111
|
-
/* The command may already have exited. */
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
const timer = setTimeout(() => {
|
|
115
|
-
timedOut = true;
|
|
116
|
-
stop();
|
|
117
|
-
}, timeoutMs);
|
|
118
|
-
options.signal?.addEventListener('abort', stop, { once: true });
|
|
119
|
-
const collect = (chunk) => {
|
|
120
|
-
tail = (tail + chunk.toString()).slice(-4000);
|
|
121
|
-
};
|
|
122
|
-
child.stdout?.on('data', collect);
|
|
123
|
-
child.stderr?.on('data', collect);
|
|
124
|
-
const cleanup = () => {
|
|
125
|
-
clearTimeout(timer);
|
|
126
|
-
options.signal?.removeEventListener('abort', stop);
|
|
127
|
-
};
|
|
128
|
-
child.once('error', (error) => {
|
|
129
|
-
cleanup();
|
|
130
|
-
reject(new ProjectDeliveryError('delivery_command_failed', error.message));
|
|
131
|
-
});
|
|
132
|
-
child.once('close', (code) => {
|
|
133
|
-
cleanup();
|
|
134
|
-
if (options.signal?.aborted)
|
|
135
|
-
reject(new ProjectDeliveryError('delivery_canceled', 'Delivery preparation was canceled'));
|
|
136
|
-
else if (timedOut)
|
|
137
|
-
reject(new ProjectDeliveryError('delivery_command_timeout', `Delivery command exceeded ${timeoutMs}ms`));
|
|
138
|
-
else if (isolation && isolationUnavailable(code, tail))
|
|
139
|
-
reject(isolationError(tail));
|
|
140
|
-
else if (code !== 0)
|
|
141
|
-
reject(new ProjectDeliveryError('delivery_command_failed', `Delivery command exited with ${code}: ${tail}`));
|
|
142
|
-
else
|
|
143
|
-
resolve();
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
}
|
package/dist/delivery/files.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export declare function inside(root: string, target: string): boolean;
|
|
2
|
-
export declare function safeExistingPath(root: string, relative: string): Promise<string>;
|
|
3
|
-
export declare function checkOutputDirectory(root: string, directory: string): Promise<void>;
|
|
4
|
-
/** Hash content and relative names, never mtime or Git HEAD, so receipts survive a clean clone. */
|
|
5
|
-
export declare function deliverySourceFingerprint(root: string, outputDirectory: string, receiptPath?: string, generatedDirectories?: readonly string[]): Promise<string>;
|
|
6
|
-
/** Versioned projects use the same exact source set as save, batch capture and a clean Worker checkout. */
|
|
7
|
-
export declare function deliveryProductionSourceSnapshot(root: string, outputDirectory: string, receiptPath?: string, generatedDirectories?: readonly string[]): Promise<import("../production-inputs.js").ProductionSourceSnapshot | undefined>;
|
|
8
|
-
export declare function outputFingerprint(root: string, directory: string, entry: string): Promise<string>;
|
|
9
|
-
export declare function entryRevision(root: string, directory: string, entry: string): Promise<string | undefined>;
|
package/dist/delivery/files.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
|
-
import { lstat, readFile, readdir, realpath } from 'node:fs/promises';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { unzipSync } from 'fflate';
|
|
5
|
-
import { ProjectDeliveryError } from './recipe.js';
|
|
6
|
-
import { readProductionSourceSnapshot, ProductionSourceError } from '../production-inputs.js';
|
|
7
|
-
import { deliveryGitSourceFingerprint } from './git-source-fingerprint.js';
|
|
8
|
-
export function inside(root, target) {
|
|
9
|
-
const relative = path.relative(root, target);
|
|
10
|
-
return (relative === '' ||
|
|
11
|
-
(!relative.startsWith(`..${path.sep}`) && relative !== '..' && !path.isAbsolute(relative)));
|
|
12
|
-
}
|
|
13
|
-
export async function safeExistingPath(root, relative) {
|
|
14
|
-
const base = await realpath(root);
|
|
15
|
-
const target = await realpath(path.resolve(root, relative)).catch(() => {
|
|
16
|
-
throw new ProjectDeliveryError('delivery_path_missing', `Required delivery path is missing: ${relative}`, relative);
|
|
17
|
-
});
|
|
18
|
-
if (!inside(base, target))
|
|
19
|
-
throw new ProjectDeliveryError('delivery_path_outside_project', 'Delivery paths must stay inside the project', relative);
|
|
20
|
-
return target;
|
|
21
|
-
}
|
|
22
|
-
export async function checkOutputDirectory(root, directory) {
|
|
23
|
-
const base = await realpath(root);
|
|
24
|
-
let candidate = path.resolve(root, directory);
|
|
25
|
-
while (candidate !== path.dirname(candidate)) {
|
|
26
|
-
try {
|
|
27
|
-
const resolved = await realpath(candidate);
|
|
28
|
-
if (!inside(base, resolved))
|
|
29
|
-
throw new ProjectDeliveryError('delivery_path_outside_project', 'Delivery output must stay inside the project', directory);
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
if (error.code !== 'ENOENT')
|
|
34
|
-
throw error;
|
|
35
|
-
candidate = path.dirname(candidate);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
async function validateEntry(output, primary) {
|
|
40
|
-
const content = await readFile(primary);
|
|
41
|
-
if (path.extname(primary).toLowerCase() === '.zip') {
|
|
42
|
-
try {
|
|
43
|
-
let totalBytes = 0;
|
|
44
|
-
const files = unzipSync(content, {
|
|
45
|
-
filter(file) {
|
|
46
|
-
totalBytes += file.originalSize;
|
|
47
|
-
if (totalBytes > 128 * 1024 * 1024 ||
|
|
48
|
-
file.name.startsWith('/') ||
|
|
49
|
-
file.name.includes('\\') ||
|
|
50
|
-
file.name.split('/').includes('..'))
|
|
51
|
-
throw new Error('Invalid delivery ZIP entries');
|
|
52
|
-
return true;
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
if (!Object.keys(files).some((name) => name.endsWith('.html')))
|
|
56
|
-
throw new Error('Delivery ZIP has no HTML entry');
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
throw new ProjectDeliveryError('delivery_package_invalid', 'The declared ZIP must be a valid Web package', path.basename(primary));
|
|
60
|
-
}
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
const html = content.toString('utf8');
|
|
64
|
-
if (!/<(?:!doctype\s+html|html|body|script|canvas)\b/i.test(html))
|
|
65
|
-
throw new ProjectDeliveryError('delivery_html_invalid', 'The declared HTML entry is not a Web document', path.basename(primary));
|
|
66
|
-
for (const tag of html.match(/<(?:script|link|img|source|audio|video)\b[^>]*>/gi) ?? []) {
|
|
67
|
-
const attribute = /\b(?:src|href)\s*=\s*['"]([^'"]+)['"]/i.exec(tag)?.[1];
|
|
68
|
-
if (!attribute || /^(?:[a-z][a-z\d+.-]*:|\/\/|#)/i.test(attribute))
|
|
69
|
-
continue;
|
|
70
|
-
let relative;
|
|
71
|
-
try {
|
|
72
|
-
relative = decodeURIComponent(attribute.split(/[?#]/)[0]);
|
|
73
|
-
}
|
|
74
|
-
catch {
|
|
75
|
-
throw new ProjectDeliveryError('delivery_resource_missing', 'A delivery resource URL is invalid', attribute);
|
|
76
|
-
}
|
|
77
|
-
const target = relative.startsWith('/')
|
|
78
|
-
? path.join(output, relative)
|
|
79
|
-
: path.resolve(path.dirname(primary), relative);
|
|
80
|
-
const resolved = await realpath(target).catch(() => undefined);
|
|
81
|
-
if (!resolved || !inside(output, resolved))
|
|
82
|
-
throw new ProjectDeliveryError('delivery_resource_missing', 'A referenced delivery resource is missing or outside the output directory', attribute);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
/** Hash content and relative names, never mtime or Git HEAD, so receipts survive a clean clone. */
|
|
86
|
-
export async function deliverySourceFingerprint(root, outputDirectory, receiptPath, generatedDirectories = []) {
|
|
87
|
-
const production = await deliveryProductionSourceSnapshot(root, outputDirectory, receiptPath, generatedDirectories);
|
|
88
|
-
if (production)
|
|
89
|
-
return production.fingerprint;
|
|
90
|
-
return deliveryGitSourceFingerprint(root, outputDirectory, receiptPath, generatedDirectories);
|
|
91
|
-
}
|
|
92
|
-
/** Versioned projects use the same exact source set as save, batch capture and a clean Worker checkout. */
|
|
93
|
-
export async function deliveryProductionSourceSnapshot(root, outputDirectory, receiptPath, generatedDirectories = []) {
|
|
94
|
-
const pattern = new RegExp(`^${path.posix.normalize(outputDirectory).replace(/[.*+?^$()|[\]\\]/g, '\\$&')
|
|
95
|
-
.replace(/\{channel\}/g, '[a-z][a-z0-9-]{0,63}').replace(/\{format\}/g, '(?:html|zip)')}(?:/|$)`);
|
|
96
|
-
try {
|
|
97
|
-
return await readProductionSourceSnapshot(root, { excludedDirectories: generatedDirectories,
|
|
98
|
-
excludedPath: name => pattern.test(name) || Boolean(receiptPath && path.resolve(root, name) === path.resolve(receiptPath)) });
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
if (error instanceof ProductionSourceError)
|
|
102
|
-
throw new ProjectDeliveryError(error.code, error.message, error.file);
|
|
103
|
-
throw error;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
export async function outputFingerprint(root, directory, entry) {
|
|
107
|
-
const output = await safeExistingPath(root, directory);
|
|
108
|
-
const primary = await safeExistingPath(root, path.posix.join(directory, entry));
|
|
109
|
-
if (!inside(output, primary) ||
|
|
110
|
-
!(await lstat(primary)).isFile() ||
|
|
111
|
-
(await lstat(primary)).size < 1) {
|
|
112
|
-
throw new ProjectDeliveryError('delivery_output_invalid', 'The declared delivery entry must be a nonempty file', entry);
|
|
113
|
-
}
|
|
114
|
-
await validateEntry(output, primary);
|
|
115
|
-
const hash = createHash('sha256');
|
|
116
|
-
const visit = async (current) => {
|
|
117
|
-
for (const child of (await readdir(current, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name, 'en'))) {
|
|
118
|
-
const absolute = path.join(current, child.name);
|
|
119
|
-
if (child.isSymbolicLink())
|
|
120
|
-
throw new ProjectDeliveryError('delivery_output_symlink', 'Delivery outputs must contain files instead of symlinks', path.relative(output, absolute));
|
|
121
|
-
if (child.isDirectory())
|
|
122
|
-
await visit(absolute);
|
|
123
|
-
else if (child.isFile()) {
|
|
124
|
-
const content = await readFile(absolute);
|
|
125
|
-
hash
|
|
126
|
-
.update(path.relative(output, absolute).split(path.sep).join('/'))
|
|
127
|
-
.update('\0')
|
|
128
|
-
.update(content)
|
|
129
|
-
.update('\0');
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
await visit(output);
|
|
134
|
-
return hash.digest('hex');
|
|
135
|
-
}
|
|
136
|
-
export async function entryRevision(root, directory, entry) {
|
|
137
|
-
try {
|
|
138
|
-
const info = await lstat(path.join(root, directory, entry), { bigint: true });
|
|
139
|
-
return [info.ino, info.size, info.mtimeNs, info.ctimeNs].join(':');
|
|
140
|
-
}
|
|
141
|
-
catch {
|
|
142
|
-
return undefined;
|
|
143
|
-
}
|
|
144
|
-
}
|