rails-vite-plugin 0.2.2 → 0.2.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/index.js CHANGED
@@ -74,6 +74,8 @@ export default function rails(options = {}) {
74
74
  const meta = { sourceDir, buildDir: effectiveBuildDir };
75
75
  if (entrypointsDir)
76
76
  meta.entrypointsDir = entrypointsDir;
77
+ if (resolvedSsr)
78
+ meta.ssrOutputDir = ssrOutDir;
77
79
  fs.writeFileSync(path.join(outDir, 'rails-vite.json'), JSON.stringify(meta));
78
80
  },
79
81
  transform(code) {
@@ -87,6 +89,8 @@ export default function rails(options = {}) {
87
89
  const meta = { url: devServerUrl, sourceDir, buildDir: effectiveBuildDir };
88
90
  if (entrypointsDir)
89
91
  meta.entrypointsDir = entrypointsDir;
92
+ if (resolvedSsr)
93
+ meta.ssrOutputDir = ssrOutDir;
90
94
  if (reactRefresh)
91
95
  meta.reactRefresh = true;
92
96
  fs.writeFileSync(devMetaPath, JSON.stringify(meta));
@@ -56,6 +56,9 @@ export default function jsbundling(options = {}) {
56
56
  outDir: userConfig.build?.outDir ?? ssrConfig.outDir,
57
57
  [bundlerOptionsKey]: {
58
58
  input: userBundlerInput ?? ssrConfig.entry,
59
+ output: {
60
+ assetFileNames: '[name][extname]',
61
+ },
59
62
  },
60
63
  },
61
64
  } : {}),
@@ -194,6 +197,8 @@ export default function jsbundling(options = {}) {
194
197
  const meta = { url: devServerUrl, sourceDir };
195
198
  if (epDir)
196
199
  meta.entrypointsDir = epDir;
200
+ if (ssrConfig)
201
+ meta.ssrOutputDir = ssrConfig.outDir;
197
202
  if (reactRefresh)
198
203
  meta.reactRefresh = true;
199
204
  meta.jsbundling = true;
@@ -1,5 +1,6 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
+ import picomatch from 'picomatch';
3
4
  import { cssExtensionList } from './css.js';
4
5
  const jsExtensions = ['mjs', 'js', 'mts', 'ts', 'jsx', 'tsx'];
5
6
  const entrypointExtensions = new RegExp(`\\.(${[...jsExtensions, ...cssExtensionList].join('|')})$`);
@@ -13,7 +14,8 @@ export function resolveEntries(input, sourceDir) {
13
14
  sourcePath: prefixWithSourceDir(value, sourceDir),
14
15
  }));
15
16
  }
16
- const inputs = Array.isArray(input) ? input : [input];
17
+ const rawInputs = Array.isArray(input) ? input : [input];
18
+ const inputs = rawInputs.flatMap(entry => expandGlob(entry, sourceDir));
17
19
  const sourcePaths = inputs.map(entry => prefixWithSourceDir(entry, sourceDir));
18
20
  const commonPrefix = detectCommonEntryPrefix(sourcePaths, sourceDir);
19
21
  return sourcePaths.map(sourcePath => ({
@@ -65,6 +67,52 @@ export function detectEntrypoint(sourceDir) {
65
67
  }
66
68
  return 'application.js';
67
69
  }
70
+ function isGlob(pattern) {
71
+ return /[*?{]/.test(pattern);
72
+ }
73
+ function expandGlob(entry, sourceDir) {
74
+ if (!isGlob(entry))
75
+ return [entry];
76
+ const matcher = picomatch(entry);
77
+ if (entry.includes('**')) {
78
+ // Recursive: find the static prefix directory, then walk it
79
+ const parts = entry.split('/');
80
+ const staticParts = [];
81
+ for (const part of parts) {
82
+ if (isGlob(part))
83
+ break;
84
+ staticParts.push(part);
85
+ }
86
+ const baseDir = staticParts.length > 0
87
+ ? path.join(sourceDir, ...staticParts)
88
+ : sourceDir;
89
+ if (!fs.existsSync(baseDir))
90
+ return [];
91
+ return walkDir(baseDir, sourceDir).filter(f => matcher(f));
92
+ }
93
+ // Non-recursive: single directory match
94
+ const dir = path.join(sourceDir, path.dirname(entry));
95
+ const pattern = path.basename(entry);
96
+ const fileMatcher = picomatch(pattern);
97
+ if (!fs.existsSync(dir))
98
+ return [];
99
+ return fs.readdirSync(dir, { withFileTypes: true })
100
+ .filter(f => f.isFile() && fileMatcher(f.name))
101
+ .map(f => path.relative(sourceDir, path.join(dir, f.name)));
102
+ }
103
+ function walkDir(dir, baseDir) {
104
+ const results = [];
105
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
106
+ const full = path.join(dir, entry.name);
107
+ if (entry.isDirectory()) {
108
+ results.push(...walkDir(full, baseDir));
109
+ }
110
+ else if (entry.isFile()) {
111
+ results.push(path.relative(baseDir, full));
112
+ }
113
+ }
114
+ return results;
115
+ }
68
116
  function discoverEntrypoints(dir, base = dir) {
69
117
  const entries = [];
70
118
  for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rails-vite-plugin",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Vite plugin for Rails integration",
5
5
  "author": "Svyatoslav Kryukov <me@skryukov.dev>",
6
6
  "license": "MIT",