Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Allow configuration of allowed_extensions for the migrations (fixes #1361) #1380

Merged
merged 6 commits into from
Nov 8, 2018
Merged

Allow configuration of allowed_extensions for the migrations (fixes #1361) #1380

merged 6 commits into from
Nov 8, 2018

Conversation

roderik
Copy link
Contributor

@roderik roderik commented Oct 25, 2018

  • I added a separate config function to truffle-config, same naming and signature scheme as the test regexp
  • I added the new config regexp as second choice to truffle-migrate. While there are no usages of the option version, I did not wan to inadvertently break any code depending on this option.
  • separate commits because my editor wanted to reformat every line of code, yay prettier :)

@sneko
Copy link

sneko commented Oct 26, 2018

@roderik after fixing what I mentioned in my comments I'm still getting errors due to TypeScript syntax.

Here one of my files:

var Migrations = artifacts.require("./Migrations.sol");

module.exports = async function(deployer, network, accounts) {
  await deployer.deploy(Migrations);
} as Truffle.Migration;

// because of https://stackoverflow.com/questions/40900791/cannot-redeclare-block-scoped-variable-in-unrelated-files
export {};

I get the following error when migrating:

} as Truffle.Migration;
  ^^

SyntaxError: Unexpected identifier

If I remove the as Truffle.Migration it shows me the next issue:

export {};
^^^^^^

SyntaxError: Unexpected token export
    at Object.createScript (vm.js:80:10)

To solve this my file needs to look like:

var Migrations = artifacts.require("./Migrations.sol");

module.exports = async function(deployer, network, accounts) {
  await deployer.deploy(Migrations);
};

Like an ES6 file...

Do you know why the parser is not using TypeScript?

Thanks,

@roderik
Copy link
Contributor Author

roderik commented Oct 27, 2018

@sneko, you are probably missing the require("ts-node/register"); line mentioned in the setup at https://github.com/ethereum-ts/truffle-typechain-example. Thanks for catching the missing require, forgot to copy paste that line in the commit :)

@sneko
Copy link

sneko commented Oct 27, 2018

@roderik I’m actually requiring the tsnode/register... hmmm I don’t understand what could be the problem.

I’m using Truffle 5 and my settings are stored in the « truffle-config.js ».

I will try to figure out tomorrow morning what’s going on. (Including cloning and testing the example)

@sneko
Copy link

sneko commented Oct 27, 2018

@roderik the truffle-typechain-example is working well for migrations if I build on my own truffle (including your PR).

But if I add this line in the truffle.js:
migrations_file_extension_regexp: /.*\.ts$/,

I get the same error than in my project:

} as Truffle.Migration;
  ^^

SyntaxError: Unexpected identifier

😢

@CruzMolina
Copy link
Contributor

CruzMolina commented Oct 29, 2018

Thanks again for doing this @roderik. @sneko I did some playing around with replicating your error and I believe it is a configuration issue on the ts side (typechain, tsconfig, possibly truffle-typings).

Since this is a simple enough feature addition, I think we're going to move ahead with supporting this after I add some tests to ensure coverage.

@CruzMolina
Copy link
Contributor

@sneko did a little more replication using the truffle-typechain-example repo.

I was able to get the example working using their current setup (package.json, tsconfig, etc). I was also able to get things working using Roderik's current workaround here.

@sneko
Copy link

sneko commented Oct 29, 2018

@CruzMolina yeah the workaround is working.

But did you succeed in replicating the issue I get?

Building Truffle with this pull request and injecting it inside the node_modules directory on truffle-typechain-example (do not forget to add migrations_file_extension_regexp: /.*\.ts$/, inside the Truffle config file)

@CruzMolina
Copy link
Contributor

CruzMolina commented Oct 30, 2018

Ah, I see what you mean @sneko. After reviewing the codebase, it looks like truffle-migrate exports the migration files to a js parser in truffle-require. For now using truffle-typings with typechain, you don't have to add to or change migrations_file_extension_regexp to parse .ts (tsc will transpile it for you to .js). I was able to get the example repo working without Roderik's workaround. You don't have to specify a different migrations_build folder, you can just use the given repo's tsconfig and the example migrations .ts file to base your own migration files.

@CruzMolina
Copy link
Contributor

CruzMolina commented Oct 30, 2018

So after diving into this, it looks like this change doesn't immediately further .ts integration or ethereum-ts support (although #1385 should help a teeny bit towards that end). However, it does make an aspect of truffle-config configurable in a way that could be useful more long term.

@fainashalts
Copy link
Contributor

+1 Looks good to me!

@CruzMolina CruzMolina merged commit 4c08ca9 into trufflesuite:next Nov 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants