@jay-framework/rollup-plugin 0.12.0 → 0.13.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.
Files changed (2) hide show
  1. package/dist/index.js +49 -5
  2. package/package.json +8 -8
package/dist/index.js CHANGED
@@ -7,13 +7,14 @@ 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 { 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";
10
+ import { getBasePath, JAY_EXTENSION, hasExtension, JAY_CONTRACT_EXTENSION, JAY_ACTION_EXTENSION, checkValidationErrors, JAY_DTS_EXTENSION, JAY_CONTRACT_DTS_EXTENSION, JAY_ACTION_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 { getLogger } from "@jay-framework/logger";
14
- import { getJayHtmlImports, parseJayFile, JAY_IMPORT_RESOLVER, parseContract, compileContract, generateSandboxRootFile, generateElementBridgeFile } from "@jay-framework/compiler-jay-html";
14
+ import fs from "node:fs";
15
+ import { getJayHtmlImports, parseJayFile, JAY_IMPORT_RESOLVER, parseContract, compileContract, parseAction, compileAction, defaultContractResolver, generateSandboxRootFile, generateElementBridgeFile } from "@jay-framework/compiler-jay-html";
15
16
  import { createRequire } from "module";
16
- import fs from "fs";
17
+ import fs$1 from "fs";
17
18
  function getFileContext(filename, extension = JAY_EXTENSION) {
18
19
  const basePath = getBasePath(filename);
19
20
  return {
@@ -44,12 +45,40 @@ function checkCodeErrors(code) {
44
45
  throw new Error("Empty code file");
45
46
  return code;
46
47
  }
48
+ function createContractResolver(baseDir, importResolver) {
49
+ return (contractSubpath) => {
50
+ const { viewStateName } = defaultContractResolver(contractSubpath);
51
+ const subpathWithExt = contractSubpath.endsWith(JAY_CONTRACT_EXTENSION) ? contractSubpath : contractSubpath + JAY_CONTRACT_EXTENSION;
52
+ const candidates = [
53
+ `./${subpathWithExt}`,
54
+ `../contracts/${subpathWithExt}`,
55
+ `./contracts/${subpathWithExt}`,
56
+ `../${subpathWithExt}`
57
+ ];
58
+ for (const candidate of candidates) {
59
+ const absolutePath = importResolver.resolveLink(baseDir, candidate);
60
+ if (fs.existsSync(absolutePath)) {
61
+ const relativePath = path.relative(baseDir, absolutePath);
62
+ const importPath = relativePath.startsWith(".") ? relativePath : "./" + relativePath;
63
+ return { importPath, viewStateName };
64
+ }
65
+ }
66
+ try {
67
+ const absolutePath = importResolver.resolveLink(baseDir, subpathWithExt);
68
+ const relativePath = path.relative(baseDir, absolutePath);
69
+ const importPath = relativePath.startsWith(".") ? relativePath : "./" + relativePath;
70
+ return { importPath, viewStateName };
71
+ } catch {
72
+ return { importPath: "./" + subpathWithExt, viewStateName };
73
+ }
74
+ };
75
+ }
47
76
  function jayDefinitions(projectRoot) {
48
77
  return {
49
78
  name: "jay:definitions",
50
79
  // this name will show up in warnings and errors
51
80
  async load(id) {
52
- if (hasExtension(id, JAY_EXTENSION) || hasExtension(id, JAY_CONTRACT_EXTENSION)) {
81
+ if (hasExtension(id, JAY_EXTENSION) || hasExtension(id, JAY_CONTRACT_EXTENSION) || hasExtension(id, JAY_ACTION_EXTENSION)) {
53
82
  const code = await readFileAsString(id);
54
83
  checkCodeErrors(code);
55
84
  return { code };
@@ -108,6 +137,21 @@ function jayDefinitions(projectRoot) {
108
137
  );
109
138
  context.info(`[transform] generated ${generatedFilename}`);
110
139
  return { code: "", map: null };
140
+ } else if (hasExtension(id, JAY_ACTION_EXTENSION)) {
141
+ const context = this;
142
+ const { filename, dirname } = getFileContext(id, JAY_ACTION_EXTENSION);
143
+ const parsedFile = parseAction(code, filename);
144
+ const contractResolver = createContractResolver(dirname, JAY_IMPORT_RESOLVER);
145
+ const tsCode = compileAction(parsedFile, contractResolver);
146
+ const validatedTsCode = checkValidationErrors(tsCode);
147
+ const generatedFilename = await writeDefinitionFile(
148
+ dirname,
149
+ filename,
150
+ validatedTsCode,
151
+ JAY_ACTION_DTS_EXTENSION
152
+ );
153
+ context.info(`[transform] generated ${generatedFilename}`);
154
+ return { code: "", map: null };
111
155
  }
112
156
  return null;
113
157
  }
@@ -490,7 +534,7 @@ class JayPluginContext {
490
534
  this.tsPrinter = createPrinter({ newLine: NewLineKind.LineFeed });
491
535
  let compilerPatternsParseResult = compileFunctionSplitPatternsBlock(
492
536
  (jayOptions.compilerPatternFiles || []).map((fileName) => {
493
- let fileContent = fs.readFileSync(fileName, { encoding: "utf8" });
537
+ let fileContent = fs$1.readFileSync(fileName, { encoding: "utf8" });
494
538
  return createTsSourceFileFromSource(fileName, fileContent);
495
539
  })
496
540
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jay-framework/rollup-plugin",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -27,17 +27,17 @@
27
27
  "test:watch": "vitest"
28
28
  },
29
29
  "dependencies": {
30
- "@jay-framework/compiler": "^0.12.0",
31
- "@jay-framework/compiler-jay-html": "^0.12.0",
32
- "@jay-framework/logger": "^0.12.0",
30
+ "@jay-framework/compiler": "^0.13.0",
31
+ "@jay-framework/compiler-jay-html": "^0.13.0",
32
+ "@jay-framework/logger": "^0.13.0",
33
33
  "fast-glob": "^3.3.2",
34
34
  "typescript": "^5.3.3"
35
35
  },
36
36
  "devDependencies": {
37
- "@jay-framework/component": "^0.12.0",
38
- "@jay-framework/dev-environment": "^0.12.0",
39
- "@jay-framework/runtime": "^0.12.0",
40
- "@jay-framework/secure": "^0.12.0",
37
+ "@jay-framework/component": "^0.13.0",
38
+ "@jay-framework/dev-environment": "^0.13.0",
39
+ "@jay-framework/runtime": "^0.13.0",
40
+ "@jay-framework/secure": "^0.13.0",
41
41
  "@types/node": "^20.11.5",
42
42
  "rimraf": "^5.0.5",
43
43
  "rollup": "^4.9.5",