Skip to content

Commit 2b92d40

Browse files
committed
Merge remote-tracking branch 'origin/master' into ss-fork-testing
2 parents 3e2b499 + 41ed6f2 commit 2b92d40

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1783
-580
lines changed

.changeset/quick-drinks-cheat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/firestore": patch
3+
---
4+
5+
The SDK no longer crashes with the error "The database connection is closing". Instead, the individual operations that cause this error may be rejected.

.changeset/spicy-masks-sort.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@firebase/firebase": patch
3+
"@firebase/analytics": patch
4+
---
5+
6+
Added Browser Extension check for Firebase Analytics. analytics.isSupported() will now return Promise<false> for extension environments.

.github/workflows/test-changed.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ jobs:
88
runs-on: ubuntu-latest
99

1010
steps:
11-
- uses: actions/checkout@v2
12-
- name: Checkout
13-
run: |
14-
git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
11+
- name: Checkout Repo
12+
uses: actions/checkout@master
13+
with:
14+
# This makes Actions fetch all Git history so run-changed script can diff properly.
15+
fetch-depth: 0
1516
- name: Set up Node (10)
1617
uses: actions/setup-node@v1
1718
with:

config/webpack.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,10 @@ module.exports = {
8686
new webpack.NormalModuleReplacementPlugin(
8787
FIRESTORE_PLATFORM_RE,
8888
resource => {
89+
const targetPlatform = process.env.TEST_PLATFORM || 'browser';
8990
resource.request = resource.request.replace(
9091
FIRESTORE_PLATFORM_RE,
91-
'$1/platform/browser/$2.ts'
92+
`$1/platform/${targetPlatform}/$2.ts`
9293
);
9394
}
9495
),

packages/analytics/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ import { ERROR_FACTORY, AnalyticsError } from './src/errors';
3535
import {
3636
isIndexedDBAvailable,
3737
validateIndexedDBOpenable,
38-
areCookiesEnabled
38+
areCookiesEnabled,
39+
isBrowserExtension
3940
} from '@firebase/util';
4041
import { name, version } from './package.json';
4142

@@ -109,19 +110,25 @@ declare module '@firebase/app-types' {
109110
}
110111

111112
/**
112-
* this is a public static method provided to users that wraps three different checks:
113+
* this is a public static method provided to users that wraps four different checks:
113114
*
115+
* 1. check if it's not a browser extension environment.
114116
* 1. check if cookie is enabled in current browser.
115-
* 2. check if IndexedDB is supported by the browser environment.
116-
* 3. check if the current browser context is valid for using IndexedDB.
117+
* 3. check if IndexedDB is supported by the browser environment.
118+
* 4. check if the current browser context is valid for using IndexedDB.
119+
*
117120
*/
118121
async function isSupported(): Promise<boolean> {
122+
if (isBrowserExtension()) {
123+
return false;
124+
}
119125
if (!areCookiesEnabled()) {
120126
return false;
121127
}
122128
if (!isIndexedDBAvailable()) {
123129
return false;
124130
}
131+
125132
try {
126133
const isDBOpenable: boolean = await validateIndexedDBOpenable();
127134
return isDBOpenable;

packages/analytics/src/errors.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export const enum AnalyticsError {
2525
INTEROP_COMPONENT_REG_FAILED = 'interop-component-reg-failed',
2626
INDEXED_DB_UNSUPPORTED = 'indexedDB-unsupported',
2727
INVALID_INDEXED_DB_CONTEXT = 'invalid-indexedDB-context',
28-
COOKIES_NOT_ENABLED = 'cookies-not-enabled'
28+
COOKIES_NOT_ENABLED = 'cookies-not-enabled',
29+
INVALID_ANALYTICS_CONTEXT = 'invalid-analytics-context'
2930
}
3031

3132
const ERRORS: ErrorMap<AnalyticsError> = {
@@ -50,7 +51,9 @@ const ERRORS: ErrorMap<AnalyticsError> = {
5051
'Wrap initialization of analytics in analytics.isSupported() ' +
5152
'to prevent initialization in unsupported environments',
5253
[AnalyticsError.COOKIES_NOT_ENABLED]:
53-
'Cookies are not enabled in this browser environment. Analytics requires cookies to be enabled.'
54+
'Cookies are not enabled in this browser environment. Analytics requires cookies to be enabled.',
55+
[AnalyticsError.INVALID_ANALYTICS_CONTEXT]:
56+
'Firebase Analytics is not supported in browser extensions.'
5457
};
5558

5659
interface ErrorParams {

packages/analytics/src/factory.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ import { FirebaseInstallations } from '@firebase/installations-types';
4141
import {
4242
isIndexedDBAvailable,
4343
validateIndexedDBOpenable,
44-
areCookiesEnabled
44+
areCookiesEnabled,
45+
isBrowserExtension
4546
} from '@firebase/util';
4647

4748
/**
@@ -122,6 +123,9 @@ export function factory(
122123
app: FirebaseApp,
123124
installations: FirebaseInstallations
124125
): FirebaseAnalytics {
126+
if (isBrowserExtension()) {
127+
throw ERROR_FACTORY.create(AnalyticsError.INVALID_ANALYTICS_CONTEXT);
128+
}
125129
if (!areCookiesEnabled()) {
126130
throw ERROR_FACTORY.create(AnalyticsError.COOKIES_NOT_ENABLED);
127131
}

packages/firestore/.idea/runConfigurations/firestore_lite_Tests__Emulator_.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/firestore/karma.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function getTestFiles(argv) {
5555
} else if (argv.integration) {
5656
return [legcayIntegrationTests];
5757
} else if (argv.lite) {
58+
process.env.TEST_PLATFORM = 'browser_lite';
5859
return [liteIntegrationTests];
5960
} else if (argv.exp) {
6061
return [expIntegrationTests];

packages/firestore/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"gendeps:exp": "../../scripts/exp/extract-deps.sh --types ./exp-types/index.d.ts --bundle ./dist/exp/tmp.js --output ./exp/dependencies.json",
2525
"pregendeps:lite": "node scripts/build-bundle.js --input ./lite/index.ts --output ./dist/lite/tmp.js",
2626
"gendeps:lite": "../../scripts/exp/extract-deps.sh --types ./lite-types/index.d.ts --bundle ./dist/lite/tmp.js --output ./lite/dependencies.json",
27-
"test:lite": "node ./scripts/run-tests.js --emulator --main=lite/index.ts 'lite/test/**/*.test.ts'",
27+
"test:lite": "node ./scripts/run-tests.js --emulator --platform node_lite --main=lite/index.ts 'lite/test/**/*.test.ts'",
2828
"test:lite:browser": "karma start --single-run --lite",
2929
"test:lite:browser:debug": "karma start --single-run --lite --auto-watch",
3030
"test:exp": "node ./scripts/run-tests.js --emulator --main=exp/index.ts test/integration/api/*.test.ts",
@@ -63,6 +63,7 @@
6363
"@firebase/webchannel-wrapper": "0.2.41",
6464
"@grpc/grpc-js": "^1.0.0",
6565
"@grpc/proto-loader": "^0.5.0",
66+
"node-fetch": "2.6.0",
6667
"tslib": "^1.11.1"
6768
},
6869
"peerDependencies": {

packages/firestore/rollup.config.lite.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const allBuilds = [
7171
format: 'es',
7272
sourcemap: true
7373
},
74-
plugins: [alias(util.generateAliasConfig('node')), ...nodePlugins],
74+
plugins: [alias(util.generateAliasConfig('node_lite')), ...nodePlugins],
7575
external: util.resolveNodeExterns,
7676
treeshake: {
7777
moduleSideEffects: false
@@ -111,7 +111,10 @@ const allBuilds = [
111111
format: 'es',
112112
sourcemap: true
113113
},
114-
plugins: [alias(util.generateAliasConfig('browser')), ...browserPlugins],
114+
plugins: [
115+
alias(util.generateAliasConfig('browser_lite')),
116+
...browserPlugins
117+
],
115118
external: util.resolveBrowserExterns,
116119
treeshake: {
117120
moduleSideEffects: false
@@ -125,7 +128,7 @@ const allBuilds = [
125128
format: 'es',
126129
sourcemap: true
127130
},
128-
plugins: [alias(util.generateAliasConfig('rn')), ...browserPlugins],
131+
plugins: [alias(util.generateAliasConfig('rn_lite')), ...browserPlugins],
129132
external: util.resolveBrowserExterns,
130133
treeshake: {
131134
moduleSideEffects: false

packages/firestore/scripts/run-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
17-
*/exports.__esModule=true;var yargs=require("yargs");var path_1=require("path");var child_process_promise_1=require("child-process-promise");var argv=yargs.options({main:{type:"string",demandOption:true},emulator:{type:"boolean"},persistence:{type:"boolean"}}).argv;var nyc=path_1.resolve(__dirname,"../../../node_modules/.bin/nyc");var mocha=path_1.resolve(__dirname,"../../../node_modules/.bin/mocha");process.env.TS_NODE_CACHE="NO";process.env.TS_NODE_COMPILER_OPTIONS='{"module":"commonjs"}';var args=[mocha,"--require","ts-node/register","--require",argv.main,"--config","../../config/mocharc.node.js"];if(argv.emulator){process.env.FIRESTORE_EMULATOR_PORT="8080";process.env.FIRESTORE_EMULATOR_PROJECT_ID="test-emulator"}if(argv.persistence){process.env.USE_MOCK_PERSISTENCE="YES";args.push("--require","test/util/node_persistence.ts")}args=args.concat(argv._);var childProcess=child_process_promise_1.spawn(nyc,args,{stdio:"inherit",cwd:process.cwd()}).childProcess;process.once("exit",(function(){return childProcess.kill()}));process.once("SIGINT",(function(){return childProcess.kill("SIGINT")}));process.once("SIGTERM",(function(){return childProcess.kill("SIGTERM")}));
17+
*/exports.__esModule=true;var yargs=require("yargs");var path_1=require("path");var child_process_promise_1=require("child-process-promise");var argv=yargs.options({main:{type:"string",demandOption:true},platform:{type:"string",default:"node"},emulator:{type:"boolean"},persistence:{type:"boolean"}}).argv;var nyc=path_1.resolve(__dirname,"../../../node_modules/.bin/nyc");var mocha=path_1.resolve(__dirname,"../../../node_modules/.bin/mocha");process.env.TS_NODE_CACHE="NO";process.env.TS_NODE_COMPILER_OPTIONS='{"module":"commonjs"}';process.env.TEST_PLATFORM=argv.platform;var args=[mocha,"--require","ts-node/register","--require",argv.main,"--config","../../config/mocharc.node.js"];if(argv.emulator){process.env.FIRESTORE_EMULATOR_PORT="8080";process.env.FIRESTORE_EMULATOR_PROJECT_ID="test-emulator"}if(argv.persistence){process.env.USE_MOCK_PERSISTENCE="YES";args.push("--require","test/util/node_persistence.ts")}args=args.concat(argv._);var childProcess=child_process_promise_1.spawn(nyc,args,{stdio:"inherit",cwd:process.cwd()}).childProcess;process.once("exit",(function(){return childProcess.kill()}));process.once("SIGINT",(function(){return childProcess.kill("SIGINT")}));process.once("SIGTERM",(function(){return childProcess.kill("SIGTERM")}));

packages/firestore/scripts/run-tests.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ const argv = yargs.options({
2424
type: 'string',
2525
demandOption: true
2626
},
27+
platform: {
28+
type: 'string',
29+
default: 'node'
30+
},
2731
emulator: {
2832
type: 'boolean'
2933
},
@@ -37,6 +41,7 @@ const mocha = resolve(__dirname, '../../../node_modules/.bin/mocha');
3741

3842
process.env.TS_NODE_CACHE = 'NO';
3943
process.env.TS_NODE_COMPILER_OPTIONS = '{"module":"commonjs"}';
44+
process.env.TEST_PLATFORM = argv.platform;
4045

4146
let args = [
4247
mocha,

0 commit comments

Comments
 (0)