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

Move platform.json in accessible place #2928

Closed
sytolk opened this issue Oct 13, 2021 · 5 comments
Closed

Move platform.json in accessible place #2928

sytolk opened this issue Oct 13, 2021 · 5 comments

Comments

@sytolk
Copy link

sytolk commented Oct 13, 2021

What are you trying to achieve?

I want programmatically to check sharp installed platform in node_modules. The only place that show this is platform.json
A1D37C38-CC06-4DAF-85E0-68445D3B1DDF

to check is it right sharp platform installed in node_modules its need to write function like this:

function checkInstalledSharpPlatform(targetPlatform, arch) {
 let shrapPath = require.resolve('sharp');
 shrapPath = path.join(shrapPath,'..','..','vendor','8.11.3','darwin-arm64v8','platform.json');

 if (!fs.existsSync(shrapPath)) {
      return false;
 }
 const data = fs.readFileSync(shrapPath, 'utf8');
 return data === '"' + targetPlatform + '-' + arch + '"';
}

but this function is not robust (8.11.3 folder or darwin-arm64v8 will be changed in the next sharp versions). Can we have platform.json in better place? (like node_modules/sharp/platform.json)

Have you searched for similar feature requests? YES

@lovell
Copy link
Owner

lovell commented Oct 13, 2021

There can be multiple copies of the (internal, not part of the public API) platform.json file as multiple vendor binaries per platform-arch combination can co-exist within the same installation tree.

The value in each platform.json file should always equal the name of its parent directory. Its presence predates using named directories and isn't really required internally any more, so perhaps we could simplify things and remove these files entirely.

@sytolk
Copy link
Author

sytolk commented Oct 13, 2021

I see that platform.json is for remove :) but this not solve an issue:
"How can I programmatically check installed sharp platform in node_modules?"
maybe something from command line can be added like: sharp --version

sharp: v0.29.1 
platform: darwin-arm64v8
arch: x64

@lovell
Copy link
Owner

lovell commented Oct 13, 2021

sharp is not a command line tool, but as you suggest there might be value in exposing at runtime which platform-arch combinations exist under vendor. This could be similar to sharp.versions (which might also benefit from a change to reflect the multi-platform directory structure), but I'd need to think about the API.

@lovell
Copy link
Owner

lovell commented Dec 12, 2021

Added as sharp.vendor via commit 3da258f

Example output:

{ current: 'linux-x64', installed: [ 'linux-x64', 'win32-ia32' ] }

This will be in v0.30.0.

@lovell lovell added this to the v0.30.0 milestone Dec 12, 2021
@lovell
Copy link
Owner

lovell commented Feb 1, 2022

v0.30.0 now available with this feature.

@lovell lovell closed this as completed Feb 1, 2022
Y2zz pushed a commit to Y2zz/sharp that referenced this issue Feb 26, 2022
martinj pushed a commit to aptoma/sharp that referenced this issue Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants