0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2025-01-11 16:00:48 -05:00

Merge branch 'master' into angle-constraints

* master:
  added version targets for examples
  added support for example versioning in tests
  add support for > and >= operators in plugin version ranges
This commit is contained in:
liabru 2020-12-30 23:54:42 +00:00
commit 85be083180
46 changed files with 225 additions and 117 deletions

View file

@ -80,6 +80,8 @@ Example.airFriction = function() {
};
};
Example.airFriction.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.airFriction;
}

View file

@ -91,6 +91,8 @@ Example.avalanche = function() {
};
};
Example.avalanche.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.avalanche;
}

View file

@ -99,6 +99,8 @@ Example.ballPool = function() {
};
};
Example.ballPool.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.ballPool;
}

View file

@ -124,6 +124,8 @@ Example.bridge = function() {
};
};
Example.bridge.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.bridge;
}

View file

@ -95,6 +95,8 @@ Example.broadphase = function() {
};
};
Example.broadphase.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.broadphase;
}

View file

@ -89,6 +89,8 @@ Example.car = function() {
};
};
Example.car.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.car;
}

View file

@ -96,6 +96,8 @@ Example.catapult = function() {
};
};
Example.catapult.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.catapult;
}

View file

@ -122,6 +122,8 @@ Example.chains = function() {
};
};
Example.chains.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.chains;
}

View file

@ -81,6 +81,8 @@ Example.circleStack = function() {
};
};
Example.circleStack.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.circleStack;
}

View file

@ -84,6 +84,8 @@ Example.cloth = function() {
};
};
Example.cloth.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.cloth;
}

View file

@ -154,6 +154,8 @@ Example.collisionFiltering = function() {
};
};
Example.collisionFiltering.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.collisionFiltering;
}

View file

@ -107,6 +107,8 @@ Example.compositeManipulation = function() {
};
};
Example.compositeManipulation.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.compositeManipulation;
}

View file

@ -106,6 +106,8 @@ Example.compound = function() {
};
};
Example.compound.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.compound;
}

View file

@ -89,6 +89,8 @@ Example.compoundStack = function() {
};
};
Example.compoundStack.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.compoundStack;
}

View file

@ -95,6 +95,8 @@ Example.concave = function() {
};
};
Example.concave.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.concave;
}

View file

@ -179,6 +179,8 @@ Example.constraints = function() {
};
};
Example.constraints.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.constraints;
}

View file

@ -148,6 +148,8 @@ Example.doublePendulum = function() {
};
};
Example.doublePendulum.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.doublePendulum;
}

View file

@ -178,6 +178,8 @@ Example.events = function() {
};
};
Example.events.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.events;
}

View file

@ -90,6 +90,8 @@ Example.friction = function() {
};
};
Example.friction.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.friction;
}

View file

@ -96,6 +96,8 @@ Example.gravity = function() {
};
};
Example.gravity.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.gravity;
}

View file

@ -130,6 +130,8 @@ Example.gyro = function() {
};
};
Example.gyro.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.gyro;
}

View file

@ -140,6 +140,8 @@ Example.manipulation = function() {
};
};
Example.manipulation.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.manipulation;
}

View file

@ -105,6 +105,8 @@ Example.mixed = function() {
};
};
Example.mixed.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.mixed;
}

View file

@ -76,6 +76,8 @@ Example.newtonsCradle = function() {
};
};
Example.newtonsCradle.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.newtonsCradle;
}

View file

@ -81,6 +81,8 @@ Example.pyramid = function() {
};
};
Example.pyramid.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.pyramid;
}

View file

@ -498,6 +498,8 @@ Example.ragdoll.ragdoll = function(x, y, scale, options) {
return person;
};
Example.ragdoll.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.ragdoll;
}

View file

@ -135,6 +135,8 @@ Example.raycasting = function() {
};
};
Example.raycasting.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.raycasting;
}

View file

@ -85,6 +85,8 @@ Example.restitution = function() {
};
};
Example.restitution.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.restitution;
}

View file

@ -109,6 +109,8 @@ Example.rounded = function() {
};
};
Example.rounded.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.rounded;
}

View file

@ -130,6 +130,8 @@ Example.sensors = function() {
};
};
Example.sensors.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.sensors;
}

View file

@ -104,6 +104,8 @@ Example.sleeping = function() {
};
};
Example.sleeping.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.sleeping;
}

View file

@ -100,6 +100,8 @@ Example.slingshot = function() {
};
};
Example.slingshot.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.slingshot;
}

View file

@ -85,6 +85,8 @@ Example.softBody = function() {
};
};
Example.softBody.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.softBody;
}

View file

@ -112,6 +112,8 @@ Example.sprites = function() {
};
};
Example.sprites.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.sprites;
}

View file

@ -81,6 +81,8 @@ Example.stack = function() {
};
};
Example.stack.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.stack;
}

View file

@ -106,6 +106,8 @@ Example.staticFriction = function() {
};
};
Example.staticFriction.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.staticFriction;
}

View file

@ -79,6 +79,8 @@ Example.stress = function() {
};
};
Example.stress.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.stress;
}

View file

@ -79,6 +79,8 @@ Example.stress2 = function() {
};
};
Example.stress2.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.stress2;
}

View file

@ -124,6 +124,8 @@ Example.svg = function() {
};
};
Example.svg.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.svg;
}

View file

@ -105,6 +105,8 @@ Example.terrain = function() {
};
};
Example.terrain.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.terrain;
}

View file

@ -151,6 +151,8 @@ Example.timescale = function() {
};
};
Example.timescale.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.timescale;
}

View file

@ -182,6 +182,8 @@ Example.views = function() {
};
};
Example.views.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.views;
}

View file

@ -93,6 +93,8 @@ Example.wreckingBall = function() {
};
};
Example.wreckingBall.for = '>=0.14.2';
if (typeof module !== 'undefined') {
module.exports = Example[Object.keys(Example)[0]];
}
module.exports = Example.wreckingBall;
}

View file

@ -266,6 +266,8 @@ var Common = require('./Common');
* Only the following range types are supported:
* - Tilde ranges e.g. `~1.2.3`
* - Caret ranges e.g. `^1.2.3`
* - Greater than ranges e.g. `>1.2.3`
* - Greater than or equal ranges e.g. `>=1.2.3`
* - Exact version e.g. `1.2.3`
* - Any version `*`
* @method versionParse
@ -273,29 +275,28 @@ var Common = require('./Common');
* @return {object} The version range parsed into its components.
*/
Plugin.versionParse = function(range) {
var pattern = /^\*|[\^~]?\d+\.\d+\.\d+(-[0-9A-Za-z-]+)?$/;
var pattern = /^(\*)|(\^|~|>=|>)?\s*((\d+)\.(\d+)\.(\d+))(-[0-9A-Za-z-]+)?$/;
if (!pattern.test(range)) {
Common.warn('Plugin.versionParse:', range, 'is not a valid version or range.');
}
var identifiers = range.split('-');
range = identifiers[0];
var isRange = isNaN(Number(range[0])),
version = isRange ? range.substr(1) : range,
parts = Common.map(version.split('.'), function(part) {
return Number(part);
});
var parts = pattern.exec(range);
var major = Number(parts[4]);
var minor = Number(parts[5]);
var patch = Number(parts[6]);
return {
isRange: isRange,
version: version,
isRange: Boolean(parts[1] || parts[2]),
version: parts[3],
range: range,
operator: isRange ? range[0] : '',
parts: parts,
prerelease: identifiers[1],
number: parts[0] * 1e8 + parts[1] * 1e4 + parts[2]
operator: parts[1] || parts[2] || '',
major: major,
minor: minor,
patch: patch,
parts: [major, minor, patch],
prerelease: parts[7],
number: major * 1e8 + minor * 1e4 + patch
};
};
@ -311,30 +312,36 @@ var Common = require('./Common');
Plugin.versionSatisfies = function(version, range) {
range = range || '*';
var rangeParsed = Plugin.versionParse(range),
rangeParts = rangeParsed.parts,
versionParsed = Plugin.versionParse(version),
versionParts = versionParsed.parts;
var r = Plugin.versionParse(range),
v = Plugin.versionParse(version);
if (rangeParsed.isRange) {
if (rangeParsed.operator === '*' || version === '*') {
if (r.isRange) {
if (r.operator === '*' || version === '*') {
return true;
}
if (rangeParsed.operator === '~') {
return versionParts[0] === rangeParts[0] && versionParts[1] === rangeParts[1] && versionParts[2] >= rangeParts[2];
if (r.operator === '>') {
return v.number > r.number;
}
if (rangeParsed.operator === '^') {
if (rangeParts[0] > 0) {
return versionParts[0] === rangeParts[0] && versionParsed.number >= rangeParsed.number;
if (r.operator === '>=') {
return v.number >= r.number;
}
if (r.operator === '~') {
return v.major === r.major && v.minor === r.minor && v.patch >= r.patch;
}
if (r.operator === '^') {
if (r.major > 0) {
return v.major === r.major && v.number >= r.number;
}
if (rangeParts[1] > 0) {
return versionParts[1] === rangeParts[1] && versionParts[2] >= rangeParts[2];
if (r.minor > 0) {
return v.minor === r.minor && v.patch >= r.patch;
}
return versionParts[2] === rangeParts[2];
return v.patch === r.patch;
}
}

View file

@ -5,9 +5,16 @@ jest.setTimeout(120 * 1000);
const puppeteer = require('puppeteer-core');
const Example = require('../examples/index');
const MatterBuild = require('../build/matter');
const { versionSatisfies } = require('../src/core/Plugin');
const fs = require('fs');
const examples = Object.keys(Example);
const examples = Object.keys(Example).filter(key => {
const buildVersion = MatterBuild.version;
const exampleFor = Example[key].for;
return versionSatisfies(buildVersion, exampleFor);
});
const browserPath = '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome';
const demoPagePath = 'http://localhost:8000/';
const totalUpdates = 5;

View file

@ -7,13 +7,21 @@ const { comparisonReport, toMatchExtrinsics, toMatchIntrinsics } = require('./Te
const Example = require('../examples/index');
const MatterBuild = require('../build/matter');
const { versionSatisfies } = require('../src/core/Plugin');
const Worker = require('jest-worker').default;
const testComparison = process.env.COMPARE === 'true';
const saveComparison = process.env.SAVE === 'true';
const excludeExamples = ['svg', 'terrain'];
const excludeJitter = ['stack', 'circleStack', 'restitution', 'staticFriction', 'friction', 'newtonsCradle', 'catapult'];
const examples = Object.keys(Example).filter(key => !excludeExamples.includes(key));
const examples = Object.keys(Example).filter(key => {
const excluded = excludeExamples.includes(key);
const buildVersion = MatterBuild.version;
const exampleFor = Example[key].for;
const supported = versionSatisfies(buildVersion, exampleFor);
return !excluded && supported;
});
const runExamples = async useDev => {
const worker = new Worker(require.resolve('./ExampleWorker'), {