Skip to content

Commit

Permalink
[fix] revert adapters automatically updating .gitignore (#1924) (#2055)
Browse files Browse the repository at this point in the history
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
  • Loading branch information
Rich-Harris and benmccann authored Aug 1, 2021
1 parent 5911b1c commit d81de60
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 44 deletions.
10 changes: 10 additions & 0 deletions .changeset/six-comics-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@sveltejs/adapter-cloudflare-workers': patch
'@sveltejs/adapter-netlify': patch
'@sveltejs/adapter-node': patch
'@sveltejs/adapter-static': patch
'@sveltejs/adapter-vercel': patch
'@sveltejs/kit': patch
---

revert adapters automatically updating .gitignore (#1924)
9 changes: 0 additions & 9 deletions documentation/docs/10-adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ export default {
};
```

Some adapters may modify your project's `.gitignore` to include their build output. In case you don't want those patterns included you can comment them out:

```diff
.svelte-kit
.env

- build
+ # build
```
A variety of official adapters exist for serverless platforms...

- [`adapter-cloudflare-workers`](https://github.com/sveltejs/kit/tree/master/packages/adapter-cloudflare-workers) — for [Cloudflare Workers](https://developers.cloudflare.com/workers/)
Expand Down
3 changes: 2 additions & 1 deletion documentation/docs/80-adapter-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ The types for `Adapter` and its parameters are available in [types/config.d.ts](
Within the `adapt` method, there are a number of things that an adapter should do:

- Clear out the build directory
- Call `utils.update_ignores` to ignore build output in existing `.gitignore` files at the location of `svelte.config.js`
- Output code that:
- Calls `init`
- Converts from the platform's request to a [SvelteKit request](#hooks-handle), calls `render`, and converts from a [SvelteKit response](#hooks-handle) to the platform's
Expand All @@ -35,4 +34,6 @@ Within the `adapt` method, there are a number of things that an adapter should d
- Call `utils.prerender`
- Put the user's static files and the generated JS/CSS in the correct location for the target platform

If possible, we recommend putting the adapter output under `'.svelte-kit/' + adapterName` with any intermediate output under `'.svelte-kit/' + adapterName + '/intermediate'`.

> The adapter API may change before 1.0.
2 changes: 0 additions & 2 deletions packages/adapter-cloudflare-workers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ export default function (options) {

const files = fileURLToPath(new URL('./files', import.meta.url));

utils.update_ignores({ patterns: [bucket, entrypoint] });

utils.rimraf(bucket);
utils.rimraf(entrypoint);

Expand Down
2 changes: 0 additions & 2 deletions packages/adapter-netlify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ export default function (options) {

const files = fileURLToPath(new URL('./files', import.meta.url));

utils.update_ignores({ patterns: [publish, functions] });

utils.log.minor('Generating serverless function...');
utils.copy(join(files, 'entry.js'), '.svelte-kit/netlify/entry.js');

Expand Down
1 change: 0 additions & 1 deletion packages/adapter-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export default function ({
name: '@sveltejs/adapter-node',

async adapt({ utils, config }) {
utils.update_ignores({ patterns: [out] });
utils.log.minor('Copying assets');
const static_directory = join(out, 'assets');
utils.copy_client_files(static_directory);
Expand Down
1 change: 0 additions & 1 deletion packages/adapter-static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export default function ({ pages = 'build', assets = pages, fallback } = {}) {
name: '@sveltejs/adapter-static',

async adapt({ utils }) {
utils.update_ignores({ patterns: [pages, assets] });
utils.copy_static_files(assets);
utils.copy_client_files(assets);

Expand Down
2 changes: 0 additions & 2 deletions packages/adapter-static/test/apps/prerendered/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ node_modules
/.svelte-kit
/build
/functions

build
2 changes: 0 additions & 2 deletions packages/adapter-static/test/apps/spa/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ node_modules
/.svelte-kit
/build
/functions

build
2 changes: 0 additions & 2 deletions packages/adapter-vercel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ export default function (options) {

async adapt({ utils }) {
const dir = '.vercel_build_output';

utils.update_ignores({ patterns: [dir] });
utils.rimraf(dir);

const files = fileURLToPath(new URL('./files', import.meta.url));
Expand Down
20 changes: 0 additions & 20 deletions packages/kit/src/core/adapt/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { SVELTE_KIT } from '../constants.js';
import { copy, rimraf, mkdirp } from '../filesystem/index.js';
import { prerender } from './prerender.js';
import fs from 'fs';

/**
* @param {{
Expand Down Expand Up @@ -43,25 +42,6 @@ export function get_utils({ cwd, config, build_data, log }) {
log
});
}
},

/** @param {{patterns: string[], log?: boolean}} options */
update_ignores({ patterns, log = true }) {
const target = '.gitignore';
if (!fs.existsSync(target)) return;

const file = fs.readFileSync(target, { encoding: 'utf-8' });
const eol = file.includes('\r\n') ? '\r\n' : '\n';
const lines = file.split(eol);
const new_lines = new Set(patterns);
// remove repeated lines
for (const line of lines) {
// this will prevent commented ignores to be reinserted
new_lines.delete(line.replace(/#\s*/, ''));
}
if (new_lines.size === 0) return;
fs.writeFileSync(target, [...lines, ...new_lines].join(eol));
if (log) this.log.success(`Updated ${target}`);
}
};
}
11 changes: 9 additions & 2 deletions packages/kit/types/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ export interface AdapterUtils {
copy_server_files: (dest: string) => void;
copy_static_files: (dest: string) => void;
copy: (from: string, to: string, filter?: (basename: string) => boolean) => void;
update_ignores: ({ patterns, log }: { patterns: string[]; log?: boolean }) => void;
prerender: (options: { all?: boolean; dest: string; fallback?: string }) => Promise<void>;
prerender: ({
all,
dest,
fallback
}: {
all?: boolean;
dest: string;
fallback?: string;
}) => Promise<void>;
}

export interface Adapter {
Expand Down

0 comments on commit d81de60

Please sign in to comment.