Merge pull request #17686 from atom/dw-repo-local-core-packages

Enable repo-local core packages in the 'packages' folder
This commit is contained in:
David Wilson 2018-08-21 10:08:39 -07:00 committed by GitHub
commit ad4553cbba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 70 additions and 18 deletions

View File

@ -2,8 +2,9 @@
'use strict'
const childProcess = require('child_process')
const path = require('path')
const CONFIG = require('./config')
const childProcess = require('child_process')
const cleanDependencies = require('./lib/clean-dependencies')
const deleteMsbuildFromPath = require('./lib/delete-msbuild-from-path')
const dependenciesFingerprint = require('./lib/dependencies-fingerprint')
@ -42,4 +43,28 @@ childProcess.execFileSync(
)
runApmInstall(CONFIG.repositoryRootPath, ci)
if (!process.env.CI) {
require('colors')
const glob = require('glob')
const {spawn} = require('child_process')
// Install the local core packages in-place so they can be used in dev mode
const files = glob.sync(path.join(CONFIG.repositoryRootPath, 'packages/*/package.json'))
if (files.length > 0) {
console.log('Installing core packages for use in dev mode...')
files.forEach(file => {
const packageDir = path.dirname(file)
process.stdout.write(`Installing packages/${path.basename(packageDir)} `)
runApmInstall(path.dirname(file), false, ['inherit', 'pipe', 'inherit'])
if (process.platform === 'win32') {
return process.stdout.write('done\n'.green)
} else {
return process.stdout.write('\u2713\n'.green)
}
})
}
}
dependenciesFingerprint.write()

View File

@ -4,7 +4,7 @@ const childProcess = require('child_process')
const CONFIG = require('../config')
module.exports = function (packagePath, ci) {
module.exports = function (packagePath, ci, stdioOptions) {
const installEnv = Object.assign({}, process.env)
// Set resource path so that apm can load metadata related to Atom.
installEnv.ATOM_RESOURCE_PATH = CONFIG.repositoryRootPath
@ -14,6 +14,6 @@ module.exports = function (packagePath, ci) {
childProcess.execFileSync(
CONFIG.getApmBinPath(),
['--loglevel=error', ci ? 'ci' : 'install'],
{env: installEnv, cwd: packagePath, stdio: 'inherit'}
{env: installEnv, cwd: packagePath, stdio: stdioOptions || 'inherit'}
)
}

View File

@ -30,13 +30,15 @@ describe('PackageManager', () => {
expect(packageManger.packageDirPaths[0]).toBe(path.join(configDirPath, 'packages'))
})
it('adds regular package path and dev package path in dev mode', () => {
it('adds regular package path, dev package path, and Atom repo package path in dev mode and dev resource path is set', () => {
const packageManger = new PackageManager({})
const configDirPath = path.join('~', 'someConfig')
packageManger.initialize({configDirPath, devMode: true})
expect(packageManger.packageDirPaths.length).toBe(2)
const resourcePath = path.join('~', '/atom')
packageManger.initialize({configDirPath, resourcePath, devMode: true})
expect(packageManger.packageDirPaths.length).toBe(3)
expect(packageManger.packageDirPaths).toContain(path.join(configDirPath, 'packages'))
expect(packageManger.packageDirPaths).toContain(path.join(configDirPath, 'dev', 'packages'))
expect(packageManger.packageDirPaths).toContain(path.join(resourcePath, 'packages'))
})
})

View File

@ -20,6 +20,7 @@ class AtomProtocolHandler {
if (!safeMode) {
this.loadPaths.push(path.join(process.env.ATOM_HOME, 'dev', 'packages'))
this.loadPaths.push(path.join(resourcePath, 'packages'))
}
this.loadPaths.push(path.join(process.env.ATOM_HOME, 'packages'))

View File

@ -0,0 +1,31 @@
'use strict'
const path = require('path')
const fs = require('fs-plus')
const CSON = require('season')
const electron = require('electron')
module.exports = function () {
const appResourcePath = path.dirname(path.dirname(__dirname))
const defaultRepositoryPath = path.join(electron.app.getPath('home'), 'github', 'atom')
if (process.env.ATOM_DEV_RESOURCE_PATH) {
return process.env.ATOM_DEV_RESOURCE_PATH
} else if (isAtomRepoPath(process.cwd())) {
return process.cwd()
} else if (fs.statSyncNoException(defaultRepositoryPath)) {
return defaultRepositoryPath
}
return appResourcePath
}
function isAtomRepoPath (repoPath) {
let packageJsonPath = path.join(repoPath, 'package.json')
if (fs.statSyncNoException(packageJsonPath)) {
let packageJson = CSON.readFileSync(packageJsonPath)
return packageJson.name === 'atom'
}
return false
}

View File

@ -4,10 +4,9 @@ if (typeof snapshotResult !== 'undefined') {
const startTime = Date.now()
const electron = require('electron')
const fs = require('fs')
const path = require('path')
const yargs = require('yargs')
const getDevResourcePath = require('./get-dev-resource-path')
const args =
yargs(process.argv)
@ -21,16 +20,8 @@ if (args.resourcePath) {
resourcePath = args.resourcePath
} else {
const stableResourcePath = path.dirname(path.dirname(__dirname))
const defaultRepositoryPath = path.join(electron.app.getPath('home'), 'github', 'atom')
if (args.dev || args.test || args.benchmark || args.benchmarkTest) {
if (process.env.ATOM_DEV_RESOURCE_PATH) {
resourcePath = process.env.ATOM_DEV_RESOURCE_PATH
} else if (fs.statSyncNoException(defaultRepositoryPath)) {
resourcePath = defaultRepositoryPath
} else {
resourcePath = stableResourcePath
}
resourcePath = getDevResourcePath() || stableResourcePath
} else {
resourcePath = stableResourcePath
}

View File

@ -5,6 +5,7 @@ const yargs = require('yargs')
const {app} = require('electron')
const path = require('path')
const fs = require('fs-plus')
const getDevResourcePath = require('./get-dev-resource-path')
module.exports = function parseCommandLine (processArgs) {
const options = yargs(processArgs).wrap(yargs.terminalWidth())
@ -119,7 +120,7 @@ module.exports = function parseCommandLine (processArgs) {
let pathsToOpen = []
let urlsToOpen = []
let devMode = args['dev']
let devResourcePath = process.env.ATOM_DEV_RESOURCE_PATH || path.join(app.getPath('home'), 'github', 'atom')
let devResourcePath = getDevResourcePath()
let resourcePath = null
for (const path of args._) {

View File

@ -61,6 +61,7 @@ module.exports = class PackageManager {
if (params.configDirPath != null && !params.safeMode) {
if (this.devMode) {
this.packageDirPaths.push(path.join(params.configDirPath, 'dev', 'packages'))
this.packageDirPaths.push(path.join(this.resourcePath, 'packages'))
}
this.packageDirPaths.push(path.join(params.configDirPath, 'packages'))
}