@jay-framework/rollup-plugin 0.11.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.
- package/dist/index.js +22 -21
- 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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
297
|
+
getLogger().info(`[load] end ${id}, code length: ${code.length}`);
|
|
297
298
|
return { code };
|
|
298
299
|
}
|
|
299
300
|
async function loadContractFile(context, id) {
|
|
300
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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);
|
|
@@ -333,10 +334,10 @@ async function loadCssFile(context, jayContext, id, isVite) {
|
|
|
333
334
|
watchChangesFor(context, cssFile);
|
|
334
335
|
}
|
|
335
336
|
}
|
|
336
|
-
|
|
337
|
+
getLogger().info(`[load] end ${id}`);
|
|
337
338
|
return { code: jayHtml.val?.css };
|
|
338
339
|
} else {
|
|
339
|
-
|
|
340
|
+
getLogger().info(`[load] rollup environment - css not supported - ignoring css ${id}`);
|
|
340
341
|
return { code: "" };
|
|
341
342
|
}
|
|
342
343
|
}
|
|
@@ -346,7 +347,7 @@ async function resolveJayHtml(context, source, importer, options, root, generati
|
|
|
346
347
|
const sourceBasePath = sourceParsed.basePath;
|
|
347
348
|
if (source.endsWith(TS_EXTENSION) || source.endsWith(TSX_EXTENSION)) {
|
|
348
349
|
const originId2 = sourceBasePath.replace(TS_EXTENSION, "").replace(TSX_EXTENSION, "");
|
|
349
|
-
|
|
350
|
+
getLogger().info(`[resolveId] already resolved ${source}, originId: ${originId2}`);
|
|
350
351
|
return {
|
|
351
352
|
id: source,
|
|
352
353
|
meta: appendJayMetadata(context, source, {
|
|
@@ -376,7 +377,7 @@ async function resolveJayHtml(context, source, importer, options, root, generati
|
|
|
376
377
|
}
|
|
377
378
|
const baseWithQuery = sourceParsed.fullQueryString ? `${originId}${sourceParsed.fullQueryString}` : originId;
|
|
378
379
|
const id = context["ssr"] && originId.startsWith(root) ? `${baseWithQuery}${extension}`.slice(root.length) : `${baseWithQuery}${extension}`;
|
|
379
|
-
|
|
380
|
+
getLogger().info(`[resolveId] resolved ${id} as ${format}`);
|
|
380
381
|
return { id, meta: appendJayMetadata(context, id, { format, originId }) };
|
|
381
382
|
}
|
|
382
383
|
async function resolveJayContract(context, source, importer, options, root) {
|
|
@@ -384,7 +385,7 @@ async function resolveJayContract(context, source, importer, options, root) {
|
|
|
384
385
|
const sourceBasePath = sourceParsed.basePath;
|
|
385
386
|
if (source.endsWith(TS_EXTENSION) || source.endsWith(TSX_EXTENSION)) {
|
|
386
387
|
const originId2 = sourceBasePath.replace(TS_EXTENSION, "").replace(TSX_EXTENSION, "");
|
|
387
|
-
|
|
388
|
+
getLogger().info(`[resolveId] already resolved contract ${source}, originId: ${originId2}`);
|
|
388
389
|
return {
|
|
389
390
|
id: source,
|
|
390
391
|
meta: appendJayMetadata(context, source, {
|
|
@@ -403,7 +404,7 @@ async function resolveJayContract(context, source, importer, options, root) {
|
|
|
403
404
|
const originId = resolvedParsed.basePath;
|
|
404
405
|
const baseWithQuery = sourceParsed.fullQueryString ? `${originId}${sourceParsed.fullQueryString}` : originId;
|
|
405
406
|
const id = context["ssr"] && originId.startsWith(root) ? `${baseWithQuery}${TS_EXTENSION}`.slice(root.length) : `${baseWithQuery}${TS_EXTENSION}`;
|
|
406
|
-
|
|
407
|
+
getLogger().info(
|
|
407
408
|
`[resolveId] contract - id: ${id}, originId: ${originId}, ssr: ${context["ssr"]}`
|
|
408
409
|
);
|
|
409
410
|
return {
|
|
@@ -429,7 +430,7 @@ async function resolveJayModeFile(context, source, importer, options) {
|
|
|
429
430
|
const format = resolvedJayMeta.format || SourceFileFormat.TypeScript;
|
|
430
431
|
const originId = resolvedJayMeta.originId || resolved.id;
|
|
431
432
|
const id = getResolvedId(resolved, mode, originId);
|
|
432
|
-
|
|
433
|
+
getLogger().info(`[resolveId] resolved ${id} as ${format}`);
|
|
433
434
|
return { id, meta: appendJayMetadata(context, id, { format, originId }, resolvedJayMeta) };
|
|
434
435
|
}
|
|
435
436
|
async function removeSandboxPrefixForWorkerRoot(context, source, importer, options) {
|
|
@@ -442,7 +443,7 @@ async function removeSandboxPrefixForWorkerRoot(context, source, importer, optio
|
|
|
442
443
|
return null;
|
|
443
444
|
const id = `${resolved.id}${JAY_QUERY_WORKER_TRUSTED_TS}`;
|
|
444
445
|
const originId = id.split("?")[0];
|
|
445
|
-
|
|
446
|
+
getLogger().info(`[resolveId] resolved sandbox root ${id}`);
|
|
446
447
|
return {
|
|
447
448
|
id,
|
|
448
449
|
meta: appendJayMetadata(context, id, {
|
|
@@ -501,14 +502,14 @@ class JayPluginContext {
|
|
|
501
502
|
this.globalFunctionsRepository = new FunctionRepositoryBuilder();
|
|
502
503
|
}
|
|
503
504
|
cacheJayFile(id, jayFile) {
|
|
504
|
-
|
|
505
|
+
getLogger().info(`[cache] set ${id}`);
|
|
505
506
|
this.jayFileCache.set(id, jayFile);
|
|
506
507
|
return jayFile;
|
|
507
508
|
}
|
|
508
509
|
getCachedJayFile(id) {
|
|
509
510
|
const jayFile = this.jayFileCache.get(id);
|
|
510
511
|
if (Boolean(jayFile)) {
|
|
511
|
-
|
|
512
|
+
getLogger().info(`[cache] hit ${id}`);
|
|
512
513
|
}
|
|
513
514
|
return jayFile;
|
|
514
515
|
}
|
|
@@ -534,7 +535,7 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
|
|
|
534
535
|
(plugin) => plugin.name === "vite:build-metadata" || plugin.name?.startsWith("vite:")
|
|
535
536
|
)
|
|
536
537
|
);
|
|
537
|
-
|
|
538
|
+
getLogger().info("[buildStart] Vite detected: " + isVite);
|
|
538
539
|
},
|
|
539
540
|
configureServer(_server) {
|
|
540
541
|
server = _server;
|
|
@@ -582,7 +583,7 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
|
|
|
582
583
|
return null;
|
|
583
584
|
},
|
|
584
585
|
watchChange(id, change) {
|
|
585
|
-
|
|
586
|
+
getLogger().info(`[watchChange] ${id} ${change.event}`);
|
|
586
587
|
jayContext.deleteCachedJayFile(id);
|
|
587
588
|
if (server) {
|
|
588
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.
|
|
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.
|
|
31
|
-
"@jay-framework/compiler-jay-html": "^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.
|
|
37
|
-
"@jay-framework/dev-environment": "^0.
|
|
38
|
-
"@jay-framework/runtime": "^0.
|
|
39
|
-
"@jay-framework/secure": "^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",
|