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

@travetto/compiler

Package Overview
Dependencies
Maintainers
1
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 0.0.48 to 0.1.1

7

package.json

@@ -7,7 +7,6 @@ {

"dependencies": {
"@travetto/base": "^0.0.162",
"@travetto/base": "^0.1.1",
"@types/source-map-support": "^0.4.1",
"source-map-support": "^0.5.6",
"string-hash": "^1.1.3",
"tslib": "^1.9.2"
"string-hash": "^1.1.3"
},

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

"scripts": {},
"version": "0.0.48"
"version": "0.1.1"
}
import * as ts from 'typescript';
import { EventEmitter } from 'events';
import { AppInfo, AppEnv } from '@travetto/base';
import { AppInfo, Env, AppCache } from '@travetto/base';
import { TransformerManager } from './transformers';

@@ -26,3 +26,3 @@ import { CompilerUtil } from './util';

constructor(public cwd: string = AppEnv.cwd) {
constructor(public cwd: string = Env.cwd) {

@@ -120,7 +120,7 @@ const exclude = [/\.d\.ts$/]; // Definition files

unload(fileName: string) {
unload(fileName: string, unlink = true) {
console.trace('Unloading', fileName);
if (this.sourceManager.has(fileName)) {
this.sourceManager.unload(fileName);
this.sourceManager.unload(fileName, unlink);
}

@@ -127,0 +127,0 @@

import { RetargettingHandler } from './proxy';
import { AppEnv } from '@travetto/base';
import { Env } from '@travetto/base';
import { CompilerUtil } from './util';

@@ -19,8 +19,7 @@

load(request: string, parent: string) {
let mod;
try {
mod = originalLoader.apply(null, arguments);
mod = originalLoader.apply(null, [request, parent]);
} catch (e) {
if (!AppEnv.prod) { // If attempting to load an optional require
if (!Env.prod) { // If attempting to load an optional require
const p = Module._resolveFilename(request, parent);

@@ -38,3 +37,3 @@ console.error(`Unable to import ${p}, stubbing out`, e);

// Proxy modules, if in watch mode for non node_modules paths
if (AppEnv.watch) {
if (Env.watch) {
const p = Module._resolveFilename(request, parent);

@@ -64,3 +63,3 @@ if (p.includes(this.cwd) && !p.includes(CompilerUtil.LIBRARY_PATH)) {

} catch (e) {
if (AppEnv.watch) { // If attempting to load an optional require
if (Env.watch) { // If attempting to load an optional require
console.error(`Unable to import ${name}, stubbing out`, e);

@@ -67,0 +66,0 @@ (m as any)._compile(CompilerUtil.EMPTY_MODULE, jsf);

@@ -1,7 +0,4 @@

import { Watcher, Entry, AppEnv, Handler, findAppFiles } from '@travetto/base';
import { CompilerUtil } from './util';
import { Watcher, ScanEntry, Env, ScanHandler, ScanApp } from '@travetto/base';
import * as path from 'path';
const EMPTY = (...args: any[]): any => { };
export interface Listener {

@@ -18,6 +15,6 @@ added(name: string): any;

constructor(private cwd: string, private listener: Listener, private excludeFiles: RegExp[], private watch: boolean = AppEnv.watch) {
constructor(private cwd: string, private listener: Listener, private excludeFiles: RegExp[], private watch: boolean = Env.watch) {
}
private watcherListener({ event, entry }: { event: string, entry: Entry }) {
private watcherListener({ event, entry }: { event: string, entry: ScanEntry }) {
if (!this.validFile(entry.file)) {

@@ -47,3 +44,3 @@ return;

private buildWatcher(cwd: string, handlers: Handler[]) {
private buildWatcher(cwd: string, handlers: ScanHandler[]) {
const watcher = new Watcher({

@@ -62,3 +59,3 @@ interval: 250,

init() {
const rootFiles = findAppFiles('.ts', x => /(^src\/)|\/src\/|\/index.ts$/.test(x) && this.validFile(x))
const rootFiles = ScanApp.findFiles('.ts', x => /(^src\/)|\/src\/|\/index.ts$/.test(x) && this.validFile(x))
.filter(x => !(x.file in require.cache)) // Pre-loaded items are fundamental and non-reloadable

@@ -65,0 +62,0 @@ .map(x => x.file);

import * as fs from 'fs';
import * as ts from 'typescript';
import * as sourcemap from 'source-map-support';
import { AppEnv } from '@travetto/base';
import { CompilerUtil } from './util';
import { Env } from '@travetto/base';
import { Cache } from '@travetto/base/src/cache';
import { CompilerUtil } from './util';
const stringHash = require('string-hash');

@@ -14,3 +16,3 @@

private hashes = new Map<string, number>();
private cache = new Cache(AppEnv.cwd);
private cache = new Cache(Env.cwd);

@@ -23,3 +25,3 @@ constructor(private config: { cache?: boolean } = {}) {

sourcemap.install({
emptyCacheBetweenOperations: AppEnv.test || AppEnv.debug,
emptyCacheBetweenOperations: Env.test || Env.debug,
retrieveFile: (p: string) => this.contents.get(p.replace('.js', '.ts'))!,

@@ -38,3 +40,3 @@ retrieveSourceMap: (source: string) => this.sourceMaps.get(source.replace('.js', '.ts'))!

if (AppEnv.watch && this.hashes.has(fileName)) {
if (Env.watch && this.hashes.has(fileName)) {
// Let's see if they are really different

@@ -53,3 +55,3 @@ hash = stringHash(content);

if (!AppEnv.prod) { // If attempting to load an optional require
if (!Env.prod) { // If attempting to load an optional require
console.error(`Unable to import ${fileName}, stubbing out`);

@@ -63,3 +65,3 @@ this.set(fileName, CompilerUtil.EMPTY_MODULE);

if (AppEnv.watch) {
if (Env.watch) {
this.hashes.set(fileName, hash);

@@ -125,9 +127,9 @@ }

deleteCached(file: string) {
deleteCached(file: string, unlink: boolean = true) {
this.cache.removeEntry(file);
}
unload(name: string) {
unload(name: string, unlink: boolean = true) {
if (this.hasCached(name)) {
this.deleteCached(name);
this.deleteCached(name, unlink);
}

@@ -134,0 +136,0 @@

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

imports: Map<string, Import>;
ids: Map<String, number>;
}

@@ -17,2 +18,8 @@

static generateUniqueId(name: string, state: State) {
const val = (state.ids.get(name) || 0) + 1;
state.ids.set(name, val);
return ts.createIdentifier(`${name}_${val}`);
}
static getDecoratorIdent(d: ts.Decorator): ts.Identifier {

@@ -60,13 +67,13 @@ if (ts.isCallExpression(d.expression)) {

);
imptStmt.parent = file;
return imptStmt;
});
file.statements = ts.createNodeArray([
const out = ts.updateSourceFileNode(file, ts.createNodeArray([
...importStmts,
...file.statements
]);
]),
file.isDeclarationFile, file.referencedFiles,
file.typeReferenceDirectives, file.hasNoDefaultLib);
return file;
return out;
}

@@ -141,2 +148,3 @@

(file: ts.SourceFile) => {
const state = init(file, context) as T;

@@ -147,2 +155,3 @@ const pth = require.resolve(file.fileName);

state.newImports = [];
state.ids = new Map();
state.imports = new Map();

@@ -152,5 +161,3 @@

if (ts.isImportDeclaration(stmt) && ts.isStringLiteral(stmt.moduleSpecifier)) {
let path = '';
stmt.importClause!;
path = require.resolve(stmt.moduleSpecifier.text
const path = require.resolve(stmt.moduleSpecifier.text
.replace(/^\.\./, dirname(dirname(state.path)))

@@ -173,6 +180,6 @@ .replace(/^\.\//, `${dirname(state.path)}/`));

const ret = visitor(context, file, state);
let ret = visitor(context, file, state);
if (state.newImports.length) {
this.addImport(ret, state.newImports);
ret = this.addImport(ret, state.newImports);
}

@@ -201,3 +208,3 @@

if (state.imports.has(importName)) {
const importIdent = ts.createUniqueName(`import_${importName}`);
const importIdent = this.generateUniqueId(`import_${importName}`, state);

@@ -216,3 +223,3 @@ state.newImports.push({

if (state.imports.has(nodeName)) {
const importName = ts.createUniqueName(`import_${nodeName}`);
const importName = this.generateUniqueId(`import_${nodeName}`, state);

@@ -219,0 +226,0 @@ state.newImports.push({

import { CustomTransformers } from 'typescript';
import { requireAppFiles, findAppFiles } from '@travetto/base';
import { ScanApp } from '@travetto/base';

@@ -14,3 +14,3 @@ export class TransformerManager {

for (const trns of requireAppFiles('.ts', x => /transformer[.].*[.]ts$/.test(x))) {
for (const trns of ScanApp.requireFiles('.ts', x => /transformer[.].*[.]ts$/.test(x))) {
for (const key of Object.keys(trns)) {

@@ -17,0 +17,0 @@ const item = trns[key];

import * as ts from 'typescript';
import { AppEnv } from '@travetto/base';
import { Env } from '@travetto/base';

@@ -19,3 +19,3 @@ export class CompilerUtil {

out.options.importHelpers = true;
out.options.noEmitOnError = AppEnv.prod;
out.options.noEmitOnError = Env.prod;
out.options.moduleResolution = ts.ModuleResolutionKind.NodeJs;

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

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