zero-com 0.0.6 → 0.0.7-s
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/lib/rollup.js +23 -6
- package/lib/webpack.js +25 -6
- package/package.json +3 -2
package/lib/rollup.js
CHANGED
|
@@ -92,14 +92,29 @@ function zeroComRollupPlugin(options) {
|
|
|
92
92
|
});
|
|
93
93
|
sourceFile.getVariableDeclarations().forEach(decl => {
|
|
94
94
|
const initializer = decl.getInitializer();
|
|
95
|
-
if (initializer
|
|
96
|
-
|
|
95
|
+
if (!initializer || !decl.isExported())
|
|
96
|
+
return;
|
|
97
|
+
if (initializer instanceof ts_morph_1.ArrowFunction && initializer.isAsync()) {
|
|
98
|
+
const funcName = decl.getName();
|
|
99
|
+
const lineNumber = decl.getStartLineNumber();
|
|
100
|
+
const funcParams = initializer.getParameters().map(p => p.getName()).join(', ');
|
|
101
|
+
const funcId = (0, common_1.formatFuncIdName)(funcName, path_1.default.relative(process.cwd(), id), lineNumber);
|
|
102
|
+
const newFunctionBody = `return window.${common_1.ZERO_COM_CLIENT_SEND}({funcId: '${funcId}', params: [${funcParams}]})`;
|
|
103
|
+
initializer.setBodyText(newFunctionBody);
|
|
104
|
+
}
|
|
105
|
+
else if (initializer.getKind() === typescript_1.default.SyntaxKind.CallExpression && initializer.getExpression().getText() === 'serverFn') {
|
|
106
|
+
const call = initializer;
|
|
107
|
+
const arg = call.getArguments()[0];
|
|
108
|
+
if (arg && arg instanceof ts_morph_1.ArrowFunction) {
|
|
97
109
|
const funcName = decl.getName();
|
|
98
110
|
const lineNumber = decl.getStartLineNumber();
|
|
99
|
-
const funcParams =
|
|
111
|
+
const funcParams = arg.getParameters().map(p => p.getName()).join(', ');
|
|
100
112
|
const funcId = (0, common_1.formatFuncIdName)(funcName, path_1.default.relative(process.cwd(), id), lineNumber);
|
|
101
113
|
const newFunctionBody = `return window.${common_1.ZERO_COM_CLIENT_SEND}({funcId: '${funcId}', params: [${funcParams}]})`;
|
|
102
|
-
|
|
114
|
+
// Create a new arrow function string
|
|
115
|
+
const newArrowFunc = `(${funcParams}) => { ${newFunctionBody} }`;
|
|
116
|
+
// Replace the serverFn call with the new arrow function
|
|
117
|
+
decl.setInitializer(newArrowFunc);
|
|
103
118
|
}
|
|
104
119
|
}
|
|
105
120
|
});
|
|
@@ -116,8 +131,10 @@ function zeroComRollupPlugin(options) {
|
|
|
116
131
|
});
|
|
117
132
|
sourceFile.getVariableDeclarations().forEach(decl => {
|
|
118
133
|
const initializer = decl.getInitializer();
|
|
119
|
-
if (initializer
|
|
120
|
-
|
|
134
|
+
if (initializer) {
|
|
135
|
+
const isServerFn = initializer.getKind() === typescript_1.default.SyntaxKind.CallExpression && initializer.getExpression().getText() === 'serverFn';
|
|
136
|
+
if ((initializer instanceof ts_morph_1.ArrowFunction && decl.isExported() && initializer.isAsync()) ||
|
|
137
|
+
(isServerFn && decl.isExported())) {
|
|
121
138
|
const funcName = decl.getName();
|
|
122
139
|
const lineNumber = decl.getStartLineNumber();
|
|
123
140
|
const funcId = (0, common_1.formatFuncIdName)(funcName, path_1.default.relative(process.cwd(), id), lineNumber);
|
package/lib/webpack.js
CHANGED
|
@@ -69,14 +69,31 @@ class ZeroComWebpackPlugin {
|
|
|
69
69
|
});
|
|
70
70
|
sourceFile.getVariableDeclarations().forEach(decl => {
|
|
71
71
|
const initializer = decl.getInitializer();
|
|
72
|
-
if (initializer
|
|
73
|
-
|
|
72
|
+
if (!initializer || !decl.isExported())
|
|
73
|
+
return;
|
|
74
|
+
if (initializer instanceof ts_morph_1.ArrowFunction && initializer.isAsync()) {
|
|
75
|
+
const funcName = decl.getName();
|
|
76
|
+
const lineNumber = decl.getStartLineNumber();
|
|
77
|
+
const funcParams = initializer.getParameters().map(p => p.getName()).join(', ');
|
|
78
|
+
const funcId = (0, common_1.formatFuncIdName)(funcName, path_1.default.relative(compiler.context, absolutePath), lineNumber);
|
|
79
|
+
const newFunctionBody = `return window.${common_1.ZERO_COM_CLIENT_SEND}({funcId: '${funcId}', params: [${funcParams}]})`;
|
|
80
|
+
initializer.setBodyText(newFunctionBody);
|
|
81
|
+
generatedFunctions.push(decl.getVariableStatementOrThrow().getText());
|
|
82
|
+
console.log('client:', funcId);
|
|
83
|
+
}
|
|
84
|
+
else if (initializer.getKind() === typescript_1.default.SyntaxKind.CallExpression && initializer.getExpression().getText() === 'serverFn') {
|
|
85
|
+
const call = initializer;
|
|
86
|
+
const arg = call.getArguments()[0];
|
|
87
|
+
if (arg && arg instanceof ts_morph_1.ArrowFunction) {
|
|
74
88
|
const funcName = decl.getName();
|
|
75
89
|
const lineNumber = decl.getStartLineNumber();
|
|
76
|
-
const funcParams =
|
|
90
|
+
const funcParams = arg.getParameters().map(p => p.getName()).join(', ');
|
|
77
91
|
const funcId = (0, common_1.formatFuncIdName)(funcName, path_1.default.relative(compiler.context, absolutePath), lineNumber);
|
|
78
92
|
const newFunctionBody = `return window.${common_1.ZERO_COM_CLIENT_SEND}({funcId: '${funcId}', params: [${funcParams}]})`;
|
|
79
|
-
|
|
93
|
+
// Create a new arrow function string
|
|
94
|
+
const newArrowFunc = `(${funcParams}) => { ${newFunctionBody} }`;
|
|
95
|
+
// Replace the serverFn call with the new arrow function
|
|
96
|
+
decl.setInitializer(newArrowFunc);
|
|
80
97
|
generatedFunctions.push(decl.getVariableStatementOrThrow().getText());
|
|
81
98
|
console.log('client:', funcId);
|
|
82
99
|
}
|
|
@@ -97,8 +114,10 @@ class ZeroComWebpackPlugin {
|
|
|
97
114
|
});
|
|
98
115
|
sourceFile.getVariableDeclarations().forEach(decl => {
|
|
99
116
|
const initializer = decl.getInitializer();
|
|
100
|
-
if (initializer
|
|
101
|
-
|
|
117
|
+
if (initializer) {
|
|
118
|
+
const isServerFn = initializer.getKind() === typescript_1.default.SyntaxKind.CallExpression && initializer.getExpression().getText() === 'serverFn';
|
|
119
|
+
if ((initializer instanceof ts_morph_1.ArrowFunction && decl.isExported() && initializer.isAsync()) ||
|
|
120
|
+
(isServerFn && decl.isExported())) {
|
|
102
121
|
const funcName = decl.getName();
|
|
103
122
|
const lineNumber = decl.getStartLineNumber();
|
|
104
123
|
const funcId = (0, common_1.formatFuncIdName)(funcName, path_1.default.relative(compiler.context, absolutePath), lineNumber);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zero-com",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7s",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"repository": "https://github.com/yosbelms/zero-com",
|
|
6
6
|
"keywords": [
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
],
|
|
14
14
|
"scripts": {
|
|
15
15
|
"build": "npx tsc -d",
|
|
16
|
-
"
|
|
16
|
+
"clean": "find . -type f \\( -name \"*.js\" -o -name \"*.js.map\" -o -name \"*.d.ts\" -o -name \"*.d.ts.map\" \\) | grep -v \"./node_modules\" | xargs rm",
|
|
17
|
+
"prepublishOnly": "npm run clean && npm run build"
|
|
17
18
|
},
|
|
18
19
|
"author": "",
|
|
19
20
|
"license": "MIT",
|