david
(David Taylor)
2025 年5 月 29 日 10:56
1
在 Discourse 的标准 linting 配置的最新版本中,我们启用了 require-strict-mode ember-template-lint 规则。这将为任何 .hbs 文件引发 linting 错误。
要解决警告,您应该将所有组件、路由和连接器模板转换为 .gjs 文件。为了方便您操作,我们构建了 discourse-gjs-codemod ,它构建在 Ember 的 @embroider/template-tag-codemod 之上。
要使用 codemod,首先通过从 plugin skeleton 或 theme skeleton 复制最新的 package.json 来确保您的 linting 依赖项是最新的。然后,运行 eslint 和 prettier:
pnpm i
pnpm eslint --fix .
pnpm prettier --write "**/*.{gjs,js,hbs,scss}"
如果任何问题无法自动修复,请现在手动解决它们。不要立即运行 ember-template-lint - 预计它会失败。
现在使用此命令运行 codemod:
pnpm dlx https://github.com/discourse/discourse-gjs-codemod
如果存在任何无法自动解决的问题,信息将打印到终端。解决问题后,再次运行 codemod。
有关 .gjs 文件格式的更多信息,请参阅官方指南:
9 个赞
pfaffman
(Jay Pfaffman)
2025 年5 月 29 日 19:11
2
它需要密码?
*) pfaffman@noreno:~/src/pfaffman/discourse-pfaffmanager$ pnpm dlx https://github.com/discourse/discourse-gjs-codemod
Username for 'https://github.com': pfaffman
Password for 'https://pfaffman@github.com':
/home/pfaffman/.cache/pnpm/dlx/txqdpi2aznswmhsvgh3pgqp3te/1971d72469d-323788:
ERROR Command failed with exit code 128: git ls-remote git+ssh://git@github.com/discourse/discourse-gjs-codemod.git HEAD
ERROR: Repository not found.
fatal: Could not read from remote repository.
https://github.com/discourse/discourse-gjs-codemods 不起作用。也许它仍然是私有的?
4 个赞
pfaffman
(Jay Pfaffman)
2025 年5 月 29 日 19:55
5
这是关于什么的?
[107/859]
WARN 发现对等依赖项存在问题
.
├─┬ ember-auto-import 2.10.0
│ ├─┬ babel-loader 8.4.1
│ │ └── ✕ 缺少对等项 webpack@">=2"
│ ├─┬ css-loader 5.2.7
│ │ └── ✕ 缺少对等项 webpack@"^4.27.0 || ^5.0.0"
│ ├─┬ style-loader 2.0.0
│ │ └── ✕ 缺少对等项 webpack@"^4.0.0 || ^5.0.0"
│ └─┬ mini-css-extract-plugin 2.9.2
│ └── ✕ 缺少对等项 webpack@^5.0.0
└─┬ ember-source 5.12.0
├── ✕ 缺少对等项 @glimmer/component@^1.1.2
└─┬ ember-auto-import 2.10.0
└── ✕ 缺少对等项 webpack@^5.0.0
应该安装的对等依赖项:
@glimmer/component@^1.1.2 webpack@">=5.0.0 <6.0.0-0"
…
使用 pnpm v9.15.9 在 1.6 秒内完成
file:///home/pfaffman/.cache/pnpm/dlx/txqdpi2aznswmhsvgh3pgqp3te/1971d8d4970-32e7a4/node_modules/.pnpm/execa@9.6.0/node_modules/execa/lib/return/final-error.js:6
return new ErrorClass(message, options);
^
ExecaError: 命令失败,退出代码为 255: '/home/pfaffman/.cache/pnpm/dlx/txqdpi2aznswmhsvgh3pgqp3te/1971d8d4970-32e7a4/node_modules/.pnpm/@embroider+template-
tag-codemod@1.2.1-unstable.ce3535d_@glimmer+component@2.0.0_handlebars@4._arnanpbg4hbtumvl4wyacggoiu/node_modules/@embroider/template-tag-codemod/dist/src/cli.js' '
--relativeLocalPaths=false' '--nativeRouteTemplates=false' '--nativeLexicalThis=false' '--templateInsertion=end' --addNameToTemplateOnly '--customResolver=/home/pfa
ffman/.cache/pnpm/dlx/txqdpi2aznswmhsvgh3pgqp3te/1971d8d4970-32e7a4/node_modules/.pnpm/discourse-gjs-codemod@https+++codeload.github.com+discourse+discourse-gjs-cod
emod+tar.gz+a4bc_2dxbzd2itovnk6l7sa4geot32y/node_modules/discourse-gjs-codemod/custom-resolver.js' '--renamingRules=/home/pfaffman/.cache/pnpm/dlx/txqdpi2aznswmhsvg
h3pgqp3te/1971d8d4970-32e7a4/node_modules/.pnpm/discourse-gjs-codemod@https+++codeload.github.com+discourse+discourse-gjs-codemod+tar.gz+a4bc_2dxbzd2itovnk6l7sa4geo
t32y/node_modules/discourse-gjs-codemod/rules.js' '--renderTests=test/**/*.js' '--routeTemplates=**/templates/**/*.hbs' '--components=**/components/**/*.hbs'
但它似乎转换了除了几个模板之外的所有模板,虽然我还不明白为什么,但我并不感到惊讶,因为它们里面有一些古怪的东西,而且我无论如何都在重写它们。
1 个赞
david
(David Taylor)
2025 年5 月 30 日 09:38
6
我认为peerdependency消息可能只是一个警告,为了代码修改的目的可以忽略。
不太确定其他的错误。在日志中更靠前的位置是否有更有用的信息?这是一个你可以分享的公共主题/插件吗?
pfaffman
(Jay Pfaffman)
2025 年5 月 30 日 10:18
7
是的。我认为这些错误都是虚假的。只有少数内容没有转换。我不太确定为什么,但就像我说的,我本来就打算重写这些内容。
它确实成功重写了十几个或更多内容,所以这绝对是个奇迹!
我很快就会在其他公开的内容上尝试一下。
谢谢!
1 个赞