2.1.1 • Published 6 years ago

bestie v2.1.1

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

bestie

npm version

bestie is a Node.js package to build Node.js packages with import and export statements. The goal of this project is to start with using the babel AST parsing to build packages to allow functionality, however then to implement a regular expression transform stream which would update references to import into require statements. The motivation for this is that a modern Node.js package would only need a single babel transform to allow imports and exports, however all babel dependencies need to be installed and linked (around 5500 dependencies). Also, when transpiling, babel transform will use requireInterop expression which VS Code IDE cannot parse, and the JSDoc documentation disappears from all functions etc not exported in the main file.

yarn add -DE bestie

Table Of Contents

CLI

To install bestie, you need to clone its repository in the working directory, and install it with the dev dependencies from there. Then, yarn link it, and again in other projects.

cd ~/work
git clone https://github.com/artdecocode/bestie.git
cd bestie
yarn
link
cd ..
cd project
yarn link bestie

Because the all dependencies that the babel needs are in the bestie directory, they will be used. No need to install them for each individual project.

The usage via the CLI is encouraged and can be achieved by specifying a script field in the package.json file, e.g.,

{
  "name": "package",
  "scripts": {
    "build": "b"
  },
  "dependencies": {
    "bestie": "2.0.0"
  }
}

--init, -i: Init .Babelrc

Create a .babelrc file in the current direcory. The default content is:

{
  "plugins": [
    "@babel/plugin-syntax-object-rest-spread",
    "@babel/plugin-transform-modules-commonjs"
  ],
  "env": {
    "test-build": {
      "plugins": [
        [
          "transform-rename-import",
          {
            "original": "^((../)+)src",
            "replacement": "$1build"
          }
        ]
      ],
      "ignore": [
        "build/**/*.js"
      ]
    },
    "debug": {
      "retainLines": true
    }
  }
}

--help, -h: Show Help

A command-line tool to build packages.
  Source is the first argument, followed by any additional arguments
  Default source is src and default out-dir is build.
  Any other additional arguments are passed along to babel.


  bestie [src] [--out-dir build] [[--copy-files] --etc] | -iIU

	--help, -h     	Print the help message.
	--init, -i     	Write the .babelrc in the current directory.
	--install, -I  	Add @babel dependencies.
	--uninstall, -U	Remove @babel dependencies from the current directory.

  Example:

    bestie src --out-dir build --copy-files

b [src] [--out-dir=build]: Build Project

The b binary will build the project, taking the files from the src directory and transpiling them into files in the out-dir.

bestie -e .: Print Node_modules Size

When installed globally, bestie can report the size of node_modules directory with -e command. The size is got from the du command. It might differ from the du -sh ./*/node_modules report.

rel                    size    
idio-dev               146.3 MB
artdeco.bz             143.8 MB
idio                   83.5 MB 
rqt                    65.6 MB 
koa2-jsx               54.2 MB 
adc.sh                 45.5 MB 
appshot                24.7 MB 
mnp                    10 MB   
documentary            9.3 MB  
pedantry               8 MB    
assert-throws          7.9 MB  
africa                 7.4 MB  
restream               7.4 MB  
expensive              7.1 MB  
usually                7.1 MB  
erte                   7.1 MB  
tablature              7.1 MB  
bosom                  7.1 MB  
zoroaster              7.1 MB  
snapshot-context       7 MB    
argufy                 6.4 MB  
makepromise            6.3 MB  
reloquent              6.1 MB  
erotic                 5.8 MB  
pompeii                5.6 MB  
ictx                   5.6 MB  
window-info            5.6 MB  
irio                   5.6 MB  
nodeeu                 5.6 MB  
aqt                    5.6 MB  
spawncommand           4.7 MB  
eslint-config-artdeco  4.6 MB  
yarn-s                 4.6 MB  
mnp-idio               4.6 MB  
mnp-irio               0 MB

bestie -I: Install @Babel

Installs the modules in the list below in the current package directory with the latest version.

@babel/cli
@babel/core
@babel/register
@babel/plugin-syntax-object-rest-spread
@babel/plugin-transform-modules-commonjs
babel-plugin-transform-rename-import
Offices-iMac:structure zavr$ yarn bI
yarn run v1.7.0
$ b -I
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 134 new dependencies.
info Direct dependencies
├─ @babel/cli@7.0.0-beta.51
├─ @babel/core@7.0.0-beta.51
├─ @babel/plugin-syntax-object-rest-spread@7.0.0-beta.51
├─ @babel/plugin-transform-modules-commonjs@7.0.0-beta.51
├─ @babel/register@7.0.0-beta.51
└─ babel-plugin-transform-rename-import@2.2.0
info All dependencies
├─ @babel/cli@7.0.0-beta.51
├─ @babel/core@7.0.0-beta.51
├─ @babel/helper-function-name@7.0.0-beta.51
├─ @babel/helper-get-function-arity@7.0.0-beta.51
├─ @babel/helper-module-imports@7.0.0-beta.51
├─ @babel/helper-module-transforms@7.0.0-beta.51
├─ @babel/helpers@7.0.0-beta.51
├─ @babel/highlight@7.0.0-beta.51
├─ @babel/plugin-syntax-object-rest-spread@7.0.0-beta.51
├─ @babel/plugin-transform-modules-commonjs@7.0.0-beta.51
├─ @babel/register@7.0.0-beta.51
├─ abbrev@1.1.1
├─ anymatch@2.0.0
├─ aproba@1.2.0
├─ are-we-there-yet@1.1.5
├─ arr-flatten@1.1.0
├─ assign-symbols@1.0.0
├─ async-each@1.0.1
├─ atob@2.1.1
├─ babel-plugin-transform-rename-import@2.2.0
├─ base@0.11.2
├─ binary-extensions@1.11.0
├─ braces@2.3.2
├─ cache-base@1.0.1
├─ chokidar@2.0.4
├─ chownr@1.0.1
├─ class-utils@0.3.6
├─ code-point-at@1.1.0
├─ collection-visit@1.0.0
├─ commander@2.15.1
├─ commondir@1.0.1
├─ console-control-strings@1.1.0
├─ copy-descriptor@0.1.1
├─ core-js@2.5.7
├─ debug@2.6.9
├─ decode-uri-component@0.2.0
├─ deep-extend@0.6.0
├─ delegates@1.0.0
├─ detect-libc@1.0.3
├─ expand-brackets@2.1.4
├─ extglob@2.0.4
├─ fill-range@4.0.0
├─ find-cache-dir@1.0.0
├─ find-up@2.1.0
├─ for-in@1.0.2
├─ fs-minipass@1.2.5
├─ fs-readdir-recursive@1.1.0
├─ fsevents@1.2.4
├─ gauge@2.7.4
├─ get-value@2.0.6
├─ glob-parent@3.1.0
├─ has-unicode@2.0.1
├─ has-value@1.0.0
├─ has-values@1.0.0
├─ home-or-tmp@3.0.0
├─ ignore-walk@3.0.1
├─ ini@1.3.5
├─ invariant@2.2.4
├─ is-accessor-descriptor@1.0.0
├─ is-binary-path@1.0.1
├─ is-data-descriptor@1.0.0
├─ is-descriptor@1.0.2
├─ is-extglob@2.1.1
├─ is-glob@4.0.0
├─ is-odd@2.0.0
├─ is-plain-obj@1.1.0
├─ is-plain-object@2.0.4
├─ is-windows@1.0.2
├─ jsesc@2.5.1
├─ json5@0.5.1
├─ kind-of@3.2.2
├─ locate-path@2.0.0
├─ lodash.debounce@4.0.8
├─ loose-envify@1.3.1
├─ make-dir@1.3.0
├─ map-visit@1.0.0
├─ micromatch@3.1.10
├─ minizlib@1.1.0
├─ mixin-deep@1.3.1
├─ nan@2.10.0
├─ nanomatch@1.2.9
├─ needle@2.2.1
├─ node-modules-regexp@1.0.0
├─ node-pre-gyp@0.10.2
├─ nopt@4.0.1
├─ npm-bundled@1.0.3
├─ npm-packlist@1.1.10
├─ npmlog@4.1.2
├─ number-is-nan@1.0.1
├─ object-copy@0.1.0
├─ os-homedir@1.0.2
├─ osenv@0.1.5
├─ output-file-sync@2.0.1
├─ p-limit@1.3.0
├─ p-locate@2.0.0
├─ p-try@1.0.0
├─ pascalcase@0.1.1
├─ path-dirname@1.0.2
├─ path-exists@3.0.0
├─ path-parse@1.0.5
├─ pirates@3.0.2
├─ pkg-dir@2.0.0
├─ posix-character-classes@0.1.1
├─ rc@1.2.8
├─ readdirp@2.1.0
├─ remove-trailing-separator@1.1.0
├─ repeat-element@1.1.2
├─ resolve-url@0.2.1
├─ resolve@1.8.1
├─ ret@0.1.15
├─ sax@1.2.4
├─ set-blocking@2.0.0
├─ set-immediate-shim@1.0.1
├─ set-value@2.0.0
├─ slash@1.0.0
├─ snapdragon-node@2.1.1
├─ snapdragon-util@3.0.1
├─ source-map-resolve@0.5.2
├─ source-map-support@0.4.18
├─ source-map-url@0.4.0
├─ source-map@0.5.7
├─ split-string@3.1.0
├─ static-extend@0.1.2
├─ tar@4.4.4
├─ to-fast-properties@2.0.0
├─ to-regex-range@2.1.1
├─ trim-right@1.0.1
├─ union-value@1.0.0
├─ unset-value@1.0.0
├─ upath@1.1.0
├─ urix@0.1.0
├─ use@3.1.0
├─ wide-align@1.1.3
└─ yallist@3.0.2
✨  Done in 62.53s.

bestie -U: Uninstall @Babel

Removes the modules (from the same list as installed), and will ask for confirmation beforehand:

Continue removing
 @babel/cli@7.0.0-beta.51
 @babel/core@7.0.0-beta.51
 @babel/register@7.0.0-beta.51
 @babel/plugin-syntax-object-rest-spread@7.0.0-beta.51
 @babel/plugin-transform-modules-commonjs@7.0.0-beta.51
 babel-plugin-transform-rename-import@2.2.0
from bestie? [y] n

API

bestie can also be used programmatically and has the following API.

async bestie(  config: {    from?: string = src,    to?: string = build,    args?: string[] = [],    stdout?: Stream = process.stdout,    stderr?: Stream = process.stderr,    cwd?: string = process.cwd(),  },): void

Calling the bestie function from the source code will return a promise to transpile files. In background, babel will be spawned via the child_process.

import bestie from 'bestie'

(async () => {
  await bestie({
    from: 'src',
    to: 'build',
    args: ['--copy-files', '--include-dotfiles'],
    stdout: process.stdout,
    stderr: process.stderr,
    cwd: process.cwd(),
  })
})()
node_modules/@babel/cli/bin/babel.js src --out-dir build --copy-files --include-dotfiles 

🎉  Successfully compiled 6 files with Babel.

How To Reduce The Size Of Node_modules

Before upgrading to using bestie, a standard package node_module directory would occupy ~ 90 MB of disk space, including @babel/cli, @babel/core, @babel/register, @babel/plugin-syntax-object-rest-spread, @babel/plugin-transform-modules-commonjs, babel-plugin-transform-rename-import and eslint.

At first, @babel was removed, and then eslint. This allowed to save 2 GB of disk space in total.

namevsizesize2size3final
adc.sh7.0.0-beta.46840644651246512x0.8
africa7.0.0-beta.5188472462007608x10.6
appshot7.0.0-beta.491040886168025320x3.1
aqt7.0.0-beta.51124712810405688x20.9
argufy7.0.0-beta.516248066006600x8.4
artdeco.bz7.0.0-beta.47197640171032147296x0.3
assert-throws7.0.0-beta.466017680648064x6.4
bestie7.0.0-beta.51642406410464120x0
bosom7.0.0-beta.4990808458407232x11.5
documentary7.0.0-beta.5190928465447936x10.4
erotic7.0.0-beta.4989192445205928x14
erte7.0.0-beta.4990896458407232x11.5
eslint-config-artdeco474447444744x0
expensive7.0.0-beta.5191320458967288x11.5
ictx7.0.0-beta.4989048442965688x14.6
idio7.0.0-beta.4715545611128885512x0.8
idio-dev7.0.0-beta.49198536173016149816x0.3
irio7.0.0-beta.4989048442965688x14.6
koa2-jsx7.0.0-beta.471255208156855544x1.2
makepromise7.0.0-beta.465845664166416x8.1
mnp7.0.0-beta.49931764888810280x8
mnp-idio472047204720x0
mnp-irio888x0
nodeeu7.0.0-beta.4989048442965688x14.6
pedantry7.0.0-beta.5189800467608152x10
pompeii7.0.0-beta.4989048442965688x14.6
reloquent7.0.0-beta.4988568444246296x13
restream7.0.0-beta.516314475927592x7.3
rqt7.0.0-beta.5117392013086467128x1.5
snapshot-context7.0.0-beta.476445671607160x8
spawncommand7.0.0-beta.476226448164816x11.9
tablature7.0.0-beta.499074472327232x11.5
usually7.0.0-beta.4990736458407232x11.5
window-info7.0.0-beta.4989296442965688x14.6
yarn-s7.0.0-beta.465625647444744x10.8
zoroaster7.0.0-beta.4790168458327224x11.4
total3120 MB1671 MB801 MBx3

(c) Art Deco Code 2018

2.1.1

6 years ago

2.1.0

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.0

6 years ago