@atproto/lex-installer 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/fs.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export declare function readJsonFile(path: string): Promise<unknown>;
2
+ export declare function writeJsonFile(path: string, data: unknown): Promise<void>;
3
+ export declare function isEnoentError(err: unknown): boolean;
4
+ //# sourceMappingURL=fs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs.d.ts","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAGA,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAGjE;AAED,wBAAsB,aAAa,CACjC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,IAAI,CAAC,CAQf;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAEnD"}
package/dist/fs.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readJsonFile = readJsonFile;
4
+ exports.writeJsonFile = writeJsonFile;
5
+ exports.isEnoentError = isEnoentError;
6
+ const promises_1 = require("node:fs/promises");
7
+ const node_path_1 = require("node:path");
8
+ async function readJsonFile(path) {
9
+ const contents = await (0, promises_1.readFile)(path, 'utf8');
10
+ return JSON.parse(contents);
11
+ }
12
+ async function writeJsonFile(path, data) {
13
+ await (0, promises_1.mkdir)((0, node_path_1.dirname)(path), { recursive: true });
14
+ const contents = JSON.stringify(data, null, 2);
15
+ await (0, promises_1.writeFile)(path, contents, {
16
+ encoding: 'utf8',
17
+ mode: 0o644,
18
+ flag: 'w', // override
19
+ });
20
+ }
21
+ function isEnoentError(err) {
22
+ return err instanceof Error && 'code' in err && err.code === 'ENOENT';
23
+ }
24
+ //# sourceMappingURL=fs.js.map
package/dist/fs.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fs.js","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":";;AAGA,oCAGC;AAED,sCAWC;AAED,sCAEC;AAvBD,+CAA6D;AAC7D,yCAAmC;AAE5B,KAAK,UAAU,YAAY,CAAC,IAAY;IAC7C,MAAM,QAAQ,GAAG,MAAM,IAAA,mBAAQ,EAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IAC7C,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;AAC7B,CAAC;AAEM,KAAK,UAAU,aAAa,CACjC,IAAY,EACZ,IAAa;IAEb,MAAM,IAAA,gBAAK,EAAC,IAAA,mBAAO,EAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IAC/C,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IAC9C,MAAM,IAAA,oBAAS,EAAC,IAAI,EAAE,QAAQ,EAAE;QAC9B,QAAQ,EAAE,MAAM;QAChB,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,GAAG,EAAE,WAAW;KACvB,CAAC,CAAA;AACJ,CAAC;AAED,SAAgB,aAAa,CAAC,GAAY;IACxC,OAAO,GAAG,YAAY,KAAK,IAAI,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAA;AACvE,CAAC","sourcesContent":["import { mkdir, readFile, writeFile } from 'node:fs/promises'\nimport { dirname } from 'node:path'\n\nexport async function readJsonFile(path: string): Promise<unknown> {\n const contents = await readFile(path, 'utf8')\n return JSON.parse(contents)\n}\n\nexport async function writeJsonFile(\n path: string,\n data: unknown,\n): Promise<void> {\n await mkdir(dirname(path), { recursive: true })\n const contents = JSON.stringify(data, null, 2)\n await writeFile(path, contents, {\n encoding: 'utf8',\n mode: 0o644,\n flag: 'w', // override\n })\n}\n\nexport function isEnoentError(err: unknown): boolean {\n return err instanceof Error && 'code' in err && err.code === 'ENOENT'\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import { LexInstallerOptions } from './lex-installer.js';
2
+ export type LexInstallOptions = LexInstallerOptions & {
3
+ add?: string[];
4
+ save?: boolean;
5
+ ci?: boolean;
6
+ };
7
+ export declare function install(options: LexInstallOptions): Promise<void>;
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAMtE,MAAM,MAAM,iBAAiB,GAAG,mBAAmB,GAAG;IACpD,GAAG,CAAC,EAAE,MAAM,EAAE,CAAA;IACd,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,EAAE,CAAC,EAAE,OAAO,CAAA;CACb,CAAA;AAED,wBAAsB,OAAO,CAAC,OAAO,EAAE,iBAAiB,iBA2BvD"}
package/dist/index.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.install = install;
4
+ const tslib_1 = require("tslib");
5
+ const fs_js_1 = require("./fs.js");
6
+ const lex_installer_js_1 = require("./lex-installer.js");
7
+ const lexicons_manifest_js_1 = require("./lexicons-manifest.js");
8
+ async function install(options) {
9
+ const env_1 = { stack: [], error: void 0, hasError: false };
10
+ try {
11
+ const manifest = await (0, fs_js_1.readJsonFile)(options.manifest).then((json) => lexicons_manifest_js_1.lexiconsManifestSchema.parse(json), (cause) => {
12
+ if ((0, fs_js_1.isEnoentError)(cause))
13
+ return undefined;
14
+ throw new Error('Failed to read lexicons manifest', { cause });
15
+ });
16
+ const additions = new Set(options.add);
17
+ // Perform the installation using the existing manifest as "hint"
18
+ const installer = tslib_1.__addDisposableResource(env_1, new lex_installer_js_1.LexInstaller(options), true);
19
+ await installer.install({ additions, manifest });
20
+ // Verify lockfile
21
+ if (options.ci && (!manifest || !installer.matches(manifest))) {
22
+ throw new Error('Lexicons manifest is out of date');
23
+ }
24
+ // Save changes if requested
25
+ if (options.save) {
26
+ await installer.save();
27
+ }
28
+ }
29
+ catch (e_1) {
30
+ env_1.error = e_1;
31
+ env_1.hasError = true;
32
+ }
33
+ finally {
34
+ const result_1 = tslib_1.__disposeResources(env_1);
35
+ if (result_1)
36
+ await result_1;
37
+ }
38
+ }
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAaA,0BA2BC;;AAxCD,mCAAqD;AACrD,yDAAsE;AACtE,iEAG+B;AAQxB,KAAK,UAAU,OAAO,CAAC,OAA0B;;;QACtD,MAAM,QAAQ,GAAiC,MAAM,IAAA,oBAAY,EAC/D,OAAO,CAAC,QAAQ,CACjB,CAAC,IAAI,CACJ,CAAC,IAAI,EAAE,EAAE,CAAC,6CAAsB,CAAC,KAAK,CAAC,IAAI,CAAC,EAC5C,CAAC,KAAc,EAAE,EAAE;YACjB,IAAI,IAAA,qBAAa,EAAC,KAAK,CAAC;gBAAE,OAAO,SAAS,CAAA;YAC1C,MAAM,IAAI,KAAK,CAAC,kCAAkC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;QAChE,CAAC,CACF,CAAA;QAED,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QAEtC,iEAAiE;QACjE,MAAY,SAAS,0CAAG,IAAI,+BAAY,CAAC,OAAO,CAAC,OAAA,CAAA;QAEjD,MAAM,SAAS,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAA;QAEhD,kBAAkB;QAClB,IAAI,OAAO,CAAC,EAAE,IAAI,CAAC,CAAC,QAAQ,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;YAC9D,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;QACrD,CAAC;QAED,4BAA4B;QAC5B,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;YACjB,MAAM,SAAS,CAAC,IAAI,EAAE,CAAA;QACxB,CAAC;;;;;;;;;;;CACF","sourcesContent":["import { isEnoentError, readJsonFile } from './fs.js'\nimport { LexInstaller, LexInstallerOptions } from './lex-installer.js'\nimport {\n LexiconsManifest,\n lexiconsManifestSchema,\n} from './lexicons-manifest.js'\n\nexport type LexInstallOptions = LexInstallerOptions & {\n add?: string[]\n save?: boolean\n ci?: boolean\n}\n\nexport async function install(options: LexInstallOptions) {\n const manifest: LexiconsManifest | undefined = await readJsonFile(\n options.manifest,\n ).then(\n (json) => lexiconsManifestSchema.parse(json),\n (cause: unknown) => {\n if (isEnoentError(cause)) return undefined\n throw new Error('Failed to read lexicons manifest', { cause })\n },\n )\n\n const additions = new Set(options.add)\n\n // Perform the installation using the existing manifest as \"hint\"\n await using installer = new LexInstaller(options)\n\n await installer.install({ additions, manifest })\n\n // Verify lockfile\n if (options.ci && (!manifest || !installer.matches(manifest))) {\n throw new Error('Lexicons manifest is out of date')\n }\n\n // Save changes if requested\n if (options.save) {\n await installer.save()\n }\n}\n"]}