@ecmaos/kernel 0.2.3 → 0.2.4

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.
@@ -1,4 +1,4 @@
1
- import { p as process$1, g as getDefaultExportFromCjs, c as chalk, a as path } from "./empty-D1k8eaRb.js";
1
+ import { p as process$1, g as getDefaultExportFromCjs, c as chalk, a as path } from "./empty-DAF3BgdH.js";
2
2
  var re = { exports: {} };
3
3
  var constants;
4
4
  var hasRequiredConstants;
@@ -1897,7 +1897,7 @@ function requireSemver() {
1897
1897
  var semverExports = requireSemver();
1898
1898
  const semver = /* @__PURE__ */ getDefaultExportFromCjs(semverExports);
1899
1899
  const install = async ({ kernel, shell, terminal, args }) => {
1900
- const [packageArg, registryArg] = args;
1900
+ const [packageArg, registryArg, reinstallArg] = args;
1901
1901
  if (!packageArg) {
1902
1902
  terminal.writeln(chalk.red("Usage: install <package-name>[@version]"));
1903
1903
  return 1;
@@ -1907,7 +1907,7 @@ const install = async ({ kernel, shell, terminal, args }) => {
1907
1907
  terminal.writeln(chalk.red("Invalid package name format"));
1908
1908
  return 1;
1909
1909
  }
1910
- const registry = registryArg || "https://registry.npmjs.org";
1910
+ const registry = registryArg || shell.env.get("REGISTRY") || "https://registry.npmjs.org";
1911
1911
  const packageName = spec[1];
1912
1912
  let version = spec[2] || "latest";
1913
1913
  if (!packageName) {
@@ -1923,6 +1923,11 @@ const install = async ({ kernel, shell, terminal, args }) => {
1923
1923
  }
1924
1924
  if (version === "latest") version = data["dist-tags"].latest;
1925
1925
  else version = semver.maxSatisfying(Object.keys(data.versions), version) || version;
1926
+ if (reinstallArg) {
1927
+ const pkgData = JSON.parse(await kernel.filesystem.fs.readFile(path.join("/usr/lib", packageName, version, "package", "package.json"), "utf-8"));
1928
+ for (const bin in pkgData.bin) await kernel.filesystem.fs.unlink(path.join("/usr/bin", bin));
1929
+ await kernel.filesystem.fs.rm(path.join("/usr/lib", packageName, version), { recursive: true, force: true });
1930
+ }
1926
1931
  const packagePath = path.join("/usr/lib", packageName, version, "package", "package.json");
1927
1932
  if (await kernel.filesystem.fs.exists(packagePath)) {
1928
1933
  terminal.writeln(chalk.green(`${packageName} v${version} is already installed`));
@@ -1930,7 +1935,7 @@ const install = async ({ kernel, shell, terminal, args }) => {
1930
1935
  }
1931
1936
  terminal.writeln(`Installing ${data.name} v${version} from ${registry}...`);
1932
1937
  const tarballUrl = data.versions[version]?.dist?.tarball;
1933
- const tarballChecksum = data.versions[version]?.dist?.shasum;
1938
+ const tarballChecksum = data.versions[version]?.dist?.shasum?.toLowerCase();
1934
1939
  if (!tarballUrl || !tarballChecksum) {
1935
1940
  terminal.writeln(chalk.red(`No tarball URL or checksum found for ${packageName} v${version}`));
1936
1941
  return 1;
@@ -1958,11 +1963,19 @@ const install = async ({ kernel, shell, terminal, args }) => {
1958
1963
  if (packageJson.bin) {
1959
1964
  if (typeof packageJson.bin === "string") {
1960
1965
  const binPath = path.join("/usr/lib", packageName, version, "package", packageJson.bin);
1966
+ if (!await kernel.filesystem.fs.exists(binPath)) {
1967
+ terminal.writeln(chalk.red(`${binPath} does not exist`));
1968
+ return 1;
1969
+ }
1961
1970
  await kernel.filesystem.fs.symlink(binPath, path.join("/usr/bin", packageJson.name));
1962
1971
  terminal.writeln(chalk.green(`Linked ${packageJson.name} to ${path.join("/usr/bin", packageJson.name)}`));
1963
1972
  } else if (typeof packageJson.bin === "object") {
1964
1973
  for (const bin in packageJson.bin) {
1965
1974
  const binPath = path.join("/usr/lib", packageName, version, "package", packageJson.bin[bin]);
1975
+ if (!await kernel.filesystem.fs.exists(binPath)) {
1976
+ terminal.writeln(chalk.red(`${binPath} does not exist`));
1977
+ return 1;
1978
+ }
1966
1979
  await kernel.filesystem.fs.symlink(binPath, path.join("/usr/bin", bin));
1967
1980
  terminal.writeln(chalk.green(`Linked ${bin} to ${path.join("/usr/bin", bin)}`));
1968
1981
  }
@@ -1981,4 +1994,4 @@ const install = async ({ kernel, shell, terminal, args }) => {
1981
1994
  export {
1982
1995
  install as default
1983
1996
  };
1984
- //# sourceMappingURL=install-DvXm00-p.js.map
1997
+ //# sourceMappingURL=install--B0gJ8Dk.js.map