jspm-rails 0.2.0 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 647327a342d54b7e908d058985494a887120aebb49c07e6f220af7b843252ea7
4
- data.tar.gz: 8595959e6a8e642ef2fb5c419274401afdad6b0caad89d32ab846ccda49da646
3
+ metadata.gz: 2066a105c29bf4cebd19a25c1afa9ac3bfb7530b080cd5f347ed1c69e3cd56b2
4
+ data.tar.gz: 1e89f49cd667a1b7771b90b2df5a8d36918d0cdb78334fe6cdee6d831d470fcc
5
5
  SHA512:
6
- metadata.gz: 5fdfb17f58799c9cf1755352615eb27a01b48a3bd219b2dcac1ecdd2a1e93090e678b6ef77691095fe58fecb079ffac5bf03e211d1913e59d66181f151793e96
7
- data.tar.gz: d4490661eaaa59ef3ba76ade81c6659e4db588e4ea692a9bd6d74c17c4f3619b272e9710110c2adca8228b17245b38d3879b113544004e0928ea546a89a1d5b1
6
+ metadata.gz: 4253a93277d3368d3e2e34fe023aeee5ac6d74090417941e36056ea65ccffb3f9465909e036ae52a00caa3bb403ef0b3d9ee7e6de26299b0f741487baf11fa30
7
+ data.tar.gz: 330b9d72f4d2b528aa4701d655cc066adf83da4fbfef4f718eb472c624d0398f52542e05ee84b97bfc3b25d4219f227e25ba2f02bc7aab9bd524cefc8ddae6ef
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0 (unreleased)
4
+
5
+ - Names every module in `app/javascript` in the import map, so stimulus-rails's `eagerLoadControllersFrom` finds controllers.
6
+
3
7
  ## 0.2.0 (unreleased)
4
8
 
5
9
  - Reads Yarn 1's `yarn.lock` as well as `package-lock.json`.
data/README.md CHANGED
@@ -1,10 +1,4 @@
1
- ```
2
- _ _ _
3
- (_) ___ _ __ _ __ _ _ __ _ (_)| | ___
4
- | |(_-<| '_ \| ' \ ___ | '_|/ _` || || |(_-<
5
- _/ |/__/| .__/|_|_|_||___||_| \__,_||_||_|/__/
6
- |__/ |_|
7
- ```
1
+ <p align="center"><img src="docs/banner.svg" alt="jspm-rails" width="576"></p>
8
2
 
9
3
  [![CI](https://github.com/ClayShentrup/jspm-rails/actions/workflows/ci.yml/badge.svg)](https://github.com/ClayShentrup/jspm-rails/actions/workflows/ci.yml)
10
4
 
@@ -95,6 +89,8 @@ import 'controllers' // app/javascript/controllers/index.js
95
89
  import { helper } from './helpers.js'
96
90
  ```
97
91
 
92
+ **Every module in `app/javascript` is in the import map by name,** even ones nothing imports directly, as importmap-rails's `pin_all_from` names them. So stimulus-rails's `eagerLoadControllersFrom("controllers", application)` and `lazyLoadControllersFrom` work unchanged.
93
+
98
94
  **Import modules that gems ship the same way.** Every engine's `app/assets` directories are on Propshaft's load path, so a gem's modules are importable by asset name with no setup:
99
95
 
100
96
  ```js
data/lib/jspm/paths.rb CHANGED
@@ -12,7 +12,8 @@ module Jspm
12
12
  ENTRY_PATH = "#{LOCAL}#{ENTRY}".freeze
13
13
  IMPORT_MAP = 'config/importmap.json'
14
14
  VENDOR = 'vendor/jspm'
15
- public_constant :CDN, :ENTRY, :ENTRY_PATH, :IMPORT_MAP, :LOCAL, :VENDOR
15
+ public_constant :CDN, :ENTRY, :ENTRY_PATH, :IMPORT_MAP, :VENDOR
16
+ private_constant :LOCAL
16
17
 
17
18
  def self.logical(url)
18
19
  return url.delete_prefix('https://').sub('/npm:', '/npm/') if url.start_with?(CDN)
data/lib/jspm/tags.rb CHANGED
@@ -9,7 +9,7 @@ module Jspm
9
9
  # imports name its siblings undigested. So the rendered map also sends each
10
10
  # undigested module URL to its digested one.
11
11
  class Tags
12
- MODULE_EXTENSIONS = %w[.css .js .mjs].freeze
12
+ MODULE_EXTENSIONS = %w[.js .mjs].freeze
13
13
  private_constant :MODULE_EXTENSIONS
14
14
 
15
15
  def self.call(view:)
data/lib/jspm/trace.mjs CHANGED
@@ -8,7 +8,7 @@ import { readFileSync } from 'node:fs';
8
8
  import { createRequire } from 'node:module';
9
9
  import { fileURLToPath, pathToFileURL } from 'node:url';
10
10
 
11
- const { entry, inputMap, resolutions, root } = JSON.parse(readFileSync(0, 'utf8'));
11
+ const { entries, inputMap, resolutions, root } = JSON.parse(readFileSync(0, 'utf8'));
12
12
  const rootUrl = pathToFileURL(`${root}/`);
13
13
  const generatorPath = createRequire(rootUrl).resolve('@jspm/generator');
14
14
  const { Generator } = await import(pathToFileURL(generatorPath));
@@ -37,7 +37,7 @@ const generator = new Generator({
37
37
  resolutions,
38
38
  });
39
39
 
40
- const { dynamicDeps, staticDeps } = await generator.link(entry);
40
+ const { dynamicDeps, staticDeps } = await generator.link(entries);
41
41
  const map = generator.getMap();
42
42
 
43
43
  process.stdout.write(
data/lib/jspm/trace.rb CHANGED
@@ -21,8 +21,14 @@ module Jspm
21
21
  # A package the app installed beats a gem's file of the same name, such
22
22
  # as actiontext's trix.js, so the app and its packages share one copy.
23
23
  pins = local_modules.pins.reject { |name, _path| resolutions.key?(name) }
24
+ # Every app module is traced and named in the map, as importmap-rails
25
+ # pins them, so code can import one by a name it computes, the way
26
+ # stimulus-rails's eagerLoadControllersFrom does.
27
+ app_dir = root.join('app/javascript').to_s
28
+ app_modules = pins.select { |_name, path| path.start_with?(app_dir) }
29
+ .keys
24
30
  input = JSON.generate(
25
- entry: Paths::ENTRY_PATH,
31
+ entries: [Paths::ENTRY_PATH, *app_modules],
26
32
  inputMap: { imports: locked_versions(root).merge(pins), scopes: {} },
27
33
  resolutions:,
28
34
  root: root.to_s
data/lib/jspm/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jspm
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  public_constant :VERSION
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jspm-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clay Shentrup