Skip to content

Commit

Permalink
chore: lint all the things
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed Aug 21, 2023
1 parent ae0db45 commit 227df10
Show file tree
Hide file tree
Showing 65 changed files with 957 additions and 832 deletions.
2 changes: 1 addition & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ module.exports = {
'subject-case': [0],
'subject-full-stop': [0],
},
};
}
24 changes: 12 additions & 12 deletions packages/aa/test/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
const path = require('path');
const test = require('ava');
const { loadCanonicalNameMap } = require('../src/index.js');
const path = require('path')
const test = require('ava')
const { loadCanonicalNameMap } = require('../src/index.js')

test('project 1', async t => {
const canonicalNameMap = await loadCanonicalNameMap({ rootDir: path.join(__dirname, 'projects', '1') });
const canonicalNameMap = await loadCanonicalNameMap({ rootDir: path.join(__dirname, 'projects', '1') })
// normalize results to be relative
const normalizedMapEntries = Array.from(canonicalNameMap.entries()).sort()
.map(([packagePath,canonicalName])=>[path.relative(__dirname,packagePath), canonicalName])
.map(([packagePath,canonicalName]) => [path.relative(__dirname,packagePath), canonicalName])
t.deepEqual(normalizedMapEntries, [
[
'projects/1',
'$root$',
],
[
'projects/1/node_modules/aaa',
'aaa'
'aaa',
],
[
'projects/1/node_modules/bbb',
Expand All @@ -28,10 +28,10 @@ test('project 1', async t => {
})

test('project 2', async t => {
const canonicalNameMap = await loadCanonicalNameMap({ rootDir: path.join(__dirname, 'projects', '2') });
const canonicalNameMap = await loadCanonicalNameMap({ rootDir: path.join(__dirname, 'projects', '2') })
// normalize results to be relative
const normalizedMapEntries = Array.from(canonicalNameMap.entries()).sort()
.map(([packagePath,canonicalName])=>[path.relative(__dirname,packagePath), canonicalName])
.map(([packagePath,canonicalName]) => [path.relative(__dirname,packagePath), canonicalName])
t.deepEqual(normalizedMapEntries, [
[
'projects/2',
Expand All @@ -52,15 +52,15 @@ test('project 2', async t => {
[
'projects/2/node_modules/good_dep',
'good_dep',
]
],
])
})

test('project 3', async t => {
const canonicalNameMap = await loadCanonicalNameMap({ rootDir: path.join(__dirname, 'projects', '3') });
const canonicalNameMap = await loadCanonicalNameMap({ rootDir: path.join(__dirname, 'projects', '3') })
// normalize results to be relative
const normalizedMapEntries = Array.from(canonicalNameMap.entries()).sort()
.map(([packagePath,canonicalName])=>[path.relative(__dirname,packagePath), canonicalName])
.map(([packagePath,canonicalName]) => [path.relative(__dirname,packagePath), canonicalName])
t.deepEqual(normalizedMapEntries, [
[
'projects/3',
Expand All @@ -83,4 +83,4 @@ test('project 3', async t => {
'evil_dep',
],
])
})
})
10 changes: 5 additions & 5 deletions packages/allow-scripts/src/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ function writeRcFileContent({file, entry}) {

let binsBlockedMemo
/**
*
* @param {Object} args
*
* @param {Object} args
* @param {boolean} noMemoization - turn off memoization, make a fresh lookup
* @returns {boolean}
*/
Expand Down Expand Up @@ -141,15 +141,15 @@ function editPackageJson () {
} else {
console.log('@lavamoat/allow-scripts: Added dependency @lavamoat/preinstall-always-fail.')
}

if(FEATURE.bins) {
// no motivation to fix lint here, there's a better implementation of this in a neighboring branch
// eslint-disable-next-line node/global-require
// eslint-disable-next-line n/global-require
const packageJson = require(addInstallParentDir('package.json'))
if(!packageJson.scripts) {
packageJson.scripts = {}
}
// If you think `node ` is redundant below, be aware that `./cli.js` won't work on Windows,
// If you think `node ` is redundant below, be aware that `./cli.js` won't work on Windows,
// but passing a unix-style path to node on Windows works fine.
packageJson.scripts['allow-scripts'] = 'node ./node_modules/@lavamoat/allow-scripts/src/cli.js --experimental-bins'
console.log('@lavamoat/allow-scripts: Adding allow-scripts as a package.json script with direct path.')
Expand Down
8 changes: 4 additions & 4 deletions packages/allow-scripts/src/whichbin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
/* eslint-disable node/shebang */
/* eslint-disable n/shebang */

// @ts-check
const path = require('path')
Expand All @@ -22,7 +22,7 @@ async function start () {
}

console.error(`-lavamoat--allow-scripts---------------------------------------------------
There's no policy for the '${binName}' bin script.
There's no policy for the '${binName}' bin script.
You can allow this script to run by adding it to lavamoat->allowBins in package.json
Add a line like this in allowBins:
Expand All @@ -34,10 +34,10 @@ Add a line like this in allowBins:
${currentBinCandidates.map(c => c.fullLinkPath).join('\n')}
`)
}

console.error(`After you're done configuring, run allow-scripts again.
---------------------------------------------------------------------------`)

process.exit(42)

}
28 changes: 14 additions & 14 deletions packages/allow-scripts/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test('cli - auto command', (t) => {
let projectRoot = path.join(__dirname, 'projects', '1')

// delete any existing package.json
fs.rmSync(path.join(projectRoot, PACKAGE_JSON), { force: true });
fs.rmSync(path.join(projectRoot, PACKAGE_JSON), { force: true })

// npm init -y
spawnSync('npm', ['init', '-y'], realisticEnvOptions(projectRoot))
Expand All @@ -35,16 +35,16 @@ test('cli - auto command', (t) => {
// assert its contents
t.deepEqual(packageJsonContents.lavamoat, {
allowScripts: {
'bbb>evil_dep': false
}
'bbb>evil_dep': false,
},
})
})

test('cli - auto command with experimental bins', (t) => {
// set up the directories
let projectRoot = path.join(__dirname, 'projects', '1')

fs.rmSync(path.join(projectRoot, PACKAGE_JSON), { force: true });
fs.rmSync(path.join(projectRoot, PACKAGE_JSON), { force: true })

// npm init -y
spawnSync('npm', ['init', '-y'], realisticEnvOptions(projectRoot))
Expand All @@ -65,8 +65,8 @@ test('cli - auto command with experimental bins', (t) => {
karramba: 'node_modules/bbb/index.js',
},
allowScripts: {
'bbb>evil_dep': false
}
'bbb>evil_dep': false,
},
})
})

Expand All @@ -78,7 +78,7 @@ test('cli - run command - good dep at the root', (t) => {
// the force option is only here to stop rm complaining if target is missing
fs.rmSync(path.join(projectRoot, 'node_modules', '.bin'), {
recursive: true,
force: true
force: true,
})

// run the "run" command
Expand Down Expand Up @@ -111,7 +111,7 @@ test('cli - run command - good dep at the root with experimental bins', (t) => {
// the force option is only here to stop rm complaining if target is missing
fs.rmSync(path.join(projectRoot, 'node_modules', '.bin'), {
recursive: true,
force: true
force: true,
})

// run the "run" command
Expand Down Expand Up @@ -151,7 +151,7 @@ test('cli - run command - good dep as a sub dep', (t) => {
fs.rmSync(path.join(projectRoot, 'node_modules', 'bbb', '.goodscriptworked'), { force: true })
fs.rmSync(path.join(projectRoot, 'node_modules', '.bin'), {
recursive: true,
force: true
force: true,
})

// generate the bin link
Expand Down Expand Up @@ -186,7 +186,7 @@ test('cli - run command - good dep as a sub dep with experimental bins', (t) =>
fs.rmSync(path.join(projectRoot, 'node_modules', 'bbb', '.goodscriptworked'), { force: true })
fs.rmSync(path.join(projectRoot, 'node_modules', '.bin'), {
recursive: true,
force: true
force: true,
})
// run the "run" command
let result = spawnSync(ALLOW_SCRIPTS_BIN, ['run', '--experimental-bins'], realisticEnvOptions(projectRoot))
Expand All @@ -197,10 +197,10 @@ test('cli - run command - good dep as a sub dep with experimental bins', (t) =>

t.assert(fs.existsSync(path.join(projectRoot, 'node_modules', 'bbb', 'node_modules', '.bin', 'good')), 'Expected a nested bin script to be installed in bbb/node_modules/.bin')
const errarr = result.stderr.toString().split('\n')
t.assert(errarr.every(line=>!line.includes('you shall not pass')), 'Should not have run the parent script from the nested package postinstall')
t.assert(errarr.some(line=>line.includes(`"good": "node_modules/`)), 'Expected to see instructions on how to enable a bin script1')
t.assert(errarr.some(line=>line.includes(`node_modules/good_dep/cli.sh`)), 'Expected to see instructions on how to enable a bin script2')
t.assert(errarr.some(line=>line.includes(`node_modules/aaa/shouldntrun.sh`)), 'Expected to see instructions on how to enable a bin script3')
t.assert(errarr.every(line => !line.includes('you shall not pass')), 'Should not have run the parent script from the nested package postinstall')
t.assert(errarr.some(line => line.includes('"good": "node_modules/')), 'Expected to see instructions on how to enable a bin script1')
t.assert(errarr.some(line => line.includes('node_modules/good_dep/cli.sh')), 'Expected to see instructions on how to enable a bin script2')
t.assert(errarr.some(line => line.includes('node_modules/aaa/shouldntrun.sh')), 'Expected to see instructions on how to enable a bin script3')
// assert the output
t.deepEqual(result.stdout.toString().split('\n'), [
'installing bin scripts',
Expand Down
10 changes: 5 additions & 5 deletions packages/browserify/test/arguments.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const test = require('ava')

const {
runScenario
runScenario,
} = require('./util')

const { createScenarioFromScaffold, runAndTestScenario } = require('lavamoat-core/test/util')
Expand All @@ -18,8 +18,8 @@ test('arguments - lavamoat command aliases work - advanced', async (t) => {
p: '',
pp: true,
d: true,
dp: true
}
dp: true,
},
})
await runAndTestScenario(t, scenario, runScenario)
})
Expand All @@ -31,9 +31,9 @@ test('arguments - invalid lavamoat commands fail', async (t) => {
},
opts: {
z: true,
c: true
c: true,
},
expectedFailure: true,
})
await runAndTestScenario(t, scenario, runScenario)
})
})
12 changes: 7 additions & 5 deletions packages/browserify/test/basic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ const {
createBundleFromEntry,
evalBundle,
createBundleForScenario,
runScenario
runScenario,
} = require('./util')

const {
createScenarioFromScaffold,
autoConfigForScenario,
runAndTestScenario
runAndTestScenario,
} = require('lavamoat-core/test/util')

test('basic - browserify bundle doesnt inject global', async (t) => {
Expand Down Expand Up @@ -43,7 +43,7 @@ test('basic - lavamoat policy and bundle', async (t) => {
},
defineTwo: () => {
module.exports = () => location.href
}
},
})
await autoConfigForScenario({ scenario })
const { bundleForScenario } = await createBundleForScenario({ scenario })
Expand All @@ -65,15 +65,17 @@ test('basic - lavamoat bundle without prelude', async (t) => {
defineTwo: () => {
module.exports = () => location.href
},
opts: { includePrelude: false }
opts: { includePrelude: false },
})

await autoConfigForScenario({ scenario })
const { bundleForScenario } = await createBundleForScenario({ scenario })

let didCallLoadBundle = false
const testGlobal = {
LavaPack: { loadBundle: () => { didCallLoadBundle = true } }
LavaPack: { loadBundle: () => {
didCallLoadBundle = true
} },
}
evalBundle(bundleForScenario, testGlobal)

Expand Down

0 comments on commit 227df10

Please sign in to comment.