@jay-framework/rollup-plugin 0.6.6 → 0.6.7

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
@@ -44,6 +44,7 @@ declare class JayPluginContext {
44
44
 
45
45
  declare function jayRuntime(jayOptions?: JayRollupConfig, givenJayContext?: JayPluginContext): {
46
46
  name: string;
47
+ buildStart(opts: any): void;
47
48
  configureServer(_server: ViteDevServer): void;
48
49
  resolveId(source: string, importer: string | undefined, options: ResolveIdOptions): Promise<ResolveIdResult>;
49
50
  load(id: string): Promise<LoadResult>;
package/dist/index.js CHANGED
@@ -277,6 +277,51 @@ function watchChangesFor(context, sourcePath) {
277
277
  context.addWatchFile(sourcePath);
278
278
  console.info(`[watch] add ${sourcePath}`);
279
279
  }
280
+ function stripTSExtension(id) {
281
+ return id.replace(compilerShared.TS_EXTENSION, "").replace(compilerShared.TSX_EXTENSION, "");
282
+ }
283
+ async function loadJayFile(context, id) {
284
+ console.info(`[load] start ${id}`);
285
+ let { originId } = getJayMetadata(context, id);
286
+ if (!Boolean(originId))
287
+ originId = stripTSExtension(id);
288
+ const code = checkCodeErrors(await readFileAsString(originId));
289
+ console.info(`[load] end ${id}`);
290
+ return { code };
291
+ }
292
+ async function loadContractFile(context, id) {
293
+ console.info(`[load] start ${id}`);
294
+ let { originId } = getJayMetadata(context, id);
295
+ if (!Boolean(originId))
296
+ originId = stripTSExtension(id);
297
+ const code = await readFileAsString(originId);
298
+ console.info(`[load] end ${id}`);
299
+ return { code };
300
+ }
301
+ async function loadCssFile(context, jayContext, id, isVite) {
302
+ if (isVite) {
303
+ console.info(`[load] start ${id}`);
304
+ const { originId } = getJayMetadata(context, id);
305
+ const code = checkCodeErrors(await readFileAsString(originId));
306
+ const fileName = path.basename(originId);
307
+ const dirName = path.dirname(originId);
308
+ const jayHtml = await compilerJayHtml.parseJayFile(
309
+ code,
310
+ fileName,
311
+ dirName,
312
+ {
313
+ relativePath: jayContext.jayOptions.tsConfigFilePath
314
+ },
315
+ compilerJayHtml.JAY_IMPORT_RESOLVER
316
+ );
317
+ console.info(`[load] end ${id}`);
318
+ return { code: jayHtml.val.css };
319
+ } else {
320
+ console.info(`[load] rollup environment - css not supported - ignoring css ${id}`);
321
+ return { code: "" };
322
+ }
323
+ }
324
+ const JAY_HTML_CSS = ".css";
280
325
  async function resolveJayHtml(context, source, importer, options, generationTarget = compilerShared.GenerateTarget.jay) {
281
326
  const resolved = await context.resolve(source, importer, { ...options, skipSelf: true });
282
327
  if (!resolved || compilerShared.hasExtension(resolved.id, compilerShared.TS_EXTENSION) || compilerShared.hasExtension(resolved.id, compilerShared.TSX_EXTENSION))
@@ -351,26 +396,23 @@ function getResolvedId(resolved, mode, originId) {
351
396
  const id = `${originId}?${mode}.${extension}`;
352
397
  return id;
353
398
  }
354
- function stripTSExtension(id) {
355
- return id.replace(compilerShared.TS_EXTENSION, "").replace(compilerShared.TSX_EXTENSION, "");
399
+ function hasCssImportedByJayHtml(source, importer) {
400
+ return compilerShared.hasExtension(source, compilerShared.CSS_EXTENSION) && importer && (compilerShared.hasExtension(importer, compilerShared.JAY_EXTENSION, { withTs: true }) || compilerShared.hasExtension(importer, compilerShared.JAY_EXTENSION + compilerShared.JAY_QUERY_MAIN_SANDBOX, { withTs: true }));
356
401
  }
357
- async function loadJayFile(context, id) {
358
- console.info(`[load] start ${id}`);
359
- let { originId } = getJayMetadata(context, id);
360
- if (!Boolean(originId))
361
- originId = stripTSExtension(id);
362
- const code = checkCodeErrors(await readFileAsString(originId));
363
- console.info(`[load] end ${id}`);
364
- return { code };
402
+ function resolveCssFile(context, importer) {
403
+ const originImporter = importer.split("?")[0];
404
+ const originId = stripTSExtension(originImporter);
405
+ const id = `${originId}${JAY_HTML_CSS}`;
406
+ return {
407
+ id,
408
+ meta: appendJayMetadata(context, id, {
409
+ format: compilerShared.SourceFileFormat.CSS,
410
+ originId
411
+ })
412
+ };
365
413
  }
366
- async function loadContractFile(context, id) {
367
- console.info(`[load] start ${id}`);
368
- let { originId } = getJayMetadata(context, id);
369
- if (!Boolean(originId))
370
- originId = stripTSExtension(id);
371
- const code = await readFileAsString(originId);
372
- console.info(`[load] end ${id}`);
373
- return { code };
414
+ function isResolvedCssFile(id) {
415
+ return id.endsWith(JAY_HTML_CSS) && id.indexOf(compilerShared.JAY_EXTENSION) > 0;
374
416
  }
375
417
  class JayPluginContext {
376
418
  constructor(jayOptions = {}) {
@@ -417,8 +459,15 @@ const GLOBAL_FUNC_REPOSITORY = "GLOBAL_FUNC_REPOSITORY.ts";
417
459
  function jayRuntime(jayOptions = {}, givenJayContext) {
418
460
  const jayContext = givenJayContext || new JayPluginContext(jayOptions);
419
461
  let server;
462
+ let isVite = false;
420
463
  return {
421
464
  name: "jay:runtime",
465
+ buildStart(opts) {
466
+ isVite = Boolean(opts.plugins?.some(
467
+ (plugin) => plugin.name === "vite:build-metadata" || plugin.name?.startsWith("vite:")
468
+ ));
469
+ console.log("[buildStart] Vite detected:", isVite);
470
+ },
422
471
  configureServer(_server) {
423
472
  server = _server;
424
473
  },
@@ -435,6 +484,9 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
435
484
  return await resolveJayContract(this, source, importer, options);
436
485
  if (compilerShared.hasJayModeExtension(source))
437
486
  return await resolveJayModeFile(this, source, importer, options);
487
+ if (hasCssImportedByJayHtml(source, importer)) {
488
+ return resolveCssFile(this, importer);
489
+ }
438
490
  if (source.includes(SANDBOX_ROOT_PREFIX) || jayOptions.isWorker && importer === void 0)
439
491
  return await removeSandboxPrefixForWorkerRoot(this, source, importer, options);
440
492
  if (source === compilerShared.Import.functionRepository.module)
@@ -442,10 +494,12 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
442
494
  return null;
443
495
  },
444
496
  async load(id) {
445
- if (compilerShared.hasExtension(id, compilerShared.JAY_EXTENSION, { withTs: true }) || compilerShared.hasJayModeExtension(id, { withTs: true }))
497
+ if (compilerShared.hasExtension(id, compilerShared.JAY_EXTENSION, { withTs: true }) || compilerShared.hasJayModeExtension(id, { withTs: true })) {
446
498
  return await loadJayFile(this, id);
447
- else if (compilerShared.hasExtension(id, compilerShared.JAY_CONTRACT_EXTENSION, { withTs: true })) {
499
+ } else if (compilerShared.hasExtension(id, compilerShared.JAY_CONTRACT_EXTENSION, { withTs: true })) {
448
500
  return await loadContractFile(this, id);
501
+ } else if (isResolvedCssFile(id)) {
502
+ return await loadCssFile(this, jayContext, id, isVite);
449
503
  } else if (id === GLOBAL_FUNC_REPOSITORY) {
450
504
  const { functionRepository } = jayContext.globalFunctionsRepository.generateGlobalFile();
451
505
  return functionRepository;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jay-framework/rollup-plugin",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/index.js",
6
6
  "keywords": [
@@ -26,16 +26,16 @@
26
26
  "test:watch": "vitest"
27
27
  },
28
28
  "dependencies": {
29
- "@jay-framework/compiler": "^0.6.6",
30
- "@jay-framework/compiler-jay-html": "^0.6.6",
29
+ "@jay-framework/compiler": "^0.6.7",
30
+ "@jay-framework/compiler-jay-html": "^0.6.7",
31
31
  "fast-glob": "^3.3.2",
32
32
  "typescript": "^5.3.3"
33
33
  },
34
34
  "devDependencies": {
35
- "@jay-framework/component": "^0.6.6",
36
- "@jay-framework/dev-environment": "^0.6.6",
37
- "@jay-framework/runtime": "^0.6.6",
38
- "@jay-framework/secure": "^0.6.6",
35
+ "@jay-framework/component": "^0.6.7",
36
+ "@jay-framework/dev-environment": "^0.6.7",
37
+ "@jay-framework/runtime": "^0.6.7",
38
+ "@jay-framework/secure": "^0.6.7",
39
39
  "@types/node": "^20.11.5",
40
40
  "rimraf": "^5.0.5",
41
41
  "rollup": "^4.9.5",