@expo-harmony/expo-modules-autolinking 55.0.25-harmony.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/README.md +12 -0
- package/bin/expo-harmony-autolinking.ts +14 -0
- package/build/bin/expo-harmony-autolinking.d.ts +2 -0
- package/build/bin/expo-harmony-autolinking.js +11 -0
- package/build/index.d.ts +8 -0
- package/build/index.js +15 -0
- package/build/src/autolinking/link.d.ts +3 -0
- package/build/src/autolinking/link.js +150 -0
- package/build/src/autolinking/resolve.d.ts +4 -0
- package/build/src/autolinking/resolve.js +25 -0
- package/build/src/autolinking/search.d.ts +3 -0
- package/build/src/autolinking/search.js +357 -0
- package/build/src/autolinking/verify.d.ts +4 -0
- package/build/src/autolinking/verify.js +366 -0
- package/build/src/commands/autolinkingOptions.d.ts +12 -0
- package/build/src/commands/autolinkingOptions.js +35 -0
- package/build/src/commands/cli.d.ts +2 -0
- package/build/src/commands/cli.js +50 -0
- package/build/src/commands/link.d.ts +2 -0
- package/build/src/commands/link.js +27 -0
- package/build/src/commands/output.d.ts +3 -0
- package/build/src/commands/output.js +33 -0
- package/build/src/commands/resolve.d.ts +2 -0
- package/build/src/commands/resolve.js +13 -0
- package/build/src/commands/search.d.ts +2 -0
- package/build/src/commands/search.js +13 -0
- package/build/src/commands/verify.d.ts +2 -0
- package/build/src/commands/verify.js +17 -0
- package/build/src/config/constants.d.ts +17 -0
- package/build/src/config/constants.js +40 -0
- package/build/src/config/options.d.ts +13 -0
- package/build/src/config/options.js +202 -0
- package/build/src/errors.d.ts +18 -0
- package/build/src/errors.js +35 -0
- package/build/src/harmony/manifest/generate.d.ts +4 -0
- package/build/src/harmony/manifest/generate.js +55 -0
- package/build/src/harmony/manifest/index.d.ts +7 -0
- package/build/src/harmony/manifest/index.js +64 -0
- package/build/src/harmony/materialize.d.ts +12 -0
- package/build/src/harmony/materialize.js +278 -0
- package/build/src/harmony/ohpm/dependencies.d.ts +7 -0
- package/build/src/harmony/ohpm/dependencies.js +52 -0
- package/build/src/harmony/persistence/canonicalize.d.ts +15 -0
- package/build/src/harmony/persistence/canonicalize.js +108 -0
- package/build/src/harmony/providers/host.d.ts +3 -0
- package/build/src/harmony/providers/host.js +88 -0
- package/build/src/harmony/rnoh/cli.d.ts +2 -0
- package/build/src/harmony/rnoh/cli.js +55 -0
- package/build/src/harmony/rnoh/link.d.ts +2 -0
- package/build/src/harmony/rnoh/link.js +419 -0
- package/build/src/harmony/rnoh/packageMetadata.d.ts +12 -0
- package/build/src/harmony/rnoh/packageMetadata.js +125 -0
- package/build/src/harmony/transaction/previousState.d.ts +15 -0
- package/build/src/harmony/transaction/previousState.js +96 -0
- package/build/src/harmony/transaction/publish.d.ts +6 -0
- package/build/src/harmony/transaction/publish.js +272 -0
- package/build/src/harmony/transaction/stageProject.d.ts +18 -0
- package/build/src/harmony/transaction/stageProject.js +313 -0
- package/build/src/metadata/descriptor.d.ts +19 -0
- package/build/src/metadata/descriptor.js +306 -0
- package/build/src/metadata/host.d.ts +5 -0
- package/build/src/metadata/host.js +37 -0
- package/build/src/metadata/schema.d.ts +10 -0
- package/build/src/metadata/schema.js +171 -0
- package/build/src/types.d.ts +194 -0
- package/build/src/types.js +2 -0
- package/build/src/utilities/values.d.ts +17 -0
- package/build/src/utilities/values.js +205 -0
- package/harmony-module.schema.json +28 -0
- package/index.ts +41 -0
- package/package.json +66 -0
- package/src/autolinking/link.ts +170 -0
- package/src/autolinking/resolve.ts +33 -0
- package/src/autolinking/search.ts +369 -0
- package/src/autolinking/verify.ts +415 -0
- package/src/commands/autolinkingOptions.ts +38 -0
- package/src/commands/cli.ts +56 -0
- package/src/commands/link.ts +28 -0
- package/src/commands/output.ts +36 -0
- package/src/commands/resolve.ts +14 -0
- package/src/commands/search.ts +14 -0
- package/src/commands/verify.ts +17 -0
- package/src/config/constants.ts +45 -0
- package/src/config/options.ts +195 -0
- package/src/errors.ts +48 -0
- package/src/harmony/manifest/generate.ts +65 -0
- package/src/harmony/manifest/index.ts +81 -0
- package/src/harmony/materialize.ts +382 -0
- package/src/harmony/ohpm/dependencies.ts +59 -0
- package/src/harmony/persistence/canonicalize.ts +156 -0
- package/src/harmony/providers/host.ts +147 -0
- package/src/harmony/rnoh/cli.ts +59 -0
- package/src/harmony/rnoh/link.ts +481 -0
- package/src/harmony/rnoh/packageMetadata.ts +105 -0
- package/src/harmony/transaction/previousState.ts +71 -0
- package/src/harmony/transaction/publish.ts +287 -0
- package/src/harmony/transaction/stageProject.ts +345 -0
- package/src/metadata/descriptor.ts +324 -0
- package/src/metadata/host.ts +41 -0
- package/src/metadata/schema.ts +184 -0
- package/src/types.ts +220 -0
- package/src/utilities/values.ts +190 -0
- package/tsconfig.json +24 -0
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.linkRnohAsync = linkRnohAsync;
|
|
7
|
+
const node_child_process_1 = __importDefault(require("node:child_process"));
|
|
8
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
const constants_1 = require("../../config/constants");
|
|
11
|
+
const errors_1 = require("../../errors");
|
|
12
|
+
const options_1 = require("../../config/options");
|
|
13
|
+
const values_1 = require("../../utilities/values");
|
|
14
|
+
const generate_1 = require("../manifest/generate");
|
|
15
|
+
const canonicalize_1 = require("../persistence/canonicalize");
|
|
16
|
+
const packageMetadata_1 = require("./packageMetadata");
|
|
17
|
+
const cli_1 = require("./cli");
|
|
18
|
+
const DEFAULT_TIMEOUT_MS = 120_000;
|
|
19
|
+
const DEFAULT_OUTPUT_LIMIT = 64 * 1024;
|
|
20
|
+
function appendBounded(current, chunk, limit) {
|
|
21
|
+
if (current.length >= limit)
|
|
22
|
+
return current;
|
|
23
|
+
return Buffer.concat([current, chunk.subarray(0, limit - current.length)]);
|
|
24
|
+
}
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
+
function spawnBoundedAsync(executable, argv, options = {}) {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
const outputLimit = options.outputLimit === undefined ? DEFAULT_OUTPUT_LIMIT : options.outputLimit;
|
|
29
|
+
const timeoutMs = options.timeoutMs === undefined ? DEFAULT_TIMEOUT_MS : options.timeoutMs;
|
|
30
|
+
if (!Number.isInteger(outputLimit) || outputLimit <= 0
|
|
31
|
+
|| !Number.isInteger(timeoutMs) || timeoutMs <= 0) {
|
|
32
|
+
reject(new errors_1.HarmonyAutolinkingError('INVALID_OPTIONS', 'timeoutMs and outputLimit must be positive integers.', { stage: 'rnoh-preflight' }));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
let stdout = Buffer.alloc(0);
|
|
36
|
+
let stderr = Buffer.alloc(0);
|
|
37
|
+
let stdoutTruncated = false;
|
|
38
|
+
let stderrTruncated = false;
|
|
39
|
+
let timedOut = false;
|
|
40
|
+
let killTimer;
|
|
41
|
+
// eslint-disable-next-line prefer-const
|
|
42
|
+
let timeout;
|
|
43
|
+
let settled = false;
|
|
44
|
+
let child;
|
|
45
|
+
try {
|
|
46
|
+
child = node_child_process_1.default.spawn(executable, argv, {
|
|
47
|
+
cwd: options.cwd,
|
|
48
|
+
env: options.env || process.env,
|
|
49
|
+
shell: false,
|
|
50
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
catch (cause) {
|
|
54
|
+
reject(cause);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
child.stdout.on('data', (chunk) => {
|
|
58
|
+
if (stdout.length + chunk.length > outputLimit)
|
|
59
|
+
stdoutTruncated = true;
|
|
60
|
+
stdout = appendBounded(stdout, chunk, outputLimit);
|
|
61
|
+
});
|
|
62
|
+
child.stderr.on('data', (chunk) => {
|
|
63
|
+
if (stderr.length + chunk.length > outputLimit)
|
|
64
|
+
stderrTruncated = true;
|
|
65
|
+
stderr = appendBounded(stderr, chunk, outputLimit);
|
|
66
|
+
});
|
|
67
|
+
child.on('error', (error) => {
|
|
68
|
+
if (settled)
|
|
69
|
+
return;
|
|
70
|
+
settled = true;
|
|
71
|
+
clearTimeout(timeout);
|
|
72
|
+
clearTimeout(killTimer);
|
|
73
|
+
reject(error);
|
|
74
|
+
});
|
|
75
|
+
timeout = setTimeout(() => {
|
|
76
|
+
timedOut = true;
|
|
77
|
+
child.kill('SIGTERM');
|
|
78
|
+
killTimer = setTimeout(() => child.kill('SIGKILL'), 1_000);
|
|
79
|
+
killTimer.unref?.();
|
|
80
|
+
}, timeoutMs);
|
|
81
|
+
timeout.unref?.();
|
|
82
|
+
child.on('close', (code, signal) => {
|
|
83
|
+
if (settled)
|
|
84
|
+
return;
|
|
85
|
+
settled = true;
|
|
86
|
+
clearTimeout(timeout);
|
|
87
|
+
clearTimeout(killTimer);
|
|
88
|
+
resolve({
|
|
89
|
+
code,
|
|
90
|
+
signal,
|
|
91
|
+
timedOut,
|
|
92
|
+
stdout: stdout.toString('utf8'),
|
|
93
|
+
stderr: stderr.toString('utf8'),
|
|
94
|
+
stdoutTruncated,
|
|
95
|
+
stderrTruncated,
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
async function readGeneratedArtifactsAsync(harmony, allowedRoot) {
|
|
101
|
+
const lexicalAllowed = node_path_1.default.resolve(allowedRoot);
|
|
102
|
+
const lexicalRoot = node_path_1.default.resolve(harmony);
|
|
103
|
+
let root;
|
|
104
|
+
try {
|
|
105
|
+
if (!(0, values_1.isPathInside)(lexicalAllowed, lexicalRoot))
|
|
106
|
+
throw new TypeError('outside staging root');
|
|
107
|
+
const allowed = await node_fs_1.default.promises.realpath(lexicalAllowed);
|
|
108
|
+
root = await node_fs_1.default.promises.realpath(lexicalRoot);
|
|
109
|
+
const stat = await node_fs_1.default.promises.stat(root);
|
|
110
|
+
if (!(0, values_1.isPathInside)(allowed, root) || !stat.isDirectory())
|
|
111
|
+
throw new TypeError('unsafe staging root');
|
|
112
|
+
}
|
|
113
|
+
catch (cause) {
|
|
114
|
+
throw new errors_1.HarmonyAutolinkingError('GENERATED_ARTIFACT_MISSING', 'RNOH output root must resolve to a directory inside the staging project.', { cause, stage: 'rnoh-validate' });
|
|
115
|
+
}
|
|
116
|
+
const artifacts = {};
|
|
117
|
+
for (const [name, relative] of Object.entries(constants_1.RnohArtifacts)) {
|
|
118
|
+
const target = node_path_1.default.join(root, relative);
|
|
119
|
+
let stat;
|
|
120
|
+
let realTarget;
|
|
121
|
+
let artifact;
|
|
122
|
+
try {
|
|
123
|
+
if (!(0, values_1.isPathInside)(root, target))
|
|
124
|
+
throw new TypeError('outside staging root');
|
|
125
|
+
stat = await node_fs_1.default.promises.lstat(target);
|
|
126
|
+
if (!stat.isFile() || stat.isSymbolicLink() || stat.size === 0) {
|
|
127
|
+
throw new TypeError('not a non-empty regular file');
|
|
128
|
+
}
|
|
129
|
+
realTarget = await node_fs_1.default.promises.realpath(target);
|
|
130
|
+
if (!(0, values_1.isPathInside)(root, realTarget))
|
|
131
|
+
throw new TypeError('outside staging root');
|
|
132
|
+
artifact = name === 'cppFactory'
|
|
133
|
+
? { path: realTarget }
|
|
134
|
+
: { path: realTarget, content: await node_fs_1.default.promises.readFile(realTarget, 'utf8') };
|
|
135
|
+
}
|
|
136
|
+
catch (cause) {
|
|
137
|
+
throw new errors_1.HarmonyAutolinkingError('GENERATED_ARTIFACT_MISSING', `RNOH did not generate a non-empty regular ${relative}.`, {
|
|
138
|
+
cause,
|
|
139
|
+
stage: 'rnoh-validate',
|
|
140
|
+
details: { artifact: relative },
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
artifacts[name] = artifact;
|
|
144
|
+
}
|
|
145
|
+
return artifacts;
|
|
146
|
+
}
|
|
147
|
+
function buildLinkCommandArgs(linkOptions) {
|
|
148
|
+
(0, options_1.assertSafeRnohPackageList)(linkOptions.include || [], 'include', 'rnoh-preflight');
|
|
149
|
+
(0, options_1.assertSafeRnohPackageList)(linkOptions.exclude || [], 'exclude', 'rnoh-preflight');
|
|
150
|
+
if (linkOptions.include?.length && linkOptions.exclude?.length) {
|
|
151
|
+
throw new errors_1.HarmonyAutolinkingError('INVALID_OPTIONS', 'include and exclude cannot both be set for RNOH link-harmony.', { stage: 'rnoh-preflight' });
|
|
152
|
+
}
|
|
153
|
+
const argv = [
|
|
154
|
+
'link-harmony',
|
|
155
|
+
'--harmony-project-path', linkOptions.harmonyProjectPath,
|
|
156
|
+
'--node-modules-path', linkOptions.nodeModulesPath,
|
|
157
|
+
'--cmake-autolink-path-relative-to-harmony', constants_1.RnohArtifacts.cmake,
|
|
158
|
+
'--cpp-rnoh-packages-factory-path-relative-to-harmony', constants_1.RnohArtifacts.cppFactory,
|
|
159
|
+
'--ets-rnoh-packages-factory-path-relative-to-harmony', constants_1.RnohArtifacts.etsFactory,
|
|
160
|
+
'--oh-package-path-relative-to-harmony', constants_1.RnohArtifacts.ohPackage,
|
|
161
|
+
];
|
|
162
|
+
if (linkOptions.include?.length)
|
|
163
|
+
argv.push('--include-npm-packages', linkOptions.include.join(';'));
|
|
164
|
+
if (linkOptions.exclude?.length)
|
|
165
|
+
argv.push('--exclude-npm-packages', linkOptions.exclude.join(';'));
|
|
166
|
+
return argv;
|
|
167
|
+
}
|
|
168
|
+
function describeProcessFailure(result, roots) {
|
|
169
|
+
const reason = result.timedOut
|
|
170
|
+
? 'timed out'
|
|
171
|
+
: result.signal
|
|
172
|
+
? `was terminated by ${result.signal}`
|
|
173
|
+
: `exited with code ${result.code}`;
|
|
174
|
+
const stderr = (0, values_1.sanitizeOutput)(result.stderr, roots);
|
|
175
|
+
return `React Native link-harmony ${reason}${stderr ? `: ${stderr}` : '.'}`;
|
|
176
|
+
}
|
|
177
|
+
function patchEtsFactorySource(source, descriptors) {
|
|
178
|
+
// RNOH 0.84.1 emits this exact zero-argument factory shape. Convert only that
|
|
179
|
+
// current toolchain output so any upstream change is visible in CI.
|
|
180
|
+
const generated = 'import type { RNPackageContext, RNOHPackage } from \'@rnoh/react-native-openharmony\';';
|
|
181
|
+
const packageTypes = 'import type { RNPackage, RNPackageContext } from \'@rnoh/react-native-openharmony\';';
|
|
182
|
+
const generatedHostProvider = 'import { expoHarmonyHostProvider } from \'./generated/ExpoHarmonyHostProvider\';';
|
|
183
|
+
const coreRootImport = 'import ExpoModulesCorePackage from \'@expo-harmony/expo-modules-core\';';
|
|
184
|
+
const coreAutolinkingImport = 'import ExpoModulesCorePackage from \'@expo-harmony/expo-modules-core/Autolinking\';';
|
|
185
|
+
const replacements = [
|
|
186
|
+
[generated, `${packageTypes}\n${generatedHostProvider}`, 'RNOH package type import'],
|
|
187
|
+
[coreRootImport, coreAutolinkingImport, 'Expo Modules Core package import'],
|
|
188
|
+
['): RNOHPackage[] {', '): RNPackage[] {', 'RNOH package factory return type'],
|
|
189
|
+
[
|
|
190
|
+
'new ExpoModulesCorePackage(ctx)',
|
|
191
|
+
'new ExpoModulesCorePackage(ctx, expoHarmonyHostProvider.expoModules, expoHarmonyHostProvider.hostState)',
|
|
192
|
+
'Expo Modules Core zero-argument registration',
|
|
193
|
+
],
|
|
194
|
+
];
|
|
195
|
+
const namedImports = new Map();
|
|
196
|
+
for (const descriptor of descriptors.filter(item => item.rnoh.harPaths.length > 0)) {
|
|
197
|
+
const rnohMetadata = (0, packageMetadata_1.resolveRnohMetadata)(descriptor);
|
|
198
|
+
if (rnohMetadata.etsPackageImport !== 'named')
|
|
199
|
+
continue;
|
|
200
|
+
const name = rnohMetadata.harMappings[0].ohPackageName;
|
|
201
|
+
const defaultImport = `import ${rnohMetadata.etsPackageClassName} from '${name}';`;
|
|
202
|
+
const namedImport = `import { ${rnohMetadata.etsPackageClassName} } from '${name}';`;
|
|
203
|
+
namedImports.set(defaultImport, namedImport);
|
|
204
|
+
}
|
|
205
|
+
for (const [defaultImport, namedImport] of namedImports) {
|
|
206
|
+
replacements.push([defaultImport, namedImport, 'RNOH named package import']);
|
|
207
|
+
}
|
|
208
|
+
let content = source;
|
|
209
|
+
for (const [generatedFragment, replacement, name] of replacements) {
|
|
210
|
+
const fragments = content.split(generatedFragment);
|
|
211
|
+
if (fragments.length !== 2) {
|
|
212
|
+
throw new errors_1.HarmonyAutolinkingError('GENERATED_ARTIFACT_SET_MISMATCH', `RNOH 0.84.1 generated factory did not contain exactly one expected ${name}.`, { stage: 'rnoh-patch', details: { fragment: name } });
|
|
213
|
+
}
|
|
214
|
+
content = `${fragments[0]}${replacement}${fragments[1]}`;
|
|
215
|
+
}
|
|
216
|
+
return content;
|
|
217
|
+
}
|
|
218
|
+
async function patchEtsFactoryAsync(artifact, descriptors) {
|
|
219
|
+
const content = patchEtsFactorySource(artifact.content, descriptors);
|
|
220
|
+
if (content !== artifact.content) {
|
|
221
|
+
await node_fs_1.default.promises.writeFile(artifact.path, content);
|
|
222
|
+
artifact.content = content;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
function patchCmakeSource(source, descriptors) {
|
|
226
|
+
let content = source;
|
|
227
|
+
const guardedBlocks = new Map();
|
|
228
|
+
for (const descriptor of descriptors.filter(item => item.rnoh.harPaths.length > 0)) {
|
|
229
|
+
const metadata = (0, packageMetadata_1.resolveRnohMetadata)(descriptor);
|
|
230
|
+
const generated = ` add_subdirectory("\${OH_MODULES_DIR}/${descriptor.packageName}/src/main/cpp" ./${metadata.cmakeLibraryTargetName})`;
|
|
231
|
+
const guarded = [
|
|
232
|
+
` if(NOT TARGET ${metadata.cmakeLibraryTargetName})`,
|
|
233
|
+
` add_subdirectory("\${OH_MODULES_DIR}/${descriptor.packageName}/src/main/cpp" ./${metadata.cmakeLibraryTargetName})`,
|
|
234
|
+
' endif()',
|
|
235
|
+
].join('\n');
|
|
236
|
+
guardedBlocks.set(metadata.cmakeLibraryTargetName, guarded);
|
|
237
|
+
const fragments = content.split(generated);
|
|
238
|
+
if (fragments.length !== 2) {
|
|
239
|
+
throw new errors_1.HarmonyAutolinkingError('GENERATED_ARTIFACT_SET_MISMATCH', `RNOH 0.84.1 generated CMake did not contain exactly one add_subdirectory for ${descriptor.packageName}.`, { stage: 'rnoh-patch', packageName: descriptor.packageName });
|
|
240
|
+
}
|
|
241
|
+
content = `${fragments[0]}${guarded}${fragments[1]}`;
|
|
242
|
+
}
|
|
243
|
+
// Core consumes the dependency's public CMake target. Configure Worklets
|
|
244
|
+
// first instead of making Core compile a private copy of dependency sources.
|
|
245
|
+
const coreBlock = guardedBlocks.get('expo_harmony__expo_modules_core');
|
|
246
|
+
const workletsBlock = guardedBlocks.get('rnoh_worklets');
|
|
247
|
+
if (coreBlock && workletsBlock) {
|
|
248
|
+
const coreIndex = content.indexOf(coreBlock);
|
|
249
|
+
const workletsIndex = content.indexOf(workletsBlock);
|
|
250
|
+
if (coreIndex >= 0 && workletsIndex > coreIndex) {
|
|
251
|
+
content = content.replace(`${workletsBlock}\n`, '');
|
|
252
|
+
const updatedCoreIndex = content.indexOf(coreBlock);
|
|
253
|
+
content = `${content.slice(0, updatedCoreIndex)}${workletsBlock}\n${content.slice(updatedCoreIndex)}`;
|
|
254
|
+
}
|
|
255
|
+
// The Harmony Worklets package cannot infer the Hermes ABI selected by the
|
|
256
|
+
// application. Forward the real build setting after its public target has
|
|
257
|
+
// been configured; Core must not hard-code or override dependency sources.
|
|
258
|
+
const configuredWorkletsBlock = [
|
|
259
|
+
workletsBlock,
|
|
260
|
+
// Worklets 1.0.0 declares implementation files as PUBLIC sources. Do not
|
|
261
|
+
// make every linked consumer compile the dependency implementation again.
|
|
262
|
+
' set_property(TARGET rnoh_worklets PROPERTY INTERFACE_SOURCES "")',
|
|
263
|
+
' set(EXPO_RNOH_PACKAGE_JSON_PATH "${OH_MODULES_DIR}/@rnoh/react-native-openharmony/oh-package.json5")',
|
|
264
|
+
' if(NOT EXISTS "${EXPO_RNOH_PACKAGE_JSON_PATH}")',
|
|
265
|
+
' message(FATAL_ERROR "Unable to locate the RNOH package manifest")',
|
|
266
|
+
' endif()',
|
|
267
|
+
' file(READ "${EXPO_RNOH_PACKAGE_JSON_PATH}" EXPO_RNOH_PACKAGE_JSON)',
|
|
268
|
+
' string(JSON EXPO_RNOH_VERSION GET "${EXPO_RNOH_PACKAGE_JSON}" version)',
|
|
269
|
+
' if(NOT EXPO_RNOH_VERSION MATCHES "^0\\\\.([0-9]+)\\\\.")',
|
|
270
|
+
' message(FATAL_ERROR "Unable to derive the React Native minor from RNOH ${EXPO_RNOH_VERSION}")',
|
|
271
|
+
' endif()',
|
|
272
|
+
' set(EXPO_RNOH_MINOR_VERSION "${CMAKE_MATCH_1}")',
|
|
273
|
+
' target_compile_definitions(rnoh_worklets PUBLIC REACT_NATIVE_MINOR_VERSION=${EXPO_RNOH_MINOR_VERSION})',
|
|
274
|
+
' if(DEFINED ENV{HERMES_V1_ENABLED} AND "$ENV{HERMES_V1_ENABLED}" STREQUAL "true")',
|
|
275
|
+
' target_compile_definitions(rnoh_worklets PRIVATE HERMES_V1_ENABLED=1)',
|
|
276
|
+
' endif()',
|
|
277
|
+
' if(EXPO_RNOH_MINOR_VERSION GREATER_EQUAL 84)',
|
|
278
|
+
' set(EXPO_WORKLETS_MODULE_SOURCE "${OH_MODULES_DIR}/@react-native-ohos/react-native-worklets/src/main/cpp/WorkletsModule.cpp")',
|
|
279
|
+
' file(READ "${EXPO_WORKLETS_MODULE_SOURCE}" EXPO_WORKLETS_MODULE_CONTENT)',
|
|
280
|
+
' set(EXPO_WORKLETS_OLD_FRAGMENT "std::shared_ptr<const BigStringBuffer> script = nullptr;")',
|
|
281
|
+
' string(FIND "${EXPO_WORKLETS_MODULE_CONTENT}" "${EXPO_WORKLETS_OLD_FRAGMENT}" EXPO_WORKLETS_FRAGMENT_OFFSET)',
|
|
282
|
+
' if(EXPO_WORKLETS_FRAGMENT_OFFSET EQUAL -1)',
|
|
283
|
+
' message(FATAL_ERROR "Worklets Harmony wrapper no longer matches the guarded RN 0.84 compatibility patch")',
|
|
284
|
+
' endif()',
|
|
285
|
+
' string(REPLACE "${EXPO_WORKLETS_OLD_FRAGMENT}" "std::shared_ptr<const JSBigStringBuffer> script = nullptr;" EXPO_WORKLETS_MODULE_CONTENT "${EXPO_WORKLETS_MODULE_CONTENT}")',
|
|
286
|
+
' set(EXPO_WORKLETS_OLD_FRAGMENT "auto jsBigString = std::make_unique<JSBigBufferString>(len);")',
|
|
287
|
+
' string(FIND "${EXPO_WORKLETS_MODULE_CONTENT}" "${EXPO_WORKLETS_OLD_FRAGMENT}" EXPO_WORKLETS_FRAGMENT_OFFSET)',
|
|
288
|
+
' if(EXPO_WORKLETS_FRAGMENT_OFFSET EQUAL -1)',
|
|
289
|
+
' message(FATAL_ERROR "Worklets Harmony bundle allocation no longer matches the guarded RN 0.84 compatibility patch")',
|
|
290
|
+
' endif()',
|
|
291
|
+
' string(REPLACE "${EXPO_WORKLETS_OLD_FRAGMENT}" "auto jsBigString = std::make_shared<JSBigBufferString>(len);" EXPO_WORKLETS_MODULE_CONTENT "${EXPO_WORKLETS_MODULE_CONTENT}")',
|
|
292
|
+
' set(EXPO_WORKLETS_OLD_FRAGMENT "char *buffer = jsBigString->data();")',
|
|
293
|
+
' string(FIND "${EXPO_WORKLETS_MODULE_CONTENT}" "${EXPO_WORKLETS_OLD_FRAGMENT}" EXPO_WORKLETS_FRAGMENT_OFFSET)',
|
|
294
|
+
' if(EXPO_WORKLETS_FRAGMENT_OFFSET EQUAL -1)',
|
|
295
|
+
' message(FATAL_ERROR "Worklets Harmony bundle buffer access no longer matches the guarded RN 0.84 compatibility patch")',
|
|
296
|
+
' endif()',
|
|
297
|
+
' string(REPLACE "${EXPO_WORKLETS_OLD_FRAGMENT}" "char *buffer = jsBigString->mutableData();" EXPO_WORKLETS_MODULE_CONTENT "${EXPO_WORKLETS_MODULE_CONTENT}")',
|
|
298
|
+
' set(EXPO_WORKLETS_OLD_FRAGMENT "script = std::make_shared<BigStringBuffer>(std::move(jsBigString));")',
|
|
299
|
+
' string(FIND "${EXPO_WORKLETS_MODULE_CONTENT}" "${EXPO_WORKLETS_OLD_FRAGMENT}" EXPO_WORKLETS_FRAGMENT_OFFSET)',
|
|
300
|
+
' if(EXPO_WORKLETS_FRAGMENT_OFFSET EQUAL -1)',
|
|
301
|
+
' message(FATAL_ERROR "Worklets Harmony bundle assignment no longer matches the guarded RN 0.84 compatibility patch")',
|
|
302
|
+
' endif()',
|
|
303
|
+
' string(REPLACE "${EXPO_WORKLETS_OLD_FRAGMENT}" "script = std::move(jsBigString);" EXPO_WORKLETS_MODULE_CONTENT "${EXPO_WORKLETS_MODULE_CONTENT}")',
|
|
304
|
+
' set(EXPO_WORKLETS_PATCH_DIR "${CMAKE_CURRENT_BINARY_DIR}/expo_worklets_compat")',
|
|
305
|
+
' file(MAKE_DIRECTORY "${EXPO_WORKLETS_PATCH_DIR}")',
|
|
306
|
+
' set(EXPO_WORKLETS_PATCHED_MODULE "${EXPO_WORKLETS_PATCH_DIR}/WorkletsModule.cpp")',
|
|
307
|
+
' file(WRITE "${EXPO_WORKLETS_PATCHED_MODULE}" "${EXPO_WORKLETS_MODULE_CONTENT}")',
|
|
308
|
+
' get_target_property(EXPO_WORKLETS_SOURCES rnoh_worklets SOURCES)',
|
|
309
|
+
' set(EXPO_WORKLETS_FILTERED_SOURCES)',
|
|
310
|
+
' foreach(EXPO_WORKLETS_SOURCE IN LISTS EXPO_WORKLETS_SOURCES)',
|
|
311
|
+
' if(NOT EXPO_WORKLETS_SOURCE MATCHES "(^|/)WorkletsModule\\\\.cpp$")',
|
|
312
|
+
' list(APPEND EXPO_WORKLETS_FILTERED_SOURCES "${EXPO_WORKLETS_SOURCE}")',
|
|
313
|
+
' endif()',
|
|
314
|
+
' endforeach()',
|
|
315
|
+
' set_property(TARGET rnoh_worklets PROPERTY SOURCES ${EXPO_WORKLETS_FILTERED_SOURCES})',
|
|
316
|
+
' target_sources(rnoh_worklets PRIVATE "${EXPO_WORKLETS_PATCHED_MODULE}")',
|
|
317
|
+
' endif()',
|
|
318
|
+
].join('\n');
|
|
319
|
+
content = content.replace(workletsBlock, configuredWorkletsBlock);
|
|
320
|
+
}
|
|
321
|
+
return content;
|
|
322
|
+
}
|
|
323
|
+
async function patchCmakeAsync(artifact, descriptors) {
|
|
324
|
+
const content = patchCmakeSource(artifact.content, descriptors);
|
|
325
|
+
if (content !== artifact.content) {
|
|
326
|
+
await node_fs_1.default.promises.writeFile(artifact.path, content);
|
|
327
|
+
artifact.content = content;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
function patchOhpmManifest(artifact, descriptors, buildType, harmonyProjectPath) {
|
|
331
|
+
artifact.content = (0, canonicalize_1.canonicalizeOhpmManifest)(artifact.content, (0, generate_1.createManifest)(descriptors, { buildType }), {
|
|
332
|
+
errorCode: 'RNOH_LINK_FAILED',
|
|
333
|
+
harmonyProjectPath,
|
|
334
|
+
stage: 'rnoh-patch',
|
|
335
|
+
}).source;
|
|
336
|
+
}
|
|
337
|
+
async function linkRnohAsync(linkOptions) {
|
|
338
|
+
const executable = await (0, cli_1.resolveCliAsync)({
|
|
339
|
+
...linkOptions,
|
|
340
|
+
nodeModulesPath: linkOptions.commandNodeModulesPath || linkOptions.nodeModulesPath,
|
|
341
|
+
});
|
|
342
|
+
const spawn = {
|
|
343
|
+
cwd: linkOptions.stageProjectRoot,
|
|
344
|
+
env: linkOptions.env ? { ...process.env, ...linkOptions.env } : process.env,
|
|
345
|
+
outputLimit: linkOptions.outputLimit,
|
|
346
|
+
timeoutMs: linkOptions.timeoutMs,
|
|
347
|
+
};
|
|
348
|
+
let result;
|
|
349
|
+
try {
|
|
350
|
+
result = await spawnBoundedAsync(executable, buildLinkCommandArgs({
|
|
351
|
+
harmonyProjectPath: linkOptions.stageHarmonyProjectPath,
|
|
352
|
+
nodeModulesPath: linkOptions.nodeModulesPath,
|
|
353
|
+
include: linkOptions.include,
|
|
354
|
+
exclude: linkOptions.exclude,
|
|
355
|
+
}), spawn);
|
|
356
|
+
}
|
|
357
|
+
catch (cause) {
|
|
358
|
+
throw new errors_1.HarmonyAutolinkingError('RNOH_LINK_FAILED', 'Unable to execute React Native link-harmony.', { cause, stage: 'rnoh-link' });
|
|
359
|
+
}
|
|
360
|
+
if (result.code !== 0 || result.signal || result.timedOut) {
|
|
361
|
+
throw new errors_1.HarmonyAutolinkingError('RNOH_LINK_FAILED', describeProcessFailure(result, [linkOptions.temporaryRoot, linkOptions.projectRoot]), {
|
|
362
|
+
stage: 'rnoh-link',
|
|
363
|
+
details: {
|
|
364
|
+
exitCode: result.code,
|
|
365
|
+
signal: result.signal,
|
|
366
|
+
timedOut: result.timedOut,
|
|
367
|
+
stdoutTruncated: result.stdoutTruncated,
|
|
368
|
+
stderrTruncated: result.stderrTruncated,
|
|
369
|
+
},
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
let artifacts;
|
|
373
|
+
try {
|
|
374
|
+
artifacts = await readGeneratedArtifactsAsync(linkOptions.stageHarmonyProjectPath, linkOptions.stageProjectRoot);
|
|
375
|
+
}
|
|
376
|
+
catch (error) {
|
|
377
|
+
const roots = [linkOptions.temporaryRoot, linkOptions.stageProjectRoot, linkOptions.projectRoot];
|
|
378
|
+
const details = {
|
|
379
|
+
...(error.details || {}),
|
|
380
|
+
stdout: (0, values_1.sanitizeOutput)(result.stdout, roots),
|
|
381
|
+
stderr: (0, values_1.sanitizeOutput)(result.stderr, roots),
|
|
382
|
+
stdoutTruncated: result.stdoutTruncated,
|
|
383
|
+
stderrTruncated: result.stderrTruncated,
|
|
384
|
+
};
|
|
385
|
+
throw new errors_1.HarmonyAutolinkingError(typeof error.code === 'string' ? error.code : 'RNOH_LINK_FAILED', error.message || 'RNOH did not generate the required artifacts.', {
|
|
386
|
+
cause: error,
|
|
387
|
+
stage: error.stage || 'rnoh-validate',
|
|
388
|
+
packageName: error.packageName,
|
|
389
|
+
diagnostics: error.diagnostics,
|
|
390
|
+
details,
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
if (linkOptions.modules) {
|
|
394
|
+
try {
|
|
395
|
+
await patchCmakeAsync(artifacts.cmake, linkOptions.modules);
|
|
396
|
+
await patchEtsFactoryAsync(artifacts.etsFactory, linkOptions.modules);
|
|
397
|
+
patchOhpmManifest(artifacts.ohPackage, linkOptions.modules, linkOptions.buildType, linkOptions.harmonyProjectPath);
|
|
398
|
+
await node_fs_1.default.promises.writeFile(artifacts.ohPackage.path, artifacts.ohPackage.content);
|
|
399
|
+
}
|
|
400
|
+
catch (error) {
|
|
401
|
+
const roots = [linkOptions.temporaryRoot, linkOptions.stageProjectRoot, linkOptions.projectRoot];
|
|
402
|
+
const details = {
|
|
403
|
+
...(error.details || {}),
|
|
404
|
+
stdout: (0, values_1.sanitizeOutput)(result.stdout, roots),
|
|
405
|
+
stderr: (0, values_1.sanitizeOutput)(result.stderr, roots),
|
|
406
|
+
stdoutTruncated: result.stdoutTruncated,
|
|
407
|
+
stderrTruncated: result.stderrTruncated,
|
|
408
|
+
};
|
|
409
|
+
throw new errors_1.HarmonyAutolinkingError(typeof error.code === 'string' ? error.code : 'RNOH_LINK_FAILED', error.message || 'Unable to patch RNOH artifacts.', {
|
|
410
|
+
cause: error,
|
|
411
|
+
stage: error.stage || 'rnoh-validate',
|
|
412
|
+
packageName: error.packageName,
|
|
413
|
+
diagnostics: error.diagnostics,
|
|
414
|
+
details,
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return artifacts;
|
|
419
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare function defaultCmakeTargetForNpmPackage(packageName: any): string;
|
|
2
|
+
declare function defaultOhPackageNameForNpmPackage(packageName: any): string;
|
|
3
|
+
declare function ohPackageNameForHar(base: any, harPath: any, harCount: any): any;
|
|
4
|
+
declare function resolveRnohMetadata(descriptor: any): {
|
|
5
|
+
packageName: any;
|
|
6
|
+
harMappings: any;
|
|
7
|
+
etsPackageClassName: any;
|
|
8
|
+
etsPackageImport: any;
|
|
9
|
+
cppPackageClassName: any;
|
|
10
|
+
cmakeLibraryTargetName: any;
|
|
11
|
+
};
|
|
12
|
+
export { defaultCmakeTargetForNpmPackage, defaultOhPackageNameForNpmPackage, ohPackageNameForHar, resolveRnohMetadata, };
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.defaultCmakeTargetForNpmPackage = defaultCmakeTargetForNpmPackage;
|
|
40
|
+
exports.defaultOhPackageNameForNpmPackage = defaultOhPackageNameForNpmPackage;
|
|
41
|
+
exports.ohPackageNameForHar = ohPackageNameForHar;
|
|
42
|
+
exports.resolveRnohMetadata = resolveRnohMetadata;
|
|
43
|
+
const path = __importStar(require("node:path"));
|
|
44
|
+
const case_1 = __importDefault(require("case"));
|
|
45
|
+
const errors_1 = require("../../errors");
|
|
46
|
+
function packageNameParts(packageName) {
|
|
47
|
+
if (packageName.startsWith('@')) {
|
|
48
|
+
const [scopeName, name] = packageName.slice(1).split('/');
|
|
49
|
+
return { scopeName, name };
|
|
50
|
+
}
|
|
51
|
+
return { scopeName: null, name: packageName };
|
|
52
|
+
}
|
|
53
|
+
function defaultPackageClassName(packageName) {
|
|
54
|
+
const { scopeName, name } = packageNameParts(packageName);
|
|
55
|
+
return scopeName
|
|
56
|
+
? `${case_1.default.pascal(scopeName)}${case_1.default.pascal(name)}Package`
|
|
57
|
+
: `${case_1.default.pascal(name)}Package`;
|
|
58
|
+
}
|
|
59
|
+
function defaultCmakeTargetForNpmPackage(packageName) {
|
|
60
|
+
const { scopeName, name } = packageNameParts(packageName);
|
|
61
|
+
return scopeName
|
|
62
|
+
? `rnoh__${case_1.default.snake(scopeName)}__${case_1.default.snake(name)}`
|
|
63
|
+
: `rnoh__${case_1.default.snake(name)}`;
|
|
64
|
+
}
|
|
65
|
+
function defaultOhPackageNameForNpmPackage(packageName) {
|
|
66
|
+
const { scopeName, name } = packageNameParts(packageName);
|
|
67
|
+
return scopeName
|
|
68
|
+
? `@rnoh/${case_1.default.kebab(scopeName)}--${case_1.default.kebab(name)}`
|
|
69
|
+
: `@rnoh/${case_1.default.kebab(name)}`;
|
|
70
|
+
}
|
|
71
|
+
function ohPackageNameForHar(base, harPath, harCount) {
|
|
72
|
+
return harCount > 1
|
|
73
|
+
? `${base}--${path.basename(harPath, '.har')}`
|
|
74
|
+
: base;
|
|
75
|
+
}
|
|
76
|
+
function resolveHarPackageMappings(descriptor) {
|
|
77
|
+
const harPaths = descriptor.rnoh.harPaths || [];
|
|
78
|
+
if (harPaths.length === 0)
|
|
79
|
+
return [];
|
|
80
|
+
const configured = descriptor.rnoh.ohPackageName;
|
|
81
|
+
if (configured === undefined) {
|
|
82
|
+
const base = defaultOhPackageNameForNpmPackage(descriptor.packageName);
|
|
83
|
+
return harPaths.map(harPath => ({
|
|
84
|
+
harPath,
|
|
85
|
+
ohPackageName: ohPackageNameForHar(base, harPath, harPaths.length),
|
|
86
|
+
}));
|
|
87
|
+
}
|
|
88
|
+
if (typeof configured === 'string') {
|
|
89
|
+
return harPaths.map(harPath => ({
|
|
90
|
+
harPath,
|
|
91
|
+
ohPackageName: ohPackageNameForHar(configured, harPath, harPaths.length),
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
const defaultName = defaultOhPackageNameForNpmPackage(descriptor.packageName);
|
|
95
|
+
return harPaths.map((harPath) => {
|
|
96
|
+
const mapping = configured.find(item => item.harName === path.basename(harPath));
|
|
97
|
+
if (!mapping)
|
|
98
|
+
return {
|
|
99
|
+
harPath,
|
|
100
|
+
ohPackageName: ohPackageNameForHar(defaultName, harPath, harPaths.length),
|
|
101
|
+
};
|
|
102
|
+
return {
|
|
103
|
+
harPath,
|
|
104
|
+
ohPackageName: mapping.packageName,
|
|
105
|
+
...(mapping.version ? { version: mapping.version } : {}),
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
function resolveRnohMetadata(descriptor) {
|
|
110
|
+
const pkg = defaultPackageClassName(descriptor.packageName);
|
|
111
|
+
if ((descriptor.rnoh.etsPackageClassName === undefined
|
|
112
|
+
|| descriptor.rnoh.cppPackageClassName === undefined)
|
|
113
|
+
&& !/^[A-Za-z_][A-Za-z0-9_]*$/u.test(pkg)) {
|
|
114
|
+
throw new errors_1.HarmonyAutolinkingError('INVALID_METADATA', 'The npm package name cannot produce a valid default RNOH package class; configure the package class names explicitly.', { packageName: descriptor.packageName, stage: 'metadata' });
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
packageName: descriptor.packageName,
|
|
118
|
+
harMappings: resolveHarPackageMappings(descriptor),
|
|
119
|
+
etsPackageClassName: descriptor.rnoh.etsPackageClassName || pkg,
|
|
120
|
+
etsPackageImport: descriptor.rnoh.etsPackageImport || 'default',
|
|
121
|
+
cppPackageClassName: descriptor.rnoh.cppPackageClassName || pkg,
|
|
122
|
+
cmakeLibraryTargetName: descriptor.rnoh.cmakeLibraryTargetName
|
|
123
|
+
|| defaultCmakeTargetForNpmPackage(descriptor.packageName),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare function readPreviousAutolinkingStateAsync(projectRoot: any): Promise<{
|
|
2
|
+
artifacts: string[];
|
|
3
|
+
managedOhpmPackageNames: string[];
|
|
4
|
+
warning: any;
|
|
5
|
+
} | {
|
|
6
|
+
artifacts: any[];
|
|
7
|
+
managedOhpmPackageNames: any[];
|
|
8
|
+
warning: {
|
|
9
|
+
severity: string;
|
|
10
|
+
code: string;
|
|
11
|
+
message: any;
|
|
12
|
+
stage: string;
|
|
13
|
+
};
|
|
14
|
+
}>;
|
|
15
|
+
export { readPreviousAutolinkingStateAsync, };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.readPreviousAutolinkingStateAsync = readPreviousAutolinkingStateAsync;
|
|
37
|
+
const fs = __importStar(require("node:fs"));
|
|
38
|
+
const path = __importStar(require("node:path"));
|
|
39
|
+
const constants_1 = require("../../config/constants");
|
|
40
|
+
const manifest_1 = require("../manifest");
|
|
41
|
+
const values_1 = require("../../utilities/values");
|
|
42
|
+
const ManagedSuffixes = [
|
|
43
|
+
...Object.values(constants_1.RnohArtifacts),
|
|
44
|
+
...Object.values(constants_1.ExpoArtifacts),
|
|
45
|
+
];
|
|
46
|
+
function isManagedArtifactPath(relativePath) {
|
|
47
|
+
if (relativePath === constants_1.ManifestArtifact)
|
|
48
|
+
return true;
|
|
49
|
+
return ManagedSuffixes.some(suffix => relativePath === suffix || relativePath.endsWith(`/${suffix}`));
|
|
50
|
+
}
|
|
51
|
+
function normalizeManagedArtifactPath(value) {
|
|
52
|
+
if (typeof value !== 'string' || !value || value.includes('\\') || path.posix.isAbsolute(value)) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
const normalized = path.posix.normalize(value);
|
|
56
|
+
if (normalized !== value || normalized === '..' || normalized.startsWith('../'))
|
|
57
|
+
return null;
|
|
58
|
+
return isManagedArtifactPath(normalized) ? normalized : null;
|
|
59
|
+
}
|
|
60
|
+
function staleManifestWarning(message) {
|
|
61
|
+
return {
|
|
62
|
+
severity: 'warning',
|
|
63
|
+
code: 'ERR_EXPO_HARMONY_STALE_MANIFEST_IGNORED',
|
|
64
|
+
message,
|
|
65
|
+
stage: 'publish',
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
async function readPreviousAutolinkingStateAsync(projectRoot) {
|
|
69
|
+
const manifestPath = path.join(projectRoot, constants_1.ManifestArtifact);
|
|
70
|
+
if (!(await (0, values_1.pathExistsAsync)(manifestPath))) {
|
|
71
|
+
return { artifacts: [], managedOhpmPackageNames: [], warning: null };
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
const stat = await fs.promises.lstat(manifestPath);
|
|
75
|
+
if (!stat.isFile() || stat.isSymbolicLink())
|
|
76
|
+
throw new TypeError('manifest is not a regular file');
|
|
77
|
+
const manifest = (0, manifest_1.validateManifest)(JSON.parse(await fs.promises.readFile(manifestPath, 'utf8')), { file: manifestPath });
|
|
78
|
+
const normalized = manifest.managedArtifacts.map(normalizeManagedArtifactPath);
|
|
79
|
+
if (normalized.some(value => value == null))
|
|
80
|
+
throw new TypeError('manifest contains an unsafe path');
|
|
81
|
+
const artifacts = normalized.filter((value) => value !== null);
|
|
82
|
+
return {
|
|
83
|
+
artifacts: [...new Set(artifacts)].map(relative => path.join(projectRoot, ...relative.split('/'))),
|
|
84
|
+
managedOhpmPackageNames: Object.keys((0, manifest_1.ohpmDependenciesFromManifest)(manifest))
|
|
85
|
+
.sort((left, right) => left.localeCompare(right, 'en')),
|
|
86
|
+
warning: null,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
catch (_cause) {
|
|
90
|
+
return {
|
|
91
|
+
artifacts: [],
|
|
92
|
+
managedOhpmPackageNames: [],
|
|
93
|
+
warning: staleManifestWarning('The previous Harmony autolinking manifest is invalid; stale artifact cleanup was skipped.'),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|