@shopify/oxygen-cli 1.12.1-unstable.202309120942.0 → 1.12.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.12.1-unstable.202309120942.0",
2
+ "version": "1.12.1",
3
3
  "commands": {
4
4
  "oxygen:deploy": {
5
5
  "id": "oxygen:deploy",
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "@shopify:registry": "https://registry.npmjs.org"
6
6
  },
7
7
  "license": "MIT",
8
- "version": "1.12.1-unstable.202309120942.0",
8
+ "version": "1.12.1",
9
9
  "type": "module",
10
10
  "scripts": {
11
11
  "build": "tsup --clean --config ./tsup.config.ts && oclif manifest",
@@ -15,9 +15,8 @@
15
15
  "lint": "eslint --ext .js,.ts --max-warnings 0 src",
16
16
  "lint:format": "prettier --write \"**/*.*\" && npm run lint --fix",
17
17
  "generate:manifest": "oclif manifest",
18
- "prepack": "npm install && npm run build",
19
- "prepublishOnly": "rm -rf dist/**/*.test.*",
20
- "release": "npm run build && npx changeset publish && git push --follow-tags",
18
+ "prepublishOnly": "npm install && npm run build && rm -rf dist/**/*.test.*",
19
+ "release": "npm run prepublishOnly && npx changeset publish && git push --follow-tags",
21
20
  "test": "vitest run",
22
21
  "test:watch": "vitest"
23
22
  },
@@ -25,7 +24,7 @@
25
24
  "oxygen-cli": "./dist/oxygen-cli.js"
26
25
  },
27
26
  "engines": {
28
- "node": ">=14.17.0"
27
+ "node": ">=16.14.0"
29
28
  },
30
29
  "exports": {
31
30
  "./deploy": "./dist/deploy/index.js"
@@ -36,7 +35,7 @@
36
35
  ],
37
36
  "dependencies": {
38
37
  "@oclif/core": "2.15.0",
39
- "@shopify/cli-kit": "nightly",
38
+ "@shopify/cli-kit": "^3.49.3",
40
39
  "async": "^3.2.4"
41
40
  },
42
41
  "devDependencies": {
@@ -44,7 +43,7 @@
44
43
  "@shopify/eslint-plugin": "^43.0.0",
45
44
  "@shopify/prettier-config": "^1.1.2",
46
45
  "@types/async": "^3.2.18",
47
- "@types/node": "^20.5.9",
46
+ "@types/node": "^20.6.3",
48
47
  "eslint": "^8.49.0",
49
48
  "eslint-plugin-prettier": "^5.0.0",
50
49
  "node-fetch": "^3.3.2",
@@ -52,7 +51,7 @@
52
51
  "tsup": "^7.2.0",
53
52
  "typescript": "^5.2.2",
54
53
  "vite": "^4.4.9",
55
- "vitest": "^0.34.4"
54
+ "vitest": "^0.34.5"
56
55
  },
57
56
  "prettier": "@shopify/prettier-config",
58
57
  "oclif": {
@@ -1,2 +0,0 @@
1
-
2
- export { }
@@ -1,90 +0,0 @@
1
- import { AbortError } from '@shopify/cli-kit/node/error';
2
- import { graphqlRequest } from '@shopify/cli-kit/node/api/graphql';
3
- import { vi, describe, test, expect } from 'vitest';
4
- import { createTestConfig } from '../utils/test-helper.js';
5
- import { stderrLogger, Header } from '../utils/utils.js';
6
- import { buildCancel } from './build-cancel.js';
7
-
8
- vi.mock("@shopify/cli-kit/node/api/graphql");
9
- vi.mock("@shopify/cli-kit/node/output", () => {
10
- return {
11
- outputInfo: vi.fn()
12
- };
13
- });
14
- const testConfig = createTestConfig("/tmp/deploymentRoot/");
15
- describe("BuildCancel", () => {
16
- test("should cancel a build", async () => {
17
- const response = {
18
- buildCancel: {
19
- userErrors: []
20
- }
21
- };
22
- vi.mocked(graphqlRequest).mockResolvedValueOnce(response);
23
- const cancelResponse = await buildCancel({
24
- config: testConfig,
25
- buildId: "build-1",
26
- reason: "because",
27
- logger: stderrLogger
28
- });
29
- expect(cancelResponse).toEqual(response.buildCancel);
30
- expect(graphqlRequest).toHaveBeenCalledWith({
31
- query: expect.any(String),
32
- api: "Oxygen",
33
- url: `${testConfig.deploymentUrl}/api/v2/admin/graphql`,
34
- token: testConfig.deploymentToken.accessToken,
35
- variables: {
36
- buildId: "build-1",
37
- reason: "because"
38
- },
39
- addedHeaders: {
40
- [Header.OxygenNamespaceHandle]: `${testConfig.deploymentToken.namespace}`
41
- }
42
- });
43
- });
44
- test("should throw AbortError when buildCancel fails with error", async () => {
45
- const response = {
46
- buildCancel: {
47
- userErrors: [
48
- {
49
- message: "Cannot cancel build."
50
- }
51
- ]
52
- }
53
- };
54
- vi.mocked(graphqlRequest).mockResolvedValueOnce(response);
55
- await expect(
56
- buildCancel({
57
- config: testConfig,
58
- buildId: "build-1",
59
- reason: "because",
60
- logger: stderrLogger
61
- })
62
- ).rejects.toThrow(
63
- new AbortError(
64
- `Failed to cancel build: ${response.buildCancel.userErrors[0]?.message}`
65
- )
66
- );
67
- });
68
- test("should throw AbortError when unauthorized", async () => {
69
- const error = {
70
- statusCode: 401
71
- };
72
- vi.mocked(graphqlRequest).mockRejectedValueOnce(error);
73
- try {
74
- await expect(
75
- buildCancel({
76
- config: testConfig,
77
- buildId: "build-1",
78
- reason: "because",
79
- logger: stderrLogger
80
- })
81
- ).rejects.toThrow(
82
- new AbortError(
83
- "You are not authorized to perform this action. Please check your deployment token."
84
- )
85
- );
86
- } catch (err) {
87
- expect(error).toBeInstanceOf(AbortError);
88
- }
89
- });
90
- });
@@ -1,2 +0,0 @@
1
-
2
- export { }
@@ -1,93 +0,0 @@
1
- import { AbortError } from '@shopify/cli-kit/node/error';
2
- import { graphqlRequest } from '@shopify/cli-kit/node/api/graphql';
3
- import { outputCompleted } from '@shopify/cli-kit/node/output';
4
- import { vi, describe, test, expect } from 'vitest';
5
- import { stderrLogger, Header } from '../utils/utils.js';
6
- import { createTestConfig } from '../utils/test-helper.js';
7
- import { buildInitiate } from './build-initiate.js';
8
-
9
- vi.mock("@shopify/cli-kit/node/api/graphql");
10
- vi.mock("@shopify/cli-kit/node/output");
11
- const testConfig = createTestConfig("/tmp/deploymentRoot/");
12
- describe("BuildInitiate", () => {
13
- test("should initiate a build", async () => {
14
- const response = {
15
- buildInitiate: {
16
- build: {
17
- id: "build-1"
18
- },
19
- userErrors: []
20
- }
21
- };
22
- vi.mocked(graphqlRequest).mockResolvedValueOnce(response);
23
- const initiateResponse = await buildInitiate({
24
- config: testConfig,
25
- environment: {
26
- tag: testConfig.environmentTag
27
- },
28
- labels: [],
29
- logger: stderrLogger
30
- });
31
- expect(initiateResponse).toEqual(response.buildInitiate);
32
- expect(graphqlRequest).toHaveBeenCalledWith({
33
- query: expect.any(String),
34
- api: "Oxygen",
35
- url: `${testConfig.deploymentUrl}/api/v2/admin/graphql`,
36
- token: testConfig.deploymentToken.accessToken,
37
- variables: { environment: { tag: testConfig.environmentTag }, labels: [] },
38
- addedHeaders: {
39
- [Header.OxygenNamespaceHandle]: `${testConfig.deploymentToken.namespace}`
40
- }
41
- });
42
- expect(outputCompleted).toHaveBeenCalledWith(
43
- "Build initiated successfully with id build-1.",
44
- stderrLogger
45
- );
46
- });
47
- test("should throw AbortError when build initiation fails due to user errors", async () => {
48
- const response = {
49
- buildInitiate: {
50
- userErrors: [
51
- {
52
- message: "Error: cannot proceed with build."
53
- }
54
- ]
55
- }
56
- };
57
- vi.mocked(graphqlRequest).mockResolvedValueOnce(response);
58
- await expect(
59
- buildInitiate({
60
- config: testConfig,
61
- environment: { tag: "preview" },
62
- labels: [],
63
- logger: stderrLogger
64
- })
65
- ).rejects.toThrow(
66
- new AbortError(
67
- `Failed to create build. ${response.buildInitiate.userErrors[0]?.message}`
68
- )
69
- );
70
- });
71
- test("should throw AbortError when unauthorized", async () => {
72
- const error = {
73
- statusCode: 401
74
- };
75
- vi.mocked(graphqlRequest).mockRejectedValueOnce(error);
76
- try {
77
- await expect(
78
- buildInitiate({
79
- config: testConfig,
80
- environment: { tag: "preview" },
81
- labels: [],
82
- logger: stderrLogger
83
- })
84
- ).rejects.toThrow(
85
- new AbortError(
86
- "You are not authorized to perform this action. Please check your deployment token."
87
- )
88
- );
89
- } catch (err) {
90
- expect(error).toBeInstanceOf(AbortError);
91
- }
92
- });
93
- });
@@ -1,2 +0,0 @@
1
-
2
- export { }
@@ -1,68 +0,0 @@
1
- import { spawn } from 'child_process';
2
- import { vi, test, expect } from 'vitest';
3
- import { createTestConfig } from '../utils/test-helper.js';
4
- import { buildProject } from './build-project.js';
5
-
6
- let returnCode = 0;
7
- vi.mock("child_process", () => {
8
- const spawn2 = vi.fn();
9
- spawn2.mockImplementation(() => {
10
- return {
11
- stdout: {
12
- on: () => {
13
- },
14
- pipe: () => {
15
- }
16
- },
17
- on: (event, callback) => {
18
- if (event === "close") {
19
- return callback(returnCode);
20
- }
21
- }
22
- };
23
- });
24
- return { spawn: spawn2 };
25
- });
26
- const testConfig = createTestConfig("rootFolder");
27
- test("BuildProject builds the project successfully", async () => {
28
- const config = {
29
- ...testConfig,
30
- buildCommand: "npm run build"
31
- };
32
- const assetPath = "https://example.com/assets";
33
- await buildProject({ config, assetPath });
34
- expect(spawn).toBeCalledWith("npm run build", [], {
35
- cwd: "rootFolder",
36
- shell: true,
37
- stdio: ["inherit", process.stderr, "inherit"],
38
- env: {
39
- // eslint-disable-next-line no-process-env
40
- ...process.env,
41
- HYDROGEN_ASSET_BASE_URL: "https://example.com/assets"
42
- }
43
- });
44
- });
45
- test("should throw error on build command failure", async () => {
46
- returnCode = 1;
47
- const assetPath = "https://example.com/assets";
48
- await expect(
49
- () => buildProject({ config: testConfig, assetPath })
50
- ).rejects.toThrow("Build failed with error code: 1");
51
- });
52
- test("should call buildFunction hook if provided", async () => {
53
- const buildFunction = vi.fn().mockResolvedValue(void 0);
54
- const hooks = { buildFunction };
55
- const assetPath = "https://example.com/assets";
56
- await buildProject({ config: testConfig, assetPath, hooks });
57
- expect(buildFunction).toBeCalledWith(assetPath);
58
- });
59
- test("should throw error if buildFunction hook fails", async () => {
60
- const buildFunction = vi.fn().mockRejectedValue(new Error("Oops! I tripped over a cable."));
61
- const hooks = { buildFunction };
62
- const assetPath = "https://example.com/assets";
63
- await expect(
64
- () => buildProject({ config: testConfig, assetPath, hooks })
65
- ).rejects.toThrow(
66
- "Build function failed with error: Error: Oops! I tripped over a cable."
67
- );
68
- });
@@ -1,2 +0,0 @@
1
-
2
- export { }
@@ -1,89 +0,0 @@
1
- import { AbortError } from '@shopify/cli-kit/node/error';
2
- import { graphqlRequest } from '@shopify/cli-kit/node/api/graphql';
3
- import { vi, describe, test, expect } from 'vitest';
4
- import { createTestConfig } from '../utils/test-helper.js';
5
- import { stderrLogger, Header } from '../utils/utils.js';
6
- import { deploymentCancel } from './deployment-cancel.js';
7
-
8
- vi.mock("@shopify/cli-kit/node/api/graphql");
9
- vi.mock("@shopify/cli-kit/node/output");
10
- const testConfig = createTestConfig("/tmp/deploymentRoot");
11
- describe("DeploymentComplete", () => {
12
- test("should cancel a deployment", async () => {
13
- const response = {
14
- deploymentCancel: {
15
- deployment: {
16
- id: "deployment-1"
17
- },
18
- userErrors: []
19
- }
20
- };
21
- vi.mocked(graphqlRequest).mockResolvedValueOnce(response);
22
- const completeResponse = await deploymentCancel({
23
- config: testConfig,
24
- deploymentId: "deployment-1",
25
- reason: "error message",
26
- logger: stderrLogger
27
- });
28
- expect(completeResponse).toEqual(response.deploymentCancel);
29
- expect(graphqlRequest).toHaveBeenCalledWith({
30
- query: expect.any(String),
31
- api: "Oxygen",
32
- url: `${testConfig.deploymentUrl}/api/v2/admin/graphql`,
33
- token: testConfig.deploymentToken.accessToken,
34
- variables: {
35
- deploymentId: "deployment-1",
36
- reason: "error message"
37
- },
38
- addedHeaders: {
39
- [Header.OxygenNamespaceHandle]: `${testConfig.deploymentToken.namespace}`
40
- }
41
- });
42
- });
43
- test("should throw AbortError when deploymentComplete fails with error", async () => {
44
- const response = {
45
- deploymentCancel: {
46
- userErrors: [
47
- {
48
- message: "Cannot cancel deployment."
49
- }
50
- ]
51
- }
52
- };
53
- vi.mocked(graphqlRequest).mockResolvedValueOnce(response);
54
- await expect(
55
- deploymentCancel({
56
- config: testConfig,
57
- deploymentId: "deployment-1",
58
- reason: "error message",
59
- logger: stderrLogger
60
- })
61
- ).rejects.toThrow(
62
- new AbortError(
63
- `Failed to cancel deployment: ${response.deploymentCancel.userErrors[0]?.message}`
64
- )
65
- );
66
- });
67
- test("should throw AbortError when unauthorized", async () => {
68
- const error = {
69
- statusCode: 401
70
- };
71
- vi.mocked(graphqlRequest).mockRejectedValueOnce(error);
72
- try {
73
- await expect(
74
- deploymentCancel({
75
- config: testConfig,
76
- deploymentId: "deployment-1",
77
- reason: "error message",
78
- logger: stderrLogger
79
- })
80
- ).rejects.toThrow(
81
- new AbortError(
82
- "You are not authorized to perform this action. Please check your deployment token."
83
- )
84
- );
85
- } catch (err) {
86
- expect(error).toBeInstanceOf(AbortError);
87
- }
88
- });
89
- });
@@ -1,2 +0,0 @@
1
-
2
- export { }
@@ -1,77 +0,0 @@
1
- import { AbortError } from '@shopify/cli-kit/node/error';
2
- import { graphqlRequest } from '@shopify/cli-kit/node/api/graphql';
3
- import { vi, describe, test, expect } from 'vitest';
4
- import { createTestConfig } from '../utils/test-helper.js';
5
- import { Header } from '../utils/utils.js';
6
- import { deploymentComplete } from './deployment-complete.js';
7
-
8
- vi.mock("@shopify/cli-kit/node/api/graphql");
9
- const testConfig = createTestConfig("/tmp/deploymentRoot");
10
- describe("DeploymentComplete", () => {
11
- test("should complete a deployment", async () => {
12
- const response = {
13
- deploymentComplete: {
14
- deployment: {
15
- id: "deployment-1",
16
- status: "pending",
17
- url: "https://www.go-here.com"
18
- },
19
- userErrors: []
20
- }
21
- };
22
- vi.mocked(graphqlRequest).mockResolvedValueOnce(response);
23
- const completeResponse = await deploymentComplete(
24
- testConfig,
25
- "deployment-1"
26
- );
27
- expect(completeResponse).toEqual(response.deploymentComplete);
28
- expect(graphqlRequest).toHaveBeenCalledWith({
29
- query: expect.any(String),
30
- api: "Oxygen",
31
- url: `${testConfig.deploymentUrl}/api/v2/admin/graphql`,
32
- token: testConfig.deploymentToken.accessToken,
33
- variables: {
34
- deploymentId: "deployment-1"
35
- },
36
- addedHeaders: {
37
- [Header.OxygenNamespaceHandle]: `${testConfig.deploymentToken.namespace}`
38
- }
39
- });
40
- });
41
- test("should throw AbortError when deploymentComplete fails with error", async () => {
42
- const response = {
43
- deploymentComplete: {
44
- userErrors: [
45
- {
46
- message: "Cannot complete deployment."
47
- }
48
- ]
49
- }
50
- };
51
- vi.mocked(graphqlRequest).mockResolvedValueOnce(response);
52
- await expect(
53
- deploymentComplete(testConfig, "deployment-1")
54
- ).rejects.toThrow(
55
- new AbortError(
56
- `Failed to complete deployment: ${response.deploymentComplete.userErrors[0]?.message}`
57
- )
58
- );
59
- });
60
- test("should throw AbortError when unauthorized", async () => {
61
- const error = {
62
- statusCode: 401
63
- };
64
- vi.mocked(graphqlRequest).mockRejectedValueOnce(error);
65
- try {
66
- await expect(
67
- deploymentComplete(testConfig, "deployment-1")
68
- ).rejects.toThrow(
69
- new AbortError(
70
- "You are not authorized to perform this action. Please check your deployment token."
71
- )
72
- );
73
- } catch (err) {
74
- expect(error).toBeInstanceOf(AbortError);
75
- }
76
- });
77
- });
@@ -1,2 +0,0 @@
1
-
2
- export { }
@@ -1,156 +0,0 @@
1
- import { AbortError } from '@shopify/cli-kit/node/error';
2
- import { graphqlRequest } from '@shopify/cli-kit/node/api/graphql';
3
- import { outputCompleted } from '@shopify/cli-kit/node/output';
4
- import { vi, describe, test, expect } from 'vitest';
5
- import { createTestConfig } from '../utils/test-helper.js';
6
- import { stderrLogger, Header } from '../utils/utils.js';
7
- import { deploymentInitiate } from './deployment-initiate.js';
8
-
9
- vi.mock("@shopify/cli-kit/node/api/graphql");
10
- vi.mock("@shopify/cli-kit/node/output");
11
- const testConfig = createTestConfig("/tmp/deploymentRoot");
12
- const testManifest = [
13
- {
14
- filePath: "index.js",
15
- fileSize: 20,
16
- mimeType: "application/javascript",
17
- fileType: "WORKER",
18
- fileHash: "b62d550d0cae0c4f15e0e16fc2492893"
19
- }
20
- ];
21
- const testResponse = {
22
- deploymentInitiate: {
23
- deployment: {
24
- id: "gid://oxygen-hub/Deployment/1"
25
- },
26
- deploymentTargets: [
27
- {
28
- filePath: "index.js",
29
- fileSize: 20,
30
- uploadUrl: "https://storage.googleapis.com/dms-assets-test/",
31
- fileType: "WORKER",
32
- parameters: []
33
- }
34
- ],
35
- userErrors: []
36
- }
37
- };
38
- describe("DeploymentInitiate", () => {
39
- test("should initiate a deployment with a buildId", async () => {
40
- vi.mocked(graphqlRequest).mockResolvedValueOnce(testResponse);
41
- const initiateResponse = await deploymentInitiate({
42
- config: testConfig,
43
- input: {
44
- buildId: "build-1",
45
- manifest: testManifest
46
- },
47
- logger: stderrLogger
48
- });
49
- expect(initiateResponse).toEqual(testResponse.deploymentInitiate);
50
- expect(graphqlRequest).toHaveBeenCalledWith({
51
- query: expect.any(String),
52
- api: "Oxygen",
53
- url: `${testConfig.deploymentUrl}/api/v2/admin/graphql`,
54
- token: testConfig.deploymentToken.accessToken,
55
- variables: {
56
- buildId: "build-1",
57
- environment: void 0,
58
- files: testManifest,
59
- isPrivate: true
60
- },
61
- addedHeaders: {
62
- [Header.OxygenNamespaceHandle]: `${testConfig.deploymentToken.namespace}`
63
- }
64
- });
65
- expect(outputCompleted).toHaveBeenCalledWith(
66
- `Deployment initiated, ${testManifest.length} files to upload.`,
67
- stderrLogger
68
- );
69
- });
70
- test("should initiate a deployment with an environmentName", async () => {
71
- vi.mocked(graphqlRequest).mockResolvedValueOnce(testResponse);
72
- const initiateResponse = await deploymentInitiate({
73
- config: testConfig,
74
- input: {
75
- buildId: void 0,
76
- environment: { tag: "preview" },
77
- manifest: testManifest
78
- },
79
- logger: stderrLogger
80
- });
81
- expect(initiateResponse).toEqual(testResponse.deploymentInitiate);
82
- expect(graphqlRequest).toHaveBeenCalledWith({
83
- query: expect.any(String),
84
- api: "Oxygen",
85
- url: `${testConfig.deploymentUrl}/api/v2/admin/graphql`,
86
- token: testConfig.deploymentToken.accessToken,
87
- variables: {
88
- buildId: void 0,
89
- environment: { tag: "preview" },
90
- files: testManifest,
91
- isPrivate: true
92
- },
93
- addedHeaders: {
94
- [Header.OxygenNamespaceHandle]: `${testConfig.deploymentToken.namespace}`
95
- }
96
- });
97
- expect(outputCompleted).toHaveBeenCalledWith(
98
- `Deployment initiated, ${testManifest.length} files to upload.`,
99
- stderrLogger
100
- );
101
- });
102
- test("should throw AbortError when deployment initiation fails due to user errors", async () => {
103
- const response = {
104
- deploymentInitiate: {
105
- userErrors: [
106
- {
107
- message: "Error: cannot proceed with deployment."
108
- }
109
- ]
110
- }
111
- };
112
- vi.mocked(graphqlRequest).mockResolvedValueOnce(response);
113
- const deploymentInitData = {
114
- buildId: void 0,
115
- environment: { tag: "preview" },
116
- manifest: testManifest
117
- };
118
- await expect(
119
- deploymentInitiate({
120
- config: testConfig,
121
- input: deploymentInitData,
122
- logger: stderrLogger
123
- })
124
- ).rejects.toThrow(
125
- new AbortError(
126
- `Failed to create deployment. ${response.deploymentInitiate.userErrors[0]?.message}`
127
- )
128
- );
129
- });
130
- test("should throw AbortError when unauthorized", async () => {
131
- const error = {
132
- statusCode: 401
133
- };
134
- vi.mocked(graphqlRequest).mockRejectedValueOnce(error);
135
- try {
136
- const deploymentInitData = {
137
- buildId: void 0,
138
- environment: { tag: "preview" },
139
- manifest: testManifest
140
- };
141
- await expect(
142
- deploymentInitiate({
143
- config: testConfig,
144
- input: deploymentInitData,
145
- logger: stderrLogger
146
- })
147
- ).rejects.toThrow(
148
- new AbortError(
149
- "You are not authorized to perform this action. Please check your deployment token."
150
- )
151
- );
152
- } catch (err) {
153
- expect(error).toBeInstanceOf(AbortError);
154
- }
155
- });
156
- });
@@ -1,2 +0,0 @@
1
-
2
- export { }