Skip to content
Permalink
Browse files

fix: Scope local storage to package name and branch name (#54)

  • Loading branch information...
markdalgleish committed Mar 29, 2019
1 parent 49ea258 commit 0dc59d303631f232c6b7499330797a39723a5597
Showing with 86 additions and 12 deletions.
  1. +1 −0 .eslintignore
  2. +5 −2 cypress/support/index.js
  3. +5 −8 lib/index.js
  4. +20 −0 lib/provideDefaultConfig.js
  5. +2 −0 package.json
  6. +2 −2 src/index.js
  7. +51 −0 yarn.lock
@@ -1,3 +1,4 @@
cypress/plugins/
cypress/fixtures/
node_modules
dist
@@ -1,4 +1,7 @@
beforeEach(() => {
beforeEach(async () => {
cy.visit('http://localhost:9000');
indexedDB.deleteDatabase('playroom');

const win = await cy.window();
const { storageKey } = win.__playroomConfig__;
indexedDB.deleteDatabase(storageKey);
});
@@ -1,15 +1,12 @@
const start = require('./start');
const build = require('./build');
const provideDefaultConfig = require('./provideDefaultConfig');

const provideDefaults = config => ({
port: 9000,
openBrowser: true,
...config
});
module.exports = userConfig => {
const config = provideDefaultConfig(userConfig);

module.exports = config => {
return {
start: callback => start(provideDefaults(config), callback),
build: callback => build(provideDefaults(config), callback)
start: callback => start(config, callback),
build: callback => build(config, callback)
};
};
@@ -0,0 +1,20 @@
const readPackage = require('read-pkg-up');
const currentGitBranch = require('current-git-branch');

const generateStorageKey = () => {
const pkg = readPackage.sync();
const packageName = (pkg && pkg.pkg && pkg.pkg.name) || null;
const branchName = currentGitBranch();

const packageLabel = packageName ? `package:${packageName}` : null;
const branchLabel = branchName ? `branch:${branchName}` : null;

return ['playroom', packageLabel, branchLabel].filter(Boolean).join('__');
};

module.exports = ({ storageKey, ...restConfig }) => ({
port: 9000,
openBrowser: true,
storageKey: storageKey || generateStorageKey(),
...restConfig
});
@@ -66,6 +66,7 @@
"command-line-args": "^5.0.2",
"command-line-usage": "^5.0.5",
"css-loader": "^1.0.0",
"current-git-branch": "^1.1.0",
"dedent": "^0.7.0",
"fast-glob": "^2.2.4",
"find-up": "^3.0.0",
@@ -87,6 +88,7 @@
"react-docgen-typescript": "^1.12.2",
"react-dom": "^16.5.2",
"react-frame-component": "^4.0.1",
"read-pkg-up": "^5.0.0",
"scope-eval": "^1.0.0",
"style-loader": "^0.23.0",
"url-join": "^4.0.0",
@@ -6,7 +6,7 @@ import base64url from 'base64-url';
import dedent from 'dedent';
import Playroom from './Playroom/Playroom';

const playroomConfig = __PLAYROOM_GLOBAL__CONFIG__;
const playroomConfig = (window.__playroomConfig__ = __PLAYROOM_GLOBAL__CONFIG__);
const staticTypes = __PLAYROOM_GLOBAL__STATIC_TYPES__;

const widths = playroomConfig.widths || [320, 375, 768, 1024];
@@ -15,7 +15,7 @@ const outlet = document.createElement('div');
document.body.appendChild(outlet);

export const store = localforage.createInstance({
name: 'playroom',
name: playroomConfig.storageKey,
version: 1
});

@@ -1612,6 +1612,11 @@ babel-messages@^6.23.0:
dependencies:
babel-runtime "^6.22.0"

babel-plugin-add-module-exports@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/babel-plugin-add-module-exports/-/babel-plugin-add-module-exports-0.2.1.tgz#9ae9a1f4a8dc67f0cdec4f4aeda1e43a5ff65e25"
integrity sha1-mumh9KjcZ/DN7E9K7aHkOl/2XiU=

babel-plugin-istanbul@^4.1.6:
version "4.1.6"
resolved "https://registry.yarnpkg.com/babel-plugin-istanbul/-/babel-plugin-istanbul-4.1.6.tgz#36c59b2192efce81c5b378321b74175add1c9a45"
@@ -2850,6 +2855,15 @@ cssstyle@^1.0.0:
dependencies:
cssom "0.3.x"

current-git-branch@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/current-git-branch/-/current-git-branch-1.1.0.tgz#3730e71ee024ed27dab16d740e5b1ea4774fa49f"
integrity sha512-n5mwGZllLsFzxDPtTmadqGe4IIBPfqPbiIRX4xgFR9VK/Bx47U+94KiVkxSKAKN6/s43TlkztS2GZpgMKzwQ8A==
dependencies:
babel-plugin-add-module-exports "^0.2.1"
execa "^0.6.1"
is-git-repository "^1.0.0"

currently-unhandled@^0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/currently-unhandled/-/currently-unhandled-0.4.1.tgz#988df33feab191ef799a61369dd76c17adf957ea"
@@ -3726,6 +3740,19 @@ execa@0.11.0:
signal-exit "^3.0.0"
strip-eof "^1.0.0"

execa@^0.6.1:
version "0.6.3"
resolved "https://registry.yarnpkg.com/execa/-/execa-0.6.3.tgz#57b69a594f081759c69e5370f0d17b9cb11658fe"
integrity sha1-V7aaWU8IF1nGnlNw8NF7nLEWWP4=
dependencies:
cross-spawn "^5.0.1"
get-stream "^3.0.0"
is-stream "^1.1.0"
npm-run-path "^2.0.0"
p-finally "^1.0.0"
signal-exit "^3.0.0"
strip-eof "^1.0.0"

execa@^0.7.0:
version "0.7.0"
resolved "https://registry.yarnpkg.com/execa/-/execa-0.7.0.tgz#944becd34cc41ee32a63a9faf27ad5a65fc59777"
@@ -5182,6 +5209,14 @@ is-generator-fn@^1.0.0:
resolved "https://registry.yarnpkg.com/is-generator-fn/-/is-generator-fn-1.0.0.tgz#969d49e1bb3329f6bb7f09089be26578b2ddd46a"
integrity sha1-lp1J4bszKfa7fwkIm+JleLLd1Go=

is-git-repository@^1.0.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/is-git-repository/-/is-git-repository-1.1.1.tgz#c68e4b7a806422349aaec488973a90558d7e9be0"
integrity sha1-xo5LeoBkIjSarsSIlzqQVY1+m+A=
dependencies:
execa "^0.6.1"
path-is-absolute "^1.0.1"

is-glob@^2.0.0, is-glob@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-2.0.1.tgz#d096f926a3ded5600f3fdfd91198cb0888c2d863"
@@ -8272,6 +8307,14 @@ read-pkg-up@^4.0.0:
find-up "^3.0.0"
read-pkg "^3.0.0"

read-pkg-up@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-5.0.0.tgz#b6a6741cb144ed3610554f40162aa07a6db621b8"
integrity sha512-XBQjqOBtTzyol2CpsQOw8LHV0XbDZVG7xMMjmXAJomlVY03WOBRmYgDJETlvcg0H63AJvPRwT7GFi5rvOzUOKg==
dependencies:
find-up "^3.0.0"
read-pkg "^5.0.0"

read-pkg@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-1.1.0.tgz#f5ffaa5ecd29cb31c0474bca7d756b6bb29e3f28"
@@ -8305,6 +8348,14 @@ read-pkg@^4.0.0, read-pkg@^4.0.1:
parse-json "^4.0.0"
pify "^3.0.0"

read-pkg@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-5.0.0.tgz#75449907ece8dfb89cbc76adcba2665316e32b94"
integrity sha512-OWufaRc67oJjcgrxckW/qO9q22iYzyiONh8h+GMcnOvSHAmhV1Dr3x+gyRjP+Qxc5jKupkSfoCQLS/98rDPh9A==
dependencies:
normalize-package-data "^2.3.2"
parse-json "^4.0.0"

read@1, read@~1.0.1, read@~1.0.7:
version "1.0.7"
resolved "https://registry.yarnpkg.com/read/-/read-1.0.7.tgz#b3da19bd052431a97671d44a42634adf710b40c4"

0 comments on commit 0dc59d3

Please sign in to comment.
You can’t perform that action at this time.