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

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
@@ -14,6 +14,16 @@ 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;
17
27
  }
18
28
 
19
29
  export { type Options, zodernRelay as default };
package/dist/Plugin.d.ts CHANGED
@@ -14,6 +14,16 @@ 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;
17
27
  }
18
28
 
19
29
  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("meteor/zodern:relay"))
46
47
  };
47
48
  const directories = [
48
49
  ...config.directories.methods.map((path) => ["methods", import_path.default.relative(cwd, path)]),
@@ -69,10 +70,15 @@ async function zodernRelay(options) {
69
70
  return;
70
71
  }
71
72
  const code = import_fs.default.readFileSync(filename, "utf-8");
73
+ if (!config.shouldTransform({ content: code, id: filename })) {
74
+ return;
75
+ }
72
76
  const transform = await (0, import_core.transformAsync)(code, {
73
77
  configFile: false,
74
78
  babelrc: false,
75
79
  filename,
80
+ presets: ["@babel/preset-typescript"],
81
+ // Add TypeScript preset
76
82
  plugins: ["@zodern/babel-plugin-meteor-relay"],
77
83
  caller: {
78
84
  name: "@meteor-vite/plugin-zodern-relay",
@@ -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 if (!relay) {\n return;\n }\n const code = FS.readFileSync(filename, 'utf-8');\n const transform = await transformAsync(code, {\n configFile: false,\n babelrc: false,\n filename,\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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ACJ,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('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"]}
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("meteor/zodern:relay"))
12
13
  };
13
14
  const directories = [
14
15
  ...config.directories.methods.map((path) => ["methods", Path.relative(cwd, path)]),
@@ -35,10 +36,15 @@ async function zodernRelay(options) {
35
36
  return;
36
37
  }
37
38
  const code = FS.readFileSync(filename, "utf-8");
39
+ if (!config.shouldTransform({ content: code, id: filename })) {
40
+ return;
41
+ }
38
42
  const transform = await transformAsync(code, {
39
43
  configFile: false,
40
44
  babelrc: false,
41
45
  filename,
46
+ presets: ["@babel/preset-typescript"],
47
+ // Add TypeScript preset
42
48
  plugins: ["@zodern/babel-plugin-meteor-relay"],
43
49
  caller: {
44
50
  name: "@meteor-vite/plugin-zodern-relay",
@@ -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 if (!relay) {\n return;\n }\n const code = FS.readFileSync(filename, 'utf-8');\n const transform = await transformAsync(code, {\n configFile: false,\n babelrc: false,\n filename,\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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ugin.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":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meteor-vite/plugin-zodern-relay",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Vite compatability plugin for zodern:relay - typed Meteor methods and publications",
5
5
  "main": "dist/Plugin.js",
6
6
  "exports": {
@@ -22,7 +22,8 @@
22
22
  "lint": "tsc --noEmit",
23
23
  "test": "npm run lint",
24
24
  "build": "tsup",
25
- "prepack": "npm run build"
25
+ "prepack": "npm run build",
26
+ "prepare": "npm run build || echo 'Warning: Failed to prepare package!' && exit 0"
26
27
  },
27
28
  "keywords": [
28
29
  "meteor-vite",
@@ -40,6 +41,7 @@
40
41
  "url": "https://github.com/JorgenVatle/meteor-vite"
41
42
  },
42
43
  "devDependencies": {
44
+ "@babel/preset-typescript": "^7.24.7",
43
45
  "@types/babel__core": "^7.20.5",
44
46
  "tsup": "^8.0.2",
45
47
  "typescript": "^5.4.2",
package/src/Plugin.ts CHANGED
@@ -10,7 +10,8 @@ export default async function zodernRelay(options?: Options): Promise<Plugin> {
10
10
  directories: {
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
15
  } satisfies Options;
15
16
 
16
17
  const directories = [
@@ -36,14 +37,23 @@ export default async function zodernRelay(options?: Options): Promise<Plugin> {
36
37
  name: 'zodern-relay',
37
38
  async load(filename) {
38
39
  const relay = resolveRelay(filename || '');
40
+
39
41
  if (!relay) {
40
42
  return;
41
43
  }
44
+
42
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
+
43
52
  const transform = await transformAsync(code, {
44
53
  configFile: false,
45
54
  babelrc: false,
46
55
  filename,
56
+ presets: ['@babel/preset-typescript'], // Add TypeScript preset
47
57
  plugins: ['@zodern/babel-plugin-meteor-relay'],
48
58
  caller: {
49
59
  name: '@meteor-vite/plugin-zodern-relay',
@@ -79,6 +89,13 @@ export interface Options {
79
89
  */
80
90
  publications?: string[],
81
91
  }
92
+ /**
93
+ * Specify a custom filter to determine whether a module should be transformed with zodern:relay.
94
+ * Used to prevent unnecessary Babel transformations.
95
+ * @default ({ content }) => content.includes('meteor/zodern:relay')
96
+ * @param id
97
+ */
98
+ shouldTransform?: (file: { content: string, id: string }) => boolean;
82
99
  }
83
100
 
84
101
  type RelayInfo = {