Skip to content

Commit 73b97d5

Browse files
authored
Fetch TypeScript standard libs at the bundled compiler version (#437)
* Pin CI to ubuntu-24.04 for Playwright system dependencies ubuntu-latest now resolves to Ubuntu 26.04, where the pinned Playwright version (1.46.1) cannot install its system dependencies: it falls back to the 24.04 package list, and packages such as libicu74 and libvpx9 do not exist there. Pin the workflows that install Playwright to ubuntu-24.04 until Playwright is upgraded. * Fetch TypeScript standard libs at the bundled compiler version Standard lib typings (lib.dom.d.ts etc.) were fetched from the CDN at typescript@latest unless the project pinned a typescript version. Since TypeScript 7 was published, the latest package no longer contains those files, so the worker got no standard typings. That broke type checking and completions that rely on them, and the completions tests. Default to the version of the TypeScript compiler bundled in the worker instead, which is the version the lib files need to match anyway. A typescript version in the project's package.json still takes precedence. * Pin GitHub Actions to commit hashes The zizmor check requires every action reference to be pinned to a commit hash. Pin each action to the commit its current tag points to, so behaviour is unchanged, and keep the version as a comment. * Harden workflow permissions and credential persistence Address the remaining zizmor findings: - Give every workflow a read-only default token (contents: read). The deploy-demo job additionally gets contents: write, which it needs to push to gh-pages. - Stop the checkout action from persisting credentials in lint, test and version-module, which never use them. deploy-demo keeps them, because its deploy step pushes with them; that finding is suppressed with a rationale.
1 parent 3853225 commit 73b97d5

8 files changed

Lines changed: 141 additions & 19 deletions

File tree

‎.github/workflows/deploy-demo.yml‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,28 @@ on:
55
branches:
66
- main
77

8+
permissions:
9+
contents: read
10+
811
jobs:
912
deploy-demo:
10-
runs-on: ubuntu-latest
13+
# Pinned because our Playwright version cannot install its system
14+
# dependencies on newer Ubuntu releases. Upgrade Playwright to unpin.
15+
runs-on: ubuntu-24.04
16+
17+
permissions:
18+
contents: write # Needed to push the built demo to the gh-pages branch.
1119

1220
steps:
13-
- uses: actions/checkout@v3
14-
- uses: actions/setup-node@v3
21+
- uses: actions/checkout@a37ce9120846195fa4ece8f58b268e6043cb2f26 # v3.7.0
22+
with:
23+
# zizmor: ignore[artipacked] - credentials are used to push to gh-pages in the deploy step
24+
persist-credentials: true
25+
- uses: actions/setup-node@3235b876344d2a9aa001b8d1453c930bba69e610 # v3.9.1
1526
with:
1627
node-version: 20
1728
cache: npm
18-
- uses: google/wireit@setup-github-actions-caching/v2
29+
- uses: google/wireit@9d7c2e5346f8ef1b1ab6014c4e96c74e234f7ed5 # setup-github-actions-caching/v2.0.4
1930

2031
- run: npm ci
2132
- run: npx playwright install-deps

‎.github/workflows/lint.yml‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,22 @@ name: lint
22

33
on: [push, pull_request]
44

5+
permissions:
6+
contents: read
7+
58
jobs:
69
lint:
710
runs-on: ubuntu-latest
811

912
steps:
10-
- uses: actions/checkout@v3
11-
- uses: actions/setup-node@v3
13+
- uses: actions/checkout@a37ce9120846195fa4ece8f58b268e6043cb2f26 # v3.7.0
14+
with:
15+
persist-credentials: false
16+
- uses: actions/setup-node@3235b876344d2a9aa001b8d1453c930bba69e610 # v3.9.1
1217
with:
1318
node-version: 20
1419
cache: npm
15-
- uses: google/wireit@setup-github-actions-caching/v2
20+
- uses: google/wireit@9d7c2e5346f8ef1b1ab6014c4e96c74e234f7ed5 # setup-github-actions-caching/v2.0.4
1621

1722
- run: npm ci
1823
- run: npm run lint

‎.github/workflows/test.yml‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,24 @@ name: test
22

33
on: [push, pull_request]
44

5+
permissions:
6+
contents: read
7+
58
jobs:
69
test:
7-
runs-on: ubuntu-latest
10+
# Pinned because our Playwright version cannot install its system
11+
# dependencies on newer Ubuntu releases. Upgrade Playwright to unpin.
12+
runs-on: ubuntu-24.04
813

914
steps:
10-
- uses: actions/checkout@v3
11-
- uses: actions/setup-node@v3
15+
- uses: actions/checkout@a37ce9120846195fa4ece8f58b268e6043cb2f26 # v3.7.0
16+
with:
17+
persist-credentials: false
18+
- uses: actions/setup-node@3235b876344d2a9aa001b8d1453c930bba69e610 # v3.9.1
1219
with:
1320
node-version: 20
1421
cache: npm
15-
- uses: google/wireit@setup-github-actions-caching/v2
22+
- uses: google/wireit@9d7c2e5346f8ef1b1ab6014c4e96c74e234f7ed5 # setup-github-actions-caching/v2.0.4
1623

1724
- run: npm ci
1825
- run: npx playwright install-deps

‎.github/workflows/version-module.yml‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,24 @@ name: version-module
22

33
on: [push, pull_request]
44

5+
permissions:
6+
contents: read
7+
58
jobs:
69
version-module:
7-
runs-on: ubuntu-latest
10+
# Pinned because our Playwright version cannot install its system
11+
# dependencies on newer Ubuntu releases. Upgrade Playwright to unpin.
12+
runs-on: ubuntu-24.04
813

914
steps:
10-
- uses: actions/checkout@v3
11-
- uses: actions/setup-node@v3
15+
- uses: actions/checkout@a37ce9120846195fa4ece8f58b268e6043cb2f26 # v3.7.0
16+
with:
17+
persist-credentials: false
18+
- uses: actions/setup-node@3235b876344d2a9aa001b8d1453c930bba69e610 # v3.9.1
1219
with:
1320
node-version: 20
1421
cache: npm
15-
- uses: google/wireit@setup-github-actions-caching/v2
22+
- uses: google/wireit@9d7c2e5346f8ef1b1ab6014c4e96c74e234f7ed5 # setup-github-actions-caching/v2.0.4
1623

1724
- run: npm ci
1825
- run: npx playwright install-deps

‎CHANGELOG.md‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1212

1313
<!-- ## [X.Y.Z] - YYYY-MM-DD -->
1414

15-
<!-- ## [Unreleased] -->
15+
## [Unreleased]
16+
17+
### Fixed
18+
19+
- TypeScript standard library typings (e.g. `lib.dom.d.ts`) are now fetched at
20+
the version of the TypeScript compiler bundled with Playground, instead of at
21+
`typescript@latest`. They could no longer be found since TypeScript 7 was
22+
published, which broke type checking and completions that rely on them. A
23+
`typescript` version in the project's `package.json` still takes precedence.
1624

1725
## [0.21.2] - 2025-10-02
1826

‎src/test/types-fetcher_test.ts‎

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
import {TypesFetcher} from '../typescript-worker/types-fetcher.js';
8+
import ts from '../internal/typescript.js';
89
import {ImportMapResolver} from '../typescript-worker/import-map-resolver.js';
910
import {configureFakeCdn} from './worker-test-util.js';
1011
import {assert} from '@esm-bundle/chai';
@@ -571,10 +572,78 @@ suite('types fetcher', () => {
571572
});
572573
});
573574

574-
test('tslibs', async () => {
575+
test('tslibs default to the bundled TypeScript version', async () => {
575576
const sourceTexts: string[] = [];
576577
const tsLibs = ['es2020', 'DOM'];
577578
const packageJson: PackageJson = {};
579+
const cdnData: CdnData = {
580+
typescript: {
581+
versions: {
582+
[ts.version]: {
583+
files: {
584+
'lib/lib.es2020.d.ts': {
585+
// References are the same as imports from our perspective.
586+
content: `/// <reference lib="es2020.promise" />`,
587+
},
588+
'lib/lib.es2020.promise.d.ts': {
589+
content: `interface PromiseConstructor { }`,
590+
},
591+
// Note standard lib files are always lower-case.
592+
'lib/lib.dom.d.ts': {
593+
content: `interface HTMLElement { }`,
594+
},
595+
},
596+
},
597+
// TypeScript 7 doesn't have the lib files. We must not try to load
598+
// the libs from here just because it is the latest version.
599+
'7.0.0': {
600+
files: {},
601+
},
602+
},
603+
},
604+
};
605+
const expectedDependencyGraph: ExpectedDependencyGraph = {
606+
root: {
607+
typescript: ts.version,
608+
},
609+
deps: {},
610+
};
611+
const expectedLayout: NodeModulesDirectory = {
612+
typescript: {
613+
version: ts.version,
614+
nodeModules: {},
615+
},
616+
};
617+
const expectedFiles = new Map([
618+
[
619+
'typescript/lib/lib.es2020.d.ts',
620+
`/// <reference lib="es2020.promise" />`,
621+
],
622+
[
623+
'typescript/lib/lib.es2020.promise.d.ts',
624+
`interface PromiseConstructor { }`,
625+
],
626+
['typescript/lib/lib.dom.d.ts', `interface HTMLElement { }`],
627+
]);
628+
await checkTypesFetcher({
629+
sourceTexts,
630+
tsLibs,
631+
packageJson,
632+
cdnData,
633+
expectedFiles,
634+
expectedDependencyGraph,
635+
expectedLayout,
636+
});
637+
});
638+
639+
test('tslibs use the TypeScript version from package.json', async () => {
640+
const sourceTexts: string[] = [];
641+
const tsLibs = ['es2020', 'DOM'];
642+
const packageJson: PackageJson = {
643+
dependencies: {
644+
typescript: '4.3.5',
645+
},
646+
};
578647
const cdnData: CdnData = {
579648
typescript: {
580649
versions: {

‎src/test/typescript-worker_test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
import {checkTransform} from './worker-test-util.js';
8+
import ts from '../internal/typescript.js';
89

910
import {BuildOutput, SampleFile} from '../shared/worker-api.js';
1011
import {CdnData} from './fake-cdn-plugin.js';
@@ -529,7 +530,8 @@ suite('typescript builder', () => {
529530
},
530531
typescript: {
531532
versions: {
532-
'4.3.5': {
533+
// Standard libs are fetched at the version of the bundled compiler.
534+
[ts.version]: {
533535
files: {
534536
'lib/lib.dom.d.ts': {
535537
content: '',

‎src/typescript-worker/types-fetcher.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,20 @@ export class TypesFetcher {
264264
from === root
265265
? this._rootPackageJson
266266
: await this._fetchPackageJsonAndAddToOutputFiles(from);
267-
return packageJson?.dependencies?.[to] ?? 'latest';
267+
const version = packageJson?.dependencies?.[to];
268+
if (version !== undefined) {
269+
return version;
270+
}
271+
if (from === root && to === 'typescript') {
272+
// The project didn't pick a TypeScript version, so use the version of
273+
// the compiler we are running. This is what the standard lib typings
274+
// (lib.dom.d.ts etc.) are fetched at, and they need to match our
275+
// compiler. We can't use "latest", because newer major versions of the
276+
// "typescript" package might not be compatible, or might not contain
277+
// these files at all (TypeScript 7 does not).
278+
return ts.version;
279+
}
280+
return 'latest';
268281
}
269282

270283
private async _getDtsPath(location: NpmFileLocation): Promise<string> {

0 commit comments

Comments
 (0)