@meteor-vite/plugin-zodern-relay 1.1.0-alpha.0 → 2.0.0-beta.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.
@@ -0,0 +1,30 @@
1
+ {
2
+ "hash": "11cdf195dea5ef395929c7f5fa71b2f713e2e3b6-94ef5b9cf9b7078f0eaf645e9705bf4e4099646f",
3
+ "fileNamesHash": "94ef5b9cf9b7078f0eaf645e9705bf4e4099646f",
4
+ "fileContentHash": "11cdf195dea5ef395929c7f5fa71b2f713e2e3b6",
5
+ "durationMs": 2586,
6
+ "filenameCount": 2,
7
+ "fileContentCount": 3,
8
+ "changes": [
9
+ "File names changed"
10
+ ],
11
+ "changed": true,
12
+ "lastBuild": {
13
+ "hash": "11cdf195dea5ef395929c7f5fa71b2f713e2e3b6-19fe354ebf5d42e7afbc9d99af15d880f5741249",
14
+ "fileNamesHash": "19fe354ebf5d42e7afbc9d99af15d880f5741249",
15
+ "fileContentHash": "11cdf195dea5ef395929c7f5fa71b2f713e2e3b6",
16
+ "durationMs": 9,
17
+ "filenameCount": 2,
18
+ "fileContentCount": 3,
19
+ "changes": [
20
+ "No previous build info found, rebuild is necessary"
21
+ ],
22
+ "changed": true,
23
+ "lastBuild": {
24
+ "hash": null,
25
+ "error": "Error: ENOENT: no such file or directory, open '/home/runner/work/meteor-vite/meteor-vite/npm-packages/@meteor-vite/plugin-zodern-relay/dist/.build-info.json'\n at async open (node:internal/fs/promises:636:25)\n at async Object.readFile (node:internal/fs/promises:1235:14)\n at async ProjectCompiler.getLastBuildInfo (/home/runner/work/meteor-vite/meteor-vite/npm-packages/@meteor-vite/toolkit/src/ProjectCompiler.ts:155:27)\n at async ProjectCompiler.getHash (/home/runner/work/meteor-vite/meteor-vite/npm-packages/@meteor-vite/toolkit/src/ProjectCompiler.ts:211:27)\n at async ProjectCompiler.saveBuildInfo (/home/runner/work/meteor-vite/meteor-vite/npm-packages/@meteor-vite/toolkit/src/ProjectCompiler.ts:177:13)\n at async Object.buildEnd (/home/runner/work/meteor-vite/meteor-vite/npm-packages/@meteor-vite/toolkit/src/buildConfig/plugins/cacheBuildInfo.ts:17:101)\n at async PluginContainer.buildFinished (/home/runner/work/meteor-vite/meteor-vite/node_modules/tsup/dist/index.js:826:9)\n at async runEsbuild (/home/runner/work/meteor-vite/meteor-vite/node_modules/tsup/dist/index.js:616:5)\n at async /home/runner/work/meteor-vite/meteor-vite/node_modules/tsup/dist/index.js:1621:19\n at async Promise.all (index 0)"
26
+ },
27
+ "timestamp": 1770269098680
28
+ },
29
+ "timestamp": 1770269100779
30
+ }
package/dist/Plugin.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  // src/Plugin.ts
2
2
  import { transformAsync } from "@babel/core";
3
3
  import FS from "fs";
4
+ import { ViteEnvironmentName } from "meteor-vite/utilities/common";
4
5
  import Path from "path";
5
6
  var cwd = process.cwd();
6
7
  async function zodernRelay(options) {
@@ -40,7 +41,7 @@ async function zodernRelay(options) {
40
41
  return;
41
42
  }
42
43
  let arch = "web.browser.vite";
43
- if (fileOptions?.ssr || this.environment.name === "server") {
44
+ if (fileOptions?.ssr || [ViteEnvironmentName.server, "server"].includes(this.environment.name)) {
44
45
  arch = "os.vite.ssr";
45
46
  }
46
47
  const transform = await transformAsync(code, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/Plugin.ts"],"sourcesContent":["import { transformAsync } from '@babel/core';\nimport FS from 'fs';\nimport Path from 'path';\nimport { type Plugin } from 'vite';\n\nconst cwd = process.cwd();\n\nexport default async function zodernRelay(options?: Options): Promise<Plugin> {\n const config = {\n directories: {\n methods: options?.directories?.methods || ['./imports/methods'],\n publications: options?.directories?.publications || ['./imports/publications'],\n },\n shouldTransform: options?.shouldTransform || (({ content }) => content.includes(options?.relayPackageId || 'meteor/zodern:relay')),\n } satisfies Options;\n \n const directories = [\n ...config.directories.methods.map((path) => ['methods', Path.relative(cwd, path)]),\n ...config.directories.publications.map((path) => ['publications', Path.relative(cwd, path)])\n ] as [RelayInfo['type'], string][];\n \n function resolveRelay(id: string): RelayInfo | undefined {\n const relativePath = Path.relative(cwd, id);\n for (const [type, directory] of directories) {\n if (!relativePath.startsWith(directory)) {\n continue;\n }\n return {\n id,\n type,\n relativePath,\n }\n }\n }\n \n return {\n name: 'zodern-relay',\n async load(filename, fileOptions) {\n const relay = resolveRelay(filename || '');\n \n if (!relay) {\n return;\n }\n \n const code = FS.readFileSync(filename, 'utf-8');\n \n // Prevent transforming files that don't use zodern:relay\n if (!config.shouldTransform({ content: code, id: filename })) {\n return;\n }\n \n let arch = 'web.browser.vite';\n \n if (fileOptions?.ssr || this.environment.name === 'server') {\n arch = 'os.vite.ssr';\n }\n \n const transform = await transformAsync(code, {\n configFile: false,\n babelrc: false,\n filename,\n presets: ['@babel/preset-typescript'], // Add TypeScript preset\n plugins: ['@zodern/babel-plugin-meteor-relay'],\n caller: {\n name: '@meteor-vite/plugin-zodern-relay',\n \n // @ts-expect-error No type definition for this, but it's required by the Babel plugin.\n arch,\n }\n });\n \n if (!transform) {\n return;\n }\n \n let newCode = transform.code ?? '';\n \n // Rewrite any newly added imports to use the correct package ID.\n // Only applicable when using a fork of zodern:relay.\n if (options?.relayPackageId) {\n newCode = newCode.replace('meteor/zodern:relay', options.relayPackageId);\n }\n \n return {\n code: newCode,\n }\n }\n }\n \n \n}\nexport interface Options {\n directories?: {\n /**\n * Path to directories where your zodern:relay methods live\n * @default ['./imports/methods']\n */\n methods?: string[],\n \n /**\n * Path to the directories where your zodern:relay publications live.\n * @default ['./imports/publications']\n */\n publications?: string[],\n }\n /**\n * Specify a custom filter to determine whether a module should be transformed with zodern:relay.\n * Used to prevent unnecessary Babel transformations.\n * @default ({ content }) => content.includes('meteor/zodern:relay')\n * @param id\n */\n shouldTransform?: (file: { content: string, id: string }) => boolean;\n \n /**\n * If you're using a fork of zodern:relay, you should specify its Meteor import string here so imports\n * can be substituted with your fork. The Babel plugin currently injects a hardcoded import string for\n * client-code `zodern:relay/client`, so it's important we correct that before finishing the transform process.\n * @default 'meteor/zodern:relay'\n */\n relayPackageId?: string;\n}\n\ntype RelayInfo = {\n type: 'methods' | 'publications';\n id: string;\n relativePath: string;\n};\n"],"mappings":";AAAA,SAAS,sBAAsB;AAC/B,OAAO,QAAQ;AACf,OAAO,UAAU;AAGjB,IAAM,MAAM,QAAQ,IAAI;AAExB,eAAO,YAAmC,SAAoC;AAC1E,QAAM,SAAS;AAAA,IACX,aAAa;AAAA,MACT,SAAS,SAAS,aAAa,WAAW,CAAC,mBAAmB;AAAA,MAC9D,cAAc,SAAS,aAAa,gBAAgB,CAAC,wBAAwB;AAAA,IACjF;AAAA,IACA,iBAAiB,SAAS,oBAAoB,CAAC,EAAE,QAAQ,MAAM,QAAQ,SAAS,SAAS,kBAAkB,qBAAqB;AAAA,EACpI;AAEA,QAAM,cAAc;AAAA,IAChB,GAAG,OAAO,YAAY,QAAQ,IAAI,CAAC,SAAS,CAAC,WAAW,KAAK,SAAS,KAAK,IAAI,CAAC,CAAC;AAAA,IACjF,GAAG,OAAO,YAAY,aAAa,IAAI,CAAC,SAAS,CAAC,gBAAgB,KAAK,SAAS,KAAK,IAAI,CAAC,CAAC;AAAA,EAC/F;AAEA,WAAS,aAAa,IAAmC;AACrD,UAAM,eAAe,KAAK,SAAS,KAAK,EAAE;AAC1C,eAAW,CAAC,MAAM,SAAS,KAAK,aAAa;AACzC,UAAI,CAAC,aAAa,WAAW,SAAS,GAAG;AACrC;AAAA,MACJ;AACA,aAAO;AAAA,QACH;AAAA,QACA;AAAA,QACA;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AAEA,SAAO;AAAA,IACH,MAAM;AAAA,IACN,MAAM,KAAK,UAAU,aAAa;AAC9B,YAAM,QAAQ,aAAa,YAAY,EAAE;AAEzC,UAAI,CAAC,OAAO;AACR;AAAA,MACJ;AAEA,YAAM,OAAO,GAAG,aAAa,UAAU,OAAO;AAG9C,UAAI,CAAC,OAAO,gBAAgB,EAAE,SAAS,MAAM,IAAI,SAAS,CAAC,GAAG;AAC1D;AAAA,MACJ;AAEA,UAAI,OAAO;AAEX,UAAI,aAAa,OAAO,KAAK,YAAY,SAAS,UAAU;AACxD,eAAO;AAAA,MACX;AAEA,YAAM,YAAY,MAAM,eAAe,MAAM;AAAA,QACzC,YAAY;AAAA,QACZ,SAAS;AAAA,QACT;AAAA,QACA,SAAS,CAAC,0BAA0B;AAAA;AAAA,QACpC,SAAS,CAAC,mCAAmC;AAAA,QAC7C,QAAQ;AAAA,UACJ,MAAM;AAAA;AAAA,UAGN;AAAA,QACJ;AAAA,MACJ,CAAC;AAED,UAAI,CAAC,WAAW;AACZ;AAAA,MACJ;AAEA,UAAI,UAAU,UAAU,QAAQ;AAIhC,UAAI,SAAS,gBAAgB;AACzB,kBAAU,QAAQ,QAAQ,uBAAuB,QAAQ,cAAc;AAAA,MAC3E;AAEA,aAAO;AAAA,QACH,MAAM;AAAA,MACV;AAAA,IACJ;AAAA,EACJ;AAGJ;","names":[]}
1
+ {"version":3,"sources":["../src/Plugin.ts"],"sourcesContent":["import { transformAsync } from '@babel/core';\nimport FS from 'fs';\nimport { ViteEnvironmentName } from 'meteor-vite/utilities/common';\nimport Path from 'path';\nimport { type Plugin } from 'vite';\n\nconst cwd = process.cwd();\n\nexport default async function zodernRelay(options?: Options): Promise<Plugin> {\n const config = {\n directories: {\n methods: options?.directories?.methods || ['./imports/methods'],\n publications: options?.directories?.publications || ['./imports/publications'],\n },\n shouldTransform: options?.shouldTransform || (({ content }) => content.includes(options?.relayPackageId || 'meteor/zodern:relay')),\n } satisfies Options;\n \n const directories = [\n ...config.directories.methods.map((path) => ['methods', Path.relative(cwd, path)]),\n ...config.directories.publications.map((path) => ['publications', Path.relative(cwd, path)])\n ] as [RelayInfo['type'], string][];\n \n function resolveRelay(id: string): RelayInfo | undefined {\n const relativePath = Path.relative(cwd, id);\n for (const [type, directory] of directories) {\n if (!relativePath.startsWith(directory)) {\n continue;\n }\n return {\n id,\n type,\n relativePath,\n }\n }\n }\n \n return {\n name: 'zodern-relay',\n async load(filename, fileOptions) {\n const relay = resolveRelay(filename || '');\n \n if (!relay) {\n return;\n }\n \n const code = FS.readFileSync(filename, 'utf-8');\n \n // Prevent transforming files that don't use zodern:relay\n if (!config.shouldTransform({ content: code, id: filename })) {\n return;\n }\n \n let arch = 'web.browser.vite';\n \n if (fileOptions?.ssr || [ViteEnvironmentName.server, 'server'].includes(this.environment.name)) {\n arch = 'os.vite.ssr';\n }\n \n const transform = await transformAsync(code, {\n configFile: false,\n babelrc: false,\n filename,\n presets: ['@babel/preset-typescript'], // Add TypeScript preset\n plugins: ['@zodern/babel-plugin-meteor-relay'],\n caller: {\n name: '@meteor-vite/plugin-zodern-relay',\n \n // @ts-expect-error No type definition for this, but it's required by the Babel plugin.\n arch,\n }\n });\n \n if (!transform) {\n return;\n }\n \n let newCode = transform.code ?? '';\n \n // Rewrite any newly added imports to use the correct package ID.\n // Only applicable when using a fork of zodern:relay.\n if (options?.relayPackageId) {\n newCode = newCode.replace('meteor/zodern:relay', options.relayPackageId);\n }\n \n return {\n code: newCode,\n }\n }\n }\n \n \n}\nexport interface Options {\n directories?: {\n /**\n * Path to directories where your zodern:relay methods live\n * @default ['./imports/methods']\n */\n methods?: string[],\n \n /**\n * Path to the directories where your zodern:relay publications live.\n * @default ['./imports/publications']\n */\n publications?: string[],\n }\n /**\n * Specify a custom filter to determine whether a module should be transformed with zodern:relay.\n * Used to prevent unnecessary Babel transformations.\n * @default ({ content }) => content.includes('meteor/zodern:relay')\n * @param id\n */\n shouldTransform?: (file: { content: string, id: string }) => boolean;\n \n /**\n * If you're using a fork of zodern:relay, you should specify its Meteor import string here so imports\n * can be substituted with your fork. The Babel plugin currently injects a hardcoded import string for\n * client-code `zodern:relay/client`, so it's important we correct that before finishing the transform process.\n * @default 'meteor/zodern:relay'\n */\n relayPackageId?: string;\n}\n\ntype RelayInfo = {\n type: 'methods' | 'publications';\n id: string;\n relativePath: string;\n};\n"],"mapp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,QAAQ,EAAE,SAAS,KAAK,YAAY,IAAI,GAAG;AAC5F,eAAO;AAAA,MACX;AAEA,YAAM,YAAY,MAAM,eAAe,MAAM;AAAA,QACzC,YAAY;AAAA,QACZ,SAAS;AAAA,QACT;AAAA,QACA,SAAS,CAAC,0BAA0B;AAAA;AAAA,QACpC,SAAS,CAAC,mCAAmC;AAAA,QAC7C,QAAQ;AAAA,UACJ,MAAM;AAAA;AAAA,UAGN;AAAA,QACJ;AAAA,MACJ,CAAC;AAED,UAAI,CAAC,WAAW;AACZ;AAAA,MACJ;AAEA,UAAI,UAAU,UAAU,QAAQ;AAIhC,UAAI,SAAS,gBAAgB;AACzB,kBAAU,QAAQ,QAAQ,uBAAuB,QAAQ,cAAc;AAAA,MAC3E;AAEA,aAAO;AAAA,QACH,MAAM;AAAA,MACV;AAAA,IACJ;AAAA,EACJ;AAGJ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meteor-vite/plugin-zodern-relay",
3
- "version": "1.1.0-alpha.0",
3
+ "version": "2.0.0-beta.0",
4
4
  "description": "Vite compatability plugin for zodern:relay - typed Meteor methods and publications",
5
5
  "main": "dist/Plugin.js",
6
6
  "exports": {
@@ -21,7 +21,7 @@
21
21
  "scripts": {
22
22
  "lint": "tsc --noEmit",
23
23
  "test": "npm run lint",
24
- "build": "tsup",
24
+ "build": "toolkit build",
25
25
  "prepack": "npm run build",
26
26
  "prepare": "npm run build || echo 'Warning: Failed to prepare package!' && exit 0"
27
27
  },
@@ -42,11 +42,16 @@
42
42
  },
43
43
  "devDependencies": {
44
44
  "@babel/preset-typescript": "^7.24.7",
45
+ "@meteor-vite/toolkit": "^1.0.0",
45
46
  "@types/babel__core": "^7.20.5",
46
47
  "tsup": "^8.0.2",
47
- "typescript": "^5.4.2"
48
+ "typescript": "^5.4.2",
49
+ "vite": "^6.2.5"
48
50
  },
49
51
  "peerDependencies": {
50
- "@babel/core": "^7.0.0"
52
+ "meteor-vite": "^3.9.0-beta.2"
53
+ },
54
+ "dependencies": {
55
+ "@babel/core": "^7.28.0"
51
56
  }
52
57
  }
package/src/Plugin.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { transformAsync } from '@babel/core';
2
2
  import FS from 'fs';
3
+ import { ViteEnvironmentName } from 'meteor-vite/utilities/common';
3
4
  import Path from 'path';
4
5
  import { type Plugin } from 'vite';
5
6
 
@@ -51,7 +52,7 @@ export default async function zodernRelay(options?: Options): Promise<Plugin> {
51
52
 
52
53
  let arch = 'web.browser.vite';
53
54
 
54
- if (fileOptions?.ssr || this.environment.name === 'server') {
55
+ if (fileOptions?.ssr || [ViteEnvironmentName.server, 'server'].includes(this.environment.name)) {
55
56
  arch = 'os.vite.ssr';
56
57
  }
57
58
 
package/dist/Plugin.d.ts DELETED
@@ -1,36 +0,0 @@
1
- import { Plugin } from 'vite';
2
-
3
- declare function zodernRelay(options?: Options): Promise<Plugin>;
4
- interface Options {
5
- directories?: {
6
- /**
7
- * Path to directories where your zodern:relay methods live
8
- * @default ['./imports/methods']
9
- */
10
- methods?: string[];
11
- /**
12
- * Path to the directories where your zodern:relay publications live.
13
- * @default ['./imports/publications']
14
- */
15
- publications?: string[];
16
- };
17
- /**
18
- * Specify a custom filter to determine whether a module should be transformed with zodern:relay.
19
- * Used to prevent unnecessary Babel transformations.
20
- * @default ({ content }) => content.includes('meteor/zodern:relay')
21
- * @param id
22
- */
23
- shouldTransform?: (file: {
24
- content: string;
25
- id: string;
26
- }) => boolean;
27
- /**
28
- * If you're using a fork of zodern:relay, you should specify its Meteor import string here so imports
29
- * can be substituted with your fork. The Babel plugin currently injects a hardcoded import string for
30
- * client-code `zodern:relay/client`, so it's important we correct that before finishing the transform process.
31
- * @default 'meteor/zodern:relay'
32
- */
33
- relayPackageId?: string;
34
- }
35
-
36
- export { type Options, zodernRelay as default };
package/dist/Plugin.js DELETED
@@ -1,106 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/Plugin.ts
31
- var Plugin_exports = {};
32
- __export(Plugin_exports, {
33
- default: () => zodernRelay
34
- });
35
- module.exports = __toCommonJS(Plugin_exports);
36
- var import_core = require("@babel/core");
37
- var import_fs = __toESM(require("fs"));
38
- var import_path = __toESM(require("path"));
39
- var cwd = process.cwd();
40
- async function zodernRelay(options) {
41
- const config = {
42
- directories: {
43
- methods: options?.directories?.methods || ["./imports/methods"],
44
- publications: options?.directories?.publications || ["./imports/publications"]
45
- },
46
- shouldTransform: options?.shouldTransform || (({ content }) => content.includes(options?.relayPackageId || "meteor/zodern:relay"))
47
- };
48
- const directories = [
49
- ...config.directories.methods.map((path) => ["methods", import_path.default.relative(cwd, path)]),
50
- ...config.directories.publications.map((path) => ["publications", import_path.default.relative(cwd, path)])
51
- ];
52
- function resolveRelay(id) {
53
- const relativePath = import_path.default.relative(cwd, id);
54
- for (const [type, directory] of directories) {
55
- if (!relativePath.startsWith(directory)) {
56
- continue;
57
- }
58
- return {
59
- id,
60
- type,
61
- relativePath
62
- };
63
- }
64
- }
65
- return {
66
- name: "zodern-relay",
67
- async load(filename, fileOptions) {
68
- const relay = resolveRelay(filename || "");
69
- if (!relay) {
70
- return;
71
- }
72
- const code = import_fs.default.readFileSync(filename, "utf-8");
73
- if (!config.shouldTransform({ content: code, id: filename })) {
74
- return;
75
- }
76
- let arch = "web.browser.vite";
77
- if (fileOptions?.ssr || this.environment.name === "server") {
78
- arch = "os.vite.ssr";
79
- }
80
- const transform = await (0, import_core.transformAsync)(code, {
81
- configFile: false,
82
- babelrc: false,
83
- filename,
84
- presets: ["@babel/preset-typescript"],
85
- // Add TypeScript preset
86
- plugins: ["@zodern/babel-plugin-meteor-relay"],
87
- caller: {
88
- name: "@meteor-vite/plugin-zodern-relay",
89
- // @ts-expect-error No type definition for this, but it's required by the Babel plugin.
90
- arch
91
- }
92
- });
93
- if (!transform) {
94
- return;
95
- }
96
- let newCode = transform.code ?? "";
97
- if (options?.relayPackageId) {
98
- newCode = newCode.replace("meteor/zodern:relay", options.relayPackageId);
99
- }
100
- return {
101
- code: newCode
102
- };
103
- }
104
- };
105
- }
106
- //# sourceMappingURL=Plugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/Plugin.ts"],"sourcesContent":["import { transformAsync } from '@babel/core';\nimport FS from 'fs';\nimport Path from 'path';\nimport { type Plugin } from 'vite';\n\nconst cwd = process.cwd();\n\nexport default async function zodernRelay(options?: Options): Promise<Plugin> {\n const config = {\n directories: {\n methods: options?.directories?.methods || ['./imports/methods'],\n publications: options?.directories?.publications || ['./imports/publications'],\n },\n shouldTransform: options?.shouldTransform || (({ content }) => content.includes(options?.relayPackageId || 'meteor/zodern:relay')),\n } satisfies Options;\n \n const directories = [\n ...config.directories.methods.map((path) => ['methods', Path.relative(cwd, path)]),\n ...config.directories.publications.map((path) => ['publications', Path.relative(cwd, path)])\n ] as [RelayInfo['type'], string][];\n \n function resolveRelay(id: string): RelayInfo | undefined {\n const relativePath = Path.relative(cwd, id);\n for (const [type, directory] of directories) {\n if (!relativePath.startsWith(directory)) {\n continue;\n }\n return {\n id,\n type,\n relativePath,\n }\n }\n }\n \n return {\n name: 'zodern-relay',\n async load(filename, fileOptions) {\n const relay = resolveRelay(filename || '');\n \n if (!relay) {\n return;\n }\n \n const code = FS.readFileSync(filename, 'utf-8');\n \n // Prevent transforming files that don't use zodern:relay\n if (!config.shouldTransform({ content: code, id: filename })) {\n return;\n }\n \n let arch = 'web.browser.vite';\n \n if (fileOptions?.ssr || this.environment.name === 'server') {\n arch = 'os.vite.ssr';\n }\n \n const transform = await transformAsync(code, {\n configFile: false,\n babelrc: false,\n filename,\n presets: ['@babel/preset-typescript'], // Add TypeScript preset\n plugins: ['@zodern/babel-plugin-meteor-relay'],\n caller: {\n name: '@meteor-vite/plugin-zodern-relay',\n \n // @ts-expect-error No type definition for this, but it's required by the Babel plugin.\n arch,\n }\n });\n \n if (!transform) {\n return;\n }\n \n let newCode = transform.code ?? '';\n \n // Rewrite any newly added imports to use the correct package ID.\n // Only applicable when using a fork of zodern:relay.\n if (options?.relayPackageId) {\n newCode = newCode.replace('meteor/zodern:relay', options.relayPackageId);\n }\n \n return {\n code: newCode,\n }\n }\n }\n \n \n}\nexport interface Options {\n directories?: {\n /**\n * Path to directories where your zodern:relay methods live\n * @default ['./imports/methods']\n */\n methods?: string[],\n \n /**\n * Path to the directories where your zodern:relay publications live.\n * @default ['./imports/publications']\n */\n publications?: string[],\n }\n /**\n * Specify a custom filter to determine whether a module should be transformed with zodern:relay.\n * Used to prevent unnecessary Babel transformations.\n * @default ({ content }) => content.includes('meteor/zodern:relay')\n * @param id\n */\n shouldTransform?: (file: { content: string, id: string }) => boolean;\n \n /**\n * If you're using a fork of zodern:relay, you should specify its Meteor import string here so imports\n * can be substituted with your fork. The Babel plugin currently injects a hardcoded import string for\n * client-code `zodern:relay/client`, so it's important we correct that before finishing the transform process.\n * @default 'meteor/zodern:relay'\n */\n relayPackageId?: string;\n}\n\ntype RelayInfo = {\n type: 'methods' | 'publications';\n id: string;\n relativePath: string;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA+B;AAC/B,gBAAe;AACf,kBAAiB;AAGjB,IAAM,MAAM,QAAQ,IAAI;AAExB,eAAO,YAAmC,SAAoC;AAC1E,QAAM,SAAS;AAAA,IACX,aAAa;AAAA,MACT,SAAS,SAAS,aAAa,WAAW,CAAC,mBAAmB;AAAA,MAC9D,cAAc,SAAS,aAAa,gBAAgB,CAAC,wBAAwB;AAAA,IACjF;AAAA,IACA,iBAAiB,SAAS,oBAAoB,CAAC,EAAE,QAAQ,MAAM,QAAQ,SAAS,SAAS,kBAAkB,qBAAqB;AAAA,EACpI;AAEA,QAAM,cAAc;AAAA,IAChB,GAAG,OAAO,YAAY,QAAQ,IAAI,CAAC,SAAS,CAAC,WAAW,YAAAA,QAAK,SAAS,KAAK,IAAI,CAAC,CAAC;AAAA,IACjF,GAAG,OAAO,YAAY,aAAa,IAAI,CAAC,SAAS,CAAC,gBAAgB,YAAAA,QAAK,SAAS,KAAK,IAAI,CAAC,CAAC;AAAA,EAC/F;AAEA,WAAS,aAAa,IAAmC;AACrD,UAAM,eAAe,YAAAA,QAAK,SAAS,KAAK,EAAE;AAC1C,eAAW,CAAC,MAAM,SAAS,KAAK,aAAa;AACzC,UAAI,CAAC,aAAa,WAAW,SAAS,GAAG;AACrC;AAAA,MACJ;AACA,aAAO;AAAA,QACH;AAAA,QACA;AAAA,QACA;AAAA,MACJ;AAAA,IACJ;AAAA,EACJ;AAEA,SAAO;AAAA,IACH,MAAM;AAAA,IACN,MAAM,KAAK,UAAU,aAAa;AAC9B,YAAM,QAAQ,aAAa,YAAY,EAA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