New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

svelte-as-markup-preprocessor

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-as-markup-preprocessor

Run any svelte preprocessor to completion in the markup phase

  • 0.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
126
increased by200%
Maintainers
2
Weekly downloads
 
Created
Source

asMarkupPreprocessor

Run any svelte preprocessor in the markup phase. Useful anytime you have a markup preprocessor that needs to run after a style or script preprocessor.

Usage

To use, simply wrap all preprocessors above the the dependent preprocessor like so

// svelte.config.js
import {asMarkupPreprocessor} from 'svelte-as-markup-preprocessor'
module.exports = {
  preprocess: [
    asMarkupPreprocessor([
      sveltePreprocess(),
      someOtherPreprocessor()
    ]),
    dependentMarkupPreprocessor()
  ]
}

asMarkupPreprocessor is a simple wrapper around svelte.preprocess, and accepts the same preprocessors array as it. In other words, anything you could put in svelte.config.js's preprocess field, you can pass into us.

Motivation

This was initially written for a preprocessor that walks svelte's ast using svelte.parse and svelte.walk. As those only work on pure svelte files, this was needed to run the all other preprocessors to completion first.

Why is this needed?

Normally, svelte runs its preprocessors in 2 phases. The markup phase, and the script/style phase. The markup phase runs first, and all markup preprocessors run before any script/style preprocessors!

This means with this setup

// svelte.config.js
module.exports = {
  preprocess: [
    preprocessor_1(),
    preprocessor_2(),
    preprocessor_3()
  ]
}

The preprocessors will run in this order

await preprocessor_1.markup()
await preprocessor_2.markup()
await preprocessor_3.markup()
await Promise.all([
  (async()=>{
    await preprocessor_1.style()
    await preprocessor_2.style()
    await preprocessor_3.style()
  })(),
  (async()=>{
    await preprocessor_1.script()
    await preprocessor_2.script()
    await preprocessor_3.script()
  })()
])

As you can see, preprocessor_2 and preprocessor_3's markup preprocessor ran before preprocessor_1's script and style preprocessors.

We act as a wrapper and change the run order. All preprocessors passed into us finish in our markup phase, guaranteeing that they have run before the any preprocessors that run after us. For example

// svelte.config.js
module.exports = {
  preprocess: [
    asMarkupPreprocessor([
      preprocessor_1(),
      preprocessor_2()
    ]),
    preprocessor_3()
  ]
}

Will changing the run order to

await ({async markup() {
  await preprocessor_1.markup()
  await preprocessor_2.markup() 
  await Promise.all([
    (async()=>{
      await preprocessor_1.style()
      await preprocessor_2.style()
    })(),
    (async()=>{
      await preprocessor_1.script()
      await preprocessor_2.script()
    })()
  ])
}}).markup()
await preprocessor_3.markup()
await Promise.all([
  (async()=>{
    await preprocessor_3.style()
  })(),
  (async()=>{
    await preprocessor_3.script()
  })()
])

Now preprocessor_3 does not run until after both preprocessor_1 and preprocessor_2 have finished preprocessing the markup, script, and style!

Keywords

FAQs

Package last updated on 25 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc