PHF
PHF

Reputation: 1893

How to debug a Meteor plugin file?

Problem: debugger; directive is ignored. How to debug the plug-in file?

Thx!


plugin/compile-atscript.js:

Plugin.registerSourceHandler(
    'ats'
    , function (compileStep) {
        var source = compileStep.read().toString('utf8');
        console.log('source: ' + source);
        debugger;
        console.log('compiled source: ' + source);
    });

Upvotes: 3

Views: 281

Answers (2)

catimos
catimos

Reputation: 156

On macOS

  1. Set Environment variable

    export TOOL_NODE_FLAGS="--inspect-brk"

  2. List env vars

    printenv

  3. Run meteor

    meteor

Debugger will be listening and will get attached to Chrome dev tools on opening the Chrome Browser.

Upvotes: 0

Matt McCutchen
Matt McCutchen

Reputation: 30889

The Meteor tool runs build plugins in-process, so you just need to run it under the debugger. On Linux and Mac OS X, the launcher script supports a TOOL_NODE_FLAGS variable that can be used to pass arguments to the Node.js runtime to enable debugging. See the instructions for debugging the Meteor tool, although these are geared toward use with a git checkout of Meteor. A hacky shortcut:

METEOR_INSTALLATION=~/.meteor/packages/meteor-tool/$(meteor --long-version | sed -ne 's/^meteor-tool@//p')/mt-$(meteor --arch)
TOOL_NODE_FLAGS=$METEOR_INSTALLATION/dev_bundle/lib/node_modules/node-inspector/bin/node-debug.js $METEOR_INSTALLATION/meteor

(Note, using just meteor on the last line may not work because when the default version of the Meteor tool executes the proper version for the app, the debugger would be started a second time.)

On Windows, support for TOOL_NODE_FLAGS was added to the launcher script in Meteor 1.4.4. If the app is using an older version of Meteor, one could manually edit the launcher script. The commands to start debugging would look like:

set METEOR_INSTALLATION=%LOCALAPPDATA%\.meteor\packages\meteor-tool\TOOL_VERSION\mt-os.windows.x86_32
set TOOL_NODE_FLAGS=%METEOR_INSTALLATION%\dev_bundle\lib\node_modules\node-inspector\bin\node-debug.js
%METEOR_INSTALLATION%\meteor.bat

(Someone else is welcome to add copy-and-pasteable code to figure out the correct TOOL_VERSION!)

Upvotes: 1

Related Questions