@jay-framework/rollup-plugin 0.15.5 → 0.16.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 CHANGED
@@ -25,6 +25,10 @@ interface JayRollupConfig {
25
25
  isWorker?: boolean;
26
26
  compilerPatternFiles?: string[];
27
27
  generationTarget?: GenerateTarget;
28
+ /** Pages source root directory (for mapping pre-rendered paths back to source) */
29
+ pagesRoot?: string;
30
+ /** Build output directory (for detecting pre-rendered files) */
31
+ buildFolder?: string;
28
32
  }
29
33
 
30
34
  declare class JayPluginContext {
@@ -35,10 +39,18 @@ declare class JayPluginContext {
35
39
  readonly compilerPatterns: CompiledPattern[];
36
40
  readonly jayFileCache: Map<string, CompilerSourceFile>;
37
41
  readonly globalFunctionsRepository: FunctionRepositoryBuilder;
42
+ private readonly preRenderedPrefix;
43
+ private readonly pagesRoot;
38
44
  constructor(jayOptions?: JayRollupConfig);
39
45
  cacheJayFile(id: string, jayFile: CompilerSourceFile): CompilerSourceFile;
40
46
  getCachedJayFile(id: string): CompilerSourceFile;
41
47
  deleteCachedJayFile(id: string): boolean;
48
+ /**
49
+ * Map a file path to its source directory. For pre-rendered files
50
+ * (under build/pre-rendered/), maps back to the original source pages directory.
51
+ * For source files, returns path.dirname(filePath) unchanged.
52
+ */
53
+ resolveSourceDir(filePath: string): string;
42
54
  }
43
55
 
44
56
  declare function jayRuntime(jayOptions?: JayRollupConfig, givenJayContext?: JayPluginContext): {
package/dist/index.js CHANGED
@@ -217,6 +217,7 @@ async function getJayFile(jayContext, meta, code) {
217
217
  }
218
218
  async function getJayStructureFromJayHtmlSource(jayContext, code, id) {
219
219
  const { filename, dirname } = getFileContext(id);
220
+ const sourceDir = jayContext.resolveSourceDir(id);
220
221
  return await parseJayFile(
221
222
  code,
222
223
  filename,
@@ -225,7 +226,8 @@ async function getJayStructureFromJayHtmlSource(jayContext, code, id) {
225
226
  relativePath: jayContext.jayOptions.tsConfigFilePath
226
227
  },
227
228
  JAY_IMPORT_RESOLVER,
228
- jayContext.projectRoot
229
+ jayContext.projectRoot,
230
+ sourceDir !== dirname ? sourceDir : void 0
229
231
  );
230
232
  }
231
233
  async function getJayStructureFromTypeScriptSource(code, id) {
@@ -375,6 +377,7 @@ async function loadCssFile(context, jayContext, id, isVite) {
375
377
  const code = checkCodeErrors(await readFileAsString(originId));
376
378
  const fileName = path.basename(originId);
377
379
  const dirName = path.dirname(originId);
380
+ const sourceDir = jayContext.resolveSourceDir(originId);
378
381
  const jayHtml = await parseJayFile(
379
382
  code,
380
383
  fileName,
@@ -383,7 +386,8 @@ async function loadCssFile(context, jayContext, id, isVite) {
383
386
  relativePath: jayContext.jayOptions.tsConfigFilePath
384
387
  },
385
388
  JAY_IMPORT_RESOLVER,
386
- jayContext.projectRoot
389
+ jayContext.projectRoot,
390
+ sourceDir !== dirName ? sourceDir : void 0
387
391
  );
388
392
  if (jayHtml.val?.linkedCssFiles) {
389
393
  for (const cssFile of jayHtml.val.linkedCssFiles) {
@@ -540,9 +544,15 @@ class JayPluginContext {
540
544
  __publicField(this, "compilerPatterns");
541
545
  __publicField(this, "jayFileCache", /* @__PURE__ */ new Map());
542
546
  __publicField(this, "globalFunctionsRepository");
547
+ __publicField(this, "preRenderedPrefix");
548
+ __publicField(this, "pagesRoot");
543
549
  this.jayOptions = jayOptions;
544
550
  this.projectRoot = path.dirname(jayOptions.tsConfigFilePath ?? process.cwd());
545
551
  this.outputDir = jayOptions.outputDir && path.join(this.projectRoot, jayOptions.outputDir);
552
+ if (jayOptions.buildFolder && jayOptions.pagesRoot) {
553
+ this.preRenderedPrefix = path.resolve(jayOptions.buildFolder, "pre-rendered");
554
+ this.pagesRoot = path.resolve(jayOptions.pagesRoot);
555
+ }
546
556
  this.tsPrinter = createPrinter({ newLine: NewLineKind.LineFeed });
547
557
  let compilerPatternsParseResult = compileFunctionSplitPatternsBlock(
548
558
  (jayOptions.compilerPatternFiles || []).map((fileName) => {
@@ -572,6 +582,19 @@ class JayPluginContext {
572
582
  deleteCachedJayFile(id) {
573
583
  return this.jayFileCache.delete(id);
574
584
  }
585
+ /**
586
+ * Map a file path to its source directory. For pre-rendered files
587
+ * (under build/pre-rendered/), maps back to the original source pages directory.
588
+ * For source files, returns path.dirname(filePath) unchanged.
589
+ */
590
+ resolveSourceDir(filePath) {
591
+ const dir = path.dirname(filePath);
592
+ if (this.preRenderedPrefix && this.pagesRoot && dir.startsWith(this.preRenderedPrefix)) {
593
+ const routeRelative = path.relative(this.preRenderedPrefix, dir);
594
+ return path.join(this.pagesRoot, routeRelative);
595
+ }
596
+ return dir;
597
+ }
575
598
  }
576
599
  const GLOBAL_FUNC_REPOSITORY = "GLOBAL_FUNC_REPOSITORY.ts";
577
600
  function jayRuntime(jayOptions = {}, givenJayContext) {
@@ -640,7 +663,7 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
640
663
  },
641
664
  watchChange(id, change) {
642
665
  getLogger().info(`[watchChange] ${id} ${change.event}`);
643
- jayContext.deleteCachedJayFile(id);
666
+ jayContext.jayFileCache.clear();
644
667
  if (server) {
645
668
  const variants = [id + TS_EXTENSION, id + JAY_QUERY_HYDRATE + TS_EXTENSION];
646
669
  let invalidated = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jay-framework/rollup-plugin",
3
- "version": "0.15.5",
3
+ "version": "0.16.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -27,17 +27,17 @@
27
27
  "test:watch": "vitest"
28
28
  },
29
29
  "dependencies": {
30
- "@jay-framework/compiler": "^0.15.5",
31
- "@jay-framework/compiler-jay-html": "^0.15.5",
32
- "@jay-framework/logger": "^0.15.5",
30
+ "@jay-framework/compiler": "^0.16.0",
31
+ "@jay-framework/compiler-jay-html": "^0.16.0",
32
+ "@jay-framework/logger": "^0.16.0",
33
33
  "fast-glob": "^3.3.2",
34
34
  "typescript": "^5.3.3"
35
35
  },
36
36
  "devDependencies": {
37
- "@jay-framework/component": "^0.15.5",
38
- "@jay-framework/dev-environment": "^0.15.5",
39
- "@jay-framework/runtime": "^0.15.5",
40
- "@jay-framework/secure": "^0.15.5",
37
+ "@jay-framework/component": "^0.16.0",
38
+ "@jay-framework/dev-environment": "^0.16.0",
39
+ "@jay-framework/runtime": "^0.16.0",
40
+ "@jay-framework/secure": "^0.16.0",
41
41
  "@types/node": "^20.11.5",
42
42
  "rimraf": "^5.0.5",
43
43
  "rollup": "^4.9.5",