@adobe/aio-commerce-lib-app 0.3.0 → 0.3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @adobe/aio-commerce-lib-app
2
2
 
3
+ ## 0.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#260](https://github.com/adobe/aio-commerce-sdk/pull/260) [`dbfb82f`](https://github.com/adobe/aio-commerce-sdk/commit/dbfb82fe4af72fe760df005506bec9f9927bbafc) Thanks [@iivvaannxx](https://github.com/iivvaannxx)! - Fix package json detection/creation on `init` script
8
+
3
9
  ## 0.3.0
4
10
 
5
11
  ### Minor Changes
@@ -895,8 +895,7 @@ async function ensureCommerceAppConfig(cwd = process.cwd()) {
895
895
  }
896
896
  }
897
897
  /** Ensure package.json has the postinstall script */
898
- async function ensurePackageJson(execCommand, cwd = process.cwd()) {
899
- const postinstallScript = `${execCommand} aio-commerce-lib-app hooks postinstall`;
898
+ async function ensurePackageJson(cwd = process.cwd()) {
900
899
  const packageJson = await require_config.readPackageJson(cwd);
901
900
  if (!packageJson) {
902
901
  consola.consola.warn("package.json not found. Creating one...");
@@ -904,16 +903,27 @@ async function ensurePackageJson(execCommand, cwd = process.cwd()) {
904
903
  name: "my-commerce-app",
905
904
  version: "1.0.0",
906
905
  private: true,
907
- scripts: { postinstall: postinstallScript }
906
+ scripts: { postinstall: "npx aio-commerce-lib-app hooks postinstall" }
908
907
  };
909
908
  await (0, fs_promises.writeFile)((0, path.join)((0, path.resolve)(cwd), PACKAGE_JSON_FILE), JSON.stringify(packageJsonContent, null, 2), "utf-8");
910
909
  consola.consola.success("Wrote package.json");
911
- return packageJsonContent;
910
+ return {
911
+ packageJson: packageJsonContent,
912
+ packageManager: "npm",
913
+ execCommand: "npx"
914
+ };
912
915
  }
916
+ const packageManager = await require_config.detectPackageManager();
917
+ const execCommand = require_config.getExecCommand(packageManager);
918
+ const postinstallScript = `${execCommand} aio-commerce-lib-app hooks postinstall`;
913
919
  packageJson.scripts ??= {};
914
920
  if (packageJson.scripts.postinstall === postinstallScript || packageJson.scripts.postinstall?.includes(postinstallScript)) {
915
921
  consola.consola.success(`postinstall script already configured in ${PACKAGE_JSON_FILE}`);
916
- return packageJson;
922
+ return {
923
+ packageJson,
924
+ packageManager,
925
+ execCommand
926
+ };
917
927
  }
918
928
  if (packageJson.scripts.postinstall) {
919
929
  consola.consola.warn(`${PACKAGE_JSON_FILE} already has a postinstall script. Adding a new one...`);
@@ -923,7 +933,11 @@ async function ensurePackageJson(execCommand, cwd = process.cwd()) {
923
933
  (0, child_process.execSync)(`npm pkg set scripts.postinstall="${postinstallScript}"`);
924
934
  }
925
935
  consola.consola.success(`Added postinstall script to ${PACKAGE_JSON_FILE}`);
926
- return packageJson;
936
+ return {
937
+ packageJson,
938
+ packageManager,
939
+ execCommand
940
+ };
927
941
  }
928
942
  /** Ensure app.config.yaml has the extension reference */
929
943
  async function ensureAppConfig(domains, cwd = process.cwd()) {
@@ -975,9 +989,7 @@ async function ensureInstallYaml(domains, cwd = process.cwd()) {
975
989
  async function exec() {
976
990
  try {
977
991
  consola.consola.start("Initializing app...");
978
- const packageManager = await require_config.detectPackageManager();
979
- const execCommand = require_config.getExecCommand(packageManager);
980
- await ensurePackageJson(execCommand);
992
+ const { execCommand, packageManager } = await ensurePackageJson();
981
993
  const { config: config$1, domains } = await ensureCommerceAppConfig();
982
994
  (0, child_process.execSync)(`npm pkg set name="${config$1.metadata.id}"`);
983
995
  (0, child_process.execSync)(`npm pkg set version="${config$1.metadata.version}"`);
@@ -889,8 +889,7 @@ async function ensureCommerceAppConfig(cwd = process.cwd()) {
889
889
  }
890
890
  }
891
891
  /** Ensure package.json has the postinstall script */
892
- async function ensurePackageJson(execCommand, cwd = process.cwd()) {
893
- const postinstallScript = `${execCommand} aio-commerce-lib-app hooks postinstall`;
892
+ async function ensurePackageJson(cwd = process.cwd()) {
894
893
  const packageJson = await readPackageJson(cwd);
895
894
  if (!packageJson) {
896
895
  consola$1.warn("package.json not found. Creating one...");
@@ -898,16 +897,27 @@ async function ensurePackageJson(execCommand, cwd = process.cwd()) {
898
897
  name: "my-commerce-app",
899
898
  version: "1.0.0",
900
899
  private: true,
901
- scripts: { postinstall: postinstallScript }
900
+ scripts: { postinstall: "npx aio-commerce-lib-app hooks postinstall" }
902
901
  };
903
902
  await writeFile(join(resolve(cwd), PACKAGE_JSON_FILE), JSON.stringify(packageJsonContent, null, 2), "utf-8");
904
903
  consola$1.success("Wrote package.json");
905
- return packageJsonContent;
904
+ return {
905
+ packageJson: packageJsonContent,
906
+ packageManager: "npm",
907
+ execCommand: "npx"
908
+ };
906
909
  }
910
+ const packageManager = await detectPackageManager();
911
+ const execCommand = getExecCommand(packageManager);
912
+ const postinstallScript = `${execCommand} aio-commerce-lib-app hooks postinstall`;
907
913
  packageJson.scripts ??= {};
908
914
  if (packageJson.scripts.postinstall === postinstallScript || packageJson.scripts.postinstall?.includes(postinstallScript)) {
909
915
  consola$1.success(`postinstall script already configured in ${PACKAGE_JSON_FILE}`);
910
- return packageJson;
916
+ return {
917
+ packageJson,
918
+ packageManager,
919
+ execCommand
920
+ };
911
921
  }
912
922
  if (packageJson.scripts.postinstall) {
913
923
  consola$1.warn(`${PACKAGE_JSON_FILE} already has a postinstall script. Adding a new one...`);
@@ -917,7 +927,11 @@ async function ensurePackageJson(execCommand, cwd = process.cwd()) {
917
927
  execSync(`npm pkg set scripts.postinstall="${postinstallScript}"`);
918
928
  }
919
929
  consola$1.success(`Added postinstall script to ${PACKAGE_JSON_FILE}`);
920
- return packageJson;
930
+ return {
931
+ packageJson,
932
+ packageManager,
933
+ execCommand
934
+ };
921
935
  }
922
936
  /** Ensure app.config.yaml has the extension reference */
923
937
  async function ensureAppConfig(domains, cwd = process.cwd()) {
@@ -969,9 +983,7 @@ async function ensureInstallYaml(domains, cwd = process.cwd()) {
969
983
  async function exec() {
970
984
  try {
971
985
  consola$1.start("Initializing app...");
972
- const packageManager = await detectPackageManager();
973
- const execCommand = getExecCommand(packageManager);
974
- await ensurePackageJson(execCommand);
986
+ const { execCommand, packageManager } = await ensurePackageJson();
975
987
  const { config: config$1, domains } = await ensureCommerceAppConfig();
976
988
  execSync(`npm pkg set name="${config$1.metadata.id}"`);
977
989
  execSync(`npm pkg set version="${config$1.metadata.version}"`);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@adobe/aio-commerce-lib-app",
3
3
  "type": "module",
4
4
  "author": "Adobe Inc.",
5
- "version": "0.3.0",
5
+ "version": "0.3.1",
6
6
  "private": false,
7
7
  "engines": {
8
8
  "node": ">=20 <=24"
@@ -81,19 +81,19 @@
81
81
  "@adobe/aio-lib-state": "^5.3.1",
82
82
  "@standard-schema/spec": "^1.1.0",
83
83
  "yaml": "^2.8.2",
84
+ "@adobe/aio-commerce-lib-api": "0.6.1",
84
85
  "@adobe/aio-commerce-lib-core": "0.6.1",
85
86
  "@adobe/aio-commerce-lib-events": "0.6.0",
86
- "@adobe/aio-commerce-lib-auth": "0.8.1",
87
- "@adobe/aio-commerce-lib-api": "0.6.1"
87
+ "@adobe/aio-commerce-lib-auth": "0.8.1"
88
88
  },
89
89
  "devDependencies": {
90
90
  "@adobe/aio-lib-core-logging": "^3.0.2",
91
91
  "@aio-commerce-sdk/common-utils": "0.2.1",
92
+ "@aio-commerce-sdk/config-tsdown": "1.0.0",
92
93
  "@aio-commerce-sdk/config-typedoc": "1.0.0",
93
- "@aio-commerce-sdk/config-vitest": "1.0.0",
94
+ "@aio-commerce-sdk/config-typescript": "1.0.0",
94
95
  "@aio-commerce-sdk/scripting-utils": "0.2.1",
95
- "@aio-commerce-sdk/config-tsdown": "1.0.0",
96
- "@aio-commerce-sdk/config-typescript": "1.0.0"
96
+ "@aio-commerce-sdk/config-vitest": "1.0.0"
97
97
  },
98
98
  "sideEffects": false,
99
99
  "scripts": {