@branchly/resolver-direnv 0.1.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/index.d.ts +11 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/package.json +30 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ConnectionResolver } from 'branchly';
|
|
2
|
+
|
|
3
|
+
interface DirenvResolverOptions {
|
|
4
|
+
readonly file?: string;
|
|
5
|
+
readonly key?: string;
|
|
6
|
+
readonly cwd?: string;
|
|
7
|
+
}
|
|
8
|
+
declare const upsertExport: (content: string, key: string, value: string) => string;
|
|
9
|
+
declare const createDirenvResolver: (options?: DirenvResolverOptions) => ConnectionResolver;
|
|
10
|
+
|
|
11
|
+
export { type DirenvResolverOptions, createDirenvResolver, createDirenvResolver as default, upsertExport };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { readFile, writeFile } from "fs/promises";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
var DEFAULT_FILE = ".envrc";
|
|
5
|
+
var DEFAULT_KEY = "DATABASE_URL";
|
|
6
|
+
var upsertExport = (content, key, value) => {
|
|
7
|
+
const line = `export ${key}=${value}`;
|
|
8
|
+
const existing = content.length === 0 ? [] : content.replace(/\n+$/, "").split("\n");
|
|
9
|
+
const replaced = existing.map((current) => current.startsWith(`export ${key}=`) ? line : current);
|
|
10
|
+
const next = replaced.includes(line) ? replaced : [...replaced, line];
|
|
11
|
+
return `${next.join("\n")}
|
|
12
|
+
`;
|
|
13
|
+
};
|
|
14
|
+
var readExisting = (path) => readFile(path, "utf8").then(
|
|
15
|
+
(content) => content,
|
|
16
|
+
() => ""
|
|
17
|
+
);
|
|
18
|
+
var createDirenvResolver = (options = {}) => {
|
|
19
|
+
const path = join(options.cwd ?? ".", options.file ?? DEFAULT_FILE);
|
|
20
|
+
const key = options.key ?? DEFAULT_KEY;
|
|
21
|
+
return {
|
|
22
|
+
id: "direnv",
|
|
23
|
+
apiVersion: 1,
|
|
24
|
+
inject: async (connection) => {
|
|
25
|
+
const existing = await readExisting(path);
|
|
26
|
+
await writeFile(path, upsertExport(existing, key, connection), "utf8");
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
var index_default = createDirenvResolver;
|
|
31
|
+
export {
|
|
32
|
+
createDirenvResolver,
|
|
33
|
+
index_default as default,
|
|
34
|
+
upsertExport
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { readFile, writeFile } from 'node:fs/promises';\nimport { join } from 'node:path';\n\nimport type { ConnectionResolver } from 'branchly';\n\nconst DEFAULT_FILE = '.envrc';\nconst DEFAULT_KEY = 'DATABASE_URL';\n\nexport interface DirenvResolverOptions {\n readonly file?: string;\n readonly key?: string;\n readonly cwd?: string;\n}\n\nexport const upsertExport = (content: string, key: string, value: string): string => {\n const line = `export ${key}=${value}`;\n const existing = content.length === 0 ? [] : content.replace(/\\n+$/, '').split('\\n');\n const replaced = existing.map((current) => (current.startsWith(`export ${key}=`) ? line : current));\n const next = replaced.includes(line) ? replaced : [...replaced, line];\n return `${next.join('\\n')}\\n`;\n};\n\nconst readExisting = (path: string): Promise<string> =>\n readFile(path, 'utf8').then(\n (content) => content,\n () => '',\n );\n\nexport const createDirenvResolver = (options: DirenvResolverOptions = {}): ConnectionResolver => {\n const path = join(options.cwd ?? '.', options.file ?? DEFAULT_FILE);\n const key = options.key ?? DEFAULT_KEY;\n return {\n id: 'direnv',\n apiVersion: 1,\n inject: async (connection) => {\n const existing = await readExisting(path);\n await writeFile(path, upsertExport(existing, key, connection), 'utf8');\n },\n };\n};\n\nexport default createDirenvResolver;\n"],"mappings":";AAAA,SAAS,UAAU,iBAAiB;AACpC,SAAS,YAAY;AAIrB,IAAM,eAAe;AACrB,IAAM,cAAc;AAQb,IAAM,eAAe,CAAC,SAAiB,KAAa,UAA0B;AACnF,QAAM,OAAO,UAAU,GAAG,IAAI,KAAK;AACnC,QAAM,WAAW,QAAQ,WAAW,IAAI,CAAC,IAAI,QAAQ,QAAQ,QAAQ,EAAE,EAAE,MAAM,IAAI;AACnF,QAAM,WAAW,SAAS,IAAI,CAAC,YAAa,QAAQ,WAAW,UAAU,GAAG,GAAG,IAAI,OAAO,OAAQ;AAClG,QAAM,OAAO,SAAS,SAAS,IAAI,IAAI,WAAW,CAAC,GAAG,UAAU,IAAI;AACpE,SAAO,GAAG,KAAK,KAAK,IAAI,CAAC;AAAA;AAC3B;AAEA,IAAM,eAAe,CAAC,SACpB,SAAS,MAAM,MAAM,EAAE;AAAA,EACrB,CAAC,YAAY;AAAA,EACb,MAAM;AACR;AAEK,IAAM,uBAAuB,CAAC,UAAiC,CAAC,MAA0B;AAC/F,QAAM,OAAO,KAAK,QAAQ,OAAO,KAAK,QAAQ,QAAQ,YAAY;AAClE,QAAM,MAAM,QAAQ,OAAO;AAC3B,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,YAAY;AAAA,IACZ,QAAQ,OAAO,eAAe;AAC5B,YAAM,WAAW,MAAM,aAAa,IAAI;AACxC,YAAM,UAAU,MAAM,aAAa,UAAU,KAAK,UAAU,GAAG,MAAM;AAAA,IACvE;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@branchly/resolver-direnv",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Reference direnv (.envrc) connection resolver for branchly.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"branchly": "0.1.0",
|
|
20
|
+
"@branchly/adapter-test-kit": "0.1.0"
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsup",
|
|
27
|
+
"dev": "tsup --watch",
|
|
28
|
+
"typecheck": "tsc --noEmit"
|
|
29
|
+
}
|
|
30
|
+
}
|