tarrencev / babel-plugin-react-intl-to-properties

Extracts React Intl messages from React components into a .properties file
Other
5 stars 2 forks source link

Problems with creating directories #6

Open JohnLindahlTech opened 7 years ago

JohnLindahlTech commented 7 years ago

It seems to be a bug at this line: https://github.com/tarrencev/babel-plugin-react-intl-to-properties/blob/master/src/index.js#L171

The reason why I consider it a bug is that per specification, the last part of the path will be stripped away:

path.dirname('/foo/bar/baz/asdf/quux') // Returns: '/foo/bar/baz/asdf'

my .babelrc-config:

        ["react-intl-to-properties", {
          "enforceDescriptions": true,
          "fileName": "server-dev",
          "messagesDir": "dist/translations/"
        }]

Resulting in the following error for me when I try to extract translations to a generated directory structure (I added a printout indicating my result of path.dirname() and the file I want to write to):

>> dirname: dist
>> propertiesFP: dist/translations/server-prod.properties
Error: src/app/information/trading-status.jsx: ENOENT: no such file or directory, open 'dist/translations/server-prod.properties'
    at Error (native)
    at Object.fs.openSync (fs.js:640:18)
    at fs.writeFileSync (fs.js:1333:33)
    at PluginPass.exit (/Users/johbac/ws/instrument-page/node_modules/babel-plugin-react-intl-to-properties/lib/index.js:148:47)
    at newFn (/Users/johbac/ws/instrument-page/node_modules/babel-traverse/lib/visitors.js:276:21)
    at NodePath._call (/Users/johbac/ws/instrument-page/node_modules/babel-traverse/lib/path/context.js:76:18)
    at NodePath.call (/Users/johbac/ws/instrument-page/node_modules/babel-traverse/lib/path/context.js:48:17)
    at NodePath.visit (/Users/johbac/ws/instrument-page/node_modules/babel-traverse/lib/path/context.js:117:8)
    at TraversalContext.visitQueue (/Users/johbac/ws/instrument-page/node_modules/babel-traverse/lib/context.js:150:16)
    at TraversalContext.visitSingle (/Users/johbac/ws/instrument-page/node_modules/babel-traverse/lib/context.js:108:19)
    at TraversalContext.visit (/Users/johbac/ws/instrument-page/node_modules/babel-traverse/lib/context.js:192:19)
    at Function.traverse.node (/Users/johbac/ws/instrument-page/node_modules/babel-traverse/lib/index.js:114:17)
tarrencev commented 7 years ago

@JohnPhoto Looks like a bug indeed. Would be happy to accept a PR addressing it

JohnLindahlTech commented 7 years ago

Now opened #7 for this purpose.