@jay-framework/rollup-plugin 0.10.0 → 0.12.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.
Files changed (2) hide show
  1. package/dist/index.js +28 -22
  2. package/package.json +8 -7
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ import path from "node:path";
10
10
  import { getBasePath, JAY_EXTENSION, hasExtension, JAY_CONTRACT_EXTENSION, checkValidationErrors, JAY_DTS_EXTENSION, JAY_CONTRACT_DTS_EXTENSION, SourceFileFormat, getModeFromExtension, GenerateTarget, RuntimeMode, TS_EXTENSION, TSX_EXTENSION, parseJayModuleSpecifier, JAY_QUERY_WORKER_TRUSTED_TS, CSS_EXTENSION, JAY_QUERY_MAIN_SANDBOX, hasJayExtension, hasJayModeExtension, Import } from "@jay-framework/compiler-shared";
11
11
  import { readFile, mkdir } from "node:fs/promises";
12
12
  import { writeFile } from "fs/promises";
13
+ import { getLogger } from "@jay-framework/logger";
13
14
  import { getJayHtmlImports, parseJayFile, JAY_IMPORT_RESOLVER, parseContract, compileContract, generateSandboxRootFile, generateElementBridgeFile } from "@jay-framework/compiler-jay-html";
14
15
  import { createRequire } from "module";
15
16
  import fs from "fs";
@@ -35,7 +36,7 @@ async function writeGeneratedFile(jayContext, context, id, code) {
35
36
  const filePath = path.resolve(jayContext.outputDir, relativePath, path.basename(id));
36
37
  await mkdir(path.dirname(filePath), { recursive: true });
37
38
  await writeFile(filePath, code, { encoding: "utf8", flag: "w" });
38
- console.info(["[transform] written", filePath].join(" "));
39
+ getLogger().info(["[transform] written", filePath].join(" "));
39
40
  return filePath;
40
41
  }
41
42
  function checkCodeErrors(code) {
@@ -269,35 +270,35 @@ async function transformJayFile(jayContext, context, code, id) {
269
270
  if (!Boolean(getJayMetadata(context, id).originId))
270
271
  return null;
271
272
  const mode = getModeFromExtension(id);
272
- console.info(`[transform] start ${mode} ${id}`);
273
+ getLogger().info(`[transform] start ${mode} ${id}`);
273
274
  const { meta, jayFile } = await getJayFileStructure(jayContext, context, code, id);
274
275
  const tsCode = await generateCodeFromStructure(jayContext, context, code, id, meta, jayFile);
275
- console.info(`[transform] end ${mode} ${id}`);
276
+ getLogger().info(`[transform] end ${mode} ${id}`);
276
277
  return { code: tsCode };
277
278
  }
278
279
  function watchChangesFor(context, sourcePath) {
279
280
  if (context.getWatchFiles().includes(sourcePath))
280
281
  return;
281
282
  context.addWatchFile(sourcePath);
282
- console.info(`[watch] add ${sourcePath}`);
283
+ getLogger().info(`[watch] add ${sourcePath}`);
283
284
  }
284
285
  function stripTSExtension(id) {
285
286
  const basePath = getBasePath(id);
286
287
  return basePath.replace(TS_EXTENSION, "").replace(TSX_EXTENSION, "");
287
288
  }
288
289
  async function loadJayFile(context, id) {
289
- console.info(`[load] start ${id}`);
290
+ getLogger().info(`[load] start ${id}`);
290
291
  const metadata = getJayMetadata(context, id);
291
292
  let originId = metadata.originId;
292
293
  if (!Boolean(originId)) {
293
294
  originId = stripTSExtension(id);
294
295
  }
295
296
  const code = checkCodeErrors(await readFileAsString(originId));
296
- console.info(`[load] end ${id}, code length: ${code.length}`);
297
+ getLogger().info(`[load] end ${id}, code length: ${code.length}`);
297
298
  return { code };
298
299
  }
299
300
  async function loadContractFile(context, id) {
300
- console.info(`[load] start ${id}`);
301
+ getLogger().info(`[load] start ${id}`);
301
302
  let { originId } = getJayMetadata(context, id);
302
303
  if (!Boolean(originId))
303
304
  originId = stripTSExtension(id);
@@ -308,12 +309,12 @@ async function loadContractFile(context, id) {
308
309
  if (!tsCode.val) {
309
310
  throw new Error(`Failed to compile contract ${id}: ${JSON.stringify(tsCode.validations)}`);
310
311
  }
311
- console.info(`[load] end ${id}`);
312
+ getLogger().info(`[load] end ${id}`);
312
313
  return { code: tsCode.val };
313
314
  }
314
315
  async function loadCssFile(context, jayContext, id, isVite) {
315
316
  if (isVite) {
316
- console.info(`[load] start ${id}`);
317
+ getLogger().info(`[load] start ${id}`);
317
318
  const { originId } = getJayMetadata(context, id);
318
319
  const code = checkCodeErrors(await readFileAsString(originId));
319
320
  const fileName = path.basename(originId);
@@ -328,10 +329,15 @@ async function loadCssFile(context, jayContext, id, isVite) {
328
329
  JAY_IMPORT_RESOLVER,
329
330
  jayContext.projectRoot
330
331
  );
331
- console.info(`[load] end ${id}`);
332
- return { code: jayHtml.val.css };
332
+ if (jayHtml.val?.linkedCssFiles) {
333
+ for (const cssFile of jayHtml.val.linkedCssFiles) {
334
+ watchChangesFor(context, cssFile);
335
+ }
336
+ }
337
+ getLogger().info(`[load] end ${id}`);
338
+ return { code: jayHtml.val?.css };
333
339
  } else {
334
- console.info(`[load] rollup environment - css not supported - ignoring css ${id}`);
340
+ getLogger().info(`[load] rollup environment - css not supported - ignoring css ${id}`);
335
341
  return { code: "" };
336
342
  }
337
343
  }
@@ -341,7 +347,7 @@ async function resolveJayHtml(context, source, importer, options, root, generati
341
347
  const sourceBasePath = sourceParsed.basePath;
342
348
  if (source.endsWith(TS_EXTENSION) || source.endsWith(TSX_EXTENSION)) {
343
349
  const originId2 = sourceBasePath.replace(TS_EXTENSION, "").replace(TSX_EXTENSION, "");
344
- console.info(`[resolveId] already resolved ${source}, originId: ${originId2}`);
350
+ getLogger().info(`[resolveId] already resolved ${source}, originId: ${originId2}`);
345
351
  return {
346
352
  id: source,
347
353
  meta: appendJayMetadata(context, source, {
@@ -371,7 +377,7 @@ async function resolveJayHtml(context, source, importer, options, root, generati
371
377
  }
372
378
  const baseWithQuery = sourceParsed.fullQueryString ? `${originId}${sourceParsed.fullQueryString}` : originId;
373
379
  const id = context["ssr"] && originId.startsWith(root) ? `${baseWithQuery}${extension}`.slice(root.length) : `${baseWithQuery}${extension}`;
374
- console.info(`[resolveId] resolved ${id} as ${format}`);
380
+ getLogger().info(`[resolveId] resolved ${id} as ${format}`);
375
381
  return { id, meta: appendJayMetadata(context, id, { format, originId }) };
376
382
  }
377
383
  async function resolveJayContract(context, source, importer, options, root) {
@@ -379,7 +385,7 @@ async function resolveJayContract(context, source, importer, options, root) {
379
385
  const sourceBasePath = sourceParsed.basePath;
380
386
  if (source.endsWith(TS_EXTENSION) || source.endsWith(TSX_EXTENSION)) {
381
387
  const originId2 = sourceBasePath.replace(TS_EXTENSION, "").replace(TSX_EXTENSION, "");
382
- console.info(`[resolveId] already resolved contract ${source}, originId: ${originId2}`);
388
+ getLogger().info(`[resolveId] already resolved contract ${source}, originId: ${originId2}`);
383
389
  return {
384
390
  id: source,
385
391
  meta: appendJayMetadata(context, source, {
@@ -398,7 +404,7 @@ async function resolveJayContract(context, source, importer, options, root) {
398
404
  const originId = resolvedParsed.basePath;
399
405
  const baseWithQuery = sourceParsed.fullQueryString ? `${originId}${sourceParsed.fullQueryString}` : originId;
400
406
  const id = context["ssr"] && originId.startsWith(root) ? `${baseWithQuery}${TS_EXTENSION}`.slice(root.length) : `${baseWithQuery}${TS_EXTENSION}`;
401
- console.info(
407
+ getLogger().info(
402
408
  `[resolveId] contract - id: ${id}, originId: ${originId}, ssr: ${context["ssr"]}`
403
409
  );
404
410
  return {
@@ -424,7 +430,7 @@ async function resolveJayModeFile(context, source, importer, options) {
424
430
  const format = resolvedJayMeta.format || SourceFileFormat.TypeScript;
425
431
  const originId = resolvedJayMeta.originId || resolved.id;
426
432
  const id = getResolvedId(resolved, mode, originId);
427
- console.info(`[resolveId] resolved ${id} as ${format}`);
433
+ getLogger().info(`[resolveId] resolved ${id} as ${format}`);
428
434
  return { id, meta: appendJayMetadata(context, id, { format, originId }, resolvedJayMeta) };
429
435
  }
430
436
  async function removeSandboxPrefixForWorkerRoot(context, source, importer, options) {
@@ -437,7 +443,7 @@ async function removeSandboxPrefixForWorkerRoot(context, source, importer, optio
437
443
  return null;
438
444
  const id = `${resolved.id}${JAY_QUERY_WORKER_TRUSTED_TS}`;
439
445
  const originId = id.split("?")[0];
440
- console.info(`[resolveId] resolved sandbox root ${id}`);
446
+ getLogger().info(`[resolveId] resolved sandbox root ${id}`);
441
447
  return {
442
448
  id,
443
449
  meta: appendJayMetadata(context, id, {
@@ -496,14 +502,14 @@ class JayPluginContext {
496
502
  this.globalFunctionsRepository = new FunctionRepositoryBuilder();
497
503
  }
498
504
  cacheJayFile(id, jayFile) {
499
- console.info("[cache] set", id);
505
+ getLogger().info(`[cache] set ${id}`);
500
506
  this.jayFileCache.set(id, jayFile);
501
507
  return jayFile;
502
508
  }
503
509
  getCachedJayFile(id) {
504
510
  const jayFile = this.jayFileCache.get(id);
505
511
  if (Boolean(jayFile)) {
506
- console.info("[cache] hit", id);
512
+ getLogger().info(`[cache] hit ${id}`);
507
513
  }
508
514
  return jayFile;
509
515
  }
@@ -529,7 +535,7 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
529
535
  (plugin) => plugin.name === "vite:build-metadata" || plugin.name?.startsWith("vite:")
530
536
  )
531
537
  );
532
- console.log("[buildStart] Vite detected:", isVite);
538
+ getLogger().info("[buildStart] Vite detected: " + isVite);
533
539
  },
534
540
  configureServer(_server) {
535
541
  server = _server;
@@ -577,7 +583,7 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
577
583
  return null;
578
584
  },
579
585
  watchChange(id, change) {
580
- console.log(`[watchChange] ${id} ${change.event}`);
586
+ getLogger().info(`[watchChange] ${id} ${change.event}`);
581
587
  jayContext.deleteCachedJayFile(id);
582
588
  if (server) {
583
589
  const module = server.moduleGraph.getModuleById(id + TS_EXTENSION);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jay-framework/rollup-plugin",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -27,16 +27,17 @@
27
27
  "test:watch": "vitest"
28
28
  },
29
29
  "dependencies": {
30
- "@jay-framework/compiler": "^0.10.0",
31
- "@jay-framework/compiler-jay-html": "^0.10.0",
30
+ "@jay-framework/compiler": "^0.12.0",
31
+ "@jay-framework/compiler-jay-html": "^0.12.0",
32
+ "@jay-framework/logger": "^0.12.0",
32
33
  "fast-glob": "^3.3.2",
33
34
  "typescript": "^5.3.3"
34
35
  },
35
36
  "devDependencies": {
36
- "@jay-framework/component": "^0.10.0",
37
- "@jay-framework/dev-environment": "^0.10.0",
38
- "@jay-framework/runtime": "^0.10.0",
39
- "@jay-framework/secure": "^0.10.0",
37
+ "@jay-framework/component": "^0.12.0",
38
+ "@jay-framework/dev-environment": "^0.12.0",
39
+ "@jay-framework/runtime": "^0.12.0",
40
+ "@jay-framework/secure": "^0.12.0",
40
41
  "@types/node": "^20.11.5",
41
42
  "rimraf": "^5.0.5",
42
43
  "rollup": "^4.9.5",