@zuplo/cli 1.138.0 → 2.2.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.
package/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ nodejs 18.20.4
package/README.md CHANGED
@@ -64,3 +64,12 @@ Commands:
64
64
  zup variable update Updates an existing variable for a branch
65
65
 
66
66
  ```
67
+
68
+ # Changelog
69
+
70
+ ## v2
71
+
72
+ - Removes the use of Deno's test runner. We now use the built-in test runner in
73
+ Node.js. All features are preserved; however, the output of `zup test` follows
74
+ the Node.js
75
+ [spec reporter](https://nodejs.org/docs/latest-v18.x/api/test.html#test-reporters).
package/dist/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="b7b80df4-c767-5f13-8cfb-0f1e1b3f3d4f")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="56d3c48c-3960-5c1d-adbd-d0a76d0ac940")}catch(e){}}();
3
3
  import * as dotenv from "dotenv";
4
4
  dotenv.config();
5
5
  import * as Sentry from "@sentry/node";
@@ -42,6 +42,12 @@ if (gte(process.versions.node, MIN_NODE_VERSION)) {
42
42
  });
43
43
  const cli = yargs(hideBin(process.argv))
44
44
  .env("ZUPLO")
45
+ .option("prompt", {
46
+ type: "boolean",
47
+ describe: "Bypass confirmation prompts",
48
+ default: true,
49
+ hidden: true,
50
+ })
45
51
  .command(compile)
46
52
  .command(convert)
47
53
  .command(deleteZup)
@@ -84,4 +90,4 @@ else {
84
90
  Consider using a Node.js version manager such as https://github.com/nvm-sh/nvm.`);
85
91
  }
86
92
  //# sourceMappingURL=cli.js.map
87
- //# debugId=b7b80df4-c767-5f13-8cfb-0f1e1b3f3d4f
93
+ //# debugId=56d3c48c-3960-5c1d-adbd-d0a76d0ac940
@@ -1,5 +1,5 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="91ee157c-141d-5381-a1b8-ef9f2f5625d8")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d280723f-9208-5c26-a757-080dd9217482")}catch(e){}}();
3
3
  import { captureEvent } from "../../common/analytics/lib.js";
4
4
  import setBlocking from "../../common/output.js";
5
5
  import { ZuploProjectValidator } from "../../common/validators/file-system-validator.js";
@@ -16,11 +16,6 @@ export default {
16
16
  default: ".",
17
17
  normalize: true,
18
18
  hidden: true,
19
- })
20
- .option("prompt", {
21
- type: "boolean",
22
- describe: "Prompt for confirmation before importing",
23
- default: true,
24
19
  })
25
20
  .option("source", {
26
21
  type: "string",
@@ -43,4 +38,4 @@ export default {
43
38
  },
44
39
  };
45
40
  //# sourceMappingURL=import-openapi.js.map
46
- //# debugId=91ee157c-141d-5381-a1b8-ef9f2f5625d8
41
+ //# debugId=d280723f-9208-5c26-a757-080dd9217482
@@ -0,0 +1,5 @@
1
+
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="3d67c996-402a-5927-8ae6-1fb20dee5751")}catch(e){}}();
3
+ export {};
4
+ //# sourceMappingURL=args.js.map
5
+ //# debugId=3d67c996-402a-5927-8ae6-1fb20dee5751
@@ -0,0 +1,66 @@
1
+
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="f4a9a7b0-4a16-5eb9-b752-e61ee1acb33e")}catch(e){}}();
3
+ import { assert } from "chai";
4
+ import { rm, writeFile } from "node:fs/promises";
5
+ import { join } from "node:path";
6
+ import { beforeEach, describe, it } from "node:test";
7
+ import { MockAgent, setGlobalDispatcher } from "undici";
8
+ import { ZUPLO_VERSION_CHECK_FILE } from "./constants.js";
9
+ import { warnIfOutdatedVersion } from "./outdated.js";
10
+ import { ZUPLO_XDG_STATE_HOME } from "./xdg/lib.js";
11
+ const versionCheckPath = join(ZUPLO_XDG_STATE_HOME, ZUPLO_VERSION_CHECK_FILE);
12
+ process.env.ZUPLO_OVERRIDE_CI_TO_TEST = "true";
13
+ describe("Outdated CLI check", function () {
14
+ let mockAgent;
15
+ beforeEach(() => {
16
+ mockAgent = new MockAgent();
17
+ mockAgent.disableNetConnect();
18
+ mockAgent
19
+ .get("https://raw.githubusercontent.com")
20
+ .intercept({
21
+ path: "/zuplo/zuplo/main/packages/zuplo/package.json",
22
+ method: "GET",
23
+ })
24
+ .reply(200, {
25
+ name: "zuplo",
26
+ dependencies: {
27
+ "@zuplo/cli": "1.109.0",
28
+ },
29
+ });
30
+ setGlobalDispatcher(mockAgent);
31
+ });
32
+ it("should warn on outdated version", async function () {
33
+ await rm(versionCheckPath, { recursive: true, force: true });
34
+ const result = await warnIfOutdatedVersion("1.0.0");
35
+ assert.isTrue(result);
36
+ assert.equal(mockAgent.pendingInterceptors.length, 0);
37
+ });
38
+ it("should not warn if current version", async function () {
39
+ const result = await warnIfOutdatedVersion("1.109.0");
40
+ assert.isFalse(result);
41
+ });
42
+ it("should not warn if still has cached result", async function () {
43
+ const state = { lastCheck: Date.now() - 1000, latestVersion: "1.108.0" };
44
+ await writeFile(versionCheckPath, JSON.stringify(state), "utf-8");
45
+ const result = await warnIfOutdatedVersion("1.108.0");
46
+ assert.isFalse(result);
47
+ });
48
+ it("should warn when time expired on outdated version", async function () {
49
+ const state = {
50
+ lastCheck: Date.now() - 1000 * 60 * 60 * 24 - 100,
51
+ latestVersion: "1.0.0",
52
+ };
53
+ await writeFile(versionCheckPath, JSON.stringify(state), "utf-8");
54
+ const result = await warnIfOutdatedVersion("1.0.0");
55
+ assert.isTrue(result);
56
+ assert.equal(mockAgent.pendingInterceptors.length, 0);
57
+ });
58
+ it("should handle invalid state", async function () {
59
+ await writeFile(versionCheckPath, "hello", "utf-8");
60
+ const result = await warnIfOutdatedVersion("0.0.1");
61
+ assert.isTrue(result);
62
+ assert.equal(mockAgent.pendingInterceptors.length, 0);
63
+ });
64
+ });
65
+ //# sourceMappingURL=outdated.test.js.map
66
+ //# debugId=f4a9a7b0-4a16-5eb9-b752-e61ee1acb33e
@@ -1,5 +1,5 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="e03e4373-c6b2-5c5e-b73d-fcff6d7d010b")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="7f37d2ec-c9c4-5c18-a196-361f8f5e4924")}catch(e){}}();
3
3
  import { readFile, writeFile } from "node:fs/promises";
4
4
  import { join } from "node:path";
5
5
  import prettier from "prettier";
@@ -30,10 +30,11 @@ export class PackageJsonUpgrader extends StandardUpgrader {
30
30
  (packageJson.scripts.build === "zup build" ||
31
31
  packageJson.scripts.build === "zuplo build"))
32
32
  delete packageJson.scripts.build;
33
- if (packageJson.scripts.test &&
34
- (packageJson.scripts.test === "zup test" ||
35
- packageJson.scripts.test === "zuplo test")) {
36
- delete packageJson.scripts.test;
33
+ if (packageJson.scripts.test && packageJson.scripts.test === "zuplo test") {
34
+ packageJson.scripts.test = "zup test";
35
+ }
36
+ else if (!packageJson.scripts.test) {
37
+ packageJson.scripts.test = "zup test";
37
38
  }
38
39
  if (packageJson.scripts.postinstall &&
39
40
  packageJson.scripts.postinstall === "husky install") {
@@ -64,4 +65,4 @@ export class PackageJsonUpgrader extends StandardUpgrader {
64
65
  }
65
66
  }
66
67
  //# sourceMappingURL=package-json-upgrader.js.map
67
- //# debugId=e03e4373-c6b2-5c5e-b73d-fcff6d7d010b
68
+ //# debugId=7f37d2ec-c9c4-5c18-a196-361f8f5e4924
@@ -0,0 +1,107 @@
1
+
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="1bf2cbbf-1e6f-586b-86a8-5ce98e9e2358")}catch(e){}}();
3
+ import { parse } from "jsonc-parser";
4
+ import { readFile, writeFile } from "node:fs/promises";
5
+ import { join } from "node:path";
6
+ import prettier from "prettier";
7
+ import ts, { ModuleKind, ModuleResolutionKind, ScriptTarget, } from "typescript";
8
+ import { StandardUpgrader } from "./lib.js";
9
+ export class FailedToParseTSConfigJson extends Error {
10
+ constructor() {
11
+ super("Invalid tsconfig.json: Failed to parse the tsconfig.json file.");
12
+ Object.setPrototypeOf(this, FailedToParseTSConfigJson.prototype);
13
+ }
14
+ }
15
+ export class InvalidTSConfigJson extends Error {
16
+ constructor(message) {
17
+ super(message);
18
+ Object.setPrototypeOf(this, InvalidTSConfigJson.prototype);
19
+ }
20
+ }
21
+ export class TSConfigUpgrader extends StandardUpgrader {
22
+ async isApplicable() {
23
+ return { ok: true };
24
+ }
25
+ async needsUpgrade() {
26
+ try {
27
+ const tsFilePath = join(this.normalizedDir, "tsconfig.json");
28
+ const tsConfigRaw = await readFile(tsFilePath, "utf-8");
29
+ const tsConfigJson = parse(tsConfigRaw);
30
+ if (!(tsConfigJson &&
31
+ typeof tsConfigJson === "object" &&
32
+ "compilerOptions" in tsConfigJson)) {
33
+ return true;
34
+ }
35
+ const { options, errors } = ts.convertCompilerOptionsFromJson(tsConfigJson.compilerOptions, this.normalizedDir);
36
+ const libValue = ["ESNext", "WebWorker", "Webworker.Iterable"];
37
+ const includesAllLibs = (userLibs) => {
38
+ const a = libValue.map((item) => item.toLowerCase());
39
+ const b = userLibs.map((item) => item.toLowerCase());
40
+ return a.every((item) => b.includes(item));
41
+ };
42
+ return (errors.length > 0 ||
43
+ options.module !== ModuleKind.ESNext ||
44
+ options.target !== ScriptTarget.ES2022 ||
45
+ options.moduleResolution !== ModuleResolutionKind.Bundler ||
46
+ !options.lib ||
47
+ options.baseUrl !== undefined ||
48
+ !includesAllLibs(tsConfigJson.compilerOptions.lib ?? []));
49
+ }
50
+ catch (err) {
51
+ return true;
52
+ }
53
+ }
54
+ async upgrade() {
55
+ if (!(await this.needsUpgrade())) {
56
+ return;
57
+ }
58
+ const tsFilePath = join(this.normalizedDir, "tsconfig.json");
59
+ const tsConfig = {
60
+ include: ["modules/**/*", ".zuplo/**/*", "tests/**/*"],
61
+ exclude: ["./node_modules", "./dist"],
62
+ compilerOptions: {
63
+ module: "ESNext",
64
+ target: "ES2022",
65
+ moduleResolution: "Bundler",
66
+ lib: ["ESNext", "WebWorker", "Webworker.Iterable"],
67
+ preserveConstEnums: true,
68
+ useUnknownInCatchVariables: false,
69
+ forceConsistentCasingInFileNames: true,
70
+ importHelpers: true,
71
+ removeComments: true,
72
+ esModuleInterop: true,
73
+ strictNullChecks: true,
74
+ noEmit: true,
75
+ },
76
+ };
77
+ const formatted = await prettier.format(JSON.stringify(tsConfig), {
78
+ parser: "json",
79
+ });
80
+ await writeFile(tsFilePath, formatted);
81
+ }
82
+ }
83
+ export const getZuploTsConfigTemplate = () => ({
84
+ include: ["modules/**/*", ".zuplo/**/*", "tests/**/*"],
85
+ exclude: ["./node_modules", "./dist"],
86
+ compilerOptions: {
87
+ baseUrl: ".",
88
+ module: ModuleKind.ESNext,
89
+ target: ScriptTarget.ESNext,
90
+ moduleResolution: ModuleResolutionKind.Bundler,
91
+ lib: ["ESNext", "WebWorker", "Webworker.Iterable"],
92
+ preserveConstEnums: true,
93
+ useUnknownInCatchVariables: false,
94
+ forceConsistentCasingInFileNames: true,
95
+ importHelpers: true,
96
+ removeComments: true,
97
+ esModuleInterop: true,
98
+ strictNullChecks: true,
99
+ experimentalDecorators: true,
100
+ noEmit: true,
101
+ paths: {
102
+ "@app/*": [".zuplo/*"],
103
+ },
104
+ },
105
+ });
106
+ //# sourceMappingURL=tsconfig-upgrader.js.map
107
+ //# debugId=1bf2cbbf-1e6f-586b-86a8-5ce98e9e2358
@@ -0,0 +1,30 @@
1
+
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="6067ec2f-ba9e-552d-86dc-efe5ac6410f1")}catch(e){}}();
3
+ import assert from "node:assert";
4
+ import { describe, test } from "node:test";
5
+ import { TSConfigUpgrader } from "./tsconfig-upgrader.js";
6
+ process.env.ZUPLO_OVERRIDE_CI_TO_TEST = "true";
7
+ describe("TSConfigUpgrader checks", async function () {
8
+ test("Should not run for a valid tsconfig.json", async function () {
9
+ const upgrader = new TSConfigUpgrader(new URL("../../../test-fixtures/tsconfig/valid", import.meta.url).pathname);
10
+ const needsUpgrade = await upgrader.needsUpgrade();
11
+ assert.equal(needsUpgrade, false);
12
+ });
13
+ test("Should run for a legacy tsconfig.json", async function () {
14
+ const upgrader = new TSConfigUpgrader(new URL("../../../test-fixtures/tsconfig/legacy", import.meta.url).pathname);
15
+ const needsUpgrade = await upgrader.needsUpgrade();
16
+ assert.equal(needsUpgrade, true);
17
+ });
18
+ test("Should run for a missing prop tsconfig.json", async function () {
19
+ const upgrader = new TSConfigUpgrader(new URL("../../../test-fixtures/tsconfig/missing-prop", import.meta.url).pathname);
20
+ const needsUpgrade = await upgrader.needsUpgrade();
21
+ assert.equal(needsUpgrade, true);
22
+ });
23
+ test("Should run when baseUrl set in tsconfig.json", async function () {
24
+ const upgrader = new TSConfigUpgrader(new URL("../../../test-fixtures/tsconfig/missing-prop", import.meta.url).pathname);
25
+ const needsUpgrade = await upgrader.needsUpgrade();
26
+ assert.equal(needsUpgrade, true);
27
+ });
28
+ });
29
+ //# sourceMappingURL=tsconfig-upgrader.test.js.map
30
+ //# debugId=6067ec2f-ba9e-552d-86dc-efe5ac6410f1
@@ -0,0 +1,302 @@
1
+
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="ef0b2816-b9e6-501e-8d11-6961d4a8afa1")}catch(e){}}();
3
+ import { expect } from "chai";
4
+ import { describe, it } from "node:test";
5
+ import { convertRoutes } from "./engine.js";
6
+ describe("Routes.json Conversion Engine", () => {
7
+ it("should handle simple route conversion (no version)", () => {
8
+ const routesConfig = {
9
+ versions: [
10
+ {
11
+ name: "v1",
12
+ pathPrefix: "/v1",
13
+ },
14
+ {
15
+ name: "none",
16
+ pathPrefix: "",
17
+ },
18
+ ],
19
+ routes: [
20
+ {
21
+ methods: ["GET"],
22
+ path: "/test",
23
+ summary: "Test route",
24
+ version: "none",
25
+ corsPolicy: "anything-goes",
26
+ description: "This is a test route",
27
+ operationId: "random",
28
+ handler: {
29
+ export: "urlRewriteHandler",
30
+ module: "$import(@zuplo/runtime)",
31
+ options: {
32
+ rewritePattern: "https://jsonplaceholder.typicode.com/todos",
33
+ forwardSearch: true,
34
+ },
35
+ },
36
+ },
37
+ ],
38
+ };
39
+ const expected = {
40
+ openapi: "3.1.0",
41
+ info: {
42
+ title: "Converted from config/routes.json",
43
+ version: "1.0.0",
44
+ },
45
+ paths: {
46
+ "/test": {
47
+ get: {
48
+ summary: "Test route",
49
+ description: "This is a test route",
50
+ operationId: "random",
51
+ "x-zuplo-route": {
52
+ corsPolicy: "anything-goes",
53
+ handler: {
54
+ export: "urlRewriteHandler",
55
+ module: "$import(@zuplo/runtime)",
56
+ options: {
57
+ rewritePattern: "https://jsonplaceholder.typicode.com/todos",
58
+ forwardSearch: true,
59
+ },
60
+ },
61
+ },
62
+ },
63
+ "x-zuplo-path": {
64
+ pathMode: "url-pattern",
65
+ },
66
+ },
67
+ },
68
+ };
69
+ const actual = convertRoutes(routesConfig);
70
+ expect(actual).to.deep.equal(expected);
71
+ });
72
+ it("should handle simple route conversion (with version)", () => {
73
+ const routesConfig = {
74
+ versions: [
75
+ {
76
+ name: "v1",
77
+ pathPrefix: "/v1",
78
+ },
79
+ {
80
+ name: "none",
81
+ pathPrefix: "",
82
+ },
83
+ ],
84
+ routes: [
85
+ {
86
+ methods: ["GET"],
87
+ path: "/test",
88
+ summary: "Test route",
89
+ version: "v1",
90
+ corsPolicy: "anything-goes",
91
+ description: "This is a test route",
92
+ operationId: "random",
93
+ handler: {
94
+ export: "urlRewriteHandler",
95
+ module: "$import(@zuplo/runtime)",
96
+ options: {
97
+ rewritePattern: "https://jsonplaceholder.typicode.com/todos",
98
+ forwardSearch: true,
99
+ },
100
+ },
101
+ },
102
+ ],
103
+ };
104
+ const expected = {
105
+ openapi: "3.1.0",
106
+ info: {
107
+ title: "Converted from config/routes.json",
108
+ version: "1.0.0",
109
+ },
110
+ paths: {
111
+ "/v1/test": {
112
+ get: {
113
+ summary: "Test route",
114
+ description: "This is a test route",
115
+ operationId: "random",
116
+ "x-zuplo-route": {
117
+ corsPolicy: "anything-goes",
118
+ handler: {
119
+ export: "urlRewriteHandler",
120
+ module: "$import(@zuplo/runtime)",
121
+ options: {
122
+ rewritePattern: "https://jsonplaceholder.typicode.com/todos",
123
+ forwardSearch: true,
124
+ },
125
+ },
126
+ },
127
+ },
128
+ "x-zuplo-path": {
129
+ pathMode: "url-pattern",
130
+ },
131
+ },
132
+ },
133
+ };
134
+ const actual = convertRoutes(routesConfig);
135
+ expect(actual).to.deep.equal(expected);
136
+ });
137
+ it("should handle single route with multiple methods", () => {
138
+ const routesConfig = {
139
+ versions: [
140
+ {
141
+ name: "v1",
142
+ pathPrefix: "/v1",
143
+ },
144
+ {
145
+ name: "none",
146
+ pathPrefix: "",
147
+ },
148
+ ],
149
+ routes: [
150
+ {
151
+ methods: ["GET", "POST", "HEAD"],
152
+ path: "/test",
153
+ summary: "Test route",
154
+ version: "v1",
155
+ corsPolicy: "anything-goes",
156
+ description: "This is a test route",
157
+ operationId: "random",
158
+ handler: {
159
+ export: "urlRewriteHandler",
160
+ module: "$import(@zuplo/runtime)",
161
+ options: {
162
+ rewritePattern: "https://jsonplaceholder.typicode.com/todos",
163
+ forwardSearch: true,
164
+ },
165
+ },
166
+ },
167
+ ],
168
+ };
169
+ const expected = {
170
+ openapi: "3.1.0",
171
+ info: {
172
+ title: "Converted from config/routes.json",
173
+ version: "1.0.0",
174
+ },
175
+ paths: {
176
+ "/v1/test": {
177
+ "get,post,head": {
178
+ summary: "Test route",
179
+ description: "This is a test route",
180
+ operationId: "random",
181
+ "x-zuplo-route": {
182
+ corsPolicy: "anything-goes",
183
+ handler: {
184
+ export: "urlRewriteHandler",
185
+ module: "$import(@zuplo/runtime)",
186
+ options: {
187
+ rewritePattern: "https://jsonplaceholder.typicode.com/todos",
188
+ forwardSearch: true,
189
+ },
190
+ },
191
+ },
192
+ },
193
+ "x-zuplo-path": {
194
+ pathMode: "url-pattern",
195
+ },
196
+ },
197
+ },
198
+ };
199
+ const actual = convertRoutes(routesConfig);
200
+ expect(actual).to.deep.equal(expected);
201
+ });
202
+ it("should handle single route with different methods", () => {
203
+ const routesConfig = {
204
+ versions: [
205
+ {
206
+ name: "v1",
207
+ pathPrefix: "/v1",
208
+ },
209
+ {
210
+ name: "none",
211
+ pathPrefix: "",
212
+ },
213
+ ],
214
+ routes: [
215
+ {
216
+ methods: ["GET"],
217
+ path: "/test",
218
+ summary: "Test route",
219
+ description: "This is a test route",
220
+ version: "v1",
221
+ corsPolicy: "anything-goes",
222
+ handler: {
223
+ export: "urlRewriteHandler",
224
+ module: "$import(@zuplo/runtime)",
225
+ options: {
226
+ rewritePattern: "https://welcome.zuplo.io/",
227
+ forwardSearch: true,
228
+ },
229
+ },
230
+ operationId: "random1",
231
+ },
232
+ {
233
+ methods: ["POST"],
234
+ path: "/test",
235
+ summary: "Test route",
236
+ description: "This is a test route",
237
+ version: "v1",
238
+ corsPolicy: "anything-goes",
239
+ handler: {
240
+ export: "urlRewriteHandler",
241
+ module: "$import(@zuplo/runtime)",
242
+ options: {
243
+ rewritePattern: "https://welcome.zuplo.io/",
244
+ forwardSearch: true,
245
+ },
246
+ },
247
+ operationId: "random2",
248
+ },
249
+ ],
250
+ };
251
+ const expected = {
252
+ openapi: "3.1.0",
253
+ info: {
254
+ title: "Converted from config/routes.json",
255
+ version: "1.0.0",
256
+ },
257
+ paths: {
258
+ "/v1/test": {
259
+ get: {
260
+ summary: "Test route",
261
+ description: "This is a test route",
262
+ operationId: "random1",
263
+ "x-zuplo-route": {
264
+ corsPolicy: "anything-goes",
265
+ handler: {
266
+ export: "urlRewriteHandler",
267
+ module: "$import(@zuplo/runtime)",
268
+ options: {
269
+ rewritePattern: "https://welcome.zuplo.io/",
270
+ forwardSearch: true,
271
+ },
272
+ },
273
+ },
274
+ },
275
+ post: {
276
+ summary: "Test route",
277
+ description: "This is a test route",
278
+ operationId: "random2",
279
+ "x-zuplo-route": {
280
+ corsPolicy: "anything-goes",
281
+ handler: {
282
+ export: "urlRewriteHandler",
283
+ module: "$import(@zuplo/runtime)",
284
+ options: {
285
+ rewritePattern: "https://welcome.zuplo.io/",
286
+ forwardSearch: true,
287
+ },
288
+ },
289
+ },
290
+ },
291
+ "x-zuplo-path": {
292
+ pathMode: "url-pattern",
293
+ },
294
+ },
295
+ },
296
+ };
297
+ const actual = convertRoutes(routesConfig);
298
+ expect(actual).to.deep.equal(expected);
299
+ });
300
+ });
301
+ //# sourceMappingURL=engine.test.js.map
302
+ //# debugId=ef0b2816-b9e6-501e-8d11-6961d4a8afa1
@@ -1,5 +1,5 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="c5129a8e-104c-557e-bd58-09f307c47a3f")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="a4e07444-c9b0-5d72-9ff0-ddd4f42e802b")}catch(e){}}();
3
3
  import { confirm } from "@inquirer/prompts";
4
4
  import jsYaml from "js-yaml";
5
5
  import { existsSync, writeFileSync } from "node:fs";
@@ -142,4 +142,4 @@ export async function importOpenApi(argv) {
142
142
  await printResultToConsoleAndExitGracefully(`Import successful. File written to ${destinationFilePath}`);
143
143
  }
144
144
  //# sourceMappingURL=handler.js.map
145
- //# debugId=c5129a8e-104c-557e-bd58-09f307c47a3f
145
+ //# debugId=a4e07444-c9b0-5d72-9ff0-ddd4f42e802b
@@ -1,29 +1,34 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="621a9145-cc00-51e8-be17-81b63287e71c")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="b240c7b1-8f8c-54c7-b381-3ec9bae18cd4")}catch(e){}}();
3
3
  import { confirm } from "@inquirer/prompts";
4
4
  import { printDiagnosticsToConsole, printResultToConsoleAndExitGracefully, } from "../../common/output.js";
5
5
  import { PackageJsonUpgrader } from "../../common/upgraders/package-json-upgrader.js";
6
+ import { TSConfigUpgrader } from "../../common/upgraders/tsconfig-upgrader.js";
6
7
  import { VsCodeSettingsJsonUpgrader } from "../../common/upgraders/vscode-settings-json-upgrader.js";
7
8
  export async function update(argv) {
8
- printDiagnosticsToConsole("This command will make changes to your source code. Please commit your changes to version control before continuing.");
9
- const answer = await confirm({ message: "Continue?", default: true });
9
+ let answer = !!argv.prompt;
10
+ if (answer) {
11
+ printDiagnosticsToConsole("This command will make changes to your source code. Please commit your changes to version control before continuing.");
12
+ answer = await confirm({ message: "Continue?", default: true });
13
+ }
10
14
  if (answer) {
11
15
  const u = new PackageJsonUpgrader(argv.dir);
12
16
  if ((await u.isApplicable()).ok) {
13
17
  printDiagnosticsToConsole("Updating your package.json...");
14
18
  await u.upgrade();
15
19
  }
16
- else {
17
- }
18
20
  const v = new VsCodeSettingsJsonUpgrader(argv.dir);
19
21
  if ((await v.isApplicable()).ok) {
20
- printDiagnosticsToConsole("Updating your .vsode settings...");
22
+ printDiagnosticsToConsole("Updating your .vscode settings...");
21
23
  await v.upgrade();
22
24
  }
23
- else {
25
+ const t = new TSConfigUpgrader(argv.dir);
26
+ if ((await t.isApplicable()).ok) {
27
+ printDiagnosticsToConsole("Rewriting your tsconfig.json...");
28
+ await t.upgrade();
24
29
  }
25
30
  await printResultToConsoleAndExitGracefully("Update completed");
26
31
  }
27
32
  }
28
33
  //# sourceMappingURL=handler.js.map
29
- //# debugId=621a9145-cc00-51e8-be17-81b63287e71c
34
+ //# debugId=b240c7b1-8f8c-54c7-b381-3ec9bae18cd4
@@ -1,23 +1,24 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="f13aec76-f70a-5053-8b92-7e9a9134dbfc")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="5c127662-31c6-5178-a683-322b67f8580c")}catch(e){}}();
3
3
  import { TEST_OUT_FOLDER } from "../common/constants.js";
4
- import { denoTestPrepPlugin } from "./esbuild-plugins/deno-test-prep-plugin.js";
4
+ import { nodeTestPrepPlugin } from "./esbuild-plugins/node-test-prep-plugin.js";
5
5
  export function generateBuildOptionsForTest(argv) {
6
6
  return {
7
7
  outdir: `${argv.dir}/${TEST_OUT_FOLDER}`,
8
+ external: ["chai", "dotenv/config", "node:test"],
9
+ platform: "node",
8
10
  bundle: true,
9
11
  treeShaking: true,
10
12
  format: "esm",
11
13
  outExtension: {
12
- ".js": ".ts",
14
+ ".js": ".mjs",
13
15
  },
14
16
  plugins: [
15
- denoTestPrepPlugin(argv, {
17
+ nodeTestPrepPlugin(argv, {
16
18
  "@zuplo/test": "",
17
- chai: "https://cdn.skypack.dev/chai@4.3.4?dts",
18
19
  }),
19
20
  ],
20
21
  };
21
22
  }
22
23
  //# sourceMappingURL=esbuild-config.js.map
23
- //# debugId=f13aec76-f70a-5053-8b92-7e9a9134dbfc
24
+ //# debugId=5c127662-31c6-5178-a683-322b67f8580c
@@ -0,0 +1,65 @@
1
+
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="c847b970-590a-5cd3-b907-2b9fad49c028")}catch(e){}}();
3
+ export function nodeTestPrepPlugin(argv, options) {
4
+ const aliases = Object.keys(options);
5
+ const re = new RegExp(`^(${aliases.map((x) => escapeRegExp(x)).join("|")})$`);
6
+ return {
7
+ name: "alias",
8
+ setup(build) {
9
+ build.onResolve({ filter: re }, (args) => {
10
+ if (/@zuplo\/test/.test(args.path)) {
11
+ return {
12
+ path: args.path,
13
+ namespace: "zuplo-url",
14
+ };
15
+ }
16
+ else {
17
+ return {
18
+ path: options[args.path],
19
+ namespace: "zuplo-url",
20
+ external: true,
21
+ };
22
+ }
23
+ });
24
+ build.onLoad({ filter: /.*/, namespace: "zuplo-url" }, (args) => {
25
+ if (/@zuplo\/test/.test(args.path)) {
26
+ return { contents: generateTestContents(argv), loader: "ts" };
27
+ }
28
+ });
29
+ },
30
+ };
31
+ }
32
+ function escapeRegExp(value) {
33
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
34
+ }
35
+ function generateTestContents(argv) {
36
+ return `
37
+ import 'dotenv/config'
38
+ import { after, afterEach, describe, it, before, beforeEach } from "node:test"
39
+
40
+ export class TestHelper {
41
+ static get TEST_URL() {
42
+ const url = "${argv.endpoint}";
43
+ if (url !== "undefined") {
44
+ return url;
45
+ }
46
+
47
+ throw new Error("TEST_URL is not set. Pass --endpoint <URL> to \`zuplo test\` on the CLI to set a value.");
48
+ }
49
+
50
+ static get environment() {
51
+ return process.env;
52
+ }
53
+ }
54
+
55
+ const afterAll = after;
56
+ const beforeAll = before;
57
+
58
+ describe.ignore = describe.skip;
59
+ it.ignore = it.skip;
60
+
61
+ export {afterAll, afterEach, beforeAll, beforeEach, describe, it};
62
+ `;
63
+ }
64
+ //# sourceMappingURL=node-test-prep-plugin.js.map
65
+ //# debugId=c847b970-590a-5cd3-b907-2b9fad49c028
@@ -1,5 +1,5 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="1ca2f9a0-dd2a-5e05-9db2-0a83d26896ad")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="08888ef0-037c-5716-a727-dd52d53a2f00")}catch(e){}}();
3
3
  import fg from "fast-glob";
4
4
  import { rimrafSync } from "rimraf";
5
5
  import { TEST_IN_FOLDER, TEST_OUT_FOLDER } from "../common/constants.js";
@@ -25,4 +25,4 @@ export async function test(argv) {
25
25
  }
26
26
  }
27
27
  //# sourceMappingURL=handler.js.map
28
- //# debugId=1ca2f9a0-dd2a-5e05-9db2-0a83d26896ad
28
+ //# debugId=08888ef0-037c-5716-a727-dd52d53a2f00
@@ -1,28 +1,27 @@
1
1
 
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="a86033b8-649a-53cf-9f24-6b9f118258b4")}catch(e){}}();
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="91819abd-e850-5b4f-83ac-b91327da0a26")}catch(e){}}();
3
3
  import { execa } from "execa";
4
4
  import { TEST_OUT_FOLDER } from "../common/constants.js";
5
- import { locateDenoExecutable, MissingDenoExecutableError, } from "../common/deno-utils/locator.js";
6
5
  import { logger } from "../common/logger.js";
6
+ class MissingNodeExecutableError extends Error {
7
+ constructor() {
8
+ super("Missing executable: Cannot locate node executable");
9
+ Object.setPrototypeOf(this, MissingNodeExecutableError.prototype);
10
+ }
11
+ }
7
12
  export async function runTests(argv) {
8
- const denoExecutable = await locateDenoExecutable();
9
- if (denoExecutable) {
10
- const args = [
11
- "test",
12
- "--allow-env",
13
- "--allow-net",
14
- "--allow-read=.env,.env.defaults,.env.example,config/",
15
- "--no-check",
16
- ];
13
+ const nodeExecutable = process.platform === "win32" ? "node.exe" : "node";
14
+ if (nodeExecutable) {
15
+ const args = ["--test", "--test-reporter=spec"];
17
16
  if (argv.filter) {
18
- args.push("--filter", argv.filter);
17
+ args.push("--test-name-pattern", argv.filter);
19
18
  }
20
19
  args.push(`${argv.dir}/${TEST_OUT_FOLDER}`);
21
- const denoProcess = execa(denoExecutable, args);
22
- denoProcess.stdout?.pipe(process.stdout);
23
- denoProcess.stderr?.pipe(process.stderr);
20
+ const nodeProcess = execa(nodeExecutable, args);
21
+ nodeProcess.stdout?.pipe(process.stdout);
22
+ nodeProcess.stderr?.pipe(process.stderr);
24
23
  try {
25
- const result = await denoProcess;
24
+ const result = await nodeProcess;
26
25
  return result;
27
26
  }
28
27
  catch (err) {
@@ -31,8 +30,8 @@ export async function runTests(argv) {
31
30
  }
32
31
  }
33
32
  else {
34
- throw new MissingDenoExecutableError();
33
+ throw new MissingNodeExecutableError();
35
34
  }
36
35
  }
37
36
  //# sourceMappingURL=invoke-test.js.map
38
- //# debugId=a86033b8-649a-53cf-9f24-6b9f118258b4
37
+ //# debugId=91819abd-e850-5b4f-83ac-b91327da0a26
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zuplo/cli",
3
- "version": "1.138.0",
3
+ "version": "2.2.0",
4
4
  "type": "module",
5
5
  "repository": "https://github.com/zuplo/cli",
6
6
  "description": "The command-line interface for Zuplo",
@@ -9,9 +9,11 @@
9
9
  "scripts": {
10
10
  "update:zuplo-dependencies-safely": "./scripts/update-zuplo-dependencies.sh",
11
11
  "build": "tsc --build && node ./scripts/post-build.js",
12
+ "build:clean": "tsc --build --clean",
12
13
  "clean": "git clean -Xfde !.env",
13
14
  "sentry:sourcemaps": "sentry-cli sourcemaps inject --org zuplo --project zuplo-cli ./dist",
14
- "test": "node --test dist/**/*.spec.js"
15
+ "test": "find dist -name \"*.test.js\" | xargs node --test --test-only",
16
+ "test:ci": "find dist -name \"*.test.js\" | xargs node --test"
15
17
  },
16
18
  "engines": {
17
19
  "node": ">=18.0.0"
@@ -59,7 +61,6 @@
59
61
  "@sentry/node": "7.69.0",
60
62
  "@swc/core": "1.3.78",
61
63
  "@zuplo/core": "5.2458.0",
62
- "@zuplo/deno-bin": "1.37.1",
63
64
  "@zuplo/pino-pretty-configurations": "^1.5.0",
64
65
  "@zuplo/runtime": "5.2458.0",
65
66
  "chalk": "^5.1.2",
@@ -1,29 +0,0 @@
1
-
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="8edf8105-ebeb-518f-8885-8891eb778b11")}catch(e){}}();
3
- import { existsSync } from "node:fs";
4
- import { dirname, resolve } from "node:path";
5
- import { fileURLToPath } from "node:url";
6
- import { logger } from "../logger.js";
7
- export class MissingDenoExecutableError extends Error {
8
- constructor() {
9
- super("Missing executable: Cannot locate deno executable");
10
- Object.setPrototypeOf(this, MissingDenoExecutableError.prototype);
11
- }
12
- }
13
- export async function locateDenoExecutable() {
14
- return locateDeno(dirname(fileURLToPath(import.meta.url)));
15
- }
16
- export async function locateDeno(dir) {
17
- const DENO_EXECUTABLE = process.platform === "win32" ? "deno.exe" : "deno";
18
- if (dir === ".") {
19
- return undefined;
20
- }
21
- const pathToDeno = resolve(dir, "node_modules", "@zuplo/deno-bin", "bin", DENO_EXECUTABLE);
22
- if (await existsSync(pathToDeno)) {
23
- logger.debug(`Path to deno: ${pathToDeno}`);
24
- return pathToDeno;
25
- }
26
- return locateDeno(dirname(dir));
27
- }
28
- //# sourceMappingURL=locator.js.map
29
- //# debugId=8edf8105-ebeb-518f-8885-8891eb778b11
@@ -1,99 +0,0 @@
1
-
2
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="327f255c-47ca-568f-9b06-a3716ca6b328")}catch(e){}}();
3
- export function denoTestPrepPlugin(argv, options) {
4
- const aliases = Object.keys(options);
5
- const re = new RegExp(`^(${aliases.map((x) => escapeRegExp(x)).join("|")})$`);
6
- return {
7
- name: "alias",
8
- setup(build) {
9
- build.onResolve({ filter: re }, (args) => {
10
- if (/@zuplo\/test/.test(args.path)) {
11
- return {
12
- path: args.path,
13
- namespace: "deno-url",
14
- };
15
- }
16
- else {
17
- return {
18
- path: options[args.path],
19
- namespace: "deno-url",
20
- external: true,
21
- };
22
- }
23
- });
24
- build.onLoad({ filter: /.*/, namespace: "deno-url" }, (args) => {
25
- if (/@zuplo\/test/.test(args.path)) {
26
- return { contents: generateTestContents(argv), loader: "ts" };
27
- }
28
- });
29
- },
30
- };
31
- }
32
- function escapeRegExp(value) {
33
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
34
- }
35
- function generateTestContents(argv) {
36
- return `
37
-
38
- // Load environment variables
39
- import { load } from "https://deno.land/std@0.203.0/dotenv/mod.ts";
40
- await load();
41
-
42
- export class TestHelper {
43
- static get TEST_URL() {
44
- const url = "${argv.endpoint}";
45
- if (url !== "undefined") {
46
- return url;
47
- }
48
-
49
- throw new Error("TEST_URL is not set. Pass --endpoint <URL> to \`zuplo test\` on the CLI to set a value.");
50
- }
51
-
52
- static get environment() {
53
- return Deno.env.toObject();
54
- }
55
- }
56
-
57
- import {
58
- afterAll,
59
- afterEach,
60
- beforeAll,
61
- beforeEach,
62
- describe as originalDescribe,
63
- it,
64
- } from "https://deno.land/std@0.203.0/testing/bdd.ts";
65
-
66
- // We want to be able to disable test sanitizers by default to
67
- // make tests easier/more familiar to write.
68
-
69
- function describe<T>(
70
- name: string,
71
- fn: () => void | Promise<void>,
72
- ): TestSuite<T> {
73
- return originalDescribe(name, {
74
- sanitizeExit: false,
75
- sanitizeOps: false,
76
- sanitizeResources: false,
77
- }, fn);
78
- }
79
-
80
- describe.only = function describeOnly<T>(
81
- name: string,
82
- fn: () => void | Promise<void>,
83
- ): TestSuite<T> {
84
- return originalDescribe.only(name, fn);
85
- };
86
-
87
- describe.ignore = function describeIgnore<T>(
88
- name: string,
89
- fn: () => void | Promise<void>,
90
- ): TestSuite<T> {
91
- return originalDescribe.ignore(name, fn);
92
- };
93
-
94
- export {afterAll, afterEach, beforeAll, beforeEach, describe, it};
95
-
96
- `;
97
- }
98
- //# sourceMappingURL=deno-test-prep-plugin.js.map
99
- //# debugId=327f255c-47ca-568f-9b06-a3716ca6b328