Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

craco-alias

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

craco-alias - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

plugin/debug.js

2

package.json
{
"name": "craco-alias",
"version": "2.0.0",
"version": "2.1.0",
"description": "A craco plugin for automatic aliases generation",

@@ -5,0 +5,0 @@ "main": "plugin/index.js",

const preCheck = require('./pre-check')
const normalizePluginOptions = require('./normalize-plugin-options')
const extractAliases = require('./extract-aliases')
const { searchObject, printBaseData, printObject } = require('./debug')
const createOverrider = cb => cracoOptions => {
const createOverrider = (cb, debugInfo) => cracoOptions => {
preCheck(cracoOptions)

@@ -11,5 +12,21 @@

return cb({ aliases, options }, cracoOptions)
if (options.debug) {
printBaseData({
initialOptions: cracoOptions.pluginOptions,
normalizedOptions: options,
aliases
})
}
const overridedConfig = cb({ aliases, options }, cracoOptions)
if (options.debug) {
const { name, aliasesPath } = debugInfo
const aliases = searchObject(overridedConfig, aliasesPath)
printObject(name, aliases)
}
return overridedConfig
}
module.exports = createOverrider

@@ -5,19 +5,31 @@ const createOverrider = require('./create-overrider')

module.exports = {
overrideWebpackConfig: createOverrider(({ aliases }, { webpackConfig }) => ({
...webpackConfig,
resolve: {
...webpackConfig.resolve,
alias: {
...webpackConfig.resolve.alias,
...aliases
overrideWebpackConfig: createOverrider(
({ aliases }, { webpackConfig }) => ({
...webpackConfig,
resolve: {
...webpackConfig.resolve,
alias: {
...webpackConfig.resolve.alias,
...aliases
}
}
}),
{
name: 'Webpack Config',
aliasesPath: 'resolve.alias'
}
})),
overrideJestConfig: createOverrider(({ aliases }, { jestConfig }) => ({
...jestConfig,
moduleNameMapper: {
...jestConfig.moduleNameMapper,
...generateModuleNameMapper({ aliases })
),
overrideJestConfig: createOverrider(
({ aliases }, { jestConfig }) => ({
...jestConfig,
moduleNameMapper: {
...jestConfig.moduleNameMapper,
...generateModuleNameMapper({ aliases })
}
}),
{
name: 'Jest Config',
aliasesPath: 'moduleNameMapper'
}
}))
)
}

@@ -21,3 +21,4 @@ const exitWithError = require('./exit-with-error')

baseUrl: './',
aliases: {}
aliases: {},
debug: false
}

@@ -29,3 +30,4 @@

tsConfigPath,
aliases = {}
aliases = {},
debug = false
} = originalOptions

@@ -36,3 +38,4 @@

source,
baseUrl
baseUrl,
debug
}

@@ -44,3 +47,4 @@

baseUrl,
tsConfigPath
tsConfigPath,
debug
}

@@ -51,3 +55,4 @@

baseUrl,
aliases
aliases,
debug
}

@@ -54,0 +59,0 @@ }

@@ -8,3 +8,4 @@ const normalize = require('./normalize-plugin-options')

baseUrl: './',
aliases: {}
aliases: {},
debug: false
})

@@ -15,3 +16,4 @@

baseUrl: './',
aliases: {}
aliases: {},
debug: false
})

@@ -29,3 +31,4 @@ })

source: 'jsconfig',
baseUrl: './'
baseUrl: './',
debug: false
})

@@ -44,3 +47,4 @@ })

baseUrl: './',
tsConfigPath: 'tsconfig.paths.json'
tsConfigPath: 'tsconfig.paths.json',
debug: false
})

@@ -63,5 +67,6 @@ })

'@file': './file.js'
}
},
debug: false
})
})
})

@@ -47,4 +47,10 @@ const normalizePluginOptions = require('../normalize-plugin-options')

}
if (typeof options.debug !== 'boolean') {
return handleError(
'The "debug" option should be a boolean value'
)
}
}
module.exports = checkOptions

@@ -88,2 +88,16 @@ const path = require('path')

})
test('should check "debug"', () => {
mockedCheck({
pluginOptions: {
source: 'options',
aliases: {},
debug: 35345
}
})
expect(handleErrorMock).toHaveBeenLastCalledWith(
'The "debug" option should be a boolean value'
)
})
})

@@ -12,2 +12,3 @@ # craco-alias

- [Examples](#examples)
- [Ran into a problem?](#ran-into-a-problem)

@@ -45,18 +46,22 @@ ### Installation

- `source`:
- `source`:
One of `"options"`, `"jsconfig"`, `"tsconfig"`
Defaults to `"options"`
- `baseUrl`:
A base url for aliases. (`./src` for example)
- `baseUrl`:
A base url for aliases. (`./src` for example)
Defaults to `./` (project root directory)
- `aliases`:
- `aliases`:
An object with aliases names and paths
Defaults to `{}`
- `tsConfigPath`:
- `tsConfigPath`:
A path to tsconfig file
Only required when `source` is set to `"tsconfig"`
- `debug`:
Enable it if you ran into a problem. It will log a useful info in console.
Defaults to `false`
### Examples

@@ -118,3 +123,3 @@

> **Note:** your jsconfig should always have `compilerOptions.paths` property. `baseUrl` is optional for plugin, but some IDEs and editors require it for intellisense.
> **Note:** your jsconfig should always have `compilerOptions.paths` property. `baseUrl` is optional for plugin, but some IDEs and editors require it for intellisense.

@@ -172,3 +177,3 @@ ```js

```
6. Edit `craco.config.js`:

@@ -197,1 +202,13 @@

</details>
### Ran into a problem?
1. Make sure your config is valid.
2. Set `debug` to `true` in [options](#options).
3. Run application again.
4. Copy a printed info.
5. [Here](https://github.com/risenforces/craco-alias/issues), create an issue describing your problem (do not forget to add the debug info).
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc