Skip to content

Commit

Permalink
Update cli-kit to 3.52 (#1579)
Browse files Browse the repository at this point in the history
* Update cli and cli-kit to 3.52

* Remove workaround for bug fixed in cli-kit

* Add deferPromise utility and refactor

* Changesets

* Changesets
  • Loading branch information
frandiox authored Dec 20, 2023
1 parent 486bf39 commit b0d727d
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 64 deletions.
10 changes: 10 additions & 0 deletions .changeset/mean-foxes-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'skeleton': patch
---

Update `@shopify/cli` dependency in `package.json`:

```diff
- "@shopify/cli": "3.51.0",
+ "@shopify/cli": "3.52.0",
```
5 changes: 5 additions & 0 deletions .changeset/tender-cooks-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/cli-hydrogen': patch
---

Update cli-kit dependency for bug fixes.
2 changes: 1 addition & 1 deletion examples/customer-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"dependencies": {
"@remix-run/react": "2.1.0",
"@remix-run/server-runtime": "2.1.0",
"@shopify/cli": "3.51.0",
"@shopify/cli": "3.52.0",
"@shopify/cli-hydrogen": "^6.1.0",
"@shopify/hydrogen": "^2023.10.3",
"@shopify/remix-oxygen": "^2.0.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"devDependencies": {
"@remix-run/dev": "2.1.0",
"@remix-run/eslint-config": "2.1.0",
"@shopify/cli": "3.51.0",
"@shopify/cli": "3.52.0",
"@shopify/cli-hydrogen": "^6.1.0",
"@types/compression": "^1.7.2",
"@types/express": "^4.17.17",
Expand Down
2 changes: 1 addition & 1 deletion examples/optimistic-cart-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"dependencies": {
"@remix-run/react": "2.1.0",
"@remix-run/server-runtime": "2.1.0",
"@shopify/cli": "3.51.0",
"@shopify/cli": "3.52.0",
"@shopify/cli-hydrogen": "^6.1.0",
"@shopify/hydrogen": "~2023.10.3",
"@shopify/remix-oxygen": "^2.0.2",
Expand Down
82 changes: 41 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@ast-grep/napi": "0.11.0",
"@graphql-codegen/cli": "5.0.0",
"@oclif/core": "2.11.7",
"@shopify/cli-kit": "3.51.0",
"@shopify/cli-kit": "3.52.0",
"@shopify/hydrogen-codegen": "^0.1.0",
"@shopify/mini-oxygen": "^2.2.4",
"@shopify/oxygen-cli": "^3.1.5",
Expand Down
23 changes: 7 additions & 16 deletions packages/cli/src/lib/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from './shopify-config.js';
import {getUserAccount} from './graphql/business-platform/user-account.js';
import {muteAuthLogs} from './log.js';
import {deferPromise} from './defer.js';

export type {AdminSession};

Expand Down Expand Up @@ -62,21 +63,12 @@ export async function login(root?: string, shop?: string | true) {
forcePrompt ||
shop !== existingConfig.shop
) {
// There's some bug in cli-kit that causes the process to exit when
// waiting for `keypress` in some situations. It seems that Node gets
// in a state where the event loop is empty while awaiting, and then exits.
// Adding a dummy timeout here to keep the event loop busy fixes it.
// Ref: https://github.com/Shopify/cli/issues/3055
const dummyTimeout = setTimeout(() => {}, 600000);

const token = await ensureAuthenticatedBusinessPlatform().catch(() => {
throw new AbortError(
'Unable to authenticate with Shopify. Please report this issue.',
);
});

clearTimeout(dummyTimeout);

const userAccount = await getUserAccount(token);
await hideLoginInfo();

Expand Down Expand Up @@ -116,10 +108,7 @@ export async function login(root?: string, shop?: string | true) {
}

function showLoginInfo() {
let deferredResolve: (value?: unknown) => void;
const promise = new Promise((resolve) => {
deferredResolve = resolve;
});
const deferred = deferPromise();

console.log('');

Expand Down Expand Up @@ -161,25 +150,27 @@ function showLoginInfo() {
{
title: 'Waiting for Shopify authentication',
task: async () => {
await promise;
await deferred.promise;
},
},
]);
});
},
});

promise.then(() => {
deferred.promise.then(() => {
restoreLogs();
if (hasLoggedPressKey) {
process.stdout.write(ansiEscapes.eraseLines(hasLoggedTimeout ? 11 : 10));
}
});

return async () => {
deferredResolve();
deferred.resolve();
// Without this timeout the process exits
// right after `renderTasks` is done.
// In some cases, it makes renderPrompt to return
// `undefined` without showing the prompt.
await new Promise((resolve) => setTimeout(resolve, 0));
};
}
Expand Down
14 changes: 14 additions & 0 deletions packages/cli/src/lib/defer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Creates a promise that can be resolved or rejected from the outter scope.
*/
export function deferPromise() {
let resolve = (value?: unknown) => {};
let reject = resolve;

const promise = new Promise((_resolve, _reject) => {
resolve = _resolve;
reject = _reject;
});

return {promise, resolve, reject};
}
Loading

0 comments on commit b0d727d

Please sign in to comment.