Skip to content

Commit f8596b1

Browse files
committed
fixing the canary build & stuff
1 parent 56b5a13 commit f8596b1

File tree

10 files changed

+24338
-25264
lines changed

10 files changed

+24338
-25264
lines changed

package-lock.json

Lines changed: 24279 additions & 25241 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
],
2323
"sideEffects": false,
2424
"scripts": {
25-
"build": "rm -rf dist && tsc && ts-node ./tools/build.ts",
25+
"build": "rm -rf dist && tsc -p tsconfig.client.json && tsc && ts-node ./tools/build.ts",
26+
"dev": "npm run build && ts-node ./tools/dev.ts",
2627
"test": "echo \"Error: no test specified\" && exit 1",
2728
"e2e:build-next": "rm -rf e2e && npx create-next-app e2e --use-npm --ts",
2829
"e2e:build-nuxt": "rm -rf e2e && npx create-nuxt-app e2e --answers '$(cat ./tools/create-nuxt-answers.json)'",
@@ -52,8 +53,7 @@
5253
"node": "./dist/server/firebase-aware.js",
5354
"default": null
5455
},
55-
"./client/auth": "./dist/client/auth/index.js",
56-
"./client/app": "./dist/client/app/index.js"
56+
"./client/auth": "./dist/client/auth/index.js"
5757
},
5858
"files": [
5959
"dist"
@@ -63,7 +63,8 @@
6363
"fs-extra": "^10.1.0",
6464
"jsonc-parser": "^3.0.0",
6565
"semver": "^7.3.7",
66-
"tslib": "^2.3.1"
66+
"tslib": "^2.3.1",
67+
"firebase": "^9.8.1"
6768
},
6869
"devDependencies": {
6970
"@angular-devkit/architect": "^0.1303.3",
@@ -76,7 +77,6 @@
7677
"@types/node": "^16.11.12",
7778
"@types/semver": "^7.3.9",
7879
"cookie": "^0.5.0",
79-
"firebase": "^9.8.1",
8080
"firebase-admin": "^10.1.0",
8181
"firebase-functions": "^3.20.1",
8282
"firebase-tools": "^10.5.0",

src/client/auth/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {
99
Dependencies
1010
} from 'firebase/auth';
1111
import type { FirebaseApp } from 'firebase/app';
12-
import { ID_TOKEN_MAX_AGE } from '../../constants';
12+
13+
export const ID_TOKEN_MAX_AGE = 5 * 60;
1314

1415
let alreadySetup = false;
1516
let lastPostedIdToken: string|undefined|null = null;
@@ -42,12 +43,14 @@ const setup = (auth: Auth) => {
4243
}
4344

4445
export function getAuth(app?: FirebaseApp) {
46+
console.log('yo!');
4547
const auth = getFirebaseAuth(app);
4648
setup(auth);
4749
return auth;
4850
}
4951

5052
export function initializeAuth(app: FirebaseApp, deps?: Dependencies) {
53+
console.log('yo!');
5154
const auth = initializeFirebaseAuth(app, deps);
5255
setup(auth);
5356
return auth;

src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export { ID_TOKEN_MAX_AGE } from './client/auth';
12
export const FIREBASE_ADMIN_VERSION = '__FIREBASE_ADMIN_VERSION__';
23
export const FIREBASE_FUNCTIONS_VERSION = '__FIREBASE_FUNCTIONS_VERSION__';
34
export const COOKIE_VERSION = '__COOKIE_VERSION__';
@@ -6,6 +7,5 @@ export const FIREBASE_FRAMEWORKS_VERSION = '__FIREBASE_FRAMEWORKS_VERSION__';
67
export const DEFAULT_REGION = 'us-central1';
78
export const LRU_MAX_INSTANCES = 100;
89
export const LRU_TTL = 1_000 * 60 * 5;
9-
export const ID_TOKEN_MAX_AGE = 5 * 60;
1010
export const COOKIE_MAX_AGE = 60 * 60 * 24 * 5 * 1_000;
1111
export const MIN_FIREBASE_SDK_FOR_AUTH = '9.8.0';

src/frameworks/next.js/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export const build = async (config: DeployConfig | Required<DeployConfig>, getPr
4444
webpack: (config, context) => {
4545
let newConfig = config;
4646
if (nextConfig.webpack) newConfig = nextConfig.webpack(config, context);
47-
const plugin = getWebpackPlugin(getProjectPath());
47+
if (context.isServer) return newConfig;
48+
const plugin = getWebpackPlugin(context.webpack, getProjectPath());
4849
newConfig.plugins ||= [];
4950
newConfig.plugins.push(plugin);
5051
return newConfig;
@@ -61,12 +62,14 @@ export const build = async (config: DeployConfig | Required<DeployConfig>, getPr
6162

6263
await nextBuild(getProjectPath(), overrideConfig as any, false, false, true);
6364

65+
console.log('Attempting `next export`...');
66+
6467
await nextExport(
6568
getProjectPath(),
6669
{ silent: true, outdir: getHostingPath() },
6770
trace('next-export-cli')
6871
).catch(() => {
69-
console.warn('\nUnable to export the app, treating as SSR.\n\n');
72+
console.warn('\nIgnore the above error, Next.js is not respecting the silent flag. Since next export did not succeed we\'ll treat as SSR.\n\n');
7073
});
7174

7275
let usingCloudFunctions = !!config.function;

src/utils.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import { exec as execCallback, spawn as spawnCallback, ExecOptions, SpawnOptionsWithoutStdio, spawnSync } from 'child_process';
1616
import { dirname, join, relative, resolve, sep } from 'path';
17-
import { exit } from 'process';
1817
import { lt } from 'semver';
1918
import { MIN_FIREBASE_SDK_FOR_AUTH } from './constants';
2019

@@ -79,16 +78,9 @@ export const findDependency = (name: string, cwd=process.cwd()) => {
7978
return search(name, json.dependencies);
8079
}
8180

82-
export const getWebpackPlugin = (cwd: string) => {
83-
let webpack: typeof import('webpack');
84-
try {
85-
webpack = require('webpack');
86-
} catch(e) {
87-
console.error('Webpack is required for auth-context awareness in SSR, npm i --save-dev webpack.');
88-
exit(1);
89-
}
81+
export const getWebpackPlugin = (webpack: typeof import('webpack'), cwd: string) => {
9082
const { NormalModuleReplacementPlugin } = webpack;
91-
new NormalModuleReplacementPlugin(/^firebase\/(auth)$/, (resource: any) => {
83+
return new NormalModuleReplacementPlugin(/^firebase\/(auth)$/, (resource: any) => {
9284
// Don't allow firebase-frameworks to recurse
9385
const frameworksRoot = resolve(`${dirname(require.resolve('.'))}${sep}..`);
9486
if (resource.context.startsWith(frameworksRoot)) return;
@@ -100,6 +92,7 @@ export const getWebpackPlugin = (cwd: string) => {
10092
if (client === 'auth' && lt(firebaseDependency.version, MIN_FIREBASE_SDK_FOR_AUTH)) return;
10193
// TODO log to the firebase.log
10294
console.log(`Substituting import of '${resource.request}' with 'firebase-frameworks/client/${client}' in ${relative(cwd, resource.context)}.`);
103-
resource.request = require.resolve(`./client/${client}`);
95+
console.log(require.resolve(`firebase-frameworks/client/${client}`));
96+
resource.request = require.resolve(`firebase-frameworks/client/${client}`);
10497
})
10598
};

tools/build.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const LOCAL_NODE_MODULES = [
1212
'nuxt',
1313
'@nuxt/kit/dist/index.mjs',
1414
'webpack',
15-
'firebase/auth',
1615
];
1716

1817
const ES_MODULES = [

tools/dev.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { exit } from 'process';
2+
import { replaceInFile } from 'replace-in-file';
3+
import { join } from 'path';
4+
import { readJson } from 'fs-extra';
5+
import { exec } from '../src/utils';
6+
7+
const run = async () => {
8+
const { name, version } = await readJson('./package.json');
9+
const path = join(process.cwd(), `${name}-${version}.tgz`);
10+
await replaceInFile({
11+
files: 'dist/constants.js',
12+
from: /^exports\.FIREBASE_FRAMEWORKS_VERSION = .*$/gm,
13+
to: `exports.FIREBASE_FRAMEWORKS_VERSION = 'file:${path}';`,
14+
});
15+
await exec('npm pack .');
16+
const npmRoot = await exec('npm root');
17+
await exec(`npm install --force --ignore-scripts --save ${path}`, { cwd: join(npmRoot as string, 'firebase-tools') });
18+
}
19+
20+
run().then(
21+
() => exit(0),
22+
() => exit(1)
23+
);

tsconfig.client.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"compilerOptions": {
3+
"outDir": "dist/client/auth",
4+
"target": "esnext",
5+
"module": "esnext",
6+
"moduleResolution": "node",
7+
"forceConsistentCasingInFileNames": true,
8+
"strict": true,
9+
"declaration": true,
10+
"skipLibCheck": true
11+
},
12+
"include": [
13+
"src/client/auth/index.ts",
14+
]
15+
}
16+

tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@
1616
"include": [
1717
"src/index.ts",
1818
"src/tools.ts",
19-
"src/client/*/index.ts",
2019
"src/server/index.ts",
2120
"src/server/firebase-aware.ts",
2221
"src/frameworks/*/server.ts",
23-
"types/*.d.ts", "src/client/auth/index.js",
22+
"types/*.d.ts"
2423
]
2524
}

0 commit comments

Comments
 (0)