rails-jsdom 0.3.0 → 0.3.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/rails_jsdom/runtime.js +19 -3
- data/lib/rails_jsdom/version.rb +1 -1
- data/lib/rails_jsdom.rb +14 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7fc4428dc052f17cd0c104a9f4712ec1021ed0595f7568b81ce94332e3b89fb3
|
|
4
|
+
data.tar.gz: 63c7b612afe81fb9ec93e08443a728c4f0d82d7f1633484ebd55b16761d29850
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 552c35d2b8dbf2a16c3411dc9114621fd4dd7867ead9739ec077102c00e56dbf68b417ba9d10630697d834a8988a60b77bdf71f66e796782f50016f3e0e43675
|
|
7
|
+
data.tar.gz: 3c65b0ad230fdbb3cbb94809f3456a4b20fbb45d1b9a5b86543f96cce31d9eebaea799d3912224b152f91d2ce77cf785b0f438e73648bb7bd728fc84125a6078
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.1 (2026-11-30)
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- Importing an importmap pin whose file is not in the asset load path, such as `pin "blocks/pele", to: "pele_block.js"` before `pele_block.js` exists or is built, fails with an error that names the pin and its file, when the import runs, as in a browser. Before, building the bundle failed with a path nobody wrote, such as `Cannot read file: app/javascript/blocks/pele.js` when a `pin_all_from` directory shared the pin's prefix, and a dynamic import of it failed with no word of the pin. A file of the pin's name in a `pin_all_from` directory is still used instead, as importmap-rails maps it.
|
|
8
|
+
|
|
3
9
|
## 0.3.0 (2026-11-28)
|
|
4
10
|
|
|
5
11
|
### Added
|
data/lib/rails_jsdom/runtime.js
CHANGED
|
@@ -8,6 +8,7 @@ const { createRequire } = require("node:module")
|
|
|
8
8
|
const { pathToFileURL } = require("node:url")
|
|
9
9
|
|
|
10
10
|
const STUB_NAMESPACE = "rails-jsdom-stub"
|
|
11
|
+
const MISSING_NAMESPACE = "rails-jsdom-missing-pin"
|
|
11
12
|
const STUB_SOURCE = "module.exports = Object.create(new Proxy({}, { get: (target, key) => typeof key === 'symbol' || key === 'then' || key === '__esModule' ? undefined : () => {} }))"
|
|
12
13
|
const STIMULUS_LOADING = "@hotwired/stimulus-loading"
|
|
13
14
|
const INLINE_ELEMENTS = new Set(["a", "abbr", "b", "bdi", "bdo", "cite", "code", "data", "dfn", "em", "i", "kbd", "label", "mark", "output", "q", "s", "samp", "small", "span", "strong", "sub", "sup", "time", "u", "var"])
|
|
@@ -232,6 +233,7 @@ function importmapPlugin() {
|
|
|
232
233
|
setup(build) {
|
|
233
234
|
build.onResolve({ filter: /^[^./]/ }, args => resolveImport(args.path) ?? unresolvedImport(args))
|
|
234
235
|
build.onLoad({ filter: /.*/, namespace: STUB_NAMESPACE }, () => ({ contents: STUB_SOURCE, loader: "js" }))
|
|
236
|
+
build.onLoad({ filter: /.*/, namespace: MISSING_NAMESPACE }, args => ({ contents: missingPinSource(args.path), loader: "js" }))
|
|
235
237
|
}
|
|
236
238
|
}
|
|
237
239
|
}
|
|
@@ -245,12 +247,26 @@ function bundlesFromNodeModules(specifier) {
|
|
|
245
247
|
}
|
|
246
248
|
|
|
247
249
|
function resolveImport(specifier) {
|
|
248
|
-
const directory = Object.keys(config.directories).find(prefix => specifier.startsWith(`${prefix}/`))
|
|
249
250
|
if (specifier === STIMULUS_LOADING || config.stubs.includes(specifier)) return { path: specifier, namespace: STUB_NAMESPACE }
|
|
250
251
|
if (config.modules[specifier]) return { path: config.modules[specifier] }
|
|
251
252
|
if (config.directories[specifier]) return { path: path.join(config.directories[specifier], "index.js") }
|
|
252
|
-
|
|
253
|
-
|
|
253
|
+
return directoryImport(specifier, directoryFile(specifier))
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function directoryFile(specifier) {
|
|
257
|
+
const directory = Object.keys(config.directories).find(prefix => specifier.startsWith(`${prefix}/`))
|
|
258
|
+
return directory ? `${path.join(config.directories[directory], specifier.slice(directory.length + 1))}.js` : undefined
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function directoryImport(specifier, file) {
|
|
262
|
+
const target = config.missing[specifier]
|
|
263
|
+
if (target && !(file && fs.existsSync(file))) return { path: specifier, namespace: MISSING_NAMESPACE }
|
|
264
|
+
return file ? { path: file } : undefined
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function missingPinSource(specifier) {
|
|
268
|
+
const message = `RailsJsdom: pin "${specifier}" points to "${config.missing[specifier]}", which is not in the asset load path. Create the file, build your assets if a build step makes it, or remove the pin.`
|
|
269
|
+
return `throw new Error(${JSON.stringify(message)})`
|
|
254
270
|
}
|
|
255
271
|
|
|
256
272
|
class Clock {
|
data/lib/rails_jsdom/version.rb
CHANGED
data/lib/rails_jsdom.rb
CHANGED
|
@@ -59,6 +59,7 @@ module RailsJsdom
|
|
|
59
59
|
entry: app_path(entry),
|
|
60
60
|
esbuild: app_path(esbuild_config),
|
|
61
61
|
modules: modules,
|
|
62
|
+
missing: missing_modules,
|
|
62
63
|
stubs: remote_modules,
|
|
63
64
|
directories: directories,
|
|
64
65
|
horizon: TIMER_HORIZON,
|
|
@@ -67,7 +68,11 @@ module RailsJsdom
|
|
|
67
68
|
end
|
|
68
69
|
|
|
69
70
|
def modules
|
|
70
|
-
|
|
71
|
+
local_packages.transform_values { |path| asset_file(path) }
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def missing_modules
|
|
75
|
+
local_packages.reject { |_name, path| asset_file(path) }
|
|
71
76
|
end
|
|
72
77
|
|
|
73
78
|
def remote_modules
|
|
@@ -111,6 +116,14 @@ module RailsJsdom
|
|
|
111
116
|
importmap ? importmap.packages.transform_values(&:path) : {}
|
|
112
117
|
end
|
|
113
118
|
|
|
119
|
+
def local_packages
|
|
120
|
+
packages.reject { |_name, path| path.match?(REMOTE) }
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def asset_file(path)
|
|
124
|
+
Rails.application.assets.load_path.find(path)&.path&.to_s
|
|
125
|
+
end
|
|
126
|
+
|
|
114
127
|
def importmap_directories
|
|
115
128
|
importmap = Rails.application.try(:importmap)
|
|
116
129
|
importmap ? importmap.directories.values : []
|