@saasak/tool-env 1.0.1 → 1.0.2

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/bin/index.js +17 -12
  2. package/package.json +1 -1
package/bin/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ #!/usr/bin/env node
2
+
1
3
  import minimist from 'minimist';
2
4
  import fs from 'fs-extra';
3
5
  import path from 'path';
@@ -164,27 +166,30 @@ async function encryptCommand() {
164
166
  }
165
167
 
166
168
  async function besafeCommand() {
167
- const relativeEnvPath = path.relative(__root, envFile);
169
+ // Find git root to ensure we're in a repository and use correct base path
170
+ const { stdout: gitRoot, exitCode: gitCheck } = await execa('git', ['rev-parse', '--show-toplevel'], { cwd: __root, reject: false });
171
+ if (gitCheck !== 0) {
172
+ return;
173
+ }
168
174
 
169
- try {
170
- const { stdout: stagedDiff } = await execa('git', ['diff', '--cached', '--name-only', '--', relativeEnvPath], { cwd: __root, reject: false });
171
- const { stdout: unstagedDiff } = await execa('git', ['diff', '--name-only', '--', relativeEnvPath], { cwd: __root, reject: false });
172
- const { stdout: untracked } = await execa('git', ['ls-files', '--others', '--exclude-standard', '--', relativeEnvPath], { cwd: __root, reject: false });
175
+ const relativeEnvPath = path.relative(gitRoot, envFile);
173
176
 
174
- if (!stagedDiff?.trim() && !unstagedDiff?.trim() && !untracked?.trim()) {
175
- return;
176
- }
177
- } catch (error) {
177
+ // Check if file has any changes (staged, unstaged, or untracked)
178
+ const { stdout: staged } = await execa('git', ['diff', '--cached', '--name-only', '--', relativeEnvPath], { cwd: gitRoot, reject: false });
179
+ const { stdout: unstaged } = await execa('git', ['diff', '--name-only', '--', relativeEnvPath], { cwd: gitRoot, reject: false });
180
+ const { stdout: untracked } = await execa('git', ['ls-files', '--others', '--exclude-standard', '--', relativeEnvPath], { cwd: gitRoot, reject: false });
181
+
182
+ if (!staged?.trim() && !unstaged?.trim() && !untracked?.trim()) {
178
183
  return;
179
184
  }
180
185
 
181
- await encrypt();
186
+ await encryptCommand();
182
187
 
183
188
  if (!secret) {
184
- console.error('Warning: potential security risk: secret not provided. Variables WERE NOT be encrypted.');
189
+ console.error('Warning: potential security risk: secret not provided. Variables WERE NOT encrypted.');
185
190
  }
186
191
 
187
- await execa('git', ['add', relativeEnvPath], { cwd: __root });
192
+ await execa('git', ['add', relativeEnvPath], { cwd: gitRoot });
188
193
  }
189
194
 
190
195
  async function addCommand() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@saasak/tool-env",
3
3
  "license": "MIT",
4
- "version": "1.0.1",
4
+ "version": "1.0.2",
5
5
  "author": "dev@saasak.studio",
6
6
  "description": "A small util to manage environment variables for your monorepo",
7
7
  "keywords": [