Skip to content

Commit 9fd2af8

Browse files
committed
Dropping the webpack plugin
1 parent a0a90f6 commit 9fd2af8

File tree

8 files changed

+431
-187
lines changed

8 files changed

+431
-187
lines changed

package-lock.json

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

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
],
2323
"sideEffects": false,
2424
"scripts": {
25-
"build": "rm -rf dist && tsc -p tsconfig.client.json && tsc && ts-node ./tools/build.ts",
25+
"build": "rm -rf dist && tsc && ts-node ./tools/build.ts",
2626
"dev": "npm run build && ts-node ./tools/dev.ts",
2727
"test": "echo \"Error: no test specified\" && exit 1",
2828
"e2e:build-next": "rm -rf e2e && npx create-next-app e2e --use-npm --ts",
@@ -63,8 +63,7 @@
6363
"fs-extra": "^10.1.0",
6464
"jsonc-parser": "^3.0.0",
6565
"semver": "^7.3.7",
66-
"tslib": "^2.3.1",
67-
"firebase": "^9.8.1"
66+
"tslib": "^2.3.1"
6867
},
6968
"devDependencies": {
7069
"@angular-devkit/architect": "^0.1303.3",
@@ -77,6 +76,7 @@
7776
"@types/node": "^16.11.12",
7877
"@types/semver": "^7.3.9",
7978
"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: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
export * from 'firebase/auth';
21
import {
32
beforeAuthStateChanged,
43
onIdTokenChanged,
5-
getAuth as getFirebaseAuth,
6-
initializeAuth as initializeFirebaseAuth,
74
User,
85
Auth,
9-
Dependencies
106
} from 'firebase/auth';
11-
import type { FirebaseApp } from 'firebase/app';
12-
13-
export const ID_TOKEN_MAX_AGE = 5 * 60;
7+
import { ID_TOKEN_MAX_AGE } from '../../constants';
148

159
let alreadySetup = false;
1610
let lastPostedIdToken: string|undefined|null = null;
@@ -31,7 +25,7 @@ const mintCookie = async (user: User|null) => {
3125
});
3226
};
3327

34-
const setup = (auth: Auth) => {
28+
export const initializeClient = (auth: Auth) => {
3529
if (auth.app.name !== '[DEFAULT]') return;
3630
if (typeof window === 'undefined') return;
3731
if (alreadySetup) return;
@@ -41,15 +35,3 @@ const setup = (auth: Auth) => {
4135
});
4236
onIdTokenChanged(auth, user => mintCookie(user));
4337
}
44-
45-
export function getAuth(app?: FirebaseApp) {
46-
const auth = getFirebaseAuth(app);
47-
setup(auth);
48-
return auth;
49-
}
50-
51-
export function initializeAuth(app: FirebaseApp, deps?: Dependencies) {
52-
const auth = initializeFirebaseAuth(app, deps);
53-
setup(auth);
54-
return auth;
55-
}

src/constants.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
export { ID_TOKEN_MAX_AGE } from './client/auth';
21
export const FIREBASE_ADMIN_VERSION = '__FIREBASE_ADMIN_VERSION__';
32
export const FIREBASE_FUNCTIONS_VERSION = '__FIREBASE_FUNCTIONS_VERSION__';
43
export const COOKIE_VERSION = '__COOKIE_VERSION__';
@@ -8,4 +7,4 @@ export const DEFAULT_REGION = 'us-central1';
87
export const LRU_MAX_INSTANCES = 100;
98
export const LRU_TTL = 1_000 * 60 * 5;
109
export const COOKIE_MAX_AGE = 60 * 60 * 24 * 5 * 1_000;
11-
export const MIN_FIREBASE_SDK_FOR_AUTH = '9.8.0';
10+
export const ID_TOKEN_MAX_AGE = 5 * 60;

src/frameworks/next.js/index.ts

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import nextExport from 'next/dist/export';
2121
import { copy } from 'fs-extra';
2222
import { trace } from 'next/dist/trace';
2323

24-
import { DeployConfig, PathFactory, findDependency, getWebpackPlugin } from '../../utils';
24+
import { DeployConfig, PathFactory } from '../../utils';
2525

2626
export const build = async (config: DeployConfig | Required<DeployConfig>, getProjectPath: PathFactory) => {
2727

@@ -35,32 +35,14 @@ export const build = async (config: DeployConfig | Required<DeployConfig>, getPr
3535
nextConfig = await import(getProjectPath('next.config.js'));
3636
}
3737

38-
let usesFirebaseConfig = false;
39-
const firebaseDependency = findDependency('firebase', getProjectPath());
40-
let overrideConfig: NextConfig|null = null;
41-
if (firebaseDependency) {
42-
overrideConfig = {
43-
...nextConfig,
44-
webpack: (config, context) => {
45-
let newConfig = config;
46-
if (nextConfig.webpack) newConfig = nextConfig.webpack(config, context);
47-
if (context.isServer) return newConfig;
48-
const plugin = getWebpackPlugin(context.webpack, getProjectPath());
49-
newConfig.plugins ||= [];
50-
newConfig.plugins.push(plugin);
51-
return newConfig;
52-
}
53-
}
54-
}
55-
5638

5739
// SEMVER these defaults are only needed for Next 11
5840
const { distDir='.next', basePath='' } = nextConfig;
5941

6042
const deployPath = (...args: string[]) => config.dist ? join(config.dist, ...args) : getProjectPath('.deploy', ...args);
6143
const getHostingPath = (...args: string[]) => deployPath('hosting', ...basePath.split('/'), ...args);
6244

63-
await nextBuild(getProjectPath(), overrideConfig as any, false, false, true);
45+
await nextBuild(getProjectPath(), null, false, false, true);
6446

6547
console.log('Attempting `next export`...');
6648

@@ -69,7 +51,7 @@ export const build = async (config: DeployConfig | Required<DeployConfig>, getPr
6951
{ silent: true, outdir: getHostingPath() },
7052
trace('next-export-cli')
7153
).catch(() => {
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');
54+
console.warn('\nYou can safely ignore the above error. Since next export did not succeed we\'ll treat as SSR.\n\n');
7355
});
7456

7557
let usingCloudFunctions = !!config.function;
@@ -149,7 +131,7 @@ export const build = async (config: DeployConfig | Required<DeployConfig>, getPr
149131
}).filter(it => it);
150132

151133
// TODO use this better detection for usesFirebaseConfig
152-
return { usingCloudFunctions, usesFirebaseConfig, headers, redirects, rewrites, framework: 'next.js', packageJson, bootstrapScript: null };
134+
return { usingCloudFunctions, headers, redirects, rewrites, framework: 'next.js', packageJson, bootstrapScript: null };
153135
}
154136

155137
type Manifest = {

src/utils.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
// limitations under the License.
1414

1515
import { exec as execCallback, spawn as spawnCallback, ExecOptions, SpawnOptionsWithoutStdio, spawnSync } from 'child_process';
16-
import { dirname, join, relative, resolve, sep } from 'path';
17-
import { lt } from 'semver';
18-
import { MIN_FIREBASE_SDK_FOR_AUTH } from './constants';
16+
import { join } from 'path';
1917

2018
export const exec = (command: string, options: ExecOptions={}) => new Promise((resolve, reject) =>
2119
execCallback(command, options, (error, stdout) => {
@@ -76,22 +74,4 @@ export const findDependency = (name: string, cwd=process.cwd()) => {
7674
return null;
7775
}
7876
return search(name, json.dependencies);
79-
}
80-
81-
export const getWebpackPlugin = (webpack: typeof import('webpack'), cwd: string) => {
82-
const { NormalModuleReplacementPlugin } = webpack;
83-
return new NormalModuleReplacementPlugin(/^firebase\/(auth)$/, (resource: any) => {
84-
// Don't allow firebase-frameworks to recurse
85-
const frameworksRoot = resolve(`${dirname(require.resolve('.'))}${sep}..`);
86-
if (resource.context.startsWith(frameworksRoot)) return;
87-
// Don't mutate their node_modules
88-
if (relative(cwd, resource.context).startsWith(`node_modules${sep}`)) return;
89-
const client = resource.request.split('firebase/')[1];
90-
const firebaseDependency = findDependency('firebase', cwd);
91-
// auth requires beforeAuthStateChanged, released in 9.8.0
92-
if (client === 'auth' && lt(firebaseDependency.version, MIN_FIREBASE_SDK_FOR_AUTH)) return;
93-
// TODO log to the firebase.log
94-
console.log(`Substituting import of '${resource.request}' with 'firebase-frameworks/client/${client}' in ${relative(cwd, resource.context)}.`);
95-
resource.request = require.resolve(`firebase-frameworks/client/${client}`);
96-
})
9777
};

tsconfig.client.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"src/server/index.ts",
2020
"src/server/firebase-aware.ts",
2121
"src/frameworks/*/server.ts",
22+
"src/client/*/index.ts",
2223
"types/*.d.ts"
2324
]
2425
}

0 commit comments

Comments
 (0)