@packmind/cli 0.3.1 → 0.3.3

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.
Files changed (2) hide show
  1. package/main.cjs +89 -16
  2. package/package.json +1 -1
package/main.cjs CHANGED
@@ -1248,21 +1248,21 @@ var GitService = class {
1248
1248
  constructor(logger = new PackmindLogger(origin6)) {
1249
1249
  this.logger = logger;
1250
1250
  }
1251
- async getGitRepositoryRoot(path2) {
1251
+ async getGitRepositoryRoot(path3) {
1252
1252
  try {
1253
1253
  const { stdout } = await execAsync("git rev-parse --show-toplevel", {
1254
- cwd: path2
1254
+ cwd: path3
1255
1255
  });
1256
1256
  const gitRoot = stdout.trim();
1257
1257
  this.logger.debug("Resolved git repository root", {
1258
- inputPath: path2,
1258
+ inputPath: path3,
1259
1259
  gitRoot
1260
1260
  });
1261
1261
  return gitRoot;
1262
1262
  } catch (error) {
1263
1263
  if (error instanceof Error) {
1264
1264
  throw new Error(
1265
- `Failed to get Git repository root. The path '${path2}' does not appear to be inside a Git repository.
1265
+ `Failed to get Git repository root. The path '${path3}' does not appear to be inside a Git repository.
1266
1266
  ${error.message}`
1267
1267
  );
1268
1268
  }
@@ -1369,14 +1369,14 @@ ${error.message}`
1369
1369
  normalizeGitUrl(url) {
1370
1370
  const sshMatch = url.match(/^git@([^:]+):(.+)$/);
1371
1371
  if (sshMatch) {
1372
- const [, host, path2] = sshMatch;
1373
- const cleanPath = path2.replace(/\.git$/, "");
1372
+ const [, host, path3] = sshMatch;
1373
+ const cleanPath = path3.replace(/\.git$/, "");
1374
1374
  return `${host}/${cleanPath}`;
1375
1375
  }
1376
1376
  const httpsMatch = url.match(/^https?:\/\/([^/]+)\/(.+)$/);
1377
1377
  if (httpsMatch) {
1378
- const [, host, path2] = httpsMatch;
1379
- const cleanPath = path2.replace(/\.git$/, "");
1378
+ const [, host, path3] = httpsMatch;
1379
+ const cleanPath = path3.replace(/\.git$/, "");
1380
1380
  return `${host}/${cleanPath}`;
1381
1381
  }
1382
1382
  return url;
@@ -1514,6 +1514,7 @@ var ListFilesInDirectoryUseCase = class {
1514
1514
 
1515
1515
  // apps/cli/src/application/useCases/LintFilesInDirectoryUseCase.ts
1516
1516
  var import_minimatch = require("minimatch");
1517
+ var path2 = __toESM(require("path"));
1517
1518
  var origin7 = "LintFilesInDirectoryUseCase";
1518
1519
  var LintFilesInDirectoryUseCase = class {
1519
1520
  constructor(services, repositories, logger = new PackmindLogger(origin7)) {
@@ -1574,13 +1575,28 @@ var LintFilesInDirectoryUseCase = class {
1574
1575
  return pattern;
1575
1576
  }
1576
1577
  async execute(command2) {
1577
- const { path: path2, draftMode, standardSlug, ruleId, language } = command2;
1578
+ const {
1579
+ path: userPath,
1580
+ draftMode,
1581
+ standardSlug,
1582
+ ruleId,
1583
+ language
1584
+ } = command2;
1585
+ this.logger.debug(
1586
+ `Starting linting: path="${userPath}", draftMode=${!!draftMode}, standardSlug="${standardSlug || "N/A"}", ruleId="${ruleId || "N/A"}", language="${language || "N/A"}"`
1587
+ );
1588
+ const gitRepoRoot = await this.services.gitRemoteUrlService.getGitRepositoryRoot(userPath);
1589
+ const absoluteLintPath = path2.isAbsolute(userPath) ? userPath : path2.resolve(process.cwd(), userPath);
1590
+ if (!absoluteLintPath.startsWith(gitRepoRoot)) {
1591
+ throw new Error(
1592
+ `The path "${absoluteLintPath}" is not within the git repository at "${gitRepoRoot}"`
1593
+ );
1594
+ }
1578
1595
  this.logger.debug(
1579
- `Starting linting: path="${path2}", draftMode=${!!draftMode}, standardSlug="${standardSlug || "N/A"}", ruleId="${ruleId || "N/A"}", language="${language || "N/A"}"`
1596
+ `Resolved paths: gitRoot="${gitRepoRoot}", lintPath="${absoluteLintPath}"`
1580
1597
  );
1581
- const gitRepoRoot = await this.services.gitRemoteUrlService.getGitRepositoryRoot(path2);
1582
1598
  const files = await this.services.listFiles.listFilesInDirectory(
1583
- gitRepoRoot,
1599
+ absoluteLintPath,
1584
1600
  [],
1585
1601
  ["node_modules", "dist", ".min.", ".map.", ".git"]
1586
1602
  );
@@ -2068,13 +2084,27 @@ var BaseParser = class _BaseParser {
2068
2084
  constructor() {
2069
2085
  this.initialized = false;
2070
2086
  }
2087
+ static {
2088
+ this.externalWasmDirectory = null;
2089
+ }
2090
+ /**
2091
+ * Set an external directory where WASM files are located
2092
+ * This is useful for CLI executables that extract WASM files at runtime
2093
+ */
2094
+ static setWasmDirectory(directory) {
2095
+ _BaseParser.externalWasmDirectory = directory;
2096
+ }
2071
2097
  /**
2072
2098
  * Helper to locate tree-sitter WASM files for CLI executable
2073
2099
  */
2074
2100
  static getTreeSitterWasmPaths() {
2101
+ const paths = [];
2102
+ if (_BaseParser.externalWasmDirectory) {
2103
+ paths.push(_BaseParser.externalWasmDirectory);
2104
+ }
2075
2105
  const execDir = process.argv[0] ? (0, import_path.dirname)(process.argv[0]) : process.cwd();
2076
2106
  const scriptDir = require.main?.filename ? (0, import_path.dirname)(require.main.filename) : process.cwd();
2077
- return [
2107
+ paths.push(
2078
2108
  // Next to the main script (for npm packages like @packmind/scan)
2079
2109
  scriptDir,
2080
2110
  (0, import_path.join)(scriptDir, "tree-sitter"),
@@ -2086,7 +2116,8 @@ var BaseParser = class _BaseParser {
2086
2116
  (0, import_path.resolve)(__dirname, "tree-sitter"),
2087
2117
  (0, import_path.resolve)(__dirname, "../../res"),
2088
2118
  (0, import_path.resolve)(__dirname, "../../../packages/linter-ast/res")
2089
- ];
2119
+ );
2120
+ return paths;
2090
2121
  }
2091
2122
  /**
2092
2123
  * Get the locateFile function for TreeSitter Parser initialization
@@ -4059,7 +4090,7 @@ var lintCommand = (0, import_cmd_ts.command)({
4059
4090
  description: "Enable debug logging"
4060
4091
  })
4061
4092
  },
4062
- handler: async ({ path: path2, draft, rule, debug, language, logger }) => {
4093
+ handler: async ({ path: path3, draft, rule, debug, language, logger }) => {
4063
4094
  if (draft && !rule) {
4064
4095
  throw new Error("option --rule is required to use --draft mode");
4065
4096
  }
@@ -4070,7 +4101,7 @@ var lintCommand = (0, import_cmd_ts.command)({
4070
4101
  );
4071
4102
  const packmindCliHexa = new PackmindCliHexa(packmindLogger);
4072
4103
  const { violations } = await packmindCliHexa.lintFilesInDirectory({
4073
- path: path2 ?? ".",
4104
+ path: path3 ?? ".",
4074
4105
  draftMode: draft,
4075
4106
  standardSlug: rule?.standardSlug,
4076
4107
  ruleId: rule?.ruleId,
@@ -4087,7 +4118,49 @@ var lintCommand = (0, import_cmd_ts.command)({
4087
4118
  }
4088
4119
  });
4089
4120
 
4121
+ // apps/cli/src/wasm-runtime.ts
4122
+ var import_fs18 = require("fs");
4123
+ var import_path2 = require("path");
4124
+ var import_os = require("os");
4125
+
4126
+ // apps/cli/src/embedded-wasm.ts
4127
+ var EMBEDDED_WASM_FILES = {};
4128
+
4129
+ // apps/cli/src/wasm-runtime.ts
4130
+ var wasmExtractedDir = null;
4131
+ function hasEmbeddedWasmFiles() {
4132
+ return Object.keys(EMBEDDED_WASM_FILES).length > 0;
4133
+ }
4134
+ function extractWasmFiles() {
4135
+ if (wasmExtractedDir && (0, import_fs18.existsSync)(wasmExtractedDir)) {
4136
+ return wasmExtractedDir;
4137
+ }
4138
+ const tempDir = (0, import_path2.join)((0, import_os.tmpdir)(), `packmind-wasm-${process.pid}`);
4139
+ if (!(0, import_fs18.existsSync)(tempDir)) {
4140
+ (0, import_fs18.mkdirSync)(tempDir, { recursive: true });
4141
+ }
4142
+ for (const [filename, base64Data] of Object.entries(EMBEDDED_WASM_FILES)) {
4143
+ const wasmPath = (0, import_path2.join)(tempDir, filename);
4144
+ if ((0, import_fs18.existsSync)(wasmPath)) {
4145
+ continue;
4146
+ }
4147
+ const wasmBuffer = Buffer.from(base64Data, "base64");
4148
+ (0, import_fs18.writeFileSync)(wasmPath, wasmBuffer);
4149
+ }
4150
+ wasmExtractedDir = tempDir;
4151
+ process.on("exit", () => {
4152
+ });
4153
+ return tempDir;
4154
+ }
4155
+
4090
4156
  // apps/cli/src/main.ts
4157
+ if (hasEmbeddedWasmFiles()) {
4158
+ try {
4159
+ const wasmDir = extractWasmFiles();
4160
+ BaseParser.setWasmDirectory(wasmDir);
4161
+ } catch {
4162
+ }
4163
+ }
4091
4164
  var app = (0, import_cmd_ts2.subcommands)({
4092
4165
  name: "packmind-cli",
4093
4166
  description: "Packmind CLI tool",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@packmind/cli",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "A command-line interface for Packmind linting and code quality checks",
5
5
  "private": false,
6
6
  "bin": {