Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
217 changes: 108 additions & 109 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,109 +1,108 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
*-lock.json
dist
.cache
/vendor
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Typescript v1 declaration files
typings/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
lib
# Logs
logs
*.log
npm-debug.log*
# Runtime data
pids
*.pid
*.seed
__MACOSX
.DS_Store
.fuse_hidden*
.project
.settings
.classpath
.sass-cache/
# OS generated files #
######################
*/.DS_Store
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directory
node_modules
# Optional npm cache directory
.npm
# Optional REPL history
.node_repl_history
# Config Files
/.env
# Runtime data
build/**/*
/.npmrc
/client-secret.json
/lib
.tgz
/public/dist
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
*-lock.json
dist
.cache
/vendor
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# nyc test coverage
.nyc_output
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
lib
# Logs
logs
*.log
npm-debug.log*
# Runtime data
pids
*.pid
*.seed
__MACOSX
.DS_Store
.fuse_hidden*
.project
.settings
.classpath
.sass-cache/
# OS generated files #
######################
*/.DS_Store
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directory
node_modules
# Optional npm cache directory
.npm
# Optional REPL history
.node_repl_history
# Config Files
/.env
# Runtime data
build/**/*
/.npmrc
/client-secret.json
/lib
.tgz
/public/dist
*.tsbuildinfo
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"ryanluker.vscode-coverage-gutters"
]
}
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# NLink

Command line interface tool to solve common problems for developing linked modules with transpiled code in [NodeJS](https://nodejs.org/es/).


> NOTE: This module is for development purposes if you new also publish the lib directory you must use in conjuntion with [semantic-release](https://github.com/semantic-release/npm#options) setting up the `pkgRoot` option pointing to the desired lib directory.

## Motivation

Nowdays is not rare to use a preprocesor transpiler such [babeljs](https://babeljs.io/), [coffeescript](https://coffeescript.org/) or [typescript](https://www.typescriptlang.org/). This module enables you to use the a transpiled lib instead of the root directory.

## Getting tarted

Nowdays it's commonly to use a different language for writing modules in NodeJS, such [typescript](https://es.wikipedia.org/wiki/TypeScript) or [coffeescript](https://es.wikipedia.org/wiki/CoffeeScript).

For such cases normally the developer creates a directory `src` containing all the sources that are not pretended to be the final code, so a proccess of transpilation generates a `lib` / `dist` folder to have a controlled way to identify where the final code will be generated, in order to ignore on the git repo or have a simple way to clean up.

Have in mind if a module wants to import a certain file of our library, due the nature of NodeJS, it only allows to exposing in package.json a [one single main file](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#main). This causes to have nested imports of 3 levels [when it should't](https://mui.com/guides/minimizing-bundle-size/#option-1), when the developer needs to [import a certain logic on a subfile](https://stackoverflow.com/questions/38935176/how-to-npm-publish-specific-folder-but-as-package-root).

```javascript
// ✅ OK
import ModuleSubFile from '@scope/packageName/subfile';
// ❌ NOT OK
import ModuleSubFile from '@scope/packageName/lib/subfile';
```

If the module is transpiled using [es-modules](https://tech-wiki.online/es/es-modules.html), this will be solved with [tree shaking](https://developer.mozilla.org/en-US/docs/Glossary/Tree_shaking) but not all versions of nodejs or browser bundlers supports this. So in order to keep the legacy compatibility we must to handle this a easy and smart way without to much headhache.




The idea for linking is to create a copy of the package.json into the `lib` / `dist` folder, a simple way to identify which directory will allocate the transpiled code will be use `tsconfig.json`[.outpuDir](https://www.typescriptlang.org/tsconfig/outDir.html) to use the package.json meta information [directories.lib](https://docs.npmjs.com/cli/v7/configuring-npm/package-json#directories).

## Linking

For development purposes, [linking](https://docs.npmjs.com/cli/v8/commands/npm-link) is a tool which allows us to test a module locally without publishing. If we have the transpiled directory, NodeJS will not be able to discover the desired exposed files, so this tool will provide us a system to identify if the modules is exposed in our environment as linked module in order to replace the linked path to the real one.

## Contributing

This module requires [node@12](https://nodejs.org/download/release/v12.22.7/).

## References
- https://blog.izs.me/2013/02/why-no-directorieslib-in-node-the-less-snarky/
- https://docs.npmjs.com/cli/v8/using-npm/scripts
3 changes: 3 additions & 0 deletions bin/cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

import('../lib/cli.js');
36 changes: 0 additions & 36 deletions clean.js

This file was deleted.

28 changes: 0 additions & 28 deletions cli

This file was deleted.

35 changes: 0 additions & 35 deletions cli.spec.js

This file was deleted.

Loading