From 5ae65a53d16196576bc49b24755d0283f9bb0884 Mon Sep 17 00:00:00 2001 From: Benjamin Kietzman Date: Sat, 27 Jan 2018 10:55:29 -0800 Subject: [PATCH 1/4] Load .atom-build.js without using require Also add support for .atom-build.coffee https://github.com/noseglid/atom-build/pull/553 https://github.com/noseglid/atom-build/issues/513 --- lib/atom-build.js | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/lib/atom-build.js b/lib/atom-build.js index ec70bf41..664f05af 100644 --- a/lib/atom-build.js +++ b/lib/atom-build.js @@ -5,23 +5,51 @@ import EventEmitter from 'events'; function getConfig(file) { const fs = require('fs'); const realFile = fs.realpathSync(file); - delete require.cache[realFile]; + const contents = fs.readFileSync(realFile); + + function fromScript(script) { + const globals = { + __dirname: require('path').dirname(realFile), + __filename: realFile, + module: { exports: {} }, + require + }; + globals.exports = globals.module.exports; + const scriptFn = new Function(...Object.keys(globals), script); + scriptFn(...Object.keys(globals).map(n => globals[n])); + return globals.module.exports; + }; + switch (require('path').extname(file)) { case '.json': + return JSON.parse(contents); + case '.js': - return require(realFile); + return fromScript(contents); + + case '.coffee': + let coffee; + try + { + coffee = require('coffeescript'); + } + catch (e) {} + if (coffee === undefined) + { + coffee = require('coffee-script'); + } + return fromScript(coffee.compile(contents, { bare: true })); case '.cson': - return require('cson-parser').parse(fs.readFileSync(realFile)); + return require('cson-parser').parse(contents); case '.yaml': case '.yml': - return require('js-yaml').safeLoad(fs.readFileSync(realFile)); + return require('js-yaml').safeLoad(contents); } return {}; } - function createBuildConfig(build, name) { const conf = { name: 'Custom: ' + name, From e6cf2f695661633c713316c241bcdc08fce6f5bd Mon Sep 17 00:00:00 2001 From: Benjamin Kietzman Date: Sat, 27 Jan 2018 11:06:51 -0800 Subject: [PATCH 2/4] add 'coffee' to isEligible --- lib/atom-build.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/atom-build.js b/lib/atom-build.js index 664f05af..cd2b47f9 100644 --- a/lib/atom-build.js +++ b/lib/atom-build.js @@ -96,7 +96,7 @@ export default class CustomFile extends EventEmitter { const os = require('os'); const fs = require('fs'); const path = require('path'); - this.files = [].concat.apply([], [ 'json', 'cson', 'yaml', 'yml', 'js' ].map(ext => [ + this.files = [].concat.apply([], [ 'json', 'cson', 'yaml', 'yml', 'js', 'coffee' ].map(ext => [ path.join(this.cwd, `.atom-build.${ext}`), path.join(os.homedir(), `.atom-build.${ext}`) ])).filter(fs.existsSync); From b22aaf1fa8a381b10e1e443a4074cdfda1bf317f Mon Sep 17 00:00:00 2001 From: Benjamin Kietzman Date: Sat, 27 Jan 2018 11:08:05 -0800 Subject: [PATCH 3/4] Update custom-provider-spec.js test .atom-build.coffee --- spec/custom-provider-spec.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spec/custom-provider-spec.js b/spec/custom-provider-spec.js index 6dd14881..d5fa0afd 100644 --- a/spec/custom-provider-spec.js +++ b/spec/custom-provider-spec.js @@ -144,4 +144,20 @@ describe('custom provider', () => { }); }); }); + + describe('when .atom-build.coffee exists', () => { + it('it should provide targets', () => { + fs.writeFileSync(`${directory}.atom-build.coffee`, fs.readFileSync(`${__dirname}/fixture/.atom-build.coffee`)); + expect(builder.isEligible()).toEqual(true); + + waitsForPromise(() => { + return Promise.resolve(builder.settings()).then(settings => { + const s = settings[0]; + expect(s.exec).toEqual('echo'); + expect(s.args).toEqual([ 'hello', 'world', 'from', 'coffeescript' ]); + expect(s.name).toEqual('Custom: from coffeescript'); + }); + }); + }); + }); }); From 5ae0bff05a110de95b3cc3fb9d5c3b6d2bbac7bf Mon Sep 17 00:00:00 2001 From: Benjamin Kietzman Date: Sat, 27 Jan 2018 11:08:45 -0800 Subject: [PATCH 4/4] Create .atom-build.coffee --- spec/fixture/.atom-build.coffee | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 spec/fixture/.atom-build.coffee diff --git a/spec/fixture/.atom-build.coffee b/spec/fixture/.atom-build.coffee new file mode 100644 index 00000000..0224bc4b --- /dev/null +++ b/spec/fixture/.atom-build.coffee @@ -0,0 +1,4 @@ +module.exports = + cmd: 'echo' + args: [ 'hello', 'world', 'from', 'js' ] + name: 'from js'