Giter Club home page Giter Club logo

Comments (2)

clsource avatar clsource commented on June 1, 2024

Dome Module Imports

For simplifying code reutilization and modularization,
this is a proposed way for DOME to handle dependencies.

modules.wren

This is a simple wren file that contains
each module path. Is inspired on https://github.com/WICG/import-maps

var Imports = {
    "domepunk": "modules/domepunk/dp.wren",
    "domepunk/": "modules/domepunk", // allow imports for files inside the domepunk/ dir
}

On startup DOME will load this file (if exists) and store the paths for reference later
when loading imports inside wren files.

The filename could be overrited using --importmap=<FILE> CLI flag.

tar files

Paths that end with tar will be considered as a tar file.
Using @ after the file extension it would mean a file inside the tar.

var Imports = {
    "domepunk": "modules/domepunk.tar",
    "domepunk/math": "modules/domepunk.tar@science/math"
}

importing

  • Using @ at the start of the import will use the importmap path first.

  • Without using @ it would follow the traditional way of importing and use the importmap last for resolve it.

  • If the paths begins with / ("/domepunk") it would consider the base path of the dome executable.

  • If the path does not begins with / ("domepunk") it would consider the base path of the main.wren file.

  • If the path begins with ./ ("./domepunk") it would consider the base path of the current file begin executed.

// Will use the math module path defined in modules.wren
import "@math" for Math

// Will use the same path for the _dome_ executable as the base path. if not found will look into the modules.wren path
import "/math" for Math

// Will use the _file_ path as base path. Then it will look for the _main.wren_ base path. Then it will look for _modules.wren_ path. Finally it will look for the _dome_ executable base path.
import "./math" for Math

// First it will look for the internal modules. Then it will use the _main.wren_ base path. Then it will look for the _file_ base path. if not found will look into the modules.wren path. Finally it will use the _dome_ executable base path.
import "hello" for Hello

default name

Modules can define a default main.wren file that will be loaded by default if no file is specified for the path.

from dome.

clsource avatar clsource commented on June 1, 2024

Based on the proof on concept. This is the proposed algorithm for resolving imports.

  • First it resolves the import using the traditional way of the path based on main.wren.

  • If the file is not found then it will look inside a modules dir.

  • If the file is not found in modules directory then it will look for a path inside dome.ini.

  • finally it will trigger import error for file not found.

  • Example:

import "domepunk" for Dp
  • This first will look for a file named domepunk.wren in the base path of main.wren.

  • Then it will look inside basepath/modules/domepunk.wren.

  • Then it will look inside basepath/modules/domepunk/domepunk.wren.

  • Then it will search for a key named domepunk inside dome.ini

  • If a key is found then it will look for a file inside {dome.ini.path}/domepunk.wren

  • Example:

import "domepunk/utils/clock" for Clock
  • This first will look for a file named clock.wren in the base path/domepunk/utils of main.wren.

  • Then it will look inside basepath/modules/domepunk/utils/clock.wren.

  • Then it will search for a key named domepunk inside dome.ini

  • If a key is found then it will look for a file inside {dome.ini.path}/utils/clock.wren

  • Example:

import "../domepunk/utils/clock" for Clock
  • This first will look for a file named ../clock.wren in the base path/../domepunk/utils of main.wren.

  • Special paths like ./ or ../ are omited in the modules search after the traditional way.

  • Then it will look inside basepath/modules/domepunk/utils/clock.wren.

  • Then it will search for a key named domepunk inside dome.ini

  • If a key is found then it will look for a file inside {dome.ini.path}/utils/clock.wren

  • Example dome.ini

[imports]
domepunk = examples/

from dome.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.