react-email-rails 0.1.1 → 0.1.3

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/bin/dev.mjs CHANGED
@@ -4,7 +4,9 @@ import { fail, isolatedViteConfig, loadReactEmailRailsConfig } from "./shared.mj
4
4
  import { RENDER_PROTOCOL_VERSION, VERSION } from "../dist/version.js"
5
5
 
6
6
  if (process.argv.includes("--health")) {
7
- process.stdout.write(JSON.stringify({ ok: true, protocolVersion: RENDER_PROTOCOL_VERSION, packageVersion: VERSION }))
7
+ process.stdout.write(
8
+ JSON.stringify({ ok: true, protocolVersion: RENDER_PROTOCOL_VERSION, packageVersion: VERSION }),
9
+ )
8
10
  process.exit(0)
9
11
  }
10
12
 
@@ -19,7 +21,19 @@ const logger = {
19
21
  hasWarned: false,
20
22
  }
21
23
 
24
+ const divertStdout = () => {
25
+ const write = process.stdout.write.bind(process.stdout)
26
+ process.stdout.write = (chunk, encoding, callback) => {
27
+ if (typeof encoding === "function") return process.stderr.write(chunk, encoding)
28
+ return process.stderr.write(chunk, encoding, callback)
29
+ }
30
+ return () => {
31
+ process.stdout.write = write
32
+ }
33
+ }
34
+
22
35
  // Load only this plugin and aliases; host dev-server plugins have global side effects.
36
+ const restoreStdout = divertStdout()
23
37
  const { userConfig, plugin, vite } = await loadReactEmailRailsConfig({
24
38
  command: "serve",
25
39
  mode: "development",
@@ -49,6 +63,7 @@ if (!isRunnableDevEnvironment(environment)) {
49
63
 
50
64
  try {
51
65
  const { run } = await environment.runner.import("virtual:react-email-rails/server")
66
+ restoreStdout()
52
67
  await run()
53
68
  } finally {
54
69
  await server.close()
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ const VIRTUAL_SERVER = "virtual:react-email-rails/server";
4
4
  const VIRTUAL_MAIN = "virtual:react-email-rails/main";
5
5
  const RESOLVED_SERVER = `\0${VIRTUAL_SERVER}`;
6
6
  const RESOLVED_MAIN = `\0${VIRTUAL_MAIN}`;
7
+ const VIRTUAL_MODULE_PATTERN = /virtual:react-email-rails\/(?:server|main)$/;
7
8
  // The dedicated build environment that emits the server-side email bundle.
8
9
  export const EMAIL_ENVIRONMENT = "email";
9
10
  const CONFIG_SYMBOL = Symbol.for("react-email-rails.config");
@@ -35,40 +36,48 @@ export function reactEmailRails(options = {}) {
35
36
  const globArg = JSON.stringify(globPatterns.length === 1 ? globPatterns[0] : globPatterns);
36
37
  const plugin = {
37
38
  name: "react-email-rails",
38
- resolveId(id) {
39
- if (id === VIRTUAL_SERVER)
40
- return RESOLVED_SERVER;
41
- if (id === VIRTUAL_MAIN)
42
- return RESOLVED_MAIN;
39
+ resolveId: {
40
+ filter: { id: VIRTUAL_MODULE_PATTERN },
41
+ handler(id) {
42
+ if (id === VIRTUAL_SERVER)
43
+ return RESOLVED_SERVER;
44
+ if (id === VIRTUAL_MAIN)
45
+ return RESOLVED_MAIN;
46
+ },
43
47
  },
44
- load(id) {
45
- if (id === RESOLVED_SERVER) {
46
- return [
47
- `import { serve, toComponentName } from "react-email-rails/runtime"`,
48
- `const modules = import.meta.glob(${globArg})`,
49
- `const extensions = ${JSON.stringify(extensions)}`,
50
- `const registry = Object.create(null)`,
51
- `for (const path in modules) {`,
52
- ` const extension = extensions.find((extension) => path.endsWith(extension)) ?? path.slice(path.lastIndexOf("."))`,
53
- ` registry[toComponentName(path, ${JSON.stringify(root)}, extension)] = modules[path]`,
54
- `}`,
55
- `export const run = () => serve(registry)`,
56
- ].join("\n");
57
- }
58
- if (id === RESOLVED_MAIN) {
59
- return `import { run } from ${JSON.stringify(VIRTUAL_SERVER)}\nrun()\n`;
60
- }
48
+ load: {
49
+ filter: { id: VIRTUAL_MODULE_PATTERN },
50
+ handler(id) {
51
+ if (id === RESOLVED_SERVER) {
52
+ return [
53
+ `import { serve, toComponentName } from "react-email-rails/runtime"`,
54
+ `const modules = import.meta.glob(${globArg})`,
55
+ `const extensions = ${JSON.stringify(extensions)}`,
56
+ `const registry = Object.create(null)`,
57
+ `for (const path in modules) {`,
58
+ ` const extension = extensions.find((extension) => path.endsWith(extension)) ?? path.slice(path.lastIndexOf("."))`,
59
+ ` registry[toComponentName(path, ${JSON.stringify(root)}, extension)] = modules[path]`,
60
+ `}`,
61
+ `export const run = () => serve(registry)`,
62
+ ].join("\n");
63
+ }
64
+ if (id === RESOLVED_MAIN) {
65
+ return `import { run } from ${JSON.stringify(VIRTUAL_SERVER)}\nrun()\n`;
66
+ }
67
+ },
61
68
  },
62
- config() {
69
+ config(_config, env) {
63
70
  // Register a dedicated `email` build environment. The official
64
71
  // react-email-rails-build bin opts into building it with an isolated
65
72
  // plugin stack so host app plugins cannot break email SSR builds.
66
- // The environment is a server consumer. Standalone builds inline Node
67
- // dependencies by default so Rails runtime images do not need node_modules.
73
+ // The environment is a server consumer. Production standalone builds inline
74
+ // Node dependencies by default so Rails runtime images do not need
75
+ // node_modules; dev rendering keeps dependencies external for Vite's module
76
+ // runner.
68
77
  return {
69
78
  environments: {
70
79
  [EMAIL_ENVIRONMENT]: {
71
- ...(standalone ? { resolve: { noExternal: true } } : {}),
80
+ ...(standalone && env.command === "build" ? { resolve: { noExternal: true } } : {}),
72
81
  build: {
73
82
  ssr: true,
74
83
  outDir: OUT_DIR,
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.1.1";
1
+ export declare const VERSION = "0.1.3";
2
2
  export declare const RENDER_PROTOCOL_VERSION = 1;
package/dist/version.js CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = "0.1.1";
1
+ export const VERSION = "0.1.3";
2
2
  export const RENDER_PROTOCOL_VERSION = 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-email-rails",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Build and send emails using React and Rails",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Plugin, UserConfig } from "vite"
1
+ import type { ConfigEnv, Plugin, UserConfig } from "vite"
2
2
 
3
3
  export type EmailsOption =
4
4
  | string
@@ -39,6 +39,7 @@ const VIRTUAL_SERVER = "virtual:react-email-rails/server"
39
39
  const VIRTUAL_MAIN = "virtual:react-email-rails/main"
40
40
  const RESOLVED_SERVER = `\0${VIRTUAL_SERVER}`
41
41
  const RESOLVED_MAIN = `\0${VIRTUAL_MAIN}`
42
+ const VIRTUAL_MODULE_PATTERN = /virtual:react-email-rails\/(?:server|main)$/
42
43
 
43
44
  // The dedicated build environment that emits the server-side email bundle.
44
45
  export const EMAIL_ENVIRONMENT = "email"
@@ -81,41 +82,49 @@ export function reactEmailRails(options: ReactEmailRailsOptions = {}): Plugin {
81
82
  const plugin: Plugin = {
82
83
  name: "react-email-rails",
83
84
 
84
- resolveId(id) {
85
- if (id === VIRTUAL_SERVER) return RESOLVED_SERVER
86
- if (id === VIRTUAL_MAIN) return RESOLVED_MAIN
85
+ resolveId: {
86
+ filter: { id: VIRTUAL_MODULE_PATTERN },
87
+ handler(id) {
88
+ if (id === VIRTUAL_SERVER) return RESOLVED_SERVER
89
+ if (id === VIRTUAL_MAIN) return RESOLVED_MAIN
90
+ },
87
91
  },
88
92
 
89
- load(id) {
90
- if (id === RESOLVED_SERVER) {
91
- return [
92
- `import { serve, toComponentName } from "react-email-rails/runtime"`,
93
- `const modules = import.meta.glob(${globArg})`,
94
- `const extensions = ${JSON.stringify(extensions)}`,
95
- `const registry = Object.create(null)`,
96
- `for (const path in modules) {`,
97
- ` const extension = extensions.find((extension) => path.endsWith(extension)) ?? path.slice(path.lastIndexOf("."))`,
98
- ` registry[toComponentName(path, ${JSON.stringify(root)}, extension)] = modules[path]`,
99
- `}`,
100
- `export const run = () => serve(registry)`,
101
- ].join("\n")
102
- }
103
-
104
- if (id === RESOLVED_MAIN) {
105
- return `import { run } from ${JSON.stringify(VIRTUAL_SERVER)}\nrun()\n`
106
- }
93
+ load: {
94
+ filter: { id: VIRTUAL_MODULE_PATTERN },
95
+ handler(id) {
96
+ if (id === RESOLVED_SERVER) {
97
+ return [
98
+ `import { serve, toComponentName } from "react-email-rails/runtime"`,
99
+ `const modules = import.meta.glob(${globArg})`,
100
+ `const extensions = ${JSON.stringify(extensions)}`,
101
+ `const registry = Object.create(null)`,
102
+ `for (const path in modules) {`,
103
+ ` const extension = extensions.find((extension) => path.endsWith(extension)) ?? path.slice(path.lastIndexOf("."))`,
104
+ ` registry[toComponentName(path, ${JSON.stringify(root)}, extension)] = modules[path]`,
105
+ `}`,
106
+ `export const run = () => serve(registry)`,
107
+ ].join("\n")
108
+ }
109
+
110
+ if (id === RESOLVED_MAIN) {
111
+ return `import { run } from ${JSON.stringify(VIRTUAL_SERVER)}\nrun()\n`
112
+ }
113
+ },
107
114
  },
108
115
 
109
- config() {
116
+ config(_config, env: ConfigEnv) {
110
117
  // Register a dedicated `email` build environment. The official
111
118
  // react-email-rails-build bin opts into building it with an isolated
112
119
  // plugin stack so host app plugins cannot break email SSR builds.
113
- // The environment is a server consumer. Standalone builds inline Node
114
- // dependencies by default so Rails runtime images do not need node_modules.
120
+ // The environment is a server consumer. Production standalone builds inline
121
+ // Node dependencies by default so Rails runtime images do not need
122
+ // node_modules; dev rendering keeps dependencies external for Vite's module
123
+ // runner.
115
124
  return {
116
125
  environments: {
117
126
  [EMAIL_ENVIRONMENT]: {
118
- ...(standalone ? { resolve: { noExternal: true } } : {}),
127
+ ...(standalone && env.command === "build" ? { resolve: { noExternal: true } } : {}),
119
128
  build: {
120
129
  ssr: true,
121
130
  outDir: OUT_DIR,
package/src/runtime.ts CHANGED
@@ -134,7 +134,9 @@ async function writePersistentResponse(
134
134
  return
135
135
  }
136
136
 
137
- write(`${JSON.stringify({ ok: true, ...(await renderEmail(request, registry)), ...protocolMetadata() })}\n`)
137
+ write(
138
+ `${JSON.stringify({ ok: true, ...(await renderEmail(request, registry)), ...protocolMetadata() })}\n`,
139
+ )
138
140
  } catch (error) {
139
141
  write(
140
142
  `${JSON.stringify({
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = "0.1.1"
1
+ export const VERSION = "0.1.3"
2
2
  export const RENDER_PROTOCOL_VERSION = 1