Socket
Socket
Sign inDemoInstall

publint

Package Overview
Dependencies
Maintainers
1
Versions
31
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.2.6 to 0.2.7

2

index.d.ts

@@ -69,5 +69,7 @@ export type MessageType = 'suggestion' | 'warning' | 'error'

| BaseMessage<'EXPORTS_VALUE_INVALID', { suggestValue: string }>
| BaseMessage<'EXPORTS_MISSING_ROOT_ENTRYPOINT', { mainFields: string[] }>
| BaseMessage<'USE_EXPORTS_BROWSER'>
| BaseMessage<'USE_EXPORTS_OR_IMPORTS_BROWSER'>
| BaseMessage<'USE_FILES'>
| BaseMessage<'USE_TYPE'>
| BaseMessage<

@@ -74,0 +76,0 @@ 'TYPES_NOT_EXPORTED',

2

package.json
{
"name": "publint",
"version": "0.2.6",
"version": "0.2.7",
"description": "Lint packaging errors",

@@ -5,0 +5,0 @@ "type": "module",

@@ -79,2 +79,13 @@ import {

// Check if "type" field is specified, help Node.js push towards an ESM default future:
// https://nodejs.org/en/blog/release/v20.10.0
if (rootPkg.type == null) {
messages.push({
code: 'USE_TYPE',
args: {},
path: ['name'],
type: 'suggestion'
})
}
// Relies on default node resolution

@@ -198,2 +209,29 @@ // https://nodejs.org/api/modules.html#all-together

// if main or module is exists, and exports exists, check if there's a root
// entrypoint in exports. it may be mistaken that exports can be used to define
// nested entrypoints only (missing the root entrypoint)
if ((main != null || module != null) && exports != null) {
let hasRootExports = true
if (typeof exports == 'object') {
const exportsKeys = Object.keys(exports)
// an exports object could contain conditions, or paths that maps to other objects.
// we can determine the type of the object by checking one of the keys ([0])
// if it's a path, which we can then proceed to check if it has the root path
if (exportsKeys[0]?.startsWith('.') && !exportsKeys.includes('.')) {
hasRootExports = false
}
}
if (!hasRootExports) {
const mainFields = []
if (main) mainFields.push('main')
if (module) mainFields.push('module')
messages.push({
code: 'EXPORTS_MISSING_ROOT_ENTRYPOINT',
args: { mainFields },
path: exportsPkgPath,
type: 'warning'
})
}
}
// check file existence for other known package fields

@@ -200,0 +238,0 @@ const knownFields = [

@@ -86,2 +86,7 @@ import c from 'picocolors'

return `${c.bold(fp(m.path))} is ${c.bold(pv(m.path))} but is invalid as it does not start with "${c.bold('./')}". Use ${c.bold(m.args.suggestValue)} instead.`
case 'EXPORTS_MISSING_ROOT_ENTRYPOINT': {
const mainField = m.args.mainFields[0]
// prettier-ignore
return `${c.bold(fp(m.path))} is missing the root entrypoint export, which is defined in ${c.bold('pkg.' + mainField)}. Environments that support the ${c.bold('"exports"')} field will ignore ${c.bold('pkg.' + mainField)} as ${c.bold('"exports"')} takes the highest priority. Consider adding ${c.bold(fp(m.path.concat('.')))}: "${c.bold(pv([mainField]))}".`
}
case 'USE_EXPORTS_BROWSER':

@@ -97,2 +102,5 @@ // prettier-ignore

return `The package ${c.bold('publishes internal tests or config files')}. You can use ${c.bold('pkg.files')} to only publish certain files and save user bandwidth.`
case 'USE_TYPE':
// prettier-ignore
return `The package does not specify the ${c.bold('type')} field. Environments may incorrectly identify a CJS file as ESM in the future. Consider adding ${c.bold('"type"')}: "${c.bold('commonjs')}".`
case 'TYPES_NOT_EXPORTED': {

@@ -99,0 +107,0 @@ const typesFilePath = exportsRel(m.args.typesFilePath)

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