mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Merge pull request #14131 from atom/mkt-prepare-build-for-per-package-transpilation
Update build to pre-compile packages with per-package transpilation configs
This commit is contained in:
@@ -44,6 +44,7 @@ const transpileBabelPaths = require('./lib/transpile-babel-paths')
|
||||
const transpileCoffeeScriptPaths = require('./lib/transpile-coffee-script-paths')
|
||||
const transpileCsonPaths = require('./lib/transpile-cson-paths')
|
||||
const transpilePegJsPaths = require('./lib/transpile-peg-js-paths')
|
||||
const transpilePackagesWithCustomTranspilerPaths = require('./lib/transpile-packages-with-custom-transpiler-paths.js')
|
||||
|
||||
process.on('unhandledRejection', function (e) {
|
||||
console.error(e.stack || e)
|
||||
@@ -53,6 +54,7 @@ process.on('unhandledRejection', function (e) {
|
||||
checkChromedriverVersion()
|
||||
cleanOutputDirectory()
|
||||
copyAssets()
|
||||
transpilePackagesWithCustomTranspilerPaths()
|
||||
transpileBabelPaths()
|
||||
transpileCoffeeScriptPaths()
|
||||
transpileCsonPaths()
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
'use strict'
|
||||
|
||||
const CompileCache = require('../../src/compile-cache')
|
||||
const fs = require('fs')
|
||||
const glob = require('glob')
|
||||
const path = require('path')
|
||||
|
||||
const CONFIG = require('../config')
|
||||
|
||||
module.exports = function () {
|
||||
console.log(`Transpiling packages with custom transpiler configurations in ${CONFIG.intermediateAppPath}`)
|
||||
let pathsToCompile = []
|
||||
for (let packageName of Object.keys(CONFIG.appMetadata.packageDependencies)) {
|
||||
const packagePath = path.join(CONFIG.intermediateAppPath, 'node_modules', packageName)
|
||||
const metadataPath = path.join(packagePath, 'package.json')
|
||||
const metadata = require(metadataPath)
|
||||
if (metadata.atomTranspilers) {
|
||||
CompileCache.addTranspilerConfigForPath(packagePath, metadata.name, metadata, metadata.atomTranspilers)
|
||||
for (let config of metadata.atomTranspilers) {
|
||||
pathsToCompile = pathsToCompile.concat(glob.sync(path.join(packagePath, config.glob)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (let path of pathsToCompile) {
|
||||
transpilePath(path)
|
||||
}
|
||||
}
|
||||
|
||||
function transpilePath (path) {
|
||||
fs.writeFileSync(path, CompileCache.addPathToCache(path, CONFIG.atomHomeDirPath))
|
||||
}
|
||||
@@ -143,5 +143,19 @@ describe("PackageTranspilationRegistry", () => {
|
||||
expect(wrappedCompiler.compile('source', hitPathMissSubdir)).toEqual('source-original-compiler')
|
||||
expect(wrappedCompiler.compile('source', nodeModulesFolder)).toEqual('source-original-compiler')
|
||||
})
|
||||
|
||||
describe('when the packages root path contains node_modules', () =>{
|
||||
beforeEach(() => {
|
||||
registry.addTranspilerConfigForPath(path.join('/path/with/node_modules/in/root'), 'my-other-package', { some: 'metadata' }, [
|
||||
jsSpec
|
||||
])
|
||||
})
|
||||
|
||||
it('returns appropriate values from shouldCompile', () => {
|
||||
spyOn(originalCompiler, 'shouldCompile').andReturn(false)
|
||||
expect(wrappedCompiler.shouldCompile('source', '/path/with/node_modules/in/root/lib/test.js')).toBe(true)
|
||||
expect(wrappedCompiler.shouldCompile('source', '/path/with/node_modules/in/root/lib/node_modules/test.js')).toBe(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -71,11 +71,6 @@ class PackageTranspilationRegistry {
|
||||
getPackageTranspilerSpecForFilePath (filePath) {
|
||||
if (this.specByFilePath[filePath] !== undefined) return this.specByFilePath[filePath]
|
||||
|
||||
// ignore node_modules
|
||||
if (filePath.indexOf(path.sep + 'node_modules' + path.sep) > -1) {
|
||||
return false
|
||||
}
|
||||
|
||||
let thisPath = filePath
|
||||
let lastPath = null
|
||||
// Iterate parents from the file path to the root, checking at each level
|
||||
@@ -85,6 +80,10 @@ class PackageTranspilationRegistry {
|
||||
while (thisPath !== lastPath) { // until we reach the root
|
||||
let config = this.configByPackagePath[thisPath]
|
||||
if (config) {
|
||||
const relativePath = path.relative(thisPath, filePath)
|
||||
if (relativePath.startsWith(`node_modules${path.sep}`) || relativePath.indexOf(`${path.sep}node_modules${path.sep}`) > -1) {
|
||||
return false
|
||||
}
|
||||
for (let i = 0; i < config.specs.length; i++) {
|
||||
const spec = config.specs[i]
|
||||
if (minimatch(filePath, path.join(config.path, spec.glob))) {
|
||||
|
||||
@@ -86,7 +86,6 @@ class Package
|
||||
@loadMenus()
|
||||
@registerDeserializerMethods()
|
||||
@activateCoreStartupServices()
|
||||
@registerTranspilerConfig()
|
||||
@configSchemaRegisteredOnLoad = @registerConfigSchemaFromMetadata()
|
||||
@requireMainModule()
|
||||
@settingsPromise = @loadSettings()
|
||||
|
||||
Reference in New Issue
Block a user