@granite-js/plugin-hermes 0.1.33 → 1.0.0

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,305 +1,13 @@
1
1
  # @granite-js/plugin-hermes
2
2
 
3
- ## 0.1.33
3
+ ## 1.0.0
4
4
 
5
- ### Patch Changes
6
-
7
- - @granite-js/plugin-core@0.1.33
8
- - @granite-js/utils@0.1.33
9
-
10
- ## 0.1.32
11
-
12
- ### Patch Changes
13
-
14
- - 7572713: bump version up babel
15
- - Updated dependencies [7572713]
16
- - @granite-js/plugin-core@0.1.32
17
- - @granite-js/utils@0.1.32
18
-
19
- ## 0.1.31
20
-
21
- ### Patch Changes
22
-
23
- - Updated dependencies [9bf8b50]
24
- - Updated dependencies [e957833]
25
- - @granite-js/plugin-core@0.1.31
26
- - @granite-js/utils@0.1.31
27
-
28
- ## 0.1.30
29
-
30
- ### Patch Changes
31
-
32
- - @granite-js/plugin-core@0.1.30
33
- - @granite-js/utils@0.1.30
34
-
35
- ## 0.1.29
36
-
37
- ### Patch Changes
38
-
39
- - Updated dependencies [ed4cdbf]
40
- - @granite-js/plugin-core@0.1.29
41
- - @granite-js/utils@0.1.29
42
-
43
- ## 0.1.28
44
-
45
- ### Patch Changes
46
-
47
- - 1d958cc: ci: provenance
48
- - Updated dependencies [1d958cc]
49
- - @granite-js/plugin-core@0.1.28
50
- - @granite-js/utils@0.1.28
51
-
52
- ## 0.1.27
53
-
54
- ### Patch Changes
55
-
56
- - e32b020: ci: oidc
57
- - Updated dependencies [e32b020]
58
- - @granite-js/plugin-core@0.1.27
59
- - @granite-js/utils@0.1.27
60
-
61
- ## 0.1.26
62
-
63
- ### Patch Changes
64
-
65
- - @granite-js/plugin-core@0.1.26
66
- - @granite-js/utils@0.1.26
67
-
68
- ## 0.1.25
69
-
70
- ### Patch Changes
71
-
72
- - @granite-js/plugin-core@0.1.25
73
- - @granite-js/utils@0.1.25
74
-
75
- ## 0.1.24
76
-
77
- ### Patch Changes
78
-
79
- - Updated dependencies [6e42c3d]
80
- - @granite-js/plugin-core@0.1.24
81
- - @granite-js/utils@0.1.24
82
-
83
- ## 0.1.23
84
-
85
- ### Patch Changes
86
-
87
- - @granite-js/plugin-core@0.1.23
88
- - @granite-js/utils@0.1.23
89
-
90
- ## 0.1.22
91
-
92
- ### Patch Changes
93
-
94
- - @granite-js/plugin-core@0.1.22
95
- - @granite-js/utils@0.1.22
96
-
97
- ## 0.1.21
98
-
99
- ### Patch Changes
100
-
101
- - @granite-js/plugin-core@0.1.21
102
- - @granite-js/utils@0.1.21
103
-
104
- ## 0.1.20
105
-
106
- ### Patch Changes
107
-
108
- - @granite-js/plugin-core@0.1.20
109
- - @granite-js/utils@0.1.20
110
-
111
- ## 0.1.19
112
-
113
- ### Patch Changes
114
-
115
- - Updated dependencies [e9a3daf]
116
- - @granite-js/plugin-core@0.1.19
117
- - @granite-js/utils@0.1.19
118
-
119
- ## 0.1.18
120
-
121
- ### Patch Changes
122
-
123
- - @granite-js/plugin-core@0.1.18
124
- - @granite-js/utils@0.1.18
125
-
126
- ## 0.1.17
127
-
128
- ### Patch Changes
129
-
130
- - Updated dependencies [9c415df]
131
- - @granite-js/plugin-core@0.1.17
132
- - @granite-js/utils@0.1.17
133
-
134
- ## 0.1.16
135
-
136
- ### Patch Changes
137
-
138
- - c9b4fff: replace .js to .hbc
139
- - 1678419: improve plugin options
140
- - @granite-js/plugin-core@0.1.16
141
- - @granite-js/utils@0.1.16
142
-
143
- ## 0.1.15
144
-
145
- ### Patch Changes
146
-
147
- - d16ee87: Add useInitialProps, useInitialSearchParams hook.
148
- - Updated dependencies [d16ee87]
149
- - @granite-js/plugin-core@0.1.15
150
- - @granite-js/utils@0.1.15
151
-
152
- ## 0.1.14
153
-
154
- ### Patch Changes
155
-
156
- - @granite-js/plugin-core@0.1.14
157
- - @granite-js/utils@0.1.14
158
-
159
- ## 0.1.13
160
-
161
- ### Patch Changes
162
-
163
- - @granite-js/plugin-core@0.1.13
164
- - @granite-js/utils@0.1.13
165
-
166
- ## 0.1.12
167
-
168
- ### Patch Changes
169
-
170
- - d1e6585: fix module resolutions
171
- - Updated dependencies [d1e6585]
172
- - Updated dependencies [1e99fe1]
173
- - @granite-js/plugin-core@0.1.12
174
- - @granite-js/utils@0.1.12
175
-
176
- ## 0.1.11
177
-
178
- ### Patch Changes
179
-
180
- - Updated dependencies [d3a2b58]
181
- - @granite-js/plugin-core@0.1.11
182
- - @granite-js/utils@0.1.11
183
-
184
- ## 0.1.10
185
-
186
- ### Patch Changes
187
-
188
- - Updated dependencies [9438be5]
189
- - @granite-js/plugin-core@0.1.10
190
- - @granite-js/utils@0.1.10
191
-
192
- ## 0.1.9
193
-
194
- ### Patch Changes
195
-
196
- - Updated dependencies [935bb36]
197
- - @granite-js/plugin-core@0.1.9
198
- - @granite-js/utils@0.1.9
199
-
200
- ## 0.1.8
201
-
202
- ### Patch Changes
203
-
204
- - Updated dependencies [b69366c]
205
- - @granite-js/plugin-core@0.1.8
206
- - @granite-js/utils@0.1.8
207
-
208
- ## 0.1.7
209
-
210
- ### Patch Changes
211
-
212
- - @granite-js/plugin-core@0.1.7
213
- - @granite-js/utils@0.1.7
214
-
215
- ## 0.1.6
216
-
217
- ### Patch Changes
218
-
219
- - @granite-js/plugin-core@0.1.6
220
- - @granite-js/utils@0.1.6
221
-
222
- ## 0.1.5
223
-
224
- ### Patch Changes
225
-
226
- - @granite-js/plugin-core@0.1.5
227
- - @granite-js/utils@0.1.5
228
-
229
- ## 0.1.4
230
-
231
- ### Patch Changes
232
-
233
- - @granite-js/plugin-core@0.1.4
234
- - @granite-js/utils@0.1.4
235
-
236
- ## 0.1.3
237
-
238
- ### Patch Changes
239
-
240
- - @granite-js/plugin-core@0.1.3
241
- - @granite-js/utils@0.1.3
242
-
243
- ## 0.1.2
244
-
245
- ### Patch Changes
246
-
247
- - @granite-js/plugin-core@0.1.2
248
- - @granite-js/utils@0.1.2
249
-
250
- ## 0.1.1
251
-
252
- ### Patch Changes
253
-
254
- - d675415: Improve scaffolding to provide a better showcase UI
255
- - 10a5f3f: empty
256
- - Updated dependencies [d675415]
257
- - Updated dependencies [10a5f3f]
258
- - @granite-js/plugin-core@0.1.1
259
- - @granite-js/utils@0.1.1
260
-
261
- ## 0.1.0
262
-
263
- ### Minor Changes
264
-
265
- - 561a3ed: fix: docs deadlink
266
-
267
- ### Patch Changes
268
-
269
- - Updated dependencies [561a3ed]
270
- - @granite-js/plugin-core@0.1.0
271
- - @granite-js/utils@0.1.0
272
-
273
- ## 0.0.3
274
-
275
- ### Patch Changes
276
-
277
- - ed4d356: changeset
278
- - Updated dependencies [ed4d356]
279
- - @granite-js/plugin-core@0.0.3
280
- - @granite-js/utils@0.0.3
5
+ ### Major Changes
281
6
 
282
- ## 0.0.2
7
+ - 260daab: feat: introduce support react native 0.84
283
8
 
284
9
  ### Patch Changes
285
10
 
286
- - 0ae09b7: deploy guide
287
- - 0ae09b7: type fix
288
- - 0ae09b7: guide
289
- - 0ae09b7: showcase
290
- - 0ae09b7: CanGoBackGuard 수정, typecheck fix, lint fix
291
- - 0ae09b7: counter
292
- - 0ae09b7: - Add plugin context to allow plugins to share data
293
- - Implement Hermes plugin to compile Hermes bytecode and compose source maps
294
- - Updated dependencies [0ae09b7]
295
- - Updated dependencies [0ae09b7]
296
- - Updated dependencies [0ae09b7]
297
- - Updated dependencies [0ae09b7]
298
- - Updated dependencies [0ae09b7]
299
- - Updated dependencies [0ae09b7]
300
- - Updated dependencies [0ae09b7]
301
- - Updated dependencies [0ae09b7]
302
- - Updated dependencies [0ae09b7]
303
- - Updated dependencies [0ae09b7]
304
- - @granite-js/plugin-core@0.0.2
305
- - @granite-js/utils@0.0.2
11
+ - Updated dependencies [260daab]
12
+ - @granite-js/plugin-core@1.0.0
13
+ - @granite-js/utils@1.0.0
package/dist/index.cjs CHANGED
@@ -1,4 +1,5 @@
1
- //#region rolldown:runtime
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ //#region \0rolldown/runtime.js
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -6,12 +7,16 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
6
7
  var __getProtoOf = Object.getPrototypeOf;
7
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
9
  var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
- });
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) {
14
+ __defProp(to, key, {
15
+ get: ((k) => from[k]).bind(null, key),
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ }
15
20
  }
16
21
  return to;
17
22
  };
@@ -21,15 +26,18 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
26
  }) : target, mod));
22
27
 
23
28
  //#endregion
24
- let __granite_js_plugin_core = require("@granite-js/plugin-core");
29
+ let _granite_js_plugin_core = require("@granite-js/plugin-core");
25
30
  let es_toolkit = require("es-toolkit");
26
31
  let execa = require("execa");
27
32
  execa = __toESM(execa);
28
33
  let fs_promises = require("fs/promises");
29
34
  fs_promises = __toESM(fs_promises);
30
35
  let source_map = require("source-map");
31
- let os = require("os");
32
- let __granite_js_utils = require("@granite-js/utils");
36
+ let fs = require("fs");
37
+ fs = __toESM(fs);
38
+ let path = require("path");
39
+ path = __toESM(path);
40
+ let _granite_js_utils = require("@granite-js/utils");
33
41
 
34
42
  //#region src/compileHbc.ts
35
43
  const DEFAULT_OPTIONS = {
@@ -79,17 +87,72 @@ async function composeSourcemap(jsSourcemapPath, hbcSourcemapPath) {
79
87
 
80
88
  //#endregion
81
89
  //#region src/resolveHermesBinaryPath.ts
82
- const BINARY_PATH = {
83
- Darwin: "react-native/sdks/hermesc/osx-bin/hermesc",
84
- Linux: "react-native/sdks/hermesc/linux64-bin/hermesc",
85
- Windows_NT: "react-native/sdks/hermesc/win64-bin/hermesc.exe"
86
- };
90
+ /**
91
+ * Returns the Hermes OS binary folder name for the current platform.
92
+ */
93
+ function getHermesOSBin() {
94
+ switch (process.platform) {
95
+ case "win32": return "win64-bin";
96
+ case "darwin": return "osx-bin";
97
+ default: return "linux64-bin";
98
+ }
99
+ }
100
+ /**
101
+ * Returns the Hermes executable name for the current platform.
102
+ */
103
+ function getHermesOSExe() {
104
+ const hermesExecutableName = "hermesc";
105
+ return process.platform === "win32" ? `${hermesExecutableName}.exe` : hermesExecutableName;
106
+ }
107
+ function getReactNativePackagePath(root) {
108
+ try {
109
+ return path.default.dirname(require.resolve("react-native/package.json", { paths: [root] }));
110
+ } catch {
111
+ return path.default.join("node_modules", "react-native");
112
+ }
113
+ }
114
+ function getHermesCompilerPackagePath(reactNativePath) {
115
+ try {
116
+ return path.default.dirname(require.resolve("hermes-compiler/package.json", { paths: [reactNativePath] }));
117
+ } catch {
118
+ return null;
119
+ }
120
+ }
121
+ function getPackagePathFromRoot(root, pkgName) {
122
+ try {
123
+ return path.default.dirname(require.resolve(`${pkgName}/package.json`, { paths: [root] }));
124
+ } catch {
125
+ return null;
126
+ }
127
+ }
128
+ function fileExists(file) {
129
+ try {
130
+ return fs.default.statSync(file).isFile();
131
+ } catch {
132
+ return false;
133
+ }
134
+ }
87
135
  function resolveHermesBinaryPath() {
88
- const root = (0, __granite_js_utils.getPackageRoot)();
89
- const os$1 = (0, os.type)();
90
- const binaryPath = BINARY_PATH[os$1];
91
- if (binaryPath == null) throw new Error(`Unsupported OS: ${os$1}`);
92
- return require.resolve(binaryPath, { paths: [root] });
136
+ const root = (0, _granite_js_utils.getPackageRoot)();
137
+ const reactNativePath = getReactNativePackagePath(root);
138
+ const hermesCompilerPath = getHermesCompilerPackagePath(reactNativePath);
139
+ if (hermesCompilerPath) {
140
+ const engine = path.default.join(hermesCompilerPath, "hermesc", getHermesOSBin(), getHermesOSExe());
141
+ if (fileExists(engine)) return engine;
142
+ }
143
+ const bundledHermesEngine = path.default.join(reactNativePath, "sdks", "hermesc", getHermesOSBin(), getHermesOSExe());
144
+ if (fileExists(bundledHermesEngine)) return bundledHermesEngine;
145
+ const hermesEnginePkg = getPackagePathFromRoot(root, "hermes-engine");
146
+ if (hermesEnginePkg) {
147
+ const engine = path.default.join(hermesEnginePkg, getHermesOSBin(), getHermesOSExe());
148
+ if (fileExists(engine)) return engine;
149
+ }
150
+ const hermesVmPkg = getPackagePathFromRoot(root, "hermesvm");
151
+ if (hermesVmPkg) {
152
+ const engine = path.default.join(hermesVmPkg, getHermesOSBin(), "hermes");
153
+ if (fileExists(engine)) return engine;
154
+ }
155
+ return path.default.join(reactNativePath, "sdks", "hermesc", getHermesOSBin(), getHermesOSExe());
93
156
  }
94
157
 
95
158
  //#endregion
@@ -102,7 +165,7 @@ const hermesPlugin = (options) => {
102
165
  order: "post",
103
166
  handler: async function(config) {
104
167
  const hermesResult = [];
105
- const files = config.buildResults.filter(__granite_js_plugin_core.isBuildSuccess).map(({ outfile, sourcemapOutfile }) => ({
168
+ const files = config.buildResults.filter(_granite_js_plugin_core.isBuildSuccess).map(({ outfile, sourcemapOutfile }) => ({
106
169
  jsBundle: outfile,
107
170
  jsSourcemap: sourcemapOutfile,
108
171
  hermesBytecode: outfile.replace(/\.js$/, ".hbc")
package/dist/index.js CHANGED
@@ -2,12 +2,13 @@ import { createRequire } from "node:module";
2
2
  import { isBuildSuccess } from "@granite-js/plugin-core";
3
3
  import { isNotNil } from "es-toolkit";
4
4
  import execa from "execa";
5
- import * as fs from "fs/promises";
5
+ import * as fs$1 from "fs/promises";
6
6
  import { SourceMapConsumer, SourceMapGenerator } from "source-map";
7
- import { type } from "os";
7
+ import fs from "fs";
8
+ import path from "path";
8
9
  import { getPackageRoot } from "@granite-js/utils";
9
10
 
10
- //#region rolldown:runtime
11
+ //#region \0rolldown/runtime.js
11
12
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
12
13
 
13
14
  //#endregion
@@ -46,10 +47,10 @@ function getBaseArguments(outfile, jsBundle) {
46
47
  //#region src/composeSourcemap.ts
47
48
  async function writeComposedSourcemap(jsSourcemapPath, hbcSourcemapPath) {
48
49
  const sourcemapContent = await composeSourcemap(jsSourcemapPath, hbcSourcemapPath);
49
- await fs.writeFile(hbcSourcemapPath, sourcemapContent, "utf-8");
50
+ await fs$1.writeFile(hbcSourcemapPath, sourcemapContent, "utf-8");
50
51
  }
51
52
  async function composeSourcemap(jsSourcemapPath, hbcSourcemapPath) {
52
- const [jsSourceMapContent, hbcSourceMapContent] = await Promise.all([fs.readFile(jsSourcemapPath, "utf8"), fs.readFile(hbcSourcemapPath, "utf8")]);
53
+ const [jsSourceMapContent, hbcSourceMapContent] = await Promise.all([fs$1.readFile(jsSourcemapPath, "utf8"), fs$1.readFile(hbcSourcemapPath, "utf8")]);
53
54
  const jsMapConsumer = await new SourceMapConsumer(jsSourceMapContent);
54
55
  const hermesMapConsumer = await new SourceMapConsumer(hbcSourceMapContent);
55
56
  const generator = SourceMapGenerator.fromSourceMap(hermesMapConsumer);
@@ -59,17 +60,72 @@ async function composeSourcemap(jsSourcemapPath, hbcSourcemapPath) {
59
60
 
60
61
  //#endregion
61
62
  //#region src/resolveHermesBinaryPath.ts
62
- const BINARY_PATH = {
63
- Darwin: "react-native/sdks/hermesc/osx-bin/hermesc",
64
- Linux: "react-native/sdks/hermesc/linux64-bin/hermesc",
65
- Windows_NT: "react-native/sdks/hermesc/win64-bin/hermesc.exe"
66
- };
63
+ /**
64
+ * Returns the Hermes OS binary folder name for the current platform.
65
+ */
66
+ function getHermesOSBin() {
67
+ switch (process.platform) {
68
+ case "win32": return "win64-bin";
69
+ case "darwin": return "osx-bin";
70
+ default: return "linux64-bin";
71
+ }
72
+ }
73
+ /**
74
+ * Returns the Hermes executable name for the current platform.
75
+ */
76
+ function getHermesOSExe() {
77
+ const hermesExecutableName = "hermesc";
78
+ return process.platform === "win32" ? `${hermesExecutableName}.exe` : hermesExecutableName;
79
+ }
80
+ function getReactNativePackagePath(root) {
81
+ try {
82
+ return path.dirname(__require.resolve("react-native/package.json", { paths: [root] }));
83
+ } catch {
84
+ return path.join("node_modules", "react-native");
85
+ }
86
+ }
87
+ function getHermesCompilerPackagePath(reactNativePath) {
88
+ try {
89
+ return path.dirname(__require.resolve("hermes-compiler/package.json", { paths: [reactNativePath] }));
90
+ } catch {
91
+ return null;
92
+ }
93
+ }
94
+ function getPackagePathFromRoot(root, pkgName) {
95
+ try {
96
+ return path.dirname(__require.resolve(`${pkgName}/package.json`, { paths: [root] }));
97
+ } catch {
98
+ return null;
99
+ }
100
+ }
101
+ function fileExists(file) {
102
+ try {
103
+ return fs.statSync(file).isFile();
104
+ } catch {
105
+ return false;
106
+ }
107
+ }
67
108
  function resolveHermesBinaryPath() {
68
109
  const root = getPackageRoot();
69
- const os = type();
70
- const binaryPath = BINARY_PATH[os];
71
- if (binaryPath == null) throw new Error(`Unsupported OS: ${os}`);
72
- return __require.resolve(binaryPath, { paths: [root] });
110
+ const reactNativePath = getReactNativePackagePath(root);
111
+ const hermesCompilerPath = getHermesCompilerPackagePath(reactNativePath);
112
+ if (hermesCompilerPath) {
113
+ const engine = path.join(hermesCompilerPath, "hermesc", getHermesOSBin(), getHermesOSExe());
114
+ if (fileExists(engine)) return engine;
115
+ }
116
+ const bundledHermesEngine = path.join(reactNativePath, "sdks", "hermesc", getHermesOSBin(), getHermesOSExe());
117
+ if (fileExists(bundledHermesEngine)) return bundledHermesEngine;
118
+ const hermesEnginePkg = getPackagePathFromRoot(root, "hermes-engine");
119
+ if (hermesEnginePkg) {
120
+ const engine = path.join(hermesEnginePkg, getHermesOSBin(), getHermesOSExe());
121
+ if (fileExists(engine)) return engine;
122
+ }
123
+ const hermesVmPkg = getPackagePathFromRoot(root, "hermesvm");
124
+ if (hermesVmPkg) {
125
+ const engine = path.join(hermesVmPkg, getHermesOSBin(), "hermes");
126
+ if (fileExists(engine)) return engine;
127
+ }
128
+ return path.join(reactNativePath, "sdks", "hermesc", getHermesOSBin(), getHermesOSExe());
73
129
  }
74
130
 
75
131
  //#endregion
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@granite-js/plugin-hermes",
3
3
  "type": "module",
4
- "version": "0.1.33",
4
+ "version": "1.0.0",
5
5
  "description": "Hermes compilation plugin for Granite",
6
6
  "scripts": {
7
7
  "prepack": "yarn build",
@@ -35,13 +35,13 @@
35
35
  ],
36
36
  "devDependencies": {
37
37
  "@vitest/coverage-v8": "^4.0.12",
38
- "tsdown": "^0.16.5",
39
- "typescript": "^5.8.3",
38
+ "tsdown": "0.20.3",
39
+ "typescript": "5.9.3",
40
40
  "vitest": "^4.0.12"
41
41
  },
42
42
  "dependencies": {
43
- "@granite-js/plugin-core": "0.1.33",
44
- "@granite-js/utils": "0.1.33",
43
+ "@granite-js/plugin-core": "1.0.0",
44
+ "@granite-js/utils": "1.0.0",
45
45
  "es-toolkit": "^1.39.8",
46
46
  "execa": "^5",
47
47
  "source-map": "^0.8.0-beta.0"