@webiny/cli-core 0.0.0-unstable.0d717d18dd → 0.0.0-unstable.292eb6dc15
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/createCliContainer.js +18 -15
- package/createCliContainer.js.map +1 -1
- package/exports/extensions.d.ts +1 -0
- package/exports/extensions.js +1 -0
- package/extensions/CliCommand.js +2 -1
- package/extensions/CliCommand.js.map +1 -1
- package/extensions/CliCommandDecorator.js +2 -1
- package/extensions/CliCommandDecorator.js.map +1 -1
- package/features/AboutCommand.js +6 -11
- package/features/AboutCommand.js.map +1 -1
- package/features/DepsSync/DependencyTree.js +1 -1
- package/features/DepsSync/DependencyTree.js.map +1 -1
- package/features/DepsSync/ListAllPackages.d.ts +1 -1
- package/features/DepsSync/ListAllPackages.js +2 -2
- package/features/DepsSync/ListAllPackages.js.map +1 -1
- package/features/DepsSync/commands/SyncDepsCommand.js +1 -1
- package/features/DepsSync/commands/SyncDepsCommand.js.map +1 -1
- package/features/DepsSync/commands/VerifyDepsCommand.js +40 -3
- package/features/DepsSync/commands/VerifyDepsCommand.js.map +1 -1
- package/features/DepsSync/createDependencyTree.d.ts +1 -1
- package/features/DepsSync/createDependencyTree.js +8 -5
- package/features/DepsSync/createDependencyTree.js.map +1 -1
- package/features/DepsSync/paths.js +1 -1
- package/features/DepsSync/paths.js.map +1 -1
- package/features/DepsSync/types.js.map +1 -1
- package/features/Wcp/LinkProjectCommand.js +1 -1
- package/features/Wcp/LinkProjectCommand.js.map +1 -1
- package/features/globalOptions/TraceGlobalOption.d.ts +5 -0
- package/features/globalOptions/TraceGlobalOption.js +22 -0
- package/features/globalOptions/TraceGlobalOption.js.map +1 -0
- package/features/globalOptions/index.d.ts +1 -0
- package/features/globalOptions/index.js +1 -0
- package/features/index.d.ts +0 -2
- package/features/index.js +0 -2
- package/namespaces/cli.d.ts +5 -0
- package/namespaces/cli.js +7 -0
- package/namespaces/cli.js.map +1 -0
- package/package.json +26 -23
- package/services/GetCliRunnerService/GetCliRunnerService.js +6 -2
- package/services/GetCliRunnerService/GetCliRunnerService.js.map +1 -1
- package/services/UiService/UiService.d.ts +18 -0
- package/services/UiService/UiService.js +18 -2
- package/services/UiService/UiService.js.map +1 -1
- package/utils/{ensureSameWebinyPackageVersions.js → ensureSameWebinyPackageVersions/ensureSameWebinyPackageVersions.js} +12 -22
- package/utils/ensureSameWebinyPackageVersions/ensureSameWebinyPackageVersions.js.map +1 -0
- package/utils/ensureSameWebinyPackageVersions/getCacheFilePath.d.ts +1 -0
- package/utils/ensureSameWebinyPackageVersions/getCacheFilePath.js +12 -0
- package/utils/ensureSameWebinyPackageVersions/getCacheFilePath.js.map +1 -0
- package/utils/ensureSameWebinyPackageVersions/hashYarnLock.d.ts +1 -0
- package/utils/ensureSameWebinyPackageVersions/hashYarnLock.js +16 -0
- package/utils/ensureSameWebinyPackageVersions/hashYarnLock.js.map +1 -0
- package/utils/ensureSameWebinyPackageVersions/index.d.ts +6 -0
- package/utils/ensureSameWebinyPackageVersions/index.js +6 -0
- package/utils/ensureSameWebinyPackageVersions/listWebinyPackageVersions.d.ts +1 -0
- package/utils/ensureSameWebinyPackageVersions/listWebinyPackageVersions.js +31 -0
- package/utils/ensureSameWebinyPackageVersions/listWebinyPackageVersions.js.map +1 -0
- package/utils/ensureSameWebinyPackageVersions/readClearedYarnLockHash.d.ts +1 -0
- package/utils/ensureSameWebinyPackageVersions/readClearedYarnLockHash.js +13 -0
- package/utils/ensureSameWebinyPackageVersions/readClearedYarnLockHash.js.map +1 -0
- package/utils/ensureSameWebinyPackageVersions/writeClearedYarnLockHash.d.ts +1 -0
- package/utils/ensureSameWebinyPackageVersions/writeClearedYarnLockHash.js +24 -0
- package/utils/ensureSameWebinyPackageVersions/writeClearedYarnLockHash.js.map +1 -0
- package/features/InfoCommand/InfoCommand.d.ts +0 -10
- package/features/InfoCommand/InfoCommand.js +0 -62
- package/features/InfoCommand/InfoCommand.js.map +0 -1
- package/features/InfoCommand/PrintInfoForEnv.d.ts +0 -14
- package/features/InfoCommand/PrintInfoForEnv.js +0 -37
- package/features/InfoCommand/PrintInfoForEnv.js.map +0 -1
- package/features/InfoCommand/index.d.ts +0 -1
- package/features/InfoCommand/index.js +0 -1
- package/features/OpenCommand.d.ts +0 -10
- package/features/OpenCommand.js +0 -55
- package/features/OpenCommand.js.map +0 -1
- package/utils/ensureSameWebinyPackageVersions.js.map +0 -1
- /package/utils/{ensureSameWebinyPackageVersions.d.ts → ensureSameWebinyPackageVersions/ensureSameWebinyPackageVersions.d.ts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/Wcp/LinkProjectCommand.js","sources":["../../../src/features/Wcp/LinkProjectCommand.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport inquirer from \"inquirer\";\nimport { CliCommandFactory, GetProjectSdkService, UiService } from \"~/abstractions/index.js\";\nimport { setTimeout } from \"node:timers/promises\";\n\nconst sleep = (ms: number = 1500) => setTimeout(ms);\n\nexport class LinkProjectCommand implements CliCommandFactory.Interface<void> {\n constructor(\n private getProjectSdkService: GetProjectSdkService.Interface,\n private uiService: UiService.Interface\n ) {}\n\n async execute() {\n const projectSdk = await this.getProjectSdkService.execute();\n const wcp = projectSdk.wcp;\n const ui = this.uiService;\n\n return {\n name: \"link-project\",\n description: \"Link a Webiny project with Webiny Control Panel\",\n examples: [\"$0 link-project\"],\n handler: async () => {\n const user = await wcp.getUser();\n\n if (!user) {\n ui.error(\"You must be logged in to link a project.\");\n return;\n }\n\n // User already linked a project?\n const orgProjectId = await projectSdk.getProjectId();\n if (orgProjectId) {\n const [, projectId] = orgProjectId.split(\"/\");\n const project = user.projects.find(item => item.id === projectId);\n if (project) {\n ui.info(\"Your %s project is already linked.\", orgProjectId);\n\n const prompt = inquirer.createPromptModule();\n const { proceed } = await prompt({\n name: \"proceed\",\n message: \"Would you like to re-link it?\",\n type: \"confirm\",\n default: false\n });\n\n if (!proceed) {\n return;\n }\n\n ui.emptyLine();\n }\n }\n\n const wcpAppUrl = projectSdk.wcp.getWcpAppUrl().toString();\n\n // Get user's organizations.\n if (!user.orgs.length) {\n ui.info(\n \"It seems you're not part of any organization. Please log in to Webiny Control Panel and create one.\"\n );\n\n const prompt = inquirer.createPromptModule();\n const { proceed } = await prompt({\n name: \"proceed\",\n message: \"Would you like to do that now?\",\n type: \"confirm\",\n default: false\n });\n\n if (proceed) {\n open(wcpAppUrl);\n }\n return;\n }\n\n let selectedOrg;\n if (user.orgs.length === 1) {\n selectedOrg = user.orgs[0];\n } else {\n ui.info(\"It seems you're part of multiple organizations. \");\n const choices = user.orgs.map(item => ({\n name: item.name,\n value: item\n }));\n\n const prompt = inquirer.createPromptModule();\n selectedOrg = await prompt({\n name: \"org\",\n message: \"Select organization:\",\n type: \"select\",\n choices,\n default: choices[0].value\n }).then(result => result.org);\n }\n\n const orgProjects = user.projects.filter(item => item.org.id === selectedOrg.id);\n\n // Get user's projects.\n if (!orgProjects.length) {\n ui.info(\n \"It seems there are no projects created within the %s organization.\",\n selectedOrg.name\n );\n\n const prompt = inquirer.createPromptModule();\n const { proceed } = await prompt({\n name: \"proceed\",\n message: \"Would you like to create one now?\",\n type: \"confirm\",\n default: false\n });\n\n if (proceed) {\n open(wcpAppUrl);\n }\n return;\n }\n\n let selectedProject;\n if (orgProjects.length === 1) {\n selectedProject = user.projects[0];\n } else {\n ui.info(\n `It seems there are multiple projects created within the organization.`,\n selectedOrg.name\n );\n const choices = orgProjects.map(item => ({\n name: item.name,\n value: item\n }));\n const prompt = inquirer.createPromptModule();\n selectedProject = await prompt({\n name: \"project\",\n message: \"Select project:\",\n type: \"select\",\n choices,\n default: choices[0].value\n }).then(result => result.project);\n }\n\n await sleep();\n ui.emptyLine();\n\n ui.info(\"Linking %s project...\", selectedProject.name);\n\n await sleep();\n\n // Assign the necessary IDs into root `webiny.project.ts` project file.\n await projectSdk.setProjectId(`${selectedOrg.id}/${selectedProject.id}`, {\n force: true\n });\n\n ui.success(`%s Project %s linked successfully.`, \"✔\", selectedProject.name);\n\n await sleep();\n\n ui.emptyLine();\n ui.textBold(\"Next Steps\");\n\n ui.text(`‣ deploy your project via the yarn webiny deploy command`);\n }\n };\n }\n}\n\nexport const linkProjectCommand = createImplementation({\n abstraction: CliCommandFactory,\n implementation: LinkProjectCommand,\n dependencies: [GetProjectSdkService, UiService]\n});\n"],"names":["sleep","ms","setTimeout","LinkProjectCommand","getProjectSdkService","uiService","projectSdk","wcp","ui","user","orgProjectId","projectId","project","item","prompt","inquirer","proceed","wcpAppUrl","open","selectedOrg","choices","result","orgProjects","selectedProject","linkProjectCommand","createImplementation","CliCommandFactory","GetProjectSdkService","UiService"],"mappings":";;;;AAKA,MAAMA,QAAQ,CAACC,KAAa,IAAI,GAAKC,oBAAWD;AAEzC,MAAME;IACT,YACYC,oBAAoD,EACpDC,SAA8B,CACxC;aAFUD,oBAAoB,GAApBA;aACAC,SAAS,GAATA;IACT;IAEH,MAAM,UAAU;QACZ,MAAMC,aAAa,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO;QAC1D,MAAMC,MAAMD,WAAW,GAAG;QAC1B,MAAME,KAAK,IAAI,CAAC,SAAS;QAEzB,OAAO;YACH,MAAM;YACN,aAAa;YACb,UAAU;gBAAC;aAAkB;YAC7B,SAAS;gBACL,MAAMC,OAAO,MAAMF,IAAI,OAAO;gBAE9B,IAAI,CAACE,MAAM,YACPD,GAAG,KAAK,CAAC;gBAKb,MAAME,eAAe,MAAMJ,WAAW,YAAY;gBAClD,IAAII,cAAc;oBACd,MAAM,GAAGC,UAAU,GAAGD,aAAa,KAAK,CAAC;oBACzC,MAAME,UAAUH,KAAK,QAAQ,CAAC,IAAI,CAACI,CAAAA,OAAQA,KAAK,EAAE,KAAKF;oBACvD,IAAIC,SAAS;wBACTJ,GAAG,IAAI,CAAC,sCAAsCE;wBAE9C,MAAMI,SAASC,SAAS,kBAAkB;wBAC1C,MAAM,EAAEC,OAAO,EAAE,GAAG,MAAM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S;oBACb;oBAEA,IAAIE,SACAE,KAAKD;oBAET;gBACJ;gBAEA,IAAIM;gBACJ,IAAID,AAAuB,MAAvBA,YAAY,MAAM,EAClBC,kBAAkBd,KAAK,QAAQ,CAAC,EAAE;qBAC/B;oBACHD,GAAG,IAAI,CACH,yEACAW,YAAY,IAAI;oBAEpB,MAAMC,UAAUE,YAAY,GAAG,CAACT,CAAAA,OAAS;4BACrC,MAAMA,KAAK,IAAI;4BACf,OAAOA;wBACX;oBACA,MAAMC,SAASC,SAAS,kBAAkB;oBAC1CQ,kBAAkB,MAAMT,OAAO;wBAC3B,MAAM;wBACN,SAAS;wBACT,MAAM;wBACNM;wBACA,SAASA,OAAO,CAAC,EAAE,CAAC,KAAK;oBAC7B,GAAG,IAAI,CAACC,CAAAA,SAAUA,OAAO,OAAO;gBACpC;gBAEA,MAAMrB;gBACNQ,GAAG,SAAS;gBAEZA,GAAG,IAAI,CAAC,yBAAyBe,gBAAgB,IAAI;gBAErD,MAAMvB;gBAGN,MAAMM,WAAW,YAAY,CAAC,GAAGa,YAAY,EAAE,CAAC,CAAC,EAAEI,gBAAgB,EAAE,EAAE,EAAE;oBACrE,OAAO;gBACX;gBAEAf,GAAG,OAAO,CAAC,sCAAsC,KAAKe,gBAAgB,IAAI;gBAE1E,MAAMvB;gBAENQ,GAAG,SAAS;gBACZA,GAAG,QAAQ,CAAC;gBAEZA,GAAG,IAAI,CAAC;YACZ;QACJ;IACJ;AACJ;AAEO,MAAMgB,qBAAqBC,qBAAqB;IACnD,aAAaC;IACb,gBAAgBvB;IAChB,cAAc;QAACwB;QAAsBC;KAAU;AACnD"}
|
|
1
|
+
{"version":3,"file":"features/Wcp/LinkProjectCommand.js","sources":["../../../src/features/Wcp/LinkProjectCommand.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport { CliCommandFactory, GetProjectSdkService, UiService } from \"~/abstractions/index.js\";\nimport { setTimeout } from \"node:timers/promises\";\n\nconst sleep = (ms: number = 1500) => setTimeout(ms);\n\nexport class LinkProjectCommand implements CliCommandFactory.Interface<void> {\n constructor(\n private getProjectSdkService: GetProjectSdkService.Interface,\n private uiService: UiService.Interface\n ) {}\n\n async execute() {\n const projectSdk = await this.getProjectSdkService.execute();\n const wcp = projectSdk.wcp;\n const ui = this.uiService;\n\n return {\n name: \"link-project\",\n description: \"Link a Webiny project with Webiny Control Panel\",\n examples: [\"$0 link-project\"],\n handler: async () => {\n // Imported here rather than at the top of the file. The CLI imports every command's\n // code on every run, even `webiny --help`, and inquirer with its dependencies is about\n // 60 modules that only this command's prompts ever need.\n const { default: inquirer } = await import(\"inquirer\");\n\n const user = await wcp.getUser();\n\n if (!user) {\n ui.error(\"You must be logged in to link a project.\");\n return;\n }\n\n // User already linked a project?\n const orgProjectId = await projectSdk.getProjectId();\n if (orgProjectId) {\n const [, projectId] = orgProjectId.split(\"/\");\n const project = user.projects.find(item => item.id === projectId);\n if (project) {\n ui.info(\"Your %s project is already linked.\", orgProjectId);\n\n const prompt = inquirer.createPromptModule();\n const { proceed } = await prompt({\n name: \"proceed\",\n message: \"Would you like to re-link it?\",\n type: \"confirm\",\n default: false\n });\n\n if (!proceed) {\n return;\n }\n\n ui.emptyLine();\n }\n }\n\n const wcpAppUrl = projectSdk.wcp.getWcpAppUrl().toString();\n\n // Get user's organizations.\n if (!user.orgs.length) {\n ui.info(\n \"It seems you're not part of any organization. Please log in to Webiny Control Panel and create one.\"\n );\n\n const prompt = inquirer.createPromptModule();\n const { proceed } = await prompt({\n name: \"proceed\",\n message: \"Would you like to do that now?\",\n type: \"confirm\",\n default: false\n });\n\n if (proceed) {\n open(wcpAppUrl);\n }\n return;\n }\n\n let selectedOrg;\n if (user.orgs.length === 1) {\n selectedOrg = user.orgs[0];\n } else {\n ui.info(\"It seems you're part of multiple organizations. \");\n const choices = user.orgs.map(item => ({\n name: item.name,\n value: item\n }));\n\n const prompt = inquirer.createPromptModule();\n selectedOrg = await prompt({\n name: \"org\",\n message: \"Select organization:\",\n type: \"select\",\n choices,\n default: choices[0].value\n }).then(result => result.org);\n }\n\n const orgProjects = user.projects.filter(item => item.org.id === selectedOrg.id);\n\n // Get user's projects.\n if (!orgProjects.length) {\n ui.info(\n \"It seems there are no projects created within the %s organization.\",\n selectedOrg.name\n );\n\n const prompt = inquirer.createPromptModule();\n const { proceed } = await prompt({\n name: \"proceed\",\n message: \"Would you like to create one now?\",\n type: \"confirm\",\n default: false\n });\n\n if (proceed) {\n open(wcpAppUrl);\n }\n return;\n }\n\n let selectedProject;\n if (orgProjects.length === 1) {\n selectedProject = user.projects[0];\n } else {\n ui.info(\n `It seems there are multiple projects created within the organization.`,\n selectedOrg.name\n );\n const choices = orgProjects.map(item => ({\n name: item.name,\n value: item\n }));\n const prompt = inquirer.createPromptModule();\n selectedProject = await prompt({\n name: \"project\",\n message: \"Select project:\",\n type: \"select\",\n choices,\n default: choices[0].value\n }).then(result => result.project);\n }\n\n await sleep();\n ui.emptyLine();\n\n ui.info(\"Linking %s project...\", selectedProject.name);\n\n await sleep();\n\n // Assign the necessary IDs into root `webiny.project.ts` project file.\n await projectSdk.setProjectId(`${selectedOrg.id}/${selectedProject.id}`, {\n force: true\n });\n\n ui.success(`%s Project %s linked successfully.`, \"✔\", selectedProject.name);\n\n await sleep();\n\n ui.emptyLine();\n ui.textBold(\"Next Steps\");\n\n ui.text(`‣ deploy your project via the yarn webiny deploy command`);\n }\n };\n }\n}\n\nexport const linkProjectCommand = createImplementation({\n abstraction: CliCommandFactory,\n implementation: LinkProjectCommand,\n dependencies: [GetProjectSdkService, UiService]\n});\n"],"names":["sleep","ms","setTimeout","LinkProjectCommand","getProjectSdkService","uiService","projectSdk","wcp","ui","inquirer","user","orgProjectId","projectId","project","item","prompt","proceed","wcpAppUrl","open","selectedOrg","choices","result","orgProjects","selectedProject","linkProjectCommand","createImplementation","CliCommandFactory","GetProjectSdkService","UiService"],"mappings":";;;AAIA,MAAMA,QAAQ,CAACC,KAAa,IAAI,GAAKC,oBAAWD;AAEzC,M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AC,EAAE,CAAC,KAAK;oBAC7B,GAAG,IAAI,CAACC,CAAAA,SAAUA,OAAO,OAAO;gBACpC;gBAEA,MAAMrB;gBACNQ,GAAG,SAAS;gBAEZA,GAAG,IAAI,CAAC,yBAAyBe,gBAAgB,IAAI;gBAErD,MAAMvB;gBAGN,MAAMM,WAAW,YAAY,CAAC,GAAGa,YAAY,EAAE,CAAC,CAAC,EAAEI,gBAAgB,EAAE,EAAE,EAAE;oBACrE,OAAO;gBACX;gBAEAf,GAAG,OAAO,CAAC,sCAAsC,KAAKe,gBAAgB,IAAI;gBAE1E,MAAMvB;gBAENQ,GAAG,SAAS;gBACZA,GAAG,QAAQ,CAAC;gBAEZA,GAAG,IAAI,CAAC;YACZ;QACJ;IACJ;AACJ;AAEO,MAAMgB,qBAAqBC,qBAAqB;IACnD,aAAaC;IACb,gBAAgBvB;IAChB,cAAc;QAACwB;QAAsBC;KAAU;AACnD"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { GlobalCliOption } from "../../abstractions/index.js";
|
|
2
|
+
export declare class TraceGlobalOption implements GlobalCliOption.Interface {
|
|
3
|
+
execute(): GlobalCliOption.Definition;
|
|
4
|
+
}
|
|
5
|
+
export declare const traceGlobalOption: import("@webiny/di").Implementation<typeof TraceGlobalOption>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createImplementation } from "@webiny/di";
|
|
2
|
+
import { GlobalCliOption } from "../../abstractions/index.js";
|
|
3
|
+
class TraceGlobalOption {
|
|
4
|
+
execute() {
|
|
5
|
+
return {
|
|
6
|
+
name: "trace",
|
|
7
|
+
config: {
|
|
8
|
+
type: "boolean",
|
|
9
|
+
default: false,
|
|
10
|
+
description: "Print a timing breakdown of the run"
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const traceGlobalOption = createImplementation({
|
|
16
|
+
abstraction: GlobalCliOption,
|
|
17
|
+
implementation: TraceGlobalOption,
|
|
18
|
+
dependencies: []
|
|
19
|
+
});
|
|
20
|
+
export { TraceGlobalOption, traceGlobalOption };
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=TraceGlobalOption.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/globalOptions/TraceGlobalOption.js","sources":["../../../src/features/globalOptions/TraceGlobalOption.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport { GlobalCliOption } from \"~/abstractions/index.js\";\n\n/*\n * Declared here only so the flag shows up in `webiny --help`. The CLI entrypoint reads it straight\n * off `process.argv`, because tracing has to be on before yargs is built.\n */\nexport class TraceGlobalOption implements GlobalCliOption.Interface {\n execute(): GlobalCliOption.Definition {\n return {\n name: \"trace\",\n config: {\n type: \"boolean\",\n default: false,\n description: \"Print a timing breakdown of the run\"\n }\n };\n }\n}\n\nexport const traceGlobalOption = createImplementation({\n abstraction: GlobalCliOption,\n implementation: TraceGlobalOption,\n dependencies: []\n});\n"],"names":["TraceGlobalOption","traceGlobalOption","createImplementation","GlobalCliOption"],"mappings":";;AAOO,MAAMA;IACT,UAAsC;QAClC,OAAO;YACH,MAAM;YACN,QAAQ;gBACJ,MAAM;gBACN,SAAS;gBACT,aAAa;YACjB;QACJ;IACJ;AACJ;AAEO,MAAMC,oBAAoBC,qBAAqB;IAClD,aAAaC;IACb,gBAAgBH;IAChB,cAAc,EAAE;AACpB"}
|
package/features/index.d.ts
CHANGED
|
@@ -3,9 +3,7 @@ export * from "./BuildCommand/index.js";
|
|
|
3
3
|
export * from "./ConfigCommand.js";
|
|
4
4
|
export * from "./DeployCommand/index.js";
|
|
5
5
|
export * from "./ExtensionCommand/index.js";
|
|
6
|
-
export * from "./InfoCommand/index.js";
|
|
7
6
|
export * from "./IsCi/index.js";
|
|
8
|
-
export * from "./OpenCommand.js";
|
|
9
7
|
export * from "./DisableTelemetryCommand.js";
|
|
10
8
|
export * from "./EnableTelemetryCommand.js";
|
|
11
9
|
export * from "./UpgradeCommand/index.js";
|
package/features/index.js
CHANGED
|
@@ -3,9 +3,7 @@ export * from "./BuildCommand/index.js";
|
|
|
3
3
|
export * from "./ConfigCommand.js";
|
|
4
4
|
export * from "./DeployCommand/index.js";
|
|
5
5
|
export * from "./ExtensionCommand/index.js";
|
|
6
|
-
export * from "./InfoCommand/index.js";
|
|
7
6
|
export * from "./IsCi/index.js";
|
|
8
|
-
export * from "./OpenCommand.js";
|
|
9
7
|
export * from "./DisableTelemetryCommand.js";
|
|
10
8
|
export * from "./EnableTelemetryCommand.js";
|
|
11
9
|
export * from "./UpgradeCommand/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"namespaces/cli.js","sources":["../../src/namespaces/cli.ts"],"sourcesContent":["import { CliCommand } from \"~/extensions/index.js\";\n\nexport const Cli = {\n Command: CliCommand\n};\n"],"names":["Cli","CliCommand"],"mappings":";AAEO,MAAMA,MAAM;IACf,SAASC;AACb"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/cli-core",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.292eb6dc15",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -13,34 +13,37 @@
|
|
|
13
13
|
"description": "A command line interface (CLI) for managing Webiny projects.",
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@webiny/di": "
|
|
17
|
-
"@webiny/feature": "0.0.0-unstable.
|
|
18
|
-
"@webiny/project": "0.0.0-unstable.
|
|
19
|
-
"@webiny/stdlib": "0.0.
|
|
20
|
-
"@webiny/telemetry": "0.0.0-unstable.
|
|
21
|
-
"chalk": "6.0.
|
|
22
|
-
"ci-info": "4.
|
|
23
|
-
"execa": "10.
|
|
16
|
+
"@webiny/di": "2.0.0",
|
|
17
|
+
"@webiny/feature": "0.0.0-unstable.292eb6dc15",
|
|
18
|
+
"@webiny/project": "0.0.0-unstable.292eb6dc15",
|
|
19
|
+
"@webiny/stdlib": "0.0.21",
|
|
20
|
+
"@webiny/telemetry": "0.0.0-unstable.292eb6dc15",
|
|
21
|
+
"chalk": "6.0.1",
|
|
22
|
+
"ci-info": "4.5.0",
|
|
23
|
+
"execa": "10.2.1",
|
|
24
24
|
"fast-glob": "3.3.3",
|
|
25
25
|
"find-up": "8.0.0",
|
|
26
|
-
"humanize-duration": "3.
|
|
27
|
-
"inquirer": "14.0
|
|
26
|
+
"humanize-duration": "3.35.1",
|
|
27
|
+
"inquirer": "14.3.0",
|
|
28
28
|
"load-json-file": "7.0.1",
|
|
29
|
-
"open": "11.0.
|
|
30
|
-
"ora": "
|
|
31
|
-
"pino": "10.
|
|
32
|
-
"pino-pretty": "13.
|
|
33
|
-
"semver": "7.8.
|
|
34
|
-
"type-fest": "
|
|
29
|
+
"open": "11.0.4",
|
|
30
|
+
"ora": "10.0.0",
|
|
31
|
+
"pino": "10.4.0",
|
|
32
|
+
"pino-pretty": "13.2.0",
|
|
33
|
+
"semver": "7.8.6",
|
|
34
|
+
"type-fest": "6.0.3",
|
|
35
|
+
"wrap-ansi": "10.0.2",
|
|
35
36
|
"write-json-file": "7.0.0",
|
|
36
|
-
"yargs": "18.
|
|
37
|
-
"zod": "4.
|
|
37
|
+
"yargs": "18.2.0",
|
|
38
|
+
"zod": "4.6.7"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
|
-
"@types/lodash": "4.17.
|
|
41
|
-
"@webiny/build-tools": "0.0.0-unstable.
|
|
42
|
-
"rimraf": "6.1.
|
|
43
|
-
"
|
|
41
|
+
"@types/lodash": "4.17.27",
|
|
42
|
+
"@webiny/build-tools": "0.0.0-unstable.292eb6dc15",
|
|
43
|
+
"rimraf": "6.1.4",
|
|
44
|
+
"strip-ansi": "7.2.0",
|
|
45
|
+
"typescript": "7.0.2",
|
|
46
|
+
"vitest": "5.1.1"
|
|
44
47
|
},
|
|
45
48
|
"publishConfig": {
|
|
46
49
|
"access": "public"
|
|
@@ -3,8 +3,9 @@ import { CommandsRegistryService, GetArgvService, GetCliRunnerService, GetProjec
|
|
|
3
3
|
import yargs_yargs from "yargs/yargs";
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import { GracefulError } from "@webiny/project";
|
|
6
|
+
import { traceRecorder } from "@webiny/project/utils/trace/index.js";
|
|
6
7
|
import { ManuallyReportedError } from "../../utils/ManuallyReportedError.js";
|
|
7
|
-
const { blue
|
|
8
|
+
const { blue, bgYellow, bold } = chalk;
|
|
8
9
|
class DefaultGetCliRunnerService {
|
|
9
10
|
constructor(commandsRegistryService, globalOptionsRegistryService, uiService, getProjectSdkService, getArgvService){
|
|
10
11
|
this.commandsRegistryService = commandsRegistryService;
|
|
@@ -75,7 +76,10 @@ class DefaultGetCliRunnerService {
|
|
|
75
76
|
});
|
|
76
77
|
const commands = this.commandsRegistryService.execute();
|
|
77
78
|
for (const command of commands){
|
|
78
|
-
const
|
|
79
|
+
const startedAt = performance.now();
|
|
80
|
+
const definition = await command.execute();
|
|
81
|
+
const { name, description, params = [], options = [], handler } = definition;
|
|
82
|
+
traceRecorder.record(`build "${name}" command`, startedAt, performance.now());
|
|
79
83
|
let yargsCommand = name;
|
|
80
84
|
const paramVersionExists = params.some((p)=>"version" === p.name);
|
|
81
85
|
if (paramVersionExists) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services/GetCliRunnerService/GetCliRunnerService.js","sources":["../../../src/services/GetCliRunnerService/GetCliRunnerService.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport {\n CliCommandFactory,\n CommandsRegistryService,\n GetArgvService,\n GetCliRunnerService,\n GlobalOptionsRegistryService,\n GetProjectSdkService,\n UiService\n} from \"~/abstractions/index.js\";\nimport yargs from \"yargs/yargs\";\nimport chalk from \"chalk\";\nimport { Argv } from \"yargs\";\nimport { GracefulError } from \"@webiny/project\";\nimport { ManuallyReportedError } from \"~/utils/ManuallyReportedError.js\";\n\nconst { blue, bgYellow, bold } = chalk;\n\nexport class DefaultGetCliRunnerService implements GetCliRunnerService.Interface {\n constructor(\n private readonly commandsRegistryService: CommandsRegistryService.Interface,\n private readonly globalOptionsRegistryService: GlobalOptionsRegistryService.Interface,\n private readonly uiService: UiService.Interface,\n private readonly getProjectSdkService: GetProjectSdkService.Interface,\n private readonly getArgvService: GetArgvService.Interface\n ) {}\n\n private yargsRunner: Argv | null = null;\n\n async execute() {\n if (this.yargsRunner) {\n return this.yargsRunner;\n }\n\n const ui = this.uiService;\n const projectSdk = await this.getProjectSdkService.execute();\n\n const yargsRunner = yargs()\n .usage(\"Usage: $0 <command> [options]\")\n .help(false)\n .demandCommand(1)\n .recommendCommands()\n .scriptName(\"webiny\")\n .epilogue(\n `To find more information, docs and tutorials, see ${blue(\n \"https://www.webiny.com/docs\"\n )}.`\n )\n .epilogue(`Want to contribute? ${blue(\"https://github.com/webiny/webiny-js\")}.`);\n\n // Register global options.\n const globalOptions = this.globalOptionsRegistryService.execute();\n for (const globalOption of globalOptions) {\n const { name, config } = await globalOption.execute();\n yargsRunner.option(name, {\n type: config.type,\n default: config.default,\n desc: config.description,\n alias: config.alias,\n choices: config.choices,\n global: true\n });\n }\n\n yargsRunner.fail((invalidParamsMessage, error) => {\n if (invalidParamsMessage) {\n if (invalidParamsMessage.includes(\"Not enough non-option arguments\")) {\n ui.emptyLine();\n ui.error(\"Command was not invoked as expected.\");\n ui.info(\n `Some non-optional arguments are missing. See the usage examples printed below.`\n );\n ui.emptyLine();\n yargsRunner.showHelp();\n process.exit(1);\n }\n\n if (invalidParamsMessage.includes(\"Missing required argument\")) {\n const args = invalidParamsMessage\n .split(\":\")[1]\n .split(\",\")\n .map(v => v.trim());\n\n ui.emptyLine();\n ui.error(\"Command was not invoked as expected.\");\n ui.info(\n `Missing required argument(s): ${args.join(\n \", \"\n )}. See the usage examples printed below.`\n );\n ui.emptyLine();\n yargsRunner.showHelp();\n process.exit(1);\n }\n\n ui.emptyLine();\n ui.error(invalidParamsMessage);\n\n process.exit(1);\n }\n\n const logger = projectSdk.getLogger();\n logger.error({ err: error }, \"CLI command execution failed.\");\n\n const realError = (error.cause as Error) || error;\n\n if (realError instanceof ManuallyReportedError) {\n // Do nothing as the error reporting has already been\n // handled within the invoked CLI command.\n } else {\n ui.error(realError.message);\n }\n\n const argv = this.getArgvService.execute();\n if (argv.showStackTrace && realError.stack) {\n ui.emptyLine();\n ui.debug(\"Stack trace:\");\n ui.text(realError.stack);\n }\n\n if (error instanceof GracefulError) {\n ui.emptyLine();\n ui.text(bgYellow(bold(\"💡 How can I resolve this?\")));\n ui.text(error.message);\n }\n\n process.exit(1);\n });\n\n const commands = this.commandsRegistryService.execute();\n\n for (const command of commands) {\n const {\n name,\n description,\n params = [],\n options = [],\n handler\n } = await command.execute();\n\n let yargsCommand = name;\n const paramVersionExists = params.some(p => {\n return p.name === \"version\";\n });\n if (paramVersionExists) {\n ui.error(\n `The command \"${name}\" cannot have a parameter named \"version\" as it conflicts with the global --version option.`\n );\n process.exit();\n }\n\n if (params.length > 0) {\n yargsCommand +=\n \" \" +\n params\n .map(param => {\n const paramName = param.array ? `${param.name}..` : param.name;\n return param.required ? `<${paramName}>` : `[${paramName}]`;\n })\n .join(\" \");\n }\n\n yargsRunner.command(\n yargsCommand,\n description,\n yargs => {\n params.forEach((param: CliCommandFactory.ParamDefinition<unknown>) => {\n const { name, required, validation, array, ...rest } = param;\n\n const yargsParam = yargs.positional(name, {\n ...rest,\n ...(array && { array: true }),\n demandOption: required\n });\n\n if (validation) {\n yargsParam.check(validation);\n }\n });\n\n options.forEach((option: CliCommandFactory.OptionDefinition<unknown>) => {\n const { name, required, validation, ...rest } = option;\n\n const yargsOption = yargs.option(name, {\n ...rest,\n demandOption: required\n });\n\n if (option.group) {\n yargsOption.group(option.name, option.group);\n }\n\n if (validation) {\n yargsOption.check(validation);\n }\n });\n },\n handler\n );\n }\n\n yargsRunner.help(true);\n yargsRunner.version(projectSdk.getProjectVersion());\n this.yargsRunner = yargsRunner;\n return this.yargsRunner;\n }\n}\n\nexport const getCliRunnerService = createImplementation({\n abstraction: GetCliRunnerService,\n implementation: DefaultGetCliRunnerService,\n dependencies: [\n CommandsRegistryService,\n GlobalOptionsRegistryService,\n UiService,\n GetProjectSdkService,\n GetArgvService\n ]\n});\n"],"names":["blue","bgYellow","bold","chalk","DefaultGetCliRunnerService","commandsRegistryService","globalOptionsRegistryService","uiService","getProjectSdkService","getArgvService","ui","projectSdk","yargsRunner","yargs","globalOptions","globalOption","name","config","invalidParamsMessage","error","process","args","v","logger","realError","ManuallyReportedError","argv","GracefulError","commands","command","description","params","options","handler","yargsCommand","paramVersionExists","p","param","paramName","required","validation","array","rest","yargsParam","option","yargsOption","getCliRunnerService","createImplementation","GetCliRunnerService","CommandsRegistryService","GlobalOptionsRegistryService","UiService","GetProjectSdkService","GetArgvService"],"mappings":";;;;;;AAgBA,MAAM,EAAEA,MAAAA,IAAI,EAAEC,UAAAA,QAAQ,EAAEC,MAAAA,IAAI,EAAE,GAAGC;AAE1B,MAAMC;IACT,YACqBC,uBAA0D,EAC1DC,4BAAoE,EACpEC,SAA8B,EAC9BC,oBAAoD,EACpDC,cAAwC,CAC3D;aALmBJ,uBAAuB,GAAvBA;aACAC,4BAA4B,GAA5BA;aACAC,SAAS,GAATA;aACAC,oBAAoB,GAApBA;aACAC,cAAc,GAAdA;aAGb,WAAW,GAAgB;IAFhC;IAIH,MAAM,UAAU;QACZ,IAAI,IAAI,CAAC,WAAW,EAChB,OAAO,IAAI,CAAC,WAAW;QAG3B,MAAMC,KAAK,IAAI,CAAC,SAAS;QACzB,MAAMC,aAAa,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO;QAE1D,MAAMC,cAAcC,cACf,KAAK,CAAC,iCACN,IAAI,CAAC,OACL,aAAa,CAAC,GACd,iBAAiB,GACjB,UAAU,CAAC,UACX,QAAQ,CACL,CAAC,kDAAkD,EAAEb,K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AAAA;gBACIkB,OAAO,OAAO,CAAC,CAACM;oBACZ,MAAM,EAAErB,IAAI,EAAEuB,QAAQ,EAAEC,UAAU,EAAEC,KAAK,EAAE,GAAGC,MAAM,GAAGL;oBAEvD,MAAMM,aAAa9B,MAAM,UAAU,CAACG,MAAM;wBACtC,GAAG0B,IAAI;wBACP,GAAID,SAAS;4BAAE,OAAO;wBAAK,CAAC;wBAC5B,cAAcF;oBAClB;oBAEA,IAAIC,YACAG,WAAW,KAAK,CAACH;gBAEzB;gBAEAR,QAAQ,OAAO,CAAC,CAACY;oBACb,MAAM,EAAE5B,IAAI,EAAEuB,QAAQ,EAAEC,UAAU,EAAE,GAAGE,MAAM,GAAGE;oBAEhD,MAAMC,cAAchC,MAAM,MAAM,CAACG,MAAM;wBACnC,GAAG0B,IAAI;wBACP,cAAcH;oBAClB;oBAEA,IAAIK,OAAO,KAAK,EACZC,YAAY,KAAK,CAACD,OAAO,IAAI,EAAEA,OAAO,KAAK;oBAG/C,IAAIJ,YACAK,YAAY,KAAK,CAACL;gBAE1B;YACJ,GACAP;QAER;QAEArB,YAAY,IAAI,CAAC;QACjBA,YAAY,OAAO,CAACD,WAAW,iBAAiB;QAChD,IAAI,CAAC,WAAW,GAAGC;QACnB,OAAO,IAAI,CAAC,WAAW;IAC3B;AACJ;AAEO,MAAMkC,sBAAsBC,qBAAqB;IACpD,aAAaC;IACb,gBAAgB5C;IAChB,cAAc;QACV6C;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
1
|
+
{"version":3,"file":"services/GetCliRunnerService/GetCliRunnerService.js","sources":["../../../src/services/GetCliRunnerService/GetCliRunnerService.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport {\n CliCommandFactory,\n CommandsRegistryService,\n GetArgvService,\n GetCliRunnerService,\n GlobalOptionsRegistryService,\n GetProjectSdkService,\n UiService\n} from \"~/abstractions/index.js\";\nimport yargs from \"yargs/yargs\";\nimport chalk from \"chalk\";\nimport { Argv } from \"yargs\";\nimport { GracefulError } from \"@webiny/project\";\nimport { traceRecorder } from \"@webiny/project/utils/trace/index.js\";\nimport { ManuallyReportedError } from \"~/utils/ManuallyReportedError.js\";\n\nconst { blue, bgYellow, bold } = chalk;\n\nexport class DefaultGetCliRunnerService implements GetCliRunnerService.Interface {\n constructor(\n private readonly commandsRegistryService: CommandsRegistryService.Interface,\n private readonly globalOptionsRegistryService: GlobalOptionsRegistryService.Interface,\n private readonly uiService: UiService.Interface,\n private readonly getProjectSdkService: GetProjectSdkService.Interface,\n private readonly getArgvService: GetArgvService.Interface\n ) {}\n\n private yargsRunner: Argv | null = null;\n\n async execute() {\n if (this.yargsRunner) {\n return this.yargsRunner;\n }\n\n const ui = this.uiService;\n const projectSdk = await this.getProjectSdkService.execute();\n\n const yargsRunner = yargs()\n .usage(\"Usage: $0 <command> [options]\")\n .help(false)\n .demandCommand(1)\n .recommendCommands()\n .scriptName(\"webiny\")\n .epilogue(\n `To find more information, docs and tutorials, see ${blue(\n \"https://www.webiny.com/docs\"\n )}.`\n )\n .epilogue(`Want to contribute? ${blue(\"https://github.com/webiny/webiny-js\")}.`);\n\n // Register global options.\n const globalOptions = this.globalOptionsRegistryService.execute();\n for (const globalOption of globalOptions) {\n const { name, config } = await globalOption.execute();\n yargsRunner.option(name, {\n type: config.type,\n default: config.default,\n desc: config.description,\n alias: config.alias,\n choices: config.choices,\n global: true\n });\n }\n\n yargsRunner.fail((invalidParamsMessage, error) => {\n if (invalidParamsMessage) {\n if (invalidParamsMessage.includes(\"Not enough non-option arguments\")) {\n ui.emptyLine();\n ui.error(\"Command was not invoked as expected.\");\n ui.info(\n `Some non-optional arguments are missing. See the usage examples printed below.`\n );\n ui.emptyLine();\n yargsRunner.showHelp();\n process.exit(1);\n }\n\n if (invalidParamsMessage.includes(\"Missing required argument\")) {\n const args = invalidParamsMessage\n .split(\":\")[1]\n .split(\",\")\n .map(v => v.trim());\n\n ui.emptyLine();\n ui.error(\"Command was not invoked as expected.\");\n ui.info(\n `Missing required argument(s): ${args.join(\n \", \"\n )}. See the usage examples printed below.`\n );\n ui.emptyLine();\n yargsRunner.showHelp();\n process.exit(1);\n }\n\n ui.emptyLine();\n ui.error(invalidParamsMessage);\n\n process.exit(1);\n }\n\n const logger = projectSdk.getLogger();\n logger.error({ err: error }, \"CLI command execution failed.\");\n\n const realError = (error.cause as Error) || error;\n\n if (realError instanceof ManuallyReportedError) {\n // Do nothing as the error reporting has already been\n // handled within the invoked CLI command.\n } else {\n ui.error(realError.message);\n }\n\n const argv = this.getArgvService.execute();\n if (argv.showStackTrace && realError.stack) {\n ui.emptyLine();\n ui.debug(\"Stack trace:\");\n ui.text(realError.stack);\n }\n\n if (error instanceof GracefulError) {\n ui.emptyLine();\n ui.text(bgYellow(bold(\"💡 How can I resolve this?\")));\n ui.text(error.message);\n }\n\n process.exit(1);\n });\n\n const commands = this.commandsRegistryService.execute();\n\n // Every registered command's definition is built on every run, no matter which command was\n // actually invoked, so each one is timed separately.\n for (const command of commands) {\n const startedAt = performance.now();\n const definition = await command.execute();\n\n const { name, description, params = [], options = [], handler } = definition;\n\n traceRecorder.record(`build \"${name}\" command`, startedAt, performance.now());\n\n let yargsCommand = name;\n const paramVersionExists = params.some(p => {\n return p.name === \"version\";\n });\n if (paramVersionExists) {\n ui.error(\n `The command \"${name}\" cannot have a parameter named \"version\" as it conflicts with the global --version option.`\n );\n process.exit();\n }\n\n if (params.length > 0) {\n yargsCommand +=\n \" \" +\n params\n .map(param => {\n const paramName = param.array ? `${param.name}..` : param.name;\n return param.required ? `<${paramName}>` : `[${paramName}]`;\n })\n .join(\" \");\n }\n\n yargsRunner.command(\n yargsCommand,\n description,\n yargs => {\n params.forEach((param: CliCommandFactory.ParamDefinition<unknown>) => {\n const { name, required, validation, array, ...rest } = param;\n\n const yargsParam = yargs.positional(name, {\n ...rest,\n ...(array && { array: true }),\n demandOption: required\n });\n\n if (validation) {\n yargsParam.check(validation);\n }\n });\n\n options.forEach((option: CliCommandFactory.OptionDefinition<unknown>) => {\n const { name, required, validation, ...rest } = option;\n\n const yargsOption = yargs.option(name, {\n ...rest,\n demandOption: required\n });\n\n if (option.group) {\n yargsOption.group(option.name, option.group);\n }\n\n if (validation) {\n yargsOption.check(validation);\n }\n });\n },\n handler\n );\n }\n\n yargsRunner.help(true);\n yargsRunner.version(projectSdk.getProjectVersion());\n this.yargsRunner = yargsRunner;\n return this.yargsRunner;\n }\n}\n\nexport const getCliRunnerService = createImplementation({\n abstraction: GetCliRunnerService,\n implementation: DefaultGetCliRunnerService,\n dependencies: [\n CommandsRegistryService,\n GlobalOptionsRegistryService,\n UiService,\n GetProjectSdkService,\n GetArgvService\n ]\n});\n"],"names":["blue","bgYellow","bold","chalk","DefaultGetCliRunnerService","commandsRegistryService","globalOptionsRegistryService","uiService","getProjectSdkService","getArgvService","ui","projectSdk","yargsRunner","yargs","globalOptions","globalOption","name","config","invalidParamsMessage","error","process","args","v","logger","realError","ManuallyReportedError","argv","GracefulError","commands","command","startedAt","performance","definition","description","params","options","handler","traceRecorder","yargsCommand","paramVersionExists","p","param","paramName","required","validation","array","rest","yargsParam","option","yargsOption","getCliRunnerService","createImplementation","GetCliRunnerService","CommandsRegistryService","GlobalOptionsRegistryService","UiService","GetProjectSdkService","GetArgvService"],"mappings":";;;;;;;AAiBA,MAAM,EAAEA,IAAI,EAAEC,QAAQ,EAAEC,IAAI,EAAE,GAAGC;AAE1B,MAAMC;IACT,YACqBC,uBAA0D,EAC1DC,4BAAoE,EACpEC,SAA8B,EAC9BC,oBAAoD,EACpDC,cAAwC,CAC3D;aALmBJ,uBAAuB,GAAvBA;aACAC,4BAA4B,GAA5BA;aACAC,SAAS,GAATA;aACAC,oBAAoB,GAApBA;aACAC,cAAc,GAAdA;aAGb,WAAW,GAAgB;IAFhC;IAIH,MAAM,UAAU;QACZ,IAAI,IAAI,CAAC,WAAW,EAChB,OAAO,IAAI,CAAC,WAAW;QAG3B,MAAMC,KAAK,IAAI,CAAC,SAAS;QACzB,MAAMC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C;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -13,5 +13,23 @@ export declare class DefaultUiService implements UiService.Interface {
|
|
|
13
13
|
error(text: string, ...args: any[]): void;
|
|
14
14
|
debug(text: string, ...args: any[]): void;
|
|
15
15
|
private typedColorizedText;
|
|
16
|
+
/**
|
|
17
|
+
* Prefixes every line of `message` with the gutter, wrapping the text to the terminal width
|
|
18
|
+
* first.
|
|
19
|
+
*
|
|
20
|
+
* The wrap has to happen here rather than being left to the terminal. Writing the whole message
|
|
21
|
+
* as one long line means the terminal wraps it at column 0, with no knowledge of the gutter -
|
|
22
|
+
* so continuation lines start underneath the pipe instead of underneath the text, and a wrapped
|
|
23
|
+
* sentence reads as though it belongs to a different paragraph.
|
|
24
|
+
*/
|
|
25
|
+
private applyGutter;
|
|
26
|
+
/**
|
|
27
|
+
* Width available for the text itself, or `null` when there is nothing to wrap to.
|
|
28
|
+
*
|
|
29
|
+
* `columns` is undefined whenever stdout is not a TTY - piped to a file, or read by another
|
|
30
|
+
* process. Wrapping to a guessed width there would bake line breaks into output that something
|
|
31
|
+
* else is going to reflow anyway, so the message is left as a single line.
|
|
32
|
+
*/
|
|
33
|
+
private getTextWidth;
|
|
16
34
|
}
|
|
17
35
|
export declare const uiService: import("@webiny/di").Implementation<typeof DefaultUiService>;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { createImplementation } from "@webiny/di";
|
|
2
2
|
import chalk from "chalk";
|
|
3
3
|
import util from "util";
|
|
4
|
+
import wrap_ansi from "wrap-ansi";
|
|
4
5
|
import { IsCi, StdioService, UiService } from "../../abstractions/index.js";
|
|
5
6
|
const NEW_LINE = "\n";
|
|
6
7
|
const PIPE_SYMBOL = "┃";
|
|
8
|
+
const GUTTER_WIDTH = 2;
|
|
9
|
+
const MIN_TEXT_WIDTH = 20;
|
|
7
10
|
const LOG_COLORS = {
|
|
8
11
|
info: chalk.blueBright,
|
|
9
12
|
error: chalk.red,
|
|
@@ -49,9 +52,22 @@ class DefaultUiService {
|
|
|
49
52
|
const prefix = `${type}: `;
|
|
50
53
|
return this.text(prefix + util.format(text, ...args));
|
|
51
54
|
}
|
|
52
|
-
const
|
|
55
|
+
const gutter = `${LOG_COLORS[type](PIPE_SYMBOL)} `;
|
|
53
56
|
const textWithColorizedPlaceholders = text.replace(/%[a-zA-Z]/g, (match)=>LOG_COLORS[type](match));
|
|
54
|
-
|
|
57
|
+
const message = util.format(textWithColorizedPlaceholders, ...args);
|
|
58
|
+
return this.text(this.applyGutter(message, gutter));
|
|
59
|
+
}
|
|
60
|
+
applyGutter(message, gutter) {
|
|
61
|
+
const textWidth = this.getTextWidth();
|
|
62
|
+
const wrapped = textWidth ? wrap_ansi(message, textWidth, {
|
|
63
|
+
hard: true
|
|
64
|
+
}) : message;
|
|
65
|
+
return wrapped.split(NEW_LINE).map((line)=>gutter + line).join(NEW_LINE);
|
|
66
|
+
}
|
|
67
|
+
getTextWidth() {
|
|
68
|
+
const columns = this.stdio.getStdout().columns;
|
|
69
|
+
if (!columns) return null;
|
|
70
|
+
return Math.max(columns - GUTTER_WIDTH, MIN_TEXT_WIDTH);
|
|
55
71
|
}
|
|
56
72
|
}
|
|
57
73
|
const uiService = createImplementation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"services/UiService/UiService.js","sources":["../../../src/services/UiService/UiService.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport chalk from \"chalk\";\nimport util from \"util\";\nimport { UiService, StdioService, IsCi } from \"~/abstractions/index.js\";\n\nconst NEW_LINE = \"\\n\";\nconst PIPE_SYMBOL = \"┃\";\n\nconst LOG_COLORS = {\n info: chalk.blueBright,\n error: chalk.red,\n warning: chalk.yellow,\n success: chalk.green,\n debug: chalk.gray\n} as const;\n\nexport class DefaultUiService implements UiService.Interface {\n constructor(\n private readonly stdio: StdioService.Interface,\n private readonly isCi: IsCi.Interface\n ) {}\n\n raw(text: string) {\n this.stdio.getStdout().write(text);\n }\n\n text(text: string) {\n this.stdio.getStdout().write(text);\n this.stdio.getStdout().write(NEW_LINE);\n }\n\n textBold(text: string) {\n this.text(chalk.bold(text));\n }\n\n emptyLine() {\n this.stdio.getStdout().write(chalk.gray(\"∙\") + NEW_LINE);\n }\n\n // The following methods are used to print texts with a specific type prefix.\n success(text: string, ...args: any[]) {\n this.typedColorizedText(\"success\", text, ...args);\n }\n\n info(text: string, ...args: any[]) {\n this.typedColorizedText(\"info\", text, ...args);\n }\n\n warning(text: string, ...args: any[]) {\n this.typedColorizedText(\"warning\", text, ...args);\n }\n\n error(text: string, ...args: any[]) {\n this.typedColorizedText(\"error\", text, ...args);\n }\n\n debug(text: string, ...args: any[]) {\n this.typedColorizedText(\"debug\", text, ...args);\n }\n\n private typedColorizedText(type: keyof typeof LOG_COLORS, text: string, ...args: any[]) {\n // Use plain text format in CI environments.\n if (this.isCi.execute()) {\n const prefix = `${type}: `;\n return this.text(prefix + util.format(text, ...args));\n }\n\n const
|
|
1
|
+
{"version":3,"file":"services/UiService/UiService.js","sources":["../../../src/services/UiService/UiService.ts"],"sourcesContent":["import { createImplementation } from \"@webiny/di\";\nimport chalk from \"chalk\";\nimport util from \"util\";\nimport wrapAnsi from \"wrap-ansi\";\nimport { UiService, StdioService, IsCi } from \"~/abstractions/index.js\";\n\nconst NEW_LINE = \"\\n\";\nconst PIPE_SYMBOL = \"┃\";\n\n// Visible width of the `┃ ` gutter that prefixes every line of a typed message. Hardcoded rather\n// than measured because the pipe is a single-column glyph and the colour codes around it occupy no\n// columns at all.\nconst GUTTER_WIDTH = 2;\n\n// A floor for very narrow terminals, so the wrap width can never go to zero or negative.\nconst MIN_TEXT_WIDTH = 20;\n\nconst LOG_COLORS = {\n info: chalk.blueBright,\n error: chalk.red,\n warning: chalk.yellow,\n success: chalk.green,\n debug: chalk.gray\n} as const;\n\nexport class DefaultUiService implements UiService.Interface {\n constructor(\n private readonly stdio: StdioService.Interface,\n private readonly isCi: IsCi.Interface\n ) {}\n\n raw(text: string) {\n this.stdio.getStdout().write(text);\n }\n\n text(text: string) {\n this.stdio.getStdout().write(text);\n this.stdio.getStdout().write(NEW_LINE);\n }\n\n textBold(text: string) {\n this.text(chalk.bold(text));\n }\n\n emptyLine() {\n this.stdio.getStdout().write(chalk.gray(\"∙\") + NEW_LINE);\n }\n\n // The following methods are used to print texts with a specific type prefix.\n success(text: string, ...args: any[]) {\n this.typedColorizedText(\"success\", text, ...args);\n }\n\n info(text: string, ...args: any[]) {\n this.typedColorizedText(\"info\", text, ...args);\n }\n\n warning(text: string, ...args: any[]) {\n this.typedColorizedText(\"warning\", text, ...args);\n }\n\n error(text: string, ...args: any[]) {\n this.typedColorizedText(\"error\", text, ...args);\n }\n\n debug(text: string, ...args: any[]) {\n this.typedColorizedText(\"debug\", text, ...args);\n }\n\n private typedColorizedText(type: keyof typeof LOG_COLORS, text: string, ...args: any[]) {\n // Use plain text format in CI environments.\n if (this.isCi.execute()) {\n const prefix = `${type}: `;\n return this.text(prefix + util.format(text, ...args));\n }\n\n const gutter = `${LOG_COLORS[type](PIPE_SYMBOL)} `;\n\n // Replace all placeholders (match with `/%[a-zA-Z]/g` regex) with colorized values.\n const textWithColorizedPlaceholders = text.replace(/%[a-zA-Z]/g, match => {\n return LOG_COLORS[type](match);\n });\n\n const message = util.format(textWithColorizedPlaceholders, ...args);\n\n return this.text(this.applyGutter(message, gutter));\n }\n\n /**\n * Prefixes every line of `message` with the gutter, wrapping the text to the terminal width\n * first.\n *\n * The wrap has to happen here rather than being left to the terminal. Writing the whole message\n * as one long line means the terminal wraps it at column 0, with no knowledge of the gutter -\n * so continuation lines start underneath the pipe instead of underneath the text, and a wrapped\n * sentence reads as though it belongs to a different paragraph.\n */\n private applyGutter(message: string, gutter: string) {\n const textWidth = this.getTextWidth();\n\n // `hard` also breaks words longer than a whole line - a long file path, or a URL. Letting\n // those overflow would hand them straight back to the terminal's own wrapping, which is\n // the column-0 behaviour this method exists to avoid.\n const wrapped = textWidth ? wrapAnsi(message, textWidth, { hard: true }) : message;\n\n return wrapped\n .split(NEW_LINE)\n .map(line => gutter + line)\n .join(NEW_LINE);\n }\n\n /**\n * Width available for the text itself, or `null` when there is nothing to wrap to.\n *\n * `columns` is undefined whenever stdout is not a TTY - piped to a file, or read by another\n * process. Wrapping to a guessed width there would bake line breaks into output that something\n * else is going to reflow anyway, so the message is left as a single line.\n */\n private getTextWidth() {\n const columns = this.stdio.getStdout().columns;\n if (!columns) {\n return null;\n }\n\n return Math.max(columns - GUTTER_WIDTH, MIN_TEXT_WIDTH);\n }\n}\n\nexport const uiService = createImplementation({\n abstraction: UiService,\n implementation: DefaultUiService,\n dependencies: [StdioService, IsCi]\n});\n"],"names":["NEW_LINE","PIPE_SYMBOL","GUTTER_WIDTH","MIN_TEXT_WIDTH","LOG_COLORS","chalk","DefaultUiService","stdio","isCi","text","args","type","prefix","util","gutter","textWithColorizedPlaceholders","match","message","textWidth","wrapped","wrapAnsi","line","columns","Math","uiService","createImplementation","UiService","StdioService","IsCi"],"mappings":";;;;;AAMA,MAAMA,WAAW;AACjB,MAAMC,cAAc;AAKpB,MAAMC,eAAe;AAGrB,MAAMC,iBAAiB;AAEvB,MAAMC,aAAa;IACf,MAAMC,MAAM,UAAU;IACtB,OAAOA,MAAM,GAAG;IAChB,SAASA,MAAM,MAAM;IACrB,SAASA,MAAM,KAAK;IACpB,OAAOA,MAAM,IAAI;AACrB;AAEO,MAAMC;IACT,YACqBC,KAA6B,EAC7BC,IAAoB,CACvC;aAFmBD,KAAK,GAALA;aACAC,IAAI,GAAJA;IAClB;IAEH,IAAIC,IAAY,EAAE;QACd,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,KAAK,CAACA;IACjC;IAEA,KAAKA,IAAY,EAAE;QACf,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,KAAK,CAACA;QAC7B,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,KAAK,CAACT;IACjC;IAEA,SAASS,IAAY,EAAE;QACnB,IAAI,CAAC,IAAI,CAACJ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SAASC,WAAW;YAAE,MAAM;QAAK,KAAKD;QAE3E,OAAOE,QACF,KAAK,CAACnB,UACN,GAAG,CAACqB,CAAAA,OAAQP,SAASO,MACrB,IAAI,CAACrB;IACd;IASQ,eAAe;QACnB,MAAMsB,UAAU,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,OAAO;QAC9C,IAAI,CAACA,SACD,OAAO;QAGX,OAAOC,KAAK,GAAG,CAACD,UAAUpB,cAAcC;IAC5C;AACJ;AAEO,MAAMqB,YAAYC,qBAAqB;IAC1C,aAAaC;IACb,gBAAgBpB;IAChB,cAAc;QAACqB;QAAcC;KAAK;AACtC"}
|
|
@@ -1,32 +1,21 @@
|
|
|
1
|
-
import { execaSync } from "execa";
|
|
2
1
|
import chalk from "chalk";
|
|
2
|
+
import { getCacheFilePath } from "./getCacheFilePath.js";
|
|
3
|
+
import { hashYarnLock } from "./hashYarnLock.js";
|
|
4
|
+
import { listWebinyPackageVersions } from "./listWebinyPackageVersions.js";
|
|
5
|
+
import { readClearedYarnLockHash } from "./readClearedYarnLockHash.js";
|
|
6
|
+
import { writeClearedYarnLockHash } from "./writeClearedYarnLockHash.js";
|
|
3
7
|
const DEBUG_FLAG = "--debug";
|
|
4
8
|
const usingDebugFlag = process.argv.includes(DEBUG_FLAG);
|
|
5
9
|
const SKIP_WEBINY_VERSIONS_CHECK_FLAG = "--no-package-versions-check";
|
|
6
10
|
const skippingWebinyVersionsCheck = process.argv.includes(SKIP_WEBINY_VERSIONS_CHECK_FLAG);
|
|
7
|
-
const listWebinyPackageVersions = ()=>{
|
|
8
|
-
const { stdout } = execaSync("yarn", [
|
|
9
|
-
"info",
|
|
10
|
-
"@webiny/*",
|
|
11
|
-
"--name-only",
|
|
12
|
-
"--all",
|
|
13
|
-
"--json"
|
|
14
|
-
], {
|
|
15
|
-
encoding: "utf8"
|
|
16
|
-
});
|
|
17
|
-
const lines = stdout.trim().split("\n").map((line)=>JSON.parse(line));
|
|
18
|
-
const versionMap = new Map();
|
|
19
|
-
for (const entry of lines){
|
|
20
|
-
const match = entry.match(/^(@webiny\/[^@]+)@npm:(.+)$/);
|
|
21
|
-
if (!match) continue;
|
|
22
|
-
const [, pkg, version] = match;
|
|
23
|
-
if (!versionMap.has(pkg)) versionMap.set(pkg, new Set());
|
|
24
|
-
versionMap.get(pkg).add(version);
|
|
25
|
-
}
|
|
26
|
-
return versionMap;
|
|
27
|
-
};
|
|
28
11
|
const ensureSameWebinyPackageVersions = ()=>{
|
|
29
12
|
if (skippingWebinyVersionsCheck) return;
|
|
13
|
+
const cacheFilePath = getCacheFilePath();
|
|
14
|
+
const yarnLockHash = hashYarnLock();
|
|
15
|
+
if (cacheFilePath && yarnLockHash) {
|
|
16
|
+
const clearedYarnLockHash = readClearedYarnLockHash(cacheFilePath);
|
|
17
|
+
if (clearedYarnLockHash === yarnLockHash) return;
|
|
18
|
+
}
|
|
30
19
|
let webinyVersions;
|
|
31
20
|
try {
|
|
32
21
|
webinyVersions = listWebinyPackageVersions();
|
|
@@ -57,6 +46,7 @@ const ensureSameWebinyPackageVersions = ()=>{
|
|
|
57
46
|
console.error(chalk.red(message.join("\n")));
|
|
58
47
|
process.exit(1);
|
|
59
48
|
}
|
|
49
|
+
if (cacheFilePath && yarnLockHash) writeClearedYarnLockHash(cacheFilePath, yarnLockHash);
|
|
60
50
|
};
|
|
61
51
|
export { ensureSameWebinyPackageVersions };
|
|
62
52
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils/ensureSameWebinyPackageVersions/ensureSameWebinyPackageVersions.js","sources":["../../../src/utils/ensureSameWebinyPackageVersions/ensureSameWebinyPackageVersions.ts"],"sourcesContent":["import chalk from \"chalk\";\nimport { getCacheFilePath } from \"./getCacheFilePath.js\";\nimport { hashYarnLock } from \"./hashYarnLock.js\";\nimport { listWebinyPackageVersions } from \"./listWebinyPackageVersions.js\";\nimport { readClearedYarnLockHash } from \"./readClearedYarnLockHash.js\";\nimport { writeClearedYarnLockHash } from \"./writeClearedYarnLockHash.js\";\n\nconst DEBUG_FLAG = \"--debug\";\nconst usingDebugFlag = process.argv.includes(DEBUG_FLAG);\n\nconst SKIP_WEBINY_VERSIONS_CHECK_FLAG = \"--no-package-versions-check\";\nconst skippingWebinyVersionsCheck = process.argv.includes(SKIP_WEBINY_VERSIONS_CHECK_FLAG);\n\n/*\n * Two `@webiny/*` packages on different versions in one install produce failures that are hard to\n * read, so the CLI refuses to start on a mismatch. The check runs on every invocation and the `yarn\n * info` call behind it is slow, so a pass is remembered against the lockfile hash and skipped while\n * that hash holds.\n *\n * Only a pass is cached. A failed `yarn info` warns and returns, and a mismatch exits, so neither\n * writes the file and the next run checks again.\n */\nexport const ensureSameWebinyPackageVersions = (): void => {\n // Just in case, we want to allow users to skip the check.\n if (skippingWebinyVersionsCheck) {\n return;\n }\n\n const cacheFilePath = getCacheFilePath();\n const yarnLockHash = hashYarnLock();\n\n if (cacheFilePath && yarnLockHash) {\n const clearedYarnLockHash = readClearedYarnLockHash(cacheFilePath);\n if (clearedYarnLockHash === yarnLockHash) {\n return;\n }\n }\n\n let webinyVersions: Map<string, Set<string>>;\n try {\n webinyVersions = listWebinyPackageVersions();\n } catch (e) {\n const message = [\"Failed to inspect Webiny package versions.\"];\n\n if (!usingDebugFlag) {\n message.push(`For more information, try running with ${chalk.yellow(DEBUG_FLAG)}.`);\n }\n\n message.push(\"Learn more: https://webiny.link/webiny-package-versions-check\");\n\n console.warn(chalk.yellow(message.join(\" \")));\n if (usingDebugFlag) {\n console.warn(e);\n }\n\n console.log();\n return;\n }\n\n const mismatchedPackages: Array<[string, Set<string>]> = [];\n for (const [pkg, versions] of webinyVersions.entries()) {\n if (versions.size > 1) {\n mismatchedPackages.push([pkg, versions]);\n }\n }\n\n if (mismatchedPackages.length > 0) {\n const message = [\n \"The following Webiny packages have mismatched versions:\",\n \"\",\n ...mismatchedPackages.map(([pkg, versions]) => {\n return `‣ ${pkg}: ${Array.from(versions).join(\", \")}`;\n }),\n \"\",\n `Please ensure all Webiny packages are using the same version. If you think this is a mistake, you can also skip this check by appending the ${chalk.red(\n SKIP_WEBINY_VERSIONS_CHECK_FLAG\n )} flag. Learn more: https://webiny.link/webiny-package-versions-check`\n ];\n\n console.error(chalk.red(message.join(\"\\n\")));\n process.exit(1);\n }\n\n if (cacheFilePath && yarnLockHash) {\n writeClearedYarnLockHash(cacheFilePath, yarnLockHash);\n }\n};\n"],"names":["DEBUG_FLAG","usingDebugFlag","process","SKIP_WEBINY_VERSIONS_CHECK_FLAG","skippingWebinyVersionsCheck","ensureSameWebinyPackageVersions","cacheFilePath","getCacheFilePath","yarnLockHash","hashYarnLock","clearedYarnLockHash","readClearedYarnLockHash","webinyVersions","listWebinyPackageVersions","e","message","chalk","console","mismatchedPackages","pkg","versions","Array","writeClearedYarnLockHash"],"mappings":";;;;;;AAOA,MAAMA,aAAa;AACnB,MAAMC,iBAAiBC,QAAQ,IAAI,CAAC,QAAQ,CAACF;AAE7C,MAAMG,kCAAkC;AACxC,MAAMC,8BAA8BF,QAAQ,IAAI,CAAC,QAAQ,CAACC;AAWnD,MAAME,kCAAkC;IAE3C,IAAID,6BACA;IAGJ,MAAME,gBAAgBC;IACtB,MAAMC,eAAeC;IAErB,IAAIH,iBAAiBE,cAAc;QAC/B,MAAME,sBAAsBC,wBAAwBL;QACpD,IAAII,wBAAwBF,cACxB;IAER;IAEA,IAAII;IACJ,IAAI;QACAA,iBAAiBC;IACrB,EAAE,OAAOC,GAAG;QACR,MAAMC,UAAU;YAAC;SAA6C;QAE9D,IAAI,CAACd,gBACDc,QAAQ,IAAI,CAAC,CAAC,uCAAuC,EAAEC,MAAM,MAAM,CAAChB,YAAY,CAAC,CAAC;QAGtFe,QAAQ,IAAI,CAAC;QAEbE,QAAQ,IAAI,CAACD,MAAM,MAAM,CAACD,QAAQ,IAAI,CAAC;QACvC,IAAId,gBACAgB,QAAQ,IAAI,CAACH;QAGjBG,QAAQ,GAAG;QACX;IACJ;IAEA,MAAMC,qBAAmD,EAAE;IAC3D,KAAK,MAAM,CAACC,KAAKC,SAAS,IAAIR,eAAe,OAAO,GAChD,IAAIQ,SAAS,IAAI,GAAG,GAChBF,mBAAmB,IAAI,CAAC;QAACC;QAAKC;KAAS;IAI/C,IAAIF,mBAAmB,MAAM,GAAG,GAAG;QAC/B,MAAMH,UAAU;YACZ;YACA;eACGG,mBAAmB,GAAG,CAAC,CAAC,CAACC,KAAKC,SAAS,GAC/B,CAAC,EAAE,EAAED,IAAI,EAAE,EAAEE,MAAM,IAAI,CAACD,UAAU,IAAI,CAAC,OAAO;YAEzD;YACA,CAAC,4IAA4I,EAAEJ,MAAM,GAAG,CACpJb,iCACF,oEAAoE,CAAC;SAC1E;QAEDc,QAAQ,KAAK,CAACD,MAAM,GAAG,CAACD,QAAQ,IAAI,CAAC;QACrCb,QAAQ,IAAI,CAAC;IACjB;IAEA,IAAII,iBAAiBE,cACjBc,yBAAyBhB,eAAeE;AAEhD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getCacheFilePath: () => string | null;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { findUpSync } from "find-up";
|
|
3
|
+
const CACHE_FILE_NAME = "package-versions-check.json";
|
|
4
|
+
const getCacheFilePath = ()=>{
|
|
5
|
+
const webinyConfigFilePath = findUpSync("webiny.config.tsx");
|
|
6
|
+
if (!webinyConfigFilePath) return null;
|
|
7
|
+
const projectRootFolderPath = path.dirname(webinyConfigFilePath);
|
|
8
|
+
return path.join(projectRootFolderPath, ".webiny", CACHE_FILE_NAME);
|
|
9
|
+
};
|
|
10
|
+
export { getCacheFilePath };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=getCacheFilePath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils/ensureSameWebinyPackageVersions/getCacheFilePath.js","sources":["../../../src/utils/ensureSameWebinyPackageVersions/getCacheFilePath.ts"],"sourcesContent":["import path from \"path\";\nimport { findUpSync } from \"find-up\";\n\nconst CACHE_FILE_NAME = \"package-versions-check.json\";\n\n/*\n * Locates `.webiny/package-versions-check.json` for the project the CLI was invoked in.\n *\n * The version check runs before the CLI has a DI container, so this cannot go through\n * `LocalStorageService`. It finds the project root the same way `GetProjectService` does, by walking\n * up to `webiny.config.tsx`, so both agree on which project is being written to. Returns null outside\n * a project, where there is nowhere to cache.\n */\nexport const getCacheFilePath = (): string | null => {\n const webinyConfigFilePath = findUpSync(\"webiny.config.tsx\");\n if (!webinyConfigFilePath) {\n return null;\n }\n\n const projectRootFolderPath = path.dirname(webinyConfigFilePath);\n\n return path.join(projectRootFolderPath, \".webiny\", CACHE_FILE_NAME);\n};\n"],"names":["CACHE_FILE_NAME","getCacheFilePath","webinyConfigFilePath","findUpSync","projectRootFolderPath","path"],"mappings":";;AAGA,MAAMA,kBAAkB;AAUjB,MAAMC,mBAAmB;IAC5B,MAAMC,uBAAuBC,WAAW;IACxC,IAAI,CAACD,sBACD,OAAO;IAGX,MAAME,wBAAwBC,KAAK,OAAO,CAACH;IAE3C,OAAOG,KAAK,IAAI,CAACD,uBAAuB,WAAWJ;AACvD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const hashYarnLock: () => string | null;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import crypto_0 from "crypto";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import { findUpSync } from "find-up";
|
|
4
|
+
const hashYarnLock = ()=>{
|
|
5
|
+
const yarnLockFilePath = findUpSync("yarn.lock");
|
|
6
|
+
if (!yarnLockFilePath) return null;
|
|
7
|
+
try {
|
|
8
|
+
const contents = fs.readFileSync(yarnLockFilePath);
|
|
9
|
+
return crypto_0.createHash("sha1").update(contents).digest("hex");
|
|
10
|
+
} catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
export { hashYarnLock };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=hashYarnLock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils/ensureSameWebinyPackageVersions/hashYarnLock.js","sources":["../../../src/utils/ensureSameWebinyPackageVersions/hashYarnLock.ts"],"sourcesContent":["import crypto from \"crypto\";\nimport fs from \"fs\";\nimport { findUpSync } from \"find-up\";\n\n/*\n * Hashes the lockfile, which is what keys the cached result of the version check.\n *\n * `yarn info` resolves from the install state, so its answer can only change when `yarn.lock` does.\n * That makes the lockfile hash a faithful key: a manifest edit that has not been installed yet cannot\n * change what the check sees.\n *\n * Returns null when there is no lockfile, and also when one exists but cannot be read, which happens\n * if an install is rewriting it. Callers treat null as a cache miss, because the cache exists to skip\n * work and must never be the reason the CLI fails to start.\n */\nexport const hashYarnLock = (): string | null => {\n const yarnLockFilePath = findUpSync(\"yarn.lock\");\n if (!yarnLockFilePath) {\n return null;\n }\n\n try {\n const contents = fs.readFileSync(yarnLockFilePath);\n\n return crypto.createHash(\"sha1\").update(contents).digest(\"hex\");\n } catch {\n return null;\n }\n};\n"],"names":["hashYarnLock","yarnLockFilePath","findUpSync","contents","fs","crypto"],"mappings":";;;AAeO,MAAMA,eAAe;IACxB,MAAMC,mBAAmBC,WAAW;IACpC,IAAI,CAACD,kBACD,OAAO;IAGX,IAAI;QACA,MAAME,WAAWC,GAAG,YAAY,CAACH;QAEjC,OAAOI,SAAAA,UAAiB,CAAC,QAAQ,MAAM,CAACF,UAAU,MAAM,CAAC;IAC7D,EAAE,OAAM;QACJ,OAAO;IACX;AACJ"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./ensureSameWebinyPackageVersions.js";
|
|
2
|
+
export * from "./getCacheFilePath.js";
|
|
3
|
+
export * from "./hashYarnLock.js";
|
|
4
|
+
export * from "./listWebinyPackageVersions.js";
|
|
5
|
+
export * from "./readClearedYarnLockHash.js";
|
|
6
|
+
export * from "./writeClearedYarnLockHash.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./ensureSameWebinyPackageVersions.js";
|
|
2
|
+
export * from "./getCacheFilePath.js";
|
|
3
|
+
export * from "./hashYarnLock.js";
|
|
4
|
+
export * from "./listWebinyPackageVersions.js";
|
|
5
|
+
export * from "./readClearedYarnLockHash.js";
|
|
6
|
+
export * from "./writeClearedYarnLockHash.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const listWebinyPackageVersions: () => Map<string, Set<string>>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { execaSync } from "execa";
|
|
2
|
+
const listWebinyPackageVersions = ()=>{
|
|
3
|
+
const patterns = [
|
|
4
|
+
"@webiny/*",
|
|
5
|
+
"webiny"
|
|
6
|
+
];
|
|
7
|
+
const args = [
|
|
8
|
+
"info",
|
|
9
|
+
...patterns,
|
|
10
|
+
"--name-only",
|
|
11
|
+
"--all",
|
|
12
|
+
"--recursive",
|
|
13
|
+
"--json"
|
|
14
|
+
];
|
|
15
|
+
const { stdout } = execaSync("yarn", args, {
|
|
16
|
+
encoding: "utf8"
|
|
17
|
+
});
|
|
18
|
+
const lines = stdout.trim().split("\n").map((line)=>JSON.parse(line));
|
|
19
|
+
const versionMap = new Map();
|
|
20
|
+
for (const entry of lines){
|
|
21
|
+
const match = entry.match(/^(webiny|@webiny\/[^@]+)@npm:(.+)$/);
|
|
22
|
+
if (!match) continue;
|
|
23
|
+
const [, pkg, version] = match;
|
|
24
|
+
if (!versionMap.has(pkg)) versionMap.set(pkg, new Set());
|
|
25
|
+
versionMap.get(pkg).add(version);
|
|
26
|
+
}
|
|
27
|
+
return versionMap;
|
|
28
|
+
};
|
|
29
|
+
export { listWebinyPackageVersions };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=listWebinyPackageVersions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils/ensureSameWebinyPackageVersions/listWebinyPackageVersions.js","sources":["../../../src/utils/ensureSameWebinyPackageVersions/listWebinyPackageVersions.ts"],"sourcesContent":["import { execaSync } from \"execa\";\n\n/*\n * Asks yarn which versions of each Webiny package the install resolved to, keyed by package name.\n * More than one version in a set is the mismatch the check is looking for.\n *\n * Both patterns are needed. `@webiny/*` covers the scoped packages, and `webiny` covers the unscoped\n * umbrella package, which is the one a generated project actually depends on: `template.package.json`\n * ships `webiny` and `@webiny/mcp` and nothing else. A scoped-only glob leaves the single most\n * important package in a user's project out of the comparison.\n *\n * `--recursive` is what makes this work outside this monorepo. `--all` on its own reports only the\n * direct dependencies of the workspaces, and in a generated project the only direct Webiny\n * dependencies are `webiny` and `@webiny/mcp`; every scoped package is transitive underneath them.\n * Without it the check would compare two packages and call that a pass. It costs nothing measurable,\n * and in this repo the two flags return the same set because every package here is a workspace.\n *\n * This is the expensive call the cache exists to avoid: it takes the better part of a second in a\n * project of any size.\n */\nexport const listWebinyPackageVersions = (): Map<string, Set<string>> => {\n const patterns = [\"@webiny/*\", \"webiny\"];\n const args = [\"info\", ...patterns, \"--name-only\", \"--all\", \"--recursive\", \"--json\"];\n\n const { stdout } = execaSync(\"yarn\", args, {\n encoding: \"utf8\"\n });\n\n // Each line is a JSON string, so parse them individually.\n const lines = stdout\n .trim()\n .split(\"\\n\")\n .map(line => JSON.parse(line) as string);\n\n const versionMap = new Map<string, Set<string>>();\n\n for (const entry of lines) {\n // Example entries: \"@webiny/cli@npm:5.42.3\" and \"webiny@npm:5.42.3\". Anything resolved to\n // something other than npm, a workspace in this repo for instance, has no version to compare.\n const match = entry.match(/^(webiny|@webiny\\/[^@]+)@npm:(.+)$/);\n if (!match) {\n continue;\n }\n\n const [, pkg, version] = match;\n if (!versionMap.has(pkg)) {\n versionMap.set(pkg, new Set());\n }\n\n versionMap.get(pkg)!.add(version);\n }\n\n return versionMap;\n};\n"],"names":["listWebinyPackageVersions","patterns","args","stdout","execaSync","lines","line","JSON","versionMap","Map","entry","match","pkg","version","Set"],"mappings":";AAoBO,MAAMA,4BAA4B;IACrC,MAAMC,WAAW;QAAC;QAAa;KAAS;IACxC,MAAMC,OAAO;QAAC;WAAWD;QAAU;QAAe;QAAS;QAAe;KAAS;IAEnF,MAAM,EAAEE,MAAM,EAAE,GAAGC,UAAU,QAAQF,MAAM;QACvC,UAAU;IACd;IAGA,MAAMG,QAAQF,OACT,IAAI,GACJ,KAAK,CAAC,MACN,GAAG,CAACG,CAAAA,OAAQC,KAAK,KAAK,CAACD;IAE5B,MAAME,aAAa,IAAIC;IAEvB,KAAK,MAAMC,SAASL,MAAO;QAGvB,MAAMM,QAAQD,MAAM,KAAK,CAAC;QAC1B,IAAI,CAACC,OACD;QAGJ,MAAM,GAAGC,KAAKC,QAAQ,GAAGF;QACzB,IAAI,CAACH,WAAW,GAAG,CAACI,MAChBJ,WAAW,GAAG,CAACI,KAAK,IAAIE;QAG5BN,WAAW,GAAG,CAACI,KAAM,GAAG,CAACC;IAC7B;IAEA,OAAOL;AACX"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const readClearedYarnLockHash: (cacheFilePath: string) => string | null;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
const readClearedYarnLockHash = (cacheFilePath)=>{
|
|
3
|
+
try {
|
|
4
|
+
const contents = fs.readFileSync(cacheFilePath, "utf8");
|
|
5
|
+
const cache = JSON.parse(contents);
|
|
6
|
+
return cache.yarnLockHash ?? null;
|
|
7
|
+
} catch {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
export { readClearedYarnLockHash };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=readClearedYarnLockHash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils/ensureSameWebinyPackageVersions/readClearedYarnLockHash.js","sources":["../../../src/utils/ensureSameWebinyPackageVersions/readClearedYarnLockHash.ts"],"sourcesContent":["import fs from \"fs\";\n\n/*\n * Reads the lockfile hash recorded the last time the version check passed. Null means \"no usable\n * record\", covering a first run, a deleted cache and a file we cannot read or parse, all of which\n * should simply run the check again.\n */\nexport const readClearedYarnLockHash = (cacheFilePath: string): string | null => {\n try {\n const contents = fs.readFileSync(cacheFilePath, \"utf8\");\n const cache = JSON.parse(contents) as { yarnLockHash?: string };\n\n return cache.yarnLockHash ?? null;\n } catch {\n return null;\n }\n};\n"],"names":["readClearedYarnLockHash","cacheFilePath","contents","fs","cache","JSON"],"mappings":";AAOO,MAAMA,0BAA0B,CAACC;IACpC,IAAI;QACA,MAAMC,WAAWC,GAAG,YAAY,CAACF,eAAe;QAChD,MAAMG,QAAQC,KAAK,KAAK,CAACH;QAEzB,OAAOE,MAAM,YAAY,IAAI;IACjC,EAAE,OAAM;QACJ,OAAO;IACX;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const writeClearedYarnLockHash: (cacheFilePath: string, yarnLockHash: string) => void;
|