@react-native-oh/react-native-harmony-cli 0.0.41 → 0.0.43
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/dist/assetResolver.js
CHANGED
|
@@ -21,6 +21,13 @@ exports.copyAssets = copyAssets;
|
|
|
21
21
|
*/
|
|
22
22
|
const fs_1 = __importDefault(require("fs"));
|
|
23
23
|
const path_1 = __importDefault(require("path"));
|
|
24
|
+
const ENABLE_DEBUG_LOG = process.env.RNOH_BUNDLE_DEBUG === 'true';
|
|
25
|
+
function debugLog(message) {
|
|
26
|
+
if (ENABLE_DEBUG_LOG) {
|
|
27
|
+
const timestamp = new Date().toISOString().replace('T', ' ').substring(0, 23);
|
|
28
|
+
console.log(`[${timestamp}] ${message}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
24
31
|
const ALLOWED_SCALES = [1, 2, 3, 4];
|
|
25
32
|
function filterAssetScales(scales) {
|
|
26
33
|
const result = scales.filter(scale => ALLOWED_SCALES.includes(scale));
|
|
@@ -94,7 +101,9 @@ function copyFiles(logger, fileDestBySrc) {
|
|
|
94
101
|
}
|
|
95
102
|
if (fileSources.length === 0) {
|
|
96
103
|
logger.info(() => `Copied ${assetFilesCount} ${assetFilesCount === 1 ? 'asset' : 'assets'}`);
|
|
104
|
+
debugLog('All assets copied, resolving promise...');
|
|
97
105
|
resolve();
|
|
106
|
+
debugLog('Assets copy promise resolved');
|
|
98
107
|
}
|
|
99
108
|
else {
|
|
100
109
|
// fileSources.length === 0 is checked in previous branch, so this is string
|
|
@@ -113,8 +122,27 @@ function copyFile(src, dest, onFinished) {
|
|
|
113
122
|
onFinished(err);
|
|
114
123
|
return;
|
|
115
124
|
}
|
|
116
|
-
fs_1.default.createReadStream(src)
|
|
117
|
-
|
|
118
|
-
|
|
125
|
+
const readStream = fs_1.default.createReadStream(src);
|
|
126
|
+
const writeStream = fs_1.default.createWriteStream(dest);
|
|
127
|
+
let finished = false;
|
|
128
|
+
const handleError = (err) => {
|
|
129
|
+
if (!finished) {
|
|
130
|
+
finished = true;
|
|
131
|
+
console.error(`[Asset Copy Error] ${src} -> ${dest}:`, err.message);
|
|
132
|
+
readStream.destroy();
|
|
133
|
+
writeStream.destroy();
|
|
134
|
+
onFinished(err);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const handleFinish = () => {
|
|
138
|
+
if (!finished) {
|
|
139
|
+
finished = true;
|
|
140
|
+
onFinished();
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
readStream.on('error', handleError);
|
|
144
|
+
writeStream.on('error', handleError);
|
|
145
|
+
writeStream.on('finish', handleFinish);
|
|
146
|
+
readStream.pipe(writeStream);
|
|
119
147
|
});
|
|
120
148
|
}
|
|
@@ -24,6 +24,7 @@ const core_1 = require("../core");
|
|
|
24
24
|
const mustache_1 = __importDefault(require("mustache"));
|
|
25
25
|
const case_1 = __importDefault(require("case"));
|
|
26
26
|
const node_path_1 = __importDefault(require("node:path"));
|
|
27
|
+
const JSON5Writer_1 = require("./JSON5Writer");
|
|
27
28
|
const ETS_RNOH_PACKAGES_FACTORY_TEMPLATE = `
|
|
28
29
|
/*
|
|
29
30
|
* This file was generated by RNOH autolinking.
|
|
@@ -215,7 +216,7 @@ class Autolinking {
|
|
|
215
216
|
],
|
|
216
217
|
ohPackagePathAndContent: [
|
|
217
218
|
input.ohPackagePathAndContent[0],
|
|
218
|
-
|
|
219
|
+
JSON5Writer_1.JSON5Writer.updateDependenciesWithFallback(input.ohPackagePathAndContent[1], Object.assign(Object.assign({}, unmanagedNativeDependencySpecifierByName), managedNativeDependencySpecifierByName)),
|
|
219
220
|
],
|
|
220
221
|
};
|
|
221
222
|
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2026 Huawei Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE-MIT file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.JSON5Writer = void 0;
|
|
13
|
+
const json5_1 = __importDefault(require("json5"));
|
|
14
|
+
/**
|
|
15
|
+
* A utility class for modifying JSON5 content while preserving comments and formatting.
|
|
16
|
+
* Uses json5-writer's AST-based transformation to maintain the original structure.
|
|
17
|
+
*/
|
|
18
|
+
class JSON5Writer {
|
|
19
|
+
/**
|
|
20
|
+
* Updates the dependencies in a JSON5 string while preserving comments and formatting.
|
|
21
|
+
*
|
|
22
|
+
* @param content - The original JSON5 content
|
|
23
|
+
* @param newDependencies - The new dependencies object to set
|
|
24
|
+
* @returns The modified JSON5 content with preserved comments
|
|
25
|
+
*/
|
|
26
|
+
static updateDependencies(content, newDependencies) {
|
|
27
|
+
const json5Writer = require('json5-writer');
|
|
28
|
+
// Parse the original content to get all fields
|
|
29
|
+
const parsed = json5_1.default.parse(content);
|
|
30
|
+
// Create the new object with updated dependencies
|
|
31
|
+
const newObject = Object.assign(Object.assign({}, parsed), { dependencies: newDependencies });
|
|
32
|
+
// Load the original content into json5-writer to preserve comments
|
|
33
|
+
const writer = json5Writer.load(content);
|
|
34
|
+
// Write the new object, which will preserve comments
|
|
35
|
+
writer.write(newObject);
|
|
36
|
+
// Return the modified source with JSON5-style formatting
|
|
37
|
+
// Use double quotes for both keys and values, and trailing commas
|
|
38
|
+
// quoteKeys: true ensures keys with special characters (like @, /, -) are properly quoted
|
|
39
|
+
return writer.toSource({ quote: 'double', quoteKeys: true, trailingComma: true }) + '\n';
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Updates dependencies with fallback to standard JSON5 stringify if preservation fails.
|
|
43
|
+
* This ensures backward compatibility.
|
|
44
|
+
*
|
|
45
|
+
* @param content - The original JSON5 content
|
|
46
|
+
* @param newDependencies - The new dependencies object to set
|
|
47
|
+
* @returns The modified JSON5 content
|
|
48
|
+
*/
|
|
49
|
+
static updateDependenciesWithFallback(content, newDependencies) {
|
|
50
|
+
try {
|
|
51
|
+
return this.updateDependencies(content, newDependencies);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
// Fallback to JSON5 stringify if AST transformation fails
|
|
55
|
+
const parsed = json5_1.default.parse(content);
|
|
56
|
+
const result = Object.assign(Object.assign({}, parsed), { dependencies: newDependencies });
|
|
57
|
+
return json5_1.default.stringify(result, { space: 2, quote: '"' }) + '\n';
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.JSON5Writer = JSON5Writer;
|
|
@@ -26,6 +26,13 @@ const Server_1 = __importDefault(require("metro/src/Server"));
|
|
|
26
26
|
const path_1 = __importDefault(require("path"));
|
|
27
27
|
const assetResolver_1 = require("../assetResolver");
|
|
28
28
|
const io_1 = require("../io");
|
|
29
|
+
const ENABLE_DEBUG_LOG = process.env.RNOH_BUNDLE_DEBUG === 'true';
|
|
30
|
+
function debugLog(message) {
|
|
31
|
+
if (ENABLE_DEBUG_LOG) {
|
|
32
|
+
const timestamp = new Date().toISOString().replace('T', ' ').substring(0, 23);
|
|
33
|
+
console.log(`[${timestamp}] ${message}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
29
36
|
const ARK_RESOURCE_PATH = './harmony/entry/src/main/resources/rawfile';
|
|
30
37
|
const ASSETS_DEFAULT_DEST_PATH = './harmony/entry/src/main/resources/rawfile/assets';
|
|
31
38
|
exports.commandBundleHarmony = {
|
|
@@ -69,6 +76,7 @@ exports.commandBundleHarmony = {
|
|
|
69
76
|
],
|
|
70
77
|
func: (argv, config, args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
78
|
const logger = new io_1.Logger();
|
|
79
|
+
debugLog('Starting bundle-harmony process...');
|
|
72
80
|
const buildOptions = {
|
|
73
81
|
entry: args.entryFile,
|
|
74
82
|
platform: 'harmony',
|
|
@@ -78,10 +86,14 @@ exports.commandBundleHarmony = {
|
|
|
78
86
|
sourceMapUrl: args.sourcemapOutput,
|
|
79
87
|
};
|
|
80
88
|
const metroConfig = yield loadMetroConfig(args.config);
|
|
89
|
+
debugLog('Creating bundle...');
|
|
81
90
|
const bundle = yield createBundle(metroConfig, buildOptions);
|
|
82
91
|
yield saveBundle(bundle, args.bundleOutput, args.sourcemapOutput);
|
|
83
92
|
const assets = yield retrieveAssetsData(metroConfig, buildOptions);
|
|
84
|
-
(
|
|
93
|
+
debugLog('Copying assets...');
|
|
94
|
+
yield (0, assetResolver_1.copyAssets)(logger, assets, args.assetsDest);
|
|
95
|
+
debugLog('Assets copy completed, cleaning up...');
|
|
96
|
+
debugLog('Bundle process finished, exiting');
|
|
85
97
|
}),
|
|
86
98
|
};
|
|
87
99
|
function loadMetroConfig(configPath) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-native-oh/react-native-harmony-cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.43",
|
|
4
4
|
"description": "",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -64,6 +64,7 @@
|
|
|
64
64
|
"ignore": "^5.2.4",
|
|
65
65
|
"inquirer": "^12.7.0",
|
|
66
66
|
"json5": "^2.2.3",
|
|
67
|
+
"json5-writer": "^0.2.0",
|
|
67
68
|
"memfs": "4.12.0",
|
|
68
69
|
"mustache": "^4.2.0",
|
|
69
70
|
"tar": "^6.1.15",
|