Skip to content

Commit 9f5d261

Browse files
committed
fix link handling
1 parent c556447 commit 9f5d261

3 files changed

Lines changed: 18 additions & 26 deletions

File tree

dev-packages/e2e-tests/lib/copyToTemp.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-console */
22
import { readFileSync, writeFileSync } from 'fs';
33
import { cp } from 'fs/promises';
4-
import { join } from 'path';
4+
import { isAbsolute, join } from 'path';
55

66
export async function copyToTemp(originalPath: string, tmpDirPath: string): Promise<void> {
77
// copy files to tmp dir
@@ -47,15 +47,22 @@ function fixPackageJson(cwd: string): void {
4747

4848
function fixFileLinkDependencies(dependencyObj: Record<string, string>): void {
4949
for (const [key, value] of Object.entries(dependencyObj)) {
50-
if (value.startsWith('link:')) {
51-
const dirPath = value.replace('link:', '');
52-
53-
// We add a virtual dir to ensure that the relative depth is consistent
54-
// dirPath is relative to ./../test-applications/xxx
55-
const newPath = join(__dirname, 'virtual-dir/', dirPath);
50+
const prefix = value.startsWith('link:') ? 'link:' : value.startsWith('file:') ? 'file:' : null;
51+
if (!prefix) {
52+
continue;
53+
}
5654

57-
dependencyObj[key] = `link:${newPath}`;
58-
console.log(`Fixed ${key} dependency to ${newPath}`);
55+
const dirPath = value.slice(prefix.length);
56+
if (isAbsolute(dirPath)) {
57+
continue;
5958
}
59+
60+
// We add a virtual dir to ensure that the relative depth is consistent
61+
// dirPath is relative to ./../test-applications/xxx
62+
const newPath = join(__dirname, 'virtual-dir/', dirPath);
63+
console.log({ key, value, newPath });
64+
65+
dependencyObj[key] = `${prefix}${newPath}`;
66+
console.log(`Fixed ${key} dependency to ${newPath}`);
6067
}
6168
}

dev-packages/e2e-tests/lib/packedTarballUtils.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,6 @@ export function versionedTarballFilename(packageName: string, version: string):
4444
return `${npmPackBasename(packageName)}-${version}.tgz`;
4545
}
4646

47-
/**
48-
* Relative POSIX path from `dev-packages/e2e-tests/packed/<symlink>` to
49-
* `packages/<pkgDir>/<versionedTarball>`.
50-
*/
51-
export function relativeTarballPathFromPackedDir(packageDirName: string, packageName: string, version: string): string {
52-
const file = versionedTarballFilename(packageName, version);
53-
return path.posix.join('..', '..', '..', 'packages', packageDirName, file);
54-
}
55-
5647
/**
5748
* npm pack tarball basename (without version and .tgz), e.g. `@sentry/core` -> `sentry-core`.
5849
*/

dev-packages/e2e-tests/lib/syncPackedTarballSymlinks.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22
import * as fs from 'fs';
33
import * as path from 'path';
44
import { sync as globSync } from 'glob';
5-
import {
6-
packedSymlinkFilename,
7-
relativeTarballPathFromPackedDir,
8-
versionedTarballFilename,
9-
} from './packedTarballUtils';
5+
import { packedSymlinkFilename, versionedTarballFilename } from './packedTarballUtils';
106

117
const e2eTestsRoot = path.resolve(__dirname, '..');
128
const repositoryRoot = path.resolve(e2eTestsRoot, '../..');
@@ -46,7 +42,6 @@ export function syncPackedTarballSymlinks(): void {
4642
}
4743

4844
const packageDir = path.dirname(packageJsonPath);
49-
const packageDirName = path.basename(packageDir);
5045
const expectedTarball = path.join(packageDir, versionedTarballFilename(name, version));
5146

5247
if (!fs.existsSync(expectedTarball)) {
@@ -55,9 +50,8 @@ export function syncPackedTarballSymlinks(): void {
5550

5651
const linkName = packedSymlinkFilename(name);
5752
const linkPath = path.join(packedDir, linkName);
58-
const target = relativeTarballPathFromPackedDir(packageDirName, name, version);
5953

60-
fs.symlinkSync(target, linkPath);
54+
fs.symlinkSync(expectedTarball, linkPath);
6155
linked++;
6256
}
6357

0 commit comments

Comments
 (0)