diff options
Diffstat (limited to 'packages/astro')
-rwxr-xr-x | packages/astro/astro.cjs | 39 | ||||
-rwxr-xr-x | packages/astro/astro.mjs | 4 | ||||
-rw-r--r-- | packages/astro/package.json | 8 |
3 files changed, 44 insertions, 7 deletions
diff --git a/packages/astro/astro.cjs b/packages/astro/astro.cjs new file mode 100755 index 000000000..896fc8687 --- /dev/null +++ b/packages/astro/astro.cjs @@ -0,0 +1,39 @@ +#!/usr/bin/env node +/* eslint-disable no-console */ +'use strict'; +const pkg = require('./package.json'); +const semver = require('semver'); +const ci = require('ci-info'); +const CI_INTRUCTIONS = { + NETLIFY: 'https://docs.netlify.com/configure-builds/manage-dependencies/#node-js-and-javascript', + GITHUB_ACTIONS: 'https://docs.github.com/en/actions/guides/building-and-testing-nodejs#specifying-the-nodejs-version', + VERCEL: 'https://vercel.com/docs/runtimes#official-runtimes/node-js/node-js-version' +} + +/** Dynamically import the CLI after checking if this version of Node is supported */ +async function main() { + const engines = pkg.engines.node; + const version = process.versions.node; + const isSupported = semver.satisfies(version, engines) + + if (!isSupported) { + console.error(`\nNode.js v${version} is not supported by Astro! +Please upgrade to one of Node.js ${engines}.\n`); + if (ci.isCI) { + let platform; + for (const [key, value] of Object.entries(ci)) { + if (value === true) { + platform = key; + break; + } + } + console.log(`To set the Node.js version for ${ci.name}, reference the official documentation`) + if (CI_INTRUCTIONS[platform]) console.log(CI_INTRUCTIONS[platform]); + } + process.exit(1); + } + + await import('./dist/cli.js').then(({cli}) => cli(process.argv)); +} + +main(); diff --git a/packages/astro/astro.mjs b/packages/astro/astro.mjs deleted file mode 100755 index 5cc56e9ef..000000000 --- a/packages/astro/astro.mjs +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env node -import { cli } from './dist/cli.js'; - -cli(process.argv); diff --git a/packages/astro/package.json b/packages/astro/package.json index 4b379ec0a..2ed044da8 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -11,7 +11,7 @@ "directory": "packages/astro" }, "exports": { - ".": "./astro.mjs", + ".": "./astro.cjs", "./package.json": "./package.json", "./snowpack-plugin": "./snowpack-plugin.cjs", "./components": "./components/index.js", @@ -25,7 +25,7 @@ "#astro/*": "./dist/*.js" }, "bin": { - "astro": "astro.mjs" + "astro": "astro.cjs" }, "files": [ "components", @@ -58,6 +58,7 @@ "astring": "^1.7.4", "autoprefixer": "^10.2.5", "cheerio": "^1.0.0-rc.6", + "ci-info": "^3.2.0", "del": "^6.0.0", "es-module-lexer": "^0.4.1", "esbuild": "^0.10.1", @@ -66,7 +67,6 @@ "fast-xml-parser": "^3.19.0", "fdir": "^5.0.0", "find-up": "^5.0.0", - "unified": "^9.2.1", "gzip-size": "^6.0.0", "hast-to-hyperscript": "~9.0.0", "kleur": "^4.1.4", @@ -83,12 +83,14 @@ "rollup": "^2.43.1", "rollup-plugin-terser": "^7.0.2", "sass": "^1.32.13", + "semver": "^7.3.5", "shorthash": "^0.0.2", "slash": "^4.0.0", "snowpack": "3.7.1", "source-map-support": "^0.5.19", "string-width": "^5.0.0", "tiny-glob": "^0.2.8", + "unified": "^9.2.1", "yargs-parser": "^20.2.7" }, "devDependencies": { |