mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Pass package info to transpilers
This commit is contained in:
@@ -56,6 +56,8 @@ describe("PackageTranspilationRegistry", () => {
|
||||
const coffeeSpec = { glob: "*.coffee", transpiler: './transpiler-coffee', options: { type: 'coffee' } }
|
||||
const omgSpec = { glob: "*.omgwhatisthis", transpiler: './transpiler-omg', options: { type: 'omg' } }
|
||||
|
||||
const expectedMeta = { name: 'my-package', path: '/path/to', meta: { some: 'metadata' } }
|
||||
|
||||
const jsTranspiler = {
|
||||
transpile: (sourceCode, filePath, options) => {
|
||||
return {code: sourceCode + "-transpiler-js"}
|
||||
@@ -98,7 +100,7 @@ describe("PackageTranspilationRegistry", () => {
|
||||
throw new Error('bad transpiler path ' + spec.transpiler)
|
||||
})
|
||||
|
||||
registry.addTranspilerConfigForPath('/path/to', 'my-package', [
|
||||
registry.addTranspilerConfigForPath('/path/to', 'my-package', { some: 'metadata' }, [
|
||||
jsSpec, coffeeSpec, omgSpec
|
||||
])
|
||||
})
|
||||
@@ -119,9 +121,9 @@ describe("PackageTranspilationRegistry", () => {
|
||||
spyOn(jsTranspiler, 'getCacheKeyData').andCallThrough()
|
||||
|
||||
wrappedCompiler.getCachePath('source', missPath, jsSpec)
|
||||
expect(jsTranspiler.getCacheKeyData).not.toHaveBeenCalled()
|
||||
expect(jsTranspiler.getCacheKeyData).not.toHaveBeenCalledWith('source', missPath, jsSpec.options, expectedMeta)
|
||||
wrappedCompiler.getCachePath('source', hitPath, jsSpec)
|
||||
expect(jsTranspiler.getCacheKeyData).toHaveBeenCalled()
|
||||
expect(jsTranspiler.getCacheKeyData).toHaveBeenCalledWith('source', hitPath, jsSpec.options, expectedMeta)
|
||||
})
|
||||
|
||||
it('compiles files matching a glob with the associated transpiler, and the old one otherwise', () => {
|
||||
@@ -130,11 +132,11 @@ describe("PackageTranspilationRegistry", () => {
|
||||
spyOn(omgTranspiler, "transpile").andCallThrough()
|
||||
|
||||
expect(wrappedCompiler.compile('source', hitPath)).toEqual('source-transpiler-js')
|
||||
expect(jsTranspiler.transpile).toHaveBeenCalledWith('source', hitPath, jsSpec.options)
|
||||
expect(jsTranspiler.transpile).toHaveBeenCalledWith('source', hitPath, jsSpec.options, expectedMeta)
|
||||
expect(wrappedCompiler.compile('source', hitPathCoffee)).toEqual('source-transpiler-coffee')
|
||||
expect(coffeeTranspiler.transpile).toHaveBeenCalledWith('source', hitPathCoffee, coffeeSpec.options)
|
||||
expect(coffeeTranspiler.transpile).toHaveBeenCalledWith('source', hitPathCoffee, coffeeSpec.options, expectedMeta)
|
||||
expect(wrappedCompiler.compile('source', hitNonStandardExt)).toEqual('source-transpiler-omg')
|
||||
expect(omgTranspiler.transpile).toHaveBeenCalledWith('source', hitNonStandardExt, omgSpec.options)
|
||||
expect(omgTranspiler.transpile).toHaveBeenCalledWith('source', hitNonStandardExt, omgSpec.options, expectedMeta)
|
||||
|
||||
expect(wrappedCompiler.compile('source', missPath)).toEqual('source-original-compiler')
|
||||
expect(wrappedCompiler.compile('source', hitPathMissExt)).toEqual('source-original-compiler')
|
||||
|
||||
@@ -19,9 +19,9 @@ var COMPILERS = {
|
||||
'.coffee': packageTranspilationRegistry.wrapTranspiler(require('./coffee-script'))
|
||||
}
|
||||
|
||||
exports.addTranspilerConfigForPath = function (packagePath, packageName, config) {
|
||||
exports.addTranspilerConfigForPath = function (packagePath, packageName, packageMeta, config) {
|
||||
packagePath = fs.realpathSync(packagePath)
|
||||
packageTranspilationRegistry.addTranspilerConfigForPath(packagePath, packageName, config)
|
||||
packageTranspilationRegistry.addTranspilerConfigForPath(packagePath, packageName, packageMeta, config)
|
||||
}
|
||||
|
||||
exports.removeTranspilerConfigForPath = function (packagePath) {
|
||||
|
||||
@@ -18,9 +18,10 @@ class PackageTranspilationRegistry {
|
||||
this.transpilerPaths = {}
|
||||
}
|
||||
|
||||
addTranspilerConfigForPath (packagePath, packageName, config) {
|
||||
addTranspilerConfigForPath (packagePath, packageName, packageMeta, config) {
|
||||
this.configByPackagePath[packagePath] = {
|
||||
name: packageName,
|
||||
meta: packageMeta,
|
||||
path: packagePath,
|
||||
specs: config
|
||||
}
|
||||
@@ -115,7 +116,8 @@ class PackageTranspilationRegistry {
|
||||
.update(sourceCode, 'utf8')
|
||||
|
||||
if (transpiler && transpiler.getCacheKeyData) {
|
||||
const additionalCacheData = transpiler.getCacheKeyData(sourceCode, filePath, spec.options)
|
||||
const meta = this.getMetadata(spec)
|
||||
const additionalCacheData = transpiler.getCacheKeyData(sourceCode, filePath, spec.options, meta)
|
||||
hash.update(additionalCacheData, 'utf8')
|
||||
}
|
||||
|
||||
@@ -126,7 +128,8 @@ class PackageTranspilationRegistry {
|
||||
const transpiler = this.getTranspiler(spec)
|
||||
|
||||
if (transpiler) {
|
||||
const result = transpiler.transpile(sourceCode, filePath, spec.options || {})
|
||||
const meta = this.getMetadata(spec)
|
||||
const result = transpiler.transpile(sourceCode, filePath, spec.options || {}, meta)
|
||||
if (result === undefined || (result && result.code === undefined)) {
|
||||
return sourceCode
|
||||
} else if (result.code) {
|
||||
@@ -140,6 +143,14 @@ class PackageTranspilationRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
getMetadata (spec) {
|
||||
return {
|
||||
name: spec._config.name,
|
||||
path: spec._config.path,
|
||||
meta: spec._config.meta
|
||||
}
|
||||
}
|
||||
|
||||
getTranspilerPath (spec) {
|
||||
Resolve = Resolve || require('resolve')
|
||||
return Resolve.sync(spec.transpiler, {
|
||||
|
||||
@@ -254,7 +254,7 @@ class Package
|
||||
|
||||
registerTranspilerConfig: ->
|
||||
if @metadata.atomTranspilers
|
||||
CompileCache.addTranspilerConfigForPath(@path, @name, @metadata.atomTranspilers)
|
||||
CompileCache.addTranspilerConfigForPath(@path, @name, @metadata, @metadata.atomTranspilers)
|
||||
|
||||
unregisterTranspilerConfig: ->
|
||||
if @metadata.atomTranspilers
|
||||
|
||||
Reference in New Issue
Block a user