Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

fix #11 support window path #12

Closed
wants to merge 2 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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"npm-run-all": "^1.5.1",
"nyc": "^5.6.0",
"rimraf": "^2.5.2",
"rollup": "^0.25.4",
"rollup": "^0.36.3",
"rollup-babel-lib-bundler": "^2.2.4"
}
},
"dependencies": {}
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fs from 'fs';
const noop = () => null;
const startsWith = (needle, haystack) => ! haystack.indexOf(needle);
const endsWith = (needle, haystack) => haystack.slice(-needle.length) === needle;
const isFilePath = id => /^\.?\//.test(id);
const isFilePath = id => /(^\.?\/)|(^[a-zA-Z]\:(\\|\/))/.test(id);
const exists = uri => {
try {
return fs.statSync(uri).isFile();
Expand Down
1 change: 1 addition & 0 deletions test/files/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ import anotherNumber from './numberFolder/anotherNumber';
import moreNumbers from 'numberFolder/anotherNumber';

export default fancyNumber + anotherFancyNumber + nonAliased + anotherNumber + moreNumbers;

42 changes: 27 additions & 15 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import test from 'ava';
import path from 'path';
import { rollup } from 'rollup';
import alias from '../dist/rollup-plugin-alias';
import os from 'os';
const isWin = os.platform() === 'win32';
const root = isWin ? 'F:\\' : '/';

test(t => {
t.is(typeof alias, 'function');
Expand Down Expand Up @@ -40,15 +43,16 @@ test(t => {
pony: './par/a/di/se',
});


const resolved = result.resolveId('foo', '/src/importer.js');
const resolved2 = result.resolveId('foo/baz', '/src/importer.js');
const resolved3 = result.resolveId('foo/baz.js', '/src/importer.js');
const resolved4 = result.resolveId('pony', '/src/highly/nested/importer.js');

t.is(resolved, '/src/bar.js');
t.is(resolved2, '/src/bar/baz.js');
t.is(resolved3, '/src/bar/baz.js');
t.is(resolved4, '/src/highly/nested/par/a/di/se.js');
t.is(resolved, path.resolve(root, '/src/bar.js'));
t.is(resolved2, path.resolve(root, '/src/bar/baz.js'));
t.is(resolved3, path.resolve(root, '/src/bar/baz.js'));
t.is(resolved4, path.resolve(root, '/src/highly/nested/par/a/di/se.js'));
});

// Absolute local aliasing
Expand All @@ -63,10 +67,10 @@ test(t => {
const resolved3 = result.resolveId('foo/baz.js', '/src/importer.js');
const resolved4 = result.resolveId('pony', '/src/highly/nested/importer.js');

t.is(resolved, '/bar.js');
t.is(resolved2, '/bar/baz.js');
t.is(resolved3, '/bar/baz.js');
t.is(resolved4, '/par/a/di/se.js');
t.is(resolved, path.resolve(root, '/bar.js'));
t.is(resolved2, path.resolve(root, '/bar/baz.js'));
t.is(resolved3, path.resolve(root, '/bar/baz.js'));
t.is(resolved4, path.resolve(root, '/par/a/di/se.js'));
});

// Test for the resolve property
Expand Down Expand Up @@ -102,21 +106,29 @@ test(t => {
});

// Tests in Rollup
test(t =>
test('Tests in Rollup', t =>
rollup({
entry: './files/index.js',
entry: isWin ? './test/files/index.js' : './files/index.js',
plugins: [alias({
fancyNumber: './aliasMe',
'./anotherFancyNumber': './localAliasMe',
numberFolder: './folder',
'./numberFolder': './folder',
})],
}).then(stats => {
t.is(stats.modules[0].id.endsWith('/files/nonAliased.js'), true);
t.is(stats.modules[1].id.endsWith('/files/aliasMe.js'), true);
t.is(stats.modules[2].id.endsWith('/files/localAliasMe.js'), true);
t.is(stats.modules[3].id.endsWith('/files/folder/anotherNumber.js'), true);
t.is(stats.modules[4].id.endsWith('/files/index.js'), true);
if (isWin) {
t.is(stats.modules[0].id.endsWith('\\files\\nonAliased.js'), true);
t.is(stats.modules[1].id.endsWith('\\files\\aliasMe.js'), true);
t.is(stats.modules[2].id.endsWith('\\files\\localAliasMe.js'), true);
t.is(stats.modules[3].id.endsWith('\\files\\folder\\anotherNumber.js'), true);
t.is(stats.modules[4].id.endsWith('\\files\\index.js'), true);
} else {
t.is(stats.modules[0].id.endsWith('/files/nonAliased.js'), true);
t.is(stats.modules[1].id.endsWith('/files/aliasMe.js'), true);
t.is(stats.modules[2].id.endsWith('/files/localAliasMe.js'), true);
t.is(stats.modules[3].id.endsWith('/files/folder/anotherNumber.js'), true);
t.is(stats.modules[4].id.endsWith('/files/index.js'), true);
}
t.is(stats.modules.length, 5);
})
);