@samitouri / QOS-React-2 / commits / 3bd6adceda

Update typescript package and jest preprocessor (#17839)

Nicolas Gallagher committed Jan 14, 2020 at 13:52 UTC 3bd6adceda6335adc5f5bbae148dd2ff290eeea6
3 files changed +37 -29
package.json
+1 -1
@@ -88,7 +88,7 @@
88 "targz": "^1.0.1",
89 "through2": "^2.0.0",
90 "tmp": "~0.0.28",
91 - "typescript": "~1.8.10",
91 + "typescript": "^3.7.4",
92 "webpack": "^4.41.2"
93 },
94 "devEngines": {
scripts/jest/typescript/preprocessor.js
+32 -24
@@ -10,29 +10,46 @@ const tsOptions = {
10 };
11
12 function formatErrorMessage(error) {
13 - return (
14 - error.file.filename +
15 - '(' +
16 - error.file.getLineAndCharacterOfPosition(error.start).line +
17 - '): ' +
18 - error.messageText
19 - );
13 + if (error.file) {
14 + const message = ts.flattenDiagnosticMessageText(error.messageText, '\n');
15 + return (
16 + error.file.fileName +
17 + '(' +
18 + error.file.getLineAndCharacterOfPosition(error.start).line +
19 + '): ' +
20 + message
21 + );
22 + } else {
23 + return ts.flattenDiagnosticMessageText(error.messageText, '\n');
24 + }
25 }
26
27 function compile(content, contentFilename) {
28 let output = null;
29 const compilerHost = {
30 + fileExists(filename) {
31 + return ts.sys.fileExists(filename);
32 + },
33 + getCanonicalFileName(filename) {
34 + return filename;
35 + },
36 + getCurrentDirectory() {
37 + return '';
38 + },
39 + getDefaultLibFileName: () => 'lib.d.ts',
40 + getNewLine: () => ts.sys.newLine,
41 getSourceFile(filename, languageVersion) {
42 let source;
43 + const libRegex = /lib\.(.+\.)?d\.ts$/;
44 const jestRegex = /jest\.d\.ts/;
45 const reactRegex = /(?:React|ReactDOM|PropTypes)(?:\.d)?\.ts$/;
46
47 // `path.normalize` is used to turn forward slashes in
48 // the file path into backslashes on Windows.
49 filename = path.normalize(filename);
33 - if (filename === 'lib.d.ts') {
50 + if (filename.match(libRegex)) {
51 source = fs
35 - .readFileSync(require.resolve('typescript/lib/lib.d.ts'))
52 + .readFileSync(require.resolve('typescript/lib/' + filename))
53 .toString();
54 } else if (filename.match(jestRegex)) {
55 source = fs.readFileSync(path.join(__dirname, 'jest.d.ts')).toString();
@@ -55,6 +72,12 @@ function compile(content, contentFilename) {
72 }
73 return ts.createSourceFile(filename, source, 'ES5', '0');
74 },
75 + readFile(filename) {
76 + return ts.sys.readFile(filename);
77 + },
78 + useCaseSensitiveFileNames() {
79 + return ts.sys.useCaseSensitiveFileNames;
80 + },
81 writeFile(name, text, writeByteOrderMark) {
82 if (output === null) {
83 output = text;
@@ -62,21 +85,6 @@ function compile(content, contentFilename) {
85 throw new Error('Expected only one dependency.');
86 }
87 },
65 - getCanonicalFileName(filename) {
66 - return filename;
67 - },
68 - getCurrentDirectory() {
69 - return '';
70 - },
71 - getNewLine() {
72 - return '\n';
73 - },
74 - fileExists(filename) {
75 - return ts.sys.fileExists(filename);
76 - },
77 - useCaseSensitiveFileNames() {
78 - return ts.sys.useCaseSensitiveFileNames;
79 - },
88 };
89 const program = ts.createProgram(
90 ['lib.d.ts', 'jest.d.ts', contentFilename],
yarn.lock
+4 -4
@@ -12804,10 +12804,10 @@ typedarray@^0.0.6:
12804 resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
12805 integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
12806
12807 -typescript@~1.8.10:
12808 - version "1.8.10"
12809 - resolved "https://registry.yarnpkg.com/typescript/-/typescript-1.8.10.tgz#b475d6e0dff0bf50f296e5ca6ef9fbb5c7320f1e"
12810 - integrity sha1-tHXW4N/wv1DyluXKbvn7tccyDx4=
12807 +typescript@^3.7.4:
12808 + version "3.7.4"
12809 + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.4.tgz#1743a5ec5fef6a1fa9f3e4708e33c81c73876c19"
12810 + integrity sha512-A25xv5XCtarLwXpcDNZzCGvW2D1S3/bACratYBx2sax8PefsFhlYmkQicKHvpYflFS8if4zne5zT5kpJ7pzuvw==
12811
12812 ua-parser-js@^0.7.18, ua-parser-js@^0.7.9:
12813 version "0.7.20"