proscenium 0.4.1-x86_64-linux → 0.5.0-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: 157126f9c1cca9d367a65d0a81bc3c75d0731fe69accc3f617039892a25e7673
4
- data.tar.gz: 37a2b9d9d8175e7e6d0cd685098645d1a0a478f4d1b23d32eee03ce83e6bc0e5
3
+ metadata.gz: 1c8a9ad032805dfed6ba21f4523f94599334ba7adfec880d3e1dab1c3ba74836
4
+ data.tar.gz: 2d8b98a5d503f8104c00c26dd90d775f9ea804cbf969d2d3182aea50d1805d60
5
5
  SHA512:
6
- metadata.gz: 9f92e30f9d35d57b698994119b4251e11f0443d94b76d45bda759c84ffbd5a4d79d837853542b22968c3c1f1af899018b5bc9c0f2a0f03a4d5858f048103b402
7
- data.tar.gz: 8d7b6e3fbfaf405c2ca8984cc5981d7f0b01f48d082a6e214df35347a894da105db6f87fda277e25f107dd44214f0ca6d9b400b0b8d636d528119f9e68a158e0
6
+ metadata.gz: a529ec0ebcc1b3306a15a2ed889dd8ce174892e3267c5040fed3b24701cf201809979bd7b49f90803624a418e7b37a376bcbeaa66c45390f9d3c126c37730757
7
+ data.tar.gz: d14bedffc25862f0a8ce20a476b1fbdfb524d19cd916031b002153af2962294eaae1a6ed00616119242d217f0ea70fad1db891d98b78e03244945259e7d619e8
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Proscenium
2
4
  class Connection < ActionCable::Connection::Base
3
5
  identified_by :uid
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Proscenium
2
4
  class ReloadChannel < ActionCable::Channel::Base
3
5
  def subscribed
data/bin/esbuild CHANGED
Binary file
data/bin/lightningcss CHANGED
Binary file
data/config/routes.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Proscenium::Railtie.routes.draw do
2
4
  if Proscenium.config.auto_reload
3
5
  mount Proscenium::Railtie.websocket => Proscenium.config.cable_mount_path
@@ -28,6 +28,7 @@ export default function () {
28
28
  font-family: var(--monospace);
29
29
  line-height: 1.5;
30
30
  width: 800px;
31
+ height: 66vh;
31
32
  color: #d8d8d8;
32
33
  margin: 30px auto;
33
34
  padding: 25px 40px;
@@ -19,9 +19,11 @@ export default setup('env', () => {
19
19
  namespace: 'env',
20
20
  callback({ path }) {
21
21
  if (path.includes(':')) {
22
+ const name = Deno.env.get(path.split(':')[1])
23
+
22
24
  return {
23
25
  loader: 'js',
24
- contents: `export default '${Deno.env.get(path.split(':')[1])}'`
26
+ contents: name ? `export default '${name}'` : `export default ${name}`
25
27
  }
26
28
  }
27
29
 
@@ -1,5 +1,6 @@
1
1
  import { join, resolve } from 'std/path/mod.ts'
2
2
  import { resolve as resolveFromImportMap } from 'import-maps/resolve'
3
+ import { cache } from 'cache'
3
4
 
4
5
  import setup from './setup_plugin.js'
5
6
 
@@ -15,6 +16,45 @@ export default setup('resolve', (build, options) => {
15
16
  const isProd = env === 'production'
16
17
 
17
18
  return [
19
+ {
20
+ // Filters for imports starting with `url:http://` or `url:https://`; returning the path
21
+ // without the `url:` prefix, and a namespace of 'url`
22
+ type: 'onResolve',
23
+ filter: /^url:https?:\/\//,
24
+ callback(args) {
25
+ return {
26
+ path: args.path.slice(4),
27
+ namespace: 'url'
28
+ }
29
+ }
30
+ },
31
+
32
+ {
33
+ type: 'onResolve',
34
+ filter: /.*/,
35
+ namespace: 'url',
36
+ callback(args) {
37
+ if (!isBareModule(args.path)) {
38
+ return {
39
+ path: new URL(args.path, args.importer).toString(),
40
+ namespace: 'url'
41
+ }
42
+ }
43
+ }
44
+ },
45
+
46
+ {
47
+ type: 'onLoad',
48
+ filter: /.*/,
49
+ namespace: 'url',
50
+ async callback(args) {
51
+ const file = await cache(args.path)
52
+ const contents = await Deno.readTextFile(file.path)
53
+
54
+ return { contents }
55
+ }
56
+ },
57
+
18
58
  {
19
59
  type: 'onResolve',
20
60
  filter: /.*/,
@@ -28,9 +68,13 @@ export default setup('resolve', (build, options) => {
28
68
  args.suffix = `?${options.cacheQueryString}`
29
69
  }
30
70
 
31
- // Mark remote modules as external.
32
- if (args.path.startsWith('http://') || args.path.startsWith('https://')) {
33
- return { external: true }
71
+ // Mark remote modules as external. If not css, then the path is prefixed with "url:", which
72
+ // is then handled by the Url Middleware.
73
+ if (
74
+ !args.importer.endsWith('.css') &&
75
+ (args.path.startsWith('http://') || args.path.startsWith('https://'))
76
+ ) {
77
+ return { path: `/url:${encodeURIComponent(args.path)}`, external: true }
34
78
  }
35
79
 
36
80
  // Rewrite the path to the actual runtime directory.
@@ -56,14 +100,24 @@ export default setup('resolve', (build, options) => {
56
100
  const result = { path: params.path, suffix: params.suffix }
57
101
 
58
102
  if (importMap) {
59
- const baseURL = new URL(params.importer.slice(cwd.length), 'file://')
103
+ let baseURL
104
+ if (params.importer.startsWith('https://') || params.importer.startsWith('http://')) {
105
+ baseURL = new URL(params.importer)
106
+ } else {
107
+ baseURL = new URL(params.importer.slice(cwd.length), 'file://')
108
+ }
109
+
60
110
  const { matched, resolvedImport } = resolveFromImportMap(params.path, importMap, baseURL)
61
111
 
62
112
  if (matched) {
63
113
  if (resolvedImport.protocol === 'file:') {
64
114
  params.path = resolvedImport.pathname
65
115
  } else {
66
- return { path: resolvedImport.href, external: true }
116
+ if (params.importer.endsWith('.css')) {
117
+ return { path: resolvedImport.href, external: true }
118
+ }
119
+
120
+ return { path: `/url:${encodeURIComponent(resolvedImport.href)}`, external: true }
67
121
  }
68
122
  }
69
123
  }
@@ -73,9 +127,7 @@ export default setup('resolve', (build, options) => {
73
127
  result.path = resolve(cwd, params.path.slice(1))
74
128
  }
75
129
 
76
- // Resolve the path using esbuild's internal resolution. This allows us to import node packages
77
- // and extension-less paths without custom code, as esbuild with resolve them for us.
78
- const resolveResult = await build.resolve(result.path, {
130
+ const resOptions = {
79
131
  // If path is a bare module (node_modules), and resolveDir is the Proscenium runtime dir, or
80
132
  // is the current working dir, then use `cwd` as the `resolveDir`, otherwise pass it through
81
133
  // as is. This ensures that nested node_modules are resolved correctly.
@@ -84,11 +136,16 @@ export default setup('resolve', (build, options) => {
84
136
  (!params.resolveDir.startsWith(cwd) || params.resolveDir.startsWith(runtimeDir))
85
137
  ? cwd
86
138
  : params.resolveDir,
139
+ kind: params.kind,
87
140
  pluginData: {
88
141
  // We use this property later on, as we should ignore this resolution call.
89
142
  isResolvingPath: true
90
143
  }
91
- })
144
+ }
145
+
146
+ // Resolve the path using esbuild's internal resolution. This allows us to import node packages
147
+ // and extension-less paths without custom code, as esbuild with resolve them for us.
148
+ const resolveResult = await build.resolve(result.path, resOptions)
92
149
 
93
150
  // Simple return the resolved result if we have an error. Usually happens when module is not
94
151
  // found.
@@ -92,9 +92,10 @@ async function main(paths = [], options = {}) {
92
92
  for await (const file of expandGlob(path, { root })) {
93
93
  file.isFile && entryPoints.add(file.path)
94
94
  }
95
- } else if (path.startsWith('/')) {
96
- // Path is absolute, so it must be outsideRoot. Don't prefix the root.
97
- // See Proscenium::Middleware::OutsideRoot.
95
+ } else if (path.startsWith('/') || /^url:https?:\/\//.test(path)) {
96
+ // Path is absolute, or is prefixed with 'url:', so it must be outsideRoot, or Url. Don't
97
+ // prefix the root.
98
+ // See Proscenium::Middleware::[OutsideRoot|Url].
98
99
  entryPoints.add(path)
99
100
  } else {
100
101
  entryPoints.add(join(root, path))
@@ -128,6 +129,12 @@ async function main(paths = [], options = {}) {
128
129
  jsxDev: !isTest && !isProd,
129
130
  minify: isProd,
130
131
  bundle: true,
132
+
133
+ // The Esbuild default places browser before module, but we're building for modern browsers
134
+ // which support esm. So we prioritise that. Some libraries export a "browser" build that still
135
+ // uses CJS.
136
+ mainFields: ['module', 'browser', 'main'],
137
+
131
138
  plugins: [
132
139
  envPlugin(),
133
140
  resolvePlugin({ runtimeDir, importMap, debug, cacheQueryString: options.cacheQueryString }),
@@ -10,15 +10,6 @@ module Proscenium
10
10
  # link_to 'Go to', MyComponent
11
11
  #
12
12
  # TODO: ummm, todo it! ;)
13
- def link_to(*args, &block)
14
- # name_argument_index = block ? 0 : 1
15
- # if (args[name_argument_index]).respond_to?(:render_in)
16
- # return super(*LinkToComponentArguments.new(args, name_argument_index,
17
- # self).helper_options, &block)
18
- # end
19
-
20
- super
21
- end
22
13
  end
23
14
 
24
15
  # Component handling for the `link_to` helper.
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Proscenium
4
+ class Middleware
5
+ # Handles requests prefixed with "url:https://"; downloading, caching, and compiling them.
6
+ class Url < Esbuild
7
+ private
8
+
9
+ # @override [Esbuild] It's a URL, so always assume it is renderable (we won't actually know
10
+ # until it's downloaded).
11
+ def renderable?
12
+ true
13
+ end
14
+
15
+ # @override [Esbuild]
16
+ def path
17
+ CGI.unescape(@request.path)[1..]
18
+ end
19
+ end
20
+ end
21
+ end
@@ -10,6 +10,7 @@ module Proscenium
10
10
  autoload :Base
11
11
  autoload :Esbuild
12
12
  autoload :Runtime
13
+ autoload :Url
13
14
  autoload :OutsideRoot
14
15
 
15
16
  def initialize(app)
@@ -45,6 +46,7 @@ module Proscenium
45
46
  return OutsideRoot if path.fnmatch?(glob_types[:outsideRoot], File::FNM_EXTGLOB)
46
47
  end
47
48
 
49
+ return Url if request.path.match?(glob_types[:url])
48
50
  return Runtime if path.fnmatch?(glob_types[:runtime], File::FNM_EXTGLOB)
49
51
  return Esbuild if path.fnmatch?(glob_types[:esbuild], File::FNM_EXTGLOB)
50
52
  end
@@ -11,9 +11,9 @@ module Proscenium
11
11
 
12
12
  module Helpers
13
13
  def side_load_javascripts(...)
14
- if (output = @_view_context.side_load_javascripts(...))
15
- @_target << output
16
- end
14
+ return unless (output = @_view_context.side_load_javascripts(...))
15
+
16
+ @_target << output
17
17
  end
18
18
 
19
19
  %i[side_load_stylesheets proscenium_dev].each do |name|
@@ -14,6 +14,7 @@ module Proscenium
14
14
  DEFAULT_GLOB_TYPES = {
15
15
  esbuild: '/{config,app,lib,node_modules}/**.{js,mjs,jsx,css}',
16
16
  runtime: '/proscenium-runtime/**.{js,jsx}',
17
+ url: %r{^/url:https?%3A%2F%2F},
17
18
  outsideRoot: '/**/*.{js,jsx,mjs,css}'
18
19
  }.freeze
19
20
 
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
3
4
  module Proscenium
4
5
  module SideLoad
5
6
  DEFAULT_EXTENSIONS = %i[js css].freeze
@@ -68,3 +69,4 @@ module Proscenium
68
69
  end
69
70
  end
70
71
  end
72
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Proscenium
4
- VERSION = '0.4.1'
4
+ VERSION = '0.5.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.4.1
4
+ version: 0.5.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-29 00:00:00.000000000 Z
11
+ date: 2022-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actioncable
@@ -132,14 +132,14 @@ dependencies:
132
132
  requirements:
133
133
  - - "~>"
134
134
  - !ruby/object:Gem::Version
135
- version: '2.0'
135
+ version: 2.74.1
136
136
  type: :runtime
137
137
  prerelease: false
138
138
  version_requirements: !ruby/object:Gem::Requirement
139
139
  requirements:
140
140
  - - "~>"
141
141
  - !ruby/object:Gem::Version
142
- version: '2.0'
142
+ version: 2.74.1
143
143
  description:
144
144
  email:
145
145
  - joel@developwithstyle.com
@@ -182,6 +182,7 @@ files:
182
182
  - lib/proscenium/middleware/outside_root.rb
183
183
  - lib/proscenium/middleware/runtime.rb
184
184
  - lib/proscenium/middleware/static.rb
185
+ - lib/proscenium/middleware/url.rb
185
186
  - lib/proscenium/phlex.rb
186
187
  - lib/proscenium/phlex/component.rb
187
188
  - lib/proscenium/phlex/react_component.rb