1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00

Flask devx fix (#13280)

* added fix for snaps devx issue

* reordered lines

* updated comment

* added test that ensures removeFencedCode detects a file with sourceMap inclusion

* fixed test

* Update development/build/transforms/remove-fenced-code.test.js

Co-authored-by: Erik Marks <25517051+rekmarks@users.noreply.github.com>
This commit is contained in:
Hassan Malik 2022-01-12 09:37:29 -08:00 committed by GitHub
parent 05f9ceda77
commit ff27f24ef9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View File

@ -200,9 +200,19 @@ const directiveParsingRegex = /^([A-Z]+):([A-Z_]+)(?:\(((?:\w+,)*\w+)\))?$/u;
* a boolean indicating whether they were modified.
*/
function removeFencedCode(filePath, typeOfCurrentBuild, fileContent) {
const matchedLines = [...fileContent.matchAll(linesWithFenceRegex)];
// Do not modify the file if we detect an inline sourcemap. For reasons
// yet to be determined, the transform receives every file twice while in
// watch mode, the second after Babel has transpiled the file. Babel adds
// inline source maps to the file, something we will never do in our own
// source files, so we use the existence of inline source maps to determine
// whether we should ignore the file.
if (/^\/\/# sourceMappingURL=/gmu.test(fileContent)) {
return [fileContent, false];
}
// If we didn't match any lines, return the unmodified file contents.
const matchedLines = [...fileContent.matchAll(linesWithFenceRegex)];
if (matchedLines.length === 0) {
return [fileContent, false];
}

View File

@ -610,6 +610,17 @@ describe('build/transforms/remove-fenced-code', () => {
});
});
it('ignores files with inline source maps', () => {
// This is so that there isn't an unnecessary second execution of
// removeFencedCode with a transpiled version of the same file
const input = getTestData().validInputs.extraContentWithFences.concat(
'\n//# sourceMappingURL=as32e32wcwc2234f2ew32cnin4243f4nv9nsdoivnxzoivnd',
);
expect(
removeFencedCode(mockFileName, BuildType.flask, input),
).toStrictEqual([input, false]);
});
// We can't do this until there's more than one command
it.todo('rejects directive pairs with mismatched commands');
});