mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-12 12:57:47 +00:00
Compare commits
12 Commits
@now/pytho
...
@now/pytho
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e293dd633 | ||
|
|
e040753b27 | ||
|
|
463aaf094d | ||
|
|
bf867b028d | ||
|
|
6dfefc2fe4 | ||
|
|
9ba8a8454c | ||
|
|
9c72839bfa | ||
|
|
2e24c92799 | ||
|
|
fa98c8aeeb | ||
|
|
f92e3496b1 | ||
|
|
0ceea76aa4 | ||
|
|
897d11a1e1 |
@@ -6,6 +6,10 @@ const REDIRECT_FILE_NAME = '__now_routes_g4t5bY.json';
|
|||||||
exports.onPostBuild = async ({ store }) => {
|
exports.onPostBuild = async ({ store }) => {
|
||||||
const { redirects, program } = store.getState();
|
const { redirects, program } = store.getState();
|
||||||
|
|
||||||
|
if (!redirects.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const routes = [{ handle: 'filesystem' }];
|
const routes = [{ handle: 'filesystem' }];
|
||||||
|
|
||||||
for (const redirect of redirects) {
|
for (const redirect of redirects) {
|
||||||
@@ -22,30 +26,8 @@ exports.onPostBuild = async ({ store }) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// we implement gatsby's recommendations
|
|
||||||
// https://www.gatsbyjs.org/docs/caching/
|
|
||||||
const finalRoutes = [
|
|
||||||
{
|
|
||||||
src: '^/static/(.*)$',
|
|
||||||
headers: { 'cache-control': 'public,max-age=31536000,immutable' },
|
|
||||||
continue: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
src: '^/.*\\.(js|css)$',
|
|
||||||
headers: { 'cache-control': 'public,max-age=31536000,immutable' },
|
|
||||||
continue: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
src: '^/(sw\\.js|app-data\\.json|.*\\.html|page-data/.*)$',
|
|
||||||
headers: { 'cache-control': 'public,max-age=0,must-revalidate' },
|
|
||||||
continue: true,
|
|
||||||
},
|
|
||||||
...routes,
|
|
||||||
{ src: '.*', status: 404, dest: '/404.html' },
|
|
||||||
];
|
|
||||||
|
|
||||||
await writeFile(
|
await writeFile(
|
||||||
path.join(program.directory, 'public', REDIRECT_FILE_NAME),
|
path.join(program.directory, 'public', REDIRECT_FILE_NAME),
|
||||||
JSON.stringify(finalRoutes)
|
JSON.stringify(routes)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "gatsby-plugin-now",
|
"name": "gatsby-plugin-now",
|
||||||
"version": "1.2.3",
|
"version": "1.2.6-canary.0",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"homepage": "https://zeit.co/guides/deploying-gatsby-with-now",
|
"homepage": "https://zeit.co/guides/deploying-gatsby-with-now",
|
||||||
|
|||||||
@@ -1,7 +1,24 @@
|
|||||||
# gatsby-plugin-now
|
# gatsby-plugin-now
|
||||||
|
|
||||||
⚠️ The use of this plugin is deprecated. ZEIT Now supports Gatsby Redirects out-of-the-box and does not require the use a plugin.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
This plugin generates [Now Routes](https://zeit.co/docs/v2/advanced/routes) for [redirects](https://www.gatsbyjs.org/docs/actions/#createRedirect) you configured for to your Gatsby project.
|
This plugin generates [Now Routes](https://zeit.co/docs/v2/advanced/routes) for [redirects](https://www.gatsbyjs.org/docs/actions/#createRedirect) you configured for to your Gatsby project.
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
|
||||||
|
1. Install the plugin:
|
||||||
|
|
||||||
|
```
|
||||||
|
npm install gatsby-plugin-now --save-dev
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Add it to the configuration file:
|
||||||
|
|
||||||
|
```
|
||||||
|
// gatsby-config.js
|
||||||
|
module.exports = {
|
||||||
|
plugins: [
|
||||||
|
'gatsby-plugin-now'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
3. [Deploy your project to ZEIT Now](https://www.gatsbyjs.org/docs/deploying-to-zeit-now/)
|
||||||
|
|||||||
@@ -2,27 +2,6 @@
|
|||||||
|
|
||||||
exports[`test generated now routes 1`] = `
|
exports[`test generated now routes 1`] = `
|
||||||
Array [
|
Array [
|
||||||
Object {
|
|
||||||
"continue": true,
|
|
||||||
"headers": Object {
|
|
||||||
"cache-control": "public,max-age=31536000,immutable",
|
|
||||||
},
|
|
||||||
"src": "^/static/(.*)$",
|
|
||||||
},
|
|
||||||
Object {
|
|
||||||
"continue": true,
|
|
||||||
"headers": Object {
|
|
||||||
"cache-control": "public,max-age=31536000,immutable",
|
|
||||||
},
|
|
||||||
"src": "^/.*\\\\.(js|css)$",
|
|
||||||
},
|
|
||||||
Object {
|
|
||||||
"continue": true,
|
|
||||||
"headers": Object {
|
|
||||||
"cache-control": "public,max-age=0,must-revalidate",
|
|
||||||
},
|
|
||||||
"src": "^/(sw\\\\.js|app-data\\\\.json|.*\\\\.html|page-data/.*)$",
|
|
||||||
},
|
|
||||||
Object {
|
Object {
|
||||||
"headers": Object {
|
"headers": Object {
|
||||||
"Location": "/",
|
"Location": "/",
|
||||||
@@ -103,10 +82,5 @@ Array [
|
|||||||
"src": "/randorect",
|
"src": "/randorect",
|
||||||
"status": 302,
|
"status": 302,
|
||||||
},
|
},
|
||||||
Object {
|
|
||||||
"dest": "/404.html",
|
|
||||||
"src": ".*",
|
|
||||||
"status": 404,
|
|
||||||
},
|
|
||||||
]
|
]
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/build-utils",
|
"name": "@now/build-utils",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1-canary.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"types": "./dist/index.d.js",
|
"types": "./dist/index.d.js",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/cgi",
|
"name": "@now/cgi",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1-canary.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "now",
|
"name": "now",
|
||||||
"version": "16.5.0",
|
"version": "16.5.3-canary.0",
|
||||||
"preferGlobal": true,
|
"preferGlobal": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"description": "The command-line interface for Now",
|
"description": "The command-line interface for Now",
|
||||||
|
|||||||
@@ -141,6 +141,7 @@ export default class DevServer {
|
|||||||
|
|
||||||
this.cachedNowConfig = null;
|
this.cachedNowConfig = null;
|
||||||
this.server = http.createServer(this.devServerHandler);
|
this.server = http.createServer(this.devServerHandler);
|
||||||
|
this.server.timeout = 0; // Disable timeout
|
||||||
this.serverUrlPrinted = false;
|
this.serverUrlPrinted = false;
|
||||||
this.stopping = false;
|
this.stopping = false;
|
||||||
this.buildMatches = new Map();
|
this.buildMatches = new Map();
|
||||||
|
|||||||
@@ -366,10 +366,8 @@ CMD ["node", "index.js"]`,
|
|||||||
},
|
},
|
||||||
'lambda-with-128-memory': {
|
'lambda-with-128-memory': {
|
||||||
'api/memory.js': `
|
'api/memory.js': `
|
||||||
const os = require('os');
|
|
||||||
|
|
||||||
module.exports = (req, res) => {
|
module.exports = (req, res) => {
|
||||||
res.json({ memory: os.totalmem() });
|
res.json({ memory: parseInt(process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE) });
|
||||||
};
|
};
|
||||||
`,
|
`,
|
||||||
'now.json': JSON.stringify({
|
'now.json': JSON.stringify({
|
||||||
@@ -382,10 +380,8 @@ CMD ["node", "index.js"]`,
|
|||||||
},
|
},
|
||||||
'lambda-with-200-memory': {
|
'lambda-with-200-memory': {
|
||||||
'api/memory.js': `
|
'api/memory.js': `
|
||||||
const os = require('os');
|
|
||||||
|
|
||||||
module.exports = (req, res) => {
|
module.exports = (req, res) => {
|
||||||
res.json({ memory: os.totalmem() });
|
res.json({ memory: parseInt(process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE) });
|
||||||
};
|
};
|
||||||
`,
|
`,
|
||||||
'now.json': JSON.stringify({
|
'now.json': JSON.stringify({
|
||||||
|
|||||||
10
packages/now-cli/test/integration.js
vendored
10
packages/now-cli/test/integration.js
vendored
@@ -1828,6 +1828,7 @@ test('create zero-config deployment', async t => {
|
|||||||
const fixturePath = fixture('zero-config-next-js');
|
const fixturePath = fixture('zero-config-next-js');
|
||||||
const output = await execute([fixturePath, '--force', '--public']);
|
const output = await execute([fixturePath, '--force', '--public']);
|
||||||
|
|
||||||
|
console.log('isCanary', isCanary);
|
||||||
console.log(output.stderr);
|
console.log(output.stderr);
|
||||||
console.log(output.stdout);
|
console.log(output.stdout);
|
||||||
console.log(output.exitCode);
|
console.log(output.exitCode);
|
||||||
@@ -1848,7 +1849,10 @@ test('create zero-config deployment', async t => {
|
|||||||
isCanary ? build.use.endsWith('@canary') : !build.use.endsWith('@canary')
|
isCanary ? build.use.endsWith('@canary') : !build.use.endsWith('@canary')
|
||||||
);
|
);
|
||||||
|
|
||||||
t.true(validBuilders, JSON.stringify(data, null, 2));
|
t.true(
|
||||||
|
validBuilders,
|
||||||
|
'Builders are not valid: ' + JSON.stringify(data, null, 2)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('now secret add', async t => {
|
test('now secret add', async t => {
|
||||||
@@ -1955,7 +1959,7 @@ test('deploy a Lambda with 128MB of memory', async t => {
|
|||||||
// It won't be exactly 128MB,
|
// It won't be exactly 128MB,
|
||||||
// so we just compare if it is lower than 450MB
|
// so we just compare if it is lower than 450MB
|
||||||
const { memory } = await response.json();
|
const { memory } = await response.json();
|
||||||
t.truthy(memory < 4.5e8, `Lambda has ${memory} bytes of memory`);
|
t.is(memory, 128, `Lambda has ${memory} bytes of memory`);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('fail to deploy a Lambda with an incorrect value for of memory', async t => {
|
test('fail to deploy a Lambda with an incorrect value for of memory', async t => {
|
||||||
@@ -2020,7 +2024,7 @@ test('fail to deploy a Lambda with a specific runtime but without a locked versi
|
|||||||
t.is(output.exitCode, 1, formatOutput(output));
|
t.is(output.exitCode, 1, formatOutput(output));
|
||||||
t.regex(
|
t.regex(
|
||||||
output.stderr,
|
output.stderr,
|
||||||
/Function runtimes must have a valid version/gm,
|
/Function Runtimes must have a valid version/gim,
|
||||||
formatOutput(output)
|
formatOutput(output)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "now-client",
|
"name": "now-client",
|
||||||
"version": "5.2.3",
|
"version": "5.2.4-canary.0",
|
||||||
"main": "dist/src/index.js",
|
"main": "dist/src/index.js",
|
||||||
"typings": "dist/src/index.d.ts",
|
"typings": "dist/src/index.d.ts",
|
||||||
"homepage": "https://zeit.co",
|
"homepage": "https://zeit.co",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/go",
|
"name": "@now/go",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1-canary.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./dist/index",
|
"main": "./dist/index",
|
||||||
"homepage": "https://zeit.co/docs/runtimes#official-runtimes/go",
|
"homepage": "https://zeit.co/docs/runtimes#official-runtimes/go",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/next",
|
"name": "@now/next",
|
||||||
"version": "1.0.5",
|
"version": "1.0.6-canary.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./dist/index",
|
"main": "./dist/index",
|
||||||
"homepage": "https://zeit.co/docs/runtimes#official-runtimes/next-js",
|
"homepage": "https://zeit.co/docs/runtimes#official-runtimes/next-js",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/node-bridge",
|
"name": "@now/node-bridge",
|
||||||
"version": "1.2.6",
|
"version": "1.2.7-canary.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./index.js",
|
"main": "./index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
Server,
|
Server,
|
||||||
IncomingHttpHeaders,
|
IncomingHttpHeaders,
|
||||||
OutgoingHttpHeaders,
|
OutgoingHttpHeaders,
|
||||||
request
|
request,
|
||||||
} from 'http';
|
} from 'http';
|
||||||
|
|
||||||
interface NowProxyEvent {
|
interface NowProxyEvent {
|
||||||
@@ -29,6 +29,7 @@ export interface NowProxyResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface ServerLike {
|
interface ServerLike {
|
||||||
|
timeout?: number;
|
||||||
listen: (
|
listen: (
|
||||||
opts: {
|
opts: {
|
||||||
host?: string;
|
host?: string;
|
||||||
@@ -132,16 +133,21 @@ export class Bridge {
|
|||||||
}
|
}
|
||||||
|
|
||||||
listen() {
|
listen() {
|
||||||
if (!this.server) {
|
const { server, resolveListening } = this;
|
||||||
|
if (!server) {
|
||||||
throw new Error('Server has not been set!');
|
throw new Error('Server has not been set!');
|
||||||
}
|
}
|
||||||
|
|
||||||
const resolveListening = this.resolveListening;
|
if (typeof server.timeout === 'number' && server.timeout > 0) {
|
||||||
|
// Disable timeout (usually 2 minutes until Node 13).
|
||||||
|
// Instead, user should assign function `maxDuration`.
|
||||||
|
server.timeout = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return this.server.listen(
|
return server.listen(
|
||||||
{
|
{
|
||||||
host: '127.0.0.1',
|
host: '127.0.0.1',
|
||||||
port: 0
|
port: 0,
|
||||||
},
|
},
|
||||||
function listeningCallback() {
|
function listeningCallback() {
|
||||||
if (!this || typeof this.address !== 'function') {
|
if (!this || typeof this.address !== 'function') {
|
||||||
@@ -206,7 +212,7 @@ export class Bridge {
|
|||||||
statusCode: response.statusCode || 200,
|
statusCode: response.statusCode || 200,
|
||||||
headers: response.headers,
|
headers: response.headers,
|
||||||
body: bodyBuffer.toString('base64'),
|
body: bodyBuffer.toString('base64'),
|
||||||
encoding: 'base64'
|
encoding: 'base64',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/node",
|
"name": "@now/node",
|
||||||
"version": "1.1.0",
|
"version": "1.1.3-canary.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./dist/index",
|
"main": "./dist/index",
|
||||||
"homepage": "https://zeit.co/docs/runtimes#official-runtimes/node-js",
|
"homepage": "https://zeit.co/docs/runtimes#official-runtimes/node-js",
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export function compile(
|
|||||||
): { code: string; map: any } {
|
): { code: string; map: any } {
|
||||||
return babel.transform(source, {
|
return babel.transform(source, {
|
||||||
filename,
|
filename,
|
||||||
|
configFile: false,
|
||||||
babelrc: false,
|
babelrc: false,
|
||||||
highlightCode: false,
|
highlightCode: false,
|
||||||
compact: false,
|
compact: false,
|
||||||
|
|||||||
@@ -1,4 +1,12 @@
|
|||||||
import { basename, dirname, join, relative, resolve, sep, parse as parsePath } from 'path';
|
import {
|
||||||
|
basename,
|
||||||
|
dirname,
|
||||||
|
join,
|
||||||
|
relative,
|
||||||
|
resolve,
|
||||||
|
sep,
|
||||||
|
parse as parsePath,
|
||||||
|
} from 'path';
|
||||||
import nodeFileTrace from '@zeit/node-file-trace';
|
import nodeFileTrace from '@zeit/node-file-trace';
|
||||||
import {
|
import {
|
||||||
glob,
|
glob,
|
||||||
@@ -19,6 +27,7 @@ import {
|
|||||||
Config,
|
Config,
|
||||||
debug,
|
debug,
|
||||||
} from '@now/build-utils';
|
} from '@now/build-utils';
|
||||||
|
export { shouldServe };
|
||||||
export { NowRequest, NowResponse } from './types';
|
export { NowRequest, NowResponse } from './types';
|
||||||
import { makeNowLauncher, makeAwsLauncher } from './launcher';
|
import { makeNowLauncher, makeAwsLauncher } from './launcher';
|
||||||
import { readFileSync, lstatSync, readlinkSync, statSync } from 'fs';
|
import { readFileSync, lstatSync, readlinkSync, statSync } from 'fs';
|
||||||
@@ -288,7 +297,9 @@ function getAWSLambdaHandler(entrypoint: string, config: Config) {
|
|||||||
|
|
||||||
if (process.env.NODEJS_AWS_HANDLER_NAME) {
|
if (process.env.NODEJS_AWS_HANDLER_NAME) {
|
||||||
const { dir, name } = parsePath(entrypoint);
|
const { dir, name } = parsePath(entrypoint);
|
||||||
return `${dir}${dir ? sep : ''}${name}.${process.env.NODEJS_AWS_HANDLER_NAME}`;
|
return `${dir}${dir ? sep : ''}${name}.${
|
||||||
|
process.env.NODEJS_AWS_HANDLER_NAME
|
||||||
|
}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
@@ -303,7 +314,9 @@ export async function build({
|
|||||||
config = {},
|
config = {},
|
||||||
meta = {},
|
meta = {},
|
||||||
}: BuildOptions) {
|
}: BuildOptions) {
|
||||||
const shouldAddHelpers = !(config.helpers === false || process.env.NODEJS_HELPERS === '0');
|
const shouldAddHelpers = !(
|
||||||
|
config.helpers === false || process.env.NODEJS_HELPERS === '0'
|
||||||
|
);
|
||||||
const awsLambdaHandler = getAWSLambdaHandler(entrypoint, config);
|
const awsLambdaHandler = getAWSLambdaHandler(entrypoint, config);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -387,5 +400,3 @@ export async function prepareCache({ workPath }: PrepareCacheOptions) {
|
|||||||
...(await glob('yarn.lock', workPath)),
|
...(await glob('yarn.lock', workPath)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export { shouldServe };
|
|
||||||
|
|||||||
3
packages/now-node/test/fixtures/49-babel-config/babel.config.js
vendored
Normal file
3
packages/now-node/test/fixtures/49-babel-config/babel.config.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = {
|
||||||
|
presets: [['@babel/preset-env', { useBuiltIns: 'usage', corejs: 3 }]],
|
||||||
|
}
|
||||||
3
packages/now-node/test/fixtures/49-babel-config/index.js
vendored
Normal file
3
packages/now-node/test/fixtures/49-babel-config/index.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export default (req, resp) => {
|
||||||
|
resp.send('Cats are the best!'.endsWith('best!'));
|
||||||
|
};
|
||||||
5
packages/now-node/test/fixtures/49-babel-config/now.json
vendored
Normal file
5
packages/now-node/test/fixtures/49-babel-config/now.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": 2,
|
||||||
|
"builds": [{ "src": "index.js", "use": "@now/node" }],
|
||||||
|
"probes": [{ "path": "/", "mustContain": "true" }]
|
||||||
|
}
|
||||||
6
packages/now-node/test/fixtures/49-babel-config/package.json
vendored
Normal file
6
packages/now-node/test/fixtures/49-babel-config/package.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/preset-env": "7.7.1",
|
||||||
|
"core-js": "3.4.1"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/python",
|
"name": "@now/python",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1-canary.0",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"homepage": "https://zeit.co/docs/runtimes#official-runtimes/python",
|
"homepage": "https://zeit.co/docs/runtimes#official-runtimes/python",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/routing-utils",
|
"name": "@now/routing-utils",
|
||||||
"version": "1.3.3",
|
"version": "1.3.4-canary.0",
|
||||||
"description": "ZEIT Now routing utilities",
|
"description": "ZEIT Now routing utilities",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/ruby",
|
"name": "@now/ruby",
|
||||||
"author": "Nathan Cahill <nathan@nathancahill.com>",
|
"author": "Nathan Cahill <nathan@nathancahill.com>",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1-canary.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./dist/index",
|
"main": "./dist/index",
|
||||||
"homepage": "https://zeit.co/docs/runtimes#official-runtimes/ruby",
|
"homepage": "https://zeit.co/docs/runtimes#official-runtimes/ruby",
|
||||||
|
|||||||
4
packages/now-static-build/.gitignore
vendored
4
packages/now-static-build/.gitignore
vendored
@@ -1,5 +1 @@
|
|||||||
dist/
|
dist/
|
||||||
|
|
||||||
# bypass all ignored files for the cache fixtures
|
|
||||||
# because they contain node_modules and package-lock.json files
|
|
||||||
!test/cache-fixtures/**
|
|
||||||
|
|||||||
@@ -3,9 +3,8 @@ set -euo pipefail
|
|||||||
|
|
||||||
ncc build src/index.ts -o dist
|
ncc build src/index.ts -o dist
|
||||||
|
|
||||||
# copy gatsby-plugin-now files to the dist folder to
|
# copy gatsby plugin files in the gatsby redirect test case
|
||||||
# make them available when they need to be injected
|
|
||||||
gatsby_plugin="$(dirname $(pwd))/gatsby-plugin-now"
|
gatsby_plugin="$(dirname $(pwd))/gatsby-plugin-now"
|
||||||
gatsby_local="dist/gatsby-plugin-now"
|
gatsby_local="test/fixtures/10a-gatsby-redirects/plugins/gatsby-plugin-now"
|
||||||
mkdir -p $gatsby_local
|
mkdir -p $gatsby_local
|
||||||
cp -v "$gatsby_plugin/gatsby-node.js" "$gatsby_plugin/package.json" "$gatsby_local"
|
cp -v "$gatsby_plugin/gatsby-node.js" "$gatsby_plugin/package.json" "$gatsby_local"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@now/static-build",
|
"name": "@now/static-build",
|
||||||
"version": "0.12.0",
|
"version": "0.12.3-canary.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./dist/index",
|
"main": "./dist/index",
|
||||||
"homepage": "https://zeit.co/docs/runtimes#official-runtimes/static-builds",
|
"homepage": "https://zeit.co/docs/runtimes#official-runtimes/static-builds",
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { readdir, stat, readFile, unlink } from 'fs';
|
|||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { Route } from '@now/build-utils';
|
import { Route } from '@now/build-utils';
|
||||||
import { injectGatsbyConfig } from './utils/gatsby-config';
|
|
||||||
|
|
||||||
const readirPromise = promisify(readdir);
|
const readirPromise = promisify(readdir);
|
||||||
const readFilePromise = promisify(readFile);
|
const readFilePromise = promisify(readFile);
|
||||||
@@ -45,10 +44,6 @@ export const frameworks: Framework[] = [
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeBuildHook: async entrypointDir => {
|
|
||||||
await injectGatsbyConfig(entrypointDir);
|
|
||||||
},
|
|
||||||
cachePattern: '.cache/**',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Hexo',
|
name: 'Hexo',
|
||||||
@@ -317,6 +312,4 @@ export interface Framework {
|
|||||||
getOutputDirName: (dirPrefix: string) => Promise<string>;
|
getOutputDirName: (dirPrefix: string) => Promise<string>;
|
||||||
defaultRoutes?: Route[] | ((dirPrefix: string) => Promise<Route[]>);
|
defaultRoutes?: Route[] | ((dirPrefix: string) => Promise<Route[]>);
|
||||||
minNodeRange?: string;
|
minNodeRange?: string;
|
||||||
beforeBuildHook?: (entrypointDir: string) => Promise<void>;
|
|
||||||
cachePattern?: string;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import {
|
|||||||
getNodeVersion,
|
getNodeVersion,
|
||||||
getSpawnOptions,
|
getSpawnOptions,
|
||||||
Files,
|
Files,
|
||||||
FileFsRef,
|
|
||||||
Route,
|
Route,
|
||||||
BuildOptions,
|
BuildOptions,
|
||||||
Config,
|
Config,
|
||||||
@@ -150,24 +149,6 @@ async function getFrameworkRoutes(
|
|||||||
return routes;
|
return routes;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPkg(entrypoint: string, workPath: string) {
|
|
||||||
if (path.basename(entrypoint) !== 'package.json') {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const pkgPath = path.join(workPath, entrypoint);
|
|
||||||
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) as PackageJson;
|
|
||||||
return pkg;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getFramework(pkg: PackageJson) {
|
|
||||||
const dependencies = Object.assign({}, pkg.dependencies, pkg.devDependencies);
|
|
||||||
const framework = frameworks.find(
|
|
||||||
({ dependency }) => dependencies[dependency || '']
|
|
||||||
);
|
|
||||||
return framework;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function build({
|
export async function build({
|
||||||
files,
|
files,
|
||||||
entrypoint,
|
entrypoint,
|
||||||
@@ -187,9 +168,11 @@ export async function build({
|
|||||||
(config && (config.distDir as string)) || 'dist'
|
(config && (config.distDir as string)) || 'dist'
|
||||||
);
|
);
|
||||||
|
|
||||||
const pkg = getPkg(entrypoint, workPath);
|
const entrypointName = path.basename(entrypoint);
|
||||||
|
|
||||||
if (pkg) {
|
if (entrypointName === 'package.json') {
|
||||||
|
const pkgPath = path.join(workPath, entrypoint);
|
||||||
|
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8')) as PackageJson;
|
||||||
const gemfilePath = path.join(workPath, 'Gemfile');
|
const gemfilePath = path.join(workPath, 'Gemfile');
|
||||||
const requirementsPath = path.join(workPath, 'requirements.txt');
|
const requirementsPath = path.join(workPath, 'requirements.txt');
|
||||||
|
|
||||||
@@ -247,7 +230,15 @@ export async function build({
|
|||||||
// `public` is the default for zero config
|
// `public` is the default for zero config
|
||||||
distPath = path.join(workPath, path.dirname(entrypoint), 'public');
|
distPath = path.join(workPath, path.dirname(entrypoint), 'public');
|
||||||
|
|
||||||
framework = getFramework(pkg);
|
const dependencies = Object.assign(
|
||||||
|
{},
|
||||||
|
pkg.dependencies,
|
||||||
|
pkg.devDependencies
|
||||||
|
);
|
||||||
|
|
||||||
|
framework = frameworks.find(
|
||||||
|
({ dependency }) => dependencies[dependency || '']
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (framework) {
|
if (framework) {
|
||||||
@@ -265,10 +256,6 @@ export async function build({
|
|||||||
`${framework.name} does not require a specific Node.js version. Continuing ...`
|
`${framework.name} does not require a specific Node.js version. Continuing ...`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (framework.beforeBuildHook) {
|
|
||||||
await framework.beforeBuildHook(entrypointDir);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const nodeVersion = await getNodeVersion(
|
const nodeVersion = await getNodeVersion(
|
||||||
@@ -390,7 +377,7 @@ export async function build({
|
|||||||
return { routes, watch, output, distPath };
|
return { routes, watch, output, distPath };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!config.zeroConfig && entrypoint.endsWith('.sh')) {
|
if (!config.zeroConfig && entrypointName.endsWith('.sh')) {
|
||||||
debug(`Running build script "${entrypoint}"`);
|
debug(`Running build script "${entrypoint}"`);
|
||||||
const nodeVersion = await getNodeVersion(entrypointDir, undefined, config);
|
const nodeVersion = await getNodeVersion(entrypointDir, undefined, config);
|
||||||
const spawnOpts = getSpawnOptions(meta, nodeVersion);
|
const spawnOpts = getSpawnOptions(meta, nodeVersion);
|
||||||
@@ -416,27 +403,10 @@ export async function build({
|
|||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function prepareCache({
|
export async function prepareCache({ workPath }: PrepareCacheOptions) {
|
||||||
entrypoint,
|
return {
|
||||||
workPath,
|
...(await glob('node_modules/**', workPath)),
|
||||||
}: PrepareCacheOptions) {
|
...(await glob('package-lock.json', workPath)),
|
||||||
// default cache paths
|
...(await glob('yarn.lock', workPath)),
|
||||||
const defaultCacheFiles = await glob(
|
};
|
||||||
'{node_modules/**,package-lock.json,yarn.lock}',
|
|
||||||
workPath
|
|
||||||
);
|
|
||||||
|
|
||||||
// framework specific cache paths
|
|
||||||
let frameworkCacheFiles: { [path: string]: FileFsRef } | null = null;
|
|
||||||
|
|
||||||
const pkg = getPkg(entrypoint, workPath);
|
|
||||||
if (pkg) {
|
|
||||||
const framework = getFramework(pkg);
|
|
||||||
|
|
||||||
if (framework && framework.cachePattern) {
|
|
||||||
frameworkCacheFiles = await glob(framework.cachePattern, workPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return { ...defaultCacheFiles, ...frameworkCacheFiles };
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,75 +0,0 @@
|
|||||||
import { writeFile, copyFile, mkdir } from 'fs';
|
|
||||||
import { join, dirname } from 'path';
|
|
||||||
import { promisify } from 'util';
|
|
||||||
|
|
||||||
const writeFilePromise = promisify(writeFile);
|
|
||||||
const mkdirPromise = promisify(mkdir);
|
|
||||||
const copyFilePromise = promisify(copyFile);
|
|
||||||
|
|
||||||
const GATSBY_PLUGIN_NOW_NAME = 'gatsby-plugin-now';
|
|
||||||
const GATSBY_USER_CONFIG_PATH = './__now_gatsby_config_user.js';
|
|
||||||
|
|
||||||
function createGatsbyConfig(hasUserConfig: boolean) {
|
|
||||||
return `let userConfig = {}
|
|
||||||
|
|
||||||
${hasUserConfig ? `userConfig = require('${GATSBY_USER_CONFIG_PATH}')` : ''}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
...userConfig,
|
|
||||||
plugins: [
|
|
||||||
...(userConfig.plugins || []),
|
|
||||||
'${GATSBY_PLUGIN_NOW_NAME}'
|
|
||||||
]
|
|
||||||
}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function injectGatsbyConfig(entrypointDir: string) {
|
|
||||||
try {
|
|
||||||
// first, we copy gatsby-plugin-now to plugins
|
|
||||||
const gatsbyPluginNowPath = join(
|
|
||||||
entrypointDir,
|
|
||||||
'plugins',
|
|
||||||
GATSBY_PLUGIN_NOW_NAME
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
|
||||||
await mkdirPromise(dirname(gatsbyPluginNowPath));
|
|
||||||
} catch (err) {
|
|
||||||
// plugins folder already exists, ignore error
|
|
||||||
}
|
|
||||||
|
|
||||||
await mkdirPromise(gatsbyPluginNowPath);
|
|
||||||
|
|
||||||
await copyFilePromise(
|
|
||||||
require.resolve('./gatsby-plugin-now/gatsby-node.js'),
|
|
||||||
join(gatsbyPluginNowPath, 'gatsby-node.js')
|
|
||||||
);
|
|
||||||
await copyFilePromise(
|
|
||||||
require.resolve('./gatsby-plugin-now/package.json'),
|
|
||||||
join(gatsbyPluginNowPath, 'package.json')
|
|
||||||
);
|
|
||||||
|
|
||||||
// then, we wrap the existing config and
|
|
||||||
// inject the plugin into the config
|
|
||||||
let hasUserConfig = false;
|
|
||||||
try {
|
|
||||||
await copyFilePromise(
|
|
||||||
join(entrypointDir, 'gatsby-config.js'),
|
|
||||||
join(entrypointDir, GATSBY_USER_CONFIG_PATH)
|
|
||||||
);
|
|
||||||
hasUserConfig = true;
|
|
||||||
} catch (err) {
|
|
||||||
// do nothing here, it just means the user
|
|
||||||
// didn't define gatsby-config.js
|
|
||||||
}
|
|
||||||
|
|
||||||
await writeFilePromise(
|
|
||||||
join(entrypointDir, 'gatsby-config.js'),
|
|
||||||
createGatsbyConfig(hasUserConfig),
|
|
||||||
{ encoding: 'utf-8' }
|
|
||||||
);
|
|
||||||
} catch (err) {
|
|
||||||
// if a step fail, we can ignore the error since we're not breaking
|
|
||||||
// the user's gatsby configuration
|
|
||||||
}
|
|
||||||
}
|
|
||||||
0
packages/now-static-build/test/cache-fixtures/default/node_modules/file
generated
vendored
0
packages/now-static-build/test/cache-fixtures/default/node_modules/file
generated
vendored
@@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"dependencies": {
|
|
||||||
"gatsby": "^2.13.3"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
27
packages/now-static-build/test/cache.test.js
vendored
27
packages/now-static-build/test/cache.test.js
vendored
@@ -1,27 +0,0 @@
|
|||||||
const { prepareCache } = require('../dist');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
describe('prepareCache', () => {
|
|
||||||
test('should cache yarn.lock, package-lock.json and node_modules', async () => {
|
|
||||||
const files = await prepareCache({
|
|
||||||
workPath: path.resolve(__dirname, './cache-fixtures/default'),
|
|
||||||
entrypoint: 'index.js',
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(files['yarn.lock']).toBeDefined();
|
|
||||||
expect(files['package-lock.json']).toBeDefined();
|
|
||||||
expect(files['node_modules/file']).toBeDefined();
|
|
||||||
|
|
||||||
expect(files['index.js']).toBeUndefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should cache `.cache` folder for gatsby deployments', async () => {
|
|
||||||
const files = await prepareCache({
|
|
||||||
workPath: path.resolve(__dirname, './cache-fixtures/gatsby'),
|
|
||||||
entrypoint: 'package.json',
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(files['.cache/file']).toBeDefined();
|
|
||||||
expect(files['yarn.lock']).toBeDefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,55 +1,9 @@
|
|||||||
{
|
{
|
||||||
"version": 2,
|
"version": 2,
|
||||||
"builds": [
|
"builds": [
|
||||||
{
|
{ "src": "package.json", "use": "@now/static-build", "config": { "zeroConfig": true } }
|
||||||
"src": "package.json",
|
|
||||||
"use": "@now/static-build",
|
|
||||||
"config": { "zeroConfig": true }
|
|
||||||
}
|
|
||||||
],
|
],
|
||||||
"probes": [
|
"probes": [
|
||||||
{ "path": "/", "mustContain": "Welcome to your new Gatsby site" },
|
{ "path": "/", "mustContain": "Welcome to your new Gatsby site" }
|
||||||
{
|
|
||||||
"path": "/static/d/856328897.json",
|
|
||||||
"responseHeaders": {
|
|
||||||
"cache-control": "public,max-age=31536000,immutable"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/app-08a9fb9626777db1bf33.js",
|
|
||||||
"responseHeaders": {
|
|
||||||
"cache-control": "public,max-age=31536000,immutable"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/styles.fc4fa5e094d218207796.css",
|
|
||||||
"responseHeaders": {
|
|
||||||
"cache-control": "public,max-age=31536000,immutable"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/sw.js",
|
|
||||||
"responseHeaders": { "cache-control": "public,max-age=0,must-revalidate" }
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/app-data.json",
|
|
||||||
"responseHeaders": { "cache-control": "public,max-age=0,must-revalidate" }
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/index.html",
|
|
||||||
"responseHeaders": { "cache-control": "public,max-age=0,must-revalidate" }
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/page-data/404/page-data.json",
|
|
||||||
"responseHeaders": { "cache-control": "public,max-age=0,must-revalidate" }
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/path-that-does-not-exist",
|
|
||||||
"mustContain": "You just hit a route that doesn't exist..."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"path": "/path-that-does-not-exist",
|
|
||||||
"status": 404
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,3 +6,4 @@ node_modules
|
|||||||
public/
|
public/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
yarn-error.log
|
yarn-error.log
|
||||||
|
plugins
|
||||||
|
|||||||
3
packages/now-static-build/test/fixtures/10a-gatsby-redirects/gatsby-config.js
vendored
Normal file
3
packages/now-static-build/test/fixtures/10a-gatsby-redirects/gatsby-config.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = {
|
||||||
|
plugins: ["gatsby-plugin-now"]
|
||||||
|
};
|
||||||
4
run.js
4
run.js
@@ -26,12 +26,12 @@ async function main() {
|
|||||||
const changed = diff
|
const changed = diff
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.filter(item => Boolean(item) && item.includes('packages/'))
|
.filter(item => Boolean(item) && item.includes('packages/'))
|
||||||
.map(item => relative('packages', item).split('/')[0]);
|
.map(item => relative('packages', item).split('/')[0])
|
||||||
|
.concat('now-cli'); // Always run tests for Now CLI
|
||||||
|
|
||||||
matches = Array.from(new Set(changed));
|
matches = Array.from(new Set(changed));
|
||||||
|
|
||||||
if (matches.length === 0) {
|
if (matches.length === 0) {
|
||||||
matches.push('now-cli');
|
|
||||||
matches.push('now-node');
|
matches.push('now-node');
|
||||||
console.log('No packages changed. Using default packages.');
|
console.log('No packages changed. Using default packages.');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user