Compare commits

..

17 Commits

Author SHA1 Message Date
Steven
0b54093ca2 Publish
- @now/go@0.5.7
 - @now/node@0.12.3
 - @now/python@0.2.13
 - @now/routing-utils@1.2.1
 - @now/rust@0.2.10
 - @now/static-build@0.9.3
2019-08-01 16:10:17 -07:00
Steven
8c7371e093 Revert "[now-build-utils][now-static-build] Fix spawn options fo… (#867)
This reverts commit cf640a619e35c8cebaf6655799f273ba11bbd6e6.
2019-08-01 16:06:00 -07:00
Matthew Sweeney
e59c0f59f5 [now-static-build] Add sapper Optimization and Test (#865)
* add sapper optimization and test

* remove test dir

* remove test scripts
2019-08-01 15:28:16 -07:00
Steven
21b115a788 Update CODEOWNERS (#866) 2019-08-01 15:28:07 -07:00
Connor Davis
c5df4f7f9e [now-routing-utils] Make Now Routing Utils a Public Library (#860)
* Make Now Routing Utils a Public Library

* Suggestions

* Cleanup

* Update lockfile

* Add to dist to eslint ignore

* v1.2.0-canary.0

* v1.2.0-canary.1

* v1.2.1-canary.0

* Use optional dep instead of peer dep
2019-08-01 15:28:02 -07:00
Igor Klopov
2429451115 [now-rust] install rust in npm install of the builder (#863) 2019-08-01 15:27:45 -07:00
Andy
21789cdbf1 [now-build-utils][now-static-build] Fix spawn options for windows (#864)
* [now-build-utils][now-static-build] Fix spawn options for windows

* Fix type

* Fix types
2019-08-01 15:27:39 -07:00
Igor Klopov
f74ed2aff1 [now-go] install golang in npm install step (#859)
* [now-go] install golang in npm install step

* update

* move logic into now-install script

* remove unneeded items from gitignore

* now-postinstall
2019-08-01 15:27:28 -07:00
Steven
2f83e6375a [now-node] Bump node-file-trace to 0.2.6 (#861) 2019-08-01 15:27:23 -07:00
Kai Richard König
99a7b8f1f7 [now-python] Use pipfile2req to convert pipfile to requirements.txt (#857)
* Use a more robust library to convert pipfile - closes #841

* Renaming for clarity

* Suppress warnings since we know it will be invoked manually

Co-Authored-By: Steven <steven@ceriously.com>

* Apply the flag while installing not while generating the requirements.

Co-Authored-By: Steven <steven@ceriously.com>
2019-08-01 15:27:17 -07:00
Steven
3fa7b80bde Publish
- @now/build-utils@0.9.6
 - @now/next@0.5.8
 - @now/node@0.12.2
2019-07-31 08:30:21 -04:00
Steven
d012e73166 [now-node] Bump node-file-trace to 0.2.5 (#852) 2019-07-31 08:29:09 -04:00
Andy
d6c46da37f [now-build-utils] Remove @now/nuxt from default builders (#850) 2019-07-31 08:29:04 -04:00
Andy
1508932ad6 [now-static-build] Allow setting the tag for zero-config builders (#842)
* [now-static-build] Allow to set the `tag` for zero-config builders

This reverts commit 32b6f1d6a9047920d6cc40385de711022f77c4d4.

* Remove unsupported builders

* Fix setting the tag
2019-07-31 08:28:58 -04:00
Steven
873b099f53 [now-node] Bump node-file-trace to 0.2.4 (#849) 2019-07-31 08:28:52 -04:00
Steven
6546d3b67d [now-build-utils] Fix require file path for legacy builders (#846)
* [now-build-utils] Fix require file path

* Add more tests
2019-07-31 08:28:46 -04:00
Steven
34ad4ac33a [now-next] Fix dev-server bundle output (#847)
* [now-next] Fix dev-server bundle

* [now-next] Fix bundle output dev-server
2019-07-31 08:28:39 -04:00
59 changed files with 1617 additions and 40 deletions

View File

@@ -15,3 +15,4 @@
/packages/now-ruby/dist/*
/packages/now-static-build/dist/*
/packages/now-static-build/test/fixtures/**
/packages/now-routing-utils/dist/*

3
.github/CODEOWNERS vendored
View File

@@ -2,6 +2,7 @@
# https://help.github.com/en/articles/about-code-owners
* @styfle
/packages/now-build-utils @styfle @AndyBitz
/packages/now-node @styfle @tootallnate @lucleray
/packages/now-node-bridge @styfle @tootallnate @lucleray
/packages/now-next @timer
@@ -9,3 +10,5 @@
/packages/now-python @styfle @sophearak
/packages/now-rust @styfle @mike-engel @anmonteiro
/packages/now-ruby @styfle @coetry @nathancahill
/packages/now-static-build @styfle @AndyBitz
/packages/now-routing-utils @dav-is

View File

@@ -1 +1 @@
module.exports = require('../dist/fs/download').default;
module.exports = require('../dist/index').download;

View File

@@ -1 +1 @@
module.exports = require('../dist/fs/get-writable-directory').default;
module.exports = require('../dist/index').getWriteableDirectory;

View File

@@ -1 +1 @@
module.exports = require('../dist/fs/glob').default;
module.exports = require('../dist/index').glob;

View File

@@ -1 +1 @@
module.exports = require('../dist/fs/rename').default;
module.exports = require('../dist/index').rename;

View File

@@ -1 +1 @@
module.exports = require('../dist/fs/run-user-scripts');
module.exports = require('../dist/index');

View File

@@ -1 +1 @@
module.exports = require('../dist/fs/stream-to-buffer').default;
module.exports = require('../dist/index').streamToBuffer;

View File

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

View File

@@ -6,24 +6,24 @@ interface ErrorResponse {
message: string;
}
interface Options {
tag?: 'canary' | 'latest';
}
const src: string = 'package.json';
const config: Config = { zeroConfig: true };
// Static builders are special cased in `@now/static-build`
const BUILDERS = new Map<string, Builder>([
['next', { src, use: '@now/next', config }],
['nuxt', { src, use: '@now/nuxt', config }],
]);
const API_BUILDERS: Builder[] = [
{ src: 'api/**/*.js', use: '@now/node', config },
{ src: 'api/**/*.ts', use: '@now/node', config },
{ src: 'api/**/*.rs', use: '@now/rust', config },
{ src: 'api/**/*.go', use: '@now/go', config },
{ src: 'api/**/*.php', use: '@now/php', config },
{ src: 'api/**/*.py', use: '@now/python', config },
{ src: 'api/**/*.rb', use: '@now/ruby', config },
{ src: 'api/**/*.sh', use: '@now/bash', config },
];
const MISSING_BUILD_SCRIPT_ERROR: ErrorResponse = {
@@ -101,7 +101,8 @@ async function detectApiBuilders(files: string[]): Promise<Builder[]> {
// to determine what builders to use
export async function detectBuilders(
files: string[],
pkg?: PackageJson | undefined | null
pkg?: PackageJson | undefined | null,
options?: Options
): Promise<{
builders: Builder[] | null;
errors: ErrorResponse[] | null;
@@ -109,7 +110,7 @@ export async function detectBuilders(
const errors: ErrorResponse[] = [];
// Detect all builders for the `api` directory before anything else
const builders = await detectApiBuilders(files);
let builders = await detectApiBuilders(files);
if (pkg && hasBuildScript(pkg)) {
builders.push(await detectBuilder(pkg));
@@ -145,6 +146,22 @@ export async function detectBuilders(
}
}
// Change the tag for the builders
if (builders && builders.length) {
const tag = options && options.tag;
if (tag) {
builders = builders.map((builder: Builder) => {
// @now/static has no canary builder
if (builder.use !== '@now/static') {
builder.use = `${builder.use}@${tag}`;
}
return builder;
});
}
}
return {
builders: builders.length ? builders : null,
errors: errors.length ? errors : null,

View File

@@ -116,6 +116,36 @@ it('should match all semver ranges', () => {
);
});
it('should support require by path for legacy builders', () => {
const index = require('@now/build-utils');
const download2 = require('@now/build-utils/fs/download.js');
const getWriteableDirectory2 = require('@now/build-utils/fs/get-writable-directory.js');
const glob2 = require('@now/build-utils/fs/glob.js');
const rename2 = require('@now/build-utils/fs/rename.js');
const {
runNpmInstall: runNpmInstall2,
} = require('@now/build-utils/fs/run-user-scripts.js');
const streamToBuffer2 = require('@now/build-utils/fs/stream-to-buffer.js');
const FileBlob2 = require('@now/build-utils/file-blob.js');
const FileFsRef2 = require('@now/build-utils/file-fs-ref.js');
const FileRef2 = require('@now/build-utils/file-ref.js');
const { Lambda: Lambda2 } = require('@now/build-utils/lambda.js');
expect(download2).toBe(index.download);
expect(getWriteableDirectory2).toBe(index.getWriteableDirectory);
expect(glob2).toBe(index.glob);
expect(rename2).toBe(index.rename);
expect(runNpmInstall2).toBe(index.runNpmInstall);
expect(streamToBuffer2).toBe(index.streamToBuffer);
expect(FileBlob2).toBe(index.FileBlob);
expect(FileFsRef2).toBe(index.FileFsRef);
expect(FileRef2).toBe(index.FileRef);
expect(Lambda2).toBe(index.Lambda);
});
// own fixtures
const fixturesPath = path.resolve(__dirname, 'fixtures');
@@ -355,7 +385,7 @@ it('Test `detectBuilders`', async () => {
const files = ['package.json', 'pages/index.js'];
const { builders } = await detectBuilders(files, pkg);
expect(builders[0].use).toBe('@now/nuxt');
expect(builders[0].use).toBe('@now/static-build');
expect(builders[0].src).toBe('package.json');
expect(builders.length).toBe(1);
}
@@ -397,6 +427,25 @@ it('Test `detectBuilders`', async () => {
expect(builders).toBe(null);
expect(errors).toBe(null);
}
{
// package.json + api + canary
const pkg = {
scripts: { build: 'next build' },
dependencies: { next: '9.0.0' },
};
const files = [
'pages/index.js',
'api/[endpoint].js',
'api/[endpoint]/[id].js',
];
const { builders } = await detectBuilders(files, pkg, { tag: 'canary' });
expect(builders[0].use).toBe('@now/node@canary');
expect(builders[1].use).toBe('@now/node@canary');
expect(builders[2].use).toBe('@now/next@canary');
expect(builders.length).toBe(3);
}
});
it('Test `detectRoutes`', async () => {

View File

@@ -3,4 +3,3 @@ node_modules
/go
/analyze
*.js
!util/install.js

View File

@@ -0,0 +1,6 @@
import { downloadGo } from './go-helpers';
downloadGo().catch(err => {
console.error(err);
process.exit(1);
});

View File

@@ -1,6 +1,6 @@
{
"name": "@now/go",
"version": "0.5.6",
"version": "0.5.7",
"license": "MIT",
"homepage": "https://zeit.co/docs/v2/deployments/official-builders/go-now-go",
"repository": {
@@ -11,7 +11,8 @@
"scripts": {
"build": "tsc",
"test": "tsc && jest",
"prepublish": "tsc"
"prepublish": "tsc",
"now-postinstall": "node install.js"
},
"files": [
"*.js",

View File

@@ -7,6 +7,10 @@ cp -v "$bridge_defs" src/now__bridge.ts
tsc
ncc build src/dev-server.ts -o dist/dev
mv dist/dev/index.js dist/dev-server.js
rm -rf dist/dev
ncc build src/index.ts -o dist/main
mv dist/main/index.js dist/index.js
rm -rf dist/main

View File

@@ -1,6 +1,6 @@
{
"name": "@now/next",
"version": "0.5.7",
"version": "0.5.8",
"license": "MIT",
"main": "./dist/index",
"homepage": "https://zeit.co/docs/v2/deployments/official-builders/next-js-now-next",

View File

@@ -0,0 +1,13 @@
describe('export', () => {
it('should require by path main', async () => {
const main = require('@now/next');
expect(main).toBeDefined();
});
it('should require by path dev-server relative to index', async () => {
const index = require('@now/next/dist/index.js');
const server = require('@now/next/dist/dev-server.js');
expect(index).toBeDefined();
expect(server).toBeDefined();
});
});

View File

@@ -1,6 +1,6 @@
{
"name": "@now/node",
"version": "0.12.1",
"version": "0.12.3",
"license": "MIT",
"main": "./dist/index",
"homepage": "https://zeit.co/docs/v2/deployments/official-builders/node-js-now-node",
@@ -28,7 +28,7 @@
"@types/etag": "1.8.0",
"@types/test-listen": "1.1.0",
"@zeit/ncc": "0.20.4",
"@zeit/node-file-trace": "0.2.3",
"@zeit/node-file-trace": "0.2.6",
"content-type": "1.0.4",
"cookie": "0.4.0",
"etag": "1.8.1",

View File

@@ -1,6 +1,6 @@
{
"name": "@now/python",
"version": "0.2.12",
"version": "0.2.13",
"main": "./dist/index.js",
"license": "MIT",
"homepage": "https://zeit.co/docs/v2/deployments/official-builders/python-now-python",

View File

@@ -71,14 +71,14 @@ async function pipInstallUser(pipPath: string, ...args: string[]) {
}
async function pipenvInstall(pyUserBase: string, srcDir: string) {
console.log('running "pipenv_to_requirements -f');
console.log('running pipfile2req');
try {
await execa(join(pyUserBase, 'bin', 'pipenv_to_requirements'), ['-f'], {
const out = await execa.stdout(join(pyUserBase, 'bin', 'pipfile2req'), [], {
cwd: srcDir,
stdio: 'inherit',
});
fs.writeFileSync(join(srcDir, 'requirements.txt'), out);
} catch (err) {
console.log('failed to run "pipenv_to_requirements -f"');
console.log('failed to run "pipfile2req"');
throw err;
}
}
@@ -145,8 +145,7 @@ export const build = async ({
console.log('found "Pipfile.lock"');
// Install pipenv.
await pipInstallUser(pipPath, ' pipenv_to_requirements');
await pipInstallUser(pipPath, 'pipfile-requirements', '--no-warn-script-location');
await pipenvInstall(pyUserBase, pipfileLockDir);
}

1
packages/now-routing-utils/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/dist

View File

@@ -0,0 +1,20 @@
# @now/routing-utils
Route validation utilities
## Usage
`yarn add @now/routing-utils`
exports.normalizeRoutes:
`(routes: Array<Route> | null) => { routes: Array<Route> | null; error: NowError | null }`
exports.schema:
```js
const ajv = new Ajv();
const validate = ajv.compile(schema);
const valid = validate([{ src: '/about', dest: '/about.html' }]);
if (!valid) console.log(validate.errors);
```

View File

@@ -0,0 +1,29 @@
{
"name": "@now/routing-utils",
"version": "1.2.1",
"description": "ZEIT Now route validation utilities",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"repository": {
"type": "git",
"url": "https://github.com/zeit/now-builders.git",
"directory": "packages/now-routing-utils"
},
"license": "MIT",
"scripts": {
"prepublishOnly": "tsc",
"build": "tsc",
"watch": "tsc --watch",
"test": "tsc && jest"
},
"devDependencies": {
"ajv": "^6.0.0",
"typescript": "3.5.2"
},
"optionalDependencies": {
"ajv": "^6.0.0"
}
}

View File

@@ -0,0 +1,175 @@
export type NowError = {
code: string;
message: string;
errors: {
message: string;
src?: string;
handle?: string;
}[];
sha?: string; // File errors
};
export type Source = {
src: string;
dest?: string;
headers?: {};
methods?: string[];
continue?: boolean;
status?: number;
};
export type Handler = {
handle: string;
};
export type Route = Source | Handler;
export function isHandler(route: Route): route is Handler {
return typeof (<Handler>route).handle !== 'undefined';
}
export function normalizeRoutes(
inputRoutes: Array<Route> | null
): { routes: Array<Route> | null; error: NowError | null } {
if (!inputRoutes || inputRoutes.length === 0) {
return { routes: inputRoutes, error: null };
}
const routes: Route[] = [];
const handling: string[] = [];
const errors = [];
// We don't want to treat the input routes as references
inputRoutes.forEach(r => routes.push(Object.assign({}, r)));
for (const route of routes) {
if (isHandler(route)) {
// typeof { handle: string }
if (Object.keys(route).length !== 1) {
errors.push({
message: `Cannot have any other keys when handle is used (handle: ${
route.handle
})`,
handle: route.handle,
});
}
if (!['filesystem'].includes(route.handle)) {
errors.push({
message: `This is not a valid handler (handle: ${route.handle})`,
handle: route.handle,
});
}
if (handling.includes(route.handle)) {
errors.push({
message: `You can only handle something once (handle: ${
route.handle
})`,
handle: route.handle,
});
} else {
handling.push(route.handle);
}
} else if (route.src) {
// typeof normal route
if (route.continue && route.dest) {
errors.push({
message: `Cannot use both continue and dest`,
src: route.src,
});
}
// Route src should always start with a '^'
if (!route.src.startsWith('^')) {
route.src = `^${route.src}`;
}
// Route src should always end with a '$'
if (!route.src.endsWith('$')) {
route.src = `${route.src}$`;
}
try {
// This feels a bit dangerous if there would be a vulnerability in RegExp.
new RegExp(route.src);
} catch (err) {
errors.push({
message: `Invalid regular expression: "${route.src}"`,
src: route.src,
});
}
} else {
errors.push({
message: 'A route must set either handle or src',
});
}
}
const error =
errors.length > 0
? {
code: 'invalid_routes',
message: `One or more invalid routes were found: \n${JSON.stringify(
errors,
null,
2
)}`,
errors,
}
: null;
return { routes, error };
}
/**
* An ajv schema for the routes array
*/
export const schema = {
type: 'array',
maxItems: 1024,
items: {
type: 'object',
additionalProperties: false,
properties: {
src: {
type: 'string',
maxLength: 4096,
},
dest: {
type: 'string',
maxLength: 4096,
},
methods: {
type: 'array',
maxItems: 10,
items: {
type: 'string',
maxLength: 32,
},
},
headers: {
type: 'object',
additionalProperties: false,
minProperties: 1,
maxProperties: 100,
patternProperties: {
'^.{1,256}$': {
type: 'string',
maxLength: 4096,
},
},
},
handle: {
type: 'string',
maxLength: 32,
},
continue: {
type: 'boolean',
},
status: {
type: 'integer',
minimum: 100,
maximum: 999,
},
},
},
};

View File

@@ -0,0 +1,406 @@
const assert = require('assert');
const Ajv = require('ajv');
const { normalizeRoutes, isHandler, schema } = require('../dist');
const ajv = new Ajv();
const assertValid = (routes) => {
const validate = ajv.compile(schema);
const valid = validate(routes);
if (!valid) console.log(validate.errors);
assert.equal(valid, true);
};
const assertError = (routes, errors) => {
const validate = ajv.compile(schema);
const valid = validate(routes);
assert.equal(valid, false);
assert.deepEqual(validate.errors, errors);
};
describe('normalizeRoutes', () => {
test('accepts valid routes', () => {
const routes = [
{ src: '^/about$' },
{
src: '^/blog$',
methods: ['GET'],
headers: { 'Cache-Control': 'no-cache' },
dest: '/blog',
},
{ handle: 'filesystem' },
{ src: '^/(?<slug>[^/]+)$', dest: 'blog?slug=$slug' },
];
assertValid(routes);
const normalized = normalizeRoutes(routes);
assert.equal(normalized.error, null);
assert.deepStrictEqual(normalized.routes, routes);
});
test('normalizes src', () => {
const expected = '^/about$';
const expected2 = '^\\/about$';
const sources = [
{ src: '/about' },
{ src: '/about$' },
{ src: '\\/about' },
{ src: '\\/about$' },
{ src: '^/about' },
{ src: '^/about$' },
{ src: '^\\/about' },
{ src: '^\\/about$' },
];
assertValid(sources);
const normalized = normalizeRoutes(sources);
assert.equal(normalized.error, null);
assert.notEqual(normalized.routes, null);
if (normalized.routes) {
normalized.routes.forEach((route) => {
if (isHandler(route)) {
assert.fail(
`Normalizer returned: { handle: ${
route.handle
} } instead of { src: ${expected} }`,
);
} else {
assert.ok(route.src === expected || route.src === expected2);
}
});
}
});
test('returns if null', () => {
const input = null;
const { error, routes } = normalizeRoutes(input);
assert.strictEqual(error, null);
assert.strictEqual(routes, input);
});
test('returns if empty', () => {
const input = [];
const { error, routes } = normalizeRoutes(input);
assert.strictEqual(error, null);
assert.strictEqual(routes, input);
});
test('fails with abnormal routes', () => {
const errors = [];
const routes = [];
routes.push({ handle: 'doesnotexist' });
errors.push({
message: 'This is not a valid handler (handle: doesnotexist)',
handle: 'doesnotexist',
});
// @ts-ignore
routes.push({ handle: 'filesystem', illegal: true });
errors.push({
message:
'Cannot have any other keys when handle is used (handle: filesystem)',
handle: 'filesystem',
});
routes.push({ handle: 'filesystem' });
errors.push({
message: 'You can only handle something once (handle: filesystem)',
handle: 'filesystem',
});
routes.push({ src: '^/about$', dest: '/about', continue: true });
errors.push({
message: 'Cannot use both continue and dest',
src: '^/about$',
});
routes.push({ src: '^/(broken]$' });
errors.push({
message: 'Invalid regular expression: "^/(broken]$"',
src: '^/(broken]$',
});
// @ts-ignore
routes.push({ doesNotExist: true });
errors.push({
message: 'A route must set either handle or src',
});
// @ts-ignore
routes.push({ src: '^/about$', doesNotExist: true });
const normalized = normalizeRoutes(routes);
assert.deepStrictEqual(normalized.routes, routes);
assert.deepStrictEqual(normalized.error, {
code: 'invalid_routes',
message: `One or more invalid routes were found: \n${JSON.stringify(
errors,
null,
2,
)}`,
errors,
});
});
test('fails if over 1024 routes', () => {
// @ts-ignore
assertError('string', [
{
dataPath: '',
keyword: 'type',
message: 'should be array',
params: {
type: 'array',
},
schemaPath: '#/type',
},
]);
const arr = new Array(1026);
arr.fill(true);
// @ts-ignore
assertError(arr, [
{
dataPath: '',
keyword: 'maxItems',
message: 'should NOT have more than 1024 items',
params: {
limit: '1024',
},
schemaPath: '#/maxItems',
},
]);
});
test('fails is src is not string', () => {
assertError(
[
// @ts-ignore
{
src: false,
},
],
[
{
dataPath: '[0].src',
keyword: 'type',
message: 'should be string',
params: {
type: 'string',
},
schemaPath: '#/items/properties/src/type',
},
],
);
});
test('fails if dest is not string', () => {
assertError(
[
// @ts-ignore
{
dest: false,
},
],
[
{
dataPath: '[0].dest',
keyword: 'type',
message: 'should be string',
params: {
type: 'string',
},
schemaPath: '#/items/properties/dest/type',
},
],
);
});
test('fails if methods is not array', () => {
assertError(
[
// @ts-ignore
{
methods: false,
},
],
[
{
dataPath: '[0].methods',
keyword: 'type',
message: 'should be array',
params: {
type: 'array',
},
schemaPath: '#/items/properties/methods/type',
},
],
);
});
test('fails if methods is not string', () => {
assertError(
[
// @ts-ignore
{
methods: [false],
},
],
[
{
dataPath: '[0].methods[0]',
keyword: 'type',
message: 'should be string',
params: {
type: 'string',
},
schemaPath: '#/items/properties/methods/items/type',
},
],
);
});
test('fails if headers is not an object', () => {
assertError(
[
// @ts-ignore
{
headers: false,
},
],
[
{
dataPath: '[0].headers',
keyword: 'type',
message: 'should be object',
params: {
type: 'object',
},
schemaPath: '#/items/properties/headers/type',
},
],
);
});
test('fails if header is not a string', () => {
assertError(
[
// @ts-ignore
{
headers: {
test: false,
},
},
],
[
{
dataPath: "[0].headers['test']",
keyword: 'type',
message: 'should be string',
params: {
type: 'string',
},
schemaPath:
'#/items/properties/headers/patternProperties/%5E.%7B1%2C256%7D%24/type',
},
],
);
});
test('fails if handle is not string', () => {
assertError(
[
// @ts-ignore
{
handle: false,
},
],
[
{
dataPath: '[0].handle',
keyword: 'type',
message: 'should be string',
params: {
type: 'string',
},
schemaPath: '#/items/properties/handle/type',
},
],
);
});
test('fails if continue is not boolean', () => {
assertError(
[
// @ts-ignore
{
continue: 'false',
},
],
[
{
dataPath: '[0].continue',
keyword: 'type',
message: 'should be boolean',
params: {
type: 'boolean',
},
schemaPath: '#/items/properties/continue/type',
},
],
);
});
test('fails if status is not number', () => {
assertError(
[
// @ts-ignore
{
status: '404',
},
],
[
{
dataPath: '[0].status',
keyword: 'type',
message: 'should be integer',
params: {
type: 'integer',
},
schemaPath: '#/items/properties/status/type',
},
],
);
});
test('fails if property does not exist', () => {
assertError(
[
{
// @ts-ignore
doesNotExist: false,
},
],
[
{
dataPath: '[0]',
keyword: 'additionalProperties',
message: 'should NOT have additional properties',
params: {
additionalProperty: 'doesNotExist',
},
schemaPath: '#/items/additionalProperties',
},
],
);
});
});

View File

@@ -0,0 +1,15 @@
{
"compilerOptions": {
"strict": true,
"esModuleInterop": true,
"lib": ["esnext"],
"target": "esnext",
"module": "commonjs",
"outDir": "dist",
"sourceMap": false,
"declaration": true,
"typeRoots": ["./@types", "./node_modules/@types"]
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}

View File

@@ -1,6 +1,6 @@
{
"name": "@now/rust",
"version": "0.2.9",
"version": "0.2.10",
"license": "MIT",
"main": "./dist/index",
"homepage": "https://zeit.co/docs/v2/deployments/official-builders/now-rust",
@@ -13,7 +13,8 @@
"build": "tsc",
"test": "tsc && jest",
"prepublish": "tsc",
"typecheck": "tsc --noEmit"
"typecheck": "tsc --noEmit",
"now-postinstall": "node dist/install.js"
},
"files": [
"dist",

View File

@@ -14,7 +14,6 @@ import {
DownloadedFiles,
Lambda,
} from '@now/build-utils'; // eslint-disable-line import/no-extraneous-dependencies
import installRust from './install-rust';
interface PackageManifest {
targets: { kind: string; name: string }[];
@@ -275,10 +274,6 @@ export async function build(opts: BuildOptions) {
const downloadedFiles = await download(files, workPath, meta);
const entryPath = downloadedFiles[entrypoint].fsPath;
if (!meta.isDev) {
await installRust(config.rust);
}
const { PATH, HOME } = process.env;
const rustEnv: Record<string, string> = {
...process.env,

View File

@@ -0,0 +1,6 @@
import installRust from './install-rust';
installRust().catch(err => {
console.error(err);
process.exit(1);
});

View File

@@ -1,6 +1,6 @@
{
"name": "@now/static-build",
"version": "0.9.2",
"version": "0.9.3",
"license": "MIT",
"main": "./dist/index",
"homepage": "https://zeit.co/docs/v2/deployments/official-builders/static-build-now-static-build",

View File

@@ -227,4 +227,9 @@ export default [
return base;
},
},
{
name: 'Sapper',
dependency: 'sapper',
getOutputDirName: async () => '__sapper__/export',
},
];

View File

@@ -0,0 +1,6 @@
.DS_Store
/node_modules/
/src/node_modules/@sapper/
yarn-error.log
/cypress/screenshots/
/__sapper__/

View File

@@ -0,0 +1,88 @@
# sapper-template
The default [Sapper](https://github.com/sveltejs/sapper) template, with branches for Rollup and webpack. To clone it and get started:
```bash
# for Rollup
npx degit "sveltejs/sapper-template#rollup" my-app
# for webpack
npx degit "sveltejs/sapper-template#webpack" my-app
cd my-app
npm install # or yarn!
npm run dev
```
Open up [localhost:3000](http://localhost:3000) and start clicking around.
Consult [sapper.svelte.dev](https://sapper.svelte.dev) for help getting started.
## Structure
Sapper expects to find two directories in the root of your project — `src` and `static`.
### src
The [src](src) directory contains the entry points for your app — `client.js`, `server.js` and (optionally) a `service-worker.js` — along with a `template.html` file and a `routes` directory.
#### src/routes
This is the heart of your Sapper app. There are two kinds of routes — *pages*, and *server routes*.
**Pages** are Svelte components written in `.svelte` files. When a user first visits the application, they will be served a server-rendered version of the route in question, plus some JavaScript that 'hydrates' the page and initialises a client-side router. From that point forward, navigating to other pages is handled entirely on the client for a fast, app-like feel. (Sapper will preload and cache the code for these subsequent pages, so that navigation is instantaneous.)
**Server routes** are modules written in `.js` files, that export functions corresponding to HTTP methods. Each function receives Express `request` and `response` objects as arguments, plus a `next` function. This is useful for creating a JSON API, for example.
There are three simple rules for naming the files that define your routes:
* A file called `src/routes/about.svelte` corresponds to the `/about` route. A file called `src/routes/blog/[slug].svelte` corresponds to the `/blog/:slug` route, in which case `params.slug` is available to the route
* The file `src/routes/index.svelte` (or `src/routes/index.js`) corresponds to the root of your app. `src/routes/about/index.svelte` is treated the same as `src/routes/about.svelte`.
* Files and directories with a leading underscore do *not* create routes. This allows you to colocate helper modules and components with the routes that depend on them — for example you could have a file called `src/routes/_helpers/datetime.js` and it would *not* create a `/_helpers/datetime` route
### static
The [static](static) directory contains any static assets that should be available. These are served using [sirv](https://github.com/lukeed/sirv).
In your [service-worker.js](src/service-worker.js) file, you can import these as `files` from the generated manifest...
```js
import { files } from '@sapper/service-worker';
```
...so that you can cache them (though you can choose not to, for example if you don't want to cache very large files).
## Bundler config
Sapper uses Rollup or webpack to provide code-splitting and dynamic imports, as well as compiling your Svelte components. With webpack, it also provides hot module reloading. As long as you don't do anything daft, you can edit the configuration files to add whatever plugins you'd like.
## Production mode and deployment
To start a production version of your app, run `npm run build && npm start`. This will disable live reloading, and activate the appropriate bundler plugins.
You can deploy your application to any environment that supports Node 8 or above. As an example, to deploy to [Now](https://zeit.co/now), run these commands:
```bash
npm install -g now
now
```
## Using external components
When using Svelte components installed from npm, such as [@sveltejs/svelte-virtual-list](https://github.com/sveltejs/svelte-virtual-list), Svelte needs the original component source (rather than any precompiled JavaScript that ships with the component). This allows the component to be rendered server-side, and also keeps your client-side app smaller.
Because of that, it's essential that the bundler doesn't treat the package as an *external dependency*. You can either modify the `external` option under `server` in [rollup.config.js](rollup.config.js) or the `externals` option in [webpack.config.js](webpack.config.js), or simply install the package to `devDependencies` rather than `dependencies`, which will cause it to get bundled (and therefore compiled) with your app:
```bash
npm install -D @sveltejs/svelte-virtual-list
```
## Bugs and feedback
Sapper is in early development, and may have the odd rough edge here and there. Please be vocal over on the [Sapper issue tracker](https://github.com/sveltejs/sapper/issues).

View File

@@ -0,0 +1,18 @@
version: "{build}"
shallow_clone: true
init:
- git config --global core.autocrlf false
build: off
environment:
matrix:
# node.js
- nodejs_version: stable
install:
- ps: Install-Product node $env:nodejs_version
- npm install cypress
- npm install

View File

@@ -0,0 +1,4 @@
{
"baseUrl": "http://localhost:3000",
"video": false
}

View File

@@ -0,0 +1,15 @@
{
"version": 2,
"builds": [
{
"src": "package.json",
"use": "@now/static-build",
"config": { "zeroConfig": true }
}
],
"probes": [
{ "path": "/", "mustContain": "Great" },
{ "path": "/about", "mustContain": "page" },
{ "path": "/blog", "mustContain": "posts" }
]
}

View File

@@ -0,0 +1,22 @@
{
"name": "TODO",
"description": "TODO",
"version": "0.0.1",
"scripts": {
"dev": "sapper dev",
"build": "sapper export",
"start": "node __sapper__/build"
},
"dependencies": {
"compression": "^1.7.1",
"polka": "next",
"sirv": "^0.4.0"
},
"devDependencies": {
"npm-run-all": "^4.1.5",
"sapper": "^0.27.0",
"svelte": "^3.0.0",
"svelte-loader": "^2.9.0",
"webpack": "^4.7.0"
}
}

View File

@@ -0,0 +1,5 @@
import * as sapper from '@sapper/app';
sapper.start({
target: document.querySelector('#sapper')
});

View File

@@ -0,0 +1,60 @@
<script>
export let segment;
</script>
<style>
nav {
border-bottom: 1px solid rgba(255,62,0,0.1);
font-weight: 300;
padding: 0 1em;
}
ul {
margin: 0;
padding: 0;
}
/* clearfix */
ul::after {
content: '';
display: block;
clear: both;
}
li {
display: block;
float: left;
}
.selected {
position: relative;
display: inline-block;
}
.selected::after {
position: absolute;
content: '';
width: calc(100% - 1em);
height: 2px;
background-color: rgb(255,62,0);
display: block;
bottom: -1px;
}
a {
text-decoration: none;
padding: 1em 0.5em;
display: block;
}
</style>
<nav>
<ul>
<li><a class='{segment === undefined ? "selected" : ""}' href='.'>home</a></li>
<li><a class='{segment === "about" ? "selected" : ""}' href='about'>about</a></li>
<!-- for the blog link, we're using rel=prefetch so that Sapper prefetches
the blog data when we hover over the link or tap it on a touchscreen -->
<li><a rel=prefetch class='{segment === "blog" ? "selected" : ""}' href='blog'>blog</a></li>
</ul>
</nav>

View File

@@ -0,0 +1,40 @@
<script>
export let status;
export let error;
const dev = process.env.NODE_ENV === 'development';
</script>
<style>
h1, p {
margin: 0 auto;
}
h1 {
font-size: 2.8em;
font-weight: 700;
margin: 0 0 0.5em 0;
}
p {
margin: 1em auto;
}
@media (min-width: 480px) {
h1 {
font-size: 4em;
}
}
</style>
<svelte:head>
<title>{status}</title>
</svelte:head>
<h1>{status}</h1>
<p>{error.message}</p>
{#if dev && error.stack}
<pre>{error.stack}</pre>
{/if}

View File

@@ -0,0 +1,22 @@
<script>
import Nav from '../components/Nav.svelte';
export let segment;
</script>
<style>
main {
position: relative;
max-width: 56em;
background-color: white;
padding: 2em;
margin: 0 auto;
box-sizing: border-box;
}
</style>
<Nav {segment}/>
<main>
<slot></slot>
</main>

View File

@@ -0,0 +1,7 @@
<svelte:head>
<title>About</title>
</svelte:head>
<h1>About this site</h1>
<p>This is the 'about' page. There's not much here.</p>

View File

@@ -0,0 +1,28 @@
import posts from './_posts.js';
const lookup = new Map();
posts.forEach(post => {
lookup.set(post.slug, JSON.stringify(post));
});
export function get(req, res, next) {
// the `slug` parameter is available because
// this file is called [slug].json.js
const { slug } = req.params;
if (lookup.has(slug)) {
res.writeHead(200, {
'Content-Type': 'application/json'
});
res.end(lookup.get(slug));
} else {
res.writeHead(404, {
'Content-Type': 'application/json'
});
res.end(JSON.stringify({
message: `Not found`
}));
}
}

View File

@@ -0,0 +1,64 @@
<script context="module">
export async function preload({ params, query }) {
// the `slug` parameter is available because
// this file is called [slug].svelte
const res = await this.fetch(`blog/${params.slug}.json`);
const data = await res.json();
if (res.status === 200) {
return { post: data };
} else {
this.error(res.status, data.message);
}
}
</script>
<script>
export let post;
</script>
<style>
/*
By default, CSS is locally scoped to the component,
and any unused styles are dead-code-eliminated.
In this page, Svelte can't know which elements are
going to appear inside the {{{post.html}}} block,
so we have to use the :global(...) modifier to target
all elements inside .content
*/
.content :global(h2) {
font-size: 1.4em;
font-weight: 500;
}
.content :global(pre) {
background-color: #f9f9f9;
box-shadow: inset 1px 1px 5px rgba(0,0,0,0.05);
padding: 0.5em;
border-radius: 2px;
overflow-x: auto;
}
.content :global(pre) :global(code) {
background-color: transparent;
padding: 0;
}
.content :global(ul) {
line-height: 1.5;
}
.content :global(li) {
margin: 0 0 0.5em 0;
}
</style>
<svelte:head>
<title>{post.title}</title>
</svelte:head>
<h1>{post.title}</h1>
<div class='content'>
{@html post.html}
</div>

View File

@@ -0,0 +1,92 @@
// Ordinarily, you'd generate this data from markdown files in your
// repo, or fetch them from a database of some kind. But in order to
// avoid unnecessary dependencies in the starter template, and in the
// service of obviousness, we're just going to leave it here.
// This file is called `_posts.js` rather than `posts.js`, because
// we don't want to create an `/blog/posts` route — the leading
// underscore tells Sapper not to do that.
const posts = [
{
title: 'What is Sapper?',
slug: 'what-is-sapper',
html: `
<p>First, you have to know what <a href='https://svelte.dev'>Svelte</a> is. Svelte is a UI framework with a bold new idea: rather than providing a library that you write code with (like React or Vue, for example), it's a compiler that turns your components into highly optimized vanilla JavaScript. If you haven't already read the <a href='https://svelte.dev/blog/frameworks-without-the-framework'>introductory blog post</a>, you should!</p>
<p>Sapper is a Next.js-style framework (<a href='blog/how-is-sapper-different-from-next'>more on that here</a>) built around Svelte. It makes it embarrassingly easy to create extremely high performance web apps. Out of the box, you get:</p>
<ul>
<li>Code-splitting, dynamic imports and hot module replacement, powered by webpack</li>
<li>Server-side rendering (SSR) with client-side hydration</li>
<li>Service worker for offline support, and all the PWA bells and whistles</li>
<li>The nicest development experience you've ever had, or your money back</li>
</ul>
<p>It's implemented as Express middleware. Everything is set up and waiting for you to get started, but you keep complete control over the server, service worker, webpack config and everything else, so it's as flexible as you need it to be.</p>
`
},
{
title: 'How to use Sapper',
slug: 'how-to-use-sapper',
html: `
<h2>Step one</h2>
<p>Create a new project, using <a href='https://github.com/Rich-Harris/degit'>degit</a>:</p>
<pre><code>npx degit "sveltejs/sapper-template#rollup" my-app
cd my-app
npm install # or yarn!
npm run dev
</code></pre>
<h2>Step two</h2>
<p>Go to <a href='http://localhost:3000'>localhost:3000</a>. Open <code>my-app</code> in your editor. Edit the files in the <code>src/routes</code> directory or add new ones.</p>
<h2>Step three</h2>
<p>...</p>
<h2>Step four</h2>
<p>Resist overdone joke formats.</p>
`
},
{
title: 'Why the name?',
slug: 'why-the-name',
html: `
<p>In war, the soldiers who build bridges, repair roads, clear minefields and conduct demolitions — all under combat conditions — are known as <em>sappers</em>.</p>
<p>For web developers, the stakes are generally lower than those for combat engineers. But we face our own hostile environment: underpowered devices, poor network connections, and the complexity inherent in front-end engineering. Sapper, which is short for <strong>S</strong>velte <strong>app</strong> mak<strong>er</strong>, is your courageous and dutiful ally.</p>
`
},
{
title: 'How is Sapper different from Next.js?',
slug: 'how-is-sapper-different-from-next',
html: `
<p><a href='https://github.com/zeit/next.js'>Next.js</a> is a React framework from <a href='https://zeit.co'>Zeit</a>, and is the inspiration for Sapper. There are a few notable differences, however:</p>
<ul>
<li>It's powered by <a href='https://svelte.dev'>Svelte</a> instead of React, so it's faster and your apps are smaller</li>
<li>Instead of route masking, we encode route parameters in filenames. For example, the page you're looking at right now is <code>src/routes/blog/[slug].html</code></li>
<li>As well as pages (Svelte components, which render on server or client), you can create <em>server routes</em> in your <code>routes</code> directory. These are just <code>.js</code> files that export functions corresponding to HTTP methods, and receive Express <code>request</code> and <code>response</code> objects as arguments. This makes it very easy to, for example, add a JSON API such as the one <a href='blog/how-is-sapper-different-from-next.json'>powering this very page</a></li>
<li>Links are just <code>&lt;a&gt;</code> elements, rather than framework-specific <code>&lt;Link&gt;</code> components. That means, for example, that <a href='blog/how-can-i-get-involved'>this link right here</a>, despite being inside a blob of HTML, works with the router as you'd expect.</li>
</ul>
`
},
{
title: 'How can I get involved?',
slug: 'how-can-i-get-involved',
html: `
<p>We're so glad you asked! Come on over to the <a href='https://github.com/sveltejs/svelte'>Svelte</a> and <a href='https://github.com/sveltejs/sapper'>Sapper</a> repos, and join us in the <a href='https://svelte.dev/chat'>Discord chatroom</a>. Everyone is welcome, especially you!</p>
`
}
];
posts.forEach(post => {
post.html = post.html.replace(/^\t{3}/gm, '');
});
export default posts;

View File

@@ -0,0 +1,16 @@
import posts from './_posts.js';
const contents = JSON.stringify(posts.map(post => {
return {
title: post.title,
slug: post.slug
};
}));
export function get(req, res) {
res.writeHead(200, {
'Content-Type': 'application/json'
});
res.end(contents);
}

View File

@@ -0,0 +1,34 @@
<script context="module">
export function preload({ params, query }) {
return this.fetch(`blog.json`).then(r => r.json()).then(posts => {
return { posts };
});
}
</script>
<script>
export let posts;
</script>
<style>
ul {
margin: 0 0 1em 0;
line-height: 1.5;
}
</style>
<svelte:head>
<title>Blog</title>
</svelte:head>
<h1>Recent posts</h1>
<ul>
{#each posts as post}
<!-- we're using the non-standard `rel=prefetch` attribute to
tell Sapper to load the data for the page as soon as
the user hovers over the link or taps it, instead of
waiting for the 'click' event -->
<li><a rel='prefetch' href='blog/{post.slug}'>{post.title}</a></li>
{/each}
</ul>

View File

@@ -0,0 +1,46 @@
<style>
h1, figure, p {
text-align: center;
margin: 0 auto;
}
h1 {
font-size: 2.8em;
text-transform: uppercase;
font-weight: 700;
margin: 0 0 0.5em 0;
}
figure {
margin: 0 0 1em 0;
}
img {
width: 100%;
max-width: 400px;
margin: 0 0 1em 0;
}
p {
margin: 1em auto;
}
@media (min-width: 480px) {
h1 {
font-size: 4em;
}
}
</style>
<svelte:head>
<title>Sapper project template</title>
</svelte:head>
<h1>Great success!</h1>
<figure>
<img alt='Borat' src='great-success.png'>
<figcaption>HIGH FIVE!</figcaption>
</figure>
<p><strong>Try editing this file (src/routes/index.svelte) to test live reloading.</strong></p>

View File

@@ -0,0 +1,17 @@
import sirv from 'sirv';
import polka from 'polka';
import compression from 'compression';
import * as sapper from '@sapper/server';
const { PORT, NODE_ENV } = process.env;
const dev = NODE_ENV === 'development';
polka() // You can also use Express
.use(
compression({ threshold: 0 }),
sirv('static', { dev }),
sapper.middleware()
)
.listen(PORT, err => {
if (err) console.log('error', err);
});

View File

@@ -0,0 +1,82 @@
import { timestamp, files, shell, routes } from '@sapper/service-worker';
const ASSETS = `cache${timestamp}`;
// `shell` is an array of all the files generated by the bundler,
// `files` is an array of everything in the `static` directory
const to_cache = shell.concat(files);
const cached = new Set(to_cache);
self.addEventListener('install', event => {
event.waitUntil(
caches
.open(ASSETS)
.then(cache => cache.addAll(to_cache))
.then(() => {
self.skipWaiting();
})
);
});
self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(async keys => {
// delete old caches
for (const key of keys) {
if (key !== ASSETS) await caches.delete(key);
}
self.clients.claim();
})
);
});
self.addEventListener('fetch', event => {
if (event.request.method !== 'GET' || event.request.headers.has('range')) return;
const url = new URL(event.request.url);
// don't try to handle e.g. data: URIs
if (!url.protocol.startsWith('http')) return;
// ignore dev server requests
if (url.hostname === self.location.hostname && url.port !== self.location.port) return;
// always serve static files and bundler-generated assets from cache
if (url.host === self.location.host && cached.has(url.pathname)) {
event.respondWith(caches.match(event.request));
return;
}
// for pages, you might want to serve a shell `service-worker-index.html` file,
// which Sapper has generated for you. It's not right for every
// app, but if it's right for yours then uncomment this section
/*
if (url.origin === self.origin && routes.find(route => route.pattern.test(url.pathname))) {
event.respondWith(caches.match('/service-worker-index.html'));
return;
}
*/
if (event.request.cache === 'only-if-cached') return;
// for everything else, try the network first, falling back to
// cache if the user is offline. (If the pages never change, you
// might prefer a cache-first approach to a network-first one.)
event.respondWith(
caches
.open(`offline${timestamp}`)
.then(async cache => {
try {
const response = await fetch(event.request);
cache.put(event.request, response.clone());
return response;
} catch(err) {
const response = await cache.match(event.request);
if (response) return response;
throw err;
}
})
);
});

View File

@@ -0,0 +1,33 @@
<!doctype html>
<html>
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width,initial-scale=1.0'>
<meta name='theme-color' content='#333333'>
%sapper.base%
<link rel='stylesheet' href='global.css'>
<link rel='manifest' href='manifest.json'>
<link rel='icon' type='image/png' href='favicon.png'>
<!-- Sapper generates a <style> tag containing critical CSS
for the current page. CSS for the rest of the app is
lazily loaded when it precaches secondary pages -->
%sapper.styles%
<!-- This contains the contents of the <svelte:head> component, if
the current page has one -->
%sapper.head%
</head>
<body>
<!-- The application will be rendered inside this element,
because `src/client.js` references it -->
<div id='sapper'>%sapper.html%</div>
<!-- Sapper creates a <script> tag containing `src/client.js`
and anything else it needs to hydrate the app and
initialise the router -->
%sapper.scripts%
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@@ -0,0 +1,36 @@
body {
margin: 0;
font-family: Roboto, -apple-system, BlinkMacSystemFont, Segoe UI, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
font-size: 14px;
line-height: 1.5;
color: #333;
}
h1, h2, h3, h4, h5, h6 {
margin: 0 0 0.5em 0;
font-weight: 400;
line-height: 1.2;
}
h1 {
font-size: 2em;
}
a {
color: inherit;
}
code {
font-family: menlo, inconsolata, monospace;
font-size: calc(1em - 2px);
color: #555;
background-color: #f0f0f0;
padding: 0.2em 0.4em;
border-radius: 2px;
}
@media (min-width: 400px) {
body {
font-size: 16px;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -0,0 +1,20 @@
{
"background_color": "#ffffff",
"theme_color": "#333333",
"name": "TODO",
"short_name": "TODO",
"display": "minimal-ui",
"start_url": "/",
"icons": [
{
"src": "logo-192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "logo-512.png",
"sizes": "512x512",
"type": "image/png"
}
]
}

View File

@@ -0,0 +1,77 @@
const webpack = require('webpack');
const path = require('path');
const config = require('sapper/config/webpack.js');
const pkg = require('./package.json');
const mode = process.env.NODE_ENV;
const dev = mode === 'development';
const alias = { svelte: path.resolve('node_modules', 'svelte') };
const extensions = ['.mjs', '.js', '.json', '.svelte', '.html'];
const mainFields = ['svelte', 'module', 'browser', 'main'];
module.exports = {
client: {
entry: config.client.entry(),
output: config.client.output(),
resolve: { alias, extensions, mainFields },
module: {
rules: [
{
test: /\.(svelte|html)$/,
use: {
loader: 'svelte-loader',
options: {
dev,
hydratable: true,
hotReload: false // pending https://github.com/sveltejs/svelte/issues/2377
}
}
}
]
},
mode,
plugins: [
// pending https://github.com/sveltejs/svelte/issues/2377
// dev && new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
'process.browser': true,
'process.env.NODE_ENV': JSON.stringify(mode)
}),
].filter(Boolean),
devtool: dev && 'inline-source-map'
},
server: {
entry: config.server.entry(),
output: config.server.output(),
target: 'node',
resolve: { alias, extensions, mainFields },
externals: Object.keys(pkg.dependencies).concat('encoding'),
module: {
rules: [
{
test: /\.(svelte|html)$/,
use: {
loader: 'svelte-loader',
options: {
css: false,
generate: 'ssr',
dev
}
}
}
]
},
mode: process.env.NODE_ENV,
performance: {
hints: false // it doesn't matter if server.js is large
}
},
serviceworker: {
entry: config.serviceworker.entry(),
output: config.serviceworker.output(),
mode: process.env.NODE_ENV
}
};

View File

@@ -1499,10 +1499,10 @@
resolved "https://registry.yarnpkg.com/@zeit/ncc/-/ncc-0.20.4.tgz#00f0a25a88cac3712af4ba66561d9e281c6f05c9"
integrity sha512-fmq+F/QxPec+k/zvT7HiVpk7oiGFseS6brfT/AYqmCUp6QFRK7vZf2Ref46MImsg/g2W3g5X6SRvGRmOAvEfdA==
"@zeit/node-file-trace@0.2.3":
version "0.2.3"
resolved "https://registry.yarnpkg.com/@zeit/node-file-trace/-/node-file-trace-0.2.3.tgz#58acc5fef28bfcf3b27481a95e2a0497358ec59e"
integrity sha512-uC0fCbwUGvqxl9kTm2rmAYJ/4EOYNzSDba1NSgyROWRF8ELUxt4th28n8xEMGNrAHwy1BUUscsKyyA8M74g0dA==
"@zeit/node-file-trace@0.2.6":
version "0.2.6"
resolved "https://registry.yarnpkg.com/@zeit/node-file-trace/-/node-file-trace-0.2.6.tgz#0884bf7a7176f6aa865a40c8c8b95513d59ee463"
integrity sha512-b6OPed+EtVPMNdSdumBPIBFq0h6CgvVj7sa4Lmbq/KJu9KnOJ19Vu4YrJvSWRjgzP4SJqlQ4ya/HUXRP/LWVog==
dependencies:
acorn "^6.1.1"
acorn-stage3 "^2.0.0"
@@ -1644,7 +1644,7 @@ agentkeepalive@^3.4.1:
dependencies:
humanize-ms "^1.2.1"
ajv@^6.10.2, ajv@^6.5.3, ajv@^6.5.5:
ajv@^6.0.0, ajv@^6.10.2, ajv@^6.5.3, ajv@^6.5.5:
version "6.10.2"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.10.2.tgz#d3cea04d6b017b2894ad69040fec8b623eb4bd52"
integrity sha512-TXtUUEYHuaTEbLZWIKUr5pmBuhDLy+8KYtPYdcV8qC+pOZL+NKqYwvWSRrVXHn+ZmRRAu8vJTAznH7Oag6RVRw==