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

@travetto/compiler

Package Overview
Dependencies
Maintainers
0
Versions
300
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@travetto/compiler - npm Package Compare versions

Comparing version 5.0.4 to 5.0.5

bin/manifest-context.mjs

29

bin/common.js

@@ -16,2 +16,5 @@ // @ts-check

const needsWriting = (/** @type {string} */ src, /** @type {string} */ dest) =>
!existsSync(dest) || getAge(statSync(dest)) < getAge(statSync(src));
const getTarget = (/** @type {Ctx} */ ctx, file = '') => ({

@@ -21,3 +24,3 @@ dest: modPath(ctx, '@travetto/compiler', file),

async writeIfStale(/** @type {(text:string)=>(string|Promise<string>)}*/ transform) {
if (!existsSync(this.dest) || getAge(statSync(this.dest)) < getAge(statSync(this.src))) {
if (needsWriting(this.src, this.dest)) {
const text = readFileSync(this.src, 'utf8');

@@ -43,13 +46,19 @@ mkdirSync(path.dirname(this.dest), { recursive: true });

// Load manifest without compiling, just stripping types away
// eslint-disable-next-line no-undef
const manifestJs = path.resolve(__dirname, 'manifest-context.mjs');
const loc = require.resolve('@travetto/manifest').replace(/__index__.*/, 'src/context.ts');
const src = readFileSync(loc, 'utf8')
// Remove type information
.replace(/\s*[|]\s+undefined/g, '')
.replace(/<([^>]|\n)+>/gsm, '')
.replace(/[?]?: (string|[A-Z][a-zA-Z]+)/g, '')
.replace(/^(import )?type .*$/gm, '');
// Compile if needed
if (needsWriting(loc, manifestJs)) {
const ts = (await import('typescript')).default;
const text = ts.transpile(readFileSync(loc, 'utf8'), {
target: ts.ScriptTarget.ES2022,
module: ts.ModuleKind.ESNext,
removeComments: true
}, manifestJs);
writeFileSync(manifestJs, text, 'utf8');
}
// Load module on demand
const { getManifestContext } = await import(`data:text/javascript;charset=utf-8,${encodeURIComponent(src)}`);
const { getManifestContext } = await import(manifestJs);

@@ -81,2 +90,3 @@ /** @type {Ctx} */

try {
/** @type {import('../support/entry.trvc')} */
const res = await import(target('support/entry.trvc.ts').dest);

@@ -90,2 +100,3 @@ return await res.main(ctx);

// eslint-disable-next-line no-undef
module.exports = { getEntry };
{
"name": "@travetto/compiler",
"version": "5.0.4",
"version": "5.0.5",
"description": "The compiler infrastructure for the Travetto framework",

@@ -36,8 +36,8 @@ "keywords": [

"@parcel/watcher": "^2.4.1",
"@travetto/manifest": "^5.0.3",
"@travetto/transformer": "^5.0.4",
"@travetto/manifest": "^5.0.4",
"@travetto/transformer": "^5.0.5",
"@types/node": "^22.5.1"
},
"peerDependencies": {
"@travetto/cli": "^5.0.4"
"@travetto/cli": "^5.0.5"
},

@@ -44,0 +44,0 @@ "peerDependenciesMeta": {

import ts from 'typescript';
import { path, ManifestModuleUtil, type ManifestModule, type ManifestRoot, ManifestIndex } from '@travetto/manifest';
import { path, ManifestModuleUtil, type ManifestModule, type ManifestRoot, ManifestIndex, ManifestModuleFolderType } from '@travetto/manifest';
import { TransformerManager } from '@travetto/transformer';

@@ -12,2 +12,5 @@

const TYPINGS_FOLDER_KEYS = new Set<ManifestModuleFolderType>(['$index', 'support', 'src']);
const TYPINGS_EXT_RE = /[.]d[.][cm]?ts([.]map)?$/;
export class CompilerState implements ts.CompilerHost {

@@ -22,2 +25,3 @@

#outputPath: string;
#typingsPath: string;
#sourceFiles = new Set<string>();

@@ -44,2 +48,16 @@ #sourceDirectory = new Map<string, string>();

#writeExternalTypings(location: string, text: string, bom: boolean): void {
let core = location.replace('.map', '');
if (!this.#outputToEntry.has(core)) {
core = core.replace('.d.ts', '.js');
}
const entry = this.#outputToEntry.get(core);
if (entry) {
const relative = this.#manifestIndex.getFromSource(entry.sourceFile)?.relativeFile;
if (relative && TYPINGS_FOLDER_KEYS.has(ManifestModuleUtil.getFolderKey(relative))) {
ts.sys.writeFile(location.replace(this.#outputPath, this.#typingsPath), text, bom);
}
}
}
async init(idx: ManifestIndex): Promise<this> {

@@ -49,4 +67,4 @@ this.#manifestIndex = idx;

this.#outputPath = path.resolve(this.#manifest.workspace.path, this.#manifest.build.outputFolder);
this.#typingsPath = path.resolve(this.#manifest.workspace.path, this.#manifest.build.typesFolder);
this.#compilerOptions = {

@@ -248,3 +266,8 @@ ...await TypescriptUtil.getCompilerOptions(this.#manifest),

}
const location = this.#tscOutputFileToOuptut.get(outputFile)! ?? outputFile;
const location = this.#tscOutputFileToOuptut.get(outputFile) ?? outputFile;
if (TYPINGS_EXT_RE.test(outputFile)) {
this.#writeExternalTypings(location, text, bom);
}
ts.sys.writeFile(location, text, bom);

@@ -251,0 +274,0 @@ }

@@ -18,3 +18,3 @@ // @trv-no-transform

const client = new CompilerClient(ctx, Log.scoped('client'));
const buildFolders = [ctx.build.outputFolder, ctx.build.compilerFolder];
const buildFolders = [ctx.build.outputFolder, ctx.build.compilerFolder, ctx.build.typesFolder];
Log.root = ctx.workspace.path;

@@ -21,0 +21,0 @@ Log.initLevel('error');

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