From aaa9183d9a746e40f63cce3f7bc88f38ab09a957 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Tue, 22 Jun 2021 16:03:30 +0700 Subject: [PATCH 01/17] preserve readme capitalization on copy --- packages/kit/src/core/make_package/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/kit/src/core/make_package/index.js b/packages/kit/src/core/make_package/index.js index a5c4fbd2297f..b6a5aa7a990e 100644 --- a/packages/kit/src/core/make_package/index.js +++ b/packages/kit/src/core/make_package/index.js @@ -90,9 +90,12 @@ export async function make_package(config, cwd = process.cwd()) { ); const project_readme = path.join(cwd, 'README.md'); - const package_readme = path.join(cwd, config.kit.package.dir, 'README.md'); + const readme_exists = fs.existsSync(project_readme); + if (!readme_exists) return; - if (fs.existsSync(project_readme) && !fs.existsSync(package_readme)) { + const preserved_filename = fs.realpathSync.native(project_readme).slice(-'README.md'.length); + const package_readme = path.join(cwd, config.kit.package.dir, preserved_filename); + if (!fs.existsSync(package_readme)) { fs.copyFileSync(project_readme, package_readme); } } From ca4857c182f3ff67d18fe066158239ee929610de Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Tue, 22 Jun 2021 16:12:48 +0700 Subject: [PATCH 02/17] copy the whole package.json --- packages/kit/src/core/make_package/index.js | 43 +++++++-------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/packages/kit/src/core/make_package/index.js b/packages/kit/src/core/make_package/index.js index b6a5aa7a990e..c0a694689207 100644 --- a/packages/kit/src/core/make_package/index.js +++ b/packages/kit/src/core/make_package/index.js @@ -18,27 +18,15 @@ export async function make_package(config, cwd = process.cwd()) { const pkg = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf8')); - const package_pkg = { - name: pkg.name, - version: pkg.version, - description: pkg.description, - keywords: pkg.keywords, - homepage: pkg.homepage, - bugs: pkg.bugs, - license: pkg.license, - author: pkg.author, - contributors: pkg.contributors, - funding: pkg.funding, - repository: pkg.repository, - dependencies: pkg.dependencies, - private: pkg.private, - publishConfig: pkg.publishConfig, - type: 'module', - /** @type {Record} */ - exports: { + pkg.type = 'module'; // type must be 'module' + + let user_defined_exports = true; + if (!('exports' in pkg)) { + user_defined_exports = false; + pkg.exports = { './package.json': './package.json' - } - }; + }; + } for (const file of files) { if (!files_filter(file)) continue; @@ -72,22 +60,19 @@ export async function make_package(config, cwd = process.cwd()) { write(path.join(cwd, config.kit.package.dir, out_file), out_contents); - if (exports_filter(file)) { + if (!user_defined_exports && exports_filter(file)) { const entry = `./${out_file}`; - package_pkg.exports[entry] = entry; + pkg.exports[entry] = entry; } } - const main = package_pkg.exports['./index.js'] || package_pkg.exports['./index.svelte']; + const main = pkg.exports['./index.js'] || pkg.exports['./index.svelte']; - if (main) { - package_pkg.exports['.'] = main; + if (!user_defined_exports && main) { + pkg.exports['.'] = main; } - write( - path.join(cwd, config.kit.package.dir, 'package.json'), - JSON.stringify(package_pkg, null, ' ') - ); + write(path.join(cwd, config.kit.package.dir, 'package.json'), JSON.stringify(pkg, null, ' ')); const project_readme = path.join(cwd, 'README.md'); const readme_exists = fs.existsSync(project_readme); From 65d8424ef8b3693f4e8b39a4f3cb374cea27db3c Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Tue, 22 Jun 2021 16:16:05 +0700 Subject: [PATCH 03/17] update packaging docs about package.json --- documentation/docs/12-packaging.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/docs/12-packaging.md b/documentation/docs/12-packaging.md index ed5858ede10b..02482d26fec4 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` copied from the project root and adds a `"type": "module"`. An `"exports"` field will also be added if it's not defined in the original file. 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. From cb681fcb49dab1ad13fe8ad0c42fc65f4a1d67ae Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Tue, 22 Jun 2021 16:20:01 +0700 Subject: [PATCH 04/17] replace windows specific separator for '/' --- 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 c0a694689207..f338241364db 100644 --- a/packages/kit/src/core/make_package/index.js +++ b/packages/kit/src/core/make_package/index.js @@ -61,7 +61,7 @@ export async function make_package(config, cwd = process.cwd()) { write(path.join(cwd, config.kit.package.dir, out_file), out_contents); if (!user_defined_exports && exports_filter(file)) { - const entry = `./${out_file}`; + const entry = `./${out_file.replace(/\\/g, '/')}`; pkg.exports[entry] = entry; } } From 2d36eb027ab9bf519e968e02b29ea2348e65b3cb Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Tue, 22 Jun 2021 16:22:46 +0700 Subject: [PATCH 05/17] add changeset --- .changeset/unlucky-planets-battle.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/unlucky-planets-battle.md diff --git a/.changeset/unlucky-planets-battle.md b/.changeset/unlucky-planets-battle.md new file mode 100644 index 000000000000..974612bf6146 --- /dev/null +++ b/.changeset/unlucky-planets-battle.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +Preserve README casing and package.json contents on svelte-kit package From 76fead9fb9eb4b410130f0abc54d8fea0617cd31 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Tue, 22 Jun 2021 21:47:50 +0700 Subject: [PATCH 06/17] remove scripts for package output --- 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 f338241364db..2dfcf7a6763b 100644 --- a/packages/kit/src/core/make_package/index.js +++ b/packages/kit/src/core/make_package/index.js @@ -18,6 +18,7 @@ export async function make_package(config, cwd = process.cwd()) { const pkg = JSON.parse(fs.readFileSync(path.join(cwd, 'package.json'), 'utf8')); + delete pkg.scripts; pkg.type = 'module'; // type must be 'module' let user_defined_exports = true; From 02f8059a8d9ac17b1ecf93e76d0c0f34863de5dc Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Thu, 8 Jul 2021 10:12:09 +0700 Subject: [PATCH 07/17] test: fixtures for nested components --- .../test/fixtures/nested/expected/Test.svelte | 12 ++++++ .../fixtures/nested/expected/Test.svelte.d.ts | 40 +++++++++++++++++++ .../test/fixtures/nested/expected/index.d.ts | 2 + .../test/fixtures/nested/expected/index.js | 2 + .../nested/expected/internal/Test.svelte | 6 +++ .../nested/expected/internal/Test.svelte.d.ts | 26 ++++++++++++ .../nested/expected/internal/foo.d.ts | 1 + .../fixtures/nested/expected/package.json | 13 ++++++ .../test/fixtures/nested/jsconfig.json | 9 +++++ .../test/fixtures/nested/package.json | 5 +++ .../test/fixtures/nested/src/app.html | 12 ++++++ .../test/fixtures/nested/src/lib/Test.svelte | 12 ++++++ .../test/fixtures/nested/src/lib/index.js | 2 + .../nested/src/lib/internal/Test.svelte | 6 +++ .../fixtures/nested/src/lib/internal/foo.d.ts | 1 + .../test/fixtures/nested/svelte.config.js | 0 16 files changed, 149 insertions(+) create mode 100644 packages/kit/src/core/make_package/test/fixtures/nested/expected/Test.svelte create mode 100644 packages/kit/src/core/make_package/test/fixtures/nested/expected/Test.svelte.d.ts create mode 100644 packages/kit/src/core/make_package/test/fixtures/nested/expected/index.d.ts create mode 100644 packages/kit/src/core/make_package/test/fixtures/nested/expected/index.js create mode 100644 packages/kit/src/core/make_package/test/fixtures/nested/expected/internal/Test.svelte create mode 100644 packages/kit/src/core/make_package/test/fixtures/nested/expected/internal/Test.svelte.d.ts create mode 100644 packages/kit/src/core/make_package/test/fixtures/nested/expected/internal/foo.d.ts create mode 100644 packages/kit/src/core/make_package/test/fixtures/nested/expected/package.json create mode 100644 packages/kit/src/core/make_package/test/fixtures/nested/jsconfig.json create mode 100644 packages/kit/src/core/make_package/test/fixtures/nested/package.json create mode 100644 packages/kit/src/core/make_package/test/fixtures/nested/src/app.html create mode 100644 packages/kit/src/core/make_package/test/fixtures/nested/src/lib/Test.svelte create mode 100644 packages/kit/src/core/make_package/test/fixtures/nested/src/lib/index.js create mode 100644 packages/kit/src/core/make_package/test/fixtures/nested/src/lib/internal/Test.svelte create mode 100644 packages/kit/src/core/make_package/test/fixtures/nested/src/lib/internal/foo.d.ts create mode 100644 packages/kit/src/core/make_package/test/fixtures/nested/svelte.config.js diff --git a/packages/kit/src/core/make_package/test/fixtures/nested/expected/Test.svelte b/packages/kit/src/core/make_package/test/fixtures/nested/expected/Test.svelte new file mode 100644 index 000000000000..31d118397f9d --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/nested/expected/Test.svelte @@ -0,0 +1,12 @@ + + + diff --git a/packages/kit/src/core/make_package/test/fixtures/nested/expected/Test.svelte.d.ts b/packages/kit/src/core/make_package/test/fixtures/nested/expected/Test.svelte.d.ts new file mode 100644 index 000000000000..8cfa75e62de7 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/nested/expected/Test.svelte.d.ts @@ -0,0 +1,40 @@ +/** @typedef {typeof __propDef.props} TestProps */ +/** @typedef {typeof __propDef.events} TestEvents */ +/** @typedef {typeof __propDef.slots} TestSlots */ +export default class Test extends SvelteComponentTyped< + { + astring: string; + }, + { + event: CustomEvent; + } & { + [evt: string]: CustomEvent; + }, + { + default: { + astring: string; + }; + } +> { + get astring(): string; +} +export type TestProps = typeof __propDef.props; +export type TestEvents = typeof __propDef.events; +export type TestSlots = typeof __propDef.slots; +import { SvelteComponentTyped } from 'svelte'; +declare const __propDef: { + props: { + astring: string; + }; + events: { + event: CustomEvent; + } & { + [evt: string]: CustomEvent; + }; + slots: { + default: { + astring: string; + }; + }; +}; +export {}; diff --git a/packages/kit/src/core/make_package/test/fixtures/nested/expected/index.d.ts b/packages/kit/src/core/make_package/test/fixtures/nested/expected/index.d.ts new file mode 100644 index 000000000000..ed60fe04da25 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/nested/expected/index.d.ts @@ -0,0 +1,2 @@ +export { default as Test } from './Test.svelte'; +export { default as Internal } from './internal/Test.svelte'; diff --git a/packages/kit/src/core/make_package/test/fixtures/nested/expected/index.js b/packages/kit/src/core/make_package/test/fixtures/nested/expected/index.js new file mode 100644 index 000000000000..ed60fe04da25 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/nested/expected/index.js @@ -0,0 +1,2 @@ +export { default as Test } from './Test.svelte'; +export { default as Internal } from './internal/Test.svelte'; diff --git a/packages/kit/src/core/make_package/test/fixtures/nested/expected/internal/Test.svelte b/packages/kit/src/core/make_package/test/fixtures/nested/expected/internal/Test.svelte new file mode 100644 index 000000000000..06a5a3408e95 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/nested/expected/internal/Test.svelte @@ -0,0 +1,6 @@ + diff --git a/packages/kit/src/core/make_package/test/fixtures/nested/expected/internal/Test.svelte.d.ts b/packages/kit/src/core/make_package/test/fixtures/nested/expected/internal/Test.svelte.d.ts new file mode 100644 index 000000000000..c787a209ac12 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/nested/expected/internal/Test.svelte.d.ts @@ -0,0 +1,26 @@ +/** @typedef {typeof __propDef.props} Test2Props */ +/** @typedef {typeof __propDef.events} Test2Events */ +/** @typedef {typeof __propDef.slots} Test2Slots */ +export default class Test2 extends SvelteComponentTyped< + { + foo: boolean; + }, + { + [evt: string]: CustomEvent; + }, + {} +> {} +export type Test2Props = typeof __propDef.props; +export type Test2Events = typeof __propDef.events; +export type Test2Slots = typeof __propDef.slots; +import { SvelteComponentTyped } from 'svelte'; +declare const __propDef: { + props: { + foo: import('./foo').Foo; + }; + events: { + [evt: string]: CustomEvent; + }; + slots: {}; +}; +export {}; diff --git a/packages/kit/src/core/make_package/test/fixtures/nested/expected/internal/foo.d.ts b/packages/kit/src/core/make_package/test/fixtures/nested/expected/internal/foo.d.ts new file mode 100644 index 000000000000..c941ad7b1ce6 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/nested/expected/internal/foo.d.ts @@ -0,0 +1 @@ +export type Foo = boolean; diff --git a/packages/kit/src/core/make_package/test/fixtures/nested/expected/package.json b/packages/kit/src/core/make_package/test/fixtures/nested/expected/package.json new file mode 100644 index 000000000000..4755aebef96b --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/nested/expected/package.json @@ -0,0 +1,13 @@ +{ + "name": "javascript", + "version": "1.0.0", + "description": "package-javascript-test", + "type": "module", + "exports": { + "./package.json": "./package.json", + "./index.js": "./index.js", + "./internal/Test.svelte": "./internal/Test.svelte", + "./Test.svelte": "./Test.svelte", + ".": "./index.js" + } +} diff --git a/packages/kit/src/core/make_package/test/fixtures/nested/jsconfig.json b/packages/kit/src/core/make_package/test/fixtures/nested/jsconfig.json new file mode 100644 index 000000000000..5417394ebe85 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/nested/jsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "checkJs": true, + "paths": { + "$lib/*": ["src/lib/*"] + } + }, + "include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.svelte"] +} diff --git a/packages/kit/src/core/make_package/test/fixtures/nested/package.json b/packages/kit/src/core/make_package/test/fixtures/nested/package.json new file mode 100644 index 000000000000..e29e4689c6e0 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/nested/package.json @@ -0,0 +1,5 @@ +{ + "name": "javascript", + "version": "1.0.0", + "description": "package-javascript-test" +} diff --git a/packages/kit/src/core/make_package/test/fixtures/nested/src/app.html b/packages/kit/src/core/make_package/test/fixtures/nested/src/app.html new file mode 100644 index 000000000000..245305c4ef5b --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/nested/src/app.html @@ -0,0 +1,12 @@ + + + + + + + %svelte.head% + + +
%svelte.body%
+ + diff --git a/packages/kit/src/core/make_package/test/fixtures/nested/src/lib/Test.svelte b/packages/kit/src/core/make_package/test/fixtures/nested/src/lib/Test.svelte new file mode 100644 index 000000000000..31d118397f9d --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/nested/src/lib/Test.svelte @@ -0,0 +1,12 @@ + + + diff --git a/packages/kit/src/core/make_package/test/fixtures/nested/src/lib/index.js b/packages/kit/src/core/make_package/test/fixtures/nested/src/lib/index.js new file mode 100644 index 000000000000..ed60fe04da25 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/nested/src/lib/index.js @@ -0,0 +1,2 @@ +export { default as Test } from './Test.svelte'; +export { default as Internal } from './internal/Test.svelte'; diff --git a/packages/kit/src/core/make_package/test/fixtures/nested/src/lib/internal/Test.svelte b/packages/kit/src/core/make_package/test/fixtures/nested/src/lib/internal/Test.svelte new file mode 100644 index 000000000000..06a5a3408e95 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/nested/src/lib/internal/Test.svelte @@ -0,0 +1,6 @@ + diff --git a/packages/kit/src/core/make_package/test/fixtures/nested/src/lib/internal/foo.d.ts b/packages/kit/src/core/make_package/test/fixtures/nested/src/lib/internal/foo.d.ts new file mode 100644 index 000000000000..c941ad7b1ce6 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/nested/src/lib/internal/foo.d.ts @@ -0,0 +1 @@ +export type Foo = boolean; diff --git a/packages/kit/src/core/make_package/test/fixtures/nested/svelte.config.js b/packages/kit/src/core/make_package/test/fixtures/nested/svelte.config.js new file mode 100644 index 000000000000..e69de29bb2d1 From 6e66222990913d8f3d5b385d64cdf631aac25414 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Thu, 8 Jul 2021 10:18:17 +0700 Subject: [PATCH 08/17] test: fixtures for user defined exports map --- .../fixtures/exports/expected/Test.svelte | 12 ++++++ .../exports/expected/Test.svelte.d.ts | 40 +++++++++++++++++++ .../test/fixtures/exports/expected/index.d.ts | 1 + .../test/fixtures/exports/expected/index.js | 1 + .../exports/expected/internal/Test.svelte | 6 +++ .../expected/internal/Test.svelte.d.ts | 26 ++++++++++++ .../exports/expected/internal/foo.d.ts | 1 + .../fixtures/exports/expected/package.json | 12 ++++++ .../test/fixtures/exports/package.json | 11 +++++ .../test/fixtures/exports/src/app.html | 12 ++++++ .../test/fixtures/exports/src/lib/Test.svelte | 12 ++++++ .../test/fixtures/exports/src/lib/index.js | 1 + .../exports/src/lib/internal/Test.svelte | 6 +++ .../exports/src/lib/internal/foo.d.ts | 1 + .../test/fixtures/exports/svelte.config.js | 0 .../test/fixtures/exports/tsconfig.json | 30 ++++++++++++++ 16 files changed, 172 insertions(+) create mode 100644 packages/kit/src/core/make_package/test/fixtures/exports/expected/Test.svelte create mode 100644 packages/kit/src/core/make_package/test/fixtures/exports/expected/Test.svelte.d.ts create mode 100644 packages/kit/src/core/make_package/test/fixtures/exports/expected/index.d.ts create mode 100644 packages/kit/src/core/make_package/test/fixtures/exports/expected/index.js create mode 100644 packages/kit/src/core/make_package/test/fixtures/exports/expected/internal/Test.svelte create mode 100644 packages/kit/src/core/make_package/test/fixtures/exports/expected/internal/Test.svelte.d.ts create mode 100644 packages/kit/src/core/make_package/test/fixtures/exports/expected/internal/foo.d.ts create mode 100644 packages/kit/src/core/make_package/test/fixtures/exports/expected/package.json create mode 100644 packages/kit/src/core/make_package/test/fixtures/exports/package.json create mode 100644 packages/kit/src/core/make_package/test/fixtures/exports/src/app.html create mode 100644 packages/kit/src/core/make_package/test/fixtures/exports/src/lib/Test.svelte create mode 100644 packages/kit/src/core/make_package/test/fixtures/exports/src/lib/index.js create mode 100644 packages/kit/src/core/make_package/test/fixtures/exports/src/lib/internal/Test.svelte create mode 100644 packages/kit/src/core/make_package/test/fixtures/exports/src/lib/internal/foo.d.ts create mode 100644 packages/kit/src/core/make_package/test/fixtures/exports/svelte.config.js create mode 100644 packages/kit/src/core/make_package/test/fixtures/exports/tsconfig.json diff --git a/packages/kit/src/core/make_package/test/fixtures/exports/expected/Test.svelte b/packages/kit/src/core/make_package/test/fixtures/exports/expected/Test.svelte new file mode 100644 index 000000000000..31d118397f9d --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/exports/expected/Test.svelte @@ -0,0 +1,12 @@ + + + diff --git a/packages/kit/src/core/make_package/test/fixtures/exports/expected/Test.svelte.d.ts b/packages/kit/src/core/make_package/test/fixtures/exports/expected/Test.svelte.d.ts new file mode 100644 index 000000000000..8cfa75e62de7 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/exports/expected/Test.svelte.d.ts @@ -0,0 +1,40 @@ +/** @typedef {typeof __propDef.props} TestProps */ +/** @typedef {typeof __propDef.events} TestEvents */ +/** @typedef {typeof __propDef.slots} TestSlots */ +export default class Test extends SvelteComponentTyped< + { + astring: string; + }, + { + event: CustomEvent; + } & { + [evt: string]: CustomEvent; + }, + { + default: { + astring: string; + }; + } +> { + get astring(): string; +} +export type TestProps = typeof __propDef.props; +export type TestEvents = typeof __propDef.events; +export type TestSlots = typeof __propDef.slots; +import { SvelteComponentTyped } from 'svelte'; +declare const __propDef: { + props: { + astring: string; + }; + events: { + event: CustomEvent; + } & { + [evt: string]: CustomEvent; + }; + slots: { + default: { + astring: string; + }; + }; +}; +export {}; diff --git a/packages/kit/src/core/make_package/test/fixtures/exports/expected/index.d.ts b/packages/kit/src/core/make_package/test/fixtures/exports/expected/index.d.ts new file mode 100644 index 000000000000..4c44188c3648 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/exports/expected/index.d.ts @@ -0,0 +1 @@ +export { default as Test } from './Test.svelte'; diff --git a/packages/kit/src/core/make_package/test/fixtures/exports/expected/index.js b/packages/kit/src/core/make_package/test/fixtures/exports/expected/index.js new file mode 100644 index 000000000000..4c44188c3648 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/exports/expected/index.js @@ -0,0 +1 @@ +export { default as Test } from './Test.svelte'; diff --git a/packages/kit/src/core/make_package/test/fixtures/exports/expected/internal/Test.svelte b/packages/kit/src/core/make_package/test/fixtures/exports/expected/internal/Test.svelte new file mode 100644 index 000000000000..06a5a3408e95 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/exports/expected/internal/Test.svelte @@ -0,0 +1,6 @@ + diff --git a/packages/kit/src/core/make_package/test/fixtures/exports/expected/internal/Test.svelte.d.ts b/packages/kit/src/core/make_package/test/fixtures/exports/expected/internal/Test.svelte.d.ts new file mode 100644 index 000000000000..c787a209ac12 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/exports/expected/internal/Test.svelte.d.ts @@ -0,0 +1,26 @@ +/** @typedef {typeof __propDef.props} Test2Props */ +/** @typedef {typeof __propDef.events} Test2Events */ +/** @typedef {typeof __propDef.slots} Test2Slots */ +export default class Test2 extends SvelteComponentTyped< + { + foo: boolean; + }, + { + [evt: string]: CustomEvent; + }, + {} +> {} +export type Test2Props = typeof __propDef.props; +export type Test2Events = typeof __propDef.events; +export type Test2Slots = typeof __propDef.slots; +import { SvelteComponentTyped } from 'svelte'; +declare const __propDef: { + props: { + foo: import('./foo').Foo; + }; + events: { + [evt: string]: CustomEvent; + }; + slots: {}; +}; +export {}; diff --git a/packages/kit/src/core/make_package/test/fixtures/exports/expected/internal/foo.d.ts b/packages/kit/src/core/make_package/test/fixtures/exports/expected/internal/foo.d.ts new file mode 100644 index 000000000000..c941ad7b1ce6 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/exports/expected/internal/foo.d.ts @@ -0,0 +1 @@ +export type Foo = boolean; diff --git a/packages/kit/src/core/make_package/test/fixtures/exports/expected/package.json b/packages/kit/src/core/make_package/test/fixtures/exports/expected/package.json new file mode 100644 index 000000000000..8c14e3c2f330 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/exports/expected/package.json @@ -0,0 +1,12 @@ +{ + "name": "javascript", + "version": "1.0.0", + "description": "package-javascript-test", + "exports": { + "./package.json": "./package.json", + ".": { + "import": "./index.js" + } + }, + "type": "module" +} diff --git a/packages/kit/src/core/make_package/test/fixtures/exports/package.json b/packages/kit/src/core/make_package/test/fixtures/exports/package.json new file mode 100644 index 000000000000..af4f9a162250 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/exports/package.json @@ -0,0 +1,11 @@ +{ + "name": "javascript", + "version": "1.0.0", + "description": "package-javascript-test", + "exports": { + "./package.json": "./package.json", + ".": { + "import": "./index.js" + } + } +} diff --git a/packages/kit/src/core/make_package/test/fixtures/exports/src/app.html b/packages/kit/src/core/make_package/test/fixtures/exports/src/app.html new file mode 100644 index 000000000000..245305c4ef5b --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/exports/src/app.html @@ -0,0 +1,12 @@ + + + + + + + %svelte.head% + + +
%svelte.body%
+ + diff --git a/packages/kit/src/core/make_package/test/fixtures/exports/src/lib/Test.svelte b/packages/kit/src/core/make_package/test/fixtures/exports/src/lib/Test.svelte new file mode 100644 index 000000000000..31d118397f9d --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/exports/src/lib/Test.svelte @@ -0,0 +1,12 @@ + + + diff --git a/packages/kit/src/core/make_package/test/fixtures/exports/src/lib/index.js b/packages/kit/src/core/make_package/test/fixtures/exports/src/lib/index.js new file mode 100644 index 000000000000..4c44188c3648 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/exports/src/lib/index.js @@ -0,0 +1 @@ +export { default as Test } from './Test.svelte'; diff --git a/packages/kit/src/core/make_package/test/fixtures/exports/src/lib/internal/Test.svelte b/packages/kit/src/core/make_package/test/fixtures/exports/src/lib/internal/Test.svelte new file mode 100644 index 000000000000..06a5a3408e95 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/exports/src/lib/internal/Test.svelte @@ -0,0 +1,6 @@ + diff --git a/packages/kit/src/core/make_package/test/fixtures/exports/src/lib/internal/foo.d.ts b/packages/kit/src/core/make_package/test/fixtures/exports/src/lib/internal/foo.d.ts new file mode 100644 index 000000000000..c941ad7b1ce6 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/exports/src/lib/internal/foo.d.ts @@ -0,0 +1 @@ +export type Foo = boolean; diff --git a/packages/kit/src/core/make_package/test/fixtures/exports/svelte.config.js b/packages/kit/src/core/make_package/test/fixtures/exports/svelte.config.js new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/kit/src/core/make_package/test/fixtures/exports/tsconfig.json b/packages/kit/src/core/make_package/test/fixtures/exports/tsconfig.json new file mode 100644 index 000000000000..0f54c3906f8b --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/exports/tsconfig.json @@ -0,0 +1,30 @@ +{ + "compilerOptions": { + "moduleResolution": "node", + "module": "es2020", + "lib": ["es2020", "DOM"], + "target": "es2019", + /** + svelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript + to enforce using \`import type\` instead of \`import\` for Types. + */ + "importsNotUsedAsValues": "error", + "isolatedModules": true, + "resolveJsonModule": true, + /** + To have warnings/errors of the Svelte compiler at the correct position, + enable source maps by default. + */ + "sourceMap": true, + "esModuleInterop": true, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "baseUrl": ".", + "allowJs": true, + "checkJs": true, + "paths": { + "$lib/*": ["src/lib/*"] + } + }, + "include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.ts", "src/**/*.svelte"] +} From fb3c4e314ed6fdf1d4c46f96dc4798308264d674 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Thu, 8 Jul 2021 10:19:32 +0700 Subject: [PATCH 09/17] adjust test infra to handle nested files --- .../kit/src/core/make_package/test/index.js | 68 +++++++++++++++---- 1 file changed, 54 insertions(+), 14 deletions(-) diff --git a/packages/kit/src/core/make_package/test/index.js b/packages/kit/src/core/make_package/test/index.js index 107563424844..4c54f93e0928 100644 --- a/packages/kit/src/core/make_package/test/index.js +++ b/packages/kit/src/core/make_package/test/index.js @@ -5,7 +5,7 @@ import { fileURLToPath } from 'url'; import { load_config } from '../../config/index.js'; import { make_package } from '../index.js'; import { rimraf } from '../../filesystem/index.js'; -import { readdirSync, readFileSync } from 'fs'; +import { lstatSync, readdirSync, readFileSync } from 'fs'; import prettier from 'prettier'; const __filename = fileURLToPath(import.meta.url); @@ -16,12 +16,30 @@ const __dirname = join(__filename, '..'); */ async function test_make_package(path) { const cwd = join(__dirname, 'fixtures', path); + const ewd = join(cwd, 'expected'); + const pwd = join(cwd, 'package'); + + /** + * @param {string} start starting pathname + * @param {string} dir absolute directory + * @returns {string[]} list of complete paths + */ + const get_complete_list = (start, dir) => { + const files = []; + for (const name of readdirSync(dir)) { + const relative = join(start, name); + const current = join(dir, name); + if (!lstatSync(current).isDirectory()) files.push(relative); + else files.concat(get_complete_list(relative, current)); + } + return files; + }; try { const config = await load_config({ cwd }); await make_package(config, cwd); - const expected_files = readdirSync(join(cwd, 'expected')); - const actual_files = readdirSync(join(cwd, 'package')); + const expected_files = get_complete_list('', ewd); + const actual_files = get_complete_list('', pwd); assert.equal( actual_files.length, expected_files.length, @@ -31,18 +49,32 @@ async function test_make_package(path) { actual_files.join(',') ); - for (const file of actual_files) { - assert.equal(expected_files.includes(file), true, `Did not expect ${file}`); - const expected_content = readFileSync(join(cwd, 'expected', file), 'utf-8'); - const actual_content = readFileSync(join(cwd, 'package', file), 'utf-8'); - assert.equal( - format(file, actual_content), - format(file, expected_content), - 'Expected equal file contents' - ); - } + /** + * @param {string[]} files relative names + * @param {string} path absolute pathnames + */ + const traverse = (files, path) => { + for (const file of files) { + const current = join(path, file); + if (lstatSync(current).isDirectory()) { + traverse(readdirSync(current), current); + } else { + assert.equal(expected_files.includes(file), true, `Did not expect ${file}`); + const expected_path = current.replace(/([/\\]test[/\\].+)package([/\\])/, '$1expected$2'); + const expected_content = readFileSync(expected_path, 'utf-8'); + const actual_content = readFileSync(current, 'utf-8'); + assert.equal( + format(file, actual_content), + format(file, expected_content), + 'Expected equal file contents' + ); + } + } + }; + + traverse(actual_files, pwd); } finally { - rimraf(join(cwd, 'package')); + rimraf(pwd); } } @@ -74,4 +106,12 @@ test('create package (typescript)', async () => { await test_make_package('typescript'); }); +test('create package (nested)', async () => { + await test_make_package('nested'); +}); + +test('create package with user defined settings (exports)', async () => { + await test_make_package('exports'); +}); + test.run(); From 25ad459a4cfa9ca0c987894f6c3fdec22e3fdf3c Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Thu, 8 Jul 2021 17:36:21 +0700 Subject: [PATCH 10/17] clean up test fixtures --- .../fixtures/exports/expected/package.json | 4 +-- .../test/fixtures/exports/jsconfig.json | 9 ++++++ .../test/fixtures/exports/package.json | 4 +-- .../test/fixtures/exports/tsconfig.json | 30 ------------------- .../fixtures/nested/expected/package.json | 4 +-- .../test/fixtures/nested/package.json | 4 +-- .../kit/src/core/make_package/test/index.js | 4 +++ 7 files changed, 21 insertions(+), 38 deletions(-) create mode 100644 packages/kit/src/core/make_package/test/fixtures/exports/jsconfig.json delete mode 100644 packages/kit/src/core/make_package/test/fixtures/exports/tsconfig.json diff --git a/packages/kit/src/core/make_package/test/fixtures/exports/expected/package.json b/packages/kit/src/core/make_package/test/fixtures/exports/expected/package.json index 8c14e3c2f330..d9a427508502 100644 --- a/packages/kit/src/core/make_package/test/fixtures/exports/expected/package.json +++ b/packages/kit/src/core/make_package/test/fixtures/exports/expected/package.json @@ -1,7 +1,7 @@ { - "name": "javascript", + "name": "exports", "version": "1.0.0", - "description": "package-javascript-test", + "description": "package-exports-test", "exports": { "./package.json": "./package.json", ".": { diff --git a/packages/kit/src/core/make_package/test/fixtures/exports/jsconfig.json b/packages/kit/src/core/make_package/test/fixtures/exports/jsconfig.json new file mode 100644 index 000000000000..5417394ebe85 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/exports/jsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "checkJs": true, + "paths": { + "$lib/*": ["src/lib/*"] + } + }, + "include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.svelte"] +} diff --git a/packages/kit/src/core/make_package/test/fixtures/exports/package.json b/packages/kit/src/core/make_package/test/fixtures/exports/package.json index af4f9a162250..3d82ac76e8cd 100644 --- a/packages/kit/src/core/make_package/test/fixtures/exports/package.json +++ b/packages/kit/src/core/make_package/test/fixtures/exports/package.json @@ -1,7 +1,7 @@ { - "name": "javascript", + "name": "exports", "version": "1.0.0", - "description": "package-javascript-test", + "description": "package-exports-test", "exports": { "./package.json": "./package.json", ".": { diff --git a/packages/kit/src/core/make_package/test/fixtures/exports/tsconfig.json b/packages/kit/src/core/make_package/test/fixtures/exports/tsconfig.json deleted file mode 100644 index 0f54c3906f8b..000000000000 --- a/packages/kit/src/core/make_package/test/fixtures/exports/tsconfig.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "compilerOptions": { - "moduleResolution": "node", - "module": "es2020", - "lib": ["es2020", "DOM"], - "target": "es2019", - /** - svelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript - to enforce using \`import type\` instead of \`import\` for Types. - */ - "importsNotUsedAsValues": "error", - "isolatedModules": true, - "resolveJsonModule": true, - /** - To have warnings/errors of the Svelte compiler at the correct position, - enable source maps by default. - */ - "sourceMap": true, - "esModuleInterop": true, - "skipLibCheck": true, - "forceConsistentCasingInFileNames": true, - "baseUrl": ".", - "allowJs": true, - "checkJs": true, - "paths": { - "$lib/*": ["src/lib/*"] - } - }, - "include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.ts", "src/**/*.svelte"] -} diff --git a/packages/kit/src/core/make_package/test/fixtures/nested/expected/package.json b/packages/kit/src/core/make_package/test/fixtures/nested/expected/package.json index 4755aebef96b..e42f6745dbed 100644 --- a/packages/kit/src/core/make_package/test/fixtures/nested/expected/package.json +++ b/packages/kit/src/core/make_package/test/fixtures/nested/expected/package.json @@ -1,7 +1,7 @@ { - "name": "javascript", + "name": "nested", "version": "1.0.0", - "description": "package-javascript-test", + "description": "package-nested-test", "type": "module", "exports": { "./package.json": "./package.json", diff --git a/packages/kit/src/core/make_package/test/fixtures/nested/package.json b/packages/kit/src/core/make_package/test/fixtures/nested/package.json index e29e4689c6e0..d575f11b5bef 100644 --- a/packages/kit/src/core/make_package/test/fixtures/nested/package.json +++ b/packages/kit/src/core/make_package/test/fixtures/nested/package.json @@ -1,5 +1,5 @@ { - "name": "javascript", + "name": "nested", "version": "1.0.0", - "description": "package-javascript-test" + "description": "package-nested-test" } diff --git a/packages/kit/src/core/make_package/test/index.js b/packages/kit/src/core/make_package/test/index.js index 4c54f93e0928..00498654c15e 100644 --- a/packages/kit/src/core/make_package/test/index.js +++ b/packages/kit/src/core/make_package/test/index.js @@ -114,4 +114,8 @@ test('create package with user defined settings (exports)', async () => { await test_make_package('exports'); }); +test('create package with preserved files', async () => { + await test_make_package('casing'); +}); + test.run(); From 1b4cbdf7f08374afe77821f239a473110f26a345 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Thu, 8 Jul 2021 17:51:36 +0700 Subject: [PATCH 11/17] test: fixtures for files preservation --- .../test/fixtures/casing/ReadMe.md | 0 .../test/fixtures/casing/expected/ReadMe.md | 0 .../test/fixtures/casing/expected/Test.svelte | 12 ++++++ .../fixtures/casing/expected/Test.svelte.d.ts | 40 +++++++++++++++++++ .../test/fixtures/casing/expected/index.d.ts | 1 + .../test/fixtures/casing/expected/index.js | 1 + .../fixtures/casing/expected/package.json | 12 ++++++ .../test/fixtures/casing/jsconfig.json | 9 +++++ .../test/fixtures/casing/package.json | 5 +++ .../test/fixtures/casing/src/app.html | 12 ++++++ .../test/fixtures/casing/src/lib/Test.svelte | 12 ++++++ .../test/fixtures/casing/src/lib/index.js | 1 + .../test/fixtures/casing/svelte.config.js | 0 13 files changed, 105 insertions(+) create mode 100644 packages/kit/src/core/make_package/test/fixtures/casing/ReadMe.md create mode 100644 packages/kit/src/core/make_package/test/fixtures/casing/expected/ReadMe.md create mode 100644 packages/kit/src/core/make_package/test/fixtures/casing/expected/Test.svelte create mode 100644 packages/kit/src/core/make_package/test/fixtures/casing/expected/Test.svelte.d.ts create mode 100644 packages/kit/src/core/make_package/test/fixtures/casing/expected/index.d.ts create mode 100644 packages/kit/src/core/make_package/test/fixtures/casing/expected/index.js create mode 100644 packages/kit/src/core/make_package/test/fixtures/casing/expected/package.json create mode 100644 packages/kit/src/core/make_package/test/fixtures/casing/jsconfig.json create mode 100644 packages/kit/src/core/make_package/test/fixtures/casing/package.json create mode 100644 packages/kit/src/core/make_package/test/fixtures/casing/src/app.html create mode 100644 packages/kit/src/core/make_package/test/fixtures/casing/src/lib/Test.svelte create mode 100644 packages/kit/src/core/make_package/test/fixtures/casing/src/lib/index.js create mode 100644 packages/kit/src/core/make_package/test/fixtures/casing/svelte.config.js diff --git a/packages/kit/src/core/make_package/test/fixtures/casing/ReadMe.md b/packages/kit/src/core/make_package/test/fixtures/casing/ReadMe.md new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/kit/src/core/make_package/test/fixtures/casing/expected/ReadMe.md b/packages/kit/src/core/make_package/test/fixtures/casing/expected/ReadMe.md new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/kit/src/core/make_package/test/fixtures/casing/expected/Test.svelte b/packages/kit/src/core/make_package/test/fixtures/casing/expected/Test.svelte new file mode 100644 index 000000000000..31d118397f9d --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/casing/expected/Test.svelte @@ -0,0 +1,12 @@ + + + diff --git a/packages/kit/src/core/make_package/test/fixtures/casing/expected/Test.svelte.d.ts b/packages/kit/src/core/make_package/test/fixtures/casing/expected/Test.svelte.d.ts new file mode 100644 index 000000000000..8cfa75e62de7 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/casing/expected/Test.svelte.d.ts @@ -0,0 +1,40 @@ +/** @typedef {typeof __propDef.props} TestProps */ +/** @typedef {typeof __propDef.events} TestEvents */ +/** @typedef {typeof __propDef.slots} TestSlots */ +export default class Test extends SvelteComponentTyped< + { + astring: string; + }, + { + event: CustomEvent; + } & { + [evt: string]: CustomEvent; + }, + { + default: { + astring: string; + }; + } +> { + get astring(): string; +} +export type TestProps = typeof __propDef.props; +export type TestEvents = typeof __propDef.events; +export type TestSlots = typeof __propDef.slots; +import { SvelteComponentTyped } from 'svelte'; +declare const __propDef: { + props: { + astring: string; + }; + events: { + event: CustomEvent; + } & { + [evt: string]: CustomEvent; + }; + slots: { + default: { + astring: string; + }; + }; +}; +export {}; diff --git a/packages/kit/src/core/make_package/test/fixtures/casing/expected/index.d.ts b/packages/kit/src/core/make_package/test/fixtures/casing/expected/index.d.ts new file mode 100644 index 000000000000..637e482009dd --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/casing/expected/index.d.ts @@ -0,0 +1 @@ +export { default as Test } from "./Test.svelte"; diff --git a/packages/kit/src/core/make_package/test/fixtures/casing/expected/index.js b/packages/kit/src/core/make_package/test/fixtures/casing/expected/index.js new file mode 100644 index 000000000000..4c44188c3648 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/casing/expected/index.js @@ -0,0 +1 @@ +export { default as Test } from './Test.svelte'; diff --git a/packages/kit/src/core/make_package/test/fixtures/casing/expected/package.json b/packages/kit/src/core/make_package/test/fixtures/casing/expected/package.json new file mode 100644 index 000000000000..82280e99ecd1 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/casing/expected/package.json @@ -0,0 +1,12 @@ +{ + "name": "casing", + "version": "1.0.0", + "description": "package-casing-test", + "type": "module", + "exports": { + "./package.json": "./package.json", + "./index.js": "./index.js", + "./Test.svelte": "./Test.svelte", + ".": "./index.js" + } +} \ No newline at end of file diff --git a/packages/kit/src/core/make_package/test/fixtures/casing/jsconfig.json b/packages/kit/src/core/make_package/test/fixtures/casing/jsconfig.json new file mode 100644 index 000000000000..5417394ebe85 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/casing/jsconfig.json @@ -0,0 +1,9 @@ +{ + "compilerOptions": { + "checkJs": true, + "paths": { + "$lib/*": ["src/lib/*"] + } + }, + "include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.svelte"] +} diff --git a/packages/kit/src/core/make_package/test/fixtures/casing/package.json b/packages/kit/src/core/make_package/test/fixtures/casing/package.json new file mode 100644 index 000000000000..858292474b29 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/casing/package.json @@ -0,0 +1,5 @@ +{ + "name": "casing", + "version": "1.0.0", + "description": "package-casing-test" +} diff --git a/packages/kit/src/core/make_package/test/fixtures/casing/src/app.html b/packages/kit/src/core/make_package/test/fixtures/casing/src/app.html new file mode 100644 index 000000000000..245305c4ef5b --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/casing/src/app.html @@ -0,0 +1,12 @@ + + + + + + + %svelte.head% + + +
%svelte.body%
+ + diff --git a/packages/kit/src/core/make_package/test/fixtures/casing/src/lib/Test.svelte b/packages/kit/src/core/make_package/test/fixtures/casing/src/lib/Test.svelte new file mode 100644 index 000000000000..31d118397f9d --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/casing/src/lib/Test.svelte @@ -0,0 +1,12 @@ + + + diff --git a/packages/kit/src/core/make_package/test/fixtures/casing/src/lib/index.js b/packages/kit/src/core/make_package/test/fixtures/casing/src/lib/index.js new file mode 100644 index 000000000000..4c44188c3648 --- /dev/null +++ b/packages/kit/src/core/make_package/test/fixtures/casing/src/lib/index.js @@ -0,0 +1 @@ +export { default as Test } from './Test.svelte'; diff --git a/packages/kit/src/core/make_package/test/fixtures/casing/svelte.config.js b/packages/kit/src/core/make_package/test/fixtures/casing/svelte.config.js new file mode 100644 index 000000000000..e69de29bb2d1 From 9120dd0947f1655adaec5bdfc9bf147d92a4926b Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Thu, 8 Jul 2021 17:54:35 +0700 Subject: [PATCH 12/17] fix lint --- .../test/fixtures/casing/expected/index.d.ts | 2 +- .../fixtures/casing/expected/package.json | 22 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/kit/src/core/make_package/test/fixtures/casing/expected/index.d.ts b/packages/kit/src/core/make_package/test/fixtures/casing/expected/index.d.ts index 637e482009dd..4c44188c3648 100644 --- a/packages/kit/src/core/make_package/test/fixtures/casing/expected/index.d.ts +++ b/packages/kit/src/core/make_package/test/fixtures/casing/expected/index.d.ts @@ -1 +1 @@ -export { default as Test } from "./Test.svelte"; +export { default as Test } from './Test.svelte'; diff --git a/packages/kit/src/core/make_package/test/fixtures/casing/expected/package.json b/packages/kit/src/core/make_package/test/fixtures/casing/expected/package.json index 82280e99ecd1..d637970e1d6f 100644 --- a/packages/kit/src/core/make_package/test/fixtures/casing/expected/package.json +++ b/packages/kit/src/core/make_package/test/fixtures/casing/expected/package.json @@ -1,12 +1,12 @@ { - "name": "casing", - "version": "1.0.0", - "description": "package-casing-test", - "type": "module", - "exports": { - "./package.json": "./package.json", - "./index.js": "./index.js", - "./Test.svelte": "./Test.svelte", - ".": "./index.js" - } -} \ No newline at end of file + "name": "casing", + "version": "1.0.0", + "description": "package-casing-test", + "type": "module", + "exports": { + "./package.json": "./package.json", + "./index.js": "./index.js", + "./Test.svelte": "./Test.svelte", + ".": "./index.js" + } +} From aefa670404d9db78bc0874387d1ad017dccdef82 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Thu, 8 Jul 2021 18:02:35 +0700 Subject: [PATCH 13/17] uhm --- .../kit/src/core/make_package/test/fixtures/casing/ReadMe.md | 1 + .../core/make_package/test/fixtures/casing/expected/ReadMe.md | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/kit/src/core/make_package/test/fixtures/casing/ReadMe.md b/packages/kit/src/core/make_package/test/fixtures/casing/ReadMe.md index e69de29bb2d1..e965047ad7c5 100644 --- a/packages/kit/src/core/make_package/test/fixtures/casing/ReadMe.md +++ b/packages/kit/src/core/make_package/test/fixtures/casing/ReadMe.md @@ -0,0 +1 @@ +Hello diff --git a/packages/kit/src/core/make_package/test/fixtures/casing/expected/ReadMe.md b/packages/kit/src/core/make_package/test/fixtures/casing/expected/ReadMe.md index e69de29bb2d1..e965047ad7c5 100644 --- a/packages/kit/src/core/make_package/test/fixtures/casing/expected/ReadMe.md +++ b/packages/kit/src/core/make_package/test/fixtures/casing/expected/ReadMe.md @@ -0,0 +1 @@ +Hello From 67387979462377b83e46c3ba49e1dbbbb148ff48 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Thu, 8 Jul 2021 18:59:53 +0700 Subject: [PATCH 14/17] windows, pls --- 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 847d1463303c..600bbc752948 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()) { write(path.join(cwd, config.kit.package.dir, 'package.json'), JSON.stringify(pkg, null, ' ')); - const project_readme = path.join(cwd, 'README.md'); + const original_case = fs.readdirSync(cwd).find((file) => file.toLowerCase() === 'readme.md'); + const project_readme = path.join(cwd, original_case || 'README.md'); const readme_exists = fs.existsSync(project_readme); if (!readme_exists) return; From 386337027ea99b16edd570c6fdf400cef9b94fca Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Sat, 10 Jul 2021 06:32:58 +0700 Subject: [PATCH 15/17] failing test for added exports --- .../make_package/test/fixtures/exports/expected/package.json | 4 ++-- .../src/core/make_package/test/fixtures/exports/package.json | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/kit/src/core/make_package/test/fixtures/exports/expected/package.json b/packages/kit/src/core/make_package/test/fixtures/exports/expected/package.json index d9a427508502..f561f9dbe440 100644 --- a/packages/kit/src/core/make_package/test/fixtures/exports/expected/package.json +++ b/packages/kit/src/core/make_package/test/fixtures/exports/expected/package.json @@ -3,10 +3,10 @@ "version": "1.0.0", "description": "package-exports-test", "exports": { - "./package.json": "./package.json", ".": { "import": "./index.js" - } + }, + "./package.json": "./package.json" }, "type": "module" } diff --git a/packages/kit/src/core/make_package/test/fixtures/exports/package.json b/packages/kit/src/core/make_package/test/fixtures/exports/package.json index 3d82ac76e8cd..7b6755bb7ce3 100644 --- a/packages/kit/src/core/make_package/test/fixtures/exports/package.json +++ b/packages/kit/src/core/make_package/test/fixtures/exports/package.json @@ -3,7 +3,6 @@ "version": "1.0.0", "description": "package-exports-test", "exports": { - "./package.json": "./package.json", ".": { "import": "./index.js" } From 1e24d9226669bec43aabe019a04d5b72abf5f844 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Sat, 10 Jul 2021 06:35:03 +0700 Subject: [PATCH 16/17] const-ify lets --- packages/kit/src/core/make_package/index.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/kit/src/core/make_package/index.js b/packages/kit/src/core/make_package/index.js index 6f8b51266be0..7746a79c4eaa 100644 --- a/packages/kit/src/core/make_package/index.js +++ b/packages/kit/src/core/make_package/index.js @@ -32,13 +32,12 @@ export async function make_package(config, cwd = process.cwd()) { delete pkg.scripts; pkg.type = 'module'; // type must be 'module' - let user_defined_exports = true; - if (!('exports' in pkg)) { - user_defined_exports = false; - pkg.exports = { - './package.json': './package.json' - }; - } + const user_defined_exports = 'exports' in pkg; + + // We still want to always predefine some exports + // like package.json that is used by other packages + if (!pkg.exports) pkg.exports = {}; + pkg.exports['./package.json'] = './package.json'; for (const file of files) { if (!files_filter(file)) continue; From 8f5294f42aa72ec5106fd53494ca321143b8ae6e Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Sat, 10 Jul 2021 06:35:44 +0700 Subject: [PATCH 17/17] execute instead of continue --- packages/kit/src/core/make_package/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/kit/src/core/make_package/index.js b/packages/kit/src/core/make_package/index.js index 7746a79c4eaa..772cb5236d57 100644 --- a/packages/kit/src/core/make_package/index.js +++ b/packages/kit/src/core/make_package/index.js @@ -104,8 +104,7 @@ export async function make_package(config, cwd = process.cwd()) { 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; - fs.copyFileSync(full_path, package_path); + if (!fs.existsSync(package_path)) fs.copyFileSync(full_path, package_path); } }