@jay-framework/rollup-plugin 0.6.6 → 0.6.8
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 +4 -3
- package/dist/index.js +180 -130
- package/package.json +9 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { CompiledPattern, FunctionRepositoryBuilder } from '@jay-framework/compiler';
|
|
2
2
|
export * from '@jay-framework/compiler';
|
|
3
3
|
import { LoadResult, TransformResult, CustomPluginOptions, ResolveIdResult } from 'rollup';
|
|
4
|
-
import * as ts from 'typescript';
|
|
5
|
-
import { CompilerOptions } from 'typescript';
|
|
6
4
|
import { GenerateTarget, CompilerSourceFile } from '@jay-framework/compiler-shared';
|
|
5
|
+
import * as ts from 'typescript';
|
|
7
6
|
import { ViteDevServer } from 'vite';
|
|
8
7
|
|
|
9
8
|
declare function jayDefinitions(): {
|
|
@@ -21,7 +20,7 @@ interface ResolveIdOptions {
|
|
|
21
20
|
|
|
22
21
|
interface JayRollupConfig {
|
|
23
22
|
tsConfigFilePath?: string;
|
|
24
|
-
tsCompilerOptionsOverrides?: CompilerOptions;
|
|
23
|
+
tsCompilerOptionsOverrides?: ts.CompilerOptions;
|
|
25
24
|
outputDir?: string;
|
|
26
25
|
isWorker?: boolean;
|
|
27
26
|
compilerPatternFiles?: string[];
|
|
@@ -44,6 +43,8 @@ declare class JayPluginContext {
|
|
|
44
43
|
|
|
45
44
|
declare function jayRuntime(jayOptions?: JayRollupConfig, givenJayContext?: JayPluginContext): {
|
|
46
45
|
name: string;
|
|
46
|
+
configResolved(config: any): void;
|
|
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
|
@@ -1,48 +1,30 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
3
|
var __publicField = (obj, key, value) => {
|
|
5
4
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6
5
|
return value;
|
|
7
6
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
function
|
|
18
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
19
|
-
if (e) {
|
|
20
|
-
for (const k in e) {
|
|
21
|
-
if (k !== "default") {
|
|
22
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
23
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
24
|
-
enumerable: true,
|
|
25
|
-
get: () => e[k]
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
n.default = e;
|
|
31
|
-
return Object.freeze(n);
|
|
32
|
-
}
|
|
33
|
-
const ts__namespace = /* @__PURE__ */ _interopNamespaceDefault(ts);
|
|
34
|
-
function getFileContext(filename, extension = compilerShared.JAY_EXTENSION) {
|
|
7
|
+
import { generateElementDefinitionFile, parseGenericTypescriptFile, generateImportsFileFromJayFile, generateElementFile, transformComponent, transformComponentBridge, compileFunctionSplitPatternsBlock, createTsSourceFileFromSource, FunctionRepositoryBuilder } from "@jay-framework/compiler";
|
|
8
|
+
export * from "@jay-framework/compiler";
|
|
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";
|
|
11
|
+
import { readFile, mkdir } from "node:fs/promises";
|
|
12
|
+
import { writeFile } from "fs/promises";
|
|
13
|
+
import { getJayHtmlImports, parseJayFile, JAY_IMPORT_RESOLVER, parseContract, compileContract, generateSandboxRootFile, generateElementBridgeFile } from "@jay-framework/compiler-jay-html";
|
|
14
|
+
import { createRequire } from "module";
|
|
15
|
+
import fs from "fs";
|
|
16
|
+
function getFileContext(filename, extension = JAY_EXTENSION) {
|
|
35
17
|
return {
|
|
36
18
|
filename: path.basename(filename).replace(extension, ""),
|
|
37
19
|
dirname: path.dirname(filename)
|
|
38
20
|
};
|
|
39
21
|
}
|
|
40
22
|
async function readFileAsString(filePath) {
|
|
41
|
-
return (await
|
|
23
|
+
return (await readFile(filePath)).toString();
|
|
42
24
|
}
|
|
43
25
|
async function writeDefinitionFile(dirname, filename, source, extension) {
|
|
44
26
|
const name = path.resolve(dirname, `${filename}${extension}`);
|
|
45
|
-
await
|
|
27
|
+
await writeFile(name, source, { encoding: "utf8", flag: "w" });
|
|
46
28
|
return name;
|
|
47
29
|
}
|
|
48
30
|
async function writeGeneratedFile(jayContext, context, id, code) {
|
|
@@ -50,8 +32,8 @@ async function writeGeneratedFile(jayContext, context, id, code) {
|
|
|
50
32
|
return;
|
|
51
33
|
const relativePath = path.dirname(path.relative(jayContext.projectRoot, id));
|
|
52
34
|
const filePath = path.resolve(jayContext.outputDir, relativePath, path.basename(id));
|
|
53
|
-
await
|
|
54
|
-
await
|
|
35
|
+
await mkdir(path.dirname(filePath), { recursive: true });
|
|
36
|
+
await writeFile(filePath, code, { encoding: "utf8", flag: "w" });
|
|
55
37
|
console.info(["[transform] written", filePath].join(" "));
|
|
56
38
|
return filePath;
|
|
57
39
|
}
|
|
@@ -65,7 +47,7 @@ function jayDefinitions() {
|
|
|
65
47
|
name: "jay:definitions",
|
|
66
48
|
// this name will show up in warnings and errors
|
|
67
49
|
async load(id) {
|
|
68
|
-
if (
|
|
50
|
+
if (hasExtension(id, JAY_EXTENSION) || hasExtension(id, JAY_CONTRACT_EXTENSION)) {
|
|
69
51
|
const code = await readFileAsString(id);
|
|
70
52
|
checkCodeErrors(code);
|
|
71
53
|
return { code };
|
|
@@ -73,50 +55,52 @@ function jayDefinitions() {
|
|
|
73
55
|
return null;
|
|
74
56
|
},
|
|
75
57
|
async transform(code, id) {
|
|
76
|
-
if (
|
|
58
|
+
if (hasExtension(id, JAY_EXTENSION)) {
|
|
77
59
|
const context = this;
|
|
78
60
|
const { filename, dirname } = getFileContext(id);
|
|
79
|
-
const imports =
|
|
80
|
-
(
|
|
61
|
+
const imports = getJayHtmlImports(code).filter(
|
|
62
|
+
(module) => module.endsWith("jay-html.d")
|
|
81
63
|
);
|
|
82
64
|
await Promise.all(
|
|
83
65
|
imports.map(
|
|
84
66
|
(imported) => context.load({
|
|
85
|
-
id: path.resolve(dirname, imported.slice(0, -2)),
|
|
67
|
+
id: path.resolve(dirname, String(imported).slice(0, -2)),
|
|
86
68
|
resolveDependencies: true
|
|
87
69
|
})
|
|
88
70
|
)
|
|
89
71
|
);
|
|
90
|
-
const parsedFile = await
|
|
72
|
+
const parsedFile = await parseJayFile(
|
|
91
73
|
code,
|
|
92
74
|
filename,
|
|
93
75
|
dirname,
|
|
94
76
|
{},
|
|
95
|
-
|
|
77
|
+
JAY_IMPORT_RESOLVER
|
|
78
|
+
);
|
|
79
|
+
const tsCode = checkValidationErrors(
|
|
80
|
+
generateElementDefinitionFile(parsedFile)
|
|
96
81
|
);
|
|
97
|
-
const tsCode = compilerShared.checkValidationErrors(compiler.generateElementDefinitionFile(parsedFile));
|
|
98
82
|
const generatedFilename = await writeDefinitionFile(
|
|
99
83
|
dirname,
|
|
100
84
|
filename,
|
|
101
85
|
tsCode,
|
|
102
|
-
|
|
86
|
+
JAY_DTS_EXTENSION
|
|
103
87
|
);
|
|
104
88
|
context.info(`[transform] generated ${generatedFilename}`);
|
|
105
89
|
return { code: "", map: null };
|
|
106
|
-
} else if (
|
|
90
|
+
} else if (hasExtension(id, JAY_CONTRACT_EXTENSION)) {
|
|
107
91
|
const context = this;
|
|
108
|
-
const { filename, dirname } = getFileContext(id,
|
|
109
|
-
const parsedFile =
|
|
110
|
-
const tsCode = await
|
|
92
|
+
const { filename, dirname } = getFileContext(id, JAY_CONTRACT_EXTENSION);
|
|
93
|
+
const parsedFile = parseContract(code, filename);
|
|
94
|
+
const tsCode = await compileContract(
|
|
111
95
|
parsedFile,
|
|
112
96
|
`${dirname}/${filename}`,
|
|
113
|
-
|
|
97
|
+
JAY_IMPORT_RESOLVER
|
|
114
98
|
);
|
|
115
99
|
const generatedFilename = await writeDefinitionFile(
|
|
116
100
|
dirname,
|
|
117
101
|
filename,
|
|
118
102
|
tsCode.val,
|
|
119
|
-
|
|
103
|
+
JAY_CONTRACT_DTS_EXTENSION
|
|
120
104
|
);
|
|
121
105
|
context.info(`[transform] generated ${generatedFilename}`);
|
|
122
106
|
return { code: "", map: null };
|
|
@@ -155,16 +139,16 @@ async function getJayFileStructure(jayContext, context, code, id) {
|
|
|
155
139
|
const sourceJayFile = jayContext.getCachedJayFile(meta.originId);
|
|
156
140
|
if (Boolean(sourceJayFile))
|
|
157
141
|
return { meta, jayFile: sourceJayFile };
|
|
158
|
-
const jayFile =
|
|
142
|
+
const jayFile = checkValidationErrors(await getJayFile(jayContext, meta, code));
|
|
159
143
|
jayContext.cacheJayFile(meta.originId, jayFile);
|
|
160
144
|
return { meta, jayFile };
|
|
161
145
|
}
|
|
162
146
|
async function getJayFile(jayContext, meta, code) {
|
|
163
147
|
const { originId: id, format } = meta;
|
|
164
148
|
switch (format) {
|
|
165
|
-
case
|
|
149
|
+
case SourceFileFormat.JayHtml:
|
|
166
150
|
return await getJayStructureFromJayHtmlSource(jayContext, code, id);
|
|
167
|
-
case
|
|
151
|
+
case SourceFileFormat.TypeScript:
|
|
168
152
|
return await getJayStructureFromTypeScriptSource(code, id);
|
|
169
153
|
default:
|
|
170
154
|
throw new Error(`Unknown Jay format ${format}`);
|
|
@@ -172,19 +156,22 @@ async function getJayFile(jayContext, meta, code) {
|
|
|
172
156
|
}
|
|
173
157
|
async function getJayStructureFromJayHtmlSource(jayContext, code, id) {
|
|
174
158
|
const { filename, dirname } = getFileContext(id);
|
|
175
|
-
return await
|
|
159
|
+
return await parseJayFile(
|
|
176
160
|
code,
|
|
177
161
|
filename,
|
|
178
162
|
dirname,
|
|
179
163
|
{
|
|
180
164
|
relativePath: jayContext.jayOptions.tsConfigFilePath
|
|
181
165
|
},
|
|
182
|
-
|
|
166
|
+
JAY_IMPORT_RESOLVER
|
|
183
167
|
);
|
|
184
168
|
}
|
|
185
169
|
async function getJayStructureFromTypeScriptSource(code, id) {
|
|
186
|
-
return await
|
|
170
|
+
return await parseGenericTypescriptFile(id, code);
|
|
187
171
|
}
|
|
172
|
+
const require$1 = createRequire(import.meta.url);
|
|
173
|
+
const tsModule$1 = require$1("typescript");
|
|
174
|
+
const { transform } = tsModule$1;
|
|
188
175
|
function checkDiagnosticsErrors(tsCode) {
|
|
189
176
|
if (tsCode.diagnostics.length > 0) {
|
|
190
177
|
throw new Error(
|
|
@@ -194,21 +181,21 @@ function checkDiagnosticsErrors(tsCode) {
|
|
|
194
181
|
}
|
|
195
182
|
async function generateCodeFromStructure(jayContext, context, code, id, meta, jayFile) {
|
|
196
183
|
const { format } = meta;
|
|
197
|
-
const mode =
|
|
198
|
-
const generationTarget = jayContext.jayOptions.generationTarget ||
|
|
199
|
-
const tsCode = format ===
|
|
184
|
+
const mode = getModeFromExtension(id);
|
|
185
|
+
const generationTarget = jayContext.jayOptions.generationTarget || GenerateTarget.jay;
|
|
186
|
+
const tsCode = format === SourceFileFormat.JayHtml ? generateCodeFromJayHtmlFile(mode, jayFile, generationTarget) : generateCodeFromTsFile(jayContext, mode, jayFile, id, code);
|
|
200
187
|
await writeGeneratedFile(jayContext, context, id, tsCode);
|
|
201
188
|
return tsCode;
|
|
202
189
|
}
|
|
203
190
|
function generateCodeFromJayHtmlFile(mode, jayFile, generationTarget) {
|
|
204
191
|
switch (mode) {
|
|
205
|
-
case
|
|
206
|
-
case
|
|
207
|
-
return
|
|
208
|
-
case
|
|
209
|
-
return
|
|
210
|
-
case
|
|
211
|
-
return hasSandboxImport(jayFile) ?
|
|
192
|
+
case RuntimeMode.MainTrusted:
|
|
193
|
+
case RuntimeMode.MainSandbox:
|
|
194
|
+
return checkValidationErrors(generateElementFile(jayFile, mode, generationTarget));
|
|
195
|
+
case RuntimeMode.WorkerSandbox:
|
|
196
|
+
return generateElementBridgeFile(jayFile);
|
|
197
|
+
case RuntimeMode.WorkerTrusted:
|
|
198
|
+
return hasSandboxImport(jayFile) ? generateSandboxRootFile(jayFile) : generateImportsFileFromJayFile(jayFile);
|
|
212
199
|
}
|
|
213
200
|
}
|
|
214
201
|
function hasSandboxImport(jayFile) {
|
|
@@ -216,15 +203,15 @@ function hasSandboxImport(jayFile) {
|
|
|
216
203
|
}
|
|
217
204
|
function generateCodeFromTsFile(jayContext, mode, jayFile, id, code) {
|
|
218
205
|
switch (mode) {
|
|
219
|
-
case
|
|
206
|
+
case RuntimeMode.MainTrusted:
|
|
220
207
|
return code;
|
|
221
|
-
case
|
|
208
|
+
case RuntimeMode.MainSandbox: {
|
|
222
209
|
if (!code.includes("makeJayComponent"))
|
|
223
210
|
return code;
|
|
224
211
|
return transformTsCode(
|
|
225
212
|
jayContext,
|
|
226
213
|
[
|
|
227
|
-
|
|
214
|
+
transformComponentBridge(
|
|
228
215
|
mode,
|
|
229
216
|
jayContext.compilerPatterns,
|
|
230
217
|
jayContext.globalFunctionsRepository
|
|
@@ -234,13 +221,13 @@ function generateCodeFromTsFile(jayContext, mode, jayFile, id, code) {
|
|
|
234
221
|
code
|
|
235
222
|
);
|
|
236
223
|
}
|
|
237
|
-
case
|
|
238
|
-
return
|
|
239
|
-
case
|
|
224
|
+
case RuntimeMode.WorkerTrusted:
|
|
225
|
+
return generateImportsFileFromJayFile(jayFile);
|
|
226
|
+
case RuntimeMode.WorkerSandbox:
|
|
240
227
|
return transformTsCode(
|
|
241
228
|
jayContext,
|
|
242
229
|
[
|
|
243
|
-
|
|
230
|
+
transformComponent(
|
|
244
231
|
jayContext.compilerPatterns,
|
|
245
232
|
jayContext.globalFunctionsRepository
|
|
246
233
|
)
|
|
@@ -251,11 +238,17 @@ function generateCodeFromTsFile(jayContext, mode, jayFile, id, code) {
|
|
|
251
238
|
}
|
|
252
239
|
}
|
|
253
240
|
function transformTsCode(jayContext, transformers, id, code) {
|
|
254
|
-
const tsSource =
|
|
255
|
-
|
|
241
|
+
const tsSource = tsModule$1.createSourceFile(
|
|
242
|
+
id,
|
|
243
|
+
code,
|
|
244
|
+
tsModule$1.ScriptTarget.Latest,
|
|
245
|
+
true,
|
|
246
|
+
tsModule$1.ScriptKind.TS
|
|
247
|
+
);
|
|
248
|
+
const tsCode = transform(tsSource, transformers);
|
|
256
249
|
checkDiagnosticsErrors(tsCode);
|
|
257
250
|
const outputCode = jayContext.tsPrinter.printNode(
|
|
258
|
-
|
|
251
|
+
tsModule$1.EmitHint.Unspecified,
|
|
259
252
|
tsCode.transformed[0],
|
|
260
253
|
tsSource
|
|
261
254
|
);
|
|
@@ -264,7 +257,7 @@ function transformTsCode(jayContext, transformers, id, code) {
|
|
|
264
257
|
async function transformJayFile(jayContext, context, code, id) {
|
|
265
258
|
if (!Boolean(getJayMetadata(context, id).originId))
|
|
266
259
|
return null;
|
|
267
|
-
const mode =
|
|
260
|
+
const mode = getModeFromExtension(id);
|
|
268
261
|
console.info(`[transform] start ${mode} ${id}`);
|
|
269
262
|
const { meta, jayFile } = await getJayFileStructure(jayContext, context, code, id);
|
|
270
263
|
const tsCode = await generateCodeFromStructure(jayContext, context, code, id, meta, jayFile);
|
|
@@ -277,12 +270,57 @@ function watchChangesFor(context, sourcePath) {
|
|
|
277
270
|
context.addWatchFile(sourcePath);
|
|
278
271
|
console.info(`[watch] add ${sourcePath}`);
|
|
279
272
|
}
|
|
280
|
-
|
|
273
|
+
function stripTSExtension(id) {
|
|
274
|
+
return id.replace(TS_EXTENSION, "").replace(TSX_EXTENSION, "");
|
|
275
|
+
}
|
|
276
|
+
async function loadJayFile(context, id) {
|
|
277
|
+
console.info(`[load] start ${id}`);
|
|
278
|
+
let { originId } = getJayMetadata(context, id);
|
|
279
|
+
if (!Boolean(originId))
|
|
280
|
+
originId = stripTSExtension(id);
|
|
281
|
+
const code = checkCodeErrors(await readFileAsString(originId));
|
|
282
|
+
console.info(`[load] end ${id}`);
|
|
283
|
+
return { code };
|
|
284
|
+
}
|
|
285
|
+
async function loadContractFile(context, id) {
|
|
286
|
+
console.info(`[load] start ${id}`);
|
|
287
|
+
let { originId } = getJayMetadata(context, id);
|
|
288
|
+
if (!Boolean(originId))
|
|
289
|
+
originId = stripTSExtension(id);
|
|
290
|
+
const code = await readFileAsString(originId);
|
|
291
|
+
console.info(`[load] end ${id}`);
|
|
292
|
+
return { code };
|
|
293
|
+
}
|
|
294
|
+
async function loadCssFile(context, jayContext, id, isVite) {
|
|
295
|
+
if (isVite) {
|
|
296
|
+
console.info(`[load] start ${id}`);
|
|
297
|
+
const { originId } = getJayMetadata(context, id);
|
|
298
|
+
const code = checkCodeErrors(await readFileAsString(originId));
|
|
299
|
+
const fileName = path.basename(originId);
|
|
300
|
+
const dirName = path.dirname(originId);
|
|
301
|
+
const jayHtml = await parseJayFile(
|
|
302
|
+
code,
|
|
303
|
+
fileName,
|
|
304
|
+
dirName,
|
|
305
|
+
{
|
|
306
|
+
relativePath: jayContext.jayOptions.tsConfigFilePath
|
|
307
|
+
},
|
|
308
|
+
JAY_IMPORT_RESOLVER
|
|
309
|
+
);
|
|
310
|
+
console.info(`[load] end ${id}`);
|
|
311
|
+
return { code: jayHtml.val.css };
|
|
312
|
+
} else {
|
|
313
|
+
console.info(`[load] rollup environment - css not supported - ignoring css ${id}`);
|
|
314
|
+
return { code: "" };
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
const JAY_HTML_CSS = ".css";
|
|
318
|
+
async function resolveJayHtml(context, source, importer, options, generationTarget = GenerateTarget.jay) {
|
|
281
319
|
const resolved = await context.resolve(source, importer, { ...options, skipSelf: true });
|
|
282
|
-
if (!resolved ||
|
|
320
|
+
if (!resolved || hasExtension(resolved.id, TS_EXTENSION) || hasExtension(resolved.id, TSX_EXTENSION))
|
|
283
321
|
return null;
|
|
284
322
|
const resolvedJayMeta = jayMetadataFromModuleMetadata(resolved.id, resolved.meta);
|
|
285
|
-
const extension = generationTarget ===
|
|
323
|
+
const extension = generationTarget === GenerateTarget.react ? TSX_EXTENSION : TS_EXTENSION;
|
|
286
324
|
if (resolvedJayMeta.originId) {
|
|
287
325
|
const { format, originId } = resolvedJayMeta;
|
|
288
326
|
const id = `${originId}${extension}`;
|
|
@@ -290,7 +328,7 @@ async function resolveJayHtml(context, source, importer, options, generationTarg
|
|
|
290
328
|
return { id, meta: appendJayMetadata(context, id, { format, originId }) };
|
|
291
329
|
} else {
|
|
292
330
|
watchChangesFor(context, resolved.id);
|
|
293
|
-
const format =
|
|
331
|
+
const format = SourceFileFormat.JayHtml;
|
|
294
332
|
const originId = resolved.id;
|
|
295
333
|
const id = `${originId}${extension}`;
|
|
296
334
|
console.info(`[resolveId] resolved ${id} as ${format}`);
|
|
@@ -299,12 +337,12 @@ async function resolveJayHtml(context, source, importer, options, generationTarg
|
|
|
299
337
|
}
|
|
300
338
|
async function resolveJayContract(context, source, importer, options) {
|
|
301
339
|
const resolved = await context.resolve(source, importer, { ...options, skipSelf: true });
|
|
302
|
-
const id = `${resolved.id}${
|
|
340
|
+
const id = `${resolved.id}${TS_EXTENSION}`;
|
|
303
341
|
console.info(`[resolveId] resolved ${id}`);
|
|
304
342
|
return {
|
|
305
343
|
id,
|
|
306
344
|
meta: appendJayMetadata(context, id, {
|
|
307
|
-
format:
|
|
345
|
+
format: SourceFileFormat.JayContract,
|
|
308
346
|
originId: resolved.id
|
|
309
347
|
})
|
|
310
348
|
};
|
|
@@ -320,7 +358,7 @@ async function resolveJayModeFile(context, source, importer, options) {
|
|
|
320
358
|
if (!resolved)
|
|
321
359
|
return null;
|
|
322
360
|
const resolvedJayMeta = jayMetadataFromModuleMetadata(resolved.id, resolved.meta);
|
|
323
|
-
const format = resolvedJayMeta.format ||
|
|
361
|
+
const format = resolvedJayMeta.format || SourceFileFormat.TypeScript;
|
|
324
362
|
const originId = resolvedJayMeta.originId || resolved.id;
|
|
325
363
|
const id = getResolvedId(resolved, mode, originId);
|
|
326
364
|
console.info(`[resolveId] resolved ${id} as ${format}`);
|
|
@@ -334,14 +372,14 @@ async function removeSandboxPrefixForWorkerRoot(context, source, importer, optio
|
|
|
334
372
|
});
|
|
335
373
|
if (!resolved)
|
|
336
374
|
return null;
|
|
337
|
-
const id = `${resolved.id}${
|
|
375
|
+
const id = `${resolved.id}${JAY_QUERY_WORKER_TRUSTED_TS}`;
|
|
338
376
|
const originId = id.split("?")[0];
|
|
339
377
|
console.info(`[resolveId] resolved sandbox root ${id}`);
|
|
340
378
|
return {
|
|
341
379
|
id,
|
|
342
380
|
meta: appendJayMetadata(context, id, {
|
|
343
381
|
originId,
|
|
344
|
-
format:
|
|
382
|
+
format: SourceFileFormat.TypeScript,
|
|
345
383
|
isWorkerRoot: true
|
|
346
384
|
})
|
|
347
385
|
};
|
|
@@ -351,27 +389,27 @@ function getResolvedId(resolved, mode, originId) {
|
|
|
351
389
|
const id = `${originId}?${mode}.${extension}`;
|
|
352
390
|
return id;
|
|
353
391
|
}
|
|
354
|
-
function
|
|
355
|
-
return
|
|
392
|
+
function hasCssImportedByJayHtml(source, importer) {
|
|
393
|
+
return hasExtension(source, CSS_EXTENSION) && importer && (hasExtension(importer, JAY_EXTENSION, { withTs: true }) || hasExtension(importer, JAY_EXTENSION + JAY_QUERY_MAIN_SANDBOX, { withTs: true }));
|
|
356
394
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
395
|
+
function resolveCssFile(context, importer) {
|
|
396
|
+
const originImporter = importer.split("?")[0];
|
|
397
|
+
const originId = stripTSExtension(originImporter);
|
|
398
|
+
const id = `${originId}${JAY_HTML_CSS}`;
|
|
399
|
+
return {
|
|
400
|
+
id,
|
|
401
|
+
meta: appendJayMetadata(context, id, {
|
|
402
|
+
format: SourceFileFormat.CSS,
|
|
403
|
+
originId
|
|
404
|
+
})
|
|
405
|
+
};
|
|
365
406
|
}
|
|
366
|
-
|
|
367
|
-
|
|
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 };
|
|
407
|
+
function isResolvedCssFile(id) {
|
|
408
|
+
return id.endsWith(JAY_HTML_CSS) && id.indexOf(JAY_EXTENSION) > 0;
|
|
374
409
|
}
|
|
410
|
+
const require2 = createRequire(import.meta.url);
|
|
411
|
+
const tsModule = require2("typescript");
|
|
412
|
+
const { NewLineKind } = tsModule;
|
|
375
413
|
class JayPluginContext {
|
|
376
414
|
constructor(jayOptions = {}) {
|
|
377
415
|
__publicField(this, "projectRoot");
|
|
@@ -383,11 +421,11 @@ class JayPluginContext {
|
|
|
383
421
|
this.jayOptions = jayOptions;
|
|
384
422
|
this.projectRoot = path.dirname(jayOptions.tsConfigFilePath ?? process.cwd());
|
|
385
423
|
this.outputDir = jayOptions.outputDir && path.join(this.projectRoot, jayOptions.outputDir);
|
|
386
|
-
this.tsPrinter =
|
|
387
|
-
let compilerPatternsParseResult =
|
|
424
|
+
this.tsPrinter = tsModule.createPrinter({ newLine: NewLineKind.LineFeed });
|
|
425
|
+
let compilerPatternsParseResult = compileFunctionSplitPatternsBlock(
|
|
388
426
|
(jayOptions.compilerPatternFiles || []).map((fileName) => {
|
|
389
427
|
let fileContent = fs.readFileSync(fileName, { encoding: "utf8" });
|
|
390
|
-
return
|
|
428
|
+
return createTsSourceFileFromSource(fileName, fileContent);
|
|
391
429
|
})
|
|
392
430
|
);
|
|
393
431
|
if (compilerPatternsParseResult.validations.length > 0)
|
|
@@ -395,7 +433,7 @@ class JayPluginContext {
|
|
|
395
433
|
"failed to parse or validate compilerPatternFiles. \n" + compilerPatternsParseResult.validations.join("\n")
|
|
396
434
|
);
|
|
397
435
|
this.compilerPatterns = compilerPatternsParseResult.val;
|
|
398
|
-
this.globalFunctionsRepository = new
|
|
436
|
+
this.globalFunctionsRepository = new FunctionRepositoryBuilder();
|
|
399
437
|
}
|
|
400
438
|
cacheJayFile(id, jayFile) {
|
|
401
439
|
console.info("[cache] set", id);
|
|
@@ -417,13 +455,25 @@ const GLOBAL_FUNC_REPOSITORY = "GLOBAL_FUNC_REPOSITORY.ts";
|
|
|
417
455
|
function jayRuntime(jayOptions = {}, givenJayContext) {
|
|
418
456
|
const jayContext = givenJayContext || new JayPluginContext(jayOptions);
|
|
419
457
|
let server;
|
|
458
|
+
let isVite = false;
|
|
420
459
|
return {
|
|
421
460
|
name: "jay:runtime",
|
|
461
|
+
configResolved(config) {
|
|
462
|
+
isVite = true;
|
|
463
|
+
},
|
|
464
|
+
buildStart(opts) {
|
|
465
|
+
isVite = isVite || Boolean(
|
|
466
|
+
opts.plugins?.some(
|
|
467
|
+
(plugin) => plugin.name === "vite:build-metadata" || plugin.name?.startsWith("vite:")
|
|
468
|
+
)
|
|
469
|
+
);
|
|
470
|
+
console.log("[buildStart] Vite detected:", isVite);
|
|
471
|
+
},
|
|
422
472
|
configureServer(_server) {
|
|
423
473
|
server = _server;
|
|
424
474
|
},
|
|
425
475
|
async resolveId(source, importer, options) {
|
|
426
|
-
if (
|
|
476
|
+
if (hasExtension(source, JAY_EXTENSION))
|
|
427
477
|
return await resolveJayHtml(
|
|
428
478
|
this,
|
|
429
479
|
source,
|
|
@@ -431,21 +481,26 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
|
|
|
431
481
|
options,
|
|
432
482
|
jayOptions.generationTarget
|
|
433
483
|
);
|
|
434
|
-
if (
|
|
484
|
+
if (hasExtension(source, JAY_CONTRACT_EXTENSION))
|
|
435
485
|
return await resolveJayContract(this, source, importer, options);
|
|
436
|
-
if (
|
|
486
|
+
if (hasJayModeExtension(source))
|
|
437
487
|
return await resolveJayModeFile(this, source, importer, options);
|
|
488
|
+
if (hasCssImportedByJayHtml(source, importer)) {
|
|
489
|
+
return resolveCssFile(this, importer);
|
|
490
|
+
}
|
|
438
491
|
if (source.includes(SANDBOX_ROOT_PREFIX) || jayOptions.isWorker && importer === void 0)
|
|
439
492
|
return await removeSandboxPrefixForWorkerRoot(this, source, importer, options);
|
|
440
|
-
if (source ===
|
|
493
|
+
if (source === Import.functionRepository.module)
|
|
441
494
|
return Promise.resolve(GLOBAL_FUNC_REPOSITORY);
|
|
442
495
|
return null;
|
|
443
496
|
},
|
|
444
497
|
async load(id) {
|
|
445
|
-
if (
|
|
498
|
+
if (hasExtension(id, JAY_EXTENSION, { withTs: true }) || hasJayModeExtension(id, { withTs: true })) {
|
|
446
499
|
return await loadJayFile(this, id);
|
|
447
|
-
else if (
|
|
500
|
+
} else if (hasExtension(id, JAY_CONTRACT_EXTENSION, { withTs: true })) {
|
|
448
501
|
return await loadContractFile(this, id);
|
|
502
|
+
} else if (isResolvedCssFile(id)) {
|
|
503
|
+
return await loadCssFile(this, jayContext, id, isVite);
|
|
449
504
|
} else if (id === GLOBAL_FUNC_REPOSITORY) {
|
|
450
505
|
const { functionRepository } = jayContext.globalFunctionsRepository.generateGlobalFile();
|
|
451
506
|
return functionRepository;
|
|
@@ -453,15 +508,15 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
|
|
|
453
508
|
return null;
|
|
454
509
|
},
|
|
455
510
|
async transform(code, id) {
|
|
456
|
-
if (
|
|
511
|
+
if (hasExtension(id, JAY_EXTENSION, { withTs: true }) || hasJayModeExtension(id, { withTs: true }))
|
|
457
512
|
return await transformJayFile(jayContext, this, code, id);
|
|
458
|
-
else if (
|
|
459
|
-
const { filename, dirname } = getFileContext(id,
|
|
460
|
-
const parsedFile =
|
|
461
|
-
const tsCode = await
|
|
513
|
+
else if (hasExtension(id, JAY_CONTRACT_EXTENSION, { withTs: true })) {
|
|
514
|
+
const { filename, dirname } = getFileContext(id, JAY_CONTRACT_EXTENSION);
|
|
515
|
+
const parsedFile = parseContract(code, filename);
|
|
516
|
+
const tsCode = await compileContract(
|
|
462
517
|
parsedFile,
|
|
463
518
|
`${dirname}/${filename}`,
|
|
464
|
-
|
|
519
|
+
JAY_IMPORT_RESOLVER
|
|
465
520
|
);
|
|
466
521
|
if (tsCode.val)
|
|
467
522
|
return Promise.resolve({
|
|
@@ -476,9 +531,9 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
|
|
|
476
531
|
console.log(`[watchChange] ${id} ${change.event}`);
|
|
477
532
|
jayContext.deleteCachedJayFile(id);
|
|
478
533
|
if (server) {
|
|
479
|
-
const
|
|
480
|
-
if (
|
|
481
|
-
server.moduleGraph.invalidateModule(
|
|
534
|
+
const module = server.moduleGraph.getModuleById(id + TS_EXTENSION);
|
|
535
|
+
if (module) {
|
|
536
|
+
server.moduleGraph.invalidateModule(module);
|
|
482
537
|
server.ws.send({
|
|
483
538
|
type: "full-reload"
|
|
484
539
|
});
|
|
@@ -487,13 +542,8 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
|
|
|
487
542
|
}
|
|
488
543
|
};
|
|
489
544
|
}
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
Object.defineProperty(exports, k, {
|
|
496
|
-
enumerable: true,
|
|
497
|
-
get: () => compiler[k]
|
|
498
|
-
});
|
|
499
|
-
});
|
|
545
|
+
export {
|
|
546
|
+
JayPluginContext,
|
|
547
|
+
jayDefinitions,
|
|
548
|
+
jayRuntime
|
|
549
|
+
};
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jay-framework/rollup-plugin",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.8",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"keywords": [
|
|
7
8
|
"jay",
|
|
8
9
|
"secure",
|
|
@@ -17,7 +18,7 @@
|
|
|
17
18
|
"build:watch": "npm run build:js -- --watch & npm run build:types -- --watch",
|
|
18
19
|
"build:watch:sandbox-counter": "vite -c test/jayRuntime/fixtures/counter/source/vite.config.ts",
|
|
19
20
|
"build:js": "vite build",
|
|
20
|
-
"build:types": "tsup lib/index.ts --dts-only --format
|
|
21
|
+
"build:types": "tsup lib/index.ts --dts-only --format esm",
|
|
21
22
|
"build:check-types": "tsc",
|
|
22
23
|
"build:executable-bin": "chmod +x dist/index.js",
|
|
23
24
|
"clean": "rimraf dist && rimraf test/jayRuntime/fixtures/counter/dist && rimraf test/jayRuntime/fixtures/exec/dist",
|
|
@@ -26,16 +27,16 @@
|
|
|
26
27
|
"test:watch": "vitest"
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|
|
29
|
-
"@jay-framework/compiler": "^0.6.
|
|
30
|
-
"@jay-framework/compiler-jay-html": "^0.6.
|
|
30
|
+
"@jay-framework/compiler": "^0.6.8",
|
|
31
|
+
"@jay-framework/compiler-jay-html": "^0.6.8",
|
|
31
32
|
"fast-glob": "^3.3.2",
|
|
32
33
|
"typescript": "^5.3.3"
|
|
33
34
|
},
|
|
34
35
|
"devDependencies": {
|
|
35
|
-
"@jay-framework/component": "^0.6.
|
|
36
|
-
"@jay-framework/dev-environment": "^0.6.
|
|
37
|
-
"@jay-framework/runtime": "^0.6.
|
|
38
|
-
"@jay-framework/secure": "^0.6.
|
|
36
|
+
"@jay-framework/component": "^0.6.8",
|
|
37
|
+
"@jay-framework/dev-environment": "^0.6.8",
|
|
38
|
+
"@jay-framework/runtime": "^0.6.8",
|
|
39
|
+
"@jay-framework/secure": "^0.6.8",
|
|
39
40
|
"@types/node": "^20.11.5",
|
|
40
41
|
"rimraf": "^5.0.5",
|
|
41
42
|
"rollup": "^4.9.5",
|