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

Typescript support #427

Closed
wants to merge 3 commits into from
Closed

Conversation

benallfree
Copy link
Collaborator

Closes:

#297
#397
#426

@urizennnn
Copy link

@benallfree how do i do that?

@benallfree
Copy link
Collaborator Author

Yeah that's a little difficult because you can't npm install a package from a monorepo. I'm looking into it more.

@benallfree
Copy link
Collaborator Author

plop-4.0.1.tgz

@urizennnn you can try this, it's a build from this PR branch

npm i plop-4.0.1.tgz

@urizennnn
Copy link

plop-4.0.1.tgz

@urizennnn you can try this, it's a build from this PR branch

npm i plop-4.0.1.tgz

can it be installed globally?

@benallfree
Copy link
Collaborator Author

Yes you can try that

@urizennnn
Copy link

Yes you can try that

image

@crutchcorn
Copy link
Member

The big problem with this approach and the reason I never merged #397, despite having the ability to is that we need a compiler flag to opt out of the TSX loader so people can use their own to support path flags and other tsconfig options

That + docs and tests that we'd need to merge this PR

@benallfree
Copy link
Collaborator Author

benallfree commented Apr 6, 2024

Yeah I experimented with integrating more with rechoir but couldn't get the ts test to pass even though yarn plop ran successfully.

Can you say more about opting out of the tsx loader?

For now #423 is working for me:

  "scripts": {
    "plop": "cross-env NODE_OPTIONS='--import tsx' plop --plopfile=plopfile.ts",
  }

If you'd like me to work more on this and get tests passing, I'm happy to keep going. This seems like something Liftoff should have working OOTB, but maybe I don't understand. I thought Liftoff was supposed to install other handlers on demand.

This works:

const Liftoff = require('liftoff')

const Hacker = new Liftoff({
  name: 'hacker',
  processTitle: 'hacker',
  moduleName: 'hacker',
  configName: 'hackerfile',
  extensions: {
    '.ts': 'tsx/dist/loader.cjs',
  },
  v8flags: ['--harmony'], // or v8flags: require('v8flags')
})

Hacker.prepare({}, function (env) {
  Hacker.execute(env, async (env) => {
    await import(env.configPath)
  })
})

@crutchcorn
Copy link
Member

Right, I ran into many of the same problems with Liftoff, myself. I think there was some reason between plop CLI and node-plop that wasn't synced leading to the mismatched behavior.

The problems with opting out come from "How do I use one TSconfig for X but another for Plop and both have paths that inherit from a base config" kinda deal.

Tbh I REALLY like your NODE_OPTIONS userland fix to this problem, rather than trying to inhouse all of the edgecases. What if we just make a PR to add the explainer on how to do that on our website instead of trying to make it a feature?

@benallfree
Copy link
Collaborator Author

Suits me perfectly, and it also is kind of a forward-looking approach since that --import and esm support seems to be stabilizing.

Shall I send a docs PR?

@crutchcorn
Copy link
Member

Let's do it! Thanks for your understanding and help! ✨

@benallfree
Copy link
Collaborator Author

Closing in favor of #428

@benallfree benallfree closed this Apr 7, 2024
@prisis prisis mentioned this pull request Apr 12, 2024
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.

3 participants