deno --watch 支持文件 glob 的语法是什么?

问题描述 投票:0回答:1

我在跑步

deno run -A --watch=./**/*.html,./**/*.js src/build.js

但是对 globbed 文件的更改永远不会触发构建。只有来自 build.js 依赖关系图的更改才会导致构建发生。我尝试在 glob 周围使用引号,或者只使用一个或另一个不带逗号但没有成功。

    --watch[=<FILES>...]
      Watch for file changes and restart process automatically.
      Local files from entry point module graph are watched by default.
      Additional paths might be watched by passing them as arguments to
      this flag.

但我似乎没有找到应该是什么语法。

我在 macOS 上使用 Deno 1.32.1。

watch deno
1个回答
0
投票

Deno 期望列表参数中的值使用逗号作为分隔符,但通配生成的列表默认使用空格。

您可以使用 shell 功能修改列表中的分隔符……或者只使用 Deno。这是一个使用 brace expansion 的示例,它应该适用于您的情况:

deno run --watch=$(deno eval -p 'Deno.args.join(",")' ./**/*.{html,js}) src/build.js

watch参数解释:

$(                                                   ) # Run the command in a subshell
  deno eval -p                                         # Evaluate JavaScript from the command line
               'Deno.args.join(",")'                   # The code to evaluate (join input arguments on a comma)
                                     ./**/*.{html,js}  # The expanded glob list

因此,例如,如果您具有

html
js
文件的文件系统结构,如下所示:

% ls -1 ./**/*.{html,js}
./files/a.html
./files/a.js
./files/nested/b.html
./files/nested/b.js
./src/build.js

然后子 shell 命令将生成一个逗号分隔的列表参数,如下所示:

% deno eval -p 'Deno.args.join(",")' ./**/*.{html,js}
./files/a.html,./files/nested/b.html,./files/a.js,./files/nested/b.js,./src/build.js
© www.soinside.com 2019 - 2024. All rights reserved.