sprockets-esbuild 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/esbuild +44 -0
- data/lib/sprockets-esbuild/transformers.rb +34 -10
- data/lib/sprockets-esbuild/upstream.rb +14 -0
- data/lib/sprockets-esbuild/version.rb +1 -1
- data/lib/sprockets-esbuild.rb +4 -0
- metadata +10 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bca55e983e0f3b8b0f6a9d019503a390f8180789ddf3a67a2e8de4afa2403e6f
|
4
|
+
data.tar.gz: e0a0c286538752cde303348acf7372995e56f79d5c04efa3bb519d021f762b77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4dbaecdf5ecae95bd636151f364c69c3a3b7c0b5826971098d0d7be6124a1f8aa5cd3df11daf855f02c5ee287e691313db4e0a1b0bc8b9deb71424ea9a44a338
|
7
|
+
data.tar.gz: 1029871174fc520da0b1f1c0f2919968c648c484104ef519282eb5a0fd9ad058756f666d7a8d45274deeb400fe0ee52d0fb97212963b5ff0d594c20c7653a130
|
data/exe/esbuild
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# because rubygems shims assume a gem's executables are Ruby
|
3
|
+
|
4
|
+
require "sprockets-esbuild/upstream"
|
5
|
+
|
6
|
+
supported_platforms = SprocketsEsbuild::Upstream::NATIVE_PLATFORMS.keys
|
7
|
+
platform = [:cpu, :os].map { |m| Gem::Platform.local.send(m) }.join("-")
|
8
|
+
|
9
|
+
if supported_platforms.none? { |supported_platform| Gem::Platform.match(supported_platform) }
|
10
|
+
STDERR.puts(<<~ERRMSG)
|
11
|
+
ERROR: sprockets-esbuild does not support the #{platform} platform
|
12
|
+
ERRMSG
|
13
|
+
exit 1
|
14
|
+
end
|
15
|
+
|
16
|
+
exe_path = Dir.glob(File.join(__dir__, "*", "esbuild")).find do |f|
|
17
|
+
Gem::Platform.match(File.basename(File.dirname(f)))
|
18
|
+
end
|
19
|
+
if exe_path.nil?
|
20
|
+
STDERR.puts(<<~ERRMSG)
|
21
|
+
ERROR: Cannot find the esbuild executable for #{platform} in #{__dir__}
|
22
|
+
If you're using bundler, please make sure you're on the latest bundler version:
|
23
|
+
|
24
|
+
gem install bundler
|
25
|
+
bundle update --bundler
|
26
|
+
|
27
|
+
Then make sure your lock file includes this platform by running:
|
28
|
+
|
29
|
+
bundle lock --add-platform #{platform}
|
30
|
+
bundle install
|
31
|
+
|
32
|
+
See `bundle lock --help` output for details.
|
33
|
+
ERRMSG
|
34
|
+
exit 1
|
35
|
+
end
|
36
|
+
|
37
|
+
if Gem.win_platform?
|
38
|
+
# use system rather than exec as exec inexplicably fails to find the executable
|
39
|
+
# on Windows
|
40
|
+
system exe_path, *ARGV
|
41
|
+
else
|
42
|
+
# use exec rather than system to avoid creating a new process
|
43
|
+
exec exe_path, *ARGV
|
44
|
+
end
|
@@ -3,13 +3,21 @@
|
|
3
3
|
|
4
4
|
require 'open3'
|
5
5
|
require 'sprockets'
|
6
|
+
require 'sprockets/source_map_utils'
|
7
|
+
require 'json'
|
8
|
+
require 'base64'
|
9
|
+
require 'pathname'
|
6
10
|
|
7
11
|
module SprocketsEsbuild
|
8
12
|
|
9
13
|
class TransformerBase
|
10
14
|
include Sprockets
|
11
15
|
|
12
|
-
ESBUILD = File.expand_path('../../exe/esbuild', __dir__)
|
16
|
+
ESBUILD = [File.expand_path('../../exe/esbuild', __dir__)]
|
17
|
+
|
18
|
+
# As windows doesn't support she-bang syntax in scripts, prepend Ruby to
|
19
|
+
# the command
|
20
|
+
ESBUILD.unshift RbConfig.ruby if Gem.win_platform?
|
13
21
|
|
14
22
|
def cache_key
|
15
23
|
@cache_key ||= "#{self.class.name}::#{VERSION}".freeze
|
@@ -20,15 +28,31 @@ module SprocketsEsbuild
|
|
20
28
|
|
21
29
|
input[:cache].fetch([cache_key, data]) do
|
22
30
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
out, err, status = Open3.capture3(*ESBUILD, '--sourcemap',
|
32
|
+
"--sourcefile=#{input[:filename]}", "--loader=#{loader}",
|
33
|
+
stdin_data: input[:data])
|
34
|
+
|
35
|
+
match = out.match %r{^//# sourceMappingURL=data:application/json;base64,(.*)\s*}
|
36
|
+
|
37
|
+
if match
|
38
|
+
# extract sourcemap from output and then format and combine it
|
39
|
+
out[match.begin(0)..match.end(0)] = ''
|
40
|
+
map = JSON.parse(Base64.decode64(match[1]))
|
41
|
+
map = SourceMapUtils.format_source_map(map, input)
|
42
|
+
map = SourceMapUtils.combine_source_maps(input[:metadata][:map], map)
|
43
|
+
else
|
44
|
+
map = nil
|
45
|
+
end
|
46
|
+
|
47
|
+
if status.success? and err.empty?
|
48
|
+
if map
|
49
|
+
{ data: out, map: map }
|
50
|
+
else
|
51
|
+
out
|
52
|
+
end
|
53
|
+
else
|
54
|
+
raise Error, "esbuild exit status=#{status.exitstatus}\n#{err}"
|
55
|
+
end
|
32
56
|
end
|
33
57
|
end
|
34
58
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module SprocketsEsbuild
|
2
|
+
# constants describing the upstream esbuild project
|
3
|
+
module Upstream
|
4
|
+
VERSION = "0.14.5"
|
5
|
+
|
6
|
+
# rubygems platform name => [upstream release tarball name, tarball path]
|
7
|
+
NATIVE_PLATFORMS = {
|
8
|
+
"arm64-darwin" => ["esbuild-darwin-arm64", "package/bin/esbuild"],
|
9
|
+
"x64-mingw32" => ["esbuild-windows-64", "package/esbuild.exe"],
|
10
|
+
"x86_64-darwin" => ["esbuild-darwin-64", "package/bin/esbuild"],
|
11
|
+
"x86_64-linux" => ["esbuild-linux-64", "package/bin/esbuild"],
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
data/lib/sprockets-esbuild.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprockets-esbuild
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Ruby
|
8
|
+
- Mike Dalessio
|
8
9
|
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2023-10-17 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: sprockets
|
@@ -26,20 +27,23 @@ dependencies:
|
|
26
27
|
version: '0'
|
27
28
|
description:
|
28
29
|
email: rubys@intertwingly.net
|
29
|
-
executables:
|
30
|
+
executables:
|
31
|
+
- esbuild
|
30
32
|
extensions: []
|
31
33
|
extra_rdoc_files: []
|
32
34
|
files:
|
33
35
|
- README.md
|
34
36
|
- Rakefile
|
37
|
+
- exe/esbuild
|
35
38
|
- lib/sprockets-esbuild.rb
|
36
39
|
- lib/sprockets-esbuild/transformers.rb
|
40
|
+
- lib/sprockets-esbuild/upstream.rb
|
37
41
|
- lib/sprockets-esbuild/version.rb
|
38
|
-
homepage: https://github.com/
|
42
|
+
homepage: https://github.com/rubys/sprockets-esbuild
|
39
43
|
licenses:
|
40
44
|
- MIT
|
41
45
|
metadata:
|
42
|
-
homepage_uri: https://github.com/
|
46
|
+
homepage_uri: https://github.com/rubys/sprockets-esbuild
|
43
47
|
post_install_message:
|
44
48
|
rdoc_options: []
|
45
49
|
require_paths:
|
@@ -55,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
59
|
- !ruby/object:Gem::Version
|
56
60
|
version: '0'
|
57
61
|
requirements: []
|
58
|
-
rubygems_version: 3.
|
62
|
+
rubygems_version: 3.4.8
|
59
63
|
signing_key:
|
60
64
|
specification_version: 4
|
61
65
|
summary: Transpile JSX, TS, and TSX files with esbuild.
|