Explorar el Código

Adds support for error messages to include a reference to require

Orta Therox hace 5 años
padre
commit
bb69053ca5
Se han modificado 1 ficheros con 6 adiciones y 2 borrados
  1. 6 2
      scripts/importTypescript.js

+ 6 - 2
scripts/importTypescript.js

@@ -50,8 +50,12 @@ export const typescriptVersion = "${typeScriptDependencyVersion}";\n`
 	// \/[*/] matches the start of a comment (single or multi-line).
 	// \/[*/] matches the start of a comment (single or multi-line).
 	// ^\s+\*[^/] matches (presumably) a later line of a multi-line comment.
 	// ^\s+\*[^/] matches (presumably) a later line of a multi-line comment.
 	const tsServicesNoCommentedRequire = tsServices.replace(/(\/[*/]|^\s+\*[^/]).*\brequire\(.*/gm, '');
 	const tsServicesNoCommentedRequire = tsServices.replace(/(\/[*/]|^\s+\*[^/]).*\brequire\(.*/gm, '');
-	const linesWithRequire = tsServicesNoCommentedRequire.match(/^.*?\brequire\(.*$/gm);
-	if (linesWithRequire && linesWithRequire.length) {
+	const linesWithRequire = tsServicesNoCommentedRequire.match(/^.*?\brequire\(.*$/gm)
+
+	// Allow error messages to include references to require() in their strings
+	const runtimeRequires = linesWithRequire && linesWithRequire.filter(l => !l.includes(": diag("))
+
+	if (runtimeRequires && runtimeRequires.length && linesWithRequire) {
 		console.error('Found new require() calls on the following lines. These should be removed to avoid breaking webpack builds.\n');
 		console.error('Found new require() calls on the following lines. These should be removed to avoid breaking webpack builds.\n');
 		console.error(linesWithRequire.join('\n'));
 		console.error(linesWithRequire.join('\n'));
 		process.exit(1);
 		process.exit(1);