@jay-framework/rollup-plugin 0.9.0 → 0.10.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 +88 -46
- 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,7 +325,8 @@ 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
|
);
|
|
317
331
|
console.info(`[load] end ${id}`);
|
|
318
332
|
return { code: jayHtml.val.css };
|
|
@@ -323,9 +337,27 @@ async function loadCssFile(context, jayContext, id, isVite) {
|
|
|
323
337
|
}
|
|
324
338
|
const JAY_HTML_CSS = ".css";
|
|
325
339
|
async function resolveJayHtml(context, source, importer, options, root, generationTarget = GenerateTarget.jay) {
|
|
326
|
-
const
|
|
340
|
+
const sourceParsed = parseJayModuleSpecifier(source);
|
|
341
|
+
const sourceBasePath = sourceParsed.basePath;
|
|
342
|
+
if (source.endsWith(TS_EXTENSION) || source.endsWith(TSX_EXTENSION)) {
|
|
343
|
+
const originId2 = sourceBasePath.replace(TS_EXTENSION, "").replace(TSX_EXTENSION, "");
|
|
344
|
+
console.info(`[resolveId] already resolved ${source}, originId: ${originId2}`);
|
|
345
|
+
return {
|
|
346
|
+
id: source,
|
|
347
|
+
meta: appendJayMetadata(context, source, {
|
|
348
|
+
format: SourceFileFormat.JayHtml,
|
|
349
|
+
originId: originId2
|
|
350
|
+
})
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
const resolved = await context.resolve(sourceBasePath, importer, {
|
|
354
|
+
...options,
|
|
355
|
+
skipSelf: true
|
|
356
|
+
});
|
|
327
357
|
if (!resolved || hasExtension(resolved.id, TS_EXTENSION) || hasExtension(resolved.id, TSX_EXTENSION))
|
|
328
358
|
return null;
|
|
359
|
+
const resolvedParsed = parseJayModuleSpecifier(resolved.id);
|
|
360
|
+
const resolvedBasePath = resolvedParsed.basePath;
|
|
329
361
|
const resolvedJayMeta = jayMetadataFromModuleMetadata(resolved.id, resolved.meta);
|
|
330
362
|
const extension = generationTarget === GenerateTarget.react ? TSX_EXTENSION : TS_EXTENSION;
|
|
331
363
|
let format, originId;
|
|
@@ -333,23 +365,48 @@ async function resolveJayHtml(context, source, importer, options, root, generati
|
|
|
333
365
|
format = resolvedJayMeta.format;
|
|
334
366
|
originId = resolvedJayMeta.originId;
|
|
335
367
|
} else {
|
|
336
|
-
watchChangesFor(context,
|
|
368
|
+
watchChangesFor(context, resolvedBasePath);
|
|
337
369
|
format = SourceFileFormat.JayHtml;
|
|
338
|
-
originId =
|
|
370
|
+
originId = resolvedBasePath;
|
|
339
371
|
}
|
|
340
|
-
const
|
|
372
|
+
const baseWithQuery = sourceParsed.fullQueryString ? `${originId}${sourceParsed.fullQueryString}` : originId;
|
|
373
|
+
const id = context["ssr"] && originId.startsWith(root) ? `${baseWithQuery}${extension}`.slice(root.length) : `${baseWithQuery}${extension}`;
|
|
341
374
|
console.info(`[resolveId] resolved ${id} as ${format}`);
|
|
342
375
|
return { id, meta: appendJayMetadata(context, id, { format, originId }) };
|
|
343
376
|
}
|
|
344
|
-
async function resolveJayContract(context, source, importer, options) {
|
|
345
|
-
const
|
|
346
|
-
const
|
|
347
|
-
|
|
377
|
+
async function resolveJayContract(context, source, importer, options, root) {
|
|
378
|
+
const sourceParsed = parseJayModuleSpecifier(source);
|
|
379
|
+
const sourceBasePath = sourceParsed.basePath;
|
|
380
|
+
if (source.endsWith(TS_EXTENSION) || source.endsWith(TSX_EXTENSION)) {
|
|
381
|
+
const originId2 = sourceBasePath.replace(TS_EXTENSION, "").replace(TSX_EXTENSION, "");
|
|
382
|
+
console.info(`[resolveId] already resolved contract ${source}, originId: ${originId2}`);
|
|
383
|
+
return {
|
|
384
|
+
id: source,
|
|
385
|
+
meta: appendJayMetadata(context, source, {
|
|
386
|
+
format: SourceFileFormat.JayContract,
|
|
387
|
+
originId: originId2
|
|
388
|
+
})
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
const resolved = await context.resolve(sourceBasePath, importer, {
|
|
392
|
+
...options,
|
|
393
|
+
skipSelf: true
|
|
394
|
+
});
|
|
395
|
+
if (!resolved)
|
|
396
|
+
return null;
|
|
397
|
+
const resolvedParsed = parseJayModuleSpecifier(resolved.id);
|
|
398
|
+
const originId = resolvedParsed.basePath;
|
|
399
|
+
const baseWithQuery = sourceParsed.fullQueryString ? `${originId}${sourceParsed.fullQueryString}` : originId;
|
|
400
|
+
const id = context["ssr"] && originId.startsWith(root) ? `${baseWithQuery}${TS_EXTENSION}`.slice(root.length) : `${baseWithQuery}${TS_EXTENSION}`;
|
|
401
|
+
console.info(
|
|
402
|
+
`[resolveId] contract - id: ${id}, originId: ${originId}, ssr: ${context["ssr"]}`
|
|
403
|
+
);
|
|
348
404
|
return {
|
|
349
405
|
id,
|
|
350
406
|
meta: appendJayMetadata(context, id, {
|
|
351
407
|
format: SourceFileFormat.JayContract,
|
|
352
|
-
originId
|
|
408
|
+
originId
|
|
409
|
+
// Use basePath without query params for file loading
|
|
353
410
|
})
|
|
354
411
|
};
|
|
355
412
|
}
|
|
@@ -478,7 +535,7 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
|
|
|
478
535
|
server = _server;
|
|
479
536
|
},
|
|
480
537
|
async resolveId(source, importer, options) {
|
|
481
|
-
if (
|
|
538
|
+
if (hasJayExtension(source, JAY_EXTENSION)) {
|
|
482
539
|
return await resolveJayHtml(
|
|
483
540
|
this,
|
|
484
541
|
source,
|
|
@@ -488,8 +545,8 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
|
|
|
488
545
|
jayOptions.generationTarget
|
|
489
546
|
);
|
|
490
547
|
}
|
|
491
|
-
if (
|
|
492
|
-
return await resolveJayContract(this, source, importer, options);
|
|
548
|
+
if (hasJayExtension(source, JAY_CONTRACT_EXTENSION))
|
|
549
|
+
return await resolveJayContract(this, source, importer, options, config?.root);
|
|
493
550
|
if (hasJayModeExtension(source))
|
|
494
551
|
return await resolveJayModeFile(this, source, importer, options);
|
|
495
552
|
if (hasCssImportedByJayHtml(source, importer)) {
|
|
@@ -502,9 +559,9 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
|
|
|
502
559
|
return null;
|
|
503
560
|
},
|
|
504
561
|
async load(id) {
|
|
505
|
-
if (
|
|
562
|
+
if (hasJayExtension(id, JAY_EXTENSION, { withTs: true }) || hasJayModeExtension(id, { withTs: true })) {
|
|
506
563
|
return await loadJayFile(this, id);
|
|
507
|
-
} else if (
|
|
564
|
+
} else if (hasJayExtension(id, JAY_CONTRACT_EXTENSION, { withTs: true })) {
|
|
508
565
|
return await loadContractFile(this, id);
|
|
509
566
|
} else if (isResolvedCssFile(id)) {
|
|
510
567
|
return await loadCssFile(this, jayContext, id, isVite);
|
|
@@ -515,23 +572,8 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
|
|
|
515
572
|
return null;
|
|
516
573
|
},
|
|
517
574
|
async transform(code, id) {
|
|
518
|
-
if (
|
|
575
|
+
if (hasJayExtension(id, JAY_EXTENSION, { withTs: true }) || hasJayModeExtension(id, { withTs: true }))
|
|
519
576
|
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
577
|
return null;
|
|
536
578
|
},
|
|
537
579
|
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.10.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.10.0",
|
|
31
|
+
"@jay-framework/compiler-jay-html": "^0.10.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.10.0",
|
|
37
|
+
"@jay-framework/dev-environment": "^0.10.0",
|
|
38
|
+
"@jay-framework/runtime": "^0.10.0",
|
|
39
|
+
"@jay-framework/secure": "^0.10.0",
|
|
40
40
|
"@types/node": "^20.11.5",
|
|
41
41
|
"rimraf": "^5.0.5",
|
|
42
42
|
"rollup": "^4.9.5",
|