From 773563fc78661e6cbd9491e0c9cac9a2dfdf001f Mon Sep 17 00:00:00 2001 From: ideayuye <576135266@qq.com> Date: Wed, 23 Nov 2016 10:19:55 +0800 Subject: [PATCH 1/2] support windows system --- package.json | 5 +++-- src/index.js | 2 +- test/files/index.js | 1 + test/index.js | 42 +++++++++++++++++++++++++++--------------- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 21e0f21..04ae0a1 100644 --- a/package.json +++ b/package.json @@ -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": {} } diff --git a/src/index.js b/src/index.js index 4f0fd28..52e83ee 100644 --- a/src/index.js +++ b/src/index.js @@ -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(); diff --git a/test/files/index.js b/test/files/index.js index 2a79b50..8246231 100644 --- a/test/files/index.js +++ b/test/files/index.js @@ -5,3 +5,4 @@ import anotherNumber from './numberFolder/anotherNumber'; import moreNumbers from 'numberFolder/anotherNumber'; export default fancyNumber + anotherFancyNumber + nonAliased + anotherNumber + moreNumbers; + diff --git a/test/index.js b/test/index.js index 87405c7..55dd14b 100644 --- a/test/index.js +++ b/test/index.js @@ -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'); @@ -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 @@ -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 @@ -102,9 +106,9 @@ test(t => { }); // Tests in Rollup -test(t => +test('Tests in Rollup', t => rollup({ - entry: './files/index.js', + entry: './test/files/index.js', plugins: [alias({ fancyNumber: './aliasMe', './anotherFancyNumber': './localAliasMe', @@ -112,11 +116,19 @@ test(t => './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); }) ); From 15bb00a0c11f8bb470f7fd094181add85aaa4f7e Mon Sep 17 00:00:00 2001 From: ideayuye <576135266@qq.com> Date: Wed, 23 Nov 2016 13:00:14 +0800 Subject: [PATCH 2/2] modify test path --- test/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/index.js b/test/index.js index 55dd14b..f75aa9b 100644 --- a/test/index.js +++ b/test/index.js @@ -108,7 +108,7 @@ test(t => { // Tests in Rollup test('Tests in Rollup', t => rollup({ - entry: './test/files/index.js', + entry: isWin ? './test/files/index.js' : './files/index.js', plugins: [alias({ fancyNumber: './aliasMe', './anotherFancyNumber': './localAliasMe',