Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass adapters directly to config #579

Merged
merged 3 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
pass adapters directly to config
  • Loading branch information
Rich-Harris committed Mar 19, 2021
commit 2c36328d33cc73057d372ff61d5db86ce04aef78
4 changes: 3 additions & 1 deletion examples/hn.svelte.dev/svelte.config.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const netlify = require('@sveltejs/adapter-netlify');

module.exports = {
kit: {
adapter: '@sveltejs/adapter-netlify',
adapter: netlify(),
target: '#svelte'
}
};
4 changes: 3 additions & 1 deletion examples/realworld.svelte.dev/svelte.config.cjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const node = require('@sveltejs/adapter-node');

module.exports = {
kit: {
// By default, `npm run build` will create a standard Node app.
// You can create optimized builds for different platforms by
// specifying a different adapter
adapter: '@sveltejs/adapter-node',
adapter: node(),

// hydrate the <div id="svelte"> element in src/app.html
target: '#svelte',
Expand Down
3 changes: 2 additions & 1 deletion examples/sandbox/svelte.config.cjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const node = require('@sveltejs/adapter-node');
const pkg = require('./package.json');

module.exports = {
kit: {
adapter: '@sveltejs/adapter-node',
adapter: node(),
target: '#svelte',
vite: {
build: {
Expand Down
4 changes: 3 additions & 1 deletion examples/svelte-kit-demo/svelte.config.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const node = require('@sveltejs/adapter-node');

module.exports = {
kit: {
adapter: '@sveltejs/adapter-node',
adapter: node(),
target: '#svelte'
}
};
4 changes: 3 additions & 1 deletion packages/adapter-begin/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store
node_modules
/files
/files
/index.cjs
/index.cjs.map
20 changes: 12 additions & 8 deletions packages/adapter-begin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,29 @@ import { copy } from '@sveltejs/app-utils/files';
import { resolve, join } from 'path';
import parse from '@architect/parser';

function parse_arc(arcPath) {
if (!existsSync(arcPath)) {
throw new Error(`No ${arcPath} found. See the documentation.`);
/** @param {string} file */
function parse_arc(file) {
if (!existsSync(file)) {
throw new Error(`No ${file} found. See the documentation.`);
}

try {
const text = readFileSync(arcPath).toString();
const text = readFileSync(file).toString();
const arc = parse(text);

return {
static: arc.static[0][1]
};
} catch (e) {
throw new Error(
`Error parsing ${arcPath}. Please consult the documentation for correct syntax.`
);
throw new Error(`Error parsing ${file}. Please consult the documentation for correct syntax.`);
}
}

export default function () {
return {
/** @type {import('@sveltejs/kit').Adapter} */
const adapter = {
name: '@sveltejs/adapter-begin',

async adapt(builder) {
builder.log.minor('Parsing app.arc file');
const { static: static_mount_point } = parse_arc('app.arc');
Expand All @@ -49,4 +51,6 @@ export default function () {
});
}
};

return adapter;
}
13 changes: 10 additions & 3 deletions packages/adapter-begin/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"name": "@sveltejs/adapter-begin",
"version": "1.0.0-next.3",
"main": "index.js",
"main": "index.cjs",
"scripts": {
"lint": "eslint --ignore-path .gitignore \"**/*.{ts,js,svelte}\" && npm run check-format",
"dev": "rollup -cw",
"build": "rollup -c",
"format": "prettier --write . --config ../../.prettierrc --ignore-path .gitignore",
"check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore"
"check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
"prepublishOnly": "npm run build"
},
"files": [
"files"
Expand All @@ -17,7 +18,13 @@
"@sveltejs/app-utils": "workspace:*"
},
"devDependencies": {
"@sveltejs/kit": "workspace:*",
"rollup": "^2.41.1",
"sirv": "^1.0.11"
"sirv": "^1.0.11",
"typescript": "^4.2.3"
},
"exports": {
"import": "./index.js",
"require": "./index.cjs"
}
}
34 changes: 24 additions & 10 deletions packages/adapter-begin/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';

export default {
input: 'src/index.js',
output: {
file: 'files/index.js',
format: 'cjs',
sourcemap: true,
exports: 'named'
export default [
{
input: 'src/index.js',
output: {
file: 'files/index.js',
format: 'cjs',
sourcemap: true,
exports: 'named'
},
plugins: [nodeResolve(), commonjs()],
external: [...require('module').builtinModules, '@architect/shared/app.js']
},
plugins: [nodeResolve(), commonjs()],
external: [...require('module').builtinModules, '@architect/shared/app.js']
};

{
input: 'index.js',
output: {
file: 'index.cjs',
format: 'cjs',
sourcemap: true,
exports: 'named'
},
plugins: [nodeResolve(), commonjs()],
external: [...require('module').builtinModules, '@architect/parser']
}
];
13 changes: 13 additions & 0 deletions packages/adapter-begin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"noEmit": true,
"noImplicitAny": true,
"target": "es2020",
"module": "es2020",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true
},
"include": ["./index.js", "src"]
}
18 changes: 10 additions & 8 deletions packages/adapter-netlify/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { existsSync, readFileSync, copyFileSync, writeFileSync, renameSync } from 'fs';
import { dirname, resolve } from 'path';
import toml from 'toml';
import { fileURLToPath } from 'url';
const { existsSync, readFileSync, copyFileSync, writeFileSync, renameSync } = require('fs');
const { resolve } = require('path');
const toml = require('toml');

const __dirname = dirname(fileURLToPath(import.meta.url));
module.exports = function () {
/** @type {import('@sveltejs/kit').Adapter} */
const adapter = {
name: '@sveltejs/adapter-netlify',

export default function () {
return {
async adapt(builder) {
let netlify_config;

Expand Down Expand Up @@ -60,4 +60,6 @@ export default function () {
});
}
};
}

return adapter;
};
5 changes: 4 additions & 1 deletion packages/adapter-netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "@sveltejs/adapter-netlify",
"version": "1.0.0-next.3",
"main": "index.js",
"type": "module",
"files": [
"files"
],
Expand All @@ -13,5 +12,9 @@
},
"dependencies": {
"toml": "^3.0.0"
},
"devDependencies": {
"@sveltejs/kit": "workspace:*",
"typescript": "^4.2.3"
}
}
13 changes: 13 additions & 0 deletions packages/adapter-netlify/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"noEmit": true,
"noImplicitAny": true,
"target": "es2020",
"module": "es2020",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true
},
"include": ["./index.js", "src"]
}
15 changes: 7 additions & 8 deletions packages/adapter-node/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { copyFileSync } from 'fs';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
const { copyFileSync } = require('fs');
const { join } = require('path');

/**
* @param {{
* out?: string;
* }} options
*/
export default function ({ out = 'build' } = {}) {
module.exports = function ({ out = 'build' } = {}) {
/** @type {import('@sveltejs/kit').Adapter} */
const adapter = {
async adapt(builder) {
const dir = dirname(fileURLToPath(import.meta.url));
name: '@sveltejs/adapter-node',

async adapt(builder) {
builder.log.minor('Copying assets');
const static_directory = join(out, 'assets');
builder.copy_client_files(static_directory);
Expand All @@ -21,7 +20,7 @@ export default function ({ out = 'build' } = {}) {
builder.log.minor('Copying server');
builder.copy_server_files(out);

copyFileSync(`${dir}/files/server.js`, `${out}/index.js`);
copyFileSync(`${__dirname}/files/server.js`, `${out}/index.js`);

builder.log.minor('Prerendering static pages');
await builder.prerender({
Expand All @@ -31,4 +30,4 @@ export default function ({ out = 'build' } = {}) {
};

return adapter;
}
};
1 change: 0 additions & 1 deletion packages/adapter-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "@sveltejs/adapter-node",
"version": "1.0.0-next.8",
"main": "index.js",
"type": "module",
"files": [
"files"
],
Expand Down
11 changes: 8 additions & 3 deletions packages/adapter-static/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
export default function ({ pages = 'build', assets = 'build' } = {}) {
return {
module.exports = function ({ pages = 'build', assets = 'build' } = {}) {
/** @type {import('@sveltejs/kit').Adapter} */
const adapter = {
name: '@sveltejs/adapter-static',

async adapt(builder) {
builder.copy_static_files(assets);
builder.copy_client_files(assets);
Expand All @@ -10,4 +13,6 @@ export default function ({ pages = 'build', assets = 'build' } = {}) {
});
}
};
}

return adapter;
};
5 changes: 4 additions & 1 deletion packages/adapter-static/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"name": "@sveltejs/adapter-static",
"version": "1.0.0-next.3",
"type": "module",
"scripts": {
"lint": "eslint --ignore-path .gitignore \"**/*.{ts,js,svelte}\" && npm run check-format",
"format": "prettier --write . --config ../../.prettierrc --ignore-path .gitignore",
"check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore"
},
"devDependencies": {
"@sveltejs/kit": "workspace:*",
"typescript": "^4.2.3"
}
}
13 changes: 13 additions & 0 deletions packages/adapter-static/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"noEmit": true,
"noImplicitAny": true,
"target": "es2020",
"module": "es2020",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true
},
"include": ["./index.js", "src"]
}
14 changes: 8 additions & 6 deletions packages/adapter-vercel/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { writeFileSync, mkdirSync, renameSync } from 'fs';
import { dirname, resolve, join } from 'path';
import { fileURLToPath } from 'url';
import { resolve, join } from 'path';
import { copy } from '@sveltejs/app-utils/files';

const __dirname = dirname(fileURLToPath(import.meta.url));
module.exports = function () {
/** @type {import('@sveltejs/kit').Adapter} */
const adapter = {
name: '@sveltejs/adapter-vercel',

export default function () {
return {
async adapt(builder) {
const vercel_output_directory = resolve('.vercel_build_output');
const config_directory = join(vercel_output_directory, 'config');
Expand Down Expand Up @@ -49,4 +49,6 @@ export default function () {
);
}
};
}

return adapter;
};
4 changes: 3 additions & 1 deletion packages/adapter-vercel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"@sveltejs/app-utils": "workspace:*"
},
"devDependencies": {
"@sveltejs/kit": "workspace:*",
"rollup": "^2.41.1",
"sirv": "^1.0.11"
"sirv": "^1.0.11",
"typescript": "^4.2.3"
}
}
13 changes: 13 additions & 0 deletions packages/adapter-vercel/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"noEmit": true,
"noImplicitAny": true,
"target": "es2020",
"module": "es2020",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true
},
"include": ["./index.js", "src"]
}
Loading