@swipt/cli 0.1.0-nightly.78 → 0.1.0-nightly.79
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/dist/availability.d.ts +5 -0
- package/dist/availability.js +349 -0
- package/dist/availability.js.map +1 -0
- package/dist/client.d.ts +25 -0
- package/dist/client.js +248 -0
- package/dist/client.js.map +1 -0
- package/dist/connection.d.ts +24 -0
- package/dist/connection.js +293 -0
- package/dist/connection.js.map +1 -0
- package/dist/coredevice.d.ts +22 -0
- package/dist/coredevice.js +329 -0
- package/dist/coredevice.js.map +1 -0
- package/dist/device.d.ts +130 -0
- package/dist/device.js +539 -0
- package/dist/device.js.map +1 -0
- package/dist/i18n.d.ts +2 -0
- package/dist/i18n.js +57 -0
- package/dist/i18n.js.map +1 -0
- package/dist/ignore.d.ts +8 -0
- package/dist/ignore.js +112 -0
- package/dist/ignore.js.map +1 -0
- package/dist/metro.d.ts +10 -0
- package/dist/metro.js +349 -0
- package/dist/metro.js.map +1 -0
- package/dist/output.d.ts +20 -0
- package/dist/output.js +116 -0
- package/dist/output.js.map +1 -0
- package/dist/project.d.ts +18 -0
- package/dist/project.js +696 -0
- package/dist/project.js.map +1 -0
- package/dist/proto/common_pb.js +34 -0
- package/dist/proto/common_pb.js.map +1 -0
- package/dist/proto/logs_pb.js +15 -0
- package/dist/proto/logs_pb.js.map +1 -0
- package/dist/proto/repl_pb.js +15 -0
- package/dist/proto/repl_pb.js.map +1 -0
- package/dist/proto/swiplets_pb.js +28 -0
- package/dist/proto/swiplets_pb.js.map +1 -0
- package/dist/proto/system_pb.js +15 -0
- package/dist/proto/system_pb.js.map +1 -0
- package/dist/sideload.d.ts +17 -0
- package/dist/sideload.js +1098 -0
- package/dist/sideload.js.map +1 -0
- package/dist/swipt.d.ts +1 -0
- package/dist/swipt.js +631 -0
- package/dist/swipt.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +15 -0
- package/dist/version.js.map +1 -0
- package/package.json +21 -7
- package/availability.mjs +0 -642
- package/client.mjs +0 -375
- package/connection.mjs +0 -450
- package/coredevice.mjs +0 -464
- package/device.mjs +0 -837
- package/i18n.mjs +0 -71
- package/ignore.mjs +0 -149
- package/metro.mjs +0 -432
- package/output.mjs +0 -177
- package/project.mjs +0 -1013
- package/proto/common_pb.js +0 -98
- package/proto/logs_pb.js +0 -34
- package/proto/repl_pb.js +0 -55
- package/proto/swiplets_pb.js +0 -179
- package/proto/system_pb.js +0 -27
- package/sideload.mjs +0 -1696
- package/swipt.mjs +0 -726
- package/version.mjs +0 -16
package/i18n.mjs
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { execFileSync } from "node:child_process";
|
|
2
|
-
import fs from "node:fs";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
|
|
5
|
-
const locales = new URL("locales/", import.meta.url);
|
|
6
|
-
|
|
7
|
-
const languages = new Set([
|
|
8
|
-
"en",
|
|
9
|
-
...fs.readdirSync(locales).map((file) => path.basename(file, ".json")),
|
|
10
|
-
]);
|
|
11
|
-
|
|
12
|
-
function preferredLanguages() {
|
|
13
|
-
const variable =
|
|
14
|
-
process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG;
|
|
15
|
-
if (variable) {
|
|
16
|
-
return [variable.split(/[.@]/)[0].replaceAll("_", "-")];
|
|
17
|
-
}
|
|
18
|
-
if (process.platform !== "darwin") {
|
|
19
|
-
return [];
|
|
20
|
-
}
|
|
21
|
-
try {
|
|
22
|
-
return (
|
|
23
|
-
execFileSync("defaults", ["read", "-g", "AppleLanguages"], {
|
|
24
|
-
encoding: "utf8",
|
|
25
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
26
|
-
}).match(/[A-Za-z][\w-]*/g) ?? []
|
|
27
|
-
);
|
|
28
|
-
} catch {
|
|
29
|
-
return [];
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function supportedLanguage(tag) {
|
|
34
|
-
let locale;
|
|
35
|
-
try {
|
|
36
|
-
locale = new Intl.Locale(tag).maximize();
|
|
37
|
-
} catch {
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
const { language, script, region } = locale;
|
|
41
|
-
const variant = {
|
|
42
|
-
es: region === "ES" ? "es" : "es-419",
|
|
43
|
-
no: "nb",
|
|
44
|
-
pt: "pt-PT",
|
|
45
|
-
}[language];
|
|
46
|
-
return [
|
|
47
|
-
`${language}-${region}`,
|
|
48
|
-
`${language}-${script}`,
|
|
49
|
-
variant,
|
|
50
|
-
language,
|
|
51
|
-
].find((candidate) => languages.has(candidate));
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export const language =
|
|
55
|
-
preferredLanguages().map(supportedLanguage).find(Boolean) ?? "en";
|
|
56
|
-
|
|
57
|
-
const messages =
|
|
58
|
-
language === "en"
|
|
59
|
-
? {}
|
|
60
|
-
: JSON.parse(fs.readFileSync(new URL(`${language}.json`, locales), "utf8"));
|
|
61
|
-
|
|
62
|
-
const pluralRules = new Intl.PluralRules(language);
|
|
63
|
-
|
|
64
|
-
export function tr(key, values = {}) {
|
|
65
|
-
const message = messages[key] ?? key;
|
|
66
|
-
const text =
|
|
67
|
-
typeof message === "string"
|
|
68
|
-
? message
|
|
69
|
-
: (message[pluralRules.select(values.count)] ?? message.other);
|
|
70
|
-
return text.replace(/\{(\w+)\}/g, (_, name) => values[name]);
|
|
71
|
-
}
|
package/ignore.mjs
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
|
|
4
|
-
const excluded = (name) =>
|
|
5
|
-
name.startsWith(".") || name === "node_modules" || name === "dist";
|
|
6
|
-
|
|
7
|
-
const escape = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
8
|
-
|
|
9
|
-
function parseRule(line) {
|
|
10
|
-
line = line.replace(/[ \t\r]+$/, "");
|
|
11
|
-
if (line === "" || line.startsWith("#")) {
|
|
12
|
-
return undefined;
|
|
13
|
-
}
|
|
14
|
-
const rule = { negated: false, directory: false };
|
|
15
|
-
if (line.startsWith("!")) {
|
|
16
|
-
rule.negated = true;
|
|
17
|
-
line = line.slice(1);
|
|
18
|
-
} else if (line.startsWith("\\")) {
|
|
19
|
-
line = line.slice(1);
|
|
20
|
-
}
|
|
21
|
-
if (line.endsWith("/")) {
|
|
22
|
-
rule.directory = true;
|
|
23
|
-
line = line.replace(/\/+$/, "");
|
|
24
|
-
}
|
|
25
|
-
if (line === "") {
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
const anchored = line.includes("/");
|
|
29
|
-
line = line.replace(/^\//, "");
|
|
30
|
-
let expression = anchored ? "^" : "^(?:.*/)?";
|
|
31
|
-
for (let index = 0; index < line.length; index++) {
|
|
32
|
-
const rest = line.slice(index);
|
|
33
|
-
if (rest.startsWith("**/")) {
|
|
34
|
-
expression += "(?:.*/)?";
|
|
35
|
-
index += 2;
|
|
36
|
-
} else if (rest === "/**") {
|
|
37
|
-
expression += "/.*";
|
|
38
|
-
index += 2;
|
|
39
|
-
} else if (rest.startsWith("**")) {
|
|
40
|
-
expression += ".*";
|
|
41
|
-
index++;
|
|
42
|
-
} else if (rest[0] === "*") {
|
|
43
|
-
expression += "[^/]*";
|
|
44
|
-
} else if (rest[0] === "?") {
|
|
45
|
-
expression += "[^/]";
|
|
46
|
-
} else if (rest[0] === "[" && rest.indexOf("]", 1) > 1) {
|
|
47
|
-
const end = rest.indexOf("]", 1);
|
|
48
|
-
let cls = rest.slice(1, end);
|
|
49
|
-
if (cls.startsWith("!")) {
|
|
50
|
-
cls = `^${cls.slice(1)}`;
|
|
51
|
-
}
|
|
52
|
-
expression += `[${cls.replaceAll("\\", "\\\\")}]`;
|
|
53
|
-
index += end;
|
|
54
|
-
} else if (rest[0] === "\\" && rest.length > 1) {
|
|
55
|
-
expression += escape(rest[1]);
|
|
56
|
-
index++;
|
|
57
|
-
} else {
|
|
58
|
-
expression += escape(rest[0]);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
try {
|
|
62
|
-
rule.pattern = new RegExp(`${expression}$`);
|
|
63
|
-
} catch {
|
|
64
|
-
return undefined;
|
|
65
|
-
}
|
|
66
|
-
return rule;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export const relativePath = (root, name) => {
|
|
70
|
-
const relative = path.relative(root, name);
|
|
71
|
-
return relative === "" ||
|
|
72
|
-
relative.startsWith("..") ||
|
|
73
|
-
path.isAbsolute(relative)
|
|
74
|
-
? ""
|
|
75
|
-
: relative.split(path.sep).join("/");
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export class Ignorer {
|
|
79
|
-
rules = [];
|
|
80
|
-
|
|
81
|
-
constructor(root) {
|
|
82
|
-
const walk = (directory) => {
|
|
83
|
-
const relative = relativePath(root, directory);
|
|
84
|
-
if (relative !== "" && this.ignored(relative, true)) {
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
this.read(path.join(directory, ".gitignore"), relative);
|
|
88
|
-
let entries;
|
|
89
|
-
try {
|
|
90
|
-
entries = fs.readdirSync(directory, { withFileTypes: true });
|
|
91
|
-
} catch {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
for (const entry of entries) {
|
|
95
|
-
if (entry.isDirectory()) {
|
|
96
|
-
walk(path.join(directory, entry.name));
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
walk(root);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
read(name, base) {
|
|
104
|
-
let text;
|
|
105
|
-
try {
|
|
106
|
-
text = fs.readFileSync(name, "utf8");
|
|
107
|
-
} catch {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
for (const line of text.split("\n")) {
|
|
111
|
-
const rule = parseRule(line);
|
|
112
|
-
if (rule) {
|
|
113
|
-
this.rules.push({ ...rule, base });
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
ignored(relative, directory) {
|
|
119
|
-
const parts = relative.split("/");
|
|
120
|
-
return parts.some(
|
|
121
|
-
(part, index) =>
|
|
122
|
-
excluded(part) ||
|
|
123
|
-
this.matches(
|
|
124
|
-
parts.slice(0, index + 1).join("/"),
|
|
125
|
-
directory || index < parts.length - 1,
|
|
126
|
-
),
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
matches(relative, directory) {
|
|
131
|
-
let ignored = false;
|
|
132
|
-
for (const rule of this.rules) {
|
|
133
|
-
if (rule.directory && !directory) {
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
|
-
let local = relative;
|
|
137
|
-
if (rule.base !== "") {
|
|
138
|
-
if (!relative.startsWith(`${rule.base}/`)) {
|
|
139
|
-
continue;
|
|
140
|
-
}
|
|
141
|
-
local = relative.slice(rule.base.length + 1);
|
|
142
|
-
}
|
|
143
|
-
if (rule.pattern.test(local)) {
|
|
144
|
-
ignored = !rule.negated;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
return ignored;
|
|
148
|
-
}
|
|
149
|
-
}
|
package/metro.mjs
DELETED
|
@@ -1,432 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
-
|
|
6
|
-
import { transformAsync } from "@babel/core";
|
|
7
|
-
import { loadProjectEnv } from "@expo/env";
|
|
8
|
-
import { imageSize } from "image-size";
|
|
9
|
-
|
|
10
|
-
import { tr } from "./i18n.mjs";
|
|
11
|
-
|
|
12
|
-
const require = createRequire(import.meta.url);
|
|
13
|
-
const cliDirectory = path.dirname(fileURLToPath(import.meta.url));
|
|
14
|
-
|
|
15
|
-
const sourceExtensions = ["js", "jsx", "json", "ts", "tsx", "cjs", "mjs"];
|
|
16
|
-
const assetExtensions = [
|
|
17
|
-
"bmp",
|
|
18
|
-
"gif",
|
|
19
|
-
"jpg",
|
|
20
|
-
"jpeg",
|
|
21
|
-
"png",
|
|
22
|
-
"psd",
|
|
23
|
-
"svg",
|
|
24
|
-
"webp",
|
|
25
|
-
"xml",
|
|
26
|
-
"m4v",
|
|
27
|
-
"mov",
|
|
28
|
-
"mp4",
|
|
29
|
-
"mpeg",
|
|
30
|
-
"mpg",
|
|
31
|
-
"webm",
|
|
32
|
-
"aac",
|
|
33
|
-
"aiff",
|
|
34
|
-
"caf",
|
|
35
|
-
"m4a",
|
|
36
|
-
"mp3",
|
|
37
|
-
"wav",
|
|
38
|
-
"html",
|
|
39
|
-
"pdf",
|
|
40
|
-
"yaml",
|
|
41
|
-
"yml",
|
|
42
|
-
"otf",
|
|
43
|
-
"ttf",
|
|
44
|
-
"zip",
|
|
45
|
-
"db",
|
|
46
|
-
"sqlite",
|
|
47
|
-
"sqlite3",
|
|
48
|
-
];
|
|
49
|
-
const imageExtensions = new Set([
|
|
50
|
-
"png",
|
|
51
|
-
"jpg",
|
|
52
|
-
"jpeg",
|
|
53
|
-
"bmp",
|
|
54
|
-
"gif",
|
|
55
|
-
"webp",
|
|
56
|
-
"psd",
|
|
57
|
-
"svg",
|
|
58
|
-
"tiff",
|
|
59
|
-
"ktx",
|
|
60
|
-
]);
|
|
61
|
-
const babelConfigNames = [
|
|
62
|
-
".babelrc",
|
|
63
|
-
".babelrc.js",
|
|
64
|
-
".babelrc.cjs",
|
|
65
|
-
".babelrc.mjs",
|
|
66
|
-
".babelrc.json",
|
|
67
|
-
".babelrc.cts",
|
|
68
|
-
"babel.config.js",
|
|
69
|
-
"babel.config.cjs",
|
|
70
|
-
"babel.config.mjs",
|
|
71
|
-
"babel.config.json",
|
|
72
|
-
"babel.config.cts",
|
|
73
|
-
"babel.config.ts",
|
|
74
|
-
"babel.config.mts",
|
|
75
|
-
];
|
|
76
|
-
const contextModes = ["sync", "eager", "lazy", "lazy-once"];
|
|
77
|
-
const scaleSuffixes = ["", "@1x", "@1.5x", "@2x", "@3x", "@4x"];
|
|
78
|
-
const platformSuffixes = ["", ".ios", ".native"];
|
|
79
|
-
const platformRank = { ios: 2, native: 1 };
|
|
80
|
-
|
|
81
|
-
const posix = (file) => file.split(path.sep).join("/");
|
|
82
|
-
const escape = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
83
|
-
|
|
84
|
-
export function loadEnvironment(root) {
|
|
85
|
-
loadProjectEnv(root, { mode: "production", silent: true });
|
|
86
|
-
process.env.BABEL_ENV ??= "production";
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function defaultPreset(root) {
|
|
90
|
-
try {
|
|
91
|
-
return createRequire(path.join(root, "package.json")).resolve(
|
|
92
|
-
"expo/internal/babel-preset",
|
|
93
|
-
);
|
|
94
|
-
} catch {
|
|
95
|
-
return require.resolve("babel-preset-expo");
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function contextFiles(directory, recursive) {
|
|
100
|
-
if (!fs.existsSync(directory)) {
|
|
101
|
-
return [];
|
|
102
|
-
}
|
|
103
|
-
const extensions = new Set([...sourceExtensions, ...assetExtensions]);
|
|
104
|
-
return fs
|
|
105
|
-
.readdirSync(directory, { recursive })
|
|
106
|
-
.map(posix)
|
|
107
|
-
.filter(
|
|
108
|
-
(file) =>
|
|
109
|
-
extensions.has(path.extname(file).slice(1)) &&
|
|
110
|
-
fs.statSync(path.join(directory, file)).isFile(),
|
|
111
|
-
)
|
|
112
|
-
.sort();
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function requireContext({ types: t, template }) {
|
|
116
|
-
const argument = (call, index, fallback, expected, check) => {
|
|
117
|
-
if (call.node.arguments[index] === undefined) {
|
|
118
|
-
if (fallback !== undefined) {
|
|
119
|
-
return fallback;
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
const { confident, value } = call.get(`arguments.${index}`).evaluate();
|
|
123
|
-
if (confident && check(value)) {
|
|
124
|
-
return value;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
throw call.buildCodeFrameError(
|
|
128
|
-
tr("argument {index} of require.context must be {expected}", {
|
|
129
|
-
index: index + 1,
|
|
130
|
-
expected,
|
|
131
|
-
}),
|
|
132
|
-
);
|
|
133
|
-
};
|
|
134
|
-
const pattern = (call, index) => {
|
|
135
|
-
const node = call.node.arguments[index];
|
|
136
|
-
if (node === undefined) {
|
|
137
|
-
return /^\.\/.*$/;
|
|
138
|
-
}
|
|
139
|
-
if (!t.isRegExpLiteral(node)) {
|
|
140
|
-
throw call.buildCodeFrameError(
|
|
141
|
-
tr(
|
|
142
|
-
"argument {index} of require.context must be a regular expression literal",
|
|
143
|
-
{ index: index + 1 },
|
|
144
|
-
),
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
return new RegExp(node.pattern, node.flags.replace(/[gy]/g, ""));
|
|
148
|
-
};
|
|
149
|
-
return {
|
|
150
|
-
name: "swipt-require-context",
|
|
151
|
-
visitor: {
|
|
152
|
-
CallExpression(call, state) {
|
|
153
|
-
const { callee } = call.node;
|
|
154
|
-
if (
|
|
155
|
-
!t.isMemberExpression(callee) ||
|
|
156
|
-
!t.isIdentifier(callee.object, { name: "require" }) ||
|
|
157
|
-
call.scope.hasBinding("require") ||
|
|
158
|
-
!(callee.computed
|
|
159
|
-
? t.isStringLiteral(callee.property, { value: "context" })
|
|
160
|
-
: t.isIdentifier(callee.property, { name: "context" }))
|
|
161
|
-
) {
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
const from = path.dirname(state.filename);
|
|
165
|
-
const directory = path.resolve(
|
|
166
|
-
from,
|
|
167
|
-
argument(
|
|
168
|
-
call,
|
|
169
|
-
0,
|
|
170
|
-
undefined,
|
|
171
|
-
tr("a string"),
|
|
172
|
-
(value) => typeof value === "string",
|
|
173
|
-
),
|
|
174
|
-
);
|
|
175
|
-
const recursive = argument(
|
|
176
|
-
call,
|
|
177
|
-
1,
|
|
178
|
-
true,
|
|
179
|
-
tr("a boolean"),
|
|
180
|
-
(value) => typeof value === "boolean",
|
|
181
|
-
);
|
|
182
|
-
const filter = pattern(call, 2);
|
|
183
|
-
const mode = argument(
|
|
184
|
-
call,
|
|
185
|
-
3,
|
|
186
|
-
"sync",
|
|
187
|
-
tr("one of {values}", { values: contextModes.join(", ") }),
|
|
188
|
-
(value) => contextModes.includes(value),
|
|
189
|
-
);
|
|
190
|
-
const entries = contextFiles(directory, recursive)
|
|
191
|
-
.map((file) => `./${file}`)
|
|
192
|
-
.filter((key) => filter.test(key))
|
|
193
|
-
.map((key) => {
|
|
194
|
-
const target = posix(
|
|
195
|
-
path.relative(from, path.join(directory, key)),
|
|
196
|
-
);
|
|
197
|
-
return `${JSON.stringify(key)}: () => require(${JSON.stringify(target.startsWith(".") ? target : `./${target}`)})`;
|
|
198
|
-
});
|
|
199
|
-
call.replaceWith(
|
|
200
|
-
template.expression.ast(`(() => {
|
|
201
|
-
const modules = { ${entries.join(", ")} };
|
|
202
|
-
const context = key => {
|
|
203
|
-
if (!Object.prototype.hasOwnProperty.call(modules, key)) {
|
|
204
|
-
throw Object.assign(new Error("Cannot find module '" + key + "'"), { code: "MODULE_NOT_FOUND" });
|
|
205
|
-
}
|
|
206
|
-
return ${mode === "sync" ? "modules[key]()" : "Promise.resolve().then(modules[key])"};
|
|
207
|
-
};
|
|
208
|
-
context.keys = () => Object.keys(modules);
|
|
209
|
-
context.resolve = key => key;
|
|
210
|
-
context.id = ${JSON.stringify(posix(path.relative(state.cwd, directory)) || ".")};
|
|
211
|
-
return context;
|
|
212
|
-
})()`),
|
|
213
|
-
);
|
|
214
|
-
},
|
|
215
|
-
},
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const loaderOf = (file) => {
|
|
220
|
-
const extension = path.extname(file);
|
|
221
|
-
return extension === ".tsx"
|
|
222
|
-
? "tsx"
|
|
223
|
-
: [".ts", ".mts", ".cts"].includes(extension)
|
|
224
|
-
? "ts"
|
|
225
|
-
: "jsx";
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
function archivedAsset(root, file) {
|
|
229
|
-
const relative = path.relative(root, file).split(path.sep);
|
|
230
|
-
return relative[0] === "assets"
|
|
231
|
-
? { path: relative.slice(1).join("/"), bundled: false }
|
|
232
|
-
: {
|
|
233
|
-
path: relative.map((part) => (part === ".." ? "__" : part)).join("/"),
|
|
234
|
-
bundled: true,
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
function assetVariants(resolved) {
|
|
239
|
-
const directory = path.dirname(resolved);
|
|
240
|
-
const extension = path.extname(resolved);
|
|
241
|
-
const stem = path
|
|
242
|
-
.basename(resolved, extension)
|
|
243
|
-
.replace(/(\.(ios|native))$/, "")
|
|
244
|
-
.replace(/@[\d.]+x$/, "");
|
|
245
|
-
const pattern = new RegExp(
|
|
246
|
-
`^${escape(stem)}(?:@([\\d.]+)x)?(?:\\.(ios|native))?${escape(extension)}$`,
|
|
247
|
-
);
|
|
248
|
-
const scales = new Map();
|
|
249
|
-
for (const name of fs.readdirSync(directory)) {
|
|
250
|
-
const match = pattern.exec(name);
|
|
251
|
-
if (match === null) {
|
|
252
|
-
continue;
|
|
253
|
-
}
|
|
254
|
-
const scale = match[1] === undefined ? 1 : Number(match[1]);
|
|
255
|
-
const rank = platformRank[match[2]] ?? 0;
|
|
256
|
-
if (Number.isFinite(scale) && (scales.get(scale)?.rank ?? -1) < rank) {
|
|
257
|
-
scales.set(scale, { rank, file: path.join(directory, name) });
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
return [...scales]
|
|
261
|
-
.sort(([a], [b]) => a - b)
|
|
262
|
-
.map(([scale, { file }]) => ({ scale, file }));
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
function assetModule(root, variants, assets) {
|
|
266
|
-
const [first] = variants;
|
|
267
|
-
const extension = path.extname(first.file).slice(1);
|
|
268
|
-
const size = imageExtensions.has(extension)
|
|
269
|
-
? imageSize(fs.readFileSync(first.file))
|
|
270
|
-
: undefined;
|
|
271
|
-
const files = variants.map(({ scale, file }) => {
|
|
272
|
-
const archived = archivedAsset(root, file);
|
|
273
|
-
if (archived.bundled) {
|
|
274
|
-
assets.set(archived.path, file);
|
|
275
|
-
}
|
|
276
|
-
return [scale, archived.path];
|
|
277
|
-
});
|
|
278
|
-
return `const { PixelRatio } = require("react-native");
|
|
279
|
-
const { assets } = require("@swipt/api/file-system");
|
|
280
|
-
const files = ${JSON.stringify(files)};
|
|
281
|
-
const ratio = PixelRatio.get();
|
|
282
|
-
const [scale, file] = files.find(([scale]) => scale >= ratio) ?? files[files.length - 1];
|
|
283
|
-
module.exports = { uri: assets.file(file).uri, scale${size ? `, width: ${size.width / first.scale}, height: ${size.height / first.scale}` : ""} };
|
|
284
|
-
`;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
function checkWorklets(root) {
|
|
288
|
-
let plugin;
|
|
289
|
-
try {
|
|
290
|
-
plugin = require.resolve("react-native-worklets/plugin", { paths: [root] });
|
|
291
|
-
} catch {
|
|
292
|
-
return;
|
|
293
|
-
}
|
|
294
|
-
const { version } = JSON.parse(
|
|
295
|
-
fs.readFileSync(
|
|
296
|
-
path.join(path.dirname(plugin), "..", "package.json"),
|
|
297
|
-
"utf8",
|
|
298
|
-
),
|
|
299
|
-
);
|
|
300
|
-
const { version: expected } = require("react-native-worklets/package.json");
|
|
301
|
-
if (version !== expected) {
|
|
302
|
-
throw new Error(
|
|
303
|
-
tr(
|
|
304
|
-
"the project has react-native-worklets {version}, but Swipt runs {expected}; install react-native-worklets@{expected} or remove it",
|
|
305
|
-
{ version, expected },
|
|
306
|
-
),
|
|
307
|
-
);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
export function metro(root, { assets, sourcemap }) {
|
|
312
|
-
checkWorklets(root);
|
|
313
|
-
const configName = babelConfigNames.find((name) =>
|
|
314
|
-
fs.existsSync(path.join(root, name)),
|
|
315
|
-
);
|
|
316
|
-
const babel = {
|
|
317
|
-
cwd: root,
|
|
318
|
-
root,
|
|
319
|
-
babelrc: false,
|
|
320
|
-
configFile: false,
|
|
321
|
-
sourceType: "unambiguous",
|
|
322
|
-
envName: "production",
|
|
323
|
-
compact: false,
|
|
324
|
-
retainLines: true,
|
|
325
|
-
sourceMaps: sourcemap ? "inline" : false,
|
|
326
|
-
...(configName
|
|
327
|
-
? { extends: path.join(root, configName) }
|
|
328
|
-
: { presets: [defaultPreset(root)] }),
|
|
329
|
-
plugins: [requireContext],
|
|
330
|
-
};
|
|
331
|
-
const caller = {
|
|
332
|
-
name: "metro",
|
|
333
|
-
bundler: "metro",
|
|
334
|
-
platform: "ios",
|
|
335
|
-
engine: "hermes",
|
|
336
|
-
isDev: false,
|
|
337
|
-
isServer: false,
|
|
338
|
-
isReactServer: false,
|
|
339
|
-
baseUrl: "",
|
|
340
|
-
routerRoot: "app",
|
|
341
|
-
projectRoot: root,
|
|
342
|
-
isHMREnabled: true,
|
|
343
|
-
metroSourceType: "module",
|
|
344
|
-
supportsStaticESM: true,
|
|
345
|
-
};
|
|
346
|
-
const internal = Symbol("internal");
|
|
347
|
-
return {
|
|
348
|
-
name: "swiplet-metro",
|
|
349
|
-
setup(build) {
|
|
350
|
-
build.onResolve({ filter: /^@babel\/runtime\// }, async (args) => {
|
|
351
|
-
if (args.pluginData === internal) {
|
|
352
|
-
return undefined;
|
|
353
|
-
}
|
|
354
|
-
const options = {
|
|
355
|
-
kind: args.kind,
|
|
356
|
-
importer: args.importer,
|
|
357
|
-
pluginData: internal,
|
|
358
|
-
};
|
|
359
|
-
const found = await build.resolve(args.path, {
|
|
360
|
-
...options,
|
|
361
|
-
resolveDir: args.resolveDir,
|
|
362
|
-
});
|
|
363
|
-
return found.errors.length === 0
|
|
364
|
-
? found
|
|
365
|
-
: build.resolve(args.path, { ...options, resolveDir: cliDirectory });
|
|
366
|
-
});
|
|
367
|
-
if (assets) {
|
|
368
|
-
build.onResolve(
|
|
369
|
-
{ filter: new RegExp(`\\.(${assetExtensions.join("|")})$`) },
|
|
370
|
-
async (args) => {
|
|
371
|
-
if (args.pluginData === internal) {
|
|
372
|
-
return undefined;
|
|
373
|
-
}
|
|
374
|
-
const extension = path.extname(args.path);
|
|
375
|
-
const stem = args.path.slice(0, -extension.length);
|
|
376
|
-
let first;
|
|
377
|
-
for (const scale of scaleSuffixes) {
|
|
378
|
-
for (const platform of platformSuffixes) {
|
|
379
|
-
const found = await build.resolve(
|
|
380
|
-
`${stem}${scale}${platform}${extension}`,
|
|
381
|
-
{
|
|
382
|
-
kind: args.kind,
|
|
383
|
-
importer: args.importer,
|
|
384
|
-
resolveDir: args.resolveDir,
|
|
385
|
-
pluginData: internal,
|
|
386
|
-
},
|
|
387
|
-
);
|
|
388
|
-
if (found.errors.length === 0) {
|
|
389
|
-
return {
|
|
390
|
-
path: found.path,
|
|
391
|
-
namespace: "swiplet-asset",
|
|
392
|
-
pluginData: assetVariants(found.path),
|
|
393
|
-
};
|
|
394
|
-
}
|
|
395
|
-
first ??= found;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
return { errors: first.errors };
|
|
399
|
-
},
|
|
400
|
-
);
|
|
401
|
-
build.onLoad({ filter: /.*/, namespace: "swiplet-asset" }, (args) => ({
|
|
402
|
-
contents: assetModule(root, args.pluginData, assets),
|
|
403
|
-
loader: "js",
|
|
404
|
-
resolveDir: root,
|
|
405
|
-
}));
|
|
406
|
-
}
|
|
407
|
-
build.onLoad(
|
|
408
|
-
{ filter: /\.[cm]?[jt]sx?$/, namespace: "file" },
|
|
409
|
-
async (args) => {
|
|
410
|
-
const result = await transformAsync(
|
|
411
|
-
await fs.promises.readFile(args.path, "utf8"),
|
|
412
|
-
{
|
|
413
|
-
...babel,
|
|
414
|
-
filename: args.path,
|
|
415
|
-
caller: {
|
|
416
|
-
...caller,
|
|
417
|
-
isNodeModule: args.path.includes("node_modules"),
|
|
418
|
-
},
|
|
419
|
-
},
|
|
420
|
-
);
|
|
421
|
-
return result === null
|
|
422
|
-
? undefined
|
|
423
|
-
: {
|
|
424
|
-
contents: result.code,
|
|
425
|
-
loader: loaderOf(args.path),
|
|
426
|
-
resolveDir: path.dirname(args.path),
|
|
427
|
-
};
|
|
428
|
-
},
|
|
429
|
-
);
|
|
430
|
-
},
|
|
431
|
-
};
|
|
432
|
-
}
|