@jay-framework/compiler-jay-stack 0.16.5 → 0.17.1

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 CHANGED
@@ -28,7 +28,7 @@ type BuildEnvironment = 'client' | 'server';
28
28
  * @param environment - Target environment ('client' or 'server')
29
29
  * @returns Transformed code
30
30
  */
31
- declare function transformJayStackBuilder(code: string, filePath: string, environment: BuildEnvironment): {
31
+ declare function transformJayStackBuilder(code: string, filePath: string, environment: BuildEnvironment, stripBuilders?: Set<string>): {
32
32
  code: string;
33
33
  map?: any;
34
34
  };
package/dist/index.js CHANGED
@@ -25,7 +25,7 @@ function shouldRemoveMethod(methodName, environment) {
25
25
  return true;
26
26
  return false;
27
27
  }
28
- const { isCallExpression: isCallExpression$1, isPropertyAccessExpression: isPropertyAccessExpression$1, isIdentifier: isIdentifier$2, isStringLiteral } = tsBridge;
28
+ const { isCallExpression: isCallExpression$1, isPropertyAccessExpression: isPropertyAccessExpression$1, isIdentifier: isIdentifier$2, isStringLiteral: isStringLiteral$1 } = tsBridge;
29
29
  function findBuilderMethodsToRemove(sourceFile, bindingResolver, environment) {
30
30
  const callsToRemove = [];
31
31
  const removedVariables = /* @__PURE__ */ new Set();
@@ -54,7 +54,7 @@ function isPartOfJayStackChain(callExpr, bindingResolver) {
54
54
  if (isIdentifier$2(current.expression)) {
55
55
  const variable = bindingResolver.explain(current.expression);
56
56
  const flattened = flattenVariable(variable);
57
- if (flattened.path.length === 1 && JAY_BUILDER_FUNCTIONS.has(flattened.path[0]) && isImportModuleVariableRoot(flattened.root) && isStringLiteral(flattened.root.module) && flattened.root.module.text === "@jay-framework/fullstack-component")
57
+ if (flattened.path.length === 1 && JAY_BUILDER_FUNCTIONS.has(flattened.path[0]) && isImportModuleVariableRoot(flattened.root) && isStringLiteral$1(flattened.root.module) && flattened.root.module.text === "@jay-framework/fullstack-component")
58
58
  return true;
59
59
  }
60
60
  if (isPropertyAccessExpression$1(current.expression)) {
@@ -185,11 +185,14 @@ const {
185
185
  isPropertyAccessExpression,
186
186
  isImportDeclaration,
187
187
  isNamedImports,
188
- isIdentifier
188
+ isIdentifier,
189
+ isStringLiteral
189
190
  } = tsBridge;
190
- function transformJayStackBuilder(code, filePath, environment) {
191
+ function transformJayStackBuilder(code, filePath, environment, stripBuilders) {
191
192
  const sourceFile = createSourceFile(filePath, code, ScriptTarget.Latest, true);
192
- const transformers = [mkTransformer(mkJayStackCodeSplitTransformer, { environment })];
193
+ const transformers = [
194
+ mkTransformer(mkJayStackCodeSplitTransformer, { environment, stripBuilders })
195
+ ];
193
196
  const printer = createPrinter();
194
197
  const result = tsBridge.transform(sourceFile, transformers);
195
198
  const transformedFile = result.transformed[0];
@@ -206,10 +209,25 @@ function mkJayStackCodeSplitTransformer({
206
209
  factory,
207
210
  sourceFile,
208
211
  context,
209
- environment
212
+ environment,
213
+ stripBuilders
210
214
  }) {
211
215
  const bindingResolver = new SourceFileBindingResolver(sourceFile);
212
- const { callsToRemove } = findBuilderMethodsToRemove(sourceFile, bindingResolver, environment);
216
+ let workingSourceFile = sourceFile;
217
+ if (stripBuilders && stripBuilders.size > 0) {
218
+ const filtered = sourceFile.statements.filter((statement) => {
219
+ const rootName = findChainRootBuilderName(statement, bindingResolver);
220
+ return !rootName || !stripBuilders.has(rootName);
221
+ });
222
+ if (filtered.length !== sourceFile.statements.length) {
223
+ workingSourceFile = factory.updateSourceFile(sourceFile, filtered);
224
+ }
225
+ }
226
+ const { callsToRemove } = findBuilderMethodsToRemove(
227
+ workingSourceFile,
228
+ bindingResolver,
229
+ environment
230
+ );
213
231
  const transformVisitor = (node) => {
214
232
  if (isCallExpression(node) && isPropertyAccessExpression(node.expression)) {
215
233
  const variable = bindingResolver.explain(node.expression);
@@ -222,7 +240,7 @@ function mkJayStackCodeSplitTransformer({
222
240
  return visitEachChild(node, transformVisitor, context);
223
241
  };
224
242
  let transformedSourceFile = visitEachChild(
225
- sourceFile,
243
+ workingSourceFile,
226
244
  transformVisitor,
227
245
  context
228
246
  );
@@ -262,6 +280,36 @@ function filterImportDeclaration(statement, unusedImports, factory) {
262
280
  statement.assertClause
263
281
  );
264
282
  }
283
+ function findChainRootBuilderName(statement, bindingResolver) {
284
+ let expr;
285
+ if (tsBridge.isVariableStatement(statement)) {
286
+ for (const decl of statement.declarationList.declarations) {
287
+ if (decl.initializer && isCallExpression(decl.initializer)) {
288
+ expr = decl.initializer;
289
+ }
290
+ }
291
+ }
292
+ if (tsBridge.isExpressionStatement(statement) && isCallExpression(statement.expression)) {
293
+ expr = statement.expression;
294
+ }
295
+ if (!expr)
296
+ return void 0;
297
+ let current = expr;
298
+ while (true) {
299
+ if (isCallExpression(current) && isPropertyAccessExpression(current.expression)) {
300
+ current = current.expression.expression;
301
+ } else if (isCallExpression(current) && isIdentifier(current.expression)) {
302
+ const variable = bindingResolver.explain(current.expression);
303
+ const flattened = flattenVariable(variable);
304
+ if (flattened.path.length === 1 && isImportModuleVariableRoot(flattened.root) && isStringLiteral(flattened.root.module) && flattened.root.module.text === "@jay-framework/fullstack-component") {
305
+ return flattened.path[0];
306
+ }
307
+ return void 0;
308
+ } else {
309
+ return void 0;
310
+ }
311
+ }
312
+ }
265
313
  const actionMetadataCache = /* @__PURE__ */ new Map();
266
314
  function clearActionMetadataCache() {
267
315
  actionMetadataCache.clear();
@@ -765,6 +813,9 @@ function jayStackCompiler(options = {}) {
765
813
  if (!id.endsWith(".ts") && !id.includes(".ts?")) {
766
814
  return null;
767
815
  }
816
+ if (id.includes(".jay-html")) {
817
+ return null;
818
+ }
768
819
  const hasComponent = code.includes("makeJayStackComponent");
769
820
  const hasInit = code.includes("makeJayInit");
770
821
  if (!hasComponent && !hasInit) {
@@ -874,6 +925,23 @@ function jayStackCompiler(options = {}) {
874
925
  }
875
926
  const result = lines.join("\n");
876
927
  return result;
928
+ },
929
+ // Strip inline makeJayAction/makeJayQuery/makeJayStream statements
930
+ // from component files in client builds. These are server-only
931
+ // constructs that shouldn't appear in client bundles.
932
+ transform(code, id, options2) {
933
+ if (options2?.ssr || isSSRBuild)
934
+ return null;
935
+ if (!id.endsWith(".ts") && !id.includes(".ts?"))
936
+ return null;
937
+ if (id.includes(".jay-html"))
938
+ return null;
939
+ if (isActionImport(id))
940
+ return null;
941
+ const ACTION_BUILDERS = ["makeJayAction", "makeJayQuery", "makeJayStream"];
942
+ if (!ACTION_BUILDERS.some((b) => code.includes(b)))
943
+ return null;
944
+ return stripInlineActionBuilders(code, ACTION_BUILDERS);
877
945
  }
878
946
  };
879
947
  })(),
@@ -882,6 +950,9 @@ function jayStackCompiler(options = {}) {
882
950
  );
883
951
  return plugins;
884
952
  }
953
+ function stripInlineActionBuilders(code, builderNames) {
954
+ return transformJayStackBuilder(code, "action-strip.ts", "client", new Set(builderNames));
955
+ }
885
956
  export {
886
957
  clearActionMetadataCache,
887
958
  createDefaultPluginDetector,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jay-framework/compiler-jay-stack",
3
- "version": "0.16.5",
3
+ "version": "0.17.1",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
@@ -27,16 +27,16 @@
27
27
  "test:watch": "vitest"
28
28
  },
29
29
  "dependencies": {
30
- "@jay-framework/compiler": "^0.16.5",
31
- "@jay-framework/compiler-shared": "^0.16.5",
32
- "@jay-framework/logger": "^0.16.5",
33
- "@jay-framework/typescript-bridge": "^0.16.5",
34
- "@jay-framework/vite-plugin": "^0.16.5",
30
+ "@jay-framework/compiler": "^0.17.1",
31
+ "@jay-framework/compiler-shared": "^0.17.1",
32
+ "@jay-framework/logger": "^0.17.1",
33
+ "@jay-framework/typescript-bridge": "^0.17.1",
34
+ "@jay-framework/vite-plugin": "^0.17.1",
35
35
  "typescript": "^5.3.3",
36
36
  "vite": "^5.0.11"
37
37
  },
38
38
  "devDependencies": {
39
- "@jay-framework/dev-environment": "^0.16.5",
39
+ "@jay-framework/dev-environment": "^0.17.1",
40
40
  "rimraf": "^5.0.5",
41
41
  "tsup": "^8.0.1",
42
42
  "vitest": "^1.2.1"