Comparing version 0.1.11 to 0.1.12
@@ -85,2 +85,6 @@ export type MessageType = 'suggestion' | 'warning' | 'error' | ||
level?: 'suggestion' | 'warning' | 'error' | ||
/** | ||
* Report warnings as errors. | ||
*/ | ||
strict?: boolean | ||
} | ||
@@ -87,0 +91,0 @@ |
@@ -14,4 +14,5 @@ import { publint as _publint } from '../src/index.js' | ||
vfs: options.vfs, | ||
level: options.level ?? 'suggestion' | ||
level: options.level ?? 'suggestion', | ||
strict: options?.strict ?? false | ||
}) | ||
} |
@@ -21,2 +21,3 @@ #!/usr/bin/env node | ||
) | ||
.option('--strict', `Report warnings as errors`, false) | ||
@@ -29,3 +30,3 @@ cli | ||
const pkgDir = dir ? path.resolve(dir) : process.cwd() | ||
const logs = await lintDir(pkgDir, opts.level) | ||
const logs = await lintDir(pkgDir, opts.level, opts.strict) | ||
logs.forEach((l) => console.log(l)) | ||
@@ -75,3 +76,3 @@ }) | ||
const depDir = await findDepPath(deps[i], pkgDir) | ||
const logs = depDir ? await lintDir(depDir, opts.level, true) : [] | ||
const logs = depDir ? await lintDir(depDir, opts.level, opts.strict, true) : [] | ||
// log this lint result | ||
@@ -106,5 +107,6 @@ const log = () => { | ||
* @param {import('../index.js').Options['level']} level | ||
* @param {import('../index.js').Options['strict']} strict | ||
* @param {boolean} [compact] | ||
*/ | ||
async function lintDir(pkgDir, level, compact = false) { | ||
async function lintDir(pkgDir, level, strict, compact = false) { | ||
/** @type {string[]} */ | ||
@@ -122,3 +124,3 @@ const logs = [] | ||
const pkgName = rootPkg.name || path.basename(pkgDir) | ||
const messages = await publint({ pkgDir, level }) | ||
const messages = await publint({ pkgDir, level, strict }) | ||
@@ -125,0 +127,0 @@ if (messages.length) { |
@@ -20,4 +20,5 @@ import fs from 'node:fs/promises' | ||
level: options?.level ?? 'suggestion', | ||
strict: options?.strict ?? false, | ||
_packedFiles: packedFiles | ||
}) | ||
} |
{ | ||
"name": "publint", | ||
"version": "0.1.11", | ||
"version": "0.1.12", | ||
"description": "Lint packaging errors", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -64,3 +64,7 @@ <br> | ||
*/ | ||
level: 'warning' | ||
level: 'warning', | ||
/** | ||
* Report warnings as errors. | ||
*/ | ||
strict: true | ||
}) | ||
@@ -75,7 +79,12 @@ | ||
import { printMessage } from 'publint/utils' | ||
import fs from 'node:fs/promises' | ||
const pkg = JSON.parse( | ||
await fs.readFile('./path/to/package/package.json', 'utf8') | ||
) | ||
for (const message of messages) { | ||
// Prints default message in Node.js. Always a no-op in browsers. | ||
// Useful for re-implementing the CLI in a programmatic way. | ||
printMessage(message) | ||
printMessage(message, pkg) | ||
} | ||
@@ -82,0 +91,0 @@ ``` |
@@ -25,3 +25,3 @@ import { | ||
*/ | ||
export async function publint({ pkgDir, vfs, level, _packedFiles }) { | ||
export async function publint({ pkgDir, vfs, level, strict, _packedFiles }) { | ||
/** @type {import('..').Message[]} */ | ||
@@ -298,2 +298,10 @@ const messages = [] | ||
if (strict) { | ||
for (const message of messages) { | ||
if (message.type === 'warning') { | ||
message.type = 'error' | ||
} | ||
} | ||
} | ||
if (level === 'warning') { | ||
@@ -300,0 +308,0 @@ return messages.filter((m) => m.type !== 'suggestion') |
@@ -140,2 +140,8 @@ /** | ||
export async function getFilePathFormat(filePath, vfs) { | ||
// React Native bundler treats `.native.js` as special platform extension, the real format | ||
// can be found after stripping `.native.js`, which I think is good enough? | ||
// https://reactnative.dev/docs/platform-specific-code#native-specific-extensions-ie-sharing-code-with-nodejs-and-web | ||
// https://github.com/apollographql/apollo-client/issues/9976#issuecomment-1545472585 | ||
// https://github.com/facebook/metro/issues/535 | ||
if (filePath.endsWith('.native.js')) filePath = filePath.slice(0, -10) | ||
if (filePath.endsWith('.mjs')) return 'ESM' | ||
@@ -142,0 +148,0 @@ if (filePath.endsWith('.cjs')) return 'CJS' |
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
45483
1222
94