@arcadia-eternity/content-sdk 4.6.0 → 4.7.1
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/README.md +2 -2
- package/dist/author-api.d.ts +12 -2
- package/dist/author-api.js +11 -2
- package/dist/author-git.d.ts +63 -0
- package/dist/author-git.js +324 -0
- package/dist/author-reference.d.ts +15 -1
- package/dist/author-reference.js +20 -1
- package/dist/cli.js +5 -4
- package/dist/content-query.d.ts +15 -1
- package/dist/content-query.js +53 -11
- package/dist/content-workspace.d.ts +423 -3
- package/dist/content-workspace.js +194 -51
- package/dist/debug-environments.d.ts +393 -25
- package/dist/debug-environments.js +3 -42
- package/dist/demo.js +1 -1
- package/dist/effect-declarations.d.ts +14 -0
- package/dist/effect-declarations.js +103 -0
- package/dist/environment-host-base.d.ts +175 -0
- package/dist/environment-host-base.js +86 -0
- package/dist/environment-member-transfer.d.ts +5 -0
- package/dist/environment-member-transfer.js +95 -0
- package/dist/environment-rules.d.ts +728 -3
- package/dist/environment-rules.js +158 -74
- package/dist/environment-sharing.d.ts +51 -0
- package/dist/environment-sharing.js +321 -0
- package/dist/environment.d.ts +2 -0
- package/dist/environment.js +32 -9
- package/dist/jobs.d.ts +5 -0
- package/dist/jobs.js +59 -10
- package/dist/learnsets.d.ts +47 -0
- package/dist/learnsets.js +124 -0
- package/dist/lib/content.d.ts +1 -1
- package/dist/lib/content.js +26 -2
- package/dist/lib/presentation.js +5 -11
- package/dist/managed-projects.d.ts +6 -0
- package/dist/managed-projects.js +137 -45
- package/dist/managed-sources.d.ts +17 -0
- package/dist/managed-sources.js +28 -10
- package/dist/mcp-contracts.d.ts +405 -4
- package/dist/mcp-contracts.js +3 -1
- package/dist/mcp.js +23 -1
- package/dist/pack-project.d.ts +2 -1
- package/dist/pack-project.js +40 -5
- package/dist/prepared-document.d.ts +476 -0
- package/dist/prepared-document.js +47 -0
- package/dist/preview.js +5 -5
- package/dist/project.d.ts +3 -1
- package/dist/project.js +47 -4
- package/dist/rule-composition.d.ts +290 -0
- package/dist/rule-composition.js +267 -0
- package/dist/template/.github/scripts/release-payload.mjs +91 -0
- package/dist/template/.github/scripts/release-test-npm.mjs +27 -0
- package/dist/template/.github/scripts/verify-release.mjs +138 -0
- package/dist/template/.github/workflows/release-pack.yml +77 -0
- package/dist/template/README.md +15 -2
- package/dist/template/gitignore-template +7 -0
- package/dist/template/npm-lock-template.json +2319 -0
- package/dist/template/package.json +4 -2
- package/dist/template/skills/arcadia-content-authoring/references/tool-workflows.md +1 -1
- package/dist/template/skills/arcadia-content-git/SKILL.md +14 -0
- package/dist/template/skills/arcadia-content-release/SKILL.md +29 -0
- package/dist/template/test/pack.test.mjs +24 -5
- package/dist/testing.d.ts +1 -0
- package/dist/testing.js +26 -7
- package/dist/workspace-cli.js +2 -2
- package/dist/workspace-materials.d.ts +4 -1
- package/dist/workspace-materials.js +8 -2
- package/dist/workspace.d.ts +11 -0
- package/dist/workspace.js +191 -31
- package/package.json +16 -4
- package/release-payload.mjs +91 -0
- package/release-test-npm.mjs +27 -0
package/dist/managed-projects.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { sha256Hex } from '@arcadia-eternity/const';
|
|
1
2
|
import { execFile } from 'node:child_process';
|
|
2
|
-
import {
|
|
3
|
-
import { mkdir, mkdtemp, readFile, realpath, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { mkdir, mkdtemp, readFile, readdir, realpath, rename, rm, writeFile } from 'node:fs/promises';
|
|
4
4
|
import { join, resolve } from 'node:path';
|
|
5
|
-
import { promisify } from 'node:util';
|
|
5
|
+
import { isDeepStrictEqual, promisify } from 'node:util';
|
|
6
6
|
import { valid, validRange } from 'semver';
|
|
7
7
|
import { inspectNpmProject, resolveNpmInvocation, withShippedEnvironmentProject, withShippedCatalogArchive, } from '@arcadia-eternity/pack-loader/node';
|
|
8
8
|
import { normalizeEnvironmentDocument } from './debug-environments.js';
|
|
@@ -140,6 +140,88 @@ export class ManagedProjects {
|
|
|
140
140
|
throw contentError('NPM_INSTALL_FAILED');
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
|
+
/** Resolve an author lock in isolation from the source tree and its linked development SDK. */
|
|
144
|
+
async authorLock(manifest, previous) {
|
|
145
|
+
const allowed = [
|
|
146
|
+
'name',
|
|
147
|
+
'version',
|
|
148
|
+
'license',
|
|
149
|
+
'engines',
|
|
150
|
+
'dependencies',
|
|
151
|
+
'devDependencies',
|
|
152
|
+
'optionalDependencies',
|
|
153
|
+
'peerDependencies',
|
|
154
|
+
'peerDependenciesMeta',
|
|
155
|
+
];
|
|
156
|
+
const metadata = Object.fromEntries(allowed.filter(key => Object.hasOwn(manifest, key)).map(key => [key, manifest[key]]));
|
|
157
|
+
checkDependencySpecs(metadata);
|
|
158
|
+
checkDependencySpecs({ dependencies: metadata.devDependencies });
|
|
159
|
+
for (const field of ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']) {
|
|
160
|
+
const specs = metadata[field];
|
|
161
|
+
if (isRecord(specs) && Object.values(specs).some(value => typeof value !== 'string' || !validRange(value)))
|
|
162
|
+
throw contentError('INSTALL_DEPENDENCY_SOURCE_FORBIDDEN');
|
|
163
|
+
}
|
|
164
|
+
if (previous)
|
|
165
|
+
checkLock(JSON.parse(previous));
|
|
166
|
+
const project = join(this.root, 'project');
|
|
167
|
+
await mkdir(project);
|
|
168
|
+
await writeFile(join(project, 'package.json'), JSON.stringify(metadata));
|
|
169
|
+
const path = join(project, 'package-lock.json');
|
|
170
|
+
if (previous)
|
|
171
|
+
await writeFile(path, previous);
|
|
172
|
+
await this.#npm(['install', '--package-lock-only', '--ignore-scripts', '--registry', this.#options.registry], project, this.#controller.signal);
|
|
173
|
+
const result = await readFile(path, 'utf8');
|
|
174
|
+
checkLock(JSON.parse(result));
|
|
175
|
+
return result;
|
|
176
|
+
}
|
|
177
|
+
async #packSource(source, destination, signal, expectedName) {
|
|
178
|
+
const captured = await acquireSource(source, {
|
|
179
|
+
destination,
|
|
180
|
+
preserveNpmArchive: true,
|
|
181
|
+
signal,
|
|
182
|
+
maxBytes: this.#options.maxBytes,
|
|
183
|
+
maxFiles: this.#options.maxFiles,
|
|
184
|
+
timeoutMs: this.#options.timeoutMs,
|
|
185
|
+
});
|
|
186
|
+
const manifest = JSON.parse(await readFile(join(captured.directory, 'package.json'), 'utf8'));
|
|
187
|
+
if (typeof manifest.name !== 'string' ||
|
|
188
|
+
!packageName.test(manifest.name) ||
|
|
189
|
+
(expectedName && manifest.name !== expectedName))
|
|
190
|
+
throw contentError('INSTALL_SOURCE_IDENTITY');
|
|
191
|
+
if (typeof manifest.version !== 'string' || !valid(manifest.version))
|
|
192
|
+
throw contentError('INSTALL_SOURCE_VERSION');
|
|
193
|
+
checkDependencySpecs(manifest);
|
|
194
|
+
try {
|
|
195
|
+
checkLock(JSON.parse(await readFile(join(captured.directory, 'npm-shrinkwrap.json'), 'utf8')));
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
if (errorCode(error) !== 'ENOENT')
|
|
199
|
+
throw error;
|
|
200
|
+
}
|
|
201
|
+
if (captured.archive)
|
|
202
|
+
return { file: captured.archive, provenance: captured.provenance };
|
|
203
|
+
const output = join(destination, 'packed');
|
|
204
|
+
await mkdir(output);
|
|
205
|
+
await this.#npm(['pack', '--ignore-scripts', '--json', '--pack-destination', output, '--registry', this.#options.registry], captured.directory, signal);
|
|
206
|
+
const files = await readdir(output);
|
|
207
|
+
if (files.length !== 1 || !files[0].endsWith('.tgz'))
|
|
208
|
+
throw contentError('INSTALL_PACK_INVALID');
|
|
209
|
+
return { file: join(output, files[0]), provenance: captured.provenance };
|
|
210
|
+
}
|
|
211
|
+
async withLocalArchive(file, signal, consume) {
|
|
212
|
+
return this.withSourceArchive({ kind: 'archive', file }, signal, consume);
|
|
213
|
+
}
|
|
214
|
+
async withSourceArchive(source, signal, consume) {
|
|
215
|
+
await mkdir(this.root, { recursive: true, mode: 0o700 });
|
|
216
|
+
const staging = await mkdtemp(join(this.root, 'archive-'));
|
|
217
|
+
try {
|
|
218
|
+
const captured = await this.#packSource(source, join(staging, 'source'), signal);
|
|
219
|
+
return await consume(captured.file, captured.provenance);
|
|
220
|
+
}
|
|
221
|
+
finally {
|
|
222
|
+
await rm(staging, { recursive: true, force: true });
|
|
223
|
+
}
|
|
224
|
+
}
|
|
143
225
|
prepareEnvironment(workspace, input, validate) {
|
|
144
226
|
if (typeof validate !== 'function')
|
|
145
227
|
return Promise.reject(contentError('STATIC_PREPARER_REQUIRED'));
|
|
@@ -152,7 +234,10 @@ export class ManagedProjects {
|
|
|
152
234
|
if ((draft?.revision ?? null) !== input.expectedRevision)
|
|
153
235
|
throw contentError('REVISION_CONFLICT');
|
|
154
236
|
return input.document ?? draft?.document;
|
|
155
|
-
}, {
|
|
237
|
+
}, {
|
|
238
|
+
...input,
|
|
239
|
+
projectDirectory: input.seedDirectory ?? join(workspace.root, 'environments', input.environmentId),
|
|
240
|
+
}, async (directory, signal, document) => {
|
|
156
241
|
return workspace.prepareEnvironment({ ...input, document, projectDirectory: directory, signal }, validate);
|
|
157
242
|
}));
|
|
158
243
|
}
|
|
@@ -324,11 +409,23 @@ export class ManagedProjects {
|
|
|
324
409
|
await mkdir(join(this.root, 'staging'), { recursive: true, mode: 0o700 });
|
|
325
410
|
directory = await mkdtemp(join(this.root, 'staging', 'prepare-'));
|
|
326
411
|
await mkdir(join(directory, 'candidates'));
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
412
|
+
const localSpecs = new Set(Object.entries(dependencies)
|
|
413
|
+
.filter(([name, spec]) => name !== baseName && spec.startsWith('file:'))
|
|
414
|
+
.map(([, spec]) => spec));
|
|
415
|
+
if (input.projectDirectory && localSpecs.size) {
|
|
416
|
+
const previous = await readFile(join(input.projectDirectory, 'package-lock.json'), 'utf8').catch(error => {
|
|
417
|
+
if (errorCode(error) !== 'ENOENT')
|
|
418
|
+
throw error;
|
|
419
|
+
});
|
|
420
|
+
if (previous)
|
|
421
|
+
for (const entry of Object.values(JSON.parse(previous).packages ?? {})) {
|
|
422
|
+
if (isRecord(entry) &&
|
|
423
|
+
typeof entry.resolved === 'string' &&
|
|
424
|
+
/^file:candidates\/[a-zA-Z0-9_.-]+\.tgz$/.test(entry.resolved))
|
|
425
|
+
localSpecs.add(entry.resolved);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
for (const spec of localSpecs) {
|
|
332
429
|
if (!input.projectDirectory)
|
|
333
430
|
throw contentError('ENVIRONMENT_SOURCE_MISSING');
|
|
334
431
|
const relativeFile = spec.slice(5);
|
|
@@ -340,7 +437,7 @@ export class ManagedProjects {
|
|
|
340
437
|
if (includesBase) {
|
|
341
438
|
await withShippedCatalogArchive(baseRoot, undefined, async (file) => {
|
|
342
439
|
const bytes = await readFile(file);
|
|
343
|
-
const filename = `candidates/base-${
|
|
440
|
+
const filename = `candidates/base-${sha256Hex(bytes)}.tgz`;
|
|
344
441
|
await writeFile(join(directory, filename), bytes);
|
|
345
442
|
dependencies[baseName] = 'file:' + filename;
|
|
346
443
|
});
|
|
@@ -357,42 +454,14 @@ export class ManagedProjects {
|
|
|
357
454
|
if (this.#options.offline && (source.kind === 'url' || source.kind === 'git'))
|
|
358
455
|
throw contentError('INSTALL_SOURCE_OFFLINE');
|
|
359
456
|
await input.onProgress?.({ stage: 'acquiring', completed: index, total: document.sources.length });
|
|
360
|
-
const
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
maxBytes: this.#options.maxBytes,
|
|
364
|
-
maxFiles: this.#options.maxFiles,
|
|
365
|
-
timeoutMs: this.#options.timeoutMs,
|
|
366
|
-
});
|
|
367
|
-
const manifest = JSON.parse(await readFile(join(captured.directory, 'package.json'), 'utf8'));
|
|
368
|
-
if (manifest.name !== name)
|
|
369
|
-
throw contentError('INSTALL_SOURCE_IDENTITY');
|
|
370
|
-
if (typeof manifest.version !== 'string' || !valid(manifest.version))
|
|
371
|
-
throw contentError('INSTALL_SOURCE_VERSION');
|
|
372
|
-
checkDependencySpecs(manifest);
|
|
373
|
-
try {
|
|
374
|
-
checkLock(JSON.parse(await readFile(join(captured.directory, 'npm-shrinkwrap.json'), 'utf8')));
|
|
375
|
-
}
|
|
376
|
-
catch (error) {
|
|
377
|
-
if (errorCode(error) !== 'ENOENT')
|
|
378
|
-
throw error;
|
|
379
|
-
}
|
|
380
|
-
const output = join(directory, 'packed-' + index);
|
|
381
|
-
await mkdir(output);
|
|
382
|
-
await this.#npm(['pack', '--ignore-scripts', '--json', '--pack-destination', output, '--registry', this.#options.registry], captured.directory, signal);
|
|
383
|
-
const { readdir } = await import('node:fs/promises');
|
|
384
|
-
const files = await readdir(output);
|
|
385
|
-
if (files.length !== 1 || !files[0].endsWith('.tgz'))
|
|
386
|
-
throw contentError('INSTALL_PACK_INVALID');
|
|
387
|
-
const archiveDigest = createHash('sha256')
|
|
388
|
-
.update(await readFile(join(output, files[0])))
|
|
389
|
-
.digest('hex');
|
|
457
|
+
const staged = join(directory, 'source-' + index);
|
|
458
|
+
const captured = await this.#packSource(source, staged, signal, name);
|
|
459
|
+
const archiveDigest = sha256Hex(await readFile(captured.file));
|
|
390
460
|
const filename = `candidates/source-${index}-${archiveDigest}.tgz`;
|
|
391
|
-
await rename(
|
|
461
|
+
await rename(captured.file, join(directory, filename));
|
|
392
462
|
dependencies[name] = 'file:' + filename;
|
|
393
463
|
provenance[name] = captured.provenance;
|
|
394
|
-
await rm(
|
|
395
|
-
await rm(output, { recursive: true, force: true });
|
|
464
|
+
await rm(staged, { recursive: true, force: true });
|
|
396
465
|
}
|
|
397
466
|
const savedManifest = input.projectDirectory
|
|
398
467
|
? JSON.parse(await readFile(join(input.projectDirectory, 'package.json'), 'utf8').catch(error => {
|
|
@@ -407,8 +476,26 @@ export class ManagedProjects {
|
|
|
407
476
|
throw error;
|
|
408
477
|
return undefined;
|
|
409
478
|
});
|
|
410
|
-
if (lock)
|
|
479
|
+
if (lock) {
|
|
411
480
|
await writeFile(join(directory, 'package-lock.json'), lock);
|
|
481
|
+
// A captured installation is sufficient for rule edits and reuse after the source/cache is gone.
|
|
482
|
+
if (localSpecs.size &&
|
|
483
|
+
!document.sources.length &&
|
|
484
|
+
isDeepStrictEqual(savedManifest.dependencies, dependencies)) {
|
|
485
|
+
const locked = JSON.parse(lock.toString());
|
|
486
|
+
checkLock(locked, true);
|
|
487
|
+
if (isDeepStrictEqual(locked.packages['']?.dependencies, dependencies)) {
|
|
488
|
+
const inspection = await inspectNpmProject(input.projectDirectory).catch(() => undefined);
|
|
489
|
+
signal.throwIfAborted();
|
|
490
|
+
if (inspection) {
|
|
491
|
+
const captured = await mkdtemp(join(directory, 'captured-'));
|
|
492
|
+
const limits = { signal, maxBytes: this.#options.maxBytes, maxFiles: this.#options.maxFiles };
|
|
493
|
+
await writeMaterials(captured, await materialFiles(input.projectDirectory, limits), limits);
|
|
494
|
+
return await consume(captured, signal, document);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
412
499
|
}
|
|
413
500
|
await writeFile(join(directory, 'package.json'), JSON.stringify({
|
|
414
501
|
...savedManifest,
|
|
@@ -430,7 +517,12 @@ export class ManagedProjects {
|
|
|
430
517
|
this.#options.registry,
|
|
431
518
|
...(this.#options.offline ? ['--offline'] : []),
|
|
432
519
|
], directory, signal);
|
|
433
|
-
|
|
520
|
+
const nextLock = JSON.parse(await readFile(join(directory, 'package-lock.json'), 'utf8'));
|
|
521
|
+
checkLock(nextLock, true);
|
|
522
|
+
const retained = new Set(Object.values(nextLock.packages).flatMap(entry => (isRecord(entry) ? [entry.resolved] : [])));
|
|
523
|
+
for (const file of await readdir(join(directory, 'candidates')))
|
|
524
|
+
if (!retained.has('file:candidates/' + file))
|
|
525
|
+
await rm(join(directory, 'candidates', file));
|
|
434
526
|
await input.onProgress?.({ stage: 'installing' });
|
|
435
527
|
await this.#npm([
|
|
436
528
|
'ci',
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Readable } from 'node:stream';
|
|
1
2
|
export type ManagedSource = {
|
|
2
3
|
kind: 'archive';
|
|
3
4
|
file: string;
|
|
@@ -16,13 +17,29 @@ export type ManagedSource = {
|
|
|
16
17
|
};
|
|
17
18
|
export interface SourceAcquisitionOptions {
|
|
18
19
|
destination: string;
|
|
20
|
+
preserveNpmArchive?: boolean;
|
|
19
21
|
signal?: AbortSignal;
|
|
20
22
|
maxBytes?: number;
|
|
21
23
|
maxFiles?: number;
|
|
22
24
|
timeoutMs?: number;
|
|
23
25
|
}
|
|
26
|
+
export declare function matchesArchiveIntegrity(bytes: Uint8Array, integrity: string): boolean;
|
|
27
|
+
interface BoundedOptions {
|
|
28
|
+
rejectPrivateFiles?: boolean;
|
|
29
|
+
signal: AbortSignal;
|
|
30
|
+
maxBytes: number;
|
|
31
|
+
maxFiles: number;
|
|
32
|
+
timeoutMs: number;
|
|
33
|
+
}
|
|
34
|
+
interface SourceFile {
|
|
35
|
+
name: string;
|
|
36
|
+
bytes: Buffer;
|
|
37
|
+
}
|
|
38
|
+
export declare function tarFiles(file: string | Readable, options: BoundedOptions): Promise<SourceFile[]>;
|
|
24
39
|
/** Only trusted host configuration supplies descriptors. HTTP callers select registered source IDs. */
|
|
25
40
|
export declare function acquireSource(source: ManagedSource, input: SourceAcquisitionOptions): Promise<{
|
|
26
41
|
directory: string;
|
|
42
|
+
archive?: string;
|
|
27
43
|
provenance: Record<string, string>;
|
|
28
44
|
}>;
|
|
45
|
+
export {};
|
package/dist/managed-sources.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { execFile } from 'node:child_process';
|
|
2
|
-
import {
|
|
2
|
+
import { sha256, sha384, sha512 } from '@noble/hashes/sha2.js';
|
|
3
3
|
import { constants, createReadStream } from 'node:fs';
|
|
4
|
-
import { mkdir, open, readdir, lstat, realpath, rm, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { mkdir, open, readdir, lstat, realpath, rename, rm, writeFile } from 'node:fs/promises';
|
|
5
5
|
import { dirname, isAbsolute, join, relative } from 'node:path';
|
|
6
6
|
import { promisify } from 'node:util';
|
|
7
7
|
import { Parser } from 'tar';
|
|
8
8
|
import yauzl from 'yauzl';
|
|
9
9
|
import { errorCode, errorMessage, isRecord } from './types.js';
|
|
10
10
|
const exec = promisify(execFile);
|
|
11
|
+
export function matchesArchiveIntegrity(bytes, integrity) {
|
|
12
|
+
const match = /^(sha256|sha384|sha512)-([A-Za-z0-9+/]+={0,2})$/.exec(integrity);
|
|
13
|
+
if (!match)
|
|
14
|
+
return false;
|
|
15
|
+
const hash = match[1] === 'sha256' ? sha256 : match[1] === 'sha384' ? sha384 : sha512;
|
|
16
|
+
return Buffer.from(hash(bytes)).toString('base64') === match[2];
|
|
17
|
+
}
|
|
11
18
|
function fail(code) {
|
|
12
19
|
throw Object.assign(new Error(code), { code });
|
|
13
20
|
}
|
|
@@ -52,6 +59,8 @@ function boundedFiles(options) {
|
|
|
52
59
|
function track(name) {
|
|
53
60
|
options.signal.throwIfAborted();
|
|
54
61
|
name = safePath(name);
|
|
62
|
+
if (options.rejectPrivateFiles && name.split('/').some(forbidden))
|
|
63
|
+
throw fail('SOURCE_PRIVATE_FILE');
|
|
55
64
|
if (++entries > options.maxFiles)
|
|
56
65
|
throw fail('SOURCE_LIMIT');
|
|
57
66
|
const key = name.normalize('NFC').toLowerCase();
|
|
@@ -114,10 +123,10 @@ async function readBounded(stream, expectedSize, options) {
|
|
|
114
123
|
abort();
|
|
115
124
|
});
|
|
116
125
|
}
|
|
117
|
-
async function tarFiles(file, options) {
|
|
126
|
+
export async function tarFiles(file, options) {
|
|
118
127
|
const output = boundedFiles(options);
|
|
119
128
|
await new Promise((resolve, reject) => {
|
|
120
|
-
const input = createReadStream(file);
|
|
129
|
+
const input = typeof file === 'string' ? createReadStream(file) : file;
|
|
121
130
|
const parser = new Parser({ strict: true, maxMetaEntrySize: 64 * 1024, maxDecompressionRatio: 1000 });
|
|
122
131
|
let failed = false;
|
|
123
132
|
const stop = (error) => {
|
|
@@ -320,10 +329,7 @@ async function download(source, file, options) {
|
|
|
320
329
|
const tokens = source.integrity.trim().split(/\s+/);
|
|
321
330
|
if (!tokens.length || tokens.some((token) => !/^sha(?:256|384|512)-[A-Za-z0-9+/]+={0,2}$/.test(token)))
|
|
322
331
|
throw fail('SOURCE_INTEGRITY_INVALID');
|
|
323
|
-
if (!tokens.some((token) =>
|
|
324
|
-
const [algorithm, expected] = token.split('-');
|
|
325
|
-
return createHash(algorithm).update(bytes).digest('base64') === expected;
|
|
326
|
-
}))
|
|
332
|
+
if (!tokens.some((token) => matchesArchiveIntegrity(bytes, token)))
|
|
327
333
|
throw fail('SOURCE_INTEGRITY_MISMATCH');
|
|
328
334
|
}
|
|
329
335
|
await writeFile(file, bytes, { flag: 'wx', mode: 0o600 });
|
|
@@ -359,6 +365,7 @@ async function gitArchive(source, root, options) {
|
|
|
359
365
|
SystemRoot: process.env.SystemRoot,
|
|
360
366
|
HOME: root,
|
|
361
367
|
GIT_CONFIG_NOSYSTEM: '1',
|
|
368
|
+
...(process.env.GIT_SSL_CAINFO ? { GIT_SSL_CAINFO: process.env.GIT_SSL_CAINFO } : {}),
|
|
362
369
|
GIT_CONFIG_GLOBAL: join(root, 'no-config'),
|
|
363
370
|
GIT_TERMINAL_PROMPT: '0',
|
|
364
371
|
};
|
|
@@ -466,6 +473,7 @@ export async function acquireSource(source, input) {
|
|
|
466
473
|
try {
|
|
467
474
|
const scratch = join(input.destination, '.source');
|
|
468
475
|
await mkdir(scratch);
|
|
476
|
+
let original;
|
|
469
477
|
let files, provenance;
|
|
470
478
|
if (source.kind === 'directory') {
|
|
471
479
|
if (typeof source.directory !== 'string' || !isAbsolute(source.directory))
|
|
@@ -502,7 +510,14 @@ export async function acquireSource(source, input) {
|
|
|
502
510
|
finally {
|
|
503
511
|
await handle.close();
|
|
504
512
|
}
|
|
505
|
-
|
|
513
|
+
if (magic.readUInt32LE(0) === 0x04034b50)
|
|
514
|
+
files = await zipFiles(file, options);
|
|
515
|
+
else {
|
|
516
|
+
const preserve = source.kind === 'url' && !!input.preserveNpmArchive && magic.readUInt16LE(0) === 0x8b1f;
|
|
517
|
+
files = await tarFiles(file, { ...options, rejectPrivateFiles: preserve });
|
|
518
|
+
if (preserve && files.every(entry => entry.name.startsWith('package/')))
|
|
519
|
+
original = file;
|
|
520
|
+
}
|
|
506
521
|
}
|
|
507
522
|
const packageFiles = files.filter(file => file.name === 'package.json' || file.name.endsWith('/package.json'));
|
|
508
523
|
const rootManifest = packageFiles.find(file => file.name === 'package.json');
|
|
@@ -526,8 +541,11 @@ export async function acquireSource(source, input) {
|
|
|
526
541
|
await mkdir(dirname(output), { recursive: true });
|
|
527
542
|
await writeFile(output, file.bytes, { flag: 'wx', mode: 0o600 });
|
|
528
543
|
}
|
|
544
|
+
const archive = original && prefix === 'package/' ? join(input.destination, 'verified.tgz') : undefined;
|
|
545
|
+
if (original && archive)
|
|
546
|
+
await rename(original, archive);
|
|
529
547
|
await rm(scratch, { recursive: true, force: true });
|
|
530
|
-
return { directory, provenance: { ...provenance, name: manifest.name, version: manifest.version } };
|
|
548
|
+
return { directory, archive, provenance: { ...provenance, name: manifest.name, version: manifest.version } };
|
|
531
549
|
}
|
|
532
550
|
catch (error) {
|
|
533
551
|
await rm(input.destination, { recursive: true, force: true });
|