proscenium 0.2.0-x86_64-linux → 0.2.1-x86_64-linux

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7674bd9b916a7862d66f1da99291a083ee033397ec1c480ef830d6e015b62466
4
- data.tar.gz: 9b906468c4f0c0dccf21cc281d6651fd57ddadaf5625cd23e635d6a3e711d7fc
3
+ metadata.gz: 3865fbb2c2e0c606febd498305b5c547f4ed96ff271012f0a0a0069f7178bed0
4
+ data.tar.gz: 4961bfa53fb5f2e495e7b5d60903fc9898cf61f9c6ac4b7fe1d33fd6e7c028d6
5
5
  SHA512:
6
- metadata.gz: 261f91913972d9d0c229851a5a698ad9725742902e6dbc3441af03a64c2ad775b00d6a6448b6bbacacbe0b0f4c5550c0ce3a595522fb8c42b946ff4a58e43704
7
- data.tar.gz: 268ae1167972e0db6709bd529fddb545f9fccc11363cffa9355ad327b157db2bf312085d2663326dab717c91bbc2b64a45d0506c40a6d4743eddde82cf4692ef
6
+ metadata.gz: c270f788bc4f61af038d19ce5250f70bbd3684061cfb2d865a5522c148ca78e713c47506c1813a73e72e11cd37f9c30d471bb04f617bbda14b7d26ded41b1b40
7
+ data.tar.gz: 894ff8cc3f247356d8cf1983fda1dba591d33fb309aaedc765d30445a2d9eba97608f656c9e4c5fb72c12c81da088e7dd15d2f55685128bdd1cda9966156b80c
data/README.md CHANGED
@@ -110,6 +110,10 @@ resulting in conflicts. For example, esm.sh also supports a `?bundle` param, bun
110
110
  dependencies into a single file. Instead, you should install the module locally using your favourite
111
111
  package manager.
112
112
 
113
+ Note that `?bundle` will only bundle that exact path. It will not bundle any descendant imports. You
114
+ can bundle all imports within a file by using the `?bundle-all` query string. Use this with caution,
115
+ as you could end up swallowing everything, resulting in a very large file.
116
+
113
117
  ## Import Map
114
118
 
115
119
  Import map for both JS and CSS is supported out of the box, and works with no regard to the browser
@@ -246,6 +250,31 @@ p {
246
250
  }
247
251
  ```
248
252
 
253
+ ## Cache Busting
254
+
255
+ By default, all assets are not cached by the browser. But if in production, you populate the
256
+ `REVISION` env variable, all CSS and JS URL's will be appended with its value as a query string, and
257
+ the `Cache-Control` response header will be set to `public` and a max-age of 30 days.
258
+
259
+ For example, if you set `REVISION=v1`, URL's will be appended with `?v1`: `/my/imported/file.js?v1`.
260
+
261
+ It is assumed that the `REVISION` env var will be unique between deploys. If it isn't, then assets
262
+ will continue to be cached as the same version between deploys. I recommend you assign a version
263
+ number or to use the Git commit hash of the deploy. Just make sure it is unique for each deploy.
264
+
265
+ You can set the `cache_query_string` config option directly to define any query string you wish:
266
+
267
+ ```ruby
268
+ Rails.application.config.proscenium.cache_query_string = 'my-cache-busting-version-string'
269
+ ```
270
+
271
+ The cache is set with a `max-age` of 30 days. You can customise this with the `cache_max_age` config
272
+ option:
273
+
274
+ ```ruby
275
+ Rails.application.config.proscenium.cache_max_age = 12.months.to_i
276
+ ```
277
+
249
278
  ## How It Works
250
279
 
251
280
  Proscenium provides a Rails middleware that proxies requests for your frontend code. By default, it will simply search for a file of the same name in your Rails root. For example, a request for '/app/views/layouts/application.js' or '/lib/hooks.js' will return that exact file relative to your Rails root.
@@ -258,10 +287,6 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
258
287
 
259
288
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
260
289
 
261
- ### Compile the compilers
262
-
263
- `deno compile --no-config -o bin/compilers/esbuild --import-map import_map.json -A lib/proscenium/compilers/esbuild.js`
264
-
265
290
  ## Contributing
266
291
 
267
292
  Bug reports and pull requests are welcome on GitHub at https://github.com/joelmoss/proscenium. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/joelmoss/proscenium/blob/master/CODE_OF_CONDUCT.md).
data/bin/esbuild CHANGED
Binary file
@@ -24,6 +24,8 @@ export default setup('resolve', (build, options) => {
24
24
  args.path = path
25
25
  args.suffix = `?${query}`
26
26
  args.queryParams = new URLSearchParams(query)
27
+ } else if (options.cacheQueryString && options.cacheQueryString !== '') {
28
+ args.suffix = `?${options.cacheQueryString}`
27
29
  }
28
30
 
29
31
  // Mark remote modules as external.
@@ -133,6 +135,10 @@ export default setup('resolve', (build, options) => {
133
135
  result.external = true
134
136
  }
135
137
 
138
+ if (result.suffix && result.suffix !== '') {
139
+ result.path = `${result.path}${result.suffix}`
140
+ }
141
+
136
142
  return result
137
143
  }
138
144
  })
@@ -3,11 +3,12 @@ import { join } from 'std/path/mod.ts'
3
3
  import compile from './esbuild.js'
4
4
 
5
5
  const root = join(Deno.cwd(), 'test', 'internal')
6
+ const lightningcssBin = join(Deno.cwd(), 'bin', 'lightningcss')
6
7
 
7
8
  Deno.bench('esbuild js', async () => {
8
- await compile(['lib/foo.js'], { root })
9
+ await compile(['lib/foo.js'], { root, lightningcssBin })
9
10
  })
10
11
 
11
12
  Deno.bench('esbuild css', async () => {
12
- await compile(['lib/foo.css'], { root })
13
+ await compile(['lib/foo.css'], { root, lightningcssBin })
13
14
  })
@@ -26,15 +26,17 @@ import throwCompileError from './esbuild/compile_error.js'
26
26
  * <PATHS_ARG>... One or more file paths or globs to compile.
27
27
  *
28
28
  * OPTIONS:
29
- * --root
29
+ * --root <PATH>
30
30
  * Relative or absolute path to the root or current working directory when compilation will
31
31
  * take place.
32
- * --import-map
32
+ * --import-map <PATH>
33
33
  * Path to an import map, relative to the <root>.
34
- * --lightningcss-bin
34
+ * --lightningcss-bin <PATH>
35
35
  * Path to the lightningcss CLI binary.
36
36
  * --write
37
37
  * Write output to the filesystem according to esbuild logic.
38
+ * --cache-query-string <STRING>
39
+ * Query string to append to all imports as a cache buster. Example: `v1`.
38
40
  * --debug
39
41
  * Debug output,
40
42
  */
@@ -42,10 +44,11 @@ if (import.meta.main) {
42
44
  !Deno.env.get('RAILS_ENV') && Deno.env.set('RAILS_ENV', 'development')
43
45
 
44
46
  const { _: paths, ...options } = parseArgs(Deno.args, {
45
- string: ['root', 'import-map', 'lightningcss-bin'],
47
+ string: ['root', 'import-map', 'lightningcss-bin', 'cache-query-string'],
46
48
  boolean: ['write', 'debug'],
47
49
  alias: {
48
50
  'import-map': 'importMap',
51
+ 'cache-query-string': 'cacheQueryString',
49
52
  'lightningcss-bin': 'lightningcssBin'
50
53
  }
51
54
  })
@@ -127,7 +130,7 @@ async function main(paths = [], options = {}) {
127
130
  bundle: true,
128
131
  plugins: [
129
132
  envPlugin(),
130
- resolvePlugin({ runtimeDir, importMap, debug }),
133
+ resolvePlugin({ runtimeDir, importMap, debug, cacheQueryString: options.cacheQueryString }),
131
134
  cssPlugin({ lightningcssBin: options.lightningcssBin, debug })
132
135
  ],
133
136
  metafile: write,
@@ -60,8 +60,8 @@ module Proscenium
60
60
  response.content_type = content_type
61
61
  response['X-Proscenium-Middleware'] = name
62
62
 
63
- if Proscenium.config.cache_query_string
64
- response['Cache-Control'] = "public, max-age=#{2.days.to_i}"
63
+ if Proscenium.config.cache_query_string && Proscenium.config.cache_max_age
64
+ response['Cache-Control'] = "public, max-age=#{Proscenium.config.cache_max_age}"
65
65
  end
66
66
 
67
67
  yield response if block_given?
@@ -15,9 +15,11 @@ module Proscenium
15
15
 
16
16
  def attempt
17
17
  benchmark :esbuild do
18
- render_response build(
19
- "#{cli} --root #{root} --lightningcss-bin #{lightningcss_cli} #{path}"
20
- )
18
+ render_response build([
19
+ "#{cli} --root #{root}",
20
+ cache_query_string,
21
+ "--lightningcss-bin #{lightningcss_cli} #{path}"
22
+ ].compact.join(' '))
21
23
  end
22
24
  rescue CompileError => e
23
25
  render_response "export default #{e.detail.to_json}" do |response|
@@ -33,9 +35,7 @@ module Proscenium
33
35
 
34
36
  def cli
35
37
  if ENV['PROSCENIUM_TEST']
36
- [
37
- 'deno run -q --import-map import_map.json -A', 'lib/proscenium/compilers/esbuild.js'
38
- ].join(' ')
38
+ 'deno run -q --import-map import_map.json -A lib/proscenium/compilers/esbuild.js'
39
39
  else
40
40
  Gem.bin_path 'proscenium', 'esbuild'
41
41
  end
@@ -48,6 +48,11 @@ module Proscenium
48
48
  Gem.bin_path 'proscenium', 'lightningcss'
49
49
  end
50
50
  end
51
+
52
+ def cache_query_string
53
+ q = Proscenium.config.cache_query_string
54
+ q ? "--cache-query-string #{q}" : nil
55
+ end
51
56
  end
52
57
  end
53
58
  end
@@ -29,6 +29,7 @@ module Proscenium
29
29
  config.proscenium = ActiveSupport::OrderedOptions.new
30
30
  config.proscenium.side_load = true
31
31
  config.proscenium.cache_query_string = Rails.env.production? && ENV.fetch('REVISION', nil)
32
+ config.proscenium.cache_max_age = 2_592_000 # 30 days
32
33
  config.proscenium.auto_reload = Rails.env.development?
33
34
  config.proscenium.auto_reload_paths ||= %w[lib app config]
34
35
  config.proscenium.auto_reload_extensions ||= /\.(css|jsx?)$/
@@ -1,5 +1,4 @@
1
- import { createConsumer } from 'https://esm.sh/@rails/actioncable@6.0.5'
2
- import debounce from 'https://esm.sh/debounce@1.2.1'
1
+ import { createConsumer } from 'https://esm.sh/v96/@rails/actioncable@7.0.4/es2022/actioncable.js'
3
2
 
4
3
  export default socketPath => {
5
4
  const uid = (Date.now() + ((Math.random() * 100) | 0)).toString()
@@ -9,7 +8,7 @@ export default socketPath => {
9
8
  received: debounce(() => {
10
9
  console.log('[Proscenium] Files changed; reloading...')
11
10
  location.reload()
12
- }, 200),
11
+ }, 200, true),
13
12
 
14
13
  connected() {
15
14
  console.log('[Proscenium] Auto-reload websocket connected')
@@ -20,3 +19,22 @@ export default socketPath => {
20
19
  }
21
20
  })
22
21
  }
22
+
23
+ function debounce(func, wait, immediate) {
24
+ let timeout
25
+
26
+ return function () {
27
+ const args = arguments
28
+
29
+ const later = () => {
30
+ timeout = null
31
+ !immediate && func.apply(this, args)
32
+ }
33
+
34
+ const callNow = immediate && !timeout
35
+ clearTimeout(timeout)
36
+ timeout = setTimeout(later, wait)
37
+
38
+ callNow && func.apply(this, args)
39
+ }
40
+ }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Proscenium
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proscenium
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: x86_64-linux
6
6
  authors:
7
7
  - Joel Moss
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-18 00:00:00.000000000 Z
11
+ date: 2022-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actioncable