@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.
Files changed (87) hide show
  1. package/CHANGELOG.md +30 -4
  2. package/README.ja.md +17 -1
  3. package/README.md +17 -1
  4. package/dist/archive.d.ts +1 -0
  5. package/dist/archive.js +16 -0
  6. package/dist/archive.js.map +1 -0
  7. package/dist/assert.d.ts +2 -0
  8. package/dist/assert.js +11 -0
  9. package/dist/assert.js.map +1 -0
  10. package/dist/bin.d.ts +1 -0
  11. package/dist/bin.js +12 -0
  12. package/dist/bin.js.map +1 -0
  13. package/dist/build.d.ts +23 -0
  14. package/dist/build.js +111 -0
  15. package/dist/build.js.map +1 -0
  16. package/dist/cli.d.ts +87 -0
  17. package/dist/cli.js +544 -0
  18. package/dist/cli.js.map +1 -0
  19. package/dist/constants.d.ts +2 -0
  20. package/dist/constants.js +7 -0
  21. package/dist/constants.js.map +1 -0
  22. package/dist/extension-api-manifest.d.ts +65 -0
  23. package/dist/extension-api-manifest.js +231 -0
  24. package/dist/extension-api-manifest.js.map +1 -0
  25. package/dist/extension-bundle-archive.d.ts +36 -0
  26. package/dist/extension-bundle-archive.js +302 -0
  27. package/dist/extension-bundle-archive.js.map +1 -0
  28. package/dist/extension-bundle-configuration.d.ts +55 -0
  29. package/dist/extension-bundle-configuration.js +200 -0
  30. package/dist/extension-bundle-configuration.js.map +1 -0
  31. package/dist/extension-bundle.d.ts +39 -0
  32. package/dist/extension-bundle.js +580 -0
  33. package/dist/extension-bundle.js.map +1 -0
  34. package/dist/extension-dependencies.d.ts +18 -0
  35. package/dist/extension-dependencies.js +59 -0
  36. package/dist/extension-dependencies.js.map +1 -0
  37. package/dist/extension-id-migration.d.ts +83 -0
  38. package/dist/extension-id-migration.js +292 -0
  39. package/dist/extension-id-migration.js.map +1 -0
  40. package/dist/extension-sync.d.ts +111 -0
  41. package/dist/extension-sync.js +463 -0
  42. package/dist/extension-sync.js.map +1 -0
  43. package/dist/import.d.ts +39 -0
  44. package/dist/import.js +244 -0
  45. package/dist/import.js.map +1 -0
  46. package/dist/index.d.ts +31 -0
  47. package/dist/index.js +18 -0
  48. package/dist/npm-extension-source.d.ts +13 -0
  49. package/dist/npm-extension-source.js +63 -0
  50. package/dist/npm-extension-source.js.map +1 -0
  51. package/dist/output-safety.d.ts +29 -0
  52. package/dist/output-safety.js +213 -0
  53. package/dist/output-safety.js.map +1 -0
  54. package/dist/project-asset-additions.d.ts +29 -0
  55. package/dist/project-asset-additions.js +412 -0
  56. package/dist/project-asset-additions.js.map +1 -0
  57. package/dist/release-snapshot.d.ts +75 -0
  58. package/dist/release-snapshot.js +177 -0
  59. package/dist/release-snapshot.js.map +1 -0
  60. package/dist/source.d.ts +41 -0
  61. package/dist/source.js +282 -0
  62. package/dist/source.js.map +1 -0
  63. package/dist/turbowarp-clean-up.d.ts +18 -0
  64. package/dist/turbowarp-clean-up.js +266 -0
  65. package/dist/turbowarp-clean-up.js.map +1 -0
  66. package/dist/types.d.ts +80 -0
  67. package/package.json +31 -20
  68. package/bin/sb3-toolchain.mjs +0 -9
  69. package/src/archive.js +0 -35
  70. package/src/build.js +0 -188
  71. package/src/cli.js +0 -748
  72. package/src/constants.js +0 -4
  73. package/src/extension-api-manifest.js +0 -336
  74. package/src/extension-bundle-archive.js +0 -422
  75. package/src/extension-bundle-configuration.js +0 -265
  76. package/src/extension-bundle.js +0 -695
  77. package/src/extension-dependencies.js +0 -114
  78. package/src/extension-id-migration.js +0 -496
  79. package/src/extension-sync.js +0 -754
  80. package/src/import.js +0 -397
  81. package/src/index.js +0 -75
  82. package/src/npm-extension-source.js +0 -111
  83. package/src/output-safety.js +0 -322
  84. package/src/project-asset-additions.js +0 -560
  85. package/src/release-snapshot.js +0 -247
  86. package/src/source.js +0 -468
  87. package/src/turbowarp-clean-up.js +0 -295
package/src/build.js DELETED
@@ -1,188 +0,0 @@
1
- // SPDX-License-Identifier: MPL-2.0
2
-
3
- import {randomUUID} from 'node:crypto';
4
- import {lstat, mkdir, mkdtemp, readdir, readFile, rename, rm, writeFile} from 'node:fs/promises';
5
- import path from 'node:path';
6
-
7
- import {pathExists} from './output-safety.js';
8
- import {createDeterministicSb3} from './source.js';
9
-
10
- function assert(condition, message) {
11
- if (!condition) {
12
- throw new Error(message);
13
- }
14
- }
15
-
16
- async function assertNoInterruptedRollback(outputPath) {
17
- const parentDirectory = path.dirname(outputPath);
18
- if (!(await pathExists(parentDirectory))) {
19
- return;
20
- }
21
- const rollbackPrefix = `.${path.basename(outputPath)}.rollback-`;
22
- const leftovers = (await readdir(parentDirectory))
23
- .filter((entryName) => entryName.startsWith(rollbackPrefix))
24
- .map((entryName) => path.join(parentDirectory, entryName));
25
- assert(
26
- leftovers.length === 0,
27
- `Found an interrupted SB3 build rollback file. Inspect or restore it before retrying: ` +
28
- leftovers.join(', '),
29
- );
30
- }
31
-
32
- async function inspectOutput(outputPath) {
33
- if (!(await pathExists(outputPath))) {
34
- return {contents: null, exists: false};
35
- }
36
- const stats = await lstat(outputPath);
37
- assert(
38
- stats.isFile() && !stats.isSymbolicLink(),
39
- `Refusing to replace a non-file or symbolic link: ${outputPath}`,
40
- );
41
- return {contents: await readFile(outputPath), exists: true};
42
- }
43
-
44
- async function assertOutputUnchanged(outputPath, expectedOutput) {
45
- const currentOutput = await inspectOutput(outputPath);
46
- assert(
47
- currentOutput.exists === expectedOutput.exists &&
48
- (!currentOutput.exists ||
49
- Buffer.compare(currentOutput.contents, expectedOutput.contents) === 0),
50
- `SB3 output changed while the build was running; refusing to replace it: ${outputPath}`,
51
- );
52
- }
53
-
54
- async function installArchiveTransactionally(archive, outputPath, expectedOutput) {
55
- const parentDirectory = path.dirname(outputPath);
56
- await assertNoInterruptedRollback(outputPath);
57
- const temporaryDirectory = await mkdtemp(
58
- path.join(parentDirectory, `.${path.basename(outputPath)}.build-`),
59
- );
60
- const temporaryPath = path.join(temporaryDirectory, path.basename(outputPath));
61
- const rollbackPath = path.join(
62
- parentDirectory,
63
- `.${path.basename(outputPath)}.rollback-${randomUUID()}`,
64
- );
65
- await writeFile(temporaryPath, archive);
66
-
67
- try {
68
- await assertOutputUnchanged(outputPath, expectedOutput);
69
- if (expectedOutput.exists) {
70
- await rename(outputPath, rollbackPath);
71
- }
72
- try {
73
- await rename(temporaryPath, outputPath);
74
- } catch (installError) {
75
- if (expectedOutput.exists) {
76
- try {
77
- await rename(rollbackPath, outputPath);
78
- } catch (restoreError) {
79
- throw new AggregateError(
80
- [installError, restoreError],
81
- `SB3 build failed and automatic restoration also failed. ` +
82
- `Original output remains at: ${rollbackPath}`,
83
- );
84
- }
85
- }
86
- throw installError;
87
- }
88
- } finally {
89
- await rm(temporaryDirectory, {recursive: true, force: true});
90
- }
91
-
92
- if (!expectedOutput.exists) {
93
- return null;
94
- }
95
- try {
96
- await rm(rollbackPath);
97
- return null;
98
- } catch (error) {
99
- return (
100
- `Built SB3 was installed, but its temporary rollback file could not be removed: ` +
101
- `${rollbackPath} (${error.message})`
102
- );
103
- }
104
- }
105
-
106
- export async function writeSb3Archive({
107
- archive,
108
- confirmReplace = undefined,
109
- outputPath,
110
- yes = false,
111
- }) {
112
- assert(archive instanceof Uint8Array, 'SB3 archive contents are required.');
113
- assert(typeof outputPath === 'string', 'SB3 output path is required.');
114
- const resolvedOutputPath = path.resolve(outputPath);
115
- assert(
116
- path.extname(resolvedOutputPath).toLowerCase() === '.sb3',
117
- `SB3 output path must use the .sb3 extension: ${resolvedOutputPath}`,
118
- );
119
- await assertNoInterruptedRollback(resolvedOutputPath);
120
- const existingOutput = await inspectOutput(resolvedOutputPath);
121
- if (existingOutput.exists) {
122
- if (Buffer.compare(existingOutput.contents, Buffer.from(archive)) === 0) {
123
- return {
124
- changed: false,
125
- outputPath: resolvedOutputPath,
126
- rollbackCleanupWarning: null,
127
- };
128
- }
129
- if (!yes) {
130
- assert(
131
- typeof confirmReplace === 'function',
132
- `Existing SB3 output differs: ${resolvedOutputPath}. ` +
133
- 'Non-interactive replacement requires --yes.',
134
- );
135
- assert(
136
- await confirmReplace(resolvedOutputPath),
137
- 'SB3 build cancelled; the existing output was not changed.',
138
- );
139
- }
140
- }
141
-
142
- await mkdir(path.dirname(resolvedOutputPath), {recursive: true});
143
- const rollbackCleanupWarning = await installArchiveTransactionally(
144
- archive,
145
- resolvedOutputPath,
146
- existingOutput,
147
- );
148
- return {
149
- changed: true,
150
- outputPath: resolvedOutputPath,
151
- rollbackCleanupWarning,
152
- };
153
- }
154
-
155
- /**
156
- * @param {{
157
- * allowedAssetRoots?: string[],
158
- * cleanUpBlocks?: boolean,
159
- * confirmReplace?: (outputPath: string) => Promise<boolean>,
160
- * outputPath: string,
161
- * projectAssetsPath?: string,
162
- * sourceDirectory: string,
163
- * yes?: boolean,
164
- * }} options
165
- */
166
- export async function buildSb3({
167
- allowedAssetRoots = [],
168
- cleanUpBlocks = false,
169
- confirmReplace,
170
- outputPath,
171
- projectAssetsPath,
172
- sourceDirectory,
173
- yes = false,
174
- }) {
175
- assert(typeof sourceDirectory === 'string', 'SB3 source directory is required.');
176
- const built = await createDeterministicSb3(sourceDirectory, {
177
- allowedAssetRoots,
178
- cleanUpBlocks,
179
- projectAssetsPath,
180
- });
181
- const written = await writeSb3Archive({
182
- archive: built.archive,
183
- confirmReplace,
184
- outputPath,
185
- yes,
186
- });
187
- return {...built, ...written};
188
- }