diff --git a/src/utils/path.js b/src/utils/path.js index b5db7c1..4f55ba8 100644 --- a/src/utils/path.js +++ b/src/utils/path.js @@ -1,6 +1,6 @@ // TODO does this all work on windows? -export const absolutePath = /^(?:\/|(?:[A-Za-z]:)?\\)/; +export const absolutePath = /^(?:\/|(?:[A-Za-z]:)?[\\|\/])/; export function isAbsolute ( path ) { return absolutePath.test( path ); diff --git a/src/utils/resolveId.js b/src/utils/resolveId.js index 6b82f0d..8a0bd47 100644 --- a/src/utils/resolveId.js +++ b/src/utils/resolveId.js @@ -24,7 +24,7 @@ export function defaultExternalResolver ( id, importer ) { const root = absolutePath.exec( importer )[0]; let dir = dirname( importer ); - while ( dir !== root ) { + while ( dir !== root && dir !== "." ) { const pkgPath = resolve( dir, 'node_modules', id, 'package.json' ); let pkgJson; diff --git a/test/cli/external-modules/main.js b/test/cli/external-modules/main.js index 03f1b74..abaa454 100644 --- a/test/cli/external-modules/main.js +++ b/test/cli/external-modules/main.js @@ -1,5 +1,5 @@ -import { relative } from 'path'; +import { relative, normalize } from 'path'; import { format } from 'util'; assert.equal( format( 'it %s', 'works' ), 'it works' ); -assert.equal( relative( 'a/b/c', 'a/c/b' ), '../../c/b' ); +assert.equal( relative( 'a/b/c', 'a/c/b' ), normalize('../../c/b') ); diff --git a/test/function/allows-external-modules-from-nested-module/main.js b/test/function/allows-external-modules-from-nested-module/main.js index 8bacdc9..bdd4f85 100644 --- a/test/function/allows-external-modules-from-nested-module/main.js +++ b/test/function/allows-external-modules-from-nested-module/main.js @@ -1,8 +1,8 @@ -import { relative } from 'path'; +import { relative, normalize } from 'path'; import foo from './foo'; var path = 'foo/bar/baz'; var path2 = 'foo/baz/bar'; -assert.equal( relative( path, path2 ), '../../baz/bar' ); -assert.equal( foo, '../../c/b' ); \ No newline at end of file +assert.equal( relative( path, path2 ), normalize('../../baz/bar') ); +assert.equal( foo, normalize('../../c/b') ); \ No newline at end of file diff --git a/test/function/custom-path-resolver-async/_config.js b/test/function/custom-path-resolver-async/_config.js index 287f536..c336d67 100644 --- a/test/function/custom-path-resolver-async/_config.js +++ b/test/function/custom-path-resolver-async/_config.js @@ -8,7 +8,7 @@ module.exports = { var Promise = require( 'sander' ).Promise; var resolved; - if ( importee === path.resolve( __dirname, 'main.js' ) ) return importee; + if ( path.normalize(importee) === path.resolve( __dirname, 'main.js' ) ) return importee; if ( importee === 'foo' ) { resolved = path.resolve( __dirname, 'bar.js' ); diff --git a/test/function/custom-path-resolver-sync/_config.js b/test/function/custom-path-resolver-sync/_config.js index 9a755e5..ee993e1 100644 --- a/test/function/custom-path-resolver-sync/_config.js +++ b/test/function/custom-path-resolver-sync/_config.js @@ -5,7 +5,7 @@ module.exports = { description: 'uses a custom path resolver (synchronous)', options: { resolveId: function ( importee, importer ) { - if ( importee === path.resolve( __dirname, 'main.js' ) ) return importee; + if ( path.normalize(importee) === path.resolve( __dirname, 'main.js' ) ) return importee; if ( importee === 'foo' ) return path.resolve( __dirname, 'bar.js' ); return false; diff --git a/test/function/duplicate-import-fails/_config.js b/test/function/duplicate-import-fails/_config.js index 4280c53..4083690 100644 --- a/test/function/duplicate-import-fails/_config.js +++ b/test/function/duplicate-import-fails/_config.js @@ -4,7 +4,7 @@ var assert = require( 'assert' ); module.exports = { description: 'disallows duplicate imports', error: function ( err ) { - assert.equal( err.file, path.resolve( __dirname, 'main.js' ) ); + assert.equal( path.normalize(err.file), path.resolve( __dirname, 'main.js' ) ); assert.deepEqual( err.loc, { line: 2, column: 9 }); assert.ok( /Duplicated import/.test( err.message ) ); } diff --git a/test/function/duplicate-import-specifier-fails/_config.js b/test/function/duplicate-import-specifier-fails/_config.js index b935a69..e3957b5 100644 --- a/test/function/duplicate-import-specifier-fails/_config.js +++ b/test/function/duplicate-import-specifier-fails/_config.js @@ -4,7 +4,7 @@ var assert = require( 'assert' ); module.exports = { description: 'disallows duplicate import specifiers', error: function ( err ) { - assert.equal( err.file, path.resolve( __dirname, 'main.js' ) ); + assert.equal( path.normalize(err.file), path.resolve( __dirname, 'main.js' ) ); assert.deepEqual( err.loc, { line: 1, column: 12 }); assert.ok( /Duplicated import/.test( err.message ) ); } diff --git a/test/function/export-not-at-top-level-fails/_config.js b/test/function/export-not-at-top-level-fails/_config.js index c68ca42..2dadeab 100644 --- a/test/function/export-not-at-top-level-fails/_config.js +++ b/test/function/export-not-at-top-level-fails/_config.js @@ -4,7 +4,7 @@ var assert = require( 'assert' ); module.exports = { description: 'disallows non-top-level exports', error: function ( err ) { - assert.equal( err.file, path.resolve( __dirname, 'main.js' ) ); + assert.equal( path.normalize(err.file), path.resolve( __dirname, 'main.js' ) ); assert.deepEqual( err.loc, { line: 2, column: 2 }); assert.ok( /may only appear at the top level/.test( err.message ) ); } diff --git a/test/function/import-default-from-external/main.js b/test/function/import-default-from-external/main.js index 5d5cd6d..aacce04 100644 --- a/test/function/import-default-from-external/main.js +++ b/test/function/import-default-from-external/main.js @@ -4,4 +4,4 @@ import path from 'path'; var path1 = 'foo/bar/baz'; var path2 = 'foo/baz/bar'; -assert.equal( path.relative( path1, path2 ), '../../baz/bar' ); \ No newline at end of file +assert.equal( path.relative( path1, path2 ), path.normalize('../../baz/bar') ); \ No newline at end of file diff --git a/test/function/import-named-from-external/main.js b/test/function/import-named-from-external/main.js index 49027f6..1030a82 100644 --- a/test/function/import-named-from-external/main.js +++ b/test/function/import-named-from-external/main.js @@ -1,6 +1,6 @@ -import { relative } from 'path'; +import { relative, normalize } from 'path'; var path = 'foo/bar/baz'; var path2 = 'foo/baz/bar'; -assert.equal( relative( path, path2 ), '../../baz/bar' ); \ No newline at end of file +assert.equal( relative( path, path2 ), normalize('../../baz/bar') ); \ No newline at end of file diff --git a/test/function/import-namespace-from-external-module-renamed/main.js b/test/function/import-namespace-from-external-module-renamed/main.js index 2208cd4..947231e 100644 --- a/test/function/import-namespace-from-external-module-renamed/main.js +++ b/test/function/import-namespace-from-external-module-renamed/main.js @@ -3,4 +3,4 @@ import * as node_path from 'path'; var path1 = 'foo/bar/baz'; var path2 = 'foo/baz/bar'; -assert.equal( node_path.relative( path1, path2 ), '../../baz/bar' ); +assert.equal( node_path.relative( path1, path2 ), node_path.normalize('../../baz/bar') ); diff --git a/test/function/import-namespace-from-external-module/main.js b/test/function/import-namespace-from-external-module/main.js index 000a219..10f9d36 100644 --- a/test/function/import-namespace-from-external-module/main.js +++ b/test/function/import-namespace-from-external-module/main.js @@ -3,4 +3,4 @@ import * as path from 'path'; var path1 = 'foo/bar/baz'; var path2 = 'foo/baz/bar'; -assert.equal( path.relative( path1, path2 ), '../../baz/bar' ); \ No newline at end of file +assert.equal( path.relative( path1, path2 ), path.normalize('../../baz/bar') ); \ No newline at end of file diff --git a/test/function/import-not-at-top-level-fails/_config.js b/test/function/import-not-at-top-level-fails/_config.js index c75e986..4f873aa 100644 --- a/test/function/import-not-at-top-level-fails/_config.js +++ b/test/function/import-not-at-top-level-fails/_config.js @@ -4,7 +4,7 @@ var assert = require( 'assert' ); module.exports = { description: 'disallows non-top-level imports', error: function ( err ) { - assert.equal( err.file, path.resolve( __dirname, 'main.js' ) ); + assert.equal( path.normalize(err.file), path.resolve( __dirname, 'main.js' ) ); assert.deepEqual( err.loc, { line: 2, column: 2 }); assert.ok( /may only appear at the top level/.test( err.message ) ); } diff --git a/test/function/imports-are-deconflicted-b/main.js b/test/function/imports-are-deconflicted-b/main.js index fa81bd0..cf917fc 100644 --- a/test/function/imports-are-deconflicted-b/main.js +++ b/test/function/imports-are-deconflicted-b/main.js @@ -1,5 +1,6 @@ import foo from './foo'; import bar from './bar'; +import { normalize } from 'path'; assert.equal( foo, 'foo' ); -assert.equal( bar(), '../../baz/bar' ); +assert.equal( bar(), normalize('../../baz/bar') ); diff --git a/test/function/imports-are-deconflicted/main.js b/test/function/imports-are-deconflicted/main.js index fa81bd0..cf917fc 100644 --- a/test/function/imports-are-deconflicted/main.js +++ b/test/function/imports-are-deconflicted/main.js @@ -1,5 +1,6 @@ import foo from './foo'; import bar from './bar'; +import { normalize } from 'path'; assert.equal( foo, 'foo' ); -assert.equal( bar(), '../../baz/bar' ); +assert.equal( bar(), normalize('../../baz/bar') ); diff --git a/test/function/namespace-reassign-import-fails/_config.js b/test/function/namespace-reassign-import-fails/_config.js index 7e2d7a8..2d606f4 100644 --- a/test/function/namespace-reassign-import-fails/_config.js +++ b/test/function/namespace-reassign-import-fails/_config.js @@ -4,7 +4,7 @@ var assert = require( 'assert' ); module.exports = { description: 'disallows reassignments to namespace exports', error: function ( err ) { - assert.equal( err.file, path.resolve( __dirname, 'main.js' ) ); + assert.equal( path.normalize(err.file), path.resolve( __dirname, 'main.js' ) ); assert.deepEqual( err.loc, { line: 3, column: 0 }); assert.ok( /Illegal reassignment/.test( err.message ) ); } diff --git a/test/function/namespace-update-import-fails/_config.js b/test/function/namespace-update-import-fails/_config.js index 116f4d0..4cff5c0 100644 --- a/test/function/namespace-update-import-fails/_config.js +++ b/test/function/namespace-update-import-fails/_config.js @@ -4,7 +4,7 @@ var assert = require( 'assert' ); module.exports = { description: 'disallows updates to namespace exports', error: function ( err ) { - assert.equal( err.file, path.resolve( __dirname, 'main.js' ) ); + assert.equal( path.normalize(err.file), path.resolve( __dirname, 'main.js' ) ); assert.deepEqual( err.loc, { line: 3, column: 0 }); assert.ok( /Illegal reassignment/.test( err.message ) ); } diff --git a/test/function/reassign-import-fails/_config.js b/test/function/reassign-import-fails/_config.js index c73c36d..e01d090 100644 --- a/test/function/reassign-import-fails/_config.js +++ b/test/function/reassign-import-fails/_config.js @@ -4,7 +4,7 @@ var assert = require( 'assert' ); module.exports = { description: 'disallows assignments to imported bindings', error: function ( err ) { - assert.equal( err.file, path.resolve( __dirname, 'main.js' ) ); + assert.equal( path.normalize(err.file), path.resolve( __dirname, 'main.js' ) ); assert.deepEqual( err.loc, { line: 8, column: 0 }); assert.ok( /Illegal reassignment/.test( err.message ) ); } diff --git a/test/function/reassign-import-not-at-top-level-fails/_config.js b/test/function/reassign-import-not-at-top-level-fails/_config.js index d17af29..6e00786 100644 --- a/test/function/reassign-import-not-at-top-level-fails/_config.js +++ b/test/function/reassign-import-not-at-top-level-fails/_config.js @@ -4,7 +4,7 @@ var assert = require( 'assert' ); module.exports = { description: 'disallows assignments to imported bindings not at the top level', error: function ( err ) { - assert.equal( err.file, path.resolve( __dirname, 'main.js' ) ); + assert.equal( path.normalize(err.file), path.resolve( __dirname, 'main.js' ) ); assert.deepEqual( err.loc, { line: 7, column: 2 }); assert.ok( /Illegal reassignment/.test( err.message ) ); } diff --git a/test/function/shadowed-external-export/main.js b/test/function/shadowed-external-export/main.js index d8a080a..37ce4be 100644 --- a/test/function/shadowed-external-export/main.js +++ b/test/function/shadowed-external-export/main.js @@ -1,4 +1,4 @@ -import { relative } from 'path'; +import { relative, normalize } from 'path'; var paths = {}; function getRelativePath ( path, path2 ) { @@ -6,5 +6,5 @@ function getRelativePath ( path, path2 ) { return relative( path, path2 ); } -assert.equal( getRelativePath( 'foo/bar/baz', 'foo/baz/bar' ), '../../baz/bar' ); +assert.equal( getRelativePath( 'foo/bar/baz', 'foo/baz/bar' ), normalize('../../baz/bar') ); assert.deepEqual( paths, { 'foo/bar/baz': true }); diff --git a/test/function/update-expression-of-import-fails/_config.js b/test/function/update-expression-of-import-fails/_config.js index f2f1390..5f5c27c 100644 --- a/test/function/update-expression-of-import-fails/_config.js +++ b/test/function/update-expression-of-import-fails/_config.js @@ -4,7 +4,7 @@ var assert = require( 'assert' ); module.exports = { description: 'disallows updates to imported bindings', error: function ( err ) { - assert.equal( err.file, path.resolve( __dirname, 'main.js' ) ); + assert.equal( path.normalize(err.file), path.resolve( __dirname, 'main.js' ) ); assert.deepEqual( err.loc, { line: 3, column: 0 }); assert.ok( /Illegal reassignment/.test( err.message ) ); } diff --git a/test/test.js b/test/test.js index 4adad98..1139505 100644 --- a/test/test.js +++ b/test/test.js @@ -2,6 +2,7 @@ require( 'source-map-support' ).install(); require( 'console-group' ).install(); var path = require( 'path' ); +var os = require( 'os' ); var sander = require( 'sander' ); var assert = require( 'assert' ); var exec = require( 'child_process' ).exec; @@ -244,9 +245,13 @@ describe( 'rollup', function () { ( config.skip ? it.skip : config.solo ? it.only : it )( dir, function ( done ) { process.chdir( path.resolve( CLI, dir ) ); + if (os.platform() === 'win32') { + config.command = "node " + path.resolve( __dirname, '../bin' ) + path.sep + config.command; + } + exec( config.command, { env: { - PATH: path.resolve( __dirname, '../bin' ) + ':' + process.env.PATH + PATH: path.resolve( __dirname, '../bin' ) + path.delimiter + process.env.PATH } }, function ( err, code, stderr ) { if ( err ) return done( err );