@flisk-sh/flisk-export 0.4.0 → 0.4.1

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/compose.js +15 -2
  2. package/package.json +1 -1
package/dist/compose.js CHANGED
@@ -7,6 +7,8 @@
7
7
  */
8
8
  import { relative, sep } from "node:path";
9
9
  import { ExportError } from "./errors.js";
10
+ /** extraPorts `publish`: digits, dots, colons and `${NAME:-default}`, as flisk core accepts it (flisk#2947). */
11
+ const PUBLISH = /^(?:[0-9.:]|\$\{[A-Za-z_][A-Za-z0-9_]*:-[0-9.:]+\})+$/;
10
12
  /** The only resource type the Compose export covers: it is the one whose service.json is a Compose service. */
11
13
  export const COMPOSE_TYPE = "bring-your-own";
12
14
  const RESTART_POLICIES = new Set(["no", "on-failure", "unless-stopped", "always"]);
@@ -130,9 +132,20 @@ function serviceLines(resource, outDir, services) {
130
132
  if (!Number.isInteger(port) || port < 1 || port > 65535) {
131
133
  throw new ExportError(`${name}: extraPorts needs a port from 1 to 65535`);
132
134
  }
133
- const hostPort = p.hostPort === undefined ? port : Number(p.hostPort);
134
- const bind = typeof p.bind === "string" && p.bind ? p.bind : "127.0.0.1";
135
135
  const protocol = p.protocol === "udp" ? "udp" : "tcp";
136
+ // `publish` (flisk#2947): the host side as the project's Compose wrote it, e.g. "${APP_HTTP_BIND:-80}"; Compose resolves it.
137
+ if (p.publish !== undefined) {
138
+ if (typeof p.publish !== "string" || !PUBLISH.test(p.publish)) {
139
+ throw new ExportError(`${name}: extraPorts publish must be a port, an IPv4 address:port, or \${NAME:-default}`);
140
+ }
141
+ lines.push(` - ${q(`${p.publish}:${port}/${protocol}`)}`);
142
+ continue;
143
+ }
144
+ const hostPort = p.hostPort === undefined ? port : Number(p.hostPort);
145
+ const bind = p.bind === undefined ? "127.0.0.1" : p.bind;
146
+ if (bind !== "127.0.0.1" && bind !== "0.0.0.0") {
147
+ throw new ExportError(`${name}: extraPorts bind must be 127.0.0.1 or 0.0.0.0`);
148
+ }
136
149
  lines.push(` - ${q(`${bind}:${hostPort}:${port}/${protocol}`)}`);
137
150
  }
138
151
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flisk-sh/flisk-export",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Write a Render Blueprint (render.yaml), a Cloudflare wrangler.toml or a standalone docker-compose.yml from Flisk service.json files. Never deploys.",
5
5
  "type": "module",
6
6
  "license": "MIT",