44
55const { randomBytes } = require ( 'crypto' )
66const specifiers = new Map ( )
7- const isWin = process . platform === " win32"
7+ const isWin = process . platform === ' win32'
88
99// FIXME: Typescript extensions are added temporarily until we find a better
1010// way of supporting arbitrary extensions
@@ -16,7 +16,7 @@ const NODE_MINOR = Number(NODE_VERSION[1])
1616let entrypoint
1717
1818let getExports
19- if ( NODE_MAJOR >= 20 || ( NODE_MAJOR == 18 && NODE_MINOR >= 19 ) ) {
19+ if ( NODE_MAJOR >= 20 || ( NODE_MAJOR === 18 && NODE_MINOR >= 19 ) ) {
2020 getExports = require ( './lib/get-exports.js' )
2121} else {
2222 getExports = ( { url } ) => import ( url ) . then ( Object . keys )
@@ -56,7 +56,7 @@ function deleteIitm (url) {
5656 return resultUrl
5757}
5858
59- function isNode16AndBiggerOrEqualsThan16_17_0 ( ) {
59+ function isNodeMajor16AndMinor17OrGreater ( ) {
6060 return NODE_MAJOR === 16 && NODE_MINOR >= 17
6161}
6262
@@ -68,11 +68,11 @@ function isNodeProtocol (urlObj) {
6868 return urlObj . protocol === 'node:'
6969}
7070
71- function needsToAddFileProtocol ( urlObj ) {
71+ function needsToAddFileProtocol ( urlObj ) {
7272 if ( NODE_MAJOR === 17 ) {
7373 return ! isFileProtocol ( urlObj )
7474 }
75- if ( isNode16AndBiggerOrEqualsThan16_17_0 ( ) ) {
75+ if ( isNodeMajor16AndMinor17OrGreater ( ) ) {
7676 return ! isFileProtocol ( urlObj ) && ! isNodeProtocol ( urlObj )
7777 }
7878 return ! isFileProtocol ( urlObj ) && NODE_MAJOR < 18
@@ -87,7 +87,7 @@ function needsToAddFileProtocol(urlObj) {
8787 * @param {string } line
8888 * @returns {boolean }
8989 */
90- function isStarExportLine ( line ) {
90+ function isStarExportLine ( line ) {
9191 return / ^ \* f r o m / . test ( line )
9292}
9393
@@ -124,7 +124,7 @@ function isStarExportLine(line) {
124124 *
125125 * @returns {Promise<ProcessedModule> }
126126 */
127- async function processModule ( {
127+ async function processModule ( {
128128 srcUrl,
129129 context,
130130 parentGetSource,
@@ -152,7 +152,7 @@ async function processModule({
152152
153153 for ( const n of exportNames ) {
154154 if ( isStarExportLine ( n ) === true ) {
155- const [ _ , modFile ] = n . split ( '* from ' )
155+ const [ , modFile ] = n . split ( '* from ' )
156156 const normalizedModName = normalizeModName ( modFile )
157157 const modUrl = new URL ( modFile , srcUrl ) . toString ( )
158158 const modName = Buffer . from ( modFile , 'hex' ) + Date . now ( ) + randomBytes ( 4 ) . toString ( 'hex' )
@@ -191,7 +191,7 @@ async function processModule({
191191 continue
192192 }
193193
194- setters . set ( `$${ n } ` + ns , `
194+ setters . set ( `$${ n } ` + ns , `
195195 let $${ n } = ${ ns } .${ n }
196196 export { $${ n } as ${ n } }
197197 set.${ n } = (v) => {
@@ -214,9 +214,9 @@ async function processModule({
214214 *
215215 * @returns {string } The normalized identifier.
216216 */
217- function normalizeModName ( name ) {
217+ function normalizeModName ( name ) {
218218 return name
219- . split ( '\ /' )
219+ . split ( '/' )
220220 . pop ( )
221221 . replace ( / ( .+ ) \. (?: j s | m j s ) $ / , '$1' )
222222 . replaceAll ( / ( - .) / g, x => x [ 1 ] . toUpperCase ( ) )
@@ -253,7 +253,6 @@ function createHook (meta) {
253253 return url
254254 }
255255
256-
257256 specifiers . set ( url . url , specifier )
258257
259258 return {
@@ -268,9 +267,9 @@ function createHook (meta) {
268267 if ( hasIitm ( url ) ) {
269268 const realUrl = deleteIitm ( url )
270269 const { imports, namespaces, setters : mapSetters } = await processModule ( {
271- srcUrl : realUrl ,
272- context,
273- parentGetSource
270+ srcUrl : realUrl ,
271+ context,
272+ parentGetSource
274273 } )
275274 const setters = Array . from ( mapSetters . values ( ) )
276275
@@ -284,7 +283,7 @@ function createHook (meta) {
284283 const renamedDefaults = setters
285284 . map ( s => {
286285 const matches = / l e t \$ ( .+ ) = ( \$ .+ ) \. d e f a u l t / . exec ( s )
287- if ( matches === null ) return
286+ if ( matches === null ) return undefined
288287 return `_['${ matches [ 1 ] } '] = ${ matches [ 2 ] } .default`
289288 } )
290289 . filter ( s => s )
0 commit comments