Compare commits

..

5 Commits

Author SHA1 Message Date
Steven
aee33f040d Publish Stable
- @now/build-utils@1.2.0
 - @now/cgi@1.0.1
 - now@16.7.0
 - @now/go@1.0.1
 - @now/next@2.2.0
 - @now/node@1.3.0
 - @now/python@1.0.1
 - @now/ruby@1.0.1
 - @now/static-build@0.14.0
2019-12-14 07:58:04 -05:00
Steven
b100677b3b Publish Canary
- @now/next@2.1.2-canary.3
2019-12-14 07:18:41 -05:00
Joe Haddad
9241b3ae2f [now-next] Compute Rewrites & Redirects Earlier (#3430)
This PR strictly moves code to make the diff for an upcoming PR cleaner.
2019-12-14 03:04:35 +00:00
Steven
1088da6871 Publish Canary
- @now/build-utils@1.1.2-canary.5
 - now@16.6.4-canary.6
 - @now/next@2.1.2-canary.2
 - @now/node@1.2.2-canary.2
 - @now/static-build@0.13.2-canary.3
2019-12-13 18:12:54 -05:00
Andy
f7b4dd4458 Revert "[now-static-build] Add support buildCommand, devCommand and outputDirectory (#3422)" (#3428)
This reverts commit 5a6d1a135f.
2019-12-13 18:12:16 -05:00
26 changed files with 51 additions and 363 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@now/build-utils",
"version": "1.1.2-canary.4",
"version": "1.2.0",
"license": "MIT",
"main": "./dist/index.js",
"types": "./dist/index.d.js",

View File

@@ -80,12 +80,7 @@ function detectFrontBuilder(
const { tag } = options;
const withTag = tag ? `@${tag}` : '';
const {
framework,
buildCommand,
outputDirectory,
devCommand,
} = detectorResult;
const { framework, buildCommand, outputDirectory } = detectorResult;
const frameworkSlug = framework ? framework.slug : null;
@@ -93,14 +88,6 @@ function detectFrontBuilder(
zeroConfig: true,
};
if (framework) {
config.framework = framework;
}
if (devCommand) {
config.devCommand = devCommand;
}
if (buildCommand) {
config.buildCommand = buildCommand;
}

View File

@@ -39,66 +39,6 @@ export function spawnAsync(
});
}
export function execAsync(
command: string,
args: string[],
opts: SpawnOptions = {}
) {
return new Promise<{ stdout: string; stderr: string; code: number }>(
(resolve, reject) => {
opts.stdio = 'pipe';
let stdout: Buffer = Buffer.from('');
let stderr: Buffer = Buffer.from('');
const child = spawn(command, args, opts);
child.stderr!.on('data', data => {
stderr = Buffer.concat([stderr, data]);
});
child.stdout!.on('data', data => {
stdout = Buffer.concat([stdout, data]);
});
child.on('error', reject);
child.on('close', (code, signal) => {
if (code !== 0) {
return reject(
new Error(
`Program "${command}" exited with non-zero exit code ${code} ${signal}.`
)
);
}
return resolve({
code,
stdout: stdout.toString(),
stderr: stderr.toString(),
});
});
}
);
}
export function spawnCommand(command: string, options: SpawnOptions = {}) {
if (process.platform === 'win32') {
return spawn('cmd.exe', ['/C', command], options);
}
return spawn('sh', ['-c', command], options);
}
export async function execCommand(command: string, options: SpawnOptions = {}) {
if (process.platform === 'win32') {
await spawnAsync('cmd.exe', ['/C', command], options);
} else {
await spawnAsync('sh', ['-c', command], options);
}
return true;
}
async function chmodPlusX(fsPath: string) {
const s = await fs.stat(fsPath);
const newMode = s.mode | 64 | 8 | 1; // eslint-disable-line no-bitwise

View File

@@ -8,10 +8,7 @@ import getWriteableDirectory from './fs/get-writable-directory';
import glob from './fs/glob';
import rename from './fs/rename';
import {
execAsync,
spawnAsync,
execCommand,
spawnCommand,
installDependencies,
runPackageJsonScript,
runNpmInstall,
@@ -41,12 +38,9 @@ export {
getWriteableDirectory,
glob,
rename,
execAsync,
spawnAsync,
installDependencies,
runPackageJsonScript,
execCommand,
spawnCommand,
runNpmInstall,
runBundleInstall,
runPipInstall,

View File

@@ -52,10 +52,6 @@ export interface Config {
zeroConfig?: boolean;
import?: { [key: string]: string };
functions?: BuilderFunctions;
framework?: {
slug: string;
version: string;
};
}
export interface Meta {

View File

@@ -502,10 +502,6 @@ describe('Test `detectBuilders`', () => {
config: {
zeroConfig: true,
buildCommand: 'yarn build',
framework: {
slug: 'next',
version: '9.0.0',
},
functions: {
'pages/api/teams/**': {
memory: 128,
@@ -573,10 +569,6 @@ describe('Test `detectBuilders`', () => {
config: {
zeroConfig: true,
buildCommand: 'yarn build',
framework: {
slug: 'next',
version: '9.0.0',
},
},
});
});
@@ -918,12 +910,8 @@ describe('Test `detectBuilders`', () => {
use: '@now/next',
src: 'package.json',
config: {
zeroConfig: true,
buildCommand: 'yarn build',
framework: {
slug: 'next',
version: '9.0.0',
},
zeroConfig: true,
},
});

View File

@@ -1,6 +1,6 @@
{
"name": "@now/cgi",
"version": "1.0.1-canary.1",
"version": "1.0.1",
"license": "MIT",
"repository": {
"type": "git",

View File

@@ -1,6 +1,6 @@
{
"name": "now",
"version": "16.6.4-canary.5",
"version": "16.7.0",
"preferGlobal": true,
"license": "Apache-2.0",
"description": "The command-line interface for Now",

View File

@@ -1,6 +1,6 @@
{
"name": "@now/go",
"version": "1.0.1-canary.1",
"version": "1.0.1",
"license": "MIT",
"main": "./dist/index",
"homepage": "https://zeit.co/docs/runtimes#official-runtimes/go",

View File

@@ -1,6 +1,6 @@
{
"name": "@now/next",
"version": "2.1.2-canary.1",
"version": "2.2.0",
"license": "MIT",
"main": "./dist/index",
"homepage": "https://zeit.co/docs/runtimes#official-runtimes/next-js",

View File

@@ -334,6 +334,27 @@ export const build = async ({
env.NODE_OPTIONS = `--max_old_space_size=${memoryToConsume}`;
await runPackageJsonScript(entryPath, shouldRunScript, { ...spawnOpts, env });
const routesManifest = await getRoutesManifest(entryPath, realNextVersion);
const rewrites: Route[] = [];
const redirects: Route[] = [];
if (routesManifest) {
switch (routesManifest.version) {
case 1: {
redirects.push(...convertRedirects(routesManifest.redirects));
rewrites.push(...convertRewrites(routesManifest.rewrites));
break;
}
default: {
// update MIN_ROUTES_MANIFEST_VERSION in ./utils.ts
throw new Error(
'This version of `@now/next` does not support the version of Next.js you are trying to deploy.\n' +
'Please upgrade your `@now/next` builder and try again. Contact support if this continues to happen.'
);
}
}
}
if (isLegacy) {
debug('Running npm install --production...');
await runNpmInstall(
@@ -819,8 +840,6 @@ export const build = async ({
let dynamicPrefix = path.join('/', entryDirectory);
dynamicPrefix = dynamicPrefix === '/' ? '' : dynamicPrefix;
const routesManifest = await getRoutesManifest(entryPath, realNextVersion);
const dynamicRoutes = await getDynamicRoutes(
entryPath,
entryDirectory,
@@ -834,26 +853,6 @@ export const build = async ({
})
);
const rewrites: Route[] = [];
const redirects: Route[] = [];
if (routesManifest) {
switch (routesManifest.version) {
case 1: {
redirects.push(...convertRedirects(routesManifest.redirects));
rewrites.push(...convertRewrites(routesManifest.rewrites));
break;
}
default: {
// update MIN_ROUTES_MANIFEST_VERSION in ./utils.ts
throw new Error(
'This version of `@now/next` does not support the version of Next.js you are trying to deploy.\n' +
'Please upgrade your `@now/next` builder and try again. Contact support if this continues to happen.'
);
}
}
}
return {
output: {
...publicDirectoryFiles,

View File

@@ -1,6 +1,6 @@
{
"name": "@now/node",
"version": "1.2.2-canary.1",
"version": "1.3.0",
"license": "MIT",
"main": "./dist/index",
"homepage": "https://zeit.co/docs/runtimes#official-runtimes/node-js",

View File

@@ -1,6 +1,6 @@
{
"name": "@now/python",
"version": "1.0.1-canary.1",
"version": "1.0.1",
"main": "./dist/index.js",
"license": "MIT",
"homepage": "https://zeit.co/docs/runtimes#official-runtimes/python",

View File

@@ -1,7 +1,7 @@
{
"name": "@now/ruby",
"author": "Nathan Cahill <nathan@nathancahill.com>",
"version": "1.0.1-canary.1",
"version": "1.0.1",
"license": "MIT",
"main": "./dist/index",
"homepage": "https://zeit.co/docs/runtimes#official-runtimes/ruby",

View File

@@ -1,6 +1,6 @@
{
"name": "@now/static-build",
"version": "0.13.2-canary.2",
"version": "0.14.0",
"license": "MIT",
"main": "./dist/index",
"homepage": "https://zeit.co/docs/runtimes#official-runtimes/static-builds",

View File

@@ -9,10 +9,7 @@ import { frameworks, Framework } from './frameworks';
import {
glob,
download,
execAsync,
spawnAsync,
execCommand,
spawnCommand,
runNpmInstall,
runBundleInstall,
runPipInstall,
@@ -163,32 +160,7 @@ function getPkg(entrypoint: string, workPath: string) {
return pkg;
}
function getFramework(config: Config, pkg?: PackageJson | null) {
if (config && config.framework && (config.framework as any).slug) {
const framework = frameworks.find(
({ dependency }) => dependency === (config.framework as any).slug!
);
if (framework) {
if (!framework.getOutputDirName && config.outputDirectory) {
return {
...framework,
getOutputDirName(prefix: string) {
return Promise.resolve(
path.join(prefix, config.outputDirectory as string)
);
},
};
}
return framework;
}
}
if (!pkg) {
return;
}
function getFramework(pkg: PackageJson) {
const dependencies = Object.assign({}, pkg.dependencies, pkg.devDependencies);
const framework = frameworks.find(
({ dependency }) => dependencies[dependency || '']
@@ -205,22 +177,18 @@ export async function build({
}: BuildOptions) {
await download(files, workPath, meta);
debug(`config:\n${JSON.stringify(config, null, 2)}`);
const mountpoint = path.dirname(entrypoint);
const entrypointDir = path.join(workPath, mountpoint);
let distPath = path.join(
workPath,
path.dirname(entrypoint),
(config && (config.distDir as string)) ||
(config.outputDirectory as string) ||
'dist'
(config && (config.distDir as string)) || 'dist'
);
const pkg = getPkg(entrypoint, workPath);
if (pkg || config.buildCommand) {
if (pkg) {
const gemfilePath = path.join(workPath, 'Gemfile');
const requirementsPath = path.join(workPath, 'requirements.txt');
@@ -229,7 +197,7 @@ export async function build({
let minNodeRange: string | undefined = undefined;
const routes: Route[] = [];
const devScript = pkg ? getCommand(pkg, 'dev', config) : null;
const devScript = getCommand(pkg, 'dev', config as Config);
if (config.zeroConfig) {
if (existsSync(gemfilePath) && !meta.isDev) {
@@ -276,13 +244,9 @@ export async function build({
}
// `public` is the default for zero config
distPath = path.join(
workPath,
path.dirname(entrypoint),
(config.outputDirectory as string) || 'public'
);
distPath = path.join(workPath, path.dirname(entrypoint), 'public');
framework = getFramework(config, pkg);
framework = getFramework(pkg);
}
if (framework) {
@@ -312,37 +276,11 @@ export async function build({
console.log('Installing dependencies...');
await runNpmInstall(entrypointDir, ['--prefer-offline'], spawnOpts, meta);
if (pkg && (config.buildCommand || config.devCommand)) {
// We want to add `node_modules/.bin` after `npm install`
const { stdout } = await execAsync('yarn', ['bin'], {
cwd: entrypointDir,
});
spawnOpts.env = {
...spawnOpts.env,
PATH: `${stdout.trim()}${path.delimiter}${
spawnOpts.env ? spawnOpts.env.PATH : ''
}`,
};
debug(
`Added "${stdout.trim()}" to PATH env because a package.json file was found.`
);
}
if (
meta.isDev &&
(config.devCommand ||
(pkg && devScript && pkg.scripts && pkg.scripts[devScript]))
) {
if (meta.isDev && pkg.scripts && pkg.scripts[devScript]) {
let devPort: number | undefined = nowDevScriptPorts.get(entrypoint);
if (typeof devPort === 'number') {
debug(
'`%s` server already running for %j',
config.devCommand || devScript,
entrypoint
);
debug('`%s` server already running for %j', devScript, entrypoint);
} else {
// Run the `now-dev` or `dev` script out-of-bounds, since it is assumed that
// it will launch a dev server that never "completes"
@@ -355,11 +293,7 @@ export async function build({
env: { ...process.env, PORT: String(devPort) },
};
const child: ChildProcess =
typeof config.devCommand === 'string'
? spawnCommand(config.devCommand, opts)
: spawn('yarn', ['run', devScript!], opts);
const child: ChildProcess = spawn('yarn', ['run', devScript], opts);
child.on('exit', () => nowDevScriptPorts.delete(entrypoint));
nowDevChildProcesses.add(child);
@@ -394,30 +328,24 @@ export async function build({
);
} else {
if (meta.isDev) {
debug(`WARN: A dev script is missing.`);
debug(`WARN: "${devScript}" script is missing from package.json`);
debug(
'See the local development docs: https://zeit.co/docs/v2/deployments/official-builders/static-build-now-static-build/#local-development'
);
}
const buildScript = pkg ? getCommand(pkg, 'build', config) : null;
debug(
`Running "${config.buildCommand ||
buildScript}" script in "${entrypoint}"`
);
const buildScript = getCommand(pkg, 'build', config as Config);
debug(`Running "${buildScript}" script in "${entrypoint}"`);
const found =
typeof config.buildCommand === 'string'
? await execCommand(config.buildCommand, {
...spawnOpts,
cwd: entrypointDir,
})
: await runPackageJsonScript(entrypointDir, buildScript!, spawnOpts);
const found = await runPackageJsonScript(
entrypointDir,
buildScript,
spawnOpts
);
if (!found) {
throw new Error(
`Missing required "${config.buildCommand ||
buildScript}" script in "${entrypoint}"`
`Missing required "${buildScript}" script in "${entrypoint}"`
);
}
@@ -486,7 +414,6 @@ export async function build({
export async function prepareCache({
entrypoint,
workPath,
config,
}: PrepareCacheOptions): Promise<Files> {
// default cache paths
const defaultCacheFiles = await glob('node_modules/**', workPath);
@@ -496,7 +423,7 @@ export async function prepareCache({
const pkg = getPkg(entrypoint, workPath);
if (pkg) {
const framework = getFramework(config, pkg);
const framework = getFramework(pkg);
if (framework && framework.cachePattern) {
frameworkCacheFiles = await glob(framework.cachePattern, workPath);

View File

@@ -1 +0,0 @@
public

View File

@@ -1,23 +0,0 @@
const path = require('path');
const { promises: fs } = require('fs');
async function main() {
console.log('Starting to build...');
await fs.mkdir(path.join(__dirname, 'public'));
await fs.writeFile(
path.join(__dirname, 'public', 'index.txt'),
`Time of Creation: ${Date.now()}`
);
console.log('Finished building...');
}
main()
.then(() => {
process.exit(0);
})
.catch(error => {
console.error(error);
process.exit(1);
});

View File

@@ -1,13 +0,0 @@
{
"builds": [
{
"src": "build.js",
"use": "@now/static-build",
"config": {
"zeroConfig": true,
"buildCommand": "node build.js"
}
}
],
"probes": [{ "path": "/", "mustContain": "Time of Creation:" }]
}

View File

@@ -1 +0,0 @@
custom-output

View File

@@ -1,23 +0,0 @@
const path = require('path');
const { promises: fs } = require('fs');
async function main() {
console.log('Starting to build...');
await fs.mkdir(path.join(__dirname, 'custom-output'));
await fs.writeFile(
path.join(__dirname, 'custom-output', 'index.txt'),
`Time of Creation: ${Date.now()}`
);
console.log('Finished building...');
}
main()
.then(() => {
process.exit(0);
})
.catch(error => {
console.error(error);
process.exit(1);
});

View File

@@ -1,30 +0,0 @@
const http = require('http');
async function main() {
console.log('Starting to build...');
const server = http.createServer((req, res) => {
console.log(`> Request ${req.url}`);
res.end(`Time of Creation: ${Date.now()}`);
});
const port = process.env.PORT || 3000;
server.listen(port, () => {
console.log(`Started server on port ${port}`);
});
await new Promise((resolve, reject) => {
server.on('exit', () => resolve());
server.on('error', error => reject(error));
});
}
main()
.then(() => {
process.exit(0);
})
.catch(error => {
console.error(error);
process.exit(1);
});

View File

@@ -1,15 +0,0 @@
{
"builds": [
{
"src": "build.js",
"use": "@now/static-build",
"config": {
"zeroConfig": true,
"buildCommand": "node build.js",
"devCommand": "node dev.js",
"outputDirectory": "custom-output"
}
}
],
"probes": [{ "path": "/", "mustContain": "Time of Creation:" }]
}

View File

@@ -1,19 +0,0 @@
{
"builds": [
{
"src": "package.json",
"use": "@now/static-build",
"config": {
"zeroConfig": true,
"buildCommand": "next build && next export",
"outputDirectory": "out"
}
}
],
"build": {
"env": {
"NOW_BUILDER_DEBUG": "1"
}
},
"probes": [{ "path": "/", "mustContain": "hello world" }]
}

View File

@@ -1,17 +0,0 @@
{
"name": "45-node-modules-bin-path",
"version": "1.0.0",
"description": "",
"main": "pages/index.js",
"scripts": {
"dev": "next",
"build": "next build"
},
"author": "Andy",
"private": true,
"dependencies": {
"next": "9.1.5",
"react": "16.12.0",
"react-dom": "16.12.0"
}
}

View File

@@ -1 +0,0 @@
export default () => <div>hello world</div>;