lemanschik / modules

StealifyOS Stack - Awesome Storage - B8G Engine - ECMAScript - modules folder contains regular used modules
The Unlicense
0 stars 0 forks source link

implement nodeNextResolve. #3

Open lemanschik opened 1 year ago

lemanschik commented 1 year ago

nodeNextResolve

is a primitive string replace resolve based on unified string representations of specifiers. where a single asterisk in a string can occure and gets replaced with a instance of the unified representation of the importSpecifier.

const baseUrl = import.meta.url

const resolveId = (id, importedById) => {
  const Uri = new URL(id, baseURL);
  // change the base example keeps search parms and that 
  // new URL(Uri.href.replace(Uri.origin, baseURL)); 
  return Uri;
}

const loader = (resolvedId) => {
  return fetch(resolvedId).then((ok) =>{}, (err) =>{});
}

lets take: https://unpkg.com/@rollup/plugin-node-resolve@15.0.1/dist/es/index.js

shim strip

// get it without the imports on top we supply that 
fetch('https://unpkg.com/@rollup/plugin-node-resolve@15.0.1/dist/es/index.js').then(async res=> (await res.text()).split('\n').slice(10).join('\n'))
import path, { dirname, resolve, extname, normalize, sep } from 'path';
import isBuiltinModule from 'is-builtin-module';
import deepMerge from 'deepmerge';
import isModule from 'is-module';
import fs, { realpathSync } from 'fs';
import { promisify } from 'util';
import { pathToFileURL, fileURLToPath } from 'url';
import resolve$1 from 'resolve';
import { createFilter } from '@rollup/pluginutils';