proscenium 0.1.2-arm64-darwin → 0.2.0-arm64-darwin

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: d20f6189b8ed53c8f8c49fdd34ff7c94e9dd664e4a270d0f19300ce2435868b2
4
- data.tar.gz: 19ca20f0dc49a00ccacddc79459cfa1f9676f3d89d5f276a8c1b9c27637f2212
3
+ metadata.gz: 37bbbaaaf48e2acf58f2f79a62a96a2829df81c0cffb1d6de8116382ceb3cf92
4
+ data.tar.gz: b421eacfd9fae7883c6858aaf30e77b4a1be63451ccdb8e42ce060013fb022e1
5
5
  SHA512:
6
- metadata.gz: 2703a824ce1acc0e8aa972012fe275b881d8946ff63c8498f8b52de64229faeadc4008e00acb960078c5c9c3d8c02b0219ddaeb75f0b7479f529e7f34495e12a
7
- data.tar.gz: fa206820113a895af26afa184c88045a62ac307e83eaf7337c9feaff202f2d4ac01d16de9b19378f162397bb839f6ca268b0429ec515a39d21899b34b706a8a5
6
+ metadata.gz: 67e7d21eb3053d07f412d9004b983faf28a10707b56d5ef3dcb638ed70296094018fe419e482649669d936570b47f9c9767235a3e65866afa815c30f6d9ab1e4
7
+ data.tar.gz: af496cb5b9ed927983630bcbd88ce8c911e3b1df4989fd454ae5c76ca6c9e9c50ef8cdc98f59f1613ac95d315a5b250713d7ff68910d0dd8b04027bc2e66b886
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: arm64-darwin
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