-
Notifications
You must be signed in to change notification settings - Fork 711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C3-workers-assets-experimental-templates #6678
Changes from all commits
15af87d
115adbb
27dc0a0
cb2626a
7dab93d
da5aa7b
68cfb80
907cdac
210ada4
59a59ca
343416f
bf1267f
e08ec14
47fe082
ce46e04
7ac13a6
1ab2c79
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"create-cloudflare": patch | ||
--- | ||
|
||
fix: do not crash if the chosen framework does not exist |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"create-cloudflare": minor | ||
--- | ||
|
||
feat: add experimental mode and associated workers + assets templates |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,22 @@ | ||
import { frameworkCliMap } from "../src/frameworks/package.json"; | ||
import { getFrameworkMap } from "../src/templates"; | ||
|
||
let targetFramework = undefined; | ||
|
||
const envCliToTest = process.env.FRAMEWORK_CLI_TO_TEST; | ||
/** | ||
* Get the name of the framework to test or undefined if not focussing on a single framework. | ||
*/ | ||
export function getFrameworkToTest({ experimental = false }) { | ||
const envCliToTest = process.env.FRAMEWORK_CLI_TO_TEST; | ||
if (!envCliToTest) { | ||
return undefined; | ||
} | ||
|
||
if (envCliToTest) { | ||
for (const [framework, cli] of Object.entries(frameworkCliMap)) { | ||
if (cli === envCliToTest) { | ||
targetFramework = framework; | ||
const frameworks = getFrameworkMap({ experimental }); | ||
for (const [framework, { frameworkCli }] of Object.entries(frameworks)) { | ||
if (frameworkCli === envCliToTest) { | ||
return framework; | ||
} | ||
} | ||
if (!targetFramework) { | ||
throw new Error( | ||
`Specified cli doesn't exist in framework map: ${envCliToTest}`, | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* In case the e2e run is supposed to only test a single framework | ||
* the framework's name is set as the value of this variable, for standard | ||
* runs this variable's value is `undefined` | ||
*/ | ||
export const frameworkToTest = targetFramework; | ||
throw new Error( | ||
`Specified cli doesn't exist in framework map: ${envCliToTest}`, | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { crash, startSection, updateStatus } from "@cloudflare/cli"; | ||
import { processArgument } from "@cloudflare/cli/args"; | ||
import { blue, brandColor, dim } from "@cloudflare/cli/colors"; | ||
import TOML from "@iarna/toml"; | ||
import { C3_DEFAULTS, openInBrowser } from "helpers/cli"; | ||
import { quoteShellArgs, runCommand } from "helpers/command"; | ||
import { detectPackageManager } from "helpers/packageManagers"; | ||
|
@@ -67,12 +68,11 @@ const isDeployable = async (ctx: C3Context) => { | |
return true; | ||
} | ||
|
||
const wranglerToml = readWranglerToml(ctx); | ||
if (wranglerToml.match(/(?<!#\s*)bindings?\s*=.*/m)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This approach was too simplistic because it also blocked Workers that have assets bindings, which can be deployed straight up. |
||
return false; | ||
} | ||
const wranglerTomlStr = readWranglerToml(ctx); | ||
|
||
return true; | ||
const wranglerToml = TOML.parse(wranglerTomlStr.replace(/\r\n/g, "\n")); | ||
|
||
return !hasBinding(wranglerToml); | ||
}; | ||
|
||
export const runDeploy = async (ctx: C3Context) => { | ||
|
@@ -139,3 +139,23 @@ export const maybeOpenBrowser = async (ctx: C3Context) => { | |
} | ||
} | ||
}; | ||
|
||
/** | ||
* Recursively search the properties of node for a binding. | ||
*/ | ||
export const hasBinding = (node: unknown): boolean => { | ||
if (typeof node !== "object" || node === null) { | ||
return false; | ||
} | ||
for (const key of Object.keys(node)) { | ||
if (key === "experimental_assets" || key === "assets") { | ||
// Properties called "binding" within "assets" do not count as bindings. | ||
continue; | ||
} | ||
if (key === "binding" || key === "bindings") { | ||
return true; | ||
} | ||
return hasBinding(node[key as keyof typeof node]); | ||
} | ||
return false; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,20 +3,17 @@ import { dim } from "@cloudflare/cli/colors"; | |
import { quoteShellArgs, runCommand } from "helpers/command"; | ||
import { detectPackageManager } from "helpers/packageManagers"; | ||
import { isInsideGitRepo } from "../git"; | ||
import clisPackageJson from "./package.json"; | ||
import frameworksPackageJson from "./package.json"; | ||
import type { C3Context } from "types"; | ||
|
||
export const getFrameworkCli = (ctx: C3Context, withVersion = true) => { | ||
if (!ctx.template) { | ||
return crash("Framework not specified."); | ||
} | ||
|
||
const framework = ctx.template | ||
.id as keyof typeof clisPackageJson.frameworkCliMap; | ||
const frameworkCli = clisPackageJson.frameworkCliMap[ | ||
framework | ||
] as keyof typeof clisPackageJson.dependencies; | ||
const version = clisPackageJson.dependencies[frameworkCli]; | ||
const frameworkCli = ctx.template | ||
.frameworkCli as keyof typeof frameworksPackageJson.dependencies; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The source of truth for mapping between frameworks and their CLI has moved to the |
||
const version = frameworksPackageJson.dependencies[frameworkCli]; | ||
return withVersion ? `${frameworkCli}@${version}` : frameworkCli; | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "../../tsconfig.json" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is needed so that VS Code (eslint) knows that the TS files in this folder are configured by TypeScript. The package.json in this directory makes eslint think this is a separate TS project. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arguably Durable Objects can be deployed if they have migrations setup.
But the previous state of affairs didn't support that, so it is out of scope for this PR to change that.