proscenium 0.4.2-x86_64-darwin → 0.5.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: 66baa8293b370fb8909751539c7e79327d7c63f9f254fbad2a38bcecf80afe75
4
- data.tar.gz: d0666219ca0b7a9b4a12627a160df177764e3b097eb3a3e6d063da585c413b05
3
+ metadata.gz: 1f905fa040049f8ad4f5863b705c9f99f74cda1e38c3cbb9325e7bada262e36d
4
+ data.tar.gz: 73ef3f88ab3a1c6510275be8df6c0ca982d483685deff51764c9ae4ae057acef
5
5
  SHA512:
6
- metadata.gz: 0cefd18721b3f644ba32274bd8a7d3eac6d38a78a203971715ae98fbef4ff2bc70fd4c3258fa049d6b75c8120c3225ebd78d5f73f0701f0dc52e7d76c3f423f5
7
- data.tar.gz: 0ffad05d6db91c8aaec6949452039d92d34c78f19110e62abd1fa4e9e303072fde623ac885418fcd3c31c228652b3d8e9800462539c08659acfcfbe58108193a
6
+ metadata.gz: da5cb634c091dba3d8a86e571dae54a1683b45620076ebbe74ac1f2990e1a5b934310704cd16cc364f4fc3b3edd6900561f5a11d20b0065379546af349a6ec17
7
+ data.tar.gz: 2468099ba8d90572e876a54e7f1a66c1b1cf77c243edcbd57a9b89a25e71f06c501c9c61133b6249082efc12675a5a24fe6d43750c2ab12422bc688a6b73b2b2
@@ -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;
@@ -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.2'
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.2
4
+ version: 0.5.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-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