-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Source maps and having
sequence
built-in (#48)
- Loading branch information
1 parent
2db8a20
commit 978fd50
Showing
4 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@melt-ui/pp': patch | ||
--- | ||
|
||
fix: Fixed source maps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@melt-ui/pp': minor | ||
--- | ||
|
||
feat: Added a built-in sequential preprocessor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Originally sourced and modified from https://github.com/pchynoweth/svelte-sequential-preprocessor | ||
|
||
import { preprocess } from 'svelte/compiler'; | ||
import { PreprocessorGroup, Processed } from 'svelte/types/compiler/preprocess'; | ||
|
||
/** | ||
* A Svelte preprocessor that wraps other preprocessors and forces them to run sequentially. | ||
* | ||
* @example | ||
* ```js | ||
* // svelte.config.js | ||
* import { preprocessMeltUI, sequence } from '@melt-ui/pp'; | ||
* | ||
* const config = { | ||
* // ... other svelte config options | ||
* preprocess: sequence([ | ||
* // ... other preprocessors (e.g. `vitePreprocess()`) | ||
* preprocessMeltUI() | ||
* ]) | ||
* // ... | ||
* }; | ||
* ``` | ||
*/ | ||
export function sequence(preprocessors: PreprocessorGroup[]): PreprocessorGroup { | ||
return { | ||
async markup({ content, filename }): Promise<Processed> { | ||
let code = content; | ||
let map: Processed['map']; | ||
let attributes: Processed['attributes']; | ||
let toString: Processed['toString']; | ||
const dependencies: Processed['dependencies'] = []; | ||
|
||
for (const pp of preprocessors) { | ||
const processed = await preprocess(code, pp, { filename }); | ||
if (processed && processed.dependencies) { | ||
dependencies.push(...processed.dependencies); | ||
} | ||
code = processed ? processed.code : code; | ||
map = processed.map ?? map; | ||
attributes = processed.attributes ?? attributes; | ||
toString = processed.toString ?? toString; | ||
} | ||
|
||
return { | ||
code, | ||
dependencies, | ||
map, | ||
attributes, | ||
toString, | ||
}; | ||
}, | ||
}; | ||
} |