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

Distribute binaries via npm module #1269

Merged
merged 11 commits into from
Aug 6, 2024
8 changes: 8 additions & 0 deletions .github/workflows/tag_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,11 @@ jobs:
GOHOSTOS: ${{ env.GOHOSTOS }}
GOHOSTARCH: ${{ env.GOHOSTARCH }}
GITHUB_TOKEN: ${{ secrets.RELEASE_GITHUB_TOKEN }}
- name: Update npm packages to latest version
working-directory: ./npm/@fastly/cli
run: npm install && npm version "${{ github.ref_name }}" --allow-same-version
- name: Publish npm packages
working-directory: ./npm/@fastly
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: for dir in *; do (echo $dir && cd $dir && npm publish); done
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ pkg/config/config.toml
# Ignore commitlint tool
commitlint.config.js
callvis.svg

# Ignore generated npm packages
npm/@fastly/cli-*/
1 change: 1 addition & 0 deletions npm/@fastly/cli/LICENSE
1 change: 1 addition & 0 deletions npm/@fastly/cli/README.md
22 changes: 22 additions & 0 deletions npm/@fastly/cli/fastly.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env node
import { execFileSync } from "node:child_process";

import { pkgForCurrentPlatform } from "./package-helpers.js";

const pkg = pkgForCurrentPlatform();

let location;
try {
// Check for the binary package from our "optionalDependencies". This
// package should have been installed alongside this package at install time.
location = (await import(pkg)).default;
} catch (e) {
throw new Error(`The package "${pkg}" could not be found, and is needed by @fastly/cli.
Either the package is missing or the platform/architecture you are using is not supported.
If you are installing @fastly/cli with npm, make sure that you don't specify the
"--no-optional" flag. The "optionalDependencies" package.json feature is used
by @fastly/cli to install the correct binary executable for your current platform.
If your platform is not supported, you can open an issue at https://github.com/fastly/cli/issues`);
}

execFileSync(location, process.argv.slice(2), { stdio: "inherit" });
19 changes: 19 additions & 0 deletions npm/@fastly/cli/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { pkgForCurrentPlatform } from "./package-helpers.js";

const pkg = pkgForCurrentPlatform();

let location;
try {
// Check for the binary package from our "optionalDependencies". This
// package should have been installed alongside this package at install time.
location = (await import(pkg)).default;
} catch (e) {
throw new Error(`The package "${pkg}" could not be found, and is needed by @fastly/cli.
Either the package is missing or the platform/architecture you are using is not supported.
If you are installing @fastly/cli with npm, make sure that you don't specify the
"--no-optional" flag. The "optionalDependencies" package.json feature is used
by @fastly/cli to install the correct binary executable for your current platform.
If your platform is not supported, you can open an issue at https://github.com/fastly/cli/issues`);
}

export default location;
5 changes: 5 additions & 0 deletions npm/@fastly/cli/package-helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { platform, arch } from "node:process";

export function pkgForCurrentPlatform() {
return `@fastly/cli-${platform}-${arch}`;
}
Loading
Loading