MCPcopy Index your code
hub / github.com/QwikDev/qwik / copyPlatformBindingWasm

Function copyPlatformBindingWasm

scripts/binding-platform.ts:52–162  ·  view source on GitHub ↗
(config: BuildConfig)

Source from the content-addressed store, hash-verified

50
51// TODO only download current target and wasm
52export async function copyPlatformBindingWasm(config: BuildConfig) {
53 ensureDir(config.distQwikPkgDir);
54 ensureDir(config.distBindingsDir);
55 const cacheDir = join(config.tmpDir, `cached-bindings`);
56
57 let version = config.distVersion;
58 const isDev = version.includes('-dev');
59 let cdnUrl = 'https://cdn.jsdelivr.net/npm/';
60 let packageName: string;
61 if (isDev) {
62 cdnUrl = `https://pkg.pr.new/QwikDev/qwik/`;
63 version = version.split('-dev')[0];
64 }
65 if (version.startsWith('2')) {
66 // 6903 is the PR that builds v2
67 packageName = `@qwik.dev/core@${isDev ? '6903' : version}`;
68 } else {
69 packageName = `@builder.io/qwik@${isDev ? 'main' : version}`;
70 }
71
72 let cacheVersionDir: string;
73 if (isDev) {
74 // We fetch from pkg.pr.new which is a CDN for the CI builds
75 // It redirects to the latest version
76 cdnUrl = `${cdnUrl}${packageName}`;
77 // First request the URL, this will redirect to the latest version
78 const rsp = await fetch(cdnUrl);
79 if (!rsp.ok) {
80 throw new Error(`Unable to find Qwik package from ${cdnUrl}`);
81 }
82 const url = rsp.url;
83 // get the package name from the url
84 const realPackageName = url.split('/').pop()!;
85 // now check if we already have this package in the cache
86 const cachedPath = join(cacheDir, realPackageName);
87 if (!existsSync(cachedPath)) {
88 ensureDir(cacheDir);
89 // download the package
90 console.log(`🦉 downloading CI build from ${url}`);
91 const pkgRsp = await fetch(url);
92 if (!pkgRsp.ok) {
93 console.error(pkgRsp);
94 throw new Error(`Unable to fetch Qwik package from ${pkgRsp.url}`);
95 }
96 await writeFile(cachedPath, pkgRsp.body as any);
97 }
98 // now unpack the package using tar, into the cache directory
99 const unpackedPath = join(cacheDir, `${realPackageName}-unpacked`);
100 ensureDir(unpackedPath);
101 await new Promise((resolve, reject) => {
102 const child = spawn('tar', ['-xvf', cachedPath, '-C', unpackedPath]);
103 child.on('error', (e) => {
104 console.error(e);
105 reject(e);
106 });
107 child.on('close', (code) => {
108 if (code === 0) {
109 resolve(child.stdout);

Callers 1

buildFunction · 0.90

Calls 5

ensureDirFunction · 0.90
joinFunction · 0.85
fetchFunction · 0.85
onMethod · 0.80
resolveFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…