@swipt/cli 0.1.0-nightly.42 → 0.1.0-nightly.43
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/metro.mjs +1 -1
- package/package.json +3 -2
- package/project.mjs +61 -10
- package/swipt.mjs +3 -3
package/metro.mjs
CHANGED
|
@@ -13,7 +13,7 @@ const cliDirectory = path.dirname(fileURLToPath(import.meta.url));
|
|
|
13
13
|
const sourceExtensions = ["js", "jsx", "json", "ts", "tsx", "cjs", "mjs"];
|
|
14
14
|
const assetExtensions = [
|
|
15
15
|
"bmp", "gif", "jpg", "jpeg", "png", "psd", "svg", "webp", "xml", "m4v", "mov", "mp4", "mpeg", "mpg", "webm", "aac", "aiff", "caf",
|
|
16
|
-
"m4a", "mp3", "wav", "html", "pdf", "yaml", "yml", "otf", "ttf", "zip",
|
|
16
|
+
"m4a", "mp3", "wav", "html", "pdf", "yaml", "yml", "otf", "ttf", "zip", "db", "sqlite", "sqlite3",
|
|
17
17
|
];
|
|
18
18
|
const imageExtensions = new Set(["png", "jpg", "jpeg", "bmp", "gif", "webp", "psd", "svg", "tiff", "ktx"]);
|
|
19
19
|
const babelConfigNames = [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swipt/cli",
|
|
3
|
-
"version": "0.1.0-nightly.
|
|
3
|
+
"version": "0.1.0-nightly.43",
|
|
4
4
|
"license": "GPL-3.0-or-later",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@babel/core": "^7.29.7",
|
|
23
|
+
"@babel/plugin-transform-block-scoping": "^7.29.12",
|
|
23
24
|
"@babel/runtime": "^7.29.10",
|
|
24
25
|
"@bufbuild/protobuf": "^2.16.0",
|
|
25
26
|
"@expo/env": "^2.5.3",
|
|
@@ -30,7 +31,7 @@
|
|
|
30
31
|
"react-native-worklets": "0.13.0"
|
|
31
32
|
},
|
|
32
33
|
"peerDependencies": {
|
|
33
|
-
"@swipt/api": "0.1.0-nightly.
|
|
34
|
+
"@swipt/api": "0.1.0-nightly.43"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@bufbuild/protoc-gen-es": "^2.16.0"
|
package/project.mjs
CHANGED
|
@@ -7,12 +7,14 @@ import path from "node:path";
|
|
|
7
7
|
import { parseArgs } from "node:util";
|
|
8
8
|
import vm from "node:vm";
|
|
9
9
|
|
|
10
|
+
import { transformAsync } from "@babel/core";
|
|
10
11
|
import { build } from "esbuild";
|
|
11
12
|
|
|
12
13
|
import { loadEnvironment, metro } from "./metro.mjs";
|
|
13
14
|
|
|
14
15
|
const { version } = JSON.parse(fs.readFileSync(new URL("package.json", import.meta.url), "utf8"));
|
|
15
|
-
const
|
|
16
|
+
const require = createRequire(import.meta.url);
|
|
17
|
+
const { peerDependencies } = require("@swipt/api/package.json");
|
|
16
18
|
|
|
17
19
|
const appModules = [
|
|
18
20
|
"react",
|
|
@@ -27,6 +29,8 @@ const appModules = [
|
|
|
27
29
|
"@swipt/api/swiplet",
|
|
28
30
|
"@swipt/api/file-system",
|
|
29
31
|
"expo-sqlite",
|
|
32
|
+
"expo-sqlite/kv-store",
|
|
33
|
+
"expo-sqlite/localStorage/install",
|
|
30
34
|
];
|
|
31
35
|
const extensionModules = [
|
|
32
36
|
"@swipt/api",
|
|
@@ -39,6 +43,8 @@ const extensionModules = [
|
|
|
39
43
|
"@swipt/api/image",
|
|
40
44
|
"expo-localization",
|
|
41
45
|
"expo-sqlite",
|
|
46
|
+
"expo-sqlite/kv-store",
|
|
47
|
+
"expo-sqlite/localStorage/install",
|
|
42
48
|
];
|
|
43
49
|
|
|
44
50
|
const idPattern = /^[a-z0-9][a-z0-9._-]{0,127}$/;
|
|
@@ -124,7 +130,10 @@ async function bundle(project) {
|
|
|
124
130
|
logLevel: "silent",
|
|
125
131
|
plugins: [...(project.extension ? [typeImport(project.extension)] : []), metro(project.root, { assets: out.assets })],
|
|
126
132
|
});
|
|
127
|
-
|
|
133
|
+
const scoped = await transformAsync(result.outputFiles[0].text, {
|
|
134
|
+
babelrc: false, configFile: false, sourceType: "script", compact: false, plugins: [require.resolve("@babel/plugin-transform-block-scoping")],
|
|
135
|
+
});
|
|
136
|
+
out.app = scoped.code;
|
|
128
137
|
}
|
|
129
138
|
if (out.app === "" && out.extension === "") {
|
|
130
139
|
throw new Error('package.json names neither "swiplet.app" nor "swiplet.extension"');
|
|
@@ -158,6 +167,9 @@ function describeExtension(source) {
|
|
|
158
167
|
get dataDirectory() {
|
|
159
168
|
throw new Error("dataDirectory is used while extension.js loads; use it inside run or an action");
|
|
160
169
|
},
|
|
170
|
+
get cacheDirectory() {
|
|
171
|
+
throw new Error("cacheDirectory is used while extension.js loads; use it inside run or an action");
|
|
172
|
+
},
|
|
161
173
|
get assets() {
|
|
162
174
|
throw new Error("assets is used while extension.js loads; use it inside run or an action");
|
|
163
175
|
},
|
|
@@ -169,26 +181,63 @@ function describeExtension(source) {
|
|
|
169
181
|
"@swipt/api/image": loading("image"),
|
|
170
182
|
"expo-localization": { getLocales: () => [{ languageTag: "en", languageCode: "en" }], getCalendars: () => [] },
|
|
171
183
|
"expo-sqlite": {
|
|
184
|
+
SQLiteDatabase: loading("SQLiteDatabase"),
|
|
185
|
+
SQLiteStatement: loading("SQLiteStatement"),
|
|
186
|
+
SQLiteTaggedQuery: loading("SQLiteTaggedQuery"),
|
|
187
|
+
SQLiteSession: loading("SQLiteSession"),
|
|
172
188
|
openDatabaseSync: () => loading("the database"),
|
|
173
189
|
openDatabaseAsync: () => Promise.resolve(loading("the database")),
|
|
190
|
+
deserializeDatabaseSync: () => loading("the database"),
|
|
191
|
+
deserializeDatabaseAsync: () => Promise.resolve(loading("the database")),
|
|
174
192
|
deleteDatabaseSync: () => {},
|
|
175
193
|
deleteDatabaseAsync: () => Promise.resolve(),
|
|
194
|
+
backupDatabaseSync: () => {},
|
|
195
|
+
backupDatabaseAsync: () => Promise.resolve(),
|
|
196
|
+
importDatabaseFromAssetAsync: () => Promise.resolve(),
|
|
176
197
|
addDatabaseChangeListener: () => ({ remove: () => {} }),
|
|
177
198
|
defaultDatabaseDirectory: "",
|
|
199
|
+
bundledExtensions: {},
|
|
200
|
+
configureWeb: () => {},
|
|
201
|
+
deepEqual: function deepEqual(a, b) {
|
|
202
|
+
if (a === b) {
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
if (a === null || b === null || typeof a !== "object" || typeof b !== "object") {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
const keys = Object.keys(a);
|
|
209
|
+
return keys.length === Object.keys(b).length && keys.every(key => deepEqual(a[key], b[key]));
|
|
210
|
+
},
|
|
211
|
+
SQLiteProvider: () => {
|
|
212
|
+
throw new Error("SQLiteProvider renders React, so it works only in the swiplet interface");
|
|
213
|
+
},
|
|
214
|
+
useSQLiteContext: () => {
|
|
215
|
+
throw new Error("useSQLiteContext renders React, so it works only in the swiplet interface");
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
"expo-sqlite/kv-store": {
|
|
219
|
+
SQLiteStorage: loading("SQLiteStorage"),
|
|
220
|
+
AsyncStorage: loading("the storage"),
|
|
221
|
+
Storage: loading("the storage"),
|
|
222
|
+
default: loading("the storage"),
|
|
223
|
+
},
|
|
224
|
+
get "expo-sqlite/localStorage/install"() {
|
|
225
|
+
context.localStorage = loading("localStorage");
|
|
226
|
+
return {};
|
|
178
227
|
},
|
|
179
228
|
};
|
|
180
229
|
const ignored = () => 0;
|
|
181
230
|
const webGlobals = [
|
|
182
|
-
"
|
|
183
|
-
"
|
|
184
|
-
"
|
|
185
|
-
"
|
|
231
|
+
"ErrorEvent", "File", "FormData", "ReadableStream", "ReadableStreamDefaultReader", "ReadableStreamBYOBReader", "ReadableStreamBYOBRequest",
|
|
232
|
+
"ReadableStreamDefaultController", "ReadableByteStreamController", "WritableStream", "WritableStreamDefaultWriter", "WritableStreamDefaultController",
|
|
233
|
+
"TransformStream", "TransformStreamDefaultController", "ByteLengthQueuingStrategy", "CountQueuingStrategy", "TextEncoderStream", "TextDecoderStream",
|
|
234
|
+
"CompressionStream", "DecompressionStream", "performance", "Performance", "PerformanceEntry", "PerformanceMark", "PerformanceMeasure",
|
|
235
|
+
"PerformanceObserver", "PerformanceObserverEntryList",
|
|
186
236
|
];
|
|
187
237
|
const context = vm.createContext({
|
|
188
238
|
console, URL, URLSearchParams, TextEncoder, TextDecoder, atob, btoa, structuredClone, queueMicrotask, crypto,
|
|
189
|
-
AbortController, AbortSignal, Event, EventTarget, CustomEvent, DOMException,
|
|
239
|
+
AbortController, AbortSignal, Event, EventTarget, CustomEvent, DOMException, Blob,
|
|
190
240
|
...Object.fromEntries(webGlobals.map(name => [name, globalThis[name]])),
|
|
191
|
-
fetch: loading("fetch"),
|
|
192
241
|
setTimeout: ignored, setInterval: ignored, clearTimeout: ignored, clearInterval: ignored,
|
|
193
242
|
navigator: { userAgent: "Swipt", language: "en", languages: ["en"] },
|
|
194
243
|
});
|
|
@@ -417,6 +466,8 @@ export function sourceCommand(root, given) {
|
|
|
417
466
|
console.log(path.relative(process.cwd(), path.join(dist, "swiplets.json")));
|
|
418
467
|
}
|
|
419
468
|
|
|
469
|
+
const swiptRange = version.includes("-") ? version : `>=${version}-0 <=${version}`;
|
|
470
|
+
|
|
420
471
|
const idOf = name => name.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^[._-]+/, "").slice(0, 128).replace(/[._-]+$/, "") || "swiplet";
|
|
421
472
|
|
|
422
473
|
const templates = {
|
|
@@ -437,8 +488,8 @@ const templates = {
|
|
|
437
488
|
scripts: { build: "swipt project build", check: "tsc" },
|
|
438
489
|
dependencies: { zod: "^4.6.7" },
|
|
439
490
|
devDependencies: {
|
|
440
|
-
"@swipt/api":
|
|
441
|
-
"@swipt/cli":
|
|
491
|
+
"@swipt/api": swiptRange,
|
|
492
|
+
"@swipt/cli": swiptRange,
|
|
442
493
|
typescript: "^7.0.2",
|
|
443
494
|
...Object.fromEntries(["@expo/ui", "@types/react", "react"].map(name => [name, peerDependencies[name]])),
|
|
444
495
|
},
|
package/swipt.mjs
CHANGED
|
@@ -169,8 +169,8 @@ const commands = [
|
|
|
169
169
|
"FILE, or standard input given as - or no argument, is a program; only its console output and thrown error are printed, and the global args holds its ARGs.",
|
|
170
170
|
'Top-level await is available, and top-level bindings persist across runs until "swipt repl reset".',
|
|
171
171
|
"An image given to show(), or as the completion value of CODE, is saved as a PNG file and printed as its path.",
|
|
172
|
-
'
|
|
173
|
-
'dataDirectory is the directory that "swipt repl data" manages.',
|
|
172
|
+
'The globals are accessibility, input, device, screen, image, dialog, dataDirectory, show and sleep; import declarations and import() load the modules that swiplets get from Swipt; "swipt repl api" declares both.',
|
|
173
|
+
'dataDirectory, which also holds the expo-sqlite databases, is the directory that "swipt repl data" manages.',
|
|
174
174
|
],
|
|
175
175
|
args: [0, Infinity],
|
|
176
176
|
passthrough: device.isProgram,
|
|
@@ -178,7 +178,7 @@ const commands = [
|
|
|
178
178
|
run: device.run,
|
|
179
179
|
},
|
|
180
180
|
{ name: "reset", short: "Reset the session", args: [0, 0], run: device.reset },
|
|
181
|
-
{ name: "api", short: "Print the TypeScript declarations of the globals", args: [0, 0], run: device.api },
|
|
181
|
+
{ name: "api", short: "Print the TypeScript declarations of the globals and modules", args: [0, 0], run: device.api },
|
|
182
182
|
dataCommands("", device.replData),
|
|
183
183
|
],
|
|
184
184
|
},
|