bpmnlint
Advanced tools
Comparing version 8.2.0 to 8.3.0
@@ -13,2 +13,4 @@ const allRules = [ | ||
'no-implicit-split', | ||
'no-implicit-end', | ||
'no-implicit-start', | ||
'no-inclusive-gateway', | ||
@@ -15,0 +17,0 @@ 'single-blank-start-event', |
@@ -14,2 +14,4 @@ module.exports = { | ||
'no-implicit-split': 'error', | ||
'no-implicit-end': 'error', | ||
'no-implicit-start': 'error', | ||
'no-inclusive-gateway': 'error', | ||
@@ -16,0 +18,0 @@ 'single-blank-start-event': 'error', |
const Module = require('module'); | ||
const path = require('path'); | ||
const { isString } = require('min-dash'); | ||
/** | ||
@@ -29,3 +31,36 @@ * A resolver that locates rules and configurations | ||
let pkgInstance; | ||
// (1) try resolving rule via $PKG.rules[$NAME] | ||
try { | ||
pkgInstance = this.require(pkg); | ||
} catch (err) { | ||
/* ignore */ | ||
} | ||
if (pkgInstance) { | ||
const rules = pkgInstance.rules || {}; | ||
if (ruleName in rules) { | ||
const rule = rules[ruleName]; | ||
if (!isString(rule)) { | ||
throw new Error('cannot resolve rule <' + ruleName + '> from <' + originalPkg + '>: illegal rule export (expected path reference)'); | ||
} | ||
// local reference, resolved relative to pkg location | ||
if (rule.startsWith('.')) { | ||
const pkgDir = path.dirname(this.require.resolve(pkg)); | ||
return this.require(path.posix.normalize(`${ pkgDir }/${ rule }`)); | ||
} | ||
// absolute reference | ||
return this.require(rule); | ||
} | ||
} | ||
// (2) try resolving rule via $PKG/rules/$NAME | ||
try { | ||
if (pkg === 'bpmnlint') { | ||
@@ -36,5 +71,5 @@ return this.requireLocal(`../../rules/${ruleName}`); | ||
} | ||
} catch (err) { | ||
throw new Error('Cannot resolve rule <' + ruleName + '> from <' + originalPkg + '>'); | ||
} | ||
} catch (err) { /* ignore */ } | ||
throw new Error('cannot resolve rule <' + ruleName + '> from <' + originalPkg + '>'); | ||
}; | ||
@@ -48,13 +83,4 @@ | ||
// resolve config via $PKG/config/$NAME | ||
// (1) try resolving config via $PKG.configs[$NAME] | ||
try { | ||
if (pkg === 'bpmnlint') { | ||
return this.requireLocal(`../../config/${configName}`); | ||
} else { | ||
return this.require(`${pkg}/config/${configName}`); | ||
} | ||
} catch (err) { /* ignore */ } | ||
// resolve config via $PKG.configs[$NAME] | ||
try { | ||
const instance = this.require(pkg); | ||
@@ -72,4 +98,13 @@ | ||
// (2) try resolving config via $PKG/config/$NAME | ||
try { | ||
if (pkg === 'bpmnlint') { | ||
return this.requireLocal(`../../config/${configName}`); | ||
} else { | ||
return this.require(`${pkg}/config/${configName}`); | ||
} | ||
} catch (err) { /* ignore */ } | ||
throw new Error( | ||
'Cannot resolve config <' + configName + '> from <' + originalPkg + '>' | ||
'cannot resolve config <' + configName + '> from <' + originalPkg + '>' | ||
); | ||
@@ -76,0 +111,0 @@ }; |
@@ -0,1 +1,5 @@ | ||
const path = require('path').posix; | ||
const { isString } = require('min-dash'); | ||
const Linter = require('../linter'); | ||
@@ -56,3 +60,3 @@ | ||
if (!rule) { | ||
throw new Error('cannot resolve rule <' + pkg + '/' + ruleName + '>'); | ||
throw new Error('cannot resolve rule <' + pkg + '/' + ruleName + '>: not bundled'); | ||
} | ||
@@ -65,3 +69,3 @@ | ||
throw new Error( | ||
'cannot resolve config <' + configName + '> in <' + pkg +'>' | ||
'cannot resolve config <' + configName + '> in <' + pkg +'>: not bundled' | ||
); | ||
@@ -98,10 +102,66 @@ }; | ||
return ` | ||
import rule_${idx} from '${resolver.normalizePkg(pkg)}/rules/${ruleName}'; | ||
cache['${pkg}/${ruleName}'] = rule_${idx};`; | ||
return createImportStatement(pkg, ruleName, idx, resolver); | ||
}).filter(e => e).join('\n'); | ||
return `${preambleCode}\n\n${importCode}`; | ||
return `${preambleCode}${importCode}`; | ||
} | ||
module.exports = compileConfig; | ||
module.exports = compileConfig; | ||
function requirePkg(resolver, pkg) { | ||
try { | ||
return resolver.require(pkg); | ||
} catch (err) { | ||
return null; | ||
} | ||
} | ||
function createImportStatement(pkg, ruleName, idx, resolver) { | ||
const originalPkg = pkg; | ||
pkg = resolver.normalizePkg(pkg); | ||
const pkgExport = requirePkg(resolver, pkg); | ||
// (1) try resolving rule via $PKG.rules[$NAME] | ||
if (pkgExport && pkgExport.rules) { | ||
const rules = pkgExport.rules; | ||
if (ruleName in rules) { | ||
const rule = rules[ruleName]; | ||
if (!isString(rule)) { | ||
throw new Error( | ||
`failed to bundle rule <${ruleName}> from <${ pkg }>: illegal rule export (expected path reference)` | ||
); | ||
} | ||
const rulePath = computeRuleImport(resolver, pkg, rule); | ||
return ` | ||
import rule_${ idx } from '${rulePath}'; | ||
cache['${ originalPkg }/${ ruleName }'] = rule_${ idx };`; | ||
} | ||
} | ||
// (2) resolve rule via $PKG/rules/$NAME | ||
return ` | ||
import rule_${ idx } from '${ pkg }/rules/${ ruleName }'; | ||
cache['${ originalPkg }/${ ruleName }'] = rule_${ idx };`; | ||
} | ||
function computeRuleImport(resolver, pkg, rule) { | ||
// local reference, resolved relative to pkg location | ||
if (rule.startsWith('.')) { | ||
const pkgDir = path.dirname(resolver.require.resolve(pkg)); | ||
return path.posix.normalize(`${ pkgDir }/${ rule }`); | ||
} | ||
// absolute reference | ||
return path.normalize(rule); | ||
} |
{ | ||
"name": "bpmnlint", | ||
"description": "Validate your BPMN diagrams based on configurable lint rules", | ||
"version": "8.2.0", | ||
"version": "8.3.0", | ||
"main": "lib/index.js", | ||
@@ -33,3 +33,3 @@ "keywords": [ | ||
"dev": "npm test -- --watch", | ||
"test": "mocha -r esm --exclude 'test/integration/cli/**' 'test/**/*.js'", | ||
"test": "mocha -r esm --exclude 'test/integration/*/**' 'test/**/*.js'", | ||
"test-coverage": "nyc --reporter=lcov --reporter=html npm test", | ||
@@ -44,7 +44,7 @@ "generate-docs-images": "npx @bpmn-io/bpmnlint-generate-docs-images ." | ||
"ansi-colors": "^4.1.3", | ||
"bpmn-moddle": "^7.1.3", | ||
"bpmnlint-utils": "^1.0.2", | ||
"bpmn-moddle": "^8.0.1", | ||
"bpmnlint-utils": "^1.1.1", | ||
"cli-table": "^0.3.11", | ||
"color-support": "^1.1.3", | ||
"min-dash": "^3.8.1", | ||
"min-dash": "^4.1.1", | ||
"mri": "^1.2.0", | ||
@@ -55,5 +55,6 @@ "pluralize": "^7.0.0", | ||
"devDependencies": { | ||
"@bpmn-io/bpmnlint-generate-docs-images": "^0.3.2", | ||
"chai": "^4.3.4", | ||
"eslint": "^8.23.1", | ||
"eslint-plugin-bpmn-io": "^0.16.0", | ||
"eslint": "^8.42.0", | ||
"eslint-plugin-bpmn-io": "^1.0.0", | ||
"esm": "^3.2.25", | ||
@@ -60,0 +61,0 @@ "execa": "^5.1.1", |
@@ -108,5 +108,3 @@ # bpmnlint | ||
For browser usage include your [linting configuration](#configuration) using your favorite bundler plug-in ([Rollup](https://www.npmjs.com/package/rollup-plugin-bpmnlint), [Webpack](https://www.npmjs.com/package/bpmnlint-loader)). | ||
## Writing a Plug-in | ||
@@ -123,2 +121,7 @@ | ||
## Bundling | ||
For browser usage include your [linting configuration](#configuration) using your favorite bundler plug-in ([Rollup](https://www.npmjs.com/package/rollup-plugin-bpmnlint), [Webpack](https://www.npmjs.com/package/bpmnlint-loader)). | ||
## Visual Feedback | ||
@@ -125,0 +128,0 @@ |
56059
35
1779
143
11
+ Addedbpmn-moddle@8.1.0(transitive)
+ Addedmin-dash@4.2.1(transitive)
+ Addedmoddle@6.2.3(transitive)
+ Addedmoddle-xml@10.1.0(transitive)
- Removedbpmn-moddle@7.1.3(transitive)
- Removedmoddle@5.0.4(transitive)
- Removedmoddle-xml@9.0.6(transitive)
Updatedbpmn-moddle@^8.0.1
Updatedbpmnlint-utils@^1.1.1
Updatedmin-dash@^4.1.1