Skip to content

Commit

Permalink
feat(dedupe): new package
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm authored and alimd committed Jan 3, 2024
1 parent 7894c4b commit 77fcdf6
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/dedupe/README.md
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');
```
14 changes: 14 additions & 0 deletions packages/dedupe/demo/dedupe.mjs
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');
76 changes: 76 additions & 0 deletions packages/dedupe/package.json
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"
}
}
36 changes: 36 additions & 0 deletions packages/dedupe/src/main.ts
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__);
11 changes: 11 additions & 0 deletions packages/dedupe/tsconfig.json
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": []
}
14 changes: 14 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ __metadata:
languageName: unknown
linkType: soft

"@alwatr/dedupe@workspace:^, @alwatr/dedupe@workspace:packages/dedupe":
version: 0.0.0-use.local
resolution: "@alwatr/dedupe@workspace:packages/dedupe"
dependencies:
"@alwatr/nano-build": "workspace:^"
"@alwatr/prettier-config": "workspace:^"
"@alwatr/tsconfig-base": "workspace:^"
"@alwatr/type-helper": "workspace:^"
"@types/node": "npm:^20.10.6"
typescript: "npm:^5.3.3"
languageName: unknown
linkType: soft

"@alwatr/deep-clone@workspace:packages/deep-clone":
version: 0.0.0-use.local
resolution: "@alwatr/deep-clone@workspace:packages/deep-clone"
Expand Down Expand Up @@ -110,6 +123,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@alwatr/logger@workspace:packages/logger"
dependencies:
"@alwatr/dedupe": "workspace:^"
"@alwatr/nano-build": "workspace:^"
"@alwatr/platform-info": "workspace:^"
"@alwatr/prettier-config": "workspace:^"
Expand Down

0 comments on commit 77fcdf6

Please sign in to comment.