Skip to content

Commit a1357a7

Browse files
authored
Merge 6cbb47e into 9fddd5c
2 parents 9fddd5c + 6cbb47e commit a1357a7

File tree

6 files changed

+187
-5
lines changed

6 files changed

+187
-5
lines changed

.changeset/old-lamps-nail.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@firebase/auth': patch
3+
'@firebase/firestore': patch
4+
'@firebase/installations-compat': patch
5+
---
6+
7+
Fix incorrect paths in package.json

.github/workflows/check-pkg-paths.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Test Package Paths
2+
3+
on: pull_request
4+
5+
jobs:
6+
test:
7+
name: Test Package Paths
8+
runs-on: ubuntu-latest
9+
10+
steps:
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
16+
- name: Set up Node (14)
17+
uses: actions/setup-node@v2
18+
with:
19+
node-version: 14.x
20+
- name: Yarn install
21+
run: yarn
22+
- name: Yarn build
23+
run: yarn build
24+
- name: Swap in public typings
25+
run: yarn release:prepare
26+
- name: Check paths
27+
run: yarn ts-node scripts/ci-test/check-paths.ts

packages/auth/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"react-native": "dist/rn/index.js",
88
"browser": "dist/esm2017/index.js",
99
"module": "dist/esm2017/index.js",
10-
"cordova": "dist/cordova/index.esm5.js",
10+
"cordova": "dist/cordova/index.js",
1111
"webworker": "dist/index.webworker.esm5.js",
1212
"esm5": "dist/esm5/index.js",
1313
"exports": {

packages/firestore/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@
5959
"require": "./dist/lite/index.node.cjs.js",
6060
"import": "./dist/lite/index.node.mjs"
6161
},
62-
"react-native": "./dist/lite/index.rn.esm2017.js",
63-
"esm5": "./dist/lite/index.browser.esm5.js",
64-
"default": "./dist/lite/index.browser.esm2017.js"
62+
"react-native": "./dist/index.rn.js",
63+
"esm5": "./dist/index.esm5.js",
64+
"default": "./dist/index.esm2017.js"
6565
},
6666
"./package.json": "./package.json"
6767
},

packages/installations-compat/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"./package.json": "./package.json"
1616
},
17-
"typings": "dist/installations-compat.d.ts",
17+
"typings": "dist/src/index.d.ts",
1818
"license": "Apache-2.0",
1919
"files": [
2020
"dist"

scripts/ci-test/check-paths.ts

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/**
2+
* @license
3+
* Copyright 2022 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import glob from 'glob';
19+
import { existsSync } from 'fs';
20+
import { resolve } from 'path';
21+
import { projectRoot as root } from '../utils';
22+
23+
/**
24+
* Top level fields in package.json that may point to entry point and
25+
* typings files.
26+
*/
27+
const TOP_LEVEL_FIELDS = [
28+
'main',
29+
'browser',
30+
'module',
31+
'typings',
32+
'react-native',
33+
'cordova',
34+
'esm5',
35+
'webworker',
36+
'main-esm'
37+
];
38+
39+
interface Result {
40+
packageName: string;
41+
found: boolean;
42+
filePath: string;
43+
fieldPath: string;
44+
}
45+
const results: Result[] = [];
46+
47+
/**
48+
* Get paths to packages. Only check the ones we actually
49+
* publish (packages/*).
50+
*/
51+
function getPaths(): Promise<string[]> {
52+
return new Promise((resolve, reject) => {
53+
glob('packages/*', (err, paths) => {
54+
if (err) reject(err);
55+
resolve(paths);
56+
});
57+
});
58+
}
59+
60+
/**
61+
* Recursively check `exports` field in package.json.
62+
*/
63+
function checkExports(
64+
pkgName: string,
65+
pkgRoot: string,
66+
path: string = '',
67+
exports: Record<string, any>
68+
) {
69+
for (const key in exports) {
70+
if (typeof exports[key] === 'string') {
71+
const filePath = resolve(pkgRoot, exports[key]);
72+
const result = {
73+
packageName: pkgName,
74+
found: false,
75+
filePath,
76+
fieldPath: `exports${path}[${key}]`
77+
};
78+
if (existsSync(filePath)) {
79+
result.found = true;
80+
}
81+
results.push(result);
82+
} else {
83+
checkExports(
84+
pkgName,
85+
pkgRoot,
86+
path ? `${path}[${key}]` : `[${key}]`,
87+
exports[key]
88+
);
89+
}
90+
}
91+
}
92+
93+
async function main() {
94+
const paths = await getPaths();
95+
96+
for (const path of paths) {
97+
const pkgRoot = `${root}/${path}`;
98+
if (existsSync(`${pkgRoot}/package.json`)) {
99+
const pkg = require(`${pkgRoot}/package.json`);
100+
101+
/**
102+
* Check top level fields.
103+
*/
104+
for (const field of TOP_LEVEL_FIELDS) {
105+
if (pkg[field]) {
106+
const filePath = resolve(pkgRoot, pkg[field]);
107+
const result = {
108+
packageName: pkg.name,
109+
found: false,
110+
filePath,
111+
fieldPath: field
112+
};
113+
if (existsSync(filePath)) {
114+
result.found = true;
115+
}
116+
results.push(result);
117+
}
118+
}
119+
/**
120+
* Check all levels of exports field.
121+
*/
122+
if (pkg.exports) {
123+
checkExports(pkg.name, pkgRoot, '', pkg.exports);
124+
}
125+
}
126+
}
127+
128+
let missingPaths: boolean = false;
129+
130+
for (const result of results) {
131+
if (!result.found) {
132+
missingPaths = true;
133+
console.log(
134+
`${result.packageName}: Field "${result.fieldPath}" ` +
135+
`points to ${result.filePath} which is not found.`
136+
);
137+
}
138+
}
139+
140+
/**
141+
* Fail CI if any missing paths found.
142+
*/
143+
if (missingPaths) {
144+
process.exit(1);
145+
}
146+
}
147+
148+
main();

0 commit comments

Comments
 (0)