Skip to content

Commit b2c27a4

Browse files
authored
Merge pull request #2032 from justinfagnani/update-typescript
Upgrade TypeScript to 4.7.4
2 parents 8206858 + c26d373 commit b2c27a4

File tree

18 files changed

+60
-34
lines changed

18 files changed

+60
-34
lines changed

.changeset/yellow-beds-shake.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
'@web/dev-server-import-maps': patch
3+
'@web/dev-server-esbuild': patch
4+
'@web/test-runner-mocha': patch
5+
'@web/polyfills-loader': patch
6+
'@web/test-runner-core': patch
7+
'@web/dev-server-core': patch
8+
'@web/config-loader': patch
9+
'@web/test-runner': patch
10+
'@web/dev-server': patch
11+
---
12+
13+
Update TypeScript

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"rollup": "^3.15.0",
7474
"rollup-plugin-terser": "^7.0.2",
7575
"ts-node": "^10.4.0",
76-
"typescript": "4.2.4"
76+
"typescript": "~4.7.4"
7777
},
7878
"resolutions": {
7979
"@lion/accordion": "^0.11.1",

packages/config-loader/src/importConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async function importConfig(path) {
3535

3636
return config.default;
3737
} catch (e) {
38-
if (CJS_ERRORS.some(msg => e.stack.includes(msg))) {
38+
if (CJS_ERRORS.some(msg => /** @type {Error} */(e).stack?.includes(msg))) {
3939
throw new ConfigLoaderError(
4040
'You are using CommonJS syntax such as "require" or "module.exports" in a config loaded as es module. ' +
4141
'Use import/export syntax, or load the file as a CommonJS module by ' +

packages/config-loader/src/requireConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function requireConfig(path) {
1414
try {
1515
return require(path);
1616
} catch (e) {
17-
if (ESM_ERRORS.some(msg => e.stack.includes(msg))) {
17+
if (ESM_ERRORS.some(msg => /** @type {Error} **/(e).stack?.includes(msg))) {
1818
throw new ConfigLoaderError(
1919
'You are using es module syntax in a config loaded as CommonJS module. ' +
2020
'Use require/module.exports syntax, or load the file as es module by using the .mjs ' +

packages/dev-server-core/src/middleware/pluginTransformMiddleware.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { DevServerCoreConfig } from '../server/DevServerCoreConfig';
55
import { PluginTransformCache } from './PluginTransformCache';
66
import { getRequestFilePath, getResponseBody, RequestCancelledError } from '../utils';
77
import { Logger } from '../logger/Logger';
8+
import type { PluginSyntaxError } from '../logger/PluginSyntaxError';
89

910
/**
1011
* Sets up a middleware which allows plugins to transform files before they are served to the browser.
@@ -84,15 +85,17 @@ export function pluginTransformMiddleware(
8485
cacheKey,
8586
);
8687
}
87-
} catch (error) {
88-
if (error instanceof RequestCancelledError) {
88+
} catch (e) {
89+
if (e instanceof RequestCancelledError) {
8990
return undefined;
9091
}
9192
context.body = 'Error while transforming file. See the terminal for more information.';
9293
context.status = 500;
9394

95+
const error = e as NodeJS.ErrnoException;
96+
9497
if (error.name === 'PluginSyntaxError') {
95-
logger.logSyntaxError(error);
98+
logger.logSyntaxError(error as PluginSyntaxError);
9699
return;
97100
}
98101

packages/dev-server-core/src/plugins/transformModuleImportsPlugin.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,14 @@ export async function transformImports(
117117
const parseResult = await parse(code, filePath);
118118
imports = parseResult[0] as any as ParsedImport[];
119119
} catch (error) {
120-
if (typeof error.idx === 'number') {
120+
if (typeof (error as Error & { idx: number }).idx === 'number') {
121+
const lexerError = error as Error & { idx: number };
121122
throw new PluginSyntaxError(
122123
'Syntax error',
123124
filePath,
124125
code,
125-
code.slice(0, error.idx).split('\n').length,
126-
error.idx - code.lastIndexOf('\n', error.idx - 1),
126+
code.slice(0, lexerError.idx).split('\n').length,
127+
lexerError.idx - code.lastIndexOf('\n', lexerError.idx - 1),
127128
);
128129
}
129130
throw error;

packages/dev-server-core/test/plugins/transformModuleImportsPlugin.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { expect } from 'chai';
22
import fetch from 'node-fetch';
33

44
import { transformImports } from '../../src/plugins/transformModuleImportsPlugin';
5+
import type { PluginSyntaxError } from '../../src/logger/PluginSyntaxError';
56
import { createTestServer } from '../helpers';
67

78
const defaultFilePath = '/root/my-file.js';
@@ -257,10 +258,10 @@ describe('transformImports()', () => {
257258
await transformImports('\n\nconst file = "a', defaultFilePath, defaultResolveImport);
258259
} catch (error) {
259260
thrown = true;
260-
expect(error.message).to.equal('Syntax error');
261-
expect(error.filePath).to.equal('/root/my-file.js');
262-
expect(error.column).to.equal(16);
263-
expect(error.line).to.equal(3);
261+
expect((error as PluginSyntaxError).message).to.equal('Syntax error');
262+
expect((error as PluginSyntaxError).filePath).to.equal('/root/my-file.js');
263+
expect((error as PluginSyntaxError).column).to.equal(16);
264+
expect((error as PluginSyntaxError).line).to.equal(3);
264265
}
265266

266267
expect(thrown).to.be.true;

packages/dev-server-esbuild/src/EsbuildPlugin.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
DevServerCoreConfig,
77
getRequestFilePath,
88
} from '@web/dev-server-core';
9-
import type { TransformOptions } from 'esbuild';
9+
import type { TransformOptions, BuildFailure } from 'esbuild';
1010
import { Loader, Message, transform } from 'esbuild';
1111
import { promisify } from 'util';
1212
import path from 'path';
@@ -203,8 +203,8 @@ export class EsbuildPlugin implements Plugin {
203203

204204
return transformedCode;
205205
} catch (e) {
206-
if (Array.isArray(e.errors)) {
207-
const msg = e.errors[0] as Message;
206+
if (Array.isArray((e as BuildFailure).errors)) {
207+
const msg = (e as BuildFailure).errors[0] as Message;
208208

209209
if (msg.location) {
210210
throw new PluginSyntaxError(

packages/dev-server-esbuild/src/browser-targets.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ function createModernTarget() {
2929
];
3030
} catch (error) {
3131
throw new Error(
32-
`Error while initializing default browser targets for @web/dev-server-esbuild: ${error.message}`,
32+
`Error while initializing default browser targets for @web/dev-server-esbuild: ${
33+
(error as Error).message
34+
}`,
3335
);
3436
}
3537
}

packages/dev-server-import-maps/src/importMapsPlugin.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ export function importMapsPlugin(config: ImportMapsPluginConfig = {}): Plugin {
148148
} catch (error) {
149149
const filePath = getRequestFilePath(context.url, rootDir);
150150
const relativeFilePath = path.relative(process.cwd(), filePath);
151-
logger.warn(`Failed to parse import map in "${relativeFilePath}": ${error.message}`);
151+
logger.warn(
152+
`Failed to parse import map in "${relativeFilePath}": ${(error as Error).message}`,
153+
);
152154
return;
153155
}
154156
}

0 commit comments

Comments
 (0)