condenser 0.0.12 → 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31107c23d48e2044816158df8cc737fdea156e2227763f4ad1409dcc36406388
4
- data.tar.gz: 3936450c32a7340a50345cc389351c2894b3263ca7e1c8f54563336a0977a445
3
+ metadata.gz: 78e391e2e34c47daeb8d0489f2ba3567d24ba9a2fecee0c8457c65276bbb6886
4
+ data.tar.gz: 354fd3b42f9eb4636a94babb725f87c0c4ea037c0943fa82380eb6f35a169338
5
5
  SHA512:
6
- metadata.gz: 0cf137d71f65b067b88e480756b74814e9e88df0342574fc7f466b87aa64515433a9c1dbf827c49aa1d816d20c0c640be6a97d55dba814aeeceade3ed200e37b
7
- data.tar.gz: cf154ab552d503a93ce487f1c7f9561faa07391c7e29d7190a66ca7e3bd9c6a842dd574193720484a84bcfba6430be58665f141519c5a4b024621169c4c89fe7
6
+ metadata.gz: a0bf3d990b15d7b225b8d0af09da4359e95e4add21222bbace313ac8a7b6833a40ee17257498e5f2a65a8fa13f47a6467bb9eae910c6acdbd2ddf7ab64b45ac2
7
+ data.tar.gz: cff15370f99605a8f87c1e313afbb65efc169acf4df4877c44acbe6b0ea36a2a772ecb98641e5c093fb1d658d35b2d562968d890a5ee328d764d3e8229a6c9aa
@@ -56,7 +56,7 @@ class Condenser
56
56
  end
57
57
 
58
58
  def restat!
59
- @stat = File.stat(@source_file)
59
+ @stat = nil
60
60
  end
61
61
 
62
62
  def inspect
@@ -1,9 +1,10 @@
1
1
  class Condenser
2
2
  class BuildCache
3
3
 
4
- attr_reader :semaphore, :listening
4
+ attr_reader :semaphore, :listening, :logger
5
5
 
6
- def initialize(path, listen: {})
6
+ def initialize(path, logger:, listen: {})
7
+ @logger = logger
7
8
  @path = path
8
9
  @map_cache = {}
9
10
  @lookup_cache = {}
@@ -22,43 +23,64 @@ class Condenser
22
23
  @semaphore = Mutex.new
23
24
  @listener = Listen.to(*path) do |modified, added, removed|
24
25
  @semaphore.synchronize do
25
- added = added.reduce([]) do |rt, added_file|
26
- rt << added_file.match(/([^\.]+)(\.|$)/).to_a[1]
27
- if path_match = @path.find { |p| added_file.start_with?(p) }
28
- a = added_file.delete_prefix(path_match).match(/([^\.]+)(\.|$)/).to_a[1]
26
+ @logger.debug { "build cache semaphore locked by #{Thread.current.object_id}" }
27
+ @logger.debug do
28
+ (
29
+ removed.map { |f| "Asset removed: #{f}" } +
30
+ added.map { |f| "Asset created: #{f}" } +
31
+ modified.map { |f| "Asset updated: #{f}" }
32
+ ).join("\n")
33
+ end
34
+
35
+ globs = []
36
+ (added + removed).each do |file|
37
+ globs << file.match(/([^\.]+)(\.|$)/).to_a[1]
38
+ if path_match = @path.find { |p| file.start_with?(p) }
39
+ a = file.delete_prefix(path_match).match(/([^\.]+)(\.|$)/).to_a[1]
29
40
  b = (File.dirname(a) + "/*")
30
41
 
31
- rt << a << a.delete_prefix('/')
32
- rt << a << b.delete_prefix('/')
42
+ globs << a << a.delete_prefix('/')
43
+ globs << a << b.delete_prefix('/')
33
44
  end
34
45
  end
35
-
36
- removed.each do |file|
37
- @map_cache&.delete_if do |k,v|
38
- v.source_file == file
39
- end
40
46
 
41
- @process_dependencies[file]&.delete_if do |asset|
42
- asset.source_file == file
43
- end
44
-
45
- @export_dependencies[file]&.delete_if do |asset|
46
- asset.source_file == file
47
+ @map_cache&.delete_if do |k,v|
48
+ if globs.any?{ |a| k.starts_with?(a) }
49
+ true
50
+ else
51
+ false
47
52
  end
48
53
  end
49
54
 
50
55
  @lookup_cache.delete_if do |key, value|
51
- if added.any?{ |a| key.starts_with?(a) }
56
+ if globs.any?{ |a| key.starts_with?(a) }
52
57
  value.each do |asset|
53
58
  modified << asset.source_file
54
59
  end
55
60
  true
56
61
  end
57
62
  end
58
- @map_cache&.delete_if do |k,v|
59
- added.any?{ |a| k.starts_with?(a) }
63
+
64
+ removed.each do |file|
65
+ @process_dependencies[file]&.delete_if do |asset|
66
+ if asset.source_file == file
67
+ true
68
+ else
69
+ asset.needs_reprocessing!
70
+ false
71
+ end
72
+ end
73
+
74
+ @export_dependencies[file]&.delete_if do |asset|
75
+ if asset.source_file == file
76
+ true
77
+ else
78
+ asset.needs_reexporting!
79
+ false
80
+ end
81
+ end
60
82
  end
61
-
83
+
62
84
  modified.each do |file|
63
85
  @process_dependencies[file]&.each do |asset|
64
86
  asset.needs_reprocessing!
@@ -68,7 +90,8 @@ class Condenser
68
90
  asset.needs_reexporting!
69
91
  end
70
92
  end
71
-
93
+
94
+ @logger.debug { "build cache semaphore unlocked by #{Thread.current.object_id}" }
72
95
  end
73
96
  end
74
97
  @listener.start
@@ -46,12 +46,6 @@ class Condenser
46
46
  raise ArgumentError, "Path \"#{path}\" does not exists" if !File.directory?(path)
47
47
  @npm_path = path
48
48
  end
49
-
50
- # def npm_check
51
- # if app.root.join('package-lock.json') && npm ls != 0
52
- # npm i
53
- # end
54
- # end
55
49
 
56
50
  def append_npm_path(*paths)
57
51
  paths.flatten.each do |path|
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) Microsoft Corporation. All rights reserved.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
@@ -1,16 +1,16 @@
1
- # Installation
2
- > `npm install --save @types/estree`
3
-
4
- # Summary
5
- This package contains type definitions for ESTree AST specification (https://github.com/estree/estree).
6
-
7
- # Details
8
- Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/estree.
9
-
10
- ### Additional Details
11
- * Last updated: Mon, 23 Dec 2019 20:14:46 GMT
12
- * Dependencies: none
13
- * Global values: none
14
-
15
- # Credits
16
- These definitions were written by RReverser (https://github.com/RReverser).
1
+ # Installation
2
+ > `npm install --save @types/estree`
3
+
4
+ # Summary
5
+ This package contains type definitions for ESTree AST specification (https://github.com/estree/estree).
6
+
7
+ # Details
8
+ Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/estree.
9
+
10
+ ### Additional Details
11
+ * Last updated: Mon, 23 Dec 2019 20:14:46 GMT
12
+ * Dependencies: none
13
+ * Global values: none
14
+
15
+ # Credits
16
+ These definitions were written by RReverser (https://github.com/RReverser).
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) Microsoft Corporation. All rights reserved.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
@@ -1,16 +1,16 @@
1
- # Installation
2
- > `npm install --save @types/node`
3
-
4
- # Summary
5
- This package contains type definitions for Node.js (http://nodejs.org/).
6
-
7
- # Details
8
- Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node.
9
-
10
- ### Additional Details
11
- * Last updated: Fri, 03 Jan 2020 23:33:08 GMT
12
- * Dependencies: none
13
- * Global values: `Buffer`, `Symbol`, `__dirname`, `__filename`, `clearImmediate`, `clearInterval`, `clearTimeout`, `console`, `exports`, `global`, `module`, `process`, `queueMicrotask`, `require`, `setImmediate`, `setInterval`, `setTimeout`
14
-
15
- # Credits
16
- These definitions were written by Microsoft TypeScript (https://github.com/Microsoft), DefinitelyTyped (https://github.com/DefinitelyTyped), Alberto Schiabel (https://github.com/jkomyno), Alexander T. (https://github.com/a-tarasyuk), Alvis HT Tang (https://github.com/alvis), Andrew Makarov (https://github.com/r3nya), Benjamin Toueg (https://github.com/btoueg), Bruno Scheufler (https://github.com/brunoscheufler), Chigozirim C. (https://github.com/smac89), Christian Vaagland Tellnes (https://github.com/tellnes), David Junger (https://github.com/touffy), Deividas Bakanas (https://github.com/DeividasBakanas), Eugene Y. Q. Shen (https://github.com/eyqs), Flarna (https://github.com/Flarna), Hannes Magnusson (https://github.com/Hannes-Magnusson-CK), Hoàng Văn Khải (https://github.com/KSXGitHub), Huw (https://github.com/hoo29), Kelvin Jin (https://github.com/kjin), Klaus Meinhardt (https://github.com/ajafff), Lishude (https://github.com/islishude), Mariusz Wiktorczyk (https://github.com/mwiktorczyk), Mohsen Azimi (https://github.com/mohsen1), Nicolas Even (https://github.com/n-e), Nicolas Voigt (https://github.com/octo-sniffle), Nikita Galkin (https://github.com/galkin), Parambir Singh (https://github.com/parambirs), Sebastian Silbermann (https://github.com/eps1lon), Simon Schick (https://github.com/SimonSchick), Thomas den Hollander (https://github.com/ThomasdenH), Wilco Bakker (https://github.com/WilcoBakker), wwwy3y3 (https://github.com/wwwy3y3), Zane Hannan AU (https://github.com/ZaneHannanAU), Samuel Ainsworth (https://github.com/samuela), Kyle Uehlein (https://github.com/kuehlein), Jordi Oliveras Rovira (https://github.com/j-oliveras), Thanik Bhongbhibhat (https://github.com/bhongy), Marcin Kopacz (https://github.com/chyzwar), Trivikram Kamat (https://github.com/trivikr), Minh Son Nguyen (https://github.com/nguymin4), Junxiao Shi (https://github.com/yoursunny), and Ilia Baryshnikov (https://github.com/qwelias).
1
+ # Installation
2
+ > `npm install --save @types/node`
3
+
4
+ # Summary
5
+ This package contains type definitions for Node.js (http://nodejs.org/).
6
+
7
+ # Details
8
+ Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node.
9
+
10
+ ### Additional Details
11
+ * Last updated: Fri, 03 Jan 2020 23:33:08 GMT
12
+ * Dependencies: none
13
+ * Global values: `Buffer`, `Symbol`, `__dirname`, `__filename`, `clearImmediate`, `clearInterval`, `clearTimeout`, `console`, `exports`, `global`, `module`, `process`, `queueMicrotask`, `require`, `setImmediate`, `setInterval`, `setTimeout`
14
+
15
+ # Credits
16
+ These definitions were written by Microsoft TypeScript (https://github.com/Microsoft), DefinitelyTyped (https://github.com/DefinitelyTyped), Alberto Schiabel (https://github.com/jkomyno), Alexander T. (https://github.com/a-tarasyuk), Alvis HT Tang (https://github.com/alvis), Andrew Makarov (https://github.com/r3nya), Benjamin Toueg (https://github.com/btoueg), Bruno Scheufler (https://github.com/brunoscheufler), Chigozirim C. (https://github.com/smac89), Christian Vaagland Tellnes (https://github.com/tellnes), David Junger (https://github.com/touffy), Deividas Bakanas (https://github.com/DeividasBakanas), Eugene Y. Q. Shen (https://github.com/eyqs), Flarna (https://github.com/Flarna), Hannes Magnusson (https://github.com/Hannes-Magnusson-CK), Hoàng Văn Khải (https://github.com/KSXGitHub), Huw (https://github.com/hoo29), Kelvin Jin (https://github.com/kjin), Klaus Meinhardt (https://github.com/ajafff), Lishude (https://github.com/islishude), Mariusz Wiktorczyk (https://github.com/mwiktorczyk), Mohsen Azimi (https://github.com/mohsen1), Nicolas Even (https://github.com/n-e), Nicolas Voigt (https://github.com/octo-sniffle), Nikita Galkin (https://github.com/galkin), Parambir Singh (https://github.com/parambirs), Sebastian Silbermann (https://github.com/eps1lon), Simon Schick (https://github.com/SimonSchick), Thomas den Hollander (https://github.com/ThomasdenH), Wilco Bakker (https://github.com/WilcoBakker), wwwy3y3 (https://github.com/wwwy3y3), Zane Hannan AU (https://github.com/ZaneHannanAU), Samuel Ainsworth (https://github.com/samuela), Kyle Uehlein (https://github.com/kuehlein), Jordi Oliveras Rovira (https://github.com/j-oliveras), Thanik Bhongbhibhat (https://github.com/bhongy), Marcin Kopacz (https://github.com/chyzwar), Trivikram Kamat (https://github.com/trivikr), Minh Son Nguyen (https://github.com/nguymin4), Junxiao Shi (https://github.com/yoursunny), and Ilia Baryshnikov (https://github.com/qwelias).
@@ -1,16 +1,16 @@
1
- # Installation
2
- > `npm install --save @types/resolve`
3
-
4
- # Summary
5
- This package contains type definitions for resolve (https://github.com/substack/node-resolve).
6
-
7
- # Details
8
- Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped.git/tree/master/types/resolve
9
-
10
- Additional Details
11
- * Last updated: Tue, 08 May 2018 17:01:00 GMT
12
- * Dependencies: node
13
- * Global values: none
14
-
15
- # Credits
16
- These definitions were written by Mario Nebl <https://github.com/marionebl>, Klaus Meinhardt <https://github.com/ajafff>.
1
+ # Installation
2
+ > `npm install --save @types/resolve`
3
+
4
+ # Summary
5
+ This package contains type definitions for resolve (https://github.com/substack/node-resolve).
6
+
7
+ # Details
8
+ Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped.git/tree/master/types/resolve
9
+
10
+ Additional Details
11
+ * Last updated: Tue, 08 May 2018 17:01:00 GMT
12
+ * Dependencies: node
13
+ * Global values: none
14
+
15
+ # Credits
16
+ These definitions were written by Mario Nebl <https://github.com/marionebl>, Klaus Meinhardt <https://github.com/ajafff>.
@@ -1,107 +1,107 @@
1
- var assert = require('assert');
2
- var babel = require('babel-core');
3
- var clear = require('clear');
4
- var diff = require('diff');
5
- var fs = require('fs');
6
- var jsonfile = require('jsonfile');
7
- var path = require('path');
8
- var Mocha = require('mocha');
9
-
10
- require('babel-register');
11
-
12
- var pluginPath = require.resolve('../src');
13
-
14
- function runTests() {
15
- var testsPath = __dirname + '/fixtures/';
16
-
17
- fs.readdirSync(testsPath).map(function(item) {
18
- return {
19
- path: path.join(testsPath, item),
20
- name: item,
21
- };
22
- }).filter(function(item) {
23
- return fs.statSync(item.path).isDirectory();
24
- }).forEach(runTest);
25
-
26
- runMocha();
27
- }
28
-
29
- function runMocha() {
30
- // Instantiate a Mocha instance.
31
- var mocha = new Mocha();
32
-
33
- var testDir = path.join(__dirname, 'mocha')
34
-
35
- var suite = path.join(testDir, 'suite.js')
36
-
37
- var output = babel.transformFileSync(suite, {
38
- plugins: [pluginPath]
39
- });
40
-
41
- var suiteCompiled = path.join(testDir, '.suite_compiled.js');
42
-
43
- fs.writeFileSync(suiteCompiled, output.code);
44
-
45
- delete require.cache[require.resolve(suiteCompiled)];
46
-
47
- mocha.addFile(suiteCompiled);
48
-
49
- // Run the tests.
50
- mocha.run();
51
- }
52
-
53
- function runTest(dir) {
54
- var babelOptions = {
55
- plugins: [pluginPath]
56
- }
57
-
58
- babelRcPath = path.join(dir.path, '.babelrc');
59
- try {
60
- fs.accessSync(babelRcPath);
61
- babelOptions = jsonfile.readFileSync(babelRcPath);
62
- } catch(e) {}
63
-
64
- var output = babel.transformFileSync(dir.path + '/actual.js', babelOptions);
65
-
66
- var expected = fs.readFileSync(dir.path + '/expected.js', 'utf-8');
67
-
68
- function normalizeLines(str) {
69
- return str.trimRight().replace(/\r\n/g, '\n');
70
- }
71
-
72
- process.stdout.write(dir.name);
73
- process.stdout.write('\n\n');
74
-
75
- diff.diffLines(normalizeLines(output.code), normalizeLines(expected))
76
- .forEach(function (part) {
77
- var value = part.value;
78
- if (part.added) {
79
- value = part.value;
80
- } else if (part.removed) {
81
- value = part.value;
82
- }
83
-
84
-
85
- process.stdout.write(value);
86
- });
87
-
88
- process.stdout.write('\n\n\n');
89
- }
90
-
91
- if (process.argv.indexOf('--watch') >= 0) {
92
- require('watch').watchTree(__dirname + '/..', {
93
- ignoreDotFiles: true
94
- }, function () {
95
- delete require.cache[pluginPath];
96
- clear();
97
- console.log('Press Ctrl+C to stop watching...');
98
- console.log('================================');
99
- try {
100
- runTests();
101
- } catch (e) {
102
- console.error(e.stack);
103
- }
104
- });
105
- } else {
106
- runTests();
107
- }
1
+ var assert = require('assert');
2
+ var babel = require('babel-core');
3
+ var clear = require('clear');
4
+ var diff = require('diff');
5
+ var fs = require('fs');
6
+ var jsonfile = require('jsonfile');
7
+ var path = require('path');
8
+ var Mocha = require('mocha');
9
+
10
+ require('babel-register');
11
+
12
+ var pluginPath = require.resolve('../src');
13
+
14
+ function runTests() {
15
+ var testsPath = __dirname + '/fixtures/';
16
+
17
+ fs.readdirSync(testsPath).map(function(item) {
18
+ return {
19
+ path: path.join(testsPath, item),
20
+ name: item,
21
+ };
22
+ }).filter(function(item) {
23
+ return fs.statSync(item.path).isDirectory();
24
+ }).forEach(runTest);
25
+
26
+ runMocha();
27
+ }
28
+
29
+ function runMocha() {
30
+ // Instantiate a Mocha instance.
31
+ var mocha = new Mocha();
32
+
33
+ var testDir = path.join(__dirname, 'mocha')
34
+
35
+ var suite = path.join(testDir, 'suite.js')
36
+
37
+ var output = babel.transformFileSync(suite, {
38
+ plugins: [pluginPath]
39
+ });
40
+
41
+ var suiteCompiled = path.join(testDir, '.suite_compiled.js');
42
+
43
+ fs.writeFileSync(suiteCompiled, output.code);
44
+
45
+ delete require.cache[require.resolve(suiteCompiled)];
46
+
47
+ mocha.addFile(suiteCompiled);
48
+
49
+ // Run the tests.
50
+ mocha.run();
51
+ }
52
+
53
+ function runTest(dir) {
54
+ var babelOptions = {
55
+ plugins: [pluginPath]
56
+ }
57
+
58
+ babelRcPath = path.join(dir.path, '.babelrc');
59
+ try {
60
+ fs.accessSync(babelRcPath);
61
+ babelOptions = jsonfile.readFileSync(babelRcPath);
62
+ } catch(e) {}
63
+
64
+ var output = babel.transformFileSync(dir.path + '/actual.js', babelOptions);
65
+
66
+ var expected = fs.readFileSync(dir.path + '/expected.js', 'utf-8');
67
+
68
+ function normalizeLines(str) {
69
+ return str.trimRight().replace(/\r\n/g, '\n');
70
+ }
71
+
72
+ process.stdout.write(dir.name);
73
+ process.stdout.write('\n\n');
74
+
75
+ diff.diffLines(normalizeLines(output.code), normalizeLines(expected))
76
+ .forEach(function (part) {
77
+ var value = part.value;
78
+ if (part.added) {
79
+ value = part.value;
80
+ } else if (part.removed) {
81
+ value = part.value;
82
+ }
83
+
84
+
85
+ process.stdout.write(value);
86
+ });
87
+
88
+ process.stdout.write('\n\n\n');
89
+ }
90
+
91
+ if (process.argv.indexOf('--watch') >= 0) {
92
+ require('watch').watchTree(__dirname + '/..', {
93
+ ignoreDotFiles: true
94
+ }, function () {
95
+ delete require.cache[pluginPath];
96
+ clear();
97
+ console.log('Press Ctrl+C to stop watching...');
98
+ console.log('================================');
99
+ try {
100
+ runTests();
101
+ } catch (e) {
102
+ console.error(e.stack);
103
+ }
104
+ });
105
+ } else {
106
+ runTests();
107
+ }