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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inconsistent filesystem state after a Haste collision #1399

Closed
wants to merge 2 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions packages/metro-file-map/src/__tests__/index-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2059,6 +2059,61 @@ describe('FileMap', () => {
}
}

fm_it(
'does not throw on a duplicate created at runtime even if throwOnModuleCollision: true',
async hm => {
mockFs[path.join('/', 'project', 'fruits', 'Pear.js')] = `
// Pear!
`;
mockFs[path.join('/', 'project', 'fruits', 'another', 'Pear.js')] = `
// Pear too!
`;
const {fileSystem} = await hm.build();
const e = mockEmitters[path.join('/', 'project', 'fruits')];
e.emit(
'all',
'change',
'Pear.js',
path.join('/', 'project', 'fruits'),
MOCK_CHANGE_FILE,
);
e.emit(
'all',
'add',
'Pear.js',
path.join('/', 'project', 'fruits', 'another'),
MOCK_CHANGE_FILE,
);
await new Promise((resolve, reject) => {
console.error.mockImplementationOnce(() => {
reject(new Error('should not print error'));
});
hm.once('change', resolve);
});
// Expect a warning to be printed, but no error.
expect(console.warn).toHaveBeenCalledWith(
expect.stringContaining(
'metro-file-map: Haste module naming collision: Pear',
),
);
// Both files should be added to the fileSystem, despite the Haste
// collision
expect(
fileSystem.exists(path.join('/', 'project', 'fruits', 'Pear.js')),
).toBe(true);
expect(
fileSystem.exists(
path.join('/', 'project', 'fruits', 'another', 'Pear.js'),
),
).toBe(true);
},
{
config: {
throwOnModuleCollision: true,
},
},
);

fm_it(
'recovers when the oldest version of the duplicates is fixed',
async hm => {
Expand Down
1 change: 1 addition & 0 deletions packages/metro-file-map/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,7 @@ export default class FileMap extends EventEmitter {
// In watch mode, we'll only warn about module collisions and we'll retain
// all files, even changes to node_modules.
this._options.throwOnModuleCollision = false;
hasteMap.setThrowOnModuleCollision(false);
this._options.retainAllFiles = true;

const hasWatchedExtension = (filePath: string) =>
Expand Down
Loading