NativeScript / plugin-seed

Build NativeScript Plugins Fast ⚡
https://docs.nativescript.org/plugins/plugin-workspace-guide
Apache License 2.0
45 stars 11 forks source link

Changing npm scope breaks "Reset focus" script #40

Closed sebj54 closed 2 months ago

sebj54 commented 2 months ago

When changing npm scope by running npm run config, it seems that a global search + replace is made but there is an incorrectly replaced line: https://github.com/NativeScript/plugin-seed/blob/ecac7537937edf86e9d178e5ade2beb263fb382f/tools/workspace-scripts.js#L75

The line is replaced like this:

-        script: 'nx g @nativescript/plugin-tools:focus-packages',
+        script: 'nx g @myscope/plugin-tools:focus-packages',

And that breaks the reset command 🤷

npm start
> plugins@0.0.0 start
> nps

nps is executing `default` : nps-i
? NativeScript Plugins ~ made with ❤️  Choose a command to start... focus.reset                    Reset Focus
nps is executing `focus.reset` : nx g @myscope/plugin-tools:focus-packages

 NX   Unable to resolve @myscope/plugin-tools:focus-packages.

Cannot find module '@myscope/plugin-tools/package.json'
Require stack:
- /Users/myuser/projects/test-plugins/node_modules/nx/src/utils/package-json.js
- /Users/myuser/projects/test-plugins/node_modules/nx/src/project-graph/plugins/loader.js
- /Users/myuser/projects/test-plugins/node_modules/nx/src/project-graph/plugins/internal-api.js
- /Users/myuser/projects/test-plugins/node_modules/nx/src/project-graph/project-graph.js
- /Users/myuser/projects/test-plugins/node_modules/nx/src/project-graph/file-utils.js
- /Users/myuser/projects/test-plugins/node_modules/nx/src/utils/package-manager.js
- /Users/myuser/projects/test-plugins/node_modules/nx/src/utils/child-process.js
- /Users/myuser/projects/test-plugins/node_modules/nx/src/command-line/migrate/command-object.js
- /Users/myuser/projects/test-plugins/node_modules/nx/src/command-line/nx-commands.js
- /Users/myuser/projects/test-plugins/node_modules/nx/bin/init-local.js
- /Users/myuser/projects/test-plugins/node_modules/nx/bin/nx.js
Pass --verbose to see the stacktrace.

The script called "focus.reset" which runs "nx g @myscope/plugin-tools:focus-packages" failed with exit code 1 https://github.com/Markforged/nps/blob/master/other/ERRORS_AND_WARNINGS.md#failed-with-exit-code
NathanWalker commented 2 months ago

Thanks for this @sebj54 would you like to try a PR here? https://github.com/NativeScript/plugin-tools Otherwise we'll try to get a patch for this in next release cycle.

sebj54 commented 2 months ago

Yes sure! Do you know which file is causing the issue?

Otherwise I'll try to find out 😅

NathanWalker commented 2 months ago

I think it may just be inadvertent change in your workspace locally.

the command does look wrong in that output:

nx g @myscope/plugin-tools:focus-packages

It should be:

nx g @nativescript/plugin-tools:focus-packages

See here: https://github.com/NativeScript/plugins/blob/1237aab9c9ca0f0e020ae229daf59136641c863d/tools/workspace-scripts.js#L460

If you find yours differs, just update workspace-scripts.js to match that.

sebj54 commented 2 months ago

Thanks for your answer but I think I misspoke. I understand what is causing the focus.reset script to fail but my question should have been:

Do you know what script is actually replacing the scope?

Don't worry though, I'll figure it out (and I already think it is this line: https://github.com/NativeScript/plugin-tools/blob/9667c86f3e74893403e38508d54e2b19575dccb2/packages/plugin-tools/src/generators/config/index.ts#L105)