Skip to content

Conversation

Copy link

Copilot AI commented Jan 12, 2026

The fs module imports in inputFile.ts cause the entire InputFile class to fail in edge runtimes (Cloudflare Workers, Vercel Edge), even for methods like fromBuffer() that don't require filesystem access.

Changes

  • Conditional imports: Replace static import statements with dynamic import() calls guarded by edge runtime detection
  • Parallel module loading: Use Promise.all() to load path and fs modules in parallel for better efficiency
  • Runtime validation: Add checks in fromPath(), size(), slice(), and toBuffer() to throw descriptive errors when fs operations are attempted in edge environments
  • Edge detection: Use typeof (globalThis as any).EdgeRuntime !== 'undefined' pattern matching client.ts.twig
  • Type safety: Use explicit interface for fs methods instead of typeof import('fs').promises to avoid edge runtime type resolution issues

Result

Buffer-based methods work in edge runtimes:

// ✅ Works in edge runtimes
const file = InputFile.fromBuffer(buffer, 'file.txt');
const file2 = InputFile.fromPlainText('content', 'file.txt');

// ❌ Clear runtime error in edge runtimes
const file3 = InputFile.fromPath('/path/to/file'); 
// Error: InputFile.fromPath is not supported in edge runtimes. Please use InputFile.fromBuffer instead.

No breaking changes for Node.js environments where all methods continue to work. Dynamic imports load asynchronously at module initialization, with undefined checks providing clear errors if modules aren't available.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 12, 2026

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI and others added 3 commits January 12, 2026 10:42
Co-authored-by: Meldiron <19310830+Meldiron@users.noreply.github.com>
Co-authored-by: Meldiron <19310830+Meldiron@users.noreply.github.com>
Co-authored-by: Meldiron <19310830+Meldiron@users.noreply.github.com>
Copy link
Author

Copilot AI commented Jan 12, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/Jean85/pretty-package-versions/zipball/4d7aa5dab42e2a76d99559706022885de0e18e1a
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/0ca86845ce43291e8f5692c7356fccf3bcf02bf4
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/matthiasmullie/minify/zipball/76ba4a5f555fd7bf4aa408af608e991569076671
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/matthiasmullie/path-converter/zipball/e7d13b2c7e2f2268e1424aaed02085518afa02d9
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/myclabs/DeepCopy/zipball/07d290f0c47959fd5eed98c95ee5602db07e0b6a
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/nikic/PHP-Parser/zipball/dca41cd15c2ac9d055ad70dbfd011130757d1f82
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/paratestphp/paratest/zipball/9b324c8fc319cf9728b581c7a90e1c8f6361c5e5
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/phar-io/manifest/zipball/54750ef60c58e43759730615a392c31c80e23176
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/2BxvG7 /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/15c5dd40dc4f38794d383bb95465193f5e0ae180
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/183a9b2632194febd219bb9246eee421dad8d45e
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/code-unit/zipball/54391c61e4af8078e5b276ab082b6d3c54c9ad64
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/comparator/zipball/85c77556683e6eee4323e4c5468641ca0237e2e8
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/complexity/zipball/ee41d384ab1906c68852636b6de493846e13e5a0
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/diff/zipball/b4ccd857127db5d41a5b676f24b51371d76d8544
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/environment/zipball/a5c75038693ad2e8d4b6c15ba2403532647830c4
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/exporter/zipball/70a298763b40b213ec087c51c739efcaa90bcd74
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/global-state/zipball/3be331570a721f9a4b5917f4209773de17f747d7
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/d36ad0d782e5756913e42ad87cb2890f4ffe467a
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/f5b498e631a74204185071eb41f33f38d64608aa
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/6e1a43b411b2ad34146dee7524cb13a068bb35f9
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/2c1ed04922802c15e1de5d7447b4856de949cf56
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/118cfaaa8bc5aef3287bf315b6060b1174754af6
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/c1ca3814734c07492b3d4c5f794f4b0995333da2
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/3e0404dc6b300e6bf56415467ebcb3fe4f33e964
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/php-timer/zipball/3b415def83fbcb41f991d9ebf16ae4ad8b7837b3
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/phpunit/zipball/75dfe79a2aa30085b7132bb84377c24062193f33
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/f6458abbf32a6c8174f8f26261475dc133b3d9dc
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/type/zipball/f77d2d4e78738c98d9a68d2596fe5e8fa380f449
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/sebastianbergmann/version/zipball/c687e3387b99f5b03b6caa64c74b63e2936ff874
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/staabm/side-effects-detector/zipball/d8334211a140ce329c13726d4a715adbddd0a163
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/console/zipball/732a9ca6cd9dfd940c639062d5edbde2f6727fb6
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/deprecation-contracts/zipball/63afe740e99a13ba87ec199bb07bbdee937a5b62
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/2BxvG7 /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/polyfill-ctype/zipball/a3cc8b044a6ea513310cbd48ef7333b384945638
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/2BxvG7 /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/380872130d3a5dd3ace2f4010d95125fde5d5c70
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/2BxvG7 /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/3833d7255cc303546435cb650316bff708a1c75c
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/2BxvG7 /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/polyfill-mbstring/zipball/6d857f4d76bd4b343eac26d6b539585d2bc56493
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/polyfill-php81/zipball/4a4cfc2d253c21a5ad0e53071df248ed48c6ce5c
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/process/zipball/2f8e1a6cdf590ca63715da4d3a7a3327404a523f
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/process/zipball/f24f8f316367b30810810d4eb30c543d7003ff3b
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/2BxvG7 /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader (http block)
  • https://api.github.com/repos/symfony/service-contracts/zipball/45112560a3ba2d715666a509a0bc9521d10b6c43
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/string/zipball/d50e862cb0a0e0886f73ca1f31b865efbb795003
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/symfony/string/zipball/f96476035142921000338bad71e5247fbc138872
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/2BxvG7 /usr/bin/composer install --ignore-platform-reqs --optimize-autoloader (http block)
  • https://api.github.com/repos/theofidry/cpu-core-counter/zipball/db9508f7b1474469d9d3c53b86f817e344732678
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/theseer/tokenizer/zipball/b7489ce515e168639d17feec34b8847c326b0b3c
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)
  • https://api.github.com/repos/twigphp/Twig/zipball/0b6f9d8370bb3b7f1ce5313ed8feb0fafd6e399a
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/gt4pVJ /usr/bin/composer update --no-interaction --prefer-dist (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Fix chunking uploads compatibility with Edge Make InputFile edge-compatible with conditional fs imports Jan 12, 2026
Copilot AI requested a review from Meldiron January 12, 2026 10:46
Comment on lines 11 to 20
// Only import fs modules if not in edge runtime
if (!isEdgeRuntime) {
try {
basename = require("path").basename;
realpathSync = require("fs").realpathSync;
fs = require("fs").promises;
} catch (e) {
// If imports fail, fs will remain undefined
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Do not use require, its not efficient. Lets switch to using import here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced require() with dynamic import() statements using top-level await. The modules are now loaded in parallel with Promise.all() for better efficiency. Changes in commit 2732380.

// Conditionally import fs modules to support edge runtimes
let basename: ((path: string) => string) | undefined;
let realpathSync: ((path: string) => string) | undefined;
let fs: typeof import('fs').promises | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot I am a bit worried about type here. This type would fail on edge runtime, right? Because edge doesnt know fs. Do we need to change this, or is it okay thanks to build step running on non-edge machine?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Replaced the typeof import('fs').promises type with an explicit interface that defines only the methods we use. This avoids any potential edge runtime type resolution issues while maintaining type safety. The explicit interface approach is safer since it doesn't reference Node.js types directly. Changes in commit 2732380.

Copilot AI and others added 3 commits January 12, 2026 10:49
Co-authored-by: Meldiron <19310830+Meldiron@users.noreply.github.com>
Co-authored-by: Meldiron <19310830+Meldiron@users.noreply.github.com>
Co-authored-by: Meldiron <19310830+Meldiron@users.noreply.github.com>
Copilot AI requested a review from Meldiron January 12, 2026 10:54
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 this pull request may close these issues.

2 participants