Skip to content

Commit

Permalink
cleaner way of handling entry point
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Oct 25, 2021
1 parent 4dddd1b commit 45f7553
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
1 change: 1 addition & 0 deletions packages/adapter-netlify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import toml from '@iarna/toml';
export default function () {
return {
name: '@sveltejs/adapter-netlify',
serverEntryPoint: '@sveltejs/adapter-netlify/entry',

async adapt({ utils }) {
// "build" is the default publish directory when Netlify detects SvelteKit
Expand Down
4 changes: 3 additions & 1 deletion packages/adapter-netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
".": {
"import": "./index.js"
},
"./entry": {
"import": "./files/entry.js"
},
"./package.json": "./package.json"
},
"main": "index.js",
"adapter": "files/entry.js",
"types": "index.d.ts",
"files": [
"files",
Expand Down
5 changes: 1 addition & 4 deletions packages/adapter-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ import zlib from 'zlib';

const pipe = promisify(pipeline);

/**
* @typedef {import('esbuild').BuildOptions} BuildOptions
*/

/** @type {import('.')} */
export default function ({
// TODO: add ability to customize entry point to build/index.js
Expand All @@ -22,6 +18,7 @@ export default function ({
} = {}) {
return {
name: '@sveltejs/adapter-node',
serverEntryPoint: '@sveltejs/adapter-node/entry',

async adapt({ utils }) {
utils.rimraf(out);
Expand Down
13 changes: 12 additions & 1 deletion packages/adapter-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"adapter": "files/index.js",
"exports": {
".": {
"import": "./index.js"
},
"./entry": {
"import": "./files/index.js"
},
"./middlewares": {
"import": "./files/middlewares.js"
},
"./package.json": "./package.json"
},
"scripts": {
"dev": "rollup -cw",
"build": "rollup -c",
Expand Down
13 changes: 2 additions & 11 deletions packages/kit/src/core/build/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { svelte } from '@sveltejs/vite-plugin-svelte';
import fs from 'fs';
import { createRequire } from 'module';
import path from 'path';
import glob from 'tiny-glob/sync.js';
import vite from 'vite';
Expand Down Expand Up @@ -463,23 +462,15 @@ async function build_server(
// don't warn on overriding defaults
const [modified_vite_config] = deep_merge(default_config, vite_config);

const adapter = config.kit?.adapter?.name;
const adapter = config.kit?.adapter?.serverEntryPoint;
/**
* @type {{ app:string, index?:string }}
*/
const input = {
app: app_file
};
if (adapter) {
const require = createRequire(import.meta.url);
let pkg_path;
try {
pkg_path = require.resolve(`${adapter}/package.json`);
} catch (err) {
throw new Error(`Could not resolve ${adapter}/package.json while building ${cwd}`);
}
const pkg = JSON.parse(fs.readFileSync(pkg_path, 'utf8'));
input.index = path.resolve(pkg_path.substring(0, pkg_path.lastIndexOf('/')), pkg.adapter);
input.index = adapter;
}

/** @type {[any, string[]]} */
Expand Down
1 change: 1 addition & 0 deletions packages/kit/types/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface AdapterUtils {

export interface Adapter {
name: string;
serverEntryPoint?: string;
adapt(context: { utils: AdapterUtils; config: ValidatedConfig }): Promise<void>;
}

Expand Down

0 comments on commit 45f7553

Please sign in to comment.