From f605f3a490b2149b7bece1ebf7e90c4789d89996 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 5 Nov 2026 04:50:00 +0000 Subject: [PATCH 1/3] fix(deps): refresh rimraf to 6.1.4 to clear the glob advisory on the nyc > rimraf path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Semver-compatible lockfile refresh (npm update rimraf, npm 11): rimraf 6.1.3 -> 6.1.4 moves its glob from 13.0.6 to 14.0.3, clearing GHSA-3g3m-2fjr-6pw4 on the nyc > rimraf path. Dev-only. A full `npm audit fix` was tried first and reverted: it also raises @oclif/core to 4.14.0, which breaks 30/31 integration tests (ESM-only wsl-utils). #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_01NTFwVv9F3TgYAwMxADEnGj --- package-lock.json | 78 +++++++++++++++++++++++++++++++---------------- 1 file changed, 51 insertions(+), 27 deletions(-) diff --git a/package-lock.json b/package-lock.json index bd7c8b9b..cf011a90 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2478,6 +2478,13 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, + "node_modules/@isaacs/nonrecursive-glob-match": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@isaacs/nonrecursive-glob-match/-/nonrecursive-glob-match-1.0.3.tgz", + "integrity": "sha512-SI7kyKHq4XXDRozw+r9GlRZkia1ZkFrpLW98r2IC2Bpr8YkFGE3fvjzmxCG0x78A++69HmDNrDvSMYBZmHGpKA==", + "dev": true, + "license": "BlueOak-1.0.0" + }, "node_modules/@istanbuljs/load-nyc-config": { "version": "1.1.0", "dev": true, @@ -5315,6 +5322,18 @@ "dev": true, "license": "MIT" }, + "node_modules/brace-expansion": { + "version": "5.0.12", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.12.tgz", + "integrity": "sha512-YovQ3rzhaLMIrDjNDMkNS01tea93qhEhG5xy8f6+R0l+dw3Ki+5sCoIoI942iuLZTHWogWktgwVDhU09iNEimQ==", + "license": "MIT", + "dependencies": { + "balanced-match": "^4.0.2" + }, + "engines": { + "node": "20 || >=22" + } + }, "node_modules/braces": { "version": "3.0.3", "dev": true, @@ -11499,18 +11518,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/minimatch/node_modules/brace-expansion": { - "version": "5.0.12", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-5.0.12.tgz", - "integrity": "sha512-YovQ3rzhaLMIrDjNDMkNS01tea93qhEhG5xy8f6+R0l+dw3Ki+5sCoIoI942iuLZTHWogWktgwVDhU09iNEimQ==", - "license": "MIT", - "dependencies": { - "balanced-match": "^4.0.2" - }, - "engines": { - "node": "20 || >=22" - } - }, "node_modules/minimist": { "version": "1.2.8", "dev": true, @@ -13462,13 +13469,13 @@ "license": "MIT" }, "node_modules/rimraf": { - "version": "6.1.3", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-6.1.3.tgz", - "integrity": "sha512-LKg+Cr2ZF61fkcaK1UdkH2yEBBKnYjTyWzTJT6KNPcSPaiT7HSdhtMXQuN5wkTX0Xu72KQ1l8S42rlmexS2hSA==", + "version": "6.1.4", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-6.1.4.tgz", + "integrity": "sha512-Fk3reQDVPZUMbEm7Zwxz03BWQMW3V5buSk9aU8OckTrO8A1nQtbqvYsAantGNermwsIsXcuOBqcoJ3HuMELctw==", "dev": true, "license": "BlueOak-1.0.0", "dependencies": { - "glob": "^13.0.3", + "glob": "^14.0.3", "package-json-from-dist": "^1.0.1" }, "bin": { @@ -13482,15 +13489,15 @@ } }, "node_modules/rimraf/node_modules/glob": { - "version": "13.0.6", - "resolved": "https://registry.npmjs.org/glob/-/glob-13.0.6.tgz", - "integrity": "sha512-Wjlyrolmm8uDpm/ogGyXZXb1Z+Ca2B8NbJwqBVg0axK9GbBeoS7yGV6vjXnYdGm6X53iehEuxxbyiKp8QmN4Vw==", + "version": "14.0.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-14.0.3.tgz", + "integrity": "sha512-A1vjIwC3qpdCso45Iw127gnp7sPhqgY8lUQhDrArIs+GbmfaaVPFuoyy7WyLT9EPZCRZ7j7aLdwUhQmHWesEow==", "dev": true, "license": "BlueOak-1.0.0", "dependencies": { - "minimatch": "^10.2.2", + "minimatch": "^11.0.2", "minipass": "^7.1.3", - "path-scurry": "^2.0.2" + "path-scurry": "^3.0.0" }, "engines": { "node": "18 || 20 || >=22" @@ -13500,19 +13507,36 @@ } }, "node_modules/rimraf/node_modules/lru-cache": { - "version": "11.5.2", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.5.2.tgz", - "integrity": "sha512-4pfM1Ff0x50o0tQwb5ucw/RzNyD0/YJME6IVcStalZuMWxdt3sR3huStTtxz4PUmvZfRguvDejasvQ2kifR11g==", + "version": "11.5.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-11.5.3.tgz", + "integrity": "sha512-U4N8FgzmWxc8k1VH8Kr6lQg18U7Fjvby6wXHVRX/ZZ7IwWbRMgrRbP0Wrb5q5NVinryp4SQampHKdvtecItxUg==", "dev": true, "license": "BlueOak-1.0.0", "engines": { "node": "20 || >=22" } }, + "node_modules/rimraf/node_modules/minimatch": { + "version": "11.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-11.0.4.tgz", + "integrity": "sha512-/UJ1dEoVQTjPNDh6SGlUo+ueLMmoHTas4q+8yaAR/5t6nLAIiBDJtoYUh20IYleix7ehiQkgczb84PE3uzHkxg==", + "dev": true, + "license": "BlueOak-1.0.0", + "dependencies": { + "@isaacs/nonrecursive-glob-match": "^1.0.3", + "brace-expansion": "^5.0.12" + }, + "engines": { + "node": "20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/rimraf/node_modules/path-scurry": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-2.0.2.tgz", - "integrity": "sha512-3O/iVVsJAPsOnpwWIeD+d6z/7PmqApyQePUtCndjatj/9I5LylHvt5qluFaBT3I5h3r1ejfR056c+FCv+NnNXg==", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-3.0.0.tgz", + "integrity": "sha512-1pTbQqH1wIwMi/eleQ5leFTTCkzFsPcgXNjwOA8YGGW/W4/kHT3dssE7Z6NH+zuqNLOzOB0uaD61yl7cAcVhgg==", "dev": true, "license": "BlueOak-1.0.0", "dependencies": { From 080cd7076f2664e6fdf3bb19114376bb2102a53f Mon Sep 17 00:00:00 2001 From: Harshi Shah Date: Tue, 17 Nov 2026 11:04:31 +0530 Subject: [PATCH 2/3] fix(deps): upgrade open to 11 and @oclif/core to 4.14 to clear Snyk findings (#286) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * style: fix existing eslint errors in base-class.ts and open.ts The next commit changes both files, and lint-staged runs eslint --fix on every staged file, so their existing errors would block it. eslint --fix: indentation, quote style, let to const, Array to T[]. By hand: drop an unused catch parameter, wrap two JSDoc lines, and add eslint-disable-next-line for long user-facing strings, one URL and the require() of the user's config file, so none of that text or behaviour changes. No functional change. .talismanrc gets a checksum entry for base-class.ts: Talisman flags the moved "key" type annotations (parseEnvVariablesString, envKeys) as potential secrets; they are not. #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude * fix(deps): upgrade open to 11 and @oclif/core to 4.14 to clear Snyk findings open@8.4.2 (SNYK-JS-OPEN-22112123, High) is fixed only in open 11, which is ESM-only. The CLI compiles to CommonJS, where TypeScript turns import() into require(), so the three browser-open call sites now go through util/open-url.ts, which loads open with a native dynamic import. The GitHub-connect step and launch:open await it, so the process cannot exit before the browser starts; the delayed deployment-URL open keeps its fire-and-forget timer. Opening the browser stays best effort: open 11 rejects when the launcher fails, and every caller prints the URL first, so openUrl swallows that instead of failing the command (or crashing with an unhandled rejection after a successful deploy). @oclif/core moves from 4.11.14 to 4.14.0 within the existing ^4.2.7 range (lockfile only). 4.14 uses ejs 6, which drops the ejs > jake > filelist > minimatch@5.1.9 path behind SNYK-JS-MINIMATCH-22111072. An override pins @oclif/core's own minimatch to ^11.0.1, as on v2-dev. Two findings remain reported, not ignored. Neither has an upgrade, so neither fails --fail-on=all: adm-zip@0.6.1 (SNYK-JS-ADMZIP-21707815), and open@8.4.2 pulled in by @contentstack/cli-utilities, whose latest release (2.0.2) still depends on open ^8.4.2. Integration tests now mock util/open-url instead of open, and stub @oclif/core's getPlatform, which 4.14 implements with a native import('wsl-utils') that Jest's VM cannot run. .talismanrc: base-class.ts checksum refreshed for its new content. #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude * test: keep the integration harness's git calls out of the repo when run from a hook Git exports GIT_DIR and the other repo-local variables to hooks, and the pre-push hook runs npm test. With them set, the harness's git init, config, commit and remote add in its temp projects acted on this repository: a push from a worktree left "initial commit" commits on the branch and set user.name, user.email, commit.gpgsign and core.bare in the shared .git/config. jest.global-setup.ts now clears the variables `git rev-parse --local-env-vars` lists. It runs in Jest's parent process, so the child processes the harness and the CLI spawn inherit the clean environment (setupFiles only change the sandbox's copy of process.env). #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude * fix: address review on the open helper, lockfile and harness docs - open-url.ts: create the dynamic importer lazily inside openUrl's try. Built at module load, new Function threw EvalError under --disallow-code-generation-from-strings, so every command importing the helper crashed instead of just not opening a browser. - openUrl takes an optional loader, and the tests inject a fake open to cover the success path (called with the URL) plus both failure paths, instead of relying on Jest's VM rejecting the native import. - Drop the code comments added in this PR (AGENTS.md: no code comments); the rationale lives in the commit messages and the PR description. - AGENTS.md: the integration harness now replaces src/util/open-url and @oclif/core's getPlatform rather than the open package, and jest.global-setup.ts clears git's repo-local env vars. - @oclif/core range raised to ^4.14.0 so installs cannot keep a 4.11.x that still carries the flagged minimatch path. - package-lock.json: restore the 23 "libc" fields npm 10 dropped, copied from development for the same package versions. npm 11 (release CI) re-resolves the file without changes. #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude * fix: address second review on the harness docs and openUrl tests - AGENTS.md: the "all run for real" sentence had been joined onto the new git-env bullet; it closes the "Only these are replaced" bullet again, so the harness contract reads as before. - open-url.test.ts: the failure-path tests now keep the happy path's assertions (AGENTS.md: do not skip assertions in edge-case tests). The load-failure test checks the loader was called; the open-failure test checks open was called with the URL. #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --------- Co-authored-by: Claude --- .talismanrc | 2 + AGENTS.md | 13 +- package-lock.json | 288 ++++++++++++++++++++++++-- package.json | 9 +- src/adapters/base-class.ts | 84 ++++---- src/commands/launch/open.ts | 16 +- src/util/open-url.test.ts | 31 +++ src/util/open-url.ts | 13 ++ test/integration/jest.global-setup.ts | 8 + test/integration/jest.setup.ts | 10 +- test/integration/specs/open.test.ts | 5 +- 11 files changed, 400 insertions(+), 79 deletions(-) create mode 100644 src/util/open-url.test.ts create mode 100644 src/util/open-url.ts diff --git a/.talismanrc b/.talismanrc index d59b6132..90a75668 100644 --- a/.talismanrc +++ b/.talismanrc @@ -43,4 +43,6 @@ fileignoreconfig: checksum: db8bc45f6d8aa3daebae621920c8618b6e23d1a20984dee0749d91bfa5c1530c - filename: test/unit/base-command.test.ts checksum: 4612c2a41c9d5a7af887f77842feee0a6f6a28ba95a094282b5e9aa20dba6c8c +- filename: src/adapters/base-class.ts + checksum: 75753f8762fc2fd3810672e7070bbdd48b152ec1ad90b18eb1ad5c817a9705aa version: "1.0" diff --git a/AGENTS.md b/AGENTS.md index 5de3c03e..e1020be3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -14,10 +14,15 @@ Integration tests (`test/integration/`) exist to catch what unit tests cannot: they run a real oclif command end to end and assert on what the CLI *does*. - Run them with `npm run test:integration` (they are also part of `npm test`). -- Only three things are replaced: the terminal prompt (`inquirer`), the `open` package, and - the Contentstack management SDK, which resolves its base URL as `https://:443` and so - cannot be pointed at a local server. Apollo, the GraphQL documents, the CLI config store, - flag parsing, the filesystem and `git` all run for real. +- Only these are replaced: the terminal prompt (`inquirer`), the browser opener + (`src/util/open-url`; the CLI never imports the `open` package directly, so mocking `open` has no + effect), `@oclif/core`'s `getPlatform` (it runs a native `import('wsl-utils')` that Jest's VM + cannot execute), and the Contentstack management SDK, which resolves its base URL as + `https://:443` and so cannot be pointed at a local server. Apollo, the GraphQL documents, + the CLI config store, flag parsing, the filesystem and `git` all run for real. +- `jest.global-setup.ts` clears git's repo-local environment variables (`git rev-parse + --local-env-vars`). Git exports them to hooks, and the pre-push hook runs this suite; left set, + the harness's git calls in its temp projects would act on this repository instead. - The Launch API is a local HTTP server (`test/integration/harness/launch-api.ts`) that the CLI reaches through a temporary region config. It records every GraphQL operation, so tests assert on the operations and variables the CLI actually sent rather than on internal method calls. diff --git a/package-lock.json b/package-lock.json index cf011a90..cd038d78 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@apollo/client": "^3.14.0", "@contentstack/cli-command": "^2.0.2", "@contentstack/cli-utilities": "^2.0.2", - "@oclif/core": "^4.2.7", + "@oclif/core": "^4.14.0", "@oclif/plugin-help": "^6.2.25", "@rollup/plugin-commonjs": "^28.0.2", "@rollup/plugin-json": "^6.1.0", @@ -29,7 +29,7 @@ "graphql": "^16.9.0", "ini": "^3.0.1", "lodash": "^4.18.1", - "open": "^8.4.2", + "open": "^11.0.4", "rollup": "^4.59.0", "winston": "^3.17.0" }, @@ -929,6 +929,44 @@ "url": "https://github.com/chalk/chalk?sponsor=1" } }, + "node_modules/@contentstack/cli-utilities/node_modules/define-lazy-prop": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/define-lazy-prop/-/define-lazy-prop-2.0.0.tgz", + "integrity": "sha512-Ds09qNh8yw3khSjiJjiUInaGX9xlqZDY7JVryGxdxV7NPeuqQfplOpQ66yJFZut3jLa5zOwkXw1g9EI2uKh4Og==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/@contentstack/cli-utilities/node_modules/is-wsl": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz", + "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==", + "license": "MIT", + "dependencies": { + "is-docker": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/@contentstack/cli-utilities/node_modules/open": { + "version": "8.4.2", + "resolved": "https://registry.npmjs.org/open/-/open-8.4.2.tgz", + "integrity": "sha512-7x81NCL719oNbsq/3mh+hVrAWmFuEYUqrq/Iw3kUzH8ReypT9QQ0BLoJS7/G9k6N81XjW4qHWtjWwe/9eLy1EQ==", + "license": "MIT", + "dependencies": { + "define-lazy-prop": "^2.0.0", + "is-docker": "^2.1.1", + "is-wsl": "^2.2.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@contentstack/management": { "version": "1.31.2", "resolved": "https://registry.npmjs.org/@contentstack/management/-/management-1.31.2.tgz", @@ -2479,10 +2517,9 @@ } }, "node_modules/@isaacs/nonrecursive-glob-match": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@isaacs/nonrecursive-glob-match/-/nonrecursive-glob-match-1.0.3.tgz", - "integrity": "sha512-SI7kyKHq4XXDRozw+r9GlRZkia1ZkFrpLW98r2IC2Bpr8YkFGE3fvjzmxCG0x78A++69HmDNrDvSMYBZmHGpKA==", - "dev": true, + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@isaacs/nonrecursive-glob-match/-/nonrecursive-glob-match-1.1.0.tgz", + "integrity": "sha512-GPm/Dbvk5RLmhRnxXIa7nTpK0xtl4E0wj0MslsuNiJ1FIROU+2+9lgUC/dgF7Ey4QCWhfEsgxilMRMCdHPfDfw==", "license": "BlueOak-1.0.0" }, "node_modules/@istanbuljs/load-nyc-config": { @@ -2974,7 +3011,9 @@ } }, "node_modules/@oclif/core": { - "version": "4.11.14", + "version": "4.14.0", + "resolved": "https://registry.npmjs.org/@oclif/core/-/core-4.14.0.tgz", + "integrity": "sha512-QCJIZoVJxV7jywgVAUlsQwl3dr3Sa21kfi5z9KrYolbexWJUtFSEtMoNiBWojD05mYycLnB50gp/VxlGdaOCRA==", "license": "MIT", "dependencies": { "ansi-escapes": "^4.3.2", @@ -2982,10 +3021,9 @@ "clean-stack": "^3.0.1", "cli-spinners": "^2.9.2", "debug": "^4.4.3", - "ejs": "^3.1.10", + "ejs": "^6", "get-package-type": "^0.1.0", "indent-string": "^4.0.0", - "is-wsl": "^2.2.0", "lilconfig": "^3.1.3", "minimatch": "^10.2.5", "semver": "^7.8.1", @@ -2994,12 +3032,69 @@ "tinyglobby": "^0.2.17", "widest-line": "^3.1.0", "wordwrap": "^1.0.0", - "wrap-ansi": "^7.0.0" + "wrap-ansi": "^7.0.0", + "wsl-utils": "^0.4.0" }, "engines": { "node": ">=18.0.0" } }, + "node_modules/@oclif/core/node_modules/ejs": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/ejs/-/ejs-6.0.1.tgz", + "integrity": "sha512-UaaM14yby8U3k02ihS1Bmj5Kz2d7CCQM1scxpgs4Mhkq8F1wR2gl3+Ts4h5Ne4Mnt7M9m4Dw7jsuMr3+xO4vZA==", + "license": "Apache-2.0", + "bin": { + "ejs": "bin/cli.js" + }, + "engines": { + "node": ">=0.12.18" + } + }, + "node_modules/@oclif/core/node_modules/minimatch": { + "version": "11.0.8", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-11.0.8.tgz", + "integrity": "sha512-nFQuYSTVrGvysVBps5Ih+0BdnYFN/Cj3C816r6+p7yK+FHrVLGE4O4N9AFwykrlNlvM2HYt+Rad1Uiro6h88Ig==", + "license": "BlueOak-1.0.0", + "dependencies": { + "@isaacs/nonrecursive-glob-match": "^1.1.0", + "brace-expansion": "^5.0.12" + }, + "engines": { + "node": "20 || >=22" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@oclif/core/node_modules/powershell-utils": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/powershell-utils/-/powershell-utils-0.1.0.tgz", + "integrity": "sha512-dM0jVuXJPsDN6DvRpea484tCUaMiXWjuCn++HGTqUWzGDjv5tZkEZldAJ/UMlqRYGFrD/etByo4/xOuC/snX2A==", + "license": "MIT", + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@oclif/core/node_modules/wsl-utils": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/wsl-utils/-/wsl-utils-0.4.0.tgz", + "integrity": "sha512-9YmF+2sFEd+T7TkwlmE337F0IVzfDvDknhtpBQxxXzEOfgPphGlFYpyx0cTuCIFj8/p+sqwBYAeGxOMNSzPPDA==", + "license": "MIT", + "dependencies": { + "is-wsl": "^3.1.0", + "powershell-utils": "^0.1.0" + }, + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@oclif/plugin-help": { "version": "6.2.53", "license": "MIT", @@ -5452,6 +5547,21 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/bundle-name": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/bundle-name/-/bundle-name-4.1.1.tgz", + "integrity": "sha512-DdH81/zPLVS11EUgWq3tEu/xn+EzljlMYooDNdzWEnFha3R3NBMpMV1UqYIpjYHV/SgpFKMIX1Oh7o06SjM/oA==", + "license": "MIT", + "dependencies": { + "run-applescript": "^7.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/bytes": { "version": "3.1.2", "license": "MIT", @@ -6371,6 +6481,34 @@ "node": ">=0.10.0" } }, + "node_modules/default-browser": { + "version": "5.5.1", + "resolved": "https://registry.npmjs.org/default-browser/-/default-browser-5.5.1.tgz", + "integrity": "sha512-m1pAzaJgZ/gssEqlOhJkPJp8Xly7QyW6xcrkUa2KKcDeDSEMP7X8xipU3snUcfisTQx0w1AGae+9UtJSfVnXGw==", + "license": "MIT", + "dependencies": { + "bundle-name": "^4.1.0", + "default-browser-id": "^5.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/default-browser-id": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/default-browser-id/-/default-browser-id-5.0.1.tgz", + "integrity": "sha512-x1VCxdX4t+8wVfd1so/9w+vQ4vx7lKd2Qp5tDRutErwmR85OgmfX7RlLRMWafRMY7hbEiXIbudNrjOAPa/hL8Q==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/default-require-extensions": { "version": "3.0.1", "dev": true, @@ -6421,10 +6559,15 @@ } }, "node_modules/define-lazy-prop": { - "version": "2.0.0", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/define-lazy-prop/-/define-lazy-prop-3.0.0.tgz", + "integrity": "sha512-N+MeXYoqr3pOgn8xfyRPREN7gHakLYjhsHhWGT3fWAiL4IkAt0iDw14QiiEm2bE30c5XX5q0FtAA3CK5f9/BUg==", "license": "MIT", "engines": { - "node": ">=8" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/define-properties": { @@ -6558,6 +6701,7 @@ }, "node_modules/ejs": { "version": "3.1.10", + "dev": true, "license": "Apache-2.0", "dependencies": { "jake": "^10.8.5" @@ -7815,6 +7959,7 @@ }, "node_modules/filelist": { "version": "1.0.6", + "dev": true, "license": "Apache-2.0", "dependencies": { "minimatch": "^5.0.1" @@ -7822,12 +7967,14 @@ }, "node_modules/filelist/node_modules/balanced-match": { "version": "1.0.2", + "dev": true, "license": "MIT" }, "node_modules/filelist/node_modules/brace-expansion": { "version": "2.1.7", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.1.7.tgz", "integrity": "sha512-uZbew1NqdmPDTMJ8ah1y+b+9QEJrfkXFk3RcTQw3X0jW/xRUvFKsg1CfQdSYGdTbXZWExtU3J3ccxtnfw1Fi0g==", + "dev": true, "license": "MIT", "dependencies": { "balanced-match": "^1.0.0" @@ -7835,6 +7982,7 @@ }, "node_modules/filelist/node_modules/minimatch": { "version": "5.1.9", + "dev": true, "license": "ISC", "dependencies": { "brace-expansion": "^2.0.1" @@ -9561,6 +9709,8 @@ }, "node_modules/is-docker": { "version": "2.2.1", + "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz", + "integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==", "license": "MIT", "bin": { "is-docker": "cli.js" @@ -9653,6 +9803,51 @@ "node": ">=0.10.0" } }, + "node_modules/is-in-ssh": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-in-ssh/-/is-in-ssh-1.0.0.tgz", + "integrity": "sha512-jYa6Q9rH90kR1vKB6NM7qqd1mge3Fx4Dhw5TVlK1MUBqhEOuCagrEHMevNuCcbECmXZ0ThXkRm+Ymr51HwEPAw==", + "license": "MIT", + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/is-inside-container": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-inside-container/-/is-inside-container-1.0.0.tgz", + "integrity": "sha512-KIYLCCJghfHZxqjYBE7rEy0OBuTd5xCHS7tHVgvCLkx7StIoaxwNW3hCALgEUjFfeRk+MG/Qxmp/vtETEF3tRA==", + "license": "MIT", + "dependencies": { + "is-docker": "^3.0.0" + }, + "bin": { + "is-inside-container": "cli.js" + }, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/is-inside-container/node_modules/is-docker": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-3.0.0.tgz", + "integrity": "sha512-eljcgEDlEns/7AXFosB5K/2nCM4P7FQPkGc/DWLy5rmFEWvZayGrik1d9/QIY5nJ4f9YsVvBkA6kJpHn9rISdQ==", + "license": "MIT", + "bin": { + "is-docker": "cli.js" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/is-interactive": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-interactive/-/is-interactive-1.0.0.tgz", @@ -9918,13 +10113,18 @@ } }, "node_modules/is-wsl": { - "version": "2.2.0", + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-3.1.1.tgz", + "integrity": "sha512-e6rvdUCiQCAuumZslxRJWR/Doq4VpPR82kqclvcS0efgt430SlGIk05vdCN58+VrzgtIcfNODjozVielycD4Sw==", "license": "MIT", "dependencies": { - "is-docker": "^2.0.0" + "is-inside-container": "^1.0.0" }, "engines": { - "node": ">=8" + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/isarray": { @@ -10052,6 +10252,7 @@ }, "node_modules/jake": { "version": "10.9.4", + "dev": true, "license": "Apache-2.0", "dependencies": { "async": "^3.2.6", @@ -11507,6 +11708,7 @@ }, "node_modules/minimatch": { "version": "10.2.5", + "dev": true, "license": "BlueOak-1.0.0", "dependencies": { "brace-expansion": "^5.0.5" @@ -12286,15 +12488,20 @@ } }, "node_modules/open": { - "version": "8.4.2", + "version": "11.0.4", + "resolved": "https://registry.npmjs.org/open/-/open-11.0.4.tgz", + "integrity": "sha512-++Zlftm0kVLPmzC06t6epuWmcRMDbI4z5P3NNX979WA/k23+NtSOynEGzsVfZwguKw2mi5umVgnBlJQMwRz4Pg==", "license": "MIT", "dependencies": { - "define-lazy-prop": "^2.0.0", - "is-docker": "^2.1.1", - "is-wsl": "^2.2.0" + "default-browser": "^5.5.1", + "define-lazy-prop": "^3.0.0", + "is-in-ssh": "^1.0.0", + "is-inside-container": "^1.0.0", + "powershell-utils": "^0.2.1", + "wsl-utils": "^1.0.0" }, "engines": { - "node": ">=12" + "node": ">=20" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -12607,6 +12814,7 @@ }, "node_modules/picocolors": { "version": "1.1.1", + "dev": true, "license": "ISC" }, "node_modules/picomatch": { @@ -12785,6 +12993,18 @@ "node": ">= 0.4" } }, + "node_modules/powershell-utils": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/powershell-utils/-/powershell-utils-0.2.1.tgz", + "integrity": "sha512-C+y9x90UElAddDZmV4qOx9W53B61PO7cIqWz2dQsWlwswuq4mr8NEwytdGKboYbQlGZ3awrkTeNvcZiZNHnQ8A==", + "license": "MIT", + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/prelude-ls": { "version": "1.2.1", "dev": true, @@ -13592,6 +13812,18 @@ "fsevents": "~2.3.2" } }, + "node_modules/run-applescript": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/run-applescript/-/run-applescript-7.1.0.tgz", + "integrity": "sha512-DPe5pVFaAsinSaV6QjQ6gdiedWDcRCbUuiQfQa2wmWV7+xC9bGulGI8+TdRmoFkAPaBXk8CrAbnlY2ISniJ47Q==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/run-async": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/run-async/-/run-async-4.0.6.tgz", @@ -15786,6 +16018,22 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/wsl-utils": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/wsl-utils/-/wsl-utils-1.0.1.tgz", + "integrity": "sha512-c16PKLIRxBYpR3jSWsdS7SFp0COm5SOQdiFjY818dYFHJbMGuLBszpF07LBWmOS1uzrHa9VGdynsEgoeKy0oOQ==", + "license": "MIT", + "dependencies": { + "is-wsl": "^3.1.0", + "powershell-utils": "^0.2.0" + }, + "engines": { + "node": ">=20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/xdg-basedir": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-4.0.0.tgz", diff --git a/package.json b/package.json index 6bc8f8ce..b0ee06a4 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "@apollo/client": "^3.14.0", "@contentstack/cli-command": "^2.0.2", "@contentstack/cli-utilities": "^2.0.2", - "@oclif/core": "^4.2.7", + "@oclif/core": "^4.14.0", "@oclif/plugin-help": "^6.2.25", "@rollup/plugin-commonjs": "^28.0.2", "@rollup/plugin-json": "^6.1.0", @@ -40,7 +40,7 @@ "graphql": "^16.9.0", "ini": "^3.0.1", "lodash": "^4.18.1", - "open": "^8.4.2", + "open": "^11.0.4", "rollup": "^4.59.0", "winston": "^3.17.0" }, @@ -114,7 +114,10 @@ }, "tmp": "^0.2.4", "serialize-javascript": "^7.1.0", - "diff": "^8.0.3" + "diff": "^8.0.3", + "@oclif/core": { + "minimatch": "^11.0.1" + } }, "engines": { "node": ">=22.0.0" diff --git a/src/adapters/base-class.ts b/src/adapters/base-class.ts index 796eff2d..d6b7e557 100755 --- a/src/adapters/base-class.ts +++ b/src/adapters/base-class.ts @@ -1,4 +1,3 @@ -import open from 'open'; import dotEnv from 'dotenv'; import map from 'lodash/map'; import keys from 'lodash/keys'; @@ -19,6 +18,7 @@ import { writeFileSync, existsSync, readFileSync } from 'fs'; import { cliux as ux, ContentstackClient } from '@contentstack/cli-utilities'; import { print, GraphqlApiClient, LogPolling, getOrganizations } from '../util'; +import { openUrl } from '../util/open-url'; import { FILE_UPLOAD_SIZE_LIMIT_USER_MESSAGE, isLaunchDeploymentFileSizeRelatedError } from '../util/deployment-errors'; import { branchesQuery, @@ -50,7 +50,7 @@ export default class BaseClass { public apolloClient: ApolloClient; public projectCreationRetryCount: number = 0; public apolloLogsClient: ApolloClient | undefined; - public envVariables: Array> = []; + public envVariables: Record[] = []; public managementSdk: ContentstackClient | undefined; constructor(options: AdapterConstructorInputs) { @@ -165,16 +165,16 @@ export default class BaseClass { const variables = this.config.provider === 'FileUpload' ? { - query: { uploadUid: this.config.uploadUid }, - } + query: { uploadUid: this.config.uploadUid }, + } : { - query: { - provider: this.config.provider, - repoName: fullName, - branchName: defaultBranch, - ...(namespace ? { namespace } : {}), - }, - }; + query: { + provider: this.config.provider, + repoName: fullName, + branchName: defaultBranch, + ...(namespace ? { namespace } : {}), + }, + }; this.config.framework = (await this.apolloClient .query({ query, variables }) .then( @@ -184,7 +184,7 @@ export default class BaseClass { }, }) => framework, ) - .catch((_error) => { + .catch(() => { // this.log("Something went wrong. Please try again.", "warn"); // this.log(error, "error"); // this.exit(1); @@ -249,6 +249,7 @@ export default class BaseClass { if (listOfStacks.length === 0) { this.log( + // eslint-disable-next-line max-len 'No stacks were found in your organization, or you do not have access to any. Please create a stack in the organization to proceed in the organization.', 'error', ); @@ -327,7 +328,7 @@ export default class BaseClass { * @return {*} {Array<{key: string, value: string}>} * @memberof BaseClass */ - private parseEnvVariablesString(envString: string): Array<{ key: string; value: string }> { + private parseEnvVariablesString(envString: string): { key: string; value: string }[] { return map(split(envString, ','), (pair) => { const trimmedPair = (pair as string).trim(); const colonIndex = trimmedPair.indexOf(':'); @@ -354,6 +355,7 @@ export default class BaseClass { type: 'input', name: 'variable', message: + // eslint-disable-next-line max-len 'Enter key and value with a colon between them, and use a comma(,) for the key-value pair. Format: :, : Ex: APP_ENV:prod, TEST_ENV:testVal', }) .then((variable) => this.parseEnvVariablesString(variable as string)); @@ -389,6 +391,7 @@ export default class BaseClass { let data: Record = {}; if (this.config.config && existsSync(this.config.config)) { + // eslint-disable-next-line @typescript-eslint/no-require-imports data = require(this.config.config); } @@ -416,10 +419,11 @@ export default class BaseClass { if (includes(this.config.supportedAdapters, this.config.provider)) { const baseUrl = this.config.host.startsWith('http') ? this.config.host : `https://${this.config.host}`; + // eslint-disable-next-line max-len const gitHubConnectUrl = `${baseUrl.replace('api', 'app').replace('io', 'com')}/#!/launch/settings/connected-accounts`; this.log(`You can connect your ${this.config.provider} account to the UI using the following URL:`, 'info'); this.log(gitHubConnectUrl, { color: 'green' }); - open(gitHubConnectUrl); + await openUrl(gitHubConnectUrl); this.exit(1); } else if (emit) { this.$event.emit('provider-changed'); @@ -505,7 +509,7 @@ export default class BaseClass { */ inquireRequireValidation(input: any): string | boolean { if (isEmpty(input)) { - return "This field can't be empty."; + return 'This field can\'t be empty.'; } return true; @@ -540,7 +544,8 @@ export default class BaseClass { variablePreparationType.length > 1 ) { this.log( - "The 'Skip adding environment variables' option cannot be combined with other environment variable options. Please choose either 'Skip adding environment variables' or one or more of the other available options.", + // eslint-disable-next-line max-len + 'The \'Skip adding environment variables\' option cannot be combined with other environment variable options. Please choose either \'Skip adding environment variables\' or one or more of the other available options.', 'error', ); this.exit(1); @@ -585,7 +590,7 @@ export default class BaseClass { this.exit(1); } if (!isEmpty(localEnv)) { - let envKeys: Record = keys(localEnv); + const envKeys: Record = keys(localEnv); const existingEnvKeys = map(this.envVariables, 'key'); const localEnvData = map(envKeys, (key) => ({ key, @@ -630,22 +635,22 @@ export default class BaseClass { this.envVariables = map(cloneDeep(this.envVariables), (variable) => { switch (variable.key) { - case 'CONTENTSTACK_API_HOST': - case 'CONTENTSTACK_CDN': - if (variable.value.startsWith('http')) { - const url = new URL(variable.value); - variable.value = url?.host || this.config.host; - } - break; - case 'CONTENTSTACK_ENVIRONMENT': - variable.value = this.config.stackEnvironment; - break; - case 'CONTENTSTACK_API_KEY': - variable.value = this.config.selectedStack.api_key; - break; - case 'CONTENTSTACK_DELIVERY_TOKEN': - variable.value = this.config.deliveryToken?.token; - break; + case 'CONTENTSTACK_API_HOST': + case 'CONTENTSTACK_CDN': + if (variable.value.startsWith('http')) { + const url = new URL(variable.value); + variable.value = url?.host || this.config.host; + } + break; + case 'CONTENTSTACK_ENVIRONMENT': + variable.value = this.config.stackEnvironment; + break; + case 'CONTENTSTACK_API_KEY': + variable.value = this.config.selectedStack.api_key; + break; + case 'CONTENTSTACK_DELIVERY_TOKEN': + variable.value = this.config.deliveryToken?.token; + break; } return variable; @@ -662,9 +667,9 @@ export default class BaseClass { ...(this.config.flags['show-variables'] ? this.envVariables : this.envVariables.map(({ key, value }) => ({ - key, - value: replace(value, /./g, '*'), - }))), + key, + value: replace(value, /./g, '*'), + }))), ]; const headers = [{ value: 'key' }, { value: 'value' }]; @@ -710,7 +715,7 @@ export default class BaseClass { if (msgType === 'info') { forEach(message, (log: DeploymentLogResp | ServerLogResp) => { - let formattedLogTimestamp = new Date(log.timestamp).toISOString()?.slice(0, 23)?.replace('T', ' '); + const formattedLogTimestamp = new Date(log.timestamp).toISOString()?.slice(0, 23)?.replace('T', ' '); this.log(`${formattedLogTimestamp}: ${log.message}`, msgType); }); } else if (msgType === 'error') { @@ -740,7 +745,7 @@ export default class BaseClass { await ux.inquire({ type: 'confirm', name: 'deployLatestSource', - message: "Would you like to change the project's name and try again?", + message: 'Would you like to change the project\'s name and try again?', }) ) { this.config.projectName = await ux.inquire({ @@ -781,6 +786,7 @@ export default class BaseClass { if (!environment) { this.log( + // eslint-disable-next-line max-len `Environment "${environmentFlagInput}" not found in this project. Please provide a valid environment name or UID.`, 'error', ); @@ -828,7 +834,7 @@ export default class BaseClass { if (openOnUi) { // NOTE delaying to open the deployment url. If we open quickly it's showing site not reachable setTimeout(() => { - open(deploymentUrl); + openUrl(deploymentUrl); }, 6000); } } diff --git a/src/commands/launch/open.ts b/src/commands/launch/open.ts index 76a6c244..e3925896 100755 --- a/src/commands/launch/open.ts +++ b/src/commands/launch/open.ts @@ -1,4 +1,3 @@ -import open from 'open'; import map from 'lodash/map'; import find from 'lodash/find'; import isEmpty from 'lodash/isEmpty'; @@ -7,6 +6,7 @@ import { FlagInput, Flags, cliux as ux } from '@contentstack/cli-utilities'; import { BaseCommand } from '../../base-command'; import { environmentsQuery } from '../../graphql'; import { print, Logger, selectOrg, selectProject } from '../../util'; +import { openUrl } from '../../util/open-url'; export default class Open extends BaseCommand { static description = 'Open a website for an environment'; @@ -44,7 +44,7 @@ export default class Open extends BaseCommand { if (!this.flags.environment) await this.getConfig(); if (this.sharedConfig.currentConfig?.uid && !isEmpty(this.sharedConfig.currentConfig?.deployments)) { - this.openWebsite(); + await this.openWebsite(); } else { await this.prepareProjectDetails(); } @@ -55,7 +55,7 @@ export default class Open extends BaseCommand { * * @memberof Open */ - openWebsite() { + async openWebsite(): Promise { const [deployment] = this.sharedConfig.currentConfig?.deployments || []; if (!isEmpty(deployment)) { @@ -66,7 +66,7 @@ export default class Open extends BaseCommand { { message: 'Deployment URL', bold: true }, { message: deploymentUrl, color: 'cyan' }, ]); - open(deploymentUrl); + await openUrl(deploymentUrl); } else { this.log('Website URL not found.!', 'error'); this.exit(1); @@ -74,7 +74,8 @@ export default class Open extends BaseCommand { } /** - * @method checkAndSetProjectDetails - validate and set project details (ex. organizationUid, uid, environment, deployment) + * @method checkAndSetProjectDetails - validate and set project details + * (ex. organizationUid, uid, environment, deployment) * * @return {*} {Promise} * @memberof Logs @@ -100,11 +101,12 @@ export default class Open extends BaseCommand { await this.validateAndSelectEnvironment(); - this.openWebsite(); + await this.openWebsite(); } /** - * @method validateAndSelectEnvironment - check whether environment is validate or not. If not then option to select environment + * @method validateAndSelectEnvironment - check whether environment is validate or not. + * If not then option to select environment * * @return {*} {Promise} * @memberof Logs diff --git a/src/util/open-url.test.ts b/src/util/open-url.test.ts new file mode 100644 index 00000000..c58f67ca --- /dev/null +++ b/src/util/open-url.test.ts @@ -0,0 +1,31 @@ +import { openUrl } from './open-url'; + +describe('openUrl', () => { + it('opens the URL with the loaded open package', async () => { + const open = jest.fn(async () => undefined); + + await openUrl('https://example.com', async () => ({ default: open })); + + expect(open).toHaveBeenCalledWith('https://example.com'); + }); + + it('resolves when the open package cannot be loaded', async () => { + const load = jest.fn(async () => { + throw new Error('load failed'); + }); + + await expect(openUrl('https://example.com', load)).resolves.toBeUndefined(); + + expect(load).toHaveBeenCalledTimes(1); + }); + + it('resolves when opening the browser fails', async () => { + const open = jest.fn(async () => { + throw new Error('spawn failed'); + }); + + await expect(openUrl('https://example.com', async () => ({ default: open }))).resolves.toBeUndefined(); + + expect(open).toHaveBeenCalledWith('https://example.com'); + }); +}); diff --git a/src/util/open-url.ts b/src/util/open-url.ts new file mode 100644 index 00000000..b76cee82 --- /dev/null +++ b/src/util/open-url.ts @@ -0,0 +1,13 @@ +type OpenModule = { default: (target: string) => Promise }; +type LoadOpen = () => Promise; + +const loadOpen: LoadOpen = async () => new Function('return import("open")')() as Promise; + +export async function openUrl(url: string, load: LoadOpen = loadOpen): Promise { + try { + const { default: open } = await load(); + await open(url); + } catch { + return; + } +} diff --git a/test/integration/jest.global-setup.ts b/test/integration/jest.global-setup.ts index 72eb2117..22f06ac0 100644 --- a/test/integration/jest.global-setup.ts +++ b/test/integration/jest.global-setup.ts @@ -10,6 +10,13 @@ const TEMP_PREFIXES = [ ]; const STALE_AFTER_MS = 60 * 60 * 1000; +const GIT_LOCAL_ENV_VARS = [ + 'GIT_ALTERNATE_OBJECT_DIRECTORIES', 'GIT_CONFIG', 'GIT_CONFIG_PARAMETERS', 'GIT_CONFIG_COUNT', + 'GIT_OBJECT_DIRECTORY', 'GIT_DIR', 'GIT_WORK_TREE', 'GIT_IMPLICIT_WORK_TREE', 'GIT_GRAFT_FILE', + 'GIT_INDEX_FILE', 'GIT_NO_REPLACE_OBJECTS', 'GIT_REPLACE_REF_BASE', 'GIT_PREFIX', 'GIT_SHALLOW_FILE', + 'GIT_COMMON_DIR', +]; + const sweepStaleTempDirs = (): void => { const now = Date.now(); for (const entry of readdirSync(tmpdir())) { @@ -26,6 +33,7 @@ const sweepStaleTempDirs = (): void => { }; export default async function globalSetup(): Promise { + for (const name of GIT_LOCAL_ENV_VARS) delete process.env[name]; sweepStaleTempDirs(); process.env.LAUNCH_CLI_ITEST_RUN_DIR = mkdtempSync(join(tmpdir(), 'launch-cli-itest-run-')); } diff --git a/test/integration/jest.setup.ts b/test/integration/jest.setup.ts index be9e0ac7..080141a0 100644 --- a/test/integration/jest.setup.ts +++ b/test/integration/jest.setup.ts @@ -1,6 +1,10 @@ -jest.mock('open', () => ({ - __esModule: true, - default: jest.fn(async () => ({ pid: 1 })), +jest.mock('../../src/util/open-url', () => ({ + openUrl: jest.fn(async () => undefined), +})); + +jest.mock(`${process.cwd()}/node_modules/@oclif/core/lib/util/os.js`, () => ({ + ...jest.requireActual(`${process.cwd()}/node_modules/@oclif/core/lib/util/os.js`), + getPlatform: async () => require('node:os').platform(), })); jest.mock('@contentstack/cli-utilities/lib/contentstack-management-sdk', () => ({ diff --git a/test/integration/specs/open.test.ts b/test/integration/specs/open.test.ts index 04879bcb..bc5fd467 100644 --- a/test/integration/specs/open.test.ts +++ b/test/integration/specs/open.test.ts @@ -1,9 +1,8 @@ -import open from 'open'; - import Open from '../../../src/commands/launch/open'; +import { openUrl } from '../../../src/util/open-url'; import { cma, fixtures, prompts, runCommand, Session, startSession } from '../harness'; -const openMock = open as unknown as jest.Mock; +const openMock = openUrl as unknown as jest.Mock; describe('launch:open', () => { let session: Session; From f6f75034cd5148c10bb541dede2f9586533d7a14 Mon Sep 17 00:00:00 2001 From: Harshi Shah Date: Tue, 17 Nov 2026 11:12:47 +0530 Subject: [PATCH 3/3] fix(deps): declare tslib as a runtime dependency (#287) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * style: fix existing eslint errors in base-class.ts and open.ts The next commit changes both files, and lint-staged runs eslint --fix on every staged file, so their existing errors would block it. eslint --fix: indentation, quote style, let to const, Array to T[]. By hand: drop an unused catch parameter, wrap two JSDoc lines, and add eslint-disable-next-line for long user-facing strings, one URL and the require() of the user's config file, so none of that text or behaviour changes. No functional change. .talismanrc gets a checksum entry for base-class.ts: Talisman flags the moved "key" type annotations (parseEnvVariablesString, envKeys) as potential secrets; they are not. #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude * fix(deps): upgrade open to 11 and @oclif/core to 4.14 to clear Snyk findings open@8.4.2 (SNYK-JS-OPEN-22112123, High) is fixed only in open 11, which is ESM-only. The CLI compiles to CommonJS, where TypeScript turns import() into require(), so the three browser-open call sites now go through util/open-url.ts, which loads open with a native dynamic import. The GitHub-connect step and launch:open await it, so the process cannot exit before the browser starts; the delayed deployment-URL open keeps its fire-and-forget timer. Opening the browser stays best effort: open 11 rejects when the launcher fails, and every caller prints the URL first, so openUrl swallows that instead of failing the command (or crashing with an unhandled rejection after a successful deploy). @oclif/core moves from 4.11.14 to 4.14.0 within the existing ^4.2.7 range (lockfile only). 4.14 uses ejs 6, which drops the ejs > jake > filelist > minimatch@5.1.9 path behind SNYK-JS-MINIMATCH-22111072. An override pins @oclif/core's own minimatch to ^11.0.1, as on v2-dev. Two findings remain reported, not ignored. Neither has an upgrade, so neither fails --fail-on=all: adm-zip@0.6.1 (SNYK-JS-ADMZIP-21707815), and open@8.4.2 pulled in by @contentstack/cli-utilities, whose latest release (2.0.2) still depends on open ^8.4.2. Integration tests now mock util/open-url instead of open, and stub @oclif/core's getPlatform, which 4.14 implements with a native import('wsl-utils') that Jest's VM cannot run. .talismanrc: base-class.ts checksum refreshed for its new content. #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude * test: keep the integration harness's git calls out of the repo when run from a hook Git exports GIT_DIR and the other repo-local variables to hooks, and the pre-push hook runs npm test. With them set, the harness's git init, config, commit and remote add in its temp projects acted on this repository: a push from a worktree left "initial commit" commits on the branch and set user.name, user.email, commit.gpgsign and core.bare in the shared .git/config. jest.global-setup.ts now clears the variables `git rev-parse --local-env-vars` lists. It runs in Jest's parent process, so the child processes the harness and the CLI spawn inherit the clean environment (setupFiles only change the sandbox's copy of process.env). #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude * fix(deps): declare tslib as a runtime dependency tsconfig sets importHelpers, so the compiled commands require tslib at runtime, but it was declared only as a devDependency. When csdx installs @contentstack/cli-launch as a plugin it skips devDependencies, so a strict install (pnpm) fails every launch command with "Cannot find module 'tslib'" (#194). Default npm installs only survived because tslib was hoisted from another package. Also drop @oclif/plugin-plugins from oclif.plugins. Its dependency was removed in February, so oclif already skipped the entry; help output and the generated manifest are unchanged without it. Add the dependency guard test from v2-dev (dc69e11). It compiles every runtime source with the project's compiler options and fails on any required package, or oclif.plugins entry, that is not a production dependency. #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude * fix: address review on the open helper, lockfile and harness docs - open-url.ts: create the dynamic importer lazily inside openUrl's try. Built at module load, new Function threw EvalError under --disallow-code-generation-from-strings, so every command importing the helper crashed instead of just not opening a browser. - openUrl takes an optional loader, and the tests inject a fake open to cover the success path (called with the URL) plus both failure paths, instead of relying on Jest's VM rejecting the native import. - Drop the code comments added in this PR (AGENTS.md: no code comments); the rationale lives in the commit messages and the PR description. - AGENTS.md: the integration harness now replaces src/util/open-url and @oclif/core's getPlatform rather than the open package, and jest.global-setup.ts clears git's repo-local env vars. - @oclif/core range raised to ^4.14.0 so installs cannot keep a 4.11.x that still carries the flagged minimatch path. - package-lock.json: restore the 23 "libc" fields npm 10 dropped, copied from development for the same package versions. npm 11 (release CI) re-resolves the file without changes. #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude * test: catch single-quoted and string-built imports in the dependency guard The guard only matched double-quoted require("x"). TypeScript emits a dynamic import('x') as require('x') with single quotes, and the open helper builds import("open") inside a string passed to new Function, so an undeclared package pulled in either way passed the guard and then failed at runtime. It now matches require(...) and import(...) with either quote style, and asserts that open is detected. #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude * fix: address second review on the harness docs and openUrl tests - AGENTS.md: the "all run for real" sentence had been joined onto the new git-env bullet; it closes the "Only these are replaced" bullet again, so the harness contract reads as before. - open-url.test.ts: the failure-path tests now keep the happy path's assertions (AGENTS.md: do not skip assertions in edge-case tests). The load-failure test checks the loader was called; the open-failure test checks open was called with the URL. #claude_code# 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --------- Co-authored-by: Claude --- package-lock.json | 2 +- package.json | 5 +- .../specs/package-dependencies.test.ts | 95 +++++++++++++++++++ 3 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 test/integration/specs/package-dependencies.test.ts diff --git a/package-lock.json b/package-lock.json index cd038d78..5e3995f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,6 +31,7 @@ "lodash": "^4.18.1", "open": "^11.0.4", "rollup": "^4.59.0", + "tslib": "^2.8.1", "winston": "^3.17.0" }, "bin": { @@ -58,7 +59,6 @@ "sinon": "^19.0.2", "ts-jest": "^29.3.1", "ts-node": "^10.9.2", - "tslib": "^2.8.1", "typescript": "^5.8.3" }, "engines": { diff --git a/package.json b/package.json index b0ee06a4..065cc997 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "lodash": "^4.18.1", "open": "^11.0.4", "rollup": "^4.59.0", + "tslib": "^2.8.1", "winston": "^3.17.0" }, "devDependencies": { @@ -66,15 +67,13 @@ "sinon": "^19.0.2", "ts-jest": "^29.3.1", "ts-node": "^10.9.2", - "tslib": "^2.8.1", "typescript": "^5.8.3" }, "oclif": { "bin": "csdx", "commands": "./dist/commands", "plugins": [ - "@oclif/plugin-help", - "@oclif/plugin-plugins" + "@oclif/plugin-help" ], "topicSeparator": ":", "additionalHelpFlags": [ diff --git a/test/integration/specs/package-dependencies.test.ts b/test/integration/specs/package-dependencies.test.ts new file mode 100644 index 00000000..8d447f0d --- /dev/null +++ b/test/integration/specs/package-dependencies.test.ts @@ -0,0 +1,95 @@ +import { readdirSync, readFileSync } from 'node:fs'; +import { builtinModules } from 'node:module'; +import { join, relative, resolve as resolvePath } from 'node:path'; + +import * as ts from 'typescript'; + +const projectRoot = resolvePath(__dirname, '..', '..', '..'); +const sourceRoot = join(projectRoot, 'src'); + +interface PackageJson { + dependencies?: Record; + oclif?: { plugins?: string[] }; +} + +function readPackage(): PackageJson { + return JSON.parse(readFileSync(join(projectRoot, 'package.json'), 'utf8')) as PackageJson; +} + +function compilerOptions(): ts.CompilerOptions { + const tsconfigPath = join(projectRoot, 'tsconfig.json'); + const tsconfig = ts.parseConfigFileTextToJson(tsconfigPath, readFileSync(tsconfigPath, 'utf8')); + + return ts.convertCompilerOptionsFromJson(tsconfig.config.compilerOptions, projectRoot).options; +} + +function runtimeSources(dir: string): string[] { + return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => { + const path = join(dir, entry.name); + + if (entry.isDirectory()) { + return runtimeSources(path); + } + + return entry.name.endsWith('.ts') && !entry.name.endsWith('.test.ts') ? [path] : []; + }); +} + +function packageOf(specifier: string): string { + const parts = specifier.split('/'); + + return specifier.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0]; +} + +function isBuiltin(specifier: string): boolean { + return specifier.startsWith('node:') || builtinModules.includes(packageOf(specifier)); +} + +function requiredPackages(): Map { + const options = compilerOptions(); + const found = new Map(); + + for (const path of runtimeSources(sourceRoot)) { + const emitted = ts.transpileModule(readFileSync(path, 'utf8'), { compilerOptions: options, fileName: path }); + + for (const match of emitted.outputText.matchAll(/\b(?:require|import)\((["'])([^"']+)\1\)/g)) { + const specifier = match[2]; + + if (specifier.startsWith('.') || isBuiltin(specifier)) { + continue; + } + + const name = packageOf(specifier); + found.set(name, [...(found.get(name) ?? []), relative(projectRoot, path)]); + } + } + + return found; +} + +describe('package dependencies', () => { + it('declares every package the compiled runtime code requires as a production dependency', () => { + const declared = Object.keys(readPackage().dependencies ?? {}); + + const required = requiredPackages(); + const undeclared = [...required.entries()] + .filter(([name]) => !declared.includes(name)) + .map(([name, files]) => `${name} (required by ${files.join(', ')})`); + + expect(required.has('tslib')).toBe(true); + expect(required.has('@oclif/core')).toBe(true); + expect(required.has('open')).toBe(true); + expect(undeclared).toEqual([]); + }); + + it('declares every oclif plugin as a production dependency', () => { + const pkg = readPackage(); + const declared = Object.keys(pkg.dependencies ?? {}); + + const plugins = pkg.oclif?.plugins ?? []; + const undeclared = plugins.filter((plugin) => !declared.includes(plugin)); + + expect(plugins).toContain('@oclif/plugin-help'); + expect(undeclared).toEqual([]); + }); +});