nearprotocol / near-runtime-ts

Typescript library for writing near smart contracts
22 stars 7 forks source link

near-runtime-ts and near-shell should depend on a fixed version of AssemblyScript compiler #85

Closed MaksymZavershynskyi closed 4 years ago

MaksymZavershynskyi commented 5 years ago

near-runtime-ts and near-shell should depend on a fixed version of AssemblyScript compiler instead of depending on the master branch.

We push code into https://github.com/nearprotocol/assemblyscript without prior staging and testing as the result, sometimes it breaks things, see https://docs.google.com/document/d/1pzujH0VxMA5aCC2XCgXX7G4o2EaZKfCPgfIP6T-oIVM/edit# Unfortunately, because we do not do versioning the breakage propagates everywhere immediately.

DanielRX commented 5 years ago

I feel like the correct way is to mirror solidity, allow the user to specify the compiler version and make the runtime agnostic

willemneal commented 5 years ago

I agree. The compiler should also be published to npm with a name like near-assemblyscript as to not be confused with the normal assemblyscript compiler. I also think that we shouldn't rely on gulp since the build process doesn't require multiple steps as it did before, instead just create something like asconfig.js in each project which will pass the compiler options and allow users to customize it if they want to have debug builds, etc. near build could then be the entry to compiling the project and would expect this file. We also don't need to implement the readFile, writeFile, etc functions since the compiler has defaults when building on node.

Currently the runtime has assemblyscript as a devDependency and if we made it one for near-shell too then it will just use the local installation of the compiler imported in the asconfig.js.

Also since near-shell depends on the runtime, the only deps a new project would need is near-assemblyscript and near-shell.

Then for NEARStudio we just do what WebAssembly.studio does

  asc.main = (main => (args, options, fn) => {
    if (typeof options === "function") {
      fn = options;
      options = undefined;
    }
    return main(args, options || {
      stdout: asc.createMemoryStream(),
      stderr: asc.createMemoryStream(logLn),
      readFile: (filename, baseDir) => {
        const file = project.getFile(baseDir + "/" + filename.replace(/^\//, ""));
        return file ? file.data : null;
      },
      writeFile: (filename, contents) => {
        const name = filename.startsWith("../") ? filename.substring(3) : filename;
        const type = fileTypeForExtension(name.substring(name.lastIndexOf(".") + 1));
        project.newFile(name, type, true).setData(contents);
      },
      listFiles: () => []
    }, fn);
  })(asc.main);

For now I think the best next step is to publish to npm so that we can start to have versions to pin projects to.