Skip to content

Commit 86f84c7

Browse files
committed
Default to skipping eas / local folders
1 parent 1ede881 commit 86f84c7

File tree

5 files changed

+66
-16
lines changed

5 files changed

+66
-16
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "expo-native-dependency-hash",
3-
"version": "2.0.4",
3+
"version": "3.0.0",
44
"license": "MIT",
55
"author": {
66
"name": "Robert Herber",

src/cli.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ void yargs(hideBin(process.argv))
5858
describe: 'root directory of the app or library',
5959
default: '.',
6060
})
61+
.option('includeAppJson', {
62+
describe: 'include app.json in the hash',
63+
default: false,
64+
})
65+
.option('includeLocalNativeFolders', {
66+
describe: 'include iOS/Android contents in the hash',
67+
default: false,
68+
})
6169
.option('verbose', {
6270
alias: 'v',
6371
type: 'boolean',
@@ -99,6 +107,14 @@ void yargs(hideBin(process.argv))
99107
describe: 'root directory of the app or library',
100108
default: '.',
101109
})
110+
.option('includeAppJson', {
111+
describe: 'include app.json in the hash',
112+
default: false,
113+
})
114+
.option('includeLocalNativeFolders', {
115+
describe: 'include iOS/Android contents in the hash',
116+
default: false,
117+
})
102118
.option('verbose', {
103119
alias: 'v',
104120
type: 'boolean',
@@ -235,7 +251,7 @@ void yargs(hideBin(process.argv))
235251
console.log('list', argv);
236252
}
237253

238-
if (verbose) console.info(`getting dependency hash for native dependencies in: ${rootDir}`);
254+
if (verbose) console.info(`getting dependency hash for ${platform} native dependencies in: ${rootDir}`);
239255

240256
const allModules = await getModulesForPlatform(platform, rootDir);
241257

@@ -284,7 +300,7 @@ void yargs(hideBin(process.argv))
284300
console.log('expo-native-dependency-hash', argv);
285301
}
286302

287-
if (verbose) console.info(`getting dependency hash for native dependencies in: ${rootDir}`);
303+
if (verbose) console.info(`getting dependency hash for ${platform} native dependencies in: ${rootDir}`);
288304
const hash = await getCurrentHash(platform, {
289305
rootDir,
290306
verbose,

src/index.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('Tests', () => {
3636
isNativeIOS: false,
3737
name: 'android-module-with-hash',
3838
nativeDependencyHash: {
39-
ios: 'db408bcb42c49f4433aa8b5a95c083e8',
39+
ios: 'e399fe1305eb2b7a64ea3cb69d92a1f4',
4040
android: '636f80339c58196c102ec0f4c9878503',
4141
all: '636f80339c58196c102ec0f4c9878503',
4242
},
@@ -106,8 +106,8 @@ describe('Tests', () => {
106106
]);
107107
});
108108

109-
test('isGitDirty', () => {
110-
const isIt = isGitDirty('.');
109+
test('isGitDirty', async () => {
110+
const isIt = await isGitDirty('.');
111111
expect(isIt).toBe(false);
112112
});
113113

src/index.ts

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,16 @@ export const getFolderHash = async (platform: Platform, rootDir: string, verbose
9898

9999
// if there are no native folders, we don't need to hash anything
100100
if (!hasAndroidOrIOSFolders) {
101+
if (verbose) {
102+
console.log('Skipping native files because there are no iOS/Android folders');
103+
}
101104
return '';
102105
}
103106

107+
if (verbose) {
108+
console.log('Reading native files from git...');
109+
}
110+
104111
const gitFiles = await execAsync('git ls-tree -r HEAD --name-only', {
105112
cwd: rootDir,
106113
encoding: 'utf8',
@@ -236,13 +243,15 @@ const GENERATE_HASH_DEFAULTS: Required<GenerateHashOptions> = {
236243
skipNodeModules: false,
237244
verbose: false,
238245
skipAppJson: false,
246+
skipLocalNativeFolders: false,
239247
};
240248

241249
type GenerateHashOptions = {
242250
verbose?: boolean,
243251
rootDir?: string,
244252
skipNodeModules?: boolean,
245253
skipAppJson?: boolean,
254+
skipLocalNativeFolders?: boolean,
246255
};
247256

248257
// this is a list of properties that should be included, lets focus on not breaking things
@@ -344,8 +353,13 @@ export const getCurrentHash = async (platform: Platform, {
344353
skipNodeModules = GENERATE_HASH_DEFAULTS.skipNodeModules,
345354
verbose = GENERATE_HASH_DEFAULTS.verbose,
346355
skipAppJson = GENERATE_HASH_DEFAULTS.skipAppJson,
356+
skipLocalNativeFolders = GENERATE_HASH_DEFAULTS.skipLocalNativeFolders,
347357
}: GenerateHashOptions = GENERATE_HASH_DEFAULTS) => {
348-
const localNativeFoldersHash = await getFolderHash(platform, rootDir, verbose);
358+
if (verbose) {
359+
console.log(`Getting hash for platform: ${platform}`);
360+
}
361+
362+
const localNativeFoldersHash = skipLocalNativeFolders ? '' : await getFolderHash(platform, rootDir, verbose);
349363

350364
const appJsonContent = skipAppJson ? '' : await getAppJsonHash(platform, rootDir, verbose);
351365

@@ -355,7 +369,7 @@ export const getCurrentHash = async (platform: Platform, {
355369

356370
const nativeModuleIdentities = nativeModules.map(getModuleIdentity(platform));
357371
if (verbose && !skipNodeModules) {
358-
console.log(`Found ${nativeModules.length} native modules (out of ${nativeModules.length} total modules)\n${nativeModuleIdentities.join('\n')}`);
372+
console.log(`Found ${nativeModules.length} native ${platform === Platform.all ? '' : `${platform} `}modules (out of ${nativeModules.length} total modules)\n${nativeModuleIdentities.join('\n')}`);
359373
}
360374
const stringToHashFrom = `app.json@${appJsonContent};local@${localNativeFoldersHash};${nativeModuleIdentities.join(',')};plugins@${appPlugins}`;
361375

@@ -390,14 +404,23 @@ export async function verifyExpoApp(
390404
{
391405
verbose,
392406
rootDir,
407+
includeAppJson,
408+
includeLocalNativeFolders,
393409
}: {
394410
verbose: boolean;
395411
rootDir: string;
412+
includeLocalNativeFolders?: boolean;
413+
includeAppJson?: boolean;
396414
},
397415
) {
398-
if (verbose) { console.info(`getting dependency hash for native dependencies in: ${rootDir}`); }
416+
if (verbose) { console.info(`[expo-native-dependency-hash] verifying expo app in: ${rootDir}`); }
399417

400-
const { ios, android, all } = await generateHashes({ rootDir, verbose });
418+
const { ios, android, all } = await generateHashes({
419+
rootDir,
420+
verbose,
421+
skipAppJson: !includeAppJson,
422+
skipLocalNativeFolders: !includeLocalNativeFolders,
423+
});
401424

402425
let valueExists = false;
403426
let hasChanged = false;
@@ -434,27 +457,38 @@ export async function verifyExpoApp(
434457
}
435458
}
436459

437-
return { valueExists, hasChanged };
460+
return {
461+
valueExists, hasChanged, ios, android, all,
462+
};
438463
}
439464

440465
export async function updateExpoApp(
441466
{
442467
rootDir,
443468
verbose,
469+
includeAppJson,
470+
includeLocalNativeFolders,
444471
}: {
445472
rootDir: string;
446473
verbose: boolean;
474+
includeAppJson?: boolean;
475+
includeLocalNativeFolders?: boolean;
447476
},
448477
) {
449-
const { hasChanged, valueExists } = await verifyExpoApp({ rootDir, verbose });
478+
const {
479+
hasChanged, valueExists, ios, android, all,
480+
} = await verifyExpoApp({
481+
rootDir,
482+
verbose,
483+
includeAppJson,
484+
includeLocalNativeFolders,
485+
});
450486

451487
if (!hasChanged && valueExists) {
452488
console.log(green('Hashes already up to date'));
453489
return;
454490
}
455491

456-
const { ios, android, all } = await generateHashes({ rootDir, verbose });
457-
458492
try {
459493
const fileStr = await readFile(Path.join(rootDir, 'app.json'), 'utf8');
460494
const prevJson = JSON.parse(fileStr) as { expo: ExpoConfig };
@@ -480,7 +514,7 @@ export async function verifyLibrary(
480514
rootDir: string;
481515
},
482516
) {
483-
if (verbose) { console.info(`getting dependency hash for native dependencies in: ${rootDir}`); }
517+
if (verbose) { console.info(`[expo-native-dependency-hash] verifying library in: ${rootDir}`); }
484518

485519
const { ios, android, all } = await generateHashes({
486520
rootDir, verbose, skipNodeModules: true, skipAppJson: true,

src/testdata/node_modules/android-module-with-hash/package.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)