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
305
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.6.0-rc.2 to 0.6.0-rc.3

6

package.json

@@ -13,3 +13,3 @@ {

"dependencies": {
"@travetto/base": "^0.6.0-rc.2",
"@travetto/base": "^0.6.0-rc.3",
"@types/source-map-support": "^0.4.1",

@@ -43,4 +43,4 @@ "source-map-support": "^0.5.9"

},
"version": "0.6.0-rc.2",
"gitHead": "c1c33c09858f017ce619c0961297e276dfa4c827"
"version": "0.6.0-rc.3",
"gitHead": "de4368934026c9c063d6c50357e1e27af44de822"
}

@@ -9,2 +9,3 @@ import { EventEmitter } from 'events';

import { FilePresenceManager } from './presence';
import { CompilerUtil } from './util';

@@ -75,12 +76,2 @@ type WatchEvent = 'required-after' | 'added' | 'changed' | 'removed';

handleLoadFailure(action: string, fileName: string, err: Error) {
if (Env.watch) {
console.trace(`Error in ${action} ${fileName}, removing`);
this.unload(fileName);
this.events.emit('removed', fileName);
} else {
throw err;
}
}
requireHandler(m: NodeModule, tsf: string) {

@@ -92,3 +83,3 @@ const jsf = tsf.replace(/\.ts$/, '.js');

if (isNew) {
this.presenceManager.addNewFile(tsf);
this.presenceManager.addNewFile(tsf); // Will transpile
}

@@ -104,6 +95,13 @@

return res;
} catch (err) {
this.handleLoadFailure('transpiling', tsf, err);
} catch (e) {
const file = tsf.replace(`${Env.cwd}/`, '');
if (tsf.includes('/extension/')) {
console.debug(`Ignoring load for ${file}:`, e.message.split(' from ')[0]);
} else if (Env.watch) {
console.error(`Stubbing out with error proxy due to error in compiling ${file}: `, e.message);
return this.moduleManager.compile(m, jsf, CompilerUtil.getErrorModuleProxySource(e.message));
} else {
throw e;
}
}
}

@@ -137,4 +135,5 @@

transpile(fileName: string, force = false) {
let changed: boolean = false;
try {
const changed = this.sourceManager.transpile(fileName, {
changed = this.sourceManager.transpile(fileName, {
fileName,

@@ -144,12 +143,17 @@ reportDiagnostics: true,

}, force);
if (changed && (force || this.presenceManager.isWatchedFileLoaded(fileName))) {
// If file is already loaded, mark for reload
this.markForReload(fileName);
} catch (err) {
if (Env.watch) { // Handle transpilation errors
this.sourceManager.set(fileName, CompilerUtil.getErrorModuleProxySource(err.message));
changed = this.sourceManager.transpile(fileName, { fileName }, true);
} else {
throw err;
}
}
return changed;
} catch (err) {
this.handleLoadFailure('transpiling', fileName, err);
if (changed && (force || this.presenceManager.isWatchedFileLoaded(fileName))) {
// If file is already loaded, mark for reload
this.markForReload(fileName);
}
return changed;
}

@@ -156,0 +160,0 @@

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

@@ -32,13 +32,10 @@ import { RetargettingHandler } from './proxy';

mod = originalLoader.apply(null, [request, parent]);
} catch (e) {
} catch (e) { // Failed due to compilation error
const p = Module._resolveFilename(request, parent);
if (!(Env.watch || p.endsWith('.ext.ts'))) {
// Marking file as being loaded, useful for the test framework
require.cache[p] = {};
if (!Env.watch || p.includes('/extension/')) {
throw e;
}
if (Env.watch) {
console.warn(`Unable to import ${p}, stubbing out`, e.message);
}
console.debug(`Unable to load ${p.replace(`${Env.cwd}/`, '')}: stubbing out with error proxy.`, e.message);
mod = CompilerUtil.getErrorModuleProxy(e.message);

@@ -74,10 +71,5 @@ }

} catch (e) {
if (Env.watch) { // If compiling fails, treat as recoverable in watch mode
console.warn(`Unable to compile ${name}, stubbing out`, e.message);
(m as any)._compile(CompilerUtil.getErrorModuleProxySource(e.message), jsf);
}
if (e.message.startsWith('Cannot find module') || e.message.startsWith('Unable to load')) {
const modName = m.filename.replace(`${this.cwd}/`, '');
const err = new Error(`${e.message} ${e.message.includes('from') ? `[via ${modName}]` : `from ${modName}`}`);
err.stack = err.stack;
const err = new AppError(`${e.message} ${e.message.includes('from') ? `[via ${modName}]` : `from ${modName}`}`, 'general');
e = err;

@@ -84,0 +76,0 @@ }

import * as ts from 'typescript';
import { dirname, } from 'path';
import { AppInfo, FsUtil, Util } from '@travetto/base';
import { Env, AppInfo, FsUtil, Util } from '@travetto/base';

@@ -63,20 +63,30 @@ export type Import = { path: string, ident: ts.Identifier };

static addImport(file: ts.SourceFile, imports: Import[]) {
const importStmts = imports
.map(({ path, ident }) => {
const imptStmt = ts.createImportDeclaration(
undefined, undefined,
ts.createImportClause(undefined, ts.createNamespaceImport(ident)),
ts.createLiteral(require.resolve(path))
);
return imptStmt;
});
try {
const importStmts = imports
.map(({ path, ident }) => {
const imptStmt = ts.createImportDeclaration(
undefined, undefined,
ts.createImportClause(undefined, ts.createNamespaceImport(ident)),
ts.createLiteral(require.resolve(path))
);
return imptStmt;
});
const out = ts.updateSourceFileNode(file, ts.createNodeArray([
...importStmts,
...file.statements
]),
file.isDeclarationFile, file.referencedFiles,
file.typeReferenceDirectives, file.hasNoDefaultLib);
const out = ts.updateSourceFileNode(file, ts.createNodeArray([
...importStmts,
...file.statements
]),
file.isDeclarationFile, file.referencedFiles,
file.typeReferenceDirectives, file.hasNoDefaultLib);
return out;
return out;
} catch (err) { // Missing import
if (file.fileName.includes('/extension/')) {
return file;
} else {
const out = new Error(`${err.message} in ${file.fileName.replace(`${Env.cwd}/`, '')}`);
out.stack = err.stack;
throw out;
}
}
}

@@ -83,0 +93,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