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

Fix default ignore pattern to work on Windows #70

Closed
herzaso opened this issue Aug 28, 2017 · 10 comments
Closed

Fix default ignore pattern to work on Windows #70

herzaso opened this issue Aug 28, 2017 · 10 comments

Comments

@herzaso
Copy link

herzaso commented Aug 28, 2017

I'm using create-react-app with react-app-rewired to enable making changes to webpack/babel without ejecting.

I've added the following config-overrides.js file (a react-app-rewired requirement):

module.exports = function override(config, env) {
	let babelLoader;

	const checkRule = rule => rule.loader && rule.loader.indexOf('babel-loader') > 0;

	config.module.rules.every(rule => {
		if (rule.oneOf) {
			babelLoader = rule.oneOf.find(checkRule);
		} else if (checkRule(rule)) {
			babelLoader = rule.loader;
		}
		return !babelLoader;
	});

	babelLoader.options.babelrc = true;
	return config
}

This make sure to load the .babelrc file with the needed presets:

{
  "plugins": [
    "syntax-dynamic-import"
  ],
  "env": {
    "test": {
      "plugins": [
        "dynamic-import-node"
      ]
    }
  },
  "presets": [
    "env",
    "react",
    "lingui-react"
  ]
}

While this approach is working, extract is failing with the following exception:

Extracting messages from source files:
C:\Development\partner_portal\client\config-overrides.js
C:\Users\ofirhe\AppData\Local\Yarn\config\global\node_modules\babel-core\lib\transformation\file\index.js:590
      throw err;
      ^

SyntaxError: C:/Development/partner_portal/client/node_modules/.bin/sha.js: Unexpected token, expected , (2:18)
  1 | #!/bin/sh
> 2 | basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
    |                   ^
  3 | 
  4 | case `uname` in
  5 |     *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
    at Parser.pp$5.raise (C:\Users\ofirhe\AppData\Local\Yarn\config\global\node_modules\babylon\lib\index.js:4454:13)
    at Parser.pp.unexpected (C:\Users\ofirhe\AppData\Local\Yarn\config\global\node_modules\babylon\lib\index.js:1761:8)
    at Parser.pp.expect (C:\Users\ofirhe\AppData\Local\Yarn\config\global\node_modules\babylon\lib\index.js:1749:33)
    at Parser.pp$3.parseCallExpressionArguments (C:\Users\ofirhe\AppData\Local\Yarn\config\global\node_modules\babylon\lib\index.js:3564:12)
    at Parser.pp$3.parseSubscripts (C:\Users\ofirhe\AppData\Local\Yarn\config\global\node_modules\babylon\lib\index.js:3533:31)
    at Parser.pp$3.parseExprSubscripts (C:\Users\ofirhe\AppData\Local\Yarn\config\global\node_modules\babylon\lib\index.js:3504:15)
    at Parser.pp$3.parseMaybeUnary (C:\Users\ofirhe\AppData\Local\Yarn\config\global\node_modules\babylon\lib\index.js:3474:19)
    at Parser.pp$3.parseExprOps (C:\Users\ofirhe\AppData\Local\Yarn\config\global\node_modules\babylon\lib\index.js:3404:19)
    at Parser.pp$3.parseMaybeConditional (C:\Users\ofirhe\AppData\Local\Yarn\config\global\node_modules\babylon\lib\index.js:3381:19)
    at Parser.pp$3.parseMaybeAssign (C:\Users\ofirhe\AppData\Local\Yarn\config\global\node_modules\babylon\lib\index.js:3344:19)

Expected:
While I think this exception should be addressed, I think it would also be beneficial to allow specifying the files to include/exclude from the extraction process

@tricoder42
Copy link
Contributor

tricoder42 commented Aug 28, 2017

Hello @herzaso,
there's already srcPathIgnorePatterns configuration (https://lingui.gitbooks.io/js/ref/cli.html), but the default value is /node_modules/ so I wonder, why it tries to extract messages from node_modules.

I'm not familiar with react-app-rewired, I'll take a look.

@tricoder42
Copy link
Contributor

It may be caused that /node_modules/ isn't treated correctly as a regexp, but rather unix-style directory, while you're on windows so it doesn't match. Just my first guess.

Could you please try to add this section to your package.json to verify it?

{
  "lingui": {
    "srcPathIgnorePatterns": ["node_modules"]
  }
}

@herzaso
Copy link
Author

herzaso commented Aug 28, 2017

@tricoder42 you are right, it was caused by the wrong path delimiter (maybe consider changing the regexp to support windows delimiter also).

Other than that, I know have another problem:

C:\Users\ofirhe\AppData\Local\Yarn\config\global\node_modules\babel-core\lib\transformation\file\index.js:590
      throw err;
      ^

SyntaxError: C:/Development/partner_portal/client/src/components/Form/Form.js: Unexpected token (41:10)
  39 |          uiSchema = Object.assign(uiSchema, schema.uiSchema)
  40 | 
> 41 |          return {...schema, uiSchema}
     |                  ^
  42 |  }
  43 | 

@tricoder42 tricoder42 changed the title Exception while extracting Fix default ignore pattern to work on Windows Aug 28, 2017
@tricoder42
Copy link
Contributor

Do I understand it correctly, that you actually have this .babelrc in root of your repository?

{
  "plugins": [
    "syntax-dynamic-import"
  ],
  "env": {
    "test": {
      "plugins": [
        "dynamic-import-node"
      ]
    }
  },
  "presets": [
    "env",
    "react",
    "lingui-react"
  ]
}

All what you do in config-overrides.js is to tell webpack to use .babelrc, right? (babelLoader.options.babelrc = true;)

@herzaso
Copy link
Author

herzaso commented Aug 28, 2017

Yes. I have added the es2015 preset just to make sure (although create-react-app should have it by default), but the result is the same

@herzaso
Copy link
Author

herzaso commented Aug 28, 2017

Nevermind, I have to add the "transform-object-rest-spread" plugin ...

@tricoder42
Copy link
Contributor

Ah, you're right! That plugin isn't part of env preset! Good job! 👍

Thank you for reporting the bug with ignore patterns. I'll fix it soon.

@tricoder42
Copy link
Contributor

It should be fixed on latest release of lingui-cli@1.2.1. Could you please confirm it? Simply remove srcPathIgnorePatterns to test the default works correctly.

@herzaso
Copy link
Author

herzaso commented Aug 29, 2017

Running the cli did produce the table with number of labels although it didn't show any file being collected (whereas before it did log the file paths that were collected).

Since I wasn't sure, I removed the locale directory and ran lingui add-locale en, but got the following error:

fs.js:641
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^

Error: ENOENT: no such file or directory, open 'C:\Development\partner_portal\client\locale\en\messages.json'
    at Error (native)
    at Object.fs.openSync (fs.js:641:18)
    at Object.fs.writeFileSync (fs.js:1347:33)
    at Object.write (C:\Users\ofirhe\AppData\Roaming\npm\node_modules\lingui-cli\dist\api\formats\lingui.js:60:20)
    at Object.addLocale (C:\Users\ofirhe\AppData\Roaming\npm\node_modules\lingui-cli\dist\api\formats\lingui.js:167:14)
    at C:\Users\ofirhe\AppData\Roaming\npm\node_modules\lingui-cli\dist\lingui-add-locale.js:29:36
    at Array.map (native)
    at command (C:\Users\ofirhe\AppData\Roaming\npm\node_modules\lingui-cli\dist\lingui-add-locale.js:28:25)
    at Object.<anonymous> (C:\Users\ofirhe\AppData\Roaming\npm\node_modules\lingui-cli\dist\lingui-add-locale.js:67:3)
    at Module._compile (module.js:570:32)

@tricoder42
Copy link
Contributor

I made the output more silent. Running lingui extract --verbose gives the full output as before.

The error is, however, weird. I'll take a look

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

No branches or pull requests

2 participants