+2
-1
@@ -15,3 +15,4 @@ export declare type Filepath = string; | ||
| files: Files; | ||
| cleanup(): Promise<boolean>; | ||
| mkdir(directory: string): string; | ||
| cleanup(): boolean; | ||
| }; |
+1
-1
@@ -1,1 +0,1 @@ | ||
| var l=Object.create;var i=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var h=Object.getPrototypeOf,u=Object.prototype.hasOwnProperty;var c=t=>i(t,"__esModule",{value:!0});var x=(t,o)=>{c(t);for(var e in o)i(t,e,{get:o[e],enumerable:!0})},F=(t,o,e)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of g(o))!u.call(t,r)&&r!=="default"&&i(t,r,{get:()=>o[r],enumerable:!(e=y(o,r))||e.enumerable});return t},n=t=>F(c(i(t!=null?l(h(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);x(exports,{afix:()=>d});var p=n(require("fs")),s=n(require("path")),a=n(require("premove")),f=n(require("nanoid")),m=n(require("graceful-goodbye"));function d(t){let o={},e=s.default.join(process.cwd(),`./.afix-${(0,f.customAlphabet)("1234567890abcdef",10)()}`);p.default.mkdirSync(e);for(let r of Object.keys(t))o[r]={path:s.default.join(e,t[r][0]),content:t[r][1]},p.default.writeFileSync(o[r].path,o[r].content,"utf8");return(0,m.default)(async()=>(0,a.premove)(e)),{root:e,files:o,cleanup(){return(0,a.premove)(e)}}}0&&(module.exports={afix}); | ||
| var g=Object.create;var p=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var u=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var c=t=>p(t,"__esModule",{value:!0});var F=(t,o)=>{c(t);for(var e in o)p(t,e,{get:o[e],enumerable:!0})},b=(t,o,e)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of h(o))!x.call(t,r)&&r!=="default"&&p(t,r,{get:()=>o[r],enumerable:!(e=y(o,r))||e.enumerable});return t},n=t=>b(c(p(t!=null?g(u(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t);F(exports,{afix:()=>j});var f=n(require("fs")),i=n(require("path")),a=n(require("premove/sync")),s=n(require("mk-dirs/sync")),l=n(require("nanoid")),d=n(require("graceful-goodbye"));function j(t){let o={},e=i.default.join(process.cwd(),`./.afix-${(0,l.customAlphabet)("1234567890abcdef",10)()}`);(0,s.mkdir)(e);for(let r of Object.keys(t))o[r]={path:i.default.join(e,t[r][0]),content:t[r][1]},(0,s.mkdir)(i.default.dirname(o[r].path)),f.default.writeFileSync(o[r].path,o[r].content,"utf8");return(0,d.default)(()=>(0,a.premove)(e)),{root:e,files:o,mkdir(r){let m=i.default.join(e,r);return(0,s.mkdir)(m),i.default.join(m)},cleanup(){return(0,a.premove)(e)}}}0&&(module.exports={afix}); |
+2
-1
| { | ||
| "name": "afix", | ||
| "version": "1.1.5", | ||
| "version": "1.2.0", | ||
| "description": "Tiny fixture utility.", | ||
@@ -44,2 +44,3 @@ "main": "./index.js", | ||
| "graceful-goodbye": "^1.0.0", | ||
| "mk-dirs": "^3.0.0", | ||
| "nanoid": "^3.1.30", | ||
@@ -46,0 +47,0 @@ "premove": "^4.0.0" |
+21
-14
@@ -13,28 +13,35 @@ # afix | ||
| Afix creates directories and files within `__dirname` of the calling file. Be | ||
| sure to call `cleanup()` at the end of each test to remove all your fixtures. | ||
| Each call to `afix()` creates a new directory in `process.cwd()` and writes | ||
| files within the new directory. | ||
| ```typescript | ||
| import fs from 'fs' | ||
| import assert from 'assert' | ||
| import baretest from 'baretest' | ||
| import { afix } from 'afix' | ||
| const test = baretest('afix') | ||
| const fixture = afix({ | ||
| config: ['config.js', 'export default { foo: true }'], | ||
| nested: ['some/path/file.js'], | ||
| }) | ||
| const dir = fixture.mkdir('/some/dir') | ||
| test('afix', async () => { | ||
| const fixture = afix({ | ||
| config: ['config.js', 'export default { foo: true }'], | ||
| }) | ||
| fs.existsSync(fixture.root) // true | ||
| assert.ok(fs.existsSync(fixture.root)) | ||
| assert(fs.existsSync(fixture.files.config.path)) | ||
| assert.equal(fs.readFileSync(fixture.files.config.path), fixture.files.config.content) | ||
| fs.existsSync(fixture.files.config.path) // true | ||
| assert.equal(fs.readFileSync(fixture.files.config.path, 'utf8'), fixture.files.config.content) | ||
| fixture.cleanup() | ||
| }) | ||
| fs.existsSync(fixture.files.nested.path) // true | ||
| assert.equal(fs.readFileSync(fixture.files.nested.path, 'utf8'), fixture.files.nested.content) | ||
| fs.existsSync(dir) // true | ||
| // remove fixture.root | ||
| fixture.cleanup() | ||
| fs.existsSync(fixture.root) // false | ||
| ``` | ||
| Plus, fixtures are automaticaly removed when the process exits. | ||
| ## License | ||
| MIT License © [Sure Thing](https://github.com/sure-thing) |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
4489
9.41%23
4.55%47
17.5%4
33.33%+ Added
+ Added