Skip to content

Commit

Permalink
Fix: Pagefind's npm wrapper should be using pagefind_extended
Browse files Browse the repository at this point in the history
  • Loading branch information
bglw committed Sep 13, 2023
1 parent 5750761 commit 2306ebd
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ jobs:
- name: Extract Binary
working-directory: build-artifacts
run: |
tar xzf pagefind-v$GIT_VERSION-${{ matrix.target }}.tar.gz
tar xzf pagefind_extended-v$GIT_VERSION-${{ matrix.target }}.tar.gz
rm *.tar.gz
mv * ../${{ matrix.package }}/bin/
- name: Prepare package
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

## Unreleased

* Fixed the new `pagefind` npm wrapper to use the `pagefind_extended` release, as documented.

## v1.0.0 (September 13, 2023)

Pagefind 1.0 is here! This release has been many months in the making, and we're thrilled to be bringing some great new features and improvements.
Expand Down
37 changes: 21 additions & 16 deletions wrappers/node/lib/resolveBinary.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,33 @@ import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);

/**
* @param {string} execname
* @param {string[]} execnames
* @returns {string}
*/
export function resolveBinaryPath(execname) {
const env_var = process.env[`${execname.toUpperCase()}_BINARY_PATH`];
if (env_var) return env_var;
export function resolveBinaryPath(execnames = []) {
for (const execname of execnames) {
const env_var = process.env[`${execname.toUpperCase()}_BINARY_PATH`];
if (env_var) return env_var;
}


const cpu = process.env.npm_config_arch || os.arch();
const platform = process.platform === 'win32' ? 'windows' : process.platform;

const executable = platform === 'windows' ? `${execname}.exe` : execname;
for (const execname of execnames) {
const executable = platform === 'windows' ? `${execname}.exe` : execname;

try {
return require.resolve(`@${execname}/${platform}-${cpu}/bin/${executable}`);
} catch (e) {
throw new Error(
[
`Failed to install ${execname}. Most likely the platform ${platform}-${cpu} is not yet a supported architecture.`,
`Please open an issue at https://github.com/CloudCannon/${execname} and paste this error message in full.`,
`If you believe this package should be compatible with your system,`,
`you can try downloading a release binary directly from https://github.com/CloudCannon/${execname}/releases`
].join('\n')
);
try {
return require.resolve(`@${execname}/${platform}-${cpu}/bin/${executable}`);
} catch (e) { }
}

throw new Error(
[
`Failed to install either of [${execnames.join(', ')}]. Most likely the platform ${platform}-${cpu} is not yet a supported architecture.`,
`Please open an issue at https://github.com/CloudCannon/pagefind and paste this error message in full.`,
`If you believe this package should be compatible with your system,`,
`you can try downloading a release binary directly from https://github.com/CloudCannon/pagefind/releases`
].join('\n')
);
}
3 changes: 2 additions & 1 deletion wrappers/node/lib/runner/bin.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
const { spawnSync } = require('child_process');

const execname = 'pagefind';
const execnames = ["pagefind_extended", "pagefind"];

(async () => {
try {
const { resolveBinaryPath } = await import("../resolveBinary.js");
const args = process.argv.slice(2);
const binaryPath = resolveBinaryPath(execname);
const binaryPath = resolveBinaryPath(execnames);
const verbose = args.filter(a => /verbose|-v$/i.test(a)).length;
if (verbose) {
console.log(`${execname} npm wrapper: Running the executable at ${binaryPath}`);
Expand Down
2 changes: 1 addition & 1 deletion wrappers/node/lib/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class PagefindService {
/**
* @type {child_process.ChildProcessByStdio<import('stream').Writable, import('stream').Readable, null> | null}
*/
this.backend = child_process.spawn(resolveBinaryPath("pagefind"), [`--service`], {
this.backend = child_process.spawn(resolveBinaryPath(["pagefind_extended", "pagefind"]), [`--service`], {
windowsHide: true,
stdio: ['pipe', 'pipe', 'inherit'],
cwd: process.cwd(),
Expand Down

0 comments on commit 2306ebd

Please sign in to comment.