@meteor-vite/plugin-zodern-relay 1.0.4 → 1.0.6

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/Plugin.d.mts CHANGED
@@ -24,6 +24,13 @@ interface Options {
24
24
  content: string;
25
25
  id: string;
26
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;
27
34
  }
28
35
 
29
36
  export { type Options, zodernRelay as default };
package/dist/Plugin.d.ts CHANGED
@@ -24,6 +24,13 @@ interface Options {
24
24
  content: string;
25
25
  id: string;
26
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;
27
34
  }
28
35
 
29
36
  export { type Options, zodernRelay as default };
package/dist/Plugin.js CHANGED
@@ -43,7 +43,7 @@ async function zodernRelay(options) {
43
43
  methods: options?.directories?.methods || ["./imports/methods"],
44
44
  publications: options?.directories?.publications || ["./imports/publications"]
45
45
  },
46
- shouldTransform: options?.shouldTransform || (({ content }) => content.includes("meteor/zodern:relay"))
46
+ shouldTransform: options?.shouldTransform || (({ content }) => content.includes(options?.relayPackageId || "meteor/zodern:relay"))
47
47
  };
48
48
  const directories = [
49
49
  ...config.directories.methods.map((path) => ["methods", import_path.default.relative(cwd, path)]),
@@ -64,7 +64,7 @@ async function zodernRelay(options) {
64
64
  }
65
65
  return {
66
66
  name: "zodern-relay",
67
- async load(filename) {
67
+ async load(filename, fileOptions) {
68
68
  const relay = resolveRelay(filename || "");
69
69
  if (!relay) {
70
70
  return;
@@ -73,6 +73,10 @@ async function zodernRelay(options) {
73
73
  if (!config.shouldTransform({ content: code, id: filename })) {
74
74
  return;
75
75
  }
76
+ let arch = "web.browser.vite";
77
+ if (fileOptions?.ssr) {
78
+ arch = "os.vite.ssr";
79
+ }
76
80
  const transform = await (0, import_core.transformAsync)(code, {
77
81
  configFile: false,
78
82
  babelrc: false,
@@ -83,14 +87,18 @@ async function zodernRelay(options) {
83
87
  caller: {
84
88
  name: "@meteor-vite/plugin-zodern-relay",
85
89
  // @ts-expect-error No type definition for this, but it's required by the Babel plugin.
86
- arch: "web.browser.vite"
90
+ arch
87
91
  }
88
92
  });
89
93
  if (!transform) {
90
94
  return;
91
95
  }
96
+ let newCode = transform.code ?? "";
97
+ if (options?.relayPackageId) {
98
+ newCode = newCode.replace("meteor/zodern:relay", options.relayPackageId);
99
+ }
92
100
  return {
93
- code: transform.code ?? ""
101
+ code: newCode
94
102
  };
95
103
  }
96
104
  };
@@ -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('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) {\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 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: 'web.browser.vite',\n }\n });\n \n if (!transform) {\n return;\n }\n \n return {\n code: transform.code ?? '',\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\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,qBAAqB;AAAA,EACzG;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;AACjB,YAAM,QAAQ,aAAa,YAAY,EAAE;AAEzC,UAAI,CAAC,OAAO;AACR;AAAA,MACJ;AAEA,YAAM,OAAO,UAAAC,QAAG,aAAa,UAAU,OAAO;AAG9C,UAAI,CAAC,OAAO,gBAAgB,EAAE,SAAS,MAAM,IAAI,SAAS,CAAC,GAAG;AAC1D;AAAA,MACJ;AAEA,YAAM,YAAY,UAAM,4BAAe,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,MAAM;AAAA,QACV;AAAA,MACJ,CAAC;AAED,UAAI,CAAC,WAAW;AACZ;AAAA,MACJ;AAEA,aAAO;AAAA,QACH,MAAM,UAAU,QAAQ;AAAA,MAC5B;AAAA,IACJ;AAAA,EACJ;AAGJ;","names":["Path","FS"]}
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) {\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,EAAE;AAEzC,UAAI,CAAC,OAAO;AACR;AAAA,MACJ;AAEA,YAAM,OAAO,UAAAC,QAAG,aAAa,UAAU,OAAO;AAG9C,UAAI,CAAC,OAAO,gBAAgB,EAAE,SAAS,MAAM,IAAI,SAAS,CAAC,GAAG;AAC1D;AAAA,MACJ;AAEA,UAAI,OAAO;AAEX,UAAI,aAAa,KAAK;AAClB,eAAO;AAAA,MACX;AAEA,YAAM,YAAY,UAAM,4BAAe,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":["Path","FS"]}
package/dist/Plugin.mjs CHANGED
@@ -9,7 +9,7 @@ async function zodernRelay(options) {
9
9
  methods: options?.directories?.methods || ["./imports/methods"],
10
10
  publications: options?.directories?.publications || ["./imports/publications"]
11
11
  },
12
- shouldTransform: options?.shouldTransform || (({ content }) => content.includes("meteor/zodern:relay"))
12
+ shouldTransform: options?.shouldTransform || (({ content }) => content.includes(options?.relayPackageId || "meteor/zodern:relay"))
13
13
  };
14
14
  const directories = [
15
15
  ...config.directories.methods.map((path) => ["methods", Path.relative(cwd, path)]),
@@ -30,7 +30,7 @@ async function zodernRelay(options) {
30
30
  }
31
31
  return {
32
32
  name: "zodern-relay",
33
- async load(filename) {
33
+ async load(filename, fileOptions) {
34
34
  const relay = resolveRelay(filename || "");
35
35
  if (!relay) {
36
36
  return;
@@ -39,6 +39,10 @@ async function zodernRelay(options) {
39
39
  if (!config.shouldTransform({ content: code, id: filename })) {
40
40
  return;
41
41
  }
42
+ let arch = "web.browser.vite";
43
+ if (fileOptions?.ssr) {
44
+ arch = "os.vite.ssr";
45
+ }
42
46
  const transform = await transformAsync(code, {
43
47
  configFile: false,
44
48
  babelrc: false,
@@ -49,14 +53,18 @@ async function zodernRelay(options) {
49
53
  caller: {
50
54
  name: "@meteor-vite/plugin-zodern-relay",
51
55
  // @ts-expect-error No type definition for this, but it's required by the Babel plugin.
52
- arch: "web.browser.vite"
56
+ arch
53
57
  }
54
58
  });
55
59
  if (!transform) {
56
60
  return;
57
61
  }
62
+ let newCode = transform.code ?? "";
63
+ if (options?.relayPackageId) {
64
+ newCode = newCode.replace("meteor/zodern:relay", options.relayPackageId);
65
+ }
58
66
  return {
59
- code: transform.code ?? ""
67
+ code: newCode
60
68
  };
61
69
  }
62
70
  };
@@ -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('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) {\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 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: 'web.browser.vite',\n }\n });\n \n if (!transform) {\n return;\n }\n \n return {\n code: transform.code ?? '',\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\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,qBAAqB;AAAA,EACzG;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;AACjB,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,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,MAAM;AAAA,QACV;AAAA,MACJ,CAAC;AAED,UAAI,CAAC,WAAW;AACZ;AAAA,MACJ;AAEA,aAAO;AAAA,QACH,MAAM,UAAU,QAAQ;AAAA,MAC5B;AAAA,IACJ;AAAA,EACJ;AAGJ;","names":[]}
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) {\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,KAAK;AAClB,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.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Vite compatability plugin for zodern:relay - typed Meteor methods and publications",
5
5
  "main": "dist/Plugin.js",
6
6
  "exports": {
package/src/Plugin.ts CHANGED
@@ -11,7 +11,7 @@ export default async function zodernRelay(options?: Options): Promise<Plugin> {
11
11
  methods: options?.directories?.methods || ['./imports/methods'],
12
12
  publications: options?.directories?.publications || ['./imports/publications'],
13
13
  },
14
- shouldTransform: options?.shouldTransform || (({ content }) => content.includes('meteor/zodern:relay')),
14
+ shouldTransform: options?.shouldTransform || (({ content }) => content.includes(options?.relayPackageId || 'meteor/zodern:relay')),
15
15
  } satisfies Options;
16
16
 
17
17
  const directories = [
@@ -35,7 +35,7 @@ export default async function zodernRelay(options?: Options): Promise<Plugin> {
35
35
 
36
36
  return {
37
37
  name: 'zodern-relay',
38
- async load(filename) {
38
+ async load(filename, fileOptions) {
39
39
  const relay = resolveRelay(filename || '');
40
40
 
41
41
  if (!relay) {
@@ -49,6 +49,12 @@ export default async function zodernRelay(options?: Options): Promise<Plugin> {
49
49
  return;
50
50
  }
51
51
 
52
+ let arch = 'web.browser.vite';
53
+
54
+ if (fileOptions?.ssr) {
55
+ arch = 'os.vite.ssr';
56
+ }
57
+
52
58
  const transform = await transformAsync(code, {
53
59
  configFile: false,
54
60
  babelrc: false,
@@ -59,7 +65,7 @@ export default async function zodernRelay(options?: Options): Promise<Plugin> {
59
65
  name: '@meteor-vite/plugin-zodern-relay',
60
66
 
61
67
  // @ts-expect-error No type definition for this, but it's required by the Babel plugin.
62
- arch: 'web.browser.vite',
68
+ arch,
63
69
  }
64
70
  });
65
71
 
@@ -67,8 +73,16 @@ export default async function zodernRelay(options?: Options): Promise<Plugin> {
67
73
  return;
68
74
  }
69
75
 
76
+ let newCode = transform.code ?? '';
77
+
78
+ // Rewrite any newly added imports to use the correct package ID.
79
+ // Only applicable when using a fork of zodern:relay.
80
+ if (options?.relayPackageId) {
81
+ newCode = newCode.replace('meteor/zodern:relay', options.relayPackageId);
82
+ }
83
+
70
84
  return {
71
- code: transform.code ?? '',
85
+ code: newCode,
72
86
  }
73
87
  }
74
88
  }
@@ -96,6 +110,14 @@ export interface Options {
96
110
  * @param id
97
111
  */
98
112
  shouldTransform?: (file: { content: string, id: string }) => boolean;
113
+
114
+ /**
115
+ * If you're using a fork of zodern:relay, you should specify its Meteor import string here so imports
116
+ * can be substituted with your fork. The Babel plugin currently injects a hardcoded import string for
117
+ * client-code `zodern:relay/client`, so it's important we correct that before finishing the transform process.
118
+ * @default 'meteor/zodern:relay'
119
+ */
120
+ relayPackageId?: string;
99
121
  }
100
122
 
101
123
  type RelayInfo = {