Files
vercel/utils/run.js
Nathan Rajlich 5b5197d2c5 [node] Create vercel-plugin-node (#6874)
* [node] Refactor to Vercel CLI Plugin

* Enforce "index" suffix on output Serverless Functions

So that nesting works properly

* Some cleanup

* Add version

* Use `@vercel/static-config`

* .

* Add support for wildcard routes

* Don't compile dotfiles, underscore prefixed files, files within `node_modules`, nor TypeScript definition files

Matches the logic from `maybeGetBuilder()` in `@vercel/build-utils`.

* Bump version

* Introduce testing framework

* Debug

* Add test without any deps

* Longer timeout to install Node.js for vercel/fun

* Install deps

* Add legacy Node.js server interface test

* More tests

* Test "assets" fixture

* Test "helpers" fixture

* fix

* Support AWS native API

* Remove debugging `console.log()` calls

* Use plugin-node for new plugin instead

* Revert "Use plugin-node for new plugin instead"

This reverts commit f317b8c6ecdc67a74d5f2b12a2e7567a27d4b6b8.

* Move to `plugin-node` directory

* Update plugin-node version in package.json

* Checkout node from main

* Add yarn.lock files for tests

* Update node-bridge

Co-authored-by: Andy <AndyBitz@users.noreply.github.com>
Co-authored-by: Andy Bitz <artzbitz@gmail.com>
2021-11-08 14:59:01 +01:00

116 lines
2.7 KiB
JavaScript
Vendored

const { execSync, spawn } = require('child_process');
const { join, relative, sep } = require('path');
// The order matters because we must build dependencies first
const allPackages = [
'routing-utils',
'frameworks',
'build-utils',
'static-config',
'middleware',
'client',
'node-bridge',
'plugin-node',
'node',
'go',
'python',
'ruby',
'cli',
];
process.chdir(join(__dirname, '..'));
async function main() {
const script = process.argv[2];
const all = process.argv[3];
let modifiedPackages = new Set(allPackages);
if (!script) {
console.error('Please provide at least one argument');
process.exit(2);
}
if (all === 'all') {
console.log(`Running script "${script}" for all packages`);
} else {
const branch =
process.env.GITHUB_HEAD_REF ||
execSync('git branch --show-current').toString().trim();
const gitPath = branch === 'main' ? 'HEAD~1' : 'origin/main...HEAD';
const diff = execSync(`git diff ${gitPath} --name-only`).toString();
const changed = diff
.split('\n')
.filter(item => Boolean(item) && item.startsWith('packages'))
.map(item => relative('packages', item).split(sep)[0])
.concat('cli'); // Always run tests for Vercel CLI
modifiedPackages = new Set(changed);
console.log(
`Running "${script}" on branch "${branch}" with the following packages:\n`
);
}
for (const pkgName of allPackages) {
if (modifiedPackages.has(pkgName)) {
console.log(` - ${pkgName}`);
}
}
for (const pkgName of allPackages) {
if (modifiedPackages.has(pkgName)) {
await runScript(pkgName, script);
}
}
}
function runScript(pkgName, script) {
return new Promise((resolve, reject) => {
const cwd = join(__dirname, '..', 'packages', pkgName);
let pkgJson = null;
try {
pkgJson = require(join(cwd, 'package.json'));
} catch (e) {
pkgJson = null;
}
if (pkgJson && pkgJson.scripts && pkgJson.scripts[script]) {
console.log(`\n[${pkgName}] Running yarn ${script}`);
const child = spawn('yarn', [script], {
cwd,
stdio: 'inherit',
shell: true,
});
child.on('error', reject);
child.on('close', (code, signal) => {
if (code === 0) {
return resolve();
}
reject(
new Error(
`[${pkgName}] Exited script "${script}" with code ${
code || signal
}.`
)
);
});
} else {
console.log(
`[${pkgName}] Skipping since script "${script}" is missing from package.json`
);
resolve();
}
});
}
main()
.then(() => {
console.log('Success!');
process.exit(0);
})
.catch(e => {
console.error(e);
process.exit(1);
});