周报@2023-05-11

使用 prisma-json-types-generator 遇到的奇怪问题

prisma-json-types-generator 在 WebStorm 中使用

定义了如下类型,但是 WebStorm Code Complete 无法正确提示类型,只有加上 export 才能正确处理。

typescript
1// should export
2// otherwise, it will not take effect
3export declare global {
4  namespace PrismaJson {
5    type Tags = string[];
6    type Size = {
7      width: number;
8      height: number;
9    };
10  }
11}

fix(eslint): @typescript-eslint/no-use-before-define settings

ts
1/* eslint @typescript-eslint/no-use-before-define: ["error", { "functions": false }] */
2func();
3function func(){
4  console.log('hello world');
5}

React Buddy

好用的插件,https://react-buddy.com/

:youtube

nodejs 如何执行 shell 命令,并把结果实时回显输出?

https://segmentfault.com/q/1010000023332928

nodejs 如何执行 shell 命令,并把结果实时回显输出

js
1const exec = require('child_process').exec;
2
3exec('shell 命令', (error, stdout, stderr) => {
4    console.log({ error, stdout, stderr });
5});

我尝试如上写法,但是发现回调函数 (error, stdout, stderr)=>{} 在命令执行完毕才一次性返回, 而不是实时回显

请问如何让输出实时回显

你需要用 spawn, 它是一个事件触发器对象版本的 exec, 以下例子来自 node 官方文档:

https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options

js
1const { spawn } = require('child_process');
2const ls = spawn('ls', ['-lh', '/usr']);
3
4ls.stdout.on('data', (data) => {
5  console.log(`stdout: ${data}`);
6});
7
8ls.stderr.on('data', (data) => {
9  console.error(`stderr: ${data}`);
10});
11
12ls.on('close', (code) => {
13  console.log(`child process exited with code ${code}`);
14});

使用 spawn 可能出现的问题

js
1Error: spawn ENOENT
2    at errnoException (child_process.js:1000:11)
3    at Process.ChildProcess._handle.onexit (child_process.js:791:34)

https://stackoverflow.com/a/59830014

simply adding shell: true option solved my problem:

incorrect:

javascript
1const { spawn } = require('child_process');
2const child = spawn('dir');

correct:

javascript
1const { spawn } = require('child_process');
2const child = spawn('dir', [], {shell: true});

based on Node.js Documentation (thank to @Boris comment):

Note that:

if the shell option is enabled, do not pass unsanitized user input to this function. Any input containing shell metacharacters may be used to trigger arbitrary command execution.

关于在 WebStorm 中使用 MUI 极其卡顿的问题

https://youtrack.jetbrains.com/issue/WEB-59766/Very-slow-code-analysis-in-React-MUI-Javascript-code#focus=Comments-27-7332672.0-0

One more note: If you experience UI freezes while using tag completion, as a workaround, you can try to disable "Preferences | Editor | General | Smart Keys | HTML/CSS" -> "Insert required attributes on tag completion" (and may be other similar options in the settings). I am not sure that this will fix the problem completely, but at least it should reduce the freezes.

Initial HTTP proxy support for Copilot

https://github.com/orgs/community/discussions/29127

copilot-proxy.githubusercontent.com 设置分流

shadowrocket 分流

  • 配置里面添加代理分组
  • 配置里面规则下设置策略