Skip to content

Commit

Permalink
Add "pack" script for Vercel deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Apr 30, 2023
1 parent 4b3e591 commit 7b872f8
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -24,3 +24,7 @@ yarn-error.log*

# vercel
.vercel

# `pack` script
*.tgz
/public
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -5,6 +5,7 @@
"build": "turbo run build",
"lint": "turbo run lint",
"test": "turbo run test",
"vercel-build": "turbo run pack",
"test-e2e": "turbo run test-e2e",
"format": "prettier --write \"**/*.{ts,tsx,md}\""
},
Expand Down
1 change: 1 addition & 0 deletions packages/agent-base/.eslintignore
@@ -0,0 +1 @@
dist
1 change: 1 addition & 0 deletions packages/agent-base/package.json
Expand Up @@ -11,6 +11,7 @@
"build": "tsc",
"test": "jest --env node --verbose --bail",
"lint": "eslint . --ext .ts",
"pack": "node ../../scripts/pack.mjs",
"prepublishOnly": "npm run build"
},
"repository": {
Expand Down
1 change: 1 addition & 0 deletions packages/data-uri-to-buffer/package.json
Expand Up @@ -11,6 +11,7 @@
"build": "tsc",
"test": "jest --env node --verbose --bail",
"lint": "eslint . --ext .ts",
"pack": "node ../../scripts/pack.mjs",
"prepublishOnly": "npm run build"
},
"repository": {
Expand Down
1 change: 1 addition & 0 deletions packages/degenerator/package.json
Expand Up @@ -11,6 +11,7 @@
"build": "tsc",
"test": "jest --env node --verbose --bail",
"lint": "eslint . --ext .ts",
"pack": "node ../../scripts/pack.mjs",
"prepublishOnly": "npm run build"
},
"author": "Nathan Rajlich <nathan@tootallnate.net> (http://n8.io/)",
Expand Down
1 change: 1 addition & 0 deletions packages/get-uri/package.json
Expand Up @@ -11,6 +11,7 @@
"build": "tsc",
"test": "jest --env node --verbose --bail",
"lint": "eslint . --ext .ts",
"pack": "node ../../scripts/pack.mjs",
"prepublishOnly": "npm run build"
},
"repository": {
Expand Down
1 change: 1 addition & 0 deletions packages/http-proxy-agent/package.json
Expand Up @@ -11,6 +11,7 @@
"build": "tsc",
"test": "mocha",
"lint": "eslint . --ext .ts",
"pack": "node ../../scripts/pack.mjs",
"prepublishOnly": "npm run build"
},
"repository": {
Expand Down
3 changes: 2 additions & 1 deletion packages/https-proxy-agent/package.json
Expand Up @@ -11,7 +11,8 @@
"build": "tsc",
"test": "jest --env node --verbose --bail test/test.ts",
"test-e2e": "jest --env node --verbose --bail test/e2e.test.ts",
"lint": "eslint src --ext .js,.ts",
"lint": "eslint --ext .ts",
"pack": "node ../../scripts/pack.mjs",
"prepublishOnly": "npm run build"
},
"repository": {
Expand Down
2 changes: 2 additions & 0 deletions packages/pac-proxy-agent/package.json
Expand Up @@ -10,6 +10,8 @@
"scripts": {
"build": "tsc",
"test": "mocha --reporter spec",
"lint": "eslint --ext .ts",
"pack": "node ../../scripts/pack.mjs",
"prepublishOnly": "npm run build"
},
"repository": {
Expand Down
1 change: 1 addition & 0 deletions packages/pac-resolver/package.json
Expand Up @@ -24,6 +24,7 @@
"build": "tsc",
"test": "mocha --reporter spec",
"lint": "eslint . --ext .ts",
"pack": "node ../../scripts/pack.mjs",
"prepublishOnly": "npm run build"
},
"repository": {
Expand Down
1 change: 1 addition & 0 deletions packages/proxy-agent/package.json
Expand Up @@ -11,6 +11,7 @@
"build": "tsc",
"test": "jest --env node --verbose --bail",
"lint": "eslint . --ext .ts",
"pack": "node ../../scripts/pack.mjs",
"prepublishOnly": "npm run build"
},
"engines": {
Expand Down
1 change: 1 addition & 0 deletions packages/proxy/package.json
Expand Up @@ -11,6 +11,7 @@
"build": "tsc",
"test": "mocha --reporter spec",
"lint": "eslint . --ext .ts",
"pack": "node ../../scripts/pack.mjs",
"prepublishOnly": "npm run build"
},
"keywords": [
Expand Down
1 change: 1 addition & 0 deletions packages/socks-proxy-agent/package.json
Expand Up @@ -137,6 +137,7 @@
"test": "mocha --reporter spec test/test.js",
"test-e2e": "jest --env node --verbose --bail test/e2e.test.ts",
"lint": "eslint . --ext .ts",
"pack": "node ../../scripts/pack.mjs",
"prepublishOnly": "npm run build"
},
"license": "MIT"
Expand Down
35 changes: 35 additions & 0 deletions scripts/pack.mjs
@@ -0,0 +1,35 @@
import { join } from 'path';
import { spawnSync } from 'child_process';
import {
readFileSync,
writeFileSync,
readdirSync,
mkdirSync,
renameSync,
} from "fs";

// eslint-disable-next-line turbo/no-undeclared-env-vars
const { VERCEL_URL } = process.env;

const cwd = process.cwd();
const publicDir = new URL('../public/', import.meta.url);
mkdirSync(publicDir, { recursive: true });

const packages = readdirSync(join(cwd, '..'));
const pkgPath = join(cwd, 'package.json');
const pkg = JSON.parse(readFileSync(pkgPath));
if (pkg.dependencies) {
for (const dep of Object.keys(pkg.dependencies)) {
if (packages.includes(dep)) {
// This dep is one of the ones within the monorepo,
// so update to use a tarball URL
pkg.dependencies[dep] = `https://${VERCEL_URL}/${dep}.tgz`
}
}
}
writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\n`);
spawnSync('pnpm', ['pack']);

const tarball = readdirSync(cwd).find(f => f.endsWith('.tgz'));
const dest = new URL(`${pkg.name}.tgz`, publicDir);
renameSync(join(cwd, tarball), dest);
4 changes: 4 additions & 0 deletions turbo.json
Expand Up @@ -18,6 +18,10 @@
"test-e2e": {
"dependsOn": ["build"]
},
"pack": {
"env": ["VERCEL_URL"],
"dependsOn": ["build"]
},
"lint": {}
}
}

0 comments on commit 7b872f8

Please sign in to comment.