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

@flatjs/evolve-launch-editor

v2.1.3

Published

## Usage

Downloads

26

Readme

@flatjs/evolve-launch-editor

Usage

  1. flatjs-evolve.config.ts

import { createLaunchEditorMiddleware } from '@flatjs/evolve-launch-editor';

export default defineConfig((env) => ({
  projectVirtualPath: '',
  devServer: {
    middlewares: [createLaunchEditorMiddleware({})],
    mockOptions: {
      port: 8000,
      ...
    },
  },

  ...
})
  1. Custom fetch server api to open the code editor gotoServerEditor.ts
const getCodeInfo = (codeInfo) =>
  'codeInfo' in codeInfo ? codeInfo.codeInfo : codeInfo;

// Note if you have an customized `devServer.pageProxy` in `flatjs-evolve.config.ts`
// e.g. `devServer.pageProxy: 'route'`, you should change to `/route/__inspect-open-in-editor`
const launchEditorEndpoint = '/pages/__inspect-open-in-editor';

/**
 * fetch server api to open the code editor
 */
export const gotoServerEditor = (
  codeInfo?,
  options?: {
    editor?;
  }
) => {
  if (!codeInfo) return;
  codeInfo = getCodeInfo(codeInfo);

  const { lineNumber, columnNumber, relativePath, absolutePath } = codeInfo;

  const isRelative = Boolean(relativePath);
  const fileName = isRelative ? relativePath : absolutePath;

  if (!fileName) {
    console.error(
      `[react-dev-inspector] Cannot open editor without source fileName`,
      codeInfo
    );
    return;
  }

  const launchParams = {
    fileName,
    lineNumber,
    colNumber: columnNumber,
    editor: options?.editor,
  };

  const urlParams = new URLSearchParams(
    Object.entries(launchParams).filter(([, value]) => Boolean(value)) as [
      string,
      string,
    ][]
  );

  fetchToServerEditor({
    apiUrl: launchEditorEndpoint,
    urlParams,
  });
};

const fetchToServerEditor = async ({
  apiUrl,
  urlParams,
  fallbackUrl,
}: {
  apiUrl: string;
  urlParams: URLSearchParams;
  fallbackUrl?: string;
}) => {
  const response = await fetch(`${apiUrl}?${urlParams}`);
  // only 404 need to try fallback legacy endpoint
  if (response.status === 404 && fallbackUrl) {
    return await fetch(`${fallbackUrl}?${urlParams}`);
  }
  return response;
};
  1. Create tsx component named FileInspector
import { useState } from 'react';
import { Inspector } from 'react-dev-inspector';
import { gotoServerEditor } from './gotoServerEditor';

export const FileInspector = () => {
  const [active, setActive] = useState(false);

  return (
    <Inspector
      active={active}
      onActiveChange={setActive}
      onInspectElement={gotoServerEditor}
    >
      <div className="mx-auto max-w-2xl">
        <div className="text-center">
          <div className="mt-8 flex flex-col items-center justify-center gap-x-6">
            <div className="mb-2 mt-6 text-[min(4.5vw,1rem)] font-light leading-[min(6vw,1.75rem)] text-gray-600 sm:text-lg">
              try shortcuts or click ↓
            </div>

            <button
              className="group flex items-center text-[min(4vw,.875rem)] leading-[min(5vw,1.25rem)] sm:text-base"
              onClick={() => setActive(true)}
            >
              <span>Ctrl + Shift + Command + C</span>
              <span className="ml-1">🍭</span>
            </button>
          </div>
        </div>
      </div>
    </Inspector>
  );
};

Custom editor support

You can use the LAUNCH_EDITOR environment variable to force a specific supported editor

LAUNCH_EDITOR=code
LAUNCH_EDITOR=code-insiders

Supported editors

| Value | Editor | Linux | Windows | macOS | | --------------- | ---------------------------------------------------------------------- | :---: | :-----: | :---: | | appcode | AppCode | | | ✓ | | atom | Atom | ✓ | ✓ | ✓ | | atom-beta | Atom Beta | | | ✓ | | brackets | Brackets | ✓ | ✓ | ✓ | | clion | Clion | | ✓ | ✓ | | code | Visual Studio Code | ✓ | ✓ | ✓ | | code-insiders | Visual Studio Code Insiders | ✓ | ✓ | ✓ | | codium | VSCodium | ✓ | ✓ | ✓ | | emacs | Emacs | ✓ | | | | idea | IDEA | ✓ | ✓ | ✓ | | notepad++ | Notepad++ | | ✓ | | | pycharm | PyCharm | ✓ | ✓ | ✓ | | phpstorm | PhpStorm | ✓ | ✓ | ✓ | | rider | Rider | ✓ | ✓ | ✓ | | rubymine | RubyMine | ✓ | ✓ | ✓ | | sublime | Sublime Text | ✓ | ✓ | ✓ | | vim | Vim | ✓ | | | | visualstudio | Visual Studio | | | ✓ | | webstorm | WebStorm | ✓ | ✓ | ✓ | | zed | Zed | | | ✓ |