proscenium 0.1.0.alpha1-x86_64-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/README.md +91 -0
- data/lib/proscenium/cli/argument_error.js +24 -0
- data/lib/proscenium/cli/builders/index.js +1 -0
- data/lib/proscenium/cli/builders/javascript.js +45 -0
- data/lib/proscenium/cli/builders/react.js +60 -0
- data/lib/proscenium/cli/builders/solid.js +46 -0
- data/lib/proscenium/cli/esbuild/env_plugin.js +21 -0
- data/lib/proscenium/cli/esbuild/resolve_plugin.js +136 -0
- data/lib/proscenium/cli/esbuild/solidjs_plugin.js +23 -0
- data/lib/proscenium/cli/js_builder.js +194 -0
- data/lib/proscenium/cli/solid.js +15 -0
- data/lib/proscenium/cli/utils.js +93 -0
- data/lib/proscenium/compiler.js +84 -0
- data/lib/proscenium/compilers/esbuild/argument_error.js +22 -0
- data/lib/proscenium/compilers/esbuild/env_plugin.js +21 -0
- data/lib/proscenium/compilers/esbuild/resolve_plugin.js +145 -0
- data/lib/proscenium/compilers/esbuild/setup_plugin.js +35 -0
- data/lib/proscenium/compilers/esbuild.bench.js +9 -0
- data/lib/proscenium/compilers/esbuild.js +82 -0
- data/lib/proscenium/css_module.rb +22 -0
- data/lib/proscenium/current.rb +9 -0
- data/lib/proscenium/helper.rb +32 -0
- data/lib/proscenium/link_to_helper.rb +49 -0
- data/lib/proscenium/middleware/base.rb +94 -0
- data/lib/proscenium/middleware/esbuild.rb +27 -0
- data/lib/proscenium/middleware/parcel_css.rb +37 -0
- data/lib/proscenium/middleware/runtime.rb +22 -0
- data/lib/proscenium/middleware/static.rb +14 -0
- data/lib/proscenium/middleware.rb +66 -0
- data/lib/proscenium/precompile.rb +31 -0
- data/lib/proscenium/railtie.rb +116 -0
- data/lib/proscenium/runtime/auto_reload.js +22 -0
- data/lib/proscenium/runtime/component_manager/index.js +27 -0
- data/lib/proscenium/runtime/component_manager/render_component.js +40 -0
- data/lib/proscenium/runtime/import_css.js +46 -0
- data/lib/proscenium/runtime/react_shim/index.js +1 -0
- data/lib/proscenium/runtime/react_shim/package.json +5 -0
- data/lib/proscenium/side_load.rb +96 -0
- data/lib/proscenium/version.rb +5 -0
- data/lib/proscenium/view_component/tag_builder.rb +23 -0
- data/lib/proscenium/view_component.rb +38 -0
- data/lib/proscenium.rb +18 -0
- data/lib/tasks/assets.rake +19 -0
- metadata +179 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3e3e07ba3e379ca73169149eecf63a25c49a6a8410200bd6d552fdff4d8e58f8
|
4
|
+
data.tar.gz: 51abd6eecf71b9a1a1c74b6b6576765710ab6d3b273daee8e3a1f02ba9e7ecbf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c05bc284df4b0ae4a84eef3a93dfdb83dbdaed624ae699fdff54cfae02d9be1d1aeb01ed4879e5b80b83ac794968fda301e83848929cfc9bdb18c880080e41be
|
7
|
+
data.tar.gz: 635bb7478afa4a130266ca7e1abfed8c3faa2da07b96cdb4a28bcaab6819d53a095b468b26d4a75ec9034bcf9943692359263a8239a4a4cc7209c3aa7be7fed2
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at joel@developwithstyle.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/README.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# Proscenium
|
2
|
+
|
3
|
+
- Serve assets from anywhere within the Rails root. (eg. `/app/views/layouts/application.css`, `/lib/utils/time.js`)
|
4
|
+
- Side loaded JS/CSS for your layouts and views.
|
5
|
+
- JS imports
|
6
|
+
- Dynamic imports
|
7
|
+
- Real-time bundling of JS, JSX and CSS.
|
8
|
+
- Import CSS and other static assets (images, fonts, etc.)
|
9
|
+
|
10
|
+
## WANT
|
11
|
+
|
12
|
+
- Nested CSS
|
13
|
+
- Import CSS Modules
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'proscenium'
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
### Side Loading
|
26
|
+
|
27
|
+
Proscenium has built in support for automatically side loading JS and CSS with your views and layouts.
|
28
|
+
|
29
|
+
Just create a JS and/or CSS file with the same name as any view or layout, and make sure your layouts include `<%= yield :side_loaded_js %>` and `<%= yield :side_loaded_css %>`. Something like this:
|
30
|
+
|
31
|
+
```html
|
32
|
+
<!DOCTYPE html>
|
33
|
+
<html>
|
34
|
+
<head>
|
35
|
+
<title>Hello World</title>
|
36
|
+
<%= yield :side_loaded_css %>
|
37
|
+
</head>
|
38
|
+
<body>
|
39
|
+
<%= yield %> <%= yield :side_loaded_js %>
|
40
|
+
</body>
|
41
|
+
</html>
|
42
|
+
```
|
43
|
+
|
44
|
+
On each page request, Proscenium will check if your layout and view has a JS/CSS file of the same name, and include them into your layout HTML.
|
45
|
+
|
46
|
+
### Importing in JS with `import`
|
47
|
+
|
48
|
+
Imports that do not begin with a `./` or `/` are bare imports, and will import a package using your local Node resolution algorithm.
|
49
|
+
|
50
|
+
`import 'react'`
|
51
|
+
`import React as * from 'react'`
|
52
|
+
`import { useState } from 'react'`
|
53
|
+
|
54
|
+
Absolute and relative import paths are supported (`/*`, `./*`), and will behave as you would expect.
|
55
|
+
|
56
|
+
Imports are assumed to be JS files, so there is no need to specify the file extesnion in such cases. But you can if you like. All other file types must be specified using their fill file name and extension.
|
57
|
+
|
58
|
+
### CSS
|
59
|
+
|
60
|
+
Direct access to CSS files are parsed through @parcel/css.
|
61
|
+
|
62
|
+
Importing a CSS file from JS will append the CSS file to the document's head. The results of the import will be an object of CSS modules.
|
63
|
+
|
64
|
+
## How It Works
|
65
|
+
|
66
|
+
Proscenium provides a Rails middleware that proxies requests for your frontend code. By default, it will simply search for a file of the same name in your Rails root. For example, a request for '/app/views/layouts/application.js' or '/lib/hooks.js' will return that exact file relative to your Rails root.
|
67
|
+
|
68
|
+
This allows your frontend code to become first class citizens of you Rails application.
|
69
|
+
|
70
|
+
## Development
|
71
|
+
|
72
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
73
|
+
|
74
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
75
|
+
|
76
|
+
### Compile the compilers
|
77
|
+
|
78
|
+
`deno compile --no-config -o bin/compilers/esbuild --import-map import_map.json -A lib/proscenium/compilers/esbuild.js`
|
79
|
+
|
80
|
+
|
81
|
+
## Contributing
|
82
|
+
|
83
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/joelmoss/proscenium. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/joelmoss/proscenium/blob/master/CODE_OF_CONDUCT.md).
|
84
|
+
|
85
|
+
## License
|
86
|
+
|
87
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
88
|
+
|
89
|
+
## Code of Conduct
|
90
|
+
|
91
|
+
Everyone interacting in the Proscenium project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/joelmoss/proscenium/blob/master/CODE_OF_CONDUCT.md).
|
@@ -0,0 +1,24 @@
|
|
1
|
+
export default class CliArgumentError extends Error {
|
2
|
+
static MESSAGES = {
|
3
|
+
cwdRequired: 'Current working directory is required as first argument.',
|
4
|
+
entrypointRequired: 'An entry point is required as second argument.',
|
5
|
+
builderRequired: 'The builder is required as third and final argument.',
|
6
|
+
|
7
|
+
cwdUnknown: ({ cwd }) => `A valid working directory is required - received ${cwd}`,
|
8
|
+
entrypointUnknown: ({ entrypoint }) =>
|
9
|
+
`A valid entrypoint is required - received ${entrypoint}`,
|
10
|
+
builderUnknown: ({ builder }) => `Unknown builder '${builder}'`
|
11
|
+
}
|
12
|
+
|
13
|
+
constructor(reason, options) {
|
14
|
+
let message = CliArgumentError.MESSAGES[reason]
|
15
|
+
if (typeof message === 'function') {
|
16
|
+
message = message(options)
|
17
|
+
}
|
18
|
+
|
19
|
+
super(message, options)
|
20
|
+
|
21
|
+
this.reason = reason
|
22
|
+
this.message = message
|
23
|
+
}
|
24
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export const builderNames = ['javascript', 'react', 'solid']
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import { build, stop } from 'esbuild'
|
2
|
+
|
3
|
+
import envPlugin from '../esbuild/env_plugin.js'
|
4
|
+
import resolvePlugin from '../esbuild/resolve_plugin.js'
|
5
|
+
|
6
|
+
export default async (cwd, entrypoint) => {
|
7
|
+
const railsEnv = Deno.env.get('RAILS_ENV')
|
8
|
+
const isProd = railsEnv === 'production'
|
9
|
+
|
10
|
+
let entrypointIsSourcemap = false
|
11
|
+
if (/\.js\.map$/.test(entrypoint)) {
|
12
|
+
entrypoint = entrypoint.replace(/\.map$/, '')
|
13
|
+
entrypointIsSourcemap = true
|
14
|
+
}
|
15
|
+
|
16
|
+
const params = {
|
17
|
+
entryPoints: [entrypoint],
|
18
|
+
absWorkingDir: cwd,
|
19
|
+
logLevel: 'error',
|
20
|
+
sourcemap: !entrypointIsSourcemap ? false : 'linked',
|
21
|
+
outdir: 'public',
|
22
|
+
outbase: './',
|
23
|
+
write: false,
|
24
|
+
format: 'esm',
|
25
|
+
minify: isProd,
|
26
|
+
bundle: true,
|
27
|
+
plugins: [envPlugin(), resolvePlugin({ debug: false })]
|
28
|
+
}
|
29
|
+
|
30
|
+
try {
|
31
|
+
const result = await build(params)
|
32
|
+
|
33
|
+
if (params.sourcemap === 'linked') {
|
34
|
+
if (entrypointIsSourcemap) {
|
35
|
+
return result.outputFiles[0].contents
|
36
|
+
} else {
|
37
|
+
return result.outputFiles[1].contents
|
38
|
+
}
|
39
|
+
} else {
|
40
|
+
return result.outputFiles[0].contents
|
41
|
+
}
|
42
|
+
} finally {
|
43
|
+
stop()
|
44
|
+
}
|
45
|
+
}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
import { build, stop } from 'esbuild'
|
2
|
+
import { join } from 'std/path/mod.ts'
|
3
|
+
|
4
|
+
import envPlugin from '../esbuild/env_plugin.js'
|
5
|
+
import resolvePlugin from '../esbuild/resolve_plugin.js'
|
6
|
+
|
7
|
+
export default async (cwd, entrypoint) => {
|
8
|
+
const railsEnv = Deno.env.get('RAILS_ENV')
|
9
|
+
const isProd = railsEnv === 'production'
|
10
|
+
|
11
|
+
let entrypointIsSourcemap = false
|
12
|
+
if (/\.jsx\.map$/.test(entrypoint)) {
|
13
|
+
entrypoint = entrypoint.replace(/\.map$/, '')
|
14
|
+
entrypointIsSourcemap = true
|
15
|
+
}
|
16
|
+
|
17
|
+
const params = {
|
18
|
+
entryPoints: [entrypoint],
|
19
|
+
absWorkingDir: cwd,
|
20
|
+
logLevel: 'error',
|
21
|
+
sourcemap: !entrypointIsSourcemap ? false : 'linked',
|
22
|
+
outdir: 'public',
|
23
|
+
outbase: './',
|
24
|
+
write: false,
|
25
|
+
format: 'esm',
|
26
|
+
minify: isProd,
|
27
|
+
bundle: true,
|
28
|
+
// jsxFactory: 'createElement',
|
29
|
+
// jsxFragment: 'Fragment',
|
30
|
+
plugins: [envPlugin(), resolvePlugin({ debug: false })]
|
31
|
+
}
|
32
|
+
|
33
|
+
if (entrypoint.endsWith('.jsx')) {
|
34
|
+
try {
|
35
|
+
const stat = Deno.lstatSync(join(cwd, 'lib/react_shim.js'))
|
36
|
+
if (stat.isFile) {
|
37
|
+
params.inject = ['./lib/react_shim.js']
|
38
|
+
}
|
39
|
+
} catch {
|
40
|
+
// Safe to swallow as this should only throw if file does not exist.
|
41
|
+
// TODO: print warning to user
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
try {
|
46
|
+
const result = await build(params)
|
47
|
+
|
48
|
+
if (params.sourcemap === 'linked') {
|
49
|
+
if (entrypointIsSourcemap) {
|
50
|
+
return result.outputFiles[0].contents
|
51
|
+
} else {
|
52
|
+
return result.outputFiles[1].contents
|
53
|
+
}
|
54
|
+
} else {
|
55
|
+
return result.outputFiles[0].contents
|
56
|
+
}
|
57
|
+
} finally {
|
58
|
+
stop()
|
59
|
+
}
|
60
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import { build, stop } from 'esbuild'
|
2
|
+
|
3
|
+
import envPlugin from '../esbuild/env_plugin.js'
|
4
|
+
import resolvePlugin from '../esbuild/resolve_plugin.js'
|
5
|
+
import solidjsPlugin from '../esbuild/solidjs_plugin.js'
|
6
|
+
|
7
|
+
export default async (cwd, entrypoint) => {
|
8
|
+
const railsEnv = Deno.env.get('RAILS_ENV')
|
9
|
+
const isProd = railsEnv === 'production'
|
10
|
+
|
11
|
+
let entrypointIsSourcemap = false
|
12
|
+
if (/\.jsx\.map$/.test(entrypoint)) {
|
13
|
+
entrypoint = entrypoint.replace(/\.map$/, '')
|
14
|
+
entrypointIsSourcemap = true
|
15
|
+
}
|
16
|
+
|
17
|
+
const params = {
|
18
|
+
entryPoints: [entrypoint],
|
19
|
+
absWorkingDir: cwd,
|
20
|
+
logLevel: 'error',
|
21
|
+
sourcemap: !entrypointIsSourcemap ? false : 'linked',
|
22
|
+
outdir: 'public',
|
23
|
+
outbase: './',
|
24
|
+
write: false,
|
25
|
+
format: 'esm',
|
26
|
+
minify: isProd,
|
27
|
+
bundle: true,
|
28
|
+
plugins: [envPlugin(), resolvePlugin({ debug: false }), solidjsPlugin({ debug: false })]
|
29
|
+
}
|
30
|
+
|
31
|
+
try {
|
32
|
+
const result = await build(params)
|
33
|
+
|
34
|
+
if (params.sourcemap === 'linked') {
|
35
|
+
if (entrypointIsSourcemap) {
|
36
|
+
return result.outputFiles[0].contents
|
37
|
+
} else {
|
38
|
+
return result.outputFiles[1].contents
|
39
|
+
}
|
40
|
+
} else {
|
41
|
+
return result.outputFiles[0].contents
|
42
|
+
}
|
43
|
+
} finally {
|
44
|
+
stop()
|
45
|
+
}
|
46
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { setup } from '../utils.js'
|
2
|
+
|
3
|
+
export default setup('env', () => {
|
4
|
+
return {
|
5
|
+
onResolve: {
|
6
|
+
filter: /^env$/,
|
7
|
+
callback({ path }) {
|
8
|
+
return { path, namespace: 'env' }
|
9
|
+
}
|
10
|
+
},
|
11
|
+
|
12
|
+
onLoad: {
|
13
|
+
filter: /.*/,
|
14
|
+
namespace: 'env',
|
15
|
+
callback() {
|
16
|
+
const env = Deno.env.toObject()
|
17
|
+
return { loader: 'json', contents: JSON.stringify(env) }
|
18
|
+
}
|
19
|
+
}
|
20
|
+
}
|
21
|
+
})
|
@@ -0,0 +1,136 @@
|
|
1
|
+
import { join, resolve } from 'std/path/mod.ts'
|
2
|
+
import {
|
3
|
+
parseFromString as parseImportMap,
|
4
|
+
resolve as resolveFromImportMap
|
5
|
+
} from 'import-maps/resolve'
|
6
|
+
|
7
|
+
import { setup } from '../utils.js'
|
8
|
+
|
9
|
+
const baseURL = new URL('file://')
|
10
|
+
const importKinds = ['import-statement', 'dynamic-import', 'require-call']
|
11
|
+
|
12
|
+
export default setup('resolve', build => {
|
13
|
+
const cwd = build.initialOptions.absWorkingDir
|
14
|
+
const importMap = readImportMap()
|
15
|
+
|
16
|
+
return {
|
17
|
+
onResolve: {
|
18
|
+
filter: /.*/,
|
19
|
+
async callback(args) {
|
20
|
+
// Remote modules
|
21
|
+
if (args.path.startsWith('http://') || args.path.startsWith('https://')) {
|
22
|
+
return { external: true }
|
23
|
+
}
|
24
|
+
|
25
|
+
// Proscenium runtime
|
26
|
+
if (args.path.startsWith('/proscenium-runtime')) {
|
27
|
+
return { external: true }
|
28
|
+
}
|
29
|
+
|
30
|
+
// Everything else is unbundled.
|
31
|
+
if (importKinds.includes(args.kind)) {
|
32
|
+
return await unbundleImport(args)
|
33
|
+
}
|
34
|
+
}
|
35
|
+
},
|
36
|
+
|
37
|
+
onLoad: {
|
38
|
+
filter: /.*/,
|
39
|
+
namespace: 'importStylesheet',
|
40
|
+
callback(args) {
|
41
|
+
const result = {
|
42
|
+
resolveDir: cwd,
|
43
|
+
loader: 'js'
|
44
|
+
}
|
45
|
+
|
46
|
+
if (args.path.endsWith('.module.css')) {
|
47
|
+
result.contents = `
|
48
|
+
import { importCssModule } from '/proscenium-runtime/import_css.js'
|
49
|
+
export default await importCssModule('${args.path}')
|
50
|
+
`
|
51
|
+
} else {
|
52
|
+
result.contents = `
|
53
|
+
import { appendStylesheet } from '/proscenium-runtime/import_css.js'
|
54
|
+
appendStylesheet('${args.path}')
|
55
|
+
`
|
56
|
+
}
|
57
|
+
|
58
|
+
return result
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
// Resolve the given `params.path` to a path relative to the Rails root.
|
64
|
+
//
|
65
|
+
// Examples:
|
66
|
+
// 'react' -> '/.../node_modules/react/index.js'
|
67
|
+
// './my_module' -> '/.../app/my_module.js'
|
68
|
+
// '/app/my_module' -> '/.../app/my_module.js'
|
69
|
+
async function unbundleImport(params) {
|
70
|
+
const result = { path: params.path }
|
71
|
+
|
72
|
+
if (importMap) {
|
73
|
+
const { matched, resolvedImport } = resolveFromImportMap(params.path, importMap, baseURL)
|
74
|
+
if (matched) {
|
75
|
+
if (resolvedImport.protocol === 'file:') {
|
76
|
+
params.path = resolvedImport.pathname
|
77
|
+
} else {
|
78
|
+
return { path: resolvedImport.href, external: true }
|
79
|
+
}
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
// Absolute path - append to current working dir.
|
84
|
+
if (params.path.startsWith('/')) {
|
85
|
+
result.path = resolve(cwd, params.path.slice(1))
|
86
|
+
}
|
87
|
+
|
88
|
+
// Resolve the path using esbuild's internal resolution. This allows us to import node packages
|
89
|
+
// and extension-less paths without custom code, as esbuild with resolve them for us.
|
90
|
+
const resolveResult = await build.resolve(result.path, {
|
91
|
+
resolveDir: params.resolveDir,
|
92
|
+
pluginData: {
|
93
|
+
// We use this property later on, as we should ignore this resolution call.
|
94
|
+
isResolvingPath: true
|
95
|
+
}
|
96
|
+
})
|
97
|
+
|
98
|
+
if (resolveResult.errors.length > 0) {
|
99
|
+
// throw `${resolveResult.errors[0].text} (resolveDir: ${cwd})`
|
100
|
+
}
|
101
|
+
|
102
|
+
result.path = resolveResult.path.slice(cwd.length)
|
103
|
+
result.sideEffects = resolveResult.sideEffects
|
104
|
+
|
105
|
+
if (
|
106
|
+
params.path.endsWith('.css') &&
|
107
|
+
params.kind === 'import-statement' &&
|
108
|
+
/\.jsx?$/.test(params.importer)
|
109
|
+
) {
|
110
|
+
// We're importing a CSS file from JS(X).
|
111
|
+
result.namespace = 'importStylesheet'
|
112
|
+
} else {
|
113
|
+
// Requested path is a bare module.
|
114
|
+
result.external = true
|
115
|
+
}
|
116
|
+
|
117
|
+
return result
|
118
|
+
}
|
119
|
+
|
120
|
+
function readImportMap() {
|
121
|
+
const file = join(cwd, 'config', 'import_map.json')
|
122
|
+
let source
|
123
|
+
|
124
|
+
try {
|
125
|
+
source = Deno.readTextFileSync(file)
|
126
|
+
} catch {
|
127
|
+
return null
|
128
|
+
}
|
129
|
+
|
130
|
+
return parseImportMap(source, baseURL)
|
131
|
+
}
|
132
|
+
})
|
133
|
+
|
134
|
+
function isBareModule(path) {
|
135
|
+
return !path.startsWith('.') && !path.startsWith('/')
|
136
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { basename } from 'std/path/mod.ts'
|
2
|
+
import { transformAsync } from '@babel/core'
|
3
|
+
import solid from 'babel-preset-solid'
|
4
|
+
|
5
|
+
import { setup } from '../utils.js'
|
6
|
+
|
7
|
+
export default setup('solidjs', () => {
|
8
|
+
return {
|
9
|
+
onLoad: {
|
10
|
+
filter: /\.jsx$/,
|
11
|
+
async callback(args) {
|
12
|
+
const source = await Deno.readTextFile(args.path)
|
13
|
+
|
14
|
+
const { code } = await transformAsync(source, {
|
15
|
+
presets: [solid],
|
16
|
+
filename: basename(args.path)
|
17
|
+
})
|
18
|
+
|
19
|
+
return { contents: code, loader: 'js' }
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
})
|