@pamenv/vite 0.0.0-stage → 0.1.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @pamenv/vite
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - First release: Vite plugin injects PAM env in an early `config` hook (`debug`, `envPriority`).
package/README.md CHANGED
@@ -1,3 +1,42 @@
1
- # Temporary Holding Version
1
+ # @pamenv/vite
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ 在 Vite 解析配置之前,把 PAM 环境写进当前进程的 `process.env`。`dev` 脚本可以继续是 `vite`,不必再包 `pamenv run`。
4
+
5
+ ```bash
6
+ pnpm add @pamenv/vite pamenv-cli
7
+ # 或 npm i @pamenv/vite pamenv-cli
8
+ ```
9
+
10
+ 依赖 `pamenv-cli`(注入与登录逻辑)。项目目录需有可用的 `.pam`(与 CLI 相同)。
11
+
12
+ ```ts
13
+ import { defineConfig } from 'vite';
14
+ import pamenv from '@pamenv/vite';
15
+
16
+ export default defineConfig({
17
+ plugins: [
18
+ pamenv({
19
+ slug: 'my-app',
20
+ env: 'local',
21
+ keepEnv: ['APP_ENV'],
22
+ // 默认 PAM 优先;本地临时改 .env / process 测值时用 'local'
23
+ // envPriority: 'local',
24
+ debug: process.env.PAMENV_DEBUG === '1'
25
+ })
26
+ ]
27
+ });
28
+ ```
29
+
30
+ 也可用命名导出:`import { createPamenvPlugin } from '@pamenv/vite'`(与 `@pamenv/next` 同名)。
31
+
32
+ Token 来自**当前项目**的 `.pam`(默认 `preferLocal: true`,不会用 `~/.pam`),不要写进配置对象。未登录时请在项目目录执行:
33
+
34
+ ```bash
35
+ pamenv login --local
36
+ ```
37
+
38
+ `enabled: false` 时不请求 PAM。未传 `enabled` 时只在 **`vite` / `vite dev`(serve)** 注入;`vite build` 默认跳过。需要构建期注入时设 `enabled: true`,或 `enabled: (command) => command === 'serve' || command === 'build'`。
39
+
40
+ `debug` 默认 `false`;`envPriority` 默认 `remote`(与 CLI / `@pamenv/next` 相同)。
41
+
42
+ `clientPublicPrefixes` 可覆盖「敏感 + 公开前缀」告警用的前缀(如 `['VITE_']`);传 `[]` 关闭该告警。
package/dist/index.cjs ADDED
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ createPamenvPlugin: () => createPamenvPlugin,
24
+ default: () => index_default
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var import_pamenv_cli = require("pamenv-cli");
28
+ function createPamenvPlugin(options) {
29
+ return {
30
+ name: "pamenv",
31
+ enforce: "pre",
32
+ async config(_userConfig, env) {
33
+ await (0, import_pamenv_cli.injectPamenvProcessEnv)({
34
+ ...options,
35
+ enabled: isEnabled(options, env)
36
+ });
37
+ return;
38
+ }
39
+ };
40
+ }
41
+ var index_default = createPamenvPlugin;
42
+ function isEnabled(options, env) {
43
+ if (typeof options.enabled === "function") {
44
+ return options.enabled(env.command);
45
+ }
46
+ if (options.enabled === false) {
47
+ return false;
48
+ }
49
+ if (options.enabled === true) {
50
+ return true;
51
+ }
52
+ return env.command === "serve";
53
+ }
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ createPamenvPlugin
57
+ });
@@ -0,0 +1,32 @@
1
+ import { PamenvInjectOptions } from 'pamenv-cli';
2
+ export { PamenvInjectOptions } from 'pamenv-cli';
3
+ import { Plugin } from 'vite';
4
+
5
+ /**
6
+ * Vite plugin that writes PAM variables onto `process.env` in an early
7
+ * `config` hook (before most other plugins and `loadEnv` consumers see env).
8
+ *
9
+ * Default: only runs for `vite` / `vite dev` (`command === 'serve'`).
10
+ * Pass `enabled: true` to also inject during `vite build`, or a function
11
+ * receiving Vite's command (`serve` | `build`).
12
+ *
13
+ * @example
14
+ * import { defineConfig } from 'vite';
15
+ * import pamenv from '@pamenv/vite';
16
+ *
17
+ * export default defineConfig({
18
+ * plugins: [
19
+ * pamenv({
20
+ * slug: 'my-app',
21
+ * env: 'local',
22
+ * debug: process.env.PAMENV_DEBUG === '1'
23
+ * })
24
+ * ]
25
+ * });
26
+ *
27
+ * @param options - Same fields as `pamenv run <slug> -e <env>`;
28
+ * `debug` / `envPriority` default false / `remote`
29
+ */
30
+ declare function createPamenvPlugin(options: PamenvInjectOptions): Plugin;
31
+
32
+ export { createPamenvPlugin, createPamenvPlugin as default };
@@ -0,0 +1,32 @@
1
+ import { PamenvInjectOptions } from 'pamenv-cli';
2
+ export { PamenvInjectOptions } from 'pamenv-cli';
3
+ import { Plugin } from 'vite';
4
+
5
+ /**
6
+ * Vite plugin that writes PAM variables onto `process.env` in an early
7
+ * `config` hook (before most other plugins and `loadEnv` consumers see env).
8
+ *
9
+ * Default: only runs for `vite` / `vite dev` (`command === 'serve'`).
10
+ * Pass `enabled: true` to also inject during `vite build`, or a function
11
+ * receiving Vite's command (`serve` | `build`).
12
+ *
13
+ * @example
14
+ * import { defineConfig } from 'vite';
15
+ * import pamenv from '@pamenv/vite';
16
+ *
17
+ * export default defineConfig({
18
+ * plugins: [
19
+ * pamenv({
20
+ * slug: 'my-app',
21
+ * env: 'local',
22
+ * debug: process.env.PAMENV_DEBUG === '1'
23
+ * })
24
+ * ]
25
+ * });
26
+ *
27
+ * @param options - Same fields as `pamenv run <slug> -e <env>`;
28
+ * `debug` / `envPriority` default false / `remote`
29
+ */
30
+ declare function createPamenvPlugin(options: PamenvInjectOptions): Plugin;
31
+
32
+ export { createPamenvPlugin, createPamenvPlugin as default };
package/dist/index.js ADDED
@@ -0,0 +1,34 @@
1
+ // src/index.ts
2
+ import {
3
+ injectPamenvProcessEnv
4
+ } from "pamenv-cli";
5
+ function createPamenvPlugin(options) {
6
+ return {
7
+ name: "pamenv",
8
+ enforce: "pre",
9
+ async config(_userConfig, env) {
10
+ await injectPamenvProcessEnv({
11
+ ...options,
12
+ enabled: isEnabled(options, env)
13
+ });
14
+ return;
15
+ }
16
+ };
17
+ }
18
+ var index_default = createPamenvPlugin;
19
+ function isEnabled(options, env) {
20
+ if (typeof options.enabled === "function") {
21
+ return options.enabled(env.command);
22
+ }
23
+ if (options.enabled === false) {
24
+ return false;
25
+ }
26
+ if (options.enabled === true) {
27
+ return true;
28
+ }
29
+ return env.command === "serve";
30
+ }
31
+ export {
32
+ createPamenvPlugin,
33
+ index_default as default
34
+ };
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
2
  "name": "@pamenv/vite",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "private": false,
6
+ "description": "Vite plugin: load PAM env into process.env before Vite resolves config",
7
+ "main": "./dist/index.cjs",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ "./package.json": "./package.json",
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js",
15
+ "require": "./dist/index.cjs"
16
+ }
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "package.json",
21
+ "README.md",
22
+ "CHANGELOG.md"
23
+ ],
24
+ "scripts": {
25
+ "build": "tsup",
26
+ "type-check": "tsc --build"
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/qlover/brain-toolkit.git",
31
+ "directory": "packages/pamenv-vite"
32
+ },
33
+ "homepage": "https://pam.qlover.top/docs/cli",
34
+ "keywords": [
35
+ "brain toolkit",
36
+ "pam",
37
+ "pamenv",
38
+ "vite",
39
+ "vite-plugin",
40
+ "dotenv"
41
+ ],
42
+ "author": "qlover",
43
+ "license": "ISC",
44
+ "publishConfig": {
45
+ "access": "public"
46
+ },
47
+ "dependencies": {
48
+ "pamenv-cli": "workspace:^"
49
+ },
50
+ "peerDependencies": {
51
+ "vite": ">=5.0.0"
52
+ },
53
+ "peerDependenciesMeta": {
54
+ "vite": {
55
+ "optional": true
56
+ }
57
+ },
58
+ "devDependencies": {
59
+ "@types/node": "^22.9.0",
60
+ "vite": "^6.1.0"
61
+ },
62
+ "engines": {
63
+ "node": ">=20.19.0"
64
+ }
65
+ }