jstwister / public

JsTwister issue tracker - Javascript productivity tooling at it's best
3 stars 0 forks source link

Only copies last line #3

Closed stijnvanderlaan closed 7 years ago

stijnvanderlaan commented 7 years ago

index.js

testFunc("asdfsdf");

console.log("112233")

src/test.js

export function testFunc(t) {
    console.log("adsfasd", t)
}

jstwister.config.js

module.exports = {
  entry: "index.js",
  resolve: {
    alias: {},
    extensions: ["", ".js", ".jsx", ".es6", ".css"],
    modules: [".", "./node_modules"]
  },
  files: [],
  exclude: [],
  printer: {
    tabWidth: 4,
    useTabs: false,
    reuseWhitespace: true,
    lineTerminator: "\n",
    wrapColumn: 80,
    quote: "single",
    trailingComma: false,
    arrayBracketSpacing: false,
    objectCurlySpacing: true,
    arrowParensAlways: false,
    flowObjectCommas: true
  },
  autostart: false,
  logLevel: "info"
};

Running Add missing imports on index.js results in:

testFunc("asdfsdf");

console.log("112233")console.log("112233")

Output:

[JSTwister Core] - info:    Received request to run refactor missing-imports on file /Users/worm/Workspace/test/jstwister/index.js

Received server response "{\"reqId\":\"33d43420-fecc-4ec7-ab66-a80049dc1458\",\"type\":\"refactor\",\"payload\":\"\\n\\ntestFunc(\\\"asdfsdf\\\");\\n\\nconsole.log(\\\"112233\\\")\",\"status\":\"ok\"}"

Version 0.0.10

gcazaciuc commented 7 years ago

Can you pls include the files in file array and try again ? I will check whats going on with the duplicate line.

stijnvanderlaan commented 7 years ago

When I add the files to the entry as an array the result is:


import { testFunc } from 'src/test.js';

testFunc("asdfsdf");

console.log("112233")console.log("112233")

I would expect the import to be './src/test.js' because webpack thinks it's a node_module now.

jstwister.config.js

module.exports = {
  entry: ["src/index.js", "src/test.js"],
  resolve: {
    alias: {},
    extensions: ["", ".js", ".jsx", ".es6", ".css"],
    modules: [".", "./node_modules"]
  },
  files: [],
  exclude: [],
  printer: {
    tabWidth: 4,
    useTabs: false,
    reuseWhitespace: true,
    lineTerminator: "\n",
    wrapColumn: 80,
    quote: "single",
    trailingComma: false,
    arrayBracketSpacing: false,
    objectCurlySpacing: true,
    arrowParensAlways: false,
    flowObjectCommas: true
  },
  autostart: false,
  logLevel: "info"
};

Unfortunately adding an entry like "**/src/**/*.js" is not working.

gcazaciuc commented 7 years ago

Sorry for the trouble. So the thing is like this:

  1. These was an error regarding last line duplication that was fixed in 0.0.11
  2. The import import { testFunc } from 'src/test.js'; is actually correct. Same as Webpack the imports are relative to the locations specified in resolve.modules. In config you have "." specified there, so that's why you get this import.

If you wish to have relative imports like './src/test.js' you can do that too, but i wouldn't recommend it for code maintainance reasons.

In config file just set the ''import-style' like this:

module.exports = {
..... 
plugins: {
        'imports-manager': {
            'import-style': 'relativeToFile' // other option is 'relativeToModules'
        }
  }
......
}
stijnvanderlaan commented 7 years ago

Thanks, I got it to work, also "**/src/**/*.js" does seems to work, that was related to something else, I created another issue.