-
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
6 changed files
with
162 additions
and
0 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,11 @@ | ||
# Dedupe | ||
|
||
A global package manager for defining and managing package versions across different parts of applications to prevent version conflicts. | ||
|
||
## Example usage | ||
|
||
```ts | ||
import {definePackage} from '@alwatr/dedupe'; | ||
|
||
definePackage('@alwatr/logger', '2.0.0'); | ||
``` |
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,76 @@ | ||
{ | ||
"name": "@alwatr/dedupe", | ||
"version": "2.4.1", | ||
"description": "A global package manager for defining and managing package versions across different parts of applications to prevent version conflicts.", | ||
"author": "S. Ali Mihandoost <[email protected]>", | ||
"keywords": [ | ||
"dedupe", | ||
"define-package", | ||
"deduplicate", | ||
"package", | ||
"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,36 @@ | ||
/// <reference types="@alwatr/nano-build/global.d.ts" /> | ||
|
||
import type {Dictionary} from '@alwatr/type-helper' | ||
|
||
declare global { | ||
// eslint-disable-next-line no-var | ||
var __dedupe__: true; | ||
} | ||
|
||
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', '2.0.1'); | ||
* ``` | ||
*/ | ||
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