@shopify/cli-kit 3.33.0 → 3.34.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/dist/constants.d.ts +2 -5
- package/dist/constants.js +0 -3
- package/dist/constants.js.map +1 -1
- package/dist/file.d.ts +1 -1
- package/dist/git.js +1 -1
- package/dist/git.js.map +1 -1
- package/dist/http.js +2 -2
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/dist/metadata.js +1 -1
- package/dist/metadata.js.map +1 -1
- package/dist/output.js +1 -1
- package/dist/output.js.map +1 -1
- package/dist/path.d.ts +1 -1
- package/dist/path.js +5 -3
- package/dist/path.js.map +1 -1
- package/dist/private/node/analytics.js +6 -9
- package/dist/private/node/analytics.js.map +1 -1
- package/dist/private/node/api/graphql.js +1 -0
- package/dist/private/node/api/graphql.js.map +1 -1
- package/dist/private/node/api/headers.js +1 -1
- package/dist/private/node/api/headers.js.map +1 -1
- package/dist/private/node/api/rest.d.ts +1 -1
- package/dist/private/node/api/rest.js.map +1 -1
- package/dist/private/node/environment/service.d.ts +18 -0
- package/dist/private/node/environment/service.js +32 -0
- package/dist/private/node/environment/service.js.map +1 -0
- package/dist/{environment → private/node/environment}/spin-cache.d.ts +0 -0
- package/dist/{environment → private/node/environment}/spin-cache.js +0 -0
- package/dist/private/node/environment/spin-cache.js.map +1 -0
- package/dist/{environment → private/node/environment}/utilities.d.ts +0 -0
- package/dist/{environment → private/node/environment}/utilities.js +0 -0
- package/dist/private/node/environment/utilities.js.map +1 -0
- package/dist/{session → private/node/session}/authorize.d.ts +1 -5
- package/dist/{session → private/node/session}/authorize.js +9 -9
- package/dist/private/node/session/authorize.js.map +1 -0
- package/dist/{session → private/node/session}/device-authorization.d.ts +0 -0
- package/dist/{session → private/node/session}/device-authorization.js +7 -9
- package/dist/private/node/session/device-authorization.js.map +1 -0
- package/dist/{session → private/node/session}/exchange.d.ts +2 -2
- package/dist/{session → private/node/session}/exchange.js +5 -5
- package/dist/private/node/session/exchange.js.map +1 -0
- package/dist/{session → private/node/session}/identity-token-validation.d.ts +0 -0
- package/dist/{session → private/node/session}/identity-token-validation.js +4 -4
- package/dist/private/node/session/identity-token-validation.js.map +1 -0
- package/dist/{session → private/node/session}/identity.d.ts +1 -1
- package/dist/{session → private/node/session}/identity.js +2 -3
- package/dist/private/node/session/identity.js.map +1 -0
- package/dist/{session → private/node/session}/post-auth.d.ts +1 -1
- package/dist/{session → private/node/session}/post-auth.js +3 -3
- package/dist/private/node/session/post-auth.js.map +1 -0
- package/dist/{session → private/node/session}/redirect-listener.d.ts +0 -0
- package/dist/{session → private/node/session}/redirect-listener.js +2 -2
- package/dist/private/node/session/redirect-listener.js.map +1 -0
- package/dist/{session → private/node/session}/schema.d.ts +1 -1
- package/dist/{session → private/node/session}/schema.js +1 -1
- package/dist/private/node/session/schema.js.map +1 -0
- package/dist/{session → private/node/session}/scopes.d.ts +1 -1
- package/dist/{session → private/node/session}/scopes.js +2 -2
- package/dist/private/node/session/scopes.js.map +1 -0
- package/dist/{session → private/node/session}/store.d.ts +0 -0
- package/dist/{session → private/node/session}/store.js +5 -5
- package/dist/private/node/session/store.js.map +1 -0
- package/dist/{session → private/node/session}/validate.d.ts +0 -0
- package/dist/{session → private/node/session}/validate.js +3 -3
- package/dist/private/node/session/validate.js.map +1 -0
- package/dist/private/node/session.d.ts +56 -0
- package/dist/{session.js → private/node/session.js} +97 -133
- package/dist/private/node/session.js.map +1 -0
- package/dist/private/node/ui.js +1 -1
- package/dist/private/node/ui.js.map +1 -1
- package/dist/public/node/analytics.js +3 -3
- package/dist/public/node/analytics.js.map +1 -1
- package/dist/public/node/api/admin.d.ts +1 -1
- package/dist/public/node/api/admin.js.map +1 -1
- package/dist/public/node/api/partners.js +1 -1
- package/dist/public/node/api/partners.js.map +1 -1
- package/dist/public/node/base-command.js +2 -2
- package/dist/public/node/base-command.js.map +1 -1
- package/dist/public/node/cli.d.ts +8 -0
- package/dist/public/node/cli.js +21 -4
- package/dist/public/node/cli.js.map +1 -1
- package/dist/public/node/environment/fqdn.d.ts +26 -0
- package/dist/{environment → public/node/environment}/fqdn.js +15 -31
- package/dist/public/node/environment/fqdn.js.map +1 -0
- package/dist/{environment → public/node/environment}/local.d.ts +62 -15
- package/dist/{environment → public/node/environment}/local.js +66 -21
- package/dist/public/node/environment/local.js.map +1 -0
- package/dist/public/node/environment/spin.d.ts +43 -0
- package/dist/{environment → public/node/environment}/spin.js +28 -35
- package/dist/public/node/environment/spin.js.map +1 -0
- package/dist/public/node/node-package-manager.js +1 -1
- package/dist/public/node/node-package-manager.js.map +1 -1
- package/dist/public/node/ruby.d.ts +1 -1
- package/dist/public/node/ruby.js +11 -12
- package/dist/public/node/ruby.js.map +1 -1
- package/dist/public/node/session.d.ts +53 -0
- package/dist/public/node/session.js +95 -0
- package/dist/public/node/session.js.map +1 -0
- package/dist/public/node/system.d.ts +44 -0
- package/dist/{system.js → public/node/system.js} +34 -54
- package/dist/public/node/system.js.map +1 -0
- package/dist/public/node/tcp.js +1 -1
- package/dist/public/node/tcp.js.map +1 -1
- package/dist/testing/ui.js +1 -1
- package/dist/testing/ui.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/ui.js +1 -1
- package/dist/ui.js.map +1 -1
- package/package.json +9 -6
- package/dist/cli.d.ts +0 -8
- package/dist/cli.js +0 -18
- package/dist/cli.js.map +0 -1
- package/dist/environment/fqdn.d.ts +0 -29
- package/dist/environment/fqdn.js.map +0 -1
- package/dist/environment/local.js.map +0 -1
- package/dist/environment/service.d.ts +0 -4
- package/dist/environment/service.js +0 -19
- package/dist/environment/service.js.map +0 -1
- package/dist/environment/spin-cache.js.map +0 -1
- package/dist/environment/spin.d.ts +0 -50
- package/dist/environment/spin.js.map +0 -1
- package/dist/environment/utilities.js.map +0 -1
- package/dist/environment.d.ts +0 -7
- package/dist/environment.js +0 -8
- package/dist/environment.js.map +0 -1
- package/dist/network/service.d.ts +0 -14
- package/dist/network/service.js +0 -11
- package/dist/network/service.js.map +0 -1
- package/dist/session/authorize.js.map +0 -1
- package/dist/session/device-authorization.js.map +0 -1
- package/dist/session/exchange.js.map +0 -1
- package/dist/session/identity-token-validation.js.map +0 -1
- package/dist/session/identity.js.map +0 -1
- package/dist/session/post-auth.js.map +0 -1
- package/dist/session/redirect-listener.js.map +0 -1
- package/dist/session/schema.js.map +0 -1
- package/dist/session/scopes.js.map +0 -1
- package/dist/session/store.js.map +0 -1
- package/dist/session/token.d.ts +0 -40
- package/dist/session/token.js +0 -22
- package/dist/session/token.js.map +0 -1
- package/dist/session/validate.js.map +0 -1
- package/dist/session.d.ts +0 -96
- package/dist/session.js.map +0 -1
- package/dist/system.d.ts +0 -51
- package/dist/system.js.map +0 -1
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { isTruthy } from '
|
|
2
|
-
import
|
|
3
|
-
import constants from '../constants.js';
|
|
1
|
+
import { isTruthy } from '../../../private/node/environment/utilities.js';
|
|
2
|
+
import constants from '../../../constants.js';
|
|
4
3
|
import { captureOutput } from '../system.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
4
|
+
import { content, token } from '../../../output.js';
|
|
5
|
+
import { exists, readSync } from '../../../file.js';
|
|
6
|
+
import { getCachedSpinFqdn, setCachedSpinFqdn } from '../../../private/node/environment/spin-cache.js';
|
|
7
|
+
import { Abort } from '../../../error.js';
|
|
8
|
+
import { Environment, serviceEnvironment } from '../../../private/node/environment/service.js';
|
|
9
|
+
const SpinInstanceNotFoundMessages = (spinInstance, error) => {
|
|
9
10
|
const errorMessage = content `${token.genericShellCommand(`spin`)} yielded the following error trying to obtain the fully qualified domain name of the Spin instance:
|
|
10
11
|
${error}
|
|
11
12
|
`;
|
|
@@ -13,17 +14,19 @@ ${error}
|
|
|
13
14
|
if (spinInstance) {
|
|
14
15
|
nextSteps = `Make sure ${spinInstance} is the instance name and not a fully qualified domain name`;
|
|
15
16
|
}
|
|
16
|
-
return
|
|
17
|
+
return { errorMessage, nextSteps };
|
|
17
18
|
};
|
|
18
19
|
const spinFqdnFilePath = '/etc/spin/machine/fqdn';
|
|
19
20
|
/**
|
|
20
21
|
* When ran in a Spin environment, it returns the fqdn of the instance.
|
|
21
22
|
*
|
|
22
23
|
* Will cache the value of the Spin FQDN during the execution of the CLI.
|
|
23
|
-
* To avoid multiple calls to `readSync` or `show
|
|
24
|
-
*
|
|
24
|
+
* To avoid multiple calls to `readSync` or `show`.
|
|
25
|
+
*
|
|
26
|
+
* @param env - Environment variables.
|
|
27
|
+
* @returns Fqdn of the Spin environment.
|
|
25
28
|
*/
|
|
26
|
-
export async function
|
|
29
|
+
export async function spinFqdn(env = process.env) {
|
|
27
30
|
let spinFqdn = getCachedSpinFqdn();
|
|
28
31
|
if (spinFqdn)
|
|
29
32
|
return spinFqdn;
|
|
@@ -40,7 +43,9 @@ export async function fqdn(env = process.env) {
|
|
|
40
43
|
}
|
|
41
44
|
/**
|
|
42
45
|
* Runs "spin show" and returns the JSON-parsed output.
|
|
46
|
+
*
|
|
43
47
|
* @param spinInstance - When it's undefined, we'll fetch the latest one.
|
|
48
|
+
* @param env - Environment variables.
|
|
44
49
|
* @returns The JSON-parsed output of the Spin CLI.
|
|
45
50
|
* @throws Any error raised from the underlying Spin CLI.
|
|
46
51
|
*/
|
|
@@ -50,7 +55,8 @@ export async function show(spinInstance, env = process.env) {
|
|
|
50
55
|
const output = await captureOutput('spin', args, { env });
|
|
51
56
|
const json = JSON.parse(output);
|
|
52
57
|
if (json.error) {
|
|
53
|
-
|
|
58
|
+
const { errorMessage, nextSteps } = SpinInstanceNotFoundMessages(spinInstance, json.error);
|
|
59
|
+
throw new Abort(errorMessage, nextSteps);
|
|
54
60
|
}
|
|
55
61
|
else {
|
|
56
62
|
return json;
|
|
@@ -58,7 +64,8 @@ export async function show(spinInstance, env = process.env) {
|
|
|
58
64
|
}
|
|
59
65
|
/**
|
|
60
66
|
* Returns true if the CLI is running in a Spin environment.
|
|
61
|
-
*
|
|
67
|
+
*
|
|
68
|
+
* @param env - Environment variables.
|
|
62
69
|
* @returns True if the CLI is running in a Spin environment.
|
|
63
70
|
*/
|
|
64
71
|
export function isSpin(env = process.env) {
|
|
@@ -66,34 +73,20 @@ export function isSpin(env = process.env) {
|
|
|
66
73
|
}
|
|
67
74
|
/**
|
|
68
75
|
* Returns the value of the SPIN_INSTANCE environment variable.
|
|
69
|
-
*
|
|
76
|
+
*
|
|
77
|
+
* @param env - Environment variables.
|
|
70
78
|
* @returns The value of the SPIN_INSTANCE environment variable.
|
|
71
79
|
*/
|
|
72
80
|
export function instance(env = process.env) {
|
|
73
81
|
return env[constants.environmentVariables.spinInstance];
|
|
74
82
|
}
|
|
75
83
|
/**
|
|
76
|
-
* Returns the
|
|
77
|
-
*
|
|
78
|
-
* @
|
|
79
|
-
|
|
80
|
-
export function workspace(env = process.env) {
|
|
81
|
-
return env[constants.environmentVariables.spinWorkspace];
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Returns the value of the SPIN_NAMESPACE environment variable.
|
|
85
|
-
* @param env - Environment variables
|
|
86
|
-
* @returns The value of the SPIN_NAMESPACE environment variable.
|
|
87
|
-
*/
|
|
88
|
-
export function namespace(env = process.env) {
|
|
89
|
-
return env[constants.environmentVariables.spinNamespace];
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Returns the value of the SPIN_HOST environment variable.
|
|
93
|
-
* @param env - Environment variables
|
|
94
|
-
* @returns The value of the SPIN_HOST environment variable.
|
|
84
|
+
* Returns true if the CLI is running in a Spin environment.
|
|
85
|
+
*
|
|
86
|
+
* @param env - Environment variables.
|
|
87
|
+
* @returns True if the CLI is running in a Spin environment.
|
|
95
88
|
*/
|
|
96
|
-
export function
|
|
97
|
-
return env
|
|
89
|
+
export function isSpinEnvironment(env = process.env) {
|
|
90
|
+
return serviceEnvironment(env) === Environment.Spin;
|
|
98
91
|
}
|
|
99
92
|
//# sourceMappingURL=spin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spin.js","sourceRoot":"","sources":["../../../../src/public/node/environment/spin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,gDAAgD,CAAA;AACvE,OAAO,SAAS,MAAM,uBAAuB,CAAA;AAC7C,OAAO,EAAC,aAAa,EAAC,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAC,OAAO,EAAE,KAAK,EAAC,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAC,MAAM,EAAE,QAAQ,EAAC,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAC,iBAAiB,EAAE,iBAAiB,EAAC,MAAM,iDAAiD,CAAA;AACpG,OAAO,EAAC,KAAK,EAAC,MAAM,mBAAmB,CAAA;AACvC,OAAO,EAAC,WAAW,EAAE,kBAAkB,EAAC,MAAM,8CAA8C,CAAA;AAE5F,MAAM,4BAA4B,GAAG,CAAC,YAAgC,EAAE,KAAa,EAAE,EAAE;IACvF,MAAM,YAAY,GAAG,OAAO,CAAA,GAAG,KAAK,CAAC,mBAAmB,CACtD,MAAM,CACP;EACD,KAAK;GACJ,CAAA;IACD,IAAI,SAA6B,CAAA;IACjC,IAAI,YAAY,EAAE;QAChB,SAAS,GAAG,aAAa,YAAY,6DAA6D,CAAA;KACnG;IACD,OAAO,EAAC,YAAY,EAAE,SAAS,EAAC,CAAA;AAClC,CAAC,CAAA;AAED,MAAM,gBAAgB,GAAG,wBAAwB,CAAA;AAEjD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG;IAC9C,IAAI,QAAQ,GAAG,iBAAiB,EAAE,CAAA;IAClC,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAA;IAE7B,IAAI,MAAM,MAAM,CAAC,gBAAgB,CAAC,EAAE;QAClC,QAAQ,GAAG,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KG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG;IACxC,OAAO,GAAG,CAAC,SAAS,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAA;AACzD,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG;IACjD,OAAO,kBAAkB,CAAC,GAAG,CAAC,KAAK,WAAW,CAAC,IAAI,CAAA;AACrD,CAAC","sourcesContent":["import {isTruthy} from '../../../private/node/environment/utilities.js'\nimport constants from '../../../constants.js'\nimport {captureOutput} from '../system.js'\nimport {content, token} from '../../../output.js'\nimport {exists, readSync} from '../../../file.js'\nimport {getCachedSpinFqdn, setCachedSpinFqdn} from '../../../private/node/environment/spin-cache.js'\nimport {Abort} from '../../../error.js'\nimport {Environment, serviceEnvironment} from '../../../private/node/environment/service.js'\n\nconst SpinInstanceNotFoundMessages = (spinInstance: string | undefined, error: string) => {\n const errorMessage = content`${token.genericShellCommand(\n `spin`,\n )} yielded the following error trying to obtain the fully qualified domain name of the Spin instance:\n${error}\n `\n let nextSteps: string | undefined\n if (spinInstance) {\n nextSteps = `Make sure ${spinInstance} is the instance name and not a fully qualified domain name`\n }\n return {errorMessage, nextSteps}\n}\n\nconst spinFqdnFilePath = '/etc/spin/machine/fqdn'\n\n/**\n * When ran in a Spin environment, it returns the fqdn of the instance.\n *\n * Will cache the value of the Spin FQDN during the execution of the CLI.\n * To avoid multiple calls to `readSync` or `show`.\n *\n * @param env - Environment variables.\n * @returns Fqdn of the Spin environment.\n */\nexport async function spinFqdn(env = process.env): Promise<string> {\n let spinFqdn = getCachedSpinFqdn()\n if (spinFqdn) return spinFqdn\n\n if (await exists(spinFqdnFilePath)) {\n spinFqdn = await readSync(spinFqdnFilePath).toString()\n } else {\n const spinInstance = await instance(env)\n const showResponse = await show(spinInstance, env)\n\n spinFqdn = showResponse.fqdn\n }\n setCachedSpinFqdn(spinFqdn)\n return spinFqdn\n}\n\n/**\n * Runs \"spin show\" and returns the JSON-parsed output.\n *\n * @param spinInstance - When it's undefined, we'll fetch the latest one.\n * @param env - Environment variables.\n * @returns The JSON-parsed output of the Spin CLI.\n * @throws Any error raised from the underlying Spin CLI.\n */\nexport async function show(spinInstance: string | undefined, env = process.env): Promise<{fqdn: string}> {\n const latest = spinInstance === undefined\n const args = latest ? ['show', '--latest', '--json'] : ['show', '--json']\n const output = await captureOutput('spin', args, {env})\n const json = JSON.parse(output)\n if (json.error) {\n const {errorMessage, nextSteps} = SpinInstanceNotFoundMessages(spinInstance, json.error)\n throw new Abort(errorMessage, nextSteps)\n } else {\n return json\n }\n}\n\n/**\n * Returns true if the CLI is running in a Spin environment.\n *\n * @param env - Environment variables.\n * @returns True if the CLI is running in a Spin environment.\n */\nexport function isSpin(env = process.env): boolean {\n return isTruthy(env[constants.environmentVariables.spin])\n}\n\n/**\n * Returns the value of the SPIN_INSTANCE environment variable.\n *\n * @param env - Environment variables.\n * @returns The value of the SPIN_INSTANCE environment variable.\n */\nexport function instance(env = process.env): string | undefined {\n return env[constants.environmentVariables.spinInstance]\n}\n\n/**\n * Returns true if the CLI is running in a Spin environment.\n *\n * @param env - Environment variables.\n * @returns True if the CLI is running in a Spin environment.\n */\nexport function isSpinEnvironment(env = process.env): boolean {\n return serviceEnvironment(env) === Environment.Spin\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AbortError, BugError } from './error.js';
|
|
2
2
|
import { Version } from './semver.js';
|
|
3
3
|
import { AbortController } from './abort.js';
|
|
4
|
-
import { exec } from '
|
|
4
|
+
import { exec } from './system.js';
|
|
5
5
|
import { exists as fileExists, read as readFile, write as writeFile } from '../../file.js';
|
|
6
6
|
import { glob, dirname, join as pathJoin, findUp, moduleDirectory } from '../../path.js';
|
|
7
7
|
import { token, content, debug } from '../../output.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node-package-manager.js","sourceRoot":"","sources":["../../../src/public/node/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kB,CAAC,WAAW,EAAE,GAAG,YAAY,EAAC;YACtD,CAAC,CAAC,YAAY,CAAA;KACjB;IACD,IAAI,cAAc,KAAK,KAAK,IAAI,cAAc,KAAK,MAAM,EAAE;QACzD,kBAAkB,CAAC,SAAS,GAAG,kBAAkB,CAAC,SAAS;YACzD,CAAC,CAAC,EAAC,GAAG,kBAAkB,CAAC,SAAS,EAAE,GAAG,YAAY,EAAC;YACpD,CAAC,CAAC,YAAY,CAAA;KACjB;IAED,MAAM,SAAS,CAAC,eAAe,EAAE,IAAI,CAAC,SAAS,CAAC,kBAAkB,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;AAC/E,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,0BAA0B,CAAC,IAAY;IACpD,KAAK,CAAC,OAAO,CAAA,8CAA8C,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAC7E,OAAO,aAAa,CAAC,IAAI,CAAC,CAAA;AAC5B,CAAC;AAMD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,OAAoC;IAC7E,MAAM,aAAa,GAAG,eAAe,CAAC,OAAO,CAAC,aAAa,CAAC,CAAA;IAC5D,MAAM,WAAW,GAAG,MAAM,wBAAwB,CAAC,aAAa,CAAC,CAAA;IACjE,8DAA8D;IAC9D,MAAM,OAAO,GAAI,WAAW,CAAC,OAAe,CAAC,OAAO,CAAA;IACpD,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,GAAG,CAAC,OAAO,CAAA,4BAA4B,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAA;KAC3G;IACD,OAAO,OAAO,CAAA;AAChB,CAAC","sourcesContent":["import {AbortError, BugError} from './error.js'\nimport {Version} from './semver.js'\nimport {AbortController, AbortSignal} from './abort.js'\nimport {exec} from '../../system.js'\nimport {exists as fileExists, read as readFile, write as writeFile} from '../../file.js'\nimport {glob, dirname, join as pathJoin, findUp, moduleDirectory} from '../../path.js'\nimport {token, content, debug} from '../../output.js'\nimport {Bug} from '../../error.js'\nimport latestVersion from 'latest-version'\nimport type {Writable} from 'stream'\nimport type {ExecOptions} from '../../system.js'\n\n/** The name of the Yarn lock file */\nexport const yarnLockfile = 'yarn.lock'\n\n/** The name of the npm lock file */\nexport const npmLockfile = 'package-lock.json'\n\n/** The name of the pnpm lock file */\nexport const pnpmLockfile = 'pnpm-lock.yaml'\n\n/** The name of the pnpm workspace file */\nexport const pnpmWorkspaceFile = 'pnpm-workspace.yaml'\n\n/** An array containing the lockfiles from all the package managers */\nexport const lockfiles: Lockfile[] = [yarnLockfile, pnpmLockfile, npmLockfile]\nexport type Lockfile = 'yarn.lock' | 'package-lock.json' | 'pnpm-lock.yaml'\n\n/**\n * A union type that represents the type of dependencies in the package.json\n * - dev: devDependencies\n * - prod: dependencies\n * - peer: peerDependencies\n */\nexport type DependencyType = 'dev' | 'prod' | 'peer'\n\n/**\n * A union that represents the package managers available.\n */\nexport const packageManager = ['yarn', 'npm', 'pnpm'] as const\nexport type PackageManager = typeof packageManager[number]\n\n/**\n * Returns an abort error that's thrown when a directory that's expected to have\n * a package.json doesn't have it.\n * @param directory - The path to the directory that should contain a package.json\n * @returns An abort error.\n */\nexport const PackageJsonNotFoundError = (directory: string): AbortError => {\n return new AbortError(`The directory ${directory} doesn't have a package.json.`)\n}\n\n/**\n * Returns a bug error that's thrown when the lookup of the package.json traversing the directory\n * hierarchy up can't find a package.json\n * @param directory - The directory from which the traverse has been done\n * @returns An abort error.\n */\nexport const FindUpAndReadPackageJsonNotFoundError = (directory: string): BugError => {\n return new BugError(content`Couldn't find a a package.json traversing directories from ${token.path(directory)}`)\n}\n\n/**\n * Returns the dependency manager used to run the create workflow.\n * @param env - The environment variables of the process in which the CLI runs.\n * @returns The dependency manager\n */\nexport function packageManagerUsedForCreating(env = process.env): PackageManager | 'unknown' {\n if (env.npm_config_user_agent?.includes('yarn')) {\n return 'yarn'\n } else if (env.npm_config_user_agent?.includes('pnpm')) {\n return 'pnpm'\n } else if (env.npm_config_user_agent?.includes('npm')) {\n return 'npm'\n }\n return 'unknown'\n}\n\n/**\n * Returns the dependency manager used by an existing project.\n * @param directory - The root directory of the project.\n * @returns The dependency manager\n */\nexport async function getPackageManager(directory: string): Promise<PackageManager> {\n debug(content`Obtaining the dependency manager in directory ${token.path(directory)}...`)\n const yarnLockPath = pathJoin(directory, yarnLockfile)\n const pnpmLockPath = pathJoin(directory, pnpmLockfile)\n if (await fileExists(yarnLockPath)) {\n return 'yarn'\n } else if (await fileExists(pnpmLockPath)) {\n return 'pnpm'\n } else {\n return 'npm'\n }\n}\n\ninterface InstallNPMDependenciesRecursivelyOptions {\n /**\n * The dependency manager to use to install the dependencies.\n */\n packageManager: PackageManager\n /**\n * The directory from where we'll find package.json's recursively\n */\n directory: string\n\n /**\n * Specifies the maximum depth of the glob search.\n */\n deep?: number\n}\n\n/**\n * This function traverses down a directory tree to find directories containing a package.json\n * and installs the dependencies if needed. To know if it's needed, it uses the \"check\" command\n * provided by dependency managers.\n * @param options - Options to install dependencies recursively.\n */\nexport async function installNPMDependenciesRecursively(\n options: InstallNPMDependenciesRecursivelyOptions,\n): Promise<void> {\n const packageJsons = await glob(pathJoin(options.directory, '**/package.json'), {\n ignore: [pathJoin(options.directory, 'node_modules/**/package.json')],\n cwd: options.directory,\n onlyFiles: true,\n deep: options.deep,\n })\n const abortController = new AbortController()\n try {\n await Promise.all(\n packageJsons.map(async (packageJsonPath) => {\n const directory = dirname(packageJsonPath)\n await installNodeModules({\n directory,\n packageManager: options.packageManager,\n stdout: undefined,\n stderr: undefined,\n signal: abortController.signal,\n args: [],\n })\n }),\n )\n } catch (error) {\n abortController.abort()\n throw error\n }\n}\n\ninterface InstallNodeModulesOptions {\n directory: string\n args: string[]\n packageManager: PackageManager\n stdout?: Writable\n stderr?: Writable\n signal?: AbortSignal\n}\n\nexport async function installNodeModules(options: InstallNodeModulesOptions): Promise<void> {\n const execOptions: ExecOptions = {\n cwd: options.directory,\n stdin: undefined,\n stdout: options.stdout,\n stderr: options.stderr,\n signal: options.signal,\n }\n let args = ['install']\n if (options.args) {\n args = args.concat(options.args)\n }\n await exec(options.packageManager, args, execOptions)\n}\n\n/**\n * Returns the name of the package configured in its package.json\n * @param packageJsonPath - Path to the package.json file\n * @returns A promise that resolves with the name.\n */\nexport async function getPackageName(packageJsonPath: string): Promise<string | undefined> {\n const packageJsonContent = await readAndParsePackageJson(packageJsonPath)\n return packageJsonContent.name\n}\n\n/**\n * Returns the list of production and dev dependencies of a package.json\n * @param packageJsonPath - Path to the package.json file\n * @returns A promise that resolves with the list of dependencies.\n */\nexport async function getDependencies(packageJsonPath: string): Promise<{[key: string]: string}> {\n const packageJsonContent = await readAndParsePackageJson(packageJsonPath)\n const dependencies: {[key: string]: string} = packageJsonContent.dependencies ?? {}\n const devDependencies: {[key: string]: string} = packageJsonContent.devDependencies ?? {}\n\n return {...dependencies, ...devDependencies}\n}\n\n/**\n * Returns true if the app uses workspaces, false otherwise.\n * @param packageJsonPath - Path to the package.json file\n * @param pnpmWorkspacePath - Path to the pnpm-workspace.yaml file\n * @returns A promise that resolves with true if the app uses workspaces, false otherwise.\n */\nexport async function usesWorkspaces(appDirectory: string): Promise<boolean> {\n const packageJsonPath = pathJoin(appDirectory, 'package.json')\n const packageJsonContent = await readAndParsePackageJson(packageJsonPath)\n const pnpmWorkspacePath = pathJoin(appDirectory, pnpmWorkspaceFile)\n return Boolean(packageJsonContent.workspaces) || fileExists(pnpmWorkspacePath)\n}\n\n/**\n * Given an NPM dependency, it checks if there's a more recent version, and if there is, it returns its value.\n * @param dependency - The dependency name (e.g. react)\n * @param currentVersion - The current version.\n * @returns A promise that resolves with a more recent version or undefined if there's no more recent version.\n */\nexport async function checkForNewVersion(dependency: string, currentVersion: string): Promise<string | undefined> {\n debug(content`Checking if there's a version of ${dependency} newer than ${currentVersion}`)\n try {\n const lastVersion = await getLatestNPMPackageVersion(dependency)\n if (lastVersion && new Version(currentVersion).compare(lastVersion) < 0) {\n return lastVersion\n } else {\n return undefined\n }\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n return undefined\n }\n}\n\n/**\n * An interface that represents a package.json\n */\nexport interface PackageJson {\n /**\n * The name attribute of the package.json\n */\n name?: string\n\n /**\n * The version attribute of the package.json\n */\n version?: string\n\n /**\n * The dependencies attribute of the package.json\n */\n dependencies?: {[key: string]: string}\n\n /**\n * The devDependencies attribute of the package.json\n */\n devDependencies?: {[key: string]: string}\n\n /**\n * The optional oclif settings attribute of the package.json\n */\n oclif?: {\n plugins?: string[]\n }\n\n /**\n * The workspaces attribute of the package.json\n */\n workspaces?: string[]\n\n /**\n * The resolutions attribute of the package.json. Only useful when using yarn as package manager\n */\n resolutions?: {[key: string]: string}\n\n /**\n * The overrides attribute of the package.json. Only useful when using npm o npmn as package managers\n */\n overrides?: {[key: string]: string}\n}\n\n/**\n * Reads and parses a package.json\n * @param packageJsonPath - Path to the package.json\n * @returns An promise that resolves with an in-memory representation\n * of the package.json or rejects with an error if the file is not found or the content is\n * not decodable.\n */\nexport async function readAndParsePackageJson(packageJsonPath: string): Promise<PackageJson> {\n if (!(await fileExists(packageJsonPath))) {\n throw PackageJsonNotFoundError(dirname(packageJsonPath))\n }\n return JSON.parse(await readFile(packageJsonPath))\n}\n\ninterface AddNPMDependenciesIfNeededOptions {\n /** How dependencies should be added */\n type: DependencyType\n\n /** The dependency manager to use to add dependencies */\n packageManager: PackageManager\n\n /** The directory that contains the package.json where dependencies will be added */\n directory: string\n\n /** Standard output coming from the underlying installation process */\n stdout?: Writable\n\n /** Standard error coming from the underlying installation process */\n stderr?: Writable\n\n /** Abort signal to stop the process */\n signal?: AbortSignal\n}\n\n/**\n * An interface that represents a dependency name with its version\n */\nexport interface DependencyVersion {\n /**\n * The name of the NPM dependency as it's reflected in the package.json:\n *\n * @example\n * In the example below name would be \"react\"\n * ```\n * {\n * \"react\": \"1.2.3\"\n * }\n * ```\n */\n name: string\n\n /**\n * The version of the NPM dependency as it's reflected in the package.json:\n *\n * @example\n * In the example below version would be \"1.2.3\"\n * ```\n * {\n * \"react\": \"1.2.3\"\n * }\n * ```\n */\n version: string | undefined\n}\n\n/**\n * Adds dependencies to a Node project (i.e. a project that has a package.json)\n * @param dependencies - List of dependencies to be added.\n * @param options - Options for adding dependencies.\n */\nexport async function addNPMDependenciesIfNeeded(\n dependencies: DependencyVersion[],\n options: AddNPMDependenciesIfNeededOptions,\n): Promise<void> {\n debug(content`Adding the following dependencies if needed:\n${token.json(dependencies)}\nWith options:\n${token.json(options)}\n `)\n const packageJsonPath = pathJoin(options.directory, 'package.json')\n if (!(await fileExists(packageJsonPath))) {\n throw PackageJsonNotFoundError(options.directory)\n }\n const existingDependencies = Object.keys(await getDependencies(packageJsonPath))\n let dependenciesToAdd = dependencies\n dependenciesToAdd = dependencies.filter((dep) => {\n return !existingDependencies.includes(dep.name)\n })\n if (dependenciesToAdd.length === 0) {\n return\n }\n await addNPMDependencies(dependenciesToAdd, options)\n}\n\nexport async function addNPMDependencies(\n dependencies: DependencyVersion[],\n options: AddNPMDependenciesIfNeededOptions,\n): Promise<void> {\n let args: string[]\n const depedenciesWithVersion = dependencies.map((dep) => {\n return dep.version ? `${dep.name}@${dep.version}` : dep.name\n })\n switch (options.packageManager) {\n case 'npm':\n args = argumentsToAddDependenciesWithNPM(depedenciesWithVersion, options.type)\n break\n case 'yarn':\n args = argumentsToAddDependenciesWithYarn(depedenciesWithVersion, options.type)\n break\n case 'pnpm':\n args = argumentsToAddDependenciesWithPNPM(depedenciesWithVersion, options.type)\n break\n }\n options.stdout?.write(`Executing... ${[options.packageManager, ...args].join(' ')}`)\n await exec(options.packageManager, args, {\n cwd: options.directory,\n stdout: options.stdout,\n stderr: options.stderr,\n signal: options.signal,\n })\n}\n\nexport async function addNPMDependenciesWithoutVersionIfNeeded(\n dependencies: string[],\n options: AddNPMDependenciesIfNeededOptions,\n): Promise<void> {\n await addNPMDependenciesIfNeeded(\n dependencies.map((dependency) => {\n return {name: dependency, version: undefined}\n }),\n options,\n )\n}\n\n/**\n * Returns the arguments to add dependencies using NPM.\n * @param dependencies - The list of dependencies to add\n * @param type - The dependency type.\n * @returns An array with the arguments.\n */\nfunction argumentsToAddDependenciesWithNPM(dependencies: string[], type: DependencyType): string[] {\n let command = ['install']\n command = command.concat(dependencies)\n switch (type) {\n case 'dev':\n command.push('--save-dev')\n break\n case 'peer':\n command.push('--save-peer')\n break\n case 'prod':\n command.push('--save-prod')\n break\n }\n return command\n}\n\n/**\n * Returns the arguments to add dependencies using Yarn.\n * @param dependencies - The list of dependencies to add\n * @param type - The dependency type.\n * @returns An array with the arguments.\n */\nfunction argumentsToAddDependenciesWithYarn(dependencies: string[], type: DependencyType): string[] {\n let command = ['add']\n command = command.concat(dependencies)\n switch (type) {\n case 'dev':\n command.push('--dev')\n break\n case 'peer':\n command.push('--peer')\n break\n case 'prod':\n command.push('--prod')\n break\n }\n return command\n}\n\n/**\n * Returns the arguments to add dependencies using PNPM.\n * @param dependencies - The list of dependencies to add\n * @param type - The dependency type.\n * @returns An array with the arguments.\n */\nfunction argumentsToAddDependenciesWithPNPM(dependencies: string[], type: DependencyType): string[] {\n let command = ['add']\n command = command.concat(dependencies)\n switch (type) {\n case 'dev':\n command.push('--save-dev')\n break\n case 'peer':\n command.push('--save-peer')\n break\n case 'prod':\n command.push('--save-prod')\n break\n }\n return command\n}\n\n/**\n * Given a directory it traverses the directory up looking for a package.json and if found, it reads it\n * decodes the JSON, and returns its content as a Javascript object.\n * @param options - The directory from which traverse up.\n * @returns If found, the promise resolves with the path to the\n * package.json and its content. If not found, it throws a FindUpAndReadPackageJsonNotFoundError error.\n */\nexport async function findUpAndReadPackageJson(fromDirectory: string): Promise<{path: string; content: unknown}> {\n const packageJsonPath = await findUp('package.json', {cwd: fromDirectory, type: 'file'})\n if (packageJsonPath) {\n const packageJson = JSON.parse(await readFile(packageJsonPath))\n return {path: packageJsonPath, content: packageJson}\n } else {\n throw FindUpAndReadPackageJsonNotFoundError(fromDirectory)\n }\n}\n\nexport async function addResolutionOrOverride(directory: string, dependencies: {[key: string]: string}): Promise<void> {\n const packageManager = await getPackageManager(directory)\n const packageJsonPath = pathJoin(directory, 'package.json')\n const packageJsonContent = await readAndParsePackageJson(packageJsonPath)\n\n if (packageManager === 'yarn') {\n packageJsonContent.resolutions = packageJsonContent.resolutions\n ? {...packageJsonContent.resolutions, ...dependencies}\n : dependencies\n }\n if (packageManager === 'npm' || packageManager === 'pnpm') {\n packageJsonContent.overrides = packageJsonContent.overrides\n ? {...packageJsonContent.overrides, ...dependencies}\n : dependencies\n }\n\n await writeFile(packageJsonPath, JSON.stringify(packageJsonContent, null, 2))\n}\n\n/**\n * Returns the latest available version of an NPM package.\n * @param name - The name of the NPM package.\n * @returns A promise to get the latest available version of a package.\n */\nasync function getLatestNPMPackageVersion(name: string) {\n debug(content`Getting the latest version of NPM package: ${token.raw(name)}`)\n return latestVersion(name)\n}\n\ninterface FindPackageVersionUpOptions {\n fromModuleURL: import('url').URL | string\n}\n\n/**\n * Given a module URL, it traverses the directory hierarchy up until it finds a package.json\n * and then it returns the version in it.\n * @param options - Options\n * @returns The version if it can find the package.json and it exists. An error otherwise.\n */\nexport async function findPackageVersionUp(options: FindPackageVersionUpOptions): Promise<string> {\n const fromDirectory = moduleDirectory(options.fromModuleURL)\n const packageJson = await findUpAndReadPackageJson(fromDirectory)\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const version = (packageJson.content as any).version\n if (!version) {\n throw new Bug(content`The package.json at path ${token.path(packageJson.path)} doesn't contain a version`)\n }\n return version\n}\n"]}
|
|
1
|
+
{"version":3,"file":"node-package-manager.js","sourceRoot":"","sources":["../../../src/public/node/node-package-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAC,MAAM,YAAY,CAAA;AAC/C,OAAO,EAAC,OAAO,EAAC,MAAM,aAAa,CAAA;AACnC,O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B,CAAC,SAAS,GAAG,kBAAkB,CAAC,SAAS;YACzD,CAAC,CAAC,EAAC,GAAG,kBAAkB,CAAC,SAAS,EAAE,GAAG,YAAY,EAAC;YACpD,CAAC,CAAC,YAAY,CAAA;KACjB;IAED,MAAM,SAAS,CAAC,eAAe,EAAE,IAAI,CAAC,SAAS,CAAC,kBAAkB,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;AAC/E,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,0BAA0B,CAAC,IAAY;IACpD,KAAK,CAAC,OAAO,CAAA,8CAA8C,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAC7E,OAAO,aAAa,CAAC,IAAI,CAAC,CAAA;AAC5B,CAAC;AAMD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,OAAoC;IAC7E,MAAM,aAAa,GAAG,eAAe,CAAC,OAAO,CAAC,aAAa,CAAC,CAAA;IAC5D,MAAM,WAAW,GAAG,MAAM,wBAAwB,CAAC,aAAa,CAAC,CAAA;IACjE,8DAA8D;IAC9D,MAAM,OAAO,GAAI,WAAW,CAAC,OAAe,CAAC,OAAO,CAAA;IACpD,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,GAAG,CAAC,OAAO,CAAA,4BAA4B,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAA;KAC3G;IACD,OAAO,OAAO,CAAA;AAChB,CAAC","sourcesContent":["import {AbortError, BugError} from './error.js'\nimport {Version} from './semver.js'\nimport {AbortController, AbortSignal} from './abort.js'\nimport {exec} from './system.js'\nimport {exists as fileExists, read as readFile, write as writeFile} from '../../file.js'\nimport {glob, dirname, join as pathJoin, findUp, moduleDirectory} from '../../path.js'\nimport {token, content, debug} from '../../output.js'\nimport {Bug} from '../../error.js'\nimport latestVersion from 'latest-version'\nimport type {Writable} from 'stream'\nimport type {ExecOptions} from './system.js'\n\n/** The name of the Yarn lock file */\nexport const yarnLockfile = 'yarn.lock'\n\n/** The name of the npm lock file */\nexport const npmLockfile = 'package-lock.json'\n\n/** The name of the pnpm lock file */\nexport const pnpmLockfile = 'pnpm-lock.yaml'\n\n/** The name of the pnpm workspace file */\nexport const pnpmWorkspaceFile = 'pnpm-workspace.yaml'\n\n/** An array containing the lockfiles from all the package managers */\nexport const lockfiles: Lockfile[] = [yarnLockfile, pnpmLockfile, npmLockfile]\nexport type Lockfile = 'yarn.lock' | 'package-lock.json' | 'pnpm-lock.yaml'\n\n/**\n * A union type that represents the type of dependencies in the package.json\n * - dev: devDependencies\n * - prod: dependencies\n * - peer: peerDependencies\n */\nexport type DependencyType = 'dev' | 'prod' | 'peer'\n\n/**\n * A union that represents the package managers available.\n */\nexport const packageManager = ['yarn', 'npm', 'pnpm'] as const\nexport type PackageManager = typeof packageManager[number]\n\n/**\n * Returns an abort error that's thrown when a directory that's expected to have\n * a package.json doesn't have it.\n * @param directory - The path to the directory that should contain a package.json\n * @returns An abort error.\n */\nexport const PackageJsonNotFoundError = (directory: string): AbortError => {\n return new AbortError(`The directory ${directory} doesn't have a package.json.`)\n}\n\n/**\n * Returns a bug error that's thrown when the lookup of the package.json traversing the directory\n * hierarchy up can't find a package.json\n * @param directory - The directory from which the traverse has been done\n * @returns An abort error.\n */\nexport const FindUpAndReadPackageJsonNotFoundError = (directory: string): BugError => {\n return new BugError(content`Couldn't find a a package.json traversing directories from ${token.path(directory)}`)\n}\n\n/**\n * Returns the dependency manager used to run the create workflow.\n * @param env - The environment variables of the process in which the CLI runs.\n * @returns The dependency manager\n */\nexport function packageManagerUsedForCreating(env = process.env): PackageManager | 'unknown' {\n if (env.npm_config_user_agent?.includes('yarn')) {\n return 'yarn'\n } else if (env.npm_config_user_agent?.includes('pnpm')) {\n return 'pnpm'\n } else if (env.npm_config_user_agent?.includes('npm')) {\n return 'npm'\n }\n return 'unknown'\n}\n\n/**\n * Returns the dependency manager used by an existing project.\n * @param directory - The root directory of the project.\n * @returns The dependency manager\n */\nexport async function getPackageManager(directory: string): Promise<PackageManager> {\n debug(content`Obtaining the dependency manager in directory ${token.path(directory)}...`)\n const yarnLockPath = pathJoin(directory, yarnLockfile)\n const pnpmLockPath = pathJoin(directory, pnpmLockfile)\n if (await fileExists(yarnLockPath)) {\n return 'yarn'\n } else if (await fileExists(pnpmLockPath)) {\n return 'pnpm'\n } else {\n return 'npm'\n }\n}\n\ninterface InstallNPMDependenciesRecursivelyOptions {\n /**\n * The dependency manager to use to install the dependencies.\n */\n packageManager: PackageManager\n /**\n * The directory from where we'll find package.json's recursively\n */\n directory: string\n\n /**\n * Specifies the maximum depth of the glob search.\n */\n deep?: number\n}\n\n/**\n * This function traverses down a directory tree to find directories containing a package.json\n * and installs the dependencies if needed. To know if it's needed, it uses the \"check\" command\n * provided by dependency managers.\n * @param options - Options to install dependencies recursively.\n */\nexport async function installNPMDependenciesRecursively(\n options: InstallNPMDependenciesRecursivelyOptions,\n): Promise<void> {\n const packageJsons = await glob(pathJoin(options.directory, '**/package.json'), {\n ignore: [pathJoin(options.directory, 'node_modules/**/package.json')],\n cwd: options.directory,\n onlyFiles: true,\n deep: options.deep,\n })\n const abortController = new AbortController()\n try {\n await Promise.all(\n packageJsons.map(async (packageJsonPath) => {\n const directory = dirname(packageJsonPath)\n await installNodeModules({\n directory,\n packageManager: options.packageManager,\n stdout: undefined,\n stderr: undefined,\n signal: abortController.signal,\n args: [],\n })\n }),\n )\n } catch (error) {\n abortController.abort()\n throw error\n }\n}\n\ninterface InstallNodeModulesOptions {\n directory: string\n args: string[]\n packageManager: PackageManager\n stdout?: Writable\n stderr?: Writable\n signal?: AbortSignal\n}\n\nexport async function installNodeModules(options: InstallNodeModulesOptions): Promise<void> {\n const execOptions: ExecOptions = {\n cwd: options.directory,\n stdin: undefined,\n stdout: options.stdout,\n stderr: options.stderr,\n signal: options.signal,\n }\n let args = ['install']\n if (options.args) {\n args = args.concat(options.args)\n }\n await exec(options.packageManager, args, execOptions)\n}\n\n/**\n * Returns the name of the package configured in its package.json\n * @param packageJsonPath - Path to the package.json file\n * @returns A promise that resolves with the name.\n */\nexport async function getPackageName(packageJsonPath: string): Promise<string | undefined> {\n const packageJsonContent = await readAndParsePackageJson(packageJsonPath)\n return packageJsonContent.name\n}\n\n/**\n * Returns the list of production and dev dependencies of a package.json\n * @param packageJsonPath - Path to the package.json file\n * @returns A promise that resolves with the list of dependencies.\n */\nexport async function getDependencies(packageJsonPath: string): Promise<{[key: string]: string}> {\n const packageJsonContent = await readAndParsePackageJson(packageJsonPath)\n const dependencies: {[key: string]: string} = packageJsonContent.dependencies ?? {}\n const devDependencies: {[key: string]: string} = packageJsonContent.devDependencies ?? {}\n\n return {...dependencies, ...devDependencies}\n}\n\n/**\n * Returns true if the app uses workspaces, false otherwise.\n * @param packageJsonPath - Path to the package.json file\n * @param pnpmWorkspacePath - Path to the pnpm-workspace.yaml file\n * @returns A promise that resolves with true if the app uses workspaces, false otherwise.\n */\nexport async function usesWorkspaces(appDirectory: string): Promise<boolean> {\n const packageJsonPath = pathJoin(appDirectory, 'package.json')\n const packageJsonContent = await readAndParsePackageJson(packageJsonPath)\n const pnpmWorkspacePath = pathJoin(appDirectory, pnpmWorkspaceFile)\n return Boolean(packageJsonContent.workspaces) || fileExists(pnpmWorkspacePath)\n}\n\n/**\n * Given an NPM dependency, it checks if there's a more recent version, and if there is, it returns its value.\n * @param dependency - The dependency name (e.g. react)\n * @param currentVersion - The current version.\n * @returns A promise that resolves with a more recent version or undefined if there's no more recent version.\n */\nexport async function checkForNewVersion(dependency: string, currentVersion: string): Promise<string | undefined> {\n debug(content`Checking if there's a version of ${dependency} newer than ${currentVersion}`)\n try {\n const lastVersion = await getLatestNPMPackageVersion(dependency)\n if (lastVersion && new Version(currentVersion).compare(lastVersion) < 0) {\n return lastVersion\n } else {\n return undefined\n }\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n return undefined\n }\n}\n\n/**\n * An interface that represents a package.json\n */\nexport interface PackageJson {\n /**\n * The name attribute of the package.json\n */\n name?: string\n\n /**\n * The version attribute of the package.json\n */\n version?: string\n\n /**\n * The dependencies attribute of the package.json\n */\n dependencies?: {[key: string]: string}\n\n /**\n * The devDependencies attribute of the package.json\n */\n devDependencies?: {[key: string]: string}\n\n /**\n * The optional oclif settings attribute of the package.json\n */\n oclif?: {\n plugins?: string[]\n }\n\n /**\n * The workspaces attribute of the package.json\n */\n workspaces?: string[]\n\n /**\n * The resolutions attribute of the package.json. Only useful when using yarn as package manager\n */\n resolutions?: {[key: string]: string}\n\n /**\n * The overrides attribute of the package.json. Only useful when using npm o npmn as package managers\n */\n overrides?: {[key: string]: string}\n}\n\n/**\n * Reads and parses a package.json\n * @param packageJsonPath - Path to the package.json\n * @returns An promise that resolves with an in-memory representation\n * of the package.json or rejects with an error if the file is not found or the content is\n * not decodable.\n */\nexport async function readAndParsePackageJson(packageJsonPath: string): Promise<PackageJson> {\n if (!(await fileExists(packageJsonPath))) {\n throw PackageJsonNotFoundError(dirname(packageJsonPath))\n }\n return JSON.parse(await readFile(packageJsonPath))\n}\n\ninterface AddNPMDependenciesIfNeededOptions {\n /** How dependencies should be added */\n type: DependencyType\n\n /** The dependency manager to use to add dependencies */\n packageManager: PackageManager\n\n /** The directory that contains the package.json where dependencies will be added */\n directory: string\n\n /** Standard output coming from the underlying installation process */\n stdout?: Writable\n\n /** Standard error coming from the underlying installation process */\n stderr?: Writable\n\n /** Abort signal to stop the process */\n signal?: AbortSignal\n}\n\n/**\n * An interface that represents a dependency name with its version\n */\nexport interface DependencyVersion {\n /**\n * The name of the NPM dependency as it's reflected in the package.json:\n *\n * @example\n * In the example below name would be \"react\"\n * ```\n * {\n * \"react\": \"1.2.3\"\n * }\n * ```\n */\n name: string\n\n /**\n * The version of the NPM dependency as it's reflected in the package.json:\n *\n * @example\n * In the example below version would be \"1.2.3\"\n * ```\n * {\n * \"react\": \"1.2.3\"\n * }\n * ```\n */\n version: string | undefined\n}\n\n/**\n * Adds dependencies to a Node project (i.e. a project that has a package.json)\n * @param dependencies - List of dependencies to be added.\n * @param options - Options for adding dependencies.\n */\nexport async function addNPMDependenciesIfNeeded(\n dependencies: DependencyVersion[],\n options: AddNPMDependenciesIfNeededOptions,\n): Promise<void> {\n debug(content`Adding the following dependencies if needed:\n${token.json(dependencies)}\nWith options:\n${token.json(options)}\n `)\n const packageJsonPath = pathJoin(options.directory, 'package.json')\n if (!(await fileExists(packageJsonPath))) {\n throw PackageJsonNotFoundError(options.directory)\n }\n const existingDependencies = Object.keys(await getDependencies(packageJsonPath))\n let dependenciesToAdd = dependencies\n dependenciesToAdd = dependencies.filter((dep) => {\n return !existingDependencies.includes(dep.name)\n })\n if (dependenciesToAdd.length === 0) {\n return\n }\n await addNPMDependencies(dependenciesToAdd, options)\n}\n\nexport async function addNPMDependencies(\n dependencies: DependencyVersion[],\n options: AddNPMDependenciesIfNeededOptions,\n): Promise<void> {\n let args: string[]\n const depedenciesWithVersion = dependencies.map((dep) => {\n return dep.version ? `${dep.name}@${dep.version}` : dep.name\n })\n switch (options.packageManager) {\n case 'npm':\n args = argumentsToAddDependenciesWithNPM(depedenciesWithVersion, options.type)\n break\n case 'yarn':\n args = argumentsToAddDependenciesWithYarn(depedenciesWithVersion, options.type)\n break\n case 'pnpm':\n args = argumentsToAddDependenciesWithPNPM(depedenciesWithVersion, options.type)\n break\n }\n options.stdout?.write(`Executing... ${[options.packageManager, ...args].join(' ')}`)\n await exec(options.packageManager, args, {\n cwd: options.directory,\n stdout: options.stdout,\n stderr: options.stderr,\n signal: options.signal,\n })\n}\n\nexport async function addNPMDependenciesWithoutVersionIfNeeded(\n dependencies: string[],\n options: AddNPMDependenciesIfNeededOptions,\n): Promise<void> {\n await addNPMDependenciesIfNeeded(\n dependencies.map((dependency) => {\n return {name: dependency, version: undefined}\n }),\n options,\n )\n}\n\n/**\n * Returns the arguments to add dependencies using NPM.\n * @param dependencies - The list of dependencies to add\n * @param type - The dependency type.\n * @returns An array with the arguments.\n */\nfunction argumentsToAddDependenciesWithNPM(dependencies: string[], type: DependencyType): string[] {\n let command = ['install']\n command = command.concat(dependencies)\n switch (type) {\n case 'dev':\n command.push('--save-dev')\n break\n case 'peer':\n command.push('--save-peer')\n break\n case 'prod':\n command.push('--save-prod')\n break\n }\n return command\n}\n\n/**\n * Returns the arguments to add dependencies using Yarn.\n * @param dependencies - The list of dependencies to add\n * @param type - The dependency type.\n * @returns An array with the arguments.\n */\nfunction argumentsToAddDependenciesWithYarn(dependencies: string[], type: DependencyType): string[] {\n let command = ['add']\n command = command.concat(dependencies)\n switch (type) {\n case 'dev':\n command.push('--dev')\n break\n case 'peer':\n command.push('--peer')\n break\n case 'prod':\n command.push('--prod')\n break\n }\n return command\n}\n\n/**\n * Returns the arguments to add dependencies using PNPM.\n * @param dependencies - The list of dependencies to add\n * @param type - The dependency type.\n * @returns An array with the arguments.\n */\nfunction argumentsToAddDependenciesWithPNPM(dependencies: string[], type: DependencyType): string[] {\n let command = ['add']\n command = command.concat(dependencies)\n switch (type) {\n case 'dev':\n command.push('--save-dev')\n break\n case 'peer':\n command.push('--save-peer')\n break\n case 'prod':\n command.push('--save-prod')\n break\n }\n return command\n}\n\n/**\n * Given a directory it traverses the directory up looking for a package.json and if found, it reads it\n * decodes the JSON, and returns its content as a Javascript object.\n * @param options - The directory from which traverse up.\n * @returns If found, the promise resolves with the path to the\n * package.json and its content. If not found, it throws a FindUpAndReadPackageJsonNotFoundError error.\n */\nexport async function findUpAndReadPackageJson(fromDirectory: string): Promise<{path: string; content: unknown}> {\n const packageJsonPath = await findUp('package.json', {cwd: fromDirectory, type: 'file'})\n if (packageJsonPath) {\n const packageJson = JSON.parse(await readFile(packageJsonPath))\n return {path: packageJsonPath, content: packageJson}\n } else {\n throw FindUpAndReadPackageJsonNotFoundError(fromDirectory)\n }\n}\n\nexport async function addResolutionOrOverride(directory: string, dependencies: {[key: string]: string}): Promise<void> {\n const packageManager = await getPackageManager(directory)\n const packageJsonPath = pathJoin(directory, 'package.json')\n const packageJsonContent = await readAndParsePackageJson(packageJsonPath)\n\n if (packageManager === 'yarn') {\n packageJsonContent.resolutions = packageJsonContent.resolutions\n ? {...packageJsonContent.resolutions, ...dependencies}\n : dependencies\n }\n if (packageManager === 'npm' || packageManager === 'pnpm') {\n packageJsonContent.overrides = packageJsonContent.overrides\n ? {...packageJsonContent.overrides, ...dependencies}\n : dependencies\n }\n\n await writeFile(packageJsonPath, JSON.stringify(packageJsonContent, null, 2))\n}\n\n/**\n * Returns the latest available version of an NPM package.\n * @param name - The name of the NPM package.\n * @returns A promise to get the latest available version of a package.\n */\nasync function getLatestNPMPackageVersion(name: string) {\n debug(content`Getting the latest version of NPM package: ${token.raw(name)}`)\n return latestVersion(name)\n}\n\ninterface FindPackageVersionUpOptions {\n fromModuleURL: import('url').URL | string\n}\n\n/**\n * Given a module URL, it traverses the directory hierarchy up until it finds a package.json\n * and then it returns the version in it.\n * @param options - Options\n * @returns The version if it can find the package.json and it exists. An error otherwise.\n */\nexport async function findPackageVersionUp(options: FindPackageVersionUpOptions): Promise<string> {\n const fromDirectory = moduleDirectory(options.fromModuleURL)\n const packageJson = await findUpAndReadPackageJson(fromDirectory)\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const version = (packageJson.content as any).version\n if (!version) {\n throw new Bug(content`The package.json at path ${token.path(packageJson.path)} doesn't contain a version`)\n }\n return version\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { AbortSignal } from './abort.js';
|
|
3
|
-
import { AdminSession } from '../../session.js';
|
|
3
|
+
import { AdminSession } from '../../public/node/session.js';
|
|
4
4
|
import { Writable } from 'stream';
|
|
5
5
|
interface ExecCLI2Options {
|
|
6
6
|
adminSession?: AdminSession;
|
package/dist/public/node/ruby.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { coerceSemverVersion } from './semver.js';
|
|
2
2
|
import { platformAndArch } from './os.js';
|
|
3
|
+
import { captureOutput, exec } from './system.js';
|
|
3
4
|
import * as file from '../../file.js';
|
|
4
5
|
import * as ui from '../../ui.js';
|
|
5
|
-
import * as system from '../../system.js';
|
|
6
6
|
import { Abort, AbortSilent } from '../../error.js';
|
|
7
7
|
import { glob, join } from '../../path.js';
|
|
8
8
|
import constants from '../../constants.js';
|
|
@@ -35,7 +35,7 @@ export async function execCLI2(args, options = {}) {
|
|
|
35
35
|
BUNDLE_GEMFILE: join(shopifyCLIDirectory(), 'Gemfile'),
|
|
36
36
|
};
|
|
37
37
|
try {
|
|
38
|
-
await
|
|
38
|
+
await exec(bundleExecutable(), ['exec', 'shopify'].concat(args), {
|
|
39
39
|
stdio: 'inherit',
|
|
40
40
|
cwd: options.directory ?? process.cwd(),
|
|
41
41
|
env,
|
|
@@ -75,7 +75,7 @@ export async function execThemeCheckCLI(options) {
|
|
|
75
75
|
}
|
|
76
76
|
},
|
|
77
77
|
});
|
|
78
|
-
await
|
|
78
|
+
await exec(bundleExecutable(), ['exec', 'theme-check'].concat([directory, ...(options.args || [])]), {
|
|
79
79
|
stdout: options.stdout,
|
|
80
80
|
stderr: customStderr,
|
|
81
81
|
cwd: themeCheckDirectory(),
|
|
@@ -151,7 +151,7 @@ async function validateRubyEnv() {
|
|
|
151
151
|
async function validateRuby() {
|
|
152
152
|
let version;
|
|
153
153
|
try {
|
|
154
|
-
const stdout = await
|
|
154
|
+
const stdout = await captureOutput(rubyExecutable(), ['-v']);
|
|
155
155
|
version = coerceSemverVersion(stdout);
|
|
156
156
|
}
|
|
157
157
|
catch {
|
|
@@ -168,7 +168,7 @@ async function validateRuby() {
|
|
|
168
168
|
async function validateBundler() {
|
|
169
169
|
let version;
|
|
170
170
|
try {
|
|
171
|
-
const stdout = await
|
|
171
|
+
const stdout = await captureOutput(bundleExecutable(), ['-v']);
|
|
172
172
|
version = coerceSemverVersion(stdout);
|
|
173
173
|
}
|
|
174
174
|
catch {
|
|
@@ -215,25 +215,25 @@ async function createThemeCheckGemfile() {
|
|
|
215
215
|
* It runs bundle install for the dev-managed copy of the Ruby CLI.
|
|
216
216
|
*/
|
|
217
217
|
async function bundleInstallLocalShopifyCLI() {
|
|
218
|
-
await
|
|
218
|
+
await exec(bundleExecutable(), ['install'], { cwd: shopifyCLIDirectory() });
|
|
219
219
|
}
|
|
220
220
|
/**
|
|
221
221
|
* It runs bundle install for the CLI-managed copy of the Ruby CLI.
|
|
222
222
|
*/
|
|
223
223
|
async function bundleInstallShopifyCLI() {
|
|
224
|
-
await
|
|
224
|
+
await exec(bundleExecutable(), ['config', 'set', '--local', 'path', shopifyCLIDirectory()], {
|
|
225
225
|
cwd: shopifyCLIDirectory(),
|
|
226
226
|
});
|
|
227
|
-
await
|
|
227
|
+
await exec(bundleExecutable(), ['install'], { cwd: shopifyCLIDirectory() });
|
|
228
228
|
}
|
|
229
229
|
/**
|
|
230
230
|
* It runs bundle install for the CLI-managed copy of theme-check.
|
|
231
231
|
*/
|
|
232
232
|
async function bundleInstallThemeCheck() {
|
|
233
|
-
await
|
|
233
|
+
await exec(bundleExecutable(), ['config', 'set', '--local', 'path', themeCheckDirectory()], {
|
|
234
234
|
cwd: themeCheckDirectory(),
|
|
235
235
|
});
|
|
236
|
-
await
|
|
236
|
+
await exec(bundleExecutable(), ['install'], { cwd: themeCheckDirectory() });
|
|
237
237
|
}
|
|
238
238
|
/**
|
|
239
239
|
* It returns the directory where the Ruby CLI is located.
|
|
@@ -257,8 +257,7 @@ function themeCheckDirectory() {
|
|
|
257
257
|
*/
|
|
258
258
|
export async function version() {
|
|
259
259
|
const parseOutput = (version) => version.match(/ruby (\d+\.\d+\.\d+)/)?.[1];
|
|
260
|
-
return
|
|
261
|
-
.captureOutput(rubyExecutable(), ['-v'])
|
|
260
|
+
return captureOutput(rubyExecutable(), ['-v'])
|
|
262
261
|
.then(parseOutput)
|
|
263
262
|
.catch(() => undefined);
|
|
264
263
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ru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AAC,WAAW,CAAC;SACjB,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;AAC3B,CAAC;AAED;;;;;;GAMG;AACH,SAAS,aAAa;IACpB,OAAO,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAA;AACxC,CAAC;AAED;;;;GAIG;AACH,SAAS,cAAc;IACrB,MAAM,UAAU,GAAG,aAAa,EAAE,CAAA;IAClC,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;AACvD,CAAC;AAED;;;;GAIG;AACH,SAAS,gBAAgB;IACvB,MAAM,UAAU,GAAG,aAAa,EAAE,CAAA;IAClC,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAA;AAC3D,CAAC;AAED;;;;GAIG;AACH,SAAS,aAAa;IACpB,MAAM,UAAU,GAAG,aAAa,EAAE,CAAA;IAClC,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;AACrD,CAAC","sourcesContent":["import {coerceSemverVersion} from './semver.js'\nimport {AbortSignal} from './abort.js'\nimport {platformAndArch} from './os.js'\nimport * as file from '../../file.js'\nimport * as ui from '../../ui.js'\nimport * as system from '../../system.js'\nimport {Abort, AbortSilent} from '../../error.js'\nimport {glob, join} from '../../path.js'\nimport constants from '../../constants.js'\nimport {AdminSession} from '../../session.js'\nimport {content, token} from '../../output.js'\nimport {Writable} from 'stream'\n\nconst RubyCLIVersion = '2.34.0'\nconst ThemeCheckVersion = '1.14.0'\nconst MinBundlerVersion = '2.3.8'\nconst MinRubyVersion = '2.7.5'\n\ninterface ExecCLI2Options {\n // Contains token and store to pass to CLI 2.0, which will be set as environment variables\n adminSession?: AdminSession\n // Contains token for storefront access to pass to CLI 2.0 as environment variable\n storefrontToken?: string\n // Contains token for partners access to pass to CLI 2.0 as environment variable\n token?: string\n // Directory in which to execute the command. Otherwise the current directory will be used.\n directory?: string\n // A signal to stop the process execution.\n signal?: AbortSignal\n}\n/**\n * Execute CLI 2.0 commands.\n * Installs a version of RubyCLI as a vendor dependency in a hidden folder in the system.\n * User must have a valid ruby+bundler environment to run any command.\n *\n * @param args - List of argumets to execute. (ex: ['theme', 'pull']).\n * @param options - Options to customize the execution of cli2.\n */\nexport async function execCLI2(args: string[], options: ExecCLI2Options = {}): Promise<void> {\n await installCLIDependencies()\n const env: NodeJS.ProcessEnv = {\n ...process.env,\n SHOPIFY_CLI_STOREFRONT_RENDERER_AUTH_TOKEN: options.storefrontToken,\n SHOPIFY_CLI_ADMIN_AUTH_TOKEN: options.adminSession?.token,\n SHOPIFY_SHOP: options.adminSession?.storeFqdn,\n SHOPIFY_CLI_AUTH_TOKEN: options.token,\n SHOPIFY_CLI_RUN_AS_SUBPROCESS: 'true',\n // Bundler uses this Gemfile to understand which gems are available in the\n // environment. We use this to specify our own Gemfile for CLI2, which exists\n // outside the user's project directory.\n BUNDLE_GEMFILE: join(shopifyCLIDirectory(), 'Gemfile'),\n }\n\n try {\n await system.exec(bundleExecutable(), ['exec', 'shopify'].concat(args), {\n stdio: 'inherit',\n cwd: options.directory ?? process.cwd(),\n env,\n signal: options.signal,\n })\n } catch (error) {\n // CLI2 will show it's own errors, we don't need to show an additional CLI3 error\n throw new AbortSilent()\n }\n}\n\ninterface ExecThemeCheckCLIOptions {\n /** A list of directories in which theme-check should run. */\n directories: string[]\n /** Arguments to pass to the theme-check CLI. */\n args?: string[]\n /** Writable to send standard output content through. */\n stdout: Writable\n /** Writable to send standard error content through. */\n stderr: Writable\n}\n\n/**\n * A function that installs (if needed) and runs the theme-check CLI.\n *\n * @param options - Options to customize the execution of theme-check.\n * @returns A promise that resolves or rejects depending on the result of the underlying theme-check process.\n */\nexport async function execThemeCheckCLI(options: ExecThemeCheckCLIOptions): Promise<void[]> {\n await installThemeCheckCLIDependencies(options.stdout)\n\n const processes = options.directories.map(async (directory): Promise<void> => {\n // Check that there are files aside from the extension TOML config file,\n // otherwise theme-check will return a false failure.\n const files = await glob(join(directory, '/**/*'))\n const fileCount = files.filter((file) => !file.match(/\\.toml$/)).length\n if (fileCount === 0) return\n\n const customStderr = new Writable({\n write(chunk, ...args) {\n // For some reason, theme-check reports this initial status line to stderr\n // See https://github.com/Shopify/theme-check/blob/1092737cfb58a73ca397ffb1371665dc55df2976/lib/theme_check/language_server/diagnostics_engine.rb#L31\n // which leads to https://github.com/Shopify/theme-check/blob/1092737cfb58a73ca397ffb1371665dc55df2976/lib/theme_check/language_server/io_messenger.rb#L65\n if (chunk.toString('ascii').match(/^Checking/)) {\n options.stdout.write(chunk, ...args)\n } else {\n options.stderr.write(chunk, ...args)\n }\n },\n })\n await system.exec(bundleExecutable(), ['exec', 'theme-check'].concat([directory, ...(options.args || [])]), {\n stdout: options.stdout,\n stderr: customStderr,\n cwd: themeCheckDirectory(),\n })\n })\n return Promise.all(processes)\n}\n\n/**\n * Validate Ruby Enviroment\n * Install Theme Check CLI and its dependencies\n * Shows a loading message if it's the first time installing dependencies\n * or if we are installing a new version of Theme Check CLI.\n *\n * @param stdout - The Writable stream on which to write the standard output.\n */\nasync function installThemeCheckCLIDependencies(stdout: Writable) {\n const exists = await file.exists(themeCheckDirectory())\n\n if (!exists) stdout.write('Installing theme dependencies...')\n const list = ui.newListr(\n [\n {\n title: 'Installing theme dependencies',\n task: async () => {\n await validateRubyEnv()\n await createThemeCheckCLIWorkingDirectory()\n await createThemeCheckGemfile()\n await bundleInstallThemeCheck()\n },\n },\n ],\n {renderer: 'silent'},\n )\n await list.run()\n if (!exists) stdout.write('Installed theme dependencies!')\n}\n\n/**\n * Validate Ruby Enviroment\n * Install RubyCLI and its dependencies\n * Shows a loading spinner if it's the first time installing dependencies\n * or if we are installing a new version of RubyCLI.\n */\nasync function installCLIDependencies() {\n const exists = await file.exists(shopifyCLIDirectory())\n const renderer = exists ? 'silent' : 'default'\n\n const list = ui.newListr(\n [\n {\n title: 'Installing theme dependencies',\n task: async () => {\n const usingLocalCLI2 = Boolean(process.env.SHOPIFY_CLI_2_0_DIRECTORY)\n await validateRubyEnv()\n if (usingLocalCLI2) {\n await bundleInstallLocalShopifyCLI()\n } else {\n await createShopifyCLIWorkingDirectory()\n await createShopifyCLIGemfile()\n await bundleInstallShopifyCLI()\n }\n },\n },\n ],\n {renderer},\n )\n await list.run()\n}\n\n/**\n * A function that validates if the environment in which the CLI is running is set up with Ruby and Bundler.\n */\nasync function validateRubyEnv() {\n await validateRuby()\n await validateBundler()\n}\n\n/**\n * A function that validates if the environment in which the CLI is running is set up with Ruby.\n */\nasync function validateRuby() {\n let version\n try {\n const stdout = await system.captureOutput(rubyExecutable(), ['-v'])\n version = coerceSemverVersion(stdout)\n } catch {\n throw new Abort(\n 'Ruby environment not found',\n `Make sure you have Ruby installed on your system. ${\n content`${token.link('Documentation.', 'https://www.ruby-lang.org/en/documentation/installation/')}`.value\n }`,\n )\n }\n\n const isValid = version?.compare(MinRubyVersion)\n if (isValid === -1 || isValid === undefined) {\n throw new Abort(\n `Ruby version ${content`${token.yellow(version.raw)}`.value} is not supported`,\n `Make sure you have at least Ruby ${content`${token.yellow(MinRubyVersion)}`.value} installed on your system. ${\n content`${token.link('Documentation.', 'https://www.ruby-lang.org/en/documentation/installation/')}`.value\n }`,\n )\n }\n}\n\n/**\n * A function that validates if the environment in which the CLI is running is set up with Bundler.\n */\nasync function validateBundler() {\n let version\n try {\n const stdout = await system.captureOutput(bundleExecutable(), ['-v'])\n version = coerceSemverVersion(stdout)\n } catch {\n throw new Abort(\n 'Bundler not found',\n `To install the latest version of Bundler, run ${\n content`${token.genericShellCommand(`${gemExecutable()} install bundler`)}`.value\n }`,\n )\n }\n\n const isValid = version?.compare(MinBundlerVersion)\n if (isValid === -1 || isValid === undefined) {\n throw new Abort(\n `Bundler version ${content`${token.yellow(version.raw)}`.value} is not supported`,\n `To update to the latest version of Bundler, run ${\n content`${token.genericShellCommand(`${gemExecutable()} install bundler`)}`.value\n }`,\n )\n }\n}\n\n/**\n * It creates the directory where the Ruby CLI will be downloaded along its dependencies.\n */\nasync function createShopifyCLIWorkingDirectory(): Promise<void> {\n return file.mkdir(shopifyCLIDirectory())\n}\n\n/**\n * It creates the directory where the theme-check CLI will be downloaded along its dependencies.\n */\nasync function createThemeCheckCLIWorkingDirectory(): Promise<void> {\n return file.mkdir(themeCheckDirectory())\n}\n\n/**\n * It creates the Gemfile to install The Ruby CLI and the dependencies.\n */\nasync function createShopifyCLIGemfile(): Promise<void> {\n const gemPath = join(shopifyCLIDirectory(), 'Gemfile')\n const gemFileContent = [\"source 'https://rubygems.org'\", `gem 'shopify-cli', '${RubyCLIVersion}'`]\n const {platform} = platformAndArch()\n if (platform === 'windows') {\n // 'wdm' is required by 'listen', see https://github.com/Shopify/cli/issues/780\n gemFileContent.push(\"gem 'wdm', '>= 0.1.0'\")\n }\n await file.write(gemPath, gemFileContent.join('\\n'))\n}\n\n/**\n * It creates the Gemfile to install theme-check and its dependencies.\n */\nasync function createThemeCheckGemfile(): Promise<void> {\n const gemPath = join(themeCheckDirectory(), 'Gemfile')\n await file.write(gemPath, `source 'https://rubygems.org'\\ngem 'theme-check', '${ThemeCheckVersion}'`)\n}\n\n/**\n * It runs bundle install for the dev-managed copy of the Ruby CLI.\n */\nasync function bundleInstallLocalShopifyCLI(): Promise<void> {\n await system.exec(bundleExecutable(), ['install'], {cwd: shopifyCLIDirectory()})\n}\n\n/**\n * It runs bundle install for the CLI-managed copy of the Ruby CLI.\n */\nasync function bundleInstallShopifyCLI() {\n await system.exec(bundleExecutable(), ['config', 'set', '--local', 'path', shopifyCLIDirectory()], {\n cwd: shopifyCLIDirectory(),\n })\n await system.exec(bundleExecutable(), ['install'], {cwd: shopifyCLIDirectory()})\n}\n\n/**\n * It runs bundle install for the CLI-managed copy of theme-check.\n */\nasync function bundleInstallThemeCheck() {\n await system.exec(bundleExecutable(), ['config', 'set', '--local', 'path', themeCheckDirectory()], {\n cwd: themeCheckDirectory(),\n })\n await system.exec(bundleExecutable(), ['install'], {cwd: themeCheckDirectory()})\n}\n\n/**\n * It returns the directory where the Ruby CLI is located.\n *\n * @returns The absolute path to the directory.\n */\nfunction shopifyCLIDirectory(): string {\n return (\n process.env.SHOPIFY_CLI_2_0_DIRECTORY ??\n join(constants.paths.directories.cache.vendor.path(), 'ruby-cli', RubyCLIVersion)\n )\n}\n\n/**\n * It returns the path to the directory containing the theme-check CLI.\n *\n * @returns The absolute path to the theme-check directory.\n */\nfunction themeCheckDirectory(): string {\n return join(constants.paths.directories.cache.vendor.path(), 'theme-check', ThemeCheckVersion)\n}\n\n/**\n * It returns the Ruby version present in the envirronment.\n */\nexport async function version(): Promise<string | undefined> {\n const parseOutput = (version: string) => version.match(/ruby (\\d+\\.\\d+\\.\\d+)/)?.[1]\n return system\n .captureOutput(rubyExecutable(), ['-v'])\n .then(parseOutput)\n .catch(() => undefined)\n}\n\n/**\n * It returns the Ruby binary path set through the environment variable SHOPIFY_RUBY_BINDIR.\n * This is useful when the CLI is managed by an installer like a Homebrew where we need to\n * point the CLI to the Ruby installation managed by Homebrew.\n *\n * @returns The value of the environment variable.\n */\nfunction getRubyBinDir(): string | undefined {\n return process.env.SHOPIFY_RUBY_BINDIR\n}\n\n/**\n * It returns the path to the \"ruby\" executable.\n *\n * @returns The path to the executable.\n */\nfunction rubyExecutable(): string {\n const rubyBinDir = getRubyBinDir()\n return rubyBinDir ? join(rubyBinDir, 'ruby') : 'ruby'\n}\n\n/**\n * It returns the path to the \"bundle\" executable.\n *\n * @returns The path to the executable.\n */\nfunction bundleExecutable(): string {\n const rubyBinDir = getRubyBinDir()\n return rubyBinDir ? join(rubyBinDir, 'bundle') : 'bundle'\n}\n\n/**\n * It returns the path to the \"gem\"\" executable.\n *\n * @returns The path to the executable.\n */\nfunction gemExecutable(): string {\n const rubyBinDir = getRubyBinDir()\n return rubyBinDir ? join(ruby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AAG,EAAE,CAAC,SAAS,CAAC,CAAA;AAC3B,CAAC;AAED;;;;;;GAMG;AACH,SAAS,aAAa;IACpB,OAAO,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAA;AACxC,CAAC;AAED;;;;GAIG;AACH,SAAS,cAAc;IACrB,MAAM,UAAU,GAAG,aAAa,EAAE,CAAA;IAClC,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;AACvD,CAAC;AAED;;;;GAIG;AACH,SAAS,gBAAgB;IACvB,MAAM,UAAU,GAAG,aAAa,EAAE,CAAA;IAClC,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAA;AAC3D,CAAC;AAED;;;;GAIG;AACH,SAAS,aAAa;IACpB,MAAM,UAAU,GAAG,aAAa,EAAE,CAAA;IAClC,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;AACrD,CAAC","sourcesContent":["import {coerceSemverVersion} from './semver.js'\nimport {AbortSignal} from './abort.js'\nimport {platformAndArch} from './os.js'\nimport {captureOutput, exec} from './system.js'\nimport * as file from '../../file.js'\nimport * as ui from '../../ui.js'\nimport {Abort, AbortSilent} from '../../error.js'\nimport {glob, join} from '../../path.js'\nimport constants from '../../constants.js'\nimport {AdminSession} from '../../public/node/session.js'\nimport {content, token} from '../../output.js'\nimport {Writable} from 'stream'\n\nconst RubyCLIVersion = '2.34.0'\nconst ThemeCheckVersion = '1.14.0'\nconst MinBundlerVersion = '2.3.8'\nconst MinRubyVersion = '2.7.5'\n\ninterface ExecCLI2Options {\n // Contains token and store to pass to CLI 2.0, which will be set as environment variables\n adminSession?: AdminSession\n // Contains token for storefront access to pass to CLI 2.0 as environment variable\n storefrontToken?: string\n // Contains token for partners access to pass to CLI 2.0 as environment variable\n token?: string\n // Directory in which to execute the command. Otherwise the current directory will be used.\n directory?: string\n // A signal to stop the process execution.\n signal?: AbortSignal\n}\n/**\n * Execute CLI 2.0 commands.\n * Installs a version of RubyCLI as a vendor dependency in a hidden folder in the system.\n * User must have a valid ruby+bundler environment to run any command.\n *\n * @param args - List of argumets to execute. (ex: ['theme', 'pull']).\n * @param options - Options to customize the execution of cli2.\n */\nexport async function execCLI2(args: string[], options: ExecCLI2Options = {}): Promise<void> {\n await installCLIDependencies()\n const env: NodeJS.ProcessEnv = {\n ...process.env,\n SHOPIFY_CLI_STOREFRONT_RENDERER_AUTH_TOKEN: options.storefrontToken,\n SHOPIFY_CLI_ADMIN_AUTH_TOKEN: options.adminSession?.token,\n SHOPIFY_SHOP: options.adminSession?.storeFqdn,\n SHOPIFY_CLI_AUTH_TOKEN: options.token,\n SHOPIFY_CLI_RUN_AS_SUBPROCESS: 'true',\n // Bundler uses this Gemfile to understand which gems are available in the\n // environment. We use this to specify our own Gemfile for CLI2, which exists\n // outside the user's project directory.\n BUNDLE_GEMFILE: join(shopifyCLIDirectory(), 'Gemfile'),\n }\n\n try {\n await exec(bundleExecutable(), ['exec', 'shopify'].concat(args), {\n stdio: 'inherit',\n cwd: options.directory ?? process.cwd(),\n env,\n signal: options.signal,\n })\n } catch (error) {\n // CLI2 will show it's own errors, we don't need to show an additional CLI3 error\n throw new AbortSilent()\n }\n}\n\ninterface ExecThemeCheckCLIOptions {\n /** A list of directories in which theme-check should run. */\n directories: string[]\n /** Arguments to pass to the theme-check CLI. */\n args?: string[]\n /** Writable to send standard output content through. */\n stdout: Writable\n /** Writable to send standard error content through. */\n stderr: Writable\n}\n\n/**\n * A function that installs (if needed) and runs the theme-check CLI.\n *\n * @param options - Options to customize the execution of theme-check.\n * @returns A promise that resolves or rejects depending on the result of the underlying theme-check process.\n */\nexport async function execThemeCheckCLI(options: ExecThemeCheckCLIOptions): Promise<void[]> {\n await installThemeCheckCLIDependencies(options.stdout)\n\n const processes = options.directories.map(async (directory): Promise<void> => {\n // Check that there are files aside from the extension TOML config file,\n // otherwise theme-check will return a false failure.\n const files = await glob(join(directory, '/**/*'))\n const fileCount = files.filter((file) => !file.match(/\\.toml$/)).length\n if (fileCount === 0) return\n\n const customStderr = new Writable({\n write(chunk, ...args) {\n // For some reason, theme-check reports this initial status line to stderr\n // See https://github.com/Shopify/theme-check/blob/1092737cfb58a73ca397ffb1371665dc55df2976/lib/theme_check/language_server/diagnostics_engine.rb#L31\n // which leads to https://github.com/Shopify/theme-check/blob/1092737cfb58a73ca397ffb1371665dc55df2976/lib/theme_check/language_server/io_messenger.rb#L65\n if (chunk.toString('ascii').match(/^Checking/)) {\n options.stdout.write(chunk, ...args)\n } else {\n options.stderr.write(chunk, ...args)\n }\n },\n })\n await exec(bundleExecutable(), ['exec', 'theme-check'].concat([directory, ...(options.args || [])]), {\n stdout: options.stdout,\n stderr: customStderr,\n cwd: themeCheckDirectory(),\n })\n })\n return Promise.all(processes)\n}\n\n/**\n * Validate Ruby Enviroment\n * Install Theme Check CLI and its dependencies\n * Shows a loading message if it's the first time installing dependencies\n * or if we are installing a new version of Theme Check CLI.\n *\n * @param stdout - The Writable stream on which to write the standard output.\n */\nasync function installThemeCheckCLIDependencies(stdout: Writable) {\n const exists = await file.exists(themeCheckDirectory())\n\n if (!exists) stdout.write('Installing theme dependencies...')\n const list = ui.newListr(\n [\n {\n title: 'Installing theme dependencies',\n task: async () => {\n await validateRubyEnv()\n await createThemeCheckCLIWorkingDirectory()\n await createThemeCheckGemfile()\n await bundleInstallThemeCheck()\n },\n },\n ],\n {renderer: 'silent'},\n )\n await list.run()\n if (!exists) stdout.write('Installed theme dependencies!')\n}\n\n/**\n * Validate Ruby Enviroment\n * Install RubyCLI and its dependencies\n * Shows a loading spinner if it's the first time installing dependencies\n * or if we are installing a new version of RubyCLI.\n */\nasync function installCLIDependencies() {\n const exists = await file.exists(shopifyCLIDirectory())\n const renderer = exists ? 'silent' : 'default'\n\n const list = ui.newListr(\n [\n {\n title: 'Installing theme dependencies',\n task: async () => {\n const usingLocalCLI2 = Boolean(process.env.SHOPIFY_CLI_2_0_DIRECTORY)\n await validateRubyEnv()\n if (usingLocalCLI2) {\n await bundleInstallLocalShopifyCLI()\n } else {\n await createShopifyCLIWorkingDirectory()\n await createShopifyCLIGemfile()\n await bundleInstallShopifyCLI()\n }\n },\n },\n ],\n {renderer},\n )\n await list.run()\n}\n\n/**\n * A function that validates if the environment in which the CLI is running is set up with Ruby and Bundler.\n */\nasync function validateRubyEnv() {\n await validateRuby()\n await validateBundler()\n}\n\n/**\n * A function that validates if the environment in which the CLI is running is set up with Ruby.\n */\nasync function validateRuby() {\n let version\n try {\n const stdout = await captureOutput(rubyExecutable(), ['-v'])\n version = coerceSemverVersion(stdout)\n } catch {\n throw new Abort(\n 'Ruby environment not found',\n `Make sure you have Ruby installed on your system. ${\n content`${token.link('Documentation.', 'https://www.ruby-lang.org/en/documentation/installation/')}`.value\n }`,\n )\n }\n\n const isValid = version?.compare(MinRubyVersion)\n if (isValid === -1 || isValid === undefined) {\n throw new Abort(\n `Ruby version ${content`${token.yellow(version.raw)}`.value} is not supported`,\n `Make sure you have at least Ruby ${content`${token.yellow(MinRubyVersion)}`.value} installed on your system. ${\n content`${token.link('Documentation.', 'https://www.ruby-lang.org/en/documentation/installation/')}`.value\n }`,\n )\n }\n}\n\n/**\n * A function that validates if the environment in which the CLI is running is set up with Bundler.\n */\nasync function validateBundler() {\n let version\n try {\n const stdout = await captureOutput(bundleExecutable(), ['-v'])\n version = coerceSemverVersion(stdout)\n } catch {\n throw new Abort(\n 'Bundler not found',\n `To install the latest version of Bundler, run ${\n content`${token.genericShellCommand(`${gemExecutable()} install bundler`)}`.value\n }`,\n )\n }\n\n const isValid = version?.compare(MinBundlerVersion)\n if (isValid === -1 || isValid === undefined) {\n throw new Abort(\n `Bundler version ${content`${token.yellow(version.raw)}`.value} is not supported`,\n `To update to the latest version of Bundler, run ${\n content`${token.genericShellCommand(`${gemExecutable()} install bundler`)}`.value\n }`,\n )\n }\n}\n\n/**\n * It creates the directory where the Ruby CLI will be downloaded along its dependencies.\n */\nasync function createShopifyCLIWorkingDirectory(): Promise<void> {\n return file.mkdir(shopifyCLIDirectory())\n}\n\n/**\n * It creates the directory where the theme-check CLI will be downloaded along its dependencies.\n */\nasync function createThemeCheckCLIWorkingDirectory(): Promise<void> {\n return file.mkdir(themeCheckDirectory())\n}\n\n/**\n * It creates the Gemfile to install The Ruby CLI and the dependencies.\n */\nasync function createShopifyCLIGemfile(): Promise<void> {\n const gemPath = join(shopifyCLIDirectory(), 'Gemfile')\n const gemFileContent = [\"source 'https://rubygems.org'\", `gem 'shopify-cli', '${RubyCLIVersion}'`]\n const {platform} = platformAndArch()\n if (platform === 'windows') {\n // 'wdm' is required by 'listen', see https://github.com/Shopify/cli/issues/780\n gemFileContent.push(\"gem 'wdm', '>= 0.1.0'\")\n }\n await file.write(gemPath, gemFileContent.join('\\n'))\n}\n\n/**\n * It creates the Gemfile to install theme-check and its dependencies.\n */\nasync function createThemeCheckGemfile(): Promise<void> {\n const gemPath = join(themeCheckDirectory(), 'Gemfile')\n await file.write(gemPath, `source 'https://rubygems.org'\\ngem 'theme-check', '${ThemeCheckVersion}'`)\n}\n\n/**\n * It runs bundle install for the dev-managed copy of the Ruby CLI.\n */\nasync function bundleInstallLocalShopifyCLI(): Promise<void> {\n await exec(bundleExecutable(), ['install'], {cwd: shopifyCLIDirectory()})\n}\n\n/**\n * It runs bundle install for the CLI-managed copy of the Ruby CLI.\n */\nasync function bundleInstallShopifyCLI() {\n await exec(bundleExecutable(), ['config', 'set', '--local', 'path', shopifyCLIDirectory()], {\n cwd: shopifyCLIDirectory(),\n })\n await exec(bundleExecutable(), ['install'], {cwd: shopifyCLIDirectory()})\n}\n\n/**\n * It runs bundle install for the CLI-managed copy of theme-check.\n */\nasync function bundleInstallThemeCheck() {\n await exec(bundleExecutable(), ['config', 'set', '--local', 'path', themeCheckDirectory()], {\n cwd: themeCheckDirectory(),\n })\n await exec(bundleExecutable(), ['install'], {cwd: themeCheckDirectory()})\n}\n\n/**\n * It returns the directory where the Ruby CLI is located.\n *\n * @returns The absolute path to the directory.\n */\nfunction shopifyCLIDirectory(): string {\n return (\n process.env.SHOPIFY_CLI_2_0_DIRECTORY ??\n join(constants.paths.directories.cache.vendor.path(), 'ruby-cli', RubyCLIVersion)\n )\n}\n\n/**\n * It returns the path to the directory containing the theme-check CLI.\n *\n * @returns The absolute path to the theme-check directory.\n */\nfunction themeCheckDirectory(): string {\n return join(constants.paths.directories.cache.vendor.path(), 'theme-check', ThemeCheckVersion)\n}\n\n/**\n * It returns the Ruby version present in the envirronment.\n */\nexport async function version(): Promise<string | undefined> {\n const parseOutput = (version: string) => version.match(/ruby (\\d+\\.\\d+\\.\\d+)/)?.[1]\n return captureOutput(rubyExecutable(), ['-v'])\n .then(parseOutput)\n .catch(() => undefined)\n}\n\n/**\n * It returns the Ruby binary path set through the environment variable SHOPIFY_RUBY_BINDIR.\n * This is useful when the CLI is managed by an installer like a Homebrew where we need to\n * point the CLI to the Ruby installation managed by Homebrew.\n *\n * @returns The value of the environment variable.\n */\nfunction getRubyBinDir(): string | undefined {\n return process.env.SHOPIFY_RUBY_BINDIR\n}\n\n/**\n * It returns the path to the \"ruby\" executable.\n *\n * @returns The path to the executable.\n */\nfunction rubyExecutable(): string {\n const rubyBinDir = getRubyBinDir()\n return rubyBinDir ? join(rubyBinDir, 'ruby') : 'ruby'\n}\n\n/**\n * It returns the path to the \"bundle\" executable.\n *\n * @returns The path to the executable.\n */\nfunction bundleExecutable(): string {\n const rubyBinDir = getRubyBinDir()\n return rubyBinDir ? join(rubyBinDir, 'bundle') : 'bundle'\n}\n\n/**\n * It returns the path to the \"gem\"\" executable.\n *\n * @returns The path to the executable.\n */\nfunction gemExecutable(): string {\n const rubyBinDir = getRubyBinDir()\n return rubyBinDir ? join(rubyBinDir, 'gem') : 'gem'\n}\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* Session Object to access the Admin API, includes the token and the store FQDN.
|
|
4
|
+
*/
|
|
5
|
+
export interface AdminSession {
|
|
6
|
+
token: string;
|
|
7
|
+
storeFqdn: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Ensure that we have a valid session to access the Partners API.
|
|
11
|
+
* If SHOPIFY_CLI_PARTNERS_TOKEN exists, that token will be used to obtain a valid Partners Token
|
|
12
|
+
* If SHOPIFY_CLI_PARTNERS_TOKEN exists, scopes will be ignored.
|
|
13
|
+
*
|
|
14
|
+
* @param scopes - Optional array of extra scopes to authenticate with.
|
|
15
|
+
* @param env - Optional environment variables to use.
|
|
16
|
+
* @returns The access token for the Partners API.
|
|
17
|
+
*/
|
|
18
|
+
export declare function ensureAuthenticatedPartners(scopes?: string[], env?: NodeJS.ProcessEnv): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* Ensure that we have a valid session to access the Storefront API.
|
|
21
|
+
*
|
|
22
|
+
* @param scopes - Optional array of extra scopes to authenticate with.
|
|
23
|
+
* @param password - Optional password to use.
|
|
24
|
+
* @returns The access token for the Storefront API.
|
|
25
|
+
*/
|
|
26
|
+
export declare function ensureAuthenticatedStorefront(scopes?: string[], password?: string | undefined): Promise<string>;
|
|
27
|
+
/**
|
|
28
|
+
* Ensure that we have a valid Admin session for the given store.
|
|
29
|
+
*
|
|
30
|
+
* @param store - Store fqdn to request auth for.
|
|
31
|
+
* @param scopes - Optional array of extra scopes to authenticate with.
|
|
32
|
+
* @param forceRefresh - Optional flag to force a refresh of the token.
|
|
33
|
+
* @returns The access token for the Admin API.
|
|
34
|
+
*/
|
|
35
|
+
export declare function ensureAuthenticatedAdmin(store: string, scopes?: string[], forceRefresh?: boolean): Promise<AdminSession>;
|
|
36
|
+
/**
|
|
37
|
+
* Ensure that we have a valid session to access the Theme API.
|
|
38
|
+
* If a password is provided, that token will be used against Theme Access API.
|
|
39
|
+
* Otherwise, it will ensure that the user is authenticated with the Admin API.
|
|
40
|
+
*
|
|
41
|
+
* @param store - Store fqdn to request auth for.
|
|
42
|
+
* @param password - Password generated from Theme Access app.
|
|
43
|
+
* @param scopes - Optional array of extra scopes to authenticate with.
|
|
44
|
+
* @param forceRefresh - Optional flag to force a refresh of the token.
|
|
45
|
+
* @returns The access token and store.
|
|
46
|
+
*/
|
|
47
|
+
export declare function ensureAuthenticatedThemes(store: string, password: string | undefined, scopes?: string[], forceRefresh?: boolean): Promise<AdminSession>;
|
|
48
|
+
/**
|
|
49
|
+
* Logout from Shopify.
|
|
50
|
+
*
|
|
51
|
+
* @returns A promise that resolves when the logout is complete.
|
|
52
|
+
*/
|
|
53
|
+
export declare function logout(): Promise<void>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { normalizeStoreFqdn } from './environment/fqdn.js';
|
|
2
|
+
import * as secureStore from '../../private/node/session/store.js';
|
|
3
|
+
import { exchangeCustomPartnerToken } from '../../private/node/session/exchange.js';
|
|
4
|
+
import constants from '../../constants.js';
|
|
5
|
+
import { content, token, debug } from '../../output.js';
|
|
6
|
+
import { Bug } from '../../error.js';
|
|
7
|
+
import { ensureAuthenticated } from '../../private/node/session.js';
|
|
8
|
+
/**
|
|
9
|
+
* Ensure that we have a valid session to access the Partners API.
|
|
10
|
+
* If SHOPIFY_CLI_PARTNERS_TOKEN exists, that token will be used to obtain a valid Partners Token
|
|
11
|
+
* If SHOPIFY_CLI_PARTNERS_TOKEN exists, scopes will be ignored.
|
|
12
|
+
*
|
|
13
|
+
* @param scopes - Optional array of extra scopes to authenticate with.
|
|
14
|
+
* @param env - Optional environment variables to use.
|
|
15
|
+
* @returns The access token for the Partners API.
|
|
16
|
+
*/
|
|
17
|
+
export async function ensureAuthenticatedPartners(scopes = [], env = process.env) {
|
|
18
|
+
debug(content `Ensuring that the user is authenticated with the Partners API with the following scopes:
|
|
19
|
+
${token.json(scopes)}
|
|
20
|
+
`);
|
|
21
|
+
const envToken = env[constants.environmentVariables.partnersToken];
|
|
22
|
+
if (envToken) {
|
|
23
|
+
return (await exchangeCustomPartnerToken(envToken)).accessToken;
|
|
24
|
+
}
|
|
25
|
+
const tokens = await ensureAuthenticated({ partnersApi: { scopes } });
|
|
26
|
+
if (!tokens.partners) {
|
|
27
|
+
throw new Bug('No partners token found after ensuring authenticated');
|
|
28
|
+
}
|
|
29
|
+
return tokens.partners;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Ensure that we have a valid session to access the Storefront API.
|
|
33
|
+
*
|
|
34
|
+
* @param scopes - Optional array of extra scopes to authenticate with.
|
|
35
|
+
* @param password - Optional password to use.
|
|
36
|
+
* @returns The access token for the Storefront API.
|
|
37
|
+
*/
|
|
38
|
+
export async function ensureAuthenticatedStorefront(scopes = [], password = undefined) {
|
|
39
|
+
if (password)
|
|
40
|
+
return password;
|
|
41
|
+
debug(content `Ensuring that the user is authenticated with the Storefront API with the following scopes:
|
|
42
|
+
${token.json(scopes)}
|
|
43
|
+
`);
|
|
44
|
+
const tokens = await ensureAuthenticated({ storefrontRendererApi: { scopes } });
|
|
45
|
+
if (!tokens.storefront) {
|
|
46
|
+
throw new Bug('No storefront token found after ensuring authenticated');
|
|
47
|
+
}
|
|
48
|
+
return tokens.storefront;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Ensure that we have a valid Admin session for the given store.
|
|
52
|
+
*
|
|
53
|
+
* @param store - Store fqdn to request auth for.
|
|
54
|
+
* @param scopes - Optional array of extra scopes to authenticate with.
|
|
55
|
+
* @param forceRefresh - Optional flag to force a refresh of the token.
|
|
56
|
+
* @returns The access token for the Admin API.
|
|
57
|
+
*/
|
|
58
|
+
export async function ensureAuthenticatedAdmin(store, scopes = [], forceRefresh = false) {
|
|
59
|
+
debug(content `Ensuring that the user is authenticated with the Admin API with the following scopes for the store ${token.raw(store)}:
|
|
60
|
+
${token.json(scopes)}
|
|
61
|
+
`);
|
|
62
|
+
const tokens = await ensureAuthenticated({ adminApi: { scopes, storeFqdn: store } }, process.env, forceRefresh);
|
|
63
|
+
if (!tokens.admin) {
|
|
64
|
+
throw new Bug('No admin token found after ensuring authenticated');
|
|
65
|
+
}
|
|
66
|
+
return tokens.admin;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Ensure that we have a valid session to access the Theme API.
|
|
70
|
+
* If a password is provided, that token will be used against Theme Access API.
|
|
71
|
+
* Otherwise, it will ensure that the user is authenticated with the Admin API.
|
|
72
|
+
*
|
|
73
|
+
* @param store - Store fqdn to request auth for.
|
|
74
|
+
* @param password - Password generated from Theme Access app.
|
|
75
|
+
* @param scopes - Optional array of extra scopes to authenticate with.
|
|
76
|
+
* @param forceRefresh - Optional flag to force a refresh of the token.
|
|
77
|
+
* @returns The access token and store.
|
|
78
|
+
*/
|
|
79
|
+
export async function ensureAuthenticatedThemes(store, password, scopes = [], forceRefresh = false) {
|
|
80
|
+
debug(content `Ensuring that the user is authenticated with the Theme API with the following scopes:
|
|
81
|
+
${token.json(scopes)}
|
|
82
|
+
`);
|
|
83
|
+
if (password)
|
|
84
|
+
return { token: password, storeFqdn: await normalizeStoreFqdn(store) };
|
|
85
|
+
return ensureAuthenticatedAdmin(store, scopes, forceRefresh);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Logout from Shopify.
|
|
89
|
+
*
|
|
90
|
+
* @returns A promise that resolves when the logout is complete.
|
|
91
|
+
*/
|
|
92
|
+
export function logout() {
|
|
93
|
+
return secureStore.remove();
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=session.js.map
|