Skip to content

Commit 88f18d4

Browse files
feat: use fs-fingerprint (#548)
* wip * bump fs-fingerprint * fixup * bump fs-fingerprint * bring back striping absolute paths * remove processExtraSources; update docs * take sourceDir into account; rework unnecessary rules * remove expo/fingerprint ref * remove preferLocal * add support for env * changeset * fixup schema * bump fs-fingerprint * use v0.7 --------- Co-authored-by: Michał Pierzchała <[email protected]>
1 parent 0c3badd commit 88f18d4

File tree

22 files changed

+234
-524
lines changed

22 files changed

+234
-524
lines changed

.changeset/odd-rings-learn.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@rock-js/platform-apple-helpers': patch
3+
'@rock-js/platform-android': patch
4+
'@rock-js/config': patch
5+
'@rock-js/tools': patch
6+
'rock': patch
7+
'rock-docs': patch
8+
---
9+
10+
feat: use fs-fingerprint

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
"publish:verdaccio": "npm publish --registry http://localhost:4873 --userconfig ../../.npmrc"
2424
},
2525
"dependencies": {
26-
"adm-zip": "^0.5.16",
2726
"@react-native-community/cli-config": "^20.0.0",
2827
"@rock-js/config": "^0.10.2",
2928
"@rock-js/tools": "^0.10.2",
29+
"adm-zip": "^0.5.16",
3030
"commander": "^12.1.0",
3131
"tar": "^7.4.3",
3232
"tslib": "^2.3.0"

packages/cli/src/lib/plugins/fingerprint.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type NativeFingerprintCommandOptions = {
1919

2020
export async function nativeFingerprintCommand(
2121
path: string,
22-
{ extraSources, ignorePaths }: FingerprintSources,
22+
{ extraSources, ignorePaths, env }: FingerprintSources,
2323
options: NativeFingerprintCommandOptions,
2424
) {
2525
validateOptions(options);
@@ -31,14 +31,15 @@ export async function nativeFingerprintCommand(
3131
platform,
3232
extraSources,
3333
ignorePaths,
34+
env,
3435
});
3536
console.log(fingerprint.hash);
3637
// log sources to stderr to avoid polluting the standard output
3738
console.error(
3839
JSON.stringify(
3940
{
4041
hash: fingerprint.hash,
41-
sources: fingerprint.sources.filter((source) => source.hash != null),
42+
sources: fingerprint.inputs.filter((source) => source.hash != null),
4243
},
4344
null,
4445
2,
@@ -57,6 +58,7 @@ export async function nativeFingerprintCommand(
5758
platform,
5859
extraSources,
5960
ignorePaths,
61+
env,
6062
});
6163
const duration = performance.now() - start;
6264

@@ -67,7 +69,7 @@ export async function nativeFingerprintCommand(
6769
logger.debug(
6870
'Sources:',
6971
JSON.stringify(
70-
fingerprint.sources.filter((source) => source.hash != null),
72+
fingerprint.inputs.filter((source) => source.hash != null),
7173
null,
7274
2,
7375
),

packages/cli/src/lib/plugins/logConfig.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ function filterConfig(config: Config) {
1818
// but in our case we don't install `@react-native-community/cli-platform-*` as a dependencies
1919
// so the config.platforms key is empty, which makes autolinking treat it as a dependency.
2020
delete filtered.dependencies['react-native'];
21+
// we don't want to show commands in the config
22+
filtered.commands = [];
2123
const dependencies: Record<string, DependencyConfig> = {};
2224
Object.keys(filtered.dependencies).forEach((item) => {
2325
if (isValidRNDependency(filtered.dependencies[item])) {

packages/config/src/lib/config.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { createRequire } from 'node:module';
33
import * as path from 'node:path';
44
import { pathToFileURL } from 'node:url';
55
import type { FingerprintSources, RemoteBuildCache } from '@rock-js/tools';
6-
import { colorLink, logger } from '@rock-js/tools';
6+
import { colorLink, getReactNativeVersion, logger } from '@rock-js/tools';
77
import type { ValidationError } from 'joi';
88
import { ConfigTypeSchema } from './schema.js';
99
import { formatValidationError } from './utils.js';
@@ -71,6 +71,7 @@ export type ConfigType = {
7171
fingerprint?: {
7272
extraSources?: string[];
7373
ignorePaths?: string[];
74+
env?: string[];
7475
};
7576
};
7677

@@ -218,24 +219,6 @@ export async function getConfig(
218219
return outputConfig;
219220
}
220221

221-
function getReactNativeVersion(root: string) {
222-
try {
223-
const require = createRequire(import.meta.url);
224-
return JSON.parse(
225-
fs.readFileSync(
226-
path.join(
227-
require.resolve('react-native', { paths: [root] }),
228-
'..',
229-
'package.json',
230-
),
231-
'utf-8',
232-
),
233-
).version;
234-
} catch {
235-
return 'unknown';
236-
}
237-
}
238-
239222
function resolveReactNativePath(root: string) {
240223
const require = createRequire(import.meta.url);
241224
return path.join(require.resolve('react-native', { paths: [root] }), '..');

packages/config/src/lib/schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ const ConfigTypeSchema = Joi.object({
5050
fingerprint: Joi.object({
5151
extraSources: Joi.array().items(Joi.string()).default([]),
5252
ignorePaths: Joi.array().items(Joi.string()).default([]),
53+
env: Joi.array().items(Joi.string()).default([]),
5354
})
5455
.default({
5556
extraSources: [],
5657
ignorePaths: [],
58+
env: [],
5759
})
5860
.optional(),
5961
}).unknown(false);

packages/platform-android/src/lib/commands/buildAndroid/buildAndroid.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export async function buildAndroid(
4141
fingerprintOptions,
4242
});
4343
const binaryPath = await getBinaryPath({
44+
platformName: 'android',
4445
artifactName,
4546
localFlag: args.local,
4647
remoteCacheProvider,

packages/platform-android/src/lib/commands/runAndroid/runAndroid.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export async function runAndroid(
6868
fingerprintOptions,
6969
});
7070
const binaryPath = await getBinaryPath({
71+
platformName: 'android',
7172
artifactName,
7273
binaryPathFlag: args.binaryPath,
7374
localFlag: args.local,

packages/platform-apple-helpers/src/lib/commands/build/createBuild.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export const createBuild = async ({
6666
let artifactName = await getArtifactName();
6767

6868
const binaryPath = await getBinaryPath({
69+
platformName,
6970
artifactName,
7071
localFlag: args.local,
7172
remoteCacheProvider,

packages/platform-apple-helpers/src/lib/commands/run/createRun.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export const createRun = async ({
6666
let artifactName = await getArtifactName();
6767

6868
const binaryPath = await getBinaryPath({
69+
platformName: 'ios',
6970
artifactName,
7071
binaryPathFlag: args.binaryPath,
7172
localFlag: args.local,

0 commit comments

Comments
 (0)