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

unimport

Package Overview
Dependencies
Maintainers
3
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unimport - npm Package Compare versions

Comparing version 0.1.9 to 0.2.0

dist/types-0a276ff1.d.ts

19

dist/index.d.ts

@@ -1,5 +0,4 @@

import { P as Preset, I as Import, B as BuiltinPresetName, T as TypeDeclrationOptions, S as ScanDirExportsOptions, U as UnimportOptions } from './types-3d1232fe.js';
export { B as BuiltinPresetName, I as Import, c as ImportCommon, a as ImportName, M as ModuleId, e as PathFromResolver, P as Preset, d as PresetImport, S as ScanDirExportsOptions, T as TypeDeclrationOptions, U as UnimportOptions, b as builtinPresets } from './types-3d1232fe.js';
import * as MagicString from 'magic-string';
import MagicString__default from 'magic-string';
import { P as Preset, I as Import, B as BuiltinPresetName, T as TypeDeclrationOptions, S as ScanDirExportsOptions, U as UnimportOptions, a as InjectImportsOptions } from './types-0a276ff1.js';
export { h as Addon, A as AddonsOptions, B as BuiltinPresetName, I as Import, d as ImportCommon, c as ImportName, a as InjectImportsOptions, M as ModuleId, g as PathFromResolver, P as Preset, e as PresetImport, S as ScanDirExportsOptions, T as TypeDeclrationOptions, f as UnimportContext, U as UnimportOptions, b as builtinPresets } from './types-0a276ff1.js';
import MagicString from 'magic-string';

@@ -20,4 +19,6 @@ declare function resolvePreset(preset: Preset): Import[];

declare function toTypeDeclrationFile(imports: Import[], options?: TypeDeclrationOptions): string;
declare function addImportToCode(code: string, imports: Import[], isCJS?: boolean, mergeExisting?: boolean): {
s: MagicString__default;
declare function getString(code: string | MagicString): string;
declare function getMagicString(code: string | MagicString): MagicString;
declare function addImportToCode(code: string | MagicString, imports: Import[], isCJS?: boolean, mergeExisting?: boolean): {
s: MagicString;
code: string;

@@ -41,4 +42,4 @@ };

}>;
injectImports: (code: string, mergeExisting?: boolean | undefined) => Promise<{
s: MagicString.default;
injectImports: (code: string | MagicString, id?: string | undefined, options?: InjectImportsOptions | undefined) => Promise<{
s: MagicString;
code: string;

@@ -50,2 +51,2 @@ }>;

export { Unimport, addImportToCode, createUnimport, dedupeImports, defineUnimportPreset, excludeRE, importAsRE, matchRE, normalizeImports, resolveBuiltinPresets, resolveFiles, resolvePreset, scanDirExports, scanExports, separatorRE, stripCommentsAndStrings, toExports, toImports, toTypeDeclrationFile, toTypeDeclrationItems };
export { Unimport, addImportToCode, createUnimport, dedupeImports, defineUnimportPreset, excludeRE, getMagicString, getString, importAsRE, matchRE, normalizeImports, resolveBuiltinPresets, resolveFiles, resolvePreset, scanDirExports, scanExports, separatorRE, stripCommentsAndStrings, toExports, toImports, toTypeDeclrationFile, toTypeDeclrationItems };
import * as unplugin from 'unplugin';
import { FilterPattern } from '@rollup/pluginutils';
import { U as UnimportOptions } from './types-3d1232fe.js';
import { U as UnimportOptions } from './types-0a276ff1.js';
import 'magic-string';

@@ -9,2 +10,3 @@ interface UnimportPluginOptions extends UnimportOptions {

dts: boolean | string;
dirs: string[];
}

@@ -11,0 +13,0 @@ declare const _default: unplugin.UnpluginInstance<Partial<UnimportPluginOptions>>;

{
"name": "unimport",
"version": "0.1.9",
"version": "0.2.0",
"description": "Unified utils for auto importing APIs in modules",

@@ -34,3 +34,5 @@ "repository": "unjs/unimport",

"prepack": "unbuild",
"typecheck": "tsc --noEmit",
"play": "pnpm -C playground run dev",
"play:build": "pnpm -C playground run build",
"typecheck": "vue-tsc --noEmit",
"release": "pnpm test && standard-version && git push --follow-tags && npm publish",

@@ -58,5 +60,6 @@ "test": "vitest run --coverage"

"unbuild": "latest",
"vitest": "latest"
"vitest": "latest",
"vue-tsc": "^0.34.11"
},
"packageManager": "pnpm@7.0.1"
}

@@ -10,2 +10,9 @@ # unimport

## Features
- Auto import registed APIs for Vite, Webpack or esbuild powered by [unplugin](https://github.com/unjs/unplugin)
- TypeScript declartion file generation
- Auto import for custom APIs defined under specific directories
- Auto import for Vue template
## Install

@@ -75,2 +82,60 @@

## Configurations
### Type Declarations
```ts
Unimport.vite({
dts: true // or a path to generateed file
})
```
### Directory Auto Import
```ts
Unimport.vite({
dirs: [
'./composables'
]
})
```
Exported APIs for modules under `./composables` will be auto imported.
### Vue Template Auto Import
In Vue's template, usage of APIs are in different context than plain modules. Thus some custom transformation are required. To enable it, set `addons.vueTemplate` to `true`:
```ts
Unimport.vite({
addons: {
vueTemplate: true
}
})
```
#### Caveats
When auto-import a ref, inline operations won't be auto unwrapped.
```ts
export const counter = ref(0)
```
```html
<template>
<!-- this is ok -->
<div>{{ counter }}</div>
<!-- counter here is a ref, this won't work, volar will throw -->
<div>{{ counter + 1 }}</div>
<!-- use this instead -->
<div>{{ counter.value + 1 }}</div>
</template>
```
We recommend using [Volar](https://github.com/johnsoncodehk/volar) for type checking, which will help you to identify the misusage.
## 💻 Development

@@ -77,0 +142,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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