Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Commit

Permalink
fix: actually skip scripts set to false
Browse files Browse the repository at this point in the history
  • Loading branch information
dominykas committed Feb 10, 2019
1 parent e3e8502 commit 73db129
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ exports.run = async (options) => {

if (allowScripts[name] === false) {
console.warn(`==========> skip ${path} (because it is not allowed in package.json)`);
return false;
}

if (allowScripts[name] === true) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/dominykas/allow-scripts.git"
},
"scripts": {
"test": "lab -L -t 78 -m 5000"
"test": "lab -L -t 80 -m 5000"
},
"bin": {
"allow-scripts": "./bin/allow-scripts.js"
Expand Down
14 changes: 14 additions & 0 deletions test/fixtures/allowed-false.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"private": true,
"name": "@example/allowed-false",
"version": "0.0.0",
"dependencies": {
"@example/with-install-script": "*",
"@example/with-postinstall-script": "*",
"@example/without-scripts": "*"
},
"allowScripts": {
"@example/with-install-script": false,
"@example/with-postinstall-script": "*"
}
}
2 changes: 1 addition & 1 deletion test/fixtures/basic.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"allowScripts": {
"@example/with-preinstall-script": "*",
"@example/with-install-script": "*",
"@example/with-postinstall-script": "*"
"@example/with-postinstall-script": true
},
"scripts": {
"preinstall": "echo preinstall from basic >> ${OUTPUT}",
Expand Down
14 changes: 13 additions & 1 deletion test/fixtures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Fs = require('fs');
const Mkdirp = require('mkdirp');
const Path = require('path');
const Rimraf = require('rimraf');
const Sinon = require('sinon');


const internals = {
Expand Down Expand Up @@ -43,6 +44,16 @@ exports.setup = (main, deps) => {
process.env.OUTPUT = originalOutput;
});

const log = [];
const appendLog = (...items) => {

log.push(items.map((i) => i || '').join(' ').replace(new RegExp(cwd, 'g'), '.'));
};

Sinon.stub(console, 'info').callsFake(appendLog);
Sinon.stub(console, 'log').callsFake(appendLog);
Sinon.stub(console, 'warn').callsFake(appendLog);

return {
getExpectedResult: () => {

Expand All @@ -55,7 +66,7 @@ exports.setup = (main, deps) => {

getLog: () => {

return console.log.args.map((args) => args[0] || '').join('\n').replace(new RegExp(cwd, 'g'), '.').trim();
return log.join('\n').trim();
}
};
};
Expand All @@ -64,4 +75,5 @@ exports.restore = () => {

internals.restore.forEach((restore) => restore());
internals.restore = [];
Sinon.restore();
};
20 changes: 15 additions & 5 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const Fixtures = require('./fixtures');
const Sinon = require('sinon');


const Allow = require('..');
Expand All @@ -17,15 +16,12 @@ describe('allow-scripts', () => {
let cwd;
beforeEach(() => {

Sinon.stub(console, 'log');
Sinon.stub(console, 'info');
cwd = process.cwd();
});

afterEach(() => {

Fixtures.restore();
Sinon.restore();
process.chdir(cwd);
});

Expand Down Expand Up @@ -56,9 +52,23 @@ describe('allow-scripts', () => {

await expect(Allow.run({})).to.reject('No entry for @example/with-install-script');

expect(fixture.getActualResult()).not.to.contain('with-postinstall-script');
expect(fixture.getActualResult()).to.equal('');
expect(fixture.getLog()).to.equal('');
});

it('skips scripts which are forbidden', async () => {

const fixture = Fixtures.setup('allowed-false', [
'with-install-script',
'with-postinstall-script',
'without-scripts'
]);

await Allow.run({});

expect(fixture.getActualResult()).not.to.contain('with-install-script');
expect(fixture.getActualResult()).to.equal('postinstall from with-postinstall-script');
expect(fixture.getLog()).to.contain('skip node_modules/@example/with-install-script (because it is not allowed in package.json)');
});
});
});

0 comments on commit 73db129

Please sign in to comment.