react-email-rails 0.1.1 → 0.1.2
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 +13 -0
- package/dist/index.js +35 -26
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/index.ts +35 -26
- package/src/version.ts +1 -1
package/bin/dev.mjs
CHANGED
|
@@ -19,7 +19,19 @@ const logger = {
|
|
|
19
19
|
hasWarned: false,
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
const divertStdout = () => {
|
|
23
|
+
const write = process.stdout.write.bind(process.stdout)
|
|
24
|
+
process.stdout.write = (chunk, encoding, callback) => {
|
|
25
|
+
if (typeof encoding === "function") return process.stderr.write(chunk, encoding)
|
|
26
|
+
return process.stderr.write(chunk, encoding, callback)
|
|
27
|
+
}
|
|
28
|
+
return () => {
|
|
29
|
+
process.stdout.write = write
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
22
33
|
// Load only this plugin and aliases; host dev-server plugins have global side effects.
|
|
34
|
+
const restoreStdout = divertStdout()
|
|
23
35
|
const { userConfig, plugin, vite } = await loadReactEmailRailsConfig({
|
|
24
36
|
command: "serve",
|
|
25
37
|
mode: "development",
|
|
@@ -49,6 +61,7 @@ if (!isRunnableDevEnvironment(environment)) {
|
|
|
49
61
|
|
|
50
62
|
try {
|
|
51
63
|
const { run } = await environment.runner.import("virtual:react-email-rails/server")
|
|
64
|
+
restoreStdout()
|
|
52
65
|
await run()
|
|
53
66
|
} finally {
|
|
54
67
|
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
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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.
|
|
67
|
-
// dependencies by default so Rails runtime images do not need
|
|
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
|
+
export declare const VERSION = "0.1.2";
|
|
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
|
+
export const VERSION = "0.1.2";
|
|
2
2
|
export const RENDER_PROTOCOL_VERSION = 1;
|
package/package.json
CHANGED
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
|
|
85
|
-
|
|
86
|
-
|
|
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
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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.
|
|
114
|
-
// dependencies by default so Rails runtime images do not need
|
|
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/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = "0.1.
|
|
1
|
+
export const VERSION = "0.1.2"
|
|
2
2
|
export const RENDER_PROTOCOL_VERSION = 1
|