amatiasq / vsc-sort-imports

Sort ES6 imports automatically.
ISC License
58 stars 24 forks source link

with v6.1.0, custom `sort-style` no longer working #56

Closed thisissami closed 3 years ago

thisissami commented 4 years ago

I use https://www.npmjs.com/package/import-sort-style-module-alias to handle my aliases within my project in a specific manner. When I updated to v6.1.0, sort-imports no longer seems to be able to load import-sort-style-module-alias. Whenever I try to run the Sort imports command, the OUTPUT tab (same area as TERMINAL) reads something like:

2019-09-02, 6:00:02 p.m.:
-------------------------
Cannot find module 'import-sort-style-module-alias'

This was never an issue previously, and I have re-installed import-sort-style-module-alias to make sure that i didn't accidentally remove it. I think a little bug has been introduced when generating the path-name to find custom sort-style plugins. probably a typo somewhere?

thisissami commented 4 years ago

My guess is it has to do with this file here: https://github.com/amatiasq/vsc-sort-imports/blob/master/src/config-cache.ts - At a cursory glance, it doesn't look like it handles anything other than the default-sort-style.

  const config = clone(DEFAULT_CONFIGS);
  const defaultSortStyle = getConfiguration<string>('default-sort-style');

  Object.keys(config).forEach(key => {
    config[key].style = require.resolve(
      `import-sort-style-${defaultSortStyle}`
    );
  });

@jquense tagging you, as you contributed that file to the source code and can speak better to this.

jquense commented 4 years ago

The logic hasn't changed from v6 to v6.1.0 around how configs are resolved, only how often configs are watched for changes. The code above doesn't handle resolving anything but the defaults, because sort itself will do that. @thisissami how are you configuring the style? Unsure why it'd stop working across a version here since the extension doesn't handle config loading logic (defers to import-sort for that)

thisissami commented 4 years ago

I'm using vscode's UI for extension settings. In there, I've typed in module-alias. I then have of course import-sort-style-module-alias added to my node_modules, and the appropriate settings for said plugin in my package.json. This has not been an issue for me until this release (though the v6.02 release had a different set of issues that rendered it impossible to use this extension on Ubuntu 18.04).

andrefox333 commented 4 years ago

Any updates? Would love to use https://www.npmjs.com/package/import-sort-style-module-alias as my style of choice...

Maweypeyyu commented 4 years ago

I had a similar issue and after a long time I figured out that neither the project's local node_modules folder nor the global node_module folder were on the search path for require.resolve() inside the extension.

My solution was to add the global node_modules folders to .bashrc via:

export NODE_PATH=/usr/lib/node_modules

then npm i -g import-sort-style-xyz, then restart vscode and it should work.


I'm not an extensions developer, but I'm wondering whether it should be possible to have extensions access the current project's/workspace's node_modules folder.

fsmaia commented 4 years ago

@andrefox333, @thisissami, did you fix it?

I have about 30 repositories with this set and never had problems.

thisissami commented 4 years ago

@fsmaia i just reverted to an earlier version and have been happy with that.

dkoprowski commented 4 years ago

I can confirm that I needed to revert two versions (to 6.0.1) to make it work.

DrewLandgraveCbsi commented 3 years ago

This is still happening in 6.2.2

secondfry commented 3 years ago

Feels like this is the root of the issue: https://github.com/amatiasq/vsc-sort-imports/commit/5ff45e31885da8645064b9a534dad409d7c03b99#diff-943b8560c99a4d9dd2a7af3c4144d6d3afc983f82ea861eb4cba6c212a0d72d4L36-R38

6.1.0:

4/14/2021, 7:32:53 PM:
----------------------
Cannot find module 'import-sort-style-module-tsconfig'
Require stack:
- /Users/secondfry/.vscode/extensions/amatiasq.sort-imports-6.1.0/out/src/config-cache.js
- /Users/secondfry/.vscode/extensions/amatiasq.sort-imports-6.1.0/out/src/extension.js
- /Users/secondfry/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js
- /Users/secondfry/Applications/Visual Studio Code.app/Contents/Resources/app/out/bootstrap-amd.js
- /Users/secondfry/Applications/Visual Studio Code.app/Contents/Resources/app/out/bootstrap-fork.js

6.0.2:

[2021-04-14 19:27:31.185] [exthost] [error] onWillSaveTextDocument-listener from extension 'amatiasq.sort-imports' threw ERROR
[2021-04-14 19:27:31.185] [exthost] [error] Error: Cannot find module 'import-sort-style-module-tsconfig'
Require stack:
- /Users/secondfry/.vscode/extensions/amatiasq.sort-imports-6.0.2/out/src/sort.js
- /Users/secondfry/.vscode/extensions/amatiasq.sort-imports-6.0.2/out/src/on-save.js
- /Users/secondfry/.vscode/extensions/amatiasq.sort-imports-6.0.2/out/src/extension.js
- /Users/secondfry/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js
- /Users/secondfry/Applications/Visual Studio Code.app/Contents/Resources/app/out/bootstrap-amd.js
- /Users/secondfry/Applications/Visual Studio Code.app/Contents/Resources/app/out/bootstrap-fork.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:1019:15)
    at Function.v.resolve (/Users/secondfry/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/loader.js:4:756)
    at /Users/secondfry/.vscode/extensions/amatiasq.sort-imports-6.0.2/out/src/sort.js:35:37
    at Array.forEach (<anonymous>)
    at Object.sort (/Users/secondfry/.vscode/extensions/amatiasq.sort-imports-6.0.2/out/src/sort.js:34:25)
    at listener (/Users/secondfry/.vscode/extensions/amatiasq.sort-imports-6.0.2/out/src/on-save.js:42:31)
    at P._deliverEventAsync (/Users/secondfry/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:86:30117)
    at P._deliverEventAsyncAndBlameBadListeners (/Users/secondfry/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:86:29345)
    at P.$participateInSave (/Users/secondfry/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:86:29046)

6.0.1 uses "import-sort": "^5.0.0", which seems to ignore default-sort-style completely.

jerome-benoit commented 3 years ago

That issue is not reproducible anymore with various local test setups since https://github.com/amatiasq/vsc-sort-imports/pull/83 merge.

You have to give us a repository where you have the issue 100% of the time to allow more investigation.

Thanks.

jerome-benoit commented 3 years ago

Fixed in 6.2.6 version.