From 25e28786c18d75d76315801dff20a4afd27c1e0f Mon Sep 17 00:00:00 2001 From: Yegor Bugayenko Date: Wed, 14 Feb 2024 17:53:24 +0300 Subject: [PATCH] #235: demand --- package-lock.json | 31 +++++++++++++++++++++++++++++ package.json | 1 + src/commands/phi.js | 6 ++++-- src/commands/unphi.js | 6 ++++-- src/demand.js | 35 +++++++++++++++++++++++++++++++++ test/commands/test_assemble.js | 2 +- test/commands/test_clean.js | 2 +- test/commands/test_compile.js | 3 ++- test/commands/test_dataize.js | 1 + test/commands/test_link.js | 1 + test/commands/test_parse.js | 2 +- test/commands/test_phi.js | 2 +- test/commands/test_register.js | 2 +- test/commands/test_sodg.js | 2 +- test/commands/test_test.js | 1 + test/commands/test_transpile.js | 2 +- test/commands/test_unphi.js | 2 +- test/commands/test_verify.js | 2 +- test/helpers.js | 2 +- 19 files changed, 90 insertions(+), 15 deletions(-) create mode 100644 src/demand.js diff --git a/package-lock.json b/package-lock.json index f3d3480..b766279 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,6 +19,7 @@ "fast-xml-parser": "4.3.4", "node": "21.6.1", "relative": "3.0.2", + "semver": "7.6.0", "sync-request": "6.1.0", "xmlhttprequest": "1.8.0" }, @@ -2210,6 +2211,17 @@ "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/make-iterator": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/make-iterator/-/make-iterator-1.0.1.tgz", @@ -2935,6 +2947,20 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "dev": true }, + "node_modules/semver": { + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", + "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", + "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", @@ -3339,6 +3365,11 @@ "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": "16.2.0", "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", diff --git a/package.json b/package.json index ecf510f..e55cf49 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "fast-xml-parser": "4.3.4", "node": "21.6.1", "relative": "3.0.2", + "semver": "7.6.0", "sync-request": "6.1.0", "xmlhttprequest": "1.8.0" }, diff --git a/src/commands/phi.js b/src/commands/phi.js index f5d8df6..0f755a3 100644 --- a/src/commands/phi.js +++ b/src/commands/phi.js @@ -24,6 +24,7 @@ const rel = require('relative'); const path = require('path'); +const {gte} = require('../demand') const {mvnw, flags} = require('../mvnw'); /** @@ -32,6 +33,7 @@ const {mvnw, flags} = require('../mvnw'); * @return {Promise} of assemble task */ module.exports = function(opts) { + gte('EO parser', opts.parser, '0.35.2'); const target = path.resolve(opts.target); const input = path.resolve(opts.target, '2-optimize'); console.debug('Reading .XMIR files from %s', rel(input)); @@ -42,8 +44,8 @@ module.exports = function(opts) { .concat(flags(opts)) .concat( [ - `-DphiInputDir=${input}`, - `-DphiOutputDir=${output}`, + `-Deo.phiInputDir=${input}`, + `-Deo.phiOutputDir=${output}`, ] ), opts.target, opts.batch diff --git a/src/commands/unphi.js b/src/commands/unphi.js index 09c062d..0bde0ba 100644 --- a/src/commands/unphi.js +++ b/src/commands/unphi.js @@ -25,6 +25,7 @@ const rel = require('relative'); const path = require('path'); const {mvnw, flags} = require('../mvnw'); +const {gte} = require('../demand') /** * Command to convert .PHI files into .XMIR files. @@ -32,6 +33,7 @@ const {mvnw, flags} = require('../mvnw'); * @return {Promise} of assemble task */ module.exports = function(opts) { + gte('EO parser', opts.parser, '0.35.2'); const input = path.resolve(opts.target, 'phi'); console.debug('Reading .PHI files from %s', rel(input)); const output = path.resolve(opts.target, 'unphi'); @@ -41,8 +43,8 @@ module.exports = function(opts) { .concat(flags(opts)) .concat( [ - `-DunphiInputDir=${input}`, - `-DunphiOutputDir=${output}`, + `-Deo.unphiInputDir=${input}`, + `-Deo.unphiOutputDir=${output}`, ] ), opts.target, opts.batch diff --git a/src/demand.js b/src/demand.js new file mode 100644 index 0000000..7fe4055 --- /dev/null +++ b/src/demand.js @@ -0,0 +1,35 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2022-2023 Objectionary.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +const semver = require('semver'); + +/** + * Only if provided version is the required one or younger. + */ +module.exports.gte = function(subject, current, min) { + if (semver.lt(current, min)) { + console.error('%s is required to have version %s or higher, while you use %s', subject, min, current); + process.exit(1); + } +} diff --git a/test/commands/test_assemble.js b/test/commands/test_assemble.js index 0b379ee..5e38df4 100644 --- a/test/commands/test_assemble.js +++ b/test/commands/test_assemble.js @@ -32,7 +32,7 @@ describe('assemble', function() { home = path.resolve('temp/test-assemble/simple'); fs.rmSync(home, {recursive: true, force: true}); fs.mkdirSync(path.resolve(home, 'src'), {recursive: true}); - fs.writeFileSync(path.resolve(home, 'src/assemble.eo'), '[] > assemble\n'); + fs.writeFileSync(path.resolve(home, 'src/assemble.eo'), '# sample\n[] > assemble\n'); const stdout = runSync([ 'assemble', '--verbose', diff --git a/test/commands/test_clean.js b/test/commands/test_clean.js index 088dcb7..59a8d59 100644 --- a/test/commands/test_clean.js +++ b/test/commands/test_clean.js @@ -36,7 +36,7 @@ describe('clean', function() { fs.rmSync(eo, {recursive: true, force: true}); fs.mkdirSync(path.resolve(home, 'src'), {recursive: true}); fs.mkdirSync(eo, {recursive: true}); - fs.writeFileSync(path.resolve(home, 'src/clean.eo'), '[] > clean\n'); + fs.writeFileSync(path.resolve(home, 'src/clean.eo'), '# sample\n[] > clean\n'); const stdout = runSync([ 'clean', '-s', path.resolve(home, 'src'), '-t', path.resolve(home, 'target'), '--global', ]); diff --git a/test/commands/test_compile.js b/test/commands/test_compile.js index 46a1eb5..05c5a5a 100644 --- a/test/commands/test_compile.js +++ b/test/commands/test_compile.js @@ -65,9 +65,9 @@ describe('compile', function() { '+package foo.bar', '+junit', '', + '# This is a sample object', '[] > simple-test-compile', ' TRUE > @', - '', ].join('\n') ); const stdout = runSync([ @@ -116,6 +116,7 @@ function simple(name) { '+package foo.bar', '+alias org.eolang.io.stdout', '', + '# This is a simple object', `[args] > ${name}`, ' stdout "Hello, world!" > @', ].join('\n'); diff --git a/test/commands/test_dataize.js b/test/commands/test_dataize.js index 702995e..ec6a857 100644 --- a/test/commands/test_dataize.js +++ b/test/commands/test_dataize.js @@ -44,6 +44,7 @@ versions.forEach(function(hash, version) { '+package foo.bar', '+alias org.eolang.io.stdout', '', + '# sample', '[args] > simple', ' stdout "Hello, world!\\n" > @', ].join('\n') diff --git a/test/commands/test_link.js b/test/commands/test_link.js index e265aa4..0ca9d6d 100644 --- a/test/commands/test_link.js +++ b/test/commands/test_link.js @@ -38,6 +38,7 @@ describe('link', function() { '+package foo.bar', '+alias org.eolang.io.stdout', '', + '# sample object' '[args] > link', ' stdout "Hello, world!" > @', ].join('\n') diff --git a/test/commands/test_parse.js b/test/commands/test_parse.js index 4b09c9a..6f79121 100644 --- a/test/commands/test_parse.js +++ b/test/commands/test_parse.js @@ -32,7 +32,7 @@ describe('parse', function() { home = path.resolve('temp/test-parse/simple'); fs.rmSync(home, {recursive: true, force: true}); fs.mkdirSync(path.resolve(home, 'src'), {recursive: true}); - fs.writeFileSync(path.resolve(home, 'src/simple.eo'), '[] > simple\n'); + fs.writeFileSync(path.resolve(home, 'src/simple.eo'), '# sample\n[] > simple\n'); const stdout = runSync([ 'parse', '--verbose', diff --git a/test/commands/test_phi.js b/test/commands/test_phi.js index a134cdc..910885a 100644 --- a/test/commands/test_phi.js +++ b/test/commands/test_phi.js @@ -31,7 +31,7 @@ describe('phi', function() { home = path.resolve('temp/test-phi/simple'); fs.rmSync(home, {recursive: true, force: true}); fs.mkdirSync(path.resolve(home, 'src'), {recursive: true}); - fs.writeFileSync(path.resolve(home, 'src/phi.eo'), '[] > phi\n'); + fs.writeFileSync(path.resolve(home, 'src/phi.eo'), '# sample\n[] > phi\n'); const stdout = runSync([ 'phi', '--verbose', diff --git a/test/commands/test_register.js b/test/commands/test_register.js index fca5b92..6b022d5 100644 --- a/test/commands/test_register.js +++ b/test/commands/test_register.js @@ -32,7 +32,7 @@ describe('register', function() { home = path.resolve('temp/test-register/simple'); fs.rmSync(home, {recursive: true, force: true}); fs.mkdirSync(path.resolve(home, 'src'), {recursive: true}); - fs.writeFileSync(path.resolve(home, 'src/simple.eo'), '[] > simple\n'); + fs.writeFileSync(path.resolve(home, 'src/simple.eo'), '# sample\n[] > simple\n'); const stdout = runSync([ 'register', '--verbose', diff --git a/test/commands/test_sodg.js b/test/commands/test_sodg.js index a53ebab..b9c8adc 100644 --- a/test/commands/test_sodg.js +++ b/test/commands/test_sodg.js @@ -32,7 +32,7 @@ describe('sodg', function() { home = path.resolve('temp/test-sodg/simple'); fs.rmSync(home, {recursive: true, force: true}); fs.mkdirSync(path.resolve(home, 'src'), {recursive: true}); - fs.writeFileSync(path.resolve(home, 'src/simple.eo'), '[] > simple\n'); + fs.writeFileSync(path.resolve(home, 'src/simple.eo'), '# sample\n[] > simple\n'); const stdout = runSync([ 'sodg', '--verbose', diff --git a/test/commands/test_test.js b/test/commands/test_test.js index f73ab54..3c2e36c 100644 --- a/test/commands/test_test.js +++ b/test/commands/test_test.js @@ -36,6 +36,7 @@ describe('test', function() { [ '+junit', '', + '# sample', '[] > simple-comparison-works', ' gt. > @', ' 10', diff --git a/test/commands/test_transpile.js b/test/commands/test_transpile.js index 41d6eb6..c6e1e54 100644 --- a/test/commands/test_transpile.js +++ b/test/commands/test_transpile.js @@ -31,7 +31,7 @@ describe('transpile', function() { home = path.resolve('temp/test-transpile/transpile'); fs.rmSync(home, {recursive: true, force: true}); fs.mkdirSync(path.resolve(home, 'src'), {recursive: true}); - fs.writeFileSync(path.resolve(home, 'src/transpile.eo'), '[] > transpile\n'); + fs.writeFileSync(path.resolve(home, 'src/transpile.eo'), '# sample\n[] > transpile\n'); const stdout = runSync([ 'transpile', '--verbose', diff --git a/test/commands/test_unphi.js b/test/commands/test_unphi.js index d0b25d4..bcc03f2 100644 --- a/test/commands/test_unphi.js +++ b/test/commands/test_unphi.js @@ -31,7 +31,7 @@ describe('unphi', function() { home = path.resolve('temp/test-unphi/simple'); fs.rmSync(home, {recursive: true, force: true}); fs.mkdirSync(path.resolve(home, 'target/phi'), {recursive: true}); - fs.writeFileSync(path.resolve(home, 'target/phi/app.phi'), '{ app ↦ ⟦ ⟧ }'); + fs.writeFileSync(path.resolve(home, 'target/phi/app.phi'), '{ ⟦ app ↦ ⟦ ⟧ ⟧ }'); const stdout = runSync([ 'unphi', '--verbose', diff --git a/test/commands/test_verify.js b/test/commands/test_verify.js index bcf8f34..cc3f3aa 100644 --- a/test/commands/test_verify.js +++ b/test/commands/test_verify.js @@ -32,7 +32,7 @@ describe('verify', function() { home = path.resolve('temp/test-verify/simple'); fs.rmSync(home, {recursive: true, force: true}); fs.mkdirSync(path.resolve(home, 'src'), {recursive: true}); - fs.writeFileSync(path.resolve(home, 'src/simple.eo'), '[] > simple\n'); + fs.writeFileSync(path.resolve(home, 'src/simple.eo'), '# sample\n[] > simple\n'); const stdout = runSync([ 'verify', '--verbose', diff --git a/test/helpers.js b/test/helpers.js index 07d9b32..bab1520 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -25,7 +25,7 @@ // When you upgrade them, don't forget to place old values to the // "test_dataize.js" table of versions, in order to make sure we // do test dataization with all possible old versions. -module.exports.parserVersion = '0.35.1'; +module.exports.parserVersion = '0.35.2'; module.exports.homeHash = '130afdd1456a0cbafd52aee8d7bc612e1faac547'; /**