Comparing version 0.1.3 to 0.1.4
@@ -62,2 +62,4 @@ export type MessageType = 'suggestion' | 'warning' | 'error' | ||
| BaseMessage<'EXPORTS_DEFAULT_SHOULD_BE_LAST'> | ||
| BaseMessage<'EXPORTS_MODULE_SHOULD_BE_ESM'> | ||
| BaseMessage<'USE_EXPORTS_BROWSER'> | ||
@@ -64,0 +66,0 @@ export interface Options { |
{ | ||
"name": "publint", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Lint packaging errors", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -200,2 +200,12 @@ import { | ||
crawlBrowser(browser) | ||
// if the package has both the `browser` and `exports` fields, recommend to use | ||
// the browser condition instead | ||
if (exports) { | ||
messages.push({ | ||
code: 'USE_EXPORTS_BROWSER', | ||
args: {}, | ||
path: ['browser'], | ||
type: 'suggestion' | ||
}) | ||
} | ||
} | ||
@@ -328,3 +338,16 @@ | ||
if (fileContent === false) return | ||
// file format checks isn't required for `browser` field or exports | ||
// the `module` condition is only used by bundlers and must be ESM | ||
if (currentPath.includes('module')) { | ||
const actualFormat = getCodeFormat(fileContent) | ||
if (actualFormat === 'CJS') { | ||
messages.push({ | ||
code: 'EXPORTS_MODULE_SHOULD_BE_ESM', | ||
args: {}, | ||
path: currentPath, | ||
type: 'error' | ||
}) | ||
} | ||
return | ||
} | ||
// file format checks isn't required for `browser` condition or exports | ||
// after the node condtion, as nodejs doesn't use it, only bundlers do, | ||
@@ -331,0 +354,0 @@ // which doesn't care of the format |
@@ -48,6 +48,12 @@ import c from 'picocolors' | ||
// prettier-ignore | ||
return `${c.bold(fp(m.path) + '.types')} should be the first in the object as required by TypeScript.` | ||
return `${c.bold(fp(m.path))} should be the first in the object as required by TypeScript.` | ||
case 'EXPORTS_DEFAULT_SHOULD_BE_LAST': | ||
// prettier-ignore | ||
return `${c.bold(fp(m.path) + '.default')} should be the last in the object so it doesn't take precedence over the keys following it.` | ||
return `${c.bold(fp(m.path))} should be the last in the object so it doesn't take precedence over the keys following it.` | ||
case 'EXPORTS_MODULE_SHOULD_BE_ESM': | ||
// prettier-ignore | ||
return `${c.bold(fp(m.path))} should be ESM, but the code is written in CJS.` | ||
case 'USE_EXPORTS_BROWSER': | ||
// prettier-ignore | ||
return `${c.bold('pkg.browser')} can be refactored to use ${c.bold('pkg.exports')} and the ${c.bold('browser')} condition instead to declare browser-specific exports.` | ||
default: | ||
@@ -54,0 +60,0 @@ // TODO |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31692
856