Socket
Book a DemoInstallSign in
Socket

mycrypto-path-alias-resolver

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mycrypto-path-alias-resolver

Resolve aliases in ts files

1.0.5-alpha
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

mycrypto-path-alias-resolver

Resolve aliases in ts files. Useful for when you want to publish a package with the typings file in package.json, as a project consuming your package will not respect your package's baseurl and path mappings. This will convert all path mappings to relative paths.

Installation

npm i -D mycrypto-path-alias-resolver

Caveats

Due to the nature of the regex used to resolve multi-line imports, it currently has the limitation of only working with prettier and the follow configuration file:

{
  "printWidth": 80,
  "singleQuote": true,
  "useTabs": false,
  "semi": true,
  "tabWidth": 2,
  "trailingComma": "all"
}

Also, support for resolving aliased exports such as export * from '@src/ethUnits'; is not implemented

How to use

Let's say you have a project that has its source files in <rootDir>/src, and you want to ignore any *.spec.ts or *.test.ts files.

Example tsconfig.json

{
  "compilerOptions": {
    "outDir": "dist",
    "target": "es2017",
    "sourceMap": true,
    "module": "es2015",
    "baseUrl": "./",
    "lib": ["es2017", "dom"],
    "allowSyntheticDefaultImports": true,
    "paths": {
      "@src*": ["src*"],
      "@test*": ["__test__*"]
    },
    "moduleResolution": "node",
    "noEmitOnError": false,
    "noImplicitAny": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "strictNullChecks": true,
    "strictPropertyInitialization": true,
    "noFallthroughCasesInSwitch": true,
    "noImplicitThis": true,
    "pretty": true
  },
  "include": ["./src/", "./__test__/"]
}

Example File Tree

├── coverage
├── dist
├── docs
├── gulpfile.js
├── node_modules
├── package.json
├── package-lock.json
├── readme.md
├── rollup.config.ts
├── src
├── __test__
├── tsconfig-build.json
├── tsconfig.json
└── tslint.json

Corresponding script gulpfile.js to use with above setup

const gulp = require('gulp');
const alias = require('path-alias-resolver/gulp');

gulp.task('default', () => {
  return gulp
    .src(['./src/**/*.ts', '!./src/**/*.spec.ts', '!./src/**/*.test.ts'])
    .pipe(alias('.', { '@src': './src' }))
    .pipe(gulp.dest('./dist/lib'));
});

Breaking gulpfile.js down

['./src/**/*.ts', '!./src/**/*.spec.ts', '!./src/**/*.test.ts']

Ignore any *.spec.ts or *.test.ts files while including all other .ts files in src

alias('.', { '@src': './src' })

The first parameter corresponds to your baseUrl setting in tsconfig.json.

The second parameter is an object of mappings from the paths key in tsconfig.json to its value.

gulp.dest('./dist/lib')

Pass the resulting transformed files to ./dist/list

FAQs

Package last updated on 06 Apr 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.