@meetploy/cli 1.9.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +86 -9
  2. package/package.json +2 -1
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire } from 'module';
3
3
  import { mkdir, writeFile, readFile, chmod, access } from 'fs/promises';
4
- import { join, dirname } from 'path';
5
- import { existsSync, readFileSync, readFile as readFile$1, mkdirSync, writeFileSync } from 'fs';
4
+ import { join, dirname, relative } from 'path';
5
+ import { existsSync, readFileSync, writeFileSync, unlinkSync, readFile as readFile$1, mkdirSync } from 'fs';
6
6
  import { promisify } from 'util';
7
7
  import { parse } from 'yaml';
8
8
  import { build } from 'esbuild';
@@ -60,6 +60,19 @@ var init_package_manager = __esm({
60
60
  "../tools/dist/package-manager.js"() {
61
61
  }
62
62
  });
63
+ function getCompatibilityFlags(config) {
64
+ if (!config.compatibility_flags || config.compatibility_flags.length === 0) {
65
+ return DEFAULT_COMPATIBILITY_FLAGS;
66
+ }
67
+ const allFlags = [
68
+ ...DEFAULT_COMPATIBILITY_FLAGS,
69
+ ...config.compatibility_flags
70
+ ];
71
+ return [...new Set(allFlags)];
72
+ }
73
+ function getCompatibilityDate(config) {
74
+ return config.compatibility_date || DEFAULT_COMPATIBILITY_DATE;
75
+ }
63
76
  function validateBindings(bindings, bindingType, configFile) {
64
77
  if (bindings === void 0) {
65
78
  return;
@@ -124,6 +137,24 @@ function validatePloyConfig(config, configFile = "ploy.yaml", options = {}) {
124
137
  if (config.monorepo !== void 0 && typeof config.monorepo !== "boolean") {
125
138
  throw new Error(`'monorepo' in ${configFile} must be a boolean`);
126
139
  }
140
+ if (config.compatibility_flags !== void 0) {
141
+ if (!Array.isArray(config.compatibility_flags)) {
142
+ throw new Error(`'compatibility_flags' in ${configFile} must be an array of strings`);
143
+ }
144
+ for (const flag of config.compatibility_flags) {
145
+ if (typeof flag !== "string") {
146
+ throw new Error(`'compatibility_flags' in ${configFile} must contain only strings`);
147
+ }
148
+ }
149
+ }
150
+ if (config.compatibility_date !== void 0) {
151
+ if (typeof config.compatibility_date !== "string") {
152
+ throw new Error(`'compatibility_date' in ${configFile} must be a string in YYYY-MM-DD format`);
153
+ }
154
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(config.compatibility_date)) {
155
+ throw new Error(`'compatibility_date' in ${configFile} must be in YYYY-MM-DD format (e.g., 2025-04-02)`);
156
+ }
157
+ }
127
158
  return validatedConfig;
128
159
  }
129
160
  async function readPloyConfig(projectDir, configPath) {
@@ -183,10 +214,12 @@ function getWorkerEntryPoint(projectDir, config) {
183
214
  }
184
215
  throw new Error("Could not find worker entry point. Specify 'main' in ploy.yaml");
185
216
  }
186
- var readFileAsync, BINDING_NAME_REGEX, RESOURCE_NAME_REGEX;
217
+ var readFileAsync, DEFAULT_COMPATIBILITY_FLAGS, DEFAULT_COMPATIBILITY_DATE, BINDING_NAME_REGEX, RESOURCE_NAME_REGEX;
187
218
  var init_ploy_config = __esm({
188
219
  "../tools/dist/ploy-config.js"() {
189
220
  readFileAsync = promisify(readFile$1);
221
+ DEFAULT_COMPATIBILITY_FLAGS = ["nodejs_compat_v2"];
222
+ DEFAULT_COMPATIBILITY_DATE = "2025-04-02";
190
223
  BINDING_NAME_REGEX = /^[A-Z][A-Z0-9_]*$/;
191
224
  RESOURCE_NAME_REGEX = /^[a-z][a-z0-9_]*$/;
192
225
  }
@@ -195,7 +228,11 @@ var init_ploy_config = __esm({
195
228
  // ../tools/dist/cli.js
196
229
  var cli_exports = {};
197
230
  __export(cli_exports, {
231
+ DEFAULT_COMPATIBILITY_DATE: () => DEFAULT_COMPATIBILITY_DATE,
232
+ DEFAULT_COMPATIBILITY_FLAGS: () => DEFAULT_COMPATIBILITY_FLAGS,
198
233
  getAddDevDependencyCommand: () => getAddDevDependencyCommand,
234
+ getCompatibilityDate: () => getCompatibilityDate,
235
+ getCompatibilityFlags: () => getCompatibilityFlags,
199
236
  getRunCommand: () => getRunCommand,
200
237
  getWorkerEntryPoint: () => getWorkerEntryPoint,
201
238
  hasBindings: () => hasBindings,
@@ -3923,31 +3960,68 @@ function detectPackageManager() {
3923
3960
  }
3924
3961
  return "npm";
3925
3962
  }
3926
- function runWranglerBuild() {
3963
+ function readExistingWranglerConfig(cwd) {
3964
+ const jsonPath = join(cwd, "wrangler.json");
3965
+ const jsoncPath = join(cwd, "wrangler.jsonc");
3966
+ if (existsSync(jsonPath)) {
3967
+ const content = readFileSync(jsonPath, "utf-8");
3968
+ return JSON.parse(content);
3969
+ }
3970
+ if (existsSync(jsoncPath)) {
3971
+ const content = readFileSync(jsoncPath, "utf-8");
3972
+ const stripped = content.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
3973
+ return JSON.parse(stripped);
3974
+ }
3975
+ return {};
3976
+ }
3977
+ function runWranglerBuild(entrypoint, ployConfig) {
3927
3978
  return new Promise((resolve, reject) => {
3979
+ const cwd = process.cwd();
3928
3980
  const packageManager = detectPackageManager();
3981
+ const existingConfig = readExistingWranglerConfig(cwd);
3982
+ const relativeEntrypoint = relative(cwd, entrypoint);
3983
+ const compatibilityFlags = getCompatibilityFlags(ployConfig);
3984
+ const compatibilityDate = getCompatibilityDate(ployConfig);
3985
+ const wranglerConfig = {
3986
+ ...existingConfig,
3987
+ main: relativeEntrypoint,
3988
+ // Use compatibility date from config, or from existing wrangler config, or default
3989
+ compatibility_date: existingConfig.compatibility_date || compatibilityDate,
3990
+ // Use compatibility flags from config, or defaults if not set in existing config
3991
+ compatibility_flags: existingConfig.compatibility_flags || compatibilityFlags
3992
+ };
3993
+ const tempConfigPath = join(cwd, ".wrangler-ploy-build.json");
3994
+ writeFileSync(tempConfigPath, JSON.stringify(wranglerConfig, null, " "));
3929
3995
  let command2;
3930
3996
  let args2;
3931
3997
  if (packageManager === "npm") {
3932
3998
  command2 = "npx";
3933
- args2 = ["wrangler", "build"];
3999
+ args2 = ["wrangler", "build", "--config", tempConfigPath];
3934
4000
  } else if (packageManager === "yarn") {
3935
4001
  command2 = "yarn";
3936
- args2 = ["wrangler", "build"];
4002
+ args2 = ["wrangler", "build", "--config", tempConfigPath];
3937
4003
  } else {
3938
4004
  command2 = "pnpm";
3939
- args2 = ["wrangler", "build"];
4005
+ args2 = ["wrangler", "build", "--config", tempConfigPath];
3940
4006
  }
3941
4007
  console.log(`Running: ${command2} ${args2.join(" ")}`);
3942
4008
  const child = spawn(command2, args2, {
3943
- cwd: process.cwd(),
4009
+ cwd,
3944
4010
  stdio: "inherit",
3945
4011
  shell: process.platform === "win32"
3946
4012
  });
3947
4013
  child.on("error", (error2) => {
4014
+ try {
4015
+ unlinkSync(tempConfigPath);
4016
+ } catch {
4017
+ }
3948
4018
  reject(new Error(`Failed to run wrangler build: ${error2.message}`));
3949
4019
  });
3950
4020
  child.on("close", (code) => {
4021
+ try {
4022
+ unlinkSync(tempConfigPath);
4023
+ } catch {
4024
+ }
3951
4025
  if (code === 0) {
3952
4026
  resolve();
3953
4027
  } else {
@@ -3964,7 +4038,10 @@ async function buildCommand(options = {}) {
3964
4038
  validatePloyConfig(config, configFile);
3965
4039
  console.log("Configuration valid.");
3966
4040
  console.log("");
3967
- await runWranglerBuild();
4041
+ const entrypoint = getWorkerEntryPoint(cwd, config);
4042
+ console.log(`Using entrypoint: ${relative(cwd, entrypoint)}`);
4043
+ console.log("");
4044
+ await runWranglerBuild(entrypoint, config);
3968
4045
  }
3969
4046
  function parseBuildArgs(args2) {
3970
4047
  const options = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meetploy/cli",
3
- "version": "1.9.0",
3
+ "version": "1.11.0",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -49,6 +49,7 @@
49
49
  "@meetploy/emulator": "*",
50
50
  "@meetploy/tools": "*",
51
51
  "@types/better-sqlite3": "^7.6.12",
52
+ "api": "*",
52
53
  "openapi-typescript": "7.8.0",
53
54
  "tsup": "^8.0.0"
54
55
  }