Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@travetto/manifest

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

@travetto/manifest - npm Package Compare versions

Comparing version 4.0.0-rc.4 to 4.0.0-rc.5

2

package.json
{
"name": "@travetto/manifest",
"version": "4.0.0-rc.4",
"version": "4.0.0-rc.5",
"description": "Support for project indexing, manifesting, along with file watching",

@@ -5,0 +5,0 @@ "keywords": [

@@ -26,4 +26,5 @@ import { PackageUtil } from './package';

constructor(public ctx: ManifestContext) {
this.#mainSourcePath = path.resolve(this.ctx.workspace.path, this.ctx.main.folder);
static async visit(ctx: ManifestContext): Promise<Iterable<PackageModule>> {
const visitor = new PackageModuleVisitor(ctx, Object.fromEntries((await PackageUtil.resolveWorkspaces(ctx)).map(x => [x.name, x.path])));
return visitor.visit();
}

@@ -33,13 +34,45 @@

#cache: Record<string, PackageModule> = {};
#workspaceModules: Map<string, string>;
#workspaceModules: Record<string, string>;
#ctx: ManifestContext;
constructor(ctx: ManifestContext, workspaceModules: Record<string, string>) {
this.#mainSourcePath = path.resolve(ctx.workspace.path, ctx.main.folder);
this.#ctx = ctx;
this.#workspaceModules = workspaceModules;
}
/**
* Build a package module
*/
#create(sourcePath: string, { main, workspace, prod = false, roleRoot = false, parent }: CreateOpts = {}): Req {
const pkg = PackageUtil.readPackage(sourcePath);
const value = this.#cache[sourcePath] ??= {
main,
prod,
name: pkg.name,
version: pkg.version,
workspace: workspace ?? (pkg.name in this.#workspaceModules),
internal: pkg.private === true,
sourceFolder: sourcePath === this.#ctx.workspace.path ? '' : sourcePath.replace(`${this.#ctx.workspace.path}/`, ''),
outputFolder: `node_modules/${pkg.name}`,
state: {
childSet: new Set(), parentSet: new Set(), roleSet: new Set(), roleRoot,
travetto: pkg.travetto, prodDeps: new Set(Object.keys(pkg.dependencies ?? {}))
}
};
const deps: PackageDepType[] = ['dependencies', ...(value.main ? ['devDependencies'] as const : [])];
const children = Object.fromEntries(deps.flatMap(x => Object.entries(pkg[x] ?? {})));
return { pkg, value, children, parent };
}
/**
* Get monorepo root includes
*/
#getMonoRootIncludes(parent: Req): Req[] {
if (!(this.ctx.workspace.mono && !this.ctx.main.folder)) { // If not mono root, bail
if (!(this.#ctx.workspace.mono && !this.#ctx.main.folder)) { // If not mono root, bail
return [];
}
return [...this.#workspaceModules.values()]
return Object.values(this.#workspaceModules)
.map(loc => this.#create(loc, { main: true, workspace: true, roleRoot: true, parent: parent.value }));

@@ -52,7 +85,7 @@ }

#getIncludes(parent: Req): Req[] {
if (this.ctx.workspace.mono && !this.ctx.main.folder) { // If mono and not at mono root, bail
if (this.#ctx.workspace.mono && !this.#ctx.main.folder) { // If mono and not at mono root, bail
return [];
}
const root = PackageUtil.readPackage(this.ctx.workspace.path);
const root = PackageUtil.readPackage(this.#ctx.workspace.path);
if (root.travetto?.build?.includes) {

@@ -63,3 +96,3 @@ return Object.entries(root.travetto.build.includes).map(([name, type]) =>

} else {
return [...this.#workspaceModules.values()]
return Object.values(this.#workspaceModules)
.filter((loc) => PackageUtil.readPackage(loc).travetto?.workspaceInclude)

@@ -71,43 +104,2 @@ .map(loc => this.#create(loc, { workspace: true, parent: parent.value }));

/**
* Initialize visitor, and provide global dependencies
*/
async init(): Promise<Iterable<Req>> {
const mainReq = this.#create(this.#mainSourcePath, { main: true, workspace: true, roleRoot: true, prod: true });
this.#workspaceModules = new Map(
(await PackageUtil.resolveWorkspaces(this.ctx)).map(x => [x.name, x.path])
);
return [
mainReq,
...this.#getMonoRootIncludes(mainReq),
...this.#getIncludes(mainReq)
];
}
/**
* Build a package module
*/
#create(sourcePath: string, { main, workspace, prod = false, roleRoot = false, parent }: CreateOpts = {}): Req {
const pkg = PackageUtil.readPackage(sourcePath);
const value = this.#cache[sourcePath] ??= {
main,
prod,
name: pkg.name,
version: pkg.version,
workspace: workspace ?? this.#workspaceModules.has(pkg.name),
internal: pkg.private === true,
sourceFolder: sourcePath === this.ctx.workspace.path ? '' : sourcePath.replace(`${this.ctx.workspace.path}/`, ''),
outputFolder: `node_modules/${pkg.name}`,
state: {
childSet: new Set(), parentSet: new Set(), roleSet: new Set(), roleRoot,
travetto: pkg.travetto, prodDeps: new Set(Object.keys(pkg.dependencies ?? {}))
}
};
const deps: PackageDepType[] = ['dependencies', ...(value.main ? ['devDependencies'] as const : [])];
const children = Object.fromEntries(deps.flatMap(x => Object.entries(pkg[x] ?? {})));
return { pkg, value, children, parent };
}
/**
* Propagate prod, role information through graph

@@ -171,4 +163,10 @@ */

const seen = new Set<PackageModule>();
const queue = [...await this.init()];
const mainReq = this.#create(this.#mainSourcePath, { main: true, workspace: true, roleRoot: true, prod: true });
const queue = [
mainReq,
...this.#getMonoRootIncludes(mainReq),
...this.#getIncludes(mainReq)
];
while (queue.length) {

@@ -181,3 +179,3 @@ const { value: node, parent, children, pkg } = queue.shift()!; // Visit initial set first

// Track parentage
if (node.name !== this.ctx.main.name && parent) {
if (node.name !== this.#ctx.main.name && parent) {
node.state.parentSet.add(parent.name);

@@ -184,0 +182,0 @@ parent.state.childSet.add(node.name);

@@ -200,3 +200,3 @@ import fs from 'node:fs/promises';

static async produceModules(ctx: ManifestContext): Promise<Record<string, ManifestModule>> {
const pkgs = await new PackageModuleVisitor(ctx).visit();
const pkgs = await PackageModuleVisitor.visit(ctx);
const modules = await Promise.all([...pkgs].map(x => this.describeModule(ctx, x)));

@@ -203,0 +203,0 @@ return Object.fromEntries(modules.map(m => [m.name, m]));

@@ -119,5 +119,5 @@ import { path } from './path';

*/
static getModuleContext(ctx: ManifestContext, folder: string): ManifestContext {
static getModuleContext(ctx: ManifestContext, folder: string, ensureLatest = false): ManifestContext {
const modPath = path.resolve(ctx.workspace.path, folder);
const pkg = PackageUtil.readPackage(modPath);
const pkg = PackageUtil.readPackage(modPath, ensureLatest);

@@ -124,0 +124,0 @@ return {

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