Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] exclude emitted declarations on packaging #2247

Merged
merged 28 commits into from
Aug 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
54fc6b7
merge preservation test into javascript suite
ignatiusmb Aug 17, 2021
d2e1ce6
rename javascript_no_types to no_emit
ignatiusmb Aug 17, 2021
81f6533
merge nested folders test into javascript suite
ignatiusmb Aug 17, 2021
1e6a26e
change cjs config to js
ignatiusmb Aug 17, 2021
1980ccc
rename again to match settings name
ignatiusmb Aug 17, 2021
c64eec1
more descriptive descriptions
ignatiusmb Aug 17, 2021
6e1b2bf
revert config changes back to cjs
ignatiusmb Aug 17, 2021
2799cb3
rename exports test to exports-replace
ignatiusmb Aug 17, 2021
7a029d1
refactor walk to utils/filesystem
ignatiusmb Aug 18, 2021
b463d3f
fix test regression
ignatiusmb Aug 18, 2021
20940e7
add missing baseUrl to jsconfig
ignatiusmb Aug 18, 2021
85b1f2e
simplify file equality check
ignatiusmb Aug 18, 2021
814b87a
better error assertion message
ignatiusmb Aug 18, 2021
d800ee5
remove typescript type module
ignatiusmb Aug 18, 2021
752d9a2
check if test pass on other machines
ignatiusmb Aug 18, 2021
432b2e4
skipping the test so I don't have to remake it later
ignatiusmb Aug 18, 2021
9ae4994
Merge branch 'chore/packaging-tests' into i1923/filter-emitted-excluded
ignatiusmb Aug 19, 2021
c8400e5
normalize path separator
ignatiusmb Aug 19, 2021
140fa96
fix expected package json contents
ignatiusmb Aug 19, 2021
d5210b7
remove emitted dts for excluded files
ignatiusmb Aug 19, 2021
da2f889
add svelte files to test suite
ignatiusmb Aug 19, 2021
5670f49
use micromatch instead of globrex
ignatiusmb Aug 19, 2021
3bf06ac
filter out nested declarations types
ignatiusmb Aug 19, 2021
5826883
unskip the test
ignatiusmb Aug 19, 2021
cfe5bd2
Merge branch 'master' of https://github.com/sveltejs/kit into i1923/f…
ignatiusmb Aug 21, 2021
a765878
remove old folder from merge conflict
ignatiusmb Aug 21, 2021
241f0a1
final fix from merge conflict
ignatiusmb Aug 21, 2021
c724841
add changeset
ignatiusmb Aug 21, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lazy-spies-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Exclude emitted declarations on packaging
4 changes: 2 additions & 2 deletions packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"@rollup/plugin-replace": "^2.4.2",
"@types/amphtml-validator": "^1.0.1",
"@types/cookie": "^0.4.0",
"@types/globrex": "^0.1.1",
"@types/marked": "^2.0.2",
"@types/micromatch": "^4.0.2",
"@types/mime": "^2.0.3",
"@types/node": "^14.14.43",
"@types/rimraf": "^3.0.0",
Expand All @@ -22,10 +22,10 @@
"cookie": "^0.4.1",
"devalue": "^2.0.1",
"eslint": "^7.25.0",
"globrex": "^0.1.2",
"kleur": "^4.1.4",
"locate-character": "^2.0.5",
"marked": "^2.0.3",
"micromatch": "^4.0.4",
"mime": "^2.5.2",
"node-fetch": "^3.0.0-beta.9",
"port-authority": "^1.1.2",
Expand Down
38 changes: 17 additions & 21 deletions packages/kit/src/packaging/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from 'fs';
import * as path from 'path';
import globrex from 'globrex';
import micromatch from 'micromatch';
import { createRequire } from 'module';
import { preprocess } from 'svelte/compiler';
import { mkdirp, rimraf, walk } from '../utils/filesystem.js';
Expand All @@ -21,8 +21,8 @@ export async function make_package(config, cwd = process.cwd()) {

const files_filter = create_filter(config.kit.package.files);
const exports_filter = create_filter({
...config.kit.package.exports,
exclude: [...config.kit.package.exports.exclude, '*.d.ts']
include: config.kit.package.exports.include,
dummdidumm marked this conversation as resolved.
Show resolved Hide resolved
exclude: [...config.kit.package.exports.exclude, '**/*.d.ts']
});

const files = walk(config.kit.files.lib);
Expand All @@ -40,14 +40,19 @@ export async function make_package(config, cwd = process.cwd()) {
pkg.exports['./package.json'] = './package.json';

for (const file of files) {
if (!files_filter(file)) continue;
const ext = path.extname(file);
const svelte_ext = config.extensions.find((ext) => file.endsWith(ext)); // unlike `ext`, could be e.g. `.svelte.md`

if (!files_filter(file.replace(/\\/g, '/'))) {
const dts_file = (svelte_ext ? file : file.slice(0, -ext.length)) + '.d.ts';
const dts_path = path.join(cwd, config.kit.package.dir, dts_file);
if (fs.existsSync(dts_path)) fs.unlinkSync(dts_path);
continue;
}

const filename = path.join(config.kit.files.lib, file);
const source = fs.readFileSync(filename, 'utf8');

const ext = path.extname(file);
const svelte_ext = config.extensions.find((ext) => file.endsWith(ext)); // unlike `ext`, could be e.g. `.svelte.md`

/** @type {string} */
let out_file;

Expand Down Expand Up @@ -163,21 +168,12 @@ function load_tsconfig(filename, ts) {
}

/**
* @param {{
* include: string[];
* exclude: string[];
* }} options
* @param {{ include: string[]; exclude: string[] }} options
* @returns {(str: string) => boolean}
*/
function create_filter(options) {
const include = options.include.map((str) => str && globrex(str));
const exclude = options.exclude.map((str) => str && globrex(str));

/** @param {string} str */
const filter = (str) =>
include.some((glob) => glob && glob.regex.test(str)) &&
!exclude.some((glob) => glob && glob.regex.test(str));

return filter;
return (str) =>
micromatch.isMatch(str, options.include) && !micromatch.isMatch(str, options.exclude);
}

/**
Expand All @@ -195,7 +191,7 @@ function write(file, contents) {
export async function emit_dts(config) {
const require = createRequire(import.meta.url);
const emit = await try_load_svelte2tsx();
emit({
await emit({
libRoot: config.kit.files.lib,
svelteShimsPath: require.resolve('svelte2tsx/svelte-shims.d.ts'),
declarationDir: config.kit.package.dir
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script>
import { createEventDispatcher } from 'svelte';
/**
* @type {string}
*/
export const astring;

const dispatch = createEventDispatcher();
dispatch('event', true);
</script>

<slot {astring} />
Original file line number Diff line number Diff line change
@@ -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<any>;
} & {
[evt: string]: CustomEvent<any>;
},
{
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<any>;
} & {
[evt: string]: CustomEvent<any>;
};
slots: {
default: {
astring: string;
};
};
};
export {};
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "javascript",
"name": "files-exclude",
"version": "1.0.0",
"description": "standard javascript package",
"description": "files.exclude settings configured",
"type": "module",
"exports": {
"./package.json": "./package.json",
"./internal": "./internal/index.js",
"./Test.svelte": "./Test.svelte",
".": "./index.js"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<script>
import { createEventDispatcher } from 'svelte';
/**
* @type {string}
*/
export const astring;

const dispatch = createEventDispatcher();
dispatch('event', true);
</script>

<slot {astring} />
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const config = {
kit: {
package: {
files: {
exclude: ['**/exclude.js', '*.mjs']
exclude: ['**/*exclude.{js,svelte}', '**/*.mjs']
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/packaging/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ test('create package with default exports settings (replace)', async () => {
await test_make_package('exports-replace');
});

test.skip('create package with files.exclude settings', async () => {
test('create package with files.exclude settings', async () => {
await test_make_package('files-exclude');
});

Expand Down
22 changes: 14 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.