@playcraft/build 0.1.91 → 0.1.92-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/index.d.ts +4 -19
- package/dist/index.js +2 -11
- package/dist/platforms/adikteev.js +0 -1
- package/dist/platforms/applovin.js +0 -1
- package/dist/platforms/base.js +2 -2
- 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 +0 -5
- package/dist/validation/html-validator.d.ts +0 -5
- package/dist/validation/html-validator.js +17 -19
- package/dist/validation/index.d.ts +0 -4
- package/dist/validation/index.js +0 -4
- 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 -155
- package/dist/validation/types.js +1 -1
- package/dist/validation/validation-runner.d.ts +2 -22
- package/dist/validation/validation-runner.js +3 -68
- 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 +54 -30
- 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 -16
- 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 -7
- package/dist/delivery/command-isolation.js +0 -252
- package/dist/delivery/commands.d.ts +0 -5
- package/dist/delivery/commands.js +0 -137
- 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 -126
- 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/validation/artifact-qa.d.ts +0 -44
- package/dist/validation/artifact-qa.js +0 -170
- package/dist/validation/artifact-rules.d.ts +0 -28
- package/dist/validation/artifact-rules.js +0 -440
- package/dist/validation/artifact.d.ts +0 -14
- package/dist/validation/artifact.js +0 -188
- package/dist/validation/runtime-load.d.ts +0 -89
- package/dist/validation/runtime-load.js +0 -654
- 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
|
@@ -1,252 +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; there is no fallback.
|
|
87
|
-
// The packed path-beneath structure and syscall numbers come from Linux's
|
|
88
|
-
// include/uapi/linux/landlock.h and x86/asm-generic syscall tables.
|
|
89
|
-
const LANDLOCK_LAUNCHER = String.raw `
|
|
90
|
-
import ctypes, json, os, platform, resource, stat, sys
|
|
91
|
-
|
|
92
|
-
def fail(reason):
|
|
93
|
-
sys.stderr.write("delivery_isolation_unavailable:" + reason + "\n")
|
|
94
|
-
sys.exit(125)
|
|
95
|
-
|
|
96
|
-
try:
|
|
97
|
-
if sys.platform != "linux" or platform.machine() not in ("x86_64", "aarch64", "riscv64"):
|
|
98
|
-
fail("unsupported_landlock_architecture")
|
|
99
|
-
policy = json.loads(sys.argv[1])
|
|
100
|
-
command = sys.argv[2:]
|
|
101
|
-
if not command:
|
|
102
|
-
fail("missing_command")
|
|
103
|
-
# Landlock does not revoke already-open descriptors. Preserve only managed
|
|
104
|
-
# stdio, never an inherited directory/file handle into the original tree.
|
|
105
|
-
ceiling = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
|
|
106
|
-
if ceiling == resource.RLIM_INFINITY:
|
|
107
|
-
ceiling = os.sysconf("SC_OPEN_MAX")
|
|
108
|
-
os.closerange(3, ceiling)
|
|
109
|
-
libc = ctypes.CDLL(None, use_errno=True)
|
|
110
|
-
libc.syscall.restype = ctypes.c_long
|
|
111
|
-
abi = libc.syscall(444, ctypes.c_void_p(), ctypes.c_size_t(0), ctypes.c_uint(1))
|
|
112
|
-
if abi < 3:
|
|
113
|
-
fail("landlock_abi_3_required")
|
|
114
|
-
handled = (1 << 15) - 1
|
|
115
|
-
if abi >= 5:
|
|
116
|
-
handled |= 1 << 15
|
|
117
|
-
if abi >= 9:
|
|
118
|
-
handled |= 1 << 16
|
|
119
|
-
class Ruleset(ctypes.Structure):
|
|
120
|
-
_fields_ = [("handled_access_fs", ctypes.c_uint64)]
|
|
121
|
-
class Beneath(ctypes.Structure):
|
|
122
|
-
_pack_ = 1
|
|
123
|
-
_fields_ = [("allowed_access", ctypes.c_uint64), ("parent_fd", ctypes.c_int32)]
|
|
124
|
-
attr = Ruleset(handled)
|
|
125
|
-
ruleset = libc.syscall(444, ctypes.byref(attr), ctypes.sizeof(attr), 0)
|
|
126
|
-
if ruleset < 0:
|
|
127
|
-
fail("landlock_ruleset_failed")
|
|
128
|
-
read = (1 << 0) | (1 << 2) | (1 << 3)
|
|
129
|
-
write = (1 << 1) | (1 << 4) | (1 << 5) | (1 << 7) | (1 << 8) | (1 << 9) | (1 << 10) | (1 << 12) | (1 << 13) | (1 << 14)
|
|
130
|
-
file_rights = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 14) | (1 << 15)
|
|
131
|
-
for item in policy["read"]:
|
|
132
|
-
if os.path.realpath(item["path"]) != item["path"]:
|
|
133
|
-
fail("allowance_changed")
|
|
134
|
-
fd = os.open(item["path"], os.O_PATH | os.O_CLOEXEC | os.O_NOFOLLOW)
|
|
135
|
-
info = os.fstat(fd)
|
|
136
|
-
if str(info.st_dev) != item["dev"] or str(info.st_ino) != item["ino"]:
|
|
137
|
-
fail("allowance_changed")
|
|
138
|
-
rights = read
|
|
139
|
-
if item["path"] in policy["write"]:
|
|
140
|
-
rights |= write
|
|
141
|
-
if not stat.S_ISDIR(info.st_mode):
|
|
142
|
-
rights &= file_rights
|
|
143
|
-
rule = Beneath(rights & handled, fd)
|
|
144
|
-
result = libc.syscall(445, ruleset, 1, ctypes.byref(rule), 0)
|
|
145
|
-
os.close(fd)
|
|
146
|
-
if result != 0:
|
|
147
|
-
fail("landlock_rule_failed")
|
|
148
|
-
# A fresh, single-threaded launcher applies policy before exec; all future
|
|
149
|
-
# threads/children inherit it. Do not spawn an untracked second executor.
|
|
150
|
-
if libc.prctl(38, 1, 0, 0, 0) != 0:
|
|
151
|
-
fail("no_new_privs_failed")
|
|
152
|
-
if libc.syscall(446, ruleset, 0) != 0:
|
|
153
|
-
fail("landlock_restrict_failed")
|
|
154
|
-
os.close(ruleset)
|
|
155
|
-
os.environ["TMPDIR"] = policy["temporary"]
|
|
156
|
-
os.environ["TMP"] = policy["temporary"]
|
|
157
|
-
os.environ["TEMP"] = policy["temporary"]
|
|
158
|
-
os.execvpe(command[0], command, os.environ)
|
|
159
|
-
except Exception:
|
|
160
|
-
fail("landlock_setup_or_exec_failed")
|
|
161
|
-
`;
|
|
162
|
-
/** Construct argv for the existing managed launcher; never execute or fall back here. */
|
|
163
|
-
export async function wrapDeliveryCommand(argv, options) {
|
|
164
|
-
if (!argv[0] || argv.some((value) => value.includes('\0')))
|
|
165
|
-
failure('The isolated command is invalid');
|
|
166
|
-
if (process.platform !== 'darwin' && process.platform !== 'linux')
|
|
167
|
-
failure('Delivery file isolation is unsupported on this operating system');
|
|
168
|
-
// Loader injection would execute before Python/Seatbelt establishes policy.
|
|
169
|
-
if (['LD_PRELOAD', 'LD_AUDIT', 'DYLD_INSERT_LIBRARIES', 'DYLD_LIBRARY_PATH'].some((key) => process.env[key]))
|
|
170
|
-
failure('Inherited loader injection is incompatible with delivery file isolation');
|
|
171
|
-
const project = await allowedPath(options.projectRoot);
|
|
172
|
-
const isolated = await allowedPath(options.isolatedRoot);
|
|
173
|
-
if (!project?.directory || !isolated?.directory || inside(isolated.path, project.path))
|
|
174
|
-
failure('The snapshot must be a separate directory from its source');
|
|
175
|
-
const dependencies = [];
|
|
176
|
-
for (const candidate of options.dependencyRoots ?? []) {
|
|
177
|
-
if (path.basename(path.resolve(candidate)) !== 'node_modules')
|
|
178
|
-
failure('Only a genuine node_modules directory can be a dependency allowance');
|
|
179
|
-
const info = await lstat(candidate).catch(() => undefined);
|
|
180
|
-
if (!info?.isDirectory() || info.isSymbolicLink())
|
|
181
|
-
failure('Dependency allowances must be real directories');
|
|
182
|
-
const dependency = await allowedPath(candidate);
|
|
183
|
-
if (!dependency?.directory ||
|
|
184
|
-
inside(dependency.path, project.path) ||
|
|
185
|
-
inside(dependency.path, isolated.path) ||
|
|
186
|
-
inside(isolated.path, dependency.path))
|
|
187
|
-
failure('Dependency allowances cannot expose the source or snapshot parent');
|
|
188
|
-
dependencies.push(dependency);
|
|
189
|
-
}
|
|
190
|
-
const roots = new Map();
|
|
191
|
-
for (const value of [isolated, ...dependencies])
|
|
192
|
-
roots.set(value.path, value);
|
|
193
|
-
const node = await allowedPath(process.execPath);
|
|
194
|
-
const nodePrefix = node ? path.dirname(path.dirname(node.path)) : undefined;
|
|
195
|
-
const candidates = [
|
|
196
|
-
...SYSTEM_PATHS,
|
|
197
|
-
...(process.platform === 'darwin' ? MAC_SYSTEM_PATHS : []),
|
|
198
|
-
process.execPath,
|
|
199
|
-
// Accommodate a versioned Node installation without admitting its home directory.
|
|
200
|
-
...(nodePrefix ? [path.join(nodePrefix, 'bin'), path.join(nodePrefix, 'lib')] : []),
|
|
201
|
-
];
|
|
202
|
-
for (const candidate of candidates) {
|
|
203
|
-
const item = await allowedPath(candidate, true);
|
|
204
|
-
if (!item)
|
|
205
|
-
continue;
|
|
206
|
-
if (inside(item.path, project.path) || inside(project.path, item.path))
|
|
207
|
-
failure('A system toolchain allowance overlaps the original project');
|
|
208
|
-
if (inside(item.path, isolated.path))
|
|
209
|
-
failure('A system toolchain allowance contains the snapshot');
|
|
210
|
-
roots.set(item.path, item);
|
|
211
|
-
}
|
|
212
|
-
const read = [...roots.values()];
|
|
213
|
-
const write = [isolated.path, (await realpath('/dev/null'))];
|
|
214
|
-
if (process.platform === 'darwin') {
|
|
215
|
-
await executable('/usr/bin/sandbox-exec');
|
|
216
|
-
const filter = (item) => `(${item.directory ? 'subpath' : 'literal'} ${JSON.stringify(item.path)})`;
|
|
217
|
-
const readable = read.map(filter).join(' ');
|
|
218
|
-
const profile = [
|
|
219
|
-
'(version 1)',
|
|
220
|
-
'(allow default)',
|
|
221
|
-
// Metadata remains visible, as with Landlock. New dyld/libignition also
|
|
222
|
-
// opens / as a directory anchor; literal / grants no descendant access.
|
|
223
|
-
// Deny actions take precedence over allow actions in Seatbelt, so encode
|
|
224
|
-
// the exceptions in the deny predicate rather than an overriding allow.
|
|
225
|
-
`(deny file-read-data (require-not (require-any (literal "/") ${readable})))`,
|
|
226
|
-
`(deny file-read-xattr (require-not (require-any ${readable})))`,
|
|
227
|
-
`(deny file-write* (require-not (require-any (subpath ${JSON.stringify(isolated.path)}) (literal "/dev/null"))))`,
|
|
228
|
-
].join('\n');
|
|
229
|
-
// env is itself sandboxed; it only confines tool temporary files to the snapshot.
|
|
230
|
-
return [
|
|
231
|
-
'/usr/bin/sandbox-exec',
|
|
232
|
-
'-p',
|
|
233
|
-
profile,
|
|
234
|
-
'/usr/bin/env',
|
|
235
|
-
`TMPDIR=${isolated.path}`,
|
|
236
|
-
`TMP=${isolated.path}`,
|
|
237
|
-
`TEMP=${isolated.path}`,
|
|
238
|
-
...argv,
|
|
239
|
-
];
|
|
240
|
-
}
|
|
241
|
-
// Use the OS interpreter, never a project-controlled PATH shim or PYTHONPATH.
|
|
242
|
-
await executable('/usr/bin/python3');
|
|
243
|
-
return [
|
|
244
|
-
'/usr/bin/python3',
|
|
245
|
-
'-I',
|
|
246
|
-
'-S',
|
|
247
|
-
'-c',
|
|
248
|
-
LANDLOCK_LAUNCHER,
|
|
249
|
-
JSON.stringify({ read, write, temporary: isolated.path }),
|
|
250
|
-
...argv,
|
|
251
|
-
];
|
|
252
|
-
}
|
|
@@ -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,137 +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
|
-
/sandbox-exec:.*(?:sandbox_(?:init|apply)|Operation not permitted)/i.test(output);
|
|
11
|
-
}
|
|
12
|
-
export async function requireExecutable(root, executable, cwd, options, isolation) {
|
|
13
|
-
if (options.runCommand) {
|
|
14
|
-
const checkArgv = [
|
|
15
|
-
'/bin/sh',
|
|
16
|
-
'-c',
|
|
17
|
-
'case "$1" in */*) test -f "$1" && test -x "$1" ;; *) command -v "$1" >/dev/null 2>&1 ;; esac',
|
|
18
|
-
'delivery-toolchain',
|
|
19
|
-
executable,
|
|
20
|
-
];
|
|
21
|
-
const check = await options.runCommand({
|
|
22
|
-
argv: isolation ? await wrapDeliveryCommand(checkArgv, isolation) : checkArgv,
|
|
23
|
-
cwd,
|
|
24
|
-
timeoutMs: 10000,
|
|
25
|
-
});
|
|
26
|
-
if (isolation && isolationUnavailable(check.code, `${check.stderr ?? ''}${check.stdout ?? ''}`))
|
|
27
|
-
throw new ProjectDeliveryError('delivery_isolation_unavailable', 'The operating system could not enforce delivery file isolation');
|
|
28
|
-
if (check.code !== 0 || check.canceled || check.timedOut)
|
|
29
|
-
throw new ProjectDeliveryError('delivery_toolchain_missing', `Required executable is unavailable: ${executable}`);
|
|
30
|
-
return executable;
|
|
31
|
-
}
|
|
32
|
-
const search = executable.includes('/') || executable.includes('\\')
|
|
33
|
-
? [path.resolve(cwd, executable)]
|
|
34
|
-
: [
|
|
35
|
-
path.join(cwd, 'node_modules', '.bin', executable),
|
|
36
|
-
path.join(root, 'node_modules', '.bin', executable),
|
|
37
|
-
...(process.env.PATH ?? '')
|
|
38
|
-
.split(path.delimiter)
|
|
39
|
-
.map((directory) => path.join(directory, executable)),
|
|
40
|
-
];
|
|
41
|
-
for (const candidate of search) {
|
|
42
|
-
try {
|
|
43
|
-
await access(candidate, process.platform === 'win32' ? constants.F_OK : constants.X_OK);
|
|
44
|
-
if ((await stat(candidate)).isFile())
|
|
45
|
-
return candidate;
|
|
46
|
-
}
|
|
47
|
-
catch {
|
|
48
|
-
/* Check the next PATH entry. */
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
throw new ProjectDeliveryError('delivery_toolchain_missing', `Required executable is unavailable: ${executable}`);
|
|
52
|
-
}
|
|
53
|
-
export async function runDeliveryCommand(root, command, replace, options, isolation) {
|
|
54
|
-
if (options.signal?.aborted)
|
|
55
|
-
throw new ProjectDeliveryError('delivery_canceled', 'Delivery preparation was canceled');
|
|
56
|
-
const cwd = await safeExistingPath(root, replace(command.cwd ?? '.'));
|
|
57
|
-
const argv = command.argv.map(replace);
|
|
58
|
-
const executable = await requireExecutable(root, argv[0], cwd, options, isolation);
|
|
59
|
-
const isolatedArgv = isolation
|
|
60
|
-
? await wrapDeliveryCommand([executable, ...argv.slice(1)], isolation)
|
|
61
|
-
: undefined;
|
|
62
|
-
const timeoutMs = command.timeoutMs ?? 300000;
|
|
63
|
-
if (options.runCommand) {
|
|
64
|
-
const result = await options.runCommand({ argv: isolatedArgv ?? argv, cwd, timeoutMs });
|
|
65
|
-
if (isolation && isolationUnavailable(result.code, `${result.stderr ?? ''}${result.stdout ?? ''}`))
|
|
66
|
-
throw new ProjectDeliveryError('delivery_isolation_unavailable', 'The operating system could not enforce delivery file isolation');
|
|
67
|
-
if (result.canceled || options.signal?.aborted)
|
|
68
|
-
throw new ProjectDeliveryError('delivery_canceled', 'Delivery preparation was canceled');
|
|
69
|
-
if (result.timedOut)
|
|
70
|
-
throw new ProjectDeliveryError('delivery_command_timeout', `Delivery command exceeded ${timeoutMs}ms`);
|
|
71
|
-
if (result.code !== 0)
|
|
72
|
-
throw new ProjectDeliveryError('delivery_command_failed', `Delivery command exited with ${result.code}: ${(result.stderr || result.stdout || '').slice(-4000)}`);
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
await new Promise((resolve, reject) => {
|
|
76
|
-
let tail = '';
|
|
77
|
-
let timedOut = false;
|
|
78
|
-
const child = spawn(isolatedArgv?.[0] ?? executable, isolatedArgv?.slice(1) ?? argv.slice(1), {
|
|
79
|
-
cwd,
|
|
80
|
-
shell: false,
|
|
81
|
-
detached: process.platform !== 'win32',
|
|
82
|
-
env: {
|
|
83
|
-
...process.env,
|
|
84
|
-
CI: 'true',
|
|
85
|
-
PLAYCRAFT_DELIVERY_EXECUTING: '1',
|
|
86
|
-
PATH: [
|
|
87
|
-
path.join(cwd, 'node_modules', '.bin'),
|
|
88
|
-
path.join(root, 'node_modules', '.bin'),
|
|
89
|
-
process.env.PATH ?? '',
|
|
90
|
-
].join(path.delimiter),
|
|
91
|
-
},
|
|
92
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
93
|
-
});
|
|
94
|
-
const stop = () => {
|
|
95
|
-
try {
|
|
96
|
-
if (process.platform !== 'win32' && child.pid)
|
|
97
|
-
process.kill(-child.pid, 'SIGTERM');
|
|
98
|
-
else
|
|
99
|
-
child.kill('SIGTERM');
|
|
100
|
-
}
|
|
101
|
-
catch {
|
|
102
|
-
/* The command may already have exited. */
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
const timer = setTimeout(() => {
|
|
106
|
-
timedOut = true;
|
|
107
|
-
stop();
|
|
108
|
-
}, timeoutMs);
|
|
109
|
-
options.signal?.addEventListener('abort', stop, { once: true });
|
|
110
|
-
const collect = (chunk) => {
|
|
111
|
-
tail = (tail + chunk.toString()).slice(-4000);
|
|
112
|
-
};
|
|
113
|
-
child.stdout?.on('data', collect);
|
|
114
|
-
child.stderr?.on('data', collect);
|
|
115
|
-
const cleanup = () => {
|
|
116
|
-
clearTimeout(timer);
|
|
117
|
-
options.signal?.removeEventListener('abort', stop);
|
|
118
|
-
};
|
|
119
|
-
child.once('error', (error) => {
|
|
120
|
-
cleanup();
|
|
121
|
-
reject(new ProjectDeliveryError('delivery_command_failed', error.message));
|
|
122
|
-
});
|
|
123
|
-
child.once('close', (code) => {
|
|
124
|
-
cleanup();
|
|
125
|
-
if (options.signal?.aborted)
|
|
126
|
-
reject(new ProjectDeliveryError('delivery_canceled', 'Delivery preparation was canceled'));
|
|
127
|
-
else if (timedOut)
|
|
128
|
-
reject(new ProjectDeliveryError('delivery_command_timeout', `Delivery command exceeded ${timeoutMs}ms`));
|
|
129
|
-
else if (isolation && isolationUnavailable(code, tail))
|
|
130
|
-
reject(new ProjectDeliveryError('delivery_isolation_unavailable', 'The operating system could not enforce delivery file isolation'));
|
|
131
|
-
else if (code !== 0)
|
|
132
|
-
reject(new ProjectDeliveryError('delivery_command_failed', `Delivery command exited with ${code}: ${tail}`));
|
|
133
|
-
else
|
|
134
|
-
resolve();
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
}
|
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
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
|
-
import { readdir, readFile } from 'node:fs/promises';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { ProjectDeliveryError } from './recipe.js';
|
|
5
|
-
const SOURCE_IGNORED = new Set([
|
|
6
|
-
'.git',
|
|
7
|
-
'node_modules',
|
|
8
|
-
'dist',
|
|
9
|
-
'.cache',
|
|
10
|
-
'.turbo',
|
|
11
|
-
'.next',
|
|
12
|
-
'.vite',
|
|
13
|
-
'.parcel-cache',
|
|
14
|
-
'.pnpm-store',
|
|
15
|
-
'.eslintcache',
|
|
16
|
-
'.DS_Store',
|
|
17
|
-
'.playcraft',
|
|
18
|
-
'.playcraft-temp',
|
|
19
|
-
'.tmp',
|
|
20
|
-
'.agents',
|
|
21
|
-
'.claude',
|
|
22
|
-
'.codex',
|
|
23
|
-
'.playcraft.json',
|
|
24
|
-
]);
|
|
25
|
-
/** The clean-Git fallback has no production audio or native package dependencies. */
|
|
26
|
-
export async function deliveryGitSourceFingerprint(root, outputDirectory, receiptPath, generatedDirectories = []) {
|
|
27
|
-
const hash = createHash('sha256');
|
|
28
|
-
const outputPattern = new RegExp(`^${path.posix
|
|
29
|
-
.normalize(outputDirectory)
|
|
30
|
-
.replace(/[.*+?^$()|[\]\\]/g, '\\$&')
|
|
31
|
-
.replace(/\{channel\}/g, '[a-z][a-z0-9-]{0,63}')
|
|
32
|
-
.replace(/\{format\}/g, '(?:html|zip)')}(?:/|$)`);
|
|
33
|
-
const receipt = receiptPath ? path.resolve(receiptPath) : undefined;
|
|
34
|
-
const visit = async (directory) => {
|
|
35
|
-
const entries = (await readdir(directory, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name, 'en'));
|
|
36
|
-
for (const entry of entries) {
|
|
37
|
-
const absolute = path.join(directory, entry.name);
|
|
38
|
-
const relative = path.relative(root, absolute).split(path.sep).join('/');
|
|
39
|
-
if (SOURCE_IGNORED.has(entry.name) ||
|
|
40
|
-
/^\.env(?:\..*)?$/.test(entry.name) ||
|
|
41
|
-
absolute === receipt ||
|
|
42
|
-
generatedDirectories.some((directory) => relative === directory || relative.startsWith(`${directory}/`)) ||
|
|
43
|
-
outputPattern.test(relative))
|
|
44
|
-
continue;
|
|
45
|
-
if (entry.isDirectory())
|
|
46
|
-
await visit(absolute);
|
|
47
|
-
else if (entry.isSymbolicLink()) {
|
|
48
|
-
throw new ProjectDeliveryError('delivery_source_symlink', 'Source symlinks require a reproducible project build input', relative);
|
|
49
|
-
}
|
|
50
|
-
else if (entry.isFile()) {
|
|
51
|
-
const content = await readFile(absolute);
|
|
52
|
-
hash.update(`${relative.length}:${relative}:${content.length}:`).update(content);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
await visit(root);
|
|
57
|
-
return hash.digest('hex');
|
|
58
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { type ProductionSourceSnapshot } from '../production-inputs.js';
|
|
2
|
-
import type { ProjectDeliveryOptions, ProjectDeliveryRecipe } from './types.js';
|
|
3
|
-
import type { DeliveryCommandIsolation } from './commands.js';
|
|
4
|
-
/** A clean source directory contains only the versioned production snapshot and controlled dependencies. */
|
|
5
|
-
export declare function buildIsolatedDelivery(root: string, snapshot: ProductionSourceSnapshot, recipe: ProjectDeliveryRecipe, options: ProjectDeliveryOptions, build: (isolated: string, isolation: DeliveryCommandIsolation) => Promise<string>): Promise<string>;
|