Skip to content

Update rcs core #44

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

Merged
merged 10 commits into from
Aug 22, 2019
Merged

Update rcs core #44

merged 10 commits into from
Aug 22, 2019

Conversation

X-Ryl669
Copy link

This update the code to work with version 3 of rcs-core.
It adds ignore feature to config file, so it's possible to ignore minified files (like those coming from external libraries)
It also adds source line tracking so generated warning are meaningful (to be used with rcs-core#94)

@X-Ryl669
Copy link
Author

I need help here, I don't know how to solve travis's report here.
I don't think it's clean to have a dependency on rcs-core^3.0.0-alpha.0 and I've tried rcs-core^3.0.0@next but it does not work either.

How to do this ?

@JPeer264
Copy link
Owner

JPeer264 commented Aug 20, 2019

I don't think it's clean to have a dependency on rcs-core^3.0.0-alpha.0

True, that's why I am not releasing a stable version of rename-css-selectors based on an alpha rcs-core dependency. You have 3 options here to lock down to the current alpha version:

{
	"dependencies": {
		// locking the version
		"rcs-core": "^3.0.0-alpha.0",
		// locking the tag
		"rcs-core": "next",
		// locking the branch of github
		"rcs-core": "github:JPeer264/node-rcs-core#master",
		// locking any commit
		"rcs-core": "github:JPeer264/node-rcs-core#2815d48e6caa619a7cb38a5d014af7b762e6de6f"
    }
}

But I would suggest to lock down the version in this case. I will release an alpha version of rename-css-selectors as long as rcs-core doesn't have a stable version :)

if (
options.type === 'js' ||
(
options.type === 'auto' &&
fileExt.js.includes(path.extname(filePath))
)
) {
data = rcs.replace.js(fileData, options.parserOptions);
// eslint-disable-next-line no-param-reassign
Copy link
Owner

Choose a reason for hiding this comment

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

I think it still works without this line?

Copy link
Author

Choose a reason for hiding this comment

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

Will try. I don't know since I can't run test on my side.

@coveralls
Copy link

coveralls commented Aug 20, 2019

Coverage Status

Coverage increased (+0.6%) to 97.026% when pulling 8d519fe on X-Ryl669:updateRCSCore into a10956d on JPeer264:master.

Copy link
Owner

@JPeer264 JPeer264 left a comment

Choose a reason for hiding this comment

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

Some changes, plus I think my linting is not included into travis, I will update that. There might be some problems of the linter as well.

}
return false;
}
}; // /include
Copy link
Owner

Choose a reason for hiding this comment

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

could you remove ; // /include?

Copy link
Author

Choose a reason for hiding this comment

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

Done

}
}; // /include

module.exports = new Config;
Copy link
Owner

Choose a reason for hiding this comment

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

I actually don't know how that works, also I've never seen it. Could you add the parentheses to the class new Config();

You know if there are any differences between new Config and new Config(), just curious.

Copy link
Author

@X-Ryl669 X-Ryl669 Aug 21, 2019

Choose a reason for hiding this comment

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

That's valid JS if there is not parameter to the constructor. The linter usually refuse it because it can lead to code like this: new Date.toString() which tries to invoke toString as the constructor of some object Date. It's usually not the developer intention. I'm changing it to be consistent.

Copy link
Owner

Choose a reason for hiding this comment

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

Ah well, thanks for the answer. That makes sense :)

package.json Outdated
"universalify": "^0.1.2"
"rcs-core": "^3.0.0-alpha.0",
"universalify": "^0.1.2",
"yarn": "^1.17.3"
Copy link
Owner

Choose a reason for hiding this comment

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

Please do not add yarn as dependency :)

Copy link
Owner

Choose a reason for hiding this comment

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

Either install yarn with homebrew (if you are on a mac) or install it globally via npm. I might switch fully to plain npm anyways soon.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, I used to use npm and when I've tried install yarn, it shouted that we shouldn't mix package manager, so I've removed the lock file and forgot to check the package.json file

Copy link
Owner

Choose a reason for hiding this comment

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

No worries, all good.

@X-Ryl669
Copy link
Author

Should be OK now. I've fixed all original code that choked with the linter too.

Copy link
Owner

@JPeer264 JPeer264 left a comment

Choose a reason for hiding this comment

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

I just saw two things - last changes then it's ready to merge :)

@@ -32,13 +32,13 @@ class Config {
}

isIgnored(filePath) {
for (let i = 0; i < this.ignorePatterns.length; i++) {
for (let i = 0; i < this.ignorePatterns.length; i += 1) {
Copy link
Owner

Choose a reason for hiding this comment

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

I just saw this now. Could you change this method to following:

isIgnored(filePath) {
  return this.ignorePatterns.some(pattern => minimatch(filePath, pattern);
}

@@ -2,38 +2,47 @@ const merge = require('lodash.merge');
const rcs = require('rcs-core');
const json = require('json-extra');

const loadMapping = (pathString, options) => {
function loadReversed(selectors) {
Copy link
Owner

Choose a reason for hiding this comment

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

Also here please change to following:

const loadReversed = selectors => (
	Object.entries(selectors).reduce((prev, [key, value]) => ({
    	...prev,
		[key.charAt(0) + value]: key.slice(1, key.length),
	}), {})
);

Copy link
Author

@X-Ryl669 X-Ryl669 Aug 21, 2019

Choose a reason for hiding this comment

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

Nope. ava or nyc does not accept object destructuring IIRC (I had to use _.merge instead).

Not sure it's more understandable this way anyway.
I'm going to do something in between without reduce

Edit: Yep, it does not work:

SyntaxError: /Users/cyril/esp/node-rename-css-selectors/lib/mapping/loadMapping.js: Unexpected token (7:4)
   5 | const loadReversed = selectors => (
   6 |   Object.entries(selectors).reduce((prev, [key, value]) => ({
>  7 |     ...prev,
     |     ^
   8 |     [key.charAt(0) + value]: key.slice(1, key.length),
   9 |   }), {}));
  10 |
    at Parser.pp$5.raise (/Users/cyril/esp/node-rename-css-selectors/node_modules/babylon/lib/index.js:4454:13)
    at Parser.pp.unexpected (/Users/cyril/esp/node-rename-css-selectors/node_modules/babylon/lib/index.js:1761:8)
    at Parser.pp$3.parseIdentifier (/Users/cyril/esp/node-rename-css-selectors/node_modules/babylon/lib/index.js:4332:10)
    at Parser.pp$3.parsePropertyName (/Users/cyril/esp/node-rename-css-selectors/node_modules/babylon/lib/index.js:4156:96)
    at Parser.pp$3.parseObj (/Users/cyril/esp/node-rename-css-selectors/node_modules/babylon/lib/index.js:4045:12)

@X-Ryl669
Copy link
Author

X-Ryl669 commented Aug 21, 2019

Let me know if it's ok for you this way. It's seem easier to read IMHO.
Also, please increment the version in rcs-core so I can add the new allWarnings.warn() call to get the final (merged) warning report on the console. I'm preparing a new PR for this on this project with some documentation update.

@JPeer264 JPeer264 merged commit c230f13 into JPeer264:master Aug 22, 2019
@JPeer264
Copy link
Owner

I released rcs-core@3.0.0-alpha.1 or rcs-core@next 👍

X-Ryl669 added a commit to X-Ryl669/node-rename-css-selectors that referenced this pull request Aug 22, 2019
* Update code to support changes in RCS core

* Add support for true options from config file.
Don't allow non JSX file to run with JSX arguments

* Chore: install rcs-core@next

* Fix all tests to run with the changes

* Improve code coverage

* Make linter happy!

* Fix requested changes


Co-authored-by: Jan Peer Stöcklmair <jan.oster94@gmail.com>
@klimashkin
Copy link

Hi! Not sure why it's in a patch update of the rename-css-selectors
It breaks my build after 3.2.5 -> 3.2.6 update. Something is replaced too greedy in js files

@JPeer264
Copy link
Owner

Uff thats really bad. So "just" JS files are breaking?

It's in a patch as it shouldn't break the usage of rcs. I'm gonna invest in this asap!

@JPeer264
Copy link
Owner

Btw which kinda errors are you getting? JS files are being replaced wrongly or you JS files where you use rcs are breaking? E.g. some methods are not found?

@JPeer264
Copy link
Owner

FYI. I unpublished 3.2.6 and released 3.2.7 which is the same as 3.2.5, so nobody should experience any issues for now, until we solved the problem with the new rcs-core.

@klimashkin
Copy link

Thanks!
Some pieces of js files where replaced outside of strings, so it became not parsable anymore

@X-Ryl669
Copy link
Author

Can you give the example code that breaks (before and after transform) ? Thanks.

@X-Ryl669
Copy link
Author

@klimashkin It'll be hard to fix if you don't give us more details. Can you give (part of) the source JS code and the compiled JS code that has broken? Thanks.

@JPeer264
Copy link
Owner

@klimashkin could you try v4.0.0-rc.0 or as alias rename-css-selectors@next and report if your error still exists? :)

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.

4 participants