Package builds copy Flow sources into lib/ and dist/ untransformed when the checkout sits below a dot-folder

未关闭 适合新手
#60,447 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
76/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
babel, javascript, node.js, react-native
领域
build-system

调研方向

阅读 packages/react-native-codegen/scripts/build.js 和 scripts/build/build.js,尤其是 issue 中描述的 glob 和 ignore 检查。在点号开头的文件夹和普通文件夹中重现构建,然后比较哪些文件被复制或编译,以及包含了哪些测试文件夹。完成标准是:无论 checkout 位于哪种位置,两种构建对源文件的处理方式都相同。

由索引模型根据 Issue 内容生成。

描述

Flow Needs: Triage :mag:
Description

I found this when a script of mine that clones react-native main into a .repro/ folder and builds ReactAndroid stopped in generateCodegenSchemaFromJavaScript: Node could not load packages/react-native-codegen/lib/cli/combine/combine-js-to-schema-cli.js (SyntaxError: Missing initializer in const declaration, line 39).

packages/react-native-codegen/scripts/build.js and scripts/build/build.js decide whether to skip a source, copy it as written or compile it with Babel by matching '**/*.js' and their ignore pattern against the file's absolute path, which comes from globSync(..., {absolute: true}) (L108-L112, L95-L99). micromatch's ** does not match a path segment that starts with a dot, so in a checkout below any dot-folder no source matches either pattern: every .js file is copied with its Flow types into lib/ or dist/, and the __tests__, __mocks__ and fixture files are copied with them.

From the same main commit, below .dot/ and below plain/:

  • yarn build in packages/react-native-codegen logs all 132 src .js files as (copy) below .dot/ and none below plain/; its lib/ holds 132 .js files, 95 of which a CommonJS parse rejects, against 81 and 1 (parsers/parserMock.js) below plain/.
  • The root yarn build leaves 111 .js files in the five packages' dist/ below .dot/, 109 rejected, against 72 and 0 below plain/.

a12b442d26 (#55259) fixed the same kind of check, an absolute path tested for /., in generateRCTThirdPartyComponents.js for #55243.

Other platform: these are react-native's own yarn build scripts; I ran them on Windows.

Steps to reproduce
  1. Clone main into a folder below a dot-folder, for example work/.dot/react-native, and run yarn install.
  2. Run yarn build in packages/react-native-codegen: it logs (copy) for every src/**/*.js file.
  3. Run yarn build at the root.
  4. Load packages/react-native-codegen/lib/cli/combine/combine-js-to-schema-cli.js with Node, as ReactAndroid's generateCodegenSchemaFromJavaScript does: SyntaxError: Missing initializer in const declaration at line 39, const platform: ?string = argv.platform;.

./reproduce.sh in the reproducer does these steps in two clones, work/.dot/react-native and work/plain/react-native, and parses every built .js file as CommonJS without running it (check-js.cjs). It exits 1 while a build below the dot-folder leaves more files the parse rejects than the same build below none, and 0 once both leave as many.

Expected: below a dot-folder, both builds compile every src .js file and skip the test folders, as they do below plain/.
Seen: both copy every source as written (output below).

React Native Version

main at b49769c0cc (after 0.90.0-nightly-20261201-13d48c3d8)

Affected Platforms

Build - Windows, Other (please specify)

Output of npx @react-native-community/cli info

Not applicable: these are react-native's own package builds. The run's host:

host: MINGW64_NT-10.0-26300 3.6.10-5a1665c8.x86_64 x86_64; node v26.13.1; yarn 1.22.22
[…]
Stacktrace or Logs
host: MINGW64_NT-10.0-26300 3.6.10-5a1665c8.x86_64 x86_64; node v26.13.1; yarn 1.22.22
.dot: react-native main at b49769c0cc543a803823716600d0b482559681dd, cloned into .dot/react-native
.dot: packages/react-native-codegen yarn build: 132 of the 132 src .js files it logs copied, not compiled
  first: src\cli\combine\combine-js-to-schema-cli.js ⇒ lib\cli\combine\combine-js-to-schema-cli.js (copy)
.dot: packages/react-native-codegen/lib: 132 .js files, 95 rejected by a CommonJS parse
  first: packages/react-native-codegen/lib/CodegenSchema.js:13: SyntaxError: Unexpected token 'export'
.dot: packages/react-native-codegen/lib/cli/combine/combine-js-to-schema-cli.js: 1 .js files, 1 rejected by a CommonJS parse
  first: packages/react-native-codegen/lib/cli/combine/combine-js-to-schema-cli.js:39: SyntaxError: Missing initializer in const declaration
.dot: packages/community-cli-plugin/dist, packages/debugger-shell/dist, packages/dev-middleware/dist, packages/metro-config/dist, packages/react-native-compatibility-check/dist: 111 .js files, 109 rejected by a CommonJS parse
  first: packages/community-cli-plugin/dist/commands/bundle/__mocks__/sign.js:11: SyntaxError: Unexpected token ':'
plain: react-native main at b49769c0cc543a803823716600d0b482559681dd, cloned into plain/react-native
plain: packages/react-native-codegen yarn build: 0 of the 132 src .js files it logs copied, not compiled
plain: packages/react-native-codegen/lib: 81 .js files, 1 rejected by a CommonJS parse
  first: packages/react-native-codegen/lib/parsers/parserMock.js:6: SyntaxError: Cannot use import statement outside a module
plain: packages/react-native-codegen/lib/cli/combine/combine-js-to-schema-cli.js: 1 .js files, 0 rejected by a CommonJS parse
plain: packages/community-cli-plugin/dist, packages/debugger-shell/dist, packages/dev-middleware/dist, packages/metro-config/dist, packages/react-native-compatibility-check/dist: 72 .js files, 0 rejected by a CommonJS parse
SUMMARY: react-native main b49769c0cc: below a dot-folder the builds leave .js files Node cannot parse; codegen lib: 95 rejected below .dot/, 1 below plain/; root build dist: 109 rejected below .dot/, 0 below plain/
MANDATORY Reproducer

https://github.com/YevheniiKotyrlo/rn-codegen-build-under-dot-folder

Screenshots and Videos

No response

主要语言
C++
星标
127k
派生
25.4k
平均合并
2 天 5 小时
30 天内合并 PR
287

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

react/react-native 的其他 Issue

查看 react/react-native 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。