Skip to content

Commit

Permalink
chore: lint everything again
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed Aug 10, 2023
1 parent 3cba023 commit e14a16b
Show file tree
Hide file tree
Showing 41 changed files with 120 additions and 97 deletions.
9 changes: 5 additions & 4 deletions packages/aa/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { readFileSync, statSync } = require('fs')
const { readFileSync } = require('fs')
const path = require('path')
const nodeResolve = require('resolve')

Expand Down Expand Up @@ -31,15 +31,15 @@ function createPerformantResolve () {
readPackageSync: readPackageWithout(path),
}),
}
};
}

/**
* @param {object} options
* @returns {Promise<Map<string, string>>}
*/
async function loadCanonicalNameMap({ rootDir, includeDevDeps, resolve } = {}) {
const canonicalNameMap = new Map()
// performant resolve avoids loading package.jsons if their path is what's being resolved,
// performant resolve avoids loading package.jsons if their path is what's being resolved,
// offering 2x performance improvement compared to using original resolve
resolve = resolve || createPerformantResolve()
// resolve = resolve || nodeResolve
Expand Down Expand Up @@ -87,7 +87,8 @@ let nextLevelTodos
* @param {object} options
* @returns {Map<{packageDir: string, logicalPathParts: string[]}>}
*/
function walkDependencyTreeForBestLogicalPaths({ packageDir, logicalPath = [], includeDevDeps = false, visited = new Set(), resolve = performantResolve }) {
function walkDependencyTreeForBestLogicalPaths({ packageDir, logicalPath = [], includeDevDeps = false, visited = new Set(), resolve }) {
resolve = resolve ?? createPerformantResolve()
const preferredPackageLogicalPathMap = new Map()
// add the entry package as the first work unit
currentLevelTodos = [{ packageDir, logicalPath, includeDevDeps, visited, resolve }]
Expand Down
37 changes: 19 additions & 18 deletions packages/allow-scripts/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ const setup = require('./setup')
* @property {BinsConfig} configs.bin
* @property {boolean} somePoliciesAreMissing
*
* Individual package info
* Individual package info
* @typedef {Object} PkgInfo
* @property {string} canonicalName
* @property {string} path
* @property {Object} scripts
*
* Individual bin link info
* Individual bin link info
* @typedef {Object} BinInfo
* @property {string} canonicalName
* @property {boolean} isDirect
Expand All @@ -41,7 +41,7 @@ const setup = require('./setup')
* @property {Array} missingPolicies
* @property {Array} excessPolicies
*
* @typedef {Map<string,[BinInfo]>} BinCandidates
* @typedef {Map<string,[BinInfo]>} BinCandidates
*
* Configuration for a type of bins policies
* @typedef {Object} BinsConfig
Expand Down Expand Up @@ -193,8 +193,8 @@ function printMissingPoliciesIfAny({ missingPolicies = [], packagesWithScripts =
// internals

/**
*
* @param {Object} arg
*
* @param {Object} arg
* @param {string} arg.event
* @param {Array<PkgInfo>} arg.packages
*/
Expand All @@ -207,7 +207,7 @@ async function runAllScriptsForEvent({ event, packages }) {
}
}
/**
* @param {Array<BinInfo>} allowedBins
* @param {Array<BinInfo>} allowedBins
*/
async function installBinScripts(allowedBins) {
for (const { bin, path, link, canonicalName } of allowedBins) {
Expand All @@ -217,7 +217,7 @@ async function installBinScripts(allowedBins) {
}
/**
* Points all bins on the list to whichbin.js cli app from allow-scripts
* @param {Array<BinInfo>} firewalledBins
* @param {Array<BinInfo>} firewalledBins
* @param {string} link - absolute path to the whichbin.js script
*/
async function installBinFirewall(firewalledBins, link) {
Expand Down Expand Up @@ -250,7 +250,7 @@ async function runScript({ path, event }) {
const bannedBins = new Set(['node', 'npm', 'yarn', 'pnpm'])

/**
* @param {BinCandidates} binCandidates
* @param {BinCandidates} binCandidates
*/
function prepareBinScriptsPolicy(binCandidates) {
const policy = {}
Expand All @@ -267,7 +267,7 @@ function prepareBinScriptsPolicy(binCandidates) {


/**
* @param {BinsConfig} param0
* @param {BinsConfig} param0
*/
function printPackagesByBins({
allowedBins,
Expand All @@ -292,7 +292,7 @@ function printPackagesByBins({
}

/**
* @param {ScriptsConfig} param0
* @param {ScriptsConfig} param0
*/
function printPackagesByScriptConfiguration({
packagesWithScripts,
Expand Down Expand Up @@ -340,8 +340,8 @@ function printPackagesByScriptConfiguration({
}

/**
*
* @param {Object} args
*
* @param {Object} args
* @param {string} args.rootDir
* @param {PkgConfs} args.conf
* @returns {Promise}
Expand All @@ -362,8 +362,8 @@ async function savePackageConfigurations({ rootDir, conf: {
}

/**
*
* @param {Object} args
*
* @param {Object} args
* @param {string} args.rootDir
* @returns {Promise<PkgConfs>}
*/
Expand All @@ -372,13 +372,14 @@ async function loadAllPackageConfigurations({ rootDir }) {
const binCandidates = new Map()

const dependencyMap = await loadCanonicalNameMap({ rootDir, includeDevDeps: true })
const sortedDepEntries = Array.from(dependencyMap.entries()).sort(sortBy(([filePath, canonicalName]) => canonicalName))
const sortedDepEntries = Array.from(dependencyMap.entries()).sort(sortBy(([, canonicalName]) => canonicalName))
const packageJson = JSON.parse(await fs.readFile(path.join(rootDir, 'package.json'), 'utf8'))
const directDeps = new Set([...Object.keys(packageJson.devDependencies||{}),...Object.keys(packageJson.dependencies||{})])

for (const [filePath, canonicalName] of sortedDepEntries) {
// const canonicalName = getCanonicalNameForPath({ rootDir, filePath: filePath })
let depPackageJson
// eslint-disable-next-line no-useless-catch
try {
depPackageJson = JSON.parse(await fs.readFile(path.join(filePath, 'package.json'), 'utf-8'))
} catch (err) {
Expand Down Expand Up @@ -412,7 +413,7 @@ async function loadAllPackageConfigurations({ rootDir }) {
}
collection.push({
// canonical name for a direct dependency is just dependency name
isDirect: directDeps.has(canonicalName),
isDirect: directDeps.has(canonicalName),
bin: name,
path: filePath,
link,
Expand Down Expand Up @@ -455,9 +456,9 @@ function indexLifecycleConfiguration(config) {
// packages with config
const configuredPatterns = Object.keys(config.allowConfig)
// select allowed + disallowed
config.allowedPatterns = Object.entries(config.allowConfig).filter(([pattern, packageData]) => !!packageData).map(([pattern]) => pattern)
config.allowedPatterns = Object.entries(config.allowConfig).filter(([, packageData]) => !!packageData).map(([pattern]) => pattern)

config.disallowedPatterns = Object.entries(config.allowConfig).filter(([pattern, packageData]) => !packageData).map(([pattern]) => pattern)
config.disallowedPatterns = Object.entries(config.allowConfig).filter(([, packageData]) => !packageData).map(([pattern]) => pattern)

config.missingPolicies = Array.from(config.packagesWithScripts.keys())
.filter(pattern => !configuredPatterns.includes(pattern))
Expand Down
1 change: 0 additions & 1 deletion packages/allow-scripts/src/linker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @ts-check
// All of this is derived from the main functionality of bin-links that unfortunately would not allow for absolute path links
const { promises: fs } = require('fs')
const binTarget = require('bin-links/lib/bin-target.js')
const isWindows = require('bin-links/lib/is-windows.js')
const linkBin = isWindows ? require('bin-links/lib/shim-bin.js') : require('bin-links/lib/link-bin.js')
Expand Down
24 changes: 12 additions & 12 deletions packages/allow-scripts/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ test('cli - run command - good dep at the root', (t) => {

// assert the output
t.deepEqual(result.stdout.toString().split('\n'), [
'running lifecycle scripts for event \"preinstall\"',
'running lifecycle scripts for event "preinstall"',
'- good_dep',
'running lifecycle scripts for event \"install\"',
'running lifecycle scripts for event \"postinstall\"',
'running lifecycle scripts for event "install"',
'running lifecycle scripts for event "postinstall"',
'running lifecycle scripts for top level package',
'',
])
Expand Down Expand Up @@ -124,10 +124,10 @@ test('cli - run command - good dep at the root with experimental bins', (t) => {
t.deepEqual(result.stdout.toString().split('\n'), [
'installing bin scripts',
'- good - from package: good_dep',
'running lifecycle scripts for event \"preinstall\"',
'running lifecycle scripts for event "preinstall"',
'- good_dep',
'running lifecycle scripts for event \"install\"',
'running lifecycle scripts for event \"postinstall\"',
'running lifecycle scripts for event "install"',
'running lifecycle scripts for event "postinstall"',
'running lifecycle scripts for top level package',
'',
])
Expand Down Expand Up @@ -166,10 +166,10 @@ test('cli - run command - good dep as a sub dep', (t) => {

// assert the output
t.deepEqual(result.stdout.toString().split('\n'), [
'running lifecycle scripts for event \"preinstall\"',
'running lifecycle scripts for event "preinstall"',
'- bbb>good_dep',
'running lifecycle scripts for event \"install\"',
'running lifecycle scripts for event \"postinstall\"',
'running lifecycle scripts for event "install"',
'running lifecycle scripts for event "postinstall"',
'- bbb',
'running lifecycle scripts for top level package',
'',
Expand Down Expand Up @@ -205,10 +205,10 @@ test('cli - run command - good dep as a sub dep with experimental bins', (t) =>
t.deepEqual(result.stdout.toString().split('\n'), [
'installing bin scripts',
'- good - from package: aaa',
'running lifecycle scripts for event \"preinstall\"',
'running lifecycle scripts for event "preinstall"',
'- bbb>good_dep',
'running lifecycle scripts for event \"install\"',
'running lifecycle scripts for event \"postinstall\"',
'running lifecycle scripts for event "install"',
'running lifecycle scripts for event "postinstall"',
'- bbb',
'',
])
Expand Down
2 changes: 1 addition & 1 deletion packages/browserify/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ function validatePolicy (policy) {
throw new Error('LavaMoat - Expected label \'resources\' for configuration key')
}

Object.entries(policy.resources).forEach(([packageName, packageOpts], index) => {
Object.entries(policy.resources).forEach(([, packageOpts]) => {
const packageOptions = Object.keys(packageOpts)
const packageEntries = Object.values(packageOpts)
const optionsWhitelist = ['globals', 'packages']
Expand Down
4 changes: 2 additions & 2 deletions packages/browserify/test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test('basic - lavamoat policy and bundle', async (t) => {
})
await autoConfigForScenario({ scenario })
const { bundleForScenario } = await createBundleForScenario({ scenario })

t.true(bundleForScenario.includes('"location.href":true'), 'prelude includes href policy')

const testHref = 'https://funky.town.gov/yolo?snake=yes'
Expand All @@ -74,7 +74,7 @@ test('basic - lavamoat bundle without prelude', async (t) => {
let didCallLoadBundle = false
const testGlobal = {
LavaPack: { loadBundle: () => {
didCallLoadBundle = true
didCallLoadBundle = true
} },
}
evalBundle(bundleForScenario, testGlobal)
Expand Down
5 changes: 4 additions & 1 deletion packages/browserify/test/generatePolicy.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-undef */
const test = require('ava')

const {
Expand All @@ -19,7 +20,7 @@ test('generatePolicy - empty policy', async (t) => {
test('generatePolicy - basic policy', async (t) => {
const scenario = createScenarioFromScaffold({
defineOne: () => {
module.exports = global.two
module.exports = global.two
},
defaultPolicy: false,
})
Expand Down Expand Up @@ -83,6 +84,8 @@ test('generatePolicy - policy ignores global refs', async (t) => {
test('generatePolicy - policy ignores global refs when properties are not accessed', async (t) => {
const scenario = createScenarioFromScaffold({
defineOne: () => {
// XXX: this is probably wrong. either use `typeof window === 'undefined'` or `window === undefined`
// eslint-disable-next-line valid-typeof
typeof window !== undefined
},
defaultPolicy: false,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/lib/strict-scope-terminator.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ const alwaysThrowHandler = new Proxy(
}),
)

/*
* scopeProxyHandlerProperties
/**
* scopeTerminatorHandler manages a strictScopeTerminator Proxy which serves as
* the final scope boundary that will always return "undefined" in order
* to prevent access to "start compartment globals".
* @type {ProxyHandler}
*/
const scopeProxyHandlerProperties = {
get(_shadow, _prop) {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/generateKernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function generateKernel (_opts = {}) {
output = replaceTemplateRequire(output, 'ses', sesSrc)
output = stringReplace(output, '__createKernelCore__', kernelCode)
output = stringReplace(output, '__lavamoatDebugOptions__', JSON.stringify({debugMode: !!opts.debugMode}))
// eslint-disable-next-line no-prototype-builtins
if (opts?.hasOwnProperty('scuttleGlobalThis')) {
// scuttleGlobalThis config placeholder should be set only if ordered so explicitly.
// if not, should be left as is to be replaced by a later processor (e.g. LavaPack).
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/generatePolicy.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function createModuleInspector (opts = {}) {
}
}

// eslint-disable-next-line no-unused-vars
function inspectBuiltinModule (moduleRecord) {
// builtins themselves do not require any configuration
// packages that import builtins need to add that to their configuration
Expand Down Expand Up @@ -189,7 +190,7 @@ function createModuleInspector (opts = {}) {
function inspectForImports (ast, moduleRecord, packageName, isBuiltin, includeDebugInfo) {
// get all requested names that resolve to isBuiltin
const namesForBuiltins = Object.entries(moduleRecord.importMap)
.filter(([_, resolvedName]) => isBuiltin(resolvedName))
.filter(([, resolvedName]) => isBuiltin(resolvedName))
.map(([requestedName]) => requestedName)
const { cjsImports: moduleBuiltins } = inspectImports(ast, namesForBuiltins)
if (!moduleBuiltins.length) {
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/kernelCoreTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,14 @@

const obj = Object.create(null)
for (const prop of props) {
// eslint-disable-next-line no-inner-declarations
function set() {
console.warn(
`LavaMoat - property "${prop}" of globalThis cannot be set under scuttling mode. ` +
'To learn more visit https://github.com/LavaMoat/LavaMoat/pull/360.',
)
}
// eslint-disable-next-line no-inner-declarations
function get() {
throw new Error(
`LavaMoat - property "${prop}" of globalThis is inaccessible under scuttling mode. ` +
Expand Down Expand Up @@ -230,6 +232,7 @@
// this is passed to the module initializer
// it adds the context of the parent module
// this could be replaced via "Function.prototype.bind" if its more performant
// eslint-disable-next-line no-inner-declarations
function requireRelativeWithContext (requestedName) {
const parentModuleExports = moduleObj.exports
const parentModuleData = moduleData
Expand All @@ -248,7 +251,8 @@
const parentModulePackageName = parentModuleData.package
const parentPackagesWhitelist = parentPackagePolicy.packages
const parentBuiltinsWhitelist = Object.entries(parentPackagePolicy.builtin)
.filter(([_, allowed]) => allowed === true)
.filter(([, allowed]) => allowed === true)
// eslint-disable-next-line no-unused-vars
.map(([packagePath, allowed]) => packagePath.split('.')[0])

// resolve the moduleId from the requestedName
Expand Down Expand Up @@ -298,6 +302,7 @@
// grab all allowed builtin paths that match this package
.filter(([packagePath, allowed]) => allowed === true && moduleId === packagePath.split('.')[0])
// only include the paths after the packageName
// eslint-disable-next-line no-unused-vars
.map(([packagePath, allowed]) => packagePath.split('.').slice(1).join('.'))
.sort()
)
Expand Down Expand Up @@ -475,7 +480,7 @@
// transform functions, getters & setters on prop descs. Solves SES scope proxy bug
Object.entries(Object.getOwnPropertyDescriptors(endowments))
// ignore non-configurable properties because we are modifying endowments in place
.filter(([key, propDesc]) => propDesc.configurable)
.filter(([, propDesc]) => propDesc.configurable)
.forEach(([key, propDesc]) => {
const wrappedPropDesc = applyEndowmentPropDescTransforms(propDesc, packageCompartment, rootPackageCompartment.globalThis)
Reflect.defineProperty(endowments, key, wrappedPropDesc)
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/kernelTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
// create the SES rootRealm
// "templateRequire" calls are inlined in "generateKernel"
// load-bearing semi-colon, do not remove
// eslint-disable-next-line no-extra-semi
;templateRequire('ses')

const lockdownOptions = {
Expand Down

0 comments on commit e14a16b

Please sign in to comment.