Strumenta / tylasu

Apache License 2.0
20 stars 4 forks source link

assertASTsAreEqual does not seem to be exported #65

Closed ftomassetti closed 5 months ago

ftomassetti commented 5 months ago

We may need to change index.ts to include symbols from testing

alessiostalla commented 5 months ago

This may have been done on purpose, to avoid having to pull the Chai library into all consumers of the library, including code that is unrelated to tests.

alessiostalla commented 5 months ago

Note that you can still import it from @strumenta/tylasu/testing/testing. By playing with Tylasu's package.json, we can omit that repeated testing and shorten the import.

ftomassetti commented 5 months ago

Thank you, but WebStorm does not seem to like that:

Screenshot 2024-05-08 at 09 39 10
alessiostalla commented 5 months ago

Does it work when compiling it? In tests, we import it with import {assertASTsAreEqual} from "../src/testing/testing"; and I believe it should work the same in consumer code, but maybe I'm missing something

ftomassetti commented 5 months ago

I have a similar issue with ASTTransformer.

I cannot import it like this (WebStorm complains):

import { ASTTransformer } from "@strumenta/tylasu/mapping"

If I import it like this WebStorm is happy to let me use it, but then I get an error down the road:

import { ASTTransformer } from "@strumenta/tylasu/src/transformation/transformation"
Screenshot 2024-05-08 at 17 37 29
ftomassetti commented 5 months ago

Does it work when compiling it? In tests, we import it with import {assertASTsAreEqual} from "../src/testing/testing"; and I believe it should work the same in consumer code, but maybe I'm missing something

No, I get this:

TSError: ⨯ Unable to compile TypeScript:
src/tests/parsing.test.ts(16,34): error TS2307: Cannot find module '@strumenta/tylasu/testing/testing' or its corresponding type declarations.
alessiostalla commented 5 months ago

ASTTransformer should be available just from @strumenta/tylasu because it's re-exported in index.ts. The mapping module is provided to make ANTLR an optional dependency: if you just import names from @strumenta/tylasu, you won't load any code that requires ANTLR.

alessiostalla commented 5 months ago

Basically we're missing a testing module like we have mapping.

ftomassetti commented 5 months ago

I have tried updating to Tylasu 1.6.24, but I do not seem to be able to import assertASTsAreEqual anyway:

Screenshot 2024-05-15 at 08 58 35

Should I do something different? Any configuration I should use?

alessiostalla commented 5 months ago

Mea culpa. I added the testing module to package.json, but didn't realize that we had to list all the source files in tsconfig.json. I've changed that to use a wildcard pattern now because it's easy to miss.

ftomassetti commented 5 months ago

Thank you @alessiostalla !

ftomassetti commented 5 months ago

I updated to Tylasu 1.6.25 and tried to import assertASTsAreEqual.

If I do this:

import { assertASTsAreEqual } from "@strumenta/tylasu/dist/types/testing/testing"

WebStorm is happy, but npm run test fails:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/types/testing/testing' is not defined by "exports" in /Users/ftomassetti/repos/PiesseQuadro-DSL/node_modules/@strumenta/tylasu/package.json
    at new NodeError (node:internal/errors:399:5)
    at exportsNotFound (node:internal/modules/esm/resolve:361:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:697:9)
    at resolveExports (node:internal/modules/cjs/loader:538:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:607:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1033:27)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/Users/ftomassetti/repos/PiesseQuadro-DSL/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
    at Function.Module._load (node:internal/modules/cjs/loader:893:27)
    at Module.require (node:internal/modules/cjs/loader:1113:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/Users/ftomassetti/repos/PiesseQuadro-DSL/src/tests/parsing.test.ts:40:1)
    at Module._compile (node:internal/modules/cjs/loader:1226:14)
    at Module.m._compile (/Users/ftomassetti/repos/PiesseQuadro-DSL/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1280:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/ftomassetti/repos/PiesseQuadro-DSL/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1089:32)
    at Function.Module._load (node:internal/modules/cjs/loader:930:12)
    at Module.require (node:internal/modules/cjs/loader:1113:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.exports.requireOrImport (/Users/ftomassetti/repos/PiesseQuadro-DSL/node_modules/mocha/lib/nodejs/esm-utils.js:53:16)
    at async Object.exports.loadFilesAsync (/Users/ftomassetti/repos/PiesseQuadro-DSL/node_modules/mocha/lib/nodejs/esm-utils.js:100:20)
    at async singleRun (/Users/ftomassetti/repos/PiesseQuadro-DSL/node_modules/mocha/lib/cli/run-helpers.js:125:3)
    at async Object.exports.handler (/Users/ftomassetti/repos/PiesseQuadro-DSL/node_modules/mocha/lib/cli/run.js:370:5)

If I import it as:

import { assertASTsAreEqual } from "@strumenta/tylasu/testing/testing"

Both WebStorm and the compiler are unhappy:

src/tests/parsing.test.ts:40:36 - error TS2307: Cannot find module '@strumenta/tylasu/testing/testing' or its corresponding type declarations.

import { assertASTsAreEqual } from "@strumenta/tylasu/testing/testing"
                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Should I do something differently?

alessiostalla commented 5 months ago

I think it should be import { assertASTsAreEqual } from "@strumenta/tylasu/testing" without the extra /testing

ftomassetti commented 5 months ago

Thank you, that works!