Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: opaque symlink support #7549

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/jest-haste-map/package.json
Expand Up @@ -19,6 +19,7 @@
"jest-util": "^24.9.0",
"jest-worker": "^24.9.0",
"micromatch": "^3.1.10",
"realpath-native": "^1.0.0",
"sane": "^4.0.3",
"walker": "^1.0.7"
},
Expand Down
30 changes: 28 additions & 2 deletions packages/jest-haste-map/src/HasteFS.ts
Expand Up @@ -5,20 +5,32 @@
* LICENSE file in the root directory of this source tree.
*/

import path from 'path';
import micromatch from 'micromatch';
import {sync as realpath} from 'realpath-native';
import {replacePathSepForGlob} from 'jest-util';
import {Config} from '@jest/types';
import {FileData} from './types';
import {FileData, LinkData} from './types';
import * as fastPath from './lib/fast_path';
import H from './constants';

export default class HasteFS {
private readonly _rootDir: Config.Path;
private readonly _files: FileData;
private readonly _links: LinkData;

constructor({rootDir, files}: {rootDir: Config.Path; files: FileData}) {
constructor({
rootDir,
files,
links,
}: {
rootDir: Config.Path;
files: FileData;
links: LinkData;
}) {
this._rootDir = rootDir;
this._files = files;
this._links = links;
}

getModuleName(file: Config.Path): string | null {
Expand Down Expand Up @@ -52,6 +64,20 @@ export default class HasteFS {
return this._getFileData(file) != null;
}

follow(file: Config.Path): Config.Path {
const name = fastPath.relative(this._rootDir, file);
const link = this._links.get(name);
if (!link) {
return file;
}
if (!link[0]) {
const target = realpath(file);
link[0] = fastPath.relative(this._rootDir, target);
return target;
}
return path.join(this._rootDir, link[0]);
}

getAllFiles(): Array<Config.Path> {
return Array.from(this.getAbsoluteFileIterator());
}
Expand Down
5 changes: 1 addition & 4 deletions packages/jest-haste-map/src/__tests__/index.test.js
Expand Up @@ -102,6 +102,7 @@ jest.mock('graceful-fs', () => ({
error.code = 'ENOENT';
throw error;
}),
realpath: jest.fn(path => path),
writeFileSync: jest.fn((path, data, options) => {
expect(options).toBe(require('v8').serialize ? undefined : 'utf8');
mockFs[path] = data;
Expand Down Expand Up @@ -224,8 +225,6 @@ describe('HasteMap', () => {

it('creates valid cache file paths', () => {
jest.resetModuleRegistry();
HasteMap = require('../');

expect(
HasteMap.getCacheFilePath('/', '@scoped/package', 'random-value'),
).toMatch(/^\/-scoped-package-(.*)$/);
Expand All @@ -241,7 +240,6 @@ describe('HasteMap', () => {

it('creates different cache file paths for different dependency extractor cache keys', () => {
jest.resetModuleRegistry();
const HasteMap = require('../');
const dependencyExtractor = require('./dependencyExtractor');
const config = {
...defaultConfig,
Expand All @@ -256,7 +254,6 @@ describe('HasteMap', () => {

it('creates different cache file paths for different hasteImplModulePath cache keys', () => {
jest.resetModuleRegistry();
const HasteMap = require('../');
const hasteImpl = require('./haste_impl');
hasteImpl.setCacheKey('foo');
const hasteMap1 = new HasteMap(defaultConfig);
Expand Down