@ducklings/workers 1.4.3-dev.2 → 1.4.3-dev.3
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.
- package/README.md +7 -14
- package/dist/vite-plugin.d.ts +22 -23
- package/dist/vite-plugin.js +28 -9
- package/dist/vite-plugin.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -71,20 +71,19 @@ export default {
|
|
|
71
71
|
|
|
72
72
|
## Vite Plugin
|
|
73
73
|
|
|
74
|
-
For projects using Vite to build Cloudflare Workers, we provide a plugin that handles WASM file resolution and copying:
|
|
74
|
+
For projects using Vite with `@cloudflare/vite-plugin` to build Cloudflare Workers, we provide a plugin that handles WASM file resolution and copying:
|
|
75
75
|
|
|
76
76
|
```typescript
|
|
77
77
|
// vite.config.ts
|
|
78
78
|
import { defineConfig } from 'vite';
|
|
79
|
+
import { cloudflare } from '@cloudflare/vite-plugin';
|
|
79
80
|
import { ducklingsWorkerPlugin } from '@ducklings/workers/vite-plugin';
|
|
80
81
|
|
|
81
82
|
export default defineConfig({
|
|
82
|
-
plugins: [
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
},
|
|
87
|
-
},
|
|
83
|
+
plugins: [
|
|
84
|
+
ducklingsWorkerPlugin(),
|
|
85
|
+
cloudflare(),
|
|
86
|
+
],
|
|
88
87
|
});
|
|
89
88
|
```
|
|
90
89
|
|
|
@@ -92,20 +91,14 @@ export default defineConfig({
|
|
|
92
91
|
|
|
93
92
|
```typescript
|
|
94
93
|
ducklingsWorkerPlugin({
|
|
95
|
-
// Output directory for the build (default: 'dist')
|
|
96
|
-
outDir: 'dist',
|
|
97
|
-
|
|
98
94
|
// Name of the WASM file in the output directory (default: 'duckdb-workers.wasm')
|
|
99
95
|
wasmFileName: 'duckdb-workers.wasm',
|
|
100
|
-
|
|
101
|
-
// Whether to copy the WASM file to the output directory (default: true)
|
|
102
|
-
copyWasm: true,
|
|
103
96
|
})
|
|
104
97
|
```
|
|
105
98
|
|
|
106
99
|
The plugin:
|
|
107
100
|
- Resolves `@ducklings/workers/wasm` imports to a relative path for wrangler
|
|
108
|
-
-
|
|
101
|
+
- Automatically copies the WASM file to the correct output directory (works with Cloudflare vite plugin's nested output structure)
|
|
109
102
|
|
|
110
103
|
## Features
|
|
111
104
|
|
package/dist/vite-plugin.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Vite plugin for @ducklings/workers on Cloudflare Workers
|
|
3
3
|
*
|
|
4
|
-
* This plugin handles WASM file resolution and
|
|
4
|
+
* This plugin handles WASM file resolution and emission for Cloudflare Workers deployments.
|
|
5
|
+
* Designed to work with @cloudflare/vite-plugin.
|
|
5
6
|
*
|
|
6
7
|
* @packageDocumentation
|
|
7
8
|
*/
|
|
@@ -11,35 +12,30 @@
|
|
|
11
12
|
interface VitePlugin {
|
|
12
13
|
name: string;
|
|
13
14
|
enforce?: 'pre' | 'post';
|
|
14
|
-
configResolved?: (config:
|
|
15
|
-
root: string;
|
|
16
|
-
}) => void;
|
|
15
|
+
configResolved?: (config: ResolvedConfig) => void;
|
|
17
16
|
resolveId?: (id: string) => {
|
|
18
17
|
id: string;
|
|
19
18
|
external: true;
|
|
20
19
|
} | null;
|
|
21
|
-
|
|
20
|
+
writeBundle?: (options: {
|
|
21
|
+
dir?: string;
|
|
22
|
+
}, bundle: Record<string, unknown>) => void;
|
|
23
|
+
}
|
|
24
|
+
interface ResolvedConfig {
|
|
25
|
+
root: string;
|
|
26
|
+
build: {
|
|
27
|
+
outDir: string;
|
|
28
|
+
};
|
|
22
29
|
}
|
|
23
30
|
/**
|
|
24
31
|
* Configuration options for the Ducklings Workers Vite plugin.
|
|
25
32
|
*/
|
|
26
33
|
interface DucklingsWorkersPluginOptions {
|
|
27
|
-
/**
|
|
28
|
-
* Output directory for the build.
|
|
29
|
-
* @default 'dist'
|
|
30
|
-
*/
|
|
31
|
-
outDir?: string;
|
|
32
34
|
/**
|
|
33
35
|
* Name of the WASM file in the output directory.
|
|
34
36
|
* @default 'duckdb-workers.wasm'
|
|
35
37
|
*/
|
|
36
38
|
wasmFileName?: string;
|
|
37
|
-
/**
|
|
38
|
-
* Whether to copy the WASM file to the output directory.
|
|
39
|
-
* Set to false if you handle WASM file copying separately.
|
|
40
|
-
* @default true
|
|
41
|
-
*/
|
|
42
|
-
copyWasm?: boolean;
|
|
43
39
|
}
|
|
44
40
|
/**
|
|
45
41
|
* Resolves the path to the WASM file bundled with @ducklings/workers.
|
|
@@ -52,7 +48,11 @@ declare function getWasmPath(): string;
|
|
|
52
48
|
*
|
|
53
49
|
* This plugin:
|
|
54
50
|
* - Resolves `@ducklings/workers/wasm` imports to a relative path for wrangler
|
|
55
|
-
* -
|
|
51
|
+
* - Copies the WASM file to the output directory after the bundle is written
|
|
52
|
+
*
|
|
53
|
+
* Designed to work with @cloudflare/vite-plugin. The plugin detects the actual
|
|
54
|
+
* output directory structure created by the Cloudflare plugin and places the
|
|
55
|
+
* WASM file in the correct location.
|
|
56
56
|
*
|
|
57
57
|
* @param options - Plugin configuration options
|
|
58
58
|
* @returns Vite plugin
|
|
@@ -61,15 +61,14 @@ declare function getWasmPath(): string;
|
|
|
61
61
|
* ```typescript
|
|
62
62
|
* // vite.config.ts
|
|
63
63
|
* import { defineConfig } from 'vite';
|
|
64
|
+
* import { cloudflare } from '@cloudflare/vite-plugin';
|
|
64
65
|
* import { ducklingsWorkerPlugin } from '@ducklings/workers/vite-plugin';
|
|
65
66
|
*
|
|
66
67
|
* export default defineConfig({
|
|
67
|
-
* plugins: [
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* },
|
|
72
|
-
* },
|
|
68
|
+
* plugins: [
|
|
69
|
+
* ducklingsWorkerPlugin(),
|
|
70
|
+
* cloudflare(),
|
|
71
|
+
* ],
|
|
73
72
|
* });
|
|
74
73
|
* ```
|
|
75
74
|
*/
|
package/dist/vite-plugin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { dirname, resolve } from 'path';
|
|
2
|
-
import { mkdirSync, copyFileSync } from 'fs';
|
|
1
|
+
import { dirname, resolve, join } from 'path';
|
|
2
|
+
import { existsSync, readdirSync, mkdirSync, copyFileSync } from 'fs';
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
|
|
5
5
|
// Ducklings Workers - Vite Plugin for Cloudflare Workers
|
|
@@ -9,13 +9,15 @@ function getWasmPath() {
|
|
|
9
9
|
return resolve(currentDir, "wasm", "duckdb-workers.wasm");
|
|
10
10
|
}
|
|
11
11
|
function ducklingsWorkerPlugin(options = {}) {
|
|
12
|
-
const {
|
|
12
|
+
const { wasmFileName = "duckdb-workers.wasm" } = options;
|
|
13
13
|
let projectRoot;
|
|
14
|
+
let outDir;
|
|
14
15
|
return {
|
|
15
16
|
name: "ducklings-workers-plugin",
|
|
16
17
|
enforce: "pre",
|
|
17
18
|
configResolved(config) {
|
|
18
19
|
projectRoot = config.root;
|
|
20
|
+
outDir = config.build.outDir;
|
|
19
21
|
},
|
|
20
22
|
// Resolve WASM imports from the package to relative path
|
|
21
23
|
resolveId(id) {
|
|
@@ -24,15 +26,32 @@ function ducklingsWorkerPlugin(options = {}) {
|
|
|
24
26
|
}
|
|
25
27
|
return null;
|
|
26
28
|
},
|
|
27
|
-
// Copy WASM file
|
|
28
|
-
|
|
29
|
-
if (!copyWasm) return;
|
|
29
|
+
// Copy WASM file after bundle is written - handles Cloudflare plugin's nested output
|
|
30
|
+
writeBundle(options2) {
|
|
30
31
|
const wasmSrcPath = getWasmPath();
|
|
31
|
-
const
|
|
32
|
+
const baseOutDir = resolve(projectRoot, outDir);
|
|
33
|
+
let targetDir = options2.dir || baseOutDir;
|
|
34
|
+
if (options2.dir) {
|
|
35
|
+
targetDir = options2.dir;
|
|
36
|
+
} else {
|
|
37
|
+
if (existsSync(baseOutDir)) {
|
|
38
|
+
const entries = readdirSync(baseOutDir, { withFileTypes: true });
|
|
39
|
+
for (const entry of entries) {
|
|
40
|
+
if (entry.isDirectory()) {
|
|
41
|
+
const potentialIndexPath = join(baseOutDir, entry.name, "index.js");
|
|
42
|
+
if (existsSync(potentialIndexPath)) {
|
|
43
|
+
targetDir = join(baseOutDir, entry.name);
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const wasmDestPath = join(targetDir, wasmFileName);
|
|
32
51
|
try {
|
|
33
|
-
mkdirSync(
|
|
52
|
+
mkdirSync(targetDir, { recursive: true });
|
|
34
53
|
copyFileSync(wasmSrcPath, wasmDestPath);
|
|
35
|
-
console.log(`[ducklings]
|
|
54
|
+
console.log(`[ducklings] WASM file written to ${wasmDestPath}`);
|
|
36
55
|
} catch (e) {
|
|
37
56
|
console.error("[ducklings] Failed to copy WASM file:", e);
|
|
38
57
|
}
|
package/dist/vite-plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/vite-plugin/index.ts"],"names":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"sources":["../src/vite-plugin/index.ts"],"names":["options"],"mappings":";;;;;;AA+CO,SAAS,WAAA,GAAsB;AAEpC,EAAA,MAAM,UAAA,GAAa,OAAA,CAAQ,aAAA,CAAc,MAAA,CAAA,IAAA,CAAY,GAAG,CAAC,CAAA;AAEzD,EAAA,OAAO,OAAA,CAAQ,UAAA,EAAY,MAAA,EAAQ,qBAAqB,CAAA;AAC1D;AA+BO,SAAS,qBAAA,CAAsB,OAAA,GAAyC,EAAC,EAAe;AAC7F,EAAA,MAAM,EAAE,YAAA,GAAe,qBAAA,EAAsB,GAAI,OAAA;AAEjD,EAAA,IAAI,WAAA;AACJ,EAAA,IAAI,MAAA;AAEJ,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,0BAAA;AAAA,IACN,OAAA,EAAS,KAAA;AAAA,IAET,eAAe,MAAA,EAAQ;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AA,CAAU,SAAA,EAAW,EAAE,SAAA,EAAW,IAAA,EAAM,CAAA;AACxC,QAAA,YAAA,CAAa,aAAa,YAAY,CAAA;AACtC,QAAA,OAAA,CAAQ,GAAA,CAAI,CAAA,iCAAA,EAAoC,YAAY,CAAA,CAAE,CAAA;AAAA,MAChE,SAAS,CAAA,EAAG;AACV,QAAA,OAAA,CAAQ,KAAA,CAAM,yCAAyC,CAAC,CAAA;AAAA,MAC1D;AAAA,IACF;AAAA,GACF;AACF;AAEA,IAAO,mBAAA,GAAQ","file":"vite-plugin.js","sourcesContent":["/**\n * Vite plugin for @ducklings/workers on Cloudflare Workers\n *\n * This plugin handles WASM file resolution and emission for Cloudflare Workers deployments.\n * Designed to work with @cloudflare/vite-plugin.\n *\n * @packageDocumentation\n */\n\nimport { resolve, dirname, join } from 'node:path';\nimport { copyFileSync, mkdirSync, existsSync, readdirSync } from 'node:fs';\nimport { fileURLToPath } from 'node:url';\n\n/**\n * Vite Plugin interface (minimal definition to avoid hard dependency on vite types)\n */\ninterface VitePlugin {\n name: string;\n enforce?: 'pre' | 'post';\n configResolved?: (config: ResolvedConfig) => void;\n resolveId?: (id: string) => { id: string; external: true } | null;\n writeBundle?: (options: { dir?: string }, bundle: Record<string, unknown>) => void;\n}\n\ninterface ResolvedConfig {\n root: string;\n build: {\n outDir: string;\n };\n}\n\n/**\n * Configuration options for the Ducklings Workers Vite plugin.\n */\nexport interface DucklingsWorkersPluginOptions {\n /**\n * Name of the WASM file in the output directory.\n * @default 'duckdb-workers.wasm'\n */\n wasmFileName?: string;\n}\n\n/**\n * Resolves the path to the WASM file bundled with @ducklings/workers.\n *\n * @returns The absolute path to the WASM file\n */\nexport function getWasmPath(): string {\n // Get the directory of this module\n const currentDir = dirname(fileURLToPath(import.meta.url));\n // WASM file is in the wasm subdirectory relative to dist\n return resolve(currentDir, 'wasm', 'duckdb-workers.wasm');\n}\n\n/**\n * Vite plugin for Cloudflare Workers that handles Ducklings Workers WASM integration.\n *\n * This plugin:\n * - Resolves `@ducklings/workers/wasm` imports to a relative path for wrangler\n * - Copies the WASM file to the output directory after the bundle is written\n *\n * Designed to work with @cloudflare/vite-plugin. The plugin detects the actual\n * output directory structure created by the Cloudflare plugin and places the\n * WASM file in the correct location.\n *\n * @param options - Plugin configuration options\n * @returns Vite plugin\n *\n * @example\n * ```typescript\n * // vite.config.ts\n * import { defineConfig } from 'vite';\n * import { cloudflare } from '@cloudflare/vite-plugin';\n * import { ducklingsWorkerPlugin } from '@ducklings/workers/vite-plugin';\n *\n * export default defineConfig({\n * plugins: [\n * ducklingsWorkerPlugin(),\n * cloudflare(),\n * ],\n * });\n * ```\n */\nexport function ducklingsWorkerPlugin(options: DucklingsWorkersPluginOptions = {}): VitePlugin {\n const { wasmFileName = 'duckdb-workers.wasm' } = options;\n\n let projectRoot: string;\n let outDir: string;\n\n return {\n name: 'ducklings-workers-plugin',\n enforce: 'pre' as const,\n\n configResolved(config) {\n projectRoot = config.root;\n outDir = config.build.outDir;\n },\n\n // Resolve WASM imports from the package to relative path\n resolveId(id) {\n if (id === '@ducklings/workers/wasm') {\n // Return external reference that will be resolved at runtime by wrangler\n return { id: `./${wasmFileName}`, external: true as const };\n }\n return null;\n },\n\n // Copy WASM file after bundle is written - handles Cloudflare plugin's nested output\n writeBundle(options) {\n const wasmSrcPath = getWasmPath();\n const baseOutDir = resolve(projectRoot, outDir);\n\n // The Cloudflare vite plugin creates a nested structure like:\n // dist/{worker_name}/index.js\n // We need to find where index.js is and put the WASM file there\n let targetDir = options.dir || baseOutDir;\n\n // If options.dir is provided, use it directly\n if (options.dir) {\n targetDir = options.dir;\n } else {\n // Look for subdirectories that contain index.js (Cloudflare plugin structure)\n if (existsSync(baseOutDir)) {\n const entries = readdirSync(baseOutDir, { withFileTypes: true });\n for (const entry of entries) {\n if (entry.isDirectory()) {\n const potentialIndexPath = join(baseOutDir, entry.name, 'index.js');\n if (existsSync(potentialIndexPath)) {\n targetDir = join(baseOutDir, entry.name);\n break;\n }\n }\n }\n }\n }\n\n const wasmDestPath = join(targetDir, wasmFileName);\n\n try {\n mkdirSync(targetDir, { recursive: true });\n copyFileSync(wasmSrcPath, wasmDestPath);\n console.log(`[ducklings] WASM file written to ${wasmDestPath}`);\n } catch (e) {\n console.error('[ducklings] Failed to copy WASM file:', e);\n }\n },\n };\n}\n\nexport default ducklingsWorkerPlugin;\n"]}
|