@shopify/cli-kit 3.79.2 → 3.80.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/private/node/session/exchange.d.ts +4 -0
- package/dist/private/node/session/exchange.js +7 -7
- package/dist/private/node/session/exchange.js.map +1 -1
- package/dist/public/common/version.d.ts +1 -1
- package/dist/public/common/version.js +1 -1
- package/dist/public/common/version.js.map +1 -1
- package/dist/public/node/archiver.d.ts +39 -0
- package/dist/public/node/archiver.js +59 -2
- package/dist/public/node/archiver.js.map +1 -1
- package/dist/public/node/context/fqdn.d.ts +6 -0
- package/dist/public/node/context/fqdn.js +17 -0
- package/dist/public/node/context/fqdn.js.map +1 -1
- package/dist/public/node/fs.d.ts +6 -0
- package/dist/public/node/fs.js +9 -1
- package/dist/public/node/fs.js.map +1 -1
- package/dist/public/node/git.d.ts +7 -0
- package/dist/public/node/git.js +12 -0
- package/dist/public/node/git.js.map +1 -1
- package/dist/public/node/hooks/prerun.js +2 -1
- package/dist/public/node/hooks/prerun.js.map +1 -1
- package/dist/public/node/http.js +2 -2
- package/dist/public/node/http.js.map +1 -1
- package/dist/public/node/tcp.js +8 -3
- package/dist/public/node/tcp.js.map +1 -1
- package/dist/public/node/ui/components.d.ts +1 -0
- package/dist/public/node/ui/components.js +1 -0
- package/dist/public/node/ui/components.js.map +1 -1
- package/dist/public/node/version.d.ts +8 -0
- package/dist/public/node/version.js +11 -1
- package/dist/public/node/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ApplicationToken, IdentityToken } from './schema.js';
|
|
2
|
+
import { API } from '../api.js';
|
|
2
3
|
import { Result } from '../../../public/node/result.js';
|
|
3
4
|
import { ExtendableError } from '../../../public/node/error.js';
|
|
4
5
|
export declare class InvalidGrantError extends ExtendableError {
|
|
@@ -61,4 +62,7 @@ type IdentityDeviceError = 'authorization_pending' | 'access_denied' | 'expired_
|
|
|
61
62
|
* @returns An instance with the identity access tokens.
|
|
62
63
|
*/
|
|
63
64
|
export declare function exchangeDeviceCodeForAccessToken(deviceCode: string): Promise<Result<IdentityToken, IdentityDeviceError>>;
|
|
65
|
+
export declare function requestAppToken(api: API, token: string, scopes?: string[], store?: string): Promise<{
|
|
66
|
+
[x: string]: ApplicationToken;
|
|
67
|
+
}>;
|
|
64
68
|
export {};
|
|
@@ -114,12 +114,12 @@ export async function exchangeDeviceCodeForAccessToken(deviceCode) {
|
|
|
114
114
|
};
|
|
115
115
|
const tokenResult = await tokenRequest(params);
|
|
116
116
|
if (tokenResult.isErr()) {
|
|
117
|
-
return err(tokenResult.error);
|
|
117
|
+
return err(tokenResult.error.error);
|
|
118
118
|
}
|
|
119
119
|
const identityToken = buildIdentityToken(tokenResult.value);
|
|
120
120
|
return ok(identityToken);
|
|
121
121
|
}
|
|
122
|
-
async function requestAppToken(api, token, scopes = [], store) {
|
|
122
|
+
export async function requestAppToken(api, token, scopes = [], store) {
|
|
123
123
|
const appId = applicationId(api);
|
|
124
124
|
const clientId = await getIdentityClientId();
|
|
125
125
|
const params = {
|
|
@@ -130,7 +130,7 @@ async function requestAppToken(api, token, scopes = [], store) {
|
|
|
130
130
|
audience: appId,
|
|
131
131
|
scope: scopes.join(' '),
|
|
132
132
|
subject_token: token,
|
|
133
|
-
...(api === 'admin' && { destination: `https://${store}/admin
|
|
133
|
+
...(api === 'admin' && { destination: `https://${store}/admin`, store }),
|
|
134
134
|
};
|
|
135
135
|
let identifier = appId;
|
|
136
136
|
if (api === 'admin' && store) {
|
|
@@ -141,15 +141,15 @@ async function requestAppToken(api, token, scopes = [], store) {
|
|
|
141
141
|
const appToken = buildApplicationToken(value);
|
|
142
142
|
return { [identifier]: appToken };
|
|
143
143
|
}
|
|
144
|
-
function tokenRequestErrorHandler(error) {
|
|
145
|
-
const invalidTargetErrorMessage =
|
|
144
|
+
function tokenRequestErrorHandler({ error, store }) {
|
|
145
|
+
const invalidTargetErrorMessage = `You are not authorized to use the CLI to develop in the provided store${store ? `: ${store}` : '.'}` +
|
|
146
146
|
'\n\n' +
|
|
147
147
|
"You can't use Shopify CLI with development stores if you only have Partner " +
|
|
148
148
|
'staff member access. If you want to use Shopify CLI to work on a development store, then ' +
|
|
149
149
|
'you should be the store owner or create a staff account on the store.' +
|
|
150
150
|
'\n\n' +
|
|
151
151
|
"If you're the store owner, then you need to log in to the store directly using the " +
|
|
152
|
-
'store URL at least once before you log in using Shopify CLI.' +
|
|
152
|
+
'store URL at least once before you log in using Shopify CLI. ' +
|
|
153
153
|
'Logging in to the Shopify admin directly connects the development ' +
|
|
154
154
|
'store with your Shopify login.';
|
|
155
155
|
if (error === 'invalid_grant') {
|
|
@@ -177,7 +177,7 @@ async function tokenRequest(params) {
|
|
|
177
177
|
const payload = await res.json();
|
|
178
178
|
if (res.ok)
|
|
179
179
|
return ok(payload);
|
|
180
|
-
return err(payload.error);
|
|
180
|
+
return err({ error: payload.error, store: params.store });
|
|
181
181
|
}
|
|
182
182
|
function buildIdentityToken(result, existingUserId) {
|
|
183
183
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../../../src/private/node/session/exchange.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAE,QAAQ,IAAI,mBAAmB,EAAC,MAAM,eAAe,CAAA;AAC5E,OAAO,EAAC,mBAAmB,EAAC,MAAM,aAAa,CAAA;AAE/C,OAAO,EAAC,YAAY,EAAC,MAAM,sCAAsC,CAAA;AACjE,OAAO,EAAC,YAAY,EAAC,MAAM,8BAA8B,CAAA;AACzD,OAAO,EAAC,GAAG,EAAE,EAAE,EAAS,MAAM,gCAAgC,CAAA;AAC9D,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAE,eAAe,EAAC,MAAM,+BAA+B,CAAA;AACnF,OAAO,EAAC,qBAAqB,EAAE,0BAA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,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC;QAC/B,MAAM;KACP,CAAA;AACH,CAAC;AAED,SAAS,qBAAqB,CAAC,MAA0B;IACvD,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,YAAY;QAChC,SAAS,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC;QAC1D,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC;KAChC,CAAA;AACH,CAAC","sourcesContent":["import {ApplicationToken, IdentityToken} from './schema.js'\nimport {applicationId, clientId as getIdentityClientId} from './identity.js'\nimport {tokenExchangeScopes} from './scopes.js'\nimport {API} from '../api.js'\nimport {identityFqdn} from '../../../public/node/context/fqdn.js'\nimport {shopifyFetch} from '../../../public/node/http.js'\nimport {err, ok, Result} from '../../../public/node/result.js'\nimport {AbortError, BugError, ExtendableError} from '../../../public/node/error.js'\nimport {setLastSeenAuthMethod, setLastSeenUserIdAfterAuth} from '../session.js'\nimport * as jose from 'jose'\nimport {nonRandomUUID} from '@shopify/cli-kit/node/crypto'\n\nexport class InvalidGrantError extends ExtendableError {}\nexport class InvalidRequestError extends ExtendableError {}\nclass InvalidTargetError extends AbortError {}\n\nexport interface ExchangeScopes {\n admin: string[]\n partners: string[]\n storefront: string[]\n businessPlatform: string[]\n appManagement: string[]\n}\n\n/**\n * Given an identity token, request an application token.\n * @param identityToken - access token obtained in a previous step\n * @param store - the store to use, only needed for admin API\n * @returns An array with the application access tokens.\n */\nexport async function exchangeAccessForApplicationTokens(\n identityToken: IdentityToken,\n scopes: ExchangeScopes,\n store?: string,\n): Promise<{[x: string]: ApplicationToken}> {\n const token = identityToken.accessToken\n\n const [partners, storefront, businessPlatform, admin, appManagement] = await Promise.all([\n requestAppToken('partners', token, scopes.partners),\n requestAppToken('storefront-renderer', token, scopes.storefront),\n requestAppToken('business-platform', token, scopes.businessPlatform),\n store ? requestAppToken('admin', token, scopes.admin, store) : {},\n requestAppToken('app-management', token, scopes.appManagement),\n ])\n\n return {\n ...partners,\n ...storefront,\n ...businessPlatform,\n ...admin,\n ...appManagement,\n }\n}\n\n/**\n * Given an expired access token, refresh it to get a new one.\n */\nexport async function refreshAccessToken(currentToken: IdentityToken): Promise<IdentityToken> {\n const clientId = getIdentityClientId()\n const params = {\n grant_type: 'refresh_token',\n access_token: currentToken.accessToken,\n refresh_token: currentToken.refreshToken,\n client_id: clientId,\n }\n const tokenResult = await tokenRequest(params)\n const value = tokenResult.mapError(tokenRequestErrorHandler).valueOrBug()\n return buildIdentityToken(value, currentToken.userId)\n}\n\n/**\n * Given a custom CLI token passed as ENV variable request a valid API access token\n * @param token - The CLI token passed as ENV variable `SHOPIFY_CLI_PARTNERS_TOKEN`\n * @param apiName - The API to exchange for the access token\n * @param scopes - The scopes to request with the access token\n * @returns An instance with the application access tokens.\n */\nasync function exchangeCliTokenForAccessToken(\n apiName: API,\n token: string,\n scopes: string[],\n): Promise<{accessToken: string; userId: string}> {\n const appId = applicationId(apiName)\n try {\n const newToken = await requestAppToken(apiName, token, scopes)\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const accessToken = newToken[appId]!.accessToken\n const userId = nonRandomUUID(token)\n setLastSeenUserIdAfterAuth(userId)\n setLastSeenAuthMethod('partners_token')\n return {accessToken, userId}\n } catch (error) {\n const prettyName = apiName.replace(/-/g, ' ').replace(/\\b\\w/g, (char) => char.toUpperCase())\n throw new AbortError(\n `The custom token provided can't be used for the ${prettyName} API.`,\n 'Ensure the token is correct and not expired.',\n )\n }\n}\n\n/**\n * Given a custom CLI token passed as ENV variable, request a valid Partners API token\n * This token does not accept extra scopes, just the cli one.\n * @param token - The CLI token passed as ENV variable `SHOPIFY_CLI_PARTNERS_TOKEN`\n * @returns An instance with the application access tokens.\n */\nexport async function exchangeCustomPartnerToken(token: string): Promise<{accessToken: string; userId: string}> {\n return exchangeCliTokenForAccessToken('partners', token, tokenExchangeScopes('partners'))\n}\n\n/**\n * Given a custom CLI token passed as ENV variable, request a valid App Management API token\n * @param token - The CLI token passed as ENV variable `SHOPIFY_CLI_PARTNERS_TOKEN`\n * @returns An instance with the application access tokens.\n */\nexport async function exchangeCliTokenForAppManagementAccessToken(\n token: string,\n): Promise<{accessToken: string; userId: string}> {\n return exchangeCliTokenForAccessToken('app-management', token, tokenExchangeScopes('app-management'))\n}\n\n/**\n * Given a custom CLI token passed as ENV variable, request a valid Business Platform API token\n * @param token - The CLI token passed as ENV variable `SHOPIFY_CLI_PARTNERS_TOKEN`\n * @returns An instance with the application access tokens.\n */\nexport async function exchangeCliTokenForBusinessPlatformAccessToken(\n token: string,\n): Promise<{accessToken: string; userId: string}> {\n return exchangeCliTokenForAccessToken('business-platform', token, tokenExchangeScopes('business-platform'))\n}\n\ntype IdentityDeviceError = 'authorization_pending' | 'access_denied' | 'expired_token' | 'slow_down' | 'unknown_failure'\n\n/**\n * Given a deviceCode obtained after starting a device identity flow, request an identity token.\n * @param deviceCode - The device code obtained after starting a device identity flow\n * @param scopes - The scopes to request\n * @returns An instance with the identity access tokens.\n */\nexport async function exchangeDeviceCodeForAccessToken(\n deviceCode: string,\n): Promise<Result<IdentityToken, IdentityDeviceError>> {\n const clientId = await getIdentityClientId()\n\n const params = {\n grant_type: 'urn:ietf:params:oauth:grant-type:device_code',\n device_code: deviceCode,\n client_id: clientId,\n }\n\n const tokenResult = await tokenRequest(params)\n if (tokenResult.isErr()) {\n return err(tokenResult.error as IdentityDeviceError)\n }\n const identityToken = buildIdentityToken(tokenResult.value)\n return ok(identityToken)\n}\n\nasync function requestAppToken(\n api: API,\n token: string,\n scopes: string[] = [],\n store?: string,\n): Promise<{[x: string]: ApplicationToken}> {\n const appId = applicationId(api)\n const clientId = await getIdentityClientId()\n\n const params = {\n grant_type: 'urn:ietf:params:oauth:grant-type:token-exchange',\n requested_token_type: 'urn:ietf:params:oauth:token-type:access_token',\n subject_token_type: 'urn:ietf:params:oauth:token-type:access_token',\n client_id: clientId,\n audience: appId,\n scope: scopes.join(' '),\n subject_token: token,\n ...(api === 'admin' && {destination: `https://${store}/admin`}),\n }\n\n let identifier = appId\n if (api === 'admin' && store) {\n identifier = `${store}-${appId}`\n }\n const tokenResult = await tokenRequest(params)\n const value = tokenResult.mapError(tokenRequestErrorHandler).valueOrBug()\n const appToken = buildApplicationToken(value)\n return {[identifier]: appToken}\n}\n\ninterface TokenRequestResult {\n access_token: string\n expires_in: number\n refresh_token: string\n scope: string\n id_token?: string\n}\n\nfunction tokenRequestErrorHandler(error: string) {\n const invalidTargetErrorMessage =\n 'You are not authorized to use the CLI to develop in the provided store.' +\n '\\n\\n' +\n \"You can't use Shopify CLI with development stores if you only have Partner \" +\n 'staff member access. If you want to use Shopify CLI to work on a development store, then ' +\n 'you should be the store owner or create a staff account on the store.' +\n '\\n\\n' +\n \"If you're the store owner, then you need to log in to the store directly using the \" +\n 'store URL at least once before you log in using Shopify CLI.' +\n 'Logging in to the Shopify admin directly connects the development ' +\n 'store with your Shopify login.'\n if (error === 'invalid_grant') {\n // There's an scenario when Identity returns \"invalid_grant\" when trying to refresh the token\n // using a valid refresh token. When that happens, we take the user through the authentication flow.\n return new InvalidGrantError()\n }\n if (error === 'invalid_request') {\n // There's an scenario when Identity returns \"invalid_request\" when exchanging an identity token.\n // This means the token is invalid. We clear the session and throw an error to let the caller know.\n return new InvalidRequestError()\n }\n if (error === 'invalid_target') {\n return new InvalidTargetError(invalidTargetErrorMessage)\n }\n // eslint-disable-next-line @shopify/cli/no-error-factory-functions\n return new AbortError(error)\n}\n\nasync function tokenRequest(params: {[key: string]: string}): Promise<Result<TokenRequestResult, string>> {\n const fqdn = await identityFqdn()\n const url = new URL(`https://${fqdn}/oauth/token`)\n url.search = new URLSearchParams(Object.entries(params)).toString()\n\n const res = await shopifyFetch(url.href, {method: 'POST'})\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const payload: any = await res.json()\n\n if (res.ok) return ok(payload)\n return err(payload.error)\n}\n\nfunction buildIdentityToken(result: TokenRequestResult, existingUserId?: string): IdentityToken {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const userId = existingUserId ?? (result.id_token ? jose.decodeJwt(result.id_token).sub! : undefined)\n\n if (!userId) {\n throw new BugError('Error setting userId for session. No id_token or pre-existing user ID provided.')\n }\n\n return {\n accessToken: result.access_token,\n refreshToken: result.refresh_token,\n expiresAt: new Date(Date.now() + result.expires_in * 1000),\n scopes: result.scope.split(' '),\n userId,\n }\n}\n\nfunction buildApplicationToken(result: TokenRequestResult): ApplicationToken {\n return {\n accessToken: result.access_token,\n expiresAt: new Date(Date.now() + result.expires_in * 1000),\n scopes: result.scope.split(' '),\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"exchange.js","sourceRoot":"","sources":["../../../../src/private/node/session/exchange.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAE,QAAQ,IAAI,mBAAmB,EAAC,MAAM,eAAe,CAAA;AAC5E,OAAO,EAAC,mBAAmB,EAAC,MAAM,aAAa,CAAA;AAE/C,OAAO,EAAC,YAAY,EAAC,MAAM,sCAAsC,CAAA;AACjE,OAAO,EAAC,YAAY,EAAC,MAAM,8BAA8B,CAAA;AACzD,OAAO,EAAC,GAAG,EAAE,EAAE,EAAS,MAAM,gCAAgC,CAAA;AAC9D,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAE,eAAe,EAAC,MAAM,+BAA+B,CAAA;AACnF,OAAO,EAAC,qBAAqB,EAAE,0BAA0B,EAAC,MAAM,eAAe,CAAA;AAC/E,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,EAAC,aAAa,EAAC,MAAM,8BAA8B,CAAA;AAE1D,MAAM,OAAO,iBAAkB,SAAQ,eAAe;CAAG;AACzD,MAAM,OAAO,mBAAoB,SAAQ,eAAe;CAAG;AAC3D,MAAM,kBAAmB,SAAQ,UAAU;CAAG;AAU9C;;;;;GAKG;AACH,MAAM,CAAC,KAAK,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ACvD,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,YAAY;QAChC,SAAS,EAAE,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC;QAC1D,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC;KAChC,CAAA;AACH,CAAC","sourcesContent":["import {ApplicationToken, IdentityToken} from './schema.js'\nimport {applicationId, clientId as getIdentityClientId} from './identity.js'\nimport {tokenExchangeScopes} from './scopes.js'\nimport {API} from '../api.js'\nimport {identityFqdn} from '../../../public/node/context/fqdn.js'\nimport {shopifyFetch} from '../../../public/node/http.js'\nimport {err, ok, Result} from '../../../public/node/result.js'\nimport {AbortError, BugError, ExtendableError} from '../../../public/node/error.js'\nimport {setLastSeenAuthMethod, setLastSeenUserIdAfterAuth} from '../session.js'\nimport * as jose from 'jose'\nimport {nonRandomUUID} from '@shopify/cli-kit/node/crypto'\n\nexport class InvalidGrantError extends ExtendableError {}\nexport class InvalidRequestError extends ExtendableError {}\nclass InvalidTargetError extends AbortError {}\n\nexport interface ExchangeScopes {\n admin: string[]\n partners: string[]\n storefront: string[]\n businessPlatform: string[]\n appManagement: string[]\n}\n\n/**\n * Given an identity token, request an application token.\n * @param identityToken - access token obtained in a previous step\n * @param store - the store to use, only needed for admin API\n * @returns An array with the application access tokens.\n */\nexport async function exchangeAccessForApplicationTokens(\n identityToken: IdentityToken,\n scopes: ExchangeScopes,\n store?: string,\n): Promise<{[x: string]: ApplicationToken}> {\n const token = identityToken.accessToken\n\n const [partners, storefront, businessPlatform, admin, appManagement] = await Promise.all([\n requestAppToken('partners', token, scopes.partners),\n requestAppToken('storefront-renderer', token, scopes.storefront),\n requestAppToken('business-platform', token, scopes.businessPlatform),\n store ? requestAppToken('admin', token, scopes.admin, store) : {},\n requestAppToken('app-management', token, scopes.appManagement),\n ])\n\n return {\n ...partners,\n ...storefront,\n ...businessPlatform,\n ...admin,\n ...appManagement,\n }\n}\n\n/**\n * Given an expired access token, refresh it to get a new one.\n */\nexport async function refreshAccessToken(currentToken: IdentityToken): Promise<IdentityToken> {\n const clientId = getIdentityClientId()\n const params = {\n grant_type: 'refresh_token',\n access_token: currentToken.accessToken,\n refresh_token: currentToken.refreshToken,\n client_id: clientId,\n }\n const tokenResult = await tokenRequest(params)\n const value = tokenResult.mapError(tokenRequestErrorHandler).valueOrBug()\n return buildIdentityToken(value, currentToken.userId)\n}\n\n/**\n * Given a custom CLI token passed as ENV variable request a valid API access token\n * @param token - The CLI token passed as ENV variable `SHOPIFY_CLI_PARTNERS_TOKEN`\n * @param apiName - The API to exchange for the access token\n * @param scopes - The scopes to request with the access token\n * @returns An instance with the application access tokens.\n */\nasync function exchangeCliTokenForAccessToken(\n apiName: API,\n token: string,\n scopes: string[],\n): Promise<{accessToken: string; userId: string}> {\n const appId = applicationId(apiName)\n try {\n const newToken = await requestAppToken(apiName, token, scopes)\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const accessToken = newToken[appId]!.accessToken\n const userId = nonRandomUUID(token)\n setLastSeenUserIdAfterAuth(userId)\n setLastSeenAuthMethod('partners_token')\n return {accessToken, userId}\n } catch (error) {\n const prettyName = apiName.replace(/-/g, ' ').replace(/\\b\\w/g, (char) => char.toUpperCase())\n throw new AbortError(\n `The custom token provided can't be used for the ${prettyName} API.`,\n 'Ensure the token is correct and not expired.',\n )\n }\n}\n\n/**\n * Given a custom CLI token passed as ENV variable, request a valid Partners API token\n * This token does not accept extra scopes, just the cli one.\n * @param token - The CLI token passed as ENV variable `SHOPIFY_CLI_PARTNERS_TOKEN`\n * @returns An instance with the application access tokens.\n */\nexport async function exchangeCustomPartnerToken(token: string): Promise<{accessToken: string; userId: string}> {\n return exchangeCliTokenForAccessToken('partners', token, tokenExchangeScopes('partners'))\n}\n\n/**\n * Given a custom CLI token passed as ENV variable, request a valid App Management API token\n * @param token - The CLI token passed as ENV variable `SHOPIFY_CLI_PARTNERS_TOKEN`\n * @returns An instance with the application access tokens.\n */\nexport async function exchangeCliTokenForAppManagementAccessToken(\n token: string,\n): Promise<{accessToken: string; userId: string}> {\n return exchangeCliTokenForAccessToken('app-management', token, tokenExchangeScopes('app-management'))\n}\n\n/**\n * Given a custom CLI token passed as ENV variable, request a valid Business Platform API token\n * @param token - The CLI token passed as ENV variable `SHOPIFY_CLI_PARTNERS_TOKEN`\n * @returns An instance with the application access tokens.\n */\nexport async function exchangeCliTokenForBusinessPlatformAccessToken(\n token: string,\n): Promise<{accessToken: string; userId: string}> {\n return exchangeCliTokenForAccessToken('business-platform', token, tokenExchangeScopes('business-platform'))\n}\n\ntype IdentityDeviceError = 'authorization_pending' | 'access_denied' | 'expired_token' | 'slow_down' | 'unknown_failure'\n\n/**\n * Given a deviceCode obtained after starting a device identity flow, request an identity token.\n * @param deviceCode - The device code obtained after starting a device identity flow\n * @param scopes - The scopes to request\n * @returns An instance with the identity access tokens.\n */\nexport async function exchangeDeviceCodeForAccessToken(\n deviceCode: string,\n): Promise<Result<IdentityToken, IdentityDeviceError>> {\n const clientId = await getIdentityClientId()\n\n const params = {\n grant_type: 'urn:ietf:params:oauth:grant-type:device_code',\n device_code: deviceCode,\n client_id: clientId,\n }\n\n const tokenResult = await tokenRequest(params)\n if (tokenResult.isErr()) {\n return err(tokenResult.error.error as IdentityDeviceError)\n }\n const identityToken = buildIdentityToken(tokenResult.value)\n return ok(identityToken)\n}\n\nexport async function requestAppToken(\n api: API,\n token: string,\n scopes: string[] = [],\n store?: string,\n): Promise<{[x: string]: ApplicationToken}> {\n const appId = applicationId(api)\n const clientId = await getIdentityClientId()\n\n const params = {\n grant_type: 'urn:ietf:params:oauth:grant-type:token-exchange',\n requested_token_type: 'urn:ietf:params:oauth:token-type:access_token',\n subject_token_type: 'urn:ietf:params:oauth:token-type:access_token',\n client_id: clientId,\n audience: appId,\n scope: scopes.join(' '),\n subject_token: token,\n ...(api === 'admin' && {destination: `https://${store}/admin`, store}),\n }\n\n let identifier = appId\n if (api === 'admin' && store) {\n identifier = `${store}-${appId}`\n }\n const tokenResult = await tokenRequest(params)\n const value = tokenResult.mapError(tokenRequestErrorHandler).valueOrBug()\n const appToken = buildApplicationToken(value)\n return {[identifier]: appToken}\n}\n\ninterface TokenRequestResult {\n access_token: string\n expires_in: number\n refresh_token: string\n scope: string\n id_token?: string\n}\n\nfunction tokenRequestErrorHandler({error, store}: {error: string; store?: string}) {\n const invalidTargetErrorMessage =\n `You are not authorized to use the CLI to develop in the provided store${store ? `: ${store}` : '.'}` +\n '\\n\\n' +\n \"You can't use Shopify CLI with development stores if you only have Partner \" +\n 'staff member access. If you want to use Shopify CLI to work on a development store, then ' +\n 'you should be the store owner or create a staff account on the store.' +\n '\\n\\n' +\n \"If you're the store owner, then you need to log in to the store directly using the \" +\n 'store URL at least once before you log in using Shopify CLI. ' +\n 'Logging in to the Shopify admin directly connects the development ' +\n 'store with your Shopify login.'\n\n if (error === 'invalid_grant') {\n // There's an scenario when Identity returns \"invalid_grant\" when trying to refresh the token\n // using a valid refresh token. When that happens, we take the user through the authentication flow.\n return new InvalidGrantError()\n }\n if (error === 'invalid_request') {\n // There's an scenario when Identity returns \"invalid_request\" when exchanging an identity token.\n // This means the token is invalid. We clear the session and throw an error to let the caller know.\n return new InvalidRequestError()\n }\n if (error === 'invalid_target') {\n return new InvalidTargetError(invalidTargetErrorMessage)\n }\n // eslint-disable-next-line @shopify/cli/no-error-factory-functions\n return new AbortError(error)\n}\n\nasync function tokenRequest(params: {\n [key: string]: string\n}): Promise<Result<TokenRequestResult, {error: string; store?: string}>> {\n const fqdn = await identityFqdn()\n const url = new URL(`https://${fqdn}/oauth/token`)\n url.search = new URLSearchParams(Object.entries(params)).toString()\n\n const res = await shopifyFetch(url.href, {method: 'POST'})\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const payload: any = await res.json()\n\n if (res.ok) return ok(payload)\n\n return err({error: payload.error, store: params.store})\n}\n\nfunction buildIdentityToken(result: TokenRequestResult, existingUserId?: string): IdentityToken {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const userId = existingUserId ?? (result.id_token ? jose.decodeJwt(result.id_token).sub! : undefined)\n\n if (!userId) {\n throw new BugError('Error setting userId for session. No id_token or pre-existing user ID provided.')\n }\n\n return {\n accessToken: result.access_token,\n refreshToken: result.refresh_token,\n expiresAt: new Date(Date.now() + result.expires_in * 1000),\n scopes: result.scope.split(' '),\n userId,\n }\n}\n\nfunction buildApplicationToken(result: TokenRequestResult): ApplicationToken {\n return {\n accessToken: result.access_token,\n expiresAt: new Date(Date.now() + result.expires_in * 1000),\n scopes: result.scope.split(' '),\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const CLI_KIT_VERSION = "3.
|
|
1
|
+
export declare const CLI_KIT_VERSION = "3.80.1";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const CLI_KIT_VERSION = '3.
|
|
1
|
+
export const CLI_KIT_VERSION = '3.80.1';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/public/common/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAA","sourcesContent":["export const CLI_KIT_VERSION = '3.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/public/common/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAA","sourcesContent":["export const CLI_KIT_VERSION = '3.80.1'\n"]}
|
|
@@ -20,4 +20,43 @@ interface ZipOptions {
|
|
|
20
20
|
* @param options - ZipOptions.
|
|
21
21
|
*/
|
|
22
22
|
export declare function zip(options: ZipOptions): Promise<void>;
|
|
23
|
+
export interface BrotliOptions {
|
|
24
|
+
/**
|
|
25
|
+
* The directory to compress.
|
|
26
|
+
*/
|
|
27
|
+
inputDirectory: string;
|
|
28
|
+
/**
|
|
29
|
+
* The path where the compressed file will be saved.
|
|
30
|
+
*/
|
|
31
|
+
outputPath: string;
|
|
32
|
+
/**
|
|
33
|
+
* An optional glob pattern to match files.
|
|
34
|
+
*/
|
|
35
|
+
matchFilePattern?: string | string[];
|
|
36
|
+
/**
|
|
37
|
+
* Brotli compression level (0-11, default: 11).
|
|
38
|
+
*/
|
|
39
|
+
level?: number;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Options for decompressing a Brotli compressed tar archive.
|
|
43
|
+
*/
|
|
44
|
+
export interface DecompressionOptions {
|
|
45
|
+
/**
|
|
46
|
+
* Path to the compressed file.
|
|
47
|
+
*/
|
|
48
|
+
inputFile: string;
|
|
49
|
+
/**
|
|
50
|
+
* Directory where files should be extracted.
|
|
51
|
+
*/
|
|
52
|
+
outputDirectory: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* It compresses a directory with Brotli.
|
|
56
|
+
* First creates a tar archive to preserve directory structure,
|
|
57
|
+
* then compresses it with Brotli.
|
|
58
|
+
*
|
|
59
|
+
* @param options - BrotliOptions.
|
|
60
|
+
*/
|
|
61
|
+
export declare function brotliCompress(options: BrotliOptions): Promise<void>;
|
|
23
62
|
export {};
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { relativePath } from './path.js';
|
|
2
|
-
import { glob } from './fs.js';
|
|
2
|
+
import { glob, removeFile } from './fs.js';
|
|
3
3
|
import { outputDebug, outputContent, outputToken } from '../../public/node/output.js';
|
|
4
4
|
import archiver from 'archiver';
|
|
5
|
-
import
|
|
5
|
+
import brotli from 'brotli';
|
|
6
|
+
import { joinPath } from '@shopify/cli-kit/node/path';
|
|
7
|
+
import { createWriteStream, readFileSync, writeFileSync } from 'fs';
|
|
8
|
+
import { tmpdir } from 'os';
|
|
9
|
+
import { randomUUID } from 'crypto';
|
|
6
10
|
/**
|
|
7
11
|
* It zips a directory and by default normalizes the paths to be forward-slash.
|
|
8
12
|
* Even with forward-slash paths, zip files should still be able to be opened on
|
|
@@ -37,4 +41,57 @@ export async function zip(options) {
|
|
|
37
41
|
archive.finalize();
|
|
38
42
|
});
|
|
39
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* It compresses a directory with Brotli.
|
|
46
|
+
* First creates a tar archive to preserve directory structure,
|
|
47
|
+
* then compresses it with Brotli.
|
|
48
|
+
*
|
|
49
|
+
* @param options - BrotliOptions.
|
|
50
|
+
*/
|
|
51
|
+
export async function brotliCompress(options) {
|
|
52
|
+
const tempTarPath = joinPath(tmpdir(), `${randomUUID()}.tar`);
|
|
53
|
+
try {
|
|
54
|
+
// Create tar archive using archiver
|
|
55
|
+
await new Promise((resolve, reject) => {
|
|
56
|
+
const archive = archiver('tar');
|
|
57
|
+
const output = createWriteStream(tempTarPath);
|
|
58
|
+
output.on('close', () => resolve());
|
|
59
|
+
archive.on('error', (error) => reject(error));
|
|
60
|
+
archive.pipe(output);
|
|
61
|
+
glob(options.matchFilePattern ?? '**/*', {
|
|
62
|
+
cwd: options.inputDirectory,
|
|
63
|
+
absolute: true,
|
|
64
|
+
dot: true,
|
|
65
|
+
followSymbolicLinks: false,
|
|
66
|
+
})
|
|
67
|
+
.then((pathsToZip) => {
|
|
68
|
+
for (const filePath of pathsToZip) {
|
|
69
|
+
const fileRelativePath = relativePath(options.inputDirectory, filePath);
|
|
70
|
+
archive.file(filePath, { name: fileRelativePath });
|
|
71
|
+
}
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
73
|
+
archive.finalize();
|
|
74
|
+
})
|
|
75
|
+
.catch((error) => reject(error));
|
|
76
|
+
});
|
|
77
|
+
const tarContent = readFileSync(tempTarPath);
|
|
78
|
+
const compressed = brotli.compress(tarContent, {
|
|
79
|
+
quality: 7,
|
|
80
|
+
mode: 0,
|
|
81
|
+
});
|
|
82
|
+
if (!compressed) {
|
|
83
|
+
throw new Error('Brotli compression failed');
|
|
84
|
+
}
|
|
85
|
+
writeFileSync(options.outputPath, compressed);
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
try {
|
|
89
|
+
await removeFile(tempTarPath);
|
|
90
|
+
// eslint-disable-next-line no-catch-all/no-catch-all
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
outputDebug(outputContent `Failed to clean up temporary file: ${outputToken.path(tempTarPath)}`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
40
97
|
//# sourceMappingURL=archiver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"archiver.js","sourceRoot":"","sources":["../../../src/public/node/archiver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,WAAW,CAAA;AACtC,OAAO,EAAC,IAAI,EAAC,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"archiver.js","sourceRoot":"","sources":["../../../src/public/node/archiver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,WAAW,CAAA;AACtC,OAAO,EAAC,IAAI,EAAE,UAAU,EAAC,MAAM,SAAS,CAAA;AACxC,OAAO,EAAC,WAAW,EAAE,aAAa,EAAE,WAAW,EAAC,MAAM,6BAA6B,CAAA;AACnF,OAAO,QAAQ,MAAM,UAAU,CAAA;AAC/B,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAAC,QAAQ,EAAC,MAAM,4BAA4B,CAAA;AACnD,OAAO,EAAC,iBAAiB,EAAE,YAAY,EAAE,aAAa,EAAC,MAAM,IAAI,CAAA;AACjE,OAAO,EAAC,MAAM,EAAC,MAAM,IAAI,CAAA;AACzB,OAAO,EAAC,UAAU,EAAC,MAAM,QAAQ,CAAA;AAmBjC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,GAAG,CAAC,OAAmB;IAC3C,MAAM,EAAC,cAAc,EAAE,aAAa,EAAE,gBAAgB,GAAG,MAAM,EAAC,GAAG,OAAO,CAAA;IAC1E,WAAW,CAAC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EAAE,CAAC;SACR,CAAC,CAAA;QAEF,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;QAC9C,CAAC;QAED,aAAa,CAAC,OAAO,CAAC,UAAU,EAAE,UAAU,CAAC,CAAA;IAC/C,CAAC;YAAS,CAAC;QACT,IAAI,CAAC;YACH,MAAM,UAAU,CAAC,WAAW,CAAC,CAAA;YAC7B,qDAAqD;QACvD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,WAAW,CAAC,aAAa,CAAA,sCAAsC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;QACjG,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import {relativePath} from './path.js'\nimport {glob, removeFile} from './fs.js'\nimport {outputDebug, outputContent, outputToken} from '../../public/node/output.js'\nimport archiver from 'archiver'\nimport brotli from 'brotli'\nimport {joinPath} from '@shopify/cli-kit/node/path'\nimport {createWriteStream, readFileSync, writeFileSync} from 'fs'\nimport {tmpdir} from 'os'\nimport {randomUUID} from 'crypto'\n\ninterface ZipOptions {\n /**\n * The absolute path to the directory to be zipped.\n */\n inputDirectory: string\n\n /**\n * The absolute path to the output zip file.\n */\n outputZipPath: string\n\n /**\n * Pattern(s) to match when adding files to zip, uses glob expressions.\n */\n matchFilePattern?: string | string[]\n}\n\n/**\n * It zips a directory and by default normalizes the paths to be forward-slash.\n * Even with forward-slash paths, zip files should still be able to be opened on\n * Windows.\n *\n * @param options - ZipOptions.\n */\nexport async function zip(options: ZipOptions): Promise<void> {\n const {inputDirectory, outputZipPath, matchFilePattern = '**/*'} = options\n outputDebug(outputContent`Zipping ${outputToken.path(inputDirectory)} into ${outputToken.path(outputZipPath)}`)\n const pathsToZip = await glob(matchFilePattern, {\n cwd: inputDirectory,\n absolute: true,\n dot: true,\n followSymbolicLinks: false,\n })\n\n return new Promise((resolve, reject) => {\n const archive = archiver('zip')\n\n const output = createWriteStream(outputZipPath)\n output.on('close', () => {\n resolve()\n })\n archive.on('error', (error) => {\n reject(error)\n })\n archive.pipe(output)\n\n for (const filePath of pathsToZip) {\n const fileRelativePath = relativePath(inputDirectory, filePath)\n archive.file(filePath, {name: fileRelativePath})\n }\n\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n archive.finalize()\n })\n}\n\nexport interface BrotliOptions {\n /**\n * The directory to compress.\n */\n inputDirectory: string\n\n /**\n * The path where the compressed file will be saved.\n */\n outputPath: string\n\n /**\n * An optional glob pattern to match files.\n */\n matchFilePattern?: string | string[]\n\n /**\n * Brotli compression level (0-11, default: 11).\n */\n level?: number\n}\n\n/**\n * Options for decompressing a Brotli compressed tar archive.\n */\nexport interface DecompressionOptions {\n /**\n * Path to the compressed file.\n */\n inputFile: string\n\n /**\n * Directory where files should be extracted.\n */\n outputDirectory: string\n}\n\n/**\n * It compresses a directory with Brotli.\n * First creates a tar archive to preserve directory structure,\n * then compresses it with Brotli.\n *\n * @param options - BrotliOptions.\n */\nexport async function brotliCompress(options: BrotliOptions): Promise<void> {\n const tempTarPath = joinPath(tmpdir(), `${randomUUID()}.tar`)\n\n try {\n // Create tar archive using archiver\n await new Promise<void>((resolve, reject) => {\n const archive = archiver('tar')\n const output = createWriteStream(tempTarPath)\n\n output.on('close', () => resolve())\n archive.on('error', (error) => reject(error))\n archive.pipe(output)\n\n glob(options.matchFilePattern ?? '**/*', {\n cwd: options.inputDirectory,\n absolute: true,\n dot: true,\n followSymbolicLinks: false,\n })\n .then((pathsToZip) => {\n for (const filePath of pathsToZip) {\n const fileRelativePath = relativePath(options.inputDirectory, filePath)\n archive.file(filePath, {name: fileRelativePath})\n }\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n archive.finalize()\n })\n .catch((error) => reject(error))\n })\n\n const tarContent = readFileSync(tempTarPath)\n const compressed = brotli.compress(tarContent, {\n quality: 7,\n mode: 0,\n })\n\n if (!compressed) {\n throw new Error('Brotli compression failed')\n }\n\n writeFileSync(options.outputPath, compressed)\n } finally {\n try {\n await removeFile(tempTarPath)\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n outputDebug(outputContent`Failed to clean up temporary file: ${outputToken.path(tempTarPath)}`)\n }\n }\n}\n"]}
|
|
@@ -9,6 +9,12 @@ export declare const NotProvidedStoreFQDNError: AbortError;
|
|
|
9
9
|
* @returns Fully-qualified domain of the partners service we should interact with.
|
|
10
10
|
*/
|
|
11
11
|
export declare function partnersFqdn(): Promise<string>;
|
|
12
|
+
/**
|
|
13
|
+
* It returns the Admin service we should interact with.
|
|
14
|
+
*
|
|
15
|
+
* @returns Fully-qualified domain of the Admin service we should interact with.
|
|
16
|
+
*/
|
|
17
|
+
export declare function adminFqdn(): Promise<string>;
|
|
12
18
|
/**
|
|
13
19
|
* It returns the App Management API service we should interact with.
|
|
14
20
|
*
|
|
@@ -27,6 +27,23 @@ export async function partnersFqdn() {
|
|
|
27
27
|
return productionFqdn;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* It returns the Admin service we should interact with.
|
|
32
|
+
*
|
|
33
|
+
* @returns Fully-qualified domain of the Admin service we should interact with.
|
|
34
|
+
*/
|
|
35
|
+
export async function adminFqdn() {
|
|
36
|
+
const environment = serviceEnvironment();
|
|
37
|
+
const productionFqdn = 'admin.shopify.com';
|
|
38
|
+
switch (environment) {
|
|
39
|
+
case 'local':
|
|
40
|
+
return new DevServerCore().host('admin');
|
|
41
|
+
case 'spin':
|
|
42
|
+
return `admin.shopify.${await spinFqdn()}`;
|
|
43
|
+
default:
|
|
44
|
+
return productionFqdn;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
30
47
|
/**
|
|
31
48
|
* It returns the App Management API service we should interact with.
|
|
32
49
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fqdn.js","sourceRoot":"","sources":["../../../../src/public/node/context/fqdn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAA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'../error.js'\nimport {serviceEnvironment} from '../../../private/node/context/service.js'\nimport {DevServer, DevServerCore} from '../vendor/dev_server/index.js'\nimport {blockPartnersAccess} from '../environment.js'\n\nexport const CouldntObtainPartnersSpinFQDNError = new AbortError(\n \"Couldn't obtain the Spin FQDN for Partners when the CLI is not running from a Spin environment.\",\n)\nexport const CouldntObtainIdentitySpinFQDNError = new AbortError(\n \"Couldn't obtain the Spin FQDN for Identity when the CLI is not running from a Spin environment.\",\n)\nexport const CouldntObtainShopifySpinFQDNError = new AbortError(\n \"Couldn't obtain the Spin FQDN for Shopify when the CLI is not running from a Spin environment.\",\n)\nexport const NotProvidedStoreFQDNError = new AbortError(\n \"Couldn't obtain the Shopify FQDN because the store FQDN was not provided.\",\n)\n\n/**\n * It returns the Partners' API service we should interact with.\n *\n * @returns Fully-qualified domain of the partners service we should interact with.\n */\nexport async function partnersFqdn(): Promise<string> {\n if (blockPartnersAccess()) {\n throw new BugError('Partners API is blocked by the SHOPIFY_CLI_NEVER_USE_PARTNERS_API environment variable.')\n }\n const environment = serviceEnvironment()\n const productionFqdn = 'partners.shopify.com'\n switch (environment) {\n case 'local':\n return new DevServer('partners').host()\n case 'spin':\n return `partners.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the App Management API service we should interact with.\n *\n * @returns Fully-qualified domain of the App Management service we should interact with.\n */\nexport async function appManagementFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'app.shopify.com'\n switch (environment) {\n case 'local':\n return new DevServerCore().host('app')\n case 'spin':\n return `app.shopify.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the App Dev API service we should interact with.\n *\n * @param storeFqdn - The store FQDN.\n * @returns Fully-qualified domain of the App Dev service we should interact with.\n */\nexport async function appDevFqdn(storeFqdn: string): Promise<string> {\n const environment = serviceEnvironment()\n switch (environment) {\n case 'local':\n return new DevServerCore().host('app')\n default:\n return storeFqdn\n }\n}\n/**\n * It returns the Developer Dashboard domain we should interact with.\n *\n * @returns Fully-qualified domain of the Developer Dashboard we should interact with.\n */\nexport async function developerDashboardFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'dev.shopify.com'\n switch (environment) {\n case 'local':\n return new DevServerCore().host('dev')\n case 'spin':\n return `dev.shopify.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the BusinessPlatform' API service we should interact with.\n *\n * @returns Fully-qualified domain of the partners service we should interact with.\n */\nexport async function businessPlatformFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'destinations.shopifysvc.com'\n switch (environment) {\n case 'local':\n return new DevServer('business-platform').host()\n case 'spin':\n return `business-platform.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the Identity service we should interact with.\n *\n * @returns Fully-qualified domain of the Identity service we should interact with.\n */\nexport async function identityFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'accounts.shopify.com'\n switch (environment) {\n case 'local':\n return new DevServer('identity').host()\n case 'spin':\n return `identity.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * Normalize the store name to be used in the CLI.\n * It will add the .myshopify.com domain if it's not present.\n * It will add the spin domain if it's not present and we're in a Spin environment.\n *\n * @param store - Store name.\n * @returns Normalized store name.\n */\nexport async function normalizeStoreFqdn(store: string): Promise<string> {\n const storeFqdn = store.replace(/^https?:\\/\\//, '').replace(/\\/$/, '')\n const addDomain = async (storeFqdn: string) => {\n switch (serviceEnvironment()) {\n case 'local':\n return new DevServerCore().host(storeFqdn)\n case 'spin':\n return `${storeFqdn}.shopify.${await spinFqdn()}`\n default:\n return `${storeFqdn}.myshopify.com`\n }\n }\n const containDomain = (storeFqdn: string) =>\n storeFqdn.includes('.myshopify.com') ||\n storeFqdn.includes('spin.dev') ||\n storeFqdn.includes('shopify.io') ||\n storeFqdn.includes('.shop.dev')\n return containDomain(storeFqdn) ? storeFqdn : addDomain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AS,YAAY,MAAM,QAAQ,EAAE,EAAE,CAAA;YACnD;gBACE,OAAO,GAAG,SAAS,gBAAgB,CAAA;QACvC,CAAC;IACH,CAAC,CAAA;IACD,MAAM,aAAa,GAAG,CAAC,SAAiB,EAAE,EAAE,CAC1C,SAAS,CAAC,QAAQ,CAAC,gBAAgB,CAAC;QACpC,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC;QAC9B,SAAS,CAAC,QAAQ,CAAC,YAAY,CAAC;QAChC,SAAS,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAA;IACjC,OAAO,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;AACpE,CAAC","sourcesContent":["import {spinFqdn} from './spin.js'\nimport {AbortError, BugError} from '../error.js'\nimport {serviceEnvironment} from '../../../private/node/context/service.js'\nimport {DevServer, DevServerCore} from '../vendor/dev_server/index.js'\nimport {blockPartnersAccess} from '../environment.js'\n\nexport const CouldntObtainPartnersSpinFQDNError = new AbortError(\n \"Couldn't obtain the Spin FQDN for Partners when the CLI is not running from a Spin environment.\",\n)\nexport const CouldntObtainIdentitySpinFQDNError = new AbortError(\n \"Couldn't obtain the Spin FQDN for Identity when the CLI is not running from a Spin environment.\",\n)\nexport const CouldntObtainShopifySpinFQDNError = new AbortError(\n \"Couldn't obtain the Spin FQDN for Shopify when the CLI is not running from a Spin environment.\",\n)\nexport const NotProvidedStoreFQDNError = new AbortError(\n \"Couldn't obtain the Shopify FQDN because the store FQDN was not provided.\",\n)\n\n/**\n * It returns the Partners' API service we should interact with.\n *\n * @returns Fully-qualified domain of the partners service we should interact with.\n */\nexport async function partnersFqdn(): Promise<string> {\n if (blockPartnersAccess()) {\n throw new BugError('Partners API is blocked by the SHOPIFY_CLI_NEVER_USE_PARTNERS_API environment variable.')\n }\n const environment = serviceEnvironment()\n const productionFqdn = 'partners.shopify.com'\n switch (environment) {\n case 'local':\n return new DevServer('partners').host()\n case 'spin':\n return `partners.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the Admin service we should interact with.\n *\n * @returns Fully-qualified domain of the Admin service we should interact with.\n */\nexport async function adminFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'admin.shopify.com'\n switch (environment) {\n case 'local':\n return new DevServerCore().host('admin')\n case 'spin':\n return `admin.shopify.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the App Management API service we should interact with.\n *\n * @returns Fully-qualified domain of the App Management service we should interact with.\n */\nexport async function appManagementFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'app.shopify.com'\n switch (environment) {\n case 'local':\n return new DevServerCore().host('app')\n case 'spin':\n return `app.shopify.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the App Dev API service we should interact with.\n *\n * @param storeFqdn - The store FQDN.\n * @returns Fully-qualified domain of the App Dev service we should interact with.\n */\nexport async function appDevFqdn(storeFqdn: string): Promise<string> {\n const environment = serviceEnvironment()\n switch (environment) {\n case 'local':\n return new DevServerCore().host('app')\n default:\n return storeFqdn\n }\n}\n/**\n * It returns the Developer Dashboard domain we should interact with.\n *\n * @returns Fully-qualified domain of the Developer Dashboard we should interact with.\n */\nexport async function developerDashboardFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'dev.shopify.com'\n switch (environment) {\n case 'local':\n return new DevServerCore().host('dev')\n case 'spin':\n return `dev.shopify.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the BusinessPlatform' API service we should interact with.\n *\n * @returns Fully-qualified domain of the partners service we should interact with.\n */\nexport async function businessPlatformFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'destinations.shopifysvc.com'\n switch (environment) {\n case 'local':\n return new DevServer('business-platform').host()\n case 'spin':\n return `business-platform.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * It returns the Identity service we should interact with.\n *\n * @returns Fully-qualified domain of the Identity service we should interact with.\n */\nexport async function identityFqdn(): Promise<string> {\n const environment = serviceEnvironment()\n const productionFqdn = 'accounts.shopify.com'\n switch (environment) {\n case 'local':\n return new DevServer('identity').host()\n case 'spin':\n return `identity.${await spinFqdn()}`\n default:\n return productionFqdn\n }\n}\n\n/**\n * Normalize the store name to be used in the CLI.\n * It will add the .myshopify.com domain if it's not present.\n * It will add the spin domain if it's not present and we're in a Spin environment.\n *\n * @param store - Store name.\n * @returns Normalized store name.\n */\nexport async function normalizeStoreFqdn(store: string): Promise<string> {\n const storeFqdn = store.replace(/^https?:\\/\\//, '').replace(/\\/$/, '')\n const addDomain = async (storeFqdn: string) => {\n switch (serviceEnvironment()) {\n case 'local':\n return new DevServerCore().host(storeFqdn)\n case 'spin':\n return `${storeFqdn}.shopify.${await spinFqdn()}`\n default:\n return `${storeFqdn}.myshopify.com`\n }\n }\n const containDomain = (storeFqdn: string) =>\n storeFqdn.includes('.myshopify.com') ||\n storeFqdn.includes('spin.dev') ||\n storeFqdn.includes('shopify.io') ||\n storeFqdn.includes('.shop.dev')\n return containDomain(storeFqdn) ? storeFqdn : addDomain(storeFqdn)\n}\n"]}
|
package/dist/public/node/fs.d.ts
CHANGED
|
@@ -318,4 +318,10 @@ export interface MatchGlobOptions {
|
|
|
318
318
|
* @returns true if the key matches the pattern, false otherwise.
|
|
319
319
|
*/
|
|
320
320
|
export declare function matchGlob(key: string, pattern: string, options?: MatchGlobOptions): boolean;
|
|
321
|
+
/**
|
|
322
|
+
* Read a directory.
|
|
323
|
+
* @param path - The path to read.
|
|
324
|
+
* @returns A promise that resolves to an array of file names.
|
|
325
|
+
*/
|
|
326
|
+
export declare function readdir(path: string): Promise<string[]>;
|
|
321
327
|
export {};
|
package/dist/public/node/fs.js
CHANGED
|
@@ -10,7 +10,7 @@ import { sep, join } from 'pathe';
|
|
|
10
10
|
import { findUp as internalFindUp } from 'find-up';
|
|
11
11
|
import { minimatch } from 'minimatch';
|
|
12
12
|
import { mkdirSync as fsMkdirSync, readFileSync as fsReadFileSync, writeFileSync as fsWriteFileSync, appendFileSync as fsAppendFileSync, statSync as fsStatSync, createReadStream as fsCreateReadStream, createWriteStream as fsCreateWriteStream, constants as fsConstants, existsSync as fsFileExistsSync, unlinkSync as fsUnlinkSync, } from 'fs';
|
|
13
|
-
import { mkdir as fsMkdir, writeFile as fsWriteFile, readFile as fsReadFile, realpath as fsRealPath, appendFile as fsAppendFile, mkdtemp as fsMkdtemp, stat as fsStat, lstat as fsLstat, chmod as fsChmod, access as fsAccess, rename as fsRename, unlink as fsUnlink, } from 'fs/promises';
|
|
13
|
+
import { mkdir as fsMkdir, writeFile as fsWriteFile, readFile as fsReadFile, realpath as fsRealPath, appendFile as fsAppendFile, mkdtemp as fsMkdtemp, stat as fsStat, lstat as fsLstat, chmod as fsChmod, access as fsAccess, rename as fsRename, unlink as fsUnlink, readdir as fsReaddir, } from 'fs/promises';
|
|
14
14
|
import { pathToFileURL as pathToFile } from 'url';
|
|
15
15
|
import * as os from 'os';
|
|
16
16
|
/**
|
|
@@ -445,4 +445,12 @@ export async function findPathUp(matcher, options) {
|
|
|
445
445
|
export function matchGlob(key, pattern, options) {
|
|
446
446
|
return minimatch(key, pattern, options);
|
|
447
447
|
}
|
|
448
|
+
/**
|
|
449
|
+
* Read a directory.
|
|
450
|
+
* @param path - The path to read.
|
|
451
|
+
* @returns A promise that resolves to an array of file names.
|
|
452
|
+
*/
|
|
453
|
+
export function readdir(path) {
|
|
454
|
+
return fsReaddir(path);
|
|
455
|
+
}
|
|
448
456
|
//# sourceMappingURL=fs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../../../src/public/node/fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,aAAa,EAAC,MAAM,WAAW,CAAA;AACjD,OAAO,EAAC,aAAa,EAAE,WAAW,EAAE,W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A;AAClC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU;IACxB,OAAO,EAAE,CAAC,GAAU,CAAA;AACtB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,OAAqD,EACrD,OAAqD;IAErD,wBAAwB;IACxB,8DAA8D;IAC9D,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,OAAc,EAAE,OAAO,CAAC,CAAA;IACzD,OAAO,GAAG,CAAC,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AAC7C,CAAC;AAOD;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW,EAAE,OAAe,EAAE,OAA0B;IAChF,OAAO,SAAS,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;AACzC,CAAC","sourcesContent":["import {joinPath, normalizePath} from './path.js'\nimport {outputContent, outputToken, outputDebug} from '../../public/node/output.js'\nimport {getRandomName, RandomNameFamily} from '../common/string.js'\nimport {OverloadParameters} from '../../private/common/ts/overloaded-parameters.js'\nimport {\n copy as fsCopy,\n ensureFile as fsEnsureFile,\n ensureFileSync as fsEnsureFileSync,\n remove as fsRemove,\n removeSync as fsRemoveSync,\n move as fsMove,\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n} from 'fs-extra/esm'\n\nimport {temporaryDirectory, temporaryDirectoryTask} from 'tempy'\nimport {sep, join} from 'pathe'\nimport {findUp as internalFindUp} from 'find-up'\nimport {minimatch} from 'minimatch'\nimport {\n mkdirSync as fsMkdirSync,\n readFileSync as fsReadFileSync,\n writeFileSync as fsWriteFileSync,\n appendFileSync as fsAppendFileSync,\n statSync as fsStatSync,\n createReadStream as fsCreateReadStream,\n createWriteStream as fsCreateWriteStream,\n constants as fsConstants,\n existsSync as fsFileExistsSync,\n unlinkSync as fsUnlinkSync,\n ReadStream,\n WriteStream,\n} from 'fs'\nimport {\n mkdir as fsMkdir,\n writeFile as fsWriteFile,\n readFile as fsReadFile,\n realpath as fsRealPath,\n appendFile as fsAppendFile,\n mkdtemp as fsMkdtemp,\n stat as fsStat,\n lstat as fsLstat,\n chmod as fsChmod,\n access as fsAccess,\n rename as fsRename,\n unlink as fsUnlink,\n} from 'fs/promises'\nimport {pathToFileURL as pathToFile} from 'url'\nimport * as os from 'os'\nimport type {Pattern, Options as GlobOptions} from 'fast-glob'\n\n/**\n * Strip the first `strip` parts of the path.\n *\n * @param path - Path to strip.\n * @param strip - Number of parts to strip.\n * @returns The stripped path.\n */\nexport function stripUpPath(path: string, strip: number): string {\n const parts = path.split(sep)\n return join(...parts.slice(strip))\n}\n\n/**\n * Creates a temporary directory and ties its lifecycle to the lifecycle of the callback.\n *\n * @param callback - The callback that receives the temporary directory.\n */\nexport async function inTemporaryDirectory<T>(callback: (tmpDir: string) => T | Promise<T>): Promise<T> {\n return temporaryDirectoryTask(callback)\n}\n\n/**\n * Return a temporary directory\n * @returns - The path to the temporary directory.\n */\nexport function tempDirectory(): string {\n return temporaryDirectory()\n}\n\n/**\n * It reads a file and returns its content as a string using the\n * utf-8 encoding.\n *\n * @param path - Path to the file to read.\n * @returns A promise that resolves with the content of the file.\n */\n\nexport type ReadOptions =\n | undefined\n | {flag?: string | undefined}\n | {\n encoding: string\n flag?: string | undefined\n }\nexport async function readFile(path: string, options?: ReadOptions): Promise<string>\nexport async function readFile(path: string, options?: ReadOptions): Promise<Buffer>\n\n/**\n * It reads a file and returns its content as a string.\n * Uses utf-8 encoding by default.\n *\n * @param path - Path to the file to read.\n * @param options - Options to read the file with (defaults to utf-8 encoding).\n * @returns A promise that resolves with the content of the file.\n */\nexport async function readFile(path: string, options: ReadOptions = {encoding: 'utf8'}): Promise<string | Buffer> {\n outputDebug(outputContent`Reading the content of file at ${outputToken.path(path)}...`)\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return fsReadFile(path, options)\n}\n\n/**\n * Synchronously reads a file and returns its content as a buffer.\n *\n * @param path - Path to the file to read.\n * @returns The content of the file.\n */\nexport function readFileSync(path: string): Buffer {\n outputDebug(outputContent`Sync-reading the content of file at ${outputToken.path(path)}...`)\n return fsReadFileSync(path)\n}\n\n/**\n * Given a path, it determines the actual path. This is useful when working\n * with paths that represent symlinks.\n *\n * @param path - Path whose real path will be returned.\n */\nexport async function fileRealPath(path: string): Promise<string> {\n return fsRealPath(path)\n}\n\n/**\n * Copies a file.\n *\n * @param from - Path to the directory or file to be copied.\n * @param to - Destination path.\n */\nexport async function copyFile(from: string, to: string): Promise<void> {\n outputDebug(outputContent`Copying file from ${outputToken.path(from)} to ${outputToken.path(to)}...`)\n await fsCopy(from, to)\n}\n\n/**\n * Creates a file at the given path.\n *\n * @param path - Path to the file to be created.\n */\nexport async function touchFile(path: string): Promise<void> {\n outputDebug(outputContent`Creating an empty file at ${outputToken.path(path)}...`)\n await fsEnsureFile(path)\n}\n\n/**\n * Synchronously creates a file at the given path.\n *\n * @param path - Path to the file to be created.\n */\nexport function touchFileSync(path: string): void {\n outputDebug(outputContent`Creating an empty file at ${outputToken.path(path)}...`)\n fsEnsureFileSync(path)\n}\n\n/**\n * Appnds content to file at path.\n *\n * @param path - Path to the file to be appended.\n * @param content - Content to be appended.\n */\nexport async function appendFile(path: string, content: string): Promise<void> {\n outputDebug(outputContent`Appending the following content to ${outputToken.path(path)}:\n ${content\n .split('\\n')\n .map((line) => ` ${line}`)\n .join('\\n')}\n `)\n await fsAppendFile(path, content)\n}\n\n/**\n * Synchronously appends content to file at path.\n *\n * @param path - Path to the file to be appended.\n * @param data - Content to be appended.\n */\nexport function appendFileSync(path: string, data: string): void {\n fsAppendFileSync(path, data)\n}\n\nexport interface WriteOptions {\n encoding: BufferEncoding\n}\n\n/**\n * Writes content to file at path.\n *\n * @param path - Path to the file to be written.\n * @param data - Content to be written.\n * @param options - Options to write the file with (defaults to utf-8 encoding).\n */\nexport async function writeFile(\n path: string,\n data: string | Buffer,\n options: WriteOptions = {encoding: 'utf8'},\n): Promise<void> {\n outputDebug(outputContent`Writing some content to file at ${outputToken.path(path)}...`)\n await fsWriteFile(path, data, options)\n}\n\n/**\n * Synchronously writes content to file at path.\n *\n * @param path - Path to the file to be written.\n * @param data - Content to be written.\n */\nexport function writeFileSync(path: string, data: string): void {\n outputDebug(outputContent`File-writing some content to file at ${outputToken.path(path)}...`)\n fsWriteFileSync(path, data)\n}\n\n/**\n * Creates a directory at the given path.\n *\n * @param path - Path to the directory to be created.\n */\nexport async function mkdir(path: string): Promise<void> {\n outputDebug(outputContent`Creating directory at ${outputToken.path(path)}...`)\n await fsMkdir(path, {recursive: true})\n}\n\n/**\n * Synchronously creates a directory at the given path.\n *\n * @param path - Path to the directory to be created.\n */\nexport function mkdirSync(path: string): void {\n outputDebug(outputContent`Sync-creating directory at ${outputToken.path(path)}...`)\n fsMkdirSync(path, {recursive: true})\n}\n\n/**\n * Removes a file at the given path.\n *\n * @param path - Path to the file to be removed.\n */\nexport async function removeFile(path: string): Promise<void> {\n outputDebug(outputContent`Removing file at ${outputToken.path(path)}...`)\n await fsRemove(path)\n}\n\n/**\n * Renames a file.\n * @param from - Path to the file to be renamed.\n * @param to - New path for the file.\n */\nexport async function renameFile(from: string, to: string): Promise<void> {\n outputDebug(outputContent`Renaming file from ${outputToken.path(from)} to ${outputToken.path(to)}...`)\n await fsRename(from, to)\n}\n\n/**\n * Synchronously removes a file at the given path.\n *\n * @param path - Path to the file to be removed.\n */\nexport function removeFileSync(path: string): void {\n outputDebug(outputContent`Sync-removing file at ${outputToken.path(path)}...`)\n fsRemoveSync(path)\n}\n\ninterface RmDirOptions {\n force?: boolean\n}\n/**\n * Removes a directory at the given path.\n *\n * @param path - Path to the directory to be removed.\n * @param options - Options to remove the directory with.\n */\nexport async function rmdir(path: string, options: RmDirOptions = {}): Promise<void> {\n const {default: del} = await import('del')\n outputDebug(outputContent`Removing directory at ${outputToken.path(path)}...`)\n await del(path, {force: options.force})\n}\n\n/**\n * Create a temporary directory within the OS provided location for temp directories\n *\n * @returns Path to the temporary directory.\n */\nexport async function mkTmpDir(): Promise<string> {\n outputDebug(outputContent`Creating a temporary directory...`)\n const directory = await fsMkdtemp(joinPath(os.tmpdir(), 'tmp-'))\n return directory\n}\n\n/**\n * Check whether a path is a directory.\n *\n * @param path - Path to check.\n * @returns True if the path is a directory, false otherwise.\n */\nexport async function isDirectory(path: string): Promise<boolean> {\n outputDebug(outputContent`Checking if ${outputToken.path(path)} is a directory...`)\n return (await fsLstat(path)).isDirectory()\n}\n\n/**\n * Get the size of a file.\n *\n * @param path - Path to the file.\n * @returns The size of the file in bytes.\n */\nexport async function fileSize(path: string): Promise<number> {\n outputDebug(outputContent`Getting the size of file file at ${outputToken.path(path)}...`)\n return (await fsStat(path)).size\n}\n\n/**\n * Synchronously get the size of a file.\n *\n * @param path - Path to the file.\n * @returns The size of the file in bytes.\n */\nexport function fileSizeSync(path: string): number {\n outputDebug(outputContent`Sync-getting the size of file file at ${outputToken.path(path)}...`)\n return fsStatSync(path).size\n}\n\n/**\n * Synchronously unlink a file at the given path.\n *\n * @param path - Path to the file.\n */\nexport function unlinkFileSync(path: string): void {\n fsUnlinkSync(path)\n}\n\n/**\n * Unlink a file at the given path.\n *\n * @param path - Path to the file.\n * @returns A promise that resolves when the file is unlinked.\n */\nexport function unlinkFile(path: string): Promise<void> {\n return fsUnlink(path)\n}\n\n/**\n * Create a read stream for a file with optional options.\n *\n * @param path - Path to the file.\n * @param options - Options for the read stream.\n * @returns A read stream for the file.\n */\nexport function createFileReadStream(\n path: string,\n options?: {encoding?: BufferEncoding; start?: number; end?: number},\n): ReadStream {\n return fsCreateReadStream(path, options)\n}\n\n/**\n * Create a write stream for a file.\n *\n * @param path - Path to the file.\n * @returns A write stream for the file.\n */\nexport function createFileWriteStream(path: string): WriteStream {\n return fsCreateWriteStream(path)\n}\n\n/**\n * Returns the Date object for the last modification of a file.\n *\n * @param path - Path to the directory or file.\n * @returns A unix timestamp.\n */\nexport async function fileLastUpdated(path: string): Promise<Date> {\n outputDebug(outputContent`Getting last updated timestamp for file at ${outputToken.path(path)}...`)\n return (await fsStat(path)).ctime\n}\n\n/**\n * Returns the unix timestamp of the last modification of a file.\n *\n * @param path - Path to the directory or file.\n * @returns A unix timestamp.\n */\nexport async function fileLastUpdatedTimestamp(path: string): Promise<number | undefined> {\n try {\n const lastUpdatedDateTime = await fileLastUpdated(path)\n return lastUpdatedDateTime.getTime()\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch {\n return undefined\n }\n}\n\ninterface MoveFileOptions {\n overwrite?: boolean\n}\n\n/**\n * Moves a file.\n *\n * @param src - File to be moved.\n * @param dest - Path to be moved to.\n * @param options - Moving options.\n */\nexport async function moveFile(src: string, dest: string, options: MoveFileOptions = {}): Promise<void> {\n await fsMove(src, dest, options)\n}\n\n/**\n * Changes the permissions of a directory or file.\n *\n * @param path - Path to the file or directory whose permissions will be modified.\n * @param mode - Permissions to set to the file or directory.\n */\nexport async function chmod(path: string, mode: number | string): Promise<void> {\n await fsChmod(path, mode)\n}\n\n/**\n * Checks if a file has executable permissions.\n *\n * @param path - Path to the file whose permissions will be checked.\n */\nexport async function fileHasExecutablePermissions(path: string): Promise<boolean> {\n try {\n await fsAccess(path, fsConstants.X_OK)\n return true\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch {\n return false\n }\n}\n\n/**\n * Returns true if a file or directory exists.\n *\n * @param path - Path to the directory or file.\n * @returns True if it exists.\n */\nexport async function fileExists(path: string): Promise<boolean> {\n try {\n await fsAccess(path)\n return true\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch {\n return false\n }\n}\n\nexport function fileExistsSync(path: string): boolean {\n return fsFileExistsSync(path)\n}\n\ninterface GenerateRandomDirectoryOptions {\n /** Suffix to include in the randomly generated directory name. */\n suffix: string\n\n /** Absolute path to the directory where the random directory will be created. */\n directory: string\n\n /** Type of word to use for random name. */\n family?: RandomNameFamily\n}\n\n/**\n * It generates a random directory directory name for a sub-directory.\n * It ensures that the returned directory name doesn't exist.\n *\n * @param options - Options to generate the random directory name.\n * @returns It returns the name of the directory.\n */\nexport async function generateRandomNameForSubdirectory(options: GenerateRandomDirectoryOptions): Promise<string> {\n const generated = `${getRandomName(options.family ?? 'business')}-${options.suffix}`\n const randomDirectoryPath = joinPath(options.directory, generated)\n const isAppDirectoryTaken = await fileExists(randomDirectoryPath)\n\n if (isAppDirectoryTaken) {\n return generateRandomNameForSubdirectory(options)\n } else {\n return generated\n }\n}\n\n/**\n * Traverse the file system and return pathnames that match the given pattern.\n *\n * @param pattern - A glob pattern or an array of glob patterns.\n * @param options - Options for the glob.\n * @returns A promise that resolves to an array of pathnames that match the given pattern.\n */\nexport async function glob(pattern: Pattern | Pattern[], options?: GlobOptions): Promise<string[]> {\n const {default: fastGlob} = await import('fast-glob')\n let overridenOptions = options\n if (options?.dot == null) {\n overridenOptions = {...options, dot: true}\n }\n return fastGlob(pattern, overridenOptions)\n}\n\n/**\n * Convert a path to a File URL.\n *\n * @param path - Path to convert.\n * @returns The File URL.\n */\nexport function pathToFileURL(path: string): URL {\n return pathToFile(path)\n}\n\n/**\n * The operating system-specific end-of-line marker:\n * - `\\n` on POSIX\n * - `\\r\\n` on Windows\n */\nexport type EOL = '\\r\\n' | '\\n'\n\n/**\n * Detects the end-of-line marker used in a string.\n *\n * @param content - file contents to analyze\n *\n * @returns The detected end-of-line marker\n */\nexport function detectEOL(content: string): EOL {\n const match = content.match(/\\r\\n|\\n/g)\n\n if (!match) {\n return defaultEOL()\n }\n\n const crlf = match.filter((eol) => eol === '\\r\\n').length\n const lf = match.filter((eol) => eol === '\\n').length\n\n return crlf > lf ? '\\r\\n' : '\\n'\n}\n\n/**\n * Returns the operating system's end-of-line marker.\n *\n * @returns The OS-specific end-of-line marker\n */\nexport function defaultEOL(): EOL {\n return os.EOL as EOL\n}\n\n/**\n * Find a file by walking parent directories.\n *\n * @param matcher - A pattern or an array of patterns to match a file name.\n * @param options - Options for the search.\n * @returns The first path found that matches or `undefined` if none could be found.\n */\nexport async function findPathUp(\n matcher: OverloadParameters<typeof internalFindUp>[0],\n options: OverloadParameters<typeof internalFindUp>[1],\n): ReturnType<typeof internalFindUp> {\n // findUp has odd typing\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const got = await internalFindUp(matcher as any, options)\n return got ? normalizePath(got) : undefined\n}\n\nexport interface MatchGlobOptions {\n matchBase: boolean\n noglobstar: boolean\n}\n\n/**\n * Matches a key against a glob pattern.\n * @param key - The key to match.\n * @param pattern - The glob pattern to match against.\n * @param options - The options to refine the matching approach.\n * @returns true if the key matches the pattern, false otherwise.\n */\nexport function matchGlob(key: string, pattern: string, options?: MatchGlobOptions): boolean {\n return minimatch(key, pattern, options)\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../../../src/public/node/fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,aAAa,EAAC,MAAM,WAAW,CAAA;AACjD,OAAO,EAAC,aAAa,EAAE,WAAW,EAAE,WAAW,EAAC,MAAM,6BAA6B,CAAA;AACnF,OAAO,EAAC,aAAa,EAAmB,MAAM,qBAAqB,CAAA;AAEnE,OAAO,EACL,IAAI,IAAI,MAAM,EACd,UAAU,IAAI,YAAY,EAC1B,cAAc,IAAI,gBAAgB,EAClC,MAAM,IAAI,QAAQ,EAClB,UAAU,IAAI,YAAY,EAC1B,IAAI,IAAI,MAAM;AACd,6DAA6D;AAC7D,aAAa;EACd,MAAM,cAAc,CAAA;AAErB,OAAO,EAAC,kBAAkB,EAAE,sBAAsB,EAAC,MAAM,OAAO,CAAA;AAChE,OAAO,EAAC,GAAG,EAAE,IAAI,EAAC,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAC,MAAM,IAAI,cAAc,EAAC,MAAM,SAAS,CAAA;AAChD,OAAO,EAAC,SAAS,EAAC,MAAM,WAAW,CAAA;AACnC,OAAO,EACL,SAAS,IAAI,WAAW,EACxB,YAAY,IAAI,cAAc,EA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,UAAU,OAAO,CAAC,IAAY;IAClC,OAAO,SAAS,CAAC,IAAI,CAAC,CAAA;AACxB,CAAC","sourcesContent":["import {joinPath, normalizePath} from './path.js'\nimport {outputContent, outputToken, outputDebug} from '../../public/node/output.js'\nimport {getRandomName, RandomNameFamily} from '../common/string.js'\nimport {OverloadParameters} from '../../private/common/ts/overloaded-parameters.js'\nimport {\n copy as fsCopy,\n ensureFile as fsEnsureFile,\n ensureFileSync as fsEnsureFileSync,\n remove as fsRemove,\n removeSync as fsRemoveSync,\n move as fsMove,\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n} from 'fs-extra/esm'\n\nimport {temporaryDirectory, temporaryDirectoryTask} from 'tempy'\nimport {sep, join} from 'pathe'\nimport {findUp as internalFindUp} from 'find-up'\nimport {minimatch} from 'minimatch'\nimport {\n mkdirSync as fsMkdirSync,\n readFileSync as fsReadFileSync,\n writeFileSync as fsWriteFileSync,\n appendFileSync as fsAppendFileSync,\n statSync as fsStatSync,\n createReadStream as fsCreateReadStream,\n createWriteStream as fsCreateWriteStream,\n constants as fsConstants,\n existsSync as fsFileExistsSync,\n unlinkSync as fsUnlinkSync,\n ReadStream,\n WriteStream,\n} from 'fs'\nimport {\n mkdir as fsMkdir,\n writeFile as fsWriteFile,\n readFile as fsReadFile,\n realpath as fsRealPath,\n appendFile as fsAppendFile,\n mkdtemp as fsMkdtemp,\n stat as fsStat,\n lstat as fsLstat,\n chmod as fsChmod,\n access as fsAccess,\n rename as fsRename,\n unlink as fsUnlink,\n readdir as fsReaddir,\n} from 'fs/promises'\nimport {pathToFileURL as pathToFile} from 'url'\nimport * as os from 'os'\nimport type {Pattern, Options as GlobOptions} from 'fast-glob'\n\n/**\n * Strip the first `strip` parts of the path.\n *\n * @param path - Path to strip.\n * @param strip - Number of parts to strip.\n * @returns The stripped path.\n */\nexport function stripUpPath(path: string, strip: number): string {\n const parts = path.split(sep)\n return join(...parts.slice(strip))\n}\n\n/**\n * Creates a temporary directory and ties its lifecycle to the lifecycle of the callback.\n *\n * @param callback - The callback that receives the temporary directory.\n */\nexport async function inTemporaryDirectory<T>(callback: (tmpDir: string) => T | Promise<T>): Promise<T> {\n return temporaryDirectoryTask(callback)\n}\n\n/**\n * Return a temporary directory\n * @returns - The path to the temporary directory.\n */\nexport function tempDirectory(): string {\n return temporaryDirectory()\n}\n\n/**\n * It reads a file and returns its content as a string using the\n * utf-8 encoding.\n *\n * @param path - Path to the file to read.\n * @returns A promise that resolves with the content of the file.\n */\n\nexport type ReadOptions =\n | undefined\n | {flag?: string | undefined}\n | {\n encoding: string\n flag?: string | undefined\n }\nexport async function readFile(path: string, options?: ReadOptions): Promise<string>\nexport async function readFile(path: string, options?: ReadOptions): Promise<Buffer>\n\n/**\n * It reads a file and returns its content as a string.\n * Uses utf-8 encoding by default.\n *\n * @param path - Path to the file to read.\n * @param options - Options to read the file with (defaults to utf-8 encoding).\n * @returns A promise that resolves with the content of the file.\n */\nexport async function readFile(path: string, options: ReadOptions = {encoding: 'utf8'}): Promise<string | Buffer> {\n outputDebug(outputContent`Reading the content of file at ${outputToken.path(path)}...`)\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n return fsReadFile(path, options)\n}\n\n/**\n * Synchronously reads a file and returns its content as a buffer.\n *\n * @param path - Path to the file to read.\n * @returns The content of the file.\n */\nexport function readFileSync(path: string): Buffer {\n outputDebug(outputContent`Sync-reading the content of file at ${outputToken.path(path)}...`)\n return fsReadFileSync(path)\n}\n\n/**\n * Given a path, it determines the actual path. This is useful when working\n * with paths that represent symlinks.\n *\n * @param path - Path whose real path will be returned.\n */\nexport async function fileRealPath(path: string): Promise<string> {\n return fsRealPath(path)\n}\n\n/**\n * Copies a file.\n *\n * @param from - Path to the directory or file to be copied.\n * @param to - Destination path.\n */\nexport async function copyFile(from: string, to: string): Promise<void> {\n outputDebug(outputContent`Copying file from ${outputToken.path(from)} to ${outputToken.path(to)}...`)\n await fsCopy(from, to)\n}\n\n/**\n * Creates a file at the given path.\n *\n * @param path - Path to the file to be created.\n */\nexport async function touchFile(path: string): Promise<void> {\n outputDebug(outputContent`Creating an empty file at ${outputToken.path(path)}...`)\n await fsEnsureFile(path)\n}\n\n/**\n * Synchronously creates a file at the given path.\n *\n * @param path - Path to the file to be created.\n */\nexport function touchFileSync(path: string): void {\n outputDebug(outputContent`Creating an empty file at ${outputToken.path(path)}...`)\n fsEnsureFileSync(path)\n}\n\n/**\n * Appnds content to file at path.\n *\n * @param path - Path to the file to be appended.\n * @param content - Content to be appended.\n */\nexport async function appendFile(path: string, content: string): Promise<void> {\n outputDebug(outputContent`Appending the following content to ${outputToken.path(path)}:\n ${content\n .split('\\n')\n .map((line) => ` ${line}`)\n .join('\\n')}\n `)\n await fsAppendFile(path, content)\n}\n\n/**\n * Synchronously appends content to file at path.\n *\n * @param path - Path to the file to be appended.\n * @param data - Content to be appended.\n */\nexport function appendFileSync(path: string, data: string): void {\n fsAppendFileSync(path, data)\n}\n\nexport interface WriteOptions {\n encoding: BufferEncoding\n}\n\n/**\n * Writes content to file at path.\n *\n * @param path - Path to the file to be written.\n * @param data - Content to be written.\n * @param options - Options to write the file with (defaults to utf-8 encoding).\n */\nexport async function writeFile(\n path: string,\n data: string | Buffer,\n options: WriteOptions = {encoding: 'utf8'},\n): Promise<void> {\n outputDebug(outputContent`Writing some content to file at ${outputToken.path(path)}...`)\n await fsWriteFile(path, data, options)\n}\n\n/**\n * Synchronously writes content to file at path.\n *\n * @param path - Path to the file to be written.\n * @param data - Content to be written.\n */\nexport function writeFileSync(path: string, data: string): void {\n outputDebug(outputContent`File-writing some content to file at ${outputToken.path(path)}...`)\n fsWriteFileSync(path, data)\n}\n\n/**\n * Creates a directory at the given path.\n *\n * @param path - Path to the directory to be created.\n */\nexport async function mkdir(path: string): Promise<void> {\n outputDebug(outputContent`Creating directory at ${outputToken.path(path)}...`)\n await fsMkdir(path, {recursive: true})\n}\n\n/**\n * Synchronously creates a directory at the given path.\n *\n * @param path - Path to the directory to be created.\n */\nexport function mkdirSync(path: string): void {\n outputDebug(outputContent`Sync-creating directory at ${outputToken.path(path)}...`)\n fsMkdirSync(path, {recursive: true})\n}\n\n/**\n * Removes a file at the given path.\n *\n * @param path - Path to the file to be removed.\n */\nexport async function removeFile(path: string): Promise<void> {\n outputDebug(outputContent`Removing file at ${outputToken.path(path)}...`)\n await fsRemove(path)\n}\n\n/**\n * Renames a file.\n * @param from - Path to the file to be renamed.\n * @param to - New path for the file.\n */\nexport async function renameFile(from: string, to: string): Promise<void> {\n outputDebug(outputContent`Renaming file from ${outputToken.path(from)} to ${outputToken.path(to)}...`)\n await fsRename(from, to)\n}\n\n/**\n * Synchronously removes a file at the given path.\n *\n * @param path - Path to the file to be removed.\n */\nexport function removeFileSync(path: string): void {\n outputDebug(outputContent`Sync-removing file at ${outputToken.path(path)}...`)\n fsRemoveSync(path)\n}\n\ninterface RmDirOptions {\n force?: boolean\n}\n/**\n * Removes a directory at the given path.\n *\n * @param path - Path to the directory to be removed.\n * @param options - Options to remove the directory with.\n */\nexport async function rmdir(path: string, options: RmDirOptions = {}): Promise<void> {\n const {default: del} = await import('del')\n outputDebug(outputContent`Removing directory at ${outputToken.path(path)}...`)\n await del(path, {force: options.force})\n}\n\n/**\n * Create a temporary directory within the OS provided location for temp directories\n *\n * @returns Path to the temporary directory.\n */\nexport async function mkTmpDir(): Promise<string> {\n outputDebug(outputContent`Creating a temporary directory...`)\n const directory = await fsMkdtemp(joinPath(os.tmpdir(), 'tmp-'))\n return directory\n}\n\n/**\n * Check whether a path is a directory.\n *\n * @param path - Path to check.\n * @returns True if the path is a directory, false otherwise.\n */\nexport async function isDirectory(path: string): Promise<boolean> {\n outputDebug(outputContent`Checking if ${outputToken.path(path)} is a directory...`)\n return (await fsLstat(path)).isDirectory()\n}\n\n/**\n * Get the size of a file.\n *\n * @param path - Path to the file.\n * @returns The size of the file in bytes.\n */\nexport async function fileSize(path: string): Promise<number> {\n outputDebug(outputContent`Getting the size of file file at ${outputToken.path(path)}...`)\n return (await fsStat(path)).size\n}\n\n/**\n * Synchronously get the size of a file.\n *\n * @param path - Path to the file.\n * @returns The size of the file in bytes.\n */\nexport function fileSizeSync(path: string): number {\n outputDebug(outputContent`Sync-getting the size of file file at ${outputToken.path(path)}...`)\n return fsStatSync(path).size\n}\n\n/**\n * Synchronously unlink a file at the given path.\n *\n * @param path - Path to the file.\n */\nexport function unlinkFileSync(path: string): void {\n fsUnlinkSync(path)\n}\n\n/**\n * Unlink a file at the given path.\n *\n * @param path - Path to the file.\n * @returns A promise that resolves when the file is unlinked.\n */\nexport function unlinkFile(path: string): Promise<void> {\n return fsUnlink(path)\n}\n\n/**\n * Create a read stream for a file with optional options.\n *\n * @param path - Path to the file.\n * @param options - Options for the read stream.\n * @returns A read stream for the file.\n */\nexport function createFileReadStream(\n path: string,\n options?: {encoding?: BufferEncoding; start?: number; end?: number},\n): ReadStream {\n return fsCreateReadStream(path, options)\n}\n\n/**\n * Create a write stream for a file.\n *\n * @param path - Path to the file.\n * @returns A write stream for the file.\n */\nexport function createFileWriteStream(path: string): WriteStream {\n return fsCreateWriteStream(path)\n}\n\n/**\n * Returns the Date object for the last modification of a file.\n *\n * @param path - Path to the directory or file.\n * @returns A unix timestamp.\n */\nexport async function fileLastUpdated(path: string): Promise<Date> {\n outputDebug(outputContent`Getting last updated timestamp for file at ${outputToken.path(path)}...`)\n return (await fsStat(path)).ctime\n}\n\n/**\n * Returns the unix timestamp of the last modification of a file.\n *\n * @param path - Path to the directory or file.\n * @returns A unix timestamp.\n */\nexport async function fileLastUpdatedTimestamp(path: string): Promise<number | undefined> {\n try {\n const lastUpdatedDateTime = await fileLastUpdated(path)\n return lastUpdatedDateTime.getTime()\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch {\n return undefined\n }\n}\n\ninterface MoveFileOptions {\n overwrite?: boolean\n}\n\n/**\n * Moves a file.\n *\n * @param src - File to be moved.\n * @param dest - Path to be moved to.\n * @param options - Moving options.\n */\nexport async function moveFile(src: string, dest: string, options: MoveFileOptions = {}): Promise<void> {\n await fsMove(src, dest, options)\n}\n\n/**\n * Changes the permissions of a directory or file.\n *\n * @param path - Path to the file or directory whose permissions will be modified.\n * @param mode - Permissions to set to the file or directory.\n */\nexport async function chmod(path: string, mode: number | string): Promise<void> {\n await fsChmod(path, mode)\n}\n\n/**\n * Checks if a file has executable permissions.\n *\n * @param path - Path to the file whose permissions will be checked.\n */\nexport async function fileHasExecutablePermissions(path: string): Promise<boolean> {\n try {\n await fsAccess(path, fsConstants.X_OK)\n return true\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch {\n return false\n }\n}\n\n/**\n * Returns true if a file or directory exists.\n *\n * @param path - Path to the directory or file.\n * @returns True if it exists.\n */\nexport async function fileExists(path: string): Promise<boolean> {\n try {\n await fsAccess(path)\n return true\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch {\n return false\n }\n}\n\nexport function fileExistsSync(path: string): boolean {\n return fsFileExistsSync(path)\n}\n\ninterface GenerateRandomDirectoryOptions {\n /** Suffix to include in the randomly generated directory name. */\n suffix: string\n\n /** Absolute path to the directory where the random directory will be created. */\n directory: string\n\n /** Type of word to use for random name. */\n family?: RandomNameFamily\n}\n\n/**\n * It generates a random directory directory name for a sub-directory.\n * It ensures that the returned directory name doesn't exist.\n *\n * @param options - Options to generate the random directory name.\n * @returns It returns the name of the directory.\n */\nexport async function generateRandomNameForSubdirectory(options: GenerateRandomDirectoryOptions): Promise<string> {\n const generated = `${getRandomName(options.family ?? 'business')}-${options.suffix}`\n const randomDirectoryPath = joinPath(options.directory, generated)\n const isAppDirectoryTaken = await fileExists(randomDirectoryPath)\n\n if (isAppDirectoryTaken) {\n return generateRandomNameForSubdirectory(options)\n } else {\n return generated\n }\n}\n\n/**\n * Traverse the file system and return pathnames that match the given pattern.\n *\n * @param pattern - A glob pattern or an array of glob patterns.\n * @param options - Options for the glob.\n * @returns A promise that resolves to an array of pathnames that match the given pattern.\n */\nexport async function glob(pattern: Pattern | Pattern[], options?: GlobOptions): Promise<string[]> {\n const {default: fastGlob} = await import('fast-glob')\n let overridenOptions = options\n if (options?.dot == null) {\n overridenOptions = {...options, dot: true}\n }\n return fastGlob(pattern, overridenOptions)\n}\n\n/**\n * Convert a path to a File URL.\n *\n * @param path - Path to convert.\n * @returns The File URL.\n */\nexport function pathToFileURL(path: string): URL {\n return pathToFile(path)\n}\n\n/**\n * The operating system-specific end-of-line marker:\n * - `\\n` on POSIX\n * - `\\r\\n` on Windows\n */\nexport type EOL = '\\r\\n' | '\\n'\n\n/**\n * Detects the end-of-line marker used in a string.\n *\n * @param content - file contents to analyze\n *\n * @returns The detected end-of-line marker\n */\nexport function detectEOL(content: string): EOL {\n const match = content.match(/\\r\\n|\\n/g)\n\n if (!match) {\n return defaultEOL()\n }\n\n const crlf = match.filter((eol) => eol === '\\r\\n').length\n const lf = match.filter((eol) => eol === '\\n').length\n\n return crlf > lf ? '\\r\\n' : '\\n'\n}\n\n/**\n * Returns the operating system's end-of-line marker.\n *\n * @returns The OS-specific end-of-line marker\n */\nexport function defaultEOL(): EOL {\n return os.EOL as EOL\n}\n\n/**\n * Find a file by walking parent directories.\n *\n * @param matcher - A pattern or an array of patterns to match a file name.\n * @param options - Options for the search.\n * @returns The first path found that matches or `undefined` if none could be found.\n */\nexport async function findPathUp(\n matcher: OverloadParameters<typeof internalFindUp>[0],\n options: OverloadParameters<typeof internalFindUp>[1],\n): ReturnType<typeof internalFindUp> {\n // findUp has odd typing\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const got = await internalFindUp(matcher as any, options)\n return got ? normalizePath(got) : undefined\n}\n\nexport interface MatchGlobOptions {\n matchBase: boolean\n noglobstar: boolean\n}\n\n/**\n * Matches a key against a glob pattern.\n * @param key - The key to match.\n * @param pattern - The glob pattern to match against.\n * @param options - The options to refine the matching approach.\n * @returns true if the key matches the pattern, false otherwise.\n */\nexport function matchGlob(key: string, pattern: string, options?: MatchGlobOptions): boolean {\n return minimatch(key, pattern, options)\n}\n\n/**\n * Read a directory.\n * @param path - The path to read.\n * @returns A promise that resolves to an array of file names.\n */\nexport function readdir(path: string): Promise<string[]> {\n return fsReaddir(path)\n}\n"]}
|
|
@@ -130,3 +130,10 @@ export declare function ensureIsClean(directory?: string): Promise<void>;
|
|
|
130
130
|
* @returns True is the .git directory is clean.
|
|
131
131
|
*/
|
|
132
132
|
export declare function isClean(directory?: string): Promise<boolean>;
|
|
133
|
+
/**
|
|
134
|
+
* Returns the latest tag of a git repository.
|
|
135
|
+
*
|
|
136
|
+
* @param directory - The directory to check.
|
|
137
|
+
* @returns String with the latest tag or undefined if no tags are found.
|
|
138
|
+
*/
|
|
139
|
+
export declare function getLatestTag(directory?: string): Promise<string | undefined>;
|
package/dist/public/node/git.js
CHANGED
|
@@ -277,4 +277,16 @@ export async function isClean(directory) {
|
|
|
277
277
|
// @ts-ignore
|
|
278
278
|
return (await git({ baseDir: directory }).status()).isClean();
|
|
279
279
|
}
|
|
280
|
+
/**
|
|
281
|
+
* Returns the latest tag of a git repository.
|
|
282
|
+
*
|
|
283
|
+
* @param directory - The directory to check.
|
|
284
|
+
* @returns String with the latest tag or undefined if no tags are found.
|
|
285
|
+
*/
|
|
286
|
+
export async function getLatestTag(directory) {
|
|
287
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
288
|
+
// @ts-ignore
|
|
289
|
+
const tags = await git({ baseDir: directory }).tags();
|
|
290
|
+
return tags.latest;
|
|
291
|
+
}
|
|
280
292
|
//# sourceMappingURL=git.js.map
|