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

Commit e423fe6

Browse files
committed
update import names for path and poisx
make it more clear
1 parent f752133 commit e423fe6

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import platformPath, { posix as path } from 'path';
1+
import path, { posix } from 'path';
22
import { platform } from 'os';
33
import fs from 'fs';
44

@@ -68,10 +68,10 @@ export default function alias(options = {}) {
6868
let updatedId = normalizeId(importeeId.replace(toReplace, entry));
6969

7070
if (isFilePath(updatedId)) {
71-
const directory = path.dirname(importerId);
71+
const directory = posix.dirname(importerId);
7272

7373
// Resolve file names
74-
const filePath = path.resolve(directory, updatedId);
74+
const filePath = posix.resolve(directory, updatedId);
7575
const match = resolve.map(ext => (endsWith(ext, filePath) ? filePath : `${filePath}${ext}`))
7676
.find(exists);
7777

@@ -86,11 +86,11 @@ export default function alias(options = {}) {
8686
}
8787
}
8888

89-
// if alias is windows absoulate path return platform
90-
// resolved path or rollup on windows will throw:
89+
// if alias is windows absoulate path return resolved path or
90+
// rollup on windows will throw:
9191
// [TypeError: Cannot read property 'specifier' of undefined]
9292
if (VOLUME.test(entry)) {
93-
return platformPath.resolve(updatedId);
93+
return path.resolve(updatedId);
9494
}
9595

9696
return updatedId;

test/index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import test from 'ava';
2-
import paltformPath, { posix as path } from 'path';
2+
import path, { posix } from 'path';
33
import { rollup } from 'rollup';
44
import alias from '../dist/rollup-plugin-alias';
55
import slash from 'slash';
@@ -94,9 +94,9 @@ test('Test for the resolve property', t => {
9494
resolve: ['.js', '.jsx'],
9595
});
9696

97-
const resolved = result.resolveId('ember', path.resolve(DIRNAME, './files/index.js'));
97+
const resolved = result.resolveId('ember', posix.resolve(DIRNAME, './files/index.js'));
9898

99-
t.is(resolved, path.resolve(DIRNAME, './files/folder/hipster.jsx'));
99+
t.is(resolved, posix.resolve(DIRNAME, './files/folder/hipster.jsx'));
100100
});
101101

102102
test(t => {
@@ -114,21 +114,21 @@ test(t => {
114114
resolve: './i/am/a/local/file',
115115
});
116116

117-
const resolved = result.resolveId('resolve', path.resolve(DIRNAME, './files/index.js'));
117+
const resolved = result.resolveId('resolve', posix.resolve(DIRNAME, './files/index.js'));
118118

119-
t.is(resolved, path.resolve(DIRNAME, './files/i/am/a/local/file.js'));
119+
t.is(resolved, posix.resolve(DIRNAME, './files/i/am/a/local/file.js'));
120120
});
121121

122122
// this test with old behaviour will fail on windows and pass on Uinx-Like platforms
123123
test('Platform path.resolve(\'file-without-extension\') aliasing', t => {
124124
// this what used in React and Vue
125125
const result = alias({
126-
test: paltformPath.resolve('./files/aliasMe'),
126+
test: path.resolve('./files/aliasMe'),
127127
});
128128

129-
const resolved = result.resolveId('test', path.resolve(DIRNAME, './files/index.js'));
129+
const resolved = result.resolveId('test', posix.resolve(DIRNAME, './files/index.js'));
130130

131-
t.is(resolved, paltformPath.resolve('./files/aliasMe.js'));
131+
t.is(resolved, path.resolve('./files/aliasMe.js'));
132132
});
133133

134134
// this test with old behaviour will fail on windows and Uinx-Like platforms
@@ -137,7 +137,7 @@ test('Windows absolute path aliasing', t => {
137137
resolve: 'E:\\react\\node_modules\\fbjs\\lib\\warning',
138138
});
139139

140-
const resolved = result.resolveId('resolve', path.resolve(DIRNAME, './files/index.js'));
140+
const resolved = result.resolveId('resolve', posix.resolve(DIRNAME, './files/index.js'));
141141

142142
t.is(
143143
normalizePath(resolved),
@@ -147,13 +147,13 @@ test('Windows absolute path aliasing', t => {
147147

148148
test('Platform path.resolve(\'file-with.ext\') aliasing', t => {
149149
const result = alias({
150-
test: paltformPath.resolve('./files/folder/hipster.jsx'),
150+
test: path.resolve('./files/folder/hipster.jsx'),
151151
resolve: ['.js', '.jsx'],
152152
});
153153

154-
const resolved = result.resolveId('test', path.resolve(DIRNAME, './files/index.js'));
154+
const resolved = result.resolveId('test', posix.resolve(DIRNAME, './files/index.js'));
155155

156-
t.is(resolved, paltformPath.resolve('./files/folder/hipster.jsx'));
156+
t.is(resolved, path.resolve('./files/folder/hipster.jsx'));
157157
});
158158

159159
// Tests in Rollup

0 commit comments

Comments
 (0)