@jay-framework/rollup-plugin 0.6.7 → 0.6.9
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 +3 -3
- package/dist/index.js +117 -121
- 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,7 @@ declare class JayPluginContext {
|
|
|
44
43
|
|
|
45
44
|
declare function jayRuntime(jayOptions?: JayRollupConfig, givenJayContext?: JayPluginContext): {
|
|
46
45
|
name: string;
|
|
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
|
@@ -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);
|
|
@@ -278,7 +271,7 @@ function watchChangesFor(context, sourcePath) {
|
|
|
278
271
|
console.info(`[watch] add ${sourcePath}`);
|
|
279
272
|
}
|
|
280
273
|
function stripTSExtension(id) {
|
|
281
|
-
return id.replace(
|
|
274
|
+
return id.replace(TS_EXTENSION, "").replace(TSX_EXTENSION, "");
|
|
282
275
|
}
|
|
283
276
|
async function loadJayFile(context, id) {
|
|
284
277
|
console.info(`[load] start ${id}`);
|
|
@@ -305,14 +298,14 @@ async function loadCssFile(context, jayContext, id, isVite) {
|
|
|
305
298
|
const code = checkCodeErrors(await readFileAsString(originId));
|
|
306
299
|
const fileName = path.basename(originId);
|
|
307
300
|
const dirName = path.dirname(originId);
|
|
308
|
-
const jayHtml = await
|
|
301
|
+
const jayHtml = await parseJayFile(
|
|
309
302
|
code,
|
|
310
303
|
fileName,
|
|
311
304
|
dirName,
|
|
312
305
|
{
|
|
313
306
|
relativePath: jayContext.jayOptions.tsConfigFilePath
|
|
314
307
|
},
|
|
315
|
-
|
|
308
|
+
JAY_IMPORT_RESOLVER
|
|
316
309
|
);
|
|
317
310
|
console.info(`[load] end ${id}`);
|
|
318
311
|
return { code: jayHtml.val.css };
|
|
@@ -322,12 +315,12 @@ async function loadCssFile(context, jayContext, id, isVite) {
|
|
|
322
315
|
}
|
|
323
316
|
}
|
|
324
317
|
const JAY_HTML_CSS = ".css";
|
|
325
|
-
async function resolveJayHtml(context, source, importer, options, generationTarget =
|
|
318
|
+
async function resolveJayHtml(context, source, importer, options, generationTarget = GenerateTarget.jay) {
|
|
326
319
|
const resolved = await context.resolve(source, importer, { ...options, skipSelf: true });
|
|
327
|
-
if (!resolved ||
|
|
320
|
+
if (!resolved || hasExtension(resolved.id, TS_EXTENSION) || hasExtension(resolved.id, TSX_EXTENSION))
|
|
328
321
|
return null;
|
|
329
322
|
const resolvedJayMeta = jayMetadataFromModuleMetadata(resolved.id, resolved.meta);
|
|
330
|
-
const extension = generationTarget ===
|
|
323
|
+
const extension = generationTarget === GenerateTarget.react ? TSX_EXTENSION : TS_EXTENSION;
|
|
331
324
|
if (resolvedJayMeta.originId) {
|
|
332
325
|
const { format, originId } = resolvedJayMeta;
|
|
333
326
|
const id = `${originId}${extension}`;
|
|
@@ -335,7 +328,7 @@ async function resolveJayHtml(context, source, importer, options, generationTarg
|
|
|
335
328
|
return { id, meta: appendJayMetadata(context, id, { format, originId }) };
|
|
336
329
|
} else {
|
|
337
330
|
watchChangesFor(context, resolved.id);
|
|
338
|
-
const format =
|
|
331
|
+
const format = SourceFileFormat.JayHtml;
|
|
339
332
|
const originId = resolved.id;
|
|
340
333
|
const id = `${originId}${extension}`;
|
|
341
334
|
console.info(`[resolveId] resolved ${id} as ${format}`);
|
|
@@ -344,12 +337,12 @@ async function resolveJayHtml(context, source, importer, options, generationTarg
|
|
|
344
337
|
}
|
|
345
338
|
async function resolveJayContract(context, source, importer, options) {
|
|
346
339
|
const resolved = await context.resolve(source, importer, { ...options, skipSelf: true });
|
|
347
|
-
const id = `${resolved.id}${
|
|
340
|
+
const id = `${resolved.id}${TS_EXTENSION}`;
|
|
348
341
|
console.info(`[resolveId] resolved ${id}`);
|
|
349
342
|
return {
|
|
350
343
|
id,
|
|
351
344
|
meta: appendJayMetadata(context, id, {
|
|
352
|
-
format:
|
|
345
|
+
format: SourceFileFormat.JayContract,
|
|
353
346
|
originId: resolved.id
|
|
354
347
|
})
|
|
355
348
|
};
|
|
@@ -365,7 +358,7 @@ async function resolveJayModeFile(context, source, importer, options) {
|
|
|
365
358
|
if (!resolved)
|
|
366
359
|
return null;
|
|
367
360
|
const resolvedJayMeta = jayMetadataFromModuleMetadata(resolved.id, resolved.meta);
|
|
368
|
-
const format = resolvedJayMeta.format ||
|
|
361
|
+
const format = resolvedJayMeta.format || SourceFileFormat.TypeScript;
|
|
369
362
|
const originId = resolvedJayMeta.originId || resolved.id;
|
|
370
363
|
const id = getResolvedId(resolved, mode, originId);
|
|
371
364
|
console.info(`[resolveId] resolved ${id} as ${format}`);
|
|
@@ -379,14 +372,14 @@ async function removeSandboxPrefixForWorkerRoot(context, source, importer, optio
|
|
|
379
372
|
});
|
|
380
373
|
if (!resolved)
|
|
381
374
|
return null;
|
|
382
|
-
const id = `${resolved.id}${
|
|
375
|
+
const id = `${resolved.id}${JAY_QUERY_WORKER_TRUSTED_TS}`;
|
|
383
376
|
const originId = id.split("?")[0];
|
|
384
377
|
console.info(`[resolveId] resolved sandbox root ${id}`);
|
|
385
378
|
return {
|
|
386
379
|
id,
|
|
387
380
|
meta: appendJayMetadata(context, id, {
|
|
388
381
|
originId,
|
|
389
|
-
format:
|
|
382
|
+
format: SourceFileFormat.TypeScript,
|
|
390
383
|
isWorkerRoot: true
|
|
391
384
|
})
|
|
392
385
|
};
|
|
@@ -397,7 +390,7 @@ function getResolvedId(resolved, mode, originId) {
|
|
|
397
390
|
return id;
|
|
398
391
|
}
|
|
399
392
|
function hasCssImportedByJayHtml(source, importer) {
|
|
400
|
-
return
|
|
393
|
+
return hasExtension(source, CSS_EXTENSION) && importer && (hasExtension(importer, JAY_EXTENSION, { withTs: true }) || hasExtension(importer, JAY_EXTENSION + JAY_QUERY_MAIN_SANDBOX, { withTs: true }));
|
|
401
394
|
}
|
|
402
395
|
function resolveCssFile(context, importer) {
|
|
403
396
|
const originImporter = importer.split("?")[0];
|
|
@@ -406,14 +399,17 @@ function resolveCssFile(context, importer) {
|
|
|
406
399
|
return {
|
|
407
400
|
id,
|
|
408
401
|
meta: appendJayMetadata(context, id, {
|
|
409
|
-
format:
|
|
402
|
+
format: SourceFileFormat.CSS,
|
|
410
403
|
originId
|
|
411
404
|
})
|
|
412
405
|
};
|
|
413
406
|
}
|
|
414
407
|
function isResolvedCssFile(id) {
|
|
415
|
-
return id.endsWith(JAY_HTML_CSS) && id.indexOf(
|
|
408
|
+
return id.endsWith(JAY_HTML_CSS) && id.indexOf(JAY_EXTENSION) > 0;
|
|
416
409
|
}
|
|
410
|
+
const require2 = createRequire(import.meta.url);
|
|
411
|
+
const tsModule = require2("typescript");
|
|
412
|
+
const { NewLineKind } = tsModule;
|
|
417
413
|
class JayPluginContext {
|
|
418
414
|
constructor(jayOptions = {}) {
|
|
419
415
|
__publicField(this, "projectRoot");
|
|
@@ -425,11 +421,11 @@ class JayPluginContext {
|
|
|
425
421
|
this.jayOptions = jayOptions;
|
|
426
422
|
this.projectRoot = path.dirname(jayOptions.tsConfigFilePath ?? process.cwd());
|
|
427
423
|
this.outputDir = jayOptions.outputDir && path.join(this.projectRoot, jayOptions.outputDir);
|
|
428
|
-
this.tsPrinter =
|
|
429
|
-
let compilerPatternsParseResult =
|
|
424
|
+
this.tsPrinter = tsModule.createPrinter({ newLine: NewLineKind.LineFeed });
|
|
425
|
+
let compilerPatternsParseResult = compileFunctionSplitPatternsBlock(
|
|
430
426
|
(jayOptions.compilerPatternFiles || []).map((fileName) => {
|
|
431
427
|
let fileContent = fs.readFileSync(fileName, { encoding: "utf8" });
|
|
432
|
-
return
|
|
428
|
+
return createTsSourceFileFromSource(fileName, fileContent);
|
|
433
429
|
})
|
|
434
430
|
);
|
|
435
431
|
if (compilerPatternsParseResult.validations.length > 0)
|
|
@@ -437,7 +433,7 @@ class JayPluginContext {
|
|
|
437
433
|
"failed to parse or validate compilerPatternFiles. \n" + compilerPatternsParseResult.validations.join("\n")
|
|
438
434
|
);
|
|
439
435
|
this.compilerPatterns = compilerPatternsParseResult.val;
|
|
440
|
-
this.globalFunctionsRepository = new
|
|
436
|
+
this.globalFunctionsRepository = new FunctionRepositoryBuilder();
|
|
441
437
|
}
|
|
442
438
|
cacheJayFile(id, jayFile) {
|
|
443
439
|
console.info("[cache] set", id);
|
|
@@ -462,17 +458,22 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
|
|
|
462
458
|
let isVite = false;
|
|
463
459
|
return {
|
|
464
460
|
name: "jay:runtime",
|
|
461
|
+
configResolved(config) {
|
|
462
|
+
isVite = true;
|
|
463
|
+
},
|
|
465
464
|
buildStart(opts) {
|
|
466
|
-
isVite = Boolean(
|
|
467
|
-
|
|
468
|
-
|
|
465
|
+
isVite = isVite || Boolean(
|
|
466
|
+
opts.plugins?.some(
|
|
467
|
+
(plugin) => plugin.name === "vite:build-metadata" || plugin.name?.startsWith("vite:")
|
|
468
|
+
)
|
|
469
|
+
);
|
|
469
470
|
console.log("[buildStart] Vite detected:", isVite);
|
|
470
471
|
},
|
|
471
472
|
configureServer(_server) {
|
|
472
473
|
server = _server;
|
|
473
474
|
},
|
|
474
475
|
async resolveId(source, importer, options) {
|
|
475
|
-
if (
|
|
476
|
+
if (hasExtension(source, JAY_EXTENSION))
|
|
476
477
|
return await resolveJayHtml(
|
|
477
478
|
this,
|
|
478
479
|
source,
|
|
@@ -480,23 +481,23 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
|
|
|
480
481
|
options,
|
|
481
482
|
jayOptions.generationTarget
|
|
482
483
|
);
|
|
483
|
-
if (
|
|
484
|
+
if (hasExtension(source, JAY_CONTRACT_EXTENSION))
|
|
484
485
|
return await resolveJayContract(this, source, importer, options);
|
|
485
|
-
if (
|
|
486
|
+
if (hasJayModeExtension(source))
|
|
486
487
|
return await resolveJayModeFile(this, source, importer, options);
|
|
487
488
|
if (hasCssImportedByJayHtml(source, importer)) {
|
|
488
489
|
return resolveCssFile(this, importer);
|
|
489
490
|
}
|
|
490
491
|
if (source.includes(SANDBOX_ROOT_PREFIX) || jayOptions.isWorker && importer === void 0)
|
|
491
492
|
return await removeSandboxPrefixForWorkerRoot(this, source, importer, options);
|
|
492
|
-
if (source ===
|
|
493
|
+
if (source === Import.functionRepository.module)
|
|
493
494
|
return Promise.resolve(GLOBAL_FUNC_REPOSITORY);
|
|
494
495
|
return null;
|
|
495
496
|
},
|
|
496
497
|
async load(id) {
|
|
497
|
-
if (
|
|
498
|
+
if (hasExtension(id, JAY_EXTENSION, { withTs: true }) || hasJayModeExtension(id, { withTs: true })) {
|
|
498
499
|
return await loadJayFile(this, id);
|
|
499
|
-
} else if (
|
|
500
|
+
} else if (hasExtension(id, JAY_CONTRACT_EXTENSION, { withTs: true })) {
|
|
500
501
|
return await loadContractFile(this, id);
|
|
501
502
|
} else if (isResolvedCssFile(id)) {
|
|
502
503
|
return await loadCssFile(this, jayContext, id, isVite);
|
|
@@ -507,15 +508,15 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
|
|
|
507
508
|
return null;
|
|
508
509
|
},
|
|
509
510
|
async transform(code, id) {
|
|
510
|
-
if (
|
|
511
|
+
if (hasExtension(id, JAY_EXTENSION, { withTs: true }) || hasJayModeExtension(id, { withTs: true }))
|
|
511
512
|
return await transformJayFile(jayContext, this, code, id);
|
|
512
|
-
else if (
|
|
513
|
-
const { filename, dirname } = getFileContext(id,
|
|
514
|
-
const parsedFile =
|
|
515
|
-
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(
|
|
516
517
|
parsedFile,
|
|
517
518
|
`${dirname}/${filename}`,
|
|
518
|
-
|
|
519
|
+
JAY_IMPORT_RESOLVER
|
|
519
520
|
);
|
|
520
521
|
if (tsCode.val)
|
|
521
522
|
return Promise.resolve({
|
|
@@ -530,9 +531,9 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
|
|
|
530
531
|
console.log(`[watchChange] ${id} ${change.event}`);
|
|
531
532
|
jayContext.deleteCachedJayFile(id);
|
|
532
533
|
if (server) {
|
|
533
|
-
const
|
|
534
|
-
if (
|
|
535
|
-
server.moduleGraph.invalidateModule(
|
|
534
|
+
const module = server.moduleGraph.getModuleById(id + TS_EXTENSION);
|
|
535
|
+
if (module) {
|
|
536
|
+
server.moduleGraph.invalidateModule(module);
|
|
536
537
|
server.ws.send({
|
|
537
538
|
type: "full-reload"
|
|
538
539
|
});
|
|
@@ -541,13 +542,8 @@ function jayRuntime(jayOptions = {}, givenJayContext) {
|
|
|
541
542
|
}
|
|
542
543
|
};
|
|
543
544
|
}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
Object.defineProperty(exports, k, {
|
|
550
|
-
enumerable: true,
|
|
551
|
-
get: () => compiler[k]
|
|
552
|
-
});
|
|
553
|
-
});
|
|
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.9",
|
|
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.9",
|
|
31
|
+
"@jay-framework/compiler-jay-html": "^0.6.9",
|
|
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.9",
|
|
37
|
+
"@jay-framework/dev-environment": "^0.6.9",
|
|
38
|
+
"@jay-framework/runtime": "^0.6.9",
|
|
39
|
+
"@jay-framework/secure": "^0.6.9",
|
|
39
40
|
"@types/node": "^20.11.5",
|
|
40
41
|
"rimraf": "^5.0.5",
|
|
41
42
|
"rollup": "^4.9.5",
|