@travetto/manifest
Advanced tools
Comparing version 3.1.0-rc.0 to 3.1.0-rc.1
@@ -84,2 +84,3 @@ // @ts-check | ||
const workspacePath = path.resolve(await $getWorkspaceRoot(folder)); | ||
const req = createRequire(`${workspacePath}/node_modules`); | ||
@@ -92,3 +93,2 @@ // If manifest specified via env var, and is a package name | ||
} | ||
const req = createRequire(`${workspacePath}/node_modules`); | ||
try { | ||
@@ -107,3 +107,3 @@ folder = path.dirname(req.resolve(`${process.env.TRV_MODULE}/package.json`)); | ||
const mainPath = await $getModuleRoot(path.resolve(folder ?? '.')); | ||
const { name: mainModule, workspaces, travetto } = (await $getPkg(mainPath)); | ||
const { name: mainModule, workspaces, travetto, version, description } = (await $getPkg(mainPath)); | ||
const monoRepo = workspacePath !== mainPath || !!workspaces; | ||
@@ -117,2 +117,4 @@ const outputFolder = travetto?.outputFolder ?? '.trv_output'; | ||
const { version: frameworkVersion } = JSON.parse(await fs.readFile(req.resolve('@travetto/manifest/package.json'), 'utf8')); | ||
const res = { | ||
@@ -127,5 +129,8 @@ moduleType, | ||
compilerFolder: '.trv_compiler', | ||
packageManager | ||
packageManager, | ||
version, | ||
description, | ||
frameworkVersion | ||
}; | ||
return res; | ||
} |
{ | ||
"name": "@travetto/manifest", | ||
"version": "3.1.0-rc.0", | ||
"version": "3.1.0-rc.1", | ||
"description": "Support for project indexing, manifesting, along with file watching", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -39,3 +39,3 @@ <!-- This file was generated by @travetto/doc and should not be modified directly --> | ||
`Ⲑid` is used heavily throughout the framework for determining which classes are owned by the framework, and being able to lookup the needed data from the [RootIndex](https://github.com/travetto/travetto/tree/main/module/manifest/src/root-index.ts#L12) using the `getFunctionMetadata` method. | ||
`Ⲑid` is used heavily throughout the framework for determining which classes are owned by the framework, and being able to lookup the needed data from the [RootIndex](https://github.com/travetto/travetto/tree/main/module/manifest/src/root-index.ts#L11) using the `getFunctionMetadata` method. | ||
@@ -157,2 +157,5 @@ **Code: Test Class** | ||
"packageManager": "npm", | ||
"version": "3.1.0-rc.0", | ||
"description": "Support for project indexing, manifesting, along with file watching", | ||
"frameworkVersion": "3.1.0-rc.0", | ||
"modules": { | ||
@@ -159,0 +162,0 @@ "@travetto/manifest": { |
@@ -6,9 +6,11 @@ import { readFileSync } from 'fs'; | ||
import { ManifestContext, Package, PackageDigest, PackageRel, PackageVisitor, PackageVisitReq, PackageWorkspaceEntry } from './types'; | ||
import { ManifestContext, Package, PackageRel, PackageVisitor, PackageVisitReq, PackageWorkspaceEntry } from './types'; | ||
import { path } from './path'; | ||
/** | ||
* Utilities for querying, traversing and reading package.json files. | ||
*/ | ||
export class PackageUtil { | ||
static #req = createRequire(path.resolve('node_modules')); | ||
static #framework: Package; | ||
static #cache: Record<string, Package> = {}; | ||
@@ -119,14 +121,2 @@ static #workspaces: Record<string, PackageWorkspaceEntry[]> = {}; | ||
/** | ||
* Write package | ||
*/ | ||
static async writePackageIfChanged(modulePath: string, pkg: Package): Promise<void> { | ||
const final = JSON.stringify(pkg, null, 2); | ||
const target = path.resolve(modulePath, 'package.json'); | ||
const current = (await fs.readFile(target, 'utf8').catch(() => '')).trim(); | ||
if (final !== current) { | ||
await fs.writeFile(target, `${final}\n`, 'utf8'); | ||
} | ||
} | ||
/** | ||
* Visit packages with ability to track duplicates | ||
@@ -170,17 +160,2 @@ */ | ||
/** | ||
* Get version of manifest package | ||
*/ | ||
static getFrameworkVersion(): string { | ||
return (this.#framework ??= this.importPackage('@travetto/manifest')).version; | ||
} | ||
/** | ||
* Produce simple digest of | ||
*/ | ||
static digest(pkg: Package): PackageDigest { | ||
const { main, name, author, license, version } = pkg; | ||
return { name, main, author, license, version, framework: this.getFrameworkVersion() }; | ||
} | ||
/** | ||
* Find workspace values from rootPath | ||
@@ -216,32 +191,2 @@ */ | ||
} | ||
/** | ||
* Sync versions across a series of folders | ||
*/ | ||
static async syncVersions(folders: string[], versionMapping: Record<string, string> = {}): Promise<void> { | ||
const packages = folders.map(folder => { | ||
const pkg = this.readPackage(folder, true); | ||
versionMapping[pkg.name] = `^${pkg.version}`; | ||
return { folder, pkg }; | ||
}); | ||
for (const { pkg } of packages) { | ||
for (const group of [ | ||
pkg.dependencies ?? {}, | ||
pkg.devDependencies ?? {}, | ||
pkg.optionalDependencies ?? {}, | ||
pkg.peerDependencies ?? {} | ||
]) { | ||
for (const [mod, ver] of Object.entries(versionMapping)) { | ||
if (mod in group && !/^[*]|(file:.*)$/.test(group[mod])) { | ||
group[mod] = ver; | ||
} | ||
} | ||
} | ||
} | ||
for (const { folder, pkg } of packages) { | ||
await this.writePackageIfChanged(folder, pkg); | ||
} | ||
} | ||
} |
import { path } from './path'; | ||
import { IndexedModule, ManifestIndex } from './manifest-index'; | ||
import { FunctionMetadata, Package, PackageDigest } from './types'; | ||
import { PackageUtil } from './package'; | ||
import { FunctionMetadata, ManifestContext, Package } from './types'; | ||
@@ -14,3 +13,2 @@ const METADATA = Symbol.for('@travetto/manifest:metadata'); | ||
#config: Package | undefined; | ||
#metadata = new Map<string, FunctionMetadata>(); | ||
@@ -24,3 +22,2 @@ | ||
this.init(`${this.outputRoot}/node_modules/${module}`); | ||
this.#config = undefined; | ||
} | ||
@@ -54,30 +51,26 @@ | ||
/** | ||
* Get main module name | ||
*/ | ||
get mainModuleName(): string { | ||
return this.manifest.mainModule; | ||
} | ||
/** | ||
* Get main module for manifest | ||
*/ | ||
get mainModule(): IndexedModule { | ||
return this.getModule(this.mainPackage.name)!; | ||
return this.getModule(this.mainModuleName)!; | ||
} | ||
/** | ||
* Get main package for manifest | ||
* Digest manifest | ||
*/ | ||
get mainPackage(): Package { | ||
if (!this.#config) { | ||
const { outputPath } = this.getModule(this.manifest.mainModule)!; | ||
this.#config = { | ||
...{ | ||
name: 'untitled', | ||
description: 'A Travetto application', | ||
version: '0.0.0', | ||
}, | ||
...PackageUtil.readPackage(outputPath) | ||
}; | ||
} | ||
return this.#config; | ||
manifestDigest(): Pick<ManifestContext, 'mainModule' | 'frameworkVersion' | 'version'> { | ||
return { | ||
mainModule: this.manifest.mainModule, | ||
frameworkVersion: this.manifest.frameworkVersion, | ||
version: this.manifest.version, | ||
}; | ||
} | ||
mainDigest(): PackageDigest { | ||
return PackageUtil.digest(this.mainPackage); | ||
} | ||
/** | ||
@@ -84,0 +77,0 @@ * Get source file from import location |
@@ -38,2 +38,5 @@ export type ManifestModuleFileType = 'typings' | 'ts' | 'js' | 'json' | 'package-json' | 'unknown' | 'fixture' | 'md'; | ||
packageManager: 'yarn' | 'npm'; | ||
frameworkVersion: string; | ||
description: string; | ||
version: string; | ||
}; | ||
@@ -90,5 +93,2 @@ | ||
export type PackageDigestField = 'name' | 'main' | 'author' | 'license' | 'version'; | ||
export type PackageDigest = Pick<Package, PackageDigestField> & { framework: string }; | ||
type OrProm<T> = T | Promise<T>; | ||
@@ -95,0 +95,0 @@ |
272
71926
1614