@meteor-vite/plugin-zodern-relay 1.0.3 → 1.0.5

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/README.md CHANGED
@@ -1,55 +1,55 @@
1
- # Vite plugin `zodern:relay`
2
-
3
- This is a Vite compatability package for
4
- [`zodern:relay`](https://github.com/zodern/meteor-relay#readme) - type safe
5
- [Meteor](https://meteor.com/) methods and publications.
6
-
7
- This plugin acts as partial replacement for the Babel `@zodern/babel-plugin-meteor-relay` plugin required by
8
- `zodern:relay`. You still need the Babel plugin as it might still be required on the server.
9
-
10
-
11
- ## Installation
12
- ```sh
13
- npm i -D @meteor-vite/plugin-zodern-relay
14
- ```
15
-
16
- ## Configuration
17
- Add the plugin to your Vite config and you're all set. If your methods and publications reside outside of `imports/api/<methods|publications>`, specify those paths when calling the plugin.
18
- ```ts
19
- // vite.config.ts
20
- import zodernRelay from '@meteor-vite/plugin-zodern-relay';
21
- import { meteor } from 'meteor-vite/plugin';
22
-
23
- export default defineConfig({
24
- plugins: [
25
- meteor({
26
- clientEntry: '...',
27
- }),
28
- zodernRelay({
29
- directories: {
30
- /**
31
- * Path to directories where your zodern:relay methods live
32
- * @default ['./imports/methods']
33
- */
34
- methods: ['./imports/methods'],
35
-
36
- /**
37
- * Path to the directories where your zodern:relay publications live.
38
- * @default ['./imports/publications']
39
- */
40
- publications: ['./imports/publications'],
41
- }
42
- }),
43
- ]
44
- })
45
- ```
46
-
47
- ## Usage & Documentation
48
- You can use [`zodern:relay`](https://github.com/zodern/meteor-relay#readme) like you normally would. Consult their
49
- readme for documentation.
50
-
51
- - `zodern:relay` - https://github.com/zodern/meteor-relay#readme
52
- - `meteor-vite` - https://github.com/JorgenVatle/meteor-vite#readme
53
-
54
- ## License
1
+ # Vite plugin `zodern:relay`
2
+
3
+ This is a Vite compatability package for
4
+ [`zodern:relay`](https://github.com/zodern/meteor-relay#readme) - type safe
5
+ [Meteor](https://meteor.com/) methods and publications.
6
+
7
+ This plugin acts as partial replacement for the Babel `@zodern/babel-plugin-meteor-relay` plugin required by
8
+ `zodern:relay`. You still need the Babel plugin as it might still be required on the server.
9
+
10
+
11
+ ## Installation
12
+ ```sh
13
+ npm i -D @meteor-vite/plugin-zodern-relay
14
+ ```
15
+
16
+ ## Configuration
17
+ Add the plugin to your Vite config and you're all set. If your methods and publications reside outside of `imports/api/<methods|publications>`, specify those paths when calling the plugin.
18
+ ```ts
19
+ // vite.config.ts
20
+ import zodernRelay from '@meteor-vite/plugin-zodern-relay';
21
+ import { meteor } from 'meteor-vite/plugin';
22
+
23
+ export default defineConfig({
24
+ plugins: [
25
+ meteor({
26
+ clientEntry: '...',
27
+ }),
28
+ zodernRelay({
29
+ directories: {
30
+ /**
31
+ * Path to directories where your zodern:relay methods live
32
+ * @default ['./imports/methods']
33
+ */
34
+ methods: ['./imports/methods'],
35
+
36
+ /**
37
+ * Path to the directories where your zodern:relay publications live.
38
+ * @default ['./imports/publications']
39
+ */
40
+ publications: ['./imports/publications'],
41
+ }
42
+ }),
43
+ ]
44
+ })
45
+ ```
46
+
47
+ ## Usage & Documentation
48
+ You can use [`zodern:relay`](https://github.com/zodern/meteor-relay#readme) like you normally would. Consult their
49
+ readme for documentation.
50
+
51
+ - `zodern:relay` - https://github.com/zodern/meteor-relay#readme
52
+ - `meteor-vite` - https://github.com/JorgenVatle/meteor-vite#readme
53
+
54
+ ## License
55
55
  MIT
package/dist/Plugin.d.mts CHANGED
@@ -14,6 +14,23 @@ interface Options {
14
14
  */
15
15
  publications?: string[];
16
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;
17
34
  }
18
35
 
19
36
  export { type Options, zodernRelay as default };
package/dist/Plugin.d.ts CHANGED
@@ -14,6 +14,23 @@ interface Options {
14
14
  */
15
15
  publications?: string[];
16
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;
17
34
  }
18
35
 
19
36
  export { type Options, zodernRelay as default };
package/dist/Plugin.js CHANGED
@@ -42,7 +42,8 @@ async function zodernRelay(options) {
42
42
  directories: {
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(options?.relayPackageId || "meteor/zodern:relay"))
46
47
  };
47
48
  const directories = [
48
49
  ...config.directories.methods.map((path) => ["methods", import_path.default.relative(cwd, path)]),
@@ -69,7 +70,7 @@ async function zodernRelay(options) {
69
70
  return;
70
71
  }
71
72
  const code = import_fs.default.readFileSync(filename, "utf-8");
72
- if (!code.includes("meteor/zodern:relay")) {
73
+ if (!config.shouldTransform({ content: code, id: filename })) {
73
74
  return;
74
75
  }
75
76
  const transform = await (0, import_core.transformAsync)(code, {
@@ -88,8 +89,12 @@ async function zodernRelay(options) {
88
89
  if (!transform) {
89
90
  return;
90
91
  }
92
+ let newCode = transform.code ?? "";
93
+ if (options?.relayPackageId) {
94
+ newCode = newCode.replace("meteor/zodern:relay", options.relayPackageId);
95
+ }
91
96
  return {
92
- code: transform.code ?? ""
97
+ code: newCode
93
98
  };
94
99
  }
95
100
  };
@@ -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 } 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 (!code.includes('meteor/zodern:relay')) {\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\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,EACJ;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,KAAK,SAAS,qBAAqB,GAAG;AACvC;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';\r\nimport FS from 'fs';\r\nimport Path from 'path';\r\nimport { type Plugin } from 'vite';\r\n\r\nconst cwd = process.cwd();\r\n\r\nexport default async function zodernRelay(options?: Options): Promise<Plugin> {\r\n const config = {\r\n directories: {\r\n methods: options?.directories?.methods || ['./imports/methods'],\r\n publications: options?.directories?.publications || ['./imports/publications'],\r\n },\r\n shouldTransform: options?.shouldTransform || (({ content }) => content.includes(options?.relayPackageId || 'meteor/zodern:relay')),\r\n } satisfies Options;\r\n \r\n const directories = [\r\n ...config.directories.methods.map((path) => ['methods', Path.relative(cwd, path)]),\r\n ...config.directories.publications.map((path) => ['publications', Path.relative(cwd, path)])\r\n ] as [RelayInfo['type'], string][];\r\n \r\n function resolveRelay(id: string): RelayInfo | undefined {\r\n const relativePath = Path.relative(cwd, id);\r\n for (const [type, directory] of directories) {\r\n if (!relativePath.startsWith(directory)) {\r\n continue;\r\n }\r\n return {\r\n id,\r\n type,\r\n relativePath,\r\n }\r\n }\r\n }\r\n \r\n return {\r\n name: 'zodern-relay',\r\n async load(filename) {\r\n const relay = resolveRelay(filename || '');\r\n \r\n if (!relay) {\r\n return;\r\n }\r\n \r\n const code = FS.readFileSync(filename, 'utf-8');\r\n \r\n // Prevent transforming files that don't use zodern:relay\r\n if (!config.shouldTransform({ content: code, id: filename })) {\r\n return;\r\n }\r\n \r\n const transform = await transformAsync(code, {\r\n configFile: false,\r\n babelrc: false,\r\n filename,\r\n presets: ['@babel/preset-typescript'], // Add TypeScript preset\r\n plugins: ['@zodern/babel-plugin-meteor-relay'],\r\n caller: {\r\n name: '@meteor-vite/plugin-zodern-relay',\r\n \r\n // @ts-expect-error No type definition for this, but it's required by the Babel plugin.\r\n arch: 'web.browser.vite',\r\n }\r\n });\r\n \r\n if (!transform) {\r\n return;\r\n }\r\n \r\n let newCode = transform.code ?? '';\r\n \r\n // Rewrite any newly added imports to use the correct package ID.\r\n // Only applicable when using a fork of zodern:relay.\r\n if (options?.relayPackageId) {\r\n newCode = newCode.replace('meteor/zodern:relay', options.relayPackageId);\r\n }\r\n \r\n return {\r\n code: newCode,\r\n }\r\n }\r\n }\r\n \r\n \r\n}\r\nexport interface Options {\r\n directories?: {\r\n /**\r\n * Path to directories where your zodern:relay methods live\r\n * @default ['./imports/methods']\r\n */\r\n methods?: string[],\r\n \r\n /**\r\n * Path to the directories where your zodern:relay publications live.\r\n * @default ['./imports/publications']\r\n */\r\n publications?: string[],\r\n }\r\n /**\r\n * Specify a custom filter to determine whether a module should be transformed with zodern:relay.\r\n * Used to prevent unnecessary Babel transformations.\r\n * @default ({ content }) => content.includes('meteor/zodern:relay')\r\n * @param id\r\n */\r\n shouldTransform?: (file: { content: string, id: string }) => boolean;\r\n \r\n /**\r\n * If you're using a fork of zodern:relay, you should specify its Meteor import string here so imports\r\n * can be substituted with your fork. The Babel plugin currently injects a hardcoded import string for\r\n * client-code `zodern:relay/client`, so it's important we correct that before finishing the transform process.\r\n * @default 'meteor/zodern:relay'\r\n */\r\n relayPackageId?: string;\r\n}\r\n\r\ntype RelayInfo = {\r\n type: 'methods' | 'publications';\r\n id: string;\r\n relativePath: string;\r\n};\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA+B;AAC/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S,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,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
@@ -8,7 +8,8 @@ async function zodernRelay(options) {
8
8
  directories: {
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(options?.relayPackageId || "meteor/zodern:relay"))
12
13
  };
13
14
  const directories = [
14
15
  ...config.directories.methods.map((path) => ["methods", Path.relative(cwd, path)]),
@@ -35,7 +36,7 @@ async function zodernRelay(options) {
35
36
  return;
36
37
  }
37
38
  const code = FS.readFileSync(filename, "utf-8");
38
- if (!code.includes("meteor/zodern:relay")) {
39
+ if (!config.shouldTransform({ content: code, id: filename })) {
39
40
  return;
40
41
  }
41
42
  const transform = await transformAsync(code, {
@@ -54,8 +55,12 @@ async function zodernRelay(options) {
54
55
  if (!transform) {
55
56
  return;
56
57
  }
58
+ let newCode = transform.code ?? "";
59
+ if (options?.relayPackageId) {
60
+ newCode = newCode.replace("meteor/zodern:relay", options.relayPackageId);
61
+ }
57
62
  return {
58
- code: transform.code ?? ""
63
+ code: newCode
59
64
  };
60
65
  }
61
66
  };
@@ -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 } 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 (!code.includes('meteor/zodern:relay')) {\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\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,aAA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;","names":[]}
1
+ {"version":3,"sources":["../src/Plugin.ts"],"sourcesContent":["import { transformAsync } from '@babel/core';\r\nimport FS from 'fs';\r\nimport Path from 'path';\r\nimport { type Plugin } from 'vite';\r\n\r\nconst cwd = process.cwd();\r\n\r\nexport default async function zodernRelay(options?: Options): Promise<Plugin> {\r\n const config = {\r\n directories: {\r\n methods: options?.directories?.methods || ['./imports/methods'],\r\n publications: options?.directories?.publications || ['./imports/publications'],\r\n },\r\n shouldTransform: options?.shouldTransform || (({ content }) => content.includes(options?.relayPackageId || 'meteor/zodern:relay')),\r\n } satisfies Options;\r\n \r\n const directories = [\r\n ...config.directories.methods.map((path) => ['methods', Path.relative(cwd, path)]),\r\n ...config.directories.publications.map((path) => ['publications', Path.relative(cwd, path)])\r\n ] as [RelayInfo['type'], string][];\r\n \r\n function resolveRelay(id: string): RelayInfo | undefined {\r\n const relativePath = Path.relative(cwd, id);\r\n for (const [type, directory] of directories) {\r\n if (!relativePath.startsWith(directory)) {\r\n continue;\r\n }\r\n return {\r\n id,\r\n type,\r\n relativePath,\r\n }\r\n }\r\n }\r\n \r\n return {\r\n name: 'zodern-relay',\r\n async load(filename) {\r\n const relay = resolveRelay(filename || '');\r\n \r\n if (!relay) {\r\n return;\r\n }\r\n \r\n const code = FS.readFileSync(filename, 'utf-8');\r\n \r\n // Prevent transforming files that don't use zodern:relay\r\n if (!config.shouldTransform({ content: code, id: filename })) {\r\n return;\r\n }\r\n \r\n const transform = await transformAsync(code, {\r\n configFile: false,\r\n babelrc: false,\r\n filename,\r\n presets: ['@babel/preset-typescript'], // Add TypeScript preset\r\n plugins: ['@zodern/babel-plugin-meteor-relay'],\r\n caller: {\r\n name: '@meteor-vite/plugin-zodern-relay',\r\n \r\n // @ts-expect-error No type definition for this, but it's required by the Babel plugin.\r\n arch: 'web.browser.vite',\r\n }\r\n });\r\n \r\n if (!transform) {\r\n return;\r\n }\r\n \r\n let newCode = transform.code ?? '';\r\n \r\n // Rewrite any newly added imports to use the correct package ID.\r\n // Only applicable when using a fork of zodern:relay.\r\n if (options?.relayPackageId) {\r\n newCode = newCode.replace('meteor/zodern:relay', options.relayPackageId);\r\n }\r\n \r\n return {\r\n code: newCode,\r\n }\r\n }\r\n }\r\n \r\n \r\n}\r\nexport interface Options {\r\n directories?: {\r\n /**\r\n * Path to directories where your zodern:relay methods live\r\n * @default ['./imports/methods']\r\n */\r\n methods?: string[],\r\n \r\n /**\r\n * Path to the directories where your zodern:relay publications live.\r\n * @default ['./imports/publications']\r\n */\r\n publications?: string[],\r\n }\r\n /**\r\n * Specify a custom filter to determine whether a module should be transformed with zodern:relay.\r\n * Used to prevent unnecessary Babel transformations.\r\n * @default ({ content }) => content.includes('meteor/zodern:relay')\r\n * @param id\r\n */\r\n shouldTransform?: (file: { content: string, id: string }) => boolean;\r\n \r\n /**\r\n * If you're using a fork of zodern:relay, you should specify its Meteor import string here so imports\r\n * can be substituted with your fork. The Babel plugin currently injects a hardcoded import string for\r\n * client-code `zodern:relay/client`, so it's important we correct that before finishing the transform process.\r\n * @default 'meteor/zodern:relay'\r\n */\r\n relayPackageId?: string;\r\n}\r\n\r\ntype RelayInfo = {\r\n type: 'methods' | 'publications';\r\n id: string;\r\n relativePath: string;\r\n};\r\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,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plugin-zodern-relay",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
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
@@ -1,97 +1,121 @@
1
- import { transformAsync } from '@babel/core';
2
- import FS from 'fs';
3
- import Path from 'path';
4
- import { type Plugin } from 'vite';
5
-
6
- const cwd = process.cwd();
7
-
8
- export default async function zodernRelay(options?: Options): Promise<Plugin> {
9
- const config = {
10
- directories: {
11
- methods: options?.directories?.methods || ['./imports/methods'],
12
- publications: options?.directories?.publications || ['./imports/publications'],
13
- }
14
- } satisfies Options;
15
-
16
- const directories = [
17
- ...config.directories.methods.map((path) => ['methods', Path.relative(cwd, path)]),
18
- ...config.directories.publications.map((path) => ['publications', Path.relative(cwd, path)])
19
- ] as [RelayInfo['type'], string][];
20
-
21
- function resolveRelay(id: string): RelayInfo | undefined {
22
- const relativePath = Path.relative(cwd, id);
23
- for (const [type, directory] of directories) {
24
- if (!relativePath.startsWith(directory)) {
25
- continue;
26
- }
27
- return {
28
- id,
29
- type,
30
- relativePath,
31
- }
32
- }
33
- }
34
-
35
- return {
36
- name: 'zodern-relay',
37
- async load(filename) {
38
- const relay = resolveRelay(filename || '');
39
-
40
- if (!relay) {
41
- return;
42
- }
43
-
44
- const code = FS.readFileSync(filename, 'utf-8');
45
-
46
- // Prevent transforming files that don't use zodern:relay
47
- if (!code.includes('meteor/zodern:relay')) {
48
- return;
49
- }
50
-
51
- const transform = await transformAsync(code, {
52
- configFile: false,
53
- babelrc: false,
54
- filename,
55
- presets: ['@babel/preset-typescript'], // Add TypeScript preset
56
- plugins: ['@zodern/babel-plugin-meteor-relay'],
57
- caller: {
58
- name: '@meteor-vite/plugin-zodern-relay',
59
-
60
- // @ts-expect-error No type definition for this, but it's required by the Babel plugin.
61
- arch: 'web.browser.vite',
62
- }
63
- });
64
-
65
- if (!transform) {
66
- return;
67
- }
68
-
69
- return {
70
- code: transform.code ?? '',
71
- }
72
- }
73
- }
74
-
75
-
76
- }
77
- export interface Options {
78
- directories?: {
79
- /**
80
- * Path to directories where your zodern:relay methods live
81
- * @default ['./imports/methods']
82
- */
83
- methods?: string[],
84
-
85
- /**
86
- * Path to the directories where your zodern:relay publications live.
87
- * @default ['./imports/publications']
88
- */
89
- publications?: string[],
90
- }
91
- }
92
-
93
- type RelayInfo = {
94
- type: 'methods' | 'publications';
95
- id: string;
96
- relativePath: string;
97
- };
1
+ import { transformAsync } from '@babel/core';
2
+ import FS from 'fs';
3
+ import Path from 'path';
4
+ import { type Plugin } from 'vite';
5
+
6
+ const cwd = process.cwd();
7
+
8
+ export default async function zodernRelay(options?: Options): Promise<Plugin> {
9
+ const config = {
10
+ directories: {
11
+ methods: options?.directories?.methods || ['./imports/methods'],
12
+ publications: options?.directories?.publications || ['./imports/publications'],
13
+ },
14
+ shouldTransform: options?.shouldTransform || (({ content }) => content.includes(options?.relayPackageId || 'meteor/zodern:relay')),
15
+ } satisfies Options;
16
+
17
+ const directories = [
18
+ ...config.directories.methods.map((path) => ['methods', Path.relative(cwd, path)]),
19
+ ...config.directories.publications.map((path) => ['publications', Path.relative(cwd, path)])
20
+ ] as [RelayInfo['type'], string][];
21
+
22
+ function resolveRelay(id: string): RelayInfo | undefined {
23
+ const relativePath = Path.relative(cwd, id);
24
+ for (const [type, directory] of directories) {
25
+ if (!relativePath.startsWith(directory)) {
26
+ continue;
27
+ }
28
+ return {
29
+ id,
30
+ type,
31
+ relativePath,
32
+ }
33
+ }
34
+ }
35
+
36
+ return {
37
+ name: 'zodern-relay',
38
+ async load(filename) {
39
+ const relay = resolveRelay(filename || '');
40
+
41
+ if (!relay) {
42
+ return;
43
+ }
44
+
45
+ const code = FS.readFileSync(filename, 'utf-8');
46
+
47
+ // Prevent transforming files that don't use zodern:relay
48
+ if (!config.shouldTransform({ content: code, id: filename })) {
49
+ return;
50
+ }
51
+
52
+ const transform = await transformAsync(code, {
53
+ configFile: false,
54
+ babelrc: false,
55
+ filename,
56
+ presets: ['@babel/preset-typescript'], // Add TypeScript preset
57
+ plugins: ['@zodern/babel-plugin-meteor-relay'],
58
+ caller: {
59
+ name: '@meteor-vite/plugin-zodern-relay',
60
+
61
+ // @ts-expect-error No type definition for this, but it's required by the Babel plugin.
62
+ arch: 'web.browser.vite',
63
+ }
64
+ });
65
+
66
+ if (!transform) {
67
+ return;
68
+ }
69
+
70
+ let newCode = transform.code ?? '';
71
+
72
+ // Rewrite any newly added imports to use the correct package ID.
73
+ // Only applicable when using a fork of zodern:relay.
74
+ if (options?.relayPackageId) {
75
+ newCode = newCode.replace('meteor/zodern:relay', options.relayPackageId);
76
+ }
77
+
78
+ return {
79
+ code: newCode,
80
+ }
81
+ }
82
+ }
83
+
84
+
85
+ }
86
+ export interface Options {
87
+ directories?: {
88
+ /**
89
+ * Path to directories where your zodern:relay methods live
90
+ * @default ['./imports/methods']
91
+ */
92
+ methods?: string[],
93
+
94
+ /**
95
+ * Path to the directories where your zodern:relay publications live.
96
+ * @default ['./imports/publications']
97
+ */
98
+ publications?: string[],
99
+ }
100
+ /**
101
+ * Specify a custom filter to determine whether a module should be transformed with zodern:relay.
102
+ * Used to prevent unnecessary Babel transformations.
103
+ * @default ({ content }) => content.includes('meteor/zodern:relay')
104
+ * @param id
105
+ */
106
+ shouldTransform?: (file: { content: string, id: string }) => boolean;
107
+
108
+ /**
109
+ * If you're using a fork of zodern:relay, you should specify its Meteor import string here so imports
110
+ * can be substituted with your fork. The Babel plugin currently injects a hardcoded import string for
111
+ * client-code `zodern:relay/client`, so it's important we correct that before finishing the transform process.
112
+ * @default 'meteor/zodern:relay'
113
+ */
114
+ relayPackageId?: string;
115
+ }
116
+
117
+ type RelayInfo = {
118
+ type: 'methods' | 'publications';
119
+ id: string;
120
+ relativePath: string;
121
+ };