-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(dedupe): new package #26
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7894c4b
feat(nano-build): __package_version__ types
njfamirm 77fcdf6
feat(dedupe): new package
njfamirm d89d076
feat(logger): use alwatr dedupe
njfamirm de8a3f9
fix: __package_version__ global type
alimd dc02ac9
docs(dedupe): update desc abd enhance examples
alimd e2e5c6c
fix(logger): definePackage
alimd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <ali.mihandoost@gmail.com>", | ||
"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,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', '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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😢