@expo/fingerprint 0.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.
Files changed (84) hide show
  1. package/.eslintignore +1 -0
  2. package/LICENSE +22 -0
  3. package/README.md +118 -0
  4. package/__mocks__/fs/promises.ts +2 -0
  5. package/__mocks__/fs.ts +2 -0
  6. package/babel.config.js +6 -0
  7. package/bin/cli.js +27 -0
  8. package/build/Dedup.d.ts +9 -0
  9. package/build/Dedup.js +83 -0
  10. package/build/Dedup.js.map +1 -0
  11. package/build/Fingerprint.d.ts +13 -0
  12. package/build/Fingerprint.js +42 -0
  13. package/build/Fingerprint.js.map +1 -0
  14. package/build/Fingerprint.types.d.ts +78 -0
  15. package/build/Fingerprint.types.js +4 -0
  16. package/build/Fingerprint.types.js.map +1 -0
  17. package/build/Options.d.ts +2 -0
  18. package/build/Options.js +23 -0
  19. package/build/Options.js.map +1 -0
  20. package/build/Sort.d.ts +2 -0
  21. package/build/Sort.js +27 -0
  22. package/build/Sort.js.map +1 -0
  23. package/build/hash/Hash.d.ts +28 -0
  24. package/build/hash/Hash.js +166 -0
  25. package/build/hash/Hash.js.map +1 -0
  26. package/build/index.d.ts +2 -0
  27. package/build/index.js +22 -0
  28. package/build/index.js.map +1 -0
  29. package/build/sourcer/Bare.d.ts +6 -0
  30. package/build/sourcer/Bare.js +107 -0
  31. package/build/sourcer/Bare.js.map +1 -0
  32. package/build/sourcer/Expo.d.ts +5 -0
  33. package/build/sourcer/Expo.js +175 -0
  34. package/build/sourcer/Expo.js.map +1 -0
  35. package/build/sourcer/PatchPackage.d.ts +2 -0
  36. package/build/sourcer/PatchPackage.js +19 -0
  37. package/build/sourcer/PatchPackage.js.map +1 -0
  38. package/build/sourcer/Sourcer.d.ts +2 -0
  39. package/build/sourcer/Sourcer.js +42 -0
  40. package/build/sourcer/Sourcer.js.map +1 -0
  41. package/build/sourcer/Utils.d.ts +2 -0
  42. package/build/sourcer/Utils.js +25 -0
  43. package/build/sourcer/Utils.js.map +1 -0
  44. package/build/utils/Profile.d.ts +8 -0
  45. package/build/utils/Profile.js +43 -0
  46. package/build/utils/Profile.js.map +1 -0
  47. package/e2e/__tests__/__snapshots__/managed-test.ts.snap +200 -0
  48. package/e2e/__tests__/bare-test.ts +66 -0
  49. package/e2e/__tests__/managed-test.ts +162 -0
  50. package/e2e/jest.config.js +10 -0
  51. package/jest.config.js +10 -0
  52. package/package.json +70 -0
  53. package/scripts/createFixture.ts +81 -0
  54. package/src/Dedup.ts +97 -0
  55. package/src/Fingerprint.ts +51 -0
  56. package/src/Fingerprint.types.ts +98 -0
  57. package/src/Options.ts +18 -0
  58. package/src/Sort.ts +22 -0
  59. package/src/__tests__/Dedup-test.ts +177 -0
  60. package/src/__tests__/Fingerprint-test.ts +116 -0
  61. package/src/__tests__/Sort-test.ts +56 -0
  62. package/src/hash/Hash.ts +204 -0
  63. package/src/hash/__tests__/Hash-test.ts +192 -0
  64. package/src/index.ts +3 -0
  65. package/src/sourcer/Bare.ts +114 -0
  66. package/src/sourcer/Expo.ts +216 -0
  67. package/src/sourcer/PatchPackage.ts +18 -0
  68. package/src/sourcer/Sourcer.ts +58 -0
  69. package/src/sourcer/Utils.ts +23 -0
  70. package/src/sourcer/__tests__/Bare-test.ts +59 -0
  71. package/src/sourcer/__tests__/Expo-test.ts +265 -0
  72. package/src/sourcer/__tests__/PatchPackage-test.ts +54 -0
  73. package/src/sourcer/__tests__/Sourcer-test.ts +14 -0
  74. package/src/sourcer/__tests__/__snapshots__/Bare-test.ts.snap +29 -0
  75. package/src/sourcer/__tests__/__snapshots__/Expo-test.ts.snap +139 -0
  76. package/src/sourcer/__tests__/fixtures/BareReactNative70Project.json +47 -0
  77. package/src/sourcer/__tests__/fixtures/ExpoAutolinkingAndroid.json +82 -0
  78. package/src/sourcer/__tests__/fixtures/ExpoAutolinkingIos.json +114 -0
  79. package/src/sourcer/__tests__/fixtures/ExpoManaged47Project.json +6 -0
  80. package/src/sourcer/__tests__/fixtures/PatchPackage.json +4 -0
  81. package/src/sourcer/__tests__/fixtures/RncliAutoLinking.json +165 -0
  82. package/src/utils/Profile.ts +47 -0
  83. package/src/utils/__tests__/Profile-test.ts +11 -0
  84. package/tsconfig.json +9 -0
package/.eslintignore ADDED
@@ -0,0 +1 @@
1
+ build
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-present 650 Industries, Inc. (aka Expo)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,118 @@
1
+ # @expo/fingerprint
2
+
3
+ A library to generate a fingerprint from a React Native project
4
+
5
+ ## Usage
6
+
7
+ ```ts
8
+ import * as Fingerprint from '@expo/fingerprint';
9
+
10
+ await Fingerprint.createFingerprintAsync('/projectRoot');
11
+ ```
12
+
13
+ ### `async function createFingerprintAsync(projectRoot: string, options?: Options): Promise<Fingerprint>`
14
+
15
+ Create a fingerprint from project
16
+
17
+ Example:
18
+
19
+ ```ts
20
+ const fingerprint = await createFingerprintAsync('/app');
21
+ console.log(fingerprint);
22
+ ```
23
+
24
+ ```json
25
+ {
26
+ "sources": [
27
+ {
28
+ "type": "file",
29
+ "filePath": "app.json",
30
+ "reasons": ["expoConfig"],
31
+ "hash": "378083de0c6e6bb6caf8fb72df658b0b26fb29ef"
32
+ },
33
+ {
34
+ "type": "file",
35
+ "filePath": "eas.json",
36
+ "reasons": ["easBuild"],
37
+ "hash": "f723802b6ea916d1a6c4767b2299cc81ddb22eb4"
38
+ },
39
+ {
40
+ "type": "dir",
41
+ "filePath": "node_modules/expo",
42
+ "reasons": ["expoAutolinkingIos", "expoAutolinkingAndroid", "bareRncliAutolinking"],
43
+ "hash": "1faee4057fa943300905750b51c3b0cbf05f4b0d"
44
+ }
45
+ ],
46
+ "hash": "bf8a3b08935f056270b1688333b02f1ef5fa25bf"
47
+ }
48
+ ```
49
+
50
+ ### `async function createProjectHashAsync(projectRoot: string, options?: Options): Promise<string>`
51
+
52
+ Create a native hash value from project
53
+
54
+ Example:
55
+
56
+ ```ts
57
+ const hash = await createProjectHashAsync('/app');
58
+ console.log(hash);
59
+ ```
60
+
61
+ ```json
62
+ bf8a3b08935f056270b1688333b02f1ef5fa25bf
63
+ ```
64
+
65
+ ### `diffFingerprintChangesAsync(fingerprint: Fingerprint, projectRoot: string, options?: Options): Promise<FingerprintSource[]>`
66
+
67
+ Differentiate given `fingerprint` with the current project fingerprint state
68
+
69
+ Example:
70
+
71
+ ```ts
72
+ const fingerprint = {
73
+ sources: [
74
+ {
75
+ type: 'file',
76
+ filePath: 'app.json',
77
+ reasons: ['expoConfig'],
78
+ hash: '378083de0c6e6bb6caf8fb72df658b0b26fb29ef',
79
+ },
80
+ {
81
+ type: 'file',
82
+ filePath: 'eas.json',
83
+ reasons: ['easBuild'],
84
+ hash: 'f723802b6ea916d1a6c4767b2299cc81ddb22eb4',
85
+ },
86
+ {
87
+ type: 'dir',
88
+ filePath: 'node_modules/expo',
89
+ reasons: ['expoAutolinkingIos', 'expoAutolinkingAndroid', 'bareRncliAutolinking'],
90
+ hash: '1faee4057fa943300905750b51c3b0cbf05f4b0d',
91
+ },
92
+ ],
93
+ hash: 'bf8a3b08935f056270b1688333b02f1ef5fa25bf',
94
+ };
95
+ const result = await diffFingerprintChangesAsync(fingerprint, '/app');
96
+ console.log(result);
97
+ ```
98
+
99
+ ```json
100
+ [
101
+ {
102
+ "filePath": "ios",
103
+ "hash": "e4190c0af9142fe4add4842777d9aec713213cd4",
104
+ "reasons": ["bareNativeDir"],
105
+ "type": "dir"
106
+ },
107
+ {
108
+ "filePath": "app.json",
109
+ "hash": "9ff1b51ca9b9435e8b849bcc82e3900d70f0feee",
110
+ "reasons": ["expoConfig"],
111
+ "type": "file"
112
+ }
113
+ ]
114
+ ```
115
+
116
+ ## CLI Usage
117
+
118
+ `npx @expo/fingerprint /path/to/projectRoot`
@@ -0,0 +1,2 @@
1
+ import { fs } from 'memfs';
2
+ module.exports = fs.promises;
@@ -0,0 +1,2 @@
1
+ import { fs } from 'memfs';
2
+ module.exports = fs;
@@ -0,0 +1,6 @@
1
+ module.exports = function (api) {
2
+ api.cache(true);
3
+ return {
4
+ presets: ['@expo/babel-preset-cli'],
5
+ };
6
+ };
package/bin/cli.js ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+ const path = require('path');
3
+
4
+ let Fingerprint;
5
+ try {
6
+ Fingerprint = require('@expo/fingerprint');
7
+ } catch {}
8
+ if (!Fingerprint) {
9
+ Fingerprint = require(path.join(__dirname, '..', 'build', 'index'));
10
+ }
11
+
12
+ (async () => {
13
+ if (process.argv.length !== 3) {
14
+ console.log(`Usage: ${path.basename(process.argv[1])} projectRoot`);
15
+ process.exit(1);
16
+ }
17
+ const projectRoot = process.argv[2];
18
+
19
+ try {
20
+ const fingerprint = await Fingerprint.createFingerprintAsync(projectRoot);
21
+ console.log(JSON.stringify(fingerprint, null, 2));
22
+ // console.log(fingerprint.hash);
23
+ } catch (e) {
24
+ console.error('Uncaught Error', e);
25
+ process.exit(1);
26
+ }
27
+ })();
@@ -0,0 +1,9 @@
1
+ import type { HashSource } from './Fingerprint.types';
2
+ /**
3
+ * Strip duplicated sources, mainly for duplicated file or dir
4
+ */
5
+ export declare function dedupSources(sources: HashSource[], projectRoot: string): HashSource[];
6
+ /**
7
+ * When two sources are duplicated, merge `src`'s reasons into `dst`
8
+ */
9
+ export declare function mergeSourceWithReasons(dst: HashSource, src: HashSource): HashSource;
package/build/Dedup.js ADDED
@@ -0,0 +1,83 @@
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.mergeSourceWithReasons = exports.dedupSources = void 0;
7
+ const assert_1 = __importDefault(require("assert"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const debug = require('debug')('expo:fingerprint:Dedup');
10
+ /**
11
+ * Strip duplicated sources, mainly for duplicated file or dir
12
+ */
13
+ function dedupSources(sources, projectRoot) {
14
+ const newSources = [];
15
+ for (const source of sources) {
16
+ const [duplicatedItemIndex, shouldSwapSource] = findDuplicatedSourceIndex(newSources, source, projectRoot);
17
+ if (duplicatedItemIndex >= 0) {
18
+ const duplicatedItem = newSources[duplicatedItemIndex];
19
+ debug(`Skipping duplicated source: ${source}`);
20
+ if (shouldSwapSource) {
21
+ newSources[duplicatedItemIndex] = {
22
+ ...source,
23
+ reasons: [...source.reasons, ...duplicatedItem.reasons],
24
+ };
25
+ }
26
+ else {
27
+ duplicatedItem.reasons.push(...source.reasons);
28
+ }
29
+ }
30
+ else {
31
+ newSources.push(source);
32
+ }
33
+ }
34
+ return newSources;
35
+ }
36
+ exports.dedupSources = dedupSources;
37
+ /**
38
+ * When two sources are duplicated, merge `src`'s reasons into `dst`
39
+ */
40
+ function mergeSourceWithReasons(dst, src) {
41
+ return dst;
42
+ }
43
+ exports.mergeSourceWithReasons = mergeSourceWithReasons;
44
+ /**
45
+ * Find the duplicated `source` in `newSources`
46
+ * @return tuple of [duplicatedItemIndexInNewSources, shouldSwapSource]
47
+ */
48
+ function findDuplicatedSourceIndex(newSources, source, projectRoot) {
49
+ let shouldSwapSource = false;
50
+ if (source.type === 'contents') {
51
+ return [
52
+ newSources.findIndex((item) => item.type === source.type && item.id === source.id) ?? null,
53
+ shouldSwapSource,
54
+ ];
55
+ }
56
+ for (const [index, existingSource] of newSources.entries()) {
57
+ if (existingSource.type === 'contents') {
58
+ continue;
59
+ }
60
+ if (isDescendant(source, existingSource, projectRoot)) {
61
+ return [index, shouldSwapSource];
62
+ }
63
+ // If the new source is ancestor of existing source, replace swap the existing source with the new source
64
+ if (isDescendant(existingSource, source, projectRoot)) {
65
+ shouldSwapSource = true;
66
+ return [index, shouldSwapSource];
67
+ }
68
+ }
69
+ return [-1, shouldSwapSource];
70
+ }
71
+ function isDescendant(from, to, projectRoot) {
72
+ if (from === to) {
73
+ return true;
74
+ }
75
+ const fromPath = path_1.default.join(projectRoot, from.filePath);
76
+ const toPath = path_1.default.join(projectRoot, to.filePath);
77
+ const result = path_1.default.relative(fromPath, toPath).match(/^[./\\/]*$/) != null;
78
+ if (result) {
79
+ (0, assert_1.default)(!(to.type === 'file' && from.type === 'dir'), `Unexpected case which a dir is a descendant of a file - from[${fromPath}] to[${toPath}]`);
80
+ }
81
+ return result;
82
+ }
83
+ //# sourceMappingURL=Dedup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Dedup.js","sourceRoot":"","sources":["../src/Dedup.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,13 @@
1
+ import type { Fingerprint, FingerprintSource, Options } from './Fingerprint.types';
2
+ /**
3
+ * Create a fingerprint from project
4
+ */
5
+ export declare function createFingerprintAsync(projectRoot: string, options?: Options): Promise<Fingerprint>;
6
+ /**
7
+ * Create a native hash value from project
8
+ */
9
+ export declare function createProjectHashAsync(projectRoot: string, options?: Options): Promise<string>;
10
+ /**
11
+ * Differentiate given `fingerprint` with the current project fingerprint state
12
+ */
13
+ export declare function diffFingerprintChangesAsync(fingerprint: Fingerprint, projectRoot: string, options?: Options): Promise<FingerprintSource[]>;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.diffFingerprintChangesAsync = exports.createProjectHashAsync = exports.createFingerprintAsync = void 0;
4
+ const Dedup_1 = require("./Dedup");
5
+ const Options_1 = require("./Options");
6
+ const Sort_1 = require("./Sort");
7
+ const Hash_1 = require("./hash/Hash");
8
+ const Sourcer_1 = require("./sourcer/Sourcer");
9
+ /**
10
+ * Create a fingerprint from project
11
+ */
12
+ async function createFingerprintAsync(projectRoot, options) {
13
+ const opts = (0, Options_1.normalizeOptions)(options);
14
+ const sources = await (0, Sourcer_1.getHashSourcesAsync)(projectRoot, opts);
15
+ const normalizedSources = (0, Sort_1.sortSources)((0, Dedup_1.dedupSources)(sources, projectRoot));
16
+ const fingerprint = await (0, Hash_1.createFingerprintFromSourcesAsync)(normalizedSources, projectRoot, opts);
17
+ return fingerprint;
18
+ }
19
+ exports.createFingerprintAsync = createFingerprintAsync;
20
+ /**
21
+ * Create a native hash value from project
22
+ */
23
+ async function createProjectHashAsync(projectRoot, options) {
24
+ const fingerprint = await createFingerprintAsync(projectRoot, options);
25
+ return fingerprint.hash;
26
+ }
27
+ exports.createProjectHashAsync = createProjectHashAsync;
28
+ /**
29
+ * Differentiate given `fingerprint` with the current project fingerprint state
30
+ */
31
+ async function diffFingerprintChangesAsync(fingerprint, projectRoot, options) {
32
+ const newFingerprint = await createFingerprintAsync(projectRoot, options);
33
+ if (fingerprint.hash === newFingerprint.hash) {
34
+ return [];
35
+ }
36
+ const result = newFingerprint.sources.filter((newItem) => {
37
+ return !fingerprint.sources.find((item) => item.type === newItem.type && item.hash === newItem.hash);
38
+ });
39
+ return result;
40
+ }
41
+ exports.diffFingerprintChangesAsync = diffFingerprintChangesAsync;
42
+ //# sourceMappingURL=Fingerprint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Fingerprint.js","sourceRoot":"","sources":["../src/Fingerprint.ts"],"names":[],"mappings":";;;AAAA,mCAAuC;AAEvC,uCAA6C;AAC7C,iCAAqC;AACrC,sCAAgE;AAChE,+CAAwD;AAExD;;GAEG;AACI,KAAK,UAAU,sBAAsB,CAC1C,WAAmB,EACnB,OAAiB;IAEjB,MAAM,IAAI,GAAG,IAAA,0BAAgB,EAAC,OAAO,CAAC,CAAC;IACvC,MAAM,OAAO,GAAG,MAAM,IAAA,6BAAmB,EAAC,WAAW,EAAE,IAAI,CAAC,CAAC;IAC7D,MAAM,iBAAiB,GAAG,IAAA,kBAAW,EAAC,IAAA,oBAAY,EAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC;IAC1E,MAAM,WAAW,GAAG,MAAM,IAAA,wCAAiC,EAAC,iBAAiB,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;IAClG,OAAO,WAAW,CAAC;AACrB,CAAC;AATD,wDASC;AAED;;GAEG;AACI,KAAK,UAAU,sBAAsB,CAC1C,WAAmB,EACnB,OAAiB;IAEjB,MAAM,WAAW,GAAG,MAAM,sBAAsB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IACvE,OAAO,WAAW,CAAC,IAAI,CAAC;AAC1B,CAAC;AAND,wDAMC;AAED;;GAEG;AACI,KAAK,UAAU,2BAA2B,CAC/C,WAAwB,EACxB,WAAmB,EACnB,OAAiB;IAEjB,MAAM,cAAc,GAAG,MAAM,sBAAsB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAC1E,IAAI,WAAW,CAAC,IAAI,KAAK,cAAc,CAAC,IAAI,EAAE;QAC5C,OAAO,EAAE,CAAC;KACX;IACD,MAAM,MAAM,GAAwB,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE;QAC5E,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAC9B,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,CACnE,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC;AAfD,kEAeC"}
@@ -0,0 +1,78 @@
1
+ /// <reference types="node" />
2
+ export type FingerprintSource = HashSource & {
3
+ /**
4
+ * Hash value of the `source`.
5
+ * If the source is excluding by `Options.dirExcludes`, the value will be null.
6
+ */
7
+ hash: string | null;
8
+ };
9
+ export interface Fingerprint {
10
+ /**
11
+ * Sources and their hash values to generate a fingerprint
12
+ */
13
+ sources: FingerprintSource[];
14
+ /**
15
+ * The final hash value of the whole fingerprint
16
+ */
17
+ hash: string;
18
+ }
19
+ export type Platform = 'android' | 'ios';
20
+ export interface Options {
21
+ /**
22
+ * Only get native files from the given platforms. Default is `['android', 'ios']`.
23
+ */
24
+ platforms?: Platform[];
25
+ /**
26
+ * I/O concurrent limit. Default is the number of CPU core.
27
+ */
28
+ concurrentIoLimit?: number;
29
+ /**
30
+ * The algorithm passing to `crypto.createHash()`. Default is `'sha1'`.
31
+ */
32
+ hashAlgorithm?: string;
33
+ /**
34
+ * Excludes directories from hashing. This supported pattern is as `glob()`.
35
+ * Default is `['android/build', 'android/app/build', 'android/app/.cxx', 'ios/Pods']`.
36
+ */
37
+ dirExcludes?: string[];
38
+ /**
39
+ * Additional sources for hashing.
40
+ */
41
+ extraSources?: HashSource[];
42
+ }
43
+ export interface NormalizedOptions extends Options {
44
+ platforms: NonNullable<Options['platforms']>;
45
+ concurrentIoLimit: NonNullable<Options['concurrentIoLimit']>;
46
+ hashAlgorithm: NonNullable<Options['hashAlgorithm']>;
47
+ dirExcludes: NonNullable<Options['dirExcludes']>;
48
+ }
49
+ export interface HashSourceFile {
50
+ type: 'file';
51
+ filePath: string;
52
+ /**
53
+ * Reasons of this source coming from
54
+ */
55
+ reasons: string[];
56
+ }
57
+ export interface HashSourceDir {
58
+ type: 'dir';
59
+ filePath: string;
60
+ /**
61
+ * Reasons of this source coming from
62
+ */
63
+ reasons: string[];
64
+ }
65
+ export interface HashSourceContents {
66
+ type: 'contents';
67
+ id: string;
68
+ contents: string | Buffer;
69
+ /**
70
+ * Reasons of this source coming from
71
+ */
72
+ reasons: string[];
73
+ }
74
+ export type HashSource = HashSourceFile | HashSourceDir | HashSourceContents;
75
+ export interface HashResult {
76
+ id: string;
77
+ hex: string;
78
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //#endregion
4
+ //# sourceMappingURL=Fingerprint.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Fingerprint.types.js","sourceRoot":"","sources":["../src/Fingerprint.types.ts"],"names":[],"mappings":";;AAiGA,YAAY"}
@@ -0,0 +1,2 @@
1
+ import type { NormalizedOptions, Options } from './Fingerprint.types';
2
+ export declare function normalizeOptions(options?: Options): NormalizedOptions;
@@ -0,0 +1,23 @@
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.normalizeOptions = void 0;
7
+ const os_1 = __importDefault(require("os"));
8
+ function normalizeOptions(options) {
9
+ return {
10
+ ...options,
11
+ platforms: options?.platforms ?? ['android', 'ios'],
12
+ concurrentIoLimit: options?.concurrentIoLimit ?? os_1.default.cpus().length,
13
+ hashAlgorithm: options?.hashAlgorithm ?? 'sha1',
14
+ dirExcludes: options?.dirExcludes ?? [
15
+ '**/android/build',
16
+ '**/android/app/build',
17
+ '**/android/app/.cxx',
18
+ 'ios/Pods',
19
+ ],
20
+ };
21
+ }
22
+ exports.normalizeOptions = normalizeOptions;
23
+ //# sourceMappingURL=Options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Options.js","sourceRoot":"","sources":["../src/Options.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AAIpB,SAAgB,gBAAgB,CAAC,OAAiB;IAChD,OAAO;QACL,GAAG,OAAO;QACV,SAAS,EAAE,OAAO,EAAE,SAAS,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC;QACnD,iBAAiB,EAAE,OAAO,EAAE,iBAAiB,IAAI,YAAE,CAAC,IAAI,EAAE,CAAC,MAAM;QACjE,aAAa,EAAE,OAAO,EAAE,aAAa,IAAI,MAAM;QAC/C,WAAW,EAAE,OAAO,EAAE,WAAW,IAAI;YACnC,kBAAkB;YAClB,sBAAsB;YACtB,qBAAqB;YACrB,UAAU;SACX;KACF,CAAC;AACJ,CAAC;AAbD,4CAaC"}
@@ -0,0 +1,2 @@
1
+ import type { HashSource } from './Fingerprint.types';
2
+ export declare function sortSources<T extends HashSource>(sources: T[]): T[];
package/build/Sort.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sortSources = void 0;
4
+ function sortSources(sources) {
5
+ const typeOrder = {
6
+ file: 0,
7
+ dir: 1,
8
+ contents: 2,
9
+ };
10
+ return sources.sort((a, b) => {
11
+ const typeResult = typeOrder[a.type] - typeOrder[b.type];
12
+ if (typeResult === 0) {
13
+ if (a.type === 'file' && b.type === 'file') {
14
+ return a.filePath.localeCompare(b.filePath);
15
+ }
16
+ else if (a.type === 'dir' && b.type === 'dir') {
17
+ return a.filePath.localeCompare(b.filePath);
18
+ }
19
+ else if (a.type === 'contents' && b.type === 'contents') {
20
+ return a.id.localeCompare(b.id);
21
+ }
22
+ }
23
+ return typeResult;
24
+ });
25
+ }
26
+ exports.sortSources = sortSources;
27
+ //# sourceMappingURL=Sort.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Sort.js","sourceRoot":"","sources":["../src/Sort.ts"],"names":[],"mappings":";;;AAEA,SAAgB,WAAW,CAAuB,OAAY;IAC5D,MAAM,SAAS,GAAG;QAChB,IAAI,EAAE,CAAC;QACP,GAAG,EAAE,CAAC;QACN,QAAQ,EAAE,CAAC;KACZ,CAAC;IACF,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QAC3B,MAAM,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACzD,IAAI,UAAU,KAAK,CAAC,EAAE;YACpB,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,EAAE;gBAC1C,OAAO,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;aAC7C;iBAAM,IAAI,CAAC,CAAC,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,IAAI,KAAK,KAAK,EAAE;gBAC/C,OAAO,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;aAC7C;iBAAM,IAAI,CAAC,CAAC,IAAI,KAAK,UAAU,IAAI,CAAC,CAAC,IAAI,KAAK,UAAU,EAAE;gBACzD,OAAO,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;aACjC;SACF;QACD,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC,CAAC;AACL,CAAC;AAnBD,kCAmBC"}
@@ -0,0 +1,28 @@
1
+ import pLimit from 'p-limit';
2
+ import type { Fingerprint, FingerprintSource, HashResult, HashSource, HashSourceContents, NormalizedOptions } from '../Fingerprint.types';
3
+ /**
4
+ * Create a `Fingerprint` from `HashSources` array
5
+ */
6
+ export declare function createFingerprintFromSourcesAsync(sources: HashSource[], projectRoot: string, options: NormalizedOptions): Promise<Fingerprint>;
7
+ /**
8
+ * Create a `FingerprintSource` from a `HashSource`
9
+ * This function will get a hash value and merge back to original source
10
+ */
11
+ export declare function createFingerprintSourceAsync(source: HashSource, limiter: pLimit.Limit, projectRoot: string, options: NormalizedOptions): Promise<FingerprintSource>;
12
+ /**
13
+ * Create a `HashResult` from a file
14
+ */
15
+ export declare function createFileHashResultsAsync(filePath: string, limiter: pLimit.Limit, projectRoot: string, options: NormalizedOptions): Promise<HashResult>;
16
+ /**
17
+ * Create `HashResult` for a dir.
18
+ * If the dir is excluded, returns null rather than a HashResult
19
+ */
20
+ export declare function createDirHashResultsAsync(dirPath: string, limiter: pLimit.Limit, projectRoot: string, options: NormalizedOptions, depth?: number): Promise<HashResult | null>;
21
+ /**
22
+ * Create `HashResult` for a `HashSourceContents`
23
+ */
24
+ export declare function createContentsHashResultsAsync(source: HashSourceContents, options: NormalizedOptions): Promise<HashResult>;
25
+ /**
26
+ * Create id from given source
27
+ */
28
+ export declare function createSourceId(source: HashSource): string;