@granite-js/plugin-hermes 3.0.3 → 3.0.4

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @granite-js/plugin-hermes
2
2
 
3
+ ## 3.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - 5cb1506: handle missing sourcemap locations
8
+ - @granite-js/plugin-core@3.0.4
9
+ - @granite-js/utils@3.0.4
10
+
3
11
  ## 3.0.3
4
12
 
5
13
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_resolveHermesBinaryPath = require('./resolveHermesBinaryPath-jlhzRycN.cjs');
2
+ const require_resolveHermesBinaryPath = require('./resolveHermesBinaryPath-BH1a-HVW.cjs');
3
3
  let node_path = require("node:path");
4
4
  node_path = require_resolveHermesBinaryPath.__toESM(node_path);
5
5
 
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as writeComposedSourcemap, r as compileHbc, t as resolveHermesBinaryPath } from "./resolveHermesBinaryPath-DwwS_er8.js";
1
+ import { n as writeComposedSourcemap, r as compileHbc, t as resolveHermesBinaryPath } from "./resolveHermesBinaryPath-g1hQbUmU.js";
2
2
  import * as path from "node:path";
3
3
 
4
4
  //#region src/next/index.ts
package/dist/mpack.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_resolveHermesBinaryPath = require('./resolveHermesBinaryPath-jlhzRycN.cjs');
2
+ const require_resolveHermesBinaryPath = require('./resolveHermesBinaryPath-BH1a-HVW.cjs');
3
3
  let _granite_js_plugin_core = require("@granite-js/plugin-core");
4
4
 
5
5
  //#region src/hermesPlugin.ts
package/dist/mpack.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as writeComposedSourcemap, r as compileHbc, t as resolveHermesBinaryPath } from "./resolveHermesBinaryPath-DwwS_er8.js";
1
+ import { n as writeComposedSourcemap, r as compileHbc, t as resolveHermesBinaryPath } from "./resolveHermesBinaryPath-g1hQbUmU.js";
2
2
  import { isBuildSuccess } from "@granite-js/plugin-core";
3
3
 
4
4
  //#region src/hermesPlugin.ts
@@ -32,6 +32,7 @@ let execa = require("execa");
32
32
  execa = __toESM(execa);
33
33
  let fs_promises = require("fs/promises");
34
34
  fs_promises = __toESM(fs_promises);
35
+ let _jridgewell_sourcemap_codec = require("@jridgewell/sourcemap-codec");
35
36
  let source_map = require("source-map");
36
37
  let node_fs = require("node:fs");
37
38
  node_fs = __toESM(node_fs);
@@ -76,11 +77,27 @@ async function writeComposedSourcemap(jsSourcemapPath, hbcSourcemapPath) {
76
77
  }
77
78
  async function composeSourcemap(jsSourcemapPath, hbcSourcemapPath) {
78
79
  const [jsSourceMapContent, hbcSourceMapContent] = await Promise.all([fs_promises.readFile(jsSourcemapPath, "utf8"), fs_promises.readFile(hbcSourcemapPath, "utf8")]);
79
- const jsMapConsumer = await new source_map.SourceMapConsumer(jsSourceMapContent);
80
- const hermesMapConsumer = await new source_map.SourceMapConsumer(hbcSourceMapContent);
81
- const generator = source_map.SourceMapGenerator.fromSourceMap(hermesMapConsumer);
82
- generator.applySourceMap(jsMapConsumer, hermesMapConsumer.sources[0]);
83
- return generator.toString();
80
+ return source_map.SourceMapConsumer.with(jsSourceMapContent, null, (jsMapConsumer) => source_map.SourceMapConsumer.with(normalizeHermesLocations(hbcSourceMapContent), null, (hermesMapConsumer) => {
81
+ const generator = source_map.SourceMapGenerator.fromSourceMap(hermesMapConsumer);
82
+ generator.applySourceMap(jsMapConsumer, hermesMapConsumer.sources[0]);
83
+ return generator.toString();
84
+ }));
85
+ }
86
+ function normalizeHermesLocations(content) {
87
+ const map = JSON.parse(content);
88
+ const mappings = (0, _jridgewell_sourcemap_codec.decode)(map.mappings);
89
+ let changed = false;
90
+ for (const line of mappings) for (let index = 0; index < line.length; index++) {
91
+ const segment = line[index];
92
+ if (segment.length === 4 && segment[1] >= 0 && segment[1] < map.sources.length && segment[2] === -1 && segment[3] === -1) {
93
+ line[index] = [segment[0]];
94
+ changed = true;
95
+ }
96
+ }
97
+ return changed ? JSON.stringify({
98
+ ...map,
99
+ mappings: (0, _jridgewell_sourcemap_codec.encode)(mappings)
100
+ }) : content;
84
101
  }
85
102
 
86
103
  //#endregion
@@ -3,6 +3,7 @@ import * as path from "node:path";
3
3
  import { isNotNil } from "es-toolkit";
4
4
  import execa from "execa";
5
5
  import * as fs$1 from "fs/promises";
6
+ import { decode, encode } from "@jridgewell/sourcemap-codec";
6
7
  import { SourceMapConsumer, SourceMapGenerator } from "source-map";
7
8
  import * as fs from "node:fs";
8
9
  import { getPackageRoot } from "@granite-js/utils";
@@ -50,11 +51,27 @@ async function writeComposedSourcemap(jsSourcemapPath, hbcSourcemapPath) {
50
51
  }
51
52
  async function composeSourcemap(jsSourcemapPath, hbcSourcemapPath) {
52
53
  const [jsSourceMapContent, hbcSourceMapContent] = await Promise.all([fs$1.readFile(jsSourcemapPath, "utf8"), fs$1.readFile(hbcSourcemapPath, "utf8")]);
53
- const jsMapConsumer = await new SourceMapConsumer(jsSourceMapContent);
54
- const hermesMapConsumer = await new SourceMapConsumer(hbcSourceMapContent);
55
- const generator = SourceMapGenerator.fromSourceMap(hermesMapConsumer);
56
- generator.applySourceMap(jsMapConsumer, hermesMapConsumer.sources[0]);
57
- return generator.toString();
54
+ return SourceMapConsumer.with(jsSourceMapContent, null, (jsMapConsumer) => SourceMapConsumer.with(normalizeHermesLocations(hbcSourceMapContent), null, (hermesMapConsumer) => {
55
+ const generator = SourceMapGenerator.fromSourceMap(hermesMapConsumer);
56
+ generator.applySourceMap(jsMapConsumer, hermesMapConsumer.sources[0]);
57
+ return generator.toString();
58
+ }));
59
+ }
60
+ function normalizeHermesLocations(content) {
61
+ const map = JSON.parse(content);
62
+ const mappings = decode(map.mappings);
63
+ let changed = false;
64
+ for (const line of mappings) for (let index = 0; index < line.length; index++) {
65
+ const segment = line[index];
66
+ if (segment.length === 4 && segment[1] >= 0 && segment[1] < map.sources.length && segment[2] === -1 && segment[3] === -1) {
67
+ line[index] = [segment[0]];
68
+ changed = true;
69
+ }
70
+ }
71
+ return changed ? JSON.stringify({
72
+ ...map,
73
+ mappings: encode(mappings)
74
+ }) : content;
58
75
  }
59
76
 
60
77
  //#endregion
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@granite-js/plugin-hermes",
3
3
  "type": "module",
4
- "version": "3.0.3",
4
+ "version": "3.0.4",
5
5
  "description": "Hermes compilation plugin for Granite",
6
6
  "scripts": {
7
7
  "prepack": "yarn build",
@@ -52,8 +52,9 @@
52
52
  "vitest": "^4.0.12"
53
53
  },
54
54
  "dependencies": {
55
- "@granite-js/plugin-core": "3.0.3",
56
- "@granite-js/utils": "3.0.3",
55
+ "@granite-js/plugin-core": "3.0.4",
56
+ "@granite-js/utils": "3.0.4",
57
+ "@jridgewell/sourcemap-codec": "^1.5.5",
57
58
  "es-toolkit": "^1.39.8",
58
59
  "execa": "^5",
59
60
  "source-map": "^0.8.0-beta.0"