@vwala/tooling-config 1.3.2 → 1.4.1

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/README.md CHANGED
@@ -19,6 +19,8 @@ src/
19
19
  │ └── hooks/
20
20
  ├── context/ Module domain-language policy (consumed via npm)
21
21
  │ └── _scripts/
22
+ ├── gcloud/ Local Google Cloud ADC helper (consumed via npm)
23
+ │ └── ensure-gcp-application-default-credentials.sh
22
24
  ├── monorepo/ Package-manifest conventions (consumed via npm)
23
25
  │ └── _scripts/
24
26
  │ └── check-exports.mjs
@@ -91,6 +93,8 @@ They are warnings because the convention applies to new code and asks that exist
91
93
 
92
94
  `__tests__`, `__mocks__`, `_scripts`, hidden folders, and the `[slug]` / `(group)` / `@slot` segments Next.js and Expo give meaning to are exempt from the folder check.
93
95
 
96
+ Paths under `prisma/migrations/` at any depth are ignored entirely because Prisma owns each migration directory name and persists that exact identity in the database, so it cannot be renamed to kebab-case.
97
+
94
98
  ### Exports
95
99
 
96
100
  Entry points are declared in a package's `package.json` `exports`, not assembled by a barrel that re-exports the world. A feature's own `index.ts` is a different thing — an internal boundary, and one [`vwala-engineering-principles`](https://github.com/vwala-be/skills) requires — so nothing here touches it. Three of Biome's own rules carry the syntax half:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vwala/tooling-config",
3
- "version": "1.3.2",
3
+ "version": "1.4.1",
4
4
  "type": "module",
5
5
  "description": "Shared tooling configuration for Vwala repositories",
6
6
  "license": "MIT",
@@ -16,6 +16,9 @@
16
16
  "!src/**/__tests__",
17
17
  "!src/**/test-support"
18
18
  ],
19
+ "bin": {
20
+ "ensure-gcp-application-default-credentials": "./src/gcloud/ensure-gcp-application-default-credentials.sh"
21
+ },
19
22
  "exports": {
20
23
  "./biome": "./src/biome/biome.config.json",
21
24
  "./commitlint": "./src/commitlint/commitlint.config.js",
@@ -35,11 +35,19 @@ const KEBAB_CASE = /^[a-z0-9]+(-[a-z0-9]+)*$/;
35
35
  // runnable helpers, anything hidden, and the bracket/paren/@ segments that
36
36
  // Next.js and Expo routing give meaning to.
37
37
  const RESERVED_FOLDER = /^(__[a-z]+__|_[a-z-]+|\..+|\[.+\]|\(.+\)|@.+|\+.+)$/;
38
+ // Paths whose names another tool owns. Prisma generates a migration directory as
39
+ // `<timestamp>_<name>` and records that exact string in the `_prisma_migrations`
40
+ // table, so the name is an identity rather than a choice: no migration can ever
41
+ // satisfy KEBAB_CASE, and renaming one to try makes the database disagree with
42
+ // the repository about which migrations have run.
43
+ const IGNORED_PATH = /(^|\/)prisma\/migrations\//;
38
44
 
39
45
  const trackedFiles = git(["ls-files"]);
40
46
  const untrackedFiles = git(["ls-files", "--others", "--exclude-standard"]);
41
47
  const files = [...trackedFiles, ...untrackedFiles].filter(
42
- (file) => !IGNORED_PREFIXES.some((prefix) => file.startsWith(prefix)),
48
+ (file) =>
49
+ !IGNORED_PREFIXES.some((prefix) => file.startsWith(prefix)) &&
50
+ !IGNORED_PATH.test(file),
43
51
  );
44
52
  const newFiles = new Set([...untrackedFiles, ...addedSinceBaseRef()]);
45
53
 
@@ -146,7 +154,20 @@ function addedSinceBaseRef() {
146
154
  );
147
155
  return [];
148
156
  }
149
- return git(["diff", "--diff-filter=A", "--name-only", mergeBase]);
157
+ // Copy and rename detection runs after `--diff-filter`, so filtering directly
158
+ // would classify a legacy-path migration copy as a new file. Parse the status
159
+ // after detection and retain only additions Git could not associate with a
160
+ // tracked source file.
161
+ return git([
162
+ "diff",
163
+ "--name-status",
164
+ "-C",
165
+ "--find-copies-harder",
166
+ mergeBase,
167
+ ]).flatMap((line) => {
168
+ const [status, file] = line.split("\t");
169
+ return status === "A" ? [file] : [];
170
+ });
150
171
  }
151
172
 
152
173
  function git(args) {
@@ -0,0 +1,19 @@
1
+ # Google Cloud Application Default Credentials
2
+
3
+ Install `@vwala/tooling-config` in the workspace that needs Google Cloud access:
4
+
5
+ ```bash
6
+ pnpm add -D @vwala/tooling-config
7
+ ```
8
+
9
+ Run the packaged command before the local service starts:
10
+
11
+ ```json
12
+ {
13
+ "scripts": {
14
+ "dev": "ensure-gcp-application-default-credentials && tsx watch --clear-screen=false src/server.ts"
15
+ }
16
+ }
17
+ ```
18
+
19
+ The command validates Application Default Credentials, opens an interactive `gcloud auth application-default login` when needed, and uses `GCP_PROJECT_ID` as the quota project with `vwala-dev` as the default. Set `SKIP_GCP_ADC_CHECK=1` to skip the check; `CI=true` skips it automatically.
@@ -0,0 +1,172 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Ensures Google Application Default Credentials are valid before local development.
4
+ # Use this before starting services that call Google Cloud APIs with user credentials.
5
+ #
6
+ # Usage: ensure-gcp-application-default-credentials [--help]
7
+ #
8
+ # Environment:
9
+ # SKIP_GCP_ADC_CHECK=1 Skip this check
10
+ # GCP_PROJECT_ID Quota project for ADC (default: vwala-dev)
11
+ # CI=true Always skip (CI has its own credentials)
12
+
13
+ set -euo pipefail
14
+ IFS=$'\n\t'
15
+
16
+ readonly SCRIPT_NAME="${0##*/}"
17
+ readonly CLOUD_PLATFORM_SCOPE="https://www.googleapis.com/auth/cloud-platform"
18
+ readonly DEFAULT_QUOTA_PROJECT="vwala-dev"
19
+
20
+ if [[ -t 1 ]]; then
21
+ readonly C_RESET=$'\033[0m'
22
+ readonly C_RED=$'\033[31m'
23
+ readonly C_GREEN=$'\033[32m'
24
+ readonly C_YELLOW=$'\033[33m'
25
+ readonly C_CYAN=$'\033[36m'
26
+ else
27
+ readonly C_RESET="" C_RED="" C_GREEN="" C_YELLOW="" C_CYAN=""
28
+ fi
29
+
30
+ info() { printf "%s\n" "${C_CYAN}$*${C_RESET}"; }
31
+ success() { printf "%s\n" "${C_GREEN}✓ $*${C_RESET}"; }
32
+ warn() { printf "%s\n" "${C_YELLOW}⚠ $*${C_RESET}"; }
33
+ error() { printf "%s\n" "${C_RED}✗ $*${C_RESET}" >&2; }
34
+
35
+ trap 'error "Failed on line ${LINENO}"' ERR
36
+
37
+ usage() {
38
+ cat <<EOF
39
+ Usage: ${SCRIPT_NAME} [--help]
40
+
41
+ Ensures Google Application Default Credentials (ADC) are valid before starting
42
+ local development that calls Google Cloud APIs.
43
+
44
+ Environment:
45
+ SKIP_GCP_ADC_CHECK=1 Skip this check
46
+ GCP_PROJECT_ID ADC quota project (default: ${DEFAULT_QUOTA_PROJECT})
47
+ CI=true Skip in continuous integration
48
+
49
+ Examples:
50
+ ${SCRIPT_NAME}
51
+ SKIP_GCP_ADC_CHECK=1 pnpm dev
52
+ EOF
53
+ }
54
+
55
+ require_command() {
56
+ if command -v "$1" >/dev/null 2>&1; then
57
+ return 0
58
+ fi
59
+
60
+ error "Required command '$1' is not installed."
61
+ case "$1" in
62
+ gcloud)
63
+ error "Install it with: brew install --cask google-cloud-sdk"
64
+ ;;
65
+ esac
66
+ return 1
67
+ }
68
+
69
+ is_interactive_terminal() {
70
+ [[ -t 0 ]]
71
+ }
72
+
73
+ quota_project() {
74
+ printf "%s" "${GCP_PROJECT_ID:-${DEFAULT_QUOTA_PROJECT}}"
75
+ }
76
+
77
+ should_skip_check() {
78
+ if [[ "${CI:-}" == "true" ]]; then
79
+ info "CI=true — skipping Google Application Default Credentials check."
80
+ return 0
81
+ fi
82
+
83
+ if [[ "${SKIP_GCP_ADC_CHECK:-}" == "1" ]]; then
84
+ warn "SKIP_GCP_ADC_CHECK=1 — skipping Google Application Default Credentials check."
85
+ return 0
86
+ fi
87
+
88
+ return 1
89
+ }
90
+
91
+ adc_token_is_valid() {
92
+ gcloud auth application-default print-access-token >/dev/null 2>&1
93
+ }
94
+
95
+ print_fix_instructions() {
96
+ local project
97
+ project="$(quota_project)"
98
+
99
+ error "Google Application Default Credentials are missing or expired."
100
+ error "Local features that call Google Cloud APIs require valid ADC."
101
+ error ""
102
+ error "Run these commands, then restart dev:"
103
+ error ""
104
+ error " gcloud auth application-default login --scopes=${CLOUD_PLATFORM_SCOPE}"
105
+ error " gcloud auth application-default set-quota-project ${project}"
106
+ error ""
107
+ error "If you use Google Workspace and see invalid_rapt, complete the browser"
108
+ error "re-authentication flow during gcloud auth application-default login."
109
+ error ""
110
+ error "To skip this check when not working on Google Cloud-backed features:"
111
+ error " SKIP_GCP_ADC_CHECK=1 pnpm dev"
112
+ }
113
+
114
+ run_interactive_login() {
115
+ local project
116
+ project="$(quota_project)"
117
+
118
+ info "Starting interactive Application Default Credentials login…"
119
+ gcloud auth application-default login --scopes="${CLOUD_PLATFORM_SCOPE}"
120
+ gcloud auth application-default set-quota-project "${project}"
121
+ success "Application Default Credentials configured (quota project: ${project})."
122
+ }
123
+
124
+ ensure_application_default_credentials() {
125
+ if should_skip_check; then
126
+ return 0
127
+ fi
128
+
129
+ require_command gcloud
130
+
131
+ if adc_token_is_valid; then
132
+ success "Google Application Default Credentials are valid."
133
+ return 0
134
+ fi
135
+
136
+ warn "Application Default Credentials are missing or expired."
137
+
138
+ if is_interactive_terminal; then
139
+ run_interactive_login
140
+ if adc_token_is_valid; then
141
+ success "Google Application Default Credentials are valid."
142
+ return 0
143
+ fi
144
+
145
+ error "Login completed but credentials are still invalid."
146
+ print_fix_instructions
147
+ return 1
148
+ fi
149
+
150
+ print_fix_instructions
151
+ error "Non-interactive terminal — cannot run gcloud auth application-default login automatically."
152
+ return 1
153
+ }
154
+
155
+ main() {
156
+ case "${1:-}" in
157
+ -h | --help)
158
+ usage
159
+ exit 0
160
+ ;;
161
+ "")
162
+ ensure_application_default_credentials
163
+ ;;
164
+ *)
165
+ error "Unknown option: $1"
166
+ usage
167
+ exit 1
168
+ ;;
169
+ esac
170
+ }
171
+
172
+ main "$@"