@hot-updater/expo 0.33.1 → 0.34.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/dist/babel-plugin.cjs +77 -37
- package/dist/babel-plugin.d.cts +5 -7
- package/dist/babel-plugin.d.mts +5 -7
- package/dist/babel-plugin.mjs +77 -37
- package/package.json +4 -4
package/dist/babel-plugin.cjs
CHANGED
|
@@ -1,10 +1,46 @@
|
|
|
1
|
+
//#region src/babel-utils.ts
|
|
2
|
+
function isWebViewExpression(t, node) {
|
|
3
|
+
return t.isIdentifier(node) && (node.name === "WebView" || node.name.endsWith("WebView")) || t.isMemberExpression(node) && t.isIdentifier(node.property, { name: "WebView" });
|
|
4
|
+
}
|
|
5
|
+
function isJsxRuntimeCallee(t, callee) {
|
|
6
|
+
if (t.isIdentifier(callee)) return [
|
|
7
|
+
"jsx",
|
|
8
|
+
"jsxs",
|
|
9
|
+
"jsxDEV"
|
|
10
|
+
].some((name) => callee.name.endsWith(name));
|
|
11
|
+
if (t.isMemberExpression(callee)) return t.isIdentifier(callee.property) && [
|
|
12
|
+
"jsx",
|
|
13
|
+
"jsxs",
|
|
14
|
+
"jsxDEV"
|
|
15
|
+
].includes(callee.property.name);
|
|
16
|
+
if (t.isSequenceExpression(callee)) return isJsxRuntimeCallee(t, callee.expressions[callee.expressions.length - 1]);
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
function isSupportedWebViewCall(t, callExpression, propsNode) {
|
|
20
|
+
if (callExpression.arguments[1] !== propsNode) return false;
|
|
21
|
+
if (!isWebViewExpression(t, callExpression.arguments[0])) return false;
|
|
22
|
+
if (t.isMemberExpression(callExpression.callee) && t.isIdentifier(callExpression.callee.property, { name: "createElement" })) return true;
|
|
23
|
+
return isJsxRuntimeCallee(t, callExpression.callee);
|
|
24
|
+
}
|
|
25
|
+
function buildHotUpdaterDomProps(t, fileName, spreadIdentifier) {
|
|
26
|
+
const overrideUri = t.objectProperty(t.identifier("overrideUri"), t.callExpression(t.memberExpression(t.arrayExpression([
|
|
27
|
+
t.identifier("baseURL"),
|
|
28
|
+
t.stringLiteral("www.bundle"),
|
|
29
|
+
t.stringLiteral(fileName)
|
|
30
|
+
]), t.identifier("join")), [t.stringLiteral("/")]));
|
|
31
|
+
const hotDomProps = spreadIdentifier ? [t.spreadElement(t.memberExpression(spreadIdentifier, t.identifier("dom"))), overrideUri] : [overrideUri];
|
|
32
|
+
const conditionalObject = t.conditionalExpression(t.identifier("baseURL"), t.objectExpression([t.objectProperty(t.identifier("dom"), t.objectExpression(hotDomProps)), t.objectProperty(t.identifier("filePath"), t.stringLiteral(fileName))]), t.objectExpression([t.objectProperty(t.identifier("filePath"), t.stringLiteral(fileName))]));
|
|
33
|
+
const arrowFunction = t.arrowFunctionExpression([t.identifier("baseURL")], conditionalObject);
|
|
34
|
+
const safeGetBaseURL = t.conditionalExpression(t.logicalExpression("&&", t.binaryExpression("!==", t.unaryExpression("typeof", t.identifier("globalThis"), true), t.stringLiteral("undefined")), t.memberExpression(t.identifier("globalThis"), t.identifier("HotUpdaterGetBaseURL"))), t.callExpression(t.memberExpression(t.identifier("globalThis"), t.identifier("HotUpdaterGetBaseURL")), []), t.unaryExpression("void", t.numericLiteral(0)));
|
|
35
|
+
return t.callExpression(arrowFunction, [safeGetBaseURL]);
|
|
36
|
+
}
|
|
37
|
+
function isWebViewJsxName(t, name) {
|
|
38
|
+
if (t.isJSXIdentifier(name)) return name.name === "WebView" || name.name.endsWith("WebView");
|
|
39
|
+
if (t.isJSXMemberExpression(name)) return isWebViewJsxName(t, name.property);
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
1
43
|
//#region src/babel.ts
|
|
2
|
-
/**
|
|
3
|
-
* Hot Updater Babel Plugin
|
|
4
|
-
*
|
|
5
|
-
* This plugin transforms Expo DOM component filePath to overrideUri for OTA
|
|
6
|
-
* updates.
|
|
7
|
-
*/
|
|
8
44
|
function babel_default({ types: t }) {
|
|
9
45
|
return {
|
|
10
46
|
name: "hot-updater-babel-plugin",
|
|
@@ -15,37 +51,41 @@ function babel_default({ types: t }) {
|
|
|
15
51
|
if (t.isVariableDeclarator(declarator) && t.isIdentifier(declarator.id) && declarator.id.name === "filePath" && t.isStringLiteral(declarator.init) && declarator.init.value.endsWith(".html")) filePathDeclarations.set(declarator.id.name, declarator.init.value);
|
|
16
52
|
});
|
|
17
53
|
});
|
|
18
|
-
programPath.traverse({
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
t.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
t.
|
|
40
|
-
t.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
programPath.traverse({
|
|
55
|
+
ObjectExpression(objPath) {
|
|
56
|
+
const filePathProp = objPath.node.properties.find((prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key, { name: "filePath" }) && (t.isIdentifier(prop.value, { name: "filePath" }) || t.isStringLiteral(prop.value) && prop.value.value.endsWith(".html")));
|
|
57
|
+
if (!filePathProp || !t.isObjectProperty(filePathProp)) return;
|
|
58
|
+
const parent = objPath.parent;
|
|
59
|
+
if (!t.isCallExpression(parent)) return;
|
|
60
|
+
if (!isSupportedWebViewCall(t, parent, objPath.node)) return;
|
|
61
|
+
const filePathValue = filePathProp.value;
|
|
62
|
+
let fileName;
|
|
63
|
+
if (t.isStringLiteral(filePathValue)) fileName = filePathValue.value;
|
|
64
|
+
else if (t.isIdentifier(filePathValue)) {
|
|
65
|
+
const declaredValue = filePathDeclarations.get(filePathValue.name);
|
|
66
|
+
if (!declaredValue) return;
|
|
67
|
+
fileName = declaredValue;
|
|
68
|
+
} else return;
|
|
69
|
+
const spreadElement = objPath.node.properties.find((prop) => t.isSpreadElement(prop));
|
|
70
|
+
const propIndex = objPath.node.properties.indexOf(filePathProp);
|
|
71
|
+
objPath.node.properties.splice(propIndex, 1, t.spreadElement(buildHotUpdaterDomProps(t, fileName, spreadElement && t.isIdentifier(spreadElement.argument) ? spreadElement.argument : void 0)));
|
|
72
|
+
},
|
|
73
|
+
JSXOpeningElement(jsxPath) {
|
|
74
|
+
if (!isWebViewJsxName(t, jsxPath.node.name)) return;
|
|
75
|
+
const filePathAttr = jsxPath.node.attributes.find((attr) => t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name, { name: "filePath" }) && (t.isStringLiteral(attr.value) || t.isJSXExpressionContainer(attr.value) && t.isIdentifier(attr.value.expression)));
|
|
76
|
+
if (!filePathAttr || !t.isJSXAttribute(filePathAttr)) return;
|
|
77
|
+
let fileName;
|
|
78
|
+
if (t.isStringLiteral(filePathAttr.value) && filePathAttr.value.value.endsWith(".html")) fileName = filePathAttr.value.value;
|
|
79
|
+
else if (t.isJSXExpressionContainer(filePathAttr.value) && t.isIdentifier(filePathAttr.value.expression)) {
|
|
80
|
+
const declaredValue = filePathDeclarations.get(filePathAttr.value.expression.name);
|
|
81
|
+
if (declaredValue) fileName = declaredValue;
|
|
82
|
+
}
|
|
83
|
+
if (!fileName) return;
|
|
84
|
+
const spreadAttribute = jsxPath.node.attributes.find((attr) => t.isJSXSpreadAttribute(attr));
|
|
85
|
+
const attrIndex = jsxPath.node.attributes.indexOf(filePathAttr);
|
|
86
|
+
jsxPath.node.attributes.splice(attrIndex, 1, t.jsxSpreadAttribute(buildHotUpdaterDomProps(t, fileName, spreadAttribute && t.isIdentifier(spreadAttribute.argument) ? spreadAttribute.argument : void 0)));
|
|
87
|
+
}
|
|
88
|
+
});
|
|
49
89
|
} } }
|
|
50
90
|
};
|
|
51
91
|
}
|
package/dist/babel-plugin.d.cts
CHANGED
|
@@ -5,10 +5,14 @@ type ObjectExpressionPath = {
|
|
|
5
5
|
node: babelTypes.ObjectExpression;
|
|
6
6
|
parent: babelTypes.Node;
|
|
7
7
|
};
|
|
8
|
+
type JSXOpeningElementPath = {
|
|
9
|
+
node: babelTypes.JSXOpeningElement;
|
|
10
|
+
};
|
|
8
11
|
type ProgramPath = {
|
|
9
12
|
node: babelTypes.Program;
|
|
10
13
|
traverse(visitor: {
|
|
11
|
-
ObjectExpression(path: ObjectExpressionPath): void;
|
|
14
|
+
ObjectExpression?(path: ObjectExpressionPath): void;
|
|
15
|
+
JSXOpeningElement?(path: JSXOpeningElementPath): void;
|
|
12
16
|
}): void;
|
|
13
17
|
};
|
|
14
18
|
type HotUpdaterBabelPlugin = {
|
|
@@ -19,12 +23,6 @@ type HotUpdaterBabelPlugin = {
|
|
|
19
23
|
};
|
|
20
24
|
};
|
|
21
25
|
};
|
|
22
|
-
/**
|
|
23
|
-
* Hot Updater Babel Plugin
|
|
24
|
-
*
|
|
25
|
-
* This plugin transforms Expo DOM component filePath to overrideUri for OTA
|
|
26
|
-
* updates.
|
|
27
|
-
*/
|
|
28
26
|
declare function export_default({
|
|
29
27
|
types: t
|
|
30
28
|
}: {
|
package/dist/babel-plugin.d.mts
CHANGED
|
@@ -5,10 +5,14 @@ type ObjectExpressionPath = {
|
|
|
5
5
|
node: babelTypes.ObjectExpression;
|
|
6
6
|
parent: babelTypes.Node;
|
|
7
7
|
};
|
|
8
|
+
type JSXOpeningElementPath = {
|
|
9
|
+
node: babelTypes.JSXOpeningElement;
|
|
10
|
+
};
|
|
8
11
|
type ProgramPath = {
|
|
9
12
|
node: babelTypes.Program;
|
|
10
13
|
traverse(visitor: {
|
|
11
|
-
ObjectExpression(path: ObjectExpressionPath): void;
|
|
14
|
+
ObjectExpression?(path: ObjectExpressionPath): void;
|
|
15
|
+
JSXOpeningElement?(path: JSXOpeningElementPath): void;
|
|
12
16
|
}): void;
|
|
13
17
|
};
|
|
14
18
|
type HotUpdaterBabelPlugin = {
|
|
@@ -19,12 +23,6 @@ type HotUpdaterBabelPlugin = {
|
|
|
19
23
|
};
|
|
20
24
|
};
|
|
21
25
|
};
|
|
22
|
-
/**
|
|
23
|
-
* Hot Updater Babel Plugin
|
|
24
|
-
*
|
|
25
|
-
* This plugin transforms Expo DOM component filePath to overrideUri for OTA
|
|
26
|
-
* updates.
|
|
27
|
-
*/
|
|
28
26
|
declare function export_default({
|
|
29
27
|
types: t
|
|
30
28
|
}: {
|
package/dist/babel-plugin.mjs
CHANGED
|
@@ -1,10 +1,46 @@
|
|
|
1
|
+
//#region src/babel-utils.ts
|
|
2
|
+
function isWebViewExpression(t, node) {
|
|
3
|
+
return t.isIdentifier(node) && (node.name === "WebView" || node.name.endsWith("WebView")) || t.isMemberExpression(node) && t.isIdentifier(node.property, { name: "WebView" });
|
|
4
|
+
}
|
|
5
|
+
function isJsxRuntimeCallee(t, callee) {
|
|
6
|
+
if (t.isIdentifier(callee)) return [
|
|
7
|
+
"jsx",
|
|
8
|
+
"jsxs",
|
|
9
|
+
"jsxDEV"
|
|
10
|
+
].some((name) => callee.name.endsWith(name));
|
|
11
|
+
if (t.isMemberExpression(callee)) return t.isIdentifier(callee.property) && [
|
|
12
|
+
"jsx",
|
|
13
|
+
"jsxs",
|
|
14
|
+
"jsxDEV"
|
|
15
|
+
].includes(callee.property.name);
|
|
16
|
+
if (t.isSequenceExpression(callee)) return isJsxRuntimeCallee(t, callee.expressions[callee.expressions.length - 1]);
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
function isSupportedWebViewCall(t, callExpression, propsNode) {
|
|
20
|
+
if (callExpression.arguments[1] !== propsNode) return false;
|
|
21
|
+
if (!isWebViewExpression(t, callExpression.arguments[0])) return false;
|
|
22
|
+
if (t.isMemberExpression(callExpression.callee) && t.isIdentifier(callExpression.callee.property, { name: "createElement" })) return true;
|
|
23
|
+
return isJsxRuntimeCallee(t, callExpression.callee);
|
|
24
|
+
}
|
|
25
|
+
function buildHotUpdaterDomProps(t, fileName, spreadIdentifier) {
|
|
26
|
+
const overrideUri = t.objectProperty(t.identifier("overrideUri"), t.callExpression(t.memberExpression(t.arrayExpression([
|
|
27
|
+
t.identifier("baseURL"),
|
|
28
|
+
t.stringLiteral("www.bundle"),
|
|
29
|
+
t.stringLiteral(fileName)
|
|
30
|
+
]), t.identifier("join")), [t.stringLiteral("/")]));
|
|
31
|
+
const hotDomProps = spreadIdentifier ? [t.spreadElement(t.memberExpression(spreadIdentifier, t.identifier("dom"))), overrideUri] : [overrideUri];
|
|
32
|
+
const conditionalObject = t.conditionalExpression(t.identifier("baseURL"), t.objectExpression([t.objectProperty(t.identifier("dom"), t.objectExpression(hotDomProps)), t.objectProperty(t.identifier("filePath"), t.stringLiteral(fileName))]), t.objectExpression([t.objectProperty(t.identifier("filePath"), t.stringLiteral(fileName))]));
|
|
33
|
+
const arrowFunction = t.arrowFunctionExpression([t.identifier("baseURL")], conditionalObject);
|
|
34
|
+
const safeGetBaseURL = t.conditionalExpression(t.logicalExpression("&&", t.binaryExpression("!==", t.unaryExpression("typeof", t.identifier("globalThis"), true), t.stringLiteral("undefined")), t.memberExpression(t.identifier("globalThis"), t.identifier("HotUpdaterGetBaseURL"))), t.callExpression(t.memberExpression(t.identifier("globalThis"), t.identifier("HotUpdaterGetBaseURL")), []), t.unaryExpression("void", t.numericLiteral(0)));
|
|
35
|
+
return t.callExpression(arrowFunction, [safeGetBaseURL]);
|
|
36
|
+
}
|
|
37
|
+
function isWebViewJsxName(t, name) {
|
|
38
|
+
if (t.isJSXIdentifier(name)) return name.name === "WebView" || name.name.endsWith("WebView");
|
|
39
|
+
if (t.isJSXMemberExpression(name)) return isWebViewJsxName(t, name.property);
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
1
43
|
//#region src/babel.ts
|
|
2
|
-
/**
|
|
3
|
-
* Hot Updater Babel Plugin
|
|
4
|
-
*
|
|
5
|
-
* This plugin transforms Expo DOM component filePath to overrideUri for OTA
|
|
6
|
-
* updates.
|
|
7
|
-
*/
|
|
8
44
|
function babel_default({ types: t }) {
|
|
9
45
|
return {
|
|
10
46
|
name: "hot-updater-babel-plugin",
|
|
@@ -15,37 +51,41 @@ function babel_default({ types: t }) {
|
|
|
15
51
|
if (t.isVariableDeclarator(declarator) && t.isIdentifier(declarator.id) && declarator.id.name === "filePath" && t.isStringLiteral(declarator.init) && declarator.init.value.endsWith(".html")) filePathDeclarations.set(declarator.id.name, declarator.init.value);
|
|
16
52
|
});
|
|
17
53
|
});
|
|
18
|
-
programPath.traverse({
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
t.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
t.
|
|
40
|
-
t.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
programPath.traverse({
|
|
55
|
+
ObjectExpression(objPath) {
|
|
56
|
+
const filePathProp = objPath.node.properties.find((prop) => t.isObjectProperty(prop) && t.isIdentifier(prop.key, { name: "filePath" }) && (t.isIdentifier(prop.value, { name: "filePath" }) || t.isStringLiteral(prop.value) && prop.value.value.endsWith(".html")));
|
|
57
|
+
if (!filePathProp || !t.isObjectProperty(filePathProp)) return;
|
|
58
|
+
const parent = objPath.parent;
|
|
59
|
+
if (!t.isCallExpression(parent)) return;
|
|
60
|
+
if (!isSupportedWebViewCall(t, parent, objPath.node)) return;
|
|
61
|
+
const filePathValue = filePathProp.value;
|
|
62
|
+
let fileName;
|
|
63
|
+
if (t.isStringLiteral(filePathValue)) fileName = filePathValue.value;
|
|
64
|
+
else if (t.isIdentifier(filePathValue)) {
|
|
65
|
+
const declaredValue = filePathDeclarations.get(filePathValue.name);
|
|
66
|
+
if (!declaredValue) return;
|
|
67
|
+
fileName = declaredValue;
|
|
68
|
+
} else return;
|
|
69
|
+
const spreadElement = objPath.node.properties.find((prop) => t.isSpreadElement(prop));
|
|
70
|
+
const propIndex = objPath.node.properties.indexOf(filePathProp);
|
|
71
|
+
objPath.node.properties.splice(propIndex, 1, t.spreadElement(buildHotUpdaterDomProps(t, fileName, spreadElement && t.isIdentifier(spreadElement.argument) ? spreadElement.argument : void 0)));
|
|
72
|
+
},
|
|
73
|
+
JSXOpeningElement(jsxPath) {
|
|
74
|
+
if (!isWebViewJsxName(t, jsxPath.node.name)) return;
|
|
75
|
+
const filePathAttr = jsxPath.node.attributes.find((attr) => t.isJSXAttribute(attr) && t.isJSXIdentifier(attr.name, { name: "filePath" }) && (t.isStringLiteral(attr.value) || t.isJSXExpressionContainer(attr.value) && t.isIdentifier(attr.value.expression)));
|
|
76
|
+
if (!filePathAttr || !t.isJSXAttribute(filePathAttr)) return;
|
|
77
|
+
let fileName;
|
|
78
|
+
if (t.isStringLiteral(filePathAttr.value) && filePathAttr.value.value.endsWith(".html")) fileName = filePathAttr.value.value;
|
|
79
|
+
else if (t.isJSXExpressionContainer(filePathAttr.value) && t.isIdentifier(filePathAttr.value.expression)) {
|
|
80
|
+
const declaredValue = filePathDeclarations.get(filePathAttr.value.expression.name);
|
|
81
|
+
if (declaredValue) fileName = declaredValue;
|
|
82
|
+
}
|
|
83
|
+
if (!fileName) return;
|
|
84
|
+
const spreadAttribute = jsxPath.node.attributes.find((attr) => t.isJSXSpreadAttribute(attr));
|
|
85
|
+
const attrIndex = jsxPath.node.attributes.indexOf(filePathAttr);
|
|
86
|
+
jsxPath.node.attributes.splice(attrIndex, 1, t.jsxSpreadAttribute(buildHotUpdaterDomProps(t, fileName, spreadAttribute && t.isIdentifier(spreadAttribute.argument) ? spreadAttribute.argument : void 0)));
|
|
87
|
+
}
|
|
88
|
+
});
|
|
49
89
|
} } }
|
|
50
90
|
};
|
|
51
91
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/expo",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.34.0",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.mjs",
|
|
@@ -27,9 +27,9 @@
|
|
|
27
27
|
"@babel/core": "7.26.0",
|
|
28
28
|
"@babel/types": "7.26.0",
|
|
29
29
|
"uuidv7": "^1.0.2",
|
|
30
|
-
"@hot-updater/
|
|
31
|
-
"@hot-updater/
|
|
32
|
-
"@hot-updater/plugin-core": "0.
|
|
30
|
+
"@hot-updater/cli-tools": "0.34.0",
|
|
31
|
+
"@hot-updater/bare": "0.34.0",
|
|
32
|
+
"@hot-updater/plugin-core": "0.34.0"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/node": "^20",
|