@granite-js/plugin-hermes 0.1.34 → 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,313 +1,13 @@
1
1
  # @granite-js/plugin-hermes
2
2
 
3
- ## 0.1.34
3
+ ## 1.0.0
4
4
 
5
- ### Patch Changes
6
-
7
- - Updated dependencies [9c39997]
8
- - @granite-js/plugin-core@0.1.34
9
- - @granite-js/utils@0.1.34
10
-
11
- ## 0.1.33
12
-
13
- ### Patch Changes
14
-
15
- - @granite-js/plugin-core@0.1.33
16
- - @granite-js/utils@0.1.33
17
-
18
- ## 0.1.32
19
-
20
- ### Patch Changes
21
-
22
- - 7572713: bump version up babel
23
- - Updated dependencies [7572713]
24
- - @granite-js/plugin-core@0.1.32
25
- - @granite-js/utils@0.1.32
26
-
27
- ## 0.1.31
28
-
29
- ### Patch Changes
30
-
31
- - Updated dependencies [9bf8b50]
32
- - Updated dependencies [e957833]
33
- - @granite-js/plugin-core@0.1.31
34
- - @granite-js/utils@0.1.31
35
-
36
- ## 0.1.30
37
-
38
- ### Patch Changes
39
-
40
- - @granite-js/plugin-core@0.1.30
41
- - @granite-js/utils@0.1.30
42
-
43
- ## 0.1.29
44
-
45
- ### Patch Changes
46
-
47
- - Updated dependencies [ed4cdbf]
48
- - @granite-js/plugin-core@0.1.29
49
- - @granite-js/utils@0.1.29
50
-
51
- ## 0.1.28
52
-
53
- ### Patch Changes
54
-
55
- - 1d958cc: ci: provenance
56
- - Updated dependencies [1d958cc]
57
- - @granite-js/plugin-core@0.1.28
58
- - @granite-js/utils@0.1.28
59
-
60
- ## 0.1.27
61
-
62
- ### Patch Changes
63
-
64
- - e32b020: ci: oidc
65
- - Updated dependencies [e32b020]
66
- - @granite-js/plugin-core@0.1.27
67
- - @granite-js/utils@0.1.27
68
-
69
- ## 0.1.26
70
-
71
- ### Patch Changes
72
-
73
- - @granite-js/plugin-core@0.1.26
74
- - @granite-js/utils@0.1.26
75
-
76
- ## 0.1.25
77
-
78
- ### Patch Changes
79
-
80
- - @granite-js/plugin-core@0.1.25
81
- - @granite-js/utils@0.1.25
82
-
83
- ## 0.1.24
84
-
85
- ### Patch Changes
86
-
87
- - Updated dependencies [6e42c3d]
88
- - @granite-js/plugin-core@0.1.24
89
- - @granite-js/utils@0.1.24
90
-
91
- ## 0.1.23
92
-
93
- ### Patch Changes
94
-
95
- - @granite-js/plugin-core@0.1.23
96
- - @granite-js/utils@0.1.23
97
-
98
- ## 0.1.22
99
-
100
- ### Patch Changes
101
-
102
- - @granite-js/plugin-core@0.1.22
103
- - @granite-js/utils@0.1.22
104
-
105
- ## 0.1.21
106
-
107
- ### Patch Changes
108
-
109
- - @granite-js/plugin-core@0.1.21
110
- - @granite-js/utils@0.1.21
111
-
112
- ## 0.1.20
113
-
114
- ### Patch Changes
115
-
116
- - @granite-js/plugin-core@0.1.20
117
- - @granite-js/utils@0.1.20
118
-
119
- ## 0.1.19
120
-
121
- ### Patch Changes
122
-
123
- - Updated dependencies [e9a3daf]
124
- - @granite-js/plugin-core@0.1.19
125
- - @granite-js/utils@0.1.19
126
-
127
- ## 0.1.18
128
-
129
- ### Patch Changes
130
-
131
- - @granite-js/plugin-core@0.1.18
132
- - @granite-js/utils@0.1.18
133
-
134
- ## 0.1.17
135
-
136
- ### Patch Changes
137
-
138
- - Updated dependencies [9c415df]
139
- - @granite-js/plugin-core@0.1.17
140
- - @granite-js/utils@0.1.17
141
-
142
- ## 0.1.16
143
-
144
- ### Patch Changes
145
-
146
- - c9b4fff: replace .js to .hbc
147
- - 1678419: improve plugin options
148
- - @granite-js/plugin-core@0.1.16
149
- - @granite-js/utils@0.1.16
150
-
151
- ## 0.1.15
152
-
153
- ### Patch Changes
154
-
155
- - d16ee87: Add useInitialProps, useInitialSearchParams hook.
156
- - Updated dependencies [d16ee87]
157
- - @granite-js/plugin-core@0.1.15
158
- - @granite-js/utils@0.1.15
159
-
160
- ## 0.1.14
161
-
162
- ### Patch Changes
163
-
164
- - @granite-js/plugin-core@0.1.14
165
- - @granite-js/utils@0.1.14
166
-
167
- ## 0.1.13
168
-
169
- ### Patch Changes
170
-
171
- - @granite-js/plugin-core@0.1.13
172
- - @granite-js/utils@0.1.13
173
-
174
- ## 0.1.12
175
-
176
- ### Patch Changes
177
-
178
- - d1e6585: fix module resolutions
179
- - Updated dependencies [d1e6585]
180
- - Updated dependencies [1e99fe1]
181
- - @granite-js/plugin-core@0.1.12
182
- - @granite-js/utils@0.1.12
183
-
184
- ## 0.1.11
185
-
186
- ### Patch Changes
187
-
188
- - Updated dependencies [d3a2b58]
189
- - @granite-js/plugin-core@0.1.11
190
- - @granite-js/utils@0.1.11
191
-
192
- ## 0.1.10
193
-
194
- ### Patch Changes
195
-
196
- - Updated dependencies [9438be5]
197
- - @granite-js/plugin-core@0.1.10
198
- - @granite-js/utils@0.1.10
199
-
200
- ## 0.1.9
201
-
202
- ### Patch Changes
203
-
204
- - Updated dependencies [935bb36]
205
- - @granite-js/plugin-core@0.1.9
206
- - @granite-js/utils@0.1.9
207
-
208
- ## 0.1.8
209
-
210
- ### Patch Changes
211
-
212
- - Updated dependencies [b69366c]
213
- - @granite-js/plugin-core@0.1.8
214
- - @granite-js/utils@0.1.8
215
-
216
- ## 0.1.7
217
-
218
- ### Patch Changes
219
-
220
- - @granite-js/plugin-core@0.1.7
221
- - @granite-js/utils@0.1.7
222
-
223
- ## 0.1.6
224
-
225
- ### Patch Changes
226
-
227
- - @granite-js/plugin-core@0.1.6
228
- - @granite-js/utils@0.1.6
229
-
230
- ## 0.1.5
231
-
232
- ### Patch Changes
233
-
234
- - @granite-js/plugin-core@0.1.5
235
- - @granite-js/utils@0.1.5
236
-
237
- ## 0.1.4
238
-
239
- ### Patch Changes
240
-
241
- - @granite-js/plugin-core@0.1.4
242
- - @granite-js/utils@0.1.4
243
-
244
- ## 0.1.3
245
-
246
- ### Patch Changes
247
-
248
- - @granite-js/plugin-core@0.1.3
249
- - @granite-js/utils@0.1.3
250
-
251
- ## 0.1.2
252
-
253
- ### Patch Changes
254
-
255
- - @granite-js/plugin-core@0.1.2
256
- - @granite-js/utils@0.1.2
257
-
258
- ## 0.1.1
259
-
260
- ### Patch Changes
261
-
262
- - d675415: Improve scaffolding to provide a better showcase UI
263
- - 10a5f3f: empty
264
- - Updated dependencies [d675415]
265
- - Updated dependencies [10a5f3f]
266
- - @granite-js/plugin-core@0.1.1
267
- - @granite-js/utils@0.1.1
268
-
269
- ## 0.1.0
270
-
271
- ### Minor Changes
272
-
273
- - 561a3ed: fix: docs deadlink
274
-
275
- ### Patch Changes
276
-
277
- - Updated dependencies [561a3ed]
278
- - @granite-js/plugin-core@0.1.0
279
- - @granite-js/utils@0.1.0
280
-
281
- ## 0.0.3
282
-
283
- ### Patch Changes
284
-
285
- - ed4d356: changeset
286
- - Updated dependencies [ed4d356]
287
- - @granite-js/plugin-core@0.0.3
288
- - @granite-js/utils@0.0.3
5
+ ### Major Changes
289
6
 
290
- ## 0.0.2
7
+ - 260daab: feat: introduce support react native 0.84
291
8
 
292
9
  ### Patch Changes
293
10
 
294
- - 0ae09b7: deploy guide
295
- - 0ae09b7: type fix
296
- - 0ae09b7: guide
297
- - 0ae09b7: showcase
298
- - 0ae09b7: CanGoBackGuard 수정, typecheck fix, lint fix
299
- - 0ae09b7: counter
300
- - 0ae09b7: - Add plugin context to allow plugins to share data
301
- - Implement Hermes plugin to compile Hermes bytecode and compose source maps
302
- - Updated dependencies [0ae09b7]
303
- - Updated dependencies [0ae09b7]
304
- - Updated dependencies [0ae09b7]
305
- - Updated dependencies [0ae09b7]
306
- - Updated dependencies [0ae09b7]
307
- - Updated dependencies [0ae09b7]
308
- - Updated dependencies [0ae09b7]
309
- - Updated dependencies [0ae09b7]
310
- - Updated dependencies [0ae09b7]
311
- - Updated dependencies [0ae09b7]
312
- - @granite-js/plugin-core@0.0.2
313
- - @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.34",
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.34",
44
- "@granite-js/utils": "0.1.34",
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"