klenod-plugin-javascript 0.0.13-x86_64-linux-gnu → 0.0.15-x86_64-linux-gnu

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93e12c1ce189a9594b75b4dd1089c0b89836820779e2e7eeb24c0d90d0ccc917
4
- data.tar.gz: 7f37d8ce72b820bdf3f4d49811339277632a3ea50106425785134ed4823a4635
3
+ metadata.gz: 6e2efdc5ff7f3e660d14d94667779d56a1f4dac6f732757bb2eeb426ac27f704
4
+ data.tar.gz: e39667dd6c82ea3474a37a195185ae656cef7c7d82560d5f8efd8bfebdeb5682
5
5
  SHA512:
6
- metadata.gz: 9b20181d84ce6a159b32e0c771d352dfb52286b2e6f795418ccb599589f621710119d3d9bafd42602f228d976a74aa20f26623f9fcd6e7d80058513954462191
7
- data.tar.gz: 26159b0c1ec522c4b4a48cd242442818aa6c4df009f391f515cfbc0cbb1040d4af5bdaf02ba3da4dab1d4d1831f4ed6f23ccd2dcc1595208dbe50bc034c75f0e
6
+ metadata.gz: bdadf68324c823a129f86fb36f4fda317299421bd1231ba631e4d3c64cbf9fe1b49830814384a20a70f90c2d9f160f5191741a9b737c26fb8130391a0813be05
7
+ data.tar.gz: c3e3b9997534cecab63b8650016b2a8be67723cf8f4508e6b2ee44f0deaf4aea8288c6b254b424be9fc9c4fffb180a0df71a8b4ee4108332ffa6eee1ffb46133
@@ -12,6 +12,7 @@ require "klenod/build/source_map"
12
12
  require "klenod/build/transform_result"
13
13
  require "klenod/runtime"
14
14
 
15
+ require_relative "../../plugin/javascript/errors"
15
16
  require_relative "../../plugin/javascript/parser"
16
17
 
17
18
  module Klenod
@@ -72,14 +73,21 @@ module Klenod
72
73
  return super unless EXTENSIONS.include?(module_id.extname)
73
74
 
74
75
  custom_element = custom_element_module?(module_id)
76
+ return analysis_transform(module_id, code, custom_element) if context.analysis?
77
+
75
78
  jsx_runtime_namespace = custom_element ? jsx_runtime_namespace(module_id) : nil
76
- transform = Parser.transform(
77
- code,
78
- filename: module_id.to_s,
79
- source_kind: source_kind(module_id),
80
- minify: minify_enabled?(context),
81
- jsx_runtime_namespace: jsx_runtime_namespace
82
- )
79
+ transform =
80
+ begin
81
+ Parser.transform(
82
+ code,
83
+ filename: module_id.to_s,
84
+ source_kind: source_kind(module_id),
85
+ minify: minify_enabled?(context),
86
+ jsx_runtime_namespace: jsx_runtime_namespace
87
+ )
88
+ rescue ScriptError => e
89
+ raise ParseError.new(e, source: code, module_id: module_id)
90
+ end
83
91
  javascript_source, imports =
84
92
  if custom_element
85
93
  inject_jsx_runtime(transform.code, transform.imports, module_id, jsx_runtime_namespace)
@@ -103,6 +111,22 @@ module Klenod
103
111
  )
104
112
  end
105
113
 
114
+ # Analysis only needs the module graph: imports are scanned without
115
+ # compiling, and the missing javascript_source makes finalize skip
116
+ # import rewriting and asset emission.
117
+ def analysis_transform(module_id, code, custom_element)
118
+ imports = Parser::FallbackScanner.new(code, module_id.to_s).imports
119
+
120
+ Klenod::Build::TransformResult.new(
121
+ module_source(nil),
122
+ build_dependencies(module_id, imports),
123
+ nil,
124
+ [],
125
+ [],
126
+ {javascript_imports: imports, javascript_custom_element: custom_element}
127
+ )
128
+ end
129
+
106
130
  def finalize(module_id, result, resolved_dependencies, dependency_records, context)
107
131
  source = result.metadata[:javascript_source]
108
132
  original_source = result.metadata[:javascript_original_source]
@@ -90,7 +90,7 @@ module Klenod
90
90
  return nil unless module_id.scheme == SCHEME
91
91
 
92
92
  path = absolute_path(module_id, context)
93
- LoadResult.new(path.read(encoding: "UTF-8"), Hashing.file_hexdigest(path), nil)
93
+ LoadResult.new(path.read(encoding: "UTF-8"), context.analysis? ? Hashing.file_key(path) : Hashing.file_hexdigest(path), nil)
94
94
  end
95
95
 
96
96
  private
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "klenod/build/source_error"
4
+
5
+ module Klenod
6
+ module Build
7
+ module Plugins
8
+ module JavaScriptPlugin
9
+ # The native parser raises a bare SyntaxError, which is a ScriptError
10
+ # rather than a StandardError, so it escapes every `rescue => e` in the
11
+ # build and takes the watcher thread down with it. Wrapping it in a
12
+ # SourceError that carries the source lets it be collected like a Haml
13
+ # parse error and rendered in the browser error dialog.
14
+ class ParseError < Klenod::Build::SourceError
15
+ # "app:/pages/thing.tsx:33:9: Expected '</', got ':'"
16
+ LOCATION = /\A(?<file>.+?):(?<line>\d+):(?<column>\d+):\s*(?<message>.*)\z/m
17
+
18
+ def kind
19
+ "JavaScript parse error"
20
+ end
21
+
22
+ private
23
+
24
+ def location(error)
25
+ found = LOCATION.match(error.message)
26
+ return nil unless found
27
+
28
+ # One-based, matching HamlPlugin::ParseError#line and the column the
29
+ # native parser reports.
30
+ Location.new(
31
+ line: found[:line].to_i,
32
+ column: found[:column].to_i,
33
+ detail: found[:message]
34
+ )
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
Binary file
@@ -4,7 +4,7 @@ module Klenod
4
4
  module Build
5
5
  module Plugins
6
6
  module JavaScriptPlugin
7
- VERSION = "0.0.13"
7
+ VERSION = "0.0.15"
8
8
  end
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: klenod-plugin-javascript
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.15
5
5
  platform: x86_64-linux-gnu
6
6
  authors:
7
7
  - Andrés Alin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-09-10 00:00:00.000000000 Z
11
+ date: 2026-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: klenod-build
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.13
19
+ version: 0.0.15
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.0.13
26
+ version: 0.0.15
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake-compiler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -50,6 +50,7 @@ files:
50
50
  - lib/klenod/build/plugins/node_modules_plugin.rb
51
51
  - lib/klenod/build/plugins/node_modules_plugin/package_exports.rb
52
52
  - lib/klenod/plugin/javascript.rb
53
+ - lib/klenod/plugin/javascript/errors.rb
53
54
  - lib/klenod/plugin/javascript/native.so
54
55
  - lib/klenod/plugin/javascript/parser.rb
55
56
  - lib/klenod/plugin/javascript/version.rb