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

Update for v5 #371

Closed
wants to merge 3 commits into from
Closed

Update for v5 #371

wants to merge 3 commits into from

Conversation

gurgunday
Copy link
Member

No description provided.

Comment on lines 26 to 34
// TODO: fix this test
// const app3 = fastify()

app3.register(require('./ts-error/app'))
// await app3.register(require('./ts-error/app'))

app3.ready(function (err) {
t.type(err, Error)
t.match(err.message, /cannot import plugin.*typescript/i)
})
// app3.ready(function (err) {
// t.type(err, Error)
// t.match(err.message, /cannot import plugin.*typescript/i)
// })
Copy link
Member Author

Choose a reason for hiding this comment

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

This no longer errors, I have no idea why

This file is supposed to cause an error, but don't know why:

https://github.com/fastify/fastify-autoload/tree/master/test/commonjs/ts-error

Copy link
Member Author

Choose a reason for hiding this comment

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

@jean-michelet

Just asking since you are contributing to tests, do you have any idea why this could be happening?

Copy link
Contributor

@jean-michelet jean-michelet Apr 13, 2024

Choose a reason for hiding this comment

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

Once the TS error is fixed, there is a loader error:

Error: tsx must be loaded with --import instead of --loader
The --loader flag was deprecated in Node v20.6.0
    at X (file:///home/runner/work/fastify-autoload/fastify-autoload/node_modules/tsx/dist/esm/index.mjs:1:1920)
    at Hooks.addCustomLoader (node:internal/modules/esm/hooks:202:24)
    at Hooks.register (node:internal/modules/esm/hooks:168:16)
    at async initializeHooks (node:internal/modules/esm/utils:167:5)
    at async customizedModuleWorker (node:internal/modules/esm/worker:104:24)
    ```

Copy link
Contributor

@jean-michelet jean-michelet Apr 13, 2024

Choose a reason for hiding this comment

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

(18, ubuntu-latest) test fail, 16 is fine: https://github.com/jean-michelet/fastify-autoload/actions/runs/8214240315/job/22466499571#step:5:793

Wasn't sure what to do here... But I can try to fix it next week.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry @gurgunday ,

I answered too quickly and didn't notice your work on your first commit.
Have you made any progress?

This file is supposed to cause an error, but don't know why:
https://github.com/fastify/fastify-autoload/tree/master/test/commonjs/ts-error

Maybe it should throw an error because autoloader try to load a file with .ts extension (lib/a.ts) here:

dir: path.join(__dirname, 'lib')

I can get your work in the first commit and try to fix it in #370, wdyt?

const app3 = fastify()
// TODO: Fix this test
// const app3 = fastify()
// app3.register(require('./ts-error/app'))
Copy link
Member

Choose a reason for hiding this comment

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

why?

// app3.ready(function (err) {
// t.type(err, Error)
// t.match(err.message, /cannot import plugin.*typescript/i)
// })
Copy link
Member

Choose a reason for hiding this comment

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

why?

@gurgunday
Copy link
Member Author

We can't merge without that test passing

@jean-michelet
Copy link
Contributor

jean-michelet commented Apr 24, 2024

When you run the relevant tests directly with Node using node test/commonjs/error.js, everything works fine. However, if you run them with Tap using npx tap test/commonjs/error.js, it fails because autoloading accepts TypeScript files (lib/a.ts).

If you log this here:

console.log(typescriptSupport, isTsNode)

You'll notice the behavior: they are both false for node test/commonjs/error.js, but both true for npx tap test/commonjs/error.js.

By the way, it seems that it doesn't check types, only transpiles them. I guess it's the expected behavior? It transpiles fine absurd typing:

'use strict';

module.exports = function (f: void, opts: void, next: void) {
  f.get('/something', (request, reply) => {
    reply.send({ something: 'else' });
  });

  next();
};

@jean-michelet
Copy link
Contributor

I'm not sure if I'll have time to address it this week, but it appears that the upgrade to Tap 18 is responsible for this behavior. They have removed some default options, as mentioned here. I managed to get the test to pass by removing the TypeScript plugin tap plugin rm @tapjs/typescript, but this action led to failures in other tests.

I hope this helps you see things more clearly ^^

@@ -4,9 +4,9 @@ const { exec } = require('node:child_process')

const args = [
'tap',
'--node-arg=--loader=ts-node/esm',
'--node-arg=--import=ts-node/esm',
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure --import=ts-node/esm will works?

Copy link
Member

Choose a reason for hiding this comment

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

It works because tap handle the transpile, you can see it run even if you remove --node-arg=--import=ts-node/esm

@jean-michelet
Copy link
Contributor

Is it possible to force typescriptSupport deactivation?

The tests would pass with small modifications: jean-michelet#6

// scripts/unit.js
'use strict'

const { exec } = require('node:child_process')

doExec('npm run unit:with-modules', {
  shell: true,
  env: {
    ...process.env,
    FASTIFY_AUTOLOAD_TYPESCRIPT: 0
  }
})

doExec('npm run unit:with-ts-modules')

function doExec (cmd, opts = {}) {
  const child = exec(cmd, opts)

  child.stdout.pipe(process.stdout)
  child.stderr.pipe(process.stderr)
  child.once('close', process.exit)
}
// index.js
let typescriptSupport = false
if (Number(process.env.FASTIFY_AUTOLOAD_TYPESCRIPT) !== 0) {
  typescriptSupport = isFastifyAutoloadTypescriptOverride || isTsNode || isVitestEnvironment || isBabelNode || isJestEnvironment || isSWCRegister || isSWCNodeRegister || isSWCNode || isTsm || isTsx || isEsbuildRegister
}

@gurgunday
Copy link
Member Author

gurgunday commented Apr 28, 2024

@jean-michelet actually would you like to take over? You can just point your branch to next with a new PR from the looks of it

@jean-michelet
Copy link
Contributor

You can just point your branch to next with a new PR from the looks of it

Not that easy now that #370 have been merged...
We are supposed to have reached 100% test coverage, meaning that I'll have to struggle with tap 18.

But, okay, I'll do it next week.

@jean-michelet jean-michelet mentioned this pull request May 3, 2024
@gurgunday gurgunday closed this May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants