From 3527af511cffd5745c47d1ebd68096c5180547b5 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Wed, 23 Jun 2021 18:08:42 +0700 Subject: [PATCH 1/8] copy all and only files in root --- packages/kit/src/core/make_package/index.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/kit/src/core/make_package/index.js b/packages/kit/src/core/make_package/index.js index a5c4fbd2297f..c79bf5341942 100644 --- a/packages/kit/src/core/make_package/index.js +++ b/packages/kit/src/core/make_package/index.js @@ -89,11 +89,13 @@ export async function make_package(config, cwd = process.cwd()) { JSON.stringify(package_pkg, null, ' ') ); - const project_readme = path.join(cwd, 'README.md'); - const package_readme = path.join(cwd, config.kit.package.dir, 'README.md'); + for (const pathname of fs.readdirSync(cwd)) { + const full_path = path.join(cwd, pathname); + if (fs.lstatSync(full_path).isDirectory()) continue; - if (fs.existsSync(project_readme) && !fs.existsSync(package_readme)) { - fs.copyFileSync(project_readme, package_readme); + const package_path = path.join(cwd, config.kit.package.dir, pathname); + if (fs.existsSync(package_path)) continue; + fs.copyFileSync(full_path, package_path); } } From 442f7de606d03ddba388e17eaf45da513bed7908 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Wed, 23 Jun 2021 18:09:49 +0700 Subject: [PATCH 2/8] copy `files` values to final package --- packages/kit/src/core/make_package/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/kit/src/core/make_package/index.js b/packages/kit/src/core/make_package/index.js index c79bf5341942..172f34a00858 100644 --- a/packages/kit/src/core/make_package/index.js +++ b/packages/kit/src/core/make_package/index.js @@ -33,6 +33,7 @@ export async function make_package(config, cwd = process.cwd()) { dependencies: pkg.dependencies, private: pkg.private, publishConfig: pkg.publishConfig, + files: pkg.files, type: 'module', /** @type {Record} */ exports: { From 4794c18179445513638a73b145b7e1204bfc9d8e Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Wed, 23 Jun 2021 18:11:37 +0700 Subject: [PATCH 3/8] update and reflect changes to docs --- documentation/docs/12-packaging.md | 2 +- packages/kit/src/core/make_package/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/docs/12-packaging.md b/documentation/docs/12-packaging.md index ed5858ede10b..0c365d754846 100644 --- a/documentation/docs/12-packaging.md +++ b/documentation/docs/12-packaging.md @@ -11,7 +11,7 @@ A SvelteKit component library has the exact same structure as a SvelteKit app, e Running `svelte-kit package` will take the contents of `src/lib` and generate a `package` directory (which can be [configured](#configuration-package)) containing the following: - All the files in `src/lib`, unless you [configure](#configuration-package) custom `include`/`exclude` options. Svelte components will be preprocessed (but note the [caveats](#packaging-caveats) below) -- A `package.json` that copies the `name`, `version`, `description`, `keywords`, `homepage`, `bugs`, `license`, `author`, `contributors`, `funding`, `repository`, `dependencies`, `private` and `publishConfig` fields from the root of the project, and adds a `"type": "module"` and an `"exports"` field +- A `package.json` that copies the `name`, `version`, `description`, `keywords`, `homepage`, `bugs`, `license`, `author`, `contributors`, `funding`, `repository`, `dependencies`, `private`, `files` and `publishConfig` fields from the root of the project, and adds a `"type": "module"` and an `"exports"` field The `"exports"` field contains the package's entry points. By default, all files in `src/lib` will be treated as an entry point unless they start with (or live in a directory that starts with) an underscore, but you can [configure](#configuration-package) this behaviour. If you have a `src/lib/index.js` or `src/lib/index.svelte` file, it will be treated as the package root. diff --git a/packages/kit/src/core/make_package/index.js b/packages/kit/src/core/make_package/index.js index 172f34a00858..6e075c408f45 100644 --- a/packages/kit/src/core/make_package/index.js +++ b/packages/kit/src/core/make_package/index.js @@ -32,8 +32,8 @@ export async function make_package(config, cwd = process.cwd()) { repository: pkg.repository, dependencies: pkg.dependencies, private: pkg.private, - publishConfig: pkg.publishConfig, files: pkg.files, + publishConfig: pkg.publishConfig, type: 'module', /** @type {Record} */ exports: { From 08da844b2d3c9f4f456362b1324fc637240e9a20 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Thu, 24 Jun 2021 14:52:28 +0700 Subject: [PATCH 4/8] add changeset --- .changeset/lazy-mice-smile.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/lazy-mice-smile.md diff --git a/.changeset/lazy-mice-smile.md b/.changeset/lazy-mice-smile.md new file mode 100644 index 000000000000..b20eb66ed834 --- /dev/null +++ b/.changeset/lazy-mice-smile.md @@ -0,0 +1,5 @@ +--- +"@sveltejs/kit": patch +--- + +copy all root files on `svelte-kit package` From 063ae907cd6bc35659075af8b97e9e438c80beb5 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Thu, 24 Jun 2021 15:22:12 +0700 Subject: [PATCH 5/8] only copy essential files from root --- .changeset/lazy-mice-smile.md | 4 ++-- packages/kit/src/core/make_package/essential_files.js | 1 + packages/kit/src/core/make_package/index.js | 8 ++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 packages/kit/src/core/make_package/essential_files.js diff --git a/.changeset/lazy-mice-smile.md b/.changeset/lazy-mice-smile.md index b20eb66ed834..0735bae540df 100644 --- a/.changeset/lazy-mice-smile.md +++ b/.changeset/lazy-mice-smile.md @@ -1,5 +1,5 @@ --- -"@sveltejs/kit": patch +'@sveltejs/kit': patch --- -copy all root files on `svelte-kit package` +copy essential root files on `svelte-kit package` diff --git a/packages/kit/src/core/make_package/essential_files.js b/packages/kit/src/core/make_package/essential_files.js new file mode 100644 index 000000000000..1a4bee68cf93 --- /dev/null +++ b/packages/kit/src/core/make_package/essential_files.js @@ -0,0 +1 @@ +export default ['README', 'LICENSE', 'CHANGELOG', '.gitignore', '.npmignore']; diff --git a/packages/kit/src/core/make_package/index.js b/packages/kit/src/core/make_package/index.js index 6e075c408f45..186e20292438 100644 --- a/packages/kit/src/core/make_package/index.js +++ b/packages/kit/src/core/make_package/index.js @@ -3,6 +3,7 @@ import * as path from 'path'; import { preprocess } from 'svelte/compiler'; import globrex from 'globrex'; import { mkdirp, rimraf } from '../filesystem'; +import essential_files from './essential_files'; /** * @param {import('types/config').ValidatedConfig} config @@ -90,9 +91,12 @@ export async function make_package(config, cwd = process.cwd()) { JSON.stringify(package_pkg, null, ' ') ); - for (const pathname of fs.readdirSync(cwd)) { + const whitelist = fs.readdirSync(cwd).filter((file) => { + return essential_files.some((name) => file.startsWith(name)); + }); + for (const pathname of whitelist) { const full_path = path.join(cwd, pathname); - if (fs.lstatSync(full_path).isDirectory()) continue; + if (fs.lstatSync(full_path).isDirectory()) continue; // just to be sure const package_path = path.join(cwd, config.kit.package.dir, pathname); if (fs.existsSync(package_path)) continue; From f3892ff2645dae86401466b0fd6e5b62c6b3b98c Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Wed, 7 Jul 2021 14:17:33 +0700 Subject: [PATCH 6/8] normalize filenames in whitelist filter --- packages/kit/src/core/make_package/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/kit/src/core/make_package/index.js b/packages/kit/src/core/make_package/index.js index 186e20292438..deb8a5546e7a 100644 --- a/packages/kit/src/core/make_package/index.js +++ b/packages/kit/src/core/make_package/index.js @@ -92,7 +92,8 @@ export async function make_package(config, cwd = process.cwd()) { ); const whitelist = fs.readdirSync(cwd).filter((file) => { - return essential_files.some((name) => file.startsWith(name)); + const lowercased = file.toLowerCase(); + return essential_files.some((name) => lowercased.startsWith(name.toLowerCase())); }); for (const pathname of whitelist) { const full_path = path.join(cwd, pathname); From 8b08a9805553508dbfbf7ce17c20178a058cad19 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Wed, 7 Jul 2021 14:25:45 +0700 Subject: [PATCH 7/8] fix test --- packages/kit/src/core/make_package/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kit/src/core/make_package/index.js b/packages/kit/src/core/make_package/index.js index a089e7ddb446..a35566b98942 100644 --- a/packages/kit/src/core/make_package/index.js +++ b/packages/kit/src/core/make_package/index.js @@ -4,7 +4,7 @@ import { createRequire } from 'module'; import * as path from 'path'; import { preprocess } from 'svelte/compiler'; import { mkdirp, rimraf } from '../filesystem/index.js'; -import essential_files from './essential_files'; +import essential_files from './essential_files.js'; /** * @param {import('types/config').ValidatedConfig} config From 0cfaf18b98c5c20060bd2c4717cdcede421725ab Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Fri, 9 Jul 2021 15:17:40 -0700 Subject: [PATCH 8/8] wait to create separate file for essential_files until there's more to put there --- packages/kit/src/core/make_package/essential_files.js | 1 - packages/kit/src/core/make_package/index.js | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 packages/kit/src/core/make_package/essential_files.js diff --git a/packages/kit/src/core/make_package/essential_files.js b/packages/kit/src/core/make_package/essential_files.js deleted file mode 100644 index 1a4bee68cf93..000000000000 --- a/packages/kit/src/core/make_package/essential_files.js +++ /dev/null @@ -1 +0,0 @@ -export default ['README', 'LICENSE', 'CHANGELOG', '.gitignore', '.npmignore']; diff --git a/packages/kit/src/core/make_package/index.js b/packages/kit/src/core/make_package/index.js index 2e8f47274370..0980533e8f7e 100644 --- a/packages/kit/src/core/make_package/index.js +++ b/packages/kit/src/core/make_package/index.js @@ -4,7 +4,8 @@ import { createRequire } from 'module'; import * as path from 'path'; import { preprocess } from 'svelte/compiler'; import { mkdirp, rimraf } from '../filesystem/index.js'; -import essential_files from './essential_files.js'; + +const essential_files = ['README', 'LICENSE', 'CHANGELOG', '.gitignore', '.npmignore']; /** * @param {import('types/config').ValidatedConfig} config