From c85ee41c21b596e9068be6dd9c82b735606bb81e Mon Sep 17 00:00:00 2001 From: Bronwen Date: Sun, 16 May 2021 20:41:45 -0400 Subject: [PATCH] use vogue from outside repo --- Module.js | 12 +++++++++--- System.js | 3 ++- run.js | 19 +++++++++++-------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Module.js b/Module.js index 00c2c4e..ca08df7 100644 --- a/Module.js +++ b/Module.js @@ -1,6 +1,8 @@ import createAst from './createAst.js' import path from 'path'; import debug from 'debug'; +import { createRequire } from 'module'; +import { pathToFileURL } from 'url'; const log = debug('vogue:module'); export default class Module { @@ -55,7 +57,11 @@ export default class Module { } async import({importName, name}) { - const imported = await import(importName); + const nodePath = path.resolve(this.rootDir, 'node_module'); + log('#'.repeat(80)); + log(nodePath); + const __require__ = createRequire(nodePath); + const imported = __require__(importName); if('default' in imported) this.imports[name] = imported.default; else this.imports[name] = imported; } @@ -64,15 +70,15 @@ export default class Module { this.variables[persist ? 'cold' : 'warm'].push(name); } - static async create(location) { + static async create(location, rootDir) { const module = new Module(); const ast = createAst(location); const name = path.parse(location).name; module.name.last = name; module.name.full = name; + module.rootDir = rootDir; - // move module whole loop ass bitch into module. for (const item of ast) { if ('name' in item) { if(item.name in module.identifiers) diff --git a/System.js b/System.js index 0815f54..7ab0862 100644 --- a/System.js +++ b/System.js @@ -13,12 +13,13 @@ export default class System extends Serializable { namespace = null; staticInstances = {}; - constructor(modules, location = '.running') { + constructor(modules, rootDir) { super(); this.modules = modules; this.createNamespace(); const bootModules = this.deriveBootModules(); this.createStaticInstances(); + this.rootDir = rootDir; log('instantiating boot modules...'); for(const name of bootModules) { diff --git a/run.js b/run.js index 1576841..09cbfec 100755 --- a/run.js +++ b/run.js @@ -1,28 +1,31 @@ #!/usr/bin/env node +import debug from 'debug'; +const log = debug('vogue:cli'); +const systemLocation = resolve(process.argv[2]); -import { resolve } from 'path'; -import { readdirSync } from 'fs'; +import { parse, resolve } from 'path'; +import { readdirSync, lstatSync } from 'fs'; import _ from 'lodash'; import Module from './Module.js'; import System from './System.js'; -import debug from 'debug'; import './extensions.js'; // globals inside grammar context import minify from './minify.js'; const { get, set } = _; -const log = debug('vogue:cli'); -const systemLocation = resolve(process.argv[2]); (async () => { // TODO simplify this line gaddam log('reading', systemLocation, '...'); const files = readdirSync(systemLocation); - const fullpaths = files.map(v => resolve(systemLocation, v)); + const fullpaths = files + .map(v => resolve(systemLocation, v)) + .filter(v => lstatSync(v).isFile()) + .filter(v => parse(v).ext === '.v'); for(const path of fullpaths) log(path); log('parsing modules...'); - const modules = await Promise.all(fullpaths.map(loc => Module.create(loc))); + const modules = await Promise.all(fullpaths.map(loc => Module.create(loc, systemLocation))); // const modules = // (await Promise.all( @@ -35,5 +38,5 @@ const systemLocation = resolve(process.argv[2]); // return acc; // }, {}); - const sys = new System(modules); + const sys = new System(modules, systemLocation); })()