mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 01:47:00 +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:
parent
05f9ceda77
commit
ff27f24ef9
@ -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];
|
||||
}
|
||||
|
@ -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');
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user