proscenium 0.22.0.beta2-x86_64-linux → 0.22.0.beta3-x86_64-linux

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: a0676f0370ca3f4ee432b27550a798ba203111170b6985458e8fad28002c93b7
4
- data.tar.gz: 57ba3c548fae842fa107c1d06f2d5a37037aeae799b2c86896c35d9ba4de0701
3
+ metadata.gz: c361f5c69260d3dea1620432c797ddab37101f3ff51d046ce21fbddc0105b65a
4
+ data.tar.gz: cce30ee6481e16c6ebbe53959717214f6eedda804cac3d6e84f374ed117fb644
5
5
  SHA512:
6
- metadata.gz: d1cb772d5f1d227d51b24abbad01732bd164fbe1699f984ac76c5c31fe0bbeac93229e02e44ead1371653d0cc0ed16e95e2a1334d752768595673496b4e57c57
7
- data.tar.gz: aeb301fb4862a552a37e37a282fb956c9d70cdecae6031b94458de2389d9a2fc1070520a7e5e52454a97aa9399b0bd7f55a67cc8b894a2ce7bb62622bdb3953f
6
+ metadata.gz: e789f3b974d80aa9d087e1a4b33455a1d0e3f7c175c49301e0a19770df788c25ec2ab502079fc26198578d97da0e3ea9ceb2bf52cae4eed4988444be3007e1e4
7
+ data.tar.gz: b07424e2ba41a0d92c427316ba845f4f3e39fc65942b8e91e9807cb4a70c04435d8b93d8b59c4aa929fbdca9e4fbc04aa95ff8ce0fdfdb34686a01e495acff76
data/README.md CHANGED
@@ -18,7 +18,6 @@
18
18
  - Deep integration with Rails.
19
19
  - Automatically side-load JS and CSS for your layouts, views, and partials.
20
20
  - Import from NPM, URL's, and locally.
21
- - Server-side import map support.
22
21
  - CSS Modules & mixins.
23
22
  - Source maps.
24
23
 
@@ -30,7 +29,6 @@
30
29
  - [Side Loading](#side-loading)
31
30
  - [Importing](#importing-assets)
32
31
  - [Local Imports](#local-imports)
33
- - [Import Maps](#import-maps)
34
32
  - [Source Maps](#source-maps)
35
33
  - [SVG](#svg)
36
34
  - [Environment Variables](#environment-variables)
@@ -48,9 +46,9 @@
48
46
  - [Typescript Caveats](#typescript-caveats)
49
47
  - [JSX](#jsx)
50
48
  - [JSON](#json)
51
- - [Cache Busting](#cache-busting)
52
49
  - [rjs is back!](#rjs-is-back)
53
50
  - [Resolution](#resolution)
51
+ - [Pre-compilation](#precompilation)
54
52
  - [Thanks](#thanks)
55
53
  - [Development](#development)
56
54
 
@@ -258,13 +256,11 @@ Sometimes you don't want to bundle an import. For example, you want to ensure th
258
256
  import React from "react" with { unbundle: 'true' };
259
257
  ```
260
258
 
261
- You can also unbundle entries in your [import map](#import-maps) using an `unbundle:` prefix, which ensures that all imports of a particular path are always unbundled:
259
+ You can also unbundle entries in [`aliases`](#aliases) using an `unbundle:` prefix, which ensures that all imports of a particular path are always unbundled:
262
260
 
263
- ```json
264
- {
265
- "imports": {
266
- "react": "unbundle:react"
267
- }
261
+ ```ruby
262
+ config.proscenium.aliases = {
263
+ "react": "unbundle:react"
268
264
  }
269
265
  ```
270
266
 
@@ -282,55 +278,6 @@ config.proscenium.bundle = false
282
278
 
283
279
  This will mean every asset and import will be loaded independently.
284
280
 
285
- ## Import Maps
286
-
287
- > **[WIP]**
288
-
289
- [Import maps](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap) for both JS and CSS is supported out of the box, and works with no regard to the browser being used. This is because the import map is parsed and resolved by Proscenium on the server, instead of by the browser. This is faster, and also allows you to use import maps in browsers that do not support them yet.
290
-
291
- If you are not familiar with import maps, think of them as a way to define aliases.
292
-
293
- Just create `config/import_map.json` and specify the imports you want to use. For example:
294
-
295
- ```json
296
- {
297
- "imports": {
298
- "react": "https://esm.sh/react@18.2.0",
299
- "start": "/lib/start.js",
300
- "common": "/lib/common.css",
301
- "@radix-ui/colors/": "https://esm.sh/@radix-ui/colors@0.1.8/"
302
- }
303
- }
304
- ```
305
-
306
- Using the above import map, we can do...
307
-
308
- ```js
309
- import { useCallback } from "react";
310
- import startHere from "start";
311
- import styles from "common";
312
- ```
313
-
314
- and for CSS...
315
-
316
- ```css
317
- @import "common";
318
- @import "@radix-ui/colors/blue.css";
319
- ```
320
-
321
- You can also write your import map in JavaScript instead of JSON. So instead of `config/import_map.json`, create `config/import_map.js`, and define an anonymous function. This function accepts a single `environment` argument.
322
-
323
- ```js
324
- (env) => ({
325
- imports: {
326
- react:
327
- env === "development"
328
- ? "https://esm.sh/react@18.2.0?dev"
329
- : "https://esm.sh/react@18.2.0",
330
- },
331
- });
332
- ```
333
-
334
281
  ## Source Maps
335
282
 
336
283
  Source maps can make it easier to debug your code. They encode the information necessary to translate from a line/column offset in a generated output file back to a line/column offset in the corresponding original input file. This is useful if your generated code is sufficiently different from your original code (e.g. your original code is TypeScript or you enabled minification). This is also useful if you prefer looking at individual files in your browser's developer tools instead of one big bundled file.
@@ -692,26 +639,6 @@ import { version } from "./package.json";
692
639
  console.log(version);
693
640
  ```
694
641
 
695
- ## Cache Busting
696
-
697
- By default, all assets are not cached by the browser. But if in production, you populate the `REVISION` env variable, all CSS and JS URL's will be appended with its value as a query string, and the `Cache-Control` response header will be set to `public` and a max-age of 30 days.
698
-
699
- For example, if you set `REVISION=v1`, URL's will be appended with `?v1`: `/my/imported/file.js?v1`.
700
-
701
- It is assumed that the `REVISION` env var will be unique between deploys. If it isn't, then assets will continue to be cached as the same version between deploys. I recommend you assign a version number or to use the Git commit hash of the deploy. Just make sure it is unique for each deploy.
702
-
703
- You can set the `cache_query_string` config option directly to define any query string you wish:
704
-
705
- ```ruby
706
- Rails.application.config.proscenium.cache_query_string = 'my-cache-busting-version-string'
707
- ```
708
-
709
- The cache is set with a `max-age` of 30 days. You can customise this with the `cache_max_age` config option:
710
-
711
- ```ruby
712
- Rails.application.config.proscenium.cache_max_age = 12.months.to_i
713
- ```
714
-
715
642
  ## rjs is back
716
643
 
717
644
  Proscenium brings back RJS! Any path ending in .rjs will be served from your Rails app. This allows you to import server rendered javascript.
@@ -726,6 +653,28 @@ You can continue to access any file in the `/public` directory as you normally w
726
653
 
727
654
  If requesting a file that exists in a root directory and the public directory, the file in the public directory will be served. For example, if you have a file at `/lib/foo.js` and `/public/lib/foo.js`, and you request `/lib/foo.js`, the file in the public directory (`/public/lib/foo.js`) will be served.
728
655
 
656
+ ## Pre-compilation
657
+
658
+ Proscenium is designed to bundle and minify your frontend code in real time, on demand, with no build step or pre-compilation needed. However, if you want to pre-compile your assets for production deployment, you can do so using the `assets:precompile` Rake task.
659
+
660
+ ```bash
661
+ rails assets:precompile
662
+ ```
663
+
664
+ Be sure to specify a `Set` of paths which you want to pre-compile via the `config.proscenium.precompile` configuration option. Each path should be a glob pattern that matches the files which are your entry points. Don't include paths that are not entry points. For example:
665
+
666
+ ```ruby
667
+ Rails.configuration.proscenium.precompile = Set[
668
+ "./app/components/**/*.js",
669
+ "./app/components/**/*.jsx",
670
+ "./app/views/**/*.js",
671
+ "./app/views/**/*.css",
672
+ "./app/views/**/*.module.css"
673
+ ]
674
+ ```
675
+
676
+ This will bundle, code split, tree shake, and compile all your JS, TS, JSX, TSX and CSS files and place them in the `public/assets` directory, ready to be served in production.
677
+
729
678
  ## Thanks
730
679
 
731
680
  HUGE thanks 🙏 go to [Evan Wallace](https://github.com/evanw) and his amazing [esbuild](https://esbuild.github.io/) project. Proscenium would not be possible without it, and it is esbuild that makes this so fast and efficient.
@@ -26,7 +26,6 @@ module Proscenium
26
26
 
27
27
  attach_function :build_to_string, [
28
28
  :string, # Path or entry point.
29
- :string, # cache_query_string.
30
29
  :pointer # Config as JSON.
31
30
  ], Result.by_value
32
31
 
@@ -68,8 +67,8 @@ module Proscenium
68
67
  end
69
68
  end
70
69
 
71
- def self.build_to_string(path, cache_query_string: '', root: nil)
72
- new(root:).build_to_string(path, cache_query_string:)
70
+ def self.build_to_string(path, root: nil)
71
+ new(root:).build_to_string(path)
73
72
  end
74
73
 
75
74
  def self.resolve(path, root: nil)
@@ -97,14 +96,13 @@ module Proscenium
97
96
  Bundle: Proscenium.config.bundle,
98
97
  Aliases: Proscenium.config.aliases,
99
98
  Precompile: Proscenium.config.precompile,
100
- QueryString: Proscenium.config.cache_query_string.presence || '',
101
99
  Debug: Proscenium.config.debug
102
100
  }.to_json)
103
101
  end
104
102
 
105
- def build_to_string(path, cache_query_string: '')
103
+ def build_to_string(path)
106
104
  ActiveSupport::Notifications.instrument('build.proscenium', identifier: path) do
107
- result = Request.build_to_string(path, cache_query_string, @request_config)
105
+ result = Request.build_to_string(path, @request_config)
108
106
 
109
107
  raise BuildError.new(path, result[:response]) unless result[:success]
110
108
 
Binary file
@@ -92,10 +92,9 @@ extern void reset_config();
92
92
  // Build the given `path` using the `config`.
93
93
  //
94
94
  // - path - The path to build relative to `root`.
95
- // - cache_query_string - The current query string used for cache busting, taken from the URL.
96
95
  // - config
97
96
  //
98
- extern struct Result build_to_string(char* filePath, char* cacheQueryString, char* configJson);
97
+ extern struct Result build_to_string(char* filePath, char* configJson);
99
98
 
100
99
  // Resolve the given `path` relative to the `root`.
101
100
  //
@@ -28,17 +28,6 @@ module Proscenium
28
28
  @path_to_build ||= @request.path[1..]
29
29
  end
30
30
 
31
- def cache_query_string
32
- @cache_query_string ||= begin
33
- params = @request.query_parameters
34
- if params.one? && params.first[0] != '' && params.first[1].nil?
35
- params.keys.first
36
- else
37
- Proscenium.config.cache_query_string
38
- end
39
- end.presence || ''
40
- end
41
-
42
31
  def sourcemap?
43
32
  @request.path.ends_with?('.map')
44
33
  end
@@ -85,10 +74,6 @@ module Proscenium
85
74
  response.content_type = content_type
86
75
  response.etag = result[:content_hash]
87
76
 
88
- if !cache_query_string.blank? && Proscenium.config.cache_max_age
89
- response.cache! Proscenium.config.cache_max_age
90
- end
91
-
92
77
  if @request.fresh?(response)
93
78
  response.status = 304
94
79
  response.body = []
@@ -4,7 +4,7 @@ module Proscenium
4
4
  class Middleware
5
5
  class Esbuild < Base
6
6
  def attempt
7
- render_response Builder.build_to_string(path_to_build, cache_query_string:)
7
+ render_response Builder.build_to_string(path_to_build)
8
8
  end
9
9
  end
10
10
  end
@@ -20,13 +20,10 @@ module Proscenium
20
20
 
21
21
  return @app.call(env) if !request.get? && !request.head?
22
22
 
23
- # If this is a request for an asset chunk, we want to serve it with a very long
24
- # cache lifetime, since these are content-hashed and will never change.
25
23
  if request.path.match?(CHUNKS_PATH)
26
24
  ::ActionDispatch::FileHandler.new(
27
25
  Proscenium.config.output_path.to_s,
28
26
  headers: {
29
- 'Cache-Control' => "public, max-age=#{100.years}, immutable",
30
27
  'etag' => request.path.match(/-\$([a-z0-9]+)\$/i)[1]
31
28
  }
32
29
  ).attempt(env) || @app.call(env)
@@ -15,8 +15,6 @@ module Proscenium
15
15
  config.proscenium.side_load = true
16
16
  config.proscenium.code_splitting = true
17
17
  config.proscenium.ensure_loaded = :raise
18
- config.proscenium.cache_query_string = Rails.env.production? && ENV.fetch('REVISION', nil)
19
- config.proscenium.cache_max_age = 2_592_000 # 30 days
20
18
  config.proscenium.aliases = {}
21
19
  config.proscenium.precompile = Set.new
22
20
  config.proscenium.output_dir = '/assets'
@@ -56,7 +54,15 @@ module Proscenium
56
54
  unless config.proscenium.logging
57
55
  app.middleware.insert_before Rails::Rack::Logger, Proscenium::Middleware::SilenceRequest
58
56
  end
59
- app.middleware.insert_before ActionDispatch::Callbacks, Proscenium::Middleware
57
+
58
+ # Ensure the middleware is inserted as early as possible.
59
+ if app.config.consider_all_requests_local
60
+ app.middleware.insert_before ActionDispatch::ActionableExceptions, Proscenium::Middleware
61
+ elsif app.config.reloading_enabled?
62
+ app.middleware.insert_before ActionDispatch::Reloader, Proscenium::Middleware
63
+ else
64
+ app.middleware.insert_before ActionDispatch::Callbacks, Proscenium::Middleware
65
+ end
60
66
  end
61
67
 
62
68
  initializer 'proscenium.sideloading' do
@@ -40,9 +40,6 @@ module Proscenium
40
40
  opts[:preload_links_header] = false if fragments
41
41
  opts[:data] ||= {}
42
42
 
43
- if Proscenium.config.cache_query_string.present?
44
- path += "?#{Proscenium.config.cache_query_string}"
45
- end
46
43
  out << helpers.stylesheet_link_tag(path.delete_prefix('/'), extname: false, **opts)
47
44
  end
48
45
 
@@ -71,9 +68,6 @@ module Proscenium
71
68
  opts = opts[:js].is_a?(Hash) ? opts[:js] : {}
72
69
  opts[:preload_links_header] = false if fragments
73
70
 
74
- if Proscenium.config.cache_query_string.present?
75
- path += "?#{Proscenium.config.cache_query_string}"
76
- end
77
71
  out << helpers.javascript_include_tag(path.delete_prefix('/'), extname: false, **opts)
78
72
  end
79
73
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Proscenium
4
- VERSION = '0.22.0.beta2'
4
+ VERSION = '0.22.0.beta3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proscenium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.0.beta2
4
+ version: 0.22.0.beta3
5
5
  platform: x86_64-linux
6
6
  authors:
7
7
  - Joel Moss