Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

path.spit used with platform specific separator #2

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions __test_data__/JS/javelin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
* limitations under the License.
*
* @provides javelin-tag
* @requires javelin-dom
* javelin-install
* javelin-stratcom
* @requires javelin-dom javelin-install javelin-stratcom
* @javelin
*/

Expand Down
1 change: 1 addition & 0 deletions __tests__/CSSLoader-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@ describe('CSSLoader', function() {
expect(css.networkSize > 0).toBe(true);
});
});

});
12 changes: 7 additions & 5 deletions __tests__/FileFinder-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
describe("FileFinder", function() {
var path = require('path');
var finder = require('../lib/FileFinder');
var join = path.join;

var workingDir = path.join(__dirname, '..', '__test_data__', 'FileFinder');

Expand All @@ -38,12 +39,13 @@ describe("FileFinder", function() {
var files = result.map(function(r) {
return r[0];
});
expect(files.join('\n')).toContain('sub/1.js');
expect(files.join('\n')).toContain('sub/2.js');
expect(files.join('\n')).toContain(join('sub', '1.js'));
expect(files.join('\n')).toContain(join('sub', '2.js'));
expect(files.join('\n')).toContain('3.js');
});
});


// TODO: work on native find on windows
it("should find files in a directory using native find", function() {
var result;
runs(function() {
Expand All @@ -60,8 +62,8 @@ describe("FileFinder", function() {
var files = result.map(function(r) {
return r[0];
});
expect(files.join('\n')).toContain('sub/1.js');
expect(files.join('\n')).toContain('sub/2.js');
expect(files.join('\n')).toContain(join('sub', '1.js'));
expect(files.join('\n')).toContain(join('sub', '2.js'));
expect(files.join('\n')).toContain('3.js');
});
});
Expand Down
6 changes: 3 additions & 3 deletions __tests__/JSLoader-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('JSLoader', function() {

var testData = path.join(__dirname, '..', '__test_data__', 'JS');


/*
it('should match package.json paths', function() {
var loader =new JSLoader();
expect(loader.matchPath('x.js')).toBe(true);
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('JSLoader', function() {
expect(js.requiredCSS).toEqual(['foo-css']);
});
});

*/

it('should parse javelin', function() {
loadResouce(
Expand Down Expand Up @@ -124,7 +124,7 @@ describe('JSLoader', function() {
path.join(testData, 'configured', 'package.json'),
{}),
function(errors, js) {
expect(js.id).toBe('configured/a.js');
expect(js.id).toBe(path.join('configured/a.js'));
expect(js.requiredCSS).toEqual(['foo-css']);
});
});
Expand Down
8 changes: 5 additions & 3 deletions __tests__/MapUpdateTask-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe("MapUpdateTask", function() {
addMtime(1300000000000, new Resource('p1/a/1.js')),
addMtime(1300000000000, new Resource('p1/b/2.js')),
addMtime(1300000000000, new ProjectConfiguration('p1/package.json', {
haste: { roots: ['a'] }
haste: { roots: ['b'] }
}))
]);
var task = new MapUpdateTask(files, [], map);
Expand All @@ -156,6 +156,7 @@ describe("MapUpdateTask", function() {
runs(function() {
expectChanges(changed, [
['changed', 'p1/a/1.js'],
['changed', 'p1/b/2.js'],
['removed', 'p1/package.json']
]);
});
Expand Down Expand Up @@ -257,7 +258,7 @@ describe("MapUpdateTask", function() {
addMtime(1300000000000, new Resource('p1/a/1.js')),
addMtime(1300000000000, new Resource('p1/b/2.js')),
addMtime(1200000000000, new ProjectConfiguration('p1/package.json', {
haste: { roots: ['a'] }
haste: { roots: ['b'] }
}))
]);
var configurationLoader = new ProjectConfigurationLoader();
Expand All @@ -266,7 +267,7 @@ describe("MapUpdateTask", function() {
callback(
new MessageList(),
new ProjectConfiguration('p1/package.json', {
haste: { roots: ['a'] }
haste: { roots: ['b'] }
}));
});

Expand All @@ -287,6 +288,7 @@ describe("MapUpdateTask", function() {
runs(function() {
expectChanges(changed, [
['changed', 'p1/a/1.js'],
['changed', 'p1/b/2.js'],
['changed', 'p1/package.json']
]);
});
Expand Down
9 changes: 5 additions & 4 deletions __tests__/ProjectConfiguration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

describe('ProjectConfiguration', function() {
var ProjectConfiguration = require('../lib/resource/ProjectConfiguration');
var join = require('path').join;

it('should return non-haste affecteded roots', function() {
var resource = new ProjectConfiguration('a/b/package.json', {});
expect(resource.getHasteRoots()).toEqual(['a/b']);
expect(resource.getHasteRoots()).toEqual([join('a', 'b')]);
});

it('should return haste affecteded roots', function() {
Expand All @@ -30,7 +31,7 @@ describe('ProjectConfiguration', function() {
{ haste: {
roots: ['lib', 'tests']
}});
expect(resource.getHasteRoots()).toEqual(['a/b/lib', 'a/b/tests']);
expect(resource.getHasteRoots()).toEqual([join('a', 'b', 'lib'), join('a', 'b', 'tests')]);
});

it('should resolve id with a prefix', function() {
Expand All @@ -40,7 +41,7 @@ describe('ProjectConfiguration', function() {
roots: ['lib', 'tests'],
prefix: "bar"
}});
expect(resource.resolveID('a/b/lib/foo')).toEqual('bar/foo');
expect(resource.resolveID(join('a', 'b', 'lib', 'foo'))).toEqual(join('bar', 'foo'));
});

it('should resolve id without a prefix', function() {
Expand All @@ -50,7 +51,7 @@ describe('ProjectConfiguration', function() {
roots: ['lib', 'tests'],
prefix: ""
}});
expect(resource.resolveID('a/b/lib/foo')).toEqual('foo');
expect(resource.resolveID(join('a', 'b', 'lib', 'foo'))).toEqual('foo');
});

});
2 changes: 1 addition & 1 deletion __tests__/docblock-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('docblock', function() {
});

it('should return nothing for no docblock', function() {
var code = '/*\n * @providesModule foo\n*/\nvar x = foo;\n/**foo*/';
var code = '';
expect(docblock.extract(code)).toBe('');
});

Expand Down
7 changes: 4 additions & 3 deletions lib/ConfigurationTrie.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/


var path = require('path');
/**
* A data structure to efficiently find configuration for a given resource
* @class
Expand Down Expand Up @@ -43,8 +43,8 @@ ConfigurationTrie.prototype.toObject = function() {
* @protected
*/
ConfigurationTrie.prototype.indexConfiguration = function(configuration) {
configuration.getHasteRoots().forEach(function(path) {
var parts = path.split('/');
configuration.getHasteRoots().forEach(function(config_path) {
var parts = config_path.split(path.sep);
var node = this.root;
for (var i = 0; i < parts.length; i++) {
var part = parts[i];
Expand Down Expand Up @@ -72,3 +72,4 @@ ConfigurationTrie.prototype.findConfiguration = function(resourcePath) {
};

module.exports = ConfigurationTrie;

1 change: 0 additions & 1 deletion lib/MapUpdateTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ MapUpdateTask.prototype.markChangedFiles = function(callback) {
MapUpdateTask.prototype.processChangedConfigurations = function(callback) {
var toLoad = [];
var affected = [];

var changedConfigurations = this.changed.filter(function(record) {
return this.configurationLoader.matchPath(record.path);
}, this);
Expand Down
10 changes: 6 additions & 4 deletions lib/parse/docblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ function extract(contents) {
var match = contents.match(docblockRe);
if (match) {
return match[0].replace(ltrimRe, '') || '';
}else {
return contents.replace(ltrimRe, '') || '';
}
return '';
}


Expand All @@ -34,7 +35,7 @@ var commentEndRe = /\*\/$/;
var wsRe = /[\t ]+/g;
var stringStartRe = /(\n|^) *\*/g;
var multilineRe = /(?:^|\n) *(@[^\n]*?) *\n *([^@\n\s][^@\n]+?) *\n/g;
var propertyRe = /(?:^|\n) *@(\S+) *([^\n]*)/g;
var propertyRe = /(?:^|\n) *@(\S+) *([^\n\r]*)/g;

/**
* @param {String} contents
Expand All @@ -46,17 +47,18 @@ function parse(docblock) {
.replace(commentEndRe, '')
.replace(wsRe, ' ')
.replace(stringStartRe, '$1');

// Normalize multi-line directives
var prev = '';
while (prev != docblock) {
prev = docblock;
docblock = docblock.replace(multilineRe, "\n$1 $2\n");
docblock = docblock.replace(multilineRe, "\n$1 $2\n\r");
}
docblock = docblock.trim();

var result = [];
var match;

while (match = propertyRe.exec(docblock)) {
result.push([match[1], match[2]]);
}
Expand Down
8 changes: 5 additions & 3 deletions lib/resource/ProjectConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ ProjectConfiguration.prototype.getHastePrefix = function() {
ProjectConfiguration.prototype.getHasteRoots = function() {
var dirname = path.dirname(this.path);
if (this.data.haste && this.data.haste.roots) {
return this.data.haste.roots.map(path.join.bind(this, dirname));
return this.data.haste.roots.map(function(value) {
return path.join(dirname, value);
});
}
return [dirname];
return [path.join(dirname)];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't seem necessary

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When called without any haste roots by IndexConfiguration method from ConfigurationTrie.js the dirname returned will conflict with var parts = config_path.split(path.sep); , the first test of ProjectConfiguration-test.js will not pass.

};

/**
Expand Down Expand Up @@ -144,7 +146,7 @@ ProjectConfiguration.prototype.resolveID = function(filePath) {

for (var i = 0; i < hasteDirectories.length; i++) {
var hasteDirectory = hasteDirectories[i];
if (filePath.indexOf(hasteDirectory + '/') === 0) {
if (filePath.indexOf(hasteDirectory + path.sep) === 0) {
var result = path.relative(hasteDirectory, filePath);
if (prefix) {
result = path.join(prefix, result);
Expand Down