Skip to content

Commit

Permalink
Fixed build issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jeannemas committed Apr 22, 2024
1 parent 9d0a8df commit 3a541dc
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 24 deletions.
48 changes: 29 additions & 19 deletions scripts/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// @ts-check

import { existsSync, readFileSync } from 'node:fs';
// @ts-expect-error This module can only be referenced with ECMAScript imports/exports by turning on the 'allowSyntheticDefaultImports' flag and referencing its default export.
import { createRequire } from 'node:module';
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
import { preprocess } from 'svelte/compiler';
Expand Down Expand Up @@ -59,15 +58,14 @@ await buildPackage({
*
* @param {Options} options
*/
export async function buildPackage(options) {
async function buildPackage(options) {
// Prepare the validator
const { analyse_code, validate } = createValidator(options);

await doBuild(options, analyse_code);

validate();
}

/**
* Generates a map to which we add the transformed code of Svelte files
* early on when we first need to look at the file contents and can read
Expand Down Expand Up @@ -292,7 +290,7 @@ async function doBuild(options, analyse_code) {
* @param {Record<string, string>} alias
* @param {File[]} files
*/
export async function emit_dts(input, output, cwd, alias, files) {
async function emit_dts(input, output, cwd, alias, files) {
const tmp = `${output}/__package_types_tmp__`;

rimraf(tmp);
Expand Down Expand Up @@ -345,23 +343,15 @@ async function emitDts(config) {
const program = ts.createProgram(filenames, options, host);
const result = program.emit();

if (result.diagnostics.length === 0) {
console.info('Generated d.ts files successfully.');

return;
}
if (result.emitSkipped) {
console.error('Failed to generate d.ts files');

for (const diagnostic of result.diagnostics) {
if (!diagnostic.file) {
continue;
}
await saveEmitResult(result);

console.error(
`File "${diagnostic.file.fileName}" had the following issue:\n`,
diagnostic.messageText,
'\n',
);
process.exit(1);
}

console.info('Generated d.ts files successfully.');
}
/**
* @param {string} filePath
Expand Down Expand Up @@ -600,6 +590,26 @@ async function process_file(input, output, file, preprocessor, aliases, tsconfig
copy(filename, dest);
}
}
/**
* Save the emit result.
*
* @param {import('typescript').EmitResult} result
*/
async function saveEmitResult(result) {
for (const diagnostic of result.diagnostics) {
if (!diagnostic.file) {
continue;
}

console.error(
`File "${diagnostic.file.fileName}" had the following issue:\n`,
diagnostic.messageText,
'\n',
diagnostic.file.text,
'\n',
);
}
}
/**
* @param {string} filePath
*/
Expand All @@ -613,7 +623,7 @@ function toRealSvelteFilepath(filePath) {
* @param {string} filename
* @param {string} source
*/
export async function transpile_ts(tsconfig, filename, source) {
async function transpile_ts(tsconfig, filename, source) {
const options = load_tsconfig(tsconfig, filename, ts);
// transpileModule treats NodeNext as CommonJS because it doesn't read the package.json. Therefore we need to override it.
// Also see https://github.com/microsoft/TypeScript/issues/53022 (the filename workaround doesn't work).
Expand Down
55 changes: 50 additions & 5 deletions src/lib/components/popover/Root.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,56 @@
/**
* The props of the popover component.
*/
export type Props = PopoverPrimitive.Props;
export type Props = {
/**
* Whether or not to close the popover when the escape key is pressed.
*
* @default true
*/
closeOnEscape?: boolean;
/**
* Whether or not to close the popover when the escape key is pressed.
*
* @default true
*/
closeOnOutsideClick?: boolean;
/**
* Whether or not to disable the focus trap when the popover is open.
*
* @default false
*/
disableFocusTrap?: boolean;
/**
* A callback function called when the open state changes.
*/
onOpenChange?: (value: boolean) => void;
/**
* A custom event handler for the "outside click" event, which
* is handled by the `document`.
* If `event.preventDefault()` is called within the function,
* the dialog will not close when the user clicks outside of it.
*/
onOutsideClick?: (event: PointerEvent | MouseEvent | TouchEvent) => void;
/**
* The open state of the popover.
* You can bind this to a boolean value to programmatically control the open state.
*
* @default false
*/
open?: boolean;
/**
* If not undefined, the popover will be rendered within the provided element or selector.
*
* @default 'body'
*/
portal?: HTMLElement | string | null;
/**
* Whether or not to prevent scrolling when the popover is open.
*
* @default false
*/
preventScroll?: boolean;
};
/**
* The slots of the popover component.
*/
Expand All @@ -22,14 +71,12 @@
type $$Props = Attributes & Props;
type $$Slots = Slots;
export let closeFocus: Props['closeFocus'] = undefined;
export let closeOnEscape: Props['closeOnEscape'] = undefined;
export let closeOnOutsideClick: Props['closeOnOutsideClick'] = undefined;
export let disableFocusTrap: Props['disableFocusTrap'] = undefined;
export let onOpenChange: Props['onOpenChange'] = undefined;
export let onOutsideClick: Props['onOutsideClick'] = undefined;
export let open: Props['open'] = undefined;
export let openFocus: Props['openFocus'] = undefined;
export let preventScroll: Props['preventScroll'] = undefined;
export let portal: Props['portal'] = undefined;
Expand All @@ -40,13 +87,11 @@
</style> -->

<PopoverPrimitive.Root
closeFocus="{closeFocus}"
closeOnEscape="{closeOnEscape}"
closeOnOutsideClick="{closeOnOutsideClick}"
disableFocusTrap="{disableFocusTrap}"
onOpenChange="{onOpenChange}"
onOutsideClick="{onOutsideClick}"
openFocus="{openFocus}"
preventScroll="{preventScroll}"
portal="{portal}"
bind:open="{open}"
Expand Down

0 comments on commit 3a541dc

Please sign in to comment.