@backstage/version-bridge 0.1.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ # @backstage/version-bridge
2
+
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - b58c70c223: This package has been promoted to v1.0! To understand how this change affects the package, please check out our [versioning policy](https://backstage.io/docs/overview/versioning-policy).
8
+
9
+ ### Patch Changes
10
+
11
+ - a422d7ce5e: chore(deps): bump `@testing-library/react` from 11.2.6 to 12.1.3
12
+
13
+ ## 0.1.2
14
+
15
+ ### Patch Changes
16
+
17
+ - c77c5c7eb6: Added `backstage.role` to `package.json`
18
+
19
+ ## 0.1.1
20
+
21
+ ### Patch Changes
22
+
23
+ - cd450844f6: Moved React dependencies to `peerDependencies` and allow both React v16 and v17 to be used.
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/lib/globalObject.ts","../src/lib/VersionedValue.ts","../src/lib/VersionedContext.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028\nfunction getGlobalObject() {\n if (typeof window !== 'undefined' && window.Math === Math) {\n return window;\n }\n if (typeof self !== 'undefined' && self.Math === Math) {\n return self;\n }\n // eslint-disable-next-line no-new-func\n return Function('return this')();\n}\n\nconst globalObject = getGlobalObject();\n\nconst makeKey = (id: string) => `__@backstage/${id}__`;\n\n/**\n * Serializes access to a global singleton value, with the first caller creating the value.\n *\n * @public\n */\nexport function getOrCreateGlobalSingleton<T>(\n id: string,\n supplier: () => T,\n): T {\n const key = makeKey(id);\n\n let value = globalObject[key];\n if (value) {\n return value;\n }\n\n value = supplier();\n globalObject[key] = value;\n return value;\n}\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * The versioned value interface is a container for a set of values that\n * can be looked up by version. It is intended to be used as a container\n * for values that can be versioned independently of package versions.\n *\n * @public\n */\nexport type VersionedValue<Versions extends { [version: number]: unknown }> = {\n atVersion<Version extends keyof Versions>(\n version: Version,\n ): Versions[Version] | undefined;\n};\n\n/**\n * Creates a container for a map of versioned values that implements VersionedValue.\n *\n * @public\n */\nexport function createVersionedValueMap<\n Versions extends { [version: number]: unknown },\n>(versions: Versions): VersionedValue<Versions> {\n Object.freeze(versions);\n return {\n atVersion(version) {\n return versions[version];\n },\n };\n}\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createContext, useContext, Context } from 'react';\nimport { getOrCreateGlobalSingleton } from './globalObject';\nimport { createVersionedValueMap, VersionedValue } from './VersionedValue';\n\n/**\n * Get the existing or create a new versioned React context that's\n * stored inside a global singleton.\n *\n * @param key - A key that uniquely identifies the context.\n * @public\n * @example\n *\n * ```ts\n * const MyContext = createVersionedContext<{ 1: string }>('my-context');\n *\n * const MyContextProvider = ({children}) => (\n * <MyContext.Provider value={createVersionedValueMap({ 1: 'value-for-version-1' })}>\n * {children}\n * <MyContext.Provider>\n * )\n * ```\n */\nexport function createVersionedContext<\n Versions extends { [version in number]: unknown },\n>(key: string): Context<VersionedValue<Versions> | undefined> {\n return getOrCreateGlobalSingleton(key, () =>\n createContext<VersionedValue<Versions> | undefined>(undefined),\n );\n}\n\n/**\n * A hook that simplifies the consumption of a versioned contexts that's\n * stored inside a global singleton.\n *\n * @param key - A key that uniquely identifies the context.\n * @public\n * @example\n *\n * ```ts\n * const versionedHolder = useVersionedContext<{ 1: string }>('my-context');\n *\n * if (!versionedHolder) {\n * throw new Error('My context is not available!')\n * }\n *\n * const myValue = versionedHolder.atVersion(1);\n *\n * // ...\n * ```\n */\nexport function useVersionedContext<\n Versions extends { [version in number]: unknown },\n>(key: string): VersionedValue<Versions> | undefined {\n return useContext(createVersionedContext<Versions>(key));\n}\n\n/**\n * Creates a helper for writing tests towards multiple different\n * combinations of versions provided from a context.\n *\n * @param key - A key that uniquely identifies the context.\n * @public\n * @example\n *\n * ```ts\n * const context = createVersionedContextForTesting('my-context');\n *\n * afterEach(() => {\n * context.reset();\n * });\n *\n * it('should work when provided with version 1', () => {\n * context.set({1: 'value-for-version-1'})\n *\n * // ...\n * })\n * ```\n */\nexport function createVersionedContextForTesting(key: string) {\n return {\n set(versions: { [version in number]: unknown }) {\n (globalThis as any)[`__@backstage/${key}__`] = createContext(\n createVersionedValueMap(versions),\n );\n },\n reset() {\n delete (globalThis as any)[`__@backstage/${key}__`];\n },\n };\n}\n"],"names":[],"mappings":";;AAiBA,2BAA2B;AACzB,MAAI,OAAO,WAAW,eAAe,OAAO,SAAS,MAAM;AACzD,WAAO;AAAA;AAET,MAAI,OAAO,SAAS,eAAe,KAAK,SAAS,MAAM;AACrD,WAAO;AAAA;AAGT,SAAO,SAAS;AAAA;AAGlB,MAAM,eAAe;AAErB,MAAM,UAAU,CAAC,OAAe,gBAAgB;oCAQ9C,IACA,UACG;AACH,QAAM,MAAM,QAAQ;AAEpB,MAAI,QAAQ,aAAa;AACzB,MAAI,OAAO;AACT,WAAO;AAAA;AAGT,UAAQ;AACR,eAAa,OAAO;AACpB,SAAO;AAAA;;iCCdP,UAA8C;AAC9C,SAAO,OAAO;AACd,SAAO;AAAA,IACL,UAAU,SAAS;AACjB,aAAO,SAAS;AAAA;AAAA;AAAA;;gCCApB,KAA4D;AAC5D,SAAO,2BAA2B,KAAK,MACrC,cAAoD;AAAA;6BA0BtD,KAAmD;AACnD,SAAO,WAAW,uBAAiC;AAAA;0CAyBJ,KAAa;AAC5D,SAAO;AAAA,IACL,IAAI,UAA4C;AAC9C,MAAC,WAAmB,gBAAgB,WAAW,cAC7C,wBAAwB;AAAA;AAAA,IAG5B,QAAQ;AACN,aAAQ,WAAmB,gBAAgB;AAAA;AAAA;AAAA;;;;"}
1
+ {"version":3,"file":"index.esm.js","sources":["../src/lib/globalObject.ts","../src/lib/VersionedValue.ts","../src/lib/VersionedContext.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028\nfunction getGlobalObject() {\n if (typeof window !== 'undefined' && window.Math === Math) {\n return window;\n }\n if (typeof self !== 'undefined' && self.Math === Math) {\n return self;\n }\n // eslint-disable-next-line no-new-func\n return Function('return this')();\n}\n\nconst globalObject = getGlobalObject();\n\nconst makeKey = (id: string) => `__@backstage/${id}__`;\n\n/**\n * Serializes access to a global singleton value, with the first caller creating the value.\n *\n * @public\n */\nexport function getOrCreateGlobalSingleton<T>(\n id: string,\n supplier: () => T,\n): T {\n const key = makeKey(id);\n\n let value = globalObject[key];\n if (value) {\n return value;\n }\n\n value = supplier();\n globalObject[key] = value;\n return value;\n}\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * The versioned value interface is a container for a set of values that\n * can be looked up by version. It is intended to be used as a container\n * for values that can be versioned independently of package versions.\n *\n * @public\n */\nexport type VersionedValue<Versions extends { [version: number]: unknown }> = {\n atVersion<Version extends keyof Versions>(\n version: Version,\n ): Versions[Version] | undefined;\n};\n\n/**\n * Creates a container for a map of versioned values that implements VersionedValue.\n *\n * @public\n */\nexport function createVersionedValueMap<\n Versions extends { [version: number]: unknown },\n>(versions: Versions): VersionedValue<Versions> {\n Object.freeze(versions);\n return {\n atVersion(version) {\n return versions[version];\n },\n };\n}\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createContext, useContext, Context } from 'react';\nimport { getOrCreateGlobalSingleton } from './globalObject';\nimport { createVersionedValueMap, VersionedValue } from './VersionedValue';\n\n/**\n * Get the existing or create a new versioned React context that's\n * stored inside a global singleton.\n *\n * @param key - A key that uniquely identifies the context.\n * @public\n * @example\n *\n * ```ts\n * const MyContext = createVersionedContext<{ 1: string }>('my-context');\n *\n * const MyContextProvider = ({children}) => (\n * <MyContext.Provider value={createVersionedValueMap({ 1: 'value-for-version-1' })}>\n * {children}\n * <MyContext.Provider>\n * )\n * ```\n */\nexport function createVersionedContext<\n Versions extends { [version in number]: unknown },\n>(key: string): Context<VersionedValue<Versions> | undefined> {\n return getOrCreateGlobalSingleton(key, () =>\n createContext<VersionedValue<Versions> | undefined>(undefined),\n );\n}\n\n/**\n * A hook that simplifies the consumption of a versioned contexts that's\n * stored inside a global singleton.\n *\n * @param key - A key that uniquely identifies the context.\n * @public\n * @example\n *\n * ```ts\n * const versionedHolder = useVersionedContext<{ 1: string }>('my-context');\n *\n * if (!versionedHolder) {\n * throw new Error('My context is not available!')\n * }\n *\n * const myValue = versionedHolder.atVersion(1);\n *\n * // ...\n * ```\n */\nexport function useVersionedContext<\n Versions extends { [version in number]: unknown },\n>(key: string): VersionedValue<Versions> | undefined {\n return useContext(createVersionedContext<Versions>(key));\n}\n\n/**\n * Creates a helper for writing tests towards multiple different\n * combinations of versions provided from a context.\n *\n * @param key - A key that uniquely identifies the context.\n * @public\n * @example\n *\n * ```ts\n * const context = createVersionedContextForTesting('my-context');\n *\n * afterEach(() => {\n * context.reset();\n * });\n *\n * it('should work when provided with version 1', () => {\n * context.set({1: 'value-for-version-1'})\n *\n * // ...\n * })\n * ```\n */\nexport function createVersionedContextForTesting(key: string) {\n return {\n set(versions: { [version in number]: unknown }) {\n (globalThis as any)[`__@backstage/${key}__`] = createContext(\n createVersionedValueMap(versions),\n );\n },\n reset() {\n delete (globalThis as any)[`__@backstage/${key}__`];\n },\n };\n}\n"],"names":[],"mappings":";;AAiBA,SAA2B,eAAA,GAAA;AACzB,EAAA,IAAI,OAAO,MAAA,KAAW,WAAe,IAAA,MAAA,CAAO,SAAS,IA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AA,CAA0C,GAAa,EAAA;AAC5D,EAAO,OAAA;AAAA,IACL,IAAI,QAA4C,EAAA;AAC9C,MAAC,UAAmB,CAAA,CAAA,aAAA,EAAgB,GAAW,CAAA,EAAA,CAAA,CAAA,GAAA,aAAA,CAC7C,uBAAwB,CAAA,QAAA,CAAA,CAAA,CAAA;AAAA,KAAA;AAAA,IAG5B,KAAQ,GAAA;AACN,MAAA,OAAQ,WAAmB,CAAgB,aAAA,EAAA,GAAA,CAAA,EAAA,CAAA,CAAA,CAAA;AAAA,KAAA;AAAA,GAAA,CAAA;AAAA;;;;"}
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "@backstage/version-bridge",
3
3
  "description": "Utilities used by @backstage packages to support multiple concurrent versions",
4
- "version": "0.1.0",
4
+ "version": "1.0.0",
5
5
  "private": false,
6
6
  "publishConfig": {
7
7
  "access": "public",
8
8
  "main": "dist/index.esm.js",
9
9
  "types": "dist/index.d.ts"
10
10
  },
11
+ "backstage": {
12
+ "role": "web-library"
13
+ },
11
14
  "homepage": "https://backstage.io",
12
15
  "repository": {
13
16
  "type": "git",
@@ -21,25 +24,26 @@
21
24
  "main": "dist/index.esm.js",
22
25
  "types": "dist/index.d.ts",
23
26
  "scripts": {
24
- "build": "backstage-cli build --outputs types,esm",
25
- "lint": "backstage-cli lint",
26
- "test": "backstage-cli test",
27
- "prepack": "backstage-cli prepack",
28
- "postpack": "backstage-cli postpack",
29
- "clean": "backstage-cli clean"
27
+ "build": "backstage-cli package build",
28
+ "lint": "backstage-cli package lint",
29
+ "test": "backstage-cli package test",
30
+ "prepack": "backstage-cli package prepack",
31
+ "postpack": "backstage-cli package postpack",
32
+ "clean": "backstage-cli package clean",
33
+ "start": "backstage-cli package start"
30
34
  },
31
- "dependencies": {
32
- "@types/react": "*",
33
- "react": "^16.12.0"
35
+ "peerDependencies": {
36
+ "@types/react": "^16.13.1 || ^17.0.0",
37
+ "react": "^16.13.1 || ^17.0.0"
34
38
  },
35
39
  "devDependencies": {
36
- "@backstage/cli": "^0.7.11",
40
+ "@backstage/cli": "^0.16.0",
37
41
  "@testing-library/jest-dom": "^5.10.1",
38
- "@testing-library/react": "^11.2.5",
39
- "@testing-library/react-hooks": "^3.4.2"
42
+ "@testing-library/react": "^12.1.3",
43
+ "@testing-library/react-hooks": "^7.0.2"
40
44
  },
41
45
  "files": [
42
46
  "dist"
43
47
  ],
44
- "gitHead": "360039a4f3baed2cc3ff7bb271205619455c3c6d"
48
+ "gitHead": "e9496f746b31600dbfac7fa76987479e66426257"
45
49
  }