npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

farm-plugin-selective

v0.2.1

Published

Selective compilation plugin for FarmFE — conditionally include/exclude code at function, class, statement, and page level

Readme

farm-plugin-selective

Selective compilation plugin for FarmFE — conditionally include/exclude code at function, class, statement, and page level.

Install

npm install farm-plugin-selective

Dependencies: This plugin uses core-ast-ts internally for AST parsing. Installed automatically.

Concept

In a multi-app monorepo, different platforms (mobile, web, desktop) share code but also have platform-specific logic. This plugin lets you mark code with conditions so that only matching branches are compiled in — at function, class, variable, statement, and even page level.

Usage

import selective from 'farm-plugin-selective'

export default {
  plugins: [
    selective({
      conditions: {
        platform: 'mobile',
        features: ['premium', 'analytics'],
        debug: false,
      },
    }),
  ],
}

Or set conditions via environment variable:

SELECTIVE_CONDITIONS='{"platform":"mobile","features":["premium"]}' farm build

Or key=value format:

SELECTIVE_CONDITIONS='platform=mobile,features=premium|analytics,debug=false' farm build

API Surface

@selective('condition') — Function/Class/Variable level

Decorate a declaration to include it only when the condition matches.

@selective('platform:mobile')
function mobileLayout() { /* only in mobile builds */ }

@selective('feature:premium')
class PremiumDashboard { /* only when premium feature enabled */ }

@selective('!debug:true')
const API_URL = '/api'  /* excluded in debug builds */

When the condition doesn't match:

  • Functions → empty stub function name() {}
  • Classes → empty stub class name {}
  • Variables → const name = undefined

$selective('condition', include, exclude?) — Expression level

const layout = $selective('platform:mobile', () => MobileLayout, () => WebLayout)
// → MobileLayout (when platform=mobile)
// → WebLayout (when platform!=mobile)

const color = $selective('feature:premium', () => 'gold')
// → 'gold' (when feature includes premium)
// → undefined (otherwise)

$selective.block('condition', () => { ... }) — Statement level

$selective.block('debug:true', () => {
  console.log('debug info')
  setupDevtools()
})
// → keeps the statements when debug=true
// → removes entirely when debug=false

@runtime — Compile-time code generator

A function decorated with @runtime executes at compile time. Its return value (a code string) replaces all call sites.

@runtime
function createHandler(env) {
  if (env.platform === 'mobile') {
    return `(url) => fetch('/m' + url)`
  }
  return `(url) => fetch('/api' + url)`
}

const handler = createHandler()
// → const handler = ((url) => fetch('/m' + url))  (when platform=mobile)

The function receives the current conditions object as its first argument, enabling condition-aware code generation.

Page-level selective compilation

selective({
  conditions: { platform: 'mobile' },
  pagePatterns: ['src/pages/**/*.vue', 'src/pages/**/*.tsx'],
})

When a page file contains @selective('condition') and the condition doesn't match, the entire page is replaced with an empty component stub. This means the page still exists in the route tree but renders nothing — no dead routes.

Custom empty page template:

selective({
  conditions: { platform: 'mobile' },
  pagePatterns: ['src/pages/**/*.vue'],
  emptyPageTemplate: (name, ext) => {
    if (ext === '.vue') return `<template><div></div></template>`
    return `export default function ${name}() { return null }`
  },
})

Condition Syntax

| Syntax | Meaning | |--------|---------| | platform:mobile | platform equals "mobile" | | !platform:mobile | platform is NOT "mobile" | | feature:premium,basic | feature is "premium" OR "basic" | | feature:* | feature key exists (any value) | | !feature:* | feature key does NOT exist | | platform:mobile && feature:premium | both conditions | | platform:mobile || platform:web | either condition |

HMR

When source files change, conditions are re-resolved and affected modules are re-transformed.

License

MIT