@jay-framework/rollup-plugin 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 +1 -1
- package/dist/index.js +94 -47
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { GenerateTarget, CompilerSourceFile } from '@jay-framework/compiler-shar
|
|
|
5
5
|
import * as ts from 'typescript';
|
|
6
6
|
import { ViteDevServer } from 'vite';
|
|
7
7
|
|
|
8
|
-
declare function jayDefinitions(): {
|
|
8
|
+
declare function jayDefinitions(projectRoot: string): {
|
|
9
9
|
name: string;
|
|
10
10
|
load(id: string): Promise<LoadResult>;
|
|
11
11
|
transform(code: string, id: string): Promise<TransformResult>;
|
package/dist/index.js
CHANGED
|
@@ -7,16 +7,17 @@ var __publicField = (obj, key, value) => {
|
|
|
7
7
|
import { generateElementDefinitionFile, parseGenericTypescriptFile, generateImportsFileFromJayFile, generateElementFile, transformComponent, transformComponentBridge, compileFunctionSplitPatternsBlock, createTsSourceFileFromSource, FunctionRepositoryBuilder } from "@jay-framework/compiler";
|
|
8
8
|
export * from "@jay-framework/compiler";
|
|
9
9
|
import path from "node:path";
|
|
10
|
-
import { JAY_EXTENSION, hasExtension, JAY_CONTRACT_EXTENSION, checkValidationErrors, JAY_DTS_EXTENSION, JAY_CONTRACT_DTS_EXTENSION, SourceFileFormat, getModeFromExtension, GenerateTarget, RuntimeMode, TS_EXTENSION, TSX_EXTENSION, JAY_QUERY_WORKER_TRUSTED_TS, CSS_EXTENSION, JAY_QUERY_MAIN_SANDBOX, hasJayModeExtension, Import } from "@jay-framework/compiler-shared";
|
|
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
13
|
import { getJayHtmlImports, parseJayFile, JAY_IMPORT_RESOLVER, parseContract, compileContract, generateSandboxRootFile, generateElementBridgeFile } from "@jay-framework/compiler-jay-html";
|
|
14
14
|
import { createRequire } from "module";
|
|
15
15
|
import fs from "fs";
|
|
16
16
|
function getFileContext(filename, extension = JAY_EXTENSION) {
|
|
17
|
+
const basePath = getBasePath(filename);
|
|
17
18
|
return {
|
|
18
|
-
filename: path.basename(
|
|
19
|
-
dirname: path.dirname(
|
|
19
|
+
filename: path.basename(basePath).replace(extension, ""),
|
|
20
|
+
dirname: path.dirname(basePath)
|
|
20
21
|
};
|
|
21
22
|
}
|
|
22
23
|
async function readFileAsString(filePath) {
|
|
@@ -42,7 +43,7 @@ function checkCodeErrors(code) {
|
|
|
42
43
|
throw new Error("Empty code file");
|
|
43
44
|
return code;
|
|
44
45
|
}
|
|
45
|
-
function jayDefinitions() {
|
|
46
|
+
function jayDefinitions(projectRoot) {
|
|
46
47
|
return {
|
|
47
48
|
name: "jay:definitions",
|
|
48
49
|
// this name will show up in warnings and errors
|
|
@@ -59,7 +60,7 @@ function jayDefinitions() {
|
|
|
59
60
|
const context = this;
|
|
60
61
|
const { filename, dirname } = getFileContext(id);
|
|
61
62
|
const imports = getJayHtmlImports(code).filter(
|
|
62
|
-
(module) => module.endsWith("jay-html.d")
|
|
63
|
+
(module) => module && module.endsWith("jay-html.d")
|
|
63
64
|
);
|
|
64
65
|
await Promise.all(
|
|
65
66
|
imports.map(
|
|
@@ -74,7 +75,8 @@ function jayDefinitions() {
|
|
|
74
75
|
filename,
|
|
75
76
|
dirname,
|
|
76
77
|
{},
|
|
77
|
-
JAY_IMPORT_RESOLVER
|
|
78
|
+
JAY_IMPORT_RESOLVER,
|
|
79
|
+
projectRoot
|
|
78
80
|
);
|
|
79
81
|
const tsCode = checkValidationErrors(
|
|
80
82
|
generateElementDefinitionFile(parsedFile)
|
|
@@ -96,10 +98,11 @@ function jayDefinitions() {
|
|
|
96
98
|
`${dirname}/${filename}`,
|
|
97
99
|
JAY_IMPORT_RESOLVER
|
|
98
100
|
);
|
|
101
|
+
const validatedTsCode = checkValidationErrors(tsCode);
|
|
99
102
|
const generatedFilename = await writeDefinitionFile(
|
|
100
103
|
dirname,
|
|
101
104
|
filename,
|
|
102
|
-
|
|
105
|
+
validatedTsCode,
|
|
103
106
|
JAY_CONTRACT_DTS_EXTENSION
|
|
104
107
|
);
|
|
105
108
|
context.info(`[transform] generated ${generatedFilename}`);
|
|
@@ -113,7 +116,7 @@ const SANDBOX_ROOT_PREFIX = "jay-sandbox:";
|
|
|
113
116
|
const SSR_METADATA = /* @__PURE__ */ new Map();
|
|
114
117
|
function getJayMetadata(context, id, { checkPresent = false } = {}) {
|
|
115
118
|
const metadataFromPlugin = context.getModuleInfo(id)?.meta?.jay;
|
|
116
|
-
const metadata = context["ssr"] ? metadataFromPlugin || SSR_METADATA.get(id) : metadataFromPlugin || {};
|
|
119
|
+
const metadata = context["ssr"] ? metadataFromPlugin || SSR_METADATA.get(id) || {} : metadataFromPlugin || {};
|
|
117
120
|
validateJayMetadata(id, metadata, checkPresent);
|
|
118
121
|
return metadata;
|
|
119
122
|
}
|
|
@@ -173,7 +176,8 @@ async function getJayStructureFromJayHtmlSource(jayContext, code, id) {
|
|
|
173
176
|
{
|
|
174
177
|
relativePath: jayContext.jayOptions.tsConfigFilePath
|
|
175
178
|
},
|
|
176
|
-
JAY_IMPORT_RESOLVER
|
|
179
|
+
JAY_IMPORT_RESOLVER,
|
|
180
|
+
jayContext.projectRoot
|
|
177
181
|
);
|
|
178
182
|
}
|
|
179
183
|
async function getJayStructureFromTypeScriptSource(code, id) {
|
|
@@ -278,15 +282,18 @@ function watchChangesFor(context, sourcePath) {
|
|
|
278
282
|
console.info(`[watch] add ${sourcePath}`);
|
|
279
283
|
}
|
|
280
284
|
function stripTSExtension(id) {
|
|
281
|
-
|
|
285
|
+
const basePath = getBasePath(id);
|
|
286
|
+
return basePath.replace(TS_EXTENSION, "").replace(TSX_EXTENSION, "");
|
|
282
287
|
}
|
|
283
288
|
async function loadJayFile(context, id) {
|
|
284
289
|
console.info(`[load] start ${id}`);
|
|
285
|
-
|
|
286
|
-
|
|
290
|
+
const metadata = getJayMetadata(context, id);
|
|
291
|
+
let originId = metadata.originId;
|
|
292
|
+
if (!Boolean(originId)) {
|
|
287
293
|
originId = stripTSExtension(id);
|
|
294
|
+
}
|
|
288
295
|
const code = checkCodeErrors(await readFileAsString(originId));
|
|
289
|
-
console.info(`[load] end ${id}`);
|
|
296
|
+
console.info(`[load] end ${id}, code length: ${code.length}`);
|
|
290
297
|
return { code };
|
|
291
298
|
}
|
|
292
299
|
async function loadContractFile(context, id) {
|
|
@@ -294,9 +301,15 @@ async function loadContractFile(context, id) {
|
|
|
294
301
|
let { originId } = getJayMetadata(context, id);
|
|
295
302
|
if (!Boolean(originId))
|
|
296
303
|
originId = stripTSExtension(id);
|
|
297
|
-
const
|
|
304
|
+
const yamlCode = await readFileAsString(originId);
|
|
305
|
+
const { filename, dirname } = getFileContext(id, JAY_CONTRACT_EXTENSION);
|
|
306
|
+
const parsedFile = parseContract(yamlCode, filename);
|
|
307
|
+
const tsCode = await compileContract(parsedFile, `${dirname}/${filename}`, JAY_IMPORT_RESOLVER);
|
|
308
|
+
if (!tsCode.val) {
|
|
309
|
+
throw new Error(`Failed to compile contract ${id}: ${JSON.stringify(tsCode.validations)}`);
|
|
310
|
+
}
|
|
298
311
|
console.info(`[load] end ${id}`);
|
|
299
|
-
return { code };
|
|
312
|
+
return { code: tsCode.val };
|
|
300
313
|
}
|
|
301
314
|
async function loadCssFile(context, jayContext, id, isVite) {
|
|
302
315
|
if (isVite) {
|
|
@@ -312,10 +325,16 @@ async function loadCssFile(context, jayContext, id, isVite) {
|
|
|
312
325
|
{
|
|
313
326
|
relativePath: jayContext.jayOptions.tsConfigFilePath
|
|
314
327
|
},
|
|
315
|
-
JAY_IMPORT_RESOLVER
|
|
328
|
+
JAY_IMPORT_RESOLVER,
|
|
329
|
+
jayContext.projectRoot
|
|
316
330
|
);
|
|
331
|
+
if (jayHtml.val?.linkedCssFiles) {
|
|
332
|
+
for (const cssFile of jayHtml.val.linkedCssFiles) {
|
|
333
|
+
watchChangesFor(context, cssFile);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
317
336
|
console.info(`[load] end ${id}`);
|
|
318
|
-
return { code: jayHtml.val
|
|
337
|
+
return { code: jayHtml.val?.css };
|
|
319
338
|
} else {
|
|
320
339
|
console.info(`[load] rollup environment - css not supported - ignoring css ${id}`);
|
|
321
340
|
return { code: "" };
|
|
@@ -323,9 +342,27 @@ async function loadCssFile(context, jayContext, id, isVite) {
|
|
|
323
342
|
}
|
|
324
343
|
const JAY_HTML_CSS = ".css";
|
|
325
344
|
async function resolveJayHtml(context, source, importer, options, root, generationTarget = GenerateTarget.jay) {
|
|
326
|
-
const
|
|
345
|
+
const sourceParsed = parseJayModuleSpecifier(source);
|
|
346
|
+
const sourceBasePath = sourceParsed.basePath;
|
|
347
|
+
if (source.endsWith(TS_EXTENSION) || source.endsWith(TSX_EXTENSION)) {
|
|
348
|
+
const originId2 = sourceBasePath.replace(TS_EXTENSION, "").replace(TSX_EXTENSION, "");
|
|
349
|
+
console.info(`[resolveId] already resolved ${source}, originId: ${originId2}`);
|
|
350
|
+
return {
|
|
351
|
+
id: source,
|
|
352
|
+
meta: appendJayMetadata(context, source, {
|
|
353
|
+
format: SourceFileFormat.JayHtml,
|
|
354
|
+
originId: originId2
|
|
355
|
+
})
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
const resolved = await context.resolve(sourceBasePath, importer, {
|
|
359
|
+
...options,
|
|
360
|
+
skipSelf: true
|
|
361
|
+
});
|
|
327
362
|
if (!resolved || hasExtension(resolved.id, TS_EXTENSION) || hasExtension(resolved.id, TSX_EXTENSION))
|
|
328
363
|
return null;
|
|
364
|
+
const resolvedParsed = parseJayModuleSpecifier(resolved.id);
|
|
365
|
+
const resolvedBasePath = resolvedParsed.basePath;
|
|
329
366
|
const resolvedJayMeta = jayMetadataFromModuleMetadata(resolved.id, resolved.meta);
|
|
330
367
|
const extension = generationTarget === GenerateTarget.react ? TSX_EXTENSION : TS_EXTENSION;
|
|
331
368
|
let format, originId;
|
|
@@ -333,23 +370,48 @@ async function resolveJayHtml(context, source, importer, options, root, generati
|
|
|
333
370
|
format = resolvedJayMeta.format;
|
|
334
371
|
originId = resolvedJayMeta.originId;
|
|
335
372
|
} else {
|
|
336
|
-
watchChangesFor(context,
|
|
373
|
+
watchChangesFor(context, resolvedBasePath);
|
|
337
374
|
format = SourceFileFormat.JayHtml;
|
|
338
|
-
originId =
|
|
375
|
+
originId = resolvedBasePath;
|
|
339
376
|
}
|
|
340
|
-
const
|
|
377
|
+
const baseWithQuery = sourceParsed.fullQueryString ? `${originId}${sourceParsed.fullQueryString}` : originId;
|
|
378
|
+
const id = context["ssr"] && originId.startsWith(root) ? `${baseWithQuery}${extension}`.slice(root.length) : `${baseWithQuery}${extension}`;
|
|
341
379
|
console.info(`[resolveId] resolved ${id} as ${format}`);
|
|
342
380
|
return { id, meta: appendJayMetadata(context, id, { format, originId }) };
|
|
343
381
|
}
|
|
344
|
-
async function resolveJayContract(context, source, importer, options) {
|
|
345
|
-
const
|
|
346
|
-
const
|
|
347
|
-
|
|
382
|
+
async function resolveJayContract(context, source, importer, options, root) {
|
|
383
|
+
const sourceParsed = parseJayModuleSpecifier(source);
|
|
384
|
+
const sourceBasePath = sourceParsed.basePath;
|
|
385
|
+
if (source.endsWith(TS_EXTENSION) || source.endsWith(TSX_EXTENSION)) {
|
|
386
|
+
const originId2 = sourceBasePath.replace(TS_EXTENSION, "").replace(TSX_EXTENSION, "");
|
|
387
|
+
console.info(`[resolveId] already resolved contract ${source}, originId: ${originId2}`);
|
|
388
|
+
return {
|
|
389
|
+
id: source,
|
|
390
|
+
meta: appendJayMetadata(context, source, {
|
|
391
|
+
format: SourceFileFormat.JayContract,
|
|
392
|
+
originId: originId2
|
|
393
|
+
})
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
const resolved = await context.resolve(sourceBasePath, importer, {
|
|
397
|
+
...options,
|
|
398
|
+
skipSelf: true
|
|
399
|
+
});
|
|
400
|
+
if (!resolved)
|
|
401
|
+
return null;
|
|
402
|
+
const resolvedParsed = parseJayModuleSpecifier(resolved.id);
|
|
403
|
+
const originId = resolvedParsed.basePath;
|
|
404
|
+
const baseWithQuery = sourceParsed.fullQueryString ? `${originId}${sourceParsed.fullQueryString}` : originId;
|
|
405
|
+
const id = context["ssr"] && originId.startsWith(root) ? `${baseWithQuery}${TS_EXTENSION}`.slice(root.length) : `${baseWithQuery}${TS_EXTENSION}`;
|
|
406
|
+
console.info(
|
|
407
|
+
`[resolveId] contract - id: ${id}, originId: ${originId}, ssr: ${context["ssr"]}`
|
|
408
|
+
);
|
|
348
409
|
return {
|
|
349
410
|
id,
|
|
350
411
|
meta: appendJayMetadata(context, id, {
|
|
351
412
|
format: SourceFileFormat.JayContract,
|
|
352
|
-
originId
|
|
413
|
+
originId
|
|
414
|
+
// Use basePath without query params for file loading
|
|
353
415
|
})
|
|
354
416
|
};
|
|
355
417
|
}
|
|
@@ -478,7 +540,7 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
|
|
|
478
540
|
server = _server;
|
|
479
541
|
},
|
|
480
542
|
async resolveId(source, importer, options) {
|
|
481
|
-
if (
|
|
543
|
+
if (hasJayExtension(source, JAY_EXTENSION)) {
|
|
482
544
|
return await resolveJayHtml(
|
|
483
545
|
this,
|
|
484
546
|
source,
|
|
@@ -488,8 +550,8 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
|
|
|
488
550
|
jayOptions.generationTarget
|
|
489
551
|
);
|
|
490
552
|
}
|
|
491
|
-
if (
|
|
492
|
-
return await resolveJayContract(this, source, importer, options);
|
|
553
|
+
if (hasJayExtension(source, JAY_CONTRACT_EXTENSION))
|
|
554
|
+
return await resolveJayContract(this, source, importer, options, config?.root);
|
|
493
555
|
if (hasJayModeExtension(source))
|
|
494
556
|
return await resolveJayModeFile(this, source, importer, options);
|
|
495
557
|
if (hasCssImportedByJayHtml(source, importer)) {
|
|
@@ -502,9 +564,9 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
|
|
|
502
564
|
return null;
|
|
503
565
|
},
|
|
504
566
|
async load(id) {
|
|
505
|
-
if (
|
|
567
|
+
if (hasJayExtension(id, JAY_EXTENSION, { withTs: true }) || hasJayModeExtension(id, { withTs: true })) {
|
|
506
568
|
return await loadJayFile(this, id);
|
|
507
|
-
} else if (
|
|
569
|
+
} else if (hasJayExtension(id, JAY_CONTRACT_EXTENSION, { withTs: true })) {
|
|
508
570
|
return await loadContractFile(this, id);
|
|
509
571
|
} else if (isResolvedCssFile(id)) {
|
|
510
572
|
return await loadCssFile(this, jayContext, id, isVite);
|
|
@@ -515,23 +577,8 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
|
|
|
515
577
|
return null;
|
|
516
578
|
},
|
|
517
579
|
async transform(code, id) {
|
|
518
|
-
if (
|
|
580
|
+
if (hasJayExtension(id, JAY_EXTENSION, { withTs: true }) || hasJayModeExtension(id, { withTs: true }))
|
|
519
581
|
return await transformJayFile(jayContext, this, code, id);
|
|
520
|
-
else if (hasExtension(id, JAY_CONTRACT_EXTENSION, { withTs: true })) {
|
|
521
|
-
const { filename, dirname } = getFileContext(id, JAY_CONTRACT_EXTENSION);
|
|
522
|
-
const parsedFile = parseContract(code, filename);
|
|
523
|
-
const tsCode = await compileContract(
|
|
524
|
-
parsedFile,
|
|
525
|
-
`${dirname}/${filename}`,
|
|
526
|
-
JAY_IMPORT_RESOLVER
|
|
527
|
-
);
|
|
528
|
-
if (tsCode.val)
|
|
529
|
-
return Promise.resolve({
|
|
530
|
-
code: tsCode.val
|
|
531
|
-
});
|
|
532
|
-
else
|
|
533
|
-
return Promise.reject(tsCode.validations);
|
|
534
|
-
}
|
|
535
582
|
return null;
|
|
536
583
|
},
|
|
537
584
|
watchChange(id, change) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jay-framework/rollup-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -27,16 +27,16 @@
|
|
|
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.11.0",
|
|
31
|
+
"@jay-framework/compiler-jay-html": "^0.11.0",
|
|
32
32
|
"fast-glob": "^3.3.2",
|
|
33
33
|
"typescript": "^5.3.3"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@jay-framework/component": "^0.
|
|
37
|
-
"@jay-framework/dev-environment": "^0.
|
|
38
|
-
"@jay-framework/runtime": "^0.
|
|
39
|
-
"@jay-framework/secure": "^0.
|
|
36
|
+
"@jay-framework/component": "^0.11.0",
|
|
37
|
+
"@jay-framework/dev-environment": "^0.11.0",
|
|
38
|
+
"@jay-framework/runtime": "^0.11.0",
|
|
39
|
+
"@jay-framework/secure": "^0.11.0",
|
|
40
40
|
"@types/node": "^20.11.5",
|
|
41
41
|
"rimraf": "^5.0.5",
|
|
42
42
|
"rollup": "^4.9.5",
|