forked from stateful/vscode-runme
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump to Node v20.17.0 (stateful#1696)
* Bump to NodeJS v20.17.0 * Node modules cleanup * Code cleanup
- Loading branch information
Showing
14 changed files
with
125 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v18.19.0 | ||
v20.17.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
nodejs 18.20.2 | ||
nodejs 20.17.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import {dirname, isAbsolute, join, extname} from 'node:path' | ||
import {cwd} from 'node:process' | ||
import {readFile} from 'node:fs/promises' | ||
|
||
|
||
let warn = (field, desc) => console.warn('⚠️ \x1b[33m%s\x1b[0m', | ||
`Warning: The package.json field 'extensionless.${field}' must be ${desc}! Using the default value instead...`) | ||
|
||
let getPkgJson = async dirPath => { | ||
do { | ||
let path = join(dirPath, 'package.json') | ||
|
||
try { | ||
return {body: JSON.parse(await readFile(path, 'utf8')), path} | ||
} catch (e) { | ||
if (!['ENOTDIR', 'ENOENT', 'EISDIR'].includes(e.code)) { | ||
throw new Error('Cannot retrieve package.json', {cause: e}) | ||
} | ||
} | ||
} while (dirPath !== (dirPath = dirname(dirPath))) | ||
} | ||
|
||
export async function getConfig({argv1 = ''} = {}) { | ||
let defaults = { | ||
lookFor: ['js'] | ||
}, dirPath = isAbsolute(argv1) ? argv1 : cwd(), { | ||
lookFor | ||
} = {...defaults, ...(await getPkgJson(dirPath))?.body.extensionless} | ||
|
||
Array.isArray(lookFor) && lookFor.length && lookFor.every(a => typeof a === 'string' && /^[a-z]\w*$/i.test(a)) || ( | ||
lookFor = defaults.lookFor, warn('lookFor', 'an array of alphanumeric strings') | ||
) | ||
|
||
return {lookFor} | ||
} | ||
|
||
|
||
let initPromise | ||
export function globalPreload({port}) { | ||
port.onmessage = e => initPromise = initialize({argv1: e.data}) | ||
|
||
return 'port.postMessage(process.argv[1])' | ||
} | ||
|
||
let indexFiles, candidates | ||
export async function initialize(data) { | ||
let {lookFor} = await getConfig(data) | ||
|
||
indexFiles = [lookFor.map(e => `index.${e}`), ['index.json']] | ||
candidates = indexFiles.map(i => i.map(f => extname(f)).concat(i.map(f => `/${f}`))) | ||
} | ||
|
||
let winAbsPath = /^[/\\]?[a-z]:[/\\]/i, relSpecs = ['.', '..'] | ||
let specStarts = ['./', '../', '/', 'file://', 'https://', '.\\', '..\\', '\\'] | ||
let knownExts = ['.js', '.cjs', '.mjs', '.json', '.node', '.wasm'], empty = [[], []] | ||
|
||
export async function resolve(specifier, context, nextResolve) { | ||
let error, prefix = winAbsPath.test(specifier) ? 'file://' : '' | ||
|
||
if (!prefix && !relSpecs.includes(specifier) && !specStarts.some(s => specifier.startsWith(s))) { | ||
try {return await nextResolve(specifier)} catch (e) {error = e} | ||
} | ||
|
||
let {type} = context.importAttributes ?? context.importAssertions | ||
let trySpec = error ? specifier : new URL(prefix + specifier, context.parentURL).href | ||
let postfixes = (await initPromise, trySpec.endsWith('/') ? | ||
indexFiles : knownExts.includes(extname(trySpec)) ? empty : candidates) | ||
|
||
for (let postfix of postfixes[+(type === 'json')]) { | ||
try {return await nextResolve(trySpec + postfix)} catch {} | ||
} | ||
|
||
if (error) { | ||
throw error | ||
} | ||
|
||
return await nextResolve(trySpec) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import {register} from 'node:module' | ||
import {argv} from 'node:process' | ||
|
||
register('./specifier-node.mjs', import.meta.url, {data: {argv1: argv[1]}}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../specifier-node.mjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../specifier-register.mjs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters