envlock-next 0.4.0 → 0.5.0

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/dist/cli/index.js +26 -7
  2. package/package.json +5 -3
package/dist/cli/index.js CHANGED
@@ -2,14 +2,16 @@
2
2
 
3
3
  // src/cli/index.ts
4
4
  import { pathToFileURL as pathToFileURL2 } from "url";
5
+ import { realpathSync } from "fs";
5
6
  import { Command } from "commander";
6
7
  import { ENVIRONMENTS, runWithSecrets, validateEnvFilePath, validateOnePasswordEnvId as validateOnePasswordEnvId2 } from "envlock-core";
8
+ import { log as log2, setVerbose } from "envlock-core";
7
9
 
8
10
  // src/cli/resolve-config.ts
9
11
  import { existsSync } from "fs";
10
12
  import { resolve } from "path";
11
13
  import { pathToFileURL } from "url";
12
- import { validateOnePasswordEnvId } from "envlock-core";
14
+ import { validateOnePasswordEnvId, log } from "envlock-core";
13
15
  var CONFIG_CANDIDATES = ["next.config.js", "next.config.mjs"];
14
16
  async function resolveConfig(cwd) {
15
17
  for (const candidate of CONFIG_CANDIDATES) {
@@ -19,12 +21,12 @@ async function resolveConfig(cwd) {
19
21
  const mod = await import(pathToFileURL(fullPath).href);
20
22
  const config = mod.default ?? mod;
21
23
  if (config && typeof config === "object" && "__envlock" in config && config.__envlock && typeof config.__envlock === "object" && "onePasswordEnvId" in config.__envlock) {
24
+ log.debug(`Config loaded from ${candidate}`);
22
25
  return config.__envlock;
23
26
  }
24
27
  } catch (err) {
25
- console.warn(
26
- `[envlock] Failed to load ${candidate}: ${err instanceof Error ? err.message : String(err)}`
27
- );
28
+ log.warn(`Failed to load ${candidate}: ${err instanceof Error ? err.message : String(err)}`);
29
+ log.debug(`Stack: ${err instanceof Error ? err.stack ?? "" : ""}`);
28
30
  }
29
31
  }
30
32
  if (process.env["ENVLOCK_OP_ENV_ID"]) {
@@ -60,6 +62,9 @@ var ARGUMENT_FLAGS = {
60
62
  async function runNextCommand(subcommand, environment, passthroughArgs) {
61
63
  const config = await resolveConfig(process.cwd());
62
64
  const envFile = config.envFiles?.[environment] ?? DEFAULT_ENV_FILES[environment];
65
+ log2.debug(`Environment: ${environment}`);
66
+ log2.debug(`Env file: ${envFile}`);
67
+ log2.debug(`Command: next ${subcommand} ${passthroughArgs.join(" ")}`);
63
68
  validateEnvFilePath(envFile, process.cwd());
64
69
  runWithSecrets({
65
70
  envFile,
@@ -94,6 +99,9 @@ async function handleRunCommand(cmd, cmdArgs, opts) {
94
99
  validateOnePasswordEnvId2(onePasswordEnvId);
95
100
  const envFile = config.envFiles?.[environment] ?? DEFAULT_ENV_FILES[environment];
96
101
  validateEnvFilePath(envFile, process.cwd());
102
+ log2.debug(`Environment: ${environment}`);
103
+ log2.debug(`Env file: ${envFile}`);
104
+ log2.debug(`Command: ${cmd} ${cmdArgs.join(" ")}`);
97
105
  runWithSecrets({
98
106
  envFile,
99
107
  environment,
@@ -103,7 +111,7 @@ async function handleRunCommand(cmd, cmdArgs, opts) {
103
111
  });
104
112
  }
105
113
  var program = new Command("envlock");
106
- program.name("envlock").description("Run Next.js commands with 1Password + dotenvx secret injection").version("0.3.0").enablePositionalOptions();
114
+ program.name("envlock").description("Run Next.js commands with 1Password + dotenvx secret injection").version("0.3.0").enablePositionalOptions().option("-d, --debug", "enable debug output");
107
115
  for (const [subcommand, defaultEnv] of Object.entries(
108
116
  SUPPORTED_SUBCOMMANDS
109
117
  )) {
@@ -122,13 +130,24 @@ addEnvFlags(runCmd).action(
122
130
  try {
123
131
  await handleRunCommand(cmd, cmdArgs, opts);
124
132
  } catch (err) {
125
- console.error(err instanceof Error ? err.message : String(err));
133
+ log2.error(err instanceof Error ? err.message : String(err));
126
134
  process.exit(1);
127
135
  }
128
136
  }
129
137
  );
130
138
  program.addCommand(runCmd);
131
- if (import.meta.url === pathToFileURL2(process.argv[1] ?? "").href) {
139
+ var _resolvedArgv1Next = (() => {
140
+ try {
141
+ return realpathSync(process.argv[1] ?? "");
142
+ } catch {
143
+ return process.argv[1] ?? "";
144
+ }
145
+ })();
146
+ if (import.meta.url === pathToFileURL2(_resolvedArgv1Next).href) {
147
+ if (process.argv.includes("--debug") || process.argv.includes("-d")) {
148
+ setVerbose(true);
149
+ }
150
+ log2.debug(`Resolved argv[1]: ${_resolvedArgv1Next}`);
132
151
  program.parse(process.argv);
133
152
  }
134
153
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "envlock-next",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "description": "Next.js plugin and CLI for envlock",
6
6
  "license": "MIT",
@@ -26,7 +26,9 @@
26
26
  "types": "./dist/index.d.ts"
27
27
  }
28
28
  },
29
- "files": ["dist"],
29
+ "files": [
30
+ "dist"
31
+ ],
30
32
  "scripts": {
31
33
  "build": "tsup",
32
34
  "dev": "tsup --watch",
@@ -34,7 +36,7 @@
34
36
  "test:watch": "vitest"
35
37
  },
36
38
  "dependencies": {
37
- "envlock-core": "workspace:*",
39
+ "envlock-core": "^0.5.0",
38
40
  "commander": "^12.0.0"
39
41
  },
40
42
  "peerDependencies": {