proscenium 0.1.2-x86_64-linux → 0.2.0-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: 446ad2f069aa35ab275b66632c447318d4f6b58306e4de6f6812b1b4cd3292b3
4
- data.tar.gz: 9e620e076b80ae0bc7613b09743b19eceec98a2e16818d19177e01e77394efe0
3
+ metadata.gz: 7674bd9b916a7862d66f1da99291a083ee033397ec1c480ef830d6e015b62466
4
+ data.tar.gz: 9b906468c4f0c0dccf21cc281d6651fd57ddadaf5625cd23e635d6a3e711d7fc
5
5
  SHA512:
6
- metadata.gz: c933cfec773e60aea31f7262bf16dc22471a6dcbb7ede70d9631ba97652f3723c8c2761872ea5276e99cdfab19481e084a6818857580b85cd905260c6d14e8f4
7
- data.tar.gz: 82116ba5093880d9a81080fc90b5611271033c595ea3799b04bb99fc8bf2790d40b517c94b5b8999745b9f93487fb85ed2ac8ea4cbc7f5e7479c800bb2bba051
6
+ metadata.gz: 261f91913972d9d0c229851a5a698ad9725742902e6dbc3441af03a64c2ad775b00d6a6448b6bbacacbe0b0f4c5550c0ce3a595522fb8c42b946ff4a58e43704
7
+ data.tar.gz: 268ae1167972e0db6709bd529fddb545f9fccc11363cffa9355ad327b157db2bf312085d2663326dab717c91bbc2b64a45d0506c40a6d4743eddde82cf4692ef
data/bin/esbuild CHANGED
Binary file
@@ -11,6 +11,9 @@ export default setup('resolve', (build, options) => {
11
11
  const runtimeCwdAlias = `${cwd}/proscenium-runtime`
12
12
  let bundled = false
13
13
 
14
+ const env = Deno.env.get('RAILS_ENV')
15
+ const isProd = env === 'production'
16
+
14
17
  return [
15
18
  {
16
19
  type: 'onResolve',
@@ -28,24 +31,7 @@ export default setup('resolve', (build, options) => {
28
31
  return { external: true }
29
32
  }
30
33
 
31
- // Proscenium runtime
32
- // if (args.path.startsWith('@proscenium/')) {
33
- // const result = { suffix: args.suffix }
34
-
35
- // if (args.queryParams?.has('bundle-all')) {
36
- // bundled = true
37
- // }
38
-
39
- // if (bundled || args.queryParams?.has('bundle')) {
40
- // result.path = join(runtimeDir, `${args.path.replace(/^@proscenium/, '')}/index.js`)
41
- // } else {
42
- // result.path = `${args.path.replace(/^@proscenium/, '/proscenium-runtime')}/index.js`
43
- // result.external = true
44
- // }
45
-
46
- // return result
47
- // }
48
-
34
+ // Rewrite the path to the actual runtime directory.
49
35
  if (args.path.startsWith(runtimeCwdAlias)) {
50
36
  return { path: join(runtimeDir, args.path.slice(runtimeCwdAlias.length)) }
51
37
  }
@@ -88,11 +74,12 @@ export default setup('resolve', (build, options) => {
88
74
  // Resolve the path using esbuild's internal resolution. This allows us to import node packages
89
75
  // and extension-less paths without custom code, as esbuild with resolve them for us.
90
76
  const resolveResult = await build.resolve(result.path, {
91
- // If path is a bare module (node_modules), and resolveDir is the Proscenium runtime dir, then
92
- // use `cwd` as the `resolveDir`, otherwise pass it through as is. This ensures that nested
93
- // node_modules are resolved correctly.
77
+ // If path is a bare module (node_modules), and resolveDir is the Proscenium runtime dir, or
78
+ // is the current working dir, then use `cwd` as the `resolveDir`, otherwise pass it through
79
+ // as is. This ensures that nested node_modules are resolved correctly.
94
80
  resolveDir:
95
- isBareModule(result.path) && params.resolveDir.startsWith(runtimeDir)
81
+ isBareModule(result.path) &&
82
+ (!params.resolveDir.startsWith(cwd) || params.resolveDir.startsWith(runtimeDir))
96
83
  ? cwd
97
84
  : params.resolveDir,
98
85
  pluginData: {
@@ -118,9 +105,17 @@ export default setup('resolve', (build, options) => {
118
105
 
119
106
  if (resolveResult.path.startsWith(runtimeDir)) {
120
107
  result.path = '/proscenium-runtime' + resolveResult.path.slice(runtimeDir.length)
121
- } else if (!resolveResult.path.startsWith(cwd)) {
122
- // If resolved path does not start with cwd, then it is most likely linked, so bundle it.
123
- return { ...resolveResult, suffix: '?bundle' }
108
+ } else if (!resolveResult.path.startsWith(cwd) && !isProd) {
109
+ // Resolved path is not in the current working directory. It could be linked to a file outside
110
+ // the CWD, or it's just invalid. If not in production, return as an outsideRoot namespaced,
111
+ // and externally suffixed path. This lets the Rails Proscenium::Middleware::OutsideRoot
112
+ // handle the import.
113
+ return {
114
+ ...resolveResult,
115
+ namespace: 'outsideRoot',
116
+ path: `${resolveResult.path}?outsideRoot`,
117
+ external: true
118
+ }
124
119
  } else {
125
120
  result.path = resolveResult.path.slice(cwd.length)
126
121
  }
@@ -23,7 +23,7 @@ import throwCompileError from './esbuild/compile_error.js'
23
23
  * esbuild [OPTIONS] <PATHS_ARG>...
24
24
  *
25
25
  * ARGS:
26
- * <PATHS_ARG>... One or more file paths to compile.
26
+ * <PATHS_ARG>... One or more file paths or globs to compile.
27
27
  *
28
28
  * OPTIONS:
29
29
  * --root
@@ -80,8 +80,8 @@ async function main(paths = [], options = {}) {
80
80
  const env = Deno.env.get('RAILS_ENV')
81
81
  const isProd = env === 'production'
82
82
  const isTest = env === 'test'
83
-
84
83
  const entryPoints = new Set()
84
+
85
85
  for (let i = 0; i < paths.length; i++) {
86
86
  const path = paths[i]
87
87
 
@@ -89,6 +89,10 @@ async function main(paths = [], options = {}) {
89
89
  for await (const file of expandGlob(path, { root })) {
90
90
  file.isFile && entryPoints.add(file.path)
91
91
  }
92
+ } else if (path.startsWith('/')) {
93
+ // Path is absolute, so it must be outsideRoot. Don't prefix the root.
94
+ // See Proscenium::Middleware::OutsideRoot.
95
+ entryPoints.add(path)
92
96
  } else {
93
97
  entryPoints.add(join(root, path))
94
98
  }
@@ -3,7 +3,15 @@
3
3
  module Proscenium
4
4
  module Helper
5
5
  def compute_asset_path(path, options = {})
6
- return "/#{path}" if %i[javascript stylesheet].include?(options[:type])
6
+ if %i[javascript stylesheet].include?(options[:type])
7
+ result = "/#{path}"
8
+
9
+ if (qs = Proscenium.config.cache_query_string)
10
+ result << "?#{qs}"
11
+ end
12
+
13
+ return result
14
+ end
7
15
 
8
16
  super
9
17
  end
@@ -60,6 +60,10 @@ 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}"
65
+ end
66
+
63
67
  yield response if block_given?
64
68
 
65
69
  response.finish
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Proscenium
4
+ class Middleware
5
+ # Provides a way to render files outside of the Rails root during non-production. This is
6
+ # primarily to support linked NPM modules, for example when using `pnpm link ...`.
7
+ class OutsideRoot < Esbuild
8
+ private
9
+
10
+ # @override [Esbuild] reassigns root to '/'.
11
+ def renderable?
12
+ old_root = root
13
+ @root = Pathname.new('/')
14
+
15
+ super
16
+ ensure
17
+ @root = old_root
18
+ end
19
+
20
+ # @override [Esbuild] does not remove leading slash, ensuring it is an absolute path.
21
+ def path
22
+ @request.path
23
+ end
24
+ end
25
+ end
26
+ end
@@ -10,6 +10,7 @@ module Proscenium
10
10
  autoload :Base
11
11
  autoload :Esbuild
12
12
  autoload :Runtime
13
+ autoload :OutsideRoot
13
14
 
14
15
  def initialize(app)
15
16
  @app = app
@@ -38,6 +39,12 @@ module Proscenium
38
39
  def find_type(request)
39
40
  path = Pathname.new(request.path)
40
41
 
42
+ # Non-production only!
43
+ if request.query_string == 'outsideRoot'
44
+ return if Rails.env.production?
45
+ return OutsideRoot if path.fnmatch?(glob_types[:outsideRoot], File::FNM_EXTGLOB)
46
+ end
47
+
41
48
  return Runtime if path.fnmatch?(glob_types[:runtime], File::FNM_EXTGLOB)
42
49
  return Esbuild if path.fnmatch?(glob_types[:esbuild], File::FNM_EXTGLOB)
43
50
  end
@@ -13,7 +13,8 @@ module Proscenium
13
13
  # See https://doc.deno.land/https://deno.land/std@0.145.0/path/mod.ts/~/globToRegExp
14
14
  DEFAULT_GLOB_TYPES = {
15
15
  esbuild: '/{config,app,lib,node_modules}/**.{js,mjs,jsx,css}',
16
- runtime: '/proscenium-runtime/**.{js,jsx}'
16
+ runtime: '/proscenium-runtime/**.{js,jsx}',
17
+ outsideRoot: '/**/*.{js,jsx,mjs,css}'
17
18
  }.freeze
18
19
 
19
20
  class << self
@@ -27,6 +28,7 @@ module Proscenium
27
28
 
28
29
  config.proscenium = ActiveSupport::OrderedOptions.new
29
30
  config.proscenium.side_load = true
31
+ config.proscenium.cache_query_string = Rails.env.production? && ENV.fetch('REVISION', nil)
30
32
  config.proscenium.auto_reload = Rails.env.development?
31
33
  config.proscenium.auto_reload_paths ||= %w[lib app config]
32
34
  config.proscenium.auto_reload_extensions ||= /\.(css|jsx?)$/
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Proscenium
4
- VERSION = '0.1.2'
4
+ VERSION = '0.2.0'
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.1.2
4
+ version: 0.2.0
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-16 00:00:00.000000000 Z
11
+ date: 2022-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actioncable
@@ -167,6 +167,7 @@ files:
167
167
  - lib/proscenium/middleware/base.rb
168
168
  - lib/proscenium/middleware/esbuild.rb
169
169
  - lib/proscenium/middleware/lightningcss.rb
170
+ - lib/proscenium/middleware/outside_root.rb
170
171
  - lib/proscenium/middleware/runtime.rb
171
172
  - lib/proscenium/middleware/static.rb
172
173
  - lib/proscenium/phlex.rb