Skip to content

Commit b3b08f9

Browse files
authoredApr 30, 2023
Add "pack" script for Vercel deployment (#145)
Enable Vercel deployments to upload tarballs of each package, so that they can be installed and tested before being released in a mainline npm package release. For example: ``` npm i https://proxy-agents-git-pack-tootallnate.vercel.app/proxy-agent.tgz ```
1 parent 4b3e591 commit b3b08f9

File tree

16 files changed

+58
-1
lines changed

16 files changed

+58
-1
lines changed
 

‎.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ yarn-error.log*
2424

2525
# vercel
2626
.vercel
27+
28+
# `pack` script
29+
*.tgz
30+
/public

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"build": "turbo run build",
66
"lint": "turbo run lint",
77
"test": "turbo run test",
8+
"vercel-build": "turbo run pack",
89
"test-e2e": "turbo run test-e2e",
910
"format": "prettier --write \"**/*.{ts,tsx,md}\""
1011
},

‎packages/agent-base/.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dist

‎packages/agent-base/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"build": "tsc",
1212
"test": "jest --env node --verbose --bail",
1313
"lint": "eslint . --ext .ts",
14+
"pack": "node ../../scripts/pack.mjs",
1415
"prepublishOnly": "npm run build"
1516
},
1617
"repository": {

‎packages/data-uri-to-buffer/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"build": "tsc",
1212
"test": "jest --env node --verbose --bail",
1313
"lint": "eslint . --ext .ts",
14+
"pack": "node ../../scripts/pack.mjs",
1415
"prepublishOnly": "npm run build"
1516
},
1617
"repository": {

‎packages/degenerator/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"build": "tsc",
1212
"test": "jest --env node --verbose --bail",
1313
"lint": "eslint . --ext .ts",
14+
"pack": "node ../../scripts/pack.mjs",
1415
"prepublishOnly": "npm run build"
1516
},
1617
"author": "Nathan Rajlich <nathan@tootallnate.net> (http://n8.io/)",

‎packages/get-uri/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"build": "tsc",
1212
"test": "jest --env node --verbose --bail",
1313
"lint": "eslint . --ext .ts",
14+
"pack": "node ../../scripts/pack.mjs",
1415
"prepublishOnly": "npm run build"
1516
},
1617
"repository": {

‎packages/http-proxy-agent/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"build": "tsc",
1212
"test": "mocha",
1313
"lint": "eslint . --ext .ts",
14+
"pack": "node ../../scripts/pack.mjs",
1415
"prepublishOnly": "npm run build"
1516
},
1617
"repository": {

‎packages/https-proxy-agent/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"build": "tsc",
1212
"test": "jest --env node --verbose --bail test/test.ts",
1313
"test-e2e": "jest --env node --verbose --bail test/e2e.test.ts",
14-
"lint": "eslint src --ext .js,.ts",
14+
"lint": "eslint --ext .ts",
15+
"pack": "node ../../scripts/pack.mjs",
1516
"prepublishOnly": "npm run build"
1617
},
1718
"repository": {

‎packages/pac-proxy-agent/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
"scripts": {
1111
"build": "tsc",
1212
"test": "mocha --reporter spec",
13+
"lint": "eslint --ext .ts",
14+
"pack": "node ../../scripts/pack.mjs",
1315
"prepublishOnly": "npm run build"
1416
},
1517
"repository": {

‎packages/pac-resolver/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"build": "tsc",
2525
"test": "mocha --reporter spec",
2626
"lint": "eslint . --ext .ts",
27+
"pack": "node ../../scripts/pack.mjs",
2728
"prepublishOnly": "npm run build"
2829
},
2930
"repository": {

‎packages/proxy-agent/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"build": "tsc",
1212
"test": "jest --env node --verbose --bail",
1313
"lint": "eslint . --ext .ts",
14+
"pack": "node ../../scripts/pack.mjs",
1415
"prepublishOnly": "npm run build"
1516
},
1617
"engines": {

‎packages/proxy/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"build": "tsc",
1212
"test": "mocha --reporter spec",
1313
"lint": "eslint . --ext .ts",
14+
"pack": "node ../../scripts/pack.mjs",
1415
"prepublishOnly": "npm run build"
1516
},
1617
"keywords": [

‎packages/socks-proxy-agent/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@
137137
"test": "mocha --reporter spec test/test.js",
138138
"test-e2e": "jest --env node --verbose --bail test/e2e.test.ts",
139139
"lint": "eslint . --ext .ts",
140+
"pack": "node ../../scripts/pack.mjs",
140141
"prepublishOnly": "npm run build"
141142
},
142143
"license": "MIT"

‎scripts/pack.mjs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { join } from 'path';
2+
import { spawnSync } from 'child_process';
3+
import {
4+
readFileSync,
5+
writeFileSync,
6+
readdirSync,
7+
mkdirSync,
8+
renameSync,
9+
} from "fs";
10+
11+
// eslint-disable-next-line turbo/no-undeclared-env-vars
12+
const { VERCEL_URL } = process.env;
13+
14+
const cwd = process.cwd();
15+
const publicDir = new URL('../public/', import.meta.url);
16+
mkdirSync(publicDir, { recursive: true });
17+
18+
const packages = readdirSync(join(cwd, '..'));
19+
const pkgPath = join(cwd, 'package.json');
20+
const pkg = JSON.parse(readFileSync(pkgPath));
21+
if (pkg.dependencies) {
22+
for (const dep of Object.keys(pkg.dependencies)) {
23+
if (packages.includes(dep)) {
24+
// This dep is one of the ones within the monorepo,
25+
// so update to use a tarball URL
26+
pkg.dependencies[dep] = `https://${VERCEL_URL}/${dep}.tgz`
27+
}
28+
}
29+
}
30+
writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
31+
spawnSync('pnpm', ['pack']);
32+
33+
const tarball = readdirSync(cwd).find(f => f.endsWith('.tgz'));
34+
const dest = new URL(`${pkg.name}.tgz`, publicDir);
35+
renameSync(join(cwd, tarball), dest);

‎turbo.json

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
"test-e2e": {
1919
"dependsOn": ["build"]
2020
},
21+
"pack": {
22+
"env": ["VERCEL_URL"],
23+
"dependsOn": ["build"]
24+
},
2125
"lint": {}
2226
}
2327
}

1 commit comments

Comments
 (1)

vercel[bot] commented on Apr 30, 2023

@vercel[bot]
Please sign in to comment.