@granite-js/plugin-hermes 2.5.5 → 3.0.1
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 +35 -0
- package/README.md +17 -14
- package/dist/index.cjs +52 -184
- package/dist/index.d.cts +14 -35
- package/dist/index.d.ts +14 -35
- package/dist/index.js +51 -158
- package/dist/mpack.cjs +41 -0
- package/dist/mpack.d.cts +7 -0
- package/dist/mpack.d.ts +7 -0
- package/dist/mpack.js +40 -0
- package/dist/resolveHermesBinaryPath-DwwS_er8.js +130 -0
- package/dist/resolveHermesBinaryPath-jlhzRycN.cjs +179 -0
- package/dist/types-BUiW2XaD.d.ts +33 -0
- package/dist/types-C06HqDVE.d.cts +33 -0
- package/package.json +23 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @granite-js/plugin-hermes
|
|
2
2
|
|
|
3
|
+
## 3.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @granite-js/plugin-core@3.0.1
|
|
8
|
+
- @granite-js/utils@3.0.1
|
|
9
|
+
|
|
10
|
+
## 3.0.0
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- @granite-js/plugin-core@3.0.0
|
|
15
|
+
- @granite-js/utils@3.0.0
|
|
16
|
+
|
|
3
17
|
## 2.5.5
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -112,6 +126,27 @@
|
|
|
112
126
|
- @granite-js/plugin-core@2.0.0
|
|
113
127
|
- @granite-js/utils@2.0.0
|
|
114
128
|
|
|
129
|
+
## 1.0.45
|
|
130
|
+
|
|
131
|
+
### Patch Changes
|
|
132
|
+
|
|
133
|
+
- @granite-js/plugin-core@1.0.45
|
|
134
|
+
- @granite-js/utils@1.0.45
|
|
135
|
+
|
|
136
|
+
## 1.0.44
|
|
137
|
+
|
|
138
|
+
### Patch Changes
|
|
139
|
+
|
|
140
|
+
- @granite-js/plugin-core@1.0.44
|
|
141
|
+
- @granite-js/utils@1.0.44
|
|
142
|
+
|
|
143
|
+
## 1.0.43
|
|
144
|
+
|
|
145
|
+
### Patch Changes
|
|
146
|
+
|
|
147
|
+
- @granite-js/plugin-core@1.0.43
|
|
148
|
+
- @granite-js/utils@1.0.43
|
|
149
|
+
|
|
115
150
|
## 1.0.42
|
|
116
151
|
|
|
117
152
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -15,12 +15,27 @@ pnpm install @granite-js/plugin-hermes
|
|
|
15
15
|
yarn add @granite-js/plugin-hermes
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
##
|
|
18
|
+
## Rollipop
|
|
19
19
|
|
|
20
20
|
```ts
|
|
21
|
-
import { defineConfig } from '@granite-js/react-native/config';
|
|
22
21
|
import { hermes } from '@granite-js/plugin-hermes';
|
|
23
22
|
|
|
23
|
+
const plugins = [
|
|
24
|
+
hermes({
|
|
25
|
+
onBuild(result) {
|
|
26
|
+
console.log(`Hermes bytecode path: ${result.hbc}`);
|
|
27
|
+
console.log(`Hermes sourcemap path: ${result.hbcSourcemap ?? 'N/A'}`);
|
|
28
|
+
},
|
|
29
|
+
}),
|
|
30
|
+
];
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Mpack (deprecated)
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { defineConfig } from '@granite-js/mpack/config';
|
|
37
|
+
import { hermes } from '@granite-js/plugin-hermes/mpack';
|
|
38
|
+
|
|
24
39
|
export default defineConfig({
|
|
25
40
|
plugins: [
|
|
26
41
|
hermes({
|
|
@@ -51,18 +66,6 @@ export default defineConfig({
|
|
|
51
66
|
});
|
|
52
67
|
```
|
|
53
68
|
|
|
54
|
-
```ts
|
|
55
|
-
// In other plugin handlers
|
|
56
|
-
function handler() {
|
|
57
|
-
const hermesPluginResults = this.meta.hermes ?? [];
|
|
58
|
-
|
|
59
|
-
for (const hermesPluginResult of hermesPluginResults) {
|
|
60
|
-
console.log(`Hermes bytecode path: ${hermesPluginResult.hbc}`);
|
|
61
|
-
console.log(`Hermes sourcemap path: ${hermesPluginResult.hbcSourcemap ?? 'N/A'}`);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
```
|
|
65
|
-
|
|
66
69
|
## License
|
|
67
70
|
|
|
68
71
|
This software is licensed under the [Apache 2 license](LICENSE), quoted below.
|
package/dist/index.cjs
CHANGED
|
@@ -1,195 +1,63 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
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
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return to;
|
|
22
|
-
};
|
|
23
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
24
|
-
value: mod,
|
|
25
|
-
enumerable: true
|
|
26
|
-
}) : target, mod));
|
|
27
|
-
|
|
28
|
-
//#endregion
|
|
29
|
-
let _granite_js_plugin_core = require("@granite-js/plugin-core");
|
|
30
|
-
let es_toolkit = require("es-toolkit");
|
|
31
|
-
let execa = require("execa");
|
|
32
|
-
execa = __toESM(execa);
|
|
33
|
-
let fs_promises = require("fs/promises");
|
|
34
|
-
fs_promises = __toESM(fs_promises);
|
|
35
|
-
let source_map = require("source-map");
|
|
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");
|
|
2
|
+
const require_resolveHermesBinaryPath = require('./resolveHermesBinaryPath-jlhzRycN.cjs');
|
|
3
|
+
let node_path = require("node:path");
|
|
4
|
+
node_path = require_resolveHermesBinaryPath.__toESM(node_path);
|
|
41
5
|
|
|
42
|
-
//#region src/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const completeOptions = {
|
|
50
|
-
...DEFAULT_OPTIONS,
|
|
51
|
-
...options
|
|
52
|
-
};
|
|
53
|
-
await (0, execa.default)(hermesc, [
|
|
54
|
-
`-${completeOptions.optimization}`,
|
|
55
|
-
completeOptions.disableWarning ? "-w" : null,
|
|
56
|
-
completeOptions.sourcemap ? "-output-source-map" : null,
|
|
57
|
-
...getBaseArguments(outfile, jsBundle)
|
|
58
|
-
].filter(es_toolkit.isNotNil));
|
|
6
|
+
//#region src/next/index.ts
|
|
7
|
+
function hermes(options = {}) {
|
|
8
|
+
const contextByOutput = /* @__PURE__ */ new Map();
|
|
9
|
+
const state = { root: process.cwd() };
|
|
10
|
+
return [hermesConfig(state, contextByOutput), hermesCompiler(options, state, contextByOutput)];
|
|
11
|
+
}
|
|
12
|
+
function hermesConfig(state, contextByOutput) {
|
|
59
13
|
return {
|
|
60
|
-
|
|
61
|
-
|
|
14
|
+
name: "granite:hermes:config",
|
|
15
|
+
config(config) {
|
|
16
|
+
state.root = config.root ?? process.cwd();
|
|
17
|
+
return {
|
|
18
|
+
output: { minify: false },
|
|
19
|
+
rolldownOptions(options, { dev, platform }) {
|
|
20
|
+
if (options.output?.file) contextByOutput.set(node_path.resolve(state.root, options.output.file), {
|
|
21
|
+
dev,
|
|
22
|
+
platform
|
|
23
|
+
});
|
|
24
|
+
return options;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
62
28
|
};
|
|
63
29
|
}
|
|
64
|
-
function
|
|
65
|
-
return [
|
|
66
|
-
"-emit-binary",
|
|
67
|
-
"-out",
|
|
68
|
-
outfile,
|
|
69
|
-
jsBundle
|
|
70
|
-
];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
//#endregion
|
|
74
|
-
//#region src/composeSourcemap.ts
|
|
75
|
-
async function writeComposedSourcemap(jsSourcemapPath, hbcSourcemapPath) {
|
|
76
|
-
const sourcemapContent = await composeSourcemap(jsSourcemapPath, hbcSourcemapPath);
|
|
77
|
-
await fs_promises.writeFile(hbcSourcemapPath, sourcemapContent, "utf-8");
|
|
78
|
-
}
|
|
79
|
-
async function composeSourcemap(jsSourcemapPath, hbcSourcemapPath) {
|
|
80
|
-
const [jsSourceMapContent, hbcSourceMapContent] = await Promise.all([fs_promises.readFile(jsSourcemapPath, "utf8"), fs_promises.readFile(hbcSourcemapPath, "utf8")]);
|
|
81
|
-
const jsMapConsumer = await new source_map.SourceMapConsumer(jsSourceMapContent);
|
|
82
|
-
const hermesMapConsumer = await new source_map.SourceMapConsumer(hbcSourceMapContent);
|
|
83
|
-
const generator = source_map.SourceMapGenerator.fromSourceMap(hermesMapConsumer);
|
|
84
|
-
generator.applySourceMap(jsMapConsumer, hermesMapConsumer.sources[0]);
|
|
85
|
-
return generator.toString();
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
//#endregion
|
|
89
|
-
//#region src/resolveHermesBinaryPath.ts
|
|
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
|
-
}
|
|
135
|
-
function resolveHermesBinaryPath() {
|
|
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());
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
//#endregion
|
|
159
|
-
//#region src/hermesPlugin.ts
|
|
160
|
-
const hermesPlugin = (options) => {
|
|
161
|
-
const hermesc = options?.binaryPath ?? resolveHermesBinaryPath();
|
|
30
|
+
function hermesCompiler({ onBuild, binaryPath, ...compilerOptions }, state, contextByOutput) {
|
|
162
31
|
return {
|
|
163
|
-
name: "hermes
|
|
164
|
-
|
|
165
|
-
order: "
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
32
|
+
name: "granite:hermes:compile",
|
|
33
|
+
writeBundle: {
|
|
34
|
+
order: "pre",
|
|
35
|
+
sequential: true,
|
|
36
|
+
async handler(output) {
|
|
37
|
+
if (!output.file) throw new Error("Hermes compilation requires an output file.");
|
|
38
|
+
const outfile = node_path.resolve(state.root, output.file);
|
|
39
|
+
const context = contextByOutput.get(outfile);
|
|
40
|
+
if (context == null) throw new Error(`Hermes build context is missing for ${outfile}.`);
|
|
41
|
+
if (context.dev) return;
|
|
42
|
+
const sourcemapOutfile = `${outfile}.map`;
|
|
43
|
+
const hbcFile = `${outfile.slice(0, outfile.length - node_path.extname(outfile).length)}.hbc`;
|
|
44
|
+
const result = await require_resolveHermesBinaryPath.compileHbc({
|
|
45
|
+
...compilerOptions,
|
|
46
|
+
hermesc: binaryPath ?? require_resolveHermesBinaryPath.resolveHermesBinaryPath(state.root),
|
|
169
47
|
jsBundle: outfile,
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
...options
|
|
180
|
-
});
|
|
181
|
-
if (hbcSourcemap != null) await writeComposedSourcemap(jsSourcemap, hbcSourcemap);
|
|
182
|
-
hermesResult.push({
|
|
183
|
-
hbc,
|
|
184
|
-
hbcSourcemap
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
this.meta.hermes = hermesResult;
|
|
48
|
+
outfile: hbcFile
|
|
49
|
+
});
|
|
50
|
+
if (result.hbcSourcemap) await require_resolveHermesBinaryPath.writeComposedSourcemap(sourcemapOutfile, result.hbcSourcemap);
|
|
51
|
+
await onBuild?.({
|
|
52
|
+
platform: context.platform,
|
|
53
|
+
outfile,
|
|
54
|
+
sourcemapOutfile,
|
|
55
|
+
...result
|
|
56
|
+
});
|
|
188
57
|
}
|
|
189
|
-
}
|
|
190
|
-
config: { esbuild: { minify: false } }
|
|
58
|
+
}
|
|
191
59
|
};
|
|
192
|
-
}
|
|
60
|
+
}
|
|
193
61
|
|
|
194
62
|
//#endregion
|
|
195
|
-
exports.hermes =
|
|
63
|
+
exports.hermes = hermes;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,38 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as HermesPluginOptions$1 } from "./types-C06HqDVE.cjs";
|
|
2
|
+
import { PluginOption } from "rollipop";
|
|
2
3
|
|
|
3
|
-
//#region src/
|
|
4
|
-
interface
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* - `O`: Expensive optimizations
|
|
11
|
-
*
|
|
12
|
-
* Defaults to `O`.
|
|
13
|
-
*/
|
|
14
|
-
optimization?: 'O0' | 'Og' | 'O';
|
|
15
|
-
/**
|
|
16
|
-
* Disable warning message.
|
|
17
|
-
*
|
|
18
|
-
* Defaults to `true`.
|
|
19
|
-
*/
|
|
20
|
-
disableWarning?: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Emit source map.
|
|
23
|
-
*
|
|
24
|
-
* Defaults to `true`.
|
|
25
|
-
*/
|
|
26
|
-
sourcemap?: boolean;
|
|
27
|
-
/**
|
|
28
|
-
* Path to hermesc binary.
|
|
29
|
-
*
|
|
30
|
-
* Defaults to `hermesc` in `react-native/sdks/hermesc/<platform>/hermesc`.
|
|
31
|
-
*/
|
|
32
|
-
binaryPath?: string;
|
|
4
|
+
//#region src/next/index.d.ts
|
|
5
|
+
interface HermesBuildResult {
|
|
6
|
+
platform: string;
|
|
7
|
+
outfile: string;
|
|
8
|
+
sourcemapOutfile: string;
|
|
9
|
+
hbc: string;
|
|
10
|
+
hbcSourcemap: string | null;
|
|
33
11
|
}
|
|
12
|
+
interface HermesPluginOptions extends HermesPluginOptions$1 {
|
|
13
|
+
onBuild?: (result: HermesBuildResult) => void | Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
declare function hermes(options?: HermesPluginOptions): PluginOption;
|
|
34
16
|
//#endregion
|
|
35
|
-
|
|
36
|
-
declare const hermesPlugin: (options?: HermesPluginOptions) => GranitePluginCore;
|
|
37
|
-
//#endregion
|
|
38
|
-
export { hermesPlugin as hermes };
|
|
17
|
+
export { HermesBuildResult, HermesPluginOptions, hermes };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,38 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as HermesPluginOptions$1 } from "./types-BUiW2XaD.js";
|
|
2
|
+
import { PluginOption } from "rollipop";
|
|
2
3
|
|
|
3
|
-
//#region src/
|
|
4
|
-
interface
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* - `O`: Expensive optimizations
|
|
11
|
-
*
|
|
12
|
-
* Defaults to `O`.
|
|
13
|
-
*/
|
|
14
|
-
optimization?: 'O0' | 'Og' | 'O';
|
|
15
|
-
/**
|
|
16
|
-
* Disable warning message.
|
|
17
|
-
*
|
|
18
|
-
* Defaults to `true`.
|
|
19
|
-
*/
|
|
20
|
-
disableWarning?: boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Emit source map.
|
|
23
|
-
*
|
|
24
|
-
* Defaults to `true`.
|
|
25
|
-
*/
|
|
26
|
-
sourcemap?: boolean;
|
|
27
|
-
/**
|
|
28
|
-
* Path to hermesc binary.
|
|
29
|
-
*
|
|
30
|
-
* Defaults to `hermesc` in `react-native/sdks/hermesc/<platform>/hermesc`.
|
|
31
|
-
*/
|
|
32
|
-
binaryPath?: string;
|
|
4
|
+
//#region src/next/index.d.ts
|
|
5
|
+
interface HermesBuildResult {
|
|
6
|
+
platform: string;
|
|
7
|
+
outfile: string;
|
|
8
|
+
sourcemapOutfile: string;
|
|
9
|
+
hbc: string;
|
|
10
|
+
hbcSourcemap: string | null;
|
|
33
11
|
}
|
|
12
|
+
interface HermesPluginOptions extends HermesPluginOptions$1 {
|
|
13
|
+
onBuild?: (result: HermesBuildResult) => void | Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
declare function hermes(options?: HermesPluginOptions): PluginOption;
|
|
34
16
|
//#endregion
|
|
35
|
-
|
|
36
|
-
declare const hermesPlugin: (options?: HermesPluginOptions) => GranitePluginCore;
|
|
37
|
-
//#endregion
|
|
38
|
-
export { hermesPlugin as hermes };
|
|
17
|
+
export { HermesBuildResult, HermesPluginOptions, hermes };
|
package/dist/index.js
CHANGED
|
@@ -1,168 +1,61 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { isNotNil } from "es-toolkit";
|
|
4
|
-
import execa from "execa";
|
|
5
|
-
import * as fs$1 from "fs/promises";
|
|
6
|
-
import { SourceMapConsumer, SourceMapGenerator } from "source-map";
|
|
7
|
-
import fs from "fs";
|
|
8
|
-
import path from "path";
|
|
9
|
-
import { getPackageRoot } from "@granite-js/utils";
|
|
1
|
+
import { n as writeComposedSourcemap, r as compileHbc, t as resolveHermesBinaryPath } from "./resolveHermesBinaryPath-DwwS_er8.js";
|
|
2
|
+
import * as path from "node:path";
|
|
10
3
|
|
|
11
|
-
//#region
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
optimization: "O",
|
|
19
|
-
sourcemap: true
|
|
20
|
-
};
|
|
21
|
-
async function compileHbc({ hermesc, jsBundle, outfile, ...options }) {
|
|
22
|
-
const completeOptions = {
|
|
23
|
-
...DEFAULT_OPTIONS,
|
|
24
|
-
...options
|
|
25
|
-
};
|
|
26
|
-
await execa(hermesc, [
|
|
27
|
-
`-${completeOptions.optimization}`,
|
|
28
|
-
completeOptions.disableWarning ? "-w" : null,
|
|
29
|
-
completeOptions.sourcemap ? "-output-source-map" : null,
|
|
30
|
-
...getBaseArguments(outfile, jsBundle)
|
|
31
|
-
].filter(isNotNil));
|
|
4
|
+
//#region src/next/index.ts
|
|
5
|
+
function hermes(options = {}) {
|
|
6
|
+
const contextByOutput = /* @__PURE__ */ new Map();
|
|
7
|
+
const state = { root: process.cwd() };
|
|
8
|
+
return [hermesConfig(state, contextByOutput), hermesCompiler(options, state, contextByOutput)];
|
|
9
|
+
}
|
|
10
|
+
function hermesConfig(state, contextByOutput) {
|
|
32
11
|
return {
|
|
33
|
-
|
|
34
|
-
|
|
12
|
+
name: "granite:hermes:config",
|
|
13
|
+
config(config) {
|
|
14
|
+
state.root = config.root ?? process.cwd();
|
|
15
|
+
return {
|
|
16
|
+
output: { minify: false },
|
|
17
|
+
rolldownOptions(options, { dev, platform }) {
|
|
18
|
+
if (options.output?.file) contextByOutput.set(path.resolve(state.root, options.output.file), {
|
|
19
|
+
dev,
|
|
20
|
+
platform
|
|
21
|
+
});
|
|
22
|
+
return options;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
35
26
|
};
|
|
36
27
|
}
|
|
37
|
-
function
|
|
38
|
-
return [
|
|
39
|
-
"-emit-binary",
|
|
40
|
-
"-out",
|
|
41
|
-
outfile,
|
|
42
|
-
jsBundle
|
|
43
|
-
];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
//#endregion
|
|
47
|
-
//#region src/composeSourcemap.ts
|
|
48
|
-
async function writeComposedSourcemap(jsSourcemapPath, hbcSourcemapPath) {
|
|
49
|
-
const sourcemapContent = await composeSourcemap(jsSourcemapPath, hbcSourcemapPath);
|
|
50
|
-
await fs$1.writeFile(hbcSourcemapPath, sourcemapContent, "utf-8");
|
|
51
|
-
}
|
|
52
|
-
async function composeSourcemap(jsSourcemapPath, hbcSourcemapPath) {
|
|
53
|
-
const [jsSourceMapContent, hbcSourceMapContent] = await Promise.all([fs$1.readFile(jsSourcemapPath, "utf8"), fs$1.readFile(hbcSourcemapPath, "utf8")]);
|
|
54
|
-
const jsMapConsumer = await new SourceMapConsumer(jsSourceMapContent);
|
|
55
|
-
const hermesMapConsumer = await new SourceMapConsumer(hbcSourceMapContent);
|
|
56
|
-
const generator = SourceMapGenerator.fromSourceMap(hermesMapConsumer);
|
|
57
|
-
generator.applySourceMap(jsMapConsumer, hermesMapConsumer.sources[0]);
|
|
58
|
-
return generator.toString();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
//#endregion
|
|
62
|
-
//#region src/resolveHermesBinaryPath.ts
|
|
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
|
-
}
|
|
108
|
-
function resolveHermesBinaryPath() {
|
|
109
|
-
const root = getPackageRoot();
|
|
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());
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
//#endregion
|
|
132
|
-
//#region src/hermesPlugin.ts
|
|
133
|
-
const hermesPlugin = (options) => {
|
|
134
|
-
const hermesc = options?.binaryPath ?? resolveHermesBinaryPath();
|
|
28
|
+
function hermesCompiler({ onBuild, binaryPath, ...compilerOptions }, state, contextByOutput) {
|
|
135
29
|
return {
|
|
136
|
-
name: "hermes
|
|
137
|
-
|
|
138
|
-
order: "
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
30
|
+
name: "granite:hermes:compile",
|
|
31
|
+
writeBundle: {
|
|
32
|
+
order: "pre",
|
|
33
|
+
sequential: true,
|
|
34
|
+
async handler(output) {
|
|
35
|
+
if (!output.file) throw new Error("Hermes compilation requires an output file.");
|
|
36
|
+
const outfile = path.resolve(state.root, output.file);
|
|
37
|
+
const context = contextByOutput.get(outfile);
|
|
38
|
+
if (context == null) throw new Error(`Hermes build context is missing for ${outfile}.`);
|
|
39
|
+
if (context.dev) return;
|
|
40
|
+
const sourcemapOutfile = `${outfile}.map`;
|
|
41
|
+
const hbcFile = `${outfile.slice(0, outfile.length - path.extname(outfile).length)}.hbc`;
|
|
42
|
+
const result = await compileHbc({
|
|
43
|
+
...compilerOptions,
|
|
44
|
+
hermesc: binaryPath ?? resolveHermesBinaryPath(state.root),
|
|
142
45
|
jsBundle: outfile,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
...options
|
|
153
|
-
});
|
|
154
|
-
if (hbcSourcemap != null) await writeComposedSourcemap(jsSourcemap, hbcSourcemap);
|
|
155
|
-
hermesResult.push({
|
|
156
|
-
hbc,
|
|
157
|
-
hbcSourcemap
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
this.meta.hermes = hermesResult;
|
|
46
|
+
outfile: hbcFile
|
|
47
|
+
});
|
|
48
|
+
if (result.hbcSourcemap) await writeComposedSourcemap(sourcemapOutfile, result.hbcSourcemap);
|
|
49
|
+
await onBuild?.({
|
|
50
|
+
platform: context.platform,
|
|
51
|
+
outfile,
|
|
52
|
+
sourcemapOutfile,
|
|
53
|
+
...result
|
|
54
|
+
});
|
|
161
55
|
}
|
|
162
|
-
}
|
|
163
|
-
config: { esbuild: { minify: false } }
|
|
56
|
+
}
|
|
164
57
|
};
|
|
165
|
-
}
|
|
58
|
+
}
|
|
166
59
|
|
|
167
60
|
//#endregion
|
|
168
|
-
export {
|
|
61
|
+
export { hermes };
|
package/dist/mpack.cjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_resolveHermesBinaryPath = require('./resolveHermesBinaryPath-jlhzRycN.cjs');
|
|
3
|
+
let _granite_js_plugin_core = require("@granite-js/plugin-core");
|
|
4
|
+
|
|
5
|
+
//#region src/hermesPlugin.ts
|
|
6
|
+
const hermesPlugin = (options) => {
|
|
7
|
+
const hermesc = options?.binaryPath ?? require_resolveHermesBinaryPath.resolveHermesBinaryPath();
|
|
8
|
+
return {
|
|
9
|
+
name: "hermes-plugin",
|
|
10
|
+
build: {
|
|
11
|
+
order: "post",
|
|
12
|
+
handler: async function(config) {
|
|
13
|
+
const hermesResult = [];
|
|
14
|
+
const files = config.buildResults.filter(_granite_js_plugin_core.isBuildSuccess).map(({ outfile, sourcemapOutfile }) => ({
|
|
15
|
+
jsBundle: outfile,
|
|
16
|
+
jsSourcemap: sourcemapOutfile,
|
|
17
|
+
hermesBytecode: outfile.replace(/\.js$/, ".hbc")
|
|
18
|
+
}));
|
|
19
|
+
for (const file of files) {
|
|
20
|
+
const { jsBundle, jsSourcemap, hermesBytecode } = file;
|
|
21
|
+
const { hbc, hbcSourcemap } = await require_resolveHermesBinaryPath.compileHbc({
|
|
22
|
+
hermesc,
|
|
23
|
+
jsBundle,
|
|
24
|
+
outfile: hermesBytecode,
|
|
25
|
+
...options
|
|
26
|
+
});
|
|
27
|
+
if (hbcSourcemap != null) await require_resolveHermesBinaryPath.writeComposedSourcemap(jsSourcemap, hbcSourcemap);
|
|
28
|
+
hermesResult.push({
|
|
29
|
+
hbc,
|
|
30
|
+
hbcSourcemap
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
this.meta.hermes = hermesResult;
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
config: { esbuild: { minify: false } }
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
exports.hermes = hermesPlugin;
|
package/dist/mpack.d.cts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { t as HermesPluginOptions } from "./types-C06HqDVE.cjs";
|
|
2
|
+
import { GranitePluginCore } from "@granite-js/plugin-core";
|
|
3
|
+
|
|
4
|
+
//#region src/hermesPlugin.d.ts
|
|
5
|
+
declare const hermesPlugin: (options?: HermesPluginOptions) => GranitePluginCore;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { hermesPlugin as hermes };
|
package/dist/mpack.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { t as HermesPluginOptions } from "./types-BUiW2XaD.js";
|
|
2
|
+
import { GranitePluginCore } from "@granite-js/plugin-core";
|
|
3
|
+
|
|
4
|
+
//#region src/hermesPlugin.d.ts
|
|
5
|
+
declare const hermesPlugin: (options?: HermesPluginOptions) => GranitePluginCore;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { hermesPlugin as hermes };
|
package/dist/mpack.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { n as writeComposedSourcemap, r as compileHbc, t as resolveHermesBinaryPath } from "./resolveHermesBinaryPath-DwwS_er8.js";
|
|
2
|
+
import { isBuildSuccess } from "@granite-js/plugin-core";
|
|
3
|
+
|
|
4
|
+
//#region src/hermesPlugin.ts
|
|
5
|
+
const hermesPlugin = (options) => {
|
|
6
|
+
const hermesc = options?.binaryPath ?? resolveHermesBinaryPath();
|
|
7
|
+
return {
|
|
8
|
+
name: "hermes-plugin",
|
|
9
|
+
build: {
|
|
10
|
+
order: "post",
|
|
11
|
+
handler: async function(config) {
|
|
12
|
+
const hermesResult = [];
|
|
13
|
+
const files = config.buildResults.filter(isBuildSuccess).map(({ outfile, sourcemapOutfile }) => ({
|
|
14
|
+
jsBundle: outfile,
|
|
15
|
+
jsSourcemap: sourcemapOutfile,
|
|
16
|
+
hermesBytecode: outfile.replace(/\.js$/, ".hbc")
|
|
17
|
+
}));
|
|
18
|
+
for (const file of files) {
|
|
19
|
+
const { jsBundle, jsSourcemap, hermesBytecode } = file;
|
|
20
|
+
const { hbc, hbcSourcemap } = await compileHbc({
|
|
21
|
+
hermesc,
|
|
22
|
+
jsBundle,
|
|
23
|
+
outfile: hermesBytecode,
|
|
24
|
+
...options
|
|
25
|
+
});
|
|
26
|
+
if (hbcSourcemap != null) await writeComposedSourcemap(jsSourcemap, hbcSourcemap);
|
|
27
|
+
hermesResult.push({
|
|
28
|
+
hbc,
|
|
29
|
+
hbcSourcemap
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
this.meta.hermes = hermesResult;
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
config: { esbuild: { minify: false } }
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
export { hermesPlugin as hermes };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { isNotNil } from "es-toolkit";
|
|
4
|
+
import execa from "execa";
|
|
5
|
+
import * as fs$1 from "fs/promises";
|
|
6
|
+
import { SourceMapConsumer, SourceMapGenerator } from "source-map";
|
|
7
|
+
import * as fs from "node:fs";
|
|
8
|
+
import { getPackageRoot } from "@granite-js/utils";
|
|
9
|
+
|
|
10
|
+
//#region \0rolldown/runtime.js
|
|
11
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/shared/compileHbc.ts
|
|
15
|
+
const DEFAULT_OPTIONS = {
|
|
16
|
+
disableWarning: true,
|
|
17
|
+
optimization: "O",
|
|
18
|
+
sourcemap: true
|
|
19
|
+
};
|
|
20
|
+
async function compileHbc({ hermesc, jsBundle, outfile, ...options }) {
|
|
21
|
+
const completeOptions = {
|
|
22
|
+
...DEFAULT_OPTIONS,
|
|
23
|
+
...options
|
|
24
|
+
};
|
|
25
|
+
await execa(hermesc, [
|
|
26
|
+
`-${completeOptions.optimization}`,
|
|
27
|
+
completeOptions.disableWarning ? "-w" : null,
|
|
28
|
+
completeOptions.sourcemap ? "-output-source-map" : null,
|
|
29
|
+
...getBaseArguments(outfile, jsBundle)
|
|
30
|
+
].filter(isNotNil));
|
|
31
|
+
return {
|
|
32
|
+
hbc: outfile,
|
|
33
|
+
hbcSourcemap: completeOptions.sourcemap ? `${outfile}.map` : null
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function getBaseArguments(outfile, jsBundle) {
|
|
37
|
+
return [
|
|
38
|
+
"-emit-binary",
|
|
39
|
+
"-out",
|
|
40
|
+
outfile,
|
|
41
|
+
jsBundle
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/shared/composeSourcemap.ts
|
|
47
|
+
async function writeComposedSourcemap(jsSourcemapPath, hbcSourcemapPath) {
|
|
48
|
+
const sourcemapContent = await composeSourcemap(jsSourcemapPath, hbcSourcemapPath);
|
|
49
|
+
await fs$1.writeFile(hbcSourcemapPath, sourcemapContent, "utf-8");
|
|
50
|
+
}
|
|
51
|
+
async function composeSourcemap(jsSourcemapPath, hbcSourcemapPath) {
|
|
52
|
+
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();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/shared/resolveHermesBinaryPath.ts
|
|
62
|
+
/**
|
|
63
|
+
* Returns the Hermes OS binary folder name for the current platform.
|
|
64
|
+
*/
|
|
65
|
+
function getHermesOSBin() {
|
|
66
|
+
switch (process.platform) {
|
|
67
|
+
case "win32": return "win64-bin";
|
|
68
|
+
case "darwin": return "osx-bin";
|
|
69
|
+
default: return "linux64-bin";
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Returns the Hermes executable name for the current platform.
|
|
74
|
+
*/
|
|
75
|
+
function getHermesOSExe() {
|
|
76
|
+
const hermesExecutableName = "hermesc";
|
|
77
|
+
return process.platform === "win32" ? `${hermesExecutableName}.exe` : hermesExecutableName;
|
|
78
|
+
}
|
|
79
|
+
function getReactNativePackagePath(root) {
|
|
80
|
+
try {
|
|
81
|
+
return path.dirname(__require.resolve("react-native/package.json", { paths: [root] }));
|
|
82
|
+
} catch {
|
|
83
|
+
return path.join("node_modules", "react-native");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function getHermesCompilerPackagePath(reactNativePath) {
|
|
87
|
+
try {
|
|
88
|
+
return path.dirname(__require.resolve("hermes-compiler/package.json", { paths: [reactNativePath] }));
|
|
89
|
+
} catch {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function getPackagePathFromRoot(root, pkgName) {
|
|
94
|
+
try {
|
|
95
|
+
return path.dirname(__require.resolve(`${pkgName}/package.json`, { paths: [root] }));
|
|
96
|
+
} catch {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function fileExists(file) {
|
|
101
|
+
try {
|
|
102
|
+
return fs.statSync(file).isFile();
|
|
103
|
+
} catch {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function resolveHermesBinaryPath(root = getPackageRoot()) {
|
|
108
|
+
const reactNativePath = getReactNativePackagePath(root);
|
|
109
|
+
const hermesCompilerPath = getHermesCompilerPackagePath(reactNativePath);
|
|
110
|
+
if (hermesCompilerPath) {
|
|
111
|
+
const engine = path.join(hermesCompilerPath, "hermesc", getHermesOSBin(), getHermesOSExe());
|
|
112
|
+
if (fileExists(engine)) return engine;
|
|
113
|
+
}
|
|
114
|
+
const bundledHermesEngine = path.join(reactNativePath, "sdks", "hermesc", getHermesOSBin(), getHermesOSExe());
|
|
115
|
+
if (fileExists(bundledHermesEngine)) return bundledHermesEngine;
|
|
116
|
+
const hermesEnginePkg = getPackagePathFromRoot(root, "hermes-engine");
|
|
117
|
+
if (hermesEnginePkg) {
|
|
118
|
+
const engine = path.join(hermesEnginePkg, getHermesOSBin(), getHermesOSExe());
|
|
119
|
+
if (fileExists(engine)) return engine;
|
|
120
|
+
}
|
|
121
|
+
const hermesVmPkg = getPackagePathFromRoot(root, "hermesvm");
|
|
122
|
+
if (hermesVmPkg) {
|
|
123
|
+
const engine = path.join(hermesVmPkg, getHermesOSBin(), "hermes");
|
|
124
|
+
if (fileExists(engine)) return engine;
|
|
125
|
+
}
|
|
126
|
+
return path.join(reactNativePath, "sdks", "hermesc", getHermesOSBin(), getHermesOSExe());
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
//#endregion
|
|
130
|
+
export { writeComposedSourcemap as n, compileHbc as r, resolveHermesBinaryPath as t };
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
let node_path = require("node:path");
|
|
29
|
+
node_path = __toESM(node_path);
|
|
30
|
+
let es_toolkit = require("es-toolkit");
|
|
31
|
+
let execa = require("execa");
|
|
32
|
+
execa = __toESM(execa);
|
|
33
|
+
let fs_promises = require("fs/promises");
|
|
34
|
+
fs_promises = __toESM(fs_promises);
|
|
35
|
+
let source_map = require("source-map");
|
|
36
|
+
let node_fs = require("node:fs");
|
|
37
|
+
node_fs = __toESM(node_fs);
|
|
38
|
+
let _granite_js_utils = require("@granite-js/utils");
|
|
39
|
+
|
|
40
|
+
//#region src/shared/compileHbc.ts
|
|
41
|
+
const DEFAULT_OPTIONS = {
|
|
42
|
+
disableWarning: true,
|
|
43
|
+
optimization: "O",
|
|
44
|
+
sourcemap: true
|
|
45
|
+
};
|
|
46
|
+
async function compileHbc({ hermesc, jsBundle, outfile, ...options }) {
|
|
47
|
+
const completeOptions = {
|
|
48
|
+
...DEFAULT_OPTIONS,
|
|
49
|
+
...options
|
|
50
|
+
};
|
|
51
|
+
await (0, execa.default)(hermesc, [
|
|
52
|
+
`-${completeOptions.optimization}`,
|
|
53
|
+
completeOptions.disableWarning ? "-w" : null,
|
|
54
|
+
completeOptions.sourcemap ? "-output-source-map" : null,
|
|
55
|
+
...getBaseArguments(outfile, jsBundle)
|
|
56
|
+
].filter(es_toolkit.isNotNil));
|
|
57
|
+
return {
|
|
58
|
+
hbc: outfile,
|
|
59
|
+
hbcSourcemap: completeOptions.sourcemap ? `${outfile}.map` : null
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function getBaseArguments(outfile, jsBundle) {
|
|
63
|
+
return [
|
|
64
|
+
"-emit-binary",
|
|
65
|
+
"-out",
|
|
66
|
+
outfile,
|
|
67
|
+
jsBundle
|
|
68
|
+
];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/shared/composeSourcemap.ts
|
|
73
|
+
async function writeComposedSourcemap(jsSourcemapPath, hbcSourcemapPath) {
|
|
74
|
+
const sourcemapContent = await composeSourcemap(jsSourcemapPath, hbcSourcemapPath);
|
|
75
|
+
await fs_promises.writeFile(hbcSourcemapPath, sourcemapContent, "utf-8");
|
|
76
|
+
}
|
|
77
|
+
async function composeSourcemap(jsSourcemapPath, hbcSourcemapPath) {
|
|
78
|
+
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();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/shared/resolveHermesBinaryPath.ts
|
|
88
|
+
/**
|
|
89
|
+
* Returns the Hermes OS binary folder name for the current platform.
|
|
90
|
+
*/
|
|
91
|
+
function getHermesOSBin() {
|
|
92
|
+
switch (process.platform) {
|
|
93
|
+
case "win32": return "win64-bin";
|
|
94
|
+
case "darwin": return "osx-bin";
|
|
95
|
+
default: return "linux64-bin";
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Returns the Hermes executable name for the current platform.
|
|
100
|
+
*/
|
|
101
|
+
function getHermesOSExe() {
|
|
102
|
+
const hermesExecutableName = "hermesc";
|
|
103
|
+
return process.platform === "win32" ? `${hermesExecutableName}.exe` : hermesExecutableName;
|
|
104
|
+
}
|
|
105
|
+
function getReactNativePackagePath(root) {
|
|
106
|
+
try {
|
|
107
|
+
return node_path.dirname(require.resolve("react-native/package.json", { paths: [root] }));
|
|
108
|
+
} catch {
|
|
109
|
+
return node_path.join("node_modules", "react-native");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function getHermesCompilerPackagePath(reactNativePath) {
|
|
113
|
+
try {
|
|
114
|
+
return node_path.dirname(require.resolve("hermes-compiler/package.json", { paths: [reactNativePath] }));
|
|
115
|
+
} catch {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function getPackagePathFromRoot(root, pkgName) {
|
|
120
|
+
try {
|
|
121
|
+
return node_path.dirname(require.resolve(`${pkgName}/package.json`, { paths: [root] }));
|
|
122
|
+
} catch {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function fileExists(file) {
|
|
127
|
+
try {
|
|
128
|
+
return node_fs.statSync(file).isFile();
|
|
129
|
+
} catch {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function resolveHermesBinaryPath(root = (0, _granite_js_utils.getPackageRoot)()) {
|
|
134
|
+
const reactNativePath = getReactNativePackagePath(root);
|
|
135
|
+
const hermesCompilerPath = getHermesCompilerPackagePath(reactNativePath);
|
|
136
|
+
if (hermesCompilerPath) {
|
|
137
|
+
const engine = node_path.join(hermesCompilerPath, "hermesc", getHermesOSBin(), getHermesOSExe());
|
|
138
|
+
if (fileExists(engine)) return engine;
|
|
139
|
+
}
|
|
140
|
+
const bundledHermesEngine = node_path.join(reactNativePath, "sdks", "hermesc", getHermesOSBin(), getHermesOSExe());
|
|
141
|
+
if (fileExists(bundledHermesEngine)) return bundledHermesEngine;
|
|
142
|
+
const hermesEnginePkg = getPackagePathFromRoot(root, "hermes-engine");
|
|
143
|
+
if (hermesEnginePkg) {
|
|
144
|
+
const engine = node_path.join(hermesEnginePkg, getHermesOSBin(), getHermesOSExe());
|
|
145
|
+
if (fileExists(engine)) return engine;
|
|
146
|
+
}
|
|
147
|
+
const hermesVmPkg = getPackagePathFromRoot(root, "hermesvm");
|
|
148
|
+
if (hermesVmPkg) {
|
|
149
|
+
const engine = node_path.join(hermesVmPkg, getHermesOSBin(), "hermes");
|
|
150
|
+
if (fileExists(engine)) return engine;
|
|
151
|
+
}
|
|
152
|
+
return node_path.join(reactNativePath, "sdks", "hermesc", getHermesOSBin(), getHermesOSExe());
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
//#endregion
|
|
156
|
+
Object.defineProperty(exports, '__toESM', {
|
|
157
|
+
enumerable: true,
|
|
158
|
+
get: function () {
|
|
159
|
+
return __toESM;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
Object.defineProperty(exports, 'compileHbc', {
|
|
163
|
+
enumerable: true,
|
|
164
|
+
get: function () {
|
|
165
|
+
return compileHbc;
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
Object.defineProperty(exports, 'resolveHermesBinaryPath', {
|
|
169
|
+
enumerable: true,
|
|
170
|
+
get: function () {
|
|
171
|
+
return resolveHermesBinaryPath;
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
Object.defineProperty(exports, 'writeComposedSourcemap', {
|
|
175
|
+
enumerable: true,
|
|
176
|
+
get: function () {
|
|
177
|
+
return writeComposedSourcemap;
|
|
178
|
+
}
|
|
179
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/shared/types.d.ts
|
|
2
|
+
interface HermesPluginOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Optimization level.
|
|
5
|
+
*
|
|
6
|
+
* - `O0`: No optimization
|
|
7
|
+
* - `Og`: Optimizations suitable for debugging
|
|
8
|
+
* - `O`: Expensive optimizations
|
|
9
|
+
*
|
|
10
|
+
* Defaults to `O`.
|
|
11
|
+
*/
|
|
12
|
+
optimization?: 'O0' | 'Og' | 'O';
|
|
13
|
+
/**
|
|
14
|
+
* Disable warning message.
|
|
15
|
+
*
|
|
16
|
+
* Defaults to `true`.
|
|
17
|
+
*/
|
|
18
|
+
disableWarning?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Emit source map.
|
|
21
|
+
*
|
|
22
|
+
* Defaults to `true`.
|
|
23
|
+
*/
|
|
24
|
+
sourcemap?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Path to hermesc binary.
|
|
27
|
+
*
|
|
28
|
+
* Defaults to `hermesc` in `react-native/sdks/hermesc/<platform>/hermesc`.
|
|
29
|
+
*/
|
|
30
|
+
binaryPath?: string;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { HermesPluginOptions as t };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/shared/types.d.ts
|
|
2
|
+
interface HermesPluginOptions {
|
|
3
|
+
/**
|
|
4
|
+
* Optimization level.
|
|
5
|
+
*
|
|
6
|
+
* - `O0`: No optimization
|
|
7
|
+
* - `Og`: Optimizations suitable for debugging
|
|
8
|
+
* - `O`: Expensive optimizations
|
|
9
|
+
*
|
|
10
|
+
* Defaults to `O`.
|
|
11
|
+
*/
|
|
12
|
+
optimization?: 'O0' | 'Og' | 'O';
|
|
13
|
+
/**
|
|
14
|
+
* Disable warning message.
|
|
15
|
+
*
|
|
16
|
+
* Defaults to `true`.
|
|
17
|
+
*/
|
|
18
|
+
disableWarning?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Emit source map.
|
|
21
|
+
*
|
|
22
|
+
* Defaults to `true`.
|
|
23
|
+
*/
|
|
24
|
+
sourcemap?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Path to hermesc binary.
|
|
27
|
+
*
|
|
28
|
+
* Defaults to `hermesc` in `react-native/sdks/hermesc/<platform>/hermesc`.
|
|
29
|
+
*/
|
|
30
|
+
binaryPath?: string;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { HermesPluginOptions as t };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@granite-js/plugin-hermes",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "3.0.1",
|
|
5
5
|
"description": "Hermes compilation plugin for Granite",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"prepack": "yarn build",
|
|
@@ -28,23 +28,43 @@
|
|
|
28
28
|
"default": "./dist/index.cjs"
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
|
+
"./mpack": {
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./dist/mpack.d.ts",
|
|
34
|
+
"default": "./dist/mpack.js"
|
|
35
|
+
},
|
|
36
|
+
"require": {
|
|
37
|
+
"types": "./dist/mpack.d.cts",
|
|
38
|
+
"default": "./dist/mpack.cjs"
|
|
39
|
+
}
|
|
40
|
+
},
|
|
31
41
|
"./package.json": "./package.json"
|
|
32
42
|
},
|
|
33
43
|
"files": [
|
|
34
44
|
"dist"
|
|
35
45
|
],
|
|
36
46
|
"devDependencies": {
|
|
47
|
+
"@types/node": "24.10.12",
|
|
37
48
|
"@vitest/coverage-v8": "^4.0.12",
|
|
49
|
+
"rollipop": "1.0.0-alpha.32",
|
|
38
50
|
"tsdown": "0.20.3",
|
|
39
51
|
"typescript": "5.9.3",
|
|
40
52
|
"vitest": "^4.0.12"
|
|
41
53
|
},
|
|
42
54
|
"dependencies": {
|
|
43
|
-
"@granite-js/plugin-core": "
|
|
44
|
-
"@granite-js/utils": "
|
|
55
|
+
"@granite-js/plugin-core": "3.0.1",
|
|
56
|
+
"@granite-js/utils": "3.0.1",
|
|
45
57
|
"es-toolkit": "^1.39.8",
|
|
46
58
|
"execa": "^5",
|
|
47
59
|
"source-map": "^0.8.0-beta.0"
|
|
48
60
|
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"rollipop": "*"
|
|
63
|
+
},
|
|
64
|
+
"peerDependenciesMeta": {
|
|
65
|
+
"rollipop": {
|
|
66
|
+
"optional": true
|
|
67
|
+
}
|
|
68
|
+
},
|
|
49
69
|
"sideEffects": false
|
|
50
70
|
}
|