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

enableTypeScript function always skipProject set true #345

Open
imjuni opened this issue Apr 2, 2020 · 1 comment
Open

enableTypeScript function always skipProject set true #345

imjuni opened this issue Apr 2, 2020 · 1 comment

Comments

@imjuni
Copy link
Contributor

imjuni commented Apr 2, 2020

Hi,

Thank you for best task runner development,

I want to use just.config .ts not just.config .js

But just-script not pass TS_NODE_PROJECT environment variable to internal ts-node processor.

This cause error from nullish operator in just.config.ts

obj[key] = process.env[key] ?? envObj[key];
                                     ^
SyntaxError: Unexpected token '?'

How can I pass TS_NODE_PROJECT to just-scripts?

@imjuni imjuni changed the title TS_NODE_PROJECT environment not pass for ts-node Unexpected token '?' from just.config.ts Apr 2, 2020
@imjuni imjuni changed the title Unexpected token '?' from just.config.ts Unexpected token '?' from just.config.ts Apr 2, 2020
@imjuni imjuni changed the title Unexpected token '?' from just.config.ts enableTypeScript function always skipProject set true Apr 2, 2020
@imjuni
Copy link
Contributor Author

imjuni commented Apr 2, 2020

I use just.config.ts file below,

task('hello', async () => {
  const envObj: { [key: string]: string } = {
    DEBUG: 'tjscli:*',
    TS_NODE_PROJECT: './tsconfig.prod.json',
  };

  const env = Object.entries(
    Object.keys(envObj).reduce<{ [key: string]: string | undefined }>((obj, key) => {
      // obj[key] = process.env[key] !== undefined ? process.env[key] : envObj[key];
      obj[key] = process.env[key] ?? envObj[key];
      return obj;
    }, {}),
  )
    .map(([key, value]) => `${key}=${value}`)
    .join(' ');
});

ts-node compiler cannot compile nullish coalescing operator. Because enableTypeScript function set skipProject always set true.

function enableTypeScript({ transpileOnly = true }) {
    const tsNodeModule = resolve_1.resolve('ts-node');
    if (tsNodeModule) {
        const tsNode = require(tsNodeModule);
        tsNode.register({
            transpileOnly, 
            skipProject: true, 
            compilerOptions: {
                target: 'esnext',          // this line cause problem

I think change below

function enableTypeScript({ transpileOnly = true }) {
    const tsNodeModule = resolve_1.resolve('ts-node');
    if (tsNodeModule) {
        const tsNode = require(tsNodeModule);
        tsNode.register({
            transpileOnly, 
            skipProject: ture,
            compilerOptions: {
                target: 'es2017',          // this line cause problem

finally I found problem and solution. I system below,

  • node v12.14.1
  • typescript 3.8.3

Node.js 12.14.1 ~ 12.16.1 not support ?? operator. I have to use stable version of Node.js. Because AWS only support 12.16.1.

Any idea?

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

No branches or pull requests

1 participant