@travetto/manifest
Advanced tools
Comparing version 3.0.2 to 3.0.3
{ | ||
"name": "@travetto/manifest", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"description": "Support for project indexing, manifesting, along with file watching", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
<!-- This file was generated by @travetto/doc and should not be modified directly --> | ||
<!-- Please modify https://github.com/travetto/travetto/tree/main/module/manifest/DOC.ts and execute "npx trv doc" to rebuild --> | ||
<!-- Please modify https://github.com/travetto/travetto/tree/main/module/manifest/DOC.tsx and execute "npx trv doc" to rebuild --> | ||
# Manifest | ||
## Support for project indexing, manifesting, along with file watching | ||
@@ -16,4 +17,2 @@ | ||
This module aims to be the boundary between the file system and the code. The module provides: | ||
* Project Manifesting | ||
@@ -30,3 +29,3 @@ * Manifest Delta | ||
### 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). | ||
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). | ||
@@ -40,7 +39,6 @@ ### Runtime Knowledge | ||
## 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. | ||
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 [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) using the `getFunctionMetadata` method. | ||
**Code: Test Class** | ||
@@ -84,3 +82,2 @@ ```typescript | ||
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 | ||
@@ -175,3 +172,3 @@ * Iterating over every test file | ||
"doc": [ | ||
[ "DOC.ts", "ts", 1868155200000, "doc" ], | ||
[ "DOC.tsx", "ts", 1868155200000, "doc" ], | ||
[ "doc/lookup.ts", "ts", 1868155200000, "doc" ], | ||
@@ -222,12 +219,11 @@ [ "doc/test-class.ts", "ts", 1868155200000, "doc" ] | ||
### General Context | ||
The general context describes the project-space and any important information for how to build/execute the code. | ||
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](https://nodejs.org/api/modules.html) or [module](https://nodejs.org/api/esm.html) | ||
* The main module to execute. **Note**: This primarily pertains to mono-repo support when there are multiple modules in the project | ||
* Module Type: `commonjs`([CommonJS](https://nodejs.org/api/modules.html)) or `module`([Ecmascript Module](https://nodejs.org/api/esm.html)) | ||
* 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. **Note**: This is determined by using the 'workspaces' field in your [object Object] | ||
* The location where all compiled code will be stored. Defaults to: `.trv_output`. **Note**: Can be overridden in your [object Object] in 'travetto.outputFolder' | ||
* Whether or not the project is a mono-repo. (*This is determined by using the 'workspaces' field in your [Package JSON](https://docs.npmjs.com/cli/v9/configuring-npm/package-json)*) | ||
* The location where all compiled code will be stored. Defaults to: `.trv_output`. (*Can be overridden in your [Package JSON](https://docs.npmjs.com/cli/v9/configuring-npm/package-json) in 'travetto.outputFolder'*) | ||
* The location where the intermediate compiler will be created. Defaults to: `.trv_compiler` | ||
@@ -238,6 +234,3 @@ * The location where tooling will be able to write to. Defaults to: `.trv_output` | ||
### Modules | ||
The modules represent all of the [Travetto](https://travetto.dev)-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 modules represent all of the [Travetto](https://travetto.dev)-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 | ||
@@ -255,3 +248,2 @@ * The dependency version | ||
The module files are a simple categorization of files into a predetermined set of folders: | ||
* $root - All uncategorized files at the module root | ||
@@ -270,3 +262,2 @@ * $index - __index__.ts, index.ts files at the root of the project | ||
* 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: | ||
@@ -273,0 +264,0 @@ |
@@ -39,11 +39,14 @@ import fs from 'fs/promises'; | ||
(await ManifestModuleUtil.scanFolder(root, left.main)) | ||
.filter(x => (x.endsWith('.ts') || x.endsWith('.js') || x.endsWith('package.json'))) | ||
.map(x => x.replace(`${root}/`, '').replace(/[.][tj]s$/, '')) | ||
.filter(x => { | ||
const type = ManifestModuleUtil.getFileType(x); | ||
return type === 'ts' || type === 'typings' || type === 'js' || type === 'package-json'; | ||
}) | ||
.map(x => ManifestModuleUtil.sourceToBlankExt(x.replace(`${root}/`, ''))) | ||
); | ||
for (const el of Object.keys(left.files)) { | ||
const output = `${outputFolder}/${left.outputFolder}/${el.replace(/[.]ts$/, '.js')}`; | ||
const output = ManifestModuleUtil.sourceToOutputExt(`${outputFolder}/${left.outputFolder}/${el}`); | ||
const [, , leftTs] = left.files[el]; | ||
const stat = await fs.stat(output).catch(() => { }); | ||
right.delete(el.replace(/[.][tj]s$/, '')); | ||
right.delete(ManifestModuleUtil.sourceToBlankExt(el)); | ||
@@ -50,0 +53,0 @@ if (!stat) { |
@@ -0,1 +1,2 @@ | ||
import { ManifestModuleUtil } from './module'; | ||
import { path } from './path'; | ||
@@ -81,9 +82,10 @@ | ||
return files.map(([f, type, ts, profile = 'std']) => { | ||
const isSource = type === 'ts' || type === 'js'; | ||
const sourceFile = path.resolve(this.#manifest.workspacePath, m.sourceFolder, f); | ||
const js = (type === 'ts' ? f.replace(/[.]ts$/, '.js') : f); | ||
const js = isSource ? ManifestModuleUtil.sourceToOutputExt(f) : f; | ||
const outputFile = this.#resolveOutput(m.outputFolder, js); | ||
const modImport = `${m.name}/${js}`; | ||
let id = modImport.replace(`${m.name}/`, _ => _.replace(/[/]$/, ':')); | ||
if (type === 'ts' || type === 'js') { | ||
id = id.replace(/[.]js$/, ''); | ||
if (isSource) { | ||
id = ManifestModuleUtil.sourceToBlankExt(id); | ||
} | ||
@@ -121,3 +123,2 @@ | ||
this.#importToEntry.set(entry.import.replace(/[.]js$/, ''), entry); | ||
this.#importToEntry.set(entry.import.replace(/[.]js$/, '.ts'), entry); | ||
} | ||
@@ -226,3 +227,3 @@ } | ||
resolveFileImport(name: string): string { | ||
return this.#importToEntry.get(name)?.outputFile ?? name; | ||
return this.getFromImport(name)?.outputFile ?? name; | ||
} | ||
@@ -243,2 +244,4 @@ | ||
getFromImport(imp: string): IndexedFile | undefined { | ||
// Strip ext | ||
imp = ManifestModuleUtil.sourceToBlankExt(imp); | ||
return this.#importToEntry.get(imp); | ||
@@ -245,0 +248,0 @@ } |
@@ -18,13 +18,11 @@ import fs from 'fs/promises'; | ||
'.ts': 'ts', | ||
'.tsx': 'ts', | ||
'.md': 'md' | ||
}; | ||
const INDEX_FILES = new Set([ | ||
'index.ts', | ||
'index.js', | ||
'__index__.ts', | ||
'__index__.js', | ||
'__index.ts', | ||
'__index.js' | ||
]); | ||
const INDEX_FILES = new Set( | ||
['__index__', '__index', 'index', 'jsx-runtime'].flatMap(f => | ||
['ts', 'tsx', 'js'].map(ext => `${f}.${ext}`) | ||
) | ||
); | ||
@@ -40,2 +38,9 @@ export class ManifestModuleUtil { | ||
/** | ||
* Replace a source file's extension with a given value | ||
*/ | ||
static #sourceToExtension(inputFile: string, ext: string): string { | ||
return inputFile.replace(/[.][tj]sx?$/, ext); | ||
} | ||
/** | ||
* Simple file scanning | ||
@@ -98,3 +103,3 @@ */ | ||
static getFileType(moduleFile: string): ManifestModuleFileType { | ||
if (moduleFile === 'package.json') { | ||
if (moduleFile.endsWith('package.json')) { | ||
return 'package-json'; | ||
@@ -123,3 +128,3 @@ } else if ( | ||
return 'test'; | ||
} else if (moduleFile.startsWith('doc/') || moduleFile === 'DOC.ts') { | ||
} else if (moduleFile.startsWith('doc/') || /^DOC[.]tsx?$/.test(moduleFile)) { | ||
return 'doc'; | ||
@@ -156,3 +161,3 @@ } else { | ||
} | ||
} else if (moduleFile === 'DOC.ts') { | ||
} else if (/^DOC[.]tsx?$/.test(moduleFile)) { | ||
return 'doc'; | ||
@@ -218,2 +223,16 @@ } else if (INDEX_FILES.has(moduleFile)) { | ||
} | ||
/** | ||
* Get the output file name for a given input | ||
*/ | ||
static sourceToOutputExt(inputFile: string): string { | ||
return this.#sourceToExtension(inputFile, '.js'); | ||
} | ||
/** | ||
* Get the file without an extension | ||
*/ | ||
static sourceToBlankExt(inputFile: string): string { | ||
return this.#sourceToExtension(inputFile, ''); | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71633
1604
265