From 06d2ae4a7fc525a0588d390eecedc575eb82916d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1n=20D=C3=A9nes?= Date: Sun, 23 Jan 2022 21:45:09 +0100 Subject: [PATCH] Switch to handrolled semver implementation --- package-lock.json | 56 ++---------------------------------------- package.json | 1 - roadmap.md | 7 +++--- rollup.config.js | 7 +++--- src/ergogen.js | 10 +++----- src/utils.js | 19 ++++++++++++++ test/unit/interface.js | 4 +-- test/unit/utils.js | 15 +++++++++++ 8 files changed, 48 insertions(+), 71 deletions(-) diff --git a/package-lock.json b/package-lock.json index e929a49..9d18e6b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 9f404f3..e2c9a2b 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/roadmap.md b/roadmap.md index b024237..e2fa5a9 100644 --- a/roadmap.md +++ b/roadmap.md @@ -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. diff --git a/rollup.config.js b/rollup.config.js index 4ba6988..8a9817b 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -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: [ diff --git a/src/ergogen.js b/src/ergogen.js index 5f223b7..8d548c7 100644 --- a/src/ergogen.js +++ b/src/ergogen.js @@ -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})!`) } } diff --git a/src/utils.js b/src/utils.js index 089f0c0..7e6b94b 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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 + ) + ) } \ No newline at end of file diff --git a/test/unit/interface.js b/test/unit/interface.js index 332c9cc..ddae923 100644 --- a/test/unit/interface.js +++ b/test/unit/interface.js @@ -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') ]) }) diff --git a/test/unit/utils.js b/test/unit/utils.js index bade0ee..b131ccb 100644 --- a/test/unit/utils.js +++ b/test/unit/utils.js @@ -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 + }) + }) \ No newline at end of file