Browse Source

ensure import paths are case-sensitive (#590)

rewrite
Rich Harris 9 years ago
parent
commit
bcd5dc789c
  1. 11
      src/utils/defaults.js
  2. 3
      test/function/paths-are-case-sensitive/Foo.js
  3. 8
      test/function/paths-are-case-sensitive/_config.js
  4. 3
      test/function/paths-are-case-sensitive/main.js

11
src/utils/defaults.js

@ -1,5 +1,5 @@
import { isFile, readFileSync } from './fs.js';
import { dirname, isAbsolute, resolve } from './path.js';
import { isFile, readdirSync, readFileSync } from './fs.js';
import { basename, dirname, isAbsolute, resolve } from './path.js';
import { blank } from './object.js';
export function load ( id ) {
@ -7,10 +7,11 @@ export function load ( id ) {
}
function addJsExtensionIfNecessary ( file ) {
if ( isFile( file ) ) return file;
const name = basename( file );
const files = readdirSync( dirname( file ) );
file += '.js';
if ( isFile( file ) ) return file;
if ( ~files.indexOf( name ) && isFile( file ) ) return file;
if ( ~files.indexOf( `${name}.js` ) && isFile( `${file}.js` ) ) return `${file}.js`;
return null;
}

3
test/function/paths-are-case-sensitive/Foo.js

@ -0,0 +1,3 @@
export default function () {
assert.ok( false );
}

8
test/function/paths-are-case-sensitive/_config.js

@ -0,0 +1,8 @@
var assert = require( 'assert' );
module.exports = {
description: 'insists on correct casing for imports',
error: function ( err ) {
assert.ok( /Could not resolve/.test( err.message ) );
}
};

3
test/function/paths-are-case-sensitive/main.js

@ -0,0 +1,3 @@
import foo from './foo.js';
foo();
Loading…
Cancel
Save