Compare commits

..

4 Commits

Author SHA1 Message Date
Steven
02fa98e5e3 Publish
- @now/build-utils@0.5.5-canary.0
 - @now/next@0.3.2-canary.0
 - @now/node-server@0.7.2-canary.0
 - @now/node@0.7.2-canary.0
 - @now/rust@0.2.4-canary.0
2019-05-07 17:08:55 -04:00
Steven
4aef9d48b0 [now-node] Bump ncc to 0.18.3 (#472) 2019-05-07 15:40:14 -04:00
Luis Fernando Alvarez D
bd2d05344e [now-next] Add public files to the output (#468) 2019-05-07 14:06:05 -05:00
Steven
edc7696623 Add newline to .gitignore 2019-05-07 09:28:59 -04:00
20 changed files with 138 additions and 30 deletions

2
.gitignore vendored
View File

@@ -1,4 +1,4 @@
node_modules
tmp
target/
.next
.next

View File

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

View File

@@ -8,12 +8,16 @@ import FileFsRef from '../file-fs-ref';
type GlobOptions = vanillaGlob_.IOptions;
interface FsFiles {
[filePath: string]: FileFsRef
[filePath: string]: FileFsRef;
}
const vanillaGlob = promisify(vanillaGlob_);
export default async function glob(pattern: string, opts: GlobOptions | string, mountpoint?: string): Promise<FsFiles> {
export default async function glob(
pattern: string,
opts: GlobOptions | string,
mountpoint?: string
): Promise<FsFiles> {
let options: GlobOptions;
if (typeof opts === 'string') {
options = { cwd: opts };
@@ -23,7 +27,7 @@ export default async function glob(pattern: string, opts: GlobOptions | string,
if (!options.cwd) {
throw new Error(
'Second argument (basePath) must be specified for names of resulting files',
'Second argument (basePath) must be specified for names of resulting files'
);
}
@@ -41,11 +45,11 @@ export default async function glob(pattern: string, opts: GlobOptions | string,
const files = await vanillaGlob(pattern, options);
for (const relativePath of files) {
const fsPath = path.join(options.cwd!, relativePath);
const fsPath = path.join(options.cwd!, relativePath).replace(/\\/g, '/');
let stat: Stats = options.statCache![fsPath] as Stats;
assert(
stat,
`statCache does not contain value for ${relativePath} (resolved to ${fsPath})`,
`statCache does not contain value for ${relativePath} (resolved to ${fsPath})`
);
if (stat.isFile()) {
const isSymlink = options.symlinks![fsPath];

View File

@@ -1,6 +1,6 @@
{
"name": "@now/next",
"version": "0.3.1",
"version": "0.3.2-canary.0",
"license": "MIT",
"main": "./dist/index",
"scripts": {

View File

@@ -32,7 +32,7 @@ import {
getRoutes,
includeOnlyEntryDirectory,
normalizePackageJson,
onlyStaticDirectory,
filesFromDirectory,
stringMap,
syncEnvVars,
validateEntrypoint,
@@ -448,13 +448,30 @@ export const build = async ({
{}
);
const staticDirectoryFiles = onlyStaticDirectory(
includeOnlyEntryDirectory(files, entryDirectory),
entryDirectory
const entryDirectoryFiles = includeOnlyEntryDirectory(files, entryDirectory);
const staticDirectoryFiles = filesFromDirectory(
entryDirectoryFiles,
path.join(entryDirectory, 'static')
);
const publicDirectoryFiles = filesFromDirectory(
entryDirectoryFiles,
path.join(entryDirectory, 'public')
);
const publicFiles = Object.keys(publicDirectoryFiles).reduce(
(mappedFiles, file) => ({
...mappedFiles,
[file.replace(/public[/\\]+/, '')]: publicDirectoryFiles[file],
}),
{}
);
return {
output: { ...lambdas, ...staticFiles, ...staticDirectoryFiles },
output: {
...publicFiles,
...lambdas,
...staticFiles,
...staticDirectoryFiles,
},
routes: [],
watch: [],
childProcesses: [],

View File

@@ -73,11 +73,11 @@ function excludeLockFiles(files: Files): Files {
}
/**
* Include the static directory from files
* Include only the files from a selected directory
*/
function onlyStaticDirectory(files: Files, entryDir: string): Files {
function filesFromDirectory(files: Files, dir: string): Files {
function matcher(filePath: string) {
return !filePath.startsWith(path.join(entryDir, 'static'));
return !filePath.startsWith(dir.replace(/\\/g, '/'));
}
return excludeFiles(files, matcher);
@@ -195,8 +195,9 @@ function getRoutes(
dest: `${url}/static/$1`,
},
];
const filePaths = Object.keys(filesInside);
for (const file of Object.keys(filesInside)) {
for (const file of filePaths) {
const relativePath = path.relative(entryDirectory, file);
const isPage = pathIsInside('pages', relativePath);
@@ -227,6 +228,25 @@ function getRoutes(
}
}
// Add public folder routes
for (const file of filePaths) {
const relativePath = path.relative(entryDirectory, file);
const isPublic = pathIsInside('public', relativePath);
if (!isPublic) continue;
const fileName = path.relative('public', relativePath);
const route = {
src: `${prefix}${fileName}`,
dest: `${url}/${fileName}`,
};
// Only add the route if a page is not already using it
if (!routes.some(r => r.src === route.src)) {
routes.push(route);
}
}
return routes;
}
@@ -250,7 +270,7 @@ export {
includeOnlyEntryDirectory,
excludeLockFiles,
normalizePackageJson,
onlyStaticDirectory,
filesFromDirectory,
getNextConfig,
getPathsInside,
getRoutes,

View File

@@ -28,6 +28,7 @@ it(
} = await runBuildLambda(path.join(__dirname, 'monorepo'));
expect(output['www/index']).toBeDefined();
expect(output['www/static/test.txt']).toBeDefined();
expect(output['www/data.txt']).toBeDefined();
const filePaths = Object.keys(output);
const hasUnderScoreAppStaticFile = filePaths.some(filePath => filePath.match(/static.*\/pages\/_app\.js$/));
const hasUnderScoreErrorStaticFile = filePaths.some(filePath => filePath.match(/static.*\/pages\/_error\.js$/));
@@ -96,3 +97,14 @@ it(
},
FOUR_MINUTES,
);
it(
'Should build the public-files test',
async () => {
const {
buildResult: { output },
} = await runBuildLambda(path.join(__dirname, 'public-files'));
expect(output['robots.txt']).toBeDefined();
},
FOUR_MINUTES,
);

View File

@@ -0,0 +1 @@
data

View File

@@ -0,0 +1,3 @@
module.exports = {
target: 'serverless',
};

View File

@@ -0,0 +1,6 @@
{
"version": 2,
"builds": [
{"src": "next.config.js", "use": "@now/next"}
]
}

View File

@@ -0,0 +1,10 @@
{
"scripts": {
"now-build": "next build"
},
"dependencies": {
"next": "8",
"react": "16",
"react-dom": "16"
}
}

View File

@@ -0,0 +1 @@
export default () => 'Index page';

View File

@@ -0,0 +1,2 @@
User-agent: *
Disallow: /

View File

@@ -22,6 +22,15 @@ describe('build meta dev', () => {
export default () => 'Index page'
`,
}),
// This file should be omitted because `pages/index.js` will use the same route
'public/index': new FileBlob({
mode: 0o777,
data: 'text',
}),
'public/data.txt': new FileBlob({
mode: 0o777,
data: 'data',
}),
'package.json': new FileBlob({
mode: 0o777,
data: `
@@ -83,8 +92,15 @@ describe('build meta dev', () => {
{ src: '/static/(.*)', dest: 'http://localhost:5000/static/$1' },
{ src: '/index', dest: 'http://localhost:5000/index' },
{ src: '/', dest: 'http://localhost:5000/' },
{ src: '/data.txt', dest: 'http://localhost:5000/data.txt' },
]);
expect(watch).toEqual([
'next.config.js',
'pages/index.js',
'public/index',
'public/data.txt',
'package.json',
]);
expect(watch).toEqual(['next.config.js', 'pages/index.js', 'package.json']);
childProcesses.forEach(cp => cp.kill());
});
});

View File

@@ -1,6 +1,6 @@
{
"name": "@now/node-server",
"version": "0.7.1",
"version": "0.7.2-canary.0",
"license": "MIT",
"repository": {
"type": "git",
@@ -9,7 +9,7 @@
},
"dependencies": {
"@now/node-bridge": "^1.1.2",
"@zeit/ncc": "0.18.2",
"@zeit/ncc": "0.18.3",
"fs-extra": "7.0.1"
},
"scripts": {

View File

@@ -1,6 +1,6 @@
{
"name": "@now/node",
"version": "0.7.1",
"version": "0.7.2-canary.0",
"license": "MIT",
"main": "./dist/index",
"repository": {
@@ -10,7 +10,7 @@
},
"dependencies": {
"@now/node-bridge": "^1.1.2",
"@zeit/ncc": "0.18.2",
"@zeit/ncc": "0.18.3",
"fs-extra": "7.0.1"
},
"scripts": {

Binary file not shown.

View File

@@ -1,6 +1,6 @@
{
"name": "@now/rust",
"version": "0.2.3",
"version": "0.2.4-canary.0",
"license": "MIT",
"repository": {
"type": "git",

View File

@@ -28,11 +28,27 @@ async function runBuildLambda(inputPath) {
entrypoint,
config: build.config,
});
console.log(analyzeResult);
const workPath = await getWritableDirectory();
const buildResult = await wrapper.build({
files: inputFiles, entrypoint, config: build.config, workPath,
files: inputFiles,
entrypoint,
config: build.config,
workPath,
});
const { output } = buildResult;
// Windows support
if (output) {
buildResult.output = Object.keys(output).reduce(
(result, path) => ({
...result,
[path.replace(/\\/g, '/')]: output[path],
}),
{},
);
}
return {
analyzeResult,
buildResult,

View File

@@ -1135,10 +1135,10 @@
globby "8.0.0"
signal-exit "3.0.2"
"@zeit/ncc@0.18.2":
version "0.18.2"
resolved "https://registry.yarnpkg.com/@zeit/ncc/-/ncc-0.18.2.tgz#b5f721ec1d23bfe531f3568633689ddab7c05638"
integrity sha512-liiuVTcxLaOIGQDftpZ2qhSS/vdEbuvmi2tkBWMfIwIyeKd/sh/jw+l8yONT3/unx/sSmfMTDnwfwUlY+saKiw==
"@zeit/ncc@0.18.3":
version "0.18.3"
resolved "https://registry.yarnpkg.com/@zeit/ncc/-/ncc-0.18.3.tgz#6a84552c7b6710ab510f71e49546fff4e3b5c545"
integrity sha512-QNSNpHoh8medZXbmHHtJRZU3/2oemb3AjMrv/2fXBWCDPDmkDCRkE6V5PRrjdMQFvEN9SerhHWR8pp3IJF6Mww==
JSONStream@^1.0.4, JSONStream@^1.3.4:
version "1.3.5"