Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

publint

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

publint - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

6

package.json
{
"name": "publint",
"version": "0.1.1",
"version": "0.1.2",
"description": "Lint packaging errors",

@@ -46,3 +46,3 @@ "type": "module",

"dependencies": {
"npm-packlist": "^5.1.0",
"npm-packlist": "^5.1.3",
"picocolors": "^1.0.0",

@@ -52,3 +52,3 @@ "sade": "^1.8.1"

"devDependencies": {
"uvu": "^0.5.3"
"uvu": "^0.5.6"
},

@@ -55,0 +55,0 @@ "scripts": {

@@ -34,3 +34,3 @@ import {

const rootPkg = JSON.parse(rootPkgContent)
const { main, module, exports } = rootPkg
const { main, module, exports, browser } = rootPkg

@@ -187,2 +187,18 @@ /**

// check file existance for other known package fields
const knownFields = ['types', 'jsnext:main', 'jsnext', 'unpkg', 'jsdelivr']
for (const field of knownFields) {
if (typeof rootPkg[field] === 'string') {
promiseQueue.push(async () => {
const fieldPath = vfs.pathJoin(pkgDir, rootPkg[field])
await readFile(fieldPath, [field], ['.js', '/index.js'])
})
}
}
// check file existance for browser field
if (browser) {
crawlBrowser(browser)
}
if (exports) {

@@ -245,3 +261,23 @@ // recursively check exports

function crawlExports(exports, currentPath = ['exports']) {
/**
* @param {string | Record<string, any>} fieldValue
* @param {string[]} currentPath
*/
function crawlBrowser(fieldValue, currentPath = ['browser']) {
if (typeof fieldValue === 'string') {
promiseQueue.push(async () => {
await readFile(fieldValue, currentPath)
})
} else if (typeof fieldValue === 'object') {
for (const key in fieldValue) {
crawlBrowser(fieldValue[key], currentPath.concat(key))
}
}
}
function crawlExports(
exports,
currentPath = ['exports'],
isAfterNodeCondition = false
) {
if (typeof exports === 'string') {

@@ -287,8 +323,12 @@ promiseQueue.push(async () => {

for (const filePath of exportsFiles) {
// TODO: Maybe check .ts in the future
// TODO: maybe check .ts in the future
if (!isPathLintable(filePath)) continue
pq.push(async () => {
// Could fail if in !isGlob
// could fail if in !isGlob
const fileContent = await readFile(filePath, currentPath)
if (fileContent === false) return
// file format checks isn't required for `browser` field or exports
// after the node condtion, as nodejs doesn't use it, only bundlers do,
// which doesn't care of the format
if (isAfterNodeCondition || currentPath.includes('browser')) return
const actualFormat = getCodeFormat(fileContent)

@@ -350,5 +390,23 @@ let expectFormat = await getFilePathFormat(filePath, vfs)

// keep special state of whether the next `crawlExports` iterations are after a node condition.
// if there are, we can skip code format check as nodejs doesn't touch them, except bundlers
// which are fine with any format.
let isKeyAfterNodeCondition = isAfterNodeCondition
for (const key of exportsKeys) {
if (key === 'types') continue
crawlExports(exports[key], currentPath.concat(key))
if (key === 'types') {
// only check file existance
promiseQueue.push(async () => {
const typesPath = vfs.pathJoin(pkgDir, exports[key])
await readFile(typesPath, currentPath.concat(key))
})
} else {
crawlExports(
exports[key],
currentPath.concat(key),
isKeyAfterNodeCondition
)
if (key === 'node') {
isKeyAfterNodeCondition = true
}
}
}

@@ -355,0 +413,0 @@ }

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