@altano/disposable-directory 0.0.0-beta.1

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/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # disposable-directory
2
+
3
+ [![npm](https://badgen.net/npm/v/@altano/disposable-directory)](https://www.npmjs.com/package/@altano/disposable-directory) ![Typed with TypeScript](https://badgen.net/npm/types/@altano/disposable-directory) ![ESM only](https://badgen.net/badge/module/esm%20only?icon=js)
4
+
5
+ Simple utility for getting a disposable, temporary directory in a Node.js-compatible environment. Directory is cleaned up automatically when the function scope exists.
6
+
7
+ Uses the new `Symbol.asyncDispose` API and therefore requires Node.js 24+.
8
+
9
+ ## Example
10
+
11
+ ```ts
12
+ async function doSomething() {
13
+ // This creates a directory
14
+ await using tempDir = await getDisposableDirectory();
15
+
16
+ // the directory exists for the scope of this function
17
+ console.log(tempDir);
18
+
19
+ // No cleanup is required. The directory will implicitly be deleted when this function exits (or throws an error).
20
+ }
21
+ ```
@@ -0,0 +1,9 @@
1
+ //#region src/getDisposableDirectory.d.ts
2
+ type DisposableDirectory = {
3
+ path: string;
4
+ [Symbol.asyncDispose](): Promise<void>;
5
+ };
6
+ declare function getDisposableDirectory(prefix?: string): Promise<DisposableDirectory>;
7
+ //#endregion
8
+ export { getDisposableDirectory };
9
+ //# sourceMappingURL=getDisposableDirectory.d.ts.map
@@ -0,0 +1,21 @@
1
+ import fs from "node:fs/promises";
2
+ import nodePath from "node:path";
3
+ import os from "node:os";
4
+
5
+ //#region src/getDisposableDirectory.ts
6
+ async function getDisposableDirectory(prefix = "disposable-directory-") {
7
+ const tempDir = await fs.mkdtemp(nodePath.join(os.tmpdir(), prefix));
8
+ return {
9
+ path: tempDir,
10
+ [Symbol.asyncDispose]() {
11
+ return fs.rm(tempDir, {
12
+ recursive: true,
13
+ force: true
14
+ });
15
+ }
16
+ };
17
+ }
18
+
19
+ //#endregion
20
+ export { getDisposableDirectory };
21
+ //# sourceMappingURL=getDisposableDirectory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getDisposableDirectory.js","names":[],"sources":["../src/getDisposableDirectory.ts"],"sourcesContent":["import fs from \"node:fs/promises\";\nimport nodePath from \"node:path\";\nimport os from \"node:os\";\n\ntype DisposableDirectory = {\n path: string;\n [Symbol.asyncDispose](): Promise<void>;\n};\n\nexport async function getDisposableDirectory(\n prefix: string = \"disposable-directory-\",\n): Promise<DisposableDirectory> {\n const tempDir = await fs.mkdtemp(nodePath.join(os.tmpdir(), prefix));\n return {\n path: tempDir,\n [Symbol.asyncDispose]() {\n return fs.rm(tempDir, { recursive: true, force: true });\n },\n };\n}\n"],"mappings":";;;;;AASA,eAAsB,uBACpB,SAAiB,yBACa;CAC9B,MAAM,UAAU,MAAM,GAAG,QAAQ,SAAS,KAAK,GAAG,QAAQ,EAAE,OAAO,CAAC;AACpE,QAAO;EACL,MAAM;EACN,CAAC,OAAO,gBAAgB;AACtB,UAAO,GAAG,GAAG,SAAS;IAAE,WAAW;IAAM,OAAO;IAAM,CAAC;;EAE1D"}
@@ -0,0 +1,2 @@
1
+ import { getDisposableDirectory } from "./getDisposableDirectory.js";
2
+ export { getDisposableDirectory };
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import { getDisposableDirectory } from "./getDisposableDirectory.js";
2
+
3
+ export { getDisposableDirectory };
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "@altano/disposable-directory",
3
+ "version": "0.0.0-beta.1",
4
+ "description": "Create a temporary, disposable directory that automatically gets cleaned up when the function scope exits. Uses the new `Symbol.asyncDispose` APIs",
5
+ "keywords": [
6
+ "directory",
7
+ "temporary",
8
+ "disposable"
9
+ ],
10
+ "homepage": "https://github.com/altano/npm-packages/tree/main/packages/disposable-directory",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/altano/npm-packages",
14
+ "directory": "packages/disposable-directory"
15
+ },
16
+ "license": "ISC",
17
+ "author": {
18
+ "name": "Alan Norbauer",
19
+ "email": "altano@gmail.com",
20
+ "url": "https://alan.norbauer.com"
21
+ },
22
+ "sideEffects": false,
23
+ "type": "module",
24
+ "exports": {
25
+ ".": "./dist/index.js",
26
+ "./*": "./dist/*"
27
+ },
28
+ "main": "./dist/index.js",
29
+ "module": "./dist/index.js",
30
+ "types": "./dist/index.d.ts",
31
+ "files": [
32
+ "dist/**/*.js",
33
+ "dist/**/*.js.map",
34
+ "dist/**/*.d.ts"
35
+ ],
36
+ "scripts": {
37
+ "build": "tsdown --config-loader unrun --config ../build-config/tsdown.config.node.ts",
38
+ "check:exports": "attw --pack . --profile esm-only --quiet",
39
+ "check:types:src": "tsc --noEmit",
40
+ "check:types:test": "tsc --noEmit --project ./tests/tsconfig.json",
41
+ "check:unused-dependencies": "depcheck",
42
+ "clean": "rm -rf .turbo && rm -rf .tsbuildinfo && rm -rf node_modules && rm -rf dist",
43
+ "dev": "pnpm run build --watch",
44
+ "format": "prettier --check src",
45
+ "format:fix": "prettier --write src",
46
+ "lint": "eslint",
47
+ "lint:fix": "TIMING=1 pnpm lint --fix",
48
+ "lint:timing": "TIMING=1 pnpm lint",
49
+ "test:build": "./tests/scripts/createRepositoryBundles.ts",
50
+ "test:unit": "vitest --run",
51
+ "test:unit:watch": "vitest"
52
+ },
53
+ "devDependencies": {
54
+ "@altano/build-config": "workspace:*",
55
+ "@altano/testing": "workspace:*",
56
+ "@altano/tsconfig": "workspace:*",
57
+ "@arethetypeswrong/cli": "catalog:",
58
+ "@types/node": "catalog:",
59
+ "@vitest/coverage-v8": "catalog:",
60
+ "@vitest/expect": "catalog:",
61
+ "depcheck": "catalog:",
62
+ "eslint": "catalog:",
63
+ "prettier": "catalog:",
64
+ "tsdown": "catalog:",
65
+ "typescript": "catalog:",
66
+ "vite": "catalog:",
67
+ "vitest": "catalog:"
68
+ },
69
+ "engines": {
70
+ "node": ">=24"
71
+ },
72
+ "publishConfig": {
73
+ "access": "public"
74
+ }
75
+ }