Skip to content

Commit 506aa79

Browse files
authored
Merge pull request #209 from contentstack/feat/DX-3423-endpoints-helper-functions
feat: update package.json and endpoints.ts to streamline regions.json…
2 parents f48d206 + aa7b891 commit 506aa79

File tree

4 files changed

+81
-110
lines changed

4 files changed

+81
-110
lines changed

.talismanrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ fileignoreconfig:
33
ignore_detectors:
44
- filecontent
55
- filename: package-lock.json
6-
checksum: d55fde89f42bf080e243915bc5c3fd1d0302e1d11c0b14deb62fef3574c5ba56
6+
checksum: 54777ceb615ca49bc21baf255b1ee9781da7e2868ff3d4292a6715bcbed33196
77
- filename: src/entry-editable.ts
88
checksum: 3ba7af9ed1c1adef2e2bd5610099716562bebb8ba750d4b41ddda99fc9eaf115
99
- filename: .husky/pre-commit

package-lock.json

Lines changed: 74 additions & 100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@
2424
"test": "npm run clear:reports && jest --ci --json --coverage --testLocationInResults --outputFile=./reports/report.json",
2525
"test:badges": "npm run clear:badges && npm run test && jest-coverage-badges --input ./reports/coverage/coverage-summary.json --output ./badges",
2626
"test:debug": "jest --watchAll --runInBand",
27-
"prebuild": "rimraf dist && mkdir -p dist/lib && curl -s --max-time 30 --fail https://artifacts.contentstack.com/regions.json -o dist/lib/regions.json || echo 'Warning: Failed to download regions.json'",
27+
"prebuild": "rimraf dist && mkdir -p dist/lib && npm run download-regions",
28+
"download-regions": "curl -s --max-time 30 --fail https://artifacts.contentstack.com/regions.json -o dist/lib/regions.json || echo 'Warning: Failed to download regions.json'",
2829
"build": "tsc && rollup -c",
2930
"format": "prettier --write \"src/**/*.ts\"",
3031
"prepare": "husky install && npm run build",
3132
"prepublishOnly": "npm test",
3233
"pre-commit": "husky install && husky && chmod +x .husky/pre-commit && ./.husky/pre-commit",
3334
"version": "npm run format && git add -A src",
3435
"postversion": "git push && git push --tags",
35-
"postinstall": "curl -s --max-time 30 --fail https://artifacts.contentstack.com/regions.json -o dist/lib/regions.json || echo 'Warning: Failed to download regions.json, using existing file if available'",
36-
"postupdate": "curl -s --max-time 30 --fail https://artifacts.contentstack.com/regions.json -o dist/lib/regions.json || echo 'Warning: Failed to download regions.json, using existing file if available'"
36+
"postinstall": "npm run download-regions",
37+
"postupdate": "npm run download-regions"
3738
},
3839
"author": "Contentstack",
3940
"license": "MIT",

src/endpoints.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
import * as path from 'path';
33
import * as fs from 'fs';
44

5-
// Type declarations for CommonJS runtime (rollup outputs CommonJS format)
6-
declare const __dirname: string;
7-
85
export interface ContentstackEndpoints {
96
[key: string]: string | ContentstackEndpoints;
107
}
@@ -25,9 +22,8 @@ export interface RegionsResponse {
2522

2623
// Load regions.json at runtime from the dist/lib directory
2724
function loadRegions(): RegionsResponse {
28-
// The bundled file is at dist/index.es.js, regions.json is at dist/lib/regions.json
29-
// So __dirname will be 'dist/' and we need to go to 'dist/lib/regions.json'
30-
const regionsPath = path.join(__dirname, 'lib', 'regions.json');
25+
// Only look for regions.json in dist/lib directory
26+
const regionsPath = path.join(process.cwd(), 'dist', 'lib', 'regions.json');
3127

3228
if (fs.existsSync(regionsPath)) {
3329
try {

0 commit comments

Comments
 (0)