Skip to content

Commit afa4ae7

Browse files
committed
Create path checker script
1 parent 9fddd5c commit afa4ae7

File tree

5 files changed

+129
-5
lines changed

5 files changed

+129
-5
lines changed

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

Lines changed: 27 additions & 0 deletions
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: xvfb-run yarn test:changed core

packages/auth/package.json

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import glob from 'glob';
2+
import { existsSync } from 'fs';
3+
import { resolve } from 'path';
4+
import { projectRoot as root } from '../utils';
5+
6+
const TOP_LEVEL_FIELDS = [
7+
'main',
8+
'browser',
9+
'module',
10+
'typings',
11+
'react-native',
12+
'cordova',
13+
'esm5',
14+
'webworker',
15+
'main-esm'
16+
];
17+
18+
interface Result {
19+
packageName: string;
20+
found: boolean;
21+
filePath: string;
22+
fieldPath: string;
23+
}
24+
const results: Result[] = [];
25+
26+
function getPaths(): Promise<string[]> {
27+
return new Promise((resolve, reject) => {
28+
glob('packages/*', (err, paths) => {
29+
if (err) reject(err);
30+
resolve(paths);
31+
});
32+
})
33+
}
34+
35+
function checkExports(pkgName: string, pkgRoot: string, path: string = '', exports: Record<string, any>) {
36+
for (const key in exports) {
37+
if (typeof exports[key] === 'string') {
38+
const filePath = resolve(pkgRoot, exports[key]);
39+
const result = {
40+
packageName: pkgName,
41+
found: false,
42+
filePath,
43+
fieldPath: `exports${path}[${key}]`
44+
};
45+
if (existsSync(filePath)) {
46+
result.found = true;
47+
}
48+
results.push(result);
49+
} else {
50+
checkExports(pkgName, pkgRoot, path ? `${path}[${key}]` : `[${key}]`, exports[key]);
51+
}
52+
}
53+
}
54+
55+
async function main() {
56+
const paths = await getPaths();
57+
for (const path of paths) {
58+
const pkgRoot = `${root}/${path}`;
59+
if (existsSync(`${pkgRoot}/package.json`)) {
60+
const pkg = require(`${pkgRoot}/package.json`);
61+
for (const field of TOP_LEVEL_FIELDS) {
62+
if (pkg[field]) {
63+
const filePath = resolve(pkgRoot, pkg[field]);
64+
const result = {
65+
packageName: pkg.name,
66+
found: false,
67+
filePath,
68+
fieldPath: field
69+
};
70+
if (existsSync(filePath)) {
71+
result.found = true;
72+
}
73+
results.push(result);
74+
}
75+
}
76+
if (pkg.exports) {
77+
checkExports(pkg.name, pkgRoot, '', pkg.exports);
78+
}
79+
}
80+
}
81+
82+
let missingPaths: boolean = false;
83+
84+
for (const result of results) {
85+
if (!result.found) {
86+
missingPaths = true;
87+
console.log(`${result.packageName}: Field "${result.fieldPath}" ` +
88+
`points to ${result.filePath} which is not found.`);
89+
}
90+
}
91+
92+
if (missingPaths) {
93+
process.exit(1);
94+
}
95+
}
96+
97+
main();

0 commit comments

Comments
 (0)