New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@apphosting/adapter-angular

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apphosting/adapter-angular - npm Package Compare versions

Comparing version 17.0.0-canary.a076bd8 to 17.0.0-canary.cbdb6cb

dist/interface.d.ts

22

dist/bin/build.js
#! /usr/bin/env node
import { spawn } from "child_process";
import { loadConfig } from "../utils.js";
const build = (cwd = process.cwd()) => new Promise((resolve, reject) => {
// TODO warn if the build script contains anything other than `ng build`
const process = spawn("npm", ["run", "build"], { cwd, shell: true, stdio: "pipe" });
process.stdout.on("data", (it) => console.log(it.toString().trim()));
process.stderr.on("data", (it) => console.error(it.toString().trim()));
process.on("exit", (code) => {
if (code === 0)
return resolve();
reject();
});
});
const config = await loadConfig(process.cwd());
await build().catch(() => process.exit(1));
// TODO do all the things
console.log({ config });
import { checkBuildConditions, build, generateOutputDirectory } from "../utils.js";
const cwd = process.cwd();
await checkBuildConditions(cwd);
const outputBundleOptions = await build().catch(() => process.exit(1));
await generateOutputDirectory(cwd, outputBundleOptions);

@@ -7,3 +7,3 @@ import assert from "assert";

const importCreateJs = import("@apphosting/adapter-angular/dist/bin/create.js");
describe("peer dependencies", async () => {
describe("peer dependencies", () => {
let expectedAngularRange;

@@ -15,5 +15,5 @@ let exepctedDevKitArchitectRange;

if (!version)
throw "couldn't parse package.json version";
throw new Error("couldn't parse package.json version");
expectedAngularRange = `~${version.major}.${version.minor}.0`;
exepctedDevKitArchitectRange = `~0.${version.major}${version.minor < 10 ? '0' : ''}${version.minor}.0`;
exepctedDevKitArchitectRange = `~0.${version.major}${version.minor < 10 ? "0" : ""}${version.minor}.0`;
});

@@ -20,0 +20,0 @@ it("expected @angular/cli version requirement to match", async () => {

@@ -1,3 +0,10 @@

export declare const readJson: typeof import("jsonfile").readFile;
export declare function loadConfig(cwd: string): Promise<import("@angular-devkit/core").JsonObject>;
/// <reference types="node" resolution-mode="require"/>
import fsExtra from "fs-extra";
import { OutputPathOptions, OutputPaths } from "./interface.js";
export declare const writeFile: typeof import("fs").writeFile.__promisify__ & typeof import("fs").writeFile, move: typeof fsExtra.move, readJson: typeof import("jsonfile").readFile;
export declare function checkBuildConditions(cwd: string): Promise<void>;
export declare function populateOutputBundleOptions(outputPaths: OutputPaths): OutputPathOptions;
export declare const build: (cwd?: string) => Promise<OutputPathOptions>;
export declare function generateOutputDirectory(cwd: string, outputPathOptions: OutputPathOptions): Promise<void>;
export declare function generateBundleYaml(outputPathOptions: OutputPathOptions, cwd: string): Promise<void>;
export declare const isMain: (meta: ImportMeta) => boolean;
import fsExtra from "fs-extra";
import logger from "firebase-functions/logger";
import { fileURLToPath } from "url";
import { spawn } from "child_process";
import { resolve, normalize, relative } from "path";
import { stringify as yamlStringify } from "yaml";
import { buildManifestSchema } from "./interface.js";
// fs-extra is CJS, readJson can't be imported using shorthand
export const { readJson } = fsExtra;
export async function loadConfig(cwd) {
// dynamically load NextJS so this can be used in an NPX context
export const { writeFile, move, readJson } = fsExtra;
/*
Check if build conditions are satisfied for the workspace:
The workspace cannot contain multiple angular projects.
The angular project must be using application builder.
*/
export async function checkBuildConditions(cwd) {
// dynamically load Angular so this can be used in an NPX context
const { NodeJsAsyncHost } = await import(`${cwd}/node_modules/@angular-devkit/core/node/index.js`);
const { workspaces } = await import(`${cwd}/node_modules/@angular-devkit/core/src/index.js`);
const { WorkspaceNodeModulesArchitectHost } = await import(`${cwd}/node_modules/@angular-devkit/architect/node/index.js`);
const host = workspaces.createWorkspaceHost(new NodeJsAsyncHost());
const { workspace } = await workspaces.readWorkspace(cwd, host);
const architectHost = new WorkspaceNodeModulesArchitectHost(workspace, cwd);
const apps = [];

@@ -27,16 +35,95 @@ workspace.projects.forEach((value, key) => {

throw new Error("Could not find build target.");
const { builder, defaultConfiguration: configuration = "production" } = workspaceProject.targets.get(target);
const { builder } = workspaceProject.targets.get(target);
if (builder !== "@angular-devkit/build-angular:application") {
throw new Error("Only the Angular application builder is supported.");
}
const buildTarget = {
project,
target,
configuration,
}
// Populate file or directory paths we need for generating output directory
export function populateOutputBundleOptions(outputPaths) {
const outputBundleDir = resolve(".apphosting");
const baseDirectory = fileURLToPath(outputPaths["root"]);
const browserRelativePath = relative(baseDirectory, fileURLToPath(outputPaths["browser"]));
let serverRelativePath = "server";
if (outputPaths["server"]) {
serverRelativePath = relative(baseDirectory, fileURLToPath(outputPaths["server"]));
}
return {
bundleYamlPath: resolve(outputBundleDir, "bundle.yaml"),
outputDirectory: outputBundleDir,
baseDirectory,
outputBaseDirectory: resolve(outputBundleDir, "dist"),
serverFilePath: resolve(outputBundleDir, "dist", serverRelativePath, "server.mjs"),
browserDirectory: resolve(outputBundleDir, "dist", browserRelativePath),
};
const options = await architectHost.getOptionsForTarget(buildTarget);
if (!options)
throw new Error("Not able to find options for build target.");
return options;
}
// Run build command
export const build = (cwd = process.cwd()) => new Promise((resolve, reject) => {
// enable JSON build logs for application builder
process.env.NG_BUILD_LOGS_JSON = "1";
const childProcess = spawn("npm", ["run", "build"], {
cwd,
shell: true,
stdio: ["inherit", "pipe", "pipe"],
});
let outputPathOptions = {};
let manifest = {};
if (childProcess.stdout) {
childProcess.stdout.on("data", (data) => {
try {
if (data.toString().includes("outputPaths")) {
const parsedManifest = JSON.parse(data);
// validate if the manifest is of the expected form
manifest = buildManifestSchema.parse(parsedManifest);
if (manifest["errors"].length > 0) {
// errors when extracting manifest
manifest.errors.forEach((error) => {
logger.error(error);
});
}
if (manifest["warnings"].length > 0) {
// warnings when extracting manifest
manifest.warnings.forEach((warning) => {
logger.info(warning);
});
}
outputPathOptions = populateOutputBundleOptions(manifest["outputPaths"]);
}
}
catch (error) {
throw new Error("Build manifest is not of expected structure: " + error);
}
});
}
else {
throw new Error("Unable to locate build manifest with output paths.");
}
childProcess.on("exit", (code) => {
if (code === 0)
return resolve(outputPathOptions);
reject();
});
});
/*
Move the base output directory, which contains the server and browser bundle directory, and prerendered routes
as well as generating bundle.yaml.
*/
export async function generateOutputDirectory(cwd, outputPathOptions) {
await Promise.all([
move(outputPathOptions.baseDirectory, outputPathOptions.outputBaseDirectory, {
overwrite: true,
}),
generateBundleYaml(outputPathOptions, cwd),
]);
}
// Generate bundle.yaml
export async function generateBundleYaml(outputPathOptions, cwd) {
await writeFile(outputPathOptions.bundleYamlPath, yamlStringify({
headers: [],
redirects: [],
rewrites: [],
runCommand: `node ${normalize(relative(cwd, outputPathOptions.serverFilePath))}`,
neededDirs: [normalize(relative(cwd, outputPathOptions.outputDirectory))],
staticAssets: [normalize(relative(cwd, outputPathOptions.browserDirectory))],
}));
}
export const isMain = (meta) => {

@@ -43,0 +130,0 @@ if (!meta)

{
"name": "@apphosting/adapter-angular",
"version": "17.0.0-canary.a076bd8",
"version": "17.0.0-canary.cbdb6cb",
"main": "dist/index.js",

@@ -42,6 +42,5 @@ "description": "Experimental addon to the Firebase CLI to add web framework support",

"dependencies": {
"fs-extra": "*",
"yaml": "*",
"tslib": "*",
"@npmcli/run-script": "*"
"fs-extra": "^11.1.1",
"yaml": "^2.3.4",
"tslib": "^2.3.1"
},

@@ -48,0 +47,0 @@ "peerDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc