Skip to content

Commit a388f17

Browse files
Merge branch 'main' into docs-product-snippet-fixes
2 parents aa03546 + c4c4ad1 commit a388f17

2 files changed

Lines changed: 36 additions & 12 deletions

File tree

src/schematics/deploy/actions.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import * as winston from 'winston';
1313
import { BuildTarget, CloudRunOptions, DeployBuilderSchema, FSHost, FirebaseTools } from '../interfaces';
1414
import { DEFAULT_FUNCTION_NAME, defaultFunction, defaultPackage, dockerfile, functionGen2 } from './functions-templates.js';
1515

16-
// @ts-ignore
17-
const __dirname = dirname(fileURLToPath(import.meta.url));
16+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
17+
// @ts-ignore `import.meta` is rejected by the --module es2015 pass of `npm run build:jasmine`.
18+
const moduleDirectory = typeof __dirname === 'string' ? __dirname : dirname(fileURLToPath(import.meta.url));
1819

1920
const { copySync, removeSync, readJsonSync } = fsExtra;
2021

@@ -128,7 +129,7 @@ const findPackageVersion = (packageManager: string, name: string) => {
128129
const getPackageJson = (context: BuilderContext, workspaceRoot: string, options: DeployBuilderOptions, main?: string) => {
129130
const dependencies: Record<string, string> = {};
130131
const devDependencies: Record<string, string> = {};
131-
const { firebaseFunctionsDependencies } = readJsonSync(join(__dirname, '..', 'versions.json'));
132+
const { firebaseFunctionsDependencies } = readJsonSync(join(moduleDirectory, '..', 'versions.json'));
132133
if (options.ssr !== 'cloud-run') {
133134
Object.keys(firebaseFunctionsDependencies).forEach(name => {
134135
const { version, dev } = firebaseFunctionsDependencies[name];

tools/build.ts

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -313,17 +313,21 @@ function spawnPromise(command: string, args: string[]) {
313313
.on('error', reject));
314314
}
315315

316+
// Path segments of each schematic entry point, relative to `schematics/` and without the file
317+
// extension: esbuild compiles the `.ts` and loadCompiledSchematics requires the emitted `.js`.
318+
const schematicEntryPoints = [
319+
['update', 'index'],
320+
['deploy', 'actions'],
321+
['deploy', 'builder'],
322+
['add', 'index'],
323+
['setup', 'index'],
324+
['update', 'v7', 'index'],
325+
['update', 'v21', 'index'],
326+
];
327+
316328
async function compileSchematics() {
317329
await esbuild.build({
318-
entryPoints: [
319-
src('schematics', "update", "index.ts"),
320-
src('schematics', "deploy", "actions.ts"),
321-
src('schematics', "deploy", "builder.ts"),
322-
src('schematics', "add", "index.ts"),
323-
src('schematics', "setup", "index.ts"),
324-
src('schematics', "update", "v7", "index.ts"),
325-
src('schematics', "update", "v21", "index.ts"),
326-
],
330+
entryPoints: schematicEntryPoints.map(segments => `${src('schematics', ...segments)}.ts`),
327331
format: "cjs",
328332
// turns out schematics don't support ESM, need to use webpack or shim these
329333
// format: "esm",
@@ -357,6 +361,25 @@ async function compileSchematics() {
357361
copy(src('schematics', 'setup', 'schema.json'), dest('schematics', 'setup', 'schema.json')),
358362
]);
359363
await replaceSchematicVersions();
364+
await loadCompiledSchematics();
365+
}
366+
367+
/**
368+
* Loads every compiled schematic entry point, so a bundle that cannot even be required fails the
369+
* build instead of shipping.
370+
*/
371+
async function loadCompiledSchematics() {
372+
const failures: string[] = [];
373+
for (const segments of schematicEntryPoints) {
374+
try {
375+
require(`${dest('schematics', ...segments)}.js`);
376+
} catch (error) {
377+
failures.push(` ${join(...segments)}.js: ${error}`);
378+
}
379+
}
380+
if (failures.length) {
381+
throw new Error(`Compiled schematics failed to load:\n${failures.join('\n')}`);
382+
}
360383
}
361384

362385
async function buildLibrary() {

0 commit comments

Comments
 (0)