-
Notifications
You must be signed in to change notification settings - Fork 755
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support non-default build conditions via the WRANGLER_BUILD_COND…
…ITIONS flag (#6743) * fix: support non-default build conditions via the WRANGLER_BUILD_CONDITIONS flag Fixes #6742 * fixup! fix: support non-default build conditions via the WRANGLER_BUILD_CONDITIONS flag * fixup! fix: support non-default build conditions via the WRANGLER_BUILD_CONDITIONS flag * fixup! fix: support non-default build conditions via the WRANGLER_BUILD_CONDITIONS flag * fixup! fix: support non-default build conditions via the WRANGLER_BUILD_CONDITIONS flag
- Loading branch information
1 parent
7e0d83d
commit b45e326
Showing
10 changed files
with
186 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
fix: ability to build tricky Node.js compat scenario Workers | ||
|
||
Adds support for non-default build conditions and platform via the WRANGLER_BUILD_CONDITIONS and WRANGLER_BUILD_PLATFORM flags. | ||
|
||
Fixes https://github.com/cloudflare/workers-sdk/issues/6742 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// This entry point should only be used if no other build condition match. | ||
export function randomBytes(length) { | ||
return new Uint8Array([8, 9, 10, 11, 12, 13]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// This entry point should only be used if the build condition contains `other`. | ||
export function randomBytes(length) { | ||
return new Uint8Array([1, 2, 3, 4, 5, 6]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { execFileSync } from "child_process"; | ||
import { mkdtempSync, readFileSync } from "fs"; | ||
import { tmpdir } from "os"; | ||
import { join, resolve } from "path"; | ||
import { beforeEach, describe, it } from "vitest"; | ||
import { wranglerEntryPath } from "../../shared/src/run-wrangler-long-lived"; | ||
|
||
describe("'wrangler dev' with WRANGLER_BUILD_CONDITIONS", () => { | ||
let tempDir: string; | ||
|
||
beforeEach(() => { | ||
tempDir = mkdtempSync(join(tmpdir(), "c3-wrangler-init--from-dash-")); | ||
}); | ||
|
||
it("should import from the `other` package export if that is in the conditions", async ({ | ||
expect, | ||
}) => { | ||
execFileSync( | ||
"node", | ||
[wranglerEntryPath, "deploy", "--dry-run", `--outdir=${tempDir}`], | ||
{ | ||
env: { | ||
...process.env, | ||
WRANGLER_BUILD_CONDITIONS: "other,node,browser", | ||
}, | ||
} | ||
); | ||
expect(readFileSync(resolve(tempDir, "index.js"), "utf8")).toContain( | ||
"isomorphic-random-example/src/other.js" | ||
); | ||
}); | ||
|
||
it("should import from the `default` package export if the conditions are explicitly empty", async ({ | ||
expect, | ||
}) => { | ||
execFileSync( | ||
"node", | ||
[wranglerEntryPath, "deploy", "--dry-run", `--outdir=${tempDir}`], | ||
{ | ||
env: { | ||
...process.env, | ||
WRANGLER_BUILD_CONDITIONS: "", | ||
}, | ||
} | ||
); | ||
expect(readFileSync(resolve(tempDir, "index.js"), "utf8")).toContain( | ||
"isomorphic-random-example/src/default.js" | ||
); | ||
}); | ||
}); | ||
|
||
describe("'wrangler build' with WRANGLER_BUILD_PLATFORM", () => { | ||
it("should import from node imports if platform is set to 'node'", ({ | ||
expect, | ||
}) => { | ||
execFileSync( | ||
"node", | ||
[wranglerEntryPath, "deploy", "--dry-run", "--outdir=dist/node"], | ||
{ | ||
env: { | ||
...process.env, | ||
WRANGLER_BUILD_PLATFORM: "node", | ||
}, | ||
} | ||
); | ||
expect( | ||
readFileSync(resolve(__dirname, "../dist/node/index.js"), "utf8") | ||
).toContain("isomorphic-random-example/src/node.js"); | ||
}); | ||
|
||
it("should import from node imports if platform is set to 'browser'", ({ | ||
expect, | ||
}) => { | ||
execFileSync( | ||
"node", | ||
[wranglerEntryPath, "deploy", "--dry-run", "--outdir=dist/browser"], | ||
{ | ||
env: { | ||
...process.env, | ||
WRANGLER_BUILD_PLATFORM: "browser", | ||
}, | ||
} | ||
); | ||
expect( | ||
readFileSync(resolve(__dirname, "../dist/browser/index.js"), "utf8") | ||
).toContain("../isomorphic-random-example/src/workerd.mjs"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters