Skip to content

Commit d5ac135

Browse files
author
Orta Therox
authored
Merge pull request #1062 from microsoft/new_targets
Adds targets for the other environments
2 parents 720ff42 + e176568 commit d5ac135

File tree

7 files changed

+171
-4
lines changed

7 files changed

+171
-4
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ npm run test
3636
| `@types/web` [0.0.1](https://www.npmjs.com/package/@types/web/v/0.0.1) | ~4.3 | 4.4 |
3737
| `@types/web` [0.0.2](https://www.npmjs.com/package/@types/web/v/0.0.2) | ~4.4 beta | 4.4 |
3838

39+
## `@types/[lib]` Minimum Target
40+
41+
The libraries available on `@types/` like `@types/web` require a [`"target"`](https://www.typescriptlang.org/tsconfig#target) of ES6 or above, because [iterator](https://www.typescriptlang.org/docs/handbook/iterators-and-generators.html) APIs are included.
42+
3943
## Contribution Guidelines
4044

4145
The `dom.generated.d.ts`, `webworker.generated.d.ts` and `dom.iterable.generated.d.ts` files from the TypeScript repo are used as baselines.

deploy/createTypesPackages.mjs

+46-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,34 @@ export const packages = [
1010
readme: "./readmes/web.md",
1111
files: [
1212
{ from: "../generated/dom.generated.d.ts", to: "index.d.ts" },
13-
{ from: "../generated/dom.iterable.generated.d.ts", to: "index.iterable.d.ts" }
13+
{ from: "../generated/dom.iterable.generated.d.ts", to: "index.iterable.d.ts", autoImport: true },
14+
],
15+
},
16+
{
17+
name: "@types/serviceworker",
18+
description: "Types for the global scope of Service Workers",
19+
readme: "./readmes/serviceworker.md",
20+
files: [
21+
{ from: "../generated/serviceworker.generated.d.ts", to: "index.d.ts" },
22+
{ from: "../generated/serviceworker.iterable.generated.d.ts", to: "index.iterable.d.ts", autoImport: true },
23+
],
24+
},
25+
{
26+
name: "@types/audioworklet",
27+
description: "Types for the global scope of Audio Worklets",
28+
readme: "./readmes/audioworklet.md",
29+
files: [
30+
{ from: "../generated/audioworklet.generated.d.ts", to: "index.d.ts" },
31+
{ from: "../generated/audioworklet.iterable.generated.d.ts", to: "index.iterable.d.ts", autoImport: true },
32+
],
33+
},
34+
{
35+
name: "@types/sharedworker",
36+
description: "Types for the global scope of Shared Workers",
37+
readme: "./readmes/sharedworker.md",
38+
files: [
39+
{ from: "../generated/sharedworker.generated.d.ts", to: "index.d.ts" },
40+
{ from: "../generated/sharedworker.iterable.generated.d.ts", to: "index.iterable.d.ts", autoImport: true },
1441
],
1542
},
1643
];
@@ -58,16 +85,18 @@ const go = async () => {
5885
);
5986
});
6087

88+
prependAutoImports(pkg, packagePath);
89+
6190
// Setup the files in the repo
62-
const newPkgJSON = await updatePackageJSON(packagePath, pkg, gitSha);
91+
const newPkgJSON = await updatePackageJSON(pkg, packagePath, gitSha);
6392
copyREADME(pkg, newPkgJSON, new URL("README.md", packagePath));
6493

6594
// Done
6695
console.log("Built:", pkg.name);
6796
}
6897
};
6998

70-
async function updatePackageJSON(packagePath, pkg, gitSha) {
99+
async function updatePackageJSON(pkg, packagePath, gitSha) {
71100
const pkgJSONPath = new URL("package.json", packagePath);
72101
const packageText = fs.readFileSync(pkgJSONPath, "utf8");
73102
const packageJSON = JSON.parse(packageText);
@@ -128,6 +157,20 @@ function copyREADME(pkg, pkgJSON, writePath) {
128157
fs.writeFileSync(writePath, readme);
129158
}
130159

160+
// Appends any files marked as autoImport in the metadata.
161+
function prependAutoImports(pkg, packagePath) {
162+
const index = new URL("index.d.ts", packagePath);
163+
if (!fs.existsSync(index)) return;
164+
165+
const toPrepend = pkg.files
166+
.filter((f) => !!f.autoImport)
167+
.map((f) => `/// <reference path="./${f.to}" />`)
168+
.join("\n");
169+
170+
let indexText = fs.readFileSync(index, "utf-8");
171+
fs.writeFileSync(index, `${toPrepend}\n\n${indexText}`);
172+
}
173+
131174
if (process.argv[1] === fileURLToPath(import.meta.url)) {
132175
await go();
133176
}

deploy/readmes/audioworklet.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
### `@types/audioworklet` - Types for the global scope of Audio Worklets
2+
3+
> The AudioWorklet interface of the Web Audio API is used to supply custom audio processing scripts that execute in a separate thread to provide very low latency audio processing. The worklet's code is run in the AudioWorkletGlobalScope global execution context, using a separate Web Audio thread which is shared by the worklet and other audio nodes.
4+
5+
From [MDN Web Docs: AudioWorklet](https://developer.mozilla.org/en-US/docs/Web/API/AudioWorklet)
6+
7+
This package contains type definitions which will set up the global environment for your TypeScript project to match the runtime environment of an Audio Worklet. The APIs inside `@types/audioworklet` are [generated from](https://github.com/microsoft/TypeScript-DOM-lib-generator/) the specifications for [Web Audio](https://webaudio.github.io/web-audio-api/).
8+
9+
## Installation
10+
11+
To use `@types/audioworklet` you need to do two things:
12+
13+
1. Install the dependency: `npm install @types/audioworklet --save-dev`, `yarn add @types/audioworklet --dev` or `pnpm add @types/audioworklet --dev`.
14+
1. Update your [`tsconfig.json`](https://www.typescriptlang.org/tsconfig) to avoid clashing with the DOM APIs. There are two cases to consider depending on if you have `lib` defined in your `tsconfig.json` or not.
15+
16+
1. **Without "lib"** - You will need to add `"lib": []`. The value you want to add inside your lib should correlate to your [`"target"`](https://www.typescriptlang.org/tsconfig#target). For example if you had `"target": "es2017"`, then you would add `"lib": ["es2017"]`
17+
1. **With "lib"** - You should remove `"dom"`.
18+
19+
That's all.
20+
21+
22+
## SemVer
23+
24+
This project does not respect semantic versioning as almost every change could potentially break a project, though we try to minimize removing types.
25+
26+
`@types/audioworklet` follow the specifications, so when they mark a function/object/API/type as deprecated or removed - that is respected.
27+
28+
## Deploy Metadata
29+
30+
You can read what changed in version {{version}} at {{release_href}}.

deploy/readmes/serviceworker.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
### `@types/serviceworker` - Types for the global scope of Service Workers
2+
3+
> Service workers essentially act as proxy servers that sit between web applications, the browser, and the network (when available). They are intended, among other things, to enable the creation of effective offline experiences, intercept network requests and take appropriate action based on whether the network is available, and update assets residing on the server. They will also allow access to push notifications and background sync APIs.
4+
5+
From [MDN Web Docs: Service Worker API](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API)
6+
7+
This package contains type definitions which will set up the global environment for your TypeScript project to match the runtime environment of a Service Worker. The APIs inside `@types/serviceworker` are [generated from](https://github.com/microsoft/TypeScript-DOM-lib-generator/) the specifications for JavaScript. Given the size and state of constant change in web browsers, `@types/serviceworker` only has APIs which have passed a certain level of standardization and are available in at least two of the most popular browser engines.
8+
9+
## Installation
10+
11+
To use `@types/serviceworker` you need to do two things:
12+
13+
1. Install the dependency: `npm install @types/serviceworker --save-dev`, `yarn add @types/serviceworker --dev` or `pnpm add @types/serviceworker --dev`.
14+
1. Update your [`tsconfig.json`](https://www.typescriptlang.org/tsconfig) to avoid clashing with the DOM APIs. There are two cases to consider depending on if you have `lib` defined in your `tsconfig.json` or not.
15+
16+
1. **Without "lib"** - You will need to add `"lib": []`. The value you want to add inside your lib should correlate to your [`"target"`](https://www.typescriptlang.org/tsconfig#target). For example if you had `"target": "es2017"`, then you would add `"lib": ["es2017"]`
17+
1. **With "lib"** - You should remove `"dom"`.
18+
19+
That's all.
20+
21+
22+
## SemVer
23+
24+
This project does not respect semantic versioning as almost every change could potentially break a project, though we try to minimize removing types.
25+
26+
`@types/serviceworker` follow the specifications, so when they mark a function/object/API/type as deprecated or removed - that is respected.
27+
28+
## Deploy Metadata
29+
30+
You can read what changed in version {{version}} at {{release_href}}.

deploy/readmes/sharedworker.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
### `@types/sharedworker` - Types for the global scope of Web Workers
2+
3+
> The SharedWorker interface represents a specific kind of worker that can be accessed from several browsing contexts, such as several windows, iframes or even workers. They implement an interface different than dedicated workers and have a different global scope, `SharedWorkerGlobalScope`.
4+
5+
From [MDN Web Docs: SharedWorker API](https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker)
6+
7+
This package contains type definitions which will set up the global environment for your TypeScript project to match the runtime environment of a Web Worker. The APIs inside `@types/sharedworker` are [generated from](https://github.com/microsoft/TypeScript-DOM-lib-generator/) the specifications for JavaScript.
8+
9+
## Installation
10+
11+
To use `@types/sharedworker` you need to do two things:
12+
13+
1. Install the dependency: `npm install @types/sharedworker --save-dev`, `yarn add @types/sharedworker --dev` or `pnpm add @types/sharedworker --dev`.
14+
1. Update your [`tsconfig.json`](https://www.typescriptlang.org/tsconfig) to avoid clashing with the DOM APIs. There are two cases to consider depending on if you have `lib` defined in your `tsconfig.json` or not.
15+
16+
1. **Without "lib"** - You will need to add `"lib": []`. The value you want to add inside your lib should correlate to your [`"target"`](https://www.typescriptlang.org/tsconfig#target). For example if you had `"target": "es2017"`, then you would add `"lib": ["es2017"]`
17+
1. **With "lib"** - You should remove `"dom"`.
18+
19+
That's all.
20+
21+
22+
## SemVer
23+
24+
This project does not respect semantic versioning as almost every change could potentially break a project, though we try to minimize removing types.
25+
26+
`@types/sharedworker` follow the specifications, so when they mark a function/object/API/type as deprecated or removed - that is respected.
27+
28+
## Deploy Metadata
29+
30+
You can read what changed in version {{version}} at {{release_href}}.

deploy/readmes/web.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This module contains the DOM types for the majority of the web APIs used in a web browser.
44

5-
The APIs inside `@types/web` are generated from the specifications for CSS, HTML and JavaScript. Given the size and state of constant change in web browsers, `@types/web` only has APIs which have passed a certain level of standardization and are available in at least two different browser engines.
5+
The APIs inside `@types/web` are [generated from](https://github.com/microsoft/TypeScript-DOM-lib-generator/) the specifications for CSS, HTML and JavaScript. Given the size and state of constant change in web browsers, `@types/web` only has APIs which have passed a certain level of standardization and are available in at least two of the most popular browser engines.
66

77
`@types/web` is also included inside TypeScript, available as `dom` in the [`lib`](https://www.typescriptlang.org/tsconfig#lib) section and included in projects by default. By using `@types/web` you can lock your the web APIs used in your projects, easing the process of updating TypeScript and offering more control in your environment.
88

deploy/readmes/webworker.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
### `@types/webworker` - Types for the global scope of Web Workers
2+
3+
> The Worker interface of the Web Workers API represents a background task that can be created via script, which can send messages back to its creator. Creating a worker is done by calling the `Worker("path/to/worker/script")` constructor.
4+
5+
From [MDN Web Docs: Worker API](https://developer.mozilla.org/en-US/docs/Web/API/Worker)
6+
7+
This package contains type definitions which will set up the global environment for your TypeScript project to match the runtime environment of a Web Worker. The APIs inside `@types/webworker` are [generated from](https://github.com/microsoft/TypeScript-DOM-lib-generator/) the specifications for JavaScript.
8+
9+
## Installation
10+
11+
To use `@types/webworker` you need to do two things:
12+
13+
1. Install the dependency: `npm install @types/webworker --save-dev`, `yarn add @types/webworker --dev` or `pnpm add @types/webworker --dev`.
14+
1. Update your [`tsconfig.json`](https://www.typescriptlang.org/tsconfig) to avoid clashing with the DOM APIs. There are two cases to consider depending on if you have `lib` defined in your `tsconfig.json` or not.
15+
16+
1. **Without "lib"** - You will need to add `"lib": []`. The value you want to add inside your lib should correlate to your [`"target"`](https://www.typescriptlang.org/tsconfig#target). For example if you had `"target": "es2017"`, then you would add `"lib": ["es2017"]`
17+
1. **With "lib"** - You should remove `"dom"`.
18+
19+
That's all.
20+
21+
22+
## SemVer
23+
24+
This project does not respect semantic versioning as almost every change could potentially break a project, though we try to minimize removing types.
25+
26+
`@types/webworker` follow the specifications, so when they mark a function/object/API/type as deprecated or removed - that is respected.
27+
28+
## Deploy Metadata
29+
30+
You can read what changed in version {{version}} at {{release_href}}.

0 commit comments

Comments
 (0)