Extract a JS/TS module and its dependencies into a new package

Overview

module-extractor

npm Code style: Prettier Donate

Extract a module and its dependencies into a new package

 

Usage

import { extractModules } from 'module-extractor'

const extraction = extractModules({
  // At least one entry module must be given
  entries: ['index.ts'],
  // The directory that contains package.json and source files
  pkgRoot: '/path/to/package',
  // Where to write the extracted modules and package.json
  outPkgRoot: './extracted',
})

// Called as the module graph is crawled
extraction.on('moduleAdded', module => {...})

// Called when an import statement points to an unknown file
extraction.on('moduleNotFound', (id, importer) => {...})

// Called after each tree-shaked module is written
extraction.on('moduleWritten', (filename, code, module) => {...})

// Called after the new package.json is written
extraction.on('packageCreated', (pkgJson) => {...})

// Called when the extraction is complete
extraction.then(() => {...})

 

Quirks

  • Namespace imports prevent tree-shaking

    // All exports of "./foo" will be kept, even if only some are needed.
    import * as foo from './foo'
  • Top-level side effects with unused return values are not preserved

    // Γ— Not preserved in module copy!
    console.log('test')
You might also like...

Find stale dependencies in the package.json file(s).

staledeps Find stale dependencies in the package.json file(s). Installation npm install -g staledeps Or simply using npx, the package runner bundled

Dec 15, 2022

Slide everything into this vanilla javascript slider: just 20kb all-inclusive, no dependencies!

Slide everything into this vanilla javascript slider: just 20kb all-inclusive, no dependencies!

Lightweight vanilla javascript media and contents slider, by LCweb Just 20KB to have: Top features list: single file, no dependencies, 100% pure javas

May 12, 2021

The frontend of a full stack application of a personal wallet made with React, Node and MongoDB that allows you to add inputs, outputs and see all your extract.

The frontend of a full stack application of a personal wallet made with React, Node and MongoDB that allows you to add inputs, outputs and see all your extract.

The frontend of a full stack application of a personal wallet made with React, Node and MongoDB that allows you to add inputs, outputs and see all your extract.

Jun 2, 2022

The backend of a full stack application of a personal wallet made with React, Node and MongoDB that allows you to add inputs, outputs and see all your extract.

The backend of a full stack application of a personal wallet made with React, Node and MongoDB that allows you to add inputs, outputs and see all your extract.

My first full stack application with the concept of a personal wallet that allows you to create a personal account to keep track of your entire statement by adding incoming and outgoing transactions, as well as calculating the total balance and being able to edit and delete old transactions.

Jun 23, 2022

This project is used to extract media from various posting platfroms like Twitter, Reddit, Pixiv, Youtube and many other

Social-Picker-API This project is used to extract media from various posting platfroms like Twitter, Reddit, Pixiv, Youtube and many others. It's writ

Nov 29, 2022

Compare πŸ‘₯ and extract πŸ”¬ differences between JSON values

json-changes Easily compare changes in JSON-like values. This can be especially useful when you want to compare an incoming payload with a counterpart

Aug 23, 2022

Tiny and fast utility to extract all possible values for a given enum.

Tiny (208B) and fast utility to extract all possible values for a given enum.

Apr 18, 2022

A GitHub Action to enable Pages and extract various metadata about a site

A GitHub Action to enable Pages and extract various metadata about a site. It can also be used to configure various static site generators we support as starter workflows.

Jan 1, 2023

Extract CSS custom properties and a JavaScript config from Drupal's theme breakpoints

Extract CSS custom properties and a JavaScript config from Drupal's theme breakpoints

Drupal breakpoints to CSS To eliminate the need for different places for breakpoints and only maintain a single source of truth for those, this node_m

Nov 21, 2022
Comments
  • Support for multiple package.json inputs

    Support for multiple package.json inputs

    Sometimes dev dependencies can exist in a monorepo's root package.json, or maybe I have multiple entries from different packages that I want merged. In the latter case, it would probably be best to add support for an entry-specific config, like so:

    // This maps "outSrcRoot" => "entry"
    entries: {
      'src/foo': 'packages/foo/src/index.ts',
      'src/bar': 'packages/bar/src/index.ts',
    }
    

    Then let's add an array version of pkgRoot option. The highest common ancestor is used to compute module IDs.

    pkgRoots: ['/path/to/packages/foo', '/path/to/packages/bar']
    
    enhancement 
    opened by aleclarson 0
Owner
Alec Larson
Vite maintainer, React Spring co-author, Immer co-author, React Native aficionado, SSR enthusiast
Alec Larson
It's a repository to studies. Its idea is to learn about Nx and its plugins.

StudyingNx This project was generated using Nx. ?? Smart, Fast and Extensible Build System Adding capabilities to your workspace Nx supports many plug

Open-ish 4 May 13, 2022
Can see everything, beware of its omniscience, kneel before its greatness.

Can see everything, beware of its omniscience, kneel before its greatness. Summary Presentation Installation Removing Credits Presentation Main goal T

Duc Justin 3 Sep 30, 2022
Repo for tricking NPM into not hoisting your package. No dependencies and a warning if imported.

noist (Short for No Hoist) Repo for tricking NPM into not hoisting your package. No dependencies and a warning if imported. Why? As of npm@7 NPM suppo

Zackery Griesinger 20 Oct 27, 2022
Userland module that implements the module path mapping that Node.js does with "exports" in package.json

exports-map Userland module that implements the module path mapping that Node.js does with "exports" in package.json npm install exports-map Usage co

Mathias Buus 9 May 31, 2022
Package fetcher is a bot messenger which gather npm packages by uploading either a json file (package.json) or a picture representing package.json. To continue...

package-fetcher Ce projet contient un boilerplate pour un bot messenger et l'executable Windows ngrok qui va permettre de crΓ©er un tunnel https pour c

AILI Fida Aliotti Christino 2 Mar 29, 2022
This package is for developers to be able to easily integrate bad word checking into their projects.\r This package can return bad words in array or regular expression (regex) form.

Vietnamese Bad Words This package is for developers to be able to easily integrate bad word checking into their projects. This package can return bad

Nguyα»…n Quang SΓ‘ng 8 Nov 3, 2022
Transmute one JavaScript string into another by way of mutating its AST. Powered by babel and recast.

equivalent-exchange Transmute one JavaScript string into another by way of mutating its AST. Powered by babel and recast. Features Can parse code usin

Lily Scott 51 Jul 9, 2022
Get into docker, its time now hhh

get_into_docker This repo is a personal reference and a guide in case of need that holds the process on my activities. This repo is a kind of knowledg

Essadeq ELAAMIRI 6 Nov 1, 2022
Show npm package authors and maintainers of your dependencies and devDependencies.

your-deps-authors Show npm package authors and maintainers of your dependencies and devDependencies. Usage $ npx your-deps-authors ╔══════════════════

Sosuke Suzuki 6 Sep 29, 2022
Zero dependencies, lightweight, and asynchronous https requests package.

This project is a Work in Progress and currently in development. The API is subject to change without warning. A small fetching package for super simp

Ray Arayilakath 11 Dec 8, 2022