diff --git a/types/shelljs/global.d.ts b/types/shelljs/global.d.ts new file mode 100644 index 00000000000000..1b8057a35b10bd --- /dev/null +++ b/types/shelljs/global.d.ts @@ -0,0 +1,35 @@ +import shelljs = require("./index"); + +declare global { + const cat: typeof shelljs.cat; + const cd: typeof shelljs.cd; + const chmod: typeof shelljs.chmod; + const cmd: typeof shelljs.cmd; + const config: typeof shelljs.config; + const cp: typeof shelljs.cp; + const dirs: typeof shelljs.dirs; + const echo: typeof shelljs.echo; + const env: typeof shelljs.env; + const error: typeof shelljs.error; + const exec: typeof shelljs.exec; + const exit: typeof shelljs.exit; + const find: typeof shelljs.find; + const grep: typeof shelljs.grep; + const head: typeof shelljs.head; + const ln: typeof shelljs.ln; + const ls: typeof shelljs.ls; + const mkdir: typeof shelljs.mkdir; + const mv: typeof shelljs.mv; + const popd: typeof shelljs.popd; + const pushd: typeof shelljs.pushd; + const pwd: typeof shelljs.pwd; + const rm: typeof shelljs.rm; + const sed: typeof shelljs.sed; + const set: typeof shelljs.set; + const sort: typeof shelljs.sort; + const tail: typeof shelljs.tail; + const tempdir: typeof shelljs.tempdir; + const touch: typeof shelljs.touch; + const uniq: typeof shelljs.uniq; + const ShellString: typeof shelljs.ShellString; +} diff --git a/types/shelljs/index.d.ts b/types/shelljs/index.d.ts index f03c6615998cad..1c45fd4d5cccac 100644 --- a/types/shelljs/index.d.ts +++ b/types/shelljs/index.d.ts @@ -1,7 +1,7 @@ /// import child = require("child_process"); -import glob = require("glob"); +import glob = require("fast-glob"); /** * Changes the current working directory dir for the duration of the script. @@ -1240,7 +1240,7 @@ export interface ShellConfig { /** * Passed to glob.sync() instead of the default options ({}). */ - globOptions: glob.GlobOptions; + globOptions: glob.Options; /** * Absolute path of the Node binary. Default is null (inferred). diff --git a/types/shelljs/make.d.ts b/types/shelljs/make.d.ts index 0df66621796517..02d1599d7702ee 100644 --- a/types/shelljs/make.d.ts +++ b/types/shelljs/make.d.ts @@ -1,4 +1,5 @@ -import shelljs = require("./index"); +import "./global"; + declare global { interface Target { (...args: any[]): void; @@ -7,38 +8,6 @@ declare global { } const target: { all?: Target; - [s: string]: Target; + [s: string]: Target | undefined; }; - - const cat: typeof shelljs.cat; - const cd: typeof shelljs.cd; - const chmod: typeof shelljs.chmod; - const cmd: typeof shelljs.cmd; - const config: typeof shelljs.config; - const cp: typeof shelljs.cp; - const dirs: typeof shelljs.dirs; - const echo: typeof shelljs.echo; - const env: typeof shelljs.env; - const error: typeof shelljs.error; - const exec: typeof shelljs.exec; - const exit: typeof shelljs.exit; - const find: typeof shelljs.find; - const grep: typeof shelljs.grep; - const head: typeof shelljs.head; - const ln: typeof shelljs.ln; - const ls: typeof shelljs.ls; - const mkdir: typeof shelljs.mkdir; - const mv: typeof shelljs.mv; - const popd: typeof shelljs.popd; - const pushd: typeof shelljs.pushd; - const pwd: typeof shelljs.pwd; - const rm: typeof shelljs.rm; - const sed: typeof shelljs.sed; - const set: typeof shelljs.set; - const sort: typeof shelljs.sort; - const tail: typeof shelljs.tail; - const tempdir: typeof shelljs.tempdir; - const touch: typeof shelljs.touch; - const uniq: typeof shelljs.uniq; - const ShellString: typeof shelljs.ShellString; } diff --git a/types/shelljs/package.json b/types/shelljs/package.json index f9b63f0aced5c1..b90c88bc5f0c6f 100644 --- a/types/shelljs/package.json +++ b/types/shelljs/package.json @@ -1,13 +1,24 @@ { "private": true, "name": "@types/shelljs", - "version": "0.8.9999", + "version": "0.10.9999", "projects": [ "http://shelljs.org", "https://github.com/shelljs/shelljs" ], + "exports": { + ".": "./index.d.ts", + "./global": "./global.d.ts", + "./global.js": "./global.d.ts", + "./make": "./make.d.ts", + "./make.js": "./make.d.ts", + "./package": "./package.json", + "./package.json": "./package.json", + "./plugin": "./plugin.d.ts", + "./plugin.js": "./plugin.d.ts" + }, "dependencies": { - "glob": "^11.0.3", + "fast-glob": "^3.3.2", "@types/node": "*" }, "devDependencies": { diff --git a/types/shelljs/plugin.d.ts b/types/shelljs/plugin.d.ts new file mode 100644 index 00000000000000..8971a46eb45e34 --- /dev/null +++ b/types/shelljs/plugin.d.ts @@ -0,0 +1,3 @@ +// TODO: proper typing +// https://github.com/shelljs/shelljs/wiki/Using-ShellJS-Plugins#pluginregister-options +export function register(...args: unknown[]): void; diff --git a/types/shelljs/shelljs-tests.ts b/types/shelljs/shelljs-tests.ts index 67cbd4ae38b832..9a3afc6d7a66d1 100644 --- a/types/shelljs/shelljs-tests.ts +++ b/types/shelljs/shelljs-tests.ts @@ -148,8 +148,6 @@ shell.chmod("u+x", "/Users/brandon"); shell.chmod("-cR", 755, "/Users/brandon"); shell.chmod("-Rv", "u+x", "/Users/brandon"); -shell.exit(0); - shell.touch("/Users/brandom/test1"); shell.touch("/Users/brandom/test1", "/Users/brandom/test2"); @@ -206,3 +204,13 @@ const farr = new shell.ShellString(["hello", "world"]); const boo = shell.ShellString("hello world"); const barr = shell.ShellString(["hello", "world"]); + +require("shelljs/make"); + +// global works +cp("some/path", "/tmp/dst/"); +target.all = () => { + ln("-sf", "some/path", "/tmp/dst"); +}; + +shell.exit(0); diff --git a/types/shelljs/tsconfig.json b/types/shelljs/tsconfig.json index 8d9284b3333466..02183e5cb4d4c3 100644 --- a/types/shelljs/tsconfig.json +++ b/types/shelljs/tsconfig.json @@ -14,6 +14,9 @@ }, "files": [ "index.d.ts", + "global.d.ts", + "make.d.ts", + "plugin.d.ts", "shelljs-tests.ts" ] } diff --git a/types/w3c-screen-capture/.npmignore b/types/w3c-screen-capture/.npmignore new file mode 100644 index 00000000000000..93e307400a5456 --- /dev/null +++ b/types/w3c-screen-capture/.npmignore @@ -0,0 +1,5 @@ +* +!**/*.d.ts +!**/*.d.cts +!**/*.d.mts +!**/*.d.*.ts diff --git a/types/w3c-screen-capture/index.d.ts b/types/w3c-screen-capture/index.d.ts new file mode 100644 index 00000000000000..3195a0827aa5b1 --- /dev/null +++ b/types/w3c-screen-capture/index.d.ts @@ -0,0 +1,108 @@ +/** + * @see https://w3c.github.io/mediacapture-screen-share + */ + +declare global { + interface MediaDevices { + getDisplayMedia(options?: DisplayMediaStreamOptions): Promise; + } +} + +export interface UserMediaStreamConstraints { + /** @default false */ + video?: boolean | MediaTrackConstraints; + /** @default false */ + audio?: boolean | MediaTrackConstraints; +} + +export type CaptureStartFocusBehavior = + | "focus-capturing-application" + | "focus-captured-surface" + | "no-focus-change"; + +declare global { + class CaptureController extends EventTarget { + constructor(); + setFocusBehavior(focusBehavior: CaptureStartFocusBehavior): void; + } +} + +export type SelfCapturePreferenceEnum = + | "include" + | "exclude"; + +export type SystemAudioPreferenceEnum = + | "include" + | "exclude"; + +export type WindowAudioPreferenceEnum = + | "system" + | "window" + | "exclude"; + +export type SurfaceSwitchingPreferenceEnum = + | "include" + | "exclude"; + +export type MonitorTypeSurfacesEnum = + | "include" + | "exclude"; + +export interface DisplayMediaStreamOptions { + /** @default true */ + video?: boolean | MediaTrackConstraints; + /** @default false */ + audio?: boolean | MediaTrackConstraints; + controller?: CaptureController; + selfBrowserSurface?: SelfCapturePreferenceEnum; + systemAudio?: SystemAudioPreferenceEnum; + windowAudio?: WindowAudioPreferenceEnum; + surfaceSwitching?: SurfaceSwitchingPreferenceEnum; + monitorTypeSurfaces?: MonitorTypeSurfacesEnum; +} + +export interface MediaTrackSupportedConstraints { + /** @default true */ + displaySurface?: boolean; + /** @default true */ + logicalSurface?: boolean; + /** @default true */ + cursor?: boolean; + /** @default true */ + restrictOwnAudio?: boolean; + /** @default true */ + suppressLocalAudioPlayback?: boolean; +} + +export interface MediaTrackConstraintSet { + displaySurface?: ConstrainDOMString; + logicalSurface?: ConstrainBoolean; + cursor?: ConstrainDOMString; + restrictOwnAudio?: ConstrainBoolean; + suppressLocalAudioPlayback?: ConstrainBoolean; +} + +export interface MediaTrackSettings { + displaySurface?: string; + logicalSurface?: boolean; + cursor?: string; + restrictOwnAudio?: boolean; + suppressLocalAudioPlayback?: boolean; + screenPixelRatio?: number; +} + +export interface MediaTrackCapabilities { + displaySurface?: string; + logicalSurface?: boolean; + cursor?: string[]; +} + +export type DisplayCaptureSurfaceType = + | "monitor" + | "window" + | "browser"; + +export type CursorCaptureConstraint = + | "never" + | "always" + | "motion"; diff --git a/types/w3c-screen-capture/package.json b/types/w3c-screen-capture/package.json new file mode 100644 index 00000000000000..2ab2000ee18f41 --- /dev/null +++ b/types/w3c-screen-capture/package.json @@ -0,0 +1,28 @@ +{ + "private": true, + "nonNpm": true, + "nonNpmDescription": "Implementation of Isolated Web App (IWA) APIs resides in Chromium.", + "name": "@types/w3c-screen-capture", + "version": "0.0.9999", + "projects": [ + "https://github.com/WICG/isolated-web-apps" + ], + "devDependencies": { + "@types/web": "*", + "@types/w3c-screen-capture": "workspace:." + }, + "owners": [ + { + "name": "Paulina Gacek", + "githubUsername": "paulinagacek" + }, + { + "name": "Andrew Rayskiy", + "githubUsername": "GrapeGreen" + }, + { + "name": "Simon Hangl", + "githubUsername": "shangl" + } + ] +} diff --git a/types/w3c-screen-capture/tsconfig.json b/types/w3c-screen-capture/tsconfig.json new file mode 100644 index 00000000000000..9b73197fd1ee94 --- /dev/null +++ b/types/w3c-screen-capture/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "module": "node16", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "paths": { + "w3c-screen-capture": [ + "./index.d.ts" + ] + } + }, + "files": [ + "index.d.ts", + "w3c-screen-capture-tests.ts" + ] +} diff --git a/types/w3c-screen-capture/w3c-screen-capture-tests.ts b/types/w3c-screen-capture/w3c-screen-capture-tests.ts new file mode 100644 index 00000000000000..6df23580e38615 --- /dev/null +++ b/types/w3c-screen-capture/w3c-screen-capture-tests.ts @@ -0,0 +1,70 @@ +import { DisplayMediaStreamOptions, MediaTrackConstraintSet } from "w3c-screen-capture"; + +function testCaptureController() { + const controller = new CaptureController(); + + // Valid behaviors + // $ExpectType void + controller.setFocusBehavior("focus-captured-surface"); + + // $ExpectType void + controller.setFocusBehavior("focus-capturing-application"); + + // $ExpectType void + controller.setFocusBehavior("no-focus-change"); + + // Inheritance check (EventTarget) + controller.addEventListener("focus", () => {}); + + // @ts-expect-error - Invalid enum value + controller.setFocusBehavior("focus-unknown"); +} + +async function testGetDisplayMedia() { + const controller = new CaptureController(); + + const options: DisplayMediaStreamOptions = { + video: true, + audio: false, + + // Advanced Enum preferences + controller: controller, + selfBrowserSurface: "include", + systemAudio: "exclude", + windowAudio: "window", + surfaceSwitching: "include", + monitorTypeSurfaces: "exclude", + }; + + const stream = await navigator.mediaDevices.getDisplayMedia(options); + const track = stream.getTracks()[0]; + track.stop(); +} + +function testConstraints() { + // Verifying the extension of constraints + const constraints: MediaTrackConstraintSet = { + // New Screen Share specific constraints + displaySurface: "monitor", + logicalSurface: true, + cursor: "motion", + restrictOwnAudio: false, + suppressLocalAudioPlayback: true, + }; + + const complexOptions: DisplayMediaStreamOptions = { + video: constraints, + audio: { echoCancellation: true }, + }; +} + +function testSettings(track: MediaStreamTrack) { + const settings: MediaTrackSettings = track.getSettings(); + + if (settings.displaySurface === "window") { + console.log("Captured a window"); + } + + // @ts-expect-error - Type 'number' is not comparable to type 'string' + if (settings.cursor === 123) {} +}