From d8850660d91a22a0d113eec5a3766eefb57b7c7d Mon Sep 17 00:00:00 2001 From: Github Actions Date: Wed, 7 Jul 2021 09:28:13 +0530 Subject: [PATCH] Add changeset --- .changeset/pink-poets-begin.md | 5 ++ .../src/core/create_manifest_data/index.js | 70 +++++++++++-------- 2 files changed, 44 insertions(+), 31 deletions(-) create mode 100644 .changeset/pink-poets-begin.md diff --git a/.changeset/pink-poets-begin.md b/.changeset/pink-poets-begin.md new file mode 100644 index 000000000000..78fad02b937b --- /dev/null +++ b/.changeset/pink-poets-begin.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +ServiceWorker files exclusion support available through svelte.config.js diff --git a/packages/kit/src/core/create_manifest_data/index.js b/packages/kit/src/core/create_manifest_data/index.js index 2a166e69ab72..6c1c8e580d04 100644 --- a/packages/kit/src/core/create_manifest_data/index.js +++ b/packages/kit/src/core/create_manifest_data/index.js @@ -23,6 +23,44 @@ import glob from 'tiny-glob/sync.js'; const specials = new Set(['__layout', '__layout.reset', '__error']); +/** + * + * @param {import('types/config').ValidatedConfig} config + * @returns {import('types/internal').ManifestData['assets']} + */ +function get_assets_list(config) { + const assets_dir = config.kit.files.assets; + /** + * @type {import('types/internal').Asset[]} + */ + let assets = []; + if (fs.existsSync(assets_dir)) { + /** + * @type {string[]} + */ + const exclusions = config.kit.serviceWorker.exclude || []; + + exclusions.push('**/.DS_STORE'); + + /** + * @type {string[]} + */ + let excluded_paths = []; + + exclusions.forEach((exclusion) => { + excluded_paths = [ + ...excluded_paths, + ...glob(exclusion, { + cwd: assets_dir, + dot: true + }) + ]; + }); + assets = list_files(assets_dir, '', [], excluded_paths); + } + return assets; +} + /** * @param {{ * config: import('types/config').ValidatedConfig; @@ -238,38 +276,8 @@ export default function create_manifest_data({ config, output, cwd = process.cwd walk(config.kit.files.routes, [], [], [layout], [error]); - const assets_dir = config.kit.files.assets; - /** - * @type {import('types/internal').Asset[]} - */ - let assets = []; - if (fs.existsSync(assets_dir)) { - /** - * @type {string[]} - */ - const exclusions = config.kit.serviceWorker.exclude || []; - - exclusions.push('**/.DS_STORE'); - - /** - * @type {string[]} - */ - let excluded_paths = []; - - exclusions.forEach((exclusion) => { - excluded_paths = [ - ...excluded_paths, - ...glob(exclusion, { - cwd: assets_dir, - dot: true - }) - ]; - }); - assets = list_files(assets_dir, '', [], excluded_paths); - } - return { - assets, + assets: get_assets_list(config), layout, error, components,