sprockets-esbuild 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +19 -0
- data/Rakefile +14 -0
- data/lib/sprockets-esbuild/transformers.rb +69 -0
- data/lib/sprockets-esbuild/version.rb +3 -0
- data/lib/sprockets-esbuild.rb +2 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5246ad865fb26e08ce0a305c8f828e41ed83b0ddbc778e123457b454c71daf4a
|
4
|
+
data.tar.gz: a920c21b7a2910ec105c37e3a554dd2cc495e37378ab62eb55854efd58e1b417
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8c5cb84dc61c7c4dcceb1667ba6d6997f2f10cba8f73bfe4a5c36587bce6961faf69b0d390ad47c9c7ce3e61c7c9a0951bfe72ff7cc592cf855c177e896d06ba
|
7
|
+
data.tar.gz: 4402a53b024d8ed8a707c40dd53d02f109d33621bb509ebc2a32d1bc86dfca45e6839e1c5fdc0d86b14d72688503d81e3d7fa175b35fa740aab2c311d1c58c8a
|
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# esbuild support for Sprockets
|
2
|
+
|
3
|
+
esbuild is an extremely fast transpiler.
|
4
|
+
|
5
|
+
This gem uses esbuild to implement Sprockets transformers that will convert
|
6
|
+
TypeScript, JSX, and TSX formats to JavaScript. Sourcemaps are produced.
|
7
|
+
|
8
|
+
This gem wraps [the standalone executable version](https://esbuild.github.io/getting-started/#download-a-build) of the esbuild executables. These executables are platform specific, so there are actually separate underlying gems per platform, but the correct gem will automatically be picked for your platform. Supported platforms are Linux x64, macOS arm64, macOS x64, and Windows x64. (Note that due to this setup, you must install the actual gems – you can't pin your gem to the github repo.)
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Inside a Rails application, run:
|
13
|
+
|
14
|
+
1. Run `./bin/bundle add sprockets-esbuild`
|
15
|
+
|
16
|
+
## License
|
17
|
+
|
18
|
+
sprockets-esbuild is released under the [MIT License](https://opensource.org/licenses/MIT).
|
19
|
+
esbuild is released under the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Define JSX, TS (TypeScript) and TSX tranformers, based on shelling
|
2
|
+
# out to a platform specific esbuild executable.
|
3
|
+
|
4
|
+
require 'open3'
|
5
|
+
require 'sprockets'
|
6
|
+
|
7
|
+
module SprocketsEsbuild
|
8
|
+
|
9
|
+
class TransformerBase
|
10
|
+
include Sprockets
|
11
|
+
|
12
|
+
ESBUILD = File.expand_path('../../exe/esbuild', __dir__)
|
13
|
+
|
14
|
+
def cache_key
|
15
|
+
@cache_key ||= "#{self.class.name}::#{VERSION}".freeze
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(input)
|
19
|
+
data = input[:data]
|
20
|
+
|
21
|
+
input[:cache].fetch([cache_key, data]) do
|
22
|
+
|
23
|
+
out, err, status = Open3.capture3(ESBUILD, '--sourcemap',
|
24
|
+
"--sourcefile=#{input[:filename]}", "--loader=#{loader}",
|
25
|
+
stdin_data: input[:data])
|
26
|
+
|
27
|
+
if status.success? and err.empty?
|
28
|
+
out
|
29
|
+
else
|
30
|
+
raise Error, "esbuild exit status=#{status.exitstatus}\n#{err}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# https://esbuild.github.io/content-types/#jsx
|
37
|
+
class JsxTransformer < TransformerBase
|
38
|
+
def loader
|
39
|
+
'jsx'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# https://esbuild.github.io/content-types/#typescript
|
44
|
+
class TsTransformer < TransformerBase
|
45
|
+
def loader
|
46
|
+
'ts'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# https://esbuild.github.io/content-types/#typescript
|
51
|
+
class TsxTransformer < TransformerBase
|
52
|
+
def loader
|
53
|
+
'tsx'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
Sprockets.register_mime_type 'application/typescript', extensions: ['.ts']
|
59
|
+
Sprockets.register_mime_type 'text/jsx', extensions: ['.jsx']
|
60
|
+
Sprockets.register_mime_type 'text/tsx', extensions: ['.tsx']
|
61
|
+
|
62
|
+
Sprockets.register_transformer 'application/typescript',
|
63
|
+
'application/javascript', SprocketsEsbuild::TsTransformer.new
|
64
|
+
|
65
|
+
Sprockets.register_transformer 'text/jsx',
|
66
|
+
'application/javascript', SprocketsEsbuild::JsxTransformer.new
|
67
|
+
|
68
|
+
Sprockets.register_transformer 'text/tsx',
|
69
|
+
'application/javascript', SprocketsEsbuild::TsxTransformer.new
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sprockets-esbuild
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sam Ruby
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-12-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sprockets
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description:
|
28
|
+
email: rubys@intertwingly.net
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- README.md
|
34
|
+
- Rakefile
|
35
|
+
- lib/sprockets-esbuild.rb
|
36
|
+
- lib/sprockets-esbuild/transformers.rb
|
37
|
+
- lib/sprockets-esbuild/version.rb
|
38
|
+
homepage: https://github.com/rails/tailwindcss-rails
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
metadata:
|
42
|
+
homepage_uri: https://github.com/rails/tailwindcss-rails
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubygems_version: 3.2.33
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: Transpile JSX, TS, and TSX files with esbuild.
|
62
|
+
test_files: []
|