Skip to content

Add normalize command.#879

Merged
yegor256 merged 30 commits intoobjectionary:masterfrom
aidarkdev:590
Mar 22, 2026
Merged

Add normalize command.#879
yegor256 merged 30 commits intoobjectionary:masterfrom
aidarkdev:590

Conversation

@aidarkdev
Copy link
Copy Markdown
Contributor

@aidarkdev aidarkdev commented Mar 9, 2026

Closes #590

Add normalize command. Works via calling phino util.

- refactor files ops funcs
-  log every step timestamps
- add check params existing
@aidarkdev aidarkdev changed the title 590 Add normalize command. Mar 9, 2026
@aidarkdev aidarkdev marked this pull request as draft March 9, 2026 18:15
@aidarkdev aidarkdev marked this pull request as ready for review March 12, 2026 16:24
@aidarkdev
Copy link
Copy Markdown
Contributor Author

@yegor256 @maxonfjvipon take a look plz.
Phino win binary is available now and all checks are ok.

src/files.js Outdated
}
return result;
}
module.exports.findFiles = findFiles;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aidarkdev let's use single module.exports at the end of the file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

const target = path.resolve(opts.target);
return elapsed(async (tracked) => {
copyDir(sources, path.join(target, 'before-normalize'), '.eo');
const xmirDir = path.join(target, '1-parse');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aidarkdev let's try to use single named variable as much as possible, parsed instead of xmirDir, xmirs instead of xmirFile, rel instead of relPath, xmir instead of xmirFile and so on. Check this: https://www.yegor256.com/2015/01/12/compound-name-is-code-smell.html

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

console.debug('Found %d XMIR file(s) to normalize', xmirFiles.length);
for (const xmirFile of xmirFiles) {
const relPath = path.relative(xmirDir, xmirFile);
const base = relPath.replace(/\.xmir$/, '');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aidarkdev I think there's a special function in path module for getting relative path

Copy link
Copy Markdown
Contributor Author

@aidarkdev aidarkdev Mar 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxonfjvipon you are rigth, there is alredy used relative funct, replace was just redundant code(that cutted file extension), it is deleted for now

console.debug('Normalizing %s', relPath);
let ts = Date.now();
const phi = execSync(
'phino rewrite --input=xmir --output=phi',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aidarkdev there's no need to call phino a several times. You can just do:

phino rewrite --input=xmir --output=xmir --normalize your-file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxonfjvipon on first version were debug mode where every phino call result can be saved. Now we can use one singel call, yes. Thanks! fixed

fs.rmSync(home, {recursive: true, force: true});
fs.mkdirSync(source, {recursive: true});
fs.mkdirSync(target, {recursive: true});
const content = '# sample\n[] > simple\n';
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aidarkdev I see a lot of code duplication across the tests:

const home = path.resolve('temp/test-normalize/simple');
const source = path.resolve(home, 'src');
const target = path.resolve(home, 'target');
fs.rmSync(home, {recursive: true, force: true});
fs.mkdirSync(source, {recursive: true});
fs.mkdirSync(target, {recursive: true});
const content = '# sample\n[] > simple\n';

I think it can be moved to some preparation function

The same story with:

runSync([
  'normalize',
  '--verbose',
  `--parser=${parserVersion}`,
  `--home-tag=${homeTag}`,
  '-s', source,
  '-t', target,
]);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

- back tests skipped before for debug
- fix link to latest phino binary
@aidarkdev
Copy link
Copy Markdown
Contributor Author

@maxonfjvipon review comments fixed, all debug logs and other workaround cleaned, checks-tests are ok

Copy link
Copy Markdown
Member

@maxonfjvipon maxonfjvipon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aidarkdev looks good, just one minor fix and we're good to merge

src/files.js Outdated
if (!fs.existsSync(src)) {return;}
fs.mkdirSync(dst, {recursive: true});
for (const entry of fs.readdirSync(src, {withFileTypes: true})) {
const srcPath = path.join(src, entry.name);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aidarkdev let's use single word name also here source instead of srcPath and dest or destination instead of dstPath

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxonfjvipon thanks!
Fixed. All checks-tests are ok.

@maxonfjvipon
Copy link
Copy Markdown
Member

@aidarkdev the only man who can merge the PR is @yegor256. So do be shy, ping him

@aidarkdev
Copy link
Copy Markdown
Contributor Author

@yegor256 need to merge here

@aidarkdev
Copy link
Copy Markdown
Contributor Author

@yegor256 ping, review ok, need to push here

@aidarkdev
Copy link
Copy Markdown
Contributor Author

@yegor256 review ok, waiting merge

@yegor256
Copy link
Copy Markdown
Member

@rultor merge

@rultor
Copy link
Copy Markdown
Contributor

rultor commented Mar 21, 2026

@rultor merge

@yegor256 OK, I'll try to merge now. You can check the progress of the merge here.

@rultor
Copy link
Copy Markdown
Contributor

rultor commented Mar 21, 2026

@rultor merge

@aidarkdev @yegor256 Oops, I failed. You can see the full log here (spent 23min).

  \u001b[32m  ✓\u001b[0m\u001b[90m fails due version mismatch if different --pin provided\u001b[0m\u001b[31m (952ms)\u001b[0m

\u001b[0m  eoc\u001b[0m
  \u001b[32m  ✓\u001b[0m\u001b[90m cleans successfully when versions match with --pin\u001b[0m\u001b[31m (952ms)\u001b[0m

\u001b[0m  eoc\u001b[0m
  \u001b[32m  ✓\u001b[0m\u001b[90m cleans successfully when if --pin not provided\u001b[0m\u001b[31m (971ms)\u001b[0m

\u001b[0m  mvnw\u001b[0m
Running mvnw with arguments: --version --quiet
+ /home/r/repo/mvnw/mvnw --version --quiet --batch-mode --color=never --fail-fast --strict-checksums
\u001b[0m\u001b[0m3.9.14
\u001b[0m\u001b[0m  \u001b[32m  ✓\u001b[0m\u001b[90m prints Maven own version\u001b[0m\u001b[31m (312ms)\u001b[0m
Sources in sources
Target in target
Running mvnw with arguments: --version --quiet -Deo.version=0.28.11 -Deo.tag=homeTag --quiet -Deo.sourcesDir=/home/r/repo/sources -Deo.targetDir=/home/r/repo/target -Deo.outputDir=/home/r/repo/target/classes -Deo.generatedDir=/home/r/repo/target/generated-sources -Deo.placed=/home/r/repo/target/eo-placed.csv -Deo.placedFormat=csv -Deo.skipLinting=false
+ /home/r/repo/mvnw/mvnw --version --quiet -Deo.version=0.28.11 -Deo.tag=homeTag --quiet -Deo.sourcesDir=/home/r/repo/sources -Deo.targetDir=/home/r/repo/target -Deo.outputDir=/home/r/repo/target/classes -Deo.generatedDir=/home/r/repo/target/generated-sources -Deo.placed=/home/r/repo/target/eo-placed.csv -Deo.placedFormat=csv -Deo.skipLinting=false --batch-mode --color=never --fail-fast --strict-checksums
\u001b[0m\u001b[0m3.9.14
\u001b[0m\u001b[0m  \u001b[32m  ✓\u001b[0m\u001b[90m sets right flags from options\u001b[0m\u001b[31m (458ms)\u001b[0m
  \u001b[32m  ✓\u001b[0m\u001b[90m should handle ENOENT race condition in count function\u001b[0m

\u001b[0m  parser-version\u001b[0m
\u001b[0m    get()\u001b[0m
The latest version of org/eolang/eo-maven-plugin at https://repo.maven.apache.org/maven2/org/eolang/eo-maven-plugin/maven-metadata.xml is 0.59.5
    \u001b[32m  ✓\u001b[0m\u001b[90m fetches the latest version from Maven Central\u001b[0m\u001b[31m (89ms)\u001b[0m
    \u001b[32m  ✓\u001b[0m\u001b[90m caches the version after first fetch\u001b[0m
\u001b[0m    exists()\u001b[0m
    \u001b[32m  ✓\u001b[0m\u001b[90m returns true for a known valid version\u001b[0m\u001b[33m (73ms)\u001b[0m
    \u001b[32m  ✓\u001b[0m\u001b[90m returns true for current default version\u001b[0m\u001b[31m (79ms)\u001b[0m
    \u001b[32m  ✓\u001b[0m\u001b[90m returns false for an obviously invalid version\u001b[0m\u001b[31m (85ms)\u001b[0m
    \u001b[32m  ✓\u001b[0m\u001b[90m returns false for undefined version\u001b[0m
    \u001b[32m  ✓\u001b[0m\u001b[90m returns false for null version\u001b[0m
    \u001b[32m  ✓\u001b[0m\u001b[90m returns false for empty string version\u001b[0m
    \u001b[32m  ✓\u001b[0m\u001b[90m returns false for "undefined" string\u001b[0m
    \u001b[32m  ✓\u001b[0m\u001b[90m constructs correct Maven Central URL\u001b[0m\u001b[31m (81ms)\u001b[0m
    \u001b[32m  ✓\u001b[0m\u001b[90m handles network errors gracefully\u001b[0m\u001b[33m (71ms)\u001b[0m

\u001b[0m  tinted-console\u001b[0m
\u001b[33mok\u001b[39m
  \u001b[32m  ✓\u001b[0m\u001b[90m allows console.warn without errors\u001b[0m


\u001b[92m \u001b[0m\u001b[32m 71 passing\u001b[0m\u001b[90m (6m)\u001b[0m
\u001b[36m \u001b[0m\u001b[36m 5 pending\u001b[0m
\u001b[31m  1 failing\u001b[0m

\u001b[0m  1) normalize
       "before all" hook for "normalizes EO files and saves originals in before-normalize/":
\u001b[0m\u001b[31m     Error: phino is required to run normalize tests, see https://github.com/objectionary/phino\u001b[0m\u001b[90m
      at Context.<anonymous> (test/commands/test_normalize.js:39:13)
      at GetAddrInfoReqWrap.callback (test/helpers.js:73:5)
      at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:109:8)
\u001b[0m


Warning:  Use --force to continue.

Aborted due to warnings.
\u001b[1G\u001b[0K⠙\u001b[1G\u001b[0Kcontainer f43a94332625368f0fb83ba571ca110b2d150f3f9ac4c456d6cce7693bf28eba is dead
Sat Mar 21 05:02:16 UTC 2026

@maxonfjvipon
Copy link
Copy Markdown
Member

@yegor256 it seems phino has to be installed in Rultor

@aidarkdev
Copy link
Copy Markdown
Contributor Author

@maxonfjvipon @yegor256 opened issue for that
yegor256/rultor#2285

@aidarkdev
Copy link
Copy Markdown
Contributor Author

@maxonfjvipon @yegor256 opened issue for that yegor256/rultor#2285

@yegor256 @maxonfjvipon found out how it works, closed the issue. Added phino install to .rultor.yml file.
Checks/tests still ok, @yegor256 need to trigger merge one more time plz.

@yegor256 yegor256 merged commit 061131c into objectionary:master Mar 22, 2026
17 checks passed
@yegor256
Copy link
Copy Markdown
Member

@aidarkdev thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Absence of normalize command for XMIR-to-.phi file conversion

4 participants