proscenium 0.1.2-x86_64-darwin → 0.2.0-x86_64-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: ad7315e0b0349ce11b5629c744808ce9a80050a32eb942bf2572e38a534b9fa9
4
- data.tar.gz: e93884817dea84e7251a0660d6d2ba650a7643c3e81f7787885e4ea13a904c02
3
+ metadata.gz: 3e3fd0fe04d0ad74e9c8a799d0f5e7a211f36754e502ae2dead2d87d84153594
4
+ data.tar.gz: 777c4b1a144554766f1397f72492182ec307c386e7ed0f1fadac5b0891a58907
5
5
  SHA512:
6
- metadata.gz: 57badd536fa32f94881fa5e02e9115510ffa1397d6425fe2ffb4438505c6eb042a8ceb87cea336939ba6972b9bcf08aab8172b7662026e964c071d0de9efd456
7
- data.tar.gz: 895b1138be200a6fb6a824309d2091d64e11d90ccc12fcb039aa91db73fe633123220cdf5f4a062490d34febe0bea47a743b797bcee77d463e215878464792be
6
+ metadata.gz: aa754d0f16d6e20158b9ed6d9140f87c6212f81c3fb9a4ab6b075cf33e2ba4dcdd5e5f984eb4dc0cd2506aa1dcfdf6b89c701a9258b3932bc6abe78c63619c33
7
+ data.tar.gz: b549656184b70c8c5a0b783f39425b1213f14efe24e2e0132dd10d63ad591b843c39b233497f7ba019348992158594112f4bebfbbcdda7ef27c32730406cac87
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-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