@travetto/compiler
Advanced tools
Comparing version 0.0.16 to 0.0.17
@@ -8,6 +8,4 @@ { | ||
"@travetto/base": "0.x.x", | ||
"@types/chokidar": "^1.7.5", | ||
"@types/node": "^9.4.7", | ||
"@types/source-map-support": "^0.4.0", | ||
"chokidar": "^2.0.3", | ||
"source-map-support": "^0.5.4", | ||
@@ -25,3 +23,3 @@ "string-hash": "^1.1.3", | ||
"scripts": {}, | ||
"version": "0.0.16" | ||
"version": "0.0.17" | ||
} |
@@ -5,7 +5,5 @@ import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import * as glob from 'glob'; | ||
import * as chokidar from 'chokidar'; | ||
import { EventEmitter } from 'events'; | ||
import { bulkRequire, bulkFindSync, AppEnv, AppInfo } from '@travetto/base'; | ||
import { bulkRequire, bulkFindSync, AppEnv, AppInfo, Watcher, Entry } from '@travetto/base'; | ||
import { RetargettingHandler } from './proxy'; | ||
@@ -30,4 +28,2 @@ | ||
static contents = new Map<string, string>(); | ||
// static servicesHost: ts.LanguageServiceHost; | ||
// static langaugeService: ts.LanguageService; | ||
static cwd: string; | ||
@@ -39,3 +35,3 @@ static options: ts.CompilerOptions; | ||
static rootFiles: string[]; | ||
static fileWatcher: chokidar.FSWatcher; | ||
static fileWatchers: { [key: string]: Watcher } = {}; | ||
static events = new EventEmitter(); | ||
@@ -48,17 +44,10 @@ static snaphost = new Map<string, ts.IScriptSnapshot | undefined>() | ||
static libraryPath = 'node_modules'; | ||
static frameworkWorkingSet = `${Compiler.libraryPath}/@travetto/*/src/**/*.ts`; | ||
static appWorkingSet = `src/**/*.ts`; | ||
static transformerSet = '**/transformer.*.ts'; | ||
static transformerPattern = /^.*\/transformer.*[.]ts$/; | ||
static optionalFiles = /\/opt\/[^/]+.ts/; | ||
static definitionFiles = /\.d\.ts$/g; | ||
static devDependencyFiles = AppInfo.DEV_PACKAGES && AppInfo.DEV_PACKAGES.length ? | ||
[new RegExp(`${Compiler.libraryPath}/(${AppInfo.DEV_PACKAGES.join('|')})/`)] : []; | ||
static devDependencyFiles = AppInfo.DEV_PACKAGES | ||
.map(x => new RegExp(`node_modules/${x}/`)); | ||
static workingSets = [Compiler.frameworkWorkingSet, Compiler.appWorkingSet]; | ||
static invalidWorkingSetFiles = [ | ||
Compiler.optionalFiles, | ||
Compiler.definitionFiles, | ||
/transformer\.[^/]+.ts/, | ||
/\.d\.ts$/g, // Definition files | ||
Compiler.transformerPattern, | ||
...Compiler.devDependencyFiles | ||
@@ -77,5 +66,4 @@ ]; | ||
static handleLoadError(p: string, e?: any): boolean { | ||
if (!AppEnv.prod || this.optionalFiles.test(p)) { // If attempting to load an optional require | ||
const extra = this.optionalFiles.test(p) ? 'optional ' : ''; | ||
console.error(`Unable to import ${extra}require, ${p}, stubbing out`, e); | ||
if (!AppEnv.prod) { // If attempting to load an optional require | ||
console.error(`Unable to import ${p}, stubbing out`, e); | ||
return true; | ||
@@ -93,8 +81,3 @@ } else { | ||
const out = ts.parseJsonSourceFileConfigFileContent( | ||
ts.readJsonConfigFile(`${this.cwd}/${this.configFile}`, x => ts.sys.readFile(x)), { | ||
useCaseSensitiveFileNames: true, | ||
fileExists: ts.sys.fileExists, | ||
readFile: ts.sys.readFile, | ||
readDirectory: ts.sys.readDirectory | ||
}, this.cwd, { | ||
ts.readJsonConfigFile(`${this.cwd}/${this.configFile}`, ts.sys.readFile), ts.sys, this.cwd, { | ||
rootDir: `${this.cwd}`, | ||
@@ -117,3 +100,3 @@ sourceMap: false, | ||
for (const trns of bulkRequire(this.transformerSet)) { | ||
for (const trns of bulkRequire([this.transformerPattern], this.cwd)) { | ||
for (const key of Object.keys(trns)) { | ||
@@ -151,3 +134,3 @@ const item = trns[key]; | ||
const p = Module._resolveFilename(request, parent); | ||
if (p.includes(process.cwd()) && !p.includes(this.libraryPath)) { | ||
if (p.includes(this.cwd) && !p.includes(this.libraryPath)) { | ||
if (!this.modules.has(p)) { | ||
@@ -180,3 +163,6 @@ const handler = new RetargettingHandler(mod); | ||
if (AppEnv.watch) { | ||
this.fileWatcher.add(tsf); | ||
const topLevel = tsf.split(`${this.cwd}/`)[1].split('/')[0]; | ||
if (this.fileWatchers[topLevel]) { | ||
this.fileWatchers[topLevel].add([tsf]); | ||
} | ||
} | ||
@@ -243,3 +229,3 @@ // Picking up missed files | ||
static emitFile(fileName: string) { | ||
// let output = this.langaugeService.getEmitOutput(fileName); | ||
console.debug('Emitting', fileName); | ||
const content = ts.sys.readFile(fileName)!; | ||
@@ -251,3 +237,3 @@ | ||
if (hash === this.hashes.get(fileName)) { | ||
console.debug('File contents unchanged'); | ||
console.debug(`Contents Unchanged: ${fileName}`); | ||
return false; | ||
@@ -259,5 +245,3 @@ } | ||
let output = res.outputText; | ||
if (fileName.match(/\/test\//)) { | ||
// console.debug(fileName, output); | ||
} | ||
const outFileName = toJsName(fileName); | ||
@@ -267,3 +251,3 @@ | ||
console.debug(`Compiling ${fileName} failed`); | ||
if (this.handleLoadError(fileName) && this.optionalFiles.test(fileName)) { | ||
if (this.handleLoadError(fileName)) { | ||
output = this.emptyRequire; | ||
@@ -285,52 +269,52 @@ } | ||
static watchFiles(fileNames: string[]) { | ||
// TODO: Replace with something that has fewer dependencies, to decrease overall footprint and load time | ||
const watcher = chokidar.watch(this.appWorkingSet, { | ||
ignored: this.invalidWorkingSetFile, | ||
persistent: true, | ||
cwd: process.cwd(), | ||
private static watcherListener({ event, entry }: { event: string, entry: Entry }) { | ||
if (this.invalidWorkingSetFile(entry.file)) { | ||
return; | ||
} | ||
console.log('Watch', event, entry.file); | ||
if (event === 'added') { | ||
this.rootFiles.push(entry.file); | ||
this.files.set(entry.file, { version: 1 }); | ||
if (this.emitFile(entry.file)) { | ||
this.events.emit(event, entry.file); | ||
} | ||
} else if (event === 'changed') { | ||
const changed = this.files.has(entry.file); | ||
if (changed) { | ||
this.snaphost.delete(entry.file); | ||
this.files.get(entry.file)!.version++; | ||
} else { | ||
this.files.set(entry.file, { version: 1 }); | ||
this.rootFiles.push(entry.file); | ||
} | ||
if (this.emitFile(entry.file)) { | ||
this.events.emit(changed ? 'changed' : 'added', entry.file); | ||
} | ||
} else if (event === 'removed') { | ||
this.unload(entry.file); | ||
this.events.emit(event, entry.file); | ||
} | ||
} | ||
static buildWatcher(tld: string) { | ||
const watcher = new Watcher({ | ||
interval: 250, | ||
ignoreInitial: false, | ||
awaitWriteFinish: { stabilityThreshold: 10 } | ||
cwd: `${this.cwd}/${tld}` | ||
}); | ||
watcher.on('ready', () => { | ||
watcher | ||
.on('add', fileName => { | ||
fileName = `${process.cwd()}/${fileName}`; | ||
fileNames.push(fileName); | ||
this.files.set(fileName, { version: 1 }); | ||
if (this.emitFile(fileName)) { | ||
this.events.emit('added', fileName); | ||
} | ||
}) | ||
.on('change', fileName => { | ||
fileName = `${process.cwd()}/${fileName}`; | ||
const changed = this.files.has(fileName); | ||
if (changed) { | ||
this.snaphost.delete(fileName); | ||
this.files.get(fileName)!.version++; | ||
} else { | ||
this.files.set(fileName, { version: 1 }); | ||
fileNames.push(fileName); | ||
} | ||
if (this.emitFile(fileName)) { | ||
this.events.emit(changed ? 'changed' : 'added', fileName); | ||
} | ||
}) | ||
.on('unlink', fileName => { | ||
fileName = `${process.cwd()}/${fileName}`; | ||
this.unload(fileName); | ||
this.events.emit('removed', fileName); | ||
}); | ||
}); | ||
watcher.on('all', this.watcherListener.bind(this)) | ||
watcher.add([/.*[.]ts$/]); // Watch ts files | ||
watcher.run(false); | ||
return watcher; | ||
} | ||
static watchFiles() { | ||
const ret = { src: this.buildWatcher('src') }; | ||
return ret; | ||
} | ||
static logErrors(fileName: string, diagnostics?: ts.Diagnostic[]) { | ||
// let allDiagnostics = this.langaugeService.getCompilerOptionsDiagnostics() | ||
// .concat(this.langaugeService.getSyntacticDiagnostics(fileName)) | ||
// .concat(this.langaugeService.getSemanticDiagnostics(fileName)); | ||
if (!diagnostics || !diagnostics.length) { | ||
@@ -354,2 +338,3 @@ return false; | ||
static transpile(input: string, fileName: string) { | ||
// console.debug('Transpiling', fileName); | ||
const output = ts.transpileModule(input, { | ||
@@ -393,27 +378,9 @@ compilerOptions: this.options, | ||
this.rootFiles = bulkFindSync(this.workingSets, undefined, this.invalidWorkingSetFile); | ||
this.rootFiles = bulkFindSync([/[^\/]+\/src\/.*[.]ts$/], `${this.cwd}/${Compiler.libraryPath}/@travetto`) | ||
.concat(bulkFindSync([/.ts/], `${this.cwd}/src`)) | ||
.filter(x => !x.stats.isDirectory() && !this.invalidWorkingSetFile(x.file)) | ||
.map(x => x.file); | ||
console.debug('Files', this.rootFiles.length); | ||
console.debug(this.workingSets); | ||
/* | ||
this.servicesHost = { | ||
getScriptFileNames: () => this.rootFiles, | ||
getScriptVersion: (fileName) => this.files.has(fileName) ? this.files.get(fileName)!.version.toString() : '', | ||
getScriptSnapshot: (fileName) => this.getSnapshot(fileName), | ||
getCurrentDirectory: () => process.cwd(), | ||
getCompilationSettings: () => this.options, | ||
getDefaultLibFileName: (options) => ts.getDefaultLibFilePath(options), | ||
fileExists: ts.sys.fileExists, | ||
readFile: ts.sys.readFile, | ||
directoryExists: ts.sys.directoryExists, | ||
readDirectory: ts.sys.readDirectory, | ||
getDirectories: ts.sys.getDirectories, | ||
getCustomTransformers: () => this.transformers | ||
}; | ||
*/ | ||
// Create the language service files | ||
// this.langaugeService = ts.createLanguageService(this.servicesHost, this.registry); | ||
// Prime for type checker | ||
@@ -427,3 +394,3 @@ for (const fileName of this.rootFiles) { | ||
if (AppEnv.watch) { | ||
this.fileWatcher = this.watchFiles(this.rootFiles); | ||
this.fileWatchers = this.watchFiles(); | ||
} | ||
@@ -436,3 +403,4 @@ | ||
if (AppEnv.watch) { | ||
this.fileWatcher.close(); | ||
Object.values(this.fileWatchers).map(x => x.close()); | ||
this.fileWatchers = {}; | ||
} | ||
@@ -439,0 +407,0 @@ this.contents.clear(); |
@@ -6,3 +6,3 @@ require('@travetto/base/bootstrap').run() | ||
Compiler.on('changed', require); | ||
require('./stack'); | ||
require('./watch'); | ||
}); |
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
6
13
23157
639
- Removed@types/chokidar@^1.7.5
- Removedchokidar@^2.0.3
- Removed@types/chokidar@1.7.5(transitive)
- Removed@types/events@3.0.3(transitive)
- Removedanymatch@2.0.0(transitive)
- Removedarr-diff@4.0.0(transitive)
- Removedarr-flatten@1.1.0(transitive)
- Removedarr-union@3.1.0(transitive)
- Removedarray-unique@0.3.2(transitive)
- Removedassign-symbols@1.0.0(transitive)
- Removedasync-each@1.0.6(transitive)
- Removedatob@2.1.2(transitive)
- Removedbase@0.11.2(transitive)
- Removedbinary-extensions@1.13.1(transitive)
- Removedbindings@1.5.0(transitive)
- Removedbraces@2.3.2(transitive)
- Removedcache-base@1.0.1(transitive)
- Removedchokidar@2.1.8(transitive)
- Removedclass-utils@0.3.6(transitive)
- Removedcollection-visit@1.0.0(transitive)
- Removedcomponent-emitter@1.3.1(transitive)
- Removedcopy-descriptor@0.1.1(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removeddebug@2.6.9(transitive)
- Removeddecode-uri-component@0.2.2(transitive)
- Removeddefine-property@0.2.51.0.02.0.2(transitive)
- Removedexpand-brackets@2.1.4(transitive)
- Removedextend-shallow@2.0.13.0.2(transitive)
- Removedextglob@2.0.4(transitive)
- Removedfile-uri-to-path@1.0.0(transitive)
- Removedfill-range@4.0.0(transitive)
- Removedfor-in@1.0.2(transitive)
- Removedfragment-cache@0.2.1(transitive)
- Removedfsevents@1.2.13(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-value@2.0.6(transitive)
- Removedglob-parent@3.1.0(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhas-value@0.3.11.0.0(transitive)
- Removedhas-values@0.1.41.0.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-accessor-descriptor@1.0.1(transitive)
- Removedis-binary-path@1.0.1(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedis-data-descriptor@1.0.1(transitive)
- Removedis-descriptor@0.1.71.0.3(transitive)
- Removedis-extendable@0.1.11.0.1(transitive)
- Removedis-extglob@2.1.1(transitive)
- Removedis-glob@3.1.04.0.3(transitive)
- Removedis-number@3.0.0(transitive)
- Removedis-plain-object@2.0.4(transitive)
- Removedis-windows@1.0.2(transitive)
- Removedisarray@1.0.0(transitive)
- Removedisobject@2.1.03.0.1(transitive)
- Removedkind-of@3.2.24.0.06.0.3(transitive)
- Removedmap-cache@0.2.2(transitive)
- Removedmap-visit@1.0.0(transitive)
- Removedmicromatch@3.1.10(transitive)
- Removedmixin-deep@1.3.2(transitive)
- Removedms@2.0.0(transitive)
- Removednan@2.22.0(transitive)
- Removednanomatch@1.2.13(transitive)
- Removednormalize-path@2.1.13.0.0(transitive)
- Removedobject-copy@0.1.0(transitive)
- Removedobject-visit@1.0.1(transitive)
- Removedobject.pick@1.3.0(transitive)
- Removedpascalcase@0.1.1(transitive)
- Removedpath-dirname@1.0.2(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedposix-character-classes@0.1.1(transitive)
- Removedprocess-nextick-args@2.0.1(transitive)
- Removedreadable-stream@2.3.8(transitive)
- Removedreaddirp@2.2.1(transitive)
- Removedregex-not@1.0.2(transitive)
- Removedremove-trailing-separator@1.1.0(transitive)
- Removedrepeat-element@1.1.4(transitive)
- Removedrepeat-string@1.6.1(transitive)
- Removedresolve-url@0.2.1(transitive)
- Removedret@0.1.15(transitive)
- Removedsafe-buffer@5.1.2(transitive)
- Removedsafe-regex@1.1.0(transitive)
- Removedset-value@2.0.1(transitive)
- Removedsnapdragon@0.8.2(transitive)
- Removedsnapdragon-node@2.1.1(transitive)
- Removedsnapdragon-util@3.0.1(transitive)
- Removedsource-map@0.5.7(transitive)
- Removedsource-map-resolve@0.5.3(transitive)
- Removedsource-map-url@0.4.1(transitive)
- Removedsplit-string@3.1.0(transitive)
- Removedstatic-extend@0.1.2(transitive)
- Removedstring_decoder@1.1.1(transitive)
- Removedto-object-path@0.3.0(transitive)
- Removedto-regex@3.0.2(transitive)
- Removedto-regex-range@2.1.1(transitive)
- Removedunion-value@1.0.1(transitive)
- Removedunset-value@1.0.0(transitive)
- Removedupath@1.2.0(transitive)
- Removedurix@0.1.0(transitive)
- Removeduse@3.1.1(transitive)
- Removedutil-deprecate@1.0.2(transitive)