@hot-updater/expo 0.28.0 → 0.29.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 +53 -0
- package/dist/babel-plugin.d.cts +33 -0
- package/dist/babel-plugin.d.mts +34 -0
- package/dist/babel-plugin.mjs +53 -0
- package/dist/index.cjs +314 -497
- package/dist/{index.js → index.mjs} +306 -476
- package/package.json +40 -8
- /package/dist/{index.d.ts → index.d.mts} +0 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//#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
|
+
function babel_default({ types: t }) {
|
|
9
|
+
return {
|
|
10
|
+
name: "hot-updater-babel-plugin",
|
|
11
|
+
visitor: { Program: { exit(programPath) {
|
|
12
|
+
const filePathDeclarations = /* @__PURE__ */ new Map();
|
|
13
|
+
programPath.node.body.forEach((node) => {
|
|
14
|
+
if (t.isVariableDeclaration(node) && node.declarations.length > 0) node.declarations.forEach((declarator) => {
|
|
15
|
+
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
|
+
});
|
|
17
|
+
});
|
|
18
|
+
programPath.traverse({ ObjectExpression(objPath) {
|
|
19
|
+
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")));
|
|
20
|
+
if (!filePathProp || !t.isObjectProperty(filePathProp)) return;
|
|
21
|
+
const parent = objPath.parent;
|
|
22
|
+
if (!t.isCallExpression(parent) || !t.isMemberExpression(parent.callee) || !t.isIdentifier(parent.callee.property, { name: "createElement" })) return;
|
|
23
|
+
const firstArg = parent.arguments[0];
|
|
24
|
+
if (!(t.isIdentifier(firstArg) && (firstArg.name === "WebView" || firstArg.name.endsWith("WebView")) || t.isMemberExpression(firstArg) && t.isIdentifier(firstArg.property, { name: "WebView" }))) return;
|
|
25
|
+
const filePathValue = filePathProp.value;
|
|
26
|
+
let fileName;
|
|
27
|
+
if (t.isStringLiteral(filePathValue)) fileName = filePathValue.value;
|
|
28
|
+
else if (t.isIdentifier(filePathValue)) {
|
|
29
|
+
const declaredValue = filePathDeclarations.get(filePathValue.name);
|
|
30
|
+
if (!declaredValue) return;
|
|
31
|
+
fileName = declaredValue;
|
|
32
|
+
} else return;
|
|
33
|
+
const spreadElement = objPath.node.properties.find((prop) => t.isSpreadElement(prop));
|
|
34
|
+
const conditionalObject = t.conditionalExpression(t.identifier("baseURL"), t.objectExpression([t.objectProperty(t.identifier("dom"), t.objectExpression(spreadElement && t.isIdentifier(spreadElement.argument) ? [t.spreadElement(t.memberExpression(spreadElement.argument, t.identifier("dom"))), t.objectProperty(t.identifier("overrideUri"), t.callExpression(t.memberExpression(t.arrayExpression([
|
|
35
|
+
t.identifier("baseURL"),
|
|
36
|
+
t.stringLiteral("www.bundle"),
|
|
37
|
+
t.stringLiteral(fileName)
|
|
38
|
+
]), t.identifier("join")), [t.stringLiteral("/")]))] : [t.objectProperty(t.identifier("overrideUri"), t.callExpression(t.memberExpression(t.arrayExpression([
|
|
39
|
+
t.identifier("baseURL"),
|
|
40
|
+
t.stringLiteral("www.bundle"),
|
|
41
|
+
t.stringLiteral(fileName)
|
|
42
|
+
]), t.identifier("join")), [t.stringLiteral("/")]))])), t.objectProperty(t.identifier("filePath"), t.stringLiteral(fileName))]), t.objectExpression([t.objectProperty(t.identifier("filePath"), t.stringLiteral(fileName))]));
|
|
43
|
+
const arrowFunction = t.arrowFunctionExpression([t.identifier("baseURL")], conditionalObject);
|
|
44
|
+
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)));
|
|
45
|
+
const iifeCall = t.callExpression(arrowFunction, [safeGetBaseURL]);
|
|
46
|
+
const propIndex = objPath.node.properties.indexOf(filePathProp);
|
|
47
|
+
objPath.node.properties.splice(propIndex, 1, t.spreadElement(iifeCall));
|
|
48
|
+
} });
|
|
49
|
+
} } }
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
module.exports = babel_default;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as babelTypes from "@babel/types";
|
|
2
|
+
|
|
3
|
+
//#region src/babel.d.ts
|
|
4
|
+
type ObjectExpressionPath = {
|
|
5
|
+
node: babelTypes.ObjectExpression;
|
|
6
|
+
parent: babelTypes.Node;
|
|
7
|
+
};
|
|
8
|
+
type ProgramPath = {
|
|
9
|
+
node: babelTypes.Program;
|
|
10
|
+
traverse(visitor: {
|
|
11
|
+
ObjectExpression(path: ObjectExpressionPath): void;
|
|
12
|
+
}): void;
|
|
13
|
+
};
|
|
14
|
+
type HotUpdaterBabelPlugin = {
|
|
15
|
+
name: string;
|
|
16
|
+
visitor: {
|
|
17
|
+
Program: {
|
|
18
|
+
exit(programPath: ProgramPath): void;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Hot Updater Babel Plugin
|
|
24
|
+
*
|
|
25
|
+
* This plugin transforms Expo DOM component filePath to overrideUri for OTA
|
|
26
|
+
* updates.
|
|
27
|
+
*/
|
|
28
|
+
declare function export_default({
|
|
29
|
+
types: t
|
|
30
|
+
}: {
|
|
31
|
+
types: typeof babelTypes;
|
|
32
|
+
}): HotUpdaterBabelPlugin;
|
|
33
|
+
export = export_default;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as babelTypes from "@babel/types";
|
|
2
|
+
|
|
3
|
+
//#region src/babel.d.ts
|
|
4
|
+
type ObjectExpressionPath = {
|
|
5
|
+
node: babelTypes.ObjectExpression;
|
|
6
|
+
parent: babelTypes.Node;
|
|
7
|
+
};
|
|
8
|
+
type ProgramPath = {
|
|
9
|
+
node: babelTypes.Program;
|
|
10
|
+
traverse(visitor: {
|
|
11
|
+
ObjectExpression(path: ObjectExpressionPath): void;
|
|
12
|
+
}): void;
|
|
13
|
+
};
|
|
14
|
+
type HotUpdaterBabelPlugin = {
|
|
15
|
+
name: string;
|
|
16
|
+
visitor: {
|
|
17
|
+
Program: {
|
|
18
|
+
exit(programPath: ProgramPath): void;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Hot Updater Babel Plugin
|
|
24
|
+
*
|
|
25
|
+
* This plugin transforms Expo DOM component filePath to overrideUri for OTA
|
|
26
|
+
* updates.
|
|
27
|
+
*/
|
|
28
|
+
declare function export_default({
|
|
29
|
+
types: t
|
|
30
|
+
}: {
|
|
31
|
+
types: typeof babelTypes;
|
|
32
|
+
}): HotUpdaterBabelPlugin;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { export_default as default };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//#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
|
+
function babel_default({ types: t }) {
|
|
9
|
+
return {
|
|
10
|
+
name: "hot-updater-babel-plugin",
|
|
11
|
+
visitor: { Program: { exit(programPath) {
|
|
12
|
+
const filePathDeclarations = /* @__PURE__ */ new Map();
|
|
13
|
+
programPath.node.body.forEach((node) => {
|
|
14
|
+
if (t.isVariableDeclaration(node) && node.declarations.length > 0) node.declarations.forEach((declarator) => {
|
|
15
|
+
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
|
+
});
|
|
17
|
+
});
|
|
18
|
+
programPath.traverse({ ObjectExpression(objPath) {
|
|
19
|
+
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")));
|
|
20
|
+
if (!filePathProp || !t.isObjectProperty(filePathProp)) return;
|
|
21
|
+
const parent = objPath.parent;
|
|
22
|
+
if (!t.isCallExpression(parent) || !t.isMemberExpression(parent.callee) || !t.isIdentifier(parent.callee.property, { name: "createElement" })) return;
|
|
23
|
+
const firstArg = parent.arguments[0];
|
|
24
|
+
if (!(t.isIdentifier(firstArg) && (firstArg.name === "WebView" || firstArg.name.endsWith("WebView")) || t.isMemberExpression(firstArg) && t.isIdentifier(firstArg.property, { name: "WebView" }))) return;
|
|
25
|
+
const filePathValue = filePathProp.value;
|
|
26
|
+
let fileName;
|
|
27
|
+
if (t.isStringLiteral(filePathValue)) fileName = filePathValue.value;
|
|
28
|
+
else if (t.isIdentifier(filePathValue)) {
|
|
29
|
+
const declaredValue = filePathDeclarations.get(filePathValue.name);
|
|
30
|
+
if (!declaredValue) return;
|
|
31
|
+
fileName = declaredValue;
|
|
32
|
+
} else return;
|
|
33
|
+
const spreadElement = objPath.node.properties.find((prop) => t.isSpreadElement(prop));
|
|
34
|
+
const conditionalObject = t.conditionalExpression(t.identifier("baseURL"), t.objectExpression([t.objectProperty(t.identifier("dom"), t.objectExpression(spreadElement && t.isIdentifier(spreadElement.argument) ? [t.spreadElement(t.memberExpression(spreadElement.argument, t.identifier("dom"))), t.objectProperty(t.identifier("overrideUri"), t.callExpression(t.memberExpression(t.arrayExpression([
|
|
35
|
+
t.identifier("baseURL"),
|
|
36
|
+
t.stringLiteral("www.bundle"),
|
|
37
|
+
t.stringLiteral(fileName)
|
|
38
|
+
]), t.identifier("join")), [t.stringLiteral("/")]))] : [t.objectProperty(t.identifier("overrideUri"), t.callExpression(t.memberExpression(t.arrayExpression([
|
|
39
|
+
t.identifier("baseURL"),
|
|
40
|
+
t.stringLiteral("www.bundle"),
|
|
41
|
+
t.stringLiteral(fileName)
|
|
42
|
+
]), t.identifier("join")), [t.stringLiteral("/")]))])), t.objectProperty(t.identifier("filePath"), t.stringLiteral(fileName))]), t.objectExpression([t.objectProperty(t.identifier("filePath"), t.stringLiteral(fileName))]));
|
|
43
|
+
const arrowFunction = t.arrowFunctionExpression([t.identifier("baseURL")], conditionalObject);
|
|
44
|
+
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)));
|
|
45
|
+
const iifeCall = t.callExpression(arrowFunction, [safeGetBaseURL]);
|
|
46
|
+
const propIndex = objPath.node.properties.indexOf(filePathProp);
|
|
47
|
+
objPath.node.properties.splice(propIndex, 1, t.spreadElement(iifeCall));
|
|
48
|
+
} });
|
|
49
|
+
} } }
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//#endregion
|
|
53
|
+
export { babel_default as default };
|