Skip to content

Commit

Permalink
rename: script to entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
RamIdeas committed Jun 19, 2024
1 parent 2bd5374 commit 5b1e416
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe("Core", () => {

const config: StartDevWorkerOptions = {
name: "worker",
script: unusable(),
entrypoint: unusable(),
compatibilityFlags: ["nodejs_compat"],
compatibilityDate: "2023-10-01",
};
Expand Down Expand Up @@ -270,7 +270,7 @@ describe("Core", () => {

const config: StartDevWorkerOptions = {
name: "worker",
script: unusable(),
entrypoint: unusable(),
};
const bundle: Bundle = {
type: "commonjs",
Expand Down Expand Up @@ -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 },
},
Expand Down Expand Up @@ -405,7 +405,7 @@ describe("Core", () => {

const config: StartDevWorkerOptions = {
name: "worker",
script: unusable(),
entrypoint: unusable(),
compatibilityDate: disabledDate,
};
const bundle = makeEsbuildBundle(dedent/*javascript*/ `
Expand Down Expand Up @@ -443,7 +443,7 @@ describe("Core", () => {

const config: StartDevWorkerOptions = {
name: "worker",
script: unusable(),
entrypoint: unusable(),
};
const bundle = makeEsbuildBundle(dedent/*javascript*/ `
export default {
Expand Down Expand Up @@ -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 } } },
Expand Down Expand Up @@ -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 } },
Expand Down Expand Up @@ -572,7 +572,7 @@ describe("Bindings", () => {

const config: StartDevWorkerOptions = {
name: "worker",
script: unusable(),
entrypoint: unusable(),
dev: { persist: { path: persist } },
};
const bundle = makeEsbuildBundle(`export default {
Expand Down Expand Up @@ -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 } },
};
Expand Down Expand Up @@ -666,7 +666,7 @@ describe("Bindings", () => {

let config: StartDevWorkerOptions = {
name: "worker",
script: unusable(),
entrypoint: unusable(),
legacy: { site: { bucket: tmp, include: ["*.txt"] } },
};
const bundle = makeEsbuildBundle(`
Expand Down Expand Up @@ -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 } },
};
Expand Down Expand Up @@ -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" },
},
Expand Down Expand Up @@ -815,7 +815,7 @@ describe("Bindings", () => {
const reportPromise = new DeferredPromise<unknown>();
const config: StartDevWorkerOptions = {
name: "worker",
script: unusable(),
entrypoint: unusable(),
bindings: {
QUEUE: { type: "queue", queue_name: "queue" },
BATCH_REPORT: {
Expand Down Expand Up @@ -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 {
Expand Down
24 changes: 12 additions & 12 deletions packages/wrangler/src/api/startDevWorker/BundlerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class BundlerController extends Controller<BundlerControllerEventMap> {
#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);
Expand All @@ -54,11 +54,11 @@ export class BundlerController extends Controller<BundlerControllerEventMap> {
// 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,
});
Expand All @@ -72,23 +72,23 @@ export class BundlerController extends Controller<BundlerControllerEventMap> {
// 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
Expand Down Expand Up @@ -138,7 +138,7 @@ export class BundlerController extends Controller<BundlerControllerEventMap> {
return;
}
const entrypointPath = realpathSync(
bundleResult?.resolvedEntryPointPath ?? config.script.path
bundleResult?.resolvedEntryPointPath ?? config.entrypoint.path
);

this.emitBundleCompleteEvent(config, {
Expand All @@ -147,7 +147,7 @@ export class BundlerController extends Controller<BundlerControllerEventMap> {
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,
Expand Down Expand Up @@ -203,12 +203,12 @@ export class BundlerController extends Controller<BundlerControllerEventMap> {
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,
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/api/startDevWorker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions packages/wrangler/src/dev/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand Down Expand Up @@ -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),

Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/dev/start-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 5b1e416

Please sign in to comment.