Skip to content

Commit 47a8193

Browse files
authored
native module resolution fix (microsoft#4467)
* resolve modules in target directory as well * reduce log level * better log level * better logging
1 parent 7dbbc8c commit 47a8193

3 files changed

Lines changed: 49 additions & 10 deletions

File tree

.vscode/launch.json

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
"version": "0.2.0",
33
"configurations": [
44
{
5-
"name": "DebugBuildTarget",
5+
"name": "HidList",
66
"type": "node",
77
"request": "launch",
88
"program": "${workspaceRoot}/built/pxt.js",
99
"stopOnEntry": false,
10-
"args": ["buildtarget"],
10+
"args": [
11+
"hidlist"
12+
],
1113
"cwd": "${workspaceRoot}/../pxt-adafruit",
1214
"runtimeExecutable": null,
1315
"runtimeArgs": [
@@ -21,12 +23,35 @@
2123
"outFiles": []
2224
},
2325
{
24-
"name": "DebugBuildPackage",
26+
"name": "BuildTarget",
2527
"type": "node",
2628
"request": "launch",
2729
"program": "${workspaceRoot}/built/pxt.js",
2830
"stopOnEntry": false,
29-
"args": ["build"],
31+
"args": [
32+
"buildtarget"
33+
],
34+
"cwd": "${workspaceRoot}/../pxt-adafruit",
35+
"runtimeExecutable": null,
36+
"runtimeArgs": [
37+
"--nolazy"
38+
],
39+
"env": {
40+
"NODE_ENV": "development"
41+
},
42+
"console": "integratedTerminal",
43+
"sourceMaps": false,
44+
"outFiles": []
45+
},
46+
{
47+
"name": "BuildPackage",
48+
"type": "node",
49+
"request": "launch",
50+
"program": "${workspaceRoot}/built/pxt.js",
51+
"stopOnEntry": false,
52+
"args": [
53+
"build"
54+
],
3055
"cwd": "${workspaceRoot}/../pxt-adafruit/projects/pxt-seesaw",
3156
"runtimeExecutable": null,
3257
"runtimeArgs": [
@@ -45,7 +70,10 @@
4570
"request": "launch",
4671
"program": "${workspaceRoot}/built/pxt.js",
4772
"stopOnEntry": false,
48-
"args": ["pyconv", "adafruit_seesaw"],
73+
"args": [
74+
"pyconv",
75+
"adafruit_seesaw"
76+
],
4977
"cwd": "${workspaceRoot}/../pxt-adafruit/projects/Adafruit_CircuitPython_seesaw",
5078
"runtimeExecutable": null,
5179
"runtimeArgs": [
@@ -59,16 +87,21 @@
5987
"outFiles": []
6088
},
6189
{
62-
"name": "Run mocha",
90+
"name": "Mocha",
6391
"type": "node",
6492
"request": "launch",
6593
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
6694
"stopOnEntry": false,
67-
"args": ["built/tests/decompile-test/runner.js", "--no-timeouts"],
95+
"args": [
96+
"built/tests/decompile-test/runner.js",
97+
"--no-timeouts"
98+
],
6899
"cwd": "${workspaceRoot}",
69100
"runtimeExecutable": null,
70-
"env": { "NODE_ENV": "testing"}
71-
},
101+
"env": {
102+
"NODE_ENV": "testing"
103+
}
104+
},
72105
{
73106
"name": "Attach",
74107
"type": "node",

cli/hid.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ export interface HidDevice {
2020

2121
export function listAsync() {
2222
return getHF2DevicesAsync()
23-
.then(devices => devices.forEach(device => pxt.log(device)));
23+
.then(devices => {
24+
pxt.log(`found ${devices.length} HID devices`);
25+
devices.forEach(device => pxt.log(device));
26+
})
2427
}
2528

2629
export function serialAsync() {

cli/nodeutil.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export let pxtCoreDir: string = path.join(__dirname, "..");
2929

3030
export function setTargetDir(dir: string) {
3131
targetDir = dir;
32+
(<any>module).paths.push(path.join(targetDir, "node_modules"));
3233
}
3334

3435
export function readResAsync(g: events.EventEmitter) {
@@ -510,6 +511,8 @@ export function lazyRequire(name: string, install = false): any {
510511
} catch (e) {
511512
if (install)
512513
pxt.log(`package "${name}" failed to load, run "pxt npminstallnative" to install native depencencies`)
514+
pxt.debug(e);
515+
pxt.debug((<any>require.resolve).paths(name));
513516
return undefined;
514517
}
515518
/* tslint:enable:non-literal-require */

0 commit comments

Comments
 (0)