Code Monkey home page Code Monkey logo

Comments (28)

remy avatar remy commented on July 1, 2024 1

@KevinGruber or @arpowers I'd appreciate some eyes on my change: https://github.com/remy/nodemon/pull/2208/files - I've tested it and it appears to work (with autocomplete), but more importantly the code actually still runs.

Again, I'm not a regular TS dev, so wary it could be wrong.

from nodemon.

remy avatar remy commented on July 1, 2024

Just checking, but does require work? And can you import using `import * as nodemon from 'nodemon'?

from nodemon.

KevinGruber avatar KevinGruber commented on July 1, 2024

const nodemon = require('nodemon'); - WORKS doesn't load types

import * as nodemon from 'nodemon'; - DOESN't work

I am pretty sure it is because there is no export of the functionality of nodemon.

Based on the types nothing is exported

from nodemon.

remy avatar remy commented on July 1, 2024

I need to have a play. I only added types as an attempt to help people who were requiring the module, but I don't personally use TypeScript (some context). If you have any advice, please do share, otherwise I'll tinker this week πŸ‘

from nodemon.

remy avatar remy commented on July 1, 2024

Okay, to clarify, import nodemon from 'nodemon' does work, i.e. this code works:

// test.mjs
import nodemon from 'nodemon'
nodemon({}).on('start', () => {
  console.log('started');
});

But the types aren't being found by tools like VS Code.

This is my code:

package.json

{
  "name": "2206",
  "version": "1.0.0",
  "main": "index.js",
  "dependencies": {
    "nodemon": "^3.1.1"
  }
}

index.js (the sub process):

console.log('Hello, World!');

And the run script: test.mjs

import nodemon from 'nodemon';

nodemon({}).on('start', () => {
  console.log('started');
});

From the command line:

SCR-20240528-jwdv

@KevinGruber you're saying it's undefined, can you share your code?

from nodemon.

KevinGruber avatar KevinGruber commented on July 1, 2024

Ok sry for the misunderstanding.

The runtime code works yes, but the typescript doesn't build because of "wrong" types.

undefined in the sense of types in TS

Beforehand it worked because there where no types (and I configured ts to allow for no types).

If you want I can make a PR with adjusted types?

from nodemon.

remy avatar remy commented on July 1, 2024

Yeah, if you could do a PR I'd appreciate it. I don't want to convert the project to typescript, but I do want to expose the types to help devs (which is why I've just added index.d.ts)

from nodemon.

KevinGruber avatar KevinGruber commented on July 1, 2024

I have the types already working, I now ran into the problem that they are not fitting the api approach types.

Can you help me and send me a list of allowed attributes? Like script etc.

are those than just merged with the current NodemonSettings? Or is NodemonSettings just the json config representation?

from nodemon.

remy avatar remy commented on July 1, 2024

This:

NodemonSettings just the json config representation

Sod, there's more props, I'll take a look and see if I can get a complete list. Annoyingly the --dump command doesn't quite list it out, because the inbound config is rearranged to the internal config (like script is moved to execOptions.

from nodemon.

remy avatar remy commented on July 1, 2024

If you have a branch, send up a work in progress PR and I can add to it (I think…)

from nodemon.

remy avatar remy commented on July 1, 2024

Found the following - pretty sure that's it.

script?: string; 
ext?: string; // "js,mjs" etc (should really support an array of strings, but I don't think it does right now)
events?: { [key: string]: string }; 
env?: { [key: string]: string };
exec?: string; // node, python, etc
execArgs?: string[]; // args passed to node, etc

from nodemon.

github-actions avatar github-actions commented on July 1, 2024

πŸŽ‰ This issue has been resolved in version 3.1.2 πŸŽ‰

The release is available on:

Your semantic-release bot πŸ“¦πŸš€

from nodemon.

arpowers avatar arpowers commented on July 1, 2024

@remy the types still aren't correct in latest version, type errors happen when using the documented API (the API that was 100% working prior to 3.1.1.

from nodemon.

KevinGruber avatar KevinGruber commented on July 1, 2024

@arpowers what do you mean with working before, it wasn't using any types before

Can you show me the error?

from nodemon.

remy avatar remy commented on July 1, 2024

@arpowers a screenshot would be useful here, or othewise some code for context. Ta.

from nodemon.

arpowers avatar arpowers commented on July 1, 2024

Sure here are the errors that show up after upgrade:

Let me know if you want a link to the code.

@fiction/core/plugin-env/restart.ts:19:13 - error TS2503: Cannot find namespace 'nodemon'.

19     config: nodemon.Settings
               ~~~~~~~

@fiction/core/plugin-env/restart.ts:65:8 - error TS2339: Property 'on' does not exist on type '(settings: NodemonSettings) => Nodemon'.

65       .on('log', () => {})
          ~~
Screenshot 2024-05-29 at 1 37 13β€―PM

from nodemon.

arpowers avatar arpowers commented on July 1, 2024

I should mention that I'm using "@types/nodemon": "^1.19.6", as well, let me try and uninstall that and see if anything changes.

....and no change, type errors are still there.

from nodemon.

remy avatar remy commented on July 1, 2024

Oooh. I know what it is. Though, not sure how you represent it in Typescript. It's because the nodemon function returns itself, and it's supposed to be a singleton.

This isn't a fix, but if you chain the. on to the call to nodemon, I suspect it will work.

I'll see if I can fix the types in the morning, or if anyone gets a PR before then, happy to merge.

Unrelated: I wonder who is maintaining @types/nodemon...that isn't mine... πŸ€”

from nodemon.

arpowers avatar arpowers commented on July 1, 2024

no hurry, just locked version for now.

from nodemon.

KevinGruber avatar KevinGruber commented on July 1, 2024

@remy yes that works for me I tested both use cases

I wasn't aware that you can use nodemon as a singleton like that. Sry for missing that :-(

I noticed another thing yesterday can you provide string and string[] to nodeArgs and execArgs?

I took your suggestion and it took only string[] but my old code provided string.

If it supports both and is expected I would change the type to string | string[]

from nodemon.

github-actions avatar github-actions commented on July 1, 2024

πŸŽ‰ This issue has been resolved in version 3.1.3 πŸŽ‰

The release is available on:

Your semantic-release bot πŸ“¦πŸš€

from nodemon.

arpowers avatar arpowers commented on July 1, 2024

@remy all working, it caused some type errors, but only because my code was wrong. Working exactly as it should. Thanks!

from nodemon.

kpman avatar kpman commented on July 1, 2024

Unrelated: I wonder who is maintaining @types/nodemon...that isn't mine... πŸ€”

@remy The @types/nodemon author's information:

Type definitions for nodemon 1.19
Project: http://nodemon.io
Definitions by: Emily Marigold Klassen <https://github.com/forivall>
Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

DefinitelyTyped/DefinitelyTyped#39088

Maybe you could contact her or just porting the type definitions into this repo.
The type definitions in 3.1.3 are not worked when using as the module.

from nodemon.

remy avatar remy commented on July 1, 2024

@kpman can you clarify this (or provide a working example)?

The type definitions in 3.1.3 are not worked when using as the module.

from nodemon.

GabenGar avatar GabenGar commented on July 1, 2024

@remy
Just FYI you can use arethetypeswrong to check if the types are declared properly.

from nodemon.

remy avatar remy commented on July 1, 2024

@GabenGar that just tells me what you told me, that they're wrong. I'm not a typescript person, and when I do use it (for work) it's a day of deciphering ts error messages.

So if you can (I'd hugely appreciate it) explain in plain English what's wrong, I can try to fix it.

from nodemon.

GabenGar avatar GabenGar commented on July 1, 2024

If you are not a typescript person then why do you provide typescript types instead of delegating them to DefinitelyTyped?
The problem at hand is not typescript per se but rather nodejs ESM/CJS shenanigans, and the explanation of the problem is as plain english as it can get, considering the subject matter.
Your types say the package is a ESM module, when in reality it's CJS and the typescript need to know this distinction to work properly with nodejs ESM code. The distinction didn't matter back when ESM was just a mere syntactic sugar meant for feeding into a bundler and it just worksβ„’, but now nodejs and even browsers support ESM, and both are pretty anal about the rules.

from nodemon.

arpowers avatar arpowers commented on July 1, 2024

I got it all working fine w "preserve" as module resolution mode. It does error due to CJS/ESM confusion if it's set to "NodeNext"...

from nodemon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.