Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race condition causing errors chmod'ing DTS files with shebangs #1001

Open
sentience opened this issue Sep 18, 2023 · 1 comment · May be fixed by #1002
Open

Race condition causing errors chmod'ing DTS files with shebangs #1001

sentience opened this issue Sep 18, 2023 · 1 comment · May be fixed by #1002

Comments

@sentience
Copy link

sentience commented Sep 18, 2023

I'm seeing build errors related to .ts files that contain #!/usr/bin/env node, which tsup tries to chmod +x in order to ensure they are executable:

⋮
ESM dist/integrations/webpack-plugin.mjs           2.93 KB
ESM dist/imperativeAPI/useIntl.mjs                 428.00 B
ESM dist/compiledLocales/es.mjs                    4.58 KB
ESM dist/compiledLocales/sr.mjs                    7.41 KB
ESM dist/types/index.mjs                           156.00 B
ESM dist/compiledLocales/et.mjs                    4.54 KB
ESM ⚡️ Build success in 140ms
DTS Build start
Error: ENOENT: no such file or directory, chmod '/Users/kyank/Developer/unified-home/packages/i18n-react-intl/dist/scripts/extract.d.mts'
Error: error occured in dts build
    at Worker.<anonymous> (/Users/kyank/Developer/unified-home/node_modules/tsup/dist/index.js:2294:26)
    at Worker.emit (node:events:513:28)
    at MessagePort.<anonymous> (node:internal/worker:243:53)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
    at exports.emitMessage (node:internal/per_context/messageport:23:28)
DTS Build error
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

If I re-run the build without deleting the dist directory first, the error does not re-occur. If I remove the scripts/extract.ts entry module from my project, the same error occurs with a different script:

⋮
ESM dist/integrations/webpack-plugin.mjs           2.93 KB
ESM dist/compiledLocales/lv.mjs                    6.08 KB
ESM dist/imperativeAPI/formatDate.mjs              166.00 B
ESM dist/compiledLocales/et.mjs                    4.54 KB
ESM dist/compiledLocales/tl.mjs                    4.53 KB
ESM dist/integrations/webpack.mjs                  328.00 B
ESM ⚡️ Build success in 172ms
DTS Build start
Error: ENOENT: no such file or directory, chmod '/Users/kyank/Developer/unified-home/packages/i18n-react-intl/dist/scripts/smartlingPush.d.mts'
Error: error occured in dts build
    at Worker.<anonymous> (/Users/kyank/Developer/unified-home/node_modules/tsup/dist/index.js:2294:26)
    at Worker.emit (node:events:513:28)
    at MessagePort.<anonymous> (node:internal/worker:243:53)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:737:20)
    at exports.emitMessage (node:internal/per_context/messageport:23:28)
DTS Build error
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I've tried and failed to reproduce this in a toy project, where I guess the generation of .d.(m)ts files runs much more quickly, and therefore all of those files are generated before tsup tries to chmod those with shebangs at the top.

Unless I'm mistaken, the .d.(m)ts files for shebang scripts don't actually need to be chmod +x; only the actual .(m)js files need to be made executable. Could this be fixed by excluding the type definition files from the shebang plug-in?

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
sentience added a commit to sentience/tsup that referenced this issue Sep 18, 2023
sentience added a commit to sentience/tsup that referenced this issue Sep 18, 2023
@sentience
Copy link
Author

I've traced this to the use of https://github.com/egoist/rollup-plugin-hashbang in tsup's invocation of rollup to build dts files. Removing it from that task's rollup configuration seems to resolve this issue with no apparent side-effects. I will open a PR for further discussion of this possible solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant