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

Support for project indexing, manifesting, along with file watching

  • 4.1.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Manifest

Support for project indexing, manifesting, along with file watching

Install: @travetto/manifest

npm install @travetto/manifest

# or

yarn add @travetto/manifest

This module aims to be the boundary between the file system and the code. The module provides:

  • Project Manifesting
  • Manifest Delta
  • Class and Function Metadata
  • Runtime Indexing
  • Path Normalization

Project Manifesting

The project manifest fulfills two main goals: Compile-time Support, and Runtime Knowledge of the project.

Compile-time Support

During the compilation process, the compiler needs to know every file that is eligible for compilation, when the file was last created/modified, and any specific patterns for interacting with a given file (e.g. transformers vs. testing code vs. support files that happen to share a common extension with code).

Runtime Knowledge

Additionally, once the code has been compiled (or even bundled after that), the executing process needs to know what files are available for loading, and any patterns necessary for knowing which files to load versus which ones to ignore. This allows for dynamic loading of modules/files without knowledge/access to the file system, and in a more performant manner.

Manifest Delta

During the compilation process, it is helpful to know how the output content differs from the manifest, which is produced from the source input. The ManifestDeltaUtil provides the functionality for a given manifest, and will produce a stream of changes grouped by module. This is the primary input into the Compiler's incremental behavior to know when a file has changed and needs to be recompiled.

Class and Function Metadata

For the framework to work properly, metadata needs to be collected about files, classes and functions to uniquely identify them, with support for detecting changes during live reloads. To achieve this, every class is decorated with an additional field of Ⲑid. Ⲑid represents a computed id that is tied to the file/class combination.

Ⲑ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 RuntimeIndex using the getFunctionMetadata method.

Code: Test Class

export class TestClass {
  async doStuff(): Promise<void> { }
}

Code: Test Class Compiled

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TestClass = void 0;
const tslib_1 = require("tslib");
const Ⲑ_runtime_1 = tslib_1.__importStar(require("@travetto/manifest/src/runtime.js"));
var ᚕf = "@travetto/manifest/doc/test-class.js";
class TestClass {
    static Ⲑinit = Ⲑ_runtime_1.RuntimeIndex.registerFunction(TestClass, ᚕf, { hash: 197152026, lines: [1, 3] }, { doStuff: { hash: 51337554, lines: [2, 2] } }, false, false);
    async doStuff() { }
}
exports.TestClass = TestClass;

Terminal: Index Lookup at Runtime

$ trv main ./doc/lookup.ts

{
  id: '@travetto/manifest:doc/test-class○TestClass',
  source: './doc/test-class.ts',
  hash: 197152026,
  lines: [ 1, 3 ],
  methods: { doStuff: { hash: 51337554, lines: [ 2, 2 ] } },
  abstract: false,
  synthetic: false
}

Module Indexing

Once the manifest is created, the application runtime can now read this manifest, which allows for influencing runtime behavior. The most common patterns include:

  • Loading all source files
  • Iterating over every test file
  • Finding all source folders for watching
  • Find all output folders for watching
  • Determining if a module is available or not
  • Resource scanning
  • Providing contextual information when provided a filename, import name, etc (e.g. logging, testing output)

Path Normalization

By default, all paths within the framework are assumed to be in a POSIX style, and all input paths are converted to the POSIX style. This works appropriately within a Unix and a Windows environment. This module offers up path as an equivalent to Node's http library. This allows for consistent behavior across all file-interactions, and also allows for easy analysis if Node's http library is ever imported.

Anatomy of a Manifest

Code: Manifest for @travetto/manifest

{
  "generated": 1868155200000,
  "workspace": {
    "name": "@travetto/mono-repo",
    "path": "<generated>",
    "mono": true,
    "manager": "npm",
    "type": "commonjs",
    "defaultEnv": "local"
  },
  "build": {
    "compilerFolder": ".trv/compiler",
    "compilerUrl": "http://127.0.0.1:26803",
    "compilerModuleFolder": "module/compiler",
    "outputFolder": ".trv/output",
    "toolFolder": ".trv/tool"
  },
  "main": {
    "name": "@travetto/manifest",
    "folder": "module/manifest",
    "version": "x.x.x",
    "description": "Support for project indexing, manifesting, along with file watching"
  },
  "modules": {
    "@travetto/manifest": {
      "main": true,
      "prod": true,
      "name": "@travetto/manifest",
      "version": "x.x.x",
      "workspace": true,
      "internal": false,
      "sourceFolder": "module/manifest",
      "outputFolder": "node_modules/@travetto/manifest",
      "roles": [ "std" ],
      "parents": [],
      "files": {
        "$root": [
          [ "DOC.html", "unknown", 1868155200000 ],
          [ "LICENSE", "unknown", 1868155200000 ],
          [ "README.md", "md", 1868155200000 ]
        ],
        "doc": [
          [ "DOC.tsx", "ts", 1868155200000, "doc" ],
          [ "doc/lookup.ts", "ts", 1868155200000, "doc" ],
          [ "doc/test-class.ts", "ts", 1868155200000, "doc" ]
        ],
        "$index": [
          [ "__index__.ts", "ts", 1868155200000 ]
        ],
        "$package": [
          [ "package.json", "package-json", 1868155200000 ]
        ],
        "test": [
          [ "test/path.ts", "ts", 1868155200000, "test" ],
          [ "test/runtime.ts", "ts", 1868155200000, "test" ]
        ],
        "test/fixtures": [
          [ "test/fixtures/simple.ts", "fixture", 1868155200000, "test" ]
        ],
        "$transformer": [
          [ "support/transformer.function-metadata.ts", "ts", 1868155200000, "compile" ]
        ],
        "src": [
          [ "src/delta.ts", "ts", 1868155200000 ],
          [ "src/dependencies.ts", "ts", 1868155200000 ],
          [ "src/file.ts", "ts", 1868155200000 ],
          [ "src/global.d.ts", "typings", 1868155200000 ],
          [ "src/manifest-index.ts", "ts", 1868155200000 ],
          [ "src/module.ts", "ts", 1868155200000 ],
          [ "src/package.ts", "ts", 1868155200000 ],
          [ "src/path.ts", "ts", 1868155200000 ],
          [ "src/runtime.ts", "ts", 1868155200000 ],
          [ "src/util.ts", "ts", 1868155200000 ],
          [ "src/types/common.ts", "ts", 1868155200000 ],
          [ "src/types/context.ts", "ts", 1868155200000 ],
          [ "src/types/manifest.ts", "ts", 1868155200000 ],
          [ "src/types/package.ts", "ts", 1868155200000 ]
        ],
        "bin": [
          [ "bin/context.d.ts", "typings", 1868155200000 ],
          [ "bin/context.js", "js", 1868155200000 ]
        ]
      }
    }
  }
}

General Context

The general context describes the project-space and any important information for how to build/execute the code.

The context contains:

  • A generated timestamp
  • Module Type: commonjs(CommonJS) or module(Ecmascript Module)
  • The main module to execute. (This primarily pertains to mono-repo support when there are multiple modules in the project)
  • The root path of the project/workspace
  • Whether or not the project is a mono-repo. (This is determined by using the 'workspaces' field in your Package JSON)
  • The location where all compiled code will be stored. Defaults to: .trv_output. (Can be overridden in your Package JSON in 'travetto.outputFolder')
  • The location where the intermediate compiler will be created. Defaults to: .trv_compiler
  • The location where tooling will be able to write to. Defaults to: .trv_output
  • Which package manager is in use Npm or Yarn
  • The main module version
  • The main module description
  • The framework version (based on @travetto/manifest)

Modules

The modules represent all of the Travetto-aware dependencies (including dev dependencies) used for compiling, testing and executing. A prod-only version is produced when packaging the final output. Each module contains:

  • The dependency npm name
  • The dependency version
  • A flag to determine if its a local module
  • A flag to determine if the module is public (could be published to npm)
  • The path to the source folder, relative to the workspace root
  • The path to the output folder, relative to the workspace output root
  • The list of all files
  • The profiles a module applies to. Values are std, test, compile, doc. Any empty value implies std
  • Parent modules that imported this module

Module Files

The module files are a simple categorization of files into a predetermined set of folders:

  • $root - All uncategorized files at the module root
  • $index - __index__.ts, index.ts files at the root of the project
  • $package - The Package JSON for the project
  • src - Code that should be automatically loaded at runtime. All .ts files under the src/ folder
  • test - Code that contains test files. All .ts files under the test/ folder
  • test/fixtures - Test resource files, pertains to the main module only. Located under test/fixtures/
  • resources - Packaged resource, meant to pertain to the main module only. Files, under resources/
  • support - All .ts files under the support/ folder
  • support/resources - Packaged resource files, meant to be included by other modules, under support/resources/
  • support/fixtures - Test resources meant to shared across modules. Under support/fixtures/
  • doc - Documentation files. DOC.tsx and All .ts/.tsx files under the doc/ folder
  • $transformer - All .ts files under the pattern support/transform*. These are used during compilation and never at runtime
  • bin - Entry point .js files. All .js files under the bin/ folder Within each file there is a pattern of either a 3 or 4 element array:

Code: Sample file

[
  "test/path.ts", // The module relative source path
  "ts", // The file type ts, js, package-json, typings, md, json, unknown
  1676751649201.1897, // Stat timestamp
  "test" // Optional profile
]

Keywords

FAQs

Package last updated on 21 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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