envlock-next 0.2.0 → 0.4.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 (3) hide show
  1. package/dist/cli/index.js +47 -3
  2. package/package.json +13 -15
  3. package/LICENSE +0 -21
package/dist/cli/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/cli/index.ts
4
+ import { pathToFileURL as pathToFileURL2 } from "url";
4
5
  import { Command } from "commander";
5
- import { ENVIRONMENTS, runWithSecrets, validateEnvFilePath } from "envlock-core";
6
+ import { ENVIRONMENTS, runWithSecrets, validateEnvFilePath, validateOnePasswordEnvId as validateOnePasswordEnvId2 } from "envlock-core";
6
7
 
7
8
  // src/cli/resolve-config.ts
8
9
  import { existsSync } from "fs";
@@ -76,8 +77,33 @@ function getEnvironment(opts, defaultEnv) {
76
77
  if (opts.staging) return ENVIRONMENTS.staging;
77
78
  return defaultEnv;
78
79
  }
80
+ async function handleRunCommand(cmd, cmdArgs, opts) {
81
+ if (!cmd) {
82
+ throw new Error(
83
+ "[envlock] Usage: envlock run <command> [args...]\nExample: envlock run node server.js --port 4000"
84
+ );
85
+ }
86
+ const environment = getEnvironment(opts, ENVIRONMENTS.development);
87
+ const config = await resolveConfig(process.cwd());
88
+ const onePasswordEnvId = process.env["ENVLOCK_OP_ENV_ID"] ?? config.onePasswordEnvId;
89
+ if (!onePasswordEnvId) {
90
+ throw new Error(
91
+ "[envlock] No onePasswordEnvId found. Set it in envlock.config.js or via ENVLOCK_OP_ENV_ID env var."
92
+ );
93
+ }
94
+ validateOnePasswordEnvId2(onePasswordEnvId);
95
+ const envFile = config.envFiles?.[environment] ?? DEFAULT_ENV_FILES[environment];
96
+ validateEnvFilePath(envFile, process.cwd());
97
+ runWithSecrets({
98
+ envFile,
99
+ environment,
100
+ onePasswordEnvId,
101
+ command: cmd,
102
+ args: cmdArgs
103
+ });
104
+ }
79
105
  var program = new Command("envlock");
80
- program.name("envlock").description("Run Next.js commands with 1Password + dotenvx secret injection").version("0.1.0");
106
+ program.name("envlock").description("Run Next.js commands with 1Password + dotenvx secret injection").version("0.3.0").enablePositionalOptions();
81
107
  for (const [subcommand, defaultEnv] of Object.entries(
82
108
  SUPPORTED_SUBCOMMANDS
83
109
  )) {
@@ -89,4 +115,22 @@ for (const [subcommand, defaultEnv] of Object.entries(
89
115
  );
90
116
  program.addCommand(cmd);
91
117
  }
92
- program.parse(process.argv);
118
+ var runCmd = new Command("run").description("Run any command with 1Password + dotenvx secret injection").allowUnknownOption(true).passThroughOptions(true);
119
+ addEnvFlags(runCmd).action(
120
+ async (opts) => {
121
+ const [cmd, ...cmdArgs] = runCmd.args;
122
+ try {
123
+ await handleRunCommand(cmd, cmdArgs, opts);
124
+ } catch (err) {
125
+ console.error(err instanceof Error ? err.message : String(err));
126
+ process.exit(1);
127
+ }
128
+ }
129
+ );
130
+ program.addCommand(runCmd);
131
+ if (import.meta.url === pathToFileURL2(process.argv[1] ?? "").href) {
132
+ program.parse(process.argv);
133
+ }
134
+ export {
135
+ handleRunCommand
136
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "envlock-next",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "description": "Next.js plugin and CLI for envlock",
6
6
  "license": "MIT",
@@ -26,28 +26,26 @@
26
26
  "types": "./dist/index.d.ts"
27
27
  }
28
28
  },
29
- "files": [
30
- "dist"
31
- ],
29
+ "files": ["dist"],
30
+ "scripts": {
31
+ "build": "tsup",
32
+ "dev": "tsup --watch",
33
+ "test": "vitest run",
34
+ "test:watch": "vitest"
35
+ },
32
36
  "dependencies": {
33
- "commander": "^12.0.0",
34
- "envlock-core": "0.2.0"
37
+ "envlock-core": "workspace:*",
38
+ "commander": "^12.0.0"
35
39
  },
36
40
  "peerDependencies": {
37
41
  "next": ">=14.0.0"
38
42
  },
39
43
  "devDependencies": {
44
+ "envlock-core": "workspace:*",
40
45
  "@types/node": "^20.14.10",
41
46
  "next": "^15.2.3",
42
47
  "tsup": "^8.0.0",
43
48
  "typescript": "^5.8.2",
44
- "vitest": "^3.0.0",
45
- "envlock-core": "0.2.0"
46
- },
47
- "scripts": {
48
- "build": "tsup",
49
- "dev": "tsup --watch",
50
- "test": "vitest run",
51
- "test:watch": "vitest"
49
+ "vitest": "^3.0.0"
52
50
  }
53
- }
51
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Benjamin Davies
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.