mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-11 21:07:47 +00:00
Compare commits
82 Commits
@vercel/py
...
@vercel/py
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
547e88228e | ||
|
|
9bfb5dd535 | ||
|
|
81ea84fae8 | ||
|
|
fa8bf07be4 | ||
|
|
cc9dce73ad | ||
|
|
bba7cbd411 | ||
|
|
9a3739bebd | ||
|
|
8c62de16ce | ||
|
|
e9333988d7 | ||
|
|
fb001ce7eb | ||
|
|
b399fe7037 | ||
|
|
88385b3c84 | ||
|
|
eed39913e1 | ||
|
|
03e9047bc9 | ||
|
|
0e35205bf1 | ||
|
|
e42fe34c4a | ||
|
|
3ece7ac969 | ||
|
|
4f832acf90 | ||
|
|
918726e01d | ||
|
|
dc2ddf867b | ||
|
|
ee1211416f | ||
|
|
570fd24e29 | ||
|
|
40681ad0f4 | ||
|
|
f20703b15d | ||
|
|
68eb197112 | ||
|
|
b8b87b96da | ||
|
|
967c24f1bb | ||
|
|
609f781234 | ||
|
|
998f6bf6e6 | ||
|
|
7511c2ef85 | ||
|
|
71425fac1f | ||
|
|
6973cd5989 | ||
|
|
24785ff50a | ||
|
|
aa3ad4478c | ||
|
|
f0d73049ca | ||
|
|
6cef07354a | ||
|
|
50af9f5b75 | ||
|
|
af76b134d8 | ||
|
|
c7640005fd | ||
|
|
3deed977ba | ||
|
|
b38c360e36 | ||
|
|
1595e48414 | ||
|
|
e6b0ee3e3c | ||
|
|
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 | ||
|
|
0c7b54edad | ||
|
|
6d42816395 | ||
|
|
6fe6d05a42 | ||
|
|
50a201f145 | ||
|
|
701a02ae9d |
4
.gitattributes
vendored
4
.gitattributes
vendored
@@ -8,3 +8,7 @@ packages/*/test/* linguist-vendored
|
|||||||
# Go build fails with Windows line endings.
|
# Go build fails with Windows line endings.
|
||||||
*.go text eol=lf
|
*.go text eol=lf
|
||||||
go.mod text eol=lf
|
go.mod text eol=lf
|
||||||
|
|
||||||
|
# Mark certain files as "binary" -- hide diffs
|
||||||
|
**/test/fixtures/**/git/**/* binary
|
||||||
|
**/test/fixtures/**/git/**/* linguist-generated
|
||||||
|
|||||||
4
.prettierignore
Normal file
4
.prettierignore
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
# https://prettier.io/docs/en/ignore.html
|
||||||
|
|
||||||
|
# ignore this file with an intentional syntax error
|
||||||
|
packages/cli/test/dev/fixtures/edge-function-error/api/edge-error-syntax.js
|
||||||
@@ -1,18 +1 @@
|
|||||||
*
|
packages/*/test/**
|
||||||
|
|
||||||
# general
|
|
||||||
!utils/
|
|
||||||
!utils/run.js
|
|
||||||
!.yarnrc
|
|
||||||
!yarn.lock
|
|
||||||
!package.json
|
|
||||||
!turbo.json
|
|
||||||
|
|
||||||
# api
|
|
||||||
!api/
|
|
||||||
!api/**
|
|
||||||
|
|
||||||
# packages
|
|
||||||
!packages/
|
|
||||||
!packages/frameworks
|
|
||||||
!packages/frameworks/**
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import fs from 'fs/promises';
|
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 { getExampleList } from '../examples/example-list';
|
||||||
import { mapOldToNew } from '../examples/map-old-to-new';
|
import { mapOldToNew } from '../examples/map-old-to-new';
|
||||||
|
|
||||||
@@ -40,7 +41,32 @@ async function main() {
|
|||||||
JSON.stringify([...existingExamples, ...oldExamples])
|
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.');
|
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,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@testing-library/jest-dom": "^5.16.1",
|
"@testing-library/jest-dom": "^5.16.4",
|
||||||
"@testing-library/react": "^12.1.2",
|
"@testing-library/react": "^13.3.0",
|
||||||
"@testing-library/user-event": "^13.5.0",
|
"@testing-library/user-event": "^14.2.0",
|
||||||
"react": "^17.0.2",
|
"react": "^18.1.0",
|
||||||
"react-dom": "^17.0.2",
|
"react-dom": "^18.1.0",
|
||||||
"react-scripts": "5.0.0",
|
"react-scripts": "5.0.1",
|
||||||
"web-vitals": "^2.1.3"
|
"web-vitals": "^2.1.4"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "react-scripts start",
|
"start": "react-scripts start",
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import ReactDOM from 'react-dom';
|
|||||||
import './index.css';
|
import './index.css';
|
||||||
import App from './App';
|
import App from './App';
|
||||||
import reportWebVitals from './reportWebVitals';
|
import reportWebVitals from './reportWebVitals';
|
||||||
|
import { sendToVercelAnalytics } from './vitals';
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<React.StrictMode>
|
<React.StrictMode>
|
||||||
@@ -11,7 +12,4 @@ ReactDOM.render(
|
|||||||
document.getElementById('root')
|
document.getElementById('root')
|
||||||
);
|
);
|
||||||
|
|
||||||
// If you want to start measuring performance in your app, pass a function
|
reportWebVitals(sendToVercelAnalytics);
|
||||||
// to log results (for example: reportWebVitals(console.log))
|
|
||||||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
|
||||||
reportWebVitals();
|
|
||||||
|
|||||||
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"
|
"@svgr/plugin-svgo" "^5.5.0"
|
||||||
loader-utils "^2.0.0"
|
loader-utils "^2.0.0"
|
||||||
|
|
||||||
"@testing-library/dom@^8.0.0":
|
"@testing-library/dom@^8.5.0":
|
||||||
version "8.11.2"
|
version "8.13.0"
|
||||||
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-8.11.2.tgz#fc110c665a066c2287be765e4a35ba8dad737015"
|
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-8.13.0.tgz#bc00bdd64c7d8b40841e27a70211399ad3af46f5"
|
||||||
integrity sha512-idsS/cqbYudXcVWngc1PuWNmXs416oBy2g/7Q8QAUREt5Z3MUkAL2XJD7xazLJ6esDfqRDi/ZBxk+OPPXitHRw==
|
integrity sha512-9VHgfIatKNXQNaZTtLnalIy0jNZzY35a4S3oi08YAt9Hv1VsfZ/DfA45lM8D/UhtHBGJ4/lGwp0PZkVndRkoOQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@babel/code-frame" "^7.10.4"
|
"@babel/code-frame" "^7.10.4"
|
||||||
"@babel/runtime" "^7.12.5"
|
"@babel/runtime" "^7.12.5"
|
||||||
@@ -1498,10 +1498,10 @@
|
|||||||
lz-string "^1.4.4"
|
lz-string "^1.4.4"
|
||||||
pretty-format "^27.0.2"
|
pretty-format "^27.0.2"
|
||||||
|
|
||||||
"@testing-library/jest-dom@^5.16.1":
|
"@testing-library/jest-dom@^5.16.4":
|
||||||
version "5.16.1"
|
version "5.16.4"
|
||||||
resolved "https://registry.yarnpkg.com/@testing-library/jest-dom/-/jest-dom-5.16.1.tgz#3db7df5ae97596264a7da9696fe14695ba02e51f"
|
resolved "https://registry.yarnpkg.com/@testing-library/jest-dom/-/jest-dom-5.16.4.tgz#938302d7b8b483963a3ae821f1c0808f872245cd"
|
||||||
integrity sha512-ajUJdfDIuTCadB79ukO+0l8O+QwN0LiSxDaYUTI4LndbbUsGi6rWU1SCexXzBA2NSjlVB9/vbkasQIL3tmPBjw==
|
integrity sha512-Gy+IoFutbMQcky0k+bqqumXZ1cTGswLsFqmNLzNdSKkU9KGV2u9oXhukCbbJ9/LRPKiqwxEE8VpV/+YZlfkPUA==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@babel/runtime" "^7.9.2"
|
"@babel/runtime" "^7.9.2"
|
||||||
"@types/testing-library__jest-dom" "^5.9.1"
|
"@types/testing-library__jest-dom" "^5.9.1"
|
||||||
@@ -1513,20 +1513,19 @@
|
|||||||
lodash "^4.17.15"
|
lodash "^4.17.15"
|
||||||
redent "^3.0.0"
|
redent "^3.0.0"
|
||||||
|
|
||||||
"@testing-library/react@^12.1.2":
|
"@testing-library/react@^13.3.0":
|
||||||
version "12.1.2"
|
version "13.3.0"
|
||||||
resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-12.1.2.tgz#f1bc9a45943461fa2a598bb4597df1ae044cfc76"
|
resolved "https://registry.yarnpkg.com/@testing-library/react/-/react-13.3.0.tgz#bf298bfbc5589326bbcc8052b211f3bb097a97c5"
|
||||||
integrity sha512-ihQiEOklNyHIpo2Y8FREkyD1QAea054U0MVbwH1m8N9TxeFz+KoJ9LkqoKqJlzx2JDm56DVwaJ1r36JYxZM05g==
|
integrity sha512-DB79aA426+deFgGSjnf5grczDPiL4taK3hFaa+M5q7q20Kcve9eQottOG5kZ74KEr55v0tU2CQormSSDK87zYQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@babel/runtime" "^7.12.5"
|
"@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":
|
"@testing-library/user-event@^14.2.0":
|
||||||
version "13.5.0"
|
version "14.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/@testing-library/user-event/-/user-event-13.5.0.tgz#69d77007f1e124d55314a2b73fd204b333b13295"
|
resolved "https://registry.yarnpkg.com/@testing-library/user-event/-/user-event-14.2.0.tgz#8293560f8f80a00383d6c755ec3e0b918acb1683"
|
||||||
integrity sha512-5Kwtbo3Y/NowpkbRuSepbyMFkZmHgD+vPzYB/RJ4oxt5Gj/avFFBYjhw27cqSVPVw/3a67NK1PbiIr9k4Gwmdg==
|
integrity sha512-+hIlG4nJS6ivZrKnOP7OGsDu9Fxmryj9vCl8x0ZINtTJcCHs2zLsYif5GzuRiBF2ck5GZG2aQr7Msg+EHlnYVQ==
|
||||||
dependencies:
|
|
||||||
"@babel/runtime" "^7.12.5"
|
|
||||||
|
|
||||||
"@tootallnate/once@1":
|
"@tootallnate/once@1":
|
||||||
version "1.1.2"
|
version "1.1.2"
|
||||||
@@ -1735,6 +1734,11 @@
|
|||||||
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.4.3.tgz#a3c65525b91fca7da00ab1a3ac2b5a2a4afbffbf"
|
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.4.3.tgz#a3c65525b91fca7da00ab1a3ac2b5a2a4afbffbf"
|
||||||
integrity sha512-QzSuZMBuG5u8HqYz01qtMdg/Jfctlnvj1z/lYnIDXs/golxw0fxtRAHd9KrzjR7Yxz1qVeI00o0kiO3PmVdJ9w==
|
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":
|
"@types/q@^1.5.1":
|
||||||
version "1.5.5"
|
version "1.5.5"
|
||||||
resolved "https://registry.yarnpkg.com/@types/q/-/q-1.5.5.tgz#75a2a8e7d8ab4b230414505d92335d1dcb53a6df"
|
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"
|
resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.4.tgz#cd667bcfdd025213aafb7ca5915a932590acdcdc"
|
||||||
integrity sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==
|
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":
|
"@types/resolve@1.17.1":
|
||||||
version "1.17.1"
|
version "1.17.1"
|
||||||
resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.17.1.tgz#3afd6ad8967c77e4376c598a82ddd58f46ec45d6"
|
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"
|
resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.1.tgz#d8f1c0d0dc23afad6dc16a9e993a0865774b4065"
|
||||||
integrity sha512-xoDlM2S4ortawSWORYqsdU+2rxdh4LRW9ytc3zmT37RIKQh6IHyKwwtKhKis9ah8ol07DCkZxPt8BBvPjC6v4g==
|
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":
|
"@types/serve-index@^1.9.1":
|
||||||
version "1.9.1"
|
version "1.9.1"
|
||||||
resolved "https://registry.yarnpkg.com/@types/serve-index/-/serve-index-1.9.1.tgz#1b5e85370a192c01ec6cec4735cf2917337a6278"
|
resolved "https://registry.yarnpkg.com/@types/serve-index/-/serve-index-1.9.1.tgz#1b5e85370a192c01ec6cec4735cf2917337a6278"
|
||||||
@@ -3175,6 +3200,11 @@ cssstyle@^2.3.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
cssom "~0.3.6"
|
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:
|
damerau-levenshtein@^1.0.7:
|
||||||
version "1.0.8"
|
version "1.0.8"
|
||||||
resolved "https://registry.yarnpkg.com/damerau-levenshtein/-/damerau-levenshtein-1.0.8.tgz#b43d286ccbd36bc5b2f7ed41caf2d0aba1f8a6e7"
|
resolved "https://registry.yarnpkg.com/damerau-levenshtein/-/damerau-levenshtein-1.0.8.tgz#b43d286ccbd36bc5b2f7ed41caf2d0aba1f8a6e7"
|
||||||
@@ -3622,10 +3652,10 @@ escodegen@^2.0.0:
|
|||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
source-map "~0.6.1"
|
source-map "~0.6.1"
|
||||||
|
|
||||||
eslint-config-react-app@^7.0.0:
|
eslint-config-react-app@^7.0.1:
|
||||||
version "7.0.0"
|
version "7.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/eslint-config-react-app/-/eslint-config-react-app-7.0.0.tgz#0fa96d5ec1dfb99c029b1554362ab3fa1c3757df"
|
resolved "https://registry.yarnpkg.com/eslint-config-react-app/-/eslint-config-react-app-7.0.1.tgz#73ba3929978001c5c86274c017ea57eb5fa644b4"
|
||||||
integrity sha512-xyymoxtIt1EOsSaGag+/jmcywRuieQoA2JbPCjnw9HukFj9/97aGPoZVFioaotzk1K5Qt9sHO5EutZbkrAXS0g==
|
integrity sha512-K6rNzvkIeHaTd8m/QEh1Zko0KI7BACWkkneSs6s9cKZC/J27X3eZR6Upt1jkmZ/4FK+XUOPPxMEN7+lbUXfSlA==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@babel/core" "^7.16.0"
|
"@babel/core" "^7.16.0"
|
||||||
"@babel/eslint-parser" "^7.16.3"
|
"@babel/eslint-parser" "^7.16.3"
|
||||||
@@ -6841,10 +6871,10 @@ react-app-polyfill@^3.0.0:
|
|||||||
regenerator-runtime "^0.13.9"
|
regenerator-runtime "^0.13.9"
|
||||||
whatwg-fetch "^3.6.2"
|
whatwg-fetch "^3.6.2"
|
||||||
|
|
||||||
react-dev-utils@^12.0.0:
|
react-dev-utils@^12.0.1:
|
||||||
version "12.0.0"
|
version "12.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/react-dev-utils/-/react-dev-utils-12.0.0.tgz#4eab12cdb95692a077616770b5988f0adf806526"
|
resolved "https://registry.yarnpkg.com/react-dev-utils/-/react-dev-utils-12.0.1.tgz#ba92edb4a1f379bd46ccd6bcd4e7bc398df33e73"
|
||||||
integrity sha512-xBQkitdxozPxt1YZ9O1097EJiVpwHr9FoAuEVURCKV0Av8NBERovJauzP7bo1ThvuhZ4shsQ1AJiu4vQpoT1AQ==
|
integrity sha512-84Ivxmr17KjUupyqzFode6xKhjwuEJDROWKJy/BthkL7Wn6NJ8h4WE6k/exAv6ImS+0oZLRRW5j/aINMHyeGeQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@babel/code-frame" "^7.16.0"
|
"@babel/code-frame" "^7.16.0"
|
||||||
address "^1.1.2"
|
address "^1.1.2"
|
||||||
@@ -6865,25 +6895,24 @@ react-dev-utils@^12.0.0:
|
|||||||
open "^8.4.0"
|
open "^8.4.0"
|
||||||
pkg-up "^3.1.0"
|
pkg-up "^3.1.0"
|
||||||
prompts "^2.4.2"
|
prompts "^2.4.2"
|
||||||
react-error-overlay "^6.0.10"
|
react-error-overlay "^6.0.11"
|
||||||
recursive-readdir "^2.2.2"
|
recursive-readdir "^2.2.2"
|
||||||
shell-quote "^1.7.3"
|
shell-quote "^1.7.3"
|
||||||
strip-ansi "^6.0.1"
|
strip-ansi "^6.0.1"
|
||||||
text-table "^0.2.0"
|
text-table "^0.2.0"
|
||||||
|
|
||||||
react-dom@^17.0.2:
|
react-dom@^18.1.0:
|
||||||
version "17.0.2"
|
version "18.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.2.tgz#ecffb6845e3ad8dbfcdc498f0d0a939736502c23"
|
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.1.0.tgz#7f6dd84b706408adde05e1df575b3a024d7e8a2f"
|
||||||
integrity sha512-s4h96KtLDUQlsENhMn1ar8t2bEa+q/YAtj8pPPdIjPDGBDIVNsrD9aXNWqspUe6AzKCIG0C1HZZLqLV7qpOBGA==
|
integrity sha512-fU1Txz7Budmvamp7bshe4Zi32d0ll7ect+ccxNu9FlObT605GOEB8BfO4tmRJ39R5Zj831VCpvQ05QPBW5yb+w==
|
||||||
dependencies:
|
dependencies:
|
||||||
loose-envify "^1.1.0"
|
loose-envify "^1.1.0"
|
||||||
object-assign "^4.1.1"
|
scheduler "^0.22.0"
|
||||||
scheduler "^0.20.2"
|
|
||||||
|
|
||||||
react-error-overlay@^6.0.10:
|
react-error-overlay@^6.0.11:
|
||||||
version "6.0.10"
|
version "6.0.11"
|
||||||
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.10.tgz#0fe26db4fa85d9dbb8624729580e90e7159a59a6"
|
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.11.tgz#92835de5841c5cf08ba00ddd2d677b6d17ff9adb"
|
||||||
integrity sha512-mKR90fX7Pm5seCOfz8q9F+66VCc1PGsWSBxKbITjfKVQHMNF2zudxHnMdJiB1fRCb+XsbQV9sO9DCkgsMQgBIA==
|
integrity sha512-/6UZ2qgEyH2aqzYZgQPxEnz33NJ2gNsnHA2o5+o4wW9bLM/JYQitNP9xPhsXwC08hMMovfGe/8retsdDsczPRg==
|
||||||
|
|
||||||
react-is@^16.13.1:
|
react-is@^16.13.1:
|
||||||
version "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"
|
resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.11.0.tgz#77198b944733f0f1f1a90e791de4541f9f074046"
|
||||||
integrity sha512-F27qZr8uUqwhWZboondsPx8tnC3Ct3SxZA3V5WyEvujRyyNv0VYPhoBg1gZ8/MV5tubQp76Trw8lTv9hzRBa+A==
|
integrity sha512-F27qZr8uUqwhWZboondsPx8tnC3Ct3SxZA3V5WyEvujRyyNv0VYPhoBg1gZ8/MV5tubQp76Trw8lTv9hzRBa+A==
|
||||||
|
|
||||||
react-scripts@5.0.0:
|
react-scripts@5.0.1:
|
||||||
version "5.0.0"
|
version "5.0.1"
|
||||||
resolved "https://registry.yarnpkg.com/react-scripts/-/react-scripts-5.0.0.tgz#6547a6d7f8b64364ef95273767466cc577cb4b60"
|
resolved "https://registry.yarnpkg.com/react-scripts/-/react-scripts-5.0.1.tgz#6285dbd65a8ba6e49ca8d651ce30645a6d980003"
|
||||||
integrity sha512-3i0L2CyIlROz7mxETEdfif6Sfhh9Lfpzi10CtcGs1emDQStmZfWjJbAIMtRD0opVUjQuFWqHZyRZ9PPzKCFxWg==
|
integrity sha512-8VAmEm/ZAwQzJ+GOMLbBsTdDKOpuZh7RPs0UymvBR2vRk4iZWCskjbFnxqjrzoIvlNNRZ3QJFx6/qDSi6zSnaQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@babel/core" "^7.16.0"
|
"@babel/core" "^7.16.0"
|
||||||
"@pmmmwh/react-refresh-webpack-plugin" "^0.5.3"
|
"@pmmmwh/react-refresh-webpack-plugin" "^0.5.3"
|
||||||
@@ -6921,7 +6950,7 @@ react-scripts@5.0.0:
|
|||||||
dotenv "^10.0.0"
|
dotenv "^10.0.0"
|
||||||
dotenv-expand "^5.1.0"
|
dotenv-expand "^5.1.0"
|
||||||
eslint "^8.3.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"
|
eslint-webpack-plugin "^3.1.1"
|
||||||
file-loader "^6.2.0"
|
file-loader "^6.2.0"
|
||||||
fs-extra "^10.0.0"
|
fs-extra "^10.0.0"
|
||||||
@@ -6938,7 +6967,7 @@ react-scripts@5.0.0:
|
|||||||
postcss-preset-env "^7.0.1"
|
postcss-preset-env "^7.0.1"
|
||||||
prompts "^2.4.2"
|
prompts "^2.4.2"
|
||||||
react-app-polyfill "^3.0.0"
|
react-app-polyfill "^3.0.0"
|
||||||
react-dev-utils "^12.0.0"
|
react-dev-utils "^12.0.1"
|
||||||
react-refresh "^0.11.0"
|
react-refresh "^0.11.0"
|
||||||
resolve "^1.20.0"
|
resolve "^1.20.0"
|
||||||
resolve-url-loader "^4.0.0"
|
resolve-url-loader "^4.0.0"
|
||||||
@@ -6955,13 +6984,12 @@ react-scripts@5.0.0:
|
|||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
fsevents "^2.3.2"
|
fsevents "^2.3.2"
|
||||||
|
|
||||||
react@^17.0.2:
|
react@^18.1.0:
|
||||||
version "17.0.2"
|
version "18.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037"
|
resolved "https://registry.yarnpkg.com/react/-/react-18.1.0.tgz#6f8620382decb17fdc5cc223a115e2adbf104890"
|
||||||
integrity sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA==
|
integrity sha512-4oL8ivCz5ZEPyclFQXaNksK3adutVS8l2xzZU0cqEFrE9Sb7fC0EFK5uEk74wIreL1DERyjvsU915j1pcT2uEQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
loose-envify "^1.1.0"
|
loose-envify "^1.1.0"
|
||||||
object-assign "^4.1.1"
|
|
||||||
|
|
||||||
readable-stream@^2.0.1:
|
readable-stream@^2.0.1:
|
||||||
version "2.3.7"
|
version "2.3.7"
|
||||||
@@ -7235,13 +7263,12 @@ saxes@^5.0.1:
|
|||||||
dependencies:
|
dependencies:
|
||||||
xmlchars "^2.2.0"
|
xmlchars "^2.2.0"
|
||||||
|
|
||||||
scheduler@^0.20.2:
|
scheduler@^0.22.0:
|
||||||
version "0.20.2"
|
version "0.22.0"
|
||||||
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.20.2.tgz#4baee39436e34aa93b4874bddcbf0fe8b8b50e91"
|
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.22.0.tgz#83a5d63594edf074add9a7198b1bae76c3db01b8"
|
||||||
integrity sha512-2eWfGgAqqWFGqtdMmcL5zCMK1U8KlXv8SQFGglL3CEtd0aDVDWgeF/YoCmvln55m5zSk3J/20hTaSBeSObsQDQ==
|
integrity sha512-6QAm1BgQI88NPYymgGQLCZgvep4FyePDWFpXVK+zNSUgHwlqpJy8VEh8Et0KxTACS4VWwMousBElAZOH9nkkoQ==
|
||||||
dependencies:
|
dependencies:
|
||||||
loose-envify "^1.1.0"
|
loose-envify "^1.1.0"
|
||||||
object-assign "^4.1.1"
|
|
||||||
|
|
||||||
schema-utils@2.7.0:
|
schema-utils@2.7.0:
|
||||||
version "2.7.0"
|
version "2.7.0"
|
||||||
@@ -8156,10 +8183,10 @@ wbuf@^1.1.0, wbuf@^1.7.3:
|
|||||||
dependencies:
|
dependencies:
|
||||||
minimalistic-assert "^1.0.0"
|
minimalistic-assert "^1.0.0"
|
||||||
|
|
||||||
web-vitals@^2.1.3:
|
web-vitals@^2.1.4:
|
||||||
version "2.1.3"
|
version "2.1.4"
|
||||||
resolved "https://registry.yarnpkg.com/web-vitals/-/web-vitals-2.1.3.tgz#6dca59f41dbc3fcccdb889da06191b437b18f534"
|
resolved "https://registry.yarnpkg.com/web-vitals/-/web-vitals-2.1.4.tgz#76563175a475a5e835264d373704f9dde718290c"
|
||||||
integrity sha512-+ijpniAzcnQicXaXIN0/eHQAiV/jMt1oHGHTmz7VdAJPPkzzDhmoYPSpLgJTuFtUh+jCjxCoeTZPg7Ic+g8o7w==
|
integrity sha512-sVWcwhU5mX6crfI5Vd2dC4qchyTqxV8URinzt25XqVh+bHEPGH4C3NPrNionCP7Obx59wrYEbNlw4Z8sjALzZg==
|
||||||
|
|
||||||
webidl-conversions@^4.0.2:
|
webidl-conversions@^4.0.2:
|
||||||
version "4.0.2"
|
version "4.0.2"
|
||||||
|
|||||||
3
examples/remix/.eslintrc.js
Normal file
3
examples/remix/.eslintrc.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = {
|
||||||
|
extends: ["@remix-run/eslint-config", "@remix-run/eslint-config/node"],
|
||||||
|
};
|
||||||
8
examples/remix/.gitignore
vendored
8
examples/remix/.gitignore
vendored
@@ -1,7 +1,11 @@
|
|||||||
node_modules
|
node_modules
|
||||||
|
|
||||||
.cache
|
.cache
|
||||||
|
.env
|
||||||
.vercel
|
.vercel
|
||||||
|
.output
|
||||||
|
|
||||||
public/build
|
/build/
|
||||||
api/_build
|
/public/build
|
||||||
|
/api/index.js
|
||||||
|
/api/index.js.map
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
const { createRequestHandler } = require("@remix-run/vercel");
|
|
||||||
|
|
||||||
module.exports = createRequestHandler({
|
|
||||||
build: require("./_build")
|
|
||||||
});
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
|
import { RemixBrowser } from "@remix-run/react";
|
||||||
import { hydrate } from "react-dom";
|
import { hydrate } from "react-dom";
|
||||||
import { RemixBrowser } from "remix";
|
|
||||||
|
|
||||||
hydrate(<RemixBrowser />, document);
|
hydrate(<RemixBrowser />, document);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
|
import type { EntryContext } from "@remix-run/node";
|
||||||
|
import { RemixServer } from "@remix-run/react";
|
||||||
import { renderToString } from "react-dom/server";
|
import { renderToString } from "react-dom/server";
|
||||||
import { RemixServer } from "remix";
|
|
||||||
import type { EntryContext } from "remix";
|
|
||||||
|
|
||||||
export default function handleRequest(
|
export default function handleRequest(
|
||||||
request: Request,
|
request: Request,
|
||||||
@@ -16,6 +16,6 @@ export default function handleRequest(
|
|||||||
|
|
||||||
return new Response("<!DOCTYPE html>" + markup, {
|
return new Response("<!DOCTYPE html>" + markup, {
|
||||||
status: responseStatusCode,
|
status: responseStatusCode,
|
||||||
headers: responseHeaders
|
headers: responseHeaders,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { LinksFunction, MetaFunction } from "@remix-run/node";
|
||||||
import {
|
import {
|
||||||
Link,
|
Link,
|
||||||
Links,
|
Links,
|
||||||
@@ -6,14 +7,13 @@ import {
|
|||||||
Outlet,
|
Outlet,
|
||||||
Scripts,
|
Scripts,
|
||||||
ScrollRestoration,
|
ScrollRestoration,
|
||||||
useCatch
|
useCatch,
|
||||||
} from "remix";
|
} from "@remix-run/react";
|
||||||
import type { LinksFunction } from "remix";
|
|
||||||
|
|
||||||
import globalStylesUrl from "~/styles/global.css";
|
|
||||||
import darkStylesUrl from "~/styles/dark.css";
|
import darkStylesUrl from "~/styles/dark.css";
|
||||||
|
import globalStylesUrl from "~/styles/global.css";
|
||||||
|
|
||||||
// https://remix.run/api/app#links
|
// https://remix.run/api/conventions#links
|
||||||
export let links: LinksFunction = () => {
|
export let links: LinksFunction = () => {
|
||||||
return [
|
return [
|
||||||
{ rel: "stylesheet", href: globalStylesUrl },
|
{ rel: "stylesheet", href: globalStylesUrl },
|
||||||
@@ -25,6 +25,12 @@ export let links: LinksFunction = () => {
|
|||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// https://remix.run/api/conventions#meta
|
||||||
|
export let meta: MetaFunction = () => ({
|
||||||
|
charset: "utf-8",
|
||||||
|
viewport: "width=device-width,initial-scale=1",
|
||||||
|
});
|
||||||
|
|
||||||
// https://remix.run/api/conventions#default-export
|
// https://remix.run/api/conventions#default-export
|
||||||
// https://remix.run/api/conventions#route-filenames
|
// https://remix.run/api/conventions#route-filenames
|
||||||
export default function App() {
|
export default function App() {
|
||||||
@@ -37,7 +43,7 @@ export default function App() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://remix.run/docs/en/v1/api/conventions#errorboundary
|
// https://remix.run/api/conventions#errorboundary
|
||||||
export function ErrorBoundary({ error }: { error: Error }) {
|
export function ErrorBoundary({ error }: { error: Error }) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return (
|
return (
|
||||||
@@ -57,7 +63,7 @@ export function ErrorBoundary({ error }: { error: Error }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://remix.run/docs/en/v1/api/conventions#catchboundary
|
// https://remix.run/api/conventions#catchboundary
|
||||||
export function CatchBoundary() {
|
export function CatchBoundary() {
|
||||||
let caught = useCatch();
|
let caught = useCatch();
|
||||||
|
|
||||||
@@ -103,8 +109,6 @@ function Document({
|
|||||||
return (
|
return (
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charSet="utf-8" />
|
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
||||||
{title ? <title>{title}</title> : null}
|
{title ? <title>{title}</title> : null}
|
||||||
<Meta />
|
<Meta />
|
||||||
<Links />
|
<Links />
|
||||||
@@ -113,7 +117,7 @@ function Document({
|
|||||||
{children}
|
{children}
|
||||||
<ScrollRestoration />
|
<ScrollRestoration />
|
||||||
<Scripts />
|
<Scripts />
|
||||||
{process.env.NODE_ENV === "development" && <LiveReload />}
|
<LiveReload />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Outlet } from "remix";
|
import type { MetaFunction, LinksFunction } from "@remix-run/node";
|
||||||
import type { MetaFunction, LinksFunction } from "remix";
|
import { Outlet } from "@remix-run/react";
|
||||||
|
|
||||||
import stylesUrl from "~/styles/demos/about.css";
|
import stylesUrl from "~/styles/demos/about.css";
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Link } from "remix";
|
import { Link } from "@remix-run/react";
|
||||||
|
|
||||||
export default function AboutIndex() {
|
export default function AboutIndex() {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Link } from "remix";
|
import { Link } from "@remix-run/react";
|
||||||
|
|
||||||
export default function AboutIndex() {
|
export default function AboutIndex() {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
|
import type { ActionFunction } from "@remix-run/node";
|
||||||
|
import { json, redirect } from "@remix-run/node";
|
||||||
|
import { Form, useActionData } from "@remix-run/react";
|
||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
import type { ActionFunction } from "remix";
|
|
||||||
import { Form, json, useActionData, redirect } from "remix";
|
|
||||||
|
|
||||||
export function meta() {
|
export function meta() {
|
||||||
return { title: "Actions Demo" };
|
return { title: "Actions Demo" };
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { useCatch, Link, json, useLoaderData, Outlet } from "remix";
|
import type { MetaFunction } from "@remix-run/node";
|
||||||
|
import { json } from "@remix-run/node";
|
||||||
|
import { Link, Outlet, useCatch, useLoaderData } from "@remix-run/react";
|
||||||
|
|
||||||
export function meta() {
|
export let meta: MetaFunction = () => ({ title: "Boundaries Demo" });
|
||||||
return { title: "Boundaries Demo" };
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function Boundaries() {
|
export default function Boundaries() {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useCatch, Link, json, useLoaderData } from "remix";
|
import type { LoaderFunction, MetaFunction } from "@remix-run/node";
|
||||||
import type { LoaderFunction, MetaFunction } from "remix";
|
import { json } from "@remix-run/node";
|
||||||
|
import { Link, useCatch, useLoaderData } from "@remix-run/react";
|
||||||
|
|
||||||
// The `$` in route filenames becomes a pattern that's parsed from the URL and
|
// The `$` in route filenames becomes a pattern that's parsed from the URL and
|
||||||
// passed to your loaders so you can look up data.
|
// passed to your loaders so you can look up data.
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { useCatch, Link, json, useLoaderData, Outlet } from "remix";
|
import type { LoaderFunction } from "@remix-run/node";
|
||||||
import type { LoaderFunction } from "remix";
|
import { json } from "@remix-run/node";
|
||||||
|
import { Link, Outlet, useCatch, useLoaderData } from "@remix-run/react";
|
||||||
|
|
||||||
export default function Boundaries() {
|
export default function Boundaries() {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { MetaFunction, LoaderFunction } from "remix";
|
import type { MetaFunction, LoaderFunction } from "@remix-run/node";
|
||||||
import { useLoaderData, json, Link } from "remix";
|
import { json } from "@remix-run/node";
|
||||||
|
import { Link, useLoaderData } from "@remix-run/react";
|
||||||
|
|
||||||
type IndexData = {
|
type IndexData = {
|
||||||
resources: Array<{ name: string; url: string }>;
|
resources: Array<{ name: string; url: string }>;
|
||||||
|
|||||||
8345
examples/remix/package-lock.json
generated
8345
examples/remix/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,26 +1,28 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "remix-app-template",
|
"sideEffects": false,
|
||||||
"description": "",
|
|
||||||
"license": "",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "remix build",
|
"build": "remix build",
|
||||||
"dev": "remix dev",
|
"dev": "remix dev"
|
||||||
"postinstall": "remix setup node"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@remix-run/react": "^1.0.6",
|
"@remix-run/node": "^1.5.1",
|
||||||
|
"@remix-run/react": "^1.5.1",
|
||||||
|
"@remix-run/vercel": "^1.5.1",
|
||||||
|
"@vercel/node": "^2.0.0",
|
||||||
"react": "^17.0.2",
|
"react": "^17.0.2",
|
||||||
"react-dom": "^17.0.2",
|
"react-dom": "^17.0.2"
|
||||||
"remix": "^1.0.6",
|
|
||||||
"@remix-run/serve": "^1.0.6",
|
|
||||||
"@remix-run/vercel": "^1.0.6"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@remix-run/dev": "^1.0.6",
|
"@remix-run/dev": "^1.5.1",
|
||||||
"@types/react": "^17.0.24",
|
"@remix-run/eslint-config": "^1.5.1",
|
||||||
"@types/react-dom": "^17.0.9",
|
"@remix-run/serve": "^1.5.1",
|
||||||
"typescript": "^4.1.2"
|
"@types/react": "^17.0.45",
|
||||||
|
"@types/react-dom": "^17.0.17",
|
||||||
|
"eslint": "^8.15.0",
|
||||||
|
"typescript": "^4.6.4"
|
||||||
},
|
},
|
||||||
"sideEffects": false
|
"engines": {
|
||||||
|
"node": ">=14"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
/**
|
/**
|
||||||
* @type {import('@remix-run/dev/config').AppConfig}
|
* @type {import('@remix-run/dev').AppConfig}
|
||||||
*/
|
*/
|
||||||
module.exports = {
|
module.exports = {
|
||||||
appDirectory: "app",
|
serverBuildTarget: "vercel",
|
||||||
browserBuildDirectory: "public/build",
|
// When running locally in development mode, we use the built in remix
|
||||||
publicPath: "/build/",
|
// server. This does not understand the vercel lambda module format,
|
||||||
serverBuildDirectory: "api/_build"
|
// so we default back to the standard build output.
|
||||||
|
server: process.env.NODE_ENV === "development" ? undefined : "./server.js",
|
||||||
|
ignoredRouteFiles: ["**/.*"],
|
||||||
|
// appDirectory: "app",
|
||||||
|
// assetsBuildDirectory: "public/build",
|
||||||
|
// serverBuildPath: "api/index.js",
|
||||||
|
// publicPath: "/build/",
|
||||||
};
|
};
|
||||||
|
|||||||
4
examples/remix/server.js
Normal file
4
examples/remix/server.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import * as build from "@remix-run/dev/server-build";
|
||||||
|
import { createRequestHandler } from "@remix-run/vercel";
|
||||||
|
|
||||||
|
export default createRequestHandler({ build, mode: process.env.NODE_ENV });
|
||||||
@@ -12,8 +12,8 @@
|
|||||||
"format": "prettier --write --plugin-search-dir=. ."
|
"format": "prettier --write --plugin-search-dir=. ."
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sveltejs/adapter-auto": "next",
|
"@sveltejs/adapter-auto": "1.0.0-next.50",
|
||||||
"@sveltejs/kit": "next",
|
"@sveltejs/kit": "1.0.0-next.347",
|
||||||
"@types/cookie": "^0.4.1",
|
"@types/cookie": "^0.4.1",
|
||||||
"prettier": "^2.5.1",
|
"prettier": "^2.5.1",
|
||||||
"prettier-plugin-svelte": "^2.5.0",
|
"prettier-plugin-svelte": "^2.5.0",
|
||||||
@@ -24,6 +24,7 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@fontsource/fira-mono": "^4.5.0",
|
"@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,19 @@
|
|||||||
<script>
|
<script>
|
||||||
import Header from '$lib/header/Header.svelte';
|
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';
|
import '../app.css';
|
||||||
|
|
||||||
|
let analyticsId = import.meta.env.VERCEL_ANALYTICS_ID;
|
||||||
|
|
||||||
|
$: if (browser && analyticsId) {
|
||||||
|
webVitals({
|
||||||
|
path: $page.url.pathname,
|
||||||
|
params: $page.params,
|
||||||
|
analyticsId
|
||||||
|
})
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Header />
|
<Header />
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ const config = {
|
|||||||
// Override http methods in the Todo forms
|
// Override http methods in the Todo forms
|
||||||
methodOverride: {
|
methodOverride: {
|
||||||
allowed: ['PATCH', 'DELETE']
|
allowed: ['PATCH', 'DELETE']
|
||||||
|
},
|
||||||
|
vite: {
|
||||||
|
define: {
|
||||||
|
'import.meta.env.VERCEL_ANALYTICS_ID': JSON.stringify(process.env.VERCEL_ANALYTICS_ID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
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,8 +30,8 @@
|
|||||||
"npm-package-arg": "6.1.0",
|
"npm-package-arg": "6.1.0",
|
||||||
"prettier": "2.6.2",
|
"prettier": "2.6.2",
|
||||||
"ts-eager": "2.0.2",
|
"ts-eager": "2.0.2",
|
||||||
"ts-jest": "28.0.0-next.1",
|
"ts-jest": "28.0.5",
|
||||||
"turbo": "1.2.14"
|
"turbo": "1.3.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lerna": "lerna",
|
"lerna": "lerna",
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
"publish-from-github": "./utils/publish.sh",
|
"publish-from-github": "./utils/publish.sh",
|
||||||
"changelog": "node utils/changelog.js",
|
"changelog": "node utils/changelog.js",
|
||||||
"build": "turbo run build",
|
"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",
|
"pre-commit": "lint-staged",
|
||||||
"test": "jest --rootDir=\"test\" --testPathPattern=\"\\.test.js\"",
|
"test": "jest --rootDir=\"test\" --testPathPattern=\"\\.test.js\"",
|
||||||
"test-unit": "yarn test && turbo run test-unit",
|
"test-unit": "yarn test && turbo run test-unit",
|
||||||
@@ -49,7 +49,8 @@
|
|||||||
"test-integration-once": "turbo run test-integration-once",
|
"test-integration-once": "turbo run test-integration-once",
|
||||||
"test-integration-dev": "turbo run test-integration-dev",
|
"test-integration-dev": "turbo run test-integration-dev",
|
||||||
"lint": "eslint . --ext .ts,.js",
|
"lint": "eslint . --ext .ts,.js",
|
||||||
"prepare": "husky install"
|
"prepare": "husky install",
|
||||||
|
"pack": "cd utils && node -r ts-eager/register ./pack.ts"
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
"./{*,{api,packages,test,utils}/**/*}.{js,ts}": [
|
"./{*,{api,packages,test,utils}/**/*}.{js,ts}": [
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@vercel/build-utils",
|
"name": "@vercel/build-utils",
|
||||||
"version": "4.0.1-canary.0",
|
"version": "4.2.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"types": "./dist/index.d.js",
|
"types": "./dist/index.d.js",
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
"@types/node-fetch": "^2.1.6",
|
"@types/node-fetch": "^2.1.6",
|
||||||
"@types/semver": "6.0.0",
|
"@types/semver": "6.0.0",
|
||||||
"@types/yazl": "2.4.2",
|
"@types/yazl": "2.4.2",
|
||||||
"@vercel/frameworks": "1.0.1",
|
"@vercel/frameworks": "1.0.2",
|
||||||
"@vercel/ncc": "0.24.0",
|
"@vercel/ncc": "0.24.0",
|
||||||
"aggregate-error": "3.0.1",
|
"aggregate-error": "3.0.1",
|
||||||
"async-retry": "1.2.3",
|
"async-retry": "1.2.3",
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ interface ErrorResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface Options {
|
interface Options {
|
||||||
tag?: 'canary' | 'latest' | string;
|
tag?: string;
|
||||||
functions?: BuilderFunctions;
|
functions?: BuilderFunctions;
|
||||||
ignoreBuildScript?: boolean;
|
ignoreBuildScript?: boolean;
|
||||||
projectSettings?: ProjectSettings;
|
projectSettings?: ProjectSettings;
|
||||||
@@ -278,7 +278,7 @@ export async function detectBuilders(
|
|||||||
// and package.json can be served as static files
|
// and package.json can be served as static files
|
||||||
frontendBuilder = {
|
frontendBuilder = {
|
||||||
use: '@vercel/static',
|
use: '@vercel/static',
|
||||||
src: '!{api/**,package.json}',
|
src: '!{api/**,package.json,middleware.[jt]s}',
|
||||||
config: {
|
config: {
|
||||||
zeroConfig: true,
|
zeroConfig: true,
|
||||||
},
|
},
|
||||||
@@ -355,7 +355,16 @@ function maybeGetApiBuilder(
|
|||||||
apiMatches: Builder[],
|
apiMatches: Builder[],
|
||||||
options: Options
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -381,7 +390,7 @@ function maybeGetApiBuilder(
|
|||||||
|
|
||||||
const { fnPattern, func } = getFunction(fileName, options);
|
const { fnPattern, func } = getFunction(fileName, options);
|
||||||
|
|
||||||
const use = (func && func.runtime) || (match && match.use);
|
const use = func?.runtime || match?.use;
|
||||||
|
|
||||||
if (!use) {
|
if (!use) {
|
||||||
return null;
|
return null;
|
||||||
@@ -389,6 +398,10 @@ function maybeGetApiBuilder(
|
|||||||
|
|
||||||
const config: Config = { zeroConfig: true };
|
const config: Config = { zeroConfig: true };
|
||||||
|
|
||||||
|
if (middleware) {
|
||||||
|
config.middleware = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (fnPattern && func) {
|
if (fnPattern && func) {
|
||||||
config.functions = { [fnPattern]: func };
|
config.functions = { [fnPattern]: func };
|
||||||
|
|
||||||
@@ -428,6 +441,7 @@ function getApiMatches() {
|
|||||||
const config = { zeroConfig: true };
|
const config = { zeroConfig: true };
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
{ src: 'middleware.[jt]s', use: `@vercel/node`, config },
|
||||||
{ src: 'api/**/*.js', use: `@vercel/node`, config },
|
{ src: 'api/**/*.js', use: `@vercel/node`, config },
|
||||||
{ src: 'api/**/*.mjs', use: `@vercel/node`, config },
|
{ src: 'api/**/*.mjs', use: `@vercel/node`, config },
|
||||||
{ src: 'api/**/*.ts', use: `@vercel/node`, config },
|
{ src: 'api/**/*.ts', use: `@vercel/node`, config },
|
||||||
|
|||||||
@@ -61,6 +61,13 @@ export interface SpawnOptionsExtended extends SpawnOptions {
|
|||||||
* Pretty formatted command that is being spawned for logging purposes.
|
* Pretty formatted command that is being spawned for logging purposes.
|
||||||
*/
|
*/
|
||||||
prettyCommand?: string;
|
prettyCommand?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns instead of throwing an error when the process exits with a
|
||||||
|
* non-0 exit code. When relevant, the returned object will include
|
||||||
|
* the error code, stdout and stderr.
|
||||||
|
*/
|
||||||
|
ignoreNon0Exit?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function spawnAsync(
|
export function spawnAsync(
|
||||||
@@ -79,7 +86,7 @@ export function spawnAsync(
|
|||||||
|
|
||||||
child.on('error', reject);
|
child.on('error', reject);
|
||||||
child.on('close', (code, signal) => {
|
child.on('close', (code, signal) => {
|
||||||
if (code === 0) {
|
if (code === 0 || opts.ignoreNon0Exit) {
|
||||||
return resolve();
|
return resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,24 +130,24 @@ export function execAsync(
|
|||||||
|
|
||||||
child.on('error', reject);
|
child.on('error', reject);
|
||||||
child.on('close', (code, signal) => {
|
child.on('close', (code, signal) => {
|
||||||
if (code !== 0) {
|
if (code === 0 || opts.ignoreNon0Exit) {
|
||||||
const cmd = opts.prettyCommand
|
return resolve({
|
||||||
? `Command "${opts.prettyCommand}"`
|
code,
|
||||||
: 'Command';
|
stdout: Buffer.concat(stdoutList).toString(),
|
||||||
|
stderr: Buffer.concat(stderrList).toString(),
|
||||||
return reject(
|
});
|
||||||
new NowBuildError({
|
|
||||||
code: `BUILD_UTILS_EXEC_${code || signal}`,
|
|
||||||
message: `${cmd} exited with ${code || signal}`,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return resolve({
|
const cmd = opts.prettyCommand
|
||||||
code,
|
? `Command "${opts.prettyCommand}"`
|
||||||
stdout: Buffer.concat(stdoutList).toString(),
|
: 'Command';
|
||||||
stderr: Buffer.concat(stderrList).toString(),
|
|
||||||
});
|
return reject(
|
||||||
|
new NowBuildError({
|
||||||
|
code: `BUILD_UTILS_EXEC_${code || signal}`,
|
||||||
|
message: `${cmd} exited with ${code || signal}`,
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -166,9 +173,30 @@ export async function execCommand(command: string, options: SpawnOptions = {}) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getNodeBinPath({ cwd }: { cwd: string }) {
|
export async function getNodeBinPath({
|
||||||
const { stdout } = await execAsync('npm', ['bin'], { cwd });
|
cwd,
|
||||||
return stdout.trim();
|
}: {
|
||||||
|
cwd: string;
|
||||||
|
}): Promise<string | undefined> {
|
||||||
|
const { code, stdout, stderr } = await execAsync('npm', ['bin'], {
|
||||||
|
cwd,
|
||||||
|
prettyCommand: 'npm bin',
|
||||||
|
|
||||||
|
// in some rare cases, we saw `npm bin` exit with a non-0 code, but still
|
||||||
|
// output the right bin path, so we ignore the exit code
|
||||||
|
ignoreNon0Exit: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const nodeBinPath = stdout.trim();
|
||||||
|
|
||||||
|
if (path.isAbsolute(nodeBinPath)) {
|
||||||
|
return nodeBinPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new NowBuildError({
|
||||||
|
code: `BUILD_UTILS_GET_NODE_BIN_PATH`,
|
||||||
|
message: `Running \`npm bin\` failed to return a valid bin path (code=${code}, stdout=${stdout}, stderr=${stderr})`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function chmodPlusX(fsPath: string) {
|
async function chmodPlusX(fsPath: string) {
|
||||||
|
|||||||
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';
|
} from './detect-builders';
|
||||||
export { detectFileSystemAPI } from './detect-file-system-api';
|
export { detectFileSystemAPI } from './detect-file-system-api';
|
||||||
export { detectFramework } from './detect-framework';
|
export { detectFramework } from './detect-framework';
|
||||||
|
export { getProjectPaths } from './get-project-paths';
|
||||||
export { DetectorFilesystem } from './detectors/filesystem';
|
export { DetectorFilesystem } from './detectors/filesystem';
|
||||||
export { readConfigFile } from './fs/read-config-file';
|
export { readConfigFile } from './fs/read-config-file';
|
||||||
export { normalizePath } from './fs/normalize-path';
|
export { normalizePath } from './fs/normalize-path';
|
||||||
|
|||||||
@@ -428,6 +428,8 @@ export interface BuildResultV2Typical {
|
|||||||
export type BuildResultV2 = BuildResultV2Typical | BuildResultBuildOutput;
|
export type BuildResultV2 = BuildResultV2Typical | BuildResultBuildOutput;
|
||||||
|
|
||||||
export interface BuildResultV3 {
|
export interface BuildResultV3 {
|
||||||
|
// TODO: use proper `Route` type from `routing-utils` (perhaps move types to a common package)
|
||||||
|
routes?: any[];
|
||||||
output: Lambda | EdgeFunction;
|
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].use).toBe('@vercel/node');
|
||||||
expect(builders![0].src).toBe('api/users.js');
|
expect(builders![0].src).toBe('api/users.js');
|
||||||
expect(builders![1].use).toBe('@vercel/static');
|
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(builders!.length).toBe(2);
|
||||||
expect(errors).toBe(null);
|
expect(errors).toBe(null);
|
||||||
});
|
});
|
||||||
@@ -89,7 +89,7 @@ describe('Test `detectBuilders`', () => {
|
|||||||
expect(builders![0].use).toBe('@vercel/node');
|
expect(builders![0].use).toBe('@vercel/node');
|
||||||
expect(builders![0].src).toBe('api/[endpoint].js');
|
expect(builders![0].src).toBe('api/[endpoint].js');
|
||||||
expect(builders![1].use).toBe('@vercel/static');
|
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(builders!.length).toBe(2);
|
||||||
expect(errors).toBe(null);
|
expect(errors).toBe(null);
|
||||||
});
|
});
|
||||||
@@ -144,7 +144,7 @@ describe('Test `detectBuilders`', () => {
|
|||||||
expect(builders![0].use).toBe('@vercel/node');
|
expect(builders![0].use).toBe('@vercel/node');
|
||||||
expect(builders![0].src).toBe('api/endpoint.js');
|
expect(builders![0].src).toBe('api/endpoint.js');
|
||||||
expect(builders![1].use).toBe('@vercel/static');
|
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(builders!.length).toBe(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -347,7 +347,7 @@ describe('Test `detectBuilders`', () => {
|
|||||||
expect(builders![0].use).toBe('@vercel/node');
|
expect(builders![0].use).toBe('@vercel/node');
|
||||||
expect(builders![0].src).toBe('api/index.ts');
|
expect(builders![0].src).toBe('api/index.ts');
|
||||||
expect(builders![1].use).toBe('@vercel/static');
|
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 () => {
|
it('functions with nextjs', async () => {
|
||||||
@@ -671,8 +671,8 @@ describe('Test `detectBuilders`', () => {
|
|||||||
expect(builders![0].use).toBe('@vercel/static');
|
expect(builders![0].use).toBe('@vercel/static');
|
||||||
|
|
||||||
expect(defaultRoutes!.length).toBe(1);
|
expect(defaultRoutes!.length).toBe(1);
|
||||||
expect((defaultRoutes![0] as any).src).toBe('/(.*)');
|
expect(defaultRoutes![0].src).toBe('/(.*)');
|
||||||
expect((defaultRoutes![0] as any).dest).toBe('/dist/$1');
|
expect(defaultRoutes![0].dest).toBe('/dist/$1');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Custom static output directory with api', async () => {
|
it('Custom static output directory with api', async () => {
|
||||||
@@ -691,9 +691,9 @@ describe('Test `detectBuilders`', () => {
|
|||||||
expect(builders![1].use).toBe('@vercel/static');
|
expect(builders![1].use).toBe('@vercel/static');
|
||||||
|
|
||||||
expect(defaultRoutes!.length).toBe(3);
|
expect(defaultRoutes!.length).toBe(3);
|
||||||
expect((defaultRoutes![1] as any).status).toBe(404);
|
expect(defaultRoutes![1].status).toBe(404);
|
||||||
expect((defaultRoutes![2] as any).src).toBe('/(.*)');
|
expect(defaultRoutes![2].src).toBe('/(.*)');
|
||||||
expect((defaultRoutes![2] as any).dest).toBe('/output/$1');
|
expect(defaultRoutes![2].dest).toBe('/output/$1');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Framework with non-package.json entrypoint', async () => {
|
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].use).toBe('@vercel/node');
|
||||||
expect(builders![0].src).toBe('api/users.js');
|
expect(builders![0].src).toBe('api/users.js');
|
||||||
expect(builders![1].use).toBe('@vercel/static');
|
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(builders!.length).toBe(2);
|
||||||
expect(errors).toBe(null);
|
expect(errors).toBe(null);
|
||||||
|
|
||||||
@@ -1032,7 +1032,7 @@ describe('Test `detectBuilders` with `featHandleMiss=true`', () => {
|
|||||||
expect(builders![0].use).toBe('@vercel/node');
|
expect(builders![0].use).toBe('@vercel/node');
|
||||||
expect(builders![0].src).toBe('api/[endpoint].js');
|
expect(builders![0].src).toBe('api/[endpoint].js');
|
||||||
expect(builders![1].use).toBe('@vercel/static');
|
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(builders!.length).toBe(2);
|
||||||
expect(errors).toBe(null);
|
expect(errors).toBe(null);
|
||||||
});
|
});
|
||||||
@@ -1258,7 +1258,7 @@ describe('Test `detectBuilders` with `featHandleMiss=true`', () => {
|
|||||||
expect(builders![0].use).toBe('@vercel/node');
|
expect(builders![0].use).toBe('@vercel/node');
|
||||||
expect(builders![0].src).toBe('api/endpoint.js');
|
expect(builders![0].src).toBe('api/endpoint.js');
|
||||||
expect(builders![1].use).toBe('@vercel/static');
|
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(builders!.length).toBe(2);
|
||||||
|
|
||||||
expect(defaultRoutes!.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].use).toBe('@vercel/node');
|
||||||
expect(builders![0].src).toBe('api/version.js');
|
expect(builders![0].src).toBe('api/version.js');
|
||||||
expect(builders![1].use).toBe('@vercel/static');
|
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(builders!.length).toBe(2);
|
||||||
|
|
||||||
expect(defaultRoutes!.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].use).toBe('@vercel/node');
|
||||||
expect(builders![0].src).toBe('api/index.ts');
|
expect(builders![0].src).toBe('api/index.ts');
|
||||||
expect(builders![1].use).toBe('@vercel/static');
|
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!.length).toBe(1);
|
||||||
expect((errorRoutes![0] as Source).status).toBe(404);
|
expect((errorRoutes![0] as Source).status).toBe(404);
|
||||||
});
|
});
|
||||||
@@ -2228,6 +2228,55 @@ describe('Test `detectBuilders` with `featHandleMiss=true`', () => {
|
|||||||
expect(builders).toBe(null);
|
expect(builders).toBe(null);
|
||||||
expect(errors).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 () => {
|
it('Test `detectRoutes`', async () => {
|
||||||
@@ -2236,10 +2285,10 @@ it('Test `detectRoutes`', async () => {
|
|||||||
|
|
||||||
const { defaultRoutes } = await detectBuilders(files);
|
const { defaultRoutes } = await detectBuilders(files);
|
||||||
expect(defaultRoutes!.length).toBe(3);
|
expect(defaultRoutes!.length).toBe(3);
|
||||||
expect((defaultRoutes![0] as any).dest).toBe('/api/team.js');
|
expect(defaultRoutes![0].dest).toBe('/api/team.js');
|
||||||
expect((defaultRoutes![1] as any).dest).toBe('/api/user.go');
|
expect(defaultRoutes![1].dest).toBe('/api/user.go');
|
||||||
expect((defaultRoutes![2] as any).dest).not.toBeDefined();
|
expect(defaultRoutes![2].dest).not.toBeDefined();
|
||||||
expect((defaultRoutes![2] as any).status).toBe(404);
|
expect(defaultRoutes![2].status).toBe(404);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -2286,10 +2335,10 @@ it('Test `detectRoutes`', async () => {
|
|||||||
];
|
];
|
||||||
|
|
||||||
const { defaultRoutes } = await detectBuilders(files);
|
const { defaultRoutes } = await detectBuilders(files);
|
||||||
expect((defaultRoutes![2] as any).status).toBe(404);
|
expect(defaultRoutes![2].status).toBe(404);
|
||||||
expect((defaultRoutes![2] as any).src).toBe('^/api(/.*)?$');
|
expect(defaultRoutes![2].src).toBe('^/api(/.*)?$');
|
||||||
expect((defaultRoutes![3] as any).src).toBe('/(.*)');
|
expect(defaultRoutes![3].src).toBe('/(.*)');
|
||||||
expect((defaultRoutes![3] as any).dest).toBe('/public/$1');
|
expect(defaultRoutes![3].dest).toBe('/public/$1');
|
||||||
expect(defaultRoutes!.length).toBe(4);
|
expect(defaultRoutes!.length).toBe(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2301,8 +2350,8 @@ it('Test `detectRoutes`', async () => {
|
|||||||
const files = ['public/index.html', 'api/[endpoint].js'];
|
const files = ['public/index.html', 'api/[endpoint].js'];
|
||||||
|
|
||||||
const { defaultRoutes } = await detectBuilders(files, pkg);
|
const { defaultRoutes } = await detectBuilders(files, pkg);
|
||||||
expect((defaultRoutes![1] as any).status).toBe(404);
|
expect(defaultRoutes![1].status).toBe(404);
|
||||||
expect((defaultRoutes![1] as any).src).toBe('^/api(/.*)?$');
|
expect(defaultRoutes![1].src).toBe('^/api(/.*)?$');
|
||||||
expect(defaultRoutes!.length).toBe(2);
|
expect(defaultRoutes!.length).toBe(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2320,14 +2369,10 @@ it('Test `detectRoutes`', async () => {
|
|||||||
const { defaultRoutes } = await detectBuilders(files);
|
const { defaultRoutes } = await detectBuilders(files);
|
||||||
|
|
||||||
expect(defaultRoutes!.length).toBe(3);
|
expect(defaultRoutes!.length).toBe(3);
|
||||||
expect((defaultRoutes![0] as any).src).toBe(
|
expect(defaultRoutes![0].src).toBe('^/api/date(/|/index|/index\\.js)?$');
|
||||||
'^/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![0] as any).dest).toBe('/api/date/index.js');
|
expect(defaultRoutes![1].dest).toBe('/api/date.js');
|
||||||
expect((defaultRoutes![1] as any).src).toBe(
|
|
||||||
'^/api/(date/|date|date\\.js)$'
|
|
||||||
);
|
|
||||||
expect((defaultRoutes![1] as any).dest).toBe('/api/date.js');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -2336,16 +2381,10 @@ it('Test `detectRoutes`', async () => {
|
|||||||
const { defaultRoutes } = await detectBuilders(files);
|
const { defaultRoutes } = await detectBuilders(files);
|
||||||
|
|
||||||
expect(defaultRoutes!.length).toBe(3);
|
expect(defaultRoutes!.length).toBe(3);
|
||||||
expect((defaultRoutes![0] as any).src).toBe(
|
expect(defaultRoutes![0].src).toBe('^/api/([^/]+)(/|/index|/index\\.js)?$');
|
||||||
'^/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![0] as any).dest).toBe(
|
expect(defaultRoutes![1].dest).toBe('/api/date.js');
|
||||||
'/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');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -2375,7 +2414,7 @@ it('Test `detectRoutes`', async () => {
|
|||||||
const { defaultRoutes } = await detectBuilders(files, null, { functions });
|
const { defaultRoutes } = await detectBuilders(files, null, { functions });
|
||||||
|
|
||||||
expect(defaultRoutes!.length).toBe(2);
|
expect(defaultRoutes!.length).toBe(2);
|
||||||
expect((defaultRoutes![0] as any).dest).toBe('/api/user.php');
|
expect(defaultRoutes![0].dest).toBe('/api/user.php');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
29
packages/build-utils/test/unit.exec-async.test.ts
vendored
Normal file
29
packages/build-utils/test/unit.exec-async.test.ts
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { execAsync, NowBuildError } from '../src';
|
||||||
|
|
||||||
|
it('should execute a command', async () => {
|
||||||
|
const { code, stdout, stderr } = await execAsync('echo', ['hello']);
|
||||||
|
|
||||||
|
expect(code).toBe(0);
|
||||||
|
expect(stdout).toContain('hello');
|
||||||
|
expect(stderr).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw if the command exits with non-0 code', async () => {
|
||||||
|
await expect(execAsync('find', ['unknown-file'])).rejects.toBeInstanceOf(
|
||||||
|
NowBuildError
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return if the command exits with non-0 code and ignoreNon0Exit=true', async () => {
|
||||||
|
const { code, stdout, stderr } = await execAsync('find', ['unknown-file'], {
|
||||||
|
ignoreNon0Exit: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(code).toBe(process.platform === 'win32' ? 2 : 1);
|
||||||
|
expect(stdout).toBe('');
|
||||||
|
expect(stderr).toContain(
|
||||||
|
process.platform === 'win32'
|
||||||
|
? 'Parameter format not correct'
|
||||||
|
: 'No such file or directory'
|
||||||
|
);
|
||||||
|
});
|
||||||
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
21
packages/build-utils/test/unit.spawn-async.test.ts
vendored
Normal file
21
packages/build-utils/test/unit.spawn-async.test.ts
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { spawnAsync, NowBuildError } from '../src';
|
||||||
|
|
||||||
|
it('should execute a command', async () => {
|
||||||
|
// should resolve (it doesn't return anything, so it resolves with "undefined")
|
||||||
|
await expect(spawnAsync('echo', ['hello'])).resolves.toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw if the command exits with non-0 code', async () => {
|
||||||
|
await expect(spawnAsync('find', ['unknown-file'])).rejects.toBeInstanceOf(
|
||||||
|
NowBuildError
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return if the command exits with non-0 code and ignoreNon0Exit=true', async () => {
|
||||||
|
// should resolve (it doesn't return anything, so it resolves with "undefined")
|
||||||
|
await expect(
|
||||||
|
spawnAsync('find', ['unknown-file'], {
|
||||||
|
ignoreNon0Exit: true,
|
||||||
|
})
|
||||||
|
).resolves.toBeUndefined();
|
||||||
|
});
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "vercel",
|
"name": "vercel",
|
||||||
"version": "25.0.2-canary.0",
|
"version": "25.2.3",
|
||||||
"preferGlobal": true,
|
"preferGlobal": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"description": "The command-line interface for Vercel",
|
"description": "The command-line interface for Vercel",
|
||||||
@@ -42,15 +42,15 @@
|
|||||||
"node": ">= 14"
|
"node": ">= 14"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@vercel/build-utils": "4.0.1-canary.0",
|
"@vercel/build-utils": "4.2.1",
|
||||||
"@vercel/go": "2.0.1-canary.0",
|
"@vercel/go": "2.0.3",
|
||||||
"@vercel/next": "3.0.1-canary.0",
|
"@vercel/next": "3.1.2",
|
||||||
"@vercel/node": "2.0.2-canary.0",
|
"@vercel/node": "2.3.3",
|
||||||
"@vercel/python": "3.0.1-canary.0",
|
"@vercel/python": "3.0.3",
|
||||||
"@vercel/redwood": "1.0.1-canary.0",
|
"@vercel/redwood": "1.0.4",
|
||||||
"@vercel/remix": "1.0.1-canary.0",
|
"@vercel/remix": "1.0.4",
|
||||||
"@vercel/ruby": "1.3.9-canary.0",
|
"@vercel/ruby": "1.3.11",
|
||||||
"@vercel/static-build": "1.0.1-canary.0",
|
"@vercel/static-build": "1.0.3",
|
||||||
"update-notifier": "5.1.0"
|
"update-notifier": "5.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -71,6 +71,7 @@
|
|||||||
"@types/fs-extra": "9.0.13",
|
"@types/fs-extra": "9.0.13",
|
||||||
"@types/glob": "7.1.1",
|
"@types/glob": "7.1.1",
|
||||||
"@types/http-proxy": "1.16.2",
|
"@types/http-proxy": "1.16.2",
|
||||||
|
"@types/ini": "1.3.31",
|
||||||
"@types/inquirer": "7.3.1",
|
"@types/inquirer": "7.3.1",
|
||||||
"@types/jest": "27.4.1",
|
"@types/jest": "27.4.1",
|
||||||
"@types/jest-expect-message": "1.0.3",
|
"@types/jest-expect-message": "1.0.3",
|
||||||
@@ -94,8 +95,8 @@
|
|||||||
"@types/which": "1.3.2",
|
"@types/which": "1.3.2",
|
||||||
"@types/write-json-file": "2.2.1",
|
"@types/write-json-file": "2.2.1",
|
||||||
"@types/yauzl-promise": "2.1.0",
|
"@types/yauzl-promise": "2.1.0",
|
||||||
"@vercel/client": "12.0.1-canary.0",
|
"@vercel/client": "12.0.3",
|
||||||
"@vercel/frameworks": "1.0.1",
|
"@vercel/frameworks": "1.0.2",
|
||||||
"@vercel/ncc": "0.24.0",
|
"@vercel/ncc": "0.24.0",
|
||||||
"@zeit/fun": "0.11.2",
|
"@zeit/fun": "0.11.2",
|
||||||
"@zeit/source-map-support": "0.6.2",
|
"@zeit/source-map-support": "0.6.2",
|
||||||
@@ -130,11 +131,13 @@
|
|||||||
"fast-deep-equal": "3.1.3",
|
"fast-deep-equal": "3.1.3",
|
||||||
"fs-extra": "10.0.0",
|
"fs-extra": "10.0.0",
|
||||||
"get-port": "5.1.1",
|
"get-port": "5.1.1",
|
||||||
|
"git-last-commit": "1.0.1",
|
||||||
"glob": "7.1.2",
|
"glob": "7.1.2",
|
||||||
"http-proxy": "1.18.1",
|
"http-proxy": "1.18.1",
|
||||||
|
"ini": "3.0.0",
|
||||||
"inquirer": "7.0.4",
|
"inquirer": "7.0.4",
|
||||||
"is-docker": "2.2.1",
|
"is-docker": "2.2.1",
|
||||||
"is-port-reachable": "3.0.0",
|
"is-port-reachable": "3.1.0",
|
||||||
"is-url": "1.2.2",
|
"is-url": "1.2.2",
|
||||||
"jaro-winkler": "0.2.8",
|
"jaro-winkler": "0.2.8",
|
||||||
"jsonlines": "0.1.1",
|
"jsonlines": "0.1.1",
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import confirm from '../../util/input/confirm';
|
|||||||
import findAliasByAliasOrId from '../../util/alias/find-alias-by-alias-or-id';
|
import findAliasByAliasOrId from '../../util/alias/find-alias-by-alias-or-id';
|
||||||
|
|
||||||
import { Alias } from '../../types';
|
import { Alias } from '../../types';
|
||||||
import { Output } from '../../util/output';
|
|
||||||
import { isValidName } from '../../util/is-valid-name';
|
import { isValidName } from '../../util/is-valid-name';
|
||||||
import { getCommandName } from '../../util/pkg-name';
|
import { getCommandName } from '../../util/pkg-name';
|
||||||
|
|
||||||
@@ -71,7 +70,7 @@ export default async function rm(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const removeStamp = stamp();
|
const removeStamp = stamp();
|
||||||
if (!opts['--yes'] && !(await confirmAliasRemove(output, alias))) {
|
if (!opts['--yes'] && !(await confirmAliasRemove(client, alias))) {
|
||||||
output.log('Aborted');
|
output.log('Aborted');
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -85,7 +84,7 @@ export default async function rm(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function confirmAliasRemove(output: Output, alias: Alias) {
|
async function confirmAliasRemove(client: Client, alias: Alias) {
|
||||||
const srcUrl = alias.deployment
|
const srcUrl = alias.deployment
|
||||||
? chalk.underline(alias.deployment.url)
|
? chalk.underline(alias.deployment.url)
|
||||||
: null;
|
: null;
|
||||||
@@ -104,7 +103,7 @@ async function confirmAliasRemove(output: Output, alias: Alias) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
output.log(`The following alias will be removed permanently`);
|
client.output.log(`The following alias will be removed permanently`);
|
||||||
output.print(` ${tbl}\n`);
|
client.output.print(` ${tbl}\n`);
|
||||||
return confirm(chalk.red('Are you sure?'), false);
|
return confirm(client, chalk.red('Are you sure?'), false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,6 +187,7 @@ export default async client => {
|
|||||||
if (cardId) {
|
if (cardId) {
|
||||||
const label = `Are you sure that you to set this card as the default?`;
|
const label = `Are you sure that you to set this card as the default?`;
|
||||||
const confirmation = await promptBool(label, {
|
const confirmation = await promptBool(label, {
|
||||||
|
...client,
|
||||||
trailing: '\n',
|
trailing: '\n',
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -262,7 +263,7 @@ export default async client => {
|
|||||||
// typed `vercel billing rm <some-id>`) is valid
|
// typed `vercel billing rm <some-id>`) is valid
|
||||||
if (cardId) {
|
if (cardId) {
|
||||||
const label = `Are you sure that you want to remove this card?`;
|
const label = `Are you sure that you want to remove this card?`;
|
||||||
const confirmation = await promptBool(label);
|
const confirmation = await promptBool(label, client);
|
||||||
if (!confirmation) {
|
if (!confirmation) {
|
||||||
console.log('Aborted');
|
console.log('Aborted');
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import Client from '../../util/client';
|
|||||||
import { getPkgName } from '../../util/pkg-name';
|
import { getPkgName } from '../../util/pkg-name';
|
||||||
import { Output } from '../../util/output';
|
import { Output } from '../../util/output';
|
||||||
import { Deployment, PaginationOptions } from '../../types';
|
import { Deployment, PaginationOptions } from '../../types';
|
||||||
|
import { normalizeURL } from '../../util/bisect/normalize-url';
|
||||||
|
|
||||||
interface DeploymentV6
|
interface DeploymentV6
|
||||||
extends Pick<
|
extends Pick<
|
||||||
@@ -97,9 +98,7 @@ export default async function main(client: Client): Promise<number> {
|
|||||||
run = resolve(run);
|
run = resolve(run);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bad.startsWith('https://')) {
|
bad = normalizeURL(bad);
|
||||||
bad = `https://${bad}`;
|
|
||||||
}
|
|
||||||
let parsed = parse(bad);
|
let parsed = parse(bad);
|
||||||
if (!parsed.hostname) {
|
if (!parsed.hostname) {
|
||||||
output.error('Invalid input: no hostname provided');
|
output.error('Invalid input: no hostname provided');
|
||||||
@@ -120,9 +119,7 @@ export default async function main(client: Client): Promise<number> {
|
|||||||
|
|
||||||
const badDeploymentPromise = getDeployment(client, bad).catch(err => err);
|
const badDeploymentPromise = getDeployment(client, bad).catch(err => err);
|
||||||
|
|
||||||
if (!good.startsWith('https://')) {
|
good = normalizeURL(good);
|
||||||
good = `https://${good}`;
|
|
||||||
}
|
|
||||||
parsed = parse(good);
|
parsed = parse(good);
|
||||||
if (!parsed.hostname) {
|
if (!parsed.hostname) {
|
||||||
output.error('Invalid input: no hostname provided');
|
output.error('Invalid input: no hostname provided');
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
import { join, relative } from 'path';
|
import { join, normalize, relative, resolve } from 'path';
|
||||||
import {
|
import {
|
||||||
detectBuilders,
|
detectBuilders,
|
||||||
normalizePath,
|
normalizePath,
|
||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
BuildResultV2,
|
BuildResultV2,
|
||||||
BuildResultV2Typical,
|
BuildResultV2Typical,
|
||||||
BuildResultV3,
|
BuildResultV3,
|
||||||
|
NowBuildError,
|
||||||
} from '@vercel/build-utils';
|
} from '@vercel/build-utils';
|
||||||
import minimatch from 'minimatch';
|
import minimatch from 'minimatch';
|
||||||
import {
|
import {
|
||||||
@@ -64,6 +65,7 @@ const help = () => {
|
|||||||
'DIR'
|
'DIR'
|
||||||
)} Path to the global ${'`.vercel`'} directory
|
)} Path to the global ${'`.vercel`'} directory
|
||||||
--cwd [path] The current working directory
|
--cwd [path] The current working directory
|
||||||
|
--output [path] Directory where built assets should be written to
|
||||||
--prod Build a production deployment
|
--prod Build a production deployment
|
||||||
-d, --debug Debug mode [off]
|
-d, --debug Debug mode [off]
|
||||||
-y, --yes Skip the confirmation prompt
|
-y, --yes Skip the confirmation prompt
|
||||||
@@ -100,7 +102,9 @@ export default async function main(client: Client): Promise<number> {
|
|||||||
// Parse CLI args
|
// Parse CLI args
|
||||||
const argv = getArgs(client.argv.slice(2), {
|
const argv = getArgs(client.argv.slice(2), {
|
||||||
'--cwd': String,
|
'--cwd': String,
|
||||||
|
'--output': String,
|
||||||
'--prod': Boolean,
|
'--prod': Boolean,
|
||||||
|
'--yes': Boolean,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (argv['--help']) {
|
if (argv['--help']) {
|
||||||
@@ -114,42 +118,54 @@ export default async function main(client: Client): Promise<number> {
|
|||||||
}
|
}
|
||||||
const cwd = process.cwd();
|
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
|
// 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
|
// Read project settings, and pull them from Vercel if necessary
|
||||||
let project = await readProjectSettings(join(cwd, VERCEL_DIR));
|
let project = await readProjectSettings(join(cwd, VERCEL_DIR));
|
||||||
const isTTY = process.stdin.isTTY;
|
const isTTY = process.stdin.isTTY;
|
||||||
while (!project?.settings) {
|
while (!project?.settings) {
|
||||||
if (!isTTY) {
|
let confirmed = yes;
|
||||||
client.output.print(
|
if (!confirmed) {
|
||||||
`No Project Settings found locally. Run ${cli.getCommandName(
|
if (!isTTY) {
|
||||||
'pull --yes'
|
client.output.print(
|
||||||
)} to retreive them.`
|
`No Project Settings found locally. Run ${cli.getCommandName(
|
||||||
);
|
'pull --yes'
|
||||||
return 1;
|
)} to retreive them.`
|
||||||
}
|
);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
const confirmed = await confirm(
|
confirmed = await confirm(
|
||||||
`No Project Settings found locally. Run ${cli.getCommandName(
|
client,
|
||||||
'pull'
|
`No Project Settings found locally. Run ${cli.getCommandName(
|
||||||
)} for retrieving them?`,
|
'pull'
|
||||||
true
|
)} for retrieving them?`,
|
||||||
);
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
if (!confirmed) {
|
if (!confirmed) {
|
||||||
client.output.print(`Aborted. No Project Settings retrieved.\n`);
|
client.output.print(`Aborted. No Project Settings retrieved.\n`);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
client.argv = [];
|
const { argv: originalArgv } = client;
|
||||||
|
client.argv = [
|
||||||
|
...originalArgv.slice(0, 2),
|
||||||
|
'pull',
|
||||||
|
`--environment`,
|
||||||
|
target,
|
||||||
|
];
|
||||||
const result = await pull(client);
|
const result = await pull(client);
|
||||||
if (result !== 0) {
|
if (result !== 0) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
client.argv = originalArgv;
|
||||||
project = await readProjectSettings(join(cwd, VERCEL_DIR));
|
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
|
// TODO: load env vars from the API, fall back to local files if that fails
|
||||||
|
|
||||||
const envPath = await checkExists([
|
const envPath = await checkExists([
|
||||||
@@ -267,7 +283,9 @@ export default async function main(client: Client): Promise<number> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Delete output directory from potential previous build
|
// Delete output directory from potential previous build
|
||||||
const outputDir = join(cwd, OUTPUT_DIR);
|
const outputDir = argv['--output']
|
||||||
|
? resolve(argv['--output'])
|
||||||
|
: join(cwd, OUTPUT_DIR);
|
||||||
await fs.remove(outputDir);
|
await fs.remove(outputDir);
|
||||||
|
|
||||||
const buildStamp = stamp();
|
const buildStamp = stamp();
|
||||||
@@ -284,6 +302,7 @@ export default async function main(client: Client): Promise<number> {
|
|||||||
{
|
{
|
||||||
'//': 'This file was generated by the `vercel build` command. It is not part of the Build Output API.',
|
'//': 'This file was generated by the `vercel build` command. It is not part of the Build Output API.',
|
||||||
target,
|
target,
|
||||||
|
argv: process.argv,
|
||||||
builds: builds.map(build => {
|
builds: builds.map(build => {
|
||||||
const builderWithPkg = buildersWithPkgs.get(build.use);
|
const builderWithPkg = buildersWithPkgs.get(build.use);
|
||||||
if (!builderWithPkg) {
|
if (!builderWithPkg) {
|
||||||
@@ -292,6 +311,7 @@ export default async function main(client: Client): Promise<number> {
|
|||||||
const { builder, pkg: builderPkg } = builderWithPkg;
|
const { builder, pkg: builderPkg } = builderWithPkg;
|
||||||
return {
|
return {
|
||||||
require: builderPkg.name,
|
require: builderPkg.name,
|
||||||
|
requirePath: builderWithPkg.path,
|
||||||
apiVersion: builder.version,
|
apiVersion: builder.version,
|
||||||
...build,
|
...build,
|
||||||
};
|
};
|
||||||
@@ -450,11 +470,12 @@ export default async function main(client: Client): Promise<number> {
|
|||||||
};
|
};
|
||||||
await fs.writeJSON(join(outputDir, 'config.json'), config, { spaces: 2 });
|
await fs.writeJSON(join(outputDir, 'config.json'), config, { spaces: 2 });
|
||||||
|
|
||||||
|
const relOutputDir = relative(cwd, outputDir);
|
||||||
output.print(
|
output.print(
|
||||||
`${prependEmoji(
|
`${prependEmoji(
|
||||||
`Build Completed in ${chalk.bold(OUTPUT_DIR)} ${chalk.gray(
|
`Build Completed in ${chalk.bold(
|
||||||
buildStamp()
|
relOutputDir.startsWith('..') ? outputDir : relOutputDir
|
||||||
)}`,
|
)} ${chalk.gray(buildStamp())}`,
|
||||||
emoji('success')
|
emoji('success')
|
||||||
)}\n`
|
)}\n`
|
||||||
);
|
);
|
||||||
@@ -463,17 +484,33 @@ export default async function main(client: Client): Promise<number> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function expandBuild(files: string[], build: Builder): Builder[] {
|
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;
|
let src = normalize(build.src || '**');
|
||||||
if (pattern[0] === '/') {
|
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
|
// Remove a leading slash so that the globbing is relative
|
||||||
// to `cwd` instead of the root of the filesystem.
|
// to `cwd` instead of the root of the filesystem.
|
||||||
pattern = pattern.substring(1);
|
src = src.substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const matches = files.filter(
|
const matches = files.filter(
|
||||||
name => name === pattern || minimatch(name, pattern, { dot: true })
|
name => name === src || minimatch(name, src, { dot: true })
|
||||||
);
|
);
|
||||||
|
|
||||||
return matches.map(m => {
|
return matches.map(m => {
|
||||||
|
|||||||
@@ -43,7 +43,9 @@ import {
|
|||||||
import { SchemaValidationFailed } from '../../util/errors';
|
import { SchemaValidationFailed } from '../../util/errors';
|
||||||
import purchaseDomainIfAvailable from '../../util/domains/purchase-domain-if-available';
|
import purchaseDomainIfAvailable from '../../util/domains/purchase-domain-if-available';
|
||||||
import confirm from '../../util/input/confirm';
|
import confirm from '../../util/input/confirm';
|
||||||
import editProjectSettings from '../../util/input/edit-project-settings';
|
import editProjectSettings, {
|
||||||
|
PartialProjectSettings,
|
||||||
|
} from '../../util/input/edit-project-settings';
|
||||||
import {
|
import {
|
||||||
getLinkedProject,
|
getLinkedProject,
|
||||||
linkFolderToProject,
|
linkFolderToProject,
|
||||||
@@ -63,6 +65,7 @@ import { help } from './args';
|
|||||||
import { getDeploymentChecks } from '../../util/deploy/get-deployment-checks';
|
import { getDeploymentChecks } from '../../util/deploy/get-deployment-checks';
|
||||||
import parseTarget from '../../util/deploy/parse-target';
|
import parseTarget from '../../util/deploy/parse-target';
|
||||||
import getPrebuiltJson from '../../util/deploy/get-prebuilt-json';
|
import getPrebuiltJson from '../../util/deploy/get-prebuilt-json';
|
||||||
|
import { createGitMeta } from '../../util/deploy/create-git-meta';
|
||||||
|
|
||||||
export default async (client: Client) => {
|
export default async (client: Client) => {
|
||||||
const { output } = client;
|
const { output } = client;
|
||||||
@@ -162,7 +165,7 @@ export default async (client: Client) => {
|
|||||||
const quiet = !isTTY;
|
const quiet = !isTTY;
|
||||||
|
|
||||||
// check paths
|
// check paths
|
||||||
const pathValidation = await validatePaths(output, paths);
|
const pathValidation = await validatePaths(client, paths);
|
||||||
|
|
||||||
if (!pathValidation.valid) {
|
if (!pathValidation.valid) {
|
||||||
return pathValidation.exitCode;
|
return pathValidation.exitCode;
|
||||||
@@ -240,6 +243,7 @@ export default async (client: Client) => {
|
|||||||
const shouldStartSetup =
|
const shouldStartSetup =
|
||||||
autoConfirm ||
|
autoConfirm ||
|
||||||
(await confirm(
|
(await confirm(
|
||||||
|
client,
|
||||||
`Set up and deploy ${chalk.cyan(`“${toHumanPath(path)}”`)}?`,
|
`Set up and deploy ${chalk.cyan(`“${toHumanPath(path)}”`)}?`,
|
||||||
true
|
true
|
||||||
));
|
));
|
||||||
@@ -284,7 +288,7 @@ export default async (client: Client) => {
|
|||||||
|
|
||||||
if (typeof projectOrNewProjectName === 'string') {
|
if (typeof projectOrNewProjectName === 'string') {
|
||||||
newProjectName = projectOrNewProjectName;
|
newProjectName = projectOrNewProjectName;
|
||||||
rootDirectory = await inputRootDirectory(path, output, autoConfirm);
|
rootDirectory = await inputRootDirectory(client, path, autoConfirm);
|
||||||
} else {
|
} else {
|
||||||
project = projectOrNewProjectName;
|
project = projectOrNewProjectName;
|
||||||
rootDirectory = project.rootDirectory;
|
rootDirectory = project.rootDirectory;
|
||||||
@@ -415,6 +419,8 @@ export default async (client: Client) => {
|
|||||||
parseMeta(argv['--meta'])
|
parseMeta(argv['--meta'])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const gitMetadata = await createGitMeta(path, output);
|
||||||
|
|
||||||
// Merge dotenv config, `env` from vercel.json, and `--env` / `-e` arguments
|
// Merge dotenv config, `env` from vercel.json, and `--env` / `-e` arguments
|
||||||
const deploymentEnv = Object.assign(
|
const deploymentEnv = Object.assign(
|
||||||
{},
|
{},
|
||||||
@@ -453,6 +459,15 @@ export default async (client: Client) => {
|
|||||||
let deployStamp = stamp();
|
let deployStamp = stamp();
|
||||||
let deployment = null;
|
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 {
|
try {
|
||||||
const createArgs: any = {
|
const createArgs: any = {
|
||||||
name: project ? project.name : newProjectName,
|
name: project ? project.name : newProjectName,
|
||||||
@@ -468,6 +483,7 @@ export default async (client: Client) => {
|
|||||||
nowConfig: localConfig,
|
nowConfig: localConfig,
|
||||||
regions,
|
regions,
|
||||||
meta,
|
meta,
|
||||||
|
gitMetadata,
|
||||||
deployStamp,
|
deployStamp,
|
||||||
target,
|
target,
|
||||||
skipAutoDetectionConfirmation: autoConfirm,
|
skipAutoDetectionConfirmation: autoConfirm,
|
||||||
@@ -475,7 +491,12 @@ export default async (client: Client) => {
|
|||||||
|
|
||||||
if (!localConfig.builds || localConfig.builds.length === 0) {
|
if (!localConfig.builds || localConfig.builds.length === 0) {
|
||||||
// Only add projectSettings for zero config deployments
|
// Only add projectSettings for zero config deployments
|
||||||
createArgs.projectSettings = { sourceFilesOutsideRootDirectory };
|
createArgs.projectSettings =
|
||||||
|
status === 'not_linked'
|
||||||
|
? {
|
||||||
|
sourceFilesOutsideRootDirectory,
|
||||||
|
}
|
||||||
|
: { ...localConfigurationOverrides, sourceFilesOutsideRootDirectory };
|
||||||
}
|
}
|
||||||
|
|
||||||
deployment = await createDeploy(
|
deployment = await createDeploy(
|
||||||
@@ -501,9 +522,11 @@ export default async (client: Client) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const settings = await editProjectSettings(
|
const settings = await editProjectSettings(
|
||||||
output,
|
client,
|
||||||
projectSettings,
|
projectSettings,
|
||||||
framework
|
framework,
|
||||||
|
false,
|
||||||
|
localConfigurationOverrides
|
||||||
);
|
);
|
||||||
|
|
||||||
// deploy again, but send projectSettings this time
|
// deploy again, but send projectSettings this time
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { resolve, join } from 'path';
|
import { resolve, join } from 'path';
|
||||||
|
import fs from 'fs-extra';
|
||||||
|
|
||||||
import DevServer from '../../util/dev/server';
|
import DevServer from '../../util/dev/server';
|
||||||
import parseListen from '../../util/dev/parse-listen';
|
import parseListen from '../../util/dev/parse-listen';
|
||||||
@@ -12,6 +13,7 @@ import setupAndLink from '../../util/link/setup-and-link';
|
|||||||
import getSystemEnvValues from '../../util/env/get-system-env-values';
|
import getSystemEnvValues from '../../util/env/get-system-env-values';
|
||||||
import { getCommandName } from '../../util/pkg-name';
|
import { getCommandName } from '../../util/pkg-name';
|
||||||
import param from '../../util/output/param';
|
import param from '../../util/output/param';
|
||||||
|
import { OUTPUT_DIR } from '../../util/build/write-build-result';
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
'--listen': string;
|
'--listen': string;
|
||||||
@@ -104,6 +106,17 @@ export default async function dev(
|
|||||||
devCommand = process.env.VERCEL_DEV_COMMAND;
|
devCommand = process.env.VERCEL_DEV_COMMAND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If there is no Development Command, we must delete the
|
||||||
|
// v3 Build Output because it will incorrectly be detected by
|
||||||
|
// @vercel/static-build in BuildOutputV3.getBuildOutputDirectory()
|
||||||
|
if (!devCommand) {
|
||||||
|
const outputDir = join(cwd, OUTPUT_DIR);
|
||||||
|
if (await fs.pathExists(outputDir)) {
|
||||||
|
output.log(`Removing ${OUTPUT_DIR}`);
|
||||||
|
await fs.remove(outputDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const devServer = new DevServer(cwd, {
|
const devServer = new DevServer(cwd, {
|
||||||
output,
|
output,
|
||||||
devCommand,
|
devCommand,
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export default async function add(
|
|||||||
|
|
||||||
const addStamp = stamp();
|
const addStamp = stamp();
|
||||||
const { domain, data: argData } = parsedParams;
|
const { domain, data: argData } = parsedParams;
|
||||||
const data = await getDNSData(output, argData);
|
const data = await getDNSData(client, argData);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
output.log(`Aborted`);
|
output.log(`Aborted`);
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
@@ -87,7 +87,8 @@ export default async function buy(
|
|||||||
!(await promptBool(
|
!(await promptBool(
|
||||||
`Buy now for ${chalk.bold(`$${price}`)} (${`${period}yr${
|
`Buy now for ${chalk.bold(`$${price}`)} (${`${period}yr${
|
||||||
period > 1 ? 's' : ''
|
period > 1 ? 's' : ''
|
||||||
}`})?`
|
}`})?`,
|
||||||
|
client
|
||||||
))
|
))
|
||||||
) {
|
) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -99,7 +100,7 @@ export default async function buy(
|
|||||||
: `Auto renew every ${renewalPrice.period} years for ${chalk.bold(
|
: `Auto renew every ${renewalPrice.period} years for ${chalk.bold(
|
||||||
`$${price}`
|
`$${price}`
|
||||||
)}?`,
|
)}?`,
|
||||||
{ defaultValue: true }
|
{ ...client, defaultValue: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
let buyResult;
|
let buyResult;
|
||||||
|
|||||||
@@ -150,17 +150,7 @@ export default async function inspect(
|
|||||||
`This Domain is not configured properly. To configure it you should either:`,
|
`This Domain is not configured properly. To configure it you should either:`,
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
null,
|
null
|
||||||
{
|
|
||||||
boxen: {
|
|
||||||
margin: {
|
|
||||||
left: 2,
|
|
||||||
right: 0,
|
|
||||||
bottom: 0,
|
|
||||||
top: 0,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
output.print(
|
output.print(
|
||||||
` ${chalk.grey('a)')} ` +
|
` ${chalk.grey('a)')} ` +
|
||||||
|
|||||||
@@ -77,7 +77,8 @@ export default async function move(
|
|||||||
!(await promptBool(
|
!(await promptBool(
|
||||||
`Are you sure you want to move ${param(domainName)} to ${param(
|
`Are you sure you want to move ${param(domainName)} to ${param(
|
||||||
destination
|
destination
|
||||||
)}?`
|
)}?`,
|
||||||
|
client
|
||||||
))
|
))
|
||||||
) {
|
) {
|
||||||
output.log('Aborted');
|
output.log('Aborted');
|
||||||
@@ -95,7 +96,8 @@ export default async function move(
|
|||||||
);
|
);
|
||||||
if (
|
if (
|
||||||
!(await promptBool(
|
!(await promptBool(
|
||||||
`Are you sure you want to move ${param(domainName)}?`
|
`Are you sure you want to move ${param(domainName)}?`,
|
||||||
|
client
|
||||||
))
|
))
|
||||||
) {
|
) {
|
||||||
output.log('Aborted');
|
output.log('Aborted');
|
||||||
|
|||||||
@@ -92,7 +92,10 @@ export default async function rm(
|
|||||||
const skipConfirmation = opts['--yes'] || false;
|
const skipConfirmation = opts['--yes'] || false;
|
||||||
if (
|
if (
|
||||||
!skipConfirmation &&
|
!skipConfirmation &&
|
||||||
!(await promptBool(`Are you sure you want to remove ${param(domainName)}?`))
|
!(await promptBool(
|
||||||
|
`Are you sure you want to remove ${param(domainName)}?`,
|
||||||
|
client
|
||||||
|
))
|
||||||
) {
|
) {
|
||||||
output.log('Aborted');
|
output.log('Aborted');
|
||||||
return 0;
|
return 0;
|
||||||
@@ -230,7 +233,7 @@ async function removeDomain(
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
!skipConfirmation &&
|
!skipConfirmation &&
|
||||||
!(await promptBool(`Remove conflicts associated with domain?`))
|
!(await promptBool(`Remove conflicts associated with domain?`, client))
|
||||||
) {
|
) {
|
||||||
output.log('Aborted');
|
output.log('Aborted');
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -81,7 +81,8 @@ export default async function transferIn(
|
|||||||
const shouldTransfer = await promptBool(
|
const shouldTransfer = await promptBool(
|
||||||
transferPolicy === 'no-change'
|
transferPolicy === 'no-change'
|
||||||
? `Transfer now for ${chalk.bold(`$${price}`)}?`
|
? `Transfer now for ${chalk.bold(`$${price}`)}?`
|
||||||
: `Transfer now with 1yr renewal for ${chalk.bold(`$${price}`)}?`
|
: `Transfer now with 1yr renewal for ${chalk.bold(`$${price}`)}?`,
|
||||||
|
client
|
||||||
);
|
);
|
||||||
if (!shouldTransfer) {
|
if (!shouldTransfer) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
2
packages/cli/src/commands/env/add.ts
vendored
2
packages/cli/src/commands/env/add.ts
vendored
@@ -31,7 +31,7 @@ export default async function add(
|
|||||||
// improve the way we show inquirer prompts
|
// improve the way we show inquirer prompts
|
||||||
require('../../util/input/patch-inquirer');
|
require('../../util/input/patch-inquirer');
|
||||||
|
|
||||||
const stdInput = await readStandardInput();
|
const stdInput = await readStandardInput(client.stdin);
|
||||||
let [envName, envTargetArg, envGitBranch] = args;
|
let [envName, envTargetArg, envGitBranch] = args;
|
||||||
|
|
||||||
if (args.length > 3) {
|
if (args.length > 3) {
|
||||||
|
|||||||
1
packages/cli/src/commands/env/pull.ts
vendored
1
packages/cli/src/commands/env/pull.ts
vendored
@@ -74,6 +74,7 @@ export default async function pull(
|
|||||||
exists &&
|
exists &&
|
||||||
!skipConfirmation &&
|
!skipConfirmation &&
|
||||||
!(await confirm(
|
!(await confirm(
|
||||||
|
client,
|
||||||
`Found existing file ${param(filename)}. Do you want to overwrite?`,
|
`Found existing file ${param(filename)}. Do you want to overwrite?`,
|
||||||
false
|
false
|
||||||
))
|
))
|
||||||
|
|||||||
1
packages/cli/src/commands/env/rm.ts
vendored
1
packages/cli/src/commands/env/rm.ts
vendored
@@ -104,6 +104,7 @@ export default async function rm(
|
|||||||
if (
|
if (
|
||||||
!skipConfirmation &&
|
!skipConfirmation &&
|
||||||
!(await confirm(
|
!(await confirm(
|
||||||
|
client,
|
||||||
`Removing Environment Variable ${param(env.key)} from ${formatEnvTarget(
|
`Removing Environment Variable ${param(env.key)} from ${formatEnvTarget(
|
||||||
env
|
env
|
||||||
)} in Project ${chalk.bold(project.name)}. Are you sure?`,
|
)} in Project ${chalk.bold(project.name)}. Are you sure?`,
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export default new Map([
|
|||||||
['certs', 'certs'],
|
['certs', 'certs'],
|
||||||
['deploy', 'deploy'],
|
['deploy', 'deploy'],
|
||||||
['dev', 'dev'],
|
['dev', 'dev'],
|
||||||
|
['develop', 'dev'],
|
||||||
['dns', 'dns'],
|
['dns', 'dns'],
|
||||||
['domain', 'domains'],
|
['domain', 'domains'],
|
||||||
['domains', 'domains'],
|
['domains', 'domains'],
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ export default async function init(
|
|||||||
return extractExample(client, name, dir, force, 'v1');
|
return extractExample(client, name, dir, force, 'v1');
|
||||||
}
|
}
|
||||||
|
|
||||||
const found = await guess(exampleList, name);
|
const found = await guess(client, exampleList, name);
|
||||||
|
|
||||||
if (typeof found === 'string') {
|
if (typeof found === 'string') {
|
||||||
return extractExample(client, found, dir, force);
|
return extractExample(client, found, dir, force);
|
||||||
@@ -194,7 +194,7 @@ function prepareFolder(cwd: string, folder: string, force?: boolean) {
|
|||||||
/**
|
/**
|
||||||
* Guess which example user try to init
|
* Guess which example user try to init
|
||||||
*/
|
*/
|
||||||
async function guess(exampleList: string[], name: string) {
|
async function guess(client: Client, exampleList: string[], name: string) {
|
||||||
const GuessError = new Error(
|
const GuessError = new Error(
|
||||||
`No example found for ${chalk.bold(name)}, run ${getCommandName(
|
`No example found for ${chalk.bold(name)}, run ${getCommandName(
|
||||||
`init`
|
`init`
|
||||||
@@ -208,7 +208,7 @@ async function guess(exampleList: string[], name: string) {
|
|||||||
const found = didYouMean(name, exampleList, 0.7);
|
const found = didYouMean(name, exampleList, 0.7);
|
||||||
|
|
||||||
if (typeof found === 'string') {
|
if (typeof found === 'string') {
|
||||||
if (await promptBool(`Did you mean ${chalk.bold(found)}?`)) {
|
if (await promptBool(`Did you mean ${chalk.bold(found)}?`, client)) {
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -387,6 +387,8 @@ const main = async () => {
|
|||||||
// Shared API `Client` instance for all sub-commands to utilize
|
// Shared API `Client` instance for all sub-commands to utilize
|
||||||
client = new Client({
|
client = new Client({
|
||||||
apiUrl,
|
apiUrl,
|
||||||
|
stdin: process.stdin,
|
||||||
|
stdout: process.stdout,
|
||||||
output,
|
output,
|
||||||
config,
|
config,
|
||||||
authConfig,
|
authConfig,
|
||||||
|
|||||||
@@ -296,6 +296,15 @@ export interface Token {
|
|||||||
teamId?: string;
|
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
|
* An object representing a Build on Vercel
|
||||||
*/
|
*/
|
||||||
|
|||||||
7
packages/cli/src/util/bisect/normalize-url.ts
Normal file
7
packages/cli/src/util/bisect/normalize-url.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
function hasScheme(url: string): Boolean {
|
||||||
|
return url.startsWith('http://') || url.startsWith('https://');
|
||||||
|
}
|
||||||
|
|
||||||
|
export function normalizeURL(url: string): string {
|
||||||
|
return hasScheme(url) ? url : `https://${url}`;
|
||||||
|
}
|
||||||
@@ -385,8 +385,14 @@ export async function* findDirs(
|
|||||||
}
|
}
|
||||||
for (const path of paths) {
|
for (const path of paths) {
|
||||||
const abs = join(dir, path);
|
const abs = join(dir, path);
|
||||||
const s = await fs.stat(abs);
|
let stat: fs.Stats;
|
||||||
if (s.isDirectory()) {
|
try {
|
||||||
|
stat = await fs.lstat(abs);
|
||||||
|
} catch (err: any) {
|
||||||
|
if (err.code === 'ENOENT') continue;
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
if (stat.isDirectory()) {
|
||||||
if (path === name) {
|
if (path === name) {
|
||||||
yield relative(root, abs);
|
yield relative(root, abs);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ export interface ClientOptions {
|
|||||||
argv: string[];
|
argv: string[];
|
||||||
apiUrl: string;
|
apiUrl: string;
|
||||||
authConfig: AuthConfig;
|
authConfig: AuthConfig;
|
||||||
|
stdin: NodeJS.ReadStream;
|
||||||
|
stdout: NodeJS.WriteStream;
|
||||||
output: Output;
|
output: Output;
|
||||||
config: GlobalConfig;
|
config: GlobalConfig;
|
||||||
localConfig?: VercelConfig;
|
localConfig?: VercelConfig;
|
||||||
@@ -45,6 +47,8 @@ export default class Client extends EventEmitter {
|
|||||||
argv: string[];
|
argv: string[];
|
||||||
apiUrl: string;
|
apiUrl: string;
|
||||||
authConfig: AuthConfig;
|
authConfig: AuthConfig;
|
||||||
|
stdin: NodeJS.ReadStream;
|
||||||
|
stdout: NodeJS.WriteStream;
|
||||||
output: Output;
|
output: Output;
|
||||||
config: GlobalConfig;
|
config: GlobalConfig;
|
||||||
localConfig?: VercelConfig;
|
localConfig?: VercelConfig;
|
||||||
@@ -55,6 +59,8 @@ export default class Client extends EventEmitter {
|
|||||||
this.argv = opts.argv;
|
this.argv = opts.argv;
|
||||||
this.apiUrl = opts.apiUrl;
|
this.apiUrl = opts.apiUrl;
|
||||||
this.authConfig = opts.authConfig;
|
this.authConfig = opts.authConfig;
|
||||||
|
this.stdin = opts.stdin;
|
||||||
|
this.stdout = opts.stdout;
|
||||||
this.output = opts.output;
|
this.output = opts.output;
|
||||||
this.config = opts.config;
|
this.config = opts.config;
|
||||||
this.localConfig = opts.localConfig;
|
this.localConfig = opts.localConfig;
|
||||||
|
|||||||
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);
|
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
|
// lambda function files are trimmed of their file extension
|
||||||
const mapToEntrypoint = new Map<string, string>();
|
const mapToEntrypoint = new Map<string, string>();
|
||||||
const extensionless = devServer.getExtensionlessFile(src);
|
const extensionless = devServer.getExtensionlessFile(src);
|
||||||
|
|||||||
18
packages/cli/src/util/dev/headers.ts
Normal file
18
packages/cli/src/util/dev/headers.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { Headers } from 'node-fetch';
|
||||||
|
import { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http';
|
||||||
|
|
||||||
|
export function nodeHeadersToFetchHeaders(
|
||||||
|
nodeHeaders: IncomingHttpHeaders | OutgoingHttpHeaders
|
||||||
|
): Headers {
|
||||||
|
const headers = new Headers();
|
||||||
|
for (const [name, value] of Object.entries(nodeHeaders)) {
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
for (const val of value) {
|
||||||
|
headers.append(name, val);
|
||||||
|
}
|
||||||
|
} else if (typeof value !== 'undefined') {
|
||||||
|
headers.set(name, String(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return headers;
|
||||||
|
}
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
|
import ms from 'ms';
|
||||||
import url, { URL } from 'url';
|
import url, { URL } from 'url';
|
||||||
import http from 'http';
|
import http from 'http';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
|
import fetch from 'node-fetch';
|
||||||
import plural from 'pluralize';
|
import plural from 'pluralize';
|
||||||
import rawBody from 'raw-body';
|
import rawBody from 'raw-body';
|
||||||
import listen from 'async-listen';
|
import listen from 'async-listen';
|
||||||
import minimatch from 'minimatch';
|
import minimatch from 'minimatch';
|
||||||
import ms from 'ms';
|
|
||||||
import httpProxy from 'http-proxy';
|
import httpProxy from 'http-proxy';
|
||||||
import { randomBytes } from 'crypto';
|
import { randomBytes } from 'crypto';
|
||||||
import serveHandler from 'serve-handler';
|
import serveHandler from 'serve-handler';
|
||||||
@@ -16,11 +17,11 @@ import path, { isAbsolute, basename, dirname, extname, join } from 'path';
|
|||||||
import once from '@tootallnate/once';
|
import once from '@tootallnate/once';
|
||||||
import directoryTemplate from 'serve-handler/src/directory';
|
import directoryTemplate from 'serve-handler/src/directory';
|
||||||
import getPort from 'get-port';
|
import getPort from 'get-port';
|
||||||
import { ChildProcess } from 'child_process';
|
|
||||||
import isPortReachable from 'is-port-reachable';
|
import isPortReachable from 'is-port-reachable';
|
||||||
import deepEqual from 'fast-deep-equal';
|
import deepEqual from 'fast-deep-equal';
|
||||||
import which from 'which';
|
import which from 'which';
|
||||||
import npa from 'npm-package-arg';
|
import npa from 'npm-package-arg';
|
||||||
|
import type { ChildProcess } from 'child_process';
|
||||||
|
|
||||||
import { getVercelIgnore, fileNameSymbol } from '@vercel/client';
|
import { getVercelIgnore, fileNameSymbol } from '@vercel/client';
|
||||||
import {
|
import {
|
||||||
@@ -90,6 +91,7 @@ import {
|
|||||||
import { ProjectEnvVariable, ProjectSettings } from '../../types';
|
import { ProjectEnvVariable, ProjectSettings } from '../../types';
|
||||||
import exposeSystemEnvs from './expose-system-envs';
|
import exposeSystemEnvs from './expose-system-envs';
|
||||||
import { treeKill } from '../tree-kill';
|
import { treeKill } from '../tree-kill';
|
||||||
|
import { nodeHeadersToFetchHeaders } from './headers';
|
||||||
|
|
||||||
const frontendRuntimeSet = new Set(
|
const frontendRuntimeSet = new Set(
|
||||||
frameworkList.map(f => f.useRuntime?.use || '@vercel/static-build')
|
frameworkList.map(f => f.useRuntime?.use || '@vercel/static-build')
|
||||||
@@ -327,6 +329,8 @@ export default class DevServer {
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const name = relative(this.cwd, fsPath);
|
const name = relative(this.cwd, fsPath);
|
||||||
try {
|
try {
|
||||||
|
await this.getVercelConfig();
|
||||||
|
|
||||||
this.files[name] = await FileFsRef.fromFsPath({ fsPath });
|
this.files[name] = await FileFsRef.fromFsPath({ fsPath });
|
||||||
const extensionless = this.getExtensionlessFile(name);
|
const extensionless = this.getExtensionlessFile(name);
|
||||||
if (extensionless) {
|
if (extensionless) {
|
||||||
@@ -593,7 +597,7 @@ export default class DevServer {
|
|||||||
await this.exit();
|
await this.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (warnings && warnings.length > 0) {
|
if (warnings?.length > 0) {
|
||||||
warnings.forEach(warning =>
|
warnings.forEach(warning =>
|
||||||
this.output.warn(warning.message, null, warning.link, warning.action)
|
this.output.warn(warning.message, null, warning.link, warning.action)
|
||||||
);
|
);
|
||||||
@@ -1106,6 +1110,7 @@ export default class DevServer {
|
|||||||
view = errorTemplate({
|
view = errorTemplate({
|
||||||
http_status_code: statusCode,
|
http_status_code: statusCode,
|
||||||
http_status_description,
|
http_status_description,
|
||||||
|
error_code,
|
||||||
request_id: requestId,
|
request_id: requestId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1337,32 +1342,6 @@ export default class DevServer {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
runDevMiddleware = async (
|
|
||||||
req: http.IncomingMessage,
|
|
||||||
res: http.ServerResponse
|
|
||||||
) => {
|
|
||||||
const { devMiddlewarePlugins } = await loadCliPlugins(
|
|
||||||
this.cwd,
|
|
||||||
this.output
|
|
||||||
);
|
|
||||||
try {
|
|
||||||
for (let plugin of devMiddlewarePlugins) {
|
|
||||||
const result = await plugin.plugin.runDevMiddleware(req, res, this.cwd);
|
|
||||||
if (result.finished) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return { finished: false };
|
|
||||||
} catch (e) {
|
|
||||||
return {
|
|
||||||
finished: true,
|
|
||||||
error: e,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serve project directory as a v2 deployment.
|
* Serve project directory as a v2 deployment.
|
||||||
*/
|
*/
|
||||||
@@ -1429,13 +1408,143 @@ export default class DevServer {
|
|||||||
let statusCode: number | undefined;
|
let statusCode: number | undefined;
|
||||||
let prevUrl = req.url;
|
let prevUrl = req.url;
|
||||||
let prevHeaders: HttpHeadersConfig = {};
|
let prevHeaders: HttpHeadersConfig = {};
|
||||||
|
let middlewarePid: number | undefined;
|
||||||
|
|
||||||
/*
|
// Run the middleware file, if present, and apply any
|
||||||
const middlewareResult = await this.runDevMiddleware(req, res);
|
// mutations to the incoming request based on the
|
||||||
|
// result of the middleware invocation.
|
||||||
|
const middleware = [...this.buildMatches.values()].find(
|
||||||
|
m => m.config?.middleware === true
|
||||||
|
);
|
||||||
|
if (middleware) {
|
||||||
|
let startMiddlewareResult: StartDevServerResult | undefined;
|
||||||
|
// TODO: can we add some caching to prevent (re-)starting
|
||||||
|
// the middleware server for every HTTP request?
|
||||||
|
const { envConfigs, files, devCacheDir, cwd: workPath } = this;
|
||||||
|
try {
|
||||||
|
startMiddlewareResult =
|
||||||
|
await middleware.builderWithPkg.builder.startDevServer?.({
|
||||||
|
files,
|
||||||
|
entrypoint: middleware.entrypoint,
|
||||||
|
workPath,
|
||||||
|
repoRootPath: this.cwd,
|
||||||
|
config: middleware.config || {},
|
||||||
|
meta: {
|
||||||
|
isDev: true,
|
||||||
|
devCacheDir,
|
||||||
|
requestUrl: req.url,
|
||||||
|
env: { ...envConfigs.runEnv },
|
||||||
|
buildEnv: { ...envConfigs.buildEnv },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
if (middlewareResult) {
|
if (startMiddlewareResult) {
|
||||||
if (middlewareResult.error) {
|
const { port, pid } = startMiddlewareResult;
|
||||||
this.sendError(
|
middlewarePid = pid;
|
||||||
|
this.devServerPids.add(pid);
|
||||||
|
|
||||||
|
const middlewareReqHeaders = nodeHeadersToFetchHeaders(req.headers);
|
||||||
|
|
||||||
|
// Add the Vercel platform proxy request headers
|
||||||
|
const proxyHeaders = this.getProxyHeaders(req, requestId, true);
|
||||||
|
for (const [name, value] of nodeHeadersToFetchHeaders(proxyHeaders)) {
|
||||||
|
middlewareReqHeaders.set(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
const middlewareRes = await fetch(
|
||||||
|
`http://127.0.0.1:${port}${parsed.path}`,
|
||||||
|
{
|
||||||
|
headers: middlewareReqHeaders,
|
||||||
|
method: req.method,
|
||||||
|
redirect: 'manual',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (middlewareRes.status === 500) {
|
||||||
|
await this.sendError(
|
||||||
|
req,
|
||||||
|
res,
|
||||||
|
requestId,
|
||||||
|
'EDGE_FUNCTION_INVOCATION_FAILED',
|
||||||
|
500
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply status code from middleware invocation,
|
||||||
|
// for i.e. redirects or a custom 404 page
|
||||||
|
res.statusCode = middlewareRes.status;
|
||||||
|
|
||||||
|
let rewritePath = '';
|
||||||
|
let contentType = '';
|
||||||
|
let shouldContinue = false;
|
||||||
|
const skipMiddlewareHeaders = new Set([
|
||||||
|
'date',
|
||||||
|
'connection',
|
||||||
|
'content-length',
|
||||||
|
'transfer-encoding',
|
||||||
|
]);
|
||||||
|
for (const [name, value] of middlewareRes.headers) {
|
||||||
|
if (name === 'x-middleware-next') {
|
||||||
|
shouldContinue = value === '1';
|
||||||
|
} else if (name === 'x-middleware-rewrite') {
|
||||||
|
rewritePath = value;
|
||||||
|
shouldContinue = true;
|
||||||
|
} else if (name === 'content-type') {
|
||||||
|
contentType = value;
|
||||||
|
} else if (!skipMiddlewareHeaders.has(name)) {
|
||||||
|
// Any other kind of response header should be included
|
||||||
|
// on both the incoming HTTP request (for when proxying
|
||||||
|
// to another function) and the outgoing HTTP response.
|
||||||
|
res.setHeader(name, value);
|
||||||
|
req.headers[name] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!shouldContinue) {
|
||||||
|
const middlewareBody = await middlewareRes.buffer();
|
||||||
|
this.setResponseHeaders(res, requestId);
|
||||||
|
if (middlewareBody.length > 0) {
|
||||||
|
res.setHeader('content-length', middlewareBody.length);
|
||||||
|
if (contentType) {
|
||||||
|
res.setHeader('content-type', contentType);
|
||||||
|
}
|
||||||
|
res.end(middlewareBody);
|
||||||
|
} else {
|
||||||
|
res.end();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rewritePath) {
|
||||||
|
// TODO: add validation?
|
||||||
|
debug(`Detected rewrite path from middleware: "${rewritePath}"`);
|
||||||
|
prevUrl = rewritePath;
|
||||||
|
|
||||||
|
// Retain orginal pathname, but override query parameters from the rewrite
|
||||||
|
const beforeRewriteUrl = req.url || '/';
|
||||||
|
const rewriteUrlParsed = url.parse(beforeRewriteUrl, true);
|
||||||
|
delete rewriteUrlParsed.search;
|
||||||
|
rewriteUrlParsed.query = url.parse(rewritePath, true).query;
|
||||||
|
req.url = url.format(rewriteUrlParsed);
|
||||||
|
debug(
|
||||||
|
`Rewrote incoming HTTP URL from "${beforeRewriteUrl}" to "${req.url}"`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
// `startDevServer()` threw an error. Most likely this means the dev
|
||||||
|
// server process exited before sending the port information message
|
||||||
|
// (missing dependency at runtime, for example).
|
||||||
|
if (err.code === 'ENOENT') {
|
||||||
|
err.message = `Command not found: ${chalk.cyan(
|
||||||
|
err.path,
|
||||||
|
...err.spawnargs
|
||||||
|
)}\nPlease ensure that ${cmd(err.path)} is properly installed`;
|
||||||
|
err.link = 'https://vercel.link/command-not-found';
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.sendError(
|
||||||
req,
|
req,
|
||||||
res,
|
res,
|
||||||
requestId,
|
requestId,
|
||||||
@@ -1443,24 +1552,12 @@ export default class DevServer {
|
|||||||
500
|
500
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
} finally {
|
||||||
if (middlewareResult.finished) {
|
if (middlewarePid) {
|
||||||
return;
|
this.killBuilderDevServer(middlewarePid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (middlewareResult.pathname) {
|
|
||||||
const origUrl = url.parse(req.url || '/', true);
|
|
||||||
origUrl.pathname = middlewareResult.pathname;
|
|
||||||
prevUrl = url.format(origUrl);
|
|
||||||
}
|
|
||||||
if (middlewareResult.query && prevUrl) {
|
|
||||||
const origUrl = url.parse(req.url || '/', true);
|
|
||||||
delete origUrl.search;
|
|
||||||
Object.assign(origUrl.query, middlewareResult.query);
|
|
||||||
prevUrl = url.format(origUrl);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
for (const phase of phases) {
|
for (const phase of phases) {
|
||||||
statusCode = undefined;
|
statusCode = undefined;
|
||||||
@@ -1740,7 +1837,10 @@ export default class DevServer {
|
|||||||
isDev: true,
|
isDev: true,
|
||||||
requestPath,
|
requestPath,
|
||||||
devCacheDir,
|
devCacheDir,
|
||||||
env: { ...envConfigs.runEnv },
|
env: {
|
||||||
|
...envConfigs.runEnv,
|
||||||
|
VERCEL_BUILDER_DEBUG: this.output.debugEnabled ? '1' : undefined,
|
||||||
|
},
|
||||||
buildEnv: { ...envConfigs.buildEnv },
|
buildEnv: { ...envConfigs.buildEnv },
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -2185,13 +2285,7 @@ function proxyPass(
|
|||||||
`Failed to complete request to ${req.url}: ${error}`
|
`Failed to complete request to ${req.url}: ${error}`
|
||||||
);
|
);
|
||||||
if (!res.headersSent) {
|
if (!res.headersSent) {
|
||||||
devServer.sendError(
|
devServer.sendError(req, res, requestId, 'FUNCTION_INVOCATION_FAILED');
|
||||||
req,
|
|
||||||
res,
|
|
||||||
requestId,
|
|
||||||
'NO_RESPONSE_FROM_FUNCTION',
|
|
||||||
502
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -2269,11 +2363,12 @@ async function findBuildMatch(
|
|||||||
if (!isIndex(match.src)) {
|
if (!isIndex(match.src)) {
|
||||||
return match;
|
return match;
|
||||||
} else {
|
} else {
|
||||||
// if isIndex === true and ends in .html, we're done. Otherwise, keep searching
|
// If isIndex === true and ends in `.html`, we're done.
|
||||||
bestIndexMatch = match;
|
// Otherwise, keep searching.
|
||||||
if (extname(match.src) === '.html') {
|
if (extname(match.src) === '.html') {
|
||||||
return bestIndexMatch;
|
return match;
|
||||||
}
|
}
|
||||||
|
bestIndexMatch = match;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2295,6 +2390,13 @@ async function shouldServe(
|
|||||||
config,
|
config,
|
||||||
builderWithPkg: { builder },
|
builderWithPkg: { builder },
|
||||||
} = match;
|
} = match;
|
||||||
|
|
||||||
|
// "middleware" file is not served as a regular asset,
|
||||||
|
// instead it gets invoked as part of the routing logic.
|
||||||
|
if (config?.middleware === true) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const cleanSrc = src.endsWith('.html') ? src.slice(0, -5) : src;
|
const cleanSrc = src.endsWith('.html') ? src.slice(0, -5) : src;
|
||||||
const trimmedPath = requestPath.endsWith('/')
|
const trimmedPath = requestPath.endsWith('/')
|
||||||
? requestPath.slice(0, -1)
|
? requestPath.slice(0, -1)
|
||||||
@@ -2447,12 +2549,10 @@ function needsBlockingBuild(buildMatch: BuildMatch): boolean {
|
|||||||
return typeof builder.shouldServe !== 'function';
|
return typeof builder.shouldServe !== 'function';
|
||||||
}
|
}
|
||||||
|
|
||||||
async function checkForPort(
|
async function checkForPort(port: number, timeout: number): Promise<void> {
|
||||||
port: number | undefined,
|
const opts = { host: '127.0.0.1' };
|
||||||
timeout: number
|
|
||||||
): Promise<void> {
|
|
||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
while (!(await isPortReachable(port))) {
|
while (!(await isPortReachable(port, opts))) {
|
||||||
if (Date.now() - start > timeout) {
|
if (Date.now() - start > timeout) {
|
||||||
throw new Error(`Detecting port ${port} timed out after ${timeout}ms`);
|
throw new Error(`Detecting port ${port} timed out after ${timeout}ms`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,26 +2,29 @@ import chalk from 'chalk';
|
|||||||
import { DNSRecordData } from '../../types';
|
import { DNSRecordData } from '../../types';
|
||||||
import textInput from '../input/text';
|
import textInput from '../input/text';
|
||||||
import promptBool from '../input/prompt-bool';
|
import promptBool from '../input/prompt-bool';
|
||||||
import { Output } from '../output';
|
import Client from '../client';
|
||||||
|
|
||||||
const RECORD_TYPES = ['A', 'AAAA', 'ALIAS', 'CAA', 'CNAME', 'MX', 'SRV', 'TXT'];
|
const RECORD_TYPES = ['A', 'AAAA', 'ALIAS', 'CAA', 'CNAME', 'MX', 'SRV', 'TXT'];
|
||||||
|
|
||||||
export default async function getDNSData(
|
export default async function getDNSData(
|
||||||
output: Output,
|
client: Client,
|
||||||
data: null | DNSRecordData
|
data: null | DNSRecordData
|
||||||
): Promise<DNSRecordData | null> {
|
): Promise<DNSRecordData | null> {
|
||||||
if (data) {
|
if (data) {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
const { output } = client;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// first ask for type, branch from there
|
// first ask for type, branch from there
|
||||||
const possibleTypes = new Set(RECORD_TYPES);
|
const possibleTypes = new Set(RECORD_TYPES);
|
||||||
const type = (await textInput({
|
const type = (
|
||||||
label: `- Record type (${RECORD_TYPES.join(', ')}): `,
|
await textInput({
|
||||||
validateValue: (v: string) =>
|
label: `- Record type (${RECORD_TYPES.join(', ')}): `,
|
||||||
Boolean(v && possibleTypes.has(v.trim().toUpperCase()))
|
validateValue: (v: string) =>
|
||||||
}))
|
Boolean(v && possibleTypes.has(v.trim().toUpperCase())),
|
||||||
|
})
|
||||||
|
)
|
||||||
.trim()
|
.trim()
|
||||||
.toUpperCase();
|
.toUpperCase();
|
||||||
|
|
||||||
@@ -39,7 +42,7 @@ export default async function getDNSData(
|
|||||||
target
|
target
|
||||||
)}.`
|
)}.`
|
||||||
);
|
);
|
||||||
return (await verifyData())
|
return (await verifyData(client))
|
||||||
? {
|
? {
|
||||||
name,
|
name,
|
||||||
type,
|
type,
|
||||||
@@ -47,8 +50,8 @@ export default async function getDNSData(
|
|||||||
priority,
|
priority,
|
||||||
weight,
|
weight,
|
||||||
port,
|
port,
|
||||||
target
|
target,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
@@ -61,23 +64,23 @@ export default async function getDNSData(
|
|||||||
`${mxPriority}`
|
`${mxPriority}`
|
||||||
)} ${chalk.cyan(value)}`
|
)} ${chalk.cyan(value)}`
|
||||||
);
|
);
|
||||||
return (await verifyData())
|
return (await verifyData(client))
|
||||||
? {
|
? {
|
||||||
name,
|
name,
|
||||||
type,
|
type,
|
||||||
value,
|
value,
|
||||||
mxPriority
|
mxPriority,
|
||||||
}
|
}
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const value = await getTrimmedString(`- ${type} value: `);
|
const value = await getTrimmedString(`- ${type} value: `);
|
||||||
output.log(`${chalk.cyan(name)} ${chalk.bold(type)} ${chalk.cyan(value)}`);
|
output.log(`${chalk.cyan(name)} ${chalk.bold(type)} ${chalk.cyan(value)}`);
|
||||||
return (await verifyData())
|
return (await verifyData(client))
|
||||||
? {
|
? {
|
||||||
name,
|
name,
|
||||||
type,
|
type,
|
||||||
value
|
value,
|
||||||
}
|
}
|
||||||
: null;
|
: null;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -85,13 +88,13 @@ export default async function getDNSData(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function verifyData() {
|
async function verifyData(client: Client) {
|
||||||
return promptBool('Is this correct?');
|
return promptBool('Is this correct?', client);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getRecordName(type: string) {
|
async function getRecordName(type: string) {
|
||||||
const input = await textInput({
|
const input = await textInput({
|
||||||
label: `- ${type} name: `
|
label: `- ${type} name: `,
|
||||||
});
|
});
|
||||||
return input === '@' ? '' : input;
|
return input === '@' ? '' : input;
|
||||||
}
|
}
|
||||||
@@ -100,14 +103,14 @@ async function getNumber(label: string) {
|
|||||||
return Number(
|
return Number(
|
||||||
await textInput({
|
await textInput({
|
||||||
label,
|
label,
|
||||||
validateValue: v => Boolean(v && Number(v))
|
validateValue: v => Boolean(v && Number(v)),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
async function getTrimmedString(label: string) {
|
async function getTrimmedString(label: string) {
|
||||||
const res = await textInput({
|
const res = await textInput({
|
||||||
label,
|
label,
|
||||||
validateValue: v => Boolean(v && v.trim().length > 0)
|
validateValue: v => Boolean(v && v.trim().length > 0),
|
||||||
});
|
});
|
||||||
return res.trim();
|
return res.trim();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,8 @@ export default async function purchaseDomainIfAvailable(
|
|||||||
!(await promptBool(
|
!(await promptBool(
|
||||||
`Buy ${chalk.underline(domain)} for ${chalk.bold(
|
`Buy ${chalk.underline(domain)} for ${chalk.bold(
|
||||||
`$${price}`
|
`$${price}`
|
||||||
)} (${plural('yr', period, true)})?`
|
)} (${plural('yr', period, true)})?`,
|
||||||
|
client
|
||||||
))
|
))
|
||||||
) {
|
) {
|
||||||
output.print(eraseLines(1));
|
output.print(eraseLines(1));
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import { responseError } from './error';
|
|||||||
import stamp from './output/stamp';
|
import stamp from './output/stamp';
|
||||||
import { APIError, BuildError } from './errors-ts';
|
import { APIError, BuildError } from './errors-ts';
|
||||||
import printIndications from './print-indications';
|
import printIndications from './print-indications';
|
||||||
import { Org } from '../types';
|
import { GitMetadata, Org } from '../types';
|
||||||
import { VercelConfig } from './dev/types';
|
import { VercelConfig } from './dev/types';
|
||||||
import Client, { FetchOptions, isJSONObject } from './client';
|
import Client, { FetchOptions, isJSONObject } from './client';
|
||||||
import { Dictionary } from '@vercel/client';
|
import { Dictionary } from '@vercel/client';
|
||||||
@@ -38,6 +38,7 @@ export interface CreateOptions {
|
|||||||
prebuilt?: boolean;
|
prebuilt?: boolean;
|
||||||
rootDirectory?: string;
|
rootDirectory?: string;
|
||||||
meta: Dictionary<string>;
|
meta: Dictionary<string>;
|
||||||
|
gitMetadata?: GitMetadata;
|
||||||
regions?: string[];
|
regions?: string[];
|
||||||
quiet?: boolean;
|
quiet?: boolean;
|
||||||
env: Dictionary<string>;
|
env: Dictionary<string>;
|
||||||
@@ -116,6 +117,7 @@ export default class Now extends EventEmitter {
|
|||||||
rootDirectory,
|
rootDirectory,
|
||||||
wantsPublic,
|
wantsPublic,
|
||||||
meta,
|
meta,
|
||||||
|
gitMetadata,
|
||||||
regions,
|
regions,
|
||||||
quiet = false,
|
quiet = false,
|
||||||
env,
|
env,
|
||||||
@@ -142,6 +144,7 @@ export default class Now extends EventEmitter {
|
|||||||
name,
|
name,
|
||||||
project,
|
project,
|
||||||
meta,
|
meta,
|
||||||
|
gitMetadata,
|
||||||
regions,
|
regions,
|
||||||
target: target || undefined,
|
target: target || undefined,
|
||||||
projectSettings,
|
projectSettings,
|
||||||
|
|||||||
@@ -1,12 +1,19 @@
|
|||||||
import inquirer from 'inquirer';
|
import inquirer from 'inquirer';
|
||||||
|
import Client from '../client';
|
||||||
|
|
||||||
export default async function confirm(
|
export default async function confirm(
|
||||||
|
client: Client,
|
||||||
message: string,
|
message: string,
|
||||||
preferred: boolean
|
preferred: boolean
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
require('./patch-inquirer');
|
require('./patch-inquirer');
|
||||||
|
|
||||||
const answers = await inquirer.prompt({
|
const prompt = inquirer.createPromptModule({
|
||||||
|
input: client.stdin,
|
||||||
|
output: client.stdout,
|
||||||
|
});
|
||||||
|
|
||||||
|
const answers = await prompt({
|
||||||
type: 'confirm',
|
type: 'confirm',
|
||||||
name: 'value',
|
name: 'value',
|
||||||
message,
|
message,
|
||||||
|
|||||||
@@ -1,38 +1,83 @@
|
|||||||
import inquirer from 'inquirer';
|
import inquirer from 'inquirer';
|
||||||
import confirm from './confirm';
|
import confirm from './confirm';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import { Output } from '../output';
|
import frameworkList, { Framework } from '@vercel/frameworks';
|
||||||
import { Framework } from '@vercel/frameworks';
|
import Client from '../client';
|
||||||
import { isSettingValue } from '../is-setting-value';
|
import { isSettingValue } from '../is-setting-value';
|
||||||
import { ProjectSettings } from '../../types';
|
import { ProjectSettings } from '../../types';
|
||||||
|
|
||||||
export interface PartialProjectSettings {
|
const settingMap = {
|
||||||
buildCommand: string | null;
|
buildCommand: 'Build Command',
|
||||||
outputDirectory: string | null;
|
devCommand: 'Development Command',
|
||||||
devCommand: string | null;
|
commandForIgnoringBuildStep: 'Ignore Command',
|
||||||
}
|
installCommand: 'Install Command',
|
||||||
|
outputDirectory: 'Output Directory',
|
||||||
const fields: { name: string; value: keyof PartialProjectSettings }[] = [
|
framework: 'Framework',
|
||||||
{ name: 'Build Command', value: 'buildCommand' },
|
} as const;
|
||||||
{ name: 'Output Directory', value: 'outputDirectory' },
|
type ConfigKeys = keyof typeof settingMap;
|
||||||
{ name: 'Development Command', value: 'devCommand' },
|
const settingKeys = Object.keys(settingMap).sort() as unknown as readonly [
|
||||||
|
ConfigKeys
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export type PartialProjectSettings = Pick<ProjectSettings, ConfigKeys>;
|
||||||
|
|
||||||
export default async function editProjectSettings(
|
export default async function editProjectSettings(
|
||||||
output: Output,
|
client: Client,
|
||||||
projectSettings: PartialProjectSettings | null,
|
projectSettings: PartialProjectSettings | null,
|
||||||
framework: Framework | null,
|
framework: Framework | null,
|
||||||
autoConfirm?: boolean
|
autoConfirm: boolean,
|
||||||
|
localConfigurationOverrides: PartialProjectSettings | null
|
||||||
): Promise<ProjectSettings> {
|
): Promise<ProjectSettings> {
|
||||||
// create new settings object, missing values will be filled with `null`
|
const { output } = client;
|
||||||
|
|
||||||
|
// Create initial settings object defaulting everything to `null` and assigning what may exist in `projectSettings`
|
||||||
const settings: ProjectSettings = Object.assign(
|
const settings: ProjectSettings = Object.assign(
|
||||||
{ framework: null },
|
{
|
||||||
|
buildCommand: null,
|
||||||
|
devCommand: null,
|
||||||
|
framework: null,
|
||||||
|
commandForIgnoringBuildStep: null,
|
||||||
|
installCommand: null,
|
||||||
|
outputDirectory: null,
|
||||||
|
},
|
||||||
projectSettings
|
projectSettings
|
||||||
);
|
);
|
||||||
|
|
||||||
for (let field of fields) {
|
// Start UX by displaying (and applying) overrides. They will be referenced throughout remainder of CLI.
|
||||||
settings[field.value] =
|
if (localConfigurationOverrides) {
|
||||||
(projectSettings && projectSettings[field.value]) || null;
|
// 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
|
// skip editing project settings if no framework is detected
|
||||||
@@ -41,6 +86,7 @@ export default async function editProjectSettings(
|
|||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A missing framework slug implies the "Other" framework was selected
|
||||||
output.print(
|
output.print(
|
||||||
!framework.slug
|
!framework.slug
|
||||||
? `No framework detected. Default Project Settings:\n`
|
? `No framework detected. Default Project Settings:\n`
|
||||||
@@ -49,44 +95,78 @@ export default async function editProjectSettings(
|
|||||||
|
|
||||||
settings.framework = framework.slug;
|
settings.framework = framework.slug;
|
||||||
|
|
||||||
for (let field of fields) {
|
// Now print defaults for the provided framework whether it was auto-detected or overwritten
|
||||||
const defaults = framework.settings[field.value];
|
for (const setting of settingKeys) {
|
||||||
|
if (setting === 'framework' || setting === 'commandForIgnoringBuildStep') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
output.print(
|
const defaultSetting = framework.settings[setting];
|
||||||
chalk.dim(
|
const override = localConfigurationOverrides?.[setting];
|
||||||
`- ${chalk.bold(`${field.name}:`)} ${`${
|
|
||||||
isSettingValue(defaults)
|
if (!override && defaultSetting) {
|
||||||
? defaults.value
|
output.print(
|
||||||
: chalk.italic(`${defaults.placeholder}`)
|
`${chalk.dim(
|
||||||
}`}`
|
`- ${chalk.bold(`${settingMap[setting]}:`)} ${
|
||||||
) + '\n'
|
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 (
|
if (
|
||||||
autoConfirm ||
|
autoConfirm ||
|
||||||
!(await confirm(`Want to override the settings?`, false))
|
!(await confirm(client, 'Want to modify these settings?', false))
|
||||||
) {
|
) {
|
||||||
return settings;
|
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',
|
name: 'settingFields',
|
||||||
type: 'checkbox',
|
type: 'checkbox',
|
||||||
message: 'Which settings would you like to overwrite (select multiple)?',
|
message: 'Which settings would you like to overwrite (select multiple)?',
|
||||||
choices: fields,
|
choices,
|
||||||
});
|
});
|
||||||
|
|
||||||
for (let setting of settingFields as (keyof PartialProjectSettings)[]) {
|
for (let setting of settingFields) {
|
||||||
const field = fields.find(f => f.value === setting);
|
const field = settingMap[setting];
|
||||||
const name = `${Date.now()}`;
|
const answers = await inquirer.prompt<{
|
||||||
const answers = await inquirer.prompt({
|
[k in Exclude<
|
||||||
|
ConfigKeys,
|
||||||
|
'framework' | 'commandForIgnoringBuildStep' | 'installCommand'
|
||||||
|
>]: string;
|
||||||
|
}>({
|
||||||
type: 'input',
|
type: 'input',
|
||||||
name: name,
|
name: setting,
|
||||||
message: `What's your ${chalk.bold(field ? field.name : setting)}?`,
|
message: `What's your ${chalk.bold(field)}?`,
|
||||||
});
|
});
|
||||||
settings[setting] = answers[name] as string;
|
settings[setting] = answers[setting];
|
||||||
}
|
}
|
||||||
|
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,11 +47,16 @@ export default async function inputProject(
|
|||||||
|
|
||||||
if (!detectedProject) {
|
if (!detectedProject) {
|
||||||
// did not auto-detect a project to link
|
// did not auto-detect a project to link
|
||||||
shouldLinkProject = await confirm(`Link to existing project?`, false);
|
shouldLinkProject = await confirm(
|
||||||
|
client,
|
||||||
|
`Link to existing project?`,
|
||||||
|
false
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
// auto-detected a project to link
|
// auto-detected a project to link
|
||||||
if (
|
if (
|
||||||
await confirm(
|
await confirm(
|
||||||
|
client,
|
||||||
`Found project ${chalk.cyan(
|
`Found project ${chalk.cyan(
|
||||||
`“${org.slug}/${detectedProject.name}”`
|
`“${org.slug}/${detectedProject.name}”`
|
||||||
)}. Link to it?`,
|
)}. Link to it?`,
|
||||||
@@ -63,6 +68,7 @@ export default async function inputProject(
|
|||||||
|
|
||||||
// user doesn't want to link the auto-detected project
|
// user doesn't want to link the auto-detected project
|
||||||
shouldLinkProject = await confirm(
|
shouldLinkProject = await confirm(
|
||||||
|
client,
|
||||||
`Link to different existing project?`,
|
`Link to different existing project?`,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
@@ -73,7 +79,11 @@ export default async function inputProject(
|
|||||||
let project: Project | ProjectNotFound | null = null;
|
let project: Project | ProjectNotFound | null = null;
|
||||||
|
|
||||||
while (!project || project instanceof ProjectNotFound) {
|
while (!project || project instanceof ProjectNotFound) {
|
||||||
const answers = await inquirer.prompt({
|
const prompt = inquirer.createPromptModule({
|
||||||
|
input: client.stdin,
|
||||||
|
output: client.stdout,
|
||||||
|
});
|
||||||
|
const answers = await prompt({
|
||||||
type: 'input',
|
type: 'input',
|
||||||
name: 'existingProjectName',
|
name: 'existingProjectName',
|
||||||
message: `What’s the name of your existing project?`,
|
message: `What’s the name of your existing project?`,
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import inquirer from 'inquirer';
|
import inquirer from 'inquirer';
|
||||||
import { Output } from '../output';
|
|
||||||
import { validateRootDirectory } from '../validate-paths';
|
import { validateRootDirectory } from '../validate-paths';
|
||||||
|
import Client from '../client';
|
||||||
|
|
||||||
export async function inputRootDirectory(
|
export async function inputRootDirectory(
|
||||||
|
client: Client,
|
||||||
cwd: string,
|
cwd: string,
|
||||||
output: Output,
|
|
||||||
autoConfirm = false
|
autoConfirm = false
|
||||||
) {
|
) {
|
||||||
if (autoConfirm) {
|
if (autoConfirm) {
|
||||||
@@ -15,7 +15,11 @@ export async function inputRootDirectory(
|
|||||||
|
|
||||||
// eslint-disable-next-line no-constant-condition
|
// eslint-disable-next-line no-constant-condition
|
||||||
while (true) {
|
while (true) {
|
||||||
const { rootDirectory } = await inquirer.prompt({
|
const prompt = inquirer.createPromptModule({
|
||||||
|
input: client.stdin,
|
||||||
|
output: client.stdout,
|
||||||
|
});
|
||||||
|
const { rootDirectory } = await prompt({
|
||||||
type: 'input',
|
type: 'input',
|
||||||
name: 'rootDirectory',
|
name: 'rootDirectory',
|
||||||
message: `In which directory is your code located?`,
|
message: `In which directory is your code located?`,
|
||||||
@@ -38,7 +42,7 @@ export async function inputRootDirectory(
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
(await validateRootDirectory(
|
(await validateRootDirectory(
|
||||||
output,
|
client.output,
|
||||||
cwd,
|
cwd,
|
||||||
fullPath,
|
fullPath,
|
||||||
'Please choose a different one.'
|
'Please choose a different one.'
|
||||||
|
|||||||
@@ -5,21 +5,21 @@ type Options = {
|
|||||||
defaultValue?: boolean;
|
defaultValue?: boolean;
|
||||||
noChar?: string;
|
noChar?: string;
|
||||||
resolveChars?: Set<string>;
|
resolveChars?: Set<string>;
|
||||||
stdin?: NodeJS.ReadStream;
|
stdin: NodeJS.ReadStream;
|
||||||
stdout?: NodeJS.WriteStream;
|
stdout: NodeJS.WriteStream;
|
||||||
trailing?: string;
|
trailing?: string;
|
||||||
yesChar?: string;
|
yesChar?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function promptBool(label: string, options: Options = {}) {
|
export default async function promptBool(label: string, options: Options) {
|
||||||
const {
|
const {
|
||||||
|
stdin,
|
||||||
|
stdout,
|
||||||
defaultValue = false,
|
defaultValue = false,
|
||||||
abortSequences = new Set(['\u0003']),
|
abortSequences = new Set(['\u0003']),
|
||||||
resolveChars = new Set(['\r']),
|
resolveChars = new Set(['\r']),
|
||||||
yesChar = 'y',
|
yesChar = 'y',
|
||||||
noChar = 'n',
|
noChar = 'n',
|
||||||
stdin = process.stdin,
|
|
||||||
stdout = process.stdout,
|
|
||||||
trailing = '',
|
trailing = '',
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
export default async function readStandardInput(): Promise<string> {
|
export default async function readStandardInput(
|
||||||
|
stdin: NodeJS.ReadStream
|
||||||
|
): Promise<string> {
|
||||||
return new Promise<string>(resolve => {
|
return new Promise<string>(resolve => {
|
||||||
setTimeout(() => resolve(''), 500);
|
setTimeout(() => resolve(''), 500);
|
||||||
|
|
||||||
if (process.stdin.isTTY) {
|
if (stdin.isTTY) {
|
||||||
// found tty so we know there is nothing piped to stdin
|
// found tty so we know there is nothing piped to stdin
|
||||||
resolve('');
|
resolve('');
|
||||||
} else {
|
} else {
|
||||||
process.stdin.setEncoding('utf8');
|
stdin.setEncoding('utf8');
|
||||||
process.stdin.once('data', resolve);
|
stdin.once('data', resolve);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user