-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
187 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Dedupe | ||
|
||
A package manager helper tool for debug list of defined (imported) packages in your ecosystem and prevent to duplicate import (install) multiple versions of the same package in your project (deduplicate packages). | ||
|
||
## Example usage | ||
|
||
```ts | ||
import {definePackage} from '@alwatr/dedupe'; | ||
|
||
definePackage('@alwatr/logger', '2.0.0'); | ||
``` | ||
|
||
You can use __package_version__ to automatically obtain the version of the package if you are using @alwatr/nano-build to build your package. | ||
|
||
```ts | ||
definePackage('@alwatr/logger', __package_version__); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {definePackage, definedPackageList} from '@alwatr/dedupe'; | ||
|
||
// Must throw an error | ||
|
||
console.log('define test1 package') | ||
definePackage('@scope/test1'); | ||
|
||
console.log('define test2 package') | ||
definePackage('@scope/test2', 'v1.0.0'); | ||
|
||
console.log('definedPackageList:', definedPackageList) | ||
|
||
console.log('redefine test2 package') | ||
definePackage('@scope/test2'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
{ | ||
"name": "@alwatr/dedupe", | ||
"version": "2.4.1", | ||
"description": "A package manager helper tool for debug list of defined (imported) packages in your ecosystem and prevent to duplicate import (install) multiple versions of the same package in your project (deduplicate packages).", | ||
"author": "S. Ali Mihandoost <ali.mihandoost@gmail.com>", | ||
"keywords": [ | ||
"dedupe", | ||
"define-package", | ||
"deduplicate", | ||
"package", | ||
"package-manager", | ||
"cross-platform", | ||
"ECMAScript", | ||
"typescript", | ||
"javascript", | ||
"node", | ||
"nodejs", | ||
"esm", | ||
"module", | ||
"utility", | ||
"util", | ||
"utils", | ||
"nanolib", | ||
"alwatr" | ||
], | ||
"type": "module", | ||
"main": "./dist/main.cjs", | ||
"module": "./dist/main.mjs", | ||
"types": "./dist/main.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "./dist/main.mjs", | ||
"require": "./dist/main.cjs", | ||
"types": "./dist/main.d.ts" | ||
} | ||
}, | ||
"license": "MIT", | ||
"files": [ | ||
"**/*.{js,mjs,cjs,map,d.ts,html,md}", | ||
"!demo/**/*" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Alwatr/nanolib", | ||
"directory": "packages/dedupe" | ||
}, | ||
"homepage": "https://github.com/Alwatr/nanolib/tree/next/packages/dedupe#readme", | ||
"bugs": { | ||
"url": "https://github.com/Alwatr/nanolib/issues" | ||
}, | ||
"prettier": "@alwatr/prettier-config", | ||
"scripts": { | ||
"b": "yarn run build", | ||
"w": "yarn run watch", | ||
"c": "yarn run clean", | ||
"cb": "yarn run clean && yarn run build", | ||
"d": "yarn run build:es && DEBUG=1 yarn node", | ||
"build": "yarn run build:ts & yarn run build:es", | ||
"build:es": "nano-build --preset=module", | ||
"build:ts": "tsc --build", | ||
"watch": "yarn run watch:ts & yarn run watch:es", | ||
"watch:es": "yarn run build:es --watch", | ||
"watch:ts": "yarn run build:ts --watch --preserveWatchOutput", | ||
"clean": "rm -rfv dist *.tsbuildinfo" | ||
}, | ||
"devDependencies": { | ||
"@alwatr/nano-build": "workspace:^", | ||
"@alwatr/prettier-config": "workspace:^", | ||
"@alwatr/tsconfig-base": "workspace:^", | ||
"@alwatr/type-helper": "workspace:^", | ||
"@types/node": "^20.10.6", | ||
"typescript": "^5.3.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type {Dictionary} from '@alwatr/type-helper' | ||
|
||
declare global { | ||
// eslint-disable-next-line no-var | ||
var __dedupe__: true; | ||
|
||
// eslint-disable-next-line no-var | ||
var __package_version__: string; | ||
} | ||
|
||
if (typeof __dedupe__ !== 'undefined') { | ||
throw new Error('duplicate_dedupe'); | ||
} | ||
|
||
export const definedPackageList: Dictionary<string> = {}; | ||
|
||
/** | ||
* Global define package for managing package versions to prevent version conflicts. | ||
* @param packageName package name including scope. e.g. `@scope/package-name` | ||
* @param version package version (optional) | ||
* | ||
* @example | ||
* ```typescript | ||
* definePackage('@scope/package-name', __package_version__); | ||
* ``` | ||
*/ | ||
export function definePackage (packageName: string, version = 'v?'): void { | ||
if (packageName in definedPackageList) { | ||
throw new Error('duplicate_package', { | ||
cause: packageName, | ||
}); | ||
} | ||
|
||
definedPackageList[packageName] = version; | ||
} | ||
|
||
definePackage('@alwatr/dedupe', __package_version__); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "@alwatr/tsconfig-base/tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "dist", | ||
"emitDeclarationOnly": true, | ||
"composite": true, | ||
}, | ||
"include": ["src/**/*.ts"], | ||
"references": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export {}; | ||
|
||
declare global { | ||
var __package_version__: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters