Skip to content

Commit a48ed51

Browse files
authored
Merge branch 'main' into feature/d1-export-multiple-tables
2 parents 5b1990f + cd16fdb commit a48ed51

File tree

11 files changed

+132
-109
lines changed

11 files changed

+132
-109
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Strip query strings from module names before writing to disk
6+
7+
When bundling modules with query string suffixes (e.g. `.wasm?module`), the `?` character was included in the output filename. Since `?` is not a valid filename character on Windows, this caused an ENOENT error during `wrangler dev`. This was particularly visible when using Prisma Client with the D1 adapter, which imports `.wasm?module` files.
8+
9+
The fix strips query strings from module names before writing them to disk, while preserving correct module resolution.

.changeset/late-humans-win.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@cloudflare/local-explorer-ui": patch
3+
"miniflare": patch
4+
---
5+
6+
Update `@hey-api/openapi-ts` to ^0.94.0

packages/create-cloudflare/e2e/tests/frameworks/test-config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ function getFrameworkTestConfig(pm: string): NamedFrameworkTestConfig[] {
4848
{
4949
name: "astro:pages",
5050
argv: ["--platform", "pages"],
51+
quarantine: true,
5152
testCommitMessage: true,
5253
unsupportedOSs: ["win32"],
5354
verifyDeploy: {
@@ -65,6 +66,7 @@ function getFrameworkTestConfig(pm: string): NamedFrameworkTestConfig[] {
6566
{
6667
name: "astro:workers",
6768
argv: ["--platform", "workers"],
69+
quarantine: true,
6870
testCommitMessage: true,
6971
unsupportedOSs: ["win32"],
7072
verifyDeploy: {
@@ -720,6 +722,7 @@ function getExperimentalFrameworkTestConfig(
720722
{
721723
name: "astro:workers",
722724
argv: ["--platform", "workers"],
725+
quarantine: true,
723726
testCommitMessage: true,
724727
unsupportedOSs: ["win32"],
725728
verifyDeploy: {

packages/local-explorer-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"devDependencies": {
4545
"@cloudflare/eslint-config-shared": "workspace:*",
4646
"@cloudflare/workers-tsconfig": "workspace:*",
47-
"@hey-api/openapi-ts": "^0.91.1",
47+
"@hey-api/openapi-ts": "catalog:default",
4848
"@tanstack/react-router-devtools": "^1.158.0",
4949
"@tanstack/router-plugin": "^1.158.0",
5050
"@types/react": "^19.2.0",

packages/miniflare/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"@cloudflare/workers-types": "catalog:default",
6565
"@cloudflare/workers-utils": "workspace:*",
6666
"@cloudflare/workflows-shared": "workspace:*",
67-
"@hey-api/openapi-ts": "^0.90.0",
67+
"@hey-api/openapi-ts": "catalog:default",
6868
"@microsoft/api-extractor": "^7.52.8",
6969
"@puppeteer/browsers": "^2.10.6",
7070
"@types/debug": "^4.1.7",

packages/workers-utils/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"build": "tsup",
3333
"check:lint": "eslint . --max-warnings=0 --cache",
3434
"check:type": "tsc -p ./tsconfig.json",
35+
"deploy": "echo 'no deploy'",
3536
"dev": "concurrently -c black,blue --kill-others-on-fail false \"pnpm tsup --watch src\" \"pnpm run check:type --watch --preserveWatchOutput\"",
3637
"test": "vitest",
3738
"test:ci": "vitest run",

packages/wrangler/src/__tests__/deploy/formats.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,47 @@ describe("deploy", () => {
344344
expect(std.warn).toMatchInlineSnapshot(`""`);
345345
});
346346

347+
it("should strip query string suffixes from module names (esm)", async () => {
348+
writeWranglerConfig();
349+
fs.writeFileSync(
350+
"./index.js",
351+
`import hello from './hello.wasm?module'; export default {};`
352+
);
353+
fs.writeFileSync("./hello.wasm", "SOME WASM CONTENT");
354+
mockSubDomainRequest();
355+
mockUploadWorkerRequest({
356+
expectedType: "esm",
357+
expectedBindings: [],
358+
expectedModules: {
359+
"./94b240d0d692281e6467aa42043986e5c7eea034-hello.wasm":
360+
"SOME WASM CONTENT",
361+
},
362+
});
363+
await runWrangler("deploy index.js");
364+
expect(std.err).toMatchInlineSnapshot(`""`);
365+
});
366+
367+
it("should strip query string suffixes from module names with preserve_file_names (esm)", async () => {
368+
writeWranglerConfig({
369+
preserve_file_names: true,
370+
});
371+
fs.writeFileSync(
372+
"./index.js",
373+
`import hello from './hello.wasm?module'; export default {};`
374+
);
375+
fs.writeFileSync("./hello.wasm", "SOME WASM CONTENT");
376+
mockSubDomainRequest();
377+
mockUploadWorkerRequest({
378+
expectedType: "esm",
379+
expectedBindings: [],
380+
expectedModules: {
381+
"./hello.wasm": "SOME WASM CONTENT",
382+
},
383+
});
384+
await runWrangler("deploy index.js");
385+
expect(std.err).toMatchInlineSnapshot(`""`);
386+
});
387+
347388
describe("inject process.env.NODE_ENV", () => {
348389
beforeEach(() => {
349390
vi.stubEnv("NODE_ENV", "some-node-env");

packages/wrangler/src/deployment-bundle/module-collection.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ export const RuleTypeToModuleType: Record<ConfigModuleRuleType, CfModuleType> =
4444

4545
export const ModuleTypeToRuleType = flipObject(RuleTypeToModuleType);
4646

47+
// Strip query string suffixes (e.g. `?module`) from module paths so that
48+
// file paths and module names don't contain characters invalid on Windows.
49+
function stripQueryString(modulePath: string): string {
50+
const queryIndex = modulePath.indexOf("?");
51+
return queryIndex !== -1 ? modulePath.slice(0, queryIndex) : modulePath;
52+
}
53+
4754
// This is a combination of an esbuild plugin and a mutable array
4855
// that we use to collect module references from source code.
4956
// There will be modules that _shouldn't_ be inlined directly into
@@ -202,10 +209,11 @@ export function createModuleCollector(props: {
202209

203210
// take the file and massage it to a
204211
// transportable/manageable format
212+
const cleanedPath = stripQueryString(args.path);
205213
const filePath = path.join(
206214
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
207215
props.wrangler1xLegacyModuleReferences!.rootDirectory,
208-
args.path
216+
cleanedPath
209217
);
210218
const fileContent = (await readFile(
211219
filePath
@@ -215,8 +223,8 @@ export function createModuleCollector(props: {
215223
.update(fileContent)
216224
.digest("hex");
217225
const fileName = props.preserveFileNames
218-
? args.path
219-
: `./${fileHash}-${path.basename(args.path)}`;
226+
? cleanedPath
227+
: `./${fileHash}-${path.basename(cleanedPath)}`;
220228

221229
const { rule } =
222230
rulesMatchers.find(({ regex }) => regex.test(fileName)) || {};
@@ -257,13 +265,17 @@ export function createModuleCollector(props: {
257265
// take the file and massage it to a
258266
// transportable/manageable format
259267

260-
let filePath = path.join(args.resolveDir, args.path);
268+
// Strip query string suffixes (e.g. `?module`) from the import
269+
// path. The `?` character is not valid in filenames on Windows
270+
// and would cause ENOENT errors when writing modules to disk.
271+
const cleanedPath = stripQueryString(args.path);
272+
let filePath = path.join(args.resolveDir, cleanedPath);
261273

262274
// If this was a found additional module, mark it as external.
263275
// Note, there's no need to watch the file here as we already
264276
// watch all `foundModulePaths` with `wrangler:modules-watch`.
265277
if (foundModulePaths.includes(filePath)) {
266-
return { path: args.path, external: true };
278+
return { path: cleanedPath, external: true };
267279
}
268280
// For JavaScript module rules, we only register this onResolve
269281
// callback if `findAdditionalModules` is true. If we didn't
@@ -277,7 +289,7 @@ export function createModuleCollector(props: {
277289
// and if so, validate the import against the package.json exports
278290
// and resolve the file path to the correct file.
279291
try {
280-
const resolved = await build.resolve(args.path, {
292+
const resolved = await build.resolve(cleanedPath, {
281293
kind: args.kind,
282294
importer: args.importer,
283295
resolveDir: args.resolveDir,
@@ -295,7 +307,7 @@ export function createModuleCollector(props: {
295307

296308
// Next try to resolve using the node module resolution algorithm
297309
try {
298-
const resolved = resolveSync(args.path, {
310+
const resolved = resolveSync(cleanedPath, {
299311
basedir: args.resolveDir,
300312
});
301313
filePath = resolved;
@@ -314,8 +326,8 @@ export function createModuleCollector(props: {
314326
.update(fileContent)
315327
.digest("hex");
316328
const fileName = props.preserveFileNames
317-
? args.path
318-
: `./${fileHash}-${path.basename(args.path)}`;
329+
? cleanedPath
330+
: `./${fileHash}-${path.basename(cleanedPath)}`;
319331

320332
// add the module to the array
321333
modules.push({

0 commit comments

Comments
 (0)