Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/cuddly-shrimps-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"miniflare": patch
"wrangler": patch
---

Use built-in stripVTControlCharacters utility rather than the `strip-ansi` package.
5 changes: 5 additions & 0 deletions .changeset/long-spiders-shop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-cloudflare": patch
---

Skip modifying the root `tsconfig.json` in projects that use TypeScript project references.
1 change: 1 addition & 0 deletions .github/workflows/changeset-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ jobs:
3. **Markdown Headers**: No h1/h2/h3 headers (breaks changelog formatting)
4. **Analytics**: If the change collects more analytics, it should be a minor even though there is no user-visible change
5. **Dependabot**: Do not validate dependency update changesets for create-cloudflare
6. **Experimental features**: Changesets for experimental features should include note on how users can opt in.
If all changesets pass, just output "✅ All changesets look good" - no need for a detailed checklist.
Expand Down
1 change: 1 addition & 0 deletions fixtures/import-npm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock.json
185 changes: 0 additions & 185 deletions fixtures/import-npm/package-lock.json

This file was deleted.

1 change: 0 additions & 1 deletion fixtures/interactive-dev-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
},
"devDependencies": {
"@fixture/shared": "workspace:*",
"strip-ansi": "^7.1.0",
"undici": "catalog:default",
"vitest": "catalog:default"
},
Expand Down
8 changes: 6 additions & 2 deletions fixtures/interactive-dev-tests/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import path from "node:path";
import rl from "node:readline";
import stream from "node:stream";
import { setTimeout } from "node:timers/promises";
import stripAnsi from "strip-ansi";
import { stripVTControlCharacters } from "node:util";
import { fetch } from "undici";
import {
afterAll,
Expand Down Expand Up @@ -151,7 +151,11 @@ if (process.platform === "win32") {
if (!skipWaitingForReady) {
let readyMatch: RegExpMatchArray | null = null;
for await (const line of stdoutInterface) {
if ((readyMatch = readyRegexp.exec(stripAnsi(line))) !== null) break;
if (
(readyMatch = readyRegexp.exec(stripVTControlCharacters(line))) !==
null
)
break;
}
assert(readyMatch !== null, "Expected ready message");
result.url = readyMatch[1];
Expand Down
1 change: 0 additions & 1 deletion fixtures/worker-logs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
},
"devDependencies": {
"@cloudflare/workers-tsconfig": "workspace:^",
"strip-ansi": "^7.1.0",
"typescript": "catalog:default",
"vitest": "catalog:default",
"wrangler": "workspace:*"
Expand Down
4 changes: 2 additions & 2 deletions fixtures/worker-logs/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { stripVTControlCharacters } from "node:util";
import { resolve } from "path";
import stripAnsi from "strip-ansi";
import { describe, expect, onTestFinished, test, vi } from "vitest";
import { runWranglerDev } from "../../shared/src/run-wrangler-long-lived";

Expand Down Expand Up @@ -43,7 +43,7 @@ async function getWranglerDevOutput(
await response.text();

return () => {
const output = stripAnsi(getOutput())
const output = stripVTControlCharacters(getOutput())
// Windows gets a different marker for ✘, so let's normalize it here
// so that these tests can be platform independent
.replaceAll("✘", "X")
Expand Down
11 changes: 9 additions & 2 deletions packages/create-cloudflare/e2e/helpers/framework-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,15 @@ export async function verifyTypes(
}

const tsconfigPath = join(projectPath, "tsconfig.json");
const tsconfigTypes = jsonc.parse(readFile(tsconfigPath)).compilerOptions
?.types;
const tsconfig = jsonc.parse(readFile(tsconfigPath));

// Skip tsconfig verification if project uses TypeScript project references
// C3 doesn't modify the root tsconfig in this case - types are defined in child tsconfigs
if (Array.isArray(tsconfig.references) && tsconfig.references.length > 0) {
return;
}

const tsconfigTypes = tsconfig.compilerOptions?.types;
if (workersTypes === "generated") {
expect(tsconfigTypes).toContain(typesPath);
}
Expand Down
26 changes: 26 additions & 0 deletions packages/create-cloudflare/src/__tests__/workers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,30 @@ describe("updateTsConfig", () => {
`./worker-configuration.d.ts`,
);
});

test("skips modification when tsconfig uses project references", async () => {
vi.mocked(readFile).mockImplementation(
() => `{
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
]
}`,
);
await updateTsConfig(ctx, { usesNodeCompat: false });
expect(writeFile).not.toHaveBeenCalled();
});

test("modifies tsconfig when references array is empty", async () => {
ctx.template.workersTypes = "installed";
vi.mocked(readFile).mockImplementation(
() => `{
"compilerOptions": { "types": [] },
"references": []
}`,
);
await updateTsConfig(ctx, { usesNodeCompat: false });
expect(writeFile).toHaveBeenCalled();
});
});
17 changes: 17 additions & 0 deletions packages/create-cloudflare/src/workers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ export async function updateTsConfig(
const tsconfig = readFile(tsconfigPath);
try {
const config = jsonc.parse(tsconfig);

// Skip if tsconfig uses project references
// Types should be defined in child tsconfigs (e.g., tsconfig.worker.json)
if (hasProjectReferences(config)) {
return;
}

const currentTypes: string[] = config.compilerOptions?.types ?? [];
let newTypes = new Set(currentTypes);
if (ctx.template.workersTypes === "installed") {
Expand Down Expand Up @@ -166,6 +173,16 @@ export async function updateTsConfig(
}
}

function hasProjectReferences(config: unknown): boolean {
if (typeof config !== "object" || config === null) {
return false;
}

const tsconfig = config as Record<string, unknown>;

return Array.isArray(tsconfig.references) && tsconfig.references.length > 0;
}

/**
* TODO: delete if/when qwik move to wrangler v4
* Installs the latest version of the `@cloudflare/workers-types` package
Expand Down
20 changes: 2 additions & 18 deletions packages/miniflare/src/shared/log.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from "node:path";
import { stripVTControlCharacters } from "node:util";
import { Colorize, dim, green, grey, red, reset, yellow } from "kleur/colors";
import { LogLevel } from "../workers";

Expand Down Expand Up @@ -186,23 +187,6 @@ export class NoOpLog extends Log {
error(_message: Error): void {}
}

// Adapted from https://github.com/chalk/ansi-regex/blob/02fa893d619d3da85411acc8fd4e2eea0e95a9d9/index.js
/*!
* MIT License
*
* Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
const ansiRegexpPattern = [
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))",
].join("|");
const ansiRegexp = new RegExp(ansiRegexpPattern, "g");
export function stripAnsi(value: string) {
return value.replace(ansiRegexp, "");
return stripVTControlCharacters(value);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "node:path";
import stripAnsi from "strip-ansi";
import { stripVTControlCharacters } from "node:util";
import { afterAll, beforeAll, describe, expect, test, vi } from "vitest";
import {
resetServerLogs,
Expand All @@ -12,7 +12,7 @@ import { resolvePluginConfig } from "../../../src/plugin-config";
import { addBindingsShortcut } from "../../../src/plugins/shortcuts";

const normalize = (logs: string[]) =>
stripAnsi(logs.join("\n"))
stripVTControlCharacters(logs.join("\n"))
.split("\n")
.map((line: string) => line.trim())
.join("\n");
Expand Down
1 change: 0 additions & 1 deletion packages/vite-plugin-cloudflare/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"@cloudflare/workers-tsconfig": "workspace:*",
"playwright-chromium": "catalog:default",
"semver": "^7.7.1",
"strip-ansi": "^7.1.0",
"ts-dedent": "^2.2.0",
"typescript": "catalog:default"
}
Expand Down
Loading
Loading