From 5b1e416de9e83204223041d04724410ea30936fe Mon Sep 17 00:00:00 2001 From: Rahul Sethi <5822355+RamIdeas@users.noreply.github.com> Date: Wed, 19 Jun 2024 19:45:02 +0100 Subject: [PATCH] rename: script to entrypoint --- .../startDevWorker/BundleController.test.ts | 14 +++++----- .../LocalRuntimeController.test.ts | 28 +++++++++---------- .../api/startDevWorker/BundlerController.ts | 24 ++++++++-------- .../wrangler/src/api/startDevWorker/types.ts | 2 +- packages/wrangler/src/dev/dev.tsx | 4 +-- packages/wrangler/src/dev/start-server.ts | 2 +- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/packages/wrangler/src/__tests__/api/startDevWorker/BundleController.test.ts b/packages/wrangler/src/__tests__/api/startDevWorker/BundleController.test.ts index b1557dbd7578..7d388504a6a2 100644 --- a/packages/wrangler/src/__tests__/api/startDevWorker/BundleController.test.ts +++ b/packages/wrangler/src/__tests__/api/startDevWorker/BundleController.test.ts @@ -67,7 +67,7 @@ describe("happy path bundle + watch", () => { }); const config: StartDevWorkerOptions = { name: "worker", - script: { path: path.resolve("src/index.ts") }, + entrypoint: { path: path.resolve("src/index.ts") }, directory: path.resolve("src"), build: { bundle: true, @@ -134,7 +134,7 @@ describe("happy path bundle + watch", () => { }); const config: StartDevWorkerOptions = { name: "worker", - script: { path: path.resolve("src/index.ts") }, + entrypoint: { path: path.resolve("src/index.ts") }, directory: path.resolve("src"), build: { bundle: true, @@ -195,7 +195,7 @@ describe("happy path bundle + watch", () => { }); const config: StartDevWorkerOptions = { name: "worker", - script: { path: path.resolve("out.ts") }, + entrypoint: { path: path.resolve("out.ts") }, directory: path.resolve("."), build: { bundle: true, @@ -265,7 +265,7 @@ describe("switching", () => { }); const config: StartDevWorkerOptions = { name: "worker", - script: { path: path.resolve("src/index.ts") }, + entrypoint: { path: path.resolve("src/index.ts") }, directory: path.resolve("src"), build: { @@ -307,7 +307,7 @@ describe("switching", () => { }); const configCustom = { name: "worker", - script: { path: path.resolve("out.ts") }, + entrypoint: { path: path.resolve("out.ts") }, directory: process.cwd(), build: { bundle: true, @@ -375,7 +375,7 @@ describe("switching", () => { }); const configCustom = { name: "worker", - script: { path: path.resolve("out.ts") }, + entrypoint: { path: path.resolve("out.ts") }, directory: process.cwd(), build: { @@ -419,7 +419,7 @@ describe("switching", () => { }); const config: StartDevWorkerOptions = { name: "worker", - script: { path: path.resolve("src/index.ts") }, + entrypoint: { path: path.resolve("src/index.ts") }, directory: path.resolve("src"), build: { diff --git a/packages/wrangler/src/__tests__/api/startDevWorker/LocalRuntimeController.test.ts b/packages/wrangler/src/__tests__/api/startDevWorker/LocalRuntimeController.test.ts index a0a9e7b4e49c..c43a76339243 100644 --- a/packages/wrangler/src/__tests__/api/startDevWorker/LocalRuntimeController.test.ts +++ b/packages/wrangler/src/__tests__/api/startDevWorker/LocalRuntimeController.test.ts @@ -125,7 +125,7 @@ describe("Core", () => { const config: StartDevWorkerOptions = { name: "worker", - script: unusable(), + entrypoint: unusable(), compatibilityFlags: ["nodejs_compat"], compatibilityDate: "2023-10-01", }; @@ -270,7 +270,7 @@ describe("Core", () => { const config: StartDevWorkerOptions = { name: "worker", - script: unusable(), + entrypoint: unusable(), }; const bundle: Bundle = { type: "commonjs", @@ -357,7 +357,7 @@ describe("Core", () => { function update(version: number) { const config: StartDevWorkerOptions = { name: "worker", - script: unusable(), + entrypoint: unusable(), bindings: { VERSION: { type: "json", value: version }, }, @@ -405,7 +405,7 @@ describe("Core", () => { const config: StartDevWorkerOptions = { name: "worker", - script: unusable(), + entrypoint: unusable(), compatibilityDate: disabledDate, }; const bundle = makeEsbuildBundle(dedent/*javascript*/ ` @@ -443,7 +443,7 @@ describe("Core", () => { const config: StartDevWorkerOptions = { name: "worker", - script: unusable(), + entrypoint: unusable(), }; const bundle = makeEsbuildBundle(dedent/*javascript*/ ` export default { @@ -502,7 +502,7 @@ describe("Bindings", () => { const config: StartDevWorkerOptions = { name: "worker", - script: unusable(), + entrypoint: unusable(), bindings: { TEXT: { type: "plain_text", value: "text" }, OBJECT: { type: "json", value: { a: { b: 1 } } }, @@ -542,7 +542,7 @@ describe("Bindings", () => { const config: StartDevWorkerOptions = { name: "worker", - script: unusable(), + entrypoint: unusable(), bindings: { // `wasm-module` bindings aren't allowed in modules workers WASM: { type: "wasm_module", source: { contents: WASM_ADD_MODULE } }, @@ -572,7 +572,7 @@ describe("Bindings", () => { const config: StartDevWorkerOptions = { name: "worker", - script: unusable(), + entrypoint: unusable(), dev: { persist: { path: persist } }, }; const bundle = makeEsbuildBundle(`export default { @@ -620,7 +620,7 @@ describe("Bindings", () => { const config: StartDevWorkerOptions = { name: "worker", - script: unusable(), + entrypoint: unusable(), bindings: { NAMESPACE: { type: "kv_namespace", id: "ns" } }, dev: { persist: { path: persist } }, }; @@ -666,7 +666,7 @@ describe("Bindings", () => { let config: StartDevWorkerOptions = { name: "worker", - script: unusable(), + entrypoint: unusable(), legacy: { site: { bucket: tmp, include: ["*.txt"] } }, }; const bundle = makeEsbuildBundle(` @@ -721,7 +721,7 @@ describe("Bindings", () => { const config: StartDevWorkerOptions = { name: "worker", - script: unusable(), + entrypoint: unusable(), bindings: { BUCKET: { type: "r2_bucket", bucket_name: "bucket" } }, dev: { persist: { path: persist } }, }; @@ -765,7 +765,7 @@ describe("Bindings", () => { const config: StartDevWorkerOptions = { name: "worker", - script: unusable(), + entrypoint: unusable(), bindings: { DB: { type: "d1", database_name: "db-name", database_id: "db" }, }, @@ -815,7 +815,7 @@ describe("Bindings", () => { const reportPromise = new DeferredPromise(); const config: StartDevWorkerOptions = { name: "worker", - script: unusable(), + entrypoint: unusable(), bindings: { QUEUE: { type: "queue", queue_name: "queue" }, BATCH_REPORT: { @@ -871,7 +871,7 @@ describe("Bindings", () => { const localConnectionString = `postgres://username:password@127.0.0.1:${port}/db`; const config: StartDevWorkerOptions = { name: "worker", - script: unusable(), + entrypoint: unusable(), bindings: { DB: { type: "hyperdrive", id: "db", localConnectionString } }, }; const bundle = makeEsbuildBundle(`export default { diff --git a/packages/wrangler/src/api/startDevWorker/BundlerController.ts b/packages/wrangler/src/api/startDevWorker/BundlerController.ts index 93821ff9c1c0..1f0741ad8f77 100644 --- a/packages/wrangler/src/api/startDevWorker/BundlerController.ts +++ b/packages/wrangler/src/api/startDevWorker/BundlerController.ts @@ -43,7 +43,7 @@ export class BundlerController extends Controller { #customBuildAborter = new AbortController(); async #runCustomBuild(config: StartDevWorkerOptions, filePath: string) { - assert(config.script.path); + assert(config.entrypoint.path); assert(config.directory); assert(config.build?.format); assert(config.build?.moduleRoot); @@ -54,11 +54,11 @@ export class BundlerController extends Controller { // Since `this.#customBuildAborter` will change as new builds are scheduled, store the specific AbortController that will be used for this build const buildAborter = this.#customBuildAborter; const relativeFile = - path.relative(config.directory, config.script.path) || "."; + path.relative(config.directory, config.entrypoint.path) || "."; logger.log(`The file ${filePath} changed, restarting build...`); this.emitBundleStartEvent(config); try { - await runCustomBuild(config.script.path, relativeFile, { + await runCustomBuild(config.entrypoint.path, relativeFile, { cwd: config.build?.custom?.workingDirectory, command: config.build?.custom?.command, }); @@ -72,23 +72,23 @@ export class BundlerController extends Controller { // if we're not bundling, let's just copy the entry to the destination directory const destinationDir = this.#tmpDir.path; writeFileSync( - path.join(destinationDir, path.basename(config.script.path)), - readFileSync(config.script.path, "utf-8") + path.join(destinationDir, path.basename(config.entrypoint.path)), + readFileSync(config.entrypoint.path, "utf-8") ); } const entry: Entry = { - file: config.script.path, + file: config.entrypoint.path, directory: config.directory, format: config.build.format, moduleRoot: config.build.moduleRoot, }; - const entryDirectory = path.dirname(config.script.path); + const entryDirectory = path.dirname(config.entrypoint.path); const moduleCollector = createModuleCollector({ wrangler1xLegacyModuleReferences: getWrangler1xLegacyModuleReferences( entryDirectory, - config.script.path + config.entrypoint.path ), entry, // `moduleCollector` doesn't get used when `noBundle` is set, so @@ -138,7 +138,7 @@ export class BundlerController extends Controller { return; } const entrypointPath = realpathSync( - bundleResult?.resolvedEntryPointPath ?? config.script.path + bundleResult?.resolvedEntryPointPath ?? config.entrypoint.path ); this.emitBundleCompleteEvent(config, { @@ -147,7 +147,7 @@ export class BundlerController extends Controller { path: entrypointPath, type: bundleResult?.bundleType ?? - getBundleType(config.build.format, config.script.path), + getBundleType(config.build.format, config.entrypoint.path), modules: bundleResult.modules, dependencies: bundleResult?.dependencies ?? {}, sourceMapPath: bundleResult?.sourceMapPath, @@ -203,12 +203,12 @@ export class BundlerController extends Controller { assert(this.#tmpDir); assert(config.build?.moduleRules, "config.build?.moduleRules"); assert(config.build?.define, "config.build?.define"); - assert(config.script.path); + assert(config.entrypoint.path); assert(config.directory); assert(config.build.format); assert(config.build.moduleRoot); const entry: Entry = { - file: config.script.path, + file: config.entrypoint.path, directory: config.directory, format: config.build.format, moduleRoot: config.build.moduleRoot, diff --git a/packages/wrangler/src/api/startDevWorker/types.ts b/packages/wrangler/src/api/startDevWorker/types.ts index 7dfaf48a5644..05f21ae4d1f9 100644 --- a/packages/wrangler/src/api/startDevWorker/types.ts +++ b/packages/wrangler/src/api/startDevWorker/types.ts @@ -51,7 +51,7 @@ export interface StartDevWorkerOptions { * This is the `main` property of a wrangler.toml. * You can specify a file path or provide the contents directly. */ - script: FilePath; + entrypoint: FilePath; /** The configuration of the worker. */ config?: FilePath; /** A worker's directory. Usually where the wrangler.toml file is located */ diff --git a/packages/wrangler/src/dev/dev.tsx b/packages/wrangler/src/dev/dev.tsx index 0d93e0158a40..f285ebb5175c 100644 --- a/packages/wrangler/src/dev/dev.tsx +++ b/packages/wrangler/src/dev/dev.tsx @@ -258,7 +258,7 @@ async function _toSDW( name: getScriptName({ name: args.name, env: args.env }, config), compatibilityDate: getDevCompatibilityDate(config, args.compatibilityDate), compatibilityFlags: args.compatibilityFlags || config.compatibility_flags, - script: { path: entry.file }, + entrypoint: { path: entry.file }, directory: entry.directory, bindings: convertCfWorkerInitBindingstoBindings(bindings), @@ -486,7 +486,7 @@ function DevSession(props: DevSessionProps) { name: props.name ?? "worker", compatibilityDate: props.compatibilityDate, compatibilityFlags: props.compatibilityFlags, - script: { path: props.entry.file }, + entrypoint: { path: props.entry.file }, directory: props.entry.directory, bindings: convertCfWorkerInitBindingstoBindings(props.bindings), diff --git a/packages/wrangler/src/dev/start-server.ts b/packages/wrangler/src/dev/start-server.ts index 4f7b886f2c46..6fffa6099a90 100644 --- a/packages/wrangler/src/dev/start-server.ts +++ b/packages/wrangler/src/dev/start-server.ts @@ -92,7 +92,7 @@ export async function startDevServer( const devEnv = props.devEnv; const startDevWorkerOptions: StartDevWorkerOptions = { name: props.name ?? "worker", - script: { path: props.entry.file }, + entrypoint: { path: props.entry.file }, directory: props.entry.directory, dev: { server: {