New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@everymundo/global-root-dir

Package Overview
Dependencies
Maintainers
26
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@everymundo/global-root-dir - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

4

index.js

@@ -1,3 +0,3 @@

const { setGlobalRootDir } = require('./set-gobal-root-dir');
const { setGlobalRootDir } = require('./set-gobal-root-dir')
module.exports = { setGlobalRootDir };
module.exports = { setGlobalRootDir }

@@ -1,1 +0,1 @@

module.exports = { globalScope: global };
module.exports = { globalScope: global }
{
"name": "@everymundo/global-root-dir",
"version": "1.1.0",
"version": "1.1.1",
"description": "Sets a global variable variable __rootdir",
"main": "index.js",
"scripts": {
"cover": "NODE_ENV=test istanbul cover -x '*test.js' _mocha -- -R spec",
"check-coverage": "istanbul check-coverage --statements 100 --branches 100 --functions 100 --lines 100",
"check-lint": "eslint *.js lib/*.js test/*.js routes/*.js",
"fix-lint": "eslint --fix *.js lib/*.js test/*.js routes/*.js",
"test": "NODE_ENV=test LOG_LEVEL=test mocha -R spec $@"
"cover": "LOG_LEVEL=trace nyc -x test --reporter=lcov --reporter=text mocha test --recursive",
"check-coverage": "nyc check-coverage --statements 100 --branches 100 --functions 100 --lines 100",
"check-lint": "standard --env=mocha *.js lib/*.js spec/*.js spec/lib/*.js",
"fix-lint": "standard --env=mocha --fix *.js lib/*.js test/*.js",
"test": "mocha $@"
},

@@ -37,9 +37,10 @@ "config": {

"devDependencies": {
"@everymundo/cleanrequire": "^1.1.1",
"chai": "^4.1.2",
"ghooks": "^2.0.2",
"istanbul": "^1.1.0-alpha.1",
"mocha": "^5.0.0",
"sinon": "^4.4.2"
"@everymundo/cleanrequire": "^1.2.1",
"chai": "^4.2.0",
"ghooks": "^2.0.4",
"mocha": "^6.1.4",
"nyc": "^14.1.1",
"sinon": "^7.3.2",
"standard": "^12.0.1"
}
}

@@ -1,16 +0,16 @@

const fs = require('fs');
const { globalScope } = require('./lib/global-scope');
const fs = require('fs')
const { globalScope } = require('./lib/global-scope')
const setGlobalRootDir = (value = '', configurable = false, overwrite = false) => {
if (globalScope.__rootdir && !overwrite) return globalScope.__rootdir;
if (globalScope.__rootdir && !overwrite) return globalScope.__rootdir
if (!value) value = process.cwd();
if (!value) value = process.cwd()
fs.readdirSync(value);
fs.readdirSync(value)
Object.defineProperty(globalScope, '__rootdir', { value, configurable });
Object.defineProperty(globalScope, '__rootdir', { value, configurable })
return globalScope.__rootdir;
};
return globalScope.__rootdir
}
module.exports = { setGlobalRootDir };
module.exports = { setGlobalRootDir }
/* eslint-env mocha */
const { expect } = require('chai');
const { expect } = require('chai')
describe('index.js', () => {
const lib = require('../index');
const lib = require('../index')
it('should have 1 key', () => {
expect(Object.keys(lib)).to.have.property('length', 1);
});
expect(Object.keys(lib)).to.have.property('length', 1)
})
it('should have the proper setGlobalRootDir key', () => {
const { setGlobalRootDir } = require('../set-gobal-root-dir');
expect(lib).to.have.property('setGlobalRootDir', setGlobalRootDir);
});
});
const { setGlobalRootDir } = require('../set-gobal-root-dir')
expect(lib).to.have.property('setGlobalRootDir', setGlobalRootDir)
})
})
/* eslint-env mocha */
const { expect } = require('chai');
const { expect } = require('chai')
describe('lib/global-scope', () => {
const { globalScope } = require('../lib/global-scope');
const { globalScope } = require('../lib/global-scope')
it('should equal the global variable from node', () => {
expect(globalScope).to.equal(global);
});
});
expect(globalScope).to.equal(global)
})
})
/* eslint-env mocha */
const { expect } = require('chai');
const sinon = require('sinon');
const cleanrequire = require('@everymundo/cleanrequire');
const { expect } = require('chai')
const sinon = require('sinon')
const cleanrequire = require('@everymundo/cleanrequire')
describe('setGlobalRootDir', () => {
const globalScopeLib = require('../lib/global-scope');
const globalScopeLib = require('../lib/global-scope')
let box;
let box
beforeEach(() => {
box = sinon.sandbox.create();
box.stub(globalScopeLib, 'globalScope').value({});
});
box = sinon.createSandbox()
box.stub(globalScopeLib, 'globalScope').value({})
})
afterEach(() => { box.restore(); });
afterEach(() => { box.restore() })
context('When no arguments are passed', () => {
beforeEach(() => {
box.stub(process, 'cwd').callsFake(() => __dirname);
});
box.stub(process, 'cwd').callsFake(() => __dirname)
})
it('should use process.pwd as value', () => {
const { setGlobalRootDir } = cleanrequire('../set-gobal-root-dir');
const { setGlobalRootDir } = cleanrequire('../set-gobal-root-dir')
const { globalScope } = require('../lib/global-scope');
expect(globalScope).to.not.have.property('__rootdir');
const { globalScope } = require('../lib/global-scope')
expect(globalScope).to.not.have.property('__rootdir')
setGlobalRootDir();
expect(globalScope).to.have.property('__rootdir', __dirname);
expect(process.cwd).to.have.property('calledOnce', true);
});
setGlobalRootDir()
expect(globalScope).to.have.property('__rootdir', __dirname)
expect(process.cwd).to.have.property('calledOnce', true)
})
it('should not call process.pwd more than once with multiple calls to it', () => {
const { setGlobalRootDir } = cleanrequire('../set-gobal-root-dir');
const { setGlobalRootDir } = cleanrequire('../set-gobal-root-dir')
const { globalScope } = require('../lib/global-scope');
expect(globalScope).to.not.have.property('__rootdir');
const { globalScope } = require('../lib/global-scope')
expect(globalScope).to.not.have.property('__rootdir')
setGlobalRootDir();
setGlobalRootDir();
setGlobalRootDir();
setGlobalRootDir()
setGlobalRootDir()
setGlobalRootDir()
expect(globalScope).to.have.property('__rootdir', __dirname);
expect(process.cwd).to.have.property('calledOnce', true);
});
});
expect(globalScope).to.have.property('__rootdir', __dirname)
expect(process.cwd).to.have.property('calledOnce', true)
})
})
context('When arguments are passed', () => {
beforeEach(() => {
box.stub(process, 'cwd').callsFake(() => __dirname);
});
box.stub(process, 'cwd').callsFake(() => __dirname)
})
context('a valid directory', () => {
it('should use the argument passed as value', () => {
const { setGlobalRootDir } = cleanrequire('../set-gobal-root-dir');
const input = require('path').dirname(__filename);
const { globalScope } = require('../lib/global-scope');
expect(globalScope).to.not.have.property('__rootdir');
setGlobalRootDir(input);
expect(globalScope).to.have.property('__rootdir', input);
expect(process.cwd).to.have.property('calledOnce', false);
});
});
const { setGlobalRootDir } = cleanrequire('../set-gobal-root-dir')
const input = require('path').dirname(__filename)
const { globalScope } = require('../lib/global-scope')
expect(globalScope).to.not.have.property('__rootdir')
setGlobalRootDir(input)
expect(globalScope).to.have.property('__rootdir', input)
expect(process.cwd).to.have.property('calledOnce', false)
})
})
context('a non existing directory', () => {
it('should throw error', () => {
const { setGlobalRootDir } = cleanrequire('../set-gobal-root-dir');
const { setGlobalRootDir } = cleanrequire('../set-gobal-root-dir')
const input = require('path').join(__dirname, String(Math.random()));
const caller = () => setGlobalRootDir(input);
const input = require('path').join(__dirname, String(Math.random()))
expect(caller).to.throw(Error, 'ENOENT');
});
});
const caller = () => setGlobalRootDir(input)
expect(caller).to.throw(Error, 'ENOENT')
})
})
context('a an existing file instead of a directory', () => {
it('should throw error', () => {
const { setGlobalRootDir } = cleanrequire('../set-gobal-root-dir');
const { setGlobalRootDir } = cleanrequire('../set-gobal-root-dir')
const input = __filename;
const caller = () => setGlobalRootDir(input);
const input = __filename
expect(caller).to.throw(Error, 'ENOTDIR');
});
});
});
});
const caller = () => setGlobalRootDir(input)
expect(caller).to.throw(Error, 'ENOTDIR')
})
})
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc