1- 'use strict' ;
1+ import assert from 'node:assert/strict' ;
2+ import path from 'node:path' ;
3+ import { fileURLToPath } from 'node:url' ;
4+ import { suite } from 'uvu' ;
5+ import resolvePath from '../index.js' ;
26
3- const assert = require ( 'node:assert' ) . strict ;
4- const path = require ( 'node:path' ) ;
5- const { suite } = require ( 'uvu' ) ;
6- const resolvePath = require ( '../index.js' ) ;
7+ const directory = fileURLToPath ( new URL ( '.' , import . meta. url ) ) ;
78
89const test = suite ( 'resolve-dependency-path' ) ;
910const multiPeriod = suite ( 'multiple period filenames' ) ;
@@ -27,22 +28,20 @@ test('throws if the directory is missing', () => {
2728 assert . throws ( ( ) => {
2829 resolvePath ( {
2930 dependency : './bar' ,
30- filename : path . join ( __dirname , '/foo.js' )
31+ filename : path . join ( directory , '/foo.js' )
3132 } ) ;
3233 } , / ^ E r r o r : d i r e c t o r y n o t g i v e n $ / ) ;
3334} ) ;
3435
3536test ( 'resolves with absolute paths' , ( ) => {
3637 const dependency = './bar' ;
37- const directory = __dirname ;
3838 const filename = path . join ( directory , '/foo.js' ) ;
3939 const resolved = resolvePath ( { dependency, filename, directory } ) ;
4040 assert . equal ( resolved . startsWith ( directory ) , true ) ;
4141} ) ;
4242
4343test ( 'resolves w/initial period, w/ending in .js' , ( ) => {
4444 const dependency = './index' ;
45- const directory = __dirname ;
4645 const filename = path . join ( directory , '/foo.js' ) ;
4746 const resolved = resolvePath ( { dependency, filename, directory } ) ;
4847 const expected = path . join ( directory , '/index.js' ) ;
@@ -51,7 +50,6 @@ test('resolves w/initial period, w/ending in .js', () => {
5150
5251test ( 'resolves w/initial period, w/o ending in .js' , ( ) => {
5352 const dependency = './index.js' ;
54- const directory = __dirname ;
5553 const filename = path . join ( directory , '/foo.js' ) ;
5654 const resolved = resolvePath ( { dependency, filename, directory } ) ;
5755 const expected = path . join ( directory , '/index.js' ) ;
@@ -60,7 +58,6 @@ test('resolves w/initial period, w/o ending in .js', () => {
6058
6159test ( 'resolves w/o initial period, w/o ending in .js' , ( ) => {
6260 const dependency = 'index' ;
63- const directory = __dirname ;
6461 const filename = path . join ( directory , '/foo.js' ) ;
6562 const resolved = resolvePath ( { dependency, filename, directory } ) ;
6663 const expected = path . join ( directory , '/index.js' ) ;
@@ -69,7 +66,6 @@ test('resolves w/o initial period, w/o ending in .js', () => {
6966
7067test ( 'resolves w/o initial period, w/ending in .js' , ( ) => {
7168 const dependency = 'index.js' ;
72- const directory = __dirname ;
7369 const filename = path . join ( directory , '/foo.js' ) ;
7470 const resolved = resolvePath ( { dependency, filename, directory } ) ;
7571 const expected = path . join ( directory , '/index.js' ) ;
@@ -78,7 +74,6 @@ test('resolves w/o initial period, w/ending in .js', () => {
7874
7975test ( 'resolves relative paths' , ( ) => {
8076 const dependency = './bar.js' ;
81- const directory = __dirname ;
8277 const filename = path . join ( directory , '/foo.js' ) ;
8378 const resolved = resolvePath ( { dependency, filename, directory } ) ;
8479 const expected = path . join ( directory , '/bar.js' ) ;
@@ -87,7 +82,6 @@ test('resolves relative paths', () => {
8782
8883test ( 'resolves non-relative paths' , ( ) => {
8984 const dependency = 'feature2/bar' ;
90- const directory = __dirname ;
9185 const filename = path . join ( directory , '/feature1/foo.js' ) ;
9286 const resolved = resolvePath ( { dependency, filename, directory } ) ;
9387 const expected = path . join ( directory , '/feature2/bar.js' ) ;
@@ -96,7 +90,6 @@ test('resolves non-relative paths', () => {
9690
9791multiPeriod ( 'resolves with multiple periods in the dependency path' , ( ) => {
9892 const dependency = './bar.baz.qux' ;
99- const directory = __dirname ;
10093 const filename = path . join ( directory , '/foo.js' ) ;
10194 const resolved = resolvePath ( { dependency, filename, directory } ) ;
10295 const expected = path . join ( directory , '/bar.baz.qux.js' ) ;
@@ -105,7 +98,6 @@ multiPeriod('resolves with multiple periods in the dependency path', () => {
10598
10699multiPeriod ( 'does not duplicate extensions' , ( ) => {
107100 const dependency = '../index.js' ;
108- const directory = __dirname ;
109101 const filename = path . join ( directory , '/foo.js' ) ;
110102 const resolved = resolvePath ( { dependency, filename, directory } ) ;
111103 // Extension after removing the .js extension
@@ -115,55 +107,48 @@ multiPeriod('does not duplicate extensions', () => {
115107
116108multiPeriod ( 'does not add the incorrect extension for sass files' , ( ) => {
117109 const dependency = 'styles' ;
118- const directory = __dirname ;
119110 const filename = path . join ( directory , '/foo.scss' ) ;
120111 const resolved = resolvePath ( { dependency, filename, directory } ) ;
121112 assert . equal ( path . extname ( resolved ) , '.scss' ) ;
122113} ) ;
123114
124115multiPeriod ( 'does not add the incorrect extension for mustache files' , ( ) => {
125116 const dependency = 'hgn!templates/foo.mustache' ;
126- const directory = __dirname ;
127117 const filename = path . join ( directory , '/foo.js' ) ;
128118 const resolved = resolvePath ( { dependency, filename, directory } ) ;
129119 assert . equal ( path . extname ( resolved ) , '.mustache' ) ;
130120} ) ;
131121
132122implicitPlugins ( 'resolve w/initial period' , ( ) => {
133123 const dependency = './templates/file.css!' ;
134- const directory = __dirname ;
135124 const filename = path . join ( directory , '/foo.js' ) ;
136125 const resolved = resolvePath ( { dependency, filename, directory } ) ;
137126 assert . equal ( path . extname ( resolved ) , '.css' ) ;
138127} ) ;
139128
140129implicitPlugins ( 'resolve w/o initial period' , ( ) => {
141130 const dependency = 'templates/file.css!' ;
142- const directory = __dirname ;
143131 const filename = path . join ( directory , '/foo.js' ) ;
144132 const resolved = resolvePath ( { dependency, filename, directory } ) ;
145133 assert . equal ( path . extname ( resolved ) , '.css' ) ;
146134} ) ;
147135
148136explicitPlugins ( 'resolve w/initial period' , ( ) => {
149137 const dependency = './templates/file.txt!text' ;
150- const directory = __dirname ;
151138 const filename = path . join ( directory , '/foo.js' ) ;
152139 const resolved = resolvePath ( { dependency, filename, directory } ) ;
153140 assert . equal ( path . extname ( resolved ) , '.txt' ) ;
154141} ) ;
155142
156143explicitPlugins ( 'resolve w/o initial period' , ( ) => {
157144 const dependency = 'templates/file.txt!text' ;
158- const directory = __dirname ;
159145 const filename = path . join ( directory , '/foo.js' ) ;
160146 const resolved = resolvePath ( { dependency, filename, directory } ) ;
161147 assert . equal ( path . extname ( resolved ) , '.txt' ) ;
162148} ) ;
163149
164150webpackSupport . skip ( 'resolves properly' , ( ) => {
165151 const dependency = './styles/foo.css' ;
166- const directory = __dirname ;
167152 const filename = path . join ( directory , '/foo.js' ) ;
168153 const resolved = resolvePath ( { dependency, filename, directory } ) ;
169154 assert . equal ( path . extname ( resolved ) , '.css' ) ;
0 commit comments