New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@travetto/compiler

Package Overview
Dependencies
Maintainers
1
Versions
303
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 0.5.8 to 0.6.0-rc.0

100

bin/travetto-cli-compile.js

@@ -1,68 +0,62 @@

//@ts-check
const fs = require('fs');
// @ts-check
// @ts-ignore
const { Util: { dependOn, program } } = require('@travetto/cli/src/util');
// @ts-ignore
const { FsUtil } = require('@travetto/cli/src/fs-util');
async function rewriteRuntimeDir(runtimeDir) {
const fs = require('fs');
const { FsUtil, AppCache } = require(`@travetto/base`);
module.exports = function () {
program
const files = fs.readdirSync(AppCache.cacheDir).map(x => FsUtil.resolveUnix(AppCache.cacheDir, x));
// Rewrite files to allow for presume different path
const FILES = `ScanApp.setFileEntries('.ts', [${files.map(x => `'${x.replace(/node_modules\/@travetto/g, '#')}'`).join(', ')}])`;
for (const file of files) {
let contents = fs.readFileSync(file).toString();
contents = contents.replace(/[/][/]#.*$/, '');
contents = contents.replace('ScanApp.cache = {}', x => `${x};\n${FILES}`);
contents = contents.replace(new RegExp(FsUtil.cwd, 'g'), runtimeDir || process.cwd());
fs.writeFileSync(file, contents);
}
}
function init() {
const { Util } = require('@travetto/cli/src/util');
return Util.program
.command('compile')
.option('-c, --clean', 'Indicates if the cache dir should be cleaned')
.option('-o, --output <output>', 'Output directory')
.option('-r, --runtime-dir [runtimeDir]', 'Expected path during runtime')
.option('-q, --quiet', 'Quiet operation')
.action(async (cmd) => {
dependOn('clean');
process.env.DEBUG = '0';
process.env.QUIET_INIT = '1';
process.env.TRV_CACHE_DIR = cmd.output || '-';
// @ts-ignore
if (cmd.clean) {
Util.dependOn('clean');
}
await require(`@travetto/base/bin/bootstrap`).run();
const { ScanApp } = require(`@travetto/base`);
const { AppCache } = require(`@travetto/base/src/cache`);
const { Compiler } = require('../src/compiler');
const count = Compiler.compileAll();
// TODO: Need to refine this
// Collect all files to force compilation
const files = ScanApp.findFiles('.ts', x =>
// Allow specific files
(
x.endsWith('index.ts') ||
(
(x.includes('src/') || x.includes('support/')) &&
!x.endsWith('.d.ts')
)
)
).filter(x => !x.file.includes('@travetto/test'));
// Require them
for (const f of files) {
require(f.file);
if (cmd.runtimeDir) {
await rewriteRuntimeDir(cmd.runtimeDir);
}
// Clear out cache if specified
if (cmd.output) {
try {
require('child_process').execSync(`rm -rf ${FsUtil.resolveNative(FsUtil.cwd, cmd.output)}`)
} catch (e) {
// Ignore
}
FsUtil.mkdirp(cmd.output);
if (!cmd.quiet) {
console.log(`${Util.colorize.success('Successfully')} wrote ${Util.colorize.output(count)} files to ${Util.colorize.path(cmd.output)}`);
}
});
}
// Find final destination
let outDir = FsUtil.resolveUnix(FsUtil.cwd, cmd.output || AppCache.cacheDir);
function complete(c) {
c.all.push('compile');
c.compile = {
'': ['--clean', '--quiet', '--runtime-dir', '--output']
}
}
const FILES = `ScanApp.setFileEntries('.ts', [${files.map(x => `'${x.module.replace(/node_modules\/@travetto/g, '#')}'`).join(', ')}])`;
// Rewrite files to allow for presume different path
for (const f of fs.readdirSync(AppCache.cacheDir)) {
const inp = FsUtil.resolveUnix(AppCache.cacheDir, f);
const out = FsUtil.resolveUnix(outDir, f);
let contents = fs.readFileSync(inp).toString();
contents = contents.replace(/[/][/]#.*$/, '');
contents = contents.replace('ScanApp.cache = {}', x => `${x};\n${FILES}`);
contents = contents.replace(new RegExp(FsUtil.cwd, 'g'), cmd.runtimeDir || process.cwd());
fs.writeFileSync(out, contents);
}
});
};
module.exports = { init, complete };
export * from './src/transform-util';
export * from './src/util';
export * from './src/proxy';
export * from './src/presence';
export * from './src/module';
export * from './src/transformers';
export * from './src/source';
export * from './src/compiler';

@@ -13,6 +13,5 @@ {

"dependencies": {
"@travetto/base": "^0.5.8",
"@travetto/base": "^0.6.0-rc.0",
"@types/source-map-support": "^0.4.1",
"source-map-support": "^0.5.9",
"string-hash": "^1.1.3"
"source-map-support": "^0.5.9"
},

@@ -44,3 +43,4 @@ "description": "Node-integration of Typescript Compiler with advanced functionality for collecting AST transformers, and detecting changes in classes and methods.",

},
"version": "0.5.8"
}
"version": "0.6.0-rc.0",
"gitHead": "0ed35f2a779cb9b93139a953d84817083ae0e7f5"
}
import { EventEmitter } from 'events';
import { AppInfo, Env, FsUtil } from '@travetto/base';
import { AppInfo, Env, FsUtil, ScanApp, AppCache } from '@travetto/base';

@@ -36,18 +36,19 @@ import { TransformerManager } from './transformers';

this.sourceManager = new SourceManager(this.cwd, {});
this.presenceManager = new FilePresenceManager(this.cwd, {
added: (name: string) => {
if (this.transpile(name)) {
this.events.emit('added', name);
this.presenceManager = new FilePresenceManager(this.cwd, Env.appRoots,
{
added: (name: string) => {
if (this.transpile(name)) {
this.events.emit('added', name);
}
},
changed: (name: string) => {
if (this.transpile(name, true)) {
this.events.emit('changed', name);
}
},
removed: (name: string) => {
this.unload(name);
this.events.emit('removed', name);
}
},
changed: (name: string) => {
if (this.transpile(name, true)) {
this.events.emit('changed', name);
}
},
removed: (name: string) => {
this.unload(name);
this.events.emit('removed', name);
}
}, exclude);
}, exclude);
}

@@ -93,6 +94,2 @@

if (Env.trace && !tsf.includes(CompilerUtil.LIBRARY_PATH)) {
console.trace(content);
}
try {

@@ -167,4 +164,15 @@ const ret = this.moduleManager.compile(m, jsf, content);

}
compileAll() {
let compiled = 0;
ScanApp.getStandardAppFiles().forEach(x => {
if (!AppCache.hasEntry(x)) {
compiled += 1;
require(x);
}
});
return compiled;
}
}
export const Compiler = new $Compiler(Env.cwd);

@@ -0,1 +1,3 @@

/// <reference types="node" />
import { Env } from '@travetto/base';

@@ -6,4 +8,2 @@

const Module = require('module') as typeof NodeJS.Module;
declare namespace NodeJS {

@@ -16,2 +16,4 @@ class Module {

const Module = require('module') as typeof NodeJS.Module;
const originalLoader = Module._load.bind(Module);

@@ -18,0 +20,0 @@

import * as path from 'path';
import { Watcher, ScanEntry, Env, ScanHandler, ScanApp, FsUtil } from '@travetto/base';
import { Watcher, ScanEntry, Env, ScanHandler, ScanApp, FsUtil, Shutdown } from '@travetto/base';

@@ -17,9 +17,24 @@ export interface Listener {

constructor(private cwd: string, private listener: Listener, private excludeFiles: RegExp[], private watch: boolean = Env.watch) {
this.watchSpaces.add('src');
if (Env.appRoot) {
this.watchSpaces.add(FsUtil.joinUnix(Env.appRoot, 'src'));
constructor(private cwd: string, private rootPaths: string[], private listener: Listener, private excludeFiles: RegExp[], private watch: boolean = Env.watch) {
if (!this.rootPaths.includes('.')) {
this.rootPaths.push('.');
}
for (const root of this.rootPaths) {
this.watchSpaces.add(FsUtil.joinUnix(root, 'src'));
}
if (Env.watch) {
Shutdown.onUnhandled(e => this.handleMissingModule(e), 0);
}
}
private handleMissingModule(err: Error) {
if (err && (err.message || '').includes('Cannot find module')) { // Handle module reloading
Env.error(err);
return true;
}
}
private watcherListener({ event, entry }: { event: string, entry: ScanEntry }) {

@@ -64,3 +79,3 @@ if (!this.validFile(entry.file)) {

init() {
const SRC_RE = new RegExp(`^(${Env.appRoot || '-'})?(\/src\/.*|index)$`);
const SRC_RE = FsUtil.appRootMatcher(this.rootPaths);

@@ -67,0 +82,0 @@ const rootFiles = ScanApp.findFiles('.ts', x => SRC_RE.test(x) && this.validFile(x)) // Only watch own files

import * as ts from 'typescript';
import * as sourcemap from 'source-map-support';
import { Env, AppError, FsUtil } from '@travetto/base';
import { FileCache } from '@travetto/base/src/cache';
import { FileCache, Env, AppError, FsUtil, Util } from '@travetto/base';
import { CompilerUtil } from './util';
const stringHash = require('string-hash');
export class SourceManager {

@@ -72,3 +69,3 @@ private sourceMaps = new Map<string, { url: string, map: string, content: string }>();

// Let's see if they are really different
hash = stringHash(content);
hash = Util.naiveHash(content);
if (hash === this.hashes.get(fileName)) {

@@ -75,0 +72,0 @@ console.trace(`Contents Unchanged: ${fileName}`);

import * as ts from 'typescript';
import { dirname, } from 'path';
import { AppInfo, Env, FsUtil } from '@travetto/base';
import { AppInfo, FsUtil, Util } from '@travetto/base';
const stringHash = require('string-hash');
export type Import = { path: string, ident: ts.Identifier };

@@ -205,4 +203,4 @@ export type DecList = ts.NodeArray<ts.Decorator>;

if (Env.frameworkDev) {
path = FsUtil.resolveFrameworkFile(path);
if (process.env.TRV_FRAMEWORK_DEV) {
path = FsUtil.resolveFrameworkDevFile(path);
}

@@ -292,3 +290,3 @@

if (!state.newImports.has(pth)) {
const ident = ts.createIdentifier(`i_${stringHash(pth)}`);
const ident = ts.createIdentifier(`i_${Util.naiveHash(pth)}`);
const imprt = {

@@ -295,0 +293,0 @@ path: pth,

@@ -20,2 +20,3 @@ import * as ts from 'typescript';

out.options.noEmitOnError = !Env.watch;
out.options.noErrorTruncation = true;
out.options.moduleResolution = ts.ModuleResolutionKind.NodeJs;

@@ -22,0 +23,0 @@

@@ -15,5 +15,4 @@ {

"importHelpers": true,
"rootDir": "src/",
"outDir": "build/"
}
}
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