summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Fred K. Schott <fkschott@gmail.com> 2021-08-20 11:04:55 -0700
committerGravatar GitHub <noreply@github.com> 2021-08-20 11:04:55 -0700
commit29b7e746e665271396a20d2b587ae8e1052a0b85 (patch)
tree4793046bbb93af1ca45579341895ad88d732082c
parent1e0e2f41cd5fa146917afada10cc894e80fd3787 (diff)
downloadastro-29b7e746e665271396a20d2b587ae8e1052a0b85.tar.gz
astro-29b7e746e665271396a20d2b587ae8e1052a0b85.tar.zst
astro-29b7e746e665271396a20d2b587ae8e1052a0b85.zip
add a real-world check for ESM<>CJS named export support (#1175)
Diffstat (limited to '')
-rwxr-xr-xpackages/astro/astro.js16
1 files changed, 13 insertions, 3 deletions
diff --git a/packages/astro/astro.js b/packages/astro/astro.js
index fe6bc8cba..d0b5a3f5f 100755
--- a/packages/astro/astro.js
+++ b/packages/astro/astro.js
@@ -14,10 +14,20 @@ const CI_INTRUCTIONS = {
};
async function main() {
- // Check for ESM support by loading the "supports-esm" in an way that works in both ESM & CJS.
- const supportsESM = typeof require !== 'undefined' ? require('supports-esm') : (await import('supports-esm')).default;
+ // Check for ESM support.
+ // Load the "supports-esm" package in an way that works in both ESM & CJS.
+ let supportsESM = typeof require !== 'undefined' ? require('supports-esm') : (await import('supports-esm')).default;
- // Supported: load Astro and run. Enjoy!
+ // Check for CJS->ESM named export support.
+ // "path-to-regexp" is a real-world package that we depend on, that only
+ // works in later versions of Node with advanced CJS->ESM support.
+ // If `import {compile} from 'path-to-regexp'` will fail, we need to know.
+ if (supportsESM) {
+ const testNamedExportsModule = await import('path-to-regexp');
+ supportsESM = !!testNamedExportsModule.compile;
+ }
+
+ // Preflight check complete. Enjoy! ✨
if (supportsESM) {
return import('./dist/cli.js')
.then(({ cli }) => cli(process.argv))