chore: import upstream snapshot with attribution
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Prerelease / build (push) Has been skipped
Handle Changesets / Handle Changesets (push) Has been cancelled
Semgrep OSS scan / semgrep-oss (push) Has been cancelled
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Prerelease / build (push) Has been skipped
Handle Changesets / Handle Changesets (push) Has been cancelled
Semgrep OSS scan / semgrep-oss (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { cp } from "node:fs/promises";
|
||||
import { build, context } from "esbuild";
|
||||
import { globSync } from "tinyglobby";
|
||||
import type { BuildOptions } from "esbuild";
|
||||
|
||||
const run = async () => {
|
||||
const argv = process.argv.slice(2);
|
||||
const watchMode = argv[0] === "--watch";
|
||||
|
||||
const config: BuildOptions = {
|
||||
entryPoints: ["./src/cli.ts"],
|
||||
bundle: true,
|
||||
outdir: "./dist",
|
||||
platform: "node",
|
||||
// This is required to support jsonc-parser. See https://github.com/microsoft/node-jsonc-parser/issues/57
|
||||
mainFields: ["module", "main"],
|
||||
format: "cjs",
|
||||
define: {
|
||||
"process.env.SPARROW_SOURCE_KEY": JSON.stringify(
|
||||
process.env.SPARROW_SOURCE_KEY ?? ""
|
||||
),
|
||||
},
|
||||
};
|
||||
|
||||
const runBuild = async () => {
|
||||
await build(config);
|
||||
// npm pack doesn't include .gitignore files (see https://github.com/npm/npm/issues/3763)
|
||||
// To workaround, copy all ".gitignore" files as "__dot__gitignore" so npm pack includes them
|
||||
// The latter has been added to the project's .gitignore file
|
||||
// This renaming will be reversed when each template is used
|
||||
// We can continue to author ".gitignore" files in each template
|
||||
for (const filepath of globSync("templates*/**/.gitignore")) {
|
||||
await cp(filepath, filepath.replace(".gitignore", "__dot__gitignore"));
|
||||
}
|
||||
};
|
||||
|
||||
const runWatch = async () => {
|
||||
const ctx = await context(config);
|
||||
await ctx.watch();
|
||||
console.log("Watching...");
|
||||
};
|
||||
|
||||
if (watchMode) {
|
||||
await runWatch();
|
||||
} else {
|
||||
await runBuild();
|
||||
}
|
||||
};
|
||||
|
||||
run().catch((error) => {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -0,0 +1,68 @@
|
||||
import { fetch } from "undici";
|
||||
|
||||
type ApiSuccessBody = {
|
||||
result: unknown[];
|
||||
};
|
||||
|
||||
export type Project = {
|
||||
name: string;
|
||||
created_on: string;
|
||||
};
|
||||
|
||||
export type Worker = {
|
||||
id: string;
|
||||
created_on: string;
|
||||
};
|
||||
|
||||
const apiFetch = async (
|
||||
path: string,
|
||||
init = { method: "GET" },
|
||||
queryParams = {}
|
||||
) => {
|
||||
const baseUrl = `https://api.cloudflare.com/client/v4/accounts/${process.env.CLOUDFLARE_ACCOUNT_ID}`;
|
||||
const queryString = queryParams
|
||||
? `?${new URLSearchParams(queryParams).toString()}`
|
||||
: "";
|
||||
const url = `${baseUrl}${path}${queryString}`;
|
||||
|
||||
const response = await fetch(url, {
|
||||
...init,
|
||||
headers: {
|
||||
Authorization: `Bearer ${process.env.CLOUDFLARE_API_TOKEN}`,
|
||||
},
|
||||
});
|
||||
|
||||
if (response.status >= 400) {
|
||||
throw { url, init, response };
|
||||
}
|
||||
|
||||
const json = (await response.json()) as ApiSuccessBody;
|
||||
|
||||
return json.result;
|
||||
};
|
||||
|
||||
export const deleteProject = async (project: string) => {
|
||||
if (!process.env.CLOUDFLARE_API_TOKEN || !process.env.CLOUDFLARE_ACCOUNT_ID) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await apiFetch(`/pages/projects/${project}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
} catch {
|
||||
// Ignore errors
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteWorker = async (id: string) => {
|
||||
if (!process.env.CLOUDFLARE_API_TOKEN || !process.env.CLOUDFLARE_ACCOUNT_ID) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await apiFetch(`/workers/scripts/${id}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
} catch {
|
||||
// Ignore errors
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Dependencies that _are not_ bundled along with create-cloudflare.
|
||||
*
|
||||
* create-cloudflare bundles all of its dependencies into a single CJS file,
|
||||
* so this list is currently empty.
|
||||
*/
|
||||
export const EXTERNAL_DEPENDENCIES: string[] = [];
|
||||
|
||||
/**
|
||||
* Bare-specifier imports that legitimately appear in create-cloudflare's
|
||||
* bundled output but should NOT be treated as missing runtime dependencies.
|
||||
*/
|
||||
export const IGNORED_DIST_IMPORTS = [
|
||||
// `recast` (a bundled devDependency) attempts `require("babylon")` inside
|
||||
// a try/catch as a fallback parser when `@babel/parser` is not available.
|
||||
// We don't need to ship `babylon` because the primary `@babel/parser`
|
||||
// path is bundled and always succeeds.
|
||||
"babylon",
|
||||
];
|
||||
@@ -0,0 +1,70 @@
|
||||
import { execSync } from "node:child_process";
|
||||
import {
|
||||
isExperimental,
|
||||
testPackageManager,
|
||||
testPackageManagerVersion,
|
||||
} from "../../e2e/helpers/constants";
|
||||
|
||||
class TestRunner {
|
||||
#failed: string[] = [];
|
||||
|
||||
execTests(testFilter: "cli" | "workers" | "frameworks") {
|
||||
const description = `Testing ${testFilter}`;
|
||||
|
||||
try {
|
||||
console.log(
|
||||
`::group::${description} (${testPackageManager}${testPackageManagerVersion ? `@${testPackageManagerVersion}` : ""}${isExperimental ? " / experimental" : ""})`
|
||||
);
|
||||
execSync(
|
||||
`pnpm turbo test:e2e --log-order=stream --output-logs=new-only --summarize --filter=create-cloudflare -- ${testFilter}`,
|
||||
{
|
||||
stdio: "inherit",
|
||||
env: {
|
||||
...process.env,
|
||||
E2E_EXPERIMENTAL: `${isExperimental}`,
|
||||
E2E_TEST_PM: testPackageManager,
|
||||
E2E_TEST_PM_VERSION: testPackageManagerVersion,
|
||||
},
|
||||
}
|
||||
);
|
||||
console.log("::endgroup::");
|
||||
} catch (e) {
|
||||
if (e instanceof Error && "signal" in e && e.signal === "SIGINT") {
|
||||
process.exit(1);
|
||||
}
|
||||
console.error("Failed, moving on");
|
||||
this.#failed.push(description);
|
||||
}
|
||||
}
|
||||
|
||||
assertNoFailures() {
|
||||
if (this.#failed.length > 0) {
|
||||
throw new Error(
|
||||
"At least one task failed:" +
|
||||
this.#failed.map((group) => `\n - ${group}`)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function main() {
|
||||
const testRunner = new TestRunner();
|
||||
if (!process.env.E2E_TEST_FILTER || process.env.E2E_TEST_FILTER === "cli") {
|
||||
testRunner.execTests("cli");
|
||||
}
|
||||
if (
|
||||
!process.env.E2E_TEST_FILTER ||
|
||||
process.env.E2E_TEST_FILTER === "workers"
|
||||
) {
|
||||
testRunner.execTests("workers");
|
||||
}
|
||||
if (
|
||||
!process.env.E2E_TEST_FILTER ||
|
||||
process.env.E2E_TEST_FILTER === "frameworks"
|
||||
) {
|
||||
testRunner.execTests("frameworks");
|
||||
}
|
||||
testRunner.assertNoFailures();
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user