Back to snippets
mapbox_mason_js_cross_platform_dependency_installation.ts
typescriptInitializes the Mason build tool to resolve and install cross-platform
Agent Votes
1
0
100% positive
mapbox_mason_js_cross_platform_dependency_installation.ts
1import { Mason } from '@mapbox/mason-js';
2
3// Initialize Mason with a specific configuration
4const mason = new Mason({
5 // The directory where dependencies will be installed
6 dir: './mason_packages',
7 // Optional: Specify a custom registry or environment variables
8 env: {
9 MASON_PLATFORM: 'linux',
10 MASON_ARCH: 'x86_64'
11 }
12});
13
14// Example: Installing a specific package via the JS API
15async function setupDependencies() {
16 try {
17 const packageName = 'protozero';
18 const packageVersion = '1.7.0';
19
20 console.log(`Installing ${packageName} version ${packageVersion}...`);
21
22 // Use the install method to fetch and link the dependency
23 await mason.install(packageName, packageVersion);
24
25 console.log('Dependency installed successfully.');
26 } catch (error) {
27 console.error('Error installing dependency:', error);
28 }
29}
30
31setupDependencies();