Switch to handrolled semver implementation
This commit is contained in:
parent
2b98b502d6
commit
06d2ae4a7f
8 changed files with 48 additions and 71 deletions
56
package-lock.json
generated
56
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "ergogen",
|
"name": "ergogen",
|
||||||
"version": "3.1.2",
|
"version": "4.0.0-develop",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "ergogen",
|
"name": "ergogen",
|
||||||
"version": "3.1.2",
|
"version": "4.0.0-develop",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@jscad/openjscad": "github:ergogen/oldjscad",
|
"@jscad/openjscad": "github:ergogen/oldjscad",
|
||||||
|
@ -15,7 +15,6 @@
|
||||||
"kle-serial": "github:ergogen/kle-serial#ergogen",
|
"kle-serial": "github:ergogen/kle-serial#ergogen",
|
||||||
"makerjs": "github:ergogen/maker.js#ergogen",
|
"makerjs": "github:ergogen/maker.js#ergogen",
|
||||||
"mathjs": "^10.0.0",
|
"mathjs": "^10.0.0",
|
||||||
"semver": "^7.3.5",
|
|
||||||
"yargs": "^17.3.0"
|
"yargs": "^17.3.0"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
|
@ -2025,17 +2024,6 @@
|
||||||
"url": "https://github.com/sponsors/sindresorhus"
|
"url": "https://github.com/sponsors/sindresorhus"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/lru-cache": {
|
|
||||||
"version": "6.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
|
|
||||||
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
|
|
||||||
"dependencies": {
|
|
||||||
"yallist": "^4.0.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=10"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/magic-string": {
|
"node_modules/magic-string": {
|
||||||
"version": "0.25.7",
|
"version": "0.25.7",
|
||||||
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.7.tgz",
|
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.7.tgz",
|
||||||
|
@ -2785,20 +2773,6 @@
|
||||||
"resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-3.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-3.0.5.tgz",
|
||||||
"integrity": "sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg=="
|
"integrity": "sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg=="
|
||||||
},
|
},
|
||||||
"node_modules/semver": {
|
|
||||||
"version": "7.3.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz",
|
|
||||||
"integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==",
|
|
||||||
"dependencies": {
|
|
||||||
"lru-cache": "^6.0.0"
|
|
||||||
},
|
|
||||||
"bin": {
|
|
||||||
"semver": "bin/semver.js"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=10"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/serialize-javascript": {
|
"node_modules/serialize-javascript": {
|
||||||
"version": "6.0.0",
|
"version": "6.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz",
|
||||||
|
@ -3127,11 +3101,6 @@
|
||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/yallist": {
|
|
||||||
"version": "4.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
|
|
||||||
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
|
|
||||||
},
|
|
||||||
"node_modules/yargs": {
|
"node_modules/yargs": {
|
||||||
"version": "17.3.0",
|
"version": "17.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.3.0.tgz",
|
||||||
|
@ -4739,14 +4708,6 @@
|
||||||
"is-unicode-supported": "^0.1.0"
|
"is-unicode-supported": "^0.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"lru-cache": {
|
|
||||||
"version": "6.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
|
|
||||||
"integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
|
|
||||||
"requires": {
|
|
||||||
"yallist": "^4.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"magic-string": {
|
"magic-string": {
|
||||||
"version": "0.25.7",
|
"version": "0.25.7",
|
||||||
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.7.tgz",
|
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.7.tgz",
|
||||||
|
@ -5330,14 +5291,6 @@
|
||||||
"resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-3.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-3.0.5.tgz",
|
||||||
"integrity": "sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg=="
|
"integrity": "sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg=="
|
||||||
},
|
},
|
||||||
"semver": {
|
|
||||||
"version": "7.3.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz",
|
|
||||||
"integrity": "sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ==",
|
|
||||||
"requires": {
|
|
||||||
"lru-cache": "^6.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"serialize-javascript": {
|
"serialize-javascript": {
|
||||||
"version": "6.0.0",
|
"version": "6.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz",
|
||||||
|
@ -5585,11 +5538,6 @@
|
||||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
|
||||||
"integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA=="
|
"integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA=="
|
||||||
},
|
},
|
||||||
"yallist": {
|
|
||||||
"version": "4.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
|
|
||||||
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
|
|
||||||
},
|
|
||||||
"yargs": {
|
"yargs": {
|
||||||
"version": "17.3.0",
|
"version": "17.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.3.0.tgz",
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
"kle-serial": "github:ergogen/kle-serial#ergogen",
|
"kle-serial": "github:ergogen/kle-serial#ergogen",
|
||||||
"makerjs": "github:ergogen/maker.js#ergogen",
|
"makerjs": "github:ergogen/maker.js#ergogen",
|
||||||
"mathjs": "^10.0.0",
|
"mathjs": "^10.0.0",
|
||||||
"semver": "^7.3.5",
|
|
||||||
"yargs": "^17.3.0"
|
"yargs": "^17.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
@ -6,15 +6,16 @@
|
||||||
|
|
||||||
### Major
|
### Major
|
||||||
|
|
||||||
|
- Anchor overhaul
|
||||||
|
- Recursive-ize anchors
|
||||||
|
- This will potentially cause `ref` to be ambiguous, so maybe introduce a separate `refs` plural?
|
||||||
|
- Add `orient`/`rotate` **towards** other anchors (again, recursively)
|
||||||
- Restructure pcb point/footprint filtering
|
- Restructure pcb point/footprint filtering
|
||||||
- Use the same `what`/`where` infrastructure as outlines
|
- Use the same `what`/`where` infrastructure as outlines
|
||||||
- Collapse params/nets/anchors into a single hierarchy from the user's POV
|
- Collapse params/nets/anchors into a single hierarchy from the user's POV
|
||||||
- Add per-footprint mirror support
|
- Add per-footprint mirror support
|
||||||
- Add some way for footprints to be able to "resist" the mirroring-related special treatment of negative X shift, rotation, etc.
|
- Add some way for footprints to be able to "resist" the mirroring-related special treatment of negative X shift, rotation, etc.
|
||||||
- Add auto-bind
|
- Add auto-bind
|
||||||
- Recursive-ize anchors
|
|
||||||
- This will potentially cause `ref` to be ambiguous, so maybe introduce a separate `refs` plural?
|
|
||||||
- Plus add `orient`/`rotate` **towards** other anchors (again, recursively)
|
|
||||||
- Merge, generalize, and uniform-ize footprints
|
- Merge, generalize, and uniform-ize footprints
|
||||||
- Template for creating them, built-in variables they can use, documentation, external links, etc.
|
- Template for creating them, built-in variables they can use, documentation, external links, etc.
|
||||||
- Also considering how (or, on which layer) they define their silks, universal mirroring behaviour, etc.
|
- Also considering how (or, on which layer) they define their silks, universal mirroring behaviour, etc.
|
||||||
|
|
|
@ -4,19 +4,18 @@ import commonjs from '@rollup/plugin-commonjs'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
input: 'src/ergogen.js',
|
input: 'src/ergogen.js',
|
||||||
external: ['makerjs', 'js-yaml', 'mathjs', 'kle-serial', '@jscad/openjscad', 'semver'],
|
external: ['makerjs', 'js-yaml', 'mathjs', 'kle-serial', '@jscad/openjscad'],
|
||||||
output: {
|
output: {
|
||||||
name: 'ergogen',
|
name: 'ergogen',
|
||||||
file: 'dist/ergogen.js',
|
file: 'dist/ergogen.js',
|
||||||
format: 'umd',
|
format: 'umd',
|
||||||
banner: `/*!\n * Ergogen v${pkg.version}\n * https://zealot.hu/ergogen\n */\n`,
|
banner: `/*!\n * Ergogen v${pkg.version}\n * https://ergogen.xyz\n */\n`,
|
||||||
globals: {
|
globals: {
|
||||||
'makerjs': 'makerjs',
|
'makerjs': 'makerjs',
|
||||||
'js-yaml': 'jsyaml',
|
'js-yaml': 'jsyaml',
|
||||||
'mathjs': 'math',
|
'mathjs': 'math',
|
||||||
'kle-serial': 'kle',
|
'kle-serial': 'kle',
|
||||||
'@jscad/openjscad': 'myjscad',
|
'@jscad/openjscad': 'myjscad'
|
||||||
'semver': 'semver'
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
|
|
|
@ -7,7 +7,6 @@ const outlines_lib = require('./outlines')
|
||||||
const cases_lib = require('./cases')
|
const cases_lib = require('./cases')
|
||||||
const pcbs_lib = require('./pcbs')
|
const pcbs_lib = require('./pcbs')
|
||||||
|
|
||||||
const semver = require('semver')
|
|
||||||
const version = require('../package.json').version
|
const version = require('../package.json').version
|
||||||
|
|
||||||
const process = async (raw, debug=false, logger=()=>{}) => {
|
const process = async (raw, debug=false, logger=()=>{}) => {
|
||||||
|
@ -34,12 +33,9 @@ const process = async (raw, debug=false, logger=()=>{}) => {
|
||||||
|
|
||||||
if (config.meta && config.meta.engine) {
|
if (config.meta && config.meta.engine) {
|
||||||
logger('Checking compatibility...')
|
logger('Checking compatibility...')
|
||||||
const engine = semver.validRange(config.meta.engine)
|
const engine = u.semver(config.meta.engine, 'config.meta.engine')
|
||||||
if (!engine) {
|
if (!u.satisfies(version, engine)) {
|
||||||
throw new Error('Invalid config engine declaration!')
|
throw new Error(`Current ergogen version (${version}) doesn\'t satisfy config's engine requirement (${config.meta.engine})!`)
|
||||||
}
|
|
||||||
if (!semver.satisfies(version, engine)) {
|
|
||||||
throw new Error(`Current ergogen version (${version}) doesn\'t satisfy config's engine requirement (${engine})!`)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
19
src/utils.js
19
src/utils.js
|
@ -108,4 +108,23 @@ exports.stack = (a, b) => {
|
||||||
a, b
|
a, b
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const semver = exports.semver = (str, name='') => {
|
||||||
|
const main = str.split('-')[0]
|
||||||
|
if (/^\d+\.\d+\.\d+$/.test(main)) {
|
||||||
|
const parts = main.split('.').map(v => parseInt(v))
|
||||||
|
return {major: parts[0], minor: parts[1], patch: parts[2]}
|
||||||
|
} else throw new Error(`Invalid semver "${str}" at ${name}!`)
|
||||||
|
}
|
||||||
|
|
||||||
|
const satisfies = exports.satisfies = (current, expected) => {
|
||||||
|
if (current.major === undefined) current = semver(current)
|
||||||
|
if (expected.major === undefined) expected = semver(expected)
|
||||||
|
return current.major === expected.major && (
|
||||||
|
current.minor > expected.minor || (
|
||||||
|
current.minor === expected.minor &&
|
||||||
|
current.patch >= expected.patch
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
|
@ -90,9 +90,9 @@ describe('Interface', function() {
|
||||||
it('engine', async function() {
|
it('engine', async function() {
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
ergogen.process({'meta.engine': 'invalid'}).should.be.rejectedWith('Invalid'),
|
ergogen.process({'meta.engine': 'invalid'}).should.be.rejectedWith('Invalid'),
|
||||||
ergogen.process({'meta.engine': '^0.1.2'}).should.be.rejectedWith('satisfy'),
|
ergogen.process({'meta.engine': '0.1.2'}).should.be.rejectedWith('satisfy'),
|
||||||
// no "points clause" means we're over the engine check, so it "succeeded"
|
// no "points clause" means we're over the engine check, so it "succeeded"
|
||||||
ergogen.process({'meta.engine': `^${version}`}).should.be.rejectedWith('points clause')
|
ergogen.process({'meta.engine': `${version}`}).should.be.rejectedWith('points clause')
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -132,4 +132,19 @@ describe('Utils', function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('semver', function() {
|
||||||
|
u.semver('1.2.3').should.deep.equal({major: 1, minor: 2, patch: 3})
|
||||||
|
u.semver('1.2.3-develop').should.deep.equal({major: 1, minor: 2, patch: 3})
|
||||||
|
u.semver.bind(this, 'invalid', 'name').should.throw()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('satisfies', function() {
|
||||||
|
u.satisfies('1.2.3', '1.2.3').should.be.true
|
||||||
|
u.satisfies('1.2.3', '1.2.1').should.be.true
|
||||||
|
u.satisfies('1.2.3', '1.1.0').should.be.true
|
||||||
|
u.satisfies('1.2.3', '1.2.4').should.be.false
|
||||||
|
u.satisfies('1.2.3', '1.3.0').should.be.false
|
||||||
|
u.satisfies('1.2.3', '2.0.0').should.be.false
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
Loading…
Add table
Add a link
Reference in a new issue