Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chaining into rpt2 from a non-.ts file? #111

Closed
coolreader18 opened this issue Sep 1, 2018 · 10 comments
Closed

Chaining into rpt2 from a non-.ts file? #111

coolreader18 opened this issue Sep 1, 2018 · 10 comments
Labels
kind: bug Something isn't working properly scope: integration Related to an integration, not necessarily to core (but could influence core)

Comments

@coolreader18
Copy link

coolreader18 commented Sep 1, 2018

What happens and why it is wrong

I'm compiling nearley to typescript and trying to pass it through to rpt2, but it's not working. The plugin just returns the compiled code, and I tried adding ["*.ne", "**/*.ne"] to the rpt2 options, but just doing that wasn't working, giving an error Error: Could not find file: '/home/coolreader18/Projects/betterfunction/src/lib/grammar/index.ne'.. After doing some debugging in typescript, I figured out that it was because it wasn't including the .ne file in the compilation, and it was erroring in the service.getEmitOutput call in index.ts L195. Is there maybe an alternate call to use to get the output from a file? Before trying to refactor it into chaining, I just called typescript().transform.call(this, code, id + ".ts") from the nearley plugin, and that worked. Maybe error handling for that call, and on an error it just uses the source code provided as a parameter?

Versions

  • typescript: 3.1.0-dev.20180825
  • rollup: 0.65.0
  • rollup-plugin-typescript2: 0.16.1

rollup.config.js

https://gist.github.com/coolreader18/c15cb2e0e8483d6c69769a0b8ade20a3
Previously I was doing:

const code = generate(compilation, path.basename(id));
const ret = ts.transform.call(this, code, `${id}.ts`);
return ret;

in the transform function, but I think chaining is a lot cleaner and less hacky.

tsconfig.json

{
  "compilerOptions": {
    "module": "es2015",
    "strictNullChecks": true,
    "target": "es2017",
    "lib": ["es2017"],
    "moduleResolution": "node"
  }
}

plugin output with verbosity 3

Full error message:

[!] (rpt2 plugin) Error: Could not find file: '/home/coolreader18/Projects/betterfunction/src/lib/grammar/index.ne'.
src/lib/grammar/index.ne
Error: Could not find file: '/home/coolreader18/Projects/betterfunction/src/lib/grammar/index.ne'.
    at getValidSourceFile (/home/coolreader18/Projects/betterfunction/node_modules/typescript/lib/typescript.js:112719:23)
    at Object.getEmitOutput (/home/coolreader18/Projects/betterfunction/node_modules/typescript/lib/typescript.js:113077:30)
    at cache.getCompiled (/home/coolreader18/Projects/betterfunction/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:20101:40)
    at TsCache.getCompiled (/home/coolreader18/Projects/betterfunction/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:19765:33)
    at Object.transform (/home/coolreader18/Projects/betterfunction/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:20099:36)
    at /home/coolreader18/Projects/betterfunction/node_modules/rollup/dist/rollup.js:20831:25
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:182:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:697:11)
    at startup (internal/bootstrap/node.js:201:19)
@ezolenko
Copy link
Owner

@coolreader18 did you try adding "*.ne", "**/*.ne" to include part in tsconfig itself?

@ezolenko
Copy link
Owner

Could you make a small repo with reproduction (or post a link to your full repo if it is opensource)

@coolreader18
Copy link
Author

Adding it to tsconfig.json didn't help, it's giving the same error. The repo is coolreader18/betterfunction.

@chinesedfan
Copy link

I have analyzed this problem recently. Refer to tsne/rollup-plugin-tsc#4 (comment).

@ezolenko
Copy link
Owner

@coolreader18 I looked at what happens again (using your repo at last aug 31st commit) and it seems like rollup never tries to pass *.ne files to rpt2 at all, imports got converted to requires and left that way. Either I reconstructed the problem incorrectly, or nearleyPlugin needs to implement resolveId and maybe load.

@chinesedfan could you make an example repo that reproduces this?

@ezolenko
Copy link
Owner

@chinesedfan ok this should be fixed in master

@chinesedfan
Copy link

@ezolenko In fact, it is the extra filter, not allowNonTsExtensions, that fixes the problem in my repository chinesedfan/rollup-pipe-ts-plugin-issue.

@ezolenko
Copy link
Owner

ezolenko commented Nov 7, 2018

@chinesedfan does current master work for you (if you set correct include in both tsconfig and plugin include option)? Not sure I want to always pass everything that is in tsconfig, it is tempting, but I'm not sure how to treat plugin's own include/exclude option then.

@chinesedfan
Copy link

chinesedfan commented Nov 7, 2018

@ezolenko Thanks. It works.

I noticed that rpt2 is different with rollup-plugin-tsc. It uses filter created by plugin include/exclude, instead of language service filter. And allowNonTsExtensions is also important.

@ezolenko
Copy link
Owner

ezolenko commented Nov 19, 2018

Fixed in 0.18.0

@agilgur5 agilgur5 added kind: bug Something isn't working properly scope: integration Related to an integration, not necessarily to core (but could influence core) labels May 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug Something isn't working properly scope: integration Related to an integration, not necessarily to core (but could influence core)
Projects
None yet
Development

No branches or pull requests

4 participants