@kubohiroya/sb3-toolchain 0.11.0 → 0.13.0
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/CHANGELOG.md +30 -4
- package/README.ja.md +17 -1
- package/README.md +17 -1
- package/dist/archive.d.ts +1 -0
- package/dist/archive.js +16 -0
- package/dist/archive.js.map +1 -0
- package/dist/assert.d.ts +2 -0
- package/dist/assert.js +11 -0
- package/dist/assert.js.map +1 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +12 -0
- package/dist/bin.js.map +1 -0
- package/dist/build.d.ts +23 -0
- package/dist/build.js +111 -0
- package/dist/build.js.map +1 -0
- package/dist/cli.d.ts +87 -0
- package/dist/cli.js +544 -0
- package/dist/cli.js.map +1 -0
- package/dist/constants.d.ts +2 -0
- package/dist/constants.js +7 -0
- package/dist/constants.js.map +1 -0
- package/dist/extension-api-manifest.d.ts +65 -0
- package/dist/extension-api-manifest.js +231 -0
- package/dist/extension-api-manifest.js.map +1 -0
- package/dist/extension-bundle-archive.d.ts +36 -0
- package/dist/extension-bundle-archive.js +302 -0
- package/dist/extension-bundle-archive.js.map +1 -0
- package/dist/extension-bundle-configuration.d.ts +55 -0
- package/dist/extension-bundle-configuration.js +200 -0
- package/dist/extension-bundle-configuration.js.map +1 -0
- package/dist/extension-bundle.d.ts +39 -0
- package/dist/extension-bundle.js +580 -0
- package/dist/extension-bundle.js.map +1 -0
- package/dist/extension-dependencies.d.ts +18 -0
- package/dist/extension-dependencies.js +59 -0
- package/dist/extension-dependencies.js.map +1 -0
- package/dist/extension-id-migration.d.ts +83 -0
- package/dist/extension-id-migration.js +292 -0
- package/dist/extension-id-migration.js.map +1 -0
- package/dist/extension-sync.d.ts +111 -0
- package/dist/extension-sync.js +463 -0
- package/dist/extension-sync.js.map +1 -0
- package/dist/import.d.ts +39 -0
- package/dist/import.js +244 -0
- package/dist/import.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +18 -0
- package/dist/npm-extension-source.d.ts +13 -0
- package/dist/npm-extension-source.js +63 -0
- package/dist/npm-extension-source.js.map +1 -0
- package/dist/output-safety.d.ts +29 -0
- package/dist/output-safety.js +213 -0
- package/dist/output-safety.js.map +1 -0
- package/dist/project-asset-additions.d.ts +29 -0
- package/dist/project-asset-additions.js +412 -0
- package/dist/project-asset-additions.js.map +1 -0
- package/dist/release-snapshot.d.ts +75 -0
- package/dist/release-snapshot.js +177 -0
- package/dist/release-snapshot.js.map +1 -0
- package/dist/source.d.ts +41 -0
- package/dist/source.js +282 -0
- package/dist/source.js.map +1 -0
- package/dist/turbowarp-clean-up.d.ts +18 -0
- package/dist/turbowarp-clean-up.js +266 -0
- package/dist/turbowarp-clean-up.js.map +1 -0
- package/dist/types.d.ts +80 -0
- package/package.json +31 -20
- package/bin/sb3-toolchain.mjs +0 -9
- package/src/archive.js +0 -35
- package/src/build.js +0 -188
- package/src/cli.js +0 -748
- package/src/constants.js +0 -4
- package/src/extension-api-manifest.js +0 -336
- package/src/extension-bundle-archive.js +0 -422
- package/src/extension-bundle-configuration.js +0 -265
- package/src/extension-bundle.js +0 -695
- package/src/extension-dependencies.js +0 -114
- package/src/extension-id-migration.js +0 -496
- package/src/extension-sync.js +0 -754
- package/src/import.js +0 -397
- package/src/index.js +0 -75
- package/src/npm-extension-source.js +0 -111
- package/src/output-safety.js +0 -322
- package/src/project-asset-additions.js +0 -560
- package/src/release-snapshot.js +0 -247
- package/src/source.js +0 -468
- package/src/turbowarp-clean-up.js +0 -295
package/src/output-safety.js
DELETED
|
@@ -1,322 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: MPL-2.0
|
|
2
|
-
|
|
3
|
-
import {execFile} from 'node:child_process';
|
|
4
|
-
import {createHash, randomUUID} from 'node:crypto';
|
|
5
|
-
import {access, lstat, realpath, readdir, readFile, readlink, rename, rm} from 'node:fs/promises';
|
|
6
|
-
import path from 'node:path';
|
|
7
|
-
|
|
8
|
-
function assert(condition, message) {
|
|
9
|
-
if (!condition) {
|
|
10
|
-
throw new Error(message);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export async function pathExists(targetPath) {
|
|
15
|
-
try {
|
|
16
|
-
await access(targetPath);
|
|
17
|
-
return true;
|
|
18
|
-
} catch (error) {
|
|
19
|
-
if (error?.code === 'ENOENT') {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
throw error;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function isSamePathOrAncestor(candidatePath, targetPath) {
|
|
27
|
-
const relativePath = path.relative(candidatePath, targetPath);
|
|
28
|
-
return (
|
|
29
|
-
relativePath === '' ||
|
|
30
|
-
(relativePath !== '..' &&
|
|
31
|
-
!relativePath.startsWith(`..${path.sep}`) &&
|
|
32
|
-
!path.isAbsolute(relativePath))
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function validateOutputDirectoryPath(outputDirectory, protectedRoot) {
|
|
37
|
-
const resolvedOutputDirectory = path.resolve(outputDirectory);
|
|
38
|
-
const resolvedProtectedRoot = path.resolve(protectedRoot);
|
|
39
|
-
assert(
|
|
40
|
-
resolvedOutputDirectory !== path.parse(resolvedOutputDirectory).root,
|
|
41
|
-
'Refusing to replace a filesystem root with imported SB3 sources.',
|
|
42
|
-
);
|
|
43
|
-
assert(
|
|
44
|
-
!isSamePathOrAncestor(resolvedOutputDirectory, resolvedProtectedRoot),
|
|
45
|
-
'Refusing to replace the repository root or one of its ancestors.',
|
|
46
|
-
);
|
|
47
|
-
assert(
|
|
48
|
-
!resolvedOutputDirectory.split(path.sep).includes('.git'),
|
|
49
|
-
'Refusing to write imported SB3 sources into a .git directory.',
|
|
50
|
-
);
|
|
51
|
-
return resolvedOutputDirectory;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export async function assertRecognizedOutputDirectory(outputDirectory, sourceFormatVersion) {
|
|
55
|
-
const stats = await lstat(outputDirectory);
|
|
56
|
-
assert(
|
|
57
|
-
stats.isDirectory() && !stats.isSymbolicLink(),
|
|
58
|
-
`Refusing to replace a non-directory or symbolic link: ${outputDirectory}`,
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
let manifest;
|
|
62
|
-
try {
|
|
63
|
-
manifest = JSON.parse(await readFile(path.join(outputDirectory, 'sb3-source.json'), 'utf8'));
|
|
64
|
-
} catch (error) {
|
|
65
|
-
if (error?.code !== 'ENOENT' && !(error instanceof SyntaxError)) {
|
|
66
|
-
throw error;
|
|
67
|
-
}
|
|
68
|
-
throw new Error(
|
|
69
|
-
`Refusing to replace an unrecognized directory without a valid sb3-source.json: ${outputDirectory}`,
|
|
70
|
-
{cause: error},
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
assert(
|
|
75
|
-
manifest?.formatVersion === sourceFormatVersion &&
|
|
76
|
-
manifest.project === 'project.source.json' &&
|
|
77
|
-
manifest.embeddedExtensions === 'embedded-extensions.json' &&
|
|
78
|
-
manifest.assetsDirectory === 'assets' &&
|
|
79
|
-
Array.isArray(manifest.archiveEntries),
|
|
80
|
-
`Refusing to replace an unrecognized directory without a valid sb3-source.json: ${outputDirectory}`,
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function digest(value) {
|
|
85
|
-
return createHash('sha256').update(value).digest('hex');
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
async function snapshotDirectory(rootDirectory) {
|
|
89
|
-
const snapshot = new Map();
|
|
90
|
-
|
|
91
|
-
async function visit(directory, relativeDirectory) {
|
|
92
|
-
const entries = await readdir(directory, {withFileTypes: true});
|
|
93
|
-
entries.sort((left, right) => (left.name < right.name ? -1 : left.name > right.name ? 1 : 0));
|
|
94
|
-
|
|
95
|
-
for (const entry of entries) {
|
|
96
|
-
const relativePath = relativeDirectory
|
|
97
|
-
? path.posix.join(relativeDirectory, entry.name)
|
|
98
|
-
: entry.name;
|
|
99
|
-
const absolutePath = path.join(directory, entry.name);
|
|
100
|
-
if (entry.isDirectory()) {
|
|
101
|
-
snapshot.set(relativePath, {type: 'directory'});
|
|
102
|
-
await visit(absolutePath, relativePath);
|
|
103
|
-
} else if (entry.isFile()) {
|
|
104
|
-
const contents = await readFile(absolutePath);
|
|
105
|
-
snapshot.set(relativePath, {
|
|
106
|
-
type: 'file',
|
|
107
|
-
size: contents.length,
|
|
108
|
-
digest: digest(contents),
|
|
109
|
-
});
|
|
110
|
-
} else if (entry.isSymbolicLink()) {
|
|
111
|
-
snapshot.set(relativePath, {
|
|
112
|
-
type: 'symbolic-link',
|
|
113
|
-
target: await readlink(absolutePath),
|
|
114
|
-
});
|
|
115
|
-
} else {
|
|
116
|
-
snapshot.set(relativePath, {type: 'other'});
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
await visit(rootDirectory, '');
|
|
122
|
-
return snapshot;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function snapshotFingerprint(snapshot) {
|
|
126
|
-
return digest(JSON.stringify([...snapshot.entries()]));
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function entriesMatch(left, right) {
|
|
130
|
-
return JSON.stringify(left) === JSON.stringify(right);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export async function compareDirectories(existingDirectory, candidateDirectory) {
|
|
134
|
-
const [existingSnapshot, candidateSnapshot] = await Promise.all([
|
|
135
|
-
snapshotDirectory(existingDirectory),
|
|
136
|
-
snapshotDirectory(candidateDirectory),
|
|
137
|
-
]);
|
|
138
|
-
const paths = [...new Set([...existingSnapshot.keys(), ...candidateSnapshot.keys()])].sort();
|
|
139
|
-
const differences = {added: [], modified: [], removed: []};
|
|
140
|
-
|
|
141
|
-
for (const relativePath of paths) {
|
|
142
|
-
const existingEntry = existingSnapshot.get(relativePath);
|
|
143
|
-
const candidateEntry = candidateSnapshot.get(relativePath);
|
|
144
|
-
if (!existingEntry) {
|
|
145
|
-
differences.added.push(relativePath);
|
|
146
|
-
} else if (!candidateEntry) {
|
|
147
|
-
differences.removed.push(relativePath);
|
|
148
|
-
} else if (!entriesMatch(existingEntry, candidateEntry)) {
|
|
149
|
-
differences.modified.push(relativePath);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
return {
|
|
154
|
-
candidateFingerprint: snapshotFingerprint(candidateSnapshot),
|
|
155
|
-
differences,
|
|
156
|
-
existingFilePaths: [...existingSnapshot.entries()]
|
|
157
|
-
.filter(([, entry]) => entry.type !== 'directory')
|
|
158
|
-
.map(([relativePath]) => relativePath),
|
|
159
|
-
existingFingerprint: snapshotFingerprint(existingSnapshot),
|
|
160
|
-
identical: Object.values(differences).every((entries) => entries.length === 0),
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function executeGit(arguments_, cwd) {
|
|
165
|
-
return new Promise((resolve, reject) => {
|
|
166
|
-
execFile(
|
|
167
|
-
'git',
|
|
168
|
-
arguments_,
|
|
169
|
-
{cwd, encoding: 'utf8', maxBuffer: 10 * 1024 * 1024},
|
|
170
|
-
(error, stdout, stderr) => {
|
|
171
|
-
if (error) {
|
|
172
|
-
error.stdout = stdout;
|
|
173
|
-
error.stderr = stderr;
|
|
174
|
-
reject(error);
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
resolve(stdout);
|
|
178
|
-
},
|
|
179
|
-
);
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function toPosixPath(value) {
|
|
184
|
-
return value.split(path.sep).join('/');
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export async function inspectGitOutputState(outputDirectory, existingFilePaths) {
|
|
188
|
-
let repositoryRoot;
|
|
189
|
-
try {
|
|
190
|
-
repositoryRoot = (await executeGit(['rev-parse', '--show-toplevel'], outputDirectory)).trim();
|
|
191
|
-
} catch (error) {
|
|
192
|
-
if (error?.code === 128) {
|
|
193
|
-
return {
|
|
194
|
-
clean: false,
|
|
195
|
-
fingerprint: 'not-git-managed',
|
|
196
|
-
managed: false,
|
|
197
|
-
repositoryRoot: null,
|
|
198
|
-
statusEntries: [],
|
|
199
|
-
untrackedContent: [...existingFilePaths],
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
throw error;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const [canonicalOutputDirectory, canonicalRepositoryRoot] = await Promise.all([
|
|
206
|
-
realpath(outputDirectory),
|
|
207
|
-
realpath(repositoryRoot),
|
|
208
|
-
]);
|
|
209
|
-
repositoryRoot = canonicalRepositoryRoot;
|
|
210
|
-
const relativeOutputDirectory = path.relative(repositoryRoot, canonicalOutputDirectory);
|
|
211
|
-
assert(
|
|
212
|
-
relativeOutputDirectory !== '..' &&
|
|
213
|
-
!relativeOutputDirectory.startsWith(`..${path.sep}`) &&
|
|
214
|
-
!path.isAbsolute(relativeOutputDirectory),
|
|
215
|
-
`Output directory is outside its detected Git worktree: ${outputDirectory}`,
|
|
216
|
-
);
|
|
217
|
-
const pathspec = relativeOutputDirectory || '.';
|
|
218
|
-
const [statusOutput, trackedOutput] = await Promise.all([
|
|
219
|
-
executeGit(
|
|
220
|
-
['status', '--porcelain=v1', '--untracked-files=all', '--', pathspec],
|
|
221
|
-
repositoryRoot,
|
|
222
|
-
),
|
|
223
|
-
executeGit(['ls-files', '-z', '--', pathspec], repositoryRoot),
|
|
224
|
-
]);
|
|
225
|
-
const statusEntries = statusOutput.split('\n').filter(Boolean);
|
|
226
|
-
const trackedPaths = new Set(
|
|
227
|
-
trackedOutput
|
|
228
|
-
.split('\0')
|
|
229
|
-
.filter(Boolean)
|
|
230
|
-
.map((trackedPath) =>
|
|
231
|
-
toPosixPath(
|
|
232
|
-
path.relative(canonicalOutputDirectory, path.join(repositoryRoot, trackedPath)),
|
|
233
|
-
),
|
|
234
|
-
),
|
|
235
|
-
);
|
|
236
|
-
const untrackedContent = existingFilePaths.filter((filePath) => !trackedPaths.has(filePath));
|
|
237
|
-
const managed = trackedPaths.size > 0;
|
|
238
|
-
const clean = managed && statusEntries.length === 0 && untrackedContent.length === 0;
|
|
239
|
-
const fingerprint = digest(
|
|
240
|
-
JSON.stringify({
|
|
241
|
-
clean,
|
|
242
|
-
managed,
|
|
243
|
-
repositoryRoot,
|
|
244
|
-
statusEntries,
|
|
245
|
-
trackedPaths: [...trackedPaths].sort(),
|
|
246
|
-
untrackedContent: [...untrackedContent].sort(),
|
|
247
|
-
}),
|
|
248
|
-
);
|
|
249
|
-
|
|
250
|
-
return {
|
|
251
|
-
clean,
|
|
252
|
-
fingerprint,
|
|
253
|
-
managed,
|
|
254
|
-
repositoryRoot,
|
|
255
|
-
statusEntries,
|
|
256
|
-
untrackedContent,
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
export async function assertNoInterruptedRollback(outputDirectory) {
|
|
261
|
-
const parentDirectory = path.dirname(outputDirectory);
|
|
262
|
-
const outputName = path.basename(outputDirectory);
|
|
263
|
-
const rollbackPrefixes = [`.${outputName}.rollback-`, `.${outputName}.backup-`];
|
|
264
|
-
const leftovers = (await readdir(parentDirectory))
|
|
265
|
-
.filter((entryName) => rollbackPrefixes.some((prefix) => entryName.startsWith(prefix)))
|
|
266
|
-
.map((entryName) => path.join(parentDirectory, entryName));
|
|
267
|
-
assert(
|
|
268
|
-
leftovers.length === 0,
|
|
269
|
-
`Found an interrupted SB3 import rollback directory. ` +
|
|
270
|
-
`Inspect or restore it before retrying: ${leftovers.join(', ')}`,
|
|
271
|
-
);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
export async function replaceDirectoryTransactionally(temporaryDirectory, outputDirectory) {
|
|
275
|
-
const parentDirectory = path.dirname(outputDirectory);
|
|
276
|
-
await assertNoInterruptedRollback(outputDirectory);
|
|
277
|
-
const rollbackDirectory = path.join(
|
|
278
|
-
parentDirectory,
|
|
279
|
-
`.${path.basename(outputDirectory)}.rollback-${randomUUID()}`,
|
|
280
|
-
);
|
|
281
|
-
assert(
|
|
282
|
-
!(await pathExists(rollbackDirectory)),
|
|
283
|
-
`Refusing to overwrite an existing rollback directory: ${rollbackDirectory}`,
|
|
284
|
-
);
|
|
285
|
-
const outputExists = await pathExists(outputDirectory);
|
|
286
|
-
|
|
287
|
-
if (outputExists) {
|
|
288
|
-
await rename(outputDirectory, rollbackDirectory);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
try {
|
|
292
|
-
await rename(temporaryDirectory, outputDirectory);
|
|
293
|
-
} catch (installError) {
|
|
294
|
-
if (outputExists) {
|
|
295
|
-
try {
|
|
296
|
-
await rename(rollbackDirectory, outputDirectory);
|
|
297
|
-
} catch (restoreError) {
|
|
298
|
-
throw new AggregateError(
|
|
299
|
-
[installError, restoreError],
|
|
300
|
-
`SB3 import failed and automatic restoration also failed. ` +
|
|
301
|
-
`Original output remains at: ${rollbackDirectory}`,
|
|
302
|
-
);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
throw installError;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
if (!outputExists) {
|
|
309
|
-
return {rollbackCleanupWarning: null};
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
try {
|
|
313
|
-
await rm(rollbackDirectory, {recursive: true});
|
|
314
|
-
return {rollbackCleanupWarning: null};
|
|
315
|
-
} catch (error) {
|
|
316
|
-
return {
|
|
317
|
-
rollbackCleanupWarning:
|
|
318
|
-
`Imported output was installed, but its temporary rollback ` +
|
|
319
|
-
`directory could not be removed: ${rollbackDirectory} (${error.message})`,
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
}
|