Giter Club home page Giter Club logo

esmon's Introduction

💛 You can help the author become a full-time open-source maintainer by sponsoring him on GitHub.


esmon

npm version

Install

npm i -D esmon

Usage

Run a script and watch for changes: (for development)

esmon your-script.ts

This will also watch all the files imported by your-script.ts and re-run it on changes.

Note that this command will emit temporary files to ./temp folder, it's recommended to add it to your .gitignore file.

If you intend to run the file without watching files, you can use the run command instead: esmon run your-script.ts.

Build a script: (for production)

esmon build your-scripts.ts

This command will emit bundled script in esm format to ./dist folder with a filename matching the original filename. i.e. here you will get ./dist/your-script.cjs.

ESM

You can also output ESM format with flag --esm, the output extension will be .mjs. __dirname and __filename will also be shimmed.

Externals

dependencies, devDependencies and peerDependencies are automatically excluded from the bundled scripts. If you wish to bundle devDependencies, you can pass the --bundleDevDeps flag.

Decorators

Both experimentalDecorators and emitDecoratorMetadata options in tsconfig.json are supported, when you have emitDecoratorMetadata enabled we will use swc to transform decorators.

License

MIT © EGOIST

esmon's People

Contributors

egoist avatar

Stargazers

 avatar kevin avatar alobe avatar  avatar  avatar Iman avatar Pavel Danilov avatar Vladislav Forsh avatar Parmesh Krishen avatar Guillaume Humbert avatar Mateusz avatar Jeff Reiner avatar Sakamoto, Kazunori avatar Floffah avatar Manvendra Singh avatar Michael Demarais avatar S.T.P avatar Goli Akshay Sujith avatar Eli avatar Simão Júnior avatar  avatar  avatar Aryan Vikash avatar ch3cknull avatar Hendry Sadrak avatar Luiz Fernando da Silva Cieslak avatar Pedro Castro avatar TK avatar dp avatar 陈随易 avatar Robert Shaw avatar CXM avatar Guillaume Dumoulin avatar Hasibul Hasan avatar Alexander Niebuhr avatar Ryota Murakami avatar Hiroki Osame avatar Jorge Perez avatar Brad Svercl avatar Artur avatar mike lee avatar Michel Betancourt avatar yyyanghj avatar YangJH avatar Jbee avatar danny avatar Rhio Kim avatar Hanxx avatar 2013WUSO01 avatar 流浪大法师 avatar Amio Jin avatar Mark1 avatar Shoichi Aizawa avatar Alexis Tyler avatar Marco Lüthy avatar Alexey avatar Lucas Jones avatar Grant Forrest avatar Arda Soyturk avatar Harshal Kaigaonkar avatar Poco avatar Vinayak Kulkarni avatar Alex avatar Josh King avatar Jeet Mandaliya avatar  avatar Peng Xiao avatar  avatar BYUNGI avatar Baki avatar Al-Khawarizmi avatar Alexandre Stahmer avatar featherlight avatar limichange avatar Daniel Perez Alvarez avatar ハン / Han avatar 엘련(Jisu Kim) avatar YangSS avatar MADAO avatar buu avatar Mocchapine avatar Robert Soriano avatar Minoah avatar Satya Wikananda avatar Hyeseong Kim avatar Javier Diaz avatar y.takahashi avatar Nirmalya Ghosh avatar Starck Lin avatar  avatar Sai Krishna avatar Nick Reese avatar Brian Faust avatar  avatar Huy Giang avatar Corentin Leruth avatar Tim Simon avatar Subhan Bakh avatar Muhammad Athif avatar Cat  avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

hiteshmah-jan

esmon's Issues

Random 'address already in use' error on restart

If I run: yarn esmon src/api/server.ts

I get random errors when I modify files:

events.js:291
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE: address already in use 127.0.0.1:3001
    at Server.setupListenHandle [as _listen2] (net.js:1316:16)
    at listenInCluster (net.js:1364:12)
    at GetAddrInfoReqWrap.doListen [as callback] (net.js:1501:7)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:68:8)
Emitted 'error' event on Server instance at:
    at emitErrorNT (net.js:1343:8)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  code: 'EADDRINUSE',
  errno: 'EADDRINUSE',
  syscall: 'listen',
  address: '127.0.0.1',
  port: 3001

I wasn't able to reproduce this on a minimal example, and I wasn't able to 'reduce' my code reliably (the error simply appears less frequently). I believe there is a race condition which has something to do with how long does the compilation and/or resource deallocation take. Could it be for instance that you don't actually wait until the 'old' process is fully gone before spawning a new one?

This is macOS 11.3.1, node 16.

Build in Docker fails with spawn Unknown system error

I have a minimal Express app with this Dockerfile

FROM node:16-alpine
WORKDIR /app
COPY package*.json ./
COPY . .
RUN npm install
CMD ["node", "dist/server.js"]

and package.json

{
	"scripts": {
		"build": "npx esmon build src/server.ts",
		"postinstall": "npm run build",
		"start": "node dist/server.js"
	} 
}

Everything works fine locally, but when I try to build Docker

docker build -t demo_app

It errors:

[+] Building 5.9s (9/9) FINISHED                                                                                                                                                                                       
 => [internal] load build definition from Dockerfile                                                                                                                                                              0.0s
 => => transferring dockerfile: 36B                                                                                                                                                                               0.0s
 => [internal] load .dockerignore                                                                                                                                                                                 0.0s
 => => transferring context: 2B                                                                                                                                                                                   0.0s
 => [internal] load metadata for docker.io/library/node:16-alpine                                                                                                                                                 0.6s
 => [1/5] FROM docker.io/library/node:16-alpine@sha256:a2b99f95311def1095e5b9604a81956f4109d9a512a44c86fc382f472cad1d91                                                                                           0.0s
 => [internal] load build context                                                                                                                                                                                 0.2s
 => => transferring context: 238.63kB                                                                                                                                                                             0.2s
 => CACHED [2/5] WORKDIR /app                                                                                                                                                                                     0.0s
 => [3/5] COPY package*.json ./                                                                                                                                                                                   0.0s
 => [4/5] COPY . .                                                                                                                                                                                                0.8s
 => ERROR [5/5] RUN npm install                                                                                                                                                                                   4.1s
------                                                                                                                                                                                                                 
 > [5/5] RUN npm install:                                                                                                                                                                                              
#9 3.472                                                                                                                                                                                                               
#9 3.472 > postinstall                                                                                                                                                                                                 
#9 3.472 > npm run build                                                                                                                                                                                               
#9 3.472                                                                                                                                                                                                               
#9 3.869 
#9 3.869 > build
#9 3.869 > npx esmon build src/server.ts
#9 3.869 
#9 4.004 node:internal/errors:464
#9 4.004     ErrorCaptureStackTrace(err);
#9 4.004     ^
#9 4.004 
#9 4.004 Error: spawn Unknown system error -8
#9 4.004     at ChildProcess.spawn (node:internal/child_process:412:11)
#9 4.004     at Object.spawn (node:child_process:698:9)
#9 4.004     at ensureServiceIsRunning (/app/node_modules/esbuild/lib/main.js:1766:29)
#9 4.004     at build (/app/node_modules/esbuild/lib/main.js:1658:26)
#9 4.004     at build (/app/node_modules/esmon/dist/index.js:151:39)
#9 4.004     at CAC.<anonymous> (/app/node_modules/esmon/dist/cli.js:618:9) {
#9 4.004   errno: -8,
#9 4.004   code: 'Unknown system error -8',
#9 4.004   syscall: 'spawn'
#9 4.004 }
#9 4.017 npm notice 
#9 4.017 npm notice New minor version of npm available! 7.21.1 -> 7.24.0
#9 4.017 npm notice Changelog: <https://github.com/npm/cli/releases/tag/v7.24.0>
#9 4.018 npm notice Run `npm install -g [email protected]` to update!
#9 4.018 npm notice 
#9 4.021 npm ERR! code 1
#9 4.021 npm ERR! path /app
#9 4.022 npm ERR! command failed
#9 4.023 npm ERR! command sh -c npm run build
#9 4.030 
#9 4.030 npm ERR! A complete log of this run can be found in:
#9 4.030 npm ERR!     /root/.npm/_logs/2021-09-17T19_39_05_993Z-debug.log
------
executor failed running [/bin/sh -c npm install]: exit code: 1

Decorator support

As ESBuild doesn't support TypeScript decorators syntax, when project contains decorator esmon will not work correctly. A plugin is required to handle decorators compilation, the implemention can be like this:

  • on .ts file load, read the file content.
  • check does decorator exist in this file, by new RegExp( /((?<![(\s]\s*['"])@\w*[\w\d]\s*(?![;])[((?=\s)])/. ) (use strip-comments package to remove comments which may also contain @ syntax)
  • if decorators are detected, use transpileModule export from typescript, and return result as contents.
  • also, if project contains lots of files with decorators, swc can be considered as replacement for tsc(in my experiments they work normally).

Better logging

Output a message when the process is restarted, and the file that triggered it

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.