@clerk/shared
Advanced tools
Comparing version 0.23.1-staging.3a527b2 to 0.23.1-staging.3b85311
@@ -28,4 +28,5 @@ "use strict"; | ||
const deprecated = (fnName, warning, key) => { | ||
const hideWarning = (0, import_runtimeEnvironment.isTestEnvironment)() || (0, import_runtimeEnvironment.isProductionEnvironment)(); | ||
const messageId = key ?? fnName; | ||
if (displayedWarnings.has(messageId) || !(0, import_runtimeEnvironment.isDevelopmentEnvironment)()) { | ||
if (displayedWarnings.has(messageId) || hideWarning) { | ||
return; | ||
@@ -32,0 +33,0 @@ } |
@@ -5,3 +5,6 @@ "use strict"; | ||
jest.mock("./runtimeEnvironment", () => { | ||
return { isDevelopmentEnvironment: jest.fn(() => true) }; | ||
return { | ||
isTestEnvironment: jest.fn(() => false), | ||
isProductionEnvironment: jest.fn(() => false) | ||
}; | ||
}); | ||
@@ -112,8 +115,8 @@ describe("deprecated(fnName, warning)", () => { | ||
}); | ||
describe("for non development environment", () => { | ||
describe("for test environment", () => { | ||
beforeEach(() => { | ||
import_runtimeEnvironment.isDevelopmentEnvironment.mockReturnValue(false); | ||
import_runtimeEnvironment.isTestEnvironment.mockReturnValue(true); | ||
}); | ||
afterEach(() => { | ||
import_runtimeEnvironment.isDevelopmentEnvironment.mockReturnValue(true); | ||
import_runtimeEnvironment.isTestEnvironment.mockReturnValue(false); | ||
}); | ||
@@ -131,2 +134,20 @@ test("deprecate function does not show warning", () => { | ||
}); | ||
describe("for production environment", () => { | ||
beforeEach(() => { | ||
import_runtimeEnvironment.isProductionEnvironment.mockReturnValue(true); | ||
}); | ||
afterEach(() => { | ||
import_runtimeEnvironment.isProductionEnvironment.mockReturnValue(false); | ||
}); | ||
test("deprecate function does not show warning", () => { | ||
const getSomeFunctionInProd = () => { | ||
(0, import_deprecated.deprecated)("getSomeFunctionInProd", "Use `getSomeFunctionInProdElse` instead."); | ||
return "getSomeFunctionInProdValue"; | ||
}; | ||
expect(consoleWarnSpy).not.toBeCalled(); | ||
expect(getSomeFunctionInProd()).toEqual("getSomeFunctionInProdValue"); | ||
expect(getSomeFunctionInProd()).toEqual("getSomeFunctionInProdValue"); | ||
expect(consoleWarnSpy).toBeCalledTimes(0); | ||
}); | ||
}); | ||
}); | ||
@@ -189,8 +210,8 @@ describe("deprecatedProperty(cls, propName, warning, isStatic = false)", () => { | ||
}); | ||
describe("for non development environment", () => { | ||
describe("for test environment", () => { | ||
beforeEach(() => { | ||
import_runtimeEnvironment.isDevelopmentEnvironment.mockReturnValue(false); | ||
import_runtimeEnvironment.isTestEnvironment.mockReturnValue(true); | ||
}); | ||
afterEach(() => { | ||
import_runtimeEnvironment.isDevelopmentEnvironment.mockReturnValue(true); | ||
import_runtimeEnvironment.isTestEnvironment.mockReturnValue(false); | ||
}); | ||
@@ -211,3 +232,24 @@ test("deprecate class readonly property does not show warning", () => { | ||
}); | ||
describe("for production environment", () => { | ||
beforeEach(() => { | ||
import_runtimeEnvironment.isProductionEnvironment.mockReturnValue(true); | ||
}); | ||
afterEach(() => { | ||
import_runtimeEnvironment.isProductionEnvironment.mockReturnValue(false); | ||
}); | ||
test("deprecate class readonly property does not show warning", () => { | ||
class Example { | ||
constructor(someReadOnlyPropInProd) { | ||
this.someReadOnlyPropInProd = someReadOnlyPropInProd; | ||
} | ||
} | ||
(0, import_deprecated.deprecatedProperty)(Example, "someReadOnlyPropInProd", "Use `someReadOnlyPropInProdElse` instead."); | ||
const example = new Example("someReadOnlyPropInProd-value"); | ||
expect(consoleWarnSpy).not.toBeCalled(); | ||
expect(example.someReadOnlyPropInProd).toEqual("someReadOnlyPropInProd-value"); | ||
expect(example.someReadOnlyPropInProd).toEqual("someReadOnlyPropInProd-value"); | ||
expect(consoleWarnSpy).toBeCalledTimes(0); | ||
}); | ||
}); | ||
}); | ||
//# sourceMappingURL=deprecated.test.js.map |
@@ -23,4 +23,3 @@ "use strict"; | ||
deprecated: () => import_deprecated.deprecated, | ||
deprecatedProperty: () => import_deprecated.deprecatedProperty, | ||
isDevelopmentEnvironment: () => import_runtimeEnvironment.isDevelopmentEnvironment | ||
deprecatedProperty: () => import_deprecated.deprecatedProperty | ||
}); | ||
@@ -52,3 +51,3 @@ module.exports = __toCommonJS(utils_exports); | ||
__reExport(utils_exports, require("./loadScript"), module.exports); | ||
var import_runtimeEnvironment = require("./runtimeEnvironment"); | ||
__reExport(utils_exports, require("./runtimeEnvironment"), module.exports); | ||
var import_deprecated = require("./deprecated"); | ||
@@ -59,3 +58,2 @@ // Annotate the CommonJS export names for ESM import in node: | ||
deprecatedProperty, | ||
isDevelopmentEnvironment, | ||
...require("./array"), | ||
@@ -84,4 +82,5 @@ ...require("./browser"), | ||
...require("./globs"), | ||
...require("./loadScript") | ||
...require("./loadScript"), | ||
...require("./runtimeEnvironment") | ||
}); | ||
//# sourceMappingURL=index.js.map |
@@ -21,6 +21,7 @@ "use strict"; | ||
__export(runtimeEnvironment_exports, { | ||
isDevelopmentEnvironment: () => isDevelopmentEnvironment | ||
isDevelopmentEnvironment: () => isDevelopmentEnvironment, | ||
isProductionEnvironment: () => isProductionEnvironment, | ||
isTestEnvironment: () => isTestEnvironment | ||
}); | ||
module.exports = __toCommonJS(runtimeEnvironment_exports); | ||
const import_meta = {}; | ||
const isDevelopmentEnvironment = () => { | ||
@@ -31,4 +32,7 @@ try { | ||
} | ||
return false; | ||
}; | ||
const isTestEnvironment = () => { | ||
try { | ||
return import_meta.env.DEV || import_meta.env.MODE === "development"; | ||
return process.env.NODE_ENV === "test"; | ||
} catch (err) { | ||
@@ -38,6 +42,15 @@ } | ||
}; | ||
const isProductionEnvironment = () => { | ||
try { | ||
return process.env.NODE_ENV === "production"; | ||
} catch (err) { | ||
} | ||
return false; | ||
}; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
isDevelopmentEnvironment | ||
isDevelopmentEnvironment, | ||
isProductionEnvironment, | ||
isTestEnvironment | ||
}); | ||
//# sourceMappingURL=runtimeEnvironment.js.map |
@@ -1,6 +0,7 @@ | ||
import { isDevelopmentEnvironment } from "./runtimeEnvironment"; | ||
import { isProductionEnvironment, isTestEnvironment } from "./runtimeEnvironment"; | ||
const displayedWarnings = /* @__PURE__ */ new Set(); | ||
const deprecated = (fnName, warning, key) => { | ||
const hideWarning = isTestEnvironment() || isProductionEnvironment(); | ||
const messageId = key ?? fnName; | ||
if (displayedWarnings.has(messageId) || !isDevelopmentEnvironment()) { | ||
if (displayedWarnings.has(messageId) || hideWarning) { | ||
return; | ||
@@ -7,0 +8,0 @@ } |
jest.mock("./runtimeEnvironment", () => { | ||
return { isDevelopmentEnvironment: jest.fn(() => true) }; | ||
return { | ||
isTestEnvironment: jest.fn(() => false), | ||
isProductionEnvironment: jest.fn(() => false) | ||
}; | ||
}); | ||
import { deprecated, deprecatedProperty } from "./deprecated"; | ||
import { isDevelopmentEnvironment } from "./runtimeEnvironment"; | ||
import { isProductionEnvironment, isTestEnvironment } from "./runtimeEnvironment"; | ||
describe("deprecated(fnName, warning)", () => { | ||
@@ -110,8 +113,8 @@ let consoleWarnSpy; | ||
}); | ||
describe("for non development environment", () => { | ||
describe("for test environment", () => { | ||
beforeEach(() => { | ||
isDevelopmentEnvironment.mockReturnValue(false); | ||
isTestEnvironment.mockReturnValue(true); | ||
}); | ||
afterEach(() => { | ||
isDevelopmentEnvironment.mockReturnValue(true); | ||
isTestEnvironment.mockReturnValue(false); | ||
}); | ||
@@ -129,2 +132,20 @@ test("deprecate function does not show warning", () => { | ||
}); | ||
describe("for production environment", () => { | ||
beforeEach(() => { | ||
isProductionEnvironment.mockReturnValue(true); | ||
}); | ||
afterEach(() => { | ||
isProductionEnvironment.mockReturnValue(false); | ||
}); | ||
test("deprecate function does not show warning", () => { | ||
const getSomeFunctionInProd = () => { | ||
deprecated("getSomeFunctionInProd", "Use `getSomeFunctionInProdElse` instead."); | ||
return "getSomeFunctionInProdValue"; | ||
}; | ||
expect(consoleWarnSpy).not.toBeCalled(); | ||
expect(getSomeFunctionInProd()).toEqual("getSomeFunctionInProdValue"); | ||
expect(getSomeFunctionInProd()).toEqual("getSomeFunctionInProdValue"); | ||
expect(consoleWarnSpy).toBeCalledTimes(0); | ||
}); | ||
}); | ||
}); | ||
@@ -187,8 +208,8 @@ describe("deprecatedProperty(cls, propName, warning, isStatic = false)", () => { | ||
}); | ||
describe("for non development environment", () => { | ||
describe("for test environment", () => { | ||
beforeEach(() => { | ||
isDevelopmentEnvironment.mockReturnValue(false); | ||
isTestEnvironment.mockReturnValue(true); | ||
}); | ||
afterEach(() => { | ||
isDevelopmentEnvironment.mockReturnValue(true); | ||
isTestEnvironment.mockReturnValue(false); | ||
}); | ||
@@ -209,3 +230,24 @@ test("deprecate class readonly property does not show warning", () => { | ||
}); | ||
describe("for production environment", () => { | ||
beforeEach(() => { | ||
isProductionEnvironment.mockReturnValue(true); | ||
}); | ||
afterEach(() => { | ||
isProductionEnvironment.mockReturnValue(false); | ||
}); | ||
test("deprecate class readonly property does not show warning", () => { | ||
class Example { | ||
constructor(someReadOnlyPropInProd) { | ||
this.someReadOnlyPropInProd = someReadOnlyPropInProd; | ||
} | ||
} | ||
deprecatedProperty(Example, "someReadOnlyPropInProd", "Use `someReadOnlyPropInProdElse` instead."); | ||
const example = new Example("someReadOnlyPropInProd-value"); | ||
expect(consoleWarnSpy).not.toBeCalled(); | ||
expect(example.someReadOnlyPropInProd).toEqual("someReadOnlyPropInProd-value"); | ||
expect(example.someReadOnlyPropInProd).toEqual("someReadOnlyPropInProd-value"); | ||
expect(consoleWarnSpy).toBeCalledTimes(0); | ||
}); | ||
}); | ||
}); | ||
//# sourceMappingURL=deprecated.test.js.map |
@@ -25,9 +25,8 @@ export * from "./array"; | ||
export * from "./loadScript"; | ||
import { isDevelopmentEnvironment } from "./runtimeEnvironment"; | ||
export * from "./runtimeEnvironment"; | ||
import { deprecated, deprecatedProperty } from "./deprecated"; | ||
export { | ||
deprecated, | ||
deprecatedProperty, | ||
isDevelopmentEnvironment | ||
deprecatedProperty | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -6,4 +6,7 @@ const isDevelopmentEnvironment = () => { | ||
} | ||
return false; | ||
}; | ||
const isTestEnvironment = () => { | ||
try { | ||
return import.meta.env.DEV || import.meta.env.MODE === "development"; | ||
return process.env.NODE_ENV === "test"; | ||
} catch (err) { | ||
@@ -13,5 +16,14 @@ } | ||
}; | ||
const isProductionEnvironment = () => { | ||
try { | ||
return process.env.NODE_ENV === "production"; | ||
} catch (err) { | ||
} | ||
return false; | ||
}; | ||
export { | ||
isDevelopmentEnvironment | ||
isDevelopmentEnvironment, | ||
isProductionEnvironment, | ||
isTestEnvironment | ||
}; | ||
//# sourceMappingURL=runtimeEnvironment.js.map |
@@ -25,4 +25,4 @@ export * from './array'; | ||
export * from './loadScript'; | ||
export { isDevelopmentEnvironment } from './runtimeEnvironment'; | ||
export * from './runtimeEnvironment'; | ||
export { deprecated, deprecatedProperty } from './deprecated'; | ||
//# sourceMappingURL=index.d.ts.map |
export declare const isDevelopmentEnvironment: () => boolean; | ||
export declare const isTestEnvironment: () => boolean; | ||
export declare const isProductionEnvironment: () => boolean; | ||
//# sourceMappingURL=runtimeEnvironment.d.ts.map |
{ | ||
"name": "@clerk/shared", | ||
"version": "0.23.1-staging.3a527b2", | ||
"version": "0.23.1-staging.3b85311", | ||
"description": "Internal package utils used by the Clerk SDKs", | ||
@@ -38,3 +38,3 @@ "types": "./dist/types/index.d.ts", | ||
"devDependencies": { | ||
"@clerk/types": "3.52.1-staging.3a527b2", | ||
"@clerk/types": "3.52.1-staging.3b85311", | ||
"@types/glob-to-regexp": "0.4.1", | ||
@@ -41,0 +41,0 @@ "@types/js-cookie": "3.0.2", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
640826
7161