initial commit taken from gitlab.lrz.de

This commit is contained in:
privatereese
2018-08-24 18:09:42 +02:00
parent ae54ed4c48
commit fc05486403
28494 changed files with 2159823 additions and 0 deletions

77
node_modules/metro-cache/package.json generated vendored Normal file
View File

@@ -0,0 +1,77 @@
{
"_args": [
[
"metro-cache@0.30.2",
"/home/bernhard/freifunk-app/node_modules/metro"
]
],
"_from": "metro-cache@0.30.2",
"_id": "metro-cache@0.30.2",
"_inCache": true,
"_installable": true,
"_location": "/metro-cache",
"_nodeVersion": "8.9.4",
"_npmOperationalInternal": {
"host": "s3://npm-registry-packages",
"tmp": "tmp/metro-cache_0.30.2_1521165817058_0.9667348655666237"
},
"_npmUser": {
"email": "rafeca@gmail.com",
"name": "rafeca"
},
"_npmVersion": "5.6.0",
"_phantomChildren": {},
"_requested": {
"name": "metro-cache",
"raw": "metro-cache@0.30.2",
"rawSpec": "0.30.2",
"scope": null,
"spec": "0.30.2",
"type": "version"
},
"_requiredBy": [
"/metro"
],
"_resolved": "https://registry.npmjs.org/metro-cache/-/metro-cache-0.30.2.tgz",
"_shasum": "1fb1ff92d3d8c596fd8cddc1635a9cb1c26e4cba",
"_shrinkwrap": null,
"_spec": "metro-cache@0.30.2",
"_where": "/home/bernhard/freifunk-app/node_modules/metro",
"bugs": {
"url": "https://github.com/facebook/metro/issues"
},
"dependencies": {
"jest-serializer": "^22.4.0",
"mkdirp": "^0.5.1"
},
"description": "🚇 Cache layers for Metro",
"devDependencies": {},
"directories": {},
"dist": {
"fileCount": 22,
"integrity": "sha512-XYd07OwgtZRHFXyip40wdNJ8abPJRziuE5bb3jjf8wvyHxCpzlZlvbe0ZhcR8ChBwFUjHMuVyoou52AC3a0f+g==",
"shasum": "1fb1ff92d3d8c596fd8cddc1635a9cb1c26e4cba",
"tarball": "https://registry.npmjs.org/metro-cache/-/metro-cache-0.30.2.tgz",
"unpackedSize": 26429
},
"homepage": "https://github.com/facebook/metro#readme",
"main": "src/index.js",
"maintainers": [
{
"name": "rafeca",
"email": "rafeca@gmail.com"
}
],
"name": "metro-cache",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+ssh://git@github.com/facebook/metro.git"
},
"scripts": {
"cleanup-release": "test ! -e build && mv src build && mv src.real src",
"prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src"
},
"version": "0.30.2"
}

64
node_modules/metro-cache/src.real/Cache.js generated vendored Normal file
View File

@@ -0,0 +1,64 @@
/**
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
import type {CacheStore} from 'metro-cache';
class Cache<T> {
_stores: $ReadOnlyArray<CacheStore<T>>;
_hits: WeakMap<Buffer, CacheStore<T>>;
constructor(stores: $ReadOnlyArray<CacheStore<T>>) {
this._hits = new WeakMap();
this._stores = stores;
}
async get(key: Buffer): Promise<?T> {
const stores = this._stores;
const length = stores.length;
for (let i = 0; i < length; i++) {
let value = stores[i].get(key);
if (value instanceof Promise) {
value = await value;
}
if (value != null) {
this._hits.set(key, stores[i]);
return value;
}
}
return null;
}
set(key: Buffer, value: T): void {
const stores = this._stores;
const stop = this._hits.get(key);
const length = stores.length;
const promises = [];
for (let i = 0; i < length && stores[i] !== stop; i++) {
promises.push(stores[i].set(key, value));
}
Promise.all(promises).catch(err => {
process.nextTick(() => {
throw err;
});
});
}
}
module.exports = Cache;

77
node_modules/metro-cache/src.real/FileStore.js generated vendored Normal file
View File

@@ -0,0 +1,77 @@
/**
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/
'use strict';
const fs = require('fs');
const mkdirp = require('mkdirp');
const path = require('path');
import type {TransformedCode} from 'metro/src/JSTransformer/worker';
export type Options = {|
root: string,
|};
const JOINER_DATA = '\0\0';
const JOINER_LIST = '\0';
class FileStore {
_root: string;
constructor(options: Options) {
const root = options.root;
for (let i = 0; i < 256; i++) {
mkdirp.sync(path.join(root, ('0' + i.toString(16)).slice(-2)));
}
this._root = root;
}
get(key: Buffer): ?TransformedCode {
try {
const data = fs.readFileSync(this._getFilePath(key), 'utf8');
const [code, dependencies, map] = data.split(JOINER_DATA);
return {
code,
dependencies: dependencies ? dependencies.split(JOINER_LIST) : [],
map: JSON.parse(map),
};
} catch (err) {
if (err.code === 'ENOENT') {
return null;
}
throw err;
}
}
set(key: Buffer, value: TransformedCode): void {
const data = [
value.code,
value.dependencies.join(JOINER_LIST),
JSON.stringify(value.map),
].join(JOINER_DATA);
fs.writeFileSync(this._getFilePath(key), data);
}
_getFilePath(key: Buffer): string {
return path.join(
this._root,
key.slice(0, 1).toString('hex'),
key.slice(1).toString('hex'),
);
}
}
module.exports = FileStore;

75
node_modules/metro-cache/src.real/PersistedMapStore.js generated vendored Normal file
View File

@@ -0,0 +1,75 @@
/**
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/
'use strict';
const fs = require('fs');
const serializer = require('jest-serializer');
export type Options = {|
path: string,
writeDelay: ?number,
|};
class PersistedMapStore {
_map: ?Map<string, mixed>;
_path: string;
_store: () => void;
_timeout: ?TimeoutID;
_writeDelay: number;
constructor(options: Options) {
this._path = options.path;
this._writeDelay = options.writeDelay || 5000;
this._store = this._store.bind(this);
this._timeout = null;
this._map = null;
}
get(key: Buffer): mixed {
this._getMap();
if (this._map) {
return this._map.get(key.toString('hex'));
}
return null;
}
set(key: Buffer, value: mixed) {
this._getMap();
if (this._map) {
this._map.set(key.toString('hex'), value);
}
if (!this._timeout) {
this._timeout = setTimeout(this._store, this._writeDelay);
}
}
_getMap() {
if (!this._map) {
if (fs.existsSync(this._path)) {
this._map = serializer.readFileSync(this._path);
} else {
this._map = new Map();
}
}
}
_store() {
serializer.writeFileSync(this._path, this._map);
this._timeout = null;
}
}
module.exports = PersistedMapStore;

View File

@@ -0,0 +1,140 @@
/**
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails oncall+javascript_foundation
* @format
* @flow
*/
'use strict';
const Cache = require('../Cache');
describe('Cache', () => {
function createStore(i) {
return {
get: jest.fn().mockImplementation(() => null),
set: jest.fn(),
};
}
afterEach(() => {
jest.restoreAllMocks();
});
it('returns null when no result is found', async () => {
const store1 = createStore();
const store2 = createStore();
const cache = new Cache([store1, store2]);
// Calling a wrapped method.
const result = await cache.get(Buffer.from('foo'));
expect(result).toBe(null);
expect(store1.get).toHaveBeenCalledTimes(1);
expect(store2.get).toHaveBeenCalledTimes(1);
});
it('sequentially searches up until it finds a valid result', async () => {
const store1 = createStore(1);
const store2 = createStore(2);
const store3 = createStore(3);
const cache = new Cache([store1, store2, store3]);
// Only cache 2 can return results.
store2.get.mockImplementation(() => 'hit!');
const result = await cache.get(Buffer.from('foo'));
expect(result).toBe('hit!');
expect(store1.get).toHaveBeenCalledTimes(1);
expect(store2.get).toHaveBeenCalledTimes(1);
expect(store3.get).not.toHaveBeenCalled();
});
it('skips all cache stores when a hit is produced, based on the same key', () => {
const store1 = createStore();
const store2 = createStore();
const store3 = createStore();
const cache = new Cache([store1, store2, store3]);
const key = Buffer.from('foo');
store2.get.mockImplementation(() => 'hit!');
// Get and set. Set should only affect store 1, not 2 (hit) and 3 (after).
cache.get(key);
cache.set(key);
expect(store1.set).toHaveBeenCalledTimes(1);
expect(store2.set).not.toHaveBeenCalled();
expect(store3.set).not.toHaveBeenCalled();
});
it('awaits for promises on stores, even if they return undefined', async () => {
let resolve;
const store1 = createStore();
const store2 = createStore();
const promise = new Promise((res, rej) => (resolve = res));
const cache = new Cache([store1, store2]);
store1.get.mockImplementation(() => promise);
const get = cache.get(Buffer.from('foo'));
// Store 1 returns a promise, so store 2 is not called until it resolves.
expect(store1.get).toHaveBeenCalledTimes(1);
expect(store2.get).not.toHaveBeenCalled();
if (!resolve) {
throw new Error('Flow needs this');
}
resolve(undefined);
await Promise.all([promise, get]);
expect(store1.get).toHaveBeenCalledTimes(1);
expect(store2.get).toHaveBeenCalledTimes(1);
});
it('throws on a buggy store set', async () => {
jest.useFakeTimers();
const store1 = createStore();
const store2 = createStore();
const cache = new Cache([store1, store2]);
let error = null;
store1.set.mockImplementation(() => null);
store2.set.mockImplementation(() => Promise.reject(new RangeError('foo')));
try {
cache.set(Buffer.from('foo'), 'arg');
jest.runAllTimers();
} catch (err) {
error = err;
}
expect(error).toBeInstanceOf(RangeError);
});
it('throws on a buggy store get', async () => {
const store1 = createStore();
const store2 = createStore();
const cache = new Cache([store1, store2]);
let error = null;
store1.get.mockImplementation(() => null);
store2.get.mockImplementation(() => Promise.reject(new TypeError('bar')));
try {
await cache.get(Buffer.from('foo'));
} catch (err) {
error = err;
}
expect(error).toBeInstanceOf(TypeError);
});
});

View File

@@ -0,0 +1,121 @@
/**
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails oncall+javascript_foundation
* @format
*/
'use strict';
describe('PersistedMapStore', () => {
const key1 = Buffer.from('foo');
const key2 = Buffer.from('bar');
let now;
let serializer;
let fs;
let PersistedMapStore;
function advance(time) {
now += time;
jest.advanceTimersByTime(time);
}
Date.now = () => now;
beforeEach(() => {
jest
.resetModules()
.resetAllMocks()
.useFakeTimers();
jest.mock('fs', () => ({
existsSync: jest.fn(),
}));
jest.mock('jest-serializer', () => ({
readFileSync: jest.fn(),
writeFileSync: jest.fn(),
}));
fs = require('fs');
serializer = require('jest-serializer');
PersistedMapStore = require('../PersistedMapStore');
now = 0;
});
it('ensures that the persisted map file is checked first', () => {
const store = new PersistedMapStore({path: '/foo'});
fs.existsSync.mockReturnValue(false);
store.get(key1);
expect(fs.existsSync).toHaveBeenCalledTimes(1);
expect(serializer.readFileSync).not.toBeCalled();
});
it('loads the file when it exists', () => {
const store = new PersistedMapStore({path: '/foo'});
fs.existsSync.mockReturnValue(true);
serializer.readFileSync.mockReturnValue(new Map());
store.get(key1);
expect(fs.existsSync).toHaveBeenCalledTimes(1);
expect(serializer.readFileSync).toHaveBeenCalledTimes(1);
expect(serializer.readFileSync.mock.calls[0]).toEqual(['/foo']);
});
it('throws if the file is invalid', () => {
const store = new PersistedMapStore({path: '/foo'});
fs.existsSync.mockReturnValue(true);
serializer.readFileSync.mockImplementation(() => {
throw new Error();
});
expect(() => store.get(key1)).toThrow();
});
it('deserializes and serializes correctly from/to disk', () => {
let file;
fs.existsSync.mockReturnValue(false);
serializer.readFileSync.mockImplementation(() => file);
serializer.writeFileSync.mockImplementation((_, data) => (file = data));
const store1 = new PersistedMapStore({path: '/foo'});
store1.set(key1, 'value1');
store1.set(key2, 123456);
// Force throttle to kick in and perform the file storage.
advance(7500);
fs.existsSync.mockReturnValue(true);
const store2 = new PersistedMapStore({path: '/foo'});
expect(store2.get(key1)).toBe('value1');
expect(store2.get(key2)).toBe(123456);
});
it('ensures that the throttling is working correctly', () => {
const store1 = new PersistedMapStore({
path: '/foo',
writeDelay: 1234,
});
// Triggers the write, multiple times (only one write should happen).
store1.set(key1, 'foo');
store1.set(key1, 'bar');
store1.set(key1, 'baz');
advance(1233);
expect(serializer.writeFileSync).toHaveBeenCalledTimes(0);
advance(1);
expect(serializer.writeFileSync).toHaveBeenCalledTimes(1);
});
});

View File

@@ -0,0 +1,37 @@
/**
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails oncall+javascript_foundation
* @format
*/
'use strict';
const stableHash = require('../stableHash');
describe('stableHash', () => {
it('ensures that the hash implementation supports switched order properties', () => {
const sortedHash = stableHash({
a: 3,
b: 4,
c: {
d: 'd',
e: 'e',
},
});
const unsortedHash = stableHash({
b: 4,
c: {
e: 'e',
d: 'd',
},
a: 3,
});
expect(unsortedHash).toEqual(sortedHash);
});
});

22
node_modules/metro-cache/src.real/index.js generated vendored Normal file
View File

@@ -0,0 +1,22 @@
/**
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
const Cache = require('./Cache');
const FileStore = require('./FileStore');
const stableHash = require('./stableHash');
export type {CacheStore} from './types.flow';
module.exports.Cache = Cache;
module.exports.FileStore = FileStore;
module.exports.stableHash = stableHash;

38
node_modules/metro-cache/src.real/stableHash.js generated vendored Normal file
View File

@@ -0,0 +1,38 @@
/**
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
const crypto = require('crypto');
function canonicalize(key: string, value: mixed): mixed {
if (!(value instanceof Object) || value instanceof Array) {
return value;
}
const keys = Object.keys(value).sort();
const length = keys.length;
const object = {};
for (let i = 0; i < length; i++) {
object[keys[i]] = value[keys[i]];
}
return object;
}
function stableHash(value: mixed) {
return crypto
.createHash('md4')
.update(JSON.stringify(value, canonicalize))
.digest();
}
module.exports = stableHash;

16
node_modules/metro-cache/src.real/types.flow.js generated vendored Normal file
View File

@@ -0,0 +1,16 @@
/**
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
export type CacheStore<T> = {
get(key: Buffer): ?T | Promise<?T>,
set(key: Buffer, value: T): void | Promise<void>,
};

64
node_modules/metro-cache/src/Cache.js generated vendored Normal file
View File

@@ -0,0 +1,64 @@
/**
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
*/
'use strict';function _asyncToGenerator(fn) {return function () {var gen = fn.apply(this, arguments);return new Promise(function (resolve, reject) {function step(key, arg) {try {var info = gen[key](arg);var value = info.value;} catch (error) {reject(error);return;}if (info.done) {resolve(value);} else {return Promise.resolve(value).then(function (value) {step("next", value);}, function (err) {step("throw", err);});}}return step("next");});};}
class Cache {
constructor(stores) {
this._hits = new WeakMap();
this._stores = stores;
}
get(key) {var _this = this;return _asyncToGenerator(function* () {
const stores = _this._stores;
const length = stores.length;
for (let i = 0; i < length; i++) {
let value = stores[i].get(key);
if (value instanceof Promise) {
value = yield value;
}
if (value != null) {
_this._hits.set(key, stores[i]);
return value;
}
}
return null;})();
}
set(key, value) {
const stores = this._stores;
const stop = this._hits.get(key);
const length = stores.length;
const promises = [];
for (let i = 0; i < length && stores[i] !== stop; i++) {
promises.push(stores[i].set(key, value));
}
Promise.all(promises).catch(err => {
process.nextTick(() => {
throw err;
});
});
}}
module.exports = Cache;

64
node_modules/metro-cache/src/Cache.js.flow generated vendored Normal file
View File

@@ -0,0 +1,64 @@
/**
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
import type {CacheStore} from 'metro-cache';
class Cache<T> {
_stores: $ReadOnlyArray<CacheStore<T>>;
_hits: WeakMap<Buffer, CacheStore<T>>;
constructor(stores: $ReadOnlyArray<CacheStore<T>>) {
this._hits = new WeakMap();
this._stores = stores;
}
async get(key: Buffer): Promise<?T> {
const stores = this._stores;
const length = stores.length;
for (let i = 0; i < length; i++) {
let value = stores[i].get(key);
if (value instanceof Promise) {
value = await value;
}
if (value != null) {
this._hits.set(key, stores[i]);
return value;
}
}
return null;
}
set(key: Buffer, value: T): void {
const stores = this._stores;
const stop = this._hits.get(key);
const length = stores.length;
const promises = [];
for (let i = 0; i < length && stores[i] !== stop; i++) {
promises.push(stores[i].set(key, value));
}
Promise.all(promises).catch(err => {
process.nextTick(() => {
throw err;
});
});
}
}
module.exports = Cache;

77
node_modules/metro-cache/src/FileStore.js generated vendored Normal file
View File

@@ -0,0 +1,77 @@
/**
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
*/
'use strict';var _slicedToArray = function () {function sliceIterator(arr, i) {var _arr = [];var _n = true;var _d = false;var _e = undefined;try {for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {_arr.push(_s.value);if (i && _arr.length === i) break;}} catch (err) {_d = true;_e = err;} finally {try {if (!_n && _i["return"]) _i["return"]();} finally {if (_d) throw _e;}}return _arr;}return function (arr, i) {if (Array.isArray(arr)) {return arr;} else if (Symbol.iterator in Object(arr)) {return sliceIterator(arr, i);} else {throw new TypeError("Invalid attempt to destructure non-iterable instance");}};}();
const fs = require('fs');
const mkdirp = require('mkdirp');
const path = require('path');
const JOINER_DATA = '\0\0';
const JOINER_LIST = '\0';
class FileStore {
constructor(options) {
const root = options.root;
for (let i = 0; i < 256; i++) {
mkdirp.sync(path.join(root, ('0' + i.toString(16)).slice(-2)));
}
this._root = root;
}
get(key) {
try {
const data = fs.readFileSync(this._getFilePath(key), 'utf8');var _data$split =
data.split(JOINER_DATA),_data$split2 = _slicedToArray(_data$split, 3);const code = _data$split2[0],dependencies = _data$split2[1],map = _data$split2[2];
return {
code,
dependencies: dependencies ? dependencies.split(JOINER_LIST) : [],
map: JSON.parse(map) };
} catch (err) {
if (err.code === 'ENOENT') {
return null;
}
throw err;
}
}
set(key, value) {
const data = [
value.code,
value.dependencies.join(JOINER_LIST),
JSON.stringify(value.map)].
join(JOINER_DATA);
fs.writeFileSync(this._getFilePath(key), data);
}
_getFilePath(key) {
return path.join(
this._root,
key.slice(0, 1).toString('hex'),
key.slice(1).toString('hex'));
}}
module.exports = FileStore;

77
node_modules/metro-cache/src/FileStore.js.flow generated vendored Normal file
View File

@@ -0,0 +1,77 @@
/**
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/
'use strict';
const fs = require('fs');
const mkdirp = require('mkdirp');
const path = require('path');
import type {TransformedCode} from 'metro/src/JSTransformer/worker';
export type Options = {|
root: string,
|};
const JOINER_DATA = '\0\0';
const JOINER_LIST = '\0';
class FileStore {
_root: string;
constructor(options: Options) {
const root = options.root;
for (let i = 0; i < 256; i++) {
mkdirp.sync(path.join(root, ('0' + i.toString(16)).slice(-2)));
}
this._root = root;
}
get(key: Buffer): ?TransformedCode {
try {
const data = fs.readFileSync(this._getFilePath(key), 'utf8');
const [code, dependencies, map] = data.split(JOINER_DATA);
return {
code,
dependencies: dependencies ? dependencies.split(JOINER_LIST) : [],
map: JSON.parse(map),
};
} catch (err) {
if (err.code === 'ENOENT') {
return null;
}
throw err;
}
}
set(key: Buffer, value: TransformedCode): void {
const data = [
value.code,
value.dependencies.join(JOINER_LIST),
JSON.stringify(value.map),
].join(JOINER_DATA);
fs.writeFileSync(this._getFilePath(key), data);
}
_getFilePath(key: Buffer): string {
return path.join(
this._root,
key.slice(0, 1).toString('hex'),
key.slice(1).toString('hex'),
);
}
}
module.exports = FileStore;

75
node_modules/metro-cache/src/PersistedMapStore.js generated vendored Normal file
View File

@@ -0,0 +1,75 @@
/**
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*
*/
'use strict';
const fs = require('fs');
const serializer = require('jest-serializer');
class PersistedMapStore {
constructor(options) {
this._path = options.path;
this._writeDelay = options.writeDelay || 5000;
this._store = this._store.bind(this);
this._timeout = null;
this._map = null;
}
get(key) {
this._getMap();
if (this._map) {
return this._map.get(key.toString('hex'));
}
return null;
}
set(key, value) {
this._getMap();
if (this._map) {
this._map.set(key.toString('hex'), value);
}
if (!this._timeout) {
this._timeout = setTimeout(this._store, this._writeDelay);
}
}
_getMap() {
if (!this._map) {
if (fs.existsSync(this._path)) {
this._map = serializer.readFileSync(this._path);
} else {
this._map = new Map();
}
}
}
_store() {
serializer.writeFileSync(this._path, this._map);
this._timeout = null;
}}
module.exports = PersistedMapStore;

75
node_modules/metro-cache/src/PersistedMapStore.js.flow generated vendored Normal file
View File

@@ -0,0 +1,75 @@
/**
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/
'use strict';
const fs = require('fs');
const serializer = require('jest-serializer');
export type Options = {|
path: string,
writeDelay: ?number,
|};
class PersistedMapStore {
_map: ?Map<string, mixed>;
_path: string;
_store: () => void;
_timeout: ?TimeoutID;
_writeDelay: number;
constructor(options: Options) {
this._path = options.path;
this._writeDelay = options.writeDelay || 5000;
this._store = this._store.bind(this);
this._timeout = null;
this._map = null;
}
get(key: Buffer): mixed {
this._getMap();
if (this._map) {
return this._map.get(key.toString('hex'));
}
return null;
}
set(key: Buffer, value: mixed) {
this._getMap();
if (this._map) {
this._map.set(key.toString('hex'), value);
}
if (!this._timeout) {
this._timeout = setTimeout(this._store, this._writeDelay);
}
}
_getMap() {
if (!this._map) {
if (fs.existsSync(this._path)) {
this._map = serializer.readFileSync(this._path);
} else {
this._map = new Map();
}
}
}
_store() {
serializer.writeFileSync(this._path, this._map);
this._timeout = null;
}
}
module.exports = PersistedMapStore;

22
node_modules/metro-cache/src/index.js generated vendored Normal file
View File

@@ -0,0 +1,22 @@
/**
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
*/
'use strict';
const Cache = require('./Cache');
const FileStore = require('./FileStore');
const stableHash = require('./stableHash');
module.exports.Cache = Cache;
module.exports.FileStore = FileStore;
module.exports.stableHash = stableHash;

22
node_modules/metro-cache/src/index.js.flow generated vendored Normal file
View File

@@ -0,0 +1,22 @@
/**
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
const Cache = require('./Cache');
const FileStore = require('./FileStore');
const stableHash = require('./stableHash');
export type {CacheStore} from './types.flow';
module.exports.Cache = Cache;
module.exports.FileStore = FileStore;
module.exports.stableHash = stableHash;

38
node_modules/metro-cache/src/stableHash.js generated vendored Normal file
View File

@@ -0,0 +1,38 @@
/**
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
*/
'use strict';
const crypto = require('crypto');
function canonicalize(key, value) {
if (!(value instanceof Object) || value instanceof Array) {
return value;
}
const keys = Object.keys(value).sort();
const length = keys.length;
const object = {};
for (let i = 0; i < length; i++) {
object[keys[i]] = value[keys[i]];
}
return object;
}
function stableHash(value) {
return crypto.
createHash('md4').
update(JSON.stringify(value, canonicalize)).
digest();
}
module.exports = stableHash;

38
node_modules/metro-cache/src/stableHash.js.flow generated vendored Normal file
View File

@@ -0,0 +1,38 @@
/**
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
const crypto = require('crypto');
function canonicalize(key: string, value: mixed): mixed {
if (!(value instanceof Object) || value instanceof Array) {
return value;
}
const keys = Object.keys(value).sort();
const length = keys.length;
const object = {};
for (let i = 0; i < length; i++) {
object[keys[i]] = value[keys[i]];
}
return object;
}
function stableHash(value: mixed) {
return crypto
.createHash('md4')
.update(JSON.stringify(value, canonicalize))
.digest();
}
module.exports = stableHash;

11
node_modules/metro-cache/src/types.flow.js generated vendored Normal file
View File

@@ -0,0 +1,11 @@
/**
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
* @format
*/
'use strict';

16
node_modules/metro-cache/src/types.flow.js.flow generated vendored Normal file
View File

@@ -0,0 +1,16 @@
/**
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
export type CacheStore<T> = {
get(key: Buffer): ?T | Promise<?T>,
set(key: Buffer, value: T): void | Promise<void>,
};