Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module require resolving refactor #493

Merged
merged 10 commits into from
Feb 12, 2018
Merged

Conversation

dustyo-O
Copy link
Contributor

@dustyo-O dustyo-O commented Dec 10, 2017

Several probs with require more than one module in different modular systems

Changes proposed in this pull request

  • If we have ym - we provide modules there, also we wrap commonJS and global deps with ym syntax
  • If we do not have ym, we ignore ym deps.
  • Priority: global - commonJS - ym;

Checklist

  • Documentation changed
  • Tests added

lib/compiler.js Outdated
var commonPath = deps.commonJS[dep];
return '_libs["' + dep + '"] = ' +
'glob && typeof glob["' + dep + '"] ' +
'!== "undefined" ? ' +
Copy link
Contributor Author

Choose a reason for hiding this comment

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

looks like no need to do it (try to use global) here - it will get to us anyway on line 222

@miripiruni
Copy link
Contributor

@dustyo-O linters are red

@coveralls
Copy link

coveralls commented Dec 19, 2017

Coverage Status

Coverage increased (+0.002%) to 99.39% when pulling f2f24e8 on dustyo-O:requires-update into 36e253c on bem:master.

@coveralls
Copy link

coveralls commented Dec 22, 2017

Coverage Status

Coverage increased (+0.002%) to 99.389% when pulling 7944c91 on dustyo-O:requires-update into e76cd62 on bem:master.

@dustyo-O
Copy link
Contributor Author

fixed linters now

TODO: check that tests will fail on corrupted data (checks are checking)

lib/compiler.js Outdated
deps.ymVarsString = deps.ymVars.map(function(item) {
return item + ':' + item;
}).join('');
deps.ymVars = ',' + deps.ymLibs.map(function (item) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we make 3 maps here, can do 1 for instead, could be faster. what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

@dustyo-O generate() is not runtime operation. No matter how it fast or slow we use it to generate bundles for browser.

var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);

describe('Require modules', function () {
Copy link
Contributor

@miripiruni miripiruni Dec 26, 2017

Choose a reason for hiding this comment

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

Needed to move back tests to test/api-generate-test.js to minimize diff.


vm.runInNewContext(code + EOL + bundle, sandbox);

var result = sandbox.exports.bemhtml.compile(function () {
Copy link
Contributor

Choose a reason for hiding this comment

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

Code style: notice that function() { in other files in the repo doesn’t have space before () brackets.

lib/compiler.js Outdated
}).join('');
deps.ymVars = ',' + deps.ymLibs.map(function (item) {
return item;
}).join(',');
Copy link
Contributor

Choose a reason for hiding this comment

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

What?

deps.ymLibs.map(function(item) { return item; }).join(',');

map is useless here.

lib/compiler.js Outdated

'modules.define("' + exportName + '",' +
JSON.stringify(deps.ymLibs) + ',' +
'function(provide' + deps.ymVars + ') { ' +
Copy link
Contributor

Choose a reason for hiding this comment

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

let’s place deps.ymVars inline?

'provide, ' + deps.  .join(', ')

lib/compiler.js Outdated
ymLibs: [],
ymVars: '',
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we need both ymVars and ymNames?
Previuosly, I used only ymVars: [] and ymVars.join(', ')

So many variables… I’m try to reduce their number.

Copy link
Contributor

@miripiruni miripiruni left a comment

Choose a reason for hiding this comment

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

In general we need to

  1. minimize diff
  2. figure out what’s changed: describe priority of module loading before and after to determine minor or major changes.

tadatuta added a commit to bem/bem-core that referenced this pull request Jan 22, 2018
tadatuta added a commit to bem/bem-core that referenced this pull request Jan 22, 2018
@miripiruni miripiruni mentioned this pull request Feb 5, 2018
3 tasks
@miripiruni
Copy link
Contributor

miripiruni commented Feb 5, 2018

JFYI: we just discussed details with @dustyo-O and decided to finish PR this evening together.

@dustyo-O dustyo-O force-pushed the requires-update branch 4 times, most recently from efca840 to 535b29d Compare February 11, 2018 11:07
@dustyo-O
Copy link
Contributor Author

ok guys, i've sawed the whole diff into step-by-step commits. i hope, this helps - happy reading!

into the f98319f i've added some alpha-version documentation, please read carefully and feel free to suggest changes. I'll add english translation before merge.

docs/ru/3-api.md Outdated

И также, модуль из CommonJS приоритетнее модуля в YModules.

Это позволяет, например, переопределять ваши модули на статические объекты в целях тестирования в соответствующих конфигурациях.
Copy link
Contributor

Choose a reason for hiding this comment

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

Кажется, что эту фразу можно пропустить.

'if (typeof modules === "object") {',

// re-define YM modules to require keys
deps.ymNames.length !== 0 ?
Copy link
Contributor

Choose a reason for hiding this comment

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

Можно оставить просто deps.ymNames.length

@miripiruni miripiruni added this to the 8.8.8 milestone Feb 12, 2018
@miripiruni miripiruni merged commit 4b1b87c into bem:master Feb 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants