1
0

Switch to handrolled semver implementation

This commit is contained in:
Bán Dénes 2022-01-23 21:45:09 +01:00
parent 2b98b502d6
commit 06d2ae4a7f
8 changed files with 48 additions and 71 deletions

56
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "ergogen",
"version": "3.1.2",
"version": "4.0.0-develop",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "ergogen",
"version": "3.1.2",
"version": "4.0.0-develop",
"license": "MIT",
"dependencies": {
"@jscad/openjscad": "github:ergogen/oldjscad",
@ -15,7 +15,6 @@
"kle-serial": "github:ergogen/kle-serial#ergogen",
"makerjs": "github:ergogen/maker.js#ergogen",
"mathjs": "^10.0.0",
"semver": "^7.3.5",
"yargs": "^17.3.0"
},
"bin": {
@ -2025,17 +2024,6 @@
"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": {
"version": "0.25.7",
"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",
"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": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz",
@ -3127,11 +3101,6 @@
"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": {
"version": "17.3.0",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.3.0.tgz",
@ -4739,14 +4708,6 @@
"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": {
"version": "0.25.7",
"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",
"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": {
"version": "6.0.0",
"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",
"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": {
"version": "17.3.0",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.3.0.tgz",

View File

@ -21,7 +21,6 @@
"kle-serial": "github:ergogen/kle-serial#ergogen",
"makerjs": "github:ergogen/maker.js#ergogen",
"mathjs": "^10.0.0",
"semver": "^7.3.5",
"yargs": "^17.3.0"
},
"devDependencies": {

View File

@ -6,15 +6,16 @@
### 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
- Use the same `what`/`where` infrastructure as outlines
- Collapse params/nets/anchors into a single hierarchy from the user's POV
- 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 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
- 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.

View File

@ -4,19 +4,18 @@ import commonjs from '@rollup/plugin-commonjs'
export default {
input: 'src/ergogen.js',
external: ['makerjs', 'js-yaml', 'mathjs', 'kle-serial', '@jscad/openjscad', 'semver'],
external: ['makerjs', 'js-yaml', 'mathjs', 'kle-serial', '@jscad/openjscad'],
output: {
name: 'ergogen',
file: 'dist/ergogen.js',
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: {
'makerjs': 'makerjs',
'js-yaml': 'jsyaml',
'mathjs': 'math',
'kle-serial': 'kle',
'@jscad/openjscad': 'myjscad',
'semver': 'semver'
'@jscad/openjscad': 'myjscad'
}
},
plugins: [

View File

@ -7,7 +7,6 @@ const outlines_lib = require('./outlines')
const cases_lib = require('./cases')
const pcbs_lib = require('./pcbs')
const semver = require('semver')
const version = require('../package.json').version
const process = async (raw, debug=false, logger=()=>{}) => {
@ -34,12 +33,9 @@ const process = async (raw, debug=false, logger=()=>{}) => {
if (config.meta && config.meta.engine) {
logger('Checking compatibility...')
const engine = semver.validRange(config.meta.engine)
if (!engine) {
throw new Error('Invalid config engine declaration!')
}
if (!semver.satisfies(version, engine)) {
throw new Error(`Current ergogen version (${version}) doesn\'t satisfy config's engine requirement (${engine})!`)
const engine = u.semver(config.meta.engine, 'config.meta.engine')
if (!u.satisfies(version, engine)) {
throw new Error(`Current ergogen version (${version}) doesn\'t satisfy config's engine requirement (${config.meta.engine})!`)
}
}

View File

@ -108,4 +108,23 @@ exports.stack = (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
)
)
}

View File

@ -90,9 +90,9 @@ describe('Interface', function() {
it('engine', async function() {
return Promise.all([
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"
ergogen.process({'meta.engine': `^${version}`}).should.be.rejectedWith('points clause')
ergogen.process({'meta.engine': `${version}`}).should.be.rejectedWith('points clause')
])
})

View File

@ -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
})
})