Skip to content

Commit b555691

Browse files
authored
Merge pull request #15 from bluesky-social/d/pnpm
Update fingerprint-native script to better support pnpm
2 parents ebc6aa6 + af4a0fc commit b555691

3 files changed

Lines changed: 57 additions & 16 deletions

File tree

build/fingerprint-native/index.js

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125609,15 +125609,26 @@ const github_1 = __nccwpck_require__(95438);
125609125609
const fingerprint_1 = __nccwpck_require__(3596);
125610125610
const fs_1 = __nccwpck_require__(57147);
125611125611
const { readFile, stat } = fs_1.promises;
125612+
const packageManagerName = (field) => {
125613+
if (typeof field === 'string')
125614+
return field;
125615+
if (Array.isArray(field))
125616+
return packageManagerName(field[0]);
125617+
if (typeof field === 'object' && field !== null) {
125618+
return field.name;
125619+
}
125620+
return undefined;
125621+
};
125612125622
const detectPackageManager = async () => {
125613125623
try {
125614125624
const pkg = JSON.parse(await readFile('package.json', 'utf8'));
125615-
const field = pkg.packageManager;
125616-
if (field?.startsWith('pnpm@'))
125625+
const name = packageManagerName(pkg.packageManager) ??
125626+
packageManagerName(pkg.devEngines?.packageManager);
125627+
if (name?.startsWith('pnpm'))
125617125628
return 'pnpm';
125618-
if (field?.startsWith('npm@'))
125629+
if (name?.startsWith('npm'))
125619125630
return 'npm';
125620-
if (field?.startsWith('yarn@'))
125631+
if (name?.startsWith('yarn'))
125621125632
return 'yarn';
125622125633
}
125623125634
catch {
@@ -125642,16 +125653,21 @@ const detectPackageManager = async () => {
125642125653
};
125643125654
const runInstall = async (pm) => {
125644125655
if (pm === 'pnpm') {
125645-
await (0, exec_1.exec)('corepack enable');
125656+
await (0, exec_1.exec)('npm install -g pnpm@11.5.3'); // > 10.21.0 will defer to `packageMananger` version.
125646125657
await (0, exec_1.exec)('pnpm install --frozen-lockfile');
125647125658
}
125648125659
else if (pm === 'npm') {
125649125660
await (0, exec_1.exec)('npm ci');
125650125661
}
125651125662
else {
125652-
await (0, exec_1.exec)('yarn install');
125663+
await (0, exec_1.exec)('yarn install --frozen-lockfile');
125653125664
}
125654125665
};
125666+
const fingerprintCommand = (pm) => {
125667+
if (pm === 'pnpm')
125668+
return 'pnpm dlx @expo/fingerprint .';
125669+
return 'npx @expo/fingerprint .';
125670+
};
125655125671
let info = {
125656125672
currentCommit: undefined,
125657125673
previousCommit: undefined,
@@ -125729,10 +125745,14 @@ const getPrevFP = async () => {
125729125745
}
125730125746
info.previousCommit = stdout.trim();
125731125747
}
125748+
if (!info.previousCommit) {
125749+
(0, core_1.setFailed)('Previous commit not found. Aborting.');
125750+
return false;
125751+
}
125732125752
await checkoutCommit(info.previousCommit);
125733125753
const pm = await detectPackageManager();
125734125754
await runInstall(pm);
125735-
const { stdout } = await (0, exec_1.getExecOutput)(`npx @expo/fingerprint .`);
125755+
const { stdout } = await (0, exec_1.getExecOutput)(fingerprintCommand(pm));
125736125756
info.previousFingerprint = JSON.parse(stdout.trim());
125737125757
return true;
125738125758
};

src/fingerprint-native/index.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,24 @@ const {readFile, stat} = promises
99

1010
type PackageManager = 'yarn' | 'pnpm' | 'npm'
1111

12+
const packageManagerName = (field: unknown): string | undefined => {
13+
if (typeof field === 'string') return field
14+
if (Array.isArray(field)) return packageManagerName(field[0])
15+
if (typeof field === 'object' && field != null) {
16+
return (field as {name?: string}).name
17+
}
18+
return undefined
19+
}
20+
1221
const detectPackageManager = async (): Promise<PackageManager> => {
1322
try {
1423
const pkg = JSON.parse(await readFile('package.json', 'utf8'))
15-
const field: string | undefined = pkg.packageManager
16-
if (field?.startsWith('pnpm@')) return 'pnpm'
17-
if (field?.startsWith('npm@')) return 'npm'
18-
if (field?.startsWith('yarn@')) return 'yarn'
24+
const name =
25+
packageManagerName(pkg.packageManager) ??
26+
packageManagerName(pkg.devEngines?.packageManager)
27+
if (name?.startsWith('pnpm')) return 'pnpm'
28+
if (name?.startsWith('npm')) return 'npm'
29+
if (name?.startsWith('yarn')) return 'yarn'
1930
} catch {
2031
// fall through
2132
}
@@ -37,15 +48,20 @@ const detectPackageManager = async (): Promise<PackageManager> => {
3748

3849
const runInstall = async (pm: PackageManager) => {
3950
if (pm === 'pnpm') {
40-
await exec('corepack enable')
51+
await exec('npm install -g pnpm@11.5.3') // > 10.21.0 will defer to `packageManager` version.
4152
await exec('pnpm install --frozen-lockfile')
4253
} else if (pm === 'npm') {
4354
await exec('npm ci')
4455
} else {
45-
await exec('yarn install')
56+
await exec('yarn install --frozen-lockfile')
4657
}
4758
}
4859

60+
const fingerprintCommand = (pm: PackageManager): string => {
61+
if (pm === 'pnpm') return 'pnpm dlx @expo/fingerprint .'
62+
return 'npx @expo/fingerprint .'
63+
}
64+
4965
type Info = {
5066
currentCommit?: string
5167
previousCommit?: string
@@ -152,11 +168,15 @@ const getPrevFP = async () => {
152168
info.previousCommit = stdout.trim()
153169
}
154170

171+
if (!info.previousCommit) {
172+
setFailed('Previous commit not found. Aborting.')
173+
return false
174+
}
155175
await checkoutCommit(info.previousCommit)
156176
const pm = await detectPackageManager()
157177
await runInstall(pm)
158178

159-
const {stdout} = await getExecOutput(`npx @expo/fingerprint .`)
179+
const {stdout} = await getExecOutput(fingerprintCommand(pm))
160180

161181
info.previousFingerprint = JSON.parse(stdout.trim())
162182
return true

tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
"compilerOptions": {
33
"jsx": "react-jsx",
44
"module": "CommonJS",
5-
"moduleResolution": "node",
5+
"skipLibCheck": true,
66
"types": ["node"],
77
"paths": {
88
"#fingerprint-native/*": ["./src/fingerprint-native*"],
99
"#fingerprint-native-post/*": ["./src/fingerprint-native-post*"]
1010
},
11-
"outDir": "./build",
11+
"rootDir": "./src/fingerprint-native",
12+
"outDir": "./build"
1213
},
1314
"exclude": ["build", "node_modules"]
1415
}

0 commit comments

Comments
 (0)