chore: add mobile app

This commit is contained in:
2026-02-07 22:33:02 +01:00
parent db34640acc
commit e89384ad4e
29327 changed files with 3886944 additions and 12 deletions
+22
View File
@@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2015-present 650 Industries, Inc. (aka Expo)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+29
View File
@@ -0,0 +1,29 @@
<!-- Title -->
<h1 align="center">
👋 Welcome to <br><code>@expo/json-file</code>
</h1>
<p align="center">A library for reading and writing JSON files.</p>
<!-- Body -->
## 🏁 Setup
Install `@expo/json-file` in your project.
```sh
yarn add @expo/json-file
```
## ⚽️ Usage
```ts
import JsonFile, { JSONObject } from '@expo/json-file';
// Create a file instance
const jsonFile = new JsonFile<JSONObject>(filePath);
// Interact with the file
await jsonFile.readAsync();
await jsonFile.writeAsync({ some: 'data' });
```
+82
View File
@@ -0,0 +1,82 @@
export type JSONValue = boolean | number | string | null | JSONArray | JSONObject;
export interface JSONArray extends Array<JSONValue> {
}
export interface JSONObject {
[key: string]: JSONValue | undefined;
}
type Defined<T> = T extends undefined ? never : T;
type Options<TJSONObject extends JSONObject> = {
badJsonDefault?: TJSONObject;
jsonParseErrorDefault?: TJSONObject;
cantReadFileDefault?: TJSONObject;
ensureDir?: boolean;
default?: TJSONObject;
json5?: boolean;
space?: number;
addNewLineAtEOF?: boolean;
};
/**
* The JsonFile class represents the contents of json file.
*
* It's polymorphic on "JSONObject", which is a simple type representing
* and object with string keys and either objects or primitive types as values.
* @type {[type]}
*/
export default class JsonFile<TJSONObject extends JSONObject> {
file: string;
options: Options<TJSONObject>;
static read: typeof read;
static readAsync: typeof readAsync;
static parseJsonString: typeof parseJsonString;
static write: typeof write;
static writeAsync: typeof writeAsync;
static get: typeof getSync;
static getAsync: typeof getAsync;
static set: typeof setSync;
static setAsync: typeof setAsync;
static merge: typeof merge;
static mergeAsync: typeof mergeAsync;
static deleteKey: typeof deleteKey;
static deleteKeyAsync: typeof deleteKeyAsync;
static deleteKeys: typeof deleteKeys;
static deleteKeysAsync: typeof deleteKeysAsync;
static rewrite: typeof rewrite;
static rewriteAsync: typeof rewriteAsync;
constructor(file: string, options?: Options<TJSONObject>);
read(options?: Options<TJSONObject>): TJSONObject;
readAsync(options?: Options<TJSONObject>): Promise<TJSONObject>;
write(object: TJSONObject, options?: Options<TJSONObject>): TJSONObject;
writeAsync(object: TJSONObject, options?: Options<TJSONObject>): Promise<TJSONObject>;
parseJsonString(json: string, options?: Options<TJSONObject>): TJSONObject;
get<K extends keyof TJSONObject, TDefault extends TJSONObject[K] | null>(key: K, defaultValue: TDefault, options?: Options<TJSONObject>): Defined<TJSONObject[K]> | TDefault;
getAsync<K extends keyof TJSONObject, TDefault extends TJSONObject[K] | null>(key: K, defaultValue: TDefault, options?: Options<TJSONObject>): Promise<Defined<TJSONObject[K]> | TDefault>;
set(key: string, value: unknown, options?: Options<TJSONObject>): TJSONObject;
setAsync(key: string, value: unknown, options?: Options<TJSONObject>): Promise<TJSONObject>;
merge(sources: Partial<TJSONObject> | Partial<TJSONObject>[], options?: Options<TJSONObject>): Promise<TJSONObject>;
mergeAsync(sources: Partial<TJSONObject> | Partial<TJSONObject>[], options?: Options<TJSONObject>): Promise<TJSONObject>;
deleteKey(key: string, options?: Options<TJSONObject>): TJSONObject;
deleteKeyAsync(key: string, options?: Options<TJSONObject>): Promise<TJSONObject>;
deleteKeys(keys: string[], options?: Options<TJSONObject>): TJSONObject;
deleteKeysAsync(keys: string[], options?: Options<TJSONObject>): Promise<TJSONObject>;
rewrite(options?: Options<TJSONObject>): TJSONObject;
rewriteAsync(options?: Options<TJSONObject>): Promise<TJSONObject>;
_getOptions(options?: Options<TJSONObject>): Options<TJSONObject>;
}
declare function read<TJSONObject extends JSONObject>(file: string, options?: Options<TJSONObject>): TJSONObject;
declare function readAsync<TJSONObject extends JSONObject>(file: string, options?: Options<TJSONObject>): Promise<TJSONObject>;
declare function parseJsonString<TJSONObject extends JSONObject>(json: string, options?: Options<TJSONObject>, fileName?: string): TJSONObject;
declare function getSync<TJSONObject extends JSONObject, K extends keyof TJSONObject, DefaultValue>(file: string, key: K, defaultValue: DefaultValue, options?: Options<TJSONObject>): any;
declare function getAsync<TJSONObject extends JSONObject, K extends keyof TJSONObject, DefaultValue>(file: string, key: K, defaultValue: DefaultValue, options?: Options<TJSONObject>): Promise<any>;
declare function write<TJSONObject extends JSONObject>(file: string, object: TJSONObject, options?: Options<TJSONObject>): TJSONObject;
declare function writeAsync<TJSONObject extends JSONObject>(file: string, object: TJSONObject, options?: Options<TJSONObject>): Promise<TJSONObject>;
declare function setSync<TJSONObject extends JSONObject>(file: string, key: string, value: unknown, options?: Options<TJSONObject>): TJSONObject;
declare function setAsync<TJSONObject extends JSONObject>(file: string, key: string, value: unknown, options?: Options<TJSONObject>): Promise<TJSONObject>;
declare function mergeAsync<TJSONObject extends JSONObject>(file: string, sources: Partial<TJSONObject> | Partial<TJSONObject>[], options?: Options<TJSONObject>): Promise<TJSONObject>;
declare function merge<TJSONObject extends JSONObject>(file: string, sources: Partial<TJSONObject> | Partial<TJSONObject>[], options?: Options<TJSONObject>): TJSONObject;
declare function deleteKeyAsync<TJSONObject extends JSONObject>(file: string, key: string, options?: Options<TJSONObject>): Promise<TJSONObject>;
declare function deleteKey<TJSONObject extends JSONObject>(file: string, key: string, options?: Options<TJSONObject>): TJSONObject;
declare function deleteKeysAsync<TJSONObject extends JSONObject>(file: string, keys: string[], options?: Options<TJSONObject>): Promise<TJSONObject>;
declare function deleteKeys<TJSONObject extends JSONObject>(file: string, keys: string[], options?: Options<TJSONObject>): TJSONObject;
declare function rewriteAsync<TJSONObject extends JSONObject>(file: string, options?: Options<TJSONObject>): Promise<TJSONObject>;
declare function rewrite<TJSONObject extends JSONObject>(file: string, options?: Options<TJSONObject>): TJSONObject;
export {};
+389
View File
@@ -0,0 +1,389 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const code_frame_1 = require("@babel/code-frame");
const json5_1 = __importDefault(require("json5"));
const node_fs_1 = __importDefault(require("node:fs"));
const node_path_1 = __importDefault(require("node:path"));
const JsonFileError_1 = __importStar(require("./JsonFileError"));
const writeAtomic_1 = require("./writeAtomic");
const DEFAULT_OPTIONS = {
badJsonDefault: undefined,
jsonParseErrorDefault: undefined,
cantReadFileDefault: undefined,
ensureDir: false,
default: undefined,
json5: false,
space: 2,
addNewLineAtEOF: true,
};
/**
* The JsonFile class represents the contents of json file.
*
* It's polymorphic on "JSONObject", which is a simple type representing
* and object with string keys and either objects or primitive types as values.
* @type {[type]}
*/
class JsonFile {
file;
options;
static read = read;
static readAsync = readAsync;
static parseJsonString = parseJsonString;
static write = write;
static writeAsync = writeAsync;
static get = getSync;
static getAsync = getAsync;
static set = setSync;
static setAsync = setAsync;
static merge = merge;
static mergeAsync = mergeAsync;
static deleteKey = deleteKey;
static deleteKeyAsync = deleteKeyAsync;
static deleteKeys = deleteKeys;
static deleteKeysAsync = deleteKeysAsync;
static rewrite = rewrite;
static rewriteAsync = rewriteAsync;
constructor(file, options = {}) {
this.file = file;
this.options = options;
}
read(options) {
return read(this.file, this._getOptions(options));
}
async readAsync(options) {
return readAsync(this.file, this._getOptions(options));
}
write(object, options) {
return write(this.file, object, this._getOptions(options));
}
async writeAsync(object, options) {
return writeAsync(this.file, object, this._getOptions(options));
}
parseJsonString(json, options) {
return parseJsonString(json, options);
}
get(key, defaultValue, options) {
return getSync(this.file, key, defaultValue, this._getOptions(options));
}
async getAsync(key, defaultValue, options) {
return getAsync(this.file, key, defaultValue, this._getOptions(options));
}
set(key, value, options) {
return setSync(this.file, key, value, this._getOptions(options));
}
async setAsync(key, value, options) {
return setAsync(this.file, key, value, this._getOptions(options));
}
async merge(sources, options) {
return merge(this.file, sources, this._getOptions(options));
}
async mergeAsync(sources, options) {
return mergeAsync(this.file, sources, this._getOptions(options));
}
deleteKey(key, options) {
return deleteKey(this.file, key, this._getOptions(options));
}
async deleteKeyAsync(key, options) {
return deleteKeyAsync(this.file, key, this._getOptions(options));
}
deleteKeys(keys, options) {
return deleteKeys(this.file, keys, this._getOptions(options));
}
async deleteKeysAsync(keys, options) {
return deleteKeysAsync(this.file, keys, this._getOptions(options));
}
rewrite(options) {
return rewrite(this.file, this._getOptions(options));
}
async rewriteAsync(options) {
return rewriteAsync(this.file, this._getOptions(options));
}
_getOptions(options) {
return {
...this.options,
...options,
};
}
}
exports.default = JsonFile;
function read(file, options) {
let json;
try {
json = node_fs_1.default.readFileSync(file, 'utf8');
}
catch (error) {
assertEmptyJsonString(json, file);
const defaultValue = cantReadFileDefault(options);
if (defaultValue === undefined) {
throw new JsonFileError_1.default(`Can't read JSON file: ${file}`, error, error.code, file);
}
else {
return defaultValue;
}
}
return parseJsonString(json, options, file);
}
async function readAsync(file, options) {
let json;
try {
json = await node_fs_1.default.promises.readFile(file, 'utf8');
}
catch (error) {
assertEmptyJsonString(json, file);
const defaultValue = cantReadFileDefault(options);
if (defaultValue === undefined) {
throw new JsonFileError_1.default(`Can't read JSON file: ${file}`, error, error.code);
}
else {
return defaultValue;
}
}
return parseJsonString(json, options);
}
function parseJsonString(json, options, fileName) {
assertEmptyJsonString(json, fileName);
try {
if (_getOption(options, 'json5')) {
return json5_1.default.parse(json);
}
else {
return JSON.parse(json);
}
}
catch (e) {
const defaultValue = jsonParseErrorDefault(options);
if (defaultValue === undefined) {
const location = locationFromSyntaxError(e, json);
if (location) {
const codeFrame = (0, code_frame_1.codeFrameColumns)(json, { start: location });
e.codeFrame = codeFrame;
e.message += `\n${codeFrame}`;
}
throw new JsonFileError_1.default(`Error parsing JSON: ${json}`, e, 'EJSONPARSE', fileName);
}
else {
return defaultValue;
}
}
}
function getSync(file, key, defaultValue, options) {
const object = read(file, options);
if (key in object) {
return object[key];
}
if (defaultValue === undefined) {
throw new JsonFileError_1.default(`No value at key path "${String(key)}" in JSON object from: ${file}`);
}
return defaultValue;
}
async function getAsync(file, key, defaultValue, options) {
const object = await readAsync(file, options);
if (key in object) {
return object[key];
}
if (defaultValue === undefined) {
throw new JsonFileError_1.default(`No value at key path "${String(key)}" in JSON object from: ${file}`);
}
return defaultValue;
}
function write(file, object, options) {
if (options?.ensureDir) {
node_fs_1.default.mkdirSync(node_path_1.default.dirname(file), { recursive: true });
}
const space = _getOption(options, 'space');
const json5 = _getOption(options, 'json5');
const addNewLineAtEOF = _getOption(options, 'addNewLineAtEOF');
let json;
try {
if (json5) {
json = json5_1.default.stringify(object, null, space);
}
else {
json = JSON.stringify(object, null, space);
}
}
catch (e) {
throw new JsonFileError_1.default(`Couldn't JSON.stringify object for file: ${file}`, e);
}
const data = addNewLineAtEOF ? `${json}\n` : json;
(0, writeAtomic_1.writeFileAtomicSync)(file, data);
return object;
}
async function writeAsync(file, object, options) {
if (options?.ensureDir) {
await node_fs_1.default.promises.mkdir(node_path_1.default.dirname(file), { recursive: true });
}
const space = _getOption(options, 'space');
const json5 = _getOption(options, 'json5');
const addNewLineAtEOF = _getOption(options, 'addNewLineAtEOF');
let json;
try {
if (json5) {
json = json5_1.default.stringify(object, null, space);
}
else {
json = JSON.stringify(object, null, space);
}
}
catch (e) {
throw new JsonFileError_1.default(`Couldn't JSON.stringify object for file: ${file}`, e);
}
const data = addNewLineAtEOF ? `${json}\n` : json;
await (0, writeAtomic_1.writeFileAtomic)(file, data);
return object;
}
function setSync(file, key, value, options) {
// TODO: Consider implementing some kind of locking mechanism, but
// it's not critical for our use case, so we'll leave it out for now
const object = read(file, options);
return write(file, { ...object, [key]: value }, options);
}
async function setAsync(file, key, value, options) {
// TODO: Consider implementing some kind of locking mechanism, but
// it's not critical for our use case, so we'll leave it out for now
const object = await readAsync(file, options);
return writeAsync(file, { ...object, [key]: value }, options);
}
async function mergeAsync(file, sources, options) {
const object = await readAsync(file, options);
if (Array.isArray(sources)) {
Object.assign(object, ...sources);
}
else {
Object.assign(object, sources);
}
return writeAsync(file, object, options);
}
function merge(file, sources, options) {
const object = read(file, options);
if (Array.isArray(sources)) {
Object.assign(object, ...sources);
}
else {
Object.assign(object, sources);
}
return write(file, object, options);
}
async function deleteKeyAsync(file, key, options) {
return deleteKeysAsync(file, [key], options);
}
function deleteKey(file, key, options) {
return deleteKeys(file, [key], options);
}
async function deleteKeysAsync(file, keys, options) {
const object = await readAsync(file, options);
let didDelete = false;
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
if (object.hasOwnProperty(key)) {
delete object[key];
didDelete = true;
}
}
if (didDelete) {
return writeAsync(file, object, options);
}
return object;
}
function deleteKeys(file, keys, options) {
const object = read(file, options);
let didDelete = false;
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
if (object.hasOwnProperty(key)) {
delete object[key];
didDelete = true;
}
}
if (didDelete) {
return write(file, object, options);
}
return object;
}
async function rewriteAsync(file, options) {
const object = await readAsync(file, options);
return writeAsync(file, object, options);
}
function rewrite(file, options) {
return write(file, read(file, options), options);
}
function jsonParseErrorDefault(options = {}) {
if (options.jsonParseErrorDefault === undefined) {
return options.default;
}
else {
return options.jsonParseErrorDefault;
}
}
function cantReadFileDefault(options = {}) {
if (options.cantReadFileDefault === undefined) {
return options.default;
}
else {
return options.cantReadFileDefault;
}
}
function _getOption(options, field) {
if (options) {
if (options[field] !== undefined) {
return options[field];
}
}
return DEFAULT_OPTIONS[field];
}
function locationFromSyntaxError(error, sourceString) {
// JSON5 SyntaxError has lineNumber and columnNumber.
if ('lineNumber' in error && 'columnNumber' in error) {
return { line: error.lineNumber, column: error.columnNumber };
}
// JSON SyntaxError only includes the index in the message.
const match = /at position (\d+)/.exec(error.message);
if (match) {
const index = parseInt(match[1], 10);
const lines = sourceString.slice(0, index + 1).split('\n');
return { line: lines.length, column: lines[lines.length - 1].length };
}
return null;
}
function assertEmptyJsonString(json, file) {
if (json?.trim() === '') {
throw new JsonFileError_1.EmptyJsonFileError(file);
}
}
//# sourceMappingURL=JsonFile.js.map
File diff suppressed because one or more lines are too long
+13
View File
@@ -0,0 +1,13 @@
/**
* Note that instances of this class do NOT pass `instanceof JsonFileError`.
*/
export default class JsonFileError extends Error {
cause: Error | undefined;
code: string | undefined;
fileName: string | undefined;
isJsonFileError: true;
constructor(message: string, cause?: Error, code?: string, fileName?: string);
}
export declare class EmptyJsonFileError extends JsonFileError {
constructor(fileName?: string);
}
+35
View File
@@ -0,0 +1,35 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EmptyJsonFileError = void 0;
/**
* Note that instances of this class do NOT pass `instanceof JsonFileError`.
*/
class JsonFileError extends Error {
cause;
code;
fileName;
isJsonFileError;
constructor(message, cause, code, fileName) {
let fullMessage = message;
if (fileName) {
fullMessage += `\n${cause ? '├' : '└'}─ File: ${fileName}`;
}
if (cause) {
fullMessage += `\n└─ Cause: ${cause.name}: ${cause.message}`;
}
super(fullMessage);
this.name = this.constructor.name;
this.cause = cause;
this.code = code;
this.fileName = fileName;
this.isJsonFileError = true;
}
}
exports.default = JsonFileError;
class EmptyJsonFileError extends JsonFileError {
constructor(fileName) {
super(`Cannot parse an empty JSON string`, undefined, 'EJSONEMPTY', fileName);
}
}
exports.EmptyJsonFileError = EmptyJsonFileError;
//# sourceMappingURL=JsonFileError.js.map
@@ -0,0 +1 @@
{"version":3,"file":"JsonFileError.js","sourceRoot":"","sources":["../src/JsonFileError.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,MAAqB,aAAc,SAAQ,KAAK;IAC9C,KAAK,CAAoB;IACzB,IAAI,CAAqB;IACzB,QAAQ,CAAqB;IAC7B,eAAe,CAAO;IAEtB,YAAY,OAAe,EAAE,KAAa,EAAE,IAAa,EAAE,QAAiB;QAC1E,IAAI,WAAW,GAAG,OAAO,CAAC;QAC1B,IAAI,QAAQ,EAAE,CAAC;YACb,WAAW,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,WAAW,QAAQ,EAAE,CAAC;QAC7D,CAAC;QACD,IAAI,KAAK,EAAE,CAAC;YACV,WAAW,IAAI,eAAe,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC;QAC/D,CAAC;QACD,KAAK,CAAC,WAAW,CAAC,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAClC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;IAC9B,CAAC;CACF;AArBD,gCAqBC;AAED,MAAa,kBAAmB,SAAQ,aAAa;IACnD,YAAY,QAAiB;QAC3B,KAAK,CAAC,mCAAmC,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,CAAC,CAAC;IAChF,CAAC;CACF;AAJD,gDAIC"}
+2
View File
@@ -0,0 +1,2 @@
export declare function writeFileAtomicSync(filename: string, data: string | Buffer): void;
export declare function writeFileAtomic(filename: string, data: string | Buffer): Promise<void>;
+54
View File
@@ -0,0 +1,54 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.writeFileAtomicSync = writeFileAtomicSync;
exports.writeFileAtomic = writeFileAtomic;
const node_crypto_1 = require("node:crypto");
const fs = __importStar(require("node:fs"));
function getTarget(filename, data) {
const hash = (0, node_crypto_1.createHash)('sha256').update(data).digest('base64url');
return `${filename}.${hash}`;
}
function writeFileAtomicSync(filename, data) {
const tmpfile = getTarget(filename, data);
fs.writeFileSync(tmpfile, data);
fs.renameSync(tmpfile, filename);
}
async function writeFileAtomic(filename, data) {
const tmpfile = getTarget(filename, data);
await fs.promises.writeFile(tmpfile, data);
await fs.promises.rename(tmpfile, filename);
}
//# sourceMappingURL=writeAtomic.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"writeAtomic.js","sourceRoot":"","sources":["../src/writeAtomic.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAQA,kDAIC;AAED,0CAIC;AAlBD,6CAAyC;AACzC,4CAA8B;AAE9B,SAAS,SAAS,CAAC,QAAgB,EAAE,IAAqB;IACxD,MAAM,IAAI,GAAG,IAAA,wBAAU,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IACnE,OAAO,GAAG,QAAQ,IAAI,IAAI,EAAE,CAAC;AAC/B,CAAC;AAED,SAAgB,mBAAmB,CAAC,QAAgB,EAAE,IAAqB;IACzE,MAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC1C,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAChC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AACnC,CAAC;AAEM,KAAK,UAAU,eAAe,CAAC,QAAgB,EAAE,IAAqB;IAC3E,MAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC1C,MAAM,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC3C,MAAM,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,22 @@
MIT License
Copyright (c) 2014-present Sebastian McKenzie and other contributors
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
# @babel/code-frame
> Generate errors that contain a code frame that point to source locations.
See our website [@babel/code-frame](https://babeljs.io/docs/en/next/babel-code-frame.html) for more information.
## Install
Using npm:
```sh
npm install --save-dev @babel/code-frame
```
or using yarn:
```sh
yarn add @babel/code-frame --dev
```
@@ -0,0 +1,167 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.codeFrameColumns = codeFrameColumns;
exports.default = _default;
var _highlight = _interopRequireWildcard(require("@babel/highlight"));
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
let deprecationWarningShown = false;
function getDefs(chalk) {
return {
gutter: chalk.grey,
marker: chalk.red.bold,
message: chalk.red.bold
};
}
const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
function getMarkerLines(loc, source, opts) {
const startLoc = Object.assign({
column: 0,
line: -1
}, loc.start);
const endLoc = Object.assign({}, startLoc, loc.end);
const {
linesAbove = 2,
linesBelow = 3
} = opts || {};
const startLine = startLoc.line;
const startColumn = startLoc.column;
const endLine = endLoc.line;
const endColumn = endLoc.column;
let start = Math.max(startLine - (linesAbove + 1), 0);
let end = Math.min(source.length, endLine + linesBelow);
if (startLine === -1) {
start = 0;
}
if (endLine === -1) {
end = source.length;
}
const lineDiff = endLine - startLine;
const markerLines = {};
if (lineDiff) {
for (let i = 0; i <= lineDiff; i++) {
const lineNumber = i + startLine;
if (!startColumn) {
markerLines[lineNumber] = true;
} else if (i === 0) {
const sourceLength = source[lineNumber - 1].length;
markerLines[lineNumber] = [startColumn, sourceLength - startColumn + 1];
} else if (i === lineDiff) {
markerLines[lineNumber] = [0, endColumn];
} else {
const sourceLength = source[lineNumber - i].length;
markerLines[lineNumber] = [0, sourceLength];
}
}
} else {
if (startColumn === endColumn) {
if (startColumn) {
markerLines[startLine] = [startColumn, 0];
} else {
markerLines[startLine] = true;
}
} else {
markerLines[startLine] = [startColumn, endColumn - startColumn];
}
}
return {
start,
end,
markerLines
};
}
function codeFrameColumns(rawLines, loc, opts = {}) {
const highlighted = (opts.highlightCode || opts.forceColor) && (0, _highlight.shouldHighlight)(opts);
const chalk = (0, _highlight.getChalk)(opts);
const defs = getDefs(chalk);
const maybeHighlight = (chalkFn, string) => {
return highlighted ? chalkFn(string) : string;
};
const lines = rawLines.split(NEWLINE);
const {
start,
end,
markerLines
} = getMarkerLines(loc, lines, opts);
const hasColumns = loc.start && typeof loc.start.column === "number";
const numberMaxWidth = String(end).length;
const highlightedLines = highlighted ? (0, _highlight.default)(rawLines, opts) : rawLines;
let frame = highlightedLines.split(NEWLINE).slice(start, end).map((line, index) => {
const number = start + 1 + index;
const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
const gutter = ` ${paddedNumber} | `;
const hasMarker = markerLines[number];
const lastMarkerLine = !markerLines[number + 1];
if (hasMarker) {
let markerLine = "";
if (Array.isArray(hasMarker)) {
const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
const numberOfMarkers = hasMarker[1] || 1;
markerLine = ["\n ", maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")), markerSpacing, maybeHighlight(defs.marker, "^").repeat(numberOfMarkers)].join("");
if (lastMarkerLine && opts.message) {
markerLine += " " + maybeHighlight(defs.message, opts.message);
}
}
return [maybeHighlight(defs.marker, ">"), maybeHighlight(defs.gutter, gutter), line, markerLine].join("");
} else {
return ` ${maybeHighlight(defs.gutter, gutter)}${line}`;
}
}).join("\n");
if (opts.message && !hasColumns) {
frame = `${" ".repeat(numberMaxWidth + 1)}${opts.message}\n${frame}`;
}
if (highlighted) {
return chalk.reset(frame);
} else {
return frame;
}
}
function _default(rawLines, lineNumber, colNumber, opts = {}) {
if (!deprecationWarningShown) {
deprecationWarningShown = true;
const message = "Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`.";
if (process.emitWarning) {
process.emitWarning(message, "DeprecationWarning");
} else {
const deprecationError = new Error(message);
deprecationError.name = "DeprecationWarning";
console.warn(new Error(message));
}
}
colNumber = Math.max(colNumber, 0);
const location = {
start: {
column: colNumber,
line: lineNumber
}
};
return codeFrameColumns(rawLines, location, opts);
}
@@ -0,0 +1,25 @@
{
"name": "@babel/code-frame",
"version": "7.10.4",
"description": "Generate errors that contain a code frame that point to source locations.",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/babel/babel.git",
"directory": "packages/babel-code-frame"
},
"main": "lib/index.js",
"dependencies": {
"@babel/highlight": "^7.10.4"
},
"devDependencies": {
"chalk": "^2.0.0",
"strip-ansi": "^4.0.0"
},
"gitHead": "7fd40d86a0d03ff0e9c3ea16b29689945433d4df"
}
+46
View File
@@ -0,0 +1,46 @@
{
"name": "@expo/json-file",
"version": "10.0.8",
"description": "A module for reading, writing, and manipulating JSON files",
"main": "build/JsonFile.js",
"scripts": {
"build": "expo-module tsc",
"clean": "expo-module clean",
"lint": "expo-module lint",
"prepare": "expo-module clean && expo-module tsc",
"prepublishOnly": "expo-module prepublishOnly",
"test": "expo-module test",
"typecheck": "expo-module typecheck",
"watch": "expo-module tsc --watch --preserveWatchOutput"
},
"repository": {
"type": "git",
"url": "https://github.com/expo/expo.git",
"directory": "packages/@expo/json-file"
},
"keywords": [
"json"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/expo/expo/issues"
},
"homepage": "https://github.com/expo/expo/tree/main/packages/@expo/json-file#readme",
"files": [
"build"
],
"dependencies": {
"@babel/code-frame": "~7.10.4",
"json5": "^2.2.3"
},
"devDependencies": {
"@types/babel__code-frame": "^7.0.1",
"@types/json5": "^2.2.0",
"expo-module-scripts": "^5.0.8",
"memfs": "^3.2.0"
},
"publishConfig": {
"access": "public"
},
"gitHead": "172a69f5f70c1d0e043e1532f924de97210cabc3"
}