@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
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import type { EnvironmentDocumentV2 } from './debug-environments.js';
|
|
2
|
+
type Material = {
|
|
3
|
+
path: string;
|
|
4
|
+
bytes: Buffer;
|
|
5
|
+
};
|
|
6
|
+
type Host = {
|
|
7
|
+
bundledPackageRoot?: string;
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
maxBytes?: number;
|
|
10
|
+
maxFiles?: number;
|
|
11
|
+
};
|
|
12
|
+
export declare function isBaseMaterial(path: string): boolean;
|
|
13
|
+
/** Transfer only membership of the host base. Rebuild its installation and lock from the receiving host. */
|
|
14
|
+
export declare function environmentShareMaterials(files: Material[], document: EnvironmentDocumentV2, receiver?: Host): Promise<{
|
|
15
|
+
files: Material[];
|
|
16
|
+
document: {
|
|
17
|
+
id: string;
|
|
18
|
+
name: string;
|
|
19
|
+
packages: Record<string, string>;
|
|
20
|
+
sources: string[];
|
|
21
|
+
schemaVersion: 2;
|
|
22
|
+
rules: {
|
|
23
|
+
schemaVersion: 1 | 2;
|
|
24
|
+
mechanics?: {
|
|
25
|
+
skillSlots?: {
|
|
26
|
+
normalMax: number;
|
|
27
|
+
climaxMax: number;
|
|
28
|
+
climaxMin?: number | undefined;
|
|
29
|
+
} | undefined;
|
|
30
|
+
individualValueDefault?: number | undefined;
|
|
31
|
+
individualValues?: {
|
|
32
|
+
max: number;
|
|
33
|
+
} | undefined;
|
|
34
|
+
allowFaintSwitch?: boolean | undefined;
|
|
35
|
+
inheritance?: {
|
|
36
|
+
eligible: "all" | "off" | "species" | string[];
|
|
37
|
+
pool?: {
|
|
38
|
+
mode: "append" | "fallback" | "replace";
|
|
39
|
+
skills: string[];
|
|
40
|
+
} | undefined;
|
|
41
|
+
} | undefined;
|
|
42
|
+
enhancement?: {
|
|
43
|
+
mode: "active" | "forbidden" | "suppressed";
|
|
44
|
+
stages?: string[] | undefined;
|
|
45
|
+
species?: string[] | undefined;
|
|
46
|
+
} | undefined;
|
|
47
|
+
secondGenerationNatures?: "all" | "off" | "species" | string[] | undefined;
|
|
48
|
+
} | undefined;
|
|
49
|
+
skillParameters?: {
|
|
50
|
+
profile?: string | undefined;
|
|
51
|
+
groups?: Record<string, number> | undefined;
|
|
52
|
+
overrides?: {
|
|
53
|
+
skill: string;
|
|
54
|
+
useId: string;
|
|
55
|
+
parameter: string;
|
|
56
|
+
value: number;
|
|
57
|
+
}[] | undefined;
|
|
58
|
+
} | undefined;
|
|
59
|
+
matchups?: {
|
|
60
|
+
table?: string | undefined;
|
|
61
|
+
adjustments?: {
|
|
62
|
+
attack: string;
|
|
63
|
+
defense: string;
|
|
64
|
+
multiplier: number;
|
|
65
|
+
}[] | undefined;
|
|
66
|
+
} | undefined;
|
|
67
|
+
learnsetAdjustments?: {
|
|
68
|
+
species: string;
|
|
69
|
+
source: "inherited" | "normal";
|
|
70
|
+
skill: string;
|
|
71
|
+
action: "add" | "remove";
|
|
72
|
+
level?: number | undefined;
|
|
73
|
+
}[] | undefined;
|
|
74
|
+
tier?: "standard" | undefined;
|
|
75
|
+
allow?: {
|
|
76
|
+
species?: string[] | undefined;
|
|
77
|
+
skills?: string[] | undefined;
|
|
78
|
+
marks?: string[] | undefined;
|
|
79
|
+
} | undefined;
|
|
80
|
+
deny?: {
|
|
81
|
+
species?: string[] | undefined;
|
|
82
|
+
skills?: string[] | undefined;
|
|
83
|
+
marks?: string[] | undefined;
|
|
84
|
+
} | undefined;
|
|
85
|
+
team?: {
|
|
86
|
+
minSize?: number | undefined;
|
|
87
|
+
maxSize?: number | undefined;
|
|
88
|
+
uniqueSpecies?: boolean | undefined;
|
|
89
|
+
} | undefined;
|
|
90
|
+
constraints?: ({
|
|
91
|
+
id: string;
|
|
92
|
+
allOf: {
|
|
93
|
+
kind: "mark" | "skill" | "species";
|
|
94
|
+
ids: string[];
|
|
95
|
+
fromCollections?: string[] | undefined;
|
|
96
|
+
}[];
|
|
97
|
+
kind: "ban";
|
|
98
|
+
scope: "pet" | "team";
|
|
99
|
+
exceptWhen?: {
|
|
100
|
+
kind: "mark" | "skill" | "species";
|
|
101
|
+
ids: string[];
|
|
102
|
+
fromCollections?: string[] | undefined;
|
|
103
|
+
}[] | undefined;
|
|
104
|
+
exceptAny?: {
|
|
105
|
+
kind: "mark" | "skill" | "species";
|
|
106
|
+
ids: string[];
|
|
107
|
+
fromCollections?: string[] | undefined;
|
|
108
|
+
}[][] | undefined;
|
|
109
|
+
} | {
|
|
110
|
+
id: string;
|
|
111
|
+
allOf: {
|
|
112
|
+
kind: "mark" | "skill" | "species";
|
|
113
|
+
ids: string[];
|
|
114
|
+
fromCollections?: string[] | undefined;
|
|
115
|
+
}[];
|
|
116
|
+
kind: "memberLimit";
|
|
117
|
+
max: number;
|
|
118
|
+
})[] | undefined;
|
|
119
|
+
collections?: {
|
|
120
|
+
id: string;
|
|
121
|
+
kind: "mark" | "skill" | "species";
|
|
122
|
+
ids: string[];
|
|
123
|
+
}[] | undefined;
|
|
124
|
+
include?: string[] | undefined;
|
|
125
|
+
constraintEdits?: {
|
|
126
|
+
remove?: string[] | undefined;
|
|
127
|
+
replace?: ({
|
|
128
|
+
id: string;
|
|
129
|
+
allOf: {
|
|
130
|
+
kind: "mark" | "skill" | "species";
|
|
131
|
+
ids: string[];
|
|
132
|
+
fromCollections?: string[] | undefined;
|
|
133
|
+
}[];
|
|
134
|
+
kind: "ban";
|
|
135
|
+
scope: "pet" | "team";
|
|
136
|
+
exceptWhen?: {
|
|
137
|
+
kind: "mark" | "skill" | "species";
|
|
138
|
+
ids: string[];
|
|
139
|
+
fromCollections?: string[] | undefined;
|
|
140
|
+
}[] | undefined;
|
|
141
|
+
exceptAny?: {
|
|
142
|
+
kind: "mark" | "skill" | "species";
|
|
143
|
+
ids: string[];
|
|
144
|
+
fromCollections?: string[] | undefined;
|
|
145
|
+
}[][] | undefined;
|
|
146
|
+
} | {
|
|
147
|
+
id: string;
|
|
148
|
+
allOf: {
|
|
149
|
+
kind: "mark" | "skill" | "species";
|
|
150
|
+
ids: string[];
|
|
151
|
+
fromCollections?: string[] | undefined;
|
|
152
|
+
}[];
|
|
153
|
+
kind: "memberLimit";
|
|
154
|
+
max: number;
|
|
155
|
+
})[] | undefined;
|
|
156
|
+
clearExceptions?: string[] | undefined;
|
|
157
|
+
exceptions?: {
|
|
158
|
+
target: string;
|
|
159
|
+
allOf: {
|
|
160
|
+
kind: "mark" | "skill" | "species";
|
|
161
|
+
ids: string[];
|
|
162
|
+
fromCollections?: string[] | undefined;
|
|
163
|
+
}[];
|
|
164
|
+
}[] | undefined;
|
|
165
|
+
} | undefined;
|
|
166
|
+
};
|
|
167
|
+
requires: {
|
|
168
|
+
engine?: string | undefined;
|
|
169
|
+
sdk?: string | undefined;
|
|
170
|
+
capabilities?: string[] | undefined;
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
usesBase: boolean;
|
|
174
|
+
}>;
|
|
175
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { sha256Hex } from '@arcadia-eternity/const';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { readFile } from 'node:fs/promises';
|
|
4
|
+
import { withShippedEnvironmentProject, withShippedCatalogArchive } from '@arcadia-eternity/pack-loader/node';
|
|
5
|
+
import { contentError, materialFiles } from './workspace-materials.js';
|
|
6
|
+
const hostBaseName = '@arcadia-eternity/data-pack-base';
|
|
7
|
+
const baseLocation = 'node_modules/' + hostBaseName;
|
|
8
|
+
export function isBaseMaterial(path) {
|
|
9
|
+
return ('/' + path.toLowerCase() + '/').includes('/' + baseLocation + '/');
|
|
10
|
+
}
|
|
11
|
+
/** Transfer only membership of the host base. Rebuild its installation and lock from the receiving host. */
|
|
12
|
+
export async function environmentShareMaterials(files, document, receiver) {
|
|
13
|
+
const manifestFile = files.find(file => file.path === 'package.json');
|
|
14
|
+
const lockFile = files.find(file => file.path === 'package-lock.json');
|
|
15
|
+
const manifest = JSON.parse(manifestFile.bytes.toString());
|
|
16
|
+
const lock = JSON.parse(lockFile.bytes.toString());
|
|
17
|
+
let hasBase = Object.hasOwn(document.packages, hostBaseName) || document.sources.includes(hostBaseName);
|
|
18
|
+
const candidates = new Set();
|
|
19
|
+
for (const [location, entry] of Object.entries(lock.packages)) {
|
|
20
|
+
if (isBaseMaterial(location)) {
|
|
21
|
+
// An enclosing npm tarball can itself contain the base. Its bytes cannot be split without breaking its integrity.
|
|
22
|
+
if (entry.inBundle)
|
|
23
|
+
throw contentError('BUNDLED_BASE_IN_DEPENDENCY', '请将基础包从第三方包的内嵌依赖中移除后再分享。');
|
|
24
|
+
hasBase = true;
|
|
25
|
+
delete lock.packages[location];
|
|
26
|
+
}
|
|
27
|
+
else if (location && entry.name === hostBaseName) {
|
|
28
|
+
throw contentError('BUNDLED_BASE_ALIAS', '请使用基础包的正式包名。');
|
|
29
|
+
}
|
|
30
|
+
else if (entry.resolved?.startsWith('file:'))
|
|
31
|
+
candidates.add(entry.resolved.slice(5));
|
|
32
|
+
}
|
|
33
|
+
// Startup synchronization can leave old base archives with arbitrary candidate filenames.
|
|
34
|
+
const portable = files.filter(file => !isBaseMaterial(file.path) && (!file.path.startsWith('candidates/') || candidates.has(file.path)));
|
|
35
|
+
if (!hasBase)
|
|
36
|
+
return { files: portable, document, usesBase: false };
|
|
37
|
+
const sources = document.sources.filter(name => name !== hostBaseName);
|
|
38
|
+
let version = '*';
|
|
39
|
+
let spec = version;
|
|
40
|
+
const materials = portable.filter(file => file !== manifestFile && file !== lockFile && file.path !== 'node_modules/.package-lock.json');
|
|
41
|
+
if (receiver) {
|
|
42
|
+
if (!receiver.bundledPackageRoot)
|
|
43
|
+
throw contentError('BUNDLED_PACKAGE_UNAVAILABLE', '接收端缺少内置基础包。');
|
|
44
|
+
const shipped = await withShippedEnvironmentProject(receiver.bundledPackageRoot, dir => materialFiles(dir, { ...receiver, subtree: baseLocation }));
|
|
45
|
+
const pkg = shipped.find(file => file.path === baseLocation + '/package.json');
|
|
46
|
+
if (!pkg)
|
|
47
|
+
throw contentError('BUNDLED_PACKAGE_INVALID');
|
|
48
|
+
const installed = JSON.parse(pkg.bytes.toString());
|
|
49
|
+
if (installed.name !== hostBaseName || typeof installed.version !== 'string')
|
|
50
|
+
throw contentError('BUNDLED_PACKAGE_INVALID');
|
|
51
|
+
version = installed.version;
|
|
52
|
+
materials.push(...shipped);
|
|
53
|
+
spec = version;
|
|
54
|
+
const entry = {
|
|
55
|
+
name: hostBaseName,
|
|
56
|
+
version,
|
|
57
|
+
};
|
|
58
|
+
// Mixed projects use the same local npm candidate as a normal managed installation.
|
|
59
|
+
if (Object.keys(lock.packages).some(location => location && location !== baseLocation)) {
|
|
60
|
+
const bytes = await withShippedCatalogArchive(receiver.bundledPackageRoot, undefined, path => readFile(path));
|
|
61
|
+
const path = 'candidates/base-' + sha256Hex(bytes) + '.tgz';
|
|
62
|
+
spec = 'file:' + path;
|
|
63
|
+
entry.resolved = spec;
|
|
64
|
+
entry.integrity = 'sha512-' + createHash('sha512').update(bytes).digest('base64');
|
|
65
|
+
materials.push({ path, bytes });
|
|
66
|
+
}
|
|
67
|
+
lock.packages[baseLocation] = entry;
|
|
68
|
+
}
|
|
69
|
+
manifest.dependencies = { ...manifest.dependencies, [hostBaseName]: spec };
|
|
70
|
+
if (manifest.arcadiaManagedSources)
|
|
71
|
+
delete manifest.arcadiaManagedSources[hostBaseName];
|
|
72
|
+
if (manifest.arcadiaEnvironment)
|
|
73
|
+
manifest.arcadiaEnvironment.sources = sources;
|
|
74
|
+
lock.packages[''] = { ...lock.packages[''], dependencies: manifest.dependencies };
|
|
75
|
+
// Version 2 locks may also carry npm's redundant legacy dependency tree.
|
|
76
|
+
if (lock.lockfileVersion === 2) {
|
|
77
|
+
delete lock.dependencies;
|
|
78
|
+
lock.lockfileVersion = 3;
|
|
79
|
+
}
|
|
80
|
+
materials.push({ path: manifestFile.path, bytes: Buffer.from(JSON.stringify(manifest)) }, { path: lockFile.path, bytes: Buffer.from(JSON.stringify(lock)) });
|
|
81
|
+
return {
|
|
82
|
+
files: materials,
|
|
83
|
+
document: { ...document, packages: { ...document.packages, [hostBaseName]: version }, sources },
|
|
84
|
+
usesBase: true,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Copy the selected installed npm subtree into a fresh project. Both inputs are read leases. */
|
|
2
|
+
export declare function copyEnvironmentMember(source: string, name: string, target: string | undefined, destination: string, signal?: AbortSignal): Promise<{
|
|
3
|
+
archive: string;
|
|
4
|
+
inspection: import("@arcadia-eternity/pack-loader/node").NpmProjectInspection;
|
|
5
|
+
}>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { sha256Hex } from '@arcadia-eternity/const';
|
|
2
|
+
import { inspectNpmProject } from '@arcadia-eternity/pack-loader/node';
|
|
3
|
+
import { contentError, materialFiles, writeMaterials } from './workspace-materials.js';
|
|
4
|
+
import { packageLocation, verifyArchive, readArchiveFiles } from './environment-sharing.js';
|
|
5
|
+
/** Copy the selected installed npm subtree into a fresh project. Both inputs are read leases. */
|
|
6
|
+
export async function copyEnvironmentMember(source, name, target, destination, signal) {
|
|
7
|
+
const inspection = await inspectNpmProject(source);
|
|
8
|
+
const root = inspection.packages.find(pkg => pkg.name === name && pkg.manifest);
|
|
9
|
+
if (!root)
|
|
10
|
+
throw contentError('ENVIRONMENT_PACKAGE_MISMATCH');
|
|
11
|
+
const materials = await materialFiles(source, { signal });
|
|
12
|
+
const groups = Map.groupBy(materials, file => packageLocation(file.path));
|
|
13
|
+
const captured = new Map(materials.map(file => [file.path, file.bytes]));
|
|
14
|
+
const files = new Map((target ? await materialFiles(target, { signal, allowMissingLock: true }) : []).map(file => [
|
|
15
|
+
file.path,
|
|
16
|
+
file.bytes,
|
|
17
|
+
]));
|
|
18
|
+
const sourceLock = JSON.parse(captured.get('package-lock.json').toString());
|
|
19
|
+
const manifest = JSON.parse(files.get('package.json')?.toString() ??
|
|
20
|
+
'{"name":"arcadia-member","version":"1.0.0","private":true,"dependencies":{}}');
|
|
21
|
+
const lock = JSON.parse(files.get('package-lock.json')?.toString() ?? '{"lockfileVersion":3,"packages":{"":{}}}');
|
|
22
|
+
const byLocation = new Map(inspection.packages.map(pkg => [pkg.location, pkg]));
|
|
23
|
+
const selected = new Set();
|
|
24
|
+
function visit(location) {
|
|
25
|
+
if (selected.has(location))
|
|
26
|
+
return;
|
|
27
|
+
selected.add(location);
|
|
28
|
+
Object.values(byLocation.get(location).dependencies).forEach(visit);
|
|
29
|
+
}
|
|
30
|
+
visit(root.location);
|
|
31
|
+
const relocate = (location) => location === root.location || location.startsWith(root.location + '/')
|
|
32
|
+
? 'node_modules/' + name + location.slice(root.location.length)
|
|
33
|
+
: location;
|
|
34
|
+
let rootArchive;
|
|
35
|
+
const copied = new Map();
|
|
36
|
+
for (const location of selected) {
|
|
37
|
+
const entry = { ...sourceLock.packages[location] };
|
|
38
|
+
if (typeof entry.resolved === 'string' && entry.resolved.startsWith('file:')) {
|
|
39
|
+
const bytes = captured.get(entry.resolved.slice(5));
|
|
40
|
+
if (!bytes || typeof entry.integrity !== 'string')
|
|
41
|
+
throw contentError('ENVIRONMENT_SOURCE_MISSING');
|
|
42
|
+
verifyArchive(bytes, entry.integrity);
|
|
43
|
+
const archive = await readArchiveFiles(bytes, { signal });
|
|
44
|
+
for (const file of groups.get(location) ?? []) {
|
|
45
|
+
if (!archive.get(file.path.slice(location.length + 1))?.equals(file.bytes))
|
|
46
|
+
throw contentError('SOURCE_INTEGRITY_MISMATCH', '已安装文件与锁定的包归档不一致');
|
|
47
|
+
}
|
|
48
|
+
const path = 'candidates/' + sha256Hex(bytes) + '.tgz';
|
|
49
|
+
copied.set(path, bytes);
|
|
50
|
+
entry.resolved = 'file:' + path;
|
|
51
|
+
if (location === root.location)
|
|
52
|
+
rootArchive = path;
|
|
53
|
+
}
|
|
54
|
+
const dest = relocate(location);
|
|
55
|
+
const previous = lock.packages[dest];
|
|
56
|
+
if (previous && (previous.version !== entry.version || previous.integrity !== entry.integrity))
|
|
57
|
+
throw contentError('ENVIRONMENT_DEPENDENCY_CONFLICT', '目标环境已使用不同的依赖版本或构建产物');
|
|
58
|
+
lock.packages[dest] = entry;
|
|
59
|
+
}
|
|
60
|
+
if (!rootArchive)
|
|
61
|
+
throw contentError('ENVIRONMENT_SOURCE_MISSING', '此内容包没有随环境保存的本地归档');
|
|
62
|
+
for (const [path, bytes] of captured) {
|
|
63
|
+
const location = packageLocation(path);
|
|
64
|
+
if (selected.has(location))
|
|
65
|
+
copied.set(relocate(location) + path.slice(location.length), bytes);
|
|
66
|
+
}
|
|
67
|
+
for (const [path, bytes] of copied) {
|
|
68
|
+
if (files.has(path) && !files.get(path).equals(bytes))
|
|
69
|
+
throw contentError('ENVIRONMENT_DEPENDENCY_CONFLICT');
|
|
70
|
+
files.set(path, bytes);
|
|
71
|
+
}
|
|
72
|
+
manifest.dependencies = { ...manifest.dependencies, [name]: 'file:' + rootArchive };
|
|
73
|
+
lock.packages[''] = {
|
|
74
|
+
...lock.packages[''],
|
|
75
|
+
name: manifest.name,
|
|
76
|
+
version: manifest.version,
|
|
77
|
+
dependencies: manifest.dependencies,
|
|
78
|
+
};
|
|
79
|
+
files.set('package.json', Buffer.from(JSON.stringify(manifest)));
|
|
80
|
+
files.set('package-lock.json', Buffer.from(JSON.stringify(lock)));
|
|
81
|
+
// npm's hidden lock describes the previous tree. The root lock owns the merged project.
|
|
82
|
+
files.delete('node_modules/.package-lock.json');
|
|
83
|
+
await writeMaterials(destination, [...files].map(([path, bytes]) => ({ path, bytes })), { signal });
|
|
84
|
+
const merged = await inspectNpmProject(destination, { includeRuleSets: true });
|
|
85
|
+
const mergedByLocation = new Map(merged.packages.map(pkg => [pkg.location, pkg]));
|
|
86
|
+
for (const location of selected) {
|
|
87
|
+
const original = byLocation.get(location);
|
|
88
|
+
const restored = mergedByLocation.get(relocate(location));
|
|
89
|
+
if (!restored ||
|
|
90
|
+
Object.entries(original.dependencies).some(([key, path]) => restored.dependencies[key] !== relocate(path))) {
|
|
91
|
+
throw contentError('ENVIRONMENT_DEPENDENCY_CONFLICT', '目标环境会改变这个包的依赖,请调整包版本');
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return { archive: rootArchive, inspection: merged };
|
|
95
|
+
}
|