Skip to content

Add support for import declarations#2

Open
ruimarinho wants to merge 1 commit intoandrewimm:masterfrom
seegno-forks:feature/import-declarations
Open

Add support for import declarations#2
ruimarinho wants to merge 1 commit intoandrewimm:masterfrom
seegno-forks:feature/import-declarations

Conversation

@ruimarinho
Copy link

Hey,

Thanks for this cool package. I really dislike having to copy the package.json to the distribution build of babel and this package allows me to do exactly just that.

I've noticed that support for the ES2015 modules was missing, so I've decided to submit this PR with support for that. Default exports won't get replaced, as expected, but no error will occur also.

I think it's time for the package to get some tests, I just didn't have the time to do it on this PR.

@ruimarinho
Copy link
Author

@andrewimm, any feedback here :)?

@andrewimm
Copy link
Owner

Apologies, I guess I never got the notifications for this. This is fantastic, I'll do a full review inline.

src/index.js Outdated
let pkg = require(path.join(srcPath, '..', node.object.arguments[0].value));
let value = pkg[node.property.name];
treePath.replaceWith(t.expressionStatement(t.valueToNode(value)));
ImportDeclaration: function importDeclaration(path) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use treePath here over path, otherwise we get implicit conflicts with the path module imported at the top.

src/index.js Outdated
return pkg[key];
}

function isManifest(node) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm never refers to package.json as a manifest, and that word has overloaded meanings for things like Heroku or Android. Could we just call this isPackageJSON?

src/index.js Outdated
return path.replaceWithMultiple(variables);
},

MemberExpression: function MemberExpression(path) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, path conflicts

@ruimarinho ruimarinho force-pushed the feature/import-declarations branch from 143ad31 to acaf7e8 Compare January 29, 2017 16:50
@ruimarinho
Copy link
Author

Feedback addressed @andrewimm.

@spheroid
Copy link

Hey @andrewimm can you please merge this PR in?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants