@jay-framework/rollup-plugin 0.6.10 → 0.8.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 +46 -39
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -43,7 +43,7 @@ declare class JayPluginContext {
|
|
|
43
43
|
|
|
44
44
|
declare function jayRuntime(jayOptions?: JayRollupConfig, givenJayContext?: JayPluginContext): {
|
|
45
45
|
name: string;
|
|
46
|
-
configResolved(
|
|
46
|
+
configResolved(_config: any): void;
|
|
47
47
|
buildStart(opts: any): void;
|
|
48
48
|
configureServer(_server: ViteDevServer): void;
|
|
49
49
|
resolveId(source: string, importer: string | undefined, options: ResolveIdOptions): Promise<ResolveIdResult>;
|
package/dist/index.js
CHANGED
|
@@ -110,20 +110,30 @@ function jayDefinitions() {
|
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
112
|
const SANDBOX_ROOT_PREFIX = "jay-sandbox:";
|
|
113
|
+
const SSR_METADATA = /* @__PURE__ */ new Map();
|
|
113
114
|
function getJayMetadata(context, id, { checkPresent = false } = {}) {
|
|
114
|
-
|
|
115
|
+
const metadataFromPlugin = context.getModuleInfo(id)?.meta?.jay;
|
|
116
|
+
const metadata = context["ssr"] ? metadataFromPlugin || SSR_METADATA.get(id) : metadataFromPlugin || {};
|
|
117
|
+
validateJayMetadata(id, metadata, checkPresent);
|
|
118
|
+
return metadata;
|
|
115
119
|
}
|
|
116
120
|
function jayMetadataFromModuleMetadata(id, meta, { checkPresent = false } = {}) {
|
|
117
121
|
const metadata = meta?.jay ?? {};
|
|
118
|
-
|
|
119
|
-
|
|
122
|
+
validateJayMetadata(id, metadata, checkPresent);
|
|
123
|
+
return metadata;
|
|
124
|
+
}
|
|
125
|
+
function validateJayMetadata(id, jayMetadata, doValidate) {
|
|
126
|
+
if (doValidate) {
|
|
127
|
+
if (!jayMetadata.originId)
|
|
120
128
|
throw new Error(`Unknown Jay originId for ${id}`);
|
|
121
|
-
if (!
|
|
129
|
+
if (!jayMetadata.format)
|
|
122
130
|
throw new Error(`Unknown Jay format for ${id}`);
|
|
123
131
|
}
|
|
124
|
-
return metadata;
|
|
125
132
|
}
|
|
126
133
|
function appendJayMetadata(context, id, metadata, moduleMetadata) {
|
|
134
|
+
if (context["ssr"]) {
|
|
135
|
+
SSR_METADATA.set(id, metadata);
|
|
136
|
+
}
|
|
127
137
|
return { jay: { ...moduleMetadata ?? getJayMetadata(context, id), ...metadata } };
|
|
128
138
|
}
|
|
129
139
|
function getSourceJayMetadata(context, id) {
|
|
@@ -132,7 +142,7 @@ function getSourceJayMetadata(context, id) {
|
|
|
132
142
|
if (!sourcePath)
|
|
133
143
|
throw new Error(`Unknown Jay originId for ${id}`);
|
|
134
144
|
const sourceMetadata = getJayMetadata(context, sourcePath);
|
|
135
|
-
return sourceMetadata
|
|
145
|
+
return sourceMetadata?.originId ? sourceMetadata : metadata;
|
|
136
146
|
}
|
|
137
147
|
async function getJayFileStructure(jayContext, context, code, id) {
|
|
138
148
|
const meta = getSourceJayMetadata(context, id);
|
|
@@ -169,9 +179,12 @@ async function getJayStructureFromJayHtmlSource(jayContext, code, id) {
|
|
|
169
179
|
async function getJayStructureFromTypeScriptSource(code, id) {
|
|
170
180
|
return await parseGenericTypescriptFile(id, code);
|
|
171
181
|
}
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
182
|
+
const s = createRequire(import.meta.url), e = s("typescript"), c = new Proxy(e, {
|
|
183
|
+
get(t, r) {
|
|
184
|
+
return t[r];
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
const { transform, EmitHint, createSourceFile, ScriptTarget, ScriptKind } = c;
|
|
175
188
|
function checkDiagnosticsErrors(tsCode) {
|
|
176
189
|
if (tsCode.diagnostics.length > 0) {
|
|
177
190
|
throw new Error(
|
|
@@ -238,17 +251,11 @@ function generateCodeFromTsFile(jayContext, mode, jayFile, id, code) {
|
|
|
238
251
|
}
|
|
239
252
|
}
|
|
240
253
|
function transformTsCode(jayContext, transformers, id, code) {
|
|
241
|
-
const tsSource =
|
|
242
|
-
id,
|
|
243
|
-
code,
|
|
244
|
-
tsModule$1.ScriptTarget.Latest,
|
|
245
|
-
true,
|
|
246
|
-
tsModule$1.ScriptKind.TS
|
|
247
|
-
);
|
|
254
|
+
const tsSource = createSourceFile(id, code, ScriptTarget.Latest, true, ScriptKind.TS);
|
|
248
255
|
const tsCode = transform(tsSource, transformers);
|
|
249
256
|
checkDiagnosticsErrors(tsCode);
|
|
250
257
|
const outputCode = jayContext.tsPrinter.printNode(
|
|
251
|
-
|
|
258
|
+
EmitHint.Unspecified,
|
|
252
259
|
tsCode.transformed[0],
|
|
253
260
|
tsSource
|
|
254
261
|
);
|
|
@@ -315,25 +322,24 @@ async function loadCssFile(context, jayContext, id, isVite) {
|
|
|
315
322
|
}
|
|
316
323
|
}
|
|
317
324
|
const JAY_HTML_CSS = ".css";
|
|
318
|
-
async function resolveJayHtml(context, source, importer, options, generationTarget = GenerateTarget.jay) {
|
|
325
|
+
async function resolveJayHtml(context, source, importer, options, root, generationTarget = GenerateTarget.jay) {
|
|
319
326
|
const resolved = await context.resolve(source, importer, { ...options, skipSelf: true });
|
|
320
327
|
if (!resolved || hasExtension(resolved.id, TS_EXTENSION) || hasExtension(resolved.id, TSX_EXTENSION))
|
|
321
328
|
return null;
|
|
322
329
|
const resolvedJayMeta = jayMetadataFromModuleMetadata(resolved.id, resolved.meta);
|
|
323
330
|
const extension = generationTarget === GenerateTarget.react ? TSX_EXTENSION : TS_EXTENSION;
|
|
331
|
+
let format, originId;
|
|
324
332
|
if (resolvedJayMeta.originId) {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
console.info(`[resolveId] resolved ${id} as ${format}`);
|
|
328
|
-
return { id, meta: appendJayMetadata(context, id, { format, originId }) };
|
|
333
|
+
format = resolvedJayMeta.format;
|
|
334
|
+
originId = resolvedJayMeta.originId;
|
|
329
335
|
} else {
|
|
330
336
|
watchChangesFor(context, resolved.id);
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
const id = `${originId}${extension}`;
|
|
334
|
-
console.info(`[resolveId] resolved ${id} as ${format}`);
|
|
335
|
-
return { id, meta: appendJayMetadata(context, id, { format, originId }) };
|
|
337
|
+
format = SourceFileFormat.JayHtml;
|
|
338
|
+
originId = resolved.id;
|
|
336
339
|
}
|
|
340
|
+
const id = context["ssr"] && originId.startsWith(root) ? `${originId}${extension}`.slice(root.length) : `${originId}${extension}`;
|
|
341
|
+
console.info(`[resolveId] resolved ${id} as ${format}`);
|
|
342
|
+
return { id, meta: appendJayMetadata(context, id, { format, originId }) };
|
|
337
343
|
}
|
|
338
344
|
async function resolveJayContract(context, source, importer, options) {
|
|
339
345
|
const resolved = await context.resolve(source, importer, { ...options, skipSelf: true });
|
|
@@ -386,16 +392,15 @@ async function removeSandboxPrefixForWorkerRoot(context, source, importer, optio
|
|
|
386
392
|
}
|
|
387
393
|
function getResolvedId(resolved, mode, originId) {
|
|
388
394
|
const extension = resolved.id.split(".").pop();
|
|
389
|
-
|
|
390
|
-
return id;
|
|
395
|
+
return `${originId}?${mode}.${extension}`;
|
|
391
396
|
}
|
|
392
397
|
function hasCssImportedByJayHtml(source, importer) {
|
|
393
398
|
return hasExtension(source, CSS_EXTENSION) && importer && (hasExtension(importer, JAY_EXTENSION, { withTs: true }) || hasExtension(importer, JAY_EXTENSION + JAY_QUERY_MAIN_SANDBOX, { withTs: true }));
|
|
394
399
|
}
|
|
395
|
-
function
|
|
400
|
+
function resolveCssFileImportedByJayHtml(context, importer, root) {
|
|
396
401
|
const originImporter = importer.split("?")[0];
|
|
397
|
-
const originId = stripTSExtension(originImporter);
|
|
398
|
-
const id = `${originId}${JAY_HTML_CSS}`;
|
|
402
|
+
const originId = context["ssr"] ? getJayMetadata(context, originImporter)?.originId : stripTSExtension(originImporter);
|
|
403
|
+
const id = context["ssr"] && originId.startsWith(root) ? `${originId}${JAY_HTML_CSS}`.slice(root.length) : `${originId}${JAY_HTML_CSS}`;
|
|
399
404
|
return {
|
|
400
405
|
id,
|
|
401
406
|
meta: appendJayMetadata(context, id, {
|
|
@@ -407,9 +412,7 @@ function resolveCssFile(context, importer) {
|
|
|
407
412
|
function isResolvedCssFile(id) {
|
|
408
413
|
return id.endsWith(JAY_HTML_CSS) && id.indexOf(JAY_EXTENSION) > 0;
|
|
409
414
|
}
|
|
410
|
-
const
|
|
411
|
-
const tsModule = require2("typescript");
|
|
412
|
-
const { NewLineKind } = tsModule;
|
|
415
|
+
const { createPrinter, NewLineKind } = c;
|
|
413
416
|
class JayPluginContext {
|
|
414
417
|
constructor(jayOptions = {}) {
|
|
415
418
|
__publicField(this, "projectRoot");
|
|
@@ -421,7 +424,7 @@ class JayPluginContext {
|
|
|
421
424
|
this.jayOptions = jayOptions;
|
|
422
425
|
this.projectRoot = path.dirname(jayOptions.tsConfigFilePath ?? process.cwd());
|
|
423
426
|
this.outputDir = jayOptions.outputDir && path.join(this.projectRoot, jayOptions.outputDir);
|
|
424
|
-
this.tsPrinter =
|
|
427
|
+
this.tsPrinter = createPrinter({ newLine: NewLineKind.LineFeed });
|
|
425
428
|
let compilerPatternsParseResult = compileFunctionSplitPatternsBlock(
|
|
426
429
|
(jayOptions.compilerPatternFiles || []).map((fileName) => {
|
|
427
430
|
let fileContent = fs.readFileSync(fileName, { encoding: "utf8" });
|
|
@@ -456,9 +459,11 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
|
|
|
456
459
|
const jayContext = givenJayContext || new JayPluginContext(jayOptions);
|
|
457
460
|
let server;
|
|
458
461
|
let isVite = false;
|
|
462
|
+
let config;
|
|
459
463
|
return {
|
|
460
464
|
name: "jay:runtime",
|
|
461
|
-
configResolved(
|
|
465
|
+
configResolved(_config) {
|
|
466
|
+
config = _config;
|
|
462
467
|
isVite = true;
|
|
463
468
|
},
|
|
464
469
|
buildStart(opts) {
|
|
@@ -473,20 +478,22 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
|
|
|
473
478
|
server = _server;
|
|
474
479
|
},
|
|
475
480
|
async resolveId(source, importer, options) {
|
|
476
|
-
if (hasExtension(source, JAY_EXTENSION))
|
|
481
|
+
if (hasExtension(source, JAY_EXTENSION)) {
|
|
477
482
|
return await resolveJayHtml(
|
|
478
483
|
this,
|
|
479
484
|
source,
|
|
480
485
|
importer,
|
|
481
486
|
options,
|
|
487
|
+
config?.root,
|
|
482
488
|
jayOptions.generationTarget
|
|
483
489
|
);
|
|
490
|
+
}
|
|
484
491
|
if (hasExtension(source, JAY_CONTRACT_EXTENSION))
|
|
485
492
|
return await resolveJayContract(this, source, importer, options);
|
|
486
493
|
if (hasJayModeExtension(source))
|
|
487
494
|
return await resolveJayModeFile(this, source, importer, options);
|
|
488
495
|
if (hasCssImportedByJayHtml(source, importer)) {
|
|
489
|
-
return
|
|
496
|
+
return resolveCssFileImportedByJayHtml(this, importer, config?.root);
|
|
490
497
|
}
|
|
491
498
|
if (source.includes(SANDBOX_ROOT_PREFIX) || jayOptions.isWorker && importer === void 0)
|
|
492
499
|
return await removeSandboxPrefixForWorkerRoot(this, source, importer, options);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jay-framework/rollup-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.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.8.0",
|
|
31
|
+
"@jay-framework/compiler-jay-html": "^0.8.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.8.0",
|
|
37
|
+
"@jay-framework/dev-environment": "^0.8.0",
|
|
38
|
+
"@jay-framework/runtime": "^0.8.0",
|
|
39
|
+
"@jay-framework/secure": "^0.8.0",
|
|
40
40
|
"@types/node": "^20.11.5",
|
|
41
41
|
"rimraf": "^5.0.5",
|
|
42
42
|
"rollup": "^4.9.5",
|