@jay-framework/compiler-shared 0.9.0 → 0.11.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/index.d.ts +198 -1
- package/dist/index.js +305 -4
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ declare const Import: {
|
|
|
31
31
|
svgDynamicElement: ImportName;
|
|
32
32
|
mathMLDynamicElement: ImportName;
|
|
33
33
|
forEach: ImportName;
|
|
34
|
+
slowForEachItem: ImportName;
|
|
34
35
|
resolved: ImportName;
|
|
35
36
|
pending: ImportName;
|
|
36
37
|
rejected: ImportName;
|
|
@@ -267,6 +268,114 @@ declare function getModeFromExtension(filename: string): RuntimeMode;
|
|
|
267
268
|
declare function getJayTsFileSourcePath(filename: string): string;
|
|
268
269
|
declare function withoutExtension(filename: string, extension: string): string;
|
|
269
270
|
|
|
271
|
+
/**
|
|
272
|
+
* Utilities for handling Jay environment metadata in module specifiers.
|
|
273
|
+
*
|
|
274
|
+
* Jay uses query parameters to pass environment information through the import chain:
|
|
275
|
+
* - `?jay-client` / `?jay-server` - Client/server code splitting
|
|
276
|
+
* - `?jay-mainSandbox` / `?jay-workerTrusted` / `?jay-workerSandbox` - Security sandbox modes
|
|
277
|
+
*
|
|
278
|
+
* These utilities provide a consistent way to parse, add, and detect these parameters
|
|
279
|
+
* while correctly handling file extensions like `.jay-contract` and `.jay-html`.
|
|
280
|
+
*/
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Environment types for Jay code splitting
|
|
284
|
+
*/
|
|
285
|
+
declare enum JayBuildEnvironment {
|
|
286
|
+
Client = "client",
|
|
287
|
+
Server = "server"
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* All possible Jay environment query parameter values
|
|
291
|
+
*/
|
|
292
|
+
type JayEnvironment = JayBuildEnvironment | RuntimeMode;
|
|
293
|
+
/**
|
|
294
|
+
* Query parameter strings for build environments
|
|
295
|
+
*/
|
|
296
|
+
declare const JAY_QUERY_CLIENT = "?jay-client";
|
|
297
|
+
declare const JAY_QUERY_SERVER = "?jay-server";
|
|
298
|
+
/**
|
|
299
|
+
* Parsed module specifier with environment information separated
|
|
300
|
+
*/
|
|
301
|
+
interface ParsedJayModuleSpecifier {
|
|
302
|
+
/** The base path without any jay query parameters */
|
|
303
|
+
basePath: string;
|
|
304
|
+
/** The build environment (client/server) if present */
|
|
305
|
+
buildEnvironment?: JayBuildEnvironment;
|
|
306
|
+
/** The runtime mode (sandbox modes) if present */
|
|
307
|
+
runtimeMode?: RuntimeMode;
|
|
308
|
+
/** Any remaining query parameters (not jay-related) */
|
|
309
|
+
otherQueryParams: string;
|
|
310
|
+
/** The full query string for reconstruction */
|
|
311
|
+
fullQueryString: string;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Parse a module specifier to extract the base path and any jay environment information.
|
|
315
|
+
*
|
|
316
|
+
* @example
|
|
317
|
+
* parseJayModuleSpecifier('./component?jay-client')
|
|
318
|
+
* // { basePath: './component', buildEnvironment: 'client', ... }
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* parseJayModuleSpecifier('./file.jay-contract?jay-server')
|
|
322
|
+
* // { basePath: './file.jay-contract', buildEnvironment: 'server', ... }
|
|
323
|
+
*/
|
|
324
|
+
declare function parseJayModuleSpecifier(specifier: string): ParsedJayModuleSpecifier;
|
|
325
|
+
/**
|
|
326
|
+
* Add a build environment (client/server) to a module specifier.
|
|
327
|
+
* If the specifier already has an environment, it will be replaced.
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* addBuildEnvironment('./component', 'client')
|
|
331
|
+
* // './component?jay-client'
|
|
332
|
+
*
|
|
333
|
+
* @example
|
|
334
|
+
* addBuildEnvironment('./file?existing=param', 'server')
|
|
335
|
+
* // './file?jay-server&existing=param'
|
|
336
|
+
*/
|
|
337
|
+
declare function addBuildEnvironment(specifier: string, environment: JayBuildEnvironment): string;
|
|
338
|
+
/**
|
|
339
|
+
* Check if a module specifier has a specific extension, ignoring any query parameters.
|
|
340
|
+
* This is the query-param-aware version of the simple `string.endsWith()` check.
|
|
341
|
+
*
|
|
342
|
+
* Handles cases where .ts/.tsx may appear:
|
|
343
|
+
* - After the extension: `file.jay-html.ts`
|
|
344
|
+
* - After query params: `file.jay-html?jay-mainSandbox.ts`
|
|
345
|
+
* - Before query params: `file.jay-contract.ts?jay-client`
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* hasJayExtension('./file.jay-contract?jay-client', '.jay-contract')
|
|
349
|
+
* // true
|
|
350
|
+
*
|
|
351
|
+
* @example
|
|
352
|
+
* hasJayExtension('./file.jay-html?jay-mainSandbox.ts', '.jay-html', { withTs: true })
|
|
353
|
+
* // true
|
|
354
|
+
*/
|
|
355
|
+
declare function hasJayExtension(specifier: string, extension: string, { withTs }?: {
|
|
356
|
+
withTs?: boolean;
|
|
357
|
+
}): boolean;
|
|
358
|
+
/**
|
|
359
|
+
* Get the base path of a module specifier without any query parameters.
|
|
360
|
+
*
|
|
361
|
+
* @example
|
|
362
|
+
* getBasePath('./component?jay-client')
|
|
363
|
+
* // './component'
|
|
364
|
+
*/
|
|
365
|
+
declare function getBasePath(specifier: string): string;
|
|
366
|
+
/**
|
|
367
|
+
* Check if a module specifier has a build environment (client or server).
|
|
368
|
+
*/
|
|
369
|
+
declare function hasBuildEnvironment(specifier: string): boolean;
|
|
370
|
+
/**
|
|
371
|
+
* Get the build environment from a module specifier, if present.
|
|
372
|
+
*/
|
|
373
|
+
declare function getBuildEnvironment(specifier: string): JayBuildEnvironment | undefined;
|
|
374
|
+
/**
|
|
375
|
+
* Check if a module specifier is a local file (relative path).
|
|
376
|
+
*/
|
|
377
|
+
declare function isLocalModule(specifier: string): boolean;
|
|
378
|
+
|
|
270
379
|
type JayValidations = Array<string>;
|
|
271
380
|
declare class WithValidations<Value> {
|
|
272
381
|
val?: Value;
|
|
@@ -351,4 +460,92 @@ declare function prettify(code: string, options?: prettier.Options): Promise<str
|
|
|
351
460
|
declare function prettifyHtml(html: string): string;
|
|
352
461
|
declare function removeComments(code: string): string;
|
|
353
462
|
|
|
354
|
-
|
|
463
|
+
/**
|
|
464
|
+
* Plugin initialization configuration.
|
|
465
|
+
*
|
|
466
|
+
* For the `makeJayInit` pattern:
|
|
467
|
+
* - undefined: Auto-discover `lib/init.ts` (for uncompiled/local plugins)
|
|
468
|
+
* - string: Export name for the JayInit constant (for compiled/NPM packages)
|
|
469
|
+
*
|
|
470
|
+
* @example
|
|
471
|
+
* ```yaml
|
|
472
|
+
* # For compiled NPM packages - specify the export name
|
|
473
|
+
* name: my-plugin
|
|
474
|
+
* init: myPluginInit
|
|
475
|
+
* ```
|
|
476
|
+
*/
|
|
477
|
+
type PluginInitConfig = string;
|
|
478
|
+
/**
|
|
479
|
+
* Plugin manifest structure from plugin.yaml
|
|
480
|
+
*/
|
|
481
|
+
interface PluginManifest {
|
|
482
|
+
name: string;
|
|
483
|
+
version?: string;
|
|
484
|
+
module?: string;
|
|
485
|
+
contracts?: Array<{
|
|
486
|
+
name: string;
|
|
487
|
+
contract: string;
|
|
488
|
+
component: string;
|
|
489
|
+
description?: string;
|
|
490
|
+
}>;
|
|
491
|
+
dynamic_contracts?: {
|
|
492
|
+
generator: string;
|
|
493
|
+
component: string;
|
|
494
|
+
prefix: string;
|
|
495
|
+
};
|
|
496
|
+
/** Named exports from plugin backend bundle that are JayAction instances */
|
|
497
|
+
actions?: string[];
|
|
498
|
+
/** Plugin initialization configuration */
|
|
499
|
+
init?: PluginInitConfig;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Result of resolving a plugin component
|
|
503
|
+
*/
|
|
504
|
+
interface PluginComponentResolution {
|
|
505
|
+
/** Absolute path to the contract file */
|
|
506
|
+
contractPath: string;
|
|
507
|
+
/** Absolute path to the component file (without extension) - used for local plugins */
|
|
508
|
+
componentPath: string;
|
|
509
|
+
/** Component name to import */
|
|
510
|
+
componentName: string;
|
|
511
|
+
/** Whether this is an NPM package (vs local plugin) */
|
|
512
|
+
isNpmPackage: boolean;
|
|
513
|
+
/** For NPM packages: the package name to import from */
|
|
514
|
+
packageName?: string;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Loads and parses a plugin.yaml file
|
|
518
|
+
*
|
|
519
|
+
* @param pluginDir - Absolute path to plugin directory
|
|
520
|
+
* @returns Parsed plugin manifest or null if not found/invalid
|
|
521
|
+
*/
|
|
522
|
+
declare function loadPluginManifest(pluginDir: string): PluginManifest | null;
|
|
523
|
+
/**
|
|
524
|
+
* Resolves a plugin component from a local plugin directory (src/plugins/)
|
|
525
|
+
*
|
|
526
|
+
* @param projectRoot - Project root directory
|
|
527
|
+
* @param pluginName - Name of the plugin
|
|
528
|
+
* @param contractName - Name of the contract to resolve
|
|
529
|
+
* @returns Resolution result with validation messages
|
|
530
|
+
*/
|
|
531
|
+
declare function resolveLocalPlugin(projectRoot: string, pluginName: string, contractName: string): WithValidations<PluginComponentResolution> | null;
|
|
532
|
+
/**
|
|
533
|
+
* Resolves a plugin component from an NPM package (node_modules/)
|
|
534
|
+
*
|
|
535
|
+
* @param projectRoot - Project root directory
|
|
536
|
+
* @param pluginName - Name of the NPM package
|
|
537
|
+
* @param contractName - Name of the contract to resolve
|
|
538
|
+
* @returns Resolution result with validation messages
|
|
539
|
+
*/
|
|
540
|
+
declare function resolveNpmPlugin(projectRoot: string, pluginName: string, contractName: string): WithValidations<PluginComponentResolution> | null;
|
|
541
|
+
/**
|
|
542
|
+
* Resolves a plugin component, trying local plugins first, then NPM packages
|
|
543
|
+
*
|
|
544
|
+
* @param projectRoot - Project root directory
|
|
545
|
+
* @param pluginName - Name of the plugin
|
|
546
|
+
* @param contractName - Name of the contract to resolve
|
|
547
|
+
* @returns Resolution result with validation messages
|
|
548
|
+
*/
|
|
549
|
+
declare function resolvePluginComponent(projectRoot: string, pluginName: string, contractName: string): WithValidations<PluginComponentResolution>;
|
|
550
|
+
|
|
551
|
+
export { CSS_EXTENSION, type CompilerSourceFile, GenerateTarget, type GenericTypescriptSourceFile, Import, type ImportName, type ImportedRefsTree, Imports, ImportsFor, JAY_4_REACT, JAY_COMPONENT, JAY_CONTRACT_DTS_EXTENSION, JAY_CONTRACT_EXTENSION, JAY_DTS_EXTENSION, JAY_EXTENSION, JAY_FULLSTACK_COMPONENTS, JAY_QUERY_CLIENT, JAY_QUERY_MAIN_SANDBOX, JAY_QUERY_MAIN_SANDBOX_TS, JAY_QUERY_PREFIX, JAY_QUERY_SERVER, JAY_QUERY_WORKER_SANDBOX, JAY_QUERY_WORKER_SANDBOX_TS, JAY_QUERY_WORKER_TRUSTED, JAY_QUERY_WORKER_TRUSTED_TS, JAY_RUNTIME, JAY_SECURE, JAY_TS_EXTENSION, JayArrayType, JayAtomicType, JayBoolean, JayBuildEnvironment, JayComponentApiMember, JayComponentType, JayDate, JayElementConstructorType, JayElementType, JayEnumType, type JayEnvironment, JayErrorType, JayHTMLType, type JayImportLink, type JayImportName, JayImportedType, JayNumber, JayObjectType, JayPromiseType, JayRecursiveType, JayString, type JayType, JayTypeAlias, JayTypeKind, JayUnionType, JayUnknown, type JayValidations, MAKE_JAY_4_REACT_COMPONENT, MAKE_JAY_COMPONENT, MAKE_JAY_TSX_COMPONENT, type MainRuntimeModes, type ParsedJayModuleSpecifier, type PluginComponentResolution, type PluginInitConfig, type PluginManifest, REACT, type RecursiveRegion, type Ref, type RefsTree, RenderFragment, RuntimeMode, SourceFileFormat, TSX_EXTENSION, TS_EXTENSION, WithValidations, addBuildEnvironment, checkValidationErrors, equalJayTypes, getBasePath, getBuildEnvironment, getJayTsFileSourcePath, getMode, getModeFileExtension, getModeFromExtension, hasBuildEnvironment, hasExtension, hasJayExtension, hasJayModeExtension, hasRefs, isArrayType, isAtomicType, isComponentType, isCurrencyType, isDateWithTimezoneType, isElementConstructorType, isElementType, isEnumType, isHTMLType, isImportedType, isLocalModule, isObjectType, isPromiseType, isRecursiveType, isTypeAliasType, isUnionType, loadPluginManifest, mergeRefsTrees, mkRef, mkRefsTree, nestRefs, parseJayModuleSpecifier, prettify, prettifyHtml, removeComments, resolveLocalPlugin, resolveNpmPlugin, resolvePluginComponent, resolvePrimitiveType, withOriginalTrace, withoutExtension };
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,9 @@ var __publicField = (obj, key, value) => {
|
|
|
6
6
|
};
|
|
7
7
|
import * as prettier from "prettier";
|
|
8
8
|
import jsBeautify from "js-beautify";
|
|
9
|
+
import fs from "fs";
|
|
10
|
+
import path from "path";
|
|
11
|
+
import YAML from "yaml";
|
|
9
12
|
import { createRequire } from "module";
|
|
10
13
|
const JAY_EXTENSION = ".jay-html";
|
|
11
14
|
const CSS_EXTENSION = ".css";
|
|
@@ -152,6 +155,12 @@ const Import = {
|
|
|
152
155
|
1
|
|
153
156
|
/* implementation */
|
|
154
157
|
),
|
|
158
|
+
slowForEachItem: importStatementFragment(
|
|
159
|
+
JAY_RUNTIME,
|
|
160
|
+
"slowForEachItem",
|
|
161
|
+
1
|
|
162
|
+
/* implementation */
|
|
163
|
+
),
|
|
155
164
|
resolved: importStatementFragment(
|
|
156
165
|
JAY_RUNTIME,
|
|
157
166
|
"resolved",
|
|
@@ -750,6 +759,133 @@ function withoutExtension(filename, extension) {
|
|
|
750
759
|
}
|
|
751
760
|
return filename.slice(0, -extension.length);
|
|
752
761
|
}
|
|
762
|
+
var JayBuildEnvironment = /* @__PURE__ */ ((JayBuildEnvironment2) => {
|
|
763
|
+
JayBuildEnvironment2["Client"] = "client";
|
|
764
|
+
JayBuildEnvironment2["Server"] = "server";
|
|
765
|
+
return JayBuildEnvironment2;
|
|
766
|
+
})(JayBuildEnvironment || {});
|
|
767
|
+
const JAY_QUERY_CLIENT = `${JAY_QUERY_PREFIX}${"client"}`;
|
|
768
|
+
const JAY_QUERY_SERVER = `${JAY_QUERY_PREFIX}${"server"}`;
|
|
769
|
+
const JAY_QUERY_PATTERNS = [
|
|
770
|
+
// Build environments
|
|
771
|
+
{
|
|
772
|
+
pattern: `${JAY_QUERY_PREFIX}${"client"}`,
|
|
773
|
+
buildEnv: "client"
|
|
774
|
+
/* Client */
|
|
775
|
+
},
|
|
776
|
+
{
|
|
777
|
+
pattern: `${JAY_QUERY_PREFIX}${"server"}`,
|
|
778
|
+
buildEnv: "server"
|
|
779
|
+
/* Server */
|
|
780
|
+
},
|
|
781
|
+
// Runtime modes (with .ts suffix)
|
|
782
|
+
{
|
|
783
|
+
pattern: `${JAY_QUERY_PREFIX}${RuntimeMode.MainSandbox}${TS_EXTENSION}`,
|
|
784
|
+
runtimeMode: RuntimeMode.MainSandbox
|
|
785
|
+
},
|
|
786
|
+
{
|
|
787
|
+
pattern: `${JAY_QUERY_PREFIX}${RuntimeMode.WorkerTrusted}${TS_EXTENSION}`,
|
|
788
|
+
runtimeMode: RuntimeMode.WorkerTrusted
|
|
789
|
+
},
|
|
790
|
+
{
|
|
791
|
+
pattern: `${JAY_QUERY_PREFIX}${RuntimeMode.WorkerSandbox}${TS_EXTENSION}`,
|
|
792
|
+
runtimeMode: RuntimeMode.WorkerSandbox
|
|
793
|
+
},
|
|
794
|
+
// Runtime modes (without .ts suffix)
|
|
795
|
+
{
|
|
796
|
+
pattern: `${JAY_QUERY_PREFIX}${RuntimeMode.MainSandbox}`,
|
|
797
|
+
runtimeMode: RuntimeMode.MainSandbox
|
|
798
|
+
},
|
|
799
|
+
{
|
|
800
|
+
pattern: `${JAY_QUERY_PREFIX}${RuntimeMode.WorkerTrusted}`,
|
|
801
|
+
runtimeMode: RuntimeMode.WorkerTrusted
|
|
802
|
+
},
|
|
803
|
+
{
|
|
804
|
+
pattern: `${JAY_QUERY_PREFIX}${RuntimeMode.WorkerSandbox}`,
|
|
805
|
+
runtimeMode: RuntimeMode.WorkerSandbox
|
|
806
|
+
}
|
|
807
|
+
];
|
|
808
|
+
function parseJayModuleSpecifier(specifier) {
|
|
809
|
+
const queryIndex = specifier.indexOf("?");
|
|
810
|
+
if (queryIndex === -1) {
|
|
811
|
+
return {
|
|
812
|
+
basePath: specifier,
|
|
813
|
+
otherQueryParams: "",
|
|
814
|
+
fullQueryString: ""
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
const basePath = specifier.substring(0, queryIndex);
|
|
818
|
+
const fullQueryString = specifier.substring(queryIndex);
|
|
819
|
+
let buildEnvironment;
|
|
820
|
+
let runtimeMode;
|
|
821
|
+
let remainingQuery = fullQueryString;
|
|
822
|
+
for (const { pattern, buildEnv, runtimeMode: rtMode } of JAY_QUERY_PATTERNS) {
|
|
823
|
+
if (remainingQuery.includes(pattern)) {
|
|
824
|
+
if (buildEnv)
|
|
825
|
+
buildEnvironment = buildEnv;
|
|
826
|
+
if (rtMode)
|
|
827
|
+
runtimeMode = rtMode;
|
|
828
|
+
remainingQuery = remainingQuery.replace(pattern, "");
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
const otherQueryParams = remainingQuery.replace(/^\?&/, "?").replace(/&&/g, "&").replace(/&$/, "").replace(/^\?$/, "");
|
|
832
|
+
return {
|
|
833
|
+
basePath,
|
|
834
|
+
buildEnvironment,
|
|
835
|
+
runtimeMode,
|
|
836
|
+
otherQueryParams,
|
|
837
|
+
fullQueryString
|
|
838
|
+
};
|
|
839
|
+
}
|
|
840
|
+
function addBuildEnvironment(specifier, environment) {
|
|
841
|
+
const parsed = parseJayModuleSpecifier(specifier);
|
|
842
|
+
const jayQuery = `${JAY_QUERY_PREFIX}${environment}`;
|
|
843
|
+
let result = parsed.basePath + jayQuery;
|
|
844
|
+
if (parsed.runtimeMode) {
|
|
845
|
+
result += `${JAY_QUERY_PREFIX}${parsed.runtimeMode}`;
|
|
846
|
+
}
|
|
847
|
+
if (parsed.otherQueryParams) {
|
|
848
|
+
if (parsed.otherQueryParams.startsWith("?")) {
|
|
849
|
+
result += "&" + parsed.otherQueryParams.substring(1);
|
|
850
|
+
} else if (parsed.otherQueryParams) {
|
|
851
|
+
result += "&" + parsed.otherQueryParams;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
return result;
|
|
855
|
+
}
|
|
856
|
+
function hasJayExtension(specifier, extension, { withTs = false } = {}) {
|
|
857
|
+
let normalizedSpecifier = specifier;
|
|
858
|
+
if (withTs) {
|
|
859
|
+
if (specifier.endsWith(TS_EXTENSION)) {
|
|
860
|
+
normalizedSpecifier = specifier.slice(0, -TS_EXTENSION.length);
|
|
861
|
+
} else if (specifier.endsWith(TSX_EXTENSION)) {
|
|
862
|
+
normalizedSpecifier = specifier.slice(0, -TSX_EXTENSION.length);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
let { basePath } = parseJayModuleSpecifier(normalizedSpecifier);
|
|
866
|
+
if (withTs) {
|
|
867
|
+
if (basePath.endsWith(TS_EXTENSION)) {
|
|
868
|
+
basePath = basePath.slice(0, -TS_EXTENSION.length);
|
|
869
|
+
} else if (basePath.endsWith(TSX_EXTENSION)) {
|
|
870
|
+
basePath = basePath.slice(0, -TSX_EXTENSION.length);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
return basePath.endsWith(extension) && basePath.length > extension.length;
|
|
874
|
+
}
|
|
875
|
+
function getBasePath(specifier) {
|
|
876
|
+
return parseJayModuleSpecifier(specifier).basePath;
|
|
877
|
+
}
|
|
878
|
+
function hasBuildEnvironment(specifier) {
|
|
879
|
+
const { buildEnvironment } = parseJayModuleSpecifier(specifier);
|
|
880
|
+
return buildEnvironment !== void 0;
|
|
881
|
+
}
|
|
882
|
+
function getBuildEnvironment(specifier) {
|
|
883
|
+
return parseJayModuleSpecifier(specifier).buildEnvironment;
|
|
884
|
+
}
|
|
885
|
+
function isLocalModule(specifier) {
|
|
886
|
+
const { basePath } = parseJayModuleSpecifier(specifier);
|
|
887
|
+
return basePath.startsWith("./") || basePath.startsWith("../");
|
|
888
|
+
}
|
|
753
889
|
class WithValidations {
|
|
754
890
|
constructor(val, validations = []) {
|
|
755
891
|
__publicField(this, "val");
|
|
@@ -826,12 +962,12 @@ function hasRefs(refs, includingAutoRefs) {
|
|
|
826
962
|
const allRefs = (ref) => true;
|
|
827
963
|
return refs.refs.filter(includingAutoRefs ? allRefs : onlyNonAutoRefs).length > 0 || refs.imported || Object.entries(refs.children).map(([ref, refs2]) => hasRefs(refs2, includingAutoRefs)).reduce((prev, curr) => prev || curr, false);
|
|
828
964
|
}
|
|
829
|
-
function nestRefs(
|
|
965
|
+
function nestRefs(path2, renderFragment) {
|
|
830
966
|
let refs = renderFragment.refs;
|
|
831
|
-
for (let index =
|
|
832
|
-
if (
|
|
967
|
+
for (let index = path2.length - 1; index >= 0; --index) {
|
|
968
|
+
if (path2[index] === ".")
|
|
833
969
|
continue;
|
|
834
|
-
refs = mkRefsTree([], { [
|
|
970
|
+
refs = mkRefsTree([], { [path2[index]]: refs }, refs.repeated);
|
|
835
971
|
}
|
|
836
972
|
return new RenderFragment(
|
|
837
973
|
renderFragment.rendered,
|
|
@@ -953,6 +1089,157 @@ function removeComments(code) {
|
|
|
953
1089
|
(line) => !(line.includes("// @ts-expect-error ") || line.includes("// @ts-ignore") || line.includes("{/* @ts-ignore */}"))
|
|
954
1090
|
).join("\n");
|
|
955
1091
|
}
|
|
1092
|
+
const require2 = createRequire(import.meta.url);
|
|
1093
|
+
function loadPluginManifest(pluginDir) {
|
|
1094
|
+
const pluginYamlPath = path.join(pluginDir, "plugin.yaml");
|
|
1095
|
+
if (!fs.existsSync(pluginYamlPath)) {
|
|
1096
|
+
return null;
|
|
1097
|
+
}
|
|
1098
|
+
try {
|
|
1099
|
+
const yamlContent = fs.readFileSync(pluginYamlPath, "utf-8");
|
|
1100
|
+
return YAML.parse(yamlContent);
|
|
1101
|
+
} catch (error) {
|
|
1102
|
+
return null;
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
function resolveLocalPlugin(projectRoot, pluginName, contractName) {
|
|
1106
|
+
const localPluginPath = path.join(projectRoot, "src/plugins", pluginName);
|
|
1107
|
+
const pluginYamlPath = path.join(localPluginPath, "plugin.yaml");
|
|
1108
|
+
if (!fs.existsSync(localPluginPath)) {
|
|
1109
|
+
return null;
|
|
1110
|
+
}
|
|
1111
|
+
if (!fs.existsSync(pluginYamlPath)) {
|
|
1112
|
+
return new WithValidations(null, [
|
|
1113
|
+
`Local plugin "${pluginName}" found at ${localPluginPath} but plugin.yaml is missing`
|
|
1114
|
+
]);
|
|
1115
|
+
}
|
|
1116
|
+
const manifest = loadPluginManifest(localPluginPath);
|
|
1117
|
+
if (!manifest) {
|
|
1118
|
+
return new WithValidations(null, [
|
|
1119
|
+
`Failed to parse plugin.yaml for local plugin "${pluginName}" at ${pluginYamlPath}`
|
|
1120
|
+
]);
|
|
1121
|
+
}
|
|
1122
|
+
if (!manifest.contracts || manifest.contracts.length === 0) {
|
|
1123
|
+
return new WithValidations(null, [
|
|
1124
|
+
`Local plugin "${pluginName}" has no contracts defined in plugin.yaml`
|
|
1125
|
+
]);
|
|
1126
|
+
}
|
|
1127
|
+
const contract = manifest.contracts.find((c2) => c2.name === contractName);
|
|
1128
|
+
if (!contract) {
|
|
1129
|
+
const availableContracts = manifest.contracts.map((c2) => c2.name).join(", ");
|
|
1130
|
+
return new WithValidations(null, [
|
|
1131
|
+
`Contract "${contractName}" not found in local plugin "${pluginName}". Available contracts: ${availableContracts}`
|
|
1132
|
+
]);
|
|
1133
|
+
}
|
|
1134
|
+
const componentModule = manifest.module || "index.js";
|
|
1135
|
+
const componentPath = path.join(localPluginPath, componentModule);
|
|
1136
|
+
return new WithValidations(
|
|
1137
|
+
{
|
|
1138
|
+
contractPath: path.join(localPluginPath, contract.contract),
|
|
1139
|
+
componentPath,
|
|
1140
|
+
componentName: contract.component,
|
|
1141
|
+
// This is the exported member name
|
|
1142
|
+
isNpmPackage: false
|
|
1143
|
+
},
|
|
1144
|
+
[]
|
|
1145
|
+
);
|
|
1146
|
+
}
|
|
1147
|
+
function resolveNpmPlugin(projectRoot, pluginName, contractName) {
|
|
1148
|
+
let pluginYamlPath;
|
|
1149
|
+
try {
|
|
1150
|
+
pluginYamlPath = require2.resolve(`${pluginName}/plugin.yaml`, {
|
|
1151
|
+
paths: [projectRoot]
|
|
1152
|
+
});
|
|
1153
|
+
} catch (error) {
|
|
1154
|
+
return new WithValidations(null, [
|
|
1155
|
+
`NPM package "${pluginName}" not found or plugin.yaml is not exported. Is this a Jay Stack plugin?`
|
|
1156
|
+
]);
|
|
1157
|
+
}
|
|
1158
|
+
const npmPluginPath = path.dirname(pluginYamlPath);
|
|
1159
|
+
if (!fs.existsSync(pluginYamlPath)) {
|
|
1160
|
+
return new WithValidations(null, [
|
|
1161
|
+
`NPM package "${pluginName}" found but plugin.yaml is missing. Is this a Jay Stack plugin?`
|
|
1162
|
+
]);
|
|
1163
|
+
}
|
|
1164
|
+
const manifest = loadPluginManifest(npmPluginPath);
|
|
1165
|
+
if (!manifest) {
|
|
1166
|
+
return new WithValidations(null, [
|
|
1167
|
+
`Failed to parse plugin.yaml for NPM package "${pluginName}" at ${pluginYamlPath}`
|
|
1168
|
+
]);
|
|
1169
|
+
}
|
|
1170
|
+
if (!manifest.contracts || manifest.contracts.length === 0) {
|
|
1171
|
+
return new WithValidations(null, [
|
|
1172
|
+
`NPM package "${pluginName}" has no contracts defined in plugin.yaml`
|
|
1173
|
+
]);
|
|
1174
|
+
}
|
|
1175
|
+
const contract = manifest.contracts.find((c2) => c2.name === contractName);
|
|
1176
|
+
if (!contract) {
|
|
1177
|
+
const availableContracts = manifest.contracts.map((c2) => c2.name).join(", ");
|
|
1178
|
+
return new WithValidations(null, [
|
|
1179
|
+
`Contract "${contractName}" not found in NPM package "${pluginName}". Available contracts: ${availableContracts}`
|
|
1180
|
+
]);
|
|
1181
|
+
}
|
|
1182
|
+
const packageJsonPath = path.join(npmPluginPath, "package.json");
|
|
1183
|
+
let componentPath;
|
|
1184
|
+
let contractPath;
|
|
1185
|
+
if (fs.existsSync(packageJsonPath)) {
|
|
1186
|
+
try {
|
|
1187
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
1188
|
+
const packageName = packageJson.name;
|
|
1189
|
+
const moduleName = manifest.module || packageName;
|
|
1190
|
+
if ((moduleName === packageName || !manifest.module) && packageJson.exports && packageJson.exports["."]) {
|
|
1191
|
+
const mainExport = packageJson.exports["."];
|
|
1192
|
+
const mainPath = typeof mainExport === "string" ? mainExport : mainExport.default || mainExport.import;
|
|
1193
|
+
componentPath = path.join(npmPluginPath, mainPath);
|
|
1194
|
+
} else {
|
|
1195
|
+
componentPath = path.join(npmPluginPath, "dist/index.js");
|
|
1196
|
+
}
|
|
1197
|
+
const contractSpec = contract.contract;
|
|
1198
|
+
const contractExportKey = "./" + contractSpec;
|
|
1199
|
+
if (packageJson.exports && packageJson.exports[contractExportKey]) {
|
|
1200
|
+
const exportPath = packageJson.exports[contractExportKey];
|
|
1201
|
+
contractPath = path.join(npmPluginPath, exportPath);
|
|
1202
|
+
} else {
|
|
1203
|
+
const possiblePaths = [
|
|
1204
|
+
path.join(npmPluginPath, "dist", contractSpec),
|
|
1205
|
+
path.join(npmPluginPath, "lib", contractSpec),
|
|
1206
|
+
path.join(npmPluginPath, contractSpec)
|
|
1207
|
+
];
|
|
1208
|
+
contractPath = possiblePaths.find((p) => fs.existsSync(p)) || possiblePaths[0];
|
|
1209
|
+
}
|
|
1210
|
+
} catch (error) {
|
|
1211
|
+
componentPath = path.join(npmPluginPath, "dist/index.js");
|
|
1212
|
+
contractPath = path.join(npmPluginPath, "dist", contract.contract);
|
|
1213
|
+
}
|
|
1214
|
+
} else {
|
|
1215
|
+
componentPath = path.join(npmPluginPath, "dist/index.js");
|
|
1216
|
+
contractPath = path.join(npmPluginPath, "dist", contract.contract);
|
|
1217
|
+
}
|
|
1218
|
+
return new WithValidations(
|
|
1219
|
+
{
|
|
1220
|
+
contractPath,
|
|
1221
|
+
componentPath,
|
|
1222
|
+
componentName: contract.component,
|
|
1223
|
+
// This is the exported member name
|
|
1224
|
+
isNpmPackage: true,
|
|
1225
|
+
packageName: pluginName
|
|
1226
|
+
},
|
|
1227
|
+
[]
|
|
1228
|
+
);
|
|
1229
|
+
}
|
|
1230
|
+
function resolvePluginComponent(projectRoot, pluginName, contractName) {
|
|
1231
|
+
const localResult = resolveLocalPlugin(projectRoot, pluginName, contractName);
|
|
1232
|
+
if (localResult !== null) {
|
|
1233
|
+
return localResult;
|
|
1234
|
+
}
|
|
1235
|
+
const npmResult = resolveNpmPlugin(projectRoot, pluginName, contractName);
|
|
1236
|
+
if (npmResult !== null) {
|
|
1237
|
+
return npmResult;
|
|
1238
|
+
}
|
|
1239
|
+
return new WithValidations(null, [
|
|
1240
|
+
`Plugin "${pluginName}" not found. Searched in src/plugins/${pluginName}/ and node_modules/${pluginName}/. Ensure the plugin is installed or exists in your project.`
|
|
1241
|
+
]);
|
|
1242
|
+
}
|
|
956
1243
|
const s = createRequire(import.meta.url), e = s("typescript"), u = e, c = new Proxy(e, {
|
|
957
1244
|
get(t, r) {
|
|
958
1245
|
return t[r];
|
|
@@ -974,9 +1261,11 @@ export {
|
|
|
974
1261
|
JAY_DTS_EXTENSION,
|
|
975
1262
|
JAY_EXTENSION,
|
|
976
1263
|
JAY_FULLSTACK_COMPONENTS,
|
|
1264
|
+
JAY_QUERY_CLIENT,
|
|
977
1265
|
JAY_QUERY_MAIN_SANDBOX,
|
|
978
1266
|
JAY_QUERY_MAIN_SANDBOX_TS,
|
|
979
1267
|
JAY_QUERY_PREFIX,
|
|
1268
|
+
JAY_QUERY_SERVER,
|
|
980
1269
|
JAY_QUERY_WORKER_SANDBOX,
|
|
981
1270
|
JAY_QUERY_WORKER_SANDBOX_TS,
|
|
982
1271
|
JAY_QUERY_WORKER_TRUSTED,
|
|
@@ -987,6 +1276,7 @@ export {
|
|
|
987
1276
|
JayArrayType,
|
|
988
1277
|
JayAtomicType,
|
|
989
1278
|
JayBoolean,
|
|
1279
|
+
JayBuildEnvironment,
|
|
990
1280
|
JayComponentApiMember,
|
|
991
1281
|
JayComponentType,
|
|
992
1282
|
JayDate,
|
|
@@ -1015,14 +1305,19 @@ export {
|
|
|
1015
1305
|
TSX_EXTENSION,
|
|
1016
1306
|
TS_EXTENSION,
|
|
1017
1307
|
WithValidations,
|
|
1308
|
+
addBuildEnvironment,
|
|
1018
1309
|
checkValidationErrors,
|
|
1019
1310
|
equalJayTypes,
|
|
1311
|
+
getBasePath,
|
|
1312
|
+
getBuildEnvironment,
|
|
1020
1313
|
getJayTsFileSourcePath,
|
|
1021
1314
|
getMode,
|
|
1022
1315
|
getModeFileExtension,
|
|
1023
1316
|
getModeFromExtension,
|
|
1024
1317
|
i as getTs,
|
|
1318
|
+
hasBuildEnvironment,
|
|
1025
1319
|
hasExtension,
|
|
1320
|
+
hasJayExtension,
|
|
1026
1321
|
hasJayModeExtension,
|
|
1027
1322
|
hasRefs,
|
|
1028
1323
|
isArrayType,
|
|
@@ -1035,18 +1330,24 @@ export {
|
|
|
1035
1330
|
isEnumType,
|
|
1036
1331
|
isHTMLType,
|
|
1037
1332
|
isImportedType,
|
|
1333
|
+
isLocalModule,
|
|
1038
1334
|
isObjectType,
|
|
1039
1335
|
isPromiseType,
|
|
1040
1336
|
isRecursiveType,
|
|
1041
1337
|
isTypeAliasType,
|
|
1042
1338
|
isUnionType,
|
|
1339
|
+
loadPluginManifest,
|
|
1043
1340
|
mergeRefsTrees,
|
|
1044
1341
|
mkRef,
|
|
1045
1342
|
mkRefsTree,
|
|
1046
1343
|
nestRefs,
|
|
1344
|
+
parseJayModuleSpecifier,
|
|
1047
1345
|
prettify,
|
|
1048
1346
|
prettifyHtml,
|
|
1049
1347
|
removeComments,
|
|
1348
|
+
resolveLocalPlugin,
|
|
1349
|
+
resolveNpmPlugin,
|
|
1350
|
+
resolvePluginComponent,
|
|
1050
1351
|
resolvePrimitiveType,
|
|
1051
1352
|
u as ts,
|
|
1052
1353
|
c as tsBridge,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jay-framework/compiler-shared",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
},
|
|
26
26
|
"author": "",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@jay-framework/component": "^0.
|
|
29
|
-
"@jay-framework/runtime": "^0.
|
|
30
|
-
"@jay-framework/secure": "^0.
|
|
31
|
-
"@jay-framework/typescript-bridge": "^0.
|
|
28
|
+
"@jay-framework/component": "^0.11.0",
|
|
29
|
+
"@jay-framework/runtime": "^0.11.0",
|
|
30
|
+
"@jay-framework/secure": "^0.11.0",
|
|
31
|
+
"@jay-framework/typescript-bridge": "^0.6.0",
|
|
32
32
|
"@types/js-yaml": "^4.0.9",
|
|
33
33
|
"change-case": "^4.1.2",
|
|
34
34
|
"js-beautify": "^1.14.11",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@caiogondim/strip-margin": "^1.0.0",
|
|
44
|
-
"@jay-framework/dev-environment": "^0.
|
|
44
|
+
"@jay-framework/dev-environment": "^0.11.0",
|
|
45
45
|
"@testing-library/jest-dom": "^6.2.0",
|
|
46
46
|
"@types/js-beautify": "^1",
|
|
47
47
|
"@types/node": "^20.11.5",
|