Skip to content

Commit 89f757b

Browse files
committed
Better handle file: deps
1 parent 578d625 commit 89f757b

File tree

9 files changed

+42
-45
lines changed

9 files changed

+42
-45
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"ssr"
2222
],
2323
"scripts": {
24-
"build": "rm -rf dist && tsc && ts-node ./tools/build.ts && npm pack .",
24+
"build": "rm -rf dist && tsc && ts-node ./tools/build.ts",
2525
"test": "echo \"Error: no test specified\" && exit 1",
2626
"e2e:build-next": "rm -rf e2e && npx create-next-app e2e --use-npm --ts",
2727
"e2e:build-nuxt": "rm -rf e2e && npx create-nuxt-app e2e --answers '$(cat ./tools/create-nuxt-answers.json)'",

src/frameworks/angular/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ import { NodeJsAsyncHost } from '@angular-devkit/core/node';
22
import { workspaces, logging } from '@angular-devkit/core';
33
import { WorkspaceNodeModulesArchitectHost } from '@angular-devkit/architect/node';
44
import { Target, Architect, targetFromTargetString, targetStringFromTarget } from '@angular-devkit/architect';
5-
import { promises } from 'fs';
5+
import { mkdir } from 'fs/promises';
66
import { join } from 'path';
77

88
import { DeployConfig, exec, findDependency, PathFactory, spawn } from '../../utils';
99

10-
const { mkdir } = promises;
11-
1210
export const build = async (config: DeployConfig | Required<DeployConfig>, getProjectPath: PathFactory) => {
1311

1412
// TODO log to firebase-tools

src/frameworks/express/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { promises as fsPromises } from 'fs';
15+
import { readFile, mkdir } from 'fs/promises';
1616
import { join } from 'path';
1717

1818
import { DeployConfig, PathFactory, exec, spawn } from '../../utils';
1919

20-
const { readFile, rm, mkdir, copyFile } = fsPromises;
21-
2220
export const build = async (config: DeployConfig | Required<DeployConfig>, getProjectPath: PathFactory) => {
2321

2422
const packageJsonBuffer = await readFile(getProjectPath('package.json'));

src/frameworks/next.js/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { promises as fsPromises } from 'fs';
15+
import { readFile, mkdir, copyFile } from 'fs/promises';
1616
import { dirname, join, relative } from 'path';
1717
import type { NextConfig } from 'next/dist/server/config-shared';
1818
import type { Header, Rewrite, Redirect } from 'next/dist/lib/load-custom-routes';
1919
import nextBuild from 'next/dist/build';
2020

2121
import { DeployConfig, PathFactory, exec } from '../../utils';
2222

23-
const { readFile, rm, mkdir, writeFile, copyFile } = fsPromises;
24-
2523
export const build = async (config: DeployConfig | Required<DeployConfig>, getProjectPath: PathFactory) => {
2624

2725
await nextBuild(getProjectPath(), null, false, false, true);

src/frameworks/nuxt/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { promises as fsPromises } from 'fs'
15+
import { readFile, mkdir } from 'fs/promises'
1616
import { join } from 'path';
1717

1818
import { DeployConfig, PathFactory, exec } from '../../utils';
1919
import { build as buildNuxt3 } from '../nuxt3';
2020

21-
const { readFile, rm, mkdir } = fsPromises;
22-
2321
export const build = async (config: DeployConfig | Required<DeployConfig>, getProjectPath: PathFactory) => {
2422

2523
let nuxt;

src/frameworks/nuxt3/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { promises as fsPromises, existsSync } from 'fs'
15+
import { existsSync } from 'fs';
16+
import { readFile, mkdir, readdir } from 'fs/promises';
1617
import { join } from 'path';
1718

1819
import { DeployConfig, PathFactory, exec } from '../../utils';
1920

20-
const { readFile, rm, mkdir, readdir } = fsPromises;
21-
2221
export const build = async (config: DeployConfig | Required<DeployConfig>, getProjectPath: PathFactory) => {
2322

2423
const { loadNuxt, buildNuxt } = await import('@nuxt/kit');

src/index.ts

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { basename, join } from 'path';
15+
import { basename, join, relative } from 'path';
1616
import { exit } from 'process';
17-
import { promises as fs } from 'fs';
17+
import { writeFile, copyFile, stat } from 'fs/promises';
1818

1919
import { build } from './frameworks';
20-
import { defaultFirebaseToolsOptions, DEFAULT_REGION, shortSiteName, spawn } from './utils';
20+
import { defaultFirebaseToolsOptions, DEFAULT_REGION, exec, shortSiteName, spawn } from './utils';
2121
import { getFirebaseTools, normalizedHostingConfigs, getInquirer, needProjectId } from './firebase';
22-
23-
const { writeFile, copyFile } = fs;
22+
import { spawnSync } from 'child_process';
2423

2524
const NODE_VERSION = parseInt(process.versions.node, 10).toString();
2625
const FIREBASE_ADMIN_VERSION = '__FIREBASE_ADMIN_VERSION__';
@@ -123,13 +122,22 @@ export const prepare = async (targetNames: string[], context: any, options: any)
123122
packageJson.main = 'server.js';
124123
delete packageJson.devDependencies;
125124
packageJson.dependencies ||= {};
126-
if (FIREBASE_FRAMEWORKS_VERSION.startsWith('file:')) {
127-
const file = FIREBASE_FRAMEWORKS_VERSION.split(':')[1];
128-
const filename = basename(file);
129-
await copyFile(file, join(functionsDist, filename));
130-
packageJson.dependencies['firebase-frameworks'] = `file:${filename}`;
131-
} else {
132-
packageJson.dependencies['firebase-frameworks'] = FIREBASE_FRAMEWORKS_VERSION;
125+
packageJson.dependencies['firebase-frameworks'] = FIREBASE_FRAMEWORKS_VERSION;
126+
for (const [name, version] of Object.entries(packageJson.dependencies as Record<string, string>)) {
127+
if (version.startsWith('file:')) {
128+
const path = version.split(':')[1];
129+
const stats = await stat(path);
130+
if (stats.isDirectory()) {
131+
const result = spawnSync('npm', ['pack', relative(functionsDist, path)], { cwd: functionsDist });
132+
if (!result.stdout) continue;
133+
const filename = result.stdout.toString().trim();
134+
packageJson.dependencies[name] = `file:${filename}`;
135+
} else {
136+
const filename = basename(path);
137+
await copyFile(path, join(functionsDist, filename));
138+
packageJson.dependencies[name] = `file:${filename}`;
139+
}
140+
}
133141
}
134142
// TODO test these with semver, error if already set out of range
135143
packageJson.dependencies['firebase-admin'] ||= FIREBASE_ADMIN_VERSION;
@@ -149,11 +157,10 @@ export const prepare = async (targetNames: string[], context: any, options: any)
149157
// Welp, that didn't work, since firebase-tools checks that they have a minimum firebase-frameworks SDK installed...
150158
// TODO explore symlinks and ways to make this faster, better, stronger
151159
// log to firebase-tools
152-
await spawn('npm', ['i', '--only', 'production', '--no-audit', '--no-fund', '--silent'], { cwd: functionsDist }, stdoutChunk => {
153-
console.log(stdoutChunk.toString());
154-
}, errChunk => {
155-
console.error(errChunk.toString());
156-
});
160+
const npmInstall = spawnSync('npm', ['i', '--only', 'production', '--no-audit', '--no-fund', '--silent'], { cwd: functionsDist });
161+
if (npmInstall.status) {
162+
console.error(npmInstall.output.toString());
163+
}
157164

158165
// TODO allow configuration of the Cloud Function
159166
await writeFile(join(functionsDist, 'settings.js'), `exports.HTTPS_OPTIONS = {};

tools/build.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ const main = async () => {
4646
to: LOCAL_NODE_MODULES.map(mod => `import(\`\${process.cwd()}/node_modules/${mod}\`)`),
4747
});
4848

49-
const { version } = require('../package.json');
5049
const npmList = JSON.parse(spawnSync('npm', ['list', '--json=true'], { encoding: 'utf8' }).stdout.toString());
5150
const from = ['__FIREBASE_FRAMEWORKS_VERSION__'];
52-
const to = [`file:${process.cwd()}/firebase-frameworks-${version}.tgz`];
51+
const to = [`file:${process.cwd()}`];
5352
for (const [dep, { version }] of Object.entries<Record<string, string>>(npmList.dependencies)) {
5453
from.push(`__${dep.toUpperCase().replace(/[^A-Z]/g, '_')}_VERSION__`);
5554
to.push(`^${version}`);

0 commit comments

Comments
 (0)