@holo-js/adapter-shared 0.3.0 → 0.3.2
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/index.d.ts +5 -2
- package/dist/index.mjs +33 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -19,8 +19,11 @@ type RealtimeDefinitionTransformResult = {
|
|
|
19
19
|
readonly code: string;
|
|
20
20
|
readonly map: RealtimeDefinitionSourceMap;
|
|
21
21
|
};
|
|
22
|
+
type RealtimeDefinitionTransformOptions = {
|
|
23
|
+
readonly preserveServerHandlers?: boolean;
|
|
24
|
+
};
|
|
22
25
|
declare function stripRealtimeServerHandlers(source: string): string;
|
|
23
26
|
declare function createRealtimeClientDefinitionModule(source: string, importTarget: string): string;
|
|
24
|
-
declare function createRealtimeClientDefinitionTransform(source: string, importTarget: string): RealtimeDefinitionTransformResult;
|
|
27
|
+
declare function createRealtimeClientDefinitionTransform(source: string, importTarget: string, options?: RealtimeDefinitionTransformOptions): RealtimeDefinitionTransformResult;
|
|
25
28
|
|
|
26
|
-
export { type ClientErrorPageOptions, type RealtimeDefinitionSourceMap, type RealtimeDefinitionTransformResult, createRealtimeClientDefinitionModule, createRealtimeClientDefinitionTransform, renderClientHttpErrorPage, stripRealtimeServerHandlers };
|
|
29
|
+
export { type ClientErrorPageOptions, type RealtimeDefinitionSourceMap, type RealtimeDefinitionTransformOptions, type RealtimeDefinitionTransformResult, createRealtimeClientDefinitionModule, createRealtimeClientDefinitionTransform, renderClientHttpErrorPage, stripRealtimeServerHandlers };
|
package/dist/index.mjs
CHANGED
|
@@ -122,6 +122,30 @@ function parseRealtimeSource(source) {
|
|
|
122
122
|
}
|
|
123
123
|
return ts.createSourceFile("realtime.ts", source, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
|
|
124
124
|
}
|
|
125
|
+
function retargetRealtimeImports(source, importTarget) {
|
|
126
|
+
const sourceFile = parseRealtimeSource(source);
|
|
127
|
+
const transformer = (context) => (root) => {
|
|
128
|
+
const visit = (node) => {
|
|
129
|
+
if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier) && node.moduleSpecifier.text === "@holo-js/realtime") {
|
|
130
|
+
return ts.factory.updateImportDeclaration(
|
|
131
|
+
node,
|
|
132
|
+
node.modifiers,
|
|
133
|
+
node.importClause,
|
|
134
|
+
ts.factory.createStringLiteral(importTarget),
|
|
135
|
+
node.attributes
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
return ts.visitEachChild(node, visit, context);
|
|
139
|
+
};
|
|
140
|
+
return ts.visitNode(root, visit);
|
|
141
|
+
};
|
|
142
|
+
const result = ts.transform(sourceFile, [transformer]);
|
|
143
|
+
try {
|
|
144
|
+
return ts.createPrinter({ newLine: ts.NewLineKind.LineFeed }).printFile(result.transformed[0]);
|
|
145
|
+
} finally {
|
|
146
|
+
result.dispose();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
125
149
|
function stripRealtimeServerHandlers(source) {
|
|
126
150
|
const sourceFile = parseRealtimeSource(source);
|
|
127
151
|
const transformer = (context) => (root) => {
|
|
@@ -146,7 +170,15 @@ function stripRealtimeServerHandlers(source) {
|
|
|
146
170
|
function createRealtimeClientDefinitionModule(source, importTarget) {
|
|
147
171
|
return createRealtimeClientDefinitionTransform(source, importTarget).code;
|
|
148
172
|
}
|
|
149
|
-
function createRealtimeClientDefinitionTransform(source, importTarget) {
|
|
173
|
+
function createRealtimeClientDefinitionTransform(source, importTarget, options = {}) {
|
|
174
|
+
if (options.preserveServerHandlers) {
|
|
175
|
+
const code = retargetRealtimeImports(source, importTarget);
|
|
176
|
+
const sourceLineCount = source.split("\n").length;
|
|
177
|
+
return Object.freeze({
|
|
178
|
+
code,
|
|
179
|
+
map: createSourceMap(source, code.split("\n").map((_, index) => Math.min(index, sourceLineCount - 1)))
|
|
180
|
+
});
|
|
181
|
+
}
|
|
150
182
|
const sourceFile = parseRealtimeSource(source);
|
|
151
183
|
const definitions = collectDefinitions(sourceFile);
|
|
152
184
|
if (definitions.length === 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@holo-js/adapter-shared",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Holo-JS Framework - shared framework adapter infrastructure",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"test": "vitest --run"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@holo-js/kernel": "^0.3.
|
|
26
|
+
"@holo-js/kernel": "^0.3.2",
|
|
27
27
|
"typescript": "^5.7.2"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|