Skip to content

Commit

Permalink
Add nodemon resolver (resolves #221)
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Aug 30, 2023
1 parent b18c8d3 commit 581aae1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/binaries/resolvers/fallback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const argFilters: ArgResolvers = {
'babel-node': withPositional,
esbuild: withPositional,
execa: withPositional,
nodemon: withPositional,
'ts-node': withPositional,
zx: withPositional,
tsx: parsed => parsed._.filter(p => p !== 'watch'),
Expand Down
1 change: 1 addition & 0 deletions src/binaries/resolvers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * as c8 from './c8.js';
export * as dotenv from './dotenv.js';
export * as node from './node.js';
export * as nodemon from './nodemon.js';
export * as npx from './npx.js';
export * as pnpm from './pnpm.js';
export * as rollup from './rollup.js';
Expand Down
17 changes: 17 additions & 0 deletions src/binaries/resolvers/nodemon.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import parseArgs from 'minimist';
import { compact } from '../../util/array.js';
import { toBinary, tryResolveFilePath, tryResolveSpecifiers } from '../util.js';
import type { Resolver } from '../types.js';

export const resolve: Resolver = (binary, args, { cwd, fromArgs }) => {
const parsed = parseArgs(args, {
string: ['r', 'exec'],
alias: { require: ['r', 'loader', 'experimental-loader', 'test-reporter'] },
});
return compact([
toBinary(binary),
tryResolveFilePath(cwd, parsed._[0]),
...tryResolveSpecifiers(cwd, [parsed.require].flat()),
...fromArgs([parsed.exec]),
]);
};
7 changes: 6 additions & 1 deletion tests/util/getReferencesFromScripts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ test('getReferencesFromScripts (ts-node/tsx)', () => {
});

test('getReferencesFromScripts (--require)', () => {
t('nodemon --require dotenv/config ./script.js --watch ./script.js', ['bin:nodemon', js, 'dotenv']);
t('program --loader tsx --test "test/*.spec.ts"', ['bin:program', 'tsx']);
t('program --loader ldr --loader tsx --test "test/*.spec.ts"', ['bin:program', 'ldr', 'tsx']);
});
Expand Down Expand Up @@ -161,6 +160,12 @@ test('getReferencesFromScripts (c8)', () => {
t('c8 --reporter=lcov --reporter text node --test --test-reporter=@org/reporter', ['bin:c8', '@org/reporter']);
});

test('getReferencesFromScripts (nodemon', () => {
t('nodemon --require dotenv/config ./script.js --watch ./script.js', ['bin:nodemon', js, 'dotenv']);
t("nodemon --exec 'ts-node --esm' ./main.ts | pino-pretty", ['bin:nodemon', ts, 'bin:ts-node', 'bin:pino-pretty']);
t('nodemon script.js', ['bin:nodemon', js]);
});

test('getReferencesFromScripts (bash expressions)', () => {
t('if test "$NODE_ENV" = "production" ; then make install ; fi ', ['bin:make']);
t('node -e "if (NODE_ENV === \'production\'){process.exit(1)} " || make install', ['bin:make']);
Expand Down

0 comments on commit 581aae1

Please sign in to comment.