-
Notifications
You must be signed in to change notification settings - Fork 637
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add and configure TypeScript, migrate .d.ts files for metro-cache
Summary: Configures repository to support TypeScript definitions inside each package directory under `types/`. This is an interim structure which preserves the current types and paths from DefinitelyTyped. In future, we may shift to inline definitions, or (more likely) auto-translated types when the [flow-api-translator](https://www.npmjs.com/package/flow-api-translator) tool is more mature. - Add `[email protected]` and configure project file. - Add step to `scripts/build.js` to copy TypeScript definitions (`.d.ts`) across to distributed code. - Add `yarn typecheck-ts` script and add to CircleCI. - Add and configure `typescript-eslint` against `types/` directories. - Migrates TypeScript definitions for `metro-cache` (self-contained package types), from DefinitelyTyped, used to validate all changes. Changelog: **[Types]** Add bundled TypeScript definitions (partial) for metro-cache Reviewed By: motiz88 Differential Revision: D44133264 fbshipit-source-id: b9b56cd751670964b57400bd9c63155349f78e81
- Loading branch information
1 parent
b752459
commit c022c36
Showing
16 changed files
with
352 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,5 @@ docs/ | |
examples/react-native | ||
flow-typed/** | ||
packages/*/build/** | ||
types/** | ||
website/ | ||
**/third-party/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
import {CacheStore} from './types'; | ||
|
||
/** | ||
* Main cache class. Receives an array of cache instances, and sequentially | ||
* traverses them to return a previously stored value. It also ensures setting | ||
* the value in all instances. | ||
* | ||
* All get/set operations are logged via Metro's logger. | ||
*/ | ||
export default class Cache<T> { | ||
constructor(stores: ReadonlyArray<CacheStore<T>>); | ||
get(key: Buffer): Promise<T | null>; | ||
set(key: Buffer, value: T): void; | ||
get isDisabled(): boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
// <reference types="node" /> | ||
|
||
import AutoCleanFileStore from './stores/AutoCleanFileStore'; | ||
import FileStore from './stores/FileStore'; | ||
import HttpGetStore from './stores/HttpGetStore'; | ||
import HttpStore from './stores/HttpStore'; | ||
import Cache from './Cache'; | ||
import stableHash from './stableHash'; | ||
|
||
export type {Options as FileOptions} from './stores/FileStore'; | ||
export type {Options as HttpOptions} from './stores/HttpStore'; | ||
export type {CacheStore} from './types'; | ||
|
||
export interface MetroCache { | ||
AutoCleanFileStore: typeof AutoCleanFileStore; | ||
Cache: typeof Cache; | ||
FileStore: typeof FileStore; | ||
HttpGetStore: typeof HttpGetStore; | ||
HttpStore: typeof HttpStore; | ||
stableHash: typeof stableHash; | ||
} | ||
|
||
export { | ||
AutoCleanFileStore, | ||
Cache, | ||
FileStore, | ||
HttpGetStore, | ||
HttpStore, | ||
stableHash, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
export default function stableHash(value: unknown): Buffer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
import type FileStore from './FileStore'; | ||
|
||
export default class AutoCleanFileStore<T> extends FileStore<T> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
export interface Options { | ||
root: string; | ||
} | ||
|
||
export default class FileStore<T> { | ||
constructor(options: Options); | ||
get(key: Buffer): Promise<T | null>; | ||
set(key: Buffer, value: T): Promise<void>; | ||
clear(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
import type {Options} from './HttpStore'; | ||
|
||
export default class HttpGetStore<T> { | ||
constructor(options: Options); | ||
get(key: Buffer): Promise<T | null>; | ||
set(key: Buffer, value: T): Promise<void>; | ||
clear(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
export interface Options { | ||
endpoint: string; | ||
family?: 4 | 6; | ||
timeout?: number; | ||
key?: string | ReadonlyArray<string> | Buffer | ReadonlyArray<Buffer>; | ||
cert?: string | ReadonlyArray<string> | Buffer | ReadonlyArray<Buffer>; | ||
ca?: string | ReadonlyArray<string> | Buffer | ReadonlyArray<Buffer>; | ||
} | ||
|
||
export default class HttpStore<T> { | ||
constructor(options: Options); | ||
get(key: Buffer): Promise<T | null>; | ||
set(key: Buffer, value: T): Promise<void>; | ||
clear(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
export interface CacheStore<T> { | ||
get(key: Buffer): T | undefined | Promise<T> | Promise<undefined>; | ||
set(key: Buffer, value: T): void | Promise<void>; | ||
clear(): void | Promise<void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const path = require('path'); | ||
|
||
require('eslint-plugin-lint').load(path.join(__dirname, 'rules')); | ||
|
||
/** | ||
* ESLint config for TypeScript definition files (.d.ts). | ||
* | ||
* @type {import('eslint').Linter.Config} | ||
*/ | ||
module.exports = { | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
'plugin:prettier/recommended', | ||
], | ||
plugins: ['@typescript-eslint', 'prettier'], | ||
parser: '@typescript-eslint/parser', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "@tsconfig/node16/tsconfig.json", | ||
"include": ["./packages/*/types/**/*.d.ts"], | ||
"compilerOptions": { | ||
"noEmit": true, | ||
"baseUrl": ".", | ||
"skipLibCheck": false, | ||
"paths": { | ||
"metro": ["./packages/metro/types"], | ||
"metro/*": ["./packages/metro/types/*"], | ||
"metro-*": ["./packages/metro-*/types"] | ||
} | ||
} | ||
} |
Oops, something went wrong.