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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@macropygia/pug-graph

v0.0.7

Published

Parses include and extends in a Pug file and gets dependencies.

Downloads

2

Readme

@macropygia/pug-graph

npm version MIT TypeScript Pug

English | 日本語

Pugの includeextends を解析して依存関係を取得する

  • このパッケージは不安定版です
    • パッチリリースを含め予告なく破壊的変更が行われる可能性があります
    • 変更点は CHANGELOG をご覧ください
  • 実行前にPrettierの @prettier/plugin-pug を使用してフォーマットすることを推奨
  • 半角スペースのみインデントとして認識する

インストール

npm install @macropygia/pug-graph

使用方法

import fg from 'fast-glob'
import PugGraph from '@macropygia/pug-graph'

// 初期化
const graph = new PugGraph({ baseDir: 'src' })

// 追加
await graph.parse('src/foo.pug')

// 再帰的に追加
await graph.parse('src/foo.pug', { recursive: true })

// 更新
await graph.parse('src/foo.pug')

// 削除
graph.unlink('src/foo.pug')

// 複数ファイルの処理
const files = fg.sync('src/**/[^_]*.pug')
await Promise.all(
  files.map((file) =>
    graph.parse(file, { recursive: true })
  )
)

// 依存関係を取得
const fooDependsOn = graph.getImportedFiles('src/foo.pug')
const barIsImportedBy = graph.getImporters('src/templates/mixins/_bar.pug', {
  ignorePartial: true,
})

// 終了
graph.exit()

API

constructor(options)

| Parameter | Type | Default | Required | | -------------------- | --------- | ------- | -------- | | options.baseDir | string | "" | No | | options.useAbsPath | boolean | false | No |

  • options.baseDir
    • Pugの同名オプションと同一
  • options.useAbsPath
    • 絶対パスを使用する

parse(filepath, options)

| Parameter | Type | Default | Required | | --------------------------- | --------- | ------- | -------- | | filepath | string | | Yes | | options.insertOnly | boolean | false | No | | options.recursive | boolean | false | No | | options.updateDescendants | boolean | false | No |

  • 非同期
  • options.insertOnly
    • データベース上に存在する場合はスキップする
  • options.recursive
    • 再帰的に実行する
    • データベース上に存在する子孫はスキップする
  • options.updateDescendants
    • データベース上に存在する子孫も更新する

getImportedFiles(filepath)

| Parameter | Type | Default | Required | | ---------- | -------- | ------- | -------- | | filepath | string | | Yes |

  • Returns: Set<string>

getImporters(filepath, ignorePartial)

| Parameter | Type | Default | Required | | --------------- | --------- | ------- | -------- | | filepath | string | | Yes | | ignorePartial | boolean | false | No |

  • Returns: Set<string>

unlink(filepath)

| Parameter | Type | Default | Required | | ---------- | -------- | ------- | -------- | | filepath | string | | Yes |

getRawData()

  • Returns: object[]
  • データベースの全レコードのオブジェクト配列を返す

exit()

  • データベースを閉じて終了する