Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@
"@qwik.dev/router": "workspace:*",
"@types/brotli": "1.3.4",
"@types/bun": "1.2.21",
"@types/cross-spawn": "6.0.6",
"@types/express": "5.0.3",
"@types/node": "24.3.0",
"@types/path-browserify": "1.0.3",
Expand All @@ -122,7 +121,6 @@
"all-contributors-cli": "6.26.1",
"brotli": "1.3.3",
"create-qwik": "workspace:*",
"cross-spawn": "7.0.6",
"csstype": "3.1.3",
"dotenv": "16.5.0",
"esbuild": "0.25.10",
Expand Down Expand Up @@ -199,7 +197,7 @@
"build.watch": "tsx --require ./scripts/runBefore.ts scripts/index.ts --qwik --qwikrouter --watch --dev --platform-binding",
"change": "changeset",
"cli": "pnpm build.cli && node packages/create-qwik/create-qwik.cjs && tsx --require ./scripts/runBefore.ts scripts/validate-cli.ts --copy-local-qwik-dist",
"cli.qwik": "pnpm build.cli && node packages/qwik/qwik-cli.cjs",
"cli.qwik": "pnpm build.cli && node packages/qwik/qwik-cli.mjs",
"cli.validate": "tsx --require ./scripts/runBefore.ts scripts/validate-cli.ts",
"deps": "corepack pnpm upgrade -i -r --latest && syncpack fix-mismatches && corepack pnpm dedupe",
"docs.dev": "pnpm -C packages/docs build.repl-sw && pnpm -C packages/docs dev",
Expand Down
39 changes: 10 additions & 29 deletions packages/qwik/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "2.0.0-beta.12",
"author": "Qwik Team",
"bin": {
"qwik": "./qwik-cli.cjs"
"qwik": "./qwik-cli.mjs"
},
"bugs": "https://github.com/QwikDev/qwik/issues",
"dependencies": {
Expand Down Expand Up @@ -35,15 +35,10 @@
"production": "./dist/core.prod.mjs",
"min": "./dist/core.min.mjs",
"default": "./dist/core.prod.mjs"
},
"require": {
"development": "./dist/core.cjs",
"production": "./dist/core.prod.cjs",
"default": "./dist/core.prod.cjs"
}
},
"./cli": {
"require": "./dist/cli.cjs"
"require": "./dist/cli.mjs"
},
"./handlers.mjs": "./handlers.mjs",
"./internal": {
Expand Down Expand Up @@ -94,50 +89,36 @@
"development": "./dist/build/index.dev.mjs",
"production": "./dist/build/index.prod.mjs",
"default": "./dist/build/index.mjs"
},
"require": {
"development": "./dist/build/index.dev.cjs",
"production": "./dist/build/index.prod.cjs",
"default": "./dist/build/index.cjs"
}
},
"./loader": {
"types": "./dist/loader/index.d.ts",
"import": "./dist/loader/index.mjs",
"require": "./dist/loader/index.cjs"
"import": "./dist/loader/index.mjs"
},
"./insights": {
"types": "./dist/insights.d.ts",
"import": "./dist/insights/index.qwik.mjs",
"require": "./dist/insights/index.qwik.cjs"
"import": "./dist/insights/index.qwik.mjs"
},
"./insights/vite": {
"types": "./dist/insights/vite.d.ts",
"import": "./dist/insights/vite/index.mjs",
"require": "./dist/insights/vite/index.cjs"
"import": "./dist/insights/vite/index.mjs"
},
"./optimizer.cjs": "./dist/optimizer.cjs",
"./optimizer.mjs": "./dist/optimizer.mjs",
"./optimizer": {
"types": "./dist/optimizer.d.ts",
"import": "./dist/optimizer.mjs",
"require": "./dist/optimizer.cjs"
"import": "./dist/optimizer.mjs"
},
"./preloader": {
"import": "./dist/preloader.mjs",
"require": "./dist/preloader.cjs"
"import": "./dist/preloader.mjs"
},
"./server.cjs": "./dist/server.cjs",
"./server.mjs": "./dist/server.mjs",
"./server": {
"types": "./server.d.ts",
"import": "./dist/server.mjs",
"require": "./dist/server.cjs"
"import": "./dist/server.mjs"
},
"./testing": {
"types": "./dist/testing/index.d.ts",
"import": "./dist/testing/index.mjs",
"require": "./dist/testing/index.cjs"
"import": "./dist/testing/index.mjs"
},
"./qwikloader.js": "./dist/qwikloader.js",
"./qwikloader.debug.js": "./dist/qwikloader.debug.js",
Expand All @@ -161,7 +142,7 @@
"public.d.ts",
"server.d.ts",
"testing.d.ts",
"qwik-cli.cjs"
"qwik-cli.mjs"
],
"homepage": "https://qwik.dev/",
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env node
// This requires the build to be run first.
const qwik = require('./dist/cli.cjs');
import * as qwik from './dist/cli.mjs';
qwik.runCli();
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env node
const qwik = require('./cli.cjs');
import * as qwik from './cli.mjs';
qwik.runCli();
54 changes: 19 additions & 35 deletions packages/qwik/src/cli/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,36 @@
import { blue, gray, green, magenta, red, reset, white } from 'kleur/colors';
import { log, outro } from '@clack/prompts';

import type { ChildProcess } from 'node:child_process';
import type { IntegrationPackageJson } from '../types';
import detectPackageManager from 'which-pm-runs';
import fs from 'node:fs';
import { join } from 'node:path';
import spawn from 'cross-spawn';

import { execa } from 'execa';
export function runCommand(cmd: string, args: string[], cwd: string) {
let child: ChildProcess;

const install = new Promise<boolean>((resolve) => {
try {
child = spawn(cmd, args, {
cwd,
stdio: 'ignore',
});

child.on('error', (e) => {
if (e) {
if (e.message) {
log.error(red(String(e.message)) + `\n\n`);
} else {
log.error(red(String(e)) + `\n\n`);
}
}
resolve(false);
});
const child = execa(cmd, args, {
cwd,
stdio: 'ignore',
});

child.on('close', (code) => {
if (code === 0) {
resolve(true);
const install: Promise<boolean> = child
.then(() => {
return true;
})
.catch((e) => {
if (e) {
if (e.message) {
log.error(red(String(e.message)) + `\n\n`);
} else {
resolve(false);
log.error(red(String(e)) + `\n\n`);
}
});
} catch (e) {
resolve(false);
}
});
}
return false;
});

const abort = async () => {
if (child) {
child.kill('SIGINT');
}
child.kill('SIGINT');
};

// 5. Return the object synchronously
return { abort, install };
}

Expand Down
13 changes: 0 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 25 additions & 51 deletions scripts/binding-platform.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,36 @@
import spawn from 'cross-spawn';
import { execa } from 'execa';
import { copyFile, writeFile } from 'fs/promises';
import { existsSync } from 'node:fs';
import { join } from 'node:path';
import { ensureDir, type BuildConfig } from './util';

export async function buildPlatformBinding(config: BuildConfig) {
await new Promise((resolve, reject) => {
try {
ensureDir(config.distQwikPkgDir);
ensureDir(config.distBindingsDir);

const cmd = `napi`;
const args = [
`build`,
`--cargo-name`,
'qwik_napi',
`--platform`,
`--config=packages/qwik/src/napi/napi.config.json`,
config.distBindingsDir,
];

if (config.platformTarget) {
args.push(`--target`, config.platformTarget);
}
if (!config.dev) {
args.push(`--release`);
args.push(`--strip`);
}
ensureDir(config.distQwikPkgDir);
ensureDir(config.distBindingsDir);

const napiCwd = join(config.rootDir);
const cmd = `napi`;
const args = [
`build`,
`--cargo-name`,
'qwik_napi',
`--platform`,
`--config=packages/qwik/src/napi/napi.config.json`,
config.distBindingsDir,
];

if (config.platformTarget) {
args.push(`--target`, config.platformTarget);
}
if (!config.dev) {
args.push(`--release`);
args.push(`--strip`);
}

const child = spawn(cmd, args, { stdio: 'inherit', cwd: napiCwd });
child.on('error', reject);
const napiCwd = join(config.rootDir);

child.on('close', (code) => {
if (code === 0) {
resolve(child.stdout);
} else {
reject(`napi exited with code ${code}`);
}
});
} catch (e) {
reject(e);
}
await execa(cmd, args, {
stdio: 'inherit',
cwd: napiCwd,
});

console.log('🐯 native binding');
Expand Down Expand Up @@ -99,21 +87,7 @@ export async function copyPlatformBindingWasm(config: BuildConfig) {
// now unpack the package using tar, into the cache directory
const unpackedPath = join(cacheDir, `${realPackageName}-unpacked`);
ensureDir(unpackedPath);
await new Promise((resolve, reject) => {
const child = spawn('tar', ['-xvf', cachedPath, '-C', unpackedPath]);
child.on('error', (e) => {
console.error(e);
reject(e);
});
child.on('close', (code) => {
if (code === 0) {
resolve(child.stdout);
} else {
console.error(child.stdout);
reject(`tar exited with code ${code}`);
}
});
});
await execa('tar', ['-xvf', cachedPath, '-C', unpackedPath]);

// now we need to find the bindings in the package
cacheVersionDir = join(unpackedPath, 'package', 'bindings');
Expand Down
31 changes: 12 additions & 19 deletions scripts/binding-wasm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type BuildConfig, copyFile, emptyDir, ensureDir } from './util';
import spawn from 'cross-spawn';
import { execa } from 'execa';
import { join } from 'node:path';
import { rollup } from 'rollup';

Expand All @@ -18,25 +18,18 @@ export async function buildWasmBinding(config: BuildConfig) {
args.push(`--release`);
}

await new Promise((resolve, reject) => {
const child = spawn(cmd, args, {
stdio: 'inherit',
shell: true,
env: {
...process.env,
...env,
},
});
child.on('error', reject);

child.on('close', (code) => {
if (code === 0) {
resolve(child.stdout);
} else {
reject(`wasm-pack exited with code ${code}`);
}
});
// 2. Replace the entire Promise wrapper with one line
// execa handles errors and non-zero exit codes automatically.
await execa(cmd, args, {
stdio: 'inherit', // 'inherit' is still used to show build output
shell: true,
env: {
...process.env,
...env,
},
});

// 3. The return statement is unchanged
return join(tmpBuildDir, 'qwik_wasm.js');
}

Expand Down
1 change: 1 addition & 0 deletions scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const args = process.argv.slice(2);
// load our build config, which figures out all the paths
// the rest of the build process uses.
const config = loadConfig(args);
console.log(config);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you take this out?

config.esmNode = true;

// let's do this!
Expand Down
Loading
Loading