欢迎光临散文网 会员登陆 & 注册

编写一个 Vscode 插件 | 从创建到发布 | 一键删除函数

2022-11-05 20:56 作者:HenryTSZ  | 我要投稿


05:42


当执行 yo 报如下错误时:

/usr/local/lib/node_modules/yo/node_modules/macos-release/index.js:27

const 【name, version】 = nameMap.get(release);

^

TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))

可以打开报错指出的第一行的文件(可能与以上路径不同,没关系),修改成如下内容即可:

const nameMap = new Map([

 [22, ['Ventura', '13']],

 [21, ['Monterey', '12']],

 [20, ['Big Sur', '11']],

 [19, ['Catalina', '10.15']],

 [18, ['Mojave', '10.14']],

 [17, ['High Sierra', '10.13']],

 [16, ['Sierra', '10.12']],

 [15, ['El Capitan', '10.11']],

 [14, ['Yosemite', '10.10']],

 [13, ['Mavericks', '10.9']],

 [12, ['Mountain Lion', '10.8']],

 [11, ['Lion', '10.7']],

 [10, ['Snow Leopard', '10.6']],

 [9, ['Leopard', '10.5']],

 [8, ['Tiger', '10.4']],

 [7, ['Panther', '10.3']],

 [6, ['Jaguar', '10.2']],

 [5, ['Puma', '10.1']]

]);

主要就是没有增加对 mac 新系统的兼容

具体参见:https://github.com/yeoman/yo/issues/753



19:18


当执行报如下错误时:

Command 'xxx' resulted in an error ('import' and 'export' may appear only with 'sourceType: "module"' (2:4))

不是 eslint 配置有误(如果你在网上搜索时,大部分都提示修改 eslint 配置),而是 parse 需要传入第二个参数:

{

   sourceType: 'module',

 }

具体参见官方例子:

https://babel.docschina.org/docs/en/babel-parser/#example

这里的例子使用的是 require,但使用 import 也是可以的

所以当你在网上查询的解决方法无效时,阅读官方文档是最快的解决方式



43:00


这是由于 @babel/parser 的 startLine: By default, the parsed code is treated as if it starts from line 1, column 0. 与 vscode 的 line A zero-based line value. 不同

所以我们可以给 parser 指定一下 startLine:

const ast = parse(code, {

 sourceType: 'module',

 startLine: 0

})



54:23


这里的 publisher name 不是崔大说的那个 name,而是需要在 https://marketplace.visualstudio.com/manage 这里注册一下的,注册完以后再使用 vsce login + 刚注册的 name。推测崔大可能注册的 name 和视频里说的 name 是一样的,但这俩 name 可以不一致,只要保证全球唯一就可以了

编写一个 Vscode 插件 | 从创建到发布 | 一键删除函数的评论 (共 条)

分享到微博请遵守国家法律