mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-11 12:57:46 +00:00
Compare commits
34 Commits
@vercel/py
...
@vercel/ne
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a247e31688 | ||
|
|
dc02e763a4 | ||
|
|
8567fc0de6 | ||
|
|
4f8f3d373f | ||
|
|
debb85b690 | ||
|
|
bfef989ada | ||
|
|
4e0b6c5eaf | ||
|
|
0ace69ef75 | ||
|
|
b7b7923f92 | ||
|
|
8167233c56 | ||
|
|
32ee6aba92 | ||
|
|
b48f7a7e6e | ||
|
|
a961c9b992 | ||
|
|
cf7c50d691 | ||
|
|
f4be388a1f | ||
|
|
c1bc53dea8 | ||
|
|
6855e3df54 | ||
|
|
0d39dbd1d9 | ||
|
|
509c85182a | ||
|
|
ae801e563d | ||
|
|
0e8278f490 | ||
|
|
0d302a6f48 | ||
|
|
4e4f5f28a2 | ||
|
|
5205a4ec4b | ||
|
|
2c15e496ed | ||
|
|
1f0ca46626 | ||
|
|
17cb5f1bc6 | ||
|
|
b095031292 | ||
|
|
f50bcbc0ba | ||
|
|
4bf6295d7a | ||
|
|
a4001ce10b | ||
|
|
2df3432d88 | ||
|
|
bcfc19de12 | ||
|
|
04381c669b |
4
.gitattributes
vendored
4
.gitattributes
vendored
@@ -8,3 +8,7 @@ packages/*/test/* linguist-vendored
|
||||
# Go build fails with Windows line endings.
|
||||
*.go text eol=lf
|
||||
go.mod text eol=lf
|
||||
|
||||
# Mark certain files as "binary" -- hide diffs
|
||||
**/test/fixtures/**/git/**/* binary
|
||||
**/test/fixtures/**/git/**/* linguist-generated
|
||||
|
||||
@@ -1,18 +1 @@
|
||||
*
|
||||
|
||||
# general
|
||||
!utils/
|
||||
!utils/run.js
|
||||
!.yarnrc
|
||||
!yarn.lock
|
||||
!package.json
|
||||
!turbo.json
|
||||
|
||||
# api
|
||||
!api/
|
||||
!api/**
|
||||
|
||||
# packages
|
||||
!packages/
|
||||
!packages/frameworks
|
||||
!packages/frameworks/**
|
||||
packages/*/test/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import fs from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
import { join, dirname } from 'path';
|
||||
import execa from 'execa';
|
||||
import { getExampleList } from '../examples/example-list';
|
||||
import { mapOldToNew } from '../examples/map-old-to-new';
|
||||
|
||||
@@ -40,7 +41,32 @@ async function main() {
|
||||
JSON.stringify([...existingExamples, ...oldExamples])
|
||||
);
|
||||
|
||||
const { stdout: sha } = await execa('git', ['rev-parse', '--short', 'HEAD'], {
|
||||
cwd: repoRoot,
|
||||
});
|
||||
|
||||
const tarballsDir = join(pubDir, 'tarballs');
|
||||
const packagesDir = join(repoRoot, 'packages');
|
||||
const packages = await fs.readdir(packagesDir);
|
||||
for (const pkg of packages) {
|
||||
const fullDir = join(packagesDir, pkg);
|
||||
const packageJsonRaw = await fs.readFile(
|
||||
join(fullDir, 'package.json'),
|
||||
'utf-8'
|
||||
);
|
||||
const packageJson = JSON.parse(packageJsonRaw);
|
||||
const tarballName = `${packageJson.name
|
||||
.replace('@', '')
|
||||
.replace('/', '-')}-v${packageJson.version}-${sha.trim()}.tgz`;
|
||||
const destTarballPath = join(tarballsDir, `${packageJson.name}.tgz`);
|
||||
await fs.mkdir(dirname(destTarballPath), { recursive: true });
|
||||
await fs.copyFile(join(fullDir, tarballName), destTarballPath);
|
||||
}
|
||||
|
||||
console.log('Completed building static frontend.');
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
main().catch(err => {
|
||||
console.log('error running build:', err);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
2
examples/create-react-app/.env.production
Normal file
2
examples/create-react-app/.env.production
Normal file
@@ -0,0 +1,2 @@
|
||||
# `REACT_APP` prefix is required to expose to client-side
|
||||
REACT_APP_VERCEL_ANALYTICS_ID=$VERCEL_ANALYTICS_ID
|
||||
@@ -1,13 +1,13 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@testing-library/jest-dom": "^5.16.1",
|
||||
"@testing-library/react": "^12.1.2",
|
||||
"@testing-library/user-event": "^13.5.0",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2",
|
||||
"react-scripts": "5.0.0",
|
||||
"web-vitals": "^2.1.3"
|
||||
"@testing-library/jest-dom": "^5.16.4",
|
||||
"@testing-library/react": "^13.3.0",
|
||||
"@testing-library/user-event": "^14.2.0",
|
||||
"react": "^18.1.0",
|
||||
"react-dom": "^18.1.0",
|
||||
"react-scripts": "5.0.1",
|
||||
"web-vitals": "^2.1.4"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
|
||||
@@ -3,6 +3,7 @@ import ReactDOM from 'react-dom';
|
||||
import './index.css';
|
||||
import App from './App';
|
||||
import reportWebVitals from './reportWebVitals';
|
||||
import { sendToVercelAnalytics } from './vitals';
|
||||
|
||||
ReactDOM.render(
|
||||
<React.StrictMode>
|
||||
@@ -11,7 +12,4 @@ ReactDOM.render(
|
||||
document.getElementById('root')
|
||||
);
|
||||
|
||||
// If you want to start measuring performance in your app, pass a function
|
||||
// to log results (for example: reportWebVitals(console.log))
|
||||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
||||
reportWebVitals();
|
||||
reportWebVitals(sendToVercelAnalytics);
|
||||
|
||||
41
examples/create-react-app/src/vitals.js
Normal file
41
examples/create-react-app/src/vitals.js
Normal file
@@ -0,0 +1,41 @@
|
||||
const vitalsUrl = 'https://vitals.vercel-analytics.com/v1/vitals';
|
||||
|
||||
function getConnectionSpeed() {
|
||||
return 'connection' in navigator &&
|
||||
navigator['connection'] &&
|
||||
'effectiveType' in navigator['connection']
|
||||
? navigator['connection']['effectiveType']
|
||||
: '';
|
||||
}
|
||||
|
||||
export function sendToVercelAnalytics(metric) {
|
||||
const analyticsId = process.env.REACT_APP_VERCEL_ANALYTICS_ID;
|
||||
if (!analyticsId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const body = {
|
||||
dsn: analyticsId,
|
||||
id: metric.id,
|
||||
page: window.location.pathname,
|
||||
href: window.location.href,
|
||||
event_name: metric.name,
|
||||
value: metric.value.toString(),
|
||||
speed: getConnectionSpeed(),
|
||||
};
|
||||
|
||||
console.log({ body });
|
||||
const blob = new Blob([new URLSearchParams(body).toString()], {
|
||||
// This content type is necessary for `sendBeacon`
|
||||
type: 'application/x-www-form-urlencoded',
|
||||
});
|
||||
if (navigator.sendBeacon) {
|
||||
navigator.sendBeacon(vitalsUrl, blob);
|
||||
} else
|
||||
fetch(vitalsUrl, {
|
||||
body: blob,
|
||||
method: 'POST',
|
||||
credentials: 'omit',
|
||||
keepalive: true,
|
||||
});
|
||||
}
|
||||
@@ -1484,10 +1484,10 @@
|
||||
"@svgr/plugin-svgo" "^5.5.0"
|
||||
loader-utils "^2.0.0"
|
||||
|
||||
"@testing-library/dom@^8.0.0":
|
||||
version "8.11.2"
|
||||
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-8.11.2.tgz#fc110c665a066c2287be765e4a35ba8dad737015"
|
||||
integrity sha512-idsS/cqbYudXcVWngc1PuWNmXs416oBy2g/7Q8QAUREt5Z3MUkAL2XJD7xazLJ6esDfqRDi/ZBxk+OPPXitHRw==
|
||||
"@testing-library/dom@^8.5.0":
|
||||
version "8.13.0"
|
||||
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-8.13.0.tgz#bc00bdd64c7d8b40841e27a70211399ad3af46f5"
|
||||
integrity sha512-9VHgfIatKNXQNaZTtLnalIy0jNZzY35a4S3oi08YAt9Hv1VsfZ/DfA45lM8D/UhtHBGJ4/lGwp0PZkVndRkoOQ==
|
||||
dependencies:
|
||||
"@babel/code-frame" "^7.10.4"
|
||||
"@babel/runtime" "^7.12.5"
|
||||
@@ -1498,10 +1498,10 @@
|
||||
lz-string "^1.4.4"
|
||||
pretty-format "^27.0.2"
|
||||
|
||||
"@testing-library/jest-dom@^5.16.1":
|
||||
version "5.16.1"
|
||||
resolved "https://registry.yarnpkg.com/@testing-library/jest-dom/-/jest-dom-5.16.1.tgz#3db7df5ae97596264a7da9696fe14695ba02e51f"
|
||||
integrity sha512-ajUJdfDIuTCadB79ukO+0l8O+QwN0LiSxDaYUTI4LndbbUsGi6rWU1SCexXzBA2NSjlVB9/vbkasQIL3tmPBjw==
|
||||
"@testing-library/jest-dom@^5.16.4":
|
||||
version "5.16.4"
|
||||
resolved "https://registry.yarnpkg.com/@testing-library/jest-dom/-/jest-dom-5.16.4.tgz#938302d7b8b483963a3ae821f1c0808f872245cd"
|
||||
integrity sha512-Gy+IoFutbMQcky0k+bqqumXZ1cTGswLsFqmNLzNdSKkU9KGV2u9oXhukCbbJ9/LRPKiqwxEE8VpV/+YZlfkPUA==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.9.2"
|
||||
"@types/testing-library__jest-dom" "^5.9.1"
|
||||
@@ -1513,20 +1513,19 @@
|
||||
lodash "^4.17.15"
|
||||
redent "^3.0.0"
|
||||
|
||||
"@testing-library/react@^12.1.2":
|
||||
version "12.1.2"
|
||||
resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-12.1.2.tgz#f1bc9a45943461fa2a598bb4597df1ae044cfc76"
|
||||
integrity sha512-ihQiEOklNyHIpo2Y8FREkyD1QAea054U0MVbwH1m8N9TxeFz+KoJ9LkqoKqJlzx2JDm56DVwaJ1r36JYxZM05g==
|
||||
"@testing-library/react@^13.3.0":
|
||||
version "13.3.0"
|
||||
resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-13.3.0.tgz#bf298bfbc5589326bbcc8052b211f3bb097a97c5"
|
||||
integrity sha512-DB79aA426+deFgGSjnf5grczDPiL4taK3hFaa+M5q7q20Kcve9eQottOG5kZ74KEr55v0tU2CQormSSDK87zYQ==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.12.5"
|
||||
"@testing-library/dom" "^8.0.0"
|
||||
"@testing-library/dom" "^8.5.0"
|
||||
"@types/react-dom" "^18.0.0"
|
||||
|
||||
"@testing-library/user-event@^13.5.0":
|
||||
version "13.5.0"
|
||||
resolved "https://registry.yarnpkg.com/@testing-library/user-event/-/user-event-13.5.0.tgz#69d77007f1e124d55314a2b73fd204b333b13295"
|
||||
integrity sha512-5Kwtbo3Y/NowpkbRuSepbyMFkZmHgD+vPzYB/RJ4oxt5Gj/avFFBYjhw27cqSVPVw/3a67NK1PbiIr9k4Gwmdg==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.12.5"
|
||||
"@testing-library/user-event@^14.2.0":
|
||||
version "14.2.0"
|
||||
resolved "https://registry.yarnpkg.com/@testing-library/user-event/-/user-event-14.2.0.tgz#8293560f8f80a00383d6c755ec3e0b918acb1683"
|
||||
integrity sha512-+hIlG4nJS6ivZrKnOP7OGsDu9Fxmryj9vCl8x0ZINtTJcCHs2zLsYif5GzuRiBF2ck5GZG2aQr7Msg+EHlnYVQ==
|
||||
|
||||
"@tootallnate/once@1":
|
||||
version "1.1.2"
|
||||
@@ -1735,6 +1734,11 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.4.3.tgz#a3c65525b91fca7da00ab1a3ac2b5a2a4afbffbf"
|
||||
integrity sha512-QzSuZMBuG5u8HqYz01qtMdg/Jfctlnvj1z/lYnIDXs/golxw0fxtRAHd9KrzjR7Yxz1qVeI00o0kiO3PmVdJ9w==
|
||||
|
||||
"@types/prop-types@*":
|
||||
version "15.7.5"
|
||||
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.5.tgz#5f19d2b85a98e9558036f6a3cacc8819420f05cf"
|
||||
integrity sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==
|
||||
|
||||
"@types/q@^1.5.1":
|
||||
version "1.5.5"
|
||||
resolved "https://registry.yarnpkg.com/@types/q/-/q-1.5.5.tgz#75a2a8e7d8ab4b230414505d92335d1dcb53a6df"
|
||||
@@ -1750,6 +1754,22 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.4.tgz#cd667bcfdd025213aafb7ca5915a932590acdcdc"
|
||||
integrity sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==
|
||||
|
||||
"@types/react-dom@^18.0.0":
|
||||
version "18.0.5"
|
||||
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-18.0.5.tgz#330b2d472c22f796e5531446939eacef8378444a"
|
||||
integrity sha512-OWPWTUrY/NIrjsAPkAk1wW9LZeIjSvkXRhclsFO8CZcZGCOg2G0YZy4ft+rOyYxy8B7ui5iZzi9OkDebZ7/QSA==
|
||||
dependencies:
|
||||
"@types/react" "*"
|
||||
|
||||
"@types/react@*":
|
||||
version "18.0.9"
|
||||
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.0.9.tgz#d6712a38bd6cd83469603e7359511126f122e878"
|
||||
integrity sha512-9bjbg1hJHUm4De19L1cHiW0Jvx3geel6Qczhjd0qY5VKVE2X5+x77YxAepuCwVh4vrgZJdgEJw48zrhRIeF4Nw==
|
||||
dependencies:
|
||||
"@types/prop-types" "*"
|
||||
"@types/scheduler" "*"
|
||||
csstype "^3.0.2"
|
||||
|
||||
"@types/resolve@1.17.1":
|
||||
version "1.17.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.17.1.tgz#3afd6ad8967c77e4376c598a82ddd58f46ec45d6"
|
||||
@@ -1762,6 +1782,11 @@
|
||||
resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.1.tgz#d8f1c0d0dc23afad6dc16a9e993a0865774b4065"
|
||||
integrity sha512-xoDlM2S4ortawSWORYqsdU+2rxdh4LRW9ytc3zmT37RIKQh6IHyKwwtKhKis9ah8ol07DCkZxPt8BBvPjC6v4g==
|
||||
|
||||
"@types/scheduler@*":
|
||||
version "0.16.2"
|
||||
resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.2.tgz#1a62f89525723dde24ba1b01b092bf5df8ad4d39"
|
||||
integrity sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==
|
||||
|
||||
"@types/serve-index@^1.9.1":
|
||||
version "1.9.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/serve-index/-/serve-index-1.9.1.tgz#1b5e85370a192c01ec6cec4735cf2917337a6278"
|
||||
@@ -3175,6 +3200,11 @@ cssstyle@^2.3.0:
|
||||
dependencies:
|
||||
cssom "~0.3.6"
|
||||
|
||||
csstype@^3.0.2:
|
||||
version "3.1.0"
|
||||
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.0.tgz#4ddcac3718d787cf9df0d1b7d15033925c8f29f2"
|
||||
integrity sha512-uX1KG+x9h5hIJsaKR9xHUeUraxf8IODOwq9JLNPq6BwB04a/xgpq3rcx47l5BZu5zBPlgD342tdke3Hom/nJRA==
|
||||
|
||||
damerau-levenshtein@^1.0.7:
|
||||
version "1.0.8"
|
||||
resolved "https://registry.yarnpkg.com/damerau-levenshtein/-/damerau-levenshtein-1.0.8.tgz#b43d286ccbd36bc5b2f7ed41caf2d0aba1f8a6e7"
|
||||
@@ -3622,10 +3652,10 @@ escodegen@^2.0.0:
|
||||
optionalDependencies:
|
||||
source-map "~0.6.1"
|
||||
|
||||
eslint-config-react-app@^7.0.0:
|
||||
version "7.0.0"
|
||||
resolved "https://registry.yarnpkg.com/eslint-config-react-app/-/eslint-config-react-app-7.0.0.tgz#0fa96d5ec1dfb99c029b1554362ab3fa1c3757df"
|
||||
integrity sha512-xyymoxtIt1EOsSaGag+/jmcywRuieQoA2JbPCjnw9HukFj9/97aGPoZVFioaotzk1K5Qt9sHO5EutZbkrAXS0g==
|
||||
eslint-config-react-app@^7.0.1:
|
||||
version "7.0.1"
|
||||
resolved "https://registry.yarnpkg.com/eslint-config-react-app/-/eslint-config-react-app-7.0.1.tgz#73ba3929978001c5c86274c017ea57eb5fa644b4"
|
||||
integrity sha512-K6rNzvkIeHaTd8m/QEh1Zko0KI7BACWkkneSs6s9cKZC/J27X3eZR6Upt1jkmZ/4FK+XUOPPxMEN7+lbUXfSlA==
|
||||
dependencies:
|
||||
"@babel/core" "^7.16.0"
|
||||
"@babel/eslint-parser" "^7.16.3"
|
||||
@@ -6841,10 +6871,10 @@ react-app-polyfill@^3.0.0:
|
||||
regenerator-runtime "^0.13.9"
|
||||
whatwg-fetch "^3.6.2"
|
||||
|
||||
react-dev-utils@^12.0.0:
|
||||
version "12.0.0"
|
||||
resolved "https://registry.yarnpkg.com/react-dev-utils/-/react-dev-utils-12.0.0.tgz#4eab12cdb95692a077616770b5988f0adf806526"
|
||||
integrity sha512-xBQkitdxozPxt1YZ9O1097EJiVpwHr9FoAuEVURCKV0Av8NBERovJauzP7bo1ThvuhZ4shsQ1AJiu4vQpoT1AQ==
|
||||
react-dev-utils@^12.0.1:
|
||||
version "12.0.1"
|
||||
resolved "https://registry.yarnpkg.com/react-dev-utils/-/react-dev-utils-12.0.1.tgz#ba92edb4a1f379bd46ccd6bcd4e7bc398df33e73"
|
||||
integrity sha512-84Ivxmr17KjUupyqzFode6xKhjwuEJDROWKJy/BthkL7Wn6NJ8h4WE6k/exAv6ImS+0oZLRRW5j/aINMHyeGeQ==
|
||||
dependencies:
|
||||
"@babel/code-frame" "^7.16.0"
|
||||
address "^1.1.2"
|
||||
@@ -6865,25 +6895,24 @@ react-dev-utils@^12.0.0:
|
||||
open "^8.4.0"
|
||||
pkg-up "^3.1.0"
|
||||
prompts "^2.4.2"
|
||||
react-error-overlay "^6.0.10"
|
||||
react-error-overlay "^6.0.11"
|
||||
recursive-readdir "^2.2.2"
|
||||
shell-quote "^1.7.3"
|
||||
strip-ansi "^6.0.1"
|
||||
text-table "^0.2.0"
|
||||
|
||||
react-dom@^17.0.2:
|
||||
version "17.0.2"
|
||||
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.2.tgz#ecffb6845e3ad8dbfcdc498f0d0a939736502c23"
|
||||
integrity sha512-s4h96KtLDUQlsENhMn1ar8t2bEa+q/YAtj8pPPdIjPDGBDIVNsrD9aXNWqspUe6AzKCIG0C1HZZLqLV7qpOBGA==
|
||||
react-dom@^18.1.0:
|
||||
version "18.1.0"
|
||||
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.1.0.tgz#7f6dd84b706408adde05e1df575b3a024d7e8a2f"
|
||||
integrity sha512-fU1Txz7Budmvamp7bshe4Zi32d0ll7ect+ccxNu9FlObT605GOEB8BfO4tmRJ39R5Zj831VCpvQ05QPBW5yb+w==
|
||||
dependencies:
|
||||
loose-envify "^1.1.0"
|
||||
object-assign "^4.1.1"
|
||||
scheduler "^0.20.2"
|
||||
scheduler "^0.22.0"
|
||||
|
||||
react-error-overlay@^6.0.10:
|
||||
version "6.0.10"
|
||||
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.10.tgz#0fe26db4fa85d9dbb8624729580e90e7159a59a6"
|
||||
integrity sha512-mKR90fX7Pm5seCOfz8q9F+66VCc1PGsWSBxKbITjfKVQHMNF2zudxHnMdJiB1fRCb+XsbQV9sO9DCkgsMQgBIA==
|
||||
react-error-overlay@^6.0.11:
|
||||
version "6.0.11"
|
||||
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.11.tgz#92835de5841c5cf08ba00ddd2d677b6d17ff9adb"
|
||||
integrity sha512-/6UZ2qgEyH2aqzYZgQPxEnz33NJ2gNsnHA2o5+o4wW9bLM/JYQitNP9xPhsXwC08hMMovfGe/8retsdDsczPRg==
|
||||
|
||||
react-is@^16.13.1:
|
||||
version "16.13.1"
|
||||
@@ -6900,10 +6929,10 @@ react-refresh@^0.11.0:
|
||||
resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.11.0.tgz#77198b944733f0f1f1a90e791de4541f9f074046"
|
||||
integrity sha512-F27qZr8uUqwhWZboondsPx8tnC3Ct3SxZA3V5WyEvujRyyNv0VYPhoBg1gZ8/MV5tubQp76Trw8lTv9hzRBa+A==
|
||||
|
||||
react-scripts@5.0.0:
|
||||
version "5.0.0"
|
||||
resolved "https://registry.yarnpkg.com/react-scripts/-/react-scripts-5.0.0.tgz#6547a6d7f8b64364ef95273767466cc577cb4b60"
|
||||
integrity sha512-3i0L2CyIlROz7mxETEdfif6Sfhh9Lfpzi10CtcGs1emDQStmZfWjJbAIMtRD0opVUjQuFWqHZyRZ9PPzKCFxWg==
|
||||
react-scripts@5.0.1:
|
||||
version "5.0.1"
|
||||
resolved "https://registry.yarnpkg.com/react-scripts/-/react-scripts-5.0.1.tgz#6285dbd65a8ba6e49ca8d651ce30645a6d980003"
|
||||
integrity sha512-8VAmEm/ZAwQzJ+GOMLbBsTdDKOpuZh7RPs0UymvBR2vRk4iZWCskjbFnxqjrzoIvlNNRZ3QJFx6/qDSi6zSnaQ==
|
||||
dependencies:
|
||||
"@babel/core" "^7.16.0"
|
||||
"@pmmmwh/react-refresh-webpack-plugin" "^0.5.3"
|
||||
@@ -6921,7 +6950,7 @@ react-scripts@5.0.0:
|
||||
dotenv "^10.0.0"
|
||||
dotenv-expand "^5.1.0"
|
||||
eslint "^8.3.0"
|
||||
eslint-config-react-app "^7.0.0"
|
||||
eslint-config-react-app "^7.0.1"
|
||||
eslint-webpack-plugin "^3.1.1"
|
||||
file-loader "^6.2.0"
|
||||
fs-extra "^10.0.0"
|
||||
@@ -6938,7 +6967,7 @@ react-scripts@5.0.0:
|
||||
postcss-preset-env "^7.0.1"
|
||||
prompts "^2.4.2"
|
||||
react-app-polyfill "^3.0.0"
|
||||
react-dev-utils "^12.0.0"
|
||||
react-dev-utils "^12.0.1"
|
||||
react-refresh "^0.11.0"
|
||||
resolve "^1.20.0"
|
||||
resolve-url-loader "^4.0.0"
|
||||
@@ -6955,13 +6984,12 @@ react-scripts@5.0.0:
|
||||
optionalDependencies:
|
||||
fsevents "^2.3.2"
|
||||
|
||||
react@^17.0.2:
|
||||
version "17.0.2"
|
||||
resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037"
|
||||
integrity sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA==
|
||||
react@^18.1.0:
|
||||
version "18.1.0"
|
||||
resolved "https://registry.yarnpkg.com/react/-/react-18.1.0.tgz#6f8620382decb17fdc5cc223a115e2adbf104890"
|
||||
integrity sha512-4oL8ivCz5ZEPyclFQXaNksK3adutVS8l2xzZU0cqEFrE9Sb7fC0EFK5uEk74wIreL1DERyjvsU915j1pcT2uEQ==
|
||||
dependencies:
|
||||
loose-envify "^1.1.0"
|
||||
object-assign "^4.1.1"
|
||||
|
||||
readable-stream@^2.0.1:
|
||||
version "2.3.7"
|
||||
@@ -7235,13 +7263,12 @@ saxes@^5.0.1:
|
||||
dependencies:
|
||||
xmlchars "^2.2.0"
|
||||
|
||||
scheduler@^0.20.2:
|
||||
version "0.20.2"
|
||||
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.20.2.tgz#4baee39436e34aa93b4874bddcbf0fe8b8b50e91"
|
||||
integrity sha512-2eWfGgAqqWFGqtdMmcL5zCMK1U8KlXv8SQFGglL3CEtd0aDVDWgeF/YoCmvln55m5zSk3J/20hTaSBeSObsQDQ==
|
||||
scheduler@^0.22.0:
|
||||
version "0.22.0"
|
||||
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.22.0.tgz#83a5d63594edf074add9a7198b1bae76c3db01b8"
|
||||
integrity sha512-6QAm1BgQI88NPYymgGQLCZgvep4FyePDWFpXVK+zNSUgHwlqpJy8VEh8Et0KxTACS4VWwMousBElAZOH9nkkoQ==
|
||||
dependencies:
|
||||
loose-envify "^1.1.0"
|
||||
object-assign "^4.1.1"
|
||||
|
||||
schema-utils@2.7.0:
|
||||
version "2.7.0"
|
||||
@@ -8156,10 +8183,10 @@ wbuf@^1.1.0, wbuf@^1.7.3:
|
||||
dependencies:
|
||||
minimalistic-assert "^1.0.0"
|
||||
|
||||
web-vitals@^2.1.3:
|
||||
version "2.1.3"
|
||||
resolved "https://registry.yarnpkg.com/web-vitals/-/web-vitals-2.1.3.tgz#6dca59f41dbc3fcccdb889da06191b437b18f534"
|
||||
integrity sha512-+ijpniAzcnQicXaXIN0/eHQAiV/jMt1oHGHTmz7VdAJPPkzzDhmoYPSpLgJTuFtUh+jCjxCoeTZPg7Ic+g8o7w==
|
||||
web-vitals@^2.1.4:
|
||||
version "2.1.4"
|
||||
resolved "https://registry.yarnpkg.com/web-vitals/-/web-vitals-2.1.4.tgz#76563175a475a5e835264d373704f9dde718290c"
|
||||
integrity sha512-sVWcwhU5mX6crfI5Vd2dC4qchyTqxV8URinzt25XqVh+bHEPGH4C3NPrNionCP7Obx59wrYEbNlw4Z8sjALzZg==
|
||||
|
||||
webidl-conversions@^4.0.2:
|
||||
version "4.0.2"
|
||||
|
||||
@@ -12,18 +12,20 @@
|
||||
"format": "prettier --write --plugin-search-dir=. ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sveltejs/adapter-auto": "next",
|
||||
"@sveltejs/kit": "next",
|
||||
"@sveltejs/adapter-auto": "1.0.0-next.50",
|
||||
"@sveltejs/kit": "1.0.0-next.347",
|
||||
"@types/cookie": "^0.4.1",
|
||||
"prettier": "^2.5.1",
|
||||
"prettier-plugin-svelte": "^2.5.0",
|
||||
"svelte": "^3.46.0",
|
||||
"svelte-check": "^2.2.6",
|
||||
"svelte-preprocess": "^4.10.6",
|
||||
"typescript": "~4.6.2"
|
||||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@fontsource/fira-mono": "^4.5.0",
|
||||
"cookie": "^0.4.1"
|
||||
"cookie": "^0.4.1",
|
||||
"web-vitals": "^2.1.4"
|
||||
}
|
||||
}
|
||||
|
||||
1633
examples/sveltekit/pnpm-lock.yaml
generated
1633
examples/sveltekit/pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
66
examples/sveltekit/src/lib/vitals.js
Normal file
66
examples/sveltekit/src/lib/vitals.js
Normal file
@@ -0,0 +1,66 @@
|
||||
import { getCLS, getFCP, getFID, getLCP, getTTFB } from 'web-vitals';
|
||||
|
||||
const vitalsUrl = 'https://vitals.vercel-analytics.com/v1/vitals';
|
||||
|
||||
function getConnectionSpeed() {
|
||||
return 'connection' in navigator &&
|
||||
navigator['connection'] &&
|
||||
'effectiveType' in navigator['connection']
|
||||
? // @ts-ignore
|
||||
navigator['connection']['effectiveType']
|
||||
: '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("web-vitals").Metric} metric
|
||||
* @param {{ params: { [s: string]: any; } | ArrayLike<any>; path: string; analyticsId: string; debug: boolean; }} options
|
||||
*/
|
||||
function sendToAnalytics(metric, options) {
|
||||
const page = Object.entries(options.params).reduce(
|
||||
(acc, [key, value]) => acc.replace(value, `[${key}]`),
|
||||
options.path
|
||||
);
|
||||
|
||||
const body = {
|
||||
dsn: options.analyticsId,
|
||||
id: metric.id,
|
||||
page,
|
||||
href: location.href,
|
||||
event_name: metric.name,
|
||||
value: metric.value.toString(),
|
||||
speed: getConnectionSpeed()
|
||||
};
|
||||
|
||||
if (options.debug) {
|
||||
console.log('[Analytics]', metric.name, JSON.stringify(body, null, 2));
|
||||
}
|
||||
|
||||
const blob = new Blob([new URLSearchParams(body).toString()], {
|
||||
// This content type is necessary for `sendBeacon`
|
||||
type: 'application/x-www-form-urlencoded'
|
||||
});
|
||||
if (navigator.sendBeacon) {
|
||||
navigator.sendBeacon(vitalsUrl, blob);
|
||||
} else
|
||||
fetch(vitalsUrl, {
|
||||
body: blob,
|
||||
method: 'POST',
|
||||
credentials: 'omit',
|
||||
keepalive: true
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} options
|
||||
*/
|
||||
export function webVitals(options) {
|
||||
try {
|
||||
getFID((metric) => sendToAnalytics(metric, options));
|
||||
getTTFB((metric) => sendToAnalytics(metric, options));
|
||||
getLCP((metric) => sendToAnalytics(metric, options));
|
||||
getCLS((metric) => sendToAnalytics(metric, options));
|
||||
getFCP((metric) => sendToAnalytics(metric, options));
|
||||
} catch (err) {
|
||||
console.error('[Analytics]', err);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,21 @@
|
||||
<script>
|
||||
import Header from '$lib/header/Header.svelte';
|
||||
import { webVitals } from '$lib/vitals';
|
||||
import { browser } from '$app/env';
|
||||
import { page } from '$app/stores';
|
||||
import '../app.css';
|
||||
|
||||
let analyticsId = import.meta.env.VERCEL_ANALYTICS_ID;
|
||||
|
||||
if (browser && analyticsId) {
|
||||
page.subscribe(({ url, params }) =>
|
||||
webVitals({
|
||||
path: url.pathname,
|
||||
params,
|
||||
analyticsId
|
||||
})
|
||||
);
|
||||
}
|
||||
</script>
|
||||
|
||||
<Header />
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import adapter from '@sveltejs/adapter-auto';
|
||||
import preprocess from 'svelte-preprocess';
|
||||
|
||||
/** @type {import('@sveltejs/kit').Config} */
|
||||
const config = {
|
||||
preprocess: preprocess({
|
||||
replace: [
|
||||
['import.meta.env.VERCEL_ANALYTICS_ID', JSON.stringify(process.env.VERCEL_ANALYTICS_ID)]
|
||||
]
|
||||
}),
|
||||
kit: {
|
||||
adapter: adapter(),
|
||||
|
||||
|
||||
1479
examples/sveltekit/yarn.lock
Normal file
1479
examples/sveltekit/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
@@ -30,7 +30,7 @@
|
||||
"npm-package-arg": "6.1.0",
|
||||
"prettier": "2.6.2",
|
||||
"ts-eager": "2.0.2",
|
||||
"ts-jest": "28.0.0-next.1",
|
||||
"ts-jest": "28.0.5",
|
||||
"turbo": "1.2.14"
|
||||
},
|
||||
"scripts": {
|
||||
@@ -41,7 +41,7 @@
|
||||
"publish-from-github": "./utils/publish.sh",
|
||||
"changelog": "node utils/changelog.js",
|
||||
"build": "turbo run build",
|
||||
"vercel-build": "yarn build && cd api && node -r ts-eager/register ./_lib/script/build.ts",
|
||||
"vercel-build": "yarn build && yarn run pack && cd api && node -r ts-eager/register ./_lib/script/build.ts",
|
||||
"pre-commit": "lint-staged",
|
||||
"test": "jest --rootDir=\"test\" --testPathPattern=\"\\.test.js\"",
|
||||
"test-unit": "yarn test && turbo run test-unit",
|
||||
@@ -49,7 +49,8 @@
|
||||
"test-integration-once": "turbo run test-integration-once",
|
||||
"test-integration-dev": "turbo run test-integration-dev",
|
||||
"lint": "eslint . --ext .ts,.js",
|
||||
"prepare": "husky install"
|
||||
"prepare": "husky install",
|
||||
"pack": "cd utils && node -r ts-eager/register ./pack.ts"
|
||||
},
|
||||
"lint-staged": {
|
||||
"./{*,{api,packages,test,utils}/**/*}.{js,ts}": [
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@vercel/build-utils",
|
||||
"version": "4.1.0",
|
||||
"version": "4.1.1-canary.1",
|
||||
"license": "MIT",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.js",
|
||||
@@ -31,7 +31,7 @@
|
||||
"@types/node-fetch": "^2.1.6",
|
||||
"@types/semver": "6.0.0",
|
||||
"@types/yazl": "2.4.2",
|
||||
"@vercel/frameworks": "1.0.1",
|
||||
"@vercel/frameworks": "1.0.2-canary.0",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"aggregate-error": "3.0.1",
|
||||
"async-retry": "1.2.3",
|
||||
|
||||
@@ -23,7 +23,7 @@ interface ErrorResponse {
|
||||
}
|
||||
|
||||
interface Options {
|
||||
tag?: 'canary' | 'latest' | string;
|
||||
tag?: string;
|
||||
functions?: BuilderFunctions;
|
||||
ignoreBuildScript?: boolean;
|
||||
projectSettings?: ProjectSettings;
|
||||
@@ -278,7 +278,7 @@ export async function detectBuilders(
|
||||
// and package.json can be served as static files
|
||||
frontendBuilder = {
|
||||
use: '@vercel/static',
|
||||
src: '!{api/**,package.json}',
|
||||
src: '!{api/**,package.json,middleware.[jt]s}',
|
||||
config: {
|
||||
zeroConfig: true,
|
||||
},
|
||||
@@ -355,7 +355,16 @@ function maybeGetApiBuilder(
|
||||
apiMatches: Builder[],
|
||||
options: Options
|
||||
) {
|
||||
if (!fileName.startsWith('api/')) {
|
||||
const middleware =
|
||||
fileName === 'middleware.js' || fileName === 'middleware.ts';
|
||||
|
||||
// Root-level Middleware file is handled by `@vercel/next`, so don't
|
||||
// schedule a separate Builder when "nextjs" framework is selected
|
||||
if (middleware && options.projectSettings?.framework === 'nextjs') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!(fileName.startsWith('api/') || middleware)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -381,7 +390,7 @@ function maybeGetApiBuilder(
|
||||
|
||||
const { fnPattern, func } = getFunction(fileName, options);
|
||||
|
||||
const use = (func && func.runtime) || (match && match.use);
|
||||
const use = func?.runtime || match?.use;
|
||||
|
||||
if (!use) {
|
||||
return null;
|
||||
@@ -389,6 +398,10 @@ function maybeGetApiBuilder(
|
||||
|
||||
const config: Config = { zeroConfig: true };
|
||||
|
||||
if (middleware) {
|
||||
config.middleware = true;
|
||||
}
|
||||
|
||||
if (fnPattern && func) {
|
||||
config.functions = { [fnPattern]: func };
|
||||
|
||||
@@ -428,6 +441,7 @@ function getApiMatches() {
|
||||
const config = { zeroConfig: true };
|
||||
|
||||
return [
|
||||
{ src: 'middleware.[jt]s', use: `@vercel/node`, config },
|
||||
{ src: 'api/**/*.js', use: `@vercel/node`, config },
|
||||
{ src: 'api/**/*.mjs', use: `@vercel/node`, config },
|
||||
{ src: 'api/**/*.ts', use: `@vercel/node`, config },
|
||||
|
||||
60
packages/build-utils/src/get-project-paths.ts
Normal file
60
packages/build-utils/src/get-project-paths.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { detectFramework } from './detect-framework';
|
||||
import { DetectorFilesystem } from './detectors/filesystem';
|
||||
import frameworks from '@vercel/frameworks';
|
||||
|
||||
const MAX_DEPTH_TRAVERSE = 3;
|
||||
|
||||
export interface GetProjectPathsOptions {
|
||||
fs: DetectorFilesystem;
|
||||
path?: string;
|
||||
skipPaths?: string[];
|
||||
depth?: number;
|
||||
}
|
||||
|
||||
export type ProjectPath = string;
|
||||
|
||||
export const getProjectPaths = async ({
|
||||
fs,
|
||||
path,
|
||||
skipPaths,
|
||||
depth = MAX_DEPTH_TRAVERSE,
|
||||
}: GetProjectPathsOptions): Promise<ProjectPath[]> => {
|
||||
if (depth === 0) return [];
|
||||
|
||||
const allPaths: Array<ProjectPath> = [];
|
||||
const topPath: string = path ?? './';
|
||||
|
||||
if (path && skipPaths?.includes(path)) {
|
||||
return allPaths;
|
||||
}
|
||||
const framework = await detectFramework({
|
||||
fs: fs.chdir(topPath),
|
||||
frameworkList: frameworks,
|
||||
});
|
||||
|
||||
if (framework !== null) allPaths.push(topPath);
|
||||
|
||||
if (depth > 1) {
|
||||
const directoryContents = await fs.readdir(topPath);
|
||||
const childDirectories = directoryContents.filter(
|
||||
stat => stat.type === 'dir' && !skipPaths?.includes(stat.path)
|
||||
);
|
||||
|
||||
const paths = (
|
||||
await Promise.all(
|
||||
childDirectories.map(({ path }) => {
|
||||
return getProjectPaths({
|
||||
fs,
|
||||
path,
|
||||
depth: depth - 1,
|
||||
skipPaths,
|
||||
});
|
||||
})
|
||||
)
|
||||
).flat();
|
||||
|
||||
return [...paths, ...allPaths];
|
||||
}
|
||||
|
||||
return allPaths;
|
||||
};
|
||||
@@ -88,6 +88,7 @@ export {
|
||||
} from './detect-builders';
|
||||
export { detectFileSystemAPI } from './detect-file-system-api';
|
||||
export { detectFramework } from './detect-framework';
|
||||
export { getProjectPaths } from './get-project-paths';
|
||||
export { DetectorFilesystem } from './detectors/filesystem';
|
||||
export { readConfigFile } from './fs/read-config-file';
|
||||
export { normalizePath } from './fs/normalize-path';
|
||||
|
||||
@@ -428,6 +428,8 @@ export interface BuildResultV2Typical {
|
||||
export type BuildResultV2 = BuildResultV2Typical | BuildResultBuildOutput;
|
||||
|
||||
export interface BuildResultV3 {
|
||||
// TODO: use proper `Route` type from `routing-utils` (perhaps move types to a common package)
|
||||
routes?: any[];
|
||||
output: Lambda | EdgeFunction;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "app-three",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"next": "^4.3.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "backend",
|
||||
"license": "MIT",
|
||||
"version": "0.1.0"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "app-one",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"next": "^4.3.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "app-one",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"next": "^4.3.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"license": "MIT",
|
||||
"version": "0.1.0"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "app-three",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"next": "^4.3.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "backend",
|
||||
"license": "MIT",
|
||||
"version": "0.1.0"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "a",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"debug": "^4.3.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "b",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"cowsay": "^1.5.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "21-npm-workspaces",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"workspaces": [
|
||||
"a",
|
||||
"b"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "app-three",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"next": "^4.3.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "backend",
|
||||
"license": "MIT",
|
||||
"version": "0.1.0"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "app-one",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"next": "^4.3.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "app-two",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"next": "^4.3.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"license": "MIT",
|
||||
"version": "0.1.0"
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "app-one",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "app-one",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"next": "^4.3.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "app-two",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"next": "^4.3.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "frontend",
|
||||
"license": "MIT",
|
||||
"version": "0.1.0"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "app-one",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"next": "^4.3.2"
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@ describe('Test `detectBuilders`', () => {
|
||||
expect(builders![0].use).toBe('@vercel/node');
|
||||
expect(builders![0].src).toBe('api/users.js');
|
||||
expect(builders![1].use).toBe('@vercel/static');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json}');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json,middleware.[jt]s}');
|
||||
expect(builders!.length).toBe(2);
|
||||
expect(errors).toBe(null);
|
||||
});
|
||||
@@ -89,7 +89,7 @@ describe('Test `detectBuilders`', () => {
|
||||
expect(builders![0].use).toBe('@vercel/node');
|
||||
expect(builders![0].src).toBe('api/[endpoint].js');
|
||||
expect(builders![1].use).toBe('@vercel/static');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json}');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json,middleware.[jt]s}');
|
||||
expect(builders!.length).toBe(2);
|
||||
expect(errors).toBe(null);
|
||||
});
|
||||
@@ -144,7 +144,7 @@ describe('Test `detectBuilders`', () => {
|
||||
expect(builders![0].use).toBe('@vercel/node');
|
||||
expect(builders![0].src).toBe('api/endpoint.js');
|
||||
expect(builders![1].use).toBe('@vercel/static');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json}');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json,middleware.[jt]s}');
|
||||
expect(builders!.length).toBe(2);
|
||||
});
|
||||
|
||||
@@ -347,7 +347,7 @@ describe('Test `detectBuilders`', () => {
|
||||
expect(builders![0].use).toBe('@vercel/node');
|
||||
expect(builders![0].src).toBe('api/index.ts');
|
||||
expect(builders![1].use).toBe('@vercel/static');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json}');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json,middleware.[jt]s}');
|
||||
});
|
||||
|
||||
it('functions with nextjs', async () => {
|
||||
@@ -671,8 +671,8 @@ describe('Test `detectBuilders`', () => {
|
||||
expect(builders![0].use).toBe('@vercel/static');
|
||||
|
||||
expect(defaultRoutes!.length).toBe(1);
|
||||
expect((defaultRoutes![0] as any).src).toBe('/(.*)');
|
||||
expect((defaultRoutes![0] as any).dest).toBe('/dist/$1');
|
||||
expect(defaultRoutes![0].src).toBe('/(.*)');
|
||||
expect(defaultRoutes![0].dest).toBe('/dist/$1');
|
||||
});
|
||||
|
||||
it('Custom static output directory with api', async () => {
|
||||
@@ -691,9 +691,9 @@ describe('Test `detectBuilders`', () => {
|
||||
expect(builders![1].use).toBe('@vercel/static');
|
||||
|
||||
expect(defaultRoutes!.length).toBe(3);
|
||||
expect((defaultRoutes![1] as any).status).toBe(404);
|
||||
expect((defaultRoutes![2] as any).src).toBe('/(.*)');
|
||||
expect((defaultRoutes![2] as any).dest).toBe('/output/$1');
|
||||
expect(defaultRoutes![1].status).toBe(404);
|
||||
expect(defaultRoutes![2].src).toBe('/(.*)');
|
||||
expect(defaultRoutes![2].dest).toBe('/output/$1');
|
||||
});
|
||||
|
||||
it('Framework with non-package.json entrypoint', async () => {
|
||||
@@ -1010,7 +1010,7 @@ describe('Test `detectBuilders` with `featHandleMiss=true`', () => {
|
||||
expect(builders![0].use).toBe('@vercel/node');
|
||||
expect(builders![0].src).toBe('api/users.js');
|
||||
expect(builders![1].use).toBe('@vercel/static');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json}');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json,middleware.[jt]s}');
|
||||
expect(builders!.length).toBe(2);
|
||||
expect(errors).toBe(null);
|
||||
|
||||
@@ -1032,7 +1032,7 @@ describe('Test `detectBuilders` with `featHandleMiss=true`', () => {
|
||||
expect(builders![0].use).toBe('@vercel/node');
|
||||
expect(builders![0].src).toBe('api/[endpoint].js');
|
||||
expect(builders![1].use).toBe('@vercel/static');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json}');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json,middleware.[jt]s}');
|
||||
expect(builders!.length).toBe(2);
|
||||
expect(errors).toBe(null);
|
||||
});
|
||||
@@ -1258,7 +1258,7 @@ describe('Test `detectBuilders` with `featHandleMiss=true`', () => {
|
||||
expect(builders![0].use).toBe('@vercel/node');
|
||||
expect(builders![0].src).toBe('api/endpoint.js');
|
||||
expect(builders![1].use).toBe('@vercel/static');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json}');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json,middleware.[jt]s}');
|
||||
expect(builders!.length).toBe(2);
|
||||
|
||||
expect(defaultRoutes!.length).toBe(2);
|
||||
@@ -1288,7 +1288,7 @@ describe('Test `detectBuilders` with `featHandleMiss=true`', () => {
|
||||
expect(builders![0].use).toBe('@vercel/node');
|
||||
expect(builders![0].src).toBe('api/version.js');
|
||||
expect(builders![1].use).toBe('@vercel/static');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json}');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json,middleware.[jt]s}');
|
||||
expect(builders!.length).toBe(2);
|
||||
|
||||
expect(defaultRoutes!.length).toBe(2);
|
||||
@@ -1567,7 +1567,7 @@ describe('Test `detectBuilders` with `featHandleMiss=true`', () => {
|
||||
expect(builders![0].use).toBe('@vercel/node');
|
||||
expect(builders![0].src).toBe('api/index.ts');
|
||||
expect(builders![1].use).toBe('@vercel/static');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json}');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json,middleware.[jt]s}');
|
||||
expect(errorRoutes!.length).toBe(1);
|
||||
expect((errorRoutes![0] as Source).status).toBe(404);
|
||||
});
|
||||
@@ -2228,6 +2228,55 @@ describe('Test `detectBuilders` with `featHandleMiss=true`', () => {
|
||||
expect(builders).toBe(null);
|
||||
expect(errors).toBe(null);
|
||||
});
|
||||
|
||||
it('no package.json + no build + root-level "middleware.js"', async () => {
|
||||
const files = ['middleware.js', 'index.html', 'web/middleware.js'];
|
||||
const { builders, errors } = await detectBuilders(files, null, {
|
||||
featHandleMiss,
|
||||
});
|
||||
expect(builders![0].use).toBe('@vercel/node');
|
||||
expect(builders![0].src).toBe('middleware.js');
|
||||
expect(builders![0].config?.middleware).toEqual(true);
|
||||
expect(builders![1].use).toBe('@vercel/static');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json,middleware.[jt]s}');
|
||||
expect(builders!.length).toBe(2);
|
||||
expect(errors).toBe(null);
|
||||
});
|
||||
|
||||
it('no package.json + no build + root-level "middleware.ts"', async () => {
|
||||
const files = ['middleware.ts', 'index.html', 'web/middleware.js'];
|
||||
const { builders, errors } = await detectBuilders(files, null, {
|
||||
featHandleMiss,
|
||||
});
|
||||
expect(builders![0].use).toBe('@vercel/node');
|
||||
expect(builders![0].src).toBe('middleware.ts');
|
||||
expect(builders![0].config?.middleware).toEqual(true);
|
||||
expect(builders![1].use).toBe('@vercel/static');
|
||||
expect(builders![1].src).toBe('!{api/**,package.json,middleware.[jt]s}');
|
||||
expect(builders!.length).toBe(2);
|
||||
expect(errors).toBe(null);
|
||||
});
|
||||
|
||||
it('should not add middleware builder when "nextjs" framework is selected', async () => {
|
||||
const files = ['package.json', 'pages/index.ts', 'middleware.ts'];
|
||||
const projectSettings = {
|
||||
framework: 'nextjs',
|
||||
};
|
||||
const { builders } = await detectBuilders(files, null, {
|
||||
projectSettings,
|
||||
featHandleMiss,
|
||||
});
|
||||
expect(builders).toEqual([
|
||||
{
|
||||
use: '@vercel/next',
|
||||
src: 'package.json',
|
||||
config: {
|
||||
zeroConfig: true,
|
||||
framework: projectSettings.framework,
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
it('Test `detectRoutes`', async () => {
|
||||
@@ -2236,10 +2285,10 @@ it('Test `detectRoutes`', async () => {
|
||||
|
||||
const { defaultRoutes } = await detectBuilders(files);
|
||||
expect(defaultRoutes!.length).toBe(3);
|
||||
expect((defaultRoutes![0] as any).dest).toBe('/api/team.js');
|
||||
expect((defaultRoutes![1] as any).dest).toBe('/api/user.go');
|
||||
expect((defaultRoutes![2] as any).dest).not.toBeDefined();
|
||||
expect((defaultRoutes![2] as any).status).toBe(404);
|
||||
expect(defaultRoutes![0].dest).toBe('/api/team.js');
|
||||
expect(defaultRoutes![1].dest).toBe('/api/user.go');
|
||||
expect(defaultRoutes![2].dest).not.toBeDefined();
|
||||
expect(defaultRoutes![2].status).toBe(404);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -2286,10 +2335,10 @@ it('Test `detectRoutes`', async () => {
|
||||
];
|
||||
|
||||
const { defaultRoutes } = await detectBuilders(files);
|
||||
expect((defaultRoutes![2] as any).status).toBe(404);
|
||||
expect((defaultRoutes![2] as any).src).toBe('^/api(/.*)?$');
|
||||
expect((defaultRoutes![3] as any).src).toBe('/(.*)');
|
||||
expect((defaultRoutes![3] as any).dest).toBe('/public/$1');
|
||||
expect(defaultRoutes![2].status).toBe(404);
|
||||
expect(defaultRoutes![2].src).toBe('^/api(/.*)?$');
|
||||
expect(defaultRoutes![3].src).toBe('/(.*)');
|
||||
expect(defaultRoutes![3].dest).toBe('/public/$1');
|
||||
expect(defaultRoutes!.length).toBe(4);
|
||||
}
|
||||
|
||||
@@ -2301,8 +2350,8 @@ it('Test `detectRoutes`', async () => {
|
||||
const files = ['public/index.html', 'api/[endpoint].js'];
|
||||
|
||||
const { defaultRoutes } = await detectBuilders(files, pkg);
|
||||
expect((defaultRoutes![1] as any).status).toBe(404);
|
||||
expect((defaultRoutes![1] as any).src).toBe('^/api(/.*)?$');
|
||||
expect(defaultRoutes![1].status).toBe(404);
|
||||
expect(defaultRoutes![1].src).toBe('^/api(/.*)?$');
|
||||
expect(defaultRoutes!.length).toBe(2);
|
||||
}
|
||||
|
||||
@@ -2320,14 +2369,10 @@ it('Test `detectRoutes`', async () => {
|
||||
const { defaultRoutes } = await detectBuilders(files);
|
||||
|
||||
expect(defaultRoutes!.length).toBe(3);
|
||||
expect((defaultRoutes![0] as any).src).toBe(
|
||||
'^/api/date(/|/index|/index\\.js)?$'
|
||||
);
|
||||
expect((defaultRoutes![0] as any).dest).toBe('/api/date/index.js');
|
||||
expect((defaultRoutes![1] as any).src).toBe(
|
||||
'^/api/(date/|date|date\\.js)$'
|
||||
);
|
||||
expect((defaultRoutes![1] as any).dest).toBe('/api/date.js');
|
||||
expect(defaultRoutes![0].src).toBe('^/api/date(/|/index|/index\\.js)?$');
|
||||
expect(defaultRoutes![0].dest).toBe('/api/date/index.js');
|
||||
expect(defaultRoutes![1].src).toBe('^/api/(date/|date|date\\.js)$');
|
||||
expect(defaultRoutes![1].dest).toBe('/api/date.js');
|
||||
}
|
||||
|
||||
{
|
||||
@@ -2336,16 +2381,10 @@ it('Test `detectRoutes`', async () => {
|
||||
const { defaultRoutes } = await detectBuilders(files);
|
||||
|
||||
expect(defaultRoutes!.length).toBe(3);
|
||||
expect((defaultRoutes![0] as any).src).toBe(
|
||||
'^/api/([^/]+)(/|/index|/index\\.js)?$'
|
||||
);
|
||||
expect((defaultRoutes![0] as any).dest).toBe(
|
||||
'/api/[date]/index.js?date=$1'
|
||||
);
|
||||
expect((defaultRoutes![1] as any).src).toBe(
|
||||
'^/api/(date/|date|date\\.js)$'
|
||||
);
|
||||
expect((defaultRoutes![1] as any).dest).toBe('/api/date.js');
|
||||
expect(defaultRoutes![0].src).toBe('^/api/([^/]+)(/|/index|/index\\.js)?$');
|
||||
expect(defaultRoutes![0].dest).toBe('/api/[date]/index.js?date=$1');
|
||||
expect(defaultRoutes![1].src).toBe('^/api/(date/|date|date\\.js)$');
|
||||
expect(defaultRoutes![1].dest).toBe('/api/date.js');
|
||||
}
|
||||
|
||||
{
|
||||
@@ -2375,7 +2414,7 @@ it('Test `detectRoutes`', async () => {
|
||||
const { defaultRoutes } = await detectBuilders(files, null, { functions });
|
||||
|
||||
expect(defaultRoutes!.length).toBe(2);
|
||||
expect((defaultRoutes![0] as any).dest).toBe('/api/user.php');
|
||||
expect(defaultRoutes![0].dest).toBe('/api/user.php');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
70
packages/build-utils/test/unit.get-project-paths.test.ts
vendored
Normal file
70
packages/build-utils/test/unit.get-project-paths.test.ts
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
import path from 'path';
|
||||
import { normalizePath } from '../src';
|
||||
import { getProjectPaths, ProjectPath } from '../src/get-project-paths';
|
||||
import { FixtureFilesystem } from './utils/fixture-filesystem';
|
||||
|
||||
describe.each<{
|
||||
fixturePath: string;
|
||||
resultPaths: ProjectPath[];
|
||||
skipPaths?: ProjectPath[];
|
||||
readdirCalls: number;
|
||||
}>([
|
||||
{
|
||||
fixturePath: '32-monorepo-highly-nested',
|
||||
resultPaths: [],
|
||||
readdirCalls: 2,
|
||||
},
|
||||
{
|
||||
fixturePath: '33-hybrid-monorepo',
|
||||
resultPaths: ['backend/app-three'],
|
||||
readdirCalls: 2,
|
||||
skipPaths: ['frontend'],
|
||||
},
|
||||
{
|
||||
fixturePath: '34-monorepo-no-workspaces',
|
||||
resultPaths: ['backend/app-three', 'frontend/app-one', 'frontend/app-two'],
|
||||
readdirCalls: 3,
|
||||
},
|
||||
{
|
||||
fixturePath: '35-no-monorepo',
|
||||
resultPaths: [],
|
||||
readdirCalls: 1,
|
||||
},
|
||||
{
|
||||
fixturePath: '36-monorepo-some-nested',
|
||||
resultPaths: ['frontend/app-two'],
|
||||
readdirCalls: 2,
|
||||
},
|
||||
{
|
||||
fixturePath: '37-project-depth-one-level',
|
||||
resultPaths: ['./'],
|
||||
readdirCalls: 1,
|
||||
},
|
||||
])(
|
||||
'`getProjectPaths()`',
|
||||
({ resultPaths, readdirCalls, fixturePath, skipPaths }) => {
|
||||
const testName =
|
||||
resultPaths.length > 0
|
||||
? `should detect ${resultPaths.join()} project${
|
||||
resultPaths.length > 1 ? 's' : ''
|
||||
} for ${fixturePath}`
|
||||
: `should not detect any path for ${fixturePath}`;
|
||||
|
||||
it(testName, async () => {
|
||||
const fixture = path.join(
|
||||
__dirname,
|
||||
'non-deployed-fixtures',
|
||||
fixturePath
|
||||
);
|
||||
const fs = new FixtureFilesystem(fixture);
|
||||
const mockReaddir = jest.fn().mockImplementation(fs.readdir);
|
||||
const mockHasPath = jest.fn().mockImplementation(fs.hasPath);
|
||||
fs.readdir = mockReaddir;
|
||||
fs.hasPath = mockHasPath;
|
||||
const actualPaths = await getProjectPaths({ fs, skipPaths });
|
||||
const normalizedPaths = actualPaths.map(path => normalizePath(path));
|
||||
expect(normalizedPaths).toEqual(resultPaths);
|
||||
expect(fs.readdir).toHaveBeenCalledTimes(readdirCalls);
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vercel",
|
||||
"version": "25.1.0",
|
||||
"version": "25.1.1-canary.5",
|
||||
"preferGlobal": true,
|
||||
"license": "Apache-2.0",
|
||||
"description": "The command-line interface for Vercel",
|
||||
@@ -42,15 +42,15 @@
|
||||
"node": ">= 14"
|
||||
},
|
||||
"dependencies": {
|
||||
"@vercel/build-utils": "4.1.0",
|
||||
"@vercel/go": "2.0.1",
|
||||
"@vercel/next": "3.0.1",
|
||||
"@vercel/node": "2.1.0",
|
||||
"@vercel/python": "3.0.1",
|
||||
"@vercel/redwood": "1.0.1",
|
||||
"@vercel/remix": "1.0.1",
|
||||
"@vercel/ruby": "1.3.9",
|
||||
"@vercel/static-build": "1.0.1",
|
||||
"@vercel/build-utils": "4.1.1-canary.1",
|
||||
"@vercel/go": "2.0.2-canary.1",
|
||||
"@vercel/next": "3.0.3",
|
||||
"@vercel/node": "2.2.1-canary.0",
|
||||
"@vercel/python": "3.0.2-canary.1",
|
||||
"@vercel/redwood": "1.0.2-canary.1",
|
||||
"@vercel/remix": "1.0.2-canary.1",
|
||||
"@vercel/ruby": "1.3.10-canary.1",
|
||||
"@vercel/static-build": "1.0.2-canary.1",
|
||||
"update-notifier": "5.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -71,6 +71,7 @@
|
||||
"@types/fs-extra": "9.0.13",
|
||||
"@types/glob": "7.1.1",
|
||||
"@types/http-proxy": "1.16.2",
|
||||
"@types/ini": "1.3.31",
|
||||
"@types/inquirer": "7.3.1",
|
||||
"@types/jest": "27.4.1",
|
||||
"@types/jest-expect-message": "1.0.3",
|
||||
@@ -94,8 +95,8 @@
|
||||
"@types/which": "1.3.2",
|
||||
"@types/write-json-file": "2.2.1",
|
||||
"@types/yauzl-promise": "2.1.0",
|
||||
"@vercel/client": "12.0.1",
|
||||
"@vercel/frameworks": "1.0.1",
|
||||
"@vercel/client": "12.0.2-canary.1",
|
||||
"@vercel/frameworks": "1.0.2-canary.0",
|
||||
"@vercel/ncc": "0.24.0",
|
||||
"@zeit/fun": "0.11.2",
|
||||
"@zeit/source-map-support": "0.6.2",
|
||||
@@ -130,11 +131,13 @@
|
||||
"fast-deep-equal": "3.1.3",
|
||||
"fs-extra": "10.0.0",
|
||||
"get-port": "5.1.1",
|
||||
"git-last-commit": "1.0.1",
|
||||
"glob": "7.1.2",
|
||||
"http-proxy": "1.18.1",
|
||||
"ini": "3.0.0",
|
||||
"inquirer": "7.0.4",
|
||||
"is-docker": "2.2.1",
|
||||
"is-port-reachable": "3.0.0",
|
||||
"is-port-reachable": "3.1.0",
|
||||
"is-url": "1.2.2",
|
||||
"jaro-winkler": "0.2.8",
|
||||
"jsonlines": "0.1.1",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import fs from 'fs-extra';
|
||||
import chalk from 'chalk';
|
||||
import dotenv from 'dotenv';
|
||||
import { join, relative } from 'path';
|
||||
import { join, normalize, relative } from 'path';
|
||||
import {
|
||||
detectBuilders,
|
||||
normalizePath,
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
BuildResultV2,
|
||||
BuildResultV2Typical,
|
||||
BuildResultV3,
|
||||
NowBuildError,
|
||||
} from '@vercel/build-utils';
|
||||
import minimatch from 'minimatch';
|
||||
import {
|
||||
@@ -101,6 +102,7 @@ export default async function main(client: Client): Promise<number> {
|
||||
const argv = getArgs(client.argv.slice(2), {
|
||||
'--cwd': String,
|
||||
'--prod': Boolean,
|
||||
'--yes': Boolean,
|
||||
});
|
||||
|
||||
if (argv['--help']) {
|
||||
@@ -114,42 +116,53 @@ export default async function main(client: Client): Promise<number> {
|
||||
}
|
||||
const cwd = process.cwd();
|
||||
|
||||
// Build `target` influences which environment variables will be used
|
||||
const target = argv['--prod'] ? 'production' : 'preview';
|
||||
const yes = Boolean(argv['--yes']);
|
||||
|
||||
// TODO: read project settings from the API, fall back to local `project.json` if that fails
|
||||
|
||||
// Read project settings, and pull them from Vercel if necessary
|
||||
let project = await readProjectSettings(join(cwd, VERCEL_DIR));
|
||||
const isTTY = process.stdin.isTTY;
|
||||
while (!project?.settings) {
|
||||
if (!isTTY) {
|
||||
client.output.print(
|
||||
`No Project Settings found locally. Run ${cli.getCommandName(
|
||||
'pull --yes'
|
||||
)} to retreive them.`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
let confirmed = yes;
|
||||
if (!confirmed) {
|
||||
if (!isTTY) {
|
||||
client.output.print(
|
||||
`No Project Settings found locally. Run ${cli.getCommandName(
|
||||
'pull --yes'
|
||||
)} to retreive them.`
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const confirmed = await confirm(
|
||||
`No Project Settings found locally. Run ${cli.getCommandName(
|
||||
'pull'
|
||||
)} for retrieving them?`,
|
||||
true
|
||||
);
|
||||
confirmed = await confirm(
|
||||
`No Project Settings found locally. Run ${cli.getCommandName(
|
||||
'pull'
|
||||
)} for retrieving them?`,
|
||||
true
|
||||
);
|
||||
}
|
||||
if (!confirmed) {
|
||||
client.output.print(`Aborted. No Project Settings retrieved.\n`);
|
||||
return 0;
|
||||
}
|
||||
client.argv = [];
|
||||
const { argv: originalArgv } = client;
|
||||
client.argv = [
|
||||
...originalArgv.slice(0, 2),
|
||||
'pull',
|
||||
`--environment`,
|
||||
target,
|
||||
];
|
||||
const result = await pull(client);
|
||||
if (result !== 0) {
|
||||
return result;
|
||||
}
|
||||
client.argv = originalArgv;
|
||||
project = await readProjectSettings(join(cwd, VERCEL_DIR));
|
||||
}
|
||||
|
||||
// Build `target` influences which environment variables will be used
|
||||
const target = argv['--prod'] ? 'production' : 'preview';
|
||||
|
||||
// TODO: load env vars from the API, fall back to local files if that fails
|
||||
|
||||
const envPath = await checkExists([
|
||||
@@ -463,17 +476,33 @@ export default async function main(client: Client): Promise<number> {
|
||||
}
|
||||
|
||||
function expandBuild(files: string[], build: Builder): Builder[] {
|
||||
if (!build.src) return [];
|
||||
if (!build.use) {
|
||||
throw new NowBuildError({
|
||||
code: `invalid_build_specification`,
|
||||
message: 'Field `use` is missing in build specification',
|
||||
link: 'https://vercel.com/docs/configuration#project/builds',
|
||||
action: 'View Documentation',
|
||||
});
|
||||
}
|
||||
|
||||
let pattern = build.src;
|
||||
if (pattern[0] === '/') {
|
||||
let src = normalize(build.src || '**');
|
||||
if (src === '.' || src === './') {
|
||||
throw new NowBuildError({
|
||||
code: `invalid_build_specification`,
|
||||
message: 'A build `src` path resolves to an empty string',
|
||||
link: 'https://vercel.com/docs/configuration#project/builds',
|
||||
action: 'View Documentation',
|
||||
});
|
||||
}
|
||||
|
||||
if (src[0] === '/') {
|
||||
// Remove a leading slash so that the globbing is relative
|
||||
// to `cwd` instead of the root of the filesystem.
|
||||
pattern = pattern.substring(1);
|
||||
src = src.substring(1);
|
||||
}
|
||||
|
||||
const matches = files.filter(
|
||||
name => name === pattern || minimatch(name, pattern, { dot: true })
|
||||
name => name === src || minimatch(name, src, { dot: true })
|
||||
);
|
||||
|
||||
return matches.map(m => {
|
||||
|
||||
@@ -43,7 +43,9 @@ import {
|
||||
import { SchemaValidationFailed } from '../../util/errors';
|
||||
import purchaseDomainIfAvailable from '../../util/domains/purchase-domain-if-available';
|
||||
import confirm from '../../util/input/confirm';
|
||||
import editProjectSettings from '../../util/input/edit-project-settings';
|
||||
import editProjectSettings, {
|
||||
PartialProjectSettings,
|
||||
} from '../../util/input/edit-project-settings';
|
||||
import {
|
||||
getLinkedProject,
|
||||
linkFolderToProject,
|
||||
@@ -63,6 +65,7 @@ import { help } from './args';
|
||||
import { getDeploymentChecks } from '../../util/deploy/get-deployment-checks';
|
||||
import parseTarget from '../../util/deploy/parse-target';
|
||||
import getPrebuiltJson from '../../util/deploy/get-prebuilt-json';
|
||||
import { createGitMeta } from '../../util/deploy/create-git-meta';
|
||||
|
||||
export default async (client: Client) => {
|
||||
const { output } = client;
|
||||
@@ -415,6 +418,8 @@ export default async (client: Client) => {
|
||||
parseMeta(argv['--meta'])
|
||||
);
|
||||
|
||||
const gitMetadata = await createGitMeta(path, output);
|
||||
|
||||
// Merge dotenv config, `env` from vercel.json, and `--env` / `-e` arguments
|
||||
const deploymentEnv = Object.assign(
|
||||
{},
|
||||
@@ -453,6 +458,15 @@ export default async (client: Client) => {
|
||||
let deployStamp = stamp();
|
||||
let deployment = null;
|
||||
|
||||
const localConfigurationOverrides: PartialProjectSettings = {
|
||||
buildCommand: localConfig?.buildCommand,
|
||||
devCommand: localConfig?.devCommand,
|
||||
framework: localConfig?.framework,
|
||||
commandForIgnoringBuildStep: localConfig?.ignoreCommand,
|
||||
installCommand: localConfig?.installCommand,
|
||||
outputDirectory: localConfig?.outputDirectory,
|
||||
};
|
||||
|
||||
try {
|
||||
const createArgs: any = {
|
||||
name: project ? project.name : newProjectName,
|
||||
@@ -468,6 +482,7 @@ export default async (client: Client) => {
|
||||
nowConfig: localConfig,
|
||||
regions,
|
||||
meta,
|
||||
gitMetadata,
|
||||
deployStamp,
|
||||
target,
|
||||
skipAutoDetectionConfirmation: autoConfirm,
|
||||
@@ -475,7 +490,12 @@ export default async (client: Client) => {
|
||||
|
||||
if (!localConfig.builds || localConfig.builds.length === 0) {
|
||||
// Only add projectSettings for zero config deployments
|
||||
createArgs.projectSettings = { sourceFilesOutsideRootDirectory };
|
||||
createArgs.projectSettings =
|
||||
status === 'not_linked'
|
||||
? {
|
||||
sourceFilesOutsideRootDirectory,
|
||||
}
|
||||
: { ...localConfigurationOverrides, sourceFilesOutsideRootDirectory };
|
||||
}
|
||||
|
||||
deployment = await createDeploy(
|
||||
@@ -503,7 +523,9 @@ export default async (client: Client) => {
|
||||
const settings = await editProjectSettings(
|
||||
output,
|
||||
projectSettings,
|
||||
framework
|
||||
framework,
|
||||
false,
|
||||
localConfigurationOverrides
|
||||
);
|
||||
|
||||
// deploy again, but send projectSettings this time
|
||||
|
||||
@@ -150,17 +150,7 @@ export default async function inspect(
|
||||
`This Domain is not configured properly. To configure it you should either:`,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
{
|
||||
boxen: {
|
||||
margin: {
|
||||
left: 2,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
top: 0,
|
||||
},
|
||||
},
|
||||
}
|
||||
null
|
||||
);
|
||||
output.print(
|
||||
` ${chalk.grey('a)')} ` +
|
||||
|
||||
@@ -9,6 +9,7 @@ export default new Map([
|
||||
['certs', 'certs'],
|
||||
['deploy', 'deploy'],
|
||||
['dev', 'dev'],
|
||||
['develop', 'dev'],
|
||||
['dns', 'dns'],
|
||||
['domain', 'domains'],
|
||||
['domains', 'domains'],
|
||||
|
||||
@@ -296,6 +296,15 @@ export interface Token {
|
||||
teamId?: string;
|
||||
}
|
||||
|
||||
export interface GitMetadata {
|
||||
commitAuthorName?: string | undefined;
|
||||
commitMessage?: string | undefined;
|
||||
commitRef?: string | undefined;
|
||||
commitSha?: string | undefined;
|
||||
dirty?: boolean | undefined;
|
||||
remoteUrl: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* An object representing a Build on Vercel
|
||||
*/
|
||||
|
||||
79
packages/cli/src/util/deploy/create-git-meta.ts
Normal file
79
packages/cli/src/util/deploy/create-git-meta.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
import fs from 'fs-extra';
|
||||
import { join } from 'path';
|
||||
import ini from 'ini';
|
||||
import git from 'git-last-commit';
|
||||
import { exec } from 'child_process';
|
||||
import { GitMetadata } from '../../types';
|
||||
import { Output } from '../output';
|
||||
|
||||
export function isDirty(directory: string): Promise<boolean> {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec('git status -s', { cwd: directory }, function (err, stdout, stderr) {
|
||||
if (err) return reject(err);
|
||||
if (stderr)
|
||||
return reject(
|
||||
new Error(
|
||||
`Failed to determine if git repo has been modified: ${stderr.trim()}`
|
||||
)
|
||||
);
|
||||
resolve(stdout.trim().length > 0);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getLastCommit(directory: string): Promise<git.Commit> {
|
||||
return new Promise((resolve, reject) => {
|
||||
git.getLastCommit(
|
||||
(err, commit) => {
|
||||
if (err) return reject(err);
|
||||
resolve(commit);
|
||||
},
|
||||
{ dst: directory }
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export async function getRemoteUrl(
|
||||
configPath: string,
|
||||
output: Output
|
||||
): Promise<string | null> {
|
||||
let gitConfig;
|
||||
try {
|
||||
gitConfig = ini.parse(await fs.readFile(configPath, 'utf-8'));
|
||||
} catch (error) {
|
||||
output.debug(`Error while parsing repo data: ${error.message}`);
|
||||
}
|
||||
if (!gitConfig) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const originUrl: string = gitConfig['remote "origin"']?.url;
|
||||
if (originUrl) {
|
||||
return originUrl;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function createGitMeta(
|
||||
directory: string,
|
||||
output: Output
|
||||
): Promise<GitMetadata | undefined> {
|
||||
const remoteUrl = await getRemoteUrl(join(directory, '.git/config'), output);
|
||||
// If we can't get the repo URL, then don't return any metadata
|
||||
if (!remoteUrl) {
|
||||
return;
|
||||
}
|
||||
const [commit, dirty] = await Promise.all([
|
||||
getLastCommit(directory),
|
||||
isDirty(directory),
|
||||
]);
|
||||
|
||||
return {
|
||||
remoteUrl,
|
||||
commitAuthorName: commit.author.name,
|
||||
commitMessage: commit.subject,
|
||||
commitRef: commit.branch,
|
||||
commitSha: commit.hash,
|
||||
dirty,
|
||||
};
|
||||
}
|
||||
@@ -417,10 +417,6 @@ export async function getBuildMatches(
|
||||
src = src.substring(1);
|
||||
}
|
||||
|
||||
// We need to escape brackets since `glob` will
|
||||
// try to find a group otherwise
|
||||
src = src.replace(/(\[|\])/g, '[$1]');
|
||||
|
||||
// lambda function files are trimmed of their file extension
|
||||
const mapToEntrypoint = new Map<string, string>();
|
||||
const extensionless = devServer.getExtensionlessFile(src);
|
||||
@@ -429,6 +425,10 @@ export async function getBuildMatches(
|
||||
src = extensionless;
|
||||
}
|
||||
|
||||
// We need to escape brackets since `glob` will
|
||||
// try to find a group otherwise
|
||||
src = src.replace(/(\[|\])/g, '[$1]');
|
||||
|
||||
const files = fileList
|
||||
.filter(name => name === src || minimatch(name, src, { dot: true }))
|
||||
.map(name => join(cwd, name));
|
||||
|
||||
@@ -2447,12 +2447,10 @@ function needsBlockingBuild(buildMatch: BuildMatch): boolean {
|
||||
return typeof builder.shouldServe !== 'function';
|
||||
}
|
||||
|
||||
async function checkForPort(
|
||||
port: number | undefined,
|
||||
timeout: number
|
||||
): Promise<void> {
|
||||
async function checkForPort(port: number, timeout: number): Promise<void> {
|
||||
const opts = { host: '127.0.0.1' };
|
||||
const start = Date.now();
|
||||
while (!(await isPortReachable(port))) {
|
||||
while (!(await isPortReachable(port, opts))) {
|
||||
if (Date.now() - start > timeout) {
|
||||
throw new Error(`Detecting port ${port} timed out after ${timeout}ms`);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import { responseError } from './error';
|
||||
import stamp from './output/stamp';
|
||||
import { APIError, BuildError } from './errors-ts';
|
||||
import printIndications from './print-indications';
|
||||
import { Org } from '../types';
|
||||
import { GitMetadata, Org } from '../types';
|
||||
import { VercelConfig } from './dev/types';
|
||||
import Client, { FetchOptions, isJSONObject } from './client';
|
||||
import { Dictionary } from '@vercel/client';
|
||||
@@ -38,6 +38,7 @@ export interface CreateOptions {
|
||||
prebuilt?: boolean;
|
||||
rootDirectory?: string;
|
||||
meta: Dictionary<string>;
|
||||
gitMetadata?: GitMetadata;
|
||||
regions?: string[];
|
||||
quiet?: boolean;
|
||||
env: Dictionary<string>;
|
||||
@@ -116,6 +117,7 @@ export default class Now extends EventEmitter {
|
||||
rootDirectory,
|
||||
wantsPublic,
|
||||
meta,
|
||||
gitMetadata,
|
||||
regions,
|
||||
quiet = false,
|
||||
env,
|
||||
@@ -142,6 +144,7 @@ export default class Now extends EventEmitter {
|
||||
name,
|
||||
project,
|
||||
meta,
|
||||
gitMetadata,
|
||||
regions,
|
||||
target: target || undefined,
|
||||
projectSettings,
|
||||
|
||||
@@ -2,37 +2,80 @@ import inquirer from 'inquirer';
|
||||
import confirm from './confirm';
|
||||
import chalk from 'chalk';
|
||||
import { Output } from '../output';
|
||||
import { Framework } from '@vercel/frameworks';
|
||||
import frameworkList, { Framework } from '@vercel/frameworks';
|
||||
import { isSettingValue } from '../is-setting-value';
|
||||
import { ProjectSettings } from '../../types';
|
||||
|
||||
export interface PartialProjectSettings {
|
||||
buildCommand: string | null;
|
||||
outputDirectory: string | null;
|
||||
devCommand: string | null;
|
||||
}
|
||||
|
||||
const fields: { name: string; value: keyof PartialProjectSettings }[] = [
|
||||
{ name: 'Build Command', value: 'buildCommand' },
|
||||
{ name: 'Output Directory', value: 'outputDirectory' },
|
||||
{ name: 'Development Command', value: 'devCommand' },
|
||||
const settingMap = {
|
||||
buildCommand: 'Build Command',
|
||||
devCommand: 'Development Command',
|
||||
commandForIgnoringBuildStep: 'Ignore Command',
|
||||
installCommand: 'Install Command',
|
||||
outputDirectory: 'Output Directory',
|
||||
framework: 'Framework',
|
||||
} as const;
|
||||
type ConfigKeys = keyof typeof settingMap;
|
||||
const settingKeys = Object.keys(settingMap).sort() as unknown as readonly [
|
||||
ConfigKeys
|
||||
];
|
||||
|
||||
export type PartialProjectSettings = Pick<ProjectSettings, ConfigKeys>;
|
||||
|
||||
export default async function editProjectSettings(
|
||||
output: Output,
|
||||
projectSettings: PartialProjectSettings | null,
|
||||
framework: Framework | null,
|
||||
autoConfirm?: boolean
|
||||
autoConfirm: boolean,
|
||||
localConfigurationOverrides: PartialProjectSettings | null
|
||||
): Promise<ProjectSettings> {
|
||||
// create new settings object, missing values will be filled with `null`
|
||||
// Create initial settings object defaulting everything to `null` and assigning what may exist in `projectSettings`
|
||||
const settings: ProjectSettings = Object.assign(
|
||||
{ framework: null },
|
||||
{
|
||||
buildCommand: null,
|
||||
devCommand: null,
|
||||
framework: null,
|
||||
commandForIgnoringBuildStep: null,
|
||||
installCommand: null,
|
||||
outputDirectory: null,
|
||||
},
|
||||
projectSettings
|
||||
);
|
||||
|
||||
for (let field of fields) {
|
||||
settings[field.value] =
|
||||
(projectSettings && projectSettings[field.value]) || null;
|
||||
// Start UX by displaying (and applying) overrides. They will be referenced throughout remainder of CLI.
|
||||
if (localConfigurationOverrides) {
|
||||
// Apply local overrides (from `vercel.json`)
|
||||
for (const setting of settingKeys) {
|
||||
const localConfigValue = localConfigurationOverrides[setting];
|
||||
if (localConfigValue) settings[setting] = localConfigValue;
|
||||
}
|
||||
|
||||
output.print('Local settings detected in vercel.json:\n');
|
||||
|
||||
// Print provided overrides including framework
|
||||
for (const setting of settingKeys) {
|
||||
const override = localConfigurationOverrides[setting];
|
||||
if (override) {
|
||||
output.print(
|
||||
`${chalk.dim(
|
||||
`- ${chalk.bold(`${settingMap[setting]}:`)} ${override}`
|
||||
)}\n`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// If framework is overridden, set it to the `framework` parameter and let the normal framework-flow occur
|
||||
if (localConfigurationOverrides.framework) {
|
||||
const overrideFramework = frameworkList.find(
|
||||
f => f.slug === localConfigurationOverrides.framework
|
||||
);
|
||||
|
||||
if (overrideFramework) {
|
||||
framework = overrideFramework;
|
||||
output.print(
|
||||
`Merging default Project Settings for ${framework.name}. Previously listed overrides are prioritized.\n`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// skip editing project settings if no framework is detected
|
||||
@@ -41,6 +84,7 @@ export default async function editProjectSettings(
|
||||
return settings;
|
||||
}
|
||||
|
||||
// A missing framework slug implies the "Other" framework was selected
|
||||
output.print(
|
||||
!framework.slug
|
||||
? `No framework detected. Default Project Settings:\n`
|
||||
@@ -49,44 +93,78 @@ export default async function editProjectSettings(
|
||||
|
||||
settings.framework = framework.slug;
|
||||
|
||||
for (let field of fields) {
|
||||
const defaults = framework.settings[field.value];
|
||||
// Now print defaults for the provided framework whether it was auto-detected or overwritten
|
||||
for (const setting of settingKeys) {
|
||||
if (setting === 'framework' || setting === 'commandForIgnoringBuildStep') {
|
||||
continue;
|
||||
}
|
||||
|
||||
output.print(
|
||||
chalk.dim(
|
||||
`- ${chalk.bold(`${field.name}:`)} ${`${
|
||||
isSettingValue(defaults)
|
||||
? defaults.value
|
||||
: chalk.italic(`${defaults.placeholder}`)
|
||||
}`}`
|
||||
) + '\n'
|
||||
);
|
||||
const defaultSetting = framework.settings[setting];
|
||||
const override = localConfigurationOverrides?.[setting];
|
||||
|
||||
if (!override && defaultSetting) {
|
||||
output.print(
|
||||
`${chalk.dim(
|
||||
`- ${chalk.bold(`${settingMap[setting]}:`)} ${
|
||||
isSettingValue(defaultSetting)
|
||||
? defaultSetting.value
|
||||
: chalk.italic(`${defaultSetting.placeholder}`)
|
||||
}`
|
||||
)}\n`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Prompt the user if they want to modify any settings not defined by local configuration.
|
||||
if (
|
||||
autoConfirm ||
|
||||
!(await confirm(`Want to override the settings?`, false))
|
||||
!(await confirm('Want to modify these settings?', false))
|
||||
) {
|
||||
return settings;
|
||||
}
|
||||
|
||||
const { settingFields } = await inquirer.prompt({
|
||||
const choices = settingKeys.reduce<Array<{ name: string; value: string }>>(
|
||||
(acc, setting) => {
|
||||
const skip =
|
||||
setting === 'framework' ||
|
||||
setting === 'commandForIgnoringBuildStep' ||
|
||||
setting === 'installCommand' ||
|
||||
localConfigurationOverrides?.[setting];
|
||||
if (!skip) {
|
||||
acc.push({ name: settingMap[setting], value: setting });
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
const { settingFields } = await inquirer.prompt<{
|
||||
settingFields: Array<
|
||||
Exclude<
|
||||
ConfigKeys,
|
||||
'framework' | 'commandForIgnoringBuildStep' | 'installCommand'
|
||||
>
|
||||
>;
|
||||
}>({
|
||||
name: 'settingFields',
|
||||
type: 'checkbox',
|
||||
message: 'Which settings would you like to overwrite (select multiple)?',
|
||||
choices: fields,
|
||||
choices,
|
||||
});
|
||||
|
||||
for (let setting of settingFields as (keyof PartialProjectSettings)[]) {
|
||||
const field = fields.find(f => f.value === setting);
|
||||
const name = `${Date.now()}`;
|
||||
const answers = await inquirer.prompt({
|
||||
for (let setting of settingFields) {
|
||||
const field = settingMap[setting];
|
||||
const answers = await inquirer.prompt<{
|
||||
[k in Exclude<
|
||||
ConfigKeys,
|
||||
'framework' | 'commandForIgnoringBuildStep' | 'installCommand'
|
||||
>]: string;
|
||||
}>({
|
||||
type: 'input',
|
||||
name: name,
|
||||
message: `What's your ${chalk.bold(field ? field.name : setting)}?`,
|
||||
name: setting,
|
||||
message: `What's your ${chalk.bold(field)}?`,
|
||||
});
|
||||
settings[setting] = answers[name] as string;
|
||||
settings[setting] = answers[setting];
|
||||
}
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,9 @@ import selectOrg from '../input/select-org';
|
||||
import inputProject from '../input/input-project';
|
||||
import { validateRootDirectory } from '../validate-paths';
|
||||
import { inputRootDirectory } from '../input/input-root-directory';
|
||||
import editProjectSettings from '../input/edit-project-settings';
|
||||
import editProjectSettings, {
|
||||
PartialProjectSettings,
|
||||
} from '../input/edit-project-settings';
|
||||
import stamp from '../output/stamp';
|
||||
import { EmojiLabel } from '../emoji';
|
||||
import createDeploy from '../deploy/create-deploy';
|
||||
@@ -162,6 +164,16 @@ export default async function setupAndLink(
|
||||
client,
|
||||
currentTeam: config.currentTeam,
|
||||
});
|
||||
|
||||
const localConfigurationOverrides: PartialProjectSettings = {
|
||||
buildCommand: localConfig?.buildCommand,
|
||||
devCommand: localConfig?.devCommand,
|
||||
framework: localConfig?.framework,
|
||||
commandForIgnoringBuildStep: localConfig?.ignoreCommand,
|
||||
installCommand: localConfig?.installCommand,
|
||||
outputDirectory: localConfig?.outputDirectory,
|
||||
};
|
||||
|
||||
const createArgs: CreateOptions = {
|
||||
name: newProjectName,
|
||||
env: {},
|
||||
@@ -176,13 +188,12 @@ export default async function setupAndLink(
|
||||
deployStamp: stamp(),
|
||||
target: undefined,
|
||||
skipAutoDetectionConfirmation: false,
|
||||
projectSettings: {
|
||||
...localConfigurationOverrides,
|
||||
sourceFilesOutsideRootDirectory,
|
||||
},
|
||||
};
|
||||
|
||||
if (isZeroConfig) {
|
||||
// Only add projectSettings for zero config deployments
|
||||
createArgs.projectSettings = { sourceFilesOutsideRootDirectory };
|
||||
}
|
||||
|
||||
const deployment = await createDeploy(
|
||||
client,
|
||||
now,
|
||||
@@ -216,7 +227,8 @@ export default async function setupAndLink(
|
||||
output,
|
||||
projectSettings,
|
||||
framework,
|
||||
autoConfirm
|
||||
autoConfirm,
|
||||
localConfigurationOverrides
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import chalk from 'chalk';
|
||||
import boxen from 'boxen';
|
||||
import renderLink from './link';
|
||||
import wait, { StopSpinner } from './wait';
|
||||
import { Writable } from 'stream';
|
||||
@@ -17,7 +16,7 @@ export interface LogOptions extends PrintOptions {
|
||||
}
|
||||
|
||||
export class Output {
|
||||
private debugEnabled: boolean;
|
||||
debugEnabled: boolean;
|
||||
private spinnerMessage: string;
|
||||
private _spinner: StopSpinner | null;
|
||||
isTTY: boolean;
|
||||
@@ -51,28 +50,15 @@ export class Output {
|
||||
str: string,
|
||||
slug: string | null = null,
|
||||
link: string | null = null,
|
||||
action: string | null = 'Learn More',
|
||||
options?: {
|
||||
boxen?: boxen.Options;
|
||||
}
|
||||
action: string | null = 'Learn More'
|
||||
) => {
|
||||
const details = slug ? `https://err.sh/vercel/${slug}` : link;
|
||||
|
||||
this.print(
|
||||
boxen(
|
||||
chalk.bold.yellow('WARN! ') +
|
||||
chalk.yellow(
|
||||
chalk.bold('WARN! ') +
|
||||
str +
|
||||
(details ? `\n${action}: ${renderLink(details)}` : ''),
|
||||
{
|
||||
padding: {
|
||||
top: 0,
|
||||
bottom: 0,
|
||||
left: 1,
|
||||
right: 1,
|
||||
},
|
||||
borderColor: 'yellow',
|
||||
...options?.boxen,
|
||||
}
|
||||
(details ? `\n${action}: ${renderLink(details)}` : '')
|
||||
)
|
||||
);
|
||||
this.print('\n');
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
import _pkg from '../../package.json';
|
||||
import fs from 'fs';
|
||||
import { join } from 'path';
|
||||
import { PackageJson } from '@vercel/build-utils';
|
||||
|
||||
const pkg: PackageJson & typeof _pkg = _pkg;
|
||||
let rootDir = __dirname;
|
||||
while (!fs.existsSync(join(rootDir, 'package.json'))) {
|
||||
rootDir = join(rootDir, '..');
|
||||
}
|
||||
|
||||
const pkgPath = join(rootDir, 'package.json');
|
||||
const pkg: PackageJson & typeof import('../../package.json') = JSON.parse(
|
||||
fs.readFileSync(pkgPath, 'utf8')
|
||||
);
|
||||
export default pkg;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
const { readFileSync } = require('fs');
|
||||
const { join } = require('path');
|
||||
|
||||
module.exports = function handler(_req, res) {
|
||||
const path = join(__dirname, '[id].js');
|
||||
const file = readFileSync(path, 'utf8');
|
||||
res.end(file ? 'found .js' : 'did not find .js');
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
import { readFileSync } from 'fs';
|
||||
|
||||
export default function handler(_req, res) {
|
||||
const url = new URL('[id].mjs', import.meta.url);
|
||||
const file = readFileSync(url, 'utf8');
|
||||
res.end(file ? 'found .mjs' : 'did not find .mjs');
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
import decamelize from 'decamelize';
|
||||
import { upper } from '../lib/upper';
|
||||
|
||||
export const config = {
|
||||
runtime: 'experimental-edge',
|
||||
};
|
||||
|
||||
export default async function edge(request, event) {
|
||||
const requestBody = await request.text();
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
headerContentType: request.headers.get('content-type'),
|
||||
url: request.url,
|
||||
method: request.method,
|
||||
body: requestBody,
|
||||
decamelized: decamelize('someCamelCaseThing'),
|
||||
uppercase: upper('someThing'),
|
||||
optionalChaining: request?.doesnotexist ?? 'fallback',
|
||||
})
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"decamelize": "6.0.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export function upper(str) {
|
||||
return str.toUpperCase();
|
||||
}
|
||||
@@ -14,6 +14,40 @@ const {
|
||||
validateResponseHeaders,
|
||||
} = require('./utils.js');
|
||||
|
||||
test('[vercel dev] should support edge functions', async () => {
|
||||
const dir = fixture('edge-function');
|
||||
const { dev, port, readyResolver } = await testFixture(dir);
|
||||
|
||||
try {
|
||||
await readyResolver;
|
||||
|
||||
const body = { hello: 'world' };
|
||||
|
||||
let res = await fetch(`http://localhost:${port}/api/edge-function`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
validateResponseHeaders(res);
|
||||
|
||||
// support for edge functions has to manually ensure that these properties
|
||||
// are set up; so, we test that they are all passed through properly
|
||||
expect(await res.json()).toMatchObject({
|
||||
headerContentType: 'application/json',
|
||||
url: `http://localhost:${port}/api/edge-function`,
|
||||
method: 'POST',
|
||||
body: '{"hello":"world"}',
|
||||
decamelized: 'some_camel_case_thing',
|
||||
uppercase: 'SOMETHING',
|
||||
optionalChaining: 'fallback',
|
||||
});
|
||||
} finally {
|
||||
await dev.kill('SIGTERM');
|
||||
}
|
||||
});
|
||||
|
||||
test('[vercel dev] should support request body', async () => {
|
||||
const dir = fixture('node-request-body');
|
||||
const { dev, port, readyResolver } = await testFixture(dir);
|
||||
|
||||
@@ -315,6 +315,14 @@ test(
|
||||
})
|
||||
);
|
||||
|
||||
test(
|
||||
'[vercel dev] 42-dynamic-esm-ext',
|
||||
testFixtureStdio('42-dynamic-esm-ext', async (testPath: any) => {
|
||||
await testPath(200, '/api/cjs/foo', 'found .js');
|
||||
await testPath(200, '/api/esm/foo', 'found .mjs');
|
||||
})
|
||||
);
|
||||
|
||||
test(
|
||||
'[vercel dev] Use `@vercel/python` with Flask requirements.txt',
|
||||
testFixtureStdio('python-flask', async (testPath: any) => {
|
||||
|
||||
7
packages/cli/test/fixtures/unit/commands/build/middleware/.vercel/project.json
vendored
Normal file
7
packages/cli/test/fixtures/unit/commands/build/middleware/.vercel/project.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"orgId": ".",
|
||||
"projectId": ".",
|
||||
"settings": {
|
||||
"framework": null
|
||||
}
|
||||
}
|
||||
1
packages/cli/test/fixtures/unit/commands/build/middleware/index.html
vendored
Normal file
1
packages/cli/test/fixtures/unit/commands/build/middleware/index.html
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<h1>Vercel</h1>
|
||||
1
packages/cli/test/fixtures/unit/commands/build/middleware/middleware.js
vendored
Normal file
1
packages/cli/test/fixtures/unit/commands/build/middleware/middleware.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export default req => new Response('middleware');
|
||||
7
packages/cli/test/fixtures/unit/commands/build/normalize-src/.vercel/project.json
vendored
Normal file
7
packages/cli/test/fixtures/unit/commands/build/normalize-src/.vercel/project.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"orgId": ".",
|
||||
"projectId": ".",
|
||||
"settings": {
|
||||
"framework": null
|
||||
}
|
||||
}
|
||||
1
packages/cli/test/fixtures/unit/commands/build/normalize-src/server.js
vendored
Normal file
1
packages/cli/test/fixtures/unit/commands/build/normalize-src/server.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = (req, res) => res.end('Vercel');
|
||||
15
packages/cli/test/fixtures/unit/commands/build/normalize-src/vercel.json
vendored
Normal file
15
packages/cli/test/fixtures/unit/commands/build/normalize-src/vercel.json
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"version": 2,
|
||||
"builds": [
|
||||
{
|
||||
"src": "./server.js",
|
||||
"use": "@vercel/node"
|
||||
}
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"src": "/(.*)",
|
||||
"dest": "/server.js"
|
||||
}
|
||||
]
|
||||
}
|
||||
4
packages/cli/test/fixtures/unit/commands/build/static-pull/.vercel/project.json
vendored
Normal file
4
packages/cli/test/fixtures/unit/commands/build/static-pull/.vercel/project.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"projectId": "vercel-pull-next",
|
||||
"orgId": "team_dummy"
|
||||
}
|
||||
1
packages/cli/test/fixtures/unit/commands/build/static-pull/index.html
vendored
Normal file
1
packages/cli/test/fixtures/unit/commands/build/static-pull/index.html
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<h1>Vercel</h1>
|
||||
1
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/HEAD
generated
vendored
Normal file
1
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/HEAD
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
ref: refs/heads/master
|
||||
7
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/config
generated
vendored
Normal file
7
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/config
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[core]
|
||||
repositoryformatversion = 0
|
||||
filemode = true
|
||||
bare = false
|
||||
logallrefupdates = true
|
||||
ignorecase = true
|
||||
precomposeunicode = true
|
||||
1
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/description
generated
vendored
Normal file
1
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/description
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Unnamed repository; edit this file 'description' to name the repository.
|
||||
15
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/applypatch-msg.sample
generated
vendored
Executable file
15
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/applypatch-msg.sample
generated
vendored
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# An example hook script to check the commit log message taken by
|
||||
# applypatch from an e-mail message.
|
||||
#
|
||||
# The hook should exit with non-zero status after issuing an
|
||||
# appropriate message if it wants to stop the commit. The hook is
|
||||
# allowed to edit the commit message file.
|
||||
#
|
||||
# To enable this hook, rename this file to "applypatch-msg".
|
||||
|
||||
. git-sh-setup
|
||||
commitmsg="$(git rev-parse --git-path hooks/commit-msg)"
|
||||
test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"}
|
||||
:
|
||||
24
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/commit-msg.sample
generated
vendored
Executable file
24
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/commit-msg.sample
generated
vendored
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# An example hook script to check the commit log message.
|
||||
# Called by "git commit" with one argument, the name of the file
|
||||
# that has the commit message. The hook should exit with non-zero
|
||||
# status after issuing an appropriate message if it wants to stop the
|
||||
# commit. The hook is allowed to edit the commit message file.
|
||||
#
|
||||
# To enable this hook, rename this file to "commit-msg".
|
||||
|
||||
# Uncomment the below to add a Signed-off-by line to the message.
|
||||
# Doing this in a hook is a bad idea in general, but the prepare-commit-msg
|
||||
# hook is more suited to it.
|
||||
#
|
||||
# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
|
||||
# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
|
||||
|
||||
# This example catches duplicate Signed-off-by lines.
|
||||
|
||||
test "" = "$(grep '^Signed-off-by: ' "$1" |
|
||||
sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
|
||||
echo >&2 Duplicate Signed-off-by lines.
|
||||
exit 1
|
||||
}
|
||||
173
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/fsmonitor-watchman.sample
generated
vendored
Executable file
173
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/fsmonitor-watchman.sample
generated
vendored
Executable file
@@ -0,0 +1,173 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use IPC::Open2;
|
||||
|
||||
# An example hook script to integrate Watchman
|
||||
# (https://facebook.github.io/watchman/) with git to speed up detecting
|
||||
# new and modified files.
|
||||
#
|
||||
# The hook is passed a version (currently 2) and last update token
|
||||
# formatted as a string and outputs to stdout a new update token and
|
||||
# all files that have been modified since the update token. Paths must
|
||||
# be relative to the root of the working tree and separated by a single NUL.
|
||||
#
|
||||
# To enable this hook, rename this file to "query-watchman" and set
|
||||
# 'git config core.fsmonitor .git/hooks/query-watchman'
|
||||
#
|
||||
my ($version, $last_update_token) = @ARGV;
|
||||
|
||||
# Uncomment for debugging
|
||||
# print STDERR "$0 $version $last_update_token\n";
|
||||
|
||||
# Check the hook interface version
|
||||
if ($version ne 2) {
|
||||
die "Unsupported query-fsmonitor hook version '$version'.\n" .
|
||||
"Falling back to scanning...\n";
|
||||
}
|
||||
|
||||
my $git_work_tree = get_working_dir();
|
||||
|
||||
my $retry = 1;
|
||||
|
||||
my $json_pkg;
|
||||
eval {
|
||||
require JSON::XS;
|
||||
$json_pkg = "JSON::XS";
|
||||
1;
|
||||
} or do {
|
||||
require JSON::PP;
|
||||
$json_pkg = "JSON::PP";
|
||||
};
|
||||
|
||||
launch_watchman();
|
||||
|
||||
sub launch_watchman {
|
||||
my $o = watchman_query();
|
||||
if (is_work_tree_watched($o)) {
|
||||
output_result($o->{clock}, @{$o->{files}});
|
||||
}
|
||||
}
|
||||
|
||||
sub output_result {
|
||||
my ($clockid, @files) = @_;
|
||||
|
||||
# Uncomment for debugging watchman output
|
||||
# open (my $fh, ">", ".git/watchman-output.out");
|
||||
# binmode $fh, ":utf8";
|
||||
# print $fh "$clockid\n@files\n";
|
||||
# close $fh;
|
||||
|
||||
binmode STDOUT, ":utf8";
|
||||
print $clockid;
|
||||
print "\0";
|
||||
local $, = "\0";
|
||||
print @files;
|
||||
}
|
||||
|
||||
sub watchman_clock {
|
||||
my $response = qx/watchman clock "$git_work_tree"/;
|
||||
die "Failed to get clock id on '$git_work_tree'.\n" .
|
||||
"Falling back to scanning...\n" if $? != 0;
|
||||
|
||||
return $json_pkg->new->utf8->decode($response);
|
||||
}
|
||||
|
||||
sub watchman_query {
|
||||
my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty')
|
||||
or die "open2() failed: $!\n" .
|
||||
"Falling back to scanning...\n";
|
||||
|
||||
# In the query expression below we're asking for names of files that
|
||||
# changed since $last_update_token but not from the .git folder.
|
||||
#
|
||||
# To accomplish this, we're using the "since" generator to use the
|
||||
# recency index to select candidate nodes and "fields" to limit the
|
||||
# output to file names only. Then we're using the "expression" term to
|
||||
# further constrain the results.
|
||||
if (substr($last_update_token, 0, 1) eq "c") {
|
||||
$last_update_token = "\"$last_update_token\"";
|
||||
}
|
||||
my $query = <<" END";
|
||||
["query", "$git_work_tree", {
|
||||
"since": $last_update_token,
|
||||
"fields": ["name"],
|
||||
"expression": ["not", ["dirname", ".git"]]
|
||||
}]
|
||||
END
|
||||
|
||||
# Uncomment for debugging the watchman query
|
||||
# open (my $fh, ">", ".git/watchman-query.json");
|
||||
# print $fh $query;
|
||||
# close $fh;
|
||||
|
||||
print CHLD_IN $query;
|
||||
close CHLD_IN;
|
||||
my $response = do {local $/; <CHLD_OUT>};
|
||||
|
||||
# Uncomment for debugging the watch response
|
||||
# open ($fh, ">", ".git/watchman-response.json");
|
||||
# print $fh $response;
|
||||
# close $fh;
|
||||
|
||||
die "Watchman: command returned no output.\n" .
|
||||
"Falling back to scanning...\n" if $response eq "";
|
||||
die "Watchman: command returned invalid output: $response\n" .
|
||||
"Falling back to scanning...\n" unless $response =~ /^\{/;
|
||||
|
||||
return $json_pkg->new->utf8->decode($response);
|
||||
}
|
||||
|
||||
sub is_work_tree_watched {
|
||||
my ($output) = @_;
|
||||
my $error = $output->{error};
|
||||
if ($retry > 0 and $error and $error =~ m/unable to resolve root .* directory (.*) is not watched/) {
|
||||
$retry--;
|
||||
my $response = qx/watchman watch "$git_work_tree"/;
|
||||
die "Failed to make watchman watch '$git_work_tree'.\n" .
|
||||
"Falling back to scanning...\n" if $? != 0;
|
||||
$output = $json_pkg->new->utf8->decode($response);
|
||||
$error = $output->{error};
|
||||
die "Watchman: $error.\n" .
|
||||
"Falling back to scanning...\n" if $error;
|
||||
|
||||
# Uncomment for debugging watchman output
|
||||
# open (my $fh, ">", ".git/watchman-output.out");
|
||||
# close $fh;
|
||||
|
||||
# Watchman will always return all files on the first query so
|
||||
# return the fast "everything is dirty" flag to git and do the
|
||||
# Watchman query just to get it over with now so we won't pay
|
||||
# the cost in git to look up each individual file.
|
||||
my $o = watchman_clock();
|
||||
$error = $output->{error};
|
||||
|
||||
die "Watchman: $error.\n" .
|
||||
"Falling back to scanning...\n" if $error;
|
||||
|
||||
output_result($o->{clock}, ("/"));
|
||||
$last_update_token = $o->{clock};
|
||||
|
||||
eval { launch_watchman() };
|
||||
return 0;
|
||||
}
|
||||
|
||||
die "Watchman: $error.\n" .
|
||||
"Falling back to scanning...\n" if $error;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub get_working_dir {
|
||||
my $working_dir;
|
||||
if ($^O =~ 'msys' || $^O =~ 'cygwin') {
|
||||
$working_dir = Win32::GetCwd();
|
||||
$working_dir =~ tr/\\/\//;
|
||||
} else {
|
||||
require Cwd;
|
||||
$working_dir = Cwd::cwd();
|
||||
}
|
||||
|
||||
return $working_dir;
|
||||
}
|
||||
8
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/post-update.sample
generated
vendored
Executable file
8
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/post-update.sample
generated
vendored
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# An example hook script to prepare a packed repository for use over
|
||||
# dumb transports.
|
||||
#
|
||||
# To enable this hook, rename this file to "post-update".
|
||||
|
||||
exec git update-server-info
|
||||
14
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/pre-applypatch.sample
generated
vendored
Executable file
14
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/pre-applypatch.sample
generated
vendored
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# An example hook script to verify what is about to be committed
|
||||
# by applypatch from an e-mail message.
|
||||
#
|
||||
# The hook should exit with non-zero status after issuing an
|
||||
# appropriate message if it wants to stop the commit.
|
||||
#
|
||||
# To enable this hook, rename this file to "pre-applypatch".
|
||||
|
||||
. git-sh-setup
|
||||
precommit="$(git rev-parse --git-path hooks/pre-commit)"
|
||||
test -x "$precommit" && exec "$precommit" ${1+"$@"}
|
||||
:
|
||||
49
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/pre-commit.sample
generated
vendored
Executable file
49
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/pre-commit.sample
generated
vendored
Executable file
@@ -0,0 +1,49 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# An example hook script to verify what is about to be committed.
|
||||
# Called by "git commit" with no arguments. The hook should
|
||||
# exit with non-zero status after issuing an appropriate message if
|
||||
# it wants to stop the commit.
|
||||
#
|
||||
# To enable this hook, rename this file to "pre-commit".
|
||||
|
||||
if git rev-parse --verify HEAD >/dev/null 2>&1
|
||||
then
|
||||
against=HEAD
|
||||
else
|
||||
# Initial commit: diff against an empty tree object
|
||||
against=$(git hash-object -t tree /dev/null)
|
||||
fi
|
||||
|
||||
# If you want to allow non-ASCII filenames set this variable to true.
|
||||
allownonascii=$(git config --type=bool hooks.allownonascii)
|
||||
|
||||
# Redirect output to stderr.
|
||||
exec 1>&2
|
||||
|
||||
# Cross platform projects tend to avoid non-ASCII filenames; prevent
|
||||
# them from being added to the repository. We exploit the fact that the
|
||||
# printable range starts at the space character and ends with tilde.
|
||||
if [ "$allownonascii" != "true" ] &&
|
||||
# Note that the use of brackets around a tr range is ok here, (it's
|
||||
# even required, for portability to Solaris 10's /usr/bin/tr), since
|
||||
# the square bracket bytes happen to fall in the designated range.
|
||||
test $(git diff --cached --name-only --diff-filter=A -z $against |
|
||||
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
|
||||
then
|
||||
cat <<\EOF
|
||||
Error: Attempt to add a non-ASCII file name.
|
||||
|
||||
This can cause problems if you want to work with people on other platforms.
|
||||
|
||||
To be portable it is advisable to rename the file.
|
||||
|
||||
If you know what you are doing you can disable this check using:
|
||||
|
||||
git config hooks.allownonascii true
|
||||
EOF
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# If there are whitespace errors, print the offending file names and fail.
|
||||
exec git diff-index --check --cached $against --
|
||||
13
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/pre-merge-commit.sample
generated
vendored
Executable file
13
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/pre-merge-commit.sample
generated
vendored
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# An example hook script to verify what is about to be committed.
|
||||
# Called by "git merge" with no arguments. The hook should
|
||||
# exit with non-zero status after issuing an appropriate message to
|
||||
# stderr if it wants to stop the merge commit.
|
||||
#
|
||||
# To enable this hook, rename this file to "pre-merge-commit".
|
||||
|
||||
. git-sh-setup
|
||||
test -x "$GIT_DIR/hooks/pre-commit" &&
|
||||
exec "$GIT_DIR/hooks/pre-commit"
|
||||
:
|
||||
53
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/pre-push.sample
generated
vendored
Executable file
53
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/pre-push.sample
generated
vendored
Executable file
@@ -0,0 +1,53 @@
|
||||
#!/bin/sh
|
||||
|
||||
# An example hook script to verify what is about to be pushed. Called by "git
|
||||
# push" after it has checked the remote status, but before anything has been
|
||||
# pushed. If this script exits with a non-zero status nothing will be pushed.
|
||||
#
|
||||
# This hook is called with the following parameters:
|
||||
#
|
||||
# $1 -- Name of the remote to which the push is being done
|
||||
# $2 -- URL to which the push is being done
|
||||
#
|
||||
# If pushing without using a named remote those arguments will be equal.
|
||||
#
|
||||
# Information about the commits which are being pushed is supplied as lines to
|
||||
# the standard input in the form:
|
||||
#
|
||||
# <local ref> <local oid> <remote ref> <remote oid>
|
||||
#
|
||||
# This sample shows how to prevent push of commits where the log message starts
|
||||
# with "WIP" (work in progress).
|
||||
|
||||
remote="$1"
|
||||
url="$2"
|
||||
|
||||
zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
|
||||
|
||||
while read local_ref local_oid remote_ref remote_oid
|
||||
do
|
||||
if test "$local_oid" = "$zero"
|
||||
then
|
||||
# Handle delete
|
||||
:
|
||||
else
|
||||
if test "$remote_oid" = "$zero"
|
||||
then
|
||||
# New branch, examine all commits
|
||||
range="$local_oid"
|
||||
else
|
||||
# Update to existing branch, examine new commits
|
||||
range="$remote_oid..$local_oid"
|
||||
fi
|
||||
|
||||
# Check for WIP commit
|
||||
commit=$(git rev-list -n 1 --grep '^WIP' "$range")
|
||||
if test -n "$commit"
|
||||
then
|
||||
echo >&2 "Found WIP commit in $local_ref, not pushing"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
exit 0
|
||||
169
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/pre-rebase.sample
generated
vendored
Executable file
169
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/pre-rebase.sample
generated
vendored
Executable file
@@ -0,0 +1,169 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2006, 2008 Junio C Hamano
|
||||
#
|
||||
# The "pre-rebase" hook is run just before "git rebase" starts doing
|
||||
# its job, and can prevent the command from running by exiting with
|
||||
# non-zero status.
|
||||
#
|
||||
# The hook is called with the following parameters:
|
||||
#
|
||||
# $1 -- the upstream the series was forked from.
|
||||
# $2 -- the branch being rebased (or empty when rebasing the current branch).
|
||||
#
|
||||
# This sample shows how to prevent topic branches that are already
|
||||
# merged to 'next' branch from getting rebased, because allowing it
|
||||
# would result in rebasing already published history.
|
||||
|
||||
publish=next
|
||||
basebranch="$1"
|
||||
if test "$#" = 2
|
||||
then
|
||||
topic="refs/heads/$2"
|
||||
else
|
||||
topic=`git symbolic-ref HEAD` ||
|
||||
exit 0 ;# we do not interrupt rebasing detached HEAD
|
||||
fi
|
||||
|
||||
case "$topic" in
|
||||
refs/heads/??/*)
|
||||
;;
|
||||
*)
|
||||
exit 0 ;# we do not interrupt others.
|
||||
;;
|
||||
esac
|
||||
|
||||
# Now we are dealing with a topic branch being rebased
|
||||
# on top of master. Is it OK to rebase it?
|
||||
|
||||
# Does the topic really exist?
|
||||
git show-ref -q "$topic" || {
|
||||
echo >&2 "No such branch $topic"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Is topic fully merged to master?
|
||||
not_in_master=`git rev-list --pretty=oneline ^master "$topic"`
|
||||
if test -z "$not_in_master"
|
||||
then
|
||||
echo >&2 "$topic is fully merged to master; better remove it."
|
||||
exit 1 ;# we could allow it, but there is no point.
|
||||
fi
|
||||
|
||||
# Is topic ever merged to next? If so you should not be rebasing it.
|
||||
only_next_1=`git rev-list ^master "^$topic" ${publish} | sort`
|
||||
only_next_2=`git rev-list ^master ${publish} | sort`
|
||||
if test "$only_next_1" = "$only_next_2"
|
||||
then
|
||||
not_in_topic=`git rev-list "^$topic" master`
|
||||
if test -z "$not_in_topic"
|
||||
then
|
||||
echo >&2 "$topic is already up to date with master"
|
||||
exit 1 ;# we could allow it, but there is no point.
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
else
|
||||
not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"`
|
||||
/usr/bin/perl -e '
|
||||
my $topic = $ARGV[0];
|
||||
my $msg = "* $topic has commits already merged to public branch:\n";
|
||||
my (%not_in_next) = map {
|
||||
/^([0-9a-f]+) /;
|
||||
($1 => 1);
|
||||
} split(/\n/, $ARGV[1]);
|
||||
for my $elem (map {
|
||||
/^([0-9a-f]+) (.*)$/;
|
||||
[$1 => $2];
|
||||
} split(/\n/, $ARGV[2])) {
|
||||
if (!exists $not_in_next{$elem->[0]}) {
|
||||
if ($msg) {
|
||||
print STDERR $msg;
|
||||
undef $msg;
|
||||
}
|
||||
print STDERR " $elem->[1]\n";
|
||||
}
|
||||
}
|
||||
' "$topic" "$not_in_next" "$not_in_master"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
<<\DOC_END
|
||||
|
||||
This sample hook safeguards topic branches that have been
|
||||
published from being rewound.
|
||||
|
||||
The workflow assumed here is:
|
||||
|
||||
* Once a topic branch forks from "master", "master" is never
|
||||
merged into it again (either directly or indirectly).
|
||||
|
||||
* Once a topic branch is fully cooked and merged into "master",
|
||||
it is deleted. If you need to build on top of it to correct
|
||||
earlier mistakes, a new topic branch is created by forking at
|
||||
the tip of the "master". This is not strictly necessary, but
|
||||
it makes it easier to keep your history simple.
|
||||
|
||||
* Whenever you need to test or publish your changes to topic
|
||||
branches, merge them into "next" branch.
|
||||
|
||||
The script, being an example, hardcodes the publish branch name
|
||||
to be "next", but it is trivial to make it configurable via
|
||||
$GIT_DIR/config mechanism.
|
||||
|
||||
With this workflow, you would want to know:
|
||||
|
||||
(1) ... if a topic branch has ever been merged to "next". Young
|
||||
topic branches can have stupid mistakes you would rather
|
||||
clean up before publishing, and things that have not been
|
||||
merged into other branches can be easily rebased without
|
||||
affecting other people. But once it is published, you would
|
||||
not want to rewind it.
|
||||
|
||||
(2) ... if a topic branch has been fully merged to "master".
|
||||
Then you can delete it. More importantly, you should not
|
||||
build on top of it -- other people may already want to
|
||||
change things related to the topic as patches against your
|
||||
"master", so if you need further changes, it is better to
|
||||
fork the topic (perhaps with the same name) afresh from the
|
||||
tip of "master".
|
||||
|
||||
Let's look at this example:
|
||||
|
||||
o---o---o---o---o---o---o---o---o---o "next"
|
||||
/ / / /
|
||||
/ a---a---b A / /
|
||||
/ / / /
|
||||
/ / c---c---c---c B /
|
||||
/ / / \ /
|
||||
/ / / b---b C \ /
|
||||
/ / / / \ /
|
||||
---o---o---o---o---o---o---o---o---o---o---o "master"
|
||||
|
||||
|
||||
A, B and C are topic branches.
|
||||
|
||||
* A has one fix since it was merged up to "next".
|
||||
|
||||
* B has finished. It has been fully merged up to "master" and "next",
|
||||
and is ready to be deleted.
|
||||
|
||||
* C has not merged to "next" at all.
|
||||
|
||||
We would want to allow C to be rebased, refuse A, and encourage
|
||||
B to be deleted.
|
||||
|
||||
To compute (1):
|
||||
|
||||
git rev-list ^master ^topic next
|
||||
git rev-list ^master next
|
||||
|
||||
if these match, topic has not merged in next at all.
|
||||
|
||||
To compute (2):
|
||||
|
||||
git rev-list master..topic
|
||||
|
||||
if this is empty, it is fully merged to "master".
|
||||
|
||||
DOC_END
|
||||
24
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/pre-receive.sample
generated
vendored
Executable file
24
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/pre-receive.sample
generated
vendored
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# An example hook script to make use of push options.
|
||||
# The example simply echoes all push options that start with 'echoback='
|
||||
# and rejects all pushes when the "reject" push option is used.
|
||||
#
|
||||
# To enable this hook, rename this file to "pre-receive".
|
||||
|
||||
if test -n "$GIT_PUSH_OPTION_COUNT"
|
||||
then
|
||||
i=0
|
||||
while test "$i" -lt "$GIT_PUSH_OPTION_COUNT"
|
||||
do
|
||||
eval "value=\$GIT_PUSH_OPTION_$i"
|
||||
case "$value" in
|
||||
echoback=*)
|
||||
echo "echo from the pre-receive-hook: ${value#*=}" >&2
|
||||
;;
|
||||
reject)
|
||||
exit 1
|
||||
esac
|
||||
i=$((i + 1))
|
||||
done
|
||||
fi
|
||||
42
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/prepare-commit-msg.sample
generated
vendored
Executable file
42
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/prepare-commit-msg.sample
generated
vendored
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# An example hook script to prepare the commit log message.
|
||||
# Called by "git commit" with the name of the file that has the
|
||||
# commit message, followed by the description of the commit
|
||||
# message's source. The hook's purpose is to edit the commit
|
||||
# message file. If the hook fails with a non-zero status,
|
||||
# the commit is aborted.
|
||||
#
|
||||
# To enable this hook, rename this file to "prepare-commit-msg".
|
||||
|
||||
# This hook includes three examples. The first one removes the
|
||||
# "# Please enter the commit message..." help message.
|
||||
#
|
||||
# The second includes the output of "git diff --name-status -r"
|
||||
# into the message, just before the "git status" output. It is
|
||||
# commented because it doesn't cope with --amend or with squashed
|
||||
# commits.
|
||||
#
|
||||
# The third example adds a Signed-off-by line to the message, that can
|
||||
# still be edited. This is rarely a good idea.
|
||||
|
||||
COMMIT_MSG_FILE=$1
|
||||
COMMIT_SOURCE=$2
|
||||
SHA1=$3
|
||||
|
||||
/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE"
|
||||
|
||||
# case "$COMMIT_SOURCE,$SHA1" in
|
||||
# ,|template,)
|
||||
# /usr/bin/perl -i.bak -pe '
|
||||
# print "\n" . `git diff --cached --name-status -r`
|
||||
# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;;
|
||||
# *) ;;
|
||||
# esac
|
||||
|
||||
# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
|
||||
# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE"
|
||||
# if test -z "$COMMIT_SOURCE"
|
||||
# then
|
||||
# /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE"
|
||||
# fi
|
||||
78
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/push-to-checkout.sample
generated
vendored
Executable file
78
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/push-to-checkout.sample
generated
vendored
Executable file
@@ -0,0 +1,78 @@
|
||||
#!/bin/sh
|
||||
|
||||
# An example hook script to update a checked-out tree on a git push.
|
||||
#
|
||||
# This hook is invoked by git-receive-pack(1) when it reacts to git
|
||||
# push and updates reference(s) in its repository, and when the push
|
||||
# tries to update the branch that is currently checked out and the
|
||||
# receive.denyCurrentBranch configuration variable is set to
|
||||
# updateInstead.
|
||||
#
|
||||
# By default, such a push is refused if the working tree and the index
|
||||
# of the remote repository has any difference from the currently
|
||||
# checked out commit; when both the working tree and the index match
|
||||
# the current commit, they are updated to match the newly pushed tip
|
||||
# of the branch. This hook is to be used to override the default
|
||||
# behaviour; however the code below reimplements the default behaviour
|
||||
# as a starting point for convenient modification.
|
||||
#
|
||||
# The hook receives the commit with which the tip of the current
|
||||
# branch is going to be updated:
|
||||
commit=$1
|
||||
|
||||
# It can exit with a non-zero status to refuse the push (when it does
|
||||
# so, it must not modify the index or the working tree).
|
||||
die () {
|
||||
echo >&2 "$*"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Or it can make any necessary changes to the working tree and to the
|
||||
# index to bring them to the desired state when the tip of the current
|
||||
# branch is updated to the new commit, and exit with a zero status.
|
||||
#
|
||||
# For example, the hook can simply run git read-tree -u -m HEAD "$1"
|
||||
# in order to emulate git fetch that is run in the reverse direction
|
||||
# with git push, as the two-tree form of git read-tree -u -m is
|
||||
# essentially the same as git switch or git checkout that switches
|
||||
# branches while keeping the local changes in the working tree that do
|
||||
# not interfere with the difference between the branches.
|
||||
|
||||
# The below is a more-or-less exact translation to shell of the C code
|
||||
# for the default behaviour for git's push-to-checkout hook defined in
|
||||
# the push_to_deploy() function in builtin/receive-pack.c.
|
||||
#
|
||||
# Note that the hook will be executed from the repository directory,
|
||||
# not from the working tree, so if you want to perform operations on
|
||||
# the working tree, you will have to adapt your code accordingly, e.g.
|
||||
# by adding "cd .." or using relative paths.
|
||||
|
||||
if ! git update-index -q --ignore-submodules --refresh
|
||||
then
|
||||
die "Up-to-date check failed"
|
||||
fi
|
||||
|
||||
if ! git diff-files --quiet --ignore-submodules --
|
||||
then
|
||||
die "Working directory has unstaged changes"
|
||||
fi
|
||||
|
||||
# This is a rough translation of:
|
||||
#
|
||||
# head_has_history() ? "HEAD" : EMPTY_TREE_SHA1_HEX
|
||||
if git cat-file -e HEAD 2>/dev/null
|
||||
then
|
||||
head=HEAD
|
||||
else
|
||||
head=$(git hash-object -t tree --stdin </dev/null)
|
||||
fi
|
||||
|
||||
if ! git diff-index --quiet --cached --ignore-submodules $head --
|
||||
then
|
||||
die "Working directory has staged changes"
|
||||
fi
|
||||
|
||||
if ! git read-tree -u -m "$commit"
|
||||
then
|
||||
die "Could not update working tree to new HEAD"
|
||||
fi
|
||||
128
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/update.sample
generated
vendored
Executable file
128
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/hooks/update.sample
generated
vendored
Executable file
@@ -0,0 +1,128 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# An example hook script to block unannotated tags from entering.
|
||||
# Called by "git receive-pack" with arguments: refname sha1-old sha1-new
|
||||
#
|
||||
# To enable this hook, rename this file to "update".
|
||||
#
|
||||
# Config
|
||||
# ------
|
||||
# hooks.allowunannotated
|
||||
# This boolean sets whether unannotated tags will be allowed into the
|
||||
# repository. By default they won't be.
|
||||
# hooks.allowdeletetag
|
||||
# This boolean sets whether deleting tags will be allowed in the
|
||||
# repository. By default they won't be.
|
||||
# hooks.allowmodifytag
|
||||
# This boolean sets whether a tag may be modified after creation. By default
|
||||
# it won't be.
|
||||
# hooks.allowdeletebranch
|
||||
# This boolean sets whether deleting branches will be allowed in the
|
||||
# repository. By default they won't be.
|
||||
# hooks.denycreatebranch
|
||||
# This boolean sets whether remotely creating branches will be denied
|
||||
# in the repository. By default this is allowed.
|
||||
#
|
||||
|
||||
# --- Command line
|
||||
refname="$1"
|
||||
oldrev="$2"
|
||||
newrev="$3"
|
||||
|
||||
# --- Safety check
|
||||
if [ -z "$GIT_DIR" ]; then
|
||||
echo "Don't run this script from the command line." >&2
|
||||
echo " (if you want, you could supply GIT_DIR then run" >&2
|
||||
echo " $0 <ref> <oldrev> <newrev>)" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then
|
||||
echo "usage: $0 <ref> <oldrev> <newrev>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# --- Config
|
||||
allowunannotated=$(git config --type=bool hooks.allowunannotated)
|
||||
allowdeletebranch=$(git config --type=bool hooks.allowdeletebranch)
|
||||
denycreatebranch=$(git config --type=bool hooks.denycreatebranch)
|
||||
allowdeletetag=$(git config --type=bool hooks.allowdeletetag)
|
||||
allowmodifytag=$(git config --type=bool hooks.allowmodifytag)
|
||||
|
||||
# check for no description
|
||||
projectdesc=$(sed -e '1q' "$GIT_DIR/description")
|
||||
case "$projectdesc" in
|
||||
"Unnamed repository"* | "")
|
||||
echo "*** Project description file hasn't been set" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# --- Check types
|
||||
# if $newrev is 0000...0000, it's a commit to delete a ref.
|
||||
zero=$(git hash-object --stdin </dev/null | tr '[0-9a-f]' '0')
|
||||
if [ "$newrev" = "$zero" ]; then
|
||||
newrev_type=delete
|
||||
else
|
||||
newrev_type=$(git cat-file -t $newrev)
|
||||
fi
|
||||
|
||||
case "$refname","$newrev_type" in
|
||||
refs/tags/*,commit)
|
||||
# un-annotated tag
|
||||
short_refname=${refname##refs/tags/}
|
||||
if [ "$allowunannotated" != "true" ]; then
|
||||
echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2
|
||||
echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
refs/tags/*,delete)
|
||||
# delete tag
|
||||
if [ "$allowdeletetag" != "true" ]; then
|
||||
echo "*** Deleting a tag is not allowed in this repository" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
refs/tags/*,tag)
|
||||
# annotated tag
|
||||
if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1
|
||||
then
|
||||
echo "*** Tag '$refname' already exists." >&2
|
||||
echo "*** Modifying a tag is not allowed in this repository." >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
refs/heads/*,commit)
|
||||
# branch
|
||||
if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then
|
||||
echo "*** Creating a branch is not allowed in this repository" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
refs/heads/*,delete)
|
||||
# delete branch
|
||||
if [ "$allowdeletebranch" != "true" ]; then
|
||||
echo "*** Deleting a branch is not allowed in this repository" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
refs/remotes/*,commit)
|
||||
# tracking branch
|
||||
;;
|
||||
refs/remotes/*,delete)
|
||||
# delete tracking branch
|
||||
if [ "$allowdeletebranch" != "true" ]; then
|
||||
echo "*** Deleting a tracking branch is not allowed in this repository" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
# Anything else (is there anything else?)
|
||||
echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# --- Finished
|
||||
exit 0
|
||||
6
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/info/exclude
generated
vendored
Normal file
6
packages/cli/test/fixtures/unit/create-git-meta/dirty/git/info/exclude
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
# git ls-files --others --exclude-from=.git/info/exclude
|
||||
# Lines that start with '#' are comments.
|
||||
# For a project mostly in C, the following would be a good set of
|
||||
# exclude patterns (uncomment them if you want to use them):
|
||||
# *.[oa]
|
||||
# *~
|
||||
1
packages/cli/test/fixtures/unit/create-git-meta/dirty/uncommitted.txt
vendored
Normal file
1
packages/cli/test/fixtures/unit/create-git-meta/dirty/uncommitted.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
hi
|
||||
11
packages/cli/test/fixtures/unit/create-git-meta/no-email/git/config
generated
vendored
Normal file
11
packages/cli/test/fixtures/unit/create-git-meta/no-email/git/config
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
[core]
|
||||
repositoryformatversion = 0
|
||||
fileMode = false
|
||||
bare = false
|
||||
logallrefupdates = true
|
||||
[user]
|
||||
name = TechBug2012
|
||||
email = <>
|
||||
[remote "origin"]
|
||||
url = https://github.com/MatthewStanciu/git-test
|
||||
fetch = +refs/heads/*:refs/remotes/origin/*
|
||||
7
packages/cli/test/fixtures/unit/create-git-meta/no-origin/git/config
generated
vendored
Normal file
7
packages/cli/test/fixtures/unit/create-git-meta/no-origin/git/config
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[core]
|
||||
repositoryformatversion = 0
|
||||
filemode = true
|
||||
bare = false
|
||||
logallrefupdates = true
|
||||
ignorecase = true
|
||||
precomposeunicode = true
|
||||
1
packages/cli/test/fixtures/unit/create-git-meta/not-dirty/committed.txt
vendored
Normal file
1
packages/cli/test/fixtures/unit/create-git-meta/not-dirty/committed.txt
vendored
Normal file
@@ -0,0 +1 @@
|
||||
hi
|
||||
1
packages/cli/test/fixtures/unit/create-git-meta/not-dirty/git/COMMIT_EDITMSG
generated
vendored
Normal file
1
packages/cli/test/fixtures/unit/create-git-meta/not-dirty/git/COMMIT_EDITMSG
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
add committed file
|
||||
1
packages/cli/test/fixtures/unit/create-git-meta/not-dirty/git/HEAD
generated
vendored
Normal file
1
packages/cli/test/fixtures/unit/create-git-meta/not-dirty/git/HEAD
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
ref: refs/heads/master
|
||||
7
packages/cli/test/fixtures/unit/create-git-meta/not-dirty/git/config
generated
vendored
Normal file
7
packages/cli/test/fixtures/unit/create-git-meta/not-dirty/git/config
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
[core]
|
||||
repositoryformatversion = 0
|
||||
filemode = true
|
||||
bare = false
|
||||
logallrefupdates = true
|
||||
ignorecase = true
|
||||
precomposeunicode = true
|
||||
1
packages/cli/test/fixtures/unit/create-git-meta/not-dirty/git/description
generated
vendored
Normal file
1
packages/cli/test/fixtures/unit/create-git-meta/not-dirty/git/description
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Unnamed repository; edit this file 'description' to name the repository.
|
||||
15
packages/cli/test/fixtures/unit/create-git-meta/not-dirty/git/hooks/applypatch-msg.sample
generated
vendored
Executable file
15
packages/cli/test/fixtures/unit/create-git-meta/not-dirty/git/hooks/applypatch-msg.sample
generated
vendored
Executable file
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# An example hook script to check the commit log message taken by
|
||||
# applypatch from an e-mail message.
|
||||
#
|
||||
# The hook should exit with non-zero status after issuing an
|
||||
# appropriate message if it wants to stop the commit. The hook is
|
||||
# allowed to edit the commit message file.
|
||||
#
|
||||
# To enable this hook, rename this file to "applypatch-msg".
|
||||
|
||||
. git-sh-setup
|
||||
commitmsg="$(git rev-parse --git-path hooks/commit-msg)"
|
||||
test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"}
|
||||
:
|
||||
24
packages/cli/test/fixtures/unit/create-git-meta/not-dirty/git/hooks/commit-msg.sample
generated
vendored
Executable file
24
packages/cli/test/fixtures/unit/create-git-meta/not-dirty/git/hooks/commit-msg.sample
generated
vendored
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# An example hook script to check the commit log message.
|
||||
# Called by "git commit" with one argument, the name of the file
|
||||
# that has the commit message. The hook should exit with non-zero
|
||||
# status after issuing an appropriate message if it wants to stop the
|
||||
# commit. The hook is allowed to edit the commit message file.
|
||||
#
|
||||
# To enable this hook, rename this file to "commit-msg".
|
||||
|
||||
# Uncomment the below to add a Signed-off-by line to the message.
|
||||
# Doing this in a hook is a bad idea in general, but the prepare-commit-msg
|
||||
# hook is more suited to it.
|
||||
#
|
||||
# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
|
||||
# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1"
|
||||
|
||||
# This example catches duplicate Signed-off-by lines.
|
||||
|
||||
test "" = "$(grep '^Signed-off-by: ' "$1" |
|
||||
sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || {
|
||||
echo >&2 Duplicate Signed-off-by lines.
|
||||
exit 1
|
||||
}
|
||||
173
packages/cli/test/fixtures/unit/create-git-meta/not-dirty/git/hooks/fsmonitor-watchman.sample
generated
vendored
Executable file
173
packages/cli/test/fixtures/unit/create-git-meta/not-dirty/git/hooks/fsmonitor-watchman.sample
generated
vendored
Executable file
@@ -0,0 +1,173 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use IPC::Open2;
|
||||
|
||||
# An example hook script to integrate Watchman
|
||||
# (https://facebook.github.io/watchman/) with git to speed up detecting
|
||||
# new and modified files.
|
||||
#
|
||||
# The hook is passed a version (currently 2) and last update token
|
||||
# formatted as a string and outputs to stdout a new update token and
|
||||
# all files that have been modified since the update token. Paths must
|
||||
# be relative to the root of the working tree and separated by a single NUL.
|
||||
#
|
||||
# To enable this hook, rename this file to "query-watchman" and set
|
||||
# 'git config core.fsmonitor .git/hooks/query-watchman'
|
||||
#
|
||||
my ($version, $last_update_token) = @ARGV;
|
||||
|
||||
# Uncomment for debugging
|
||||
# print STDERR "$0 $version $last_update_token\n";
|
||||
|
||||
# Check the hook interface version
|
||||
if ($version ne 2) {
|
||||
die "Unsupported query-fsmonitor hook version '$version'.\n" .
|
||||
"Falling back to scanning...\n";
|
||||
}
|
||||
|
||||
my $git_work_tree = get_working_dir();
|
||||
|
||||
my $retry = 1;
|
||||
|
||||
my $json_pkg;
|
||||
eval {
|
||||
require JSON::XS;
|
||||
$json_pkg = "JSON::XS";
|
||||
1;
|
||||
} or do {
|
||||
require JSON::PP;
|
||||
$json_pkg = "JSON::PP";
|
||||
};
|
||||
|
||||
launch_watchman();
|
||||
|
||||
sub launch_watchman {
|
||||
my $o = watchman_query();
|
||||
if (is_work_tree_watched($o)) {
|
||||
output_result($o->{clock}, @{$o->{files}});
|
||||
}
|
||||
}
|
||||
|
||||
sub output_result {
|
||||
my ($clockid, @files) = @_;
|
||||
|
||||
# Uncomment for debugging watchman output
|
||||
# open (my $fh, ">", ".git/watchman-output.out");
|
||||
# binmode $fh, ":utf8";
|
||||
# print $fh "$clockid\n@files\n";
|
||||
# close $fh;
|
||||
|
||||
binmode STDOUT, ":utf8";
|
||||
print $clockid;
|
||||
print "\0";
|
||||
local $, = "\0";
|
||||
print @files;
|
||||
}
|
||||
|
||||
sub watchman_clock {
|
||||
my $response = qx/watchman clock "$git_work_tree"/;
|
||||
die "Failed to get clock id on '$git_work_tree'.\n" .
|
||||
"Falling back to scanning...\n" if $? != 0;
|
||||
|
||||
return $json_pkg->new->utf8->decode($response);
|
||||
}
|
||||
|
||||
sub watchman_query {
|
||||
my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty')
|
||||
or die "open2() failed: $!\n" .
|
||||
"Falling back to scanning...\n";
|
||||
|
||||
# In the query expression below we're asking for names of files that
|
||||
# changed since $last_update_token but not from the .git folder.
|
||||
#
|
||||
# To accomplish this, we're using the "since" generator to use the
|
||||
# recency index to select candidate nodes and "fields" to limit the
|
||||
# output to file names only. Then we're using the "expression" term to
|
||||
# further constrain the results.
|
||||
if (substr($last_update_token, 0, 1) eq "c") {
|
||||
$last_update_token = "\"$last_update_token\"";
|
||||
}
|
||||
my $query = <<" END";
|
||||
["query", "$git_work_tree", {
|
||||
"since": $last_update_token,
|
||||
"fields": ["name"],
|
||||
"expression": ["not", ["dirname", ".git"]]
|
||||
}]
|
||||
END
|
||||
|
||||
# Uncomment for debugging the watchman query
|
||||
# open (my $fh, ">", ".git/watchman-query.json");
|
||||
# print $fh $query;
|
||||
# close $fh;
|
||||
|
||||
print CHLD_IN $query;
|
||||
close CHLD_IN;
|
||||
my $response = do {local $/; <CHLD_OUT>};
|
||||
|
||||
# Uncomment for debugging the watch response
|
||||
# open ($fh, ">", ".git/watchman-response.json");
|
||||
# print $fh $response;
|
||||
# close $fh;
|
||||
|
||||
die "Watchman: command returned no output.\n" .
|
||||
"Falling back to scanning...\n" if $response eq "";
|
||||
die "Watchman: command returned invalid output: $response\n" .
|
||||
"Falling back to scanning...\n" unless $response =~ /^\{/;
|
||||
|
||||
return $json_pkg->new->utf8->decode($response);
|
||||
}
|
||||
|
||||
sub is_work_tree_watched {
|
||||
my ($output) = @_;
|
||||
my $error = $output->{error};
|
||||
if ($retry > 0 and $error and $error =~ m/unable to resolve root .* directory (.*) is not watched/) {
|
||||
$retry--;
|
||||
my $response = qx/watchman watch "$git_work_tree"/;
|
||||
die "Failed to make watchman watch '$git_work_tree'.\n" .
|
||||
"Falling back to scanning...\n" if $? != 0;
|
||||
$output = $json_pkg->new->utf8->decode($response);
|
||||
$error = $output->{error};
|
||||
die "Watchman: $error.\n" .
|
||||
"Falling back to scanning...\n" if $error;
|
||||
|
||||
# Uncomment for debugging watchman output
|
||||
# open (my $fh, ">", ".git/watchman-output.out");
|
||||
# close $fh;
|
||||
|
||||
# Watchman will always return all files on the first query so
|
||||
# return the fast "everything is dirty" flag to git and do the
|
||||
# Watchman query just to get it over with now so we won't pay
|
||||
# the cost in git to look up each individual file.
|
||||
my $o = watchman_clock();
|
||||
$error = $output->{error};
|
||||
|
||||
die "Watchman: $error.\n" .
|
||||
"Falling back to scanning...\n" if $error;
|
||||
|
||||
output_result($o->{clock}, ("/"));
|
||||
$last_update_token = $o->{clock};
|
||||
|
||||
eval { launch_watchman() };
|
||||
return 0;
|
||||
}
|
||||
|
||||
die "Watchman: $error.\n" .
|
||||
"Falling back to scanning...\n" if $error;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub get_working_dir {
|
||||
my $working_dir;
|
||||
if ($^O =~ 'msys' || $^O =~ 'cygwin') {
|
||||
$working_dir = Win32::GetCwd();
|
||||
$working_dir =~ tr/\\/\//;
|
||||
} else {
|
||||
require Cwd;
|
||||
$working_dir = Cwd::cwd();
|
||||
}
|
||||
|
||||
return $working_dir;
|
||||
}
|
||||
8
packages/cli/test/fixtures/unit/create-git-meta/not-dirty/git/hooks/post-update.sample
generated
vendored
Executable file
8
packages/cli/test/fixtures/unit/create-git-meta/not-dirty/git/hooks/post-update.sample
generated
vendored
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# An example hook script to prepare a packed repository for use over
|
||||
# dumb transports.
|
||||
#
|
||||
# To enable this hook, rename this file to "post-update".
|
||||
|
||||
exec git update-server-info
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user