Skip to content

Commit

Permalink
refactor(global-scope): Improve shared scope definition
Browse files Browse the repository at this point in the history
Improve the shared scope definition in the global-scope module. Instead of using a boolean value, now it accepts a string or boolean value. If the value is true, it is updated to '1.1.x'. Additionally, an error is thrown if duplication is detected, providing information about the package name, old version, and new version.

Closes #123
  • Loading branch information
alimd committed Sep 29, 2024
1 parent 1ebbe92 commit 4704a02
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/global-scope/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,20 @@ export const sharedScope_: Record<string, unknown> = {};

declare global {
// eslint-disable-next-line no-var
var __shared_scope_defined__: boolean;
var __shared_scope_defined__: string | boolean;
}

if (globalScope.__shared_scope_defined__ !== undefined) {
if (globalScope.__shared_scope_defined__ === true) {
globalScope.__shared_scope_defined__ = '1.1.x';
}
console.error(new Error('duplication_detected', {
cause: {
name: __package_name__,
oldVersion: globalScope.__shared_scope_defined__,
newVersion: __package_version__
},
}));
throw new Error('global_scope_module_duplicated');
}
globalScope.__shared_scope_defined__ = true;
globalScope.__shared_scope_defined__ = __package_version__;

0 comments on commit 4704a02

Please sign in to comment.