@solcreek/adapter-creek 0.2.1 → 0.2.2
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/dist/bundler.d.ts +15 -0
- package/dist/bundler.js +30 -6
- package/package.json +1 -1
package/dist/bundler.d.ts
CHANGED
|
@@ -7,6 +7,21 @@
|
|
|
7
7
|
* This works with both webpack and Turbopack output — wrangler handles
|
|
8
8
|
* the custom chunk format that plain esbuild cannot follow.
|
|
9
9
|
*/
|
|
10
|
+
/**
|
|
11
|
+
* Resolve wrangler's CLI entry script through Node module resolution.
|
|
12
|
+
*
|
|
13
|
+
* Never guess `<adapterDir>/node_modules/.bin/wrangler`: npm hoists
|
|
14
|
+
* wrangler to the top of the install tree (under the Creek CLI's lazy
|
|
15
|
+
* install that's `.creek/node_modules/.bin`), so the nested path only
|
|
16
|
+
* exists when hoisting is defeated by a version conflict. Resolving
|
|
17
|
+
* `wrangler/package.json` and reading its `bin` field finds the real
|
|
18
|
+
* entry under npm hoisting, pnpm's virtual store, and link installs
|
|
19
|
+
* alike — and running it with process.execPath sidesteps `.bin` shell
|
|
20
|
+
* shims entirely (which also don't exist as POSIX scripts on Windows).
|
|
21
|
+
*
|
|
22
|
+
* Exported for tests.
|
|
23
|
+
*/
|
|
24
|
+
export declare function resolveWranglerEntry(requireFn: Pick<NodeRequire, "resolve">): Promise<string>;
|
|
10
25
|
export interface BundleOptions {
|
|
11
26
|
workerSource: string;
|
|
12
27
|
outputDir: string;
|
package/dist/bundler.js
CHANGED
|
@@ -9,8 +9,32 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import * as fs from "node:fs/promises";
|
|
11
11
|
import * as path from "node:path";
|
|
12
|
-
import {
|
|
12
|
+
import { execFileSync } from "node:child_process";
|
|
13
13
|
import { builtinModules, createRequire } from "node:module";
|
|
14
|
+
import { fileURLToPath } from "node:url";
|
|
15
|
+
/**
|
|
16
|
+
* Resolve wrangler's CLI entry script through Node module resolution.
|
|
17
|
+
*
|
|
18
|
+
* Never guess `<adapterDir>/node_modules/.bin/wrangler`: npm hoists
|
|
19
|
+
* wrangler to the top of the install tree (under the Creek CLI's lazy
|
|
20
|
+
* install that's `.creek/node_modules/.bin`), so the nested path only
|
|
21
|
+
* exists when hoisting is defeated by a version conflict. Resolving
|
|
22
|
+
* `wrangler/package.json` and reading its `bin` field finds the real
|
|
23
|
+
* entry under npm hoisting, pnpm's virtual store, and link installs
|
|
24
|
+
* alike — and running it with process.execPath sidesteps `.bin` shell
|
|
25
|
+
* shims entirely (which also don't exist as POSIX scripts on Windows).
|
|
26
|
+
*
|
|
27
|
+
* Exported for tests.
|
|
28
|
+
*/
|
|
29
|
+
export async function resolveWranglerEntry(requireFn) {
|
|
30
|
+
const pkgPath = requireFn.resolve("wrangler/package.json");
|
|
31
|
+
const pkg = JSON.parse(await fs.readFile(pkgPath, "utf-8"));
|
|
32
|
+
const binRel = typeof pkg.bin === "string" ? pkg.bin : pkg.bin?.wrangler;
|
|
33
|
+
if (!binRel) {
|
|
34
|
+
throw new Error(`wrangler package.json at ${pkgPath} has no usable bin field`);
|
|
35
|
+
}
|
|
36
|
+
return path.join(path.dirname(pkgPath), binRel);
|
|
37
|
+
}
|
|
14
38
|
/**
|
|
15
39
|
* Patch Turbopack runtime to inline chunk loading.
|
|
16
40
|
*
|
|
@@ -645,8 +669,9 @@ export async function bundleForWorkers(opts) {
|
|
|
645
669
|
const destPath = path.join(opts.outputDir, destName);
|
|
646
670
|
await fs.copyFile(absPath, destPath);
|
|
647
671
|
}
|
|
648
|
-
// Resolve adapter paths
|
|
649
|
-
|
|
672
|
+
// Resolve adapter paths. fileURLToPath, not URL#pathname — the latter
|
|
673
|
+
// yields "/C:/..." on Windows, which every alias below would inherit.
|
|
674
|
+
const adapterDir = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
|
650
675
|
// Generate wrangler config for the bundle step
|
|
651
676
|
const wranglerConfig = {
|
|
652
677
|
name: "creek-adapter-build",
|
|
@@ -778,10 +803,9 @@ export async function bundleForWorkers(opts) {
|
|
|
778
803
|
}
|
|
779
804
|
}
|
|
780
805
|
const bundleDir = path.join(opts.outputDir, "__bundle");
|
|
781
|
-
|
|
782
|
-
const wranglerBin = path.join(adapterDir, "node_modules", ".bin", "wrangler");
|
|
806
|
+
const wranglerEntry = await resolveWranglerEntry(adapterRequire);
|
|
783
807
|
try {
|
|
784
|
-
|
|
808
|
+
execFileSync(process.execPath, [wranglerEntry, "deploy", "--dry-run", "--outdir", bundleDir, "--config", configPath], {
|
|
785
809
|
cwd: path.dirname(opts.distDir),
|
|
786
810
|
stdio: "pipe",
|
|
787
811
|
env: process.env,
|