@qds.dev/code 0.8.5 → 0.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +102 -0
  2. package/lib-types/src/debug.d.ts +1 -0
  3. package/lib-types/src/index.d.ts +2 -0
  4. package/lib-types/src/preview/bundler/bundled-config.d.ts +33 -0
  5. package/lib-types/src/preview/bundler/bundled.d.ts +3 -0
  6. package/lib-types/src/preview/bundler/bundled.unit.d.ts +1 -0
  7. package/lib-types/src/preview/bundler/client-events-listener.d.ts +1 -0
  8. package/lib-types/src/preview/bundler/index.d.ts +34 -0
  9. package/lib-types/src/preview/bundler/repl-bundler-worker.d.ts +30 -0
  10. package/lib-types/src/preview/bundler/repl-ssr-worker.d.ts +27 -0
  11. package/lib-types/src/preview/bundler/rollup-plugins.d.ts +5 -0
  12. package/lib-types/src/preview/bundler/rollup-plugins.unit.d.ts +1 -0
  13. package/lib-types/src/preview/constants.d.ts +5 -0
  14. package/lib-types/src/preview/index.d.ts +19 -0
  15. package/lib-types/src/preview/mocks/browser.d.ts +2 -0
  16. package/lib-types/src/preview/preview-sw.d.ts +20 -0
  17. package/lib-types/src/preview/preview-sw.unit.d.ts +1 -0
  18. package/lib-types/src/preview/register-preview-sw.d.ts +2 -0
  19. package/lib-types/src/preview/register-preview-sw.unit.d.ts +1 -0
  20. package/lib-types/src/preview/repl-editor.d.ts +1 -0
  21. package/lib-types/src/preview/repl-helpers-node.d.ts +4 -0
  22. package/lib-types/src/preview/repl-helpers.d.ts +16 -0
  23. package/lib-types/src/preview/repl-helpers.unit.d.ts +1 -0
  24. package/lib-types/src/preview/test-extend.d.ts +9 -0
  25. package/lib-types/src/preview/types.d.ts +70 -0
  26. package/lib-types/tsconfig.tsbuildinfo +1 -1
  27. package/package.json +13 -8
  28. package/LICENSE +0 -21
  29. package/lib/node_modules/.pnpm/@emnapi_core@1.7.1/node_modules/@emnapi/core/dist/emnapi-core.esm-bundler.qwik.mjs +0 -5533
  30. package/lib/node_modules/.pnpm/@emnapi_runtime@1.8.1/node_modules/@emnapi/runtime/dist/emnapi.esm-bundler.qwik.mjs +0 -1225
  31. package/lib/node_modules/.pnpm/@emnapi_wasi-threads@1.1.0/node_modules/@emnapi/wasi-threads/dist/wasi-threads.esm-bundler.qwik.mjs +0 -619
  32. package/lib/node_modules/.pnpm/@napi-rs_wasm-runtime@1.1.1/node_modules/@napi-rs/wasm-runtime/dist/fs.qwik.mjs +0 -14854
  33. package/lib/node_modules/.pnpm/@napi-rs_wasm-runtime@1.1.1/node_modules/@napi-rs/wasm-runtime/fs-proxy.qwik.mjs +0 -109
  34. package/lib/node_modules/.pnpm/@napi-rs_wasm-runtime@1.1.1/node_modules/@napi-rs/wasm-runtime/runtime.qwik.mjs +0 -4
  35. package/lib/node_modules/.pnpm/@qwik.dev_core@2.0.0-beta.15_vite@7.1.5_@types_node@24.9.0_jiti@2.6.1_lightningcss@1.30.1_ter_sl453hnfnrysgqsj6ikt4cdmnq/node_modules/@qwik.dev/core/dist/qwikloader.qwik.mjs +0 -152
  36. package/lib/node_modules/.pnpm/@rolldown_browser@1.0.0-beta.59/node_modules/@rolldown/browser/dist/index.browser.qwik.mjs +0 -13
  37. package/lib/node_modules/.pnpm/@rolldown_browser@1.0.0-beta.59/node_modules/@rolldown/browser/dist/normalize-string-or-regex-BB1FWNyl.qwik.mjs +0 -789
  38. package/lib/node_modules/.pnpm/@rolldown_browser@1.0.0-beta.59/node_modules/@rolldown/browser/dist/rolldown-binding.wasi-browser.qwik.mjs +0 -107
  39. package/lib/node_modules/.pnpm/@rolldown_browser@1.0.0-beta.59/node_modules/@rolldown/browser/dist/rolldown-build-Bfw5c2c3.qwik.mjs +0 -4157
  40. package/lib/node_modules/.pnpm/@tybys_wasm-util@0.10.1/node_modules/@tybys/wasm-util/dist/wasm-util.esm-bundler.qwik.mjs +0 -1968
  41. package/lib/node_modules/.pnpm/magic-regexp@0.10.0/node_modules/magic-regexp/dist/index.qwik.mjs +0 -10
  42. package/lib/node_modules/.pnpm/magic-regexp@0.10.0/node_modules/magic-regexp/dist/shared/magic-regexp.DKp_q_HX.qwik.mjs +0 -95
  43. package/lib/node_modules/.pnpm/tslib@2.8.1/node_modules/tslib/tslib.es6.qwik.mjs +0 -34
package/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # @qds.dev/code
2
+
3
+ **Interactive code previews and playgrounds for Qwik**
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@qds.dev/code.svg)](https://www.npmjs.com/package/@qds.dev/code)
6
+
7
+ ## Overview
8
+
9
+ Documentation with static code examples is hard to learn from. You want to experiment, modify, and see results immediately, but building a live code playground is complex. You need sandboxed execution, bundling, and preview rendering.
10
+
11
+ **@qds.dev/code** provides a PreviewCompiler class that bundles and executes Qwik code in the browser. Powered by Rolldown WASM for fast bundling, your users can compile code and see instant results without any server setup.
12
+
13
+ **What makes this different:** Incremental builds. WASM-based bundling for instant feedback. No remote compilation, no cold starts, no server costs.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @qds.dev/code
19
+ ```
20
+
21
+ **Note:** Typically used in documentation sites, not application code. The WASM bundler adds significant weight (~2MB+). It's recommended to only show the component preview when the user has made the intent they would like to edit code or view a preview.
22
+
23
+ ## Quick Start
24
+
25
+ **Simplest case:** Compile and run code
26
+
27
+ ```typescript
28
+ import { PreviewCompiler } from '@qds.dev/code/preview';
29
+ import { component$ } from '@qwik.dev/core';
30
+
31
+ export default component$(() => {
32
+ const compiler = new PreviewCompiler({
33
+ deps: {
34
+ '@qwik.dev/core': './path-to-core-module'
35
+ }
36
+ });
37
+
38
+ const result = await compiler.compile({
39
+ srcInputs: {
40
+ '/src/app.tsx': `export default component$(() => {
41
+ return <button>Click me</button>;
42
+ });`
43
+ }
44
+ });
45
+
46
+ return <div>{/* Render result */}</div>;
47
+ });
48
+ ```
49
+
50
+ **Common pattern:** Browser-based bundling
51
+
52
+ ```typescript
53
+ import { PreviewCompiler } from '@qds.dev/code/preview';
54
+
55
+ export default component$(() => {
56
+ const compiler = new PreviewCompiler({
57
+ deps: {
58
+ '@qwik.dev/core': './path-to-core-module'
59
+ }
60
+ });
61
+
62
+ const compile$ = $(async (code: string) => {
63
+ return await compiler.compile({
64
+ srcInputs: { '/src/app.tsx': code }
65
+ });
66
+ });
67
+
68
+ return <div>{/* Use compile$ for interactive editing */}</div>;
69
+ });
70
+ ```
71
+
72
+ ## Architecture
73
+
74
+ For package internals, dependency relationships, and design decisions, see [ARCHITECTURE.md](./ARCHITECTURE.md).
75
+
76
+ ## API
77
+
78
+ | Export | Purpose |
79
+ |--------|---------|
80
+ | `.` | debug function for development logging |
81
+ | `./preview` | PreviewCompiler class and compilation utilities |
82
+ | `./preview/node` | Server-side helpers for REPL |
83
+
84
+ ## Why This Pattern?
85
+
86
+ **Browser-based bundling:** We use Rolldown WASM instead of server-side compilation because it eliminates network latency and server costs. Your users get instant feedback. No waiting for compilation, no server to configure or maintain.
87
+
88
+ **Component isolation:** Previews run in sandboxed iframes, isolated from your main application. This prevents code in previews from affecting your documentation site's state or styles. Users can experiment freely without breaking anything.
89
+
90
+ ## Related Packages
91
+
92
+ **Depends on:**
93
+ - [@rolldown/browser](https://www.npmjs.com/package/@rolldown/browser) - WASM bundler for in-browser compilation
94
+
95
+ **Used by:**
96
+ - QDS documentation site - Powers all interactive code examples
97
+
98
+ ## Known Limitations
99
+
100
+ - **Bundle size:** The WASM bundler adds significant weight (~2MB+ for Rolldown). This package is designed for documentation sites where rich interactivity justifies the cost, not for production applications.
101
+ - **Documentation only:** Not intended for production apps. The bundle size and browser-based compilation are optimized for learning environments.
102
+ - **Modern browsers:** Requires WebAssembly and modern JavaScript features (ES2020+). Won't work in IE11 or older browsers.
@@ -0,0 +1 @@
1
+ export declare function debug(...args: unknown[]): void;
@@ -0,0 +1,2 @@
1
+ export * from "./debug";
2
+ export * from "./preview";
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Shared configuration for bundled Qwik dependencies.
3
+ * This defines which files from @qwik.dev/core should be bundled.
4
+ *
5
+ * Both the library (using ?inline-asset) and docs (using ?no-transform)
6
+ * use this same configuration to ensure consistency.
7
+ */
8
+ import type { PkgUrls } from "../types";
9
+ export declare const QWIK_PKG_NAME = "@qwik.dev/core";
10
+ /**
11
+ * List of file paths within @qwik.dev/core that need to be bundled
12
+ */
13
+ export declare const BUNDLED_FILE_PATHS: readonly ["/dist/build/index.d.ts", "/dist/core.d.ts", "/dist/core.min.mjs", "/dist/core.mjs", "/dist/optimizer.mjs", "/dist/server.mjs", "/dist/server.d.ts", "/dist/preloader.mjs", "/dist/qwikloader.js", "/bindings/qwik.wasm.mjs", "/bindings/qwik_wasm_bg.wasm", "/handlers.mjs"];
14
+ /**
15
+ * Map of internal path aliases to actual file paths
16
+ * Some internal references use core.d.ts but the actual file is core-internal.d.ts
17
+ */
18
+ export declare const FILE_PATH_ALIASES: Record<string, string>;
19
+ /**
20
+ * Get the actual file path to import, considering aliases
21
+ */
22
+ export declare function getImportPath(path: string): string;
23
+ /**
24
+ * Helper to create a bundled object from imported assets.
25
+ * This ensures both files use the same structure without duplication.
26
+ *
27
+ * The imports array must be in the same order as BUNDLED_FILE_PATHS.
28
+ *
29
+ * @param imports - Array of imported content (string URLs or inline content) in BUNDLED_FILE_PATHS order
30
+ * @param version - The Qwik version
31
+ * @returns A properly structured PkgUrls object
32
+ */
33
+ export declare function createBundledConfig(imports: readonly string[], version: string): PkgUrls;
@@ -0,0 +1,3 @@
1
+ import type { PkgUrls } from "../types";
2
+ export declare const bundled: PkgUrls;
3
+ export declare const getDeps: () => PkgUrls;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,34 @@
1
+ /** Bundler that manages WebWorkers */
2
+ import type { PkgUrls, PreviewInputOptions, PreviewResult } from "../types";
3
+ import type { OutgoingMessage } from "./repl-bundler-worker";
4
+ declare class Bundler {
5
+ worker: Worker | null;
6
+ private initP;
7
+ private ready;
8
+ private deps;
9
+ private qwikWasm?;
10
+ private timer;
11
+ buildPromises: Map<number, {
12
+ resolve: (value: PreviewResult) => void;
13
+ reject: (reason?: any) => void;
14
+ }>;
15
+ nextBuildId: number;
16
+ constructor(deps: PkgUrls, qwikWasm?: WebAssembly.Module);
17
+ initWorker(): void;
18
+ messageHandler: (e: MessageEvent<OutgoingMessage>) => void;
19
+ keepAlive(): void;
20
+ bundle(options: Omit<PreviewInputOptions, "version" | "serverUrl">): Promise<PreviewResult>;
21
+ terminateWorker(): void;
22
+ private _ssrWorker;
23
+ private _ssrWorkerP;
24
+ private _ssrKey;
25
+ private _resultResolver;
26
+ private getSsrWorker;
27
+ executeSSR(result: PreviewResult): Promise<{
28
+ html: string;
29
+ events?: any[];
30
+ }>;
31
+ hasQwikWasm(): boolean;
32
+ }
33
+ export declare const getBundler: (deps?: PkgUrls, qwikWasm?: WebAssembly.Module) => Bundler;
34
+ export {};
@@ -0,0 +1,30 @@
1
+ import type { PkgUrls, ReplInputOptions, ReplResult } from "../types";
2
+ interface MessageBase {
3
+ type: string;
4
+ }
5
+ export interface InitMessage extends MessageBase {
6
+ type: "init";
7
+ deps: PkgUrls;
8
+ qwikWasm?: WebAssembly.Module;
9
+ }
10
+ export interface BundleMessage extends MessageBase {
11
+ type: "bundle";
12
+ buildId: number;
13
+ data: Omit<ReplInputOptions, "version" | "serverUrl">;
14
+ }
15
+ export interface ReadyMessage extends MessageBase {
16
+ type: "ready";
17
+ }
18
+ export interface ResultMessage extends MessageBase {
19
+ type: "result";
20
+ buildId: number;
21
+ result: ReplResult;
22
+ }
23
+ export interface ErrorMessage extends MessageBase {
24
+ type: "error";
25
+ buildId: number;
26
+ error: string;
27
+ stack?: string;
28
+ }
29
+ export type OutgoingMessage = ReadyMessage | ResultMessage | ErrorMessage;
30
+ export {};
@@ -0,0 +1,27 @@
1
+ import type { QwikManifest } from "@qwik.dev/core/optimizer";
2
+ import type { PreviewEvent } from "../types";
3
+ interface MessageBase {
4
+ type: string;
5
+ }
6
+ export interface InitSSRMessage extends MessageBase {
7
+ type: "run-ssr";
8
+ replId: string;
9
+ entry: string;
10
+ baseUrl: string;
11
+ manifest: QwikManifest | undefined;
12
+ }
13
+ export interface SSRReadyMessage extends MessageBase {
14
+ type: "ready";
15
+ }
16
+ export interface SSRResultMessage extends MessageBase {
17
+ type: "ssr-result";
18
+ html: string;
19
+ events: PreviewEvent[];
20
+ }
21
+ export interface SSRErrorMessage extends MessageBase {
22
+ type: "ssr-error";
23
+ error: string;
24
+ stack?: string;
25
+ }
26
+ export type OutgoingMessage = SSRReadyMessage | SSRResultMessage | SSRErrorMessage;
27
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { Plugin } from "@rolldown/browser";
2
+ import type { PkgUrls, PreviewInputOptions } from "../types";
3
+ export declare const definesPlugin: (defines: Record<string, string>) => Plugin;
4
+ export declare const replResolver: (deps: PkgUrls, options: Pick<PreviewInputOptions, "srcInputs" | "buildMode">, target: "client" | "ssr") => Plugin;
5
+ export declare const replCss: (options: Pick<PreviewInputOptions, "srcInputs">) => Plugin;
@@ -0,0 +1,5 @@
1
+ export declare const QWIK_PKG_NAME = "@qwik.dev/core";
2
+ export declare const PREVIEW_CONFIG: {
3
+ serviceWorkerPath: string;
4
+ scope: string;
5
+ };
@@ -0,0 +1,19 @@
1
+ import type { PkgUrls, PreviewInputOptions, PreviewResult } from "./types";
2
+ export * from "./bundler";
3
+ export { BUNDLED_FILE_PATHS, createBundledConfig, FILE_PATH_ALIASES, getImportPath, QWIK_PKG_NAME } from "./bundler/bundled-config";
4
+ export * from "./constants";
5
+ export * from "./repl-helpers";
6
+ export * from "./register-preview-sw";
7
+ export type { PkgUrls, PreviewInputOptions, PreviewInputOptions as ReplInputOptions, PreviewModuleInput, PreviewModuleInput as ReplModuleInput, PreviewModuleOutput, PreviewModuleOutput as ReplModuleOutput, PreviewResult, PreviewResult as ReplResult } from "./types";
8
+ export * from "./types";
9
+ export interface PreviewCompilerOptions extends Partial<PreviewInputOptions> {
10
+ /** Qwik dependency URLs - must be provided by consuming app */
11
+ deps: PkgUrls;
12
+ }
13
+ export declare class PreviewCompiler {
14
+ options: PreviewCompilerOptions;
15
+ private bundler;
16
+ constructor(options: PreviewCompilerOptions);
17
+ compile(input: Partial<PreviewInputOptions>): Promise<PreviewResult>;
18
+ }
19
+ export { PreviewCompiler as ReplCompiler };
@@ -0,0 +1,2 @@
1
+ export declare const handlers: import("msw").HttpHandler[];
2
+ export declare const worker: import("msw/browser").SetupWorker;
@@ -0,0 +1,20 @@
1
+ export type RequestMessage = {
2
+ type: "preview-request";
3
+ requestId: number;
4
+ previewId: string;
5
+ url: string;
6
+ };
7
+ export type ResponseMessage = {
8
+ type: "preview-response";
9
+ requestId: number;
10
+ response: {
11
+ status: number;
12
+ statusText: string;
13
+ headers: Record<string, string>;
14
+ body: string;
15
+ } | null;
16
+ };
17
+ type SendPreviewMessage = (msg: RequestMessage) => void;
18
+ /** Intercept requests for `/repl/[id]/*` and request them over the broadcast channel */
19
+ export declare const handleFetch: (ev: FetchEvent, selfOrigin: string, sendMessage: SendPreviewMessage) => void;
20
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare const registerReplSW: () => Promise<ServiceWorkerRegistration | null>;
2
+ export declare const _resetPromise: () => void;
@@ -0,0 +1 @@
1
+ export declare const ReplEditor: import("@qwik.dev/core").Component<unknown>;
@@ -0,0 +1,4 @@
1
+ export interface CopyReplAssetsOptions {
2
+ publicDir: string;
3
+ }
4
+ export declare const copyReplAssets: ({ publicDir }: CopyReplAssetsOptions) => Promise<void>;
@@ -0,0 +1,16 @@
1
+ import type { Plugin } from "vite";
2
+ export type ReplWorkerMode = "dev" | "preview";
3
+ export interface ReplWorkerUrlOptions {
4
+ mode: ReplWorkerMode;
5
+ scopePrefix?: string;
6
+ }
7
+ export declare const getReplWorkerUrls: ({ mode, scopePrefix }: ReplWorkerUrlOptions) => {
8
+ bundler: string;
9
+ ssr: string;
10
+ };
11
+ export interface ReplVitePluginOptions {
12
+ serviceWorkerScope?: string;
13
+ assetsInlineLimit?: number;
14
+ optimizeDepsExclude?: string[];
15
+ }
16
+ export declare const getReplVitePlugin: (options?: ReplVitePluginOptions) => Plugin;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Extended test with MSW worker fixture.
3
+ * - Starts MSW before each test
4
+ * - Exposes `worker` in test context for adding handlers
5
+ * - Resets handlers after each test
6
+ */
7
+ export declare const test: import("vitest").TestAPI<{
8
+ worker: import("msw/browser").SetupWorker;
9
+ }>;
@@ -0,0 +1,70 @@
1
+ import type { Signal } from "@qwik.dev/core";
2
+ import type { Diagnostic, QwikManifest, QwikRollupPluginOptions, TransformModule } from "@qwik.dev/core/optimizer";
3
+ export interface PreviewAppInput {
4
+ files: PreviewModuleInput[];
5
+ version: string;
6
+ buildMode: "development" | "production";
7
+ entryStrategy: string;
8
+ debug?: boolean;
9
+ }
10
+ export type PkgUrls = {
11
+ [pkgName: string]: {
12
+ [path: string]: string;
13
+ version: string;
14
+ };
15
+ };
16
+ export interface PreviewInputOptions extends Omit<QwikRollupPluginOptions, "srcDir"> {
17
+ replId: string;
18
+ srcInputs: PreviewModuleInput[];
19
+ version: string;
20
+ buildMode: "development" | "production";
21
+ debug?: boolean;
22
+ qwikWasm?: WebAssembly.Module;
23
+ }
24
+ export interface PreviewModuleInput {
25
+ path: string;
26
+ code: string;
27
+ hidden?: boolean;
28
+ }
29
+ export interface PreviewModuleOutput {
30
+ path: string;
31
+ code: string;
32
+ size?: string;
33
+ shorten?: Signal<boolean>;
34
+ }
35
+ export interface PreviewEvent {
36
+ start: number;
37
+ end?: number;
38
+ kind: "console-log" | "console-debug" | "console-warn" | "console-error" | "symbol" | "pause" | "resume" | "client-module" | "prefetch";
39
+ scope: "ssr" | "client" | "build" | "network";
40
+ message: string[];
41
+ element?: Element;
42
+ }
43
+ export interface PreviewResult {
44
+ buildId: number;
45
+ replId: string;
46
+ html: string;
47
+ transformedModules: TransformModule[];
48
+ clientBundles: PreviewModuleOutput[];
49
+ ssrModules: PreviewModuleOutput[];
50
+ manifest: QwikManifest | undefined;
51
+ diagnostics: Diagnostic[];
52
+ events: PreviewEvent[];
53
+ }
54
+ export type SSROutgoingMessage = {
55
+ type: "ready";
56
+ } | {
57
+ type: "ssr-result";
58
+ html: string;
59
+ events: any[];
60
+ } | {
61
+ type: "ssr-error";
62
+ error: string;
63
+ stack?: string;
64
+ };
65
+ export type ReplAppInput = PreviewAppInput;
66
+ export type ReplInputOptions = PreviewInputOptions;
67
+ export type ReplModuleInput = PreviewModuleInput;
68
+ export type ReplModuleOutput = PreviewModuleOutput;
69
+ export type ReplEvent = PreviewEvent;
70
+ export type ReplResult = PreviewResult;